aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorneonloop2023-01-09 18:53:01 +0000
committerneonloop2023-01-09 18:53:01 +0000
commit5648b7259834bc493afcc93c2c261c7997363ddd (patch)
treea4e9e48700000b00af5d5df30e940b19a88a28ac
parent77698840e8cd8ad0b59d6ac1a30a7ecf418ca470 (diff)
downloadpicoarch-5648b7259834bc493afcc93c2c261c7997363ddd.tar.gz
picoarch-5648b7259834bc493afcc93c2c261c7997363ddd.tar.bz2
picoarch-5648b7259834bc493afcc93c2c261c7997363ddd.zip
Waits to suspend until after game loop
Suspending during loop caused corrupt states
-rw-r--r--funkey/fk_instant_play.c12
-rw-r--r--funkey/fk_instant_play.h1
-rw-r--r--main.c15
-rw-r--r--main.h5
4 files changed, 32 insertions, 1 deletions
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
diff --git a/main.c b/main.c
index 925de70..241f689 100644
--- a/main.c
+++ b/main.c
@@ -26,8 +26,10 @@ char save_template_path[MAX_PATH];
#include "funkey/fk_menu.h"
#include "funkey/fk_instant_play.h"
static bool instant_play = false;
+bool should_suspend = false;
#endif
+bool in_menu = false;
bool should_quit = false;
unsigned current_audio_buffer_size;
char core_name[MAX_PATH];
@@ -211,6 +213,10 @@ void set_defaults(void)
scale_size = SCALE_SIZE_NONE;
scale_filter = SCALE_FILTER_NEAREST;
+#ifdef FUNKEY_S
+ enable_drc = 0;
+#endif
+
/* Sets better defaults for small screen */
if (SCREEN_WIDTH == 240) {
scale_size = SCALE_SIZE_CROP;
@@ -372,6 +378,7 @@ void handle_emu_action(emu_action action)
case EACTION_MENU:
toggle_fast_forward(1); /* Force FF off */
sram_write();
+ in_menu = true;
#if defined(MMENU)
if (mmenu && content && content->path) {
ShowMenu_t ShowMenu = (ShowMenu_t)dlsym(mmenu, "ShowMenu");
@@ -424,6 +431,7 @@ void handle_emu_action(emu_action action)
#else
menu_loop();
#endif
+ in_menu = false;
break;
case EACTION_TOGGLE_HUD:
show_hud = !show_hud;
@@ -592,7 +600,7 @@ int main(int argc, char **argv) {
}
if (argc > 1 && argv[1]) {
- if (!realpath(argv[1], &core_path)) {
+ if (!realpath(argv[1], core_path)) {
strncpy(core_path, argv[1], sizeof(core_path) - 1);
}
} else {
@@ -677,6 +685,11 @@ int main(int argc, char **argv) {
count_fps();
adjust_audio();
current_core.retro_run();
+#ifdef FUNKEY_S
+ if (should_suspend)
+ FK_Suspend();
+#endif
+
if (!should_quit)
plat_video_flip();
} while (!should_quit);
diff --git a/main.h b/main.h
index f7b4225..5428d6c 100644
--- a/main.h
+++ b/main.h
@@ -27,6 +27,11 @@ typedef enum {
CONFIG_TYPE_AUTO,
} config_type;
+#ifdef FUNKEY_S
+extern bool should_suspend;
+#endif
+
+extern bool in_menu;
extern bool should_quit;
extern unsigned current_audio_buffer_size;
extern char core_name[MAX_PATH];