From 71ef40f4b67eaa0f808374c20d5cb87bc45bd9c1 Mon Sep 17 00:00:00 2001 From: Lior Halphon Date: Sun, 10 Apr 2016 22:24:53 +0300 Subject: [PATCH] "Standardized" the finish/next call depth as debugger "hooks" --- Core/debugger.c | 12 ++++++++++++ Core/debugger.h | 2 ++ Core/z80_cpu.c | 10 ++++++---- 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/Core/debugger.c b/Core/debugger.c index bf8bc24..0ac7a3d 100644 --- a/Core/debugger.c +++ b/Core/debugger.c @@ -629,6 +629,18 @@ static const debugger_command_t *find_command(const char *string) return NULL; } +void debugger_call_hook(GB_gameboy_t *gb) +{ + /* Called just after the CPU calls a function/enters an interrupt/etc... */ + gb->debug_call_depth++; +} + +void debugger_ret_hook(GB_gameboy_t *gb) +{ + /* Called just before the CPU runs ret/reti */ + gb->debug_call_depth--; +} + /* The debugger interface is quite primitive. One letter commands with a single parameter maximum. Only one breakpoint is allowed at a time. More features will be added later. */ void debugger_run(GB_gameboy_t *gb) diff --git a/Core/debugger.h b/Core/debugger.h index 949523a..3369195 100644 --- a/Core/debugger.h +++ b/Core/debugger.h @@ -3,5 +3,7 @@ #include "gb.h" void debugger_run(GB_gameboy_t *gb); +void debugger_call_hook(GB_gameboy_t *gb); +void debugger_ret_hook(GB_gameboy_t *gb); #endif /* debugger_h */ diff --git a/Core/z80_cpu.c b/Core/z80_cpu.c index c0dddbd..5018bce 100644 --- a/Core/z80_cpu.c +++ b/Core/z80_cpu.c @@ -3,6 +3,7 @@ #include "z80_cpu.h" #include "timing.h" #include "memory.h" +#include "debugger.h" #include "gb.h" @@ -698,11 +699,11 @@ static void halt(GB_gameboy_t *gb, unsigned char opcode) static void ret_cc(GB_gameboy_t *gb, unsigned char opcode) { if (condition_code(gb, read_memory(gb, gb->pc++))) { + debugger_ret_hook(gb); advance_cycles(gb, 20); gb->pc = read_memory(gb, gb->registers[GB_REGISTER_SP]) | (read_memory(gb, gb->registers[GB_REGISTER_SP] + 1) << 8); gb->registers[GB_REGISTER_SP] += 2; - gb->debug_call_depth--; } else { advance_cycles(gb, 8); @@ -749,7 +750,7 @@ static void call_cc_a16(GB_gameboy_t *gb, unsigned char opcode) write_memory(gb, gb->registers[GB_REGISTER_SP], (gb->pc + 2) & 0xFF); write_memory(gb, gb->registers[GB_REGISTER_SP] + 1, (gb->pc + 2) >> 8); gb->pc = read_memory(gb, gb->pc) | (read_memory(gb, gb->pc + 1) << 8); - gb->debug_call_depth++; + debugger_call_hook(gb); } else { advance_cycles(gb, 12); @@ -914,15 +915,16 @@ static void rst(GB_gameboy_t *gb, unsigned char opcode) write_memory(gb, gb->registers[GB_REGISTER_SP], (gb->pc + 1) & 0xFF); write_memory(gb, gb->registers[GB_REGISTER_SP] + 1, (gb->pc + 1) >> 8); gb->pc = opcode ^ 0xC7; + debugger_call_hook(gb); } static void ret(GB_gameboy_t *gb, unsigned char opcode) { + debugger_ret_hook(gb); advance_cycles(gb, 16); gb->pc = read_memory(gb, gb->registers[GB_REGISTER_SP]) | (read_memory(gb, gb->registers[GB_REGISTER_SP] + 1) << 8); gb->registers[GB_REGISTER_SP] += 2; - gb->debug_call_depth--; } static void reti(GB_gameboy_t *gb, unsigned char opcode) @@ -939,7 +941,7 @@ static void call_a16(GB_gameboy_t *gb, unsigned char opcode) write_memory(gb, gb->registers[GB_REGISTER_SP], (gb->pc + 2) & 0xFF); write_memory(gb, gb->registers[GB_REGISTER_SP] + 1, (gb->pc + 2) >> 8); gb->pc = read_memory(gb, gb->pc) | (read_memory(gb, gb->pc + 1) << 8); - gb->debug_call_depth++; + debugger_call_hook(gb); } static void ld_da8_a(GB_gameboy_t *gb, unsigned char opcode)