summaryrefslogtreecommitdiff
path: root/src/code/code_800F7260.c
diff options
context:
space:
mode:
authorzelda2774 <69368340+zelda2774@users.noreply.github.com>2021-08-31 15:22:56 +0200
committerGitHub <noreply@github.com>2021-08-31 09:22:56 -0400
commit6ef1f3ea3e690a3371454e1b02c385a3cfaf05ec (patch)
tree3158f0b35a62746f9f3051a26d284f3241fea59d /src/code/code_800F7260.c
parent1117783731523947813e3834ae6871a0de37108c (diff)
Match Audio_ProcessSoundRequest (#935)
Co-authored-by: zelda2774 <zelda2774@invalid>
Diffstat (limited to 'src/code/code_800F7260.c')
-rw-r--r--src/code/code_800F7260.c205
1 files changed, 98 insertions, 107 deletions
diff --git a/src/code/code_800F7260.c b/src/code/code_800F7260.c
index 9ed8e8382..b1d4196dd 100644
--- a/src/code/code_800F7260.c
+++ b/src/code/code_800F7260.c
@@ -155,12 +155,12 @@ void Audio_RemoveMatchingSoundRequests(u8 aspect, SoundBankEntry* cmp) {
req = &sSoundRequests[i];
switch (aspect) {
case 0:
- if (SFX_BANK_MASK(req->sfxId) == SFX_BANK_MASK(cmp->unk_28)) {
+ if (SFX_BANK_MASK(req->sfxId) == SFX_BANK_MASK(cmp->sfxId)) {
remove = true;
}
break;
case 1:
- if (SFX_BANK_MASK(req->sfxId) == SFX_BANK_MASK(cmp->unk_28) && (&req->pos->x == cmp->posX)) {
+ if (SFX_BANK_MASK(req->sfxId) == SFX_BANK_MASK(cmp->sfxId) && (&req->pos->x == cmp->posX)) {
remove = true;
}
break;
@@ -170,17 +170,17 @@ void Audio_RemoveMatchingSoundRequests(u8 aspect, SoundBankEntry* cmp) {
}
break;
case 3:
- if (&req->pos->x == cmp->posX && req->sfxId == cmp->unk_28) {
+ if (&req->pos->x == cmp->posX && req->sfxId == cmp->sfxId) {
remove = true;
}
break;
case 4:
- if (req->unk_8 == cmp->unk_C && req->sfxId == cmp->unk_28) {
+ if (req->unk_8 == cmp->unk_C && req->sfxId == cmp->sfxId) {
remove = true;
}
break;
case 5:
- if (req->sfxId == cmp->unk_28) {
+ if (req->sfxId == cmp->sfxId) {
remove = true;
}
break;
@@ -191,113 +191,104 @@ void Audio_RemoveMatchingSoundRequests(u8 aspect, SoundBankEntry* cmp) {
}
}
-#ifdef NON_MATCHING
-// Down to a/v regalloc and some stuff where the compiler gets confused about reusing values. There's some fake matching
-// stuff to improve regalloc enough to verify equivalence.
void Audio_ProcessSoundRequest(void) {
- u16 flag1;
- u8 sp55;
- u8 phi_a1;
- SoundRequest* req; // sp50
- SoundBankEntry* temp_v0;
+ u16 sfxId;
+ u8 count;
+ u8 index;
+ SoundRequest* req;
+ SoundBankEntry* entry;
Struct_8013331C* sp48;
- s32 phi_s5;
- u8 sp43;
- u8 phi_s1;
- u16 flag2;
+ s32 bankId;
+ u8 bestValue;
+ u8 bestIndex;
req = &sSoundRequests[sSoundRequestReadIndex];
- phi_s1 = 0x80;
+ bestIndex = 0x80;
if (req->sfxId == 0) {
return;
}
- phi_s5 = SFX_BANK(req->sfxId);
- if ((1 << phi_s5) & D_801333F0) {
+ bankId = SFX_BANK(req->sfxId);
+ if ((1 << bankId) & D_801333F0) {
AudioDebug_ScrPrt((const s8*)D_80133340, req->sfxId);
- phi_s5 = SFX_BANK(req->sfxId);
+ bankId = SFX_BANK(req->sfxId);
}
- sp55 = 0;
- phi_a1 = gSoundBanks[phi_s5][0].next;
- while (phi_a1 != 0xFF && phi_a1 != 0) {
- if (gSoundBanks[phi_s5][phi_a1].posX == &req->pos->x) {
- sp48 = &D_8013331C[SFX_BANK_SHIFT(req->sfxId)][SFX_INDEX(req->sfxId)];
- if (!(!(sp48->unk_2 & 0x20) || sp48->unk_0 != gSoundBanks[phi_s5][phi_a1].unk_24)) {
+ count = 0;
+ index = gSoundBanks[bankId][0].next;
+ while (index != 0xFF && index != 0) {
+ if (gSoundBanks[bankId][index].posX == &req->pos->x) {
+ if ((D_8013331C[SFX_BANK_SHIFT(req->sfxId)][SFX_INDEX(req->sfxId)].unk_2 & 0x20) &&
+ D_8013331C[SFX_BANK_SHIFT(req->sfxId)][SFX_INDEX(req->sfxId)].unk_0 ==
+ gSoundBanks[bankId][index].unk_24) {
return;
}
- if (gSoundBanks[phi_s5][phi_a1].unk_28 == req->sfxId) {
- sp55 = D_80130594[D_801333CC][phi_s5];
+ if (gSoundBanks[bankId][index].sfxId == req->sfxId) {
+ count = D_80130594[D_801333CC][bankId];
} else {
- //! @bug possibly uninitialized sp43 ? confirm when matching
- if (sp55 == 0) {
- phi_s1 = phi_a1;
- flag1 = gSoundBanks[phi_s5][phi_a1].unk_28 & 0xFFFF;
- sp43 = D_8013331C[SFX_BANK_SHIFT(flag1)][SFX_INDEX(flag1)].unk_0;
- } else if (gSoundBanks[phi_s5][phi_a1].unk_24 < sp43) {
- phi_s1 = phi_a1;
- flag1 = gSoundBanks[phi_s5][phi_a1].unk_28 & 0xFFFF;
- sp43 = D_8013331C[SFX_BANK_SHIFT(flag1)][SFX_INDEX(flag1)].unk_0;
+ if (count == 0) {
+ bestIndex = index;
+ sfxId = gSoundBanks[bankId][index].sfxId & 0xFFFF;
+ bestValue = D_8013331C[SFX_BANK_SHIFT(sfxId)][SFX_INDEX(sfxId)].unk_0;
+ } else if (gSoundBanks[bankId][index].unk_24 < bestValue) {
+ bestIndex = index;
+ sfxId = gSoundBanks[bankId][index].sfxId & 0xFFFF;
+ bestValue = D_8013331C[SFX_BANK_SHIFT(sfxId)][SFX_INDEX(sfxId)].unk_0;
}
- sp55++;
- if (sp55 == D_80130594[D_801333CC][phi_s5]) {
- phi_a1 = (sp48->unk_0 >= sp43) ? phi_s1 : 0;
+ count++;
+ if (count == D_80130594[D_801333CC][bankId]) {
+ index = (D_8013331C[SFX_BANK_SHIFT(req->sfxId)][SFX_INDEX(req->sfxId)].unk_0 >= bestValue)
+ ? bestIndex
+ : 0;
}
}
- if (D_80130594[D_801333CC][phi_s5] == sp55) {
- flag2 = req->sfxId & 0xC00; // Problem is around here
+ if (count == D_80130594[D_801333CC][bankId]) {
sp48 = &D_8013331C[SFX_BANK_SHIFT(req->sfxId)][SFX_INDEX(req->sfxId)];
- if ((flag2) || (D_8013331C[SFX_BANK_SHIFT(req->sfxId)][SFX_INDEX(req->sfxId)].unk_2 & 4) ||
- (phi_a1 == phi_s1)) {
- if ((gSoundBanks[phi_s5][phi_a1].unk_26 & 8) && gSoundBanks[phi_s5][phi_a1].unk_2A != 1) {
- Audio_ClearBGMMute(gSoundBanks[phi_s5][phi_a1].unk_2E);
+ if ((req->sfxId & 0xC00) || (sp48->unk_2 & 4) || (index == bestIndex)) {
+ if ((gSoundBanks[bankId][index].unk_26 & 8) && gSoundBanks[bankId][index].unk_2A != 1) {
+ Audio_ClearBGMMute(gSoundBanks[bankId][index].unk_2E);
}
- gSoundBanks[phi_s5][phi_a1].unk_C = req->unk_8;
- gSoundBanks[phi_s5][phi_a1].unk_28 = req->sfxId;
- gSoundBanks[phi_s5][phi_a1].unk_2A = 1;
- gSoundBanks[phi_s5][phi_a1].unk_2B = 2;
- gSoundBanks[phi_s5][phi_a1].freqScale = req->freqScale;
- gSoundBanks[phi_s5][phi_a1].unk_14 = req->unk_10;
- gSoundBanks[phi_s5][phi_a1].reverbAdd = req->reverbAdd;
- gSoundBanks[phi_s5][phi_a1].unk_26 = sp48->unk_2;
- gSoundBanks[phi_s5][phi_a1].unk_24 = sp48->unk_0;
- if (!sp48->unk_2) {}
- } else if (gSoundBanks[phi_s5][phi_a1].unk_2A == 5) {
- gSoundBanks[phi_s5][phi_a1].unk_2A = 4;
+ gSoundBanks[bankId][index].unk_C = req->unk_8;
+ gSoundBanks[bankId][index].sfxId = req->sfxId;
+ gSoundBanks[bankId][index].unk_2A = 1;
+ gSoundBanks[bankId][index].unk_2B = 2;
+ gSoundBanks[bankId][index].freqScale = req->freqScale;
+ gSoundBanks[bankId][index].unk_14 = req->unk_10;
+ gSoundBanks[bankId][index].reverbAdd = req->reverbAdd;
+ gSoundBanks[bankId][index].unk_26 = sp48->unk_2;
+ gSoundBanks[bankId][index].unk_24 = sp48->unk_0;
+ } else if (gSoundBanks[bankId][index].unk_2A == 5) {
+ gSoundBanks[bankId][index].unk_2A = 4;
}
- phi_a1 = 0;
+ index = 0;
}
}
- if (phi_a1 != 0) {
- phi_a1 = gSoundBanks[phi_s5][phi_a1].next;
+ if (index != 0) {
+ index = gSoundBanks[bankId][index].next;
}
}
- if (gSoundBanks[phi_s5][D_8016E1A8[phi_s5]].next != 0xFF && phi_a1 != 0) {
- phi_a1 = D_8016E1A8[phi_s5];
- temp_v0 = &gSoundBanks[phi_s5][phi_a1];
- temp_v0->posX = &req->pos->x;
- temp_v0->posY = &req->pos->y;
- temp_v0->posZ = &req->pos->z;
- temp_v0->unk_C = req->unk_8;
- temp_v0->freqScale = req->freqScale;
- temp_v0->unk_14 = req->unk_10;
- temp_v0->reverbAdd = req->reverbAdd;
+ if (gSoundBanks[bankId][D_8016E1A8[bankId]].next != 0xFF && index != 0) {
+ index = D_8016E1A8[bankId];
+ entry = &gSoundBanks[bankId][index];
+ entry->posX = &req->pos->x;
+ entry->posY = &req->pos->y;
+ entry->posZ = &req->pos->z;
+ entry->unk_C = req->unk_8;
+ entry->freqScale = req->freqScale;
+ entry->unk_14 = req->unk_10;
+ entry->reverbAdd = req->reverbAdd;
sp48 = &D_8013331C[SFX_BANK_SHIFT(req->sfxId)][SFX_INDEX(req->sfxId)];
- temp_v0->unk_26 = sp48->unk_2;
- temp_v0->unk_24 = sp48->unk_0;
- temp_v0->unk_28 = req->sfxId;
- temp_v0->unk_2A = 1;
- temp_v0->unk_2B = 2;
- temp_v0->prev = D_8016E1A0[phi_s5];
- gSoundBanks[phi_s5][D_8016E1A0[phi_s5]].next = D_8016E1A8[phi_s5];
- D_8016E1A0[phi_s5] = D_8016E1A8[phi_s5];
- D_8016E1A8[phi_s5] = gSoundBanks[phi_s5][D_8016E1A8[phi_s5]].next;
- gSoundBanks[phi_s5][D_8016E1A8[phi_s5]].prev = 0xFF;
- temp_v0->next = 0xFF;
+ entry->unk_26 = sp48->unk_2;
+ entry->unk_24 = sp48->unk_0;
+ entry->sfxId = req->sfxId;
+ entry->unk_2A = 1;
+ entry->unk_2B = 2;
+ entry->prev = D_8016E1A0[bankId];
+ gSoundBanks[bankId][D_8016E1A0[bankId]].next = D_8016E1A8[bankId];
+ D_8016E1A0[bankId] = D_8016E1A8[bankId];
+ D_8016E1A8[bankId] = gSoundBanks[bankId][D_8016E1A8[bankId]].next;
+ gSoundBanks[bankId][D_8016E1A8[bankId]].prev = 0xFF;
+ entry->next = 0xFF;
}
}
-#else
-void Audio_ProcessSoundRequest(void);
-#pragma GLOBAL_ASM("asm/non_matchings/code/code_800F7260/Audio_ProcessSoundRequest.s")
-#endif
void func_800F7B54(u8 bankId, u8 bankIndex) {
SoundBankEntry* entry = &gSoundBanks[bankId][bankIndex];
@@ -351,9 +342,9 @@ void func_800F7CEC(u8 arg0) {
phi_s4 = gSoundBanks[arg0][0].next;
phi_s0 = 0;
while (phi_s4 != 0xFF) {
- if ((1 == gSoundBanks[arg0][phi_s4].unk_2A) && (gSoundBanks[arg0][phi_s4].unk_28 & 0xC00)) {
+ if ((1 == gSoundBanks[arg0][phi_s4].unk_2A) && (gSoundBanks[arg0][phi_s4].sfxId & 0xC00)) {
gSoundBanks[arg0][phi_s4].unk_2B--;
- } else if (!(gSoundBanks[arg0][phi_s4].unk_28 & 0xC00) && (gSoundBanks[arg0][phi_s4].unk_2A == 5)) {
+ } else if (!(gSoundBanks[arg0][phi_s4].sfxId & 0xC00) && (gSoundBanks[arg0][phi_s4].unk_2A == 5)) {
Audio_QueueCmdS8((gSoundBanks[arg0][phi_s4].unk_2E << 8) | 0x6020000, 0);
func_800F7B54(arg0, phi_s4);
}
@@ -374,10 +365,10 @@ void func_800F7CEC(u8 arg0) {
} else {
if (entry->dist > 0x7FFFFFD0) {
entry->dist = 0x70000008;
- osSyncPrintf(D_80133344, entry->unk_28, entry->posX, entry->posZ, *entry->posX,
- *entry->posY, *entry->posZ);
+ osSyncPrintf(D_80133344, entry->sfxId, entry->posX, entry->posZ, *entry->posX, *entry->posY,
+ *entry->posZ);
}
- temp3 = entry->unk_28;
+ temp3 = entry->sfxId;
entry->unk_20 = (u32)entry->dist + (SQ(0xFF - spA9) * 0x1690) + temp3 - temp3;
if (*entry->posZ < 0.0f) {
entry->unk_20 += (s32)(-*entry->posZ * 6.0f);
@@ -386,7 +377,7 @@ void func_800F7CEC(u8 arg0) {
if (entry->dist > SQ(1e5f)) {
if (entry->unk_2A == 4) {
Audio_QueueCmdS8((entry->unk_2E << 8) | 0x6020000, 0);
- if (entry->unk_28 & 0xC00) {
+ if (entry->sfxId & 0xC00) {
func_800F7B54(arg0, phi_s4);
phi_s4 = phi_s0;
}
@@ -431,7 +422,7 @@ void func_800F7CEC(u8 arg0) {
} else {
entry = &gSoundBanks[arg0][temp_s4_3[0].unk_4];
if (entry->unk_2A == 4) {
- if (entry->unk_28 & 0xC00) {
+ if (entry->sfxId & 0xC00) {
func_800F7B54(arg0, temp_s4_3->unk_4);
} else {
entry->unk_2A = 1;
@@ -512,11 +503,11 @@ void func_800F8480(u8 bankId) {
}
Audio_SetSoundProperties(bankId, bankIndex, D_8016E260);
Audio_QueueCmdS8(0x06020000 | ((D_8016E260 & 0xFF) << 8), 1);
- Audio_QueueCmdS8(0x06020000 | ((D_8016E260 & 0xFF) << 8) | 4, entry->unk_28 & 0xFF);
+ Audio_QueueCmdS8(0x06020000 | ((D_8016E260 & 0xFF) << 8) | 4, entry->sfxId & 0xFF);
if (D_80130570[bankId] != 0) {
- Audio_QueueCmdS8(0x06020000 | ((D_8016E260 & 0xFF) << 8) | 5, (entry->unk_28 & 0x100) >> 8);
+ Audio_QueueCmdS8(0x06020000 | ((D_8016E260 & 0xFF) << 8) | 5, (entry->sfxId & 0x100) >> 8);
}
- if (entry->unk_28 & 0xC00) {
+ if (entry->sfxId & 0xC00) {
entry->unk_2A = 4;
} else {
entry->unk_2A = 5;
@@ -525,7 +516,7 @@ void func_800F8480(u8 bankId) {
func_800F7B54(bankId, bankIndex);
} else if (entry->unk_2A == 3) {
Audio_SetSoundProperties(bankId, bankIndex, D_8016E260);
- if (entry->unk_28 & 0xC00) {
+ if (entry->sfxId & 0xC00) {
entry->unk_2A = 4;
} else {
entry->unk_2A = 5;
@@ -552,7 +543,7 @@ void func_800F87A0(u8 bankId) {
}
bankIndex = gSoundBanks[bankId][0].next;
}
- cmp.unk_28 = bankId << 12;
+ cmp.sfxId = bankId << 12;
Audio_RemoveMatchingSoundRequests(0, &cmp);
}
@@ -581,7 +572,7 @@ void func_800F89A0(u8 bankId, Vec3f* pos) {
SoundBankEntry cmp;
func_800F8884(bankId, pos);
- cmp.unk_28 = bankId << 12;
+ cmp.sfxId = bankId << 12;
cmp.posX = &pos->x;
Audio_RemoveMatchingSoundRequests(1, &cmp);
}
@@ -605,7 +596,7 @@ void func_800F8A44(Vec3f* pos, u16 sfxId) {
while (bankIndex != 0xFF) {
entry = &gSoundBanks[SFX_BANK(sfxId)][bankIndex];
- if (entry->posX == &pos->x && entry->unk_28 == sfxId) {
+ if (entry->posX == &pos->x && entry->sfxId == sfxId) {
if (entry->unk_2A >= 3) {
Audio_QueueCmdS8(0x06020000 | ((entry->unk_2E & 0xFF) << 8), 0);
}
@@ -621,7 +612,7 @@ void func_800F8A44(Vec3f* pos, u16 sfxId) {
}
}
cmp.posX = &pos->x;
- cmp.unk_28 = sfxId;
+ cmp.sfxId = sfxId;
Audio_RemoveMatchingSoundRequests(3, &cmp);
}
@@ -633,7 +624,7 @@ void func_800F8BA0(u8 arg0, u16 sfxId) {
while (bankIndex != 0xFF) {
entry = &gSoundBanks[SFX_BANK(sfxId)][bankIndex];
- if (entry->unk_C == arg0 && entry->unk_28 == sfxId) {
+ if (entry->unk_C == arg0 && entry->sfxId == sfxId) {
if (entry->unk_2A >= 3) {
Audio_QueueCmdS8(0x06020000 | ((entry->unk_2E & 0xFF) << 8), 0);
}
@@ -648,7 +639,7 @@ void func_800F8BA0(u8 arg0, u16 sfxId) {
}
}
cmp.unk_C = arg0;
- cmp.unk_28 = sfxId;
+ cmp.sfxId = sfxId;
Audio_RemoveMatchingSoundRequests(4, &cmp);
}
@@ -660,7 +651,7 @@ void Audio_StopSfx(u32 sfxId) {
while (bankIndex != 0xFF) {
entry = &gSoundBanks[SFX_BANK(sfxId)][bankIndex];
- if (entry->unk_28 == sfxId) {
+ if (entry->sfxId == sfxId) {
if (entry->unk_2A >= 3) {
Audio_QueueCmdS8(0x06020000 | ((entry->unk_2E & 0xFF) << 8), 0);
}
@@ -672,7 +663,7 @@ void Audio_StopSfx(u32 sfxId) {
}
bankIndex = gSoundBanks[SFX_BANK(sfxId)][bankIndex2].next;
}
- cmp.unk_28 = sfxId;
+ cmp.sfxId = sfxId;
Audio_RemoveMatchingSoundRequests(5, &cmp);
}
@@ -722,7 +713,7 @@ u8 Audio_IsSfxPlaying(u32 sfxId) {
while (bankIndex != 0xFF) {
entry = &gSoundBanks[SFX_BANK(sfxId)][bankIndex];
- if (entry->unk_28 == sfxId) {
+ if (entry->sfxId == sfxId) {
return true;
}
bankIndex = entry->next;