From d70906fee7bcb51433bac4df78b660ee7559d974 Mon Sep 17 00:00:00 2001 From: engineer124 Date: Sun, 3 Oct 2021 16:29:33 +1100 Subject: [PATCH 1/4] Voice progress --- include/functions.h | 14 +++++----- include/os.h | 10 +++++++ src/libultra/voice/voicecheckresult.c | 20 +++++++++++++- src/libultra/voice/voicecleardictionary.c | 31 +++++++++++++++++++++- src/libultra/voice/voicecrc.c | 32 ++++++++++++++++++++++- 5 files changed, 97 insertions(+), 10 deletions(-) diff --git a/include/functions.h b/include/functions.h index 367d784ae..fab8136ba 100644 --- a/include/functions.h +++ b/include/functions.h @@ -355,11 +355,11 @@ void guLookAtHiliteF(float mf[4][4], LookAt* l, Hilite* h, f32 xEye, f32 yEye, f void guLookAtHilite(Mtx* m, LookAt* l, Hilite* h, f32 xEye, f32 yEye, f32 zEye, f32 xAt, f32 yAt, f32 zAt, f32 xUp, f32 yUp, f32 zUp, f32 xl1, f32 yl1, f32 zl1, f32 xl2, f32 yl2, f32 zl2, s32 twidth, s32 theight); s32 _Printf(PrintCallback pfn, void* arg, const char* fmt, va_list ap); void _Putfld(_Pft* px, va_list* pap, u8 code, u8* ac); -// void osVoiceClearDictionary(void); +s32 osVoiceClearDictionary(OSVoiceHandle* hd, u8 words); void osUnmapTLBAll(void); s32 osEPiStartDma(OSPiHandle* pihandle, OSIoMesg* mb, s32 direction); -// void __osVoiceContRead2(void); -// void __osVoiceContDataCrc(void); +s32 __osVoiceContRead2(OSMesgQueue* mq, s32 port, s32, u8 dst[2]); +u8 __osVoiceContDataCrc(u8* data, u32 arg1); const char* strchr(const char* __s, s32 __c); size_t strlen(const char* __s); void* memcpy(void* __dest, const void* __src, size_t __n); @@ -388,7 +388,7 @@ OSTime osGetTime(void); 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); -// void osVoiceInit(void); +s32 osVoiceInit(OSMesgQueue* siMessageQ, OSVoiceHandle* hd, s32 channel); // void __osContChannelReset(void); // void __osVoiceSetADConverter(void); s32 osAiSetFrequency(u32 frequency); @@ -418,7 +418,7 @@ f32 __cosf(f32 __x); void osViSetSpecialFeatures(u32 func); s16 coss(u16 x); void osSetTime(OSTime ticks); -// void osVoiceStopReadData(void); +s32 osVoiceStopReadData(OSVoiceHandle* hd); void osViSetEvent(OSMesgQueue* mq, OSMesg m, u32 retraceCount); s32 osPfsIsPlug(OSMesgQueue* queue, u8* pattern); // void __osPfsRequestData(void); @@ -473,11 +473,11 @@ float __ll_to_f(long long l); double __ull_to_d(unsigned long long l); float __ull_to_f(unsigned long long l); // void osVoiceCheckWord(void); -// void osVoiceControlGain(void); +s32 osVoiceControlGain(OSVoiceHandle *hd, s32 analog, s32 digital); // void osVoiceStartReadData(void); void* osViGetCurrentFramebuffer(void); s32 __osSpSetPc(void* data); -// void __osVoiceContWrite4(void); +// s32 __osVoiceContWrite4(OSMesgQueue* hd, s32 arg1, s32 arg2, OSVoiceData* voiceData); void __osGetHWIntrRoutine(s32 idx, OSMesgQueue** outQueue, OSMesg* outMsg); // void __osSetHWIntrRoutine(void); u32 __osGetWatchLo(void); diff --git a/include/os.h b/include/os.h index 50f3b10c4..cdfa49c91 100644 --- a/include/os.h +++ b/include/os.h @@ -131,4 +131,14 @@ typedef struct { /* 0xC */ u8 status; } OSVoiceHandle; // size = 0x10 +typedef struct { + /* 0x00 */ u16 warning; /* Warning */ + /* 0x02 */ u16 answer_num; /* Candidate number (0~5) */ + /* 0x04 */ u16 voice_level; /* Voice input level */ + /* 0x06 */ u16 voice_sn; /* Relative voice level */ + /* 0x08 */ u16 voice_time; /* Voice input time */ + /* 0x0A */ u16 answer[5]; /* Candidate word number */ + /* 0x14 */ u16 distance[5]; /* Distance value */ +} OSVoiceData; // size = 0x20 + #endif diff --git a/src/libultra/voice/voicecheckresult.c b/src/libultra/voice/voicecheckresult.c index 44fb69be5..bd4060a37 100644 --- a/src/libultra/voice/voicecheckresult.c +++ b/src/libultra/voice/voicecheckresult.c @@ -1,3 +1,21 @@ #include "global.h" -#pragma GLOBAL_ASM("asm/non_matchings/boot/voicecheckresult/__osVoiceCheckResult.s") +s32 __osVoiceCheckResult(OSVoiceHandle* handle, u8* status) { + s32 phi_v1; + u8 sp20[2]; + + if (phi_v1 = __osVoiceGetStatus(handle->mq, handle->port, status), phi_v1 == 0) { + if (*status & 1) { + phi_v1 = 0xF; + } else if (phi_v1 = __osVoiceContRead2(handle->mq, handle->port, 0, sp20), phi_v1 == 0) { + handle->status = sp20[0] & 7; + + if (sp20[0] & 0x40) { + phi_v1 = 0xF; + } else { + phi_v1 = sp20[1] << 8; + } + } + } + return phi_v1; +} diff --git a/src/libultra/voice/voicecleardictionary.c b/src/libultra/voice/voicecleardictionary.c index d6278d3fa..4de1eef59 100644 --- a/src/libultra/voice/voicecleardictionary.c +++ b/src/libultra/voice/voicecleardictionary.c @@ -1,4 +1,33 @@ #include "global.h" // Initializes Voice Recognition System word registration dictionary -#pragma GLOBAL_ASM("asm/non_matchings/boot/voicecleardictionary/osVoiceClearDictionary.s") +s32 osVoiceClearDictionary(OSVoiceHandle* hd, u8 words) { + u8* registration_word; + u8 status; + s32 sp24; + s32 temp_v0; + + temp_v0 = __osVoiceGetStatus(hd->mq, hd->port, &status); + if (temp_v0 != 0) { + return temp_v0; + } + + registration_word = &sp24; + if (status & 2) { + return 0xF; + } + + sp24 = 0x2000000; + registration_word[2] = words; + + temp_v0 = __osVoiceContWrite4(hd->mq, hd->port, 0, registration_word); + if (temp_v0 != 0) { + return temp_v0; + } + + temp_v0 = __osVoiceCheckResult(hd, &status); + if ((temp_v0 & 0xFF00) != 0) { + temp_v0 = 5; + } + return temp_v0; +} diff --git a/src/libultra/voice/voicecrc.c b/src/libultra/voice/voicecrc.c index cc23e89dd..e1530fcb8 100644 --- a/src/libultra/voice/voicecrc.c +++ b/src/libultra/voice/voicecrc.c @@ -1,3 +1,33 @@ #include "global.h" -#pragma GLOBAL_ASM("asm/non_matchings/boot/voicecrc/__osVoiceContDataCrc.s") +u8 __osVoiceContDataCrc(u8* data, u32 arg1) { + u32 bit; + u32 byte; + u32 ret = 0; + + for (byte = arg1; byte > 0; byte--) { + for (bit = 0x80; bit > 0; bit >>= 1) { + ret <<= 1; + if (*data & bit) { + if (ret & 0x100) { + ret ^= 0x84; + } else { + ret++; + } + } else if (ret & 0x100) { + ret ^= 0x85; + } + } + data++; + } + + do { + ret <<= 1; + if (ret & 0x100) { + ret ^= 0x85; + } + byte++; + } while (byte < 8); + + return ret; +} From 357ee948bb6f43f80ad988e2e306b71f47db673f Mon Sep 17 00:00:00 2001 From: engineer124 Date: Sun, 3 Oct 2021 17:32:28 +1100 Subject: [PATCH 2/4] Match osVoiceControlGain --- include/functions.h | 4 +-- src/libultra/voice/voicecontrolgain.c | 37 ++++++++++++++++++++++++++- 2 files changed, 38 insertions(+), 3 deletions(-) diff --git a/include/functions.h b/include/functions.h index fab8136ba..431376e1e 100644 --- a/include/functions.h +++ b/include/functions.h @@ -390,7 +390,7 @@ 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); -// void __osVoiceSetADConverter(void); +s32 __osVoiceSetADConverter(OSMesgQueue* mq, s32 port, u8 arg2, OSVoiceHandle* hd); s32 osAiSetFrequency(u32 frequency); s32 __osContRamRead(OSMesgQueue* mq, s32 channel, u16 address, u8* buffer); // void __osVoiceContWrite20(void); @@ -477,7 +477,7 @@ s32 osVoiceControlGain(OSVoiceHandle *hd, s32 analog, s32 digital); // void osVoiceStartReadData(void); void* osViGetCurrentFramebuffer(void); s32 __osSpSetPc(void* data); -// s32 __osVoiceContWrite4(OSMesgQueue* hd, s32 arg1, s32 arg2, OSVoiceData* voiceData); +s32 __osVoiceContWrite4(OSMesgQueue* hd, s32 arg1, s32 arg2, OSVoiceData* voiceData); void __osGetHWIntrRoutine(s32 idx, OSMesgQueue** outQueue, OSMesg* outMsg); // void __osSetHWIntrRoutine(void); u32 __osGetWatchLo(void); diff --git a/src/libultra/voice/voicecontrolgain.c b/src/libultra/voice/voicecontrolgain.c index d4020e605..cfca63fbb 100644 --- a/src/libultra/voice/voicecontrolgain.c +++ b/src/libultra/voice/voicecontrolgain.c @@ -1,4 +1,39 @@ #include "global.h" +extern u8 D_80098180[]; + // Adjusts the input gain of the Voice Recognition System -#pragma GLOBAL_ASM("asm/non_matchings/boot/voicecontrolgain/osVoiceControlGain.s") +s32 osVoiceControlGain(OSVoiceHandle* hd, s32 analog, s32 digital) { + s32 ret; + u8 phi_a2; + + + if (analog == 0) { + phi_a2 = 0x18; + } else { + phi_a2 = 0x98; + } + + ret = __osVoiceSetADConverter(hd->mq, hd->port, phi_a2, hd); + if (ret != 0) { + return ret; + } + + if (!((digital < 8) && (digital >= 0))){ + goto dummy; + } + + phi_a2 = D_80098180[digital] + 2; + + if (0) { + dummy: + return 5; + } + + ret = __osVoiceSetADConverter(hd->mq, hd->port, phi_a2, hd); + if (ret != 0) { + return ret; + } + + return ret; +} From 6cbf9734a7dbfb8997a79033fbca7565642d8117 Mon Sep 17 00:00:00 2001 From: engineer124 Date: Sun, 3 Oct 2021 17:43:53 +1100 Subject: [PATCH 3/4] Match osVoiceStartReadData --- include/functions.h | 6 ++--- src/libultra/voice/voicecheckresult.c | 8 +++--- src/libultra/voice/voicestartreaddata.c | 33 ++++++++++++++++++++++++- 3 files changed, 39 insertions(+), 8 deletions(-) diff --git a/include/functions.h b/include/functions.h index 431376e1e..b0b68959d 100644 --- a/include/functions.h +++ b/include/functions.h @@ -280,7 +280,7 @@ void __osDispatchThread(void); void __osCleanupThread(void); void __osDequeueThread(OSThread** param_1, OSThread* param_2); void osDestroyThread(OSThread* puParm1); -// void __osVoiceCheckResult(void); +s32 __osVoiceCheckResult(OSVoiceHandle* hd, u8* status); void bzero(void* begin, s32 length); // void osSetRumble(void); // void osSetUpMempakWrite(void); @@ -473,8 +473,8 @@ float __ll_to_f(long long l); double __ull_to_d(unsigned long long l); float __ull_to_f(unsigned long long l); // void osVoiceCheckWord(void); -s32 osVoiceControlGain(OSVoiceHandle *hd, s32 analog, s32 digital); -// void osVoiceStartReadData(void); +s32 osVoiceControlGain(OSVoiceHandle* hd, s32 analog, s32 digital); +s32 osVoiceStartReadData(OSVoiceHandle* hd); void* osViGetCurrentFramebuffer(void); s32 __osSpSetPc(void* data); s32 __osVoiceContWrite4(OSMesgQueue* hd, s32 arg1, s32 arg2, OSVoiceData* voiceData); diff --git a/src/libultra/voice/voicecheckresult.c b/src/libultra/voice/voicecheckresult.c index bd4060a37..a20c88461 100644 --- a/src/libultra/voice/voicecheckresult.c +++ b/src/libultra/voice/voicecheckresult.c @@ -1,14 +1,14 @@ #include "global.h" -s32 __osVoiceCheckResult(OSVoiceHandle* handle, u8* status) { +s32 __osVoiceCheckResult(OSVoiceHandle* hd, u8* status) { s32 phi_v1; u8 sp20[2]; - if (phi_v1 = __osVoiceGetStatus(handle->mq, handle->port, status), phi_v1 == 0) { + if (phi_v1 = __osVoiceGetStatus(hd->mq, hd->port, status), phi_v1 == 0) { if (*status & 1) { phi_v1 = 0xF; - } else if (phi_v1 = __osVoiceContRead2(handle->mq, handle->port, 0, sp20), phi_v1 == 0) { - handle->status = sp20[0] & 7; + } else if (phi_v1 = __osVoiceContRead2(hd->mq, hd->port, 0, sp20), phi_v1 == 0) { + hd->status = sp20[0] & 7; if (sp20[0] & 0x40) { phi_v1 = 0xF; diff --git a/src/libultra/voice/voicestartreaddata.c b/src/libultra/voice/voicestartreaddata.c index 118cc3f60..809ee805e 100644 --- a/src/libultra/voice/voicestartreaddata.c +++ b/src/libultra/voice/voicestartreaddata.c @@ -1,4 +1,35 @@ #include "global.h" // Start voice recognition by the Voice Recognition System -#pragma GLOBAL_ASM("asm/non_matchings/boot/voicestartreaddata/osVoiceStartReadData.s") +s32 osVoiceStartReadData(OSVoiceHandle* hd) { + s32 temp_v0; + u8 sp2B; + s32 sp24; + + temp_v0 = __osVoiceGetStatus(hd->mq, hd->port, &sp2B); + if (temp_v0 != 0) { + return temp_v0; + } + + if ((sp2B & 2) != 0) { + return 0xF; + } + + if (hd->mode != 0) { + return 5; + } + + sp24 = 0x5000000; + temp_v0 = __osVoiceContWrite4(hd->mq, hd->port, 0, &sp24); + + if (temp_v0 == 0) { + temp_v0 = __osVoiceCheckResult(hd, &sp2B); + if ((temp_v0 & 0xFF00) != 0) { + temp_v0 = 5; + } else { + hd->mode = 1; + } + } + + return temp_v0; +} From d1225a5634892d15e770e6aa1fc6c4852c1afdc0 Mon Sep 17 00:00:00 2001 From: engineer124 Date: Sun, 3 Oct 2021 17:45:24 +1100 Subject: [PATCH 4/4] Cleanup --- src/libultra/voice/voicestartreaddata.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/src/libultra/voice/voicestartreaddata.c b/src/libultra/voice/voicestartreaddata.c index 809ee805e..e0e696749 100644 --- a/src/libultra/voice/voicestartreaddata.c +++ b/src/libultra/voice/voicestartreaddata.c @@ -2,13 +2,13 @@ // Start voice recognition by the Voice Recognition System s32 osVoiceStartReadData(OSVoiceHandle* hd) { - s32 temp_v0; + s32 ret; u8 sp2B; s32 sp24; - temp_v0 = __osVoiceGetStatus(hd->mq, hd->port, &sp2B); - if (temp_v0 != 0) { - return temp_v0; + ret = __osVoiceGetStatus(hd->mq, hd->port, &sp2B); + if (ret != 0) { + return ret; } if ((sp2B & 2) != 0) { @@ -20,16 +20,17 @@ s32 osVoiceStartReadData(OSVoiceHandle* hd) { } sp24 = 0x5000000; - temp_v0 = __osVoiceContWrite4(hd->mq, hd->port, 0, &sp24); + ret = __osVoiceContWrite4(hd->mq, hd->port, 0, &sp24); - if (temp_v0 == 0) { - temp_v0 = __osVoiceCheckResult(hd, &sp2B); - if ((temp_v0 & 0xFF00) != 0) { - temp_v0 = 5; + if (ret == 0) { + ret = __osVoiceCheckResult(hd, &sp2B); + + if ((ret & 0xFF00) != 0) { + ret = 5; } else { hd->mode = 1; } } - return temp_v0; + return ret; }