sim: added special moves
authorMartin Perner <martin@perner.cc>
Wed, 3 Nov 2010 17:56:44 +0000 (18:56 +0100)
committerMartin Perner <martin@perner.cc>
Wed, 3 Nov 2010 18:44:12 +0000 (19:44 +0100)
3b_sim/ccpu.cpp
3b_sim/ccpu.hpp
3c_disasm/instr/movf.cpp [new file with mode: 0644]
3c_disasm/instr/movt.cpp [new file with mode: 0644]

index fb480f48fec4843aa2f9121f199d9a27023c0f10..04dd5951b4021e13ac62a86bbd28f390a6af2983 100644 (file)
@@ -109,6 +109,13 @@ CDat CCpu::getFlags() const {
        return psw;
 }
 
+void CCpu::setFlags(CDat psw) {
+       this->m_Z = ((psw & 0x1) != 0);
+       this->m_O = ((psw & 0x2) != 0);
+       this->m_C = ((psw & 0x4) != 0);
+       this->m_S = ((psw & 0x8) != 0);
+}
+
 void CCpu::updateFlags(CDat val) {
        this->m_Z = (val == 0);
        this->m_S = ((val >> (BIT_LEN-1)) & 0x1);
index 0dd8b1bde760d5942aaabeae35ac1b8fe33afd91..86940a29f1f8743bbae2eb3aa923befbfd709365 100644 (file)
@@ -39,6 +39,7 @@ class CCpu {
                void setNextPC(CDat);
 
                CDat getFlags() const;
+               void setFlags(CDat);
                /* will only change zero and sign */
                void updateFlags(CDat);
                /* will change all flags */
diff --git a/3c_disasm/instr/movf.cpp b/3c_disasm/instr/movf.cpp
new file mode 100644 (file)
index 0000000..d2c0a35
--- /dev/null
@@ -0,0 +1,79 @@
+#include "../Iinstr.hpp"
+
+class Cmovf : public Iinstr {
+       private:
+               bool m_type;
+       public:
+               Cmovf();
+               void evalInstr();
+               void execInstr();
+               std::string toString();
+               Iinstr* getNew();
+};
+
+/**
+ * Name:      create_instruction
+ * Purpose:   if compiled as shared library, this functions creates the 
+              instruction object
+
+ * Returns:   pointer to instruction object
+ */
+extern "C" Iinstr* create_instruction() {
+    return new Cmovf();
+}
+
+Iinstr* Cmovf::getNew() {
+       return new Cmovf();
+}
+
+/**
+ * Name:      destroy_instruction
+ * Purpose:   if compiled as shared library, this functions destoys the 
+              instruction object
+
+ * Parameter: IInstruction - the instruction object to delete
+ */
+extern "C" void destroy_instruction(Iinstr* p) {
+    delete p;
+}
+
+Cmovf::Cmovf() : m_type(0)
+{
+       opcode = B5(01100);
+       name = "movf";
+}
+
+void Cmovf::evalInstr()
+{
+       this->m_type = argbits[18];
+       if(this->m_type) {
+               name = "movpf";
+       }
+       else {
+               name = "movsf";
+       }
+       
+       argbits >>= 19;
+       m_rd = this->getRegister(argbits);
+}
+
+void Cmovf::execInstr()
+{
+       //cout << "should exec " << this->toString() << endl;
+       CDat val;
+       if(this->m_type) {
+               val = this->m_cpu->getFlags();
+       }
+       else {
+               val = this->m_cpu->getStack();
+       }
+       this->m_cpu->setRegister(this->m_rd, val);
+}
+
+std::string Cmovf::toString()
+{
+       stringstream op;
+       op << this->getName();
+       op << " r" << m_rd;
+       return op.str();
+}
diff --git a/3c_disasm/instr/movt.cpp b/3c_disasm/instr/movt.cpp
new file mode 100644 (file)
index 0000000..416812a
--- /dev/null
@@ -0,0 +1,78 @@
+#include "../Iinstr.hpp"
+
+class Cmovt : public Iinstr {
+       private:
+               bool m_type;
+       public:
+               Cmovt();
+               void evalInstr();
+               void execInstr();
+               std::string toString();
+               Iinstr* getNew();
+};
+
+/**
+ * Name:      create_instruction
+ * Purpose:   if compiled as shared library, this functions creates the 
+              instruction object
+
+ * Returns:   pointer to instruction object
+ */
+extern "C" Iinstr* create_instruction() {
+    return new Cmovt();
+}
+
+Iinstr* Cmovt::getNew() {
+       return new Cmovt();
+}
+
+/**
+ * Name:      destroy_instruction
+ * Purpose:   if compiled as shared library, this functions destoys the 
+              instruction object
+
+ * Parameter: IInstruction - the instruction object to delete
+ */
+extern "C" void destroy_instruction(Iinstr* p) {
+    delete p;
+}
+
+Cmovt::Cmovt() : m_type(0)
+{
+       opcode = B5(01101);
+       name = "movt";
+}
+
+void Cmovt::evalInstr()
+{
+       this->m_type = argbits[18];
+       if(this->m_type) {
+               name = "movpt";
+       }
+       else {
+               name = "movst";
+       }
+       
+       argbits >>= 19;
+       m_rd = this->getRegister(argbits);
+}
+
+void Cmovt::execInstr()
+{
+       //cout << "should exec " << this->toString() << endl;
+       CDat val = this->m_cpu->getRegister(this->m_rd);
+       if(this->m_type) {
+               this->m_cpu->setFlags(val);
+       }
+       else {
+               this->m_cpu->setStack(val);
+       }
+}
+
+std::string Cmovt::toString()
+{
+       stringstream op;
+       op << this->getName();
+       op << " r" << m_rd;
+       return op.str();
+}