summaryrefslogtreecommitdiff
path: root/src/code
diff options
context:
space:
mode:
authorengineer124 <47598039+engineer124@users.noreply.github.com>2023-06-06 05:03:02 +1000
committerGitHub <noreply@github.com>2023-06-05 15:03:02 -0400
commit8cabbb1a2bd282e0a757385aa8d23d710aaafb13 (patch)
tree8a726686e1e6359a3f081e5651424203b67c5ca3 /src/code
parentcd53dd317fa1ce2958f2c6af618059a31db59076 (diff)
File Select (1 Non-Matching) (#1158)
* Everything below Main OK, and some small ones at the top * 3 more short ones * FileChoose_Main * SelectModeUpdate/Draw * SelectMode update functions done * 2 more small ones * ConfigModeDraw * SetWindowVtx * FileChoose_FadeInMenuElements * Rest of the Config Mode Update Functions * Minor cleanup * FileChoose_UpdateMainMenu * Make xml for title_static * Minor correction * One nasty draw, thanks Synray Co-Authored-By: Synray <31429825+Synray@users.noreply.github.com> * import data * some cleanup * import OoT docs * missed some docs * some progress * FileSelect_SetWindowContentVtx WIP * improve FileSelect_SetWindowContentVtx * match z_file_nameset_NES * cleanup and docs * title static * a few more functions * even more functions * small cleanup * Data Cleanup * 2 more matches * z_file_choose_80807940 OK * cleanup * fix merge master * FileSelect_DrawFileInfo wip * small cleanup * minor * fix merge * match FileSelect_DrawFileInfo * cleanup * fix merge * fix merge * sram cleanup * document select mode * many docs * more docs * more cleanup * small nitpick * consistency * more cleanup * more cleanup * small * small typos * octal bad * pr review * noop * elliptic review * more review * non-matching * oops * more suggestions * keyboard formatting * fix master * sound * padding --------- Co-authored-by: Elliptic Ellipsis <elliptic.ellipsis@gmail.com> Co-authored-by: Synray <31429825+Synray@users.noreply.github.com>
Diffstat (limited to 'src/code')
-rw-r--r--src/code/graph.c2
-rw-r--r--src/code/z_common_data.c6
-rw-r--r--src/code/z_demo.c21
-rw-r--r--src/code/z_game_dlftbls.c2
-rw-r--r--src/code/z_game_over.c2
-rw-r--r--src/code/z_lifemeter.c4
-rw-r--r--src/code/z_parameter.c2
-rw-r--r--src/code/z_play.c12
-rw-r--r--src/code/z_scene.c4
-rw-r--r--src/code/z_sram_NES.c609
-rw-r--r--src/code/z_vr_box.c4
11 files changed, 400 insertions, 268 deletions
diff --git a/src/code/graph.c b/src/code/graph.c
index bf9067b69..2e104234e 100644
--- a/src/code/graph.c
+++ b/src/code/graph.c
@@ -2,7 +2,7 @@
#include "buffers.h"
#include "system_malloc.h"
#include "overlays/gamestates/ovl_daytelop/z_daytelop.h"
-#include "overlays/gamestates/ovl_file_choose/z_file_choose.h"
+#include "overlays/gamestates/ovl_file_choose/z_file_select.h"
#include "overlays/gamestates/ovl_opening/z_opening.h"
#include "overlays/gamestates/ovl_select/z_select.h"
#include "overlays/gamestates/ovl_title/z_title.h"
diff --git a/src/code/z_common_data.c b/src/code/z_common_data.c
index 0e682231f..46dfe189e 100644
--- a/src/code/z_common_data.c
+++ b/src/code/z_common_data.c
@@ -8,10 +8,10 @@ void SaveContext_Init(void) {
gSaveContext.save.playerForm = 0;
gSaveContext.seqId = (u8)NA_BGM_DISABLED;
gSaveContext.ambienceId = AMBIENCE_ID_DISABLED;
- gSaveContext.unk_3F46 = NA_BGM_GENERAL_SFX;
+ gSaveContext.forcedSeqId = NA_BGM_GENERAL_SFX;
gSaveContext.nextCutsceneIndex = 0xFFEF;
gSaveContext.cutsceneTrigger = 0;
- gSaveContext.unk_3F4D = 0;
+ gSaveContext.chamberCutsceneNum = 0;
gSaveContext.nextDayTime = 0xFFFF;
gSaveContext.skyboxTime = 0;
gSaveContext.dogIsLost = true;
@@ -19,6 +19,6 @@ void SaveContext_Init(void) {
gSaveContext.prevHudVisibility = HUD_VISIBILITY_ALL;
gSaveContext.options.language = 1;
- gSaveContext.options.audioSetting = 0;
+ gSaveContext.options.audioSetting = SAVE_AUDIO_STEREO;
gSaveContext.options.zTargetSetting = 0;
}
diff --git a/src/code/z_demo.c b/src/code/z_demo.c
index 733ec4bc1..00ee877e9 100644
--- a/src/code/z_demo.c
+++ b/src/code/z_demo.c
@@ -171,15 +171,15 @@ void CutsceneCmd_Misc(PlayState* play, CutsceneContext* csCtx, CsCmdMisc* cmd) {
case CS_MISC_CLOUDY_SKY:
if (isFirstFrame) {
- play->envCtx.unk_19 = 1;
- play->envCtx.unk_17 = 1;
- play->envCtx.unk_18 = 0;
- play->envCtx.unk_1A = 0x3C;
- play->envCtx.unk_21 = 1;
- play->envCtx.unk_1F = 0;
- play->envCtx.unk_20 = 1;
- play->envCtx.unk_24 = 0x3C;
- play->envCtx.unk_22 = play->envCtx.unk_24;
+ play->envCtx.changeSkyboxState = 1;
+ play->envCtx.skyboxConfig = 1;
+ play->envCtx.changeSkyboxNextConfig = 0;
+ play->envCtx.changeSkyboxTimer = 60;
+ play->envCtx.changeLightEnabled = true;
+ play->envCtx.lightConfig = 0;
+ play->envCtx.changeLightNextConfig = 1;
+ play->envCtx.changeDuration = 60;
+ play->envCtx.changeLightTimer = play->envCtx.changeDuration;
}
break;
@@ -327,8 +327,7 @@ void CutsceneCmd_Misc(PlayState* play, CutsceneContext* csCtx, CsCmdMisc* cmd) {
case CS_MISC_MOON_CRASH_SKYBOX:
if (isFirstFrame) {
- // skyboxConfig
- play->envCtx.unk_17 = 0xD;
+ play->envCtx.skyboxConfig = 0xD;
}
break;
diff --git a/src/code/z_game_dlftbls.c b/src/code/z_game_dlftbls.c
index 1b82705f5..7336b01f6 100644
--- a/src/code/z_game_dlftbls.c
+++ b/src/code/z_game_dlftbls.c
@@ -1,6 +1,6 @@
#include "global.h"
#include "overlays/gamestates/ovl_daytelop/z_daytelop.h"
-#include "overlays/gamestates/ovl_file_choose/z_file_choose.h"
+#include "overlays/gamestates/ovl_file_choose/z_file_select.h"
#include "overlays/gamestates/ovl_opening/z_opening.h"
#include "overlays/gamestates/ovl_select/z_select.h"
#include "overlays/gamestates/ovl_title/z_title.h"
diff --git a/src/code/z_game_over.c b/src/code/z_game_over.c
index d0e5e45f2..c3c6819be 100644
--- a/src/code/z_game_over.c
+++ b/src/code/z_game_over.c
@@ -49,7 +49,7 @@ void GameOver_Update(PlayState* play) {
}
}
- gSaveContext.unk_3DC0 = 2000;
+ gSaveContext.nayrusLoveTimer = 2000;
gSaveContext.save.saveInfo.playerData.tatlTimer = 0;
gSaveContext.seqId = (u8)NA_BGM_DISABLED;
gSaveContext.ambienceId = AMBIENCE_ID_DISABLED;
diff --git a/src/code/z_lifemeter.c b/src/code/z_lifemeter.c
index c9bea1669..7226a6719 100644
--- a/src/code/z_lifemeter.c
+++ b/src/code/z_lifemeter.c
@@ -16,14 +16,14 @@ s16 sBeatingHeartsDDEnv[3];
s16 sHeartsDDPrim[2][3];
s16 sHeartsDDEnv[2][3];
-TexturePtr sHeartTextures[] = {
+static TexturePtr sHeartTextures[] = {
gHeartFullTex, gHeartQuarterTex, gHeartQuarterTex, gHeartQuarterTex,
gHeartQuarterTex, gHeartQuarterTex, gHeartHalfTex, gHeartHalfTex,
gHeartHalfTex, gHeartHalfTex, gHeartHalfTex, gHeartThreeQuarterTex,
gHeartThreeQuarterTex, gHeartThreeQuarterTex, gHeartThreeQuarterTex, gHeartThreeQuarterTex,
};
-TexturePtr sHeartDDTextures[] = {
+static TexturePtr sHeartDDTextures[] = {
gDefenseHeartFullTex, gDefenseHeartQuarterTex, gDefenseHeartQuarterTex,
gDefenseHeartQuarterTex, gDefenseHeartQuarterTex, gDefenseHeartQuarterTex,
gDefenseHeartHalfTex, gDefenseHeartHalfTex, gDefenseHeartHalfTex,
diff --git a/src/code/z_parameter.c b/src/code/z_parameter.c
index 9672b8804..f8f28f4b8 100644
--- a/src/code/z_parameter.c
+++ b/src/code/z_parameter.c
@@ -147,7 +147,7 @@ s16 D_801BF97C = 255;
f32 D_801BF980 = 1.0f;
s32 D_801BF984 = 0;
-Gfx sScreenFillSetupDL[] = {
+static Gfx sScreenFillSetupDL[] = {
gsDPPipeSync(),
gsSPClearGeometryMode(G_ZBUFFER | G_SHADE | G_CULL_BOTH | G_FOG | G_LIGHTING | G_TEXTURE_GEN |
G_TEXTURE_GEN_LINEAR | G_LOD | G_SHADING_SMOOTH),
diff --git a/src/code/z_play.c b/src/code/z_play.c
index dade44cf6..dd9b6c561 100644
--- a/src/code/z_play.c
+++ b/src/code/z_play.c
@@ -7,7 +7,7 @@
#include "z64view.h"
#include "overlays/gamestates/ovl_daytelop/z_daytelop.h"
#include "overlays/gamestates/ovl_opening/z_opening.h"
-#include "overlays/gamestates/ovl_file_choose/z_file_choose.h"
+#include "overlays/gamestates/ovl_file_choose/z_file_select.h"
#include "overlays/kaleido_scope/ovl_kaleido_scope/z_kaleido_scope.h"
s32 gDbgCamEnabled = false;
@@ -1036,9 +1036,9 @@ void Play_UpdateMain(PlayState* this) {
if (this->sramCtx.status != 0) {
if (gSaveContext.save.isOwlSave) {
- func_80147198(&this->sramCtx);
+ Sram_UpdateWriteToFlashOwlSave(&this->sramCtx);
} else {
- func_80147068(&this->sramCtx);
+ Sram_UpdateWriteToFlashDefault(&this->sramCtx);
}
}
}
@@ -1272,8 +1272,8 @@ void Play_DrawMain(PlayState* this) {
if ((this->skyboxId != SKYBOX_NONE) && !this->envCtx.skyboxDisabled) {
if ((this->skyboxId == SKYBOX_NORMAL_SKY) || (this->skyboxId == SKYBOX_3)) {
Environment_UpdateSkybox(this->skyboxId, &this->envCtx, &this->skyboxCtx);
- Skybox_Draw(&this->skyboxCtx, gfxCtx, this->skyboxId, this->envCtx.unk_13, this->view.eye.x,
- this->view.eye.y, this->view.eye.z);
+ Skybox_Draw(&this->skyboxCtx, gfxCtx, this->skyboxId, this->envCtx.skyboxBlend,
+ this->view.eye.x, this->view.eye.y, this->view.eye.z);
} else if (!this->skyboxCtx.skyboxShouldDraw) {
Skybox_Draw(&this->skyboxCtx, gfxCtx, this->skyboxId, 0, this->view.eye.x, this->view.eye.y,
this->view.eye.z);
@@ -2217,7 +2217,7 @@ void Play_Init(GameState* thisx) {
if (((gSaveContext.gameMode != GAMEMODE_NORMAL) && (gSaveContext.gameMode != GAMEMODE_TITLE_SCREEN)) ||
(gSaveContext.save.cutsceneIndex >= 0xFFF0)) {
- gSaveContext.unk_3DC0 = 0;
+ gSaveContext.nayrusLoveTimer = 0;
Magic_Reset(this);
gSaveContext.sceneLayer = (gSaveContext.save.cutsceneIndex & 0xF) + 1;
diff --git a/src/code/z_scene.c b/src/code/z_scene.c
index 623db6b24..368b4509e 100644
--- a/src/code/z_scene.c
+++ b/src/code/z_scene.c
@@ -365,8 +365,8 @@ void Scene_LoadAreaTextures(PlayState* play, s32 fileIndex) {
// SceneTableEntry Header Command 0x11: Skybox Settings
void Scene_CommandSkyboxSettings(PlayState* play, SceneCmd* cmd) {
play->skyboxId = cmd->skyboxSettings.skyboxId & 3;
- play->envCtx.unk_17 = play->envCtx.unk_18 = cmd->skyboxSettings.unk5;
- play->envCtx.unk_1E = cmd->skyboxSettings.unk6;
+ play->envCtx.skyboxConfig = play->envCtx.changeSkyboxNextConfig = cmd->skyboxSettings.skyboxConfig;
+ play->envCtx.lightMode = cmd->skyboxSettings.envLightMode;
Scene_LoadAreaTextures(play, cmd->skyboxSettings.data1);
}
diff --git a/src/code/z_sram_NES.c b/src/code/z_sram_NES.c
index f47a8e201..21bfaf7ef 100644
--- a/src/code/z_sram_NES.c
+++ b/src/code/z_sram_NES.c
@@ -1,9 +1,9 @@
#include "prevent_bss_reordering.h"
#include "global.h"
#include "z64horse.h"
-#include "overlays/gamestates/ovl_file_choose/z_file_choose.h"
+#include "overlays/gamestates/ovl_file_choose/z_file_select.h"
-void func_80146EBC(SramContext* sramCtx, s32 curPage, s32 numPages);
+void Sram_SyncWriteToFlash(SramContext* sramCtx, s32 curPage, s32 numPages);
void func_80147314(SramContext* sramCtx, s32 fileNum);
void func_80147414(SramContext* sramCtx, s32 fileNum, s32 arg2);
@@ -140,9 +140,21 @@ u16 D_801C66D0[ARRAY_COUNT(gSaveContext.save.saveInfo.weekEventReg)] = {
/* 99 */ 0,
};
+// Unused remnant values from OoT. Not the correct sizes in MM.
+#define OOT_SAVECONTEXT_SIZE 0x1428
+#define OOT_SLOT_SIZE (OOT_SAVECONTEXT_SIZE + 0x28)
+#define OOT_SRAM_HEADER_SIZE 0x10
+#define OOT_SLOT_OFFSET(index) (OOT_SRAM_HEADER_SIZE + 0x10 + (index * OOT_SLOT_SIZE))
+
// used in other files
-s32 D_801C6798[] = {
- 0x00000020, 0x00001470, 0x000028C0, 0x00003D10, 0x00005160, 0x000065B0,
+u32 gSramSlotOffsets[] = {
+ OOT_SLOT_OFFSET(0),
+ OOT_SLOT_OFFSET(1),
+ OOT_SLOT_OFFSET(2),
+ // the latter three saves are backup saves for the former saves (in OoT)
+ OOT_SLOT_OFFSET(3),
+ OOT_SLOT_OFFSET(4),
+ OOT_SLOT_OFFSET(5),
};
u8 gAmmoItems[] = {
@@ -172,28 +184,89 @@ u8 gAmmoItems[] = {
ITEM_NONE, // SLOT_BOTTLE_6
};
-s32 D_801C67C8[] = { 0, 0x40, 0x80, 0xC0, 0x100, 0x180, 0x200, 0x280, 0x300, 0x380 };
+// Stores flash start page number
+s32 gFlashSaveStartPages[] = {
+ 0, // File 1 New Cycle Save
+ 0x40, // File 1 New Cycle Save Backup
+ 0x80, // File 2 New Cycle Save
+ 0xC0, // File 2 New Cycle Save Backup
+ 0x100, // File 1 Owl Save
+ 0x180, // File 1 Owl Save Backup
+ 0x200, // File 2 Owl Save
+ 0x280, // File 2 Owl Save Backup
+ 0x300, // Sram Header (SaveOptions)
+ 0x380, // Sram Header Backup (SaveOptions)
+};
+
+// Flash rom number of pages
+s32 gFlashSaveNumPages[] = {
+ 0x40, // File 1 New Cycle Save
+ 0x40, // File 1 New Cycle Save Backup
+ 0x40, // File 2 New Cycle Save
+ 0x40, // File 2 New Cycle Save Backup
+ 0x80, // File 1 Owl Save
+ 0x80, // File 1 Owl Save Backup
+ 0x80, // File 2 Owl Save
+ 0x80, // File 2 Owl Save Backup
+ 1, // Sram Header (SaveOptions)
+ 1, // Sram Header Backup (SaveOptions)
+};
-s32 D_801C67F0[] = { 0x40, 0x40, 0x40, 0x40, 0x80, 0x80, 0x80, 0x80, 1, 1 };
+// Flash rom number of pages on very first time Player enters South Clock Town from the Clock Tower
+s32 gFlashSpecialSaveNumPages[] = {
+ 0x80, // File 1 New Cycle Save
+ 0x80, // File 1 New Cycle Save Backup
+ 0x80, // File 2 New Cycle Save
+ 0x80, // File 2 New Cycle Save Backup
+ 0x80, // File 1 Owl Save
+ 0x80, // File 1 Owl Save Backup
+ 0x80, // File 2 Owl Save
+ 0x80, // File 2 Owl Save Backup
+ 1, // Sram Header (SaveOptions)
+ 1, // Sram Header Backup (SaveOptions)
+};
+
+// Owl Save flash rom start page number
+s32 gFlashOwlSaveStartPages[] = {
+ 0x100, // File 1 Owl Save
+ 0x180, // File 1 Owl Save Backup
+ 0x200, // File 2 Owl Save
+ 0x280, // File 2 Owl Save Backup
+};
-s32 D_801C6818[] = { 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 1, 1 };
+// Owl Save flash rom number of pages
+s32 gFlashOwlSaveNumPages[] = {
+ 0x80, // File 1 Owl Save
+ 0x80, // File 1 Owl Save Backup
+ 0x80, // File 2 Owl Save
+ 0x80, // File 2 Owl Save Backup
+};
-s32 D_801C6840[] = { 0x100, 0x180, 0x200, 0x280 };
+// Save Options Sram Header flash rom start page number
+s32 gFlashOptionsSaveStartPages[] = {
+ 0x300, // Sram Header (SaveOptions)
+ 0x380, // Sram Header Backup (SaveOptions)
+};
-s32 D_801C6850[] = { 0x80, 0x80, 0x80, 0x80, 0x300, 0x380, 1, 1 };
+// Save Options Sram Header flash rom number of pages
+s32 gFlashOptionsSaveNumPages[] = {
+ 1, // Sram Header (SaveOptions)
+ 1, // Sram Header Backup (SaveOptions)
+};
-s32 D_801C6870[] = {
- sizeof(Save),
- sizeof(Save),
- sizeof(Save),
- sizeof(Save),
- offsetof(SaveContext, fileNum),
- offsetof(SaveContext, fileNum),
- offsetof(SaveContext, fileNum),
- offsetof(SaveContext, fileNum),
+// Flash rom actual size needed
+s32 gFlashSaveSizes[] = {
+ sizeof(Save), // size = 0x100C - File 1 New Cycle Save
+ sizeof(Save), // size = 0x100C - File 1 New Cycle Save Backup
+ sizeof(Save), // size = 0x100C - File 2 New Cycle Save
+ sizeof(Save), // size = 0x100C - File 2 New Cycle Save Backup
+ offsetof(SaveContext, fileNum), // size = 0x3CA0 - File 1 Owl Save
+ offsetof(SaveContext, fileNum), // size = 0x3CA0 - File 1 Owl Save Backup
+ offsetof(SaveContext, fileNum), // size = 0x3CA0 - File 2 Owl Save
+ offsetof(SaveContext, fileNum), // size = 0x3CA0 - File 2 Owl Save Backup
};
-u8 D_801C6890[8] = { 1, 2, 4, 8, 0x10, 0x20, 0x40, 0x80 };
+u8 D_801C6890[8] = { 1 << 0, 1 << 1, 1 << 2, 1 << 3, 1 << 4, 1 << 5, 1 << 6, 1 << 7 };
u16 D_801F6AF0;
u8 D_801F6AF2;
@@ -245,9 +318,9 @@ void Sram_SaveEndOfCycle(PlayState* play) {
gSaveContext.save.day = 0;
gSaveContext.save.time = CLOCK_TIME(6, 0) - 1;
- gSaveContext.save.saveInfo.playerData.deaths++;
- if (gSaveContext.save.saveInfo.playerData.deaths > 999) {
- gSaveContext.save.saveInfo.playerData.deaths = 999;
+ gSaveContext.save.saveInfo.playerData.threeDayResetCount++;
+ if (gSaveContext.save.saveInfo.playerData.threeDayResetCount > 999) {
+ gSaveContext.save.saveInfo.playerData.threeDayResetCount = 999;
}
sceneId = Play_GetOriginalSceneId(play->sceneId);
@@ -577,7 +650,7 @@ void Sram_GenerateRandomSaveFields(void) {
SavePlayerData sSaveDefaultPlayerData = {
{ '\0', '\0', '\0', '\0', '\0', '\0' }, // newf
- 0, // deaths
+ 0, // threeDayResetCount
{ 0x3E, 0x3E, 0x3E, 0x3E, 0x3E, 0x3E, 0x3E, 0x3E }, // playerName " "
0x30, // healthCapacity
0x30, // health
@@ -678,7 +751,7 @@ void Sram_InitNewSave(void) {
SavePlayerData sSaveDebugPlayerData = {
{ 'Z', 'E', 'L', 'D', 'A', '3' }, // newf
- 0x0000, // deaths
+ 0, // threeDayResetCount
{ 0x15, 0x12, 0x17, 0x14, 0x3E, 0x3E, 0x3E, 0x3E }, // playerName "LINK "
0x80, // healthCapacity
0x80, // health
@@ -775,7 +848,18 @@ Inventory sSaveDebugInventory = {
(1 << QUEST_SONG_SOARING) | (1 << QUEST_SONG_STORMS) | (1 << QUEST_BOMBERS_NOTEBOOK) |
(1 << QUEST_SONG_LULLABY_INTRO),
// dungeonItems
- { 7, 7, 7, 7, 7, 7, 7, 7, 7, 7 },
+ {
+ (1 << DUNGEON_BOSS_KEY) | (1 << DUNGEON_COMPASS) | (1 << DUNGEON_MAP),
+ (1 << DUNGEON_BOSS_KEY) | (1 << DUNGEON_COMPASS) | (1 << DUNGEON_MAP),
+ (1 << DUNGEON_BOSS_KEY) | (1 << DUNGEON_COMPASS) | (1 << DUNGEON_MAP),
+ (1 << DUNGEON_BOSS_KEY) | (1 << DUNGEON_COMPASS) | (1 << DUNGEON_MAP),
+ (1 << DUNGEON_BOSS_KEY) | (1 << DUNGEON_COMPASS) | (1 << DUNGEON_MAP),
+ (1 << DUNGEON_BOSS_KEY) | (1 << DUNGEON_COMPASS) | (1 << DUNGEON_MAP),
+ (1 << DUNGEON_BOSS_KEY) | (1 << DUNGEON_COMPASS) | (1 << DUNGEON_MAP),
+ (1 << DUNGEON_BOSS_KEY) | (1 << DUNGEON_COMPASS) | (1 << DUNGEON_MAP),
+ (1 << DUNGEON_BOSS_KEY) | (1 << DUNGEON_COMPASS) | (1 << DUNGEON_MAP),
+ (1 << DUNGEON_BOSS_KEY) | (1 << DUNGEON_COMPASS) | (1 << DUNGEON_MAP),
+ },
// dungeonKeys
{ 8, 8, 8, 8, 8, 8, 8, 8, 8 },
// defenseHearts
@@ -851,15 +935,15 @@ void Sram_ResetSaveFromMoonCrash(SramContext* sramCtx) {
bzero(sramCtx->saveBuf, SAVE_BUFFER_SIZE);
- if (SysFlashrom_ReadData(sramCtx->saveBuf, D_801C67C8[gSaveContext.fileNum * 2],
- D_801C67F0[gSaveContext.fileNum * 2]) != 0) {
- SysFlashrom_ReadData(sramCtx->saveBuf, D_801C67C8[gSaveContext.fileNum * 2 + 1],
- D_801C67F0[gSaveContext.fileNum * 2 + 1]);
+ 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]);
}
Lib_MemCpy(&gSaveContext.save, sramCtx->saveBuf, sizeof(Save));
if (CHECK_NEWF(gSaveContext.save.saveInfo.playerData.newf)) {
- SysFlashrom_ReadData(sramCtx->saveBuf, D_801C67C8[gSaveContext.fileNum * 2 + 1],
- D_801C67F0[gSaveContext.fileNum * 2 + 1]);
+ SysFlashrom_ReadData(sramCtx->saveBuf, gFlashSaveStartPages[gSaveContext.fileNum * 2 + 1],
+ gFlashSaveNumPages[gSaveContext.fileNum * 2 + 1]);
Lib_MemCpy(&gSaveContext, sramCtx->saveBuf, sizeof(Save));
}
gSaveContext.save.cutsceneIndex = cutsceneIndex;
@@ -907,32 +991,34 @@ void Sram_OpenSave(FileSelectState* fileSelect, SramContext* sramCtx) {
s32 pad1;
s32 fileNum;
- if (gSaveContext.unk_3F3F) {
+ if (gSaveContext.flashSaveAvailable) {
bzero(sramCtx->saveBuf, SAVE_BUFFER_SIZE);
if (gSaveContext.fileNum == 0xFF) {
- SysFlashrom_ReadData(sramCtx->saveBuf, D_801C67C8[0], D_801C67F0[0]);
- } else if (fileSelect->unk_2446A[gSaveContext.fileNum] != 0) {
+ SysFlashrom_ReadData(sramCtx->saveBuf, gFlashSaveStartPages[0], gFlashSaveNumPages[0]);
+ } else if (fileSelect->isOwlSave[gSaveContext.fileNum + 2]) {
phi_t1 = gSaveContext.fileNum + 2;
phi_t1 *= 2;
- if (SysFlashrom_ReadData(sramCtx->saveBuf, D_801C67C8[phi_t1], D_801C67F0[phi_t1]) != 0) {
- SysFlashrom_ReadData(sramCtx->saveBuf, D_801C67C8[phi_t1 + 1], D_801C67F0[phi_t1 + 1]);
+ if (SysFlashrom_ReadData(sramCtx->saveBuf, gFlashSaveStartPages[phi_t1], gFlashSaveNumPages[phi_t1]) != 0) {
+ SysFlashrom_ReadData(sramCtx->saveBuf, gFlashSaveStartPages[phi_t1 + 1],
+ gFlashSaveNumPages[phi_t1 + 1]);
}
} else {
phi_t1 = gSaveContext.fileNum;
phi_t1 *= 2;
- if (SysFlashrom_ReadData(sramCtx->saveBuf, D_801C67C8[phi_t1], D_801C67F0[phi_t1]) != 0) {
- SysFlashrom_ReadData(sramCtx->saveBuf, D_801C67C8[phi_t1 + 1], D_801C67F0[phi_t1 + 1]);
+ if (SysFlashrom_ReadData(sramCtx->saveBuf, gFlashSaveStartPages[phi_t1], gFlashSaveNumPages[phi_t1]) != 0) {
+ SysFlashrom_ReadData(sramCtx->saveBuf, gFlashSaveStartPages[phi_t1 + 1],
+ gFlashSaveNumPages[phi_t1 + 1]);
}
}
- Lib_MemCpy(&gSaveContext, sramCtx->saveBuf, D_801C6870[phi_t1]);
+ Lib_MemCpy(&gSaveContext, sramCtx->saveBuf, gFlashSaveSizes[phi_t1]);
if (CHECK_NEWF(gSaveContext.save.saveInfo.playerData.newf)) {
- SysFlashrom_ReadData(sramCtx->saveBuf, D_801C67C8[phi_t1 + 1], D_801C67F0[phi_t1 + 1]);
- Lib_MemCpy(&gSaveContext, sramCtx->saveBuf, D_801C6870[phi_t1]);
+ SysFlashrom_ReadData(sramCtx->saveBuf, gFlashSaveStartPages[phi_t1 + 1], gFlashSaveNumPages[phi_t1 + 1]);
+ Lib_MemCpy(&gSaveContext, sramCtx->saveBuf, gFlashSaveSizes[phi_t1]);
}
}
@@ -963,7 +1049,7 @@ void Sram_OpenSave(FileSelectState* fileSelect, SramContext* sramCtx) {
if (gSaveContext.save.isFirstCycle) {
gSaveContext.save.entrance = ENTRANCE(SOUTH_CLOCK_TOWN, 0);
gSaveContext.save.day = 0;
- gSaveContext.save.time = 0x3FFF;
+ gSaveContext.save.time = CLOCK_TIME(6, 0) - 1;
} else {
gSaveContext.save.entrance = ENTRANCE(CUTSCENE, 0);
gSaveContext.nextCutsceneIndex = 0;
@@ -1028,7 +1114,7 @@ void func_8014546C(SramContext* sramCtx) {
gSaveContext.save.saveInfo.checksum = 0;
gSaveContext.save.saveInfo.checksum = Sram_CalcChecksum(&gSaveContext.save, sizeof(Save));
- if (gSaveContext.unk_3F3F) {
+ if (gSaveContext.flashSaveAvailable) {
Lib_MemCpy(sramCtx->saveBuf, &gSaveContext, sizeof(Save));
Lib_MemCpy(&sramCtx->saveBuf[0x2000], &gSaveContext.save, sizeof(Save));
}
@@ -1051,7 +1137,7 @@ void func_80145698(SramContext* sramCtx) {
gSaveContext.save.saveInfo.checksum = 0;
gSaveContext.save.saveInfo.checksum = Sram_CalcChecksum(&gSaveContext.save, sizeof(Save));
- if (gSaveContext.unk_3F3F) {
+ if (gSaveContext.flashSaveAvailable) {
Lib_MemCpy(sramCtx->saveBuf, &gSaveContext, sizeof(Save));
Lib_MemCpy(&sramCtx->saveBuf[0x2000], &gSaveContext.save, sizeof(Save));
}
@@ -1059,31 +1145,21 @@ void func_80145698(SramContext* sramCtx) {
// Verifies save and use backup if corrupted?
#ifdef NON_EQUIVALENT
-void func_801457CC(FileSelectState* fileSelect2, SramContext* sramCtx) {
- FileSelectState* fileSelect = fileSelect2;
+void func_801457CC(GameState* gameState, SramContext* sramCtx) {
+ FileSelectState* fileSelect = (FileSelectState*)gameState;
u16 sp7A;
- // u16 sp78;
+ u16 oldCheckSum; // s2
u16 sp76;
- // u16 sp74;
- u16 sp6E; //!
- // s32 sp68;
- // u16 sp66;
- u16 phi_s2; //!
- u16 sp64;
- // s32 sp60;
- // s32 sp5C;
- // s32 sp58;
- // u32 new_var;
- u16 phi_s2_3;
- // s16 fakevar;
-
- u16 temp_s2;
- u16 temp_v0_2;
- u16 phi_a0; // maskCount
-
- if (gSaveContext.unk_3F3F) {
+ u16 sp64; // sp74?
+ u16 phi_s2;
+ u16 phi_s7;
+ u16 sp6E;
+ u16 newCheckSum; // v0
+ u16 phi_a0; // maskCount
+
+ if (gSaveContext.flashSaveAvailable) {
D_801F6AF0 = gSaveContext.save.time;
- D_801F6AF2 = gSaveContext.unk_3F3F;
+ D_801F6AF2 = gSaveContext.flashSaveAvailable;
sp64 = 0;
for (sp76 = 0; sp76 < 5; sp76++, sp64 += 2) {
@@ -1091,40 +1167,65 @@ void func_801457CC(FileSelectState* fileSelect2, SramContext* sramCtx) {
phi_s2 = false;
sp6E = 0;
- if (SysFlashrom_ReadData(sramCtx->saveBuf, D_801C67C8[sp64], D_801C67F0[sp64])) {
+ // read main save from flash
+ if (SysFlashrom_ReadData(sramCtx->saveBuf, gFlashSaveStartPages[sp64], gFlashSaveNumPages[sp64]) != 0) {
+ // main save didn't work
sp6E = 1;
- if (SysFlashrom_ReadData(sramCtx->saveBuf, D_801C67C8[sp64 + 1], D_801C67F0[sp64 + 1])) {
+ // read backup save from flash
+ if (SysFlashrom_ReadData(sramCtx->saveBuf, gFlashSaveStartPages[sp64 + 1],
+ gFlashSaveNumPages[sp64 + 1]) != 0) {
+ // backup save didn't work
phi_s2 = true;
}
}
if (sp76 < 2) {
- fileSelect->unk_24468[sp76] = 0;
+ // Non-owl save
+ // sp76 = 0: main save
+ // sp76 = 1: backup save
+
+ fileSelect->isOwlSave[sp76] = 0;
if (phi_s2) {
+ // both main save and backup save failed
bzero(sramCtx->saveBuf, SAVE_BUFFER_SIZE);
- Lib_MemCpy(&gSaveContext, sramCtx->saveBuf, D_801C6870[sp64]);
+ Lib_MemCpy(&gSaveContext, sramCtx->saveBuf, gFlashSaveSizes[sp64]);
} else {
- // Lib_MemCpy(&gSaveContext, sramCtx->saveBuf, D_801C6870[sp64]);
- Lib_MemCpy(&gSaveContext, sramCtx->saveBuf, D_801C6870[sp64]);
- temp_s2 = gSaveContext.save.saveInfo.checksum;
+ Lib_MemCpy(&gSaveContext, sramCtx->saveBuf, gFlashSaveSizes[sp64]);
+
+ // test checksum of main save
+ oldCheckSum = gSaveContext.save.saveInfo.checksum;
gSaveContext.save.saveInfo.checksum = 0;
- temp_v0_2 = Sram_CalcChecksum(&gSaveContext, D_801C6870[sp64]);
- gSaveContext.save.saveInfo.checksum = temp_s2;
+ newCheckSum = Sram_CalcChecksum(&gSaveContext, gFlashSaveSizes[sp64]);
+ gSaveContext.save.saveInfo.checksum = oldCheckSum;
- if (CHECK_NEWF(gSaveContext.save.saveInfo.playerData.newf) || (temp_s2 != temp_v0_2)) {
+ if (CHECK_NEWF(gSaveContext.save.saveInfo.playerData.newf) || (oldCheckSum != newCheckSum)) {
+ // checksum didnt match, try backup save
sp6E = 1;
- if (CHECK_NEWF2(gSaveContext.save.saveInfo.playerData.newf)) {}
- phi_s2 = false;
- if (SysFlashrom_ReadData(sramCtx->saveBuf, D_801C67C8[sp64 + 1], D_801C67F0[sp64 + 1])) {
+ if ((gSaveContext.save.saveInfo.playerData.newf[0] == 'Z') &&
+ (gSaveContext.save.saveInfo.playerData.newf[1] == 'E')) {
+ phi_s2 = false;
+ }
+
+ // phi_s2 = false;
+
+ // read backup save from flash
+ if (SysFlashrom_ReadData(sramCtx->saveBuf, gFlashSaveStartPages[sp64 + 1],
+ gFlashSaveNumPages[sp64 + 1]) != 0) {
+ // backup save didn't work
phi_s2 = true;
}
- Lib_MemCpy(&gSaveContext, sramCtx->saveBuf, D_801C6870[sp64]);
- temp_s2 = gSaveContext.save.saveInfo.checksum;
+ Lib_MemCpy(&gSaveContext, sramCtx->saveBuf, gFlashSaveSizes[sp64]);
+
+ // test checksum of backup save
+ oldCheckSum = gSaveContext.save.saveInfo.checksum;
gSaveContext.save.saveInfo.checksum = 0;
+
+ //! FAKE: (s32)sp64
if (phi_s2 || CHECK_NEWF(gSaveContext.save.saveInfo.playerData.newf) ||
- (temp_s2 != Sram_CalcChecksum(&gSaveContext, D_801C6870[sp64]))) {
+ (oldCheckSum != Sram_CalcChecksum(&gSaveContext, gFlashSaveSizes[(s32)sp64]))) {
+ // backup save didn't work
bzero(sramCtx->saveBuf, SAVE_BUFFER_SIZE);
Lib_MemCpy(&gSaveContext.save, sramCtx->saveBuf, sizeof(Save));
sp6E = 999;
@@ -1133,29 +1234,30 @@ void func_801457CC(FileSelectState* fileSelect2, SramContext* sramCtx) {
}
gSaveContext.save.saveInfo.checksum = 0;
+ // FAKE: Needed?
gSaveContext.save.saveInfo.checksum =
- Sram_CalcChecksum(&gSaveContext, D_801C6870[sp64 & 0xFFFFFFFF]); // TODO: Needed?
+ Sram_CalcChecksum(&gSaveContext, gFlashSaveSizes[sp64 & 0xFFFFFFFF]);
for (sp7A = 0; sp7A < ARRAY_COUNT(gSaveContext.save.saveInfo.playerData.newf); sp7A++) {
fileSelect->newf[sp76][sp7A] = gSaveContext.save.saveInfo.playerData.newf[sp7A];
}
if (!CHECK_NEWF(fileSelect->newf[sp76])) {
- fileSelect->unk_2440C[sp76] = gSaveContext.save.saveInfo.playerData.deaths;
+ fileSelect->threeDayResetCount[sp76] = gSaveContext.save.saveInfo.playerData.threeDayResetCount;
for (sp7A = 0; sp7A < ARRAY_COUNT(gSaveContext.save.saveInfo.playerData.playerName); sp7A++) {
- fileSelect->unk_24414[sp76][sp7A] = gSaveContext.save.saveInfo.playerData.playerName[sp7A];
+ fileSelect->fileNames[sp76][sp7A] = gSaveContext.save.saveInfo.playerData.playerName[sp7A];
}
fileSelect->healthCapacity[sp76] = gSaveContext.save.saveInfo.playerData.healthCapacity;
fileSelect->health[sp76] = gSaveContext.save.saveInfo.playerData.health;
- fileSelect->unk_24454[sp76] = gSaveContext.save.saveInfo.inventory.defenseHearts;
- fileSelect->unk_24444[sp76] = gSaveContext.save.saveInfo.inventory.questItems;
- fileSelect->unk_24458[sp76] = gSaveContext.save.time;
- fileSelect->unk_24460[sp76] = gSaveContext.save.day;
- fileSelect->unk_24468[sp76] = gSaveContext.save.isOwlSave;
+ fileSelect->defenseHearts[sp76] = gSaveContext.save.saveInfo.inventory.defenseHearts;
+ fileSelect->questItems[sp76] = gSaveContext.save.saveInfo.inventory.questItems;
+ fileSelect->time[sp76] = gSaveContext.save.time;
+ fileSelect->day[sp76] = gSaveContext.save.day;
+ fileSelect->isOwlSave[sp76] = gSaveContext.save.isOwlSave;
fileSelect->rupees[sp76] = gSaveContext.save.saveInfo.playerData.rupees;
- fileSelect->unk_24474[sp76] = CUR_UPG_VALUE(4);
+ fileSelect->walletUpgrades[sp76] = CUR_UPG_VALUE(UPG_WALLET);
for (sp7A = 0, phi_a0 = 0; sp7A < 24; sp7A++) {
if (gSaveContext.save.saveInfo.inventory.items[sp7A + 24] != 0xFF) {
@@ -1168,90 +1270,106 @@ void func_801457CC(FileSelectState* fileSelect2, SramContext* sramCtx) {
}
if (sp6E == 1) {
+ // backup save
Lib_MemCpy(&sramCtx->saveBuf[0x2000], &gSaveContext.save, sizeof(Save));
- func_80146EBC(sramCtx, D_801C67C8[sp64], D_801C6818[sp64]);
- } else if (sp6E == 0) { // TODO: == 0?
- temp_s2 = gSaveContext.save.saveInfo.checksum;
- if (SysFlashrom_ReadData(sramCtx->saveBuf, D_801C67C8[sp64 + 1], D_801C67F0[sp64 + 1])) {
- phi_s2_3 = 1;
+ Sram_SyncWriteToFlash(sramCtx, gFlashSaveStartPages[sp64], gFlashSpecialSaveNumPages[sp64]);
+ } else if (!sp6E) {
+ // main save
+ phi_s7 = gSaveContext.save.saveInfo.checksum;
+
+ if (SysFlashrom_ReadData(sramCtx->saveBuf, gFlashSaveStartPages[sp64 + 1],
+ gFlashSaveNumPages[sp64 + 1]) != 0) {
+ oldCheckSum = 1;
} else {
Lib_MemCpy(&gSaveContext.save, sramCtx->saveBuf, sizeof(Save));
- phi_s2_3 = gSaveContext.save.saveInfo.checksum;
+ oldCheckSum = gSaveContext.save.saveInfo.checksum;
gSaveContext.save.saveInfo.checksum = 0;
sp7A = Sram_CalcChecksum(&gSaveContext.save, sizeof(Save));
}
- if (CHECK_NEWF(gSaveContext.save.saveInfo.playerData.newf) || (phi_s2_3 != sp7A) ||
- (phi_s2_3 != temp_s2)) {
- SysFlashrom_ReadData(sramCtx->saveBuf, D_801C67C8[sp64], D_801C67F0[sp64]);
+ if (CHECK_NEWF(gSaveContext.save.saveInfo.playerData.newf) || (oldCheckSum != sp7A) ||
+ (oldCheckSum != phi_s7)) {
+ SysFlashrom_ReadData(sramCtx->saveBuf, gFlashSaveStartPages[sp64], gFlashSaveNumPages[sp64]);
Lib_MemCpy(&gSaveContext.save, sramCtx->saveBuf, sizeof(Save));
Lib_MemCpy(&sramCtx->saveBuf[0x2000], &gSaveContext.save, sizeof(Save));
- func_80146EBC(sramCtx, D_801C67C8[sp64], D_801C6818[sp64]);
+ Sram_SyncWriteToFlash(sramCtx, gFlashSaveStartPages[sp64], gFlashSpecialSaveNumPages[sp64]);
}
}
} else if (sp76 < 4) {
- fileSelect->unk_24468[sp76] = 0;
+ // Owl Save:
+ // sp76 = 3: main owl save
+ // sp76 = 4: backup owl save
+ fileSelect->isOwlSave[sp76] = 0;
- if (!CHECK_NEWF(fileSelect->newf2[(s32)sp76])) { // TODO: Needed?
+ if (!CHECK_NEWF(fileSelect->newf[sp76 - 2])) {
if (phi_s2) {
+ // both main save and backup save failed
bzero(sramCtx->saveBuf, SAVE_BUFFER_SIZE);
- Lib_MemCpy(&gSaveContext, sramCtx->saveBuf,
- D_801C6870[sp64]); // TODO: Needed?
+ Lib_MemCpy(&gSaveContext, sramCtx->saveBuf, gFlashSaveSizes[sp64]);
} else {
- Lib_MemCpy(&gSaveContext, sramCtx->saveBuf, D_801C6870[sp64]);
- temp_s2 = gSaveContext.save.saveInfo.checksum;
+ Lib_MemCpy(&gSaveContext, sramCtx->saveBuf, gFlashSaveSizes[sp64]);
+ oldCheckSum = gSaveContext.save.saveInfo.checksum;
+ // test checksum of main save
gSaveContext.save.saveInfo.checksum = 0;
- temp_v0_2 = Sram_CalcChecksum(&gSaveContext, D_801C6870[sp64]);
- gSaveContext.save.saveInfo.checksum = temp_s2;
- if (CHECK_NEWF(gSaveContext.save.saveInfo.playerData.newf) || (temp_s2 != temp_v0_2)) {
+ newCheckSum = Sram_CalcChecksum(&gSaveContext, gFlashSaveSizes[sp64]);
+ gSaveContext.save.saveInfo.checksum = oldCheckSum;
+
+ if (CHECK_NEWF(gSaveContext.save.saveInfo.playerData.newf) || (oldCheckSum != newCheckSum)) {
+ // checksum didnt match, try backup save
sp6E = 1;
if ((gSaveContext.save.saveInfo.playerData.newf[0] == 'Z') &&
(gSaveContext.save.saveInfo.playerData.newf[1] == 'E')) {
phi_s2 = false;
}
- if (SysFlashrom_ReadData(sramCtx->saveBuf, D_801C67C8[sp64 + 1], D_801C67F0[sp64 + 1])) {
+ // read backup save from flash
+ if (SysFlashrom_ReadData(sramCtx->saveBuf, gFlashSaveStartPages[sp64 + 1],
+ gFlashSaveNumPages[sp64 + 1])) {
+ // backup save didn't work
phi_s2 = true;
}
- Lib_MemCpy(&gSaveContext, sramCtx->saveBuf, D_801C6870[sp64]);
- temp_s2 = gSaveContext.save.saveInfo.checksum;
+ Lib_MemCpy(&gSaveContext, sramCtx->saveBuf, gFlashSaveSizes[sp64]);
+
+ // test checksum of backup save
+ oldCheckSum = gSaveContext.save.saveInfo.checksum;
gSaveContext.save.saveInfo.checksum = 0;
+
if (phi_s2 || CHECK_NEWF(gSaveContext.save.saveInfo.playerData.newf) ||
- (temp_s2 != Sram_CalcChecksum(&gSaveContext, D_801C6870[sp64]))) {
+ (oldCheckSum != Sram_CalcChecksum(&gSaveContext, gFlashSaveSizes[sp64]))) {
bzero(sramCtx->saveBuf, SAVE_BUFFER_SIZE);
- Lib_MemCpy(&gSaveContext, sramCtx->saveBuf, D_801C6870[sp64]);
+ Lib_MemCpy(&gSaveContext, sramCtx->saveBuf, gFlashSaveSizes[sp64]);
sp6E = 999;
}
}
}
gSaveContext.save.saveInfo.checksum = 0;
+ // FAKE: Needed?
gSaveContext.save.saveInfo.checksum =
- Sram_CalcChecksum(&gSaveContext, D_801C6870[sp64 & 0xFFFFFFFF]); // TODO: Needed?
+ Sram_CalcChecksum(&gSaveContext, gFlashSaveSizes[sp64 & 0xFFFFFFFF]);
for (sp7A = 0; sp7A < ARRAY_COUNT(gSaveContext.save.saveInfo.playerData.newf); sp7A++) {
fileSelect->newf[sp76][sp7A] = gSaveContext.save.saveInfo.playerData.newf[sp7A];
}
if (!CHECK_NEWF(fileSelect->newf[sp76])) {
- fileSelect->unk_2440C[sp76] = gSaveContext.save.saveInfo.playerData.deaths;
+ fileSelect->threeDayResetCount[sp76] = gSaveContext.save.saveInfo.playerData.threeDayResetCount;
for (sp7A = 0; sp7A < ARRAY_COUNT(gSaveContext.save.saveInfo.playerData.playerName); sp7A++) {
- phi_s2 += 0; // TODO: Needed?
- fileSelect->unk_24414[sp76][sp7A] = gSaveContext.save.saveInfo.playerData.playerName[sp7A];
+ fileSelect->fileNames[sp76][sp7A] = gSaveContext.save.saveInfo.playerData.playerName[sp7A];
}
fileSelect->healthCapacity[sp76] = gSaveContext.save.saveInfo.playerData.healthCapacity;
fileSelect->health[sp76] = gSaveContext.save.saveInfo.playerData.health;
- fileSelect->unk_24454[sp76] = gSaveContext.save.saveInfo.inventory.defenseHearts;
- fileSelect->unk_24444[sp76] = gSaveContext.save.saveInfo.inventory.questItems;
- fileSelect->unk_24458[sp76] = gSaveContext.save.time;
- fileSelect->unk_24460[sp76] = gSaveContext.save.day;
- fileSelect->unk_24468[sp76] = gSaveContext.save.isOwlSave;
+ fileSelect->defenseHearts[sp76] = gSaveContext.save.saveInfo.inventory.defenseHearts;
+ fileSelect->questItems[sp76] = gSaveContext.save.saveInfo.inventory.questItems;
+ fileSelect->time[sp76] = gSaveContext.save.time;
+ fileSelect->day[sp76] = gSaveContext.save.day;
+ fileSelect->isOwlSave[sp76] = gSaveContext.save.isOwlSave;
fileSelect->rupees[sp76] = gSaveContext.save.saveInfo.playerData.rupees;
- fileSelect->unk_24474[sp76] = CUR_UPG_VALUE(4);
+ fileSelect->walletUpgrades[sp76] = CUR_UPG_VALUE(UPG_WALLET);
for (sp7A = 0, phi_a0 = 0; sp7A < 24; sp7A++) {
if (gSaveContext.save.saveInfo.inventory.items[sp7A + 24] != 0xFF) {
@@ -1264,39 +1382,44 @@ void func_801457CC(FileSelectState* fileSelect2, SramContext* sramCtx) {
}
if (sp6E == 1) {
- func_80146EBC(sramCtx, D_801C67C8[sp64], D_801C67F0[sp64]);
- func_80146EBC(sramCtx, D_801C67C8[sp64 + 1], D_801C67F0[sp64 + 1]);
- } else if (!sp6E) { // TODO: == 0?
- temp_s2 = gSaveContext.save.saveInfo.checksum;
- if (SysFlashrom_ReadData(sramCtx->saveBuf, D_801C67C8[sp64 + 1], D_801C67F0[sp64 + 1])) {
- phi_s2_3 = 1;
+ // backup save
+ Sram_SyncWriteToFlash(sramCtx, gFlashSaveStartPages[sp64], gFlashSaveNumPages[sp64]);
+ Sram_SyncWriteToFlash(sramCtx, gFlashSaveStartPages[sp64 + 1], gFlashSaveNumPages[sp64 + 1]);
+ } else if (!sp6E) {
+ // main save
+ phi_s7 = gSaveContext.save.saveInfo.checksum;
+
+ if (SysFlashrom_ReadData(sramCtx->saveBuf, gFlashSaveStartPages[sp64 + 1],
+ gFlashSaveNumPages[sp64 + 1])) {
+ oldCheckSum = 1;
} else {
- Lib_MemCpy(&gSaveContext, sramCtx->saveBuf, D_801C6870[sp64]);
- phi_s2_3 = gSaveContext.save.saveInfo.checksum;
+ Lib_MemCpy(&gSaveContext, sramCtx->saveBuf, gFlashSaveSizes[sp64]);
+ oldCheckSum = gSaveContext.save.saveInfo.checksum;
gSaveContext.save.saveInfo.checksum = 0;
- // phi_s2_3 = gSaveContext.save.saveInfo.checksum;
- sp7A = Sram_CalcChecksum(&gSaveContext, D_801C6870[sp64]);
+ sp7A = Sram_CalcChecksum(&gSaveContext, gFlashSaveSizes[sp64]);
}
- if (CHECK_NEWF(gSaveContext.save.saveInfo.playerData.newf) || (phi_s2_3 != sp7A) ||
- (phi_s2_3 != temp_s2)) {
- SysFlashrom_ReadData(sramCtx->saveBuf, D_801C67C8[sp64], D_801C67F0[sp64]);
- Lib_MemCpy(&gSaveContext, sramCtx->saveBuf, D_801C6870[sp64]);
- func_80146EBC(sramCtx, D_801C67C8[sp64], D_801C67F0[sp64]);
- func_80146EBC(sramCtx, D_801C67C8[sp64 + 1], D_801C67F0[sp64 + 1]);
+ if (CHECK_NEWF(gSaveContext.save.saveInfo.playerData.newf) || (oldCheckSum != sp7A) ||
+ (oldCheckSum != phi_s7)) {
+ SysFlashrom_ReadData(sramCtx->saveBuf, gFlashSaveStartPages[sp64],
+ gFlashSaveNumPages[sp64]);
+ Lib_MemCpy(&gSaveContext, sramCtx->saveBuf, gFlashSaveSizes[sp64]);
+ Sram_SyncWriteToFlash(sramCtx, gFlashSaveStartPages[sp64], gFlashSaveNumPages[sp64]);
+ Sram_SyncWriteToFlash(sramCtx, gFlashSaveStartPages[sp64 + 1],
+ gFlashSaveNumPages[sp64 + 1]);
}
}
} else {
bzero(sramCtx->saveBuf, SAVE_BUFFER_SIZE);
- Lib_MemCpy(&gSaveContext, sramCtx->saveBuf, D_801C6870[sp64]);
- func_80146EBC(sramCtx, D_801C67C8[sp64], D_801C67F0[sp64]);
- func_80146EBC(sramCtx, D_801C67C8[sp64 + 1], D_801C67F0[sp64 + 1]);
+ Lib_MemCpy(&gSaveContext, sramCtx->saveBuf, gFlashSaveSizes[sp64]);
+ Sram_SyncWriteToFlash(sramCtx, gFlashSaveStartPages[sp64], gFlashSaveNumPages[sp64]);
+ Sram_SyncWriteToFlash(sramCtx, gFlashSaveStartPages[sp64 + 1], gFlashSaveNumPages[sp64 + 1]);
}
} else {
if (phi_s2) {
gSaveContext.options.optionId = 0xA51D;
gSaveContext.options.language = 1;
- gSaveContext.options.audioSetting = 0;
+ gSaveContext.options.audioSetting = SAVE_AUDIO_STEREO;
gSaveContext.options.languageSetting = 0;
gSaveContext.options.zTargetSetting = 0;
} else {
@@ -1304,7 +1427,7 @@ void func_801457CC(FileSelectState* fileSelect2, SramContext* sramCtx) {
if (gSaveContext.options.optionId != 0xA51D) {
gSaveContext.options.optionId = 0xA51D;
gSaveContext.options.language = 1;
- gSaveContext.options.audioSetting = 0;
+ gSaveContext.options.audioSetting = SAVE_AUDIO_STEREO;
gSaveContext.options.languageSetting = 0;
gSaveContext.options.zTargetSetting = 0;
}
@@ -1314,7 +1437,7 @@ void func_801457CC(FileSelectState* fileSelect2, SramContext* sramCtx) {
}
gSaveContext.save.time = D_801F6AF0;
- gSaveContext.unk_3F3F = D_801F6AF2;
+ gSaveContext.flashSaveAvailable = D_801F6AF2;
}
gSaveContext.options.language = 1;
@@ -1323,50 +1446,52 @@ void func_801457CC(FileSelectState* fileSelect2, SramContext* sramCtx) {
#pragma GLOBAL_ASM("asm/non_matchings/code/z_sram_NES/func_801457CC.s")
#endif
-void func_80146580(FileSelectState* fileSelect2, SramContext* sramCtx, s32 fileNum) {
+void Sram_EraseSave(FileSelectState* fileSelect2, SramContext* sramCtx, s32 fileNum) {
FileSelectState* fileSelect = fileSelect2;
s32 pad;
- if (gSaveContext.unk_3F3F) {
- if (fileSelect->unk_2446A[fileNum]) {
+ if (gSaveContext.flashSaveAvailable) {
+ if (fileSelect->isOwlSave[fileNum + 2]) {
func_80147314(sramCtx, fileNum);
- fileSelect->unk_2446A[fileNum] = 0;
+ fileSelect->isOwlSave[fileNum + 2] = false;
}
bzero(sramCtx->saveBuf, SAVE_BUFFER_SIZE);
Lib_MemCpy(&gSaveContext, sramCtx->saveBuf, sizeof(Save));
}
gSaveContext.save.time = D_801F6AF0;
- gSaveContext.unk_3F3F = D_801F6AF2;
+ gSaveContext.flashSaveAvailable = D_801F6AF2;
}
#ifdef NON_MATCHING
// v0/v1
-void func_80146628(FileSelectState* fileSelect2, SramContext* sramCtx) {
+void Sram_CopySave(FileSelectState* fileSelect2, SramContext* sramCtx) {
FileSelectState* fileSelect = fileSelect2;
u16 i;
s16 maskCount;
- if (gSaveContext.unk_3F3F) {
- if (fileSelect->unk_2446A[fileSelect->unk_2448E]) {
- func_80147414(sramCtx, fileSelect->unk_2448E, fileSelect->fileNum);
- fileSelect->unk_24410[fileSelect->fileNum] = gSaveContext.save.saveInfo.playerData.deaths;
+ if (gSaveContext.flashSaveAvailable) {
+ if (fileSelect->isOwlSave[fileSelect->selectedFileIndex + 2]) {
+ func_80147414(sramCtx, fileSelect->selectedFileIndex, fileSelect->copyDestFileIndex);
+ fileSelect->threeDayResetCount[fileSelect->copyDestFileIndex + 2] =
+ gSaveContext.save.saveInfo.playerData.threeDayResetCount;
for (i = 0; i < ARRAY_COUNT(gSaveContext.save.saveInfo.playerData.playerName); i++) {
- fileSelect->unk_24424[fileSelect->fileNum][i] = gSaveContext.save.saveInfo.playerData.playerName[i];
+ fileSelect->fileNames[fileSelect->copyDestFileIndex + 2][i] =
+ gSaveContext.save.saveInfo.playerData.playerName[i];
}
- fileSelect->unk_24438[fileSelect->fileNum] = gSaveContext.save.saveInfo.playerData.healthCapacity;
- fileSelect->unk_24440[fileSelect->fileNum] = gSaveContext.save.saveInfo.playerData.health;
- fileSelect->unk_24456[fileSelect->fileNum] = gSaveContext.save.saveInfo.inventory.defenseHearts;
- fileSelect->unk_2444C[fileSelect->fileNum] = gSaveContext.save.saveInfo.inventory.questItems;
- fileSelect->unk_2445C[fileSelect->fileNum] = gSaveContext.save.time;
- fileSelect->unk_24464[fileSelect->fileNum] = gSaveContext.save.day;
- fileSelect->unk_2446A[fileSelect->fileNum] = gSaveContext.save.isOwlSave;
- fileSelect->unk_24470[fileSelect->fileNum] = gSaveContext.save.saveInfo.playerData.rupees;
- // = CUR_UPG_VALUE(UPG_WALLET);
- fileSelect->unk_24476[fileSelect->fileNum] =
- (gSaveContext.save.saveInfo.inventory.upgrades & gUpgradeMasks[4]) >> gUpgradeShifts[4];
+ fileSelect->healthCapacity[fileSelect->copyDestFileIndex + 2] =
+ gSaveContext.save.saveInfo.playerData.healthCapacity;
+ fileSelect->health[fileSelect->copyDestFileIndex + 2] = gSaveContext.save.saveInfo.playerData.health;
+ fileSelect->defenseHearts[fileSelect->copyDestFileIndex + 2] =
+ 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);
for (i = 0, maskCount = 0; i < 24; i++) {
if (gSaveContext.save.saveInfo.inventory.items[i + 24] != ITEM_NONE) {
@@ -1374,42 +1499,42 @@ void func_80146628(FileSelectState* fileSelect2, SramContext* sramCtx) {
}
}
- fileSelect->unk_2447A[fileSelect->fileNum] = maskCount;
- fileSelect->unk_2447E[fileSelect->fileNum] =
- (gSaveContext.save.saveInfo.inventory.questItems & 0xF0000000) >> 0x1C;
+ fileSelect->maskCount[fileSelect->copyDestFileIndex + 2] = maskCount;
+ fileSelect->heartPieceCount[fileSelect->copyDestFileIndex + 2] = GET_QUEST_HEART_PIECE_COUNT;
}
// clear buffer
bzero(sramCtx->saveBuf, SAVE_BUFFER_SIZE);
// read to buffer
- SysFlashrom_ReadData(sramCtx->saveBuf, D_801C67C8[fileSelect->unk_2448E * 2],
- D_801C67F0[fileSelect->unk_2448E * 2]);
-
+ SysFlashrom_ReadData(&sramCtx->saveBuf[0], gFlashSaveStartPages[fileSelect->selectedFileIndex * 2],
+ gFlashSaveNumPages[fileSelect->selectedFileIndex * 2]);
if (1) {}
- SysFlashrom_ReadData(&sramCtx->saveBuf[0x2000], D_801C67C8[fileSelect->unk_2448E * 2 + 1],
- D_801C67F0[fileSelect->unk_2448E * 2 + 1]);
+
+ SysFlashrom_ReadData(&sramCtx->saveBuf[0x2000], gFlashSaveStartPages[fileSelect->selectedFileIndex * 2 + 1],
+ gFlashSaveNumPages[fileSelect->selectedFileIndex * 2 + 1]);
if (1) {}
// copy buffer to save context
Lib_MemCpy(&gSaveContext.save, sramCtx->saveBuf, sizeof(Save));
- fileSelect->unk_2440C[fileSelect->fileNum] = gSaveContext.save.saveInfo.playerData.deaths;
+ fileSelect->threeDayResetCount[fileSelect->copyDestFileIndex] =
+ gSaveContext.save.saveInfo.playerData.threeDayResetCount;
for (i = 0; i < ARRAY_COUNT(gSaveContext.save.saveInfo.playerData.playerName); i++) {
- fileSelect->unk_24414[fileSelect->fileNum][i] = gSaveContext.save.saveInfo.playerData.playerName[i];
+ fileSelect->fileNames[fileSelect->copyDestFileIndex][i] =
+ gSaveContext.save.saveInfo.playerData.playerName[i];
}
- fileSelect->healthCapacity[fileSelect->fileNum] = gSaveContext.save.saveInfo.playerData.healthCapacity;
- fileSelect->health[fileSelect->fileNum] = gSaveContext.save.saveInfo.playerData.health;
- fileSelect->unk_24454[fileSelect->fileNum] = gSaveContext.save.saveInfo.inventory.defenseHearts;
- fileSelect->unk_24444[fileSelect->fileNum] = gSaveContext.save.saveInfo.inventory.questItems;
- fileSelect->unk_24458[fileSelect->fileNum] = gSaveContext.save.time;
- fileSelect->unk_24460[fileSelect->fileNum] = gSaveContext.save.day;
- fileSelect->unk_24468[fileSelect->fileNum] = gSaveContext.save.isOwlSave;
- fileSelect->rupees[fileSelect->fileNum] = gSaveContext.save.saveInfo.playerData.rupees;
- // = CUR_UPG_VALUE(UPG_WALLET);
- fileSelect->unk_24474[fileSelect->fileNum] =
- (gSaveContext.save.saveInfo.inventory.upgrades & gUpgradeMasks[4]) >> gUpgradeShifts[4];
+ fileSelect->healthCapacity[fileSelect->copyDestFileIndex] =
+ gSaveContext.save.saveInfo.playerData.healthCapacity;
+ fileSelect->health[fileSelect->copyDestFileIndex] = gSaveContext.save.saveInfo.playerData.health;
+ fileSelect->defenseHearts[fileSelect->copyDestFileIndex] = gSaveContext.save.saveInfo.inventory.defenseHearts;
+ fileSelect->questItems[fileSelect->copyDestFileIndex] = gSaveContext.save.saveInfo.inventory.questItems;
+ fileSelect->time[fileSelect->copyDestFileIndex] = gSaveContext.save.time;
+ fileSelect->day[fileSelect->copyDestFileIndex] = gSaveContext.save.day;
+ fileSelect->isOwlSave[fileSelect->copyDestFileIndex] = gSaveContext.save.isOwlSave;
+ fileSelect->rupees[fileSelect->copyDestFileIndex] = gSaveContext.save.saveInfo.playerData.rupees;
+ fileSelect->walletUpgrades[fileSelect->copyDestFileIndex] = CUR_UPG_VALUE(UPG_WALLET);
for (i = 0, maskCount = 0; i < 24; i++) {
if (gSaveContext.save.saveInfo.inventory.items[i + 24] != ITEM_NONE) {
@@ -1417,16 +1542,15 @@ void func_80146628(FileSelectState* fileSelect2, SramContext* sramCtx) {
}
}
- fileSelect->maskCount[fileSelect->fileNum] = maskCount;
- fileSelect->heartPieceCount[fileSelect->fileNum] =
- (gSaveContext.save.saveInfo.inventory.questItems & 0xF0000000) >> 0x1C;
+ fileSelect->maskCount[fileSelect->copyDestFileIndex] = maskCount;
+ fileSelect->heartPieceCount[fileSelect->copyDestFileIndex] = GET_QUEST_HEART_PIECE_COUNT;
}
gSaveContext.save.time = D_801F6AF0;
- gSaveContext.unk_3F3F = D_801F6AF2;
+ gSaveContext.flashSaveAvailable = D_801F6AF2;
}
#else
-#pragma GLOBAL_ASM("asm/non_matchings/code/z_sram_NES/func_80146628.s")
+#pragma GLOBAL_ASM("asm/non_matchings/code/z_sram_NES/Sram_CopySave.s")
#endif
void Sram_InitSave(FileSelectState* fileSelect2, SramContext* sramCtx) {
@@ -1435,15 +1559,15 @@ void Sram_InitSave(FileSelectState* fileSelect2, SramContext* sramCtx) {
FileSelectState* fileSelect = fileSelect2;
s16 maskCount;
- if (gSaveContext.unk_3F3F) {
+ if (gSaveContext.flashSaveAvailable) {
Sram_InitNewSave();
- if (fileSelect->unk_24480 == 0) {
+ if (fileSelect->buttonIndex == 0) {
gSaveContext.save.cutsceneIndex = 0xFFF0;
}
for (phi_v0 = 0; phi_v0 < ARRAY_COUNT(gSaveContext.save.saveInfo.playerData.playerName); phi_v0++) {
gSaveContext.save.saveInfo.playerData.playerName[phi_v0] =
- fileSelect->unk_24414[fileSelect->unk_24480][phi_v0];
+ fileSelect->fileNames[fileSelect->buttonIndex][phi_v0];
}
gSaveContext.save.saveInfo.playerData.newf[0] = 'Z';
@@ -1459,24 +1583,25 @@ void Sram_InitSave(FileSelectState* fileSelect2, SramContext* sramCtx) {
Lib_MemCpy(&sramCtx->saveBuf[0x2000], &gSaveContext.save, sizeof(Save));
for (i = 0; i < ARRAY_COUNT(gSaveContext.save.saveInfo.playerData.newf); i++) {
- fileSelect->newf[fileSelect->unk_24480][i] = gSaveContext.save.saveInfo.playerData.newf[i];
+ fileSelect->newf[fileSelect->buttonIndex][i] = gSaveContext.save.saveInfo.playerData.newf[i];
}
- fileSelect->unk_2440C[fileSelect->unk_24480] = gSaveContext.save.saveInfo.playerData.deaths;
+ fileSelect->threeDayResetCount[fileSelect->buttonIndex] =
+ gSaveContext.save.saveInfo.playerData.threeDayResetCount;
for (i = 0; i < ARRAY_COUNT(gSaveContext.save.saveInfo.playerData.playerName); i++) {
- fileSelect->unk_24414[fileSelect->unk_24480][i] = gSaveContext.save.saveInfo.playerData.playerName[i];
+ fileSelect->fileNames[fileSelect->buttonIndex][i] = gSaveContext.save.saveInfo.playerData.playerName[i];
}
- fileSelect->healthCapacity[fileSelect->unk_24480] = gSaveContext.save.saveInfo.playerData.healthCapacity;
- fileSelect->health[fileSelect->unk_24480] = gSaveContext.save.saveInfo.playerData.health;
- fileSelect->unk_24454[fileSelect->unk_24480] = gSaveContext.save.saveInfo.inventory.defenseHearts;
- fileSelect->unk_24444[fileSelect->unk_24480] = gSaveContext.save.saveInfo.inventory.questItems;
- fileSelect->unk_24458[fileSelect->unk_24480] = gSaveContext.save.time;
- fileSelect->unk_24460[fileSelect->unk_24480] = gSaveContext.save.day;
- fileSelect->unk_24468[fileSelect->unk_24480] = gSaveContext.save.isOwlSave;
- fileSelect->rupees[fileSelect->unk_24480] = gSaveContext.save.saveInfo.playerData.rupees;
- fileSelect->unk_24474[fileSelect->unk_24480] = CUR_UPG_VALUE(UPG_WALLET);
+ fileSelect->healthCapacity[fileSelect->buttonIndex] = gSaveContext.save.saveInfo.playerData.healthCapacity;
+ fileSelect->health[fileSelect->buttonIndex] = gSaveContext.save.saveInfo.playerData.health;
+ fileSelect->defenseHearts[fileSelect->buttonIndex] = gSaveContext.save.saveInfo.inventory.defenseHearts;
+ fileSelect->questItems[fileSelect->buttonIndex] = gSaveContext.save.saveInfo.inventory.questItems;
+ fileSelect->time[fileSelect->buttonIndex] = gSaveContext.save.time;
+ fileSelect->day[fileSelect->buttonIndex] = gSaveContext.save.day;
+ fileSelect->isOwlSave[fileSelect->buttonIndex] = gSaveContext.save.isOwlSave;
+ fileSelect->rupees[fileSelect->buttonIndex] = gSaveContext.save.saveInfo.playerData.rupees;
+ fileSelect->walletUpgrades[fileSelect->buttonIndex] = CUR_UPG_VALUE(UPG_WALLET);
for (i = 0, maskCount = 0; i < 24; i++) {
if (gSaveContext.save.saveInfo.inventory.items[i + 24] != ITEM_NONE) {
@@ -1484,17 +1609,19 @@ void Sram_InitSave(FileSelectState* fileSelect2, SramContext* sramCtx) {
}
}
- fileSelect->maskCount[fileSelect->unk_24480] = maskCount;
- fileSelect->heartPieceCount[fileSelect->unk_24480] =
- (gSaveContext.save.saveInfo.inventory.questItems & 0xF0000000) >> 0x1C;
+ fileSelect->maskCount[fileSelect->buttonIndex] = maskCount;
+ fileSelect->heartPieceCount[fileSelect->buttonIndex] = GET_QUEST_HEART_PIECE_COUNT;
}
gSaveContext.save.time = D_801F6AF0;
- gSaveContext.unk_3F3F = D_801F6AF2;
+ gSaveContext.flashSaveAvailable = D_801F6AF2;
}
-void func_80146DF8(SramContext* sramCtx) {
- if (gSaveContext.unk_3F3F) {
+/**
+ * Write the SaveOptions of SaveContext to the save buffer
+ */
+void Sram_WriteSaveOptionsToBuffer(SramContext* sramCtx) {
+ if (gSaveContext.flashSaveAvailable) {
// TODO: macros for languages
gSaveContext.options.language = 1;
Lib_MemCpy(sramCtx->saveBuf, &gSaveContext.options, sizeof(SaveOptions));
@@ -1508,7 +1635,7 @@ void Sram_InitSram(GameState* gameState, SramContext* sramCtx) {
}
void Sram_Alloc(GameState* gameState, SramContext* sramCtx) {
- if (gSaveContext.unk_3F3F) {
+ if (gSaveContext.flashSaveAvailable) {
sramCtx->saveBuf = THA_AllocTailAlign16(&gameState->heap, SAVE_BUFFER_SIZE);
sramCtx->status = 0;
}
@@ -1517,7 +1644,7 @@ void Sram_Alloc(GameState* gameState, SramContext* sramCtx) {
/**
* Synchronous flash write
*/
-void func_80146EBC(SramContext* sramCtx, s32 curPage, s32 numPages) {
+void Sram_SyncWriteToFlash(SramContext* sramCtx, s32 curPage, s32 numPages) {
sramCtx->curPage = curPage;
sramCtx->numPages = numPages;
SysFlashrom_WriteDataSync(sramCtx->saveBuf, curPage, numPages);
@@ -1533,8 +1660,8 @@ void Sram_SaveSpecialEnterClockTown(PlayState* play) {
gSaveContext.save.isFirstCycle = true;
gSaveContext.save.isOwlSave = false;
func_80145698(sramCtx);
- SysFlashrom_WriteDataSync(sramCtx->saveBuf, D_801C67C8[gSaveContext.fileNum * 2],
- D_801C6818[gSaveContext.fileNum * 2]);
+ SysFlashrom_WriteDataSync(sramCtx->saveBuf, gFlashSaveStartPages[gSaveContext.fileNum * 2],
+ gFlashSpecialSaveNumPages[gSaveContext.fileNum * 2]);
}
/**
@@ -1555,25 +1682,25 @@ void Sram_SaveSpecialNewDay(PlayState* play) {
gSaveContext.save.day = day;
gSaveContext.save.time = time;
gSaveContext.save.cutsceneIndex = cutsceneIndex;
- SysFlashrom_WriteDataSync(play->sramCtx.saveBuf, D_801C67C8[gSaveContext.fileNum * 2],
- D_801C67F0[gSaveContext.fileNum * 2]);
+ SysFlashrom_WriteDataSync(play->sramCtx.saveBuf, gFlashSaveStartPages[gSaveContext.fileNum * 2],
+ gFlashSaveNumPages[gSaveContext.fileNum * 2]);
}
-void func_80147008(SramContext* sramCtx, u32 curPage, u32 numPages) {
+void Sram_SetFlashPagesDefault(SramContext* sramCtx, u32 curPage, u32 numPages) {
sramCtx->curPage = curPage;
sramCtx->numPages = numPages;
sramCtx->status = 1;
}
-void func_80147020(SramContext* sramCtx) {
+void Sram_StartWriteToFlashDefault(SramContext* sramCtx) {
// async flash write
SysFlashrom_WriteDataAsync(sramCtx->saveBuf, sramCtx->curPage, sramCtx->numPages);
- sramCtx->unk_18 = osGetTime();
+ sramCtx->startWriteOsTime = osGetTime();
sramCtx->status = 2;
}
-void func_80147068(SramContext* sramCtx) {
+void Sram_UpdateWriteToFlashDefault(SramContext* sramCtx) {
if (sramCtx->status == 2) {
if (SysFlashrom_IsBusy() != 0) { // if task running
if (SysFlashrom_AwaitResult() == 0) { // wait for task done
@@ -1584,25 +1711,26 @@ void func_80147068(SramContext* sramCtx) {
sramCtx->status = 4;
}
}
- } else if (OSTIME_TO_TIMER(osGetTime() - sramCtx->unk_18) >= SECONDS_TO_TIMER(2)) {
+ } else if (OSTIME_TO_TIMER(osGetTime() - sramCtx->startWriteOsTime) >= SECONDS_TO_TIMER(2)) {
+ // Finished status is hardcoded to 2 seconds instead of when the task finishes
sramCtx->status = 0;
}
}
-void func_80147138(SramContext* sramCtx, s32 curPage, s32 numPages) {
+void Sram_SetFlashPagesOwlSave(SramContext* sramCtx, s32 curPage, s32 numPages) {
sramCtx->curPage = curPage;
sramCtx->numPages = numPages;
sramCtx->status = 6;
}
-void func_80147150(SramContext* sramCtx) {
+void Sram_StartWriteToFlashOwlSave(SramContext* sramCtx) {
SysFlashrom_WriteDataAsync(sramCtx->saveBuf, sramCtx->curPage, sramCtx->numPages);
- sramCtx->unk_18 = osGetTime();
+ sramCtx->startWriteOsTime = osGetTime();
sramCtx->status = 7;
}
-void func_80147198(SramContext* sramCtx) {
+void Sram_UpdateWriteToFlashOwlSave(SramContext* sramCtx) {
if (sramCtx->status == 7) {
if (SysFlashrom_IsBusy() != 0) { // Is task running
if (SysFlashrom_AwaitResult() == 0) { // Wait for task done
@@ -1621,7 +1749,8 @@ void func_80147198(SramContext* sramCtx) {
sramCtx->status = 4;
}
}
- } else if (OSTIME_TO_TIMER(osGetTime() - sramCtx->unk_18) >= SECONDS_TO_TIMER(2)) {
+ } else if (OSTIME_TO_TIMER(osGetTime() - sramCtx->startWriteOsTime) >= SECONDS_TO_TIMER(2)) {
+ // Finished status is hardcoded to 2 seconds instead of when the task finishes
sramCtx->status = 0;
bzero(sramCtx->saveBuf, SAVE_BUFFER_SIZE);
gSaveContext.save.isOwlSave = false;
@@ -1648,8 +1777,9 @@ void func_80147314(SramContext* sramCtx, s32 fileNum) {
gSaveContext.save.saveInfo.checksum = Sram_CalcChecksum(&gSaveContext, offsetof(SaveContext, fileNum));
Lib_MemCpy(sramCtx->saveBuf, &gSaveContext, offsetof(SaveContext, fileNum));
- func_80146EBC(sramCtx, D_801C6840[fileNum * 2], D_801C6850[fileNum * 2]);
- func_80146EBC(sramCtx, D_801C6840[fileNum * 2 + 1], D_801C6850[fileNum * 2]);
+ 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]);
gSaveContext.save.isOwlSave = true;
@@ -1661,6 +1791,7 @@ void func_80147314(SramContext* sramCtx, s32 fileNum) {
gSaveContext.save.saveInfo.playerData.newf[5] = '3';
}
+// Used by `Sram_CopySave` with `isOwlSave` set
void func_80147414(SramContext* sramCtx, s32 fileNum, s32 arg2) {
s32 pad;
@@ -1668,16 +1799,18 @@ void func_80147414(SramContext* sramCtx, s32 fileNum, s32 arg2) {
bzero(sramCtx->saveBuf, SAVE_BUFFER_SIZE);
// Read save file
- if (SysFlashrom_ReadData(sramCtx->saveBuf, D_801C6840[fileNum * 2], D_801C6850[fileNum * 2]) != 0) {
+ if (SysFlashrom_ReadData(sramCtx->saveBuf, gFlashOwlSaveStartPages[fileNum * 2],
+ gFlashOwlSaveNumPages[fileNum * 2]) != 0) {
// If failed, read backup save file
- SysFlashrom_ReadData(sramCtx->saveBuf, D_801C6840[fileNum * 2 + 1], D_801C6850[fileNum * 2 + 1]);
+ SysFlashrom_ReadData(sramCtx->saveBuf, gFlashOwlSaveStartPages[fileNum * 2 + 1],
+ gFlashOwlSaveNumPages[fileNum * 2 + 1]);
}
// Copy buffer to save context
Lib_MemCpy(&gSaveContext, sramCtx->saveBuf, offsetof(SaveContext, fileNum));
- func_80146EBC(sramCtx, D_801C6840[arg2 * 2], D_801C6850[arg2 * 2]);
- func_80146EBC(sramCtx, D_801C6840[arg2 * 2 + 1], D_801C6850[arg2 * 2]);
+ Sram_SyncWriteToFlash(sramCtx, gFlashOwlSaveStartPages[arg2 * 2], gFlashOwlSaveNumPages[arg2 * 2]);
+ Sram_SyncWriteToFlash(sramCtx, gFlashOwlSaveStartPages[arg2 * 2 + 1], gFlashOwlSaveNumPages[arg2 * 2]);
}
void Sram_nop8014750C(UNK_TYPE4 arg0) {
diff --git a/src/code/z_vr_box.c b/src/code/z_vr_box.c
index 911e3e757..dd0785d94 100644
--- a/src/code/z_vr_box.c
+++ b/src/code/z_vr_box.c
@@ -239,7 +239,7 @@ void func_80143324(PlayState* play, SkyboxContext* skyboxCtx, s16 skyboxId) {
case SKYBOX_NORMAL_SKY:
osCreateMesgQueue(&skyboxCtx->loadQueue, &skyboxCtx->loadMsg, 1);
- if (play->envCtx.unk_10 == 0) {
+ if (play->envCtx.skybox1Index == 0) {
// Send a DMA request for the clear sky texture
size = SEGMENT_ROM_SIZE(d2_fine_static);
@@ -256,7 +256,7 @@ void func_80143324(PlayState* play, SkyboxContext* skyboxCtx, s16 skyboxId) {
osRecvMesg(&skyboxCtx->loadQueue, NULL, OS_MESG_BLOCK);
osCreateMesgQueue(&skyboxCtx->loadQueue, &skyboxCtx->loadMsg, 1);
- if (play->envCtx.unk_11 == 0) {
+ if (play->envCtx.skybox2Index == 0) {
// Send a DMA request for the clear sky texture
size = SEGMENT_ROM_SIZE(d2_fine_static);