diff --git a/include/functions.h b/include/functions.h index 87e3ba2be..2ed3bf63c 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); -s32 __osVoiceContWrite20(OSMesgQueue*, s32, u8, u8*); +s32 __osVoiceContWrite20(OSMesgQueue* mq, s32 port, u16 arg2, u8 dst[20]); u8 __osContAddressCrc(u16 addr); u8 __osContDataCrc(u8* data); OSThread* __osGetActiveQueue(void); @@ -470,7 +470,7 @@ s32 osVoiceControlGain(OSVoiceHandle* hd, s32 analog, s32 digital); s32 osVoiceStartReadData(OSVoiceHandle* hd); u32* osViGetCurrentFramebuffer(void); s32 __osSpSetPc(void* pc); -s32 __osVoiceContWrite4(OSMesgQueue* mq, s32 port, u16 arg2, u8* dst[4]); +s32 __osVoiceContWrite4(OSMesgQueue* mq, s32 port, u16 arg2, u8 dst[4]); void __osGetHWIntrRoutine(s32 idx, OSMesgQueue** outQueue, OSMesg* outMsg); void __osSetHWIntrRoutine(s32 idx, OSMesgQueue* queue, OSMesg msg); u32 __osGetWatchLo(void); diff --git a/src/libultra/voice/voicecontwrite20.c b/src/libultra/voice/voicecontwrite20.c index 5ca3560ed..9eba371c6 100644 --- a/src/libultra/voice/voicecontwrite20.c +++ b/src/libultra/voice/voicecontwrite20.c @@ -1,3 +1,68 @@ #include "global.h" -#pragma GLOBAL_ASM("asm/non_matchings/boot/voicecontwrite20/__osVoiceContWrite20.s") +s32 __osVoiceContWrite20(OSMesgQueue* mq, s32 port, u16 arg2, u8 dst[20]) { + s32 errorCode; + u8 status; + u8* ptr; + s32 retryCount = 2; + s32 i; + u8 temp_s2; + + __osSiGetAccess(); + + do { + + ptr = (u8*)&__osPfsPifRam; + + if ((__osContLastCmd != 0xA) || (port != D_80097FB0)) { + __osContLastCmd = 0xA; + D_80097FB0 = port; + + for (i = 0; i < port; i++, *ptr++ = 0) { + ; + } + + __osPfsPifRam.pifstatus = CONT_CMD_READ_BUTTON; + + ptr[0] = 0xFF; + ptr[1] = 0x17; + ptr[2] = 1; + ptr[3] = 0xA; + ptr[0x1A] = 0xFF; + ptr[0x1B] = 0xFE; + } else { + ptr = (u8*)&__osPfsPifRam + port; + } + + ptr[4] = arg2 >> 3; + ptr[5] = __osContAddressCrc(arg2) | (arg2 << 5); + + bcopy(dst, &ptr[6], 20); + + __osSiRawStartDma(OS_WRITE, &__osPfsPifRam); + temp_s2 = __osVoiceContDataCrc(dst, 20); + osRecvMesg(mq, NULL, OS_MESG_BLOCK); + __osSiRawStartDma(OS_READ, &__osPfsPifRam); + osRecvMesg(mq, NULL, OS_MESG_BLOCK); + + errorCode = (ptr[2] & 0xC0) >> 4; + + if (errorCode == 0) { + if (ptr[0x1A] != ((void)0, temp_s2)) { + errorCode = __osVoiceGetStatus(mq, port, &status); + if (errorCode != 0) { + break; + } + + errorCode = CONT_ERR_CONTRFAIL; + } + } else { + errorCode = CONT_ERR_NO_CONTROLLER; + } + + } while ((errorCode == CONT_ERR_CONTRFAIL) && (retryCount-- >= 0)); + + __osSiRelAccess(); + + return errorCode; +} diff --git a/src/libultra/voice/voicecontwrite4.c b/src/libultra/voice/voicecontwrite4.c index 09158c043..8e1af6bd8 100644 --- a/src/libultra/voice/voicecontwrite4.c +++ b/src/libultra/voice/voicecontwrite4.c @@ -1,6 +1,6 @@ #include "global.h" -s32 __osVoiceContWrite4(OSMesgQueue* mq, s32 port, u16 arg2, u8* dst[4]) { +s32 __osVoiceContWrite4(OSMesgQueue* mq, s32 port, u16 arg2, u8 dst[4]) { s32 errorCode; u8 status; u8* ptr; @@ -48,7 +48,7 @@ s32 __osVoiceContWrite4(OSMesgQueue* mq, s32 port, u16 arg2, u8* dst[4]) { errorCode = (ptr[2] & 0xC0) >> 4; if (errorCode == 0) { - if (ptr[0xA] != (0, temp_s2)) { + if (ptr[0xA] != ((void)0, temp_s2)) { errorCode = __osVoiceGetStatus(mq, port, &status); if (errorCode != 0) { break;