diff --git a/include/functions.h b/include/functions.h index e16858aa1..b153e3cdd 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); @@ -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,9 +388,9 @@ 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 __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); @@ -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); -// void osVoiceStartReadData(void); +s32 osVoiceControlGain(OSVoiceHandle* hd, s32 analog, s32 digital); +s32 osVoiceStartReadData(OSVoiceHandle* hd); 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..a20c88461 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* hd, u8* status) { + s32 phi_v1; + u8 sp20[2]; + + if (phi_v1 = __osVoiceGetStatus(hd->mq, hd->port, status), phi_v1 == 0) { + if (*status & 1) { + phi_v1 = 0xF; + } 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; + } 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/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; +} 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; +} diff --git a/src/libultra/voice/voicestartreaddata.c b/src/libultra/voice/voicestartreaddata.c index 118cc3f60..e0e696749 100644 --- a/src/libultra/voice/voicestartreaddata.c +++ b/src/libultra/voice/voicestartreaddata.c @@ -1,4 +1,36 @@ #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 ret; + u8 sp2B; + s32 sp24; + + ret = __osVoiceGetStatus(hd->mq, hd->port, &sp2B); + if (ret != 0) { + return ret; + } + + if ((sp2B & 2) != 0) { + return 0xF; + } + + if (hd->mode != 0) { + return 5; + } + + sp24 = 0x5000000; + ret = __osVoiceContWrite4(hd->mq, hd->port, 0, &sp24); + + if (ret == 0) { + ret = __osVoiceCheckResult(hd, &sp2B); + + if ((ret & 0xFF00) != 0) { + ret = 5; + } else { + hd->mode = 1; + } + } + + return ret; +}