diff --git a/Core/gb.c b/Core/gb.c index bf41891..cc86fef 100755 --- a/Core/gb.c +++ b/Core/gb.c @@ -271,15 +271,17 @@ exit: return; } -void GB_run(GB_gameboy_t *gb) +uint8_t GB_run(GB_gameboy_t *gb) { GB_debugger_run(gb); + gb->cycles_since_run = 0; GB_cpu_run(gb); if (gb->vblank_just_occured) { GB_update_joyp(gb); GB_rtc_run(gb); GB_debugger_handle_async_commands(gb); } + return gb->cycles_since_run; } uint64_t GB_run_frame(GB_gameboy_t *gb) diff --git a/Core/gb.h b/Core/gb.h index dbe81ed..ca373f5 100644 --- a/Core/gb.h +++ b/Core/gb.h @@ -483,6 +483,7 @@ struct GB_gameboy_internal_s { uint32_t ram_size; // Different between CGB and DMG uint8_t boot_rom[0x900]; bool vblank_just_occured; // For slow operations involving syscalls; these should only run once per vblank + uint8_t cycles_since_run; // How many cycles have passed since the last call to GB_run() ); }; @@ -506,7 +507,9 @@ bool GB_is_cgb(GB_gameboy_t *gb); void GB_free(GB_gameboy_t *gb); void GB_reset(GB_gameboy_t *gb); void GB_switch_model_and_reset(GB_gameboy_t *gb, bool is_cgb); -void GB_run(GB_gameboy_t *gb); + +/* Returns the time passed, in 4MHz ticks. */ +uint8_t GB_run(GB_gameboy_t *gb); /* Returns the time passed since the last frame, in nanoseconds */ uint64_t GB_run_frame(GB_gameboy_t *gb); diff --git a/Core/timing.c b/Core/timing.c index 1818a7c..cbcfb82 100644 --- a/Core/timing.c +++ b/Core/timing.c @@ -153,6 +153,7 @@ void GB_advance_cycles(GB_gameboy_t *gb, uint8_t cycles) gb->cycles_since_ir_change += cycles; gb->cycles_since_input_ir_change += cycles; gb->cycles_since_last_sync += cycles; + gb->cycles_since_run += cycles; GB_dma_run(gb); GB_hdma_run(gb); GB_apu_run(gb);