diff --git a/asm/non_matchings/unknown_003260/__amDMA.s b/asm/non_matchings/unknown_003260/__amDMA.s index c4349ffd..bc1a769f 100644 --- a/asm/non_matchings/unknown_003260/__amDMA.s +++ b/asm/non_matchings/unknown_003260/__amDMA.s @@ -22,8 +22,8 @@ glabel __amDMA /* 003A84 80002E84 1420000A */ bnez $at, .L80002EB0 /* 003A88 80002E88 02003025 */ move $a2, $s0 /* 003A8C 80002E8C 8E180010 */ lw $t8, 0x10($s0) -/* 003A90 80002E90 3C0F800E */ lui $t7, %hi(D_800DC680) # $t7, 0x800e -/* 003A94 80002E94 8DEFC680 */ lw $t7, %lo(D_800DC680)($t7) +/* 003A90 80002E90 3C0F800E */ lui $t7, %hi(audFrameCt) # $t7, 0x800e +/* 003A94 80002E94 8DEFC680 */ lw $t7, %lo(audFrameCt)($t7) /* 003A98 80002E98 0307C821 */ addu $t9, $t8, $a3 /* 003A9C 80002E9C 03222023 */ subu $a0, $t9, $v0 /* 003AA0 80002EA0 0C03233C */ jal osVirtualToPhysical @@ -87,22 +87,22 @@ glabel __amDMA .L80002F70: /* 003B70 80002F70 8FAC0048 */ lw $t4, 0x48($sp) .L80002F74: -/* 003B74 80002F74 3C0D800E */ lui $t5, %hi(D_800DC680) # $t5, 0x800e +/* 003B74 80002F74 3C0D800E */ lui $t5, %hi(audFrameCt) # $t5, 0x800e /* 003B78 80002F78 00EC3823 */ subu $a3, $a3, $t4 /* 003B7C 80002F7C AE070008 */ sw $a3, 8($s0) -/* 003B80 80002F80 8DADC680 */ lw $t5, %lo(D_800DC680)($t5) +/* 003B80 80002F80 8DADC680 */ lw $t5, %lo(audFrameCt)($t5) /* 003B84 80002F84 3C08800E */ lui $t0, %hi(D_800DC684) # $t0, 0x800e /* 003B88 80002F88 2508C684 */ addiu $t0, %lo(D_800DC684) # addiu $t0, $t0, -0x397c /* 003B8C 80002F8C AE0D000C */ sw $t5, 0xc($s0) /* 003B90 80002F90 8E030010 */ lw $v1, 0x10($s0) /* 003B94 80002F94 8D020000 */ lw $v0, ($t0) -/* 003B98 80002F98 3C0F8012 */ lui $t7, %hi(D_80119640) # $t7, 0x8012 +/* 003B98 80002F98 3C0F8012 */ lui $t7, %hi(audDMAIOMesgBuf) # $t7, 0x8012 /* 003B9C 80002F9C 00027080 */ sll $t6, $v0, 2 -/* 003BA0 80002FA0 3C198012 */ lui $t9, %hi(D_80119AF0) # $t9, 0x8012 +/* 003BA0 80002FA0 3C198012 */ lui $t9, %hi(audDMAMessageQ) # $t9, 0x8012 /* 003BA4 80002FA4 01C27023 */ subu $t6, $t6, $v0 /* 003BA8 80002FA8 000E70C0 */ sll $t6, $t6, 3 -/* 003BAC 80002FAC 27399AF0 */ addiu $t9, %lo(D_80119AF0) # addiu $t9, $t9, -0x6510 -/* 003BB0 80002FB0 25EF9640 */ addiu $t7, %lo(D_80119640) # addiu $t7, $t7, -0x69c0 +/* 003BAC 80002FAC 27399AF0 */ addiu $t9, %lo(audDMAMessageQ) # addiu $t9, $t9, -0x6510 +/* 003BB0 80002FB0 25EF9640 */ addiu $t7, %lo(audDMAIOMesgBuf) # addiu $t7, $t7, -0x69c0 /* 003BB4 80002FB4 24180400 */ li $t8, 1024 /* 003BB8 80002FB8 244B0001 */ addiu $t3, $v0, 1 /* 003BBC 80002FBC AD0B0000 */ sw $t3, ($t0) diff --git a/asm/non_matchings/unknown_003260/audioNewThread.s b/asm/non_matchings/unknown_003260/audioNewThread.s index d88dbb2c..8ec5d4ce 100644 --- a/asm/non_matchings/unknown_003260/audioNewThread.s +++ b/asm/non_matchings/unknown_003260/audioNewThread.s @@ -27,11 +27,11 @@ glabel audioNewThread /* 0032C4 800026C4 44814000 */ mtc1 $at, $f8 /* 0032C8 800026C8 44988000 */ mtc1 $t8, $f16 /* 0032CC 800026CC 46083282 */ mul.s $f10, $f6, $f8 -/* 0032D0 800026D0 3C048012 */ lui $a0, %hi(D_8011962C) # $a0, 0x8012 -/* 0032D4 800026D4 2484962C */ addiu $a0, %lo(D_8011962C) # addiu $a0, $a0, -0x69d4 -/* 0032D8 800026D8 3C148012 */ lui $s4, %hi(D_80119630) # $s4, 0x8012 +/* 0032D0 800026D0 3C048012 */ lui $a0, %hi(framesize) # $a0, 0x8012 +/* 0032D4 800026D4 2484962C */ addiu $a0, %lo(framesize) # addiu $a0, $a0, -0x69d4 +/* 0032D8 800026D8 3C148012 */ lui $s4, %hi(maxFrameSize) # $s4, 0x8012 /* 0032DC 800026DC 468084A0 */ cvt.s.w $f18, $f16 -/* 0032E0 800026E0 26949630 */ addiu $s4, %lo(D_80119630) # addiu $s4, $s4, -0x69d0 +/* 0032E0 800026E0 26949630 */ addiu $s4, %lo(maxFrameSize) # addiu $s4, $s4, -0x69d0 /* 0032E4 800026E4 46125003 */ div.s $f0, $f10, $f18 /* 0032E8 800026E8 4459F800 */ cfc1 $t9, $31 /* 0032EC 800026EC 00000000 */ nop @@ -66,8 +66,8 @@ glabel audioNewThread /* 003358 80002758 AC830000 */ sw $v1, ($a0) .L8000275C: /* 00335C 8000275C 246EFFF0 */ addiu $t6, $v1, -0x10 -/* 003360 80002760 3C018012 */ lui $at, %hi(D_80119628) # $at, 0x8012 -/* 003364 80002764 AC2E9628 */ sw $t6, %lo(D_80119628)($at) +/* 003360 80002760 3C018012 */ lui $at, %hi(minFrameSize) # $at, 0x8012 +/* 003364 80002764 AC2E9628 */ sw $t6, %lo(minFrameSize)($at) /* 003368 80002768 246F0070 */ addiu $t7, $v1, 0x70 /* 00336C 8000276C AE8F0000 */ sw $t7, ($s4) /* 003370 80002770 9278001C */ lbu $t8, 0x1c($s3) @@ -236,10 +236,10 @@ glabel audioNewThread /* 0035DC 800029DC 24846160 */ addiu $a0, %lo(OSMesgQueue_80116160) # addiu $a0, $a0, 0x6160 /* 0035E0 800029E0 0C032208 */ jal osCreateMesgQueue /* 0035E4 800029E4 24060008 */ li $a2, 8 -/* 0035E8 800029E8 3C048012 */ lui $a0, %hi(D_80119AF0) # $a0, 0x8012 -/* 0035EC 800029EC 3C058012 */ lui $a1, %hi(D_80119B08) # $a1, 0x8012 -/* 0035F0 800029F0 24A59B08 */ addiu $a1, %lo(D_80119B08) # addiu $a1, $a1, -0x64f8 -/* 0035F4 800029F4 24849AF0 */ addiu $a0, %lo(D_80119AF0) # addiu $a0, $a0, -0x6510 +/* 0035E8 800029E8 3C048012 */ lui $a0, %hi(audDMAMessageQ) # $a0, 0x8012 +/* 0035EC 800029EC 3C058012 */ lui $a1, %hi(audDMAMessageBuf) # $a1, 0x8012 +/* 0035F0 800029F0 24A59B08 */ addiu $a1, %lo(audDMAMessageBuf) # addiu $a1, $a1, -0x64f8 +/* 0035F4 800029F4 24849AF0 */ addiu $a0, %lo(audDMAMessageQ) # addiu $a0, $a0, -0x6510 /* 0035F8 800029F8 0C032208 */ jal osCreateMesgQueue /* 0035FC 800029FC 24060032 */ li $a2, 50 /* 003600 80002A00 8FB9004C */ lw $t9, 0x4c($sp) diff --git a/asm/non_matchings/unknown_003260/func_80002A98.s b/asm/non_matchings/unknown_003260/func_80002A98.s index c6732fd4..8f19cae9 100644 --- a/asm/non_matchings/unknown_003260/func_80002A98.s +++ b/asm/non_matchings/unknown_003260/func_80002A98.s @@ -5,7 +5,7 @@ glabel func_80002A98 /* 0036A4 80002AA4 AFBF003C */ sw $ra, 0x3c($sp) /* 0036A8 80002AA8 AFB00018 */ sw $s0, 0x18($sp) /* 0036AC 80002AAC 8C845F90 */ lw $a0, %lo(D_80115F90)($a0) -/* 0036B0 80002AB0 3C058011 */ lui $a1, %hi(D_80116220) # $a1, 0x8011 +/* 0036B0 80002AB0 3C058011 */ lui $a1, %hi(audioStack) # $a1, 0x8011 /* 0036B4 80002AB4 3C068011 */ lui $a2, %hi(OSMesgQueue_80116160) # $a2, 0x8011 /* 0036B8 80002AB8 AFBE0038 */ sw $fp, 0x38($sp) /* 0036BC 80002ABC AFB70034 */ sw $s7, 0x34($sp) @@ -19,14 +19,14 @@ glabel func_80002A98 /* 0036DC 80002ADC AFA00048 */ sw $zero, 0x48($sp) /* 0036E0 80002AE0 AFA00044 */ sw $zero, 0x44($sp) /* 0036E4 80002AE4 24C66160 */ addiu $a2, %lo(OSMesgQueue_80116160) # addiu $a2, $a2, 0x6160 -/* 0036E8 80002AE8 24A56220 */ addiu $a1, %lo(D_80116220) # addiu $a1, $a1, 0x6220 +/* 0036E8 80002AE8 24A56220 */ addiu $a1, %lo(audioStack) # addiu $a1, $a1, 0x6220 /* 0036EC 80002AEC 0C01E520 */ jal osScAddClient /* 0036F0 80002AF0 24070001 */ li $a3, 1 /* 0036F4 80002AF4 3C1E8011 */ lui $fp, %hi(D_80116198) # $fp, 0x8011 -/* 0036F8 80002AF8 3C16800E */ lui $s6, %hi(D_800DC680) # $s6, 0x800e +/* 0036F8 80002AF8 3C16800E */ lui $s6, %hi(audFrameCt) # $s6, 0x800e /* 0036FC 80002AFC 3C158011 */ lui $s5, %hi(D_80115F98) # $s5, 0x8011 /* 003700 80002B00 26B55F98 */ addiu $s5, %lo(D_80115F98) # addiu $s5, $s5, 0x5f98 -/* 003704 80002B04 26D6C680 */ addiu $s6, %lo(D_800DC680) # addiu $s6, $s6, -0x3980 +/* 003704 80002B04 26D6C680 */ addiu $s6, %lo(audFrameCt) # addiu $s6, $s6, -0x3980 /* 003708 80002B08 27DE6198 */ addiu $fp, %lo(D_80116198) # addiu $fp, $fp, 0x6198 /* 00370C 80002B0C 24170003 */ li $s7, 3 /* 003710 80002B10 2414000A */ li $s4, 10 diff --git a/asm/non_matchings/unknown_003260/func_80002C00.s b/asm/non_matchings/unknown_003260/func_80002C00.s index ce4a8b56..e85f43dc 100644 --- a/asm/non_matchings/unknown_003260/func_80002C00.s +++ b/asm/non_matchings/unknown_003260/func_80002C00.s @@ -33,15 +33,15 @@ glabel func_80002C00 .L80002C7C: /* 00387C 80002C7C 0C032388 */ jal osAiGetLength /* 003880 80002C80 00000000 */ nop -/* 003884 80002C84 3C188012 */ lui $t8, %hi(D_8011962C) # $t8, 0x8012 -/* 003888 80002C88 8F18962C */ lw $t8, %lo(D_8011962C)($t8) +/* 003884 80002C84 3C188012 */ lui $t8, %hi(framesize) # $t8, 0x8012 +/* 003888 80002C88 8F18962C */ lw $t8, %lo(framesize)($t8) /* 00388C 80002C8C 0002C882 */ srl $t9, $v0, 2 /* 003890 80002C90 03194023 */ subu $t0, $t8, $t9 /* 003894 80002C94 25090070 */ addiu $t1, $t0, 0x70 /* 003898 80002C98 312AFFF0 */ andi $t2, $t1, 0xfff0 /* 00389C 80002C9C A60A0004 */ sh $t2, 4($s0) -/* 0038A0 80002CA0 3C038012 */ lui $v1, %hi(D_80119628) # $v1, 0x8012 -/* 0038A4 80002CA4 8C639628 */ lw $v1, %lo(D_80119628)($v1) +/* 0038A0 80002CA0 3C038012 */ lui $v1, %hi(minFrameSize) # $v1, 0x8012 +/* 0038A4 80002CA4 8C639628 */ lw $v1, %lo(minFrameSize)($v1) /* 0038A8 80002CA8 86070004 */ lh $a3, 4($s0) /* 0038AC 80002CAC 3C0B800E */ lui $t3, %hi(D_800DC688) # $t3, 0x800e /* 0038B0 80002CB0 00E3082B */ sltu $at, $a3, $v1 @@ -52,13 +52,13 @@ glabel func_80002C00 /* 0038C4 80002CC4 00000000 */ nop .L80002CC8: /* 0038C8 80002CC8 8D6BC688 */ lw $t3, %lo(D_800DC688)($t3) -/* 0038CC 80002CCC 3C058012 */ lui $a1, %hi(D_80119634) # $a1, 0x8012 +/* 0038CC 80002CCC 3C058012 */ lui $a1, %hi(nextDMA) # $a1, 0x8012 /* 0038D0 80002CD0 000B6080 */ sll $t4, $t3, 2 /* 0038D4 80002CD4 008C2021 */ addu $a0, $a0, $t4 /* 0038D8 80002CD8 8C845F98 */ lw $a0, %lo(D_80115F98)($a0) /* 0038DC 80002CDC 8FA60024 */ lw $a2, 0x24($sp) /* 0038E0 80002CE0 0C019525 */ jal alAudioFrame -/* 0038E4 80002CE4 24A59634 */ addiu $a1, %lo(D_80119634) # addiu $a1, $a1, -0x69cc +/* 0038E4 80002CE4 24A59634 */ addiu $a1, %lo(nextDMA) # addiu $a1, $a1, -0x69cc /* 0038E8 80002CE8 3C0D8011 */ lui $t5, %hi(D_80116198) # $t5, 0x8011 /* 0038EC 80002CEC 24030002 */ li $v1, 2 /* 0038F0 80002CF0 3C06800E */ lui $a2, %hi(D_800DC688) # $a2, 0x800e diff --git a/asm/non_matchings/unknown_003260/func_80003040.s b/asm/non_matchings/unknown_003260/func_80003040.s index 3419bf91..53c1c76b 100644 --- a/asm/non_matchings/unknown_003260/func_80003040.s +++ b/asm/non_matchings/unknown_003260/func_80003040.s @@ -12,8 +12,8 @@ glabel func_80003040 /* 003C68 80003068 AFA00040 */ sw $zero, 0x40($sp) /* 003C6C 8000306C 11C0000D */ beqz $t6, .L800030A4 /* 003C70 80003070 00008025 */ move $s0, $zero -/* 003C74 80003074 3C118012 */ lui $s1, %hi(D_80119AF0) # $s1, 0x8012 -/* 003C78 80003078 26319AF0 */ addiu $s1, %lo(D_80119AF0) # addiu $s1, $s1, -0x6510 +/* 003C74 80003074 3C118012 */ lui $s1, %hi(audDMAMessageQ) # $s1, 0x8012 +/* 003C78 80003078 26319AF0 */ addiu $s1, %lo(audDMAMessageQ) # addiu $s1, $s1, -0x6510 /* 003C7C 8000307C 27B20040 */ addiu $s2, $sp, 0x40 /* 003C80 80003080 02202025 */ move $a0, $s1 .L80003084: @@ -29,9 +29,9 @@ glabel func_80003040 /* 003CA4 800030A4 3C128012 */ lui $s2, %hi(dmaState) # $s2, 0x8012 /* 003CA8 800030A8 26529230 */ addiu $s2, %lo(dmaState) # addiu $s2, $s2, -0x6dd0 /* 003CAC 800030AC 8E500004 */ lw $s0, 4($s2) -/* 003CB0 800030B0 3C13800E */ lui $s3, %hi(D_800DC680) # $s3, 0x800e +/* 003CB0 800030B0 3C13800E */ lui $s3, %hi(audFrameCt) # $s3, 0x800e /* 003CB4 800030B4 1200001C */ beqz $s0, .L80003128 -/* 003CB8 800030B8 2673C680 */ addiu $s3, %lo(D_800DC680) # addiu $s3, $s3, -0x3980 +/* 003CB8 800030B8 2673C680 */ addiu $s3, %lo(audFrameCt) # addiu $s3, $s3, -0x3980 .L800030BC: /* 003CBC 800030BC 8E19000C */ lw $t9, 0xc($s0) /* 003CC0 800030C0 8E780000 */ lw $t8, ($s3) @@ -64,8 +64,8 @@ glabel func_80003040 /* 003D20 80003120 1620FFE6 */ bnez $s1, .L800030BC /* 003D24 80003124 02208025 */ move $s0, $s1 .L80003128: -/* 003D28 80003128 3C13800E */ lui $s3, %hi(D_800DC680) # $s3, 0x800e -/* 003D2C 8000312C 2673C680 */ addiu $s3, %lo(D_800DC680) # addiu $s3, $s3, -0x3980 +/* 003D28 80003128 3C13800E */ lui $s3, %hi(audFrameCt) # $s3, 0x800e +/* 003D2C 8000312C 2673C680 */ addiu $s3, %lo(audFrameCt) # addiu $s3, $s3, -0x3980 /* 003D30 80003130 8E6A0000 */ lw $t2, ($s3) /* 003D34 80003134 8FBF002C */ lw $ra, 0x2c($sp) /* 003D38 80003138 254B0001 */ addiu $t3, $t2, 1 diff --git a/src/unknown_003260.c b/src/unknown_003260.c index 268cd00e..d7c06110 100644 --- a/src/unknown_003260.c +++ b/src/unknown_003260.c @@ -19,17 +19,19 @@ extern OSMesg D_80116178[8]; extern OSMesgQueue D_80116198; extern OSMesg D_801161B0[8]; extern ALGlobals ALGlobals_801161D0; -extern s32 D_80116220[3076]; +extern u64 audioStack[AUDIO_STACKSIZE/sizeof(u64)]; extern AMDMAState dmaState; extern AMDMABuffer dmaBuffs[50]; -extern s32 D_80119628; -extern s32 D_8011962C; -extern s32 D_80119630; -extern s32 D_80119634; -extern s32 D_80119638[2]; -extern s32 D_80119640[300]; -extern OSMesgQueue D_80119AF0; -extern OSMesg D_80119B08[50]; +extern u32 minFrameSize; +extern u32 framesize; +extern u32 maxFrameSize; +extern u32 nextDMA; +extern u32 frameSize; +extern u32 D_8011963c; +extern u32 maxRSPCmds; +extern OSIoMesg audDMAIOMesgBuf[NUM_DMA_MESSAGES]; +extern OSMesgQueue audDMAMessageQ; +extern OSMesg audDMAMessageBuf[NUM_DMA_MESSAGES]; extern unk800DC6BC D_80119BD0; extern u16 *D_80119C28; extern f32 gVideoRefreshRate; @@ -38,7 +40,7 @@ extern f32 gVideoRefreshRate; /************ .data ************/ -s32 D_800DC680 = 0; // Currently unknown, might be a different type. +u32 audFrameCt = 0; // Currently unknown, might be a different type. s32 D_800DC684 = 0; // Currently unknown, might be a different type. s32 D_800DC688 = 0; // Currently unknown, might be a different type. s32 D_800DC68C = 0; // Currently unknown, might be a different type. @@ -93,8 +95,8 @@ void audioNewThread(ALSynConfig *c, OSPri p, OSSched *arg2) { D_80115F94 = c->heap; c->dmaproc = &__amDmaNew; c->outputRate = osAiSetFrequency(22050); - D_8011962C = (((f32)c->outputRate) * 2.0f) / gVideoRefreshRate; - if (D_8011962C < 0) { + framesize = (((f32)c->outputRate) * 2.0f) / gVideoRefreshRate; + if (framesize < 0) { } if (c->fxType == AL_FX_CUSTOM) { @@ -121,7 +123,7 @@ void audioNewThread(ALSynConfig *c, OSPri p, OSSched *arg2) { osCreateMesgQueue(&D_80116198, &D_801161B0, 8); osCreateMesgQueue(&OSMesgQueue_80116160, &D_80116178, 8); - osCreateMesgQueue(&D_80119AF0, &D_80119B08, 50); + osCreateMesgQueue(&audDMAMessageQ, &audDMAMessageBuf, 50); osCreateThread(&audioThread, 4, &func_80002A98, NULL, &dmaState, p); } @@ -138,8 +140,118 @@ void audioStopThread(void) { GLOBAL_ASM("asm/non_matchings/unknown_003260/func_80002A98.s") GLOBAL_ASM("asm/non_matchings/unknown_003260/func_80002C00.s") GLOBAL_ASM("asm/non_matchings/unknown_003260/func_80002DF8.s") -GLOBAL_ASM("asm/non_matchings/unknown_003260/__amDMA.s") +/****************************************************************************** + * + * __amDMA This routine handles the dma'ing of samples from rom to ram. + * First it checks the current buffers to see if the samples needed are + * already in place. Because buffers are linked sequentially by the + * addresses where the samples are on rom, it doesn't need to check all + * of them, only up to the address that it needs. If it finds one, it + * returns the address of that buffer. If it doesn't find the samples + * that it needs, it will initiate a DMA of the samples that it needs. + * In either case, it updates the lastFrame variable, to indicate that + * this buffer was last used in this frame. This is important for the + * __clearAudioDMA routine. + * + *****************************************************************************/ +#if 0 +#define DMA_BUFFER_LENGTH 0x400 +s32 __amDMA(s32 addr, s32 len, void *state) +{ + void *foundBuffer; + s32 delta, addrEnd, buffEnd; + AMDMABuffer *dmaPtr, *lastDmaPtr; + + lastDmaPtr = 0; + dmaPtr = dmaState.firstUsed; + addrEnd = addr+len; + + /* first check to see if a currently existing buffer contains the + sample that you need. */ + + while(dmaPtr) + { + buffEnd = dmaPtr->startAddr + DMA_BUFFER_LENGTH; + if(dmaPtr->startAddr > addr) /* since buffers are ordered */ + break; /* abort if past possible */ + + else if(addrEnd <= buffEnd) /* yes, found a buffer with samples */ + { + dmaPtr->lastFrame = audFrameCt; /* mark it used */ + foundBuffer = dmaPtr->ptr + addr - dmaPtr->startAddr; + return (int) osVirtualToPhysical(foundBuffer); + } + lastDmaPtr = dmaPtr; + dmaPtr = (AMDMABuffer*)dmaPtr->node.next; + } + + /* get here, and you didn't find a buffer, so dma a new one */ + + /* get a buffer from the free list */ + dmaPtr = dmaState.firstFree; + + /* + * if you get here and dmaPtr is null, send back the a bogus + * pointer, it's better than nothing + */ + if(!dmaPtr) + return osVirtualToPhysical(dmaState.firstUsed); + + dmaState.firstFree = (AMDMABuffer*)dmaPtr->node.next; + alUnlink((ALLink*)dmaPtr); + + /* add it to the used list */ + if(lastDmaPtr) /* if you have other dmabuffers used, add this one */ + { /* to the list, after the last one checked above */ + alLink((ALLink*)dmaPtr,(ALLink*)lastDmaPtr); + } + else if(dmaState.firstUsed) /* if this buffer is before any others */ + { /* jam at begining of list */ + lastDmaPtr = dmaState.firstUsed; + dmaState.firstUsed = dmaPtr; + dmaPtr->node.next = (ALLink*)lastDmaPtr; + dmaPtr->node.prev = 0; + lastDmaPtr->node.prev = (ALLink*)dmaPtr; + } + else /* no buffers in list, this is the first one */ + { + dmaState.firstUsed = dmaPtr; + dmaPtr->node.next = 0; + dmaPtr->node.prev = 0; + } + + foundBuffer = dmaPtr->ptr; + delta = addr & 0x1; + addr -= delta; + dmaPtr->startAddr = addr; + dmaPtr->lastFrame = audFrameCt; /* mark it */ + + audDMAIOMesgBuf[nextDMA].hdr.pri = OS_MESG_PRI_NORMAL; + audDMAIOMesgBuf[nextDMA].hdr.retQueue = &audDMAMessageQ; + audDMAIOMesgBuf[nextDMA].dramAddr = foundBuffer; + audDMAIOMesgBuf[nextDMA].devAddr = (u32)addr; + audDMAIOMesgBuf[nextDMA].size = DMA_BUFFER_LENGTH; + + osPiStartDma(&audDMAIOMesgBuf[nextDMA++], 1, 0, addr, foundBuffer, 0x400U, &audDMAMessageQ); + + return (int) osVirtualToPhysical(foundBuffer) + delta; +} +#else +GLOBAL_ASM("asm/non_matchings/unknown_003260/__amDMA.s") +#endif + +/****************************************************************************** + * + * __amDmaNew. Initialize the dma buffers and return the address of the + * procedure that will be used to dma the samples from rom to ram. This + * routine will be called once for each physical voice that is created. + * In this case, because we know where all the buffers are, and since + * they are not attached to a specific voice, we will only really do any + * initialization the first time. After that we just return the address + * to the dma routine. + * + *****************************************************************************/ ALDMAproc __amDmaNew(AMDMAState **state) { int i; diff --git a/src/unknown_003260.h b/src/unknown_003260.h index 56ae3757..42ad6c2d 100644 --- a/src/unknown_003260.h +++ b/src/unknown_003260.h @@ -18,6 +18,9 @@ #define AL_SNDP_END_EVT (1 << 7) #define AL_SNDP_FX_EVT (1 << 8) +#define AUDIO_STACKSIZE 0x3010 +#define NUM_DMA_MESSAGES 50 + typedef struct unk800DC6BC_40 { ALLink node; u8 pad0C[0x38]; @@ -49,12 +52,12 @@ typedef union { }ALSndpEvent; -typedef struct AMDMABuffer +typedef struct { - ALLink node; - u32 unk08; - u32 unk0C; - void *unk10; + ALLink node; + u32 startAddr; + u32 lastFrame; + char *ptr; } AMDMABuffer; /* Unknown Size */ @@ -74,12 +77,11 @@ typedef struct audioMgrConfig_s{ typedef struct { u8 initialized; - u8 unk1[3]; AMDMABuffer *firstUsed; AMDMABuffer *firstFree; } AMDMAState; -extern s32 D_800DC680; +extern u32 audFrameCt; extern s32 D_800DC684; extern s32 D_800DC688; extern s32 D_800DC68C; diff --git a/src/unknown_003260_bss.c b/src/unknown_003260_bss.c index 84740ab7..d5e5e236 100644 --- a/src/unknown_003260_bss.c +++ b/src/unknown_003260_bss.c @@ -14,16 +14,17 @@ OSMesg D_80116178[8]; OSMesgQueue D_80116198; OSMesg D_801161B0[8]; ALGlobals ALGlobals_801161D0; -s32 D_80116220[3076]; +u64 audioStack[AUDIO_STACKSIZE/sizeof(u64)]; AMDMAState dmaState; AMDMABuffer dmaBuffs[50]; -s32 D_80119628; -s32 D_8011962C; -s32 D_80119630; -s32 D_80119634; -s32 D_80119638[2]; -s32 D_80119640[300]; -OSMesgQueue D_80119AF0; -OSMesg D_80119B08[50]; +u32 minFrameSize; +u32 framesize; +u32 maxFrameSize; +u32 nextDMA; +u32 D_80119638; +u32 D_8011963C; +OSIoMesg audDMAIOMesgBuf[NUM_DMA_MESSAGES]; +OSMesgQueue audDMAMessageQ; +OSMesg audDMAMessageBuf[NUM_DMA_MESSAGES]; unk800DC6BC D_80119BD0; u16 *D_80119C28;