From abdece7737c272dc3f1e771fd18256b4d6da8bb9 Mon Sep 17 00:00:00 2001 From: James Larrowe Date: Sat, 30 May 2020 16:35:07 -0400 Subject: [PATCH] add debugger command to enable and disable --- Core/debugger.c | 18 ++++++++++++++++++ Core/gb.h | 2 +- Core/sm83_cpu.c | 6 ++++-- 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/Core/debugger.c b/Core/debugger.c index a46de86..ed498c9 100644 --- a/Core/debugger.c +++ b/Core/debugger.c @@ -832,6 +832,23 @@ static bool registers(GB_gameboy_t *gb, char *arguments, char *modifiers, const return true; } +/* Enable or disable software breakpoints */ +static bool softbreak(GB_gameboy_t *gb, char *arguments, char *modifiers, const debugger_command_t *command) +{ + NO_MODIFIERS + if (strcmp(lstrip(arguments), "on") == 0) { + gb->has_software_breakpoints = true; + } + else if(strcmp(lstrip(arguments), "off") == 0) { + gb->has_software_breakpoints = false; + } + else { + print_usage(gb, command); + } + + return true; +} + /* Find the index of the closest breakpoint equal or greater to addr */ static uint16_t find_breakpoint(GB_gameboy_t *gb, value_t addr) { @@ -1780,6 +1797,7 @@ static const debugger_command_t commands[] = { "a more (c)ompact one, or a one-(l)iner", "", "(f|c|l)"}, {"lcd", 3, lcd, "Displays information about the current state of the LCD controller"}, {"palettes", 3, palettes, "Displays the current CGB palettes"}, + {"softbreak", 2, softbreak, "Enables or disables software breakpoints", "(on|off)"}, {"breakpoint", 1, breakpoint, "Add a new breakpoint at the specified address/expression" HELP_NEWLINE "Can also modify the condition of existing breakpoints." HELP_NEWLINE "If the j modifier is used, the breakpoint will occur just before" HELP_NEWLINE diff --git a/Core/gb.h b/Core/gb.h index 97a8069..1445a68 100644 --- a/Core/gb.h +++ b/Core/gb.h @@ -601,7 +601,7 @@ struct GB_gameboy_internal_s { /* Breakpoints */ uint16_t n_breakpoints; struct GB_breakpoint_s *breakpoints; - bool has_jump_to_breakpoints; + bool has_jump_to_breakpoints, has_software_breakpoints; void *nontrivial_jump_state; bool non_trivial_jump_breakpoint_occured; diff --git a/Core/sm83_cpu.c b/Core/sm83_cpu.c index 9dbc90f..b337b36 100644 --- a/Core/sm83_cpu.c +++ b/Core/sm83_cpu.c @@ -790,10 +790,12 @@ LD_X_Y(l,b) LD_X_Y(l,c) LD_X_Y(l,d) LD_X_Y(l,e) LD_X_Y(l,h) LD_X_DHL LD_DHL_Y(b) LD_DHL_Y(c) LD_DHL_Y(d) LD_DHL_Y(e) LD_DHL_Y(h) LD_DHL_Y(l) LD_DHL_Y(a) LD_X_Y(a,b) LD_X_Y(a,c) LD_X_Y(a,d) LD_X_Y(a,e) LD_X_Y(a,h) LD_X_Y(a,l) LD_X_DHL(a) -// simply fire the debugger +// fire the debugger if software breakpoints are enabled static void ld_b_b(GB_gameboy_t *gb, uint8_t opcode) { - GB_debugger_break(gb); + if(gb->has_software_breakpoints) { + GB_debugger_break(gb); + } } static void add_a_r(GB_gameboy_t *gb, uint8_t opcode)