From 67e64c58c1a02ec44d27e0f4c663397b1979c5b5 Mon Sep 17 00:00:00 2001 From: Patrick12115 <115201185+Patrick12115@users.noreply.github.com> Date: Sat, 25 May 2024 13:17:07 -0400 Subject: [PATCH] [Enhancement] Dpad Ocarina (#324) * Add dpad ocarina option Co-authored-by: Patrick12115 <115201185+Patrick12115@users.noreply.github.com> * uint8_t --------- Co-authored-by: Garrett Cox --- mm/2s2h/BenGui/BenMenuBar.cpp | 2 ++ mm/src/audio/code_8019AF00.c | 22 ++++++++++++++-------- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/mm/2s2h/BenGui/BenMenuBar.cpp b/mm/2s2h/BenGui/BenMenuBar.cpp index f297012fc..ce0d12a05 100644 --- a/mm/2s2h/BenGui/BenMenuBar.cpp +++ b/mm/2s2h/BenGui/BenMenuBar.cpp @@ -548,6 +548,8 @@ void DrawEnhancementsMenu() { { .tooltip = "Enables the partially implemented Sun's Song. RIGHT-DOWN-UP-RIGHT-DOWN-UP to play it. " "This song will make time move very fast until either Link moves to a different scene, " "or when the time switches to a new time period." }); + UIWidgets::CVarCheckbox("Dpad Ocarina", "gEnhancements.Playback.DpadOcarina", + { .tooltip = "Enables using the Dpad for Ocarina playback." }); UIWidgets::CVarCheckbox("Prevent Dropped Ocarina Inputs", "gEnhancements.Playback.NoDropOcarinaInput", { .tooltip = "Prevent dropping inputs when playing the ocarina quickly" }); diff --git a/mm/src/audio/code_8019AF00.c b/mm/src/audio/code_8019AF00.c index 85badd038..4ad272c41 100644 --- a/mm/src/audio/code_8019AF00.c +++ b/mm/src/audio/code_8019AF00.c @@ -2595,14 +2595,18 @@ void AudioOcarina_PlayControllerInput(u8 isOcarinaSfxSuppressedWhenCancelled) { // Ensures the button pressed to start the ocarina does not also play an ocarina note if ((sOcarinaInputButtonStart == 0) || - ((sOcarinaInputButtonStart & (BTN_A | BTN_CRIGHT | BTN_CLEFT | BTN_CDOWN | BTN_CUP)) != - (sOcarinaInputButtonCur & (BTN_A | BTN_CRIGHT | BTN_CLEFT | BTN_CDOWN | BTN_CUP)))) { + ((sOcarinaInputButtonStart & + (BTN_A | BTN_CRIGHT | BTN_CLEFT | BTN_CDOWN | BTN_CUP | BTN_DRIGHT | BTN_DLEFT | BTN_DDOWN | BTN_DUP)) != + (sOcarinaInputButtonCur & + (BTN_A | BTN_CRIGHT | BTN_CLEFT | BTN_CDOWN | BTN_CUP | BTN_DRIGHT | BTN_DLEFT | BTN_DDOWN | BTN_DUP)))) { sOcarinaInputButtonStart = 0; if (1) {} sCurOcarinaPitch = OCARINA_PITCH_NONE; sCurOcarinaButtonIndex = OCARINA_BTN_INVALID; - ocarinaBtnsHeld = (sOcarinaInputButtonCur & (BTN_A | BTN_CRIGHT | BTN_CLEFT | BTN_CDOWN | BTN_CUP)) & - (sOcarinaInputButtonPrev & (BTN_A | BTN_CRIGHT | BTN_CLEFT | BTN_CDOWN | BTN_CUP)); + ocarinaBtnsHeld = (sOcarinaInputButtonCur & (BTN_A | BTN_CRIGHT | BTN_CLEFT | BTN_CDOWN | BTN_CUP | BTN_DRIGHT | + BTN_DLEFT | BTN_DDOWN | BTN_DUP)) & + (sOcarinaInputButtonPrev & (BTN_A | BTN_CRIGHT | BTN_CLEFT | BTN_CDOWN | BTN_CUP | + BTN_DRIGHT | BTN_DLEFT | BTN_DDOWN | BTN_DUP)); if (!(sOcarinaInputButtonPress & ocarinaBtnsHeld) && (sOcarinaInputButtonCur != 0)) { sOcarinaInputButtonPress = sOcarinaInputButtonCur; @@ -2610,24 +2614,26 @@ void AudioOcarina_PlayControllerInput(u8 isOcarinaSfxSuppressedWhenCancelled) { sOcarinaInputButtonPress &= ocarinaBtnsHeld; } + uint8_t dpadCvarActive = CVarGetInteger("gEnhancements.Playback.DpadOcarina", 0); + // Interprets and transforms controller input into ocarina buttons and notes if (CHECK_BTN_ANY(sOcarinaInputButtonPress, BTN_A)) { sCurOcarinaPitch = OCARINA_PITCH_D4; sCurOcarinaButtonIndex = OCARINA_BTN_A; - } else if (CHECK_BTN_ANY(sOcarinaInputButtonPress, BTN_CDOWN)) { + } else if (CHECK_BTN_ANY(sOcarinaInputButtonPress, BTN_CDOWN | (dpadCvarActive ? BTN_DDOWN : 0))) { sCurOcarinaPitch = OCARINA_PITCH_F4; sCurOcarinaButtonIndex = OCARINA_BTN_C_DOWN; - } else if (CHECK_BTN_ANY(sOcarinaInputButtonPress, BTN_CRIGHT)) { + } else if (CHECK_BTN_ANY(sOcarinaInputButtonPress, BTN_CRIGHT | (dpadCvarActive ? BTN_DRIGHT : 0))) { sCurOcarinaPitch = OCARINA_PITCH_A4; sCurOcarinaButtonIndex = OCARINA_BTN_C_RIGHT; - } else if (CHECK_BTN_ANY(sOcarinaInputButtonPress, BTN_CLEFT)) { + } else if (CHECK_BTN_ANY(sOcarinaInputButtonPress, BTN_CLEFT | (dpadCvarActive ? BTN_DLEFT : 0))) { sCurOcarinaPitch = OCARINA_PITCH_B4; sCurOcarinaButtonIndex = OCARINA_BTN_C_LEFT; - } else if (CHECK_BTN_ANY(sOcarinaInputButtonPress, BTN_CUP)) { + } else if (CHECK_BTN_ANY(sOcarinaInputButtonPress, BTN_CUP | (dpadCvarActive ? BTN_DUP : 0))) { sCurOcarinaPitch = OCARINA_PITCH_D5; sCurOcarinaButtonIndex = OCARINA_BTN_C_UP; }