Merge pull request #47 from robojumper/m_pad

m_pad
This commit is contained in:
Elijah Thomas
2024-05-31 20:10:22 -04:00
committed by GitHub
9 changed files with 232 additions and 34 deletions
+7
View File
@@ -258,6 +258,13 @@ m/m_mtx.cpp:
.text start:0x802F1660 end:0x802F1F20
.ctors start:0x804DB8D4 end:0x804DB8D8
m/m_pad.cpp:
.text start:0x802F1F20 end:0x802F232C
.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
+27 -27
View File
@@ -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$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
@@ -26336,7 +26336,7 @@ getNthController__Q23EGG17CoreControllerMgrFi = .text:0x80499BE0; // type:functi
errRangeOver__Q23EGG32TBuffer<PQ23EGG14CoreController>Fv = .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__Q23EGG32TBuffer<PQ23EGG14CoreController>Fv = .text:0x8049A030; // type:function size:0x78
__dt__Q23EGG29TBuffer<Q23EGG12eCoreDevType>Fv = .text:0x8049A0B0; // type:function size:0x78
@@ -40321,14 +40321,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: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
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
@@ -45895,7 +45895,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
@@ -48185,7 +48185,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
@@ -49126,11 +49126,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
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_core__4mPad = .bss:0x805CB0B8; // type:object size:0x10 data:4byte
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
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
+1
View File
@@ -310,6 +310,7 @@ config.libs = [
Object(Matching, "m/m_dvd.cpp"),
Object(Matching, "m/m_heap.cpp"),
Object(NonMatching, "m/m_mtx.cpp"),
Object(Matching, "m/m_pad.cpp"),
Object(Matching, "DynamicLink.cpp"),
# framework (f_name)
# d stuff (d_name)
+12 -5
View File
@@ -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);
+4
View File
@@ -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 {
+17
View File
@@ -0,0 +1,17 @@
#ifndef M_PAD_H
#define M_PAD_H
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();
} // namespace mPad
#endif
+14
View File
@@ -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
}
+2 -2
View File
@@ -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);
+148
View File
@@ -0,0 +1,148 @@
#include <common.h>
#include <egg/core/eggController.h>
#include <egg/math/eggVector.h>
#include <m/m_pad.h>
#include <rvl/WPAD.h>
namespace mPad {
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 bool s_WPADInfoAvailable[4];
static u32 s_GetWPADInfoInterval = 0;
static u32 s_GetWPADInfoCount = 0;
struct PadAdditionalData_t {
PadAdditionalData_t() {}
~PadAdditionalData_t() {}
EGG::Vector2f v1;
EGG::Vector2f v2;
EGG::Vector2f v3;
};
static PadAdditionalData_t g_PadAdditionalData[4];
static WPADInfo s_WPADInfo[4];
static WPADInfo 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();
}
// 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() {
g_PadFrame++;
g_padMg->beginFrame();
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);
*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 - dat->v1;
dat->v1 = pos;
dat->v3 = v - dat->v2;
dat->v2 = v;
if (!*connected) {
*connected = 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 (*connected) {
ctl->coreStatus->init();
ctl->sceneReset();
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);
*connected = false;
}
p_ctl++;
dat++;
connected++;
}
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 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;
clear(&s_WPADInfo[controller]);
}
static void initWPADInfo() {
for (int i = 0; i < 4; i++) {
clearWPADInfo(i);
}
}
extern "C" void fn_80058DA0(s32, s32);
static int getWPADInfoCB(int controller) {
int result = WPADGetInfoAsync(controller, &s_WPADInfoTmp[controller], fn_80058DA0);
if (result == -1) {
clearWPADInfo(controller);
}
return result;
}
} // namespace mPad