summaryrefslogtreecommitdiff
path: root/src/audio/load.c
diff options
context:
space:
mode:
authorMegaMech <MegaMech@users.noreply.github.com>2022-04-17 00:11:40 -0600
committerGitHub <noreply@github.com>2022-04-16 23:11:40 -0700
commite4e5f91be58aa5a08eb3b05ca1ea7803c8d91afa (patch)
treeeb9017e043bff83a3f3e1b1398db5cba5b5f657c /src/audio/load.c
parent13a11f0ffa97db0efee0e3ba5ab187d9f537aa92 (diff)
audio load.c decomp (#176)
Diffstat (limited to 'src/audio/load.c')
-rw-r--r--src/audio/load.c721
1 files changed, 347 insertions, 374 deletions
diff --git a/src/audio/load.c b/src/audio/load.c
index 8dbd8cee0..c0f39c0a4 100644
--- a/src/audio/load.c
+++ b/src/audio/load.c
@@ -1,145 +1,248 @@
#include <ultra64.h>
#include <macros.h>
+#include "load.h"
+#include "data.h"
+#include "heap.h"
+#include "internal.h"
+
+#define ALIGN16(val) (((val) + 0xF) & ~0xF)
+struct SharedDma {
+ /*0x0*/ u8 *buffer; // target, points to pre-allocated buffer
+ /*0x4*/ uintptr_t source; // device address
+ /*0x8*/ u16 sizeUnused; // set to bufSize, never read
+ /*0xA*/ u16 bufSize; // size of buffer
+ /*0xC*/ u8 unused2; // set to 0, never read
+ /*0xD*/ u8 reuseIndex; // position in sSampleDmaReuseQueue1/2, if ttl == 0
+ /*0xE*/ u8 ttl; // duration after which the DMA can be discarded
+}; // size = 0x10
-#ifdef MIPS_TO_C
-//generated by mips_to_c commit 3c3b0cede1a99430bfd3edf8d385802b94f91307
-? osPiStartDma(? *, ?, ?, s32, void *, u32, OSMesgQueue *); // extern
extern OSMesgQueue D_803B6720;
-extern ? D_803B6740;
-
-void func_800BAA80(s32 arg0, void *arg1, u32 arg2) {
- osInvalDCache(arg1, arg2);
- osPiStartDma(&D_803B6740, 1, 0, arg0, arg1, arg2, &D_803B6720);
- osRecvMesg(&D_803B6720, NULL, 1);
+extern OSIoMesg D_803B6740;
+
+extern OSMesgQueue gCurrAudioFrameDmaQueue; // gCurrAudioFrameDmaQueue
+extern OSMesg gCurrAudioFrameDmaMesgBufs[AUDIO_FRAME_DMA_QUEUE_SIZE]; // gCurrAudioFrameDmaMesgBufs
+extern OSIoMesg gCurrAudioFrameDmaIoMesgBufs[AUDIO_FRAME_DMA_QUEUE_SIZE]; // gCurrAudioFrameDmaIoMesgBufs
+
+extern struct SharedDma sSampleDmas[0x60]; // sSampleDmas
+extern u32 gSampleDmaNumListItems; // gSampleDmaNumListItems
+extern u32 sSampleDmaListSize1; // sSampleDmaListSize1
+extern s32 D_803B6E60; // sUnused80226B40
+
+extern u8 sSampleDmaReuseQueue1[256]; // sSampleDmaReuseQueue1
+extern u8 sSampleDmaReuseQueue2[256]; // sSampleDmaReuseQueue2
+extern u8 sSampleDmaReuseQueueTail1; // sSampleDmaReuseQueueTail1
+extern u8 sSampleDmaReuseQueueTail2; // sSampleDmaReuseQueueTail2
+extern u8 sSampleDmaReuseQueueHead1; // sSampleDmaReuseQueueHead1
+extern u8 sSampleDmaReuseQueueHead2; // sSampleDmaReuseQueueHead2
+
+
+
+extern void *soundAlloc(struct SoundAllocPool *pool, u32 size);
+
+/**
+ * Performs an immediate DMA copy
+ */
+// audio_dma_copy_immediate
+void audio_dma_copy_immediate(uintptr_t devAddr, void *vAddr, size_t nbytes) {
+ stubbed_printf_3("Romcopy %x -> %x ,size %x\n", devAddr, vAddr, nbytes);
+ osInvalDCache(vAddr, nbytes);
+ osPiStartDma(&D_803B6740, OS_MESG_PRI_HIGH, OS_READ, devAddr, vAddr, nbytes, &D_803B6720);
+ osRecvMesg(&D_803B6720, NULL, OS_MESG_BLOCK);
+ stubbed_printf_0("Romcopyend\n");
}
-#else
-GLOBAL_ASM("asm/non_matchings/audio/load/func_800BAA80.s")
-#endif
-#ifdef MIPS_TO_C
-//generated by mips_to_c commit 3c3b0cede1a99430bfd3edf8d385802b94f91307
-? osPiStartDma(s32, ?, ?, s32, void *, u32, s32); // extern
-
-void func_800BAAF8(s32 arg0, void *arg1, u32 arg2, s32 arg3, s32 arg4) {
- osInvalDCache(arg1, arg2);
- osPiStartDma(arg4, 0, 0, arg0, arg1, arg2, arg3);
+const char audioString34[] = "CAUTION:WAVE CACHE FULL %d";
+const char audioString35[] = "LOAD Rom :%x -> Ram :%x Len:%x\n";
+const char audioString36[] = "BASE %x %x\n";
+const char audioString37[] = "LOAD %x %x %x\n";
+const char audioString38[] = "INSTTOP %x\n";
+const char audioString39[] = "INSTMAP[0] %x\n";
+const char audioString40[] = "already flags %d\n";
+const char audioString41[] = "already flags %d\n";
+const char audioString42[] = "ERR:SLOW BANK DMA BUSY\n";
+const char audioString43[] = "ERR:SLOW DMA BUSY\n";
+const char audioString44[] = "Check %d bank %d\n";
+const char audioString45[] = "Cache Check\n";
+const char audioString46[] = "NO BANK ERROR\n";
+const char audioString47[] = "BANK %d LOADING START\n";
+const char audioString48[] = "BANK %d LOAD MISS (NO MEMORY)!\n";
+const char audioString49[] = "BANK %d ALREADY CACHED\n";
+const char audioString50[] = "BANK LOAD MISS! FOR %d\n";
+
+
+const char audioString51[] = "Seq %d Loading Start\n";
+
+const char audioString52[] = "Heap Overflow Error\n";
+
+const char asdf[] = "SEQ %d ALREADY CACHED\n";
+const char fdsa[] = "Ok,one bank slow load Start \n";
+const char af[] = "Sorry,too many %d bank is none.fast load Start \n";
+
+
+
+/**
+ * Performs an asynchronus (normal priority) DMA copy
+ */
+//audio_dma_copy_async
+void func_800BAAF8(uintptr_t devAddr, void *vAddr, size_t nbytes, OSMesgQueue *queue, OSIoMesg *mesg) {
+ osInvalDCache(vAddr, nbytes);
+ osPiStartDma(mesg, OS_MESG_PRI_NORMAL, OS_READ, devAddr, vAddr, nbytes, queue);
}
-#else
-GLOBAL_ASM("asm/non_matchings/audio/load/func_800BAAF8.s")
-#endif
+//#else
+//GLOBAL_ASM("asm/non_matchings/audio/load/func_800BAAF8.s")
+//#endif
-#ifdef MIPS_TO_C
+//#ifdef MIPS_TO_C
//generated by mips_to_c commit 3c3b0cede1a99430bfd3edf8d385802b94f91307
-? osPiStartDma(s32, ?, ?, s32, void *, u32, s32); // extern
-
-void func_800BAB58(s32 *arg0, void **arg1, s32 *arg2, s32 arg3, s32 arg4) {
- s32 temp_v0;
- u32 phi_s0;
+//? osPiStartDma(s32, ?, ?, s32, void *, u32, s32); // extern
+
+
+/**
+ * Performs a partial asynchronous (normal priority) DMA copy. This is limited
+ * to 0x1000 bytes transfer at once.
+ */
+// audio_dma_partial_copy_async
+void func_800BAB58(uintptr_t *devAddr, u8 **vAddr, ssize_t *remaining, OSMesgQueue *queue, OSIoMesg *mesg) {
+ ssize_t transfer = (*remaining >= 0x1000 ? 0x1000 : *remaining);
+ *remaining -= transfer;
+ osInvalDCache(*vAddr, transfer);
+ osPiStartDma(mesg, OS_MESG_PRI_NORMAL, OS_READ, *devAddr, *vAddr, transfer, queue);
+ *devAddr += transfer;
+ *vAddr += transfer;
+}
+//#else
+//GLOBAL_ASM("asm/non_matchings/audio/load/func_800BAB58.s")
+//#endif
+
+// decrease_sample_dma_ttls
+
+void func_800BAC04() {
+ u32 i;
+
+ for (i = 0; i < sSampleDmaListSize1; i++) {
+ struct SharedDma *temp = &sSampleDmas[i];
+ if (temp->ttl != 0) {
+ temp->ttl--;
+ if (temp->ttl == 0) {
+ temp->reuseIndex = sSampleDmaReuseQueueHead1;
+ sSampleDmaReuseQueue1[sSampleDmaReuseQueueHead1++] = (u8) i;
+ }
+ }
+ }
- temp_v0 = *arg2;
- phi_s0 = temp_v0;
- if (temp_v0 >= 0x1000) {
- phi_s0 = 0x1000;
+ for (i = sSampleDmaListSize1; i < gSampleDmaNumListItems; i++) {
+ struct SharedDma *temp = &sSampleDmas[i];
+ if (temp->ttl != 0) {
+ temp->ttl--;
+ if (temp->ttl == 0) {
+ temp->reuseIndex = sSampleDmaReuseQueueHead2;
+ sSampleDmaReuseQueue2[sSampleDmaReuseQueueHead2++] = (u8) i;
+ }
+ }
}
- *arg2 = temp_v0 - phi_s0;
- osInvalDCache(*arg1, phi_s0);
- osPiStartDma(arg4, 0, 0, *arg0, *arg1, phi_s0, arg3);
- *arg0 = *arg0 + phi_s0;
- *arg1 = *arg1 + phi_s0;
+
+ D_803B6E60 = 0;
}
-#else
-GLOBAL_ASM("asm/non_matchings/audio/load/func_800BAB58.s")
-#endif
#ifdef MIPS_TO_C
-//generated by mips_to_c commit 3c3b0cede1a99430bfd3edf8d385802b94f91307
-extern ? D_803B6758;
-extern u32 D_803B6E58;
-extern u32 D_803B6E5C;
-extern s32 D_803B6E60;
-extern ? D_803B6E68;
-extern ? D_803B6F68;
-extern u8 D_803B706A;
-extern u8 D_803B706B;
-
-void func_800BAC04(void) {
- u32 temp_v0;
- u32 temp_v0_2;
- u8 temp_t4;
- u8 temp_t6;
- u8 temp_t6_2;
- u8 temp_t8;
- u8 temp_v1;
- u8 temp_v1_2;
- u8 temp_v1_3;
- u8 temp_v1_4;
- ? *phi_a0;
- s8 phi_v0;
- void *phi_a0_2;
- s8 phi_v0_2;
-
- phi_a0 = &D_803B6758;
- phi_v0 = 0;
- if (D_803B6E5C != 0) {
- do {
- temp_v1 = phi_a0->unkE;
- temp_t6 = temp_v1 - 1;
- if (temp_v1 != 0) {
- phi_a0->unkE = temp_t6;
- if ((temp_t6 & 0xFF) == 0) {
- temp_v1_2 = D_803B706A;
- temp_t8 = D_803B706A;
- *(&D_803B6E68 + temp_v1_2) = phi_v0;
- D_803B706A = temp_v1_2 + 1;
- phi_a0->unkD = temp_t8;
+// dma_sample_data 3000 score diff
+void *func_800BAD0C(uintptr_t devAddr, u32 size, s32 arg2, u8 *dmaIndexRef) {
+ s32 hasDma = FALSE;
+ struct SharedDma *dma;
+ uintptr_t dmaDevAddr;
+ u32 transfer;
+ u32 i;
+ u32 dmaIndex;
+ ssize_t bufferPos;
+ UNUSED u32 pad;
+
+ if (arg2 != 0 || *dmaIndexRef >= sSampleDmaListSize1) {
+ for (i = sSampleDmaListSize1; i < gSampleDmaNumListItems; i++) {
+ dma = &sSampleDmas[i];
+ bufferPos = devAddr - dma->source;
+ if (0 <= bufferPos && (size_t) bufferPos <= dma->bufSize - size) {
+ // We already have a DMA request for this memory range.
+ if (dma->ttl == 0 && sSampleDmaReuseQueueTail2 != sSampleDmaReuseQueueHead2) {
+ // Move the DMA out of the reuse queue, by swapping it with the
+ // tail, and then incrementing the tail.
+ if (dma->reuseIndex != sSampleDmaReuseQueueTail2) {
+ sSampleDmaReuseQueue2[dma->reuseIndex] =
+ sSampleDmaReuseQueue2[sSampleDmaReuseQueueTail2];
+ sSampleDmas[sSampleDmaReuseQueue2[sSampleDmaReuseQueueTail2]].reuseIndex =
+ dma->reuseIndex;
+ }
+ sSampleDmaReuseQueueTail2++;
}
+ dma->ttl = 60;
+ *dmaIndexRef = (u8) i;
+ return &dma->buffer[(devAddr - dma->source)];
}
- temp_v0 = phi_v0 + 1;
- phi_a0 += 0x10;
- phi_v0 = temp_v0;
- } while (temp_v0 < D_803B6E5C);
- }
- phi_v0_2 = D_803B6E5C;
- if (D_803B6E5C < D_803B6E58) {
- phi_a0_2 = (D_803B6E5C * 0x10) + &D_803B6758;
- do {
- temp_v1_3 = phi_a0_2->unkE;
- temp_t4 = temp_v1_3 - 1;
- if (temp_v1_3 != 0) {
- phi_a0_2->unkE = temp_t4;
- if ((temp_t4 & 0xFF) == 0) {
- temp_v1_4 = D_803B706B;
- temp_t6_2 = D_803B706B;
- *(&D_803B6F68 + temp_v1_4) = phi_v0_2;
- D_803B706B = temp_v1_4 + 1;
- phi_a0_2->unkD = temp_t6_2;
+ }
+
+ if (sSampleDmaReuseQueueTail2 != sSampleDmaReuseQueueHead2 && arg2 != 0) {
+ // Allocate a DMA from reuse queue 2. This queue can be empty, since
+ // TTL 60 is pretty large.
+ dmaIndex = sSampleDmaReuseQueue2[sSampleDmaReuseQueueTail2];
+ sSampleDmaReuseQueueTail2++;
+ dma = sSampleDmas + dmaIndex;
+ hasDma = TRUE;
+ }
+ } else {
+ dma = sSampleDmas;
+ dma += *dmaIndexRef;
+ bufferPos = devAddr - dma->source;
+ if (0 <= bufferPos && (size_t) bufferPos <= dma->bufSize - size) {
+ // We already have DMA for this memory range.
+ if (dma->ttl == 0) {
+ // Move the DMA out of the reuse queue, by swapping it with the
+ // tail, and then incrementing the tail.
+ if (dma->reuseIndex != sSampleDmaReuseQueueTail1) {
+ if (1) {
+ }
+ sSampleDmaReuseQueue1[dma->reuseIndex] =
+ sSampleDmaReuseQueue1[sSampleDmaReuseQueueTail1];
+ sSampleDmas[sSampleDmaReuseQueue1[sSampleDmaReuseQueueTail1]].reuseIndex =
+ dma->reuseIndex;
}
+ sSampleDmaReuseQueueTail1++;
}
- temp_v0_2 = phi_v0_2 + 1;
- phi_a0_2 += 0x10;
- phi_v0_2 = temp_v0_2;
- } while (temp_v0_2 < D_803B6E58);
+ dma->ttl = 2;
+ return dma->buffer + (devAddr - dma->source);
+ }
}
- D_803B6E60 = 0;
+
+ if (!hasDma) {
+ // Allocate a DMA from reuse queue 1. This queue will hopefully never
+ // be empty, since TTL 2 is so small.
+ dmaIndex = sSampleDmaReuseQueue1[sSampleDmaReuseQueueTail1++];
+ dma = sSampleDmas + dmaIndex;
+ hasDma = TRUE;
+ }
+
+ transfer = dma->bufSize;
+ dmaDevAddr = devAddr & ~0xF;
+ dma->ttl = 2;
+ dma->source = dmaDevAddr;
+ dma->sizeUnused = transfer;
+ osPiStartDma(&gCurrAudioFrameDmaIoMesgBufs[gCurrAudioFrameDmaCount++], OS_MESG_PRI_NORMAL,
+ OS_READ, dmaDevAddr, dma->buffer, transfer, &gCurrAudioFrameDmaQueue);
+ *dmaIndexRef = dmaIndex;
+ return (devAddr - dmaDevAddr) + dma->buffer;
}
-#else
-GLOBAL_ASM("asm/non_matchings/audio/load/func_800BAC04.s")
-#endif
-#ifdef MIPS_TO_C
//generated by mips_to_c commit 3c3b0cede1a99430bfd3edf8d385802b94f91307
? osPiStartDma(void *, ?, ?, s32, s32, s32, ? *); // extern
-extern ? D_803B6008;
-extern ? D_803B6120;
-extern ? D_803B6758;
-extern u32 D_803B6E58;
-extern u32 D_803B6E5C;
-extern ? D_803B6E68;
-extern ? D_803B6F68;
-extern u8 D_803B7068;
-extern u8 D_803B7069;
-extern u8 D_803B706B;
-extern s32 D_803B70BC;
+extern ? gCurrAudioFrameDmaQueue;
+extern ? gCurrAudioFrameDmaIoMesgBufs;
+extern ? sSampleDmas;
+extern u32 gSampleDmaNumListItems;
+extern u32 sSampleDmaListSize1;
+extern ? sSampleDmaReuseQueue1;
+extern ? sSampleDmaReuseQueue2;
+extern u8 sSampleDmaReuseQueueTail1;
+extern u8 sSampleDmaReuseQueueTail2;
+extern u8 sSampleDmaReuseQueueHead2;
+extern s32 gCurrAudioFrameDmaCount;
s32 func_800BAD0C(s32 arg0, s32 arg1, s32 arg2, u8 *arg3) {
void *sp40;
@@ -178,25 +281,25 @@ s32 func_800BAD0C(s32 arg0, s32 arg1, s32 arg2, u8 *arg3) {
phi_t3 = 0;
phi_t3 = 0;
- if ((arg2 != 0) || (temp_a1 = D_803B6E5C, temp_v0 = *arg3, phi_v1 = 0, ((temp_v0 < temp_a1) == 0))) {
- temp_a1_2 = D_803B6E58;
- temp_v1_3 = D_803B6E5C;
+ if ((arg2 != 0) || (temp_a1 = sSampleDmaListSize1, temp_v0 = *arg3, phi_v1 = 0, ((temp_v0 < temp_a1) == 0))) {
+ temp_a1_2 = gSampleDmaNumListItems;
+ temp_v1_3 = sSampleDmaListSize1;
phi_v1_2 = temp_v1_3;
if (temp_v1_3 < temp_a1_2) {
- phi_a0 = (temp_v1_3 * 0x10) + &D_803B6758;
+ phi_a0 = (temp_v1_3 * 0x10) + &sSampleDmas;
loop_4:
temp_v0_4 = arg0 - phi_a0->unk4;
if ((temp_v0_4 >= 0) && ((phi_a0->unkA - arg1) >= temp_v0_4)) {
if (phi_a0->unkE == 0) {
- temp_a1_3 = D_803B7069;
- if (D_803B706B != temp_a1_3) {
+ temp_a1_3 = sSampleDmaReuseQueueTail2;
+ if (sSampleDmaReuseQueueHead2 != temp_a1_3) {
temp_a3 = phi_a0->unkD;
- temp_v0_5 = &D_803B6F68 + temp_a1_3;
+ temp_v0_5 = &sSampleDmaReuseQueue2 + temp_a1_3;
if (temp_a1_3 != temp_a3) {
- *(&D_803B6F68 + temp_a3) = *temp_v0_5;
- (&D_803B6758 + (*temp_v0_5 * 0x10))->unkD = phi_a0->unkD;
+ *(&sSampleDmaReuseQueue2 + temp_a3) = *temp_v0_5;
+ (&sSampleDmas + (*temp_v0_5 * 0x10))->unkD = phi_a0->unkD;
}
- D_803B7069 = temp_a1_3 + 1;
+ sSampleDmaReuseQueueTail2 = temp_a1_3 + 1;
}
}
phi_a0->unkE = 0x3C;
@@ -213,18 +316,18 @@ loop_4:
goto loop_4;
}
block_14:
- temp_a1_4 = D_803B7069;
+ temp_a1_4 = sSampleDmaReuseQueueTail2;
phi_t0_2 = sp40;
- if ((D_803B706B != temp_a1_4) && (arg2 != 0)) {
- temp_t2 = *(&D_803B6F68 + temp_a1_4);
- D_803B7069 = temp_a1_4 + 1;
+ if ((sSampleDmaReuseQueueHead2 != temp_a1_4) && (arg2 != 0)) {
+ temp_t2 = *(&sSampleDmaReuseQueue2 + temp_a1_4);
+ sSampleDmaReuseQueueTail2 = temp_a1_4 + 1;
sp30 = temp_t2;
phi_t3 = 1;
- phi_t0_2 = &D_803B6758 + (temp_t2 * 0x10);
+ phi_t0_2 = &sSampleDmas + (temp_t2 * 0x10);
}
goto block_27;
}
- temp_t0 = &D_803B6758 + (temp_v0 * 0x10);
+ temp_t0 = &sSampleDmas + (temp_v0 * 0x10);
phi_t0 = temp_t0;
phi_t0_2 = temp_t0;
if (temp_a1 != 0) {
@@ -234,19 +337,19 @@ loop_19:
phi_v1 = temp_v1;
if ((temp_v0_2 >= 0) && ((phi_t0->unkA - arg1) >= temp_v0_2)) {
if (phi_t0->unkE == 0) {
- temp_v1_2 = D_803B7068;
+ temp_v1_2 = sSampleDmaReuseQueueTail1;
temp_a0 = phi_t0->unkD;
- temp_v0_3 = &D_803B6E68 + temp_v1_2;
+ temp_v0_3 = &sSampleDmaReuseQueue1 + temp_v1_2;
if (temp_v1_2 != temp_a0) {
- *(&D_803B6E68 + temp_a0) = *temp_v0_3;
- (&D_803B6758 + (*temp_v0_3 * 0x10))->unkD = phi_t0->unkD;
+ *(&sSampleDmaReuseQueue1 + temp_a0) = *temp_v0_3;
+ (&sSampleDmas + (*temp_v0_3 * 0x10))->unkD = phi_t0->unkD;
}
- D_803B7068 = temp_v1_2 + 1;
+ sSampleDmaReuseQueueTail1 = temp_v1_2 + 1;
}
phi_t0->unkE = 2;
return (phi_t0->unk0 + arg0) - phi_t0->unk4;
}
- temp_t0_2 = &D_803B6758 + (phi_v1 * 0x10);
+ temp_t0_2 = &sSampleDmas + (phi_v1 * 0x10);
phi_t0 = temp_t0_2;
phi_t0_2 = temp_t0_2;
if (temp_v1 >= temp_a1) {
@@ -257,10 +360,10 @@ loop_19:
block_27:
phi_t2 = sp30;
if (phi_t3 == 0) {
- temp_v1_5 = D_803B7068;
- temp_t2_2 = *(&D_803B6E68 + temp_v1_5);
- D_803B7068 = temp_v1_5 + 1;
- phi_t0_2 = &D_803B6758 + (temp_t2_2 * 0x10);
+ temp_v1_5 = sSampleDmaReuseQueueTail1;
+ temp_t2_2 = *(&sSampleDmaReuseQueue1 + temp_v1_5);
+ sSampleDmaReuseQueueTail1 = temp_v1_5 + 1;
+ phi_t0_2 = &sSampleDmas + (temp_t2_2 * 0x10);
phi_t2 = temp_t2_2;
}
temp_v0_6 = phi_t0_2->unkA;
@@ -268,12 +371,12 @@ block_27:
phi_t0_2->unkE = 2;
phi_t0_2->unk4 = temp_s0;
phi_t0_2->unk8 = temp_v0_6;
- temp_v1_6 = D_803B70BC;
+ temp_v1_6 = gCurrAudioFrameDmaCount;
temp_t9 = temp_v1_6 * 0x18;
- D_803B70BC = temp_v1_6 + 1;
+ gCurrAudioFrameDmaCount = temp_v1_6 + 1;
sp30 = phi_t2;
- sp40 = phi_t0_2;
- osPiStartDma(temp_t9 + &D_803B6120, 0, 0, temp_s0, phi_t0_2->unk0, temp_v0_6, &D_803B6008);
+ sp40 = phi_t0_2;./
+ osPiStartDma(temp_t9 + &gCurrAudioFrameDmaIoMesgBufs, 0, 0, temp_s0, phi_t0_2->unk0, temp_v0_6, &gCurrAudioFrameDmaQueue);
*arg3 = phi_t2;
return (arg0 - temp_s0) + phi_t0_2->unk0;
}
@@ -281,223 +384,95 @@ block_27:
GLOBAL_ASM("asm/non_matchings/audio/load/func_800BAD0C.s")
#endif
-#ifdef MIPS_TO_C
-//generated by mips_to_c commit 3c3b0cede1a99430bfd3edf8d385802b94f91307
-s32 func_800B8FFC(? *, s32, u32); // extern
-extern ? D_803BFBE8;
-extern ? D_803B6758;
-extern u32 D_803B6E58;
-extern u32 D_803B6E5C;
-extern s8 D_803B6E68;
-extern ? D_803B6F68;
-extern s8 D_803B7068;
-extern s8 D_803B7069;
-extern s8 D_803B706A;
-extern s8 D_803B706B;
-extern s16 D_803B7088;
-extern s32 D_803B70A8;
-extern s32 D_803B70B0;
-
-void func_800BB030(s32 arg0, u32 arg2) {
- s32 temp_a1;
- s32 temp_a1_2;
- s32 temp_s0;
- s32 temp_s0_3;
- s32 temp_v0;
- s32 temp_v0_3;
- s8 temp_v0_4;
- u32 temp_a1_3;
- u32 temp_a2;
- u32 temp_a2_2;
- u32 temp_a2_3;
- u32 temp_s0_2;
- u32 temp_s0_4;
- u32 temp_v0_2;
- u32 temp_v0_5;
- void *temp_v1;
- void *temp_v1_2;
- s32 phi_a1;
- u32 phi_a2;
- s32 phi_s0;
- s8 phi_s0_2;
- s8 *phi_v0;
- ? *phi_v1;
- void *phi_v0_2;
- s32 phi_a1_2;
- s32 phi_s0_3;
- u32 phi_a2_2;
- s8 phi_s0_4;
- s8 *phi_a0;
- s8 phi_v0_3;
- void *phi_v1_2;
- s32 phi_a3;
- void *phi_v0_4;
- u32 phi_a2_3;
+extern u32 D_803B70A8; // sDmaBufSize
+extern s32 gMaxSimultaneousNotes; // gMaxSimultaneousNotes
+extern struct AudioBufferParametersEU gAudioBufferParameters; // gAudioBufferParameters
+//extern struct SoundAllocPool gNotesAndBuffersPool; // remove when possible. This is in heap.h
+// init_sample_dma_buffers
+void func_800BB030(UNUSED s32 arg0) {
+ s32 i;
+#define j i
D_803B70A8 = 0x5A0;
- phi_a1 = 0x5A0;
- phi_a2 = arg2;
- phi_s0 = 0;
- phi_s0_3 = 0;
- if ((D_803B70B0 * 3 * D_803B7088) > 0) {
-loop_1:
- temp_v0 = func_800B8FFC(&D_803BFBE8, phi_a1, phi_a2);
- temp_a2 = D_803B6E58;
- temp_v1 = &D_803B6758 + (temp_a2 * 0x10);
- temp_v1->unk0 = temp_v0;
- phi_a2 = temp_a2;
- if (temp_v0 == 0) {
- } else {
- temp_a1 = D_803B70A8;
- temp_s0 = phi_s0 + 1;
- temp_v1->unk4 = 0;
- temp_v1->unk8 = 0;
- temp_v1->unkC = 0;
- temp_v1->unkE = 0;
- D_803B6E58 = temp_a2 + 1;
- temp_v1->unkA = temp_a1;
- phi_a1 = temp_a1;
- phi_s0 = temp_s0;
- if (temp_s0 >= (D_803B70B0 * 3 * D_803B7088)) {
-
- } else {
- goto loop_1;
- }
+ for (i = 0; i < gMaxSimultaneousNotes * 3 * gAudioBufferParameters.presetUnk4; i++)
+ {
+ sSampleDmas[gSampleDmaNumListItems].buffer = soundAlloc(&gNotesAndBuffersPool, D_803B70A8);
+ if (sSampleDmas[gSampleDmaNumListItems].buffer == NULL) {
+ break;
}
+ sSampleDmas[gSampleDmaNumListItems].bufSize = D_803B70A8;
+ sSampleDmas[gSampleDmaNumListItems].source = 0;
+ sSampleDmas[gSampleDmaNumListItems].sizeUnused = 0;
+ sSampleDmas[gSampleDmaNumListItems].unused2 = 0;
+ sSampleDmas[gSampleDmaNumListItems].ttl = 0;
+ gSampleDmaNumListItems++;
}
- temp_a2_2 = D_803B6E58;
- phi_s0_2 = 0;
- phi_a2_2 = temp_a2_2;
- if (temp_a2_2 != 0) {
- phi_v0 = &D_803B6E68;
- phi_v1 = &D_803B6758;
- do {
- *phi_v0 = phi_s0_2;
- phi_v1->unkD = phi_s0_2;
- temp_s0_2 = phi_s0_2 + 1;
- phi_s0_2 = temp_s0_2;
- phi_v0 += 1;
- phi_v1 += 0x10;
- } while (temp_s0_2 < temp_a2_2);
+
+ for (i = 0; (u32) i < gSampleDmaNumListItems; i++) {
+ sSampleDmaReuseQueue1[i] = (u8) i;
+ sSampleDmas[i].reuseIndex = (u8) i;
}
- phi_a3 = temp_a2_2;
- if (temp_a2_2 < 0x100) {
- phi_v0_2 = temp_a2_2 + &D_803B6E68;
- do {
- temp_v0_2 = phi_v0_2 + 1;
- temp_v0_2->unk-1 = 0;
- phi_v0_2 = temp_v0_2;
- } while (temp_v0_2 < &D_803B6F68);
+
+ for (j = gSampleDmaNumListItems; j < 0x100; j++) {
+ sSampleDmaReuseQueue1[j] = 0;
}
- D_803B7068 = 0;
- D_803B706A = temp_a2_2;
- D_803B6E5C = temp_a2_2;
+
+ sSampleDmaReuseQueueTail1 = 0;
+ sSampleDmaReuseQueueHead1 = (u8) gSampleDmaNumListItems;
+ sSampleDmaListSize1 = gSampleDmaNumListItems;
+
D_803B70A8 = 0x180;
- if (D_803B70B0 > 0) {
- phi_a1_2 = 0x180;
-loop_13:
- temp_v0_3 = func_800B8FFC(&D_803BFBE8, phi_a1_2, D_803B6E58);
- temp_a2_3 = D_803B6E58;
- temp_s0_3 = phi_s0_3 + 1;
- temp_v1_2 = &D_803B6758 + (temp_a2_3 * 0x10);
- temp_v1_2->unk0 = temp_v0_3;
- phi_s0_3 = temp_s0_3;
- phi_a2_3 = temp_a2_3;
- if (temp_v0_3 == 0) {
-
- } else {
- temp_a1_2 = D_803B70A8;
- temp_v1_2->unk4 = 0;
- temp_v1_2->unk8 = 0;
- temp_v1_2->unkC = 0;
- temp_v1_2->unkE = 0;
- D_803B6E58 = temp_a2_3 + 1;
- temp_v1_2->unkA = temp_a1_2;
- phi_a1_2 = temp_a1_2;
- if (temp_s0_3 >= D_803B70B0) {
- phi_a2_3 = D_803B6E58;
- } else {
- goto loop_13;
- }
+ for (i = 0; i < gMaxSimultaneousNotes; i++) {
+ sSampleDmas[gSampleDmaNumListItems].buffer = soundAlloc(&gNotesAndBuffersPool, D_803B70A8);
+ if (sSampleDmas[gSampleDmaNumListItems].buffer == NULL) {
+ break;
}
- phi_a2_2 = phi_a2_3;
- phi_a3 = phi_a2_3;
+ sSampleDmas[gSampleDmaNumListItems].bufSize = D_803B70A8;
+ sSampleDmas[gSampleDmaNumListItems].source = 0;
+ sSampleDmas[gSampleDmaNumListItems].sizeUnused = 0;
+ sSampleDmas[gSampleDmaNumListItems].unused2 = 0;
+ sSampleDmas[gSampleDmaNumListItems].ttl = 0;
+ gSampleDmaNumListItems++;
}
- temp_a1_3 = D_803B6E5C;
- phi_s0_4 = temp_a1_3;
- if (temp_a1_3 < phi_a2_2) {
- temp_v0_4 = temp_a1_3 * 0;
- phi_a0 = temp_v0_4 + &D_803B6F68;
- phi_v0_3 = temp_v0_4;
- phi_v1_2 = (temp_a1_3 * 0x10) + &D_803B6758;
- do {
- *phi_a0 = phi_s0_4;
- temp_s0_4 = phi_s0_4 + 1;
- phi_v1_2->unkD = phi_v0_3;
- phi_s0_4 = temp_s0_4;
- phi_a0 += 1;
- phi_v0_3 += 1;
- phi_v1_2 += 0x10;
- } while (temp_s0_4 < phi_a2_2);
+
+ for (i = sSampleDmaListSize1; (u32) i < gSampleDmaNumListItems; i++) {
+ sSampleDmaReuseQueue2[i - sSampleDmaListSize1] = (u8) i;
+ sSampleDmas[i].reuseIndex = (u8)(i - sSampleDmaListSize1);
}
- if (phi_a3 < 0x100) {
- phi_v0_4 = phi_a3 + &D_803B6F68;
- do {
- temp_v0_5 = phi_v0_4 + 1;
- temp_v0_5->unk-1 = temp_a1_3;
- phi_v0_4 = temp_v0_5;
- } while (temp_v0_5 < &D_803B7068);
+
+ // This probably meant to touch the range size1..size2 as well... but it
+ // doesn't matter, since these values are never read anyway.
+ for (j = gSampleDmaNumListItems; j < 0x100; j++) {
+ sSampleDmaReuseQueue2[j] = sSampleDmaListSize1;
}
- D_803B7069 = 0;
- D_803B706B = phi_a2_2 - temp_a1_3;
-}
-#else
-GLOBAL_ASM("asm/non_matchings/audio/load/func_800BB030.s")
-#endif
-#ifdef MIPS_TO_C
-//generated by mips_to_c commit 3c3b0cede1a99430bfd3edf8d385802b94f91307
-s32 func_800B8FFC(? *, s32, void *); // extern
-? func_800BAA80(s32, s32, s32, void *); // extern
-extern ? D_803BFBE8;
+ sSampleDmaReuseQueueTail2 = 0;
+ sSampleDmaReuseQueueHead2 = gSampleDmaNumListItems - sSampleDmaListSize1;
+#undef j
+}
-void func_800BB304(void *arg0) {
- s32 sp1C;
- s32 temp_a0;
- s32 temp_a1;
- s32 temp_a1_2;
- s32 temp_a2;
- s32 temp_v0;
- void *temp_a3;
- void *temp_a3_2;
+// Similar to patch_sound, but not really
+s32 func_800BB304(struct AudioBankSample *sample) {
+ //struct AudioBankSample *sample = sound->sample;
+ UNUSED u8 *mem;
- temp_a3 = arg0;
- if (arg0 == 0) {
- return;
+ if (sample == (void *)NULL) {
+ return -1;
}
- if (temp_a3->unk1 == 1) {
- temp_a1 = temp_a3->unk10;
- arg0 = temp_a3;
- temp_v0 = func_800B8FFC(&D_803BFBE8, temp_a1, temp_a3);
- temp_a3_2 = arg0;
- temp_a1_2 = temp_v0;
- if (temp_v0 == 0) {
- return;
+
+ if (sample->loaded == 1) {
+ //temp_a1 = sound->sampleAddr // unk10;
+ mem = soundAlloc(&gNotesAndBuffersPool, sample->sampleSize);
+ //temp_a1_2 = temp_v0;
+ if (mem == (void *)NULL) {
+ return -1;
}
- temp_a0 = temp_a3_2->unk4;
- temp_a2 = temp_a3_2->unk10;
- arg0 = temp_a3_2;
- sp1C = temp_a1_2;
- func_800BAA80(temp_a0, temp_a1_2, temp_a2, temp_a3_2);
- arg0->unk1 = 0x81;
- arg0->unk4 = temp_a1_2;
- // Duplicate return node #6. Try simplifying control flow for better match
+ audio_dma_copy_immediate((uintptr_t)sample->sampleAddr, mem, sample->sampleSize);
+ sample->loaded = 0x81;
+ sample->sampleAddr = mem; // sound->unk4
}
}
-#else
-GLOBAL_ASM("asm/non_matchings/audio/load/func_800BB304.s")
-#endif
#ifdef MIPS_TO_C
//generated by mips_to_c commit 3c3b0cede1a99430bfd3edf8d385802b94f91307
@@ -574,9 +549,9 @@ GLOBAL_ASM("asm/non_matchings/audio/load/func_800BB43C.s")
#ifdef MIPS_TO_C
//generated by mips_to_c commit 3c3b0cede1a99430bfd3edf8d385802b94f91307
-s32 func_800B8FFC(? *, s32, s32); // extern
-? func_800BAA80(s32, s32, s32, s32); // extern
-extern ? D_803BFBE8;
+s32 soundAlloc(? *, s32, s32); // extern
+? audio_dma_copy_immediate(s32, s32, s32, s32); // extern
+extern ? gNotesAndBuffersPool;
void func_800BB484(void **arg0, s32 arg1, s32 arg2) {
void *sp2C;
@@ -604,14 +579,14 @@ void func_800BB484(void **arg0, s32 arg1, s32 arg2) {
temp_a3_2 = temp_a3->unk4 + arg2;
sp28 = temp_a3_2;
sp2C = temp_a3;
- temp_v0_2 = func_800B8FFC(&D_803BFBE8, temp_a3->unk10, temp_a3_2);
+ temp_v0_2 = soundAlloc(&gNotesAndBuffersPool, temp_a3->unk10, temp_a3_2);
if (temp_v0_2 == 0) {
temp_a3->unk4 = temp_a3_2;
temp_a3->unk1 = 1;
} else {
sp24 = temp_v0_2;
sp2C = temp_a3;
- func_800BAA80(temp_a3_2, temp_v0_2, temp_a3->unk10, temp_a3_2);
+ audio_dma_copy_immediate(temp_a3_2, temp_v0_2, temp_a3->unk10, temp_a3_2);
temp_a3->unk1 = 0x81;
temp_a3->unk4 = temp_v0_2;
}
@@ -723,10 +698,12 @@ void func_800BB624(void **arg0, ? arg1, s32 arg2, s32 arg3) {
GLOBAL_ASM("asm/non_matchings/audio/load/func_800BB624.s")
#endif
+
+
#ifdef MIPS_TO_C
//generated by mips_to_c commit 3c3b0cede1a99430bfd3edf8d385802b94f91307
s32 func_800B93BC(? *, ?, s32, ?, s32); // extern
-? func_800BAA80(s32, s32, s32); // extern
+? audio_dma_copy_immediate(s32, s32, s32); // extern
? func_800BB584(s32); // extern
extern ? D_803AFE18;
extern ? D_803B03C0;
@@ -751,7 +728,7 @@ s32 func_800BB780(s32 arg0, ? arg1) {
return 0;
}
sp2C = temp_v0_2;
- func_800BAA80(sp28 + 0x10, temp_v0_2, temp_a2);
+ audio_dma_copy_immediate(sp28 + 0x10, temp_v0_2, temp_a2);
(D_803B7080 + (arg0 * 0xC))->unk4 = sp2C + 4;
func_800BB584(arg0);
temp_v0_3 = arg0 + &D_803B03C0;
@@ -819,7 +796,7 @@ GLOBAL_ASM("asm/non_matchings/audio/load/func_800BB864.s")
#ifdef MIPS_TO_C
//generated by mips_to_c commit 3c3b0cede1a99430bfd3edf8d385802b94f91307
s32 func_800B93BC(? *, ?, s32, ?, s32); // extern
-? func_800BAA80(s32, s32, s32); // extern
+? audio_dma_copy_immediate(s32, s32, s32); // extern
extern ? D_803AFC48;
extern ? D_803B0400;
extern s32 D_803B706C;
@@ -842,7 +819,7 @@ s32 func_800BB99C(s32 arg0, ? arg1) {
return 0;
}
sp28 = temp_v0;
- func_800BAA80(sp24, temp_v0, sp2C);
+ audio_dma_copy_immediate(sp24, temp_v0, sp2C);
temp_v0_3 = arg0 + &D_803B0400;
if (*temp_v0_3 != 5) {
*temp_v0_3 = 2;
@@ -856,7 +833,7 @@ GLOBAL_ASM("asm/non_matchings/audio/load/func_800BB99C.s")
#ifdef MIPS_TO_C
//generated by mips_to_c commit 3c3b0cede1a99430bfd3edf8d385802b94f91307
s32 func_800B93BC(? *, ?, s32, ?, s32); // extern
-? func_800BAA80(s32, s32, s32); // extern
+? audio_dma_copy_immediate(s32, s32, s32); // extern
? func_800BAAF8(s32, s32, s32, OSMesgQueue *, void *); // extern
extern ? D_803AFC48;
extern ? D_803B0400;
@@ -882,13 +859,13 @@ s32 func_800BBA50(s32 arg0, ? arg1, u8 *arg2) {
return 0;
}
if (temp_s0 < 0x41) {
- func_800BAA80(sp3C, temp_v0, temp_s0);
+ audio_dma_copy_immediate(sp3C, temp_v0, temp_s0);
temp_v0_3 = arg0 + &D_803B0400;
if (*temp_v0_3 != 5) {
*temp_v0_3 = 2;
}
} else {
- func_800BAA80(sp3C, temp_v0, 0x40);
+ audio_dma_copy_immediate(sp3C, temp_v0, 0x40);
temp_a3 = arg2 + 0xD4;
sp34 = temp_a3;
osCreateMesgQueue(temp_a3, arg2 + 0xEC, 1);
@@ -1064,24 +1041,20 @@ block_11:
#else
GLOBAL_ASM("asm/non_matchings/audio/load/func_800BBDDC.s")
#endif
-
-#ifdef MIPS_TO_C
-//generated by mips_to_c commit 3c3b0cede1a99430bfd3edf8d385802b94f91307
-? func_800BBF44(); // extern
-extern s32 D_800EA5DC;
-
-void func_800BBEF0(s32 arg2) {
- if (arg2 == 0) {
- D_800EA5DC = 0x19710515;
+extern volatile s32 D_800EA5DC;
+//load_sequence_internal
+void func_800BBF44(u32 player, u32 seqId, s32 loadAsync);
+//load_sequence
+void func_800BBEF0(u32 player, u32 seqId, s32 loadAsync) {
+ if (!loadAsync) {
+ D_800EA5DC = AUDIO_LOCK_LOADING; // gAudioLoadLock
}
- func_800BBF44();
- if (arg2 == 0) {
- D_800EA5DC = 0x76557364;
+ func_800BBF44(player, seqId, loadAsync);
+ if (!loadAsync) {
+ D_800EA5DC = AUDIO_LOCK_NOT_LOADING;
}
}
-#else
-GLOBAL_ASM("asm/non_matchings/audio/load/func_800BBEF0.s")
-#endif
+//GLOBAL_ASM("asm/non_matchings/audio/load/func_800BBEF0.s")
#ifdef MIPS_TO_C
//generated by mips_to_c commit 3c3b0cede1a99430bfd3edf8d385802b94f91307