From 1cab391be8c70483785ca9a2878303ffede85c61 Mon Sep 17 00:00:00 2001 From: Themaister Date: Mon, 29 Apr 2013 15:56:49 +0200 Subject: [PATCH] Add SRAM autosave option to RGUI. --- frontend/menu/menu_common.h | 1 + frontend/menu/rgui.c | 24 +++++++++++++++++++++++- general.h | 2 ++ retroarch.c | 12 ++++++------ 4 files changed, 32 insertions(+), 7 deletions(-) diff --git a/frontend/menu/menu_common.h b/frontend/menu/menu_common.h index 3391e1ab31..cd176ffb5f 100644 --- a/frontend/menu/menu_common.h +++ b/frontend/menu/menu_common.h @@ -135,6 +135,7 @@ typedef enum RGUI_SETTINGS_CORE_OPTIONS, RGUI_SETTINGS_REWIND_ENABLE, RGUI_SETTINGS_REWIND_GRANULARITY, + RGUI_SETTINGS_SRAM_AUTOSAVE, RGUI_SETTINGS_SAVESTATE_SAVE, RGUI_SETTINGS_SAVESTATE_LOAD, RGUI_SETTINGS_DISK_INDEX, diff --git a/frontend/menu/rgui.c b/frontend/menu/rgui.c index 0a8c36f7ec..4f1cf3082d 100644 --- a/frontend/menu/rgui.c +++ b/frontend/menu/rgui.c @@ -544,7 +544,10 @@ static void render_text(rgui_handle_t *rgui) strlcpy(type_str, "OFF", sizeof(type_str)); break; case RGUI_SETTINGS_REWIND_GRANULARITY: - snprintf(type_str, sizeof(type_str), "%d", g_settings.rewind_granularity); + snprintf(type_str, sizeof(type_str), "%u", g_settings.rewind_granularity); + break; + case RGUI_SETTINGS_SRAM_AUTOSAVE: + strlcpy(type_str, g_settings.autosave_interval ? "ON" : "OFF", sizeof(type_str)); break; case RGUI_SETTINGS_SAVESTATE_SAVE: case RGUI_SETTINGS_SAVESTATE_LOAD: @@ -786,6 +789,22 @@ static int rgui_settings_toggle_setting(rgui_handle_t *rgui, unsigned setting, r else if (action == RGUI_ACTION_START) g_settings.rewind_granularity = 1; break; +#if defined(HAVE_THREADS) && !defined(RARCH_CONSOLE) + case RGUI_SETTINGS_SRAM_AUTOSAVE: + if (action == RGUI_ACTION_OK || action == RGUI_ACTION_RIGHT || action == RGUI_ACTION_LEFT) + { + rarch_deinit_autosave(); + g_settings.autosave_interval = (!g_settings.autosave_interval) * 10; + if (g_settings.autosave_interval) + rarch_init_autosave(); + } + else if (action == RGUI_ACTION_START) + { + rarch_deinit_autosave(); + g_settings.autosave_interval = 0; + } + break; +#endif case RGUI_SETTINGS_SAVESTATE_SAVE: case RGUI_SETTINGS_SAVESTATE_LOAD: if (action == RGUI_ACTION_OK) @@ -1133,6 +1152,9 @@ static void rgui_settings_populate_entries(rgui_handle_t *rgui) rgui_list_push(rgui->selection_buf, "Rewind", RGUI_SETTINGS_REWIND_ENABLE, 0); rgui_list_push(rgui->selection_buf, "Rewind Granularity", RGUI_SETTINGS_REWIND_GRANULARITY, 0); +#if defined(HAVE_THREADS) && !defined(RARCH_CONSOLE) + rgui_list_push(rgui->selection_buf, "SRAM Autosave", RGUI_SETTINGS_SRAM_AUTOSAVE, 0); +#endif rgui_list_push(rgui->selection_buf, "Mute Audio", RGUI_SETTINGS_AUDIO_MUTE, 0); rgui_list_push(rgui->selection_buf, "Audio Control Rate", RGUI_SETTINGS_AUDIO_CONTROL_RATE, 0); #ifdef GEKKO diff --git a/general.h b/general.h index 2151f9b44e..d940aaa4d7 100644 --- a/general.h +++ b/general.h @@ -690,6 +690,8 @@ void rarch_set_fullscreen(bool fullscreen); void rarch_disk_control_set_eject(bool state, bool log); void rarch_disk_control_set_index(unsigned index); void rarch_disk_control_append_image(const char *path); +void rarch_init_autosave(void); +void rarch_deinit_autosave(void); void rarch_load_state(void); void rarch_save_state(void); diff --git a/retroarch.c b/retroarch.c index c960f1c900..bc10f628d1 100644 --- a/retroarch.c +++ b/retroarch.c @@ -1669,7 +1669,7 @@ static void init_libretro_cbs(void) } #if defined(HAVE_THREADS) && !defined(RARCH_CONSOLE) -static void init_autosave(void) +void rarch_init_autosave(void) { int ram_types[2] = {-1, -1}; const char *ram_paths[2] = {NULL, NULL}; @@ -1722,7 +1722,7 @@ static void init_autosave(void) } } -static void deinit_autosave(void) +void rarch_deinit_autosave(void) { for (unsigned i = 0; i < ARRAY_SIZE(g_extern.autosave); i++) { @@ -2445,7 +2445,7 @@ void rarch_disk_control_append_image(const char *path) msg_queue_push(g_extern.msg_queue, msg, 0, 180); #if defined(HAVE_THREADS) && !defined(RARCH_CONSOLE) - deinit_autosave(); + rarch_deinit_autosave(); #endif // Update paths for our new image. @@ -2456,7 +2456,7 @@ void rarch_disk_control_append_image(const char *path) fill_pathnames(); #if defined(HAVE_THREADS) && !defined(RARCH_CONSOLE) - init_autosave(); + rarch_init_autosave(); #endif rarch_disk_control_set_eject(false, false); @@ -2966,7 +2966,7 @@ int rarch_main_init(int argc, char *argv[]) #if defined(HAVE_THREADS) && !defined(RARCH_CONSOLE) if (g_extern.use_sram) - init_autosave(); + rarch_init_autosave(); #endif #ifdef HAVE_NETPLAY @@ -3102,7 +3102,7 @@ void rarch_main_deinit(void) #if defined(HAVE_THREADS) && !defined(RARCH_CONSOLE) if (g_extern.use_sram) - deinit_autosave(); + rarch_deinit_autosave(); #endif #ifdef HAVE_FFMPEG