sim: bugfix for overflow and so ...
authorMartin Perner <martin@perner.cc>
Tue, 9 Nov 2010 15:56:57 +0000 (16:56 +0100)
committerMartin Perner <martin@perner.cc>
Tue, 9 Nov 2010 15:56:57 +0000 (16:56 +0100)
3b_sim/ccpu.cpp
3c_disasm/instr/cmp.cpp
3c_disasm/instr/cmpi.cpp
3c_disasm/instr/sub.cpp
3c_disasm/instr/subi.cpp

index 04dd5951b4021e13ac62a86bbd28f390a6af2983..abeeafd607c912e01402a9d889871895fe6bee49 100644 (file)
@@ -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)
index 7924ed7511d97cefb550e6b416cb603b4c6acde8..b9b02bfef4b450de938a4f685ee0a669166552c9 100644 (file)
@@ -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()
index 0de9659ed7511d583661ceb95224dc0bb61a31d8..2a80bf78cbb6338427d2127aff4e768eb42f0122 100644 (file)
@@ -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();
 }
index d17473512e1b5249e084479f61690b483920d04e..6936f52265a6c1fba7bfa9b6af6752fcb1208850 100644 (file)
@@ -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);
        }
 }
 
index 701599c3323c84108c848c3ae34cb3c19ebc2960..d264ee3d0c819ddca9445712d2c46d35ce433565 100644 (file)
@@ -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);
        }
 }