bootromfun: wir kriegen ein 'O' \o/ (wenn man ein 'H' aufn UART schreibt)
[calu.git] / 3c_disasm / instr / branch.cpp
index 28ff4ebaee30acec0097030c1b3e95db4be2dfe6..f1f9138cbfffb875d1f02aa9cb1d5db45342b8e5 100644 (file)
@@ -64,9 +64,11 @@ void Cbranch::evalInstr()
                        break;
                case 2:
                        this->name = "ret";
+                       this->clockcount = 3;
                        break;
                case 3:
                        this->name = "reti";
+                       this->clockcount = 3;
                        break;
                default:
                        cerr << "What have you done? 2 bits that have more than 4 values?!" << endl;
@@ -76,7 +78,7 @@ void Cbranch::evalInstr()
 
        dynamic_bitset<> immb = argbits;
        immb.resize(16);
-       this->m_imm = this->generate16ImmSign(immb.to_ulong());
+       this->m_imm = this->generate16ImmSign(immb.to_ulong())*4;
 
 }
 
@@ -89,11 +91,12 @@ void Cbranch::execInstr()
                        {
                        CDat sp = this->m_cpu->getStack();
                        sp -= 4;
-                       this->m_cpu->setRAM(sp, pc);
+                       this->m_cpu->setRAM(sp, this->m_cpu->getNextPC());
                        this->m_cpu->setStack(sp);
                        }
+                       /* fall through */
                case 0:
-                       this->m_cpu->setNextPC(pc+this->m_imm);
+                       this->m_cpu->setNextPC(pc+(this->m_imm));
                        break;
                case 2:
                case 3:
@@ -115,7 +118,7 @@ std::string Cbranch::toString()
 
        op << this->getConditionFlag() << (m_taken ? '+' : '-');
        if(m_typ < 2) {
-               op << " 0x" << std::hex << m_imm << "(" << std::dec << m_imm << ")";
+               op << " 0x" << std::hex << m_imm << "(" << std::dec << m_imm << ", " << (int) m_imm << ")";
        }
        return op.str();
 }