Added the GB_run_frame API; closes #5.

This commit is contained in:
Lior Halphon 2017-04-25 00:19:10 +03:00
parent 22d3510dde
commit b858f17425
2 changed files with 22 additions and 0 deletions

View File

@ -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) void GB_set_pixels_output(GB_gameboy_t *gb, uint32_t *output)
{ {
gb->screen = output; gb->screen = output;

View File

@ -491,6 +491,8 @@ void GB_free(GB_gameboy_t *gb);
void GB_reset(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_switch_model_and_reset(GB_gameboy_t *gb, bool is_cgb);
void GB_run(GB_gameboy_t *gb); 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 { typedef enum {
GB_DIRECT_ACCESS_ROM, GB_DIRECT_ACCESS_ROM,