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 << "Executing: " << instr->toString() << endl;
25 cout << "Didn't Execute " << instr->toString() << "; condition wasn't met" << endl;
30 bool CCpu::conditionMet(short cond)
58 return (!this->m_C && !this->m_Z);
61 return (this->m_C || this->m_Z);
64 return (this->m_S == this->m_O);
67 return (this->m_S != this->m_O);
70 return (!this->m_Z && (this->m_S == this->m_O));
73 return (!this->m_Z || (this->m_S != this->m_O));
82 cerr << "What did you do? more than 16 values in 5 bits?!" << endl;
88 CDat CCpu::getNextPC() const
93 CDat CCpu::getCurPC() const
98 void CCpu::setNextPC(CDat val)
103 CDat CCpu::getFlags() const {
105 psw += (this->m_Z ? 1 : 0);
106 psw += (this->m_O ? 2 : 0);
107 psw += (this->m_C ? 4 : 0);
108 psw += (this->m_S ? 8 : 0);
112 void CCpu::setFlags(CDat psw) {
113 this->m_Z = ((psw & 0x1) != 0);
114 this->m_O = ((psw & 0x2) != 0);
115 this->m_C = ((psw & 0x4) != 0);
116 this->m_S = ((psw & 0x8) != 0);
119 void CCpu::updateFlags(CDat val) {
120 this->m_Z = (val == 0);
121 this->m_S = ((val >> (BIT_LEN-1)) & 0x1);
122 /* this->m_C = false;
123 this->m_O = false; */
126 void CCpu::updateFlags(CDatd val, CDat a, CDat b) {
127 this->m_Z = (val == 0);
128 this->m_S = ((val >> (BIT_LEN-1)) & 0x1);
129 this->m_C = ((val >> (BIT_LEN)) & 0x1);
130 bool a_31 = ((a >> (BIT_LEN-1)) & 0x1);
131 bool b_31 = ((b >> (BIT_LEN-1)) & 0x1);
132 bool val_31 = ((val >> (BIT_LEN-1)) & 0x1);
133 this->m_O = ((a_31 && b_31 && !val_31) || (!a_31 && !b_31 && val_31));
136 void CCpu::updateCarry(bool c)
141 bool CCpu::getCarry()
146 void CCpu::updateFlags(bool z, bool o, bool c, bool s)
154 CDat CCpu::getRegister(const int addr) const
156 return m_reg.getDirect(addr);
159 void CCpu::setRegister(const int addr, CDat data)
161 m_reg.setDirect(addr, data);
164 CDat CCpu::getRAM(const int addr) const
166 return m_ram.get(addr);
168 void CCpu::setRAM(const int addr, CDat data)
170 m_ram.set(addr, data);
173 void CCpu::setProg(int addr, Iinstr* instr)
175 m_prog.set(addr, instr);
178 Iinstr* CCpu::getProg(const int addr) const
180 return m_prog.get(addr);
183 int CCpu::getStack() const
185 return this->m_stack;
188 void CCpu::setStack(const int val)
193 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_reg(regs), m_ram(ram), m_prog(prog), m_stack(0)