sim: new instructions, bugfix in others
authorMartin Perner <martin@perner.cc>
Sun, 31 Oct 2010 22:27:40 +0000 (23:27 +0100)
committerMartin Perner <martin@perner.cc>
Sun, 31 Oct 2010 22:32:48 +0000 (23:32 +0100)
not tested!

3c_disasm/instr/add.cpp
3c_disasm/instr/addi.cpp
3c_disasm/instr/and.cpp [new file with mode: 0644]
3c_disasm/instr/andx.cpp [new file with mode: 0644]
3c_disasm/instr/or.cpp [new file with mode: 0644]
3c_disasm/instr/orx.cpp [new file with mode: 0644]
3c_disasm/instr/sub.cpp [new file with mode: 0644]
3c_disasm/instr/subi.cpp
3c_disasm/instr/xor.cpp [new file with mode: 0644]
3c_disasm/instr/xorx.cpp [new file with mode: 0644]

index 413193236479a821769d65d8f5178068e50722f1..b5cd4f9fb6d90662941c78b3d956a2ff7f81cd09 100644 (file)
@@ -63,7 +63,9 @@ void Cadd::execInstr()
        CDat rb = this->m_cpu->getRegister(m_rb);
        CDatd val = ra + rb;
        this->m_cpu->setRegister(m_rd, val);
-       this->m_cpu->updateFlags(val, ra, rb);
+       if(!this->m_d) {
+               this->m_cpu->updateFlags(val, ra, rb);
+       }
 }
 
 std::string Cadd::toString()
index 9b9b44fae264787f08ab59a9a4c21565eaee26a6..5aab94c3933ae4d0f6dcb37aa9ff185105461bf1 100644 (file)
@@ -66,7 +66,9 @@ void Caddi::execInstr()
        CDat ra = this->m_cpu->getRegister(m_ra);
        CDatd reg = ra + this->m_imm;
        this->m_cpu->setRegister(m_rd, reg);
-       this->m_cpu->updateFlags(reg, ra, this->m_imm);
+       if(!this->m_d) {
+               this->m_cpu->updateFlags(reg, ra, this->m_imm);
+       }
 }
 
 std::string Caddi::toString()
