95e32ea635af27c21a02fe41eeb5250584086bb0
[calu.git] / 3c_disasm / instr / orx.cpp
1 #include "../Iinstr.hpp"
2
3
4 class Corx : public Iinstr {
5         public:
6                 Corx();
7                 void evalInstr();
8                 void execInstr();
9                 std::string toString();
10                 Iinstr* getNew();
11 };
12
13 /**
14  * Name:      create_instruction
15  * Purpose:   if compiled as shared library, this functions creates the 
16               instruction object
17
18  * Returns:   pointer to instruction object
19  */
20 extern "C" Iinstr* create_instruction() {
21     return new Corx();
22 }
23
24 Iinstr* Corx::getNew()
25 {
26     return new Corx();
27 }
28 /**
29  * Name:      destroy_instruction
30  * Purpose:   if compiled as shared library, this functions destoys the 
31               instruction object
32
33  * Parameter: IInstruction - the instruction object to delete
34  */
35 extern "C" void destroy_instruction(Iinstr* p) {
36     delete p;
37 }
38
39 Corx::Corx()
40 {
41         opcode = B5(00111);
42         name = "orx";
43 }
44
45 void Corx::evalInstr()
46 {
47         this->m_d = argbits[0];
48         this->m_f = argbits[1];
49         this->m_hl = argbits[2];
50
51         argbits >>= 3;
52         dynamic_bitset<> immb = argbits;
53         immb.resize(16);
54         this->m_imm = this->generate16ImmSign(immb.to_ulong());
55
56         argbits >>= 16;
57         m_rd = this->getRegister(argbits);
58 }
59
60 void Corx::execInstr()
61 {
62         CDat val = this->m_cpu->getRegister(this->m_rd);
63         CDat imm = generate16ImmFill(this->m_imm);
64         val |= imm;
65
66         this->m_cpu->setRegister(this->m_rd, val);
67         if(!this->m_d) {
68                 this->m_cpu->updateFlags(val);
69         }
70 }
71
72 std::string Corx::toString()
73 {
74         stringstream op;
75         op << this->getName();
76
77         if(m_hl) op << 'H';
78         if(m_f) op << 'F';
79         if(m_d) op << 'D';
80
81         op << this->getConditionFlag() << " r" << m_rd << ", " << m_imm;
82
83         return op.str();
84 }