From 995d557218cc8a009f40204581a8cfc3bbe9aece Mon Sep 17 00:00:00 2001 From: Ignacio Sanchez Gines <863613+drhelius@users.noreply.github.com> Date: Mon, 20 Jan 2025 19:55:32 +0100 Subject: [PATCH] Add automatic hardware labels to disassembler --- platforms/shared/desktop/config.cpp | 2 + platforms/shared/desktop/config.h | 1 + .../shared/desktop/gui_debug_constants.h | 35 +++++++++++++ .../shared/desktop/gui_debug_disassembler.cpp | 51 ++++++++++++++++--- 4 files changed, 83 insertions(+), 6 deletions(-) diff --git a/platforms/shared/desktop/config.cpp b/platforms/shared/desktop/config.cpp index 4351087..f138886 100644 --- a/platforms/shared/desktop/config.cpp +++ b/platforms/shared/desktop/config.cpp @@ -129,6 +129,7 @@ void config_read(void) config_debug.dis_show_bank = read_bool("Debug", "DisBank", true); config_debug.dis_show_auto_symbols = read_bool("Debug", "DisAutoSymbols", true); config_debug.dis_replace_symbols = read_bool("Debug", "DisReplaceSymbols", true); + config_debug.dis_replace_labels = read_bool("Debug", "DisReplaceLabels", true); config_debug.font_size = read_int("Debug", "FontSize", 0); config_debug.multi_viewport = read_bool("Debug", "MultiViewport", false); @@ -253,6 +254,7 @@ void config_write(void) write_bool("Debug", "DisBank", config_debug.dis_show_bank); write_bool("Debug", "DisAutoSymbols", config_debug.dis_show_auto_symbols); write_bool("Debug", "DisReplaceSymbols", config_debug.dis_replace_symbols); + write_bool("Debug", "DisReplaceLabels", config_debug.dis_replace_labels); write_int("Debug", "FontSize", config_debug.font_size); write_bool("Debug", "MultiViewport", config_debug.multi_viewport); diff --git a/platforms/shared/desktop/config.h b/platforms/shared/desktop/config.h index 96973af..6c71816 100644 --- a/platforms/shared/desktop/config.h +++ b/platforms/shared/desktop/config.h @@ -129,6 +129,7 @@ struct config_Debug bool dis_show_bank = true; bool dis_show_auto_symbols = true; bool dis_replace_symbols = true; + bool dis_replace_labels = true; int font_size = 0; bool multi_viewport = false; }; diff --git a/platforms/shared/desktop/gui_debug_constants.h b/platforms/shared/desktop/gui_debug_constants.h index a43e5bc..afb5978 100644 --- a/platforms/shared/desktop/gui_debug_constants.h +++ b/platforms/shared/desktop/gui_debug_constants.h @@ -21,6 +21,7 @@ #define GUI_DEBUG_CONSTANTS_H #include "imgui/imgui.h" +#include "../../../src/geargrafx.h" static const ImVec4 cyan = ImVec4(0.10f, 0.90f, 0.90f, 1.0f); static const ImVec4 dark_cyan = ImVec4(0.00f, 0.30f, 0.30f, 1.0f); @@ -44,4 +45,38 @@ static const ImVec4 mid_gray = ImVec4(0.40f, 0.40f, 0.40f, 1.0f); static const ImVec4 dark_gray = ImVec4(0.10f, 0.10f, 0.10f, 1.0f); static const ImVec4 black = ImVec4(0.00f, 0.00f, 0.00f, 1.0f); +struct stDebugLabel +{ + u16 address; + const char* label; +}; + +static const int k_debug_label_count = 23; +static const stDebugLabel k_debug_labels[k_debug_label_count] = +{ + { 0x0000, "VDC_ADDRESS_" }, + { 0x0002, "VDC_DATA_LO_" }, + { 0x0003, "VDC_DATA_HI_" }, + { 0x0400, "VCE_CONTROL_" }, + { 0x0402, "VCE_ADDR_LO_" }, + { 0x0403, "VCE_ADDR_HI_" }, + { 0x0404, "VCE_DATA_LO_" }, + { 0x0405, "VCE_DATA_HI_" }, + { 0x0800, "PSG_CH_SELECT_" }, + { 0x0801, "PSG_MAIN_VOL_" }, + { 0x0802, "PSG_FREQ_LO_" }, + { 0x0803, "PSG_FREQ_HI_" }, + { 0x0804, "PSG_CH_CTRL_" }, + { 0x0805, "PSG_CH_VOL_" }, + { 0x0806, "PSG_CH_DATA_" }, + { 0x0807, "PSG_NOISE_" }, + { 0x0808, "PSG_LFO_FREQ_" }, + { 0x0809, "PSG_LFO_CTRL_" }, + { 0x0C00, "TIMER_COUNTER_" }, + { 0x0C01, "TIMER_CONTROL_" }, + { 0x1000, "JOYPAD_" }, + { 0x1402, "IRQ_DISABLE_" }, + { 0x1403, "IRQ_STATUS_" } +}; + #endif /* GUI_DEBUG_CONSTANTS_H */ \ No newline at end of file diff --git a/platforms/shared/desktop/gui_debug_disassembler.cpp b/platforms/shared/desktop/gui_debug_disassembler.cpp index e528029..fdf8c36 100644 --- a/platforms/shared/desktop/gui_debug_disassembler.cpp +++ b/platforms/shared/desktop/gui_debug_disassembler.cpp @@ -42,7 +42,7 @@ struct DisassemblerLine u16 address; bool is_breakpoint; Memory::GG_Disassembler_Record* record; - char name_with_symbol[64]; + char name_enhanced[64]; int name_real_length; DebugSymbol* symbol; }; @@ -83,6 +83,7 @@ static void add_breakpoint(int type); static void request_goto_address(u16 addr); static bool is_return_instruction(u8 opcode); static void replace_symbols(DisassemblerLine* line, const char* color); +static void replace_labels(DisassemblerLine* line, const char* color, const char* original_color); static void draw_instruction_name(DisassemblerLine* line, bool is_pc); static void disassembler_menu(void); static void add_bookmark_popup(void); @@ -553,7 +554,7 @@ static void prepare_drawable_lines(void) line.symbol = NULL; line.is_breakpoint = false; line.record = record; - snprintf(line.name_with_symbol, 64, "%s", line.record->name); + snprintf(line.name_enhanced, 64, "%s", line.record->name); std::vector* breakpoints = emu_get_core()->GetHuC6280()->GetBreakpoints(); @@ -946,7 +947,7 @@ static void replace_symbols(DisassemblerLine* line, const char* color) if (pos != std::string::npos) { instr.replace(pos, 5, color + symbol); - snprintf(line->name_with_symbol, 64, "%s", instr.c_str()); + snprintf(line->name_enhanced, 64, "%s", instr.c_str()); symbol_found = true; } } @@ -966,40 +967,73 @@ static void replace_symbols(DisassemblerLine* line, const char* color) if (pos != std::string::npos) { instr.replace(pos, 5, color + symbol); - snprintf(line->name_with_symbol, 64, "%s", instr.c_str()); + snprintf(line->name_enhanced, 64, "%s", instr.c_str()); } } } +static void replace_labels(DisassemblerLine* line, const char* color, const char* original_color) +{ + u16 hardware_offset = 0x0000; + + for (int i = 0; i < 8; i++) + { + if (emu_get_core()->GetMemory()->GetMpr(i) == 0xFF) + { + hardware_offset = i * 0x2000; + break; + } + } + + for (int i = 0; i < k_debug_label_count; i++) + { + std::string instr = line->record->name; + std::string label = k_debug_labels[i].label; + char label_address[6]; + snprintf(label_address, 6, "$%04X", k_debug_labels[i].address + hardware_offset); + size_t pos = instr.find(label_address); + if (pos != std::string::npos) + { + instr.replace(pos, 5, color + label + label_address + original_color); + snprintf(line->name_enhanced, 64, "%s", instr.c_str()); + } + } +} + static const char* const c_yellow = "{FFE60C}"; static const char* const c_white = "{FFFFFF}"; static const char* const c_red = "{FA2573}"; static const char* const c_green = "{1AE51A}"; static const char* const c_blue = "{3466FF}"; +static const char* const c_orange = "{FD9820}"; static void draw_instruction_name(DisassemblerLine* line, bool is_pc) { const char* color; const char* symbol_color; + const char* label_color; const char* extra_color; if (is_pc) { color = c_yellow; symbol_color = c_yellow; + label_color = c_yellow; extra_color = c_yellow; } else if (line->is_breakpoint) { color = c_red; symbol_color = c_red; + label_color = c_red; extra_color = c_red; } else { color = c_white; symbol_color = c_green; + label_color = c_orange; extra_color = c_blue; } @@ -1008,8 +1042,12 @@ static void draw_instruction_name(DisassemblerLine* line, bool is_pc) replace_symbols(line, symbol_color); } - const char* name = config_debug.dis_replace_symbols ? line->name_with_symbol : line->record->name; - std::string instr = name; + if (config_debug.dis_replace_labels) + { + replace_labels(line, label_color, color); + } + + std::string instr = line->name_enhanced; size_t pos = instr.find("{}"); if (pos != std::string::npos) instr.replace(pos, 2, extra_color); @@ -1183,6 +1221,7 @@ static void disassembler_menu(void) { ImGui::MenuItem("Automatic Symbols", NULL, &config_debug.dis_show_auto_symbols); ImGui::MenuItem("Replace Address With Symbol", NULL, &config_debug.dis_replace_symbols); + ImGui::MenuItem("Replace Address With Label", NULL, &config_debug.dis_replace_labels); ImGui::Separator();