From 6775824c4d71e407dcf98d4a096711a30db32cb9 Mon Sep 17 00:00:00 2001 From: engineer124 Date: Tue, 9 Nov 2021 10:50:33 +1100 Subject: [PATCH] Add error codes --- src/libultra/voice/voicecheckresult.c | 4 ++-- src/libultra/voice/voicecheckword.c | 24 ++++++++++---------- src/libultra/voice/voicecleardictionary.c | 6 ++--- src/libultra/voice/voicecontrolgain.c | 2 +- src/libultra/voice/voicegetreaddata.c | 14 ++++++------ src/libultra/voice/voicegetstatus.c | 27 ++++++++++++----------- src/libultra/voice/voiceinit.c | 16 +++++++------- src/libultra/voice/voicesetword.c | 16 +++++++------- src/libultra/voice/voicestartreaddata.c | 6 ++--- src/libultra/voice/voicestopread.c | 8 +++---- 10 files changed, 62 insertions(+), 61 deletions(-) diff --git a/src/libultra/voice/voicecheckresult.c b/src/libultra/voice/voicecheckresult.c index 97af48094..907376734 100644 --- a/src/libultra/voice/voicecheckresult.c +++ b/src/libultra/voice/voicecheckresult.c @@ -6,12 +6,12 @@ s32 __osVoiceCheckResult(OSVoiceHandle* hd, u8* status) { if (errorCode = __osVoiceGetStatus(hd->mq, hd->port, status), errorCode == 0) { if (*status & 1) { - errorCode = 0xF; + errorCode = CONT_ERR_VOICE_NO_RESPONSE; } else if (errorCode = __osVoiceContRead2(hd->mq, hd->port, 0, sp20), errorCode == 0) { hd->status = sp20[0] & 7; if (sp20[0] & 0x40) { - errorCode = 0xF; + errorCode = CONT_ERR_VOICE_NO_RESPONSE; } else { errorCode = sp20[1] << 8; } diff --git a/src/libultra/voice/voicecheckword.c b/src/libultra/voice/voicecheckword.c index 78b835579..f7c640760 100644 --- a/src/libultra/voice/voicecheckword.c +++ b/src/libultra/voice/voicecheckword.c @@ -13,34 +13,34 @@ s32 osVoiceCheckWord(u8* word) { currentWord = word[i + 1] + (new_var << 8); if (((currentWord != 0x815B) && (currentWord < 0x829F)) || ((currentWord >= 0x82F2) && (currentWord < 0x8340)) || (currentWord == 0x837F) || (currentWord >= 0x8397)) { - errorCode = 0xE; + errorCode = CONT_ERR_VOICE_WORD; } else if ((i == 0) && ((currentWord == 0x815B) || (currentWord == 0x82F1) || (currentWord == 0x82C1) || (currentWord == 0x82EC) || (currentWord == 0x8393) || (currentWord == 0x8362) || (currentWord == 0x838E) || (currentWord == 0x8395) || (currentWord == 0x8396))) { - errorCode = 0xE; + errorCode = CONT_ERR_VOICE_WORD; } else if (((currentWord == 0x829F) || (currentWord == 0x8340)) && (currentWord != 0x82D3) && (currentWord != 0x8374) && (currentWord != 0x8394)) { - errorCode = 0xE; + errorCode = CONT_ERR_VOICE_WORD; } else if (((currentWord == 0x82A1) || (currentWord == 0x8342)) && (currentWord != 0x82A4) && (currentWord != 0x82C4) && (currentWord != 0x82C5) && (currentWord != 0x82D3) && (currentWord != 0x8345) && (currentWord != 0x8365) && (currentWord != 0x8366) && (currentWord != 0x8374) && (currentWord != 0x8394)) { - errorCode = 0xE; + errorCode = CONT_ERR_VOICE_WORD; } else if (((currentWord == 0x82A3) || (currentWord == 0x8344)) && (currentWord != 0x82C6) && (currentWord != 0x82C7) && (currentWord != 0x82D3) && (currentWord != 0x8367) && (currentWord != 0x8368) && (currentWord != 0x8374) && (currentWord != 0x8394)) { - errorCode = 0xE; + errorCode = CONT_ERR_VOICE_WORD; } else if (((currentWord == 0x82A5) || (currentWord == 0x8346)) && (currentWord != 0x82A4) && (currentWord != 0x82B5) && (currentWord != 0x82B6) && (currentWord != 0x82BF) && (currentWord != 0x82C0) && (currentWord != 0x82C2) && (currentWord != 0x82D3) && (currentWord != 0x8345) && (currentWord != 0x8356) && (currentWord != 0x8357) && (currentWord != 0x8360) && (currentWord != 0x8361) && (currentWord != 0x8363) && (currentWord != 0x8374) && (currentWord != 0x8394)) { - errorCode = 0xE; + errorCode = CONT_ERR_VOICE_WORD; } else if (((currentWord == 0x82A7) || (currentWord == 0x8348)) && (currentWord != 0x82A4) && (currentWord != 0x82D3) && (currentWord != 0x8345) && (currentWord != 0x8374) && (currentWord != 0x8394)) { - errorCode = 0xE; + errorCode = CONT_ERR_VOICE_WORD; } else if (((currentWord == 0x82E1) || (currentWord == 0x82E3) || (currentWord == 0x82E5) || (currentWord == 0x8383) || (currentWord == 0x8385) || (currentWord == 0x8387)) && (currentWord != 0x82AB) && (currentWord != 0x82B5) && (currentWord != 0x82BF) && @@ -52,13 +52,13 @@ s32 osVoiceCheckWord(u8* word) { (currentWord != 0x838A) && (currentWord != 0x834D) && (currentWord != 0x8357) && (currentWord != 0x8361) && (currentWord != 0x8372) && (currentWord != 0x8373) && (currentWord != 0x8394)) { - errorCode = 0xE; + errorCode = CONT_ERR_VOICE_WORD; } else if ((currentWord == 0x815B) && ((currentWord == 0x82F1) || (currentWord == 0x82C1) || (currentWord == 0x8393) || (currentWord == 0x8362))) { - errorCode = 0xE; + errorCode = CONT_ERR_VOICE_WORD; } else if (((currentWord == 0x82F1) || (currentWord == 0x8393)) && ((currentWord == 0x82F1) || (currentWord == 0x8393))) { - errorCode = 0xE; + errorCode = CONT_ERR_VOICE_WORD; } else if (((currentWord == 0x82C1) || (currentWord == 0x8362)) && ((currentWord == 0x815B) || (currentWord == 0x82A0) || (currentWord == 0x82A2) || (currentWord == 0x82A4) || (currentWord == 0x82A6) || (currentWord == 0x82A8) || @@ -86,7 +86,7 @@ s32 osVoiceCheckWord(u8* word) { (currentWord == 0x8344) || (currentWord == 0x8346) || (currentWord == 0x8348) || (currentWord == 0x8383) || (currentWord == 0x8385) || (currentWord == 0x8387) || (currentWord == 0x8362) || (currentWord == 0x838E))) { - errorCode = 0xE; + errorCode = CONT_ERR_VOICE_WORD; } if (errorCode != 0) { @@ -95,7 +95,7 @@ s32 osVoiceCheckWord(u8* word) { } if ((currentWord == 0x82C1) || (currentWord == 0x8362)) { - errorCode = 0xE; + errorCode = CONT_ERR_VOICE_WORD; } return errorCode; diff --git a/src/libultra/voice/voicecleardictionary.c b/src/libultra/voice/voicecleardictionary.c index 92114809d..9bb490a97 100644 --- a/src/libultra/voice/voicecleardictionary.c +++ b/src/libultra/voice/voicecleardictionary.c @@ -14,7 +14,7 @@ s32 osVoiceClearDictionary(OSVoiceHandle* hd, u8 words) { registration_word = &sp24; if (status & 2) { - return 0xF; + return CONT_ERR_VOICE_NO_RESPONSE; } sp24 = 0x2000000; @@ -26,8 +26,8 @@ s32 osVoiceClearDictionary(OSVoiceHandle* hd, u8 words) { } errorCode = __osVoiceCheckResult(hd, &status); - if ((errorCode & 0xFF00) != 0) { - errorCode = 5; + if (errorCode & 0xFF00) { + errorCode = CONT_ERR_INVALID; } return errorCode; diff --git a/src/libultra/voice/voicecontrolgain.c b/src/libultra/voice/voicecontrolgain.c index 251dc1144..eb896bb72 100644 --- a/src/libultra/voice/voicecontrolgain.c +++ b/src/libultra/voice/voicecontrolgain.c @@ -27,7 +27,7 @@ s32 osVoiceControlGain(OSVoiceHandle* hd, s32 analog, s32 digital) { if (0) { dummy: - return 5; + return CONT_ERR_INVALID; } errorCode = __osVoiceSetADConverter(hd->mq, hd->port, phi_a2); diff --git a/src/libultra/voice/voicegetreaddata.c b/src/libultra/voice/voicegetreaddata.c index c202ad27d..e94202aca 100644 --- a/src/libultra/voice/voicegetreaddata.c +++ b/src/libultra/voice/voicegetreaddata.c @@ -17,7 +17,7 @@ s32 osVoiceGetReadData(OSVoiceHandle* hd, OSVoiceData* result) { } if (sp38[39] & 1) { - return 0xC; + return CONT_ERR_NOT_READY; } errorCode = __osVoiceContRead2(hd->mq, hd->port, 0, sp38); @@ -29,7 +29,7 @@ s32 osVoiceGetReadData(OSVoiceHandle* hd, OSVoiceData* result) { hd->status = temp_t9; D_8009CF60 = temp_t9; if ((temp_t9 != 0) && (temp_t9 != 7)) { - return 0xC; + return CONT_ERR_NOT_READY; } case 2: hd->mode = 2; @@ -41,7 +41,7 @@ s32 osVoiceGetReadData(OSVoiceHandle* hd, OSVoiceData* result) { if (0) {} if (sp38[39] & 2) { - return 0xF; + return CONT_ERR_VOICE_NO_RESPONSE; } sp38[0] = 0x600; // Not reading in correctly since 0x600 is out-of-range for u8 @@ -59,7 +59,7 @@ s32 osVoiceGetReadData(OSVoiceHandle* hd, OSVoiceData* result) { } if (sp38[39] & 1) { - return 0xF; + return CONT_ERR_VOICE_NO_RESPONSE; } errorCode = __osVoiceContRead36(hd->mq, hd->port, 0, sp38); @@ -96,7 +96,7 @@ s32 osVoiceGetReadData(OSVoiceHandle* hd, OSVoiceData* result) { } if (sp38[39] & 1) { - return 0xF; + return CONT_ERR_VOICE_NO_RESPONSE; } errorCode = __osVoiceContRead2(hd->mq, hd->port, 0, sp38); @@ -106,12 +106,12 @@ s32 osVoiceGetReadData(OSVoiceHandle* hd, OSVoiceData* result) { hd->status = sp38[0] & 7; if ((sp38[0] & 7) != 0) { - return 0xF; + return CONT_ERR_VOICE_NO_RESPONSE; } break; default: - return 5; + return CONT_ERR_INVALID; } hd->mode = 0; return errorCode; diff --git a/src/libultra/voice/voicegetstatus.c b/src/libultra/voice/voicegetstatus.c index 1711eb56d..7946b4904 100644 --- a/src/libultra/voice/voicegetstatus.c +++ b/src/libultra/voice/voicegetstatus.c @@ -3,7 +3,7 @@ s32 __osVoiceGetStatus(OSMesgQueue* mq, s32 port, u8* status) { __OSContRequestHeaderAligned header; - s32 ret = 0; + s32 errorCode = 0; s32 i; u8* ptr = (u8*)&__osContPifRam; s32 var = 2; @@ -11,7 +11,7 @@ s32 __osVoiceGetStatus(OSMesgQueue* mq, s32 port, u8* status) { __osSiGetAccess(); do { - if (ret != CONT_ERR_CONTRFAIL) { + if (errorCode != CONT_ERR_CONTRFAIL) { __osContPifRam.pifstatus = CONT_CMD_READ_BUTTON; for (i = 0; i < port; i++, *ptr++ = 0) { @@ -25,34 +25,35 @@ s32 __osVoiceGetStatus(OSMesgQueue* mq, s32 port, u8* status) { *ptr = CONT_CMD_END; __osContLastCmd = CONT_CMD_END; - ret = __osSiRawStartDma(OS_WRITE, &__osContPifRam); + errorCode = __osSiRawStartDma(OS_WRITE, &__osContPifRam); osRecvMesg(mq, NULL, OS_MESG_BLOCK); } - ret = __osSiRawStartDma(OS_READ, &__osContPifRam); + errorCode = __osSiRawStartDma(OS_READ, &__osContPifRam); osRecvMesg(mq, NULL, OS_MESG_BLOCK); ptr = (u8*)&__osContPifRam + port; header = *((__OSContRequestHeaderAligned*)ptr); - ret = (u8)((header.rxsize & 0xC0) >> 4); + errorCode = (u8)((header.rxsize & 0xC0) >> 4); *status = header.status; - if (ret == 0) { + if (errorCode == 0) { if (header.typeh == 0 && header.typel == 1) { if (header.status & 4) { - ret = CONT_ERR_CONTRFAIL; + errorCode = CONT_ERR_CONTRFAIL; } } else { - ret = CONT_ERR_DEVICE; + errorCode = CONT_ERR_DEVICE; } - } else if (ret & CONT_NO_RESPONSE_ERROR) { - ret = CONT_ERR_NO_CONTROLLER; + } else if (errorCode & CONT_NO_RESPONSE_ERROR) { + errorCode = CONT_ERR_NO_CONTROLLER; } else { - ret = CONT_ERR_CONTRFAIL; + errorCode = CONT_ERR_CONTRFAIL; } - } while ((ret == CONT_ERR_CONTRFAIL) && (var-- >= 0)); + } while ((errorCode == CONT_ERR_CONTRFAIL) && (var-- >= 0)); __osSiRelAccess(); - return (ret); + + return errorCode; } diff --git a/src/libultra/voice/voiceinit.c b/src/libultra/voice/voiceinit.c index 54e13fa4c..7cc4f817a 100644 --- a/src/libultra/voice/voiceinit.c +++ b/src/libultra/voice/voiceinit.c @@ -7,7 +7,7 @@ extern u8 D_80097FA5; s32 osVoiceInit(OSMesgQueue* siMessageQ, OSVoiceHandle* hd, s32 channel) { s32 errorCode; u8* phi_s0; - u8 sp37 = 0; + u8 status = 0; s32 sp30; s32 pad; @@ -15,13 +15,13 @@ s32 osVoiceInit(OSMesgQueue* siMessageQ, OSVoiceHandle* hd, s32 channel) { hd->mq = siMessageQ; hd->mode = 0; - errorCode = __osVoiceGetStatus(siMessageQ, channel, &sp37); + errorCode = __osVoiceGetStatus(siMessageQ, channel, &status); if (errorCode != 0) { return errorCode; } if (__osContChannelReset(siMessageQ, channel) != 0) { - return 4; + return CONT_ERR_CONTRFAIL; } for (phi_s0 = &D_80097FA0;;) { @@ -33,12 +33,12 @@ s32 osVoiceInit(OSMesgQueue* siMessageQ, OSVoiceHandle* hd, s32 channel) { } if (phi_s0 == &D_80097FA5) { - errorCode = __osVoiceGetStatus(siMessageQ, channel, &sp37); + errorCode = __osVoiceGetStatus(siMessageQ, channel, &status); if (errorCode != 0) { return errorCode; } - if (sp37 & 2) { - return 0xF; + if (status & 2) { + return CONT_ERR_VOICE_NO_RESPONSE; } sp30 = 0x100; @@ -47,9 +47,9 @@ s32 osVoiceInit(OSMesgQueue* siMessageQ, OSVoiceHandle* hd, s32 channel) { return errorCode; } - errorCode = __osVoiceCheckResult(hd, &sp37); + errorCode = __osVoiceCheckResult(hd, &status); if (errorCode & 0xFF00) { - errorCode = 5; + errorCode = CONT_ERR_INVALID; } return errorCode; diff --git a/src/libultra/voice/voicesetword.c b/src/libultra/voice/voicesetword.c index 83cf97516..3c927740c 100644 --- a/src/libultra/voice/voicesetword.c +++ b/src/libultra/voice/voicesetword.c @@ -5,16 +5,16 @@ s32 osVoiceSetWord(OSVoiceHandle* hd, u8* word) { s32 i; s32 sp50; s32 errorCode; - u8 sp4B; + u8 status; u8 sp20[0x28]; - errorCode = __osVoiceGetStatus(hd->mq, hd->port, &sp4B); + errorCode = __osVoiceGetStatus(hd->mq, hd->port, &status); if (errorCode != 0) { return errorCode; } - if (sp4B & 2) { - return 0xF; + if (status & 2) { + return CONT_ERR_VOICE_NO_RESPONSE; } sp50 = 0; @@ -44,15 +44,15 @@ s32 osVoiceSetWord(OSVoiceHandle* hd, u8* word) { return errorCode; } - errorCode = __osVoiceCheckResult(hd, &sp4B); + errorCode = __osVoiceCheckResult(hd, &status); if (errorCode != 0) { if (errorCode & 0x100) { - errorCode = 0xD; + errorCode = CONT_ERR_VOICE_MEMORY; } else if (errorCode & 0x200) { - errorCode = 0xE; + errorCode = CONT_ERR_VOICE_WORD; } else if (errorCode & 0xFF00) { - errorCode = 5; + errorCode = CONT_ERR_INVALID; } } diff --git a/src/libultra/voice/voicestartreaddata.c b/src/libultra/voice/voicestartreaddata.c index 88c77dc2c..5e65d3ce4 100644 --- a/src/libultra/voice/voicestartreaddata.c +++ b/src/libultra/voice/voicestartreaddata.c @@ -12,11 +12,11 @@ s32 osVoiceStartReadData(OSVoiceHandle* hd) { } if (status & 2) { - return 0xF; + return CONT_ERR_VOICE_NO_RESPONSE; } if (hd->mode != 0) { - return 5; + return CONT_ERR_INVALID; } sp24 = 0x5000000; @@ -26,7 +26,7 @@ s32 osVoiceStartReadData(OSVoiceHandle* hd) { errorCode = __osVoiceCheckResult(hd, &status); if (errorCode & 0xFF00) { - errorCode = 5; + errorCode = CONT_ERR_INVALID; } else { hd->mode = 1; } diff --git a/src/libultra/voice/voicestopread.c b/src/libultra/voice/voicestopread.c index d7dad3291..4c9a1dc88 100644 --- a/src/libultra/voice/voicestopread.c +++ b/src/libultra/voice/voicestopread.c @@ -14,11 +14,11 @@ s32 osVoiceStopReadData(OSVoiceHandle* hd) { } if (sp3F & 2) { - return 0xF; + return CONT_ERR_VOICE_NO_RESPONSE; } if (hd->mode == 0) { - return 5; + return CONT_ERR_INVALID; } sp38 = 0x700; @@ -33,13 +33,13 @@ s32 osVoiceStopReadData(OSVoiceHandle* hd) { errorCode = 0; hd->mode = 0; } else { - errorCode = 5; + errorCode = CONT_ERR_INVALID; } } else { hd->mode = 0; } - if (errorCode != 0xF) { + if (errorCode != CONT_ERR_VOICE_NO_RESPONSE) { break; } }