From 3ff19c253e045ac7fd6b81f625703f3403bfa2f2 Mon Sep 17 00:00:00 2001 From: engineer124 <47598039+engineer124@users.noreply.github.com> Date: Tue, 7 Jun 2022 15:19:05 +1000 Subject: [PATCH] Introduce Sequence flags (#1261) * Sequence Flags * Document some seqFlags * PR Suggestion --- src/code/code_800EC960.c | 258 ++++++++++++++++++++------------------- 1 file changed, 134 insertions(+), 124 deletions(-) diff --git a/src/code/code_800EC960.c b/src/code/code_800EC960.c index 9ed6dbbb4f..bbd3435997 100644 --- a/src/code/code_800EC960.c +++ b/src/code/code_800EC960.c @@ -143,117 +143,127 @@ u8 sAudioExtraFilter2 = 0; Vec3f* sSariaBgmPtr = NULL; f32 D_80130650 = 2000.0f; u8 sSeqModeInput = 0; + +#define SEQ_FLAG_ENEMY (1 << 0) // Allows enemy bgm +#define SEQ_FLAG_FANFARE (1 << 1) +#define SEQ_FLAG_FANFARE_GANON (1 << 2) +#define SEQ_FLAG_RESTORE (1 << 3) // required for func_800F5B58 to restore a sequence after func_800F5ACC +#define SEQ_FLAG_4 (1 << 4) +#define SEQ_FLAG_5 (1 << 5) +#define SEQ_FLAG_6 (1 << 6) +#define SEQ_FLAG_NO_AMBIENCE (1 << 7) + u8 sSeqFlags[0x6E] = { - 0x2, // NA_BGM_GENERAL_SFX - 0x1, // NA_BGM_NATURE_BACKGROUND - 0, // NA_BGM_FIELD_LOGIC - 0, // NA_BGM_FIELD_INIT - 0, // NA_BGM_FIELD_DEFAULT_1 - 0, // NA_BGM_FIELD_DEFAULT_2 - 0, // NA_BGM_FIELD_DEFAULT_3 - 0, // NA_BGM_FIELD_DEFAULT_4 - 0, // NA_BGM_FIELD_DEFAULT_5 - 0, // NA_BGM_FIELD_DEFAULT_6 - 0, // NA_BGM_FIELD_DEFAULT_7 - 0, // NA_BGM_FIELD_DEFAULT_8 - 0, // NA_BGM_FIELD_DEFAULT_9 - 0, // NA_BGM_FIELD_DEFAULT_A - 0, // NA_BGM_FIELD_DEFAULT_B - 0, // NA_BGM_FIELD_ENEMY_INIT - 0, // NA_BGM_FIELD_ENEMY_1 - 0, // NA_BGM_FIELD_ENEMY_2 - 0, // NA_BGM_FIELD_ENEMY_3 - 0, // NA_BGM_FIELD_ENEMY_4 - 0, // NA_BGM_FIELD_STILL_1 - 0, // NA_BGM_FIELD_STILL_2 - 0, // NA_BGM_FIELD_STILL_3 - 0, // NA_BGM_FIELD_STILL_4 - 0x21, // NA_BGM_DUNGEON - 0x10, // NA_BGM_KAKARIKO_ADULT - 0, // NA_BGM_ENEMY - 0x88, // NA_BGM_BOSS - 0x1, // NA_BGM_INSIDE_DEKU_TREE - 0, // NA_BGM_MARKET - 0, // NA_BGM_TITLE - 0x20, // NA_BGM_LINK_HOUSE - 0, // NA_BGM_GAME_OVER - 0, // NA_BGM_BOSS_CLEAR - 0x2, // NA_BGM_ITEM_GET - 0x4, // NA_BGM_OPENING_GANON - 0x2, // NA_BGM_HEART_GET - 0x2, // NA_BGM_OCA_LIGHT - 0x1, // NA_BGM_JABU_JABU - 0x10, // NA_BGM_KAKARIKO_KID - 0, // NA_BGM_GREAT_FAIRY - 0, // NA_BGM_ZELDA_THEME - 0x1, // NA_BGM_FIRE_TEMPLE - 0x2, // NA_BGM_OPEN_TRE_BOX - 0x1, // NA_BGM_FOREST_TEMPLE - 0, // NA_BGM_COURTYARD - 0x80, // NA_BGM_GANON_TOWER - 0, // NA_BGM_LONLON - 0x80, // NA_BGM_GORON_CITY - 0, // NA_BGM_FIELD_MORNING - 0x2, // NA_BGM_SPIRITUAL_STONE - 0x2, // NA_BGM_OCA_BOLERO - 0x2, // NA_BGM_OCA_MINUET - 0x2, // NA_BGM_OCA_SERENADE - 0x2, // NA_BGM_OCA_REQUIEM - 0x2, // NA_BGM_OCA_NOCTURNE - 0x88, // NA_BGM_MINI_BOSS - 0x2, // NA_BGM_SMALL_ITEM_GET - 0, // NA_BGM_TEMPLE_OF_TIME - 0x2, // NA_BGM_EVENT_CLEAR - 0x11, // NA_BGM_KOKIRI - 0x2, // NA_BGM_OCA_FAIRY_GET - 0x1, // NA_BGM_SARIA_THEME - 0x1, // NA_BGM_SPIRIT_TEMPLE - 0, // NA_BGM_HORSE - 0, // NA_BGM_HORSE_GOAL - 0, // NA_BGM_INGO - 0x2, // NA_BGM_MEDALLION_GET - 0x2, // NA_BGM_OCA_SARIA - 0x2, // NA_BGM_OCA_EPONA - 0x2, // NA_BGM_OCA_ZELDA - 0x2, // NA_BGM_OCA_SUNS - 0x2, // NA_BGM_OCA_TIME - 0x2, // NA_BGM_OCA_STORM - 0, // NA_BGM_NAVI_OPENING - 0, // NA_BGM_DEKU_TREE_CS - 0, // NA_BGM_WINDMILL - 0, // NA_BGM_HYRULE_CS - 0x20, // NA_BGM_MINI_GAME - 0, // NA_BGM_SHEIK - 0x10, // NA_BGM_ZORA_DOMAIN - 0x2, // NA_BGM_APPEAR - 0, // NA_BGM_ADULT_LINK - 0, // NA_BGM_MASTER_SWORD - 0x4, // NA_BGM_INTRO_GANON - 0x20, // NA_BGM_SHOP - 0x40, // NA_BGM_CHAMBER_OF_SAGES - 0x40, // NA_BGM_FILE_SELECT - 0x1, // NA_BGM_ICE_CAVERN - 0x2, // NA_BGM_DOOR_OF_TIME - 0x2, // NA_BGM_OWL - 0x1, // NA_BGM_SHADOW_TEMPLE - 0x1, // NA_BGM_WATER_TEMPLE - 0x2, // NA_BGM_BRIDGE_TO_GANONS - 0, // NA_BGM_OCARINA_OF_TIME - 0x11, // NA_BGM_GERUDO_VALLEY - 0, // NA_BGM_POTION_SHOP - 0, // NA_BGM_KOTAKE_KOUME - 0x80, // NA_BGM_ESCAPE - 0, // NA_BGM_UNDERGROUND - 0x80, // NA_BGM_GANON_BATTLE_1 - 0x80, // NA_BGM_GANON_BATTLE_2 - 0, // NA_BGM_END_DEMO - 0, // NA_BGM_STAFF_1 - 0, // NA_BGM_STAFF_2 - 0, // NA_BGM_STAFF_3 - 0, // NA_BGM_STAFF_4 - 0, // NA_BGM_FIRE_BOSS - 0x8, // NA_BGM_TIMED_MINI_GAME - 0, // NA_BGM_CUTSCENE_EFFECTS + SEQ_FLAG_FANFARE, // NA_BGM_GENERAL_SFX + SEQ_FLAG_ENEMY, // NA_BGM_NATURE_BACKGROUND + 0, // NA_BGM_FIELD_LOGIC + 0, // NA_BGM_FIELD_INIT + 0, // NA_BGM_FIELD_DEFAULT_1 + 0, // NA_BGM_FIELD_DEFAULT_2 + 0, // NA_BGM_FIELD_DEFAULT_3 + 0, // NA_BGM_FIELD_DEFAULT_4 + 0, // NA_BGM_FIELD_DEFAULT_5 + 0, // NA_BGM_FIELD_DEFAULT_6 + 0, // NA_BGM_FIELD_DEFAULT_7 + 0, // NA_BGM_FIELD_DEFAULT_8 + 0, // NA_BGM_FIELD_DEFAULT_9 + 0, // NA_BGM_FIELD_DEFAULT_A + 0, // NA_BGM_FIELD_DEFAULT_B + 0, // NA_BGM_FIELD_ENEMY_INIT + 0, // NA_BGM_FIELD_ENEMY_1 + 0, // NA_BGM_FIELD_ENEMY_2 + 0, // NA_BGM_FIELD_ENEMY_3 + 0, // NA_BGM_FIELD_ENEMY_4 + 0, // NA_BGM_FIELD_STILL_1 + 0, // NA_BGM_FIELD_STILL_2 + 0, // NA_BGM_FIELD_STILL_3 + 0, // NA_BGM_FIELD_STILL_4 + SEQ_FLAG_5 | SEQ_FLAG_ENEMY, // NA_BGM_DUNGEON + SEQ_FLAG_4, // NA_BGM_KAKARIKO_ADULT + 0, // NA_BGM_ENEMY + SEQ_FLAG_NO_AMBIENCE | SEQ_FLAG_RESTORE, // NA_BGM_BOSS + SEQ_FLAG_ENEMY, // NA_BGM_INSIDE_DEKU_TREE + 0, // NA_BGM_MARKET + 0, // NA_BGM_TITLE + SEQ_FLAG_5, // NA_BGM_LINK_HOUSE + 0, // NA_BGM_GAME_OVER + 0, // NA_BGM_BOSS_CLEAR + SEQ_FLAG_FANFARE, // NA_BGM_ITEM_GET + SEQ_FLAG_FANFARE_GANON, // NA_BGM_OPENING_GANON + SEQ_FLAG_FANFARE, // NA_BGM_HEART_GET + SEQ_FLAG_FANFARE, // NA_BGM_OCA_LIGHT + SEQ_FLAG_ENEMY, // NA_BGM_JABU_JABU + SEQ_FLAG_4, // NA_BGM_KAKARIKO_KID + 0, // NA_BGM_GREAT_FAIRY + 0, // NA_BGM_ZELDA_THEME + SEQ_FLAG_ENEMY, // NA_BGM_FIRE_TEMPLE + SEQ_FLAG_FANFARE, // NA_BGM_OPEN_TRE_BOX + SEQ_FLAG_ENEMY, // NA_BGM_FOREST_TEMPLE + 0, // NA_BGM_COURTYARD + SEQ_FLAG_NO_AMBIENCE, // NA_BGM_GANON_TOWER + 0, // NA_BGM_LONLON + SEQ_FLAG_NO_AMBIENCE, // NA_BGM_GORON_CITY + 0, // NA_BGM_FIELD_MORNING + SEQ_FLAG_FANFARE, // NA_BGM_SPIRITUAL_STONE + SEQ_FLAG_FANFARE, // NA_BGM_OCA_BOLERO + SEQ_FLAG_FANFARE, // NA_BGM_OCA_MINUET + SEQ_FLAG_FANFARE, // NA_BGM_OCA_SERENADE + SEQ_FLAG_FANFARE, // NA_BGM_OCA_REQUIEM + SEQ_FLAG_FANFARE, // NA_BGM_OCA_NOCTURNE + SEQ_FLAG_NO_AMBIENCE | SEQ_FLAG_RESTORE, // NA_BGM_MINI_BOSS + SEQ_FLAG_FANFARE, // NA_BGM_SMALL_ITEM_GET + 0, // NA_BGM_TEMPLE_OF_TIME + SEQ_FLAG_FANFARE, // NA_BGM_EVENT_CLEAR + SEQ_FLAG_4 | SEQ_FLAG_ENEMY, // NA_BGM_KOKIRI + SEQ_FLAG_FANFARE, // NA_BGM_OCA_FAIRY_GET + SEQ_FLAG_ENEMY, // NA_BGM_SARIA_THEME + SEQ_FLAG_ENEMY, // NA_BGM_SPIRIT_TEMPLE + 0, // NA_BGM_HORSE + 0, // NA_BGM_HORSE_GOAL + 0, // NA_BGM_INGO + SEQ_FLAG_FANFARE, // NA_BGM_MEDALLION_GET + SEQ_FLAG_FANFARE, // NA_BGM_OCA_SARIA + SEQ_FLAG_FANFARE, // NA_BGM_OCA_EPONA + SEQ_FLAG_FANFARE, // NA_BGM_OCA_ZELDA + SEQ_FLAG_FANFARE, // NA_BGM_OCA_SUNS + SEQ_FLAG_FANFARE, // NA_BGM_OCA_TIME + SEQ_FLAG_FANFARE, // NA_BGM_OCA_STORM + 0, // NA_BGM_NAVI_OPENING + 0, // NA_BGM_DEKU_TREE_CS + 0, // NA_BGM_WINDMILL + 0, // NA_BGM_HYRULE_CS + SEQ_FLAG_5, // NA_BGM_MINI_GAME + 0, // NA_BGM_SHEIK + SEQ_FLAG_4, // NA_BGM_ZORA_DOMAIN + SEQ_FLAG_FANFARE, // NA_BGM_APPEAR + 0, // NA_BGM_ADULT_LINK + 0, // NA_BGM_MASTER_SWORD + SEQ_FLAG_FANFARE_GANON, // NA_BGM_INTRO_GANON + SEQ_FLAG_5, // NA_BGM_SHOP + SEQ_FLAG_6, // NA_BGM_CHAMBER_OF_SAGES + SEQ_FLAG_6, // NA_BGM_FILE_SELECT + SEQ_FLAG_ENEMY, // NA_BGM_ICE_CAVERN + SEQ_FLAG_FANFARE, // NA_BGM_DOOR_OF_TIME + SEQ_FLAG_FANFARE, // NA_BGM_OWL + SEQ_FLAG_ENEMY, // NA_BGM_SHADOW_TEMPLE + SEQ_FLAG_ENEMY, // NA_BGM_WATER_TEMPLE + SEQ_FLAG_FANFARE, // NA_BGM_BRIDGE_TO_GANONS + 0, // NA_BGM_OCARINA_OF_TIME + SEQ_FLAG_4 | SEQ_FLAG_ENEMY, // NA_BGM_GERUDO_VALLEY + 0, // NA_BGM_POTION_SHOP + 0, // NA_BGM_KOTAKE_KOUME + SEQ_FLAG_NO_AMBIENCE, // NA_BGM_ESCAPE + 0, // NA_BGM_UNDERGROUND + SEQ_FLAG_NO_AMBIENCE, // NA_BGM_GANON_BATTLE_1 + SEQ_FLAG_NO_AMBIENCE, // NA_BGM_GANON_BATTLE_2 + 0, // NA_BGM_END_DEMO + 0, // NA_BGM_STAFF_1 + 0, // NA_BGM_STAFF_2 + 0, // NA_BGM_STAFF_3 + 0, // NA_BGM_STAFF_4 + 0, // NA_BGM_FIRE_BOSS + SEQ_FLAG_RESTORE, // NA_BGM_TIMED_MINI_GAME + 0, // NA_BGM_CUTSCENE_EFFECTS }; s8 sSpecReverbs[20] = { 0, 0, 0, 0, 0, 0, 0, 40, 0, 15, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; @@ -4581,7 +4591,7 @@ void func_800F5550(u16 seqId) { Audio_QueueCmdS32(0xF8000000, 0); } - if ((sSeqFlags[D_80130630] & 0x20) && sSeqFlags[(seqId & 0xFF) & 0xFF] & 0x10) { + if ((sSeqFlags[D_80130630] & SEQ_FLAG_5) && sSeqFlags[(seqId & 0xFF) & 0xFF] & SEQ_FLAG_4) { if ((D_8013062C & 0x3F) != 0) { sp27 = 0x1E; @@ -4591,9 +4601,9 @@ void func_800F5550(u16 seqId) { D_8013062C = 0; } else { - nv = (sSeqFlags[(seqId & 0xFF) & 0xFF] & 0x40) ? 1 : 0xFF; + nv = (sSeqFlags[(seqId & 0xFF) & 0xFF] & SEQ_FLAG_6) ? 1 : 0xFF; func_800F5E18(SEQ_PLAYER_BGM_MAIN, seqId, 0, 7, nv); - if (!(sSeqFlags[seqId] & 0x20)) { + if (!(sSeqFlags[seqId] & SEQ_FLAG_5)) { D_8013062C = 0xC0; } } @@ -4607,7 +4617,7 @@ void func_800F56A8(void) { temp_v0 = func_800FA0B4(SEQ_PLAYER_BGM_MAIN); bvar = temp_v0 & 0xFF; - if ((temp_v0 != NA_BGM_DISABLED) && (sSeqFlags[bvar] & 0x10)) { + if ((temp_v0 != NA_BGM_DISABLED) && (sSeqFlags[bvar] & SEQ_FLAG_4)) { if (D_8013062C != 0xC0) { D_8013062C = gAudioContext.seqPlayers[SEQ_PLAYER_BGM_MAIN].soundScriptIO[3]; } else { @@ -4640,9 +4650,9 @@ void func_800F5918(void) { void func_800F595C(u16 arg0) { u8 arg0b = arg0 & 0xFF; - if (sSeqFlags[arg0b] & 2) { + if (sSeqFlags[arg0b] & SEQ_FLAG_FANFARE) { Audio_PlayFanfare(arg0); - } else if (sSeqFlags[arg0b] & 4) { + } else if (sSeqFlags[arg0b] & SEQ_FLAG_FANFARE_GANON) { Audio_StartSeq(SEQ_PLAYER_FANFARE, 0, arg0); } else { @@ -4654,9 +4664,9 @@ void func_800F595C(u16 arg0) { void func_800F59E8(u16 arg0) { u8 arg0b = arg0 & 0xFF; - if (sSeqFlags[arg0b] & 2) { + if (sSeqFlags[arg0b] & SEQ_FLAG_FANFARE) { Audio_SeqCmd1(SEQ_PLAYER_FANFARE, 0); - } else if (sSeqFlags[arg0b] & 4) { + } else if (sSeqFlags[arg0b] & SEQ_FLAG_FANFARE_GANON) { Audio_SeqCmd1(SEQ_PLAYER_FANFARE, 0); } else { Audio_SeqCmd1(SEQ_PLAYER_BGM_MAIN, 0); @@ -4666,9 +4676,9 @@ void func_800F59E8(u16 arg0) { s32 func_800F5A58(u8 arg0) { u8 phi_a1 = 0; - if (sSeqFlags[arg0 & 0xFF] & 2) { + if (sSeqFlags[arg0 & 0xFF] & SEQ_FLAG_FANFARE) { phi_a1 = 1; - } else if (sSeqFlags[arg0 & 0xFF] & 4) { + } else if (sSeqFlags[arg0 & 0xFF] & SEQ_FLAG_FANFARE_GANON) { phi_a1 = 1; } @@ -4703,7 +4713,7 @@ void func_800F5ACC(u16 seqId) { */ void func_800F5B58(void) { if ((func_800FA0B4(SEQ_PLAYER_BGM_MAIN) != NA_BGM_DISABLED) && (sPrevMainBgmSeqId != NA_BGM_DISABLED) && - (sSeqFlags[func_800FA0B4(SEQ_PLAYER_BGM_MAIN) & 0xFF] & 8)) { + (sSeqFlags[func_800FA0B4(SEQ_PLAYER_BGM_MAIN) & 0xFF] & SEQ_FLAG_RESTORE)) { if (sPrevMainBgmSeqId == NA_BGM_DISABLED) { Audio_SeqCmd1(SEQ_PLAYER_BGM_MAIN, 0); } else { @@ -4809,7 +4819,7 @@ void Audio_SetSequenceMode(u8 seqMode) { seqMode = SEQ_MODE_IGNORE; } - if ((seqId == NA_BGM_DISABLED) || (sSeqFlags[(u8)(seqId & 0xFF)] & 1) || + if ((seqId == NA_BGM_DISABLED) || (sSeqFlags[(u8)(seqId & 0xFF)] & SEQ_FLAG_ENEMY) || ((sPrevSeqMode & 0x7F) == SEQ_MODE_ENEMY)) { if (seqMode != (sPrevSeqMode & 0x7F)) { if (seqMode == SEQ_MODE_ENEMY) { @@ -5231,8 +5241,8 @@ void Audio_PlayNatureAmbienceSequence(u8 natureAmbienceId) { u8 port; u8 val; - if ((D_8016E750[SEQ_PLAYER_BGM_MAIN].unk_254 == NA_BGM_DISABLED) || - !(sSeqFlags[((u8)D_8016E750[SEQ_PLAYER_BGM_MAIN].unk_254) & 0xFF] & 0x80)) { + if (!((D_8016E750[SEQ_PLAYER_BGM_MAIN].unk_254 != NA_BGM_DISABLED) && + (sSeqFlags[((u8)D_8016E750[SEQ_PLAYER_BGM_MAIN].unk_254) & 0xFF] & SEQ_FLAG_NO_AMBIENCE))) { Audio_StartNatureAmbienceSequence(sNatureAmbienceDataIO[natureAmbienceId].playerIO, sNatureAmbienceDataIO[natureAmbienceId].channelMask);