Paper Mario DX
Paper Mario (N64) modding
 
Loading...
Searching...
No Matches
25f00_len_940.c File Reference

Go to the source code of this file.

Functions

u8 rspbootUcodeBuffer[0x100] ALIGNED (16)
 
void create_audio_system (void)
 
void nuAuPreNMIFuncSet (NUAuPreNMIFunc func)
 
void nuAuMgr (void *arg)
 
s32 nuAuDmaCallBack (s32 addr, s32 len, void *state, u8 arg3)
 
ALDMAproc nuAuDmaNew (NUDMAState **state)
 
void nuAuCleanDMABuffers (void)
 
void nuAuPreNMIProc (NUScMsg mesg_type, u32 frameCounter)
 
void alLink (ALLink *element, ALLink *after)
 
void alUnlink (ALLink *element)
 

Variables

u8 nuAuPreNMI = 0
 
NUAuPreNMIFunc nuAuPreNMIFunc = NULL
 
s32 nuAuDmaNext = 0
 
u32 nuAuFrameCounter = 0
 
u8 nuAuTaskStop = NU_AU_TASK_RUN
 
u8 volatile AuSynUseStereo = TRUE
 
BSS u16 AuInitialGlobalVolume
 
BSS OSThread nuAuMgrThread
 
BSS u64 AuStack [NU_AU_STACK_SIZE/sizeof(u64)]
 
BSS Acmd * AlCmdListBuffers [3]
 
BSS NUScTask nuAuTasks [3]
 
BSS u8 * D_800A3628 [3]
 
BSS s32 AlFrameSize
 
BSS s32 AlMinFrameSize
 
BSS OSMesgQueue nuAuDmaMesgQ
 
BSS OSMesg nuAuDmaMesgBuf [50]
 
BSS OSIoMesg nuAuDmaIOMesgBuf [50]
 
BSS NUDMAState nuAuDmaState
 
BSS NUDMABuffer nuAuDmaBufList [50]
 
ALHeap nuAuHeap
 
AuSynDriver auSynDriver
 
u64 n_aspMain_text_bin []
 
u64 n_aspMain_data_bin []
 
u8 AuHeapBase [AUDIO_HEAP_SIZE]
 

Function Documentation

◆ ALIGNED()

u8 rspbootUcodeBuffer[0x100] ALIGNED ( 16 )

◆ create_audio_system()

void create_audio_system ( void )

Definition at line 39 of file 25f00_len_940.c.

