From ba7be37093e40bc5b3fea558c6635fc0997a80c0 Mon Sep 17 00:00:00 2001 From: Lemeon <66488505+ThothWhatsThis@users.noreply.github.com> Date: Sun, 21 Jan 2024 19:17:42 +0100 Subject: [PATCH 01/10] True Match sub_080A5F48 matched sub_080A5F48 using typecast on Div. --- src/menu/pauseMenu.c | 59 +++++++++++++++++++++++++------------------- 1 file changed, 34 insertions(+), 25 deletions(-) diff --git a/src/menu/pauseMenu.c b/src/menu/pauseMenu.c index 3877c6893..8ed35cfd4 100644 --- a/src/menu/pauseMenu.c +++ b/src/menu/pauseMenu.c @@ -1232,15 +1232,26 @@ bool32 sub_080A5F24(void) { return result; } -void sub_080A5F48(Item item, u32 param_2) { - extern u32 gSprite_082E68F4[]; - u32 ammoCount; - u32 tensDigit; - u8* puVar2; - u32 temp1; +typedef union{ + struct{ + s32 v1; + s32 v2; + } values; + u64 raw; +} DoubleReturnValue; + +void sub_080A5F48(Item item, u32 offset) { + //this funcitons signature allows the div function to return a u64 (2x 32 bit registers) + //with the result in one register and the remainder in the other + typedef u64 DivRem (u32, u32); + + s32 ammoCount; + s32 onesDigit; + s32 tensDigit; + void* dest; u16* temp2; - u32 temp3; - register u32 rem asm("r1"); + u32 index; + DoubleReturnValue ret; switch (item) { case ITEM_BOTTLE1: @@ -1248,17 +1259,14 @@ void sub_080A5F48(Item item, u32 param_2) { case ITEM_BOTTLE3: case ITEM_BOTTLE4: item = gSave.stats.bottles[item - ITEM_BOTTLE1]; - break; - default: - break; } + + dest = OBJ_VRAM0 + (offset * 0x20); + index = gSpriteAnimations_322[item]->index; + temp2 = &gMoreSpritePtrs[1][index * 2]; + DmaCopy32(3, &gMoreSpritePtrs[2][temp2[1] * 0x10], dest, 0x40 * 4); - temp1 = param_2 * 0x20 + 0x6010000; - temp3 = gSpriteAnimations_322[item]->index; - temp2 = &gMoreSpritePtrs[1][temp3 * 2]; - DmaCopy32(3, &gMoreSpritePtrs[2][temp2[1] * 0x10], temp1, 0x40 * 4); ammoCount = -1; - switch (item) { case 7: case 8: @@ -1270,15 +1278,16 @@ void sub_080A5F48(Item item, u32 param_2) { break; } - if (-1 < (int)ammoCount) { - tensDigit = Div(ammoCount, 10); - item = rem; - if ((int)tensDigit >= 10) { - tensDigit = 9; - } - DmaCopy32(3, gUnk_085C4620 + tensDigit * 0x8, temp1, 0x8 * 4); - DmaCopy32(3, gUnk_085C4620 + (item + 10) * 0x8, temp1 + 0x20, 0x8 * 4); - } + if (ammoCount < 0) return; + + ret.raw = ((DivRem*)Div)(ammoCount,10); //by casting to DivRem, we can recover the remainder from the Div call + onesDigit = ret.values.v2; + tensDigit = ret.values.v1; + + if (tensDigit >= 10) tensDigit = 9; + + DmaCopy32(3, gUnk_085C4620 + tensDigit * 0x8, dest, 0x8 * 4); + DmaCopy32(3, gUnk_085C4620 + (onesDigit + 10) * 0x8, dest + 0x20, 0x8 * 4); } void PauseMenu_Screen_7(void) { From 8a6d23411c4d2aef7400f67241f476ea225dcb0d Mon Sep 17 00:00:00 2001 From: Lemeon <66488505+ThothWhatsThis@users.noreply.github.com> Date: Sun, 21 Jan 2024 20:12:35 +0100 Subject: [PATCH 02/10] True Match DrawChargeBar Matched DrawChargeBar using typecast on Div --- src/ui.c | 88 ++++++++++++++++++++++++++++++-------------------------- 1 file changed, 47 insertions(+), 41 deletions(-) diff --git a/src/ui.c b/src/ui.c index e1c17292e..9b7aa7983 100644 --- a/src/ui.c +++ b/src/ui.c @@ -440,62 +440,68 @@ void EraseChargeBar(void) { } } +typedef union{ + u32 values[2]; + u64 raw; +} returnValues; + +typedef u64 DivRem (u32, u32); + void DrawChargeBar(void) { bool32 tmp1; - u16* ptr1; - u32 tmp2; - u32 tmp3; - register u32 rem asm("r1"); - u32 tmp5; + u16* BufferPos; + returnValues ret; + //these names are almost certainly inaccurate + u32 chargeTime; + u32 chargeState; + u32 chargeFrame; tmp1 = FALSE; - if ((gHUD.hideFlags & HUD_HIDE_CHARGE_BAR) == 0) { - tmp1 = gPlayerState.chargeState.action != 0; - } - - if (!tmp1) - return EraseChargeBar(); - - if (gHUD.maxHealth > 10 * 4) { - ptr1 = &gBG0Buffer[0x60]; - } else { - ptr1 = &gBG0Buffer[0x40]; - } - - tmp2 = Div(gPlayerState.chargeState.chargeTimer + 19, 20); - if (tmp2 > 40) { - tmp2 = 40; - } - if (gHUD.unk_6 == 0 || gHUD.unk_7 != tmp2) { - gHUD.unk_6 = 1; - gHUD.unk_7 = tmp2; - tmp3 = Div(tmp2, 4); - tmp5 = rem; - ptr1[0] = 0xf016; - ptr1[11] = 0xf416; - DmaSet(3, gUnk_080C8F54 + (10 - tmp3), ptr1 + 1, 0x8000000a); - if (tmp5 != 0) { - ptr1[tmp3 + 1] = ((tmp5 + 0x17U) & 0x3ff) | 0xf000; - } + if (!(gUnk_0200AF00.unk_1 & 0x20)) tmp1 = gPlayerState.chargeState.action != 0; + if (!tmp1) return EraseChargeBar(); + + if (gUnk_0200AF00.maxHealth > 10 * 4) + BufferPos = &gBG0Buffer[0x60]; + else + BufferPos = &gBG0Buffer[0x40]; + + chargeTime = Div(gPlayerState.chargeState.chargeTimer + 19, 20); + if (chargeTime > 40) chargeTime = 40; + + if (gUnk_0200AF00.unk_6 == 0 || gUnk_0200AF00.unk_7 != chargeTime) { + gUnk_0200AF00.unk_6 = 1; + gUnk_0200AF00.unk_7 = chargeTime; + + //this calls Div and returns the result in ret.values[0] and the remainder in ret.values[1] + ret.raw = ((DivRem*)&Div)(chargeTime, 4); + chargeState = ret.values[0]; + chargeFrame = ret.values[1]; + + BufferPos[0] = 0xf016; + BufferPos[11] = 0xf416; + DmaSet(3, &gUnk_080C8F54[10 - chargeState], BufferPos + 1, 0x8000000a); + if (chargeFrame != 0) + BufferPos[chargeState + 1] = ((chargeFrame + 0x17U) & 0x3ff) | 0xf000; gScreen.bg0.updated = 1; } switch (gPlayerState.chargeState.action) { case 4: case 5: - gHUD.unk_9 += (gPlayerState.chargeState.action == 4) ? 2 : 1; - tmp3 = gHUD.unk_9 >> 4 & 3; + gUnk_0200AF00.unk_9 += (gPlayerState.chargeState.action == 4) ? 2 : 1; + chargeState = gUnk_0200AF00.unk_9 >> 4 & 3; break; default: - tmp3 = 0; + chargeState = 0; break; } - if (tmp3 != gHUD.unk_8) { - gHUD.unk_8 = tmp3; - ptr1 = (u16*)0x600c2c0; - DmaSet(3, gUnk_080C8F7C[tmp3], ptr1, 0x84000030); - } + if (chargeState == gUnk_0200AF00.unk_8) return; + + gUnk_0200AF00.unk_8 = chargeState; + + BufferPos = (u16*)(VRAM + 0xc2c0); + DmaSet(3, gUnk_080C8F7C[chargeState], BufferPos, 0x84000030); } void DrawKeys(void) { From d40e4cee2ca32e9c4c8f545cc8ef87d51a95265f Mon Sep 17 00:00:00 2001 From: Lemeon <66488505+ThothWhatsThis@users.noreply.github.com> Date: Sun, 21 Jan 2024 20:23:43 +0100 Subject: [PATCH 03/10] Update ui.c changed gUnk_0200AF00 to gHUD. this change is not yet in the repo, which the nonmatch website uses --- src/ui.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/ui.c b/src/ui.c index 9b7aa7983..515b47c82 100644 --- a/src/ui.c +++ b/src/ui.c @@ -457,10 +457,10 @@ void DrawChargeBar(void) { u32 chargeFrame; tmp1 = FALSE; - if (!(gUnk_0200AF00.unk_1 & 0x20)) tmp1 = gPlayerState.chargeState.action != 0; + if (!(gHUD.hideFlags & HUD_HIDE_CHARGE_BAR)) tmp1 = gPlayerState.chargeState.action != 0; if (!tmp1) return EraseChargeBar(); - if (gUnk_0200AF00.maxHealth > 10 * 4) + if (gHUD.maxHealth > 10 * 4) BufferPos = &gBG0Buffer[0x60]; else BufferPos = &gBG0Buffer[0x40]; @@ -468,9 +468,9 @@ void DrawChargeBar(void) { chargeTime = Div(gPlayerState.chargeState.chargeTimer + 19, 20); if (chargeTime > 40) chargeTime = 40; - if (gUnk_0200AF00.unk_6 == 0 || gUnk_0200AF00.unk_7 != chargeTime) { - gUnk_0200AF00.unk_6 = 1; - gUnk_0200AF00.unk_7 = chargeTime; + if (gHUD.unk_6 == 0 || gHUD.unk_7 != chargeTime) { + gHUD.unk_6 = 1; + gHUD.unk_7 = chargeTime; //this calls Div and returns the result in ret.values[0] and the remainder in ret.values[1] ret.raw = ((DivRem*)&Div)(chargeTime, 4); @@ -488,17 +488,17 @@ void DrawChargeBar(void) { switch (gPlayerState.chargeState.action) { case 4: case 5: - gUnk_0200AF00.unk_9 += (gPlayerState.chargeState.action == 4) ? 2 : 1; - chargeState = gUnk_0200AF00.unk_9 >> 4 & 3; + gHUD.unk_9 += (gPlayerState.chargeState.action == 4) ? 2 : 1; + chargeState = gHUD.unk_9 >> 4 & 3; break; default: chargeState = 0; break; } - if (chargeState == gUnk_0200AF00.unk_8) return; + if (chargeState == gHUD.unk_8) return; - gUnk_0200AF00.unk_8 = chargeState; + gHUD.unk_8 = chargeState; BufferPos = (u16*)(VRAM + 0xc2c0); DmaSet(3, gUnk_080C8F7C[chargeState], BufferPos, 0x84000030); From db4fb73c382ad6f44c496cb4060e32790178db57 Mon Sep 17 00:00:00 2001 From: Lemeon <66488505+ThothWhatsThis@users.noreply.github.com> Date: Sun, 21 Jan 2024 20:38:04 +0100 Subject: [PATCH 04/10] Update ui.c changes to how my code looks --- src/ui.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/ui.c b/src/ui.c index 515b47c82..85c871bb3 100644 --- a/src/ui.c +++ b/src/ui.c @@ -457,16 +457,20 @@ void DrawChargeBar(void) { u32 chargeFrame; tmp1 = FALSE; - if (!(gHUD.hideFlags & HUD_HIDE_CHARGE_BAR)) tmp1 = gPlayerState.chargeState.action != 0; - if (!tmp1) return EraseChargeBar(); - + if (!(gHUD.hideFlags & HUD_HIDE_CHARGE_BAR)) + tmp1 = gPlayerState.chargeState.action != 0; + if (!tmp1) { + EraseChargeBar(); + return + } if (gHUD.maxHealth > 10 * 4) BufferPos = &gBG0Buffer[0x60]; else BufferPos = &gBG0Buffer[0x40]; chargeTime = Div(gPlayerState.chargeState.chargeTimer + 19, 20); - if (chargeTime > 40) chargeTime = 40; + if (chargeTime > 40) + chargeTime = 40; if (gHUD.unk_6 == 0 || gHUD.unk_7 != chargeTime) { gHUD.unk_6 = 1; @@ -496,7 +500,8 @@ void DrawChargeBar(void) { break; } - if (chargeState == gHUD.unk_8) return; + if (chargeState == gHUD.unk_8) + return; gHUD.unk_8 = chargeState; From 25ef3a2541481dd12f7cedb15146fee76be976f5 Mon Sep 17 00:00:00 2001 From: Lemeon <66488505+ThothWhatsThis@users.noreply.github.com> Date: Sun, 21 Jan 2024 20:41:17 +0100 Subject: [PATCH 05/10] Update ui.c ; --- src/ui.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ui.c b/src/ui.c index 85c871bb3..2b81bbbe3 100644 --- a/src/ui.c +++ b/src/ui.c @@ -461,7 +461,7 @@ void DrawChargeBar(void) { tmp1 = gPlayerState.chargeState.action != 0; if (!tmp1) { EraseChargeBar(); - return + return; } if (gHUD.maxHealth > 10 * 4) BufferPos = &gBG0Buffer[0x60]; From 9175401caa664779d4c2637e7afc7c131f59c4b1 Mon Sep 17 00:00:00 2001 From: Lemeon <66488505+ThothWhatsThis@users.noreply.github.com> Date: Sun, 21 Jan 2024 20:44:20 +0100 Subject: [PATCH 06/10] Update pauseMenu.c --- src/menu/pauseMenu.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/menu/pauseMenu.c b/src/menu/pauseMenu.c index 8ed35cfd4..583cf0f03 100644 --- a/src/menu/pauseMenu.c +++ b/src/menu/pauseMenu.c @@ -1241,8 +1241,8 @@ typedef union{ } DoubleReturnValue; void sub_080A5F48(Item item, u32 offset) { - //this funcitons signature allows the div function to return a u64 (2x 32 bit registers) - //with the result in one register and the remainder in the other + // this funcitons signature allows the div function to return a u64 (2x 32 bit registers) + // with the result in one register and the remainder in the other typedef u64 DivRem (u32, u32); s32 ammoCount; @@ -1278,15 +1278,17 @@ void sub_080A5F48(Item item, u32 offset) { break; } - if (ammoCount < 0) return; + if (ammoCount < 0) + return; - ret.raw = ((DivRem*)Div)(ammoCount,10); //by casting to DivRem, we can recover the remainder from the Div call + ret.raw = ((DivRem*)Div)(ammoCount,10); // by casting to DivRem, we can recover the remainder from the Div call onesDigit = ret.values.v2; tensDigit = ret.values.v1; - if (tensDigit >= 10) tensDigit = 9; + if (tensDigit >= 10) + tensDigit = 9; - DmaCopy32(3, gUnk_085C4620 + tensDigit * 0x8, dest, 0x8 * 4); + DmaCopy32(3, gUnk_085C4620 + tensDigit * 0x8, dest, 0x8 * 4); DmaCopy32(3, gUnk_085C4620 + (onesDigit + 10) * 0x8, dest + 0x20, 0x8 * 4); } From 31b6c813e0583cc3db82a11b2329e2e122ec3df7 Mon Sep 17 00:00:00 2001 From: Lemeon <66488505+ThothWhatsThis@users.noreply.github.com> Date: Sun, 21 Jan 2024 20:46:00 +0100 Subject: [PATCH 07/10] Update ui.c --- src/ui.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ui.c b/src/ui.c index 2b81bbbe3..304cf2736 100644 --- a/src/ui.c +++ b/src/ui.c @@ -451,7 +451,7 @@ void DrawChargeBar(void) { bool32 tmp1; u16* BufferPos; returnValues ret; - //these names are almost certainly inaccurate + // these names are almost certainly inaccurate u32 chargeTime; u32 chargeState; u32 chargeFrame; @@ -476,7 +476,7 @@ void DrawChargeBar(void) { gHUD.unk_6 = 1; gHUD.unk_7 = chargeTime; - //this calls Div and returns the result in ret.values[0] and the remainder in ret.values[1] + // this calls Div and returns the result in ret.values[0] and the remainder in ret.values[1] ret.raw = ((DivRem*)&Div)(chargeTime, 4); chargeState = ret.values[0]; chargeFrame = ret.values[1]; From cf72e7b2d33b3a677ddb4d4432d56399665dcaab Mon Sep 17 00:00:00 2001 From: Lemeon <66488505+ThothWhatsThis@users.noreply.github.com> Date: Sun, 21 Jan 2024 20:55:42 +0100 Subject: [PATCH 08/10] Update ui.c whitespace... --- src/ui.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/ui.c b/src/ui.c index 304cf2736..3db7734f1 100644 --- a/src/ui.c +++ b/src/ui.c @@ -457,7 +457,7 @@ void DrawChargeBar(void) { u32 chargeFrame; tmp1 = FALSE; - if (!(gHUD.hideFlags & HUD_HIDE_CHARGE_BAR)) + if (!(gHUD.hideFlags & HUD_HIDE_CHARGE_BAR)) tmp1 = gPlayerState.chargeState.action != 0; if (!tmp1) { EraseChargeBar(); @@ -469,7 +469,7 @@ void DrawChargeBar(void) { BufferPos = &gBG0Buffer[0x40]; chargeTime = Div(gPlayerState.chargeState.chargeTimer + 19, 20); - if (chargeTime > 40) + if (chargeTime > 40) chargeTime = 40; if (gHUD.unk_6 == 0 || gHUD.unk_7 != chargeTime) { @@ -477,14 +477,14 @@ void DrawChargeBar(void) { gHUD.unk_7 = chargeTime; // this calls Div and returns the result in ret.values[0] and the remainder in ret.values[1] - ret.raw = ((DivRem*)&Div)(chargeTime, 4); + ret.raw = ((DivRem*)&Div)(chargeTime, 4); chargeState = ret.values[0]; chargeFrame = ret.values[1]; BufferPos[0] = 0xf016; BufferPos[11] = 0xf416; DmaSet(3, &gUnk_080C8F54[10 - chargeState], BufferPos + 1, 0x8000000a); - if (chargeFrame != 0) + if (chargeFrame != 0) BufferPos[chargeState + 1] = ((chargeFrame + 0x17U) & 0x3ff) | 0xf000; gScreen.bg0.updated = 1; } @@ -500,13 +500,13 @@ void DrawChargeBar(void) { break; } - if (chargeState == gHUD.unk_8) + if (chargeState == gHUD.unk_8) return; gHUD.unk_8 = chargeState; BufferPos = (u16*)(VRAM + 0xc2c0); - DmaSet(3, gUnk_080C8F7C[chargeState], BufferPos, 0x84000030); + DmaSet(3, gUnk_080C8F7C[chargeState], BufferPos, 0x84000030); } void DrawKeys(void) { From 299ca4abd654bd499a60f9c67fa5137f048e967f Mon Sep 17 00:00:00 2001 From: Lemeon <66488505+ThothWhatsThis@users.noreply.github.com> Date: Sun, 21 Jan 2024 20:59:59 +0100 Subject: [PATCH 09/10] Update pauseMenu.c fighting with the lint system --- src/menu/pauseMenu.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/menu/pauseMenu.c b/src/menu/pauseMenu.c index 583cf0f03..8e0cfadff 100644 --- a/src/menu/pauseMenu.c +++ b/src/menu/pauseMenu.c @@ -1232,8 +1232,8 @@ bool32 sub_080A5F24(void) { return result; } -typedef union{ - struct{ +typedef union { + struct { s32 v1; s32 v2; } values; @@ -1243,8 +1243,8 @@ typedef union{ void sub_080A5F48(Item item, u32 offset) { // this funcitons signature allows the div function to return a u64 (2x 32 bit registers) // with the result in one register and the remainder in the other - typedef u64 DivRem (u32, u32); - + typedef u64 DivRem(u32, u32); + s32 ammoCount; s32 onesDigit; s32 tensDigit; @@ -1260,7 +1260,7 @@ void sub_080A5F48(Item item, u32 offset) { case ITEM_BOTTLE4: item = gSave.stats.bottles[item - ITEM_BOTTLE1]; } - + dest = OBJ_VRAM0 + (offset * 0x20); index = gSpriteAnimations_322[item]->index; temp2 = &gMoreSpritePtrs[1][index * 2]; @@ -1278,14 +1278,14 @@ void sub_080A5F48(Item item, u32 offset) { break; } - if (ammoCount < 0) - return; - - ret.raw = ((DivRem*)Div)(ammoCount,10); // by casting to DivRem, we can recover the remainder from the Div call + if (ammoCount < 0) + return; + + ret.raw = ((DivRem*)Div)(ammoCount, 10); // by casting to DivRem, we can recover the remainder from the Div call onesDigit = ret.values.v2; tensDigit = ret.values.v1; - if (tensDigit >= 10) + if (tensDigit >= 10) tensDigit = 9; DmaCopy32(3, gUnk_085C4620 + tensDigit * 0x8, dest, 0x8 * 4); From ead5277a6644c4227133dd932ed2ba9c9f86edf3 Mon Sep 17 00:00:00 2001 From: Lemeon <66488505+ThothWhatsThis@users.noreply.github.com> Date: Sun, 21 Jan 2024 21:02:06 +0100 Subject: [PATCH 10/10] Update ui.c that should be the right format now --- src/ui.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ui.c b/src/ui.c index 3db7734f1..ac66ddcf7 100644 --- a/src/ui.c +++ b/src/ui.c @@ -440,12 +440,12 @@ void EraseChargeBar(void) { } } -typedef union{ +typedef union { u32 values[2]; u64 raw; } returnValues; -typedef u64 DivRem (u32, u32); +typedef u64 DivRem(u32, u32); void DrawChargeBar(void) { bool32 tmp1;