summaryrefslogtreecommitdiff
path: root/mm/src/code
diff options
context:
space:
mode:
authorArchez <Archez@users.noreply.github.com>2025-01-08 21:37:08 -0500
committerGitHub <noreply@github.com>2025-01-08 21:37:08 -0500
commit92eaced2f3ff599376900bb193391cae2590f81b (patch)
treed005125c80e28799461a2ad2fff707297a45a922 /mm/src/code
parent1de88406c5421c8df9aa80852edc3a8272117f26 (diff)
Add enums for sram and save file magic values (#933)
Diffstat (limited to 'mm/src/code')
-rw-r--r--mm/src/code/z_message.c10
-rw-r--r--mm/src/code/z_sram_NES.c181
2 files changed, 111 insertions, 80 deletions
diff --git a/mm/src/code/z_message.c b/mm/src/code/z_message.c
index 652996300..628e049dd 100644
--- a/mm/src/code/z_message.c
+++ b/mm/src/code/z_message.c
@@ -6157,8 +6157,9 @@ void Message_Update(PlayState* play) {
gSaveContext.save.cutsceneIndex = sp44;
if (gSaveContext.fileNum != 0xFF) {
- Sram_SetFlashPagesDefault(&play->sramCtx, gFlashSaveStartPages[gSaveContext.fileNum * 2],
- gFlashSpecialSaveNumPages[gSaveContext.fileNum * 2]);
+ Sram_SetFlashPagesDefault(&play->sramCtx,
+ gFlashSaveStartPages[gSaveContext.fileNum * FLASH_SAVE_MAIN_MULTIPLIER],
+ gFlashSpecialSaveNumPages[gSaveContext.fileNum * FLASH_SAVE_MAIN_MULTIPLIER]);
Sram_StartWriteToFlashDefault(&play->sramCtx);
}
msgCtx->msgMode = MSGMODE_NEW_CYCLE_1;
@@ -6184,8 +6185,9 @@ void Message_Update(PlayState* play) {
func_8014546C(&play->sramCtx);
if (gSaveContext.fileNum != 0xFF) {
- Sram_SetFlashPagesOwlSave(&play->sramCtx, gFlashOwlSaveStartPages[gSaveContext.fileNum * 2],
- gFlashOwlSaveNumPages[gSaveContext.fileNum * 2]);
+ Sram_SetFlashPagesOwlSave(&play->sramCtx,
+ gFlashOwlSaveStartPages[gSaveContext.fileNum * FLASH_SAVE_MAIN_MULTIPLIER],
+ gFlashOwlSaveNumPages[gSaveContext.fileNum * FLASH_SAVE_MAIN_MULTIPLIER]);
Sram_StartWriteToFlashOwlSave(&play->sramCtx);
}
msgCtx->msgMode = MSGMODE_OWL_SAVE_1;
diff --git a/mm/src/code/z_sram_NES.c b/mm/src/code/z_sram_NES.c
index bb2fcc753..680989224 100644
--- a/mm/src/code/z_sram_NES.c
+++ b/mm/src/code/z_sram_NES.c
@@ -1219,15 +1219,19 @@ void Sram_ResetSaveFromMoonCrash(SramContext* sramCtx) {
memset(sramCtx->saveBuf, 0, SAVE_BUFFER_SIZE);
- if (SysFlashrom_ReadData(sramCtx->saveBuf, gFlashSaveStartPages[gSaveContext.fileNum * 2],
- gFlashSaveNumPages[gSaveContext.fileNum * 2]) != 0) {
- SysFlashrom_ReadData(sramCtx->saveBuf, gFlashSaveStartPages[gSaveContext.fileNum * 2 + 1],
- gFlashSaveNumPages[gSaveContext.fileNum * 2 + 1]);
+ if (SysFlashrom_ReadData(sramCtx->saveBuf, gFlashSaveStartPages[gSaveContext.fileNum * FLASH_SAVE_MAIN_MULTIPLIER],
+ gFlashSaveNumPages[gSaveContext.fileNum * FLASH_SAVE_MAIN_MULTIPLIER]) != 0) {
+ SysFlashrom_ReadData(
+ sramCtx->saveBuf,
+ gFlashSaveStartPages[gSaveContext.fileNum * FLASH_SAVE_MAIN_MULTIPLIER + FLASH_SAVE_BACKUP_OFFSET],
+ gFlashSaveNumPages[gSaveContext.fileNum * FLASH_SAVE_MAIN_MULTIPLIER + FLASH_SAVE_BACKUP_OFFSET]);
}
memcpy(&gSaveContext.save, sramCtx->saveBuf, sizeof(Save));
if (CHECK_NEWF(gSaveContext.save.saveInfo.playerData.newf)) {
- SysFlashrom_ReadData(sramCtx->saveBuf, gFlashSaveStartPages[gSaveContext.fileNum * 2 + 1],
- gFlashSaveNumPages[gSaveContext.fileNum * 2 + 1]);
+ SysFlashrom_ReadData(
+ sramCtx->saveBuf,
+ gFlashSaveStartPages[gSaveContext.fileNum * FLASH_SAVE_MAIN_MULTIPLIER + FLASH_SAVE_BACKUP_OFFSET],
+ gFlashSaveNumPages[gSaveContext.fileNum * FLASH_SAVE_MAIN_MULTIPLIER + FLASH_SAVE_BACKUP_OFFSET]);
memcpy(&gSaveContext, sramCtx->saveBuf, sizeof(Save));
}
gSaveContext.save.cutsceneIndex = cutsceneIndex;
@@ -1279,29 +1283,31 @@ void Sram_OpenSave(FileSelectState* fileSelect, SramContext* sramCtx) {
memset(sramCtx->saveBuf, 0, SAVE_BUFFER_SIZE);
if (gSaveContext.fileNum == 0xFF) {
- SysFlashrom_ReadData(sramCtx->saveBuf, gFlashSaveStartPages[0], gFlashSaveNumPages[0]);
- } else if (fileSelect->isOwlSave[gSaveContext.fileNum + 2]) {
- phi_t1 = gSaveContext.fileNum + 2;
- phi_t1 *= 2;
+ SysFlashrom_ReadData(sramCtx->saveBuf, gFlashSaveStartPages[FLASH_SAVE_FILE_1_NEW_CYCLE_SAVE],
+ gFlashSaveNumPages[FLASH_SAVE_FILE_1_NEW_CYCLE_SAVE]);
+ } else if (fileSelect->isOwlSave[gSaveContext.fileNum + FILE_NUM_OWL_SAVE_OFFSET]) {
+ phi_t1 = gSaveContext.fileNum + FILE_NUM_OWL_SAVE_OFFSET;
+ phi_t1 *= FLASH_SAVE_MAIN_MULTIPLIER;
if (SysFlashrom_ReadData(sramCtx->saveBuf, gFlashSaveStartPages[phi_t1], gFlashSaveNumPages[phi_t1]) != 0) {
- SysFlashrom_ReadData(sramCtx->saveBuf, gFlashSaveStartPages[phi_t1 + 1],
- gFlashSaveNumPages[phi_t1 + 1]);
+ SysFlashrom_ReadData(sramCtx->saveBuf, gFlashSaveStartPages[phi_t1 + FLASH_SAVE_BACKUP_OFFSET],
+ gFlashSaveNumPages[phi_t1 + FLASH_SAVE_BACKUP_OFFSET]);
}
} else {
phi_t1 = gSaveContext.fileNum;
- phi_t1 *= 2;
+ phi_t1 *= FLASH_SAVE_MAIN_MULTIPLIER;
if (SysFlashrom_ReadData(sramCtx->saveBuf, gFlashSaveStartPages[phi_t1], gFlashSaveNumPages[phi_t1]) != 0) {
- SysFlashrom_ReadData(sramCtx->saveBuf, gFlashSaveStartPages[phi_t1 + 1],
- gFlashSaveNumPages[phi_t1 + 1]);
+ SysFlashrom_ReadData(sramCtx->saveBuf, gFlashSaveStartPages[phi_t1 + FLASH_SAVE_BACKUP_OFFSET],
+ gFlashSaveNumPages[phi_t1 + FLASH_SAVE_BACKUP_OFFSET]);
}
}
memcpy(&gSaveContext, sramCtx->saveBuf, gFlashSaveSizes[phi_t1]);
if (CHECK_NEWF(gSaveContext.save.saveInfo.playerData.newf)) {
- SysFlashrom_ReadData(sramCtx->saveBuf, gFlashSaveStartPages[phi_t1 + 1], gFlashSaveNumPages[phi_t1 + 1]);
+ SysFlashrom_ReadData(sramCtx->saveBuf, gFlashSaveStartPages[phi_t1 + FLASH_SAVE_BACKUP_OFFSET],
+ gFlashSaveNumPages[phi_t1 + FLASH_SAVE_BACKUP_OFFSET]);
memcpy(&gSaveContext, sramCtx->saveBuf, gFlashSaveSizes[phi_t1]);
}
}
@@ -1410,7 +1416,7 @@ void func_8014546C(SramContext* sramCtx) {
if (gSaveContext.flashSaveAvailable) {
memcpy(sramCtx->saveBuf, &gSaveContext, sizeof(Save));
- memcpy(&sramCtx->saveBuf[0x2000], &gSaveContext.save, sizeof(Save));
+ memcpy(&sramCtx->saveBuf[SAVE_BUFFER_SIZE_HALF], &gSaveContext.save, sizeof(Save));
}
}
}
@@ -1433,7 +1439,7 @@ void func_80145698(SramContext* sramCtx) {
gSaveContext.save.saveInfo.checksum = Sram_CalcChecksum(&gSaveContext.save, sizeof(Save));
if (gSaveContext.flashSaveAvailable) {
memcpy(sramCtx->saveBuf, &gSaveContext, sizeof(Save));
- memcpy(&sramCtx->saveBuf[0x2000], &gSaveContext.save, sizeof(Save));
+ memcpy(&sramCtx->saveBuf[SAVE_BUFFER_SIZE_HALF], &gSaveContext.save, sizeof(Save));
}
}
@@ -1455,7 +1461,7 @@ void func_801457CC(GameState* gameState, SramContext* sramCtx) {
D_801F6AF2 = gSaveContext.flashSaveAvailable;
sp64 = 0;
- for (sp76 = 0; sp76 < 5; sp76++, sp64 += 2) {
+ for (sp76 = 0; sp76 < FLASH_SAVE_MAX / 2; sp76++, sp64 += FLASH_SAVE_MAIN_MULTIPLIER) {
memset(sramCtx->saveBuf, 0, SAVE_BUFFER_SIZE);
phi_s2 = false;
@@ -1465,17 +1471,17 @@ void func_801457CC(GameState* gameState, SramContext* sramCtx) {
// main save didn't work
sp6E = 1;
// read backup save from flash
- if (SysFlashrom_ReadData(sramCtx->saveBuf, gFlashSaveStartPages[sp64 + 1],
- gFlashSaveNumPages[sp64 + 1]) != 0) {
+ if (SysFlashrom_ReadData(sramCtx->saveBuf, gFlashSaveStartPages[sp64 + FLASH_SAVE_BACKUP_OFFSET],
+ gFlashSaveNumPages[sp64 + FLASH_SAVE_BACKUP_OFFSET]) != 0) {
// backup save didn't work
phi_s2 = true;
}
}
- if (sp76 < 2) {
+ if (sp76 < FILE_NUM_MAX) {
// Non-owl save
- // sp76 = 0: main save
- // sp76 = 1: backup save
+ // sp76 = 0: file 1
+ // sp76 = 1: file 2
fileSelect->isOwlSave[sp76] = 0;
if (phi_s2) {
@@ -1503,8 +1509,9 @@ void func_801457CC(GameState* gameState, SramContext* sramCtx) {
// read backup save from flash
phi_s2 = false;
- if (SysFlashrom_ReadData(sramCtx->saveBuf, gFlashSaveStartPages[sp64 + 1],
- gFlashSaveNumPages[sp64 + 1]) != 0) {
+ if (SysFlashrom_ReadData(sramCtx->saveBuf,
+ gFlashSaveStartPages[sp64 + FLASH_SAVE_BACKUP_OFFSET],
+ gFlashSaveNumPages[sp64 + FLASH_SAVE_BACKUP_OFFSET]) != 0) {
// backup save didn't work
phi_s2 = true;
}
@@ -1562,14 +1569,14 @@ void func_801457CC(GameState* gameState, SramContext* sramCtx) {
if (sp6E == 1) {
// backup save
- memcpy(&sramCtx->saveBuf[0x2000], &gSaveContext.save, sizeof(Save));
+ memcpy(&sramCtx->saveBuf[SAVE_BUFFER_SIZE_HALF], &gSaveContext.save, sizeof(Save));
Sram_SyncWriteToFlash(sramCtx, gFlashSaveStartPages[sp64], gFlashSpecialSaveNumPages[sp64]);
} else if (!sp6E) {
// main save
oldCheckSum = gSaveContext.save.saveInfo.checksum;
- if (SysFlashrom_ReadData(sramCtx->saveBuf, gFlashSaveStartPages[sp64 + 1],
- gFlashSaveNumPages[sp64 + 1]) != 0) {
+ if (SysFlashrom_ReadData(sramCtx->saveBuf, gFlashSaveStartPages[sp64 + FLASH_SAVE_BACKUP_OFFSET],
+ gFlashSaveNumPages[sp64 + FLASH_SAVE_BACKUP_OFFSET]) != 0) {
phi_s2 = 1;
} else {
memcpy(&gSaveContext.save, sramCtx->saveBuf, sizeof(Save));
@@ -1582,17 +1589,17 @@ void func_801457CC(GameState* gameState, SramContext* sramCtx) {
(oldCheckSum != phi_s2)) {
SysFlashrom_ReadData(sramCtx->saveBuf, gFlashSaveStartPages[sp64], gFlashSaveNumPages[sp64]);
memcpy(&gSaveContext.save, sramCtx->saveBuf, sizeof(Save));
- memcpy(&sramCtx->saveBuf[0x2000], &gSaveContext.save, sizeof(Save));
+ memcpy(&sramCtx->saveBuf[SAVE_BUFFER_SIZE_HALF], &gSaveContext.save, sizeof(Save));
Sram_SyncWriteToFlash(sramCtx, gFlashSaveStartPages[sp64], gFlashSpecialSaveNumPages[sp64]);
}
}
- } else if (sp76 < 4) {
+ } else if (sp76 < FILE_NUM_MAX_WITH_OWL_SAVE) {
// Owl Save:
- // sp76 = 3: main owl save
- // sp76 = 4: backup owl save
+ // sp76 = 2: file 1
+ // sp76 = 3: file 2
fileSelect->isOwlSave[sp76] = 0;
- if (!CHECK_NEWF(fileSelect->newf[sp76 - 2])) {
+ if (!CHECK_NEWF(fileSelect->newf[sp76 - FILE_NUM_OWL_SAVE_OFFSET])) {
if (phi_s2) {
// both main save and backup save failed
memset(sramCtx->saveBuf, 0, SAVE_BUFFER_SIZE);
@@ -1617,8 +1624,9 @@ void func_801457CC(GameState* gameState, SramContext* sramCtx) {
phi_s2 = false;
// read backup save from flash
- if (SysFlashrom_ReadData(sramCtx->saveBuf, gFlashSaveStartPages[sp64 + 1],
- gFlashSaveNumPages[sp64 + 1]) != 0) {
+ if (SysFlashrom_ReadData(sramCtx->saveBuf,
+ gFlashSaveStartPages[sp64 + FLASH_SAVE_BACKUP_OFFSET],
+ gFlashSaveNumPages[sp64 + FLASH_SAVE_BACKUP_OFFSET]) != 0) {
// backup save didn't work
phi_s2 = true;
}
@@ -1677,13 +1685,15 @@ void func_801457CC(GameState* gameState, SramContext* sramCtx) {
if (sp6E == 1) {
// backup save
Sram_SyncWriteToFlash(sramCtx, gFlashSaveStartPages[sp64], gFlashSaveNumPages[sp64]);
- Sram_SyncWriteToFlash(sramCtx, gFlashSaveStartPages[sp64 + 1], gFlashSaveNumPages[sp64 + 1]);
+ Sram_SyncWriteToFlash(sramCtx, gFlashSaveStartPages[sp64 + FLASH_SAVE_BACKUP_OFFSET],
+ gFlashSaveNumPages[sp64 + FLASH_SAVE_BACKUP_OFFSET]);
} else if (!sp6E) {
// main save
oldCheckSum = gSaveContext.save.saveInfo.checksum;
- if (SysFlashrom_ReadData(sramCtx->saveBuf, gFlashSaveStartPages[sp64 + 1],
- gFlashSaveNumPages[sp64 + 1]) != 0) {
+ if (SysFlashrom_ReadData(sramCtx->saveBuf,
+ gFlashSaveStartPages[sp64 + FLASH_SAVE_BACKUP_OFFSET],
+ gFlashSaveNumPages[sp64 + FLASH_SAVE_BACKUP_OFFSET]) != 0) {
phi_s2 = 1;
} else {
memcpy(&gSaveContext, sramCtx->saveBuf, gFlashSaveSizes[sp64]);
@@ -1698,15 +1708,16 @@ void func_801457CC(GameState* gameState, SramContext* sramCtx) {
gFlashSaveNumPages[sp64]);
memcpy(&gSaveContext, sramCtx->saveBuf, gFlashSaveSizes[sp64]);
Sram_SyncWriteToFlash(sramCtx, gFlashSaveStartPages[sp64], gFlashSaveNumPages[sp64]);
- Sram_SyncWriteToFlash(sramCtx, gFlashSaveStartPages[sp64 + 1],
- gFlashSaveNumPages[sp64 + 1]);
+ Sram_SyncWriteToFlash(sramCtx, gFlashSaveStartPages[sp64 + FLASH_SAVE_BACKUP_OFFSET],
+ gFlashSaveNumPages[sp64 + FLASH_SAVE_BACKUP_OFFSET]);
}
}
} else {
memset(sramCtx->saveBuf, 0, SAVE_BUFFER_SIZE);
memcpy(&gSaveContext, sramCtx->saveBuf, gFlashSaveSizes[sp64]);
Sram_SyncWriteToFlash(sramCtx, gFlashSaveStartPages[sp64], gFlashSaveNumPages[sp64]);
- Sram_SyncWriteToFlash(sramCtx, gFlashSaveStartPages[sp64 + 1], gFlashSaveNumPages[sp64 + 1]);
+ Sram_SyncWriteToFlash(sramCtx, gFlashSaveStartPages[sp64 + FLASH_SAVE_BACKUP_OFFSET],
+ gFlashSaveNumPages[sp64 + FLASH_SAVE_BACKUP_OFFSET]);
}
} else {
if (phi_s2) {
@@ -1741,9 +1752,9 @@ void Sram_EraseSave(FileSelectState* fileSelect2, SramContext* sramCtx, s32 file
s32 pad;
if (gSaveContext.flashSaveAvailable) {
- if (fileSelect->isOwlSave[fileNum + 2]) {
+ if (fileSelect->isOwlSave[fileNum + FILE_NUM_OWL_SAVE_OFFSET]) {
func_80147314(sramCtx, fileNum);
- fileSelect->isOwlSave[fileNum + 2] = false;
+ fileSelect->isOwlSave[fileNum + FILE_NUM_OWL_SAVE_OFFSET] = false;
}
memset(sramCtx->saveBuf, 0, SAVE_BUFFER_SIZE);
memcpy(&gSaveContext, sramCtx->saveBuf, sizeof(Save));
@@ -1759,27 +1770,32 @@ void Sram_CopySave(FileSelectState* fileSelect2, SramContext* sramCtx) {
s16 maskCount;
if (gSaveContext.flashSaveAvailable) {
- if (fileSelect->isOwlSave[fileSelect->selectedFileIndex + 2]) {
+ if (fileSelect->isOwlSave[fileSelect->selectedFileIndex + FILE_NUM_OWL_SAVE_OFFSET]) {
func_80147414(sramCtx, fileSelect->selectedFileIndex, fileSelect->copyDestFileIndex);
- fileSelect->threeDayResetCount[fileSelect->copyDestFileIndex + 2] =
+ fileSelect->threeDayResetCount[fileSelect->copyDestFileIndex + FILE_NUM_OWL_SAVE_OFFSET] =
gSaveContext.save.saveInfo.playerData.threeDayResetCount;
for (i = 0; i < ARRAY_COUNT(gSaveContext.save.saveInfo.playerData.playerName); i++) {
- fileSelect->fileNames[fileSelect->copyDestFileIndex + 2][i] =
+ fileSelect->fileNames[fileSelect->copyDestFileIndex + FILE_NUM_OWL_SAVE_OFFSET][i] =
gSaveContext.save.saveInfo.playerData.playerName[i];
}
- fileSelect->healthCapacity[fileSelect->copyDestFileIndex + 2] =
+ fileSelect->healthCapacity[fileSelect->copyDestFileIndex + FILE_NUM_OWL_SAVE_OFFSET] =
gSaveContext.save.saveInfo.playerData.healthCapacity;
- fileSelect->health[fileSelect->copyDestFileIndex + 2] = gSaveContext.save.saveInfo.playerData.health;
- fileSelect->defenseHearts[fileSelect->copyDestFileIndex + 2] =
+ fileSelect->health[fileSelect->copyDestFileIndex + FILE_NUM_OWL_SAVE_OFFSET] =
+ gSaveContext.save.saveInfo.playerData.health;
+ fileSelect->defenseHearts[fileSelect->copyDestFileIndex + FILE_NUM_OWL_SAVE_OFFSET] =
gSaveContext.save.saveInfo.inventory.defenseHearts;
- fileSelect->questItems[fileSelect->copyDestFileIndex + 2] = gSaveContext.save.saveInfo.inventory.questItems;
- fileSelect->time[fileSelect->copyDestFileIndex + 2] = gSaveContext.save.time;
- fileSelect->day[fileSelect->copyDestFileIndex + 2] = gSaveContext.save.day;
- fileSelect->isOwlSave[fileSelect->copyDestFileIndex + 2] = gSaveContext.save.isOwlSave;
- fileSelect->rupees[fileSelect->copyDestFileIndex + 2] = gSaveContext.save.saveInfo.playerData.rupees;
- fileSelect->walletUpgrades[fileSelect->copyDestFileIndex + 2] = CUR_UPG_VALUE(UPG_WALLET);
+ fileSelect->questItems[fileSelect->copyDestFileIndex + FILE_NUM_OWL_SAVE_OFFSET] =
+ gSaveContext.save.saveInfo.inventory.questItems;
+ fileSelect->time[fileSelect->copyDestFileIndex + FILE_NUM_OWL_SAVE_OFFSET] = gSaveContext.save.time;
+ fileSelect->day[fileSelect->copyDestFileIndex + FILE_NUM_OWL_SAVE_OFFSET] = gSaveContext.save.day;
+ fileSelect->isOwlSave[fileSelect->copyDestFileIndex + FILE_NUM_OWL_SAVE_OFFSET] =
+ gSaveContext.save.isOwlSave;
+ fileSelect->rupees[fileSelect->copyDestFileIndex + FILE_NUM_OWL_SAVE_OFFSET] =
+ gSaveContext.save.saveInfo.playerData.rupees;
+ fileSelect->walletUpgrades[fileSelect->copyDestFileIndex + FILE_NUM_OWL_SAVE_OFFSET] =
+ CUR_UPG_VALUE(UPG_WALLET);
for (i = 0, maskCount = 0; i < MASK_NUM_SLOTS; i++) {
if (gSaveContext.save.saveInfo.inventory.items[i + ITEM_NUM_SLOTS] != ITEM_NONE) {
@@ -1787,18 +1803,23 @@ void Sram_CopySave(FileSelectState* fileSelect2, SramContext* sramCtx) {
}
}
- fileSelect->maskCount[fileSelect->copyDestFileIndex + 2] = maskCount;
- fileSelect->heartPieceCount[fileSelect->copyDestFileIndex + 2] = GET_QUEST_HEART_PIECE_COUNT;
+ fileSelect->maskCount[fileSelect->copyDestFileIndex + FILE_NUM_OWL_SAVE_OFFSET] = maskCount;
+ fileSelect->heartPieceCount[fileSelect->copyDestFileIndex + FILE_NUM_OWL_SAVE_OFFSET] =
+ GET_QUEST_HEART_PIECE_COUNT;
}
// clear buffer
memset(sramCtx->saveBuf, 0, SAVE_BUFFER_SIZE);
// read to buffer
- if (SysFlashrom_ReadData(&sramCtx->saveBuf[0], gFlashSaveStartPages[fileSelect->selectedFileIndex * 2],
- gFlashSaveNumPages[fileSelect->selectedFileIndex * 2])) {}
+ if (SysFlashrom_ReadData(&sramCtx->saveBuf[0],
+ gFlashSaveStartPages[fileSelect->selectedFileIndex * FLASH_SAVE_MAIN_MULTIPLIER],
+ gFlashSaveNumPages[fileSelect->selectedFileIndex * FLASH_SAVE_MAIN_MULTIPLIER])) {}
- if (SysFlashrom_ReadData(&sramCtx->saveBuf[0x2000], gFlashSaveStartPages[fileSelect->selectedFileIndex * 2 + 1],
- gFlashSaveNumPages[fileSelect->selectedFileIndex * 2 + 1])) {}
+ if (SysFlashrom_ReadData(&sramCtx->saveBuf[SAVE_BUFFER_SIZE_HALF],
+ gFlashSaveStartPages[fileSelect->selectedFileIndex * FLASH_SAVE_MAIN_MULTIPLIER +
+ FLASH_SAVE_BACKUP_OFFSET],
+ gFlashSaveNumPages[fileSelect->selectedFileIndex * FLASH_SAVE_MAIN_MULTIPLIER +
+ FLASH_SAVE_BACKUP_OFFSET])) {}
// copy buffer to save context
memcpy(&gSaveContext.save, sramCtx->saveBuf, sizeof(Save));
@@ -1865,7 +1886,7 @@ void Sram_InitSave(FileSelectState* fileSelect2, SramContext* sramCtx) {
GameInteractor_ExecuteOnSaveInit(fileSelect->buttonIndex);
memcpy(sramCtx->saveBuf, &gSaveContext.save, sizeof(Save));
- memcpy(&sramCtx->saveBuf[0x2000], &gSaveContext.save, sizeof(Save));
+ memcpy(&sramCtx->saveBuf[SAVE_BUFFER_SIZE_HALF], &gSaveContext.save, sizeof(Save));
for (i = 0; i < ARRAY_COUNT(gSaveContext.save.saveInfo.playerData.newf); i++) {
fileSelect->newf[fileSelect->buttonIndex][i] = gSaveContext.save.saveInfo.playerData.newf[i];
@@ -1944,8 +1965,8 @@ void Sram_SaveSpecialEnterClockTown(PlayState* play) {
gSaveContext.save.isFirstCycle = true;
gSaveContext.save.isOwlSave = false;
func_80145698(sramCtx);
- SysFlashrom_WriteDataSync(sramCtx->saveBuf, gFlashSaveStartPages[gSaveContext.fileNum * 2],
- gFlashSpecialSaveNumPages[gSaveContext.fileNum * 2]);
+ SysFlashrom_WriteDataSync(sramCtx->saveBuf, gFlashSaveStartPages[gSaveContext.fileNum * FLASH_SAVE_MAIN_MULTIPLIER],
+ gFlashSpecialSaveNumPages[gSaveContext.fileNum * FLASH_SAVE_MAIN_MULTIPLIER]);
}
/**
@@ -1966,8 +1987,9 @@ void Sram_SaveSpecialNewDay(PlayState* play) {
gSaveContext.save.day = day;
gSaveContext.save.time = time;
gSaveContext.save.cutsceneIndex = cutsceneIndex;
- SysFlashrom_WriteDataSync(play->sramCtx.saveBuf, gFlashSaveStartPages[gSaveContext.fileNum * 2],
- gFlashSaveNumPages[gSaveContext.fileNum * 2]);
+ SysFlashrom_WriteDataSync(play->sramCtx.saveBuf,
+ gFlashSaveStartPages[gSaveContext.fileNum * FLASH_SAVE_MAIN_MULTIPLIER],
+ gFlashSaveNumPages[gSaveContext.fileNum * FLASH_SAVE_MAIN_MULTIPLIER]);
}
void Sram_SetFlashPagesDefault(SramContext* sramCtx, u32 curPage, u32 numPages) {
@@ -2065,9 +2087,12 @@ void func_80147314(SramContext* sramCtx, s32 fileNum) {
gSaveContext.save.saveInfo.checksum = Sram_CalcChecksum(&gSaveContext, offsetof(SaveContext, fileNum));
memcpy(sramCtx->saveBuf, &gSaveContext, offsetof(SaveContext, fileNum));
- Sram_SyncWriteToFlash(sramCtx, gFlashOwlSaveStartPages[fileNum * 2], gFlashOwlSaveNumPages[fileNum * 2]);
- //! Note: should be `gFlashOwlSaveNumPages[fileNum * 2 + 1]`?
- Sram_SyncWriteToFlash(sramCtx, gFlashOwlSaveStartPages[fileNum * 2 + 1], gFlashOwlSaveNumPages[fileNum * 2]);
+ Sram_SyncWriteToFlash(sramCtx, gFlashOwlSaveStartPages[fileNum * FLASH_SAVE_MAIN_MULTIPLIER],
+ gFlashOwlSaveNumPages[fileNum * FLASH_SAVE_MAIN_MULTIPLIER]);
+ //! Note: should be `gFlashOwlSaveNumPages[fileNum * FLASH_SAVE_MAIN_MULTIPLIER + FLASH_SAVE_BACKUP_OFFSET]`?
+ Sram_SyncWriteToFlash(sramCtx,
+ gFlashOwlSaveStartPages[fileNum * FLASH_SAVE_MAIN_MULTIPLIER + FLASH_SAVE_BACKUP_OFFSET],
+ gFlashOwlSaveNumPages[fileNum * FLASH_SAVE_MAIN_MULTIPLIER]);
gSaveContext.save.isOwlSave = true;
@@ -2087,18 +2112,22 @@ void func_80147414(SramContext* sramCtx, s32 fileNum, s32 arg2) {
memset(sramCtx->saveBuf, 0, SAVE_BUFFER_SIZE);
// Read save file
- if (SysFlashrom_ReadData(sramCtx->saveBuf, gFlashOwlSaveStartPages[fileNum * 2],
- gFlashOwlSaveNumPages[fileNum * 2]) != 0) {
+ if (SysFlashrom_ReadData(sramCtx->saveBuf, gFlashOwlSaveStartPages[fileNum * FLASH_SAVE_MAIN_MULTIPLIER],
+ gFlashOwlSaveNumPages[fileNum * FLASH_SAVE_MAIN_MULTIPLIER]) != 0) {
// If failed, read backup save file
- SysFlashrom_ReadData(sramCtx->saveBuf, gFlashOwlSaveStartPages[fileNum * 2 + 1],
- gFlashOwlSaveNumPages[fileNum * 2 + 1]);
+ SysFlashrom_ReadData(sramCtx->saveBuf,
+ gFlashOwlSaveStartPages[fileNum * FLASH_SAVE_MAIN_MULTIPLIER + FLASH_SAVE_BACKUP_OFFSET],
+ gFlashOwlSaveNumPages[fileNum * FLASH_SAVE_MAIN_MULTIPLIER + FLASH_SAVE_BACKUP_OFFSET]);
}
// Copy buffer to save context
memcpy(&gSaveContext, sramCtx->saveBuf, offsetof(SaveContext, fileNum));
- Sram_SyncWriteToFlash(sramCtx, gFlashOwlSaveStartPages[arg2 * 2], gFlashOwlSaveNumPages[arg2 * 2]);
- Sram_SyncWriteToFlash(sramCtx, gFlashOwlSaveStartPages[arg2 * 2 + 1], gFlashOwlSaveNumPages[arg2 * 2]);
+ Sram_SyncWriteToFlash(sramCtx, gFlashOwlSaveStartPages[arg2 * FLASH_SAVE_MAIN_MULTIPLIER],
+ gFlashOwlSaveNumPages[arg2 * FLASH_SAVE_MAIN_MULTIPLIER]);
+ Sram_SyncWriteToFlash(sramCtx,
+ gFlashOwlSaveStartPages[arg2 * FLASH_SAVE_MAIN_MULTIPLIER + FLASH_SAVE_BACKUP_OFFSET],
+ gFlashOwlSaveNumPages[arg2 * FLASH_SAVE_MAIN_MULTIPLIER]);
}
void Sram_nop8014750C(UNK_TYPE4 arg0) {