diff --git a/Core/debugger.c b/Core/debugger.c index ca0c367..a689ea7 100644 --- a/Core/debugger.c +++ b/Core/debugger.c @@ -1185,6 +1185,21 @@ static bool backtrace(GB_gameboy_t *gb, char *arguments, const debugger_command_ return true; } +static bool ticks(GB_gameboy_t *gb, char *arguments, const debugger_command_t *command) +{ + STOPPED_ONLY + + if (strlen(lstrip(arguments))) { + print_usage(gb, command); + return true; + } + + GB_log(gb, "Ticks: %lu. (Resetting)\n", gb->debugger_ticks); + gb->debugger_ticks = 0; + + return true; +} + static bool help(GB_gameboy_t *gb, char *arguments, const debugger_command_t *command); #define HELP_NEWLINE "\n " @@ -1198,6 +1213,7 @@ static const debugger_command_t commands[] = { {"backtrace", 2, backtrace, "Display the current call stack"}, {"bt", 2, }, /* Alias */ {"sld", 3, stack_leak_detection, "Like finish, but stops if a stack leak is detected. (Experimental)"}, + {"ticks", 2, ticks, "Display the number of CPU ticks since the last time 'ticks' was used. "}, {"registers", 1, registers, "Print values of processor registers and other important registers"}, {"cartridge", 2, mbc, "Displays information about the MBC and cartridge"}, {"mbc", 3, }, /* Alias */ diff --git a/Core/gb.h b/Core/gb.h index a2a7d8b..b1326f8 100644 --- a/Core/gb.h +++ b/Core/gb.h @@ -409,6 +409,9 @@ typedef struct GB_gameboy_s { GB_symbol_map_t *bank_symbols[0x200]; GB_reversed_symbol_map_t reversed_symbol_map; + /* Ticks command */ + unsigned long debugger_ticks; + /* Misc */ bool turbo; bool turbo_dont_skip; diff --git a/Core/timing.c b/Core/timing.c index 726fb36..b31826b 100644 --- a/Core/timing.c +++ b/Core/timing.c @@ -53,6 +53,8 @@ void GB_advance_cycles(GB_gameboy_t *gb, uint8_t cycles) } } + gb->debugger_ticks += cycles; + if (gb->cgb_double_speed) { cycles >>=1; }