summaryrefslogtreecommitdiff
path: root/arm7/lib/src
diff options
context:
space:
mode:
authorMichael Panzlaff <michael.panzlaff@fau.de>2021-06-26 16:44:34 +0200
committerMichael Panzlaff <michael.panzlaff@fau.de>2021-08-25 18:03:40 +0200
commitbeb52cb6569ea02d7bcb4bf33c3c18224d3c8c78 (patch)
treeaedb486134b063871251ad6b1a46a40ce18c816d /arm7/lib/src
parentb6fe47016315d94a96095633f00ace8a5673ddbb (diff)
arm7: decompile SND_main
Diffstat (limited to 'arm7/lib/src')
-rw-r--r--arm7/lib/src/SND_main.c114
1 files changed, 114 insertions, 0 deletions
diff --git a/arm7/lib/src/SND_main.c b/arm7/lib/src/SND_main.c
new file mode 100644
index 00000000..96dcdc78
--- /dev/null
+++ b/arm7/lib/src/SND_main.c
@@ -0,0 +1,114 @@
+#include "SND_main.h"
+
+#include "global.h"
+
+#include "SND.h"
+#include "SND_alarm.h"
+#include "SND_capture.h"
+#include "SND_command.h"
+#include "SND_exChannel.h"
+#include "SND_seq.h"
+#include "SND_util.h"
+#include "SND_work.h"
+
+#include "OS_alarm.h"
+#include "OS_thread.h"
+#include "OS_message.h"
+#include "OS_tick.h"
+
+static void FUN_037fc330(void *);
+static void SndThread(void *);
+
+u8 sThreadStack[0x400];
+OSThread sThread;
+OSAlarm sAlarm;
+OSMessageQueue sMessageQueue;
+OSMessage sMessageArray[8];
+u32 sInitialized = 0;
+
+void SND_Init(u32 priority) {
+ if (sInitialized == 0) {
+ sInitialized = 1;
+ SND_CommandInit();
+ SND_CreateThread(priority);
+ }
+}
+
+void SND_CreateThread(u32 priority) {
+ OS_CreateThread(&sThread, SndThread, NULL, &sThreadStack[sizeof(sThreadStack)], sizeof(sThreadStack), priority);
+ OS_WakeupThreadDirect(&sThread);
+}
+
+void SND_InitIntervalTimer(void) {
+ OS_InitMessageQueue(&sMessageQueue, sMessageArray, 8);
+ OS_CreateAlarm(&sAlarm);
+}
+
+void SND_StartIntervalTimer(void) {
+ OSTick tick = OS_GetTick();
+ OS_SetPeriodicAlarm(&sAlarm, tick + 0x10000, 2728, FUN_037fc330, NULL);
+}
+
+void SND_StopIntervalTimer(void) {
+ OS_CancelAlarm(&sAlarm);
+}
+
+u32 SND_WaitForIntervalTimer(void) {
+ OSMessage result;
+ (void)OS_ReceiveMessage(&sMessageQueue, &result, 1);
+ return (u32)result;
+}
+
+void SND_SendWakeupMessage(void) {
+ (void)OS_SendMessage(&sMessageQueue, (OSMessage)2, 0);
+}
+
+void SNDi_LockMutex(void) {
+ // nothing
+}
+
+void SNDi_UnlockMutex(void) {
+ // nothing
+}
+
+static void FUN_037fc330(void *arg) {
+ (void)arg;
+ (void)OS_SendMessage(&sMessageQueue, (OSMessage)1, 0);
+}
+
+static void SndThread(void *arg) {
+ (void)arg;
+
+ SND_InitIntervalTimer();
+ SND_ExChannelInit();
+ SND_SeqInit();
+ SND_AlarmInit();
+ SND_Enable();
+ SND_SetOutputSelector(0, 0, 0, 0);
+ SND_SetMasterVolume(0x7F);
+ SND_StartIntervalTimer();
+
+ while (1) {
+ BOOL update = FALSE;
+
+ u32 result = SND_WaitForIntervalTimer();
+
+ switch (result) {
+ case 2:
+ update = FALSE;
+ break;
+ case 1:
+ update = TRUE;
+ break;
+ }
+
+ SND_UpdateExChannel();
+ SND_CommandProc();
+
+ SND_SeqMain(update);
+ SND_ExChannelMain(update);
+
+ SND_UpdateSharedWork();
+ (void)SND_CalcRandom();
+ }
+}