From d05a543bc1e4d2e6e0bb1370975f50157d9e745e Mon Sep 17 00:00:00 2001 From: robojumper Date: Tue, 28 May 2024 01:19:06 +0200 Subject: [PATCH 1/2] m_pad except one function regshuffles --- config/SOUE01/splits.txt | 7 ++ config/SOUE01/symbols.txt | 50 +++++------ configure.py | 1 + include/egg/core/eggController.h | 17 ++-- include/egg/math/eggVector.h | 4 + include/m/m_pad.h | 12 +++ src/egg/core/eggController.cpp | 4 +- src/m/m_pad.cpp | 146 +++++++++++++++++++++++++++++++ 8 files changed, 209 insertions(+), 32 deletions(-) create mode 100644 src/m/m_pad.cpp diff --git a/config/SOUE01/splits.txt b/config/SOUE01/splits.txt index 34ce56fe..1d9aba53 100644 --- a/config/SOUE01/splits.txt +++ b/config/SOUE01/splits.txt @@ -247,6 +247,13 @@ m/m_mtx.cpp: .text start:0x802F1660 end:0x802F1F20 .ctors start:0x804DB8D4 end:0x804DB8D8 +m/m_pad.cpp: + .text start:0x802F1F20 end:0x802F2330 + .ctors start:0x804DB8D8 end:0x804DB8DC + .sbss start:0x80575C50 end:0x80575C70 + .sdata2 start:0x8057CDF8 end:0x8057CE00 + .bss start:0x805CB0B8 end:0x805CB1F8 + rvl/CX/cx.c: .text start:0x803CEE90 end:0x803D0B20 diff --git a/config/SOUE01/symbols.txt b/config/SOUE01/symbols.txt index 8f6bb548..8c4bf1c6 100644 --- a/config/SOUE01/symbols.txt +++ b/config/SOUE01/symbols.txt @@ -17851,16 +17851,16 @@ toRot__6mMtx_cCFR7mAng3_c = .text:0x802F1B60; // type:function size:0xDC fn_802F1C40 = .text:0x802F1C40; // type:function size:0x220 fn_802F1E60 = .text:0x802F1E60; // type:function size:0x58 __sinit_\m_mtx_cpp = .text:0x802F1EC0; // type:function size:0x58 -fn_802F1F20 = .text:0x802F1F20; // type:function size:0x30 -fn_802F1F50 = .text:0x802F1F50; // type:function size:0x1E4 -fn_802F2140 = .text:0x802F2140; // type:function size:0x14 -fn_802F2160 = .text:0x802F2160; // type:function size:0x44 -fn_802F21B0 = .text:0x802F21B0; // type:function size:0x3C -fn_802F21F0 = .text:0x802F21F0; // type:function size:0x64 -fn_802F2260 = .text:0x802F2260; // type:function size:0x58 -fn_802F22C0 = .text:0x802F22C0; // type:function size:0x4 -fn_802F22D0 = .text:0x802F22D0; // type:function size:0x40 -fn_802F2310 = .text:0x802F2310; // type:function size:0x1C +create__4mPadFv = .text:0x802F1F20; // type:function size:0x30 +beginPad__4mPadFv = .text:0x802F1F50; // type:function size:0x1E4 +endPad__4mPadFv = .text:0x802F2140; // type:function size:0x14 +clearWPADInfo__4mPadFi = .text:0x802F2160; // type:function size:0x44 +initWPADInfo__4mPadFv = .text:0x802F21B0; // type:function size:0x3C +getWPADInfoCB__4mPadFi = .text:0x802F21F0; // type:function size:0x64 +__sinit_\m_pad_cpp = .text:0x802F2260; // type:function size:0x58 scope:local +__ct__Q24mPad19PadAdditionalData_tFv = .text:0x802F22C0; // type:function size:0x4 +__dt__Q24mPad19PadAdditionalData_tFv = .text:0x802F22D0; // type:function size:0x40 +__arraydtor$4391 = .text:0x802F2310; // type:function size:0x1C fn_802F2330 = .text:0x802F2330; // type:function size:0x120 fn_802F2450 = .text:0x802F2450; // type:function size:0x18C fn_802F25E0 = .text:0x802F25E0; // type:function size:0x19C @@ -26336,7 +26336,7 @@ getNthController__Q23EGG17CoreControllerMgrFi = .text:0x80499BE0; // type:functi errRangeOver__Q23EGG32TBufferFv = .text:0x80499C60; // type:function size:0x4 allocThunk__Q23EGG17CoreControllerMgrFUl = .text:0x80499C70; // type:function size:0x18 deleteThunk__Q23EGG17CoreControllerMgrFPv = .text:0x80499C90; // type:function size:0x38 -connectCallback__Q23EGG17CoreControllerMgrFii = .text:0x80499CD0; // type:function size:0x3C +connectCallback__Q23EGG17CoreControllerMgrFll = .text:0x80499CD0; // type:function size:0x3C __ct__Q23EGG17CoreControllerMgrFv = .text:0x80499D10; // type:function size:0x320 __dt__Q23EGG32TBufferFv = .text:0x8049A030; // type:function size:0x78 __dt__Q23EGG29TBufferFv = .text:0x8049A0B0; // type:function size:0x78 @@ -40276,14 +40276,14 @@ g_archiveHeap__5mHeap = .sbss:0x80575C3C; // type:object size:0x4 data:4byte g_commandHeap__5mHeap = .sbss:0x80575C40; // type:object size:0x4 data:4byte g_dylinkHeap__5mHeap = .sbss:0x80575C44; // type:object size:0x4 data:4byte g_assertHeap__5mHeap = .sbss:0x80575C48; // type:object size:0x4 data:4byte -lbl_80575C50 = .sbss:0x80575C50; // type:object size:0x4 data:4byte -lbl_80575C54 = .sbss:0x80575C54; // type:object size:0x4 data:4byte -lbl_80575C58 = .sbss:0x80575C58; // type:object size:0x4 data:4byte -lbl_80575C5C = .sbss:0x80575C5C; // type:object size:0x1 data:byte -lbl_80575C60 = .sbss:0x80575C60; // type:object size:0x4 data:4byte -lbl_80575C64 = .sbss:0x80575C64; // type:object size:0x4 -lbl_80575C68 = .sbss:0x80575C68; // type:object size:0x4 data:4byte -lbl_80575C6C = .sbss:0x80575C6C; // type:object size:0x4 data:4byte +g_padMg__4mPad = .sbss:0x80575C50; // type:object size:0x4 data:4byte +g_currentCoreId__4mPad = .sbss:0x80575C54; // type:object size:0x4 data:4byte +g_currentCore__4mPad = .sbss:0x80575C58; // type:object size:0x4 data:4byte +g_IsConnected__4mPad = .sbss:0x80575C5C; // type:object size:0x1 data:byte +g_PadFrame__4mPad = .sbss:0x80575C60; // type:object size:0x4 data:4byte +s_WPADInfoAvailable__4mPad = .sbss:0x80575C64; // type:object size:0x4 +s_GetWPADInfoInterval__4mPad = .sbss:0x80575C68; // type:object size:0x4 data:4byte +s_GetWPADInfoCount__4mPad = .sbss:0x80575C6C; // type:object size:0x4 data:4byte lbl_80575C70 = .sbss:0x80575C70; // type:object size:0x8 data:float lbl_80575C78 = .sbss:0x80575C78; // type:object size:0x8 data:float lbl_80575C80 = .sbss:0x80575C80; // type:object size:0x8 data:float @@ -45850,7 +45850,7 @@ lbl_8057CDE4 = .sdata2:0x8057CDE4; // type:object size:0x4 data:float lbl_8057CDE8 = .sdata2:0x8057CDE8; // type:object size:0x4 data:float lbl_8057CDEC = .sdata2:0x8057CDEC; // type:object size:0x4 data:float lbl_8057CDF0 = .sdata2:0x8057CDF0; // type:object size:0x8 data:float -lbl_8057CDF8 = .sdata2:0x8057CDF8; // type:object size:0x8 data:float +lbl_8057CDF8 = .sdata2:0x8057CDF8; // type:object size:0x4 data:float lbl_8057CE00 = .sdata2:0x8057CE00; // type:object size:0x4 data:float lbl_8057CE04 = .sdata2:0x8057CE04; // type:object size:0x4 data:float lbl_8057CE08 = .sdata2:0x8057CE08; // type:object size:0x4 data:float @@ -48140,7 +48140,7 @@ lbl_805976C0 = .bss:0x805976C0; // type:object size:0x80 data:byte sAllocator__14dHeapAllocator = .bss:0x80597740; // type:object size:0x18 data:4byte lbl_80597758 = .bss:0x80597758; // type:object size:0x318 lbl_80597A70 = .bss:0x80597A70; // type:object size:0x10 -lbl_80597A80 = .bss:0x80597A80; // type:object size:0x8B70 data:float +sControllers = .bss:0x80597A80; // type:object size:0x8B70 data:float lbl_805A05F0 = .bss:0x805A05F0; // type:object size:0x60 lbl_805A0650 = .bss:0x805A0650; // type:object size:0x60 lbl_805A06B0 = .bss:0x805A06B0; // type:object size:0xC data:float @@ -49081,11 +49081,11 @@ lbl_805CAF98 = .bss:0x805CAF98; // type:object size:0xC @LOCAL@loadToMainRAM__4mDvdFiPcPQ23EGG4HeapQ33EGG9DvdRipper15EAllocDirectionlPUlPUlUl@DvdFile = .bss:0x805CAFA8; // type:object size:0xD0 g_gameHeaps__5mHeap = .bss:0x805CB078; // type:object size:0x10 data:4byte lbl_805CB088 = .bss:0x805CB088; // type:object size:0x30 data:4byte -lbl_805CB0B8 = .bss:0x805CB0B8; // type:object size:0x10 data:4byte +g_core__4mPad = .bss:0x805CB0B8; // type:object size:0x10 data:4byte lbl_805CB0C8 = .bss:0x805CB0C8; // type:object size:0x10 -lbl_805CB0D8 = .bss:0x805CB0D8; // type:object size:0x60 data:float -lbl_805CB138 = .bss:0x805CB138; // type:object size:0x60 -lbl_805CB198 = .bss:0x805CB198; // type:object size:0x60 +g_PadAdditionalData__4mPad = .bss:0x805CB0D8; // type:object size:0x60 data:float +s_WPADInfo__4mPad = .bss:0x805CB138; // type:object size:0x60 +s_WPADInfoTmp__4mPad = .bss:0x805CB198; // type:object size:0x60 lbl_805CB1F8 = .bss:0x805CB1F8; // type:object size:0xC data:float lbl_805CB204 = .bss:0x805CB204; // type:object size:0xC data:float lbl_805CB210 = .bss:0x805CB210; // type:object size:0xC data:float diff --git a/configure.py b/configure.py index 62187b35..cad27891 100644 --- a/configure.py +++ b/configure.py @@ -307,6 +307,7 @@ config.libs = [ Object(Matching, "m/m_dvd.cpp"), Object(Matching, "m/m_heap.cpp"), Object(NonMatching, "m/m_mtx.cpp"), + Object(NonMatching, "m/m_pad.cpp"), Object(Matching, "DynamicLink.cpp"), # framework (f_name) # d stuff (d_name) diff --git a/include/egg/core/eggController.h b/include/egg/core/eggController.h index b3b4c024..ba983622 100644 --- a/include/egg/core/eggController.h +++ b/include/egg/core/eggController.h @@ -25,12 +25,15 @@ class CoreStatus { public: /* 0x00 */ u8 field_0x00[0x0C]; /* 0x0C */ f32 accel[3]; - /* 0x18 */ u8 field_0x01[0x08]; + /* 0x18 */ u8 field_0x01[0x20 - 0x18]; /* 0x20 */ f32 dpdRawX; /* 0x24 */ f32 dpdRawY; - /* 0x28 */ u8 field_0x02[0x36]; - /* 0x58 */ s8 dpdDistance; - /* 0x5C */ s8 unknown; + /* 0x28 */ u8 field_0x02[0x54 - 0x28]; + /* 0x54 */ f32 float_0x54; + /* 0x58 */ f32 float_0x58; + /* 0x5C */ u8 field_0x5C[0x5E - 0x5C]; + /* 0x5E */ s8 dpdDistance; + /* 0x5F */ s8 unknown; /* 0x60 */ f32 fsStickButton; /* 0x60 */ f32 fsStickButton2; /* 0x64 */ u8 field_0x03[0x88]; @@ -38,6 +41,10 @@ public: public: /* 80498f90 */ void init(); /* 80498fa0 */ u32 getFSStickButton() const; + + inline Vector2f getUnk() { + return Vector2f(float_0x54, float_0x58); + } }; class CoreController { @@ -128,7 +135,7 @@ public: public: /* 80499b80 */ static CoreControllerMgr *createInstance(); /* 80499bd0 */ static void deleteInstance(); - /* 80499be0 */ CoreController *getNthController(s32); + /* 80499be0 */ CoreController *getNthController(int); static void *allocThunk(size_t size); static int deleteThunk(void *ptr); diff --git a/include/egg/math/eggVector.h b/include/egg/math/eggVector.h index 0d8735ee..2090b5b7 100644 --- a/include/egg/math/eggVector.h +++ b/include/egg/math/eggVector.h @@ -117,6 +117,10 @@ public: /* 805767c0 */ static const Vector2f zero; /* 805767c8 */ static const Vector2f ex; /* 805767d0 */ static const Vector2f ey; + + Vector2f operator-(const Vector2f &v) { + return Vector2f(x - v.x, y - v.y); + } }; struct Vector3s { diff --git a/include/m/m_pad.h b/include/m/m_pad.h index e69de29b..7878204a 100644 --- a/include/m/m_pad.h +++ b/include/m/m_pad.h @@ -0,0 +1,12 @@ +#ifndef M_PAD_H +#define M_PAD_H + +namespace mPad { + +void create(); +void beginPad(); +void endPad(); + +} // namespace mPad + +#endif diff --git a/src/egg/core/eggController.cpp b/src/egg/core/eggController.cpp index d6a4c4eb..3088eff2 100644 --- a/src/egg/core/eggController.cpp +++ b/src/egg/core/eggController.cpp @@ -173,7 +173,7 @@ extern "C" void fn_803DB1E0(s32 channel, bool arg); CoreControllerMgr::T__Disposer::sStaticDisposer = nullptr; } -/* 0x80499BE0 */ EGG::CoreController *CoreControllerMgr::getNthController(s32 n) { +/* 0x80499BE0 */ EGG::CoreController *CoreControllerMgr::getNthController(int n) { return this->mControllers(n); } @@ -186,7 +186,7 @@ extern "C" void fn_803DB1E0(s32 channel, bool arg); return 1; } -/* 0x80499CD0 */ void CoreControllerMgr::connectCallback(int a1, int a2) { +/* 0x80499CD0 */ void CoreControllerMgr::connectCallback(s32 a1, s32 a2) { int args[] = {a1, a2}; if (sConnectCallback != nullptr) { (sConnectCallback)(args); diff --git a/src/m/m_pad.cpp b/src/m/m_pad.cpp new file mode 100644 index 00000000..63b4bf18 --- /dev/null +++ b/src/m/m_pad.cpp @@ -0,0 +1,146 @@ +#include +#include +#include +#include + +namespace mPad { + +static EGG::CoreControllerMgr *g_padMg; +static int g_currentCoreId; +static EGG::CoreController *g_currentCore; +static bool g_IsConnected[4]; +static u32 g_PadFrame; + +static u32 s_GetWPADInfoInterval = 0; +static bool s_WPADInfoAvailable[4]; +static u32 s_GetWPADInfoCount = 0; + +static EGG::CoreController *g_core[4]; + +struct WPADInfo_t { + u32 field_0x00; + u32 field_0x04; + u32 field_0x08; + u32 field_0x0C; + u32 field_0x10; + bool field_0x14; + bool field_0x15; + bool field_0x16; + bool field_0x17; + + inline void clear() { + field_0x00 = 0; + field_0x04 = 0; + field_0x08 = 0; + field_0x0C = 0; + field_0x10 = 0; + field_0x14 = false; + field_0x15 = false; + field_0x16 = false; + field_0x17 = false; + } +}; + +struct PadAdditionalData_t { + PadAdditionalData_t() {} + ~PadAdditionalData_t() {} + + EGG::Vector2f v1; + EGG::Vector2f v2; + EGG::Vector2f v3; +}; + +static PadAdditionalData_t g_PadAdditionalData[4]; +static WPADInfo_t s_WPADInfo[4]; +static WPADInfo_t s_WPADInfoTmp[4]; + +static void initWPADInfo(); +static void clearWPADInfo(int); +static int getWPADInfoCB(int controller); + +void create() { + g_padMg = EGG::CoreControllerMgr::sInstance; + initWPADInfo(); + beginPad(); + endPad(); +} + +// Has a regshuffle +void beginPad() { + EGG::CoreController *ctl; + + g_PadFrame++; + g_padMg->beginFrame(); + + for (int i = 0; i < 4; i++) { + ctl = g_padMg->getNthController(i); + g_core[i] = ctl; + if (ctl->mFlag.onBit(0)) { + // These sort of look like value, first order derivative, and second order derivative + // So perhaps value, velocity, acceleration? + EGG::Vector2f pos = ctl->coreStatus[0].getUnk(); + EGG::Vector2f v = pos - g_PadAdditionalData[i].v1; + g_PadAdditionalData[i].v1 = pos; + g_PadAdditionalData[i].v3 = v - g_PadAdditionalData[i].v2; + g_PadAdditionalData[i].v2 = v; + + if (!g_IsConnected[i]) { + g_IsConnected[i] = true; + } + + // Not sure why this checks the controller index against the tick count + if (s_GetWPADInfoInterval != 0 && + ((s_GetWPADInfoInterval == 1 || s_GetWPADInfoCount == i) || + (s_GetWPADInfoInterval <= 3 && (s_GetWPADInfoCount & 1) == (i & 1)))) { + getWPADInfoCB(i); + } + } else if (g_IsConnected[i]) { + ctl->coreStatus->init(); + ctl->sceneReset(); + g_PadAdditionalData[i].v1.x = 0.0f; + g_PadAdditionalData[i].v1.y = 0.0f; + g_PadAdditionalData[i].v3.x = 0.0f; + g_PadAdditionalData[i].v3.y = 0.0f; + g_PadAdditionalData[i].v2.x = 0.0f; + g_PadAdditionalData[i].v2.y = 0.0f; + clearWPADInfo(i); + g_IsConnected[i] = false; + } + } + + if (s_GetWPADInfoInterval != 0) { + s_GetWPADInfoCount++; + if (s_GetWPADInfoCount > s_GetWPADInfoInterval) { + s_GetWPADInfoCount = 0; + } + } + g_currentCore = g_core[g_currentCoreId]; +} + +void endPad() { + g_padMg->endFrame(); +} + +static void clearWPADInfo(int controller) { + s_WPADInfoAvailable[controller] = false; + s_WPADInfo[controller].clear(); +} + +static void initWPADInfo() { + for (int i = 0; i < 4; i++) { + clearWPADInfo(i); + } +} + +extern "C" int fn_803DAFC0(int controller, void *data, void (*callback)(int, int)); +extern "C" void fn_80058DA0(int, int); + +static int getWPADInfoCB(int controller) { + int result = fn_803DAFC0(controller, &s_WPADInfoTmp[controller], fn_80058DA0); + if (result == -1) { + clearWPADInfo(controller); + } + return result; +} + +} // namespace mPad From 35a4b294a158286fb1b44241914b780abecde9d2 Mon Sep 17 00:00:00 2001 From: robojumper Date: Tue, 28 May 2024 20:45:14 +0200 Subject: [PATCH 2/2] Look if it matches it matches --- config/SOUE01/splits.txt | 2 +- config/SOUE01/symbols.txt | 8 +-- configure.py | 2 +- include/m/m_pad.h | 5 ++ include/rvl/WPAD/WPAD.h | 14 +++++ src/m/m_pad.cpp | 108 +++++++++++++++++++------------------- 6 files changed, 80 insertions(+), 59 deletions(-) diff --git a/config/SOUE01/splits.txt b/config/SOUE01/splits.txt index 1d9aba53..17d8a230 100644 --- a/config/SOUE01/splits.txt +++ b/config/SOUE01/splits.txt @@ -248,7 +248,7 @@ m/m_mtx.cpp: .ctors start:0x804DB8D4 end:0x804DB8D8 m/m_pad.cpp: - .text start:0x802F1F20 end:0x802F2330 + .text start:0x802F1F20 end:0x802F232C .ctors start:0x804DB8D8 end:0x804DB8DC .sbss start:0x80575C50 end:0x80575C70 .sdata2 start:0x8057CDF8 end:0x8057CE00 diff --git a/config/SOUE01/symbols.txt b/config/SOUE01/symbols.txt index 8c4bf1c6..82cc7bad 100644 --- a/config/SOUE01/symbols.txt +++ b/config/SOUE01/symbols.txt @@ -17860,7 +17860,7 @@ getWPADInfoCB__4mPadFi = .text:0x802F21F0; // type:function size:0x64 __sinit_\m_pad_cpp = .text:0x802F2260; // type:function size:0x58 scope:local __ct__Q24mPad19PadAdditionalData_tFv = .text:0x802F22C0; // type:function size:0x4 __dt__Q24mPad19PadAdditionalData_tFv = .text:0x802F22D0; // type:function size:0x40 -__arraydtor$4391 = .text:0x802F2310; // type:function size:0x1C +__arraydtor$4414 = .text:0x802F2310; // type:function size:0x1C fn_802F2330 = .text:0x802F2330; // type:function size:0x120 fn_802F2450 = .text:0x802F2450; // type:function size:0x18C fn_802F25E0 = .text:0x802F25E0; // type:function size:0x19C @@ -22811,7 +22811,7 @@ fn_803DADF0 = .text:0x803DADF0; // type:function size:0x5C fn_803DAE50 = .text:0x803DAE50; // type:function size:0x44 fn_803DAEA0 = .text:0x803DAEA0; // type:function size:0xC0 fn_803DAF60 = .text:0x803DAF60; // type:function size:0x54 -fn_803DAFC0 = .text:0x803DAFC0; // type:function size:0x220 +WPADGetInfoAsync = .text:0x803DAFC0; // type:function size:0x220 fn_803DB1E0 = .text:0x803DB1E0; // type:function size:0xCC fn_803DB2B0 = .text:0x803DB2B0; // type:function size:0x34 fn_803DB2F0 = .text:0x803DB2F0; // type:function size:0x34 @@ -40279,7 +40279,7 @@ g_assertHeap__5mHeap = .sbss:0x80575C48; // type:object size:0x4 data:4byte g_padMg__4mPad = .sbss:0x80575C50; // type:object size:0x4 data:4byte g_currentCoreId__4mPad = .sbss:0x80575C54; // type:object size:0x4 data:4byte g_currentCore__4mPad = .sbss:0x80575C58; // type:object size:0x4 data:4byte -g_IsConnected__4mPad = .sbss:0x80575C5C; // type:object size:0x1 data:byte +g_IsConnected__4mPad = .sbss:0x80575C5C; // type:object size:0x4 data:byte g_PadFrame__4mPad = .sbss:0x80575C60; // type:object size:0x4 data:4byte s_WPADInfoAvailable__4mPad = .sbss:0x80575C64; // type:object size:0x4 s_GetWPADInfoInterval__4mPad = .sbss:0x80575C68; // type:object size:0x4 data:4byte @@ -49082,7 +49082,7 @@ lbl_805CAF98 = .bss:0x805CAF98; // type:object size:0xC g_gameHeaps__5mHeap = .bss:0x805CB078; // type:object size:0x10 data:4byte lbl_805CB088 = .bss:0x805CB088; // type:object size:0x30 data:4byte g_core__4mPad = .bss:0x805CB0B8; // type:object size:0x10 data:4byte -lbl_805CB0C8 = .bss:0x805CB0C8; // type:object size:0x10 +lbl_805CB0C8 = .bss:0x805CB0C8; // type:object size:0xC g_PadAdditionalData__4mPad = .bss:0x805CB0D8; // type:object size:0x60 data:float s_WPADInfo__4mPad = .bss:0x805CB138; // type:object size:0x60 s_WPADInfoTmp__4mPad = .bss:0x805CB198; // type:object size:0x60 diff --git a/configure.py b/configure.py index cad27891..ca6a97c8 100644 --- a/configure.py +++ b/configure.py @@ -307,7 +307,7 @@ config.libs = [ Object(Matching, "m/m_dvd.cpp"), Object(Matching, "m/m_heap.cpp"), Object(NonMatching, "m/m_mtx.cpp"), - Object(NonMatching, "m/m_pad.cpp"), + Object(Matching, "m/m_pad.cpp"), Object(Matching, "DynamicLink.cpp"), # framework (f_name) # d stuff (d_name) diff --git a/include/m/m_pad.h b/include/m/m_pad.h index 7878204a..fd45ee3b 100644 --- a/include/m/m_pad.h +++ b/include/m/m_pad.h @@ -3,6 +3,11 @@ namespace mPad { +extern EGG::CoreControllerMgr *g_padMg; +extern int g_currentCoreId; +extern EGG::CoreController *g_currentCore; +extern EGG::CoreController *g_core[4]; + void create(); void beginPad(); void endPad(); diff --git a/include/rvl/WPAD/WPAD.h b/include/rvl/WPAD/WPAD.h index 67a16c43..271433bf 100644 --- a/include/rvl/WPAD/WPAD.h +++ b/include/rvl/WPAD/WPAD.h @@ -17,12 +17,26 @@ typedef enum { WPAD_RESULT_SUCCESS = 0, } WPADResult; + +typedef struct { + u32 field_0x00; + u32 field_0x04; + u32 field_0x08; + u32 field_0x0C; + u32 field_0x10; + bool field_0x14; + bool field_0x15; + bool field_0x16; + bool field_0x17; +} WPADInfo; + UNKTYPE WPADControlSpeaker(s32, UNKWORD, WPADCallback); BOOL WPADCanSendStreamData(s32); UNKWORD WPADSendStreamData(s32, UNKTYPE *, UNKWORD); s32 WPADProbe(s32 chan, u32 *type); s32 WPADReadFaceData(s32 chan, void *dst, u32 size, u32 src, WPADCallback cb); +s32 WPADGetInfoAsync(s32 chan, WPADInfo *dst, WPADCallback cb); #ifdef __cplusplus } diff --git a/src/m/m_pad.cpp b/src/m/m_pad.cpp index 63b4bf18..3b880d96 100644 --- a/src/m/m_pad.cpp +++ b/src/m/m_pad.cpp @@ -2,44 +2,22 @@ #include #include #include +#include namespace mPad { -static EGG::CoreControllerMgr *g_padMg; -static int g_currentCoreId; -static EGG::CoreController *g_currentCore; +EGG::CoreControllerMgr *g_padMg; +int g_currentCoreId; +EGG::CoreController *g_currentCore; +EGG::CoreController *g_core[4]; + static bool g_IsConnected[4]; static u32 g_PadFrame; -static u32 s_GetWPADInfoInterval = 0; static bool s_WPADInfoAvailable[4]; +static u32 s_GetWPADInfoInterval = 0; static u32 s_GetWPADInfoCount = 0; -static EGG::CoreController *g_core[4]; - -struct WPADInfo_t { - u32 field_0x00; - u32 field_0x04; - u32 field_0x08; - u32 field_0x0C; - u32 field_0x10; - bool field_0x14; - bool field_0x15; - bool field_0x16; - bool field_0x17; - - inline void clear() { - field_0x00 = 0; - field_0x04 = 0; - field_0x08 = 0; - field_0x0C = 0; - field_0x10 = 0; - field_0x14 = false; - field_0x15 = false; - field_0x16 = false; - field_0x17 = false; - } -}; struct PadAdditionalData_t { PadAdditionalData_t() {} @@ -51,8 +29,8 @@ struct PadAdditionalData_t { }; static PadAdditionalData_t g_PadAdditionalData[4]; -static WPADInfo_t s_WPADInfo[4]; -static WPADInfo_t s_WPADInfoTmp[4]; +static WPADInfo s_WPADInfo[4]; +static WPADInfo s_WPADInfoTmp[4]; static void initWPADInfo(); static void clearWPADInfo(int); @@ -65,27 +43,36 @@ void create() { endPad(); } -// Has a regshuffle +// This code looks really bad. +// It mostly matches when writing it the obvious way +// (just indexing the arrays normally) +// but has an annoying regshuffle void beginPad() { - EGG::CoreController *ctl; g_PadFrame++; g_padMg->beginFrame(); - for (int i = 0; i < 4; i++) { + EGG::CoreController *ctl; + EGG::CoreController **p_ctl = g_core; + PadAdditionalData_t *dat = g_PadAdditionalData; + bool *connected; + int i = 0; + connected = g_IsConnected; + + for (; i < 4; i++) { ctl = g_padMg->getNthController(i); - g_core[i] = ctl; + *p_ctl = ctl; if (ctl->mFlag.onBit(0)) { // These sort of look like value, first order derivative, and second order derivative // So perhaps value, velocity, acceleration? EGG::Vector2f pos = ctl->coreStatus[0].getUnk(); - EGG::Vector2f v = pos - g_PadAdditionalData[i].v1; - g_PadAdditionalData[i].v1 = pos; - g_PadAdditionalData[i].v3 = v - g_PadAdditionalData[i].v2; - g_PadAdditionalData[i].v2 = v; + EGG::Vector2f v = pos - dat->v1; + dat->v1 = pos; + dat->v3 = v - dat->v2; + dat->v2 = v; - if (!g_IsConnected[i]) { - g_IsConnected[i] = true; + if (!*connected) { + *connected = true; } // Not sure why this checks the controller index against the tick count @@ -94,18 +81,22 @@ void beginPad() { (s_GetWPADInfoInterval <= 3 && (s_GetWPADInfoCount & 1) == (i & 1)))) { getWPADInfoCB(i); } - } else if (g_IsConnected[i]) { + } else if (*connected) { ctl->coreStatus->init(); ctl->sceneReset(); - g_PadAdditionalData[i].v1.x = 0.0f; - g_PadAdditionalData[i].v1.y = 0.0f; - g_PadAdditionalData[i].v3.x = 0.0f; - g_PadAdditionalData[i].v3.y = 0.0f; - g_PadAdditionalData[i].v2.x = 0.0f; - g_PadAdditionalData[i].v2.y = 0.0f; + dat->v1.x = 0.0f; + dat->v1.y = 0.0f; + dat->v3.x = 0.0f; + dat->v3.y = 0.0f; + dat->v2.x = 0.0f; + dat->v2.y = 0.0f; clearWPADInfo(i); - g_IsConnected[i] = false; + *connected = false; } + + p_ctl++; + dat++; + connected++; } if (s_GetWPADInfoInterval != 0) { @@ -121,9 +112,21 @@ void endPad() { g_padMg->endFrame(); } +static inline void clear(WPADInfo *info) { + info->field_0x00 = 0; + info->field_0x04 = 0; + info->field_0x08 = 0; + info->field_0x0C = 0; + info->field_0x10 = 0; + info->field_0x14 = false; + info->field_0x15 = false; + info->field_0x16 = false; + info->field_0x17 = false; +} + static void clearWPADInfo(int controller) { s_WPADInfoAvailable[controller] = false; - s_WPADInfo[controller].clear(); + clear(&s_WPADInfo[controller]); } static void initWPADInfo() { @@ -132,11 +135,10 @@ static void initWPADInfo() { } } -extern "C" int fn_803DAFC0(int controller, void *data, void (*callback)(int, int)); -extern "C" void fn_80058DA0(int, int); +extern "C" void fn_80058DA0(s32, s32); static int getWPADInfoCB(int controller) { - int result = fn_803DAFC0(controller, &s_WPADInfoTmp[controller], fn_80058DA0); + int result = WPADGetInfoAsync(controller, &s_WPADInfoTmp[controller], fn_80058DA0); if (result == -1) { clearWPADInfo(controller); }