"Standardized" the finish/next call depth as debugger "hooks"
This commit is contained in:
parent
bf6dff30cb
commit
71ef40f4b6
@ -629,6 +629,18 @@ static const debugger_command_t *find_command(const char *string)
|
|||||||
return NULL;
|
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.
|
/* 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. */
|
Only one breakpoint is allowed at a time. More features will be added later. */
|
||||||
void debugger_run(GB_gameboy_t *gb)
|
void debugger_run(GB_gameboy_t *gb)
|
||||||
|
@ -3,5 +3,7 @@
|
|||||||
#include "gb.h"
|
#include "gb.h"
|
||||||
|
|
||||||
void debugger_run(GB_gameboy_t *gb);
|
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 */
|
#endif /* debugger_h */
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
#include "z80_cpu.h"
|
#include "z80_cpu.h"
|
||||||
#include "timing.h"
|
#include "timing.h"
|
||||||
#include "memory.h"
|
#include "memory.h"
|
||||||
|
#include "debugger.h"
|
||||||
#include "gb.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)
|
static void ret_cc(GB_gameboy_t *gb, unsigned char opcode)
|
||||||
{
|
{
|
||||||
if (condition_code(gb, read_memory(gb, gb->pc++))) {
|
if (condition_code(gb, read_memory(gb, gb->pc++))) {
|
||||||
|
debugger_ret_hook(gb);
|
||||||
advance_cycles(gb, 20);
|
advance_cycles(gb, 20);
|
||||||
gb->pc = read_memory(gb, gb->registers[GB_REGISTER_SP]) |
|
gb->pc = read_memory(gb, gb->registers[GB_REGISTER_SP]) |
|
||||||
(read_memory(gb, gb->registers[GB_REGISTER_SP] + 1) << 8);
|
(read_memory(gb, gb->registers[GB_REGISTER_SP] + 1) << 8);
|
||||||
gb->registers[GB_REGISTER_SP] += 2;
|
gb->registers[GB_REGISTER_SP] += 2;
|
||||||
gb->debug_call_depth--;
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
advance_cycles(gb, 8);
|
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], (gb->pc + 2) & 0xFF);
|
||||||
write_memory(gb, gb->registers[GB_REGISTER_SP] + 1, (gb->pc + 2) >> 8);
|
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->pc = read_memory(gb, gb->pc) | (read_memory(gb, gb->pc + 1) << 8);
|
||||||
gb->debug_call_depth++;
|
debugger_call_hook(gb);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
advance_cycles(gb, 12);
|
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], (gb->pc + 1) & 0xFF);
|
||||||
write_memory(gb, gb->registers[GB_REGISTER_SP] + 1, (gb->pc + 1) >> 8);
|
write_memory(gb, gb->registers[GB_REGISTER_SP] + 1, (gb->pc + 1) >> 8);
|
||||||
gb->pc = opcode ^ 0xC7;
|
gb->pc = opcode ^ 0xC7;
|
||||||
|
debugger_call_hook(gb);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ret(GB_gameboy_t *gb, unsigned char opcode)
|
static void ret(GB_gameboy_t *gb, unsigned char opcode)
|
||||||
{
|
{
|
||||||
|
debugger_ret_hook(gb);
|
||||||
advance_cycles(gb, 16);
|
advance_cycles(gb, 16);
|
||||||
gb->pc = read_memory(gb, gb->registers[GB_REGISTER_SP]) |
|
gb->pc = read_memory(gb, gb->registers[GB_REGISTER_SP]) |
|
||||||
(read_memory(gb, gb->registers[GB_REGISTER_SP] + 1) << 8);
|
(read_memory(gb, gb->registers[GB_REGISTER_SP] + 1) << 8);
|
||||||
gb->registers[GB_REGISTER_SP] += 2;
|
gb->registers[GB_REGISTER_SP] += 2;
|
||||||
gb->debug_call_depth--;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void reti(GB_gameboy_t *gb, unsigned char opcode)
|
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], (gb->pc + 2) & 0xFF);
|
||||||
write_memory(gb, gb->registers[GB_REGISTER_SP] + 1, (gb->pc + 2) >> 8);
|
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->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)
|
static void ld_da8_a(GB_gameboy_t *gb, unsigned char opcode)
|
||||||
|
Loading…
Reference in New Issue
Block a user