This commit is contained in:
2026-06-07 21:16:46 -05:00
parent 51388c90d5
commit dc41c0e302
97 changed files with 1107 additions and 481 deletions
+22 -12
View File
@@ -9,7 +9,9 @@
#include "util/memory.h"
#include "util/string.h"
static void _saveGetFileName(const uint8_t slot, char_t *out, const size_t max) {
static void _saveGetFileName(
const uint8_t slot, char_t *out, const size_t max
) {
snprintf(out, max, "%s_%u", SAVE_DOLPHIN_GAME_CODE, (uint32_t)slot);
}
@@ -42,7 +44,9 @@ errorret_t saveLoadDolphin(const uint8_t slot, savefile_t *file) {
char_t fileName[SAVE_DOLPHIN_FILE_NAME_MAX];
_saveGetFileName(slot, fileName, SAVE_DOLPHIN_FILE_NAME_MAX);
int32_t result = CARD_Open(SAVE_DOLPHIN_CHANNEL, fileName, &SAVE.platform.cardFile);
int32_t result = CARD_Open(
SAVE_DOLPHIN_CHANNEL, fileName, &SAVE.platform.cardFile
);
if(result == CARD_ERROR_NOFILE) {
file->exists = false;
errorOk();
@@ -54,17 +58,19 @@ errorret_t saveLoadDolphin(const uint8_t slot, savefile_t *file) {
);
}
void *buffer = memalign(32, SAVE_DOLPHIN_SECTOR_SIZE);
void *buffer = memoryAlign(32, SAVE_DOLPHIN_SECTOR_SIZE);
if(!buffer) {
CARD_Close(&SAVE.platform.cardFile);
errorThrow("Failed to allocate memory card read buffer");
}
result = CARD_Read(&SAVE.platform.cardFile, buffer, SAVE_DOLPHIN_SECTOR_SIZE, 0);
result = CARD_Read(
&SAVE.platform.cardFile, buffer, SAVE_DOLPHIN_SECTOR_SIZE, 0
);
CARD_Close(&SAVE.platform.cardFile);
if(result < 0) {
free(buffer);
memoryFree(buffer);
file->exists = false;
errorThrow("Failed to read memory card data for slot %u (error %d)",
(uint32_t)slot, result
@@ -72,7 +78,7 @@ errorret_t saveLoadDolphin(const uint8_t slot, savefile_t *file) {
}
memoryCopy(file, buffer, sizeof(savefile_t));
free(buffer);
memoryFree(buffer);
file->exists = true;
errorOk();
@@ -82,15 +88,17 @@ errorret_t saveWriteDolphin(const uint8_t slot, const savefile_t *file) {
char_t fileName[SAVE_DOLPHIN_FILE_NAME_MAX];
_saveGetFileName(slot, fileName, SAVE_DOLPHIN_FILE_NAME_MAX);
void *buffer = memalign(32, SAVE_DOLPHIN_SECTOR_SIZE);
void *buffer = memoryAlign(32, SAVE_DOLPHIN_SECTOR_SIZE);
if(!buffer) {
errorThrow("Failed to allocate memory card write buffer");
}
memset(buffer, 0, SAVE_DOLPHIN_SECTOR_SIZE);
memoryZero(buffer, SAVE_DOLPHIN_SECTOR_SIZE);
memoryCopy(buffer, file, sizeof(savefile_t));
// Try open existing file first; create if absent.
int32_t result = CARD_Open(SAVE_DOLPHIN_CHANNEL, fileName, &SAVE.platform.cardFile);
int32_t result = CARD_Open(
SAVE_DOLPHIN_CHANNEL, fileName, &SAVE.platform.cardFile
);
if(result == CARD_ERROR_NOFILE) {
result = CARD_Create(
SAVE_DOLPHIN_CHANNEL,
@@ -101,15 +109,17 @@ errorret_t saveWriteDolphin(const uint8_t slot, const savefile_t *file) {
}
if(result < 0) {
free(buffer);
memoryFree(buffer);
errorThrow("Failed to open/create memory card file for slot %u (error %d)",
(uint32_t)slot, result
);
}
result = CARD_Write(&SAVE.platform.cardFile, buffer, SAVE_DOLPHIN_SECTOR_SIZE, 0);
result = CARD_Write(
&SAVE.platform.cardFile, buffer, SAVE_DOLPHIN_SECTOR_SIZE, 0
);
CARD_Close(&SAVE.platform.cardFile);
free(buffer);
memoryFree(buffer);
if(result < 0) {
errorThrow("Failed to write memory card data for slot %u (error %d)",