From 9a7c63c46cfcb3531c8ae1c0a555b4978556537f Mon Sep 17 00:00:00 2001 From: GaryOderNichts <12049776+GaryOderNichts@users.noreply.github.com> Date: Sat, 2 Apr 2022 13:47:22 +0200 Subject: [PATCH 1/3] Allocate aligned heaps --- soh/include/functions.h | 3 +++ soh/include/variables.h | 4 ++-- soh/src/buffers/heaps.c | 45 +++++++++++++++++++++++++++++++++++++---- soh/src/code/main.c | 3 +++ 4 files changed, 49 insertions(+), 6 deletions(-) diff --git a/soh/include/functions.h b/soh/include/functions.h index 060022ac9..a4b1a9a99 100644 --- a/soh/include/functions.h +++ b/soh/include/functions.h @@ -2397,6 +2397,9 @@ void FileChoose_Destroy(GameState* thisx); char* SetQuote(); +void Heaps_Alloc(void); +void Heaps_Free(void); + #ifdef __cplusplus }; #endif diff --git a/soh/include/variables.h b/soh/include/variables.h index 80e3b792d..b58166b60 100644 --- a/soh/include/variables.h +++ b/soh/include/variables.h @@ -237,8 +237,8 @@ extern void(*D_801755D0)(void); extern u8 gGfxSPTaskYieldBuffer[OS_YIELD_DATA_SIZE]; // 0xC00 bytes extern u8 gGfxSPTaskStack[0x400]; // 0x400 bytes extern GfxPool gGfxPools[2]; // 0x24820 bytes - extern u8 gAudioHeap[0x38000]; // 0x38000 bytes - extern u8 gSystemHeap[]; + extern u8* gAudioHeap; + extern u8* gSystemHeap; #ifdef __cplusplus }; diff --git a/soh/src/buffers/heaps.c b/soh/src/buffers/heaps.c index 4309acd18..6d162bc9e 100644 --- a/soh/src/buffers/heaps.c +++ b/soh/src/buffers/heaps.c @@ -1,7 +1,44 @@ #include "z64.h" +#include +#include -// 0x38000 bytes -u8 gAudioHeap[0x38000]; +#ifndef _MSC_VER +#include +#endif -//u8 gSystemHeap[UNK_SIZE]; -u8 gSystemHeap[1024 * 1024 * 128]; +#define AUDIO_HEAP_SIZE 0x38000 +#define SYSTEM_HEAP_SIZE (1024 * 1024 * 128) + +u8* gAudioHeap; + +u8* gSystemHeap; + +void Heaps_Alloc(void) +{ +#ifdef _MSC_VER + gAudioHeap = (u8*)_aligned_malloc(AUDIO_HEAP_SIZE, 16); + gSystemHeap = (u8*)_aligned_malloc(SYSTEM_HEAP_SIZE, 16); +#elif defined(_POSIX_VERSION) && (_POSIX_VERSION >= 200112L) + if (posix_memalign((void**)&gAudioHeap, 16, AUDIO_HEAP_SIZE) != 0) + gAudioHeap = NULL; + if (posix_memalign((void**)&gSystemHeap, 16, SYSTEM_HEAP_SIZE) != 0) + gSystemHeap = NULL; +#else + gAudioHeap = (u8*)memalign(16, AUDIO_HEAP_SIZE); + gSystemHeap = (u8*)memalign(16, SYSTEM_HEAP_SIZE); +#endif + + assert(gAudioHeap != NULL); + assert(gSystemHeap != NULL); +} + +void Heaps_Free(void) +{ +#ifdef _MSC_VER + _aligned_free(gAudioHeap); + _aligned_free(gSystemHeap); +#else + free(gAudioHeap); + free(gSystemHeap); +#endif +} diff --git a/soh/src/code/main.c b/soh/src/code/main.c index eaaa7b388..0680aad3e 100644 --- a/soh/src/code/main.c +++ b/soh/src/code/main.c @@ -63,6 +63,7 @@ void Main(void* arg) { PreNmiBuff_Init(gAppNmiBufferPtr); Fault_Init(); SysCfb_Init(0); + Heaps_Alloc(); sysHeap = gSystemHeap; fb = SysCfb_GetFbPtr(0); gSystemHeapSize = 1024 * 1024 * 4; @@ -131,4 +132,6 @@ void Main(void* arg) { osDestroyThread(&sGraphThread); func_800FBFD8(); osSyncPrintf("mainproc 実行終了\n"); // "End of execution" + + Heaps_Free(); } From beb454d0002c9e6ef5c7f708ae7f088c15aa59eb Mon Sep 17 00:00:00 2001 From: GaryOderNichts <12049776+GaryOderNichts@users.noreply.github.com> Date: Mon, 11 Apr 2022 19:46:42 +0200 Subject: [PATCH 2/3] Formatting fixes --- soh/src/buffers/heaps.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/soh/src/buffers/heaps.c b/soh/src/buffers/heaps.c index 6d162bc9e..d09f86e72 100644 --- a/soh/src/buffers/heaps.c +++ b/soh/src/buffers/heaps.c @@ -10,22 +10,21 @@ #define SYSTEM_HEAP_SIZE (1024 * 1024 * 128) u8* gAudioHeap; - u8* gSystemHeap; void Heaps_Alloc(void) { #ifdef _MSC_VER - gAudioHeap = (u8*)_aligned_malloc(AUDIO_HEAP_SIZE, 16); - gSystemHeap = (u8*)_aligned_malloc(SYSTEM_HEAP_SIZE, 16); + gAudioHeap = (u8*)_aligned_malloc(AUDIO_HEAP_SIZE, 0x10); + gSystemHeap = (u8*)_aligned_malloc(SYSTEM_HEAP_SIZE, 0x10); #elif defined(_POSIX_VERSION) && (_POSIX_VERSION >= 200112L) - if (posix_memalign((void**)&gAudioHeap, 16, AUDIO_HEAP_SIZE) != 0) + if (posix_memalign((void**)&gAudioHeap, 0x10, AUDIO_HEAP_SIZE) != 0) gAudioHeap = NULL; - if (posix_memalign((void**)&gSystemHeap, 16, SYSTEM_HEAP_SIZE) != 0) + if (posix_memalign((void**)&gSystemHeap, 0x10, SYSTEM_HEAP_SIZE) != 0) gSystemHeap = NULL; #else - gAudioHeap = (u8*)memalign(16, AUDIO_HEAP_SIZE); - gSystemHeap = (u8*)memalign(16, SYSTEM_HEAP_SIZE); + gAudioHeap = (u8*)memalign(0x10, AUDIO_HEAP_SIZE); + gSystemHeap = (u8*)memalign(0x10, SYSTEM_HEAP_SIZE); #endif assert(gAudioHeap != NULL); From 03a5c7ed29db889344a8275c4c0a8c7ae1480779 Mon Sep 17 00:00:00 2001 From: Josh Bodner <30329717+jbodner09@users.noreply.github.com> Date: Mon, 11 Apr 2022 14:06:55 -0700 Subject: [PATCH 3/3] Added DPad support to ocarina and text prompts (#137) * Added DPad support to ocarina playing and text choice selection. * Wrap changes in CVar * Fix mapping not updating if CVar is changed in-game * Remove unnecessary const_cast * Fixed transparent texture making framebuffers also transparent in D3D11. (#84) This happened with the Mirror Shield in the inventory screen preview. * Add save editor * Added DPad support to ocarina playing and text choice selection. * Fixing rebase conflict * Fix mapping not updating if CVar is changed in-game * Remove unnecessary const_cast * Added DPad support to file selection and pause screens (#124) * Added DPad support to file selection and pause screens * Wrap changes behind CVar * Fix merge conflict for real * Remove unnecessary const_cast * Fixed transparent texture making framebuffers also transparent in D3D11. (#84) This happened with the Mirror Shield in the inventory screen preview. * Add save editor * Added DPad support to file selection and pause screens * Fixing rebase conflict * Remove unnecessary const_cast Co-authored-by: MaikelChan Co-authored-by: rozlette * Added DPad support to ocarina playing and text choice selection. * Fixing rebase conflict again * Fix mapping not updating if CVar is changed in-game Co-authored-by: MaikelChan Co-authored-by: rozlette --- libultraship/libultraship/GameSettings.cpp | 4 ++ libultraship/libultraship/GameSettings.h | 1 + libultraship/libultraship/SohImGuiImpl.cpp | 5 +++ soh/src/code/code_800EC960.c | 46 +++++++++++++--------- soh/src/code/z_message_PAL.c | 7 ++-- 5 files changed, 41 insertions(+), 22 deletions(-) diff --git a/libultraship/libultraship/GameSettings.cpp b/libultraship/libultraship/GameSettings.cpp index 28f4b23cb..c3294d9e3 100644 --- a/libultraship/libultraship/GameSettings.cpp +++ b/libultraship/libultraship/GameSettings.cpp @@ -92,6 +92,9 @@ namespace Game { Settings.controller.dpad_pause_name = stob(Conf[ControllerSection]["dpad_pause_name"]); CVar_SetS32("gDpadPauseName", Settings.controller.dpad_pause_name); + + Settings.controller.dpad_ocarina_text = stob(Conf[ControllerSection]["dpad_ocarina_text"]); + CVar_SetS32("gDpadOcarinaText", Settings.controller.dpad_ocarina_text); // Cheats Settings.cheats.debug_mode = stob(Conf[CheatSection]["debug_mode"]); @@ -153,6 +156,7 @@ namespace Game { Conf[ControllerSection]["input_scale"] = std::to_string(Settings.controller.input_scale); Conf[ControllerSection]["input_enabled"] = std::to_string(Settings.controller.input_enabled); Conf[ControllerSection]["dpad_pause_name"] = std::to_string(Settings.controller.dpad_pause_name); + Conf[ControllerSection]["dpad_ocarina_text"] = std::to_string(Settings.controller.dpad_ocarina_text); // Cheats Conf[CheatSection]["debug_mode"] = std::to_string(Settings.cheats.debug_mode); diff --git a/libultraship/libultraship/GameSettings.h b/libultraship/libultraship/GameSettings.h index 15ebdad16..8e1293c65 100644 --- a/libultraship/libultraship/GameSettings.h +++ b/libultraship/libultraship/GameSettings.h @@ -35,6 +35,7 @@ struct SoHConfigType { float gyroDriftY = 0.0f; bool input_enabled = false; bool dpad_pause_name = false; + bool dpad_ocarina_text = false; } controller; // Cheats diff --git a/libultraship/libultraship/SohImGuiImpl.cpp b/libultraship/libultraship/SohImGuiImpl.cpp index cef156246..7bdf4859a 100644 --- a/libultraship/libultraship/SohImGuiImpl.cpp +++ b/libultraship/libultraship/SohImGuiImpl.cpp @@ -360,6 +360,11 @@ namespace SohImGui { needs_save = true; } + if (ImGui::Checkbox("DPad Support in Ocarina and Text Choice", &Game::Settings.controller.dpad_ocarina_text)) { + CVar_SetS32("gDpadOcarinaText", Game::Settings.controller.dpad_ocarina_text); + needs_save = true; + } + ImGui::EndMenu(); } diff --git a/soh/src/code/code_800EC960.c b/soh/src/code/code_800EC960.c index 5efa93167..23d1ba375 100644 --- a/soh/src/code/code_800EC960.c +++ b/soh/src/code/code_800EC960.c @@ -824,10 +824,12 @@ NatureAmbienceDataIO sNatureAmbienceDataIO[20] = { }, }; -u32 sOcarinaAllowedBtnMask = 0x800F; -s32 sOcarinaABtnMap = 0x8000; -s32 sOcarinaCUPBtnMap = 8; -s32 sOcarinaCDownBtnMap = 4; +u32 sOcarinaAllowedBtnMask = (BTN_A | BTN_CUP | BTN_CDOWN | BTN_CLEFT | BTN_CRIGHT); +s32 sOcarinaABtnMap = BTN_A; +s32 sOcarinaCUPBtnMap = BTN_CUP; +s32 sOcarinaCDownBtnMap = BTN_CDOWN; +s32 sOcarinaCLeftBtnMap = BTN_CLEFT; +s32 sOcarinaCRightBtnMap = BTN_CRIGHT; u8 sOcarinaInpEnabled = 0; s8 D_80130F10 = 0; // "OCA", ocarina active? u8 sCurOcarinaBtnVal = 0xFF; @@ -1245,19 +1247,23 @@ void func_800F56A8(void); void Audio_PlayNatureAmbienceSequence(u8 natureAmbienceId); s32 Audio_SetGanonDistVol(u8 targetVol); -void func_800EC960(u8 custom) { - if (!custom) { - osSyncPrintf("AUDIO : Ocarina Control Assign Normal\n"); +// Function originally not called, so repurposing for DPad input +void func_800EC960(u8 dpad) { + if (dpad) { + sOcarinaAllowedBtnMask = + (BTN_A | BTN_CUP | BTN_CDOWN | BTN_CLEFT | BTN_CRIGHT | BTN_DUP | BTN_DDOWN | BTN_DLEFT | BTN_DRIGHT); + sOcarinaABtnMap = BTN_A; + sOcarinaCUPBtnMap = BTN_CUP | BTN_DUP; + sOcarinaCDownBtnMap = BTN_CDOWN | BTN_DDOWN; + sOcarinaCLeftBtnMap = BTN_CLEFT | BTN_DLEFT; + sOcarinaCRightBtnMap = BTN_CRIGHT | BTN_DRIGHT; + } else { sOcarinaAllowedBtnMask = (BTN_A | BTN_CUP | BTN_CDOWN | BTN_CLEFT | BTN_CRIGHT); sOcarinaABtnMap = BTN_A; sOcarinaCUPBtnMap = BTN_CUP; sOcarinaCDownBtnMap = BTN_CDOWN; - } else { - osSyncPrintf("AUDIO : Ocarina Control Assign Custom\n"); - sOcarinaAllowedBtnMask = (BTN_A | BTN_B | BTN_CDOWN | BTN_CLEFT | BTN_CRIGHT); - sOcarinaABtnMap = BTN_B; - sOcarinaCUPBtnMap = BTN_CDOWN; - sOcarinaCDownBtnMap = BTN_A; + sOcarinaCLeftBtnMap = BTN_CLEFT; + sOcarinaCRightBtnMap = BTN_CRIGHT; } } @@ -1542,6 +1548,7 @@ void func_800ED200(void) { void func_800ED458(s32 arg0) { u32 phi_v1_2; + bool dpad = CVar_GetS32("gDpadOcarinaText", 0); if (D_80130F3C != 0 && D_80131880 != 0) { D_80131880--; @@ -1561,6 +1568,7 @@ void func_800ED458(s32 arg0) { D_8016BA18 &= phi_v1_2; } + func_800EC960(dpad); if (D_8016BA18 & sOcarinaABtnMap) { osSyncPrintf("Presss NA_KEY_D4 %08x\n", sOcarinaABtnMap); sCurOcarinaBtnVal = 2; @@ -1569,12 +1577,12 @@ void func_800ED458(s32 arg0) { osSyncPrintf("Presss NA_KEY_F4 %08x\n", sOcarinaCDownBtnMap); sCurOcarinaBtnVal = 5; sCurOcarinaBtnIdx = 1; - } else if (D_8016BA18 & 1) { - osSyncPrintf("Presss NA_KEY_A4 %08x\n", 1); + } else if (D_8016BA18 & sOcarinaCRightBtnMap) { + osSyncPrintf("Presss NA_KEY_A4 %08x\n", sOcarinaCRightBtnMap); sCurOcarinaBtnVal = 9; sCurOcarinaBtnIdx = 2; - } else if (D_8016BA18 & 2) { - osSyncPrintf("Presss NA_KEY_B4 %08x\n", 2); + } else if (D_8016BA18 & sOcarinaCLeftBtnMap) { + osSyncPrintf("Presss NA_KEY_B4 %08x\n", sOcarinaCRightBtnMap); sCurOcarinaBtnVal = 0xB; sCurOcarinaBtnIdx = 3; } else if (D_8016BA18 & sOcarinaCUPBtnMap) { @@ -1671,7 +1679,7 @@ void Audio_OcaSetSongPlayback(s8 songIdxPlusOne, s8 playbackState) { void Audio_OcaPlayback(void) { u32 noteTimerStep; - u32 nextNoteTimerStep; + u32 nextNoteTimerStep = 0; if (sPlaybackState != 0) { if (sStaffPlaybackPos == 0) { @@ -4772,7 +4780,7 @@ void Audio_SetCodeReverb(s8 reverb) { } void func_800F6700(s8 arg0) { - s8 sp1F; + s8 sp1F = 0; switch (arg0) { case 0: diff --git a/soh/src/code/z_message_PAL.c b/soh/src/code/z_message_PAL.c index 4979f047c..43b0fcc12 100644 --- a/soh/src/code/z_message_PAL.c +++ b/soh/src/code/z_message_PAL.c @@ -203,8 +203,9 @@ void Message_HandleChoiceSelection(GlobalContext* globalCtx, u8 numChoices) { static s16 sAnalogStickHeld = false; MessageContext* msgCtx = &globalCtx->msgCtx; Input* input = &globalCtx->state.input[0]; + bool dpad = CVar_GetS32("gDpadOcarinaText", 0); - if (input->rel.stick_y >= 30 && !sAnalogStickHeld) { + if ((input->rel.stick_y >= 30 && !sAnalogStickHeld) || (dpad && CHECK_BTN_ALL(input->press.button, BTN_DUP))) { sAnalogStickHeld = true; msgCtx->choiceIndex--; if (msgCtx->choiceIndex > 128) { @@ -212,7 +213,7 @@ void Message_HandleChoiceSelection(GlobalContext* globalCtx, u8 numChoices) { } else { Audio_PlaySoundGeneral(NA_SE_SY_CURSOR, &D_801333D4, 4, &D_801333E0, &D_801333E0, &D_801333E8); } - } else if (input->rel.stick_y <= -30 && !sAnalogStickHeld) { + } else if ((input->rel.stick_y <= -30 && !sAnalogStickHeld) || (dpad && CHECK_BTN_ALL(input->press.button, BTN_DDOWN))) { sAnalogStickHeld = true; msgCtx->choiceIndex++; if (msgCtx->choiceIndex > numChoices) { @@ -3032,7 +3033,7 @@ void Message_Update(GlobalContext* globalCtx) { Input* input = &globalCtx->state.input[0]; s16 var; s16 focusScreenPosX; - s16 averageY; + s16 averageY = 0; s16 playerFocusScreenPosY; s16 actorFocusScreenPosY;