copyleft: gplv3 added and set repo to public
[calu.git] / 3c_disasm / instr / branch.cpp
index 90a56cbce8258d2a882f1ade81f48015784fdeb4..f62569a5b97de3a3d8b40fe0230f21907ae8cd6f 100644 (file)
@@ -1,3 +1,24 @@
+/*   `Deep Thought', a softcore CPU implemented on a FPGA
+
+    Copyright (C) 2010 Markus Hofstaetter <markus.manrow@gmx.at>
+    Copyright (C) 2010 Martin Perner <e0725782@student.tuwien.ac.at>
+    Copyright (C) 2010 Stefan Rebernig <stefan.rebernig@gmail.com>
+    Copyright (C) 2010 Manfred Schwarz <e0725898@student.tuwien.ac.at>
+    Copyright (C) 2010 Bernhard Urban <lewurm@gmail.com>
+
+    This program is free software: you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation, either version 3 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program.  If not, see <http://www.gnu.org/licenses/>. */
+
 #include "../Iinstr.hpp"
 
 class Cbranch : public Iinstr {
@@ -64,9 +85,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,24 +99,25 @@ 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;
 
 }
 
 void Cbranch::execInstr()
 {
-       cout << "should exec " << this->toString() << endl;
+       //cout << "should exec " << this->toString() << endl;
        CDat pc = this->m_cpu->getCurPC();
        switch(this->m_typ) {
                case 1:
                        {
                        CDat sp = this->m_cpu->getStack();
-                       this->m_cpu->setRAM(sp, pc);
                        sp -= 4;
+                       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 +139,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();
 }