39 {
40 u32 i;
41 u32 outputRate, frameSize;
42 ALConfig config;
43
44 nuAuTaskStop = NU_AU_TASK_RUN;
45 nuAuPreNMI = 0;
47 config.num_pvoice = 24;
48 config.num_bus = 4;
49 outputRate = osAiSetFrequency(32000);
50 frameSize = (nusched.retraceCount * outputRate + 59) / 60;
51 config.outputRate = outputRate;
52 config.unk_0C = 0;
53 config.heap = &nuAuHeap;
54 config.dmaNew = nuAuDmaNew;
55 AlFrameSize = ((frameSize / AUDIO_SAMPLES) + 1) * AUDIO_SAMPLES;
57
58 for (i = 0; i < ARRAY_COUNT(AlCmdListBuffers); i++) {
60 }
61
62 for (i = 0; i < ARRAY_COUNT(nuAuTasks); i++) {
63 nuAuTasks[i].next = NULL;
64 nuAuTasks[i].msg = 0;
65 nuAuTasks[i].list.t.type = M_AUDTASK;
66#if VERSION_IQUE
67 nuAuTasks[i].list.t.ucode_boot = (u64*) rspbootTextStart;
68 nuAuTasks[i].list.t.ucode_boot_size = (u32) rspbootTextEnd - (u32) rspbootTextStart;
69#else
70 nuAuTasks[i].list.t.ucode_boot = (u64*) rspbootUcodeBuffer;
71 nuAuTasks[i].list.t.ucode_boot_size = 0x100;
72#endif
73 nuAuTasks[i].list.t.ucode = n_aspMain_text_bin;
74 nuAuTasks[i].list.t.ucode_data = n_aspMain_data_bin;
75 nuAuTasks[i].list.t.ucode_data_size = SP_UCODE_DATA_SIZE;
76 nuAuTasks[i].list.t.dram_stack = NULL;
77 nuAuTasks[i].list.t.dram_stack_size = 0;
78 nuAuTasks[i].list.t.output_buff = NULL;
79 nuAuTasks[i].list.t.output_buff_size = 0;
80 nuAuTasks[i].list.t.yield_data_ptr = NULL;
81 nuAuTasks[i].list.t.yield_data_size = 0;
82 }
83
84 for (i = 0; i < ARRAY_COUNT(D_800A3628); i++) {
85 D_800A3628[i] = alHeapAlloc(config.heap, 1, AlFrameSize * 4);
86 }
87
88 nuAuDmaBufList[0].node.next = nuAuDmaBufList[0].node.prev = NULL;
89 for (i = 0; i < ARRAY_COUNT(nuAuDmaBufList) - 1; i++) {
90 alLink(&nuAuDmaBufList[i+1].node, &nuAuDmaBufList[i].node);
91 nuAuDmaBufList[i].ptr = alHeapAlloc(config.heap, 1, 0x500);
92 }
93 nuAuDmaBufList[i].ptr = alHeapAlloc(config.heap, 1, 0x500);
94
95 osCreateMesgQueue(&nuAuDmaMesgQ, nuAuDmaMesgBuf, 50);
97 au_driver_init(&auSynDriver, &config);
99 osCreateThread(&nuAuMgrThread, NU_MAIN_THREAD_ID, nuAuMgr, NULL, &AuStack[NU_AU_STACK_SIZE / sizeof(u64)], NU_AU_MGR_THREAD_PRI); //why main thread?
100 osStartThread(&nuAuMgrThread);
101}
BSS OSThread nuAuMgrThread
u8 AuHeapBase[AUDIO_HEAP_SIZE]
u8 nuAuPreNMI
u64 n_aspMain_data_bin[]
AuSynDriver auSynDriver
BSS NUDMABuffer nuAuDmaBufList[50]
ALHeap nuAuHeap
void alLink(ALLink *element, ALLink *after)
BSS NUScTask nuAuTasks[3]
BSS s32 AlFrameSize
void nuAuPreNMIProc(NUScMsg mesg_type, u32 frameCounter)
BSS OSMesg nuAuDmaMesgBuf[50]
BSS u8 * D_800A3628[3]
void nuAuMgr(void *arg)
BSS u64 AuStack[NU_AU_STACK_SIZE/sizeof(u64)]
u64 n_aspMain_text_bin[]
BSS s32 AlMinFrameSize
u8 nuAuTaskStop
ALDMAproc nuAuDmaNew(NUDMAState **state)
NUAuPreNMIFunc nuAuPreNMIFunc
BSS Acmd * AlCmdListBuffers[3]
BSS OSMesgQueue nuAuDmaMesgQ
void au_engine_init(s32 outputRate)
void au_driver_init(AuSynDriver *driver, ALConfig *config)
Definition 31650.c:25
void alHeapInit(ALHeap *hp, u8 *base, s32 len)
Definition 31650.c:725
void * alHeapAlloc(ALHeap *heap, s32 count, s32 size)
Definition 31650.c:743
ALHeap * heap
Definition audio.h:1186
s32 num_pvoice
Definition audio.h:1180
#define AUDIO_HEAP_SIZE
Definition audio.h:42
void * dmaNew
Definition audio.h:1185
u8 unk_0C
Definition audio.h:1183
#define AUDIO_SAMPLES
Definition audio.h:44
s32 outputRate
Definition audio.h:1182
#define AUDIO_COMMAND_LIST_BUFFER_SIZE
Definition audio.h:45
s32 num_bus
Definition audio.h:1181
#define ARRAY_COUNT(arr)
Definition macros.h:40

Referenced by create_audio_system_obfuscated().

◆ nuAuPreNMIFuncSet()

void nuAuPreNMIFuncSet ( NUAuPreNMIFunc func)

Definition at line 103 of file 25f00_len_940.c.

