Little disasm improvements
authorslack <slack@ommadawn.(none)>
Sun, 22 Jun 2008 14:50:06 +0000 (16:50 +0200)
committerslack <slack@ommadawn.(none)>
Sun, 22 Jun 2008 14:50:06 +0000 (16:50 +0200)
gbcore.cc
gbcore.h
tests/test_core.cc

index 12298547dfb184e37633367a90b30387c32c5f5b..292539320768a898f823859fc4237f59307dedab 100644 (file)
--- a/gbcore.cc
+++ b/gbcore.cc
@@ -949,8 +949,29 @@ GameBoy::run_status GameBoy::run()
        return status;
 }
 
+std::string GameBoy::get_port_name(int port) const
+{
+       std::string port_name;
+
+       switch (port)
+       {
+               case 0x40: port_name = "LCDC"; break;
+               case 0x41: port_name = "STAT"; break;
+               case 0x42: port_name = "SCY "; break; 
+               case 0x43: port_name = "SCX "; break; 
+               case 0x44: port_name = "LY  "; break; 
+               case 0x45: port_name = "LYC "; break; 
+               case 0x4A: port_name = "WY  "; break; 
+               case 0x4B: port_name = "WX  "; break; 
+               case 0x47: port_name = "BGP "; break; 
+               case 0x48: port_name = "OBP0"; break; 
+               case 0x49: port_name = "OBP1"; break; 
+               case 0x46: port_name = "DMA "; break; 
+       }
+       return port_name;
+}
 
-std::string GameBoy::status_string()
+std::string GameBoy::status_string() const
 {
        std::string disassembled_instruction;
        int length;
@@ -972,7 +993,7 @@ std::string GameBoy::status_string()
 }
 
 #include "disasm.h"
-void GameBoy::disassemble_opcode(u16 addr, std::string &instruction, int &length)
+void GameBoy::disassemble_opcode(u16 addr, std::string &instruction, int &length) const
 {
        int opcode;
        u16 PC = addr;
@@ -1027,15 +1048,19 @@ void GameBoy::disassemble_opcode(u16 addr, std::string &instruction, int &length
 
                // LDH (n), A
                case 0xE0: {
-                       result << "LD (IO_BASE + 0x" << 
-                                       std::setw(2) << int(memory.read(PC++)) << "), A";
+                       int port = int(memory.read(PC++));
+                       
+                       result << "LD (0xFF" << 
+                                       std::setw(2) << port << "), A" << "\t[" << get_port_name(port) << "]";
                        break;
                }
                // LDH A, (n)
-               case 0xF0:
-                       result << "LD A, (IO_BASE + 0x" << 
-                                       std::setw(2) << int(memory.read(PC++)) << ")";
+               case 0xF0: {
+                       int port = int(memory.read(PC++));
+                       result << "LD A, (0xFF" << 
+                                       std::setw(2) << port << ")" << "\t[" << get_port_name(port) << "]";
                        break;
+               }
 
                dis_reg16_inm(0x01, "LD", BC)
                dis_reg16_inm(0x11, "LD", DE)
index 04caef31a62da82b6337adc9c9a543b0c451d621..c5a6fccc5885ba5a548b4d6cd2af1247d014a316 100644 (file)
--- a/gbcore.h
+++ b/gbcore.h
@@ -80,7 +80,7 @@ class GameBoy
 
        void set_flag  (Flag f) { regs.flags |= f; }
        void reset_flag(Flag f) { regs.flags &= (~f); }
-       bool check_flag(Flag f) { return ((regs.flags & f) != 0); }
+       bool check_flag(Flag f) const { return ((regs.flags & f) != 0); }
 
        enum run_status 
        {
@@ -98,8 +98,9 @@ class GameBoy
        run_status run();
 
        // debug methods
-       void disassemble_opcode(u16 addr, std::string &instruction, int &length);
-       std::string status_string();
+       void disassemble_opcode(u16 addr, std::string &instruction, int &length) const;
+       std::string status_string() const;
+       std::string get_port_name(int port) const;
 
 };
 
index a15dfe3e418c1638237860ed5ce07b3457950a62..2d31c895ac4bb47348e0544f697928863c5c3ffa 100644 (file)
@@ -64,11 +64,11 @@ int main(int argc, char **argv)
                        {
                                case 0:
                                        start = gb.regs.PC;
-                                       end = start + 256;
+                                       end = start + 30;
                                        break;
                                case 1:
                                        start = atoi(arguments[0].c_str());
-                                       end = start + 256;
+                                       end = start + 30;
                                        break;
                                case 2:
                                default:
@@ -84,7 +84,12 @@ int main(int argc, char **argv)
                                int len;
                                gb.disassemble_opcode(pos, ins, len);
                                cout << "0x" << std::hex << std::setw(4) << std::setfill('0') << 
-                                               pos << "\t" << ins << endl;
+                                               pos << "\t";
+                               for (int i=0; i<len; i++)
+                                       cout << std::setw(2) << int(gb.memory.read(pos+i)) << " ";
+                       
+                               if (len < 3) cout << "\t";
+                               cout << "\t" << ins << endl;
                                pos += len;
                        }