3 /* CDat m_pc, m_pc_next;
7 //void registerExtension() {};
16 Iinstr* instr = this->getProg(m_pc);
18 throw string("Out of Instructions!");
20 if(this->conditionMet(instr->getCondition())) {
21 cout << color(green,black) << "Executing: " << color(white,black) << instr->toString() << endl;
23 this->incPerfBy(instr->getClockCount());
26 cout << color(red,black) << "Didn't Execute " << color(white,black) << instr->toString() << "; condition wasn't met" << endl;
32 bool CCpu::conditionMet(short cond)
60 return (!this->m_C && !this->m_Z);
63 return (this->m_C || this->m_Z);
66 return (this->m_S == this->m_O);
69 return (this->m_S != this->m_O);
72 return (!this->m_Z && (this->m_S == this->m_O));
75 return (!this->m_Z || (this->m_S != this->m_O));
84 cerr << "What did you do? more than 16 values in 5 bits?!" << endl;
90 CDat CCpu::getNextPC() const
95 CDat CCpu::getCurPC() const
100 void CCpu::setNextPC(CDat val)
105 CDat CCpu::getFlags() const {
107 psw += (this->m_Z ? 1 : 0);
108 psw += (this->m_O ? 2 : 0);
109 psw += (this->m_C ? 4 : 0);
110 psw += (this->m_S ? 8 : 0);
114 void CCpu::setFlags(CDat psw) {
115 this->m_Z = ((psw & 0x1) != 0);
116 this->m_O = ((psw & 0x2) != 0);
117 this->m_C = ((psw & 0x4) != 0);
118 this->m_S = ((psw & 0x8) != 0);
121 void CCpu::updateFlags(CDat val) {
122 this->m_Z = (val == 0);
123 this->m_S = ((val >> (BIT_LEN-1)) & 0x1);
124 /* this->m_C = false;
125 this->m_O = false; */
128 void CCpu::updateFlags(CDatd val, CDat a, CDat b) {
129 this->m_Z = (val == 0);
130 this->m_S = ((val >> (BIT_LEN-1)) & 0x1);
131 this->m_C = ((val >> (BIT_LEN)) & 0x1);
132 bool a_31 = ((a >> (BIT_LEN-1)) & 0x1);
133 bool b_31 = ((b >> (BIT_LEN-1)) & 0x1);
134 bool val_31 = ((val >> (BIT_LEN-1)) & 0x1);
135 this->m_O = ((a_31 && b_31 && !val_31) || (!a_31 && !b_31 && val_31));
138 void CCpu::updateCarry(bool c)
143 bool CCpu::getCarry()
148 void CCpu::updateFlags(bool z, bool o, bool c, bool s)
156 CDat CCpu::getRegister(const int addr) const
158 return m_reg.getDirect(addr);
161 void CCpu::setRegister(const int addr, CDat data)
163 m_reg.setDirect(addr, data);
166 CDat CCpu::getRAM(const int addr) const
168 return m_ram.get(addr);
170 void CCpu::setRAM(const int addr, CDat data)
172 m_ram.set(addr, data);
175 void CCpu::setProg(int addr, Iinstr* instr)
177 m_prog.set(addr, instr);
180 Iinstr* CCpu::getProg(const int addr) const
182 return m_prog.get(addr);
185 int CCpu::getStack() const
187 return this->m_stack;
190 void CCpu::setStack(const int val)
195 CDat CCpu::getPerf() const
200 void CCpu::setPerf(CDat val)
210 void CCpu::incPerfBy(short inc)
216 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)