103 {
104 OSIntMask mask = osSetIntMask(OS_IM_NONE);
105
106 nuAuPreNMIFunc = func;
107 osSetIntMask(mask);
108}

◆ nuAuMgr()

void nuAuMgr ( void * arg)

Definition at line 110 of file 25f00_len_940.c.

110 {
111 NUScClient auClient;
112 OSMesgQueue auMesgQ;
113 OSMesg auMsgBuf[NU_AU_MESG_MAX];
114 OSMesgQueue auRtnMesgQ;
115 OSMesg auRtnMesgBuf;
116 NUScMsg* mesg_type;
117 s32 cmdList_len;
118 Acmd* cmdListAfter_ptr;
119 s32 cmdListIndex;
120 s32 bufferIndex;
121 s32 sampleSize;
122 Acmd* cmdListBuf;
123 u8* bufferPtr;
124 s32 samples;
125 s32 cond;
126
127 osCreateMesgQueue(&auMesgQ, auMsgBuf, NU_AU_MESG_MAX);
128 osCreateMesgQueue(&auRtnMesgQ, &auRtnMesgBuf, 1);
129 nuScAddClient(&auClient, &auMesgQ, NU_SC_RETRACE_MSG | NU_SC_PRENMI_MSG);
130
131 cmdList_len = 0;
132 cmdListIndex = 0;
133 bufferIndex = 0;
134 samples = 0;
135 cmdListBuf = AlCmdListBuffers[0];
136 bufferPtr = D_800A3628[0];
137 while (TRUE) {
138 osRecvMesg(&auMesgQ, (OSMesg*)&mesg_type, OS_MESG_BLOCK);
139 switch (*mesg_type) {
140 case NU_SC_RETRACE_MSG:
141 if (cmdList_len != 0 && nuAuTaskStop == NU_AU_TASK_RUN) {
142 nuAuTasks[cmdListIndex].msgQ = &auRtnMesgQ;
143 nuAuTasks[cmdListIndex].list.t.data_ptr = (u64*)cmdListBuf;
144 nuAuTasks[cmdListIndex].list.t.data_size = (cmdListAfter_ptr - cmdListBuf) * sizeof(Acmd);
146 osSendMesg(&nusched.audioRequestMQ, &nuAuTasks[cmdListIndex], OS_MESG_BLOCK);
149 osRecvMesg(&auRtnMesgQ, NULL, 1);
150 if (++bufferIndex == 3) {
151 bufferIndex = 0;
152 }
153 if (++cmdListIndex == 3) {
154 cmdListIndex = 0;
155 }
156 }
157 profiler_audio_started(); // XXX: is this the right place?
158 if (osAiGetStatus() & AI_STATUS_FIFO_FULL) {
159 cond = FALSE;
161 continue;
162 }
163 sampleSize = osAiGetLength() >> 2;
164 if (cmdList_len != 0 && nuAuTaskStop == NU_AU_TASK_RUN) {
165 osAiSetNextBuffer(bufferPtr, samples * 4);
166 cmdListBuf = AlCmdListBuffers[cmdListIndex];
167 bufferPtr = D_800A3628[bufferIndex];
168 }
169 if (sampleSize < AUDIO_SAMPLES || cond) {
170 samples = AlFrameSize;
171 cond = FALSE;
172 } else {
173 samples = AlMinFrameSize;
174 cond = TRUE;
175 }
176 cmdListAfter_ptr = alAudioFrame(cmdListBuf, &cmdList_len, (s16*)osVirtualToPhysical(bufferPtr), samples);
177 if (nuAuPreNMIFunc != 0 && nuAuPreNMI != 0) {
178 nuAuPreNMIFunc(NU_SC_RETRACE_MSG, nuAuPreNMI);
179 nuAuPreNMI++;
180 }
181
182 break;
183 case NU_SC_PRENMI_MSG:
184 if (nuAuPreNMIFunc) {
185 nuAuPreNMIFunc(NU_SC_PRENMI_MSG, nuAuPreNMI);
186 }
187 nuAuPreNMI++;
188 break;
189 }
191 }
192}
void nuAuCleanDMABuffers(void)
Acmd * alAudioFrame(Acmd *cmdList, s32 *cmdLen, s16 *outBuf, s32 outLen)
Definition 31650.c:119
@ PROFILER_RSP_AUDIO
Definition profiling.h:99
#define profiler_rsp_started(which)
Definition profiling.h:160
#define profiler_rsp_completed(which)
Definition profiling.h:161
#define profiler_audio_completed()
Definition profiling.h:164
#define profiler_audio_started()
Definition profiling.h:163

