Bug fix: check if vm exists
[avr-sim.git] / Stack.h
blob8a323b308bf6d609b3e7d490856a5a659d98a142
1 #ifndef AVR_STACK_H
2 #define AVR_STACK_H
4 #include "MMU.h"
5 #include "Hardware.h"
7 namespace avr {
9 class Stack : public Hardware {
10 public:
11 Stack(Bus & bus, MMU & mmu, word mask);
13 public:
14 word getSP() const;
15 unsigned char getSPH() const;
16 unsigned char getSPL() const;
18 void setSP(word sp);
20 public:
21 void push(unsigned char val);
22 unsigned char pop();
24 public:
25 bool attachReg(const char *name, IORegister *reg);
26 void regChanged(IORegister *reg);
27 void step();
29 private:
30 void setSPH(unsigned char sph);
31 void setSPL(unsigned char spl);
33 private:
34 MMU & mmu;
35 word mask;
36 word sp;
38 private:
39 Register *sph;
40 Register *spl;
43 inline unsigned char Stack::getSPH() const {
44 return (sp>>8) & 0xff;
47 inline unsigned char Stack::getSPL() const {
48 return (sp & 0xff);
51 inline word Stack::getSP() const {
52 return sp;
55 inline void Stack::setSPH(unsigned char sph) {
56 sp = sp & 0x00ff;
57 sp |= (sph<<8);
58 sp &= mask;
61 inline void Stack::setSPL(unsigned char spl) {
62 sp = sp & 0xff00;
63 sp |= spl;
64 sp &= mask;
69 #endif /*AVR_STACK_H*/