From b858f1742503a274527aa8a2735936a485ed1dc9 Mon Sep 17 00:00:00 2001 From: Lior Halphon Date: Tue, 25 Apr 2017 00:19:10 +0300 Subject: [PATCH] Added the GB_run_frame API; closes #5. --- Core/gb.c | 20 ++++++++++++++++++++ Core/gb.h | 2 ++ 2 files changed, 22 insertions(+) diff --git a/Core/gb.c b/Core/gb.c index 8eb280d2..372830f8 100755 --- a/Core/gb.c +++ b/Core/gb.c @@ -416,6 +416,26 @@ void GB_run(GB_gameboy_t *gb) } } +uint64_t GB_run_frame(GB_gameboy_t *gb) +{ + /* Configure turbo temporarily, the user wants to handle FPS capping manually. */ + bool old_turbo = gb->turbo; + bool old_dont_skip = gb->turbo_dont_skip; + gb->turbo = true; + gb->turbo_dont_skip = true; + + gb->cycles_since_last_sync = 0; + while (true) { + GB_run(gb); + if (gb->vblank_just_occured) { + break; + } + } + gb->turbo = old_turbo; + gb->turbo_dont_skip = old_dont_skip; + return gb->cycles_since_last_sync * FRAME_LENGTH * LCDC_PERIOD; +} + void GB_set_pixels_output(GB_gameboy_t *gb, uint32_t *output) { gb->screen = output; diff --git a/Core/gb.h b/Core/gb.h index ca717e78..a978e1a4 100644 --- a/Core/gb.h +++ b/Core/gb.h @@ -491,6 +491,8 @@ 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 since the last frame, in nanoseconds */ +uint64_t GB_run_frame(GB_gameboy_t *gb); typedef enum { GB_DIRECT_ACCESS_ROM,