From e12e03d9c2c475288336cd1b14094603d61e84e0 Mon Sep 17 00:00:00 2001 From: Lior Halphon Date: Sat, 18 May 2019 20:37:41 +0300 Subject: [PATCH] SGB revision selection in the SDL port --- SDL/gui.c | 26 ++++++++++++++++++++++++++ SDL/gui.h | 8 ++++++++ SDL/main.c | 32 +++++++++++++++++++++----------- 3 files changed, 55 insertions(+), 11 deletions(-) diff --git a/SDL/gui.c b/SDL/gui.c index 80f1507..c515273 100644 --- a/SDL/gui.c +++ b/SDL/gui.c @@ -307,6 +307,31 @@ const char *current_model_string(unsigned index) [configuration.model]; } +static void cycle_sgb_revision(unsigned index) +{ + + configuration.sgb_revision++; + if (configuration.sgb_revision == SGB_MAX) { + configuration.sgb_revision = 0; + } + pending_command = GB_SDL_RESET_COMMAND; +} + +static void cycle_sgb_revision_backwards(unsigned index) +{ + if (configuration.sgb_revision == 0) { + configuration.sgb_revision = SGB_MAX; + } + configuration.sgb_revision--; + pending_command = GB_SDL_RESET_COMMAND; +} + +const char *current_sgb_revision_string(unsigned index) +{ + return (const char *[]){"Super Game Boy NTSC", "Super Game Boy PAL", "Super Game Boy 2"} + [configuration.sgb_revision]; +} + static const uint32_t rewind_lengths[] = {0, 10, 30, 60, 60 * 2, 60 * 5, 60 * 10}; static const char *rewind_strings[] = {"Disabled", "10 Seconds", @@ -355,6 +380,7 @@ const char *current_rewind_string(unsigned index) static const struct menu_item emulation_menu[] = { {"Emulated Model:", cycle_model, current_model_string, cycle_model_backwards}, + {"SGB Revision:", cycle_sgb_revision, current_sgb_revision_string, cycle_sgb_revision_backwards}, {"Rewind Length:", cycle_rewind, current_rewind_string, cycle_rewind_backwards}, {"Back", return_to_root_menu}, {NULL,} diff --git a/SDL/gui.h b/SDL/gui.h index 9711e83..de7ddaa 100644 --- a/SDL/gui.h +++ b/SDL/gui.h @@ -86,6 +86,14 @@ typedef struct { SDL_Scancode keys_2[32]; /* Rewind and underclock, + padding for the future */ uint8_t joypad_configuration[32]; /* 12 Keys + padding for the future*/; uint8_t joypad_axises[JOYPAD_AXISES_MAX]; + + /* v0.12 */ + enum { + SGB_NTSC, + SGB_PAL, + SGB_2, + SGB_MAX + } sgb_revision; } configuration_t; extern configuration_t configuration; diff --git a/SDL/main.c b/SDL/main.c index 8a65a74..6506a3e 100755 --- a/SDL/main.c +++ b/SDL/main.c @@ -35,14 +35,6 @@ static char *battery_save_path_ptr; SDL_AudioDeviceID device_id; -static const GB_model_t sdl_to_internal_model[] = -{ - [MODEL_DMG] = GB_MODEL_DMG_B, - [MODEL_CGB] = GB_MODEL_CGB_E, - [MODEL_AGB] = GB_MODEL_AGB, - [MODEL_SGB] = GB_MODEL_SGB, -}; - void set_filename(const char *new_filename, bool new_should_free) { if (filename && should_free_filename) { @@ -407,13 +399,27 @@ static bool handle_pending_command(void) static void run(void) { + GB_model_t model; pending_command = GB_SDL_NO_COMMAND; restart: + model = (GB_model_t []) + { + [MODEL_DMG] = GB_MODEL_DMG_B, + [MODEL_CGB] = GB_MODEL_CGB_E, + [MODEL_AGB] = GB_MODEL_AGB, + [MODEL_SGB] = (GB_model_t []) + { + [SGB_NTSC] = GB_MODEL_SGB_NTSC, + [SGB_PAL] = GB_MODEL_SGB_PAL, + [SGB_2] = GB_MODEL_SGB2, + }[configuration.sgb_revision], + }[configuration.model]; + if (GB_is_inited(&gb)) { - GB_switch_model_and_reset(&gb, sdl_to_internal_model[configuration.model]); + GB_switch_model_and_reset(&gb, model); } else { - GB_init(&gb, sdl_to_internal_model[configuration.model]); + GB_init(&gb, model); GB_set_vblank_callback(&gb, (GB_vblank_callback_t) vblank); GB_set_pixels_output(&gb, active_pixel_buffer); @@ -434,7 +440,11 @@ restart: bool error = false; start_capturing_logs(); const char * const boot_roms[] = {"dmg_boot.bin", "cgb_boot.bin", "agb_boot.bin", "sgb_boot.bin"}; - error = GB_load_boot_rom(&gb, resource_path(boot_roms[configuration.model])); + const char *boot_rom = boot_roms[configuration.model]; + if (configuration.model == GB_MODEL_SGB && configuration.sgb_revision == SGB_2) { + boot_rom = "sgb2_boot.bin"; + } + error = GB_load_boot_rom(&gb, resource_path(boot_rom)); end_capturing_logs(true, error); start_capturing_logs();