papermario/src/code_25f00_len_940.c

130 lines
3.0 KiB
C
Raw Normal View History

2020-08-04 08:49:11 +02:00
#include "common.h"
2020-12-09 23:53:35 +01:00
#include "nu/nusys.h"
#include "nu/nualsgi.h"
2020-12-18 03:29:35 +01:00
#include "audio.h"
2020-08-04 08:49:11 +02:00
2020-12-10 07:39:32 +01:00
extern NUDMAState nuAuDmaState;
2020-12-18 03:29:35 +01:00
s32 D_80078170 = 0;
NUAuPreNMIFunc nuAuPreNMIFunc = NULL;
s32 nuAuDmaNext = 0;
u32 nuAuFrameCounter = 0;
u8 D_80078180 = 1;
u8 D_80078181 = 1;
2020-12-10 07:39:32 +01:00
2020-09-25 23:18:09 +02:00
INCLUDE_ASM(s32, "code_25f00_len_940", func_8004AB00);
2020-08-04 08:49:11 +02:00
2020-12-09 23:53:35 +01:00
void nuAuPreNMIFuncSet(NUAuPreNMIFunc func) {
OSIntMask mask = osSetIntMask(OS_IM_NONE);
2020-12-08 11:50:14 +01:00
2020-12-09 23:53:35 +01:00
nuAuPreNMIFunc = func;
osSetIntMask(mask);
2020-12-08 11:50:14 +01:00
}
2020-08-04 08:49:11 +02:00
2020-09-25 23:18:09 +02:00
INCLUDE_ASM(s32, "code_25f00_len_940", func_8004AE08);
2020-08-04 08:49:11 +02:00
2020-12-18 11:12:41 +01:00
s32 nuAuDmaCallBack(s32 addr, s32 len, void* state, s32 arg3);
INCLUDE_ASM(s32, "code_25f00_len_940", nuAuDmaCallBack, s32 addr, s32 len, void* state, s32 arg3);
2020-10-15 06:43:07 +02:00
2020-12-12 09:55:21 +01:00
ALDMAproc nuAuDmaNew(NUDMAState** state) {
2020-12-10 07:39:32 +01:00
if (!nuAuDmaState.initialized) {
nuAuDmaState.firstFree = &nuAuDmaBuf;
nuAuDmaState.firstUsed = NULL;
nuAuDmaState.initialized = TRUE;
}
nuAuDmaNext = 0;
*state = &nuAuDmaState;
return nuAuDmaCallBack;
}
2020-08-04 08:49:11 +02:00
2020-12-10 14:24:28 +01:00
void nuAuCleanDMABuffers(void) {
2020-12-18 03:29:35 +01:00
NUDMAState* state = &nuAuDmaState;
NUDMABuffer* dmaPtr = state->firstUsed;
2020-12-18 03:31:02 +01:00
// A bit odd, this
2020-12-18 03:29:35 +01:00
do {
NUDMAState* state = &nuAuDmaState;
NUDMABuffer* nextPtr;
u32* frameCounter;
while (dmaPtr != NULL) {
nextPtr = dmaPtr->node.next;
2020-12-18 03:31:02 +01:00
if (dmaPtr->frameCnt + 1 < nuAuFrameCounter) {
2020-12-18 03:29:35 +01:00
if (state->firstUsed == dmaPtr) {
state->firstUsed = nextPtr;
}
2020-12-18 03:31:02 +01:00
2020-12-18 03:29:35 +01:00
alUnlink(dmaPtr);
2020-12-18 03:31:02 +01:00
2020-12-18 03:29:35 +01:00
if (state->firstFree != 0) {
alLink(dmaPtr, state->firstFree);
} else {
state->firstFree = dmaPtr;
dmaPtr->node.next = 0;
dmaPtr->node.prev = 0;
}
2020-12-10 14:24:28 +01:00
}
2020-12-18 03:31:02 +01:00
2020-12-18 03:29:35 +01:00
dmaPtr = nextPtr;
2020-12-10 14:24:28 +01:00
}
2020-12-18 03:29:35 +01:00
nuAuDmaNext = 0;
frameCounter = &nuAuFrameCounter;
*frameCounter += 1;
} while (0);
2020-12-10 14:24:28 +01:00
}
2020-12-18 03:29:35 +01:00
2020-12-18 15:11:54 +01:00
// Nop issue
#ifdef NON_MATCHING
void func_8004B328(s16 arg0, s32 arg1) {
s16 temp_a0_2;
s32 temp_s0;
switch (arg0) {
case 2:
D_800A0F50 = func_80056D50();
func_80056D34();
break;
case 1:
temp_a0_2 = D_800A0F50;
temp_s0 = temp_a0_2 - (temp_a0_2 / 20) * arg1;
if (temp_s0 < 0) {
temp_s0 = 0;
}
temp_s0 = (temp_s0 * temp_s0) >> 0xF;
func_80056D44(temp_s0);
if (temp_s0 == 0) {
D_80078180 = 0;
}
break;
}
}
#else
2020-09-25 23:18:09 +02:00
INCLUDE_ASM(s32, "code_25f00_len_940", func_8004B328);
2020-12-18 15:11:54 +01:00
#endif
2020-09-24 05:16:13 +02:00
2020-11-06 01:37:31 +01:00
void alLink(ALLink* element, ALLink* after) {
2020-11-06 01:30:17 +01:00
element->next = after->next;
element->prev = after;
if (after->next != NULL) {
after->next->prev = element;
}
after->next = element;
}
2020-11-06 01:37:31 +01:00
void alUnlink(ALLink* element) {
2020-11-06 01:30:17 +01:00
if (element->next != NULL) {
element->next->prev = element->prev;
}
if (element->prev != NULL) {
element->prev->next = element->next;
}
}