diff options
| author | Tharo <17233964+Thar0@users.noreply.github.com> | 2021-11-23 01:20:30 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-11-22 20:20:30 -0500 |
| commit | a497f33bda7686e3aa948898000ecd3a861c5704 (patch) | |
| tree | 23484d614897f25b2d10b465a52c1ce6d34a0c59 /src/code | |
| parent | 03636166b35b4ff8fac5991bea51eccb071f1f31 (diff) | |
z_message_PAL, message_data_static and surrounding doc (#996)
* Initial progress on z_message_PAL, very messy
* Fix merge
* Some more progress
* Fix merge
* More z_message_PAL
* Small progress
* More small progress
* message_data_static files OK
* Prepare z_message_tables
* Matched another function, small updates
* Attempt to use asm-processor static-symbols branch
* Refactor text id declarations
* Begin large text codes parser function
* Fix merge
* Refactor done
* Build OK, add color and highscore names
* Remove encoded text headers and automatically encode during build
* Fix kanfont
* Various cleanups
* DISP macros
* Another match aside data
* Further progress
* Small improvements
* Deduplicate magic values for text control codes, small improvements
* Tiny progress
* Minor cleanups
* Clean up z_message_PAL comment
* Progress on large functions
* Further progress on large functions
* Changes to mkldscript to link .data in the .rodata section
* data OK
* Few improvements
* Use gDPLoadTextureBlock macros where appropriate
* rm z_message_tables, progress on large functions
* 2 more matches
* Improvements
* Small progress
* More progress on big function
* progress
* match func_80107980
* match Message_Update
* match func_8010BED8
* done
* Progress on remaining large functions
* Small progress on largest function
* Another match, extract text and move to assets, improve text build system
* Small nonmatchings improvements
* docs wip
* Largest function maybe equivalent
* Fix merge
* Document do_action values, largest function is almost instruction-matching
* Rename NAVI do_action to NONE, as that appears to be how that value is used in practice
* Fix merge
* one match
* Last function is instruction-matching
* Fix
* Improvements thanks to engineer124
* Stack matched thanks to petrie911, now just a/v/low t regalloc issues, some cleanup
* More variables labeled, use text state enum everywhere
* More labels and names
* Fix
* Actor_IsTalking -> Actor_TalkRequested
* Match func_8010C39C and remove unused asm
* More docs
* Mostly ocarina related docs
* All msgModes named
* Fix assetclean
* Cleanup
* Extraction fixes and headers
* Suggestions
* Review suggestions
* Change text extraction again, only extract if the headers do not already exist
* Fix
* Use ast for charmap, fix assetclean for real this time
* Review suggestions
* BGM ids and ran formatter
* Review comments
* rename include_readonly to include_data_with_rodata
* Remove leading 0s in number directives
* Review suggestions for message_data_static
* textbox pos enum comments, rename several enum names from Message to TextBox
Co-authored-by: Thar0 <maximilianc64@gmail.com>
Co-authored-by: Zelllll <56516451+Zelllll@users.noreply.github.com>
Co-authored-by: petrie911 <pmontag@DESKTOP-LG8A167.localdomain>
Co-authored-by: Roman971 <romanlasnier@hotmail.com>
Diffstat (limited to 'src/code')
| -rw-r--r-- | src/code/audio_load.c | 6 | ||||
| -rw-r--r-- | src/code/code_800EC960.c | 427 | ||||
| -rw-r--r-- | src/code/code_800F9280.c | 1 | ||||
| -rw-r--r-- | src/code/db_camera.c | 35 | ||||
| -rw-r--r-- | src/code/fault.c | 36 | ||||
| -rw-r--r-- | src/code/ucode_disas.c | 61 | ||||
| -rw-r--r-- | src/code/z_actor.c | 56 | ||||
| -rw-r--r-- | src/code/z_camera.c | 12 | ||||
| -rw-r--r-- | src/code/z_construct.c | 115 | ||||
| -rw-r--r-- | src/code/z_debug.c | 22 | ||||
| -rw-r--r-- | src/code/z_demo.c | 25 | ||||
| -rw-r--r-- | src/code/z_en_a_keep.c | 4 | ||||
| -rw-r--r-- | src/code/z_fbdemo_wipe1.c | 4 | ||||
| -rw-r--r-- | src/code/z_game_over.c | 34 | ||||
| -rw-r--r-- | src/code/z_kaleido_setup.c | 2 | ||||
| -rw-r--r-- | src/code/z_kanfont.c | 46 | ||||
| -rw-r--r-- | src/code/z_kankyo.c | 4 | ||||
| -rw-r--r-- | src/code/z_map_mark.c | 8 | ||||
| -rw-r--r-- | src/code/z_message_PAL.c | 3305 | ||||
| -rw-r--r-- | src/code/z_onepointdemo.c | 4 | ||||
| -rw-r--r-- | src/code/z_parameter.c | 127 | ||||
| -rw-r--r-- | src/code/z_play.c | 10 | ||||
| -rw-r--r-- | src/code/z_player_lib.c | 2 | ||||
| -rw-r--r-- | src/code/z_scene.c | 2 | ||||
| -rw-r--r-- | src/code/z_sram.c | 10 |
25 files changed, 3865 insertions, 493 deletions
diff --git a/src/code/audio_load.c b/src/code/audio_load.c index 291ee5670..a29b883a9 100644 --- a/src/code/audio_load.c +++ b/src/code/audio_load.c @@ -213,7 +213,8 @@ void AudioLoad_InitSampleDmaBuffers(s32 arg0) { t2 = 3 * gAudioContext.numNotes * gAudioContext.audioBufferParameters.specUnk4; for (i = 0; i < t2; i++) { dma = &gAudioContext.sampleDmas[gAudioContext.sampleDmaCount]; - dma->ramAddr = AudioHeap_AllocAttemptExternal(&gAudioContext.notesAndBuffersPool, gAudioContext.sampleDmaBufSize); + dma->ramAddr = + AudioHeap_AllocAttemptExternal(&gAudioContext.notesAndBuffersPool, gAudioContext.sampleDmaBufSize); if (dma->ramAddr == NULL) { break; } else { @@ -243,7 +244,8 @@ void AudioLoad_InitSampleDmaBuffers(s32 arg0) { for (j = 0; j < gAudioContext.numNotes; j++) { dma = &gAudioContext.sampleDmas[gAudioContext.sampleDmaCount]; - dma->ramAddr = AudioHeap_AllocAttemptExternal(&gAudioContext.notesAndBuffersPool, gAudioContext.sampleDmaBufSize); + dma->ramAddr = + AudioHeap_AllocAttemptExternal(&gAudioContext.notesAndBuffersPool, gAudioContext.sampleDmaBufSize); if (dma->ramAddr == NULL) { break; } else { diff --git a/src/code/code_800EC960.c b/src/code/code_800EC960.c index 3dad66642..811e16447 100644 --- a/src/code/code_800EC960.c +++ b/src/code/code_800EC960.c @@ -82,9 +82,6 @@ typedef enum { #define SCROLL_PRINT_BUF_SIZE 25 -#define OCA_SONGS_SCARECROW 12 -#define OCA_SONGS_MEMORYGAME 13 - #define SFX_PLAYER_CHANNEL_OCARINA 13 extern f32 D_8012F6B4[]; // from audio_synthesis @@ -219,8 +216,8 @@ u8 sOcaMinigameAppendPos = 0; u8 sOcaMinigameEndPos = 0; u8 sOcaMinigameNoteCnts[] = { 5, 6, 8 }; -OcarinaNote sOcarinaSongs[14][20] = { - // minuet +OcarinaNote sOcarinaSongs[OCARINA_SONG_MAX][20] = { + // Minuet { { 2, 0, 18, 86, 0, 0, 0 }, { 14, 0, 18, 92, 0, 0, 0 }, @@ -231,7 +228,7 @@ OcarinaNote sOcarinaSongs[14][20] = { { 0xFF, 0, 0, 86, 0, 0, 0 }, }, - // bolero + // Bolero { { 5, 0, 15, 80, 0, 0, 0 }, { 2, 0, 15, 72, 0, 0, 0 }, @@ -244,7 +241,7 @@ OcarinaNote sOcarinaSongs[14][20] = { { 0xFF, 0, 0, 66, 0, 0, 0 }, }, - // serenade + // Serenade { { 2, 0, 36, 60, 0, 0, 0 }, { 5, 0, 36, 78, 0, 0, 0 }, @@ -255,7 +252,7 @@ OcarinaNote sOcarinaSongs[14][20] = { { 0xFF, 0, 0, 90, 0, 0, 0 }, }, - // requiem + // Requiem { { 2, 0, 45, 88, 0, 0, 0 }, { 5, 0, 23, 86, 0, 0, 0 }, @@ -266,7 +263,7 @@ OcarinaNote sOcarinaSongs[14][20] = { { 0xFF, 0, 0, 94, 0, 0, 0 }, }, - // nocturne + // Nocturne { { 11, 0, 36, 88, 0, 0, 0 }, { 9, 0, 33, 84, 0, 0, 0 }, @@ -279,7 +276,7 @@ OcarinaNote sOcarinaSongs[14][20] = { { 0xFF, 0, 0, 96, 0, 0, 0 }, }, - // prelude + // Prelude { { 14, 0, 15, 84, 0, 0, 0 }, { 9, 0, 45, 88, 0, 0, 0 }, @@ -291,7 +288,7 @@ OcarinaNote sOcarinaSongs[14][20] = { { 0xFF, 0, 0, 90, 0, 0, 0 }, }, - // sarias + // Sarias { { 5, 0, 17, 84, 0, 0, 0 }, { 9, 0, 17, 88, 0, 0, 0 }, @@ -302,7 +299,7 @@ OcarinaNote sOcarinaSongs[14][20] = { { 0xFF, 0, 0, 90, 0, 0, 0 }, }, - // epona + // Epona { { 14, 0, 18, 84, 0, 0, 0 }, { 11, 0, 18, 88, 0, 0, 0 }, @@ -313,7 +310,7 @@ OcarinaNote sOcarinaSongs[14][20] = { { 0xFF, 0, 0, 90, 0, 0, 0 }, }, - // lullaby + // Lullaby { { 11, 0, 51, 84, 0, 0, 0 }, { 14, 0, 25, 88, 0, 0, 0 }, @@ -324,7 +321,7 @@ OcarinaNote sOcarinaSongs[14][20] = { { 0xFF, 0, 0, 90, 0, 0, 0 }, }, - // suns + // Suns { { 9, 0, 12, 84, 0, 0, 0 }, { 5, 0, 13, 88, 0, 0, 0 }, @@ -336,7 +333,7 @@ OcarinaNote sOcarinaSongs[14][20] = { { 0xFF, 0, 0, 90, 0, 0, 0 }, }, - // song of time + // Song of Time { { 9, 0, 32, 84, 0, 0, 0 }, { 2, 0, 65, 88, 0, 0, 0 }, @@ -347,7 +344,7 @@ OcarinaNote sOcarinaSongs[14][20] = { { 0xFF, 0, 0, 90, 0, 0, 0 }, }, - // storms + // Storms { { 2, 0, 11, 84, 0, 0, 0 }, { 5, 0, 11, 88, 0, 0, 0 }, @@ -358,13 +355,13 @@ OcarinaNote sOcarinaSongs[14][20] = { { 0xFF, 0, 0, 90, 0, 0, 0 }, }, - // scarecrow + // Scarecrow { { 2, 0, 3, 0, 0, 0, 0 }, { 0xFF, 0, 0, 255, 0, 0, 0 }, }, - // OCA_SONGS_MEMORYGAME + // Lost Woods Memory Game { { 2, 0, 3, 0, 0, 0, 0 }, { 0xFF, 0, 0, 0, 0, 0, 0 }, @@ -372,9 +369,13 @@ OcarinaNote sOcarinaSongs[14][20] = { }; OcarinaNote* sPlaybackSong = sOcarinaSongs[0]; -u8 D_80131844[14] = { 0, 3, 2, 1, 3, 2, 1, 0, 1, 0, 1, 2, 3, 0 }; -u8* gFrogsSongPtr = D_80131844; -u8 D_80131858 = 0; // "REC" +u8 sFrogsSongNotes[14] = { + OCARINA_NOTE_A, OCARINA_NOTE_C_LEFT, OCARINA_NOTE_C_RIGHT, OCARINA_NOTE_C_DOWN, OCARINA_NOTE_C_LEFT, + OCARINA_NOTE_C_RIGHT, OCARINA_NOTE_C_DOWN, OCARINA_NOTE_A, OCARINA_NOTE_C_DOWN, OCARINA_NOTE_A, + OCARINA_NOTE_C_DOWN, OCARINA_NOTE_C_RIGHT, OCARINA_NOTE_C_LEFT, OCARINA_NOTE_A, +}; +u8* gFrogsSongPtr = sFrogsSongNotes; +u8 sRecordingState = 0; u8 sRecordSongPos = 0; u32 D_80131860 = 0; u8 D_80131864 = 0; @@ -392,26 +393,137 @@ OcarinaNote sPierresSong[108] = { }; OcarinaNote* gScarecrowCustomSongPtr = sPierresSong; -u8* gScarecrowSpawnSongPtr = (u8*)&sOcarinaSongs[OCA_SONGS_SCARECROW]; -OcarinaNote* D_80131BEC = sOcarinaSongs[OCA_SONGS_MEMORYGAME]; +u8* gScarecrowSpawnSongPtr = (u8*)&sOcarinaSongs[OCARINA_SONG_SCARECROW]; +OcarinaNote* D_80131BEC = sOcarinaSongs[OCARINA_SONG_MEMORY_GAME]; u8 sNoteValueIndexMap[16] = { 0, 0, 0, 0, 1, 1, 1, 2, 2, 2, 5, 3, 3, 4, 4, 4 }; -// clang-format off -OcarinaSongInfo gOcarinaSongNotes[14] = { - { 6, { 0, 4, 3, 2, 3, 2 }}, - { 8, { 1, 0, 1, 0, 2, 1, 2, 1 }}, - { 5, { 0, 1, 2, 2, 3 }}, - { 6, { 0, 1, 0, 2, 1, 0 }}, - { 7, { 3, 2, 2, 0, 3, 2, 1 }}, - { 6, { 4, 2, 4, 2, 3, 4 }}, - { 6, { 1, 2, 3, 1, 2, 3 }}, - { 6, { 4, 3, 2, 4, 3, 2 }}, - { 6, { 3, 4, 2, 3, 4, 2 }}, - { 6, { 2, 1, 4, 2, 1, 4 }}, - { 6, { 2, 0, 1, 2, 0, 1 }}, - { 6, { 0, 1, 4, 0, 1, 4 }}, - { 8, { 0, 0, 0, 0, 0, 0, 0, 0 }}, - { 0, { 0, 0, 0, 0, 0, 0, 0, 0 }}, +OcarinaSongInfo gOcarinaSongNotes[OCARINA_SONG_MAX] = { + // Minuet + { 6, + { + OCARINA_NOTE_A, + OCARINA_NOTE_C_UP, + OCARINA_NOTE_C_LEFT, + OCARINA_NOTE_C_RIGHT, + OCARINA_NOTE_C_LEFT, + OCARINA_NOTE_C_RIGHT, + } }, + // Bolero + { 8, + { + OCARINA_NOTE_C_DOWN, + OCARINA_NOTE_A, + OCARINA_NOTE_C_DOWN, + OCARINA_NOTE_A, + OCARINA_NOTE_C_RIGHT, + OCARINA_NOTE_C_DOWN, + OCARINA_NOTE_C_RIGHT, + OCARINA_NOTE_C_DOWN, + } }, + // Serenade + { 5, + { + OCARINA_NOTE_A, + OCARINA_NOTE_C_DOWN, + OCARINA_NOTE_C_RIGHT, + OCARINA_NOTE_C_RIGHT, + OCARINA_NOTE_C_LEFT, + } }, + // Requiem + { 6, + { + OCARINA_NOTE_A, + OCARINA_NOTE_C_DOWN, + OCARINA_NOTE_A, + OCARINA_NOTE_C_RIGHT, + OCARINA_NOTE_C_DOWN, + OCARINA_NOTE_A, + } }, + // Nocturne + { 7, + { + OCARINA_NOTE_C_LEFT, + OCARINA_NOTE_C_RIGHT, + OCARINA_NOTE_C_RIGHT, + OCARINA_NOTE_A, + OCARINA_NOTE_C_LEFT, + OCARINA_NOTE_C_RIGHT, + OCARINA_NOTE_C_DOWN, + } }, + // Prelude + { 6, + { + OCARINA_NOTE_C_UP, + OCARINA_NOTE_C_RIGHT, + OCARINA_NOTE_C_UP, + OCARINA_NOTE_C_RIGHT, + OCARINA_NOTE_C_LEFT, + OCARINA_NOTE_C_UP, + } }, + // Sarias + { 6, + { + OCARINA_NOTE_C_DOWN, + OCARINA_NOTE_C_RIGHT, + OCARINA_NOTE_C_LEFT, + OCARINA_NOTE_C_DOWN, + OCARINA_NOTE_C_RIGHT, + OCARINA_NOTE_C_LEFT, + } }, + // Epona + { 6, + { + OCARINA_NOTE_C_UP, + OCARINA_NOTE_C_LEFT, + OCARINA_NOTE_C_RIGHT, + OCARINA_NOTE_C_UP, + OCARINA_NOTE_C_LEFT, + OCARINA_NOTE_C_RIGHT, + } }, + // Lullaby + { 6, + { + OCARINA_NOTE_C_LEFT, + OCARINA_NOTE_C_UP, + OCARINA_NOTE_C_RIGHT, + OCARINA_NOTE_C_LEFT, + OCARINA_NOTE_C_UP, + OCARINA_NOTE_C_RIGHT, + } }, + // Suns + { 6, + { + OCARINA_NOTE_C_RIGHT, + OCARINA_NOTE_C_DOWN, + OCARINA_NOTE_C_UP, + OCARINA_NOTE_C_RIGHT, + OCARINA_NOTE_C_DOWN, + OCARINA_NOTE_C_UP, + } }, + // Song of Time + { 6, + { + OCARINA_NOTE_C_RIGHT, + OCARINA_NOTE_A, + OCARINA_NOTE_C_DOWN, + OCARINA_NOTE_C_RIGHT, + OCARINA_NOTE_A, + OCARINA_NOTE_C_DOWN, + } }, + // Storms + { 6, + { + OCARINA_NOTE_A, + OCARINA_NOTE_C_DOWN, + OCARINA_NOTE_C_UP, + OCARINA_NOTE_A, + OCARINA_NOTE_C_DOWN, + OCARINA_NOTE_C_UP, + } }, + // Scarecrow + { 8, { 0, 0, 0, 0, 0, 0, 0, 0 } }, + // Lost Woods Memory Game + { 0, { 0, 0, 0, 0, 0, 0, 0, 0 } }, }; // clang-format on @@ -454,9 +566,9 @@ u8 D_8016B9F3; u8 D_8016B9F4; u16 D_8016B9F6; -OcarinaStaff D_8016B9F8; // playing along staff? -OcarinaStaff sDisplayedStaff; // displayed staff? -OcarinaStaff D_8016BA00; // ?? note and status not updated, pos updated as you play +OcarinaStaff sPlayingStaff; +OcarinaStaff sDisplayedStaff; +OcarinaStaff sRecordingStaff; u32 D_8016BA04; typedef struct { s8 x; @@ -474,7 +586,7 @@ u8 sOcarinaHasStartedSong; u8 sOcarinaSongNoteStartIdx; u8 sOcarinaSongCnt; u16 sOcarinaAvailSongs; -u8 D_8016BA2E; +u8 sStaffPlayingPos; u16 sLearnSongPos[0x10]; u16 D_8016BA50[0x10]; u16 D_8016BA70[0x10]; @@ -547,7 +659,7 @@ f32 Audio_OcaAdjStick(s8 inp) { return ret; } -u8 func_800ECAF0(void) { +u8 Audio_OcaGetPlayingState(void) { u8 ret; if (D_80131878 != 0) { @@ -585,7 +697,7 @@ void func_800ECB7C(u8 songIdx) { while (savedSongIdx < 8 && scarecrowSongIdx < 0x10) { noteIdx = sOcarinaSongs[songIdx][scarecrowSongIdx++].noteIdx; if (noteIdx != 0xFF) { - gOcarinaSongNotes[OCA_SONGS_SCARECROW].notesIdx[savedSongIdx++] = sNoteValueIndexMap[noteIdx]; + gOcarinaSongNotes[OCARINA_SONG_SCARECROW].notesIdx[savedSongIdx++] = sNoteValueIndexMap[noteIdx]; } } } @@ -594,15 +706,15 @@ void func_800ECB7C(u8 songIdx) { void func_800ECC04(u16 flg) { u8 i; - if ((sOcarinaSongs[OCA_SONGS_SCARECROW][1].volume != 0xFF) && ((flg & 0xFFF) == 0xFFF)) { + if ((sOcarinaSongs[OCARINA_SONG_SCARECROW][1].volume != 0xFF) && ((flg & 0xFFF) == 0xFFF)) { flg |= 0x1000; } - if ((flg == 0xCFFF) && (sOcarinaSongs[OCA_SONGS_SCARECROW][1].volume != 0xFF)) { + if ((flg == 0xCFFF) && (sOcarinaSongs[OCARINA_SONG_SCARECROW][1].volume != 0xFF)) { flg = 0xDFFF; } - if ((flg == 0xFFF) && (sOcarinaSongs[OCA_SONGS_SCARECROW][1].volume != 0xFF)) { + if ((flg == 0xFFF) && (sOcarinaSongs[OCARINA_SONG_SCARECROW][1].volume != 0xFF)) { flg = 0x1FFF; } @@ -617,8 +729,8 @@ void func_800ECC04(u16 flg) { D_8013187C = 8; sOcarinaHasStartedSong = 0; D_80131878 = 0; - D_8016BA2E = 0; - D_8016B9F8.state = func_800ECAF0(); + sStaffPlayingPos = 0; + sPlayingStaff.state = Audio_OcaGetPlayingState(); sOcarinaInpEnabled = 1; D_80130F4C = 0; for (i = 0; i < 0xE; i++) { @@ -637,8 +749,7 @@ void func_800ECC04(u16 flg) { } if (flg & 0xD000) { - func_800ECB7C(0xC); - return; + func_800ECB7C(OCARINA_SONG_SCARECROW); } } else { D_80130F3C = 0; @@ -707,7 +818,8 @@ void func_800ECDF8(void) { if (sCurOcarinaBtnVal != sLearnSongExpectedNote[i]) { sOcarinaAvailSongs ^= sh; } - while (prevNote->noteIdx == note->noteIdx || (note->noteIdx == 0xFF && note->unk_02 != 0)) { + while (prevNote->noteIdx == note->noteIdx || + (note->noteIdx == OCARINA_NOTE_INVALID && note->unk_02 != 0)) { D_8016BA70[i] += note->unk_02; prevNote = &sOcarinaSongs[i][sLearnSongPos[i]]; note = &sOcarinaSongs[i][sLearnSongPos[i] + 1]; @@ -722,7 +834,7 @@ void func_800ECDF8(void) { } } - if (sOcarinaAvailSongs == 0 && D_8016BA2E >= D_8013187C) { + if (sOcarinaAvailSongs == 0 && sStaffPlayingPos >= D_8013187C) { sOcarinaInpEnabled = 0; if (CHECK_BTN_ANY(D_80130F3C, BTN_B) && sCurOcarinaBtnVal == sOcarinaSongs[i][0].noteIdx) { D_80130F4C = D_80130F3C; @@ -734,7 +846,7 @@ void func_800ECDF8(void) { if (!inputChanged) { sLearnSongLastBtn = sCurOcarinaBtnVal; - D_8016BA2E += sp57 + 1; + sStaffPlayingPos += sp57 + 1; } } } @@ -754,9 +866,9 @@ void func_800ED200(void) { if (sOcarinaHasStartedSong) { if ((sPrevOcarinaNoteVal != sCurOcarinaBtnVal) && (sCurOcarinaBtnVal != 0xFF)) { - D_8016BA2E++; - if (D_8016BA2E >= 9) { - D_8016BA2E = 1; + sStaffPlayingPos++; + if (sStaffPlayingPos >= 9) { + sStaffPlayingPos = 1; } if (sOcarinaSongAppendPos == 8) { @@ -839,17 +951,17 @@ void func_800ED458(s32 arg0) { sCurOcarinaBtnIdx = 4; } - if (sCurOcarinaBtnVal != 0xFF && sCurOcarinaBtnPress & 0x10 && D_80131858 != 2) { + if (sCurOcarinaBtnVal != 0xFF && sCurOcarinaBtnPress & 0x10 && sRecordingState != 2) { sCurOcarinaBtnIdx += 0x80; sCurOcarinaBtnVal++; } - if ((sCurOcarinaBtnVal != 0xFF) && (sCurOcarinaBtnPress & 0x2000) && (D_80131858 != 2)) { + if ((sCurOcarinaBtnVal != 0xFF) && (sCurOcarinaBtnPress & 0x2000) && (sRecordingState != 2)) { sCurOcarinaBtnIdx += 0x40; sCurOcarinaBtnVal--; } - if (D_80131858 != 2) { + if (sRecordingState != 2) { D_80130F2C = sCurOcaStick.y; D_80130F24 = Audio_OcaAdjStick(D_80130F2C); @@ -874,7 +986,7 @@ void func_800ED848(u8 inputEnabled) { sOcarinaInpEnabled = inputEnabled; } -void func_800ED858(u8 arg0) { +void Audio_OcaSetInstrument(u8 arg0) { if (D_80130F10 == arg0) { return; } @@ -902,25 +1014,25 @@ void func_800ED858(u8 arg0) { } } -void func_800ED93C(s8 songIdx, s8 arg1) { - if (songIdx == 0) { +void Audio_OcaSetSongPlayback(s8 songIdxPlusOne, s8 playbackState) { + if (songIdxPlusOne == 0) { sPlaybackState = 0; Audio_StopSfxById(NA_SE_OC_OCARINA); return; } - if (songIdx < 0xF) { - sPlaybackSong = sOcarinaSongs[songIdx - 1]; + if (songIdxPlusOne < 0xF) { + sPlaybackSong = sOcarinaSongs[songIdxPlusOne - 1]; } else { sPlaybackSong = sPierresSong; } - sPlaybackState = arg1; + sPlaybackState = playbackState; sNotePlaybackTimer = 0; sDisplayedNoteValue = 0xFF; sPlaybackNotePos = 0; sStaffPlaybackPos = 0; - while (sPlaybackSong[sPlaybackNotePos].noteIdx == 0xFF) { + while (sPlaybackSong[sPlaybackNotePos].noteIdx == OCARINA_NOTE_INVALID) { sPlaybackNotePos++; } } @@ -1020,7 +1132,7 @@ void func_800EDD68(u8 arg0) { s32 t; OcarinaNote* song; - if (D_80131858 == 1) { + if (sRecordingState == 1) { song = gScarecrowCustomSongPtr; } else { song = D_80131BEC; @@ -1058,26 +1170,26 @@ void func_800EDD68(u8 arg0) { song[sRecordSongPos].unk_02 = 0; - if (D_80131858 == 2) { - if (D_8016BA2E >= 8) { + if (sRecordingState == 2) { + if (sStaffPlayingPos >= 8) { for (i = 0; i < sRecordSongPos; i++) { song[i] = song[i + 1]; } - func_800ECB7C(OCA_SONGS_MEMORYGAME); + func_800ECB7C(OCARINA_SONG_MEMORY_GAME); - for (i = 0; i < OCA_SONGS_SCARECROW; i++) { + for (i = 0; i < OCARINA_SONG_SCARECROW; i++) { for (j = 0; j < 9 - gOcarinaSongNotes[i].len; j++) { for (k = 0; k < gOcarinaSongNotes[i].len && k + j < 8 && - gOcarinaSongNotes[i].notesIdx[k] == gOcarinaSongNotes[OCA_SONGS_SCARECROW].notesIdx[k + j]; + gOcarinaSongNotes[i].notesIdx[k] == gOcarinaSongNotes[OCARINA_SONG_SCARECROW].notesIdx[k + j]; k++) { ; } if (k == gOcarinaSongNotes[i].len) { - D_80131858 = 0xFF; - sOcarinaSongs[OCA_SONGS_SCARECROW][1].volume = 0xFF; + sRecordingState = 0xFF; + sOcarinaSongs[OCARINA_SONG_SCARECROW][1].volume = 0xFF; return; } } @@ -1085,8 +1197,8 @@ void func_800EDD68(u8 arg0) { i = 1; while (i < 8) { - if (gOcarinaSongNotes[OCA_SONGS_SCARECROW].notesIdx[0] != - gOcarinaSongNotes[OCA_SONGS_SCARECROW].notesIdx[i]) { + if (gOcarinaSongNotes[OCARINA_SONG_SCARECROW].notesIdx[0] != + gOcarinaSongNotes[OCARINA_SONG_SCARECROW].notesIdx[i]) { i = 9; } else { i++; @@ -1094,35 +1206,35 @@ void func_800EDD68(u8 arg0) { } if (i == 8) { - D_80131858 = 0xFF; - sOcarinaSongs[OCA_SONGS_SCARECROW][1].volume = 0xFF; + sRecordingState = 0xFF; + sOcarinaSongs[OCARINA_SONG_SCARECROW][1].volume = 0xFF; return; } for (i = 0; i < sRecordSongPos; i++) { - sOcarinaSongs[OCA_SONGS_SCARECROW][i] = sOcarinaSongs[OCA_SONGS_MEMORYGAME][i]; + sOcarinaSongs[OCARINA_SONG_SCARECROW][i] = sOcarinaSongs[OCARINA_SONG_MEMORY_GAME][i]; } sOcarinaInpEnabled = 0; } else { - sOcarinaSongs[OCA_SONGS_SCARECROW][1].volume = 0xFF; + sOcarinaSongs[OCARINA_SONG_SCARECROW][1].volume = 0xFF; } } - D_80131858 = 0; + sRecordingState = 0; } // start custom song? /** - * arg0 = 1, start - * arg0 = 0, finish - * arg0 = 2, also start? + * recordingState = 1, start long scarecrows song + * recordingState = 0, end + * recordingState = 2, also scarecrows song */ -void func_800EE170(u8 arg0) { - if ((u32)arg0 == D_80131858) { +void Audio_OcaSetRecordingState(u8 recordingState) { + if ((u32)recordingState == sRecordingState) { return; } - if (arg0 != 0) { + if (recordingState != 0) { D_80131860 = D_8016BA04; D_80131864 = 0xFF; D_80131868 = 0x57; @@ -1131,41 +1243,41 @@ void func_800EE170(u8 arg0) { D_80131874 = 0; sRecordSongPos = 0; sOcarinaInpEnabled = 1; - D_8016BA2E = 0; + sStaffPlayingPos = 0; D_8016BAA0 = sPierresSong[1]; } else { if (sRecordSongPos == 0) { sPierresSong[1] = D_8016BAA0; } else { - if (D_80131858 == 2) { - D_8016BA2E = 1; + if (sRecordingState == 2) { + sStaffPlayingPos = 1; } func_800EDD68(1); } sOcarinaInpEnabled = 0; - D_8016BA2E = 0; + sStaffPlayingPos = 0; } - D_80131858 = arg0; + sRecordingState = recordingState; } -void func_800EE29C(void) { - D_8016BA00.state = D_80131858; - D_8016BA00.pos = D_8016BA2E; - if (D_80131858 == 0xFF) { - D_80131858 = 0; +void Audio_OcaUpdateRecordingStaff(void) { + sRecordingStaff.state = sRecordingState; + sRecordingStaff.pos = sStaffPlayingPos; + if (sRecordingState == 0xFF) { + sRecordingState = 0; } } -void func_800EE2D4(void) { - D_8016B9F8.noteIdx = sCurOcarinaBtnIdx & 0x3F; - D_8016B9F8.state = func_800ECAF0(); - D_8016B9F8.pos = D_8016BA2E; +void Audio_OcaUpdatePlayingStaff(void) { + sPlayingStaff.noteIdx = sCurOcarinaBtnIdx & 0x3F; + sPlayingStaff.state = Audio_OcaGetPlayingState(); + sPlayingStaff.pos = sStaffPlayingPos; } -void func_800EE318(void) { +void Audio_OcaUpdateDisplayedStaff(void) { if ((sDisplayedNoteValue & 0x3F) < 0x10) { sDisplayedStaff.noteIdx = Audio_OcaMapNoteValue(sDisplayedNoteValue); } @@ -1181,42 +1293,42 @@ void func_800EE318(void) { } } -OcarinaStaff* func_800EE3C8(void) { - return &D_8016BA00; +OcarinaStaff* Audio_OcaGetRecordingStaff(void) { + return &sRecordingStaff; } -OcarinaStaff* func_800EE3D4(void) { - if (D_8016B9F8.state < 0xFE) { +OcarinaStaff* Audio_OcaGetPlayingStaff(void) { + if (sPlayingStaff.state < 0xFE) { D_80130F3C = 0; } - return &D_8016B9F8; + return &sPlayingStaff; } -OcarinaStaff* Audio_OcaGetDisplayStaff(void) { +OcarinaStaff* Audio_OcaGetDisplayingStaff(void) { return &sDisplayedStaff; } void func_800EE404(void) { s32 noteChanged; - if ((D_80131858 != 0) && ((D_8016BA04 - D_80131860) >= 3)) { + if ((sRecordingState != 0) && ((D_8016BA04 - D_80131860) >= 3)) { noteChanged = false; if (D_80131864 != sCurOcarinaBtnVal) { if (sCurOcarinaBtnVal != 0xFF) { - D_8016BA00.noteIdx = sCurOcarinaBtnIdx & 0x3F; - D_8016BA2E++; - } else if ((D_80131858 == 2) && (D_8016BA2E == 8)) { + sRecordingStaff.noteIdx = sCurOcarinaBtnIdx & 0x3F; + sStaffPlayingPos++; + } else if ((sRecordingState == 2) && (sStaffPlayingPos == 8)) { func_800EDD68(1); return; } - if (D_8016BA2E > 8) { - if (D_80131858 == 2) { + if (sStaffPlayingPos > 8) { + if (sRecordingState == 2) { // notes played are over 8 and in recording mode. func_800EDD68(1); return; } - D_8016BA2E = true; + sStaffPlayingPos = true; } noteChanged = true; @@ -1235,22 +1347,22 @@ void func_800EE404(void) { } } -void func_800EE57C(u8 minigameIdx) { +void Audio_OcaMemoryGameStart(u8 minigameRound) { u8 i; - if (minigameIdx > 2) { - minigameIdx = 2; + if (minigameRound > 2) { + minigameRound = 2; } sOcaMinigameAppendPos = 0; - sOcaMinigameEndPos = sOcaMinigameNoteCnts[minigameIdx]; + sOcaMinigameEndPos = sOcaMinigameNoteCnts[minigameRound]; for (i = 0; i < 3; i++) { - func_800EE5EC(); + Audio_OcaMemoryGameGenNote(); } } -s32 func_800EE5EC(void) { +s32 Audio_OcaMemoryGameGenNote(void) { u32 rnd; u8 rndNote; @@ -1261,22 +1373,22 @@ s32 func_800EE5EC(void) { rnd = Audio_NextRandom(); rndNote = sOcarinaNoteValues[rnd % 5]; - if (sOcarinaSongs[OCA_SONGS_MEMORYGAME][sOcaMinigameAppendPos - 1].noteIdx == rndNote) { + if (sOcarinaSongs[OCARINA_SONG_MEMORY_GAME][sOcaMinigameAppendPos - 1].noteIdx == rndNote) { rndNote = sOcarinaNoteValues[(rnd + 1) % 5]; } - sOcarinaSongs[OCA_SONGS_MEMORYGAME][sOcaMinigameAppendPos].noteIdx = rndNote; - sOcarinaSongs[OCA_SONGS_MEMORYGAME][sOcaMinigameAppendPos].unk_02 = 0x2D; - sOcarinaSongs[OCA_SONGS_MEMORYGAME][sOcaMinigameAppendPos].volume = 0x50; - sOcarinaSongs[OCA_SONGS_MEMORYGAME][sOcaMinigameAppendPos].vibrato = 0; - sOcarinaSongs[OCA_SONGS_MEMORYGAME][sOcaMinigameAppendPos].tone = 0; + sOcarinaSongs[OCARINA_SONG_MEMORY_GAME][sOcaMinigameAppendPos].noteIdx = rndNote; + sOcarinaSongs[OCARINA_SONG_MEMORY_GAME][sOcaMinigameAppendPos].unk_02 = 0x2D; + sOcarinaSongs[OCARINA_SONG_MEMORY_GAME][sOcaMinigameAppendPos].volume = 0x50; + sOcarinaSongs[OCARINA_SONG_MEMORY_GAME][sOcaMinigameAppendPos].vibrato = 0; + sOcarinaSongs[OCARINA_SONG_MEMORY_GAME][sOcaMinigameAppendPos].tone = 0; sOcaMinigameAppendPos++; - sOcarinaSongs[OCA_SONGS_MEMORYGAME][sOcaMinigameAppendPos].noteIdx = 0xFF; - sOcarinaSongs[OCA_SONGS_MEMORYGAME][sOcaMinigameAppendPos].unk_02 = 0; - sOcarinaSongs[OCA_SONGS_MEMORYGAME][sOcaMinigameAppendPos + 1].noteIdx = 0xFF; - sOcarinaSongs[OCA_SONGS_MEMORYGAME][sOcaMinigameAppendPos + 1].unk_02 = 0; + sOcarinaSongs[OCARINA_SONG_MEMORY_GAME][sOcaMinigameAppendPos].noteIdx = 0xFF; + sOcarinaSongs[OCARINA_SONG_MEMORY_GAME][sOcaMinigameAppendPos].unk_02 = 0; + sOcarinaSongs[OCARINA_SONG_MEMORY_GAME][sOcaMinigameAppendPos + 1].noteIdx = 0xFF; + sOcarinaSongs[OCARINA_SONG_MEMORY_GAME][sOcaMinigameAppendPos + 1].unk_02 = 0; if (1) {} return 0; } @@ -1313,9 +1425,9 @@ void func_800EE6F4(void) { sPrevOcarinaNoteVal = sCurOcarinaBtnVal; } - func_800EE2D4(); - func_800EE318(); - func_800EE29C(); + Audio_OcaUpdatePlayingStaff(); + Audio_OcaUpdateDisplayedStaff(); + Audio_OcaUpdateRecordingStaff(); } void func_800EE824(void) { @@ -1330,20 +1442,20 @@ void func_800EE824(void) { D_80131C80++; } else { D_80131C80 = 3; - func_800ED858(0); + Audio_OcaSetInstrument(0); } D_80131C88 = 1200; } break; case 1: Audio_SetSoundBanksMute(0); - func_800ED858(D_80131C84); - func_800ED93C(0xF, 1); + Audio_OcaSetInstrument(D_80131C84); + Audio_OcaSetSongPlayback(OCARINA_SONG_SCARECROW_LONG + 1, 1); D_80131C84++; D_80131C80++; break; case 2: - if (Audio_OcaGetDisplayStaff()->state == 0) { + if (Audio_OcaGetDisplayingStaff()->state == 0) { D_80131C80 = 0; } break; @@ -1351,15 +1463,15 @@ void func_800EE824(void) { } void func_800EE930(void) { - D_8016B9F8.noteIdx = 0xFF; - D_8016B9F8.state = 0xFF; - D_8016B9F8.pos = 0; - sDisplayedStaff.noteIdx = 0xFF; + sPlayingStaff.noteIdx = OCARINA_NOTE_INVALID; + sPlayingStaff.state = 0xFF; + sPlayingStaff.pos = 0; + sDisplayedStaff.noteIdx = OCARINA_NOTE_INVALID; sDisplayedStaff.state = 0; sDisplayedStaff.pos = 0; - D_8016BA00.noteIdx = 0xFF; - D_8016BA00.state = 0xFF; - D_8016BA00.pos = 0; + sRecordingStaff.noteIdx = OCARINA_NOTE_INVALID; + sRecordingStaff.state = 0xFF; + sRecordingStaff.pos = 0; D_80131880 = 0; } @@ -2022,7 +2134,8 @@ void AudioDebug_Draw(GfxPrint* printer) { sDisplayedStaff.pos); GfxPrint_SetPos(printer, 3, 5); - GfxPrint_Printf(printer, "PLAY INFO : %2d %02x %d", D_8016B9F8.noteIdx, D_8016B9F8.state, D_8016B9F8.pos); + GfxPrint_Printf(printer, "PLAY INFO : %2d %02x %d", sPlayingStaff.noteIdx, sPlayingStaff.state, + sPlayingStaff.pos); GfxPrint_SetPos(printer, 3, 6); GfxPrint_Printf(printer, "8note REC POINTER : %08x", gScarecrowSpawnSongPtr); @@ -2037,7 +2150,7 @@ void AudioDebug_Draw(GfxPrint* printer) { GfxPrint_SetPos(printer, 3, 24); GfxPrint_Printf(printer, "OCA:%02x SEQ:%04x PLAY:%02x REC:%02x", D_80130F10, D_80130F3C, sPlaybackState, - D_80131858); + sRecordingState); break; case PAGE_SFX_PARAMETER_CHANGE: @@ -2438,15 +2551,13 @@ void AudioDebug_ProcessInput_SfxSwap(void) { val = gAudioSfxSwapSource[sAudioSfxSwapSel] >> ((3 - sAudioSfxSwapNibbleSel) * 4); val = (val + step) & 0xF; gAudioSfxSwapSource[sAudioSfxSwapSel] = - (gAudioSfxSwapSource[sAudioSfxSwapSel] & - ((0xF << ((3 - sAudioSfxSwapNibbleSel) * 4)) ^ 0xFFFF)) + + (gAudioSfxSwapSource[sAudioSfxSwapSel] & ((0xF << ((3 - sAudioSfxSwapNibbleSel) * 4)) ^ 0xFFFF)) + (val << ((3 - sAudioSfxSwapNibbleSel) * 4)); } else { val = gAudioSfxSwapTarget[sAudioSfxSwapSel] >> ((7 - sAudioSfxSwapNibbleSel) * 4); val = (val + step) & 0xF; gAudioSfxSwapTarget[sAudioSfxSwapSel] = - (gAudioSfxSwapTarget[sAudioSfxSwapSel] & - ((0xF << ((7 - sAudioSfxSwapNibbleSel) * 4)) ^ 0xFFFF)) + + (gAudioSfxSwapTarget[sAudioSfxSwapSel] & ((0xF << ((7 - sAudioSfxSwapNibbleSel) * 4)) ^ 0xFFFF)) + (val << ((7 - sAudioSfxSwapNibbleSel) * 4)); } } @@ -3648,7 +3759,7 @@ void func_800F595C(u16 arg0) { u8 arg0b = arg0 & 0xFF; if (D_80130658[arg0b] & 2) { - func_800F5C64(arg0); + Audio_PlayFanfare(arg0); } else if (D_80130658[arg0b] & 4) { Audio_StartSeq(1, 0, arg0); @@ -3730,7 +3841,7 @@ void func_800F5C2C(void) { D_80130628 = NA_BGM_DISABLED; } -void func_800F5C64(u16 arg0) { +void Audio_PlayFanfare(u16 seqId) { u16 sp26; u32 sp20; u8* sp1C; @@ -3738,14 +3849,14 @@ void func_800F5C64(u16 arg0) { sp26 = func_800FA0B4(1); sp1C = func_800E5E84(sp26 & 0xFF, &sp20); - sp18 = func_800E5E84(arg0 & 0xFF, &sp20); + sp18 = func_800E5E84(seqId & 0xFF, &sp20); if ((sp26 == NA_BGM_DISABLED) || (*sp1C == *sp18)) { D_8016B9F4 = 1; } else { D_8016B9F4 = 5; Audio_SeqCmd1(1, 0); } - D_8016B9F6 = arg0; + D_8016B9F6 = seqId; } void func_800F5CF8(void) { @@ -4125,7 +4236,7 @@ void func_800F6C34(void) { sAudioExtraFilter = 0; sAudioBaseFilter2 = 0; sAudioExtraFilter2 = 0; - func_800ED858(0); + Audio_OcaSetInstrument(0); sRiverFreqScaleLerp.remainingFrames = 0; sWaterfallFreqScaleLerp.remainingFrames = 0; sRiverFreqScaleLerp.value = 1.0f; diff --git a/src/code/code_800F9280.c b/src/code/code_800F9280.c index f6eddd4a6..4d2a5143f 100644 --- a/src/code/code_800F9280.c +++ b/src/code/code_800F9280.c @@ -2,7 +2,6 @@ #include "global.h" #include "ultra64/abi.h" -extern unk_D_8016E750 D_8016E750[4]; extern u8 D_8016E348[4]; extern u32 sAudioSeqCmds[0x100]; extern u8 sSeqCmdRdPos; diff --git a/src/code/db_camera.c b/src/code/db_camera.c index 2a9738228..f686a7f37 100644 --- a/src/code/db_camera.c +++ b/src/code/db_camera.c @@ -1293,9 +1293,8 @@ void DbCamera_Update(DbCamera* dbCamera, Camera* cam) { DbCamera_SetTextValue(dbCamera->sub.lookAt[dbCamera->sub.unkIdx].cameraRoll, &D_8012D084[10], 3); func_8006376C(0x10, 0x16, (dbCamera->sub.unk_0A == 2) ? 7 : 4, D_8012D084); func_8006376C(0xF, 0x17, (dbCamera->sub.unk_0A == 3) ? 7 : 4, - (dbCamera->sub.mode == 1) ? D_8012CF14 - : (dbCamera->sub.mode == 0) ? *D_8012CF18 - : D_8012CFB0); + (dbCamera->sub.mode == 1) ? D_8012CF14 + : (dbCamera->sub.mode == 0) ? *D_8012CF18 : D_8012CFB0); if (dbCamera->sub.unk_0C) { D_8012D05C[80] = '>'; } else { @@ -1320,9 +1319,9 @@ void DbCamera_Update(DbCamera* dbCamera, Camera* cam) { if (dbCamera->sub.mode != 1) { func_8006376C(3, 0x16, - ((dbCamera->sub.unk_08 == 1) && (dbCamera->sub.unk_0A == 4) && !D_80161144) ? 7 - : !D_80161144 ? 4 - : 3, + ((dbCamera->sub.unk_08 == 1) && (dbCamera->sub.unk_0A == 4) && !D_80161144) + ? 7 + : !D_80161144 ? 4 : 3, D_8012CF30); sp110 = 'X'; DbCamera_SetTextValue(dbCamera->at.x, &sp111, 6); @@ -1333,11 +1332,10 @@ void DbCamera_Update(DbCamera* dbCamera, Camera* cam) { sp110 = 'Z'; DbCamera_SetTextValue(dbCamera->at.z, &sp111, 6); func_8006376C(3, 0x19, 2, &sp110); - func_8006376C(0x1E, 0x16, - ((dbCamera->sub.unk_08 == 1) && (dbCamera->sub.unk_0A == 4) && D_80161144) ? 7 - : D_80161144 ? 4 - : 3, - D_8012CF34); + func_8006376C( + 0x1E, 0x16, + ((dbCamera->sub.unk_08 == 1) && (dbCamera->sub.unk_0A == 4) && D_80161144) ? 7 : D_80161144 ? 4 : 3, + D_8012CF34); sp110 = 'X'; DbCamera_SetTextValue(dbCamera->eye.x, &sp111, 6); func_8006376C(0x1E, 0x17, 2, &sp110); @@ -1352,9 +1350,9 @@ void DbCamera_Update(DbCamera* dbCamera, Camera* cam) { OLib_Vec3fDiffToVecSphGeo(&spFC, sp90, sp7C); spFC.yaw -= cam->playerPosRot.rot.y; func_8006376C(3, 0x16, - ((dbCamera->sub.unk_08 == 1) && (dbCamera->sub.unk_0A == 4) && !D_80161144) ? 7 - : !D_80161144 ? 4 - : 3, + ((dbCamera->sub.unk_08 == 1) && (dbCamera->sub.unk_0A == 4) && !D_80161144) + ? 7 + : !D_80161144 ? 4 : 3, D_8012CF30); DbCamera_SetTextValue(spFC.pitch * 0.00549325f, &D_8012D0E4[10], 4); func_8006376C(3, 0x17, 3, D_8012D0E4); @@ -1364,11 +1362,10 @@ void DbCamera_Update(DbCamera* dbCamera, Camera* cam) { func_8006376C(3, 0x19, 3, D_8012D0D4); OLib_Vec3fDiffToVecSphGeo(&spFC, sp90, sp80); spFC.yaw -= cam->playerPosRot.rot.y; - func_8006376C(0x1E, 0x16, - ((dbCamera->sub.unk_08 == 1) && (dbCamera->sub.unk_0A == 4) && D_80161144) ? 7 - : D_80161144 ? 4 - : 3, - D_8012CF34); + func_8006376C( + 0x1E, 0x16, + ((dbCamera->sub.unk_08 == 1) && (dbCamera->sub.unk_0A == 4) && D_80161144) ? 7 : D_80161144 ? 4 : 3, + D_8012CF34); DbCamera_SetTextValue(spFC.pitch * 0.00549325f, &D_8012D0E4[10], 4); func_8006376C(0x1C, 0x17, 3, D_8012D0E4); DbCamera_SetTextValue(spFC.yaw * 0.00549325f, &D_8012D0F8[10], 4); diff --git a/src/code/fault.c b/src/code/fault.c index 52fe378f2..397d8bf1a 100644 --- a/src/code/fault.c +++ b/src/code/fault.c @@ -283,7 +283,7 @@ void Fault_UpdatePadImpl() { } u32 Fault_WaitForInputImpl() { - Input* curInput = &sFaultStructPtr->padInput; + Input* input = &sFaultStructPtr->padInput; s32 count = 600; u32 kDown; @@ -291,7 +291,7 @@ u32 Fault_WaitForInputImpl() { Fault_Sleep(0x10); Fault_UpdatePadImpl(); - kDown = curInput->press.button; + kDown = input->press.button; if (kDown == BTN_L) { sFaultStructPtr->faultActive = !sFaultStructPtr->faultActive; @@ -539,7 +539,7 @@ void Fault_Wait5Seconds(void) { } void Fault_WaitForButtonCombo() { - Input* curInput = &sFaultStructPtr->padInput; + Input* input = &sFaultStructPtr->padInput; s32 state; u32 s1; u32 s2; @@ -567,8 +567,8 @@ void Fault_WaitForButtonCombo() { Fault_Sleep(0x10); Fault_UpdatePadImpl(); - kDown = curInput->press.button; - kCur = curInput->cur.button; + kDown = input->press.button; + kCur = input->cur.button; if ((kCur == 0) && (s1 == s2)) { s1 = 0; @@ -717,7 +717,7 @@ void Fault_DrawMemDumpPage(const char* title, u32* addr, u32 param_3) { } void Fault_DrawMemDump(u32 pc, u32 sp, u32 unk0, u32 unk1) { - Input* curInput = &sFaultStructPtr->padInput; + Input* input = &sFaultStructPtr->padInput; u32 addr = pc; s32 count; u32 off; @@ -743,7 +743,7 @@ void Fault_DrawMemDump(u32 pc, u32 sp, u32 unk0, u32 unk1) { count--; Fault_Sleep(0x10); Fault_UpdatePadImpl(); - if (CHECK_BTN_ALL(curInput->press.button, BTN_L)) { + if (CHECK_BTN_ALL(input->press.button, BTN_L)) { sFaultStructPtr->faultActive = false; } } @@ -751,40 +751,40 @@ void Fault_DrawMemDump(u32 pc, u32 sp, u32 unk0, u32 unk1) { do { Fault_Sleep(0x10); Fault_UpdatePadImpl(); - } while (curInput->press.button == 0); + } while (input->press.button == 0); - if (CHECK_BTN_ALL(curInput->press.button, BTN_START) || CHECK_BTN_ALL(curInput->cur.button, BTN_A)) { + if (CHECK_BTN_ALL(input->press.button, BTN_START) || CHECK_BTN_ALL(input->cur.button, BTN_A)) { return; } off = 0x10; - if (CHECK_BTN_ALL(curInput->cur.button, BTN_Z)) { + if (CHECK_BTN_ALL(input->cur.button, BTN_Z)) { off = 0x100; } - if (CHECK_BTN_ALL(curInput->cur.button, BTN_B)) { + if (CHECK_BTN_ALL(input->cur.button, BTN_B)) { off <<= 8; } - if (CHECK_BTN_ALL(curInput->press.button, BTN_DUP)) { + if (CHECK_BTN_ALL(input->press.button, BTN_DUP)) { addr -= off; } - if (CHECK_BTN_ALL(curInput->press.button, BTN_DDOWN)) { + if (CHECK_BTN_ALL(input->press.button, BTN_DDOWN)) { addr += off; } - if (CHECK_BTN_ALL(curInput->press.button, BTN_CUP)) { + if (CHECK_BTN_ALL(input->press.button, BTN_CUP)) { addr = pc; } - if (CHECK_BTN_ALL(curInput->press.button, BTN_CDOWN)) { + if (CHECK_BTN_ALL(input->press.button, BTN_CDOWN)) { addr = sp; } - if (CHECK_BTN_ALL(curInput->press.button, BTN_CLEFT)) { + if (CHECK_BTN_ALL(input->press.button, BTN_CLEFT)) { addr = unk0; } - if (CHECK_BTN_ALL(curInput->press.button, BTN_CRIGHT)) { + if (CHECK_BTN_ALL(input->press.button, BTN_CRIGHT)) { addr = unk1; } - } while (!CHECK_BTN_ALL(curInput->press.button, BTN_L)); + } while (!CHECK_BTN_ALL(input->press.button, BTN_L)); sFaultStructPtr->faultActive = true; } diff --git a/src/code/ucode_disas.c b/src/code/ucode_disas.c index f94fa5137..ded32479a 100644 --- a/src/code/ucode_disas.c +++ b/src/code/ucode_disas.c @@ -708,10 +708,11 @@ void UCodeDisas_Disassemble(UCodeDisas* this, GfxMod* ptr) { Gfillrect setscissor = ptr->fillrect; const char* modeStr; - modeStr = (setscissor.pad == G_SC_NON_INTERLACE) ? "G_SC_NON_INTERLACE" - : (setscissor.pad == G_SC_ODD_INTERLACE) ? "G_SC_ODD_INTERLACE" - : (setscissor.pad == G_SC_EVEN_INTERLACE) ? "G_SC_EVEN_INTERLACE" - : "???"; + modeStr = (setscissor.pad == G_SC_NON_INTERLACE) + ? "G_SC_NON_INTERLACE" + : (setscissor.pad == G_SC_ODD_INTERLACE) + ? "G_SC_ODD_INTERLACE" + : (setscissor.pad == G_SC_EVEN_INTERLACE) ? "G_SC_EVEN_INTERLACE" : "???"; if ((setscissor.x0frac | setscissor.y0frac | setscissor.x1frac | setscissor.y1frac)) { if (1) {} @@ -737,15 +738,12 @@ void UCodeDisas_Disassemble(UCodeDisas* this, GfxMod* ptr) { u32 siz = ((curGfx->words.w0 & 0x180000) >> 0x13) & 0xff; DISAS_LOG("gsDPSetColorImage(G_IM_FMT_%s, G_IM_SIZ_%s, %d, 0x%08x(0x%08x) ),", - (fmt == G_IM_FMT_RGBA) ? "RGBA" - : (fmt == G_IM_FMT_YUV) ? "YUV" - : (fmt == G_IM_FMT_CI) ? "CI" - : (fmt == G_IM_FMT_IA) ? "IA" - : "I", - (siz == G_IM_SIZ_4b) ? "4b" - : (siz == G_IM_SIZ_8b) ? "8b" - : (siz == G_IM_SIZ_16b) ? "16b" - : "32b", + (fmt == G_IM_FMT_RGBA) + ? "RGBA" + : (fmt == G_IM_FMT_YUV) ? "YUV" + : (fmt == G_IM_FMT_CI) ? "CI" : (fmt == G_IM_FMT_IA) ? "IA" : "I", + (siz == G_IM_SIZ_4b) ? "4b" + : (siz == G_IM_SIZ_8b) ? "8b" : (siz == G_IM_SIZ_16b) ? "16b" : "32b", (curGfx->dma.len & 0xfff) + 1, curGfx->setimg.dram, addr); if (this->pipeSyncRequired) { @@ -768,15 +766,12 @@ void UCodeDisas_Disassemble(UCodeDisas* this, GfxMod* ptr) { u32 siz = ((curGfx->words.w0 & 0x180000) >> 0x13) & 0xff; DISAS_LOG("gsDPSetTextureImage(G_IM_FMT_%s, G_IM_SIZ_%s, %d, 0x%08x(0x%08x)),", - (fmt == G_IM_FMT_RGBA) ? "RGBA" - : (fmt == G_IM_FMT_YUV) ? "YUV" - : (fmt == G_IM_FMT_CI) ? "CI" - : (fmt == G_IM_FMT_IA) ? "IA" - : "I", - (siz == G_IM_SIZ_4b) ? "4b" - : (siz == G_IM_SIZ_8b) ? "8b" - : (siz == G_IM_SIZ_16b) ? "16b" - : "32b", + (fmt == G_IM_FMT_RGBA) + ? "RGBA" + : (fmt == G_IM_FMT_YUV) ? "YUV" + : (fmt == G_IM_FMT_CI) ? "CI" : (fmt == G_IM_FMT_IA) ? "IA" : "I", + (siz == G_IM_SIZ_4b) ? "4b" + : (siz == G_IM_SIZ_8b) ? "8b" : (siz == G_IM_SIZ_16b) ? "16b" : "32b", (curGfx->dma.len & 0xfff) + 1, curGfx->setimg.dram, addr); } break; @@ -994,11 +989,15 @@ void UCodeDisas_Disassemble(UCodeDisas* this, GfxMod* ptr) { case G_MODIFYVTX: { DISAS_LOG("gsSPModifyVertex(%d, %s, %08x),", curGfx->dma.par, - (curGfx->dma.len == G_MWO_POINT_RGBA) ? "G_MWO_POINT_RGBA" - : (curGfx->dma.len == G_MWO_POINT_ST) ? "G_MWO_POINT_ST" - : (curGfx->dma.len == G_MWO_POINT_XYSCREEN) ? "G_MWO_POINT_XYSCREEN" - : (curGfx->dma.len == G_MWO_POINT_ZSCREEN) ? "G_MWO_POINT_ZSCREEN" - : "G_MWO_POINT_????", + (curGfx->dma.len == G_MWO_POINT_RGBA) + ? "G_MWO_POINT_RGBA" + : (curGfx->dma.len == G_MWO_POINT_ST) + ? "G_MWO_POINT_ST" + : (curGfx->dma.len == G_MWO_POINT_XYSCREEN) + ? "G_MWO_POINT_XYSCREEN" + : (curGfx->dma.len == G_MWO_POINT_ZSCREEN) + ? "G_MWO_POINT_ZSCREEN" + : "G_MWO_POINT_????", curGfx->dma.addr); this->vtxCnt += curGfx->dma.par; this->spvtxCnt++; @@ -1211,9 +1210,7 @@ void UCodeDisas_Disassemble(UCodeDisas* this, GfxMod* ptr) { } } break; - default: { - DISAS_LOG("AnyDisplayList(),"); - } break; + default: { DISAS_LOG("AnyDisplayList(),"); } break; } } break; @@ -1338,9 +1335,7 @@ void UCodeDisas_Disassemble(UCodeDisas* this, GfxMod* ptr) { DISAS_LOG("gsSPObjRenderMode(0x%08x),", dma.addr); } break; - default: { - DISAS_LOG("AnyDisplayList(),"); - } break; + default: { DISAS_LOG("AnyDisplayList(),"); } break; } } } diff --git a/src/code/z_actor.c b/src/code/z_actor.c index fdd8bfd43..36533a77c 100644 --- a/src/code/z_actor.c +++ b/src/code/z_actor.c @@ -1489,7 +1489,7 @@ s32 func_8002F0C8(Actor* actor, Player* player, s32 flag) { return false; } -u32 func_8002F194(Actor* actor, GlobalContext* globalCtx) { +u32 Actor_ProcessTalkRequest(Actor* actor, GlobalContext* globalCtx) { if (actor->flags & 0x100) { actor->flags &= ~0x100; return true; @@ -1530,8 +1530,8 @@ s32 func_8002F2F4(Actor* actor, GlobalContext* globalCtx) { return func_8002F2CC(actor, globalCtx, var1); } -u32 func_8002F334(Actor* actor, GlobalContext* globalCtx) { - if (func_8010BDBC(&globalCtx->msgCtx) == 2) { +u32 Actor_TextboxIsClosing(Actor* actor, GlobalContext* globalCtx) { + if (Message_GetState(&globalCtx->msgCtx) == TEXT_STATE_CLOSING) { return true; } else { return false; @@ -1544,13 +1544,13 @@ s8 func_8002F368(GlobalContext* globalCtx) { return player->exchangeItemId; } -void func_8002F374(GlobalContext* globalCtx, Actor* actor, s16* x, s16* y) { - Vec3f sp1C; - f32 sp18; +void Actor_GetScreenPos(GlobalContext* globalCtx, Actor* actor, s16* x, s16* y) { + Vec3f projectedPos; + f32 w; - func_8002BE04(globalCtx, &actor->focus.pos, &sp1C, &sp18); - *x = sp1C.x * sp18 * 160.0f + 160.0f; - *y = sp1C.y * sp18 * -120.0f + 120.0f; + func_8002BE04(globalCtx, &actor->focus.pos, &projectedPos, &w); + *x = projectedPos.x * w * (SCREEN_WIDTH / 2) + (SCREEN_WIDTH / 2); + *y = projectedPos.y * w * -(SCREEN_HEIGHT / 2) + (SCREEN_HEIGHT / 2); } u32 Actor_HasParent(Actor* actor, GlobalContext* globalCtx) { @@ -2862,7 +2862,7 @@ s32 func_80032880(GlobalContext* globalCtx, Actor* actor) { s16 sp1E; s16 sp1C; - func_8002F374(globalCtx, actor, &sp1E, &sp1C); + Actor_GetScreenPos(globalCtx, actor, &sp1E, &sp1C); return (sp1E > -20) && (sp1E < 340) && (sp1C > -160) && (sp1C < 400); } @@ -3585,12 +3585,12 @@ Hilite* func_8003435C(Vec3f* object, GlobalContext* globalCtx) { return func_8002EB44(object, &globalCtx->view.eye, &lightDir, globalCtx->state.gfxCtx); } -s32 func_800343CC(GlobalContext* globalCtx, Actor* actor, s16* arg2, f32 arg3, callback1_800343CC unkFunc1, +s32 func_800343CC(GlobalContext* globalCtx, Actor* actor, s16* arg2, f32 interactRange, callback1_800343CC unkFunc1, callback2_800343CC unkFunc2) { - s16 sp26; - s16 sp24; + s16 x; + s16 y; - if (func_8002F194(actor, globalCtx)) { + if (Actor_ProcessTalkRequest(actor, globalCtx)) { *arg2 = 1; return true; } @@ -3600,13 +3600,13 @@ s32 func_800343CC(GlobalContext* globalCtx, Actor* actor, s16* arg2, f32 arg3, c return false; } - func_8002F374(globalCtx, actor, &sp26, &sp24); + Actor_GetScreenPos(globalCtx, actor, &x, &y); - if ((sp26 < 0) || (sp26 > SCREEN_WIDTH) || (sp24 < 0) || (sp24 > SCREEN_HEIGHT)) { + if ((x < 0) || (x > SCREEN_WIDTH) || (y < 0) || (y > SCREEN_HEIGHT)) { return false; } - if (!func_8002F2CC(actor, globalCtx, arg3)) { + if (!func_8002F2CC(actor, globalCtx, interactRange)) { return false; } @@ -4128,7 +4128,7 @@ void func_800359B8(Actor* actor, s16 arg1, Vec3s* arg2) { } void func_80035B18(GlobalContext* globalCtx, Actor* actor, u16 textId) { - func_8010B720(globalCtx, textId); + Message_ContinueTextbox(globalCtx, textId); actor->textId = textId; } @@ -5203,7 +5203,7 @@ s32 func_800374E0(GlobalContext* globalCtx, Actor* actor, u16 textId) { ret = 0; break; case 0x1041: - if (msgCtx->unk_E2FA == 0x1035) { + if (msgCtx->choiceTextId == 0x1035) { if (msgCtx->choiceIndex == 0) { func_80035B18(globalCtx, actor, 0x1036); Flags_SetInfTable(0x2A); @@ -5213,7 +5213,7 @@ s32 func_800374E0(GlobalContext* globalCtx, Actor* actor, u16 textId) { Flags_SetInfTable(0x2B); } } - if (msgCtx->unk_E2FA == 0x1038) { + if (msgCtx->choiceTextId == 0x1038) { if (msgCtx->choiceIndex == 0) { func_80035B18(globalCtx, actor, 0x1039); Flags_SetInfTable(0x2E); @@ -5362,16 +5362,16 @@ s32 func_80037CB8(GlobalContext* globalCtx, Actor* actor, s16 arg2) { MessageContext* msgCtx = &globalCtx->msgCtx; s32 ret = false; - switch (func_8010BDBC(msgCtx)) { - case 2: + switch (Message_GetState(msgCtx)) { + case TEXT_STATE_CLOSING: func_80037C5C(globalCtx, arg2, actor->textId); ret = true; break; - case 4: - case 5: - if (func_80106BC8(globalCtx) && func_80037C94(globalCtx, actor, arg2)) { + case TEXT_STATE_CHOICE: + case TEXT_STATE_EVENT: + if (Message_ShouldAdvance(globalCtx) && func_80037C94(globalCtx, actor, arg2)) { Audio_PlaySoundGeneral(NA_SE_SY_CANCEL, &D_801333D4, 4, &D_801333E0, &D_801333E0, &D_801333E8); - msgCtx->msgMode = 0x36; + msgCtx->msgMode = MSGMODE_TEXT_CLOSING; ret = true; } break; @@ -5386,7 +5386,7 @@ s32 func_80037D98(GlobalContext* globalCtx, Actor* actor, s16 arg2, s32* arg3) { s16 sp2A; s16 abs_var; - if (func_8002F194(actor, globalCtx)) { + if (Actor_ProcessTalkRequest(actor, globalCtx)) { *arg3 = 1; return true; } @@ -5398,7 +5398,7 @@ s32 func_80037D98(GlobalContext* globalCtx, Actor* actor, s16 arg2, s32* arg3) { return false; } - func_8002F374(globalCtx, actor, &sp2C, &sp2A); + Actor_GetScreenPos(globalCtx, actor, &sp2C, &sp2A); if (0) {} // Necessary to match diff --git a/src/code/z_camera.c b/src/code/z_camera.c index e22724903..1e33d1918 100644 --- a/src/code/z_camera.c +++ b/src/code/z_camera.c @@ -1690,9 +1690,9 @@ s32 Camera_Normal2(Camera* camera) { anim->unk_20 = BGCAM_ROT(bgData).x; anim->unk_22 = BGCAM_ROT(bgData).y; anim->unk_24 = playerPosRot->pos.y; - anim->unk_1C = BGCAM_FOV(bgData) == -1 ? norm2->unk_14 - : BGCAM_FOV(bgData) >= 0x169 ? PCT(BGCAM_FOV(bgData)) - : BGCAM_FOV(bgData); + anim->unk_1C = BGCAM_FOV(bgData) == -1 + ? norm2->unk_14 + : BGCAM_FOV(bgData) >= 0x169 ? PCT(BGCAM_FOV(bgData)) : BGCAM_FOV(bgData); anim->unk_28 = BGCAM_JFIFID(bgData) == -1 ? 0 : BGCAM_JFIFID(bgData); @@ -2920,9 +2920,7 @@ s32 Camera_Battle1(Camera* camera) { } anim->roll += (((OREG(36) * camera->speedRatio) * (1.0f - distRatio)) - anim->roll) * PCT(OREG(37)); camera->roll = DEGF_TO_BINANG(anim->roll); - camera->fov = Camera_LERPCeilF((player->swordState != 0 ? 0.8f - : gSaveContext.health <= 0x10 ? 0.8f - : 1.0f) * + camera->fov = Camera_LERPCeilF((player->swordState != 0 ? 0.8f : gSaveContext.health <= 0x10 ? 0.8f : 1.0f) * (fov - ((fov * 0.05f) * distRatio)), camera->fov, camera->fovUpdateRate, 1.0f); } @@ -5829,7 +5827,7 @@ s32 Camera_Demo5(Camera* camera) { Actor_GetFocus(&camera->targetPosRot, camera->target); OLib_Vec3fDiffToVecSphGeo(&playerTargetGeo, &camera->targetPosRot.pos, &camera->playerPosRot.pos); D_8011D3AC = camera->target->category; - func_8002F374(camera->globalCtx, camera->target, &sp78.yaw, &sp78.pitch); + Actor_GetScreenPos(camera->globalCtx, camera->target, &sp78.yaw, &sp78.pitch); eyeTargetDist = OLib_Vec3fDist(&camera->targetPosRot.pos, &camera->eye); OLib_Vec3fDiffToVecSphGeo(&eyePlayerGeo, &playerhead.pos, &camera->eyeNext); sp4A = eyePlayerGeo.yaw - playerTargetGeo.yaw; diff --git a/src/code/z_construct.c b/src/code/z_construct.c index fb2241d2f..7c3947f74 100644 --- a/src/code/z_construct.c +++ b/src/code/z_construct.c @@ -47,9 +47,9 @@ void func_801109B0(GlobalContext* globalCtx) { ASSERT(interfaceCtx->doActionSegment != NULL, "parameter->do_actionSegment != NULL", "../z_construct.c", 169); - if (gSaveContext.language == 0) { + if (gSaveContext.language == LANGUAGE_ENG) { doActionOffset = 0; - } else if (gSaveContext.language == 1) { + } else if (gSaveContext.language == LANGUAGE_GER) { doActionOffset = 0x2B80; } else { doActionOffset = 0x5700; @@ -58,9 +58,9 @@ void func_801109B0(GlobalContext* globalCtx) { DmaMgr_SendRequest1(interfaceCtx->doActionSegment, (u32)_do_action_staticSegmentRomStart + doActionOffset, 0x300, "../z_construct.c", 174); - if (gSaveContext.language == 0) { + if (gSaveContext.language == LANGUAGE_ENG) { doActionOffset = 0x480; - } else if (gSaveContext.language == 1) { + } else if (gSaveContext.language == LANGUAGE_GER) { doActionOffset = 0x3000; } else { doActionOffset = 0x5B80; @@ -164,18 +164,18 @@ void func_801109B0(GlobalContext* globalCtx) { R_A_BTN_COLOR(2) = 50; } -void func_80110F68(GlobalContext* globalCtx) { +void Message_Init(GlobalContext* globalCtx) { MessageContext* msgCtx = &globalCtx->msgCtx; s32 pad; - func_8011040C(); + Message_SetTables(); - globalCtx->msgCtx.unk_E3EE = 0; + globalCtx->msgCtx.ocarinaMode = OCARINA_MODE_00; - msgCtx->msgMode = 0; - msgCtx->unk_E300 = 0; - msgCtx->unk_E2F8 = msgCtx->unk_E3E4 = msgCtx->choiceIndex = msgCtx->unk_E3F0 = msgCtx->unk_E3D6 = 0; - msgCtx->unk_E3E2 = 0xFF; + msgCtx->msgMode = MSGMODE_NONE; + msgCtx->msgLength = 0; + msgCtx->textId = msgCtx->textboxEndType = msgCtx->choiceIndex = msgCtx->ocarinaAction = msgCtx->textUnskippable = 0; + msgCtx->textColorAlpha = 255; View_Init(&msgCtx->view, globalCtx->state.gfxCtx); @@ -195,10 +195,10 @@ void func_80111070(void) { YREG(8) = 10; YREG(14) = 0; YREG(15) = 0; - YREG(16) = 0; - YREG(17) = 0; - YREG(22) = 50; - YREG(23) = 0; + R_TEXTBOX_TEXWIDTH = 0; + R_TEXTBOX_TEXHEIGHT = 0; + R_TEXTBOX_WIDTH = 50; + R_TEXTBOX_HEIGHT = 0; YREG(24) = -60; YREG(25) = 13; YREG(26) = 15; @@ -240,15 +240,15 @@ void func_80111070(void) { YREG(68) = 0; YREG(69) = 0; YREG(70) = 0; - YREG(71) = -6; - YREG(72) = 10; + R_TEXTBOX_ICON_XPOS = -6; + R_TEXTBOX_ICON_YPOS = 10; YREG(73) = -8; YREG(74) = 8; - YREG(75) = 24; + R_TEXTBOX_ICON_SIZE = 24; YREG(76) = 32; YREG(77) = 0; - YREG(78) = 0; - YREG(79) = 48; + R_MESSAGE_DEBUGGER_SELECT = 0; + R_MESSAGE_DEBUGGER_TEXTID = 48; YREG(80) = 450; YREG(81) = 0; YREG(82) = -15; @@ -388,30 +388,30 @@ void func_80111070(void) { R_MAGIC_FILL_X = 26; XREG(52) = 0; XREG(53) = 1; - XREG(54) = 65; - XREG(55) = 60; - XREG(56) = 16; - XREG(57) = 80; + R_TEXT_INIT_XPOS = 65; + R_TEXT_INIT_YPOS = 60; + R_TEXT_LINE_SPACING = 16; + R_TEXT_CHAR_SCALE = 80; XREG(58) = 80; XREG(59) = 12; - XREG(60) = 1; - XREG(61) = 3; + R_TEXT_DROP_SHADOW_OFFSET = 1; + R_TEXTBOX_BG_YPOS = 3; XREG(62) = 0; XREG(63) = 100; - XREG(64) = 158; - XREG(65) = 102; - XREG(66) = 48; - XREG(67) = 54; - XREG(68) = 70; - XREG(69) = 86; + R_TEXTBOX_END_XPOS = 158; + R_TEXTBOX_END_YPOS = 102; + R_TEXT_CHOICE_XPOS = 48; + R_TEXT_CHOICE_YPOS(0) = 54; + R_TEXT_CHOICE_YPOS(1) = 70; + R_TEXT_CHOICE_YPOS(2) = 86; XREG(70) = -300; XREG(71) = 0; - XREG(72) = 54; - XREG(73) = 48; - XREG(74) = 128; - XREG(75) = 64; - XREG(76) = 2048; - XREG(77) = 512; + R_TEXTBOX_X_TARGET = 54; + R_TEXTBOX_Y_TARGET = 48; + R_TEXTBOX_WIDTH_TARGET = 128; + R_TEXTBOX_HEIGHT_TARGET = 64; + R_TEXTBOX_TEXWIDTH_TARGET = 2048; + R_TEXTBOX_TEXHEIGHT_TARGET = 512; XREG(78) = 96; XREG(79) = 98; XREG(80) = 0; @@ -507,15 +507,15 @@ void func_80111070(void) { WREG(95) = 6; if (gSaveContext.gameMode == 0) { - VREG(0) = 52; - VREG(1) = 36; + R_TEXTBOX_X = 52; + R_TEXTBOX_Y = 36; VREG(2) = 214; VREG(3) = 76; VREG(4) = 304; VREG(5) = 430; VREG(6) = 1; - VREG(7) = 78; - VREG(8) = 166; + R_TEXTBOX_CLEF_XPOS = 78; + R_TEXTBOX_CLEF_YPOS = 166; VREG(9) = 40; R_COMPASS_SCALE_X = 32; R_COMPASS_SCALE_Y = 32; @@ -533,28 +533,31 @@ void func_80111070(void) { VREG(25) = 0; VREG(26) = 0; VREG(27) = 0; - VREG(28) = 98; - VREG(29) = 18; + R_OCARINA_NOTES_XPOS = 98; + R_OCARINA_NOTES_XPOS_OFFSET = 18; VREG(30) = 0; VREG(31) = 0; VREG(32) = 0; - VREG(33) = 70; - VREG(34) = 255; - VREG(35) = 80; - VREG(36) = 70; - VREG(37) = 255; - VREG(38) = 80; + + R_TEXT_ADJUST_COLOR_1_R = 70; + R_TEXT_ADJUST_COLOR_1_G = 255; + R_TEXT_ADJUST_COLOR_1_B = 80; + + R_TEXT_ADJUST_COLOR_2_R = 70; + R_TEXT_ADJUST_COLOR_2_G = 255; + R_TEXT_ADJUST_COLOR_2_B = 80; + VREG(40) = 9; VREG(42) = 250; VREG(43) = 440; VREG(44) = 10; - VREG(45) = 190; - VREG(46) = 184; - VREG(47) = 176; - VREG(48) = 172; - VREG(49) = 170; + R_OCARINA_NOTES_YPOS(0) = 190; + R_OCARINA_NOTES_YPOS(1) = 184; + R_OCARINA_NOTES_YPOS(2) = 176; + R_OCARINA_NOTES_YPOS(3) = 172; + R_OCARINA_NOTES_YPOS(4) = 170; VREG(50) = 30; - VREG(51) = 0; + R_OCARINA_NOTES_YPOS_OFFSET = 0; VREG(52) = -16; VREG(53) = 230; VREG(54) = 230; diff --git a/src/code/z_debug.c b/src/code/z_debug.c index 55eedb17f..21b0fee3e 100644 --- a/src/code/z_debug.c +++ b/src/code/z_debug.c @@ -151,15 +151,19 @@ void func_8006390C(Input* input) { gGameInfo->dpadLast = dpad; } - increment = CHECK_BTN_ANY(dpad, BTN_DRIGHT) ? (CHECK_BTN_ALL(input->cur.button, BTN_A | BTN_B) ? 1000 - : CHECK_BTN_ALL(input->cur.button, BTN_A) ? 100 - : CHECK_BTN_ALL(input->cur.button, BTN_B) ? 10 - : 1) - : CHECK_BTN_ANY(dpad, BTN_DLEFT) ? (CHECK_BTN_ALL(input->cur.button, BTN_A | BTN_B) ? -1000 - : CHECK_BTN_ALL(input->cur.button, BTN_A) ? -100 - : CHECK_BTN_ALL(input->cur.button, BTN_B) ? -10 - : -1) - : 0; + increment = CHECK_BTN_ANY(dpad, BTN_DRIGHT) + ? (CHECK_BTN_ALL(input->cur.button, BTN_A | BTN_B) + ? 1000 + : CHECK_BTN_ALL(input->cur.button, BTN_A) + ? 100 + : CHECK_BTN_ALL(input->cur.button, BTN_B) ? 10 : 1) + : CHECK_BTN_ANY(dpad, BTN_DLEFT) + ? (CHECK_BTN_ALL(input->cur.button, BTN_A | BTN_B) + ? -1000 + : CHECK_BTN_ALL(input->cur.button, BTN_A) + ? -100 + : CHECK_BTN_ALL(input->cur.button, BTN_B) ? -10 : -1) + : 0; gGameInfo->data[gGameInfo->regCur + regGroup] += increment; if (CHECK_BTN_ANY(dpad, BTN_DUP)) { diff --git a/src/code/z_demo.c b/src/code/z_demo.c index 817f0d70e..413d84e07 100644 --- a/src/code/z_demo.c +++ b/src/code/z_demo.c @@ -1489,11 +1489,11 @@ void Cutscene_Command_Textbox(GlobalContext* globalCtx, CutsceneContext* csCtx, if (D_8011E1C0 != cmd->base) { D_8011E1C0 = cmd->base; if ((cmd->type == 3) && CHECK_QUEST_ITEM(QUEST_ZORA_SAPPHIRE)) { - func_8010B680(globalCtx, cmd->textId1, NULL); + Message_StartTextbox(globalCtx, cmd->textId1, NULL); } else if ((cmd->type == 4) && CHECK_QUEST_ITEM(QUEST_GORON_RUBY)) { - func_8010B680(globalCtx, cmd->textId1, NULL); + Message_StartTextbox(globalCtx, cmd->textId1, NULL); } else { - func_8010B680(globalCtx, cmd->base, NULL); + Message_StartTextbox(globalCtx, cmd->base, NULL); } return; } @@ -1507,37 +1507,38 @@ void Cutscene_Command_Textbox(GlobalContext* globalCtx, CutsceneContext* csCtx, if (csCtx->frames >= cmd->endFrame) { originalCsFrames = csCtx->frames; - dialogState = func_8010BDBC(&globalCtx->msgCtx); + dialogState = Message_GetState(&globalCtx->msgCtx); - if ((dialogState != 2) && (dialogState != 0) && (dialogState != 7) && (dialogState != 8)) { + if ((dialogState != TEXT_STATE_CLOSING) && (dialogState != TEXT_STATE_NONE) && + (dialogState != TEXT_STATE_SONG_DEMO_DONE) && (dialogState != TEXT_STATE_8)) { csCtx->frames--; - if ((dialogState == 4) && (func_80106BC8(globalCtx) != 0)) { + if ((dialogState == TEXT_STATE_CHOICE) && Message_ShouldAdvance(globalCtx)) { if (globalCtx->msgCtx.choiceIndex == 0) { if (cmd->textId1 != 0xFFFF) { - func_8010B720(globalCtx, cmd->textId1); + Message_ContinueTextbox(globalCtx, cmd->textId1); } else { csCtx->frames++; } } else { if (cmd->textId2 != 0xFFFF) { - func_8010B720(globalCtx, cmd->textId2); + Message_ContinueTextbox(globalCtx, cmd->textId2); } else { csCtx->frames++; } } } - if (dialogState == 9) { + if (dialogState == TEXT_STATE_9) { if (cmd->textId1 != 0xFFFF) { - func_8010B720(globalCtx, cmd->textId1); + Message_ContinueTextbox(globalCtx, cmd->textId1); } else { csCtx->frames++; } } - if (dialogState == 5) { - if (func_80106BC8(globalCtx) != 0) { + if (dialogState == TEXT_STATE_EVENT) { + if (Message_ShouldAdvance(globalCtx)) { func_8010BD58(globalCtx, cmd->base); } } diff --git a/src/code/z_en_a_keep.c b/src/code/z_en_a_keep.c index 5f08d1821..4dc68d04a 100644 --- a/src/code/z_en_a_keep.c +++ b/src/code/z_en_a_keep.c @@ -199,7 +199,7 @@ void EnAObj_Destroy(Actor* thisx, GlobalContext* globalCtx) { } void EnAObj_WaitFinishedTalking(EnAObj* this, GlobalContext* globalCtx) { - if (func_8002F334(&this->dyna.actor, globalCtx)) { + if (Actor_TextboxIsClosing(&this->dyna.actor, globalCtx)) { EnAObj_SetupWaitTalk(this, this->dyna.actor.params); } } @@ -215,7 +215,7 @@ void EnAObj_WaitTalk(EnAObj* this, GlobalContext* globalCtx) { relYawTowardsPlayer = this->dyna.actor.yawTowardsPlayer - this->dyna.actor.shape.rot.y; if (ABS(relYawTowardsPlayer) < 0x2800 || (this->dyna.actor.params == A_OBJ_SIGNPOST_ARROW && ABS(relYawTowardsPlayer) > 0x5800)) { - if (func_8002F194(&this->dyna.actor, globalCtx)) { + if (Actor_ProcessTalkRequest(&this->dyna.actor, globalCtx)) { EnAObj_SetupAction(this, EnAObj_WaitFinishedTalking); } else { func_8002F2F4(&this->dyna.actor, globalCtx); diff --git a/src/code/z_fbdemo_wipe1.c b/src/code/z_fbdemo_wipe1.c index fcf96994a..ca238643b 100644 --- a/src/code/z_fbdemo_wipe1.c +++ b/src/code/z_fbdemo_wipe1.c @@ -13,8 +13,8 @@ Gfx sWipeDList[] = { gsDPSetCombineLERP(TEXEL1, TEXEL0, PRIM_LOD_FRAC, TEXEL0, TEXEL1, TEXEL0, PRIM_LOD_FRAC, TEXEL0, COMBINED, 0, PRIMITIVE, 0, COMBINED, 0, PRIMITIVE, 0), gsDPSetPrimDepth(0, 0), - gsDPLoadTextureBlock_4b(sWipe1Tex, G_IM_FMT_I, 64, 64, 0, G_TX_NOMIRROR | G_TX_WRAP, G_TX_MIRROR | G_TX_WRAP, 6, - 6, 11, G_TX_NOLOD), + gsDPLoadTextureBlock_4b(sWipe1Tex, G_IM_FMT_I, 64, 64, 0, G_TX_NOMIRROR | G_TX_WRAP, G_TX_MIRROR | G_TX_WRAP, 6, 6, + 11, G_TX_NOLOD), gsDPLoadMultiBlock_4b(sWipe1Tex, 0x0100, 1, G_IM_FMT_I, 64, 64, 0, G_TX_NOMIRROR | G_TX_WRAP, G_TX_MIRROR | G_TX_WRAP, 6, 6, 11, 1), gsDPSetTextureLUT(G_TT_NONE), diff --git a/src/code/z_game_over.c b/src/code/z_game_over.c index 1834ea1b9..d8e00faad 100644 --- a/src/code/z_game_over.c +++ b/src/code/z_game_over.c @@ -13,10 +13,8 @@ void GameOver_FadeInLights(GlobalContext* globalCtx) { } } -// This variable has the same problem as z_message's data going to rodata. -// A fix for this is planned, and will be taken care of with z_message. -// For now this variable is externed from z_message's rodata.s file. -extern s16 D_80153D80; // todo: rename to `timer` and make this in function static (after rodata issue is resolved) +// This variable cannot be moved into this file as all of z_message_PAL rodata is in the way +extern s16 gGameOverTimer; void GameOver_Update(GlobalContext* globalCtx) { GameOverContext* gameOverCtx = &globalCtx->gameOverCtx; @@ -28,7 +26,7 @@ void GameOver_Update(GlobalContext* globalCtx) { switch (gameOverCtx->state) { case GAMEOVER_DEATH_START: - func_80106CCC(globalCtx); + Message_CloseTextbox(globalCtx); gSaveContext.timer1State = 0; gSaveContext.timer2State = 0; @@ -75,7 +73,7 @@ void GameOver_Update(GlobalContext* globalCtx) { gSaveContext.unk_13E7 = gSaveContext.unk_13E8 = gSaveContext.unk_13EA = gSaveContext.unk_13EC = 0; Environment_InitGameOverLights(globalCtx); - D_80153D80 = 20; + gGameOverTimer = 20; if (1) {} v90 = VREG(90); v91 = VREG(91); @@ -91,9 +89,9 @@ void GameOver_Update(GlobalContext* globalCtx) { break; case GAMEOVER_DEATH_DELAY_MENU: - D_80153D80--; + gGameOverTimer--; - if (D_80153D80 == 0) { + if (gGameOverTimer == 0) { globalCtx->pauseCtx.state = 8; gameOverCtx->state++; func_800AA15C(); @@ -102,13 +100,13 @@ void GameOver_Update(GlobalContext* globalCtx) { case GAMEOVER_REVIVE_START: gameOverCtx->state++; - D_80153D80 = 0; + gGameOverTimer = 0; Environment_InitGameOverLights(globalCtx); ShrinkWindow_SetVal(0x20); return; case GAMEOVER_REVIVE_RUMBLE: - D_80153D80 = 50; + gGameOverTimer = 50; gameOverCtx->state++; if (1) {} @@ -121,28 +119,28 @@ void GameOver_Update(GlobalContext* globalCtx) { break; case GAMEOVER_REVIVE_WAIT_GROUND: - D_80153D80--; + gGameOverTimer--; - if (D_80153D80 == 0) { - D_80153D80 = 64; + if (gGameOverTimer == 0) { + gGameOverTimer = 64; gameOverCtx->state++; } break; case GAMEOVER_REVIVE_WAIT_FAIRY: - D_80153D80--; + gGameOverTimer--; - if (D_80153D80 == 0) { - D_80153D80 = 50; + if (gGameOverTimer == 0) { + gGameOverTimer = 50; gameOverCtx->state++; } break; case GAMEOVER_REVIVE_FADE_OUT: Environment_FadeOutGameOverLights(globalCtx); - D_80153D80--; + gGameOverTimer--; - if (D_80153D80 == 0) { + if (gGameOverTimer == 0) { gameOverCtx->state = GAMEOVER_INACTIVE; } break; diff --git a/src/code/z_kaleido_setup.c b/src/code/z_kaleido_setup.c index adc829d01..7fad9e060 100644 --- a/src/code/z_kaleido_setup.c +++ b/src/code/z_kaleido_setup.c @@ -111,7 +111,7 @@ void KaleidoSetup_Init(GlobalContext* globalCtx) { pauseCtx->nameDisplayTimer = 0; pauseCtx->nameColorSet = 0; pauseCtx->cursorColorSet = 4; - pauseCtx->unk_264 = -1; + pauseCtx->ocarinaSongIdx = -1; pauseCtx->cursorSpecialPos = 0; View_Init(&pauseCtx->view, globalCtx->state.gfxCtx); diff --git a/src/code/z_kanfont.c b/src/code/z_kanfont.c index 1bfc0dcf8..c9a150a5b 100644 --- a/src/code/z_kanfont.c +++ b/src/code/z_kanfont.c @@ -1,27 +1,34 @@ #include "global.h" +#include "message_data_static.h" -// To be moved to message_data_static header -#define MESSAGE_NEWLINE '\x01' -#define MESSAGE_END '\x02' -// message_data_static symbols -extern const char D_07000000[]; // start of file -extern const char D_070380D4[]; // charset message (id 0xFFFC) -extern const char D_0703811C[]; // end marker of last message - -// stubbed in PAL -void func_8006EE50(Font* font, s16 arg1, s16 arg2) { +void func_8006EE50(Font* font, u16 arg1, u16 arg2) { } +/** + * Loads a texture from nes_font_static for the requested `character` into the character texture buffer + * at `codePointIndex`. The value of `character` is the ASCII codepoint subtract ' '/0x20. + */ void Font_LoadChar(Font* font, u8 character, u16 codePointIndex) { - DmaMgr_SendRequest1(&font->unk_8[codePointIndex], &_nes_font_staticSegmentRomStart[character * FONT_CHAR_TEX_SIZE], - FONT_CHAR_TEX_SIZE, "../z_kanfont.c", 93); + DmaMgr_SendRequest1(&font->charTexBuf[codePointIndex], + &_nes_font_staticSegmentRomStart[character * FONT_CHAR_TEX_SIZE], FONT_CHAR_TEX_SIZE, + "../z_kanfont.c", 93); } -void Font_LoadMessageBoxEndIcon(Font* font, u16 icon) { - DmaMgr_SendRequest1(font->iconBuf, &_message_staticSegmentRomStart[4 * 0x1000 + icon * FONT_CHAR_TEX_SIZE], +/** + * Loads a message box icon from message_static, such as the ending triangle/square or choice arrow into the + * icon buffer. + * The different icons are given in the MessageBoxIcon enum. + */ +void Font_LoadMessageBoxIcon(Font* font, u16 icon) { + DmaMgr_SendRequest1(font->iconBuf, + &_message_staticSegmentRomStart[4 * MESSAGE_STATIC_TEX_SIZE + icon * FONT_CHAR_TEX_SIZE], FONT_CHAR_TEX_SIZE, "../z_kanfont.c", 100); } +/** + * Loads a full set of character textures based on their ordering in the message with text id 0xFFFC into + * the font buffer. + */ void Font_LoadOrderedFont(Font* font) { s32 len; s32 jj; @@ -31,24 +38,29 @@ void Font_LoadOrderedFont(Font* font) { s32 fontBufIndex; s32 offset; - font->msgOffset = D_070380D4 - D_07000000; - len = font->msgLength = D_0703811C - D_070380D4; + font->msgOffset = _message_0xFFFC_nes - (const char*)_nes_message_data_staticSegmentStart; + len = font->msgLength = _message_0xFFFD_nes - _message_0xFFFC_nes; + DmaMgr_SendRequest1(font->msgBuf, &_nes_message_data_staticSegmentRomStart[font->msgOffset], len, "../z_kanfont.c", 122); osSyncPrintf("msg_data=%x, msg_data0=%x jj=%x\n", font->msgOffset, font->msgLength, jj = len); + len = jj; for (fontBufIndex = 0, codePointIndex = 0; font->msgBuf[codePointIndex] != MESSAGE_END; codePointIndex++) { if (codePointIndex > len) { osSyncPrintf("ERROR!! エラー!!! error───!!!!\n"); return; } + if (font->msgBuf[codePointIndex] != MESSAGE_NEWLINE) { fontBuf = font->fontBuf + fontBufIndex * 8; fontStatic = _nes_font_staticSegmentRomStart; + osSyncPrintf("nes_mes_buf[%d]=%d\n", codePointIndex, font->msgBuf[codePointIndex]); + offset = (font->msgBuf[codePointIndex] - '\x20') * FONT_CHAR_TEX_SIZE; DmaMgr_SendRequest1(fontBuf, fontStatic + offset, FONT_CHAR_TEX_SIZE, "../z_kanfont.c", 134); - fontBufIndex += 0x10; + fontBufIndex += FONT_CHAR_TEX_SIZE / 8; } } } diff --git a/src/code/z_kankyo.c b/src/code/z_kankyo.c index 63b0e7b99..8136ae000 100644 --- a/src/code/z_kankyo.c +++ b/src/code/z_kankyo.c @@ -882,7 +882,7 @@ void Environment_Update(GlobalContext* globalCtx, EnvironmentContext* envCtx, Li } if ((pauseCtx->state == 0) && (gameOverCtx->state == GAMEOVER_INACTIVE)) { - if (((msgCtx->unk_E300 == 0) && (msgCtx->msgMode == 0)) || (((void)0, gSaveContext.gameMode) == 3)) { + if (((msgCtx->msgLength == 0) && (msgCtx->msgMode == 0)) || (((void)0, gSaveContext.gameMode) == 3)) { if ((envCtx->unk_1A == 0) && !FrameAdvance_IsEnabled(globalCtx) && (globalCtx->transitionMode == 0 || ((void)0, gSaveContext.gameMode) != 0)) { @@ -2029,7 +2029,7 @@ void func_80075B44(GlobalContext* globalCtx) { if ((Inventory_ReplaceItem(globalCtx, ITEM_WEIRD_EGG, ITEM_CHICKEN) || Inventory_ReplaceItem(globalCtx, ITEM_POCKET_EGG, ITEM_POCKET_CUCCO)) && globalCtx->csCtx.state == 0 && !Player_InCsMode(globalCtx)) { - func_8010B680(globalCtx, 0x3066, NULL); + Message_StartTextbox(globalCtx, 0x3066, NULL); } globalCtx->envCtx.unk_E0++; } diff --git a/src/code/z_map_mark.c b/src/code/z_map_mark.c index a096a9b56..8718b8de4 100644 --- a/src/code/z_map_mark.c +++ b/src/code/z_map_mark.c @@ -63,10 +63,10 @@ void MapMark_Init(GlobalContext* globalCtx) { Overlay_Load(overlay->vromStart, overlay->vromEnd, overlay->vramStart, overlay->vramEnd, overlay->loadedRamAddr); sLoadedMarkDataTable = gMapMarkDataTable; - sLoadedMarkDataTable = (void*)(u32)((overlay->vramTable != NULL) - ? (void*)((u32)overlay->vramTable - - (s32)((u32)overlay->vramStart - (u32)overlay->loadedRamAddr)) - : NULL); + sLoadedMarkDataTable = (void*)(u32)( + (overlay->vramTable != NULL) + ? (void*)((u32)overlay->vramTable - (s32)((u32)overlay->vramStart - (u32)overlay->loadedRamAddr)) + : NULL); } void MapMark_ClearPointers(GlobalContext* globalCtx) { diff --git a/src/code/z_message_PAL.c b/src/code/z_message_PAL.c index 3423934dc..58c87347b 100644 --- a/src/code/z_message_PAL.c +++ b/src/code/z_message_PAL.c @@ -1,66 +1,3307 @@ #include "global.h" +#include "message_data_static.h" +#include "vt.h" #include "textures/parameter_static/parameter_static.h" -#pragma GLOBAL_ASM("asm/non_matchings/code/z_message_PAL/func_801069B0.s") +s16 sTextFade = false; // original name: key_off_flag ? -#pragma GLOBAL_ASM("asm/non_matchings/code/z_message_PAL/func_80106AA8.s") +u8 D_8014B2F4 = 0; -#pragma GLOBAL_ASM("asm/non_matchings/code/z_message_PAL/func_80106BC8.s") +s16 sOcarinaNoteBufPos = 0; -#pragma GLOBAL_ASM("asm/non_matchings/code/z_message_PAL/func_80106C88.s") +s16 sOcarinaNoteBufLen = 0; -#pragma GLOBAL_ASM("asm/non_matchings/code/z_message_PAL/func_80106CCC.s") +u8 sTextboxSkipped = false; -#pragma GLOBAL_ASM("asm/non_matchings/code/z_message_PAL/func_80106D40.s") +u16 sNextTextId = 0; -#pragma GLOBAL_ASM("asm/non_matchings/code/z_message_PAL/func_80106F1C.s") +s16 sTextIsCredits = false; -#pragma GLOBAL_ASM("asm/non_matchings/code/z_message_PAL/func_80107244.s") +UNK_TYPE D_8014B30C = 0; -#pragma GLOBAL_ASM("asm/non_matchings/code/z_message_PAL/func_80107448.s") +s16 sLastPlayedSong = 0xFF; // last played song? -#pragma GLOBAL_ASM("asm/non_matchings/code/z_message_PAL/func_80107628.s") +s16 sHasSunsSong = false; -#pragma GLOBAL_ASM("asm/non_matchings/code/z_message_PAL/func_801076CC.s") +s16 sMessageHasSetSfx = false; -#pragma GLOBAL_ASM("asm/non_matchings/code/z_message_PAL/func_80107980.s") +u16 sOcarinaSongBitFlags = 0; // ocarina bit flags -#pragma GLOBAL_ASM("asm/non_matchings/code/z_message_PAL/func_801080B4.s") +MessageTableEntry sNesMessageEntryTable[] = { +#define DEFINE_MESSAGE(textId, type, yPos, nesMessage, gerMessage, fraMessage) \ + { textId, (_SHIFTL(type, 4, 8) | _SHIFTL(yPos, 0, 8)), _message_##textId##_nes }, +#define DEFINE_MESSAGE_FFFC +#include "text/message_data.h" +#undef DEFINE_MESSAGE_FFFC +#undef DEFINE_MESSAGE + { 0xFFFF, 0, NULL }, +}; -#pragma GLOBAL_ASM("asm/non_matchings/code/z_message_PAL/func_801083F8.s") +const char* sGerMessageEntryTable[] = { +#define DEFINE_MESSAGE(textId, type, yPos, nesMessage, gerMessage, fraMessage) _message_##textId##_ger, +#include "text/message_data.h" +#undef DEFINE_MESSAGE + NULL, +}; -#pragma GLOBAL_ASM("asm/non_matchings/code/z_message_PAL/func_801086B0.s") +const char* sFraMessageEntryTable[] = { +#define DEFINE_MESSAGE(textId, type, yPos, nesMessage, gerMessage, fraMessage) _message_##textId##_fra, +#include "text/message_data.h" +#undef DEFINE_MESSAGE + NULL, +}; -#pragma GLOBAL_ASM("asm/non_matchings/code/z_message_PAL/func_80109968.s") +MessageTableEntry sStaffMessageEntryTable[] = { +#define DEFINE_MESSAGE(textId, type, yPos, staffMessage) \ + { textId, (_SHIFTL(type, 4, 8) | _SHIFTL(yPos, 0, 8)), _message_##textId##_staff }, +#include "text/message_data_staff.h" +#undef DEFINE_MESSAGE + { 0xFFFF, 0, NULL }, +}; -#pragma GLOBAL_ASM("asm/non_matchings/code/z_message_PAL/func_80109B3C.s") +MessageTableEntry* sNesMessageEntryTablePtr = sNesMessageEntryTable; +const char** sGerMessageEntryTablePtr = sGerMessageEntryTable; +const char** sFraMessageEntryTablePtr = sFraMessageEntryTable; +MessageTableEntry* sStaffMessageEntryTablePtr = sStaffMessageEntryTable; -#pragma GLOBAL_ASM("asm/non_matchings/code/z_message_PAL/func_8010B0C0.s") +s16 sTextboxBackgroundForePrimColors[][3] = { + { 255, 255, 255 }, { 50, 20, 0 }, { 255, 60, 0 }, { 255, 255, 255 }, + { 255, 255, 255 }, { 255, 255, 255 }, { 255, 255, 255 }, { 255, 255, 255 }, +}; -#pragma GLOBAL_ASM("asm/non_matchings/code/z_message_PAL/func_8010B680.s") +s16 sTextboxBackgroundBackPrimColors[][3] = { + { 0, 0, 0 }, + { 220, 150, 0 }, + { 0, 0, 0 }, + { 0, 0, 0 }, +}; -#pragma GLOBAL_ASM("asm/non_matchings/code/z_message_PAL/func_8010B720.s") +s16 sTextboxBackgroundYOffsets[] = { + 1, + 2, +}; -#pragma GLOBAL_ASM("asm/non_matchings/code/z_message_PAL/func_8010B820.s") +// original name: onpu_buff +u8 sOcarinaNoteBuf[12] = { 0 }; -#pragma GLOBAL_ASM("asm/non_matchings/code/z_message_PAL/func_8010BD58.s") +s16 sOcarinaNotesAlphaValues[9] = { 0 }; -#pragma GLOBAL_ASM("asm/non_matchings/code/z_message_PAL/func_8010BD88.s") +// Maps the ocarina song order to the quest item order +s16 gOcarinaSongItemMap[] = { + OCARINA_SONG_MINUET, OCARINA_SONG_BOLERO, OCARINA_SONG_SERENADE, OCARINA_SONG_REQUIEM, + OCARINA_SONG_NOCTURNE, OCARINA_SONG_PRELUDE, OCARINA_SONG_LULLABY, OCARINA_SONG_EPONAS, + OCARINA_SONG_SARIAS, OCARINA_SONG_SUNS, OCARINA_SONG_TIME, OCARINA_SONG_STORMS, +}; -#pragma GLOBAL_ASM("asm/non_matchings/code/z_message_PAL/func_8010BDBC.s") +s32 sCharTexSize; +s32 sCharTexScale; +s16 sOcarinaNoteAPrimR; +s16 sOcarinaNoteAPrimB; +s16 sOcarinaNoteAPrimG; +s16 sOcarinaNoteAEnvR; +s16 sOcarinaNoteAEnvB; +s16 sOcarinaNoteAEnvG; +s16 sOcarinaNoteCPrimR; +s16 sOcarinaNoteCPrimB; +s16 sOcarinaNoteCPrimG; +s16 sOcarinaNoteCEnvR; +s16 sOcarinaNoteCEnvB; +s16 sOcarinaNoteCEnvG; -#pragma GLOBAL_ASM("asm/non_matchings/code/z_message_PAL/func_8010BED8.s") +void Message_ResetOcarinaNoteState(void) { + R_OCARINA_NOTES_YPOS(0) = 189; + R_OCARINA_NOTES_YPOS(1) = 184; + R_OCARINA_NOTES_YPOS(2) = 179; + R_OCARINA_NOTES_YPOS(3) = 174; + R_OCARINA_NOTES_YPOS(4) = 169; + sOcarinaNoteBuf[0] = 0xFF; + sOcarinaNotesAlphaValues[0] = sOcarinaNotesAlphaValues[1] = sOcarinaNotesAlphaValues[2] = + sOcarinaNotesAlphaValues[3] = sOcarinaNotesAlphaValues[4] = sOcarinaNotesAlphaValues[5] = + sOcarinaNotesAlphaValues[6] = sOcarinaNotesAlphaValues[7] = sOcarinaNotesAlphaValues[8] = 0; + sOcarinaNoteAPrimR = 80; + sOcarinaNoteAPrimG = 255; + sOcarinaNoteAPrimB = 150; + sOcarinaNoteAEnvR = 10; + sOcarinaNoteAEnvG = 10; + sOcarinaNoteAEnvB = 10; + sOcarinaNoteCPrimR = 255; + sOcarinaNoteCPrimG = 255; + sOcarinaNoteCPrimB = 50; + sOcarinaNoteCEnvR = 10; + sOcarinaNoteCEnvG = 10; + sOcarinaNoteCEnvB = 10; +} -#pragma GLOBAL_ASM("asm/non_matchings/code/z_message_PAL/func_8010C358.s") +void Message_UpdateOcarinaGame(GlobalContext* globalCtx) { + MessageContext* msgCtx = &globalCtx->msgCtx; -#pragma GLOBAL_ASM("asm/non_matchings/code/z_message_PAL/func_8010C39C.s") + globalCtx->msgCtx.msgMode++; -#pragma GLOBAL_ASM("asm/non_matchings/code/z_message_PAL/func_8010F2CC.s") + if (globalCtx->msgCtx.msgMode == MSGMODE_MEMORY_GAME_PLAYER_PLAYING) { + Audio_OcaSetInstrument(1); + msgCtx->ocarinaStaff = Audio_OcaGetPlayingStaff(); + msgCtx->ocarinaStaff->pos = sOcarinaNoteBufPos = 0; + func_800ECC04((1 << OCARINA_SONG_MEMORY_GAME) + 0x8000); + msgCtx->textDrawPos = msgCtx->decodedTextLen; + } else if (msgCtx->msgMode == MSGMODE_MEMORY_GAME_RIGHT_SKULLKID_PLAYING) { + Audio_OcaSetInstrument(6); + msgCtx->ocarinaStaff = Audio_OcaGetDisplayingStaff(); + msgCtx->ocarinaStaff->pos = sOcarinaNoteBufPos = 0; + Audio_OcaSetSongPlayback(OCARINA_SONG_MEMORY_GAME + 1, 1); + msgCtx->stateTimer = 2; + } + Message_ResetOcarinaNoteState(); +} -#pragma GLOBAL_ASM("asm/non_matchings/code/z_message_PAL/func_8010F494.s") +u8 Message_ShouldAdvance(GlobalContext* globalCtx) { + Input* input = &globalCtx->state.input[0]; -#pragma GLOBAL_ASM("asm/non_matchings/code/z_message_PAL/func_8010F58C.s") + if (CHECK_BTN_ALL(input->press.button, BTN_A) || CHECK_BTN_ALL(input->press.button, BTN_B) || + CHECK_BTN_ALL(input->press.button, BTN_CUP)) { + Audio_PlaySoundGeneral(NA_SE_SY_MESSAGE_PASS, &D_801333D4, 4, &D_801333E0, &D_801333E0, &D_801333E8); + } + return CHECK_BTN_ALL(input->press.button, BTN_A) || CHECK_BTN_ALL(input->press.button, BTN_B) || + CHECK_BTN_ALL(input->press.button, BTN_CUP); +} -#pragma GLOBAL_ASM("asm/non_matchings/code/z_message_PAL/func_8010F6F0.s") +u8 Message_ShouldAdvanceSilent(GlobalContext* globalCtx) { + Input* input = &globalCtx->state.input[0]; -#pragma GLOBAL_ASM("asm/non_matchings/code/z_message_PAL/func_8011040C.s") + return CHECK_BTN_ALL(input->press.button, BTN_A) || CHECK_BTN_ALL(input->press.button, BTN_B) || + CHECK_BTN_ALL(input->press.button, BTN_CUP); +} + +/** + * Closes any currently displayed textbox immediately, without waiting for + * input from the player. + */ +void Message_CloseTextbox(GlobalContext* globalCtx) { + MessageContext* msgCtx = &globalCtx->msgCtx; + + if (msgCtx->msgLength != 0) { + msgCtx->stateTimer = 2; + msgCtx->msgMode = MSGMODE_TEXT_CLOSING; + msgCtx->textboxEndType = TEXTBOX_ENDTYPE_DEFAULT; + Audio_PlaySoundGeneral(0, &D_801333D4, 4, &D_801333E0, &D_801333E0, &D_801333E8); + } +} + +void Message_HandleChoiceSelection(GlobalContext* globalCtx, u8 numChoices) { + static s16 sAnalogStickHeld = false; + MessageContext* msgCtx = &globalCtx->msgCtx; + Input* input = &globalCtx->state.input[0]; + + if (input->rel.stick_y >= 30 && !sAnalogStickHeld) { + sAnalogStickHeld = true; + msgCtx->choiceIndex--; + if (msgCtx->choiceIndex > 128) { + msgCtx->choiceIndex = 0; + } else { + Audio_PlaySoundGeneral(NA_SE_SY_CURSOR, &D_801333D4, 4, &D_801333E0, &D_801333E0, &D_801333E8); + } + } else if (input->rel.stick_y <= -30 && !sAnalogStickHeld) { + sAnalogStickHeld = true; + msgCtx->choiceIndex++; + if (msgCtx->choiceIndex > numChoices) { + msgCtx->choiceIndex = numChoices; + } else { + Audio_PlaySoundGeneral(NA_SE_SY_CURSOR, &D_801333D4, 4, &D_801333E0, &D_801333E0, &D_801333E8); + } + } else if (ABS(input->rel.stick_y) < 30) { + sAnalogStickHeld = false; + } + msgCtx->textPosX = R_TEXT_CHOICE_XPOS; + msgCtx->textPosY = + (numChoices == 1) ? R_TEXT_CHOICE_YPOS(msgCtx->choiceIndex + 1) : R_TEXT_CHOICE_YPOS(msgCtx->choiceIndex); +} + +void Message_DrawTextChar(GlobalContext* globalCtx, void* textureImage, Gfx** p) { + MessageContext* msgCtx = &globalCtx->msgCtx; + Gfx* gfx = *p; + s16 x = msgCtx->textPosX; + s16 y = msgCtx->textPosY; + + gDPPipeSync(gfx++); + + sCharTexSize = (R_TEXT_CHAR_SCALE / 100.0f) * 16.0f; + sCharTexScale = 1024.0f / (R_TEXT_CHAR_SCALE / 100.0f); + + gDPLoadTextureBlock_4b(gfx++, textureImage, G_IM_FMT_I, FONT_CHAR_TEX_WIDTH, FONT_CHAR_TEX_HEIGHT, 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); + + // Draw drop shadow + if (msgCtx->textBoxType != TEXTBOX_TYPE_NONE_NO_SHADOW) { + gDPSetPrimColor(gfx++, 0, 0, 0, 0, 0, msgCtx->textColorAlpha); + gSPTextureRectangle(gfx++, (x + R_TEXT_DROP_SHADOW_OFFSET) << 2, (y + R_TEXT_DROP_SHADOW_OFFSET) << 2, + (x + R_TEXT_DROP_SHADOW_OFFSET + sCharTexSize) << 2, + (y + R_TEXT_DROP_SHADOW_OFFSET + sCharTexSize) << 2, G_TX_RENDERTILE, 0, 0, sCharTexScale, + sCharTexScale); + } + + gDPPipeSync(gfx++); + gDPSetPrimColor(gfx++, 0, 0, msgCtx->textColorR, msgCtx->textColorG, msgCtx->textColorB, msgCtx->textColorAlpha); + gSPTextureRectangle(gfx++, x << 2, y << 2, (x + sCharTexSize) << 2, (y + sCharTexSize) << 2, G_TX_RENDERTILE, 0, 0, + sCharTexScale, sCharTexScale); + *p = gfx; +} + +// resizes textboxes when opening them +void Message_GrowTextbox(MessageContext* msgCtx) { + static f32 sWidthCoefficients[] = { + 1.2f, 1.5f, 1.8f, 2.0f, 2.1f, 2.2f, 2.1f, 2.0f, + }; + static f32 sHeightCoefficients[] = { + 0.6f, 0.75f, 0.9f, 1.0f, 1.05f, 1.1f, 1.05f, 1.0f, + }; + f32 width = + R_TEXTBOX_WIDTH_TARGET * (sWidthCoefficients[msgCtx->stateTimer] + sWidthCoefficients[msgCtx->stateTimer]); + f32 height = R_TEXTBOX_HEIGHT_TARGET * sHeightCoefficients[msgCtx->stateTimer]; + f32 texWidth = + R_TEXTBOX_TEXWIDTH_TARGET / (sWidthCoefficients[msgCtx->stateTimer] + sWidthCoefficients[msgCtx->stateTimer]); + f32 texHeight = R_TEXTBOX_TEXHEIGHT_TARGET / sHeightCoefficients[msgCtx->stateTimer]; + + // Adjust y pos + R_TEXTBOX_Y = R_TEXTBOX_Y_TARGET + + (R_TEXTBOX_Y_TARGET - (s16)(R_TEXTBOX_Y_TARGET * sHeightCoefficients[msgCtx->stateTimer] + 0.5f)) / 2; + + msgCtx->textboxColorAlphaCurrent += msgCtx->textboxColorAlphaTarget / 8; + msgCtx->stateTimer++; + if (msgCtx->stateTimer == 8) { + // Reached the end + R_TEXTBOX_X = R_TEXTBOX_X_TARGET; + R_TEXTBOX_Y = R_TEXTBOX_Y_TARGET; + msgCtx->msgMode = MSGMODE_TEXT_STARTING; + msgCtx->textboxColorAlphaCurrent = msgCtx->textboxColorAlphaTarget; + } + // Adjust width and height + R_TEXTBOX_WIDTH = (s16)(width + 0.5f) / 2; + R_TEXTBOX_HEIGHT = (s16)(height + 0.5f); + // Adjust texture coordinates + R_TEXTBOX_TEXWIDTH = texWidth + 0.5f; + R_TEXTBOX_TEXHEIGHT = texHeight + 0.5f; + // Adjust x pos + R_TEXTBOX_X = (R_TEXTBOX_X_TARGET + R_TEXTBOX_WIDTH_TARGET) - (R_TEXTBOX_WIDTH / 2); +} + +void Message_FindMessage(GlobalContext* globalCtx, u16 textId) { + const char* foundSeg; + const char* nextSeg; + MessageTableEntry* messageTableEntry = sNesMessageEntryTablePtr; + const char** languageSegmentTable; + Font* font; + const char* seg; + + if (gSaveContext.language == LANGUAGE_ENG) { + seg = messageTableEntry->segment; + + while (messageTableEntry->textId != 0xFFFF) { + font = &globalCtx->msgCtx.font; + + if (messageTableEntry->textId == textId) { + foundSeg = messageTableEntry->segment; + font->charTexBuf[0] = messageTableEntry->typePos; + messageTableEntry++; + nextSeg = messageTableEntry->segment; + font->msgOffset = foundSeg - seg; + font->msgLength = nextSeg - foundSeg; + // "Message found!!!" + osSyncPrintf(" メッセージが,見つかった!!! = %x " + "(data=%x) (data0=%x) (data1=%x) (data2=%x) (data3=%x)\n", + textId, font->msgOffset, font->msgLength, foundSeg, seg, nextSeg); + return; + } + messageTableEntry++; + } + } else { + languageSegmentTable = + (gSaveContext.language == LANGUAGE_GER) ? sGerMessageEntryTablePtr : sFraMessageEntryTablePtr; + seg = messageTableEntry->segment; + + while (messageTableEntry->textId != 0xFFFF) { + font = &globalCtx->msgCtx.font; + + if (messageTableEntry->textId == textId) { + foundSeg = *languageSegmentTable; + font->charTexBuf[0] = messageTableEntry->typePos; + languageSegmentTable++; + nextSeg = *languageSegmentTable; + font->msgOffset = foundSeg - seg; + font->msgLength = nextSeg - foundSeg; + // "Message found!!!" + osSyncPrintf(" メッセージが,見つかった!!! = %x " + "(data=%x) (data0=%x) (data1=%x) (data2=%x) (data3=%x)\n", + textId, font->msgOffset, font->msgLength, foundSeg, seg, nextSeg); + return; + } + messageTableEntry++; + languageSegmentTable++; + } + } + // "Message not found!!!" + osSyncPrintf(" メッセージが,見つからなかった!!! = %x\n", textId); + font = &globalCtx->msgCtx.font; + messageTableEntry = sNesMessageEntryTablePtr; + + if (gSaveContext.language == LANGUAGE_ENG) { + foundSeg = messageTableEntry->segment; + font->charTexBuf[0] = messageTableEntry->typePos; + messageTableEntry++; + nextSeg = messageTableEntry->segment; + } else { + languageSegmentTable = + (gSaveContext.language == LANGUAGE_GER) ? sGerMessageEntryTablePtr : sFraMessageEntryTablePtr; + foundSeg = *languageSegmentTable; + font->charTexBuf[0] = messageTableEntry->typePos; + languageSegmentTable++; + nextSeg = *languageSegmentTable; + } + font->msgOffset = foundSeg - seg; + font->msgLength = nextSeg - foundSeg; +} + +void Message_FindCreditsMessage(GlobalContext* globalCtx, u16 textId) { + const char* foundSeg; + const char* nextSeg; + const char* seg; + MessageTableEntry* messageTableEntry = sStaffMessageEntryTablePtr; + Font* font; + + seg = messageTableEntry->segment; + while (messageTableEntry->textId != 0xFFFF) { + font = &globalCtx->msgCtx.font; + + if (messageTableEntry->textId == textId) { + foundSeg = messageTableEntry->segment; + font->charTexBuf[0] = messageTableEntry->typePos; + messageTableEntry++; + nextSeg = messageTableEntry->segment; + font->msgOffset = foundSeg - seg; + font->msgLength = nextSeg - foundSeg; + // "Message found!!!" + osSyncPrintf(" メッセージが,見つかった!!! = %x (data=%x) (data0=%x) (data1=%x) (data2=%x) (data3=%x)\n", + textId, font->msgOffset, font->msgLength, foundSeg, seg, nextSeg); + return; + } + messageTableEntry++; + } +} + +void Message_SetTextColor(MessageContext* msgCtx, u16 colorParameter) { + switch (colorParameter) { + case MSGCOL_RED: + if (msgCtx->textBoxType == TEXTBOX_TYPE_WOODEN) { + msgCtx->textColorR = 255; + msgCtx->textColorG = 120; + msgCtx->textColorB = 0; + } else { + msgCtx->textColorR = 255; + msgCtx->textColorG = 60; + msgCtx->textColorB = 60; + } + break; + case MSGCOL_ADJUSTABLE: + if (msgCtx->textBoxType == TEXTBOX_TYPE_WOODEN) { + msgCtx->textColorR = R_TEXT_ADJUST_COLOR_1_R; + msgCtx->textColorG = R_TEXT_ADJUST_COLOR_1_G; + msgCtx->textColorB = R_TEXT_ADJUST_COLOR_1_B; + } else { + msgCtx->textColorR = R_TEXT_ADJUST_COLOR_2_R; + msgCtx->textColorG = R_TEXT_ADJUST_COLOR_2_G; + msgCtx->textColorB = R_TEXT_ADJUST_COLOR_2_B; + } + break; + case MSGCOL_BLUE: + if (msgCtx->textBoxType == TEXTBOX_TYPE_WOODEN) { + msgCtx->textColorR = 80; + msgCtx->textColorG = 110; + msgCtx->textColorB = 255; + } else { + msgCtx->textColorR = 80; + msgCtx->textColorG = 90; + msgCtx->textColorB = 255; + } + break; + case MSGCOL_LIGHTBLUE: + if (msgCtx->textBoxType == TEXTBOX_TYPE_WOODEN) { + msgCtx->textColorR = 90; + msgCtx->textColorG = 180; + msgCtx->textColorB = 255; + } else if (msgCtx->textBoxType == TEXTBOX_TYPE_NONE_NO_SHADOW) { + msgCtx->textColorR = 80; + msgCtx->textColorG = 150; + msgCtx->textColorB = 180; + } else { + msgCtx->textColorR = 100; + msgCtx->textColorG = 180; + msgCtx->textColorB = 255; + } + break; + case MSGCOL_PURPLE: + if (msgCtx->textBoxType == TEXTBOX_TYPE_WOODEN) { + msgCtx->textColorR = 210; + msgCtx->textColorG = 100; + msgCtx->textColorB = 255; + } else { + msgCtx->textColorR = 255; + msgCtx->textColorG = 150; + msgCtx->textColorB = 180; + } + break; + case MSGCOL_YELLOW: + if (msgCtx->textBoxType == TEXTBOX_TYPE_WOODEN) { + msgCtx->textColorR = 255; + msgCtx->textColorG = 255; + msgCtx->textColorB = 30; + } else { + msgCtx->textColorR = 225; + msgCtx->textColorG = 255; + msgCtx->textColorB = 50; + } + break; + case MSGCOL_BLACK: + msgCtx->textColorR = msgCtx->textColorG = msgCtx->textColorB = 0; + break; + case MSGCOL_DEFAULT: + default: + if (msgCtx->textBoxType == TEXTBOX_TYPE_NONE_NO_SHADOW) { + msgCtx->textColorR = msgCtx->textColorG = msgCtx->textColorB = 0; + } else { + msgCtx->textColorR = msgCtx->textColorG = msgCtx->textColorB = 255; + } + break; + } +} + +void Message_DrawTextboxIcon(GlobalContext* globalCtx, Gfx** p, s16 x, s16 y) { + static s16 sIconPrimColors[][3] = { + { 0, 200, 80 }, + { 50, 255, 130 }, + }; + static s16 sIconEnvColors[][3] = { + { 0, 0, 0 }, + { 0, 255, 130 }, + }; + static s16 sIconPrimR = 0; + static s16 sIconPrimG = 200; + static s16 sIconPrimB = 80; + static s16 sIconFlashTimer = 12; + static s16 sIconFlashColorIdx = 0; + static s16 sIconEnvR = 0; + static s16 sIconEnvG = 0; + static s16 sIconEnvB = 0; + MessageContext* msgCtx = &globalCtx->msgCtx; + Font* font = &msgCtx->font; + Gfx* gfx = *p; + s16 primR; + s16 primG; + s16 primB; + s16 envR; + s16 envG; + s16 envB; + u8* iconTexture = font->iconBuf; + + if (sTextIsCredits) { + return; + } + + primR = (ABS(sIconPrimR - sIconPrimColors[sIconFlashColorIdx][0])) / sIconFlashTimer; + primG = (ABS(sIconPrimG - sIconPrimColors[sIconFlashColorIdx][1])) / sIconFlashTimer; + primB = (ABS(sIconPrimB - sIconPrimColors[sIconFlashColorIdx][2])) / sIconFlashTimer; + + if (sIconPrimR >= sIconPrimColors[sIconFlashColorIdx][0]) { + sIconPrimR -= primR; + } else { + sIconPrimR += primR; + } + + if (sIconPrimG >= sIconPrimColors[sIconFlashColorIdx][1]) { + sIconPrimG -= primG; + } else { + sIconPrimG += primG; + } + + if (sIconPrimB >= sIconPrimColors[sIconFlashColorIdx][2]) { + sIconPrimB -= primB; + } else { + sIconPrimB += primB; + } + + envR = (ABS(sIconEnvR - sIconEnvColors[sIconFlashColorIdx][0])) / sIconFlashTimer; + envG = (ABS(sIconEnvG - sIconEnvColors[sIconFlashColorIdx][1])) / sIconFlashTimer; + envB = (ABS(sIconEnvB - sIconEnvColors[sIconFlashColorIdx][2])) / sIconFlashTimer; + + if (sIconEnvR >= sIconEnvColors[sIconFlashColorIdx][0]) { + sIconEnvR -= envR; + } else { + sIconEnvR += envR; + } + + if (sIconEnvG >= sIconEnvColors[sIconFlashColorIdx][1]) { + sIconEnvG -= envG; + } else { + sIconEnvG += envG; + } + + if (sIconEnvB >= sIconEnvColors[sIconFlashColorIdx][2]) { + sIconEnvB -= envB; + } else { + sIconEnvB += envB; + } + + sIconFlashTimer--; + + if (sIconFlashTimer == 0) { + sIconPrimR = sIconPrimColors[sIconFlashColorIdx][0]; + sIconPrimG = sIconPrimColors[sIconFlashColorIdx][1]; + sIconPrimB = sIconPrimColors[sIconFlashColorIdx][2]; + sIconEnvR = sIconEnvColors[sIconFlashColorIdx][0]; + sIconEnvG = sIconEnvColors[sIconFlashColorIdx][1]; + sIconEnvB = sIconEnvColors[sIconFlashColorIdx][2]; + sIconFlashTimer = 12; + sIconFlashColorIdx ^= 1; + } + + gDPPipeSync(gfx++); + + gDPSetCombineLERP(gfx++, PRIMITIVE, ENVIRONMENT, TEXEL0, ENVIRONMENT, TEXEL0, 0, PRIMITIVE, 0, PRIMITIVE, + ENVIRONMENT, TEXEL0, ENVIRONMENT, TEXEL0, 0, PRIMITIVE, 0); + + gDPSetPrimColor(gfx++, 0, 0, sIconPrimR, sIconPrimG, sIconPrimB, 255); + gDPSetEnvColor(gfx++, sIconEnvR, sIconEnvG, sIconEnvB, 255); + + gDPLoadTextureBlock_4b(gfx++, iconTexture, G_IM_FMT_I, FONT_CHAR_TEX_WIDTH, FONT_CHAR_TEX_HEIGHT, 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); + + sCharTexSize = 16.0f * ((f32)R_TEXT_CHAR_SCALE / 100.0f); + sCharTexScale = 1024.0f / ((f32)R_TEXT_CHAR_SCALE / 100.0f); + + gSPTextureRectangle(gfx++, x << 2, y << 2, (x + sCharTexSize) << 2, (y + sCharTexSize) << 2, G_TX_RENDERTILE, 0, 0, + sCharTexScale, sCharTexScale); + + msgCtx->stateTimer++; + + *p = gfx; +} + +#define MESSAGE_SPACE_WIDTH 6 +f32 sFontWidths[144] = { + 8.0f, // ' ' + 8.0f, // '!' + 6.0f, // '"' + 9.0f, // '#' + 9.0f, // '$' + 14.0f, // '%' + 12.0f, // '&' + 3.0f, // ''' + 7.0f, // '(' + 7.0f, // ')' + 7.0f, // '*' + 9.0f, // '+' + 4.0f, // ',' + 6.0f, // '-' + 4.0f, // '.' + 9.0f, // '/' + 10.0f, // '0' + 5.0f, // '1' + 9.0f, // '2' + 9.0f, // '3' + 10.0f, // '4' + 9.0f, // '5' + 9.0f, // '6' + 9.0f, // '7' + 9.0f, // '8' + 9.0f, // '9' + 6.0f, // ':' + 6.0f, // ';' + 9.0f, // '<' + 11.0f, // '=' + 9.0f, // '>' + 11.0f, // '?' + 13.0f, // '@' + 12.0f, // 'A' + 9.0f, // 'B' + 11.0f, // 'C' + 11.0f, // 'D' + 8.0f, // 'E' + 8.0f, // 'F' + 12.0f, // 'G' + 10.0f, // 'H' + 4.0f, // 'I' + 8.0f, // 'J' + 10.0f, // 'K' + 8.0f, // 'L' + 13.0f, // 'M' + 11.0f, // 'N' + 13.0f, // 'O' + 9.0f, // 'P' + 13.0f, // 'Q' + 10.0f, // 'R' + 10.0f, // 'S' + 9.0f, // 'T' + 10.0f, // 'U' + 11.0f, // 'V' + 15.0f, // 'W' + 11.0f, // 'X' + 10.0f, // 'Y' + 10.0f, // 'Z' + 7.0f, // '[' + 10.0f, // '\' + 7.0f, // ']' + 10.0f, // '^' + 9.0f, // '_' + 5.0f, // '`' + 8.0f, // 'a' + 9.0f, // 'b' + 8.0f, // 'c' + 9.0f, // 'd' + 9.0f, // 'e' + 6.0f, // 'f' + 9.0f, // 'g' + 8.0f, // 'h' + 4.0f, // 'i' + 6.0f, // 'j' + 8.0f, // 'k' + 4.0f, // 'l' + 12.0f, // 'm' + 9.0f, // 'n' + 9.0f, // 'o' + 9.0f, // 'p' + 9.0f, // 'q' + 7.0f, // 'r' + 8.0f, // 's' + 7.0f, // 't' + 8.0f, // 'u' + 9.0f, // 'v' + 12.0f, // 'w' + 8.0f, // 'x' + 9.0f, // 'y' + 8.0f, // 'z' + 7.0f, // '{' + 5.0f, // '|' + 7.0f, // '}' + 10.0f, // '~' + 10.0f, // '‾' + 12.0f, // 'À' + 6.0f, // 'î' + 12.0f, // 'Â' + 12.0f, // 'Ä' + 11.0f, // 'Ç' + 8.0f, // 'È' + 8.0f, // 'É' + 8.0f, // 'Ê' + 6.0f, // 'Ë' + 6.0f, // 'Ï' + 13.0f, // 'Ô' + 13.0f, // 'Ö' + 10.0f, // 'Ù' + 10.0f, // 'Û' + 10.0f, // 'Ü' + 9.0f, // 'ß' + 8.0f, // 'à' + 8.0f, // 'á' + 8.0f, // 'â' + 8.0f, // 'ä' + 8.0f, // 'ç' + 9.0f, // 'è' + 9.0f, // 'é' + 9.0f, // 'ê' + 9.0f, // 'ë' + 6.0f, // 'ï' + 9.0f, // 'ô' + 9.0f, // 'ö' + 9.0f, // 'ù' + 9.0f, // 'û' + 9.0f, // 'ü' + 14.0f, // '[A]' + 14.0f, // '[B]' + 14.0f, // '[C]' + 14.0f, // '[L]' + 14.0f, // '[R]' + 14.0f, // '[Z]' + 14.0f, // '[C-Up]' + 14.0f, // '[C-Down]' + 14.0f, // '[C-Left]' + 14.0f, // '[C-Right]' + 14.0f, // '▼' + 14.0f, // '[Control-Pad]' + 14.0f, // '[D-Pad]' + 14.0f, // ? + 14.0f, // ? + 14.0f, // ? + 14.0f, // ? +}; + +u16 Message_DrawItemIcon(GlobalContext* globalCtx, u16 itemId, Gfx** p, u16 i) { + s32 pad; + Gfx* gfx = *p; + MessageContext* msgCtx = &globalCtx->msgCtx; + + // clang-format off + if (msgCtx->msgMode == MSGMODE_TEXT_DISPLAYING) { Audio_PlaySoundGeneral(0, &D_801333D4, 4, &D_801333E0, &D_801333E0, &D_801333E8); } + // clang-format on + + gDPPipeSync(gfx++); + gDPSetCombineMode(gfx++, G_CC_MODULATEIA_PRIM, G_CC_MODULATEIA_PRIM); + gDPSetPrimColor(gfx++, 0, 0, 255, 255, 255, msgCtx->textColorAlpha); + + if (itemId >= ITEM_MEDALLION_FOREST) { + gDPLoadTextureBlock(gfx++, (u32)msgCtx->textboxSegment + MESSAGE_STATIC_TEX_SIZE, G_IM_FMT_RGBA, G_IM_SIZ_32b, + 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); + } else { + gDPLoadTextureBlock(gfx++, (u32)msgCtx->textboxSegment + MESSAGE_STATIC_TEX_SIZE, G_IM_FMT_RGBA, G_IM_SIZ_32b, + 32, 32, 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(gfx++, (msgCtx->textPosX + R_TEXTBOX_ICON_XPOS) << 2, R_TEXTBOX_ICON_YPOS << 2, + (msgCtx->textPosX + R_TEXTBOX_ICON_XPOS + R_TEXTBOX_ICON_SIZE) << 2, + (R_TEXTBOX_ICON_YPOS + R_TEXTBOX_ICON_SIZE) << 2, G_TX_RENDERTILE, 0, 0, 1 << 10, 1 << 10); + gDPPipeSync(gfx++); + gDPSetCombineLERP(gfx++, 0, 0, 0, PRIMITIVE, TEXEL0, 0, PRIMITIVE, 0, 0, 0, 0, PRIMITIVE, TEXEL0, 0, PRIMITIVE, 0); + + msgCtx->textPosX += 32; + + i++; + *p = gfx; + + return i; +} + +void Message_HandleOcarina(GlobalContext* globalCtx) { + MessageContext* msgCtx = &globalCtx->msgCtx; + + if (globalCtx->msgCtx.msgMode == MSGMODE_TEXT_DISPLAYING) { + globalCtx->msgCtx.ocarinaMode = OCARINA_MODE_01; + + if (msgCtx->ocarinaAction == OCARINA_ACTION_SCARECROW_LONG_RECORDING) { + msgCtx->msgMode = MSGMODE_SCARECROW_LONG_RECORDING_START; + // "Recording Start / Recording Start / Recording Start / Recording Start -> " + osSyncPrintf("録音開始 録音開始 録音開始 録音開始 -> "); + } else if (msgCtx->ocarinaAction == OCARINA_ACTION_SCARECROW_LONG_PLAYBACK) { + // "Recording Playback / Recording Playback / Recording Playback / Recording Playback -> " + osSyncPrintf("録音再生 録音再生 録音再生 録音再生 -> "); + Audio_OcaSetInstrument(1); + Audio_OcaSetInstrument(1); + msgCtx->ocarinaStaff = Audio_OcaGetDisplayingStaff(); + sOcarinaNoteBufPos = sOcarinaNoteBufLen = 0; + msgCtx->ocarinaStaff->pos = sOcarinaNoteBufPos; + Message_ResetOcarinaNoteState(); + msgCtx->stateTimer = 3; + msgCtx->msgMode = MSGMODE_SCARECROW_LONG_PLAYBACK; + Audio_OcaSetSongPlayback(OCARINA_SONG_SCARECROW_LONG + 1, 1); + } else if (msgCtx->ocarinaAction == OCARINA_ACTION_SCARECROW_RECORDING) { + msgCtx->msgMode = MSGMODE_SCARECROW_RECORDING_START; + // "8 Note Recording Start / 8 Note Recording Start / 8 Note Recording Start -> " + osSyncPrintf("8音録音開始 8音録音開始 8音録音開始 -> "); + } else if (msgCtx->ocarinaAction == OCARINA_ACTION_SCARECROW_PLAYBACK) { + // "8 Note Playback / 8 Note Playback / 8 Note Playback -> " + osSyncPrintf("8音再生 8音再生 8音再生 -> "); + Audio_OcaSetInstrument(1); + Audio_OcaSetInstrument(1); + msgCtx->ocarinaStaff = Audio_OcaGetDisplayingStaff(); + sOcarinaNoteBufPos = sOcarinaNoteBufLen = 0; + msgCtx->ocarinaStaff->pos = sOcarinaNoteBufPos; + Message_ResetOcarinaNoteState(); + msgCtx->stateTimer = 3; + msgCtx->msgMode = MSGMODE_SCARECROW_PLAYBACK; + Audio_OcaSetSongPlayback(OCARINA_SONG_SCARECROW + 1, 1); + } else if (msgCtx->ocarinaAction == OCARINA_ACTION_MEMORY_GAME) { + msgCtx->msgMode = MSGMODE_MEMORY_GAME_START; + // "Musical Round Start / Musical Round Start / Musical Round Start / Musical Round Start -> " + osSyncPrintf("輪唱開始 輪唱開始 輪唱開始 輪唱開始 -> "); + } else if (msgCtx->ocarinaAction == OCARINA_ACTION_FROGS) { + msgCtx->msgMode = MSGMODE_FROGS_START; + // "Frog Chorus / Frog Chorus -> " + osSyncPrintf("カエルの合唱 カエルの合唱 -> "); + } else { + // "Ocarina(%d)" + osSyncPrintf("オカリナ(%d) ", msgCtx->ocarinaAction); + if (msgCtx->ocarinaAction == OCARINA_ACTION_UNK_0 || msgCtx->ocarinaAction == OCARINA_ACTION_FREE_PLAY || + msgCtx->ocarinaAction >= OCARINA_ACTION_CHECK_SARIA) { + msgCtx->msgMode = MSGMODE_OCARINA_STARTING; + osSyncPrintf("000000000000 -> "); + } else if (msgCtx->ocarinaAction >= OCARINA_ACTION_TEACH_MINUET && + msgCtx->ocarinaAction <= OCARINA_ACTION_TEACH_STORMS) { + msgCtx->msgMode = MSGMODE_SONG_DEMONSTRATION_STARTING; + osSyncPrintf("111111111111 -> "); + } else { + msgCtx->msgMode = MSGMODE_SONG_PLAYBACK_STARTING; + osSyncPrintf("222222222222 -> "); + } + } + osSyncPrintf("msg_mode=%d\n", msgCtx->msgMode); + } +} + +/** + * Draws the text contents of a textbox, up to the current point that has + * been scrolled to so far. + */ +void Message_DrawText(GlobalContext* globalCtx, Gfx** gfxP) { + MessageContext* msgCtx = &globalCtx->msgCtx; + u16 lookAheadCharacter; + u8 character; + u16 j; + u16 i; + u16 sfxHi; + u16 charTexIdx; + Font* font = &globalCtx->msgCtx.font; + Gfx* gfx = *gfxP; + + globalCtx->msgCtx.textPosX = R_TEXT_INIT_XPOS; + + if (sTextIsCredits == false) { + msgCtx->textPosY = R_TEXT_INIT_YPOS; + } else { + msgCtx->textPosY = YREG(1); + } + + if (msgCtx->textBoxType == TEXTBOX_TYPE_NONE_NO_SHADOW) { + msgCtx->textColorR = msgCtx->textColorG = msgCtx->textColorB = 0; + } else { + msgCtx->textColorR = msgCtx->textColorG = msgCtx->textColorB = 255; + } + + msgCtx->unk_E3D0 = 0; + charTexIdx = 0; + + for (i = 0; i < msgCtx->textDrawPos; i++) { + character = msgCtx->msgBufDecoded[i]; + + switch (character) { + case MESSAGE_NEWLINE: + msgCtx->textPosX = R_TEXT_INIT_XPOS; + if (msgCtx->choiceNum == 1 || msgCtx->choiceNum == 3) { + msgCtx->textPosX += 32; + } + if (msgCtx->choiceNum == 2 && msgCtx->textPosY != R_TEXT_INIT_YPOS) { + msgCtx->textPosX += 32; + } + msgCtx->textPosY += R_TEXT_LINE_SPACING; + break; + case MESSAGE_COLOR: + Message_SetTextColor(msgCtx, msgCtx->msgBufDecoded[++i] & 0xF); + break; + case ' ': + msgCtx->textPosX += MESSAGE_SPACE_WIDTH; + break; + case MESSAGE_BOX_BREAK: + if (msgCtx->msgMode == MSGMODE_TEXT_DISPLAYING) { + if (!sTextboxSkipped) { + Audio_PlaySoundGeneral(0, &D_801333D4, 4, &D_801333E0, &D_801333E0, &D_801333E8); + msgCtx->msgMode = MSGMODE_TEXT_AWAIT_NEXT; + Font_LoadMessageBoxIcon(font, TEXTBOX_ICON_TRIANGLE); + } else { + msgCtx->msgMode = MSGMODE_TEXT_NEXT_MSG; + msgCtx->textUnskippable = false; + msgCtx->msgBufPos++; + } + } + *gfxP = gfx; + return; + case MESSAGE_SHIFT: + msgCtx->textPosX += msgCtx->msgBufDecoded[++i]; + break; + case MESSAGE_TEXTID: + msgCtx->textboxEndType = TEXTBOX_ENDTYPE_HAS_NEXT; + if (msgCtx->msgMode == MSGMODE_TEXT_DISPLAYING) { + Audio_PlaySoundGeneral(0, &D_801333D4, 4, &D_801333E0, &D_801333E0, &D_801333E8); + msgCtx->msgMode = MSGMODE_TEXT_DONE; + Font_LoadMessageBoxIcon(font, TEXTBOX_ICON_TRIANGLE); + } + *gfxP = gfx; + return; + case MESSAGE_QUICKTEXT_ENABLE: + if (i + 1 == msgCtx->textDrawPos && (msgCtx->msgMode == MSGMODE_TEXT_DISPLAYING || + (msgCtx->msgMode >= MSGMODE_OCARINA_STARTING && + msgCtx->msgMode < MSGMODE_SCARECROW_LONG_RECORDING_START))) { + j = i; + while (true) { + lookAheadCharacter = msgCtx->msgBufDecoded[j]; + if (lookAheadCharacter == MESSAGE_SHIFT) { + j += 2; + } else if ((lookAheadCharacter != MESSAGE_QUICKTEXT_DISABLE) && + (lookAheadCharacter != MESSAGE_PERSISTENT) && + (lookAheadCharacter != MESSAGE_EVENT) && + (lookAheadCharacter != MESSAGE_BOX_BREAK_DELAYED) && + (lookAheadCharacter != MESSAGE_AWAIT_BUTTON_PRESS) && + (lookAheadCharacter != MESSAGE_BOX_BREAK) && (lookAheadCharacter != MESSAGE_END)) { + j++; + } else { + break; + } + } + i = j - 1; + msgCtx->textDrawPos = i + 1; + + if (character) {} + } + case MESSAGE_QUICKTEXT_DISABLE: + break; + case MESSAGE_AWAIT_BUTTON_PRESS: + if (i + 1 == msgCtx->textDrawPos) { + if (msgCtx->msgMode == MSGMODE_TEXT_DISPLAYING) { + msgCtx->msgMode = MSGMODE_TEXT_AWAIT_INPUT; + Font_LoadMessageBoxIcon(font, TEXTBOX_ICON_TRIANGLE); + } + *gfxP = gfx; + return; + } + break; + case MESSAGE_BOX_BREAK_DELAYED: + if (msgCtx->msgMode == MSGMODE_TEXT_DISPLAYING) { + msgCtx->stateTimer = msgCtx->msgBufDecoded[++i]; + msgCtx->msgMode = MSGMODE_TEXT_DELAYED_BREAK; + } + *gfxP = gfx; + return; + case MESSAGE_FADE2: + if (msgCtx->msgMode == MSGMODE_TEXT_DISPLAYING) { + msgCtx->msgMode = MSGMODE_TEXT_DONE; + msgCtx->textboxEndType = TEXTBOX_ENDTYPE_FADING; + // "Timer" + osSyncPrintf("タイマー (%x) (%x)", msgCtx->msgBufDecoded[i + 1], msgCtx->msgBufDecoded[i + 2]); + msgCtx->stateTimer = msgCtx->msgBufDecoded[++i] << 8; + msgCtx->stateTimer |= msgCtx->msgBufDecoded[++i]; + // "Total wct" + osSyncPrintf("合計wct=%x(%d)\n", msgCtx->stateTimer, msgCtx->stateTimer); + } + *gfxP = gfx; + return; + case MESSAGE_SFX: + if (msgCtx->msgMode == MSGMODE_TEXT_DISPLAYING && !sMessageHasSetSfx) { + sMessageHasSetSfx = true; + // "Sound (SE)" + osSyncPrintf("サウンド(SE)\n"); + sfxHi = msgCtx->msgBufDecoded[i + 1] << 8; + Audio_PlaySoundGeneral(sfxHi | msgCtx->msgBufDecoded[i + 2], &D_801333D4, 4, &D_801333E0, + &D_801333E0, &D_801333E8); + } + i += 2; + break; + case MESSAGE_ITEM_ICON: + i = Message_DrawItemIcon(globalCtx, msgCtx->msgBufDecoded[i + 1], &gfx, i); + break; + case MESSAGE_BACKGROUND: + // clang-format off + if (msgCtx->msgMode == MSGMODE_TEXT_DISPLAYING) { Audio_PlaySoundGeneral(0, &D_801333D4, 4, &D_801333E0, &D_801333E0, &D_801333E8); } + // clang-format on + gDPPipeSync(gfx++); + gDPSetCombineMode(gfx++, G_CC_MODULATEIA_PRIM, G_CC_MODULATEIA_PRIM); + gDPSetPrimColor(gfx++, 0, 0, sTextboxBackgroundBackPrimColors[msgCtx->textboxBackgroundBackColorIdx][0], + sTextboxBackgroundBackPrimColors[msgCtx->textboxBackgroundBackColorIdx][1], + sTextboxBackgroundBackPrimColors[msgCtx->textboxBackgroundBackColorIdx][2], + msgCtx->textColorAlpha); + + gDPLoadTextureBlock_4b(gfx++, (u32)msgCtx->textboxSegment + MESSAGE_STATIC_TEX_SIZE, G_IM_FMT_I, 96, 48, + 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( + gfx++, (msgCtx->textPosX + 1) << 2, + (R_TEXTBOX_BG_YPOS + sTextboxBackgroundYOffsets[msgCtx->textboxBackgroundYOffsetIdx]) << 2, + (msgCtx->textPosX + 96 + 1) << 2, + (R_TEXTBOX_BG_YPOS + sTextboxBackgroundYOffsets[msgCtx->textboxBackgroundYOffsetIdx] + 48) << 2, + G_TX_RENDERTILE, 0, 0, 1 << 10, 1 << 10); + + gDPLoadTextureBlock_4b(gfx++, (u32)msgCtx->textboxSegment + MESSAGE_STATIC_TEX_SIZE + 0x900, G_IM_FMT_I, + 96, 48, 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( + gfx++, (msgCtx->textPosX + 96 + 1) << 2, + (R_TEXTBOX_BG_YPOS + sTextboxBackgroundYOffsets[msgCtx->textboxBackgroundYOffsetIdx]) << 2, + (msgCtx->textPosX + 96 + 1 + 96 + 1) << 2, + (R_TEXTBOX_BG_YPOS + sTextboxBackgroundYOffsets[msgCtx->textboxBackgroundYOffsetIdx] + 48) << 2, + G_TX_RENDERTILE, 0, 0, 1 << 10, 1 << 10); + + gDPPipeSync(gfx++); + gDPSetPrimColor(gfx++, 0, 0, sTextboxBackgroundForePrimColors[msgCtx->textboxBackgroundForeColorIdx][0], + sTextboxBackgroundForePrimColors[msgCtx->textboxBackgroundForeColorIdx][1], + sTextboxBackgroundForePrimColors[msgCtx->textboxBackgroundForeColorIdx][2], + msgCtx->textColorAlpha); + + gDPLoadTextureBlock_4b(gfx++, ((u32)msgCtx->textboxSegment + MESSAGE_STATIC_TEX_SIZE), G_IM_FMT_I, 96, + 48, 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(gfx++, msgCtx->textPosX << 2, R_TEXTBOX_BG_YPOS << 2, (msgCtx->textPosX + 96) << 2, + (R_TEXTBOX_BG_YPOS + 48) << 2, G_TX_RENDERTILE, 0, 0, 1 << 10, 1 << 10); + + gDPLoadTextureBlock_4b(gfx++, ((u32)msgCtx->textboxSegment + MESSAGE_STATIC_TEX_SIZE + 0x900), + G_IM_FMT_I, 96, 48, 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(gfx++, (msgCtx->textPosX + 96) << 2, R_TEXTBOX_BG_YPOS << 2, + (msgCtx->textPosX + 192) << 2, (R_TEXTBOX_BG_YPOS + 48) << 2, G_TX_RENDERTILE, 0, 0, + 1 << 10, 1 << 10); + + gDPPipeSync(gfx++); + gDPSetCombineLERP(gfx++, 0, 0, 0, PRIMITIVE, TEXEL0, 0, PRIMITIVE, 0, 0, 0, 0, PRIMITIVE, TEXEL0, 0, + PRIMITIVE, 0); + + msgCtx->textPosX += 32; + break; + case MESSAGE_TEXT_SPEED: + msgCtx->textDelay = msgCtx->msgBufDecoded[++i]; + break; + case MESSAGE_UNSKIPPABLE: + msgCtx->textUnskippable = true; + break; + case MESSAGE_TWO_CHOICE: + msgCtx->textboxEndType = TEXTBOX_ENDTYPE_2_CHOICE; + if (msgCtx->msgMode == MSGMODE_TEXT_DISPLAYING) { + msgCtx->choiceTextId = msgCtx->textId; + msgCtx->stateTimer = 4; + msgCtx->choiceIndex = 0; + Font_LoadMessageBoxIcon(font, TEXTBOX_ICON_ARROW); + } + break; + case MESSAGE_THREE_CHOICE: + msgCtx->textboxEndType = TEXTBOX_ENDTYPE_3_CHOICE; + if (msgCtx->msgMode == MSGMODE_TEXT_DISPLAYING) { + msgCtx->choiceTextId = msgCtx->textId; + msgCtx->stateTimer = 4; + msgCtx->choiceIndex = 0; + Font_LoadMessageBoxIcon(font, TEXTBOX_ICON_ARROW); + } + break; + case MESSAGE_END: + if (msgCtx->msgMode == MSGMODE_TEXT_DISPLAYING) { + msgCtx->msgMode = MSGMODE_TEXT_DONE; + if (msgCtx->textboxEndType == TEXTBOX_ENDTYPE_DEFAULT) { + Audio_PlaySoundGeneral(NA_SE_SY_MESSAGE_END, &D_801333D4, 4, &D_801333E0, &D_801333E0, + &D_801333E8); + Font_LoadMessageBoxIcon(font, TEXTBOX_ICON_SQUARE); + if (globalCtx->csCtx.state == 0) { + Interface_SetDoAction(globalCtx, DO_ACTION_RETURN); + } + } + } + *gfxP = gfx; + return; + case MESSAGE_OCARINA: + if (i + 1 == msgCtx->textDrawPos) { + Message_HandleOcarina(globalCtx); + *gfxP = gfx; + return; + } + break; + case MESSAGE_FADE: + if (msgCtx->msgMode == MSGMODE_TEXT_DISPLAYING) { + msgCtx->msgMode = MSGMODE_TEXT_DONE; + msgCtx->textboxEndType = TEXTBOX_ENDTYPE_FADING; + msgCtx->stateTimer = msgCtx->msgBufDecoded[++i]; + Font_LoadMessageBoxIcon(font, TEXTBOX_ICON_SQUARE); + if (globalCtx->csCtx.state == 0) { + Interface_SetDoAction(globalCtx, DO_ACTION_RETURN); + } + } + *gfxP = gfx; + return; + case MESSAGE_PERSISTENT: + if (msgCtx->msgMode == MSGMODE_TEXT_DISPLAYING) { + Audio_PlaySoundGeneral(0, &D_801333D4, 4, &D_801333E0, &D_801333E0, &D_801333E8); + msgCtx->msgMode = MSGMODE_TEXT_DONE; + msgCtx->textboxEndType = TEXTBOX_ENDTYPE_PERSISTENT; + } + *gfxP = gfx; + return; + case MESSAGE_EVENT: + if (msgCtx->msgMode == MSGMODE_TEXT_DISPLAYING) { + msgCtx->msgMode = MSGMODE_TEXT_DONE; + msgCtx->textboxEndType = TEXTBOX_ENDTYPE_EVENT; + Font_LoadMessageBoxIcon(font, TEXTBOX_ICON_TRIANGLE); + Audio_PlaySoundGeneral(NA_SE_SY_MESSAGE_END, &D_801333D4, 4, &D_801333E0, &D_801333E0, &D_801333E8); + } + *gfxP = gfx; + return; + default: + if (msgCtx->msgMode == MSGMODE_TEXT_DISPLAYING && i + 1 == msgCtx->textDrawPos && + msgCtx->textDelayTimer == msgCtx->textDelay) { + Audio_PlaySoundGeneral(0, &D_801333D4, 4, &D_801333E0, &D_801333E0, &D_801333E8); + } + Message_DrawTextChar(globalCtx, &font->charTexBuf[charTexIdx], &gfx); + charTexIdx += FONT_CHAR_TEX_SIZE; + + msgCtx->textPosX += (s32)(sFontWidths[character - ' '] * (R_TEXT_CHAR_SCALE / 100.0f)); + break; + } + } + if (msgCtx->textDelayTimer == 0) { + msgCtx->textDrawPos = i + 1; + msgCtx->textDelayTimer = msgCtx->textDelay; + } else { + msgCtx->textDelayTimer--; + } + *gfxP = gfx; +} + +void Message_LoadItemIcon(GlobalContext* globalCtx, u16 itemId, s16 y) { + static s16 sIconItem32XOffsets[] = { 74, 74, 74 }; + static s16 sIconItem24XOffsets[] = { 72, 72, 72 }; + MessageContext* msgCtx = &globalCtx->msgCtx; + InterfaceContext* interfaceCtx = &globalCtx->interfaceCtx; + + if (itemId == ITEM_DUNGEON_MAP) { + interfaceCtx->mapPalette[30] = 0xFF; + interfaceCtx->mapPalette[31] = 0xFF; + } + if (itemId < ITEM_MEDALLION_FOREST) { + R_TEXTBOX_ICON_XPOS = R_TEXT_INIT_XPOS - sIconItem32XOffsets[gSaveContext.language]; + R_TEXTBOX_ICON_YPOS = y + 6; + R_TEXTBOX_ICON_SIZE = 32; + DmaMgr_SendRequest1((u32)msgCtx->textboxSegment + MESSAGE_STATIC_TEX_SIZE, + (u32)_icon_item_staticSegmentRomStart + (itemId * 0x1000), 0x1000, "../z_message_PAL.c", + 1473); + // "Item 32-0" + osSyncPrintf("アイテム32-0\n"); + } else { + R_TEXTBOX_ICON_XPOS = R_TEXT_INIT_XPOS - sIconItem24XOffsets[gSaveContext.language]; + R_TEXTBOX_ICON_YPOS = y + 10; + R_TEXTBOX_ICON_SIZE = 24; + DmaMgr_SendRequest1((u32)msgCtx->textboxSegment + MESSAGE_STATIC_TEX_SIZE, + (u32)_icon_item_24_staticSegmentRomStart + (itemId - ITEM_MEDALLION_FOREST) * 0x900, 0x900, + "../z_message_PAL.c", 1482); + // "Item 24" + osSyncPrintf("アイテム24=%d (%d) {%d}\n", itemId, itemId - ITEM_KOKIRI_EMERALD, 84); + } + msgCtx->msgBufPos++; + msgCtx->choiceNum = 1; +} + +void Message_Decode(GlobalContext* globalCtx) { + u8 temp_s2; + u8 phi_s1; + u16 phi_s0_3; + s32 loadChar; + s32 charTexIdx = 0; + s16 playerNameLen; + s16 decodedBufPos = 0; + s16 numLines = 0; + s16 i; + s16 digits[4]; + f32 timeInSeconds; + MessageContext* msgCtx = &globalCtx->msgCtx; + Font* font = &globalCtx->msgCtx.font; + + globalCtx->msgCtx.textDelayTimer = 0; + globalCtx->msgCtx.textUnskippable = globalCtx->msgCtx.textDelay = globalCtx->msgCtx.textDelayTimer = 0; + sTextFade = false; + + while (true) { + phi_s1 = temp_s2 = msgCtx->msgBufDecoded[decodedBufPos] = font->msgBuf[msgCtx->msgBufPos]; + + if (temp_s2 == MESSAGE_BOX_BREAK || temp_s2 == MESSAGE_TEXTID || temp_s2 == MESSAGE_BOX_BREAK_DELAYED || + temp_s2 == MESSAGE_EVENT || temp_s2 == MESSAGE_END) { + // Textbox decoding ends with any of the above text control characters + msgCtx->msgMode = MSGMODE_TEXT_DISPLAYING; + msgCtx->textDrawPos = 1; + R_TEXT_INIT_YPOS = R_TEXTBOX_Y + 8; + osSyncPrintf("JJ=%d\n", numLines); + if (msgCtx->textBoxType != TEXTBOX_TYPE_NONE_BOTTOM) { + if (numLines == 0) { + R_TEXT_INIT_YPOS = (u16)(R_TEXTBOX_Y + 26); + } else if (numLines == 1) { + R_TEXT_INIT_YPOS = (u16)(R_TEXTBOX_Y + 20); + } else if (numLines == 2) { + R_TEXT_INIT_YPOS = (u16)(R_TEXTBOX_Y + 16); + } + } + if (phi_s1 == MESSAGE_TEXTID) { + osSyncPrintf("NZ_NEXTMSG=%x, %x, %x\n", font->msgBuf[msgCtx->msgBufPos], + font->msgBuf[msgCtx->msgBufPos + 1], font->msgBuf[msgCtx->msgBufPos + 2]); + temp_s2 = msgCtx->msgBufDecoded[++decodedBufPos] = font->msgBuf[msgCtx->msgBufPos + 1]; + msgCtx->msgBufDecoded[++decodedBufPos] = font->msgBuf[msgCtx->msgBufPos + 2]; + phi_s0_3 = temp_s2 << 8; + sNextTextId = msgCtx->msgBufDecoded[decodedBufPos] | phi_s0_3; + } + if (phi_s1 == MESSAGE_BOX_BREAK_DELAYED) { + msgCtx->msgBufDecoded[++decodedBufPos] = font->msgBuf[msgCtx->msgBufPos + 1]; + msgCtx->msgBufPos += 2; + } + msgCtx->decodedTextLen = decodedBufPos; + if (sTextboxSkipped) { + msgCtx->textDrawPos = msgCtx->decodedTextLen; + } + break; + } else if (temp_s2 == MESSAGE_NAME) { + // Substitute the player name control character for the file's player name. + for (playerNameLen = ARRAY_COUNT(gSaveContext.playerName); playerNameLen > 0; playerNameLen--) { + if (gSaveContext.playerName[playerNameLen - 1] != 0x3E) { + break; + } + } + // "Name" + osSyncPrintf("\n名前 = "); + for (i = 0; i < playerNameLen; i++) { + phi_s1 = gSaveContext.playerName[i]; + if (phi_s1 == 0x3E) { + phi_s1 = ' '; + } else if (phi_s1 == 0x40) { + phi_s1 = '.'; + } else if (phi_s1 == 0x3F) { + phi_s1 = '-'; + } else if (phi_s1 < 0xA) { + phi_s1 += 0; + phi_s1 += '0'; + } else if (phi_s1 < 0x24) { + phi_s1 += 0; + phi_s1 += '7'; + } else if (phi_s1 < 0x3E) { + phi_s1 += 0; + phi_s1 += '='; + } + if (phi_s1 != ' ') { + Font_LoadChar(font, phi_s1 - ' ', charTexIdx); + charTexIdx += FONT_CHAR_TEX_SIZE; + } + osSyncPrintf("%x ", phi_s1); + msgCtx->msgBufDecoded[decodedBufPos] = phi_s1; + decodedBufPos++; + } + decodedBufPos--; + } else if (temp_s2 == MESSAGE_MARATHON_TIME || temp_s2 == MESSAGE_RACE_TIME) { + // Convert the values of the appropriate timer to digits and add the + // digits to the decoded buffer in place of the control character. + // "EVENT timer" + osSyncPrintf("\nEVENTタイマー = "); + digits[0] = digits[1] = digits[2] = 0; + if (temp_s2 == MESSAGE_RACE_TIME) { + digits[3] = gSaveContext.timer1Value; + } else { + digits[3] = gSaveContext.timer2Value; + } + + while (digits[3] >= 60) { + digits[1]++; + if (digits[1] >= 10) { + digits[0]++; + digits[1] -= 10; + } + digits[3] -= 60; + } + while (digits[3] >= 10) { + digits[2]++; + digits[3] -= 10; + } + + for (i = 0; i < 4; i++) { + Font_LoadChar(font, digits[i] + '0' - ' ', charTexIdx); + charTexIdx += FONT_CHAR_TEX_SIZE; + msgCtx->msgBufDecoded[decodedBufPos] = digits[i] + '0'; + decodedBufPos++; + if (i == 1) { + Font_LoadChar(font, '"' - ' ', charTexIdx); + charTexIdx += FONT_CHAR_TEX_SIZE; + msgCtx->msgBufDecoded[decodedBufPos] = '"'; + decodedBufPos++; + } else if (i == 3) { + Font_LoadChar(font, '"' - ' ', charTexIdx); + charTexIdx += FONT_CHAR_TEX_SIZE; + msgCtx->msgBufDecoded[decodedBufPos] = '"'; + } + } + } else if (temp_s2 == MESSAGE_POINTS) { + // Convert the values of the current minigame score to digits and + // add the digits to the decoded buffer in place of the control character. + // "Yabusame score" + osSyncPrintf("\n流鏑馬スコア = %d\n", gSaveContext.minigameScore); + digits[0] = digits[1] = digits[2] = 0; + digits[3] = gSaveContext.minigameScore; + + while (digits[3] >= 1000) { + digits[0]++; + digits[3] -= 1000; + } + while (digits[3] >= 100) { + digits[1]++; + digits[3] -= 100; + } + while (digits[3] >= 10) { + digits[2]++; + digits[3] -= 10; + } + + loadChar = false; + for (i = 0; i < 4; i++) { + if (i == 3 || digits[i] != 0) { + loadChar = true; + } + if (loadChar) { + Font_LoadChar(font, digits[i] + '0' - ' ', charTexIdx); + msgCtx->msgBufDecoded[decodedBufPos] = digits[i] + '0'; + charTexIdx += FONT_CHAR_TEX_SIZE; + decodedBufPos++; + } + } + decodedBufPos--; + } else if (temp_s2 == MESSAGE_TOKENS) { + // Convert the current number of collected gold skulltula tokens to digits and + // add the digits to the decoded buffer in place of the control character. + // "Total number of gold stars" + osSyncPrintf("\n金スタ合計数 = %d", gSaveContext.inventory.gsTokens); + digits[0] = digits[1] = 0; + digits[2] = gSaveContext.inventory.gsTokens; + + while (digits[2] >= 100) { + digits[0]++; + digits[2] -= 100; + } + while (digits[2] >= 10) { + digits[1]++; + digits[2] -= 10; + } + + loadChar = false; + for (i = 0; i < 3; i++) { + if (i == 2 || digits[i] != 0) { + loadChar = true; + } + if (loadChar) { + Font_LoadChar(font, digits[i] + '0' - ' ', charTexIdx); + msgCtx->msgBufDecoded[decodedBufPos] = digits[i] + '0'; + charTexIdx += FONT_CHAR_TEX_SIZE; + osSyncPrintf("%x(%x) ", digits[i] + '0' - ' ', digits[i]); + decodedBufPos++; + } + } + decodedBufPos--; + } else if (temp_s2 == MESSAGE_FISH_INFO) { + // "Fishing hole fish size" + osSyncPrintf("\n釣り堀魚サイズ = "); + digits[0] = 0; + digits[1] = gSaveContext.minigameScore; + + while (digits[1] >= 10) { + digits[0]++; + digits[1] -= 10; + } + + for (i = 0; i < 2; i++) { + if (i == 1 || digits[i] != 0) { + Font_LoadChar(font, digits[i] + '0' - ' ', charTexIdx); + msgCtx->msgBufDecoded[decodedBufPos] = digits[i] + '0'; + charTexIdx += FONT_CHAR_TEX_SIZE; + osSyncPrintf("%x(%x) ", digits[i] + '0' - ' ', digits[i]); + decodedBufPos++; + } + } + decodedBufPos--; + } else if (temp_s2 == MESSAGE_HIGHSCORE) { + phi_s0_3 = HIGH_SCORE((u8)font->msgBuf[++msgCtx->msgBufPos]); + // "Highscore" + osSyncPrintf("ランキング=%d\n", font->msgBuf[msgCtx->msgBufPos]); + if ((font->msgBuf[msgCtx->msgBufPos] & 0xFF) == 2) { + if (LINK_AGE_IN_YEARS == YEARS_CHILD) { + phi_s0_3 &= 0x7F; + } else { + osSyncPrintf("HI_SCORE( kanfont->mbuff.nes_mes_buf[message->rdp] & 0xff000000 ) = %x\n", + HIGH_SCORE(font->msgBufWide[msgCtx->msgBufPos] & 0xFF000000)); + phi_s0_3 = ((HIGH_SCORE((u8)font->msgBuf[msgCtx->msgBufPos]) & 0xFF000000) >> 0x18) & 0x7F; + } + phi_s0_3 = SQ((f32)phi_s0_3) * 0.0036f + 0.5f; + osSyncPrintf("score=%d\n", phi_s0_3); + } + switch (font->msgBuf[msgCtx->msgBufPos] & 0xFF) { + case HS_HBA: + case HS_POE_POINTS: + case HS_FISHING: + digits[0] = digits[1] = digits[2] = 0; + digits[3] = phi_s0_3; + + while (digits[3] >= 1000) { + digits[0]++; + digits[3] -= 1000; + } + while (digits[3] >= 100) { + digits[1]++; + digits[3] -= 100; + } + while (digits[3] >= 10) { + digits[2]++; + digits[3] -= 10; + } + if (temp_s2) {} + + loadChar = false; + for (i = 0; i < 4; i++) { + if (i == 3 || digits[i] != 0) { + loadChar = true; + } + if (loadChar) { + Font_LoadChar(font, digits[i] + '0' - ' ', charTexIdx); + msgCtx->msgBufDecoded[decodedBufPos] = digits[i] + '0'; + charTexIdx += FONT_CHAR_TEX_SIZE; + decodedBufPos++; + } + } + decodedBufPos--; + break; + case HS_UNK_05: + break; + case HS_HORSE_RACE: + case HS_MARATHON: + case HS_DAMPE_RACE: + digits[0] = digits[1] = digits[2] = 0; + digits[3] = phi_s0_3; + + while (digits[3] >= 60) { + digits[1]++; + if (digits[1] >= 10) { + digits[0]++; + digits[1] -= 10; + } + digits[3] -= 60; + } + while (digits[3] >= 10) { + digits[2]++; + digits[3] -= 10; + } + + for (i = 0; i < 4; i++) { + Font_LoadChar(font, digits[i] + '0' - ' ', charTexIdx); + charTexIdx += FONT_CHAR_TEX_SIZE; + msgCtx->msgBufDecoded[decodedBufPos] = digits[i] + '0'; + decodedBufPos++; + if (i == 1) { + Font_LoadChar(font, '"' - ' ', charTexIdx); + charTexIdx += FONT_CHAR_TEX_SIZE; + msgCtx->msgBufDecoded[decodedBufPos] = '"'; + decodedBufPos++; + } else if (i == 3) { + Font_LoadChar(font, '"' - ' ', charTexIdx); + charTexIdx += FONT_CHAR_TEX_SIZE; + msgCtx->msgBufDecoded[decodedBufPos] = '"'; + } + } + break; + } + } else if (temp_s2 == MESSAGE_TIME) { + // "Zelda time" + osSyncPrintf("\nゼルダ時間 = "); + digits[0] = 0; + timeInSeconds = gSaveContext.dayTime * (24.0f * 60.0f / 0x10000); + + digits[1] = timeInSeconds / 60.0f; + while (digits[1] >= 10) { + digits[0]++; + digits[1] -= 10; + } + digits[2] = 0; + digits[3] = (s16)timeInSeconds % 60; + while (digits[3] >= 10) { + digits[2]++; + digits[3] -= 10; + } + + for (i = 0; i < 4; i++) { + Font_LoadChar(font, digits[i] + '0' - ' ', charTexIdx); + charTexIdx += FONT_CHAR_TEX_SIZE; + msgCtx->msgBufDecoded[decodedBufPos] = digits[i] + '0'; + decodedBufPos++; + if (i == 1) { + Font_LoadChar(font, ':' - ' ', charTexIdx); + charTexIdx += FONT_CHAR_TEX_SIZE; + msgCtx->msgBufDecoded[decodedBufPos] = ':'; + decodedBufPos++; + } + } + decodedBufPos--; + } else if (temp_s2 == MESSAGE_ITEM_ICON) { + msgCtx->msgBufDecoded[++decodedBufPos] = font->msgBuf[msgCtx->msgBufPos + 1]; + osSyncPrintf("ITEM_NO=(%d) (%d)\n", msgCtx->msgBufDecoded[decodedBufPos], + font->msgBuf[msgCtx->msgBufPos + 1]); + Message_LoadItemIcon(globalCtx, font->msgBuf[msgCtx->msgBufPos + 1], R_TEXTBOX_Y + 10); + } else if (temp_s2 == MESSAGE_BACKGROUND) { + msgCtx->textboxBackgroundIdx = font->msgBuf[msgCtx->msgBufPos + 1] * 2; + msgCtx->textboxBackgroundForeColorIdx = (font->msgBuf[msgCtx->msgBufPos + 2] & 0xF0) >> 4; + msgCtx->textboxBackgroundBackColorIdx = font->msgBuf[msgCtx->msgBufPos + 2] & 0xF; + msgCtx->textboxBackgroundYOffsetIdx = (font->msgBuf[msgCtx->msgBufPos + 3] & 0xF0) >> 4; + msgCtx->textboxBackgroundUnkArg = font->msgBuf[msgCtx->msgBufPos + 3] & 0xF; + DmaMgr_SendRequest1((u32)msgCtx->textboxSegment + MESSAGE_STATIC_TEX_SIZE, + (u32)_message_texture_staticSegmentRomStart + msgCtx->textboxBackgroundIdx * 0x900, + 0x900, "../z_message_PAL.c", 1830); + DmaMgr_SendRequest1((u32)msgCtx->textboxSegment + MESSAGE_STATIC_TEX_SIZE + 0x900, + (u32)_message_texture_staticSegmentRomStart + + (msgCtx->textboxBackgroundIdx + 1) * 0x900, + 0x900, "../z_message_PAL.c", 1834); + msgCtx->msgBufPos += 3; + R_TEXTBOX_BG_YPOS = R_TEXTBOX_Y + 8; + numLines = 2; + R_TEXT_INIT_XPOS = 50; + } else if (temp_s2 == MESSAGE_COLOR) { + msgCtx->msgBufDecoded[++decodedBufPos] = font->msgBuf[++msgCtx->msgBufPos]; + } else if (temp_s2 == MESSAGE_NEWLINE) { + numLines++; + } else if (temp_s2 != MESSAGE_QUICKTEXT_ENABLE && temp_s2 != MESSAGE_QUICKTEXT_DISABLE && + temp_s2 != MESSAGE_AWAIT_BUTTON_PRESS && temp_s2 != MESSAGE_OCARINA && + temp_s2 != MESSAGE_PERSISTENT && temp_s2 != MESSAGE_UNSKIPPABLE) { + if (temp_s2 == MESSAGE_FADE) { + sTextFade = true; + osSyncPrintf("NZ_TIMER_END (key_off_flag=%d)\n", sTextFade); + msgCtx->msgBufDecoded[++decodedBufPos] = font->msgBuf[++msgCtx->msgBufPos]; + } else if (temp_s2 == MESSAGE_FADE2) { + sTextFade = true; + osSyncPrintf("NZ_BGM (key_off_flag=%d)\n", sTextFade); + msgCtx->msgBufDecoded[++decodedBufPos] = font->msgBuf[++msgCtx->msgBufPos]; + msgCtx->msgBufDecoded[++decodedBufPos] = font->msgBuf[++msgCtx->msgBufPos]; + } else if (temp_s2 == MESSAGE_SHIFT || temp_s2 == MESSAGE_TEXT_SPEED) { + msgCtx->msgBufDecoded[++decodedBufPos] = font->msgBuf[++msgCtx->msgBufPos] & 0xFF; + } else if (temp_s2 == MESSAGE_SFX) { + msgCtx->msgBufDecoded[++decodedBufPos] = font->msgBuf[++msgCtx->msgBufPos]; + msgCtx->msgBufDecoded[++decodedBufPos] = font->msgBuf[++msgCtx->msgBufPos]; + } else if (temp_s2 == MESSAGE_TWO_CHOICE) { + msgCtx->choiceNum = 2; + } else if (temp_s2 == MESSAGE_THREE_CHOICE) { + msgCtx->choiceNum = 3; + } else if (temp_s2 != ' ') { + Font_LoadChar(font, temp_s2 - ' ', charTexIdx); + charTexIdx += FONT_CHAR_TEX_SIZE; + } + } + decodedBufPos++; + msgCtx->msgBufPos++; + } +} + +void Message_OpenText(GlobalContext* globalCtx, u16 textId) { + static s16 messageStaticIndices[] = { 0, 1, 3, 2 }; + MessageContext* msgCtx = &globalCtx->msgCtx; + Font* font = &msgCtx->font; + s16 textBoxType; + + if (msgCtx->msgMode == MSGMODE_NONE) { + gSaveContext.unk_13EE = gSaveContext.unk_13EA; + } + if (YREG(15) == 0x10) { + Interface_ChangeAlpha(5); + } + + sMessageHasSetSfx = D_8014B2F4 = sTextboxSkipped = sTextIsCredits = 0; + + if (textId >= 0x0500 && textId < 0x0600) { // text ids 0500 to 0600 are reserved for credits + sTextIsCredits = true; + R_TEXT_CHAR_SCALE = 85; + R_TEXT_LINE_SPACING = 6; + R_TEXT_INIT_XPOS = 20; + YREG(1) = 48; + } else { + R_TEXT_CHAR_SCALE = 75; + R_TEXT_LINE_SPACING = 12; + R_TEXT_INIT_XPOS = 65; + } + if (textId == 0xC2 || textId == 0xFA) { + // Increments text id based on piece of heart count, assumes the piece of heart text is all + // in order and that you don't have more than the intended amount of heart pieces. + textId += (gSaveContext.inventory.questItems & 0xF0000000 & 0xF0000000) >> 0x1C; + } else if (msgCtx->textId == 0xC && CHECK_OWNED_EQUIP(EQUIP_SWORD, 2)) { + textId = 0xB; // Traded Giant's Knife for Biggoron Sword + } else if (msgCtx->textId == 0xB4 && (gSaveContext.eventChkInf[9] & 0x40)) { + textId = 0xB5; // Destroyed Gold Skulltula + } + // Ocarina Staff + Dialog + if (textId == 0x4077 || // Pierre? + textId == 0x407A || // Pierre? + textId == 0x2061 || // Learning Epona's Song + textId == 0x5035 || // Guru-Guru in Windmill + textId == 0x40AC) { // Ocarina Frog Minigame + Interface_ChangeAlpha(1); + } + msgCtx->textId = textId; + + if (textId == 0x2030) { // Talking to Ingo as adult in Lon Lon Ranch for the first time before freeing Epona + osSyncPrintf(VT_FGCOL(YELLOW)); + osSyncPrintf("???????????????? z_message.c ??????????????????\n"); + osSyncPrintf(VT_RST); + gSaveContext.eventInf[0] = gSaveContext.eventInf[1] = gSaveContext.eventInf[2] = gSaveContext.eventInf[3] = 0; + } + + if (sTextIsCredits) { + Message_FindCreditsMessage(globalCtx, textId); + msgCtx->msgLength = font->msgLength; + DmaMgr_SendRequest1(font->msgBuf, (u32)(_staff_message_data_staticSegmentRomStart + font->msgOffset), + font->msgLength, "../z_message_PAL.c", 1954); + } else { + if (gSaveContext.language == LANGUAGE_ENG) { + Message_FindMessage(globalCtx, textId); + msgCtx->msgLength = font->msgLength; + DmaMgr_SendRequest1(font->msgBuf, (u32)(_nes_message_data_staticSegmentRomStart + font->msgOffset), + font->msgLength, "../z_message_PAL.c", 1966); + } else if (gSaveContext.language == LANGUAGE_GER) { + Message_FindMessage(globalCtx, textId); + msgCtx->msgLength = font->msgLength; + DmaMgr_SendRequest1(font->msgBuf, (u32)(_ger_message_data_staticSegmentRomStart + font->msgOffset), + font->msgLength, "../z_message_PAL.c", 1978); + } else { + Message_FindMessage(globalCtx, textId); + msgCtx->msgLength = font->msgLength; + DmaMgr_SendRequest1(font->msgBuf, (u32)(_fra_message_data_staticSegmentRomStart + font->msgOffset), + font->msgLength, "../z_message_PAL.c", 1990); + } + } + msgCtx->textBoxProperties = font->charTexBuf[0]; + msgCtx->textBoxType = msgCtx->textBoxProperties >> 4; + msgCtx->textBoxPos = msgCtx->textBoxProperties & 0xF; + textBoxType = msgCtx->textBoxType; + // "Text Box Type" + osSyncPrintf("吹き出し種類=%d\n", msgCtx->textBoxType); + if (textBoxType < TEXTBOX_TYPE_NONE_BOTTOM) { + DmaMgr_SendRequest1( + msgCtx->textboxSegment, + (u32)(_message_staticSegmentRomStart + (messageStaticIndices[textBoxType] * MESSAGE_STATIC_TEX_SIZE)), + MESSAGE_STATIC_TEX_SIZE, "../z_message_PAL.c", 2006); + if (textBoxType == TEXTBOX_TYPE_BLACK) { + msgCtx->textboxColorRed = 0; + msgCtx->textboxColorGreen = 0; + msgCtx->textboxColorBlue = 0; + } else if (textBoxType == TEXTBOX_TYPE_WOODEN) { + msgCtx->textboxColorRed = 70; + msgCtx->textboxColorGreen = 50; + msgCtx->textboxColorBlue = 30; + } else if (textBoxType == TEXTBOX_TYPE_BLUE) { + msgCtx->textboxColorRed = 0; + msgCtx->textboxColorGreen = 10; + msgCtx->textboxColorBlue = 50; + } else { + msgCtx->textboxColorRed = 255; + msgCtx->textboxColorGreen = 0; + msgCtx->textboxColorBlue = 0; + } + if (textBoxType == TEXTBOX_TYPE_WOODEN) { + msgCtx->textboxColorAlphaTarget = 230; + } else if (textBoxType == TEXTBOX_TYPE_OCARINA) { + msgCtx->textboxColorAlphaTarget = 180; + } else { + msgCtx->textboxColorAlphaTarget = 170; + } + msgCtx->textboxColorAlphaCurrent = 0; + } + msgCtx->choiceNum = msgCtx->textUnskippable = msgCtx->textboxEndType = 0; + msgCtx->msgBufPos = msgCtx->unk_E3D0 = msgCtx->textDrawPos = 0; +} + +void Message_StartTextbox(GlobalContext* globalCtx, u16 textId, Actor* actor) { + MessageContext* msgCtx = &globalCtx->msgCtx; + + osSyncPrintf(VT_FGCOL(BLUE)); + // "Message" + osSyncPrintf("めっせーじ=%x(%d)\n", textId, actor); + osSyncPrintf(VT_RST); + + msgCtx->ocarinaAction = 0xFFFF; + Message_OpenText(globalCtx, textId); + msgCtx->talkActor = actor; + msgCtx->msgMode = MSGMODE_TEXT_START; + msgCtx->stateTimer = 0; + msgCtx->textDelayTimer = 0; + globalCtx->msgCtx.ocarinaMode = OCARINA_MODE_00; +} + +void Message_ContinueTextbox(GlobalContext* globalCtx, u16 textId) { + MessageContext* msgCtx = &globalCtx->msgCtx; + + osSyncPrintf(VT_FGCOL(GREEN)); + // "Message" + osSyncPrintf("めっせーじ=%x message->msg_data\n", textId, msgCtx->msgLength); + osSyncPrintf(VT_RST); + + msgCtx->msgLength = 0; + Message_OpenText(globalCtx, textId); + msgCtx->msgMode = MSGMODE_NONE; + msgCtx->textboxColorAlphaCurrent = msgCtx->textboxColorAlphaTarget; + msgCtx->msgMode = MSGMODE_TEXT_CONTINUING; + msgCtx->stateTimer = 3; + msgCtx->textboxEndType = msgCtx->msgBufPos = msgCtx->unk_E3D0 = msgCtx->textDrawPos = msgCtx->textDelayTimer = 0; + msgCtx->textColorAlpha = 255; + + if (YREG(31) == 0 && globalCtx->interfaceCtx.unk_1FA == 0) { + Interface_SetDoAction(globalCtx, DO_ACTION_NEXT); + } + msgCtx->textboxColorAlphaCurrent = msgCtx->textboxColorAlphaTarget; +} + +void Message_StartOcarina(GlobalContext* globalCtx, u16 ocarinaActionId) { + static u16 sOcarinaSongFlagsMap[] = { + (1 << OCARINA_SONG_MINUET), (1 << OCARINA_SONG_BOLERO), (1 << OCARINA_SONG_SERENADE), + (1 << OCARINA_SONG_REQUIEM), (1 << OCARINA_SONG_NOCTURNE), (1 << OCARINA_SONG_PRELUDE), + (1 << OCARINA_SONG_LULLABY), (1 << OCARINA_SONG_EPONAS), (1 << OCARINA_SONG_SARIAS), + (1 << OCARINA_SONG_SUNS), (1 << OCARINA_SONG_TIME), (1 << OCARINA_SONG_STORMS), + (1 << OCARINA_SONG_SCARECROW), + }; + MessageContext* msgCtx = &globalCtx->msgCtx; + s32 textId; + s16 j; + s16 i; + s16 noStop; + s32 k; + + osSyncPrintf(VT_FGCOL(GREEN)); + + for (i = sOcarinaSongBitFlags = 0; i < (QUEST_KOKIRI_EMERALD - QUEST_SONG_MINUET); i++) { + if (CHECK_QUEST_ITEM(QUEST_SONG_MINUET + i)) { + osSyncPrintf("ocarina_check_bit[%d]=%x\n", i, sOcarinaSongFlagsMap[i]); + sOcarinaSongBitFlags |= sOcarinaSongFlagsMap[i]; + } + } + if (gSaveContext.scarecrowSpawnSongSet) { + sOcarinaSongBitFlags |= (1 << OCARINA_SONG_SCARECROW); + } + osSyncPrintf("ocarina_bit = %x\n", sOcarinaSongBitFlags); + osSyncPrintf(VT_RST); + + sHasSunsSong = CHECK_QUEST_ITEM(QUEST_SONG_SUN); + msgCtx->ocarinaStaff = Audio_OcaGetRecordingStaff(); + msgCtx->ocarinaStaff->pos = sOcarinaNoteBufPos = 0; + sOcarinaNoteBufLen = 0; + Message_ResetOcarinaNoteState(); + sLastPlayedSong = msgCtx->unk_E3F2 = msgCtx->lastOcaNoteIdx = 0xFF; + + // "Ocarina Number" + osSyncPrintf(VT_FGCOL(RED) "☆☆☆☆☆ オカリナ番号=%d(%d) ☆☆☆☆☆\n" VT_RST, ocarinaActionId, 2); + noStop = false; + if (ocarinaActionId >= 0x893) { + Message_OpenText(globalCtx, ocarinaActionId); // You played the [song name] + textId = ocarinaActionId + 0x86E; + } else if (ocarinaActionId == OCARINA_ACTION_MEMORY_GAME) { + msgCtx->ocarinaAction = ocarinaActionId; + Message_OpenText(globalCtx, 0x86D); // Play using [A] and [C]. + textId = ocarinaActionId + 0x86E; + } else if (ocarinaActionId == OCARINA_ACTION_FREE_PLAY || ocarinaActionId >= OCARINA_ACTION_CHECK_SARIA) { + osSyncPrintf("ocarina_set 000000000000000000 = %d\n", ocarinaActionId); + msgCtx->ocarinaAction = ocarinaActionId; + if (ocarinaActionId >= OCARINA_ACTION_CHECK_SARIA && ocarinaActionId <= OCARINA_ACTION_CHECK_STORMS) { + Audio_PlaySoundGeneral(NA_SE_SY_TRE_BOX_APPEAR, &D_801333D4, 4, &D_801333E0, &D_801333E0, &D_801333E8); + } + if (ocarinaActionId == OCARINA_ACTION_SCARECROW_PLAYBACK) { + Message_OpenText(globalCtx, 0x86F); // Ocarina + textId = ocarinaActionId + 0x86E; + } else { + Message_OpenText(globalCtx, 0x86E); // Play using [A] and [C]; [B] to Stop. + textId = ocarinaActionId + 0x86E; + } + } else { + msgCtx->ocarinaAction = ocarinaActionId; + noStop = true; + if (ocarinaActionId >= OCARINA_ACTION_PLAYBACK_MINUET) { + osSyncPrintf("222222222\n"); + Message_OpenText(globalCtx, 0x86D); // Play using [A] and [C]. + textId = ocarinaActionId + 0x86E; + } else { + osSyncPrintf("333333333\n"); + textId = ocarinaActionId + 0x86E; + Message_OpenText(globalCtx, textId); // Play using [A] and [C]; [B] to Stop. + } + } + msgCtx->talkActor = NULL; + // "Ocarina Mode" + osSyncPrintf("オカリナモード = %d (%x)\n", msgCtx->ocarinaAction, textId); + msgCtx->textDelayTimer = 0; + globalCtx->msgCtx.ocarinaMode = OCARINA_MODE_00; + R_TEXTBOX_X = 34; + R_TEXTBOX_Y = 142; + R_TEXTBOX_TEXWIDTH = 512; + R_TEXTBOX_TEXHEIGHT = 512; + R_TEXTBOX_WIDTH = 256; + R_TEXTBOX_HEIGHT = 64; + msgCtx->stateTimer = 0; + if (YREG(12) != 0) { + msgCtx->msgMode = MSGMODE_TEXT_NEXT_MSG; + } else { + msgCtx->stateTimer = 2; + msgCtx->msgMode = MSGMODE_TEXT_CONTINUING; + } + msgCtx->textboxColorAlphaCurrent = msgCtx->textboxColorAlphaTarget; + if (noStop == false) { + Interface_LoadActionLabelB(globalCtx, DO_ACTION_STOP); + noStop = gSaveContext.unk_13EA; + Interface_ChangeAlpha(0xA); + gSaveContext.unk_13EA = noStop; + } + // "Music Performance Start" + osSyncPrintf("演奏開始\n"); + if (ocarinaActionId == OCARINA_ACTION_FREE_PLAY || ocarinaActionId == OCARINA_ACTION_CHECK_NOWARP) { + msgCtx->msgMode = MSGMODE_OCARINA_STARTING; + msgCtx->textBoxType = 0x63; + } else if (ocarinaActionId == OCARINA_ACTION_FROGS) { + msgCtx->msgMode = MSGMODE_FROGS_START; + msgCtx->textBoxType = TEXTBOX_TYPE_BLUE; + } else if (ocarinaActionId == OCARINA_ACTION_MEMORY_GAME) { + Interface_ChangeAlpha(1); + Message_Decode(globalCtx); + msgCtx->msgMode = MSGMODE_MEMORY_GAME_START; + } else if (ocarinaActionId == OCARINA_ACTION_SCARECROW_LONG_PLAYBACK) { + // "?????Recording Playback / Recording Playback / Recording Playback / Recording Playback -> " + osSyncPrintf("?????録音再生 録音再生 録音再生 録音再生 -> "); + Audio_OcaSetInstrument(1); + Audio_OcaSetInstrument(1); + msgCtx->ocarinaStaff = Audio_OcaGetDisplayingStaff(); + sOcarinaNoteBufPos = sOcarinaNoteBufLen = 0; + msgCtx->ocarinaStaff->pos = sOcarinaNoteBufPos; + Message_ResetOcarinaNoteState(); + msgCtx->stateTimer = 3; + msgCtx->msgMode = MSGMODE_SCARECROW_LONG_PLAYBACK; + Audio_OcaSetSongPlayback(OCARINA_SONG_SCARECROW_LONG + 1, 1); + gSaveContext.unk_13EA = 0; + Interface_ChangeAlpha(1); + } + for (k = 0, j = 0; j < 48; j++, k += 0x80) { + func_8006EE50(&globalCtx->msgCtx.font, 0x8140, k); + } +} + +void func_8010BD58(GlobalContext* globalCtx, u16 ocarinaActionId) { + globalCtx->msgCtx.unk_E40E = 0; + Message_StartOcarina(globalCtx, ocarinaActionId); +} + +void func_8010BD88(GlobalContext* globalCtx, u16 ocarinaActionId) { + globalCtx->msgCtx.unk_E40E = 1; + Message_StartOcarina(globalCtx, ocarinaActionId); +} + +u8 Message_GetState(MessageContext* msgCtx) { + u8 state; + + if (msgCtx->msgLength == 0) { + state = TEXT_STATE_NONE; + } else if (msgCtx->msgMode == MSGMODE_TEXT_DONE) { + if (msgCtx->textboxEndType == TEXTBOX_ENDTYPE_HAS_NEXT) { + state = TEXT_STATE_DONE_HAS_NEXT; + } else if (msgCtx->textboxEndType == TEXTBOX_ENDTYPE_2_CHOICE || + msgCtx->textboxEndType == TEXTBOX_ENDTYPE_3_CHOICE) { + state = TEXT_STATE_CHOICE; + } else if (msgCtx->textboxEndType == TEXTBOX_ENDTYPE_EVENT || + msgCtx->textboxEndType == TEXTBOX_ENDTYPE_PERSISTENT) { + state = TEXT_STATE_EVENT; + } else if (msgCtx->textboxEndType == TEXTBOX_ENDTYPE_FADING) { + state = TEXT_STATE_DONE_FADING; + } else { + state = TEXT_STATE_DONE; + } + } else if (msgCtx->msgMode == MSGMODE_TEXT_AWAIT_NEXT) { + state = TEXT_STATE_AWAITING_NEXT; + } else if (msgCtx->msgMode == MSGMODE_SONG_DEMONSTRATION_DONE) { + state = TEXT_STATE_SONG_DEMO_DONE; + } else if (msgCtx->ocarinaMode == OCARINA_MODE_03) { + state = TEXT_STATE_8; + } else if (msgCtx->msgMode == MSGMODE_OCARINA_AWAIT_INPUT) { + state = TEXT_STATE_9; + } else if (msgCtx->msgMode == MSGMODE_TEXT_CLOSING && msgCtx->stateTimer == 1) { + state = TEXT_STATE_CLOSING; + } else { + state = TEXT_STATE_DONE_FADING; + } + return state; +} + +void Message_DrawTextBox(GlobalContext* globalCtx, Gfx** p) { + MessageContext* msgCtx = &globalCtx->msgCtx; + Gfx* gfx = *p; + + gDPPipeSync(gfx++); + gDPSetPrimColor(gfx++, 0, 0, msgCtx->textboxColorRed, msgCtx->textboxColorGreen, msgCtx->textboxColorBlue, + msgCtx->textboxColorAlphaCurrent); + + if (!(msgCtx->textBoxType) || msgCtx->textBoxType == TEXTBOX_TYPE_BLUE) { + gDPLoadTextureBlock_4b(gfx++, msgCtx->textboxSegment, G_IM_FMT_I, 128, 64, 0, G_TX_MIRROR, G_TX_NOMIRROR, 7, 0, + G_TX_NOLOD, G_TX_NOLOD); + } else { + if (msgCtx->textBoxType == TEXTBOX_TYPE_OCARINA) { + gDPSetEnvColor(gfx++, 0, 0, 0, 255); + } else { + gDPSetEnvColor(gfx++, 50, 20, 0, 255); + } + + gDPLoadTextureBlock_4b(gfx++, msgCtx->textboxSegment, G_IM_FMT_IA, 128, 64, 0, G_TX_MIRROR, G_TX_MIRROR, 7, 0, + G_TX_NOLOD, G_TX_NOLOD); + } + + gSPTextureRectangle(gfx++, R_TEXTBOX_X << 2, R_TEXTBOX_Y << 2, (R_TEXTBOX_X + R_TEXTBOX_WIDTH) << 2, + (R_TEXTBOX_Y + R_TEXTBOX_HEIGHT) << 2, G_TX_RENDERTILE, 0, 0, R_TEXTBOX_TEXWIDTH << 1, + R_TEXTBOX_TEXHEIGHT << 1); + + // Draw treble clef + if (msgCtx->textBoxType == TEXTBOX_TYPE_OCARINA) { + gDPPipeSync(gfx++); + gDPSetCombineLERP(gfx++, 1, 0, PRIMITIVE, 0, TEXEL0, 0, PRIMITIVE, 0, 1, 0, PRIMITIVE, 0, TEXEL0, 0, PRIMITIVE, + 0); + gDPSetPrimColor(gfx++, 0, 0, 255, 100, 0, 255); + gDPLoadTextureBlock_4b(gfx++, gOcarinaTrebleClefTex, G_IM_FMT_I, 16, 32, 0, G_TX_MIRROR, G_TX_MIRROR, + G_TX_NOMASK, G_TX_NOMASK, G_TX_NOLOD, G_TX_NOLOD); + gSPTextureRectangle(gfx++, R_TEXTBOX_CLEF_XPOS << 2, R_TEXTBOX_CLEF_YPOS << 2, (R_TEXTBOX_CLEF_XPOS + 16) << 2, + (R_TEXTBOX_CLEF_YPOS + 32) << 2, G_TX_RENDERTILE, 0, 0, 1 << 10, 1 << 10); + } + + *p = gfx; +} + +void Message_SetView(View* view) { + SET_FULLSCREEN_VIEWPORT(view); + func_800AB2C4(view); +} + +/** + * Draws the textbox in full and updates ocarina state + */ +void Message_DrawMain(GlobalContext* globalCtx, Gfx** p) { + static s16 sOcarinaEffectActorIds[] = { + ACTOR_OCEFF_WIPE3, ACTOR_OCEFF_WIPE2, ACTOR_OCEFF_WIPE, ACTOR_OCEFF_SPOT, + ACTOR_OCEFF_WIPE, ACTOR_OCEFF_STORM, ACTOR_OCEFF_WIPE4, + }; + static s16 sOcarinaEffectActorParams[] = { 0x0000, 0x0000, 0x0000, 0x0000, 0x0001, 0x0000, 0x0000 }; + static void* sOcarinaNoteTextures[] = { + gOcarinaATex, gOcarinaCDownTex, gOcarinaCRightTex, gOcarinaCLeftTex, gOcarinaCUpTex, + }; + static s16 sOcarinaNoteAPrimColors[][3] = { + { 80, 255, 150 }, + { 100, 255, 200 }, + }; + static s16 sOcarinaNoteAEnvColors[][3] = { + { 10, 10, 10 }, + { 50, 255, 50 }, + }; + static s16 sOcarinaNoteCPrimColors[][3] = { + { 255, 255, 50 }, + { 255, 255, 180 }, + }; + static s16 sOcarinaNoteCEnvColors[][3] = { + { 10, 10, 10 }, + { 110, 110, 50 }, + }; + static s16 sOcarinaNoteFlashTimer = 12; + static s16 sOcarinaNoteFlashColorIdx = 1; + static s16 sOcarinaSongFanfares[] = { + NA_BGM_OCA_MINUET, NA_BGM_OCA_BOLERO, NA_BGM_OCA_SERENADE, NA_BGM_OCA_REQUIEM, + NA_BGM_OCA_NOCTURNE, NA_BGM_OCA_LIGHT, NA_BGM_OCA_SARIA, NA_BGM_OCA_EPONA, + NA_BGM_OCA_ZELDA, NA_BGM_OCA_SUNS, NA_BGM_OCA_TIME, NA_BGM_OCA_STORM, + }; + InterfaceContext* interfaceCtx = &globalCtx->interfaceCtx; + MessageContext* msgCtx = &globalCtx->msgCtx; + u16 noteBufPos; + Player* player = GET_PLAYER(globalCtx); + s32 pad; + Gfx* gfx = *p; + s16 r; + s16 g; + s16 b; + u16 i; + u16 notePosX; + u16 pad1; + u16 j; + + gSPSegment(gfx++, 0x02, globalCtx->interfaceCtx.parameterSegment); + gSPSegment(gfx++, 0x07, msgCtx->textboxSegment); + + if (msgCtx->msgLength != 0) { + if (msgCtx->ocarinaAction != OCARINA_ACTION_FROGS && msgCtx->msgMode != MSGMODE_SONG_PLAYED_ACT && + msgCtx->msgMode >= MSGMODE_TEXT_BOX_GROWING && msgCtx->msgMode < MSGMODE_TEXT_CLOSING && + msgCtx->textBoxType < TEXTBOX_TYPE_NONE_BOTTOM) { + Message_SetView(&msgCtx->view); + func_8009457C(&gfx); + Message_DrawTextBox(globalCtx, &gfx); + } + + func_8009457C(&gfx); + + gDPSetAlphaCompare(gfx++, G_AC_NONE); + gDPSetCombineLERP(gfx++, 0, 0, 0, PRIMITIVE, TEXEL0, 0, PRIMITIVE, 0, 0, 0, 0, PRIMITIVE, TEXEL0, 0, PRIMITIVE, + 0); + + switch (msgCtx->msgMode) { + case MSGMODE_TEXT_START: + case MSGMODE_TEXT_BOX_GROWING: + case MSGMODE_TEXT_STARTING: + case MSGMODE_TEXT_NEXT_MSG: + break; + case MSGMODE_TEXT_CONTINUING: + if (msgCtx->stateTimer == 1) { + for (j = 0, i = 0; i < 48; i++, j += 0x80) { + func_8006EE50(&globalCtx->msgCtx.font, 0x8140, j); + } + Message_DrawText(globalCtx, &gfx); + } + break; + case MSGMODE_TEXT_DISPLAYING: + case MSGMODE_TEXT_DELAYED_BREAK: + Message_DrawText(globalCtx, &gfx); + break; + case MSGMODE_TEXT_AWAIT_INPUT: + case MSGMODE_TEXT_AWAIT_NEXT: + Message_DrawText(globalCtx, &gfx); + Message_DrawTextboxIcon(globalCtx, &gfx, R_TEXTBOX_END_XPOS, R_TEXTBOX_END_YPOS); + break; + case MSGMODE_OCARINA_STARTING: + case MSGMODE_SONG_DEMONSTRATION_STARTING: + case MSGMODE_SONG_PLAYBACK_STARTING: + Audio_OcaSetInstrument(1); + msgCtx->ocarinaStaff = Audio_OcaGetPlayingStaff(); + msgCtx->ocarinaStaff->pos = sOcarinaNoteBufPos = 0; + globalCtx->msgCtx.ocarinaMode = OCARINA_MODE_01; + Message_ResetOcarinaNoteState(); + sOcarinaNoteFlashTimer = 3; + sOcarinaNoteFlashColorIdx = 1; + if (msgCtx->msgMode == MSGMODE_OCARINA_STARTING) { + if (msgCtx->ocarinaAction == OCARINA_ACTION_UNK_0 || + msgCtx->ocarinaAction == OCARINA_ACTION_FREE_PLAY || + msgCtx->ocarinaAction == OCARINA_ACTION_SCARECROW_RECORDING || + msgCtx->ocarinaAction == OCARINA_ACTION_CHECK_NOWARP || + msgCtx->ocarinaAction >= OCARINA_ACTION_CHECK_SARIA) { + if (msgCtx->ocarinaAction == OCARINA_ACTION_FREE_PLAY || + msgCtx->ocarinaAction == OCARINA_ACTION_CHECK_NOWARP) { + func_800ECC04(sOcarinaSongBitFlags + 0xC000); + } else { + // "On Stage Performance" + osSyncPrintf("台上演奏\n"); + func_800ECC04(sOcarinaSongBitFlags); + } + } else { + osSyncPrintf("Na_StartOcarinaSinglePlayCheck2( message->ocarina_no );\n"); + func_800ECC04((1 << msgCtx->ocarinaAction) + 0x8000); + } + msgCtx->msgMode = MSGMODE_OCARINA_PLAYING; + } else if (msgCtx->msgMode == MSGMODE_SONG_DEMONSTRATION_STARTING) { + msgCtx->stateTimer = 20; + msgCtx->msgMode = MSGMODE_SONG_DEMONSTRATION_SELECT_INSTRUMENT; + } else { + func_800ECC04((1 << (msgCtx->ocarinaAction + 0x11)) + 0x8000); + // "Performance Check" + osSyncPrintf("演奏チェック=%d\n", msgCtx->ocarinaAction - OCARINA_ACTION_PLAYBACK_MINUET); + msgCtx->msgMode = MSGMODE_SONG_PLAYBACK; + } + if (msgCtx->ocarinaAction != OCARINA_ACTION_FREE_PLAY && + msgCtx->ocarinaAction != OCARINA_ACTION_CHECK_NOWARP) { + Message_DrawText(globalCtx, &gfx); + } + break; + case MSGMODE_OCARINA_PLAYING: + msgCtx->ocarinaStaff = Audio_OcaGetPlayingStaff(); + if (msgCtx->ocarinaStaff->pos) { + osSyncPrintf("locate=%d onpu_pt=%d\n", msgCtx->ocarinaStaff->pos, sOcarinaNoteBufPos); + if (msgCtx->ocarinaStaff->pos == 1 && sOcarinaNoteBufPos == 8) { + sOcarinaNoteBufPos = 0; + } + if (sOcarinaNoteBufPos == msgCtx->ocarinaStaff->pos - 1) { + msgCtx->lastOcaNoteIdx = sOcarinaNoteBuf[msgCtx->ocarinaStaff->pos - 1] = + msgCtx->ocarinaStaff->noteIdx; + sOcarinaNoteBuf[msgCtx->ocarinaStaff->pos] = OCARINA_NOTE_INVALID; + sOcarinaNoteBufPos++; + } + } + msgCtx->lastPlayedSong = msgCtx->ocarinaStaff->state; + if (msgCtx->ocarinaStaff->state < OCARINA_SONG_MEMORY_GAME) { + if (msgCtx->ocarinaStaff->state == OCARINA_SONG_SCARECROW || + CHECK_QUEST_ITEM(QUEST_SONG_MINUET + gOcarinaSongItemMap[msgCtx->ocarinaStaff->state])) { + sLastPlayedSong = msgCtx->unk_E3F2 = msgCtx->lastPlayedSong = msgCtx->ocarinaStaff->state; + msgCtx->msgMode = MSGMODE_OCARINA_CORRECT_PLAYBACK; + msgCtx->stateTimer = 20; + if (msgCtx->ocarinaAction == OCARINA_ACTION_CHECK_NOWARP) { + if (msgCtx->ocarinaStaff->state < OCARINA_SONG_SARIAS || + msgCtx->ocarinaStaff->state == OCARINA_SONG_SCARECROW) { + Audio_OcaSetInstrument(0); + Audio_PlaySoundGeneral(NA_SE_SY_OCARINA_ERROR, &D_801333D4, 4, &D_801333E0, &D_801333E0, + &D_801333E8); + msgCtx->msgMode = MSGMODE_OCARINA_STARTING; + } else { + // "Ocarina_Flog Correct Example Performance" + osSyncPrintf("Ocarina_Flog 正解模範演奏=%x\n", msgCtx->lastPlayedSong); + Message_ContinueTextbox(globalCtx, 0x86F); // Ocarina + msgCtx->msgMode = MSGMODE_SONG_PLAYED; + msgCtx->textBoxType = TEXTBOX_TYPE_OCARINA; + msgCtx->stateTimer = 10; + Audio_PlaySoundGeneral(NA_SE_SY_TRE_BOX_APPEAR, &D_801333D4, 4, &D_801333E0, + &D_801333E0, &D_801333E8); + Interface_ChangeAlpha(1); + } + } else if (msgCtx->ocarinaAction == OCARINA_ACTION_CHECK_SCARECROW) { + if (msgCtx->ocarinaStaff->state < OCARINA_SONG_SCARECROW) { + Audio_OcaSetInstrument(0); + Audio_PlaySoundGeneral(NA_SE_SY_OCARINA_ERROR, &D_801333D4, 4, &D_801333E0, &D_801333E0, + &D_801333E8); + msgCtx->stateTimer = 10; + msgCtx->msgMode = MSGMODE_OCARINA_FAIL; + } else { + // "Ocarina_Flog Correct Example Performance" + osSyncPrintf("Ocarina_Flog 正解模範演奏=%x\n", msgCtx->lastPlayedSong); + Message_ContinueTextbox(globalCtx, 0x86F); // Ocarina + msgCtx->msgMode = MSGMODE_SONG_PLAYED; + msgCtx->textBoxType = TEXTBOX_TYPE_OCARINA; + msgCtx->stateTimer = 10; + Audio_PlaySoundGeneral(NA_SE_SY_TRE_BOX_APPEAR, &D_801333D4, 4, &D_801333E0, + &D_801333E0, &D_801333E8); + Interface_ChangeAlpha(1); + } + } else if (msgCtx->ocarinaAction == OCARINA_ACTION_FREE_PLAY) { + // "Ocarina_Free Correct Example Performance" + osSyncPrintf("Ocarina_Free 正解模範演奏=%x\n", msgCtx->lastPlayedSong); + Message_ContinueTextbox(globalCtx, 0x86F); // Ocarina + msgCtx->msgMode = MSGMODE_SONG_PLAYED; + msgCtx->textBoxType = TEXTBOX_TYPE_OCARINA; + msgCtx->stateTimer = 10; + Audio_PlaySoundGeneral(NA_SE_SY_TRE_BOX_APPEAR, &D_801333D4, 4, &D_801333E0, &D_801333E0, + &D_801333E8); + } else { + Audio_PlaySoundGeneral(NA_SE_SY_TRE_BOX_APPEAR, &D_801333D4, 4, &D_801333E0, &D_801333E0, + &D_801333E8); + } + Interface_ChangeAlpha(1); + } else { + Audio_OcaSetInstrument(0); + Audio_PlaySoundGeneral(NA_SE_SY_OCARINA_ERROR, &D_801333D4, 4, &D_801333E0, &D_801333E0, + &D_801333E8); + msgCtx->msgMode = MSGMODE_OCARINA_STARTING; + } + } else if (msgCtx->ocarinaStaff->state == 0xFF) { + Audio_OcaSetInstrument(0); + Audio_PlaySoundGeneral(NA_SE_SY_OCARINA_ERROR, &D_801333D4, 4, &D_801333E0, &D_801333E0, + &D_801333E8); + msgCtx->stateTimer = 10; + msgCtx->msgMode = MSGMODE_OCARINA_FAIL; + } else if (CHECK_BTN_ALL(globalCtx->state.input[0].press.button, BTN_B)) { + Audio_OcaSetInstrument(0); + globalCtx->msgCtx.ocarinaMode = OCARINA_MODE_04; + Message_CloseTextbox(globalCtx); + } + if (msgCtx->ocarinaAction != OCARINA_ACTION_FREE_PLAY && + msgCtx->ocarinaAction != OCARINA_ACTION_CHECK_NOWARP) { + Message_DrawText(globalCtx, &gfx); + } + break; + case MSGMODE_OCARINA_CORRECT_PLAYBACK: + case MSGMODE_SONG_PLAYBACK_SUCCESS: + case MSGMODE_SCARECROW_RECORDING_DONE: + r = ABS(sOcarinaNoteAPrimR - sOcarinaNoteAPrimColors[sOcarinaNoteFlashColorIdx][0]) / + sOcarinaNoteFlashTimer; + g = ABS(sOcarinaNoteAPrimG - sOcarinaNoteAPrimColors[sOcarinaNoteFlashColorIdx][1]) / + sOcarinaNoteFlashTimer; + b = ABS(sOcarinaNoteAPrimB - sOcarinaNoteAPrimColors[sOcarinaNoteFlashColorIdx][2]) / + sOcarinaNoteFlashTimer; + + if (sOcarinaNoteAPrimR >= sOcarinaNoteAPrimColors[sOcarinaNoteFlashColorIdx][0]) { + sOcarinaNoteAPrimR -= r; + } else { + sOcarinaNoteAPrimR += r; + } + if (sOcarinaNoteAPrimG >= sOcarinaNoteAPrimColors[sOcarinaNoteFlashColorIdx][1]) { + sOcarinaNoteAPrimG -= g; + } else { + sOcarinaNoteAPrimG += g; + } + if (sOcarinaNoteAPrimB >= sOcarinaNoteAPrimColors[sOcarinaNoteFlashColorIdx][2]) { + sOcarinaNoteAPrimB -= b; + } else { + sOcarinaNoteAPrimB += b; + } + + r = ABS(sOcarinaNoteAEnvR - sOcarinaNoteAEnvColors[sOcarinaNoteFlashColorIdx][0]) / + sOcarinaNoteFlashTimer; + g = ABS(sOcarinaNoteAEnvG - sOcarinaNoteAEnvColors[sOcarinaNoteFlashColorIdx][1]) / + sOcarinaNoteFlashTimer; + b = ABS(sOcarinaNoteAEnvB - sOcarinaNoteAEnvColors[sOcarinaNoteFlashColorIdx][2]) / + sOcarinaNoteFlashTimer; + + if (sOcarinaNoteCEnvR >= sOcarinaNoteAEnvColors[sOcarinaNoteFlashColorIdx][0]) { + sOcarinaNoteAEnvR -= r; + } else { + sOcarinaNoteAEnvR += r; + } + if (sOcarinaNoteCEnvG >= sOcarinaNoteAEnvColors[sOcarinaNoteFlashColorIdx][1]) { + sOcarinaNoteAEnvG -= g; + } else { + sOcarinaNoteAEnvG += g; + } + if (sOcarinaNoteCEnvB >= sOcarinaNoteAEnvColors[sOcarinaNoteFlashColorIdx][2]) { + sOcarinaNoteAEnvB -= b; + } else { + sOcarinaNoteAEnvB += b; + } + + r = ABS(sOcarinaNoteCPrimR - sOcarinaNoteCPrimColors[sOcarinaNoteFlashColorIdx][0]) / + sOcarinaNoteFlashTimer; + g = ABS(sOcarinaNoteCPrimG - sOcarinaNoteCPrimColors[sOcarinaNoteFlashColorIdx][1]) / + sOcarinaNoteFlashTimer; + b = ABS(sOcarinaNoteCPrimB - sOcarinaNoteCPrimColors[sOcarinaNoteFlashColorIdx][2]) / + sOcarinaNoteFlashTimer; + + if (sOcarinaNoteCPrimR >= sOcarinaNoteCPrimColors[sOcarinaNoteFlashColorIdx][0]) { + sOcarinaNoteCPrimR -= r; + } else { + sOcarinaNoteCPrimR += r; + } + if (sOcarinaNoteCPrimG >= sOcarinaNoteCPrimColors[sOcarinaNoteFlashColorIdx][1]) { + sOcarinaNoteCPrimG -= g; + } else { + sOcarinaNoteCPrimG += g; + } + if (sOcarinaNoteCPrimB >= sOcarinaNoteCPrimColors[sOcarinaNoteFlashColorIdx][2]) { + sOcarinaNoteCPrimB -= b; + } else { + sOcarinaNoteCPrimB += b; + } + + r = ABS(sOcarinaNoteCEnvR - sOcarinaNoteCEnvColors[sOcarinaNoteFlashColorIdx][0]) / + sOcarinaNoteFlashTimer; + g = ABS(sOcarinaNoteCEnvG - sOcarinaNoteCEnvColors[sOcarinaNoteFlashColorIdx][1]) / + sOcarinaNoteFlashTimer; + b = ABS(sOcarinaNoteCEnvB - sOcarinaNoteCEnvColors[sOcarinaNoteFlashColorIdx][2]) / + sOcarinaNoteFlashTimer; + + if (sOcarinaNoteCEnvR >= sOcarinaNoteCEnvColors[sOcarinaNoteFlashColorIdx][0]) { + sOcarinaNoteCEnvR -= r; + } else { + sOcarinaNoteCEnvR += r; + } + if (sOcarinaNoteCEnvG >= sOcarinaNoteCEnvColors[sOcarinaNoteFlashColorIdx][1]) { + sOcarinaNoteCEnvG -= g; + } else { + sOcarinaNoteCEnvG += g; + } + if (sOcarinaNoteCEnvB >= sOcarinaNoteCEnvColors[sOcarinaNoteFlashColorIdx][2]) { + sOcarinaNoteCEnvB -= b; + } else { + sOcarinaNoteCEnvB += b; + } + + sOcarinaNoteFlashTimer--; + if (sOcarinaNoteFlashTimer == 0) { + sOcarinaNoteAPrimR = sOcarinaNoteAPrimColors[sOcarinaNoteFlashColorIdx][0]; + sOcarinaNoteAPrimG = sOcarinaNoteAPrimColors[sOcarinaNoteFlashColorIdx][1]; + sOcarinaNoteAPrimB = sOcarinaNoteAPrimColors[sOcarinaNoteFlashColorIdx][2]; + sOcarinaNoteAEnvR = sOcarinaNoteAEnvColors[sOcarinaNoteFlashColorIdx][0]; + sOcarinaNoteAEnvG = sOcarinaNoteAEnvColors[sOcarinaNoteFlashColorIdx][1]; + sOcarinaNoteAEnvB = sOcarinaNoteAEnvColors[sOcarinaNoteFlashColorIdx][2]; + sOcarinaNoteCPrimR = sOcarinaNoteCPrimColors[sOcarinaNoteFlashColorIdx][0]; + sOcarinaNoteCPrimG = sOcarinaNoteCPrimColors[sOcarinaNoteFlashColorIdx][1]; + sOcarinaNoteCPrimB = sOcarinaNoteCPrimColors[sOcarinaNoteFlashColorIdx][2]; + sOcarinaNoteCEnvR = sOcarinaNoteCEnvColors[sOcarinaNoteFlashColorIdx][0]; + sOcarinaNoteCEnvG = sOcarinaNoteCEnvColors[sOcarinaNoteFlashColorIdx][1]; + sOcarinaNoteCEnvB = sOcarinaNoteCEnvColors[sOcarinaNoteFlashColorIdx][2]; + sOcarinaNoteFlashTimer = 3; + sOcarinaNoteFlashColorIdx ^= 1; + } + + msgCtx->stateTimer--; + if (msgCtx->stateTimer == 0) { + Audio_OcaSetInstrument(0); + if (msgCtx->msgMode == MSGMODE_OCARINA_CORRECT_PLAYBACK) { + // "Correct Example Performance" + osSyncPrintf("正解模範演奏=%x\n", msgCtx->lastPlayedSong); + Message_ContinueTextbox(globalCtx, 0x86F); // Ocarina + msgCtx->msgMode = MSGMODE_SONG_PLAYED; + msgCtx->textBoxType = TEXTBOX_TYPE_OCARINA; + msgCtx->stateTimer = 1; + } else if (msgCtx->msgMode == MSGMODE_SONG_PLAYBACK_SUCCESS) { + if (msgCtx->lastPlayedSong >= OCARINA_SONG_SARIAS) { + Message_ContinueTextbox(globalCtx, 0x86F); // Ocarina + msgCtx->msgMode = MSGMODE_SONG_PLAYED; + msgCtx->textBoxType = TEXTBOX_TYPE_OCARINA; + msgCtx->stateTimer = 1; + } else { + Message_CloseTextbox(globalCtx); + globalCtx->msgCtx.ocarinaMode = OCARINA_MODE_04; + } + } else { + Message_CloseTextbox(globalCtx); + globalCtx->msgCtx.ocarinaMode = OCARINA_MODE_03; + } + } + Message_DrawText(globalCtx, &gfx); + break; + case MSGMODE_OCARINA_FAIL: + case MSGMODE_SONG_PLAYBACK_FAIL: + Message_DrawText(globalCtx, &gfx); + case MSGMODE_OCARINA_FAIL_NO_TEXT: + msgCtx->stateTimer--; + if (msgCtx->stateTimer == 0) { + R_OCARINA_NOTES_YPOS_OFFSET = 1; + if (msgCtx->msgMode == MSGMODE_SONG_PLAYBACK_FAIL) { + // "kokokokokoko" + osSyncPrintf("ここここここ\n"); + Message_ContinueTextbox(globalCtx, 0x88B); // red X background + Message_Decode(globalCtx); + msgCtx->msgMode = MSGMODE_SONG_PLAYBACK_NOTES_DROP; + } else { + msgCtx->msgMode = MSGMODE_OCARINA_NOTES_DROP; + } + // "Cancel" + osSyncPrintf("キャンセル\n"); + } + break; + case MSGMODE_OCARINA_NOTES_DROP: + case MSGMODE_SONG_PLAYBACK_NOTES_DROP: + for (i = 0; i < 5; i++) { + R_OCARINA_NOTES_YPOS(i) += R_OCARINA_NOTES_YPOS_OFFSET; + } + R_OCARINA_NOTES_YPOS_OFFSET += R_OCARINA_NOTES_YPOS_OFFSET; + if (R_OCARINA_NOTES_YPOS_OFFSET >= 550) { + sOcarinaNoteBuf[0] = OCARINA_NOTE_INVALID; + sOcarinaNotesAlphaValues[0] = sOcarinaNotesAlphaValues[1] = sOcarinaNotesAlphaValues[2] = + sOcarinaNotesAlphaValues[3] = sOcarinaNotesAlphaValues[4] = sOcarinaNotesAlphaValues[5] = + sOcarinaNotesAlphaValues[6] = sOcarinaNotesAlphaValues[7] = sOcarinaNotesAlphaValues[8] = 0; + if (msgCtx->msgMode == MSGMODE_SONG_PLAYBACK_NOTES_DROP) { + msgCtx->msgMode = MSGMODE_OCARINA_AWAIT_INPUT; + } else { + msgCtx->msgMode = MSGMODE_OCARINA_STARTING; + } + } + break; + case MSGMODE_SONG_PLAYED: + msgCtx->stateTimer--; + if (msgCtx->stateTimer == 0) { + Audio_OcaSetInstrument(0); + osSyncPrintf(VT_FGCOL(GREEN)); + osSyncPrintf("Na_StopOcarinaMode();\n"); + osSyncPrintf("Na_StopOcarinaMode();\n"); + osSyncPrintf("Na_StopOcarinaMode();\n"); + osSyncPrintf(VT_RST); + Message_Decode(globalCtx); + msgCtx->msgMode = MSGMODE_SETUP_DISPLAY_SONG_PLAYED; + msgCtx->ocarinaStaff = Audio_OcaGetPlayingStaff(); + msgCtx->ocarinaStaff->pos = sOcarinaNoteBufPos = 0; + Message_ResetOcarinaNoteState(); + if (msgCtx->lastPlayedSong >= OCARINA_SONG_SARIAS && + msgCtx->lastPlayedSong < OCARINA_SONG_MEMORY_GAME) { + Actor_Spawn(&globalCtx->actorCtx, globalCtx, + sOcarinaEffectActorIds[msgCtx->lastPlayedSong - OCARINA_SONG_SARIAS], + player->actor.world.pos.x, player->actor.world.pos.y, player->actor.world.pos.z, 0, + 0, 0, sOcarinaEffectActorParams[msgCtx->lastPlayedSong - OCARINA_SONG_SARIAS]); + } + } + break; + case MSGMODE_SETUP_DISPLAY_SONG_PLAYED: + Message_DrawText(globalCtx, &gfx); + Audio_OcaSetInstrument(1); + Audio_OcaSetInstrument(1); + Audio_OcaSetSongPlayback(msgCtx->lastPlayedSong + 1, 1); + if (msgCtx->lastPlayedSong != OCARINA_SONG_SCARECROW) { + Audio_PlayFanfare(sOcarinaSongFanfares[msgCtx->lastPlayedSong]); + Audio_SetSoundBanksMute(0x20); + } + globalCtx->msgCtx.ocarinaMode = OCARINA_MODE_01; + if (msgCtx->ocarinaAction == OCARINA_ACTION_FREE_PLAY) { + msgCtx->ocarinaAction = OCARINA_ACTION_FREE_PLAY_DONE; + } + if (msgCtx->ocarinaAction == OCARINA_ACTION_CHECK_NOWARP) { + msgCtx->ocarinaAction = OCARINA_ACTION_CHECK_NOWARP_DONE; + } + sOcarinaNoteBufPos = 0; + msgCtx->msgMode = MSGMODE_DISPLAY_SONG_PLAYED; + break; + case MSGMODE_SONG_DEMONSTRATION_SELECT_INSTRUMENT: + msgCtx->stateTimer--; + if (msgCtx->stateTimer == 0) { + // "ocarina_no=%d Song Chosen=%d" + osSyncPrintf("ocarina_no=%d 選曲=%d\n", msgCtx->ocarinaAction, 0x16); + if (msgCtx->ocarinaAction < OCARINA_ACTION_TEACH_SARIA) { + Audio_OcaSetInstrument(4); + } else if (msgCtx->ocarinaAction == OCARINA_ACTION_TEACH_EPONA) { + Audio_OcaSetInstrument(2); + } else if (msgCtx->ocarinaAction == OCARINA_ACTION_TEACH_LULLABY) { + Audio_OcaSetInstrument(3); + } else if (msgCtx->ocarinaAction == OCARINA_ACTION_TEACH_STORMS) { + Audio_OcaSetInstrument(5); + } else { + Audio_OcaSetInstrument(1); + } + // "Example Performance" + osSyncPrintf("模範演奏=%x\n", msgCtx->ocarinaAction - OCARINA_ACTION_TEACH_MINUET); + Audio_OcaSetSongPlayback(msgCtx->ocarinaAction - OCARINA_ACTION_TEACH_MINUET + 1, 2); + sOcarinaNoteBufPos = 0; + msgCtx->msgMode = MSGMODE_SONG_DEMONSTRATION; + } + Message_DrawText(globalCtx, &gfx); + break; + case MSGMODE_DISPLAY_SONG_PLAYED_TEXT_BEGIN: + Message_ContinueTextbox(globalCtx, msgCtx->lastPlayedSong + 0x893); // You played [song name] + Message_Decode(globalCtx); + msgCtx->msgMode = MSGMODE_DISPLAY_SONG_PLAYED_TEXT; + msgCtx->stateTimer = 20; + Message_DrawText(globalCtx, &gfx); + break; + case MSGMODE_DISPLAY_SONG_PLAYED_TEXT: + msgCtx->stateTimer--; + if (msgCtx->stateTimer == 0) { + msgCtx->msgMode = MSGMODE_SONG_PLAYED_ACT_BEGIN; + } + Message_DrawText(globalCtx, &gfx); + break; + case MSGMODE_SONG_PLAYED_ACT_BEGIN: + Audio_OcaSetInstrument(0); + Message_ResetOcarinaNoteState(); + msgCtx->msgMode = MSGMODE_SONG_PLAYED_ACT; + msgCtx->stateTimer = 2; + Message_DrawText(globalCtx, &gfx); + break; + case MSGMODE_SONG_PLAYED_ACT: + msgCtx->stateTimer--; + if (msgCtx->stateTimer == 0) { + if (msgCtx->lastPlayedSong < OCARINA_SONG_SARIAS && + (msgCtx->ocarinaAction < OCARINA_ACTION_PLAYBACK_MINUET || + msgCtx->ocarinaAction >= OCARINA_ACTION_PLAYBACK_SARIA)) { + if (msgCtx->disableWarpSongs || interfaceCtx->restrictions.warpSongs == 3) { + Message_StartTextbox(globalCtx, 0x88C, NULL); // "You can't warp here!" + globalCtx->msgCtx.ocarinaMode = OCARINA_MODE_04; + } else if ((gSaveContext.eventInf[0] & 0xF) != 1) { + Message_StartTextbox(globalCtx, msgCtx->lastPlayedSong + 0x88D, + NULL); // "Warp to [place name]?" + globalCtx->msgCtx.ocarinaMode = OCARINA_MODE_01; + } else { + Message_CloseTextbox(globalCtx); + } + } else { + Message_CloseTextbox(globalCtx); + if (msgCtx->lastPlayedSong == OCARINA_SONG_EPONAS) { + DREG(53) = 1; + } + osSyncPrintf(VT_FGCOL(YELLOW)); + osSyncPrintf("☆☆☆ocarina=%d message->ocarina_no=%d ", msgCtx->lastPlayedSong, + msgCtx->ocarinaAction); + if (msgCtx->ocarinaAction == OCARINA_ACTION_FREE_PLAY_DONE) { + globalCtx->msgCtx.ocarinaMode = OCARINA_MODE_01; + if (msgCtx->lastPlayedSong == OCARINA_SONG_SCARECROW) { + globalCtx->msgCtx.ocarinaMode = OCARINA_MODE_0B; + } + } else if (msgCtx->ocarinaAction >= OCARINA_ACTION_CHECK_MINUET) { + osSyncPrintf(VT_FGCOL(YELLOW)); + osSyncPrintf("Ocarina_PC_Wind=%d(%d) ☆☆☆ ", OCARINA_ACTION_CHECK_MINUET, + msgCtx->ocarinaAction - OCARINA_ACTION_CHECK_MINUET); + if (msgCtx->lastPlayedSong + OCARINA_ACTION_CHECK_MINUET == msgCtx->ocarinaAction) { + globalCtx->msgCtx.ocarinaMode = OCARINA_MODE_03; + } else { + globalCtx->msgCtx.ocarinaMode = msgCtx->lastPlayedSong - 1; + } + } else { + osSyncPrintf(VT_FGCOL(GREEN)); + osSyncPrintf("Ocarina_C_Wind=%d(%d) ☆☆☆ ", OCARINA_ACTION_PLAYBACK_MINUET, + msgCtx->ocarinaAction - OCARINA_ACTION_PLAYBACK_MINUET); + if (msgCtx->lastPlayedSong + OCARINA_ACTION_PLAYBACK_MINUET == msgCtx->ocarinaAction) { + globalCtx->msgCtx.ocarinaMode = OCARINA_MODE_03; + } else { + globalCtx->msgCtx.ocarinaMode = OCARINA_MODE_04; + } + } + osSyncPrintf(VT_RST); + osSyncPrintf("→ OCARINA_MODE=%d\n", globalCtx->msgCtx.ocarinaMode); + } + } + break; + case MSGMODE_DISPLAY_SONG_PLAYED: + case MSGMODE_SONG_DEMONSTRATION: + msgCtx->ocarinaStaff = Audio_OcaGetDisplayingStaff(); + if (msgCtx->ocarinaStaff->state == 0) { + if (msgCtx->msgMode == MSGMODE_DISPLAY_SONG_PLAYED) { + msgCtx->msgMode = MSGMODE_DISPLAY_SONG_PLAYED_TEXT_BEGIN; + } else { + msgCtx->msgMode = MSGMODE_SONG_DEMONSTRATION_DONE; + } + osSyncPrintf("onpu_buff[%d]=%x\n", msgCtx->ocarinaStaff->pos, + sOcarinaNoteBuf[msgCtx->ocarinaStaff->pos]); + } else { + if (sOcarinaNoteBufPos != 0 && msgCtx->ocarinaStaff->pos == 1) { + sOcarinaNoteBufPos = 0; + } + if (msgCtx->ocarinaStaff->pos && sOcarinaNoteBufPos == msgCtx->ocarinaStaff->pos - 1) { + msgCtx->lastOcaNoteIdx = sOcarinaNoteBuf[msgCtx->ocarinaStaff->pos - 1] = + msgCtx->ocarinaStaff->noteIdx; + sOcarinaNoteBuf[msgCtx->ocarinaStaff->pos] = OCARINA_NOTE_INVALID; + sOcarinaNoteBufPos++; + } + } + case MSGMODE_SONG_DEMONSTRATION_DONE: + Message_DrawText(globalCtx, &gfx); + break; + case MSGMODE_SONG_PLAYBACK: + msgCtx->ocarinaStaff = Audio_OcaGetPlayingStaff(); + if (msgCtx->ocarinaStaff->pos && sOcarinaNoteBufPos == msgCtx->ocarinaStaff->pos - 1) { + sOcarinaNoteBuf[msgCtx->ocarinaStaff->pos - 1] = msgCtx->ocarinaStaff->noteIdx; + sOcarinaNoteBuf[msgCtx->ocarinaStaff->pos] = OCARINA_NOTE_INVALID; + sOcarinaNoteBufPos++; + } + if (msgCtx->ocarinaStaff->state < OCARINA_SONG_MEMORY_GAME) { + osSyncPrintf("M_OCARINA20 : ocarina_no=%x status=%x\n", msgCtx->ocarinaAction, + msgCtx->ocarinaStaff->state); + msgCtx->lastPlayedSong = msgCtx->ocarinaStaff->state; + msgCtx->msgMode = MSGMODE_SONG_PLAYBACK_SUCCESS; + Item_Give(globalCtx, ITEM_SONG_MINUET + gOcarinaSongItemMap[msgCtx->ocarinaStaff->state]); + osSyncPrintf(VT_FGCOL(YELLOW)); + // "z_message.c Song Acquired" + osSyncPrintf("z_message.c 取得メロディ=%d\n", ITEM_SONG_MINUET + msgCtx->ocarinaStaff->state); + osSyncPrintf(VT_RST); + msgCtx->stateTimer = 20; + Audio_PlaySoundGeneral(NA_SE_SY_TRE_BOX_APPEAR, &D_801333D4, 4, &D_801333E0, &D_801333E0, + &D_801333E8); + } else if (msgCtx->ocarinaStaff->state == 0xFF) { + Audio_PlaySoundGeneral(NA_SE_SY_OCARINA_ERROR, &D_801333D4, 4, &D_801333E0, &D_801333E0, + &D_801333E8); + msgCtx->stateTimer = 10; + msgCtx->msgMode = MSGMODE_SONG_PLAYBACK_FAIL; + } + Message_DrawText(globalCtx, &gfx); + break; + case MSGMODE_OCARINA_AWAIT_INPUT: + Message_DrawText(globalCtx, &gfx); + if (Message_ShouldAdvance(globalCtx)) { + func_8010BD58(globalCtx, msgCtx->ocarinaAction); + } + break; + case MSGMODE_SCARECROW_LONG_RECORDING_START: + // "Scarecrow Recording Initialization" + osSyncPrintf("案山子録音 初期化\n"); + Audio_OcaSetRecordingState(1); + Audio_OcaSetInstrument(1); + msgCtx->ocarinaStaff = Audio_OcaGetRecordingStaff(); + msgCtx->ocarinaStaff->pos = sOcarinaNoteBufPos = 0; + sOcarinaNoteBufLen = 0; + Message_ResetOcarinaNoteState(); + msgCtx->msgMode = MSGMODE_SCARECROW_LONG_RECORDING_ONGOING; + Message_DrawText(globalCtx, &gfx); + break; + case MSGMODE_SCARECROW_LONG_RECORDING_ONGOING: + msgCtx->ocarinaStaff = Audio_OcaGetRecordingStaff(); + osSyncPrintf("\nonpu_pt=%d, locate=%d", sOcarinaNoteBufPos, msgCtx->ocarinaStaff->pos); + if (msgCtx->ocarinaStaff->pos && sOcarinaNoteBufPos == msgCtx->ocarinaStaff->pos - 1) { + if (sOcarinaNoteBufLen >= 8) { + for (noteBufPos = sOcarinaNoteBufLen - 8, i = 0; i < 8; i++, noteBufPos++) { + sOcarinaNoteBuf[noteBufPos] = sOcarinaNoteBuf[noteBufPos + 1]; + } + sOcarinaNoteBufLen--; + } + // "Button Entered" + osSyncPrintf(" 入力ボタン【%d】=%d", sOcarinaNoteBufLen, msgCtx->ocarinaStaff->noteIdx); + msgCtx->lastOcaNoteIdx = sOcarinaNoteBuf[sOcarinaNoteBufLen] = msgCtx->ocarinaStaff->noteIdx; + sOcarinaNoteBufLen++; + sOcarinaNoteBuf[sOcarinaNoteBufLen] = OCARINA_NOTE_INVALID; + sOcarinaNoteBufPos++; + if (msgCtx->ocarinaStaff->pos == 8) { + sOcarinaNoteBufPos = 0; + } + } + if (msgCtx->ocarinaStaff->state == 0 || CHECK_BTN_ALL(globalCtx->state.input[0].press.button, BTN_B)) { + if (sOcarinaNoteBufLen != 0) { + // "Recording complete!!!!!!!!!" + osSyncPrintf("録音終了!!!!!!!!! message->info->status=%d \n", + msgCtx->ocarinaStaff->state); + gSaveContext.scarecrowCustomSongSet = true; + } + Audio_PlaySoundGeneral(NA_SE_SY_OCARINA_ERROR, &D_801333D4, 4, &D_801333E0, &D_801333E0, + &D_801333E8); + osSyncPrintf("aaaaaaaaaaaaaa\n"); + Audio_OcaSetRecordingState(0); + msgCtx->stateTimer = 10; + globalCtx->msgCtx.ocarinaMode = OCARINA_MODE_04; + Message_CloseTextbox(globalCtx); + // "Recording complete!!!!!!!!!Recording Complete" + osSyncPrintf("録音終了!!!!!!!!!録音終了\n"); + osSyncPrintf(VT_FGCOL(YELLOW)); + osSyncPrintf("\n====================================================================\n"); + MemCopy(gSaveContext.scarecrowCustomSong, gScarecrowCustomSongPtr, + sizeof(gSaveContext.scarecrowCustomSong)); + for (i = 0; i < ARRAY_COUNT(gSaveContext.scarecrowCustomSong); i++) { + osSyncPrintf("%d, ", gSaveContext.scarecrowCustomSong[i]); + } + osSyncPrintf(VT_RST); + osSyncPrintf("\n====================================================================\n"); + } + Message_DrawText(globalCtx, &gfx); + break; + case MSGMODE_SCARECROW_LONG_PLAYBACK: + case MSGMODE_SCARECROW_PLAYBACK: + msgCtx->ocarinaStaff = Audio_OcaGetDisplayingStaff(); + if (msgCtx->ocarinaStaff->pos && sOcarinaNoteBufPos == msgCtx->ocarinaStaff->pos - 1) { + if (sOcarinaNoteBufLen >= 8) { + for (noteBufPos = sOcarinaNoteBufLen - 8, i = 0; i < 8; i++, noteBufPos++) { + sOcarinaNoteBuf[noteBufPos] = sOcarinaNoteBuf[noteBufPos + 1]; + } + sOcarinaNoteBufLen--; + } + sOcarinaNoteBuf[sOcarinaNoteBufLen] = msgCtx->ocarinaStaff->noteIdx; + sOcarinaNoteBufLen++; + sOcarinaNoteBuf[sOcarinaNoteBufLen] = OCARINA_NOTE_INVALID; + sOcarinaNoteBufPos++; + if (msgCtx->ocarinaStaff->pos == 8) { + sOcarinaNoteBufLen = sOcarinaNoteBufPos = 0; + } + } + osSyncPrintf("status=%d (%d)\n", msgCtx->ocarinaStaff->state, 0); + if (msgCtx->stateTimer == 0) { + if (msgCtx->ocarinaStaff->state == 0) { + osSyncPrintf("bbbbbbbbbbb\n"); + Audio_OcaSetInstrument(0); + globalCtx->msgCtx.ocarinaMode = OCARINA_MODE_0F; + Message_CloseTextbox(globalCtx); + } + } else { + msgCtx->stateTimer--; + } + break; + case MSGMODE_SCARECROW_RECORDING_START: + Audio_OcaSetRecordingState(2); + Audio_OcaSetInstrument(1); + msgCtx->msgMode = MSGMODE_SCARECROW_RECORDING_ONGOING; + Message_DrawText(globalCtx, &gfx); + break; + case MSGMODE_SCARECROW_RECORDING_ONGOING: + msgCtx->ocarinaStaff = Audio_OcaGetRecordingStaff(); + if (msgCtx->ocarinaStaff->pos && sOcarinaNoteBufPos == msgCtx->ocarinaStaff->pos - 1) { + msgCtx->lastOcaNoteIdx = sOcarinaNoteBuf[sOcarinaNoteBufPos] = msgCtx->ocarinaStaff->noteIdx; + sOcarinaNoteBufPos++; + sOcarinaNoteBuf[sOcarinaNoteBufPos] = OCARINA_NOTE_INVALID; + } + if (msgCtx->ocarinaStaff->state == 0) { + // "8 Note Recording OK!" + osSyncPrintf("8音録音OK!\n"); + msgCtx->stateTimer = 20; + gSaveContext.scarecrowSpawnSongSet = true; + msgCtx->msgMode = MSGMODE_SCARECROW_RECORDING_DONE; + Audio_PlaySoundGeneral(NA_SE_SY_TRE_BOX_APPEAR, &D_801333D4, 4, &D_801333E0, &D_801333E0, + &D_801333E8); + osSyncPrintf(VT_FGCOL(YELLOW)); + osSyncPrintf("\n====================================================================\n"); + MemCopy(gSaveContext.scarecrowSpawnSong, gScarecrowSpawnSongPtr, + sizeof(gSaveContext.scarecrowSpawnSong)); + for (i = 0; i < ARRAY_COUNT(gSaveContext.scarecrowSpawnSong); i++) { + osSyncPrintf("%d, ", gSaveContext.scarecrowSpawnSong[i]); + } + osSyncPrintf(VT_RST); + osSyncPrintf("\n====================================================================\n"); + } else if (msgCtx->ocarinaStaff->state == 0xFF || + CHECK_BTN_ALL(globalCtx->state.input[0].press.button, BTN_B)) { + // "Played an existing song!!!" + osSyncPrintf("すでに存在する曲吹いた!!! \n"); + Audio_OcaSetRecordingState(0); + Audio_PlaySoundGeneral(NA_SE_SY_OCARINA_ERROR, &D_801333D4, 4, &D_801333E0, &D_801333E0, + &D_801333E8); + Message_CloseTextbox(globalCtx); + msgCtx->msgMode = MSGMODE_SCARECROW_RECORDING_FAILED; + } + Message_DrawText(globalCtx, &gfx); + break; + case MSGMODE_SCARECROW_RECORDING_FAILED: + osSyncPrintf("cccccccccccc\n"); + Audio_OcaSetInstrument(0); + Message_StartTextbox(globalCtx, 0x40AD, NULL); // Bonooru doesn't remember your song + globalCtx->msgCtx.ocarinaMode = OCARINA_MODE_04; + break; + case MSGMODE_MEMORY_GAME_START: + Audio_OcaSetInstrument(1); + Audio_OcaSetInstrument(6); + Audio_OcaMemoryGameStart(gSaveContext.ocarinaGameRoundNum); + msgCtx->ocarinaStaff = Audio_OcaGetDisplayingStaff(); + msgCtx->ocarinaStaff->pos = sOcarinaNoteBufPos = 0; + Message_ResetOcarinaNoteState(); + Audio_OcaSetSongPlayback(OCARINA_SONG_MEMORY_GAME + 1, 1); + msgCtx->msgMode = MSGMODE_MEMORY_GAME_LEFT_SKULLKID_PLAYING; + msgCtx->stateTimer = 2; + break; + case MSGMODE_MEMORY_GAME_LEFT_SKULLKID_PLAYING: + case MSGMODE_MEMORY_GAME_RIGHT_SKULLKID_PLAYING: + Audio_PlaySoundGeneral(NA_SE_SY_METRONOME_LV - SFX_FLAG, &D_801333D4, 4, &D_801333E0, &D_801333E0, + &D_801333E8); + msgCtx->ocarinaStaff = Audio_OcaGetDisplayingStaff(); + if (msgCtx->ocarinaStaff->pos && sOcarinaNoteBufPos == msgCtx->ocarinaStaff->pos - 1) { + sOcarinaNoteBuf[msgCtx->ocarinaStaff->pos - 1] = msgCtx->ocarinaStaff->noteIdx; + sOcarinaNoteBuf[msgCtx->ocarinaStaff->pos] = OCARINA_NOTE_INVALID; + sOcarinaNoteBufPos++; + } + if (msgCtx->stateTimer == 0) { + if (msgCtx->ocarinaStaff->state == 0) { + if (msgCtx->msgMode == MSGMODE_MEMORY_GAME_LEFT_SKULLKID_PLAYING) { + Audio_PlaySoundGeneral(NA_SE_SY_METRONOME, &D_801333D4, 4, &D_801333E0, &D_801333E0, + &D_801333E8); + } else { + Audio_PlaySoundGeneral(NA_SE_SY_METRONOME_2, &D_801333D4, 4, &D_801333E0, &D_801333E0, + &D_801333E8); + } + msgCtx->msgMode++; + } + } else { + msgCtx->stateTimer--; + } + break; + case MSGMODE_MEMORY_GAME_LEFT_SKULLKID_WAIT: + case MSGMODE_MEMORY_GAME_RIGHT_SKULLKID_WAIT: + msgCtx->ocarinaStaff = Audio_OcaGetDisplayingStaff(); + if (msgCtx->ocarinaStaff->pos && sOcarinaNoteBufPos == msgCtx->ocarinaStaff->pos - 1) { + sOcarinaNoteBuf[msgCtx->ocarinaStaff->pos - 1] = msgCtx->ocarinaStaff->noteIdx; + sOcarinaNoteBuf[msgCtx->ocarinaStaff->pos] = OCARINA_NOTE_INVALID; + sOcarinaNoteBufPos++; + } + break; + case MSGMODE_MEMORY_GAME_PLAYER_PLAYING: + Audio_PlaySoundGeneral(NA_SE_SY_METRONOME_LV - SFX_FLAG, &D_801333D4, 4, &D_801333E0, &D_801333E0, + &D_801333E8); + msgCtx->ocarinaStaff = Audio_OcaGetPlayingStaff(); + if (msgCtx->ocarinaStaff->pos && sOcarinaNoteBufPos == msgCtx->ocarinaStaff->pos - 1) { + sOcarinaNoteBuf[msgCtx->ocarinaStaff->pos - 1] = msgCtx->ocarinaStaff->noteIdx; + sOcarinaNoteBuf[msgCtx->ocarinaStaff->pos] = OCARINA_NOTE_INVALID; + sOcarinaNoteBufPos++; + } + if (msgCtx->ocarinaStaff->state == 0xFF) { + // "Musical round failed!!!!!!!!!" + osSyncPrintf("輪唱失敗!!!!!!!!!\n"); + Audio_OcaSetInstrument(0); + Audio_PlaySoundGeneral(NA_SE_SY_OCARINA_ERROR, &D_801333D4, 4, &D_801333E0, &D_801333E0, + &D_801333E8); + msgCtx->stateTimer = 10; + globalCtx->msgCtx.ocarinaMode = OCARINA_MODE_03; + } else if (msgCtx->ocarinaStaff->state == 0xD) { + // "Musical round succeeded!!!!!!!!!" + osSyncPrintf("輪唱成功!!!!!!!!!\n"); + Audio_PlaySoundGeneral(NA_SE_SY_GET_ITEM, &D_801333D4, 4, &D_801333E0, &D_801333E0, &D_801333E8); + msgCtx->msgMode = MSGMODE_MEMORY_GAME_ROUND_SUCCESS; + msgCtx->stateTimer = 30; + } + Message_DrawText(globalCtx, &gfx); + break; + case MSGMODE_MEMORY_GAME_ROUND_SUCCESS: + msgCtx->ocarinaStaff = Audio_OcaGetPlayingStaff(); + if (msgCtx->ocarinaStaff->pos && sOcarinaNoteBufPos == msgCtx->ocarinaStaff->pos - 1) { + sOcarinaNoteBuf[msgCtx->ocarinaStaff->pos - 1] = msgCtx->ocarinaStaff->noteIdx; + sOcarinaNoteBuf[msgCtx->ocarinaStaff->pos] = OCARINA_NOTE_INVALID; + sOcarinaNoteBufPos++; + } + msgCtx->stateTimer--; + if (msgCtx->stateTimer == 0) { + if (Audio_OcaMemoryGameGenNote() != 1) { + Audio_PlaySoundGeneral(NA_SE_SY_METRONOME, &D_801333D4, 4, &D_801333E0, &D_801333E0, + &D_801333E8); + msgCtx->ocarinaStaff = Audio_OcaGetPlayingStaff(); + msgCtx->ocarinaStaff->pos = sOcarinaNoteBufPos = 0; + Message_ResetOcarinaNoteState(); + msgCtx->msgMode = MSGMODE_MEMORY_GAME_START_NEXT_ROUND; + } else { + globalCtx->msgCtx.ocarinaMode = OCARINA_MODE_0F; + } + } + Message_DrawText(globalCtx, &gfx); + break; + case MSGMODE_MEMORY_GAME_START_NEXT_ROUND: + if (!Audio_IsSfxPlaying(NA_SE_SY_METRONOME)) { + msgCtx->ocarinaStaff = Audio_OcaGetDisplayingStaff(); + msgCtx->ocarinaStaff->pos = sOcarinaNoteBufPos = 0; + Message_ResetOcarinaNoteState(); + Audio_OcaSetSongPlayback(OCARINA_SONG_MEMORY_GAME + 1, 1); + } + break; + case MSGMODE_FROGS_START: + Audio_OcaSetInstrument(1); + msgCtx->ocarinaStaff = Audio_OcaGetPlayingStaff(); + msgCtx->ocarinaStaff->pos = sOcarinaNoteBufPos = 0; + globalCtx->msgCtx.ocarinaMode = OCARINA_MODE_01; + Message_ResetOcarinaNoteState(); + func_800ECC04(sOcarinaSongBitFlags + 0xC000); + msgCtx->msgMode = MSGMODE_FROGS_PLAYING; + break; + case MSGMODE_FROGS_PLAYING: + msgCtx->ocarinaStaff = Audio_OcaGetPlayingStaff(); + if (msgCtx->ocarinaStaff->pos && sOcarinaNoteBufPos == msgCtx->ocarinaStaff->pos - 1) { + msgCtx->lastOcaNoteIdx = msgCtx->ocarinaStaff->noteIdx; + msgCtx->ocarinaStaff->pos = sOcarinaNoteBufPos = 0; + Message_ResetOcarinaNoteState(); + msgCtx->msgMode = MSGMODE_FROGS_WAITING; + } + case MSGMODE_FROGS_WAITING: + break; + case MSGMODE_TEXT_DONE: + Message_DrawText(globalCtx, &gfx); + + switch (msgCtx->textboxEndType) { + case TEXTBOX_ENDTYPE_2_CHOICE: + Message_HandleChoiceSelection(globalCtx, 1); + Message_DrawTextboxIcon(globalCtx, &gfx, msgCtx->textPosX, msgCtx->textPosY); + break; + case TEXTBOX_ENDTYPE_3_CHOICE: + Message_HandleChoiceSelection(globalCtx, 2); + Message_DrawTextboxIcon(globalCtx, &gfx, msgCtx->textPosX, msgCtx->textPosY); + break; + case TEXTBOX_ENDTYPE_PERSISTENT: + if (msgCtx->textId >= 0x6D && msgCtx->textId < 0x73) { + msgCtx->stateTimer++; + if (msgCtx->stateTimer >= 31) { + msgCtx->stateTimer = 2; + msgCtx->msgMode = MSGMODE_TEXT_CLOSING; + } + } + break; + case TEXTBOX_ENDTYPE_EVENT: + default: + Message_DrawTextboxIcon(globalCtx, &gfx, R_TEXTBOX_END_XPOS, R_TEXTBOX_END_YPOS); + case TEXTBOX_ENDTYPE_FADING: + break; + } + break; + case MSGMODE_TEXT_CLOSING: + case MSGMODE_PAUSED: + break; + case MSGMODE_UNK_20: + default: + msgCtx->msgMode = MSGMODE_TEXT_DISPLAYING; + break; + } + + if (msgCtx->msgMode >= MSGMODE_OCARINA_PLAYING && msgCtx->msgMode < MSGMODE_TEXT_AWAIT_NEXT && + msgCtx->ocarinaAction != OCARINA_ACTION_FREE_PLAY && msgCtx->ocarinaAction != OCARINA_ACTION_CHECK_NOWARP) { + func_8009457C(&gfx); + + gDPSetCombineLERP(gfx++, PRIMITIVE, ENVIRONMENT, TEXEL0, ENVIRONMENT, TEXEL0, 0, PRIMITIVE, 0, PRIMITIVE, + ENVIRONMENT, TEXEL0, ENVIRONMENT, TEXEL0, 0, PRIMITIVE, 0); + + if (msgCtx->msgMode == MSGMODE_SONG_PLAYBACK) { + g = msgCtx->ocarinaAction - OCARINA_ACTION_PLAYBACK_MINUET; + r = gOcarinaSongNotes[g].len; + for (notePosX = R_OCARINA_NOTES_XPOS, i = 0; i < r; i++, notePosX += R_OCARINA_NOTES_XPOS_OFFSET) { + gDPPipeSync(gfx++); + gDPSetPrimColor(gfx++, 0, 0, 150, 150, 150, 150); + gDPSetEnvColor(gfx++, 10, 10, 10, 0); + + gDPLoadTextureBlock(gfx++, sOcarinaNoteTextures[gOcarinaSongNotes[g].notesIdx[i]], G_IM_FMT_IA, + G_IM_SIZ_8b, 16, 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( + gfx++, notePosX << 2, R_OCARINA_NOTES_YPOS(gOcarinaSongNotes[g].notesIdx[i]) << 2, + (notePosX + 16) << 2, (R_OCARINA_NOTES_YPOS(gOcarinaSongNotes[g].notesIdx[i]) + 16) << 2, + G_TX_RENDERTILE, 0, 0, 1 << 10, 1 << 10); + } + } + + if (msgCtx->msgMode != MSGMODE_SCARECROW_LONG_RECORDING_START && + msgCtx->msgMode != MSGMODE_MEMORY_GAME_START) { + for (notePosX = R_OCARINA_NOTES_XPOS, i = 0; i < 8; i++, notePosX += R_OCARINA_NOTES_XPOS_OFFSET) { + if (sOcarinaNoteBuf[i] == OCARINA_NOTE_INVALID) { + break; + } + + if (1) {} + if (sOcarinaNotesAlphaValues[i] != 255) { + sOcarinaNotesAlphaValues[i] += VREG(50); + if (sOcarinaNotesAlphaValues[i] >= 255) { + sOcarinaNotesAlphaValues[i] = 255; + } + } + + gDPPipeSync(gfx++); + if (sOcarinaNoteBuf[i] == OCARINA_NOTE_A) { + gDPSetPrimColor(gfx++, 0, 0, sOcarinaNoteAPrimR, sOcarinaNoteAPrimG, sOcarinaNoteAPrimB, + sOcarinaNotesAlphaValues[i]); + gDPSetEnvColor(gfx++, sOcarinaNoteAEnvR, sOcarinaNoteAEnvG, sOcarinaNoteAEnvB, 0); + } else { + gDPSetPrimColor(gfx++, 0, 0, sOcarinaNoteCPrimR, sOcarinaNoteCPrimG, sOcarinaNoteCPrimB, + sOcarinaNotesAlphaValues[i]); + gDPSetEnvColor(gfx++, sOcarinaNoteCEnvR, sOcarinaNoteCEnvG, sOcarinaNoteCEnvB, 0); + } + + gDPLoadTextureBlock(gfx++, sOcarinaNoteTextures[sOcarinaNoteBuf[i]], G_IM_FMT_IA, G_IM_SIZ_8b, 16, + 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(gfx++, notePosX << 2, R_OCARINA_NOTES_YPOS(sOcarinaNoteBuf[i]) << 2, + (notePosX + 16) << 2, (R_OCARINA_NOTES_YPOS(sOcarinaNoteBuf[i]) + 16) << 2, + G_TX_RENDERTILE, 0, 0, 1 << 10, 1 << 10); + } + } + } + } + *p = gfx; +} + +/** + * If the s16 variable pointed to by `var` changes in value, a black bar and white box + * are briefly drawn onto the screen. It can only watch one variable per build due to + * the last value being saved in a static variable. + */ +void Message_DrawDebugVariableChanged(s16* var, GraphicsContext* gfxCtx) { + static s16 sVarLastValue = 0; + static s16 sFillTimer = 0; + s32 pad; + + OPEN_DISPS(gfxCtx, "../z_message_PAL.c", 3485); + + if (sVarLastValue != *var) { + sVarLastValue = *var; + sFillTimer = 30; + } + if (sFillTimer != 0) { + sFillTimer--; + gDPPipeSync(POLY_OPA_DISP++); + gDPSetCycleType(POLY_OPA_DISP++, G_CYC_FILL); + gDPSetRenderMode(POLY_OPA_DISP++, G_RM_NOOP, G_RM_NOOP2); + gDPSetFillColor(POLY_OPA_DISP++, GPACK_RGBA5551(0, 0, 0, 1) << 0x10 | GPACK_RGBA5551(0, 0, 0, 1)); + gDPFillRectangle(POLY_OPA_DISP++, 0, 110, SCREEN_WIDTH - 1, 150); // 40x319 black bar + gDPPipeSync(POLY_OPA_DISP++); + gDPPipeSync(POLY_OPA_DISP++); + gDPSetCycleType(POLY_OPA_DISP++, G_CYC_FILL); + gDPSetRenderMode(POLY_OPA_DISP++, G_RM_NOOP, G_RM_NOOP2); + gDPSetFillColor(POLY_OPA_DISP++, GPACK_RGBA5551(255, 255, 255, 1) << 0x10 | GPACK_RGBA5551(255, 255, 255, 1)); + gDPFillRectangle(POLY_OPA_DISP++, 40, 120, 60, 140); // 20x20 white box + gDPPipeSync(POLY_OPA_DISP++); + } + CLOSE_DISPS(gfxCtx, "../z_message_PAL.c", 3513); +} + +void Message_DrawDebugText(GlobalContext* globalCtx, Gfx** p) { + s32 pad; + GfxPrint printer; + s32 pad1; + + GfxPrint_Init(&printer); + GfxPrint_Open(&printer, *p); + GfxPrint_SetPos(&printer, 6, 26); + GfxPrint_SetColor(&printer, 255, 60, 0, 255); + GfxPrint_Printf(&printer, "%s", "MESSAGE"); + GfxPrint_SetPos(&printer, 14, 26); + GfxPrint_Printf(&printer, "%s", "="); + GfxPrint_SetPos(&printer, 16, 26); + GfxPrint_Printf(&printer, "%x", globalCtx->msgCtx.textId); + *p = GfxPrint_Close(&printer); + GfxPrint_Destroy(&printer); +} + +void Message_Draw(GlobalContext* globalCtx) { + Gfx* plusOne; + Gfx* polyOpaP; + s16 watchVar; + + OPEN_DISPS(globalCtx->state.gfxCtx, "../z_message_PAL.c", 3554); + + watchVar = gSaveContext.scarecrowCustomSongSet; + Message_DrawDebugVariableChanged(&watchVar, globalCtx->state.gfxCtx); + if (BREG(0) != 0 && globalCtx->msgCtx.textId != 0) { + plusOne = Graph_GfxPlusOne(polyOpaP = POLY_OPA_DISP); + gSPDisplayList(OVERLAY_DISP++, plusOne); + Message_DrawDebugText(globalCtx, &plusOne); + gSPEndDisplayList(plusOne++); + Graph_BranchDlist(polyOpaP, plusOne); + POLY_OPA_DISP = plusOne; + } + if (1) {} + plusOne = Graph_GfxPlusOne(polyOpaP = POLY_OPA_DISP); + gSPDisplayList(OVERLAY_DISP++, plusOne); + Message_DrawMain(globalCtx, &plusOne); + gSPEndDisplayList(plusOne++); + Graph_BranchDlist(polyOpaP, plusOne); + POLY_OPA_DISP = plusOne; + CLOSE_DISPS(globalCtx->state.gfxCtx, "../z_message_PAL.c", 3582); +} + +void Message_Update(GlobalContext* globalCtx) { + static s16 sTextboxXPositions[] = { + 34, 34, 34, 34, 34, 34, + }; + static s16 sTextboxMidYPositions[] = { + 142, 142, 142, 142, 174, 142, + }; + static s16 sTextboxUpperYPositions[] = { + 38, 38, 38, 38, 174, 38, + }; + static s16 sTextboxLowerYPositions[] = { + 90, 90, 90, 90, 174, 90, + }; + static s16 sTextboxEndIconYOffset[] = { + 59, 59, 59, 59, 34, 59, + }; + static s16 D_80153D3C[] = { + // additional unreferenced data + 0x0400, 0x0400, 0x0200, 0x0000, 0x1038, 0x0008, 0x200A, 0x088B, 0x0007, 0x0009, 0x000A, 0x107E, 0x2008, 0x2007, + 0x0015, 0x0016, 0x0017, 0x0003, 0x0000, 0x270B, 0x00C8, 0x012C, 0x012D, 0xFFDA, 0x0014, 0x0016, 0x0014, 0x0016, + }; + static u8 D_80153D74 = 0; + static u16 D_80153D78 = 0; + MessageContext* msgCtx = &globalCtx->msgCtx; + InterfaceContext* interfaceCtx = &globalCtx->interfaceCtx; + Player* player = GET_PLAYER(globalCtx); + Input* input = &globalCtx->state.input[0]; + s16 var; + s16 focusScreenPosX; + s16 averageY; + s16 playerFocusScreenPosY; + s16 actorFocusScreenPosY; + + if (BREG(0) != 0) { + if (CHECK_BTN_ALL(input->press.button, BTN_DDOWN) && CHECK_BTN_ALL(input->cur.button, BTN_L)) { + osSyncPrintf("msgno=%d\n", D_80153D78); + Message_StartTextbox(globalCtx, R_MESSAGE_DEBUGGER_TEXTID, NULL); + D_80153D78 = (D_80153D78 + 1) % 10; + } + if (R_MESSAGE_DEBUGGER_SELECT != 0) { + while (R_MESSAGE_DEBUGGER_TEXTID != 0x8000) { + MessageTableEntry* entry = &sNesMessageEntryTablePtr[0]; + + while (entry->textId != 0xFFFD) { + if (entry->textId == R_MESSAGE_DEBUGGER_TEXTID) { + // "The message was found! !! !!" + osSyncPrintf(" メッセージが,見つかった!!! = %x\n", R_MESSAGE_DEBUGGER_TEXTID); + Message_StartTextbox(globalCtx, R_MESSAGE_DEBUGGER_TEXTID, NULL); + R_MESSAGE_DEBUGGER_TEXTID++; + R_MESSAGE_DEBUGGER_SELECT = 0; + return; + } + entry++; + } + R_MESSAGE_DEBUGGER_TEXTID++; + } + } + } + + if (msgCtx->msgLength == 0) { + return; + } + + switch (msgCtx->msgMode) { + case MSGMODE_TEXT_START: + D_8014B2F4++; + + var = false; + if (YREG(15) == 0x40) { + if (D_8014B2F4 >= 4) { + var = true; + } + } else if (YREG(15) != 0 || globalCtx->sceneNum == SCENE_HAIRAL_NIWA) { + var = true; + } else if (D_8014B2F4 >= 4 || msgCtx->talkActor == NULL) { + var = true; + } + + if (var) { + if (msgCtx->talkActor != NULL) { + Actor_GetScreenPos(globalCtx, &GET_PLAYER(globalCtx)->actor, &focusScreenPosX, + &playerFocusScreenPosY); + Actor_GetScreenPos(globalCtx, msgCtx->talkActor, &focusScreenPosX, &actorFocusScreenPosY); + + if (playerFocusScreenPosY >= actorFocusScreenPosY) { + averageY = ((playerFocusScreenPosY - actorFocusScreenPosY) / 2) + actorFocusScreenPosY; + } else { + averageY = ((actorFocusScreenPosY - playerFocusScreenPosY) / 2) + playerFocusScreenPosY; + } + osSyncPrintf("dxpos=%d dypos=%d dypos1 dypos2=%d\n", focusScreenPosX, averageY, + playerFocusScreenPosY, actorFocusScreenPosY); + } else { + R_TEXTBOX_X = R_TEXTBOX_X_TARGET; + R_TEXTBOX_Y = R_TEXTBOX_Y_TARGET; + } + + var = msgCtx->textBoxType; + + if (!msgCtx->textBoxPos) { // variable position + if (YREG(15) != 0 || globalCtx->sceneNum == SCENE_HAIRAL_NIWA) { + if (averageY < XREG(92)) { + R_TEXTBOX_Y_TARGET = sTextboxMidYPositions[var]; + } else { + R_TEXTBOX_Y_TARGET = sTextboxUpperYPositions[var]; + } + } else if (globalCtx->sceneNum == SCENE_MARKET_DAY || globalCtx->sceneNum == SCENE_MARKET_NIGHT || + globalCtx->sceneNum == SCENE_MARKET_RUINS) { + if (averageY < XREG(93)) { + R_TEXTBOX_Y_TARGET = sTextboxMidYPositions[var]; + } else { + R_TEXTBOX_Y_TARGET = sTextboxUpperYPositions[var]; + } + } else { + if (averageY < XREG(94)) { + R_TEXTBOX_Y_TARGET = sTextboxMidYPositions[var]; + } else { + R_TEXTBOX_Y_TARGET = sTextboxUpperYPositions[var]; + } + } + } else { + if (msgCtx->textBoxPos == TEXTBOX_POS_TOP) { + R_TEXTBOX_Y_TARGET = sTextboxUpperYPositions[var]; + } else if (msgCtx->textBoxPos == TEXTBOX_POS_BOTTOM) { + R_TEXTBOX_Y_TARGET = sTextboxLowerYPositions[var]; + } else { + R_TEXTBOX_Y_TARGET = sTextboxMidYPositions[var]; + } + } + + R_TEXTBOX_X_TARGET = sTextboxXPositions[var]; + R_TEXTBOX_END_YPOS = sTextboxEndIconYOffset[var] + R_TEXTBOX_Y_TARGET; + R_TEXT_CHOICE_YPOS(0) = R_TEXTBOX_Y_TARGET + 20; + R_TEXT_CHOICE_YPOS(1) = R_TEXTBOX_Y_TARGET + 32; + R_TEXT_CHOICE_YPOS(2) = R_TEXTBOX_Y_TARGET + 44; + osSyncPrintf("message->msg_disp_type=%x\n", msgCtx->textBoxProperties & 0xF0); + if (msgCtx->textBoxType == TEXTBOX_TYPE_NONE_BOTTOM || msgCtx->textBoxType == TEXTBOX_TYPE_NONE_NO_SHADOW) { + msgCtx->msgMode = MSGMODE_TEXT_STARTING; + R_TEXTBOX_X = R_TEXTBOX_X_TARGET; + R_TEXTBOX_Y = R_TEXTBOX_Y_TARGET; + R_TEXTBOX_WIDTH = 256; + R_TEXTBOX_HEIGHT = 64; + R_TEXTBOX_TEXWIDTH = 512; + R_TEXTBOX_TEXHEIGHT = 512; + } else { + Message_GrowTextbox(msgCtx); + Audio_PlaySoundIfNotInCutscene(0); + msgCtx->stateTimer = 0; + msgCtx->msgMode = MSGMODE_TEXT_BOX_GROWING; + } + } + break; + case MSGMODE_TEXT_BOX_GROWING: + Message_GrowTextbox(msgCtx); + break; + case MSGMODE_TEXT_STARTING: + msgCtx->msgMode = MSGMODE_TEXT_NEXT_MSG; + if (YREG(31) == 0) { + Interface_SetDoAction(globalCtx, DO_ACTION_NEXT); + } + break; + case MSGMODE_TEXT_NEXT_MSG: + Message_Decode(globalCtx); + if (sTextFade) { + Interface_ChangeAlpha(1); + } + if (D_80153D74 != 0) { + msgCtx->textDrawPos = msgCtx->decodedTextLen; + D_80153D74 = 0; + } + break; + case MSGMODE_TEXT_CONTINUING: + msgCtx->stateTimer--; + if (msgCtx->stateTimer == 0) { + Message_Decode(globalCtx); + } + break; + case MSGMODE_TEXT_DISPLAYING: + if (msgCtx->textBoxType != TEXTBOX_TYPE_NONE_BOTTOM && YREG(31) == 0 && + CHECK_BTN_ALL(globalCtx->state.input[0].press.button, BTN_B) && !msgCtx->textUnskippable) { + sTextboxSkipped = true; + msgCtx->textDrawPos = msgCtx->decodedTextLen; + } + break; + case MSGMODE_TEXT_AWAIT_INPUT: + if (YREG(31) == 0 && Message_ShouldAdvance(globalCtx)) { + msgCtx->msgMode = MSGMODE_TEXT_DISPLAYING; + msgCtx->textDrawPos++; + } + break; + case MSGMODE_TEXT_DELAYED_BREAK: + msgCtx->stateTimer--; + if (msgCtx->stateTimer == 0) { + msgCtx->msgMode = MSGMODE_TEXT_NEXT_MSG; + } + break; + case MSGMODE_TEXT_AWAIT_NEXT: + if (Message_ShouldAdvance(globalCtx)) { + msgCtx->msgMode = MSGMODE_TEXT_NEXT_MSG; + msgCtx->textUnskippable = false; + msgCtx->msgBufPos++; + } + break; + case MSGMODE_TEXT_DONE: + if (msgCtx->textboxEndType == TEXTBOX_ENDTYPE_FADING) { + msgCtx->stateTimer--; + if (msgCtx->stateTimer == 0) { + Message_CloseTextbox(globalCtx); + } + } else if (msgCtx->textboxEndType != TEXTBOX_ENDTYPE_PERSISTENT && + msgCtx->textboxEndType != TEXTBOX_ENDTYPE_EVENT && YREG(31) == 0) { + if (msgCtx->textboxEndType == TEXTBOX_ENDTYPE_2_CHOICE && + globalCtx->msgCtx.ocarinaMode == OCARINA_MODE_01) { + if (Message_ShouldAdvance(globalCtx)) { + osSyncPrintf("OCARINA_MODE=%d -> ", globalCtx->msgCtx.ocarinaMode); + globalCtx->msgCtx.ocarinaMode = (msgCtx->choiceIndex == 0) ? OCARINA_MODE_02 : OCARINA_MODE_04; + osSyncPrintf("InRaceSeq=%d(%d) OCARINA_MODE=%d --> ", gSaveContext.eventInf[0] & 0xF, 1, + globalCtx->msgCtx.ocarinaMode); + Message_CloseTextbox(globalCtx); + osSyncPrintf("OCARINA_MODE=%d\n", globalCtx->msgCtx.ocarinaMode); + } + } else if (Message_ShouldAdvanceSilent(globalCtx)) { + osSyncPrintf("select=%d\n", msgCtx->textboxEndType); + if (msgCtx->textboxEndType == TEXTBOX_ENDTYPE_HAS_NEXT) { + Audio_PlaySoundGeneral(NA_SE_SY_MESSAGE_PASS, &D_801333D4, 4, &D_801333E0, &D_801333E0, + &D_801333E8); + Message_ContinueTextbox(globalCtx, sNextTextId); + } else { + Audio_PlaySoundGeneral(NA_SE_SY_DECIDE, &D_801333D4, 4, &D_801333E0, &D_801333E0, &D_801333E8); + Message_CloseTextbox(globalCtx); + } + } + } + break; + case MSGMODE_TEXT_CLOSING: + msgCtx->stateTimer--; + if (msgCtx->stateTimer != 0) { + break; + } + if ((msgCtx->textId >= 0xC2 && msgCtx->textId < 0xC7) || + (msgCtx->textId >= 0xFA && msgCtx->textId < 0xFE)) { + gSaveContext.healthAccumulator = 0x140; // Refill 20 hearts + } + if (msgCtx->textId == 0x301F || msgCtx->textId == 0xA || msgCtx->textId == 0xC || msgCtx->textId == 0xCF || + msgCtx->textId == 0x21C || msgCtx->textId == 9 || msgCtx->textId == 0x4078 || + msgCtx->textId == 0x2015 || msgCtx->textId == 0x3040) { + gSaveContext.unk_13EE = 0x32; + } + if (globalCtx->csCtx.state == 0) { + osSyncPrintf(VT_FGCOL(GREEN)); + osSyncPrintf("day_time=%x active_camera=%d ", gSaveContext.cutsceneIndex, globalCtx->activeCamera); + + if (msgCtx->textId != 0x2061 && msgCtx->textId != 0x2025 && msgCtx->textId != 0x208C && + ((msgCtx->textId < 0x88D || msgCtx->textId >= 0x893) || msgCtx->choiceIndex != 0) && + (msgCtx->textId != 0x3055 && gSaveContext.cutsceneIndex < 0xFFF0)) { + osSyncPrintf("=== day_time=%x ", ((void)0, gSaveContext.cutsceneIndex)); + if (globalCtx->activeCamera == MAIN_CAM) { + if (gSaveContext.unk_13EE == 0 || gSaveContext.unk_13EE == 1 || gSaveContext.unk_13EE == 2) { + gSaveContext.unk_13EE = 0x32; + } + gSaveContext.unk_13EA = 0; + Interface_ChangeAlpha(gSaveContext.unk_13EE); + } + } + } + osSyncPrintf(VT_RST); + msgCtx->msgLength = 0; + msgCtx->msgMode = MSGMODE_NONE; + interfaceCtx->unk_1FA = interfaceCtx->unk_1FC = 0; + msgCtx->textId = msgCtx->stateTimer = 0; + + if (msgCtx->textboxEndType == TEXTBOX_ENDTYPE_PERSISTENT) { + msgCtx->textboxEndType = TEXTBOX_ENDTYPE_DEFAULT; + globalCtx->msgCtx.ocarinaMode = OCARINA_MODE_02; + } else { + msgCtx->textboxEndType = TEXTBOX_ENDTYPE_DEFAULT; + } + if ((s32)(gSaveContext.inventory.questItems & 0xF0000000) == 0x40000000) { + gSaveContext.inventory.questItems ^= 0x40000000; + gSaveContext.healthCapacity += 0x10; + gSaveContext.health += 0x10; + } + if (msgCtx->ocarinaAction != OCARINA_ACTION_CHECK_NOWARP_DONE) { + if (sLastPlayedSong == OCARINA_SONG_SARIAS) { + //! @bug The last played song is not unset often, and if something interrupts the message system + // before it reaches this point after playing Saria's song, the song will be "stored". + // Later, if the ocarina has not been played and another textbox is closed, this handling + // for Saria's song will be carried out. + player->naviTextId = -0xE0; + player->naviActor->flags |= 0x10000; + } + if (msgCtx->ocarinaAction == OCARINA_ACTION_FREE_PLAY_DONE && + (globalCtx->msgCtx.ocarinaMode == OCARINA_MODE_01 || + globalCtx->msgCtx.ocarinaMode == OCARINA_MODE_0B)) { + globalCtx->msgCtx.ocarinaMode = OCARINA_MODE_04; + if (msgCtx->unk_E3F2 == OCARINA_SONG_SUNS) { + globalCtx->msgCtx.ocarinaMode = OCARINA_MODE_01; + } + } + } + sLastPlayedSong = 0xFF; + osSyncPrintf("OCARINA_MODE=%d chk_ocarina_no=%d\n", globalCtx->msgCtx.ocarinaMode, msgCtx->unk_E3F2); + break; + case MSGMODE_PAUSED: + break; + default: + msgCtx->lastOcaNoteIdx = OCARINA_NOTE_INVALID; + break; + } +} + +void Message_SetTables(void) { + sNesMessageEntryTablePtr = sNesMessageEntryTable; + sGerMessageEntryTablePtr = sGerMessageEntryTable; + sFraMessageEntryTablePtr = sFraMessageEntryTable; + sStaffMessageEntryTablePtr = sStaffMessageEntryTable; +} + +// Appears to be file padding +UNK_TYPE D_80153D7C = 0x00000000; + +// This should be part of z_game_over.c, but cannot be moved there as the entire +// late_rodata section of this file is in the way +s16 gGameOverTimer = 0; diff --git a/src/code/z_onepointdemo.c b/src/code/z_onepointdemo.c index fb074315e..96ef33c18 100644 --- a/src/code/z_onepointdemo.c +++ b/src/code/z_onepointdemo.c @@ -227,8 +227,8 @@ s32 OnePointCutscene_SetInfo(GlobalContext* globalCtx, s16 camIdx, s16 csId, Act s16 sp7E; s16 sp7C; - func_8002F374(globalCtx, &player->actor, &sp82, &sp7E); - func_8002F374(globalCtx, actor, &sp80, &sp7C); + Actor_GetScreenPos(globalCtx, &player->actor, &sp82, &sp7E); + Actor_GetScreenPos(globalCtx, actor, &sp80, &sp7C); if ((sp82 > 0) && (sp82 < 320) && (sp7E > 0) && (sp7E < 240) && (sp80 > 0) && (sp80 < 320) && (sp7C > 0) && (sp7C < 240) && !OnePointCutscene_BgCheckLineTest(&globalCtx->colCtx, &actor->focus.pos, &player->actor.focus.pos)) { diff --git a/src/code/z_parameter.c b/src/code/z_parameter.c index 26a926126..c0d674e7c 100644 --- a/src/code/z_parameter.c +++ b/src/code/z_parameter.c @@ -4,6 +4,11 @@ #include "textures/do_action_static/do_action_static.h" #include "textures/icon_item_static/icon_item_static.h" +// TODO extract this information from the texture definitions themselves +#define DO_ACTION_TEX_WIDTH 48 +#define DO_ACTION_TEX_HEIGHT 16 +#define DO_ACTION_TEX_SIZE ((DO_ACTION_TEX_WIDTH * DO_ACTION_TEX_HEIGHT) / 2) // (sizeof(gCheckDoActionENGTex)) + typedef struct { /* 0x00 */ u8 scene; /* 0x01 */ u8 flags1; @@ -700,7 +705,7 @@ void func_80083108(GlobalContext* globalCtx) { gSaveContext.buttonStatus[3] = BTN_DISABLED; Interface_ChangeAlpha(50); } - } else if (msgCtx->msgMode == 0) { + } else if (msgCtx->msgMode == MSGMODE_NONE) { if ((func_8008F2F8(globalCtx) >= 2) && (func_8008F2F8(globalCtx) < 5)) { if (gSaveContext.buttonStatus[0] != BTN_DISABLED) { sp28 = 1; @@ -2031,30 +2036,32 @@ void func_80086D5C(s32* buf, u16 size) { } } -void Interface_LoadActionLabel(InterfaceContext* interfaceCtx, u16 action, s16 arg2) { +void Interface_LoadActionLabel(InterfaceContext* interfaceCtx, u16 action, s16 loadOffset) { static void* sDoActionTextures[] = { gAttackDoActionENGTex, gCheckDoActionENGTex }; - if (action >= 0x1D) { - action = 0x0A; + if (action >= DO_ACTION_MAX) { + action = DO_ACTION_NONE; } - if (gSaveContext.language != 0) { - action += 0x1D; + if (gSaveContext.language != LANGUAGE_ENG) { + action += DO_ACTION_MAX; } - if (gSaveContext.language == 2) { - action += 0x1D; + if (gSaveContext.language == LANGUAGE_FRA) { + action += DO_ACTION_MAX; } - if ((action != 0x0A) && (action != 0x27) && (action != 0x44)) { + if ((action != DO_ACTION_NONE) && (action != DO_ACTION_MAX + DO_ACTION_NONE) && + (action != 2 * DO_ACTION_MAX + DO_ACTION_NONE)) { osCreateMesgQueue(&interfaceCtx->loadQueue, &interfaceCtx->loadMsg, OS_MESG_BLOCK); - DmaMgr_SendRequest2(&interfaceCtx->dmaRequest_160, interfaceCtx->doActionSegment + (arg2 * 0x180), - (u32)_do_action_staticSegmentRomStart + (action * 0x180), 0x180, 0, - &interfaceCtx->loadQueue, NULL, "../z_parameter.c", 2145); + DmaMgr_SendRequest2(&interfaceCtx->dmaRequest_160, + interfaceCtx->doActionSegment + (loadOffset * DO_ACTION_TEX_SIZE), + (u32)_do_action_staticSegmentRomStart + (action * DO_ACTION_TEX_SIZE), DO_ACTION_TEX_SIZE, + 0, &interfaceCtx->loadQueue, NULL, "../z_parameter.c", 2145); osRecvMesg(&interfaceCtx->loadQueue, NULL, OS_MESG_BLOCK); } else { gSegments[7] = VIRTUAL_TO_PHYSICAL(interfaceCtx->doActionSegment); - func_80086D5C(SEGMENTED_TO_VIRTUAL(sDoActionTextures[arg2]), 0x180 / 4); + func_80086D5C(SEGMENTED_TO_VIRTUAL(sDoActionTextures[loadOffset]), DO_ACTION_TEX_SIZE / 4); } } @@ -2098,20 +2105,20 @@ void Interface_SetNaviCall(GlobalContext* globalCtx, u16 naviCallState) { void Interface_LoadActionLabelB(GlobalContext* globalCtx, u16 action) { InterfaceContext* interfaceCtx = &globalCtx->interfaceCtx; - if (gSaveContext.language != 0) { - action += 0x1D; + if (gSaveContext.language != LANGUAGE_ENG) { + action += DO_ACTION_MAX; } - if (gSaveContext.language == 2) { - action += 0x1D; + if (gSaveContext.language == LANGUAGE_FRA) { + action += DO_ACTION_MAX; } interfaceCtx->unk_1FC = action; osCreateMesgQueue(&interfaceCtx->loadQueue, &interfaceCtx->loadMsg, OS_MESG_BLOCK); - DmaMgr_SendRequest2(&interfaceCtx->dmaRequest_160, interfaceCtx->doActionSegment + 0x180, - (u32)_do_action_staticSegmentRomStart + (action * 0x180), 0x180, 0, &interfaceCtx->loadQueue, - NULL, "../z_parameter.c", 2228); + DmaMgr_SendRequest2(&interfaceCtx->dmaRequest_160, interfaceCtx->doActionSegment + DO_ACTION_TEX_SIZE, + (u32)_do_action_staticSegmentRomStart + (action * DO_ACTION_TEX_SIZE), DO_ACTION_TEX_SIZE, 0, + &interfaceCtx->loadQueue, NULL, "../z_parameter.c", 2228); osRecvMesg(&interfaceCtx->loadQueue, NULL, OS_MESG_BLOCK); interfaceCtx->unk_1FA = 1; @@ -2445,9 +2452,9 @@ void Interface_UpdateMagicBar(GlobalContext* globalCtx) { break; case 7: - if ((globalCtx->pauseCtx.state == 0) && (globalCtx->pauseCtx.debugState == 0) && (msgCtx->msgMode == 0) && - (globalCtx->gameOverCtx.state == GAMEOVER_INACTIVE) && (globalCtx->sceneLoadFlag == 0) && - (globalCtx->transitionMode == 0) && !Gameplay_InCsMode(globalCtx)) { + if ((globalCtx->pauseCtx.state == 0) && (globalCtx->pauseCtx.debugState == 0) && + (msgCtx->msgMode == MSGMODE_NONE) && (globalCtx->gameOverCtx.state == GAMEOVER_INACTIVE) && + (globalCtx->sceneLoadFlag == 0) && (globalCtx->transitionMode == 0) && !Gameplay_InCsMode(globalCtx)) { if ((gSaveContext.magic == 0) || ((func_8008F2F8(globalCtx) >= 2) && (func_8008F2F8(globalCtx) < 5)) || ((gSaveContext.equips.buttonItems[1] != ITEM_LENS) && (gSaveContext.equips.buttonItems[2] != ITEM_LENS) && @@ -2633,8 +2640,9 @@ void func_80088B34(s16 arg0) { void Interface_DrawActionLabel(GraphicsContext* gfxCtx, void* texture) { OPEN_DISPS(gfxCtx, "../z_parameter.c", 2820); - gDPLoadTextureBlock_4b(OVERLAY_DISP++, texture, G_IM_FMT_IA, 48, 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); + gDPLoadTextureBlock_4b(OVERLAY_DISP++, texture, G_IM_FMT_IA, DO_ACTION_TEX_WIDTH, DO_ACTION_TEX_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(OVERLAY_DISP++, 0, 2, 3, 1, 0); @@ -2700,13 +2708,13 @@ void Interface_DrawItemButtons(GlobalContext* globalCtx) { gDPSetCombineLERP(OVERLAY_DISP++, PRIMITIVE, ENVIRONMENT, TEXEL0, ENVIRONMENT, TEXEL0, 0, PRIMITIVE, 0, PRIMITIVE, ENVIRONMENT, TEXEL0, ENVIRONMENT, TEXEL0, 0, PRIMITIVE, 0); - gDPLoadTextureBlock_4b(OVERLAY_DISP++, interfaceCtx->doActionSegment + 0x300, G_IM_FMT_IA, 48, 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); + gDPLoadTextureBlock_4b(OVERLAY_DISP++, interfaceCtx->doActionSegment + DO_ACTION_TEX_SIZE * 2, G_IM_FMT_IA, + DO_ACTION_TEX_WIDTH, DO_ACTION_TEX_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); dxdy = (1 << 10) / (R_START_LABEL_DD(gSaveContext.language) / 100.0f); - width = 48.0f / (R_START_LABEL_DD(gSaveContext.language) / 100.0f); - height = 16.0f / (R_START_LABEL_DD(gSaveContext.language) / 100.0f); + width = DO_ACTION_TEX_WIDTH / (R_START_LABEL_DD(gSaveContext.language) / 100.0f); + height = DO_ACTION_TEX_HEIGHT / (R_START_LABEL_DD(gSaveContext.language) / 100.0f); gSPTextureRectangle( OVERLAY_DISP++, R_START_LABEL_X(gSaveContext.language) << 2, R_START_LABEL_Y(gSaveContext.language) << 2, (R_START_LABEL_X(gSaveContext.language) + width) << 2, @@ -3164,15 +3172,16 @@ void Interface_Draw(GlobalContext* globalCtx) { PRIMITIVE, ENVIRONMENT, TEXEL0, ENVIRONMENT, TEXEL0, 0, PRIMITIVE, 0); gDPSetPrimColor(OVERLAY_DISP++, 0, 0, 255, 255, 255, interfaceCtx->bAlpha); - gDPLoadTextureBlock_4b(OVERLAY_DISP++, interfaceCtx->doActionSegment + 0x180, G_IM_FMT_IA, 48, 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); + gDPLoadTextureBlock_4b(OVERLAY_DISP++, interfaceCtx->doActionSegment + DO_ACTION_TEX_SIZE, G_IM_FMT_IA, + DO_ACTION_TEX_WIDTH, DO_ACTION_TEX_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); R_B_LABEL_DD = (1 << 10) / (WREG(37 + gSaveContext.language) / 100.0f); gSPTextureRectangle(OVERLAY_DISP++, R_B_LABEL_X(gSaveContext.language) << 2, - R_B_LABEL_Y(gSaveContext.language) << 2, (R_B_LABEL_X(gSaveContext.language) + 48) << 2, - (R_B_LABEL_Y(gSaveContext.language) + 16) << 2, G_TX_RENDERTILE, 0, 0, R_B_LABEL_DD, - R_B_LABEL_DD); + R_B_LABEL_Y(gSaveContext.language) << 2, + (R_B_LABEL_X(gSaveContext.language) + DO_ACTION_TEX_WIDTH) << 2, + (R_B_LABEL_Y(gSaveContext.language) + DO_ACTION_TEX_HEIGHT) << 2, G_TX_RENDERTILE, 0, 0, + R_B_LABEL_DD, R_B_LABEL_DD); } gDPPipeSync(OVERLAY_DISP++); @@ -3239,7 +3248,7 @@ void Interface_Draw(GlobalContext* globalCtx) { if ((interfaceCtx->unk_1EC < 2) || (interfaceCtx->unk_1EC == 3)) { Interface_DrawActionLabel(globalCtx->state.gfxCtx, interfaceCtx->doActionSegment); } else { - Interface_DrawActionLabel(globalCtx->state.gfxCtx, interfaceCtx->doActionSegment + 0x180); + Interface_DrawActionLabel(globalCtx->state.gfxCtx, interfaceCtx->doActionSegment + DO_ACTION_TEX_SIZE); } gDPPipeSync(OVERLAY_DISP++); @@ -3355,7 +3364,7 @@ void Interface_Draw(GlobalContext* globalCtx) { } } - if ((gSaveContext.timer2State == 5) && (func_8010BDBC(&globalCtx->msgCtx) == 5)) { + if ((gSaveContext.timer2State == 5) && (Message_GetState(&globalCtx->msgCtx) == TEXT_STATE_EVENT)) { // Trade quest timer reached 0 D_8015FFE6 = 40; gSaveContext.cutsceneIndex = 0; @@ -3393,7 +3402,7 @@ void Interface_Draw(GlobalContext* globalCtx) { } if ((globalCtx->pauseCtx.state == 0) && (globalCtx->pauseCtx.debugState == 0) && - (globalCtx->gameOverCtx.state == GAMEOVER_INACTIVE) && (msgCtx->msgMode == 0) && + (globalCtx->gameOverCtx.state == GAMEOVER_INACTIVE) && (msgCtx->msgMode == MSGMODE_NONE) && !(player->stateFlags2 & 0x01000000) && (globalCtx->sceneLoadFlag == 0) && (globalCtx->transitionMode == 0) && !Gameplay_InCsMode(globalCtx) && (gSaveContext.minigameState != 1) && (globalCtx->shootingGalleryStatus <= 1) && @@ -3474,7 +3483,7 @@ void Interface_Draw(GlobalContext* globalCtx) { } } - if ((gSaveContext.timer1State >= 3) && (msgCtx->unk_E300 == 0)) { + if ((gSaveContext.timer1State >= 3) && (msgCtx->msgLength == 0)) { D_8015FFE0--; if (D_8015FFE0 == 0) { if (gSaveContext.timer1Value != 0) { @@ -3659,7 +3668,7 @@ void Interface_Draw(GlobalContext* globalCtx) { D_8015FFE6 = 40; gSaveContext.timer2State = 5; gSaveContext.cutsceneIndex = 0; - func_8010B680(globalCtx, 0x71B0, NULL); + Message_StartTextbox(globalCtx, 0x71B0, NULL); func_8002DF54(globalCtx, NULL, 8); } else { D_8015FFE6 = 40; @@ -3683,7 +3692,7 @@ void Interface_Draw(GlobalContext* globalCtx) { gSaveContext.timer2Value++; if (gSaveContext.eventInf[1] & 1) { if (gSaveContext.timer2Value == 240) { - func_8010B680(globalCtx, 0x6083, NULL); + Message_StartTextbox(globalCtx, 0x6083, NULL); gSaveContext.eventInf[1] &= ~1; gSaveContext.timer2State = 0; } @@ -3799,20 +3808,21 @@ void Interface_Update(GlobalContext* globalCtx) { Input* debugInput = &globalCtx->state.input[2]; if (CHECK_BTN_ALL(debugInput->press.button, BTN_DLEFT)) { - gSaveContext.language = 0; + gSaveContext.language = LANGUAGE_ENG; osSyncPrintf("J_N=%x J_N=%x\n", gSaveContext.language, &gSaveContext.language); } else if (CHECK_BTN_ALL(debugInput->press.button, BTN_DUP)) { - gSaveContext.language = 1; + gSaveContext.language = LANGUAGE_GER; osSyncPrintf("J_N=%x J_N=%x\n", gSaveContext.language, &gSaveContext.language); } else if (CHECK_BTN_ALL(debugInput->press.button, BTN_DRIGHT)) { - gSaveContext.language = 2; + gSaveContext.language = LANGUAGE_FRA; osSyncPrintf("J_N=%x J_N=%x\n", gSaveContext.language, &gSaveContext.language); } if ((globalCtx->pauseCtx.state == 0) && (globalCtx->pauseCtx.debugState == 0)) { if ((gSaveContext.minigameState == 1) || (gSaveContext.sceneSetupIndex < 4) || ((globalCtx->sceneNum == SCENE_SPOT20) && (gSaveContext.sceneSetupIndex == 4))) { - if ((msgCtx->msgMode == 0) || ((msgCtx->msgMode != 0) && (globalCtx->sceneNum == SCENE_BOWLING))) { + if ((msgCtx->msgMode == MSGMODE_NONE) || + ((msgCtx->msgMode != MSGMODE_NONE) && (globalCtx->sceneNum == SCENE_BOWLING))) { if (globalCtx->gameOverCtx.state == GAMEOVER_INACTIVE) { func_80083108(globalCtx); } @@ -3952,7 +3962,7 @@ void Interface_Update(GlobalContext* globalCtx) { HealthMeter_Update(globalCtx); if ((gSaveContext.timer1State >= 3) && (globalCtx->pauseCtx.state == 0) && (globalCtx->pauseCtx.debugState == 0) && - (msgCtx->msgMode == 0) && !(player->stateFlags2 & 0x01000000) && (globalCtx->sceneLoadFlag == 0) && + (msgCtx->msgMode == MSGMODE_NONE) && !(player->stateFlags2 & 0x01000000) && (globalCtx->sceneLoadFlag == 0) && (globalCtx->transitionMode == 0) && !Gameplay_InCsMode(globalCtx)) {} if (gSaveContext.rupeeAccumulator != 0) { @@ -4002,8 +4012,8 @@ void Interface_Update(GlobalContext* globalCtx) { interfaceCtx->unk_1EC = 0; interfaceCtx->unk_1EE = interfaceCtx->unk_1F0; action = interfaceCtx->unk_1EE; - if ((action == 0x1D) || (action == 0x1E)) { - action = 0xA; + if ((action == DO_ACTION_MAX) || (action == DO_ACTION_MAX + 1)) { + action = DO_ACTION_NONE; } Interface_LoadActionLabel(interfaceCtx, action, 0); } @@ -4022,8 +4032,8 @@ void Interface_Update(GlobalContext* globalCtx) { interfaceCtx->unk_1EC = 0; interfaceCtx->unk_1EE = interfaceCtx->unk_1F0; action = interfaceCtx->unk_1EE; - if ((action == 0x1D) || (action == 0x1E)) { - action = 0xA; + if ((action == DO_ACTION_MAX) || (action == DO_ACTION_MAX + 1)) { + action = DO_ACTION_NONE; } Interface_LoadActionLabel(interfaceCtx, action, 0); } @@ -4032,9 +4042,9 @@ void Interface_Update(GlobalContext* globalCtx) { WREG(7) = interfaceCtx->unk_1F4; - if ((globalCtx->pauseCtx.state == 0) && (globalCtx->pauseCtx.debugState == 0) && (msgCtx->msgMode == 0) && - (globalCtx->sceneLoadFlag == 0) && (globalCtx->gameOverCtx.state == GAMEOVER_INACTIVE) && - (globalCtx->transitionMode == 0) && + if ((globalCtx->pauseCtx.state == 0) && (globalCtx->pauseCtx.debugState == 0) && + (msgCtx->msgMode == MSGMODE_NONE) && (globalCtx->sceneLoadFlag == 0) && + (globalCtx->gameOverCtx.state == GAMEOVER_INACTIVE) && (globalCtx->transitionMode == 0) && ((globalCtx->csCtx.state == CS_STATE_IDLE) || !Player_InCsMode(globalCtx))) { if ((gSaveContext.magicAcquired != 0) && (gSaveContext.magicLevel == 0)) { gSaveContext.magicLevel = gSaveContext.doubleMagic + 1; @@ -4100,8 +4110,9 @@ void Interface_Update(GlobalContext* globalCtx) { if (gSaveContext.sunsSongState != SUNSSONG_INACTIVE) { // exit out of ocarina mode after suns song finishes playing - if ((msgCtx->unk_E3F0 != 0x31) && (gSaveContext.sunsSongState == SUNSSONG_START)) { - globalCtx->msgCtx.unk_E3EE = 4; + if ((msgCtx->ocarinaAction != OCARINA_ACTION_CHECK_NOWARP_DONE) && + (gSaveContext.sunsSongState == SUNSSONG_START)) { + globalCtx->msgCtx.ocarinaMode = OCARINA_MODE_04; } // handle suns song in areas where time moves @@ -4119,12 +4130,12 @@ void Interface_Update(GlobalContext* globalCtx) { if ((gSaveContext.dayTime >= 0x4555) && (gSaveContext.dayTime <= 0xC001)) { gSaveContext.sunsSongState = SUNSSONG_INACTIVE; gTimeIncrement = sPrevTimeIncrement; - globalCtx->msgCtx.unk_E3EE = 4; + globalCtx->msgCtx.ocarinaMode = OCARINA_MODE_04; } } else if (gSaveContext.dayTime > 0xC001) { gSaveContext.sunsSongState = SUNSSONG_INACTIVE; gTimeIncrement = sPrevTimeIncrement; - globalCtx->msgCtx.unk_E3EE = 4; + globalCtx->msgCtx.ocarinaMode = OCARINA_MODE_04; } } else if ((globalCtx->roomCtx.curRoom.unk_03 != 1) && (interfaceCtx->restrictions.sunsSong != 3)) { if ((gSaveContext.dayTime >= 0x4555) && (gSaveContext.dayTime < 0xC001)) { diff --git a/src/code/z_play.c b/src/code/z_play.c index b7fbe0862..3a168f0b4 100644 --- a/src/code/z_play.c +++ b/src/code/z_play.c @@ -226,7 +226,7 @@ void Gameplay_Init(GameState* thisx) { func_8005AC48(&globalCtx->mainCamera, 0xFF); Sram_Init(globalCtx, &globalCtx->sramCtx); func_80112098(globalCtx); - func_80110F68(globalCtx); + Message_Init(globalCtx); GameOver_Init(globalCtx); func_8006BA00(globalCtx); Effect_InitContext(globalCtx); @@ -311,7 +311,7 @@ void Gameplay_Init(GameState* thisx) { gSaveContext.dogIsLost = true; if (Inventory_ReplaceItem(globalCtx, ITEM_WEIRD_EGG, ITEM_CHICKEN) || Inventory_ReplaceItem(globalCtx, ITEM_POCKET_EGG, ITEM_POCKET_CUCCO)) { - func_8010B680(globalCtx, 0x3066, NULL); + Message_StartTextbox(globalCtx, 0x3066, NULL); } gSaveContext.nextDayTime = 0xFFFE; } else { @@ -773,7 +773,7 @@ void Gameplay_Update(GlobalContext* globalCtx) { LOG_NUM("1", 1, "../z_play.c", 3542); } - if ((gSaveContext.gameMode == 0) && (globalCtx->msgCtx.msgMode == 0) && + if ((gSaveContext.gameMode == 0) && (globalCtx->msgCtx.msgMode == MSGMODE_NONE) && (globalCtx->gameOverCtx.state == GAMEOVER_INACTIVE)) { KaleidoSetup_Update(globalCtx); } @@ -951,7 +951,7 @@ void Gameplay_Update(GlobalContext* globalCtx) { LOG_NUM("1", 1, "../z_play.c", 3733); } - func_8010F6F0(globalCtx); + Message_Update(globalCtx); } if (1 && HREG(63)) { @@ -1045,7 +1045,7 @@ void Gameplay_DrawOverlayElements(GlobalContext* globalCtx) { Interface_Draw(globalCtx); } - func_8010F58C(globalCtx); + Message_Draw(globalCtx); if (globalCtx->gameOverCtx.state != GAMEOVER_INACTIVE) { GameOver_FadeInLights(globalCtx); diff --git a/src/code/z_player_lib.c b/src/code/z_player_lib.c index 69cf11f67..3625d5062 100644 --- a/src/code/z_player_lib.c +++ b/src/code/z_player_lib.c @@ -605,7 +605,7 @@ s32 func_8008F2F8(GlobalContext* globalCtx) { (((var == 0) && (this->currentTunic != PLAYER_TUNIC_GORON)) || (((var == 1) || (var == 3)) && (this->currentBoots == PLAYER_BOOTS_IRON) && (this->currentTunic != PLAYER_TUNIC_ZORA)))) { - func_8010B680(globalCtx, triggerEntry->textId, NULL); + Message_StartTextbox(globalCtx, triggerEntry->textId, NULL); gSaveContext.textTriggerFlags |= triggerEntry->flag; } } diff --git a/src/code/z_scene.c b/src/code/z_scene.c index f61802f2c..d6fcf566c 100644 --- a/src/code/z_scene.c +++ b/src/code/z_scene.c @@ -247,7 +247,7 @@ void func_80098904(GlobalContext* globalCtx, SceneCmd* cmd) { globalCtx->roomCtx.curRoom.unk_03 = cmd->roomBehavior.gpFlag1; globalCtx->roomCtx.curRoom.unk_02 = cmd->roomBehavior.gpFlag2 & 0xFF; globalCtx->roomCtx.curRoom.showInvisActors = (cmd->roomBehavior.gpFlag2 >> 8) & 1; - globalCtx->msgCtx.unk_E40C = (cmd->roomBehavior.gpFlag2 >> 0xA) & 1; + globalCtx->msgCtx.disableWarpSongs = (cmd->roomBehavior.gpFlag2 >> 0xA) & 1; } // Scene Command 0x0A: Mesh Header diff --git a/src/code/z_sram.c b/src/code/z_sram.c index 030529293..8dc83b8c1 100644 --- a/src/code/z_sram.c +++ b/src/code/z_sram.c @@ -22,7 +22,7 @@ typedef struct { /* 0x20 */ u8 doubleMagic; /* 0x21 */ u8 doubleDefense; /* 0x22 */ u8 bgsFlag; - /* 0x23 */ u8 ocarinaGameReward; + /* 0x23 */ u8 ocarinaGameRoundNum; /* 0x24 */ ItemEquips childEquips; /* 0x2E */ ItemEquips adultEquips; /* 0x38 */ u32 unk_38; // this may be incorrect, currently used for alignement @@ -113,7 +113,7 @@ static SavePlayerData sNewSavePlayerData = { 0, // doubleMagic 0, // doubleDefense 0, // bgsFlag - 0, // ocarinaGameReward + 0, // ocarinaGameRoundNum { { ITEM_NONE, ITEM_NONE, ITEM_NONE, ITEM_NONE }, // buttonItems { SLOT_NONE, SLOT_NONE, SLOT_NONE }, // cButtonSlots @@ -196,7 +196,7 @@ static SavePlayerData sDebugSavePlayerData = { 0, // doubleMagic 0, // doubleDefense 0, // bgsFlag - 0, // ocarinaGameReward + 0, // ocarinaGameRoundNum { { ITEM_NONE, ITEM_NONE, ITEM_NONE, ITEM_NONE }, // buttonItems { SLOT_NONE, SLOT_NONE, SLOT_NONE }, // cButtonSlots @@ -845,8 +845,8 @@ void Sram_InitSram(GameState* gameState, SramContext* sramCtx) { gSaveContext.zTargetSetting = sramCtx->readBuff[SRAM_HEADER_ZTARGET] & 1; gSaveContext.language = sramCtx->readBuff[SRAM_HEADER_LANGUAGE]; - if (gSaveContext.language > 2) { - gSaveContext.language = 0; + if (gSaveContext.language >= LANGUAGE_MAX) { + gSaveContext.language = LANGUAGE_ENG; sramCtx->readBuff[SRAM_HEADER_LANGUAGE] = gSaveContext.language; Sram_WriteSramHeader(sramCtx); } |
