From 0572b2d93d0e5d65d9a0bb0a514e476ecfae61ff Mon Sep 17 00:00:00 2001 From: FIX94 Date: Mon, 18 Sep 2017 23:40:12 +0200 Subject: [PATCH] -added WiiDRC_Connected that can be used to detect if the wii vc was started with drc on or off when using a r570 or r590 fw.img --- include/wiidrc/wiidrc.h | 1 + source/wiidrc.c | 31 +++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/include/wiidrc/wiidrc.h b/include/wiidrc/wiidrc.h index e556338..50facd1 100644 --- a/include/wiidrc/wiidrc.h +++ b/include/wiidrc/wiidrc.h @@ -44,6 +44,7 @@ bool WiiDRC_Init(); bool WiiDRC_Inited(); bool WiiDRC_Recalibrate(); bool WiiDRC_ScanPads(); +bool WiiDRC_Connected(); const u8 *WiiDRC_GetRawI2CAddr(); const struct WiiDRCData *WiiDRC_Data(); u32 WiiDRC_ButtonsUp(); diff --git a/source/wiidrc.c b/source/wiidrc.c index 3c66f9b..0fe2eb1 100644 --- a/source/wiidrc.c +++ b/source/wiidrc.c @@ -16,6 +16,7 @@ static struct WiiDRCButtons __WiiDRC_PadButtons; static u32 __WiiDRC_Inited = 0; static u8 *__WiiDRC_I2CBuf = NULL; +static u8 *__WiiDRC_DRCStateBuf = NULL; static bool __WiiDRC_SetI2CBuf() { @@ -39,12 +40,32 @@ static bool __WiiDRC_SetI2CBuf() return false; } +static bool __WiiDRC_SetDRCStateBuf() +{ + //TODO r569 + DCInvalidateRange((void*)0x938B563C, 4); + if(*(vu32*)0x938B563C == 0x138BE770) //r570 + { + __WiiDRC_DRCStateBuf = (u8*)0x938BE770; + return true; + } + DCInvalidateRange((void*)0x938B5724, 4); + if(*(vu32*)0x938B5724 == 0x138BD770) //r590 + { + __WiiDRC_DRCStateBuf = (u8*)0x938BD770; + return true; + } + return false; +} + bool WiiDRC_Init() { if(__WiiDRC_Inited == 1) return false; if(!__WiiDRC_SetI2CBuf()) return false; + //can fail on r569 for now + __WiiDRC_SetDRCStateBuf(); __WiiDRC_Inited = 1; @@ -98,6 +119,16 @@ bool WiiDRC_ScanPads() return true; } +bool WiiDRC_Connected() +{ + if(__WiiDRC_DRCStateBuf) + { + DCInvalidateRange(__WiiDRC_DRCStateBuf, 4); + return !!(*(vu32*)__WiiDRC_DRCStateBuf); + } + return true; //default connect +} + const u8 *WiiDRC_GetRawI2CAddr() { return __WiiDRC_I2CBuf;