17f90b18d6abadf65092469b230a38fd6213f101
[calu.git] / 3b_sim / ccpu.hpp
1 #ifndef __CPU__H__
2 #define __CPU__H__
3
4 #include "cdat.hpp"
5 #include "cmem.hpp"
6 #include "cpmem.hpp"
7
8 #include "ccolor.h"
9
10 class Iinstr;
11 class Iext;
12
13 #include "iext.hpp"
14 #include <boost/regex.hpp>
15 #include "Iinstr.hpp"
16
17
18 class CCpu {
19         private:
20
21                 bool m_Z, m_S, m_C, m_O, m_breakNext;
22
23                 CDat m_pc, m_pc_next, m_perf;
24                 CMem<CDat> m_reg, m_ram;
25                 CPMem<Iinstr*> m_prog;
26
27                 vector<Iext*> m_exts;
28
29                 CDat m_stack;
30
31                 static const int EXT_MODEL_OFFSET = 0x2000;
32
33         public:
34                 void registerExtension() {};
35                 void applyToExtensions(const vector<string>& in);
36                 void tick();
37
38                 void breakNext();
39                 bool shouldBreak();
40
41                 CDat getRegister(const int) const;
42                 void setRegister(const int, CDat);
43
44                 CDat getRAM(const int) const;
45                 void setRAM(const int, CDat);
46
47                 Iinstr* getProg(const int) const;
48                 void setProg(const int, Iinstr*);
49
50                 void registerExtension(Iext*);
51
52                 CDat getPerf() const;
53                 void setPerf(CDat);
54                 void incPerf();
55                 void incPerfBy(short);
56
57                 CDat getCurPC() const;
58                 CDat getNextPC() const;
59                 void setNextPC(CDat);
60
61                 CDat getFlags() const;
62                 void setFlags(CDat);
63                 /* will only change zero and sign */
64                 void updateFlags(CDat);
65                 /* will change all flags */
66                 void updateFlags(CDatd, CDat, CDat);
67                 /* will change all flags */
68                 void updateFlags(bool z, bool o, bool c, bool s);
69                 /* will change carry */
70                 void updateCarry(bool c);
71
72                 bool getCarry();
73
74                 bool conditionMet(short);
75
76                 int getStack() const;
77                 void setStack(const int);
78
79                 string colorifyInstr(string instr);
80
81                 CCpu(int,int,int);
82
83 };
84
85
86 #endif