Compare commits

...

5 Commits

Author SHA1 Message Date
coah
4e41a7ba9c fix controller manager readability 2026-09-28 23:23:30 +00:00
coah
d2d00f38ff split iplController into controller and manager units, decompile the asm 2026-09-28 23:23:30 +00:00
coah
33911687c7 decompile controller leaf destructors 2026-09-28 23:23:30 +00:00
coah
03bc324c97 model controller inheritance 2026-09-28 23:23:30 +00:00
coah
7e24906764 decompile controller asm bodies 2026-09-28 23:23:30 +00:00
7 changed files with 745 additions and 1726 deletions

View File

@@ -37,11 +37,16 @@ src/system/iplSystem.cpp:
.sdata start:0x81696060 end:0x81696080
src/system/iplController.cpp:
.text start:0x81335CCC end:0x81337978
.text start:0x81335CCC end:0x81337318
.rodata start:0x8160D2C0 end:0x8160D2D0
.data start:0x816346A8 end:0x81634A28
.sdata2 start:0x81694440 end:0x81694490
.data start:0x816346A8 end:0x81634910
.sdata2 start:0x81694440 end:0x81694478
.sdata start:0x81696080 end:0x81696088
src/system/iplControllerManager.cpp:
.text start:0x81337318 end:0x81337978
.data start:0x81634910 end:0x81634A28
.sdata2 start:0x81694478 end:0x81694490
.sbss start:0x81698680 end:0x81698690
src/system/iplChannelManager.cpp:

View File

