summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRoman971 <32455037+Roman971@users.noreply.github.com>2020-12-18 01:12:22 +0100
committerGitHub <noreply@github.com>2020-12-17 19:12:22 -0500
commit83e53bbaf255c9936414f6b249dcec46cef8471b (patch)
tree723feb17a0e559b60ad8ea1d10ef39056d9ba04c /src
parent0376242365c15345f7ab33edfab7408877164a92 (diff)
Fix some non matchings in actors and parameter (#540)
* Fix some non matchings in actors and parameter - `EnTuboTrap_HandleImpact` from `z_en_tubo_trap.c` (fully matching) - `func_80ADA35C` from `z_en_po_sisters.c` (fully matching) - `func_80B0B81C` from `z_en_stream.c` (fully matching) - `Item_Give` from `z_parameter.c` (1 non matching left) * Rectify bss ordering comment
Diffstat (limited to 'src')
-rw-r--r--src/code/z_parameter.c73
-rw-r--r--src/overlays/actors/ovl_En_Po_Sisters/z_en_po_sisters.c11
-rw-r--r--src/overlays/actors/ovl_En_Stream/z_en_stream.c25
-rw-r--r--src/overlays/actors/ovl_En_Tubo_Trap/z_en_tubo_trap.c8
4 files changed, 53 insertions, 64 deletions
diff --git a/src/code/z_parameter.c b/src/code/z_parameter.c
index 4f64280d2..1b1b0f993 100644
--- a/src/code/z_parameter.c
+++ b/src/code/z_parameter.c
@@ -1304,15 +1304,10 @@ void func_80084BF4(GlobalContext* globalCtx, u16 flag) {
s16 sAmmoRefillCounts[] = { 5, 10, 20, 30, 5, 10, 30, 0, 5, 20, 1, 5, 20, 50, 200, 10 };
-#ifdef NON_MATCHING
-// regalloc, minor ordering and stack usage differences
u8 Item_Give(GlobalContext* globalCtx, u8 item) {
s16 i;
s16 slot;
- s16 oldItem;
- s16 bottleSlot;
- s16 prevTradeItem;
- s8 bombCount;
+ s16 temp;
slot = SLOT(item);
if (item >= ITEM_STICKS_5) {
@@ -1571,16 +1566,12 @@ u8 Item_Give(GlobalContext* globalCtx, u8 item) {
} else if (item == ITEM_BOMB) {
// Translates to: "Bomb Bomb Bomb Bomb Bomb Bomb Bomb"
osSyncPrintf(" 爆弾 爆弾 爆弾 爆弾 爆弾 爆弾 爆弾 \n");
- bombCount = AMMO(ITEM_BOMB) + 1;
- AMMO(ITEM_BOMB) = bombCount;
- if (bombCount > CUR_CAPACITY(UPG_BOMB_BAG)) {
+ if ((AMMO(ITEM_BOMB) += 1) > CUR_CAPACITY(UPG_BOMB_BAG)) {
AMMO(ITEM_BOMB) = CUR_CAPACITY(UPG_BOMB_BAG);
}
return ITEM_NONE;
} else if ((item >= ITEM_BOMBS_5) && (item <= ITEM_BOMBS_30)) {
- bombCount = AMMO(ITEM_BOMB) + sAmmoRefillCounts[item - ITEM_BOMBS_5];
- AMMO(ITEM_BOMB) = bombCount;
- if (bombCount > CUR_CAPACITY(UPG_BOMB_BAG)) {
+ if ((AMMO(ITEM_BOMB) += sAmmoRefillCounts[item - ITEM_BOMBS_5]) > CUR_CAPACITY(UPG_BOMB_BAG)) {
AMMO(ITEM_BOMB) = CUR_CAPACITY(UPG_BOMB_BAG);
}
return ITEM_NONE;
@@ -1713,50 +1704,52 @@ u8 Item_Give(GlobalContext* globalCtx, u8 item) {
Rupees_ChangeBy(sAmmoRefillCounts[item - ITEM_RUPEE_GREEN + 10]);
return ITEM_NONE;
} else if (item == ITEM_BOTTLE) {
+ temp = SLOT(item);
+
for (i = 0; i < 4; i++) {
- if (gSaveContext.inventory.items[SLOT(item) + i] == ITEM_NONE) {
- gSaveContext.inventory.items[SLOT(item) + i] = item;
+ if (gSaveContext.inventory.items[temp + i] == ITEM_NONE) {
+ gSaveContext.inventory.items[temp + i] = item;
return ITEM_NONE;
}
}
} else if (((item >= ITEM_POTION_RED) && (item <= ITEM_POE)) || (item == ITEM_MILK)) {
- bottleSlot = SLOT(item);
+ temp = SLOT(item);
if ((item != ITEM_MILK_BOTTLE) && (item != ITEM_LETTER_RUTO)) {
if (item == ITEM_MILK) {
item = ITEM_MILK_BOTTLE;
- bottleSlot = SLOT(item);
+ temp = SLOT(item);
}
for (i = 0; i < 4; i++) {
- if (gSaveContext.inventory.items[bottleSlot + i] == ITEM_BOTTLE) {
+ if (gSaveContext.inventory.items[temp + i] == ITEM_BOTTLE) {
// Translates to: "Item_Pt(1)=%d Item_Pt(2)=%d Item_Pt(3)=%d Empty Bottle=%d Content=%d"
osSyncPrintf("Item_Pt(1)=%d Item_Pt(2)=%d Item_Pt(3)=%d 空瓶=%d 中味=%d\n",
gSaveContext.equips.cButtonSlots[0], gSaveContext.equips.cButtonSlots[1],
- gSaveContext.equips.cButtonSlots[2], bottleSlot + i, item);
+ gSaveContext.equips.cButtonSlots[2], temp + i, item);
- if ((bottleSlot + i) == gSaveContext.equips.cButtonSlots[0]) {
+ if ((temp + i) == gSaveContext.equips.cButtonSlots[0]) {
gSaveContext.equips.buttonItems[1] = item;
Interface_LoadItemIcon2(globalCtx, 1);
gSaveContext.buttonStatus[1] = BTN_ENABLED;
- } else if ((bottleSlot + i) == gSaveContext.equips.cButtonSlots[1]) {
+ } else if ((temp + i) == gSaveContext.equips.cButtonSlots[1]) {
gSaveContext.equips.buttonItems[2] = item;
Interface_LoadItemIcon2(globalCtx, 2);
gSaveContext.buttonStatus[2] = BTN_ENABLED;
- } else if ((bottleSlot + i) == gSaveContext.equips.cButtonSlots[2]) {
+ } else if ((temp + i) == gSaveContext.equips.cButtonSlots[2]) {
gSaveContext.equips.buttonItems[3] = item;
Interface_LoadItemIcon1(globalCtx, 3);
gSaveContext.buttonStatus[3] = BTN_ENABLED;
}
- gSaveContext.inventory.items[bottleSlot + i] = item;
+ gSaveContext.inventory.items[temp + i] = item;
return ITEM_NONE;
}
}
} else {
for (i = 0; i < 4; i++) {
- if (gSaveContext.inventory.items[bottleSlot + i] == ITEM_NONE) {
- gSaveContext.inventory.items[bottleSlot + i] = item;
+ if (gSaveContext.inventory.items[temp + i] == ITEM_NONE) {
+ gSaveContext.inventory.items[temp + i] = item;
return ITEM_NONE;
}
}
@@ -1766,12 +1759,12 @@ u8 Item_Give(GlobalContext* globalCtx, u8 item) {
gSaveContext.itemGetInf[1] |= 0x8000;
}
- prevTradeItem = INV_CONTENT(item);
+ temp = INV_CONTENT(item);
INV_CONTENT(item) = item;
- if (prevTradeItem != ITEM_NONE) {
+ if (temp != ITEM_NONE) {
for (i = 1; i < 4; i++) {
- if (prevTradeItem == gSaveContext.equips.buttonItems[i]) {
+ if (temp == gSaveContext.equips.buttonItems[i]) {
if (item != ITEM_SOLD_OUT) {
gSaveContext.equips.buttonItems[i] = item;
Interface_LoadItemIcon1(globalCtx, i);
@@ -1786,20 +1779,17 @@ u8 Item_Give(GlobalContext* globalCtx, u8 item) {
return ITEM_NONE;
}
- oldItem = gSaveContext.inventory.items[slot];
- osSyncPrintf("Item_Register(%d)=%d %d\n", slot, item, oldItem);
+ temp = gSaveContext.inventory.items[slot];
+ osSyncPrintf("Item_Register(%d)=%d %d\n", slot, item, temp);
INV_CONTENT(item) = item;
- return oldItem;
+ return temp;
}
-#else
-#pragma GLOBAL_ASM("asm/non_matchings/code/z_parameter/Item_Give.s")
-#endif
u8 Item_CheckObtainability(u8 item) {
s16 i;
s16 slot;
- s32 bottleSlot;
+ s32 temp;
slot = SLOT(item);
if (item >= ITEM_STICKS_5) {
@@ -1898,22 +1888,22 @@ u8 Item_CheckObtainability(u8 item) {
} else if (item == ITEM_BOTTLE) {
return ITEM_NONE;
} else if (((item >= ITEM_POTION_RED) && (item <= ITEM_POE)) || (item == ITEM_MILK)) {
- bottleSlot = SLOT(item);
+ temp = SLOT(item);
if ((item != ITEM_MILK_BOTTLE) && (item != ITEM_LETTER_RUTO)) {
if (item == ITEM_MILK) {
item = ITEM_MILK_BOTTLE;
- bottleSlot = SLOT(item);
+ temp = SLOT(item);
}
for (i = 0; i < 4; i++) {
- if (gSaveContext.inventory.items[bottleSlot + i] == ITEM_BOTTLE) {
+ if (gSaveContext.inventory.items[temp + i] == ITEM_BOTTLE) {
return ITEM_NONE;
}
}
} else {
for (i = 0; i < 4; i++) {
- if (gSaveContext.inventory.items[bottleSlot + i] == ITEM_NONE) {
+ if (gSaveContext.inventory.items[temp + i] == ITEM_NONE) {
return ITEM_NONE;
}
}
@@ -3055,6 +3045,13 @@ u16 D_80125B54 = 0xC220; // unused
u16 D_80125B58 = 0xC20C; // unused
s16 D_80125B5C[] = { 91, 91 }; // unused
+// Due to an unknown reason, bss ordering changes within the 5 static variables in the function below.
+// In order to restore the correct order, we need a specific number of bss variables in the file before that point.
+// For this, we introduce 3 dummy variables which end up in padding at the end of the file's bss, so they don't actually take space.
+s8 sBssDummy1;
+s8 sBssDummy2;
+s8 sBssDummy3;
+
#ifdef NON_MATCHING
// mostly regalloc, minor ordering and stack usage differences
void Interface_Draw(GlobalContext* globalCtx) {
diff --git a/src/overlays/actors/ovl_En_Po_Sisters/z_en_po_sisters.c b/src/overlays/actors/ovl_En_Po_Sisters/z_en_po_sisters.c
index 2cbd6a837..9fb718522 100644
--- a/src/overlays/actors/ovl_En_Po_Sisters/z_en_po_sisters.c
+++ b/src/overlays/actors/ovl_En_Po_Sisters/z_en_po_sisters.c
@@ -524,8 +524,6 @@ void func_80ADA2BC(EnPoSisters* this, GlobalContext* globalCtx) {
this->actionFunc = func_80ADBF58;
}
-#ifdef NON_MATCHING
-// Single register swap
void func_80ADA35C(EnPoSisters* this, GlobalContext* globalCtx) {
f32 targetY;
Player* player = PLAYER;
@@ -538,11 +536,11 @@ void func_80ADA35C(EnPoSisters* this, GlobalContext* globalCtx) {
targetY = 832.0f;
}
Math_SmoothScaleMaxF(&this->actor.posRot.pos.y, targetY, 0.5f, 3.0f);
- if (this->unk_196 == 0) {
+ if (!this->unk_196) {
this->unk_196 = 32;
}
- if (this->unk_196 != 0U) { // U improves codegen from missing move + regalloc to just regalloc
- this->unk_196 -= 1U;
+ if (this->unk_196 != 0) {
+ this->unk_196--;
}
this->actor.posRot.pos.y += (2.0f + 0.5f * Math_Rand_ZeroOne()) * Math_Sins(this->unk_196 * 0x800);
if (this->unk_22E.a == 255 && this->actionFunc != func_80ADA8C0 && this->actionFunc != func_80ADA7F0) {
@@ -553,9 +551,6 @@ void func_80ADA35C(EnPoSisters* this, GlobalContext* globalCtx) {
}
}
}
-#else
-#pragma GLOBAL_ASM("asm/non_matchings/overlays/actors/ovl_En_Po_Sisters/func_80ADA35C.s")
-#endif
void func_80ADA4A8(EnPoSisters* this, GlobalContext* globalCtx) {
SkelAnime_FrameUpdateMatrix(&this->skelAnime);
diff --git a/src/overlays/actors/ovl_En_Stream/z_en_stream.c b/src/overlays/actors/ovl_En_Stream/z_en_stream.c
index aaa33dc93..01718b319 100644
--- a/src/overlays/actors/ovl_En_Stream/z_en_stream.c
+++ b/src/overlays/actors/ovl_En_Stream/z_en_stream.c
@@ -52,34 +52,35 @@ void EnStream_Init(Actor* thisx, GlobalContext* globalCtx) {
void EnStream_Destroy(Actor* thisx, GlobalContext* globalCtx) {
}
-#ifdef NON_MATCHING
-// regalloc differences, checks if the player is range of the vortex
+// Checks if the player is in range of the vortex
s32 func_80B0B81C(Vec3f* vortexPosRot, Vec3f* playerPosRot, Vec3f* posDifference, f32 vortexYScale) {
s32 ret = 0;
- f32 smallConstant = 28;
- f32 lowerBounds = 0 * vortexYScale * 50;
- f32 upperBounds = 160 * vortexYScale * 50;
+ f32 smallConstant = 28.0f;
+ f32 upperBounds = 160 * vortexYScale * 50.0f;
+ f32 lowerBounds = 0 * vortexYScale * 50.0f;
f32 xzDist;
+ f32 range;
posDifference->x = playerPosRot->x - vortexPosRot->x;
posDifference->y = playerPosRot->y - vortexPosRot->y;
posDifference->z = playerPosRot->z - vortexPosRot->z;
xzDist = sqrtf(SQ(posDifference->x) + SQ(posDifference->z));
+
if (lowerBounds <= posDifference->y && posDifference->y <= upperBounds) {
- posDifference->y = posDifference->y - lowerBounds;
- if (xzDist <= (((75 - smallConstant) * (posDifference->y / (upperBounds - lowerBounds))) + 28)) {
+ posDifference->y -= lowerBounds;
+
+ range = ((75.0f - smallConstant) * (posDifference->y / (upperBounds - lowerBounds))) + 28.0f;
+ if (xzDist <= range) {
ret = 1;
}
}
- if ((posDifference->y <= lowerBounds) && (xzDist <= 28)) {
+
+ if ((posDifference->y <= lowerBounds) && (xzDist <= 28.0f)) {
ret = 2;
}
+
return ret;
}
-#else
-s32 func_80B0B81C(Vec3f* vortexPos, Vec3f* playerPos, Vec3f* posDifference, f32 vortexYScale);
-#pragma GLOBAL_ASM("asm/non_matchings/overlays/actors/ovl_En_Stream/func_80B0B81C.s")
-#endif
void EnStream_SuckPlayer(EnStream* this, GlobalContext* globalCtx) {
Player* player = PLAYER;
diff --git a/src/overlays/actors/ovl_En_Tubo_Trap/z_en_tubo_trap.c b/src/overlays/actors/ovl_En_Tubo_Trap/z_en_tubo_trap.c
index 843b09c27..a189c8cec 100644
--- a/src/overlays/actors/ovl_En_Tubo_Trap/z_en_tubo_trap.c
+++ b/src/overlays/actors/ovl_En_Tubo_Trap/z_en_tubo_trap.c
@@ -156,10 +156,9 @@ void EnTuboTrap_SpawnEffectsInWater(EnTuboTrap* this, GlobalContext* globalCtx)
}
}
-#ifdef NON_MATCHING
void EnTuboTrap_HandleImpact(EnTuboTrap* this, GlobalContext* globalCtx) {
- s32 pad;
Player* player = PLAYER;
+ Player* player2 = PLAYER;
if ((this->actor.bgCheckFlags & 0x20) && (this->actor.waterY > 15.0f)) {
EnTuboTrap_SpawnEffectsInWater(this, globalCtx);
@@ -194,7 +193,7 @@ void EnTuboTrap_HandleImpact(EnTuboTrap* this, GlobalContext* globalCtx) {
if (this->collider.base.at == &player->actor) {
EnTuboTrap_SpawnEffectsOnLand(this, globalCtx);
Audio_PlaySoundAtPosition(globalCtx, &this->actor.posRot.pos, 40, NA_SE_EV_POT_BROKEN);
- Audio_PlaySoundAtPosition(globalCtx, &player->actor.posRot.pos, 40, NA_SE_PL_BODY_HIT);
+ Audio_PlaySoundAtPosition(globalCtx, &player2->actor.posRot.pos, 40, NA_SE_PL_BODY_HIT);
EnTuboTrap_DropCollectible(this, globalCtx);
Actor_Kill(&this->actor);
return;
@@ -209,9 +208,6 @@ void EnTuboTrap_HandleImpact(EnTuboTrap* this, GlobalContext* globalCtx) {
return;
}
}
-#else
-#pragma GLOBAL_ASM("asm/non_matchings/overlays/actors/ovl_En_Tubo_Trap/EnTuboTrap_HandleImpact.s")
-#endif
void EnTuboTrap_WaitForProximity(EnTuboTrap* this, GlobalContext* globalCtx) {
Player* player = PLAYER;