git.y1.nz

SameBoy

Accurate GB/GBC emulator
download: https://git.y1.nz/archives/sameboy.tar.gz
README | Files | Log | Refs | LICENSE

commit 51aa09517d51140744e07634b8ca06847b53e9b7
parent 93eb32c40f2282654306bc98c1905aea312bb7d2
Author: Lior Halphon <LIJI32@gmail.com>
Date:   Sat, 17 Sep 2022 13:57:38 +0300

SDL cart swap

Diffstat:
MSDL/gui.c27++++++++++++++++++++++++++-
MSDL/gui.h1+
MSDL/main.c10+++++++++-
3 files changed, 36 insertions(+), 2 deletions(-)

diff --git a/SDL/gui.c b/SDL/gui.c @@ -304,6 +304,15 @@ static void open_rom(unsigned index) } } +static void cart_swap(unsigned index) +{ + char *filename = do_open_rom_dialog(); + if (filename) { + set_filename(filename, free); + pending_command = GB_SDL_CART_SWAP_COMMAND; + } +} + static void recalculate_menu_height(void) { menu_height = 24; @@ -380,6 +389,7 @@ static void enter_options_menu(unsigned index) static const struct menu_item paused_menu[] = { {"Resume", NULL}, {"Open ROM", open_rom}, + {"Hot Swap Cartridge", cart_swap}, {"Options", enter_options_menu}, {audio_recording_menu_item, toggle_audio_recording}, {"Help & About", enter_help_menu}, @@ -388,7 +398,22 @@ static const struct menu_item paused_menu[] = { {NULL,} }; -static const struct menu_item *const nonpaused_menu = &paused_menu[1]; +static struct menu_item nonpaused_menu[sizeof(paused_menu) / sizeof(paused_menu[0]) - 2]; + +static void __attribute__((constructor)) build_nonpaused_menu(void) +{ + const struct menu_item *in = paused_menu; + struct menu_item *out = nonpaused_menu; + while (in->string) { + if (in->handler == NULL || in->handler == cart_swap) { + in++; + continue; + } + *out = *in; + out++; + in++; + } +} static const struct menu_item help_menu[] = { {"Shortcuts", item_help}, diff --git a/SDL/gui.h b/SDL/gui.h @@ -33,6 +33,7 @@ enum pending_command { GB_SDL_NEW_FILE_COMMAND, GB_SDL_QUIT_COMMAND, GB_SDL_LOAD_STATE_FROM_FILE_COMMAND, + GB_SDL_CART_SWAP_COMMAND, }; #define GB_SDL_DEFAULT_SCALE_MAX 8 diff --git a/SDL/main.c b/SDL/main.c @@ -580,6 +580,7 @@ static void gb_audio_callback(GB_gameboy_t *gb, GB_sample_t *sample) } +static bool doing_hot_swap = false; static bool handle_pending_command(void) { switch (pending_command) { @@ -632,6 +633,8 @@ static bool handle_pending_command(void) case GB_SDL_NO_COMMAND: return false; + case GB_SDL_CART_SWAP_COMMAND: + doing_hot_swap = true; case GB_SDL_RESET_COMMAND: case GB_SDL_NEW_FILE_COMMAND: GB_save_battery(&gb, battery_save_path_ptr); @@ -700,7 +703,12 @@ restart: }[configuration.model]; if (GB_is_inited(&gb)) { - GB_switch_model_and_reset(&gb, model); + if (doing_hot_swap) { + doing_hot_swap = false; + } + else { + GB_switch_model_and_reset(&gb, model); + } } else { GB_init(&gb, model);

This webpage is intended to be an accessible preview of this repository. To get a fuller picture, clone it and use the git CLI.