From 5459a9e781791eea6138ac79a22ff3a49b5aa62a Mon Sep 17 00:00:00 2001 From: engineer124 Date: Tue, 9 Nov 2021 00:06:50 +1100 Subject: [PATCH] Match osVoiceSetWord --- include/functions.h | 2 +- src/libultra/voice/voicesetword.c | 58 ++++++++++++++++++++++++++++++- 2 files changed, 58 insertions(+), 2 deletions(-) diff --git a/include/functions.h b/include/functions.h index 5bfe48049..f05849d92 100644 --- a/include/functions.h +++ b/include/functions.h @@ -386,7 +386,7 @@ 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); +s32 __osVoiceContWrite20(OSMesgQueue*, s32, u8, u8*); u8 __osContAddressCrc(u16 addr); u8 __osContDataCrc(u8* data); OSThread* __osGetActiveQueue(void); diff --git a/src/libultra/voice/voicesetword.c b/src/libultra/voice/voicesetword.c index dbc1a6df6..83cf97516 100644 --- a/src/libultra/voice/voicesetword.c +++ b/src/libultra/voice/voicesetword.c @@ -1,4 +1,60 @@ #include "global.h" // Registers words to the Voice Recognition System dictionary -#pragma GLOBAL_ASM("asm/non_matchings/boot/voicesetword/osVoiceSetWord.s") +s32 osVoiceSetWord(OSVoiceHandle* hd, u8* word) { + s32 i; + s32 sp50; + s32 errorCode; + u8 sp4B; + u8 sp20[0x28]; + + errorCode = __osVoiceGetStatus(hd->mq, hd->port, &sp4B); + if (errorCode != 0) { + return errorCode; + } + + if (sp4B & 2) { + return 0xF; + } + + sp50 = 0; + + while (word[sp50] != 0) { + sp50 += 2; + } + + bzero(&sp20, 0x28); + + for (i = 0; i < sp50; i += 2) { + sp20[0x27 - sp50 + i] = word[i]; + sp20[0x27 - sp50 + i - 1] = word[i + 1]; + } + + sp20[0x27 - i - 5] = 3; + + if (sp50 >= 0xF) { + errorCode = __osVoiceContWrite20(hd->mq, hd->port, 0, &sp20); + if (errorCode != 0) { + return errorCode; + } + } + + errorCode = __osVoiceContWrite20(hd->mq, hd->port, 0, &sp20[0x14]); + if (errorCode != 0) { + return errorCode; + } + + errorCode = __osVoiceCheckResult(hd, &sp4B); + + if (errorCode != 0) { + if (errorCode & 0x100) { + errorCode = 0xD; + } else if (errorCode & 0x200) { + errorCode = 0xE; + } else if (errorCode & 0xFF00) { + errorCode = 5; + } + } + + return errorCode; +}