Skip to content

Commit

Permalink
Add automatic hardware labels to disassembler
Browse files Browse the repository at this point in the history
  • Loading branch information
drhelius committed Jan 20, 2025
1 parent c2b33bd commit 995d557
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 6 deletions.
2 changes: 2 additions & 0 deletions platforms/shared/desktop/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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);

Expand Down
1 change: 1 addition & 0 deletions platforms/shared/desktop/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand Down
35 changes: 35 additions & 0 deletions platforms/shared/desktop/gui_debug_constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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 */
51 changes: 45 additions & 6 deletions platforms/shared/desktop/gui_debug_disassembler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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<HuC6280::GG_Breakpoint>* breakpoints = emu_get_core()->GetHuC6280()->GetBreakpoints();

Expand Down Expand Up @@ -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;
}
}
Expand All @@ -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;
}

Expand All @@ -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);
Expand Down Expand Up @@ -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();

Expand Down

0 comments on commit 995d557

Please sign in to comment.