From f105f2801791f9cafe309adaa407e3c22b2ac3c7 Mon Sep 17 00:00:00 2001 From: James Larrowe Date: Sat, 30 May 2020 15:54:51 -0400 Subject: [PATCH 1/5] Add ld b,b breakpoint Signed-off-by: James Larrowe --- Core/sm83_cpu.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/Core/sm83_cpu.c b/Core/sm83_cpu.c index 13f05df..9dbc90f 100644 --- a/Core/sm83_cpu.c +++ b/Core/sm83_cpu.c @@ -1,6 +1,7 @@ #include #include #include +#include "debugger.h" #include "gb.h" @@ -789,6 +790,11 @@ 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 +static void ld_b_b(GB_gameboy_t *gb, uint8_t opcode) +{ + GB_debugger_break(gb); +} static void add_a_r(GB_gameboy_t *gb, uint8_t opcode) { @@ -1462,7 +1468,7 @@ static GB_opcode_t *opcodes[256] = { jr_cc_r8, add_hl_rr, ld_a_dhli, dec_rr, inc_lr, dec_lr, ld_lr_d8, cpl, jr_cc_r8, ld_rr_d16, ld_dhld_a, inc_rr, inc_dhl, dec_dhl, ld_dhl_d8, scf, /* 3X */ jr_cc_r8, add_hl_rr, ld_a_dhld, dec_rr, inc_hr, dec_hr, ld_hr_d8, ccf, - nop, ld_b_c, ld_b_d, ld_b_e, ld_b_h, ld_b_l, ld_b_dhl, ld_b_a, /* 4X */ + ld_b_b, ld_b_c, ld_b_d, ld_b_e, ld_b_h, ld_b_l, ld_b_dhl, ld_b_a, /* 4X */ ld_c_b, nop, ld_c_d, ld_c_e, ld_c_h, ld_c_l, ld_c_dhl, ld_c_a, ld_d_b, ld_d_c, nop, ld_d_e, ld_d_h, ld_d_l, ld_d_dhl, ld_d_a, /* 5X */ ld_e_b, ld_e_c, ld_e_d, nop, ld_e_h, ld_e_l, ld_e_dhl, ld_e_a, From abdece7737c272dc3f1e771fd18256b4d6da8bb9 Mon Sep 17 00:00:00 2001 From: James Larrowe Date: Sat, 30 May 2020 16:35:07 -0400 Subject: [PATCH 2/5] 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) From 6fcf77c7f6e83b3f6e0a207f6a80ea2a2ba3e4af Mon Sep 17 00:00:00 2001 From: James Larrowe Date: Sat, 30 May 2020 16:46:17 -0400 Subject: [PATCH 3/5] Make no argument for softbreak be equivalent to "on" --- Core/debugger.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Core/debugger.c b/Core/debugger.c index ed498c9..09f78c8 100644 --- a/Core/debugger.c +++ b/Core/debugger.c @@ -836,7 +836,7 @@ static bool registers(GB_gameboy_t *gb, char *arguments, char *modifiers, const static bool softbreak(GB_gameboy_t *gb, char *arguments, char *modifiers, const debugger_command_t *command) { NO_MODIFIERS - if (strcmp(lstrip(arguments), "on") == 0) { + if (strcmp(lstrip(arguments), "on") == 0 || !strlen(lstrip(arguments))) { gb->has_software_breakpoints = true; } else if(strcmp(lstrip(arguments), "off") == 0) { From fd97e1191914df4d1ea78024e1f7255dfe7f4fb9 Mon Sep 17 00:00:00 2001 From: Lior Halphon Date: Sun, 31 May 2020 00:54:13 +0300 Subject: [PATCH 4/5] Spacing --- Core/sm83_cpu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Core/sm83_cpu.c b/Core/sm83_cpu.c index b337b36..f6a69fb 100644 --- a/Core/sm83_cpu.c +++ b/Core/sm83_cpu.c @@ -793,7 +793,7 @@ 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 // fire the debugger if software breakpoints are enabled static void ld_b_b(GB_gameboy_t *gb, uint8_t opcode) { - if(gb->has_software_breakpoints) { + if (gb->has_software_breakpoints) { GB_debugger_break(gb); } } From f1ea39f1c660ef2e377473a3e3264bed8ed05332 Mon Sep 17 00:00:00 2001 From: Lior Halphon Date: Sun, 31 May 2020 00:54:49 +0300 Subject: [PATCH 5/5] Spacing --- Core/debugger.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Core/debugger.c b/Core/debugger.c index 09f78c8..87b0914 100644 --- a/Core/debugger.c +++ b/Core/debugger.c @@ -839,7 +839,7 @@ static bool softbreak(GB_gameboy_t *gb, char *arguments, char *modifiers, const if (strcmp(lstrip(arguments), "on") == 0 || !strlen(lstrip(arguments))) { gb->has_software_breakpoints = true; } - else if(strcmp(lstrip(arguments), "off") == 0) { + else if (strcmp(lstrip(arguments), "off") == 0) { gb->has_software_breakpoints = false; } else {