Add state ini (not used yet)

prefix temp files with ed_ for the moment.
This commit is contained in:
Robin Jones 2023-10-20 23:52:27 +01:00
parent 0f17c610e0
commit 7b4a675193
3 changed files with 73 additions and 5 deletions

View File

@ -12,18 +12,18 @@
#include "../flashcart_utils.h" #include "../flashcart_utils.h"
#include "ed64_ll.h" #include "ed64_ll.h"
#include "ed64.h" #include "ed64.h"
#include "ed64_state.h"
// #include "../menu/settings.h"
// This is a trial hack before using the settings API. // FIXME: Use one file using the ed64_pseudo_writeback_t struct.
#ifndef LAST_SAVE_FILE_PATH #ifndef LAST_SAVE_FILE_PATH
#define LAST_SAVE_FILE_PATH "/menu/last_rom.tmp" #define LAST_SAVE_FILE_PATH "/menu/ed_last_rom.tmp"
#endif #endif
#ifndef RESET_CHECK_FILE_PATH #ifndef RESET_CHECK_FILE_PATH
#define RESET_CHECK_FILE_PATH "/menu/reset.tmp" #define RESET_CHECK_FILE_PATH "/menu/ed_reset.tmp"
#endif #endif
#ifndef FLASHRAM_CHECK_FILE_PATH #ifndef FLASHRAM_CHECK_FILE_PATH
#define FLASHRAM_CHECK_FILE_PATH "/menu/flashram.tmp" #define FLASHRAM_CHECK_FILE_PATH "/menu/ed_flashram.tmp"
#endif #endif
extern int ed_exit (void); extern int ed_exit (void);

View File

@ -0,0 +1,42 @@
#include <libdragon.h>
#include <mini.c/src/mini.h>
#include "ed64_state.h"
#include "utils/fs.h"
#ifndef ED64_STATE_FILE_PATH
#define ED64_STATE_FILE_PATH "sd:/menu/ed64_state.ini"
#endif
static ed64_pseudo_writeback_t init = {
.is_warm_start = false,
.last_rom_save_type = false,
.last_rom_path = ""
};
void ed64_state_load (ed64_pseudo_writeback_t *state) {
if (!file_exists(ED64_STATE_FILE_PATH)) {
ed64_state_save(&init);
}
mini_t *ini = mini_try_load(ED64_STATE_FILE_PATH);
state->is_warm_start = mini_get_bool(ini, "ed64", "is_warm_start", init.is_warm_start);
state->last_rom_save_type = mini_get_bool(ini, "ed64", "last_rom_save_type", init.last_rom_save_type);
state->last_rom_path = strdup(mini_get_string(ini, "ed64", "last_rom_path", init.last_rom_path));
mini_free(ini);
}
void ed64_state_save (ed64_pseudo_writeback_t *state) {
mini_t *ini = mini_create(ED64_STATE_FILE_PATH);
mini_set_bool(ini, "ed64", "is_warm_start", state->is_warm_start);
mini_set_bool(ini, "ed64", "last_rom_save_type", state->last_rom_save_type);
mini_set_string(ini, "ed64", "last_rom_path", state->last_rom_path);
mini_save(ini);
mini_free(ini);
}

View File

@ -0,0 +1,26 @@
/**
* @file settings.h
* @brief Menu Settings
* @ingroup menu
*/
#ifndef FLASHCART_ED64_STATE_H__
#define LASHCART_ED64_STATE_H__
#include <stdint.h>
/** @brief ed64 pseudo Writeback Structure */
typedef struct {
/** @brief The reset button was used */
bool is_warm_start;
/** @brief The last save type used */
bool last_rom_save_type; // FIXME: for the moment only a bool for flashram
/** @brief The path to the last loaded ROM */
char *last_rom_path;
} ed64_pseudo_writeback_t;
void ed64_state_load (ed64_pseudo_writeback_t *state);
void ed64_state_save (ed64_pseudo_writeback_t *state);
#endif