From 6235f3138b0459d7ce198dcf2864621971de8dfd Mon Sep 17 00:00:00 2001 From: "Joseph C. Osborn" Date: Wed, 30 Apr 2025 12:32:54 -0700 Subject: [PATCH] Add command.h commands for saving/loading sram --- command.c | 23 +++++++++++++++++++++++ command.h | 6 ++++++ retroarch.c | 3 +++ 3 files changed, 32 insertions(+) diff --git a/command.c b/command.c index 009b1867b8..e778b736cf 100644 --- a/command.c +++ b/command.c @@ -809,6 +809,29 @@ bool command_play_replay_slot(command_t *cmd, const char *arg) #endif } +bool command_save_savefiles(command_t *cmd, const char* arg) +{ + char reply[4]; + size_t _len = strlcpy(reply, "OK", sizeof(reply)); + reply[ _len] = '\n'; + reply[++_len] = '\0'; + /* In the future, this should probably send each saved file path + to the replier. */ + command_event(CMD_EVENT_SAVE_FILES, NULL); + cmd->replier(cmd, reply, _len); + return true; +} + +bool command_load_savefiles(command_t *cmd, const char* arg) +{ + char reply[4]; + size_t _len = strlcpy(reply, "OK", sizeof(reply)); + reply[ _len] = '\n'; + reply[++_len] = '\0'; + command_event(CMD_EVENT_LOAD_FILES, NULL); + cmd->replier(cmd, reply, _len); + return true; +} #if defined(HAVE_CHEEVOS) bool command_read_ram(command_t *cmd, const char *arg) diff --git a/command.h b/command.h index dd08854284..8fa57ec7b3 100644 --- a/command.h +++ b/command.h @@ -258,6 +258,7 @@ enum event_command CMD_EVENT_AI_SERVICE_CALL, /* Misc. */ CMD_EVENT_SAVE_FILES, + CMD_EVENT_LOAD_FILES, CMD_EVENT_CONTROLLER_INIT, CMD_EVENT_DISCORD_INIT, CMD_EVENT_PRESENCE_UPDATE, @@ -420,6 +421,8 @@ bool command_get_config_param(command_t *cmd, const char* arg); bool command_show_osd_msg(command_t *cmd, const char* arg); bool command_load_state_slot(command_t *cmd, const char* arg); bool command_play_replay_slot(command_t *cmd, const char* arg); +bool command_save_savefiles(command_t *cmd, const char* arg); +bool command_load_savefiles(command_t *cmd, const char* arg); #ifdef HAVE_CHEEVOS bool command_read_ram(command_t *cmd, const char *arg); bool command_write_ram(command_t *cmd, const char *arg); @@ -446,6 +449,9 @@ static const struct cmd_action_map action_map[] = { { "LOAD_STATE_SLOT",command_load_state_slot, ""}, { "PLAY_REPLAY_SLOT",command_play_replay_slot, ""}, + + { "SAVE_FILES", command_save_savefiles, "No argument"}, + { "LOAD_FILES", command_load_savefiles, "No argument"}, }; static const struct cmd_map map[] = { diff --git a/retroarch.c b/retroarch.c index 1577940750..1f6f602fb2 100644 --- a/retroarch.c +++ b/retroarch.c @@ -3020,6 +3020,9 @@ bool command_event(enum event_command cmd, void *data) switch (cmd) { + case CMD_EVENT_LOAD_FILES: + event_load_save_files(runloop_st->flags & RUNLOOP_FLAG_IS_SRAM_LOAD_DISABLED); + break; case CMD_EVENT_SAVE_FILES: event_save_files( runloop_st->flags & RUNLOOP_FLAG_USE_SRAM,