6bc03410beaa53449263d06b99b7f05e5f9beb85
[calu.git] / 3c_disasm / instr / andx.cpp
1 #include "../Iinstr.hpp"
2
3
4 class Candx : public Iinstr {
5         public:
6                 Candx();
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 Candx();
22 }
23
24 Iinstr* Candx::getNew()
25 {
26     return new Candx();
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 Candx::Candx()
40 {
41         opcode = B5(00101);
42         name = "andx";
43 }
44
45 void Candx::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 Candx::execInstr()
61 {
62         CDat val = this->m_cpu->getRegister(this->m_rd);
63         CDat imm = generate16ImmFill(this->m_imm);
64         if(this->m_hl) {
65                 imm <<= 16;
66         }
67         val &= imm;
68
69         this->m_cpu->setRegister(this->m_rd, val);
70         if(!this->m_d) {
71                 this->m_cpu->updateFlags(val);
72         }
73 }
74
75 std::string Candx::toString()
76 {
77         stringstream op;
78         op << this->getName();
79
80         if(m_hl) op << 'H';
81         if(m_f) op << 'F';
82         if(m_d) op << 'D';
83
84         op << this->getConditionFlag() << " r" << m_rd << ", " << m_imm;
85
86         return op.str();
87 }