From: slack Date: Sun, 22 Jun 2008 14:50:06 +0000 (+0200) Subject: Little disasm improvements X-Git-Tag: v0.1~49 X-Git-Url: http://slack.codemaniacs.com/git/?a=commitdiff_plain;h=e5ccedce2bfe9502900fff619c35e07f7e6f2cee;p=wenboi.git Little disasm improvements --- diff --git a/gbcore.cc b/gbcore.cc index 1229854..2925393 100644 --- 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) diff --git a/gbcore.h b/gbcore.h index 04caef3..c5a6fcc 100644 --- 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; }; diff --git a/tests/test_core.cc b/tests/test_core.cc index a15dfe3..2d31c89 100644 --- a/tests/test_core.cc +++ b/tests/test_core.cc @@ -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