3 /* CDat m_pc, m_pc_next;
7 //void registerExtension() {};
16 Iinstr* instr = this->getProg(m_pc);
18 throw string("Out of Instructions!");
21 if(this->conditionMet(instr->getCondition())) {
22 cout << "Executing: " << instr->toString() << endl;
26 cout << "Didn't Execute " << instr->toString() << "; condition wasn't met" << endl;
31 bool CCpu::conditionMet(short cond)
59 return (!this->m_C && !this->m_Z);
62 return (this->m_C || this->m_Z);
65 return (this->m_S == this->m_O);
68 return (this->m_S != this->m_O);
71 return (!this->m_Z && (this->m_S == this->m_O));
74 return (!this->m_Z || (this->m_S != this->m_O));
83 cerr << "What did you do? more than 16 values in 5 bits?!" << endl;
89 CDat CCpu::getNextPC() const
94 CDat CCpu::getCurPC() const
99 void CCpu::setNextPC(CDat val)
104 CDat CCpu::getFlags() const {
106 psw += (this->m_Z ? 1 : 0);
107 psw += (this->m_O ? 2 : 0);
108 psw += (this->m_C ? 4 : 0);
109 psw += (this->m_S ? 8 : 0);
113 void CCpu::setFlags(CDat psw) {
114 this->m_Z = ((psw & 0x1) != 0);
115 this->m_O = ((psw & 0x2) != 0);
116 this->m_C = ((psw & 0x4) != 0);
117 this->m_S = ((psw & 0x8) != 0);
120 void CCpu::updateFlags(CDat val) {
121 this->m_Z = (val == 0);
122 this->m_S = ((val >> (BIT_LEN-1)) & 0x1);
123 /* this->m_C = false;
124 this->m_O = false; */
127 void CCpu::updateFlags(CDatd val, CDat a, CDat b) {
128 this->m_Z = (val == 0);
129 this->m_S = ((val >> (BIT_LEN-1)) & 0x1);
130 this->m_C = ((val >> (BIT_LEN)) & 0x1);
131 bool a_31 = ((a >> (BIT_LEN-1)) & 0x1);
132 bool b_31 = ((b >> (BIT_LEN-1)) & 0x1);
133 bool val_31 = ((val >> (BIT_LEN-1)) & 0x1);
134 this->m_O = ((a_31 && b_31 && !val_31) || (!a_31 && !b_31 && val_31));
137 void CCpu::updateCarry(bool c)
142 bool CCpu::getCarry()
147 void CCpu::updateFlags(bool z, bool o, bool c, bool s)
155 CDat CCpu::getRegister(const int addr) const
157 return m_reg.getDirect(addr);
160 void CCpu::setRegister(const int addr, CDat data)
162 m_reg.setDirect(addr, data);
165 CDat CCpu::getRAM(const int addr) const
167 return m_ram.get(addr);
169 void CCpu::setRAM(const int addr, CDat data)
171 m_ram.set(addr, data);
174 void CCpu::setProg(int addr, Iinstr* instr)
176 m_prog.set(addr, instr);
179 Iinstr* CCpu::getProg(const int addr) const
181 return m_prog.get(addr);
184 int CCpu::getStack() const
186 return this->m_stack;
189 void CCpu::setStack(const int val)
194 CDat CCpu::getPerf() const
199 void CCpu::setPerf(CDat val)
210 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)