Add command.h commands for saving/loading sram

This commit is contained in:
Joseph C. Osborn 2025-04-30 12:32:54 -07:00
parent 05f94af415
commit 6235f3138b
3 changed files with 32 additions and 0 deletions

View File

@ -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)

View File

@ -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, "<slot number>"},
{ "PLAY_REPLAY_SLOT",command_play_replay_slot, "<slot number>"},
{ "SAVE_FILES", command_save_savefiles, "No argument"},
{ "LOAD_FILES", command_load_savefiles, "No argument"},
};
static const struct cmd_map map[] = {

View File

@ -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,