2 #include <boost/dynamic_bitset.hpp>
9 /* concept from https://groups.google.com/group/comp.arch.embedded/msg/9d430b6d3da12c8f */
10 #define to_HEX__(x) 0x##x##LU
12 #define to_B5__(x) ((x & 0x0000FUL) ? 1 : 0) \
13 +((x & 0x000F0UL) ? 2 : 0) \
14 +((x & 0x00F00UL) ? 4 : 0) \
15 +((x & 0x0F000UL) ? 8 : 0) \
16 +((x & 0xF0000UL) ? 16 : 0)
18 #define B5(x) ((unsigned char)to_B5__(to_HEX__(x)))
21 using namespace boost;
46 short m_ra, m_rb, m_rd;
47 bool m_c, m_d, m_hl, m_f, m_s;
50 boost::dynamic_bitset<> argbits;
51 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) {}
53 int generate16ImmFill(const int value) {
55 if(m_hl == true && m_f == true) {
59 else if(m_hl == true && m_f == false) {
63 else if(m_hl == false && m_f == true) {
73 int generate16ImmSign(const int value) {
78 else if(m_s == true && (i & 0x8000) != 0) {
85 int generate12ImmSign(const int value) {
87 if(m_s == true && (i & 0x0800) != 0) {
94 int generate15ImmSign(const int value) {
96 if(m_s == true && (i & 0x4000) != 0) {
105 int getRegister(boost::dynamic_bitset<> bits) {
107 return bits.to_ulong();
112 virtual short getOpcode() { return this->opcode; }
113 virtual std::string getName() { return this->name; }
114 virtual void loadBits(boost::dynamic_bitset<> bits) { argbits = bits; }
115 virtual void evalInstr() = 0;
116 virtual void execInstr() = 0;
117 virtual std::string toString() = 0;
119 void decodeCondition(short condition) {
120 if(condition >= 0 && condition <= 15) {
124 throw std::string("Invalid Condition!");
129 std::string getConditionFlag()
182 cerr << "What did you do? more than 16 values in 5 bits?!" << endl;