From ccccf8ff51358db4118e58c56c38a44df934168b Mon Sep 17 00:00:00 2001 From: David Benepe Date: Thu, 22 Jul 2021 14:33:07 -0500 Subject: [PATCH] Split unknown_0667D0 into main & alSynStartVoiceParams --- asm/entrypoint.s | 4 +- .../{unknown_0667D0 => main}/func_80065D98.s | 2 +- .../{unknown_0667D0 => main}/func_80065E30.s | 0 .../menu/menu_audio_options_loop.s | 2 +- .../unknown_066500/alSynSetPan.s | 2 +- .../unknown_0667D0/alSynStartVoiceParams.s | 69 ----------------- lib/src/mips1/al/alSynStartVoiceParams.c | 51 ++++++++++++ lib/src/mips1/al/alSynStartVoiceParams.h | 14 ++++ src/main.c | 77 +++++++++++++++++++ src/menu.c | 2 +- src/unknown_0667D0.c | 72 ----------------- src/unknown_0667D0.h | 8 -- 12 files changed, 148 insertions(+), 155 deletions(-) rename asm/non_matchings/{unknown_0667D0 => main}/func_80065D98.s (97%) rename asm/non_matchings/{unknown_0667D0 => main}/func_80065E30.s (100%) delete mode 100644 asm/non_matchings/unknown_0667D0/alSynStartVoiceParams.s create mode 100644 lib/src/mips1/al/alSynStartVoiceParams.c create mode 100644 lib/src/mips1/al/alSynStartVoiceParams.h create mode 100644 src/main.c delete mode 100644 src/unknown_0667D0.c delete mode 100644 src/unknown_0667D0.h diff --git a/asm/entrypoint.s b/asm/entrypoint.s index a394c0a0..6ecad654 100644 --- a/asm/entrypoint.s +++ b/asm/entrypoint.s @@ -20,9 +20,9 @@ glabel entrypoint /* 001018 80000418 AD000004 */ sw $zero, 4($t0) /* 00101C 8000041C 1520FFFC */ bnez $t1, .L80000410 /* 001020 80000420 21080008 */ addi $t0, $t0, 8 -/* 001024 80000424 3C0A8006 */ lui $t2, %hi(func_80065D40) # $t2, 0x8006 +/* 001024 80000424 3C0A8006 */ lui $t2, %hi(main) # $t2, 0x8006 /* 001028 80000428 3C1D8012 */ lui $sp, %hi(D_80120AC0) # $sp, 0x8012 -/* 00102C 8000042C 254A5D40 */ addiu $t2, %lo(func_80065D40) # addiu $t2, $t2, 0x5d40 +/* 00102C 8000042C 254A5D40 */ addiu $t2, %lo(main) # addiu $t2, $t2, 0x5d40 /* 001030 80000430 01400008 */ jr $t2 /* 001034 80000434 27BD0AC0 */ addiu $sp, %lo(D_80120AC0) # addiu $sp, $sp, 0xac0 /* 001038 80000438 00000000 */ nop diff --git a/asm/non_matchings/unknown_0667D0/func_80065D98.s b/asm/non_matchings/main/func_80065D98.s similarity index 97% rename from asm/non_matchings/unknown_0667D0/func_80065D98.s rename to asm/non_matchings/main/func_80065D98.s index f0630ecd..edf42ebb 100644 --- a/asm/non_matchings/unknown_0667D0/func_80065D98.s +++ b/asm/non_matchings/main/func_80065D98.s @@ -1,4 +1,4 @@ -glabel D_80065D98 +glabel func_80065D98 /* 066998 80065D98 27BDFFE0 */ addiu $sp, $sp, -0x20 /* 06699C 80065D9C AFBF001C */ sw $ra, 0x1c($sp) /* 0669A0 80065DA0 0C02DBD4 */ jal func_800B6F50 diff --git a/asm/non_matchings/unknown_0667D0/func_80065E30.s b/asm/non_matchings/main/func_80065E30.s similarity index 100% rename from asm/non_matchings/unknown_0667D0/func_80065E30.s rename to asm/non_matchings/main/func_80065E30.s diff --git a/asm/non_matchings/menu/menu_audio_options_loop.s b/asm/non_matchings/menu/menu_audio_options_loop.s index 9f9f9e51..501e10d2 100644 --- a/asm/non_matchings/menu/menu_audio_options_loop.s +++ b/asm/non_matchings/menu/menu_audio_options_loop.s @@ -187,7 +187,7 @@ glabel menu_audio_options_loop /* 085B18 80084F18 AC400000 */ sw $zero, ($v0) /* 085B1C 80084F1C 00002025 */ move $a0, $zero .L80084F20: -/* 085B20 80084F20 0C0196F4 */ jal func_80065BD0 +/* 085B20 80084F20 0C0196F4 */ jal set_stereo_pan_mode /* 085B24 80084F24 00000000 */ nop /* 085B28 80084F28 240E0001 */ li $t6, 1 /* 085B2C 80084F2C 10000074 */ b .L80085100 diff --git a/asm/non_matchings/unknown_066500/alSynSetPan.s b/asm/non_matchings/unknown_066500/alSynSetPan.s index 91652705..46d98986 100644 --- a/asm/non_matchings/unknown_066500/alSynSetPan.s +++ b/asm/non_matchings/unknown_066500/alSynSetPan.s @@ -21,7 +21,7 @@ glabel alSynSetPan /* 06676C 80065B6C 032A5821 */ addu $t3, $t9, $t2 /* 066770 80065B70 AC4B0004 */ sw $t3, 4($v0) /* 066774 80065B74 93A4002B */ lbu $a0, 0x2b($sp) -/* 066778 80065B78 0C0196FB */ jal func_80065BEC +/* 066778 80065B78 0C0196FB */ jal modify_panning /* 06677C 80065B7C AFA2001C */ sw $v0, 0x1c($sp) /* 066780 80065B80 8FA6001C */ lw $a2, 0x1c($sp) /* 066784 80065B84 24050003 */ li $a1, 3 diff --git a/asm/non_matchings/unknown_0667D0/alSynStartVoiceParams.s b/asm/non_matchings/unknown_0667D0/alSynStartVoiceParams.s deleted file mode 100644 index 100a6b6a..00000000 --- a/asm/non_matchings/unknown_0667D0/alSynStartVoiceParams.s +++ /dev/null @@ -1,69 +0,0 @@ -glabel alSynStartVoiceParams -/* 066838 80065C38 27BDFFE0 */ addiu $sp, $sp, -0x20 -/* 06683C 80065C3C AFBF0014 */ sw $ra, 0x14($sp) -/* 066840 80065C40 AFA40020 */ sw $a0, 0x20($sp) -/* 066844 80065C44 AFA50024 */ sw $a1, 0x24($sp) -/* 066848 80065C48 AFA60028 */ sw $a2, 0x28($sp) -/* 06684C 80065C4C AFA7002C */ sw $a3, 0x2c($sp) -/* 066850 80065C50 8CAF0008 */ lw $t7, 8($a1) -/* 066854 80065C54 00000000 */ nop -/* 066858 80065C58 11E00036 */ beqz $t7, .L80065D34 -/* 06685C 80065C5C 8FBF0014 */ lw $ra, 0x14($sp) -/* 066860 80065C60 0C01959A */ jal __allocParam -/* 066864 80065C64 00000000 */ nop -/* 066868 80065C68 10400031 */ beqz $v0, .L80065D30 -/* 06686C 80065C6C 00403025 */ move $a2, $v0 -/* 066870 80065C70 8FA20024 */ lw $v0, 0x24($sp) -/* 066874 80065C74 8FB80020 */ lw $t8, 0x20($sp) -/* 066878 80065C78 8C480008 */ lw $t0, 8($v0) -/* 06687C 80065C7C 8F19001C */ lw $t9, 0x1c($t8) -/* 066880 80065C80 8D0900D8 */ lw $t1, 0xd8($t0) -/* 066884 80065C84 240B000D */ li $t3, 13 -/* 066888 80065C88 03295021 */ addu $t2, $t9, $t1 -/* 06688C 80065C8C ACCA0004 */ sw $t2, 4($a2) -/* 066890 80065C90 ACC00000 */ sw $zero, ($a2) -/* 066894 80065C94 A4CB0008 */ sh $t3, 8($a2) -/* 066898 80065C98 844C001A */ lh $t4, 0x1a($v0) -/* 06689C 80065C9C 00000000 */ nop -/* 0668A0 80065CA0 A4CC000A */ sh $t4, 0xa($a2) -/* 0668A4 80065CA4 93A40037 */ lbu $a0, 0x37($sp) -/* 0668A8 80065CA8 0C0196FB */ jal func_80065BEC -/* 0668AC 80065CAC AFA6001C */ sw $a2, 0x1c($sp) -/* 0668B0 80065CB0 8FA6001C */ lw $a2, 0x1c($sp) -/* 0668B4 80065CB4 00000000 */ nop -/* 0668B8 80065CB8 A0C20012 */ sb $v0, 0x12($a2) -/* 0668BC 80065CBC 87AD0032 */ lh $t5, 0x32($sp) -/* 0668C0 80065CC0 00000000 */ nop -/* 0668C4 80065CC4 A4CD0010 */ sh $t5, 0x10($a2) -/* 0668C8 80065CC8 93AE003B */ lbu $t6, 0x3b($sp) -/* 0668CC 80065CCC 00000000 */ nop -/* 0668D0 80065CD0 A0CE0013 */ sb $t6, 0x13($a2) -/* 0668D4 80065CD4 C7A4002C */ lwc1 $f4, 0x2c($sp) -/* 0668D8 80065CD8 00000000 */ nop -/* 0668DC 80065CDC E4C4000C */ swc1 $f4, 0xc($a2) -/* 0668E0 80065CE0 8FA5003C */ lw $a1, 0x3c($sp) -/* 0668E4 80065CE4 8FA40020 */ lw $a0, 0x20($sp) -/* 0668E8 80065CE8 0C0195F1 */ jal __timeToSamples -/* 0668EC 80065CEC 00000000 */ nop -/* 0668F0 80065CF0 8FA6001C */ lw $a2, 0x1c($sp) -/* 0668F4 80065CF4 24050003 */ li $a1, 3 -/* 0668F8 80065CF8 ACC20014 */ sw $v0, 0x14($a2) -/* 0668FC 80065CFC 8FAF0028 */ lw $t7, 0x28($sp) -/* 066900 80065D00 00000000 */ nop -/* 066904 80065D04 ACCF0018 */ sw $t7, 0x18($a2) -/* 066908 80065D08 8FB80024 */ lw $t8, 0x24($sp) -/* 06690C 80065D0C 00000000 */ nop -/* 066910 80065D10 8F080008 */ lw $t0, 8($t8) -/* 066914 80065D14 00000000 */ nop -/* 066918 80065D18 8D04000C */ lw $a0, 0xc($t0) -/* 06691C 80065D1C 00000000 */ nop -/* 066920 80065D20 8C990008 */ lw $t9, 8($a0) -/* 066924 80065D24 00000000 */ nop -/* 066928 80065D28 0320F809 */ jalr $t9 -/* 06692C 80065D2C 00000000 */ nop -.L80065D30: -/* 066930 80065D30 8FBF0014 */ lw $ra, 0x14($sp) -.L80065D34: -/* 066934 80065D34 27BD0020 */ addiu $sp, $sp, 0x20 -/* 066938 80065D38 03E00008 */ jr $ra -/* 06693C 80065D3C 00000000 */ nop diff --git a/lib/src/mips1/al/alSynStartVoiceParams.c b/lib/src/mips1/al/alSynStartVoiceParams.c new file mode 100644 index 00000000..1eea9e40 --- /dev/null +++ b/lib/src/mips1/al/alSynStartVoiceParams.c @@ -0,0 +1,51 @@ +/* The comment below is needed for this file to be picked up by generate_ld */ +/* RAM_POS: 0x80065BD0 */ + +#include "alSynStartVoiceParams.h" + +s16 gStereoPanMode = STEREO; + +void set_stereo_pan_mode(s32 panMode) { + gStereoPanMode = panMode; +} + +/* Unused. */ +s16 get_stereo_pan_mode(void) { + return gStereoPanMode; +} + +s32 modify_panning(s32 pan) { + switch(gStereoPanMode) { + case STEREO: + return pan; + case HEADPHONES: + pan = ((pan - 64) >> 1) + 64; + return pan; + case MONO: + default: + return 64; + } +} + +void alSynStartVoiceParams(ALSynth *s, ALVoice *v, ALWaveTable *w, f32 pitch, s16 vol, ALPan pan, u8 fxmix, ALMicroTime t) { + ALStartParamAlt *update; + ALFilter *f; + + if (v->pvoice) { + update = (ALStartParamAlt *)__allocParam(); + if (update != NULL) { + update->delta = s->paramSamples + v->pvoice->offset; + update->next = 0; + update->type = AL_FILTER_START_VOICE_ALT; + update->unity = v->unityPitch; + update->pan = modify_panning(pan); + update->volume = vol; + update->fxMix = fxmix; + update->pitch = pitch; + update->samples = __timeToSamples(s, t); + update->wave = w; + f = v->pvoice->channelKnob; + (*f->setParam)(f, AL_FILTER_ADD_UPDATE, update); + } + } +} diff --git a/lib/src/mips1/al/alSynStartVoiceParams.h b/lib/src/mips1/al/alSynStartVoiceParams.h new file mode 100644 index 00000000..6544052c --- /dev/null +++ b/lib/src/mips1/al/alSynStartVoiceParams.h @@ -0,0 +1,14 @@ +#ifndef AL_SYN_START_VOICE_PARAMS +#define AL_SYN_START_VOICE_PARAMS + +#include "types.h" +#include "audio_internal.h" + +// Can be changed in the "Audio Options" menu. +enum StereoPanMode { + STEREO, + MONO, + HEADPHONES +}; + +#endif \ No newline at end of file diff --git a/src/main.c b/src/main.c new file mode 100644 index 00000000..d7164f05 --- /dev/null +++ b/src/main.c @@ -0,0 +1,77 @@ +/* The comment below is needed for this file to be picked up by generate_ld */ +/* RAM_POS: 0x80065D40 */ + +#include "types.h" +#include "macros.h" +#include "libultra_internal.h" + +/************ .rodata ************/ + +#ifndef NON_MATCHING +// Remove this when func_80065E30 is matching. +const char D_800E6ED0[] = "WARNING: Stack overflow/underflow!!!\n"; +#endif + +/*********************************/ + +/************ .bss ************/ + +s32 *D_8011D750; // stack pointer for thread 1 +s32 D_8011D754; +s32 D_8011D758[2048]; +s32 *D_8011F758; +s32 D_8011F75C; +OSThread *D_8011F760; // OSThread for thread 1 +s32 D_8011F764; +s32 D_8011F768[106]; +OSThread *D_8011F910; // OSThread for thread 3 +s32 D_8011F914; +s32 D_8011F918[1130]; + +/******************************/ + +void func_80065D98(s32 arg0); +void thread3_main(s32 arg0); + +void main(void) { + osInitialize(); + osCreateThread(&D_8011F760, 1, &func_80065D98, 0, &D_8011D750, 0); + osStartThread(&D_8011F760); +} + +#ifdef NON_MATCHING +void func_80065D98(s32 arg0) { + func_800B6F50(); + osCreateThread(&D_8011F910, 3, &thread3_main, 0, &D_8011F758, 10); + D_8011D758[2049] = 0; + D_8011D758[2048] = 0; + D_8011D758[1] = 0; + D_8011D758[0] = 0; + osStartThread(&D_8011F910); + osSetThreadPri(NULL, 0); + while(1){} +} +#else +GLOBAL_ASM("asm/non_matchings/main/func_80065D98.s") +#endif + +#ifdef NON_MATCHING +void func_80065E30(void) { + s32 temp, temp2, temp3, temp4; + temp = D_8011D758[2049] + 1; + temp2 = D_8011D758[2048] + (temp == 0); + temp3 = D_8011D758[1] + 1; + temp4 = D_8011D758[0] + (temp3 == 0); + D_8011D758[2049] = temp; + D_8011D758[2048] = temp2; + D_8011D758[1] = temp3; + D_8011D758[0] = temp4; + if ((temp2 != temp4) || (temp != temp3)) { + func_800C9D54("WARNING: Stack overflow/underflow!!!\n"); + } +} +#else +GLOBAL_ASM("asm/non_matchings/main/func_80065E30.s") +#endif + + diff --git a/src/menu.c b/src/menu.c index 351ee3ba..4a885a8c 100644 --- a/src/menu.c +++ b/src/menu.c @@ -2213,7 +2213,7 @@ s32 menu_audio_options_loop(s32 arg0) { if (D_800DFAC8 > 2) { D_800DFAC8 = 0; } - func_80065BD0(D_800DFAC8); + set_stereo_pan_mode(D_800DFAC8); sp30 = 1; } else if ((phi_a2 >> 2) != 0) { if(gOptionsMenuItemIndex == 2) { diff --git a/src/unknown_0667D0.c b/src/unknown_0667D0.c deleted file mode 100644 index e4aa8899..00000000 --- a/src/unknown_0667D0.c +++ /dev/null @@ -1,72 +0,0 @@ -/* The comment below is needed for this file to be picked up by generate_ld */ -/* RAM_POS: 0x80065BD0 */ - -#include "unknown_0667D0.h" - -#include "types.h" -#include "macros.h" -#include "libultra_internal.h" - -/************ .data ************/ - -s16 D_800DD050 = 0; - -/*******************************/ - -extern s32* D_80065D98; // func_80065D98 is the entry function for thread 1 - -/************ .rodata ************/ - -// In func_80065E30 -const char D_800E6ED0[] = "WARNING: Stack overflow/underflow!!!\n"; - -/*********************************/ - -/************ .bss ************/ - -s32 *D_8011D750; // stack pointer for thread 1 -s32 D_8011D754; -s32 D_8011D758[2048]; -s32 *D_8011F758; -s32 D_8011F75C; -OSThread *D_8011F760; // OSThread for thread 1 -s32 D_8011F764; -s32 D_8011F768[106]; -s32 *D_8011F910[1132]; - -/******************************/ - -void func_80065BD0(s32 arg0) { - D_800DD050 = arg0; -} - -/* Unused? */ -s16 func_80065BDC(void) { - return D_800DD050; -} - -s32 func_80065BEC(s32 arg0) { - switch(D_800DD050) { - case 0: - return arg0; - case 2: - arg0 = ((arg0 - 0x40) >> 1) + 0x40; - return arg0; - case 1: - default: - return 0x40; - } -} - -GLOBAL_ASM("asm/non_matchings/unknown_0667D0/alSynStartVoiceParams.s") - -void func_80065D40(void) { - osInitialize(); - osCreateThread(&D_8011F760, 1, &D_80065D98, 0, &D_8011D750, 0); - osStartThread(&D_8011F760); -} - -GLOBAL_ASM("asm/non_matchings/unknown_0667D0/func_80065D98.s") -GLOBAL_ASM("asm/non_matchings/unknown_0667D0/func_80065E30.s") - - diff --git a/src/unknown_0667D0.h b/src/unknown_0667D0.h deleted file mode 100644 index 0eb70020..00000000 --- a/src/unknown_0667D0.h +++ /dev/null @@ -1,8 +0,0 @@ -#ifndef _UNKNOWN_066500_H_ -#define _UNKNOWN_066500_H_ - -#include "types.h" - -extern s16 D_800DD050; - -#endif \ No newline at end of file