diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/code/code_800EC960.c | 8 | ||||
| -rw-r--r-- | src/code/graph.c | 2 | ||||
| -rw-r--r-- | src/code/z_demo.c | 6 | ||||
| -rw-r--r-- | src/code/z_game_dlftbls.c | 2 | ||||
| -rw-r--r-- | src/code/z_parameter.c | 8 | ||||
| -rw-r--r-- | src/code/z_play.c | 4 | ||||
| -rw-r--r-- | src/code/z_sram.c | 120 | ||||
| -rw-r--r-- | src/code/z_vr_box.c | 14 | ||||
| -rw-r--r-- | src/overlays/actors/ovl_En_Ossan/z_en_ossan.c | 14 | ||||
| -rw-r--r-- | src/overlays/gamestates/ovl_file_choose/file_choose.h | 219 | ||||
| -rw-r--r-- | src/overlays/gamestates/ovl_file_choose/overlay.cfg | 2 | ||||
| -rw-r--r-- | src/overlays/gamestates/ovl_file_choose/z_file_choose.c | 1887 | ||||
| -rw-r--r-- | src/overlays/gamestates/ovl_file_choose/z_file_copy_erase.c | 1073 | ||||
| -rw-r--r-- | src/overlays/gamestates/ovl_file_choose/z_file_nameset_PAL.c | 1094 | ||||
| -rw-r--r-- | src/overlays/gamestates/ovl_file_choose/z_file_nameset_data.c | 11 | ||||
| -rw-r--r-- | src/overlays/gamestates/ovl_select/z_select.c | 36 |
16 files changed, 4270 insertions, 230 deletions
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); diff --git a/src/overlays/actors/ovl_En_Ossan/z_en_ossan.c b/src/overlays/actors/ovl_En_Ossan/z_en_ossan.c index ee4fb5e87..e3435fea2 100644 --- a/src/overlays/actors/ovl_En_Ossan/z_en_ossan.c +++ b/src/overlays/actors/ovl_En_Ossan/z_en_ossan.c @@ -665,8 +665,8 @@ void EnOssan_EndInteraction(GlobalContext* globalCtx, EnOssan* this) { this->stateFlag = OSSAN_STATE_IDLE; } -s32 EnOssan_TestEndInteraction(EnOssan* this, GlobalContext* globalCtx, Input* controller1) { - if (CHECK_BTN_ALL(controller1->press.button, BTN_B)) { +s32 EnOssan_TestEndInteraction(EnOssan* this, GlobalContext* globalCtx, Input* input) { + if (CHECK_BTN_ALL(input->press.button, BTN_B)) { EnOssan_EndInteraction(globalCtx, this); return true; } else { @@ -674,8 +674,8 @@ s32 EnOssan_TestEndInteraction(EnOssan* this, GlobalContext* globalCtx, Input* c } } -s32 EnOssan_TestCancelOption(EnOssan* this, GlobalContext* globalCtx, Input* controller1) { - if (CHECK_BTN_ALL(controller1->press.button, BTN_B)) { +s32 EnOssan_TestCancelOption(EnOssan* this, GlobalContext* globalCtx, Input* input) { + if (CHECK_BTN_ALL(input->press.button, BTN_B)) { this->stateFlag = this->tempStateFlag; func_8010B720(globalCtx, this->shelfSlots[this->cursorIndex]->actor.textId); return true; @@ -747,9 +747,9 @@ void EnOssan_State_Idle(EnOssan* this, GlobalContext* globalCtx, Player* player) } void EnOssan_UpdateJoystickInputState(GlobalContext* globalCtx, EnOssan* this) { - Input* controller1 = &globalCtx->state.input[0]; - s8 stickX = controller1->rel.stick_x; - s8 stickY = controller1->rel.stick_y; + Input* input = &globalCtx->state.input[0]; + s8 stickX = input->rel.stick_x; + s8 stickY = input->rel.stick_y; this->moveHorizontal = this->moveVertical = false; diff --git a/src/overlays/gamestates/ovl_file_choose/file_choose.h b/src/overlays/gamestates/ovl_file_choose/file_choose.h new file mode 100644 index 000000000..3590d3048 --- /dev/null +++ b/src/overlays/gamestates/ovl_file_choose/file_choose.h @@ -0,0 +1,219 @@ +#ifndef _FILE_CHOOSE_H_ +#define _FILE_CHOOSE_H_ + +#include "ultra64.h" +#include "global.h" +#include "vt.h" + + +#define GET_NEWF(sramCtx, slotNum, index) (sramCtx->readBuff[gSramSlotOffsets[slotNum] + OFFSETOF(SaveContext, newf[index])]) + +#define SLOT_OCCUPIED(sramCtx, slotNum) \ + ((GET_NEWF(sramCtx, slotNum, 0) == 'Z') || \ + (GET_NEWF(sramCtx, slotNum, 1) == 'E') || \ + (GET_NEWF(sramCtx, slotNum, 2) == 'L') || \ + (GET_NEWF(sramCtx, slotNum, 3) == 'D') || \ + (GET_NEWF(sramCtx, slotNum, 4) == 'A') || \ + (GET_NEWF(sramCtx, slotNum, 5) == 'Z')) + +// Init mode: Initial setup as the file select is starting up, fades and slides in various menu elements +// Config mode: Handles the bulk of the file select, various configuration tasks like picking a file, copy/erase, and the options menu +// Select mode: Displays the selected file with various details about it, and allows the player to confirm and open it +typedef enum { + /* 0 */ FS_MENU_MODE_INIT, + /* 1 */ FS_MENU_MODE_CONFIG, + /* 2 */ FS_MENU_MODE_SELECT +} MenuMode; + +typedef enum { + /* 00 */ CM_FADE_IN_START, + /* 01 */ CM_FADE_IN_END, + /* 02 */ CM_MAIN_MENU, + /* 03 */ CM_SETUP_COPY_SOURCE, + /* 04 */ CM_SELECT_COPY_SOURCE, + /* 05 */ CM_SETUP_COPY_DEST_1, + /* 06 */ CM_SETUP_COPY_DEST_2, + /* 07 */ CM_SELECT_COPY_DEST, + /* 08 */ CM_EXIT_TO_COPY_SOURCE_1, + /* 09 */ CM_EXIT_TO_COPY_SOURCE_2, + /* 10 */ CM_SETUP_COPY_CONFIRM_1, + /* 11 */ CM_SETUP_COPY_CONFIRM_2, + /* 12 */ CM_COPY_CONFIRM, + /* 13 */ CM_RETURN_TO_COPY_DEST, + /* 14 */ CM_COPY_ANIM_1, + /* 15 */ CM_COPY_ANIM_2, + /* 16 */ CM_COPY_ANIM_3, + /* 17 */ CM_COPY_ANIM_4, + /* 18 */ CM_COPY_ANIM_5, + /* 19 */ CM_COPY_RETURN_MAIN, + /* 20 */ CM_SETUP_ERASE_SELECT, + /* 21 */ CM_ERASE_SELECT, + /* 22 */ CM_SETUP_ERASE_CONFIRM_1, + /* 23 */ CM_SETUP_ERASE_CONFIRM_2, + /* 24 */ CM_ERASE_CONFIRM, + /* 25 */ CM_EXIT_TO_ERASE_SELECT_1, + /* 26 */ CM_EXIT_TO_ERASE_SELECT_2, + /* 27 */ CM_ERASE_ANIM_1, + /* 28 */ CM_ERASE_ANIM_2, + /* 29 */ CM_ERASE_ANIM_3, + /* 30 */ CM_EXIT_ERASE_TO_MAIN, + /* 31 */ CM_UNUSED_31, + /* 32 */ CM_ROTATE_TO_NAME_ENTRY, + /* 33 */ CM_NAME_ENTRY, + /* 34 */ CM_START_NAME_ENTRY, + /* 35 */ CM_NAME_ENTRY_TO_MAIN, + /* 36 */ CM_MAIN_TO_OPTIONS, + /* 37 */ CM_OPTIONS_MENU, + /* 38 */ CM_START_OPTIONS, + /* 39 */ CM_OPTIONS_TO_MAIN, + /* 40 */ CM_UNUSED_DELAY +} ConfigMode; + +typedef enum { + /* 0 */ SM_FADE_MAIN_TO_SELECT, + /* 1 */ SM_MOVE_FILE_TO_TOP, + /* 2 */ SM_FADE_IN_FILE_INFO, + /* 3 */ SM_CONFIRM_FILE, + /* 4 */ SM_FADE_OUT_FILE_INFO, + /* 5 */ SM_MOVE_FILE_TO_SLOT, + /* 6 */ SM_FADE_OUT, + /* 7 */ SM_LOAD_GAME +} SelectMode; + +typedef enum { + /* 0 */ FS_TITLE_SELECT_FILE, // "Please select a file." + /* 1 */ FS_TITLE_OPEN_FILE, // "Open this file?" + /* 2 */ FS_TITLE_COPY_FROM, // "Copy which file?" + /* 3 */ FS_TITLE_COPY_TO, // "Copy to which file?" + /* 4 */ FS_TITLE_COPY_CONFIRM, // "Are you sure?" + /* 5 */ FS_TITLE_COPY_COMPLETE, // "File copied." + /* 6 */ FS_TITLE_ERASE_FILE, // "Erase which file?" + /* 7 */ FS_TITLE_ERASE_CONFIRM, // "Are you sure?" + /* 8 */ FS_TITLE_ERASE_COMPLETE // "File erased." +} TitleLabel; + +typedef enum { + /* -1 */ FS_WARNING_NONE = -1, + /* 0 */ FS_WARNING_NO_FILE_COPY, // "No file to copy." + /* 1 */ FS_WARNING_NO_FILE_ERASE, // "No file to erase." + /* 2 */ FS_WARNING_NO_EMPTY_FILES, // "There is no empty file." + /* 3 */ FS_WARNING_FILE_EMPTY, // "This is an empty file." + /* 4 */ FS_WARNING_FILE_IN_USE // "This file is in use." +} WarningLabel; + +typedef enum { + /* 0 */ FS_BTN_MAIN_FILE_1, + /* 1 */ FS_BTN_MAIN_FILE_2, + /* 2 */ FS_BTN_MAIN_FILE_3, + /* 3 */ FS_BTN_MAIN_COPY, + /* 4 */ FS_BTN_MAIN_ERASE, + /* 5 */ FS_BTN_MAIN_OPTIONS +} MainMenuButtonIndex; + +typedef enum { + /* 0 */ FS_BTN_COPY_FILE_1, + /* 1 */ FS_BTN_COPY_FILE_2, + /* 2 */ FS_BTN_COPY_FILE_3, + /* 3 */ FS_BTN_COPY_QUIT +} CopyMenuButtonIndex; + +typedef enum { + /* 0 */ FS_BTN_ERASE_FILE_1, + /* 1 */ FS_BTN_ERASE_FILE_2, + /* 2 */ FS_BTN_ERASE_FILE_3, + /* 3 */ FS_BTN_ERASE_QUIT +} EraseMenuButtonIndex; + +typedef enum { + /* 0 */ FS_BTN_SELECT_FILE_1, + /* 1 */ FS_BTN_SELECT_FILE_2, + /* 2 */ FS_BTN_SELECT_FILE_3, + /* 3 */ FS_BTN_SELECT_YES, + /* 4 */ FS_BTN_SELECT_QUIT +} SelectMenuButtonIndex; + +typedef enum { + /* 0 */ FS_BTN_CONFIRM_YES, + /* 1 */ FS_BTN_CONFIRM_QUIT +} ConfirmButtonIndex; + +typedef enum { + /* 0 */ FS_BTN_ACTION_COPY, + /* 1 */ FS_BTN_ACTION_ERASE +} ActionButtonIndex; + +typedef enum { + /* 0 */ FS_SETTING_AUDIO, + /* 1 */ FS_SETTING_TARGET +} SettingIndex; + +typedef enum { + /* 0 */ FS_AUDIO_STEREO, + /* 1 */ FS_AUDIO_MONO, + /* 2 */ FS_AUDIO_HEADSET, + /* 3 */ FS_AUDIO_SURROUND +} AudioOption; + +typedef enum { + /* 0 */ FS_CHAR_PAGE_HIRA, + /* 1 */ FS_CHAR_PAGE_KATA, + /* 2 */ FS_CHAR_PAGE_ENG +} CharPage; + +typedef enum { + /* 00 */ FS_KBD_BTN_HIRA, + /* 01 */ FS_KBD_BTN_KATA, + /* 02 */ FS_KBD_BTN_ENG, + /* 03 */ FS_KBD_BTN_BACKSPACE, + /* 04 */ FS_KBD_BTN_END, + /* 99 */ FS_KBD_BTN_NONE = 99 +} KeyboardButton; + +void FileChoose_SetupCopySource(GameState* thisx); +void FileChoose_SelectCopySource(GameState* thisx); +void FileChoose_SetupCopyDest1(GameState* thisx); +void FileChoose_SetupCopyDest2(GameState* thisx); +void FileChoose_SelectCopyDest(GameState* thisx); +void FileChoose_ExitToCopySource1(GameState* thisx); +void FileChoose_ExitToCopySource2(GameState* thisx); +void FileChoose_SetupCopyConfirm1(GameState* thisx); +void FileChoose_SetupCopyConfirm2(GameState* thisx); +void FileChoose_CopyConfirm(GameState* thisx); +void FileChoose_ReturnToCopyDest(GameState* thisx); +void FileChoose_CopyAnim1(GameState* thisx); +void FileChoose_CopyAnim2(GameState* thisx); +void FileChoose_CopyAnim3(GameState* thisx); +void FileChoose_CopyAnim4(GameState* thisx); +void FileChoose_CopyAnim5(GameState* thisx); + +void FileChoose_ExitCopyToMain(GameState* thisx); +void FileChoose_SetupEraseSelect(GameState* thisx); +void FileChoose_EraseSelect(GameState* thisx); +void FileChoose_SetupEraseConfirm1(GameState* thisx); +void FileChoose_SetupEraseConfirm2(GameState* thisx); +void FileChoose_EraseConfirm(GameState* thisx); +void FileChoose_ExitToEraseSelect1(GameState* thisx); +void FileChoose_ExitToEraseSelect2(GameState* thisx); +void FileChoose_EraseAnim1(GameState* thisx); +void FileChoose_EraseAnim2(GameState* thisx); +void FileChoose_EraseAnim3(GameState* thisx); +void FileChoose_ExitEraseToMain(GameState* thisx); + +void FileChoose_UpdateKeyboardCursor(GameState* thisx); +void FileChoose_StartNameEntry(GameState* thisx); +void FileChoose_UpdateOptionsMenu(GameState* thisx); +void FileChoose_StartOptions(GameState* thisx); + +void FileChoose_InitModeDraw(GameState* thisx); +void FileChoose_ConfigModeDraw(GameState* thisx); +void FileChoose_SelectModeDraw(GameState* thisx); + +void FileChoose_PulsateCursor(GameState* thisx); +void FileChoose_DrawOptions(GameState* thisx); + +void FileChoose_DrawNameEntry(GameState* thisx); +void FileChoose_DrawCharacter(GraphicsContext* gfxCtx, void* texture, s16 vtx); + +extern s16 D_808123F0[]; + +#endif diff --git a/src/overlays/gamestates/ovl_file_choose/overlay.cfg b/src/overlays/gamestates/ovl_file_choose/overlay.cfg index a331aa406..6ab3dcceb 100644 --- a/src/overlays/gamestates/ovl_file_choose/overlay.cfg +++ b/src/overlays/gamestates/ovl_file_choose/overlay.cfg @@ -1,3 +1,5 @@ ovl_file_choose +z_file_nameset_data.c +z_file_copy_erase.c z_file_nameset_PAL.c z_file_choose.c
\ No newline at end of file diff --git a/src/overlays/gamestates/ovl_file_choose/z_file_choose.c b/src/overlays/gamestates/ovl_file_choose/z_file_choose.c index bbd34a759..bb2b97903 100644 --- a/src/overlays/gamestates/ovl_file_choose/z_file_choose.c +++ b/src/overlays/gamestates/ovl_file_choose/z_file_choose.c @@ -1,37 +1,1886 @@ -#pragma GLOBAL_ASM("asm/non_matchings/overlays/gamestates/ovl_file_choose/func_8080C330.s") +#include "file_choose.h" +#include "textures/title_static/title_static.h" +#include "textures/parameter_static/parameter_static.h" -#pragma GLOBAL_ASM("asm/non_matchings/overlays/gamestates/ovl_file_choose/func_8080C60C.s") +static s16 sUnused = 106; -#pragma GLOBAL_ASM("asm/non_matchings/overlays/gamestates/ovl_file_choose/func_8080D8CC.s") +static s16 sScreenFillAlpha = 255; -#pragma GLOBAL_ASM("asm/non_matchings/overlays/gamestates/ovl_file_choose/func_8080E074.s") +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), + gsDPSetOtherMode(G_AD_DISABLE | G_CD_MAGICSQ | G_CK_NONE | G_TC_FILT | G_TF_BILERP | G_TT_NONE | G_TL_TILE | + G_TD_CLAMP | G_TP_NONE | G_CYC_1CYCLE | G_PM_1PRIMITIVE, + G_AC_NONE | G_ZS_PIXEL | G_RM_CLD_SURF | G_RM_CLD_SURF2), + gsDPSetCombineMode(G_CC_PRIMITIVE, G_CC_PRIMITIVE), + gsSPEndDisplayList(), +}; -#pragma GLOBAL_ASM("asm/non_matchings/overlays/gamestates/ovl_file_choose/func_8080F560.s") +static s16 sFileInfoBoxPartWidths[] = { 36, 36, 36, 36, 24 }; -#pragma GLOBAL_ASM("asm/non_matchings/overlays/gamestates/ovl_file_choose/func_8080FE2C.s") +static s16 sWindowContentColors[2][3] = { + { 100, 150, 255 }, // blue + { 100, 100, 100 }, // gray +}; -#pragma GLOBAL_ASM("asm/non_matchings/overlays/gamestates/ovl_file_choose/func_8080FF98.s") +void FileChoose_SetView(FileChooseContext* this, f32 eyeX, f32 eyeY, f32 eyeZ) { + Vec3f eye; + Vec3f lookAt; + Vec3f up; -#pragma GLOBAL_ASM("asm/non_matchings/overlays/gamestates/ovl_file_choose/func_8081009C.s") + lookAt.x = lookAt.y = lookAt.z = 0.0f; + up.x = up.z = 0.0f; -#pragma GLOBAL_ASM("asm/non_matchings/overlays/gamestates/ovl_file_choose/func_8081017C.s") + eye.x = eyeX; + eye.y = eyeY; + eye.z = eyeZ; -#pragma GLOBAL_ASM("asm/non_matchings/overlays/gamestates/ovl_file_choose/func_80810354.s") + up.y = 1.0f; -#pragma GLOBAL_ASM("asm/non_matchings/overlays/gamestates/ovl_file_choose/func_80810440.s") + func_800AA358(&this->view, &eye, &lookAt, &up); + func_800AAA50(&this->view, 0x7F); +} -#pragma GLOBAL_ASM("asm/non_matchings/overlays/gamestates/ovl_file_choose/func_80810698.s") +Gfx* FileChoose_QuadTextureIA8(Gfx* gfx, void* texture, s16 width, s16 height, s16 point) { + gDPLoadTextureBlock(gfx++, texture, G_IM_FMT_IA, G_IM_SIZ_8b, width, height, 0, G_TX_NOMIRROR | G_TX_WRAP, + G_TX_NOMIRROR | G_TX_WRAP, G_TX_NOMASK, G_TX_NOMASK, G_TX_NOLOD, G_TX_NOLOD); -#pragma GLOBAL_ASM("asm/non_matchings/overlays/gamestates/ovl_file_choose/func_808106F4.s") + gSP1Quadrangle(gfx++, point, point + 2, point + 3, point + 1, 0); -#pragma GLOBAL_ASM("asm/non_matchings/overlays/gamestates/ovl_file_choose/func_8081097C.s") + return gfx; +} -#pragma GLOBAL_ASM("asm/non_matchings/overlays/gamestates/ovl_file_choose/func_808109B8.s") +void FileChoose_InitModeUpdate(GameState* thisx) { + FileChooseContext* this = (FileChooseContext*)thisx; -#pragma GLOBAL_ASM("asm/non_matchings/overlays/gamestates/ovl_file_choose/func_80810DAC.s") + if (this->menuMode == FS_MENU_MODE_INIT) { + this->menuMode = FS_MENU_MODE_CONFIG; + this->configMode = CM_FADE_IN_START; + this->nextTitleLabel = FS_TITLE_OPEN_FILE; + osSyncPrintf("Sram Start─Load 》》》》》 "); + Sram_VerifyAndLoadAllSaves(this, &this->sramCtx); + osSyncPrintf("終了!!!\n"); + } +} -#pragma GLOBAL_ASM("asm/non_matchings/overlays/gamestates/ovl_file_choose/func_808113A8.s") +void FileChoose_InitModeDraw(GameState* thisx) { +} -#pragma GLOBAL_ASM("asm/non_matchings/overlays/gamestates/ovl_file_choose/func_80811A18.s") +/** + * Fade in the menu window and title label. + * If a file is occupied fade in the name, name box, and connector. + * Fade in the copy erase and options button according to the window alpha. + */ +void FileChoose_FadeInMenuElements(GameState* thisx) { + FileChooseContext* this = (FileChooseContext*)thisx; + SramContext* sramCtx = &this->sramCtx; + s16 i; -#pragma GLOBAL_ASM("asm/non_matchings/overlays/gamestates/ovl_file_choose/func_80811A20.s") + this->titleAlpha[0] += VREG(1); + this->windowAlpha += VREG(2); + + for (i = 0; i < 3; i++) { + this->fileButtonAlpha[i] = this->windowAlpha; + + if (SLOT_OCCUPIED(sramCtx, i)) { + this->nameBoxAlpha[i] = this->nameAlpha[i] = this->windowAlpha; + this->connectorAlpha[i] += VREG(1); + if (this->connectorAlpha[i] >= 255) { + this->connectorAlpha[i] = 255; + } + } + } + + this->actionButtonAlpha[FS_BTN_ACTION_COPY] = this->actionButtonAlpha[FS_BTN_ACTION_ERASE] = + this->optionButtonAlpha = this->windowAlpha; +} + +/** + * Converts a numerical value to ones-tens-hundreds digits + */ +void FileChoose_SplitNumber(u16 value, s16* hundreds, s16* tens, s16* ones) { + *hundreds = 0; + *tens = 0; + *ones = value; + + while (true) { + if ((*ones - 100) < 0) { + break; + } + (*hundreds)++; + *ones -= 100; + } + + while (true) { + if ((*ones - 10) < 0) { + break; + } + (*tens)++; + *ones -= 10; + } +} + +/** + * Reduce the alpha of the black screen fill to create a fade in effect. + * Additionally, slide the window from the right to the center of the screen. + * Update function for `CM_FADE_IN_START` + */ +void FileChoose_StartFadeIn(GameState* thisx) { + FileChooseContext* this = (FileChooseContext*)thisx; + + FileChoose_FadeInMenuElements(&this->state); + sScreenFillAlpha -= 40; + this->windowPosX -= 20; + + if (this->windowPosX <= -94) { + this->windowPosX = -94; + this->configMode = CM_FADE_IN_END; + sScreenFillAlpha = 0; + } +} + +/** + * Finish fading in the remaining menu elements. + * Fade in the controls text at the bottom of the screen. + * Update function for `CM_FADE_IN_END` + */ +void FileChoose_FinishFadeIn(GameState* thisx) { + FileChooseContext* this = (FileChooseContext*)thisx; + + this->controlsAlpha += VREG(1); + FileChoose_FadeInMenuElements(&this->state); + + if (this->titleAlpha[0] >= 255) { + this->titleAlpha[0] = 255; + this->controlsAlpha = 255; + this->windowAlpha = 200; + this->configMode = CM_MAIN_MENU; + } +} + +/** + * Update the cursor and wait for the player to select a button to change menus accordingly. + * If an empty file is selected, enter the name entry config mode. + * If an occupied file is selected, enter the `Select` menu mode. + * If copy, erase, or options is selected, set config mode accordingly. + * Lastly, set any warning labels if appropriate. + * Update function for `CM_MAIN_MENU` + */ +void FileChoose_UpdateMainMenu(GameState* thisx) { + static u8 emptyName[] = { 0x3E, 0x3E, 0x3E, 0x3E, 0x3E, 0x3E, 0x3E, 0x3E }; + FileChooseContext* this = (FileChooseContext*)thisx; + SramContext* sramCtx = &this->sramCtx; + Input* input = &this->state.input[0]; + + if (CHECK_BTN_ALL(input->press.button, BTN_START) || CHECK_BTN_ALL(input->press.button, BTN_A)) { + if (this->buttonIndex <= FS_BTN_MAIN_FILE_3) { + osSyncPrintf("REGCK_ALL[%x]=%x,%x,%x,%x,%x,%x\n", this->buttonIndex, + GET_NEWF(sramCtx, this->buttonIndex, 0), GET_NEWF(sramCtx, this->buttonIndex, 1), + GET_NEWF(sramCtx, this->buttonIndex, 2), GET_NEWF(sramCtx, this->buttonIndex, 3), + GET_NEWF(sramCtx, this->buttonIndex, 4), GET_NEWF(sramCtx, this->buttonIndex, 5)); + + if (!SLOT_OCCUPIED(sramCtx, this->buttonIndex)) { + Audio_PlaySoundGeneral(NA_SE_SY_FSEL_DECIDE_L, &D_801333D4, 4, &D_801333E0, &D_801333E0, &D_801333E8); + this->configMode = CM_ROTATE_TO_NAME_ENTRY; + this->kbdButton = FS_KBD_BTN_NONE; + this->charPage = FS_CHAR_PAGE_ENG; + this->kbdX = 0; + this->kbdY = 0; + this->charIndex = 0; + this->charBgAlpha = 0; + this->newFileNameCharCount = 0; + this->nameEntryBoxPosX = 120; + this->nameEntryBoxAlpha = 0; + MemCopy(&this->fileNames[this->buttonIndex][0], &emptyName, 8); + } else if (this->n64ddFlags[this->buttonIndex] == this->n64ddFlag) { + Audio_PlaySoundGeneral(NA_SE_SY_FSEL_DECIDE_L, &D_801333D4, 4, &D_801333E0, &D_801333E0, &D_801333E8); + this->actionTimer = 8; + this->selectMode = SM_FADE_MAIN_TO_SELECT; + this->selectedFileIndex = this->buttonIndex; + this->menuMode = FS_MENU_MODE_SELECT; + this->nextTitleLabel = FS_TITLE_OPEN_FILE; + } else if (!this->n64ddFlags[this->buttonIndex]) { + Audio_PlaySoundGeneral(NA_SE_SY_FSEL_ERROR, &D_801333D4, 4, &D_801333E0, &D_801333E0, &D_801333E8); + } + } else { + if (this->warningLabel == FS_WARNING_NONE) { + Audio_PlaySoundGeneral(NA_SE_SY_FSEL_DECIDE_L, &D_801333D4, 4, &D_801333E0, &D_801333E0, &D_801333E8); + this->prevConfigMode = this->configMode; + + if (this->buttonIndex == FS_BTN_MAIN_COPY) { + this->configMode = CM_SETUP_COPY_SOURCE; + this->nextTitleLabel = FS_TITLE_COPY_FROM; + } else if (this->buttonIndex == FS_BTN_MAIN_ERASE) { + this->configMode = CM_SETUP_ERASE_SELECT; + this->nextTitleLabel = FS_TITLE_ERASE_FILE; + } else { + this->configMode = CM_MAIN_TO_OPTIONS; + this->kbdButton = 0; + this->kbdX = 0; + this->kbdY = 0; + this->charBgAlpha = 0; + this->newFileNameCharCount = 0; + this->nameEntryBoxPosX = 120; + } + + this->actionTimer = 8; + } else { + Audio_PlaySoundGeneral(NA_SE_SY_FSEL_ERROR, &D_801333D4, 4, &D_801333E0, &D_801333E0, &D_801333E8); + } + } + } else { + if (ABS(this->stickRelY) > 30) { + Audio_PlaySoundGeneral(NA_SE_SY_FSEL_CURSOR, &D_801333D4, 4, &D_801333E0, &D_801333E0, &D_801333E8); + + if (this->stickRelY > 30) { + this->buttonIndex--; + if (this->buttonIndex < FS_BTN_MAIN_FILE_1) { + this->buttonIndex = FS_BTN_MAIN_OPTIONS; + } + } else { + this->buttonIndex++; + if (this->buttonIndex > FS_BTN_MAIN_OPTIONS) { + this->buttonIndex = FS_BTN_MAIN_FILE_1; + } + } + } + + if (this->buttonIndex == FS_BTN_MAIN_COPY) { + if (!SLOT_OCCUPIED(sramCtx, 0) && !SLOT_OCCUPIED(sramCtx, 1) && !SLOT_OCCUPIED(sramCtx, 2)) { + this->warningButtonIndex = this->buttonIndex; + this->warningLabel = FS_WARNING_NO_FILE_COPY; + this->emptyFileTextAlpha = 255; + } else if (SLOT_OCCUPIED(sramCtx, 0) && SLOT_OCCUPIED(sramCtx, 1) && SLOT_OCCUPIED(sramCtx, 2)) { + this->warningButtonIndex = this->buttonIndex; + this->warningLabel = FS_WARNING_NO_EMPTY_FILES; + this->emptyFileTextAlpha = 255; + } else { + this->warningLabel = FS_WARNING_NONE; + } + } else if (this->buttonIndex == FS_BTN_MAIN_ERASE) { + if (!SLOT_OCCUPIED(sramCtx, 0) && !SLOT_OCCUPIED(sramCtx, 1) && !SLOT_OCCUPIED(sramCtx, 2)) { + this->warningButtonIndex = this->buttonIndex; + this->warningLabel = FS_WARNING_NO_FILE_ERASE; + this->emptyFileTextAlpha = 255; + } else { + this->warningLabel = FS_WARNING_NONE; + } + } else { + this->warningLabel = FS_WARNING_NONE; + } + } +} + +/** + * Update function for `CM_UNUSED_31` + */ +void FileChoose_UnusedCM31(GameState* thisx) { +} + +/** + * Delay the next config mode from running until `XREG(73)` reaches 254. + * Because the timer increments by 2, the delay is 127 frames (assuming the value was not changed by reg editor). + * Unused in the final game, was possibly used for debugging. + * Update function for `CM_UNUSED_DELAY` + */ +void FileChoose_UnusedCMDelay(GameState* thisx) { + FileChooseContext* this = (FileChooseContext*)thisx; + + XREG(73) += 2; + + if (XREG(73) == 254) { + this->configMode = this->nextConfigMode; + XREG(73) = 0; + } +} + +/** + * Rotate the window from the main menu to the name entry menu. + * Update function for `CM_ROTATE_TO_NAME_ENTRY` + */ +void FileChoose_RotateToNameEntry(GameState* thisx) { + FileChooseContext* this = (FileChooseContext*)thisx; + + this->windowRot += VREG(16); + + if (this->windowRot >= 314.0f) { + this->windowRot = 314.0f; + this->configMode = CM_START_NAME_ENTRY; + } +} + +/** + * Rotate the window from the main menu to the options menu. + * Update function for `CM_MAIN_TO_OPTIONS` + */ +void FileChoose_RotateToOptions(GameState* thisx) { + FileChooseContext* this = (FileChooseContext*)thisx; + + this->windowRot += VREG(16); + + if (this->windowRot >= 314.0f) { + this->windowRot = 314.0f; + this->configMode = CM_START_OPTIONS; + } +} + +/** + * Rotate the window from the options menu to the main menu. + * Update function for `CM_NAME_ENTRY_TO_MAIN` and `CM_OPTIONS_TO_MAIN` + */ +void FileChoose_RotateToMain(GameState* thisx) { + FileChooseContext* this = (FileChooseContext*)thisx; + + this->windowRot += VREG(16); + + if (this->windowRot >= 628.0f) { + this->windowRot = 0.0f; + this->configMode = CM_MAIN_MENU; + } +} + +static void (*gConfigModeUpdateFuncs[])(GameState*) = { + FileChoose_StartFadeIn, FileChoose_FinishFadeIn, + FileChoose_UpdateMainMenu, FileChoose_SetupCopySource, + FileChoose_SelectCopySource, FileChoose_SetupCopyDest1, + FileChoose_SetupCopyDest2, FileChoose_SelectCopyDest, + FileChoose_ExitToCopySource1, FileChoose_ExitToCopySource2, + FileChoose_SetupCopyConfirm1, FileChoose_SetupCopyConfirm2, + FileChoose_CopyConfirm, FileChoose_ReturnToCopyDest, + FileChoose_CopyAnim1, FileChoose_CopyAnim2, + FileChoose_CopyAnim3, FileChoose_CopyAnim4, + FileChoose_CopyAnim5, FileChoose_ExitCopyToMain, + FileChoose_SetupEraseSelect, FileChoose_EraseSelect, + FileChoose_SetupEraseConfirm1, FileChoose_SetupEraseConfirm2, + FileChoose_EraseConfirm, FileChoose_ExitToEraseSelect1, + FileChoose_ExitToEraseSelect2, FileChoose_EraseAnim1, + FileChoose_EraseAnim2, FileChoose_EraseAnim3, + FileChoose_ExitEraseToMain, FileChoose_UnusedCM31, + FileChoose_RotateToNameEntry, FileChoose_UpdateKeyboardCursor, + FileChoose_StartNameEntry, FileChoose_RotateToMain, + FileChoose_RotateToOptions, FileChoose_UpdateOptionsMenu, + FileChoose_StartOptions, FileChoose_RotateToMain, + FileChoose_UnusedCMDelay, +}; + +/** + * Updates the alpha of the cursor to make it pulsate. + * On the debug rom, this function also handles switching languages with controller 3. + */ +void FileChoose_PulsateCursor(GameState* thisx) { + static s16 cursorAlphaTargets[] = { 70, 200 }; + FileChooseContext* this = (FileChooseContext*)thisx; + s16 alphaStep; + SramContext* sramCtx = &this->sramCtx; + Input* debugInput = &this->state.input[2]; + + if (CHECK_BTN_ALL(debugInput->press.button, BTN_DLEFT)) { + sramCtx->readBuff[SRAM_HEADER_LANGUAGE] = gSaveContext.language = 0; + *((u8*)0x80000002) = 0; + + SsSram_ReadWrite(OS_K1_TO_PHYSICAL(0xA8000000), sramCtx->readBuff, 3, OS_WRITE); + osSyncPrintf("1:read_buff[]=%x, %x, %x, %x\n", sramCtx->readBuff[SRAM_HEADER_SOUND], + sramCtx->readBuff[SRAM_HEADER_ZTARGET], sramCtx->readBuff[SRAM_HEADER_LANGUAGE], + sramCtx->readBuff[SRAM_HEADER_MAGIC]); + + SsSram_ReadWrite(OS_K1_TO_PHYSICAL(0xA8000000), sramCtx->readBuff, SRAM_SIZE, OS_READ); + osSyncPrintf("read_buff[]=%x, %x, %x, %x\n", sramCtx->readBuff[SRAM_HEADER_SOUND], + sramCtx->readBuff[SRAM_HEADER_ZTARGET], sramCtx->readBuff[SRAM_HEADER_LANGUAGE], + sramCtx->readBuff[SRAM_HEADER_MAGIC]); + } else if (CHECK_BTN_ALL(debugInput->press.button, BTN_DUP)) { + sramCtx->readBuff[SRAM_HEADER_LANGUAGE] = gSaveContext.language = 1; + *((u8*)0x80000002) = 1; + + SsSram_ReadWrite(OS_K1_TO_PHYSICAL(0xA8000000), sramCtx->readBuff, 3, OS_WRITE); + osSyncPrintf("1:read_buff[]=%x, %x, %x, %x\n", sramCtx->readBuff[SRAM_HEADER_SOUND], + sramCtx->readBuff[SRAM_HEADER_ZTARGET], sramCtx->readBuff[SRAM_HEADER_LANGUAGE], + sramCtx->readBuff[SRAM_HEADER_MAGIC]); + SsSram_ReadWrite(OS_K1_TO_PHYSICAL(0xA8000000), sramCtx->readBuff, SRAM_SIZE, OS_READ); + osSyncPrintf("read_buff[]=%x, %x, %x, %x\n", sramCtx->readBuff[SRAM_HEADER_SOUND], + sramCtx->readBuff[SRAM_HEADER_ZTARGET], sramCtx->readBuff[SRAM_HEADER_LANGUAGE], + sramCtx->readBuff[SRAM_HEADER_MAGIC]); + } else if (CHECK_BTN_ALL(debugInput->press.button, BTN_DRIGHT)) { + sramCtx->readBuff[SRAM_HEADER_LANGUAGE] = gSaveContext.language = 2; + *((u8*)0x80000002) = 2; + + SsSram_ReadWrite(OS_K1_TO_PHYSICAL(0xA8000000), sramCtx->readBuff, 3, OS_WRITE); + osSyncPrintf("1:read_buff[]=%x, %x, %x, %x\n", sramCtx->readBuff[SRAM_HEADER_SOUND], + sramCtx->readBuff[SRAM_HEADER_ZTARGET], sramCtx->readBuff[SRAM_HEADER_LANGUAGE], + sramCtx->readBuff[SRAM_HEADER_MAGIC]); + + SsSram_ReadWrite(OS_K1_TO_PHYSICAL(0xA8000000), sramCtx->readBuff, SRAM_SIZE, OS_READ); + osSyncPrintf("read_buff[]=%x, %x, %x, %x\n", sramCtx->readBuff[SRAM_HEADER_SOUND], + sramCtx->readBuff[SRAM_HEADER_ZTARGET], sramCtx->readBuff[SRAM_HEADER_LANGUAGE], + sramCtx->readBuff[SRAM_HEADER_MAGIC]); + } + + alphaStep = ABS(this->highlightColor[3] - cursorAlphaTargets[this->highlightPulseDir]) / XREG(35); + + if (this->highlightColor[3] >= cursorAlphaTargets[this->highlightPulseDir]) { + this->highlightColor[3] -= alphaStep; + } else { + this->highlightColor[3] += alphaStep; + } + + XREG(35)--; + + if (XREG(35) == 0) { + this->highlightColor[3] = cursorAlphaTargets[this->highlightPulseDir]; + XREG(35) = XREG(36 + this->highlightPulseDir); + this->highlightPulseDir ^= 1; + } +} + +void FileChoose_ConfigModeUpdate(GameState* thisx) { + FileChooseContext* this = (FileChooseContext*)thisx; + + gConfigModeUpdateFuncs[this->configMode](&this->state); +} + +void FileChoose_SetWindowVtx(GameState* thisx) { + FileChooseContext* this = (FileChooseContext*)thisx; + s16 i; + s16 j; + s16 x; + s16 tmp; + s16 tmp2; + s16 tmp3; + + this->windowVtx = Graph_Alloc(this->state.gfxCtx, sizeof(Vtx) * 80); + tmp = this->windowPosX - 90; + + for (x = 0, i = 0; i < 4; i++) { + tmp += 0x40; + tmp2 = (i == 3) ? 0x30 : 0x40; + + for (j = 0, tmp3 = 0x50; j < 5; j++, x += 4, tmp3 -= 0x20) { + this->windowVtx[x].v.ob[0] = this->windowVtx[x + 2].v.ob[0] = tmp; + + this->windowVtx[x + 1].v.ob[0] = this->windowVtx[x + 3].v.ob[0] = tmp + tmp2; + + this->windowVtx[x].v.ob[1] = this->windowVtx[x + 1].v.ob[1] = tmp3; + + this->windowVtx[x + 2].v.ob[1] = this->windowVtx[x + 3].v.ob[1] = tmp3 - 0x20; + + this->windowVtx[x].v.ob[2] = this->windowVtx[x + 1].v.ob[2] = this->windowVtx[x + 2].v.ob[2] = + this->windowVtx[x + 3].v.ob[2] = 0; + + this->windowVtx[x].v.flag = this->windowVtx[x + 1].v.flag = this->windowVtx[x + 2].v.flag = + this->windowVtx[x + 3].v.flag = 0; + + this->windowVtx[x].v.tc[0] = this->windowVtx[x].v.tc[1] = this->windowVtx[x + 1].v.tc[1] = + this->windowVtx[x + 2].v.tc[0] = 0; + + this->windowVtx[x + 1].v.tc[0] = this->windowVtx[x + 3].v.tc[0] = tmp2 * 0x20; + + this->windowVtx[x + 2].v.tc[1] = this->windowVtx[x + 3].v.tc[1] = 0x400; + + this->windowVtx[x].v.cn[0] = this->windowVtx[x + 2].v.cn[0] = this->windowVtx[x].v.cn[1] = + this->windowVtx[x + 2].v.cn[1] = this->windowVtx[x].v.cn[2] = this->windowVtx[x + 2].v.cn[2] = + this->windowVtx[x + 1].v.cn[0] = this->windowVtx[x + 3].v.cn[0] = this->windowVtx[x + 1].v.cn[1] = + this->windowVtx[x + 3].v.cn[1] = this->windowVtx[x + 1].v.cn[2] = + this->windowVtx[x + 3].v.cn[2] = this->windowVtx[x].v.cn[3] = + this->windowVtx[x + 2].v.cn[3] = this->windowVtx[x + 1].v.cn[3] = + this->windowVtx[x + 3].v.cn[3] = 255; + } + } +} + +static s16 D_80812818[] = { 0x001A, 0x000A, 0x000A, 0x000A }; +static s16 D_80812820[] = { 0x0020, 0x000C, 0x000C, 0x000C }; +static s16 D_80812828[] = { 0x0010, 0x000C, 0x000C, 0x000C }; +static s16 D_80812830[] = { 0x0040, 0x0054, 0x0068, 0x0274, 0x0278, 0x027C }; +static s16 D_8081283C[] = { 0x0040, 0x0054, 0x0068, 0x0278 }; +static s16 D_80812844[] = { 0x0274, 0x0278 }; +static s16 D_80812848[] = { 0x0274, 0x0278 }; + +void FileChoose_SetWindowContentVtx(GameState* thisx) { + FileChooseContext* this = (FileChooseContext*)thisx; + s16 phi_t2; + s16 phi_t0; + s16 phi_t5; + s16 phi_a1; + s16 phi_ra; + s16 temp_t1; + SramContext* sramCtx = &this->sramCtx; + + this->windowContentVtx = Graph_Alloc(this->state.gfxCtx, 0x288 * sizeof(Vtx)); + + for (phi_t2 = 0; phi_t2 < 0x288; phi_t2 += 4) { + this->windowContentVtx[phi_t2].v.ob[0] = this->windowContentVtx[phi_t2 + 2].v.ob[0] = 0x12C; + this->windowContentVtx[phi_t2 + 1].v.ob[0] = this->windowContentVtx[phi_t2 + 3].v.ob[0] = + this->windowContentVtx[phi_t2].v.ob[0] + 0x10; + + this->windowContentVtx[phi_t2].v.ob[1] = this->windowContentVtx[phi_t2 + 1].v.ob[1] = 0; + this->windowContentVtx[phi_t2 + 2].v.ob[1] = this->windowContentVtx[phi_t2 + 3].v.ob[1] = + this->windowContentVtx[phi_t2].v.ob[1] - 0x10; + + this->windowContentVtx[phi_t2].v.ob[2] = this->windowContentVtx[phi_t2 + 1].v.ob[2] = + this->windowContentVtx[phi_t2 + 2].v.ob[2] = this->windowContentVtx[phi_t2 + 3].v.ob[2] = 0; + + this->windowContentVtx[phi_t2].v.flag = this->windowContentVtx[phi_t2 + 1].v.flag = + this->windowContentVtx[phi_t2 + 2].v.flag = this->windowContentVtx[phi_t2 + 3].v.flag = 0; + + this->windowContentVtx[phi_t2].v.tc[0] = this->windowContentVtx[phi_t2].v.tc[1] = + this->windowContentVtx[phi_t2 + 1].v.tc[1] = this->windowContentVtx[phi_t2 + 2].v.tc[0] = 0; + + this->windowContentVtx[phi_t2 + 1].v.tc[0] = this->windowContentVtx[phi_t2 + 2].v.tc[1] = + this->windowContentVtx[phi_t2 + 3].v.tc[0] = this->windowContentVtx[phi_t2 + 3].v.tc[1] = 0x200; + + this->windowContentVtx[phi_t2].v.cn[0] = this->windowContentVtx[phi_t2 + 1].v.cn[0] = + this->windowContentVtx[phi_t2 + 2].v.cn[0] = this->windowContentVtx[phi_t2 + 3].v.cn[0] = + this->windowContentVtx[phi_t2].v.cn[1] = this->windowContentVtx[phi_t2 + 1].v.cn[1] = + this->windowContentVtx[phi_t2 + 2].v.cn[1] = this->windowContentVtx[phi_t2 + 3].v.cn[1] = + this->windowContentVtx[phi_t2].v.cn[2] = this->windowContentVtx[phi_t2 + 1].v.cn[2] = + this->windowContentVtx[phi_t2 + 2].v.cn[2] = this->windowContentVtx[phi_t2 + 3].v.cn[2] = + this->windowContentVtx[phi_t2].v.cn[3] = this->windowContentVtx[phi_t2 + 1].v.cn[3] = + this->windowContentVtx[phi_t2 + 2].v.cn[3] = + this->windowContentVtx[phi_t2 + 3].v.cn[3] = 0xFF; + } + + this->windowContentVtx[0].v.ob[0] = this->windowContentVtx[2].v.ob[0] = this->windowPosX; + this->windowContentVtx[1].v.ob[0] = this->windowContentVtx[3].v.ob[0] = this->windowContentVtx[0].v.ob[0] + 0x80; + this->windowContentVtx[0].v.ob[1] = this->windowContentVtx[1].v.ob[1] = 0x48; + this->windowContentVtx[2].v.ob[1] = this->windowContentVtx[3].v.ob[1] = this->windowContentVtx[0].v.ob[1] - 0x10; + this->windowContentVtx[1].v.tc[0] = this->windowContentVtx[3].v.tc[0] = 0x1000; + + for (phi_a1 = 0, phi_t2 = 4; phi_a1 < 3; phi_a1++) { + phi_t0 = this->windowPosX - 6; + + for (phi_t5 = 0; phi_t5 < 5; phi_t5++, phi_t2 += 4) { + this->windowContentVtx[phi_t2].v.ob[0] = this->windowContentVtx[phi_t2 + 2].v.ob[0] = phi_t0; + this->windowContentVtx[phi_t2 + 1].v.ob[0] = this->windowContentVtx[phi_t2 + 3].v.ob[0] = + this->windowContentVtx[phi_t2].v.ob[0] + sFileInfoBoxPartWidths[phi_t5]; + + this->windowContentVtx[phi_t2].v.ob[1] = this->windowContentVtx[phi_t2 + 1].v.ob[1] = + this->fileNamesY[phi_a1] + 0x2C; + + this->windowContentVtx[phi_t2 + 2].v.ob[1] = this->windowContentVtx[phi_t2 + 3].v.ob[1] = + this->windowContentVtx[phi_t2].v.ob[1] - 0x38; + + this->windowContentVtx[phi_t2 + 1].v.tc[0] = this->windowContentVtx[phi_t2 + 3].v.tc[0] = + sFileInfoBoxPartWidths[phi_t5] << 5; + this->windowContentVtx[phi_t2 + 2].v.tc[1] = this->windowContentVtx[phi_t2 + 3].v.tc[1] = 0x700; + phi_t0 += sFileInfoBoxPartWidths[phi_t5]; + } + } + + phi_t0 = this->windowPosX - 6; + phi_ra = 0x2C; + + for (phi_t5 = 0; phi_t5 < 3; phi_t5++, phi_t2 += 20, phi_ra -= 0x10) { + this->windowContentVtx[phi_t2].v.ob[0] = this->windowContentVtx[phi_t2 + 2].v.ob[0] = phi_t0; + + this->windowContentVtx[phi_t2 + 1].v.ob[0] = this->windowContentVtx[phi_t2 + 3].v.ob[0] = + this->windowContentVtx[phi_t2].v.ob[0] + 0x40; + + this->windowContentVtx[phi_t2].v.ob[1] = this->windowContentVtx[phi_t2 + 1].v.ob[1] = + this->buttonYOffsets[phi_t5] + phi_ra; + this->windowContentVtx[phi_t2 + 2].v.ob[1] = this->windowContentVtx[phi_t2 + 3].v.ob[1] = + this->windowContentVtx[phi_t2].v.ob[1] - 0x10; + + this->windowContentVtx[phi_t2 + 1].v.tc[0] = this->windowContentVtx[phi_t2 + 3].v.tc[0] = 0x800; + + this->windowContentVtx[phi_t2 + 4].v.ob[0] = this->windowContentVtx[phi_t2 + 6].v.ob[0] = phi_t0 + 0x40; + + this->windowContentVtx[phi_t2 + 5].v.ob[0] = this->windowContentVtx[phi_t2 + 7].v.ob[0] = + this->windowContentVtx[phi_t2 + 4].v.ob[0] + 0x6C; + + this->windowContentVtx[phi_t2 + 4].v.ob[1] = this->windowContentVtx[phi_t2 + 5].v.ob[1] = + this->buttonYOffsets[phi_t5] + phi_ra; + + this->windowContentVtx[phi_t2 + 6].v.ob[1] = this->windowContentVtx[phi_t2 + 7].v.ob[1] = + this->windowContentVtx[phi_t2 + 4].v.ob[1] - 0x10; + + this->windowContentVtx[phi_t2 + 5].v.tc[0] = this->windowContentVtx[phi_t2 + 7].v.tc[0] = 0xD80; + + if ((this->configMode == CM_COPY_ANIM_2) && (phi_t5 == this->copyDestFileIndex)) { + temp_t1 = this->fileNamesY[phi_t5] + 0x2C; + } else if (((this->configMode == CM_COPY_ANIM_3) || (this->configMode == CM_COPY_ANIM_4)) && + (phi_t5 == this->copyDestFileIndex)) { + temp_t1 = this->buttonYOffsets[phi_t5] + phi_ra; + } else { + temp_t1 = phi_ra + this->buttonYOffsets[phi_t5] + this->fileNamesY[phi_t5]; + } + + this->windowContentVtx[phi_t2 + 8].v.ob[0] = this->windowContentVtx[phi_t2 + 10].v.ob[0] = phi_t0 + 0xA8; + + this->windowContentVtx[phi_t2 + 9].v.ob[0] = this->windowContentVtx[phi_t2 + 11].v.ob[0] = + this->windowContentVtx[phi_t2 + 8].v.ob[0] + 0x2C; + + this->windowContentVtx[phi_t2 + 8].v.ob[1] = this->windowContentVtx[phi_t2 + 9].v.ob[1] = temp_t1; + this->windowContentVtx[phi_t2 + 10].v.ob[1] = this->windowContentVtx[phi_t2 + 11].v.ob[1] = + this->windowContentVtx[phi_t2 + 8].v.ob[1] - 0x10; + + this->windowContentVtx[phi_t2 + 9].v.tc[0] = this->windowContentVtx[phi_t2 + 11].v.tc[0] = 0x580; + this->windowContentVtx[phi_t2 + 12].v.ob[0] = this->windowContentVtx[phi_t2 + 14].v.ob[0] = phi_t0 + 0x34; + this->windowContentVtx[phi_t2 + 13].v.ob[0] = this->windowContentVtx[phi_t2 + 15].v.ob[0] = + this->windowContentVtx[phi_t2 + 12].v.ob[0] + 0x18; + + this->windowContentVtx[phi_t2 + 12].v.ob[1] = this->windowContentVtx[phi_t2 + 13].v.ob[1] = + this->buttonYOffsets[phi_t5] + phi_ra; + + this->windowContentVtx[phi_t2 + 14].v.ob[1] = this->windowContentVtx[phi_t2 + 15].v.ob[1] = + this->windowContentVtx[phi_t2 + 12].v.ob[1] - 0x10; + + this->windowContentVtx[phi_t2 + 13].v.tc[0] = this->windowContentVtx[phi_t2 + 15].v.tc[0] = 0x300; + this->windowContentVtx[phi_t2 + 16].v.ob[0] = this->windowContentVtx[phi_t2 + 18].v.ob[0] = phi_t0 + 0x9C; + this->windowContentVtx[phi_t2 + 17].v.ob[0] = this->windowContentVtx[phi_t2 + 19].v.ob[0] = + this->windowContentVtx[phi_t2 + 16].v.ob[0] + 0x18; + + this->windowContentVtx[phi_t2 + 16].v.ob[1] = this->windowContentVtx[phi_t2 + 17].v.ob[1] = + this->buttonYOffsets[phi_t5] + phi_ra; + + this->windowContentVtx[phi_t2 + 18].v.ob[1] = this->windowContentVtx[phi_t2 + 19].v.ob[1] = + this->windowContentVtx[phi_t2 + 16].v.ob[1] - 0x10; + + this->windowContentVtx[phi_t2 + 17].v.tc[0] = this->windowContentVtx[phi_t2 + 19].v.tc[0] = 0x300; + } + + phi_ra = 0x2C; + + for (phi_t5 = 0; phi_t5 < 3; phi_t5++, phi_ra -= WREG(38)) { + if (SLOT_OCCUPIED(sramCtx, phi_t5)) { + phi_t0 = this->windowPosX - WREG(39); + + if ((this->configMode == 0xF) && (phi_t5 == this->copyDestFileIndex)) { + temp_t1 = this->fileNamesY[phi_t5] + 0x2C; + } else if (((this->configMode == CM_COPY_ANIM_3) || (this->configMode == CM_COPY_ANIM_4)) && + (phi_t5 == this->copyDestFileIndex)) { + temp_t1 = this->buttonYOffsets[phi_t5] + phi_ra; + } else { + temp_t1 = phi_ra + this->buttonYOffsets[phi_t5] + this->fileNamesY[phi_t5]; + } + + temp_t1 += 2; + + for (phi_a1 = 0; phi_a1 < 8; phi_a1++, phi_t2 += 4, phi_t0 += WREG(40)) { + this->windowContentVtx[phi_t2].v.ob[0] = this->windowContentVtx[phi_t2 + 2].v.ob[0] = + WREG(41) + phi_t0 + 0x40; + this->windowContentVtx[phi_t2 + 1].v.ob[0] = this->windowContentVtx[phi_t2 + 3].v.ob[0] = + this->windowContentVtx[phi_t2].v.ob[0] + WREG(42); + this->windowContentVtx[phi_t2].v.ob[1] = this->windowContentVtx[phi_t2 + 1].v.ob[1] = temp_t1 - 3; + this->windowContentVtx[phi_t2 + 2].v.ob[1] = this->windowContentVtx[phi_t2 + 3].v.ob[1] = + this->windowContentVtx[phi_t2].v.ob[1] - WREG(43); + } + + phi_t0 = this->windowPosX - 14; + temp_t1 -= 0x16; + + for (phi_a1 = 0; phi_a1 < 4; phi_a1++, phi_t2 += 4) { + this->windowContentVtx[phi_t2].v.ob[0] = this->windowContentVtx[phi_t2 + 2].v.ob[0] = phi_t0; + this->windowContentVtx[phi_t2 + 1].v.ob[0] = this->windowContentVtx[phi_t2 + 3].v.ob[0] = + this->windowContentVtx[phi_t2].v.ob[0] + D_80812820[phi_a1]; + this->windowContentVtx[phi_t2].v.ob[1] = this->windowContentVtx[phi_t2 + 1].v.ob[1] = temp_t1; + this->windowContentVtx[phi_t2 + 2].v.ob[1] = this->windowContentVtx[phi_t2 + 3].v.ob[1] = + this->windowContentVtx[phi_t2].v.ob[1] - D_80812828[phi_a1]; + phi_t0 += D_80812818[phi_a1]; + } + + this->windowContentVtx[phi_t2 - 15].v.tc[0] = this->windowContentVtx[phi_t2 - 13].v.tc[0] = 0x400; + + phi_t0 = this->windowPosX + 63; + temp_t1 += 4; + + for (phi_a1 = 0; phi_a1 < 20; phi_a1++, phi_t2 += 4, phi_t0 += 9) { + this->windowContentVtx[phi_t2].v.ob[0] = this->windowContentVtx[phi_t2 + 2].v.ob[0] = phi_t0; + this->windowContentVtx[phi_t2 + 1].v.ob[0] = this->windowContentVtx[phi_t2 + 3].v.ob[0] = + this->windowContentVtx[phi_t2].v.ob[0] + 0xA; + this->windowContentVtx[phi_t2].v.ob[1] = this->windowContentVtx[phi_t2 + 1].v.ob[1] = temp_t1; + this->windowContentVtx[phi_t2 + 2].v.ob[1] = this->windowContentVtx[phi_t2 + 3].v.ob[1] = + this->windowContentVtx[phi_t2].v.ob[1] - 0xA; + + if (phi_a1 == 9) { + phi_t0 = this->windowPosX + 54; + temp_t1 -= 8; + } + } + + phi_t0 = this->windowPosX + 4; + temp_t1 -= 0xA; + + for (phi_a1 = 0; phi_a1 < 10; phi_a1++, phi_t2 += 4, phi_t0 += 0x10) { + this->windowContentVtx[phi_t2].v.ob[0] = this->windowContentVtx[phi_t2 + 2].v.ob[0] = phi_t0; + this->windowContentVtx[phi_t2 + 1].v.ob[0] = this->windowContentVtx[phi_t2 + 3].v.ob[0] = + this->windowContentVtx[phi_t2].v.ob[0] + 0x10; + this->windowContentVtx[phi_t2].v.ob[1] = this->windowContentVtx[phi_t2 + 1].v.ob[1] = temp_t1; + this->windowContentVtx[phi_t2 + 2].v.ob[1] = this->windowContentVtx[phi_t2 + 3].v.ob[1] = + this->windowContentVtx[phi_t2].v.ob[1] - 0x10; + } + } else { + phi_t2 += 0xA8; + } + } + + phi_t0 = this->windowPosX - 6; + phi_ra = -0xC; + + for (phi_t5 = 0; phi_t5 < 2; phi_t5++, phi_t2 += 4, phi_ra -= 0x10) { + this->windowContentVtx[phi_t2].v.ob[0] = this->windowContentVtx[phi_t2 + 2].v.ob[0] = phi_t0; + this->windowContentVtx[phi_t2 + 1].v.ob[0] = this->windowContentVtx[phi_t2 + 3].v.ob[0] = + this->windowContentVtx[phi_t2].v.ob[0] + 0x40; + this->windowContentVtx[phi_t2].v.ob[1] = this->windowContentVtx[phi_t2 + 1].v.ob[1] = + this->buttonYOffsets[phi_t5 + 3] + phi_ra; + this->windowContentVtx[phi_t2 + 2].v.ob[1] = this->windowContentVtx[phi_t2 + 3].v.ob[1] = + this->windowContentVtx[phi_t2].v.ob[1] - 0x10; + this->windowContentVtx[phi_t2 + 1].v.tc[0] = this->windowContentVtx[phi_t2 + 3].v.tc[0] = 0x800; + } + + this->windowContentVtx[phi_t2].v.ob[0] = this->windowContentVtx[phi_t2 + 2].v.ob[0] = phi_t0; + this->windowContentVtx[phi_t2 + 1].v.ob[0] = this->windowContentVtx[phi_t2 + 3].v.ob[0] = + this->windowContentVtx[phi_t2].v.ob[0] + 0x40; + this->windowContentVtx[phi_t2].v.ob[1] = this->windowContentVtx[phi_t2 + 1].v.ob[1] = + this->buttonYOffsets[5] - 0x34; + this->windowContentVtx[phi_t2 + 2].v.ob[1] = this->windowContentVtx[phi_t2 + 3].v.ob[1] = + this->windowContentVtx[phi_t2].v.ob[1] - 0x10; + this->windowContentVtx[phi_t2 + 1].v.tc[0] = this->windowContentVtx[phi_t2 + 3].v.tc[0] = 0x800; + + phi_t2 += 4; + + if (((this->menuMode == FS_MENU_MODE_CONFIG) && (this->configMode >= CM_MAIN_MENU)) || + ((this->menuMode == FS_MENU_MODE_SELECT) && (this->selectMode == SM_CONFIRM_FILE))) { + if (this->menuMode == FS_MENU_MODE_CONFIG) { + if ((this->configMode == CM_SELECT_COPY_SOURCE) || (this->configMode == CM_SELECT_COPY_DEST) || + (this->configMode == CM_ERASE_SELECT)) { + phi_t5 = D_8081283C[this->buttonIndex]; + } else if ((this->configMode == CM_ERASE_CONFIRM) || (this->configMode == CM_COPY_CONFIRM)) { + phi_t5 = D_80812844[this->buttonIndex]; + } else { + phi_t5 = D_80812830[this->buttonIndex]; + } + } else { + phi_t5 = D_80812848[this->confirmButtonIndex]; + } + + this->windowContentVtx[phi_t2].v.ob[0] = this->windowContentVtx[phi_t2 + 2].v.ob[0] = this->windowPosX - 0xA; + this->windowContentVtx[phi_t2 + 1].v.ob[0] = this->windowContentVtx[phi_t2 + 3].v.ob[0] = + this->windowContentVtx[phi_t2].v.ob[0] + 0x48; + this->windowContentVtx[phi_t2].v.ob[1] = this->windowContentVtx[phi_t2 + 1].v.ob[1] = + this->windowContentVtx[phi_t5].v.ob[1] + 4; + this->windowContentVtx[phi_t2 + 2].v.ob[1] = this->windowContentVtx[phi_t2 + 3].v.ob[1] = + this->windowContentVtx[phi_t2].v.ob[1] - 0x18; + this->windowContentVtx[phi_t2 + 1].v.tc[0] = this->windowContentVtx[phi_t2 + 3].v.tc[0] = 0x900; + this->windowContentVtx[phi_t2 + 2].v.tc[1] = this->windowContentVtx[phi_t2 + 3].v.tc[1] = 0x300; + } + + this->windowContentVtx[phi_t2 + 4].v.ob[0] = this->windowContentVtx[phi_t2 + 6].v.ob[0] = this->windowPosX + 0x3A; + this->windowContentVtx[phi_t2 + 5].v.ob[0] = this->windowContentVtx[phi_t2 + 7].v.ob[0] = + this->windowContentVtx[phi_t2 + 4].v.ob[0] + 0x80; + this->windowContentVtx[phi_t2 + 4].v.ob[1] = this->windowContentVtx[phi_t2 + 5].v.ob[1] = + this->windowContentVtx[D_80812830[this->warningButtonIndex]].v.ob[1]; + this->windowContentVtx[phi_t2 + 6].v.ob[1] = this->windowContentVtx[phi_t2 + 7].v.ob[1] = + this->windowContentVtx[phi_t2 + 4].v.ob[1] - 0x10; + this->windowContentVtx[phi_t2 + 5].v.tc[0] = this->windowContentVtx[phi_t2 + 7].v.tc[0] = 0x1000; +} + +static u16 D_8081284C[] = { 0x007C, 0x0124, 0x01CC }; + +static void* sQuestItemTextures[] = { + gFileSelKokiriEmeraldTex, gFileSelGoronRubyTex, gFileSelZoraSapphireTex, + gFileSelForestMedallionTex, gFileSelFireMedallionTex, gFileSelWaterMedallionTex, + gFileSelSpiritMedallionTex, gFileSelShadowMedallionTex, gFileSelLightMedallionTex, +}; + +static s16 sQuestItemRed[] = { 255, 255, 255, 0, 255, 0, 255, 200, 200 }; +static s16 sQuestItemGreen[] = { 255, 255, 255, 255, 60, 100, 130, 50, 200 }; +static s16 sQuestItemBlue[] = { 255, 255, 255, 0, 0, 255, 0, 255, 0 }; +static s16 sQuestItemFlags[] = { 0x0012, 0x0013, 0x0014, 0x0000, 0x0001, 0x0002, 0x0003, 0x0004, 0x0005 }; +static s16 sNamePrimColors[2][3] = { { 255, 255, 255 }, { 100, 100, 100 } }; +static void* sHeartTextures[] = { gHeartFullTex, gDefenseHeartFullTex }; +static s16 sHeartPrimColors[2][3] = { { 255, 70, 50 }, { 200, 0, 0 } }; +static s16 sHeartEnvColors[2][3] = { { 50, 40, 60 }, { 255, 255, 255 } }; + +void FileChoose_DrawFileInfo(GameState* thisx, s16 fileIndex, s16 isActive) { + FileChooseContext* this = (FileChooseContext*)thisx; + Font* sp54 = &this->font; + s32 heartType; + s16 i; + s16 vtxOffset; + s16 j; + s16 deathCountSplit[3]; + + if (1) {} + + OPEN_DISPS(this->state.gfxCtx, "../z_file_choose.c", 1709); + + gDPPipeSync(POLY_OPA_DISP++); + gDPSetCombineLERP(POLY_OPA_DISP++, 0, 0, 0, PRIMITIVE, TEXEL0, 0, PRIMITIVE, 0, 0, 0, 0, PRIMITIVE, TEXEL0, 0, + PRIMITIVE, 0); + + // draw file name + if (this->nameAlpha[fileIndex] != 0) { + gSPVertex(POLY_OPA_DISP++, &this->windowContentVtx[D_8081284C[fileIndex]], 32, 0); + gDPSetPrimColor(POLY_OPA_DISP++, 0x00, 0x00, sNamePrimColors[isActive][0], sNamePrimColors[isActive][1], + sNamePrimColors[isActive][2], this->nameAlpha[fileIndex]); + + for (i = 0, vtxOffset = 0; vtxOffset < 0x20; i++, vtxOffset += 4) { + FileChoose_DrawCharacter(this->state.gfxCtx, + sp54->fontBuf + this->fileNames[fileIndex][i] * FONT_CHAR_TEX_SIZE, vtxOffset); + } + } + + if ((fileIndex == this->selectedFileIndex) || (fileIndex == this->copyDestFileIndex)) { + gDPPipeSync(POLY_OPA_DISP++); + gDPSetCombineLERP(POLY_OPA_DISP++, 1, 0, PRIMITIVE, 0, TEXEL0, 0, PRIMITIVE, 0, 1, 0, PRIMITIVE, 0, TEXEL0, 0, + PRIMITIVE, 0); + gDPSetPrimColor(POLY_OPA_DISP++, 0x00, 0x00, 255, 255, 255, this->fileInfoAlpha[fileIndex]); + gSPVertex(POLY_OPA_DISP++, &this->windowContentVtx[D_8081284C[fileIndex]] + 0x24, 12, 0); + + FileChoose_SplitNumber(this->deaths[fileIndex], &deathCountSplit[0], &deathCountSplit[1], &deathCountSplit[2]); + + // draw death count + for (i = 0, vtxOffset = 0; i < 3; i++, vtxOffset += 4) { + FileChoose_DrawCharacter(this->state.gfxCtx, sp54->fontBuf + deathCountSplit[i] * FONT_CHAR_TEX_SIZE, + vtxOffset); + } + + gDPPipeSync(POLY_OPA_DISP++); + + heartType = (this->defense[fileIndex] == 0) ? 0 : 1; + + gDPPipeSync(POLY_OPA_DISP++); + gDPSetCombineLERP(POLY_OPA_DISP++, PRIMITIVE, ENVIRONMENT, TEXEL0, ENVIRONMENT, TEXEL0, 0, PRIMITIVE, 0, + PRIMITIVE, ENVIRONMENT, TEXEL0, ENVIRONMENT, TEXEL0, 0, PRIMITIVE, 0); + gDPSetPrimColor(POLY_OPA_DISP++, 0x00, 0x00, sHeartPrimColors[heartType][0], sHeartPrimColors[heartType][1], + sHeartPrimColors[heartType][2], this->fileInfoAlpha[fileIndex]); + gDPSetEnvColor(POLY_OPA_DISP++, sHeartEnvColors[heartType][0], sHeartEnvColors[heartType][1], + sHeartEnvColors[heartType][2], 255); + + i = this->healthCapacities[fileIndex] / 0x10; + + // draw hearts + for (vtxOffset = 0, j = 0; j < i; j++, vtxOffset += 4) { + gSPVertex(POLY_OPA_DISP++, &this->windowContentVtx[D_8081284C[fileIndex] + vtxOffset] + 0x30, 4, 0); + + POLY_OPA_DISP = FileChoose_QuadTextureIA8(POLY_OPA_DISP, sHeartTextures[heartType], 0x10, 0x10, 0); + } + + gDPPipeSync(POLY_OPA_DISP++); + + // draw quest items + for (vtxOffset = 0, j = 0; j < 9; j++, vtxOffset += 4) { + if (this->questItems[fileIndex] & gBitFlags[sQuestItemFlags[j]]) { + gSPVertex(POLY_OPA_DISP++, &this->windowContentVtx[D_8081284C[fileIndex] + vtxOffset] + 0x80, 4, 0); + gDPPipeSync(POLY_OPA_DISP++); + gDPSetPrimColor(POLY_OPA_DISP++, 0x00, 0x00, sQuestItemRed[j], sQuestItemGreen[j], sQuestItemBlue[j], + this->fileInfoAlpha[fileIndex]); + gDPSetEnvColor(POLY_OPA_DISP++, 0, 0, 0, 0); + + if (j < 3) { + gDPLoadTextureBlock(POLY_OPA_DISP++, sQuestItemTextures[j], G_IM_FMT_RGBA, G_IM_SIZ_32b, 16, 16, 0, + G_TX_NOMIRROR | G_TX_WRAP, G_TX_NOMASK, G_TX_NOLOD, G_TX_NOMIRROR | G_TX_WRAP, + G_TX_NOMASK, G_TX_NOLOD); + gSP1Quadrangle(POLY_OPA_DISP++, 0, 2, 3, 1, 0); + + } else { + POLY_OPA_DISP = FileChoose_QuadTextureIA8(POLY_OPA_DISP, sQuestItemTextures[j], 0x10, 0x10, 0); + } + } + } + } + + CLOSE_DISPS(this->state.gfxCtx, "../z_file_choose.c", 1797); +} + +static void* sFileInfoBoxTextures[] = { + gFileSelFileInfoBox1Tex, gFileSelFileInfoBox2Tex, gFileSelFileInfoBox3Tex, + gFileSelFileInfoBox4Tex, gFileSelFileInfoBox5Tex, +}; + +static void* sTitleLabels[3][9] = { + { gFileSelPleaseSelectAFileENGTex, gFileSelOpenThisFileENGTex, gFileSelCopyWhichFileENGTex, + gFileSelCopyToWhichFileENGTex, gFileSelAreYouSureENGTex, gFileSelFileCopiedENGTex, gFileSelEraseWhichFileENGTex, + gFileSelAreYouSure2ENGTex, gFileSelFileErasedENGTex }, + { gFileSelPleaseSelectAFileGERTex, gFileSelOpenThisFileGERTex, gFileSelWhichFile1GERTex, + gFileSelCopyToWhichFileGERTex, gFileSelAreYouSureGERTex, gFileSelFileCopiedGERTex, gFileSelWhichFile2GERTex, + gFileSelAreYouSure2GERTex, gFileSelFileErasedGERTex }, + { gFileSelPleaseSelectAFileFRATex, gFileSelOpenThisFileFRATex, gFileSelCopyWhichFileFRATex, + gFileSelCopyToWhichFileFRATex, gFileSelAreYouSureFRATex, gFileSelFileCopiedFRATex, gFileSelEraseWhichFileFRATex, + gFileSelAreYouSure2FRATex, gFileSelFileErasedFRATex } +}; + +static void* sWarningLabels[3][5] = { + { gFileSelNoFileToCopyENGTex, gFileSelNoFileToEraseENGTex, gFileSelNoEmptyFileENGTex, gFileSelFileEmptyENGTex, + gFileSelFileInUseENGTex }, + { gFileSelNoFileToCopyGERTex, gFileSelNoFileToEraseGERTex, gFileSelNoEmptyFileGERTex, gFileSelFileEmptyGERTex, + gFileSelFileInUseGERTex }, + { gFileSelNoFileToCopyFRATex, gFileSelNoFileToEraseFRATex, gFileSelNoEmptyFileFRATex, gFileSelFileEmptyFRATex, + gFileSelFileInUseFRATex }, +}; + +static void* sFileButtonTextures[3][3] = { + { gFileSelFile1ButtonENGTex, gFileSelFile2ButtonENGTex, gFileSelFile3ButtonENGTex }, + { gFileSelFile1ButtonGERTex, gFileSelFile2ButtonGERTex, gFileSelFile3ButtonGERTex }, + { gFileSelFile1ButtonFRATex, gFileSelFile2ButtonFRATex, gFileSelFile3ButtonFRATex }, +}; + +static void* sActionButtonTextures[3][4] = { + { gFileSelCopyButtonENGTex, gFileSelEraseButtonENGTex, gFileSelYesButtonENGTex, gFileSelQuitButtonENGTex }, + { gFileSelCopyButtonGERTex, gFileSelEraseButtonGERTex, gFileSelYesButtonGERTex, gFileSelQuitButtonGERTex }, + { gFileSelCopyButtonFRATex, gFileSelEraseButtonFRATex, gFileSelYesButtonFRATex, gFileSelQuitButtonFRATex }, +}; + +static void* sOptionsButtonTextures[] = { + gFileSelOptionsButtonENGTex, + gFileSelOptionsButtonGERTex, + gFileSelOptionsButtonENGTex, +}; + +/** + * Draw most window contents including buttons, labels, and icons. + * Does not include anything from the keyboard and settings windows. + */ +void FileChoose_DrawWindowContents(GameState* thisx) { + FileChooseContext* this = (FileChooseContext*)thisx; + s16 fileIndex; + s16 temp; + s16 i; + s16 quadVtxIndex; + s16 isActive; + s16 pad; + + OPEN_DISPS(this->state.gfxCtx, "../z_file_choose.c", 1940); + + // draw title label + gDPPipeSync(POLY_OPA_DISP++); + gDPSetCombineLERP(POLY_OPA_DISP++, PRIMITIVE, ENVIRONMENT, TEXEL0, ENVIRONMENT, TEXEL0, 0, PRIMITIVE, 0, PRIMITIVE, + ENVIRONMENT, TEXEL0, ENVIRONMENT, TEXEL0, 0, PRIMITIVE, 0); + gDPSetPrimColor(POLY_OPA_DISP++, 0, 0, 255, 255, 255, this->titleAlpha[0]); + gDPSetEnvColor(POLY_OPA_DISP++, 0, 0, 0, 0); + gSPVertex(POLY_OPA_DISP++, this->windowContentVtx, 4, 0); + gDPLoadTextureBlock(POLY_OPA_DISP++, sTitleLabels[gSaveContext.language][this->titleLabel], G_IM_FMT_IA, + G_IM_SIZ_8b, 128, 16, 0, G_TX_NOMIRROR | G_TX_WRAP, G_TX_NOMIRROR | G_TX_WRAP, G_TX_NOMASK, + G_TX_NOMASK, G_TX_NOLOD, G_TX_NOLOD); + gSP1Quadrangle(POLY_OPA_DISP++, 0, 2, 3, 1, 0); + + // draw next title label + gDPPipeSync(POLY_OPA_DISP++); + gDPSetPrimColor(POLY_OPA_DISP++, 0, 0, 255, 255, 255, this->titleAlpha[1]); + gDPLoadTextureBlock(POLY_OPA_DISP++, sTitleLabels[gSaveContext.language][this->nextTitleLabel], G_IM_FMT_IA, + G_IM_SIZ_8b, 128, 16, 0, G_TX_NOMIRROR | G_TX_WRAP, G_TX_NOMIRROR | G_TX_WRAP, G_TX_NOMASK, + G_TX_NOMASK, G_TX_NOLOD, G_TX_NOLOD); + gSP1Quadrangle(POLY_OPA_DISP++, 0, 2, 3, 1, 0); + + temp = 4; + + gDPPipeSync(POLY_OPA_DISP++); + + // draw file info box (large box when a file is selected) + for (fileIndex = 0; fileIndex < 3; fileIndex++, temp += 20) { + gDPPipeSync(POLY_OPA_DISP++); + gDPSetPrimColor(POLY_OPA_DISP++, 0, 0, this->windowColor[0], this->windowColor[1], this->windowColor[2], + this->fileInfoAlpha[fileIndex]); + gSPVertex(POLY_OPA_DISP++, &this->windowContentVtx[temp], 20, 0); + + for (quadVtxIndex = 0, i = 0; i < 5; i++, quadVtxIndex += 4) { + gDPLoadTextureBlock(POLY_OPA_DISP++, sFileInfoBoxTextures[i], G_IM_FMT_IA, G_IM_SIZ_16b, + sFileInfoBoxPartWidths[i], 56, 0, G_TX_NOMIRROR | G_TX_WRAP, G_TX_NOMIRROR | G_TX_WRAP, + G_TX_NOMASK, G_TX_NOMASK, G_TX_NOLOD, G_TX_NOLOD); + gSP1Quadrangle(POLY_OPA_DISP++, quadVtxIndex, quadVtxIndex + 2, quadVtxIndex + 3, quadVtxIndex + 1, 0); + } + } + + for (i = 0; i < 3; i++, temp += 20) { + // draw file button + gSPVertex(POLY_OPA_DISP++, &this->windowContentVtx[temp], 20, 0); + + isActive = ((this->n64ddFlag == this->n64ddFlags[i]) || (this->nameBoxAlpha[i] == 0)) ? 0 : 1; + + gDPSetPrimColor(POLY_OPA_DISP++, 0, 0, sWindowContentColors[isActive][0], sWindowContentColors[isActive][1], + sWindowContentColors[isActive][2], this->fileButtonAlpha[i]); + gDPLoadTextureBlock(POLY_OPA_DISP++, sFileButtonTextures[gSaveContext.language][i], G_IM_FMT_IA, G_IM_SIZ_16b, + 64, 16, 0, G_TX_NOMIRROR | G_TX_WRAP, G_TX_NOMIRROR | G_TX_WRAP, G_TX_NOMASK, G_TX_NOMASK, + G_TX_NOLOD, G_TX_NOLOD); + gSP1Quadrangle(POLY_OPA_DISP++, 0, 2, 3, 1, 0); + + // draw file name box + gDPSetPrimColor(POLY_OPA_DISP++, 0, 0, sWindowContentColors[isActive][0], sWindowContentColors[isActive][1], + sWindowContentColors[isActive][2], this->nameBoxAlpha[i]); + gDPLoadTextureBlock(POLY_OPA_DISP++, gFileSelNameBoxTex, G_IM_FMT_IA, G_IM_SIZ_16b, 108, 16, 0, + G_TX_NOMIRROR | G_TX_WRAP, G_TX_NOMIRROR | G_TX_WRAP, G_TX_NOMASK, G_TX_NOMASK, G_TX_NOLOD, + G_TX_NOLOD); + gSP1Quadrangle(POLY_OPA_DISP++, 4, 6, 7, 5, 0); + + // draw disk label for 64DD + if (this->n64ddFlags[i]) { + gDPSetPrimColor(POLY_OPA_DISP++, 0, 0, sWindowContentColors[isActive][0], sWindowContentColors[isActive][1], + sWindowContentColors[isActive][2], this->nameAlpha[i]); + gDPLoadTextureBlock(POLY_OPA_DISP++, gFileSelDISKButtonTex, G_IM_FMT_IA, G_IM_SIZ_16b, 44, 16, 0, + G_TX_NOMIRROR | G_TX_WRAP, G_TX_NOMIRROR | G_TX_WRAP, G_TX_NOMASK, G_TX_NOMASK, + G_TX_NOLOD, G_TX_NOLOD); + gSP1Quadrangle(POLY_OPA_DISP++, 8, 10, 11, 9, 0); + } + + // draw connectors + gDPSetPrimColor(POLY_OPA_DISP++, 0, 0, sWindowContentColors[isActive][0], sWindowContentColors[isActive][1], + sWindowContentColors[isActive][2], this->connectorAlpha[i]); + gDPLoadTextureBlock(POLY_OPA_DISP++, gFileSelConnectorTex, G_IM_FMT_IA, G_IM_SIZ_8b, 24, 16, 0, + G_TX_NOMIRROR | G_TX_WRAP, G_TX_NOMIRROR | G_TX_WRAP, G_TX_NOMASK, G_TX_NOMASK, G_TX_NOLOD, + G_TX_NOLOD); + gSP1Quadrangle(POLY_OPA_DISP++, 12, 14, 15, 13, 0); + + if (this->n64ddFlags[i]) { + gSP1Quadrangle(POLY_OPA_DISP++, 16, 18, 19, 17, 0); + } + } + + // draw file info + for (fileIndex = 0; fileIndex < 3; fileIndex++) { + isActive = ((this->n64ddFlag == this->n64ddFlags[fileIndex]) || (this->nameBoxAlpha[fileIndex] == 0)) ? 0 : 1; + FileChoose_DrawFileInfo(&this->state, fileIndex, isActive); + } + + gDPPipeSync(POLY_OPA_DISP++); + gDPSetCombineLERP(POLY_OPA_DISP++, PRIMITIVE, ENVIRONMENT, TEXEL0, ENVIRONMENT, TEXEL0, 0, PRIMITIVE, 0, PRIMITIVE, + ENVIRONMENT, TEXEL0, ENVIRONMENT, TEXEL0, 0, PRIMITIVE, 0); + gDPSetEnvColor(POLY_OPA_DISP++, 0, 0, 0, 0); + gSPVertex(POLY_OPA_DISP++, &this->windowContentVtx[0x274], 20, 0); + + // draw primary action buttons (copy/erase) + for (quadVtxIndex = 0, i = 0; i < 2; i++, quadVtxIndex += 4) { + gDPPipeSync(POLY_OPA_DISP++); + gDPSetPrimColor(POLY_OPA_DISP++, 0, 0, this->windowColor[0], this->windowColor[1], this->windowColor[2], + this->actionButtonAlpha[i]); + gDPLoadTextureBlock(POLY_OPA_DISP++, sActionButtonTextures[gSaveContext.language][i], G_IM_FMT_IA, G_IM_SIZ_16b, + 64, 16, 0, G_TX_NOMIRROR | G_TX_WRAP, G_TX_NOMIRROR | G_TX_WRAP, G_TX_NOMASK, G_TX_NOMASK, + G_TX_NOLOD, G_TX_NOLOD); + gSP1Quadrangle(POLY_OPA_DISP++, quadVtxIndex, quadVtxIndex + 2, quadVtxIndex + 3, quadVtxIndex + 1, 0); + } + + gDPPipeSync(POLY_OPA_DISP++); + + // draw confirm buttons (yes/quit) + for (quadVtxIndex = 0, i = 0; i < 2; i++, quadVtxIndex += 4) { + temp = this->confirmButtonTexIndices[i]; + + gDPSetPrimColor(POLY_OPA_DISP++, 0, 0, this->windowColor[0], this->windowColor[1], this->windowColor[2], + this->confirmButtonAlpha[i]); + gDPLoadTextureBlock(POLY_OPA_DISP++, sActionButtonTextures[gSaveContext.language][temp], G_IM_FMT_IA, + G_IM_SIZ_16b, 64, 16, 0, G_TX_NOMIRROR | G_TX_WRAP, G_TX_NOMIRROR | G_TX_WRAP, G_TX_NOMASK, + G_TX_NOMASK, G_TX_NOLOD, G_TX_NOLOD); + gSP1Quadrangle(POLY_OPA_DISP++, quadVtxIndex, quadVtxIndex + 2, quadVtxIndex + 3, quadVtxIndex + 1, 0); + } + + // draw options button + gDPPipeSync(POLY_OPA_DISP++); + gDPSetPrimColor(POLY_OPA_DISP++, 0, 0, this->windowColor[0], this->windowColor[1], this->windowColor[2], + this->optionButtonAlpha); + gDPLoadTextureBlock(POLY_OPA_DISP++, sOptionsButtonTextures[gSaveContext.language], G_IM_FMT_IA, G_IM_SIZ_16b, 64, + 16, 0, G_TX_NOMIRROR | G_TX_WRAP, G_TX_NOMIRROR | G_TX_WRAP, G_TX_NOMASK, G_TX_NOMASK, + G_TX_NOLOD, G_TX_NOLOD); + gSP1Quadrangle(POLY_OPA_DISP++, 8, 10, 11, 9, 0); + + // draw highlight over currently selected button + if (((this->menuMode == FS_MENU_MODE_CONFIG) && + ((this->configMode == CM_MAIN_MENU) || (this->configMode == CM_SELECT_COPY_SOURCE) || + (this->configMode == CM_SELECT_COPY_DEST) || (this->configMode == CM_COPY_CONFIRM) || + (this->configMode == CM_ERASE_SELECT) || (this->configMode == CM_ERASE_CONFIRM))) || + ((this->menuMode == FS_MENU_MODE_SELECT) && (this->selectMode == SM_CONFIRM_FILE))) { + gDPPipeSync(POLY_OPA_DISP++); + gDPSetCombineLERP(POLY_OPA_DISP++, 1, 0, PRIMITIVE, 0, TEXEL0, 0, PRIMITIVE, 0, 1, 0, PRIMITIVE, 0, TEXEL0, 0, + PRIMITIVE, 0); + gDPSetPrimColor(POLY_OPA_DISP++, 0, 0, this->highlightColor[0], this->highlightColor[1], + this->highlightColor[2], this->highlightColor[3]); + gDPLoadTextureBlock(POLY_OPA_DISP++, gFileSelBigButtonHighlightTex, G_IM_FMT_I, G_IM_SIZ_8b, 72, 24, 0, + G_TX_NOMIRROR | G_TX_WRAP, G_TX_NOMIRROR | G_TX_WRAP, G_TX_NOMASK, G_TX_NOMASK, G_TX_NOLOD, + G_TX_NOLOD); + gSP1Quadrangle(POLY_OPA_DISP++, 12, 14, 15, 13, 0); + } + + // draw warning labels + if (this->warningLabel > FS_WARNING_NONE) { + gDPPipeSync(POLY_OPA_DISP++); + gDPSetCombineLERP(POLY_OPA_DISP++, PRIMITIVE, ENVIRONMENT, TEXEL0, ENVIRONMENT, TEXEL0, 0, PRIMITIVE, 0, + PRIMITIVE, ENVIRONMENT, TEXEL0, ENVIRONMENT, TEXEL0, 0, PRIMITIVE, 0); + gDPSetPrimColor(POLY_OPA_DISP++, 0, 0, 255, 255, 255, this->emptyFileTextAlpha); + gDPSetEnvColor(POLY_OPA_DISP++, 0, 0, 0, 0); + gDPLoadTextureBlock(POLY_OPA_DISP++, sWarningLabels[gSaveContext.language][this->warningLabel], G_IM_FMT_IA, + G_IM_SIZ_8b, 128, 16, 0, G_TX_NOMIRROR | G_TX_WRAP, G_TX_NOMIRROR | G_TX_WRAP, G_TX_NOMASK, + G_TX_NOMASK, G_TX_NOLOD, G_TX_NOLOD); + gSP1Quadrangle(POLY_OPA_DISP++, 16, 18, 19, 17, 0); + } + + gDPPipeSync(POLY_OPA_DISP++); + gDPSetCombineMode(POLY_OPA_DISP++, G_CC_MODULATEIDECALA, G_CC_MODULATEIDECALA); + + CLOSE_DISPS(this->state.gfxCtx, "../z_file_choose.c", 2198); +} + +void FileChoose_ConfigModeDraw(GameState* thisx) { + FileChooseContext* this = (FileChooseContext*)thisx; + f32 eyeX; + f32 eyeY; + f32 eyeZ; + + OPEN_DISPS(this->state.gfxCtx, "../z_file_choose.c", 2218); + gDPPipeSync(POLY_OPA_DISP++); + + eyeX = 1000.0f * Math_CosS(ZREG(11)) - 1000.0f * Math_SinS(ZREG(11)); + eyeY = ZREG(13); + eyeZ = 1000.0f * Math_SinS(ZREG(11)) + 1000.0f * Math_CosS(ZREG(11)); + + FileChoose_SetView(this, eyeX, eyeY, eyeZ); + SkyboxDraw_Draw(&this->skyboxCtx, this->state.gfxCtx, 1, this->envCtx.skyboxBlend, eyeX, eyeY, eyeZ); + gDPSetTextureLUT(POLY_OPA_DISP++, G_TT_NONE); + ZREG(11) += ZREG(10); + Environment_UpdateSkybox(SKYBOX_NORMAL_SKY, &this->envCtx, &this->skyboxCtx); + gDPPipeSync(POLY_OPA_DISP++); + func_800949A8(this->state.gfxCtx); + FileChoose_SetView(this, 0.0f, 0.0f, 64.0f); + FileChoose_SetWindowVtx(&this->state); + FileChoose_SetWindowContentVtx(&this->state); + + if ((this->configMode != CM_NAME_ENTRY) && (this->configMode != CM_START_NAME_ENTRY)) { + gDPPipeSync(POLY_OPA_DISP++); + gDPSetCombineMode(POLY_OPA_DISP++, G_CC_MODULATEIA_PRIM, G_CC_MODULATEIA_PRIM); + gDPSetPrimColor(POLY_OPA_DISP++, 0, 0, this->windowColor[0], this->windowColor[1], this->windowColor[2], + this->windowAlpha); + gDPSetEnvColor(POLY_OPA_DISP++, 0, 0, 0, 0); + + Matrix_Translate(0.0f, 0.0f, -93.6f, MTXMODE_NEW); + Matrix_Scale(0.78f, 0.78f, 0.78f, MTXMODE_APPLY); + + if (this->windowRot != 0) { + Matrix_RotateX(this->windowRot / 100.0f, MTXMODE_APPLY); + } + + gSPMatrix(POLY_OPA_DISP++, Matrix_NewMtx(this->state.gfxCtx, "../z_file_choose.c", 2282), + G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW); + + gSPVertex(POLY_OPA_DISP++, &this->windowVtx[0], 32, 0); + gSPDisplayList(POLY_OPA_DISP++, gFileSelWindow1DL); + + gSPVertex(POLY_OPA_DISP++, &this->windowVtx[32], 32, 0); + gSPDisplayList(POLY_OPA_DISP++, gFileSelWindow2DL); + + gSPVertex(POLY_OPA_DISP++, &this->windowVtx[64], 16, 0); + gSPDisplayList(POLY_OPA_DISP++, gFileSelWindow3DL); + + gDPPipeSync(POLY_OPA_DISP++); + + FileChoose_DrawWindowContents(&this->state); + } + + // draw name entry menu + if ((this->configMode >= CM_ROTATE_TO_NAME_ENTRY) && (this->configMode <= CM_NAME_ENTRY_TO_MAIN)) { + gDPPipeSync(POLY_OPA_DISP++); + gDPSetCombineMode(POLY_OPA_DISP++, G_CC_MODULATEIA_PRIM, G_CC_MODULATEIA_PRIM); + gDPSetPrimColor(POLY_OPA_DISP++, 0, 0, this->windowColor[0], this->windowColor[1], this->windowColor[2], + this->windowAlpha); + gDPSetEnvColor(POLY_OPA_DISP++, 0, 0, 0, 0); + + Matrix_Translate(0.0f, 0.0f, -93.6f, MTXMODE_NEW); + Matrix_Scale(0.78f, 0.78f, 0.78f, MTXMODE_APPLY); + Matrix_RotateX((this->windowRot - 314.0f) / 100.0f, MTXMODE_APPLY); + gSPMatrix(POLY_OPA_DISP++, Matrix_NewMtx(this->state.gfxCtx, "../z_file_choose.c", 2316), + G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW); + + gSPVertex(POLY_OPA_DISP++, &this->windowVtx[0], 32, 0); + gSPDisplayList(POLY_OPA_DISP++, gFileSelWindow1DL); + + gSPVertex(POLY_OPA_DISP++, &this->windowVtx[32], 32, 0); + gSPDisplayList(POLY_OPA_DISP++, gFileSelWindow2DL); + + gSPVertex(POLY_OPA_DISP++, &this->windowVtx[64], 16, 0); + gSPDisplayList(POLY_OPA_DISP++, gFileSelWindow3DL); + + gDPPipeSync(POLY_OPA_DISP++); + + FileChoose_DrawNameEntry(&this->state); + } + + // draw options menu + if ((this->configMode >= CM_MAIN_TO_OPTIONS) && (this->configMode <= CM_OPTIONS_TO_MAIN)) { + gDPPipeSync(POLY_OPA_DISP++); + gDPSetCombineMode(POLY_OPA_DISP++, G_CC_MODULATEIA_PRIM, G_CC_MODULATEIA_PRIM); + gDPSetPrimColor(POLY_OPA_DISP++, 0, 0, this->windowColor[0], this->windowColor[1], this->windowColor[2], + this->windowAlpha); + gDPSetEnvColor(POLY_OPA_DISP++, 0, 0, 0, 0); + + Matrix_Translate(0.0f, 0.0f, -93.6f, MTXMODE_NEW); + Matrix_Scale(0.78f, 0.78f, 0.78f, MTXMODE_APPLY); + Matrix_RotateX((this->windowRot - 314.0f) / 100.0f, MTXMODE_APPLY); + + gSPMatrix(POLY_OPA_DISP++, Matrix_NewMtx(this->state.gfxCtx, "../z_file_choose.c", 2337), + G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW); + + gSPVertex(POLY_OPA_DISP++, &this->windowVtx[0], 32, 0); + gSPDisplayList(POLY_OPA_DISP++, gFileSelWindow1DL); + + gSPVertex(POLY_OPA_DISP++, &this->windowVtx[32], 32, 0); + gSPDisplayList(POLY_OPA_DISP++, gFileSelWindow2DL); + + gSPVertex(POLY_OPA_DISP++, &this->windowVtx[64], 16, 0); + gSPDisplayList(POLY_OPA_DISP++, gFileSelWindow3DL); + + gDPPipeSync(POLY_OPA_DISP++); + + FileChoose_DrawOptions(&this->state); + } + + gDPPipeSync(POLY_OPA_DISP++); + FileChoose_SetView(this, 0.0f, 0.0f, 64.0f); + + CLOSE_DISPS(this->state.gfxCtx, "../z_file_choose.c", 2352); +} + +/** + * Fade out the main menu elements to transition to select mode. + * Update function for `SM_FADE_MAIN_TO_SELECT` + */ +void FileChoose_FadeMainToSelect(GameState* thisx) { + FileChooseContext* this = (FileChooseContext*)thisx; + SramContext* sramCtx = &this->sramCtx; + s16 i; + + for (i = 0; i < 3; i++) { + if (i != this->buttonIndex) { + this->fileButtonAlpha[i] -= 25; + this->actionButtonAlpha[FS_BTN_ACTION_COPY] = this->actionButtonAlpha[FS_BTN_ACTION_ERASE] = + this->optionButtonAlpha = this->fileButtonAlpha[i]; + + if (SLOT_OCCUPIED(sramCtx, i)) { + this->nameAlpha[i] = this->nameBoxAlpha[i] = this->fileButtonAlpha[i]; + this->connectorAlpha[i] -= 31; + } + } + } + + this->titleAlpha[0] -= 31; + this->titleAlpha[1] += 31; + this->actionTimer--; + + if (this->actionTimer == 0) { + this->actionTimer = 8; + this->selectMode++; + this->confirmButtonIndex = FS_BTN_CONFIRM_YES; + } +} + +/** + * Moves the selected file to the top of the window. + * Update function for `SM_MOVE_FILE_TO_TOP` + */ +void FileChoose_MoveSelectedFileToTop(GameState* thisx) { + static s16 fileYOffsets[] = { 0, 16, 32 }; // amount to move by to reach the top of the screen + FileChooseContext* this = (FileChooseContext*)thisx; + s16 yStep; + + yStep = ABS(this->buttonYOffsets[this->buttonIndex] - fileYOffsets[this->buttonIndex]) / this->actionTimer; + this->buttonYOffsets[this->buttonIndex] += yStep; + this->actionTimer--; + + if ((this->actionTimer == 0) || (this->buttonYOffsets[this->buttonIndex] == fileYOffsets[this->buttonIndex])) { + this->buttonYOffsets[FS_BTN_SELECT_YES] = this->buttonYOffsets[FS_BTN_SELECT_QUIT] = -24; + this->actionTimer = 8; + this->selectMode++; + } +} + +/** + * Fade in the file info for the selected file. + * Update function for `SM_FADE_IN_FILE_INFO` + */ +void FileChoose_FadeInFileInfo(GameState* thisx) { + FileChooseContext* this = (FileChooseContext*)thisx; + + this->fileInfoAlpha[this->buttonIndex] += 25; + this->nameBoxAlpha[this->buttonIndex] -= 50; + + if (this->nameBoxAlpha[this->buttonIndex] <= 0) { + this->nameBoxAlpha[this->buttonIndex] = 0; + } + + this->actionTimer--; + + if (this->actionTimer == 0) { + this->fileInfoAlpha[this->buttonIndex] = 200; + this->actionTimer = 8; + this->selectMode++; + } + + this->confirmButtonAlpha[FS_BTN_CONFIRM_YES] = this->confirmButtonAlpha[FS_BTN_CONFIRM_QUIT] = + this->fileInfoAlpha[this->buttonIndex]; +} + +/** + * Update the cursor and handle the option that the player picks for confirming the selected file. + * Update function for `SM_CONFIRM_FILE` + */ +void FileChoose_ConfirmFile(GameState* thisx) { + FileChooseContext* this = (FileChooseContext*)thisx; + Input* input = &this->state.input[0]; + + if (CHECK_BTN_ALL(input->press.button, BTN_START) || (CHECK_BTN_ALL(input->press.button, BTN_A))) { + if (this->confirmButtonIndex == FS_BTN_CONFIRM_YES) { + func_800AA000(300.0f, 180, 20, 100); + Audio_PlaySoundGeneral(NA_SE_SY_FSEL_DECIDE_L, &D_801333D4, 4, &D_801333E0, &D_801333E0, &D_801333E8); + this->selectMode = SM_FADE_OUT; + func_800F6964(0xF); + } else { + Audio_PlaySoundGeneral(NA_SE_SY_FSEL_CLOSE, &D_801333D4, 4, &D_801333E0, &D_801333E0, &D_801333E8); + this->selectMode++; + } + } else if (CHECK_BTN_ALL(input->press.button, BTN_B)) { + Audio_PlaySoundGeneral(NA_SE_SY_FSEL_CLOSE, &D_801333D4, 4, &D_801333E0, &D_801333E0, &D_801333E8); + this->selectMode++; + } else if (ABS(this->stickRelY) >= 30) { + Audio_PlaySoundGeneral(NA_SE_SY_FSEL_CURSOR, &D_801333D4, 4, &D_801333E0, &D_801333E0, &D_801333E8); + this->confirmButtonIndex ^= 1; + } +} + +/** + * Fade out the file info for the selected file before returning to the main menu. + * Update function for `SM_FADE_OUT_FILE_INFO` + */ +void FileChoose_FadeOutFileInfo(GameState* thisx) { + FileChooseContext* this = (FileChooseContext*)thisx; + + this->fileInfoAlpha[this->buttonIndex] -= 25; + this->nameBoxAlpha[this->buttonIndex] += 25; + this->actionTimer--; + + if (this->actionTimer == 0) { + this->buttonYOffsets[FS_BTN_SELECT_YES] = this->buttonYOffsets[FS_BTN_SELECT_QUIT] = 0; + this->nameBoxAlpha[this->buttonIndex] = 200; + this->fileInfoAlpha[this->buttonIndex] = 0; + this->nextTitleLabel = FS_TITLE_SELECT_FILE; + this->actionTimer = 8; + this->selectMode++; + } + + this->confirmButtonAlpha[0] = this->confirmButtonAlpha[1] = this->fileInfoAlpha[this->buttonIndex]; +} + +/** + * Move the selected file back to the slot position then go to config mode for the main menu. + * Update function for `SM_MOVE_FILE_TO_SLOT` + */ +void FileChoose_MoveSelectedFileToSlot(GameState* thisx) { + FileChooseContext* this = (FileChooseContext*)thisx; + SramContext* sramCtx = &this->sramCtx; + s16 yStep; + s16 i; + + yStep = ABS(this->buttonYOffsets[this->buttonIndex]) / this->actionTimer; + this->buttonYOffsets[this->buttonIndex] -= yStep; + + if (this->buttonYOffsets[this->buttonIndex] <= 0) { + this->buttonYOffsets[this->buttonIndex] = 0; + } + + for (i = 0; i < 3; i++) { + if (i != this->buttonIndex) { + this->fileButtonAlpha[i] += 25; + + if (this->fileButtonAlpha[i] >= 200) { + this->fileButtonAlpha[i] = 200; + } + + this->actionButtonAlpha[FS_BTN_ACTION_COPY] = this->actionButtonAlpha[FS_BTN_ACTION_ERASE] = + this->optionButtonAlpha = this->fileButtonAlpha[i]; + + if (SLOT_OCCUPIED(sramCtx, i)) { + this->nameBoxAlpha[i] = this->nameAlpha[i] = this->fileButtonAlpha[i]; + this->connectorAlpha[i] += 31; + } + } + } + + this->titleAlpha[0] -= 31; + this->titleAlpha[1] += 31; + this->actionTimer--; + + if (this->actionTimer == 0) { + this->titleAlpha[0] = 255; + this->titleAlpha[1] = 0; + this->titleLabel = this->nextTitleLabel; + this->actionTimer = 8; + this->menuMode = FS_MENU_MODE_CONFIG; + this->configMode = CM_MAIN_MENU; + this->nextConfigMode = CM_MAIN_MENU; + this->selectMode = SM_FADE_MAIN_TO_SELECT; + } +} + +/** + * Fill the screen with black to fade out. + * Update function for `SM_FADE_OUT` + */ +void FileChoose_FadeOut(GameState* thisx) { + FileChooseContext* this = (FileChooseContext*)thisx; + + sScreenFillAlpha += VREG(10); + + if (sScreenFillAlpha >= 255) { + sScreenFillAlpha = 255; + this->selectMode++; + } +} + +/** + * Load the save for the appropriate file and start the game. + * Note: On Debug ROM, File 1 will go to Map Select. + * Update function for `SM_LOAD_GAME` + */ +void FileChoose_LoadGame(GameState* thisx) { + FileChooseContext* this = (FileChooseContext*)thisx; + u16 swordEquipMask; + s32 pad; + + if (this->buttonIndex == FS_BTN_SELECT_FILE_1) { + Audio_PlaySoundGeneral(NA_SE_SY_FSEL_DECIDE_L, &D_801333D4, 4, &D_801333E0, &D_801333E0, &D_801333E8); + gSaveContext.fileNum = this->buttonIndex; + Sram_OpenSave(&this->sramCtx); + gSaveContext.gameMode = 0; + SET_NEXT_GAMESTATE(&this->state, Select_Init, SelectContext); + this->state.running = false; + } else { + Audio_PlaySoundGeneral(NA_SE_SY_FSEL_DECIDE_L, &D_801333D4, 4, &D_801333E0, &D_801333E0, &D_801333E8); + gSaveContext.fileNum = this->buttonIndex; + Sram_OpenSave(&this->sramCtx); + gSaveContext.gameMode = 0; + SET_NEXT_GAMESTATE(&this->state, Gameplay_Init, GlobalContext); + this->state.running = false; + } + + gSaveContext.respawn[0].entranceIndex = -1; + gSaveContext.respawnFlag = 0; + gSaveContext.seqIndex = 0xFF; + gSaveContext.nightSeqIndex = 0xFF; + gSaveContext.showTitleCard = true; + gSaveContext.dogParams = 0; + gSaveContext.timer1State = 0; + gSaveContext.timer2State = 0; + gSaveContext.eventInf[0] = 0; + gSaveContext.eventInf[1] = 0; + gSaveContext.eventInf[2] = 0; + gSaveContext.eventInf[3] = 0; + gSaveContext.unk_13EE = 0x32; + gSaveContext.nayrusLoveTimer = 0; + gSaveContext.healthAccumulator = 0; + gSaveContext.unk_13F0 = 0; + gSaveContext.unk_13F2 = 0; + gSaveContext.unk_140E = 0; + gSaveContext.skyboxTime = 0; + gSaveContext.nextTransition = 0xFF; + gSaveContext.nextCutsceneIndex = 0xFFEF; + gSaveContext.cutsceneTrigger = 0; + gSaveContext.chamberCutsceneNum = 0; + gSaveContext.nextDayTime = 0xFFFF; + gSaveContext.unk_13C3 = 0; + + gSaveContext.buttonStatus[0] = gSaveContext.buttonStatus[1] = gSaveContext.buttonStatus[2] = + gSaveContext.buttonStatus[3] = gSaveContext.buttonStatus[4] = BTN_ENABLED; + + gSaveContext.unk_13E7 = gSaveContext.unk_13E8 = gSaveContext.unk_13EA = gSaveContext.unk_13EC = + gSaveContext.unk_13F4 = 0; + + gSaveContext.unk_13F6 = gSaveContext.magic; + gSaveContext.magic = 0; + gSaveContext.magicLevel = gSaveContext.magic; + + if (1) {} + + osSyncPrintf(VT_FGCOL(GREEN)); + osSyncPrintf("Z_MAGIC_NOW_NOW=%d MAGIC_NOW=%d\n", ((void)0, gSaveContext.unk_13F6), gSaveContext.magic); + osSyncPrintf(VT_RST); + + gSaveContext.naviTimer = 0; + + if ((gSaveContext.equips.buttonItems[0] != ITEM_SWORD_KOKIRI) && + (gSaveContext.equips.buttonItems[0] != ITEM_SWORD_MASTER) && + (gSaveContext.equips.buttonItems[0] != ITEM_SWORD_BGS) && + (gSaveContext.equips.buttonItems[0] != ITEM_SWORD_KNIFE)) { + + gSaveContext.equips.buttonItems[0] = ITEM_NONE; + swordEquipMask = gEquipMasks[EQUIP_SWORD] & gSaveContext.equips.equipment; + gSaveContext.equips.equipment &= gEquipNegMasks[EQUIP_SWORD]; + gSaveContext.inventory.equipment ^= (gBitFlags[swordEquipMask - 1] << gEquipShifts[EQUIP_SWORD]); + } +} + +static void (*gSelectModeUpdateFuncs[])(GameState*) = { + FileChoose_FadeMainToSelect, FileChoose_MoveSelectedFileToTop, FileChoose_FadeInFileInfo, FileChoose_ConfirmFile, + FileChoose_FadeOutFileInfo, FileChoose_MoveSelectedFileToSlot, FileChoose_FadeOut, FileChoose_LoadGame, +}; + +void FileChoose_SelectModeUpdate(GameState* thisx) { + FileChooseContext* this = (FileChooseContext*)thisx; + + gSelectModeUpdateFuncs[this->selectMode](&this->state); +} + +void FileChoose_SelectModeDraw(GameState* thisx) { + FileChooseContext* this = (FileChooseContext*)thisx; + f32 eyeX; + f32 eyeY; + f32 eyeZ; + + OPEN_DISPS(this->state.gfxCtx, "../z_file_choose.c", 2753); + + gDPPipeSync(POLY_OPA_DISP++); + + eyeX = 1000.0f * Math_CosS(ZREG(11)) - 1000.0f * Math_SinS(ZREG(11)); + eyeY = ZREG(13); + eyeZ = 1000.0f * Math_SinS(ZREG(11)) + 1000.0f * Math_CosS(ZREG(11)); + + FileChoose_SetView(this, eyeX, eyeY, eyeZ); + SkyboxDraw_Draw(&this->skyboxCtx, this->state.gfxCtx, 1, this->envCtx.skyboxBlend, eyeX, eyeY, eyeZ); + gDPSetTextureLUT(POLY_OPA_DISP++, G_TT_NONE); + ZREG(11) += ZREG(10); + Environment_UpdateSkybox(SKYBOX_NORMAL_SKY, &this->envCtx, &this->skyboxCtx); + gDPPipeSync(POLY_OPA_DISP++); + func_800949A8(this->state.gfxCtx); + FileChoose_SetView(this, 0.0f, 0.0f, 64.0f); + FileChoose_SetWindowVtx(&this->state); + FileChoose_SetWindowContentVtx(&this->state); + + gDPSetCombineMode(POLY_OPA_DISP++, G_CC_MODULATEIA_PRIM, G_CC_MODULATEIA_PRIM); + gDPSetPrimColor(POLY_OPA_DISP++, 0, 0, this->windowColor[0], this->windowColor[1], this->windowColor[2], + this->windowAlpha); + gDPSetEnvColor(POLY_OPA_DISP++, 0, 0, 0, 0); + + Matrix_Translate(0.0f, 0.0f, -93.6f, MTXMODE_NEW); + Matrix_Scale(0.78f, 0.78f, 0.78f, MTXMODE_APPLY); + Matrix_RotateX(this->windowRot / 100.0f, MTXMODE_APPLY); + gSPMatrix(POLY_OPA_DISP++, Matrix_NewMtx(this->state.gfxCtx, "../z_file_choose.c", 2810), + G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW); + + gSPVertex(POLY_OPA_DISP++, &this->windowVtx[0], 32, 0); + gSPDisplayList(POLY_OPA_DISP++, gFileSelWindow1DL); + + gSPVertex(POLY_OPA_DISP++, &this->windowVtx[32], 32, 0); + gSPDisplayList(POLY_OPA_DISP++, gFileSelWindow2DL); + + gSPVertex(POLY_OPA_DISP++, &this->windowVtx[64], 16, 0); + gSPDisplayList(POLY_OPA_DISP++, gFileSelWindow3DL); + + FileChoose_DrawWindowContents(&this->state); + gDPPipeSync(POLY_OPA_DISP++); + FileChoose_SetView(this, 0.0f, 0.0f, 64.0f); + + CLOSE_DISPS(this->state.gfxCtx, "../z_file_choose.c", 2834); +} + +static void (*gFileSelectDrawFuncs[])(GameState*) = { + FileChoose_InitModeDraw, + FileChoose_ConfigModeDraw, + FileChoose_SelectModeDraw, +}; + +static void (*gFileSelectUpdateFuncs[])(GameState*) = { + FileChoose_InitModeUpdate, + FileChoose_ConfigModeUpdate, + FileChoose_SelectModeUpdate, +}; + +void FileChoose_Main(GameState* thisx) { + static void* controlsTextures[] = { + gFileSelControlsENGTex, + gFileSelControlsGERTex, + gFileSelControlsFRATex, + }; + FileChooseContext* this = (FileChooseContext*)thisx; + Input* input = &this->state.input[0]; + + OPEN_DISPS(this->state.gfxCtx, "../z_file_choose.c", 2898); + + this->n64ddFlag = 0; + + gSPSegment(POLY_OPA_DISP++, 0x00, NULL); + gSPSegment(POLY_OPA_DISP++, 0x01, this->staticSegment); + gSPSegment(POLY_OPA_DISP++, 0x02, this->parameterSegment); + + func_80095248(this->state.gfxCtx, 0, 0, 0); + + this->stickRelX = input->rel.stick_x; + this->stickRelY = input->rel.stick_y; + + if (this->stickRelX < -30) { + if (this->stickXDir == -1) { + this->inputTimerX--; + if (this->inputTimerX < 0) { + this->inputTimerX = 2; + } else { + this->stickRelX = 0; + } + } else { + this->inputTimerX = 10; + this->stickXDir = -1; + } + } else if (this->stickRelX > 30) { + if (this->stickXDir == 1) { + this->inputTimerX--; + if (this->inputTimerX < 0) { + this->inputTimerX = 2; + } else { + this->stickRelX = 0; + } + } else { + this->inputTimerX = 10; + this->stickXDir = 1; + } + } else { + this->stickXDir = 0; + } + + if (this->stickRelY < -30) { + if (this->stickYDir == -1) { + this->inputTimerY -= 1; + if (this->inputTimerY < 0) { + this->inputTimerY = 2; + } else { + this->stickRelY = 0; + } + } else { + this->inputTimerY = 10; + this->stickYDir = -1; + } + } else if (this->stickRelY > 30) { + if (this->stickYDir == 1) { + this->inputTimerY -= 1; + if (this->inputTimerY < 0) { + this->inputTimerY = 2; + } else { + this->stickRelY = 0; + } + } else { + this->inputTimerY = 10; + this->stickYDir = 1; + } + } else { + this->stickYDir = 0; + } + + this->emptyFileTextAlpha = 0; + + FileChoose_PulsateCursor(&this->state); + gFileSelectUpdateFuncs[this->menuMode](&this->state); + gFileSelectDrawFuncs[this->menuMode](&this->state); + + // do not draw controls text in the options menu + if ((this->configMode <= CM_NAME_ENTRY_TO_MAIN) || (this->configMode >= CM_UNUSED_DELAY)) { + func_800944C4(this->state.gfxCtx); + + gDPSetCombineLERP(POLY_OPA_DISP++, PRIMITIVE, ENVIRONMENT, TEXEL0, ENVIRONMENT, TEXEL0, 0, PRIMITIVE, 0, + PRIMITIVE, ENVIRONMENT, TEXEL0, ENVIRONMENT, TEXEL0, 0, PRIMITIVE, 0); + gDPSetPrimColor(POLY_OPA_DISP++, 0, 0, 100, 255, 255, this->controlsAlpha); + gDPSetEnvColor(POLY_OPA_DISP++, 0, 0, 0, 0); + gDPLoadTextureBlock(POLY_OPA_DISP++, controlsTextures[gSaveContext.language], G_IM_FMT_IA, G_IM_SIZ_8b, 144, 16, + 0, G_TX_NOMIRROR | G_TX_WRAP, G_TX_NOMIRROR | G_TX_WRAP, G_TX_NOMASK, G_TX_NOMASK, + G_TX_NOLOD, G_TX_NOLOD); + gSPTextureRectangle(POLY_OPA_DISP++, 0x0168, 0x0330, 0x03A8, 0x0370, G_TX_RENDERTILE, 0, 0, 0x0400, 0x0400); + } + + gDPPipeSync(POLY_OPA_DISP++); + gSPDisplayList(POLY_OPA_DISP++, sScreenFillSetupDL); + gDPSetPrimColor(POLY_OPA_DISP++, 0, 0, 0, 0, 0, sScreenFillAlpha); + gDPFillRectangle(POLY_OPA_DISP++, 0, 0, gScreenWidth - 1, gScreenHeight - 1); + + CLOSE_DISPS(this->state.gfxCtx, "../z_file_choose.c", 3035); +} + +void FileChoose_InitContext(GameState* thisx) { + FileChooseContext* this = (FileChooseContext*)thisx; + EnvironmentContext* envCtx = &this->envCtx; + SramContext* sramCtx = &this->sramCtx; + + Sram_Alloc(&this->state, sramCtx); + + ZREG(7) = 32; + ZREG(8) = 22; + ZREG(9) = 20; + ZREG(10) = -10; + ZREG(11) = 0; + ZREG(12) = 1000; + ZREG(13) = -700; + ZREG(14) = 164; + ZREG(15) = 104; + ZREG(16) = 160; + ZREG(17) = 100; + ZREG(18) = 162; + ZREG(19) = 152; + ZREG(20) = 214; + + XREG(13) = 580; + XREG(14) = 400; + XREG(35) = 20; + XREG(36) = 20; + XREG(37) = 20; + XREG(43) = 8; + XREG(44) = -78; + XREG(45) = 0; + XREG(46) = 0; + XREG(47) = 0; + XREG(48) = 0; + XREG(49) = 3; + XREG(50) = 8; + XREG(51) = 8; + XREG(52) = 10; + XREG(73) = 0; + + VREG(0) = 14; + VREG(1) = 5; + VREG(2) = 4; + VREG(4) = 1; + VREG(5) = 6; + VREG(6) = 2; + VREG(7) = 6; + VREG(8) = 80; + + sScreenFillAlpha = 255; + + VREG(10) = 10; + VREG(11) = 30; + VREG(12) = -100; + VREG(13) = -85; + VREG(14) = 4; + VREG(16) = 25; + VREG(17) = 1; + VREG(18) = 1; + VREG(20) = 92; + VREG(21) = 171; + VREG(22) = 11; + VREG(23) = 10; + VREG(24) = 26; + VREG(25) = 2; + VREG(26) = 1; + VREG(27) = 0; + VREG(28) = 0; + VREG(29) = 160; + VREG(30) = 64; + VREG(31) = 154; + VREG(32) = 152; + VREG(33) = 106; + + WREG(38) = 16; + WREG(39) = 9; + WREG(40) = 10; + WREG(41) = 14; + WREG(42) = 11; + WREG(43) = 12; + + this->menuMode = FS_MENU_MODE_INIT; + + this->buttonIndex = this->selectMode = this->selectedFileIndex = this->copyDestFileIndex = + this->confirmButtonIndex = 0; + + this->confirmButtonTexIndices[0] = 2; + this->confirmButtonTexIndices[1] = 3; + this->titleLabel = FS_TITLE_SELECT_FILE; + this->nextTitleLabel = FS_TITLE_OPEN_FILE; + this->highlightPulseDir = 1; + this->unk_1CAAC = 0xC; + this->highlightColor[0] = 155; + this->highlightColor[1] = 255; + this->highlightColor[2] = 255; + this->highlightColor[3] = 70; + this->configMode = CM_FADE_IN_START; + this->windowRot = 0.0f; + this->stickXDir = this->inputTimerX = 0; + this->stickYDir = this->inputTimerY = 0; + this->kbdX = this->kbdY = this->charIndex = 0; + this->kbdButton = FS_KBD_BTN_NONE; + + this->windowColor[0] = 100; + this->windowColor[1] = 150; + this->windowColor[2] = 255; + + this->windowAlpha = this->titleAlpha[0] = this->titleAlpha[1] = this->fileButtonAlpha[0] = + this->fileButtonAlpha[1] = this->fileButtonAlpha[2] = this->nameBoxAlpha[0] = this->nameBoxAlpha[1] = + this->nameBoxAlpha[2] = this->nameAlpha[0] = this->nameAlpha[1] = this->nameAlpha[2] = + this->connectorAlpha[0] = this->connectorAlpha[1] = this->connectorAlpha[2] = this->fileInfoAlpha[0] = + this->fileInfoAlpha[1] = this->fileInfoAlpha[2] = this->actionButtonAlpha[FS_BTN_ACTION_COPY] = + this->actionButtonAlpha[FS_BTN_ACTION_ERASE] = this->confirmButtonAlpha[FS_BTN_CONFIRM_YES] = + this->confirmButtonAlpha[FS_BTN_CONFIRM_QUIT] = this->optionButtonAlpha = + this->nameEntryBoxAlpha = this->controlsAlpha = this->emptyFileTextAlpha = 0; + + this->windowPosX = 6; + this->actionTimer = 8; + this->warningLabel = FS_WARNING_NONE; + + this->warningButtonIndex = this->buttonYOffsets[0] = this->buttonYOffsets[1] = this->buttonYOffsets[2] = + this->buttonYOffsets[3] = this->buttonYOffsets[4] = this->buttonYOffsets[5] = this->fileNamesY[0] = + this->fileNamesY[1] = this->fileNamesY[2] = 0; + + this->unk_1CAD6[0] = 0; + this->unk_1CAD6[1] = 3; + this->unk_1CAD6[2] = 6; + this->unk_1CAD6[3] = 8; + this->unk_1CAD6[4] = 10; + + ShrinkWindow_SetVal(0); + + gSaveContext.skyboxTime = 0; + gSaveContext.dayTime = 0; + + Skybox_Init(&this->state, &this->skyboxCtx, SKYBOX_NORMAL_SKY); + + gTimeIncrement = 10; + + envCtx->unk_19 = 0; + envCtx->unk_1A = 0; + envCtx->unk_21 = 0; + envCtx->unk_22 = 0; + envCtx->skyboxDmaState = SKYBOX_DMA_INACTIVE; + envCtx->skybox1Index = 99; + envCtx->skybox2Index = 99; + envCtx->unk_1F = 0; + envCtx->unk_20 = 0; + envCtx->unk_BD = 0; + envCtx->unk_17 = 2; + envCtx->skyboxDisabled = 0; + envCtx->skyboxBlend = 0; + envCtx->unk_84 = 0.0f; + envCtx->unk_88 = 0.0f; + + Environment_UpdateSkybox(SKYBOX_NORMAL_SKY, &this->envCtx, &this->skyboxCtx); + + gSaveContext.buttonStatus[0] = gSaveContext.buttonStatus[1] = gSaveContext.buttonStatus[2] = + gSaveContext.buttonStatus[3] = gSaveContext.buttonStatus[4] = BTN_ENABLED; + + this->n64ddFlags[0] = this->n64ddFlags[1] = this->n64ddFlags[2] = this->defense[0] = this->defense[1] = + this->defense[2] = 0; + + SsSram_ReadWrite(OS_K1_TO_PHYSICAL(0xA8000000), sramCtx->readBuff, SRAM_SIZE, OS_READ); + + gSaveContext.language = sramCtx->readBuff[SRAM_HEADER_LANGUAGE]; + + if (gSaveContext.language > 2) { + sramCtx->readBuff[SRAM_HEADER_LANGUAGE] = gSaveContext.language = 0; + } +} + +void FileChoose_Destroy(GameState* thisx) { +} + +void FileChoose_Init(GameState* thisx) { + FileChooseContext* this = (FileChooseContext*)thisx; + u32 size = (u32)_title_staticSegmentRomEnd - (u32)_title_staticSegmentRomStart; + s32 pad; + + SREG(30) = 1; + osSyncPrintf("SIZE=%x\n", size); + + this->staticSegment = GameState_Alloc(&this->state, size, "../z_file_choose.c", 3392); + ASSERT(this->staticSegment != NULL, "this->staticSegment != NULL", "../z_file_choose.c", 3393); + DmaMgr_SendRequest1(this->staticSegment, (u32)_title_staticSegmentRomStart, size, "../z_file_choose.c", 3394); + + size = (u32)_parameter_staticSegmentRomEnd - (u32)_parameter_staticSegmentRomStart; + this->parameterSegment = GameState_Alloc(&this->state, size, "../z_file_choose.c", 3398); + ASSERT(this->parameterSegment != NULL, "this->parameterSegment != NULL", "../z_file_choose.c", 3399); + DmaMgr_SendRequest1(this->parameterSegment, (u32)_parameter_staticSegmentRomStart, size, "../z_file_choose.c", + 3400); + + Matrix_Init(&this->state); + View_Init(&this->view, this->state.gfxCtx); + this->state.main = FileChoose_Main; + this->state.destroy = FileChoose_Destroy; + FileChoose_InitContext(&this->state); + Font_LoadOrderedFont(&this->font); + Audio_QueueSeqCmd(0xF000000A); + func_800F5E18(0, 0x57, 0, 7, 1); +} diff --git a/src/overlays/gamestates/ovl_file_choose/z_file_copy_erase.c b/src/overlays/gamestates/ovl_file_choose/z_file_copy_erase.c new file mode 100644 index 000000000..5d13c408d --- /dev/null +++ b/src/overlays/gamestates/ovl_file_choose/z_file_copy_erase.c @@ -0,0 +1,1073 @@ +#include "file_choose.h" + +// when choosing a file to copy or erase, the 6 main menu buttons are placed at these offsets +static s16 sChooseFileYOffsets[] = { -48, -48, -48, -24, -24, 0 }; + +static s16 D_8081248C[3][3] = { + { 0, -48, -48 }, + { -64, 16, -48 }, + { -64, -64, 32 }, +}; + +static s16 sEraseDelayTimer = 15; + +/** + * Move buttons into place for the select source screen and fade in the proper labels. + * Update function for `CM_SETUP_COPY_SOURCE` + */ +void FileChoose_SetupCopySource(GameState* thisx) { + FileChooseContext* this = (FileChooseContext*)thisx; + s16 yStep; + s16 i; + + for (i = 0; i < 5; i++) { + yStep = (ABS(this->buttonYOffsets[i] - sChooseFileYOffsets[i])) / this->actionTimer; + + if (this->buttonYOffsets[i] >= sChooseFileYOffsets[i]) { + this->buttonYOffsets[i] -= yStep; + } else { + this->buttonYOffsets[i] += yStep; + } + } + + this->actionButtonAlpha[FS_BTN_ACTION_COPY] -= 25; + this->actionButtonAlpha[FS_BTN_ACTION_ERASE] -= 25; + this->optionButtonAlpha -= 25; + this->confirmButtonAlpha[FS_BTN_CONFIRM_QUIT] += 25; + this->titleAlpha[0] -= 31; + this->titleAlpha[1] += 31; + this->actionTimer--; + + if (this->actionTimer == 0) { + this->actionTimer = 8; + + this->actionButtonAlpha[FS_BTN_ACTION_COPY] = this->actionButtonAlpha[FS_BTN_ACTION_ERASE] = + this->optionButtonAlpha = 0; + + this->confirmButtonAlpha[FS_BTN_CONFIRM_QUIT] = 200; + this->titleLabel = this->nextTitleLabel; + + this->titleAlpha[0] = 255; + this->titleAlpha[1] = 0; + this->buttonIndex = FS_BTN_COPY_QUIT; + this->configMode++; + } +} + +/** + * Allow the player to select a file to copy or exit back to the main menu. + * Update function for `CM_SELECT_COPY_SOURCE` + */ +void FileChoose_SelectCopySource(GameState* thisx) { + FileChooseContext* this = (FileChooseContext*)thisx; + SramContext* sramCtx = &this->sramCtx; + Input* input = &this->state.input[0]; + + if (((this->buttonIndex == FS_BTN_COPY_QUIT) && CHECK_BTN_ANY(input->press.button, BTN_A | BTN_START)) || + CHECK_BTN_ALL(input->press.button, BTN_B)) { + this->actionTimer = 8; + this->buttonIndex = FS_BTN_MAIN_COPY; + this->nextTitleLabel = FS_TITLE_SELECT_FILE; + this->configMode = CM_COPY_RETURN_MAIN; + this->warningLabel = FS_WARNING_NONE; + Audio_PlaySoundGeneral(NA_SE_SY_FSEL_CLOSE, &D_801333D4, 4, &D_801333E0, &D_801333E0, &D_801333E8); + } else if (CHECK_BTN_ANY(input->press.button, BTN_A | BTN_START)) { + if (SLOT_OCCUPIED(sramCtx, this->buttonIndex)) { + this->actionTimer = 8; + this->selectedFileIndex = this->buttonIndex; + this->configMode = CM_SETUP_COPY_DEST_1; + this->nextTitleLabel = FS_TITLE_COPY_TO; + Audio_PlaySoundGeneral(NA_SE_SY_FSEL_DECIDE_L, &D_801333D4, 4, &D_801333E0, &D_801333E0, &D_801333E8); + } else { + Audio_PlaySoundGeneral(NA_SE_SY_FSEL_ERROR, &D_801333D4, 4, &D_801333E0, &D_801333E0, &D_801333E8); + } + } else { + if (ABS(this->stickRelY) >= 30) { + Audio_PlaySoundGeneral(NA_SE_SY_FSEL_CURSOR, &D_801333D4, 4, &D_801333E0, &D_801333E0, &D_801333E8); + + if (this->stickRelY >= 30) { + this->buttonIndex--; + + if (this->buttonIndex < FS_BTN_COPY_FILE_1) { + this->buttonIndex = FS_BTN_COPY_QUIT; + } + } else { + this->buttonIndex++; + + if (this->buttonIndex > FS_BTN_COPY_QUIT) { + this->buttonIndex = FS_BTN_COPY_FILE_1; + } + } + } + + if (this->buttonIndex != FS_BTN_COPY_QUIT) { + if (!SLOT_OCCUPIED(sramCtx, this->buttonIndex)) { + this->warningLabel = FS_WARNING_FILE_EMPTY; + this->warningButtonIndex = this->buttonIndex; + this->emptyFileTextAlpha = 255; + } else { + this->warningLabel = FS_WARNING_NONE; + } + } + } +} + +/** + * Move the menu buttons into place for the copy destination selection and switch titles. + * Update function for `CM_SETUP_COPY_DEST_1` + */ +void FileChoose_SetupCopyDest1(GameState* thisx) { + FileChooseContext* this = (FileChooseContext*)thisx; + s16 yStep; + s16 i; + + for (i = 0; i < 3; i++) { + yStep = ABS(this->buttonYOffsets[i] - D_8081248C[this->buttonIndex][i]) / this->actionTimer; + + if (D_8081248C[this->buttonIndex][i] >= this->buttonYOffsets[i]) { + this->buttonYOffsets[i] += yStep; + } else { + this->buttonYOffsets[i] -= yStep; + } + } + + this->titleAlpha[0] -= 31; + this->titleAlpha[1] += 31; + this->nameBoxAlpha[this->buttonIndex] -= 25; + + this->actionTimer--; + if (this->actionTimer == 0) { + this->buttonYOffsets[this->buttonIndex] = D_8081248C[this->buttonIndex][this->buttonIndex]; + this->titleLabel = this->nextTitleLabel; + this->titleAlpha[0] = 255; + this->titleAlpha[1] = 0; + this->actionTimer = 8; + this->configMode++; + } +} + +/** + * Show the file info of the file selected to copy from. + * Update function for `CM_SETUP_COPY_DEST_2` + */ +void FileChoose_SetupCopyDest2(GameState* thisx) { + FileChooseContext* this = (FileChooseContext*)thisx; + + this->nameBoxAlpha[this->buttonIndex] -= 25; + this->fileInfoAlpha[this->buttonIndex] += 25; + this->actionTimer--; + + if (this->actionTimer == 0) { + this->nameBoxAlpha[this->buttonIndex] = 0; + this->fileInfoAlpha[this->buttonIndex] = 200; + this->buttonIndex = FS_BTN_COPY_QUIT; + this->actionTimer = 8; + this->configMode = CM_SELECT_COPY_DEST; + } +} + +/** + * Allow the player to select a slot to copy to or exit to the copy select screen. + * Update function for `CM_SELECT_COPY_DEST` + */ +void FileChoose_SelectCopyDest(GameState* thisx) { + FileChooseContext* this = (FileChooseContext*)thisx; + SramContext* sramCtx = &this->sramCtx; + Input* input = &this->state.input[0]; + + if (((this->buttonIndex == FS_BTN_COPY_QUIT) && CHECK_BTN_ANY(input->press.button, BTN_A | BTN_START)) || + CHECK_BTN_ALL(input->press.button, BTN_B)) { + this->buttonIndex = this->selectedFileIndex; + this->nextTitleLabel = FS_TITLE_COPY_FROM; + this->actionTimer = 8; + this->configMode = CM_EXIT_TO_COPY_SOURCE_1; + Audio_PlaySoundGeneral(NA_SE_SY_FSEL_CLOSE, &D_801333D4, 4, &D_801333E0, &D_801333E0, &D_801333E8); + } else if (CHECK_BTN_ANY(input->press.button, BTN_A | BTN_START)) { + if (!SLOT_OCCUPIED(sramCtx, this->buttonIndex)) { + this->copyDestFileIndex = this->buttonIndex; + this->nextTitleLabel = FS_TITLE_COPY_CONFIRM; + this->actionTimer = 8; + this->configMode = CM_SETUP_COPY_CONFIRM_1; + Audio_PlaySoundGeneral(NA_SE_SY_FSEL_DECIDE_L, &D_801333D4, 4, &D_801333E0, &D_801333E0, &D_801333E8); + } else { + Audio_PlaySoundGeneral(NA_SE_SY_FSEL_ERROR, &D_801333D4, 4, &D_801333E0, &D_801333E0, &D_801333E8); + } + } else { + + if (ABS(this->stickRelY) >= 30) { + Audio_PlaySoundGeneral(NA_SE_SY_FSEL_CURSOR, &D_801333D4, 4, &D_801333E0, &D_801333E0, &D_801333E8); + + if (this->stickRelY >= 30) { + this->buttonIndex--; + + if ((this->buttonIndex == this->selectedFileIndex)) { + this->buttonIndex--; + + if (this->buttonIndex < FS_BTN_COPY_FILE_1) { + this->buttonIndex = FS_BTN_COPY_QUIT; + } + } else { + if (this->buttonIndex < FS_BTN_COPY_FILE_1) { + this->buttonIndex = FS_BTN_COPY_QUIT; + } + } + } else { + this->buttonIndex++; + + if (this->buttonIndex > FS_BTN_COPY_QUIT) { + this->buttonIndex = FS_BTN_COPY_FILE_1; + } + + if (this->buttonIndex == this->selectedFileIndex) { + this->buttonIndex++; + } + } + } + + if (this->buttonIndex != FS_BTN_COPY_QUIT) { + if (SLOT_OCCUPIED(sramCtx, this->buttonIndex)) { + this->warningLabel = FS_WARNING_FILE_IN_USE; + this->warningButtonIndex = this->buttonIndex; + this->emptyFileTextAlpha = 255; + } else { + this->warningLabel = FS_WARNING_NONE; + } + } + } +} + +/** + * Fade out file info, bring back the name box, and get ready to return to copy source screen. + * Update function for `CM_EXIT_TO_COPY_SOURCE_1` + */ +void FileChoose_ExitToCopySource1(GameState* thisx) { + FileChooseContext* this = (FileChooseContext*)thisx; + + this->fileInfoAlpha[this->buttonIndex] -= 25; + this->nameBoxAlpha[this->buttonIndex] += 25; + this->actionTimer--; + + if (this->actionTimer == 0) { + this->nextTitleLabel = FS_TITLE_COPY_FROM; + this->nameBoxAlpha[this->buttonIndex] = 200; + this->fileInfoAlpha[this->buttonIndex] = 0; + this->actionTimer = 8; + this->configMode++; + } +} + +/** + * Move the buttons back into place and return to copy source select. + * Update function for `CM_EXIT_TO_COPY_SOURCE_2` + */ +void FileChoose_ExitToCopySource2(GameState* thisx) { + FileChooseContext* this = (FileChooseContext*)thisx; + SramContext* sramCtx = &this->sramCtx; + s16 i; + s16 yStep; + + for (i = 0; i < 3; i++) { + yStep = ABS(this->buttonYOffsets[i] - sChooseFileYOffsets[i]) / this->actionTimer; + + if (this->buttonYOffsets[i] >= sChooseFileYOffsets[i]) { + this->buttonYOffsets[i] -= yStep; + } else { + this->buttonYOffsets[i] += yStep; + } + } + + this->titleAlpha[0] -= 31; + this->titleAlpha[1] += 31; + this->actionTimer--; + + if (this->actionTimer == 0) { + this->titleLabel = this->nextTitleLabel; + this->titleAlpha[0] = 255; + this->titleAlpha[1] = 0; + this->buttonIndex = 3; + this->configMode = CM_SELECT_COPY_SOURCE; + } +} + +/** + * Rearrange buttons on the screen to prepare for copy confirmation. + * Update function for `CM_SETUP_COPY_CONFIRM_1` + */ +void FileChoose_SetupCopyConfirm1(GameState* thisx) { + static s16 D_808124A4[] = { -56, -40, -24, 0 }; + FileChooseContext* this = (FileChooseContext*)thisx; + SramContext* sramCtx = &this->sramCtx; + s16 i; + s16 yStep; + + this->titleAlpha[0] -= 31; + this->titleAlpha[1] += 31; + + for (i = 0; i < 3; i++) { + if ((i != this->copyDestFileIndex) && (i != this->selectedFileIndex)) { + this->fileButtonAlpha[i] -= 25; + + if (SLOT_OCCUPIED(sramCtx, i)) { + this->connectorAlpha[i] -= 31; + this->nameBoxAlpha[i] = this->nameAlpha[i] = this->fileButtonAlpha[i]; + } + } else { + if (this->copyDestFileIndex == i) { + yStep = ABS(this->buttonYOffsets[i] - D_808124A4[i]) / this->actionTimer; + this->buttonYOffsets[i] += yStep; + + if (this->buttonYOffsets[i] >= D_808124A4[i]) { + this->buttonYOffsets[i] = D_808124A4[i]; + } + } + } + } + + this->actionTimer--; + + if (this->actionTimer == 0) { + this->titleLabel = this->nextTitleLabel; + this->titleAlpha[0] = 255; + this->titleAlpha[1] = 0; + this->actionTimer = 8; + this->configMode++; + } +} + +/** + * Fade in the 'Yes' button before allowing the player to decide. + * Update function for `CM_SETUP_COPY_CONFIRM_2` + */ +void FileChoose_SetupCopyConfirm2(GameState* thisx) { + FileChooseContext* this = (FileChooseContext*)thisx; + + this->confirmButtonAlpha[FS_BTN_CONFIRM_YES] += 25; + this->actionTimer--; + + if (this->actionTimer == 0) { + this->configMode = CM_COPY_CONFIRM; + this->buttonIndex = FS_BTN_CONFIRM_QUIT; + } +} + +/** + * Allow the player to confirm the copy, or quit back to the destination select. + * If yes is selected, the actual copy occurs in this function before moving on to the animation. + * Update function for `CM_COPY_CONFIRM` + */ +void FileChoose_CopyConfirm(GameState* thisx) { + FileChooseContext* this = (FileChooseContext*)thisx; + SramContext* sramCtx = &this->sramCtx; + Input* input = &this->state.input[0]; + u16 dayTime; + + if (((this->buttonIndex != FS_BTN_CONFIRM_YES) && CHECK_BTN_ANY(input->press.button, BTN_A | BTN_START)) || + CHECK_BTN_ALL(input->press.button, BTN_B)) { + this->actionTimer = 8; + this->nextTitleLabel = FS_TITLE_COPY_TO; + this->configMode = CM_RETURN_TO_COPY_DEST; + Audio_PlaySoundGeneral(NA_SE_SY_FSEL_CLOSE, &D_801333D4, 4, &D_801333E0, &D_801333E0, &D_801333E8); + } else if (CHECK_BTN_ANY(input->press.button, BTN_A | BTN_START)) { + dayTime = gSaveContext.dayTime; + Sram_CopySave(this, sramCtx); + gSaveContext.dayTime = dayTime; + this->fileInfoAlpha[this->copyDestFileIndex] = this->nameAlpha[this->copyDestFileIndex] = 0; + this->nextTitleLabel = FS_TITLE_COPY_COMPLETE; + this->actionTimer = 8; + this->configMode = CM_COPY_ANIM_1; + func_800AA000(300.0f, 0xB4, 0x14, 0x64); + Audio_PlaySoundGeneral(NA_SE_SY_FSEL_DECIDE_L, &D_801333D4, 4, &D_801333E0, &D_801333E0, &D_801333E8); + } else if (ABS(this->stickRelY) >= 30) { + Audio_PlaySoundGeneral(NA_SE_SY_FSEL_CURSOR, &D_801333D4, 4, &D_801333E0, &D_801333E0, &D_801333E8); + this->buttonIndex ^= 1; + } +} + +/** + * Move buttons back in place and return to copy destination select. + * Update function for `CM_RETURN_TO_COPY_DEST` + */ +void FileChoose_ReturnToCopyDest(GameState* thisx) { + FileChooseContext* this = (FileChooseContext*)thisx; + SramContext* sramCtx = &this->sramCtx; + s16 i; + s16 yStep; + + this->titleAlpha[0] -= 31; + this->titleAlpha[1] += 31; + this->confirmButtonAlpha[FS_BTN_CONFIRM_YES] -= 25; + + for (i = 0; i < 3; i++) { + if ((i != this->copyDestFileIndex) && (i != this->selectedFileIndex)) { + this->fileButtonAlpha[i] += 25; + + if (SLOT_OCCUPIED(sramCtx, i)) { + this->nameBoxAlpha[i] = this->nameAlpha[i] = this->fileButtonAlpha[i]; + this->connectorAlpha[i] += 31; + } + } + + yStep = ABS(this->buttonYOffsets[i] - D_8081248C[this->selectedFileIndex][i]) / this->actionTimer; + + if (D_8081248C[this->selectedFileIndex][i] >= this->buttonYOffsets[i]) { + this->buttonYOffsets[i] += yStep; + } else { + this->buttonYOffsets[i] -= yStep; + } + } + + this->actionTimer--; + + if (this->actionTimer == 0) { + this->titleLabel = this->nextTitleLabel; + this->titleAlpha[0] = 255; + this->titleAlpha[1] = 0; + this->actionTimer = 8; + this->buttonIndex = FS_BTN_COPY_QUIT; + this->configMode = CM_SELECT_COPY_DEST; + } +} + +/** + * Hide title + * Update function for `CM_COPY_ANIM_1` + */ +void FileChoose_CopyAnim1(GameState* thisx) { + FileChooseContext* this = (FileChooseContext*)thisx; + + this->titleAlpha[0] -= 31; + this->confirmButtonAlpha[FS_BTN_CONFIRM_YES] -= 25; + this->confirmButtonAlpha[FS_BTN_CONFIRM_QUIT] -= 25; + this->actionTimer--; + + if (this->actionTimer == 0) { + this->titleAlpha[0] = 0; + this->actionTimer = 8; + this->configMode++; + osSyncPrintf("connect_alpha=%d decision_alpha[%d]=%d\n", this->connectorAlpha[this->copyDestFileIndex], + this->copyDestFileIndex, this->fileInfoAlpha[this->copyDestFileIndex]); + } +} + +/** + * Move a copy of the file window down and fade in the file info. + * Update function for `CM_COPY_ANIM_2` + */ +void FileChoose_CopyAnim2(GameState* thisx) { + FileChooseContext* this = (FileChooseContext*)thisx; + s16 yStep; + + this->fileInfoAlpha[this->copyDestFileIndex] += 25; + this->nameAlpha[this->copyDestFileIndex] += 25; + this->titleAlpha[1] += 31; + yStep = ABS(this->fileNamesY[this->copyDestFileIndex] + 56) / this->actionTimer; + this->fileNamesY[this->copyDestFileIndex] -= yStep; + + if (this->fileNamesY[this->copyDestFileIndex] <= -56) { + this->fileNamesY[this->copyDestFileIndex] = -56; + } + + this->actionTimer--; + + if (this->actionTimer == 0) { + this->actionTimer = 90; + this->titleLabel = this->nextTitleLabel; + this->titleAlpha[0] = 255; + this->titleAlpha[1] = 0; + this->configMode++; + } +} + +/** + * Play sound to indicate that the copy has completed. Wait for a timer or for + * the player to press a button before moving on. + * Update function for `CM_COPY_ANIM_3` + */ +void FileChoose_CopyAnim3(GameState* thisx) { + FileChooseContext* this = (FileChooseContext*)thisx; + Input* input = &this->state.input[0]; + + if (this->actionTimer == 75) { + this->connectorAlpha[this->copyDestFileIndex] = 255; + Audio_PlaySoundGeneral(NA_SE_EV_DIAMOND_SWITCH, &D_801333D4, 4, &D_801333E0, &D_801333E0, &D_801333E8); + } + + this->actionTimer--; + + if (this->actionTimer < 74) { + if (CHECK_BTN_ANY(input->press.button, BTN_A | BTN_B | BTN_START) || (this->actionTimer == 0)) { + this->actionTimer = 8; + this->nextTitleLabel = FS_TITLE_SELECT_FILE; + this->configMode++; + Audio_PlaySoundGeneral(NA_SE_SY_FSEL_DECIDE_L, &D_801333D4, 4, &D_801333E0, &D_801333E0, &D_801333E8); + } + } +} + +/** + * Fade out the info boxes for both files and bring in their name boxes. Fade out title. + * Update function for `CM_COPY_ANIM_4` + */ +void FileChoose_CopyAnim4(GameState* thisx) { + FileChooseContext* this = (FileChooseContext*)thisx; + + this->fileInfoAlpha[this->selectedFileIndex] -= 25; + this->fileInfoAlpha[this->copyDestFileIndex] -= 25; + this->nameBoxAlpha[this->selectedFileIndex] += 25; + this->nameBoxAlpha[this->copyDestFileIndex] += 25; + this->titleAlpha[0] -= 31; + this->actionTimer--; + + if (this->actionTimer == 0) { + this->fileNamesY[this->copyDestFileIndex] = this->buttonYOffsets[3] = 0; + this->actionTimer = 8; + this->titleAlpha[0] = 0; + this->configMode++; + } +} + +/** + * Restore all buttons and labels back to their original place and go back to the main menu. + * Update function for `CM_COPY_ANIM_5` + */ +void FileChoose_CopyAnim5(GameState* thisx) { + FileChooseContext* this = (FileChooseContext*)thisx; + SramContext* sramCtx = &this->sramCtx; + s16 i; + s16 yStep; + + for (i = 0; i < 5; i++) { + yStep = ABS(this->buttonYOffsets[i]) / this->actionTimer; + + if (this->buttonYOffsets[i] >= 0) { + this->buttonYOffsets[i] -= yStep; + } else { + this->buttonYOffsets[i] += yStep; + } + } + + for (i = 0; i < 3; i++) { + if (i != this->buttonIndex) { + this->fileButtonAlpha[i] += 25; + + if (SLOT_OCCUPIED(sramCtx, i)) { + this->nameBoxAlpha[i] = this->nameAlpha[i] = this->fileButtonAlpha[i]; + this->connectorAlpha[i] += 31; + } + } + } + + this->actionButtonAlpha[FS_BTN_ACTION_COPY] += 25; + this->actionButtonAlpha[FS_BTN_ACTION_ERASE] += 25; + this->optionButtonAlpha += 25; + this->titleAlpha[1] += 31; + this->actionTimer--; + + if (this->actionTimer == 0) { + for (i = 0; i < 3; i++) { + this->connectorAlpha[i] = 0; + this->fileButtonAlpha[i] = 200; + this->nameBoxAlpha[i] = this->nameAlpha[i] = this->connectorAlpha[i]; + + if (SLOT_OCCUPIED(sramCtx, i)) { + this->connectorAlpha[i] = 255; + this->nameBoxAlpha[i] = this->nameAlpha[i] = this->fileButtonAlpha[i]; + } + } + + this->fileNamesY[this->selectedFileIndex] = 0; + this->highlightColor[3] = 70; + this->highlightPulseDir = 1; + XREG(35) = XREG(36); + this->titleLabel = this->nextTitleLabel; + this->titleAlpha[0] = 255; + this->titleAlpha[1] = 0; + this->configMode = CM_MAIN_MENU; + } +} + +/** + * Exit from the copy source screen to the main menu. Return all buttons and labels to their original place. + * Update function for `CM_COPY_RETURN_MAIN` + */ +void FileChoose_ExitCopyToMain(GameState* thisx) { + FileChooseContext* this = (FileChooseContext*)thisx; + s16 i; + s16 yStep; + + for (i = 0; i < 5; i++) { + yStep = ABS(this->buttonYOffsets[i]) / this->actionTimer; + + if (this->buttonYOffsets[i] >= 0) { + this->buttonYOffsets[i] -= yStep; + } else { + this->buttonYOffsets[i] += yStep; + } + } + + this->actionButtonAlpha[FS_BTN_ACTION_COPY] += 25; + this->confirmButtonAlpha[FS_BTN_CONFIRM_QUIT] -= 25; + this->titleAlpha[0] -= 31; + this->titleAlpha[1] += 31; + this->actionTimer--; + + if (this->actionTimer == 0) { + this->actionButtonAlpha[FS_BTN_ACTION_COPY] = 200; + this->confirmButtonAlpha[FS_BTN_CONFIRM_QUIT] = 0; + this->titleLabel = this->nextTitleLabel; + this->titleAlpha[0] = 255; + this->titleAlpha[1] = 0; + this->configMode = CM_MAIN_MENU; + } + + this->optionButtonAlpha = this->actionButtonAlpha[FS_BTN_ACTION_ERASE] = + this->actionButtonAlpha[FS_BTN_ACTION_COPY]; +} + +/** + * Move buttons into place for the erase select screen and fade in the proper labels. + * Update function for `CM_SETUP_ERASE_SELECT` + */ +void FileChoose_SetupEraseSelect(GameState* thisx) { + FileChooseContext* this = (FileChooseContext*)thisx; + s16 i; + s16 yStep; + + for (i = 0; i < 5; i++) { + yStep = ABS(this->buttonYOffsets[i] - sChooseFileYOffsets[i]) / this->actionTimer; + + if (this->buttonYOffsets[i] >= sChooseFileYOffsets[i]) { + this->buttonYOffsets[i] -= yStep; + } else { + this->buttonYOffsets[i] += yStep; + } + } + + this->actionButtonAlpha[FS_BTN_ACTION_COPY] -= 50; + this->actionButtonAlpha[FS_BTN_ACTION_ERASE] -= 50; + this->optionButtonAlpha -= 50; + this->confirmButtonAlpha[FS_BTN_CONFIRM_QUIT] += 25; + + if (this->actionButtonAlpha[FS_BTN_ACTION_COPY] <= 0) { + this->actionButtonAlpha[FS_BTN_ACTION_COPY] = this->actionButtonAlpha[FS_BTN_ACTION_ERASE] = + this->optionButtonAlpha = 0; + } + + this->titleAlpha[0] -= 31; + this->titleAlpha[1] += 31; + this->actionTimer--; + + if (this->actionTimer == 0) { + this->highlightColor[3] = 70; + this->highlightPulseDir = 1; + XREG(35) = XREG(36); + this->actionButtonAlpha[FS_BTN_ACTION_COPY] = this->actionButtonAlpha[FS_BTN_ACTION_ERASE] = + this->optionButtonAlpha = 0; + this->confirmButtonAlpha[1] = 200; + this->titleLabel = this->nextTitleLabel; + this->titleAlpha[0] = 255; + this->titleAlpha[1] = 0; + this->buttonIndex = FS_BTN_ERASE_QUIT; + this->configMode++; + } +} + +/** + * Allow the player to select a file to erase or exit back to the main menu. + * Update function for `CM_ERASE_SELECT` + */ +void FileChoose_EraseSelect(GameState* thisx) { + FileChooseContext* this = (FileChooseContext*)thisx; + SramContext* sramCtx = &this->sramCtx; + Input* input = &this->state.input[0]; + + if (((this->buttonIndex == FS_BTN_COPY_QUIT) && CHECK_BTN_ANY(input->press.button, BTN_A | BTN_START)) || + CHECK_BTN_ALL(input->press.button, BTN_B)) { + this->buttonIndex = FS_BTN_MAIN_ERASE; + this->actionTimer = 8; + this->nextTitleLabel = FS_TITLE_SELECT_FILE; + this->configMode = CM_EXIT_ERASE_TO_MAIN; + this->warningLabel = FS_WARNING_NONE; + Audio_PlaySoundGeneral(NA_SE_SY_FSEL_CLOSE, &D_801333D4, 4, &D_801333E0, &D_801333E0, &D_801333E8); + } else if (CHECK_BTN_ANY(input->press.button, BTN_A | BTN_START)) { + if (SLOT_OCCUPIED(sramCtx, this->buttonIndex)) { + this->actionTimer = 8; + this->selectedFileIndex = this->buttonIndex; + this->configMode = CM_SETUP_ERASE_CONFIRM_1; + this->nextTitleLabel = FS_TITLE_ERASE_CONFIRM; + Audio_PlaySoundGeneral(NA_SE_SY_FSEL_DECIDE_L, &D_801333D4, 4, &D_801333E0, &D_801333E0, &D_801333E8); + } else { + Audio_PlaySoundGeneral(NA_SE_SY_FSEL_ERROR, &D_801333D4, 4, &D_801333E0, &D_801333E0, &D_801333E8); + } + } else { + if (ABS(this->stickRelY) >= 30) { + Audio_PlaySoundGeneral(NA_SE_SY_FSEL_CURSOR, &D_801333D4, 4, &D_801333E0, &D_801333E0, &D_801333E8); + + if (this->stickRelY >= 30) { + this->buttonIndex--; + if (this->buttonIndex < FS_BTN_ERASE_FILE_1) { + this->buttonIndex = FS_BTN_ERASE_QUIT; + } + } else { + this->buttonIndex++; + if (this->buttonIndex > FS_BTN_ERASE_QUIT) { + this->buttonIndex = FS_BTN_ERASE_FILE_1; + } + } + } + + if (this->buttonIndex != FS_BTN_ERASE_QUIT) { + if (!SLOT_OCCUPIED(sramCtx, this->buttonIndex)) { + this->warningLabel = FS_WARNING_FILE_EMPTY; + this->warningButtonIndex = this->buttonIndex; + this->emptyFileTextAlpha = 255; + } else { + this->warningLabel = FS_WARNING_NONE; + } + } else { + this->warningLabel = FS_WARNING_NONE; + } + } +} + +/** + * ... + * Update function for `CM_SETUP_ERASE_CONFIRM_1` + */ +void FileChoose_SetupEraseConfirm1(GameState* thisx) { + static s16 D_808124AC[] = { 0, 16, 32 }; + FileChooseContext* this = (FileChooseContext*)thisx; + SramContext* sramCtx = &this->sramCtx; + s16 i; + s16 yStep; + + for (i = 0; i < 3; i++) { + if (i != this->buttonIndex) { + this->fileButtonAlpha[i] -= 25; + + if (SLOT_OCCUPIED(sramCtx, i)) { + this->connectorAlpha[i] -= 31; + this->nameBoxAlpha[i] = this->nameAlpha[i] = this->fileButtonAlpha[i]; + } + } else { + this->nameBoxAlpha[i] -= 25; + } + } + this->titleAlpha[0] -= 15; + this->titleAlpha[1] += 15; + + yStep = ABS(this->buttonYOffsets[this->buttonIndex] - D_808124AC[this->buttonIndex]) / this->actionTimer; + + if (this->buttonYOffsets[this->buttonIndex] >= D_808124AC[this->buttonIndex]) { + this->buttonYOffsets[this->buttonIndex] -= yStep; + } else { + this->buttonYOffsets[this->buttonIndex] += yStep; + } + + this->actionTimer--; + + if (this->actionTimer == 0) { + for (i = 0; i < 3; i++) { + if (i != this->buttonIndex) { + this->fileButtonAlpha[i] = 0; + + if (SLOT_OCCUPIED(sramCtx, i)) { + this->connectorAlpha[i] = 0; + this->nameBoxAlpha[i] = this->nameAlpha[i] = this->fileButtonAlpha[i] = 0; + } + } else { + this->nameBoxAlpha[i] = 0; + } + } + + this->buttonYOffsets[this->buttonIndex] = D_808124AC[this->buttonIndex]; + this->actionTimer = 8; + this->configMode++; + } +} + +/** + * Show the file info of the file selected to erase. + * Update function for `CM_SETUP_ERASE_CONFIRM_2` + */ +void FileChoose_SetupEraseConfirm2(GameState* thisx) { + FileChooseContext* this = (FileChooseContext*)thisx; + + this->confirmButtonAlpha[FS_BTN_CONFIRM_YES] += 25; + this->titleAlpha[0] -= 15; + this->titleAlpha[1] += 15; + this->fileInfoAlpha[this->buttonIndex] += 25; + this->actionTimer--; + + if (this->actionTimer == 0) { + this->actionTimer = 8; + this->titleLabel = this->nextTitleLabel; + this->fileInfoAlpha[this->buttonIndex] = this->titleAlpha[0] = 255; + this->titleAlpha[1] = 0; + this->confirmButtonAlpha[FS_BTN_CONFIRM_YES] = 200; + this->buttonIndex = FS_BTN_ERASE_FILE_2; + this->configMode = CM_ERASE_CONFIRM; + } +} + +/** + * Allow the player to confirm their chioce to erase or return back to erase select. + * Update function for `CM_ERASE_CONFIRM` + */ +void FileChoose_EraseConfirm(GameState* thisx) { + FileChooseContext* this = (FileChooseContext*)thisx; + Input* input = &this->state.input[0]; + + if (((this->buttonIndex != FS_BTN_CONFIRM_YES) && CHECK_BTN_ANY(input->press.button, BTN_A | BTN_START)) || + CHECK_BTN_ALL(input->press.button, BTN_B)) { + this->buttonIndex = this->selectedFileIndex; + this->nextTitleLabel = FS_TITLE_ERASE_FILE; + this->configMode = CM_EXIT_TO_ERASE_SELECT_1; + this->actionTimer = 8; + Audio_PlaySoundGeneral(NA_SE_SY_FSEL_CLOSE, &D_801333D4, 4, &D_801333E0, &D_801333E0, &D_801333E8); + } else if (CHECK_BTN_ANY(input->press.button, BTN_A | BTN_START)) { + this->n64ddFlags[this->selectedFileIndex] = this->connectorAlpha[this->selectedFileIndex] = 0; + Audio_PlaySoundGeneral(NA_SE_EV_DIAMOND_SWITCH, &D_801333D4, 4, &D_801333E0, &D_801333E0, &D_801333E8); + this->actionTimer = 8; + this->configMode = CM_ERASE_ANIM_1; + this->nextTitleLabel = FS_TITLE_ERASE_COMPLETE; + func_800AA000(200.0f, 0xFF, 0x14, 0x96); + sEraseDelayTimer = 15; + } else if (ABS(this->stickRelY) >= 30) { + Audio_PlaySoundGeneral(NA_SE_SY_FSEL_CURSOR, &D_801333D4, 4, &D_801333E0, &D_801333E0, &D_801333E8); + this->buttonIndex ^= 1; + } +} + +/** + * Fade out file info, bring back the name box, and get ready to return to erase select screen. + * Update function for `CM_EXIT_TO_ERASE_SELECT_1` + */ +void FileChoose_ExitToEraseSelect1(GameState* thisx) { + FileChooseContext* this = (FileChooseContext*)thisx; + + this->fileInfoAlpha[this->buttonIndex] -= 25; + this->nameBoxAlpha[this->buttonIndex] += 25; + this->confirmButtonAlpha[FS_BTN_CONFIRM_YES] -= 25; + this->actionTimer--; + + if (this->actionTimer == 0) { + this->actionTimer = 8; + this->fileInfoAlpha[this->buttonIndex] = 0; + this->configMode++; + } +} + +/** + * Move the buttons back into place and return to erase select. + * Update function for `CM_EXIT_TO_ERASE_SELECT_2` + */ +void FileChoose_ExitToEraseSelect2(GameState* thisx) { + FileChooseContext* this = (FileChooseContext*)thisx; + SramContext* sramCtx = &this->sramCtx; + s16 i; + s16 yStep; + + yStep = ABS(this->buttonYOffsets[this->buttonIndex] - sChooseFileYOffsets[this->buttonIndex]) / this->actionTimer; + + if (this->buttonYOffsets[this->buttonIndex] >= sChooseFileYOffsets[this->buttonIndex]) { + this->buttonYOffsets[this->buttonIndex] -= yStep; + } else { + this->buttonYOffsets[this->buttonIndex] += yStep; + } + + for (i = 0; i < 3; i++) { + if (i != this->buttonIndex) { + this->fileButtonAlpha[i] += 25; + + if (SLOT_OCCUPIED(sramCtx, i)) { + this->nameBoxAlpha[i] = this->nameAlpha[i] = this->fileButtonAlpha[i]; + this->connectorAlpha[i] += 31; + } + } + } + + this->titleAlpha[0] -= 31; + this->titleAlpha[1] += 31; + this->actionTimer--; + + if (this->actionTimer == 0) { + this->buttonYOffsets[this->buttonIndex] = sChooseFileYOffsets[this->buttonIndex]; + this->actionTimer = 8; + this->buttonIndex = FS_BTN_ERASE_QUIT; + this->titleLabel = this->nextTitleLabel; + this->titleAlpha[0] = 255; + this->titleAlpha[1] = 0; + this->configMode = CM_ERASE_SELECT; + } +} + +/** + * Wait for an initial delay, then start fading out the selected file. + * The actual file deletion occurs in this function + * Update function for `CM_ERASE_ANIM_1` + */ +void FileChoose_EraseAnim1(GameState* thisx) { + static s16 D_80813800; + FileChooseContext* this = (FileChooseContext*)thisx; + SramContext* sramCtx = &this->sramCtx; + + if (sEraseDelayTimer == 0) { + if (this->actionTimer == 8) { + D_80813800 = 1; + } + + if (this->actionTimer != 0) { + this->titleAlpha[0] -= 31; + this->titleAlpha[1] += 31; + this->fileInfoAlpha[this->selectedFileIndex] -= 25; + this->confirmButtonAlpha[FS_BTN_CONFIRM_YES] -= 25; + this->confirmButtonAlpha[FS_BTN_CONFIRM_QUIT] -= 25; + } + + this->fileNamesY[this->selectedFileIndex] -= D_80813800; + this->actionTimer--; + D_80813800 += 2; + + if (this->actionTimer == 0) { + Sram_EraseSave(this, sramCtx); + this->titleLabel = this->nextTitleLabel; + this->titleAlpha[0] = 255; + this->titleAlpha[1] = this->connectorAlpha[this->selectedFileIndex] = 0; + + // probably a fake match, there should be a better chained assignment + this->confirmButtonAlpha[0] = this->confirmButtonAlpha[1] = 0; + if (1) {} + this->fileInfoAlpha[this->selectedFileIndex] = this->nameBoxAlpha[this->selectedFileIndex] = + this->confirmButtonAlpha[1]; + + this->configMode++; + this->actionTimer = 90; + } + } else { + sEraseDelayTimer--; + + if (sEraseDelayTimer == 0) { + Audio_PlaySoundGeneral(NA_SE_OC_ABYSS, &D_801333D4, 4, &D_801333E0, &D_801333E0, &D_801333E8); + } + } +} + +/** + * Wait for a delay timer or for the palyer to press a button before returning to the main menu. + * Update function for `CM_ERASE_ANIM_2` + */ +void FileChoose_EraseAnim2(GameState* thisx) { + FileChooseContext* this = (FileChooseContext*)thisx; + Input* input = &this->state.input[0]; + + if (CHECK_BTN_ANY(input->press.button, BTN_A | BTN_B | BTN_START) || (--this->actionTimer == 0)) { + this->buttonYOffsets[3] = 0; + this->actionTimer = 8; + this->nextTitleLabel = FS_TITLE_SELECT_FILE; + this->configMode++; + Audio_PlaySoundGeneral(NA_SE_SY_FSEL_CLOSE, &D_801333D4, 4, &D_801333E0, &D_801333E0, &D_801333E8); + } +} + +/** + * Exit from the erase animation to the main menu. Return all buttons and labels to their original place. + * Update function for `CM_ERASE_ANIM_3` + */ +void FileChoose_EraseAnim3(GameState* thisx) { + FileChooseContext* this = (FileChooseContext*)thisx; + SramContext* sramCtx = &this->sramCtx; + s16 i; + s16 yStep; + + for (i = 0; i < 5; i++) { + yStep = ABS(this->buttonYOffsets[i]) / this->actionTimer; + + if (this->buttonYOffsets[i] >= 0) { + this->buttonYOffsets[i] -= yStep; + } else { + this->buttonYOffsets[i] += yStep; + } + } + + for (i = 0; i < 3; i++) { + this->fileButtonAlpha[i] += 25; + + if (SLOT_OCCUPIED(sramCtx, i)) { + this->nameBoxAlpha[i] = this->nameAlpha[i] = this->fileButtonAlpha[i]; + this->connectorAlpha[i] += 31; + } + } + + if (this->fileButtonAlpha[this->selectedFileIndex] >= 200) { + this->fileButtonAlpha[this->selectedFileIndex] = 200; + } + + this->titleAlpha[0] -= 31; + this->titleAlpha[1] += 31; + this->actionTimer--; + + if (this->actionTimer == 0) { + this->fileNamesY[this->selectedFileIndex] = 0; + this->highlightColor[3] = 70; + this->highlightPulseDir = 1; + XREG(35) = XREG(36); + this->actionButtonAlpha[FS_BTN_ACTION_COPY] = 200; + this->confirmButtonAlpha[0] = this->confirmButtonAlpha[1] = 0; + this->titleLabel = this->nextTitleLabel; + this->titleAlpha[0] = 255; + this->titleAlpha[1] = 0; + this->configMode = CM_MAIN_MENU; + } + + this->optionButtonAlpha = this->actionButtonAlpha[FS_BTN_ACTION_ERASE] = + this->actionButtonAlpha[FS_BTN_ACTION_COPY]; +} + +/** + * Exit from the erase select screen to the main menu. Return all buttons and labels to their original place. + * Update function for `CM_EXIT_ERASE_TO_MAIN` + */ +void FileChoose_ExitEraseToMain(GameState* thisx) { + FileChooseContext* this = (FileChooseContext*)thisx; + s16 i; + s16 yStep; + + for (i = 0; i < 5; i++) { + yStep = ABS(this->buttonYOffsets[i]) / this->actionTimer; + + if (this->buttonYOffsets[i] >= 0) { + this->buttonYOffsets[i] -= yStep; + } else { + this->buttonYOffsets[i] += yStep; + } + } + + this->actionButtonAlpha[FS_BTN_ACTION_COPY] += 25; + this->actionButtonAlpha[FS_BTN_ACTION_ERASE] += 25; + this->optionButtonAlpha += 25; + this->confirmButtonAlpha[FS_BTN_CONFIRM_QUIT] -= 50; + + if (this->confirmButtonAlpha[FS_BTN_CONFIRM_QUIT] <= 0) { + this->confirmButtonAlpha[FS_BTN_CONFIRM_QUIT] = 0; + } + + this->titleAlpha[0] -= 31; + this->titleAlpha[1] += 31; + this->actionTimer--; + + if (this->actionTimer == 0) { + this->highlightColor[3] = 70; + this->highlightPulseDir = 1; + XREG(35) = XREG(36); + this->actionButtonAlpha[FS_BTN_ACTION_COPY] = 200; + this->confirmButtonAlpha[FS_BTN_CONFIRM_QUIT] = 0; + this->titleLabel = this->nextTitleLabel; + this->titleAlpha[0] = 255; + this->titleAlpha[1] = 0; + this->configMode = CM_MAIN_MENU; + } + + this->optionButtonAlpha = this->actionButtonAlpha[FS_BTN_ACTION_ERASE] = + this->actionButtonAlpha[FS_BTN_ACTION_COPY]; +} diff --git a/src/overlays/gamestates/ovl_file_choose/z_file_nameset_PAL.c b/src/overlays/gamestates/ovl_file_choose/z_file_nameset_PAL.c index 6e4c70f49..6eea5f23e 100644 --- a/src/overlays/gamestates/ovl_file_choose/z_file_nameset_PAL.c +++ b/src/overlays/gamestates/ovl_file_choose/z_file_nameset_PAL.c @@ -1,105 +1,991 @@ -#pragma GLOBAL_ASM("asm/non_matchings/overlays/gamestates/ovl_file_choose/func_80803D40.s") +#include "file_choose.h" +#include "textures/title_static/title_static.h" +#include "assets/overlays/ovl_File_Choose/ovl_file_choose.h" -#pragma GLOBAL_ASM("asm/non_matchings/overlays/gamestates/ovl_file_choose/func_80803ED8.s") - -#pragma GLOBAL_ASM("asm/non_matchings/overlays/gamestates/ovl_file_choose/func_80804248.s") - -#pragma GLOBAL_ASM("asm/non_matchings/overlays/gamestates/ovl_file_choose/func_808043D8.s") - -#pragma GLOBAL_ASM("asm/non_matchings/overlays/gamestates/ovl_file_choose/func_808044A0.s") - -#pragma GLOBAL_ASM("asm/non_matchings/overlays/gamestates/ovl_file_choose/func_80804858.s") - -#pragma GLOBAL_ASM("asm/non_matchings/overlays/gamestates/ovl_file_choose/func_80804924.s") - -#pragma GLOBAL_ASM("asm/non_matchings/overlays/gamestates/ovl_file_choose/func_80804A50.s") - -#pragma GLOBAL_ASM("asm/non_matchings/overlays/gamestates/ovl_file_choose/func_80804C74.s") - -#pragma GLOBAL_ASM("asm/non_matchings/overlays/gamestates/ovl_file_choose/func_80804CD0.s") - -#pragma GLOBAL_ASM("asm/non_matchings/overlays/gamestates/ovl_file_choose/func_80804ED8.s") - -#pragma GLOBAL_ASM("asm/non_matchings/overlays/gamestates/ovl_file_choose/func_8080510C.s") - -#pragma GLOBAL_ASM("asm/non_matchings/overlays/gamestates/ovl_file_choose/func_808051C8.s") - -#pragma GLOBAL_ASM("asm/non_matchings/overlays/gamestates/ovl_file_choose/func_80805318.s") - -#pragma GLOBAL_ASM("asm/non_matchings/overlays/gamestates/ovl_file_choose/func_80805434.s") - -#pragma GLOBAL_ASM("asm/non_matchings/overlays/gamestates/ovl_file_choose/func_80805524.s") - -#pragma GLOBAL_ASM("asm/non_matchings/overlays/gamestates/ovl_file_choose/func_80805824.s") - -#pragma GLOBAL_ASM("asm/non_matchings/overlays/gamestates/ovl_file_choose/func_8080595C.s") - -#pragma GLOBAL_ASM("asm/non_matchings/overlays/gamestates/ovl_file_choose/func_80805B2C.s") - -#pragma GLOBAL_ASM("asm/non_matchings/overlays/gamestates/ovl_file_choose/func_80805EB8.s") - -#pragma GLOBAL_ASM("asm/non_matchings/overlays/gamestates/ovl_file_choose/func_80806180.s") - -#pragma GLOBAL_ASM("asm/non_matchings/overlays/gamestates/ovl_file_choose/func_8080625C.s") - -#pragma GLOBAL_ASM("asm/non_matchings/overlays/gamestates/ovl_file_choose/func_80806444.s") - -#pragma GLOBAL_ASM("asm/non_matchings/overlays/gamestates/ovl_file_choose/func_808064F4.s") - -#pragma GLOBAL_ASM("asm/non_matchings/overlays/gamestates/ovl_file_choose/func_80806710.s") - -#pragma GLOBAL_ASM("asm/non_matchings/overlays/gamestates/ovl_file_choose/func_808068F0.s") - -#pragma GLOBAL_ASM("asm/non_matchings/overlays/gamestates/ovl_file_choose/func_808069B4.s") - -#pragma GLOBAL_ASM("asm/non_matchings/overlays/gamestates/ovl_file_choose/func_80806C20.s") - -#pragma GLOBAL_ASM("asm/non_matchings/overlays/gamestates/ovl_file_choose/func_80806DB0.s") - -#pragma GLOBAL_ASM("asm/non_matchings/overlays/gamestates/ovl_file_choose/func_80806F34.s") - -#pragma GLOBAL_ASM("asm/non_matchings/overlays/gamestates/ovl_file_choose/func_8080723C.s") - -#pragma GLOBAL_ASM("asm/non_matchings/overlays/gamestates/ovl_file_choose/func_80807DCC.s") - -#pragma GLOBAL_ASM("asm/non_matchings/overlays/gamestates/ovl_file_choose/func_80808000.s") - -#pragma GLOBAL_ASM("asm/non_matchings/overlays/gamestates/ovl_file_choose/func_80808F84.s") - -#pragma GLOBAL_ASM("asm/non_matchings/overlays/gamestates/ovl_file_choose/func_80809038.s") - -#pragma GLOBAL_ASM("asm/non_matchings/overlays/gamestates/ovl_file_choose/func_8080960C.s") - -#pragma GLOBAL_ASM("asm/non_matchings/overlays/gamestates/ovl_file_choose/func_8080969C.s") - -#pragma GLOBAL_ASM("asm/non_matchings/overlays/gamestates/ovl_file_choose/func_808099C8.s") - -#pragma GLOBAL_ASM("asm/non_matchings/overlays/gamestates/ovl_file_choose/func_8080AF30.s") - -#pragma GLOBAL_ASM("asm/non_matchings/overlays/gamestates/ovl_file_choose/func_8080AF50.s") - -#pragma GLOBAL_ASM("asm/non_matchings/overlays/gamestates/ovl_file_choose/func_8080AFD0.s") - -#pragma GLOBAL_ASM("asm/non_matchings/overlays/gamestates/ovl_file_choose/func_8080B1A8.s") - -#pragma GLOBAL_ASM("asm/non_matchings/overlays/gamestates/ovl_file_choose/func_8080B22C.s") - -#pragma GLOBAL_ASM("asm/non_matchings/overlays/gamestates/ovl_file_choose/func_8080B394.s") - -#pragma GLOBAL_ASM("asm/non_matchings/overlays/gamestates/ovl_file_choose/func_8080B40C.s") - -#pragma GLOBAL_ASM("asm/non_matchings/overlays/gamestates/ovl_file_choose/func_8080B494.s") - -#pragma GLOBAL_ASM("asm/non_matchings/overlays/gamestates/ovl_file_choose/func_8080B52C.s") - -#pragma GLOBAL_ASM("asm/non_matchings/overlays/gamestates/ovl_file_choose/func_8080BE30.s") - -#pragma GLOBAL_ASM("asm/non_matchings/overlays/gamestates/ovl_file_choose/func_8080BE84.s") - -#pragma GLOBAL_ASM("asm/non_matchings/overlays/gamestates/ovl_file_choose/func_8080BEF8.s") - -#pragma GLOBAL_ASM("asm/non_matchings/overlays/gamestates/ovl_file_choose/func_8080BF6C.s") - -#pragma GLOBAL_ASM("asm/non_matchings/overlays/gamestates/ovl_file_choose/func_8080BFE4.s") - -#pragma GLOBAL_ASM("asm/non_matchings/overlays/gamestates/ovl_file_choose/func_8080C2F4.s") +static s16 D_808124C0[] = { + 0x0002, 0x0003, 0x0002, 0x0002, 0x0002, 0x0002, 0x0002, 0x0002, 0x0002, 0x0002, 0x0001, 0x0002, 0x0000, 0x0001, + 0x0001, 0x0002, 0x0001, 0x0001, 0x0004, 0x0002, 0x0002, 0x0002, 0x0001, 0x0001, 0x0000, 0x0002, 0x0000, 0x0001, + 0x0001, 0x0001, 0x0001, 0x0001, 0x0000, 0x0001, 0x0001, 0x0001, 0x0002, 0x0002, 0x0002, 0x0002, 0x0002, 0x0003, + 0x0002, 0x0002, 0x0004, 0x0003, 0x0002, 0x0004, 0x0001, 0x0002, 0x0002, 0x0001, 0x0001, 0x0002, 0x0002, 0x0003, + 0x0002, 0x0002, 0x0000, 0x0002, 0x0002, 0x0002, 0x0000, 0x0003, 0x0001, 0x0000, +}; + +static s16 D_80812544[] = { + 0x0001, 0x0002, 0x0000, 0x0001, 0x0001, 0x0002, 0x0001, 0x0001, 0x0004, 0x0002, 0x0002, 0x0002, 0x0001, + 0x0001, 0x0000, 0x0002, 0x0000, 0x0001, 0x0001, 0x0001, 0x0001, 0x0001, 0x0000, 0x0001, 0x0001, 0x0001, + 0x0002, 0x0002, 0x0002, 0x0002, 0x0002, 0x0003, 0x0002, 0x0002, 0x0004, 0x0003, 0x0002, 0x0004, 0x0001, + 0x0002, 0x0002, 0x0001, 0x0001, 0x0002, 0x0002, 0x0003, 0x0002, 0x0002, 0x0000, 0x0002, 0x0002, 0x0002, + 0x0003, 0x0002, 0x0002, 0x0002, 0x0002, 0x0002, 0x0002, 0x0002, 0x0002, 0x0002, 0x0001, 0x0003, +}; + +void FileChoose_DrawCharacter(GraphicsContext* gfxCtx, void* texture, s16 vtx) { + OPEN_DISPS(gfxCtx, "../z_file_nameset_PAL.c", 110); + + gDPLoadTextureBlock_4b(POLY_OPA_DISP++, texture, G_IM_FMT_I, 16, 16, 0, G_TX_NOMIRROR | G_TX_CLAMP, + G_TX_NOMIRROR | G_TX_CLAMP, G_TX_NOMASK, G_TX_NOMASK, G_TX_NOLOD, G_TX_NOLOD); + gSP1Quadrangle(POLY_OPA_DISP++, vtx, vtx + 2, vtx + 3, vtx + 1, 0); + + CLOSE_DISPS(gfxCtx, "../z_file_nameset_PAL.c", 119); +} + +void FileChoose_SetKeyboardVtx(GameState* thisx) { + FileChooseContext* this = (FileChooseContext*)thisx; + s16 val; + s16 phi_t2; + s16 phi_t0; + s16 phi_t3; + s16 phi_s1; + s16 phi_t1; + s16 phi_s2; + + this->keyboardVtx = Graph_Alloc(this->state.gfxCtx, sizeof(Vtx) * 4 * 5 * 13); + + phi_s1 = 0x26; + + for (phi_t2 = 0, phi_s2 = 0, phi_t3 = 0; phi_s2 < 5; phi_s2++) { + phi_t0 = -0x60; + + for (phi_t1 = 0; phi_t1 < 13; phi_t1++, phi_t3 += 4, phi_t2++) { + this->keyboardVtx[phi_t3].v.ob[0] = this->keyboardVtx[phi_t3 + 2].v.ob[0] = D_80812544[phi_t2] + phi_t0; + + this->keyboardVtx[phi_t3 + 1].v.ob[0] = this->keyboardVtx[phi_t3 + 3].v.ob[0] = + D_80812544[phi_t2] + phi_t0 + 12; + + this->keyboardVtx[phi_t3].v.ob[1] = this->keyboardVtx[phi_t3 + 1].v.ob[1] = phi_s1; + + this->keyboardVtx[phi_t3 + 2].v.ob[1] = this->keyboardVtx[phi_t3 + 3].v.ob[1] = phi_s1 - 12; + + this->keyboardVtx[phi_t3].v.ob[2] = this->keyboardVtx[phi_t3 + 1].v.ob[2] = + this->keyboardVtx[phi_t3 + 2].v.ob[2] = this->keyboardVtx[phi_t3 + 3].v.ob[2] = 0; + + this->keyboardVtx[phi_t3].v.flag = this->keyboardVtx[phi_t3 + 1].v.flag = + this->keyboardVtx[phi_t3 + 2].v.flag = this->keyboardVtx[phi_t3 + 3].v.flag = 0; + + this->keyboardVtx[phi_t3].v.tc[0] = this->keyboardVtx[phi_t3].v.tc[1] = + this->keyboardVtx[phi_t3 + 1].v.tc[1] = this->keyboardVtx[phi_t3 + 2].v.tc[0] = 0; + + this->keyboardVtx[phi_t3 + 1].v.tc[0] = this->keyboardVtx[phi_t3 + 2].v.tc[1] = + this->keyboardVtx[phi_t3 + 3].v.tc[0] = this->keyboardVtx[phi_t3 + 3].v.tc[1] = 0x200; + + this->keyboardVtx[phi_t3].v.cn[0] = this->keyboardVtx[phi_t3 + 1].v.cn[0] = + this->keyboardVtx[phi_t3 + 2].v.cn[0] = this->keyboardVtx[phi_t3 + 3].v.cn[0] = + this->keyboardVtx[phi_t3].v.cn[1] = this->keyboardVtx[phi_t3 + 1].v.cn[1] = + this->keyboardVtx[phi_t3 + 2].v.cn[1] = this->keyboardVtx[phi_t3 + 3].v.cn[1] = + this->keyboardVtx[phi_t3].v.cn[2] = this->keyboardVtx[phi_t3 + 1].v.cn[2] = + this->keyboardVtx[phi_t3 + 2].v.cn[2] = this->keyboardVtx[phi_t3 + 3].v.cn[2] = + this->keyboardVtx[phi_t3].v.cn[3] = this->keyboardVtx[phi_t3 + 1].v.cn[3] = + this->keyboardVtx[phi_t3 + 2].v.cn[3] = this->keyboardVtx[phi_t3 + 3].v.cn[3] = + 255; + + phi_t0 += 0x10; + } + + phi_s1 -= 0x10; + } +} + +static void* sNameLabelTextures[] = { gFileSelNameENGTex, gFileSelNameENGTex, gFileSelNameFRATex }; + +static void* sBackspaceEndTextures[][2] = { + { gFileSelBackspaceButtonTex, gFileSelENDButtonENGTex }, + { gFileSelBackspaceButtonTex, gFileSelENDButtonGERTex }, + { gFileSelBackspaceButtonTex, gFileSelENDButtonFRATex }, +}; + +static u16 sBackspaceEndWidths[] = { 28, 44 }; + +static s16 D_808125EC[] = { + 0xFFE2, 0xFFF0, 0xFFFA, 0x0004, 0x000E, 0x0018, 0x0022, 0x002C, 0x0036, 0xFFF0, 0xFFF0, +}; + +static s16 D_80812604[] = { + 0x0048, 0x0045, 0x0045, 0x0045, 0x0045, 0x0045, 0x0045, 0x0045, 0x0045, 0x0045, 0x0045, +}; + +/** + * Set vertices used by all elements of the name entry screen that are NOT the keyboard. + * This includes the cursor highlight, the name entry plate and characters, and the buttons. + */ +void FileChoose_SetNameEntryVtx(GameState* thisx) { + FileChooseContext* this = (FileChooseContext*)thisx; + Font* font = &this->font; + s16 phi_s0; + s16 phi_t1; + u8 temp; + s16 phi_v0; + + if (1) {} + if (1) {} + + OPEN_DISPS(this->state.gfxCtx, "../z_file_nameset_PAL.c", 205); + + gDPPipeSync(POLY_OPA_DISP++); + gDPSetCombineLERP(POLY_OPA_DISP++, PRIMITIVE, ENVIRONMENT, TEXEL0, ENVIRONMENT, TEXEL0, 0, PRIMITIVE, 0, PRIMITIVE, + ENVIRONMENT, TEXEL0, ENVIRONMENT, TEXEL0, 0, PRIMITIVE, 0); + gDPSetPrimColor(POLY_OPA_DISP++, 0, 0, 255, 255, 255, this->titleAlpha[0]); + gDPSetEnvColor(POLY_OPA_DISP++, 0, 0, 0, 0); + gSPVertex(POLY_OPA_DISP++, D_80811BB0, 24, 0); + gDPLoadTextureBlock(POLY_OPA_DISP++, sNameLabelTextures[gSaveContext.language], G_IM_FMT_IA, G_IM_SIZ_8b, 56, 16, 0, + G_TX_NOMIRROR | G_TX_WRAP, G_TX_NOMIRROR | G_TX_WRAP, G_TX_NOMASK, G_TX_NOMASK, G_TX_NOLOD, + G_TX_NOLOD); + gSP1Quadrangle(POLY_OPA_DISP++, 0, 2, 3, 1, 0); + gDPPipeSync(POLY_OPA_DISP++); + + phi_s0 = 0x10; + for (phi_t1 = 0; phi_t1 < 2; phi_t1++, phi_s0 += 4) { + gDPSetPrimColor(POLY_OPA_DISP++, 0, 0, this->windowColor[0], this->windowColor[1], this->windowColor[2], 255); + gDPSetEnvColor(POLY_OPA_DISP++, 0, 0, 0, 0); + gDPLoadTextureBlock(POLY_OPA_DISP++, sBackspaceEndTextures[gSaveContext.language][phi_t1], G_IM_FMT_IA, + G_IM_SIZ_16b, sBackspaceEndWidths[phi_t1], 16, 0, G_TX_NOMIRROR | G_TX_WRAP, + G_TX_NOMIRROR | G_TX_WRAP, G_TX_NOMASK, G_TX_NOMASK, G_TX_NOLOD, G_TX_NOLOD); + gSP1Quadrangle(POLY_OPA_DISP++, phi_s0, phi_s0 + 2, phi_s0 + 3, phi_s0 + 1, 0); + } + + this->nameEntryVtx = Graph_Alloc(this->state.gfxCtx, 44 * sizeof(Vtx)); + + for (phi_s0 = 0, phi_t1 = 0; phi_t1 < 44; phi_t1 += 4, phi_s0++) { + if ((phi_s0 > 0) && (phi_s0 < 9)) { + temp = this->fileNames[this->buttonIndex][phi_s0 - 1]; + + this->nameEntryVtx[phi_t1].v.ob[0] = this->nameEntryVtx[phi_t1 + 2].v.ob[0] = + D_808125EC[phi_s0] + this->nameEntryBoxPosX + D_808124C0[temp]; + + this->nameEntryVtx[phi_t1 + 1].v.ob[0] = this->nameEntryVtx[phi_t1 + 3].v.ob[0] = + this->nameEntryVtx[phi_t1].v.ob[0] + 0xA; + } else { + this->nameEntryVtx[phi_t1].v.ob[0] = this->nameEntryVtx[phi_t1 + 2].v.ob[0] = + D_808125EC[phi_s0] + this->nameEntryBoxPosX; + + this->nameEntryVtx[phi_t1 + 1].v.ob[0] = this->nameEntryVtx[phi_t1 + 3].v.ob[0] = + this->nameEntryVtx[phi_t1].v.ob[0] + 0xA; + } + + this->nameEntryVtx[phi_t1].v.ob[1] = this->nameEntryVtx[phi_t1 + 1].v.ob[1] = D_80812604[phi_s0]; + + this->nameEntryVtx[phi_t1 + 2].v.ob[1] = this->nameEntryVtx[phi_t1 + 3].v.ob[1] = + this->nameEntryVtx[phi_t1].v.ob[1] - 0xA; + + this->nameEntryVtx[phi_t1].v.ob[2] = this->nameEntryVtx[phi_t1 + 1].v.ob[2] = + this->nameEntryVtx[phi_t1 + 2].v.ob[2] = this->nameEntryVtx[phi_t1 + 3].v.ob[2] = 0; + + this->nameEntryVtx[phi_t1].v.flag = this->nameEntryVtx[phi_t1 + 1].v.flag = + this->nameEntryVtx[phi_t1 + 2].v.flag = this->nameEntryVtx[phi_t1 + 3].v.flag = 0; + + this->nameEntryVtx[phi_t1].v.tc[0] = this->nameEntryVtx[phi_t1].v.tc[1] = + this->nameEntryVtx[phi_t1 + 1].v.tc[1] = this->nameEntryVtx[phi_t1 + 2].v.tc[0] = 0; + + this->nameEntryVtx[phi_t1 + 1].v.tc[0] = this->nameEntryVtx[phi_t1 + 2].v.tc[1] = + this->nameEntryVtx[phi_t1 + 3].v.tc[0] = this->nameEntryVtx[phi_t1 + 3].v.tc[1] = 0x200; + + this->nameEntryVtx[phi_t1].v.cn[0] = this->nameEntryVtx[phi_t1 + 1].v.cn[0] = + this->nameEntryVtx[phi_t1 + 2].v.cn[0] = this->nameEntryVtx[phi_t1 + 3].v.cn[0] = + this->nameEntryVtx[phi_t1].v.cn[1] = this->nameEntryVtx[phi_t1 + 1].v.cn[1] = + this->nameEntryVtx[phi_t1 + 2].v.cn[1] = this->nameEntryVtx[phi_t1 + 3].v.cn[1] = + this->nameEntryVtx[phi_t1].v.cn[2] = this->nameEntryVtx[phi_t1 + 1].v.cn[2] = + this->nameEntryVtx[phi_t1 + 2].v.cn[2] = this->nameEntryVtx[phi_t1 + 3].v.cn[2] = + this->nameEntryVtx[phi_t1].v.cn[3] = this->nameEntryVtx[phi_t1 + 1].v.cn[3] = + this->nameEntryVtx[phi_t1 + 2].v.cn[3] = this->nameEntryVtx[phi_t1 + 3].v.cn[3] = + 0xFF; + } + + this->nameEntryVtx[1].v.ob[0] = this->nameEntryVtx[3].v.ob[0] = this->nameEntryVtx[0].v.ob[0] + 0x6C; + this->nameEntryVtx[2].v.ob[1] = this->nameEntryVtx[3].v.ob[1] = this->nameEntryVtx[0].v.ob[1] - 0x10; + this->nameEntryVtx[1].v.tc[0] = this->nameEntryVtx[3].v.tc[0] = 0xD80; + + gDPPipeSync(POLY_OPA_DISP++); + gDPSetCombineLERP(POLY_OPA_DISP++, PRIMITIVE, ENVIRONMENT, TEXEL0, ENVIRONMENT, TEXEL0, 0, PRIMITIVE, 0, PRIMITIVE, + ENVIRONMENT, TEXEL0, ENVIRONMENT, TEXEL0, 0, PRIMITIVE, 0); + gDPSetPrimColor(POLY_OPA_DISP++, 0, 0, this->windowColor[0], this->windowColor[1], this->windowColor[2], + this->nameEntryBoxAlpha); + gSPVertex(POLY_OPA_DISP++, this->nameEntryVtx, 4, 0); + gDPLoadTextureBlock(POLY_OPA_DISP++, gFileSelNameBoxTex, G_IM_FMT_IA, G_IM_SIZ_16b, 108, 16, 0, + G_TX_NOMIRROR | G_TX_WRAP, G_TX_NOMIRROR | G_TX_WRAP, G_TX_NOMASK, G_TX_NOMASK, G_TX_NOLOD, + G_TX_NOLOD); + gSP1Quadrangle(POLY_OPA_DISP++, 0, 2, 3, 1, 0); + gDPPipeSync(POLY_OPA_DISP++); + gDPSetCombineLERP(POLY_OPA_DISP++, 0, 0, 0, PRIMITIVE, TEXEL0, 0, PRIMITIVE, 0, 0, 0, 0, PRIMITIVE, TEXEL0, 0, + PRIMITIVE, 0); + gSPVertex(POLY_OPA_DISP++, this->nameEntryVtx + 4, 32, 0); + gDPSetPrimColor(POLY_OPA_DISP++, 0, 0, 255, 255, 255, this->nameEntryBoxAlpha); + + for (phi_v0 = 0, phi_s0 = 0; phi_s0 < 0x20; phi_s0 += 4, phi_v0++) { + FileChoose_DrawCharacter(this->state.gfxCtx, + font->fontBuf + this->fileNames[this->buttonIndex][phi_v0] * FONT_CHAR_TEX_SIZE, + phi_s0); + } + + this->nameEntryVtx[0x25].v.tc[0] = this->nameEntryVtx[0x26].v.tc[1] = this->nameEntryVtx[0x27].v.tc[0] = + this->nameEntryVtx[0x27].v.tc[1] = this->nameEntryVtx[0x29].v.tc[0] = this->nameEntryVtx[0x2A].v.tc[1] = + this->nameEntryVtx[0x2B].v.tc[0] = this->nameEntryVtx[0x2B].v.tc[1] = 0x300; + + if ((this->kbdButton == 0) || (this->kbdButton == 1) || (this->kbdButton == 4)) { + this->nameEntryVtx[0x29].v.tc[0] = this->nameEntryVtx[0x2B].v.tc[0] = 0x700; + } else if ((this->kbdButton == 2) || (this->kbdButton == 3)) { + this->nameEntryVtx[0x29].v.tc[0] = this->nameEntryVtx[0x2B].v.tc[0] = 0x500; + } + + CLOSE_DISPS(this->state.gfxCtx, "../z_file_nameset_PAL.c", 307); +} + +void FileChoose_DrawKeyboard(GameState* thisx) { + FileChooseContext* this = (FileChooseContext*)thisx; + Font* font = &this->font; + s16 i = 0; + s16 tmp; + s16 vtx = 0; + + OPEN_DISPS(this->state.gfxCtx, "../z_file_nameset_PAL.c", 324); + + func_800949A8(this->state.gfxCtx); + gDPSetCycleType(POLY_OPA_DISP++, G_CYC_2CYCLE); + gDPSetRenderMode(POLY_OPA_DISP++, G_RM_PASS, G_RM_XLU_SURF2); + gDPSetCombineLERP(POLY_OPA_DISP++, 0, 0, 0, PRIMITIVE, TEXEL1, TEXEL0, PRIM_LOD_FRAC, TEXEL0, 0, 0, 0, COMBINED, 0, + 0, 0, COMBINED); + gDPSetPrimColor(POLY_OPA_DISP++, 0, this->charBgAlpha, 255, 255, 255, 255); + + while (vtx < 0x100) { + gSPVertex(POLY_OPA_DISP++, &this->keyboardVtx[vtx], 32, 0); + + for (tmp = 0; tmp < 32; i++, tmp += 4) { + FileChoose_DrawCharacter(this->state.gfxCtx, font->fontBuf + D_808123F0[i] * FONT_CHAR_TEX_SIZE, tmp); + } + + vtx += 32; + } + + gSPVertex(POLY_OPA_DISP++, &this->keyboardVtx[0x100], 4, 0); + FileChoose_DrawCharacter(this->state.gfxCtx, font->fontBuf + D_808123F0[i] * FONT_CHAR_TEX_SIZE, 0); + + CLOSE_DISPS(this->state.gfxCtx, "../z_file_nameset_PAL.c", 347); +} + +void FileChoose_DrawNameEntry(GameState* thisx) { + FileChooseContext* this = (FileChooseContext*)thisx; + Font* font = &this->font; + Input* input = &this->state.input[0]; + s16 i; + s16 tmp; + u16 dayTime; + s16 validName; + + OPEN_DISPS(this->state.gfxCtx, "../z_file_nameset_PAL.c", 368); + + FileChoose_SetKeyboardVtx(&this->state); + FileChoose_SetNameEntryVtx(&this->state); + FileChoose_PulsateCursor(&this->state); + + tmp = (this->newFileNameCharCount * 4) + 4; + this->nameEntryVtx[36].v.ob[0] = this->nameEntryVtx[38].v.ob[0] = this->nameEntryVtx[tmp].v.ob[0] - 6; + this->nameEntryVtx[37].v.ob[0] = this->nameEntryVtx[39].v.ob[0] = this->nameEntryVtx[36].v.ob[0] + 24; + this->nameEntryVtx[36].v.ob[1] = this->nameEntryVtx[37].v.ob[1] = this->nameEntryVtx[tmp].v.ob[1] + 7; + this->nameEntryVtx[38].v.ob[1] = this->nameEntryVtx[39].v.ob[1] = this->nameEntryVtx[36].v.ob[1] - 24; + + if ((this->kbdButton == FS_KBD_BTN_HIRA) || (this->kbdButton == FS_KBD_BTN_KATA) || + (this->kbdButton == FS_KBD_BTN_END)) { + if (this->kbdX != this->kbdButton) { + osSyncPrintf("014 xpos=%d contents=%d\n", this->kbdX, this->kbdButton); + } + this->nameEntryVtx[40].v.ob[0] = this->nameEntryVtx[42].v.ob[0] = D_80811BB0[(this->kbdX + 1) * 4].v.ob[0] - 4; + this->nameEntryVtx[41].v.ob[0] = this->nameEntryVtx[43].v.ob[0] = this->nameEntryVtx[40].v.ob[0] + 52; + this->nameEntryVtx[40].v.ob[1] = this->nameEntryVtx[41].v.ob[1] = D_80811BB0[(this->kbdX + 1) * 4].v.ob[1] + 4; + + } else if ((this->kbdButton == FS_KBD_BTN_ENG) || (this->kbdButton == FS_KBD_BTN_BACKSPACE)) { + if (this->kbdX != this->kbdButton) { + osSyncPrintf("23 xpos=%d contents=%d\n", this->kbdX, this->kbdButton); + } + this->nameEntryVtx[40].v.ob[0] = this->nameEntryVtx[42].v.ob[0] = D_80811BB0[(this->kbdX + 1) * 4].v.ob[0] - 4; + this->nameEntryVtx[41].v.ob[0] = this->nameEntryVtx[43].v.ob[0] = this->nameEntryVtx[40].v.ob[0] + 40; + this->nameEntryVtx[40].v.ob[1] = this->nameEntryVtx[41].v.ob[1] = D_80811BB0[(this->kbdX + 1) * 4].v.ob[1] + 4; + } else { + if (this->charIndex >= 65) { + osSyncPrintf("mjp=%d xpos=%d ypos=%d name_contents=%d\n", this->charIndex, this->kbdX, this->kbdY, + this->kbdButton); + } + + this->nameEntryVtx[40].v.ob[0] = this->nameEntryVtx[42].v.ob[0] = + this->keyboardVtx[this->charIndex * 4].v.ob[0] - D_80812544[this->charIndex] - 6; + this->nameEntryVtx[41].v.ob[0] = this->nameEntryVtx[43].v.ob[0] = this->nameEntryVtx[40].v.ob[0] + 24; + this->nameEntryVtx[40].v.ob[1] = this->nameEntryVtx[41].v.ob[1] = + this->keyboardVtx[this->charIndex * 4].v.ob[1] + 6; + } + + this->nameEntryVtx[42].v.ob[1] = this->nameEntryVtx[43].v.ob[1] = this->nameEntryVtx[40].v.ob[1] - 24; + + gSPVertex(POLY_OPA_DISP++, &this->nameEntryVtx[36], 8, 0); + gDPPipeSync(POLY_OPA_DISP++); + gDPSetCombineLERP(POLY_OPA_DISP++, 1, 0, PRIMITIVE, 0, TEXEL0, 0, PRIMITIVE, 0, 1, 0, PRIMITIVE, 0, TEXEL0, 0, + PRIMITIVE, 0); + gDPSetPrimColor(POLY_OPA_DISP++, 0, 0, this->highlightColor[0], this->highlightColor[1], this->highlightColor[2], + this->highlightColor[3]); + gDPLoadTextureBlock(POLY_OPA_DISP++, gFileSelCharHighlightTex, G_IM_FMT_I, G_IM_SIZ_8b, 24, 24, 0, + G_TX_NOMIRROR | G_TX_WRAP, G_TX_NOMIRROR | G_TX_WRAP, G_TX_NOMASK, G_TX_NOMASK, G_TX_NOLOD, + G_TX_NOLOD); + gSP1Quadrangle(POLY_OPA_DISP++, 0, 2, 3, 1, 0); + + if ((this->kbdButton == FS_KBD_BTN_HIRA) || (this->kbdButton == FS_KBD_BTN_KATA) || + (this->kbdButton == FS_KBD_BTN_END)) { + gDPLoadTextureBlock(POLY_OPA_DISP++, gFileSelMediumButtonHighlightTex, G_IM_FMT_I, G_IM_SIZ_8b, 56, 24, 0, + G_TX_NOMIRROR | G_TX_WRAP, G_TX_NOMIRROR | G_TX_WRAP, G_TX_NOMASK, G_TX_NOMASK, G_TX_NOLOD, + G_TX_NOLOD); + + } else if ((this->kbdButton == FS_KBD_BTN_ENG) || (this->kbdButton == FS_KBD_BTN_BACKSPACE)) { + gDPLoadTextureBlock(POLY_OPA_DISP++, gFileSelSmallButtonHighlightTex, G_IM_FMT_I, G_IM_SIZ_8b, 40, 24, 0, + G_TX_NOMIRROR | G_TX_WRAP, G_TX_NOMIRROR | G_TX_WRAP, G_TX_NOMASK, G_TX_NOMASK, G_TX_NOLOD, + G_TX_NOLOD); + } + + gSP1Quadrangle(POLY_OPA_DISP++, 4, 6, 7, 5, 0); + + FileChoose_DrawKeyboard(&this->state); + gDPPipeSync(POLY_OPA_DISP++); + func_800949A8(this->state.gfxCtx); + + gDPSetCombineLERP(POLY_OPA_DISP++, 0, 0, 0, PRIMITIVE, TEXEL0, 0, PRIMITIVE, 0, 0, 0, 0, PRIMITIVE, TEXEL0, 0, + PRIMITIVE, 0); + gDPSetPrimColor(POLY_OPA_DISP++, 0, 0, 255, 255, 255, 255); + + if (this->configMode == CM_NAME_ENTRY) { + if (CHECK_BTN_ALL(input->press.button, BTN_START)) { + Audio_PlaySoundGeneral(NA_SE_SY_FSEL_DECIDE_L, &D_801333D4, 4, &D_801333E0, &D_801333E0, &D_801333E8); + // place cursor on END button + this->kbdY = 5; + this->kbdX = 4; + } else if (CHECK_BTN_ALL(input->press.button, BTN_B)) { + if ((this->newFileNameCharCount == 7) && (this->fileNames[this->buttonIndex][7] != 0x3E)) { + for (i = this->newFileNameCharCount; i < 7; i++) { + this->fileNames[this->buttonIndex][i] = this->fileNames[this->buttonIndex][i + 1]; + } + + this->fileNames[this->buttonIndex][i] = 0x3E; + Audio_PlaySoundGeneral(NA_SE_SY_FSEL_DECIDE_S, &D_801333D4, 4, &D_801333E0, &D_801333E0, &D_801333E8); + } else { + this->newFileNameCharCount--; + + if (this->newFileNameCharCount < 0) { + this->newFileNameCharCount = 0; + this->configMode = CM_NAME_ENTRY_TO_MAIN; + } else { + for (i = this->newFileNameCharCount; i < 7; i++) { + this->fileNames[this->buttonIndex][i] = this->fileNames[this->buttonIndex][i + 1]; + } + + this->fileNames[this->buttonIndex][i] = 0x3E; + Audio_PlaySoundGeneral(NA_SE_SY_FSEL_DECIDE_S, &D_801333D4, 4, &D_801333E0, &D_801333E0, + &D_801333E8); + } + } + } else { + if (this->charPage <= FS_CHAR_PAGE_ENG) { + if (this->kbdY != 5) { + // draw the character the cursor is hovering over in yellow + gDPSetPrimColor(POLY_OPA_DISP++, 0, 0, 255, 255, 0, 255); + gSPVertex(POLY_OPA_DISP++, &this->keyboardVtx[this->charIndex * 4], 4, 0); + + FileChoose_DrawCharacter(this->state.gfxCtx, + font->fontBuf + D_808123F0[this->charIndex] * FONT_CHAR_TEX_SIZE, 0); + + if (CHECK_BTN_ALL(input->press.button, BTN_A)) { + Audio_PlaySoundGeneral(NA_SE_SY_FSEL_DECIDE_S, &D_801333D4, 4, &D_801333E0, &D_801333E0, + &D_801333E8); + this->fileNames[this->buttonIndex][this->newFileNameCharCount] = D_808123F0[this->charIndex]; + this->newFileNameCharCount++; + + if (this->newFileNameCharCount > 7) { + this->newFileNameCharCount = 7; + } + } + } else if (CHECK_BTN_ALL(input->press.button, BTN_A) && (this->charPage != this->kbdButton)) { + if (this->kbdButton == FS_KBD_BTN_BACKSPACE) { + if ((this->newFileNameCharCount == 7) && (this->fileNames[this->buttonIndex][7] != 0x3E)) { + for (i = this->newFileNameCharCount; i < 7; i++) { + this->fileNames[this->buttonIndex][i] = this->fileNames[this->buttonIndex][i + 1]; + } + + this->fileNames[this->buttonIndex][i] = 0x3E; + Audio_PlaySoundGeneral(NA_SE_SY_FSEL_DECIDE_S, &D_801333D4, 4, &D_801333E0, &D_801333E0, + &D_801333E8); + } else { + this->newFileNameCharCount--; + + if (this->newFileNameCharCount < 0) { + this->newFileNameCharCount = 0; + } + + for (i = this->newFileNameCharCount; i < 7; i++) { + this->fileNames[this->buttonIndex][i] = this->fileNames[this->buttonIndex][i + 1]; + } + + this->fileNames[this->buttonIndex][i] = 0x3E; + Audio_PlaySoundGeneral(NA_SE_SY_FSEL_DECIDE_S, &D_801333D4, 4, &D_801333E0, &D_801333E0, + &D_801333E8); + } + } else if (this->kbdButton == FS_KBD_BTN_END) { + validName = false; + + for (i = 0; i < 8; i++) { + if (this->fileNames[this->buttonIndex][i] != 0x3E) { + validName = true; + break; + } + } + + if (validName) { + Audio_PlaySoundGeneral(NA_SE_SY_FSEL_DECIDE_L, &D_801333D4, 4, &D_801333E0, &D_801333E0, + &D_801333E8); + gSaveContext.fileNum = this->buttonIndex; + dayTime = ((void)0, gSaveContext.dayTime); + Sram_InitSave(this, &this->sramCtx); + gSaveContext.dayTime = dayTime; + this->configMode = CM_NAME_ENTRY_TO_MAIN; + this->nameBoxAlpha[this->buttonIndex] = this->nameAlpha[this->buttonIndex] = 200; + this->connectorAlpha[this->buttonIndex] = 255; + func_800AA000(300.0f, 0xB4, 0x14, 0x64); + } else { + Audio_PlaySoundGeneral(NA_SE_SY_FSEL_ERROR, &D_801333D4, 4, &D_801333E0, &D_801333E0, + &D_801333E8); + } + } + } + + if (CHECK_BTN_ALL(input->press.button, BTN_CRIGHT)) { + Audio_PlaySoundGeneral(NA_SE_SY_FSEL_CURSOR, &D_801333D4, 4, &D_801333E0, &D_801333E0, &D_801333E8); + this->newFileNameCharCount++; + + if (this->newFileNameCharCount > 7) { + this->newFileNameCharCount = 7; + } + } else if (CHECK_BTN_ALL(input->press.button, BTN_CLEFT)) { + Audio_PlaySoundGeneral(NA_SE_SY_FSEL_CURSOR, &D_801333D4, 4, &D_801333E0, &D_801333E0, &D_801333E8); + this->newFileNameCharCount--; + + if (this->newFileNameCharCount < 0) { + this->newFileNameCharCount = 0; + } + } + } + } + } + + gDPPipeSync(POLY_OPA_DISP++); + gDPSetCombineMode(POLY_OPA_DISP++, G_CC_MODULATEIDECALA, G_CC_MODULATEIDECALA); + + CLOSE_DISPS(this->state.gfxCtx, "../z_file_nameset_PAL.c", 550); +} + +/** + * Fade in the name entry box and slide it to the center of the screen from the right side. + * After the name entry box is in place, init the keyboard/cursor and change modes. + * Update function for `CM_START_NAME_ENTRY` + */ +void FileChoose_StartNameEntry(GameState* thisx) { + FileChooseContext* this = (FileChooseContext*)thisx; + + this->nameEntryBoxAlpha += 25; + + if (this->nameEntryBoxAlpha >= 255) { + this->nameEntryBoxAlpha = 255; + } + + this->nameEntryBoxPosX -= 30; + + if (this->nameEntryBoxPosX <= 0) { + this->nameEntryBoxPosX = 0; + this->nameEntryBoxAlpha = 255; + this->kbdX = 0; + this->kbdY = 0; + this->kbdButton = 99; + this->configMode = CM_NAME_ENTRY; + } +} + +/** + * Update the keyboard cursor and play sounds at the appropriate times. + * There are many special cases for warping the cursor depending on where + * the cursor currently is. + * Update function for `CM_NAME_ENTRY` + */ +void FileChoose_UpdateKeyboardCursor(GameState* thisx) { + FileChooseContext* this = (FileChooseContext*)thisx; + s16 prevKbdX; + + this->kbdButton = 99; + + if (this->kbdY != 5) { + if (this->stickRelX < -30) { + Audio_PlaySoundGeneral(NA_SE_SY_FSEL_CURSOR, &D_801333D4, 4, &D_801333E0, &D_801333E0, &D_801333E8); + this->charIndex--; + this->kbdX--; + if (this->kbdX < 0) { + this->kbdX = 12; + this->charIndex = (this->kbdY * 13) + this->kbdX; + } + } else if (this->stickRelX > 30) { + Audio_PlaySoundGeneral(NA_SE_SY_FSEL_CURSOR, &D_801333D4, 4, &D_801333E0, &D_801333E0, &D_801333E8); + this->charIndex++; + this->kbdX++; + if (this->kbdX > 12) { + this->kbdX = 0; + this->charIndex = (this->kbdY * 13) + this->kbdX; + } + } + } else { + if (this->stickRelX < -30) { + Audio_PlaySoundGeneral(NA_SE_SY_FSEL_CURSOR, &D_801333D4, 4, &D_801333E0, &D_801333E0, &D_801333E8); + this->kbdX--; + if (this->kbdX < 3) { + this->kbdX = 4; + } + } else if (this->stickRelX > 30) { + Audio_PlaySoundGeneral(NA_SE_SY_FSEL_CURSOR, &D_801333D4, 4, &D_801333E0, &D_801333E0, &D_801333E8); + this->kbdX++; + if (this->kbdX > 4) { + this->kbdX = 3; + } + } + } + + if (this->stickRelY > 30) { + Audio_PlaySoundGeneral(NA_SE_SY_FSEL_CURSOR, &D_801333D4, 4, &D_801333E0, &D_801333E0, &D_801333E8); + this->kbdY--; + + if (this->kbdY < 0) { + // dont go to bottom row + if (this->kbdX < 8) { + this->kbdY = 4; + this->charIndex = (s32)(this->kbdX + 52); + } else { + this->kbdY = 5; + this->charIndex += 52; + prevKbdX = this->kbdX; + + if (this->kbdX < 10) { + this->kbdX = 3; + } else if (this->kbdX < 13) { + this->kbdX = 4; + } + + this->unk_1CAD6[this->kbdX] = prevKbdX; + } + } else { + this->charIndex -= 13; + + if (this->kbdY == 4) { + this->charIndex = 52; + this->kbdX = this->unk_1CAD6[this->kbdX]; + this->charIndex += this->kbdX; + } + } + } else if (this->stickRelY < -30) { + Audio_PlaySoundGeneral(NA_SE_SY_FSEL_CURSOR, &D_801333D4, 4, &D_801333E0, &D_801333E0, &D_801333E8); + this->kbdY++; + + if (this->kbdY > 5) { + this->kbdY = 0; + this->kbdX = this->unk_1CAD6[this->kbdX]; + this->charIndex = this->kbdX; + } else { + this->charIndex += 13; + + if (this->kbdY == 5) { + if (this->kbdX < 8) { + this->kbdY = 0; + this->charIndex = this->kbdX; + } else { + prevKbdX = this->kbdX; + + if (this->kbdX < 3) { + this->kbdX = 0; + } else if (this->kbdX < 6) { + this->kbdX = 1; + } else if (this->kbdX < 8) { + this->kbdX = 2; + } else if (this->kbdX < 10) { + this->kbdX = 3; + } else if (this->kbdX < 13) { + this->kbdX = 4; + } + + this->unk_1CAD6[this->kbdX] = prevKbdX; + } + } + } + } + + if (this->kbdY == 5) { + this->kbdButton = this->kbdX; + } +} + +/** + * This function is mostly a copy paste of `FileChoose_StartNameEntry`. + * The name entry box fades and slides in even though it is not visible. + * After this is complete, change to the options config mode. + * Update function for `CM_START_OPTIONS` + */ +void FileChoose_StartOptions(GameState* thisx) { + FileChooseContext* this = (FileChooseContext*)thisx; + + this->nameEntryBoxAlpha += 25; + + if (this->nameEntryBoxAlpha >= 255) { + this->nameEntryBoxAlpha = 255; + } + + this->nameEntryBoxPosX -= 30; + + if (this->nameEntryBoxPosX <= 0) { + this->nameEntryBoxPosX = 0; + this->nameEntryBoxAlpha = 255; + this->configMode = CM_OPTIONS_MENU; + } +} + +static u8 sSelectedSetting; + +/** + * Update the cursor and appropriate settings for the options menu. + * If the player presses B, write the selected options to the SRAM header + * and set config mode to rotate back to the main menu. + * Update function for `CM_OPTIONS_MENU` + */ +void FileChoose_UpdateOptionsMenu(GameState* thisx) { + FileChooseContext* this = (FileChooseContext*)thisx; + SramContext* sramCtx = &this->sramCtx; + Input* input = &this->state.input[0]; + + if (CHECK_BTN_ALL(input->press.button, BTN_B)) { + Audio_PlaySoundGeneral(NA_SE_SY_FSEL_DECIDE_L, &D_801333D4, 4, &D_801333E0, &D_801333E0, &D_801333E8); + this->configMode = CM_OPTIONS_TO_MAIN; + sramCtx->readBuff[0] = gSaveContext.audioSetting; + sramCtx->readBuff[1] = gSaveContext.zTargetSetting; + osSyncPrintf("SAVE"); + Sram_WriteSramHeader(sramCtx); + osSyncPrintf(VT_FGCOL(YELLOW)); + osSyncPrintf("sram->read_buff[2] = J_N = %x\n", sramCtx->readBuff[2]); + osSyncPrintf("sram->read_buff[2] = J_N = %x\n", &sramCtx->readBuff[2]); + osSyncPrintf("Na_SetSoundOutputMode = %d\n", gSaveContext.audioSetting); + osSyncPrintf("Na_SetSoundOutputMode = %d\n", gSaveContext.audioSetting); + osSyncPrintf("Na_SetSoundOutputMode = %d\n", gSaveContext.audioSetting); + osSyncPrintf(VT_RST); + func_800F6700(gSaveContext.audioSetting); + osSyncPrintf("終了\n"); + return; + } + + if (this->stickRelX < -30) { + Audio_PlaySoundGeneral(NA_SE_SY_FSEL_CURSOR, &D_801333D4, 4, &D_801333E0, &D_801333E0, &D_801333E8); + + if (sSelectedSetting == FS_SETTING_AUDIO) { + gSaveContext.audioSetting--; + + // because audio setting is unsigned, can't check for < 0 + if (gSaveContext.audioSetting > 0xF0) { + gSaveContext.audioSetting = FS_AUDIO_SURROUND; + } + } else { + gSaveContext.zTargetSetting ^= 1; + } + } else if (this->stickRelX > 30) { + Audio_PlaySoundGeneral(NA_SE_SY_FSEL_CURSOR, &D_801333D4, 4, &D_801333E0, &D_801333E0, &D_801333E8); + + if (sSelectedSetting == FS_SETTING_AUDIO) { + gSaveContext.audioSetting++; + + if (gSaveContext.audioSetting > FS_AUDIO_SURROUND) { + gSaveContext.audioSetting = FS_AUDIO_STEREO; + } + } else { + gSaveContext.zTargetSetting ^= 1; + } + } + + if ((this->stickRelY < -30) || (this->stickRelY > 30)) { + Audio_PlaySoundGeneral(NA_SE_SY_FSEL_CURSOR, &D_801333D4, 4, &D_801333E0, &D_801333E0, &D_801333E8); + sSelectedSetting ^= 1; + } else if (CHECK_BTN_ALL(input->press.button, BTN_A)) { + Audio_PlaySoundGeneral(NA_SE_SY_FSEL_DECIDE_L, &D_801333D4, 4, &D_801333E0, &D_801333E0, &D_801333E8); + sSelectedSetting ^= 1; + } +} + +typedef struct { + /* 0x00 */ void* texture[3]; + /* 0x0C */ u16 width[3]; + /* 0x12 */ u16 height; +} OptionsMenuTextureInfo; // size = 0x14 + +static OptionsMenuTextureInfo gOptionsMenuHeaders[] = { + { + { gFileSelOptionsENGTex, gFileSelOptionsGERTex, gFileSelOptionsENGTex }, + { 128, 128, 128 }, + 16, + }, + { + { gFileSelSOUNDENGTex, gFileSelSOUNDENGTex, gFileSelSOUNDFRATex }, + { 64, 64, 64 }, + 16, + }, + { + { gFileSelLTargetingENGTex, gFileSelLTargetingGERTex, gFileSelLTargetingFRATex }, + { 64, 144, 64 }, + 16, + }, + { + { gFileSelCheckBrightnessENGTex, gFileSelCheckBrightnessGERTex, gFileSelCheckBrightnessFRATex }, + { 128, 128, 128 }, + 16, + }, +}; + +static OptionsMenuTextureInfo gOptionsMenuSettings[] = { + { + { gFileSelStereoENGTex, gFileSelStereoENGTex, gFileSelStereoFRATex }, + { 48, 48, 48 }, + 16, + }, + { + { gFileSelMonoENGTex, gFileSelMonoENGTex, gFileSelMonoENGTex }, + { 48, 48, 48 }, + 16, + }, + { + { gFileSelHeadsetENGTex, gFileSelHeadsetGERTex, gFileSelHeadsetFRATex }, + { 48, 48, 48 }, + 16, + }, + { + { gFileSelSurroundENGTex, gFileSelSurroundENGTex, gFileSelSurroundENGTex }, + { 48, 48, 48 }, + 16, + }, + { + { gFileSelSwitchENGTex, gFileSelSwitchGERTex, gFileSelSwitchFRATex }, + { 48, 80, 48 }, + 16, + }, + { + { gFileSelHoldENGTex, gFileSelHoldGERTex, gFileSelHoldFRATex }, + { 48, 80, 48 }, + 16, + }, +}; + +void FileChoose_DrawOptionsImpl(GameState* thisx) { + static s16 cursorPrimRed = 255; + static s16 cursorPrimGreen = 255; + static s16 cursorPrimBlue = 255; + static s16 cursorEnvRed = 0; + static s16 cursorEnvGreen = 0; + static s16 cursorEnvBlue = 0; + static s16 cursorPulseDir = 1; + static s16 cursorFlashTimer = 20; + static s16 cursorPrimColors[][3] = { + { 255, 255, 255 }, + { 0, 255, 255 }, + }; + static s16 cursorEnvColors[][3] = { + { 0, 0, 0 }, + { 0, 150, 150 }, + }; + FileChooseContext* this = (FileChooseContext*)thisx; + s16 cursorRed; + s16 cursorGreen; + s16 cursorBlue; + s16 i; + s16 j; + s16 vtx; + + OPEN_DISPS(this->state.gfxCtx, "../z_file_nameset_PAL.c", 848); + + cursorRed = ABS(cursorPrimRed - cursorPrimColors[cursorPulseDir][0]) / cursorFlashTimer; + cursorGreen = ABS(cursorPrimGreen - cursorPrimColors[cursorPulseDir][1]) / cursorFlashTimer; + cursorBlue = ABS(cursorPrimBlue - cursorPrimColors[cursorPulseDir][2]) / cursorFlashTimer; + + if (cursorPrimRed >= cursorPrimColors[cursorPulseDir][0]) { + cursorPrimRed -= cursorRed; + } else { + cursorPrimRed += cursorRed; + } + + if (cursorPrimGreen >= cursorPrimColors[cursorPulseDir][1]) { + cursorPrimGreen -= cursorGreen; + } else { + cursorPrimGreen += cursorGreen; + } + + if (cursorPrimBlue >= cursorPrimColors[cursorPulseDir][2]) { + cursorPrimBlue -= cursorBlue; + } else { + cursorPrimBlue += cursorBlue; + } + + cursorRed = ABS(cursorEnvRed - cursorEnvColors[cursorPulseDir][0]) / cursorFlashTimer; + cursorGreen = ABS(cursorEnvGreen - cursorEnvColors[cursorPulseDir][1]) / cursorFlashTimer; + cursorBlue = ABS(cursorEnvBlue - cursorEnvColors[cursorPulseDir][2]) / cursorFlashTimer; + + if (cursorEnvRed >= cursorEnvColors[cursorPulseDir][0]) { + cursorEnvRed -= cursorRed; + } else { + cursorEnvRed += cursorRed; + } + + if (cursorEnvGreen >= cursorEnvColors[cursorPulseDir][1]) { + cursorEnvGreen -= cursorGreen; + } else { + cursorEnvGreen += cursorGreen; + } + + if (cursorEnvBlue >= cursorEnvColors[cursorPulseDir][2]) { + cursorEnvBlue -= cursorBlue; + } else { + cursorEnvBlue += cursorBlue; + } + + if (--cursorFlashTimer == 0) { + cursorPrimRed = cursorPrimColors[cursorPulseDir][0]; + cursorPrimGreen = cursorPrimColors[cursorPulseDir][1]; + cursorPrimBlue = cursorPrimColors[cursorPulseDir][2]; + + cursorEnvRed = cursorEnvColors[cursorPulseDir][0]; + cursorEnvGreen = cursorEnvColors[cursorPulseDir][1]; + cursorEnvBlue = cursorEnvColors[cursorPulseDir][2]; + + cursorFlashTimer = 20; + + if (++cursorPulseDir > 1) { + cursorPulseDir = 0; + } + } + + if (gSaveContext.language == 1) { + gSPVertex(POLY_OPA_DISP++, D_80811E30, 32, 0); + } else { + gSPVertex(POLY_OPA_DISP++, D_80811D30, 32, 0); + } + + gDPPipeSync(POLY_OPA_DISP++); + gDPSetCombineLERP(POLY_OPA_DISP++, PRIMITIVE, ENVIRONMENT, TEXEL0, ENVIRONMENT, TEXEL0, 0, PRIMITIVE, 0, PRIMITIVE, + ENVIRONMENT, TEXEL0, ENVIRONMENT, TEXEL0, 0, PRIMITIVE, 0); + gDPSetPrimColor(POLY_OPA_DISP++, 0, 0, 255, 255, 255, this->titleAlpha[0]); + gDPSetEnvColor(POLY_OPA_DISP++, 0, 0, 0, 255); + + for (i = 0, vtx = 0; i < 4; i++, vtx += 4) { + gDPLoadTextureBlock(POLY_OPA_DISP++, gOptionsMenuHeaders[i].texture[gSaveContext.language], G_IM_FMT_IA, + G_IM_SIZ_8b, gOptionsMenuHeaders[i].width[gSaveContext.language], + gOptionsMenuHeaders[i].height, 0, G_TX_NOMIRROR | G_TX_WRAP, G_TX_NOMIRROR | G_TX_WRAP, + G_TX_NOMASK, G_TX_NOMASK, G_TX_NOLOD, G_TX_NOLOD); + gSP1Quadrangle(POLY_OPA_DISP++, vtx, vtx + 2, vtx + 3, vtx + 1, 0); + } + + if (gSaveContext.language == 1) { + gSPVertex(POLY_OPA_DISP++, D_80812130, 32, 0); + } else { + gSPVertex(POLY_OPA_DISP++, D_80811F30, 32, 0); + } + + for (i = 0, vtx = 0; i < 4; i++, vtx += 4) { + gDPPipeSync(POLY_OPA_DISP++); + if (i == gSaveContext.audioSetting) { + if (sSelectedSetting == FS_SETTING_AUDIO) { + gDPSetPrimColor(POLY_OPA_DISP++, 0, 0, cursorPrimRed, cursorPrimGreen, cursorPrimBlue, + this->titleAlpha[0]); + gDPSetEnvColor(POLY_OPA_DISP++, cursorEnvRed, cursorEnvGreen, cursorEnvBlue, 255); + } else { + gDPSetPrimColor(POLY_OPA_DISP++, 0, 0, 255, 255, 255, this->titleAlpha[0]); + gDPSetEnvColor(POLY_OPA_DISP++, 0, 0, 0, 255); + } + } else { + gDPSetPrimColor(POLY_OPA_DISP++, 0, 0, 120, 120, 120, this->titleAlpha[0]); + gDPSetEnvColor(POLY_OPA_DISP++, 0, 0, 0, 255); + } + + gDPLoadTextureBlock(POLY_OPA_DISP++, gOptionsMenuSettings[i].texture[gSaveContext.language], G_IM_FMT_IA, + G_IM_SIZ_8b, gOptionsMenuSettings[i].width[gSaveContext.language], + gOptionsMenuHeaders[i].height, 0, G_TX_NOMIRROR | G_TX_WRAP, G_TX_NOMIRROR | G_TX_WRAP, + G_TX_NOMASK, G_TX_NOMASK, G_TX_NOLOD, G_TX_NOLOD); + gSP1Quadrangle(POLY_OPA_DISP++, vtx, vtx + 2, vtx + 3, vtx + 1, 0); + } + + for (; i < 6; i++, vtx += 4) { + gDPPipeSync(POLY_OPA_DISP++); + + if (i == (gSaveContext.zTargetSetting + 4)) { + if (sSelectedSetting != FS_SETTING_AUDIO) { + gDPSetPrimColor(POLY_OPA_DISP++, 0, 0, cursorPrimRed, cursorPrimGreen, cursorPrimBlue, + this->titleAlpha[0]); + gDPSetEnvColor(POLY_OPA_DISP++, cursorEnvRed, cursorEnvGreen, cursorEnvBlue, 0xFF); + } else { + gDPSetPrimColor(POLY_OPA_DISP++, 0, 0, 255, 255, 255, this->titleAlpha[0]); + gDPSetEnvColor(POLY_OPA_DISP++, 0, 0, 0, 255); + } + } else { + gDPSetPrimColor(POLY_OPA_DISP++, 0, 0, 120, 120, 120, this->titleAlpha[0]); + gDPSetEnvColor(POLY_OPA_DISP++, 0, 0, 0, 255); + } + + gDPLoadTextureBlock(POLY_OPA_DISP++, gOptionsMenuSettings[i].texture[gSaveContext.language], G_IM_FMT_IA, + G_IM_SIZ_8b, gOptionsMenuSettings[i].width[gSaveContext.language], + gOptionsMenuHeaders[i].height, 0, G_TX_NOMIRROR | G_TX_WRAP, G_TX_NOMIRROR | G_TX_WRAP, + G_TX_NOMASK, G_TX_NOMASK, G_TX_NOLOD, G_TX_NOLOD); + gSP1Quadrangle(POLY_OPA_DISP++, vtx, vtx + 2, vtx + 3, vtx + 1, 0); + } + + gDPPipeSync(POLY_OPA_DISP++); + + // check brightness bars + gDPLoadTextureBlock_4b(POLY_OPA_DISP++, gFileSelBrightnessCheckTex, G_IM_FMT_IA, 96, 16, 0, + G_TX_NOMIRROR | G_TX_WRAP, G_TX_NOMIRROR | G_TX_WRAP, G_TX_NOMASK, G_TX_NOMASK, G_TX_NOLOD, + G_TX_NOLOD); + gDPSetPrimColor(POLY_OPA_DISP++, 0, 0, 55, 55, 55, this->titleAlpha[0]); + gDPSetEnvColor(POLY_OPA_DISP++, 40, 40, 40, 255); + gSP1Quadrangle(POLY_OPA_DISP++, vtx, vtx + 2, vtx + 3, vtx + 1, 0); + + vtx += 4; + + gDPPipeSync(POLY_OPA_DISP++); + gDPSetPrimColor(POLY_OPA_DISP++, 0, 0, 30, 30, 30, this->titleAlpha[0]); + gDPSetEnvColor(POLY_OPA_DISP++, 0, 0, 0, 255); + gSP1Quadrangle(POLY_OPA_DISP++, vtx, vtx + 2, vtx + 3, vtx + 1, 0); + + vtx += 4; + + // blue divider lines + gDPPipeSync(POLY_OPA_DISP++); + gDPSetPrimColor(POLY_OPA_DISP++, 0, 0, 0, 255, 255, this->titleAlpha[0]); + gDPSetEnvColor(POLY_OPA_DISP++, 0, 0, 0, 0); + + gDPLoadTextureBlock_4b(POLY_OPA_DISP++, gFileSelOptionsDividerTex, G_IM_FMT_IA, 256, 2, 0, + G_TX_NOMIRROR | G_TX_WRAP, G_TX_NOMIRROR | G_TX_WRAP, G_TX_NOMASK, G_TX_NOMASK, G_TX_NOLOD, + G_TX_NOLOD); + + Matrix_Push(); + Matrix_Translate(0.0f, 0.1f, 0.0f, MTXMODE_APPLY); + gSPMatrix(POLY_OPA_DISP++, Matrix_NewMtx(this->state.gfxCtx, "../z_file_nameset_PAL.c", 1009), + G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW); + gSPVertex(POLY_OPA_DISP++, gOptionsDividerTopVtx, 4, 0); + gSP1Quadrangle(POLY_OPA_DISP++, 0, 2, 3, 1, 0); + Matrix_Pop(); + + Matrix_Push(); + Matrix_Translate(0.0f, 0.2f, 0.0f, MTXMODE_APPLY); + gSPMatrix(POLY_OPA_DISP++, Matrix_NewMtx(this->state.gfxCtx, "../z_file_nameset_PAL.c", 1021), + G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW); + + gSPVertex(POLY_OPA_DISP++, gOptionsDividerMiddleVtx, 4, 0); + gSP1Quadrangle(POLY_OPA_DISP++, 0, 2, 3, 1, 0); + Matrix_Pop(); + + Matrix_Push(); + Matrix_Translate(0.0f, 0.4f, 0.0f, MTXMODE_APPLY); + gSPMatrix(POLY_OPA_DISP++, Matrix_NewMtx(this->state.gfxCtx, "../z_file_nameset_PAL.c", 1033), + G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW); + gSPVertex(POLY_OPA_DISP++, gOptionsDividerBottomVtx, 4, 0); + gSP1Quadrangle(POLY_OPA_DISP++, 0, 2, 3, 1, 0); + Matrix_Pop(); + + CLOSE_DISPS(this->state.gfxCtx, "../z_file_nameset_PAL.c", 1040); +} + +void FileChoose_DrawOptions(GameState* thisx) { + FileChoose_DrawOptionsImpl(thisx); +} diff --git a/src/overlays/gamestates/ovl_file_choose/z_file_nameset_data.c b/src/overlays/gamestates/ovl_file_choose/z_file_nameset_data.c new file mode 100644 index 000000000..f53da9730 --- /dev/null +++ b/src/overlays/gamestates/ovl_file_choose/z_file_nameset_data.c @@ -0,0 +1,11 @@ +#include "file_choose.h" + +#include "assets/overlays/ovl_File_Choose/ovl_file_choose.c" + +s16 D_808123F0[] = { + 0x000A, 0x000B, 0x000C, 0x000D, 0x000E, 0x000F, 0x0010, 0x0011, 0x0012, 0x0013, 0x0014, 0x0015, 0x0016, + 0x0017, 0x0018, 0x0019, 0x001A, 0x001B, 0x001C, 0x001D, 0x001E, 0x001F, 0x0020, 0x0021, 0x0022, 0x0023, + 0x0024, 0x0025, 0x0026, 0x0027, 0x0028, 0x0029, 0x002A, 0x002B, 0x002C, 0x002D, 0x002E, 0x002F, 0x0030, + 0x0031, 0x0032, 0x0033, 0x0034, 0x0035, 0x0036, 0x0037, 0x0038, 0x0039, 0x003A, 0x003B, 0x003C, 0x003D, + 0x0001, 0x0002, 0x0003, 0x0004, 0x0005, 0x0006, 0x0007, 0x0008, 0x0009, 0x0000, 0x0040, 0x003F, 0x003E, +}; diff --git a/src/overlays/gamestates/ovl_select/z_select.c b/src/overlays/gamestates/ovl_select/z_select.c index 3fcbdfd43..a1046401c 100644 --- a/src/overlays/gamestates/ovl_select/z_select.c +++ b/src/overlays/gamestates/ovl_select/z_select.c @@ -25,11 +25,8 @@ void Select_LoadGame(SelectContext* this, s32 entranceIndex) { gSaveContext.unk_13F4 = 0; gSaveContext.magicLevel = gSaveContext.magic; } - gSaveContext.buttonStatus[4] = BTN_ENABLED; - gSaveContext.buttonStatus[3] = BTN_ENABLED; - gSaveContext.buttonStatus[2] = BTN_ENABLED; - gSaveContext.buttonStatus[1] = BTN_ENABLED; - gSaveContext.buttonStatus[0] = BTN_ENABLED; + gSaveContext.buttonStatus[0] = gSaveContext.buttonStatus[1] = gSaveContext.buttonStatus[2] = + gSaveContext.buttonStatus[3] = gSaveContext.buttonStatus[4] = BTN_ENABLED; gSaveContext.unk_13E7 = gSaveContext.unk_13E8 = gSaveContext.unk_13EA = gSaveContext.unk_13EC = 0; Audio_QueueSeqCmd(NA_BGM_STOP); gSaveContext.entranceIndex = entranceIndex; @@ -195,19 +192,19 @@ static SceneSelectEntry sScenes[] = { }; void Select_UpdateMenu(SelectContext* this) { - Input* controller1 = &this->state.input[0]; + Input* input = &this->state.input[0]; s32 pad; SceneSelectEntry* selectedScene; if (this->verticalInputAccumulator == 0) { - if (CHECK_BTN_ALL(controller1->press.button, BTN_A) || CHECK_BTN_ALL(controller1->press.button, BTN_START)) { + if (CHECK_BTN_ALL(input->press.button, BTN_A) || CHECK_BTN_ALL(input->press.button, BTN_START)) { selectedScene = &this->scenes[this->currentScene]; if (selectedScene->loadFunc != NULL) { selectedScene->loadFunc(this, selectedScene->entranceIndex); } } - if (CHECK_BTN_ALL(controller1->press.button, BTN_B)) { + if (CHECK_BTN_ALL(input->press.button, BTN_B)) { if (LINK_AGE_IN_YEARS == YEARS_ADULT) { gSaveContext.linkAge = 1; } else { @@ -215,7 +212,7 @@ void Select_UpdateMenu(SelectContext* this) { } } - if (CHECK_BTN_ALL(controller1->press.button, BTN_Z)) { + if (CHECK_BTN_ALL(input->press.button, BTN_Z)) { if (gSaveContext.cutsceneIndex == 0x8000) { gSaveContext.cutsceneIndex = 0; } else if (gSaveContext.cutsceneIndex == 0) { @@ -243,7 +240,7 @@ void Select_UpdateMenu(SelectContext* this) { } else if (gSaveContext.cutsceneIndex == 0xFFFA) { gSaveContext.cutsceneIndex = 0x8000; } - } else if (CHECK_BTN_ALL(controller1->press.button, BTN_R)) { + } else if (CHECK_BTN_ALL(input->press.button, BTN_R)) { if (gSaveContext.cutsceneIndex == 0x8000) { gSaveContext.cutsceneIndex = 0xFFFA; } else if (gSaveContext.cutsceneIndex == 0) { @@ -279,14 +276,14 @@ void Select_UpdateMenu(SelectContext* this) { } // user can change "opt", but it doesn't do anything - if (CHECK_BTN_ALL(controller1->press.button, BTN_CUP)) { + if (CHECK_BTN_ALL(input->press.button, BTN_CUP)) { this->opt--; } - if (CHECK_BTN_ALL(controller1->press.button, BTN_CDOWN)) { + if (CHECK_BTN_ALL(input->press.button, BTN_CDOWN)) { this->opt++; } - if (CHECK_BTN_ALL(controller1->press.button, BTN_DUP)) { + if (CHECK_BTN_ALL(input->press.button, BTN_DUP)) { if (this->lockUp == true) { this->timerUp = 0; } @@ -298,12 +295,12 @@ void Select_UpdateMenu(SelectContext* this) { } } - if (CHECK_BTN_ALL(controller1->cur.button, BTN_DUP) && this->timerUp == 0) { + if (CHECK_BTN_ALL(input->cur.button, BTN_DUP) && this->timerUp == 0) { Audio_PlaySoundGeneral(NA_SE_IT_SWORD_IMPACT, &D_801333D4, 4, &D_801333E0, &D_801333E0, &D_801333E8); this->verticalInput = R_UPDATE_RATE * 3; } - if (CHECK_BTN_ALL(controller1->press.button, BTN_DDOWN)) { + if (CHECK_BTN_ALL(input->press.button, BTN_DDOWN)) { if (this->lockDown == true) { this->timerDown = 0; } @@ -315,24 +312,23 @@ void Select_UpdateMenu(SelectContext* this) { } } - if (CHECK_BTN_ALL(controller1->cur.button, BTN_DDOWN) && (this->timerDown == 0)) { + if (CHECK_BTN_ALL(input->cur.button, BTN_DDOWN) && (this->timerDown == 0)) { Audio_PlaySoundGeneral(NA_SE_IT_SWORD_IMPACT, &D_801333D4, 4, &D_801333E0, &D_801333E0, &D_801333E8); this->verticalInput = -R_UPDATE_RATE * 3; } - if (CHECK_BTN_ALL(controller1->press.button, BTN_DLEFT) || CHECK_BTN_ALL(controller1->cur.button, BTN_DLEFT)) { + if (CHECK_BTN_ALL(input->press.button, BTN_DLEFT) || CHECK_BTN_ALL(input->cur.button, BTN_DLEFT)) { Audio_PlaySoundGeneral(NA_SE_IT_SWORD_IMPACT, &D_801333D4, 4, &D_801333E0, &D_801333E0, &D_801333E8); this->verticalInput = R_UPDATE_RATE; } - if (CHECK_BTN_ALL(controller1->press.button, BTN_DRIGHT) || - CHECK_BTN_ALL(controller1->cur.button, BTN_DRIGHT)) { + if (CHECK_BTN_ALL(input->press.button, BTN_DRIGHT) || CHECK_BTN_ALL(input->cur.button, BTN_DRIGHT)) { Audio_PlaySoundGeneral(NA_SE_IT_SWORD_IMPACT, &D_801333D4, 4, &D_801333E0, &D_801333E0, &D_801333E8); this->verticalInput = -R_UPDATE_RATE; } } - if (CHECK_BTN_ALL(controller1->press.button, BTN_L)) { + if (CHECK_BTN_ALL(input->press.button, BTN_L)) { this->pageDownIndex++; this->pageDownIndex = (this->pageDownIndex + ARRAY_COUNT(this->pageDownStops)) % ARRAY_COUNT(this->pageDownStops); |
