@@ -95,6 +95,7 @@ static rg_task_t tasks[8];
9595
9696static const char * SETTING_BOOT_NAME = "BootName" ;
9797static const char * SETTING_BOOT_ARGS = "BootArgs" ;
98+ static const char * SETTING_BOOT_SLOT = "BootSlot" ;
9899static const char * SETTING_BOOT_FLAGS = "BootFlags" ;
99100static const char * SETTING_TIMEZONE = "Timezone" ;
100101static const char * SETTING_INDICATOR_MASK = "Indicators" ;
@@ -123,12 +124,13 @@ IRAM_ATTR void esp_panic_putchar_hook(char c)
123124 logbuf_putc (& panicTrace , c );
124125}
125126
126- static bool update_boot_config (const char * partition , const char * name , const char * args , uint32_t flags )
127+ static bool update_boot_config (const char * partition , const char * name , const char * args , int save_slot , uint32_t flags )
127128{
128129 if (app .initialized )
129130 {
130131 rg_settings_set_string (NS_BOOT , SETTING_BOOT_NAME , name );
131132 rg_settings_set_string (NS_BOOT , SETTING_BOOT_ARGS , args );
133+ rg_settings_set_number (NS_BOOT , SETTING_BOOT_SLOT , save_slot );
132134 rg_settings_set_number (NS_BOOT , SETTING_BOOT_FLAGS , flags );
133135 rg_settings_commit ();
134136 }
@@ -348,7 +350,7 @@ static void enter_recovery_mode(void)
348350 rg_storage_delete (RG_BASE_PATH_CACHE );
349351 break ;
350352 case 1 :
351- rg_system_switch_app (RG_APP_FACTORY , 0 , 0 , 0 );
353+ rg_system_switch_app (RG_APP_FACTORY , NULL , NULL , 0 , 0 );
352354 case 2 :
353355 default :
354356 rg_system_exit ();
@@ -470,6 +472,7 @@ rg_app_t *rg_system_init(int sampleRate, const rg_handlers_t *handlers, void *_u
470472 app .configNs = rg_settings_get_string (NS_BOOT , SETTING_BOOT_NAME , app .configNs );
471473 app .bootArgs = rg_settings_get_string (NS_BOOT , SETTING_BOOT_ARGS , app .bootArgs );
472474 app .bootFlags = rg_settings_get_number (NS_BOOT , SETTING_BOOT_FLAGS , app .bootFlags );
475+ app .saveSlot = rg_settings_get_number (NS_BOOT , SETTING_BOOT_SLOT , app .saveSlot );
473476 rg_display_init ();
474477 rg_gui_init ();
475478
@@ -500,7 +503,6 @@ rg_app_t *rg_system_init(int sampleRate, const rg_handlers_t *handlers, void *_u
500503 app .lowMemoryMode = statistics .totalMemoryExt == 0 ;
501504
502505 app .indicatorsMask = rg_settings_get_number (NS_GLOBAL , SETTING_INDICATOR_MASK , app .indicatorsMask );
503- app .saveSlot = (app .bootFlags & RG_BOOT_SLOT_MASK ) >> 4 ;
504506 app .romPath = app .bootArgs ?: "" ; // For whatever reason some of our code isn't NULL-aware, sigh..
505507
506508 rg_gui_draw_hourglass ();
@@ -523,7 +525,7 @@ rg_app_t *rg_system_init(int sampleRate, const rg_handlers_t *handlers, void *_u
523525 rg_gui_alert ("External memory not detected" , "Boot will continue but it will surely crash..." );
524526
525527 if (app .bootFlags & RG_BOOT_ONCE )
526- update_boot_config (RG_APP_LAUNCHER , NULL , NULL , 0 );
528+ update_boot_config (RG_APP_LAUNCHER , NULL , NULL , 0 , 0 );
527529
528530 rg_task_create ("rg_sysmon" , & system_monitor_task , NULL , 3 * 1024 , RG_TASK_PRIORITY_5 , -1 );
529531 app .initialized = true;
@@ -902,14 +904,14 @@ void rg_system_restart(void)
902904void rg_system_exit (void )
903905{
904906 RG_LOGW ("Exiting application!" );
905- rg_system_switch_app (RG_APP_LAUNCHER , 0 , 0 , 0 );
907+ rg_system_switch_app (RG_APP_LAUNCHER , NULL , NULL , 0 , 0 );
906908}
907909
908- void rg_system_switch_app (const char * partition , const char * name , const char * args , uint32_t flags )
910+ void rg_system_switch_app (const char * partition , const char * name , const char * args , int save_slot , uint32_t flags )
909911{
910912 RG_LOGI ("Switching to app %s (%s)" , partition ?: "-" , name ?: "-" );
911913
912- if (update_boot_config (partition , name , args , flags ))
914+ if (update_boot_config (partition , name , args , save_slot , flags ))
913915 rg_system_restart ();
914916
915917 RG_PANIC ("Failed to switch app!" );
@@ -1227,12 +1229,7 @@ static void emu_update_save_slot(uint8_t slot)
12271229
12281230 // Set bootflags to resume from this state on next boot
12291231 if ((app .bootFlags & RG_BOOT_ONCE ) == 0 )
1230- {
1231- app .bootFlags &= ~RG_BOOT_SLOT_MASK ;
1232- app .bootFlags |= app .saveSlot << 4 ;
1233- app .bootFlags |= RG_BOOT_RESUME ;
1234- update_boot_config (NULL , app .configNs , app .bootArgs , app .bootFlags );
1235- }
1232+ update_boot_config (NULL , app .configNs , app .bootArgs , app .saveSlot , app .bootFlags | RG_BOOT_RESUME );
12361233
12371234 rg_storage_commit ();
12381235}
0 commit comments