Referenced by create_audio_system().

◆ nuAuDmaCallBack()

s32 nuAuDmaCallBack ( s32 addr,
s32 len,
void * state,
u8 arg3 )

Definition at line 194 of file 25f00_len_940.c.

194 {
195 NUDMABuffer* dmaPtr;
196 NUDMABuffer* freeBuffer;
197 OSIoMesg* mesg;
198 s32 delta;
199 u32 startAddr;
200 s32 addrEnd, buffEnd;
201 NUDMABuffer* lastDmaPtr;
202
203 if (arg3 == 0) {
204 return osVirtualToPhysical((void*)addr);
205 }
206
207 lastDmaPtr = NULL;
208 dmaPtr = nuAuDmaState.firstUsed;
209 addrEnd = addr + len;
210
211 while (dmaPtr != NULL) {
212 startAddr = dmaPtr->startAddr;
213 buffEnd = dmaPtr->startAddr + 0x500;
214 if (addr >= startAddr && buffEnd >= addrEnd) {
215 dmaPtr->frameCnt = nuAuFrameCounter;
216 freeBuffer = (NUDMABuffer*)(dmaPtr->ptr + addr - dmaPtr->startAddr);
217 return osVirtualToPhysical(freeBuffer);
218 } else if (addr < startAddr) {
219 break;
220 }
221 lastDmaPtr = dmaPtr;
222 dmaPtr = (NUDMABuffer*)dmaPtr->node.next;
223 }
224
225 dmaPtr = nuAuDmaState.firstFree;
226 if (dmaPtr == NULL) {
227 return osVirtualToPhysical(nuAuDmaState.firstUsed);
228 }
229
230 nuAuDmaState.firstFree = (NUDMABuffer*)dmaPtr->node.next;
231 alUnlink(&dmaPtr->node);
232
233 if (lastDmaPtr != NULL) {
234 alLink(&dmaPtr->node, &lastDmaPtr->node);
235 } else if (nuAuDmaState.firstUsed != NULL){
236 lastDmaPtr = nuAuDmaState.firstUsed;
237 nuAuDmaState.firstUsed = dmaPtr;
238 dmaPtr->node.next = &lastDmaPtr->node;
239 dmaPtr->node.prev = NULL;
240 lastDmaPtr->node.prev = &dmaPtr->node;
241 } else {
242 nuAuDmaState.firstUsed = dmaPtr;
243 dmaPtr->node.next = NULL;
244 dmaPtr->node.prev = NULL;
245 }
246
247 freeBuffer = (NUDMABuffer*)dmaPtr->ptr;
248 delta = addr & 1;
249 addr -= delta;
250 dmaPtr->startAddr = addr;
251 dmaPtr->frameCnt = nuAuFrameCounter;
252
253 mesg = &nuAuDmaIOMesgBuf[nuAuDmaNext++];
254 mesg->hdr.pri = OS_MESG_PRI_NORMAL;
255 mesg->hdr.retQueue = &nuAuDmaMesgQ;
256 mesg->dramAddr = freeBuffer;
257 mesg->devAddr = addr;
258 mesg->size = 0x500;
259 osEPiStartDma(nuPiCartHandle, mesg, 0);
260 return osVirtualToPhysical(freeBuffer) + delta;
261}
u32 nuAuFrameCounter
BSS NUDMAState nuAuDmaState
void alUnlink(ALLink *element)
s32 nuAuDmaNext
BSS OSIoMesg nuAuDmaIOMesgBuf[50]

Referenced by nuAuDmaNew().

◆ nuAuDmaNew()

ALDMAproc nuAuDmaNew ( NUDMAState ** state)

