From 5aa43d1c2985a6dec47672024c67a4cc9d14d621 Mon Sep 17 00:00:00 2001 From: engineer124 Date: Mon, 8 Nov 2021 00:27:05 +1100 Subject: [PATCH] Match voiceinit.c --- include/functions.h | 4 +- src/libultra/voice/voicecontrolgain.c | 4 +- src/libultra/voice/voiceinit.c | 57 ++++++++++++++++++++++++++- 3 files changed, 60 insertions(+), 5 deletions(-) diff --git a/include/functions.h b/include/functions.h index 0fff4f8f4..5bfe48049 100644 --- a/include/functions.h +++ b/include/functions.h @@ -382,8 +382,8 @@ void guRotateF(float mf[4][4], f32 a, f32 x, f32 y, f32 z); void guRotate(Mtx* m, f32 a, f32 x, f32 y, f32 z); void __osSetGlobalIntMask(u32 mask); s32 osVoiceInit(OSMesgQueue* siMessageQ, OSVoiceHandle* hd, s32 channel); -// void __osContChannelReset(void); -s32 __osVoiceSetADConverter(OSMesgQueue* mq, s32 port, u8 arg2, OSVoiceHandle* hd); +s32 __osContChannelReset(OSMesgQueue* mq, s32 count); +s32 __osVoiceSetADConverter(OSMesgQueue* mq, s32 port, u8 arg2); s32 osAiSetFrequency(u32 frequency); s32 __osContRamRead(OSMesgQueue* mq, s32 channel, u16 address, u8* buffer); // void __osVoiceContWrite20(void); diff --git a/src/libultra/voice/voicecontrolgain.c b/src/libultra/voice/voicecontrolgain.c index b0a66284a..251dc1144 100644 --- a/src/libultra/voice/voicecontrolgain.c +++ b/src/libultra/voice/voicecontrolgain.c @@ -14,7 +14,7 @@ s32 osVoiceControlGain(OSVoiceHandle* hd, s32 analog, s32 digital) { phi_a2 = 0x98; } - errorCode = __osVoiceSetADConverter(hd->mq, hd->port, phi_a2, hd); + errorCode = __osVoiceSetADConverter(hd->mq, hd->port, phi_a2); if (errorCode != 0) { return errorCode; } @@ -30,7 +30,7 @@ s32 osVoiceControlGain(OSVoiceHandle* hd, s32 analog, s32 digital) { return 5; } - errorCode = __osVoiceSetADConverter(hd->mq, hd->port, phi_a2, hd); + errorCode = __osVoiceSetADConverter(hd->mq, hd->port, phi_a2); if (errorCode != 0) { return errorCode; } diff --git a/src/libultra/voice/voiceinit.c b/src/libultra/voice/voiceinit.c index 69fd1e36e..50dab4fdc 100644 --- a/src/libultra/voice/voiceinit.c +++ b/src/libultra/voice/voiceinit.c @@ -1,4 +1,59 @@ #include "global.h" +extern u8 D_80097FA0; +extern u8 D_80097FA5; + // Initializes Voice Recognition System control structure and hardware -#pragma GLOBAL_ASM("asm/non_matchings/boot/voiceinit/osVoiceInit.s") +s32 osVoiceInit(OSMesgQueue* siMessageQ, OSVoiceHandle* hd, s32 channel) { + s32 errorCode; + u8* phi_s0; + u8 sp37 = 0; + s32 sp30; + s32 pad; + + hd->port = channel; + hd->mq = siMessageQ; + hd->mode = 0; + + errorCode = __osVoiceGetStatus(siMessageQ, channel, &sp37); + if (errorCode != 0) { + return errorCode; + } + + if (__osContChannelReset(siMessageQ, channel) != 0) { + return 4; + } + + for (phi_s0 = &D_80097FA0;;) { + errorCode = __osVoiceSetADConverter(siMessageQ, channel, *phi_s0); + + phi_s0++; + if (errorCode != 0) { + return errorCode; + } + + if (phi_s0 == &D_80097FA5) { + errorCode = __osVoiceGetStatus(siMessageQ, channel, &sp37); + if (errorCode != 0) { + return errorCode; + } + if ((sp37 & 2) != 0) { + return 0xF; + } + + sp30 = 0x100; + errorCode = __osVoiceContWrite4(siMessageQ, channel, 0, &sp30); + if (errorCode != 0) { + return errorCode; + } + + errorCode = __osVoiceCheckResult(hd, &sp37); + if (errorCode & 0xFF00) { + errorCode = 5; + } + + return errorCode; + } + } +} +