From 023dbb2126cf490b407a2dd34179558ff2451ab0 Mon Sep 17 00:00:00 2001 From: Ryan Myers Date: Tue, 31 Jan 2023 07:39:22 -0500 Subject: [PATCH] Match and split unknown_003260.c into audiomgr.c and audiosfx.c (#364) * Minor code cleanup and documenting in audio.c * Match to func_80002DF8 to _amDmaNew * Match func_800042CC * Match func_8000410C * Match func_800041FC as _removeEvents, and rename thread4_main to __amMain while also getting it's code to closer resemble the example code * Add missing file * MAtch __clearAudioDMA * Cleanup __clearAudioDMA to match our code style a little better * Match __amHandleFrameMsg * Rename audio microcode from unknown, and clean up some code styles and variables names * WIP audioNewThread * Update WIP for audioNewThread * Close to matching audioNewThread * Match amCreateAudioMgr * Match __amDMA * Add constants, and remove static functions from header * Make funcitons static where the originals were * Fix score.py * Split audiomgr and audiosfx files * WIP clean up of audiomgr.c * Finalize split of audiomgr and audiosfx * Use AMAudioMgr * Move the deck chairs * Clean up sfx header * Cleanup * Cleanup sfx file, and move asm files * Update score * Fix NON_EQUIVALENT * Match _sndpVoiceHandler * Update some types --- README.md | 20 +- asm/assets/ucode_data.s | 4 +- asm/assets/ucode_text.s | 4 +- .../_handleEvent.s | 2 +- .../func_8000418C.s | 4 +- .../func_80004384.s | 0 .../func_80004520.s | 0 .../func_80004668.s | 4 +- .../func_800048D8.s | 4 +- asm/non_matchings/unknown_003260/__amDMA.s | 129 ----- .../unknown_003260/_sndpVoiceHandler.s | 47 -- .../unknown_003260/audioNewThread.s | 265 --------- .../unknown_003260/func_80002C00.s | 130 ----- .../unknown_003260/func_80003040.s | 81 --- .../unknown_003260/func_8000410C.s | 35 -- .../unknown_003260/func_800041FC.s | 58 -- .../unknown_003260/func_800042CC.s | 54 -- extract-ver/us_1.0.config.json | 4 +- include/sched.h | 11 +- lib/src/os/osAiGetLength.c | 7 + src/audio.c | 88 ++- src/audio.h | 2 +- src/audiomgr.c | 538 ++++++++++++++++++ src/audiomgr.h | 59 ++ src/audiosfx.c | 303 ++++++++++ src/audiosfx.h | 139 +++++ src/game.c | 3 +- src/game_ui.c | 2 +- src/menu.c | 4 +- src/object_functions.c | 2 +- src/racer.c | 2 +- src/unknown_003260.c | 489 ---------------- src/unknown_003260.h | 137 ----- src/unknown_003260_bss.c | 30 - src/unknown_008C40.c | 2 +- tools/python/generate_assets.py | 4 +- 36 files changed, 1128 insertions(+), 1539 deletions(-) rename asm/non_matchings/{unknown_003260 => audiosfx}/_handleEvent.s (99%) rename asm/non_matchings/{unknown_003260 => audiosfx}/func_8000418C.s (90%) rename asm/non_matchings/{unknown_003260 => audiosfx}/func_80004384.s (100%) rename asm/non_matchings/{unknown_003260 => audiosfx}/func_80004520.s (100%) rename asm/non_matchings/{unknown_003260 => audiosfx}/func_80004668.s (97%) rename asm/non_matchings/{unknown_003260 => audiosfx}/func_800048D8.s (93%) delete mode 100644 asm/non_matchings/unknown_003260/__amDMA.s delete mode 100644 asm/non_matchings/unknown_003260/_sndpVoiceHandler.s delete mode 100644 asm/non_matchings/unknown_003260/audioNewThread.s delete mode 100644 asm/non_matchings/unknown_003260/func_80002C00.s delete mode 100644 asm/non_matchings/unknown_003260/func_80003040.s delete mode 100644 asm/non_matchings/unknown_003260/func_8000410C.s delete mode 100644 asm/non_matchings/unknown_003260/func_800041FC.s delete mode 100644 asm/non_matchings/unknown_003260/func_800042CC.s create mode 100644 src/audiomgr.c create mode 100644 src/audiomgr.h create mode 100644 src/audiosfx.c create mode 100644 src/audiosfx.h delete mode 100644 src/unknown_003260.c delete mode 100644 src/unknown_003260.h delete mode 100644 src/unknown_003260_bss.c diff --git a/README.md b/README.md index c9796019..8a79d4ed 100644 --- a/README.md +++ b/README.md @@ -120,30 +120,30 @@ s32 is_drumstick_unlocked(void) { ``` -As of January 23, 2023, this is our current score: +As of January 30, 2023, this is our current score: ``` =================================================================== ADVENTURE ONE (ASM -> C Decompilation) - ------------------------- 49.47% Complete ------------------------- - # Decompiled functions: 1477 - # GLOBAL_ASM remaining: 361 + ------------------------- 49.78% Complete ------------------------- + # Decompiled functions: 1478 + # GLOBAL_ASM remaining: 353 # NON_MATCHING functions: 10 - # NON_EQUIVALENT WIP functions: 66 + # NON_EQUIVALENT WIP functions: 63 --------------------------- Game Status --------------------------- Balloons: 24/47, Keys: 3/4, Trophies: 2/5 T.T. Amulets: 2/4, Wizpig Amulets: 2/4 ------------------------------------------------------------------- - We are racing in Pirate Lagoon. (Lap 2/3) + We are racing in Pirate Lagoon. (Lap 3/3) =================================================================== ADVENTURE TWO (Cleanup & Documentation) - ------------------------- 23.13% Complete ------------------------- - # Documented functions: 428 - # Undocumented remaining: 1145 + ------------------------- 23.09% Complete ------------------------- + # Documented functions: 427 + # Undocumented remaining: 1139 --------------------------- Game Status --------------------------- Balloons: 12/47, Keys: 1/4, Trophies: 0/5 T.T. Amulets: 1/4, Wizpig Amulets: 1/4 ------------------------------------------------------------------- - We are participating in the Trophy Race of Dino Domain. (Round Two) + We are participating in the Trophy Race of Dino Domain. (Round One) =================================================================== ``` diff --git a/asm/assets/ucode_data.s b/asm/assets/ucode_data.s index d3cd9401..0f4da3be 100644 --- a/asm/assets/ucode_data.s +++ b/asm/assets/ucode_data.s @@ -2,8 +2,8 @@ .include "macros.inc" -glabel rspUnknownDataStart -.incbin "./build/us_1.0/ucode/data_unknown.bin" +glabel aspMainDataStart +.incbin "./build/us_1.0/ucode/data_audio.bin" glabel rspF3DDKRDataDramStart .incbin "./build/us_1.0/ucode/data_f3ddkr_dram.bin" glabel rspF3DDKRDataFifoStart diff --git a/asm/assets/ucode_text.s b/asm/assets/ucode_text.s index 945a6928..d014c215 100644 --- a/asm/assets/ucode_text.s +++ b/asm/assets/ucode_text.s @@ -2,8 +2,8 @@ .include "macros.inc" -glabel rspUnknownStart -.incbin "./build/us_1.0/ucode/ucode_unknown.bin" +glabel aspMainTextStart +.incbin "./build/us_1.0/ucode/ucode_audio.bin" glabel rspF3DDKRBootStart .incbin "./build/us_1.0/ucode/ucode_boot.bin" glabel rspF3DDKRDramStart diff --git a/asm/non_matchings/unknown_003260/_handleEvent.s b/asm/non_matchings/audiosfx/_handleEvent.s similarity index 99% rename from asm/non_matchings/unknown_003260/_handleEvent.s rename to asm/non_matchings/audiosfx/_handleEvent.s index 8a97527d..6ac4d396 100644 --- a/asm/non_matchings/unknown_003260/_handleEvent.s +++ b/asm/non_matchings/audiosfx/_handleEvent.s @@ -416,7 +416,7 @@ glabel L80003A0C /* 004654 80003A54 24010002 */ li $at, 2 .L80003A58: /* 004658 80003A58 02202825 */ move $a1, $s1 -/* 00465C 80003A5C 0C00107F */ jal func_800041FC +/* 00465C 80003A5C 0C00107F */ jal _removeEvents /* 004660 80003A60 24060040 */ li $a2, 64 /* 004664 80003A64 8E4D0000 */ lw $t5, ($s2) /* 004668 80003A68 C6260028 */ lwc1 $f6, 0x28($s1) diff --git a/asm/non_matchings/unknown_003260/func_8000418C.s b/asm/non_matchings/audiosfx/func_8000418C.s similarity index 90% rename from asm/non_matchings/unknown_003260/func_8000418C.s rename to asm/non_matchings/audiosfx/func_8000418C.s index dcae67fe..b2e40e04 100644 --- a/asm/non_matchings/unknown_003260/func_8000418C.s +++ b/asm/non_matchings/audiosfx/func_8000418C.s @@ -9,9 +9,9 @@ glabel func_8000418C /* 004DA8 800041A8 0C032678 */ jal alCents2Ratio /* 004DAC 800041AC AFA70030 */ sw $a3, 0x30($sp) /* 004DB0 800041B0 8FA70030 */ lw $a3, 0x30($sp) -/* 004DB4 800041B4 3C04800E */ lui $a0, %hi(gAlSndPlayer) # $a0, 0x800e +/* 004DB4 800041B4 3C04800E */ lui $a0, %hi(gAlSndPlayerPtr) # $a0, 0x800e /* 004DB8 800041B8 C4E4002C */ lwc1 $f4, 0x2c($a3) -/* 004DBC 800041BC 8C84C6BC */ lw $a0, %lo(gAlSndPlayer)($a0) +/* 004DBC 800041BC 8C84C6BC */ lw $a0, %lo(gAlSndPlayerPtr)($a0) /* 004DC0 800041C0 46040182 */ mul.s $f6, $f0, $f4 /* 004DC4 800041C4 24180010 */ li $t8, 16 /* 004DC8 800041C8 A7B80020 */ sh $t8, 0x20($sp) diff --git a/asm/non_matchings/unknown_003260/func_80004384.s b/asm/non_matchings/audiosfx/func_80004384.s similarity index 100% rename from asm/non_matchings/unknown_003260/func_80004384.s rename to asm/non_matchings/audiosfx/func_80004384.s diff --git a/asm/non_matchings/unknown_003260/func_80004520.s b/asm/non_matchings/audiosfx/func_80004520.s similarity index 100% rename from asm/non_matchings/unknown_003260/func_80004520.s rename to asm/non_matchings/audiosfx/func_80004520.s diff --git a/asm/non_matchings/unknown_003260/func_80004668.s b/asm/non_matchings/audiosfx/func_80004668.s similarity index 97% rename from asm/non_matchings/unknown_003260/func_80004668.s rename to asm/non_matchings/audiosfx/func_80004668.s index 12890277..98bc3078 100644 --- a/asm/non_matchings/unknown_003260/func_80004668.s +++ b/asm/non_matchings/audiosfx/func_80004668.s @@ -24,9 +24,9 @@ glabel func_80004668 /* 0052C0 800046C0 10000066 */ b .L8000485C /* 0052C4 800046C4 00001025 */ move $v0, $zero .L800046C8: -/* 0052C8 800046C8 3C15800E */ lui $s5, %hi(gAlSndPlayer) # $s5, 0x800e +/* 0052C8 800046C8 3C15800E */ lui $s5, %hi(gAlSndPlayerPtr) # $s5, 0x800e /* 0052CC 800046CC 8FB30064 */ lw $s3, 0x64($sp) -/* 0052D0 800046D0 26B5C6BC */ addiu $s5, %lo(gAlSndPlayer) # addiu $s5, $s5, -0x3944 +/* 0052D0 800046D0 26B5C6BC */ addiu $s5, %lo(gAlSndPlayerPtr) # addiu $s5, $s5, -0x3944 /* 0052D4 800046D4 AFA40080 */ sw $a0, 0x80($sp) /* 0052D8 800046D8 27B60050 */ addiu $s6, $sp, 0x50 /* 0052DC 800046DC 8FA40080 */ lw $a0, 0x80($sp) diff --git a/asm/non_matchings/unknown_003260/func_800048D8.s b/asm/non_matchings/audiosfx/func_800048D8.s similarity index 93% rename from asm/non_matchings/unknown_003260/func_800048D8.s rename to asm/non_matchings/audiosfx/func_800048D8.s index c529bff2..7773b50e 100644 --- a/asm/non_matchings/unknown_003260/func_800048D8.s +++ b/asm/non_matchings/audiosfx/func_800048D8.s @@ -15,8 +15,8 @@ glabel func_800048D8 /* 00550C 8000490C AFA2004C */ sw $v0, 0x4c($sp) /* 005510 80004910 12000016 */ beqz $s0, .L8000496C /* 005514 80004914 02408825 */ move $s1, $s2 -/* 005518 80004918 3C13800E */ lui $s3, %hi(gAlSndPlayer) # $s3, 0x800e -/* 00551C 8000491C 2673C6BC */ addiu $s3, %lo(gAlSndPlayer) # addiu $s3, $s3, -0x3944 +/* 005518 80004918 3C13800E */ lui $s3, %hi(gAlSndPlayerPtr) # $s3, 0x800e +/* 00551C 8000491C 2673C6BC */ addiu $s3, %lo(gAlSndPlayerPtr) # addiu $s3, $s3, -0x3944 /* 005520 80004920 27B4003C */ addiu $s4, $sp, 0x3c /* 005524 80004924 2412FFEF */ li $s2, -17 /* 005528 80004928 240E0400 */ li $t6, 1024 diff --git a/asm/non_matchings/unknown_003260/__amDMA.s b/asm/non_matchings/unknown_003260/__amDMA.s deleted file mode 100644 index bc1a769f..00000000 --- a/asm/non_matchings/unknown_003260/__amDMA.s +++ /dev/null @@ -1,129 +0,0 @@ -glabel __amDMA -/* 003A38 80002E38 3C098012 */ lui $t1, %hi(dmaState) # $t1, 0x8012 -/* 003A3C 80002E3C 25299230 */ addiu $t1, %lo(dmaState) # addiu $t1, $t1, -0x6dd0 -/* 003A40 80002E40 27BDFFB0 */ addiu $sp, $sp, -0x50 -/* 003A44 80002E44 8D280004 */ lw $t0, 4($t1) -/* 003A48 80002E48 AFB00028 */ sw $s0, 0x28($sp) -/* 003A4C 80002E4C AFA60058 */ sw $a2, 0x58($sp) -/* 003A50 80002E50 308A0001 */ andi $t2, $a0, 1 -/* 003A54 80002E54 AFBF002C */ sw $ra, 0x2c($sp) -/* 003A58 80002E58 00803825 */ move $a3, $a0 -/* 003A5C 80002E5C 00003025 */ move $a2, $zero -/* 003A60 80002E60 AFAA0048 */ sw $t2, 0x48($sp) -/* 003A64 80002E64 11000016 */ beqz $t0, .L80002EC0 -/* 003A68 80002E68 01008025 */ move $s0, $t0 -.L80002E6C: -/* 003A6C 80002E6C 8E020008 */ lw $v0, 8($s0) -/* 003A70 80002E70 00E57021 */ addu $t6, $a3, $a1 -/* 003A74 80002E74 00E2082B */ sltu $at, $a3, $v0 -/* 003A78 80002E78 14200011 */ bnez $at, .L80002EC0 -/* 003A7C 80002E7C 24430400 */ addiu $v1, $v0, 0x400 -/* 003A80 80002E80 006E082A */ slt $at, $v1, $t6 -/* 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(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 -/* 003AA4 80002EA4 AE0F000C */ sw $t7, 0xc($s0) -/* 003AA8 80002EA8 10000054 */ b .L80002FFC -/* 003AAC 80002EAC 8FBF002C */ lw $ra, 0x2c($sp) -.L80002EB0: -/* 003AB0 80002EB0 8E100000 */ lw $s0, ($s0) -/* 003AB4 80002EB4 00000000 */ nop -/* 003AB8 80002EB8 1600FFEC */ bnez $s0, .L80002E6C -/* 003ABC 80002EBC 00000000 */ nop -.L80002EC0: -/* 003AC0 80002EC0 8D300008 */ lw $s0, 8($t1) -/* 003AC4 80002EC4 00000000 */ nop -/* 003AC8 80002EC8 16000004 */ bnez $s0, .L80002EDC -/* 003ACC 80002ECC 02002025 */ move $a0, $s0 -/* 003AD0 80002ED0 14C00002 */ bnez $a2, .L80002EDC -/* 003AD4 80002ED4 00000000 */ nop -/* 003AD8 80002ED8 01003025 */ move $a2, $t0 -.L80002EDC: -/* 003ADC 80002EDC 16000007 */ bnez $s0, .L80002EFC -/* 003AE0 80002EE0 00000000 */ nop -/* 003AE4 80002EE4 8CC40010 */ lw $a0, 0x10($a2) -/* 003AE8 80002EE8 0C03233C */ jal osVirtualToPhysical -/* 003AEC 80002EEC AFAA0030 */ sw $t2, 0x30($sp) -/* 003AF0 80002EF0 8FAA0030 */ lw $t2, 0x30($sp) -/* 003AF4 80002EF4 10000040 */ b .L80002FF8 -/* 003AF8 80002EF8 004A1021 */ addu $v0, $v0, $t2 -.L80002EFC: -/* 003AFC 80002EFC 8E0B0000 */ lw $t3, ($s0) -/* 003B00 80002F00 AFA70050 */ sw $a3, 0x50($sp) -/* 003B04 80002F04 AFA60038 */ sw $a2, 0x38($sp) -/* 003B08 80002F08 0C0321D8 */ jal alUnlink -/* 003B0C 80002F0C AD2B0008 */ sw $t3, 8($t1) -/* 003B10 80002F10 8FA60038 */ lw $a2, 0x38($sp) -/* 003B14 80002F14 8FA70050 */ lw $a3, 0x50($sp) -/* 003B18 80002F18 3C098012 */ lui $t1, %hi(dmaState) # $t1, 0x8012 -/* 003B1C 80002F1C 10C00008 */ beqz $a2, .L80002F40 -/* 003B20 80002F20 25299230 */ addiu $t1, %lo(dmaState) # addiu $t1, $t1, -0x6dd0 -/* 003B24 80002F24 02002025 */ move $a0, $s0 -/* 003B28 80002F28 00C02825 */ move $a1, $a2 -/* 003B2C 80002F2C 0C0321E4 */ jal alLink -/* 003B30 80002F30 AFA70050 */ sw $a3, 0x50($sp) -/* 003B34 80002F34 8FA70050 */ lw $a3, 0x50($sp) -/* 003B38 80002F38 1000000E */ b .L80002F74 -/* 003B3C 80002F3C 8FAC0048 */ lw $t4, 0x48($sp) -.L80002F40: -/* 003B40 80002F40 8D280004 */ lw $t0, 4($t1) -/* 003B44 80002F44 00000000 */ nop -/* 003B48 80002F48 11000006 */ beqz $t0, .L80002F64 -/* 003B4C 80002F4C 00000000 */ nop -/* 003B50 80002F50 AD300004 */ sw $s0, 4($t1) -/* 003B54 80002F54 AE080000 */ sw $t0, ($s0) -/* 003B58 80002F58 AE000004 */ sw $zero, 4($s0) -/* 003B5C 80002F5C 10000004 */ b .L80002F70 -/* 003B60 80002F60 AD100004 */ sw $s0, 4($t0) -.L80002F64: -/* 003B64 80002F64 AD300004 */ sw $s0, 4($t1) -/* 003B68 80002F68 AE000000 */ sw $zero, ($s0) -/* 003B6C 80002F6C AE000004 */ sw $zero, 4($s0) -.L80002F70: -/* 003B70 80002F70 8FAC0048 */ lw $t4, 0x48($sp) -.L80002F74: -/* 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(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(audDMAIOMesgBuf) # $t7, 0x8012 -/* 003B9C 80002F9C 00027080 */ sll $t6, $v0, 2 -/* 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(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) -/* 003BC0 80002FC0 AFB80014 */ sw $t8, 0x14($sp) -/* 003BC4 80002FC4 01CF2021 */ addu $a0, $t6, $t7 -/* 003BC8 80002FC8 AFB90018 */ sw $t9, 0x18($sp) -/* 003BCC 80002FCC 24050001 */ li $a1, 1 -/* 003BD0 80002FD0 00003025 */ move $a2, $zero -/* 003BD4 80002FD4 AFA30010 */ sw $v1, 0x10($sp) -/* 003BD8 80002FD8 0C0323E0 */ jal osPiStartDma -/* 003BDC 80002FDC AFA3004C */ sw $v1, 0x4c($sp) -/* 003BE0 80002FE0 8FA4004C */ lw $a0, 0x4c($sp) -/* 003BE4 80002FE4 0C03233C */ jal osVirtualToPhysical -/* 003BE8 80002FE8 00000000 */ nop -/* 003BEC 80002FEC 8FAC0048 */ lw $t4, 0x48($sp) -/* 003BF0 80002FF0 00000000 */ nop -/* 003BF4 80002FF4 004C1021 */ addu $v0, $v0, $t4 -.L80002FF8: -/* 003BF8 80002FF8 8FBF002C */ lw $ra, 0x2c($sp) -.L80002FFC: -/* 003BFC 80002FFC 8FB00028 */ lw $s0, 0x28($sp) -/* 003C00 80003000 03E00008 */ jr $ra -/* 003C04 80003004 27BD0050 */ addiu $sp, $sp, 0x50 - diff --git a/asm/non_matchings/unknown_003260/_sndpVoiceHandler.s b/asm/non_matchings/unknown_003260/_sndpVoiceHandler.s deleted file mode 100644 index c5e6b997..00000000 --- a/asm/non_matchings/unknown_003260/_sndpVoiceHandler.s +++ /dev/null @@ -1,47 +0,0 @@ -glabel _sndpVoiceHandler -/* 003FC8 800033C8 27BDFFB0 */ addiu $sp, $sp, -0x50 -/* 003FCC 800033CC AFB40028 */ sw $s4, 0x28($sp) -/* 003FD0 800033D0 AFB30024 */ sw $s3, 0x24($sp) -/* 003FD4 800033D4 AFB20020 */ sw $s2, 0x20($sp) -/* 003FD8 800033D8 AFB1001C */ sw $s1, 0x1c($sp) -/* 003FDC 800033DC AFB00018 */ sw $s0, 0x18($sp) -/* 003FE0 800033E0 00808025 */ move $s0, $a0 -/* 003FE4 800033E4 AFBF002C */ sw $ra, 0x2c($sp) -/* 003FE8 800033E8 24910028 */ addiu $s1, $a0, 0x28 -/* 003FEC 800033EC 24920014 */ addiu $s2, $a0, 0x14 -/* 003FF0 800033F0 24130020 */ li $s3, 32 -/* 003FF4 800033F4 27B4003C */ addiu $s4, $sp, 0x3c -.L800033F8: -/* 003FF8 800033F8 860E0028 */ lh $t6, 0x28($s0) -/* 003FFC 800033FC 240F0020 */ li $t7, 32 -/* 004000 80003400 166E0008 */ bne $s3, $t6, .L80003424 -/* 004004 80003404 02002025 */ move $a0, $s0 -/* 004008 80003408 A7AF003C */ sh $t7, 0x3c($sp) -/* 00400C 8000340C 8E06004C */ lw $a2, 0x4c($s0) -/* 004010 80003410 02402025 */ move $a0, $s2 -/* 004014 80003414 0C03246B */ jal alEvtqPostEvent -/* 004018 80003418 02802825 */ move $a1, $s4 -/* 00401C 8000341C 10000004 */ b .L80003430 -/* 004020 80003420 02402025 */ move $a0, $s2 -.L80003424: -/* 004024 80003424 0C000D1C */ jal _handleEvent -/* 004028 80003428 02202825 */ move $a1, $s1 -/* 00402C 8000342C 02402025 */ move $a0, $s2 -.L80003430: -/* 004030 80003430 0C0324B4 */ jal alEvtqNextEvent -/* 004034 80003434 02202825 */ move $a1, $s1 -/* 004038 80003438 1040FFEF */ beqz $v0, .L800033F8 -/* 00403C 8000343C AE020050 */ sw $v0, 0x50($s0) -/* 004040 80003440 8E180054 */ lw $t8, 0x54($s0) -/* 004044 80003444 00000000 */ nop -/* 004048 80003448 0302C821 */ addu $t9, $t8, $v0 -/* 00404C 8000344C AE190054 */ sw $t9, 0x54($s0) -/* 004050 80003450 8FBF002C */ lw $ra, 0x2c($sp) -/* 004054 80003454 8FB40028 */ lw $s4, 0x28($sp) -/* 004058 80003458 8FB30024 */ lw $s3, 0x24($sp) -/* 00405C 8000345C 8FB20020 */ lw $s2, 0x20($sp) -/* 004060 80003460 8FB1001C */ lw $s1, 0x1c($sp) -/* 004064 80003464 8FB00018 */ lw $s0, 0x18($sp) -/* 004068 80003468 03E00008 */ jr $ra -/* 00406C 8000346C 27BD0050 */ addiu $sp, $sp, 0x50 - diff --git a/asm/non_matchings/unknown_003260/audioNewThread.s b/asm/non_matchings/unknown_003260/audioNewThread.s deleted file mode 100644 index 6c247905..00000000 --- a/asm/non_matchings/unknown_003260/audioNewThread.s +++ /dev/null @@ -1,265 +0,0 @@ -glabel audioNewThread -/* 003260 80002660 27BDFFB8 */ addiu $sp, $sp, -0x48 -/* 003264 80002664 3C018011 */ lui $at, %hi(gAudioSched) # $at, 0x8011 -/* 003268 80002668 AFBF0034 */ sw $ra, 0x34($sp) -/* 00326C 8000266C AFB40030 */ sw $s4, 0x30($sp) -/* 003270 80002670 AFB3002C */ sw $s3, 0x2c($sp) -/* 003274 80002674 AFB20028 */ sw $s2, 0x28($sp) -/* 003278 80002678 AFB10024 */ sw $s1, 0x24($sp) -/* 00327C 8000267C AFB00020 */ sw $s0, 0x20($sp) -/* 003280 80002680 AFA5004C */ sw $a1, 0x4c($sp) -/* 003284 80002684 AC265F90 */ sw $a2, %lo(gAudioSched)($at) -/* 003288 80002688 8C8E0014 */ lw $t6, 0x14($a0) -/* 00328C 8000268C 3C018011 */ lui $at, %hi(D_80115F94) # $at, 0x8011 -/* 003290 80002690 3C0F8000 */ lui $t7, %hi(__amDmaNew) # $t7, 0x8000 -/* 003294 80002694 25EF3008 */ addiu $t7, %lo(__amDmaNew) # addiu $t7, $t7, 0x3008 -/* 003298 80002698 AC2E5F94 */ sw $t6, %lo(D_80115F94)($at) -/* 00329C 8000269C 00809825 */ move $s3, $a0 -/* 0032A0 800026A0 AC8F0010 */ sw $t7, 0x10($a0) -/* 0032A4 800026A4 0C032180 */ jal osAiSetFrequency -/* 0032A8 800026A8 24045622 */ li $a0, 22050 -/* 0032AC 800026AC 44822000 */ mtc1 $v0, $f4 -/* 0032B0 800026B0 AE620018 */ sw $v0, 0x18($s3) -/* 0032B4 800026B4 3C188012 */ lui $t8, %hi(gVideoRefreshRate) # $t8, 0x8012 -/* 0032B8 800026B8 468021A0 */ cvt.s.w $f6, $f4 -/* 0032BC 800026BC 8F186170 */ lw $t8, %lo(gVideoRefreshRate)($t8) -/* 0032C0 800026C0 3C014000 */ li $at, 0x40000000 # 2.000000 -/* 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(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(maxFrameSize) # addiu $s4, $s4, -0x69d0 -/* 0032E4 800026E4 46125003 */ div.s $f0, $f10, $f18 -/* 0032E8 800026E8 4459F800 */ cfc1 $t9, $31 -/* 0032EC 800026EC 00000000 */ nop -/* 0032F0 800026F0 37210003 */ ori $at, $t9, 3 -/* 0032F4 800026F4 38210002 */ xori $at, $at, 2 -/* 0032F8 800026F8 44C1F800 */ ctc1 $at, $31 -/* 0032FC 800026FC 00000000 */ nop -/* 003300 80002700 46000124 */ cvt.w.s $f4, $f0 -/* 003304 80002704 44032000 */ mfc1 $v1, $f4 -/* 003308 80002708 44D9F800 */ ctc1 $t9, $31 -/* 00330C 8000270C 44833000 */ mtc1 $v1, $f6 -/* 003310 80002710 AC830000 */ sw $v1, ($a0) -/* 003314 80002714 04610005 */ bgez $v1, .L8000272C -/* 003318 80002718 46803220 */ cvt.s.w $f8, $f6 -/* 00331C 8000271C 3C014F80 */ li $at, 0x4F800000 # 4294967296.000000 -/* 003320 80002720 44818000 */ mtc1 $at, $f16 -/* 003324 80002724 00000000 */ nop -/* 003328 80002728 46104200 */ add.s $f8, $f8, $f16 -.L8000272C: -/* 00332C 8000272C 4600403C */ c.lt.s $f8, $f0 -/* 003330 80002730 00000000 */ nop -/* 003334 80002734 45000003 */ bc1f .L80002744 -/* 003338 80002738 246A0001 */ addiu $t2, $v1, 1 -/* 00333C 8000273C AC8A0000 */ sw $t2, ($a0) -/* 003340 80002740 01401825 */ move $v1, $t2 -.L80002744: -/* 003344 80002744 306B000F */ andi $t3, $v1, 0xf -/* 003348 80002748 11600004 */ beqz $t3, .L8000275C -/* 00334C 8000274C 2401FFF0 */ li $at, -16 -/* 003350 80002750 00616024 */ and $t4, $v1, $at -/* 003354 80002754 25830010 */ addiu $v1, $t4, 0x10 -/* 003358 80002758 AC830000 */ sw $v1, ($a0) -.L8000275C: -/* 00335C 8000275C 246EFFF0 */ addiu $t6, $v1, -0x10 -/* 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) -/* 003374 80002774 24010006 */ li $at, 6 -/* 003378 80002778 1701001B */ bne $t8, $at, .L800027E8 -/* 00337C 8000277C 00000000 */ nop -/* 003380 80002780 0C01DB16 */ jal load_asset_section_from_rom -/* 003384 80002784 24040026 */ li $a0, 38 -/* 003388 80002788 8C590024 */ lw $t9, 0x24($v0) -/* 00338C 8000278C 8C490020 */ lw $t1, 0x20($v0) -/* 003390 80002790 3C0500FF */ lui $a1, (0x00FFFFFF >> 16) # lui $a1, 0xff -/* 003394 80002794 03298023 */ subu $s0, $t9, $t1 -/* 003398 80002798 00409025 */ move $s2, $v0 -/* 00339C 8000279C 02002025 */ move $a0, $s0 -/* 0033A0 800027A0 0C01C327 */ jal allocate_from_main_pool_safe -/* 0033A4 800027A4 34A5FFFF */ ori $a1, (0x00FFFFFF & 0xFFFF) # ori $a1, $a1, 0xffff -/* 0033A8 800027A8 8E460020 */ lw $a2, 0x20($s2) -/* 0033AC 800027AC 00408825 */ move $s1, $v0 -/* 0033B0 800027B0 24040027 */ li $a0, 39 -/* 0033B4 800027B4 00402825 */ move $a1, $v0 -/* 0033B8 800027B8 0C01DB9A */ jal load_asset_to_address -/* 0033BC 800027BC 02003825 */ move $a3, $s0 -/* 0033C0 800027C0 3C048011 */ lui $a0, %hi(ALGlobals_801161D0) # $a0, 0x8011 -/* 0033C4 800027C4 AE710020 */ sw $s1, 0x20($s3) -/* 0033C8 800027C8 AE600024 */ sw $zero, 0x24($s3) -/* 0033CC 800027CC 248461D0 */ addiu $a0, %lo(ALGlobals_801161D0) # addiu $a0, $a0, 0x61d0 -/* 0033D0 800027D0 0C0321FB */ jal alInit -/* 0033D4 800027D4 02602825 */ move $a1, $s3 -/* 0033D8 800027D8 0C01C450 */ jal free_from_memory_pool -/* 0033DC 800027DC 02202025 */ move $a0, $s1 -/* 0033E0 800027E0 10000005 */ b .L800027F8 -/* 0033E4 800027E4 00000000 */ nop -.L800027E8: -/* 0033E8 800027E8 3C048011 */ lui $a0, %hi(ALGlobals_801161D0) # $a0, 0x8011 -/* 0033EC 800027EC 248461D0 */ addiu $a0, %lo(ALGlobals_801161D0) # addiu $a0, $a0, 0x61d0 -/* 0033F0 800027F0 0C0321FB */ jal alInit -/* 0033F4 800027F4 02602825 */ move $a1, $s3 -.L800027F8: -/* 0033F8 800027F8 3C028012 */ lui $v0, %hi(dmaBuffs) # $v0, 0x8012 -/* 0033FC 800027FC 24429240 */ addiu $v0, %lo(dmaBuffs) # addiu $v0, $v0, -0x6dc0 -/* 003400 80002800 3C128012 */ lui $s2, %hi(dmaBuffs) # $s2, 0x8012 -/* 003404 80002804 3C108012 */ lui $s0, %hi(dmaBuffs+20) # $s0, 0x8012 -/* 003408 80002808 AC400004 */ sw $zero, 4($v0) -/* 00340C 8000280C AC400000 */ sw $zero, ($v0) -/* 003410 80002810 26109254 */ addiu $s0, %lo(dmaBuffs+20) # addiu $s0, $s0, -0x6dac -/* 003414 80002814 26529240 */ addiu $s2, %lo(dmaBuffs) # addiu $s2, $s2, -0x6dc0 -/* 003418 80002818 00008825 */ move $s1, $zero -.L8000281C: -/* 00341C 8000281C 02002025 */ move $a0, $s0 -/* 003420 80002820 0C0321E4 */ jal alLink -/* 003424 80002824 02402825 */ move $a1, $s2 -/* 003428 80002828 8E660014 */ lw $a2, 0x14($s3) -/* 00342C 8000282C 240A0400 */ li $t2, 1024 -/* 003430 80002830 AFAA0010 */ sw $t2, 0x10($sp) -/* 003434 80002834 00002025 */ move $a0, $zero -/* 003438 80002838 00002825 */ move $a1, $zero -/* 00343C 8000283C 0C031DFC */ jal alHeapDBAlloc -/* 003440 80002840 24070001 */ li $a3, 1 -/* 003444 80002844 26310001 */ addiu $s1, $s1, 1 -/* 003448 80002848 2A210031 */ slti $at, $s1, 0x31 -/* 00344C 8000284C 26520014 */ addiu $s2, $s2, 0x14 -/* 003450 80002850 26100014 */ addiu $s0, $s0, 0x14 -/* 003454 80002854 1420FFF1 */ bnez $at, .L8000281C -/* 003458 80002858 AE42FFFC */ sw $v0, -4($s2) -/* 00345C 8000285C 8E660014 */ lw $a2, 0x14($s3) -/* 003460 80002860 240B0400 */ li $t3, 1024 -/* 003464 80002864 AFAB0010 */ sw $t3, 0x10($sp) -/* 003468 80002868 00002025 */ move $a0, $zero -/* 00346C 8000286C 00002825 */ move $a1, $zero -/* 003470 80002870 0C031DFC */ jal alHeapDBAlloc -/* 003474 80002874 24070001 */ li $a3, 1 -/* 003478 80002878 3C048012 */ lui $a0, %hi(D_80119638) # $a0, 0x8012 -/* 00347C 8000287C 24849638 */ addiu $a0, %lo(D_80119638) # addiu $a0, $a0, -0x69c8 -/* 003480 80002880 240C0400 */ li $t4, 1024 -/* 003484 80002884 3C08800E */ lui $t0, %hi(D_800DC68C) # $t0, 0x800e -/* 003488 80002888 A48C0000 */ sh $t4, ($a0) -/* 00348C 8000288C 84860000 */ lh $a2, ($a0) -/* 003490 80002890 2508C68C */ addiu $t0, %lo(D_800DC68C) # addiu $t0, $t0, -0x3974 -/* 003494 80002894 3C0D8002 */ lui $t5, %hi(func_80019808) # $t5, 0x8002 -/* 003498 80002898 AE420010 */ sw $v0, 0x10($s2) -/* 00349C 8000289C 25AD9808 */ addiu $t5, %lo(func_80019808) # addiu $t5, $t5, -0x67f8 -/* 0034A0 800028A0 A1000000 */ sb $zero, ($t0) -/* 0034A4 800028A4 3C05800E */ lui $a1, %hi(gFunc80019808Length) # $a1, 0x800e -/* 0034A8 800028A8 8CA5C694 */ lw $a1, %lo(gFunc80019808Length)($a1) -/* 0034AC 800028AC 01A61823 */ subu $v1, $t5, $a2 -/* 0034B0 800028B0 00C33821 */ addu $a3, $a2, $v1 -/* 0034B4 800028B4 00008825 */ move $s1, $zero -/* 0034B8 800028B8 18A0000B */ blez $a1, .L800028E8 -/* 0034BC 800028BC 00001825 */ move $v1, $zero -/* 0034C0 800028C0 00E01025 */ move $v0, $a3 -.L800028C4: -/* 0034C4 800028C4 848F0000 */ lh $t7, ($a0) -/* 0034C8 800028C8 904E0000 */ lbu $t6, ($v0) -/* 0034CC 800028CC 26310001 */ addiu $s1, $s1, 1 -/* 0034D0 800028D0 0225082A */ slt $at, $s1, $a1 -/* 0034D4 800028D4 25F80001 */ addiu $t8, $t7, 1 -/* 0034D8 800028D8 24420001 */ addiu $v0, $v0, 1 -/* 0034DC 800028DC A4980000 */ sh $t8, ($a0) -/* 0034E0 800028E0 1420FFF8 */ bnez $at, .L800028C4 -/* 0034E4 800028E4 006E1821 */ addu $v1, $v1, $t6 -.L800028E8: -/* 0034E8 800028E8 3C19800E */ lui $t9, %hi(gFunc80019808Checksum) # $t9, 0x800e -/* 0034EC 800028EC 8F39C690 */ lw $t9, %lo(gFunc80019808Checksum)($t9) -/* 0034F0 800028F0 3C108011 */ lui $s0, %hi(D_80115F98) # $s0, 0x8011 -/* 0034F4 800028F4 10790003 */ beq $v1, $t9, .L80002904 -/* 0034F8 800028F8 26105F98 */ addiu $s0, %lo(D_80115F98) # addiu $s0, $s0, 0x5f98 -/* 0034FC 800028FC 24090001 */ li $t1, 1 -/* 003500 80002900 A1090000 */ sb $t1, ($t0) -.L80002904: -/* 003504 80002904 3C118011 */ lui $s1, %hi(D_80115FA0) # $s1, 0x8011 -/* 003508 80002908 26315FA0 */ addiu $s1, %lo(D_80115FA0) # addiu $s1, $s1, 0x5fa0 -.L8000290C: -/* 00350C 8000290C 8E660014 */ lw $a2, 0x14($s3) -/* 003510 80002910 340AA000 */ li $t2, 40960 -/* 003514 80002914 AFAA0010 */ sw $t2, 0x10($sp) -/* 003518 80002918 00002025 */ move $a0, $zero -/* 00351C 8000291C 00002825 */ move $a1, $zero -/* 003520 80002920 0C031DFC */ jal alHeapDBAlloc -/* 003524 80002924 24070001 */ li $a3, 1 -/* 003528 80002928 26100004 */ addiu $s0, $s0, 4 -/* 00352C 8000292C 0211082B */ sltu $at, $s0, $s1 -/* 003530 80002930 1420FFF6 */ bnez $at, .L8000290C -/* 003534 80002934 AE02FFFC */ sw $v0, -4($s0) -/* 003538 80002938 8E820000 */ lw $v0, ($s4) -/* 00353C 8000293C 3C0C803F */ lui $t4, (0x803FFE00 >> 16) # lui $t4, 0x803f -/* 003540 80002940 00025880 */ sll $t3, $v0, 2 -/* 003544 80002944 01625823 */ subu $t3, $t3, $v0 -/* 003548 80002948 000B2080 */ sll $a0, $t3, 2 -/* 00354C 8000294C 358CFE00 */ ori $t4, (0x803FFE00 & 0xFFFF) # ori $t4, $t4, 0xfe00 -/* 003550 80002950 3C0600FF */ lui $a2, (0x00FFFFFF >> 16) # lui $a2, 0xff -/* 003554 80002954 34C6FFFF */ ori $a2, (0x00FFFFFF & 0xFFFF) # ori $a2, $a2, 0xffff -/* 003558 80002958 01842823 */ subu $a1, $t4, $a0 -/* 00355C 8000295C 0C01C3BE */ jal allocate_at_address_in_main_pool -/* 003560 80002960 00801025 */ move $v0, $a0 -/* 003564 80002964 3C108011 */ lui $s0, %hi(D_80115F98) # $s0, 0x8011 -/* 003568 80002968 3C118011 */ lui $s1, %hi(D_80115FA0+4) # $s1, 0x8011 -/* 00356C 8000296C 00401825 */ move $v1, $v0 -/* 003570 80002970 26315FA4 */ addiu $s1, %lo(D_80115FA0+4) # addiu $s1, $s1, 0x5fa4 -/* 003574 80002974 26105F98 */ addiu $s0, %lo(D_80115F98) # addiu $s0, $s0, 0x5f98 -.L80002978: -/* 003578 80002978 8E660014 */ lw $a2, 0x14($s3) -/* 00357C 8000297C 240D0078 */ li $t5, 120 -/* 003580 80002980 AFAD0010 */ sw $t5, 0x10($sp) -/* 003584 80002984 AFA3003C */ sw $v1, 0x3c($sp) -/* 003588 80002988 00002025 */ move $a0, $zero -/* 00358C 8000298C 00002825 */ move $a1, $zero -/* 003590 80002990 0C031DFC */ jal alHeapDBAlloc -/* 003594 80002994 24070001 */ li $a3, 1 -/* 003598 80002998 8FA3003C */ lw $v1, 0x3c($sp) -/* 00359C 8000299C AE020008 */ sw $v0, 8($s0) -/* 0035A0 800029A0 AC430000 */ sw $v1, ($v0) -/* 0035A4 800029A4 8E8E0000 */ lw $t6, ($s4) -/* 0035A8 800029A8 26100004 */ addiu $s0, $s0, 4 -/* 0035AC 800029AC 000E7880 */ sll $t7, $t6, 2 -/* 0035B0 800029B0 1611FFF1 */ bne $s0, $s1, .L80002978 -/* 0035B4 800029B4 006F1821 */ addu $v1, $v1, $t7 -/* 0035B8 800029B8 3C048011 */ lui $a0, %hi(D_80116198) # $a0, 0x8011 -/* 0035BC 800029BC 3C058011 */ lui $a1, %hi(D_801161B0) # $a1, 0x8011 -/* 0035C0 800029C0 24A561B0 */ addiu $a1, %lo(D_801161B0) # addiu $a1, $a1, 0x61b0 -/* 0035C4 800029C4 24846198 */ addiu $a0, %lo(D_80116198) # addiu $a0, $a0, 0x6198 -/* 0035C8 800029C8 0C032208 */ jal osCreateMesgQueue -/* 0035CC 800029CC 24060008 */ li $a2, 8 -/* 0035D0 800029D0 3C048011 */ lui $a0, %hi(gAudioMesgQueue) # $a0, 0x8011 -/* 0035D4 800029D4 3C058011 */ lui $a1, %hi(D_80116178) # $a1, 0x8011 -/* 0035D8 800029D8 24A56178 */ addiu $a1, %lo(D_80116178) # addiu $a1, $a1, 0x6178 -/* 0035DC 800029DC 24846160 */ addiu $a0, %lo(gAudioMesgQueue) # addiu $a0, $a0, 0x6160 -/* 0035E0 800029E0 0C032208 */ jal osCreateMesgQueue -/* 0035E4 800029E4 24060008 */ li $a2, 8 -/* 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) -/* 003604 80002A04 3C188012 */ lui $t8, %hi(dmaState) # $t8, 0x8012 -/* 003608 80002A08 27189230 */ addiu $t8, %lo(dmaState) # addiu $t8, $t8, -0x6dd0 -/* 00360C 80002A0C 3C048011 */ lui $a0, %hi(audioThread) # $a0, 0x8011 -/* 003610 80002A10 3C068000 */ lui $a2, %hi(thread4_audio) # $a2, 0x8000 -/* 003614 80002A14 24C62A98 */ addiu $a2, %lo(thread4_audio) # addiu $a2, $a2, 0x2a98 -/* 003618 80002A18 24845FB0 */ addiu $a0, %lo(audioThread) # addiu $a0, $a0, 0x5fb0 -/* 00361C 80002A1C AFB80010 */ sw $t8, 0x10($sp) -/* 003620 80002A20 24050004 */ li $a1, 4 -/* 003624 80002A24 00003825 */ move $a3, $zero -/* 003628 80002A28 0C032214 */ jal osCreateThread -/* 00362C 80002A2C AFB90014 */ sw $t9, 0x14($sp) -/* 003630 80002A30 8FBF0034 */ lw $ra, 0x34($sp) -/* 003634 80002A34 8FB00020 */ lw $s0, 0x20($sp) -/* 003638 80002A38 8FB10024 */ lw $s1, 0x24($sp) -/* 00363C 80002A3C 8FB20028 */ lw $s2, 0x28($sp) -/* 003640 80002A40 8FB3002C */ lw $s3, 0x2c($sp) -/* 003644 80002A44 8FB40030 */ lw $s4, 0x30($sp) -/* 003648 80002A48 03E00008 */ jr $ra -/* 00364C 80002A4C 27BD0048 */ addiu $sp, $sp, 0x48 - diff --git a/asm/non_matchings/unknown_003260/func_80002C00.s b/asm/non_matchings/unknown_003260/func_80002C00.s deleted file mode 100644 index 2d08e45f..00000000 --- a/asm/non_matchings/unknown_003260/func_80002C00.s +++ /dev/null @@ -1,130 +0,0 @@ -glabel func_80002C00 -/* 003800 80002C00 27BDFFD8 */ addiu $sp, $sp, -0x28 -/* 003804 80002C04 AFBF001C */ sw $ra, 0x1c($sp) -/* 003808 80002C08 AFB00018 */ sw $s0, 0x18($sp) -/* 00380C 80002C0C 00808025 */ move $s0, $a0 -/* 003810 80002C10 0C000C10 */ jal func_80003040 -/* 003814 80002C14 AFA5002C */ sw $a1, 0x2c($sp) -/* 003818 80002C18 8E040000 */ lw $a0, ($s0) -/* 00381C 80002C1C 0C03233C */ jal osVirtualToPhysical -/* 003820 80002C20 00000000 */ nop -/* 003824 80002C24 8FA3002C */ lw $v1, 0x2c($sp) -/* 003828 80002C28 AFA20024 */ sw $v0, 0x24($sp) -/* 00382C 80002C2C 10600013 */ beqz $v1, .L80002C7C -/* 003830 80002C30 00000000 */ nop -/* 003834 80002C34 8C640000 */ lw $a0, ($v1) -/* 003838 80002C38 3C01800E */ lui $at, %hi(D_800DC698) # $at, 0x800e -/* 00383C 80002C3C AC24C698 */ sw $a0, %lo(D_800DC698)($at) -/* 003840 80002C40 84650004 */ lh $a1, 4($v1) -/* 003844 80002C44 3C01800E */ lui $at, %hi(D_800DC69C) # $at, 0x800e -/* 003848 80002C48 00057080 */ sll $t6, $a1, 2 -/* 00384C 80002C4C 01C02825 */ move $a1, $t6 -/* 003850 80002C50 0C03235C */ jal osAiSetNextBuffer -/* 003854 80002C54 AC2EC69C */ sw $t6, %lo(D_800DC69C)($at) -/* 003858 80002C58 3C0F800E */ lui $t7, %hi(D_800DC68C) # $t7, 0x800e -/* 00385C 80002C5C 81EFC68C */ lb $t7, %lo(D_800DC68C)($t7) -/* 003860 80002C60 00002025 */ move $a0, $zero -/* 003864 80002C64 11E00005 */ beqz $t7, .L80002C7C -/* 003868 80002C68 00000000 */ nop -/* 00386C 80002C6C 0C01BE53 */ jal get_random_number_from_range -/* 003870 80002C70 24052710 */ li $a1, 10000 -/* 003874 80002C74 0C032180 */ jal osAiSetFrequency -/* 003878 80002C78 24445622 */ addiu $a0, $v0, 0x5622 -.L80002C7C: -/* 00387C 80002C7C 0C032388 */ jal osAiGetLength -/* 003880 80002C80 00000000 */ nop -/* 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(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 -/* 0038B4 80002CB4 10200004 */ beqz $at, .L80002CC8 -/* 0038B8 80002CB8 3C048011 */ lui $a0, %hi(D_80115F98) # $a0, 0x8011 -/* 0038BC 80002CBC A6030004 */ sh $v1, 4($s0) -/* 0038C0 80002CC0 86070004 */ lh $a3, 4($s0) -/* 0038C4 80002CC4 00000000 */ nop -.L80002CC8: -/* 0038C8 80002CC8 8D6BC688 */ lw $t3, %lo(D_800DC688)($t3) -/* 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(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 -/* 0038F4 80002CF4 25AD6198 */ addiu $t5, %lo(D_80116198) # addiu $t5, $t5, 0x6198 -/* 0038F8 80002CF8 240EFFFF */ li $t6, -1 -/* 0038FC 80002CFC 240F00FF */ li $t7, 255 -/* 003900 80002D00 24C6C688 */ addiu $a2, %lo(D_800DC688) # addiu $a2, $a2, -0x3978 -/* 003904 80002D04 AE000008 */ sw $zero, 8($s0) -/* 003908 80002D08 AE0D0058 */ sw $t5, 0x58($s0) -/* 00390C 80002D0C AE10005C */ sw $s0, 0x5c($s0) -/* 003910 80002D10 AE030010 */ sw $v1, 0x10($s0) -/* 003914 80002D14 AE0E0060 */ sw $t6, 0x60($s0) -/* 003918 80002D18 AE0F0068 */ sw $t7, 0x68($s0) -/* 00391C 80002D1C AE000064 */ sw $zero, 0x64($s0) -/* 003920 80002D20 AE00006C */ sw $zero, 0x6c($s0) -/* 003924 80002D24 8CD80000 */ lw $t8, ($a2) -/* 003928 80002D28 3C078011 */ lui $a3, %hi(D_80115F98) # $a3, 0x8011 -/* 00392C 80002D2C 24E75F98 */ addiu $a3, %lo(D_80115F98) # addiu $a3, $a3, 0x5f98 -/* 003930 80002D30 0018C880 */ sll $t9, $t8, 2 -/* 003934 80002D34 00F94021 */ addu $t0, $a3, $t9 -/* 003938 80002D38 8D090000 */ lw $t1, ($t0) -/* 00393C 80002D3C 3C05800E */ lui $a1, %hi(rspF3DDKRBootStart) # $a1, 0x800e -/* 003940 80002D40 AE090048 */ sw $t1, 0x48($s0) -/* 003944 80002D44 8CCA0000 */ lw $t2, ($a2) -/* 003948 80002D48 3C19800E */ lui $t9, %hi(rspF3DDKRDramStart) # $t9, 0x800e -/* 00394C 80002D4C 000A5880 */ sll $t3, $t2, 2 -/* 003950 80002D50 00EB6021 */ addu $t4, $a3, $t3 -/* 003954 80002D54 8D8D0000 */ lw $t5, ($t4) -/* 003958 80002D58 24A584C0 */ addiu $a1, %lo(rspF3DDKRBootStart) # addiu $a1, $a1, -0x7b40 -/* 00395C 80002D5C 004D7023 */ subu $t6, $v0, $t5 -/* 003960 80002D60 000E78C3 */ sra $t7, $t6, 3 -/* 003964 80002D64 27398590 */ addiu $t9, %lo(rspF3DDKRDramStart) # addiu $t9, $t9, -0x7a70 -/* 003968 80002D68 3C09800D */ lui $t1, %hi(rspUnknownStart) # $t1, 0x800d -/* 00396C 80002D6C 3C0A800F */ lui $t2, %hi(rspUnknownDataStart) # $t2, 0x800f -/* 003970 80002D70 000FC0C0 */ sll $t8, $t7, 3 -/* 003974 80002D74 03254023 */ subu $t0, $t9, $a1 -/* 003978 80002D78 25297600 */ addiu $t1, %lo(rspUnknownStart) # addiu $t1, $t1, 0x7600 -/* 00397C 80002D7C 254A98D0 */ addiu $t2, %lo(rspUnknownDataStart) # addiu $t2, $t2, -0x6730 -/* 003980 80002D80 240B0800 */ li $t3, 2048 -/* 003984 80002D84 240C0001 */ li $t4, 1 -/* 003988 80002D88 AE18004C */ sw $t8, 0x4c($s0) -/* 00398C 80002D8C AE030018 */ sw $v1, 0x18($s0) -/* 003990 80002D90 AE050020 */ sw $a1, 0x20($s0) -/* 003994 80002D94 AE080024 */ sw $t0, 0x24($s0) -/* 003998 80002D98 AE03001C */ sw $v1, 0x1c($s0) -/* 00399C 80002D9C AE090028 */ sw $t1, 0x28($s0) -/* 0039A0 80002DA0 AE0A0030 */ sw $t2, 0x30($s0) -/* 0039A4 80002DA4 AE0B0034 */ sw $t3, 0x34($s0) -/* 0039A8 80002DA8 AE000050 */ sw $zero, 0x50($s0) -/* 0039AC 80002DAC AE000054 */ sw $zero, 0x54($s0) -/* 0039B0 80002DB0 AE0C0074 */ sw $t4, 0x74($s0) -/* 0039B4 80002DB4 3C048011 */ lui $a0, %hi(gAudioSched) # $a0, 0x8011 -/* 0039B8 80002DB8 8C845F90 */ lw $a0, %lo(gAudioSched)($a0) -/* 0039BC 80002DBC 0C01E55D */ jal osScGetCmdQ -/* 0039C0 80002DC0 00000000 */ nop -/* 0039C4 80002DC4 00402025 */ move $a0, $v0 -/* 0039C8 80002DC8 26050008 */ addiu $a1, $s0, 8 -/* 0039CC 80002DCC 0C03238C */ jal osSendMesg -/* 0039D0 80002DD0 00003025 */ move $a2, $zero -/* 0039D4 80002DD4 3C03800E */ lui $v1, %hi(D_800DC688) # $v1, 0x800e -/* 0039D8 80002DD8 2463C688 */ addiu $v1, %lo(D_800DC688) # addiu $v1, $v1, -0x3978 -/* 0039DC 80002DDC 8C6D0000 */ lw $t5, ($v1) -/* 0039E0 80002DE0 8FBF001C */ lw $ra, 0x1c($sp) -/* 0039E4 80002DE4 8FB00018 */ lw $s0, 0x18($sp) -/* 0039E8 80002DE8 39AE0001 */ xori $t6, $t5, 1 -/* 0039EC 80002DEC AC6E0000 */ sw $t6, ($v1) -/* 0039F0 80002DF0 03E00008 */ jr $ra -/* 0039F4 80002DF4 27BD0028 */ addiu $sp, $sp, 0x28 - diff --git a/asm/non_matchings/unknown_003260/func_80003040.s b/asm/non_matchings/unknown_003260/func_80003040.s deleted file mode 100644 index 53c1c76b..00000000 --- a/asm/non_matchings/unknown_003260/func_80003040.s +++ /dev/null @@ -1,81 +0,0 @@ -glabel func_80003040 -/* 003C40 80003040 27BDFFB8 */ addiu $sp, $sp, -0x48 -/* 003C44 80003044 AFB40028 */ sw $s4, 0x28($sp) -/* 003C48 80003048 3C14800E */ lui $s4, %hi(D_800DC684) # $s4, 0x800e -/* 003C4C 8000304C 2694C684 */ addiu $s4, %lo(D_800DC684) # addiu $s4, $s4, -0x397c -/* 003C50 80003050 8E8E0000 */ lw $t6, ($s4) -/* 003C54 80003054 AFB00018 */ sw $s0, 0x18($sp) -/* 003C58 80003058 AFBF002C */ sw $ra, 0x2c($sp) -/* 003C5C 8000305C AFB30024 */ sw $s3, 0x24($sp) -/* 003C60 80003060 AFB20020 */ sw $s2, 0x20($sp) -/* 003C64 80003064 AFB1001C */ sw $s1, 0x1c($sp) -/* 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(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: -/* 003C84 80003084 02402825 */ move $a1, $s2 -/* 003C88 80003088 0C0322EC */ jal osRecvMesg -/* 003C8C 8000308C 00003025 */ move $a2, $zero -/* 003C90 80003090 8E8F0000 */ lw $t7, ($s4) -/* 003C94 80003094 26100001 */ addiu $s0, $s0, 1 -/* 003C98 80003098 020F082B */ sltu $at, $s0, $t7 -/* 003C9C 8000309C 1420FFF9 */ bnez $at, .L80003084 -/* 003CA0 800030A0 02202025 */ move $a0, $s1 -.L800030A4: -/* 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(audFrameCt) # $s3, 0x800e -/* 003CB4 800030B4 1200001C */ beqz $s0, .L80003128 -/* 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) -/* 003CC4 800030C4 8E020000 */ lw $v0, ($s0) -/* 003CC8 800030C8 27280001 */ addiu $t0, $t9, 1 -/* 003CCC 800030CC 0118082B */ sltu $at, $t0, $t8 -/* 003CD0 800030D0 10200013 */ beqz $at, .L80003120 -/* 003CD4 800030D4 00408825 */ move $s1, $v0 -/* 003CD8 800030D8 8E490004 */ lw $t1, 4($s2) -/* 003CDC 800030DC 00000000 */ nop -/* 003CE0 800030E0 16090002 */ bne $s0, $t1, .L800030EC -/* 003CE4 800030E4 00000000 */ nop -/* 003CE8 800030E8 AE420004 */ sw $v0, 4($s2) -.L800030EC: -/* 003CEC 800030EC 0C0321D8 */ jal alUnlink -/* 003CF0 800030F0 02002025 */ move $a0, $s0 -/* 003CF4 800030F4 8E450008 */ lw $a1, 8($s2) -/* 003CF8 800030F8 00000000 */ nop -/* 003CFC 800030FC 10A00005 */ beqz $a1, .L80003114 -/* 003D00 80003100 00000000 */ nop -/* 003D04 80003104 0C0321E4 */ jal alLink -/* 003D08 80003108 02002025 */ move $a0, $s0 -/* 003D0C 8000310C 10000004 */ b .L80003120 -/* 003D10 80003110 00000000 */ nop -.L80003114: -/* 003D14 80003114 AE500008 */ sw $s0, 8($s2) -/* 003D18 80003118 AE000000 */ sw $zero, ($s0) -/* 003D1C 8000311C AE000004 */ sw $zero, 4($s0) -.L80003120: -/* 003D20 80003120 1620FFE6 */ bnez $s1, .L800030BC -/* 003D24 80003124 02208025 */ move $s0, $s1 -.L80003128: -/* 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 -/* 003D3C 8000313C AE800000 */ sw $zero, ($s4) -/* 003D40 80003140 AE6B0000 */ sw $t3, ($s3) -/* 003D44 80003144 8FB30024 */ lw $s3, 0x24($sp) -/* 003D48 80003148 8FB40028 */ lw $s4, 0x28($sp) -/* 003D4C 8000314C 8FB00018 */ lw $s0, 0x18($sp) -/* 003D50 80003150 8FB1001C */ lw $s1, 0x1c($sp) -/* 003D54 80003154 8FB20020 */ lw $s2, 0x20($sp) -/* 003D58 80003158 03E00008 */ jr $ra -/* 003D5C 8000315C 27BD0048 */ addiu $sp, $sp, 0x48 - diff --git a/asm/non_matchings/unknown_003260/func_8000410C.s b/asm/non_matchings/unknown_003260/func_8000410C.s deleted file mode 100644 index 159db186..00000000 --- a/asm/non_matchings/unknown_003260/func_8000410C.s +++ /dev/null @@ -1,35 +0,0 @@ -glabel func_8000410C -/* 004D0C 8000410C 27BDFFE0 */ addiu $sp, $sp, -0x20 -/* 004D10 80004110 AFBF0014 */ sw $ra, 0x14($sp) -/* 004D14 80004114 AFA40020 */ sw $a0, 0x20($sp) -/* 004D18 80004118 908F003E */ lbu $t7, 0x3e($a0) -/* 004D1C 8000411C 00807025 */ move $t6, $a0 -/* 004D20 80004120 31F80004 */ andi $t8, $t7, 4 -/* 004D24 80004124 1300000C */ beqz $t8, .L80004158 -/* 004D28 80004128 3C19800E */ lui $t9, %hi(gAlSndPlayer) # $t9, 0x800e -/* 004D2C 8000412C 8F39C6BC */ lw $t9, %lo(gAlSndPlayer)($t9) -/* 004D30 80004130 25C5000C */ addiu $a1, $t6, 0xc -/* 004D34 80004134 8F240038 */ lw $a0, 0x38($t9) -/* 004D38 80004138 0C03262C */ jal alSynStopVoice -/* 004D3C 8000413C AFA5001C */ sw $a1, 0x1c($sp) -/* 004D40 80004140 3C08800E */ lui $t0, %hi(gAlSndPlayer) # $t0, 0x800e -/* 004D44 80004144 8D08C6BC */ lw $t0, %lo(gAlSndPlayer)($t0) -/* 004D48 80004148 8FA5001C */ lw $a1, 0x1c($sp) -/* 004D4C 8000414C 8D040038 */ lw $a0, 0x38($t0) -/* 004D50 80004150 0C03264C */ jal alSynFreeVoice -/* 004D54 80004154 00000000 */ nop -.L80004158: -/* 004D58 80004158 8FA40020 */ lw $a0, 0x20($sp) -/* 004D5C 8000415C 0C001148 */ jal func_80004520 -/* 004D60 80004160 00000000 */ nop -/* 004D64 80004164 3C04800E */ lui $a0, %hi(gAlSndPlayer) # $a0, 0x800e -/* 004D68 80004168 8C84C6BC */ lw $a0, %lo(gAlSndPlayer)($a0) -/* 004D6C 8000416C 8FA50020 */ lw $a1, 0x20($sp) -/* 004D70 80004170 3406FFFF */ li $a2, 65535 -/* 004D74 80004174 0C00107F */ jal func_800041FC -/* 004D78 80004178 24840014 */ addiu $a0, $a0, 0x14 -/* 004D7C 8000417C 8FBF0014 */ lw $ra, 0x14($sp) -/* 004D80 80004180 27BD0020 */ addiu $sp, $sp, 0x20 -/* 004D84 80004184 03E00008 */ jr $ra -/* 004D88 80004188 00000000 */ nop - diff --git a/asm/non_matchings/unknown_003260/func_800041FC.s b/asm/non_matchings/unknown_003260/func_800041FC.s deleted file mode 100644 index ecd35cbc..00000000 --- a/asm/non_matchings/unknown_003260/func_800041FC.s +++ /dev/null @@ -1,58 +0,0 @@ -glabel func_800041FC -/* 004DFC 800041FC 27BDFFB8 */ addiu $sp, $sp, -0x48 -/* 004E00 80004200 AFB20020 */ sw $s2, 0x20($sp) -/* 004E04 80004204 00809025 */ move $s2, $a0 -/* 004E08 80004208 AFBF002C */ sw $ra, 0x2c($sp) -/* 004E0C 8000420C AFB40028 */ sw $s4, 0x28($sp) -/* 004E10 80004210 AFB30024 */ sw $s3, 0x24($sp) -/* 004E14 80004214 00A09825 */ move $s3, $a1 -/* 004E18 80004218 30D4FFFF */ andi $s4, $a2, 0xffff -/* 004E1C 8000421C AFB1001C */ sw $s1, 0x1c($sp) -/* 004E20 80004220 AFB00018 */ sw $s0, 0x18($sp) -/* 004E24 80004224 AFA60050 */ sw $a2, 0x50($sp) -/* 004E28 80004228 0C03268C */ jal osSetIntMask -/* 004E2C 8000422C 24040001 */ li $a0, 1 -/* 004E30 80004230 AFA20030 */ sw $v0, 0x30($sp) -/* 004E34 80004234 8E500008 */ lw $s0, 8($s2) -/* 004E38 80004238 00000000 */ nop -/* 004E3C 8000423C 12000019 */ beqz $s0, .L800042A4 -/* 004E40 80004240 8FA40030 */ lw $a0, 0x30($sp) -.L80004244: -/* 004E44 80004244 8E0E0010 */ lw $t6, 0x10($s0) -/* 004E48 80004248 8E110000 */ lw $s1, ($s0) -/* 004E4C 8000424C 166E0012 */ bne $s3, $t6, .L80004298 -/* 004E50 80004250 00000000 */ nop -/* 004E54 80004254 960F000C */ lhu $t7, 0xc($s0) -/* 004E58 80004258 00000000 */ nop -/* 004E5C 8000425C 01F4C024 */ and $t8, $t7, $s4 -/* 004E60 80004260 1300000D */ beqz $t8, .L80004298 -/* 004E64 80004264 00000000 */ nop -/* 004E68 80004268 12200006 */ beqz $s1, .L80004284 -/* 004E6C 8000426C 00000000 */ nop -/* 004E70 80004270 8E390008 */ lw $t9, 8($s1) -/* 004E74 80004274 8E080008 */ lw $t0, 8($s0) -/* 004E78 80004278 00000000 */ nop -/* 004E7C 8000427C 03284821 */ addu $t1, $t9, $t0 -/* 004E80 80004280 AE290008 */ sw $t1, 8($s1) -.L80004284: -/* 004E84 80004284 0C0321D8 */ jal alUnlink -/* 004E88 80004288 02002025 */ move $a0, $s0 -/* 004E8C 8000428C 02002025 */ move $a0, $s0 -/* 004E90 80004290 0C0321E4 */ jal alLink -/* 004E94 80004294 02402825 */ move $a1, $s2 -.L80004298: -/* 004E98 80004298 1620FFEA */ bnez $s1, .L80004244 -/* 004E9C 8000429C 02208025 */ move $s0, $s1 -/* 004EA0 800042A0 8FA40030 */ lw $a0, 0x30($sp) -.L800042A4: -/* 004EA4 800042A4 0C03268C */ jal osSetIntMask -/* 004EA8 800042A8 00000000 */ nop -/* 004EAC 800042AC 8FBF002C */ lw $ra, 0x2c($sp) -/* 004EB0 800042B0 8FB00018 */ lw $s0, 0x18($sp) -/* 004EB4 800042B4 8FB1001C */ lw $s1, 0x1c($sp) -/* 004EB8 800042B8 8FB20020 */ lw $s2, 0x20($sp) -/* 004EBC 800042BC 8FB30024 */ lw $s3, 0x24($sp) -/* 004EC0 800042C0 8FB40028 */ lw $s4, 0x28($sp) -/* 004EC4 800042C4 03E00008 */ jr $ra -/* 004EC8 800042C8 27BD0048 */ addiu $sp, $sp, 0x48 - diff --git a/asm/non_matchings/unknown_003260/func_800042CC.s b/asm/non_matchings/unknown_003260/func_800042CC.s deleted file mode 100644 index 8aad9544..00000000 --- a/asm/non_matchings/unknown_003260/func_800042CC.s +++ /dev/null @@ -1,54 +0,0 @@ -glabel func_800042CC -/* 004ECC 800042CC 27BDFFD8 */ addiu $sp, $sp, -0x28 -/* 004ED0 800042D0 AFBF0014 */ sw $ra, 0x14($sp) -/* 004ED4 800042D4 AFA40028 */ sw $a0, 0x28($sp) -/* 004ED8 800042D8 AFA5002C */ sw $a1, 0x2c($sp) -/* 004EDC 800042DC 0C03268C */ jal osSetIntMask -/* 004EE0 800042E0 24040001 */ li $a0, 1 -/* 004EE4 800042E4 3C07800E */ lui $a3, %hi(D_800DC6B0) # $a3, 0x800e -/* 004EE8 800042E8 24E7C6B0 */ addiu $a3, %lo(D_800DC6B0) # addiu $a3, $a3, -0x3950 -/* 004EEC 800042EC 8CE30000 */ lw $v1, ($a3) -/* 004EF0 800042F0 8CE40008 */ lw $a0, 8($a3) -/* 004EF4 800042F4 8CE50004 */ lw $a1, 4($a3) -/* 004EF8 800042F8 AFA20024 */ sw $v0, 0x24($sp) -/* 004EFC 800042FC 10600006 */ beqz $v1, .L80004318 -/* 004F00 80004300 00003025 */ move $a2, $zero -.L80004304: -/* 004F04 80004304 8C630000 */ lw $v1, ($v1) -/* 004F08 80004308 24C60001 */ addiu $a2, $a2, 1 -/* 004F0C 8000430C 30CEFFFF */ andi $t6, $a2, 0xffff -/* 004F10 80004310 1460FFFC */ bnez $v1, .L80004304 -/* 004F14 80004314 01C03025 */ move $a2, $t6 -.L80004318: -/* 004F18 80004318 10800006 */ beqz $a0, .L80004334 -/* 004F1C 8000431C 00001025 */ move $v0, $zero -.L80004320: -/* 004F20 80004320 8C840000 */ lw $a0, ($a0) -/* 004F24 80004324 24420001 */ addiu $v0, $v0, 1 -/* 004F28 80004328 304FFFFF */ andi $t7, $v0, 0xffff -/* 004F2C 8000432C 1480FFFC */ bnez $a0, .L80004320 -/* 004F30 80004330 01E01025 */ move $v0, $t7 -.L80004334: -/* 004F34 80004334 10A00006 */ beqz $a1, .L80004350 -/* 004F38 80004338 00001825 */ move $v1, $zero -.L8000433C: -/* 004F3C 8000433C 8CA50004 */ lw $a1, 4($a1) -/* 004F40 80004340 24630001 */ addiu $v1, $v1, 1 -/* 004F44 80004344 3078FFFF */ andi $t8, $v1, 0xffff -/* 004F48 80004348 14A0FFFC */ bnez $a1, .L8000433C -/* 004F4C 8000434C 03001825 */ move $v1, $t8 -.L80004350: -/* 004F50 80004350 8FB90028 */ lw $t9, 0x28($sp) -/* 004F54 80004354 00000000 */ nop -/* 004F58 80004358 A7220000 */ sh $v0, ($t9) -/* 004F5C 8000435C 8FA8002C */ lw $t0, 0x2c($sp) -/* 004F60 80004360 00000000 */ nop -/* 004F64 80004364 A5060000 */ sh $a2, ($t0) -/* 004F68 80004368 8FA40024 */ lw $a0, 0x24($sp) -/* 004F6C 8000436C 0C03268C */ jal osSetIntMask -/* 004F70 80004370 A7A3001E */ sh $v1, 0x1e($sp) -/* 004F74 80004374 8FBF0014 */ lw $ra, 0x14($sp) -/* 004F78 80004378 97A2001E */ lhu $v0, 0x1e($sp) -/* 004F7C 8000437C 03E00008 */ jr $ra -/* 004F80 80004380 27BD0028 */ addiu $sp, $sp, 0x28 - diff --git a/extract-ver/us_1.0.config.json b/extract-ver/us_1.0.config.json index d88ecb92..20b1f80d 100755 --- a/extract-ver/us_1.0.config.json +++ b/extract-ver/us_1.0.config.json @@ -32,7 +32,7 @@ "type": "Binary", "folder": "../../../ucode/us_1.0", "files": [{ - "filename": "ucode_unknown", + "filename": "ucode_audio", "length": "0xEC0" }, { @@ -69,7 +69,7 @@ "type": "Binary", "folder": "../../../ucode/us_1.0", "files": [{ - "filename": "data_unknown", + "filename": "data_audio", "length": "0x2D0" }, { diff --git a/include/sched.h b/include/sched.h index 799a6aca..3e734e25 100644 --- a/include/sched.h +++ b/include/sched.h @@ -63,13 +63,12 @@ typedef struct OSScTask_s { OSTask list; OSMesgQueue *msgQ; OSMesg msg; -#ifndef _FINALROM /* all #ifdef items should */ - OSTime startTime; /* remain at the end!!, or */ - OSTime totalTime; /* possible conflict if */ -#endif /* FINALROM library used with */ - /* non FINALROM code */ - + s32 unk58; + s32 unk5C; + s32 unk60; + s32 unk64; s32 unk68; /* Added by Rare? */ + s32 unk6C; } OSScTask; typedef struct SCClient_s { diff --git a/lib/src/os/osAiGetLength.c b/lib/src/os/osAiGetLength.c index 7232001c..8f4f4728 100644 --- a/lib/src/os/osAiGetLength.c +++ b/lib/src/os/osAiGetLength.c @@ -3,6 +3,13 @@ #include "PR/rcp.h" +/** + * This function (osAiGetLength) returns the number of bytes remaining in the current DMA buffer. + * Notes: + * For hardware version 1.0, the audio DMA length register is only 15-bit long and thus supports + * a maximum transfer size of 32 Kbytes. In the final release, this register is extended to + * 18 bits to support a transfer of 256 Kbytes. + */ u32 osAiGetLength(void) { return IO_READ(AI_LEN_REG); } diff --git a/src/audio.c b/src/audio.c index 1b7142bd..c6c914b7 100644 --- a/src/audio.c +++ b/src/audio.c @@ -9,7 +9,8 @@ #include "asset_enums.h" #include "asset_loading.h" #include "audio_internal.h" -#include "unknown_003260.h" +#include "audiomgr.h" +#include "audiosfx.h" #include "sched.h" #include "lib/src/mips1/al/unknown_0646F0.h" @@ -66,8 +67,8 @@ ALBankFile *ALBankFile_80115D14; // These are sound effects, I do not know if it unk80115D18 *sSoundEffectsPool; unk80115D1C *sMusicPool; -s32 D_80115D20; -s32 D_80115D24; +s32 sSoundEffectsPoolCount; +s32 sMusicPoolCount; u32 sSoundEffectsPoolSize; u32 sMusicPoolSize; s16 sMusicTempo; @@ -102,33 +103,33 @@ void audio_init(OSSched *sc) { audioMgrConfig audConfig; seqLength = 0; - alHeapInit(&gALHeap, gBssSectionStart, AUDIO_HEAP_SIZE); + alHeapInit(&gALHeap, gBssSectionStart, sizeof(gBssSectionStart)); addrPtr = (s32 *) load_asset_section_from_rom(ASSET_AUDIO_TABLE); - ALBankFile_80115D14 = (ALBankFile *) allocate_from_main_pool_safe(addrPtr[2] - addrPtr[1], COLOUR_TAG_CYAN); - load_asset_to_address(ASSET_AUDIO, (u32) ALBankFile_80115D14, addrPtr[1], addrPtr[2] - addrPtr[1]); - alBnkfNew(ALBankFile_80115D14, get_rom_offset_of_asset(ASSET_AUDIO, addrPtr[2])); + ALBankFile_80115D14 = (ALBankFile *) allocate_from_main_pool_safe(addrPtr[ASSET_AUDIO_2] - addrPtr[ASSET_AUDIO_1], COLOUR_TAG_CYAN); + load_asset_to_address(ASSET_AUDIO, (u32) ALBankFile_80115D14, addrPtr[ASSET_AUDIO_1], addrPtr[ASSET_AUDIO_2] - addrPtr[ASSET_AUDIO_1]); + alBnkfNew(ALBankFile_80115D14, get_rom_offset_of_asset(ASSET_AUDIO, addrPtr[ASSET_AUDIO_2])); - sSoundEffectsPoolSize = addrPtr[7] - addrPtr[6]; + sSoundEffectsPoolSize = addrPtr[ASSET_AUDIO_7] - addrPtr[ASSET_AUDIO_6]; sSoundEffectsPool = (unk80115D18 *) allocate_from_main_pool_safe(sSoundEffectsPoolSize, COLOUR_TAG_CYAN); - load_asset_to_address(ASSET_AUDIO, (u32) sSoundEffectsPool, addrPtr[6], sSoundEffectsPoolSize); - D_80115D20 = sSoundEffectsPoolSize / 10; + load_asset_to_address(ASSET_AUDIO, (u32) sSoundEffectsPool, addrPtr[ASSET_AUDIO_6], sSoundEffectsPoolSize); + sSoundEffectsPoolCount = sSoundEffectsPoolSize / sizeof(unk80115D18); - sMusicPoolSize = addrPtr[6] - addrPtr[5]; + sMusicPoolSize = addrPtr[ASSET_AUDIO_6] - addrPtr[ASSET_AUDIO_5]; sMusicPool = (unk80115D1C *) allocate_from_main_pool_safe(sMusicPoolSize, COLOUR_TAG_CYAN); - load_asset_to_address(ASSET_AUDIO, (u32) sMusicPool, addrPtr[5], sMusicPoolSize); - D_80115D24 = sMusicPoolSize / 3; + load_asset_to_address(ASSET_AUDIO, (u32) sMusicPool, addrPtr[ASSET_AUDIO_5], sMusicPoolSize); + sMusicPoolCount = sMusicPoolSize / sizeof(unk80115D1C); - ALBankFile_80115D10 = (ALBankFile *) allocate_from_main_pool_safe(addrPtr[0], COLOUR_TAG_CYAN); - load_asset_to_address(ASSET_AUDIO, (u32) ALBankFile_80115D10, 0, addrPtr[0]); - alBnkfNew(ALBankFile_80115D10, get_rom_offset_of_asset(ASSET_AUDIO, addrPtr[0])); - ALSeqFile_80115CF8 = (ALSeqFile *) alHeapDBAlloc(0, 0, &gALHeap, 1, 4); - load_asset_to_address(ASSET_AUDIO, (u32) ALSeqFile_80115CF8, addrPtr[4], 4); + ALBankFile_80115D10 = (ALBankFile *) allocate_from_main_pool_safe(addrPtr[ASSET_AUDIO_0], COLOUR_TAG_CYAN); + load_asset_to_address(ASSET_AUDIO, (u32) ALBankFile_80115D10, 0, addrPtr[ASSET_AUDIO_0]); + alBnkfNew(ALBankFile_80115D10, get_rom_offset_of_asset(ASSET_AUDIO, addrPtr[ASSET_AUDIO_0])); + ALSeqFile_80115CF8 = (ALSeqFile *) alHeapAlloc(&gALHeap, 1, 4); + load_asset_to_address(ASSET_AUDIO, (u32) ALSeqFile_80115CF8, addrPtr[ASSET_AUDIO_4], 4); seqfSize = (ALSeqFile_80115CF8->seqCount) * 8 + 4; ALSeqFile_80115CF8 = allocate_from_main_pool_safe(seqfSize, COLOUR_TAG_CYAN); - load_asset_to_address(ASSET_AUDIO, (u32) ALSeqFile_80115CF8, addrPtr[4], seqfSize); - alSeqFileNew(ALSeqFile_80115CF8, get_rom_offset_of_asset(ASSET_AUDIO, addrPtr[4])); + load_asset_to_address(ASSET_AUDIO, (u32) ALSeqFile_80115CF8, addrPtr[ASSET_AUDIO_4], seqfSize); + alSeqFileNew(ALSeqFile_80115CF8, get_rom_offset_of_asset(ASSET_AUDIO, addrPtr[ASSET_AUDIO_4])); gSeqLengthTable = (u32 *) allocate_from_main_pool_safe((ALSeqFile_80115CF8->seqCount) * 4, COLOUR_TAG_CYAN); for (iCnt = 0; iCnt < ALSeqFile_80115CF8->seqCount; iCnt++) { @@ -150,7 +151,7 @@ void audio_init(OSSched *sc) { synth_config.fxType[1] = 2; synth_config.outputRate = 0; synth_config.heap = &gALHeap; - audioNewThread(&synth_config, 12, sc); + amCreateAudioMgr(&synth_config, 12, sc); gMusicPlayer = func_80002224(24, 120); set_voice_limit(gMusicPlayer, 18); gSndFxPlayer = func_80002224(16, 50); @@ -172,7 +173,6 @@ void audio_init(OSSched *sc) { D_800DC658 = 0; gSkipResetChannels = FALSE; gAudioVolumeSetting = VOLUME_NORMAL; - return; } /** @@ -223,7 +223,7 @@ void adjust_audio_volume(s32 behaviour) { set_sound_channel_volume(2, 32767); set_sound_channel_volume(4, 32767); alCSPSetVol((ALCSPlayer *) gMusicPlayer, (s16) (musicRelativeVolume * musicVolumeSliderPercentage)); - alCSPSetVol((ALCSPlayer *) gSndFxPlayer, (s16) (sfxGetVolumeSlider() * sfxRelativeVolume)); + alCSPSetVol((ALCSPlayer *) gSndFxPlayer, (s16) (get_sfx_volume_slider() * sfxRelativeVolume)); break; } gAudioVolumeSetting = behaviour; @@ -609,7 +609,7 @@ s32 musicGetVolSliderPercentage(void) { void sfxSetRelativeVolume(u8 arg0) { sfxRelativeVolume = arg0; - alCSPSetVol((ALCSPlayer *) gSndFxPlayer, (s16)(sfxGetVolumeSlider() * sfxRelativeVolume)); + alCSPSetVol((ALCSPlayer *) gSndFxPlayer, (s16)(get_sfx_volume_slider() * sfxRelativeVolume)); } void sfxSetPan(ALPan pan) { @@ -647,11 +647,11 @@ UNUSED void set_all_channel_volume(u16 volume) { } } -u16 func_80001CB8(u16 arg0) { - if (D_80115D20 < arg0) { +u16 func_80001CB8(u16 soundId) { + if (soundId > sSoundEffectsPoolCount) { return 0; } - return sSoundEffectsPool[arg0].unk6; + return sSoundEffectsPool[soundId].unk6; } /** @@ -662,7 +662,7 @@ void play_sound_global(u16 soundID, s32 *soundMask) { f32 volumeF; s32 soundBite; - if (D_80115D20 < soundID) { + if (soundID > sSoundEffectsPoolCount) { if (soundMask != NULL) { *soundMask = NULL; } @@ -759,7 +759,7 @@ void func_80002128(unk80115D18 **arg0, s32 *arg1, s32 *arg2) { *arg1 = sSoundEffectsPoolSize; } if (arg2 != NULL) { - *arg2 = D_80115D20; + *arg2 = sSoundEffectsPoolCount; } } @@ -771,7 +771,7 @@ UNUSED void func_8000216C(unk80115D1C **arg0, s32 *arg1, s32 *arg2) { *arg1 = sMusicPoolSize; } if (arg2 != NULL) { - *arg2 = D_80115D24; + *arg2 = sMusicPoolCount; } } @@ -795,7 +795,7 @@ ALSeqPlayer *func_80002224(s32 _max_voices, s32 _max_events) { config.updateOsc = NULL; config.stopOsc = NULL; - cseqp = (ALCSPlayer *)alHeapDBAlloc(NULL, 0, &gALHeap, 1, sizeof(ALCSPlayer)); + cseqp = (ALCSPlayer *)alHeapAlloc(&gALHeap, 1, sizeof(ALCSPlayer)); alCSPNew(cseqp, &config); alCSPSetBank(cseqp, ALBankFile_80115D10->bankArray[0]); cseqp->unk36 = 0x7F; @@ -814,17 +814,17 @@ void func_800022BC(u8 arg0, ALSeqPlayer *arg1) { } } -void func_8000232C(ALSeqPlayer *arg0, void *arg1, u8 *arg2, ALCSeq *arg3) { - s32 var_s0; +void func_8000232C(ALSeqPlayer *seqp, void *arg1, u8 *arg2, ALCSeq *seq) { + s32 i; u8 temp_a0; u8 temp_a0_2; - if ((alCSPGetState((ALCSPlayer* ) arg0) == 0) && (*arg2 != 0)) { + if ((alCSPGetState((ALCSPlayer* ) seqp) == 0) && (*arg2 != 0)) { load_asset_to_address(ASSET_AUDIO, (u32) arg1, ALSeqFile_80115CF8->seqArray[*arg2].offset - get_rom_offset_of_asset(ASSET_AUDIO, 0), (s32) gSeqLengthTable[*arg2]); - alCSeqNew(arg3, arg1); - alCSPSetSeq((ALCSPlayer* ) arg0, arg3); - alCSPPlay((ALCSPlayer* ) arg0); - if (arg0 == gMusicPlayer) { + alCSeqNew(seq, arg1); + alCSPSetSeq((ALCSPlayer* ) seqp, seq); + alCSPPlay((ALCSPlayer* ) seqp); + if (seqp == gMusicPlayer) { set_relative_volume_for_music(sMusicPool[*arg2].unk0); temp_a0 = sMusicPool[*arg2].unk1; if (temp_a0 != 0) { @@ -834,16 +834,14 @@ void func_8000232C(ALSeqPlayer *arg0, void *arg1, u8 *arg2, ALCSeq *arg3) { } func_80002608(sMusicPool[*arg2].unk2); D_80115D04 = *arg2; - var_s0 = 0; if (D_80115F7C != -1) { - do { - if ((1 << var_s0) & D_80115F7C) { - func_80001170(var_s0); + for (i = 0; i < 16; i++) { + if ((1 << i) & D_80115F7C) { + func_80001170(i); } else { - func_80001114(var_s0); + func_80001114(i); } - var_s0 += 1; - } while (var_s0 != 0x10); + } } } else { sfxSetRelativeVolume(sMusicPool[*arg2].unk0); diff --git a/src/audio.h b/src/audio.h index e5b12205..a743ccb1 100644 --- a/src/audio.h +++ b/src/audio.h @@ -109,7 +109,7 @@ void sfxSetPan(ALPan pan); void play_sequence(u8 seqID); u32 func_80001C08(void); void set_all_channel_volume(u16 arg0); -u16 func_80001CB8(u16 arg0); +u16 func_80001CB8(u16 soundId); void play_sound_spatial(u16 soundID, f32 x, f32 y, f32 z, s32 **arg4); void func_80001F14(u16 soundID, s32 *arg1); u16 ALBankFile_80115D14_GetSoundCount(void); diff --git a/src/audiomgr.c b/src/audiomgr.c new file mode 100644 index 00000000..458c9fb2 --- /dev/null +++ b/src/audiomgr.c @@ -0,0 +1,538 @@ +/* The comment below is needed for this file to be picked up by generate_ld */ +/* RAM_POS: 0x80002660 */ + +#include "audiomgr.h" +#include "memory.h" +#include "audio_internal.h" +#include "video.h" +#include "math_util.h" +#include "asset_loading.h" +#include "objects.h" +#include "PR/abi.h" + +/**** type define's for structures unique to audiomgr ****/ +typedef union { + + struct { + short type; + } gen; + + struct { + short type; + struct AudioInfo_s *info; + } done; + + OSScMsg app; + +} AudioMsg; + +// TODO: Rare likely modified this struct as evidenced by __amHandleFrameMsg +// using *data when it should have been using msg. +typedef struct AudioInfo_s { + short *data; /* Output data pointer */ + short frameSamples; /* # of samples synthesized in this frame */ + OSScTask task; /* scheduler structure */ + AudioMsg msg; /* completion message */ +} AudioInfo; + +typedef struct { + Acmd *ACMDList[NUM_ACMD_LISTS]; + AudioInfo *audioInfo[NUM_OUTPUT_BUFFERS]; + OSThread thread; + OSMesgQueue audioFrameMsgQ; + OSMesg audioFrameMsgBuf[MAX_MESGS]; + OSMesgQueue audioReplyMsgQ; + OSMesg audioReplyMsgBuf[MAX_MESGS]; + ALGlobals g; +} AMAudioMgr; + +typedef struct +{ + ALLink node; + u32 startAddr; + u32 lastFrame; + char *ptr; +} AMDMABuffer; + +typedef struct { + u8 initialized; + AMDMABuffer *firstUsed; + AMDMABuffer *firstFree; +} AMDMAState; + + +/**** audio manager globals ****/ + +OSSched *gAudioSched; +ALHeap *gAudioHeap; // Set but not used + +AMAudioMgr __am; +static u64 audioStack[AUDIO_STACKSIZE/sizeof(u64)]; + +AMDMAState dmaState; +AMDMABuffer dmaBuffs[NUM_DMA_BUFFERS]; +u32 audFrameCt = 0; +u32 nextDMA = 0; +u32 curAcmdList = 0; +u32 minFrameSize; +u32 frameSize; +u32 maxFrameSize; +s32 gAudioCmdLen; // Set but not used + +/**** Anti Piracy - Sets random audio frequency ****/ +s16 gAntiPiracyCRCStart; +s8 gAntiPiracyAudioFreq = FALSE; +s32 gFunc80019808Checksum = 0x35281; +s32 gFunc80019808Length = 0xFD0; + +/** Queues and storage for use with audio DMA's ****/ +OSIoMesg audDMAIOMesgBuf[NUM_DMA_MESSAGES]; +OSMesgQueue audDMAMessageQ; +OSMesg audDMAMessageBuf[NUM_DMA_MESSAGES]; + +/**** Not really sure why these are here. They are set, but never used. ****/ +static s16 *gLastAudioPtr = 0; +static s32 gLastAudioFrameSamples = 0; + +/**** private routines ****/ +static void __amMain(UNUSED void *arg); +static s32 __amDMA(s32 addr, s32 len, void *state); +static ALDMAproc __amDmaNew(AMDMAState **state); +static u32 __amHandleFrameMsg(AudioInfo *info, AudioInfo *lastInfo); +static void __amHandleDoneMsg(AudioInfo *info); +static void __clearAudioDMA(void); + + +/**** Debug strings ****/ +const char D_800E49F0[] = "audio manager: RCP audio interface bug caused DMA from bad address - move audiomgr.c in the makelist!\n"; +const char D_800E4A58[] = "audio: ai out of samples\n"; +const char D_800E4A74[] = "OH DEAR - No audio DMA buffers left\n"; +const char D_800E4A9C[] = "Dma not done\n"; +const char D_800E4AAC[] = ""; +const char D_800E49B0[] = "Bad soundState: voices =%d, states free =%d, states busy =%d, type %d data %x\n"; +const char D_800E4B00[] = "playing a playing sound\n"; +const char D_800E4B1C[] = "Nonsense sndp event\n"; +const char D_800E4B34[] = "Sound state allocate failed - sndId %d\n"; +const char D_800E4B5C[] = "Don't worry - game should cope OK\n"; +const char D_800E4B80[] = "WARNING: Attempt to stop NULL sound aborted\n"; + +/****************************************************************************** + * Audio Manager API + *****************************************************************************/ +void amCreateAudioMgr(ALSynConfig *c, OSPri pri, OSSched *audSched) { + s32 i; + f32 fsize; + uintptr_t *asset; + u32 *assetAudioTable; + s32 *asset8; + s32 assetSize; + s32 checksum; + u8 *crc_region_start; + u8 *crc_region; + + gAudioSched = audSched; + gAudioHeap = c->heap; + + c->dmaproc = &__amDmaNew; + c->outputRate = osAiSetFrequency(OUTPUT_RATE); + + /* + * Calculate the frame sample parameters from the + * video field rate and the output rate + */ + fsize = (f32) c->outputRate * 2 / (f32) gVideoRefreshRate; + frameSize = (s32) fsize; + if (frameSize < fsize) { + frameSize++; + } + if (frameSize & 0xf) { + frameSize = (frameSize & ~0xf) + 0x10; + } + minFrameSize = frameSize - 16; + maxFrameSize = frameSize + EXTRA_SAMPLES + 16; + + if (c->fxType[0] == AL_FX_CUSTOM) { + assetAudioTable = load_asset_section_from_rom(ASSET_AUDIO_TABLE); + assetSize = assetAudioTable[ASSET_AUDIO_9] - assetAudioTable[ASSET_AUDIO_8]; + asset8 = allocate_from_main_pool_safe(assetSize, COLOUR_TAG_CYAN); + load_asset_to_address(ASSET_AUDIO, (u32) asset8, assetAudioTable[ASSET_AUDIO_8], assetSize); + c->params = asset8; + c[1].maxVVoices = 0; + alInit(&__am.g, c); + free_from_memory_pool(asset8); + } else { + alInit(&__am.g, c); + } + + dmaBuffs[0].node.prev = 0; + dmaBuffs[0].node.next = 0; + + for (i = 0; i < NUM_DMA_BUFFERS - 1; i++) { + alLink((ALLink *) &(dmaBuffs[i + 1]), (ALLink *) &(dmaBuffs[i])); + dmaBuffs[i].ptr = alHeapAlloc(c->heap, 1, DMA_BUFFER_LENGTH); + } + /* last buffer already linked, but still needs buffer */ + dmaBuffs[i].ptr = alHeapAlloc(c->heap, 1, DMA_BUFFER_LENGTH); + + // Antipiracy measure + gAntiPiracyCRCStart = DMA_BUFFER_LENGTH; + checksum = (s32) &func_80019808 - gAntiPiracyCRCStart; + crc_region_start = (u8 *) checksum; + crc_region = &crc_region_start[gAntiPiracyCRCStart]; + gAntiPiracyAudioFreq = FALSE; + i = 0; + for (checksum = 0; i < gFunc80019808Length; i++) { + checksum += crc_region[i]; + gAntiPiracyCRCStart++; + } + if (checksum != gFunc80019808Checksum) { + gAntiPiracyAudioFreq = TRUE; + } + + for (i = 0; i < NUM_ACMD_LISTS; i++) { + __am.ACMDList[i] = (Acmd *) alHeapAlloc(c->heap, 1, 0xA000); //sizeof(Acmd) * DMA_BUFFER_LENGTH * 5? + } + + asset = allocate_at_address_in_main_pool((maxFrameSize * 12), (u8 *)(0x803FFE00 - (maxFrameSize * 12)), COLOUR_TAG_CYAN); + + /**** initialize the done messages ****/ + for (i = 0; i < NUM_ACMD_LISTS + 1; i++) { + __am.ACMDList[i + NUM_ACMD_LISTS] = (Acmd *) alHeapAlloc(c->heap, 1, 120); + __am.ACMDList[i + NUM_ACMD_LISTS]->words.w0 = (uintptr_t) asset; + asset += maxFrameSize; + } + + osCreateMesgQueue(&__am.audioReplyMsgQ, __am.audioReplyMsgBuf, MAX_MESGS); + osCreateMesgQueue(&__am.audioFrameMsgQ, __am.audioFrameMsgBuf, MAX_MESGS); + osCreateMesgQueue(&audDMAMessageQ, audDMAMessageBuf, NUM_DMA_MESSAGES); + + osCreateThread(&__am.thread, 4, __amMain, 0, + (void *)(audioStack+AUDIO_STACKSIZE/sizeof(u64)), pri); +} + +void audioStartThread(void) { + osStartThread(&__am.thread); +} + +void audioStopThread(void) { + osStopThread(&__am.thread); +} + +/****************************************************************************** + * + * Audio Manager implementation. This thread wakes up at every retrace, + * and builds an audio task, which it returns to the scheduler, who then + * is responsible for its finally execution on the RSP. Once the task has + * finished execution, the scheduler sends back a message saying the task + * is complete. The audio is triple buffered because the switching to a new + * audio buffer does not occur exactly at the gfx swapbuffer time. With + * 3 buffers you ensure that the program does not destroy data before it is + * played. + * + *****************************************************************************/ +/** + * Main function for handling ingame audio. Loops continuously as long as the scheduler feeds it updates. + */ +static void __amMain(UNUSED void *arg) { + s32 done = 0; + AudioMsg *msg = NULL; + AudioInfo *lastInfo = 0; + + osScAddClient(gAudioSched, (OSScClient *) &audioStack, &__am.audioFrameMsgQ, OS_MESG_BLOCK); + + while (!done) { + (void) osRecvMesg(&__am.audioFrameMsgQ, (OSMesg *) &msg, 1); + switch (msg->gen.type) { + case OS_SC_RETRACE_MSG: + //TODO: Check type of ACMDList? + __amHandleFrameMsg((AudioInfo *) __am.ACMDList[(((u32) audFrameCt % 3))+2], lastInfo); + /* wait for done message */ + osRecvMesg(&__am.audioReplyMsgQ, (OSMesg *) &lastInfo, OS_MESG_BLOCK); + __amHandleDoneMsg(lastInfo); + break; + case OS_SC_PRE_NMI_MSG: + /* what should we really do here? quit? ramp down volume? */ + break; + case QUIT_MSG: + done = 1; + break; + default: + break; + } + } + + alClose(&__am.g); +} + +/****************************************************************************** + * + * __amHandleFrameMsg. First, clear the past audio dma's, then calculate + * the number of samples you will need for this frame. This value varies + * due to the fact that audio is synchronised off of the video interupt + * which can have a small amount of jitter in it. Varying the number of + * samples slightly will allow you to stay in synch with the video. This + * is an advantageous thing to do, since if you are in synch with the + * video, you will have fewer graphics yields. After you've calculated + * the number of frames needed, call alAudioFrame, which will call all + * of the synthesizer's players (sequence player and sound player) to + * generate the audio task list. If you get a valid task list back, put + * it in a task structure and send a message to the scheduler to let it + * know that the next frame of audio is ready for processing. + * + *****************************************************************************/ +static u32 __amHandleFrameMsg(AudioInfo *info, AudioInfo *lastInfo) { + s16 *audioPtr; + Acmd *cmdp; + int samplesLeft = 0; + OSScTask *t; + u32 ret; + + + __clearAudioDMA(); /* call once a frame, before doing alAudioFrame */ + + audioPtr = (s16 *) osVirtualToPhysical(info->data); + + if (lastInfo) { + s16 *outputDataPointer; + s32 frameSamples; + + gLastAudioPtr = outputDataPointer = lastInfo->data; + gLastAudioFrameSamples = frameSamples = lastInfo->frameSamples << 2; + osAiSetNextBuffer(outputDataPointer, frameSamples); + + // Antipiracy measure + if (gAntiPiracyAudioFreq != 0) { + osAiSetFrequency(get_random_number_from_range(0, 10000) + OUTPUT_RATE); + } + } + + + /* calculate how many samples needed for this frame to keep the DAC full */ + /* this will vary slightly frame to frame, must recalculate every frame */ + samplesLeft = osAiGetLength() >> 2; /* divide by four, to convert bytes */ + /* to stereo 16 bit samples */ + info->frameSamples = (16 + (frameSize - samplesLeft + EXTRA_SAMPLES)) & ~0xf; + if ((u32)info->frameSamples < minFrameSize) + info->frameSamples = minFrameSize; + + cmdp = alAudioFrame(__am.ACMDList[curAcmdList], &gAudioCmdLen, audioPtr, + info->frameSamples); + + t = &info->task; + + t->next = 0; /* paranoia */ + t->msgQ = &__am.audioReplyMsgQ; /* reply to when finished */ + //TODO: This should be &info->msg, but the struct is likely modified. + t->msg = (OSMesg) &info->data; /* reply with this message */ + t->flags = OS_SC_NEEDS_RSP; + t->unk58 = -1; + t->unk60 = 0xFF; + t->unk5C = 0; + t->unk64 = 0; + + t->list.t.data_ptr = (u64 *) __am.ACMDList[curAcmdList]; + t->list.t.data_size = (cmdp - __am.ACMDList[curAcmdList]) * sizeof(Acmd); + t->list.t.type = M_AUDTASK; + t->list.t.ucode_boot = (u64 *)rspF3DDKRBootStart; + t->list.t.ucode_boot_size = + ((int) rspF3DDKRDramStart - (int) rspF3DDKRBootStart); + t->list.t.flags = OS_TASK_DP_WAIT; + t->list.t.ucode = (u64 *) aspMainTextStart; + t->list.t.ucode_data = (u64 *) aspMainDataStart; + t->list.t.ucode_data_size = SP_UCODE_DATA_SIZE; + t->list.t.yield_data_ptr = NULL; + t->list.t.yield_data_size = 0; + t->unk6C = 1; + + ret = osSendMesg(osScGetCmdQ(gAudioSched), (OSMesg) t, OS_MESG_NOBLOCK); + + curAcmdList ^= 1; /* swap which acmd list you use each frame */ + + return ret; +} + +/****************************************************************************** + * + * __amHandleDoneMsg. Really just debugging info in this frame. Checks + * to make sure we completed before we were out of samples. + * + *****************************************************************************/ +static void __amHandleDoneMsg(UNUSED AudioInfo *info) { + s32 samplesLeft; + static int firstTime = 1; + + samplesLeft = osAiGetLength()>>2; + if (samplesLeft == 0 && !firstTime) { + //stubbed_printf("audio: ai out of samples\n"); + firstTime = 0; + } +} + +/****************************************************************************** + * + * __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. + * + *****************************************************************************/ +static s32 __amDMA(s32 addr, s32 len, UNUSED void *state) { + void *foundBuffer; + s32 delta, addrEnd, buffEnd; + AMDMABuffer *dmaPtr, *lastDmaPtr; + UNUSED s32 pad; + + lastDmaPtr = 0; + delta = addr & 1; + 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 > (u32)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 (!dmaPtr && !lastDmaPtr) { + lastDmaPtr = dmaState.firstUsed; + } + + /* + * if you get here and dmaPtr is null, send back the a bogus + * pointer, it's better than nothing + */ + if (!dmaPtr) { + return (int) osVirtualToPhysical(lastDmaPtr->ptr) + delta; + } + + 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; + addr -= delta; + dmaPtr->startAddr = addr; + dmaPtr->lastFrame = audFrameCt; /* mark it */ + + osPiStartDma(&audDMAIOMesgBuf[nextDMA++], OS_MESG_PRI_HIGH, OS_READ, + addr, foundBuffer, DMA_BUFFER_LENGTH, &audDMAMessageQ); + + return (int) osVirtualToPhysical(foundBuffer) + delta; +} + +/****************************************************************************** + * + * __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. + * + *****************************************************************************/ +static ALDMAproc __amDmaNew(AMDMAState **state) { + + if(!dmaState.initialized) { /* only do this once */ + dmaState.firstUsed = 0; + dmaState.firstFree = &dmaBuffs[0]; + dmaState.initialized = 1; + } + + *state = &dmaState; /* state is never used in this case */ + + return __amDMA; +} + +/****************************************************************************** + * + * __clearAudioDMA. Routine to move dma buffers back to the unused list. + * First clear out your dma messageQ. Then check each buffer to see when + * it was last used. If that was more than FRAME_LAG frames ago, move it + * back to the unused list. + * + *****************************************************************************/ +static void __clearAudioDMA(void) { + u32 i; + OSIoMesg *iomsg = 0; + AMDMABuffer *dmaPtr,*nextPtr; + + /* + * Don't block here. If dma's aren't complete, you've had an audio + * overrun. (Bad news, but go for it anyway, and try and recover. + */ + for (i = 0; i < nextDMA; i++) { + if (osRecvMesg(&audDMAMessageQ, (OSMesg *) &iomsg, OS_MESG_NOBLOCK) == -1) + { /* stubbed_printf("Dma not done\n"); */ } + // if (logging) + // osLogEvent(log, 17, 2, iomsg->devAddr, iomsg->size); + } + + + dmaPtr = dmaState.firstUsed; + while(dmaPtr) { + nextPtr = (AMDMABuffer *) dmaPtr->node.next; + + /* remove old dma's from list */ + /* Can change FRAME_LAG value. Should be at least one. */ + /* Larger values mean more buffers needed, but fewer DMA's */ + if(dmaPtr->lastFrame + FRAME_LAG < audFrameCt) { + if(dmaState.firstUsed == dmaPtr) { + dmaState.firstUsed = (AMDMABuffer *) dmaPtr->node.next; + } + alUnlink((ALLink *) dmaPtr); + if(dmaState.firstFree) { + alLink((ALLink *) dmaPtr, (ALLink *) dmaState.firstFree); + } + else { + dmaState.firstFree = dmaPtr; + dmaPtr->node.next = 0; + dmaPtr->node.prev = 0; + } + } + dmaPtr = nextPtr; + } + + nextDMA = 0; /* reset */ + audFrameCt++; +} diff --git a/src/audiomgr.h b/src/audiomgr.h new file mode 100644 index 00000000..9fefe24c --- /dev/null +++ b/src/audiomgr.h @@ -0,0 +1,59 @@ +#ifndef _AUDIOMGR_H_ +#define _AUDIOMGR_H_ + +#include "types.h" +#include "macros.h" +#include "audio_internal.h" +#include "asset_enums.h" +#include "libultra_internal.h" +#include "sched.h" + +#define MAX_UPDATES 32 +#define MAX_EVENTS 32 +#define AUDIO_HEAP_SIZE 0x29D88 + +#define MAX_VOICES 22 +#define EXTRA_SAMPLES 96 +#define NUM_OUTPUT_BUFFERS 3 /* Need three of these */ +#define OUTPUT_RATE 22050 +#define MAX_MESGS 8 +#define QUIT_MSG 10 + +#define DMA_BUFFER_LENGTH 0x400 /* Larger buffers result in fewer DMA' but more */ + /* memory being used. */ + + +#define NUM_ACMD_LISTS 2 /* two lists used by this example */ +#define MAX_RSP_CMDS 4096 /* max number of commands in any command list. */ + /* Mainly dependent on sequences used */ + +#define NUM_DMA_BUFFERS 50 /* max number of dma buffers needed. */ + /* Mainly dependent on sequences and sfx's */ + +#define NUM_DMA_MESSAGES 50 /* The maximum number of DMAs any one frame can */ + /* have. */ + +#define FRAME_LAG 1 /* The number of frames to keep a dma buffer. */ + /* Increasing this number causes buffers to not */ + /* be deleted as quickly. This results in fewer */ + /* DMA's but you need more buffers. */ + + +#define AUDIO_STACKSIZE 0x3010 + +#define MAX_SEQ_LENGTH 20000 + +extern Acmd *alAudioFrame(Acmd *cmdList, s32 *cmdLen, s16 *outBuf, s32 outLen); +extern void *alHeapDBAlloc(u8 *file, s32 line, ALHeap *hp, s32 num, s32 size); +extern void alInit(ALGlobals *g, ALSynConfig *c); + +extern s8 rspF3DDKRBootStart[]; +extern s8 rspF3DDKRDramStart[]; +extern s8 aspMainDataStart[]; +extern s8 aspMainTextStart[]; + +void audioStartThread(void); +void audioStopThread(void); +void amCreateAudioMgr(ALSynConfig *c, OSPri pri, OSSched *audSched); + +#endif diff --git a/src/audiosfx.c b/src/audiosfx.c new file mode 100644 index 00000000..8f27bd7b --- /dev/null +++ b/src/audiosfx.c @@ -0,0 +1,303 @@ +/* The comment below is needed for this file to be picked up by generate_ld */ +/* RAM_POS: 0x80003160 */ + +#include "audiosfx.h" +#include "memory.h" +#include "audio_internal.h" +#include "video.h" +#include "math_util.h" +#include "asset_loading.h" +#include "objects.h" +#include "PR/libaudio.h" + +ALEventQueue *D_800DC6B0 = NULL; +s32 D_800DC6B4 = 0; // Currently unknown, might be a different type. +unk800DC6BC_40 *D_800DC6B8 = NULL; // Set but not used. +unk800DC6BC gAlSndPlayer; +unk800DC6BC *gAlSndPlayerPtr = &gAlSndPlayer; +s32 sfxVolumeSlider = 256; +s32 D_800DC6C4 = 0; // Currently unknown, might be a different type. +u16 *gSoundChannelVolume; + +static void _removeEvents(ALEventQueue *, ALSoundState *, u16); + +void set_sfx_volume_slider(u32 volume) { + if (volume > 256) { + volume = 256; + } + + sfxVolumeSlider = volume; +} + +s32 get_sfx_volume_slider(void) { + return sfxVolumeSlider; +} + +/** + * Sets the number of active sound channels to either the passed number, or the maximum amount, whichever's lower. + */ +void set_sound_channel_count(s32 numChannels) { + if (gAlSndPlayerPtr->soundChannelsMax >= numChannels) { + gAlSndPlayerPtr->soundChannels = numChannels; + } else { + gAlSndPlayerPtr->soundChannels = gAlSndPlayerPtr->soundChannelsMax; + } +} + +void alSndPNew(audioMgrConfig *c) { + u32 i; + unk800DC6BC_40 *tmp1; + ALEvent evt; + + /* + * Init member variables + */ + gAlSndPlayerPtr->soundChannelsMax = c->maxChannels; + gAlSndPlayerPtr->soundChannels = c->maxChannels; + gAlSndPlayerPtr->unk3C = 0; + gAlSndPlayerPtr->frameTime = 33000; //AL_USEC_PER_FRAME /* time between API events */ + gAlSndPlayerPtr->unk40 = (unk800DC6BC_40 *) alHeapAlloc(c->hp, 1, + c->unk00 * sizeof(unk800DC6BC_40)); + alEvtqNew(&(gAlSndPlayerPtr->evtq), alHeapAlloc(c->hp, 1, (c->unk04) * 28), c->unk04); + D_800DC6B8 = gAlSndPlayerPtr->unk40; + for (i = 1; i < c->unk00; i++) { + tmp1 = gAlSndPlayerPtr->unk40; + alLink((ALLink *) (i + tmp1), (ALLink *) (i + tmp1 - 1)); + } + + /* + * init the event queue + */ + gSoundChannelVolume = alHeapAlloc(c->hp, 2, c->unk10); + for (i = 0; i < c->unk10; i++) { + gSoundChannelVolume[i] = 32767; + } + + /* + * add ourselves to the driver + */ + gAlSndPlayerPtr->drvr = (ALSynth *) alGlobals; + gAlSndPlayerPtr->node.next = NULL; + gAlSndPlayerPtr->node.handler = _sndpVoiceHandler; + gAlSndPlayerPtr->node.clientData = gAlSndPlayerPtr; + alSynAddPlayer(gAlSndPlayerPtr->drvr, (ALPlayer *) gAlSndPlayerPtr); + + /* + * Start responding to API events + */ + evt.type = AL_SNDP_API_EVT; + alEvtqPostEvent(&gAlSndPlayerPtr->evtq, (ALEvent *) &evt, gAlSndPlayerPtr->frameTime); + gAlSndPlayerPtr->nextDelta = alEvtqNextEvent(&gAlSndPlayerPtr->evtq, &gAlSndPlayerPtr->nextEvent); +} + +ALMicroTime _sndpVoiceHandler(void *node) { + unk800DC6BC *sndp = (unk800DC6BC *) node; + ALSndpEvent evt; + u32 eventType = AL_SNDP_API_EVT; + + do { + switch (sndp->nextEvent.type) { + case (AL_SNDP_API_EVT): + evt.common.type = eventType; + alEvtqPostEvent(&sndp->evtq, (ALEvent *) &evt, sndp->frameTime); + break; + + default: + _handleEvent(sndp, (ALSndpEvent *) &sndp->nextEvent); + break; + } + sndp->nextDelta = alEvtqNextEvent(&sndp->evtq, &sndp->nextEvent); + + } while (sndp->nextDelta == 0); + sndp->curTime += sndp->nextDelta; + return sndp->nextDelta; +} + +GLOBAL_ASM("asm/non_matchings/audiosfx/_handleEvent.s") + +void func_8000410C(ALSoundState *state) { + if (state->unk3E & 4) { + alSynStopVoice(gAlSndPlayerPtr->drvr, &state->voice); + alSynFreeVoice(gAlSndPlayerPtr->drvr, &state->voice); + } + func_80004520(state); + _removeEvents(&gAlSndPlayerPtr->evtq, state, 0xFFFF); +} + +#if 0 +void func_8000418C(void *arg0) { + f32 sp28; + void *sp24; + s16 sp20; + f32 sp1C; + f32 temp_f6; + + temp_f6 = alCents2Ratio((s32) arg0->unk8->unk4->unk5) * arg0->unk2C; + sp20 = 16; + sp1C = temp_f6; + sp24 = arg0; + sp28 = sp1C; + alEvtqPostEvent(&gAlSndPlayerPtr->evtq, (ALEvent *) &sp20, 33333); +} +#else +GLOBAL_ASM("asm/non_matchings/audiosfx/func_8000418C.s") +#endif + +static void _removeEvents(ALEventQueue *evtq, ALSoundState *state, u16 eventType) { + ALLink *thisNode; + ALLink *nextNode; + ALEventListItem *thisItem; + ALEventListItem *nextItem; + ALSndpEvent *thisEvent; + OSIntMask mask; + + mask = osSetIntMask(OS_IM_NONE); + + thisNode = evtq->allocList.next; + while( thisNode != 0 ) { + nextNode = thisNode->next; + thisItem = (ALEventListItem *)thisNode; + nextItem = (ALEventListItem *)nextNode; + thisEvent = (ALSndpEvent *) &thisItem->evt; + if (thisEvent->common.state == state && (u16)thisEvent->msg.type & eventType){ + if( nextItem ) + nextItem->delta += thisItem->delta; + alUnlink(thisNode); + alLink(thisNode, &evtq->freeList); + } + thisNode = nextNode; + } + + osSetIntMask(mask); +} + +u16 func_800042CC(u16 *lastAllocListIndex, u16 *lastFreeListIndex) { + OSIntMask mask; + u16 freeListNextIndex; + u16 allocListNextIndex; + u16 freeListLastIndex; + ALLink *nextAllocList; + ALLink *nextFreeList; + ALLink *prevFreeList; + ALEventQueue *queue; + + mask = osSetIntMask(OS_IM_NONE); + queue = (ALEventQueue *) &D_800DC6B0; //D_800DC6B0 could be a different type? + nextFreeList = queue->freeList.next; + nextAllocList = queue->allocList.next; + prevFreeList = queue->freeList.prev; + + for (freeListNextIndex = 0; nextFreeList != 0; freeListNextIndex++) { + nextFreeList = (ALLink *) nextFreeList->next; + } + + for (allocListNextIndex = 0; nextAllocList != 0; allocListNextIndex++) { + nextAllocList = (ALLink *) nextAllocList->next; + } + + for (freeListLastIndex = 0; prevFreeList != 0; freeListLastIndex++) { + prevFreeList = (ALLink *) prevFreeList->prev; + } + + *lastAllocListIndex = allocListNextIndex; + *lastFreeListIndex = freeListNextIndex; + + osSetIntMask(mask); + + return freeListLastIndex; +} + +GLOBAL_ASM("asm/non_matchings/audiosfx/func_80004384.s") +GLOBAL_ASM("asm/non_matchings/audiosfx/func_80004520.s") + +void func_80004604(u8 *arg0, u8 arg1) { + if (arg0) + arg0[0x36] = arg1; +} + +UNUSED u8 func_8000461C(u8 *arg0) { + if (arg0) + return arg0[0x3F]; + return 0; +} + +s32 func_80004638(ALBank *bnk, s16 sndIndx, s32 arg2) { + return func_80004668(bnk, sndIndx, 0, arg2); +} + +#ifdef NON_EQUIVALENT +s32 func_80004668(ALBank *bnk, s16 sndIndx, u8 arg2, s32 arg3) { +} +#else +GLOBAL_ASM("asm/non_matchings/audiosfx/func_80004668.s") +#endif + +//input typing not right (some type of struct) +// 99% sure this function will clear the audio buffer associated with a given sound mask. +void func_8000488C(u8 *arg0) { + ALEvent sp_18; + sp_18.type = 1024; + ((u32 *)(&sp_18))[1] = (u32)arg0; + if (arg0) { + arg0[0x3e] &= ~(1 << 4); + alEvtqPostEvent(&(gAlSndPlayerPtr->evtq), &sp_18, 0); + } +} + +GLOBAL_ASM("asm/non_matchings/audiosfx/func_800048D8.s") + +UNUSED void func_80004998(void) { + func_800048D8(1); +} + +UNUSED void func_800049B8(void) { + func_800048D8(17); +} + +void func_800049D8(void) { + func_800048D8(3); +} + +void func_800049F8(s32 soundMask, s16 type, u32 volume) { + ALEvent2 sndEvt; + sndEvt.snd_event.type = type; + sndEvt.snd_event.state = (void *) soundMask; + sndEvt.snd_event.unk04 = volume; + if (soundMask) { + alEvtqPostEvent(&(gAlSndPlayerPtr->evtq), (ALEvent *) &sndEvt, 0); + } +} + +/** + * Returns the volume level of the channel ID. +*/ +u16 get_sound_channel_volume(u8 channel) { + return gSoundChannelVolume[channel]; +} + +//TODO: The structs used here are almost definitely wrong, but they do match, so it can at least show the pattern we're looking for. +/** + * Looks for the intended audio channel in the main buffer and adjusts its volume +*/ +void set_sound_channel_volume(u8 channel, u16 volume) { + OSIntMask mask; + ALEventQueue *queue; + UNUSED s32 pad; + ALEvent evt; + + mask = osSetIntMask(OS_IM_NONE); + queue = D_800DC6B0; + gSoundChannelVolume[channel] = volume; + + while (queue != NULL) { + //This is almost definitely the wrong struct list, but it matches so I'm not going to complain + if ((((ALInstrument *) queue->allocList.next->prev)->priority & 0x3F) == channel) { + evt.type = AL_SNDP_UNK_11_EVT; + evt.msg.spseq.seq = (void *) queue; + alEvtqPostEvent(&gAlSndPlayerPtr->evtq, &evt, 0); + } + queue = (ALEventQueue *) queue->freeList.next; + } + + osSetIntMask(mask); +} diff --git a/src/audiosfx.h b/src/audiosfx.h new file mode 100644 index 00000000..fc12ff21 --- /dev/null +++ b/src/audiosfx.h @@ -0,0 +1,139 @@ +#ifndef _AUDIOSFX_H_ +#define _AUDIOSFX_H_ + +#include "types.h" +#include "macros.h" +#include "audio_internal.h" +#include "asset_enums.h" +#include "libultra_internal.h" +#include "sched.h" + +#define AL_SNDP_PLAY_EVT (1 << 0) +#define AL_SNDP_STOP_EVT (1 << 1) +#define AL_SNDP_PAN_EVT (1 << 2) +#define AL_SNDP_VOL_EVT (1 << 3) +#define AL_SNDP_PITCH_EVT (1 << 4) +#define AL_SNDP_API_EVT (1 << 5) +#define AL_SNDP_DECAY_EVT (1 << 6) +#define AL_SNDP_END_EVT (1 << 7) +#define AL_SNDP_FX_EVT (1 << 8) +#define AL_SNDP_UNK_9_EVT (1 << 9) +#define AL_SNDP_UNK_10_EVT (1 << 10) +#define AL_SNDP_UNK_11_EVT (1 << 11) + +typedef struct { + /* 0x00 */ s8 pad00[0x0C]; + /* 0x0C */ ALVoice voice; + ALSound *sound; /* sound referenced here */ + s16 priority; + f32 pitch; /* current playback pitch */ + s32 state; /* play state for this sound */ + s16 vol; /* volume - combined with volume from bank */ + ALPan pan; /* pan - 0 = left, 127 = right */ + u8 fxMix; /* wet/dry mix - 0 = dry, 127 = wet */ + /* 0x3C */ u8 pad3C[2]; + /* 0x3E */ u8 unk3E; +} ALSoundState; + +typedef struct unk800DC6BC_40 { + ALLink node; + u8 pad0C[0x38]; +} unk800DC6BC_40; //ALSoundState + +/* Unknown Size */ +typedef struct unk800DC6BC { + ALPlayer node; + ALEventQueue evtq; + ALEvent nextEvent; + ALSynth *drvr; + u32 unk3C; + unk800DC6BC_40 *unk40; + s32 soundChannelsMax; + s32 soundChannels; + s32 frameTime; + ALMicroTime nextDelta; + ALMicroTime curTime; +} unk800DC6BC; //ALSndPlayer + +typedef union { + ALEvent msg; + + struct{ + s16 type; + void* state; + u32 unk04; + }snd_event; + +} ALEvent2; + +typedef union { + + ALEvent msg; + + struct { + s16 type; + ALSoundState *state; + } common; + + struct { + s16 type; + ALSoundState *state; + s16 vol; + } vol; + + struct { + s16 type; + ALSoundState *state; + f32 pitch; + } pitch; + + struct { + s16 type; + ALSoundState *state; + ALPan pan; + } pan; + + struct { + s16 type; + ALSoundState *state; + u8 mix; + } fx; + +} ALSndpEvent; + +typedef struct audioMgrConfig_s{ + u32 unk00; + u32 unk04; + u32 maxChannels; + ALHeap *hp; + u16 unk10; // Heap Size? +} audioMgrConfig; + +extern void *alHeapDBAlloc(u8 *file, s32 line, ALHeap *hp, s32 num, s32 size); //lib/src/al +extern void alEvtqNew(ALEventQueue *evtq, ALEventListItem *items, s32 itemCount); //lib/src/unknown_0C9C90.c +extern ALMicroTime alEvtqNextEvent(ALEventQueue *evtq, ALEvent *evt); //lib/src/unknown_0C9C90.c +extern void alSynAddPlayer(ALSynth *drvr, ALPlayer *client); //lib/src/unknown_0C9C90.c +extern void alEvtqPostEvent(ALEventQueue *evtq, ALEvent *evt, ALMicroTime delta); //lib/src/unknown_0C9C90.c Non Matching + +void set_sfx_volume_slider(u32 volume); +s32 get_sfx_volume_slider(void); +void set_sound_channel_count(s32 numChannels); +void alSndPNew(audioMgrConfig *c); +ALMicroTime _sndpVoiceHandler(void *node); +void func_8000410C(ALSoundState *state); +u16 func_800042CC(u16 *lastAllocListIndex, u16 *lastFreeListIndex); +void func_80004604(u8 *arg0, u8 arg1); +s32 func_80004638(ALBank *bnk, s16 sndIndx, s32 arg2); +void func_800049D8(void); +void func_800049F8(s32 soundMask, s16 type, u32 volume); +u16 get_sound_channel_volume(u8 channel); +void set_sound_channel_volume(u8 channel, u16 volume); + +// Non Matching +void func_80004520(ALSoundState *); +s32 func_80004668(ALBank *bnk, s16 sndIndx, u8, s32); +INCONSISTENT void func_8000488C(); +void func_800048D8(s32); +void _handleEvent(unk800DC6BC *sndp, ALSndpEvent *event); + +#endif diff --git a/src/game.c b/src/game.c index 7def7501..97f7d428 100644 --- a/src/game.c +++ b/src/game.c @@ -26,7 +26,8 @@ #include "camera.h" #include "save_data.h" #include "unknown_078050.h" -#include "unknown_003260.h" +#include "audiosfx.h" +#include "audiomgr.h" #include "unknown_032760.h" #include "textures_sprites.h" #include "PR/os_internal.h" diff --git a/src/game_ui.c b/src/game_ui.c index 0c9d6b0e..fd6eba60 100644 --- a/src/game_ui.c +++ b/src/game_ui.c @@ -17,7 +17,7 @@ #include "object_models.h" #include "unknown_0255E0.h" #include "unknown_078050.h" -#include "unknown_003260.h" +#include "audiosfx.h" #include "printf.h" #include "unknown_008C40.h" diff --git a/src/menu.c b/src/menu.c index 23c70507..60ceb12a 100644 --- a/src/menu.c +++ b/src/menu.c @@ -25,7 +25,7 @@ #include "unknown_078050.h" #include "save_data.h" #include "object_functions.h" -#include "unknown_003260.h" +#include "audiosfx.h" #include "racer.h" #include "unknown_078050.h" #include "unknown_0255E0.h" @@ -2840,7 +2840,7 @@ void menu_audio_options_init(void) { transition_begin(&sMenuTransitionFadeOut); func_8007FFEC(2); gMusicVolumeSliderValue = musicGetVolSliderPercentage(); - gSfxVolumeSliderValue = sfxGetVolumeSlider(); + gSfxVolumeSliderValue = get_sfx_volume_slider(); if (gActiveMagicCodes & CHEAT_MUSIC_MENU) { // Check if "JUKEBOX" cheat is active gAudioMenuStrings[6].unkC = gMusicTestString; gAudioMenuStrings[3].unk2 = 0xD4; diff --git a/src/object_functions.c b/src/object_functions.c index 712e8e7a..cf15b0f4 100644 --- a/src/object_functions.c +++ b/src/object_functions.c @@ -22,7 +22,7 @@ #include "unknown_032760.h" #include "game_ui.h" #include "waves.h" -#include "unknown_003260.h" +#include "audiosfx.h" #include "math_util.h" #include "game_text.h" #include "fade_transition.h" diff --git a/src/racer.c b/src/racer.c index 0bb0d638..e427fb6f 100644 --- a/src/racer.c +++ b/src/racer.c @@ -24,7 +24,7 @@ #include "unknown_005740.h" #include "game_ui.h" #include "object_models.h" -#include "unknown_003260.h" +#include "audiosfx.h" #include "collision.h" diff --git a/src/unknown_003260.c b/src/unknown_003260.c deleted file mode 100644 index 2bb4a119..00000000 --- a/src/unknown_003260.c +++ /dev/null @@ -1,489 +0,0 @@ -/* The comment below is needed for this file to be picked up by generate_ld */ -/* RAM_POS: 0x80002660 */ - -#include "unknown_003260.h" -#include "memory.h" -#include "audio_internal.h" -#include "video.h" - -/************ .bss ************/ - -// All of these are defined in unknown_003260_bss.c -// This was needed, since there is a bss reordering issue with D_80119BD0 and gAlSndPlayer - -extern OSSched *gAudioSched; -extern ALHeap *D_80115F94; -extern s32 D_80115F98[2]; -extern s32 D_80115FA0[3]; -extern OSThread audioThread; -extern OSMesgQueue gAudioMesgQueue; -extern OSMesg D_80116178[8]; -extern OSMesgQueue D_80116198; -extern OSMesg D_801161B0[8]; -extern ALGlobals ALGlobals_801161D0; -extern u64 audioStack[AUDIO_STACKSIZE/sizeof(u64)]; -extern AMDMAState dmaState; -extern AMDMABuffer dmaBuffs[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 *gSoundChannelVolume; - -/******************************/ - -/************ .data ************/ - -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. -s32 gFunc80019808Checksum = 0x35281; -s32 gFunc80019808Length = 0xFD0; -s32 D_800DC698 = 0; // Currently unknown, might be a different type. -s32 D_800DC69C = 0; // Currently unknown, might be a different type. - -/*******************************/ - -/************ .rodata ************/ - -// Debug strings -const char D_800E49F0[] = "audio manager: RCP audio interface bug caused DMA from bad address - move audiomgr.c in the makelist!\n"; -const char D_800E4A58[] = "audio: ai out of samples\n"; -const char D_800E4A74[] = "OH DEAR - No audio DMA buffers left\n"; -const char D_800E4A9C[] = "Dma not done\n"; -const char D_800E4AAC[] = ""; -const char D_800E49B0[] = "Bad soundState: voices =%d, states free =%d, states busy =%d, type %d data %x\n"; -const char D_800E4B00[] = "playing a playing sound\n"; -const char D_800E4B1C[] = "Nonsense sndp event\n"; -const char D_800E4B34[] = "Sound state allocate failed - sndId %d\n"; -const char D_800E4B5C[] = "Don't worry - game should cope OK\n"; -const char D_800E4B80[] = "WARNING: Attempt to stop NULL sound aborted\n"; - -/*********************************/ - -s32 __amDMA(s32 addr, s32 len, void *state); - -#ifdef NON_EQUIVALENT -void audioNewThread(ALSynConfig *c, OSPri p, OSSched *arg2) { - u32 *reg_v0; - void *reg_s0; - u32 tmp_size; - s32 tmp; - s32 i; - gAudioSched = arg2; - D_80115F94 = c->heap; - c->dmaproc = &__amDmaNew; - c->outputRate = osAiSetFrequency(22050); - framesize = (((f32)c->outputRate) * 2.0f) / gVideoRefreshRate; - if (framesize < 0) { - } - - // if (c->fxType == AL_FX_CUSTOM) { - // reg_v0 = load_asset_section_from_rom(ASSET_AUDIO_TABLE); - // tmp_size = reg_v0[9] - reg_v0[8]; - // reg_s0 = allocate_from_main_pool_safe(tmp_size, COLOUR_TAG_CYAN); - // load_asset_to_address(39, reg_s0, reg_v0[8], tmp_size); - // c->params = reg_s0; - // c[1].maxVVoices = 0; - // alInit(&ALGlobals_801161D0, c); - // free_from_memory_pool(reg_s0); - // } else { - // alInit(&ALGlobals_801161D0, c); - // } - // D_80119240[0].node.next = NULL; - // D_80119240[0].node.prev = NULL; - - // for (i = 0; i < 0x30; i++) { - // alLink(&(D_80119240[i + 1].node), &(D_80119240[i].node)); - // D_80119240[i].unk10 = alHeapDBAlloc(0, 0, c->heap, 1, 0x400); - // } - // D_80119240[i].unk10 = alHeapDBAlloc(0, 0, c->heap, 1, 0x400); - alHeapDBAlloc(0, 0, c->heap, 1, 120); - - osCreateMesgQueue(&D_80116198, &D_801161B0, 8); - osCreateMesgQueue(&gAudioMesgQueue, &D_80116178, 8); - osCreateMesgQueue(&audDMAMessageQ, &audDMAMessageBuf, 50); - - osCreateThread(&audioThread, 4, &thread4_audio, NULL, &dmaState, p); -} -#else -GLOBAL_ASM("asm/non_matchings/unknown_003260/audioNewThread.s") -#endif - -void audioStartThread(void) { - osStartThread(&audioThread); -} - -void audioStopThread(void) { - osStopThread(&audioThread); -} - -/** - * Main function for handling ingame audio. Loops continuously as long as the scheduler feeds it updates. - */ -void thread4_audio(UNUSED void *arg) { - s32 audioThreadMarkExit; - s16 *audioThreadRetraceMesg; - OSMesg *audioThreadUpdateMesg; - - audioThreadMarkExit = FALSE; - audioThreadRetraceMesg = NULL; - audioThreadUpdateMesg = NULL; - - osScAddClient(gAudioSched, (OSScClient *) &audioStack, &gAudioMesgQueue, OS_SC_ID_AUDIO); - while (!audioThreadMarkExit) { - osRecvMesg(&gAudioMesgQueue, (OSMesg *) &audioThreadRetraceMesg, 1); - switch (*audioThreadRetraceMesg) { - case 1: - func_80002C00(D_80115F98[(((u32) audFrameCt % 3))+2], audioThreadUpdateMesg); - osRecvMesg(&D_80116198, (OSMesg *) &audioThreadUpdateMesg, 1); - func_80002DF8(audioThreadUpdateMesg); - break; - case 4: - // Mysterious void. - break; - case 10: - audioThreadMarkExit = TRUE; - break; - } - } - alClose(&ALGlobals_801161D0); -} - -GLOBAL_ASM("asm/non_matchings/unknown_003260/func_80002C00.s") - -void func_80002DF8(UNUSED OSMesg mesg) { - static s32 D_800DC6A0 = 1; - if ((osAiGetLength() >> 2) == 0) { - if (D_800DC6A0 == 0) { - D_800DC6A0 = 0; - } - } -} - -s32 D_800DC6A4 = 0; // Currently unknown, might be a different type. -s32 D_800DC6A8 = 0; // Currently unknown, might be a different type. -s32 D_800DC6AC = 0; // Currently unknown, might be a different type. - -ALEventQueue *D_800DC6B0 = NULL; -s32 D_800DC6B4 = 0; // Currently unknown, might be a different type. -unk800DC6BC_40 *D_800DC6B8 = NULL; -unk800DC6BC *gAlSndPlayer = &D_80119BD0; - -s32 sfxVolumeSlider = 256; -s32 D_800DC6C4 = 0; // Currently unknown, might be a different type. - -/****************************************************************************** - * - * __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. - * - *****************************************************************************/ -#ifdef NON_EQUIVALENT -#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) { - - if(!dmaState.initialized) { /* only do this once */ - dmaState.firstUsed = 0; - dmaState.firstFree = &dmaBuffs[0]; - dmaState.initialized = 1; - } - - *state = &dmaState; /* state is never used in this case */ - - return __amDMA; -} - -GLOBAL_ASM("asm/non_matchings/unknown_003260/func_80003040.s") - -void set_sfx_volume_slider(u32 volume) { - if (volume > 256) { - volume = 256; - } - - sfxVolumeSlider = volume; -} - -s32 sfxGetVolumeSlider(void) { - return sfxVolumeSlider; -} - -/** - * Sets the number of active sound channels to either the passed number, or the maximum amount, whichever's lower. - */ -void set_sound_channel_count(s32 numChannels) { - if (gAlSndPlayer->soundChannelsMax >= numChannels) { - gAlSndPlayer->soundChannels = numChannels; - } else { - gAlSndPlayer->soundChannels = gAlSndPlayer->soundChannelsMax; - } -} - -void alSndPNew(audioMgrConfig *c) { - u32 i; - unk800DC6BC_40 *tmp1; - ALEvent sp_38; - - gAlSndPlayer->soundChannelsMax = c->maxChannels; - gAlSndPlayer->soundChannels = c->maxChannels; - gAlSndPlayer->unk3C = 0; - gAlSndPlayer->frameTime = 33000; - gAlSndPlayer->unk40 = (unk800DC6BC_40 *)alHeapDBAlloc(0, 0, c->hp, 1, (c->unk00) << 6); - alEvtqNew(&(gAlSndPlayer->evtq), alHeapDBAlloc(0, 0, c->hp, 1, (c->unk04) * 28), c->unk04); - D_800DC6B8 = gAlSndPlayer->unk40; - i = 1; - for (i = 1; i < c->unk00; i++) { - tmp1 = gAlSndPlayer->unk40; - alLink((ALLink *) (i + tmp1), (ALLink *) (i + tmp1 - 1)); - } - - gSoundChannelVolume = alHeapDBAlloc(0, 0, c->hp, 2, c->unk10); - for (i = 0; i < c->unk10; i++) { - gSoundChannelVolume[i] = 32767; - } - - gAlSndPlayer->drvr = (ALSynth *) alGlobals; - gAlSndPlayer->node.next = NULL; - gAlSndPlayer->node.handler = &_sndpVoiceHandler; - gAlSndPlayer->node.clientData = gAlSndPlayer; - - alSynAddPlayer(gAlSndPlayer->drvr, (ALPlayer *) gAlSndPlayer); - sp_38.type = 32; - alEvtqPostEvent(&(gAlSndPlayer->evtq), &sp_38, gAlSndPlayer->frameTime); - gAlSndPlayer->nextDelta = alEvtqNextEvent(&(gAlSndPlayer->evtq), &(gAlSndPlayer->nextEvent)); -} - -#ifdef NON_EQUIVALENT -ALMicroTime _sndpVoiceHandler(void *node) { - unk800DC6BC *sndp = (unk800DC6BC *)node; - ALSndpEvent evt; - - do { - switch (sndp->nextEvent.type) { - case (AL_SNDP_API_EVT): - //TODO cannot get this const to load into reg t7 - evt.snd_event.type = AL_SNDP_API_EVT; - alEvtqPostEvent(&sndp->evtq, (ALEvent *)&evt, sndp->frameTime); - break; - - default: - _handleEvent(sndp, (ALSndpEvent *)&sndp->nextEvent); - break; - } - sndp->nextDelta = alEvtqNextEvent(&sndp->evtq, &sndp->nextEvent); - - } while (sndp->nextDelta == 0); - sndp->curTime += sndp->nextDelta; - return sndp->nextDelta; -} -#else -GLOBAL_ASM("asm/non_matchings/unknown_003260/_sndpVoiceHandler.s") -#endif - -GLOBAL_ASM("asm/non_matchings/unknown_003260/_handleEvent.s") -GLOBAL_ASM("asm/non_matchings/unknown_003260/func_8000410C.s") -GLOBAL_ASM("asm/non_matchings/unknown_003260/func_8000418C.s") -GLOBAL_ASM("asm/non_matchings/unknown_003260/func_800041FC.s") -GLOBAL_ASM("asm/non_matchings/unknown_003260/func_800042CC.s") -GLOBAL_ASM("asm/non_matchings/unknown_003260/func_80004384.s") -GLOBAL_ASM("asm/non_matchings/unknown_003260/func_80004520.s") - -void func_80004604(u8 *arg0, u8 arg1) { - if (arg0) - arg0[0x36] = arg1; -} - -u8 func_8000461C(u8 *arg0) { - if (arg0) - return arg0[0x3F]; - return 0; -} - -void func_80004638(ALBank *bnk, s16 sndIndx, s32 arg2) { - func_80004668(bnk, sndIndx, 0, arg2); -} - -#ifdef NON_EQUIVALENT -void func_80004668(ALBank *bnk, s16 sndIndx, u8 arg2, s32 arg3) { -} -#else -GLOBAL_ASM("asm/non_matchings/unknown_003260/func_80004668.s") -#endif - -//input typing not right (some type of struct) -// 99% sure this function will clear the audio buffer associated with a given sound mask. -void func_8000488C(u8 *arg0) { - ALEvent sp_18; - sp_18.type = 1024; - ((u32 *)(&sp_18))[1] = (u32)arg0; - if (arg0) { - arg0[0x3e] &= ~(1 << 4); - alEvtqPostEvent(&(gAlSndPlayer->evtq), &sp_18, 0); - } -} - -GLOBAL_ASM("asm/non_matchings/unknown_003260/func_800048D8.s") - -UNUSED void func_80004998(void) { - func_800048D8(1); -} - -UNUSED void func_800049B8(void) { - func_800048D8(17); -} - -void func_800049D8(void) { - func_800048D8(3); -} - -void func_800049F8(s32 soundMask, s16 type, u32 volume) { - ALSndpEvent sndEvt; - sndEvt.snd_event.type = type; - sndEvt.snd_event.state = (void *) soundMask; - sndEvt.snd_event.unk04 = volume; - if (soundMask) { - alEvtqPostEvent(&(gAlSndPlayer->evtq), (ALEvent *) &sndEvt, 0); - } -} - -/** - * Returns the volume level of the channel ID. -*/ -u16 get_sound_channel_volume(u8 channel) { - return gSoundChannelVolume[channel]; -} - -//TODO: The structs used here are almost definitely wrong, but they do match, so it can at least show the pattern we're looking for. -/** - * Looks for the intended audio channel in the main buffer and adjusts its volume -*/ -void set_sound_channel_volume(u8 channel, u16 volume) { - OSIntMask mask; - ALEventQueue *queue; - UNUSED s32 pad; - ALEvent evt; - - mask = osSetIntMask(1); - queue = D_800DC6B0; - gSoundChannelVolume[channel] = volume; - - while (queue != NULL) { - //This is almost definitely the wrong struct list, but it matches so I'm not going to complain - if ((((ALInstrument *) queue->allocList.next->prev)->priority & 0x3F) == channel) { - evt.type = 0x800; - evt.msg.spseq.seq = (void *) queue; - alEvtqPostEvent(&gAlSndPlayer->evtq, &evt, 0); - } - queue = (ALEventQueue *) queue->freeList.next; - } - - osSetIntMask(mask); -} diff --git a/src/unknown_003260.h b/src/unknown_003260.h deleted file mode 100644 index 94fb4919..00000000 --- a/src/unknown_003260.h +++ /dev/null @@ -1,137 +0,0 @@ -#ifndef _UNKNOWN_003260_H_ -#define _UNKNOWN_003260_H_ - -#include "types.h" -#include "macros.h" -#include "audio_internal.h" -#include "asset_enums.h" -#include "libultra_internal.h" -#include "sched.h" - -#define AL_SNDP_PLAY_EVT (1 << 0) -#define AL_SNDP_STOP_EVT (1 << 1) -#define AL_SNDP_PAN_EVT (1 << 2) -#define AL_SNDP_VOL_EVT (1 << 3) -#define AL_SNDP_PITCH_EVT (1 << 4) -#define AL_SNDP_API_EVT (1 << 5) -#define AL_SNDP_DECAY_EVT (1 << 6) -#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]; -} unk800DC6BC_40; //ALSoundState - -/* Unknown Size */ -typedef struct unk800DC6BC { - ALPlayer node; - ALEventQueue evtq; - ALEvent nextEvent; - ALSynth *drvr; - u32 unk3C; - unk800DC6BC_40 *unk40; - s32 soundChannelsMax; - s32 soundChannels; - s32 frameTime; - ALMicroTime nextDelta; - ALMicroTime curTime; -} unk800DC6BC; //ALSndPlayer - -typedef union { - ALEvent msg; - - struct{ - s16 type; - void* state; - u32 unk04; - }snd_event; - -}ALSndpEvent; - -typedef struct -{ - ALLink node; - u32 startAddr; - u32 lastFrame; - char *ptr; -} AMDMABuffer; - -/* Unknown Size */ -/*typedef struct unk800DC6B0 { - ALLink node; - ALLink_s * unk08; -} unk800DC6B0; -*/ - -typedef struct audioMgrConfig_s{ - u32 unk00; - u32 unk04; - u32 maxChannels; - ALHeap *hp; - u16 unk10; -} audioMgrConfig; - -typedef struct { - u8 initialized; - AMDMABuffer *firstUsed; - AMDMABuffer *firstFree; -} AMDMAState; - -extern u32 audFrameCt; -extern s32 D_800DC684; -extern s32 D_800DC688; -extern s32 D_800DC68C; -extern s32 gFunc80019808Checksum; -extern s32 gFunc80019808Length; -extern s32 D_800DC698; -extern s32 D_800DC69C; -extern s32 D_800DC6A0; -extern s32 D_800DC6A4; -extern s32 D_800DC6A8; -extern s32 D_800DC6AC; - -extern ALEventQueue *D_800DC6B0; -extern s32 D_800DC6B4; -extern unk800DC6BC_40* D_800DC6B8; -extern unk800DC6BC* gAlSndPlayer; - -extern s32 sfxVolumeSlider; -extern s32 D_800DC6C4; - -extern void thread4_audio(void*); -void *alHeapDBAlloc(u8 *file, s32 line, ALHeap *hp, s32 num, s32 size); //lib/src/al -void alEvtqNew(ALEventQueue *evtq, ALEventListItem *items, s32 itemCount); //lib/src/unknown_0C9C90.c -ALMicroTime alEvtqNextEvent(ALEventQueue *evtq, ALEvent *evt); //lib/src/unknown_0C9C90.c -void alSynAddPlayer(ALSynth *drvr, ALPlayer *client); //lib/src/unknown_0C9C90.c -void alEvtqPostEvent(ALEventQueue *evtq, ALEvent *evt, ALMicroTime delta); //lib/src/unknown_0C9C90.c Non Matching - -void audioStartThread(void); -void audioStopThread(void); -void set_sfx_volume_slider(u32 arg0); -s32 sfxGetVolumeSlider(void); -void set_sound_channel_count(s32 arg0); -void alSndPNew(audioMgrConfig *c); -void func_80004604(u8 *arg0, u8 arg1); -u8 func_8000461C(u8 *arg0); -void func_80004638(ALBank *bnk, s16 sndIndx, s32 arg2); -INCONSISTENT void func_8000488C(); -void func_800049D8(void); -void func_800049F8(s32 soundMask, s16 type, u32 volume); -u16 get_sound_channel_volume(u8 arg0); -ALDMAproc __amDmaNew(AMDMAState **state); -void set_sound_channel_volume(u8 arg0, u16 arg1); -void func_80002DF8(OSMesg mesg); - -// Non Matching -ALMicroTime _sndpVoiceHandler(void *node); -void func_80004668(ALBank *bnk, s16 sndIndx, u8, s32); -void audioNewThread(ALSynConfig *c, OSPri p, OSSched *arg2); -void func_800048D8(s32); -void func_80002C00(s32, OSMesg mesg); -void _handleEvent(unk800DC6BC *snd, ALSndpEvent *event); - -#endif diff --git a/src/unknown_003260_bss.c b/src/unknown_003260_bss.c deleted file mode 100644 index c6d3226d..00000000 --- a/src/unknown_003260_bss.c +++ /dev/null @@ -1,30 +0,0 @@ -/* The comment below is needed for this file to be picked up by generate_ld */ -/* RAM_POS: 0x80002660 */ - -#include "unknown_003260.h" -// This file is needed, since there is a bss reordering issue with D_80119BD0 and gAlSndPlayer - -OSSched *gAudioSched; -ALHeap *D_80115F94; -s32 D_80115F98[2]; -s32 D_80115FA0[3]; -OSThread audioThread; -OSMesgQueue gAudioMesgQueue; -OSMesg D_80116178[8]; -OSMesgQueue D_80116198; -OSMesg D_801161B0[8]; -ALGlobals ALGlobals_801161D0; -u64 audioStack[AUDIO_STACKSIZE/sizeof(u64)]; -AMDMAState dmaState; -AMDMABuffer dmaBuffs[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 *gSoundChannelVolume; diff --git a/src/unknown_008C40.c b/src/unknown_008C40.c index dd606636..9e763c40 100644 --- a/src/unknown_008C40.c +++ b/src/unknown_008C40.c @@ -10,7 +10,7 @@ #include "audio.h" #include "textures_sprites.h" #include "objects.h" -#include "unknown_003260.h" +#include "audiosfx.h" #include "unknown_0255E0.h" #include "math_util.h" diff --git a/tools/python/generate_assets.py b/tools/python/generate_assets.py index 33918e40..e1474164 100644 --- a/tools/python/generate_assets.py +++ b/tools/python/generate_assets.py @@ -43,7 +43,7 @@ class GenerateAssets: def generate_ucode_files(self): assetsUCodeText = '# This file was generated by generate_ld.py\n\n' assetsUCodeText += '.include "macros.inc"\n\n' - assetsUCodeText += self.generate_ucode_file('rspUnknownStart', 'ucode/ucode_unknown.bin') + assetsUCodeText += self.generate_ucode_file('aspMainTextStart', 'ucode/ucode_audio.bin') assetsUCodeText += self.generate_ucode_file('rspF3DDKRBootStart', 'ucode/ucode_boot.bin') assetsUCodeText += self.generate_ucode_file('rspF3DDKRDramStart', 'ucode/ucode_f3ddkr_dram.bin') assetsUCodeText += self.generate_ucode_file('rspF3DDKRFifoStart', 'ucode/ucode_f3ddkr_fifo.bin') @@ -54,7 +54,7 @@ class GenerateAssets: assetsUCodeData = '# This file was generated by generate_ld.py\n\n' assetsUCodeData += '.include "macros.inc"\n\n' - assetsUCodeData += self.generate_ucode_file('rspUnknownDataStart', 'ucode/data_unknown.bin') + assetsUCodeData += self.generate_ucode_file('aspMainDataStart', 'ucode/data_audio.bin') assetsUCodeData += self.generate_ucode_file('rspF3DDKRDataDramStart', 'ucode/data_f3ddkr_dram.bin') assetsUCodeData += self.generate_ucode_file('rspF3DDKRDataFifoStart', 'ucode/data_f3ddkr_fifo.bin') assetsUCodeData += self.generate_ucode_file('rspF3DDKRDataXbusStart', 'ucode/data_f3ddkr_xbus.bin')