Definition at line 263 of file 25f00_len_940.c.

263 {
264 if (!nuAuDmaState.initialized) {
265 nuAuDmaState.firstFree = &nuAuDmaBufList[0];
266 nuAuDmaState.firstUsed = NULL;
267 nuAuDmaState.initialized = TRUE;
268 }
269
270 nuAuDmaNext = 0;
271 *state = &nuAuDmaState;
272 return (ALDMAproc)nuAuDmaCallBack;
273}
s32 nuAuDmaCallBack(s32 addr, s32 len, void *state, u8 arg3)

Referenced by create_audio_system().

◆ nuAuCleanDMABuffers()

void nuAuCleanDMABuffers ( void )

Definition at line 275 of file 25f00_len_940.c.

275 {
276 NUDMAState* state = &nuAuDmaState;
277 NUDMABuffer* dmaPtr = state->firstUsed;
278 NUDMABuffer* nextPtr;
279 u32* frameCounter;
280
281 while (dmaPtr != NULL) {
282 nextPtr = (NUDMABuffer*)dmaPtr->node.next;
283
284 if (dmaPtr->frameCnt + 1 < nuAuFrameCounter) {
285 if (state->firstUsed == dmaPtr) {
286 state->firstUsed = nextPtr;
287 }
288
289 alUnlink(&dmaPtr->node);
290
291 if (state->firstFree != 0) {
292 alLink(&dmaPtr->node, &state->firstFree->node);
293 } else {
294 state->firstFree = dmaPtr;
295 dmaPtr->node.next = 0;
296 dmaPtr->node.prev = 0;
297 }
298 }
299
300 dmaPtr = nextPtr;
301 }
302
303 nuAuDmaNext = 0;
304 frameCounter = &nuAuFrameCounter;
305 *frameCounter += 1;
306}

Referenced by nuAuMgr().

◆ nuAuPreNMIProc()

void nuAuPreNMIProc ( NUScMsg mesg_type,
u32 frameCounter )

Definition at line 308 of file 25f00_len_940.c.

308 {
309 s16 maxVol;
310 s32 vol;
311
312 switch (mesg_type) {
313 case NU_SC_PRENMI_MSG:
316 break;
317 case NU_SC_RETRACE_MSG:
318 maxVol = AuInitialGlobalVolume;
319 vol = maxVol - (maxVol / 20) * frameCounter;
320
321 if (vol < 0) {
322 vol = 0;
323 }
324
325 vol = SQ(vol) >> 15;
327
328 if (vol == 0) {
329 nuAuTaskStop = NU_AU_TASK_STOP;
330 }
331 break;
332 }
333}
BSS u16 AuInitialGlobalVolume
void au_set_global_volume(s16 arg0)
Definition 31650.c:254
void au_use_global_volume(void)
Definition 31650.c:250
s16 au_get_global_volume(void)
Definition 31650.c:258
#define SQ(x)
Definition macros.h:166

Referenced by create_audio_system().

◆ alLink()

void alLink ( ALLink * element,
ALLink * after )

Definition at line 335 of file 25f00_len_940.c.

335 {
336 element->next = after->next;
337 element->prev = after;
338
339 if (after->next != NULL) {
340 after->next->prev = element;
341 }
342 after->next = element;
343}

Referenced by create_audio_system(), nuAuCleanDMABuffers(), and nuAuDmaCallBack().

◆ alUnlink()

void alUnlink ( ALLink * element)

Definition at line 345 of file 25f00_len_940.c.

345 {
346 if (element->next != NULL) {
347 element->next->prev = element->prev;
348 }
349
350 if (element->prev != NULL) {
351 element->prev->next = element->next;
352 }
353}

Referenced by nuAuCleanDMABuffers(), and nuAuDmaCallBack().

Variable Documentation

◆ nuAuPreNMI

u8 nuAuPreNMI = 0

Definition at line 7 of file 25f00_len_940.c.

Referenced by create_audio_system(), and nuAuMgr().

◆ nuAuPreNMIFunc

NUAuPreNMIFunc nuAuPreNMIFunc = NULL

