From 0fc998041136496575fc67e2a75aeddeee1ce2e1 Mon Sep 17 00:00:00 2001 From: Phillip Stephens Date: Mon, 27 Feb 2023 06:14:29 -0800 Subject: [PATCH] More MusyX progress, fully match hardware.c Former-commit-id: 4baceece91dcd003521b3b33efc7ca710842e24b --- asm/musyx/runtime/synthmacros.s | 118 +--- configure.py | 6 +- include/musyx/assert.h | 23 +- include/musyx/musyx.h | 2 + include/musyx/musyx_priv.h | 14 +- include/musyx/synth.h | 2 +- include/musyx/version.h | 26 + libc/math.h | 4 +- src/musyx/runtime/CheapReverb/creverb.c | 31 + src/musyx/runtime/CheapReverb/creverb_fx.c | 32 +- src/musyx/runtime/Chorus/chorus_fx.c | 628 ++++++++++++--------- src/musyx/runtime/Delay/delay_fx.c | 96 ++-- src/musyx/runtime/StdReverb/reverb_fx.c | 4 +- src/musyx/runtime/hardware.c | 156 ++--- src/musyx/runtime/hw_dolphin.c | 2 +- src/musyx/runtime/hw_dspctrl.c | 4 +- src/musyx/runtime/s_data.c | 12 +- src/musyx/runtime/snd_init.c | 6 +- src/musyx/runtime/snd_midictrl.c | 6 +- src/musyx/runtime/synth.c | 2 +- src/musyx/runtime/synth_adsr.c | 2 +- src/musyx/runtime/synth_vsamples.c | 12 +- src/musyx/runtime/synthdata.c | 2 +- src/musyx/runtime/synthmacros.c | 417 ++++++++++++-- src/musyx/runtime/synthvoice.c | 88 ++- src/musyx/txwin/txwin.c | 24 +- 26 files changed, 1068 insertions(+), 651 deletions(-) create mode 100644 include/musyx/version.h create mode 100644 src/musyx/runtime/CheapReverb/creverb.c diff --git a/asm/musyx/runtime/synthmacros.s b/asm/musyx/runtime/synthmacros.s index 108d025a..a8c92267 100644 --- a/asm/musyx/runtime/synthmacros.s +++ b/asm/musyx/runtime/synthmacros.s @@ -8,16 +8,23 @@ .section .sbss .balign 8 -"cstep$1643": +.obj "cstep$1643", local .skip 0x8 -macRealTime: +.endobj "cstep$1643" +.obj macRealTime, local .skip 0x8 -macTimeQueueRoot: +.endobj macRealTime + +.obj macTimeQueueRoot, local .skip 0x4 -macActiveMacroRoot: +.endobj macTimeQueueRoot + +.obj macActiveMacroRoot, local .skip 0x4 -DebugMacroSteps: - .skip 0x8 +.endobj macActiveMacroRoot +.obj DebugMacroSteps, local + .skip 0x1 +.endobj DebugMacroSteps .section .data, "wa" .balign 8 @@ -1662,8 +1669,8 @@ lbl_803A3C3C: /* 803A3C4C 003A0BAC 38 21 00 50 */ addi r1, r1, 0x50 /* 803A3C50 003A0BB0 4E 80 00 20 */ blr -.global macSetPanning -macSetPanning: +.global mcmdSetPanning +mcmdSetPanning: /* 803A3C54 003A0BB4 94 21 FF E0 */ stwu r1, -0x20(r1) /* 803A3C58 003A0BB8 7C 08 02 A6 */ mflr r0 /* 803A3C5C 003A0BBC 90 01 00 24 */ stw r0, 0x24(r1) @@ -1706,8 +1713,8 @@ lbl_803A3CC8: /* 803A3CE8 003A0C48 38 21 00 20 */ addi r1, r1, 0x20 /* 803A3CEC 003A0C4C 4E 80 00 20 */ blr -.global mcmdSetPanning -mcmdSetPanning: +.global mcmdSetSurroundPanning +mcmdSetSurroundPanning: /* 803A3CF0 003A0C50 94 21 FF E0 */ stwu r1, -0x20(r1) /* 803A3CF4 003A0C54 7C 08 02 A6 */ mflr r0 /* 803A3CF8 003A0C58 90 01 00 24 */ stw r0, 0x24(r1) @@ -2843,8 +2850,8 @@ lbl_803A4CB0: /* 803A4CE8 003A1C48 38 21 00 10 */ addi r1, r1, 0x10 /* 803A4CEC 003A1C4C 4E 80 00 20 */ blr -.global mcmdSurroundingPanningSelect -mcmdSurroundingPanningSelect: +.global mcmdSurroundPanningSelect +mcmdSurroundPanningSelect: /* 803A4CF0 003A1C50 94 21 FF F0 */ stwu r1, -0x10(r1) /* 803A4CF4 003A1C54 7C 08 02 A6 */ mflr r0 /* 803A4CF8 003A1C58 3C A0 04 00 */ lis r5, 0x400 @@ -4108,7 +4115,6 @@ lbl_803A5E38: /* 803A5E8C 003A2DEC 7C 03 00 2E */ lwzx r0, r3, r0 /* 803A5E90 003A2DF0 7C 09 03 A6 */ mtctr r0 /* 803A5E94 003A2DF4 4E 80 04 20 */ bctr -.global lbl_803A5E98 lbl_803A5E98: /* 803A5E98 003A2DF8 7F E3 FB 78 */ mr r3, r31 /* 803A5E9C 003A2DFC 48 00 18 A5 */ bl vidRemoveVoiceReferences @@ -4116,7 +4122,6 @@ lbl_803A5E98: /* 803A5EA4 003A2E04 48 00 24 01 */ bl voiceFree /* 803A5EA8 003A2E08 3B C0 00 01 */ li r30, 1 /* 803A5EAC 003A2E0C 48 00 0C 58 */ b lbl_803A6B04 -.global lbl_803A5EB0 lbl_803A5EB0: /* 803A5EB0 003A2E10 7F E3 FB 78 */ mr r3, r31 /* 803A5EB4 003A2E14 48 00 18 8D */ bl vidRemoveVoiceReferences @@ -4124,7 +4129,6 @@ lbl_803A5EB0: /* 803A5EBC 003A2E1C 48 00 23 E9 */ bl voiceFree /* 803A5EC0 003A2E20 3B C0 00 01 */ li r30, 1 /* 803A5EC4 003A2E24 48 00 0C 40 */ b lbl_803A6B04 -.global lbl_803A5EC8 lbl_803A5EC8: /* 803A5EC8 003A2E28 A0 7F 01 2C */ lhz r3, 0x12c(r31) /* 803A5ECC 003A2E2C 57 40 C6 3E */ rlwinm r0, r26, 0x18, 0x18, 0x1f @@ -4140,7 +4144,6 @@ lbl_803A5EC8: /* 803A5EF4 003A2E54 7C 03 02 14 */ add r0, r3, r0 /* 803A5EF8 003A2E58 90 1F 00 38 */ stw r0, 0x38(r31) /* 803A5EFC 003A2E5C 48 00 0C 08 */ b lbl_803A6B04 -.global lbl_803A5F00 lbl_803A5F00: /* 803A5F00 003A2E60 80 7F 01 54 */ lwz r3, 0x154(r31) /* 803A5F04 003A2E64 57 40 C6 3E */ rlwinm r0, r26, 0x18, 0x18, 0x1f @@ -4157,20 +4160,17 @@ lbl_803A5F00: /* 803A5F30 003A2E90 7C 03 02 14 */ add r0, r3, r0 /* 803A5F34 003A2E94 90 1F 00 38 */ stw r0, 0x38(r31) /* 803A5F38 003A2E98 48 00 0B CC */ b lbl_803A6B04 -.global lbl_803A5F3C lbl_803A5F3C: /* 803A5F3C 003A2E9C 7F E3 FB 78 */ mr r3, r31 /* 803A5F40 003A2EA0 38 8D AE E0 */ addi r4, r13, "cstep$1643"@sda21 /* 803A5F44 003A2EA4 4B FF CA 81 */ bl mcmdWait /* 803A5F48 003A2EA8 7C 7E 1B 78 */ mr r30, r3 /* 803A5F4C 003A2EAC 48 00 0B B8 */ b lbl_803A6B04 -.global lbl_803A5F50 lbl_803A5F50: /* 803A5F50 003A2EB0 7F E3 FB 78 */ mr r3, r31 /* 803A5F54 003A2EB4 38 8D AE E0 */ addi r4, r13, "cstep$1643"@sda21 /* 803A5F58 003A2EB8 4B FF CE 2D */ bl mcmdLoop /* 803A5F5C 003A2EBC 48 00 0B A8 */ b lbl_803A6B04 -.global lbl_803A5F60 lbl_803A5F60: /* 803A5F60 003A2EC0 57 43 84 3E */ srwi r3, r26, 0x10 /* 803A5F64 003A2EC4 4B FF C5 99 */ bl dataGetMacro @@ -4192,7 +4192,6 @@ lbl_803A5F8C: lbl_803A5FA0: /* 803A5FA0 003A2F00 7C 9E 23 78 */ mr r30, r4 /* 803A5FA4 003A2F04 48 00 0B 60 */ b lbl_803A6B04 -.global lbl_803A5FA8 lbl_803A5FA8: /* 803A5FA8 003A2F08 38 00 00 01 */ li r0, 1 /* 803A5FAC 003A2F0C 7F E3 FB 78 */ mr r3, r31 @@ -4201,13 +4200,11 @@ lbl_803A5FA8: /* 803A5FB8 003A2F18 4B FF CA 0D */ bl mcmdWait /* 803A5FBC 003A2F1C 7C 7E 1B 78 */ mr r30, r3 /* 803A5FC0 003A2F20 48 00 0B 44 */ b lbl_803A6B04 -.global lbl_803A5FC4 lbl_803A5FC4: /* 803A5FC4 003A2F24 7F E3 FB 78 */ mr r3, r31 /* 803A5FC8 003A2F28 38 8D AE E0 */ addi r4, r13, "cstep$1643"@sda21 /* 803A5FCC 003A2F2C 4B FF CF 0D */ bl mcmdPlayMacro /* 803A5FD0 003A2F30 48 00 0B 34 */ b lbl_803A6B04 -.global lbl_803A5FD4 lbl_803A5FD4: /* 803A5FD4 003A2F34 88 9F 01 2F */ lbz r4, 0x12f(r31) /* 803A5FD8 003A2F38 57 43 C6 3E */ rlwinm r3, r26, 0x18, 0x18, 0x1f @@ -4243,7 +4240,6 @@ lbl_803A6040: /* 803A6044 003A2FA4 7C 1B 00 40 */ cmplw r27, r0 /* 803A6048 003A2FA8 41 80 FF B0 */ blt lbl_803A5FF8 /* 803A604C 003A2FAC 48 00 0A B8 */ b lbl_803A6B04 -.global lbl_803A6050 lbl_803A6050: /* 803A6050 003A2FB0 88 1F 01 21 */ lbz r0, 0x121(r31) /* 803A6054 003A2FB4 28 00 00 FF */ cmplwi r0, 0xff @@ -4265,7 +4261,6 @@ lbl_803A6050: /* 803A6094 003A2FF4 7C 03 02 14 */ add r0, r3, r0 /* 803A6098 003A2FF8 90 1F 00 38 */ stw r0, 0x38(r31) /* 803A609C 003A2FFC 48 00 0A 68 */ b lbl_803A6B04 -.global lbl_803A60A0 lbl_803A60A0: /* 803A60A0 003A3000 A0 9F 01 2C */ lhz r4, 0x12c(r31) /* 803A60A4 003A3004 57 45 86 3E */ rlwinm r5, r26, 0x10, 0x18, 0x1f @@ -4289,43 +4284,36 @@ lbl_803A60E4: /* 803A60E4 003A3044 90 1F 01 80 */ stw r0, 0x180(r31) /* 803A60E8 003A3048 90 1F 01 70 */ stw r0, 0x170(r31) /* 803A60EC 003A304C 48 00 0A 18 */ b lbl_803A6B04 -.global lbl_803A60F0 lbl_803A60F0: /* 803A60F0 003A3050 7F E3 FB 78 */ mr r3, r31 /* 803A60F4 003A3054 38 8D AE E0 */ addi r4, r13, "cstep$1643"@sda21 /* 803A60F8 003A3058 4B FF D5 5D */ bl mcmdSetADSR /* 803A60FC 003A305C 48 00 0A 08 */ b lbl_803A6B04 -.global lbl_803A6100 lbl_803A6100: /* 803A6100 003A3060 7F E3 FB 78 */ mr r3, r31 /* 803A6104 003A3064 38 8D AE E0 */ addi r4, r13, "cstep$1643"@sda21 /* 803A6108 003A3068 4B FF DC 85 */ bl mcmdScaleVolume /* 803A610C 003A306C 48 00 09 F8 */ b lbl_803A6B04 -.global lbl_803A6110 lbl_803A6110: /* 803A6110 003A3070 7F E3 FB 78 */ mr r3, r31 /* 803A6114 003A3074 38 8D AE E0 */ addi r4, r13, "cstep$1643"@sda21 -/* 803A6118 003A3078 4B FF DB 3D */ bl macSetPanning +/* 803A6118 003A3078 4B FF DB 3D */ bl mcmdSetPanning /* 803A611C 003A307C 48 00 09 E8 */ b lbl_803A6B04 -.global lbl_803A6120 lbl_803A6120: /* 803A6120 003A3080 7F E3 FB 78 */ mr r3, r31 /* 803A6124 003A3084 38 8D AE E0 */ addi r4, r13, "cstep$1643"@sda21 /* 803A6128 003A3088 4B FF DD 99 */ bl mcmdEnvelope /* 803A612C 003A308C 48 00 09 D8 */ b lbl_803A6B04 -.global lbl_803A6130 lbl_803A6130: /* 803A6130 003A3090 7F E3 FB 78 */ mr r3, r31 /* 803A6134 003A3094 38 8D AE E0 */ addi r4, r13, "cstep$1643"@sda21 /* 803A6138 003A3098 4B FF D0 05 */ bl mcmdStartSample /* 803A613C 003A309C 48 00 09 C8 */ b lbl_803A6B04 -.global lbl_803A6140 lbl_803A6140: /* 803A6140 003A30A0 80 1F 00 F4 */ lwz r0, 0xf4(r31) /* 803A6144 003A30A4 54 03 06 3E */ clrlwi r3, r0, 0x18 /* 803A6148 003A30A8 48 00 D2 45 */ bl hwBreak /* 803A614C 003A30AC 48 00 09 B8 */ b lbl_803A6B04 -.global lbl_803A6150 lbl_803A6150: /* 803A6150 003A30B0 80 1F 01 18 */ lwz r0, 0x118(r31) /* 803A6154 003A30B4 7F E3 FB 78 */ mr r3, r31 @@ -4333,7 +4321,6 @@ lbl_803A6150: /* 803A615C 003A30BC 90 1F 01 18 */ stw r0, 0x118(r31) /* 803A6160 003A30C0 4B FF 49 81 */ bl synthKeyStateUpdate /* 803A6164 003A30C4 48 00 09 A0 */ b lbl_803A6B04 -.global lbl_803A6168 lbl_803A6168: /* 803A6168 003A30C8 48 00 CC 39 */ bl sndRand /* 803A616C 003A30CC 80 8D AE E0 */ lwz r4, "cstep$1643"@sda21(r13) @@ -4351,38 +4338,32 @@ lbl_803A6168: /* 803A619C 003A30FC 7C 03 02 14 */ add r0, r3, r0 /* 803A61A0 003A3100 90 1F 00 38 */ stw r0, 0x38(r31) /* 803A61A4 003A3104 48 00 09 60 */ b lbl_803A6B04 -.global lbl_803A61A8 lbl_803A61A8: /* 803A61A8 003A3108 7F E3 FB 78 */ mr r3, r31 /* 803A61AC 003A310C 38 8D AE E0 */ addi r4, r13, "cstep$1643"@sda21 /* 803A61B0 003A3110 4B FF DE 41 */ bl mcmdFadeIn /* 803A61B4 003A3114 48 00 09 50 */ b lbl_803A6B04 -.global lbl_803A61B8 lbl_803A61B8: /* 803A61B8 003A3118 7F E3 FB 78 */ mr r3, r31 /* 803A61BC 003A311C 38 8D AE E0 */ addi r4, r13, "cstep$1643"@sda21 -/* 803A61C0 003A3120 4B FF DB 31 */ bl mcmdSetPanning +/* 803A61C0 003A3120 4B FF DB 31 */ bl mcmdSetSurroundPanning /* 803A61C4 003A3124 48 00 09 40 */ b lbl_803A6B04 -.global lbl_803A61C8 lbl_803A61C8: /* 803A61C8 003A3128 7F E3 FB 78 */ mr r3, r31 /* 803A61CC 003A312C 38 8D AE E0 */ addi r4, r13, "cstep$1643"@sda21 /* 803A61D0 003A3130 4B FF D6 DD */ bl mcmdSetADSRFromCtrl /* 803A61D4 003A3134 48 00 09 30 */ b lbl_803A6B04 -.global lbl_803A61D8 lbl_803A61D8: /* 803A61D8 003A3138 7F E3 FB 78 */ mr r3, r31 /* 803A61DC 003A313C 38 8D AE E0 */ addi r4, r13, "cstep$1643"@sda21 /* 803A61E0 003A3140 4B FF DF 4D */ bl mcmdRandomKey /* 803A61E4 003A3144 48 00 09 20 */ b lbl_803A6B04 -.global lbl_803A61E8 lbl_803A61E8: /* 803A61E8 003A3148 7F E3 FB 78 */ mr r3, r31 /* 803A61EC 003A314C 38 8D AE E0 */ addi r4, r13, "cstep$1643"@sda21 /* 803A61F0 003A3150 4B FF CE 75 */ bl mcmdAddKey /* 803A61F4 003A3154 7C 7E 1B 78 */ mr r30, r3 /* 803A61F8 003A3158 48 00 09 0C */ b lbl_803A6B04 -.global lbl_803A61FC lbl_803A61FC: /* 803A61FC 003A315C 57 40 C6 7E */ rlwinm r0, r26, 0x18, 0x19, 0x1f /* 803A6200 003A3160 7F E3 FB 78 */ mr r3, r31 @@ -4406,7 +4387,6 @@ lbl_803A6234: /* 803A6244 003A31A4 4B FF C7 81 */ bl mcmdWait /* 803A6248 003A31A8 7C 7E 1B 78 */ mr r30, r3 /* 803A624C 003A31AC 48 00 08 B8 */ b lbl_803A6B04 -.global lbl_803A6250 lbl_803A6250: /* 803A6250 003A31B0 57 40 C6 3E */ rlwinm r0, r26, 0x18, 0x18, 0x1f /* 803A6254 003A31B4 88 7F 01 30 */ lbz r3, 0x130(r31) @@ -4443,19 +4423,16 @@ lbl_803A62B4: /* 803A62C4 003A3224 4B FF C7 01 */ bl mcmdWait /* 803A62C8 003A3228 7C 7E 1B 78 */ mr r30, r3 /* 803A62CC 003A322C 48 00 08 38 */ b lbl_803A6B04 -.global lbl_803A62D0 lbl_803A62D0: /* 803A62D0 003A3230 7F E3 FB 78 */ mr r3, r31 /* 803A62D4 003A3234 38 8D AE E0 */ addi r4, r13, "cstep$1643"@sda21 /* 803A62D8 003A3238 4B FF F0 1D */ bl mcmdPortamento /* 803A62DC 003A323C 48 00 08 28 */ b lbl_803A6B04 -.global lbl_803A62E0 lbl_803A62E0: /* 803A62E0 003A3240 7F E3 FB 78 */ mr r3, r31 /* 803A62E4 003A3244 38 8D AE E0 */ addi r4, r13, "cstep$1643"@sda21 /* 803A62E8 003A3248 4B FF D0 51 */ bl mcmdVibrato /* 803A62EC 003A324C 48 00 08 18 */ b lbl_803A6B04 -.global lbl_803A62F0 lbl_803A62F0: /* 803A62F0 003A3250 38 00 00 00 */ li r0, 0 /* 803A62F4 003A3254 90 1F 01 A0 */ stw r0, 0x1a0(r31) @@ -4485,7 +4462,6 @@ lbl_803A6334: /* 803A634C 003A32AC 4B FF C6 79 */ bl mcmdWait /* 803A6350 003A32B0 7C 7E 1B 78 */ mr r30, r3 /* 803A6354 003A32B4 48 00 07 B0 */ b lbl_803A6B04 -.global lbl_803A6358 lbl_803A6358: /* 803A6358 003A32B8 38 00 00 00 */ li r0, 0 /* 803A635C 003A32BC 90 1F 01 A4 */ stw r0, 0x1a4(r31) @@ -4515,7 +4491,6 @@ lbl_803A639C: /* 803A63B4 003A3314 4B FF C6 11 */ bl mcmdWait /* 803A63B8 003A3318 7C 7E 1B 78 */ mr r30, r3 /* 803A63BC 003A331C 48 00 07 48 */ b lbl_803A6B04 -.global lbl_803A63C0 lbl_803A63C0: /* 803A63C0 003A3320 57 40 C2 3E */ srwi r0, r26, 8 /* 803A63C4 003A3324 90 1F 01 28 */ stw r0, 0x128(r31) @@ -4531,13 +4506,11 @@ lbl_803A63C0: /* 803A63EC 003A334C 7F E3 FB 78 */ mr r3, r31 /* 803A63F0 003A3350 4B FF D0 C5 */ bl DoSetPitch /* 803A63F4 003A3354 48 00 07 10 */ b lbl_803A6B04 -.global lbl_803A63F8 lbl_803A63F8: /* 803A63F8 003A3358 7F E3 FB 78 */ mr r3, r31 /* 803A63FC 003A335C 38 8D AE E0 */ addi r4, r13, "cstep$1643"@sda21 /* 803A6400 003A3360 4B FF D5 D9 */ bl mcmdSetPitchADSR /* 803A6404 003A3364 48 00 07 00 */ b lbl_803A6B04 -.global lbl_803A6408 lbl_803A6408: /* 803A6408 003A3368 57 40 46 3F */ rlwinm. r0, r26, 8, 0x18, 0x1f /* 803A640C 003A336C 57 43 C4 3E */ rlwinm r3, r26, 0x18, 0x10, 0x1f @@ -4565,7 +4538,6 @@ lbl_803A6454: /* 803A6458 003A33B8 60 00 10 00 */ ori r0, r0, 0x1000 /* 803A645C 003A33BC 90 1F 01 14 */ stw r0, 0x114(r31) /* 803A6460 003A33C0 48 00 06 A4 */ b lbl_803A6B04 -.global lbl_803A6464 lbl_803A6464: /* 803A6464 003A33C4 57 40 C2 3E */ srwi r0, r26, 8 /* 803A6468 003A33C8 7C 00 07 74 */ extsb r0, r0 @@ -4601,7 +4573,6 @@ lbl_803A64B4: /* 803A64DC 003A343C 7C 00 20 50 */ subf r0, r0, r4 /* 803A64E0 003A3440 B0 1F 01 50 */ sth r0, 0x150(r31) /* 803A64E4 003A3444 48 00 06 20 */ b lbl_803A6B04 -.global lbl_803A64E8 lbl_803A64E8: /* 803A64E8 003A3448 57 40 C4 3E */ rlwinm r0, r26, 0x18, 0x10, 0x1f /* 803A64EC 003A344C C0 02 D5 8C */ lfs f0, lbl_805AF2AC@sda21(r2) @@ -4610,7 +4581,6 @@ lbl_803A64E8: /* 803A64F8 003A3458 B0 1F 01 6E */ sth r0, 0x16e(r31) /* 803A64FC 003A345C D0 1F 01 68 */ stfs f0, 0x168(r31) /* 803A6500 003A3460 48 00 06 04 */ b lbl_803A6B04 -.global lbl_803A6504 lbl_803A6504: /* 803A6504 003A3464 88 1F 00 8C */ lbz r0, 0x8c(r31) /* 803A6508 003A3468 28 00 00 00 */ cmplwi r0, 0 @@ -4633,14 +4603,12 @@ lbl_803A6504: /* 803A654C 003A34AC 38 03 FF FF */ addi r0, r3, -1 /* 803A6550 003A34B0 98 1F 00 8C */ stb r0, 0x8c(r31) /* 803A6554 003A34B4 48 00 05 B0 */ b lbl_803A6B04 -.global lbl_803A6558 lbl_803A6558: /* 803A6558 003A34B8 7F E3 FB 78 */ mr r3, r31 /* 803A655C 003A34BC 38 8D AE E0 */ addi r4, r13, "cstep$1643"@sda21 /* 803A6560 003A34C0 4B FF C7 55 */ bl mcmdGosub /* 803A6564 003A34C4 7C 7E 1B 78 */ mr r30, r3 /* 803A6568 003A34C8 48 00 05 9C */ b lbl_803A6B04 -.global lbl_803A656C lbl_803A656C: /* 803A656C 003A34CC 57 43 84 3E */ srwi r3, r26, 0x10 /* 803A6570 003A34D0 4B FF BF 8D */ bl dataGetMacro @@ -4672,7 +4640,6 @@ lbl_803A656C: /* 803A65D8 003A3538 60 80 04 00 */ ori r0, r4, 0x400 /* 803A65DC 003A353C 90 1F 01 14 */ stw r0, 0x114(r31) /* 803A65E0 003A3540 48 00 05 24 */ b lbl_803A6B04 -.global lbl_803A65E4 lbl_803A65E4: /* 803A65E4 003A3544 57 43 D5 BA */ rlwinm r3, r26, 0x1a, 0x16, 0x1d /* 803A65E8 003A3548 38 80 00 00 */ li r4, 0 @@ -4693,13 +4660,11 @@ lbl_803A6610: /* 803A661C 003A357C 38 00 00 00 */ li r0, 0 /* 803A6620 003A3580 98 1F 00 68 */ stb r0, 0x68(r31) /* 803A6624 003A3584 48 00 04 E0 */ b lbl_803A6B04 -.global lbl_803A6628 lbl_803A6628: /* 803A6628 003A3588 7F E3 FB 78 */ mr r3, r31 /* 803A662C 003A358C 38 8D AE E0 */ addi r4, r13, "cstep$1643"@sda21 /* 803A6630 003A3590 4B FF F1 FD */ bl mcmdSendMessage /* 803A6634 003A3594 48 00 04 D0 */ b lbl_803A6B04 -.global lbl_803A6638 lbl_803A6638: /* 803A6638 003A3598 88 1F 03 EC */ lbz r0, 0x3ec(r31) /* 803A663C 003A359C 38 A0 00 00 */ li r5, 0 @@ -4731,13 +4696,11 @@ lbl_803A6690: /* 803A669C 003A35FC 7C 60 22 14 */ add r3, r0, r4 /* 803A66A0 003A3600 90 A3 FF C0 */ stw r5, -0x40(r3) /* 803A66A4 003A3604 48 00 04 60 */ b lbl_803A6B04 -.global lbl_803A66A8 lbl_803A66A8: /* 803A66A8 003A3608 7F E3 FB 78 */ mr r3, r31 /* 803A66AC 003A360C 38 8D AE E0 */ addi r4, r13, "cstep$1643"@sda21 /* 803A66B0 003A3610 4B FF F3 C1 */ bl mcmdGetVID /* 803A66B4 003A3614 48 00 04 50 */ b lbl_803A6B04 -.global lbl_803A66B8 lbl_803A66B8: /* 803A66B8 003A3618 80 7F 01 10 */ lwz r3, 0x110(r31) /* 803A66BC 003A361C 57 40 84 3E */ srwi r0, r26, 0x10 @@ -4769,7 +4732,6 @@ lbl_803A6704: /* 803A6718 003A3678 50 A4 C0 0E */ rlwimi r4, r5, 0x18, 0, 7 /* 803A671C 003A367C 48 00 CA A9 */ bl hwSetPriority /* 803A6720 003A3680 48 00 03 E4 */ b lbl_803A6B04 -.global lbl_803A6724 lbl_803A6724: /* 803A6724 003A3684 57 40 F8 60 */ rlwinm r0, r26, 0x1f, 1, 0x10 /* 803A6728 003A3688 90 1F 01 10 */ stw r0, 0x110(r31) @@ -4781,7 +4743,6 @@ lbl_803A6724: /* 803A6740 003A36A0 50 A4 C0 0E */ rlwimi r4, r5, 0x18, 0, 7 /* 803A6744 003A36A4 48 00 CA 81 */ bl hwSetPriority /* 803A6748 003A36A8 48 00 03 BC */ b lbl_803A6B04 -.global lbl_803A674C lbl_803A674C: /* 803A674C 003A36AC 3C 60 80 55 */ lis r3, synthGlobalVariable@ha /* 803A6750 003A36B0 57 44 86 3E */ rlwinm r4, r26, 0x10, 0x18, 0x1f @@ -4789,7 +4750,6 @@ lbl_803A674C: /* 803A6758 003A36B8 38 63 0A B4 */ addi r3, r3, synthGlobalVariable@l /* 803A675C 003A36BC 7C 83 01 2E */ stwx r4, r3, r0 /* 803A6760 003A36C0 48 00 03 A4 */ b lbl_803A6B04 -.global lbl_803A6764 lbl_803A6764: /* 803A6764 003A36C4 57 40 86 3E */ rlwinm r0, r26, 0x10, 0x18, 0x1f /* 803A6768 003A36C8 98 1F 01 D6 */ stb r0, 0x1d6(r31) @@ -4797,7 +4757,6 @@ lbl_803A6764: /* 803A6770 003A36D0 54 00 C6 3E */ rlwinm r0, r0, 0x18, 0x18, 0x1f /* 803A6774 003A36D4 98 1F 01 D7 */ stb r0, 0x1d7(r31) /* 803A6778 003A36D8 48 00 03 8C */ b lbl_803A6B04 -.global lbl_803A677C lbl_803A677C: /* 803A677C 003A36DC 57 40 C6 3E */ rlwinm r0, r26, 0x18, 0x18, 0x1f /* 803A6780 003A36E0 98 1F 01 90 */ stb r0, 0x190(r31) @@ -4805,20 +4764,17 @@ lbl_803A677C: /* 803A6788 003A36E8 54 00 86 3E */ rlwinm r0, r0, 0x10, 0x18, 0x1f /* 803A678C 003A36EC 98 1F 01 91 */ stb r0, 0x191(r31) /* 803A6790 003A36F0 48 00 03 74 */ b lbl_803A6B04 -.global lbl_803A6794 lbl_803A6794: /* 803A6794 003A36F4 80 9F 01 18 */ lwz r4, 0x118(r31) /* 803A6798 003A36F8 3C 00 00 01 */ lis r0, 1 /* 803A679C 003A36FC 7C 80 03 78 */ or r0, r4, r0 /* 803A67A0 003A3700 90 1F 01 18 */ stw r0, 0x118(r31) /* 803A67A4 003A3704 48 00 03 60 */ b lbl_803A6B04 -.global lbl_803A67A8 lbl_803A67A8: /* 803A67A8 003A3708 7F E3 FB 78 */ mr r3, r31 /* 803A67AC 003A370C 57 44 C6 3E */ rlwinm r4, r26, 0x18, 0x18, 0x1f /* 803A67B0 003A3710 48 00 14 49 */ bl voiceSetPriority /* 803A67B4 003A3714 48 00 03 50 */ b lbl_803A6B04 -.global lbl_803A67B8 lbl_803A67B8: /* 803A67B8 003A3718 57 40 84 3E */ srwi r0, r26, 0x10 /* 803A67BC 003A371C 88 9F 01 0C */ lbz r4, 0x10c(r31) @@ -4838,7 +4794,6 @@ lbl_803A67EC: /* 803A67EC 003A374C 54 04 06 3E */ clrlwi r4, r0, 0x18 /* 803A67F0 003A3750 48 00 14 09 */ bl voiceSetPriority /* 803A67F4 003A3754 48 00 03 10 */ b lbl_803A6B04 -.global lbl_803A67F8 lbl_803A67F8: /* 803A67F8 003A3758 80 7C 00 04 */ lwz r3, 4(r28) /* 803A67FC 003A375C 28 03 00 00 */ cmplwi r3, 0 @@ -4852,7 +4807,6 @@ lbl_803A6818: /* 803A6818 003A3778 38 00 00 00 */ li r0, 0 /* 803A681C 003A377C B0 1F 01 0E */ sth r0, 0x10e(r31) /* 803A6820 003A3780 48 00 02 E4 */ b lbl_803A6B04 -.global lbl_803A6824 lbl_803A6824: /* 803A6824 003A3784 80 9F 01 54 */ lwz r4, 0x154(r31) /* 803A6828 003A3788 57 45 84 3E */ srwi r5, r26, 0x10 @@ -4876,97 +4830,81 @@ lbl_803A6854: /* 803A686C 003A37CC 50 A4 C0 0E */ rlwimi r4, r5, 0x18, 0, 7 /* 803A6870 003A37D0 48 00 C9 55 */ bl hwSetPriority /* 803A6874 003A37D4 48 00 02 90 */ b lbl_803A6B04 -.global lbl_803A6878 lbl_803A6878: /* 803A6878 003A37D8 7F E3 FB 78 */ mr r3, r31 /* 803A687C 003A37DC 38 8D AE E0 */ addi r4, r13, "cstep$1643"@sda21 /* 803A6880 003A37E0 4B FF DA 49 */ bl mcmdVolumeSelect /* 803A6884 003A37E4 48 00 02 80 */ b lbl_803A6B04 -.global lbl_803A6888 lbl_803A6888: /* 803A6888 003A37E8 7F E3 FB 78 */ mr r3, r31 /* 803A688C 003A37EC 38 8D AE E0 */ addi r4, r13, "cstep$1643"@sda21 /* 803A6890 003A37F0 4B FF DB 3D */ bl mcmdPanningSelect /* 803A6894 003A37F4 48 00 02 70 */ b lbl_803A6B04 -.global lbl_803A6898 lbl_803A6898: /* 803A6898 003A37F8 7F E3 FB 78 */ mr r3, r31 /* 803A689C 003A37FC 38 8D AE E0 */ addi r4, r13, "cstep$1643"@sda21 /* 803A68A0 003A3800 4B FF DC 31 */ bl mcmdPitchWheelSelect /* 803A68A4 003A3804 48 00 02 60 */ b lbl_803A6B04 -.global lbl_803A68A8 lbl_803A68A8: /* 803A68A8 003A3808 7F E3 FB 78 */ mr r3, r31 /* 803A68AC 003A380C 38 8D AE E0 */ addi r4, r13, "cstep$1643"@sda21 /* 803A68B0 003A3810 4B FF DD 25 */ bl mcmdModWheelSelect /* 803A68B4 003A3814 48 00 02 50 */ b lbl_803A6B04 -.global lbl_803A68B8 lbl_803A68B8: /* 803A68B8 003A3818 7F E3 FB 78 */ mr r3, r31 /* 803A68BC 003A381C 38 8D AE E0 */ addi r4, r13, "cstep$1643"@sda21 /* 803A68C0 003A3820 4B FF DE 19 */ bl mcmdPedalSelect /* 803A68C4 003A3824 48 00 02 40 */ b lbl_803A6B04 -.global lbl_803A68C8 lbl_803A68C8: /* 803A68C8 003A3828 7F E3 FB 78 */ mr r3, r31 /* 803A68CC 003A382C 38 8D AE E0 */ addi r4, r13, "cstep$1643"@sda21 /* 803A68D0 003A3830 4B FF DF 0D */ bl mcmdPortamentoSelect /* 803A68D4 003A3834 48 00 02 30 */ b lbl_803A6B04 -.global lbl_803A68D8 lbl_803A68D8: /* 803A68D8 003A3838 7F E3 FB 78 */ mr r3, r31 /* 803A68DC 003A383C 38 8D AE E0 */ addi r4, r13, "cstep$1643"@sda21 /* 803A68E0 003A3840 4B FF E0 01 */ bl mcmdReverbSelect /* 803A68E4 003A3844 48 00 02 20 */ b lbl_803A6B04 -.global lbl_803A68E8 lbl_803A68E8: /* 803A68E8 003A3848 7F E3 FB 78 */ mr r3, r31 /* 803A68EC 003A384C 38 8D AE E0 */ addi r4, r13, "cstep$1643"@sda21 -/* 803A68F0 003A3850 4B FF E4 01 */ bl mcmdSurroundingPanningSelect +/* 803A68F0 003A3850 4B FF E4 01 */ bl mcmdSurroundPanningSelect /* 803A68F4 003A3854 48 00 02 10 */ b lbl_803A6B04 -.global lbl_803A68F8 lbl_803A68F8: /* 803A68F8 003A3858 7F E3 FB 78 */ mr r3, r31 /* 803A68FC 003A385C 38 8D AE E0 */ addi r4, r13, "cstep$1643"@sda21 /* 803A6900 003A3860 4B FF E4 F5 */ bl mcmdDopplerSelect /* 803A6904 003A3864 48 00 02 00 */ b lbl_803A6B04 -.global lbl_803A6908 lbl_803A6908: /* 803A6908 003A3868 7F E3 FB 78 */ mr r3, r31 /* 803A690C 003A386C 38 8D AE E0 */ addi r4, r13, "cstep$1643"@sda21 /* 803A6910 003A3870 4B FF E5 E9 */ bl mcmdTremoloSelect /* 803A6914 003A3874 48 00 01 F0 */ b lbl_803A6B04 -.global lbl_803A6918 lbl_803A6918: /* 803A6918 003A3878 7F E3 FB 78 */ mr r3, r31 /* 803A691C 003A387C 38 8D AE E0 */ addi r4, r13, "cstep$1643"@sda21 /* 803A6920 003A3880 4B FF E0 C5 */ bl mcmdPreAuxASelect /* 803A6924 003A3884 48 00 01 E0 */ b lbl_803A6B04 -.global lbl_803A6928 lbl_803A6928: /* 803A6928 003A3888 7F E3 FB 78 */ mr r3, r31 /* 803A692C 003A388C 38 8D AE E0 */ addi r4, r13, "cstep$1643"@sda21 /* 803A6930 003A3890 4B FF E1 B9 */ bl mcmdPreAuxBSelect /* 803A6934 003A3894 48 00 01 D0 */ b lbl_803A6B04 -.global lbl_803A6938 lbl_803A6938: /* 803A6938 003A3898 7F E3 FB 78 */ mr r3, r31 /* 803A693C 003A389C 38 8D AE E0 */ addi r4, r13, "cstep$1643"@sda21 /* 803A6940 003A38A0 4B FF E2 AD */ bl mcmdPostAuxBSelect /* 803A6944 003A38A4 48 00 01 C0 */ b lbl_803A6B04 -.global lbl_803A6948 lbl_803A6948: /* 803A6948 003A38A8 7F E3 FB 78 */ mr r3, r31 /* 803A694C 003A38AC 38 8D AE E0 */ addi r4, r13, "cstep$1643"@sda21 /* 803A6950 003A38B0 4B FF E6 AD */ bl mcmdAuxAFXSelect /* 803A6954 003A38B4 48 00 01 B0 */ b lbl_803A6B04 -.global lbl_803A6958 lbl_803A6958: /* 803A6958 003A38B8 7F E3 FB 78 */ mr r3, r31 /* 803A695C 003A38BC 38 8D AE E0 */ addi r4, r13, "cstep$1643"@sda21 /* 803A6960 003A38C0 4B FF E8 19 */ bl mcmdAuxBFXSelect /* 803A6964 003A38C4 48 00 01 A0 */ b lbl_803A6B04 -.global lbl_803A6968 lbl_803A6968: /* 803A6968 003A38C8 57 40 84 3E */ srwi r0, r26, 0x10 /* 803A696C 003A38CC 38 61 00 08 */ addi r3, r1, 8 @@ -4989,7 +4927,6 @@ lbl_803A69AC: /* 803A69AC 003A390C 80 01 00 08 */ lwz r0, 8(r1) /* 803A69B0 003A3910 90 19 01 C0 */ stw r0, 0x1c0(r25) /* 803A69B4 003A3914 48 00 01 50 */ b lbl_803A6B04 -.global lbl_803A69B8 lbl_803A69B8: /* 803A69B8 003A3918 57 43 C6 3E */ rlwinm r3, r26, 0x18, 0x18, 0x1f /* 803A69BC 003A391C 7C 03 00 D0 */ neg r0, r3 @@ -5002,13 +4939,11 @@ lbl_803A69B8: /* 803A69D8 003A3938 54 00 DE 3E */ rlwinm r0, r0, 0x1b, 0x18, 0x1f /* 803A69DC 003A393C 98 1F 01 93 */ stb r0, 0x193(r31) /* 803A69E0 003A3940 48 00 01 24 */ b lbl_803A6B04 -.global lbl_803A69E4 lbl_803A69E4: /* 803A69E4 003A3944 7F E3 FB 78 */ mr r3, r31 /* 803A69E8 003A3948 38 8D AE E0 */ addi r4, r13, "cstep$1643"@sda21 /* 803A69EC 003A394C 4B FF F1 05 */ bl mcmdSetKeyGroup /* 803A69F0 003A3950 48 00 01 14 */ b lbl_803A6B04 -.global lbl_803A69F4 lbl_803A69F4: /* 803A69F4 003A3954 80 1F 00 F4 */ lwz r0, 0xf4(r31) /* 803A69F8 003A3958 57 44 C6 3E */ rlwinm r4, r26, 0x18, 0x18, 0x1f @@ -5023,42 +4958,36 @@ lbl_803A69F4: /* 803A6A1C 003A397C 60 00 08 00 */ ori r0, r0, 0x800 /* 803A6A20 003A3980 90 1F 01 14 */ stw r0, 0x114(r31) /* 803A6A24 003A3984 48 00 00 E0 */ b lbl_803A6B04 -.global lbl_803A6A28 lbl_803A6A28: /* 803A6A28 003A3988 7F E3 FB 78 */ mr r3, r31 /* 803A6A2C 003A398C 38 8D AE E0 */ addi r4, r13, "cstep$1643"@sda21 /* 803A6A30 003A3990 38 A0 00 00 */ li r5, 0 /* 803A6A34 003A3994 4B FF EA 8D */ bl mcmdVarCalculation /* 803A6A38 003A3998 48 00 00 CC */ b lbl_803A6B04 -.global lbl_803A6A3C lbl_803A6A3C: /* 803A6A3C 003A399C 7F E3 FB 78 */ mr r3, r31 /* 803A6A40 003A39A0 38 8D AE E0 */ addi r4, r13, "cstep$1643"@sda21 /* 803A6A44 003A39A4 38 A0 00 01 */ li r5, 1 /* 803A6A48 003A39A8 4B FF EA 79 */ bl mcmdVarCalculation /* 803A6A4C 003A39AC 48 00 00 B8 */ b lbl_803A6B04 -.global lbl_803A6A50 lbl_803A6A50: /* 803A6A50 003A39B0 7F E3 FB 78 */ mr r3, r31 /* 803A6A54 003A39B4 38 8D AE E0 */ addi r4, r13, "cstep$1643"@sda21 /* 803A6A58 003A39B8 38 A0 00 02 */ li r5, 2 /* 803A6A5C 003A39BC 4B FF EA 65 */ bl mcmdVarCalculation /* 803A6A60 003A39C0 48 00 00 A4 */ b lbl_803A6B04 -.global lbl_803A6A64 lbl_803A6A64: /* 803A6A64 003A39C4 7F E3 FB 78 */ mr r3, r31 /* 803A6A68 003A39C8 38 8D AE E0 */ addi r4, r13, "cstep$1643"@sda21 /* 803A6A6C 003A39CC 38 A0 00 03 */ li r5, 3 /* 803A6A70 003A39D0 4B FF EA 51 */ bl mcmdVarCalculation /* 803A6A74 003A39D4 48 00 00 90 */ b lbl_803A6B04 -.global lbl_803A6A78 lbl_803A6A78: /* 803A6A78 003A39D8 7F E3 FB 78 */ mr r3, r31 /* 803A6A7C 003A39DC 38 8D AE E0 */ addi r4, r13, "cstep$1643"@sda21 /* 803A6A80 003A39E0 38 A0 00 04 */ li r5, 4 /* 803A6A84 003A39E4 4B FF EA 3D */ bl mcmdVarCalculation /* 803A6A88 003A39E8 48 00 00 7C */ b lbl_803A6B04 -.global lbl_803A6A8C lbl_803A6A8C: /* 803A6A8C 003A39EC 80 7C 00 04 */ lwz r3, 4(r28) /* 803A6A90 003A39F0 57 40 C6 3F */ rlwinm. r0, r26, 0x18, 0x18, 0x1f @@ -5083,20 +5012,17 @@ lbl_803A6AC8: /* 803A6AD4 003A3A34 7C 60 22 14 */ add r3, r0, r4 /* 803A6AD8 003A3A38 90 A3 FF C0 */ stw r5, -0x40(r3) /* 803A6ADC 003A3A3C 48 00 00 28 */ b lbl_803A6B04 -.global lbl_803A6AE0 lbl_803A6AE0: /* 803A6AE0 003A3A40 7F E3 FB 78 */ mr r3, r31 /* 803A6AE4 003A3A44 38 8D AE E0 */ addi r4, r13, "cstep$1643"@sda21 /* 803A6AE8 003A3A48 38 A0 00 00 */ li r5, 0 /* 803A6AEC 003A3A4C 4B FF EB F5 */ bl mcmdIfVarCompare /* 803A6AF0 003A3A50 48 00 00 14 */ b lbl_803A6B04 -.global lbl_803A6AF4 lbl_803A6AF4: /* 803A6AF4 003A3A54 7F E3 FB 78 */ mr r3, r31 /* 803A6AF8 003A3A58 38 8D AE E0 */ addi r4, r13, "cstep$1643"@sda21 /* 803A6AFC 003A3A5C 38 A0 00 01 */ li r5, 1 /* 803A6B00 003A3A60 4B FF EB E1 */ bl mcmdIfVarCompare -.global lbl_803A6B04 lbl_803A6B04: /* 803A6B04 003A3A64 28 1E 00 00 */ cmplwi r30, 0 /* 803A6B08 003A3A68 41 82 F3 30 */ beq lbl_803A5E38 diff --git a/configure.py b/configure.py index 6933f49f..4ecfbf89 100755 --- a/configure.py +++ b/configure.py @@ -920,9 +920,9 @@ LIBS = [ { "lib": "musyx", #"mw_version": "1.2.5", - #"cflags": "-proc gecko -fp hard -nodefaults -nosyspath -i include -i libc -g -sym on -D_DEBUG=1 -enum int ", + #"cflags": "-proc gecko -fp hard -nodefaults -nosyspath -i include -i libc -g -sym on -D_DEBUG=1 -enum int -DMUSY_VERSION_MAJOR=1 -DMUSY_VERSION_MINOR=5 -DMUSY_VERSION_PATCH=3", "mw_version": "1.3.2", - "cflags": "$cflags_musyx", + "cflags": "$cflags_musyx -DMUSY_VERSION_MAJOR=1 -DMUSY_VERSION_MINOR=5 -DMUSY_VERSION_PATCH=4", "host": False, "objects": [ "musyx/runtime/seq", @@ -951,7 +951,7 @@ LIBS = [ ["musyx/runtime/hw_dolphin", True], ["musyx/runtime/hw_memory", True], ["musyx/runtime/CheapReverb/creverb_fx", True], - "musyx/runtime/CheapReverb/creverb", + ["musyx/runtime/CheapReverb/creverb", False], ["musyx/runtime/StdReverb/reverb_fx", True], ["musyx/runtime/StdReverb/reverb", False], ["musyx/runtime/Delay/delay_fx", True], diff --git a/include/musyx/assert.h b/include/musyx/assert.h index b5f5b76d..451e6a21 100644 --- a/include/musyx/assert.h +++ b/include/musyx/assert.h @@ -4,29 +4,42 @@ extern void OSPanic(const char* file, int line, const char* msg, ...); extern void OSReport(const char* msg, ...); +static inline unsigned __SOME_ASSERT_DERP1() { + return 0; +} + +static inline unsigned __SOME_ASSERT_DERP2() { + return __SOME_ASSERT_DERP1(); +} + +static inline void __SOME_ASSERT_DERP() { + __SOME_ASSERT_DERP2() != 0; +} + #ifndef ASSERT #ifdef _DEBUG -#define ASSERT(cond) \ +#define MUSY_ASSERT(cond) \ do { \ if (!(cond)) { \ OSPanic(__FILE__, __LINE__, "Failed assertion " #cond); \ } \ + __SOME_ASSERT_DERP(); \ } while(0) #else -#define ASSERT(cond) +#define MUSY_ASSERT(cond) #endif #endif -#ifndef ASSERT_MSG +#ifndef MUSY_ASSERT_MSG #ifdef _DEBUG -#define ASSERT_MSG(cond, msg) \ +#define MUSY_ASSERT_MSG(cond, msg) \ do { \ if (!(cond)) { \ OSPanic(__FILE__, __LINE__, msg); \ } \ } while(0) #else -#define ASSERT_MSG(cond, msg) +#define MUSY_ASSERT_MSG(cond, msg) #endif #endif diff --git a/include/musyx/musyx.h b/include/musyx/musyx.h index 486adf79..e4979b0c 100644 --- a/include/musyx/musyx.h +++ b/include/musyx/musyx.h @@ -1,6 +1,8 @@ #ifndef _MUSYX_MUSYX #define _MUSYX_MUSYX +#include "musyx/version.h" + #include #ifdef __cplusplus diff --git a/include/musyx/musyx_priv.h b/include/musyx/musyx_priv.h index d60dcdd8..d884d970 100644 --- a/include/musyx/musyx_priv.h +++ b/include/musyx/musyx_priv.h @@ -1,6 +1,7 @@ #ifndef _MUSYX_MUSYX_PRIV #define _MUSYX_MUSYX_PRIV +#include "musyx/assert.h" #include "musyx/musyx.h" #ifdef __cplusplus @@ -857,6 +858,7 @@ u32 dataRemoveMacro(u16 mid); u32 dataInsertCurve(u16 cid, void* curvedata); u32 dataRemoveCurve(u16 sid); long dataGetSample(u16 sid, SAMPLE_INFO* newsmp); +void* dataGetCurve(u16 cid); u32 dataAddSampleReference(u16 sid); u32 dataRemoveSampleReference(u16 sid); u32 dataInsertKeymap(u16 cid, void* keymapdata); @@ -884,14 +886,16 @@ void s3dKillEmitterByFXID(FX_TAB* fxTab, unsigned long num); void s3dExit(); void synthInit(u32, u8); /* extern */ void synthFXCloneMidiSetup(SYNTH_VOICE* dest, SYNTH_VOICE* src); + extern u32 synthGlobalVariable[16]; -extern s16 voicePrioSortRootListRoot; +extern u16 voicePrioSortRootListRoot; extern u8 voiceMusicRunning; extern u8 voiceFxRunning; extern u8 voiceListInsert; extern u8 voiceListRoot; void voiceSetPriority(struct SYNTH_VOICE* svoice, unsigned char prio); u32 voiceIsLastStarted(struct SYNTH_VOICE* svoice); +s32 voiceKillSound(u32 voiceid); u32 synthGetTicksPerSecond(SYNTH_VOICE* svoice); void synthKillVoicesByMacroReferences(u16* ref); @@ -916,6 +920,7 @@ typedef s32 (*SND_MESSAGE_CALLBACK)(u32, u32); typedef void (*SND_SOME_CALLBACK)(); extern SND_MESSAGE_CALLBACK salMessageCallback; +extern SND_MESSAGE_CALLBACK synthMessageCallback; /* Math */ void salApplyMatrix(const SND_FMATRIX* a, const SND_FVECTOR* b, SND_FVECTOR* out); float salNormalizeVector(SND_FVECTOR* vec); @@ -960,8 +965,13 @@ typedef struct SND_STREAM_INFO { } SND_STREAM_INFO; void streamOutputModeChanged(); -void inpSetExCtrl(struct SYNTH_VOICE* svoice, unsigned char ctrl, signed short v); +void inpSetGlobalMIDIDirtyFlag(u8 chan, u8 midiSet, s32 flag); +void inpAddCtrl(struct CTRL_DEST* dest, unsigned char ctrl, long scale, unsigned char comb, + unsigned long isVar); +void inpSetExCtrl(SYNTH_VOICE* svoice, unsigned char ctrl, signed short v); CHANNEL_DEFAULTS* inpGetChannelDefaults(unsigned char midi, unsigned char midiSet); +extern CTRL_DEST inpAuxA[8][4]; +extern CTRL_DEST inpAuxB[8][4]; void inpSetMidiLastNote(u8 midi, u8 midiSet, u8 key); u8 inpGetMidiLastNote(u8 midi, u8 midiSet); unsigned short inpGetExCtrl(SYNTH_VOICE* svoice, unsigned char ctrl); diff --git a/include/musyx/synth.h b/include/musyx/synth.h index 32e48682..94d49692 100644 --- a/include/musyx/synth.h +++ b/include/musyx/synth.h @@ -18,7 +18,7 @@ extern void* synthAuxBUser[8]; extern u8 synthITDDefault[16]; extern u32 synthFlags; -s32 vidGetInternalId(SND_VOICEID id); +u32 vidGetInternalId(SND_VOICEID id); bool synthFXSetCtrl(SND_VOICEID vid, u8 ctrl, u8 value); bool synthFXSetCtrl14(SND_VOICEID vid, u8 ctrl, u16 value); bool synthSendKeyOff(SND_VOICEID vid); diff --git a/include/musyx/version.h b/include/musyx/version.h new file mode 100644 index 00000000..69d59cfd --- /dev/null +++ b/include/musyx/version.h @@ -0,0 +1,26 @@ +#ifndef _MUSYX_VERSION +#define _MUSYX_VERSION + + +#ifndef MUSY_VERSION_CHECK +#define MUSY_VERSION_CHECK(major, minor, patch) ((major << 16) | (minor << 8) | (patch)) +#endif + +#ifndef MUSY_VERSION_MAJOR +#define MUSY_VERSION_MAJOR 1 +#endif + +#ifndef MUSY_VERSION_MINOR +#define MUSY_VERSION_MINOR 5 +#endif + +#ifndef MUSY_VERSION_PATCH +#define MUSY_VERSION_PATCH 3 +#endif + + +#ifndef MUSY_VERSION +#define MUSY_VERSION MUSY_VERSION_CHECK(MUSY_VERSION_MAJOR, MUSY_VERSION_MINOR, MUSY_VERSION_PATCH) +#endif + +#endif // _MUSYX_VERSION diff --git a/libc/math.h b/libc/math.h index 1bc6d7f6..5dd235a0 100644 --- a/libc/math.h +++ b/libc/math.h @@ -160,7 +160,7 @@ static inline int __fpclassifyd(double x) { #define isinf(x) (fpclassify(x) == FP_INFINITE) #define isfinite(x) ((fpclassify(x) > FP_INFINITE)) -static float sqrtf(float x) { +static inline float sqrtf(float x) { const double _half = .5; const double _three = 3.0; volatile float y; @@ -179,7 +179,7 @@ static float sqrtf(float x) { return x; } -static double sqrt(double x) { +static inline double sqrt(double x) { if (x > 0.0) { double guess = __frsqrte(x); /* returns an approximation to */ guess = .5 * guess * (3.0 - guess * guess * x); /* now have 8 sig bits */ diff --git a/src/musyx/runtime/CheapReverb/creverb.c b/src/musyx/runtime/CheapReverb/creverb.c new file mode 100644 index 00000000..dd9f31f9 --- /dev/null +++ b/src/musyx/runtime/CheapReverb/creverb.c @@ -0,0 +1,31 @@ +/* --------------------------------------- + + + + + + + + + --------------------------------------- +*/ +#include "musyx/musyx_priv.h" + +static void DLsetdelay(_SND_REVSTD_DELAYLINE * dl, s32 lag) { + dl->outPoint = dl->inPoint - (lag * sizeof(f32)); + while (dl->outPoint < 0) { + dl->outPoint += dl->length; + } +} + +static void DLcreate(_SND_REVSTD_DELAYLINE* dl, s32 len) { + dl->length = len * sizeof(f32); + dl->inputs = (f32*)salMalloc(len * sizeof(f32)); + memset(dl->inputs, 0, len * sizeof(len)); + dl->lastOutput = 0.f; + DLsetdelay(dl, len >> 1); + dl->inPoint = 0; + dl->outPoint = 0; +} + +static void DLdelete(_SND_REVSTD_DELAYLINE* dl) { salFree(dl->inputs); } diff --git a/src/musyx/runtime/CheapReverb/creverb_fx.c b/src/musyx/runtime/CheapReverb/creverb_fx.c index a6293a8c..64739073 100644 --- a/src/musyx/runtime/CheapReverb/creverb_fx.c +++ b/src/musyx/runtime/CheapReverb/creverb_fx.c @@ -1,26 +1,46 @@ +/* --------------------------------------- + + + + + + + + + --------------------------------------- +*/ + #include "musyx/musyx_priv.h" extern bool ReverbSTDCreate(_SND_REVSTD_WORK* rv, f32 coloration, f32 time, f32 mix, f32 damping, f32 preDelay); extern void ReverbHIFree(_SND_REVSTD_WORK* rev); extern void ReverbSTDCallback(s32* left, s32* right, s32* surround, _SND_REVSTD_WORK* rv); +extern unsigned long ReverbSTDModify(_SND_REVSTD_WORK* rv, float coloration, float time, float mix, + float damping, float predelay); void sndAuxCallbackReverbSTD(u8 reason, SND_AUX_INFO* info, void* user) { - SND_AUX_REVERBSTD* rev; switch (reason) { case SND_AUX_REASON_BUFFERUPDATE: - rev = (SND_AUX_REVERBSTD*)user; - if ((u8)rev->tempDisableFX == 0) { + if ((u8)((SND_AUX_REVERBSTD*)user)->tempDisableFX == 0) { ReverbSTDCallback(info->data.bufferUpdate.left, info->data.bufferUpdate.right, - info->data.bufferUpdate.surround, &rev->rv); + info->data.bufferUpdate.surround, &((SND_AUX_REVERBSTD*)user)->rv); } + break; case SND_AUX_REASON_PARAMETERUPDATE: + // UNIMPLEMENTED break; default: - // ASSERT_MSG(FALSE); + MUSY_ASSERT(FALSE); break; } } +bool sndAuxCallbackUpdateSettingsReverbSTD(SND_AUX_REVERBSTD* rev) { + rev->tempDisableFX = TRUE; + ReverbSTDModify(&rev->rv, rev->coloration, rev->time, rev->mix, rev->damping, rev->preDelay); + rev->tempDisableFX = FALSE; + return TRUE; +} bool sndAuxCallbackPrepareReverbSTD(SND_AUX_REVERBSTD* rev) { rev->tempDisableFX = 0; @@ -31,5 +51,3 @@ bool sndAuxCallbackShutdownReverbSTD(SND_AUX_REVERBSTD* rev) { ReverbSTDFree(&rev->rv); return TRUE; } - -bool sndAuxCallbackUpdateSettingsReverbSTD(SND_AUX_REVERBSTD* rev) { return FALSE; } diff --git a/src/musyx/runtime/Chorus/chorus_fx.c b/src/musyx/runtime/Chorus/chorus_fx.c index b1c0135a..4afb8c78 100644 --- a/src/musyx/runtime/Chorus/chorus_fx.c +++ b/src/musyx/runtime/Chorus/chorus_fx.c @@ -109,363 +109,489 @@ static float rsmpTab12khz[512] = { const double i2fMagic = 4.503601774854144E15; -#if NONMATCHING -void do_src1(_SND_CHORUS_SRCINFO* src) { - // TODO: Match this -} -#else -/* clang-format off */ -#pragma push -#pragma optimization_level 0 -#pragma optimizewithasm off -asm void do_src1(_SND_CHORUS_SRCINFO* src) { - nofralloc - stwu r1, -0x40(r1) - stmw r26, 0x28(r1) +static asm void do_src1(_SND_CHORUS_SRCINFO* src) { + nofralloc + + stwu r1, -0x40(sp) + stmw r26, 0x28(sp) + + lwz r4, 0xc(r3) lwz r5, 0x10(r3) + lwz r6, 0x14(r3) + lwz r8, 0x1c(r3) lwz r7, 0x20(r3) + lwz r31, 4(r3) + lwz r30, 0(r3) + lwz r9, 8(r3) + lis r10, 0x4330 - stw r10, 8(r1) - stw r10, 0x10(r1) - stw r10, 0x18(r1) - stw r10, 0x20(r1) + stw r10, 8(sp) + stw r10, 0x10(sp) + stw r10, 0x18(sp) + stw r10, 0x20(sp) + lis r10, i2fMagic@ha lfd f9, i2fMagic@l(r10) + slwi r10, r5, 2 lwz r11, 0(r9) + lwz r29, 4(r9) - lwz r28, 8(r9) + lwz r28, 8(r9) lwzx r27, r31, r10 + xoris r11, r11, 0x8000 - xoris r29, r29, 0x8000 - stw r11, 0xc(r1) + xoris r29, r29, 0x8000 + stw r11, 0xc(sp) xoris r28, r28, 0x8000 - stw r29, 0x14(r1) + stw r29, 0x14(sp) xoris r27, r27, 0x8000 - stw r28, 0x1c(r1) - lfd f1, 8(r1) - stw r27, 0x24(r1) - lfd f2, 0x10(r1) + stw r28, 0x1c(sp) + lfd f1, 8(sp) + stw r27, 0x24(sp) + lfd f2, 0x10(sp) fsubs f1, f1, f9 - lfd f3, 0x18(r1) + lfd f3, 0x18(sp) fsubs f2, f2, f9 - lfd f4, 0x20(r1) + lfd f4, 0x20(sp) fsubs f3, f3, f9 fsubs f4, f4, f9 + li r26, -4 + lis r12, rsmpTab12khz@ha addi r12, r12, rsmpTab12khz@l + li r9, 0xa0 mtctr r9 lbl_803B6D5C: rlwinm r10, r4, 7, 0x15, 0x1b + addc r4, r4, r6 + add r10, r10, r12 + mcrxr cr0 + lfs f5, 0(r10) + beq lbl_803B6DA4 + lfs f6, 4(r10) + fmuls f10, f1, f5 + lfs f7, 8(r10) + fmadds f10, f2, f6, f10 + lfs f8, 0xc(r10) + fmadds f10, f3, f7, f10 + addi r30, r30, 4 + fmadds f10, f4, f8, f10 + fctiwz f10, f10 + stfiwx f10, r26, r30 + bdnz lbl_803B6D5C + b lbl_803B6E10 + + lbl_803B6DA4: addi r5, r5, 1 + lfs f6, 4(r10) + fmuls f10, f1, f5 + cmpw r5, r8 + fmr f1, f2 + lfs f7, 8(r10) + fmadds f10, f2, f6, f10 + fmr f2, f3 + lfs f8, 0xc(r10) + fmadds f10, f3, f7, f10 + addi r30, r30, 4 + fmr f3, f4 + bne+ lbl_803B6DDC mr r5, r7 + lbl_803B6DDC: fmadds f10, f4, f8, f10 + slwi r9, r5, 2 + bdz lbl_803B6E08 + lwzx r10, r9, r31 + fctiwz f10, f10 + xoris r10, r10, 0x8000 - stw r10, 0xc(r1) + + stw r10, 0xc(sp) + stfiwx f10, r26, r30 - lfd f4, 8(r1) + + lfd f4, 8(sp) + fsubs f4, f4, f9 + b lbl_803B6D5C + + lbl_803B6E08: fctiwz f10, f10 stfiwx f10, r26, r30 + + lbl_803B6E10: lwz r9, 8(r3) + fctiwz f1, f1 fctiwz f2, f2 fctiwz f3, f3 + stfiwx f1, r0, r9 addi r10, r9, 4 stfiwx f2, r0, r10 addi r10, r9, 8 stfiwx f3, r0, r10 + stw r4, 0xc(r3) stw r5, 0x10(r3) - lmw r26, 0x28(r1) + + lmw r26, 0x28(sp) addi r1, r1, 0x40 blr } -#pragma pop -/* clang-format on */ -#endif -#if NONMATCHING -void do_src2(_SND_CHORUS_SRCINFO* src) { - // TODO: Match this -} -#else -/* clang-format off */ -#pragma push -#pragma optimization_level 0 -#pragma optimizewithasm off -asm void do_src2(_SND_CHORUS_SRCINFO* src) { - nofralloc - stwu r1, -0x40(r1) - stmw r26, 0x28(r1) - lwz r4, 0xc(r3) - lwz r5, 0x10(r3) - lwz r6, 0x14(r3) - lwz r8, 0x1c(r3) - lwz r7, 0x20(r3) - lwz r31, 4(r3) - lwz r30, 0(r3) - lwz r9, 8(r3) - lis r10, 0x4330 - stw r10, 8(r1) - stw r10, 0x10(r1) - stw r10, 0x18(r1) - stw r10, 0x20(r1) - lis r10, i2fMagic@ha - lfd f9, i2fMagic@l(r10) - slwi r10, r5, 2 - lwz r11, 0(r9) - lwz r29, 4(r9) - lwz r28, 8(r9) - lwzx r27, r31, r10 - xoris r11, r11, 0x8000 - xoris r29, r29, 0x8000 - stw r11, 0xc(r1) - xoris r28, r28, 0x8000 - stw r29, 0x14(r1) - xoris r27, r27, 0x8000 - stw r28, 0x1c(r1) - lfd f1, 8(r1) - stw r27, 0x24(r1) - lfd f2, 0x10(r1) - fsubs f1, f1, f9 - lfd f3, 0x18(r1) - fsubs f2, f2, f9 - lfd f4, 0x20(r1) - fsubs f3, f3, f9 - fsubs f4, f4, f9 - li r26, -4 - lis r12, rsmpTab12khz@ha - addi r12, r12, rsmpTab12khz@l - li r9, 0xa0 - mtctr r9 -lbl_803B6EF4: - rlwinm r10, r4, 7, 0x15, 0x1b - addc r4, r4, r6 - add r10, r10, r12 - mcrxr cr0 - addi r5, r5, 1 - lfs f5, 0(r10) - beq lbl_803B6F70 - lfs f6, 4(r10) - fmuls f10, f1, f5 - cmpw r5, r8 - fmr f1, f2 - lfs f7, 8(r10) - fmadds f10, f2, f6, f10 - fmr f2, f3 - lfs f8, 0xc(r10) - fmadds f10, f3, f7, f10 - addi r30, r30, 4 - fmr f3, f4 - bne+ lbl_803B6F44 - mr r5, r7 -lbl_803B6F44: - fmadds f10, f4, f8, f10 - slwi r9, r5, 2 - bdz lbl_803B6FF4 - lwzx r10, r9, r31 - fctiwz f10, f10 - xoris r10, r10, 0x8000 - stw r10, 0xc(r1) - stfiwx f10, r26, r30 - lfd f4, 8(r1) - fsubs f4, f4, f9 - b lbl_803B6EF4 -lbl_803B6F70: - cmpw r5, r8 - lfs f6, 4(r10) - bne+ lbl_803B6F80 - mr r5, r7 -lbl_803B6F80: - slwi r11, r5, 2 - addi r5, r5, 1 - lwzx r29, r11, r31 - fmuls f10, f1, f5 - cmpw r5, r8 - xoris r29, r29, 0x8000 - fmr f1, f3 - lfs f7, 8(r10) - stw r29, 0xc(r1) - fmadds f10, f2, f6, f10 - lfs f8, 0xc(r10) - fmadds f10, f3, f7, f10 - lfd f3, 8(r1) - fmr f2, f4 - addi r30, r30, 4 - fsubs f3, f3, f9 - bne+ lbl_803B6FC8 - mr r5, r7 -lbl_803B6FC8: - fmadds f10, f4, f8, f10 - slwi r9, r5, 2 - bdz lbl_803B6FF4 - lwzx r10, r9, r31 - fctiwz f10, f10 - xoris r10, r10, 0x8000 - stw r10, 0xc(r1) - stfiwx f10, r26, r30 - lfd f4, 8(r1) - fsubs f4, f4, f9 - b lbl_803B6EF4 -lbl_803B6FF4: - fctiwz f10, f10 - stfiwx f10, r26, r30 - lwz r9, 8(r3) - fctiwz f1, f1 - fctiwz f2, f2 - fctiwz f3, f3 - stfiwx f1, r0, r9 - addi r10, r9, 4 - stfiwx f2, r0, r10 - addi r10, r9, 8 - stfiwx f3, r0, r10 - stw r4, 0xc(r3) - stw r5, 0x10(r3) - lmw r26, 0x28(r1) - addi r1, r1, 0x40 - blr -} -#pragma pop /* clang-format on */ -#endif + +static asm void do_src2(register _SND_CHORUS_SRCINFO* src) { +#define posLoV r4 +#define posHiV r5 +#define pitchLoV r6 +#define triggerV r8 +#define targetV r7 +#define oldPtr r9 +#define destPtr r30 +#define smpBasePtr r31 + + nofralloc; + /* Save stack state to stack */ + stwu r1, -0x40(sp); + stmw r26, 0x28(sp); + + lwz posLoV, src->posLo; + lwz posHiV, src->posHi; + + lwz pitchLoV, src->pitchLo; + + lwz triggerV, src->trigger; + lwz targetV, src->target; + + lwz smpBasePtr, src->smpBase; + + lwz destPtr, src->dest; + + lwz oldPtr, src->old; + /* Store upper portion of int->float conversion constant */ + lis r10, 0x4330; + stw r10, 0x08(sp); + stw r10, 0x10(sp); + stw r10, 0x18(sp); + stw r10, 0x20(sp); + + lis r10, i2fMagic @ha; + lfd f9, i2fMagic @l(r10); + + // posHi * 4 + slwi r10, posHiV, 2; + lwz r11, 0(oldPtr); + lwz r29, 4(oldPtr); + lwz r28, 8(oldPtr); + lwzx r27, smpBasePtr, r10; + + xoris r11, r11, 0x8000; + xoris r29, r29, 0x8000; + stw r11, 0xc(sp); + xoris r28, r28, 0x8000; + stw r29, 0x14(sp); + xoris r27, r27, 0x8000; + stw r28, 0x1c(sp); + lfd f1, 0x08(sp); + stw r27, 0x24(sp); + lfd f2, 0x10(sp); + fsubs f1, f1, f9; + lfd f3, 0x18(sp); + fsubs f2, f2, f9; + lfd f4, 0x20(sp); + fsubs f3, f3, f9; + fsubs f4, f4, f9; + /* Some offset? */ + li r26, -4; + + lis r12, rsmpTab12khz @ha; + addi r12, r12, rsmpTab12khz @l; + + li r9, 0xa0; + mtctr r9; +lbl_803B6EF4: + rlwinm r10, posLoV, 7, 0x15, 0x1b; + + addc posLoV, posLoV, pitchLoV; + + add r10, r10, r12; + + mcrxr cr0; + + addi posHiV, posHiV, 1; + + lfs f5, 0(r10); + + beq lbl_803B6F70; + + lfs f6, 4(r10); + + fmuls f10, f1, f5; + + cmpw posHiV, triggerV; + + fmr f1, f2; + + lfs f7, 8(r10); + + fmadds f10, f2, f6, f10; + + fmr f2, f3; + + lfs f8, 0xc(r10); + + fmadds f10, f3, f7, f10; + + addi destPtr, destPtr, 4; + + fmr f3, f4; + + bne + lbl_803B6F44; + mr posHiV, targetV; + +lbl_803B6F44: + fmadds f10, f4, f8, f10; + + slwi r9, posHiV, 2; + + bdz lbl_803B6FF4; + + lwzx r10, r9, smpBasePtr; + + fctiwz f10, f10; + + xoris r10, r10, 0x8000; + + stw r10, 0xc(sp); + + stfiwx f10, r26, destPtr; + + lfd f4, 8(sp); + + fsubs f4, f4, f9; + + b lbl_803B6EF4; + +lbl_803B6F70: + + cmpw posHiV, triggerV; + + lfs f6, 4(r10); + + bne + lbl_803B6F80; + mr posHiV, targetV; + +lbl_803B6F80: + + slwi r11, posHiV, 2; + addi posHiV, posHiV, 1; + + lwzx r29, r11, smpBasePtr; + + fmuls f10, f1, f5; + + cmpw posHiV, triggerV; + xoris r29, r29, 0x8000; + + fmr f1, f3; + + lfs f7, 8(r10); + + stw r29, 0xc(sp); + + fmadds f10, f2, f6, f10; + + lfs f8, 0xc(r10); + + fmadds f10, f3, f7, f10; + + lfd f3, 8(sp); + + fmr f2, f4; + + addi destPtr, destPtr, 4; + + fsubs f3, f3, f9; + + bne + lbl_803B6FC8; + mr posHiV, targetV; + +lbl_803B6FC8: + + fmadds f10, f4, f8, f10; + + slwi r9, posHiV, 2; + + bdz lbl_803B6FF4; + + lwzx r10, r9, smpBasePtr; + + fctiwz f10, f10; + + xoris r10, r10, 0x8000; + + stw r10, 0xc(sp); + + stfiwx f10, r26, destPtr; + lfd f4, 8(sp); + fsubs f4, f4, f9; + + b lbl_803B6EF4; + +lbl_803B6FF4: + + fctiwz f10, f10; + stfiwx f10, r26, destPtr; + + lwz r9, 8(r3); + + fctiwz f1, f1; + fctiwz f2, f2; + fctiwz f3, f3; + stfiwx f1, r0, r9; + addi r10, r9, 4; + stfiwx f2, r0, r10; + addi r10, r9, 8; + stfiwx f3, r0, r10; + + stw posLoV, src->posLo; + stw posHiV, src->posHi; + + /* Pop and restore LR to original values */ + lmw r26, 0x28(sp); + addi r1, r1, 0x40; + blr; + +#undef posLoV +#undef posHiV +#undef pitchLoV +#undef triggerV +#undef targetV +#undef oldPtr +#undef destPtr +#undef smpBasePtr +} void sndAuxCallbackChorus(u8 reason, SND_AUX_INFO* info, void* user) { - SND_AUX_CHORUS* chorus; - u8 currLast; - s32* lastLeft; - s32* lastRight; - s32* lastSur; - s32* left; - s32* right; - s32* sur; + SND_AUX_CHORUS* c; + s32 *leftD, *rightD, *surD, *leftS, *rightS, *surS; u32 i; - s32 tmp; - + u8 nextCurrentLast; switch (reason) { case SND_AUX_REASON_BUFFERUPDATE: - chorus = (SND_AUX_CHORUS*)user; - currLast = (chorus->work.currentLast + 1) % 3; - lastLeft = chorus->work.lastLeft[currLast]; - lastRight = chorus->work.lastRight[currLast]; - lastSur = chorus->work.lastSur[currLast]; - left = info->data.bufferUpdate.left; - right = info->data.bufferUpdate.right; - sur = info->data.bufferUpdate.surround; + c = (SND_AUX_CHORUS*)user; + nextCurrentLast = (c->work.currentLast + 1) % 3; + leftD = c->work.lastLeft[nextCurrentLast]; + rightD = c->work.lastRight[nextCurrentLast]; + surD = c->work.lastSur[nextCurrentLast]; + leftS = info->data.bufferUpdate.left; + rightS = info->data.bufferUpdate.right; + surS = info->data.bufferUpdate.surround; for (i = 0; i < 160; ++i) { - int tmp = *left; - ++left; - *lastLeft = tmp; - ++lastLeft; - - tmp = *right; - ++right; - *lastRight = tmp; - ++lastRight; - - tmp = *sur; - ++sur; - *lastSur = tmp; - ++lastSur; + *leftD = *leftS++; + leftD++; + *rightD = *rightS++; + rightD++; + *surD = *surS++; + surD++; } - chorus->work.src.pitchHi = (chorus->work.pitchOffset >> 0x10) + 1; - chorus->work.src.pitchLo = (chorus->work.pitchOffset << 0x10); - - tmp = chorus->work.pitchOffsetPeriodCount - 1; - chorus->work.pitchOffsetPeriodCount = tmp; - if (tmp == 0) { - chorus->work.pitchOffsetPeriodCount = chorus->work.pitchOffsetPeriod; - chorus->work.pitchOffset = -chorus->work.pitchOffset; + c->work.src.pitchHi = (c->work.pitchOffset >> 0x10) + 1; + c->work.src.pitchLo = ((c->work.pitchOffset & 0xFFFF) << 16); + if (--c->work.pitchOffsetPeriodCount == 0) { + c->work.pitchOffsetPeriodCount = c->work.pitchOffsetPeriod; + c->work.pitchOffset = -c->work.pitchOffset; } for (i = 0; i < 3; ++i) { - chorus->work.src.posHi = chorus->work.currentPosHi; - chorus->work.src.posLo = chorus->work.currentPosLo; + c->work.src.posHi = c->work.currentPosHi; + c->work.src.posLo = c->work.currentPosLo; switch (i) { case 0: - chorus->work.src.smpBase = chorus->work.lastLeft[0]; - chorus->work.src.dest = info->data.bufferUpdate.left; - chorus->work.src.old = chorus->work.oldLeft; + c->work.src.smpBase = c->work.lastLeft[0]; + c->work.src.dest = info->data.bufferUpdate.left; + c->work.src.old = c->work.oldLeft; break; case 1: - chorus->work.src.smpBase = chorus->work.lastRight[0]; - chorus->work.src.dest = info->data.bufferUpdate.right; - chorus->work.src.old = chorus->work.oldRight; + c->work.src.smpBase = c->work.lastRight[0]; + c->work.src.dest = info->data.bufferUpdate.right; + c->work.src.old = c->work.oldRight; break; case 2: - chorus->work.src.smpBase = chorus->work.lastSur[0]; - chorus->work.src.dest = info->data.bufferUpdate.surround; - chorus->work.src.old = chorus->work.oldSur; + c->work.src.smpBase = c->work.lastSur[0]; + c->work.src.dest = info->data.bufferUpdate.surround; + c->work.src.old = c->work.oldSur; break; } - switch (chorus->work.src.pitchHi) { + switch (c->work.src.pitchHi) { case 0: - do_src1(&chorus->work.src); + do_src1(&c->work.src); break; case 1: - do_src2(&chorus->work.src); + do_src2(&c->work.src); break; } } - chorus->work.currentPosHi = chorus->work.src.posHi % 480; - chorus->work.currentPosLo = chorus->work.src.posLo; - chorus->work.currentLast = currLast; + c->work.currentPosHi = c->work.src.posHi % 480; + c->work.currentPosLo = c->work.src.posLo; + c->work.currentLast = nextCurrentLast; break; case SND_AUX_REASON_PARAMETERUPDATE: break; default: - ASSERT(FALSE); + #line 957 + MUSY_ASSERT(FALSE); break; } } @@ -482,7 +608,6 @@ bool sndAuxCallbackUpdateSettingsChorus(SND_AUX_CHORUS* ch) { bool sndAuxCallbackPrepareChorus(SND_AUX_CHORUS* chorus) { u32 i; - bool ret; s32* lastLeft; s32* lastRight; s32* lastSur; @@ -493,7 +618,7 @@ bool sndAuxCallbackPrepareChorus(SND_AUX_CHORUS* chorus) { chorus->work.lastRight[0] = chorus->work.lastLeft[0] + 0x1e0; chorus->work.lastSur[0] = chorus->work.lastRight[0] + 0x1e0; - for (i = 0; i < 3; ++i) { + for (i = 1; i < 3; ++i) { chorus->work.lastLeft[i] = chorus->work.lastLeft[0] + i * 0xa0; chorus->work.lastRight[i] = chorus->work.lastRight[0] + i * 0xa0; chorus->work.lastSur[i] = chorus->work.lastSur[0] + i * 0xa0; @@ -503,35 +628,20 @@ bool sndAuxCallbackPrepareChorus(SND_AUX_CHORUS* chorus) { lastRight = chorus->work.lastRight[0]; lastSur = chorus->work.lastSur[0]; for (i = 0; i < 0x140; i += 1) { - *lastLeft = 0; - ++lastLeft; - *lastRight = 0; - ++lastRight; - *lastSur = 0; - ++lastSur; + *lastLeft++ = 0; + *lastRight++ = 0; + *lastSur++ = 0; } chorus->work.currentLast = 1; - chorus->work.oldLeft[3] = 0; - chorus->work.oldLeft[2] = 0; - chorus->work.oldLeft[1] = 0; - chorus->work.oldLeft[0] = 0; - chorus->work.oldRight[3] = 0; - chorus->work.oldRight[2] = 0; - chorus->work.oldRight[1] = 0; - chorus->work.oldRight[0] = 0; - chorus->work.oldSur[3] = 0; - chorus->work.oldSur[2] = 0; - chorus->work.oldSur[1] = 0; - chorus->work.oldSur[0] = 0; - + chorus->work.oldLeft[0] = chorus->work.oldLeft[1] = chorus->work.oldLeft[2] = chorus->work.oldLeft[3] = 0; + chorus->work.oldRight[0] = chorus->work.oldRight[1] = chorus->work.oldRight[2] = chorus->work.oldRight[3] = 0; + chorus->work.oldSur[0] = chorus->work.oldSur[1] = chorus->work.oldSur[2] = chorus->work.oldSur[3] = 0; chorus->work.src.trigger = 480; chorus->work.src.target = 0; - ret = sndAuxCallbackUpdateSettingsChorus(chorus); - } else { - ret = FALSE; + return sndAuxCallbackUpdateSettingsChorus(chorus); } - return ret; + return FALSE; } bool sndAuxCallbackShutdownChorus(SND_AUX_CHORUS* ch) { diff --git a/src/musyx/runtime/Delay/delay_fx.c b/src/musyx/runtime/Delay/delay_fx.c index cef13cd3..82134e3b 100644 --- a/src/musyx/runtime/Delay/delay_fx.c +++ b/src/musyx/runtime/Delay/delay_fx.c @@ -12,56 +12,56 @@ #include "musyx/musyx_priv.h" void sndAuxCallbackDelay(u8 reason, SND_AUX_INFO* info, void* user) { - s32 curSur; - s32 curLeft; - s32 curRight; - s32 i; - s32* leftOffset; - s32* surOffset; - s32* rightOffset; - s32* leftPtr; - s32* rightPtr; - s32* surPtr; - SND_AUX_DELAY* delay; + long l; // r30 + long r; // r29 + long s; // r28 + long* lBuf; // r27 + long* rBuf; // r26 + long* sBuf; // r25 + unsigned long i; // r24 + struct SND_AUX_DELAY* c; // r31 + long* left; // r23 + long* right; // r22 + long* sur; // r21 + switch (reason) { case SND_AUX_REASON_BUFFERUPDATE: - delay = (SND_AUX_DELAY*)user; - leftOffset = delay->left + (delay->currentPos[0] * 160); - leftPtr = info->data.bufferUpdate.left; - rightPtr = info->data.bufferUpdate.right; - rightOffset = delay->right + (delay->currentPos[1] * 160); - surPtr = info->data.bufferUpdate.surround; - surOffset = delay->sur + (delay->currentPos[2] * 160); - for (i = 160; i > 0; --i) { - curLeft = *leftOffset; - curRight = *rightOffset; - curSur = *surOffset; - *leftOffset = *leftPtr + ((s32)(curLeft * delay->currentFeedback[0]) >> 7); - ++leftOffset; - *rightOffset = *rightPtr + ((s32)(curRight * delay->currentFeedback[1]) >> 7); - ++rightOffset; - *surOffset = *surPtr + ((s32)(curSur * delay->currentFeedback[2]) >> 7); - ++surOffset; - *leftPtr = (s32)(curLeft * delay->currentOutput[0]) >> 7; - ++leftPtr; - *rightPtr = (s32)(curRight * delay->currentOutput[1]) >> 7; - ++rightPtr; - *surPtr = (s32)(curSur * delay->currentOutput[2]) >> 7; - ++surPtr; + c = (SND_AUX_DELAY*)user; + left = info->data.bufferUpdate.left; + right = info->data.bufferUpdate.right; + sur = info->data.bufferUpdate.surround; + lBuf = c->left + (c->currentPos[0] * 160); + rBuf = c->right + (c->currentPos[1] * 160); + sBuf = c->sur + (c->currentPos[2] * 160); + for (i = 0; i < 160; ++i) { + + l = *lBuf; + r = *rBuf; + s = *sBuf; + + *lBuf++ = *left + ((s32)(l * c->currentFeedback[0]) >> 7); + *rBuf++ = *right + ((s32)(r * c->currentFeedback[1]) >> 7); + *sBuf++ = *sur + ((s32)(s * c->currentFeedback[2]) >> 7); + + *left++ = (s32)(l * c->currentOutput[0]) >> 7; + *right++ = (s32)(r * c->currentOutput[1]) >> 7; + *sur++ = (s32)(s * c->currentOutput[2]) >> 7; } - delay->currentPos[0] = (delay->currentPos[0] + 1) % delay->currentSize[0]; - delay->currentPos[1] = (delay->currentPos[1] + 1) % delay->currentSize[1]; - delay->currentPos[2] = (delay->currentPos[2] + 1) % delay->currentSize[2]; + + c->currentPos[0] = (c->currentPos[0] + 1) % c->currentSize[0]; + c->currentPos[1] = (c->currentPos[1] + 1) % c->currentSize[1]; + c->currentPos[2] = (c->currentPos[2] + 1) % c->currentSize[2]; + break; case SND_AUX_REASON_PARAMETERUPDATE: break; default: - // ASSERT_MSG(FALSE); + MUSY_ASSERT(FALSE); break; } } bool sndAuxCallbackUpdateSettingsDelay(SND_AUX_DELAY* delay) { - s32 i; + u32 i; s32* left; s32* right; s32* sur; @@ -77,25 +77,25 @@ bool sndAuxCallbackUpdateSettingsDelay(SND_AUX_DELAY* delay) { delay->left = (s32*)salMalloc(delay->currentSize[0] * 160 * 4); delay->right = (s32*)salMalloc(delay->currentSize[1] * 160 * 4); delay->sur = (s32*)salMalloc(delay->currentSize[2] * 160 * 4); + + /* clang-format off */ + MUSY_ASSERT(delay->left!=NULL); + MUSY_ASSERT(delay->right!=NULL); + MUSY_ASSERT(delay->sur!=NULL); + /* clang-format on */ left = delay->left; right = delay->right; sur = delay->sur; - // ASSERT_MSG(delay->left!=NULL); - // ASSERT_MSG(delay->right!=NULL); - // ASSERT_MSG(delay->sur!=NULL); for (i = 0; i < delay->currentSize[0] * 160; ++i) { - *left = 0; - ++left; + *left++ = 0; } for (i = 0; i < delay->currentSize[1] * 160; ++i) { - *right = 0; - ++right; + *right++ = 0; } for (i = 0; i < delay->currentSize[2] * 160; ++i) { - *sur = 0; - ++sur; + *sur++ = 0; } return TRUE; } diff --git a/src/musyx/runtime/StdReverb/reverb_fx.c b/src/musyx/runtime/StdReverb/reverb_fx.c index 2e8eaac7..23d56a31 100644 --- a/src/musyx/runtime/StdReverb/reverb_fx.c +++ b/src/musyx/runtime/StdReverb/reverb_fx.c @@ -26,10 +26,12 @@ void sndAuxCallbackReverbHI(u8 reason, SND_AUX_INFO* info, void* user) { ReverbHICallback(info->data.bufferUpdate.left, info->data.bufferUpdate.right, info->data.bufferUpdate.surround, (SND_AUX_REVERBHI*)user); } + + break; case SND_AUX_REASON_PARAMETERUPDATE: break; default: - // ASSERT_MSG(FALSE); + MUSY_ASSERT(FALSE); break; } } diff --git a/src/musyx/runtime/hardware.c b/src/musyx/runtime/hardware.c index 5e8e7f7b..f57e4e6a 100644 --- a/src/musyx/runtime/hardware.c +++ b/src/musyx/runtime/hardware.c @@ -1,4 +1,4 @@ -#include "musyx/assert.h" + #include "musyx/musyx_priv.h" extern void OSReport(const char*, ...); @@ -6,15 +6,13 @@ extern void OSReport(const char*, ...); extern void DCStoreRange(void* addr, u32 nBytes); static volatile const u16 itdOffTab[128] = { - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, - 2, 3, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 6, 6, 6, 7, 7, 7, 8, 8, 8, - 9, 9, 9, 10, 10, 10, 11, 11, 12, 12, 12, 13, 13, 13, 14, 14, 15, 15, 15, 16, 16, 17, - 17, 17, 18, 18, 19, 19, 19, 20, 20, 20, 21, 21, 22, 22, 22, 23, 23, 23, 24, 24, 24, 25, - 25, 25, 26, 26, 26, 27, 27, 27, 28, 28, 28, 28, 29, 29, 29, 29, 29, 30, 30, 30, 30, 30, - 31, 31, 31, 31, 31, 31, 31, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4, 4, + 5, 5, 5, 6, 6, 6, 7, 7, 7, 8, 8, 8, 9, 9, 9, 10, 10, 10, 11, 11, 12, 12, 12, 13, 13, 13, 14, 14, 15, 15, 15, 16, + 16, 17, 17, 17, 18, 18, 19, 19, 19, 20, 20, 20, 21, 21, 22, 22, 22, 23, 23, 23, 24, 24, 24, 25, 25, 25, 26, 26, 26, 27, 27, 27, + 28, 28, 28, 28, 29, 29, 29, 29, 29, 30, 30, 30, 30, 30, 31, 31, 31, 31, 31, 31, 31, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, }; -SND_PROFILE_INFO prof; +//SND_PROFILE_INFO prof; u8 salFrame; u8 salAuxFrame; @@ -24,7 +22,7 @@ SND_HOOKS salHooks; u8 salTimeOffset; void hwSetTimeOffset(u8 offset); -void snd_handle_irq() { +static void snd_handle_irq() { u8 r; // r31 u8 i; // r30 u8 v; // r29 @@ -135,13 +133,13 @@ void hwSetTimeOffset(u8 offset) { salTimeOffset = offset; } u8 hwGetTimeOffset() { return salTimeOffset; } u32 hwIsActive(u32 v) { return dspVoice[v].state != 0; } +u32 hwGlobalActivity() { return 0; } void hwSetMesgCallback(SND_MESSAGE_CALLBACK callback) { salMessageCallback = callback; } void hwSetPriority(u32 idx, u32 priority) { dspVoice[idx].prio = priority; } -void hwInitSamplePlayback(u32 v, u16 smpID, void* newsmp, u32 set_defadsr, u32 prio, - u32 callbackUserValue, u32 setSRC, u8 itdMode) { +void hwInitSamplePlayback(u32 v, u16 smpID, void* newsmp, u32 set_defadsr, u32 prio, u32 callbackUserValue, u32 setSRC, u8 itdMode) { unsigned char i; // r30 unsigned long bf; // r29 bf = 0; @@ -257,8 +255,7 @@ void hwSetPitch(unsigned long v, unsigned short speed) { speed = 0x3fff; } - if (dsp_vptr->lastUpdate.pitch != 0xff && - dsp_vptr->pitch[dsp_vptr->lastUpdate.pitch] == speed * 16) { + if (dsp_vptr->lastUpdate.pitch != 0xff && dsp_vptr->pitch[dsp_vptr->lastUpdate.pitch] == speed * 16) { return; } @@ -281,7 +278,7 @@ void hwSetPolyPhaseFilter(unsigned long v, unsigned char salCoefSel) { dsp_vptr->changed[0] |= 0x80; } -void SetupITD(DSPvoice* dsp_vptr, u8 pan) { +static void SetupITD(DSPvoice* dsp_vptr, u8 pan) { dsp_vptr->itdShiftL = itdOffTab[pan]; dsp_vptr->itdShiftR = 32 - itdOffTab[pan]; dsp_vptr->changed[0] |= 0x200; @@ -299,8 +296,7 @@ void hwSetITDMode(u32 v, u8 mode) { #define hwGetITDMode(dsp_vptr) (dsp_vptr->flags & 0x80000000) -void hwSetVolume(unsigned long v, unsigned char table, float vol, unsigned long pan, - unsigned long span, float auxa, float auxb) { +void hwSetVolume(unsigned long v, unsigned char table, float vol, unsigned long pan, unsigned long span, float auxa, float auxb) { SAL_VOLINFO vi; // r1+0x24 unsigned short il; // r30 unsigned short ir; // r29 @@ -325,8 +321,7 @@ void hwSetVolume(unsigned long v, unsigned char table, float vol, unsigned long ir = 32767.f * vi.volR; is = 32767.f * vi.volS; - if (dsp_vptr->lastUpdate.vol == 0xff || dsp_vptr->volL != il || dsp_vptr->volR != ir || - dsp_vptr->volS != is) { + if (dsp_vptr->lastUpdate.vol == 0xff || dsp_vptr->volL != il || dsp_vptr->volR != ir || dsp_vptr->volS != is) { dsp_vptr->volL = il; dsp_vptr->volR = ir; dsp_vptr->volS = is; @@ -338,8 +333,7 @@ void hwSetVolume(unsigned long v, unsigned char table, float vol, unsigned long ir = 32767.f * vi.volAuxAR; is = 32767.f * vi.volAuxAS; - if (dsp_vptr->lastUpdate.volA == 0xff || dsp_vptr->volLa != il || dsp_vptr->volRa != ir || - dsp_vptr->volSa != is) { + if (dsp_vptr->lastUpdate.volA == 0xff || dsp_vptr->volLa != il || dsp_vptr->volRa != ir || dsp_vptr->volSa != is) { dsp_vptr->volLa = il; dsp_vptr->volRa = ir; dsp_vptr->volSa = is; @@ -351,8 +345,7 @@ void hwSetVolume(unsigned long v, unsigned char table, float vol, unsigned long ir = 32767.f * vi.volAuxBR; is = 32767.f * vi.volAuxBS; - if (dsp_vptr->lastUpdate.volB == 0xff || dsp_vptr->volLb != il || dsp_vptr->volRb != ir || - dsp_vptr->volSb != is) { + if (dsp_vptr->lastUpdate.volB == 0xff || dsp_vptr->volLb != il || dsp_vptr->volRb != ir || dsp_vptr->volSb != is) { dsp_vptr->volLb = il; dsp_vptr->volRb = ir; dsp_vptr->volSb = is; @@ -367,31 +360,24 @@ void hwSetVolume(unsigned long v, unsigned char table, float vol, unsigned long void hwOff(s32 vid) { salDeactivateVoice(&dspVoice[vid]); } -void hwSetAUXProcessingCallbacks(u8 studio, SND_AUX_CALLBACK auxA, void* userA, - SND_AUX_CALLBACK auxB, void* userB) { +void hwSetAUXProcessingCallbacks(u8 studio, SND_AUX_CALLBACK auxA, void* userA, SND_AUX_CALLBACK auxB, void* userB) { dspStudio[studio].auxAHandler = auxA; dspStudio[studio].auxAUser = userA; dspStudio[studio].auxBHandler = auxB; dspStudio[studio].auxBUser = userB; } -void hwActivateStudio(unsigned char studio, unsigned long isMaster, SND_STUDIO_TYPE type) { - salActivateStudio(studio, isMaster, type); -} +void hwActivateStudio(unsigned char studio, unsigned long isMaster, SND_STUDIO_TYPE type) { salActivateStudio(studio, isMaster, type); } void hwDeactivateStudio(u8 studio) { salDeactivateStudio(studio); } void hwChangeStudioMix(u8 studio, u32 isMaster) { dspStudio[studio].isMaster = isMaster; } -bool hwIsStudioActive(u32 studio) { return dspStudio[studio].state == 1; } +bool hwIsStudioActive(u8 studio) { return dspStudio[studio].state == 1; } -bool hwAddInput(u8 studio, SND_STUDIO_INPUT* in_desc) { - return salAddStudioInput(&dspStudio[studio], in_desc); -} +bool hwAddInput(u8 studio, SND_STUDIO_INPUT* in_desc) { return salAddStudioInput(&dspStudio[studio], in_desc); } -bool hwRemoveInput(u8 studio, SND_STUDIO_INPUT* in_desc) { - return salRemoveStudioInput(&dspStudio[studio], in_desc); -} +bool hwRemoveInput(u8 studio, SND_STUDIO_INPUT* in_desc) { return salRemoveStudioInput(&dspStudio[studio], in_desc); } void hwChangeStudio(u32 v, u8 studio) { salReconnectVoice(&dspVoice[v], studio); } @@ -424,84 +410,36 @@ u32 hwGetPos(u32 v) { return pos; } -#if NONMATCHING -void hwFlushStream(void* base, unsigned long offset, unsigned long bytes, - unsigned char hwStreamHandle, void (*callback)(unsigned long), +void hwFlushStream(void* base, unsigned long offset, unsigned long bytes, unsigned char hwStreamHandle, void (*callback)(unsigned long), unsigned long user) { - unsigned long aram; // r28 - unsigned long mram; // r29 - unsigned long len; + u32 aram; // r28 + u32 mram; // r29 + u32 len; aram = aramGetStreamBufferAddress(hwStreamHandle, &len); - DCStoreRange((void*)((u32)base + (offset & ~31)), bytes + ((offset & 31) + 31) & ~31); - aramUploadData((void*)((u32)base + (offset & ~31)), aram + (offset & ~31), - bytes + ((offset & 31) + 31) & ~31, 1, callback, user); + bytes += (offset & 31); + offset &= ~31; + bytes = (bytes + 31) & ~31; + mram = (u32)base + offset; + DCStoreRange((void*)mram, bytes); + aramUploadData((void*)mram, aram + offset, bytes, 1, callback, user); } -#else -/* clang-format off */ -#pragma push -#pragma optimization_level 0 -#pragma optimizewithasm off -extern void _savegpr_25(); -extern void _restgpr_25(); -asm void hwFlushStream(void* base, unsigned long offset, unsigned long bytes, - unsigned char hwStreamHandle, void (*callback)(unsigned long), - unsigned long user) { - nofralloc - stwu r1, -0x30(r1) - mflr r0 - stw r0, 0x34(r1) - addi r11, r1, 0x30 - bl _savegpr_25 - mr r25, r3 - mr r29, r4 - mr r26, r5 - mr r27, r7 - mr r28, r8 - mr r3, r6 - addi r4, r1, 8 - bl aramGetStreamBufferAddress - clrlwi r0, r29, 0x1b - rlwinm r30, r29, 0, 0, 0x1a - add r26, r26, r0 - mr r31, r3 - addi r0, r26, 0x1f - add r29, r25, r30 - rlwinm r26, r0, 0, 0, 0x1a - mr r3, r29 - mr r4, r26 - bl DCStoreRange - mr r3, r29 - mr r5, r26 - mr r7, r27 - mr r8, r28 - add r4, r31, r30 - li r6, 1 - bl aramUploadData - addi r11, r1, 0x30 - bl _restgpr_25 - lwz r0, 0x34(r1) - mtlr r0 - addi r1, r1, 0x30 - blr -} -#pragma pop -/* clang-format on */ -#endif void hwPrepareStreamBuffer() {} u32 hwInitStream(u32 len) { return aramAllocateStreamBuffer(len); } void hwExitStream(u8 id) { aramFreeStreamBuffer(id); } -void* hwGetStreamPlayBuffer(u8 hwStreamHandle) { - return (void*)aramGetStreamBufferAddress(hwStreamHandle, NULL); -} +void* hwGetStreamPlayBuffer(u8 hwStreamHandle) { return (void*)aramGetStreamBufferAddress(hwStreamHandle, NULL); } void* hwTransAddr(void* samples) { return samples; } u32 hwFrq2Pitch(u32 frq) { return (frq * 4096.f) / synthInfo.mixFrq; } -void hwInitSampleMem(u32 baseAddr, u32 length) { aramInit(length); } +void hwInitSampleMem(u32 baseAddr, u32 length) { +#line 940 + MUSY_ASSERT(baseAddr == 0x00000000); + aramInit(length); +} void hwExitSampleMem() { aramExit(); } @@ -519,25 +457,17 @@ static u32 convert_length(u32 len, u8 type) { } void hwSaveSample(void* header, void* data) { - u32 len; - u8 type; - - header = (void*)((u32*)header)[0]; - header = (void*)((u32*)header)[1]; - len = (u32)header & 0xFFFFFF; - type = (u32)header >> 0x18; - *((u32*)data) = (u32)aramStoreData((void*)*((u32*)data), convert_length(len, type)); + u32 len = ((u32*)*((u32*)header))[1] & 0xFFFFFF; + u8 type = ((u32*)*((u32*)header))[1] >> 0x18; + len = convert_length(len, type); + *((u32*)data) = (u32)aramStoreData((void*)*((u32*)data), len); } -void hwSetSaveSampleCallback(ARAMUploadCallback callback, unsigned long chunckSize) { - aramSetUploadCallback(callback); -} +void hwSetSaveSampleCallback(ARAMUploadCallback callback, unsigned long chunckSize) { aramSetUploadCallback(callback, chunckSize); } void hwRemoveSample(void* header, void* data) { - u32 len; // r31 - u8 type; // r30 - type = ((u32*)header)[1] >> 0x18; - len = convert_length(((u32*)header)[1] & 0xFFFFFF, type); + u8 type = (((u32*)header))[1] >> 0x18; + u32 len = convert_length((((u32*)header))[1] & 0xFFFFFF, type); aramRemoveData(data, len); } diff --git a/src/musyx/runtime/hw_dolphin.c b/src/musyx/runtime/hw_dolphin.c index 3eabebb5..487771ef 100644 --- a/src/musyx/runtime/hw_dolphin.c +++ b/src/musyx/runtime/hw_dolphin.c @@ -134,7 +134,7 @@ u32 salExitDsp() { void salStartDsp(u16* cmdList) { salDspIsDone = FALSE; PPCSync(); - ASSERT(((u32)cmdList & 0x1F)==0); + MUSY_ASSERT(((u32)cmdList & 0x1F)==0); DSPSendMailToDSP(dspCmdFirstSize | 0xbabe0000); while (DSPCheckMailToDSP()) diff --git a/src/musyx/runtime/hw_dspctrl.c b/src/musyx/runtime/hw_dspctrl.c index ab5303b9..b76bc981 100644 --- a/src/musyx/runtime/hw_dspctrl.c +++ b/src/musyx/runtime/hw_dspctrl.c @@ -1,4 +1,4 @@ -#include "musyx/assert.h" + #include "musyx/musyx_priv.h" #ifdef _DEBUG @@ -31,7 +31,7 @@ u32 salInitDspCtrl(u8 numVoices, u8 numStudios, u32 defaultStudioDPL2) { salNumVoices = numVoices; salMaxStudioNum = numStudios; #line 66 - ASSERT(salMaxStudioNum <= SAL_MAX_STUDIONUM); + MUSY_ASSERT(salMaxStudioNum <= SAL_MAX_STUDIONUM); dspARAMZeroBuffer = aramGetZeroBuffer(); if ((dspCmdList = salMalloc(1024 * sizeof(u16))) != NULL) { MUSY_DEBUG("Allocated dspCmdList.\n\n"); diff --git a/src/musyx/runtime/s_data.c b/src/musyx/runtime/s_data.c index 8366a9c5..edf2a275 100644 --- a/src/musyx/runtime/s_data.c +++ b/src/musyx/runtime/s_data.c @@ -1,4 +1,4 @@ -#include "musyx/assert.h" + #include "musyx/musyx_priv.h" static GSTACK gs[128]; @@ -182,8 +182,8 @@ void sndSetSampleDataUploadCallback(void* (*callback)(unsigned long, unsigned lo u32 sndPushGroup(void* prj_data, u16 gid, void* samples, void* sdir, void* pool) { GROUP_DATA* g; // r31 #line 0x18d - ASSERT_MSG(prj_data != NULL, "Project data pointer is NULL"); - ASSERT_MSG(sdir != NULL, "Sample directory pointer is NULL"); + MUSY_ASSERT_MSG(prj_data != NULL, "Project data pointer is NULL"); + MUSY_ASSERT_MSG(sdir != NULL, "Sample directory pointer is NULL"); if (sndActive && sp < 128) { g = prj_data; @@ -232,8 +232,8 @@ unsigned long sndPopGroup() { void* prj; struct FX_DATA* fd; - ASSERT_MSG(sndActive != FALSE, "Sound system is not initialized."); - ASSERT_MSG(sp != 0, "Soundstack is empty."); + MUSY_ASSERT_MSG(sndActive != FALSE, "Sound system is not initialized."); + MUSY_ASSERT_MSG(sp != 0, "Soundstack is empty."); g = gs[--sp].gAddr; prj = gs[sp].prjAddr; sdir = gs[sp].sdirAddr; @@ -282,7 +282,7 @@ u32 seqPlaySong(u16 sgid, u16 sid, void* arrfile, SND_PLAYPARA* para, u8 irq_cal MIDISETUP* midiSetup; u32 seqId; void* prj; - ASSERT_MSG(sndActive != FALSE, "Sound system is not initialized."); + MUSY_ASSERT_MSG(sndActive != FALSE, "Sound system is not initialized."); for (i = 0; i < sp; ++i) { if (sgid != gs[i].gAddr->id) { diff --git a/src/musyx/runtime/snd_init.c b/src/musyx/runtime/snd_init.c index c6b799b1..dce384b0 100644 --- a/src/musyx/runtime/snd_init.c +++ b/src/musyx/runtime/snd_init.c @@ -1,6 +1,6 @@ #include "musyx/musyx_priv.h" //#define _DEBUG -#include "musyx/assert.h" + s32 DoInit(u32 rate, u32 aramSize, u8 voices, u32 flags) { dataInitStack(); @@ -50,8 +50,8 @@ void sndQuit() { } void sndSetMaxVoices(u8 music, u8 sfx) { - ASSERT_MSG(music > synthInfo.voiceNum, "Music voices are above maximum voice number."); - ASSERT_MSG(sfx > synthInfo.voiceNum, "Sfx voices are above maximum voice number."); + MUSY_ASSERT_MSG(music > synthInfo.voiceNum, "Music voices are above maximum voice number."); + MUSY_ASSERT_MSG(sfx > synthInfo.voiceNum, "Sfx voices are above maximum voice number."); synthInfo.maxMusic = music; synthInfo.maxSFX = sfx; } diff --git a/src/musyx/runtime/snd_midictrl.c b/src/musyx/runtime/snd_midictrl.c index e89ca95a..81e9dd22 100644 --- a/src/musyx/runtime/snd_midictrl.c +++ b/src/musyx/runtime/snd_midictrl.c @@ -1,4 +1,4 @@ -#include "musyx/assert.h" + #include "musyx/musyx_priv.h" #define SYNTH_FX_MIDISET 0xFF @@ -29,7 +29,7 @@ void inpResetGlobalMIDIDirtyFlags() { } bool inpResetGlobalMIDIDirtyFlag(u8 chan, u8 midiSet, s32 flag) { - // ASSERT(midiSet!=SYNTH_FX_MIDISET); + // MUSY_ASSERT(midiSet!=SYNTH_FX_MIDISET); bool ret = GetGlobalFlagSet(chan, midiSet, flag); if (ret) { inpGlobalMIDIDirtyFlags[midiSet][chan] &= ~flag; @@ -38,7 +38,7 @@ bool inpResetGlobalMIDIDirtyFlag(u8 chan, u8 midiSet, s32 flag) { } void inpSetGlobalMIDIDirtyFlag(u8 chan, u8 midiSet, s32 flag) { - // ASSERT(midiSet!=SYNTH_FX_MIDISET); + // MUSY_ASSERT(midiSet!=SYNTH_FX_MIDISET); inpGlobalMIDIDirtyFlags[midiSet][chan] |= flag; } diff --git a/src/musyx/runtime/synth.c b/src/musyx/runtime/synth.c index 620c7087..ac4543f6 100644 --- a/src/musyx/runtime/synth.c +++ b/src/musyx/runtime/synth.c @@ -1,4 +1,4 @@ -#include "musyx/assert.h" + #include "musyx/musyx_priv.h" static u32 synthTicksPerSecond[9][16]; diff --git a/src/musyx/runtime/synth_adsr.c b/src/musyx/runtime/synth_adsr.c index 98bb4353..df06efcd 100644 --- a/src/musyx/runtime/synth_adsr.c +++ b/src/musyx/runtime/synth_adsr.c @@ -1,4 +1,4 @@ -#include "musyx/assert.h" + #include "musyx/musyx_priv.h" #include "musyx/synth_dbtab.h" diff --git a/src/musyx/runtime/synth_vsamples.c b/src/musyx/runtime/synth_vsamples.c index 1a6e8b55..3aa6128d 100644 --- a/src/musyx/runtime/synth_vsamples.c +++ b/src/musyx/runtime/synth_vsamples.c @@ -1,4 +1,4 @@ -#include "musyx/assert.h" + #include "musyx/musyx_priv.h" static VS vs; @@ -160,8 +160,8 @@ unsigned long sndVirtualSampleAllocateBuffers(unsigned char numInstances, long i; // r31 unsigned long len; // r28 #line 437 - ASSERT_MSG(sndActive, "Sound system is not initialized."); - ASSERT_MSG(numInstances <= 64, "Parameter exceeded maximum number of instances allowable"); + MUSY_ASSERT_MSG(sndActive, "Sound system is not initialized."); + MUSY_ASSERT_MSG(numInstances <= 64, "Parameter exceeded maximum number of instances allowable"); #line 159 hwDisableIrq(); vs.numBuffers = numInstances; @@ -193,7 +193,7 @@ unsigned long sndVirtualSampleAllocateBuffers(unsigned char numInstances, void sndVirtualSampleFreeBuffers() { u8 i; // r31 #line 481 - ASSERT_MSG(sndActive, "Sound system is not initialized."); + MUSY_ASSERT_MSG(sndActive, "Sound system is not initialized."); for (i = 0; i < vs.numBuffers; ++i) { aramFreeStreamBuffer(vs.streamBuffer[i].hwId); @@ -205,7 +205,7 @@ void sndVirtualSampleFreeBuffers() { void sndVirtualSampleSetCallback(unsigned long (*callback)(unsigned char, struct SND_VIRTUALSAMPLE_INFO*)) { #line 0x1ed - ASSERT_MSG(sndActive, "Sound system is not initialized."); + MUSY_ASSERT_MSG(sndActive, "Sound system is not initialized."); vs.callback = callback; } @@ -221,7 +221,7 @@ void sndVirtualSampleARAMUpdate(unsigned short instID, void* base, unsigned long unsigned long len1, unsigned long off2, unsigned long len2) { u8 i; #line 0x203 - ASSERT_MSG(sndActive, "Sound system is not initialized."); + MUSY_ASSERT_MSG(sndActive, "Sound system is not initialized."); hwDisableIrq(); diff --git a/src/musyx/runtime/synthdata.c b/src/musyx/runtime/synthdata.c index 8a881f60..90dd00af 100644 --- a/src/musyx/runtime/synthdata.c +++ b/src/musyx/runtime/synthdata.c @@ -1,4 +1,4 @@ -#include "musyx/assert.h" + #include "musyx/musyx_priv.h" static u16 dataSmpSDirNum = 0; diff --git a/src/musyx/runtime/synthmacros.c b/src/musyx/runtime/synthmacros.c index 06d6ff9e..a064e13d 100644 --- a/src/musyx/runtime/synthmacros.c +++ b/src/musyx/runtime/synthmacros.c @@ -1,9 +1,6 @@ -#include "musyx/assert.h" #include "musyx/musyx_priv.h" -#ifdef _DEBUG static u8 DebugMacroSteps = 0; -#endif static SYNTH_VOICE* macActiveMacroRoot = NULL; static SYNTH_VOICE* macTimeQueueRoot = NULL; @@ -17,6 +14,37 @@ void macSetExternalKeyoff(SYNTH_VOICE* svoice); static void DoSetPitch(SYNTH_VOICE* svoice); +/* + This may look like a fakematch, however this actually makes sense if you break it down: + 1) Shift right to clear bottom 2 nybbles; + 2) Shift left to put the moved nybbles back to their original location + 3) Mask off the top nybble leaving only 3rd nybble + + So taking 0x1234567 as an example the logic looks something like this + 1) 0x12345678 >> 16 == 0x00001234 + 2) 0x00001234 << 16 == 0x12340000 + 3) 0x12340000 & 0x00FFFFFF == 0x00340000 + + This behavior could also be matched with a simple mask + + 0x12345678 & 0x00FF0000 == 0x00340000 + + But on PPC with CodeWarrior this just produces an improper load: + + ` + lwz r0,0(r29) + rlwinm r0,r0,0,8,0xf + ` + + Instead of the expected + ` + lwz r3,0(r29) + rlwinm r0,r3,0,8,0xf + ` + Note the use of r3 instead of r0 +*/ +#define EXTRACT_3RDNYBBLE(v) (((v >> 16) << 16) & 0x00FFFFFF) + static int SendSingleKeyOff(u32 voiceid) { u32 i; // r31 @@ -221,7 +249,7 @@ static u32 mcmdGoto(SYNTH_VOICE* svoice, MSTEP* cstep) { static u32 mcmdGosub(SYNTH_VOICE* svoice, MSTEP* cstep) { MSTEP* addr; // r30 - if ((addr = (MSTEP*)dataGetMacro(cstep->para[0] >> 0x10)) != NULL) { + if ((addr = (MSTEP*)dataGetMacro((u16)(cstep->para[0] >> 0x10))) != NULL) { svoice->callStackIndex = (svoice->callStackIndex + 1) & 3; svoice->callStack[svoice->callStackIndex].addr = svoice->addr; svoice->callStack[svoice->callStackIndex].curAddr = svoice->curAddr; @@ -271,11 +299,7 @@ static void mcmdPlayMacro(SYNTH_VOICE* svoice, MSTEP* cstep) { u32 new_child; // r30 key = ((u32)svoice->orgNote + (s8)(u8)(cstep->para[0] >> 8)); - if (key < 0) { - key = 0; - } else if (key > 0x7f) { - key = 0x7f; - } + key = (key < 0) ? 0 : key > 0x7f ? 0x7f : key; if (svoice->fxFlag != 0) { key |= 0x80; @@ -601,8 +625,20 @@ static void mcmdSetPitchADSR(SYNTH_VOICE* svoice, MSTEP* cstep) { s32 ascale; // r27 s32 dscale; // r26 } -u32 mcmdPitchSweep(SYNTH_VOICE* svoice, MSTEP* cstep, int num) { +static u32 mcmdPitchSweep(SYNTH_VOICE* svoice, MSTEP* cstep, int num) { s32 delta; // r31 + svoice->sweepOff[num] = 0; + svoice->sweepNum[num] = (u8)(cstep->para[0] >> 8); + svoice->sweepCnt[num] = (s32)svoice->sweepNum[num] << 0x10; + delta = (int)(short)(cstep->para[0] >> 0x10); + if (delta >= 0) { + delta = hwFrq2Pitch(delta); + } else { + delta = -hwFrq2Pitch(-delta); + } + svoice->sweepAdd[num] = delta << 0x10; + cstep->para[0] = 0; + mcmdWait(svoice, cstep); } static void DoPanningSetup(SYNTH_VOICE* svoice, MSTEP* cstep, u8 pi) { @@ -624,32 +660,131 @@ static void DoPanningSetup(SYNTH_VOICE* svoice, MSTEP* cstep, u8 pi) { static void mcmdSetPanning(SYNTH_VOICE* svoice, MSTEP* cstep) { DoPanningSetup(svoice, cstep, 0); } -static void mcmdSetSurroundPanning(SYNTH_VOICE* svoice, MSTEP* cstep) {} +static void mcmdSetSurroundPanning(SYNTH_VOICE* svoice, MSTEP* cstep) { + DoPanningSetup(svoice, cstep, 1); +} + static void mcmdSetPianoPanning(SYNTH_VOICE* svoice, MSTEP* cstep) { s32 delta; // r31 s32 scale; // r30 + delta = (svoice->curNote << 16) - EXTRACT_3RDNYBBLE(cstep->para[0]); + scale = (s8)(u8)(cstep->para[0] >> 8); + delta = ((delta * scale) >> 7); + delta += (u8)(cstep->para[0] >> 0x18) << 16; + if (delta < 0) { + delta = 0; + } else if (delta > 0x7f0000) { + delta = 0x7f0000; + } + svoice->panTarget[0] = delta; + svoice->panning[0] = delta; } static u32 TranslateVolume(u32 volume, u16 curve) { u8* ptr; // r30 u32 vlow; // r28 u32 vhigh; // r31 s32 d; // r27 + + if (curve != 0xFFFF) { + if ((ptr = (u8*)dataGetCurve(curve))) { + vhigh = (volume >> 16) & 0xFFFF; + vlow = volume & 0xFFFF; + + if (vhigh < 0x7f) { + d = vlow * (ptr[vhigh + 1] - ptr[vhigh]); + volume = d + (ptr[vhigh] << 16); + } else { + volume = ptr[vhigh] << 16; + } + } + } + + return volume; } + static void mcmdScaleVolume(SYNTH_VOICE* svoice, MSTEP* cstep) { u16 curve; // r29 u16 scale; // r28 + scale = (u16)(u8)(cstep->para[0] >> 8); + + if ((u8)(cstep->para[1] >> 8) == 0) { + svoice->volume = (svoice->volume * scale) / 0x7f; + } else { + svoice->volume = (svoice->orgVolume * scale) / 0x7f; + } + + svoice->volume += EXTRACT_3RDNYBBLE(cstep->para[0]); + + if (svoice->volume > 0x7f0000) { + svoice->volume = 0x7f0000; + } + + curve = (u8)(cstep->para[0] >> 0x18); + curve |= ((u16)((u8)cstep->para[1]) << 8); + + svoice->volume = TranslateVolume(svoice->volume, curve); + svoice->cFlags |= 0x100000000000; } + static void mcmdScaleVolumeDLS(SYNTH_VOICE* svoice, MSTEP* cstep) { u16 scale; // r31 + + scale = (u16)(cstep->para[0] >> 8); + if (cstep->para[0] >> 0x18 == 0) { + svoice->volume = ((svoice->volume >> 5) * scale) >> 7; + } else { + svoice->volume = ((svoice->orgVolume >> 5) * scale) >> 7; + } + if (svoice->volume > 0x7f0000) { + svoice->volume = 0x7f0000; + } + + svoice->cFlags |= 0x100000000000; } + static void DoEnvelopeCalculation(SYNTH_VOICE* svoice, MSTEP* cstep, s32 start_vol) { u32 tvol; // r31 u32 time; // r1+0x14 s32 mstime; // r28 u16 curve; // r27 + + time = (cstep->para[1] >> 16); + + if ((u8)(cstep->para[1] >> 8) & 1) { + sndConvertMs(&time); + } else { + sndConvertTicks(&time, svoice); + } + + mstime = sndConvert2Ms(time); + if (mstime == 0) { + mstime = 1; + } + + tvol = (svoice->volume * (u8)(cstep->para[0] >> 8) >> 7); + tvol += EXTRACT_3RDNYBBLE(cstep->para[0]); + + if (tvol > 0x7f0000) { + tvol = 0x7f0000; + } + + curve = (u16)(u8)(cstep->para[0] >> 0x18); + curve |= (((u16)(u8)cstep->para[1]) << 8) & 0xFFFF00; + tvol = TranslateVolume(tvol, curve); + svoice->envTarget = tvol; + svoice->envCurrent = start_vol; + svoice->envDelta = (s32)(tvol - start_vol) / mstime; + svoice->volume = start_vol; + svoice->cFlags |= 0x8000; } -static void mcmdEnvelope(SYNTH_VOICE* svoice, MSTEP* cstep) {} -static void mcmdFadeIn(SYNTH_VOICE* svoice, MSTEP* cstep) {} + +static void mcmdEnvelope(SYNTH_VOICE* svoice, MSTEP* cstep) { + DoEnvelopeCalculation(svoice, cstep, svoice->volume); +} +static void mcmdFadeIn(SYNTH_VOICE* svoice, MSTEP* cstep) { + DoEnvelopeCalculation(svoice, cstep, 0); +} + static void mcmdRandomKey(SYNTH_VOICE* svoice, MSTEP* cstep) { u8 k1; // r30 u8 k2; // r29 @@ -658,49 +793,105 @@ static void mcmdRandomKey(SYNTH_VOICE* svoice, MSTEP* cstep) { s32 i2; // r27 u8 detune; // r26 } -static void mcmdSetPitchbendAfterKeyOff(SYNTH_VOICE* svoice) {} -static void mcmdScaleReverb(SYNTH_VOICE* svoice, MSTEP* cstep) {} +static void mcmdSetPitchbendAfterKeyOff(SYNTH_VOICE* svoice) { svoice->cFlags |= 0x10000; } +static void mcmdScaleReverb(SYNTH_VOICE* svoice, MSTEP* cstep) { + svoice->revVolScale = (u8)(cstep->para[0] >> 8); + svoice->revVolOffset = (u8)(cstep->para[0] >> 0x10); +} static void SelectSource(SYNTH_VOICE* svoice, CTRL_DEST* dest, MSTEP* cstep, u64 tstflag, u32 dirtyFlag) { u8 comb; // r28 s32 scale; // r30 + + if (!(svoice->cFlags & tstflag)) { + comb = 0; + svoice->cFlags |= tstflag; + } else { + comb = (u8)cstep->para[1]; + } + + scale = (s32)(cstep->para[0] & 0xFFFF0000) / 100; + if (scale < 0) { + scale -= ((s8)(cstep->para[1] >> 0x10) << 8) / 100; + } else { + scale += ((s8)(cstep->para[1] >> 0x10) << 8) / 100; + } + + inpAddCtrl(dest, (u8)(cstep->para[0] >> 8), scale, comb, (u8)(cstep->para[1] >> 8) != 0); + + if ((dirtyFlag & 0x80000000) != 0) { + inpSetGlobalMIDIDirtyFlag(svoice->midi, svoice->midiSet, dirtyFlag); + } else { + svoice->midiDirtyFlags |= dirtyFlag; + } } -static void mcmdVolumeSelect(SYNTH_VOICE* svoice, MSTEP* cstep) {} -static void mcmdPanningSelect(SYNTH_VOICE* svoice, MSTEP* cstep) {} +static void mcmdVolumeSelect(SYNTH_VOICE* svoice, MSTEP* cstep) { + SelectSource(svoice, &svoice->inpVolume, cstep, 0x80000, 1); +} -static void mcmdPitchWheelSelect(SYNTH_VOICE* svoice, MSTEP* cstep) {} +static void mcmdPanningSelect(SYNTH_VOICE* svoice, MSTEP* cstep) { + SelectSource(svoice, &svoice->inpPanning, cstep, 0x100000, 2); +} -static void mcmdModWheelSelect(SYNTH_VOICE* svoice, MSTEP* cstep) {} +static void mcmdPitchWheelSelect(SYNTH_VOICE* svoice, MSTEP* cstep) { + SelectSource(svoice, &svoice->inpPitchBend, cstep, 0x200000, 8); +} -static void mcmdPedalSelect(SYNTH_VOICE* svoice, MSTEP* cstep) {} +static void mcmdModWheelSelect(SYNTH_VOICE* svoice, MSTEP* cstep) { + SelectSource(svoice, &svoice->inpModulation, cstep, 0x400000, 0x20); +} -static void mcmdPortamentoSelect(SYNTH_VOICE* svoice, MSTEP* cstep) {} +static void mcmdPedalSelect(SYNTH_VOICE* svoice, MSTEP* cstep) { + SelectSource(svoice, &svoice->inpPedal, cstep, 0x2000000, 0x40); +} -static void mcmdReverbSelect(SYNTH_VOICE* svoice, MSTEP* cstep) {} +static void mcmdPortamentoSelect(SYNTH_VOICE* svoice, MSTEP* cstep) { + SelectSource(svoice, &svoice->inpPortamento, cstep, 0x1000000, 0x80); +} -static void mcmdPreAuxASelect(SYNTH_VOICE* svoice, MSTEP* cstep) {} +static void mcmdReverbSelect(SYNTH_VOICE* svoice, MSTEP* cstep) { + SelectSource(svoice, &svoice->inpReverb, cstep, 0x800000, 0x200); +} -static void mcmdPreAuxBSelect(SYNTH_VOICE* svoice, MSTEP* cstep) {} +static void mcmdPreAuxASelect(SYNTH_VOICE* svoice, MSTEP* cstep) { + SelectSource(svoice, &svoice->inpPreAuxA, cstep, 0x20000000, 0x100); +} -static void mcmdPostAuxBSelect(SYNTH_VOICE* svoice, MSTEP* cstep) {} +static void mcmdPreAuxBSelect(SYNTH_VOICE* svoice, MSTEP* cstep) { + SelectSource(svoice, &svoice->inpPreAuxB, cstep, 0x40000000, 0x400); +} -static void mcmdSurroundPanningSelect(SYNTH_VOICE* svoice, MSTEP* cstep) {} +static void mcmdPostAuxBSelect(SYNTH_VOICE* svoice, MSTEP* cstep) { + SelectSource(svoice, &svoice->inpPostAuxB, cstep, 0x80000000, 0x800); +} -static void mcmdDopplerSelect(SYNTH_VOICE* svoice, MSTEP* cstep) {} +static void mcmdSurroundPanningSelect(SYNTH_VOICE* svoice, MSTEP* cstep) { + SelectSource(svoice, &svoice->inpSurroundPanning, cstep, 0x4000000, 4); +} -static void mcmdTremoloSelect(SYNTH_VOICE* svoice, MSTEP* cstep) {} +static void mcmdDopplerSelect(SYNTH_VOICE* svoice, MSTEP* cstep) { + SelectSource(svoice, &svoice->inpDoppler, cstep, 0x8000000, 0x10); +} + +static void mcmdTremoloSelect(SYNTH_VOICE* svoice, MSTEP* cstep) { + SelectSource(svoice, &svoice->inpTremolo, cstep, 0x10000000, 0x1000); +} static void mcmdAuxAFXSelect(SYNTH_VOICE* svoice, MSTEP* cstep) { u32 i; // r31 static u64 mask[4] = {0x100000000, 0x200000000, 0x400000000, 0x800000000}; // size: 0x20 static u32 dirty[4] = {0x80000001, 0x80000002, 0x80000004, 0x80000008}; // size: 0x10 + i = cstep->para[1] >> 0x18; + SelectSource(svoice, &inpAuxA[svoice->studio][i], cstep, mask[i], dirty[i]); } static void mcmdAuxBFXSelect(SYNTH_VOICE* svoice, MSTEP* cstep) { u32 i; // r31 static u64 mask[4] = {0x1000000000, 0x2000000000, 0x4000000000, 0x8000000000}; // size: 0x20 static u32 dirty[4] = {0x80000010, 0x80000020, 0x80000040, 0x80000080}; // size: 0x10 + i = cstep->para[1] >> 0x18; + SelectSource(svoice, &inpAuxB[svoice->studio][i], cstep, mask[i], dirty[i]); } static void mcmdPortamento(SYNTH_VOICE* svoice, MSTEP* cstep) { @@ -736,38 +927,161 @@ void varSet32(SYNTH_VOICE* svoice, u32 ctrl, u8 index, s32 v) { synthGlobalVariable[index - 16] = v; } void varSet(SYNTH_VOICE* svoice, u32 ctrl, u8 index, s16 v) { varSet32(svoice, ctrl, index, v); } + static void mcmdVarCalculation(SYNTH_VOICE* svoice, MSTEP* cstep, u8 op) { - s16 s1; // r28 - s16 s2; // r31 + s16 s1 = 0; // r28 + s16 s2 = 0; // r31 s32 t; // r30 + + s1 = varGet(svoice, (cstep->para[0] >> 24), cstep->para[1]); + if (op == 4) { + s2 = cstep->para[1] >> 8; + } else { + s2 = varGet(svoice, (u8)(cstep->para[1] >> 8), cstep->para[1] >> 16); + } + switch (op) { + case 4: + case 0: + t = (s1 + s2); + break; + case 1: + t = (s1 - s2); + break; + case 2: + t = (s1 * s2); + break; + case 3: + if (s2 != 0) { + t = (s1 / s2); + } else { + t = 0; + } + break; + } + + varSet(svoice, (u8)(cstep->para[0] >> 8), (u8)(cstep->para[0] >> 0x10), + (t < -0x8000 ? -0x8000 + : t > 0x7FFF ? 0x7FFF + : t)); +} + +static void mcmdSetVarImmediate(SYNTH_VOICE* svoice, MSTEP* cstep) { + varSet(svoice, (u8)(cstep->para[0] >> 8), (u8)(cstep->para[0] >> 0x10), (s16)cstep->para[1]); } -static void mcmdSetVarImmediate(SYNTH_VOICE* svoice, MSTEP* cstep) {} static void mcmdIfVarCompare(SYNTH_VOICE* svoice, MSTEP* cstep, u8 cmp) { s32 a; // r28 s32 b; // r27 u8 result; // r30 + + a = varGet32(svoice, (u8)(cstep->para[0] >> 8), (u8)(cstep->para[0] >> 0x10)); + b = varGet32(svoice, (u8)(cstep->para[0] >> 0x18), (u8)cstep->para[1]); + + switch (cmp) { + case 0: + result = (u16) !(b - a); + break; + case 1: + result = (a < b); + break; + } + + if ((u8)(cstep->para[1] >> 8) != 0) { + result = !result; + } + if ((u8)result != 0) { + svoice->curAddr = svoice->addr + (u16)(cstep->para[1] >> 0x10); + } } u32 macPostMessage(u32 vid, s32 mesg) { SYNTH_VOICE* sv; // r31 + if ((vid = vidGetInternalId(vid)) != -1 && (sv = &synthVoice[vid & 0xFF])->mesgNum < 4) { + ++sv->mesgNum; + sv->mesgQueue[sv->mesgWrite] = mesg; + sv->mesgWrite = (sv->mesgWrite + 1) & 3; + ExecuteTrap(sv, 2); + return 1; + } + + return 0; } static void mcmdSendMessage(SYNTH_VOICE* svoice, MSTEP* cstep) { u8 i; // r31 s32 mesg; // r30 u16 macro; // r28 + + mesg = varGet32(svoice, 0, (u8)(cstep->para[1] >> 8)); + + if (!(u8)(cstep->para[0] >> 8)) { + macro = (u16)(cstep->para[0] >> 16); + if (macro != 0xFFFF) { + for (i = 0; i < synthInfo.voiceNum; ++i) { + if (synthVoice[i].addr != NULL && macro == synthVoice[i].macroId) { + macPostMessage(synthVoice[i].vidList->vid, mesg); + } + } + } else if (synthMessageCallback != NULL) { + synthMessageCallback(svoice->vidList->vid, mesg); + } + } else { + macPostMessage(varGet32(svoice, 0, (u8)cstep->para[1]), mesg); + } } + static void mcmdGetMessage(SYNTH_VOICE* svoice, MSTEP* cstep) { s32 mesg; // r30 + mesg = 0; + if (svoice->mesgNum != '\0') { + mesg = svoice->mesgQueue[svoice->mesgRead]; + svoice->mesgRead = (svoice->mesgRead + 1) & 3; + --svoice->mesgNum; + } + varSet32(svoice, 0, (u8)(cstep->para[0] >> 8), mesg); +} +static void mcmdGetVID(SYNTH_VOICE* svoice, MSTEP* cstep) { + if ((u8)(cstep->para[0] >> 0x10) == 0) { + varSet32(svoice, 0, (u8)(cstep->para[0] >> 8), svoice->vidList->vid); + } else { + varSet32(svoice, 0, (u8)(cstep->para[0] >> 8), svoice->lastVID); + } +} +static void mcmdModeSelect(SYNTH_VOICE* svoice, MSTEP* cstep) { + svoice->volTable = (u8)(cstep->para[0] >> 8) ? TRUE : FALSE; + svoice->itdMode = (u8)(cstep->para[0] >> 0x10) ? FALSE : TRUE; +} +static void mcmdSRCModeSelect(SYNTH_VOICE* svoice, MSTEP* cstep) { + hwSetSRCType(svoice->id & 0xff, (u8)(cstep->para[0] >> 8)); + hwSetPolyPhaseFilter(svoice->id & 0xff, (u8)(cstep->para[0] >> 0x10)); + svoice->cFlags |= 0x80000000000; } -static void mcmdGetVID(SYNTH_VOICE* svoice, MSTEP* cstep) {} -static void mcmdModeSelect(SYNTH_VOICE* svoice, MSTEP* cstep) {} -static void mcmdSRCModeSelect(SYNTH_VOICE* svoice, MSTEP* cstep) {} static void mcmdSetKeyGroup(SYNTH_VOICE* svoice, MSTEP* cstep) { u32 i; // r31 u8 kg; // r30 u32 kill; // r29 + + svoice->keyGroup = 0; + kg = (u8)(cstep->para[0] >> 8); + kill = (u8)(cstep->para[0] >> 0x10) != 0; + + if (kg) { + for (i = 0; i < synthInfo.voiceNum; ++i) { + if (synthVoice[i].addr != NULL && (synthVoice[i].cFlags & 0x2) == 0 && + kg == synthVoice[i].keyGroup) { + if (!kill) { + macSetExternalKeyoff(&synthVoice[i]); + } else { + voiceKill(i); + } + } + } + svoice->keyGroup = kg; + } +} +static void mcmdSetupTremolo(SYNTH_VOICE* svoice, MSTEP* cstep) { + svoice->treScale = (cstep->para[0] >> 8); + svoice->treModAddScale = cstep->para[1]; + svoice->treCurScale = 1.f; } -static void mcmdSetupTremolo(SYNTH_VOICE* svoice, MSTEP* cstep) {} static void macHandleActive(SYNTH_VOICE* svoice) { u8 i; // r29 @@ -848,16 +1162,12 @@ static void macHandleActive(SYNTH_VOICE* svoice) { synthStartSynthJobHandling(svoice); } -#ifdef _DEBUG DebugMacroSteps = 0; -#endif do { -#ifdef _DEBUG if (++DebugMacroSteps > 32) { break; } -#endif cstep.para[0] = svoice->curAddr->para[0]; cstep.para[1] = svoice->curAddr->para[1]; @@ -1112,22 +1422,21 @@ void macHandle(u32 deltaTime) { SYNTH_VOICE* nextSv; // r30 u64 w; // r28 - for (nextSv = macTimeQueueRoot; nextSv != NULL && nextSv->wait <= macRealTime;) { - sv = nextSv->nextTimeQueueMacro; - w = nextSv->wait; - macMakeActive(nextSv); - nextSv->waitTime = w; - nextSv = sv; + for (sv = macTimeQueueRoot; sv != NULL && sv->wait <= macRealTime;) { + nextSv = sv->nextTimeQueueMacro; + w = sv->wait; + macMakeActive(sv); + sv->waitTime = w; + sv = nextSv; } - nextSv = macActiveMacroRoot; - while (nextSv != NULL) { - if (HasHWEventTrap(nextSv) != 0) { - CheckHWEventTrap(nextSv); + sv = macActiveMacroRoot; + for (; sv != NULL; sv = sv->nextMacActive) { + if (HasHWEventTrap(sv) != 0) { + CheckHWEventTrap(sv); } - macHandleActive(nextSv); - nextSv = nextSv->nextMacActive; + macHandleActive(sv); } macRealTime += deltaTime; } @@ -1137,7 +1446,7 @@ void macSampleEndNotify(SYNTH_VOICE* sv) { return; } #line 3156 /* clang-format off */ - ASSERT(sv->addr!=NULL); + MUSY_ASSERT(sv->addr!=NULL); /* clang-format on */ if (!ExecuteTrap(sv, 1) && (sv->cFlags & 0x40000)) { @@ -1231,7 +1540,7 @@ void macMakeActive(SYNTH_VOICE* sv) { return; } #line 3297 /* clang-format off */ - ASSERT(sv->addr!=NULL); + MUSY_ASSERT(sv->addr!=NULL); /* clang-format on */ UnYieldMacro(sv, 0); if (sv->nextMacActive = macActiveMacroRoot) { @@ -1248,7 +1557,7 @@ void macMakeInactive(SYNTH_VOICE* svoice, MAC_STATE newState) { } #line 3333 /* clang-format off */ - ASSERT(svoice->addr!=NULL); + MUSY_ASSERT(svoice->addr!=NULL); /* clang-format on */ if (svoice->macState == MAC_STATE_RUNNABLE) { if (svoice->prevMacActive == NULL) { diff --git a/src/musyx/runtime/synthvoice.c b/src/musyx/runtime/synthvoice.c index 87f0d4fb..5013a182 100644 --- a/src/musyx/runtime/synthvoice.c +++ b/src/musyx/runtime/synthvoice.c @@ -1,4 +1,4 @@ -#include "musyx/assert.h" + #include "musyx/musyx_priv.h" void voiceResetLastStarted(SYNTH_VOICE* svoice); @@ -205,13 +205,13 @@ void voiceRemovePriority(SYNTH_VOICE* svoice) { return; } - if (vps->prev != 0xff) { + if (vps->prev != 0xFF) { voicePrioSortVoices[vps->prev].next = vps->next; } else { voicePrioSortVoicesRoot[svoice->prio] = vps->next; } - if (vps->next != 0xff) { + if (vps->next != 0xFF) { voicePrioSortVoices[vps->next].prev = vps->prev; } else if (vps->prev == 0xFF) { rps = &voicePrioSortRootList[svoice->prio]; @@ -231,14 +231,61 @@ void voiceRemovePriority(SYNTH_VOICE* svoice) { vps->user = 0; } -#pragma dont_inline on void voiceSetPriority(SYNTH_VOICE* svoice, u8 prio) { u16 i; // r29 u16 li; // r25 SYNTH_VOICELIST* vps; // r27 u32 v; // r26 + v = (u8)svoice->id; + vps = &voicePrioSortVoices[v]; + if (vps->user == 1) { + if (svoice->prio == prio) { + return; + } + + voiceRemovePriority(svoice); + } + + vps->user = 1; + vps->prev = 0xff; + if ((vps->next = voicePrioSortVoicesRoot[prio]) != 0xFF) { + voicePrioSortVoices[voicePrioSortVoicesRoot[prio]].prev = v; + } else { + if (voicePrioSortRootListRoot != 0xFFFF) { + if (prio >= voicePrioSortRootListRoot) { + for (i = voicePrioSortRootListRoot; i != 0xFFFF; i = voicePrioSortRootList[i].next) { + if ((u16)i > prio) { + break; + } + li = i; + } + + voicePrioSortRootList[li].next = (u16)prio; + voicePrioSortRootList[prio].prev = li; + voicePrioSortRootList[prio].next = i; + if (i != 0xFFFF) { + voicePrioSortRootList[i].prev = prio; + } + + } else { + voicePrioSortRootList[prio].next = voicePrioSortRootListRoot; + voicePrioSortRootList[prio].prev = 0xFFFF; + voicePrioSortRootList[voicePrioSortRootListRoot].prev = prio; + voicePrioSortRootListRoot = prio; + } + } else { + voicePrioSortRootList[prio].next = 0xFFFF; + voicePrioSortRootList[prio].prev = 0xFFFF; + voicePrioSortRootListRoot = prio; + } + } + + voicePrioSortVoicesRoot[prio] = v; + svoice->prio = prio; + hwSetPriority((u8)svoice->id, (((u32)prio << 24) | ((u32)svoice->age >> 15))); } +#pragma dont_inline on u32 voiceAllocate(u8 priority, u8 maxVoices, u16 allocId, u8 fxFlag) { long i; // r31 long num; // r26 @@ -253,7 +300,7 @@ void voiceFree(SYNTH_VOICE* svoice) { u32 i; // r29 SYNTH_VOICELIST* sfv; // r30 #line 628 - ASSERT(svoice->id != 0xFFFFFFFF); + MUSY_ASSERT(svoice->id != 0xFFFFFFFF); #line 256 macMakeInactive(svoice, MAC_STATE_STOPPED); voiceRemovePriority(svoice); @@ -306,14 +353,16 @@ void synthInitAllocationAids() { } u32 voiceBlock(unsigned char prio) { - u32 voice = voiceAllocate(prio, 0xFF, 0xFFFF, 1); + u32 voice; - if (voice != 0xFFFFFFFF) { + if ((voice = voiceAllocate(prio, 0xFF, 0xFFFF, 1)) != 0xFFFFFFFF) { synthVoice[voice].block = 1; synthVoice[voice].fxFlag = 1; -#ifdef PRIME1 + +#if MUSY_VERSION >= MUSY_VERSION_CHECK(1, 5, 4) synthVoice[voice].allocId = 0xFFFF; #endif + vidRemoveVoiceReferences(&synthVoice[voice]); synthVoice[voice].id = voice | 0xFFFFFF00; @@ -360,24 +409,17 @@ void voiceKill(u32 vi) { } long voiceKillSound(u32 voiceid) { - long ret; - u32 next_voiceid; - u32 i; - u32 vid; - - ret = -1; - + s32 ret = -1; // r29 + u32 next_voiceid; // r28 + u32 i; // r30 if (sndActive != FALSE) { - i = vidGetInternalId(voiceid); - - while (i != 0xFFFFFFFF) { - vid = i & 0xFF; - next_voiceid = synthVoice[vid].child; - if (i == synthVoice[vid].id) { - voiceKill(vid); + for (i = vidGetInternalId(voiceid); i != 0xFFFFFFFF; i = next_voiceid) { + voiceid = (u8)i; + next_voiceid = synthVoice[voiceid].child; + if (i == synthVoice[voiceid].id) { + voiceKill(voiceid); ret = 0; } - i = next_voiceid; } } diff --git a/src/musyx/txwin/txwin.c b/src/musyx/txwin/txwin.c index 00535965..739cb6d5 100644 --- a/src/musyx/txwin/txwin.c +++ b/src/musyx/txwin/txwin.c @@ -34,12 +34,12 @@ void winInit() { sWIN* winOpenWindow(s32 x1, s32 y1, s32 x2, s32 y2, char* caption, void* func, u32 flags) { sWIN* handle; // r31 #line 109 - ASSERT_MSG(x1 < x2, "TXWIN: Illegal X coords for window\n"); - ASSERT_MSG(y1 < y2, "TXWIN: Illegal y coords for window\n"); + MUSY_ASSERT_MSG(x1 < x2, "TXWIN: Illegal X coords for window\n"); + MUSY_ASSERT_MSG(y1 < y2, "TXWIN: Illegal y coords for window\n"); handle = OSAlloc(sizeof(sWIN)); - ASSERT_MSG(handle != NULL, "TXWIN: FAILED TO ALLOCATE WINDOW!\n"); + MUSY_ASSERT_MSG(handle != NULL, "TXWIN: FAILED TO ALLOCATE WINDOW!\n"); __win_add_node(handle); handle->x1 = x1; handle->y1 = y1; @@ -70,7 +70,7 @@ sWIN* winOpenLogWindow(s32 x1, s32 y1, s32 x2, s32 y2, char* caption, u16 num_li handle->buffer = OSAlloc(handle->total_lines * 4); #line 192 - ASSERT_MSG(handle->buffer != NULL, "TXWIN: Unable to allocate log window buffer.\n"); + MUSY_ASSERT_MSG(handle->buffer != NULL, "TXWIN: Unable to allocate log window buffer.\n"); for (i = 0; i < handle->total_lines; ++i) { @@ -78,7 +78,7 @@ sWIN* winOpenLogWindow(s32 x1, s32 y1, s32 x2, s32 y2, char* caption, u16 num_li memset(handle->buffer[i], 0, handle->char_width + 1); - ASSERT_MSG(handle->buffer[i] != NULL, "TXWIN: Failed to allocate buffer element\n"); + MUSY_ASSERT_MSG(handle->buffer[i] != NULL, "TXWIN: Failed to allocate buffer element\n"); } return handle; @@ -145,7 +145,7 @@ void winSetFontSize(u16 size) { void winRefresh() { sWIN* ptr; #line 338 - ASSERT_MSG(__FirstNode != NULL, ">> winRefresh(): window list is empty!\n"); + MUSY_ASSERT_MSG(__FirstNode != NULL, ">> winRefresh(): window list is empty!\n"); ptr = __FirstNode; DEMOInitCaption(2, __X_Res, __Y_Res); @@ -160,7 +160,7 @@ void winRefresh() { } void __win_add_node(sWIN* handle) { #line 390 - ASSERT_MSG(handle != NULL, "__add_node(): you're adding a NULL node!\n"); + MUSY_ASSERT_MSG(handle != NULL, "__add_node(): you're adding a NULL node!\n"); if ((sWIN*)NULL == __LastNode) { @@ -174,7 +174,7 @@ void __win_add_node(sWIN* handle) { handle->prev = NULL; - ASSERT_MSG(__FirstNode != NULL, " > __FirstNode: NULL HANDLE!\n"); + MUSY_ASSERT_MSG(__FirstNode != NULL, " > __FirstNode: NULL HANDLE!\n"); } else { __LastNode->next = handle; handle->next = NULL; @@ -185,7 +185,7 @@ void __win_add_node(sWIN* handle) { void __win_delete_node(sWIN* handle) { #line 434 - ASSERT_MSG(handle != NULL, "__delete_node(): you're deleting a NULL node!\n"); + MUSY_ASSERT_MSG(handle != NULL, "__delete_node(): you're deleting a NULL node!\n"); if (__FirstNode == handle) { if (handle->next != NULL) { @@ -213,21 +213,19 @@ void __win_delete_node(sWIN* handle) { } void __win_log_refresh(struct STRUCT_WIN* handle) { - u32 uVar1; - int iVar2; unsigned short n; // r30 unsigned short i; // r29 unsigned short x; // r28 unsigned short y; // r27 unsigned short index; // r1+0xC #line 506 - ASSERT_MSG(handle != NULL, "OHMYGAWD\n"); + MUSY_ASSERT_MSG(handle != NULL, "OHMYGAWD\n"); n = (u32)handle->curr_output_line; x = handle->x1; y = handle->y2; i = 0; for (i = 0; i < handle->char_height; ++i) { - n = index = (u16)(n + (handle->total_lines - 1)) % (u32)handle->total_lines; + n = index + (u16)(n + (handle->total_lines - 1)) % (u32)handle->total_lines; DEMOPrintf(x, (y + i) % 2, 0, "%s", handle->buffer[index]); } }