From a773297b3a4863d56f908b4b9fbb70bec17a2125 Mon Sep 17 00:00:00 2001 From: Lior Halphon Date: Sat, 2 Jul 2022 18:11:55 +0300 Subject: [PATCH] Add CGB revision selection to the SDL frontend --- SDL/gui.c | 34 ++++++++++++++++++++++++++++++++++ SDL/gui.h | 7 ++++++- SDL/main.c | 5 +++-- 3 files changed, 43 insertions(+), 3 deletions(-) diff --git a/SDL/gui.c b/SDL/gui.c index f5b093b..bb7b80b 100644 --- a/SDL/gui.c +++ b/SDL/gui.c @@ -113,6 +113,7 @@ configuration_t configuration = .rumble_mode = GB_RUMBLE_ALL_GAMES, .default_scale = 2, .color_temperature = 10, + .cgb_revision = GB_MODEL_CGB_E - GB_MODEL_CGB_0, }; @@ -397,6 +398,38 @@ const char *current_model_string(unsigned index) [configuration.model]; } +static void cycle_cgb_revision(unsigned index) +{ + + configuration.cgb_revision++; + if (configuration.cgb_revision == GB_MODEL_CGB_E - GB_MODEL_CGB_0) { + configuration.cgb_revision = 0; + } + pending_command = GB_SDL_RESET_COMMAND; +} + +static void cycle_cgb_revision_backwards(unsigned index) +{ + if (configuration.cgb_revision == 0) { + configuration.cgb_revision = GB_MODEL_CGB_E - GB_MODEL_CGB_0; + } + configuration.cgb_revision--; + pending_command = GB_SDL_RESET_COMMAND; +} + +const char *current_cgb_revision_string(unsigned index) +{ + return (const char *[]){ + "CPU CGB 0 (Exp.)", + "CPU CGB A (Exp.)", + "CPU CGB B (Exp.)", + "CPU CGB C (Exp.)", + "CPU CGB D", + "CPU CGB E", + } + [configuration.cgb_revision]; +} + static void cycle_sgb_revision(unsigned index) { @@ -524,6 +557,7 @@ const char *current_rtc_mode_string(unsigned index) static const struct menu_item emulation_menu[] = { {"Emulated Model:", cycle_model, current_model_string, cycle_model_backwards}, + {"GBC Revision:", cycle_cgb_revision, current_cgb_revision_string, cycle_cgb_revision_backwards}, {"SGB Revision:", cycle_sgb_revision, current_sgb_revision_string, cycle_sgb_revision_backwards}, {"Boot ROMs Folder:", toggle_bootrom, current_bootrom_string, toggle_bootrom}, {"Rewind Length:", cycle_rewind, current_rewind_string, cycle_rewind_backwards}, diff --git a/SDL/gui.h b/SDL/gui.h index 81a13bb..cc34733 100644 --- a/SDL/gui.h +++ b/SDL/gui.h @@ -123,9 +123,14 @@ typedef struct { /* v0.14.4 */ bool osd; - + + struct __attribute__((packed, aligned(4))) { + /* v0.15 */ bool allow_mouse_controls; + uint8_t cgb_revision; + + }; } configuration_t; extern configuration_t configuration; diff --git a/SDL/main.c b/SDL/main.c index 9a85661..686dcb4 100644 --- a/SDL/main.c +++ b/SDL/main.c @@ -649,7 +649,7 @@ restart: model = (GB_model_t []) { [MODEL_DMG] = GB_MODEL_DMG_B, - [MODEL_CGB] = GB_MODEL_CGB_E, + [MODEL_CGB] = GB_MODEL_CGB_0 + configuration.cgb_revision, [MODEL_AGB] = GB_MODEL_AGB_A, [MODEL_MGB] = GB_MODEL_MGB, [MODEL_SGB] = (GB_model_t []) @@ -857,7 +857,7 @@ int main(int argc, char **argv) fclose(prefs_file); /* Sanitize for stability */ - configuration.color_correction_mode %= GB_COLOR_CORRECTION_LOW_CONTRAST +1; + configuration.color_correction_mode %= GB_COLOR_CORRECTION_LOW_CONTRAST + 1; configuration.scaling_mode %= GB_SDL_SCALING_MAX; configuration.default_scale %= GB_SDL_DEFAULT_SCALE_MAX + 1; configuration.blending_mode %= GB_FRAME_BLENDING_MODE_ACCURATE + 1; @@ -869,6 +869,7 @@ int main(int argc, char **argv) configuration.rumble_mode %= GB_RUMBLE_ALL_GAMES + 1; configuration.color_temperature %= 21; configuration.bootrom_path[sizeof(configuration.bootrom_path) - 1] = 0; + configuration.cgb_revision %= GB_MODEL_CGB_E - GB_MODEL_CGB_0 + 1; } if (configuration.model >= MODEL_MAX) {