"Standardized" the finish/next call depth as debugger "hooks"

This commit is contained in:
Lior Halphon 2016-04-10 22:24:53 +03:00
parent bf6dff30cb
commit 71ef40f4b6
3 changed files with 20 additions and 4 deletions

View File

@ -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)

View File

@ -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 */

View File

@ -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)