diff --git a/Cocoa/GBView.m b/Cocoa/GBView.m index fc0c04a..2e907ed 100644 --- a/Cocoa/GBView.m +++ b/Cocoa/GBView.m @@ -172,7 +172,7 @@ handled = true; switch (i) { case GBTurbo: - GB_set_turbo_mode(_gb, true); + GB_set_turbo_mode(_gb, true, false); break; default: @@ -198,7 +198,7 @@ handled = true; switch (i) { case GBTurbo: - GB_set_turbo_mode(_gb, false); + GB_set_turbo_mode(_gb, false, false); break; default: diff --git a/Core/apu.h b/Core/apu.h index 261c1e1..ecb8a8b 100644 --- a/Core/apu.h +++ b/Core/apu.h @@ -54,6 +54,7 @@ typedef struct GB_apu_channel_t wave_channels[4]; } GB_apu_t; +void GB_set_sample_rate(GB_gameboy_t *gb, unsigned int sample_rate); void GB_apu_copy_buffer(GB_gameboy_t *gb, GB_sample_t *dest, unsigned int count); #ifdef GB_INTERNAL diff --git a/Core/display.c b/Core/display.c index ddb1524..3e7d6f1 100755 --- a/Core/display.c +++ b/Core/display.c @@ -239,29 +239,10 @@ void display_vblank(GB_gameboy_t *gb) } gb->last_vblank = nanoseconds; } - - /* - static long start = 0; - static long last = 0; - static long frames = 0; - - if (last == 0) { - last = time(NULL); - } - - if (last != time(NULL)) { - last = time(NULL); - if (start == 0) { - start = last; - frames = 0; - } - printf("Average FPS: %f\n", frames / (double)(last - start)); - } - frames++; - */ - - if (!(gb->io_registers[GB_IO_LCDC] & 0x80) || gb->stopped) { + + if (!gb->disable_rendering && (!(gb->io_registers[GB_IO_LCDC] & 0x80) || gb->stopped)) { /* LCD is off, memset screen to white */ + /* Todo: use RGB callback */ memset(gb->screen, 0xFF, WIDTH * LINES * 4); } diff --git a/Core/gb.c b/Core/gb.c index 9261e2d..89265c2 100755 --- a/Core/gb.c +++ b/Core/gb.c @@ -540,9 +540,15 @@ bool GB_is_inited(GB_gameboy_t *gb) return gb->magic == 'SAME'; } -void GB_set_turbo_mode(GB_gameboy_t *gb, bool on) +void GB_set_turbo_mode(GB_gameboy_t *gb, bool on, bool no_frame_skip) { gb->turbo = on; + gb->turbo_dont_skip = no_frame_skip; +} + +void GB_set_rendering_disabled(GB_gameboy_t *gb, bool disabled) +{ + gb->disable_rendering = disabled; } void *GB_get_user_data(GB_gameboy_t *gb) diff --git a/Core/gb.h b/Core/gb.h index 72abea3..c9b772b 100644 --- a/Core/gb.h +++ b/Core/gb.h @@ -480,28 +480,41 @@ __attribute__((__format__ (__printf__, fmtarg, firstvararg))) void GB_init(GB_gameboy_t *gb); void GB_init_cgb(GB_gameboy_t *gb); +bool GB_is_inited(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); + +void *GB_get_user_data(GB_gameboy_t *gb); +void GB_set_user_data(GB_gameboy_t *gb, void *data); + int GB_load_boot_rom(GB_gameboy_t *gb, const char *path); int GB_load_rom(GB_gameboy_t *gb, const char *path); + int GB_save_battery(GB_gameboy_t *gb, const char *path); void GB_load_battery(GB_gameboy_t *gb, const char *path); + int GB_save_state(GB_gameboy_t *gb, const char *path); int GB_load_state(GB_gameboy_t *gb, const char *path); -void GB_run(GB_gameboy_t *gb); -void GB_set_pixels_output(GB_gameboy_t *gb, uint32_t *output); -void GB_set_vblank_callback(GB_gameboy_t *gb, GB_vblank_callback_t callback); -void GB_set_log_callback(GB_gameboy_t *gb, GB_log_callback_t callback); + +void GB_set_turbo_mode(GB_gameboy_t *gb, bool on, bool no_frame_skip); +void GB_set_rendering_disabled(GB_gameboy_t *gb, bool disabled); + void GB_log(GB_gameboy_t *gb, const char *fmt, ...) __printflike(2, 3); void GB_attributed_log(GB_gameboy_t *gb, GB_log_attributes attributes, const char *fmt, ...) __printflike(3, 4); -void GB_set_input_callback(GB_gameboy_t *gb, GB_input_callback_t callback); -void GB_set_async_input_callback(GB_gameboy_t *gb, GB_input_callback_t callback); -void GB_set_sample_rate(GB_gameboy_t *gb, unsigned int sample_rate); -void GB_set_rgb_encode_callback(GB_gameboy_t *gb, GB_rgb_encode_callback_t callback); -void GB_set_infrared_callback(GB_gameboy_t *gb, GB_infrared_callback_t callback); + +void GB_set_pixels_output(GB_gameboy_t *gb, uint32_t *output); + void GB_set_infrared_input(GB_gameboy_t *gb, bool state); void GB_queue_infrared_input(GB_gameboy_t *gb, bool state, long cycles_after_previous_change); + +void GB_set_vblank_callback(GB_gameboy_t *gb, GB_vblank_callback_t callback); +void GB_set_log_callback(GB_gameboy_t *gb, GB_log_callback_t callback); +void GB_set_input_callback(GB_gameboy_t *gb, GB_input_callback_t callback); +void GB_set_async_input_callback(GB_gameboy_t *gb, GB_input_callback_t callback); +void GB_set_rgb_encode_callback(GB_gameboy_t *gb, GB_rgb_encode_callback_t callback); +void GB_set_infrared_callback(GB_gameboy_t *gb, GB_infrared_callback_t callback); void GB_set_rumble_callback(GB_gameboy_t *gb, GB_rumble_callback_t callback); /* These APIs are used when using internal clock */ @@ -511,11 +524,7 @@ void GB_set_serial_transfer_end_callback(GB_gameboy_t *gb, GB_serial_transfer_en /* These APIs are used when using external clock */ uint8_t GB_serial_get_data(GB_gameboy_t *gb); void GB_serial_set_data(GB_gameboy_t *gb, uint8_t data); - + void GB_disconnect_serial(GB_gameboy_t *gb); -bool GB_is_inited(GB_gameboy_t *gb); -void GB_set_turbo_mode(GB_gameboy_t *gb, bool on); -void *GB_get_user_data(GB_gameboy_t *gb); -void GB_set_user_data(GB_gameboy_t *gb, void *data); #endif /* GB_h */ diff --git a/QuickLook/get_image_for_rom.c b/QuickLook/get_image_for_rom.c index 59e1c5d..3dfbe9b 100755 --- a/QuickLook/get_image_for_rom.c +++ b/QuickLook/get_image_for_rom.c @@ -1,6 +1,3 @@ -#define GB_INTERNAL // Todo: This file runs SameBoy in a special configuration - // of the turbo mode, which is not available without direct - // struct access #include #include #include @@ -36,7 +33,7 @@ static void vblank(GB_gameboy_t *gb) local_data->running = false; } else if (local_data->frames == LENGTH - 1) { - gb->disable_rendering = false; + GB_set_rendering_disabled(gb, false); } local_data->frames++; @@ -72,13 +69,16 @@ int get_image_for_rom(const char *filename, const char *boot_path, uint32_t *out GB_set_user_data(&gb, &local_data); local_data.running = true; local_data.frames = 0; - gb.turbo = gb.turbo_dont_skip = gb.disable_rendering = true; + GB_set_rendering_disabled(&gb, true); + GB_set_turbo_mode(&gb, true, true); + + *cgb_flag = GB_read_memory(&gb, 0x143) & 0xC0; + while (local_data.running) { GB_run(&gb); } - *cgb_flag = gb.rom[0x143] & 0xC0; GB_free(&gb); return 0; diff --git a/SDL/main.c b/SDL/main.c index 943ff7d..cd7cf18 100755 --- a/SDL/main.c +++ b/SDL/main.c @@ -63,7 +63,7 @@ static void GB_update_keys_status(GB_gameboy_t *gb) GB_set_key_state(gb, GB_KEY_START, event.type == SDL_KEYDOWN); break; case SDLK_SPACE: - GB_set_turbo_mode(gb, event.type == SDL_KEYDOWN); + GB_set_turbo_mode(gb, event.type == SDL_KEYDOWN, false); break; case SDLK_LCTRL: case SDLK_RCTRL: