diff --git a/config.def.h b/config.def.h index f1f22da4df..4972c213db 100644 --- a/config.def.h +++ b/config.def.h @@ -277,6 +277,11 @@ static const bool block_sram_overwrite = false; // When the ROM is loaded, state index will be set to the highest existing value. static const bool savestate_auto_index = false; +// Automatically saves a savestate at the end of RetroArch's lifetime. +// The path is $SRAM_PATH.auto. +// RetroArch will automatically load any savestate with this path on startup. +static const bool savestate_auto_save = false; + // Slowmotion ratio. static const float slowmotion_ratio = 3.0; diff --git a/general.h b/general.h index 17680d65af..796079c323 100644 --- a/general.h +++ b/general.h @@ -181,6 +181,7 @@ struct settings bool block_sram_overwrite; bool savestate_auto_index; + bool savestate_auto_save; bool network_cmd_enable; uint16_t network_cmd_port; diff --git a/retroarch.c b/retroarch.c index 644e12515a..496f59ea05 100644 --- a/retroarch.c +++ b/retroarch.c @@ -1642,6 +1642,18 @@ static void load_auto_state(void) } } +static void save_auto_state(void) +{ + if (!g_settings.savestate_auto_save) + return; + + char savestate_name_auto[PATH_MAX]; + fill_pathname_noext(savestate_name_auto, g_extern.savestate_name, + ".auto", sizeof(savestate_name_auto)); + + save_state(savestate_name_auto); +} + void rarch_load_state(void) { char load_path[PATH_MAX]; @@ -2558,6 +2570,8 @@ void rarch_main_deinit(void) deinit_movie(); #endif + save_auto_state(); + pretro_unload_game(); pretro_deinit(); uninit_drivers(); diff --git a/retroarch.cfg b/retroarch.cfg index 9246d93788..3cf0b40a3b 100644 --- a/retroarch.cfg +++ b/retroarch.cfg @@ -8,6 +8,11 @@ # This will be overridden by explicit command line options. # savestate_directory = +# Automatically saves a savestate at the end of RetroArch's lifetime. +# The path is $SRAM_PATH.auto. +# RetroArch will automatically load any savestate with this path on startup. +# savestate_auto_save = false + # Load libretro from a dynamic location for dynamically built RetroArch. # This option is mandatory. # libretro_path = "/path/to/libretro.so" diff --git a/settings.c b/settings.c index f3a9083def..d72e7a9125 100644 --- a/settings.c +++ b/settings.c @@ -189,6 +189,7 @@ void config_set_defaults(void) g_settings.block_sram_overwrite = block_sram_overwrite; g_settings.savestate_auto_index = savestate_auto_index; + g_settings.savestate_auto_save = savestate_auto_save; g_settings.network_cmd_enable = network_cmd_enable; g_settings.network_cmd_port = network_cmd_port; @@ -458,6 +459,7 @@ bool config_load_file(const char *path) CONFIG_GET_BOOL(block_sram_overwrite, "block_sram_overwrite"); CONFIG_GET_BOOL(savestate_auto_index, "savestate_auto_index"); + CONFIG_GET_BOOL(savestate_auto_save, "savestate_auto_save"); CONFIG_GET_BOOL(network_cmd_enable, "network_cmd_enable"); CONFIG_GET_INT(network_cmd_port, "network_cmd_port");