Fixed problem in DeviceSettings::strParam, returned wrong string
[avr-sim.git] / src / Stack.h
blob6fb80ac55ae6fc85802aaccfcbf1f5586e27c736
1 #ifndef AVR_STACK_H
2 #define AVR_STACK_H
4 #include "MMU.h"
5 #include "Hardware.h"
7 namespace avr {
9 /**
10 * @author Tom Haber
11 * @date Apr 23, 2008
12 * @brief Represents the stack within the chip.
14 * A software stack implementation. Provides methods
15 * for pushing and popping.
17 class Stack : public Hardware {
18 public:
19 Stack(Bus & bus, MMU & mmu, word mask);
21 public:
22 word getSP() const;
23 unsigned char getSPH() const;
24 unsigned char getSPL() const;
26 void setSP(word sp);
28 public:
29 void push(unsigned char val);
30 unsigned char pop();
32 public:
33 bool attachReg(const char *name, IORegister *reg);
34 bool finishBuild();
35 void regChanged(IORegister *reg);
37 private:
38 void setSPH(unsigned char sph);
39 void setSPL(unsigned char spl);
41 private:
42 MMU & mmu;
43 word mask;
44 word sp;
46 private:
47 Register *sph;
48 Register *spl;
51 inline unsigned char Stack::getSPH() const {
52 return (sp>>8) & 0xff;
55 inline unsigned char Stack::getSPL() const {
56 return (sp & 0xff);
59 inline word Stack::getSP() const {
60 return sp;
63 inline void Stack::setSPH(unsigned char sph) {
64 sp = sp & 0x00ff;
65 sp |= (sph<<8);
66 sp &= mask;
69 inline void Stack::setSPL(unsigned char spl) {
70 sp = sp & 0xff00;
71 sp |= spl;
72 sp &= mask;
77 #endif /*AVR_STACK_H*/