sim: new instructions, bugfix in others
[calu.git] / 3c_disasm / instr / xorx.cpp
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();
+}