sim: instrs can have different effect on perf count
authorMartin Perner <martin@perner.cc>
Sat, 13 Nov 2010 17:39:45 +0000 (18:39 +0100)
committerMartin Perner <martin@perner.cc>
Sat, 13 Nov 2010 17:39:45 +0000 (18:39 +0100)
3b_sim/ccpu.cpp
3b_sim/ccpu.hpp
3c_disasm/Iinstr.hpp
3c_disasm/instr/branch.cpp

index 5f533ce42c546860fd22e9f99d63ae77d371f2b8..6bfb65481fd61162ddcb9afd2ec3a9f14f102de1 100644 (file)
@@ -17,13 +17,14 @@ void CCpu::tick()
        if(instr == NULL) {
                throw string("Out of Instructions!");
        }
-       this->incPerf();
        if(this->conditionMet(instr->getCondition())) {
                cout << "Executing: " << instr->toString() << endl;
                instr->execInstr();
+               this->incPerfBy(instr->getClockCount());
        }
        else {
                cout << "Didn't Execute " << instr->toString() << "; condition wasn't met" << endl;
+               this->incPerf();
        }
 
 }
@@ -206,6 +207,11 @@ void CCpu::incPerf()
        this->m_perf++;
 }
 
+void CCpu::incPerfBy(short inc)
+{
+       this->m_perf += inc;
+}
+
 
 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_perf(0), m_reg(regs), m_ram(ram), m_prog(prog), m_stack(0)
 {
index ebe15f91c24cf03d14e88dd83e308d8c6cfd1847..4c250b57570b97363655da1bbf9c8374e3013843 100644 (file)
@@ -37,6 +37,7 @@ class CCpu {
                CDat getPerf() const;
                void setPerf(CDat);
                void incPerf();
+               void incPerfBy(short);
 
                CDat getCurPC() const;
                CDat getNextPC() const;
index 2cc17df5e1f4d5093e10a75d4eb5f3b03db25e41..e16c26c13a90200373d6de7e9af94d2d28a121f2 100644 (file)
@@ -51,7 +51,7 @@ enum CONDITIONS {
 
 class Iinstr {
        protected:
-               short opcode;
+               short opcode, clockcount;
                std::string name;
                short m_ra, m_rb, m_rd;
                bool m_c, m_d, m_hl, m_f, m_s;
@@ -59,7 +59,7 @@ class Iinstr {
                short m_cond;
                boost::dynamic_bitset<> argbits;
                CDat hexdump;
-               Iinstr() : opcode(0), name(""), m_ra(0), m_rb(0), m_rd(0), m_c(0), m_d(0), m_hl(0), m_f(0), m_s(0), m_imm(0), m_cond(ALWAYS), argbits(32), hexdump(0) {}
+               Iinstr() : opcode(0), clockcount(1), name(""), m_ra(0), m_rb(0), m_rd(0), m_c(0), m_d(0), m_hl(0), m_f(0), m_s(0), m_imm(0), m_cond(ALWAYS), argbits(32), hexdump(0) {}
 
                CDat generate16ImmFill(const CDat value) const {
                        CDat i = value;
@@ -141,6 +141,10 @@ class Iinstr {
                        return m_cond;
                }
 
+               short getClockCount() {
+                       return clockcount;
+               }
+
                void decodeCondition(short condition) {
                        if(condition >= 0 && condition <= 15) {
                                m_cond = condition;
index 39b2e73c415348fcef9ed366893eb55902f6cd2f..b8781da5d07ed42c323e2b67da8acbf189b9e01b 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;