3 /* CDat m_pc, m_pc_next;
7 //void registerExtension() {};
9 const char* expression = "(;.*)|(r0)|(rX)|(r1[0-5])|(r[1-5])|(r[6-9])|(0x[a-fA-F0-9]+)|([-]?\\d+)";
10 const char* format = "(?1$&)"
11 //Return-Register: violett
12 "(?2\033[0m\033[35m$&\033[0m\\3:)"
13 // Callee-saved Register: rot
14 "(?4\033[0m\033[31m$&\033[0m\\3:)"
15 //Argument-Register: gruen
16 "(?5\033[0m\033[32m$&\033[0m\\3:)"
17 // Temporary Register: gelb
18 "(?6\033[0m\033[33m$&\033[0m\\3:)"
19 // Zahlenwerte: tuerkis
20 "(?7\033[0m\033[36m$&\033[0m\\3:)"
21 "(?8\033[0m\033[36m$&\033[0m\\3:)";
24 string CCpu::colorifyInstr(string instr)
28 return boost::regex_replace(instr, e, format, boost::match_default | boost::format_all);
39 Iinstr* instr = this->getProg(m_pc);
41 throw string("Out of Instructions!");
43 if(this->conditionMet(instr->getCondition())) {
44 cout << color(green,black) << "Executing: " << color(white,black) << colorifyInstr(instr->toString()) << endl;
46 this->incPerfBy(instr->getClockCount());
49 cout << color(red,black) << "Didn't Execute " << color(white,black) << colorifyInstr(instr->toString()) << "; condition wasn't met" << endl;
55 bool CCpu::conditionMet(short cond)
83 return (!this->m_C && !this->m_Z);
86 return (this->m_C || this->m_Z);
89 return (this->m_S == this->m_O);
92 return (this->m_S != this->m_O);
95 return (!this->m_Z && (this->m_S == this->m_O));
98 return (!this->m_Z || (this->m_S != this->m_O));
107 cerr << "What did you do? more than 16 values in 5 bits?!" << endl;
113 CDat CCpu::getNextPC() const
118 CDat CCpu::getCurPC() const
123 void CCpu::setNextPC(CDat val)
128 CDat CCpu::getFlags() const {
130 psw += (this->m_Z ? 1 : 0);
131 psw += (this->m_O ? 2 : 0);
132 psw += (this->m_C ? 4 : 0);
133 psw += (this->m_S ? 8 : 0);
137 void CCpu::setFlags(CDat psw) {
138 this->m_Z = ((psw & 0x1) != 0);
139 this->m_O = ((psw & 0x2) != 0);
140 this->m_C = ((psw & 0x4) != 0);
141 this->m_S = ((psw & 0x8) != 0);
144 void CCpu::updateFlags(CDat val) {
145 this->m_Z = (val == 0);
146 this->m_S = ((val >> (BIT_LEN-1)) & 0x1);
147 /* this->m_C = false;
148 this->m_O = false; */
151 void CCpu::updateFlags(CDatd val, CDat a, CDat b) {
152 this->m_Z = (val == 0);
153 this->m_S = ((val >> (BIT_LEN-1)) & 0x1);
154 this->m_C = ((val >> (BIT_LEN)) & 0x1);
155 bool a_31 = ((a >> (BIT_LEN-1)) & 0x1);
156 bool b_31 = ((b >> (BIT_LEN-1)) & 0x1);
157 bool val_31 = ((val >> (BIT_LEN-1)) & 0x1);
158 this->m_O = ((a_31 && b_31 && !val_31) || (!a_31 && !b_31 && val_31));
161 void CCpu::updateCarry(bool c)
166 bool CCpu::getCarry()
171 void CCpu::updateFlags(bool z, bool o, bool c, bool s)
179 CDat CCpu::getRegister(const int addr) const
181 return m_reg.getDirect(addr);
184 void CCpu::setRegister(const int addr, CDat data)
186 m_reg.setDirect(addr, data);
189 CDat CCpu::getRAM(const int addr) const
191 return m_ram.get(addr);
193 void CCpu::setRAM(const int addr, CDat data)
195 m_ram.set(addr, data);
198 void CCpu::setProg(int addr, Iinstr* instr)
200 m_prog.set(addr, instr);
203 Iinstr* CCpu::getProg(const int addr) const
205 return m_prog.get(addr);
208 int CCpu::getStack() const
210 return this->m_stack;
213 void CCpu::setStack(const int val)
218 CDat CCpu::getPerf() const
223 void CCpu::setPerf(CDat val)
233 void CCpu::incPerfBy(short inc)
239 CCpu::CCpu(int regs, int ram, int prog) : m_Z(false), m_S(false), m_C(false), m_O(false), m_pc(0), m_pc_next(0), m_perf(0), m_reg(regs), m_ram(ram), m_prog(prog), m_stack(0)