5 #include <boost/dynamic_bitset.hpp>
18 /* concept from https://groups.google.com/group/comp.arch.embedded/msg/9d430b6d3da12c8f */
19 #define to_HEX__(x) 0x##x##LU
21 #define to_B5__(x) ((x & 0x0000FUL) ? 1 : 0) \
22 +((x & 0x000F0UL) ? 2 : 0) \
23 +((x & 0x00F00UL) ? 4 : 0) \
24 +((x & 0x0F000UL) ? 8 : 0) \
25 +((x & 0xF0000UL) ? 16 : 0)
27 #define B5(x) ((unsigned char)to_B5__(to_HEX__(x)))
31 using namespace boost;
54 short opcode, clockcount;
56 short m_ra, m_rb, m_rd;
57 bool m_c, m_d, m_hl, m_f, m_s;
60 boost::dynamic_bitset<> argbits;
62 Iinstr() : opcode(0), clockcount(1), name(""), m_ra(0), m_rb(0), m_rd(0), m_c(0), m_d(0), m_hl(0), m_f(0), m_s(0), m_imm(0), m_cond(ALWAYS), argbits(32), hexdump(0) {}
64 CDat generate16ImmFill(const CDat value) const {
66 if(m_hl == true && m_f == true) {
70 else if(m_hl == true && m_f == false) {
74 else if(m_hl == false && m_f == true) {
84 CDat generate16ImmSign(const CDat value) const {
89 else if(m_s == true && (i & 0x8000) != 0) {
96 CDat generate12ImmSign(const CDat value) const {
98 if(m_s == true && (i & 0x0800) != 0) {
105 CDat generate15ImmSign(const CDat value) const {
107 if(m_s == true && (i & 0x4000) != 0) {
116 int getRegister(boost::dynamic_bitset<> bits) {
118 return bits.to_ulong();
122 static disasm* m_disasm;
126 static void setCPU(CCpu* cpu) { m_cpu = cpu; }
127 static void setDisasm(disasm* dasm) { m_disasm = dasm; }
130 virtual short getOpcode() { return this->opcode; }
131 virtual std::string getName() { return this->name; }
132 virtual void loadBits(boost::dynamic_bitset<> bits) { argbits = bits; this->constructHex(); }
133 virtual void evalInstr() = 0;
134 virtual void execInstr() = 0;
135 virtual std::string toString() = 0;
136 virtual Iinstr* getNew() = 0;
138 unsigned long toNum() { return this->hexdump; }
140 short getCondition() {
144 short getClockCount() {
148 void decodeCondition(short condition) {
149 if(condition >= 0 && condition <= 15) {
153 throw std::string("Invalid Condition!");
161 hexdump = this->m_cond;
163 hexdump += this->opcode;
165 hexdump += this->argbits.to_ulong();
168 std::string getConditionFlag()
221 cerr << "What did you do? more than 16 values in 5 bits?!" << endl;