Definition at line 8 of file 25f00_len_940.c.

Referenced by create_audio_system(), nuAuMgr(), and nuAuPreNMIFuncSet().

◆ nuAuDmaNext

s32 nuAuDmaNext = 0

Definition at line 9 of file 25f00_len_940.c.

Referenced by nuAuCleanDMABuffers(), nuAuDmaCallBack(), and nuAuDmaNew().

◆ nuAuFrameCounter

u32 nuAuFrameCounter = 0

Definition at line 10 of file 25f00_len_940.c.

Referenced by nuAuCleanDMABuffers(), and nuAuDmaCallBack().

◆ nuAuTaskStop

u8 nuAuTaskStop = NU_AU_TASK_RUN

Definition at line 11 of file 25f00_len_940.c.

Referenced by create_audio_system(), nuAuMgr(), and nuAuPreNMIProc().

◆ AuSynUseStereo

◆ AuInitialGlobalVolume

BSS u16 AuInitialGlobalVolume

Definition at line 14 of file 25f00_len_940.c.

Referenced by nuAuPreNMIProc().

◆ nuAuMgrThread

BSS OSThread nuAuMgrThread

Definition at line 15 of file 25f00_len_940.c.

Referenced by create_audio_system().

◆ AuStack

BSS u64 AuStack[NU_AU_STACK_SIZE/sizeof(u64)]

Definition at line 16 of file 25f00_len_940.c.

Referenced by create_audio_system().

◆ AlCmdListBuffers

BSS Acmd* AlCmdListBuffers[3]

Definition at line 17 of file 25f00_len_940.c.

Referenced by create_audio_system(), and nuAuMgr().

◆ nuAuTasks

BSS NUScTask nuAuTasks[3]

Definition at line 18 of file 25f00_len_940.c.

Referenced by create_audio_system(), and nuAuMgr().

◆ D_800A3628

BSS u8* D_800A3628[3]

Definition at line 19 of file 25f00_len_940.c.

Referenced by create_audio_system(), and nuAuMgr().

◆ AlFrameSize

BSS s32 AlFrameSize

Definition at line 20 of file 25f00_len_940.c.

Referenced by create_audio_system(), and nuAuMgr().

◆ AlMinFrameSize

BSS s32 AlMinFrameSize

Definition at line 21 of file 25f00_len_940.c.

Referenced by create_audio_system(), and nuAuMgr().

◆ nuAuDmaMesgQ

BSS OSMesgQueue nuAuDmaMesgQ

Definition at line 22 of file 25f00_len_940.c.

Referenced by create_audio_system(), and nuAuDmaCallBack().

◆ nuAuDmaMesgBuf

BSS OSMesg nuAuDmaMesgBuf[50]

Definition at line 23 of file 25f00_len_940.c.

Referenced by create_audio_system().

◆ nuAuDmaIOMesgBuf

BSS OSIoMesg nuAuDmaIOMesgBuf[50]

Definition at line 24 of file 25f00_len_940.c.

Referenced by nuAuDmaCallBack().

◆ nuAuDmaState

BSS NUDMAState nuAuDmaState

Definition at line 25 of file 25f00_len_940.c.

Referenced by nuAuCleanDMABuffers(), nuAuDmaCallBack(), and nuAuDmaNew().

◆ nuAuDmaBufList

BSS NUDMABuffer nuAuDmaBufList[50]

Definition at line 26 of file 25f00_len_940.c.

Referenced by create_audio_system(), and nuAuDmaNew().

◆ nuAuHeap

ALHeap nuAuHeap

Definition at line 28 of file 25f00_len_940.c.

Referenced by create_audio_system().

◆ auSynDriver

AuSynDriver auSynDriver

Definition at line 29 of file 25f00_len_940.c.

Referenced by create_audio_system().

◆ n_aspMain_text_bin

u64 n_aspMain_text_bin[]
extern

Referenced by create_audio_system().

◆ n_aspMain_data_bin

u64 n_aspMain_data_bin[]
extern

Referenced by create_audio_system().

◆ AuHeapBase

BSS u8 AuHeapBase ( )
extern

Referenced by create_audio_system().