From 5648b7259834bc493afcc93c2c261c7997363ddd Mon Sep 17 00:00:00 2001 From: neonloop Date: Mon, 9 Jan 2023 18:53:01 +0000 Subject: Waits to suspend until after game loop Suspending during loop caused corrupt states --- funkey/fk_instant_play.c | 12 ++++++++++++ funkey/fk_instant_play.h | 1 + 2 files changed, 13 insertions(+) (limited to 'funkey') diff --git a/funkey/fk_instant_play.c b/funkey/fk_instant_play.c index eeacae8..a4aebd3 100644 --- a/funkey/fk_instant_play.c +++ b/funkey/fk_instant_play.c @@ -64,12 +64,23 @@ static void handle_sigusr1(int signal) } pclose(fp); + if (in_menu) { + FK_Suspend(); + } else { + /* Wait for the core to be ready to save */ + should_suspend = true; + } +} + +void FK_Suspend(void) +{ state_slot = AUTOSAVE_SLOT; if(!state_write()) { printf("Save failed"); state_slot = 0; } + sram_write(); save_config(CONFIG_TYPE_AUTO); /* Perform Instant Play save and shutdown */ @@ -82,6 +93,7 @@ static void handle_sigusr1(int signal) exit(0); } + void FK_InitInstantPlay(int argc, char **argv) { prog_name = argv[0]; diff --git a/funkey/fk_instant_play.h b/funkey/fk_instant_play.h index b3e3845..5185065 100644 --- a/funkey/fk_instant_play.h +++ b/funkey/fk_instant_play.h @@ -41,6 +41,7 @@ extern "C" { #define AUTOSAVE_SLOT 99 extern void FK_InitInstantPlay(int argc, char **argv); +extern void FK_Suspend(void); /* Ends C function definitions when using C++ */ #ifdef __cplusplus -- cgit v1.2.3