@@ -625,6 +625,7 @@ config.libs = [
Object(Matching, "system/RIPL_BoardRecord.c"),
Object(Matching, "system/iplSystem.cpp"),
Object(NonMatching, "system/iplController.cpp"),
Object(NonMatching, "system/iplControllerManager.cpp"),
Object(Matching, "system/iplChannelManager.cpp"),
Object(Matching, "system/iplChannelScriptManager.cpp"),
Object(Matching, "system/iplNand.cpp"),

View File

@@ -35,6 +35,10 @@ namespace ipl {
return x;
}
}
#ifdef IPL_CONTROLLER_OUT_OF_LINE_ABS_CLAMP
template <>
f32 abs_clamp<f32>(const f32& x, const f32& y);
#endif
typedef struct MTX33 : public nw4r::math::MTX33 {
} MTX33;
@@ -55,19 +59,27 @@ namespace ipl {
x = r.x;
y = r.y;
}
#ifdef IPL_CONTROLLER_OUT_OF_LINE_VEC2
VEC2(f32 fx, f32 fy);
#else
VEC2(f32 fx, f32 fy) {
x = fx;
y = fy;
}
#endif
void operator=(const VEC2& r);
VEC2 operator*(f32 val) const { return VEC2(x * val, y * val); }
#ifdef IPL_CONTROLLER_OUT_OF_LINE_VEC2
void set(f32 fx, f32 fy);
#else
void set(f32 fx, f32 fy) {
x = fx;
y = fy;
}
#endif
void clear() {
y = 0;

View File

@@ -62,6 +62,200 @@ namespace ipl {
};
// clang-format on
#ifdef IPL_CONTROLLER_NATIVE_HIERARCHY
#ifdef IPL_CONTROLLER_INLINE_INTERFACE
#define IPL_CONTROLLER_DEFAULT_VIRTUAL(signature, implementation) virtual signature implementation
#else
#define IPL_CONTROLLER_DEFAULT_VIRTUAL(signature, implementation) virtual signature;
#endif
class Interface {
public:
virtual ~Interface() = 0;
IPL_CONTROLLER_DEFAULT_VIRTUAL(int getType() const, { return -1; })
IPL_CONTROLLER_DEFAULT_VIRTUAL(int getChannel() const, { return -1; })
IPL_CONTROLLER_DEFAULT_VIRTUAL(bool down(u32 button) const, { return false; })
IPL_CONTROLLER_DEFAULT_VIRTUAL(bool downTrg(u32 button) const, { return false; })
IPL_CONTROLLER_DEFAULT_VIRTUAL(bool upTrg(u32 button) const, { return false; })
IPL_CONTROLLER_DEFAULT_VIRTUAL(int pinch() const, { return 0; })
IPL_CONTROLLER_DEFAULT_VIRTUAL(int pinchTrg() const, { return 0; })
IPL_CONTROLLER_DEFAULT_VIRTUAL(int pinchOffTrg() const, { return 0; })
IPL_CONTROLLER_DEFAULT_VIRTUAL(int decide() const, { return 0; })
IPL_CONTROLLER_DEFAULT_VIRTUAL(bool repeat(u32 button) const, { return false; })
IPL_CONTROLLER_DEFAULT_VIRTUAL(BOOL rumble(int type = 0), { return FALSE; })
IPL_CONTROLLER_DEFAULT_VIRTUAL(void cancelRumbling(), { })
IPL_CONTROLLER_DEFAULT_VIRTUAL(int getHoldFlag() const, { return 0; })
IPL_CONTROLLER_DEFAULT_VIRTUAL(int getTrigFlag() const, { return 0; })
IPL_CONTROLLER_DEFAULT_VIRTUAL(int getReleaseFlag() const, { return 0; })
IPL_CONTROLLER_DEFAULT_VIRTUAL(int getClassicHoldFlag() const, { return 0; })
IPL_CONTROLLER_DEFAULT_VIRTUAL(int getClassicTrigFlag() const, { return 0; })
IPL_CONTROLLER_DEFAULT_VIRTUAL(int getClassicReleaseFlag() const, { return 0; })
IPL_CONTROLLER_DEFAULT_VIRTUAL(math::VEC2 getDpdPos() const, { return math::VEC2(0.0f, 0.0f); })
IPL_CONTROLLER_DEFAULT_VIRTUAL(math::VEC2 getDpdProjectionPos() const, { return math::VEC2(0.0f, 0.0f); })
IPL_CONTROLLER_DEFAULT_VIRTUAL(math::VEC2 getHorizon() const, { return math::VEC2(0.0f, 0.0f); })
IPL_CONTROLLER_DEFAULT_VIRTUAL(f32 getDpdDistance() const, { return 0.0f; })
IPL_CONTROLLER_DEFAULT_VIRTUAL(KPADStatus* getKPADStatus() const, { return NULL; })
IPL_CONTROLLER_DEFAULT_VIRTUAL(PADStatus* getPADStatus() const, { return NULL; })
IPL_CONTROLLER_DEFAULT_VIRTUAL(bool isValidBtn() const, { return false; })
IPL_CONTROLLER_DEFAULT_VIRTUAL(bool isValidDpd() const, { return false; })
virtual void setForceInvalid(bool flag) = 0;
IPL_CONTROLLER_DEFAULT_VIRTUAL(int getMainStickX() const, { return 0; })
IPL_CONTROLLER_DEFAULT_VIRTUAL(int getMainStickY() const, { return 0; })
IPL_CONTROLLER_DEFAULT_VIRTUAL(int getSubStickX() const, { return 0; })
IPL_CONTROLLER_DEFAULT_VIRTUAL(int getSubStickY() const, { return 0; })
IPL_CONTROLLER_DEFAULT_VIRTUAL(void read(), { })
};
#undef IPL_CONTROLLER_DEFAULT_VIRTUAL
#ifdef IPL_CONTROLLER_INLINE_INTERFACE
inline Interface::~Interface() {}
#endif
class Base : public Interface {
public:
Base(int chan, KPADStatus& status) {
mButton = 0;
unk_0x08 = 0;
mLastRumbleTime = 0;
mRumbleType = -1;
mChan = chan;
mType = 2;
unk_0x1C = 0;
KPADEnableDPD(chan);
unk_0x1D = 0;
unk_0x1E = 0;
unk_0x20 = &status;
}
Base(int chan, int type, KPADStatus& status) {
mButton = 0;
unk_0x08 = 0;
mLastRumbleTime = 0;
mRumbleType = -1;
mChan = chan;
mType = type;
unk_0x1C = 0;
KPADEnableDPD(chan);
}
virtual ~Base();
virtual int getType() const override;
virtual int getChannel() const override;
virtual int decide() const override;
virtual BOOL rumble(int timer = 0) override;
virtual void cancelRumbling() override;
virtual void setForceInvalid(bool flag) override;
virtual void read() override;
protected:
u8 mButton;
u32 unk_0x08;
OSTick mLastRumbleTime;
s32 mRumbleType;
u32 mChan;
u32 mType;
u8 unk_0x1C;
u8 unk_0x1D;
u8 unk_0x1E;
KPADStatus* unk_0x20;
};
class Revolution : public Base {
public:
Revolution(int chan, KPADStatus& status) : Base(chan, status) {}
Revolution(int chan, int type, KPADStatus& status);
virtual ~Revolution();
virtual bool down(u32 button) const override;
virtual bool downTrg(u32 button) const override;
virtual bool upTrg(u32 button) const override;
virtual int pinch() const override;
virtual int pinchTrg() const override;
virtual int pinchOffTrg() const override;
virtual bool repeat(u32 button) const override;
virtual f32 getDpdDistance() const override;
virtual KPADStatus* getKPADStatus() const override;
virtual int getReleaseFlag() const override;
virtual int getTrigFlag() const override;
virtual int getHoldFlag() const override;
virtual math::VEC2 getDpdPos() const override;
virtual math::VEC2 getDpdProjectionPos() const override;
virtual math::VEC2 getHorizon() const override;
virtual bool isValidBtn() const override;
virtual bool isValidDpd() const override;
virtual void read() override;
};
class Classic : public Revolution {
public:
Classic(int chan, KPADStatus& status);
virtual ~Classic();
virtual bool down(u32 button) const override;
virtual bool downTrg(u32 button) const override;
virtual bool upTrg(u32 button) const override;
virtual int getClassicHoldFlag() const override;
virtual int getClassicTrigFlag() const override;
virtual int getClassicReleaseFlag() const override;
virtual math::VEC2 getDpdPos() const override;
virtual math::VEC2 getDpdProjectionPos() const override;
virtual math::VEC2 getHorizon() const override;
virtual bool isValidDpd() const override;
virtual void read() override;
virtual BOOL isValidDpdClassic() const;
private:
math::VEC2 unk_0x24;
int unk_0x2C;
};
class Master : public Interface {
public:
Master(Interface** controllers) : mpControllers(controllers) {}
virtual ~Master();
virtual bool down(u32 button) const override;
virtual bool downTrg(u32 button) const override;
virtual bool upTrg(u32 button) const override;
virtual bool repeat(u32 button) const override;
virtual int decide() const override;
virtual void setForceInvalid(bool flag) override;
private:
bool call(u32 button, bool (Interface::*func)(u32) const) const;
Interface** mpControllers;
};
class Core : public Revolution {
public:
Core(int chan, int type, KPADStatus& status) : Revolution(chan, type, status) {}
virtual ~Core();
};
class FreeStyle : public Revolution {
public:
FreeStyle(int chan, int type, KPADStatus& status) : Revolution(chan, type, status) {}
virtual ~FreeStyle();
};
class Manager {
public:
Manager(EGG::Heap* heap);
void read();
Interface* getController(int chan);
Interface* getMasterController();
Interface* getYoungController();
static void* alloc(u32 size);
static int free(void* ptr);
private:
static void* mpBuf;
static EGG::Heap* mpParentHeap;
static EGG::ExpHeap* mpHeap;
static EGG::Allocator* mpAllocator;
Interface* mControllers[4];
u32 mControllerStorage[4][12];
Master mMaster;
KPADStatus mKPADStatus[4];
s32 mInvalidCount[4];
};
#else
class Base {
public:
Base(int chan, KPADStatus& arg1) {
@@ -118,11 +312,11 @@ namespace ipl {
virtual bool setForceInvalid(bool flag); // 0x74
virtual f32 getMainStickX() const; // 0x78
virtual f32 getMainStickY() const; // 0x7C
virtual int getMainStickX() const; // 0x78
virtual int getMainStickY() const; // 0x7C
virtual f32 getSubStickX() const; // 0x80
virtual f32 getSubStickY() const; // 0x84
virtual int getSubStickX() const; // 0x80
virtual int getSubStickY() const; // 0x84
virtual void read(); // 0x88
@@ -169,10 +363,10 @@ namespace ipl {
virtual math::VEC2 getDpdPos() const override;
virtual math::VEC2 getDpdProjectionPos() const override;
virtual math::VEC2 getHorizon() const override;
virtual f32 getMainStickX() const override;
virtual f32 getMainStickY() const override;
virtual f32 getSubStickX() const override;
virtual f32 getSubStickY() const override;
virtual int getMainStickX() const override;
virtual int getMainStickY() const override;
virtual int getSubStickX() const override;
virtual int getSubStickY() const override;
virtual BOOL rumble(int type = 0) override;
virtual void read() override;
};
@@ -228,6 +422,7 @@ namespace ipl {
class Classic : public Revolution {
public:
Classic(int arg0, KPADStatus& arg1);
virtual ~Classic();
virtual bool down(u32 button) const override;
virtual bool downTrg(u32 button) const override;
@@ -268,6 +463,7 @@ namespace ipl {
static EGG::Allocator* mpAllocator;
u8 dummy[0x2F8];
};
#endif
} // namespace controller
} // namespace ipl

View File

@@ -16,7 +16,9 @@ namespace nw4r {
#endif
Rect(f32 l, f32 t, f32 r, f32 b) : left(l), top(t), right(r), bottom(b) {}
#ifndef IPL_CONTROLLER_TRIVIAL_RECT_DTOR
~Rect() {}
#endif
void SetWidth(f32 width) { right = left + width; }
void SetHeight(f32 height) { bottom = top + height; }

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,187 @@
#include <decomp/ide.h>
#include <math/iplMathTypes.h>
#define IPL_SOUND_RECT_OUT_OF_LINE
#include <nw4r/ut/Rect.h>
#undef IPL_SOUND_RECT_OUT_OF_LINE
#include <revolution/kpad.h>
#include <revolution/mtx/GeoTypes.h>
#include <revolution/os.h>
#include <revolution/os/OSTime.h>
#include <revolution/sc.h>
#include <revolution/wpad.h>
#define IPL_CONTROLLER_NATIVE_HIERARCHY
#include "system/iplController.h"
#undef IPL_CONTROLLER_NATIVE_HIERARCHY
#include "system/iplSystem.h"
extern "C" void _savegpr_16();
extern "C" void _restgpr_16();
extern "C" void _savegpr_29();
extern "C" void _restgpr_29();
extern "C" void _savegpr_27();
extern "C" void _restgpr_27();
extern "C" void _savegpr_28();
extern "C" void _restgpr_28();
namespace ipl {
namespace controller {
void* Manager::mpBuf;
EGG::Heap* Manager::mpParentHeap;
EGG::ExpHeap* Manager::mpHeap;
EGG::Allocator* Manager::mpAllocator;
void* Manager::alloc(u32 size) {
return mpAllocator->alloc(size);
}
int Manager::free(void* ptr) {
mpAllocator->free(ptr);
return TRUE;
}
Manager::Manager(EGG::Heap* heap) : mMaster(mControllers) {
memset(mKPADStatus, 0, sizeof(mKPADStatus));
memset(mControllers, 0, sizeof(mControllers));
u32 workSize = WPADGetWorkMemorySize() + 0x400;
if (mpBuf != NULL && mpParentHeap != NULL) {
mpParentHeap->free(mpBuf);
}
mpParentHeap = heap;
mpBuf = heap->alloc(workSize, 0x20);
if (mpHeap != NULL) {
mpHeap->destroy();
}
mpHeap = EGG::ExpHeap::create(mpBuf, workSize, 2);
if (mpAllocator != NULL) {
delete mpAllocator;
}
mpAllocator = new (heap, 4) EGG::Allocator(mpHeap, 4);
WPADRegisterAllocator(alloc, free);
KPADInit();
u32 sensitivity = SCGetBtDpdSensibility();
for (int i = 0; i < 4; i++) {
WPADSetDpdSensitivity(sensitivity);
KPADSetBtnRepeat(i, 0.5f, 0.1f);
}
read();
}
void Manager::read() {
for (int chan = 0; chan < 4; chan++) {
if (SCGetWpadSensorBarPosition() == 1) {
KPADSetSensorHeight(chan, 0.2f);
} else {
KPADSetSensorHeight(chan, -0.2f);
}
u32 deviceType;
s32 probe = WPADProbe(chan, &deviceType);
if (probe == -1) {
goto probe_invalid;
}
if (probe < -1) {
if (probe >= -3) {
goto probe_valid;
}
goto probe_invalid;
} else if (probe >= 1) {
goto probe_invalid;
}
probe_valid:
{
s32 read = KPADRead(chan, &mKPADStatus[chan], 1);
if (read > 0) {
if (mKPADStatus[chan].wpad_err == -4 || deviceType == 0xfd) {
goto store_null;
}
mInvalidCount[chan] = 0;
if (mKPADStatus[chan].wpad_err == -7 || deviceType == 0 || deviceType == 0xfb ||
deviceType == 0xfc || deviceType == 0xff) {
if (mControllers[chan] == NULL || mControllers[chan]->getType() != 0) {
mControllers[chan] = new (mControllerStorage[chan]) Core(chan, 0, mKPADStatus[chan]);
}
} else if (deviceType == 1) {
if (mControllers[chan] == NULL || mControllers[chan]->getType() != 1) {
mControllers[chan] = new (mControllerStorage[chan]) FreeStyle(chan, 1, mKPADStatus[chan]);
}
} else if (deviceType == 2) {
if (mControllers[chan] == NULL || mControllers[chan]->getType() != 2) {
mControllers[chan] = new (mControllerStorage[chan]) Classic(chan, mKPADStatus[chan]);
}
} else {
mControllers[chan] = NULL;
}
} else if (read == 0) {
mInvalidCount[chan]++;
if (mInvalidCount[chan] > 0x3c) {
mInvalidCount[chan] = 0x3c;
if (mControllers[chan] != NULL) {
WPADControlMotor(chan, 0);
}
mControllers[chan] = NULL;
}
} else {
goto store_null;
}
}
goto channel_done;
store_null:
mControllers[chan] = NULL;
goto channel_done;
probe_invalid:
KPADRead(chan, &mKPADStatus[chan], 1);
mControllers[chan] = NULL;
channel_done:
KPADSetPosParam(chan, 0.05f, 1.0f);
}
for (int chan = 0; chan < 4; chan++) {
if (mControllers[chan] != NULL) {
mControllers[chan]->read();
}
}
}
Revolution::Revolution(int chan, int type, KPADStatus& status) : Base(chan, type, status) {
unk_0x1D = 0;
unk_0x1E = 0;
unk_0x20 = &status;
}
Interface* Manager::getMasterController() {
return &mMaster;
}
Interface* Manager::getController(int chan) {
return ((Interface**)this)[chan];
}
Interface* Manager::getYoungController() {
Interface* ret = NULL;
for (int i = 0; i < 4; i++) {
Interface* controller = ((Interface**)this)[i];
if (controller != NULL) {
ret = controller;
break;
}
}
return ret;
}
Core::~Core() {}
FreeStyle::~FreeStyle() {}
}
}