From eeb92580c6fc8607f914e771095834b234a81f5b Mon Sep 17 00:00:00 2001 From: Martin Perner Date: Tue, 9 Nov 2010 16:56:57 +0100 Subject: [PATCH] sim: bugfix for overflow and so ... --- 3b_sim/ccpu.cpp | 6 ++++-- 3c_disasm/instr/cmp.cpp | 2 +- 3c_disasm/instr/cmpi.cpp | 5 +++-- 3c_disasm/instr/sub.cpp | 2 +- 3c_disasm/instr/subi.cpp | 2 +- 5 files changed, 10 insertions(+), 7 deletions(-) diff --git a/3b_sim/ccpu.cpp b/3b_sim/ccpu.cpp index 04dd595..abeeafd 100644 --- a/3b_sim/ccpu.cpp +++ b/3b_sim/ccpu.cpp @@ -127,8 +127,10 @@ void CCpu::updateFlags(CDatd val, CDat a, CDat b) { this->m_Z = (val == 0); this->m_S = ((val >> (BIT_LEN-1)) & 0x1); this->m_C = ((val >> (BIT_LEN)) & 0x1); - bool v = (((a ^ b) >> (BIT_LEN-1)) & 0x1) ? true : false; - this->m_O = (this->m_S != v); + bool a_31 = ((a >> (BIT_LEN-1)) & 0x1); + bool b_31 = ((b >> (BIT_LEN-1)) & 0x1); + bool val_31 = ((val >> (BIT_LEN-1)) & 0x1); + this->m_O = ((a_31 && b_31 && !val_31) || (!a_31 && !b_31 && val_31)); } void CCpu::updateCarry(bool c) diff --git a/3c_disasm/instr/cmp.cpp b/3c_disasm/instr/cmp.cpp index 7924ed7..b9b02bf 100644 --- a/3c_disasm/instr/cmp.cpp +++ b/3c_disasm/instr/cmp.cpp @@ -56,7 +56,7 @@ void Ccmp::execInstr() CDat ra = this->m_cpu->getRegister(m_ra); CDat rb = this->m_cpu->getRegister(m_rb); CDatd val = ra - rb; - this->m_cpu->updateFlags(val, ra, rb); + this->m_cpu->updateFlags(val, ra, (~rb)+1); } std::string Ccmp::toString() diff --git a/3c_disasm/instr/cmpi.cpp b/3c_disasm/instr/cmpi.cpp index 0de9659..2a80bf7 100644 --- a/3c_disasm/instr/cmpi.cpp +++ b/3c_disasm/instr/cmpi.cpp @@ -41,6 +41,7 @@ Ccmpi::Ccmpi() name = "cmpi"; } + void Ccmpi::evalInstr() { argbits >>= 3; @@ -57,7 +58,7 @@ void Ccmpi::execInstr() //cout << "should exec " << this->toString() << endl; CDat ra = this->m_cpu->getRegister(m_ra); CDatd reg = ra - this->m_imm; - this->m_cpu->updateFlags(reg, ra, this->m_imm); + this->m_cpu->updateFlags(reg, ra, (~this->m_imm)+1); } std::string Ccmpi::toString() @@ -69,7 +70,7 @@ std::string Ccmpi::toString() if(m_s) op << 'S'; if(m_c) op << 'C'; - op << this->getConditionFlag() << " r" << m_rd << ", r" << m_ra << ", " << m_imm; + op << this->getConditionFlag() << " r" << m_ra << ", " << m_imm; return op.str(); } diff --git a/3c_disasm/instr/sub.cpp b/3c_disasm/instr/sub.cpp index d174735..6936f52 100644 --- a/3c_disasm/instr/sub.cpp +++ b/3c_disasm/instr/sub.cpp @@ -64,7 +64,7 @@ void Csub::execInstr() CDatd val = ra - rb; this->m_cpu->setRegister(m_rd, val); if(!this->m_d) { - this->m_cpu->updateFlags(val, ra, rb); + this->m_cpu->updateFlags(val, ra, (~rb)+1); } } diff --git a/3c_disasm/instr/subi.cpp b/3c_disasm/instr/subi.cpp index 701599c..d264ee3 100644 --- a/3c_disasm/instr/subi.cpp +++ b/3c_disasm/instr/subi.cpp @@ -66,7 +66,7 @@ void Csubi::execInstr() CDatd reg = ra - this->m_imm; this->m_cpu->setRegister(m_rd, reg); if(!this->m_d) { - this->m_cpu->updateFlags(reg, ra, this->m_imm); + this->m_cpu->updateFlags(reg, ra, (~this->m_imm)+1); } } -- 2.25.1