diff --git a/3c_disasm/instr/and.cpp b/3c_disasm/instr/and.cpp
new file mode 100644 (file)
index 0000000..b1aae59
--- /dev/null
@@ -0,0 +1,80 @@
+#include "../Iinstr.hpp"
+
+class Cand : public Iinstr {
+       public:
+               Cand();
+               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 Cand();
+}
+
+Iinstr* Cand::getNew() {
+       return new Cand();
+}
+
+/**
+ * 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;
+}
+
+Cand::Cand()
+{
+       opcode = B5(00100);
+       name = "and";
+}
+
+void Cand::evalInstr()
+{
+       this->m_d = argbits[0];
+       
+       argbits >>= 11;
+       m_rb = this->getRegister(argbits);
+
+       argbits >>= 4;
+       m_ra = this->getRegister(argbits);
+
+       argbits >>= 4;
+       m_rd = this->getRegister(argbits);
+}
+
+void Cand::execInstr()
+{
+       //cout << "should exec " << this->toString() << endl;
+       CDat ra = this->m_cpu->getRegister(m_ra);
+       CDat rb = this->m_cpu->getRegister(m_rb);
+       CDat val = ra & rb;
+       this->m_cpu->setRegister(m_rd, val);
+       if(!this->m_d) {
+               this->m_cpu->updateFlags(val);
+       }
+}
+
+std::string Cand::toString()
+{
+       stringstream op;
+       op << this->getName();
+
+       if(m_d) op << 'D';
+       if(m_c) op << 'C';
+
+       op << " r" << m_rd << ", r" << m_ra << ", r" << m_rb;
+       return op.str();
+}
diff --git a/3c_disasm/instr/andx.cpp b/3c_disasm/instr/andx.cpp
new file mode 100644 (file)
index 0000000..fed2237
--- /dev/null
@@ -0,0 +1,84 @@
+#include "../Iinstr.hpp"
+
+
+class Candx : public Iinstr {
+       public:
+               Candx();
+               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 Candx();
+}
+
+Iinstr* Candx::getNew()
+{
+    return new Candx();
+}
+/**
+ * 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;
+}
+
+Candx::Candx()
+{
+       opcode = B5(00101);
+       name = "andx";
+}
+
+void Candx::evalInstr()
+{
+       this->m_d = argbits[0];
+       this->m_f = argbits[1];
+       this->m_hl = argbits[2];
+
+       argbits >>= 3;
+       dynamic_bitset<> immb = argbits;
+       immb.resize(16);
+       this->m_imm = this->generate16ImmSign(immb.to_ulong());
+
+       argbits >>= 16;
+       m_rd = this->getRegister(argbits);
+}
+
+void Candx::execInstr()
+{
+       CDat val = this->m_cpu->getRegister(this->m_rd);
+       CDat imm = generate16ImmFill(this->m_imm);
+       val &= imm;
+
+       this->m_cpu->setRegister(this->m_rd, val);
+       if(!this->m_d) {
+               this->m_cpu->updateFlags(val);
+       }
+}
+
+std::string Candx::toString()
+{
+       stringstream op;
+       op << this->getName();
+
+       if(m_hl) op << 'H';
+       if(m_f) op << 'F';
+       if(m_d) op << 'D';
+
+       op << this->getConditionFlag() << " r" << m_rd << ", " << m_imm;
+
+       return op.str();
+}
diff --git a/3c_disasm/instr/or.cpp b/3c_disasm/instr/or.cpp
new file mode 100644 (file)
index 0000000..e81b41d
--- /dev/null
@@ -0,0 +1,80 @@
+#include "../Iinstr.hpp"
+
+class Cor : public Iinstr {
+       public:
+               Cor();
+               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 Cor();
+}
+
+Iinstr* Cor::getNew() {
+       return new Cor();
+}
+
+/**
+ * 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;
+}
+
+Cor::Cor()
+{
+       opcode = B5(00110);
+       name = "or";
+}
+
+void Cor::evalInstr()
+{
+       this->m_d = argbits[0];
+       
+       argbits >>= 11;
+       m_rb = this->getRegister(argbits);
+
+       argbits >>= 4;
+       m_ra = this->getRegister(argbits);
+
+       argbits >>= 4;
+       m_rd = this->getRegister(argbits);
+}
+
+void Cor::execInstr()
+{
+       //cout << "should exec " << this->toString() << endl;
+       CDat ra = this->m_cpu->getRegister(m_ra);
+       CDat rb = this->m_cpu->getRegister(m_rb);
+       CDat val = ra | rb;
+       this->m_cpu->setRegister(m_rd, val);
+       if(!this->m_d) {
+               this->m_cpu->updateFlags(val);
+       }
+}
+
+std::string Cor::toString()
+{
+       stringstream op;
+       op << this->getName();
+
+       if(m_d) op << 'D';
+       if(m_c) op << 'C';
+
+       op << " r" << m_rd << ", r" << m_ra << ", r" << m_rb;
+       return op.str();
+}
diff --git a/3c_disasm/instr/orx.cpp b/3c_disasm/instr/orx.cpp
new file mode 100644 (file)
index 0000000..95e32ea
--- /dev/null
@@ -0,0 +1,84 @@
+#include "../Iinstr.hpp"
+
+
+class Corx : public Iinstr {
+       public:
+               Corx();
+               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 Corx();
+}
+
+Iinstr* Corx::getNew()
+{
+    return new Corx();
+}
+/**
+ * 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;
+}
+
+Corx::Corx()
+{
+       opcode = B5(00111);
+       name = "orx";
+}
+
+void Corx::evalInstr()
+{
+       this->m_d = argbits[0];
+       this->m_f = argbits[1];
+       this->m_hl = argbits[2];
+
+       argbits >>= 3;
+       dynamic_bitset<> immb = argbits;
+       immb.resize(16);
+       this->m_imm = this->generate16ImmSign(immb.to_ulong());
+
+       argbits >>= 16;
+       m_rd = this->getRegister(argbits);
+}
+
+void Corx::execInstr()
+{
+       CDat val = this->m_cpu->getRegister(this->m_rd);
+       CDat imm = generate16ImmFill(this->m_imm);
+       val |= imm;
+
+       this->m_cpu->setRegister(this->m_rd, val);
+       if(!this->m_d) {
+               this->m_cpu->updateFlags(val);
+       }
+}
+
+std::string Corx::toString()
+{
+       stringstream op;
+       op << this->getName();
+
+       if(m_hl) op << 'H';
+       if(m_f) op << 'F';
+       if(m_d) op << 'D';
+
+       op << this->getConditionFlag() << " r" << m_rd << ", " << m_imm;
+
+       return op.str();
+}
diff --git a/3c_disasm/instr/sub.cpp b/3c_disasm/instr/sub.cpp
new file mode 100644 (file)
index 0000000..d174735
--- /dev/null
@@ -0,0 +1,81 @@
+#include "../Iinstr.hpp"
+
+class Csub : public Iinstr {
+       public:
+               Csub();
+               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 Csub();
+}
+
+Iinstr* Csub::getNew() {
+       return new Csub();
+}
+
+/**
+ * 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;
+}
+
+Csub::Csub()
+{
+       opcode = B5(00001);
+       name = "sub";
+}
+
+void Csub::evalInstr()
+{
+       this->m_d = argbits[0];
+       this->m_c = argbits[1];
+       
+       argbits >>= 11;
+       m_rb = this->getRegister(argbits);
+
+       argbits >>= 4;
+       m_ra = this->getRegister(argbits);
+
+       argbits >>= 4;
+       m_rd = this->getRegister(argbits);
+}
+
+void Csub::execInstr()
+{
+       //cout << "should exec " << this->toString() << endl;
+       CDat ra = this->m_cpu->getRegister(m_ra);
+       CDat rb = this->m_cpu->getRegister(m_rb);
+       CDatd val = ra - rb;
+       this->m_cpu->setRegister(m_rd, val);
+       if(!this->m_d) {
+               this->m_cpu->updateFlags(val, ra, rb);
+       }
+}
+
+std::string Csub::toString()
+{
+       stringstream op;
+       op << this->getName();
+
+       if(m_d) op << 'D';
+       if(m_c) op << 'C';
+
+       op << " r" << m_rd << ", r" << m_ra << ", r" << m_rb;
+       return op.str();
+}
index 69ba7e1029526eb08dcfceb9f0ca05479ebf7416..701599c3323c84108c848c3ae34cb3c19ebc2960 100644 (file)
@@ -65,7 +65,9 @@ void Csubi::execInstr()
        CDat ra = this->m_cpu->getRegister(m_ra);
        CDatd reg = ra - this->m_imm;
        this->m_cpu->setRegister(m_rd, reg);
-       this->m_cpu->updateFlags(reg, ra, this->m_imm);
+       if(!this->m_d) {
+               this->m_cpu->updateFlags(reg, ra, this->m_imm);
+       }
 }
 
 std::string Csubi::toString()
diff --git a/3c_disasm/instr/xor.cpp b/3c_disasm/instr/xor.cpp
new file mode 100644 (file)
index 0000000..900dbc3
--- /dev/null
@@ -0,0 +1,80 @@
+#include "../Iinstr.hpp"
+
+class Cxor : public Iinstr {
+       public:
+               Cxor();
+               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 Cxor();
+}
+
+Iinstr* Cxor::getNew() {
+       return new Cxor();
+}
+
+/**
+ * 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;
+}
+
+Cxor::Cxor()
+{
+       opcode = B5(01000);
+       name = "or";
+}
+
+void Cxor::evalInstr()
+{
+       this->m_d = argbits[0];
+       
+       argbits >>= 11;
+       m_rb = this->getRegister(argbits);
+
+       argbits >>= 4;
+       m_ra = this->getRegister(argbits);
+
+       argbits >>= 4;
+       m_rd = this->getRegister(argbits);
+}
+
+void Cxor::execInstr()
+{
+       //cout << "should exec " << this->toString() << endl;
+       CDat ra = this->m_cpu->getRegister(m_ra);
+       CDat rb = this->m_cpu->getRegister(m_rb);
+       CDat val = ra ^ rb;
+       this->m_cpu->setRegister(m_rd, val);
+       if(!this->m_d) {
+               this->m_cpu->updateFlags(val);
+       }
+}
+
+std::string Cxor::toString()
+{
+       stringstream op;
+       op << this->getName();
+
+       if(m_d) op << 'D';
+       if(m_c) op << 'C';
+
+       op << " r" << m_rd << ", r" << m_ra << ", r" << m_rb;
+       return op.str();
+}
diff --git a/3c_disasm/instr/xorx.cpp b/3c_disasm/instr/xorx.cpp
new file mode 100644 (file)
index 0000000..ca940ae
--- /dev/null
@@ -0,0 +1,84 @@
+#include "../Iinstr.hpp"
+
+
+class Cxorx : public Iinstr {
+       public:
+               Cxorx();
+               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 Cxorx();
+}
+
+Iinstr* Cxorx::getNew()
+{
+    return new Cxorx();
+}
+/**
+ * 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;
+}
+
+Cxorx::Cxorx()
+{
+       opcode = B5(01001);
+       name = "xorx";
+}
+
+void Cxorx::evalInstr()
+{
+       this->m_d = argbits[0];
+       this->m_f = argbits[1];
+       this->m_hl = argbits[2];
+
+       argbits >>= 3;
+       dynamic_bitset<> immb = argbits;
+       immb.resize(16);
+       this->m_imm = this->generate16ImmSign(immb.to_ulong());
+
+       argbits >>= 16;
+       m_rd = this->getRegister(argbits);
+}
+
+void Cxorx::execInstr()
+{
+       CDat val = this->m_cpu->getRegister(this->m_rd);
+       CDat imm = generate16ImmFill(this->m_imm);
+       val ^= imm;
+
+       this->m_cpu->setRegister(this->m_rd, val);
+       if(!this->m_d) {
+               this->m_cpu->updateFlags(val);
+       }
+}
+
+std::string Cxorx::toString()
+{
+       stringstream op;
+       op << this->getName();
+
+       if(m_hl) op << 'H';
+       if(m_f) op << 'F';
+       if(m_d) op << 'D';
+
+       op << this->getConditionFlag() << " r" << m_rd << ", " << m_imm;
+
+       return op.str();
+}