5 #include <boost/dynamic_bitset.hpp>
14 /* concept from https://groups.google.com/group/comp.arch.embedded/msg/9d430b6d3da12c8f */
15 #define to_HEX__(x) 0x##x##LU
17 #define to_B5__(x) ((x & 0x0000FUL) ? 1 : 0) \
18 +((x & 0x000F0UL) ? 2 : 0) \
19 +((x & 0x00F00UL) ? 4 : 0) \
20 +((x & 0x0F000UL) ? 8 : 0) \
21 +((x & 0xF0000UL) ? 16 : 0)
23 #define B5(x) ((unsigned char)to_B5__(to_HEX__(x)))
27 using namespace boost;
52 short m_ra, m_rb, m_rd;
53 bool m_c, m_d, m_hl, m_f, m_s;
56 boost::dynamic_bitset<> argbits;
57 Iinstr() : opcode(0), 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) {}
59 CDat generate16ImmFill(const CDat value) const {
61 if(m_hl == true && m_f == true) {
65 else if(m_hl == true && m_f == false) {
69 else if(m_hl == false && m_f == true) {
79 CDat generate16ImmSign(const CDat value) const {
84 else if(m_s == true && (i & 0x8000) != 0) {
91 CDat generate12ImmSign(const CDat value) const {
93 if(m_s == true && (i & 0x0800) != 0) {
100 CDat generate15ImmSign(const CDat value) const {
102 if(m_s == true && (i & 0x4000) != 0) {
111 int getRegister(boost::dynamic_bitset<> bits) {
113 return bits.to_ulong();
120 static void setCPU(CCpu* cpu) { m_cpu = cpu; }
123 virtual short getOpcode() { return this->opcode; }
124 virtual std::string getName() { return this->name; }
125 virtual void loadBits(boost::dynamic_bitset<> bits) { argbits = bits; }
126 virtual void evalInstr() = 0;
127 virtual void execInstr() = 0;
128 virtual std::string toString() = 0;
129 virtual Iinstr* getNew() = 0;
131 short getCondition() {
135 void decodeCondition(short condition) {
136 if(condition >= 0 && condition <= 15) {
140 throw std::string("Invalid Condition!");
146 std::string getConditionFlag()
199 cerr << "What did you do? more than 16 values in 5 bits?!" << endl;