diff --git a/include/functions.h b/include/functions.h index 03b8c394..dcdfcb39 100644 --- a/include/functions.h +++ b/include/functions.h @@ -3,6 +3,8 @@ #include "ultra64.h" +f32 __sinf(f32); + void func_80057FD0(void *, int); s32 func_8005A990(OSPiHandle *); diff --git a/include/global.h b/include/global.h index 967aede4..a137740e 100644 --- a/include/global.h +++ b/include/global.h @@ -2,6 +2,7 @@ #define _COMMON_H #include +#include typedef unsigned int uintptr_t; @@ -13,6 +14,7 @@ typedef unsigned int uintptr_t; #include "sections.h" #include "gfx.h" #include "color.h" +#include "sound.h" #include "math.h" typedef struct unk_D_86002F58_004_000_00C_028 { diff --git a/include/sound.h b/include/sound.h new file mode 100644 index 00000000..08457327 --- /dev/null +++ b/include/sound.h @@ -0,0 +1,17 @@ +#ifndef _SOUND_H +#define _SOUND_H + +#include +#include + +typedef struct SoundBank { + /* 0x00 */ char header_name[16]; // N64 PtrTablesV2\x0 + /* 0x10 */ u32 flags; + /* 0x14 */ char wbk_name[12]; + /* 0x20 */ s32 count; + /* 0x24 */ char* basenote; + /* 0x28 */ f32* detune; + /* 0x2C */ ALWaveTable** wave_list; +} SoundBank; // size = 0x30 + +#endif diff --git a/include/variables.h b/include/variables.h index 647510c0..ad41b2ae 100644 --- a/include/variables.h +++ b/include/variables.h @@ -116,7 +116,9 @@ extern struct Vec3s D_8006F05C; extern struct Vec3f D_8006F064; typedef struct unk_D_8006FF00 { - /* 0x00 */ char unk_00[0x10]; + /* 0x00 */ char unk_00[0x4]; + /* 0x04 */ char* name; + /* 0x08 */ char unk_08[0x8]; /* 0x10 */ s16 unk_10; /* 0x12 */ s16 unk_12; /* 0x14 */ char unk_14[0x8]; @@ -143,11 +145,6 @@ extern unk_D_800AC870* D_800AC870; extern Gfx D_8006F498[]; -extern f32 D_80077DD4; -extern f32 D_80077DD8; -extern f32 D_80077DDC; -extern f32 D_80077DE0; -extern s8 D_80077DE4; extern s32 D_80078E60; extern s32 D_80078E64; extern s32 D_80078E68; @@ -191,6 +188,6 @@ extern u8 D_87B000D0; extern u8 D_87B000D4; extern s32 D_800FC820; -extern s32 D_800FF9C0; +extern u8* D_800FF9C0; #endif diff --git a/linker_scripts/us/symbol_addrs.txt b/linker_scripts/us/symbol_addrs.txt index 9cd9b2c3..e06da2f2 100644 --- a/linker_scripts/us/symbol_addrs.txt +++ b/linker_scripts/us/symbol_addrs.txt @@ -271,3 +271,22 @@ CHORUS_PARAMS_N = 0x80079488; FLANGE_PARAMS_N = 0x800794B0; NULL_PARAMS_N = 0x800794D8; n_eqpower = 0x80078600; +frameSize = 0x800FCAC8; +curAcmdList = 0x80077DB8; +maxRSPCmds = 0x800FCAD0; +minFrameSize = 0x800FCAC4; +maxFrameSize = 0x800FCACC; +dmaBuffs = 0x800FCAF8; +dmaState = 0x800FCAB8; // size:0xC +__am = 0x800FC830; // size:0x288 +lastInfo = 0x80077DBC; +min_only_one = 0x80077DC0; +audFrameCt = 0x80077DB0; +dmaBufferLen = 0x800FCB04; +audDMAIOMesgBuf = 0x800FCAFC; +nextDMA = 0x80077DB4; +audDMAMessageBuf = 0x800FCB00; +rspbootTextStart = 0x80065FC0; +aspMainTextStart = 0x80067420; +aspMainDataStart = 0x8007EA70; +audDMAMessageQ = 0x800FCAE0; diff --git a/linker_scripts/us/symbol_addrs_code.txt b/linker_scripts/us/symbol_addrs_code.txt index e15a69a2..46d3aa1e 100644 --- a/linker_scripts/us/symbol_addrs_code.txt +++ b/linker_scripts/us/symbol_addrs_code.txt @@ -1257,11 +1257,11 @@ func_8003C2F8 = 0x8003C2F8; // type:func func_8003C35C = 0x8003C35C; // type:func func_8003C3A0 = 0x8003C3A0; // type:func func_8003C408 = 0x8003C408; // type:func -func_8003C540 = 0x8003C540; // type:func -func_8003C8DC = 0x8003C8DC; // type:func +amCreateAudioMgr = 0x8003C540; // type:func +__amDMA = 0x8003C8DC; // type:func func_8003CADC = 0x8003CADC; // type:func -func_8003D128 = 0x8003D128; // type:func -func_8003D160 = 0x8003D160; // type:func +__amDmaNew = 0x8003D128; // type:func +__clearAudioDMA = 0x8003D160; // type:func func_8003D264 = 0x8003D264; // type:func func_8003D2B8 = 0x8003D2B8; // type:func func_8003D32C = 0x8003D32C; // type:func diff --git a/src/19840.c b/src/19840.c index 7777f9a2..3d04b71d 100644 --- a/src/19840.c +++ b/src/19840.c @@ -1,5 +1,11 @@ -#include "global.h" #include "19840.h" +#include "src/18480.h" +#include "src/1C720.h" +#include "src/3FB0.h" +#include "src/dma.h" +#include "src/memmap.h" +#include "src/memory.h" +#include "src/util.h" #pragma GLOBAL_ASM("asm/us/nonmatchings/19840/func_80018C40.s") diff --git a/src/1CF30.c b/src/1CF30.c index 7aee1c55..4026a3cf 100644 --- a/src/1CF30.c +++ b/src/1CF30.c @@ -3,6 +3,7 @@ #include "include/string.h" #include "src/3FB0.h" #include "src/6A40.h" +#include "src/20470.h" #include "src/6BC0.h" #include "src/E890.h" #include "src/memory.h" @@ -10,7 +11,6 @@ #include "lib/ultralib/src/libc/xstdio.h" extern Gfx D_8006F4C0[]; -extern Gfx D_8006F610[]; extern Gfx D_8006F710[]; extern Gfx D_8006F750[]; extern Gfx D_8006F768[]; @@ -66,7 +66,7 @@ void func_8001C6AC(s16 arg0, s16 arg1, s16 arg2, s16 arg3, u8* arg4, s16 arg5, s func_8001C330(arg0, arg1, arg2, arg3, 0, 0, 0x400, 0x400, arg6); } -void func_8001C8C4(s16 arg0, s16 arg1, s16 arg2, s16 arg3, u32* arg4, s16 arg5, s32 arg6) { +void func_8001C8C4(s16 arg0, s16 arg1, s16 arg2, s16 arg3, u8* arg4, s16 arg5, s32 arg6) { gDPLoadTextureBlock(gDisplayListHead++, arg4, G_IM_FMT_RGBA, G_IM_SIZ_32b, arg5, arg3, 0, G_TX_NOMIRROR | G_TX_CLAMP, G_TX_NOMIRROR | G_TX_CLAMP, G_TX_NOMASK, G_TX_NOMASK, G_TX_NOLOD, G_TX_NOLOD); @@ -74,40 +74,40 @@ void func_8001C8C4(s16 arg0, s16 arg1, s16 arg2, s16 arg3, u32* arg4, s16 arg5, func_8001C330(arg0, arg1, arg2, arg3, 0, 0, 0x400, 0x400, arg6); } -void func_8001CADC(s16 arg0, s16 arg1, s16 arg2, s16 arg3, u32* arg4, s16 arg5, s32 arg6) { +void func_8001CADC(s16 arg0, s16 arg1, s16 arg2, s16 arg3, u8* arg4, s16 arg5, s32 arg6) { gDPLoadTextureBlock(gDisplayListHead++, arg4, G_IM_FMT_IA, G_IM_SIZ_8b, arg5, arg3, 0, G_TX_NOMIRROR | G_TX_CLAMP, G_TX_NOMIRROR | G_TX_CLAMP, G_TX_NOMASK, G_TX_NOMASK, G_TX_NOLOD, G_TX_NOLOD); func_8001C330(arg0, arg1, arg2, arg3, 0, 0, 0x400, 0x400, arg6); } -void func_8001CCF8(s16 arg0, s16 arg1, s16 arg2, s16 arg3, u32* arg4, s16 arg5, s32 arg6) { +void func_8001CCF8(s16 arg0, s16 arg1, s16 arg2, s16 arg3, u8* arg4, s16 arg5, s32 arg6) { gDPLoadTextureBlock(gDisplayListHead++, arg4, G_IM_FMT_IA, G_IM_SIZ_16b, arg5, arg3, 0, G_TX_NOMIRROR | G_TX_CLAMP, G_TX_NOMIRROR | G_TX_CLAMP, G_TX_NOMASK, G_TX_NOMASK, G_TX_NOLOD, G_TX_NOLOD); func_8001C330(arg0, arg1, arg2, arg3, 0, 0, 0x400, 0x400, arg6); } -void func_8001CF10(s16 arg0, s16 arg1, s16 arg2, s16 arg3, u32* arg4, s16 arg5, s32 arg6) { +void func_8001CF10(s16 arg0, s16 arg1, s16 arg2, s16 arg3, u8* arg4, s16 arg5, s32 arg6) { gDPLoadTextureBlock_4b(gDisplayListHead++, arg4, G_IM_FMT_I, arg5, arg3, 0, G_TX_NOMIRROR | G_TX_CLAMP, G_TX_NOMIRROR | G_TX_CLAMP, G_TX_NOMASK, G_TX_NOMASK, G_TX_NOLOD, G_TX_NOLOD); func_8001C330(arg0, arg1, arg2, arg3, 0, 0, 0x400, 0x400, arg6); } -void func_8001D12C(s16 arg0, s16 arg1, s16 arg2, s16 arg3, u32* arg4, s16 arg5, s32 arg6) { +void func_8001D12C(s16 arg0, s16 arg1, s16 arg2, s16 arg3, u8* arg4, s16 arg5, s32 arg6) { gDPLoadTextureBlock(gDisplayListHead++, arg4, G_IM_FMT_I, G_IM_SIZ_8b, arg5, arg3, 0, G_TX_NOMIRROR | G_TX_CLAMP, G_TX_NOMIRROR | G_TX_CLAMP, G_TX_NOMASK, G_TX_NOMASK, G_TX_NOLOD, G_TX_NOLOD); func_8001C330(arg0, arg1, arg2, arg3, 0, 0, 0x400, 0x400, arg6); } -void func_8001D348(s16 arg0, s16 arg1, s16 arg2, s16 arg3, u32* arg4, s16 arg5, s32 arg6) { +void func_8001D348(s16 arg0, s16 arg1, s16 arg2, s16 arg3, u8* arg4, s16 arg5, s32 arg6) { gDPLoadTextureBlock(gDisplayListHead++, arg4, G_IM_FMT_I, G_IM_SIZ_16b, arg5, arg3, 0, G_TX_NOMIRROR | G_TX_CLAMP, G_TX_NOMIRROR | G_TX_CLAMP, G_TX_NOMASK, G_TX_NOMASK, G_TX_NOLOD, G_TX_NOLOD); func_8001C330(arg0, arg1, arg2, arg3, 0, 0, 0x400, 0x400, arg6); } -void func_8001D560(s16 arg0, s16 arg1, s16 arg2, s16 arg3, u32* arg4, u32* arg5, s16 arg6, s32 arg7) { +void func_8001D560(s16 arg0, s16 arg1, s16 arg2, s16 arg3, u8* arg4, u8* arg5, s16 arg6, s32 arg7) { gDPLoadTextureBlock(gDisplayListHead++, arg4, G_IM_FMT_RGBA, G_IM_SIZ_16b, arg6, arg3, 0, G_TX_NOMIRROR | G_TX_CLAMP, G_TX_NOMIRROR | G_TX_CLAMP, G_TX_NOMASK, G_TX_NOMASK, G_TX_NOLOD, G_TX_NOLOD); @@ -315,9 +315,9 @@ u8 func_8001E730(u16 arg0) { u8 var_v1 = 0; if ((arg0 >= 0x20) && (arg0 < 0x80)) { - var_v1 = ((u8*)D_8006F630)[arg0 + 0]; + var_v1 = ((u8*)D_8006F630)[arg0]; } else if ((arg0 >= 0xA0) && (arg0 < 0x100)) { - var_v1 = ((u8*)D_8006F610)[arg0 + 0]; + var_v1 = ((u8*)D_8006F608)[sizeof(Gfx) + arg0]; } return var_v1; diff --git a/src/1CF30.h b/src/1CF30.h index b4f3bf82..ca9a7cb5 100644 --- a/src/1CF30.h +++ b/src/1CF30.h @@ -8,13 +8,13 @@ void func_8001C4E4(s32 arg0, s32 arg1, s32 arg2, s32 arg3, s32 arg4, s32 arg5, s void func_8001C560(s16 arg0, s16 arg1, s16 arg2, s16 arg3, u8 arg4, u8 arg5, u8 arg6); void func_8001C604(s16 arg0, s16 arg1, s16 arg2, s16 arg3, u8 arg4, u8 arg5, u8 arg6, u8 arg7); void func_8001C6AC(s16 arg0, s16 arg1, s16 arg2, s16 arg3, u8* arg4, s16 arg5, s32 arg6); -void func_8001C8C4(s16 arg0, s16 arg1, s16 arg2, s16 arg3, u32* arg4, s16 arg5, s32 arg6); -void func_8001CADC(s16 arg0, s16 arg1, s16 arg2, s16 arg3, u32* arg4, s16 arg5, s32 arg6); -void func_8001CCF8(s16 arg0, s16 arg1, s16 arg2, s16 arg3, u32* arg4, s16 arg5, s32 arg6); -void func_8001CF10(s16 arg0, s16 arg1, s16 arg2, s16 arg3, u32* arg4, s16 arg5, s32 arg6); -void func_8001D12C(s16 arg0, s16 arg1, s16 arg2, s16 arg3, u32* arg4, s16 arg5, s32 arg6); -void func_8001D348(s16 arg0, s16 arg1, s16 arg2, s16 arg3, u32* arg4, s16 arg5, s32 arg6); -void func_8001D560(s16 arg0, s16 arg1, s16 arg2, s16 arg3, u32* arg4, u32* arg5, s16 arg6, s32 arg7); +void func_8001C8C4(s16 arg0, s16 arg1, s16 arg2, s16 arg3, u8* arg4, s16 arg5, s32 arg6); +void func_8001CADC(s16 arg0, s16 arg1, s16 arg2, s16 arg3, u8* arg4, s16 arg5, s32 arg6); +void func_8001CCF8(s16 arg0, s16 arg1, s16 arg2, s16 arg3, u8* arg4, s16 arg5, s32 arg6); +void func_8001CF10(s16 arg0, s16 arg1, s16 arg2, s16 arg3, u8* arg4, s16 arg5, s32 arg6); +void func_8001D12C(s16 arg0, s16 arg1, s16 arg2, s16 arg3, u8* arg4, s16 arg5, s32 arg6); +void func_8001D348(s16 arg0, s16 arg1, s16 arg2, s16 arg3, u8* arg4, s16 arg5, s32 arg6); +void func_8001D560(s16 arg0, s16 arg1, s16 arg2, s16 arg3, u8* arg4, u8* arg5, s16 arg6, s32 arg7); void func_8001D924(u8* arg0); void func_8001DBDC(u32 arg0, s16 arg1, s16 arg2, s16 arg3, s16 arg4); void func_8001E000(s16 arg0, s16 arg1, s16 arg2, f32 arg3, Vtx* arg4, u32 arg5); diff --git a/src/20470.c b/src/20470.c index 4038b17f..de957a43 100644 --- a/src/20470.c +++ b/src/20470.c @@ -1,36 +1,517 @@ -#include "global.h" #include "20470.h" +#include "src/1CF30.h" +#include "src/2E110.h" +#include "src/6A40.h" +#include "src/6BC0.h" +#include "src/hal_libc.h" +#include "src/stage_loader.h" -#pragma GLOBAL_ASM("asm/us/nonmatchings/20470/func_8001F870.s") +extern u8 D_10025D0[]; +extern u8 D_1002650[]; +extern u8 D_10026D0[]; +extern u8 D_1002750[]; +extern u8 D_10027D0[]; +extern u8 D_1002850[]; +extern u8 D_10028D0[]; +extern u8 D_1002950[]; +extern u8 D_10029D0[]; +extern u8 D_1002A50[]; +extern u8 D_1002AD0[]; +extern u8 D_1002B50[]; +extern u8 D_1002BD0[]; +extern u8 D_1002C50[]; +extern u8 D_1002CD0[]; +extern u8 D_1002D50[]; +extern u8 D_1002DD0[]; +extern u8 D_1002E50[]; +extern u8 D_1002ED0[]; +extern u8 D_1002F50[]; +extern u8 D_1002FD0[]; +extern u8 D_1003050[]; +extern u8 D_10030D0[]; +extern u8 D_1003150[]; +extern u8 D_10031D0[]; +extern u8 D_1003750[]; +extern u8 D_1003890[]; +extern u8 D_1003930[]; +extern u8 D_10039F0[]; +extern u8 D_1003AB0[]; +extern u8 D_1003B70[]; +extern u8 D_1003C30[]; +extern u8 D_1003CF0[]; +extern u8 D_1003DB0[]; +extern u8 D_1003E50[]; +extern u8 D_1003EA0[]; +extern u8 D_1003EC8[]; +extern u8 D_1003EF0[]; +extern u8 D_2004000[]; +extern u8 D_2004320[]; -#pragma GLOBAL_ASM("asm/us/nonmatchings/20470/func_8001F9D4.s") +Gfx D_8006F470[] = { + gsDPPipeSync(), + gsDPSetCycleType(G_CYC_1CYCLE), + gsDPSetRenderMode(G_RM_AA_OPA_SURF, G_RM_AA_OPA_SURF2), + gsDPSetCombineMode(G_CC_PRIMITIVE, G_CC_PRIMITIVE), + gsSPEndDisplayList(), +}; -#pragma GLOBAL_ASM("asm/us/nonmatchings/20470/func_8001FB40.s") +Gfx D_8006F498[] = { + gsDPPipeSync(), + gsDPSetCycleType(G_CYC_1CYCLE), + gsDPSetRenderMode(G_RM_AA_XLU_SURF, G_RM_AA_XLU_SURF2), + gsDPSetCombineMode(G_CC_PRIMITIVE, G_CC_PRIMITIVE), + gsSPEndDisplayList(), +}; -#pragma GLOBAL_ASM("asm/us/nonmatchings/20470/func_8001FCAC.s") +Gfx D_8006F4C0[] = { + gsDPPipeSync(), + gsDPSetCycleType(G_CYC_FILL), + gsDPSetRenderMode(G_RM_NOOP, G_RM_NOOP2), + gsSPEndDisplayList(), +}; -#pragma GLOBAL_ASM("asm/us/nonmatchings/20470/func_8001FE18.s") +Gfx D_8006F4E0[] = { + gsDPPipeSync(), + gsDPSetCycleType(G_CYC_COPY), + gsDPSetTexturePersp(G_TP_NONE), + gsDPSetAlphaCompare(G_AC_THRESHOLD), + gsDPSetRenderMode(G_RM_NOOP, G_RM_NOOP2), + gsDPSetCombineMode(G_CC_DECALRGBA, G_CC_DECALRGBA), + gsSPEndDisplayList(), +}; -#pragma GLOBAL_ASM("asm/us/nonmatchings/20470/func_8001FF68.s") +Gfx D_8006F518[] = { + gsDPPipeSync(), + gsDPSetCycleType(G_CYC_1CYCLE), + gsDPSetTexturePersp(G_TP_NONE), + gsDPSetCombineLERP(TEXEL0, 0, ENVIRONMENT, 0, TEXEL0, 0, ENVIRONMENT, 0, TEXEL0, 0, ENVIRONMENT, 0, TEXEL0, 0, + ENVIRONMENT, 0), + gsDPSetRenderMode(G_RM_XLU_SURF, G_RM_XLU_SURF2), + gsDPSetEnvColor(255, 255, 255, 255), + gsSPClearGeometryMode(G_ZBUFFER | G_LIGHTING), + gsSPEndDisplayList(), +}; -#pragma GLOBAL_ASM("asm/us/nonmatchings/20470/func_800200B8.s") +Gfx D_8006F558[] = { + gsDPPipeSync(), + gsDPSetCycleType(G_CYC_1CYCLE), + gsDPSetTexturePersp(G_TP_NONE), + gsDPSetCombineLERP(ENVIRONMENT, PRIMITIVE, TEXEL0, PRIMITIVE, TEXEL0, 0, ENVIRONMENT, 0, ENVIRONMENT, PRIMITIVE, + TEXEL0, PRIMITIVE, TEXEL0, 0, ENVIRONMENT, 0), + gsDPSetRenderMode(G_RM_XLU_SURF, G_RM_XLU_SURF2), + gsDPSetEnvColor(255, 255, 255, 255), + gsDPSetPrimColor(0, 0, 0, 0, 0, 255), + gsSPClearGeometryMode(G_ZBUFFER | G_LIGHTING), + gsSPEndDisplayList(), +}; -#pragma GLOBAL_ASM("asm/us/nonmatchings/20470/func_80020460.s") +Gfx D_8006F5A0[] = { + gsDPPipeSync(), + gsDPSetCycleType(G_CYC_2CYCLE), + gsDPSetTexturePersp(G_TP_NONE), + gsDPSetRenderMode(G_RM_PASS, G_RM_XLU_SURF2), + gsDPSetCombineLERP(TEXEL0, 0, ENVIRONMENT, 0, TEXEL1, 0, ENVIRONMENT, 0, 0, 0, 0, COMBINED, 0, 0, 0, COMBINED), + gsDPSetEnvColor(255, 255, 255, 255), + gsSPEndDisplayList(), +}; -#pragma GLOBAL_ASM("asm/us/nonmatchings/20470/func_8002053C.s") +Gfx D_8006F5D8[] = { + gsDPPipeSync(), + gsDPSetCycleType(G_CYC_2CYCLE), + gsDPSetRenderMode(G_RM_PASS, G_RM_XLU_SURF2), + gsDPSetCombineLERP(ENVIRONMENT, PRIMITIVE, TEXEL0, PRIMITIVE, TEXEL0, 0, ENVIRONMENT, 0, COMBINED, 0, TEXEL1, 0, 0, + 0, 0, COMBINED), + gsDPSetPrimColor(0, 0, 255, 255, 255, 255), + gsSPEndDisplayList(), +}; -#pragma GLOBAL_ASM("asm/us/nonmatchings/20470/func_80020678.s") +Gfx D_8006F608[] = { + gsDPPipeSync(), + gsDPSetCycleType(G_CYC_1CYCLE), + gsDPSetCombineLERP(TEXEL0, 0, ENVIRONMENT, 0, TEXEL0, 0, ENVIRONMENT, 0, TEXEL0, 0, ENVIRONMENT, 0, TEXEL0, 0, + ENVIRONMENT, 0), + gsDPSetRenderMode(G_RM_XLU_SURF, G_RM_XLU_SURF2), + gsSPEndDisplayList(), +}; -#pragma GLOBAL_ASM("asm/us/nonmatchings/20470/func_80020754.s") +Gfx D_8006F630[] = { + gsDPPipeSync(), + gsDPSetTexturePersp(G_TP_PERSP), + gsDPSetAlphaCompare(G_AC_NONE), + gsSPEndDisplayList(), +}; -#pragma GLOBAL_ASM("asm/us/nonmatchings/20470/func_800207FC.s") +static u8 D_8006F650[] = { + 0x00, 0x34, 0x35, 0x0F, 0x00, 0x06, 0x0D, 0x37, 0x03, 0x04, 0x38, 0x39, 0x3A, 0x3B, 0x3C, 0x3D, 0x10, 0x11, + 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x3E, 0x42, 0x00, 0x3F, 0x00, 0x40, 0x00, 0x1A, 0x1B, 0x1C, + 0x1D, 0x1E, 0x1F, 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2A, 0x2B, 0x2C, 0x2D, 0x2E, + 0x2F, 0x30, 0x31, 0x32, 0x33, 0x07, 0x00, 0x08, 0x00, 0x00, 0x00, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4A, 0x4B, + 0x4C, 0x4D, 0x4E, 0x4F, 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5A, 0x5B, 0x5C, 0x5D, + 0x5E, 0x00, 0x00, 0x00, 0x0E, 0x00, 0x00, 0x8F, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02, 0x8D, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x8C, 0x00, 0x43, 0x44, + 0x41, 0x8E, 0x67, 0x66, 0x68, 0x00, 0x5F, 0x00, 0x00, 0x69, 0x6B, 0x6A, 0x6C, 0x6D, 0x7F, 0x7E, 0x80, 0x6F, + 0x00, 0x81, 0x83, 0x82, 0x6E, 0x00, 0x60, 0x36, 0x00, 0x70, 0x84, 0x71, 0x61, 0x00, 0x00, 0x65, 0x73, 0x72, + 0x74, 0x00, 0x62, 0x00, 0x00, 0x75, 0x77, 0x76, 0x78, 0x79, 0x86, 0x85, 0x87, 0x7B, 0x00, 0x88, 0x8A, 0x89, + 0x7A, 0x00, 0x63, 0x00, 0x00, 0x7C, 0x8B, 0x7D, 0x64, 0x00, 0x00, 0x00, +}; -#pragma GLOBAL_ASM("asm/us/nonmatchings/20470/func_80020928.s") +Gfx D_8006F710[] = { + gsDPPipeSync(), + gsDPSetCycleType(G_CYC_1CYCLE), + gsSPClearGeometryMode(G_ZBUFFER), + gsDPSetTexturePersp(G_TP_NONE), + gsDPSetCombineLERP(TEXEL0, 0, ENVIRONMENT, 0, TEXEL0, 0, ENVIRONMENT, 0, TEXEL0, 0, ENVIRONMENT, 0, TEXEL0, 0, + ENVIRONMENT, 0), + gsDPSetRenderMode(G_RM_XLU_SURF, G_RM_XLU_SURF2), + gsDPSetEnvColor(255, 255, 255, 255), + gsSPEndDisplayList(), +}; -#pragma GLOBAL_ASM("asm/us/nonmatchings/20470/func_800209B4.s") +Gfx D_8006F750[] = { + gsDPPipeSync(), + gsDPSetTexturePersp(G_TP_PERSP), + gsSPEndDisplayList(), +}; -#pragma GLOBAL_ASM("asm/us/nonmatchings/20470/func_80020B88.s") +Gfx D_8006F768[] = { + gsDPPipeSync(), + gsDPSetCycleType(G_CYC_2CYCLE), + gsDPSetRenderMode(G_RM_PASS, G_RM_XLU_SURF2), + gsDPSetCombineLERP(ENVIRONMENT, PRIMITIVE, TEXEL1, PRIMITIVE, 0, 0, 0, 0, COMBINED, 0, TEXEL1, 0, TEXEL1, 0, + ENVIRONMENT, 0), + gsDPSetPrimColor(0, 0, 255, 255, 255, 255), + gsSPEndDisplayList(), +}; -#pragma GLOBAL_ASM("asm/us/nonmatchings/20470/func_80021270.s") +Gfx D_8006F798[] = { + gsDPPipeSync(), + gsDPSetCycleType(G_CYC_1CYCLE), + gsDPSetCombineLERP(TEXEL0, 0, ENVIRONMENT, 0, TEXEL0, 0, ENVIRONMENT, 0, TEXEL0, 0, ENVIRONMENT, 0, TEXEL0, 0, + ENVIRONMENT, 0), + gsDPSetRenderMode(G_RM_XLU_SURF, G_RM_XLU_SURF2), + gsSPEndDisplayList(), +}; -#pragma GLOBAL_ASM("asm/us/nonmatchings/20470/func_80021920.s") +static s32 pad_D_8006F7C0[] = { 0, 0, 0, 0 }; + +void func_8001F870(s32 arg0, s32 arg1, s32 arg2, s32 arg3, u8* arg4) { + s32 sp34 = (arg2 < 9) ? 0x400 : 0; + s32 sp30 = (arg3 < 9) ? 0x400 : 0; + + gDPLoadTextureBlock(gDisplayListHead++, arg4, G_IM_FMT_RGBA, G_IM_SIZ_16b, 8, 8, 0, G_TX_NOMIRROR | G_TX_CLAMP, + G_TX_NOMIRROR | G_TX_CLAMP, G_TX_NOMASK, G_TX_NOMASK, G_TX_NOLOD, G_TX_NOLOD); + + func_8001C330(arg0, arg1, arg2, arg3, 0, 0, sp34, sp30, 0); +} + +void func_8001F9D4(s32 arg0, s32 arg1, s32 arg2, s32 arg3) { + func_8001F870(arg0, arg1, 8, 8, D_10027D0); + func_8001F870(arg0, (arg1 + arg3) - 8, 8, 8, D_1002850); + func_8001F870((arg0 + arg2) - 8, (arg1 + arg3) - 8, 8, 8, D_10028D0); + func_8001F870((arg0 + arg2) - 8, arg1, 8, 8, D_1002950); + + if (arg2 > 16) { + func_8001F870(arg0 + 8, arg1, arg2 - 0x10, 8, D_10025D0); + func_8001F870(arg0 + 8, (arg1 + arg3) - 8, arg2 - 0x10, 8, D_1002650); + } + + if (arg3 > 16) { + func_8001F870(arg0, arg1 + 8, 8, arg3 - 0x10, D_10026D0); + func_8001F870((arg0 + arg2) - 8, arg1 + 8, 8, arg3 - 0x10, D_1002750); + } +} + +void func_8001FB40(s32 arg0, s32 arg1, s32 arg2, s32 arg3) { + func_8001F870(arg0, arg1, 8, 8, D_1002BD0); + func_8001F870(arg0, (arg1 + arg3) - 8, 8, 8, D_1002C50); + func_8001F870((arg0 + arg2) - 8, (arg1 + arg3) - 8, 8, 8, D_1002CD0); + func_8001F870((arg0 + arg2) - 8, arg1, 8, 8, D_1002D50); + + if (arg2 > 16) { + func_8001F870(arg0 + 8, arg1, arg2 - 0x10, 8, D_10029D0); + func_8001F870(arg0 + 8, (arg1 + arg3) - 8, arg2 - 0x10, 8, D_1002A50); + } + + if (arg3 > 16) { + func_8001F870(arg0, arg1 + 8, 8, arg3 - 0x10, D_1002AD0); + func_8001F870((arg0 + arg2) - 8, arg1 + 8, 8, arg3 - 0x10, D_1002B50); + } +} + +void func_8001FCAC(s32 arg0, s32 arg1, s32 arg2, s32 arg3) { + func_8001F870(arg0, arg1, 8, 8, D_1002FD0); + func_8001F870(arg0, (arg1 + arg3) - 8, 8, 8, D_1003050); + func_8001F870((arg0 + arg2) - 8, (arg1 + arg3) - 8, 8, 8, D_10030D0); + func_8001F870((arg0 + arg2) - 8, arg1, 8, 8, D_1003150); + + if (arg2 > 16) { + func_8001F870(arg0 + 8, arg1, arg2 - 0x10, 8, D_1002DD0); + func_8001F870(arg0 + 8, (arg1 + arg3) - 8, arg2 - 0x10, 8, D_1002E50); + } + + if (arg3 > 16) { + func_8001F870(arg0, arg1 + 8, 8, arg3 - 0x10, D_1002ED0); + func_8001F870((arg0 + arg2) - 8, arg1 + 8, 8, arg3 - 0x10, D_1002F50); + } +} + +void func_8001FE18(s32 arg0, s32 arg1, s32 arg2, s32 arg3, u16 arg4) { + gSPDisplayList(gDisplayListHead++, D_8006F4C0); + gDPSetFillColor(gDisplayListHead++, (arg4 << 0x10) | arg4); + + if (func_80007A58() != 0) { + gDPFillRectangle(gDisplayListHead++, arg0 + 7, arg1 + 7, (arg0 + arg2) - 8, (arg1 + arg3) - 8); + } else { + gDPFillRectangle(gDisplayListHead++, arg0 + 3, arg1 + 3, (arg0 + arg2) - 4, (arg1 + arg3) - 4); + } +} + +void func_8001FF68(s32 arg0, s32 arg1, s32 arg2, s32 arg3, u16 arg4) { + gSPDisplayList(gDisplayListHead++, D_8006F4C0); + gDPSetFillColor(gDisplayListHead++, (arg4 << 0x10) | arg4); + + if (func_80007A58() != 0) { + gDPFillRectangle(gDisplayListHead++, arg0 + 5, arg1 + 5, (arg0 + arg2) - 6, (arg1 + arg3) - 6); + } else { + gDPFillRectangle(gDisplayListHead++, arg0 + 3, arg1 + 3, (arg0 + arg2) - 4, (arg1 + arg3) - 4); + } +} + +void func_800200B8(s32 arg0, s32 arg1, s32 arg2, s32 arg3, Color_RGB8* arg4, Color_RGB8* arg5) { + Vtx* temp_s2; + unk_D_80068BB0* temp_s1; + Mtx* sp7C; + Vp* sp78; + + temp_s1 = func_8000648C(); + temp_s2 = func_80005F5C(sizeof(Vtx) * 4); + sp7C = func_80005F5C(sizeof(Mtx) * 1); + sp78 = func_80005F5C(sizeof(Vp) * 1); + + func_8001E6E8(sp78, temp_s1->width, temp_s1->height); + + gSPViewport(gDisplayListHead++, (u32)sp78 & 0x1FFFFFFF); + + guOrtho(sp7C, 0.5f, temp_s1->width - 0.5f, temp_s1->height - 0.5f, 0.5f, -2.0f, 2.0f, 1.0f); + func_8001E680(&temp_s2[0], arg0, arg1, -1, 0, 0, arg4->r, arg4->g, arg4->b, 0xFF); + func_8001E680(&temp_s2[1], arg0 + arg2, arg1, -1, 0, 0, arg4->r, arg4->g, arg4->b, 0xFF); + func_8001E680(&temp_s2[2], arg0, arg1 + arg3, -1, 0, 0, arg5->r, arg5->g, arg5->b, 0xFF); + func_8001E680(&temp_s2[3], arg0 + arg2, arg1 + arg3, -1, 0, 0, arg5->r, arg5->g, arg5->b, 0xFF); + + gDPPipeSync(gDisplayListHead++); + + gDPSetCycleType(gDisplayListHead++, G_CYC_1CYCLE); + gSPClearGeometryMode(gDisplayListHead++, G_ZBUFFER | G_LIGHTING); + gDPSetCombineMode(gDisplayListHead++, G_CC_SHADE, G_CC_SHADE); + gDPSetRenderMode(gDisplayListHead++, G_RM_OPA_SURF, G_RM_OPA_SURF2); + gSPPerspNormalize(gDisplayListHead++, 0xFFFF); + + gSPMatrix(gDisplayListHead++, (u32)sp7C & 0x1FFFFFFF, G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_PROJECTION); + gSPMatrix(gDisplayListHead++, (u32)&D_8006F010 & 0x1FFFFFFF, G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW); + + gSPVertex(gDisplayListHead++, (u32)temp_s2 & 0x1FFFFFFF, 4, 0); + gSP2Triangles(gDisplayListHead++, 0, 2, 3, 0, 0, 3, 1, 0); +} + +void func_80020460(s32 arg0, s32 arg1, s32 arg2, s32 arg3, u16 arg4) { + gSPDisplayList(gDisplayListHead++, D_8006F518); + + if (func_80007A58() != 0) { + func_8001F9D4(arg0, arg1, arg2, arg3); + } else { + func_8001FCAC(arg0, arg1, arg2, arg3); + } + + if ((arg2 >= 0xF) && (arg3 >= 0xF)) { + func_8001FE18(arg0, arg1, arg2, arg3, arg4); + } + + gSPDisplayList(gDisplayListHead++, D_8006F630); +} + +void func_8002053C(s32 arg0, s32 arg1, s32 arg2, s32 arg3, Color_RGB8* arg4, Color_RGB8* arg5) { + if ((arg2 >= 0xF) && (arg3 >= 0xF)) { + if (func_80007A58() != 0) { + func_800200B8(arg0 + 6, arg1 + 6, arg2 - 0xC, arg3 - 0xC, arg4, arg5); + } else { + func_800200B8(arg0 + 2, arg1 + 2, arg2 - 4, arg3 - 4, arg4, arg5); + } + } + + gSPDisplayList(gDisplayListHead++, D_8006F518); + + if (func_80007A58() != 0) { + func_8001F9D4(arg0, arg1, arg2, arg3); + } else { + func_8001FCAC(arg0, arg1, arg2, arg3); + } + + gSPDisplayList(gDisplayListHead++, D_8006F630); +} + +void func_80020678(s32 arg0, s32 arg1, s32 arg2, s32 arg3, u16 arg4) { + gSPDisplayList(gDisplayListHead++, D_8006F518); + + if (func_80007A58() != 0) { + func_8001FB40(arg0, arg1, arg2, arg3); + } else { + func_8001FCAC(arg0, arg1, arg2, arg3); + } + + if ((arg2 >= 0xF) && (arg3 >= 0xF)) { + func_8001FF68(arg0, arg1, arg2, arg3, arg4); + } + + gSPDisplayList(gDisplayListHead++, D_8006F630); +} + +void func_80020754(s32 arg0, s32 arg1, s32 arg2, s32 arg3) { + gSPDisplayList(gDisplayListHead++, D_8006F518); + + if (func_80007A58() != 0) { + func_8001F9D4(arg0, arg1, arg2, arg3); + } else { + func_8001FCAC(arg0, arg1, arg2, arg3); + } + + gSPDisplayList(gDisplayListHead++, D_8006F630); +} + +void func_800207FC(s32 arg0, s32 arg1) { + if (func_80007A58() != 0) { + gSPDisplayList(gDisplayListHead++, D_8006F4E0); + func_8001C6AC(arg0, arg1, 0x20, 0x16, D_10031D0, 0x20, 0x200000); + } else { + gSPDisplayList(gDisplayListHead++, D_8006F5A0); + func_8001D560(arg0, arg1, 0xC, 0xA, D_1003750, D_1003890, 0x10, 0x100000); + } + + gSPDisplayList(gDisplayListHead++, D_8006F630); +} + +void func_80020928(s16 arg0, s16 arg1) { + static s16 D_8006F7D0 = 0; + + if (D_8006F7D0 < 6) { + arg0 += D_8006F7D0; + } else { + arg0 = (arg0 - D_8006F7D0) + 0xC; + } + func_800207FC(arg0, arg1); + D_8006F7D0 = (D_8006F7D0 + 1) % 12; +} + +void func_800209B4(s32 arg0, s32 arg1, s32 arg2) { + u8* var_t4; + + if (arg2 != 0) { + var_t4 = D_2004320; + } else { + var_t4 = D_2004000; + } + + gSPDisplayList(gDisplayListHead++, D_8006F4E0); + gDPLoadTextureBlock(gDisplayListHead++, var_t4, G_IM_FMT_RGBA, G_IM_SIZ_16b, 20, 20, 0, G_TX_NOMIRROR | G_TX_CLAMP, + G_TX_NOMIRROR | G_TX_CLAMP, G_TX_NOMASK, G_TX_NOMASK, G_TX_NOLOD, G_TX_NOLOD); + gSPTextureRectangle(gDisplayListHead++, arg0 << 2, arg1 << 2, (arg0 + 0x13) << 2, (arg1 + 0x13) << 2, + G_TX_RENDERTILE, 0, 0, 0x1000, 0x0400); + gSPDisplayList(gDisplayListHead++, D_8006F630); +} + +void func_80020B88(s32 arg0, s32 arg1, s32 arg2, s32 arg3, s32 arg4) { + u8* spDC; + s32 spD8 = arg2 - 4; + s32 temp_lo = ((arg4 - arg3) * (arg2 - 4)) / arg4; + s32 sp1C = (arg2 - temp_lo) - 4; + + if ((arg3 * 0x30) < (arg4 * 0xA)) { + spDC = D_1003CF0; + } else if ((arg3 * 0x30) < (arg4 * 0x1B)) { + spDC = D_1003C30; + } else { + spDC = D_1003B70; + } + + gSPDisplayList(gDisplayListHead++, D_8006F4E0); + + gDPLoadTextureBlock(gDisplayListHead++, D_1003930, G_IM_FMT_RGBA, G_IM_SIZ_16b, 8, 12, 0, + G_TX_NOMIRROR | G_TX_CLAMP, G_TX_NOMIRROR | G_TX_CLAMP, G_TX_NOMASK, G_TX_NOMASK, G_TX_NOLOD, + G_TX_NOLOD); + gSPTextureRectangle(gDisplayListHead++, arg0 << 2, arg1 << 2, (arg0 + 1) << 2, (arg1 + 0xB) << 2, G_TX_RENDERTILE, + 0, 0, 0x1000, 0x0400); + + gDPLoadTextureBlock(gDisplayListHead++, D_10039F0, G_IM_FMT_RGBA, G_IM_SIZ_16b, 8, 12, 0, + G_TX_NOMIRROR | G_TX_CLAMP, G_TX_NOMIRROR | G_TX_CLAMP, G_TX_NOMASK, G_TX_NOMASK, G_TX_NOLOD, + G_TX_NOLOD); + gSPTextureRectangle(gDisplayListHead++, ((arg0 + spD8) + 2) << 2, arg1 << 2, ((arg0 + spD8) + 3) << 2, + (arg1 + 0xB) << 2, G_TX_RENDERTILE, 0, 0, 0x1000, 0x0400); + + if (sp1C > 0) { + gDPLoadTextureBlock(gDisplayListHead++, spDC, G_IM_FMT_RGBA, G_IM_SIZ_16b, 8, 12, 0, G_TX_NOMIRROR | G_TX_CLAMP, + G_TX_NOMIRROR | G_TX_CLAMP, G_TX_NOMASK, G_TX_NOMASK, G_TX_NOLOD, G_TX_NOLOD); + gSPTextureRectangle(gDisplayListHead++, (arg0 + 2) << 2, arg1 << 2, (arg0 + sp1C + 1) << 2, (arg1 + 0xB) << 2, + G_TX_RENDERTILE, 0, 0, 0, 0x0400); + } + + if (temp_lo > 0) { + gDPLoadTextureBlock(gDisplayListHead++, D_1003AB0, G_IM_FMT_RGBA, G_IM_SIZ_16b, 8, 12, 0, + G_TX_NOMIRROR | G_TX_CLAMP, G_TX_NOMIRROR | G_TX_CLAMP, G_TX_NOMASK, G_TX_NOMASK, + G_TX_NOLOD, G_TX_NOLOD); + gSPTextureRectangle(gDisplayListHead++, ((arg0 + sp1C) + 2) << 2, arg1 << 2, ((arg0 + sp1C) + temp_lo + 1) << 2, + (arg1 + 0xB) << 2, G_TX_RENDERTILE, 0, 0, 0, 0x0400); + } + + gSPDisplayList(gDisplayListHead++, D_8006F630); +} + +void func_80021270(s32 arg0, s32 arg1, s32 arg2, s32 arg3) { + u8* spCC; + s32 temp_lo = ((arg3 - arg2) * 0x30) / arg3; + s32 sp14 = 0x30 - temp_lo; + + if ((arg2 * 0x30) < (arg3 * 0xA)) { + spCC = D_1003EF0; + } else if ((arg2 * 0x30) < (arg3 * 0x1B)) { + spCC = D_1003EC8; + } else { + spCC = D_1003EA0; + } + + gSPDisplayList(gDisplayListHead++, D_8006F518); + + gDPLoadTextureBlock(gDisplayListHead++, D_1003DB0, G_IM_FMT_RGBA, G_IM_SIZ_16b, 16, 5, 0, + G_TX_NOMIRROR | G_TX_CLAMP, G_TX_NOMIRROR | G_TX_CLAMP, G_TX_NOMASK, G_TX_NOMASK, G_TX_NOLOD, + G_TX_NOLOD); + gSPTextureRectangle(gDisplayListHead++, arg0 << 2, arg1 << 2, (arg0 + 0x10) << 2, (arg1 + 5) << 2, G_TX_RENDERTILE, + 0, 0, 0x0400, 0x0400); + gDPLoadTextureBlock(gDisplayListHead++, D_1003E50, G_IM_FMT_RGBA, G_IM_SIZ_16b, 4, 5, 0, G_TX_NOMIRROR | G_TX_CLAMP, + G_TX_NOMIRROR | G_TX_CLAMP, G_TX_NOMASK, G_TX_NOMASK, G_TX_NOLOD, G_TX_NOLOD); + gSPTextureRectangle(gDisplayListHead++, (arg0 + 0x40) << 2, arg1 << 2, (arg0 + 0x41) << 2, (arg1 + 5) << 2, + G_TX_RENDERTILE, 0, 0, 0x0400, 0x0400); + + if (sp14 > 0) { + gDPLoadTextureBlock(gDisplayListHead++, spCC, G_IM_FMT_RGBA, G_IM_SIZ_16b, 4, 5, 0, G_TX_NOMIRROR | G_TX_CLAMP, + G_TX_NOMIRROR | G_TX_CLAMP, G_TX_NOMASK, G_TX_NOMASK, G_TX_NOLOD, G_TX_NOLOD); + gSPTextureRectangle(gDisplayListHead++, (arg0 + 0x10) << 2, arg1 << 2, (arg0 + sp14 + 0x10) << 2, + (arg1 + 5) << 2, G_TX_RENDERTILE, 0, 0, 0, 0x0400); + } + + if (temp_lo > 0) { + gDPLoadTextureBlock(gDisplayListHead++, D_1003E78, G_IM_FMT_RGBA, G_IM_SIZ_16b, 4, 5, 0, + G_TX_NOMIRROR | G_TX_CLAMP, G_TX_NOMIRROR | G_TX_CLAMP, G_TX_NOMASK, G_TX_NOMASK, + G_TX_NOLOD, G_TX_NOLOD); + gSPTextureRectangle(gDisplayListHead++, ((arg0 + sp14) + 0x10) << 2, arg1 << 2, + ((arg0 + sp14) + temp_lo + 0x10) << 2, (arg1 + 5) << 2, G_TX_RENDERTILE, 0, 0, 0, 0x0400); + } + + gSPDisplayList(gDisplayListHead++, D_8006F630); +} + +void func_80021920(void) { + s32 temp_s2 = func_8002D5AC(0x24); + s32 i; + + for (i = 0; i < 151; i++) { + HAL_Strcpy(D_8006FF00[i].name, func_8002D7C0(NULL, 0, temp_s2, i)); + } +} diff --git a/src/20470.h b/src/20470.h index ce3eade9..94dfe405 100644 --- a/src/20470.h +++ b/src/20470.h @@ -3,8 +3,22 @@ #include "global.h" -void func_80020460(s32, s32, s32, s32, s32); -void func_8002053C(s32 arg0, s32 arg1, s32 arg2, s32 arg3, u8*, u8*); +extern Gfx D_8006F470[]; +extern Gfx D_8006F498[]; +extern Gfx D_8006F4C0[]; +extern Gfx D_8006F4E0[]; +extern Gfx D_8006F518[]; +extern Gfx D_8006F558[]; +extern Gfx D_8006F5A0[]; +extern Gfx D_8006F608[]; +extern Gfx D_8006F630[]; +extern Gfx D_8006F710[]; +extern Gfx D_8006F750[]; +extern Gfx D_8006F768[]; +extern Gfx D_8006F798[]; + +void func_80020460(s32, s32, s32, s32, u16); +void func_8002053C(s32 arg0, s32 arg1, s32 arg2, s32 arg3, Color_RGB8*, Color_RGB8*); void func_80021920(void); diff --git a/src/373A0.c b/src/373A0.c index b0b5a7f4..41a60484 100644 --- a/src/373A0.c +++ b/src/373A0.c @@ -5,7 +5,7 @@ #include "src/38BB0.h" #include "src/4B940.h" #include "src/4BA90.h" -#include "src/50CC0.h" +#include "src/51740.h" #include "src/4F410.h" #include "src/485C0.h" @@ -428,7 +428,7 @@ s32 func_800367A0(u32 arg0, s32 arg1, s32 arg2) { return sp2C; } -s32 func_80037234(s32 arg0, s32 arg1) { +s32 func_80037234(s32 arg0, u32 arg1) { switch (arg0) { case 0x0: if (arg1 == 0) { @@ -487,6 +487,8 @@ void func_80037360(u32* arg0, u32 arg1, s32 arg2) { } } +#define AUDIO_HEAP_SIZE 300000 + s32 func_800373D8(void) { s32 i; FileHeaders* sp78; @@ -498,9 +500,9 @@ s32 func_800373D8(void) { sp38.unk_04 = 0x34; sp38.unk_08 = 0x18; sp38.unk_0C = D_800B32A0; - sp38.unk_10 = 0x493E0; + sp38.unk_10 = AUDIO_HEAP_SIZE; sp38.unk_14 = 0x100; - sp38.unk_18 = 0x7D00; + sp38.unk_18 = 32000; sp38.unk_1C = 0x440; sp38.unk_20 = 1; sp38.unk_24 = 0x30; @@ -510,9 +512,9 @@ s32 func_800373D8(void) { func_80038B68(&sp38); func_8004AD40(2); - D_800FC6DC = alHeapDBAlloc(NULL, 0, D_800FC810, 1, 0x61A8); - D_800FC798 = alHeapDBAlloc(NULL, 0, D_800FC810, 8, 4); - D_800FC6E0 = alHeapDBAlloc(NULL, 0, D_800FC810, 7, 4); + D_800FC6DC = alHeapAlloc(D_800FC810, 1, 0x61A8); + D_800FC798 = alHeapAlloc(D_800FC810, 8, 4); + D_800FC6E0 = alHeapAlloc(D_800FC810, 7, 4); // Copy rom data from 0x15C0000 into D_800FC6E0 func_8004ADB0(&D_15C0000, D_800FC6E0, sizeof(u8*) * 7); @@ -526,7 +528,7 @@ s32 func_800373D8(void) { num_files = sp78->file1.num_files; // Allocate vram, copy rom bytes, and add address to make absolute, // for all of the first archive's files, including header. - D_800FC6E4 = alHeapDBAlloc(NULL, 0, D_800FC810, (0xC / sizeof(u32)) + num_files, sizeof(u32)); + D_800FC6E4 = alHeapAlloc(D_800FC810, (0xC / sizeof(u32)) + num_files, sizeof(u32)); func_8004ADB0(D_800FC6E0[1], D_800FC6E4, 0xC + (num_files * 4)); // Update just the first 2 pointers from the header, // pointer to first file, and pointer to N64 wave tables. @@ -538,7 +540,7 @@ s32 func_800373D8(void) { func_8004ADB0(D_800FC6E4->offset1, D_800FC6DC, D_800FC6E4->wave_tables_offset - D_800FC6E4->offset1); // Decompressed first file memory. - D_800FC684 = alHeapDBAlloc(NULL, 0, D_800FC810, 1, 0x4120); + D_800FC684 = alHeapAlloc(D_800FC810, 1, 0x4120); // Decompress first file Yay0 from D_800FC6DC, into D_800FC684 func_80050B40(D_800FC6DC, D_800FC684, 0x4120); @@ -546,27 +548,27 @@ s32 func_800373D8(void) { // ?? func_8003979C(D_800FC684, D_800FC6E4->wave_tables_offset); - D_800FC680 = alHeapDBAlloc(NULL, 0, D_800FC810, 1, 0x98D8); + D_800FC680 = alHeapAlloc(D_800FC810, 1, 0x98D8); // Load second archive header at 0x16F27E0 func_8004ADB0(D_800FC6E0[2], sp78, 4 + 4); num_files = sp78->seq.seqCount; // Memory to hold archive toc - D_800FC6E8 = alHeapDBAlloc(NULL, 0, D_800FC810, 1, 4 + (num_files * sizeof(ALSeqData))); + D_800FC6E8 = alHeapAlloc(D_800FC810, 1, 4 + (num_files * sizeof(ALSeqData))); // Read the alSeqFile into D_800FC6E8 func_8004ADB0(D_800FC6E0[2], D_800FC6E8, 4 + (num_files * sizeof(ALSeqData))); // Initialise the memory as an alSeqFile alSeqFileNew(D_800FC6E8, D_800FC6E0[2]); // Read the first archive sub header from 0x16F2804, into D_800FC6EC - D_800FC6EC = alHeapDBAlloc(NULL, 0, D_800FC810, 3, 4); + D_800FC6EC = alHeapAlloc(D_800FC810, 3, 4); func_8004ADB0(D_800FC6E8->seqArray[0].offset, D_800FC6EC, sizeof(File2SubHeader1)); func_80037360(D_800FC6EC, D_800FC6E8->seqArray[0].offset, sizeof(File2SubHeader1) / sizeof(u32)); // Read the first file from the sub header into D_800FC6DC (0x16F2814) func_8004ADB0(D_800FC6EC->offset1, D_800FC6DC, D_800FC6EC->offset2 - D_800FC6EC->offset1); // Decompress the yay0 file into D_800FC688 - D_800FC688 = alHeapDBAlloc(NULL, 0, D_800FC810, 1, 0xBB8); + D_800FC688 = alHeapAlloc(D_800FC810, 1, 0xBB8); func_80050B40(D_800FC6DC, D_800FC688, 0xBB8); // ??? func_800397BC(D_800FC688); @@ -574,7 +576,7 @@ s32 func_800373D8(void) { // Read the second file from the sub header into D_800FC6DC (0x16F2BD0) func_8004ADB0(D_800FC6EC->offset2, D_800FC6DC, D_800FC6EC->wave_tables_offset - D_800FC6EC->offset2); // Decompress the yay0 file into D_800FC688 - D_800FC68C = alHeapDBAlloc(NULL, 0, D_800FC810, 1, 0x157C); + D_800FC68C = alHeapAlloc(D_800FC810, 1, 0x157C); func_80050B40(D_800FC6DC, D_800FC68C, 0x157C); // ??? func_8003979C(D_800FC68C, D_800FC6EC->wave_tables_offset); @@ -583,42 +585,42 @@ s32 func_800373D8(void) { func_8004ADB0(D_800FC6E8->seqArray[1].offset, sp78, sizeof(File2SubHeader2)); num_files = sp78->file2sub2.num_files; - D_800FC6F0 = alHeapDBAlloc(NULL, 0, D_800FC810, 4, (sizeof(File2SubHeader2) / sizeof(u32)) + num_files); + D_800FC6F0 = alHeapAlloc(D_800FC810, 4, (sizeof(File2SubHeader2) / sizeof(u32)) + num_files); func_8004ADB0(D_800FC6E8->seqArray[1].offset, D_800FC6F0, sizeof(File2SubHeader2) + (num_files * sizeof(u32))); func_80037360(&D_800FC6F0->offset1, D_800FC6E8->seqArray[1].offset, num_files + 2); func_8004ADB0(D_800FC6F0->offset1, D_800FC6DC, D_800FC6F0->wave_tables_offset - D_800FC6F0->offset1); // Decompress the yay0 file into D_800FC688 - D_800FC690 = alHeapDBAlloc(NULL, 0, D_800FC810, 1, 0x2EE0); + D_800FC690 = alHeapAlloc(D_800FC810, 1, 0x2EE0); func_80050B40(D_800FC6DC, D_800FC690, 0x2EE0); // ??? func_8003979C(D_800FC690, D_800FC6F0->wave_tables_offset); - D_800FC698[0] = alHeapDBAlloc(NULL, 0, D_800FC810, 1, 0x258); - D_800FC698[1] = alHeapDBAlloc(NULL, 0, D_800FC810, 1, 0x258); - D_800FC698[2] = alHeapDBAlloc(NULL, 0, D_800FC810, 1, 0x258); + D_800FC698[0] = alHeapAlloc(D_800FC810, 1, 0x258); + D_800FC698[1] = alHeapAlloc(D_800FC810, 1, 0x258); + D_800FC698[2] = alHeapAlloc(D_800FC810, 1, 0x258); // Read the second seq array (0x17C9C24) func_8004ADB0(D_800FC6E8->seqArray[2].offset, sp78, sizeof(File2SubHeader2)); num_files = sp78->file2sub2.num_files; - D_800FC6FC = alHeapDBAlloc(NULL, 0, D_800FC810, 4, num_files + 3); + D_800FC6FC = alHeapAlloc(D_800FC810, 4, num_files + 3); func_8004ADB0(D_800FC6E8->seqArray[2].offset, D_800FC6FC, sizeof(File2SubHeader2) + (num_files * sizeof(u32))); func_80037360(&D_800FC6FC->offset1, D_800FC6E8->seqArray[2].offset, num_files + 2); func_8004ADB0(D_800FC6FC->offset1, D_800FC6DC, D_800FC6FC->wave_tables_offset - D_800FC6FC->offset1); - D_800FC6AC = alHeapDBAlloc(NULL, 0, D_800FC810, 1, 0x9C4); + D_800FC6AC = alHeapAlloc(D_800FC810, 1, 0x9C4); // Decompress func_80050B40(D_800FC6DC, D_800FC6AC, 0x9C4); func_8003979C(D_800FC6AC, D_800FC6FC->wave_tables_offset); - D_800FC6B0[0] = alHeapDBAlloc(NULL, 0, D_800FC810, 1, 0x3E8); - D_800FC6B0[1] = alHeapDBAlloc(NULL, 0, D_800FC810, 1, 0x3E8); - D_800FC6B0[2] = alHeapDBAlloc(NULL, 0, D_800FC810, 1, 0x3E8); + D_800FC6B0[0] = alHeapAlloc(D_800FC810, 1, 0x3E8); + D_800FC6B0[1] = alHeapAlloc(D_800FC810, 1, 0x3E8); + D_800FC6B0[2] = alHeapAlloc(D_800FC810, 1, 0x3E8); // Read seq header from 0x17DC304 func_8004ADB0(D_800FC6E8->seqArray[3].offset, sp78, 4 + 4); num_files = sp78->seq.seqCount; - D_800FC6F4 = alHeapDBAlloc(NULL, 0, D_800FC810, 4, 4 + (num_files * sizeof(ALSeqData))); + D_800FC6F4 = alHeapAlloc(D_800FC810, 4, 4 + (num_files * sizeof(ALSeqData))); func_8004ADB0(D_800FC6E8->seqArray[3].offset, D_800FC6F4, 4 + (num_files * sizeof(ALSeqData))); alSeqFileNew(D_800FC6F4, D_800FC6E8->seqArray[3].offset); @@ -626,18 +628,18 @@ s32 func_800373D8(void) { func_8004ADB0(D_800FC6F4->seqArray[1].offset, sp78, 4 + 4); num_files = sp78->seq.seqCount; - D_800FC6F8 = alHeapDBAlloc(NULL, 0, D_800FC810, 4, 4 + (num_files * sizeof(ALSeqData))); + D_800FC6F8 = alHeapAlloc(D_800FC810, 4, 4 + (num_files * sizeof(ALSeqData))); func_8004ADB0(D_800FC6F4->seqArray[1].offset, D_800FC6F8, 4 + (num_files * sizeof(ALSeqData))); alSeqFileNew(D_800FC6F8, D_800FC6F4->seqArray[1].offset); - D_800FC6A4 = alHeapDBAlloc(NULL, 0, D_800FC810, 1, 0x1388); - D_800FC6A8 = alHeapDBAlloc(NULL, 0, D_800FC810, 1, 0xBB8); + D_800FC6A4 = alHeapAlloc(D_800FC810, 1, 0x1388); + D_800FC6A8 = alHeapAlloc(D_800FC810, 1, 0xBB8); // load third archive from the main list, archive is at 0x1978820 func_8004ADB0(D_800FC6E0[3], sp78, 4 + 4); num_files = sp78->seq.seqCount; - D_800FC700 = alHeapDBAlloc(NULL, 0, D_800FC810, 1, 4 + (num_files * sizeof(ALSeqData))); + D_800FC700 = alHeapAlloc(D_800FC810, 1, 4 + (num_files * sizeof(ALSeqData))); func_8004ADB0(D_800FC6E0[3], D_800FC700, 4 + (num_files * sizeof(ALSeqData))); alSeqFileNew(D_800FC700, D_800FC6E0[3]); @@ -645,18 +647,18 @@ s32 func_800373D8(void) { func_8004ADB0(D_800FC6E0[4], sp78, 4 + 4); num_files = sp78->seq.seqCount; - D_800FC704 = alHeapDBAlloc(NULL, 0, D_800FC810, 1, 4 + (num_files * sizeof(ALSeqData))); + D_800FC704 = alHeapAlloc(D_800FC810, 1, 4 + (num_files * sizeof(ALSeqData))); func_8004ADB0(D_800FC6E0[4], D_800FC704, 4 + (num_files * sizeof(ALSeqData))); alSeqFileNew(D_800FC704, D_800FC6E0[4]); - D_800FC6C0[0] = alHeapDBAlloc(NULL, 0, D_800FC810, 1, 0x44C); - D_800FC6C0[1] = alHeapDBAlloc(NULL, 0, D_800FC810, 1, 0x44C); - D_800FC6C0[2] = alHeapDBAlloc(NULL, 0, D_800FC810, 1, 0x44C); + D_800FC6C0[0] = alHeapAlloc(D_800FC810, 1, 0x44C); + D_800FC6C0[1] = alHeapAlloc(D_800FC810, 1, 0x44C); + D_800FC6C0[2] = alHeapAlloc(D_800FC810, 1, 0x44C); // load the fourth archive's first seq, at 0x197C1FC func_8004ADB0(D_800FC704->seqArray[0].offset, sp78, 4 + 4); num_files = sp78->seq.seqCount; - D_800FC708 = alHeapDBAlloc(NULL, 0, D_800FC810, 1, 4 + (num_files * sizeof(ALSeqData))); + D_800FC708 = alHeapAlloc(D_800FC810, 1, 4 + (num_files * sizeof(ALSeqData))); func_8004ADB0(D_800FC704->seqArray[0].offset, D_800FC708, 4 + (num_files * sizeof(ALSeqData))); alSeqFileNew(D_800FC708, D_800FC704->seqArray[0].offset); @@ -665,25 +667,25 @@ s32 func_800373D8(void) { // load the fourth archive's third seq at 0x1A2AD20 func_8004ADB0(D_800FC704->seqArray[2].offset, sp78, 4 + 4); num_files = sp78->seq.seqCount; - D_800FC714 = alHeapDBAlloc(NULL, 0, D_800FC810, 1, 4 + (num_files * sizeof(ALSeqData))); + D_800FC714 = alHeapAlloc(D_800FC810, 1, 4 + (num_files * sizeof(ALSeqData))); func_8004ADB0(D_800FC704->seqArray[2].offset, D_800FC714, 4 + (num_files * sizeof(ALSeqData))); alSeqFileNew(D_800FC714, D_800FC704->seqArray[2].offset); - D_800FC6D8 = alHeapDBAlloc(NULL, 0, D_800FC810, 0xB80, 2); + D_800FC6D8 = alHeapAlloc(D_800FC810, 0xB80, 2); // load the 5th main archive at 0x1FBA260 - D_800FC6D4 = alHeapDBAlloc(NULL, 0, D_800FC810, 0x1388, 1); + D_800FC6D4 = alHeapAlloc(D_800FC810, 0x1388, 1); func_8004ADB0(D_800FC6E0[5], D_800FC6D4, D_800FC6E0[6] - D_800FC6E0[5]); // load the 6th main archive at 0x1FBB220 - D_800FC6CC = alHeapDBAlloc(NULL, 0, D_800FC810, 0x100, 1); + D_800FC6CC = alHeapAlloc(D_800FC810, 0x100, 1); func_8004ADB0(D_800FC6E0[6], D_800FC6CC, 0x100); for (i = 0; i < 32; i++) { D_800FC6CC[i].unk_00 += D_800FC6E0[6]; } - D_800FC6D0 = alHeapDBAlloc(NULL, 0, D_800FC810, 0x2328, 1); + D_800FC6D0 = alHeapAlloc(D_800FC810, 0x2328, 1); func_8004AE90(2, 2); func_8004AE90(1, 3); diff --git a/src/373A0.h b/src/373A0.h index d9563e01..833160e3 100644 --- a/src/373A0.h +++ b/src/373A0.h @@ -65,7 +65,7 @@ extern ALSeqFile* D_800FC714; extern u32* D_800FC798; s32 func_800367A0(u32, s32, s32); -s32 func_80037234(s32, s32); +s32 func_80037234(s32, u32); void func_80037360(u32*, u32, s32); #endif // _373A0_H_ diff --git a/src/38BB0.c b/src/38BB0.c index 7979ca5e..ec97d288 100644 --- a/src/38BB0.c +++ b/src/38BB0.c @@ -1,209 +1,2292 @@ #include "38BB0.h" - -#pragma GLOBAL_ASM("asm/us/nonmatchings/38BB0/func_80037FB0.s") - -#pragma GLOBAL_ASM("asm/us/nonmatchings/38BB0/func_80037FD0.s") - -#pragma GLOBAL_ASM("asm/us/nonmatchings/38BB0/func_80038008.s") - -#pragma GLOBAL_ASM("asm/us/nonmatchings/38BB0/func_8003802C.s") - -#pragma GLOBAL_ASM("asm/us/nonmatchings/38BB0/func_80038038.s") - -#pragma GLOBAL_ASM("asm/us/nonmatchings/38BB0/func_800381B4.s") - -#pragma GLOBAL_ASM("asm/us/nonmatchings/38BB0/func_80038268.s") - -#pragma GLOBAL_ASM("asm/us/nonmatchings/38BB0/func_8003827C.s") - -#pragma GLOBAL_ASM("asm/us/nonmatchings/38BB0/func_800382AC.s") - -#pragma GLOBAL_ASM("asm/us/nonmatchings/38BB0/func_80038304.s") - -#pragma GLOBAL_ASM("asm/us/nonmatchings/38BB0/func_80038360.s") - -#pragma GLOBAL_ASM("asm/us/nonmatchings/38BB0/func_80038374.s") - -#pragma GLOBAL_ASM("asm/us/nonmatchings/38BB0/func_800383B8.s") - -#pragma GLOBAL_ASM("asm/us/nonmatchings/38BB0/func_800383C8.s") - -#pragma GLOBAL_ASM("asm/us/nonmatchings/38BB0/func_800383D8.s") - -#pragma GLOBAL_ASM("asm/us/nonmatchings/38BB0/func_800383E8.s") - -#pragma GLOBAL_ASM("asm/us/nonmatchings/38BB0/func_8003844C.s") - -#pragma GLOBAL_ASM("asm/us/nonmatchings/38BB0/func_800384AC.s") - -#pragma GLOBAL_ASM("asm/us/nonmatchings/38BB0/func_800384BC.s") - -#pragma GLOBAL_ASM("asm/us/nonmatchings/38BB0/func_800384C8.s") - -#pragma GLOBAL_ASM("asm/us/nonmatchings/38BB0/func_800384D8.s") - -#pragma GLOBAL_ASM("asm/us/nonmatchings/38BB0/func_800384E4.s") - -#pragma GLOBAL_ASM("asm/us/nonmatchings/38BB0/func_800385D0.s") - -#pragma GLOBAL_ASM("asm/us/nonmatchings/38BB0/func_80038688.s") - -#pragma GLOBAL_ASM("asm/us/nonmatchings/38BB0/func_800386A8.s") - -#pragma GLOBAL_ASM("asm/us/nonmatchings/38BB0/func_800386B4.s") - -#pragma GLOBAL_ASM("asm/us/nonmatchings/38BB0/func_800386C4.s") - -#pragma GLOBAL_ASM("asm/us/nonmatchings/38BB0/func_800386D0.s") - -#pragma GLOBAL_ASM("asm/us/nonmatchings/38BB0/func_800386E4.s") - -#pragma GLOBAL_ASM("asm/us/nonmatchings/38BB0/func_80038704.s") - -#pragma GLOBAL_ASM("asm/us/nonmatchings/38BB0/func_80038710.s") - -#pragma GLOBAL_ASM("asm/us/nonmatchings/38BB0/func_80038738.s") - -#pragma GLOBAL_ASM("asm/us/nonmatchings/38BB0/func_80038744.s") - -#pragma GLOBAL_ASM("asm/us/nonmatchings/38BB0/func_80038750.s") - -#pragma GLOBAL_ASM("asm/us/nonmatchings/38BB0/func_800387B4.s") - -#pragma GLOBAL_ASM("asm/us/nonmatchings/38BB0/func_800387C4.s") - -#pragma GLOBAL_ASM("asm/us/nonmatchings/38BB0/func_80038814.s") - -#pragma GLOBAL_ASM("asm/us/nonmatchings/38BB0/func_80038864.s") - -#pragma GLOBAL_ASM("asm/us/nonmatchings/38BB0/func_800388B4.s") - -#pragma GLOBAL_ASM("asm/us/nonmatchings/38BB0/func_800388C4.s") - -#pragma GLOBAL_ASM("asm/us/nonmatchings/38BB0/func_800389C0.s") - -#pragma GLOBAL_ASM("asm/us/nonmatchings/38BB0/func_80038A10.s") - -#pragma GLOBAL_ASM("asm/us/nonmatchings/38BB0/func_80038A34.s") - -#pragma GLOBAL_ASM("asm/us/nonmatchings/38BB0/func_80038B30.s") - -#pragma GLOBAL_ASM("asm/us/nonmatchings/38BB0/func_80038B54.s") - +#include "src/3D140.h" +#include "src/435B0.h" + +typedef u8* (*func_D_80077C98)(unk_D_800FC7D0*, u8*); +typedef u8* (*func_D_80077D5C)(u8*); + +static s32 D_80077C90 = -1; +static u8 D_80077C94 = 0; +static func_D_80077C98 D_80077C98[] = { + func_80037FB0, func_80037FD0, func_80038008, func_8003802C, func_80038038, func_800381B4, func_8003827C, + func_80038268, func_800382AC, func_80038304, func_80038360, func_80038374, func_800383B8, func_800383C8, + func_800383D8, func_800383E8, func_8003844C, func_800384AC, func_800384BC, func_800384C8, func_800384D8, + func_800384E4, func_800385D0, func_80038688, func_800386A8, func_800386B4, func_800386C4, func_800386D0, + func_800386E4, func_80038704, func_80038710, func_80038738, func_80038744, func_80038750, func_800387B4, + func_800387C4, func_80038814, func_80038864, func_800388B4, func_800388C4, func_800389C0, func_80038A10, + NULL, NULL, NULL, NULL, NULL, NULL, func_80038A34, +}; +static func_D_80077D5C D_80077D5C[] = { + func_80039D58, func_8003A10C, func_8003A234, func_8003A2F0, func_8003A39C, func_8003A438, func_8003A4D8, + func_8003A564, func_8003A614, func_8003A6D4, func_8003A744, func_80039F28, NULL, +}; + +static ALPlayer D_800FC7A0; +static ALHeap D_800FC7B8; +static s32 pad_D_800FC7C8; +static u32 D_800FC7CC; +static unk_D_800FC7D0* D_800FC7D0; +static u32 D_800FC7D4; +static u32 D_800FC7D8; +static u16 D_800FC7DC; +static u16 D_800FC7DE; +static u32 D_800FC7E0; +static s32 D_800FC7E4; +static u8* D_800FC7E8; +static s32 D_800FC7EC; +static u32 D_800FC7F0; +static u8 D_800FC7F4; +static u32 D_800FC7F8; +static unk_D_800FC7D0_148* D_800FC7FC; +static unk_D_800FC7D0_148* D_800FC800; +static unk_D_800FC7D0_148* D_800FC804; +static unk_D_800FC7D0_148* D_800FC808; +static unk_D_800FC7D0_148* D_800FC80C; +ALHeap* D_800FC810; +u32 D_800FC814; +s32 D_800FC818; +s32 D_800FC81C; + +u8* func_80037FB0(unk_D_800FC7D0* arg0, UNUSED u8* arg1) { + arg0->unk_060 = 0; + arg0->unk_05C = 0; + arg0->unk_08C = 0; + arg0->unk_0BA = 0; + arg0->unk_064 = 0; + return NULL; +} + +u8* func_80037FD0(unk_D_800FC7D0* arg0, u8* arg1) { + u16 var_v1 = *arg1++; + + if (var_v1 & 0x80) { + var_v1 = (var_v1 & 0x7F) << 8; + var_v1 |= *arg1++; + } + + arg0->unk_0C2 = var_v1; + return arg1; +} + +u8* func_80038008(unk_D_800FC7D0* arg0, u8* arg1) { + arg0->unk_0CC = *arg1++; + if (arg0->unk_0CC) { + arg0->unk_070 = arg0->unk_054; + } + return arg1; +} + +u8* func_8003802C(unk_D_800FC7D0* arg0, u8* arg1) { + arg0->unk_0CC = 0; + return arg1; +} + +u8* func_80038038(unk_D_800FC7D0* arg0, u8* arg1) { + u8 var_v0; + + var_v0 = *arg1++; + if (var_v0 == 0) { + var_v0 = 1; + } + arg0->unk_0D3 = var_v0; + arg0->unk_07C = 0x400 / var_v0; + arg0->unk_0D4 = 0; + + arg1++; + + var_v0 = *arg1++; + if (var_v0 == 0) { + var_v0 = 1; + } + arg0->unk_0DA = var_v0; + arg0->unk_0D5 = *arg1++; + arg0->unk_074 = (1.0 / (f32)var_v0) * (f32)(arg0->unk_0D5 - arg0->unk_0D4); + + var_v0 = *arg1++; + if (var_v0 == 0) { + var_v0 = 1; + } + arg0->unk_0DB = var_v0; + arg0->unk_0D6 = *arg1++; + arg0->unk_078 = (1.0f / var_v0) * ((f32)arg0->unk_0D6 - arg0->unk_0D5); + + var_v0 = *arg1++; + if (var_v0 == 0) { + var_v0 = 1; + } + arg0->unk_0E0 = var_v0; + + return arg1; +} + +u8* func_800381B4(unk_D_800FC7D0* arg0, u8* arg1) { + s32 i; + s32 temp_lo; + s32 temp2; + unk_D_800FC7D0* var_a3; + + temp_lo = ((*arg1++ * 0x6000) / 120) / D_800FC7D4; + temp2 = (arg0->unk_0AC * temp_lo) >> 7; + + if (arg0->unk_0BA != 0) { + arg0->unk_0B0 = temp_lo; + } else { + for (i = 0, var_a3 = D_800FC7D0; i < D_800FC7CC; i++, var_a3++) { + if (var_a3->unk_08C == arg0->unk_08C) { + var_a3->unk_0BC = temp_lo; + var_a3->unk_0B0 = temp2; + } + } + } + + return arg1; +} + +u8* func_80038268(unk_D_800FC7D0* arg0, u8* arg1) { + arg0->unk_0C8 = *arg1++; + arg0->unk_0C6 = 0; + return arg1; +} + +u8* func_8003827C(unk_D_800FC7D0* arg0, u8* arg1) { + s16 tmp = *arg1++ << 8; + + tmp |= *arg1++; + + arg0->unk_0C6 = tmp; + arg0->unk_0C8 = 0; + + return arg1; +} + +u8* func_800382AC(unk_D_800FC7D0* arg0, u8* arg1) { + arg0->unk_0CA = *arg1++; + arg0->unk_0EC = *arg1++; + arg0->unk_048 = (f32)*arg1++ / 50.0; + return arg1; +} + +u8* func_80038304(unk_D_800FC7D0* arg0, u8* arg1) { + arg0->unk_0CA = *arg1++; + arg0->unk_0EC = *arg1++; + arg0->unk_048 = -(f32)*arg1++ / 50.0; + + return arg1; +} + +u8* func_80038360(unk_D_800FC7D0* arg0, u8* arg1) { + arg0->unk_0EC = 0; + arg0->unk_080 = 0.0f; + return arg1; +} + +u8* func_80038374(unk_D_800FC7D0* arg0, u8* arg1) { + u8 temp_v0 = *arg1++; + + if (temp_v0 < 0x80) { + arg0->unk_0C0 = temp_v0; + } else { + arg0->unk_0C0 = (temp_v0 & 0x7F) << 8; + arg0->unk_0C0 += *arg1++; + } + return arg1; +} + +u8* func_800383B8(unk_D_800FC7D0* arg0, u8* arg1) { + arg0->unk_0CB = 1; + return arg1; +} + +u8* func_800383C8(unk_D_800FC7D0* arg0, u8* arg1) { + arg0->unk_0CD = *arg1++; + return arg1; +} + +u8* func_800383D8(unk_D_800FC7D0* arg0, u8* arg1) { + arg0->unk_0CE = 1; + return arg1; +} + +u8* func_800383E8(unk_D_800FC7D0* arg0, u8* arg1) { + s32 var_v1 = *arg1++; + + if (var_v1 & 0x80) { + var_v1 |= ~0xFF; + } + arg0->unk_058 -= arg0->unk_0A4; + arg0->unk_0A4 = (f32)var_v1 / 100.0; + arg0->unk_058 += arg0->unk_0A4; + return arg1; +} + +u8* func_8003844C(unk_D_800FC7D0* arg0, u8* arg1) { + s32 var_v0 = *arg1++; + + if (var_v0 & 0x80) { + var_v0 = (var_v0 & 0x7F) << 8; + var_v0 |= *arg1++; + } + + func_80038038(arg0, (u8*)&arg0->unk_08C->unk_10[var_v0]); + return arg1; +} + +u8* func_800384AC(unk_D_800FC7D0* arg0, u8* arg1) { + arg0->unk_0ED = 1; + return arg1; +} + +u8* func_800384BC(unk_D_800FC7D0* arg0, u8* arg1) { + arg0->unk_0ED = 0; + return arg1; +} + +u8* func_800384C8(unk_D_800FC7D0* arg0, u8* arg1) { + arg0->unk_0EE = 1; + return arg1; +} + +u8* func_800384D8(unk_D_800FC7D0* arg0, u8* arg1) { + arg0->unk_0EE = 0; + return arg1; +} + +u8* func_800384E4(unk_D_800FC7D0* arg0, u8* arg1) { + u8 temp_v1 = arg0->unk_0F2; + + arg0->unk_134[temp_v1] = *arg1++; + + arg0->unk_0F4[temp_v1] = arg1; + arg0->unk_104[temp_v1] = arg0->unk_060; + arg0->unk_114[temp_v1] = arg0->unk_05C; + + arg0->unk_138[temp_v1] = arg0->unk_0D0; + arg0->unk_13C[temp_v1] = arg0->unk_088; + + arg0->unk_124[temp_v1] = arg0->unk_0B6; + arg0->unk_12C[temp_v1] = arg0->unk_0B8; + + arg0->unk_0F2++; + return arg1; +} + +u8* func_800385D0(unk_D_800FC7D0* arg0, u8* arg1) { + s32 var_v0 = arg0->unk_0F2 - 1; + + if (arg0->unk_134[var_v0] != 0xFF) { + arg0->unk_134[var_v0]--; + if (!arg0->unk_134[var_v0]) { + arg0->unk_0F2 = var_v0; + var_v0 = -1; + } + } + + if (var_v0 >= 0) { + arg1 = arg0->unk_0F4[var_v0]; + + arg0->unk_060 = arg0->unk_104[var_v0]; + arg0->unk_05C = arg0->unk_114[var_v0]; + arg0->unk_0D0 = arg0->unk_138[var_v0]; + + arg0->unk_088 = arg0->unk_13C[var_v0]; + arg0->unk_0B6 = arg0->unk_124[var_v0]; + arg0->unk_0B8 = arg0->unk_12C[var_v0]; + arg0->unk_084 = 0.03125f; + arg0->unk_04C = arg0->unk_088 * arg0->unk_084; + } + + return arg1; +} + +u8* func_80038688(unk_D_800FC7D0* arg0, u8* arg1) { + arg0->unk_0EF = *arg1++; + arg0->unk_0E5 = *arg1++; + arg0->unk_0E6 = *arg1++; + return arg1; +} + +u8* func_800386A8(unk_D_800FC7D0* arg0, u8* arg1) { + arg0->unk_0E5 = 0; + return arg1; +} + +u8* func_800386B4(unk_D_800FC7D0* arg0, u8* arg1) { + arg0->unk_0E9 = 1; + return arg1; +} + +u8* func_800386C4(unk_D_800FC7D0* arg0, u8* arg1) { + arg0->unk_0E9 = 0; + return arg1; +} + +u8* func_800386D0(unk_D_800FC7D0* arg0, u8* arg1) { + arg0->unk_0EA = *arg1++; + arg0->unk_0E9 = 0; + return arg1; +} + +u8* func_800386E4(unk_D_800FC7D0* arg0, u8* arg1) { + arg0->unk_0D1 = *arg1++ / 2; + return arg1; +} + +u8* func_80038704(UNUSED unk_D_800FC7D0* arg0, u8* arg1) { + arg1++; + arg1++; + return arg1; +} + +u8* func_80038710(unk_D_800FC7D0* arg0, u8* arg1) { + u8* ptr = (u8*)&arg0->unk_08C->unk_00 + arg0->unk_08C->unk_14[*arg1++]; + + arg0->unk_098 = ptr; + return arg1; +} + +u8* func_80038738(unk_D_800FC7D0* arg0, u8* arg1) { + arg0->unk_098 = NULL; + return arg1; +} + +u8* func_80038744(UNUSED unk_D_800FC7D0* arg0, u8* arg1) { + arg1++; + return arg1; +} + +u8* func_80038750(unk_D_800FC7D0* arg0, u8* arg1) { + s32 tmp0; + s32 tmp2; + + tmp0 = *arg1++ << 8; + tmp0 += *arg1++; + + tmp2 = *arg1++ << 8; + tmp2 += *arg1++; + + arg0->unk_060 = &arg0->unk_0A0[tmp2]; + arg0->unk_0B6 = 1; + + tmp2 = *arg1++ << 8; + tmp2 += *arg1++; + + arg0->unk_05C = &arg0->unk_09C[tmp2]; + arg0->unk_0B8 = 1; + + return &arg0->unk_094[tmp0]; +} + +u8* func_800387B4(unk_D_800FC7D0* arg0, u8* arg1) { + arg0->unk_0E2 = *arg1++; + return arg1; +} + +u8* func_800387C4(unk_D_800FC7D0* arg0, u8* arg1) { + arg0->unk_0CD = func_8003BEF4(*arg1++); + arg0->unk_0CD += *arg1++; + return arg1; +} + +u8* func_80038814(unk_D_800FC7D0* arg0, u8* arg1) { + arg0->unk_0D0 = func_8003BEF4(*arg1++); + arg0->unk_0D0 += *arg1++; + return arg1; +} + +u8* func_80038864(unk_D_800FC7D0* arg0, u8* arg1) { + arg0->unk_0D1 = func_8003BEF4(*arg1++); + arg0->unk_0D1 += *arg1++; + return arg1; +} + +u8* func_800388B4(unk_D_800FC7D0* arg0, u8* arg1) { + arg0->unk_0D0 = *arg1++; + return arg1; +} + +u8* func_800388C4(unk_D_800FC7D0* arg0, u8* arg1) { + s32 i; + s32 var_s1; + unk_D_800FC7D0* var_a0; + u32* sp30; + + var_s1 = *arg1++; + if (var_s1 >= 0x80) { + var_s1 = *arg1++ + ((var_s1 & 0x7F) << 8); + } + + sp30 = arg0->unk_140->unk_0C; + for (i = 0, var_a0 = D_800FC7D0; i < D_800FC7CC; i++, var_a0++) { + if (var_a0->unk_038 == NULL) { + func_8003C2A4(var_a0, var_s1, arg0->unk_0B2, arg0->unk_0C4, arg0->unk_068); + + var_a0->unk_064 = arg0->unk_064; + var_a0->unk_090 = arg0->unk_090; + var_a0->unk_140 = arg0->unk_140; + var_a0->unk_040 = arg0->unk_040; + var_a0->unk_044 = arg0->unk_044; + + var_a0->unk_038 = var_a0->unk_094 = sp30[var_s1]; + break; + } + } + + return arg1; +} + +u8* func_800389C0(unk_D_800FC7D0* arg0, u8* arg1) { + arg0->unk_084 = (f32)*arg1++ * 0.015625; + arg0->unk_04C = SQ(arg0->unk_088); + return arg1; +} + +u8* func_80038A10(unk_D_800FC7D0* arg0, u8* arg1) { + arg0->unk_0EB = *arg1++; + if (!arg0->unk_0EB) { + arg0->unk_0C4 = 0x80; + } + return arg1; +} + +u8* func_80038A34(unk_D_800FC7D0* arg0, u8* arg1) { + s32 i; + s32 var_s1; + unk_D_800FC7D0* var_a0; + s32* sp30; + + var_s1 = *arg1++; + if (var_s1 >= 0x80) { + var_s1 = *arg1++ + ((var_s1 & 0x7F) << 8); + } + + sp30 = arg0->unk_140->unk_0C; + for (i = 0, var_a0 = D_800FC7D0; i < D_800FC7CC; i++, var_a0++) { + if (var_a0->unk_038 == NULL) { + func_8003C2A4(var_a0, var_s1, arg0->unk_0B2, arg0->unk_0C4, arg0->unk_068); + var_a0->unk_064 = arg0->unk_064; + var_a0->unk_090 = arg0->unk_090; + var_a0->unk_140 = arg0->unk_140; + var_a0->unk_040 = arg0->unk_040; + var_a0->unk_044 = arg0->unk_044; + var_a0->unk_038 = var_a0->unk_094 = sp30[var_s1]; + break; + } + } + + return arg1; +} + +void func_80038B30(u8* arg0, u32 arg1) { + *arg0++ = (arg1 >> 0x18) & 0xFF; + *arg0++ = (arg1 >> 0x10) & 0xFF; + *arg0++ = (arg1 >> 8) & 0xFF; + *arg0++ = (arg1 >> 0) & 0xFF; +} + +void func_80038B54(u8* arg0, u32 arg1) { + *arg0++ = (arg1 >> 8u) & 0xFF; + *arg0++ = arg1 & 0xFF; +} + +#ifdef NON_MATCHING +s32 func_80038B68(sp38_func_800373D8* arg0) { + UNUSED s32 pad[2]; + s32 i; + ALSynConfig sp4C; + amConfig sp40; + + sp4C.outputRate = osAiSetFrequency(arg0->unk_18); + D_800FC7CC = arg0->unk_00; + if (osTvType == OS_TV_PAL) { + D_800FC7D4 = 50; + } else { + D_800FC7D4 = 60; + } + D_800FC7D8 = 1000000 / D_800FC7D4; + + func_8003C1D0(arg0->unk_0C, 0, arg0->unk_10); + alHeapInit(&D_800FC7B8, arg0->unk_0C, arg0->unk_10); + D_800FC810 = &D_800FC7B8; + D_800FC7D0 = alHeapAlloc(&D_800FC7B8, 1, D_800FC7CC * sizeof(unk_D_800FC7D0)); + func_8003C1D0(D_800FC7D0, 0, D_800FC7CC * sizeof(unk_D_800FC7D0)); + + D_800FC7E8 = alHeapAlloc(&D_800FC7B8, 1, arg0->unk_2C); + D_800FC7EC = 0; + D_800FC7F0 = arg0->unk_2C; + + D_800FC7FC = alHeapAlloc(&D_800FC7B8, arg0->unk_04, sizeof(unk_D_800FC7D0_148)); + D_800FC804 = NULL; + D_800FC800 = NULL; + D_800FC808 = NULL; + D_800FC80C = NULL; + D_800FC818 = 0; + D_800FC81C = 0; + + for (i = 0; i < arg0->unk_04; i++) { + func_8003C2F8(D_800FC7FC++); + } + + sp4C.maxVVoices = arg0->unk_04; + sp4C.maxPVoices = arg0->unk_08; + sp4C.maxUpdates = arg0->unk_14; + sp4C.dmaproc = NULL; + sp4C.fxType = AL_FX_BIGROOM; + sp4C.heap = &D_800FC7B8; + + sp40.outputRate = arg0->unk_18; + sp40.framesPerField = arg0->unk_20; + sp40.maxACMDSize = arg0->unk_1C; + + amCreateAudioMgr(&sp4C, &sp40, arg0->unk_24, arg0->unk_28, D_800FC7D4); + + D_800FC814 = arg0->unk_04; + D_800FC7E0 = 1; + D_800FC7F8 = 0; + D_800FC7DE = 0x7FFF; + D_800FC7DC = 0x7FFF; + + D_80077C90 = -1; + D_80077DE4 = 0; + D_80077C94 = 1; + + D_800FC7A0.next = NULL; + D_800FC7A0.handler = func_8003A78C; + D_800FC7A0.clientData = &D_800FC7A0; + + n_alSynAddPlayer(&D_800FC7A0); + + for (i = 0; i < D_800FC7CC; i++) { + D_800FC7D0[i].unk_0E1 = 0; + D_800FC7D0[i].unk_038 = 0; + func_8003BFF4(&D_800FC7D0[i]); + } + + return D_800FC7B8.cur - D_800FC7B8.base; +} +#else #pragma GLOBAL_ASM("asm/us/nonmatchings/38BB0/func_80038B68.s") +#endif + +void func_80038E98(s32 arg0, u32 arg1) { + u8* temp_a0; + u32 sp18 = osSetIntMask(1); + + temp_a0 = D_800FC7E8; + temp_a0 += D_800FC7EC; + + *temp_a0++ = 9; + *temp_a0++ = arg0; + func_80038B54(temp_a0, arg1); + temp_a0 += 2; + + D_800FC7EC += 4; + if (D_800FC7EC >= D_800FC7F0) { + D_800FC7EC -= 4; + } + + osSetIntMask(sp18); +} + +s32 func_80038F30(SoundBank* arg0, s32 arg1) { + u8* temp_a0; + u32 sp20; + UNUSED s32 pad; + u32 sp18; + + if (arg0 == 0) { + return 0; + } + + if (!(arg0->flags & 1)) { + return 0; + } + + sp18 = osSetIntMask(1); + + temp_a0 = D_800FC7E8; + temp_a0 += D_800FC7EC; + + sp20 = D_800FC7E0; + D_800FC7E0++; + + *temp_a0++ = 0; + func_80038B30(temp_a0, arg0); + temp_a0 += 4; + func_80038B30(temp_a0, arg1); + temp_a0 += 4; + func_80038B30(temp_a0, sp20); + temp_a0 += 4; + + D_800FC7EC += 0xD; + if (D_800FC7EC >= D_800FC7F0) { + D_800FC7EC -= 0xD; + } + + osSetIntMask(sp18); + return sp20; +} + +s32 func_80039024(SoundBank* arg0, s32 arg1, s32 arg2, s32 arg3, u32 arg4, s32 arg5) { + u32 sp2C; + UNUSED s32 pad[2]; + u32 sp20; + u8* temp_s0; + + if (D_80077DE4 != 0) { + return 0; + } + + if (arg0 == NULL) { + return 0; + } + + if (!(arg0->flags & 1)) { + return 0; + } + + sp20 = osSetIntMask(1); + + temp_s0 = D_800FC7E8; + temp_s0 += D_800FC7EC; + + sp2C = D_800FC7E0; + D_800FC7E0++; + + *temp_s0++ = 1; + func_80038B30(temp_s0, arg0); + temp_s0 += 4; + func_80038B30(temp_s0, arg1); + temp_s0 += 4; + func_80038B30(temp_s0, sp2C); + temp_s0 += 4; + func_80038B30(temp_s0, arg2); + temp_s0 += 4; + + *temp_s0++ = arg3; + *temp_s0++ = arg4; + *temp_s0++ = arg5; + + D_800FC7EC += 0x14; + if (D_800FC7EC >= D_800FC7F0) { + D_800FC7EC -= 0x14; + } + + osSetIntMask(sp20); + return sp2C; +} + +void func_8003916C(s32 arg0, u32 arg1) { + u8* temp_a0; + u32 sp18 = osSetIntMask(1); + + temp_a0 = D_800FC7E8; + temp_a0 += D_800FC7EC; + + *temp_a0++ = 8; + *temp_a0++ = arg0; + func_80038B54(temp_a0, arg1); + temp_a0 += 2; + + D_800FC7EC += 4; + if (D_800FC7EC >= D_800FC7F0) { + D_800FC7EC -= 4; + } + + osSetIntMask(sp18); +} + +s32 func_80039204(s32 arg0) { + s32 i; + s32 sp20; + unk_D_800FC7D0* var_v1; + u32 sp18; + + sp18 = osSetIntMask(1); + + for (i = 0, sp20 = 0, var_v1 = D_800FC7D0; i < D_800FC7CC; i++, var_v1++) { + if (var_v1->unk_038 != NULL) { + if (((var_v1->unk_0BA != 0) && (arg0 & 1)) || ((var_v1->unk_0BA == 0) && (arg0 & 2))) { + sp20++; + } + } + } + + osSetIntMask(sp18); + return sp20; +} + +void func_800392A8(s32 arg0, u32 arg1) { + UNUSED s32 pad; + u8* temp_a0; + u32 sp1C; + + if (arg0 != 0) { + sp1C = osSetIntMask(1); + + temp_a0 = D_800FC7E8; + temp_a0 += D_800FC7EC; + + *temp_a0++ = 7; + func_80038B30(temp_a0, arg0); + temp_a0 += 4; + func_80038B54(temp_a0, (u16)arg1); + + D_800FC7EC += 7; + if (D_800FC7EC >= D_800FC7F0) { + D_800FC7EC -= 7; + } + + osSetIntMask(sp1C); + } +} + +s32 func_80039354(s32 arg0) { + unk_D_800FC7D0* var_a0; + s32 i; + s32 sp1C; + u32 sp18; + + if (arg0 == 0) { + return 0; + } + + sp18 = osSetIntMask(1); + + for (i = 0, sp1C = 0, var_a0 = D_800FC7D0; i < D_800FC7CC; i++, var_a0++) { + if (arg0 == var_a0->unk_064) { + sp1C++; + } + } + + osSetIntMask(sp18); + + return sp1C; +} + +void func_800393DC(s32 arg0, u32 arg1) { + u8* temp_a0; + UNUSED s32 pad[2]; + u32 sp18; + + if (arg0 != 0) { + sp18 = osSetIntMask(1); + + temp_a0 = D_800FC7E8; + temp_a0 += D_800FC7EC; + + *temp_a0++ = 4; + func_80038B30(temp_a0, arg0); + temp_a0 += 4; + func_80038B54(temp_a0, (u16)arg1); + + D_800FC7EC += 7; + if (D_800FC7EC >= D_800FC7F0) { + D_800FC7EC -= 7; + } + + osSetIntMask(sp18); + } +} + +void func_80039488(s32 arg0, u16 arg1) { + u8* temp_a0; + UNUSED s32 pad[2]; + u32 sp18; + + if (arg0 != 0) { + sp18 = osSetIntMask(1); + + temp_a0 = D_800FC7E8; + temp_a0 += D_800FC7EC; + + *temp_a0++ = 5; + func_80038B30(temp_a0, arg0); + temp_a0 += 4; + func_80038B54(temp_a0, arg1); + temp_a0 += 2; + + D_800FC7EC += 7; + if (D_800FC7EC >= D_800FC7F0) { + D_800FC7EC -= 7; + } + osSetIntMask(sp18); + } +} + +void func_80039534(s32 arg0, f32 arg1) { + u8* temp_a0; + UNUSED s32 pad[3]; + u32 sp1C; + UNUSED s32 pad2; + + if (arg0 != 0) { + sp1C = osSetIntMask(1); + + temp_a0 = D_800FC7E8; + temp_a0 += D_800FC7EC; + + *temp_a0++ = 2; + func_80038B30(temp_a0, arg0); + temp_a0 += 4; + func_80038B54(temp_a0, (s32)(255.0f * arg1) & 0xFFFF); + + D_800FC7EC += 7; + if (D_800FC7EC >= D_800FC7F0) { + D_800FC7EC -= 7; + } + + osSetIntMask(sp1C); + } +} + +void func_800395FC(s32 arg0, s32 arg1) { + u8* temp_a0; + UNUSED s32 pad; + u32 sp1C; + + if (arg0 != 0) { + if (arg1 <= 0) { + arg1 = 1; + } else if (arg1 > 0x100) { + arg1 = 0x100; + } + arg1--; + + sp1C = osSetIntMask(1); + temp_a0 = D_800FC7E8; + temp_a0 += D_800FC7EC; + + *temp_a0++ = 3; + func_80038B30(temp_a0, arg0); + temp_a0 += 4; + func_80038B54(temp_a0, arg1 & 0xFFFF); + + D_800FC7EC += 7; + if (D_800FC7EC >= D_800FC7F0) { + D_800FC7EC -= 7; + } + + osSetIntMask(sp1C); + } +} + +void func_800396D0(u32 arg0, s32 arg1) { + u8* temp_a0; + UNUSED s32 pad; + u32 sp1C; + + if (arg0 != 0) { + if (arg1 < 0) { + arg1 = 0; + } else if (arg1 >= 0x80) { + arg1 = 0x7F; + } + + sp1C = osSetIntMask(1); + + temp_a0 = D_800FC7E8; + temp_a0 += D_800FC7EC; + + *temp_a0++ = 3; + func_80038B30(temp_a0, arg0); + temp_a0 += 4; + + *temp_a0++ = arg1; + + D_800FC7EC += 6; + if (D_800FC7EC >= D_800FC7F0) { + D_800FC7EC -= 6; + } + + osSetIntMask(sp1C); + } +} + +void func_8003979C(s32 arg0, s32 arg1) { + func_8003BD2C(arg0, arg1); +} + +void func_800397BC(unk_func_800397BC* arg0) { + u32 i; + u32* ptr; + u32 num_entries; + u32 val; + u32 a0 = (u32)arg0; -#pragma GLOBAL_ASM("asm/us/nonmatchings/38BB0/func_80038E98.s") - -#pragma GLOBAL_ASM("asm/us/nonmatchings/38BB0/func_80038F30.s") - -#pragma GLOBAL_ASM("asm/us/nonmatchings/38BB0/func_80039024.s") - -#pragma GLOBAL_ASM("asm/us/nonmatchings/38BB0/func_8003916C.s") - -#pragma GLOBAL_ASM("asm/us/nonmatchings/38BB0/func_80039204.s") + if (arg0->flags & 2) { + return; + } -#pragma GLOBAL_ASM("asm/us/nonmatchings/38BB0/func_800392A8.s") + num_entries = arg0->num_entries; -#pragma GLOBAL_ASM("asm/us/nonmatchings/38BB0/func_80039354.s") + val = arg0->unk_offset; + arg0->unk_offset = a0 + val; -#pragma GLOBAL_ASM("asm/us/nonmatchings/38BB0/func_800393DC.s") + val = arg0->entries_offset; + arg0->entries_offset = a0 + val; -#pragma GLOBAL_ASM("asm/us/nonmatchings/38BB0/func_80039488.s") + ptr = arg0->entries_offset; + if (0) {} + + for (i = 0; i < num_entries; i++, ptr++) { + *ptr += a0; + } + + arg0->flags |= 2; +} -#pragma GLOBAL_ASM("asm/us/nonmatchings/38BB0/func_80039534.s") +void func_8003986C(s32 arg0) { + u32 temp_v0 = osSetIntMask(1); + u8* temp_v1 = D_800FC7E8; -#pragma GLOBAL_ASM("asm/us/nonmatchings/38BB0/func_800395FC.s") + temp_v1 += D_800FC7EC; -#pragma GLOBAL_ASM("asm/us/nonmatchings/38BB0/func_800396D0.s") + *temp_v1++ = 0xA; + *temp_v1++ = arg0; -#pragma GLOBAL_ASM("asm/us/nonmatchings/38BB0/func_8003979C.s") + D_800FC7EC += 2; + if (D_800FC7EC >= D_800FC7F0) { + D_800FC7EC -= 2; + } -#pragma GLOBAL_ASM("asm/us/nonmatchings/38BB0/func_800397BC.s") + osSetIntMask(temp_v0); +} -#pragma GLOBAL_ASM("asm/us/nonmatchings/38BB0/func_8003986C.s") +void func_800398F0(s32 arg0) { + u32 temp_a0 = osSetIntMask(1); -#pragma GLOBAL_ASM("asm/us/nonmatchings/38BB0/func_800398F0.s") + if (arg0 != 0) { + D_80077C94 = 1; + } else { + D_80077C94 = 0; + } -#pragma GLOBAL_ASM("asm/us/nonmatchings/38BB0/func_80039940.s") + osSetIntMask(temp_a0); +} -#pragma GLOBAL_ASM("asm/us/nonmatchings/38BB0/func_80039A7C.s") +void func_80039940(void) { + UNUSED s32 pad[4]; + u32 sp34 = osSetIntMask(1); + u32 i; + unk_D_800FC7D0* ptr = D_800FC7D0; -#pragma GLOBAL_ASM("asm/us/nonmatchings/38BB0/func_80039B88.s") + for (i = 0; i < D_800FC7CC; i++, ptr++) { + if ((ptr->unk_0BA != 0) || (ptr->unk_038 == 0)) { + continue; + } -#pragma GLOBAL_ASM("asm/us/nonmatchings/38BB0/func_80039C84.s") + ptr->unk_038 = func_80037FB0(ptr, 0); -#pragma GLOBAL_ASM("asm/us/nonmatchings/38BB0/func_80039CB4.s") + if (ptr->unk_0E1 == 0) { + ptr->unk_03C = 0; + continue; + } -#pragma GLOBAL_ASM("asm/us/nonmatchings/38BB0/func_80039CD0.s") + ptr->unk_148->unk_2A = 4; + ptr->unk_148->unk_24 = D_800FC7F8 + 2; -#pragma GLOBAL_ASM("asm/us/nonmatchings/38BB0/func_80039D58.s") + n_alSynSetVol(&ptr->unk_148->voice, 0, D_800FC7D8 * 2); -#pragma GLOBAL_ASM("asm/us/nonmatchings/38BB0/func_80039F28.s") + func_800429B0(&ptr->unk_148->voice, 0); + func_8003C3A0(ptr->unk_148); -#pragma GLOBAL_ASM("asm/us/nonmatchings/38BB0/func_8003A10C.s") + ptr->unk_148 = NULL; + ptr->unk_0DC = 1; + ptr->unk_0E1 = 0; + ptr->unk_03C = 0; + } -#pragma GLOBAL_ASM("asm/us/nonmatchings/38BB0/func_8003A234.s") + osSetIntMask(sp34); +} + +s32 func_80039A7C(SoundBank* arg0, s32 arg1, s32 arg2) { + u8* temp_s0; + s32 sp28; + UNUSED s32 pad; + u32 sp20; -#pragma GLOBAL_ASM("asm/us/nonmatchings/38BB0/func_8003A2F0.s") - -#pragma GLOBAL_ASM("asm/us/nonmatchings/38BB0/func_8003A39C.s") - -#pragma GLOBAL_ASM("asm/us/nonmatchings/38BB0/func_8003A438.s") - -#pragma GLOBAL_ASM("asm/us/nonmatchings/38BB0/func_8003A4D8.s") - -#pragma GLOBAL_ASM("asm/us/nonmatchings/38BB0/func_8003A564.s") - -#pragma GLOBAL_ASM("asm/us/nonmatchings/38BB0/func_8003A614.s") - -#pragma GLOBAL_ASM("asm/us/nonmatchings/38BB0/func_8003A6D4.s") - -#pragma GLOBAL_ASM("asm/us/nonmatchings/38BB0/func_8003A744.s") + if (arg0 == NULL) { + return 0; + } + + if (!(arg0->flags & 1)) { + return 0; + } + sp20 = osSetIntMask(1); + + temp_s0 = D_800FC7E8; + temp_s0 += D_800FC7EC; + + sp28 = D_800FC7E0++; + + *temp_s0++ = 11; + func_80038B30(temp_s0, arg0->header_name); + temp_s0 += sizeof(u32); + func_80038B30(temp_s0, arg1); + temp_s0 += sizeof(u32); + func_80038B30(temp_s0, sp28); + temp_s0 += sizeof(u32); + func_80038B30(temp_s0, arg2); + + D_800FC7EC += 17; + if (D_800FC7EC >= D_800FC7F0) { + D_800FC7EC -= 17; + } + + osSetIntMask(sp20); + + return sp28; +} + +s32 func_80039B88(s32 arg0, u8 arg1, u8 arg2, u32 arg3) { + u32 temp_v0; + + if (arg1 == arg2) { + return 0; + } + + if (D_80077DC4 != 0) { + return 0; + } + + temp_v0 = osSetIntMask(1); + + D_80077DC4 = arg0; + D_80077DD0 = ((f32)arg2 - arg1) / arg3; + D_80077DC8 = arg1; + D_80077DCC = arg2; + + osSetIntMask(temp_v0); + + return 1; +} + +u32 func_80039C84(u8* arg0) { + u32 val = *arg0++ << 0x18; + val += *arg0++ << 0x10; + val += *arg0++ << 8; + val += *arg0++; + return val; +} + +u16 func_80039CB4(u8* arg0) { + u32 val = *arg0++ << 8; + val += *arg0++; + return val; +} + +void func_80039CD0(void) { + u8* var_s0 = D_800FC7E8; + s32 idx; + + while (D_800FC7EC) { + idx = *var_s0++; + D_800FC7EC--; + var_s0 = D_80077D5C[idx](var_s0); + } +} + +u8* func_80039D58(u8* arg0) { + unk_D_800FC7D0_08C* sp4C; + unk_D_800FC7D0_08C* temp_s2; + unk_D_800FC7D0_08C* sp44; + unk_D_800FC7D0* temp_s0; + u32 i; + u32 count; + u32 temp_v0; + + sp44 = func_80039C84(arg0); + arg0 += 4; + temp_s2 = func_80039C84(arg0); + arg0 += 4; + sp4C = func_80039C84(arg0); + arg0 += 4; + + D_800FC7EC -= 0xC; + + count = temp_s2->unk_00; + if ((u32)temp_s2->unk_04 < 0x400) { + func_8003C204(&temp_s2->unk_04, temp_s2, 5); + func_8003C204(temp_s2->unk_04, temp_s2, count); + func_8003C204(temp_s2->unk_08, temp_s2, count); + func_8003C204(temp_s2->unk_0C, temp_s2, count); + } + + for (i = 0; i < count; i++) { + if (temp_s2->unk_04[i] == 0) { + continue; + } + + temp_v0 = func_8003C180(temp_s2, i); + if (temp_v0 == -1) { + continue; + } + + temp_s0 = &D_800FC7D0[temp_v0]; + func_8003BFF4(temp_s0); + temp_s0->unk_08C = temp_s2; + temp_s0->unk_090 = sp44; + temp_s0->unk_060 = temp_s0->unk_0A0 = temp_s0->unk_08C->unk_08[i]; + temp_s0->unk_05C = temp_s0->unk_09C = temp_s0->unk_08C->unk_0C[i]; + temp_s0->unk_038 = temp_s0->unk_094 = temp_s0->unk_08C->unk_04[i]; + temp_s0->unk_064 = sp4C; + temp_s0->unk_068 = 0x3C; + } + + D_80077C90 = -1; + return arg0; +} + +u8* func_80039F28(u8* arg0) { + u32 sp5C; + u32 i; + u32 sp54; + s32 temp_v0; + u32 temp_fp; + unk_D_800FC7D0_08C* temp_s2; + unk_D_800FC7D0* temp_s0; + u32 sp40; + + sp54 = func_80039C84(arg0); + arg0 += 4; + temp_s2 = func_80039C84(arg0); + arg0 += 4; + sp5C = func_80039C84(arg0); + arg0 += 4; + sp40 = func_80039C84(arg0); + arg0 += 4; + + D_800FC7EC -= 0x10; + + temp_fp = temp_s2->unk_00; + if ((u32)temp_s2->unk_04 < 0x400) { + func_8003C204(&temp_s2->unk_04, temp_s2, 5); + func_8003C204(temp_s2->unk_04, temp_s2, temp_fp); + func_8003C204(temp_s2->unk_08, temp_s2, temp_fp); + func_8003C204(temp_s2->unk_0C, temp_s2, temp_fp); + } + + for (i = 0; i < temp_fp; i++) { + if (temp_s2->unk_04[i] == 0) { + continue; + } + + temp_v0 = func_8003C180(temp_s2, i); + if (temp_v0 == -1) { + continue; + } + + temp_s0 = &D_800FC7D0[temp_v0]; + func_8003BFF4(temp_s0); + temp_s0->unk_08C = temp_s2; + temp_s0->unk_090 = sp54; + temp_s0->unk_060 = temp_s0->unk_0A0 = temp_s2->unk_08[i]; + temp_s0->unk_05C = temp_s0->unk_09C = temp_s2->unk_0C[i]; + temp_s0->unk_038 = temp_s0->unk_094 = temp_s2->unk_04[i]; + temp_s0->unk_064 = sp5C; + temp_s0->unk_068 = 0x3C; + } + + D_80077C90 = sp40; + return arg0; +} + +u8* func_8003A10C(u8* arg0) { + u32 sp44; + unk_D_800FC7D0_140* sp40; + u32* sp3C; + u32 sp38; + u32 sp34; + u32 i; + u8 var_t0; + u8 var_t1; + u8 var_t2; + unk_D_800FC7D0* var_a0; + unk_D_800FC7D0_08C_008* a; + + sp44 = func_80039C84(arg0); + arg0 += 4; + sp40 = func_80039C84(arg0); + arg0 += 4; + sp38 = func_80039C84(arg0); + arg0 += 4; + sp34 = func_80039C84(arg0); + arg0 += 4; + + var_t2 = *arg0++; + var_t1 = *arg0++; + var_t0 = *arg0++; + + D_800FC7EC -= 0x13; + sp3C = sp40->unk_0C; + a = sp40->unk_08; + + if (var_t0 == 0xFF) { + var_t0 = a[sp34].unk_00[3]; + } + + for (i = 0, var_a0 = D_800FC7D0; i < D_800FC7CC; i++, var_a0++) { + if (var_a0->unk_038 == NULL) { + func_8003C2A4(var_a0, sp34, var_t2, var_t1, var_t0); + var_a0->unk_064 = sp38; + var_a0->unk_090 = sp44; + var_a0->unk_140 = sp40; + var_a0->unk_038 = var_a0->unk_094 = sp3C[sp34]; + break; + } + } + + return arg0; +} + +u8* func_8003A234(u8* arg0) { + u32 sp1C; + s32 i; + s16 temp_v0; + unk_D_800FC7D0* var_a0; + + sp1C = func_80039C84(arg0); + arg0 += 4; + temp_v0 = func_80039CB4(arg0); + arg0 += 2; + + D_800FC7EC -= 6; + + for (i = 0, var_a0 = D_800FC7D0; i < D_800FC7CC; i++, var_a0++) { + if (sp1C == var_a0->unk_064) { + var_a0->unk_058 = var_a0->unk_0A4 + (temp_v0 / 255.0f); + } + } + + return arg0; +} + +u8* func_8003A2F0(u8* arg0) { + u32 sp24; + u16 temp_v0; + unk_D_800FC7D0* var_v1; + u32 i; + u8 val; + + sp24 = func_80039C84(arg0); + arg0 += 4; + temp_v0 = func_80039CB4(arg0); + arg0 += 2; + + D_800FC7EC -= 6; + + for (i = 0, var_v1 = D_800FC7D0; i < D_800FC7CC; i++, var_v1++) { + if (sp24 == var_v1->unk_064) { + val = temp_v0; + var_v1->unk_0AC = val; + var_v1->unk_0B0 = (var_v1->unk_0BC * val) >> 7; + } + } + + return arg0; +} + +u8* func_8003A39C(u8* arg0) { + u32 sp1C; + u32 i; + unk_D_800FC7D0* var_v1; + u16 temp_v0; + u8 val; + + sp1C = func_80039C84(arg0); + arg0 += 4; + temp_v0 = func_80039CB4(arg0); + arg0 += 2; + + D_800FC7EC -= 6; + + for (i = 0, var_v1 = D_800FC7D0; i < D_800FC7CC; i++, var_v1++) { + if (sp1C == var_v1->unk_064) { + val = temp_v0; + var_v1->unk_0B2 = val; + } + } + + return arg0; +} + +u8* func_8003A438(u8* arg0) { + u32 sp24; + u32 i; + u16 temp_v0; + unk_D_800FC7D0* var_v1; + u8 val; + + sp24 = func_80039C84(arg0); + arg0 += 4; + temp_v0 = func_80039CB4(arg0); + arg0 += 2; + + D_800FC7EC -= 6; + + for (i = 0, var_v1 = D_800FC7D0; i < D_800FC7CC; i++, var_v1++) { + if (sp24 == var_v1->unk_064) { + val = temp_v0; + var_v1->unk_0C4 = val; + var_v1->unk_0D2 = 0xFF; + } + } + + return arg0; +} + +u8* func_8003A4D8(u8* arg0) { + u32 i; + u32 temp_v0; + unk_D_800FC7D0* var_v1; + u8 val; + + temp_v0 = func_80039C84(arg0); + arg0 += 4; + val = *arg0++; + + D_800FC7EC -= 5; + + for (i = 0, var_v1 = D_800FC7D0; i < D_800FC7CC; i++, var_v1++) { + if (temp_v0 == var_v1->unk_064) { + var_v1->unk_0E3 = val; + var_v1->unk_0E4 = 0xFF; + } + } + + return arg0; +} + +u8* func_8003A564(u8* arg0) { + u32 sp24; + u32 i; + u32 var_a2; + u16 temp_v0; + unk_D_800FC7D0* var_v1; + + sp24 = func_80039C84(arg0); + arg0 += 4; + temp_v0 = func_80039CB4(arg0); + arg0 += 2; + + D_800FC7EC -= 6; + + if (sp24 != 0) { + if (temp_v0 != 0) { + var_a2 = temp_v0 & 0xFFFF; + } else { + var_a2 = 1; + } + + for (i = 0, var_v1 = D_800FC7D0; i < D_800FC7CC; i++, var_v1++) { + if (sp24 == var_v1->unk_064) { + var_v1->unk_040 = temp_v0; + var_v1->unk_044 = var_a2; + } + } + } + + return arg0; +} + +u8* func_8003A614(u8* arg0) { + u8 sp27; + u32 i; + u32 var_t0; + u32 temp_v0; + unk_D_800FC7D0* var_a0; + + sp27 = *arg0++; + temp_v0 = func_80039CB4(arg0); + arg0 += 2; + + D_800FC7EC -= 3; + + if (temp_v0 != 0) { + var_t0 = temp_v0 & 0xFFFF; + } else { + var_t0 = 1; + } + + for (i = 0, var_a0 = D_800FC7D0; i < D_800FC7CC; i++, var_a0++) { + if (((var_a0->unk_0BA != 0) && (sp27 & 1)) || ((var_a0->unk_0BA == 0) && (sp27 & 2))) { + var_a0->unk_040 = temp_v0; + var_a0->unk_044 = var_t0; + } + } + + return arg0; +} + +u8* func_8003A6D4(u8* arg0) { + u8 sp1F; + u16 temp_v0; + + sp1F = *arg0++; + temp_v0 = func_80039CB4(arg0); + arg0 += 2; + + D_800FC7EC -= 3; + + if (sp1F & 1) { + D_800FC7DC = temp_v0; + } + + if (sp1F & 2) { + D_800FC7DE = temp_v0; + } + + return arg0; +} + +u8* func_8003A744(u8* arg0) { + u8 val = *arg0++; + + D_800FC7EC--; + + if (val == 1) { + D_800FC7F4 = 1; + } else { + D_800FC7F4 = 0; + } + return arg0; +} + +#ifdef NON_MATCHING +s32 func_8003A78C(void* arg0) { + s32 i; + UNUSED s32 pad4[1]; + f32 spA4; + UNUSED s32 pad[4]; + ALVoiceConfig sp8C; + UNUSED s32 pad2[3]; + UNUSED s32 pad3[1]; + f32 var_fs0; + s32 temp_s3; + u32 var_s4; + u32 temp_s1; + s32 var_s2; + unk_D_800FC7D0* ptr; + + if (D_80077C90 > 0) { + D_80077C90--; + } + + if (D_80077C90 == 0) { + func_80039940(); + D_80077C90 = -1; + } + + func_80039CD0(); + + ptr = D_800FC7D0; + + for (i = 0; i < D_800FC7CC; i++, ptr++) { + if (ptr->unk_038 == 0) { + continue; + } + + ptr->unk_008 += ptr->unk_0B0; + + if (ptr->unk_0AE != 0x7FFF) { + while ((ptr->unk_008 > ptr->unk_020) && (ptr->unk_038 != 0)) { + func_8003AD58(ptr); + } + } + + if (ptr->unk_060 != 0) { + if (ptr->unk_010 < ptr->unk_008) { + func_8003B94C(ptr); + } + } + + if (ptr->unk_05C != 0) { + if (ptr->unk_018 < ptr->unk_008) { + func_8003BA44(ptr); + } + } + + if (ptr->unk_040 != -1) { + ptr->unk_040--; + if (ptr->unk_040 == -1) { + ptr->unk_038 = func_80037FB0(ptr, 0); + if (ptr->unk_0E1 != 0) { + ptr->unk_0E1 = 0; + n_alSynStopVoice(&ptr->unk_148->voice); + n_alSynFreeVoice(&ptr->unk_148->voice); + ptr->unk_148->unk_2A = 5; + func_8003C2F8(ptr->unk_148); + ptr->unk_148 = NULL; + ptr->unk_0BA = 0; + } + ptr->unk_03C = 0; + } + } + + if (ptr->unk_03C == 0) { + continue; + } + + func_8003B2B4(ptr); + + if (ptr->unk_03C == 0) { + continue; + } + + spA4 = ptr->unk_058; + if (ptr->unk_0EC != 0) { + spA4 += func_8003B8A4(ptr); + } + + if (ptr->unk_0E5 != 0) { + spA4 += func_8003B854(ptr); + } + + var_fs0 = func_8003B0DC(ptr, spA4); + temp_s3 = func_8003B00C(ptr); + + if (ptr->unk_0EB != 0) { + if (ptr->unk_0A8 < ptr->unk_008) { + func_8003B788(ptr); + } + } + + if (D_800FC7F4 == 1) { + var_s2 = 0x40; + } else { + var_s2 = ((ptr->unk_0D1 * ptr->unk_0C4) >> 7) & 0x7F; + } + + var_s4 = ptr->unk_008 - ptr->unk_028; + ptr->unk_0BE = var_s4 >> 8; + + temp_s1 = ptr->unk_0E3; + temp_s1 += (((0x80 - temp_s1) * ptr->unk_0E2) >> 7); + + if (ptr->unk_0E1 != 0) { + if (var_fs0 != 0.0f) { + n_alSynSetPitch(&ptr->unk_148->voice, var_fs0); + } + + if (temp_s3 != ptr->unk_0B4) { + ptr->unk_0B4 = temp_s3; + n_alSynSetVol(&ptr->unk_148->voice, temp_s3, D_800FC7D8); + } + + if (var_s2 != ptr->unk_0D2) { + ptr->unk_0D2 = var_s2; + n_alSynSetPan(&ptr->unk_148->voice, var_s2); + } + + if (ptr->unk_0E2 != ptr->unk_0E4) { + ptr->unk_0E4 = temp_s1; + n_alSynSetFXMix(&ptr->unk_148->voice, temp_s1); + } + } else { + ptr->unk_148 = func_8003C35C(); + if (ptr->unk_148 == NULL) { + ptr->unk_03C = 0; + continue; + } + + ptr->unk_148->unk_2A = ptr->unk_0D7; + ptr->unk_148->unk_28 = ptr->unk_0E0; + + if (ptr->unk_068 >= 0x80) { + sp8C.priority = 0x7F; + } else { + sp8C.priority = ptr->unk_068; + } + + sp8C.unityPitch = 0; + sp8C.fxBus = 0; + n_alSynAllocVoice(&ptr->unk_148->voice, &sp8C); + + ptr->unk_0B4 = temp_s3; + ptr->unk_0D2 = var_s2; + ptr->unk_0E4 = temp_s1; + + if (var_fs0 == 0.0f) { + var_fs0 = func_8003BBA4(ptr->unk_050 * 0.0833333333333333287); + if (var_fs0 > 2.0) { + var_fs0 = 2.0f; + } + } + + if (D_80077C94 == 0) { + n_alSynStartVoiceParams(&ptr->unk_148->voice, ptr->unk_03C, var_fs0, temp_s3, var_s2, temp_s1, + D_800FC7D8); + } else { + n_alSynStartVoiceParams(&ptr->unk_148->voice, ptr->unk_03C, var_fs0, temp_s3, var_s2, temp_s1, 1); + } + + ptr->unk_0DC = 0; + ptr->unk_0E1 = 1; + ptr->unk_148->unk_2A = 1; + } + } + + func_8003C408(); + D_800FC7F8++; + + return D_800FC7D8; +} +#else #pragma GLOBAL_ASM("asm/us/nonmatchings/38BB0/func_8003A78C.s") - -#pragma GLOBAL_ASM("asm/us/nonmatchings/38BB0/func_8003AD58.s") - -#pragma GLOBAL_ASM("asm/us/nonmatchings/38BB0/func_8003B00C.s") - -#pragma GLOBAL_ASM("asm/us/nonmatchings/38BB0/func_8003B0DC.s") - -#pragma GLOBAL_ASM("asm/us/nonmatchings/38BB0/func_8003B214.s") - -#pragma GLOBAL_ASM("asm/us/nonmatchings/38BB0/func_8003B2B4.s") - -#pragma GLOBAL_ASM("asm/us/nonmatchings/38BB0/func_8003B76C.s") - -#pragma GLOBAL_ASM("asm/us/nonmatchings/38BB0/func_8003B788.s") - -#pragma GLOBAL_ASM("asm/us/nonmatchings/38BB0/func_8003B854.s") - -#pragma GLOBAL_ASM("asm/us/nonmatchings/38BB0/func_8003B8A4.s") - -#pragma GLOBAL_ASM("asm/us/nonmatchings/38BB0/func_8003B94C.s") - -#pragma GLOBAL_ASM("asm/us/nonmatchings/38BB0/func_8003BA44.s") - -#pragma GLOBAL_ASM("asm/us/nonmatchings/38BB0/func_8003BBA4.s") - -#pragma GLOBAL_ASM("asm/us/nonmatchings/38BB0/func_8003BD2C.s") - -#pragma GLOBAL_ASM("asm/us/nonmatchings/38BB0/func_8003BEF4.s") - -#pragma GLOBAL_ASM("asm/us/nonmatchings/38BB0/func_8003BFF4.s") - -#pragma GLOBAL_ASM("asm/us/nonmatchings/38BB0/func_8003C180.s") - -#pragma GLOBAL_ASM("asm/us/nonmatchings/38BB0/func_8003C1D0.s") - -#pragma GLOBAL_ASM("asm/us/nonmatchings/38BB0/func_8003C204.s") - -#pragma GLOBAL_ASM("asm/us/nonmatchings/38BB0/func_8003C2A4.s") - -#pragma GLOBAL_ASM("asm/us/nonmatchings/38BB0/func_8003C2F8.s") - -#pragma GLOBAL_ASM("asm/us/nonmatchings/38BB0/func_8003C35C.s") - -#pragma GLOBAL_ASM("asm/us/nonmatchings/38BB0/func_8003C3A0.s") - -#pragma GLOBAL_ASM("asm/us/nonmatchings/38BB0/func_8003C408.s") +#endif + +void func_8003AD58(unk_D_800FC7D0* arg0) { + s32 pad[2]; + unk_D_800FC7D0_08C* temp_s0; + u8* var_s0; + u8 temp_a0; + u8 tmp; + u8 tmp1; + u16 tmp2; + u32 tmp3; + + var_s0 = arg0->unk_038; + while (var_s0 != NULL && (tmp1 = *var_s0) >= 0x80) { + var_s0 = D_80077C98[tmp1 & 0x7F](arg0, var_s0 + 1); + } + arg0->unk_038 = var_s0; + + if (arg0->unk_038 != NULL) { + arg0->unk_06C = arg0->unk_070; + tmp = *arg0->unk_038++; + + if (arg0->unk_0E9 != 0) { + arg0->unk_0CF = *arg0->unk_038++; + } else { + arg0->unk_0CF = arg0->unk_0EA; + } + + if (arg0->unk_0C0 != 0) { + if (arg0->unk_0CB == 0) { + arg0->unk_0AE = arg0->unk_0C0; + } else { + arg0->unk_0CB = 0; + temp_a0 = *arg0->unk_038++; + if (temp_a0 < 0x80) { + arg0->unk_0AE = temp_a0; + } else { + arg0->unk_0AE = *arg0->unk_038++ + ((temp_a0 & 0x7F) << 8); + } + } + } else { + temp_a0 = *arg0->unk_038++; + if (temp_a0 < 0x80) { + arg0->unk_0AE = temp_a0 ^ 0; + } else { + arg0->unk_0AE = *arg0->unk_038++ + ((temp_a0 & 0x7F) << 8); + } + } + + arg0->unk_028 = arg0->unk_020; + arg0->unk_020 += arg0->unk_0AE << 8; + + arg0->unk_0BE = 0; + arg0->unk_0E8 = 0; + arg0->unk_0E7 = arg0->unk_0E6; + + if (tmp != 0x60) { + temp_s0 = arg0->unk_090; + func_8003B214(arg0); + + if (arg0->unk_0EB != 0) { + func_8003B76C(arg0); + } + + if (arg0->unk_0E1 != 0) { + arg0->unk_03C = NULL; + func_8003B2B4(arg0); + } + + tmp2 = arg0->unk_0C2; + tmp3 = temp_s0->unk_2C[tmp2]; + arg0->unk_03C = tmp3; + arg0->unk_054 = temp_s0->unk_28[tmp2] + tmp; + } else { + arg0->unk_03C = NULL; + if (arg0->unk_0E1 != 0) { + arg0->unk_030 = arg0->unk_008; + func_8003B2B4(arg0); + } + } + } else { + arg0->unk_03C = NULL; + if (arg0->unk_0E1 != 0) { + arg0->unk_030 = arg0->unk_008; + func_8003B2B4(arg0); + } + } +} + +s32 func_8003B00C(unk_D_800FC7D0* arg0) { + u32 var_v1 = arg0->unk_0D0 * arg0->unk_0D8 * arg0->unk_0CF * arg0->unk_0B2; + + var_v1 >>= 0xD; + if (arg0->unk_0BA == 0) { + var_v1 *= D_800FC7DE; + } else { + var_v1 *= D_800FC7DC; + } + + var_v1 >>= 0xF; + if (var_v1 >= 0x8000) { + var_v1 = 0x7FFF; + } + + if (arg0->unk_040 != -1) { + var_v1 = (arg0->unk_040 * var_v1) / arg0->unk_044; + } + + return var_v1; +} + +f32 func_8003B0DC(unk_D_800FC7D0* arg0, f32 arg1) { + f32 temp_fv1; + f32 var_fv1; + f32 var_fv1_2; + s32 temp_lo; + + temp_fv1 = arg0->unk_054; + if (arg0->unk_0CC != 0) { + if (arg0->unk_0CC >= arg0->unk_0BE) { + var_fv1_2 = ((temp_fv1 - arg0->unk_06C) / arg0->unk_0CC); + var_fv1_2 *= arg0->unk_0BE; + temp_fv1 = arg0->unk_06C + var_fv1_2; + } + arg0->unk_070 = temp_fv1; + } + + temp_lo = arg0->unk_0CD * (1 - arg0->unk_0CE); + + arg0->unk_0CE = 0; + + temp_fv1 += (arg1 + arg0->unk_04C + temp_lo); + if (temp_fv1 == arg0->unk_050) { + return 0.0f; + } + arg0->unk_050 = temp_fv1; + + temp_fv1 = func_8003BBA4(temp_fv1 * 0.0833333333333333287); + if (temp_fv1 > 2.0) { + temp_fv1 = 2.0f; + arg0->unk_0CF = 0; + } + + return temp_fv1; +} + +void func_8003B214(unk_D_800FC7D0* arg0) { + s32 temp_t7; + s32 temp_t7_2; + u16 temp_v0; + u32 temp_t3; + u32 temp_t5; + + if (arg0->unk_0AE != 0x7FFF) { + if (arg0->unk_0C6 != 0) { + arg0->unk_030 = arg0->unk_028 + (arg0->unk_0C6 << 8); + } else { + arg0->unk_030 = arg0->unk_020 - (arg0->unk_0C8 << 8); + } + } else { + arg0->unk_030 = 0x7FFFFFFF; + } + + arg0->unk_0D8 = arg0->unk_0D4; + arg0->unk_0D9 = arg0->unk_0D3; + arg0->unk_0D7 = 1; +} + +void func_8003B2B4(unk_D_800FC7D0* arg0) { + u32 temp_ft4; + s32 var_v1; + u32 temp_a0; + + if (arg0->unk_148 != NULL) { + if (((arg0->unk_008 >= arg0->unk_030) && (arg0->unk_148->unk_2A < 4)) || (arg0->unk_03C == 0)) { + arg0->unk_148->unk_2A = 4; + temp_ft4 = (f32)arg0->unk_148->unk_28 / ((f32)arg0->unk_0B0 * 0.00390625); + if (temp_ft4 == 0) { + temp_ft4++; + } + arg0->unk_148->unk_24 = D_800FC7F8 + temp_ft4 + 1; + + n_alSynSetVol(&arg0->unk_148->voice, 0, D_800FC7D8 * temp_ft4); + + if (arg0->unk_068 < 0x80) { + if (arg0->unk_0BA != 0) { + func_800429B0(&arg0->unk_148->voice, 1); + } else { + func_800429B0(&arg0->unk_148->voice, 0); + } + } + + func_8003C3A0(arg0->unk_148); + + arg0->unk_148 = NULL; + arg0->unk_0DC = 1; + arg0->unk_0E1 = 0; + arg0->unk_03C = 0; + } else { + switch (arg0->unk_148->unk_2A) { + case 1: + temp_a0 = (u32)(arg0->unk_008 - arg0->unk_028) >> 8; + if (temp_a0 < arg0->unk_0DA) { + arg0->unk_0D8 = arg0->unk_074 * temp_a0; + } else { + arg0->unk_148->unk_2A++; + arg0->unk_0D8 = arg0->unk_0D5; + } + break; + + case 2: + temp_a0 = ((arg0->unk_008 - arg0->unk_028) >> 8) - arg0->unk_0DA; + if (temp_a0 < arg0->unk_0DB) { + arg0->unk_0D8 = arg0->unk_0D5 + (s32)(arg0->unk_078 * temp_a0); + } else { + arg0->unk_148->unk_2A++; + arg0->unk_0D8 = arg0->unk_0D6; + } + break; + + case 3: + case 4: + break; + } + } + } else { + temp_a0 = (u32)(arg0->unk_008 - arg0->unk_028) >> 8; + if ((temp_a0 < arg0->unk_0DA) && (arg0->unk_0DA >= 2)) { + arg0->unk_0D7 = 1; + arg0->unk_0D8 = arg0->unk_074 * temp_a0; + } else { + arg0->unk_0D7 = 2; + arg0->unk_0D8 = arg0->unk_0D5; + } + } +} + +void func_8003B76C(unk_D_800FC7D0* arg0) { + arg0->unk_0A8 = arg0->unk_028; + arg0->unk_0F0 = 0; + arg0->unk_0F1 = arg0->unk_0C4 & 0x80; +} + +void func_8003B788(unk_D_800FC7D0* arg0) { + u32 temp_v1; + u32 var_v0; + + do { + arg0->unk_0A8 += 0x100; + + temp_v1 = arg0->unk_0F0 + (arg0->unk_0EB * 2); + if (temp_v1 < 0x80) { + arg0->unk_0F0 = temp_v1; + continue; + } + + arg0->unk_0F0 = temp_v1 & 0x7F; + temp_v1 >>= 7; + if (arg0->unk_0F1 == 0) { + var_v0 = arg0->unk_0C4; + var_v0 += temp_v1; + if (var_v0 >= 0xFF) { + var_v0 = 0xFE; + arg0->unk_0F1 = 1; + } + arg0->unk_0C4 = var_v0; + } else { + var_v0 = arg0->unk_0C4; + var_v0 -= temp_v1; + if ((var_v0 >= 0xFF) || (var_v0 == 0)) { + var_v0 = 1; + arg0->unk_0F1 = 0; + } + arg0->unk_0C4 = var_v0; + } + } while (arg0->unk_0A8 < arg0->unk_008); + + arg0->unk_0D2 = 0xFF; +} + +f32 func_8003B854(unk_D_800FC7D0* arg0) { + arg0->unk_0E7--; + if (!arg0->unk_0E7) { + if (arg0->unk_0E8 == 0) { + arg0->unk_0E8 = arg0->unk_0EF; + arg0->unk_0E7 = arg0->unk_0E5; + } else { + arg0->unk_0E8 = 0; + arg0->unk_0E7 = arg0->unk_0E6; + } + } + + return arg0->unk_0E8; +} + +f32 func_8003B8A4(unk_D_800FC7D0* arg0) { + u32 temp_v0 = arg0->unk_0BE - arg0->unk_0CA; + f32 tmp; + + if (temp_v0 != 0) { + tmp = __sinf(((temp_v0 / (f32)arg0->unk_0EC) * 2) * 3.14159260000000007) * arg0->unk_048; + arg0->unk_080 = tmp; + } + return arg0->unk_080; +} + +void func_8003B94C(unk_D_800FC7D0* arg0) { + s32 tmp; + + do { + arg0->unk_010 += 0x100; + + arg0->unk_0B6--; + if (arg0->unk_0B6) { + continue; + } + + tmp = *arg0->unk_060++; + if (tmp >= 0x80u) { + arg0->unk_0D0 = tmp & 0x7F; + + tmp = *arg0->unk_060++; + if (tmp >= 0x80u) { + arg0->unk_0B6 = (tmp & 0x7F) << 8; + arg0->unk_0B6 += *arg0->unk_060++ + 2; + } else { + arg0->unk_0B6 = tmp + 2; + } + } else { + arg0->unk_0D0 = tmp; + arg0->unk_0B6 = 1; + } + } while (arg0->unk_010 < arg0->unk_008); +} + +void func_8003BA44(unk_D_800FC7D0* arg0) { + u8 tmp; + + do { + arg0->unk_018 += 0x100; + + arg0->unk_0B8--; + if (arg0->unk_0B8) { + continue; + } + + tmp = *arg0->unk_05C++; + if (tmp >= 0x80) { + arg0->unk_088 = (f32)(tmp & 0x7F) - 64.0; + arg0->unk_04C = arg0->unk_088 * arg0->unk_084; + tmp = *arg0->unk_05C++; + if (tmp >= 0x80) { + arg0->unk_0B8 = (tmp & 0x7F) << 8; + arg0->unk_0B8 += *arg0->unk_05C++ + 2; + } else { + arg0->unk_0B8 = tmp + 2; + } + } else { + arg0->unk_088 = (f32)(tmp)-64.0; + arg0->unk_04C = arg0->unk_088 * arg0->unk_084; + arg0->unk_0B8 = 1; + } + } while (arg0->unk_018 < arg0->unk_008); +} + +f32 func_8003BBA4(f32 arg0) { + f32 temp_fa1; + f32 temp_fv1; + + if (arg0 == 0.0f) { + return 1.0f; + } + + if (arg0 > 0.0f) { + temp_fv1 = SQ(arg0); + temp_fa1 = SQ(temp_fv1); + return (arg0 * 0.693147180559944953) + 1.0 + (temp_fv1 * 0.240226506959100999) + + ((temp_fv1 * arg0) * 0.055504108664821597) + (temp_fa1 * 0.00961812910762848035) + + ((temp_fa1 * arg0) * 0.00133335581464283999) + ((temp_fa1 * temp_fv1) * 0.000154035303933816006); + } else { + arg0 = -arg0; + temp_fv1 = SQ(arg0); + temp_fa1 = SQ(temp_fv1); + return 1.0 / ((arg0 * 0.693147180559944953) + 1.0 + (temp_fv1 * 0.240226506959100999) + + ((temp_fv1 * arg0) * 0.055504108664821597) + (temp_fa1 * 0.00961812910762848035) + + ((temp_fa1 * arg0) * 0.00133335581464283999) + ((temp_fa1 * temp_fv1) * 0.000154035303933816006)); + } +} + +void func_8003BD2C(u8* arg0, s32 arg1) { + UNUSED s32 pad; + u32 i; + f32 var_fv0; + SoundBank* soundbank = arg0; + u8 temp_v1; + + if (soundbank->flags & 1) { + return; + } + + soundbank->flags |= 1; + + func_8003C204(&soundbank->basenote, arg0, 3); + func_8003C204(soundbank->wave_list, arg0, soundbank->count); + + for (i = 0; i < soundbank->count; i++) { + f32* ptr = &soundbank->detune[i]; + + temp_v1 = *(u8*)ptr; + if (temp_v1 & 0x80) { + var_fv0 = -(0x100 - temp_v1); + } else { + var_fv0 = (s32)temp_v1; + } + *ptr = var_fv0 / 100.0; + + temp_v1 = soundbank->basenote[i] - 0x30; + if (temp_v1 & 0x80) { + var_fv0 = -(0x100 - temp_v1); + } else { + var_fv0 = (s32)temp_v1; + } + *ptr += var_fv0; + + if (soundbank->wave_list[i]->flags == 0) { + u32 tmp = soundbank->wave_list[i]->base; + + if ((tmp & 0xFF000000) != 0xFF000000) { + tmp += arg1; + soundbank->wave_list[i]->base = tmp; + } + + soundbank->wave_list[i]->flags = 1; + + if (soundbank->wave_list[i]->waveInfo.rawWave.loop != NULL) { + soundbank->wave_list[i]->waveInfo.rawWave.loop = + (u32)soundbank + (u32)soundbank->wave_list[i]->waveInfo.rawWave.loop; + } + + if (soundbank->wave_list[i]->type == AL_ADPCM_WAVE) { + soundbank->wave_list[i]->waveInfo.adpcmWave.book = + (u32)soundbank + (u32)soundbank->wave_list[i]->waveInfo.adpcmWave.book; + } + } + } + + osWritebackDCacheAll(); +} + +s32 func_8003BEF4(s32 arg0) { + s32 i; + s32 tmp; + f32 tmpf; + + for (i = 0; i < 8; i++) { + tmp = D_800FC7E4 & 0x48000000; + D_800FC7E4 <<= 1; + if ((tmp == 0x48000000) || (tmp == 0x08000000)) { + D_800FC7E4 |= 1; + } + } + + tmpf = D_800FC7E4 / 65536.0f; + tmpf /= 65536.0f; + return arg0 * tmpf; +} + +void func_8003BFF4(unk_D_800FC7D0* arg0) { + u8* ptr; + s32 i; + + arg0->unk_038 = 0; + arg0->unk_090 = 0; + arg0->unk_03C = 0; + arg0->unk_148 = NULL; + + arg0->unk_008 = 0; + arg0->unk_010 = 0; + arg0->unk_018 = 0; + arg0->unk_020 = 0; + arg0->unk_028 = 0; + arg0->unk_030 = 0; + + ptr = (u8*)&arg0->unk_030 + 4; + for (i = 0x34; i < 0x150; i++) { + *ptr++ = 0; + } + + arg0->unk_0B4 = 0xFFFF; + arg0->unk_0E4 = -1; + arg0->unk_0D2 = -1; + arg0->unk_050 = 99.90000153f; + + arg0->unk_0B0 = arg0->unk_0BC = 0x6000 / D_800FC7D4; + arg0->unk_0AE = 1; + + arg0->unk_0E9 = 0; + arg0->unk_0EA = 0x7F; + + if (1) {} + + arg0->unk_0C0 = 0; + arg0->unk_0CB = 0; + arg0->unk_0D0 = 0x7F; + arg0->unk_0D1 = 0x40; + arg0->unk_0B6 = 1; + arg0->unk_0B8 = 1; + arg0->unk_040 = -1; + arg0->unk_0EB = 0; + arg0->unk_0B2 = 0x80; + arg0->unk_0C4 = 0x80; + arg0->unk_0AC = 0x80; + arg0->unk_0D3 = 1; + arg0->unk_0DA = 1; + arg0->unk_0D5 = 0x7F; + arg0->unk_0DB = -1; + arg0->unk_084 = 0.03125f; + + arg0->unk_074 = 1.0f; + arg0->unk_078 = 0.003921568859f; + arg0->unk_04C = 0.0f; + arg0->unk_058 = 0.0f; + arg0->unk_070 = 0.0f; + arg0->unk_0A4 = 0.0f; + + arg0->unk_0D6 = 0x7F; + arg0->unk_0E0 = 1; + arg0->unk_0DC = 1; + arg0->unk_0EC = 0; + arg0->unk_0E5 = 0; + arg0->unk_0BA = 0; + arg0->unk_0E1 = 0; +} + +s32 func_8003C180(unk_D_800FC7D0_08C* arg0, s32 arg1) { + s32 i; + unk_D_800FC7D0* var_v0 = D_800FC7D0; + + for (i = 0; i < D_800FC7CC; i++, var_v0++) { + if (var_v0->unk_038 == NULL) { + return i; + } + } + + return -1; +} + +void func_8003C1D0(u8* arg0, u8 arg1, u32 arg2) { + u8* a0 = arg0; + + while (arg2--) { + *a0++ = arg1; + } +} + +void func_8003C204(u8* arg0, u32 arg1, u32 arg2) { + u32* ptr = arg0; + u32 i; + + for (i = 0; i < arg2; i++) { + if (ptr[i] != 0) { + ptr[i] += arg1; + } + } +} + +s32 func_8003C2A4(unk_D_800FC7D0* arg0, s32 arg1, s32 arg2, s32 arg3, s32 arg4) { + func_8003BFF4(arg0); + arg0->unk_0BA = arg1; + arg0->unk_0B2 = arg2; + arg0->unk_0C4 = arg3; + arg0->unk_068 = arg4; + return arg0->unk_064; +} + +void func_8003C2F8(unk_D_800FC7D0_148* arg0) { + if (D_800FC800 == NULL) { + D_800FC800 = D_800FC804 = arg0; + arg0->node.next = NULL; + } else { + D_800FC804->node.next = arg0; + arg0->node.next = NULL; + D_800FC804 = arg0; + } + + arg0->unk_2A = 5; + D_800FC818++; +} + +unk_D_800FC7D0_148* func_8003C35C(void) { + unk_D_800FC7D0_148* temp_v0; + + if (D_800FC800 == NULL) { + return NULL; + } + + temp_v0 = D_800FC800; + D_800FC800 = D_800FC800->node.next; + + D_800FC818--; + return temp_v0; +} + +void func_8003C3A0(unk_D_800FC7D0_148* arg0) { + if (D_800FC808 == NULL) { + D_800FC808 = D_800FC80C = arg0; + arg0->node.next = NULL; + arg0->node.prev = NULL; + } else { + D_800FC80C->node.next = arg0; + arg0->node.next = NULL; + arg0->node.prev = D_800FC80C; + D_800FC80C = arg0; + } + + D_800FC81C++; +} + +void func_8003C408(void) { + unk_D_800FC7D0_148* temp_s1; + unk_D_800FC7D0_148* var_s0; + + if (D_800FC808 != NULL) { + var_s0 = D_800FC808; + + do { + if (var_s0->unk_24 < D_800FC7F8) { + n_alSynStopVoice(&var_s0->voice); + n_alSynFreeVoice(&var_s0->voice); + + var_s0->unk_2A = 5; + if (var_s0->node.prev != NULL) { + if (var_s0->node.next != NULL) { + var_s0->node.prev->next = var_s0->node.next; + var_s0->node.next->prev = var_s0->node.prev; + } else { + var_s0->node.prev->next = NULL; + D_800FC80C = var_s0->node.prev; + } + } else if (var_s0->node.next != NULL) { + D_800FC808 = var_s0->node.next; + if (!var_s0) {} + D_800FC808->node.prev = NULL; + } else { + D_800FC808 = D_800FC80C = NULL; + } + temp_s1 = var_s0->node.next; + D_800FC81C -= 1; + func_8003C2F8(var_s0); + var_s0 = temp_s1; + } else { + var_s0 = var_s0->node.next; + } + } while (var_s0 != NULL); + } +} diff --git a/src/38BB0.h b/src/38BB0.h index cba39cd3..974e7d14 100644 --- a/src/38BB0.h +++ b/src/38BB0.h @@ -2,13 +2,16 @@ #define _38BB0_H_ #include "global.h" +#include "src/libnaudio/n_libaudio_sc.h" +#include "src/libnaudio/n_libaudio_sn_sc.h" +#include "src/libnaudio/n_synthInternals.h" typedef struct sp38_func_800373D8 { /* 0x00 */ u32 unk_00; /* 0x04 */ u32 unk_04; /* 0x08 */ u32 unk_08; /* 0x0C */ void* unk_0C; - /* 0x10 */ u32 unk_10; + /* 0x10 */ s32 unk_10; /* 0x14 */ u32 unk_14; /* 0x18 */ u32 unk_18; /* 0x1C */ u32 unk_1C; @@ -18,25 +21,260 @@ typedef struct sp38_func_800373D8 { /* 0x2C */ u32 unk_2C; } sp38_func_800373D8; // size >= 0x30 +typedef struct unk_D_800FC7D0_08C_010 { + /* 0x00 */ char unk00[0x7]; +} unk_D_800FC7D0_08C_010; // size = 0x7 + +typedef struct unk_D_800FC7D0_08C_008 { + /* 0x00 */ u8 unk_00[4]; +} unk_D_800FC7D0_08C_008; // size = 0x4 + +typedef struct unk_D_800FC7D0_08C { + /* 0x00 */ u32 unk_00; + /* 0x04 */ u32* unk_04; + /* 0x08 */ unk_D_800FC7D0_08C_008** unk_08; + /* 0x0C */ u32* unk_0C; + /* 0x10 */ unk_D_800FC7D0_08C_010* unk_10; + /* 0x14 */ s32* unk_14; + /* 0x18 */ char unk18[0x10]; + /* 0x28 */ f32* unk_28; + /* 0x2C */ u32* unk_2C; +} unk_D_800FC7D0_08C; // size >= 0x18 + +typedef struct unk_D_800FC7D0_140 { + /* 0x00 */ char unk00[0x8]; + /* 0x08 */ unk_D_800FC7D0_08C_008** unk_08; + /* 0x0C */ u32* unk_0C; +} unk_D_800FC7D0_140; // size >= 0x10 + +typedef struct unk_D_800FC7D0_148 { + /* 0x00 */ ALLink node; + /* 0x08 */ N_ALVoice voice; + /* 0x24 */ s32 unk_24; + /* 0x28 */ u16 unk_28; + /* 0x2A */ u8 unk_2A; +} unk_D_800FC7D0_148; // size >= 0x2C + +typedef struct unk_D_800FC7D0 { + /* 0x000 */ struct unk_D_800FC7D0* unk_000; + /* 0x004 */ char unk004[0x4]; + /* 0x008 */ u64 unk_008; + /* 0x010 */ u64 unk_010; + /* 0x018 */ u64 unk_018; + /* 0x020 */ u64 unk_020; + /* 0x028 */ u64 unk_028; + /* 0x030 */ u64 unk_030; + /* 0x038 */ u8* unk_038; + /* 0x03C */ s32 unk_03C; + /* 0x040 */ s32 unk_040; + /* 0x044 */ s32 unk_044; + /* 0x048 */ f32 unk_048; + /* 0x04C */ f32 unk_04C; + /* 0x050 */ f32 unk_050; + /* 0x054 */ f32 unk_054; + /* 0x058 */ f32 unk_058; + /* 0x05C */ u8* unk_05C; + /* 0x060 */ u8* unk_060; + /* 0x064 */ s32 unk_064; + /* 0x067 */ s32 unk_068; + /* 0x06C */ f32 unk_06C; + /* 0x070 */ f32 unk_070; + /* 0x074 */ f32 unk_074; + /* 0x078 */ f32 unk_078; + /* 0x07C */ s32 unk_07C; + /* 0x080 */ f32 unk_080; + /* 0x084 */ f32 unk_084; + /* 0x088 */ f32 unk_088; + /* 0x08C */ unk_D_800FC7D0_08C* unk_08C; + /* 0x090 */ unk_D_800FC7D0_08C* unk_090; + /* 0x094 */ u8* unk_094; + /* 0x098 */ u8* unk_098; + /* 0x09C */ u8* unk_09C; + /* 0x0A0 */ u8* unk_0A0; + /* 0x0A4 */ f32 unk_0A4; + /* 0x0A8 */ u32 unk_0A8; + /* 0x0AC */ s16 unk_0AC; + /* 0x0AE */ u16 unk_0AE; + /* 0x0B0 */ u16 unk_0B0; + /* 0x0B2 */ s16 unk_0B2; + /* 0x0B4 */ u16 unk_0B4; + /* 0x0B6 */ u16 unk_0B6; + /* 0x0B8 */ u16 unk_0B8; + /* 0x0BA */ u16 unk_0BA; + /* 0x0BC */ u16 unk_0BC; + /* 0x0BE */ u16 unk_0BE; + /* 0x0C0 */ u16 unk_0C0; + /* 0x0C2 */ u16 unk_0C2; + /* 0x0C4 */ s16 unk_0C4; + /* 0x0C6 */ u16 unk_0C6; + /* 0x0C8 */ u16 unk_0C8; + /* 0x0CA */ u8 unk_0CA; + /* 0x0CB */ u8 unk_0CB; + /* 0x0CC */ u8 unk_0CC; + /* 0x0CD */ s8 unk_0CD; + /* 0x0CE */ u8 unk_0CE; + /* 0x0CF */ u8 unk_0CF; + /* 0x0D0 */ u8 unk_0D0; + /* 0x0D1 */ u8 unk_0D1; + /* 0x0D2 */ u8 unk_0D2; + /* 0x0D3 */ u8 unk_0D3; + /* 0x0D4 */ u8 unk_0D4; + /* 0x0D5 */ u8 unk_0D5; + /* 0x0D6 */ u8 unk_0D6; + /* 0x0D7 */ u8 unk_0D7; + /* 0x0D8 */ u8 unk_0D8; + /* 0x0D9 */ u8 unk_0D9; + /* 0x0DA */ u8 unk_0DA; + /* 0x0DB */ u8 unk_0DB; + /* 0x0DC */ u32 unk_0DC; + /* 0x0E0 */ u8 unk_0E0; + /* 0x0E1 */ u8 unk_0E1; + /* 0x0E2 */ u8 unk_0E2; + /* 0x0E3 */ u8 unk_0E3; + /* 0x0E4 */ u8 unk_0E4; + /* 0x0E5 */ u8 unk_0E5; + /* 0x0E6 */ u8 unk_0E6; + /* 0x0E7 */ u8 unk_0E7; + /* 0x0E8 */ s8 unk_0E8; + /* 0x0E9 */ u8 unk_0E9; + /* 0x0EA */ u8 unk_0EA; + /* 0x0EB */ u8 unk_0EB; + /* 0x0EC */ u8 unk_0EC; + /* 0x0ED */ u8 unk_0ED; + /* 0x0EE */ u8 unk_0EE; + /* 0x0EF */ s8 unk_0EF; + /* 0x0F0 */ u8 unk_0F0; + /* 0x0F1 */ u8 unk_0F1; + /* 0x0F2 */ u8 unk_0F2; + /* 0x0F4 */ u8* unk_0F4[4]; + /* 0x104 */ u8* unk_104[4]; + /* 0x114 */ u8* unk_114[4]; + /* 0x124 */ u16 unk_124[4]; + /* 0x12C */ u16 unk_12C[4]; + /* 0x134 */ u8 unk_134[4]; + /* 0x138 */ u8 unk_138[4]; + /* 0x13C */ u8 unk_13C[4]; + /* 0x140 */ unk_D_800FC7D0_140* unk_140; + /* 0x144 */ char unk144[0x4]; + /* 0x148 */ unk_D_800FC7D0_148* unk_148; + /* 0x14C */ char unk14C[0x4]; +} unk_D_800FC7D0; // size = 0x150 + +typedef struct unk_func_800397BC { + /* 0x00 */ u32 num_entries; + /* 0x04 */ u32 flags; + /* 0x08 */ u32* unk_offset; + /* 0x0C */ u32* entries_offset; +} unk_func_800397BC; // size = 0x10 + extern ALHeap* D_800FC810; +extern u32 D_800FC814; +extern s32 D_800FC818; +extern s32 D_800FC81C; -void func_80038B68(sp38_func_800373D8*); -void func_80038E98(s32, s32); -s32 func_80038F30(s32, s32); -s32 func_80039024(s32, s32, s32, s32, u32, s32); -void func_8003916C(s32, s32); -s32 func_80039204(s32); -void func_800392A8(s32, s32); -s32 func_80039354(s32); -void func_800393DC(s32, s32); -void func_80039534(s32, f32); -void func_800395FC(s32, s32); -void func_8003979C(s32, s32); -void func_800397BC(s32); -void func_8003986C(s32); -void func_800398F0(s32); +u8* func_80037FB0(unk_D_800FC7D0* arg0, UNUSED u8* arg1); +u8* func_80037FD0(unk_D_800FC7D0* arg0, u8* arg1); +u8* func_80038008(unk_D_800FC7D0* arg0, u8* arg1); +u8* func_8003802C(unk_D_800FC7D0* arg0, u8* arg1); +u8* func_80038038(unk_D_800FC7D0* arg0, u8* arg1); +u8* func_800381B4(unk_D_800FC7D0* arg0, u8* arg1); +u8* func_80038268(unk_D_800FC7D0* arg0, u8* arg1); +u8* func_8003827C(unk_D_800FC7D0* arg0, u8* arg1); +u8* func_800382AC(unk_D_800FC7D0* arg0, u8* arg1); +u8* func_80038304(unk_D_800FC7D0* arg0, u8* arg1); +u8* func_80038360(unk_D_800FC7D0* arg0, u8* arg1); +u8* func_80038374(unk_D_800FC7D0* arg0, u8* arg1); +u8* func_800383B8(unk_D_800FC7D0* arg0, u8* arg1); +u8* func_800383C8(unk_D_800FC7D0* arg0, u8* arg1); +u8* func_800383D8(unk_D_800FC7D0* arg0, u8* arg1); +u8* func_800383E8(unk_D_800FC7D0* arg0, u8* arg1); +u8* func_8003844C(unk_D_800FC7D0* arg0, u8* arg1); +u8* func_800384AC(unk_D_800FC7D0* arg0, u8* arg1); +u8* func_800384BC(unk_D_800FC7D0* arg0, u8* arg1); +u8* func_800384C8(unk_D_800FC7D0* arg0, u8* arg1); +u8* func_800384D8(unk_D_800FC7D0* arg0, u8* arg1); +u8* func_800384E4(unk_D_800FC7D0* arg0, u8* arg1); +u8* func_800385D0(unk_D_800FC7D0* arg0, u8* arg1); +u8* func_80038688(unk_D_800FC7D0* arg0, u8* arg1); +u8* func_800386A8(unk_D_800FC7D0* arg0, u8* arg1); +u8* func_800386B4(unk_D_800FC7D0* arg0, u8* arg1); +u8* func_800386C4(unk_D_800FC7D0* arg0, u8* arg1); +u8* func_800386D0(unk_D_800FC7D0* arg0, u8* arg1); +u8* func_800386E4(unk_D_800FC7D0* arg0, u8* arg1); +u8* func_80038704(UNUSED unk_D_800FC7D0* arg0, u8* arg1); +u8* func_80038710(unk_D_800FC7D0* arg0, u8* arg1); +u8* func_80038738(unk_D_800FC7D0* arg0, u8* arg1); +u8* func_80038744(UNUSED unk_D_800FC7D0* arg0, u8* arg1); +u8* func_80038750(unk_D_800FC7D0* arg0, u8* arg1); +u8* func_800387B4(unk_D_800FC7D0* arg0, u8* arg1); +u8* func_800387C4(unk_D_800FC7D0* arg0, u8* arg1); +u8* func_80038814(unk_D_800FC7D0* arg0, u8* arg1); +u8* func_80038864(unk_D_800FC7D0* arg0, u8* arg1); +u8* func_800388B4(unk_D_800FC7D0* arg0, u8* arg1); +u8* func_800388C4(unk_D_800FC7D0* arg0, u8* arg1); +u8* func_800389C0(unk_D_800FC7D0* arg0, u8* arg1); +u8* func_80038A10(unk_D_800FC7D0* arg0, u8* arg1); +u8* func_80038A34(unk_D_800FC7D0* arg0, u8* arg1); +void func_80038B30(u8* arg0, u32 arg1); +void func_80038B54(u8* arg0, u32 arg1); +s32 func_80038B68(sp38_func_800373D8* arg0); +void func_80038E98(s32 arg0, u32 arg1); +s32 func_80038F30(SoundBank* arg0, s32 arg1); +s32 func_80039024(SoundBank* arg0, s32 arg1, s32 arg2, s32 arg3, u32 arg4, s32 arg5); +void func_8003916C(s32 arg0, u32 arg1); +s32 func_80039204(s32 arg0); +void func_800392A8(s32 arg0, u32 arg1); +s32 func_80039354(s32 arg0); +void func_800393DC(s32 arg0, u32 arg1); +void func_80039488(s32 arg0, u16 arg1); +void func_80039534(s32 arg0, f32 arg1); +void func_800395FC(s32 arg0, s32 arg1); +void func_800396D0(u32 arg0, s32 arg1); +void func_8003979C(s32 arg0, s32 arg1); +void func_800397BC(unk_func_800397BC* arg0); +void func_8003986C(s32 arg0); +void func_800398F0(s32 arg0); void func_80039940(void); -s32 func_80039A7C(s32, s32, s32); -void func_80039B88(s32, s32, s32, s32); +s32 func_80039A7C(SoundBank* arg0, s32 arg1, s32 arg2); +s32 func_80039B88(s32 arg0, u8 arg1, u8 arg2, u32 arg3); +u32 func_80039C84(u8* arg0); +u16 func_80039CB4(u8* arg0); +void func_80039CD0(void); +u8* func_80039D58(u8* arg0); +u8* func_80039F28(u8* arg0); +u8* func_8003A10C(u8* arg0); +u8* func_8003A234(u8* arg0); +u8* func_8003A2F0(u8* arg0); +u8* func_8003A39C(u8* arg0); +u8* func_8003A438(u8* arg0); +u8* func_8003A4D8(u8* arg0); +u8* func_8003A564(u8* arg0); +u8* func_8003A614(u8* arg0); +u8* func_8003A6D4(u8* arg0); +u8* func_8003A744(u8* arg0); +s32 func_8003A78C(void* arg0); +void func_8003AD58(unk_D_800FC7D0* arg0); +s32 func_8003B00C(unk_D_800FC7D0* arg0); +f32 func_8003B0DC(unk_D_800FC7D0* arg0, f32 arg1); +void func_8003B214(unk_D_800FC7D0* arg0); +void func_8003B2B4(unk_D_800FC7D0* arg0); +void func_8003B76C(unk_D_800FC7D0* arg0); +void func_8003B788(unk_D_800FC7D0* arg0); +f32 func_8003B854(unk_D_800FC7D0* arg0); +f32 func_8003B8A4(unk_D_800FC7D0* arg0); +void func_8003B94C(unk_D_800FC7D0* arg0); +void func_8003BA44(unk_D_800FC7D0* arg0); +f32 func_8003BBA4(f32 arg0); +void func_8003BD2C(u8* arg0, s32 arg1); +s32 func_8003BEF4(s32 arg0); +void func_8003BFF4(unk_D_800FC7D0* arg0); +s32 func_8003C180(unk_D_800FC7D0_08C* arg0, s32 arg1); +void func_8003C1D0(u8* arg0, u8 arg1, u32 arg2); +void func_8003C204(u8* arg0, u32 arg1, u32 arg2); +s32 func_8003C2A4(unk_D_800FC7D0* arg0, s32 arg1, s32 arg2, s32 arg3, s32 arg4); +void func_8003C2F8(unk_D_800FC7D0_148* arg0); +unk_D_800FC7D0_148* func_8003C35C(void); +void func_8003C3A0(unk_D_800FC7D0_148* arg0); +void func_8003C408(void); #endif // _38BB0_H_ diff --git a/src/3D140.c b/src/3D140.c index 86d4d1c2..0e4fbbaa 100644 --- a/src/3D140.c +++ b/src/3D140.c @@ -1,12 +1,70 @@ #include "3D140.h" -#include "373A0.h" -#include "45720.h" +#include "lib/ultralib/include/PR/leo.h" +#include "src/373A0.h" +#include "src/38BB0.h" +#include "src/3D140.h" +#include "src/435D0.h" +#include "src/libnaudio/n_libaudio_sc.h" +#include "src/libnaudio/n_libaudio_sn_sc.h" +#include "src/45720.h" +#include "src/4A3E0.h" +#include "src/4BDC0.h" + +typedef union { + struct { + s16 type; + } gen; + struct { + s16 type; + struct AudioInfo* info; + } done; +} AudioMsg; // size = 0x8 + +typedef struct AudioInfo { + /* 0x00 */ s16* data; + /* 0x04 */ s16 frameSamples; + /* 0x08 */ AudioMsg msg; +} AudioInfo; // size = 0x10 + +#define NUM_ACMD_LISTS 2 +#define NUM_OUTPUT_BUFFERS 2 +#define MAX_MESGS 3 +#define NUM_DMA_BUFFERS 48 +#define SAMPLES 184 + +typedef struct AMAudioMgr { + /* 0x000 */ Acmd* ACMDList[NUM_ACMD_LISTS]; + /* 0x008 */ AudioInfo* audioInfo[NUM_OUTPUT_BUFFERS]; + /* 0x010 */ char unk10[0x228]; + ///* 0x010 */ OSThread thread; + ///* 0x1C0 */ OSMesgQueue audioFrameMsgQ; + ///* 0x1D8 */ OSMesg audioFrameMsgBuf[MAX_MESGS]; + ///* 0x1E0 */ OSMesgQueue audioReplyMsgQ; + ///* 0x1F8 */ OSMesg audioReplyMsgBuf[MAX_MESGS]; + /* 0x238 */ ALGlobals g; +} AMAudioMgr; // size = 0x284 ?? + +typedef struct AMDMABuffer { + /* 0x00 */ ALLink node; + /* 0x08 */ u32 startAddr; + /* 0x0C */ u32 lastFrame; + /* 0x10 */ char* ptr; +} AMDMABuffer; // size = 0x14 + +typedef struct AMDMAState { + /* 0x00 */ u8 initialized; + /* 0x04 */ AMDMABuffer* firstUsed; + /* 0x08 */ AMDMABuffer* firstFree; +} AMDMAState; // size = 0xC extern u8 D_800783FC; extern u8 D_80078400; extern u16 D_80078410[1][9]; extern u16 D_80078446[1][9]; extern u16 D_800784EA[1][9]; +extern s32 D_80077DC4; +extern f32 D_80077DC8; +extern u8 D_80077DCC; extern u16 D_80077DF0[]; extern u16 D_80077E00[]; extern u16 D_80077E10[]; @@ -29,7 +87,7 @@ extern u16 D_800780A8[]; extern u8 D_800783BC; extern u8 D_800783C0; extern u8 D_800783C4; -extern s32 D_800783C8; +extern u32 D_800783C8; extern u32 D_800783CC; extern u8 D_800783D4; extern u8 D_800783D8; @@ -42,6 +100,16 @@ extern f64 D_8007C7E8; extern f64 D_8007C7F0; extern f64 D_8007C7F8; extern u8 D_800FCD18[]; +extern u8 D_80077D90; +extern u8 D_80077D98; +extern u8 D_80077D9C; +extern u8 D_80077DA8; +extern s32 D_80077DAC; +extern u32 audFrameCt; +extern AudioInfo* lastInfo; +extern s32 min_only_one; +extern u8 D_800FC825; +extern s32 D_800FC828; typedef struct unk_D_800FCB18 { /* 0x00 */ char pad00[0xC]; @@ -67,8 +135,9 @@ typedef struct unk_D_800FCB48 { /* 0x7C */ s32 unk_7C; /* 0x80 */ char pad80[0x4]; } unk_D_800FCB48; // size = 0x84 + extern unk_D_800FCB48 D_800FCB48[2]; -extern s32 D_800FCCA4; +extern u32 D_800FCCA4; extern u8 D_800FCCAE; extern u8 D_800FCCAF; extern u8 D_800FCCB0; @@ -87,8 +156,8 @@ extern u8 D_800FCB38[2][8]; extern s32 D_800FCC50[]; extern s8 D_800FCCA0; extern s8 D_800FCCA1; -extern s8 D_800FCCA2; -extern s8 D_800FCCAC; +extern u8 D_800FCCA2; +extern u8 D_800FCCAC; extern s8 D_800FCCB7; extern s8 D_800FCCB8[]; extern s8 D_800FCCBA[]; @@ -102,28 +171,400 @@ extern s8 D_800FCCD8[]; extern s32 D_80078388; extern u32 D_800783A4[4]; extern s32 D_800783B8; +extern u32 nextDMA; +extern u16 D_80077DA0; +extern u32 D_80077DA4; +extern s8 D_800FC824; +extern AMAudioMgr __am; +extern AMDMAState dmaState; +extern s32 minFrameSize; +extern u32 frameSize; +extern s32 maxFrameSize; +extern s32 maxRSPCmds; +extern s32 D_800FCAD4; +extern s32 D_800FCAD8; +extern OSMesgQueue audDMAMessageQ; +extern AMDMABuffer (*dmaBuffs)[NUM_DMA_BUFFERS]; +extern OSIoMesg (*audDMAIOMesgBuf)[NUM_DMA_BUFFERS]; +extern OSMesg (*audDMAMessageBuf)[NUM_DMA_BUFFERS]; +extern u32 dmaBufferLen; +extern OSPiHandle* D_800FCB08; +extern u32 curAcmdList; +extern u16 D_80077E98; +extern u16 D_80077EA4; +extern u16 D_80077EB4; +extern u16 D_80077F04; +extern u16 D_80077F44; +extern u16 D_80077F60; +extern u32 D_800783B4; +extern s32 D_800FCCA8; +extern u8 D_800FCCAD; + +ALDMAproc __amDmaNew(AMDMAState** state); + +#ifdef NON_MATCHING +void amCreateAudioMgr(ALSynConfig* c, amConfig* amc, u32 num_dma_buffers, s32 arg3, s32 arg4) { + u32 i; + f32 fsize; + + D_800FCB08 = osCartRomInit(); + dmaBufferLen = arg3; + + dmaState.initialized = FALSE; + + c->dmaproc = __amDmaNew; + c->outputRate = amc->outputRate; + + dmaBuffs = alHeapAlloc(c->heap, 1, num_dma_buffers * sizeof(AMDMABuffer)); + audDMAIOMesgBuf = alHeapAlloc(c->heap, 1, (num_dma_buffers << 1) * sizeof(OSIoMesg)); + audDMAMessageBuf = alHeapAlloc(c->heap, 1, (num_dma_buffers << 1) * sizeof(OSMesg)); + + fsize = (f32)amc->framesPerField * c->outputRate / arg4; + frameSize = (s32)fsize; + if (frameSize < fsize) { + frameSize++; + } + + frameSize = ((frameSize / SAMPLES) + 1) * SAMPLES; + minFrameSize = frameSize - SAMPLES; + maxFrameSize = frameSize + 0x100; + + alInit(&__am.g, c); + + (*dmaBuffs)[0].node.prev = NULL; + (*dmaBuffs)[0].node.next = NULL; + + for (i = 0; i < num_dma_buffers - 1; i++) { + alLink(&(*dmaBuffs)[i + 1].node, &(*dmaBuffs)[i].node); + (*dmaBuffs)[i].ptr = alHeapAlloc(c->heap, 1, arg3); + } + + (*dmaBuffs)[i].ptr = alHeapAlloc(c->heap, 1, arg3); + + for (i = 0; i < 2; i++) { + __am.ACMDList[i] = alHeapAlloc(c->heap, 1, amc->maxACMDSize * 8); + } + + maxRSPCmds = amc->maxACMDSize; + + for (i = 0; i < 2; i++) { + __am.audioInfo[i] = alHeapAlloc(c->heap, 1, sizeof(AudioInfo)); + __am.audioInfo[i]->msg.done.type = 0; + __am.audioInfo[i]->msg.done.info = __am.audioInfo[i]; + __am.audioInfo[i]->data = alHeapAlloc(c->heap, 1, maxFrameSize * 4); + } + + osCreateMesgQueue(&audDMAMessageQ, audDMAMessageBuf, num_dma_buffers << 1); + + D_800FCAD4 = c->outputRate; + D_800FCAD8 = c->maxVVoices; + D_800FC824 = 0; + + func_80044B20(c->heap, minFrameSize, maxFrameSize); +} +#else +#pragma GLOBAL_ASM("asm/us/nonmatchings/3D140/amCreateAudioMgr.s") +#endif + +s32 __amDMA(s32 addr, s32 len, void* state) { + void* foundBuffer; + s32 delta; + AMDMABuffer* sp34; + OSIoMesg* ioMesg; + AMDMABuffer* dmaPtr; + AMDMABuffer* lastDmaPtr; + OSPiHandle* sp2C; + s32 buffEnd; + + if (D_800FC820 & 0x80000000) { + return osVirtualToPhysical(addr); + } + + sp2C = D_800FCB08; + dmaPtr = dmaState.firstUsed; + lastDmaPtr = NULL; + while (dmaPtr) { + buffEnd = dmaPtr->startAddr + dmaBufferLen; + + if (dmaPtr->startAddr > addr) { + break; + } + + if (buffEnd >= (addr + len)) { + dmaPtr->lastFrame = audFrameCt; + return osVirtualToPhysical(dmaPtr->ptr + addr - dmaPtr->startAddr); + } + + lastDmaPtr = dmaPtr; + dmaPtr = dmaPtr->node.next; + } + + dmaPtr = dmaState.firstFree; + if (!dmaPtr) { + return osVirtualToPhysical(dmaState.firstUsed); + } + + dmaState.firstFree = dmaPtr->node.next; + alUnlink(&dmaPtr->node); + + if (lastDmaPtr != NULL) { + alLink(&dmaPtr->node, &lastDmaPtr->node); + } else if (dmaState.firstUsed) { + lastDmaPtr = dmaState.firstUsed; + + dmaState.firstUsed = dmaPtr; + dmaPtr->node.next = lastDmaPtr; + dmaPtr->node.prev = NULL; + + lastDmaPtr->node.prev = &dmaPtr->node; + } else { + dmaState.firstUsed = dmaPtr; + dmaPtr->node.next = NULL; + dmaPtr->node.prev = NULL; + } + + foundBuffer = dmaPtr->ptr; + delta = addr & 1; + addr -= delta; + dmaPtr->startAddr = addr; + dmaPtr->lastFrame = audFrameCt; + + ioMesg = (*audDMAIOMesgBuf) + nextDMA++; + ioMesg->hdr.pri = OS_MESG_PRI_HIGH; + ioMesg->hdr.retQueue = &audDMAMessageQ; + ioMesg->devAddr = addr; + ioMesg->dramAddr = foundBuffer; + ioMesg->size = dmaBufferLen; + + osInvalDCache(foundBuffer, dmaBufferLen); + osEPiStartDma(sp2C, ioMesg, OS_READ); + + return osVirtualToPhysical(foundBuffer) + delta; +} + +OSTask* func_8003CADC(OSTask* arg0) { + s16* audioPtr; + Acmd* cmdp; + s32 cmdLen; + s32 samplesLeft; + OSTask sp38; + s32 pad[2]; + AudioInfo* info; + AMAudioMgr* mgr; + + info = __am.audioInfo[audFrameCt % 3]; + audioPtr = osVirtualToPhysical(info->data); + samplesLeft = HW_REG(AI_LEN_REG, u32) >> 2; + + if ((D_80077DA8 == 0) && (lastInfo != NULL)) { + osAiSetNextBuffer(lastInfo->data, lastInfo->frameSamples << 2); + } + + if ((samplesLeft >= 0x1A9) && (min_only_one != 0)) { + info->frameSamples = minFrameSize; + min_only_one = 0; + } else { + info->frameSamples = frameSize; + min_only_one = 1; + } + + __clearAudioDMA(); + + if (D_80077DAC != 0) { + D_800FC828 = LeoTestUnitReady(&D_800FC825); + } + + cmdp = alAudioFrame(__am.ACMDList[curAcmdList], &cmdLen, audioPtr, info->frameSamples); + sp38.t.data_ptr = __am.ACMDList[curAcmdList]; + sp38.t.data_size = (cmdp - __am.ACMDList[curAcmdList]) * sizeof(Acmd); + + sp38.t.type = M_AUDTASK; + sp38.t.ucode_boot = &rspbootTextStart; + sp38.t.ucode_boot_size = (s32)_binary_assets_us_F3DEX2_bin_start - (s32)rspbootTextStart; + sp38.t.flags = 0; + sp38.t.ucode = &aspMainTextStart; + sp38.t.ucode_data = &aspMainDataStart; + sp38.t.ucode_data_size = SP_UCODE_DATA_SIZE; + sp38.t.dram_stack = NULL; + sp38.t.dram_stack_size = 0; + sp38.t.output_buff = NULL; + sp38.t.output_buff_size = 0; + sp38.t.yield_data_ptr = NULL; + sp38.t.yield_data_size = 0; + + curAcmdList ^= 1; + lastInfo = __am.audioInfo[audFrameCt % 3]; + audFrameCt++; + + if (D_80077D9C != 0) { + func_8003D32C(); + } + + if (D_80077D90 != 0) { + func_800429D0(); + if (lastInfo != NULL) { + func_800497E0(lastInfo->data, 0, ((audFrameCt % 3) == 0) ? 0x216 : 0x215, 0); + } + } + + if (D_80077D98 != 0) { + func_80044EA4(); + } + + func_800416BC(); + + if (D_80077DC4 != 0) { + D_80077DC8 += D_80077DD0; + if (D_80077DD0 > 0.0f) { + if (D_80077DCC <= D_80077DC8) { + D_80077DC8 = D_80077DCC; + } + } else { + if (D_80077DC8 <= D_80077DCC) { + D_80077DC8 = D_80077DCC; + } + } + + func_800393DC(D_80077DC4, (u32)D_80077DC8 & 0xFF); + + if (D_80077DC8 == D_80077DCC) { + D_80077DC4 = 0; + } + } + + if (D_80077DD4 != 0.0f) { + D_80077DD4 -= D_80077DD8; + if (D_80077DD4 <= 0) { + D_80077DD4 = 0.0f; + func_8003916C(2, 1); + } + func_80038E98(2, D_80077DD4); + } + + if (D_80077DDC != 0.0f) { + D_80077DDC -= D_80077DE0; + if (D_80077DDC <= 0) { + D_80077DDC = 0.0f; + func_8003916C(1, 1); + } + func_80038E98(1, D_80077DDC); + } + + if (D_80077DA8 != 0) { + sp38.t.data_size = 0; + } + + *arg0 = sp38; + + return arg0; +} + +ALDMAproc __amDmaNew(AMDMAState** state) { + if (!dmaState.initialized) { + dmaState.firstUsed = NULL; + dmaState.firstFree = &dmaBuffs[0]; + dmaState.initialized = TRUE; + } + + *state = &dmaState; + + return __amDMA; +} + +#define FRAME_LAG 1 + +void __clearAudioDMA(void) { + s32 i; + void* sp40; + AMDMABuffer* var_s0_2; + ALLink* node; + + for (i = 0; i < nextDMA; i++) { + osRecvMesg(&audDMAMessageQ, &sp40, 0); + } -void func_80041A98(void); -void func_80041C70(u32); -void func_800420C0(u16*); + var_s0_2 = dmaState.firstUsed; + while (var_s0_2 != NULL) { + node = var_s0_2->node.next; -#pragma GLOBAL_ASM("asm/us/nonmatchings/3D140/func_8003C540.s") + if ((var_s0_2->lastFrame + FRAME_LAG) < audFrameCt) { + if (var_s0_2 == dmaState.firstUsed) { + dmaState.firstUsed = var_s0_2->node.next; + } -#pragma GLOBAL_ASM("asm/us/nonmatchings/3D140/func_8003C8DC.s") + alUnlink(var_s0_2); -#pragma GLOBAL_ASM("asm/us/nonmatchings/3D140/func_8003CADC.s") + if (dmaState.firstFree != NULL) { + alLink(var_s0_2, dmaState.firstFree); + } else { + dmaState.firstFree = var_s0_2; + var_s0_2->node.next = NULL; + var_s0_2->node.prev = NULL; + } + } -#pragma GLOBAL_ASM("asm/us/nonmatchings/3D140/func_8003D128.s") + var_s0_2 = node; + } -#pragma GLOBAL_ASM("asm/us/nonmatchings/3D140/func_8003D160.s") + nextDMA = 0; +} #pragma GLOBAL_ASM("asm/us/nonmatchings/3D140/func_8003D264.s") #pragma GLOBAL_ASM("asm/us/nonmatchings/3D140/func_8003D2B8.s") +#ifdef NON_MATCHING +void func_8003D32C(void) { + switch (D_80077D9C) { + case 1: + func_80039B88(D_80078E70, 0x50, 0x18, 3); + func_80042AB0(D_80077DA0); + D_80077D9C++; + D_80077DA4 = 0; + break; + + case 2: + D_80077DA4++; + if (D_80077DA4 >= 2) { + D_80077DA4 = 0; + D_80077D9C++; + D_800FC824 = 1; + } + break; + + case 3: + if (func_800449F8() == 0) { + D_80077D9C++; + D_80077DA4 = 0; + } + break; + + case 4: + if (D_80077DA4 == 0) { + func_80039B88(D_80078E70, 0x18, 0x50, 0x14); + } + + if (D_80077DA4 >= 0x1F) { + D_80077D9C++; + } + + D_80077DA4++; + break; + + case 5: + D_80077D9C = 0; + D_80077D90 = 0; + D_800FC824 = 0; + break; + } +} +#else #pragma GLOBAL_ASM("asm/us/nonmatchings/3D140/func_8003D32C.s") +#endif -#pragma GLOBAL_ASM("asm/us/nonmatchings/3D140/func_8003D494.s") +s32 func_8003D494(void) { + return D_80077D90; +} #pragma GLOBAL_ASM("asm/us/nonmatchings/3D140/func_8003D4A0.s") @@ -135,7 +576,13 @@ void func_800420C0(u16*); #pragma GLOBAL_ASM("asm/us/nonmatchings/3D140/func_8003D624.s") -#pragma GLOBAL_ASM("asm/us/nonmatchings/3D140/func_8003D68C.s") +void func_8003D68C(s32 arg0) { + if (arg0 != 0) { + D_80078388 = 1; + } else { + D_80078388 = 0; + } +} #pragma GLOBAL_ASM("asm/us/nonmatchings/3D140/func_8003D6B0.s") @@ -652,7 +1099,70 @@ void func_8003DB84(s32 arg0) { #pragma GLOBAL_ASM("asm/us/nonmatchings/3D140/func_80041688.s") -#pragma GLOBAL_ASM("asm/us/nonmatchings/3D140/func_800416BC.s") +void func_800416BC(void) { + u8* seq; + + if ((D_800783B4 < D_800783B8) && (D_80078388 != 0) && (func_80044E54(1) == 0)) { + if (D_800783A4[D_800783B4 & 3] != 0) { + seq = D_800FC714->seqArray[D_800783A4[D_800783B4 & 3] - 1].offset; + func_80044CBC(1, seq, 0x7E, 0); + } + D_800783B4++; + } + + if (D_800783BC != 0) { + if ((D_800783C8 >= 0x3E9) && (D_800783C0 == 0) && (D_800783CC != 0)) { + func_80041C70(0x248); + D_800783C0 = 1; + } else if ((D_800783C8 >= 0x7D1) && (D_800783C0 == 0) && (D_800783CC == 0)) { + func_80041C70(0x248); + D_800783C0 = 1; + D_800783C8 = 0x3E8; + } else if ((D_800783C8 >= 0x641) && (D_800783C0 == 1)) { + func_80041C70(0x249); + if (D_800783C4 == 0) { + func_800367A0(0x5B, D_80078400, 0); + D_800783C4 = 1; + } + D_800783C0 = 2; + } else if ((D_800783C8 >= 0x899) && (D_800783C0 == 2)) { + func_80041C70(0x24A); + D_800783C8 = 0x3E8; + D_800783C0 = 1; + } + + D_800783C8++; + } + + if (D_800FCCA2 != 0) { + if (D_800FCCA2 == 1) { + if (D_800FCCA4 != 0) { + if (D_800FCCA4 >= 0x29) { + if (((D_800FCCAD == 0x10) || (D_800FCCAD == 0x11) || (D_800FCCAD == 0x12) || (D_800FCCAD == 0x15) || + (D_800FCCAD == 0x16) || (D_800FCCAD == 0x53) || (D_800FCCAD == 0x54) || + (D_800FCCAD == 0x55)) && + ((D_800FCCAC == 0x34) || (D_800FCCAC == 0x35) || (D_800FCCAC == 0x7E))) { + func_800420C0(&D_80077F44); + } else { + func_800420C0(&D_80077E98); + } + } else if (D_800FCCA4 >= 6) { + if ((D_800FCB18[0]->unk_0C > 0) && (D_800FCB18[1]->unk_0C > 0)) { + func_800420C0(&D_80077EA4); + } else { + func_800420C0(&D_80077F60); + } + } else if ((D_800FCB18[0]->unk_0C > 0) && (D_800FCB18[1]->unk_0C > 0)) { + func_800420C0(&D_80077EB4); + } else { + func_800420C0(&D_80077F04); + } + } + D_800FCCA8 = D_800FCCA4; + } + D_800FCCA2--; + } +} #ifdef NON_MATCHING void func_80041A98(void) { diff --git a/src/3D140.h b/src/3D140.h index e75adab7..3b431284 100644 --- a/src/3D140.h +++ b/src/3D140.h @@ -3,11 +3,32 @@ #include "global.h" -void func_8003CADC(void*); +extern s32 D_80077DC4; +extern f32 D_80077DC8; +extern u8 D_80077DCC; +extern f32 D_80077DD0; +extern f32 D_80077DD4; +extern f32 D_80077DD8; +extern f32 D_80077DDC; +extern f32 D_80077DE0; +extern u8 D_80077DE4; + +typedef struct amConfig { + /* 0x00 */ u32 outputRate; + /* 0x04 */ u32 framesPerField; + /* 0x08 */ u32 maxACMDSize; +} amConfig; // size = 0xC + + +void amCreateAudioMgr(ALSynConfig*, amConfig*, u32, s32, s32); +OSTask* func_8003CADC(OSTask*); +void __clearAudioDMA(void); +void func_8003D32C(void); s32 func_8003D494(void); void func_8003D68C(s32); void func_8003D918(u32 arg0, u32 arg1); void func_8003DB84(s32 arg0); +void func_800416BC(void); void func_80041A98(void); void func_80041C70(u32 arg0); void func_80041D50(u8* arg0, u8* arg1); diff --git a/src/3FB0.c b/src/3FB0.c index 2075b816..cd9c877c 100644 --- a/src/3FB0.c +++ b/src/3FB0.c @@ -1,5 +1,4 @@ #include "3FB0.h" -#include "include/functions.h" #include "src/3FB0.h" #include "src/D470.h" #include "src/dma.h" @@ -96,15 +95,14 @@ void func_800033C8(unk_func_80003680_sp300* arg0, u8* arg1) { arg0->height = (arg0->start_of_frame[1] << 8) | arg0->start_of_frame[2]; } -extern u64 D_80065FC0[]; extern u64 D_80068080[]; extern u64 D_8007ED20[]; void func_80003558(UnkStruct80001380* arg0, unk_func_80003680_sp90* arg1) { arg0->task.t.type = 4; arg0->task.t.flags = 0; - arg0->task.t.ucode_boot = D_80065FC0; - arg0->task.t.ucode_boot_size = (u32)_binary_assets_us_F3DEX2_bin_start - (u32)D_80065FC0; + arg0->task.t.ucode_boot = rspbootTextStart; + arg0->task.t.ucode_boot_size = (u32)_binary_assets_us_F3DEX2_bin_start - (u32)rspbootTextStart; arg0->task.t.ucode = D_80068080; arg0->task.t.ucode_size = 0x1000; arg0->task.t.ucode_data = D_8007ED20; diff --git a/src/435B0.c b/src/435B0.c index 72ece799..875e2afc 100644 --- a/src/435B0.c +++ b/src/435B0.c @@ -1,10 +1,5 @@ -#include "global.h" +#include "435B0.h" -typedef struct { - /* 0x00 */ char unk_00[0x16]; - /* 0x16 */ s16 unk_16; -} struct_800429B0; - -void func_800429B0(struct_800429B0* arg0, s16 arg1) { - arg0->unk_16 = arg1; +void func_800429B0(N_ALVoice* arg0, s16 arg1) { + arg0->priority = arg1; } diff --git a/src/435B0.h b/src/435B0.h new file mode 100644 index 00000000..3dcd5595 --- /dev/null +++ b/src/435B0.h @@ -0,0 +1,10 @@ +#ifndef _435B0_H_ +#define _435B0_H_ + +#include "global.h" +#include "src/libnaudio/n_libaudio_sc.h" +#include "src/libnaudio/n_libaudio_sn_sc.h" + +void func_800429B0(N_ALVoice* arg0, s16 arg1); + +#endif // _435B0_H_ diff --git a/src/435D0.c b/src/435D0.c index ed5a4e7f..354e9065 100644 --- a/src/435D0.c +++ b/src/435D0.c @@ -1,4 +1,4 @@ -#include "global.h" +#include "435D0.h" #pragma GLOBAL_ASM("asm/us/nonmatchings/435D0/func_800429D0.s") diff --git a/src/435D0.h b/src/435D0.h new file mode 100644 index 00000000..ba54d9f5 --- /dev/null +++ b/src/435D0.h @@ -0,0 +1,10 @@ +#ifndef _435D0_H_ +#define _435D0_H_ + +#include "global.h" + +void func_800429D0(void); +void func_80042AB0(u16); +s32 func_800449F8(void); + +#endif // _435D0_H_ diff --git a/src/45720.h b/src/45720.h index 24a46971..f40e0e6a 100644 --- a/src/45720.h +++ b/src/45720.h @@ -3,8 +3,11 @@ #include "global.h" +void func_80044B20(ALHeap*, s32, s32); +void func_80044CBC(s32, s32, s32, s32); void func_80044D78(u32, u32); s32 func_80044E54(s32); void func_80044E80(s32); +void func_80044EA4(void); #endif // _45720_H_ diff --git a/src/490A0.h b/src/490A0.h index 9061cccd..3ad86c53 100644 --- a/src/490A0.h +++ b/src/490A0.h @@ -3,10 +3,6 @@ #include "global.h" -extern s32 D_800FC814; -extern s32 D_800FC818; -extern s32 D_800FC81C; - void func_800484A0(s32 arg0); s32 func_800484C0(s32 arg0); s32 func_800484E0(void); diff --git a/src/4A3E0.c b/src/4A3E0.c index 1120e86c..b77f5793 100644 --- a/src/4A3E0.c +++ b/src/4A3E0.c @@ -1,4 +1,4 @@ -#include "global.h" +#include "4A3E0.h" #pragma GLOBAL_ASM("asm/us/nonmatchings/4A3E0/func_800497E0.s") diff --git a/src/4A3E0.h b/src/4A3E0.h new file mode 100644 index 00000000..e254c1b0 --- /dev/null +++ b/src/4A3E0.h @@ -0,0 +1,8 @@ +#ifndef _4A3E0_H_ +#define _4A3E0_H_ + +#include "global.h" + +void func_800497E0(void*, s32, s32, f32); + +#endif // _4A3E0_H_ diff --git a/src/4BA90.c b/src/4BA90.c index b81a3a10..49b196a5 100644 --- a/src/4BA90.c +++ b/src/4BA90.c @@ -1,6 +1,7 @@ #include "4BA90.h" #include "src/49790.h" #include "src/38BB0.h" +#include "src/3D140.h" void func_8004AE90(s32 arg0, u32 arg1) { s32 var_a1; diff --git a/src/4BDC0.c b/src/4BDC0.c index 59d9f2c6..9e6b3a02 100644 --- a/src/4BDC0.c +++ b/src/4BDC0.c @@ -4,7 +4,7 @@ #include "src/4CBC0.h" #include "src/4B940.h" #include "src/45720.h" -#include "src/50CC0.h" +#include "src/51740.h" #include "src/3D140.h" #include "src/373A0.h" diff --git a/src/4CBC0.c b/src/4CBC0.c index 302561c3..4f2392a0 100644 --- a/src/4CBC0.c +++ b/src/4CBC0.c @@ -3,7 +3,7 @@ #include "src/49790.h" #include "src/4B940.h" #include "src/4BDC0.h" -#include "src/50CC0.h" +#include "src/51740.h" #include "src/373A0.h" #include "src/50860.h" diff --git a/src/50860.h b/src/50860.h index f2531efb..487c3985 100644 --- a/src/50860.h +++ b/src/50860.h @@ -4,5 +4,6 @@ #include "global.h" void func_8004FC60(s32, s32); +void func_8004FCD8(s32); #endif // _50860_H_ diff --git a/src/50A00.c b/src/50A00.c index b39d96af..a8e5260e 100644 --- a/src/50A00.c +++ b/src/50A00.c @@ -1,5 +1,33 @@ #include "50A00.h" +#include "src/38BB0.h" +#include "src/4B940.h" +#include "src/51740.h" +#include "src/50860.h" +#include "src/373A0.h" -#pragma GLOBAL_ASM("asm/us/nonmatchings/50A00/func_8004FE00.s") +s32 func_8004FE00(u8* arg0) { + UNUSED s32 pad[2]; + u8* sp1C; -#pragma GLOBAL_ASM("asm/us/nonmatchings/50A00/func_8004FF20.s") + func_8004FCD8(1); + D_800FF9C0 = arg0; + sp1C = D_800FF9C0 + 0x4120; + + if (1) {} + + func_8004ADB0(D_800FC6E4->offset1, D_800FC6DC, D_800FC6E4->wave_tables_offset - D_800FC6E4->offset1); + func_80050B40(D_800FC6DC, D_800FF9C0, 0x4120); + func_8004ADB0(D_800FC6E4->wave_tables_offset, sp1C, D_800FC6E4->files[0] - D_800FC6E4->wave_tables_offset); + func_8003979C(D_800FF9C0, sp1C); + D_800FC820 |= 0x80000000; + func_8004ADB0(D_800FC6E4->files[0], D_800FC6DC, D_800FC6E4->files[1] - D_800FC6E4->files[0]); + func_80050B40(D_800FC6DC, D_800FC680, 0x98D8); + D_80078E70 = func_80038F30(D_800FF9C0, D_800FC680); + func_800393DC(D_80078E70, 0x70); + + return D_80078E70; +} + +void func_8004FF20(void) { + D_800FC820 &= ~0x80000000; +} diff --git a/src/50A00.h b/src/50A00.h index bbedb019..043327b1 100644 --- a/src/50A00.h +++ b/src/50A00.h @@ -3,7 +3,7 @@ #include "global.h" -void func_8004FE00(void*); +s32 func_8004FE00(u8*); void func_8004FF20(void); diff --git a/src/50CC0.h b/src/50CC0.h deleted file mode 100644 index 31f8a97b..00000000 --- a/src/50CC0.h +++ /dev/null @@ -1,8 +0,0 @@ -#ifndef _50CC0_H_ -#define _50CC0_H_ - -#include "global.h" - -void func_80050B40(s32, s32, s32); - -#endif // _50CC0_H_ diff --git a/src/51740.c b/src/51740.c index 3b12cfb9..9044486c 100644 --- a/src/51740.c +++ b/src/51740.c @@ -1,4 +1,8 @@ -#include "global.h" +#include "51740.h" - -#pragma GLOBAL_ASM("asm/us/nonmatchings/51740/func_80050B40.s") +void func_80050B40(s32 arg0, void* arg1, s32 arg2) { + osInvalICache(arg1, arg2); + osInvalDCache(arg1, arg2); + func_80050BA0(arg0, arg1); + osWritebackDCache(arg1, arg2); +} diff --git a/src/51740.h b/src/51740.h new file mode 100644 index 00000000..f7608bda --- /dev/null +++ b/src/51740.h @@ -0,0 +1,8 @@ +#ifndef _51740_H_ +#define _51740_H_ + +#include "global.h" + +void func_80050B40(s32, void*, s32); + +#endif // _51740_H_ diff --git a/src/517A0.h b/src/517A0.h new file mode 100644 index 00000000..a097785e --- /dev/null +++ b/src/517A0.h @@ -0,0 +1,8 @@ +#ifndef _517A0_H_ +#define _517A0_H_ + +#include "global.h" + +void func_80050BA0(s32, void*); + +#endif // _517A0_H_ diff --git a/src/5580.h b/src/5580.h index 372e84c8..c9fa8baf 100644 --- a/src/5580.h +++ b/src/5580.h @@ -8,7 +8,7 @@ typedef struct UnkStruct80001380 { /* 0x04 */ OSMesgQueue queue; /* 0x1C */ s16 unk_1C; /* 0x1E */ s16 unk_1E; - /* 0x1C */ OSTask task; + /* 0x20 */ OSTask task; /* 0x60 */ char unk60[0x8]; } UnkStruct80001380; // size = 0x68 diff --git a/src/DDC0.c b/src/DDC0.c index 777904c8..068fdbaa 100644 --- a/src/DDC0.c +++ b/src/DDC0.c @@ -5,6 +5,7 @@ #include "4BDC0.h" #include "5580.h" #include "373A0.h" +#include "src/50860.h" extern s32 D_800A83A0; @@ -21,7 +22,6 @@ s32 func_800484E0(void); void func_80009210(void); void func_8004FD44(void); void func_8004B9C4(); -void func_8004FCD8(s32); void func_8003D4A0(s32); void func_8004AF24(s32); void func_8004FD64(s32); diff --git a/src/fragments/2/fragment2.c b/src/fragments/2/fragment2.c index 6e0cb319..5927f592 100644 --- a/src/fragments/2/fragment2.c +++ b/src/fragments/2/fragment2.c @@ -36,7 +36,6 @@ static s32 pad_D_8780FA4C; s16 D_8780FA50; s16 D_8780FA52[2][4]; s16 D_8780FA68[4]; -u32* D_8780FA70; void func_87800020(void) { func_8002D510(); @@ -93,13 +92,11 @@ u32 func_878001E8(s32 arg0) { return var_v1; } -#ifdef NON_MATCHING void func_8780024C(s32 arg0, s32 arg1, s32 arg2, s32 arg3, s32 arg4) { - s32 temp_lo; - s32 spF0; - - spF0 = arg2 - 2; - temp_lo = ((arg4 - arg3) * spF0) / arg4; + UNUSED s32 pad; + s32 spF0 = arg2 - 2; + s32 temp_lo = ((arg4 - arg3) * spF0) / arg4; + s32 sp1C = (arg2 - temp_lo) - 2; gSPDisplayList(gDisplayListHead++, D_8006F518); @@ -126,13 +123,11 @@ void func_8780024C(s32 arg0, s32 arg1, s32 arg2, s32 arg3, s32 arg4) { gSPTextureRectangle(gDisplayListHead++, ((arg0 + spF0) + 2) << 2, arg1 << 2, ((arg0 + spF0) + 4) << 2, (arg1 + 0xC) << 2, G_TX_RENDERTILE, 0x00C0, 0, 0x0400, 0x0400); - spF0 = (arg2 - temp_lo) - 2; - - if (spF0 > 0) { + if (sp1C > 0) { gDPLoadTextureBlock(gDisplayListHead++, D_87806730, G_IM_FMT_RGBA, G_IM_SIZ_16b, 8, 12, 0, G_TX_NOMIRROR | G_TX_CLAMP, G_TX_NOMIRROR | G_TX_CLAMP, G_TX_NOMASK, G_TX_NOMASK, G_TX_NOLOD, G_TX_NOLOD); - gSPTextureRectangle(gDisplayListHead++, (arg0 + 2) << 2, arg1 << 2, ((arg0 + 2) + spF0) << 2, (arg1 + 0xC) << 2, + gSPTextureRectangle(gDisplayListHead++, (arg0 + 2) << 2, arg1 << 2, ((arg0 + 2) + sp1C) << 2, (arg1 + 0xC) << 2, G_TX_RENDERTILE, 0, 0, 0, 0x0400); } @@ -140,21 +135,17 @@ void func_8780024C(s32 arg0, s32 arg1, s32 arg2, s32 arg3, s32 arg4) { gDPLoadTextureBlock(gDisplayListHead++, D_878065B0, G_IM_FMT_RGBA, G_IM_SIZ_16b, 8, 12, 0, G_TX_NOMIRROR | G_TX_CLAMP, G_TX_NOMIRROR | G_TX_CLAMP, G_TX_NOMASK, G_TX_NOMASK, G_TX_NOLOD, G_TX_NOLOD); - gSPTextureRectangle(gDisplayListHead++, ((arg0 + 2) + spF0) << 2, arg1 << 2, - (((arg0 + 2) + spF0) + temp_lo) << 2, (arg1 + 0xC) << 2, G_TX_RENDERTILE, 0, 0, 0, 0x0400); + gSPTextureRectangle(gDisplayListHead++, ((arg0 + 2) + sp1C) << 2, arg1 << 2, + (((arg0 + 2) + sp1C) + temp_lo) << 2, (arg1 + 0xC) << 2, G_TX_RENDERTILE, 0, 0, 0, 0x0400); } gSPDisplayList(gDisplayListHead++, D_8006F630); } -#else -#pragma GLOBAL_ASM("asm/us/nonmatchings/fragments/2/fragment2/func_8780024C.s") -#endif -#ifdef NON_MATCHING void func_878009BC(s32 arg0, s32 arg1, s32 arg2, s32 arg3) { u32* spCC; - s32 sp14; - s32 temp_lo; + s32 temp_lo = ((arg3 - arg2) * 0x30) / arg3; + s32 sp14 = 0x30 - temp_lo; if (arg2 < ((arg3 * 0xA) / 48)) { spCC = D_87806730; @@ -178,9 +169,6 @@ void func_878009BC(s32 arg0, s32 arg1, s32 arg2, s32 arg3) { gSPTextureRectangle(gDisplayListHead++, (arg0 + 0x40) << 2, arg1 << 2, (arg0 + 0x41) << 2, (arg1 + 5) << 2, G_TX_RENDERTILE, 0, 0, 0x0400, 0x0400); - temp_lo = ((arg3 - arg2) * 0x30) / arg3; - sp14 = 0x30 - temp_lo; - if (sp14 > 0) { gDPLoadTextureBlock(gDisplayListHead++, spCC, G_IM_FMT_RGBA, G_IM_SIZ_16b, 4, 5, 0, G_TX_NOMIRROR | G_TX_CLAMP, G_TX_NOMIRROR | G_TX_CLAMP, G_TX_NOMASK, G_TX_NOMASK, G_TX_NOLOD, G_TX_NOLOD); @@ -198,9 +186,6 @@ void func_878009BC(s32 arg0, s32 arg1, s32 arg2, s32 arg3) { gSPDisplayList(gDisplayListHead++, D_8006F630); } -#else -#pragma GLOBAL_ASM("asm/us/nonmatchings/fragments/2/fragment2/func_878009BC.s") -#endif s16 D_87806338 = -1; u32* D_8780633C[] = { D_878067F0, D_87807690, D_87808530, D_878093D0 }; @@ -321,8 +306,11 @@ s32 func_878013D4(UNUSED unk_D_800AC870* arg0, char* arg1) { return func_8001F5B0(0, 0, arg1); } +// Needs in-function static to match, but D_8780FA70 is referenced in fragment 20 and 39? #ifdef NON_MATCHING void func_87801400(s32 arg0, s16 arg1, s16 arg2, f32 arg3, f32 arg4) { + static u32* D_8780FA70; + f32 temp_fa0; f32 temp_fv1; s16 a; @@ -332,36 +320,23 @@ void func_87801400(s32 arg0, s16 arg1, s16 arg2, f32 arg3, f32 arg4) { if ((arg3 != 0.0f) && (arg4 != 0.0f)) { if (arg0 < 0) { arg0 = -1 - arg0; - var_t3 = D_8780634C[arg0]; + D_8780FA70 = D_8780634C[arg0]; } else { - var_t3 = D_8780633C[arg0 % 4]; + D_8780FA70 = D_8780633C[arg0 % 4]; } - gDPLoadTextureBlock(gDisplayListHead++, var_t3, G_IM_FMT_RGBA, G_IM_SIZ_32b, 36, 26, 0, + gDPLoadTextureBlock(gDisplayListHead++, D_8780FA70, G_IM_FMT_RGBA, G_IM_SIZ_32b, 36, 26, 0, G_TX_NOMIRROR | G_TX_CLAMP, G_TX_NOMIRROR | G_TX_CLAMP, G_TX_NOMASK, G_TX_NOMASK, G_TX_NOLOD, G_TX_NOLOD); - D_8780FA70 = var_t3; - - temp_fa0 = 36.0f * arg3; - if (temp_fa0 > 0.0f) { - temp_fv1 = 0.5f; - } else { - temp_fv1 = -0.5f; - } - a = temp_fv1 + temp_fa0; - temp_fa0 = 26.0f * arg4; - if (temp_fa0 > 0.0f) { - temp_fv1 = 0.5f; - } else { - temp_fv1 = -0.5f; - } - b = temp_fv1 + temp_fa0; + a = ROUND_MAX(36.0f * arg3); + b = ROUND_MAX(26.0f * arg4); func_8001C330(arg1, arg2, a, b, 0, 0, 1024.0f / arg3, 1024.0f / arg4, 0); } } #else +u32* D_8780FA70; #pragma GLOBAL_ASM("asm/us/nonmatchings/fragments/2/fragment2/func_87801400.s") #endif diff --git a/src/libnaudio/n_auxbus.c b/src/libnaudio/n_auxbus.c index 10651610..a83cfa89 100644 --- a/src/libnaudio/n_auxbus.c +++ b/src/libnaudio/n_auxbus.c @@ -19,22 +19,20 @@ #include "n_synthInternals.h" -Acmd *n_alAuxBusPull(s32 sampleOffset, Acmd *p) -{ - Acmd *ptr = p; - N_ALAuxBus *m = (N_ALAuxBus *)n_syn->auxBus; - N_PVoice **sources = m->sources; - s32 i; +Acmd* n_alAuxBusPull(s32 sampleOffset, Acmd* p) { + Acmd* ptr = p; + N_ALAuxBus* m = (N_ALAuxBus*)n_syn->auxBus; + N_PVoice** sources = m->sources; + s32 i; #ifndef N_MICRO - aClearBuffer(ptr++, AL_AUX_L_OUT, FIXED_SAMPLE<<1); - aClearBuffer(ptr++, AL_AUX_R_OUT, FIXED_SAMPLE<<1); + aClearBuffer(ptr++, AL_AUX_L_OUT, FIXED_SAMPLE << 1); + aClearBuffer(ptr++, AL_AUX_R_OUT, FIXED_SAMPLE << 1); #else - aClearBuffer(ptr++, N_AL_AUX_L_OUT, N_AL_DIVIDED<<1); + aClearBuffer(ptr++, N_AL_AUX_L_OUT, N_AL_DIVIDED << 1); #endif - for (i = 0; i < m->sourceCount; i++) - ptr = n_alEnvmixerPull(sources[i],sampleOffset,ptr); - return ptr; + for (i = 0; i < m->sourceCount; i++) + ptr = n_alEnvmixerPull(sources[i], sampleOffset, ptr); + return ptr; } - diff --git a/src/libnaudio/n_drvrNew.c b/src/libnaudio/n_drvrNew.c index de9f2d67..bb7dae9c 100644 --- a/src/libnaudio/n_drvrNew.c +++ b/src/libnaudio/n_drvrNew.c @@ -17,7 +17,6 @@ * Copyright Laws of the United States. *====================================================================*/ - #include "n_synthInternals.h" #include #include @@ -26,185 +25,188 @@ * WARNING: THE FOLLOWING CONSTANT MUST BE KEPT IN SYNC * WITH SCALING IN MICROCODE!!! */ -#define SCALE 16384 +#define SCALE 16384 /* * the following arrays contain default parameters for * a few hopefully useful effects. */ -#define ms *(((s32)((f32)44.1))&~0x7) - +#define ms *(((s32)((f32)44.1)) & ~0x7) + s32 SMALLROOM_PARAMS_N[26] = { /* sections length */ - 3, 100 ms, - /* chorus chorus filter - input output fbcoef ffcoef gain rate depth coef */ - 0, 54 ms, 9830, -9830, 0, 0, 0, 0, - 19 ms, 38 ms, 3276, -3276, 0x3fff, 0, 0, 0, - 0, 60 ms, 5000, 0, 0, 0, 0, 0x5000 + 3, 100 ms, + /* chorus chorus filter +input output fbcoef ffcoef gain rate depth coef */ + 0, 54 ms, 9830, -9830, 0, 0, 0, 0, 19 ms, 38 ms, 3276, -3276, 0x3fff, 0, 0, 0, 0, 60 ms, 5000, 0, 0, 0, 0, 0x5000 }; s32 BIGROOM_PARAMS_N[34] = { /* sections length */ - 4, 100 ms, - /* chorus chorus filter - input output fbcoef ffcoef gain rate depth coef */ - 0, 66 ms, 9830, -9830, 0, 0, 0, 0, - 22 ms, 54 ms, 3276, -3276, 0x3fff, 0, 0, 0, - 66 ms, 91 ms, 3276, -3276, 0x3fff, 0, 0, 0, - 0, 94 ms, 8000, 0, 0, 0, 0, 0x5000 + 4, 100 ms, + /* chorus chorus filter +input output fbcoef ffcoef gain rate depth coef */ + 0, 66 ms, 9830, -9830, 0, 0, 0, 0, 22 ms, 54 ms, 3276, -3276, 0x3fff, 0, 0, 0, 66 ms, 91 ms, 3276, -3276, 0x3fff, 0, + 0, 0, 0, 94 ms, 8000, 0, 0, 0, 0, 0x5000 }; s32 ECHO_PARAMS_N[10] = { /* sections length */ - 1, 200 ms, - /* chorus chorus filter - input output fbcoef ffcoef gain rate depth coef */ - 0, 179 ms, 12000, 0, 0x7fff, 0, 0, 0 + 1, 200 ms, + /* chorus chorus filter +input output fbcoef ffcoef gain rate depth coef */ + 0, 179 ms, 12000, 0, 0x7fff, 0, 0, 0 }; s32 CHORUS_PARAMS_N[10] = { /* sections length */ - 1, 20 ms, - /* chorus chorus filter - input output fbcoef ffcoef gain rate depth coef */ - 0, 5 ms, 0x4000, 0, 0x7fff, 7600, 700, 0 + 1, 20 ms, + /* chorus chorus filter +input output fbcoef ffcoef gain rate depth coef */ + 0, 5 ms, 0x4000, 0, 0x7fff, 7600, 700, 0 }; s32 FLANGE_PARAMS_N[10] = { /* sections length */ - 1, 20 ms, - /* chorus chorus filter - input output fbcoef ffcoef gain rate depth coef */ - 0, 5 ms, 0, 0x5fff, 0x7fff, 380, 500, 0 + 1, 20 ms, + /* chorus chorus filter +input output fbcoef ffcoef gain rate depth coef */ + 0, 5 ms, 0, 0x5fff, 0x7fff, 380, 500, 0 }; -s32 NULL_PARAMS_N[10] = { - 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0 -}; +s32 NULL_PARAMS_N[10] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; -void n_alFxNew(ALFx **fx_ar, ALSynConfig *c, ALHeap *hp) -{ - u16 i, j, k; - s32 *param = 0; - ALDelay *d; - ALFx *r; +void n_alFxNew(ALFx** fx_ar, ALSynConfig* c, ALHeap* hp) { + u16 i, j, k; + s32* param = 0; + ALDelay* d; + ALFx* r; - *fx_ar = r = (ALFx *)alHeapAlloc(hp, 1, sizeof(ALFx)); + *fx_ar = r = (ALFx*)alHeapAlloc(hp, 1, sizeof(ALFx)); switch (c->fxType) { - case AL_FX_SMALLROOM: param = SMALLROOM_PARAMS_N; break; - case AL_FX_BIGROOM: param = BIGROOM_PARAMS_N; break; - case AL_FX_ECHO: param = ECHO_PARAMS_N; break; - case AL_FX_CHORUS: param = CHORUS_PARAMS_N; break; - case AL_FX_FLANGE: param = FLANGE_PARAMS_N; break; - case AL_FX_CUSTOM: param = c->params; break; - default: param = NULL_PARAMS_N; break; + case AL_FX_SMALLROOM: + param = SMALLROOM_PARAMS_N; + break; + case AL_FX_BIGROOM: + param = BIGROOM_PARAMS_N; + break; + case AL_FX_ECHO: + param = ECHO_PARAMS_N; + break; + case AL_FX_CHORUS: + param = CHORUS_PARAMS_N; + break; + case AL_FX_FLANGE: + param = FLANGE_PARAMS_N; + break; + case AL_FX_CUSTOM: + param = c->params; + break; + default: + param = NULL_PARAMS_N; + break; } - j = 0; - + r->section_count = param[j++]; - r->length = param[j++]; + r->length = param[j++]; r->delay = alHeapAlloc(hp, r->section_count, sizeof(ALDelay)); r->base = alHeapAlloc(hp, r->length, sizeof(s16)); r->input = r->base; - for ( k=0; k < r->length; k++) - r->base[k] = 0; + for (k = 0; k < r->length; k++) + r->base[k] = 0; - for ( i=0; isection_count; i++ ){ - d = &r->delay[i]; - d->input = param[j++]; - d->output = param[j++]; - d->fbcoef = param[j++]; - d->ffcoef = param[j++]; - d->gain = param[j++]; + for (i = 0; i < r->section_count; i++) { + d = &r->delay[i]; + d->input = param[j++]; + d->output = param[j++]; + d->fbcoef = param[j++]; + d->ffcoef = param[j++]; + d->gain = param[j++]; - if (param[j]) { + if (param[j]) { #define RANGE 2.0 -/* d->rsinc = ((f32) param[j++])/0xffffff; */ - d->rsinc = ((((f32)param[j++])/1000) * RANGE)/c->outputRate; - - /* - * the following constant is derived from: - * - * ratio = 2^(cents/1200) - * - * and therefore for hundredths of a cent - * x - * ln(ratio) = --------------- - * (120,000)/ln(2) - * where - * 120,000/ln(2) = 173123.40... - */ + /* d->rsinc = ((f32) param[j++])/0xffffff; */ + d->rsinc = ((((f32)param[j++]) / 1000) * RANGE) / c->outputRate; + + /* + * the following constant is derived from: + * + * ratio = 2^(cents/1200) + * + * and therefore for hundredths of a cent + * x + * ln(ratio) = --------------- + * (120,000)/ln(2) + * where + * 120,000/ln(2) = 173123.40... + */ #define CONVERT 173123.404906676 -#define LENGTH (d->output - d->input) - d->rsgain = (((f32) param[j++])/CONVERT) * LENGTH; - d->rsval = 1.0; - d->rsdelta = 0.0; - d->rs = alHeapAlloc(hp, 1, sizeof(ALResampler)); - d->rs->state = alHeapAlloc(hp, 1, sizeof(RESAMPLE_STATE)); - d->rs->delta = 0.0; - d->rs->first = 1; - } else { - d->rs = 0; - j++; - j++; - } - - if (param[j]) { - d->lp = alHeapAlloc(hp, 1, sizeof(ALLowPass)); - d->lp->fstate = alHeapAlloc(hp, 1, sizeof(POLEF_STATE)); - d->lp->fc = param[j++]; +#define LENGTH (d->output - d->input) + d->rsgain = (((f32)param[j++]) / CONVERT) * LENGTH; + d->rsval = 1.0; + d->rsdelta = 0.0; + d->rs = alHeapAlloc(hp, 1, sizeof(ALResampler)); + d->rs->state = alHeapAlloc(hp, 1, sizeof(RESAMPLE_STATE)); + d->rs->delta = 0.0; + d->rs->first = 1; + } else { + d->rs = 0; + j++; + j++; + } + + if (param[j]) { + d->lp = alHeapAlloc(hp, 1, sizeof(ALLowPass)); + d->lp->fstate = alHeapAlloc(hp, 1, sizeof(POLEF_STATE)); + d->lp->fc = param[j++]; #ifdef _OLD_AUDIO_LIBRARY - init_lpfilter(d->lp); + init_lpfilter(d->lp); #else - _init_lpfilter(d->lp); + _init_lpfilter(d->lp); #endif - } else { - d->lp = 0; - j++; - } + } else { + d->lp = 0; + j++; + } } } -void alN_PVoiceNew(N_PVoice *mv, ALDMANew dmaNew, ALHeap *hp) -{ - mv->dc_state = alHeapAlloc(hp, 1, sizeof(ADPCM_STATE)); - mv->dc_lstate = alHeapAlloc(hp, 1, sizeof(ADPCM_STATE)); - mv->dc_dma = dmaNew(&mv->dc_dmaState); - mv->dc_lastsam = 0; - mv->dc_first = 1; - mv->dc_memin = 0; - - mv->rs_state = alHeapAlloc(hp, 1, sizeof(RESAMPLE_STATE)); - mv->rs_delta = 0.0; - mv->rs_first = 1; - mv->rs_ratio = 1.0; - mv->rs_upitch = 0; - - mv->em_state = alHeapAlloc(hp, 1, sizeof(ENVMIX_STATE)); - mv->em_first = 1; - mv->em_motion = AL_STOPPED; - mv->em_volume = 1; - mv->em_ltgt = 1; - mv->em_rtgt = 1; - mv->em_cvolL = 1; - mv->em_cvolR = 1; - mv->em_dryamt = 0; - mv->em_wetamt = 0; - mv->em_lratm = 1; - mv->em_lratl = 0; - mv->em_lratm = 1; - mv->em_lratl = 0; - mv->em_delta = 0; - mv->em_segEnd = 0; - mv->em_pan = 0; - mv->em_ctrlList = 0; - mv->em_ctrlTail = 0; +void alN_PVoiceNew(N_PVoice* mv, ALDMANew dmaNew, ALHeap* hp) { + mv->dc_state = alHeapAlloc(hp, 1, sizeof(ADPCM_STATE)); + mv->dc_lstate = alHeapAlloc(hp, 1, sizeof(ADPCM_STATE)); + mv->dc_dma = dmaNew(&mv->dc_dmaState); + mv->dc_lastsam = 0; + mv->dc_first = 1; + mv->dc_memin = 0; + + mv->rs_state = alHeapAlloc(hp, 1, sizeof(RESAMPLE_STATE)); + mv->rs_delta = 0.0; + mv->rs_first = 1; + mv->rs_ratio = 1.0; + mv->rs_upitch = 0; + + mv->em_state = alHeapAlloc(hp, 1, sizeof(ENVMIX_STATE)); + mv->em_first = 1; + mv->em_motion = AL_STOPPED; + mv->em_volume = 1; + mv->em_ltgt = 1; + mv->em_rtgt = 1; + mv->em_cvolL = 1; + mv->em_cvolR = 1; + mv->em_dryamt = 0; + mv->em_wetamt = 0; + mv->em_lratm = 1; + mv->em_lratl = 0; + mv->em_lratm = 1; + mv->em_lratl = 0; + mv->em_delta = 0; + mv->em_segEnd = 0; + mv->em_pan = 0; + mv->em_ctrlList = 0; + mv->em_ctrlTail = 0; } - diff --git a/src/libnaudio/n_env.c b/src/libnaudio/n_env.c index 9f6b21de..98612263 100644 --- a/src/libnaudio/n_env.c +++ b/src/libnaudio/n_env.c @@ -36,538 +36,507 @@ extern u32 vol_num, vol_cnt, vol_max, vol_min; #define N_EQPOWER_LENGTH 128 -s16 n_eqpower[ N_EQPOWER_LENGTH ] = { - 32767, 32764, 32757, 32744, 32727, 32704, - 32677, 32644, 32607, 32564, 32517, 32464, - 32407, 32344, 32277, 32205, 32127, 32045, - 31958, 31866, 31770, 31668, 31561, 31450, - 31334, 31213, 31087, 30957, 30822, 30682, - 30537, 30388, 30234, 30075, 29912, 29744, - 29572, 29395, 29214, 29028, 28838, 28643, - 28444, 28241, 28033, 27821, 27605, 27385, - 27160, 26931, 26698, 26461, 26220, 25975, - 25726, 25473, 25216, 24956, 24691, 24423, - 24151, 23875, 23596, 23313, 23026, 22736, - 22442, 22145, 21845, 21541, 21234, 20924, - 20610, 20294, 19974, 19651, 19325, 18997, - 18665, 18331, 17993, 17653, 17310, 16965, - 16617, 16266, 15913, 15558, 15200, 14840, - 14477, 14113, 13746, 13377, 13006, 12633, - 12258, 11881, 11503, 11122, 10740, 10357, - 9971, 9584, 9196, 8806, 8415, 8023, - 7630, 7235, 6839, 6442, 6044, 5646, - 5246, 4845, 4444, 4042, 3640, 3237, - 2833, 2429, 2025, 1620, 1216, 810, - 405, 0 +s16 n_eqpower[N_EQPOWER_LENGTH] = { + 32767, 32764, 32757, 32744, 32727, 32704, 32677, 32644, 32607, 32564, 32517, 32464, 32407, 32344, 32277, 32205, + 32127, 32045, 31958, 31866, 31770, 31668, 31561, 31450, 31334, 31213, 31087, 30957, 30822, 30682, 30537, 30388, + 30234, 30075, 29912, 29744, 29572, 29395, 29214, 29028, 28838, 28643, 28444, 28241, 28033, 27821, 27605, 27385, + 27160, 26931, 26698, 26461, 26220, 25975, 25726, 25473, 25216, 24956, 24691, 24423, 24151, 23875, 23596, 23313, + 23026, 22736, 22442, 22145, 21845, 21541, 21234, 20924, 20610, 20294, 19974, 19651, 19325, 18997, 18665, 18331, + 17993, 17653, 17310, 16965, 16617, 16266, 15913, 15558, 15200, 14840, 14477, 14113, 13746, 13377, 13006, 12633, + 12258, 11881, 11503, 11122, 10740, 10357, 9971, 9584, 9196, 8806, 8415, 8023, 7630, 7235, 6839, 6442, + 6044, 5646, 5246, 4845, 4444, 4042, 3640, 3237, 2833, 2429, 2025, 1620, 1216, 810, 405, 0 }; #ifndef N_MICRO -extern f64 __pow(f64, f64); -extern f64 _frexpf(f64 value, s32 *eptr); +extern f64 __pow(f64, f64); +extern f64 _frexpf(f64 value, s32* eptr); extern f64 _ldexpf(f64 in, s32 ex); #endif /* * prototypes for private enveloper functions */ -static Acmd *_pullSubFrame(N_PVoice *pv, s16 *inp, s16 *outp, s32 outCount, - Acmd *p) ; +static Acmd* _pullSubFrame(N_PVoice* pv, s16* inp, s16* outp, s32 outCount, Acmd* p); + +static s16 _getRate(f64 vol, f64 tgt, s32 count, u16* ratel); -static s16 _getRate(f64 vol, f64 tgt, s32 count, u16* ratel); - #ifndef N_MICRO -static f32 _getVol(f32 ivol, s32 samples, s16 ratem, u16 ratel); +static f32 _getVol(f32 ivol, s32 samples, s16 ratem, u16 ratel); #else -static s16 _getVol(s16 ivol, s32 samples, s16 ratem, u16 ratel); +static s16 _getVol(s16 ivol, s32 samples, s16 ratem, u16 ratel); #endif /*********************************************************************** - * Enveloper filter public interfaces + * Enveloper filter public interfaces ***********************************************************************/ -Acmd *n_alEnvmixerPull(N_PVoice *filter, s32 sampleOffset, Acmd *p) -{ - Acmd *ptr = p; - - - N_PVoice *e = (N_PVoice *)filter; - - s16 inp; - s32 lastOffset; - s32 thisOffset = sampleOffset; - s32 samples; - s16 loutp = 0; - s32 fVol; - ALParam *thisParam; - s32 outCount = FIXED_SAMPLE; - +Acmd* n_alEnvmixerPull(N_PVoice* filter, s32 sampleOffset, Acmd* p) { + Acmd* ptr = p; + + N_PVoice* e = (N_PVoice*)filter; + + s16 inp; + s32 lastOffset; + s32 thisOffset = sampleOffset; + s32 samples; + s16 loutp = 0; + s32 fVol; + ALParam* thisParam; + s32 outCount = FIXED_SAMPLE; + #ifdef AUD_PROFILE - lastCnt[++cnt_index] = osGetCount(); + lastCnt[++cnt_index] = osGetCount(); #endif - - /* - * Force the input to be the resampler output - */ + + /* + * Force the input to be the resampler output + */ #ifndef N_MICRO - inp = AL_RESAMPLER_OUT; + inp = AL_RESAMPLER_OUT; #else - inp = N_AL_RESAMPLER_OUT; + inp = N_AL_RESAMPLER_OUT; #endif - - while (e->em_ctrlList != 0) { - - lastOffset = thisOffset; - thisOffset = e->em_ctrlList->delta; + + while (e->em_ctrlList != 0) { + + lastOffset = thisOffset; + thisOffset = e->em_ctrlList->delta; #ifdef FINAL_ROUND - samples = SAMPLE184(thisOffset - lastOffset); - if(!samples) - thisOffset = lastOffset; + samples = SAMPLE184(thisOffset - lastOffset); + if (!samples) + thisOffset = lastOffset; #else - samples = thisOffset - lastOffset; + samples = thisOffset - lastOffset; #endif - if (samples > outCount) - break; - + if (samples > outCount) { + break; + } + #ifdef _DEBUG - assert(samples >= 0); + assert(samples >= 0); #ifndef N_MICRO - assert(samples <= AL_MAX_RSP_SAMPLES); + assert(samples <= AL_MAX_RSP_SAMPLES); #else - assert(samples <= FIXED_SAMPLE); + assert(samples <= FIXED_SAMPLE); #endif #endif /* _DEBUG */ - switch (e->em_ctrlList->type) { - case (AL_FILTER_START_VOICE_ALT): - { - ALStartParamAlt *param = (ALStartParamAlt *)e->em_ctrlList; - ALFilter *f = (ALFilter *) e; - s32 tmp; - - if (param->unity) { - e->rs_upitch = 1; - } - - n_alLoadParam(e, AL_FILTER_SET_WAVETABLE, param->wave); - e->em_motion = AL_PLAYING; - e->em_first = 1; - e->em_delta = 0; + switch (e->em_ctrlList->type) { + case (AL_FILTER_START_VOICE_ALT): { + ALStartParamAlt* param = (ALStartParamAlt*)e->em_ctrlList; + ALFilter* f = (ALFilter*)e; + s32 tmp; + + if (param->unity) { + e->rs_upitch = 1; + } + + n_alLoadParam(e, AL_FILTER_SET_WAVETABLE, param->wave); + e->em_motion = AL_PLAYING; + e->em_first = 1; + e->em_delta = 0; #ifdef FINAL_ROUND - e->em_segEnd = SAMPLE184(param->samples); + e->em_segEnd = SAMPLE184(param->samples); #else - e->em_segEnd = param->samples; + e->em_segEnd = param->samples; #endif - tmp = ((s32)param->volume * (s32)param->volume) >> 15; - - - e->em_volume = (s16) tmp; - e->em_pan = param->pan; - e->em_dryamt = n_eqpower[param->fxMix]; - e->em_wetamt = n_eqpower[N_EQPOWER_LENGTH - param->fxMix - 1]; - - if (param->samples) { - e->em_cvolL = 1; - e->em_cvolR = 1; - } else { - /* - * Attack time is zero. Simply set the - * volume. We don't want an attack segment. - */ - e->em_cvolL = (e->em_volume * n_eqpower[e->em_pan]) >> 15; - e->em_cvolR = (e->em_volume * - n_eqpower[N_EQPOWER_LENGTH - e->em_pan - 1]) >> 15; - } - e->rs_ratio = param->pitch; - } - - break; - - case (AL_FILTER_SET_FXAMT): - case (AL_FILTER_SET_PAN): - case (AL_FILTER_SET_VOLUME): - ptr = _pullSubFrame(e, &inp, &loutp, samples, ptr); - - if (e->em_delta >= e->em_segEnd){ - - /* - * We should have reached our target, calculate - * target in case e->em_segEnd was 0 - */ - e->em_ltgt = (e->em_volume * n_eqpower[e->em_pan]) >> 15; - e->em_rtgt = (e->em_volume * - n_eqpower[N_EQPOWER_LENGTH - e->em_pan - 1]) >> 15; - e->em_delta = e->em_segEnd; /* To prevent overflow */ - e->em_cvolL = e->em_ltgt; - e->em_cvolR = e->em_rtgt; - } else { - /* - * Estimate the current volume - */ - e->em_cvolL = _getVol(e->em_cvolL, e->em_delta, e->em_lratm, e->em_lratl); - e->em_cvolR = _getVol(e->em_cvolR, e->em_delta, e->em_rratm, e->em_rratl); - } - - /* - * We can't have volume of zero, because the envelope - * would never go anywhere from there - */ - if( e->em_cvolL == 0 ) e->em_cvolL = 1; - if( e->em_cvolR == 0 ) e->em_cvolR = 1; - - if (e->em_ctrlList->type == AL_FILTER_SET_PAN) - - /* - * This should result in a change to the current - * segment rate and target - */ - e->em_pan = (s16) e->em_ctrlList->data.i; - - if (e->em_ctrlList->type == AL_FILTER_SET_VOLUME){ - - /* - * Switching to a new segment - */ - e->em_delta = 0; - - /* - * Map volume non-linearly to give something close to - * loudness - */ - fVol = (e->em_ctrlList->data.i); - fVol = (fVol*fVol)>>15; - e->em_volume = (s16) fVol; - + tmp = ((s32)param->volume * (s32)param->volume) >> 15; + + e->em_volume = (s16)tmp; + e->em_pan = param->pan; + e->em_dryamt = n_eqpower[param->fxMix]; + e->em_wetamt = n_eqpower[N_EQPOWER_LENGTH - param->fxMix - 1]; + + if (param->samples) { + e->em_cvolL = 1; + e->em_cvolR = 1; + } else { + /* + * Attack time is zero. Simply set the + * volume. We don't want an attack segment. + */ + e->em_cvolL = (e->em_volume * n_eqpower[e->em_pan]) >> 15; + e->em_cvolR = (e->em_volume * n_eqpower[N_EQPOWER_LENGTH - e->em_pan - 1]) >> 15; + } + e->rs_ratio = param->pitch; + } + + break; + + case (AL_FILTER_SET_FXAMT): + case (AL_FILTER_SET_PAN): + case (AL_FILTER_SET_VOLUME): + ptr = _pullSubFrame(e, &inp, &loutp, samples, ptr); + + if (e->em_delta >= e->em_segEnd) { + + /* + * We should have reached our target, calculate + * target in case e->em_segEnd was 0 + */ + e->em_ltgt = (e->em_volume * n_eqpower[e->em_pan]) >> 15; + e->em_rtgt = (e->em_volume * n_eqpower[N_EQPOWER_LENGTH - e->em_pan - 1]) >> 15; + e->em_delta = e->em_segEnd; /* To prevent overflow */ + e->em_cvolL = e->em_ltgt; + e->em_cvolR = e->em_rtgt; + } else { + /* + * Estimate the current volume + */ + e->em_cvolL = _getVol(e->em_cvolL, e->em_delta, e->em_lratm, e->em_lratl); + e->em_cvolR = _getVol(e->em_cvolR, e->em_delta, e->em_rratm, e->em_rratl); + } + + /* + * We can't have volume of zero, because the envelope + * would never go anywhere from there + */ + if (e->em_cvolL == 0) { + e->em_cvolL = 1; + } + if (e->em_cvolR == 0) { + e->em_cvolR = 1; + } + + if (e->em_ctrlList->type == AL_FILTER_SET_PAN) + + /* + * This should result in a change to the current + * segment rate and target + */ + e->em_pan = (s16)e->em_ctrlList->data.i; + + if (e->em_ctrlList->type == AL_FILTER_SET_VOLUME) { + + /* + * Switching to a new segment + */ + e->em_delta = 0; + + /* + * Map volume non-linearly to give something close to + * loudness + */ + fVol = (e->em_ctrlList->data.i); + fVol = (fVol * fVol) >> 15; + e->em_volume = (s16)fVol; + #ifdef FINAL_ROUND - e->em_segEnd = SAMPLE184(e->em_ctrlList->moredata.i); + e->em_segEnd = SAMPLE184(e->em_ctrlList->moredata.i); #else - e->em_segEnd = e->em_ctrlList->moredata.i; + e->em_segEnd = e->em_ctrlList->moredata.i; #endif - - } - - if (e->em_ctrlList->type == AL_FILTER_SET_FXAMT){ - e->em_dryamt = n_eqpower[e->em_ctrlList->data.i]; - e->em_wetamt = n_eqpower[N_EQPOWER_LENGTH - e->em_ctrlList->data.i - 1]; - } - - /* - * Force a volume update - */ - e->em_first = 1; - break; - - case (AL_FILTER_START_VOICE): - { - ALStartParam *p = (ALStartParam *)e->em_ctrlList; - - /* - * Changing to PLAYING (since the previous state was - * persumable STOPPED, we'll just bump the output - * pointer rather than pull a subframe of zeros). - */ - if (p->unity) { - e->rs_upitch = 1; - } - - n_alLoadParam(e, AL_FILTER_SET_WAVETABLE, p->wave); - e->em_motion = AL_PLAYING; - } - break; - case (AL_FILTER_STOP_VOICE): - { - /* - * Changing to STOPPED and reset the filter - */ - ptr = _pullSubFrame(e, &inp, &loutp, samples, ptr); - n_alEnvmixerParam(e, AL_FILTER_RESET, 0); - } - break; - - case (AL_FILTER_FREE_VOICE): - { - N_ALFreeParam *param = (N_ALFreeParam *)e->em_ctrlList; - param->pvoice->offset = 0; - _n_freePVoice((N_PVoice *)param->pvoice); - } - break; + } + + if (e->em_ctrlList->type == AL_FILTER_SET_FXAMT) { + e->em_dryamt = n_eqpower[e->em_ctrlList->data.i]; + e->em_wetamt = n_eqpower[N_EQPOWER_LENGTH - e->em_ctrlList->data.i - 1]; + } + + /* + * Force a volume update + */ + e->em_first = 1; + break; + + case (AL_FILTER_START_VOICE): { + ALStartParam* p = (ALStartParam*)e->em_ctrlList; + + /* + * Changing to PLAYING (since the previous state was + * persumable STOPPED, we'll just bump the output + * pointer rather than pull a subframe of zeros). + */ + if (p->unity) { + e->rs_upitch = 1; + } + + n_alLoadParam(e, AL_FILTER_SET_WAVETABLE, p->wave); + e->em_motion = AL_PLAYING; + } break; + case (AL_FILTER_STOP_VOICE): { + /* + * Changing to STOPPED and reset the filter + */ + ptr = _pullSubFrame(e, &inp, &loutp, samples, ptr); + n_alEnvmixerParam(e, AL_FILTER_RESET, 0); + } break; + + case (AL_FILTER_FREE_VOICE): { + N_ALFreeParam* param = (N_ALFreeParam*)e->em_ctrlList; + param->pvoice->offset = 0; + _n_freePVoice((N_PVoice*)param->pvoice); + } break; #if 1 - case (AL_FILTER_SET_PITCH): - ptr = _pullSubFrame(e, &inp, &loutp, samples, ptr); - e->rs_ratio = e->em_ctrlList->data.f; - break; - case (AL_FILTER_SET_UNITY_PITCH): - ptr = _pullSubFrame(e, &inp, &loutp, samples, ptr); - e->rs_upitch = 1; - break; - case (AL_FILTER_SET_WAVETABLE): - ptr = _pullSubFrame(e, &inp, &loutp, samples, ptr); - n_alLoadParam(e, AL_FILTER_SET_WAVETABLE, - (void *)e->em_ctrlList->data.i); - break; + case (AL_FILTER_SET_PITCH): + ptr = _pullSubFrame(e, &inp, &loutp, samples, ptr); + e->rs_ratio = e->em_ctrlList->data.f; + break; + case (AL_FILTER_SET_UNITY_PITCH): + ptr = _pullSubFrame(e, &inp, &loutp, samples, ptr); + e->rs_upitch = 1; + break; + case (AL_FILTER_SET_WAVETABLE): + ptr = _pullSubFrame(e, &inp, &loutp, samples, ptr); + n_alLoadParam(e, AL_FILTER_SET_WAVETABLE, (void*)e->em_ctrlList->data.i); + break; #endif - default: - /* - * Pull the reuired number of samples and then pass the message - * on down the chain - */ - ptr = _pullSubFrame(e, &inp, &loutp, samples, ptr); - n_alEnvmixerParam(e, e->em_ctrlList->type, - (void *) e->em_ctrlList->data.i); - break; + default: + /* + * Pull the reuired number of samples and then pass the message + * on down the chain + */ + ptr = _pullSubFrame(e, &inp, &loutp, samples, ptr); + n_alEnvmixerParam(e, e->em_ctrlList->type, (void*)e->em_ctrlList->data.i); + break; + } + loutp += (samples << 1); + outCount -= samples; + + /* + * put the param record back on the free list + */ + thisParam = e->em_ctrlList; + e->em_ctrlList = e->em_ctrlList->next; + if (e->em_ctrlList == 0) { + e->em_ctrlTail = 0; + } + + _n_freeParam(thisParam); } - loutp += (samples<<1); - outCount -= samples; - + + ptr = _pullSubFrame(e, &inp, &loutp, outCount, ptr); + /* - * put the param record back on the free list + * Prevent overflow in e->em_delta */ - thisParam = e->em_ctrlList; - e->em_ctrlList = e->em_ctrlList->next; - if (e->em_ctrlList == 0) - e->em_ctrlTail = 0; - - _n_freeParam(thisParam); - - } - - ptr = _pullSubFrame(e, &inp, &loutp, outCount, ptr); - - /* - * Prevent overflow in e->em_delta - */ - if (e->em_delta > e->em_segEnd) - e->em_delta = e->em_segEnd; - + if (e->em_delta > e->em_segEnd) { + e->em_delta = e->em_segEnd; + } + #ifdef AUD_PROFILE - PROFILE_AUD(env_num, env_cnt, env_max, env_min); + PROFILE_AUD(env_num, env_cnt, env_max, env_min); #endif - return ptr; + return ptr; } -s32 - n_alEnvmixerParam(N_PVoice *filter, s32 paramID, void *param) -{ - N_PVoice *e = filter; - - switch (paramID) { - case (AL_FILTER_ADD_UPDATE): - if (e->em_ctrlTail) { - e->em_ctrlTail->next = (ALParam *)param; - } else { - e->em_ctrlList = (ALParam *)param; - } - e->em_ctrlTail = (ALParam *)param; - break; - case (AL_FILTER_RESET): - e->em_first = 1; - e->em_motion = AL_STOPPED; - e->em_volume = 1; - e->em_segEnd = 0; - e->rs_delta = 0.0; - e->rs_first = 1; - e->rs_upitch = 0; - n_alLoadParam(e, AL_FILTER_RESET, param); - break; - case (AL_FILTER_START): - e->em_motion = AL_PLAYING; - break; - default: +s32 n_alEnvmixerParam(N_PVoice* filter, s32 paramID, void* param) { + N_PVoice* e = filter; + + switch (paramID) { + case (AL_FILTER_ADD_UPDATE): + if (e->em_ctrlTail) { + e->em_ctrlTail->next = (ALParam*)param; + } else { + e->em_ctrlList = (ALParam*)param; + } + e->em_ctrlTail = (ALParam*)param; + break; + case (AL_FILTER_RESET): + e->em_first = 1; + e->em_motion = AL_STOPPED; + e->em_volume = 1; + e->em_segEnd = 0; + e->rs_delta = 0.0; + e->rs_first = 1; + e->rs_upitch = 0; + n_alLoadParam(e, AL_FILTER_RESET, param); + break; + case (AL_FILTER_START): + e->em_motion = AL_PLAYING; + break; + default: #if 1 - n_alLoadParam(e, paramID, param); + n_alLoadParam(e, paramID, param); #else - n_alResampleParam(e, paramID, param); + n_alResampleParam(e, paramID, param); #endif - break; - } - return 0; + break; + } + return 0; } -static - Acmd* _pullSubFrame(N_PVoice *filter, s16 *inp, s16 *outp, s32 outCount, - Acmd *p) -{ - Acmd *ptr = p; - N_PVoice *e = filter; +static Acmd* _pullSubFrame(N_PVoice* filter, s16* inp, s16* outp, s32 outCount, Acmd* p) { + Acmd* ptr = p; + N_PVoice* e = filter; #ifndef N_MICRO - s16 *inpp = AL_RESAMPLER_OUT; + s16* inpp = AL_RESAMPLER_OUT; #else - s16 *inpp = N_AL_RESAMPLER_OUT; + s16* inpp = N_AL_RESAMPLER_OUT; #endif - /* filter must be playing and request non-zero output samples to pull. */ - if (e->em_motion != AL_PLAYING || !outCount) - return ptr; - - /* - * ask all filters upstream from us to build their command - * lists. - */ - - ptr = n_alResamplePull(e,inp, p); - - /* - * construct our portion of the command list - */ -#ifndef N_MICRO - aSetBuffer(ptr++, A_MAIN, *inp, AL_MAIN_L_OUT, FIXED_SAMPLE<<1); - aSetBuffer(ptr++, A_AUX, AL_MAIN_R_OUT , AL_AUX_L_OUT , - AL_AUX_R_OUT ); -#endif - - if (e->em_first){ - e->em_first = 0; - + /* filter must be playing and request non-zero output samples to pull. */ + if (e->em_motion != AL_PLAYING || !outCount) + return ptr; + + /* + * ask all filters upstream from us to build their command + * lists. + */ + + ptr = n_alResamplePull(e, inp, p); + /* - * Calculate derived parameters + * construct our portion of the command list */ - e->em_ltgt = (e->em_volume * n_eqpower[e->em_pan]) >> 15; - e->em_lratm = _getRate((f64)e->em_cvolL, (f64)e->em_ltgt, - e->em_segEnd, &(e->em_lratl)); - e->em_rtgt = (e->em_volume * - n_eqpower[N_EQPOWER_LENGTH - e->em_pan - 1]) >> 15; - e->em_rratm = _getRate((f64)e->em_cvolR, (f64)e->em_rtgt, e->em_segEnd, - &(e->em_rratl)); - #ifndef N_MICRO - aSetVolume(ptr++, A_LEFT | A_VOL, e->em_cvolL, 0, 0); - aSetVolume(ptr++, A_RIGHT | A_VOL, e->em_cvolR, 0, 0); - aSetVolume(ptr++, A_LEFT | A_RATE, e->em_ltgt, e->em_lratm, e->em_lratl); - aSetVolume(ptr++, A_RIGHT | A_RATE, e->em_rtgt, e->em_rratm, e->em_rratl); - aSetVolume(ptr++, A_AUX, e->em_dryamt, 0, e->em_wetamt); - aEnvMixer (ptr++, A_INIT | A_AUX, osVirtualToPhysical(e->em_state)); - } - else - aEnvMixer(ptr++, A_CONTINUE | A_AUX, osVirtualToPhysical(e->em_state)); + aSetBuffer(ptr++, A_MAIN, *inp, AL_MAIN_L_OUT, FIXED_SAMPLE << 1); + aSetBuffer(ptr++, A_AUX, AL_MAIN_R_OUT, AL_AUX_L_OUT, AL_AUX_R_OUT); +#endif + + if (e->em_first) { + e->em_first = 0; + + /* + * Calculate derived parameters + */ + e->em_ltgt = (e->em_volume * n_eqpower[e->em_pan]) >> 15; + e->em_lratm = _getRate((f64)e->em_cvolL, (f64)e->em_ltgt, e->em_segEnd, &(e->em_lratl)); + e->em_rtgt = (e->em_volume * n_eqpower[N_EQPOWER_LENGTH - e->em_pan - 1]) >> 15; + e->em_rratm = _getRate((f64)e->em_cvolR, (f64)e->em_rtgt, e->em_segEnd, &(e->em_rratl)); + +#ifndef N_MICRO + aSetVolume(ptr++, A_LEFT | A_VOL, e->em_cvolL, 0, 0); + aSetVolume(ptr++, A_RIGHT | A_VOL, e->em_cvolR, 0, 0); + aSetVolume(ptr++, A_LEFT | A_RATE, e->em_ltgt, e->em_lratm, e->em_lratl); + aSetVolume(ptr++, A_RIGHT | A_RATE, e->em_rtgt, e->em_rratm, e->em_rratl); + aSetVolume(ptr++, A_AUX, e->em_dryamt, 0, e->em_wetamt); + aEnvMixer(ptr++, A_INIT | A_AUX, osVirtualToPhysical(e->em_state)); + } else { + EnvMixer(ptr++, A_CONTINUE | A_AUX, osVirtualToPhysical(e->em_state)); + } #else - // needs to be on same line. - n_aSetVolume(ptr++, A_RATE, e->em_ltgt, e->em_lratm, e->em_lratl); n_aSetVolume(ptr++, A_LEFT | A_VOL, e->em_cvolL, e->em_dryamt, e->em_wetamt); n_aSetVolume(ptr++, A_RIGHT | A_VOL, e->em_rtgt, e->em_rratm, e->em_rratl); n_aEnvMixer (ptr++, A_INIT, e->em_cvolR, osVirtualToPhysical(e->em_state)); } else n_aEnvMixer(ptr++, A_CONTINUE, 0, osVirtualToPhysical(e->em_state)); -#endif - /* - * bump the input buffer pointer - */ - - *inp += (FIXED_SAMPLE<<1); - e->em_delta += FIXED_SAMPLE; - - return ptr; + // clang-format off + // needs to be on same line. + n_aSetVolume(ptr++, A_RATE, e->em_ltgt, e->em_lratm, e->em_lratl); \ + n_aSetVolume(ptr++, A_LEFT | A_VOL, e->em_cvolL, e->em_dryamt, e->em_wetamt); \ + n_aSetVolume(ptr++, A_RIGHT | A_VOL, e->em_rtgt, e->em_rratm, e->em_rratl); \ + n_aEnvMixer(ptr++, A_INIT, e->em_cvolR, osVirtualToPhysical(e->em_state)); + // clang-format on + } else { + n_aEnvMixer(ptr++, A_CONTINUE, 0, osVirtualToPhysical(e->em_state)); + } +#endif + + /* + * bump the input buffer pointer + */ + + *inp += (FIXED_SAMPLE << 1); + e->em_delta += FIXED_SAMPLE; + + return ptr; } #ifndef N_MICRO -#define EXP_MASK 0x7f800000 +#define EXP_MASK 0x7f800000 #define MANT_MASK 0x807fffff -static - s16 _getRate(f64 vol, f64 tgt, s32 count, u16* ratel) -{ - s16 s; - - f64 invn = 1.0/count, eps, a, fs, mant; - s32 i_invn, ex, indx; - +static s16 _getRate(f64 vol, f64 tgt, s32 count, u16* ratel) { + s16 s; + + f64 invn = 1.0 / count, eps, a, fs, mant; + s32 i_invn, ex, indx; + #ifdef AUD_PROFILE - lastCnt[++cnt_index] = osGetCount(); + lastCnt[++cnt_index] = osGetCount(); #endif - - if (count == 0){ - if (tgt >= vol){ - *ratel = 0xffff; - return 0x7fff; - } - else{ - *ratel = 0; - return 0; + + if (count == 0) { + if (tgt >= vol) { + *ratel = 0xffff; + return 0x7fff; + } else { + *ratel = 0; + return 0; + } } - } - - if (tgt < 1.0) - tgt = 1.0; - if (vol <= 0) vol = 1; /* zero and neg values not allowed */ - + + if (tgt < 1.0) + tgt = 1.0; + if (vol <= 0) + vol = 1; /* zero and neg values not allowed */ + #define NBITS (3) -#define NPOS (1<>= 1; +#define M_LN2 0.69314718055994530942 + /* + * rww's parametric pow() + Goal: compute a = (tgt/vol)^(1/count) + + Approach: + (tgt/vol)^(1/count) = + ((tgt/vol)^(1/2^30))^(2^30*1/count) + + (tgt/vol)^(1/2^30) ~= 1 + eps + + where + + eps ~= ln(tgt/vol)/2^30 + + ln(tgt/vol) = ln2(tgt/vol) * ln(2) + + ln2(tgt/vol) = fp_exponent( tgt/vol ) + + ln2( fp_mantissa( tgt/vol ) ) + + fp_mantissa() and fp_exponent() are + calculated via tricky bit manipulations of + the floating point number. ln2() is + approximated by a look up table. + + Note that this final (1+eps) value needs + to be raised to the 2^30/count power. This + is done by operating on the binary representaion + of this number in the final while loop. + + Enjoy! + */ + { + f64 logtab[] = { -0.912537, -0.752072, -0.607683, -0.476438, -0.356144, -0.245112, -0.142019, -0.045804 }; + + i_invn = (s32)_ldexpf(invn, NFRACBITS); + mant = _frexpf(tgt / vol, &ex); + indx = (s32)(_ldexpf(mant, NBITS + 1)); /* NPOS <= indx < 2*NPOS */ + eps = (logtab[indx - NPOS] + ex) * M_LN2; + eps /= _ldexpf(1, NFRACBITS); /* eps / 2^NFRACBITS */ + fs = (1.0 + eps); + a = 1.0; + while (i_invn) { + if (i_invn & 1) + a = a * fs; + fs *= fs; + i_invn >>= 1; + } } - } - - a *= (a *= (a *= a)); - s = (s16) a; - *ratel = (s16)(0xffff * (a - (f32) s)); - + + a *= (a *= (a *= a)); + s = (s16)a; + *ratel = (s16)(0xffff * (a - (f32)s)); + #ifdef AUD_PROFILE - PROFILE_AUD(rate_num, rate_cnt, rate_max, rate_min); + PROFILE_AUD(rate_num, rate_cnt, rate_max, rate_min); #endif - return (s16)a; - + return (s16)a; } #else -static -s16 _getRate(f64 vol, f64 tgt, s32 count, u16* ratel) -{ - s16 s, tmp; - f64 invn, a, f; +static s16 _getRate(f64 vol, f64 tgt, s32 count, u16* ratel) { + s16 s, tmp; + f64 invn, a, f; #ifdef AUD_PROFILE lastCnt[++cnt_index] = osGetCount(); #endif - - if (count == 0){ - if (tgt >= vol){ + + if (count == 0) { + if (tgt >= vol) { *ratel = 0xffff; return 0x7fff; - } - else{ - *ratel = 0; + } else { + *ratel = 0; return 0x8000; } } @@ -576,7 +545,8 @@ s16 _getRate(f64 vol, f64 tgt, s32 count, u16* ratel) if (tgt < 1.0) tgt = 1.0; - if (vol <= 0.0) vol = 1.0; /* zero and neg values not allowed */ + if (vol <= 0.0) + vol = 1.0; /* zero and neg values not allowed */ a = (tgt - vol) * invn * 8.0; s = (s16)a; @@ -588,7 +558,7 @@ s16 _getRate(f64 vol, f64 tgt, s32 count, u16* ratel) f -= (f64)tmp; #ifdef AUD_PROFILE - PROFILE_AUD( rate_num, rate_cnt, rate_max, rate_min); + PROFILE_AUD(rate_num, rate_cnt, rate_max, rate_min); #endif *ratel = (u16)(0xffff * f); @@ -597,51 +567,48 @@ s16 _getRate(f64 vol, f64 tgt, s32 count, u16* ratel) #endif #ifndef N_MICRO -static - f32 _getVol(f32 ivol, s32 samples, s16 ratem, u16 ratel) -{ - f32 r, a; - s32 i; - +static f32 _getVol(f32 ivol, s32 samples, s16 ratem, u16 ratel) { + f32 r, a; + s32 i; + #ifdef AUD_PROFILE - lastCnt[++cnt_index] = osGetCount(); + lastCnt[++cnt_index] = osGetCount(); #endif - - /* - * Rate values are actually rate^8 - */ - samples >>=3; - if (samples == 0){ - return ivol; - } - r = ((f32) (ratem<<16) + (f32) ratel)/65536; - - a = 1.0; - for (i=0; i<32; i++){ - if( samples & 1 ) - a *= r; - samples >>= 1; - if (samples == 0) - break; - r *= r; - } - ivol *= a; + + /* + * Rate values are actually rate^8 + */ + samples >>= 3; + if (samples == 0) { + return ivol; + } + r = ((f32)(ratem << 16) + (f32)ratel) / 65536; + + a = 1.0; + for (i = 0; i < 32; i++) { + if (samples & 1) + a *= r; + samples >>= 1; + if (samples == 0) { + break; + } + r *= r; + } + ivol *= a; #ifdef AUD_PROFILE - PROFILE_AUD(vol_num, vol_cnt, vol_max, vol_min); + PROFILE_AUD(vol_num, vol_cnt, vol_max, vol_min); #endif - return ivol; + return ivol; } #else -static -s16 _getVol(s16 ivol, s32 samples, s16 ratem, u16 ratel) -{ +static s16 _getVol(s16 ivol, s32 samples, s16 ratem, u16 ratel) { s32 tmp1; #ifdef AUD_PROFILE lastCnt[++cnt_index] = osGetCount(); #endif - + samples >>= 3; - if (samples == 0){ + if (samples == 0) { return ivol; } diff --git a/src/libnaudio/n_load.c b/src/libnaudio/n_load.c index d41ba7d1..6f69492e 100644 --- a/src/libnaudio/n_load.c +++ b/src/libnaudio/n_load.c @@ -22,305 +22,303 @@ #include #ifndef MIN -# define MIN(a,b) (((a)<(b))?(a):(b)) +#define MIN(a, b) (((a) < (b)) ? (a) : (b)) #endif #ifdef AUD_PROFILE extern u32 cnt_index, adpcm_num, adpcm_cnt, adpcm_max, adpcm_min, lastCnt[]; #endif -#define ADPCMFBYTES 9 -#define LFSAMPLES 4 - -static - Acmd *_decodeChunk(Acmd *ptr, N_PVoice *f, s32 tsam, s32 nbytes, s16 outp, s16 inp, u32 flags); - -Acmd *n_alAdpcmPull(N_PVoice *filter, s16 *outp, s32 outCount, Acmd *p) -{ - Acmd *ptr = p; - s16 inp; - s32 tsam; - s32 nframes; - s32 nbytes; - s32 overFlow; - s32 startZero; - s32 nOver; - s32 nSam; - s32 op; - s32 nLeft; - s32 bEnd; - s32 decoded = 0; - s32 looped = 0; - - N_PVoice *f = filter; - +#define ADPCMFBYTES 9 +#define LFSAMPLES 4 + +static Acmd* _decodeChunk(Acmd* ptr, N_PVoice* f, s32 tsam, s32 nbytes, s16 outp, s16 inp, u32 flags); + +Acmd* n_alAdpcmPull(N_PVoice* filter, s16* outp, s32 outCount, Acmd* p) { + Acmd* ptr = p; + s16 inp; + s32 tsam; + s32 nframes; + s32 nbytes; + s32 overFlow; + s32 startZero; + s32 nOver; + s32 nSam; + s32 op; + s32 nLeft; + s32 bEnd; + s32 decoded = 0; + s32 looped = 0; + + N_PVoice* f = filter; + #ifdef AUD_PROFILE - lastCnt[++cnt_index] = osGetCount(); + lastCnt[++cnt_index] = osGetCount(); #endif - - if (outCount == 0) - return ptr; -#ifndef N_MICRO - inp = AL_DECODER_IN; + if (outCount == 0) + return ptr; + +#ifndef N_MICRO + inp = AL_DECODER_IN; #else - inp = N_AL_DECODER_IN; + inp = N_AL_DECODER_IN; #endif - aLoadADPCM(ptr++, f->dc_bookSize, - K0_TO_PHYS(f->dc_table->waveInfo.adpcmWave.book->book)); - - looped = (outCount + f->dc_sample > f->dc_loop.end) && (f->dc_loop.count != 0); - if (looped) - nSam = f->dc_loop.end - f->dc_sample; - else - nSam = outCount; - - if (f->dc_lastsam) - nLeft = ADPCMFSIZE - f->dc_lastsam; - else - nLeft = 0; - tsam = nSam - nLeft; - if (tsam<0) tsam = 0; - - nframes = (tsam+ADPCMFSIZE-1)>>LFSAMPLES; - nbytes = nframes*ADPCMFBYTES; - - if (looped){ - - ptr = _decodeChunk(ptr, f, tsam, nbytes, *outp, inp, f->dc_first); - - /* - * Fix up output pointer, which will be used as the input pointer - * by the following module. - */ - if (f->dc_lastsam) - *outp += (f->dc_lastsam<<1); - else - *outp += (ADPCMFSIZE<<1); - - /* - * Now fix up state info to reflect the loop start point - */ - f->dc_lastsam = f->dc_loop.start &0xf; - f->dc_memin = (s32) f->dc_table->base + ADPCMFBYTES * - ((s32) (f->dc_loop.start>>LFSAMPLES) + 1); - f->dc_sample = f->dc_loop.start; - - bEnd = *outp; - while (outCount > nSam){ - - outCount -= nSam; - - /* - * Put next one after the end of the last lot - on the - * frame boundary (32 byte) after the end. - */ + aLoadADPCM(ptr++, f->dc_bookSize, K0_TO_PHYS(f->dc_table->waveInfo.adpcmWave.book->book)); + + looped = (outCount + f->dc_sample > f->dc_loop.end) && (f->dc_loop.count != 0); + if (looped) { + nSam = f->dc_loop.end - f->dc_sample; + } else { + nSam = outCount; + } + + if (f->dc_lastsam) { + nLeft = ADPCMFSIZE - f->dc_lastsam; + } else { + nLeft = 0; + } + tsam = nSam - nLeft; + if (tsam < 0) { + tsam = 0; + } + + nframes = (tsam + ADPCMFSIZE - 1) >> LFSAMPLES; + nbytes = nframes * ADPCMFBYTES; + + if (looped) { + + ptr = _decodeChunk(ptr, f, tsam, nbytes, *outp, inp, f->dc_first); + + /* + * Fix up output pointer, which will be used as the input pointer + * by the following module. + */ + if (f->dc_lastsam) + *outp += (f->dc_lastsam << 1); + else + *outp += (ADPCMFSIZE << 1); + + /* + * Now fix up state info to reflect the loop start point + */ + f->dc_lastsam = f->dc_loop.start & 0xf; + f->dc_memin = (s32)f->dc_table->base + ADPCMFBYTES * ((s32)(f->dc_loop.start >> LFSAMPLES) + 1); + f->dc_sample = f->dc_loop.start; + + bEnd = *outp; + while (outCount > nSam) { + + outCount -= nSam; + + /* + * Put next one after the end of the last lot - on the + * frame boundary (32 byte) after the end. + */ #if 0 op = (bEnd + ((nframes+1)<<(LFSAMPLES+1))) & ~0x1f; #else - op = (bEnd + ((nframes+1)<<(LFSAMPLES+1)) + 16) & ~0x1f; + op = (bEnd + ((nframes + 1) << (LFSAMPLES + 1)) + 16) & ~0x1f; #endif - - /* - * The actual end of data - */ - bEnd += (nSam<<1); - - /* - * -1 is loop forever - the loop count is not exact now - * for small loops! - */ - if ((f->dc_loop.count != -1) && (f->dc_loop.count != 0)) - f->dc_loop.count--; - - /* - * What's left to compute. - */ - nSam = MIN(outCount, f->dc_loop.end - f->dc_loop.start); - tsam = nSam - ADPCMFSIZE + f->dc_lastsam; - if (tsam<0) tsam = 0; - nframes = (tsam+ADPCMFSIZE-1)>>LFSAMPLES; - nbytes = nframes*ADPCMFBYTES; - ptr = _decodeChunk(ptr, f, tsam, nbytes, op, inp, f->dc_first | A_LOOP); - /* - * Merge the two sections in DMEM. - */ - aDMEMMove(ptr++, op+(f->dc_lastsam<<1), bEnd, nSam<<1); + + /* + * The actual end of data + */ + bEnd += (nSam << 1); + + /* + * -1 is loop forever - the loop count is not exact now + * for small loops! + */ + if ((f->dc_loop.count != -1) && (f->dc_loop.count != 0)) { + f->dc_loop.count--; + } + + /* + * What's left to compute. + */ + nSam = MIN(outCount, f->dc_loop.end - f->dc_loop.start); + tsam = nSam - ADPCMFSIZE + f->dc_lastsam; + if (tsam < 0) { + tsam = 0; + } + nframes = (tsam + ADPCMFSIZE - 1) >> LFSAMPLES; + nbytes = nframes * ADPCMFBYTES; + ptr = _decodeChunk(ptr, f, tsam, nbytes, op, inp, f->dc_first | A_LOOP); + /* + * Merge the two sections in DMEM. + */ + aDMEMMove(ptr++, op + (f->dc_lastsam << 1), bEnd, nSam << 1); + } + + f->dc_lastsam = (outCount + f->dc_lastsam) & 0xf; + f->dc_sample += outCount; + f->dc_memin += ADPCMFBYTES * nframes; +#ifdef AUD_PROFILE + PROFILE_AUD(adpcm_num, adpcm_cnt, adpcm_max, adpcm_min); +#endif + return ptr; + } + + /* + * The unlooped case, which is executed most of the time + */ + + nSam = nframes << LFSAMPLES; + + /* + * overFlow is the number of bytes past the end + * of the bitstream I try to generate + */ + overFlow = f->dc_memin + nbytes - ((s32)f->dc_table->base + f->dc_table->len); + if (overFlow < 0) { + overFlow = 0; + } + nOver = (overFlow / ADPCMFBYTES) << LFSAMPLES; + if (nOver > nSam + nLeft) { + nOver = nSam + nLeft; + } + + nbytes -= overFlow; + + if ((nOver - (nOver & 0xf)) < outCount) { + decoded = 1; + ptr = _decodeChunk(ptr, f, nSam - nOver, nbytes, *outp, inp, f->dc_first); + + if (f->dc_lastsam) + *outp += (f->dc_lastsam << 1); + else + *outp += (ADPCMFSIZE << 1); + + f->dc_lastsam = (outCount + f->dc_lastsam) & 0xf; + f->dc_sample += outCount; + f->dc_memin += ADPCMFBYTES * nframes; + } else { + f->dc_lastsam = 0; + f->dc_memin += ADPCMFBYTES * nframes; + } + + /* + * Put zeros in if necessary + */ + if (nOver) { + f->dc_lastsam = 0; + if (decoded) { + startZero = (nLeft + nSam - nOver) << 1; + } else { + startZero = 0; + } + aClearBuffer(ptr++, startZero + *outp, nOver << 1); } - - f->dc_lastsam = (outCount + f->dc_lastsam) & 0xf; - f->dc_sample += outCount; - f->dc_memin += ADPCMFBYTES*nframes; #ifdef AUD_PROFILE PROFILE_AUD(adpcm_num, adpcm_cnt, adpcm_max, adpcm_min); #endif + return ptr; - } - - /* - * The unlooped case, which is executed most of the time - */ - - nSam = nframes<dc_memin + nbytes - ((s32) f->dc_table->base + f->dc_table->len); - if (overFlow < 0) - overFlow = 0; - nOver = (overFlow/ADPCMFBYTES)< nSam + nLeft) - nOver = nSam + nLeft; - - nbytes -= overFlow; - - if ((nOver - (nOver & 0xf))< outCount){ - decoded = 1; - ptr = _decodeChunk(ptr, f, nSam - nOver, nbytes, *outp, inp, f->dc_first); - - if (f->dc_lastsam) - *outp += (f->dc_lastsam<<1); - else - *outp += (ADPCMFSIZE<<1); - - f->dc_lastsam = (outCount + f->dc_lastsam) & 0xf; - f->dc_sample += outCount; - f->dc_memin += ADPCMFBYTES*nframes; - } else { - f->dc_lastsam = 0; - f->dc_memin += ADPCMFBYTES*nframes; - } - - /* - * Put zeros in if necessary - */ - if (nOver){ - f->dc_lastsam = 0; - if (decoded) - startZero = (nLeft + nSam - nOver)<<1; - else - startZero = 0; - aClearBuffer(ptr++, startZero + *outp, nOver<<1); - } -#ifdef AUD_PROFILE - PROFILE_AUD(adpcm_num, adpcm_cnt, adpcm_max, adpcm_min); -#endif - - return ptr; } -s32 - n_alLoadParam(N_PVoice *filter, s32 paramID, void *param) -{ - N_PVoice *a = filter; +s32 n_alLoadParam(N_PVoice* filter, s32 paramID, void* param) { + N_PVoice* a = filter; #if 0 ALFilter *f = (ALFilter *) filter; #endif - - switch (paramID) { - case (AL_FILTER_SET_WAVETABLE): - a->dc_table = (ALWaveTable *) param; - a->dc_memin = (s32) a->dc_table->base; - a->dc_sample = 0; - switch (a->dc_table->type){ - case (AL_ADPCM_WAVE): - - a->dc_table->len = ADPCMFBYTES * - ((s32) (a->dc_table->len/ADPCMFBYTES)); - - a->dc_bookSize = 2*a->dc_table->waveInfo.adpcmWave.book->order* - a->dc_table->waveInfo.adpcmWave.book->npredictors*ADPCMVSIZE; - if (a->dc_table->waveInfo.adpcmWave.loop) { - a->dc_loop.start = a->dc_table->waveInfo.adpcmWave.loop->start; - a->dc_loop.end = a->dc_table->waveInfo.adpcmWave.loop->end; - a->dc_loop.count = a->dc_table->waveInfo.adpcmWave.loop->count; - alCopy(a->dc_table->waveInfo.adpcmWave.loop->state, - a->dc_lstate, sizeof(ADPCM_STATE)); - } else { - a->dc_loop.start = a->dc_loop.end = a->dc_loop.count = 0; - } - break; - - case (AL_RAW16_WAVE): - if (a->dc_table->waveInfo.rawWave.loop) { - a->dc_loop.start = a->dc_table->waveInfo.rawWave.loop->start; - a->dc_loop.end = a->dc_table->waveInfo.rawWave.loop->end; - a->dc_loop.count = a->dc_table->waveInfo.rawWave.loop->count; - } else { - a->dc_loop.start = a->dc_loop.end = a->dc_loop.count = 0; - } - break; - - default: - break; - + + switch (paramID) { + case (AL_FILTER_SET_WAVETABLE): + a->dc_table = (ALWaveTable*)param; + a->dc_memin = (s32)a->dc_table->base; + a->dc_sample = 0; + switch (a->dc_table->type) { + case (AL_ADPCM_WAVE): + + a->dc_table->len = ADPCMFBYTES * ((s32)(a->dc_table->len / ADPCMFBYTES)); + + a->dc_bookSize = 2 * a->dc_table->waveInfo.adpcmWave.book->order * + a->dc_table->waveInfo.adpcmWave.book->npredictors * ADPCMVSIZE; + if (a->dc_table->waveInfo.adpcmWave.loop) { + a->dc_loop.start = a->dc_table->waveInfo.adpcmWave.loop->start; + a->dc_loop.end = a->dc_table->waveInfo.adpcmWave.loop->end; + a->dc_loop.count = a->dc_table->waveInfo.adpcmWave.loop->count; + alCopy(a->dc_table->waveInfo.adpcmWave.loop->state, a->dc_lstate, sizeof(ADPCM_STATE)); + } else { + a->dc_loop.start = a->dc_loop.end = a->dc_loop.count = 0; + } + break; + + case (AL_RAW16_WAVE): + if (a->dc_table->waveInfo.rawWave.loop) { + a->dc_loop.start = a->dc_table->waveInfo.rawWave.loop->start; + a->dc_loop.end = a->dc_table->waveInfo.rawWave.loop->end; + a->dc_loop.count = a->dc_table->waveInfo.rawWave.loop->count; + } else { + a->dc_loop.start = a->dc_loop.end = a->dc_loop.count = 0; + } + break; + + default: + break; + } + break; + + case (AL_FILTER_RESET): + a->dc_lastsam = 0; + a->dc_first = 1; + a->dc_sample = 0; + + /* sct 2/14/96 - Check table since it is initialized to null and */ + /* Get loop info according to table type. */ + if (a->dc_table) { + a->dc_memin = (s32)a->dc_table->base; + if (a->dc_table->type == AL_ADPCM_WAVE) { + if (a->dc_table->waveInfo.adpcmWave.loop) { + a->dc_loop.count = a->dc_table->waveInfo.adpcmWave.loop->count; + } + } else if (a->dc_table->type == AL_RAW16_WAVE) { + if (a->dc_table->waveInfo.rawWave.loop) { + a->dc_loop.count = a->dc_table->waveInfo.rawWave.loop->count; + } + } + } + + break; + + default: + break; } - break; - - case (AL_FILTER_RESET): - a->dc_lastsam = 0; - a->dc_first = 1; - a->dc_sample = 0; - - /* sct 2/14/96 - Check table since it is initialized to null and */ - /* Get loop info according to table type. */ - if (a->dc_table) - { - a->dc_memin = (s32) a->dc_table->base; - if (a->dc_table->type == AL_ADPCM_WAVE) - { - if (a->dc_table->waveInfo.adpcmWave.loop) - a->dc_loop.count = a->dc_table->waveInfo.adpcmWave.loop->count; - } - else if (a->dc_table->type == AL_RAW16_WAVE) - { - if (a->dc_table->waveInfo.rawWave.loop) - a->dc_loop.count = a->dc_table->waveInfo.rawWave.loop->count; - } - } - - break; - - default: - break; - } } -Acmd *_decodeChunk(Acmd *ptr, N_PVoice *f, s32 tsam, - s32 nbytes, s16 outp, s16 inp, u32 flags) -{ - s32 dramAlign, dramLoc; - - if (nbytes > 0){ - dramLoc = (f->dc_dma)(f->dc_memin, nbytes, f->dc_dmaState); - /* - * Make sure enough is loaded into DMEM to take care - * of 8 byte alignment - */ - dramAlign = dramLoc & 0x7; - nbytes += dramAlign; +Acmd* _decodeChunk(Acmd* ptr, N_PVoice* f, s32 tsam, s32 nbytes, s16 outp, s16 inp, u32 flags) { + s32 dramAlign, dramLoc; + + if (nbytes > 0) { + dramLoc = (f->dc_dma)(f->dc_memin, nbytes, f->dc_dmaState); + /* + * Make sure enough is loaded into DMEM to take care + * of 8 byte alignment + */ + dramAlign = dramLoc & 0x7; + nbytes += dramAlign; #ifndef N_MICRO - aSetBuffer(ptr++, 0, inp, 0, nbytes + 8 - (nbytes & 0x7)); - aLoadBuffer(ptr++, dramLoc - dramAlign); + aSetBuffer(ptr++, 0, inp, 0, nbytes + 8 - (nbytes & 0x7)); + aLoadBuffer(ptr++, dramLoc - dramAlign); #else - n_aLoadBuffer(ptr++, nbytes + 8 - (nbytes & 0x7), inp, dramLoc - dramAlign); + n_aLoadBuffer(ptr++, nbytes + 8 - (nbytes & 0x7), inp, dramLoc - dramAlign); #endif - } else - dramAlign = 0; - - if (flags & A_LOOP){ - aSetLoop(ptr++, K0_TO_PHYS(f->dc_lstate)); - } + } else { + dramAlign = 0; + } + + if (flags & A_LOOP) { + aSetLoop(ptr++, K0_TO_PHYS(f->dc_lstate)); + } #ifndef N_MICRO - aSetBuffer(ptr++, 0, inp + dramAlign, outp, tsam<<1); - aADPCMdec(ptr++, flags, K0_TO_PHYS(f->dc_state)); + aSetBuffer(ptr++, 0, inp + dramAlign, outp, tsam << 1); + aADPCMdec(ptr++, flags, K0_TO_PHYS(f->dc_state)); #else - n_aADPCMdec(ptr++, K0_TO_PHYS(f->dc_state), flags, tsam<<1, dramAlign, outp); + n_aADPCMdec(ptr++, K0_TO_PHYS(f->dc_state), flags, tsam << 1, dramAlign, outp); #endif - f->dc_first = 0; - return ptr; + f->dc_first = 0; + return ptr; } diff --git a/src/libnaudio/n_mainbus.c b/src/libnaudio/n_mainbus.c index 9bdcfb34..30e5d859 100644 --- a/src/libnaudio/n_mainbus.c +++ b/src/libnaudio/n_mainbus.c @@ -28,49 +28,47 @@ extern u32 D_800FD6F0; extern u8* D_800FCF28[]; extern u32 D_800FCF30[]; -Acmd *n_alMainBusPull(s32 sampleOffset, Acmd *p) -{ - Acmd *ptr = p; +Acmd* n_alMainBusPull(s32 sampleOffset, Acmd* p) { + Acmd* ptr = p; s32 i; - aClearBuffer(ptr++, N_AL_MAIN_L_OUT, N_AL_DIVIDED<<1); + aClearBuffer(ptr++, N_AL_MAIN_L_OUT, N_AL_DIVIDED << 1); - ptr = (n_syn->mainBus->filter.handler)(sampleOffset,ptr); + ptr = (n_syn->mainBus->filter.handler)(sampleOffset, ptr); - aMix(ptr++, 0, 0x7fff, N_AL_AUX_L_OUT, N_AL_MAIN_L_OUT); - aMix(ptr++, 0, 0x7fff, N_AL_AUX_R_OUT, N_AL_MAIN_R_OUT); + aMix(ptr++, 0, 0x7fff, N_AL_AUX_L_OUT, N_AL_MAIN_L_OUT); + aMix(ptr++, 0, 0x7fff, N_AL_AUX_R_OUT, N_AL_MAIN_R_OUT); - // theres more code after? - if (D_800FC824 != 0) { - aClearBuffer(ptr++, 0x7C0, 0x2E0); - n_aLoadBuffer(ptr++, 0x170, 0x7C0, osVirtualToPhysical(&D_800FC6D8[D_800FD6F0 * 2])); - n_aLoadBuffer(ptr++, 0x170, 0x930, osVirtualToPhysical(&D_800FC6D8[D_800FD6F0 * 2])); + // theres more code after? + if (D_800FC824 != 0) { + aClearBuffer(ptr++, 0x7C0, 0x2E0); + n_aLoadBuffer(ptr++, 0x170, 0x7C0, osVirtualToPhysical(&D_800FC6D8[D_800FD6F0 * 2])); + n_aLoadBuffer(ptr++, 0x170, 0x930, osVirtualToPhysical(&D_800FC6D8[D_800FD6F0 * 2])); - D_800FD6F0 += 0xB8; + D_800FD6F0 += 0xB8; if (D_800FD6F0 >= 0xB80) { D_800FD6F0 = 0; } - aMix(ptr++, 0, 0x7fff, N_AL_AUX_L_OUT, N_AL_MAIN_L_OUT); - aMix(ptr++, 0, 0x7fff, N_AL_AUX_R_OUT, N_AL_MAIN_R_OUT); - aClearBuffer(ptr++, 0x7C0, 0x2E0); - } + aMix(ptr++, 0, 0x7fff, N_AL_AUX_L_OUT, N_AL_MAIN_L_OUT); + aMix(ptr++, 0, 0x7fff, N_AL_AUX_R_OUT, N_AL_MAIN_R_OUT); + aClearBuffer(ptr++, 0x7C0, 0x2E0); + } + + if (D_80077D98 != 0) { + for (i = 0; i < 2; i++) { + aClearBuffer(ptr++, 0x7C0, 0x2E0); + n_aLoadBuffer(ptr++, 0x170, 0x7C0, osVirtualToPhysical(&D_800FCF28[i][D_800FCF30[i] * 2])); + n_aLoadBuffer(ptr++, 0x170, 0x930, osVirtualToPhysical(&D_800FCF28[i][D_800FCF30[i] * 2])); - if (D_80077D98 != 0) { - for (i = 0; i < 2; i++) { - aClearBuffer(ptr++, 0x7C0, 0x2E0); - n_aLoadBuffer(ptr++, 0x170, 0x7C0, osVirtualToPhysical(&D_800FCF28[i][D_800FCF30[i] * 2])); - n_aLoadBuffer(ptr++, 0x170, 0x930, osVirtualToPhysical(&D_800FCF28[i][D_800FCF30[i] * 2])); + D_800FCF30[i] += 0xB8; + if (D_800FCF30[i] >= 0x8A0) { + D_800FCF30[i] = 0; + } - D_800FCF30[i] += 0xB8; - if (D_800FCF30[i] >= 0x8A0) { - D_800FCF30[i] = 0; + aMix(ptr++, 0, 0x7fff, N_AL_AUX_L_OUT, N_AL_MAIN_L_OUT); + aMix(ptr++, 0, 0x7fff, N_AL_AUX_R_OUT, N_AL_MAIN_R_OUT); } - - aMix(ptr++, 0, 0x7fff, N_AL_AUX_L_OUT, N_AL_MAIN_L_OUT); - aMix(ptr++, 0, 0x7fff, N_AL_AUX_R_OUT, N_AL_MAIN_R_OUT); } - } - - return ptr; -} + return ptr; +} diff --git a/src/libnaudio/n_resample.c b/src/libnaudio/n_resample.c index f7f40585..3323e802 100644 --- a/src/libnaudio/n_resample.c +++ b/src/libnaudio/n_resample.c @@ -29,14 +29,13 @@ extern u32 cnt_index, resampler_num, resampler_cnt, resampler_max, resampler_min /*********************************************************************** * Resampler filter public interfaces ***********************************************************************/ -Acmd *n_alResamplePull(N_PVoice *e, s16 *outp, Acmd *p) -{ - Acmd *ptr = p; - s16 inp; - s32 inCount; - s32 incr; - f32 finCount; - +Acmd* n_alResamplePull(N_PVoice* e, s16* outp, Acmd* p) { + Acmd* ptr = p; + s16 inp; + s32 inCount; + s32 incr; + f32 finCount; + #ifdef AUD_PROFILE lastCnt[++cnt_index] = osGetCount(); #endif @@ -46,69 +45,69 @@ Acmd *n_alResamplePull(N_PVoice *e, s16 *outp, Acmd *p) #else inp = N_AL_DECODER_OUT; #endif - + /* * check if resampler is required */ if (e->rs_upitch) { - ptr = n_alAdpcmPull(e, &inp, FIXED_SAMPLE, p); - aDMEMMove(ptr++, inp, *outp , FIXED_SAMPLE<<1); + ptr = n_alAdpcmPull(e, &inp, FIXED_SAMPLE, p); + aDMEMMove(ptr++, inp, *outp, FIXED_SAMPLE << 1); } else { - /* - * clip to maximum allowable pitch - * FIXME: should we check for some minimum as well? - */ - if (e->rs_ratio > MAX_RATIO) e->rs_ratio = MAX_RATIO; - - /* - * quantize the pitch - */ - e->rs_ratio = (s32)(e->rs_ratio * UNITY_PITCH); - e->rs_ratio = e->rs_ratio / UNITY_PITCH; - - /* - * determine how many samples to generate - */ - finCount = e->rs_delta + (e->rs_ratio * (f32)FIXED_SAMPLE); - inCount = (s32) finCount; - e->rs_delta = finCount - (f32)inCount; - - /* - * ask all filters upstream from us to build their command - * lists. - */ - ptr = n_alAdpcmPull(e, &inp,inCount, p); - - /* - * construct our portion of the command list - */ - incr = (s32)(e->rs_ratio * UNITY_PITCH); + /* + * clip to maximum allowable pitch + * FIXME: should we check for some minimum as well? + */ + if (e->rs_ratio > MAX_RATIO) + e->rs_ratio = MAX_RATIO; + + /* + * quantize the pitch + */ + e->rs_ratio = (s32)(e->rs_ratio * UNITY_PITCH); + e->rs_ratio = e->rs_ratio / UNITY_PITCH; + + /* + * determine how many samples to generate + */ + finCount = e->rs_delta + (e->rs_ratio * (f32)FIXED_SAMPLE); + inCount = (s32)finCount; + e->rs_delta = finCount - (f32)inCount; + + /* + * ask all filters upstream from us to build their command + * lists. + */ + ptr = n_alAdpcmPull(e, &inp, inCount, p); + + /* + * construct our portion of the command list + */ + incr = (s32)(e->rs_ratio * UNITY_PITCH); #ifndef N_MICRO - aSetBuffer(ptr++, 0, inp , *outp, FIXED_SAMPLE<<1); - aResample(ptr++, e->rs_first, incr, osVirtualToPhysical(e->rs_state)); + aSetBuffer(ptr++, 0, inp, *outp, FIXED_SAMPLE << 1); + aResample(ptr++, e->rs_first, incr, osVirtualToPhysical(e->rs_state)); #else - n_aResample(ptr++, osVirtualToPhysical(e->rs_state), e->rs_first, incr, inp, 0); + n_aResample(ptr++, osVirtualToPhysical(e->rs_state), e->rs_first, incr, inp, 0); #endif - e->rs_first = 0; + e->rs_first = 0; } - + #ifdef AUD_PROFILE PROFILE_AUD(resampler_num, resampler_cnt, resampler_max, resampler_min); #endif return ptr; } -s32 n_alResampleParam(N_PVoice *filter, s32 paramID, void *param) -{ - N_PVoice *r = filter; +s32 n_alResampleParam(N_PVoice* filter, s32 paramID, void* param) { + N_PVoice* r = filter; union { - f32 f; - s32 i; + f32 f; + s32 i; } data; - + switch (paramID) { #if 0 case (AL_FILTER_RESET): @@ -127,11 +126,10 @@ s32 n_alResampleParam(N_PVoice *filter, s32 paramID, void *param) case (AL_FILTER_SET_UNITY_PITCH): r->rs_upitch = 1; break; -#endif +#endif default: - n_alLoadParam(filter, paramID, param); + n_alLoadParam(filter, paramID, param); break; } return 0; } - diff --git a/src/libnaudio/n_reverb.c b/src/libnaudio/n_reverb.c index 4484b4a5..0f653fc7 100644 --- a/src/libnaudio/n_reverb.c +++ b/src/libnaudio/n_reverb.c @@ -33,261 +33,255 @@ extern u32 load_num, load_cnt, load_max, load_min, save_num, save_cnt, save_max, /* * macros */ -#define SWAP(in, out) \ -{ \ - s16 t = out; \ - out = in; \ - in = t; \ - } - -Acmd *_n_loadOutputBuffer(ALFx *r, ALDelay *d, s32 buff, Acmd *p); -Acmd *_n_loadBuffer(ALFx *r, s16 *curr_ptr, s32 buff, s32 count, Acmd *p); -Acmd *_n_saveBuffer(ALFx *r, s16 *curr_ptr, s32 buff, Acmd *p); -Acmd *_n_filterBuffer(ALLowPass *lp, s32 buff, Acmd *p); - -extern f32 _doModFunc(ALDelay *d, s32 count); +#define SWAP(in, out) \ + { \ + s16 t = out; \ + out = in; \ + in = t; \ + } + +Acmd* _n_loadOutputBuffer(ALFx* r, ALDelay* d, s32 buff, Acmd* p); +Acmd* _n_loadBuffer(ALFx* r, s16* curr_ptr, s32 buff, s32 count, Acmd* p); +Acmd* _n_saveBuffer(ALFx* r, s16* curr_ptr, s32 buff, Acmd* p); +Acmd* _n_filterBuffer(ALLowPass* lp, s32 buff, Acmd* p); + +extern f32 _doModFunc(ALDelay* d, s32 count); extern s32 L_INC[]; /*********************************************************************** * Reverb filter public interfaces ***********************************************************************/ -Acmd *n_alFxPull(s32 sampleOffset, Acmd *p) -{ - Acmd *ptr = p; - ALFx *r = (ALFx *)n_syn->auxBus->fx; - s16 i, buff1, buff2, input, output; - s16 *in_ptr, *out_ptr, gain, *prev_out_ptr = 0; - ALDelay *d, *pd; - +Acmd* n_alFxPull(s32 sampleOffset, Acmd* p) { + Acmd* ptr = p; + ALFx* r = (ALFx*)n_syn->auxBus->fx; + s16 i, buff1, buff2, input, output; + s16 *in_ptr, *out_ptr, gain, *prev_out_ptr = 0; + ALDelay *d, *pd; + #ifdef AUD_PROFILE - lastCnt[++cnt_index] = osGetCount(); + lastCnt[++cnt_index] = osGetCount(); #endif - - /* - * pull channels going into this effect first - */ - ptr = n_alAuxBusPull(sampleOffset, p); - + + /* + * pull channels going into this effect first + */ + ptr = n_alAuxBusPull(sampleOffset, p); + #ifndef N_MICRO - input = AL_AUX_L_OUT; - output = AL_AUX_R_OUT; - buff1 = AL_TEMP_0; - buff2 = AL_TEMP_1; + input = AL_AUX_L_OUT; + output = AL_AUX_R_OUT; + buff1 = AL_TEMP_0; + buff2 = AL_TEMP_1; #else - input = N_AL_AUX_L_OUT; - output = N_AL_AUX_R_OUT; - buff1 = N_AL_TEMP_0; - buff2 = N_AL_TEMP_1; + input = N_AL_AUX_L_OUT; + output = N_AL_AUX_R_OUT; + buff1 = N_AL_TEMP_0; + buff2 = N_AL_TEMP_1; #endif - + #ifndef N_MICRO - aSetBuffer(ptr++, 0, 0, 0, FIXED_SAMPLE<<1); /* set the buffer size */ - aMix(ptr++, 0, 0xda83, AL_AUX_L_OUT, input); /* .707L = L - .293L */ - aMix(ptr++, 0, 0x5a82, AL_AUX_R_OUT, input); /* mix the AuxL and AuxR into the AuxL */ + aSetBuffer(ptr++, 0, 0, 0, FIXED_SAMPLE << 1); /* set the buffer size */ + aMix(ptr++, 0, 0xda83, AL_AUX_L_OUT, input); /* .707L = L - .293L */ + aMix(ptr++, 0, 0x5a82, AL_AUX_R_OUT, input); /* mix the AuxL and AuxR into the AuxL */ #else - aMix(ptr++, 0, 0xda83, N_AL_AUX_L_OUT, input); - aMix(ptr++, 0, 0x5a82, N_AL_AUX_R_OUT, input); + aMix(ptr++, 0, 0xda83, N_AL_AUX_L_OUT, input); + aMix(ptr++, 0, 0x5a82, N_AL_AUX_R_OUT, input); #endif - /* and write the mixed value to the delay line at r->input */ - ptr = _n_saveBuffer(r, r->input, input, ptr); - - aClearBuffer(ptr++, output, FIXED_SAMPLE<<1); /* clear the AL_AUX_R_OUT */ - - for (i = 0; i < r->section_count; i++) { - d = &r->delay[i]; /* get the ALDelay structure */ - in_ptr = &r->input[-d->input]; - out_ptr = &r->input[-d->output]; - - if (in_ptr == prev_out_ptr) { - SWAP(buff1, buff2); - } else { /* load data at in_ptr into buff1 */ - ptr = _n_loadBuffer(r, in_ptr, buff1, FIXED_SAMPLE, ptr); - } - ptr = _n_loadOutputBuffer(r, d, buff2, ptr); - - if (d->ffcoef) { - aMix(ptr++, 0, (u16)d->ffcoef, buff1, buff2); - if (!d->rs && !d->lp) { - ptr = _n_saveBuffer(r, out_ptr, buff2, ptr); - } + /* and write the mixed value to the delay line at r->input */ + ptr = _n_saveBuffer(r, r->input, input, ptr); + + aClearBuffer(ptr++, output, FIXED_SAMPLE << 1); /* clear the AL_AUX_R_OUT */ + + for (i = 0; i < r->section_count; i++) { + d = &r->delay[i]; /* get the ALDelay structure */ + in_ptr = &r->input[-d->input]; + out_ptr = &r->input[-d->output]; + + if (in_ptr == prev_out_ptr) { + SWAP(buff1, buff2); + } else { /* load data at in_ptr into buff1 */ + ptr = _n_loadBuffer(r, in_ptr, buff1, FIXED_SAMPLE, ptr); + } + ptr = _n_loadOutputBuffer(r, d, buff2, ptr); + + if (d->ffcoef) { + aMix(ptr++, 0, (u16)d->ffcoef, buff1, buff2); + if (!d->rs && !d->lp) { + ptr = _n_saveBuffer(r, out_ptr, buff2, ptr); + } + } + + if (d->fbcoef) { + aMix(ptr++, 0, (u16)d->fbcoef, buff2, buff1); + ptr = _n_saveBuffer(r, in_ptr, buff1, ptr); + } + + if (d->lp) + ptr = _n_filterBuffer(d->lp, buff2, ptr); + + if (!d->rs) + ptr = _n_saveBuffer(r, out_ptr, buff2, ptr); + + if (d->gain) + aMix(ptr++, 0, (u16)d->gain, buff2, output); + + prev_out_ptr = &r->input[d->output]; } - - if (d->fbcoef) { - aMix(ptr++, 0, (u16)d->fbcoef, buff2, buff1); - ptr = _n_saveBuffer(r, in_ptr, buff1, ptr); + + /* + * bump the master delay line input pointer + * modulo the length + */ + r->input += FIXED_SAMPLE; + if (r->input > &r->base[r->length]) { + r->input -= r->length; } - - if (d->lp) - ptr = _n_filterBuffer(d->lp, buff2, ptr); - - if (!d->rs) - ptr = _n_saveBuffer(r, out_ptr, buff2, ptr); - - if (d->gain) - aMix(ptr++, 0, (u16)d->gain, buff2, output); - - prev_out_ptr = &r->input[d->output]; - } - - /* - * bump the master delay line input pointer - * modulo the length - */ - r->input += FIXED_SAMPLE; - if (r->input > &r->base[r->length]) - r->input -= r->length; - - /* - * output already in AL_AUX_R_OUT - * just copy to AL_AUX_L_OUT - */ + + /* + * output already in AL_AUX_R_OUT + * just copy to AL_AUX_L_OUT + */ #ifndef N_MICRO - aDMEMMove(ptr++, output, AL_AUX_L_OUT, FIXED_SAMPLE<<1); + aDMEMMove(ptr++, output, AL_AUX_L_OUT, FIXED_SAMPLE << 1); #else - aDMEMMove(ptr++, output, N_AL_AUX_L_OUT, FIXED_SAMPLE<<1); + aDMEMMove(ptr++, output, N_AL_AUX_L_OUT, FIXED_SAMPLE << 1); #endif - + #ifdef AUD_PROFILE - PROFILE_AUD(reverb_num, reverb_cnt, reverb_max, reverb_min); + PROFILE_AUD(reverb_num, reverb_cnt, reverb_max, reverb_min); #endif - return ptr; + return ptr; } /* - * This routine gets called by alSynSetFXParam. No checking takes place to - * verify the validity of the paramID or the param value. input and output - * values must be 8 byte aligned, so round down any param passed. + * This routine gets called by alSynSetFXParam. No checking takes place to + * verify the validity of the paramID or the param value. input and output + * values must be 8 byte aligned, so round down any param passed. */ -s32 n_alFxParamHdl(void *filter, s32 paramID, void *param) -{ - ALFx *f = (ALFx *) filter; - s32 p = (paramID - 2) % 8; - s32 s = (paramID - 2) / 8; - s32 val = *(s32*)param; - -#define INPUT_PARAM 0 -#define OUTPUT_PARAM 1 -#define FBCOEF_PARAM 2 -#define FFCOEF_PARAM 3 -#define GAIN_PARAM 4 -#define CHORUSRATE_PARAM 5 -#define CHORUSDEPTH_PARAM 6 -#define LPFILT_PARAM 7 - - switch(p) - { - case INPUT_PARAM: - f->delay[s].input = (u32)val & 0xFFFFFFF8; - break; - case OUTPUT_PARAM: - f->delay[s].output = (u32)val & 0xFFFFFFF8; - break; - case FFCOEF_PARAM: - f->delay[s].ffcoef = (s16)val; - break; - case FBCOEF_PARAM: - f->delay[s].fbcoef = (s16)val; - break; - case GAIN_PARAM: - f->delay[s].gain = (s16)val; - break; - case CHORUSRATE_PARAM: - /* f->delay[s].rsinc = ((f32)val)/0xffffff; */ - f->delay[s].rsinc - = ((((f32)val)/1000) * RANGE)/n_syn->outputRate; - break; - - /* - * the following constant is derived from: - * - * ratio = 2^(cents/1200) - * - * and therefore for hundredths of a cent - * x - * ln(ratio) = --------------- - * (120,000)/ln(2) - * where - * 120,000/ln(2) = 173123.40... - */ +s32 n_alFxParamHdl(void* filter, s32 paramID, void* param) { + ALFx* f = (ALFx*)filter; + s32 p = (paramID - 2) % 8; + s32 s = (paramID - 2) / 8; + s32 val = *(s32*)param; + +#define INPUT_PARAM 0 +#define OUTPUT_PARAM 1 +#define FBCOEF_PARAM 2 +#define FFCOEF_PARAM 3 +#define GAIN_PARAM 4 +#define CHORUSRATE_PARAM 5 +#define CHORUSDEPTH_PARAM 6 +#define LPFILT_PARAM 7 + + switch (p) { + case INPUT_PARAM: + f->delay[s].input = (u32)val & 0xFFFFFFF8; + break; + case OUTPUT_PARAM: + f->delay[s].output = (u32)val & 0xFFFFFFF8; + break; + case FFCOEF_PARAM: + f->delay[s].ffcoef = (s16)val; + break; + case FBCOEF_PARAM: + f->delay[s].fbcoef = (s16)val; + break; + case GAIN_PARAM: + f->delay[s].gain = (s16)val; + break; + case CHORUSRATE_PARAM: + /* f->delay[s].rsinc = ((f32)val)/0xffffff; */ + f->delay[s].rsinc = ((((f32)val) / 1000) * RANGE) / n_syn->outputRate; + break; + + /* + * the following constant is derived from: + * + * ratio = 2^(cents/1200) + * + * and therefore for hundredths of a cent + * x + * ln(ratio) = --------------- + * (120,000)/ln(2) + * where + * 120,000/ln(2) = 173123.40... + */ #define CONVERT 173123.404906676 -#define LENGTH (f->delay[s].output - f->delay[s].input) - - case CHORUSDEPTH_PARAM: - /*f->delay[s].rsgain = (((f32)val) / CONVERT) * LENGTH; */ - f->delay[s].rsgain = (((f32)val) / CONVERT) * LENGTH; - break; - case LPFILT_PARAM: - if(f->delay[s].lp) - { - f->delay[s].lp->fc = (s16)val; +#define LENGTH (f->delay[s].output - f->delay[s].input) + + case CHORUSDEPTH_PARAM: + /*f->delay[s].rsgain = (((f32)val) / CONVERT) * LENGTH; */ + f->delay[s].rsgain = (((f32)val) / CONVERT) * LENGTH; + break; + case LPFILT_PARAM: + if (f->delay[s].lp) { + f->delay[s].lp->fc = (s16)val; #ifdef _OLD_AUDIO_LIBRARY - init_lpfilter(f->delay[s].lp); + init_lpfilter(f->delay[s].lp); #else - _init_lpfilter(f->delay[s].lp); + _init_lpfilter(f->delay[s].lp); #endif - } - break; + } + break; } - return 0; + return 0; } -Acmd *_n_loadOutputBuffer(ALFx *r, ALDelay *d, s32 buff, Acmd *p) -{ - Acmd *ptr = p; +Acmd* _n_loadOutputBuffer(ALFx* r, ALDelay* d, s32 buff, Acmd* p) { + Acmd* ptr = p; #ifndef N_MICRO - s32 ratio, count, rbuff = AL_TEMP_2; + s32 ratio, count, rbuff = AL_TEMP_2; #else - s32 ratio, count, rbuff = N_AL_TEMP_2; + s32 ratio, count, rbuff = N_AL_TEMP_2; #endif - s16 *out_ptr; - f32 fincount, fratio, delta; - s32 ramalign = 0, length; - static f32 val=0.0, lastval=-10.0; - static f32 blob=0; - s32 incount = FIXED_SAMPLE; - - if (d->rs) { - length = d->output - d->input; - delta = _doModFunc(d, incount); - delta /= length; - delta = (s32)(delta * UNITY_PITCH); - delta = delta / UNITY_PITCH; - fratio = 1.0 - delta; - fincount = d->rs->delta + (fratio * (f32)incount); - count = (s32) fincount; - d->rs->delta = fincount - (f32)count; - out_ptr = &r->input[-(d->output - d->rsdelta)]; - ramalign = ((s32)out_ptr & 0x7) >> 1; - ptr = _n_loadBuffer(r, out_ptr - ramalign, rbuff, count + ramalign, ptr); - - ratio = (s32)(fratio * UNITY_PITCH); + s16* out_ptr; + f32 fincount, fratio, delta; + s32 ramalign = 0, length; + static f32 val = 0.0, lastval = -10.0; + static f32 blob = 0; + s32 incount = FIXED_SAMPLE; + + if (d->rs) { + length = d->output - d->input; + delta = _doModFunc(d, incount); + delta /= length; + delta = (s32)(delta * UNITY_PITCH); + delta = delta / UNITY_PITCH; + fratio = 1.0 - delta; + fincount = d->rs->delta + (fratio * (f32)incount); + count = (s32)fincount; + d->rs->delta = fincount - (f32)count; + out_ptr = &r->input[-(d->output - d->rsdelta)]; + ramalign = ((s32)out_ptr & 0x7) >> 1; + ptr = _n_loadBuffer(r, out_ptr - ramalign, rbuff, count + ramalign, ptr); + + ratio = (s32)(fratio * UNITY_PITCH); #ifndef N_MICRO - aSetBuffer(ptr++, 0, rbuff + (ramalign<<1), buff, incount<<1); - aResample(ptr++, d->rs->first, ratio, osVirtualToPhysical(d->rs->state)); + aSetBuffer(ptr++, 0, rbuff + (ramalign << 1), buff, incount << 1); + aResample(ptr++, d->rs->first, ratio, osVirtualToPhysical(d->rs->state)); #else - { - s16 tmp; + { + s16 tmp; - tmp = buff >> 8; - n_aResample(ptr++, osVirtualToPhysical(d->rs->state), d->rs->first, ratio, rbuff + (ramalign<<1), tmp); - } -#endif - d->rs->first = 0; - d->rsdelta += count - incount; - } else { - out_ptr = &r->input[-d->output]; - ptr = _n_loadBuffer(r, out_ptr, buff, FIXED_SAMPLE, ptr); - } - - return ptr; + tmp = buff >> 8; + n_aResample(ptr++, osVirtualToPhysical(d->rs->state), d->rs->first, ratio, rbuff + (ramalign << 1), tmp); + } +#endif + d->rs->first = 0; + d->rsdelta += count - incount; + } else { + out_ptr = &r->input[-d->output]; + ptr = _n_loadBuffer(r, out_ptr, buff, FIXED_SAMPLE, ptr); + } + + return ptr; } -Acmd *_n_loadBuffer(ALFx *r, s16 *curr_ptr, s32 buff,s32 count, Acmd *p) -{ - Acmd *ptr = p; - s32 after_end, before_end; - s16 *updated_ptr, *delay_end; +Acmd* _n_loadBuffer(ALFx* r, s16* curr_ptr, s32 buff, s32 count, Acmd* p) { + Acmd* ptr = p; + s32 after_end, before_end; + s16 *updated_ptr, *delay_end; #ifdef AUD_PROFILE lastCnt[++cnt_index] = osGetCount(); @@ -296,35 +290,35 @@ Acmd *_n_loadBuffer(ALFx *r, s16 *curr_ptr, s32 buff,s32 count, Acmd *p) delay_end = &r->base[r->length]; #ifdef _DEBUG - if(curr_ptr > delay_end) + if (curr_ptr > delay_end) __osError(ERR_ALMODDELAYOVERFLOW, 1, delay_end - curr_ptr); #endif if (curr_ptr < r->base) - curr_ptr += r->length; + curr_ptr += r->length; updated_ptr = curr_ptr + count; - + if (updated_ptr > delay_end) { after_end = updated_ptr - delay_end; before_end = delay_end - curr_ptr; - + #ifndef N_MICRO - aSetBuffer(ptr++, 0, buff, 0, before_end<<1); + aSetBuffer(ptr++, 0, buff, 0, before_end << 1); aLoadBuffer(ptr++, osVirtualToPhysical(curr_ptr)); - aSetBuffer(ptr++, 0, buff+(before_end<<1), 0, after_end<<1); + aSetBuffer(ptr++, 0, buff + (before_end << 1), 0, after_end << 1); aLoadBuffer(ptr++, osVirtualToPhysical(r->base)); } else { - aSetBuffer(ptr++, 0, buff, 0, count<<1); + aSetBuffer(ptr++, 0, buff, 0, count << 1); aLoadBuffer(ptr++, osVirtualToPhysical(curr_ptr)); } - aSetBuffer(ptr++, 0, 0, 0, count<<1); + aSetBuffer(ptr++, 0, 0, 0, count << 1); #else - n_aLoadBuffer(ptr++, before_end<<1, buff, osVirtualToPhysical(curr_ptr)); - n_aLoadBuffer(ptr++, after_end<<1, buff+(before_end<<1), osVirtualToPhysical(r->base)); - } else { - n_aLoadBuffer(ptr++, count<<1, buff, osVirtualToPhysical(curr_ptr)); - } + n_aLoadBuffer(ptr++, before_end << 1, buff, osVirtualToPhysical(curr_ptr)); + n_aLoadBuffer(ptr++, after_end << 1, buff + (before_end << 1), osVirtualToPhysical(r->base)); + } else { + n_aLoadBuffer(ptr++, count << 1, buff, osVirtualToPhysical(curr_ptr)); + } #endif #ifdef AUD_PROFILE @@ -333,18 +327,17 @@ Acmd *_n_loadBuffer(ALFx *r, s16 *curr_ptr, s32 buff,s32 count, Acmd *p) return ptr; } -Acmd *_n_saveBuffer(ALFx *r, s16 *curr_ptr, s32 buff, Acmd *p) -{ - Acmd *ptr = p; - s32 after_end, before_end; - s16 *updated_ptr, *delay_end; +Acmd* _n_saveBuffer(ALFx* r, s16* curr_ptr, s32 buff, Acmd* p) { + Acmd* ptr = p; + s32 after_end, before_end; + s16 *updated_ptr, *delay_end; #ifdef AUD_PROFILE lastCnt[++cnt_index] = osGetCount(); #endif delay_end = &r->base[r->length]; - if (curr_ptr < r->base) /* probably just security */ - curr_ptr += r->length; /* shouldn't occur */ + if (curr_ptr < r->base) /* probably just security */ + curr_ptr += r->length; /* shouldn't occur */ updated_ptr = curr_ptr + FIXED_SAMPLE; if (updated_ptr > delay_end) { /* if the data wraps past end of r->base */ @@ -352,44 +345,42 @@ Acmd *_n_saveBuffer(ALFx *r, s16 *curr_ptr, s32 buff, Acmd *p) before_end = delay_end - curr_ptr; #ifndef N_MICRO - aSetBuffer(ptr++, 0, 0, buff, before_end<<1); + aSetBuffer(ptr++, 0, 0, buff, before_end << 1); aSaveBuffer(ptr++, osVirtualToPhysical(curr_ptr)); - aSetBuffer(ptr++, 0, 0, buff+(before_end<<1), after_end<<1); + aSetBuffer(ptr++, 0, 0, buff + (before_end << 1), after_end << 1); aSaveBuffer(ptr++, osVirtualToPhysical(r->base)); - aSetBuffer(ptr++, 0, 0, 0, FIXED_SAMPLE<<1); + aSetBuffer(ptr++, 0, 0, 0, FIXED_SAMPLE << 1); } else { - aSetBuffer(ptr++, 0, 0, buff, FIXED_SAMPLE<<1); + aSetBuffer(ptr++, 0, 0, buff, FIXED_SAMPLE << 1); aSaveBuffer(ptr++, osVirtualToPhysical(curr_ptr)); } #else - n_aSaveBuffer(ptr++, before_end<<1, buff, osVirtualToPhysical(curr_ptr)); - n_aSaveBuffer(ptr++, after_end<<1, buff+(before_end<<1), osVirtualToPhysical(r->base)); - } else { - n_aSaveBuffer(ptr++, FIXED_SAMPLE<<1, buff, osVirtualToPhysical(curr_ptr)); - } + n_aSaveBuffer(ptr++, before_end << 1, buff, osVirtualToPhysical(curr_ptr)); + n_aSaveBuffer(ptr++, after_end << 1, buff + (before_end << 1), osVirtualToPhysical(r->base)); + } else { + n_aSaveBuffer(ptr++, FIXED_SAMPLE << 1, buff, osVirtualToPhysical(curr_ptr)); + } #endif #ifdef AUD_PROFILE PROFILE_AUD(save_num, save_cnt, save_max, save_min); #endif return ptr; - } -Acmd *_n_filterBuffer(ALLowPass *lp, s32 buff, Acmd *p) -{ - Acmd *ptr = p; +Acmd* _n_filterBuffer(ALLowPass* lp, s32 buff, Acmd* p) { + Acmd* ptr = p; #ifndef N_MICRO - aSetBuffer(ptr++, 0, buff, buff, FIXED_SAMPLE<<1); + aSetBuffer(ptr++, 0, buff, buff, FIXED_SAMPLE << 1); aLoadADPCM(ptr++, 32, osVirtualToPhysical(lp->fcvec.fccoef)); aPoleFilter(ptr++, lp->first, lp->fgain, osVirtualToPhysical(lp->fstate)); #else { - s16 tmp; + s16 tmp; - tmp = buff >> 8; - n_aLoadADPCM(ptr++, 32, osVirtualToPhysical(lp->fcvec.fccoef)); - n_aPoleFilter(ptr++, lp->first, lp->fgain, tmp, osVirtualToPhysical(lp->fstate)); + tmp = buff >> 8; + n_aLoadADPCM(ptr++, 32, osVirtualToPhysical(lp->fcvec.fccoef)); + n_aPoleFilter(ptr++, lp->first, lp->fgain, tmp, osVirtualToPhysical(lp->fstate)); } #endif @@ -397,5 +388,3 @@ Acmd *_n_filterBuffer(ALLowPass *lp, s32 buff, Acmd *p) return ptr; } - - diff --git a/src/libnaudio/n_save.c b/src/libnaudio/n_save.c index bc0ebd9a..41f2493c 100644 --- a/src/libnaudio/n_save.c +++ b/src/libnaudio/n_save.c @@ -21,22 +21,21 @@ #include -Acmd *n_alSavePull(s32 sampleOffset, Acmd *p) -{ - Acmd *ptr = p; +Acmd* n_alSavePull(s32 sampleOffset, Acmd* p) { + Acmd* ptr = p; ptr = n_alMainBusPull(sampleOffset, ptr); - + #ifndef N_MICRO - aSetBuffer (ptr++, 0, 0, 0, FIXED_SAMPLE<<1); + aSetBuffer(ptr++, 0, 0, 0, FIXED_SAMPLE << 1); aInterleave(ptr++, AL_MAIN_L_OUT, AL_MAIN_R_OUT); - aSetBuffer (ptr++, 0, 0, 0, FIXED_SAMPLE<<2); + aSetBuffer(ptr++, 0, 0, 0, FIXED_SAMPLE << 2); aSaveBuffer(ptr++, n_syn->sv_dramout); #else - n_aInterleave(ptr++); n_aSaveBuffer(ptr++, FIXED_SAMPLE<<2, 0, n_syn->sv_dramout); + // clang-format off + n_aInterleave(ptr++); \ + n_aSaveBuffer(ptr++, FIXED_SAMPLE << 2, 0, n_syn->sv_dramout); + // clang-format on #endif return ptr; } - - - diff --git a/src/libnaudio/n_sl.c b/src/libnaudio/n_sl.c index d9fe8e1d..a16e2e7e 100644 --- a/src/libnaudio/n_sl.c +++ b/src/libnaudio/n_sl.c @@ -19,25 +19,23 @@ #include "n_synthInternals.h" -N_ALGlobals *n_alGlobals = 0; -N_ALSynth *n_syn = 0; +N_ALGlobals* n_alGlobals = 0; +N_ALSynth* n_syn = 0; -void n_alInit(N_ALGlobals *g, ALSynConfig *c) -{ +void n_alInit(N_ALGlobals* g, ALSynConfig* c) { if (!n_alGlobals) { /* already initialized? */ - n_alGlobals = g; - if(!n_syn) { - n_syn = &n_alGlobals -> drvr; - n_alSynNew(c); - } + n_alGlobals = g; + if (!n_syn) { + n_syn = &n_alGlobals->drvr; + n_alSynNew(c); + } } } -void n_alClose(void) -{ +void n_alClose(void) { if (n_alGlobals) { n_alSynDelete(); n_alGlobals = 0; - n_syn = 0; + n_syn = 0; } } diff --git a/src/libnaudio/n_synaddplayer.c b/src/libnaudio/n_synaddplayer.c index a4203d24..86890a33 100644 --- a/src/libnaudio/n_synaddplayer.c +++ b/src/libnaudio/n_synaddplayer.c @@ -19,15 +19,12 @@ #include #include "n_synthInternals.h" - -void n_alSynAddPlayer(ALPlayer *client) -{ +void n_alSynAddPlayer(ALPlayer* client) { OSIntMask mask = osSetIntMask(OS_IM_NONE); client->samplesLeft = n_syn->curSamples; client->next = n_syn->head; - n_syn->head = client; + n_syn->head = client; osSetIntMask(mask); } - diff --git a/src/libnaudio/n_synallocfx.c b/src/libnaudio/n_synallocfx.c index ee4d73c5..bfe666e2 100644 --- a/src/libnaudio/n_synallocfx.c +++ b/src/libnaudio/n_synallocfx.c @@ -18,8 +18,7 @@ *====================================================================*/ #include "n_synthInternals.h" -ALFxRef n_alSynAllocFX(s16 bus, ALSynConfig *c, ALHeap *hp) -{ +ALFxRef n_alSynAllocFX(s16 bus, ALSynConfig* c, ALHeap* hp) { n_alFxNew(&n_syn->auxBus->fx_array[bus], c, hp); - return(n_syn->auxBus->fx_array[bus]); + return (n_syn->auxBus->fx_array[bus]); } diff --git a/src/libnaudio/n_synallocvoice.c b/src/libnaudio/n_synallocvoice.c index 2ce7c913..6412dce0 100644 --- a/src/libnaudio/n_synallocvoice.c +++ b/src/libnaudio/n_synallocvoice.c @@ -20,16 +20,14 @@ #include #include "n_synthInternals.h" +static s32 _allocatePVoice(N_PVoice** pvoice, s16 priority); -static s32 _allocatePVoice(N_PVoice **pvoice, s16 priority); - -s32 n_alSynAllocVoice(N_ALVoice *voice, ALVoiceConfig *vc) -{ - N_PVoice *pvoice = 0; - ALFilter *f; - ALParam *update; +s32 n_alSynAllocVoice(N_ALVoice* voice, ALVoiceConfig* vc) { + N_PVoice* pvoice = 0; + ALFilter* f; + ALParam* update; s32 stolen; - + #ifdef _DEBUG /* need two updates if voice is stolen */ if (n_syn->paramList == 0) { @@ -39,42 +37,42 @@ s32 n_alSynAllocVoice(N_ALVoice *voice, ALVoiceConfig *vc) __osError(ERR_ALSYN_NO_UPDATE, 0); return 0; } -#endif +#endif - voice->priority = vc->priority; - voice->unityPitch = vc->unityPitch; - voice->table = 0; - voice->fxBus = vc->fxBus; - voice->state = AL_STOPPED; - voice->pvoice = 0; + voice->priority = vc->priority; + voice->unityPitch = vc->unityPitch; + voice->table = 0; + voice->fxBus = vc->fxBus; + voice->state = AL_STOPPED; + voice->pvoice = 0; stolen = _allocatePVoice(&pvoice, vc->priority); - - if (pvoice) { /* if we were able to allocate a voice */ + + if (pvoice) { /* if we were able to allocate a voice */ if (stolen) { - + pvoice->offset = 552; pvoice->vvoice->pvoice = 0; /* zero stolen voice */ #if 1 - pvoice->vvoice = voice; - voice->pvoice = pvoice; + pvoice->vvoice = voice; + voice->pvoice = pvoice; #endif - + /* * ramp down stolen voice */ update = __n_allocParam(); #ifdef SAMPLE_ROUND - update->delta = SAMPLE184( n_syn->paramSamples ); + update->delta = SAMPLE184(n_syn->paramSamples); #else - update->delta = n_syn->paramSamples; + update->delta = n_syn->paramSamples; #endif - update->type = AL_FILTER_SET_VOLUME; - update->data.i = 0; + update->type = AL_FILTER_SET_VOLUME; + update->data.i = 0; update->moredata.i = 368; /* pvoice->offset - 184 */ - n_alEnvmixerParam(voice->pvoice, AL_FILTER_ADD_UPDATE, update); + n_alEnvmixerParam(voice->pvoice, AL_FILTER_ADD_UPDATE, update); /* * stop stolen voice @@ -82,16 +80,16 @@ s32 n_alSynAllocVoice(N_ALVoice *voice, ALVoiceConfig *vc) update = __n_allocParam(); if (update) { #ifdef SAMPLE_ROUND - update->delta = SAMPLE184( n_syn->paramSamples + pvoice->offset); + update->delta = SAMPLE184(n_syn->paramSamples + pvoice->offset); #else - update->delta = n_syn->paramSamples + pvoice->offset; + update->delta = n_syn->paramSamples + pvoice->offset; #endif - update->type = AL_FILTER_STOP_VOICE; - update->next = 0; - n_alEnvmixerParam(voice->pvoice, AL_FILTER_ADD_UPDATE, update); + update->type = AL_FILTER_STOP_VOICE; + update->next = 0; + n_alEnvmixerParam(voice->pvoice, AL_FILTER_ADD_UPDATE, update); } else { -#ifdef _DEBUG +#ifdef _DEBUG __osError(ERR_ALSYN_NO_UPDATE, 0); #endif } @@ -99,37 +97,35 @@ s32 n_alSynAllocVoice(N_ALVoice *voice, ALVoiceConfig *vc) } else { pvoice->offset = 0; #if 1 - pvoice->vvoice = voice; - voice->pvoice = pvoice; + pvoice->vvoice = voice; + voice->pvoice = pvoice; #endif - } #if 0 pvoice->vvoice = voice; /* assign new voice */ voice->pvoice = pvoice; #endif } - - return (pvoice != 0); + + return (pvoice != 0); } -s32 _allocatePVoice(N_PVoice **pvoice, s16 priority) -{ - ALLink *dl; - N_PVoice *pv; - s32 stolen = 0; - +s32 _allocatePVoice(N_PVoice** pvoice, s16 priority) { + ALLink* dl; + N_PVoice* pv; + s32 stolen = 0; + if ((dl = n_syn->pLameList.next) != 0) { /* check the lame list first */ - *pvoice = (N_PVoice *)dl; + *pvoice = (N_PVoice*)dl; alUnlink(dl); - alLink(dl, &n_syn->pAllocList); + alLink(dl, &n_syn->pAllocList); } else if ((dl = n_syn->pFreeList.next) != 0) { /* from the free list */ - *pvoice = (N_PVoice *) dl; + *pvoice = (N_PVoice*)dl; alUnlink(dl); - alLink(dl, &n_syn->pAllocList); + alLink(dl, &n_syn->pAllocList); } else { /* steal one */ for (dl = n_syn->pAllocList.next; dl != 0; dl = dl->next) { - pv = (N_PVoice *)dl; + pv = (N_PVoice*)dl; /* * if it is lower priority and not already stolen, keep it @@ -142,7 +138,6 @@ s32 _allocatePVoice(N_PVoice **pvoice, s16 priority) } } } - + return stolen; } - diff --git a/src/libnaudio/n_syndelete.c b/src/libnaudio/n_syndelete.c index 8d1f1ceb..9150ef4f 100644 --- a/src/libnaudio/n_syndelete.c +++ b/src/libnaudio/n_syndelete.c @@ -18,8 +18,6 @@ *====================================================================*/ #include "n_synthInternals.h" -void n_alSynDelete(void) -{ +void n_alSynDelete(void) { n_syn->head = 0; } - diff --git a/src/libnaudio/n_synfreevoice.c b/src/libnaudio/n_synfreevoice.c index 0445d13e..1df1c6a0 100644 --- a/src/libnaudio/n_synfreevoice.c +++ b/src/libnaudio/n_synfreevoice.c @@ -22,28 +22,27 @@ #include #include "n_synthInternals.h" -void n_alSynFreeVoice(N_ALVoice *voice) -{ - ALFilter *f; - N_ALFreeParam *update; +void n_alSynFreeVoice(N_ALVoice* voice) { + ALFilter* f; + N_ALFreeParam* update; if (voice->pvoice) { if (voice->pvoice->offset) { /* if voice was stolen */ - update = (N_ALFreeParam *)__n_allocParam(); + update = (N_ALFreeParam*)__n_allocParam(); ALFailIf(update == 0, ERR_ALSYN_NO_UPDATE); /* * set voice data */ #ifdef SAMPLE_ROUND - update->delta = SAMPLE184( n_syn->paramSamples + voice->pvoice->offset); + update->delta = SAMPLE184(n_syn->paramSamples + voice->pvoice->offset); #else - update->delta = n_syn->paramSamples + voice->pvoice->offset; + update->delta = n_syn->paramSamples + voice->pvoice->offset; #endif - update->type = AL_FILTER_FREE_VOICE; + update->type = AL_FILTER_FREE_VOICE; update->pvoice = voice->pvoice; - n_alEnvmixerParam(voice->pvoice, AL_FILTER_ADD_UPDATE, update); + n_alEnvmixerParam(voice->pvoice, AL_FILTER_ADD_UPDATE, update); } else { _n_freePVoice(voice->pvoice); } diff --git a/src/libnaudio/n_synsetfxmix.c b/src/libnaudio/n_synsetfxmix.c index b397e0e0..4cec11b6 100644 --- a/src/libnaudio/n_synsetfxmix.c +++ b/src/libnaudio/n_synsetfxmix.c @@ -21,9 +21,8 @@ #include #include "n_synthInternals.h" -void n_alSynSetFXMix(N_ALVoice *v, u8 fxmix) -{ - ALParam *update; +void n_alSynSetFXMix(N_ALVoice* v, u8 fxmix) { + ALParam* update; if (v->pvoice) { /* @@ -36,17 +35,16 @@ void n_alSynSetFXMix(N_ALVoice *v, u8 fxmix) * set offset and fxmix data */ #ifdef SAMPLE_ROUND - update->delta = SAMPLE184( n_syn->paramSamples + v->pvoice->offset); + update->delta = SAMPLE184(n_syn->paramSamples + v->pvoice->offset); #else - update->delta = n_syn->paramSamples + v->pvoice->offset; + update->delta = n_syn->paramSamples + v->pvoice->offset; #endif - update->type = AL_FILTER_SET_FXAMT; - if (fxmix > 127) - fxmix = 127; - update->data.i = fxmix; - update->next = 0; + update->type = AL_FILTER_SET_FXAMT; + if (fxmix > 127) + fxmix = 127; + update->data.i = fxmix; + update->next = 0; - n_alEnvmixerParam(v->pvoice, AL_FILTER_ADD_UPDATE, update); + n_alEnvmixerParam(v->pvoice, AL_FILTER_ADD_UPDATE, update); } } - diff --git a/src/libnaudio/n_synsetpan.c b/src/libnaudio/n_synsetpan.c index 22a3d062..ebb29e02 100644 --- a/src/libnaudio/n_synsetpan.c +++ b/src/libnaudio/n_synsetpan.c @@ -21,9 +21,8 @@ #include #include "n_synthInternals.h" -void n_alSynSetPan(N_ALVoice *v, u8 pan) -{ - ALParam *update; +void n_alSynSetPan(N_ALVoice* v, u8 pan) { + ALParam* update; if (v->pvoice) { @@ -37,15 +36,14 @@ void n_alSynSetPan(N_ALVoice *v, u8 pan) * set offset and pan data */ #ifdef SAMPLE_ROUND - update->delta = SAMPLE184( n_syn->paramSamples + v->pvoice->offset); + update->delta = SAMPLE184(n_syn->paramSamples + v->pvoice->offset); #else - update->delta = n_syn->paramSamples + v->pvoice->offset; + update->delta = n_syn->paramSamples + v->pvoice->offset; #endif - update->type = AL_FILTER_SET_PAN; + update->type = AL_FILTER_SET_PAN; update->data.i = pan; - update->next = 0; + update->next = 0; - n_alEnvmixerParam(v->pvoice, AL_FILTER_ADD_UPDATE, update); + n_alEnvmixerParam(v->pvoice, AL_FILTER_ADD_UPDATE, update); } } - diff --git a/src/libnaudio/n_synsetpitch.c b/src/libnaudio/n_synsetpitch.c index 76b000f5..b0dc5367 100644 --- a/src/libnaudio/n_synsetpitch.c +++ b/src/libnaudio/n_synsetpitch.c @@ -21,15 +21,14 @@ #include #include "n_synthInternals.h" -void n_alSynSetPitch(N_ALVoice *v, f32 pitch) -{ - ALParam *update; +void n_alSynSetPitch(N_ALVoice* v, f32 pitch) { + ALParam* update; - if (v->pvoice) { + if (v->pvoice) { /* * get new update struct from the free list */ - + update = __n_allocParam(); ALFailIf(update == 0, ERR_ALSYN_NO_UPDATE); @@ -37,15 +36,14 @@ void n_alSynSetPitch(N_ALVoice *v, f32 pitch) * set offset and pitch data */ #ifdef SAMPLE_ROUND - update->delta = SAMPLE184( n_syn->paramSamples + v->pvoice->offset); + update->delta = SAMPLE184(n_syn->paramSamples + v->pvoice->offset); #else - update->delta = n_syn->paramSamples + v->pvoice->offset; + update->delta = n_syn->paramSamples + v->pvoice->offset; #endif - update->type = AL_FILTER_SET_PITCH; + update->type = AL_FILTER_SET_PITCH; update->data.f = pitch; - update->next = 0; + update->next = 0; - n_alEnvmixerParam(v->pvoice, AL_FILTER_ADD_UPDATE, update); + n_alEnvmixerParam(v->pvoice, AL_FILTER_ADD_UPDATE, update); } } - diff --git a/src/libnaudio/n_synsetvol.c b/src/libnaudio/n_synsetvol.c index 84b72d85..45782d36 100644 --- a/src/libnaudio/n_synsetvol.c +++ b/src/libnaudio/n_synsetvol.c @@ -21,10 +21,9 @@ #include #include "n_synthInternals.h" -void n_alSynSetVol(N_ALVoice *v, s16 volume, ALMicroTime t) -{ - ALParam *update; - ALFilter *f; +void n_alSynSetVol(N_ALVoice* v, s16 volume, ALMicroTime t) { + ALParam* update; + ALFilter* f; if (v->pvoice) { /* @@ -37,21 +36,20 @@ void n_alSynSetVol(N_ALVoice *v, s16 volume, ALMicroTime t) * set offset and volume data */ #ifdef SAMPLE_ROUND - update->delta = SAMPLE184( n_syn->paramSamples + v->pvoice->offset); + update->delta = SAMPLE184(n_syn->paramSamples + v->pvoice->offset); #else - update->delta = n_syn->paramSamples + v->pvoice->offset; + update->delta = n_syn->paramSamples + v->pvoice->offset; #endif - update->type = AL_FILTER_SET_VOLUME; - update->data.i = volume; + update->type = AL_FILTER_SET_VOLUME; + update->data.i = volume; #ifdef SAMPLE_ROUND - update->moredata.i = SAMPLE184( _n_timeToSamples(t) ); + update->moredata.i = SAMPLE184(_n_timeToSamples(t)); #else - update->moredata.i = _n_timeToSamples(t); + update->moredata.i = _n_timeToSamples(t); #endif - update->next = 0; + update->next = 0; - n_alEnvmixerParam(v->pvoice, AL_FILTER_ADD_UPDATE, update); + n_alEnvmixerParam(v->pvoice, AL_FILTER_ADD_UPDATE, update); } } - diff --git a/src/libnaudio/n_synstartvoiceparam.c b/src/libnaudio/n_synstartvoiceparam.c index 679bea35..e7ba52f6 100644 --- a/src/libnaudio/n_synstartvoiceparam.c +++ b/src/libnaudio/n_synstartvoiceparam.c @@ -20,47 +20,42 @@ #include #include -void n_alSynStartVoiceParams(N_ALVoice *v, ALWaveTable *w, f32 pitch, - s16 vol, ALPan pan, u8 fxmix, ALMicroTime t) -{ - ALStartParamAlt *update; +void n_alSynStartVoiceParams(N_ALVoice* v, ALWaveTable* w, f32 pitch, s16 vol, ALPan pan, u8 fxmix, ALMicroTime t) { + ALStartParamAlt* update; if (v->pvoice) { /* * get new update struct from the free list */ - update = (ALStartParamAlt *)__n_allocParam(); + update = (ALStartParamAlt*)__n_allocParam(); ALFailIf(update == 0, ERR_ALSYN_NO_UPDATE); - if (fxmix > 127) + if (fxmix > 127) fxmix = 127; - - /* - * set offset and fxmix data - */ + + /* + * set offset and fxmix data + */ #ifdef SAMPLE_ROUND - update->delta = SAMPLE184( n_syn->paramSamples + v->pvoice->offset); + update->delta = SAMPLE184(n_syn->paramSamples + v->pvoice->offset); #else - update->delta = n_syn->paramSamples + v->pvoice->offset; + update->delta = n_syn->paramSamples + v->pvoice->offset; #endif - update->next = 0; - update->type = AL_FILTER_START_VOICE_ALT; + update->next = 0; + update->type = AL_FILTER_START_VOICE_ALT; - update->unity = v->unityPitch; - update->pan = pan; + update->unity = v->unityPitch; + update->pan = pan; update->volume = vol; - update->fxMix = fxmix; - update->pitch = pitch; + update->fxMix = fxmix; + update->pitch = pitch; #ifdef SAMPLE_ROUND - update->samples = SAMPLE184( _n_timeToSamples(t) ); + update->samples = SAMPLE184(_n_timeToSamples(t)); #else update->samples = _n_timeToSamples(t); #endif - update->wave = w; - - n_alEnvmixerParam(v->pvoice, AL_FILTER_ADD_UPDATE, update); + update->wave = w; + + n_alEnvmixerParam(v->pvoice, AL_FILTER_ADD_UPDATE, update); } - } - - diff --git a/src/libnaudio/n_synstopvoice.c b/src/libnaudio/n_synstopvoice.c index 0a626d41..68b3eec5 100644 --- a/src/libnaudio/n_synstopvoice.c +++ b/src/libnaudio/n_synstopvoice.c @@ -21,26 +21,23 @@ #include #include "n_synthInternals.h" +void n_alSynStopVoice(N_ALVoice* v) { + ALParam* update; + ALFilter* f; -void n_alSynStopVoice(N_ALVoice *v) -{ - ALParam *update; - ALFilter *f; - if (v->pvoice) { - + update = __n_allocParam(); ALFailIf(update == 0, ERR_ALSYN_NO_UPDATE); #ifdef SAMPLE_ROUND - update->delta = SAMPLE184( n_syn->paramSamples + v->pvoice->offset); + update->delta = SAMPLE184(n_syn->paramSamples + v->pvoice->offset); #else - update->delta = n_syn->paramSamples + v->pvoice->offset; + update->delta = n_syn->paramSamples + v->pvoice->offset; #endif - update->type = AL_FILTER_STOP_VOICE; - update->next = 0; + update->type = AL_FILTER_STOP_VOICE; + update->next = 0; - n_alEnvmixerParam(v->pvoice, AL_FILTER_ADD_UPDATE, update); + n_alEnvmixerParam(v->pvoice, AL_FILTER_ADD_UPDATE, update); } } - diff --git a/src/libnaudio/n_synthInternals.h b/src/libnaudio/n_synthInternals.h index ac5aa3b6..bf9ce34b 100644 --- a/src/libnaudio/n_synthInternals.h +++ b/src/libnaudio/n_synthInternals.h @@ -20,7 +20,7 @@ #ifndef __N_SYNTHINTERNALS__ #define __N_SYNTHINTERNALS__ -#include +#include "synthInternals.h" #include "n_libaudio_sc.h" #include "n_abi.h" diff --git a/src/libnaudio/n_synthesizer.c b/src/libnaudio/n_synthesizer.c index 88857f5d..4ac3f8b1 100644 --- a/src/libnaudio/n_synthesizer.c +++ b/src/libnaudio/n_synthesizer.c @@ -30,63 +30,61 @@ extern u32 client_num, client_cnt, client_max, client_min; #endif #ifndef MIN -# define MIN(a,b) (((a)<(b))?(a):(b)) +#define MIN(a, b) (((a) < (b)) ? (a) : (b)) #endif -static s32 __n_nextSampleTime(ALPlayer **client); +static s32 __n_nextSampleTime(ALPlayer** client); static s32 _n_timeToSamplesNoRound(s32 micros); /*********************************************************************** * Synthesis driver public interfaces ***********************************************************************/ -void n_alSynNew(ALSynConfig *c) -{ - s32 i; - N_ALVoice *vv; - N_PVoice *pv; - N_ALVoice *vvoices; - N_PVoice *pvoices; - ALHeap *hp = c->heap; - ALSave *save; - ALFilter *sources; - N_PVoice *m_sources; - ALParam *params; - ALParam *paramPtr; - - n_syn->head = NULL; - n_syn->numPVoices = c->maxPVoices; - n_syn->curSamples = 0; - n_syn->paramSamples = 0; - n_syn->outputRate = c->outputRate; +void n_alSynNew(ALSynConfig* c) { + s32 i; + N_ALVoice* vv; + N_PVoice* pv; + N_ALVoice* vvoices; + N_PVoice* pvoices; + ALHeap* hp = c->heap; + ALSave* save; + ALFilter* sources; + N_PVoice* m_sources; + ALParam* params; + ALParam* paramPtr; + + n_syn->head = NULL; + n_syn->numPVoices = c->maxPVoices; + n_syn->curSamples = 0; + n_syn->paramSamples = 0; + n_syn->outputRate = c->outputRate; #ifndef N_MICRO - n_syn->maxOutSamples = AL_MAX_RSP_SAMPLES; + n_syn->maxOutSamples = AL_MAX_RSP_SAMPLES; #else - n_syn->maxOutSamples = FIXED_SAMPLE; + n_syn->maxOutSamples = FIXED_SAMPLE; #endif - n_syn->dma = (ALDMANew) c->dmaproc; + n_syn->dma = (ALDMANew)c->dmaproc; -/******* save new *******************************/ + /******* save new *******************************/ n_syn->sv_dramout = 0; n_syn->sv_first = 1; -/******* aux new *******************************/ - n_syn->auxBus = (N_ALAuxBus *)alHeapAlloc(hp, 1, sizeof(N_ALAuxBus)); + /******* aux new *******************************/ + n_syn->auxBus = (N_ALAuxBus*)alHeapAlloc(hp, 1, sizeof(N_ALAuxBus)); n_syn->auxBus->sourceCount = 0; n_syn->auxBus->maxSources = c->maxPVoices; - n_syn->auxBus->sources = (N_PVoice **) - alHeapAlloc(hp, c->maxPVoices, sizeof(N_PVoice *)); + n_syn->auxBus->sources = (N_PVoice**)alHeapAlloc(hp, c->maxPVoices, sizeof(N_PVoice*)); -/******* main new *******************************/ - n_syn->mainBus = (N_ALMainBus *)alHeapAlloc(hp, 1, sizeof(N_ALMainBus)); + /******* main new *******************************/ + n_syn->mainBus = (N_ALMainBus*)alHeapAlloc(hp, 1, sizeof(N_ALMainBus)); -/******* fx new *******************************/ + /******* fx new *******************************/ - if (c->fxType != AL_FX_NONE){ - n_syn->auxBus->fx = n_alSynAllocFX(0, c, hp); - n_syn->mainBus->filter.handler = (N_ALCmdHandler)n_alFxPull; + if (c->fxType != AL_FX_NONE) { + n_syn->auxBus->fx = n_alSynAllocFX(0, c, hp); + n_syn->mainBus->filter.handler = (N_ALCmdHandler)n_alFxPull; } else { - n_syn->mainBus->filter.handler = (N_ALCmdHandler)n_alAuxBusPull; + n_syn->mainBus->filter.handler = (N_ALCmdHandler)n_alAuxBusPull; } n_syn->pFreeList.next = 0; @@ -98,40 +96,39 @@ void n_alSynNew(ALSynConfig *c) pvoices = alHeapAlloc(hp, c->maxPVoices, sizeof(N_PVoice)); for (i = 0; i < c->maxPVoices; i++) { - pv = &pvoices[i]; - alLink((ALLink *)pv, &n_syn->pFreeList); - pv->vvoice = 0; - alN_PVoiceNew(pv, n_syn->dma, hp); - n_syn->auxBus->sources[n_syn->auxBus->sourceCount++] = pv; + pv = &pvoices[i]; + alLink((ALLink*)pv, &n_syn->pFreeList); + pv->vvoice = 0; + alN_PVoiceNew(pv, n_syn->dma, hp); + n_syn->auxBus->sources[n_syn->auxBus->sourceCount++] = pv; } params = alHeapAlloc(hp, c->maxUpdates, sizeof(ALParam)); n_syn->paramList = 0; for (i = 0; i < c->maxUpdates; i++) { - paramPtr= ¶ms[i]; + paramPtr = ¶ms[i]; paramPtr->next = n_syn->paramList; n_syn->paramList = paramPtr; } n_syn->heap = hp; } -Acmd *n_alAudioFrame(Acmd *cmdList, s32 *cmdLen, s16 *outBuf, s32 outLen) -{ - ALPlayer *client; - s16 tmp = 0; /* Starting buffer in DMEM */ - Acmd *cmdlEnd = cmdList; - Acmd *cmdPtr; - s32 nOut; - s16 *lOutBuf = outBuf; +Acmd* n_alAudioFrame(Acmd* cmdList, s32* cmdLen, s16* outBuf, s32 outLen) { + ALPlayer* client; + s16 tmp = 0; /* Starting buffer in DMEM */ + Acmd* cmdlEnd = cmdList; + Acmd* cmdPtr; + s32 nOut; + s16* lOutBuf = outBuf; #ifdef AUD_PROFILE lastCnt[++cnt_index] = osGetCount(); #endif - + if (n_syn->head == 0) { - *cmdLen = 0; - return cmdList; /* nothing to do */ - } + *cmdLen = 0; + return cmdList; /* nothing to do */ + } /* * run down list of clients and execute callback if needed this @@ -155,19 +152,16 @@ Acmd *n_alAudioFrame(Acmd *cmdList, s32 *cmdLen, s16 *outBuf, s32 outLen) */ #ifndef ONLY_ONE_PLAYER - for (n_syn->paramSamples = __n_nextSampleTime(&client); - n_syn->paramSamples - n_syn->curSamples < outLen; - n_syn->paramSamples = __n_nextSampleTime(&client)) - { - n_syn->paramSamples &= ~0xf; - client->samplesLeft += _n_timeToSamplesNoRound((*client->handler)(client)); + for (n_syn->paramSamples = __n_nextSampleTime(&client); n_syn->paramSamples - n_syn->curSamples < outLen; + n_syn->paramSamples = __n_nextSampleTime(&client)) { + n_syn->paramSamples &= ~0xf; + client->samplesLeft += _n_timeToSamplesNoRound((*client->handler)(client)); } #else client = n_syn->head; - while(client->samplesLeft - n_syn->curSamples < outLen) - { - n_syn->paramSamples = (client->samplesLeft & ~0xf); - client->samplesLeft += _n_timeToSamplesNoRound((*client->handler)(client)); + while (client->samplesLeft - n_syn->curSamples < outLen) { + n_syn->paramSamples = (client->samplesLeft & ~0xf); + client->samplesLeft += _n_timeToSamplesNoRound((*client->handler)(client)); } #endif @@ -185,7 +179,7 @@ Acmd *n_alAudioFrame(Acmd *cmdList, s32 *cmdLen, s16 *outBuf, s32 outLen) /* * Now build the command list in small chunks */ - while (outLen > 0){ + while (outLen > 0) { nOut = MIN(n_syn->maxOutSamples, outLen); /* @@ -196,18 +190,17 @@ Acmd *n_alAudioFrame(Acmd *cmdList, s32 *cmdLen, s16 *outBuf, s32 outLen) #ifndef N_MICRO aSegment(cmdPtr++, 0, 0); #endif - n_syn->sv_dramout = (s32)lOutBuf; + n_syn->sv_dramout = (s32)lOutBuf; cmdlEnd = n_alSavePull(n_syn->curSamples, cmdPtr); - + outLen -= nOut; - lOutBuf += nOut<<1; /* For Stereo */ + lOutBuf += nOut << 1; /* For Stereo */ n_syn->curSamples += nOut; - } - *cmdLen = (s32) (cmdlEnd - cmdList); + *cmdLen = (s32)(cmdlEnd - cmdList); _n_collectPVoices(); /* collect free physical voices */ - + #ifdef AUD_PROFILE PROFILE_AUD(drvr_num, drvr_cnt, drvr_max, drvr_min); #endif @@ -218,78 +211,70 @@ Acmd *n_alAudioFrame(Acmd *cmdList, s32 *cmdLen, s16 *outBuf, s32 outLen) * Synthesis driver private interfaces ***********************************************************************/ -ALParam *__n_allocParam(void) -{ - ALParam *update = 0; +ALParam* __n_allocParam(void) { + ALParam* update = 0; - if (n_syn->paramList) { + if (n_syn->paramList) { update = n_syn->paramList; n_syn->paramList = n_syn->paramList->next; update->next = 0; } return update; } - -void _n_freeParam(ALParam *param) -{ + +void _n_freeParam(ALParam* param) { param->next = n_syn->paramList; n_syn->paramList = param; } -void _n_collectPVoices(void) -{ - ALLink *dl; - N_PVoice *pv; +void _n_collectPVoices(void) { + ALLink* dl; + N_PVoice* pv; while ((dl = n_syn->pLameList.next) != 0) { - pv = (N_PVoice *)dl; + pv = (N_PVoice*)dl; /* ### remove from mixer */ alUnlink(dl); - alLink(dl, &n_syn->pFreeList); + alLink(dl, &n_syn->pFreeList); } } -void _n_freePVoice(N_PVoice *pvoice) -{ +void _n_freePVoice(N_PVoice* pvoice) { /* * move the voice from the allocated list to the lame list */ - alUnlink((ALLink *)pvoice); - alLink((ALLink *)pvoice, &n_syn->pLameList); + alUnlink((ALLink*)pvoice); + alLink((ALLink*)pvoice, &n_syn->pLameList); } - /* Add 0.5 to adjust the average affect of the truncation error produced by casting a float to an int. */ -s32 _n_timeToSamplesNoRound(s32 micros) -{ +s32 _n_timeToSamplesNoRound(s32 micros) { f32 tmp = ((f32)micros) * n_syn->outputRate / 1000000.0 + 0.5; return (s32)tmp; } -s32 _n_timeToSamples(s32 micros) -{ +s32 _n_timeToSamples(s32 micros) { return _n_timeToSamplesNoRound(micros) & ~0xf; } #ifndef ONLY_ONE_PLAYER -static s32 __n_nextSampleTime(ALPlayer **client) -{ - ALMicroTime delta = 0x7fffffff; /* max delta for s32 */ - ALPlayer *cl; +static s32 __n_nextSampleTime(ALPlayer** client) { + ALMicroTime delta = 0x7fffffff; /* max delta for s32 */ + ALPlayer* cl; u32 tt; #ifdef _DEBUG assert(n_syn->head); #endif *client = 0; - + for (cl = n_syn->head; cl != 0; cl = cl->next) { if ((cl->samplesLeft - n_syn->curSamples) < delta) { *client = cl; diff --git a/yamls/us/rom.yaml b/yamls/us/rom.yaml index 6f16db0c..e073e150 100644 --- a/yamls/us/rom.yaml +++ b/yamls/us/rom.yaml @@ -340,10 +340,13 @@ - [0x6A3E0, data, rom_data_6A3E0] - [0x6A3F0, .data, math_util] - [0x6FC00, data, rom_data_6FC00] + - [0x70070, .data, 20470] + - [0x703E0, data, rom_data_703E0] - [0x76260, .data, 29BA0] - [0x76280, data, rom_data_76280] - [0x78570, .data, 373A0] - - [0x78890, data, rom_data_78890] + - [0x78890, .data, 38BB0] + - [0x78990, data, rom_data_78990] - [0x79180, .data, libnaudio/n_sl] - [0x79190, data, rom_data_79190] - [0x79200, .data, libnaudio/n_env] @@ -416,7 +419,8 @@ - [0x7D110, rodata, rom_rodata_7D110] - [0x7D1B0, rodata, rom_rodata_7D1B0] - [0x7D230, .rodata, 373A0] - - [0x7D340, rodata, rom_rodata_7D340] + - [0x7D340, .rodata, 38BB0] + - [0x7D3C0, rodata, rom_rodata_7D3C0] - [0x7D3E0, rodata, rom_rodata_7D3E0] - [0x7D880, .rodata, libnaudio/n_env] - [0x7D8D0, rodata, rom_rodata_7D8D0] @@ -484,7 +488,8 @@ - {vram: 0x800AE520, type: .bss, name: 29BA0} - {vram: 0x800AF740, type: bss, name: unk_bss_7} - {vram: 0x800B32A0, type: .bss, name: 373A0} - - {vram: 0x800FC7A0, type: bss, name: unk_bss_12} + - {vram: 0x800FC7A0, type: .bss, name: 38BB0} + - {vram: 0x800FC820, type: bss, name: unk_bss_12} - {vram: 0x800FF990, type: .bss, name: 4B940} - {vram: 0x800FF9B0, type: .bss, name: 4BDC0} - {vram: 0x800FF9C0, type: bss, name: unk_bss_10}