From a3b4dcf388f7b424aedce4e9e8b130fa5c82a5d9 Mon Sep 17 00:00:00 2001 From: fig02 Date: Mon, 15 Nov 2021 16:33:44 -0500 Subject: File Select (z_file_choose) OK (#1012) * matching split * migrate progress * split done and rodata migrated * all data migrated to c * start init * progress * progress * progress * progress * progress * progress * copy done * progress * erase and settings done * progress * progress * progress * start keyboard * progress * progress * progress * progress * Minor progress * fix z_magic_dark issue * func_80806F34 decomp'd * verified equivalence * one fix * format * merge petries work * reorganizing * lots of reorganizing and wraning fixing * rename file * remove language enum * unwanted changes * some symbol replacement, organization, and some names * all symbols replaced, some organization * some more cleanup * continue docs * Match the remaining functions in file_choose * merge master * select mode documented, all functions in file_choose.c named * nameset functions named, some other cleaning * some more general cleanup * stub comments for cm, name a few things * fix data and sizeof * copy/erase functions and modes named * rename assets, format * change some struct members * fixes * review1 * fix maching error * extract VTX data * re add werror to ZAPD * review 2 * fix * remove file boundary padding * remove zeroes * review3 * change skybox stuff * changes to vs etc Co-authored-by: KrimtonZ Co-authored-by: Thar0 <17233964+Thar0@users.noreply.github.com> Co-authored-by: mzxrules Co-authored-by: petrie911 Co-authored-by: Roman971 Co-authored-by: Louis --- src/code/code_800EC960.c | 8 ++-- src/code/graph.c | 2 +- src/code/z_demo.c | 6 +-- src/code/z_game_dlftbls.c | 2 +- src/code/z_parameter.c | 8 ++-- src/code/z_play.c | 4 +- src/code/z_sram.c | 120 +++++++++++++++++++++++----------------------- src/code/z_vr_box.c | 14 +++--- 8 files changed, 84 insertions(+), 80 deletions(-) (limited to 'src/code') diff --git a/src/code/code_800EC960.c b/src/code/code_800EC960.c index afae2a59c..3dad66642 100644 --- a/src/code/code_800EC960.c +++ b/src/code/code_800EC960.c @@ -519,15 +519,15 @@ void func_800EC960(u8 custom) { void Audio_GetOcaInput(void) { Input inputs[4]; - Input* controller1 = &inputs[0]; + Input* input = &inputs[0]; u32 sp18; sp18 = sCurOcarinaBtnPress; PadMgr_RequestPadData(&gPadMgr, inputs, 0); - sCurOcarinaBtnPress = controller1->cur.button; + sCurOcarinaBtnPress = input->cur.button; sPrevOcarinaBtnPress = sp18; - sCurOcaStick.x = controller1->rel.stick_x; - sCurOcaStick.y = controller1->rel.stick_y; + sCurOcaStick.x = input->rel.stick_x; + sCurOcaStick.y = input->rel.stick_y; } f32 Audio_OcaAdjStick(s8 inp) { diff --git a/src/code/graph.c b/src/code/graph.c index be788f5f5..80d6714af 100644 --- a/src/code/graph.c +++ b/src/code/graph.c @@ -116,7 +116,7 @@ GameStateOverlay* Graph_GetNextGameState(GameState* gameState) { if (gameStateInitFunc == Opening_Init) { return &gGameStateOverlayTable[4]; } - if (gameStateInitFunc == func_80811A20) { + if (gameStateInitFunc == FileChoose_Init) { return &gGameStateOverlayTable[5]; } diff --git a/src/code/z_demo.c b/src/code/z_demo.c index da566eb6b..817f0d70e 100644 --- a/src/code/z_demo.c +++ b/src/code/z_demo.c @@ -148,16 +148,16 @@ void func_80064558(GlobalContext* globalCtx, CutsceneContext* csCtx) { } void func_800645A0(GlobalContext* globalCtx, CutsceneContext* csCtx) { - Input* pad1 = &globalCtx->state.input[0]; + Input* input = &globalCtx->state.input[0]; - if (CHECK_BTN_ALL(pad1->press.button, BTN_DLEFT) && (csCtx->state == CS_STATE_IDLE) && + if (CHECK_BTN_ALL(input->press.button, BTN_DLEFT) && (csCtx->state == CS_STATE_IDLE) && (gSaveContext.sceneSetupIndex >= 4)) { D_8015FCC8 = 0; gSaveContext.cutsceneIndex = 0xFFFD; gSaveContext.cutsceneTrigger = 1; } - if (CHECK_BTN_ALL(pad1->press.button, BTN_DUP) && (csCtx->state == CS_STATE_IDLE) && + if (CHECK_BTN_ALL(input->press.button, BTN_DUP) && (csCtx->state == CS_STATE_IDLE) && (gSaveContext.sceneSetupIndex >= 4) && !gDbgCamEnabled) { D_8015FCC8 = 1; gSaveContext.cutsceneIndex = 0xFFFD; diff --git a/src/code/z_game_dlftbls.c b/src/code/z_game_dlftbls.c index d54364068..a8cc07733 100644 --- a/src/code/z_game_dlftbls.c +++ b/src/code/z_game_dlftbls.c @@ -14,5 +14,5 @@ GameStateOverlay gGameStateOverlayTable[] = { GAMESTATE_OVERLAY(title, Title_Init, Title_Destroy, sizeof(TitleContext)), GAMESTATE_OVERLAY_INTERNAL(Gameplay_Init, Gameplay_Destroy, sizeof(GlobalContext)), GAMESTATE_OVERLAY(opening, Opening_Init, Opening_Destroy, sizeof(OpeningContext)), - GAMESTATE_OVERLAY(file_choose, func_80811A20, func_80811A18, 0x1CAE0), + GAMESTATE_OVERLAY(file_choose, FileChoose_Init, FileChoose_Destroy, sizeof(FileChooseContext)), }; diff --git a/src/code/z_parameter.c b/src/code/z_parameter.c index cca781945..26a926126 100644 --- a/src/code/z_parameter.c +++ b/src/code/z_parameter.c @@ -3796,15 +3796,15 @@ void Interface_Update(GlobalContext* globalCtx) { s16 alpha; s16 alpha1; u16 action; - Input* input = &globalCtx->state.input[2]; + Input* debugInput = &globalCtx->state.input[2]; - if (CHECK_BTN_ALL(input->press.button, BTN_DLEFT)) { + if (CHECK_BTN_ALL(debugInput->press.button, BTN_DLEFT)) { gSaveContext.language = 0; osSyncPrintf("J_N=%x J_N=%x\n", gSaveContext.language, &gSaveContext.language); - } else if (CHECK_BTN_ALL(input->press.button, BTN_DUP)) { + } else if (CHECK_BTN_ALL(debugInput->press.button, BTN_DUP)) { gSaveContext.language = 1; osSyncPrintf("J_N=%x J_N=%x\n", gSaveContext.language, &gSaveContext.language); - } else if (CHECK_BTN_ALL(input->press.button, BTN_DRIGHT)) { + } else if (CHECK_BTN_ALL(debugInput->press.button, BTN_DRIGHT)) { gSaveContext.language = 2; osSyncPrintf("J_N=%x J_N=%x\n", gSaveContext.language, &gSaveContext.language); } diff --git a/src/code/z_play.c b/src/code/z_play.c index 0807d91a7..b7fbe0862 100644 --- a/src/code/z_play.c +++ b/src/code/z_play.c @@ -584,7 +584,7 @@ void Gameplay_Update(GlobalContext* globalCtx) { gSaveContext.minigameState = 3; } } else { - SET_NEXT_GAMESTATE(&globalCtx->state, func_80811A20, char[0x1CAE0]); + SET_NEXT_GAMESTATE(&globalCtx->state, FileChoose_Init, FileChooseContext); } } else { globalCtx->transitionCtx.destroy(&globalCtx->transitionCtx); @@ -1439,7 +1439,7 @@ void* Gameplay_LoadFile(GlobalContext* globalCtx, RomFile* file) { } void Gameplay_InitEnvironment(GlobalContext* globalCtx, s16 skyboxId) { - Skybox_Init(globalCtx, &globalCtx->skyboxCtx, skyboxId); + Skybox_Init(&globalCtx->state, &globalCtx->skyboxCtx, skyboxId); Environment_Init(globalCtx, &globalCtx->envCtx, 0); } diff --git a/src/code/z_sram.c b/src/code/z_sram.c index 195da41b5..030529293 100644 --- a/src/code/z_sram.c +++ b/src/code/z_sram.c @@ -82,7 +82,7 @@ typedef struct { #define DEFENSE OFFSETOF(SaveContext, inventory.defenseHearts) #define HEALTH OFFSETOF(SaveContext, health) -#define SLOT_OFFSET(idx) (SLOT_SIZE * idx + 0x20) +#define SLOT_OFFSET(index) (SRAM_HEADER_SIZE + 0x10 + (index * SLOT_SIZE)) u16 gSramSlotOffsets[] = { SLOT_OFFSET(0), @@ -102,7 +102,7 @@ static SavePlayerData sNewSavePlayerData = { { 0x3E, 0x3E, 0x3E, 0x3E, 0x3E, 0x3E, 0x3E, 0x3E }, // playerName 0, // n64ddFlag 0x30, // healthCapacity - 0x30, // heartStatus + 0x30, // defense 0, // magicLevel 0x30, // magic 0, // rupees @@ -381,10 +381,10 @@ void Sram_OpenSave(SramContext* sramCtx) { osSyncPrintf(VT_FGCOL(BLUE)); osSyncPrintf("\n====================================================================\n"); - MemCopy(gScarecrowCustomSongPtr, &gSaveContext.scarecrowCustomSong, 0x360); + MemCopy(gScarecrowCustomSongPtr, &gSaveContext.scarecrowCustomSong, sizeof(gSaveContext.scarecrowCustomSong)); ptr = (u8*)gScarecrowCustomSongPtr; - for (i = 0; i < 0x360; i++, ptr++) { + for (i = 0; i < ARRAY_COUNT(gSaveContext.scarecrowCustomSong); i++, ptr++) { osSyncPrintf("%d, ", *ptr); } @@ -396,10 +396,10 @@ void Sram_OpenSave(SramContext* sramCtx) { osSyncPrintf(VT_FGCOL(GREEN)); osSyncPrintf("\n====================================================================\n"); - MemCopy(gScarecrowSpawnSongPtr, &gSaveContext.scarecrowSpawnSong, 0x80); + MemCopy(gScarecrowSpawnSongPtr, &gSaveContext.scarecrowSpawnSong, sizeof(gSaveContext.scarecrowSpawnSong)); ptr = gScarecrowSpawnSongPtr; - for (i = 0; i < 0x80; i++, ptr++) { + for (i = 0; i < ARRAY_COUNT(gSaveContext.scarecrowSpawnSong); i++, ptr++) { osSyncPrintf("%d, ", *ptr); } @@ -651,23 +651,22 @@ void Sram_VerifyAndLoadAllSaves(FileChooseContext* fileChooseCtx, SramContext* s MemCopy(&fileChooseCtx->n64ddFlags[2], sramCtx->readBuff + SLOT_OFFSET(2) + N64DD, sizeof(fileChooseCtx->n64ddFlags[0])); - MemCopy(&fileChooseCtx->heartStatus[0], sramCtx->readBuff + SLOT_OFFSET(0) + DEFENSE, - sizeof(fileChooseCtx->heartStatus[0])); - MemCopy(&fileChooseCtx->heartStatus[1], sramCtx->readBuff + SLOT_OFFSET(1) + DEFENSE, - sizeof(fileChooseCtx->heartStatus[0])); - MemCopy(&fileChooseCtx->heartStatus[2], sramCtx->readBuff + SLOT_OFFSET(2) + DEFENSE, - sizeof(fileChooseCtx->heartStatus[0])); + MemCopy(&fileChooseCtx->defense[0], sramCtx->readBuff + SLOT_OFFSET(0) + DEFENSE, + sizeof(fileChooseCtx->defense[0])); + MemCopy(&fileChooseCtx->defense[1], sramCtx->readBuff + SLOT_OFFSET(1) + DEFENSE, + sizeof(fileChooseCtx->defense[0])); + MemCopy(&fileChooseCtx->defense[2], sramCtx->readBuff + SLOT_OFFSET(2) + DEFENSE, + sizeof(fileChooseCtx->defense[0])); - MemCopy(&fileChooseCtx->nowLife[0], sramCtx->readBuff + SLOT_OFFSET(0) + HEALTH, sizeof(fileChooseCtx->nowLife[0])); - MemCopy(&fileChooseCtx->nowLife[1], sramCtx->readBuff + SLOT_OFFSET(1) + HEALTH, sizeof(fileChooseCtx->nowLife[0])); - MemCopy(&fileChooseCtx->nowLife[2], sramCtx->readBuff + SLOT_OFFSET(2) + HEALTH, sizeof(fileChooseCtx->nowLife[0])); + MemCopy(&fileChooseCtx->health[0], sramCtx->readBuff + SLOT_OFFSET(0) + HEALTH, sizeof(fileChooseCtx->health[0])); + MemCopy(&fileChooseCtx->health[1], sramCtx->readBuff + SLOT_OFFSET(1) + HEALTH, sizeof(fileChooseCtx->health[0])); + MemCopy(&fileChooseCtx->health[2], sramCtx->readBuff + SLOT_OFFSET(2) + HEALTH, sizeof(fileChooseCtx->health[0])); osSyncPrintf("f_64dd=%d, %d, %d\n", fileChooseCtx->n64ddFlags[0], fileChooseCtx->n64ddFlags[1], fileChooseCtx->n64ddFlags[2]); - osSyncPrintf("heart_status=%d, %d, %d\n", fileChooseCtx->heartStatus[0], fileChooseCtx->heartStatus[1], - fileChooseCtx->heartStatus[2]); - osSyncPrintf("now_life=%d, %d, %d\n", fileChooseCtx->nowLife[0], fileChooseCtx->nowLife[1], - fileChooseCtx->nowLife[2]); + osSyncPrintf("heart_status=%d, %d, %d\n", fileChooseCtx->defense[0], fileChooseCtx->defense[1], + fileChooseCtx->defense[2]); + osSyncPrintf("now_life=%d, %d, %d\n", fileChooseCtx->health[0], fileChooseCtx->health[1], fileChooseCtx->health[2]); } void Sram_InitSave(FileChooseContext* fileChooseCtx, SramContext* sramCtx) { @@ -676,7 +675,7 @@ void Sram_InitSave(FileChooseContext* fileChooseCtx, SramContext* sramCtx) { u16* ptr; u16 checksum; - if (fileChooseCtx->btnIdx != 0) { + if (fileChooseCtx->buttonIndex != 0) { Sram_InitNewSave(); } else { Sram_InitDebugSave(); @@ -687,12 +686,12 @@ void Sram_InitSave(FileChooseContext* fileChooseCtx, SramContext* sramCtx) { gSaveContext.dayTime = 0x6AAB; gSaveContext.cutsceneIndex = 0xFFF1; - if (fileChooseCtx->btnIdx == 0) { + if (fileChooseCtx->buttonIndex == 0) { gSaveContext.cutsceneIndex = 0; } for (offset = 0; offset < 8; offset++) { - gSaveContext.playerName[offset] = fileChooseCtx->fileNames[fileChooseCtx->btnIdx][offset]; + gSaveContext.playerName[offset] = fileChooseCtx->fileNames[fileChooseCtx->buttonIndex][offset]; } gSaveContext.newf[0] = 'Z'; @@ -750,14 +749,14 @@ void Sram_InitSave(FileChooseContext* fileChooseCtx, SramContext* sramCtx) { sizeof(fileChooseCtx->questItems[0])); MemCopy(&fileChooseCtx->n64ddFlags[gSaveContext.fileNum], sramCtx->readBuff + j + N64DD, sizeof(fileChooseCtx->n64ddFlags[0])); - MemCopy(&fileChooseCtx->heartStatus[gSaveContext.fileNum], sramCtx->readBuff + j + DEFENSE, - sizeof(fileChooseCtx->heartStatus[0])); - MemCopy(&fileChooseCtx->nowLife[gSaveContext.fileNum], sramCtx->readBuff + j + HEALTH, - sizeof(fileChooseCtx->nowLife[0])); + MemCopy(&fileChooseCtx->defense[gSaveContext.fileNum], sramCtx->readBuff + j + DEFENSE, + sizeof(fileChooseCtx->defense[0])); + MemCopy(&fileChooseCtx->health[gSaveContext.fileNum], sramCtx->readBuff + j + HEALTH, + sizeof(fileChooseCtx->health[0])); osSyncPrintf("f_64dd[%d]=%d\n", gSaveContext.fileNum, fileChooseCtx->n64ddFlags[gSaveContext.fileNum]); - osSyncPrintf("heart_status[%d]=%d\n", gSaveContext.fileNum, fileChooseCtx->heartStatus[gSaveContext.fileNum]); - osSyncPrintf("now_life[%d]=%d\n", gSaveContext.fileNum, fileChooseCtx->nowLife[gSaveContext.fileNum]); + osSyncPrintf("heart_status[%d]=%d\n", gSaveContext.fileNum, fileChooseCtx->defense[gSaveContext.fileNum]); + osSyncPrintf("now_life[%d]=%d\n", gSaveContext.fileNum, fileChooseCtx->health[gSaveContext.fileNum]); } void Sram_EraseSave(FileChooseContext* fileChooseCtx, SramContext* sramCtx) { @@ -765,14 +764,14 @@ void Sram_EraseSave(FileChooseContext* fileChooseCtx, SramContext* sramCtx) { Sram_InitNewSave(); - offset = gSramSlotOffsets[fileChooseCtx->selectedFileIdx]; + offset = gSramSlotOffsets[fileChooseCtx->selectedFileIndex]; MemCopy(sramCtx->readBuff + offset, &gSaveContext, sizeof(Save)); SsSram_ReadWrite(OS_K1_TO_PHYSICAL(0xA8000000) + offset, &gSaveContext, SLOT_SIZE, OS_WRITE); - MemCopy(&fileChooseCtx->n64ddFlags[fileChooseCtx->selectedFileIdx], sramCtx->readBuff + offset + N64DD, + MemCopy(&fileChooseCtx->n64ddFlags[fileChooseCtx->selectedFileIndex], sramCtx->readBuff + offset + N64DD, sizeof(fileChooseCtx->n64ddFlags[0])); - offset = gSramSlotOffsets[fileChooseCtx->selectedFileIdx + 3]; + offset = gSramSlotOffsets[fileChooseCtx->selectedFileIndex + 3]; MemCopy(sramCtx->readBuff + offset, &gSaveContext, sizeof(Save)); SsSram_ReadWrite(OS_K1_TO_PHYSICAL(0xA8000000) + offset, &gSaveContext, SLOT_SIZE, OS_WRITE); @@ -782,45 +781,48 @@ void Sram_EraseSave(FileChooseContext* fileChooseCtx, SramContext* sramCtx) { void Sram_CopySave(FileChooseContext* fileChooseCtx, SramContext* sramCtx) { s32 offset; - osSyncPrintf("READ=%d(%x) COPY=%d(%x)\n", fileChooseCtx->selectedFileIdx, - gSramSlotOffsets[fileChooseCtx->selectedFileIdx], fileChooseCtx->copyDestFileIdx, - gSramSlotOffsets[fileChooseCtx->copyDestFileIdx]); + osSyncPrintf("READ=%d(%x) COPY=%d(%x)\n", fileChooseCtx->selectedFileIndex, + gSramSlotOffsets[fileChooseCtx->selectedFileIndex], fileChooseCtx->copyDestFileIndex, + gSramSlotOffsets[fileChooseCtx->copyDestFileIndex]); - offset = gSramSlotOffsets[fileChooseCtx->selectedFileIdx]; + offset = gSramSlotOffsets[fileChooseCtx->selectedFileIndex]; MemCopy(&gSaveContext, sramCtx->readBuff + offset, sizeof(Save)); - offset = gSramSlotOffsets[fileChooseCtx->copyDestFileIdx]; + offset = gSramSlotOffsets[fileChooseCtx->copyDestFileIndex]; MemCopy(sramCtx->readBuff + offset, &gSaveContext, sizeof(Save)); - offset = gSramSlotOffsets[fileChooseCtx->copyDestFileIdx + 3]; + offset = gSramSlotOffsets[fileChooseCtx->copyDestFileIndex + 3]; MemCopy(sramCtx->readBuff + offset, &gSaveContext, sizeof(Save)); SsSram_ReadWrite(OS_K1_TO_PHYSICAL(0xA8000000), sramCtx->readBuff, SRAM_SIZE, OS_WRITE); - offset = gSramSlotOffsets[fileChooseCtx->copyDestFileIdx]; + offset = gSramSlotOffsets[fileChooseCtx->copyDestFileIndex]; - MemCopy(&fileChooseCtx->deaths[fileChooseCtx->copyDestFileIdx], sramCtx->readBuff + offset + DEATHS, + MemCopy(&fileChooseCtx->deaths[fileChooseCtx->copyDestFileIndex], sramCtx->readBuff + offset + DEATHS, sizeof(fileChooseCtx->deaths[0])); - MemCopy(&fileChooseCtx->fileNames[fileChooseCtx->copyDestFileIdx], sramCtx->readBuff + offset + NAME, + MemCopy(&fileChooseCtx->fileNames[fileChooseCtx->copyDestFileIndex], sramCtx->readBuff + offset + NAME, sizeof(fileChooseCtx->fileNames[0])); - MemCopy(&fileChooseCtx->healthCapacities[fileChooseCtx->copyDestFileIdx], sramCtx->readBuff + offset + HEALTH_CAP, + MemCopy(&fileChooseCtx->healthCapacities[fileChooseCtx->copyDestFileIndex], sramCtx->readBuff + offset + HEALTH_CAP, sizeof(fileChooseCtx->healthCapacities[0])); - MemCopy(&fileChooseCtx->questItems[fileChooseCtx->copyDestFileIdx], sramCtx->readBuff + offset + QUEST, + MemCopy(&fileChooseCtx->questItems[fileChooseCtx->copyDestFileIndex], sramCtx->readBuff + offset + QUEST, sizeof(fileChooseCtx->questItems[0])); - MemCopy(&fileChooseCtx->n64ddFlags[fileChooseCtx->copyDestFileIdx], sramCtx->readBuff + offset + N64DD, + MemCopy(&fileChooseCtx->n64ddFlags[fileChooseCtx->copyDestFileIndex], sramCtx->readBuff + offset + N64DD, sizeof(fileChooseCtx->n64ddFlags[0])); - MemCopy(&fileChooseCtx->heartStatus[fileChooseCtx->copyDestFileIdx], sramCtx->readBuff + offset + DEFENSE, - sizeof(fileChooseCtx->heartStatus[0])); - MemCopy(&fileChooseCtx->nowLife[fileChooseCtx->copyDestFileIdx], (sramCtx->readBuff + offset) + HEALTH, - sizeof(fileChooseCtx->nowLife[0])); + MemCopy(&fileChooseCtx->defense[fileChooseCtx->copyDestFileIndex], sramCtx->readBuff + offset + DEFENSE, + sizeof(fileChooseCtx->defense[0])); + MemCopy(&fileChooseCtx->health[fileChooseCtx->copyDestFileIndex], (sramCtx->readBuff + offset) + HEALTH, + sizeof(fileChooseCtx->health[0])); osSyncPrintf("f_64dd[%d]=%d\n", gSaveContext.fileNum, fileChooseCtx->n64ddFlags[gSaveContext.fileNum]); - osSyncPrintf("heart_status[%d]=%d\n", gSaveContext.fileNum, fileChooseCtx->heartStatus[gSaveContext.fileNum]); + osSyncPrintf("heart_status[%d]=%d\n", gSaveContext.fileNum, fileChooseCtx->defense[gSaveContext.fileNum]); osSyncPrintf("COPY終了\n"); // "Copy end" } -void Sram_Write16Bytes(SramContext* sramCtx) { - SsSram_ReadWrite(OS_K1_TO_PHYSICAL(0xA8000000), sramCtx->readBuff, 0x10, OS_WRITE); +/** + * Write the first 16 bytes of the read buffer to the SRAM header + */ +void Sram_WriteSramHeader(SramContext* sramCtx) { + SsSram_ReadWrite(OS_K1_TO_PHYSICAL(0xA8000000), sramCtx->readBuff, SRAM_HEADER_SIZE, OS_WRITE); } void Sram_InitSram(GameState* gameState, SramContext* sramCtx) { @@ -830,23 +832,23 @@ void Sram_InitSram(GameState* gameState, SramContext* sramCtx) { SsSram_ReadWrite(OS_K1_TO_PHYSICAL(0xA8000000), sramCtx->readBuff, SRAM_SIZE, OS_READ); for (i = 0; i < ARRAY_COUNTU(sZeldaMagic) - 3; i++) { - if (sZeldaMagic[i + 3] != sramCtx->readBuff[i + 3]) { + if (sZeldaMagic[i + SRAM_HEADER_MAGIC] != sramCtx->readBuff[i + SRAM_HEADER_MAGIC]) { osSyncPrintf("SRAM破壊!!!!!!\n"); // "SRAM destruction! ! ! ! ! !" - gSaveContext.language = sramCtx->readBuff[2]; + gSaveContext.language = sramCtx->readBuff[SRAM_HEADER_LANGUAGE]; MemCopy(sramCtx->readBuff, sZeldaMagic, sizeof(sZeldaMagic)); - sramCtx->readBuff[2] = gSaveContext.language; - Sram_Write16Bytes(sramCtx); + sramCtx->readBuff[SRAM_HEADER_LANGUAGE] = gSaveContext.language; + Sram_WriteSramHeader(sramCtx); } } - gSaveContext.audioSetting = sramCtx->readBuff[0] & 3; - gSaveContext.zTargetSetting = sramCtx->readBuff[1] & 1; - gSaveContext.language = sramCtx->readBuff[2]; + gSaveContext.audioSetting = sramCtx->readBuff[SRAM_HEADER_SOUND] & 3; + gSaveContext.zTargetSetting = sramCtx->readBuff[SRAM_HEADER_ZTARGET] & 1; + gSaveContext.language = sramCtx->readBuff[SRAM_HEADER_LANGUAGE]; if (gSaveContext.language > 2) { gSaveContext.language = 0; - sramCtx->readBuff[2] = gSaveContext.language; - Sram_Write16Bytes(sramCtx); + sramCtx->readBuff[SRAM_HEADER_LANGUAGE] = gSaveContext.language; + Sram_WriteSramHeader(sramCtx); } if (CHECK_BTN_ANY(gameState->input[2].cur.button, BTN_DRIGHT)) { diff --git a/src/code/z_vr_box.c b/src/code/z_vr_box.c index 3dbb91db5..8f2e5b4db 100644 --- a/src/code/z_vr_box.c +++ b/src/code/z_vr_box.c @@ -907,7 +907,9 @@ void Skybox_Setup(GlobalContext* globalCtx, SkyboxContext* skyboxCtx, s16 skybox } } -void Skybox_Init(GlobalContext* globalCtx, SkyboxContext* skyboxCtx, s16 skyboxId) { +void Skybox_Init(GameState* state, SkyboxContext* skyboxCtx, s16 skyboxId) { + GlobalContext* globalCtx = (GlobalContext*)state; + skyboxCtx->unk_140 = 0; skyboxCtx->rot.x = skyboxCtx->rot.y = skyboxCtx->rot.z = 0.0f; @@ -921,24 +923,24 @@ void Skybox_Init(GlobalContext* globalCtx, SkyboxContext* skyboxCtx, s16 skyboxI osSyncPrintf(VT_FGCOL(GREEN)); if (skyboxCtx->unk_140 != 0) { - skyboxCtx->dListBuf = GameState_Alloc(&globalCtx->state, 8 * 150 * sizeof(Gfx), "../z_vr_box.c", 1636); + skyboxCtx->dListBuf = GameState_Alloc(state, 8 * 150 * sizeof(Gfx), "../z_vr_box.c", 1636); ASSERT(skyboxCtx->dListBuf != NULL, "vr_box->dpList != NULL", "../z_vr_box.c", 1637); - skyboxCtx->roomVtx = GameState_Alloc(&globalCtx->state, 256 * sizeof(Vtx), "../z_vr_box.c", 1639); + skyboxCtx->roomVtx = GameState_Alloc(state, 256 * sizeof(Vtx), "../z_vr_box.c", 1639); ASSERT(skyboxCtx->roomVtx != NULL, "vr_box->roomVtx != NULL", "../z_vr_box.c", 1640); func_800AEFC8(skyboxCtx, skyboxId); } else { - skyboxCtx->dListBuf = GameState_Alloc(&globalCtx->state, 12 * 150 * sizeof(Gfx), "../z_vr_box.c", 1643); + skyboxCtx->dListBuf = GameState_Alloc(state, 12 * 150 * sizeof(Gfx), "../z_vr_box.c", 1643); ASSERT(skyboxCtx->dListBuf != NULL, "vr_box->dpList != NULL", "../z_vr_box.c", 1644); if (skyboxId == SKYBOX_CUTSCENE_MAP) { - skyboxCtx->roomVtx = GameState_Alloc(&globalCtx->state, 192 * sizeof(Vtx), "../z_vr_box.c", 1648); + skyboxCtx->roomVtx = GameState_Alloc(state, 192 * sizeof(Vtx), "../z_vr_box.c", 1648); ASSERT(skyboxCtx->roomVtx != NULL, "vr_box->roomVtx != NULL", "../z_vr_box.c", 1649); func_800AF178(skyboxCtx, 6); } else { - skyboxCtx->roomVtx = GameState_Alloc(&globalCtx->state, 160 * sizeof(Vtx), "../z_vr_box.c", 1653); + skyboxCtx->roomVtx = GameState_Alloc(state, 160 * sizeof(Vtx), "../z_vr_box.c", 1653); ASSERT(skyboxCtx->roomVtx != NULL, "vr_box->roomVtx != NULL", "../z_vr_box.c", 1654); func_800AF178(skyboxCtx, 5); -- cgit v1.2.3