Skip to content

Commit dfac63d

Browse files
committed
rg_system: Added save_slot argument to rg_system_switch_app
Before we had to do bit manipulation to inject the slot number into the flags. This was a legacy from how I first implemented multi-state. We can now do better.
1 parent 498241c commit dfac63d

5 files changed

Lines changed: 16 additions & 30 deletions

File tree

components/retro-go/rg_gui.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1731,7 +1731,7 @@ void rg_gui_debug_menu(void)
17311731
switch (rg_gui_dialog("Debugging", options, 0))
17321732
{
17331733
case 1:
1734-
rg_system_switch_app(RG_APP_FACTORY, 0, 0, 0);
1734+
rg_system_switch_app(RG_APP_FACTORY, NULL, NULL, 0, 0);
17351735
break;
17361736
case 2:
17371737
rg_storage_delete(RG_BASE_PATH_CACHE);

components/retro-go/rg_system.c

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ static rg_task_t tasks[8];
9595

9696
static const char *SETTING_BOOT_NAME = "BootName";
9797
static const char *SETTING_BOOT_ARGS = "BootArgs";
98+
static const char *SETTING_BOOT_SLOT = "BootSlot";
9899
static const char *SETTING_BOOT_FLAGS = "BootFlags";
99100
static const char *SETTING_TIMEZONE = "Timezone";
100101
static 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)
902904
void 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
}

components/retro-go/rg_system.h

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,7 @@ typedef enum
5757
RG_BOOT_RESET = 0x04,
5858
RG_BOOT_NETPLAY = 0x08,
5959
RG_BOOT_MODE_MASK = 0x0F,
60-
// bits 4-7: slot
61-
RG_BOOT_SLOT0 = 0x00,
62-
RG_BOOT_SLOT1 = 0x10,
63-
RG_BOOT_SLOT2 = 0x20,
64-
RG_BOOT_SLOT3 = 0x30,
65-
RG_BOOT_SLOT_MASK = 0xF0,
66-
// bits 8-31: unused...
60+
// bits 4-31: unused...
6761
} rg_boot_flags_t;
6862

6963
// RG_TASK_PRIORITY_1 is the same as the main task's. Anything
@@ -216,7 +210,7 @@ void rg_system_shutdown(void) __attribute__((noreturn));
216210
void rg_system_sleep(void) __attribute__((noreturn));
217211
void rg_system_restart(void) __attribute__((noreturn));
218212
void rg_system_exit(void) __attribute__((noreturn));
219-
void rg_system_switch_app(const char *part, const char *name, const char *args, uint32_t flags) __attribute__((noreturn));
213+
void rg_system_switch_app(const char *part, const char *name, const char *args, int save_slot, uint32_t flags) __attribute__((noreturn));
220214
bool rg_system_have_app(const char *app);
221215
void rg_system_set_indicator(rg_indicator_t indicator, bool on);
222216
bool rg_system_get_indicator(rg_indicator_t indicator);

launcher/main/applications.c

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -129,14 +129,9 @@ static void application_start(retro_file_t *file, int load_state)
129129
char *part = strdup(file->app->partition);
130130
char *name = strdup(file->app->short_name);
131131
char *path = strdup(get_file_path(file));
132-
int flags = (gui.startup_mode ? RG_BOOT_ONCE : 0);
133-
if (load_state != -1)
134-
{
135-
flags |= RG_BOOT_RESUME;
136-
flags |= (load_state << 4) & RG_BOOT_SLOT_MASK;
137-
}
132+
int flags = (gui.startup_mode ? RG_BOOT_ONCE : 0) | (load_state != -1 ? RG_BOOT_RESUME : 0);
138133
bookmark_add(BOOK_TYPE_RECENT, file); // This could relocate *file, but we no longer need it
139-
rg_system_switch_app(part, name, path, flags);
134+
rg_system_switch_app(part, name, path, load_state, flags);
140135
}
141136

142137
static uint32_t crc_read_file(retro_file_t *file, bool interactive)

launcher/main/updater.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ static rg_gui_event_t view_release_cb(rg_gui_option_t *option, rg_gui_event_t ev
149149
if (download_file(release->assets[sel].url, dest_path))
150150
{
151151
if (rg_gui_confirm(_("Download complete!"), _("Reboot to flash?"), true))
152-
rg_system_switch_app(RG_UPDATER_APPLICATION, NULL, dest_path, 0);
152+
rg_system_switch_app(RG_UPDATER_APPLICATION, NULL, dest_path, 0, 0);
153153
}
154154
}
155155
#else

0 commit comments

Comments
 (0)