diff --git a/config/SOUE01/splits.txt b/config/SOUE01/splits.txt index 051178df..fe5bc675 100644 --- a/config/SOUE01/splits.txt +++ b/config/SOUE01/splits.txt @@ -341,7 +341,7 @@ egg/core/eggAssertHeap.cpp: egg/core/eggDisposer.cpp: .text start:0x80496830 end:0x80496904 - .data start:0x8056EA30 end:0x8056EA40 + .data start:0x8056EA30 end:0x8056EA3C egg/core/eggThread.cpp: .text start:0x80496910 end:0x80496DD8 @@ -398,6 +398,7 @@ egg/core/eggController.cpp: .ctors start:0x804DB98C end:0x804DB990 .rodata start:0x804FBA20 end:0x804FBA30 .data start:0x8056EB90 end:0x8056EC88 + .sbss start:0x805767A8 end:0x805767C0 .sdata2 start:0x8057F338 end:0x8057F360 .bss start:0x80673B40 end:0x80674C00 diff --git a/config/SOUE01/symbols.txt b/config/SOUE01/symbols.txt index d28509e7..bc2934cf 100644 --- a/config/SOUE01/symbols.txt +++ b/config/SOUE01/symbols.txt @@ -498,7 +498,7 @@ fn_800146E0 = .text:0x800146E0; // type:function size:0x38 fn_80014720 = .text:0x80014720; // type:function size:0x228 fn_80014950 = .text:0x80014950; // type:function size:0x5C fn_800149B0 = .text:0x800149B0; // type:function size:0x478 -fn_80014E30 = .text:0x80014E30; // type:function size:0x18 +isTriggered__Q23EGG14CoreControllerFUi = .text:0x80014E30; // type:function size:0x18 fn_80014E50 = .text:0x80014E50; // type:function size:0x54 fn_80014EB0 = .text:0x80014EB0; // type:function size:0x3C4 fn_80015280 = .text:0x80015280; // type:function size:0x1C @@ -2370,8 +2370,8 @@ fn_800597A0 = .text:0x800597A0; // type:function size:0x18 fn_800597C0 = .text:0x800597C0; // type:function size:0x18 fn_800597E0 = .text:0x800597E0; // type:function size:0x18 fn_80059800 = .text:0x80059800; // type:function size:0x18 -fn_80059820 = .text:0x80059820; // type:function size:0x18 -fn_80059840 = .text:0x80059840; // type:function size:0x18 +isPressed__Q23EGG14CoreControllerFUi = .text:0x80059820; // type:function size:0x18 +isAllPressed__Q23EGG14CoreControllerFv = .text:0x80059840; // type:function size:0x18 fn_80059860 = .text:0x80059860; // type:function size:0x18 fn_80059880 = .text:0x80059880; // type:function size:0x18 fn_800598A0 = .text:0x800598A0; // type:function size:0x18 @@ -2384,12 +2384,12 @@ fn_80059960 = .text:0x80059960; // type:function size:0x18 fn_80059980 = .text:0x80059980; // type:function size:0x18 fn_800599A0 = .text:0x800599A0; // type:function size:0x18 fn_800599C0 = .text:0x800599C0; // type:function size:0x18 -fn_800599E0 = .text:0x800599E0; // type:function size:0x18 +isReleased__Q23EGG14CoreControllerFv = .text:0x800599E0; // type:function size:0x18 fn_80059A00 = .text:0x80059A00; // type:function size:0x18 fn_80059A20 = .text:0x80059A20; // type:function size:0x18 fn_80059A40 = .text:0x80059A40; // type:function size:0x18 -fn_80059A60 = .text:0x80059A60; // type:function size:0x1C -fn_80059A80 = .text:0x80059A80; // type:function size:0x14 +isAnyPressed__Q23EGG14CoreControllerFUi = .text:0x80059A60; // type:function size:0x1C +isNotPressed__Q23EGG14CoreControllerFv = .text:0x80059A80; // type:function size:0x14 fn_80059AA0 = .text:0x80059AA0; // type:function size:0x18 fn_80059AC0 = .text:0x80059AC0; // type:function size:0x8 fn_80059AD0 = .text:0x80059AD0; // type:function size:0xC @@ -2835,7 +2835,7 @@ fn_800644D0 = .text:0x800644D0; // type:function size:0x10 fn_800644E0 = .text:0x800644E0; // type:function size:0x60 fn_80064540 = .text:0x80064540; // type:function size:0x14 fn_80064560 = .text:0x80064560; // type:function size:0x3BC -fn_80064920 = .text:0x80064920; // type:function size:0x8 +setPosParam__Q23EGG14CoreControllerFff = .text:0x80064920; // type:function size:0x8 fn_80064930 = .text:0x80064930; // type:function size:0x1F4 fn_80064B30 = .text:0x80064B30; // type:function size:0x268 fn_80064DA0 = .text:0x80064DA0; // type:function size:0xB8 @@ -26323,9 +26323,9 @@ stopMotor__Q23EGG14CoreControllerFv = .text:0x804991B0; // type:function size:0x createRumbleMgr__Q23EGG14CoreControllerFUc = .text:0x804991C0; // type:function size:0x58 startPatternRumble__Q23EGG14CoreControllerFPCcib = .text:0x80499220; // type:function size:0x14 stopRumbleMgr__Q23EGG14CoreControllerFv = .text:0x80499240; // type:function size:0x14 -FUN_80499260 = .text:0x80499260; // type:function size:0x10 +getCoreStatus__Q23EGG14CoreControllerFi = .text:0x80499260; // type:function size:0x10 calc_posture_matrix__Q23EGG14CoreControllerFRQ23EGG9Matrix34fb = .text:0x80499270; // type:function size:0x3E8 -beginFrame__Q23EGG14CoreControllerFP9PADStatus = .text:0x80499660; // type:function size:0x3F4 +beginFrame__Q23EGG14CoreControllerFPv = .text:0x80499660; // type:function size:0x3F4 endFrame__Q23EGG14CoreControllerFv = .text:0x80499A60; // type:function size:0x5C getFreeStickX__Q23EGG14CoreControllerCFv = .text:0x80499AC0; // type:function size:0x1C getFreeStickY__Q23EGG14CoreControllerCFv = .text:0x80499AE0; // type:function size:0x1C @@ -26333,10 +26333,10 @@ __dt__Q33EGG17CoreControllerMgr11T__DisposerFv = .text:0x80499B00; // type:funct createInstance__Q23EGG17CoreControllerMgrFv = .text:0x80499B80; // type:function size:0x48 deleteInstance__Q23EGG17CoreControllerMgrFv = .text:0x80499BD0; // type:function size:0x10 getNthController__Q23EGG17CoreControllerMgrFi = .text:0x80499BE0; // type:function size:0x74 -errRangeOver__Q23EGG32TBufferCFv = .text:0x80499C60; // type:function size:0x4 -alloc__Q23EGG27@unnamed@eggController_cpp@FUl = .text:0x80499C70; // type:function size:0x18 -free__Q23EGG27@unnamed@eggController_cpp@FPv = .text:0x80499C90; // type:function size:0x38 -connectCallback__Q23EGG17CoreControllerMgrFll = .text:0x80499CD0; // type:function size:0x3C +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 __ct__Q23EGG17CoreControllerMgrFv = .text:0x80499D10; // type:function size:0x320 __dt__Q23EGG32TBufferFv = .text:0x8049A030; // type:function size:0x78 __dt__Q23EGG29TBufferFv = .text:0x8049A0B0; // type:function size:0x78 @@ -37102,7 +37102,7 @@ lbl_8056E990 = .data:0x8056E990; // type:object size:0xB data:string __vt__Q23EGG7ExpHeap = .data:0x8056E9A0; // type:object size:0x30 lbl_8056E9D0 = .data:0x8056E9D0; // type:object size:0x30 lbl_8056EA00 = .data:0x8056EA00; // type:object size:0x30 -lbl_8056EA30 = .data:0x8056EA30; // type:object size:0x10 +__vt__Q23EGG8Disposer = .data:0x8056EA30; // type:object size:0xC __vt__Q23EGG6Thread = .data:0x8056EA40; // type:object size:0x18 lbl_8056EA58 = .data:0x8056EA58; // type:object size:0x70 __vt__Q23EGG7Display = .data:0x8056EAC8; // type:object size:0x20 @@ -37111,14 +37111,14 @@ clear_z_TX__29@unnamed@eggAsyncDisplay_cpp@ = .data:0x8056EB20; // type:object s __vt__Q23EGG12AsyncDisplay = .data:0x8056EB60; // type:object size:0x20 __vt__Q23EGG12GraphicsFifo = .data:0x8056EB80; // type:object size:0xC lbl_8056EB90 = .data:0x8056EB90; // type:object size:0x18 -lbl_8056EBA8 = .data:0x8056EBA8; // type:object size:0xC -lbl_8056EBB4 = .data:0x8056EBB4; // type:object size:0xC -lbl_8056EBC0 = .data:0x8056EBC0; // type:object size:0x38 -lbl_8056EBF8 = .data:0x8056EBF8; // type:object size:0x10 -lbl_8056EC08 = .data:0x8056EC08; // type:object size:0x1C -lbl_8056EC24 = .data:0x8056EC24; // type:object size:0x1C -lbl_8056EC40 = .data:0x8056EC40; // type:object size:0x10 -lbl_8056EC50 = .data:0x8056EC50; // type:object size:0x38 +__vt__Q23EGG19ControllerRumbleMgr = .data:0x8056EBA8; // type:object size:0xC +__vt__Q23EGG20ControllerRumbleUnit = .data:0x8056EBB4; // type:object size:0xC +__vt__Q23EGG14NullController = .data:0x8056EBC0; // type:object size:0x38 +__vt__Q23EGG17CoreControllerMgr = .data:0x8056EBF8; // type:object size:0x10 +__vt__Q23EGG29TBuffer = .data:0x8056EC08; // type:object size:0x1C +__vt__Q23EGG32TBuffer = .data:0x8056EC24; // type:object size:0x1C +__vt__Q33EGG17CoreControllerMgr11T__Disposer = .data:0x8056EC40; // type:object size:0x10 +__vt__Q23EGG14CoreController = .data:0x8056EC50; // type:object size:0x38 lbl_8056EC88 = .data:0x8056EC88; // type:object size:0xE data:string lbl_8056EC98 = .data:0x8056EC98; // type:object size:0x16 data:string lbl_8056ECB0 = .data:0x8056ECB0; // type:object size:0x20 data:string @@ -40902,12 +40902,12 @@ sTickPeriod__Q23EGG7Display = .sbss:0x80576788; // type:object size:0x4 data:4by spSelector = .sbss:0x80576790; // type:object size:0x4 data:4byte sGraphicsFifo__Q23EGG12GraphicsFifo = .sbss:0x80576798; // type:object size:0x4 data:4byte sGpStatus__Q23EGG12GraphicsFifo = .sbss:0x8057679C; // type:object size:0x5 data:byte -lbl_805767A8 = .sbss:0x805767A8; // type:object size:0x4 data:4byte -lbl_805767AC = .sbss:0x805767AC; // type:object size:0x4 data:4byte -lbl_805767B0 = .sbss:0x805767B0; // type:object size:0x4 data:4byte -lbl_805767B4 = .sbss:0x805767B4; // type:object size:0x4 data:4byte -lbl_805767B8 = .sbss:0x805767B8; // type:object size:0x1 data:byte -lbl_805767BC = .sbss:0x805767BC; // type:object size:0x4 data:4byte +sInstance__Q23EGG17CoreControllerMgr = .sbss:0x805767A8; // type:object size:0x4 data:4byte +sStaticDisposer__Q33EGG17CoreControllerMgr11T__Disposer = .sbss:0x805767AC; // type:object size:0x4 data:4byte +sCoreControllerFactory__Q23EGG17CoreControllerMgr = .sbss:0x805767B0; // type:object size:0x4 data:4byte +sConnectCallback__Q23EGG17CoreControllerMgr = .sbss:0x805767B4; // type:object size:0x4 data:4byte +sUseBuiltinWpadAllocator__Q23EGG17CoreControllerMgr = .sbss:0x805767B8; // type:object size:0x1 data:byte +sWPADAllocator__3EGG = .sbss:0x805767BC; // type:object size:0x4 data:4byte zero__Q23EGG8Vector2f = .sbss:0x805767C0; // type:object size:0x8 data:float ex__Q23EGG8Vector2f = .sbss:0x805767C8; // type:object size:0x8 data:float ey__Q23EGG8Vector2f = .sbss:0x805767D0; // type:object size:0x8 data:float diff --git a/configure.py b/configure.py index 20859932..a09d4edc 100644 --- a/configure.py +++ b/configure.py @@ -359,7 +359,7 @@ config.libs = [ Object(Matching, "egg/core/eggExpHeap.cpp"), Object(NonMatching, "egg/core/eggFrmHeap.cpp"), Object(NonMatching, "egg/core/eggAssertHeap.cpp"), - Object(NonMatching, "egg/core/eggDisposer.cpp"), + Object(Matching, "egg/core/eggDisposer.cpp"), Object(Matching, "egg/core/eggThread.cpp"), Object(NonMatching, "egg/core/eggUnk.cpp"), Object(NonMatching, "egg/core/eggSystem.cpp"), diff --git a/include/egg/core/eggController.h b/include/egg/core/eggController.h index ce4e48ae..b3b4c024 100644 --- a/include/egg/core/eggController.h +++ b/include/egg/core/eggController.h @@ -13,13 +13,27 @@ namespace EGG { class ControllerRumbleMgr; +class CoreController; // To Be Filled out enum eCoreDevType {}; +typedef void (*ConnectCallback)(int args[]); +typedef class CoreController* (*ControllerFactory)(); + class CoreStatus { public: - /* 0x00 */ u8 field_0x00[0xF0]; + /* 0x00 */ u8 field_0x00[0x0C]; + /* 0x0C */ f32 accel[3]; + /* 0x18 */ u8 field_0x01[0x08]; + /* 0x20 */ f32 dpdRawX; + /* 0x24 */ f32 dpdRawY; + /* 0x28 */ u8 field_0x02[0x36]; + /* 0x58 */ s8 dpdDistance; + /* 0x5C */ s8 unknown; + /* 0x60 */ f32 fsStickButton; + /* 0x60 */ f32 fsStickButton2; + /* 0x64 */ u8 field_0x03[0x88]; public: /* 80498f90 */ void init(); @@ -29,16 +43,21 @@ public: class CoreController { public: // vtable 0x000 | 8056ec50 - /* vt 0x08 | 80064920 */ virtual void setPosParam(f32, f32); - /* vt 0x0C | 8049a940 */ virtual void setHoriParam(f32, f32); - /* vt 0x10 | 8049a930 */ virtual void setDistParam(f32, f32); - /* vt 0x14 | 8049a920 */ virtual void setAccParam(f32, f32); - /* vt 0x18 | 80059820 */ virtual bool isPressed(u32 mask); - /* vt 0x1C | 80059a60 */ virtual bool isAnyPressed(u32 mask); - /* vt 0x20 | 80014e30 */ virtual bool isTriggered(u32 mask); - /* vt 0x24 | 800599e0 */ virtual bool isReleased(); - /* vt 0x28 | 80059840 */ virtual bool isAllPressed(); - /* vt 0x2C | 80059a80 */ virtual bool isNotPressed(); + // TODO all of these have inline implementations and are scattered + // across the binary + /* vt 0x08 | 80064920 */ virtual void setPosParam(f32, f32) {} + /* vt 0x0C | 8049a940 */ virtual void setHoriParam(f32, f32) {} + /* vt 0x10 | 8049a930 */ virtual void setDistParam(f32, f32) {} + /* vt 0x14 | 8049a920 */ virtual void setAccParam(f32, f32) {} + /* vt 0x18 | 80059820 */ virtual bool isPressed(u32 mask) {} + /* vt 0x1C | 80059a60 */ virtual bool isAnyPressed(u32 mask) {} + /* vt 0x20 | 80014e30 */ virtual bool isTriggered(u32 mask) {} + /* vt 0x24 | 800599e0 */ virtual bool isReleased() {} + /* vt 0x28 | 80059840 */ virtual bool isAllPressed() {} + /* vt 0x2C | 80059a80 */ virtual bool isNotPressed() {} + // We know the above are inline because if a class has any non-inline virtual functions, + // then the TU that contains an implementation of said function gets the vtable, + // and we know that eggController.cpp contains the vtable and the functions below /* vt 0x30 | 80499660 */ virtual void beginFrame(void *padStatus); // Really needs to be PADStatus /* vt 0x34 | 80499a60 */ virtual void endFrame(); @@ -73,21 +92,63 @@ public: public: /* 80499050 */ CoreController(); /* 804990b0 */ void sceneReset(); - /* 80499170 */ Vector2f getDpdRawPos(); - /* 80499190 */ s32 getDpdDistance(); + /* 80499170 */ Vector2f getDpdRawPos() const; + /* 80499190 */ s32 getDpdDistance() const; /* 804991a0 */ void startMotor(); /* 804991b0 */ void stopMotor(); - /* 804991c0 */ void createRumberMgr(u8); + /* 804991c0 */ void createRumbleMgr(u8); /* 80499220 */ void startPatternRumble(const char *, int, bool); /* 80499240 */ void stopRumbleMgr(); /* 80499260 */ CoreStatus *getCoreStatus(s32 idx); - /* 8056ebf8 */ void calc_posture_matrix(Matrix34f &mat, bool); - /* 80499ac0 */ f32 getFreeStickX(); - /* 80499ae0 */ f32 getFreeStickY(); + /* 80499270 */ void calc_posture_matrix(Matrix34f &mat, bool); + /* 80499ac0 */ f32 getFreeStickX() const; + /* 80499ae0 */ f32 getFreeStickY() const; +}; + +class CoreControllerMgr { +public: + struct T__Disposer : Disposer { + /* vt 0x08 | 80499b00 */ virtual ~T__Disposer(); + /* 805767ac */ static T__Disposer *sStaticDisposer; + }; + // Disposer Vtable: 8056ec40 + /* 0x0000 */ T__Disposer mDisposer; // for the static T__Disposer +public: + // 0x0010 vtable | 8056ebf8 + /* vt 0x08 | 8049a130 */ virtual void beginFrame(); + /* vt 0x0C | 8049a1e0 */ virtual void endFrame(); + +public: + /* 0x0014 */ TBuffer mControllers; + /* 0x0020 */ u8 field_0x20[0x10a0 - 0x0020]; + /* 0x10A0 */ u32 field_0x10A0; + /* 0x10A4 */ TBuffer mDevTypes; + /* 0x10b0 */ u8 field_0x10B0[0x10e0 - 0x10b0]; + +public: + /* 80499b80 */ static CoreControllerMgr *createInstance(); + /* 80499bd0 */ static void deleteInstance(); + /* 80499be0 */ CoreController *getNthController(s32); + + static void *allocThunk(size_t size); + static int deleteThunk(void *ptr); + + /* 80499cd0 */ static void connectCallback(s32, s32); + /* 80499d10 */ CoreControllerMgr(); + +public: + /* 805767a8 */ static CoreControllerMgr *sInstance; + /* 805767b0 */ static CoreController *(*sCoreControllerFactory)(); + /* 805767b4 */ static ConnectCallback sConnectCallback; + /* 805767b8 */ static bool sUseBuiltinWpadAllocator; + // /* 805767bc */ static sAllocator; // defined in cpp file }; class NullController : public CoreController { public: + NullController() { + unk[92] = 0xfe; + } // idk this has NO effect on anything u8 unk[0x80674c00 - 0x80674b10]; }; @@ -95,14 +156,15 @@ public: class ControllerRumbleUnit { public: // 0x00 vtable | 8056ebb4 - /* vt 0x08 | 8049a8e0 */ virtual ~ControllerRumbleUnit(); + inline ControllerRumbleUnit(): mFlag(0) { init(); } + /* vt 0x08 | 8049a8e0 */ virtual ~ControllerRumbleUnit() {} public: - /* 0x04 */ char *mPattern; - /* 0x08 */ char *mPatternPos; + /* 0x04 */ const char *mPattern; + /* 0x08 */ const char *mPatternPos; /* 0x0C */ s32 mTimer; // guess /* 0x10 */ f32 mRampUp; // guess - /* 0x14 */ f32 mIntesity; // guess + /* 0x14 */ f32 mIntensity; // guess /* 0x18 */ TBitFlag mFlag; /* 0x1C */ nw4r::ut::Node mNode; /* 0x24 */ u32 field_0x24; // could just be part of the node (List) @@ -115,7 +177,7 @@ public: class ControllerRumbleMgr { public: // 0x00 vtable | 8056eba8 - /* vt 0x08 | 8049a8a0 */ virtual ~ControllerRumbleMgr(); + /* vt 0x08 | 8049a8a0 */ virtual ~ControllerRumbleMgr() {} public: /* 0x04 */ nw4r::ut::List mActiveUnitList; @@ -130,48 +192,7 @@ public: /* 8049a7a0 */ void startPattern(const char *pattern, int, bool); /* 8049a7f0 */ ControllerRumbleUnit *getUnitFromList(bool bGrabActive); }; -class CoreControllerMgr { -public: - struct T__Disposer { - Disposer mDisposer; - /* vt 0x08 | 80499b00 */ virtual ~T__Disposer(); - /* 805767ac */ static T__Disposer *sStaticDisposer; - }; - // Disposer Vtable: 8056ec40 - /* 0x0000 */ T__Disposer mDisposer; // for the static T__Disposer -public: - // 0x0010 vtable | 8056ebf8 - /* vt 0x08 | 8049a130 */ void beginFrame(); - /* vt 0x0C | 8049a1e0 */ void endFrame(); -public: - /* 0x0014 */ TBuffer mControllers; - /* 0x0020 */ u8 field_0x20[0x10a4 - 0x0020]; - /* 0x10A4 */ TBuffer mDevTypes; - /* 0x10b0 */ u8 field_0x10B0[0x10e0 - 0x10b0]; - -public: - /* 80499b80 */ static void createInstance(); - /* 80499bd0 */ static void deleteInstance(); - /* 80499cd0 */ void connectCallback(s32, s32); - /* 80499d10 */ CoreControllerMgr(); - -public: - /* 805767a8 */ static CoreControllerMgr *sInstance; - /* 805767b0 */ static CoreController *(*sCoreControllerFactory)(); - /* 805767b4 */ static void (*sConnectCallback)(s32, s32); - /* 805767b8 */ static bool sUnk; - // /* 805767bc */ static sAllocator; // defined in cpp file - - // Other Stuff thats autogen (buffers/sinit/etc) - // /* 8049a950 */ void TBuffer::allocate(int, int); - // /* 8049a9a0 */ void TBuffer::allocate(int, Heap*, int); - // /* 8049aa20 */ void TBuffer::onAllocate(Heap*); - // /* 8049aa30 */ void TBuffer::allocate(int, int); - // /* 8049aa80 */ void TBuffer::allocate(int, Heap*, int); - // /* 8049ab00 */ void TBuffer::onAllocate(Heap*); - // /* 8049ab10 */ void sinit(); // NULL CONTROLLER -}; } // namespace EGG diff --git a/include/egg/core/eggDisposer.h b/include/egg/core/eggDisposer.h index 2bdbff38..0009137d 100644 --- a/include/egg/core/eggDisposer.h +++ b/include/egg/core/eggDisposer.h @@ -10,9 +10,8 @@ namespace EGG { class Heap; class Disposer : private NonCopyable { - friend class Heap; -protected: +public: /* vt 0x08 | 80496890 */ virtual ~Disposer(); /* 80496830 */ Disposer(); diff --git a/include/egg/math/eggMath.h b/include/egg/math/eggMath.h index 5381f635..d608e4a0 100644 --- a/include/egg/math/eggMath.h +++ b/include/egg/math/eggMath.h @@ -2,6 +2,7 @@ #define EGG_MATH_H #include +#include namespace EGG { diff --git a/include/egg/math/eggVector.h b/include/egg/math/eggVector.h index bbad7315..0d8735ee 100644 --- a/include/egg/math/eggVector.h +++ b/include/egg/math/eggVector.h @@ -109,7 +109,9 @@ struct Vector3f : public nw4r::math::VEC3 { }; struct Vector2f : nw4r::math::VEC2 { + inline Vector2f() {} Vector2f(f32 fx, f32 fy) : VEC2(fx, fy) {} + inline ~Vector2f() {} public: /* 805767c0 */ static const Vector2f zero; diff --git a/include/egg/prim/eggBuffer.h b/include/egg/prim/eggBuffer.h index a5312bf5..c757d2af 100644 --- a/include/egg/prim/eggBuffer.h +++ b/include/egg/prim/eggBuffer.h @@ -11,8 +11,10 @@ class TBuffer { public: // vtable 0x00 /* vt 0x08 */ virtual ~TBuffer() { - delete[] mBuffer; - mBuffer = nullptr; + if (mBuffer != nullptr) { + delete[] mBuffer; + mBuffer = nullptr; + } } /* vt 0x0C */ virtual void allocate(int n, int) { mSize = n; @@ -24,7 +26,7 @@ public: if (heap == nullptr) { heap = Heap::sCurrentHeap; } - mBuffer = new (heap, 4) T[n]; + mBuffer = new (heap, 4) T[mSize]; onAllocate(heap); } /* vt 0x14 */ virtual void onAllocate(Heap *) { diff --git a/src/egg/core/eggController.cpp b/src/egg/core/eggController.cpp index 645eca40..fb359817 100644 --- a/src/egg/core/eggController.cpp +++ b/src/egg/core/eggController.cpp @@ -1,14 +1,395 @@ #include "egg/core/eggController.h" +#include "egg/core/eggAllocator.h" +#include "egg/core/eggExpHeap.h" +#include "egg/core/eggSystem.h" +#include "MSL_C/string.h" +#include "rvl/VI.h" +EGG::NullController null_controller; +namespace EGG { -namespace EGG -{ - -void CoreControllerMgr::beginFrame() { +CoreControllerMgr *CoreControllerMgr::sInstance; +CoreControllerMgr::T__Disposer *CoreControllerMgr::T__Disposer::sStaticDisposer; +ControllerFactory CoreControllerMgr::sCoreControllerFactory; +ConnectCallback CoreControllerMgr::sConnectCallback; +// This controls whether EggController registers an allocator within the WPAD driver +bool CoreControllerMgr::sUseBuiltinWpadAllocator; +static Allocator *sWPADAllocator; + +/* 0x80498F90 */ void CoreStatus::init() { + memset(this, 0, sizeof(CoreStatus)); +} + +/* 0x80498FA0 */ u32 CoreStatus::getFSStickButton() const { + f32 button = this->fsStickButton; + u32 result = 0; + // TODO what are these flags and why is this code so weird? + + if (!(-0.25f < button) || !(button < 0.25f)) { + if (button <= -0.5f) { + result = 0; + result |= 0x40000; + } else if (button >= 0.5f) { + result = 0; + result |= 0x80000; + } + } + + button = this->fsStickButton2; + if (!(-0.25f < button) || !(button < 0.25f)) { + if (button <= -0.5f) { + result &= ~0x10000; + result |= 0x20000; + } else if (button >= 0.5f) { + result &= ~0x20000; + result |= 0x10000; + } + } + + return result; +} + +/* 0x80499050 */ CoreController::CoreController() : mDpdPos(), mAccel(), mAccelFlags(), mFlag(0) { + this->mRumbleMgr = nullptr; + this->mButtonHeld = 0; + this->mButtonTriggered = 0; + this->mButtonReleased = 0; + this->sceneReset(); + this->mFlag.makeAllZero(); +} + +/* 0x804990B0 */ void CoreController::sceneReset() { + this->mAccel.set(0.0, 0.0, 0.0); + this->mDpdPos.x = 0.0; + this->mDpdPos.y = 0.0; + this->field_0xf28 = 0; + this->mPostureMatrixPrev.makeIdentity(); + this->mPostureMatrix.makeIdentity(); + this->mMaxAccelFrameTime = 10; + this->mMaxAccelDiff = 0.13; + this->mPrevAccel.set(0.0, 0.0, 0.0); + this->mAccelFlags.makeAllZero(); + this->mAccelFrameTimeZ = 0; + this->mAccelFrameTimeY = 0; + this->mAccelFrameTimeX = 0; + this->mMotorPattern = 0; + this->mMotorFrameDuration = 0; + this->mEnableMotor = false; + this->mMotorPatternLength = 0x20; + this->mMotorPatternPos = 0x1f; + this->stopRumbleMgr(); +} + +/* 0x80499170 */ Vector2f CoreController::getDpdRawPos() const { + return Vector2f(this->coreStatus[0].dpdRawX, this->coreStatus[0].dpdRawY); +} + +/* 0x80499190 */ s32 CoreController::getDpdDistance() const { + return this->coreStatus[0].dpdDistance; +} + +// TODO +extern "C" void fn_803DB1E0(s32 channel, bool arg); + +/* 0x804991A0 */ void CoreController::startMotor() { + fn_803DB1E0(mChannelID, true); +} + +/* 0x804991B0 */ void CoreController::stopMotor() { + fn_803DB1E0(mChannelID, false); +} + +/* 0x804991C0 */ void CoreController::createRumbleMgr(u8 numUnits) { + this->mRumbleMgr = new ControllerRumbleMgr(); + this->mRumbleMgr->createUnit(numUnits, this); +} + +/* 0x80499220 */ void CoreController::startPatternRumble(const char *pattern, int duration, bool bGrabActive) { + if (this->mRumbleMgr) { + this->mRumbleMgr->startPattern(pattern, duration, bGrabActive); + } +} + +/* 0x80499240 */ void CoreController::stopRumbleMgr() { + if (this->mRumbleMgr) { + this->mRumbleMgr->stop(); + } +} + +/* 0x80499260 */ CoreStatus *CoreController::getCoreStatus(s32 idx) { + return &this->coreStatus[idx]; +} + +/* 0x80499270 */ void CoreController::calc_posture_matrix(Matrix34f &mat, bool someBool) { + if (!someBool || this->mAccelFlags.onBit(7)) { + Vector3f vec = Vector3f(-mat(2, 3), -mat(2, 2), -mat(2, 1)); + Vector3f vec3 = vec; + vec.normalise(); + // TODO lots of inlined math + } +} + +/* 0x80499660 */ void CoreController::beginFrame(void *padStatus) {} + +/* 0x80499A60 */ void CoreController::endFrame() { + this->mAccel(0) = this->coreStatus[0].accel[0]; + this->mAccel(1) = this->coreStatus[0].accel[1]; + this->mAccel(2) = this->coreStatus[0].accel[2]; + this->mDpdPos = this->getDpdRawPos(); +} + +/* 0x80499AC0 */ f32 CoreController::getFreeStickX() const { + if (this->coreStatus[0].field_0x00[0x5C] == 0) { + return 0.0; + } + return ((f32 *)(&this->coreStatus[0].field_0x00))[0x18]; +} + +/* 0x80499AE0 */ f32 CoreController::getFreeStickY() const { + if (this->coreStatus[0].field_0x00[0x5C] == 0) { + return 0.0; + } + return ((f32 *)(&this->coreStatus[0].field_0x00))[0x19]; +} + +/* 0x80499B00 */ CoreControllerMgr::T__Disposer::~T__Disposer() { + if (this == CoreControllerMgr::T__Disposer::sStaticDisposer) { + deleteInstance(); + } +} + +/* 0x80499B80 */ CoreControllerMgr *CoreControllerMgr::createInstance() { + if (CoreControllerMgr::sInstance == nullptr) { + CoreControllerMgr *mgr = new CoreControllerMgr(); + CoreControllerMgr::sInstance = mgr; + CoreControllerMgr::T__Disposer::sStaticDisposer = &mgr->mDisposer; + } + return CoreControllerMgr::sInstance; +} + +/* 0x80499BD0 */ void CoreControllerMgr::deleteInstance() { + CoreControllerMgr::sInstance = nullptr; + CoreControllerMgr::T__Disposer::sStaticDisposer = nullptr; +} + +/* 0x80499BE0 */ EGG::CoreController *CoreControllerMgr::getNthController(s32 n) { + return this->mControllers(n); +} + +/* 0x80499C70 */ void *CoreControllerMgr::allocThunk(size_t size) { + return sWPADAllocator->alloc(size); +} + +/* 0x80499C90 */ int CoreControllerMgr::deleteThunk(void *ptr) { + sWPADAllocator->free(ptr); + return 1; +} + +/* 0x80499CD0 */ void CoreControllerMgr::connectCallback(int a1, int a2) { + int args[] = {a1, a2}; + if (sConnectCallback != nullptr) { + (sConnectCallback)(args); + } +} + +extern "C" long lbl_80574EE8; +// TODO headers +extern "C" void fn_803D9400(void *a, void *b); +extern "C" void fn_803F2040(void *a, int b); +extern "C" void fn_803F26B0(int a, void *b); + +/* 0x80499D10 */ CoreControllerMgr::CoreControllerMgr() { + const int idxes[] = {0, 1, 2, 3}; + if (sUseBuiltinWpadAllocator == false) { + Heap *heap = ExpHeap::create(lbl_80574EE8, BaseSystem::mConfigData->mRootHeapMem2, 0); + heap->mName = "EGG::CoreControllerMgr"; + sWPADAllocator = new Allocator(heap, 0x20); + fn_803D9400(allocThunk, deleteThunk); + } + fn_803F2040(field_0x20, 0x40); + beginFrame(); + endFrame(); + VIWaitForRetrace(); + + for (int i = 0; i < 4; i++) { + fn_803F26B0(idxes[i], connectCallback); + } + + // TODO these allocate calls cause the relevant inline buffer functions to be moved + // from the bottom of the TU to after this ctor. How to fix? + mControllers.allocate(4, 0); + for (int i = 0; i < 4; i++) { + if (sCoreControllerFactory != nullptr) { + mControllers(i) = (sCoreControllerFactory)(); + } else { + mControllers(i) = new CoreController(); + } + } + + mDevTypes.allocate(4, 0); + for (int i = 0; i < 4; i++) { + mControllers(i)->mChannelID = idxes[i]; + mDevTypes(i) = (eCoreDevType)0xfd; + } + field_0x10A0 = 0; +} + +/* 0x8049A130 */ void CoreControllerMgr::beginFrame() { for (int i = 0; i < mControllers.getSize(); ++i) { mControllers(i)->beginFrame(NULL); } -} +} +/* 0x8049A1E0 */ void CoreControllerMgr::endFrame() { + for (int i = 0; i < mControllers.mSize; i++) { + mControllers(i)->endFrame(); + // TODO WPADprobe + // Update device type after probe? + } +} + +/* 0x8049A3B0 */ void ControllerRumbleUnit::init() { + this->mPattern = nullptr; + this->mPatternPos = nullptr; + this->mTimer = 0; + this->mIntensity = 0.0; + this->mRampUp = 0.0; + this->mFlag.makeAllZero(); +} + +/* 0x8049A3E0 */ void ControllerRumbleUnit::startPattern(const char *pattern, int duration) { + this->mPattern = pattern; + this->mPatternPos = pattern; + + this->mFlag.value &= 0xef; + this->mFlag.value &= 0xdf; + + if (duration < 0) { + this->mFlag.set(0x10); + } else if (duration > 0) { + this->mFlag.set(0x30); + } + + this->mTimer = duration; + this->mFlag.value = ((this->mFlag.value | 0x01) & 0xfd) | 0x8; +} + +/* 0x8049A440 */ f32 ControllerRumbleUnit::calc() { + f32 result = 0.0f; + if (this->mFlag.onBit(3)) { + if (this->mFlag.onBit(0)) { + char x = *++this->mPatternPos; + if (x == '\0') { + if (this->mFlag.onBit(4)) { + this->mPatternPos = this->mPattern; + } else { + this->mFlag.reset(~0xf7); + } + } else if (x == '*') { + result = 1.0f; + } + + if (this->mFlag.offBit(5)) { + return result; + } + + if (--this->mTimer > 0) { + return result; + } + this->mFlag.reset(~0xf7); + return result; + } else { + f32 intensity = this->mIntensity + this->mRampUp; + this->mIntensity = intensity; + if (intensity >= 1.0f) { + result = 1.0f; + this->mIntensity = 0.0f; + } + + // infinite flag? + if (this->mFlag.onBit(2)) { + return result; + } + + if (--this->mTimer > 0) { + return result; + } + } + this->mFlag.reset(~0xf7); + return result; + } else { + return -1.0f; + } +} + +/* 0x8049A530 */ ControllerRumbleMgr::ControllerRumbleMgr() { + this->mController = nullptr; + // TODO offsetof macro + List_Init(&this->mActiveUnitList, 0x1c); + List_Init(&this->mInactiveUnitList, 0x1c); +} + +/* 0x8049A590 */ void ControllerRumbleMgr::createUnit(u8 numUnits, CoreController *ctrl) { + for (u8 created = 0; created < numUnits; created++) { + ControllerRumbleUnit *unit = new ControllerRumbleUnit(); + List_Append(&this->mInactiveUnitList, unit); + } + this->mController = ctrl; +} + +/* 0x8049A620 */ void ControllerRumbleMgr::stop() { + this->mController->stopMotor(); + while (List_GetSize(&this->mActiveUnitList) != 0) { + ControllerRumbleUnit *unit = static_cast(List_GetNext(&this->mActiveUnitList, nullptr)); + List_Remove(&this->mActiveUnitList, unit); + List_Append(&this->mInactiveUnitList, unit); + } +} + +/* 0x8049A690 */ void ControllerRumbleMgr::calc() { + if (List_GetSize(&this->mActiveUnitList) != 0) { + void *object = List_GetFirst(&this->mActiveUnitList); + f32 acc = 0.0f; + + while (object != nullptr) { + ControllerRumbleUnit *unit = static_cast(object); + f32 x = unit->calc(); + void *nextObject = List_GetNext(&this->mActiveUnitList, object); + if (x < 0.0f) { + List_Remove(&this->mActiveUnitList, object); + List_Append(&this->mInactiveUnitList, object); + } else { + acc += x; + } + object = nextObject; + } + + if (acc >= 1.0f) { + this->mController->startMotor(); + } else { + this->mController->stopMotor(); + } + } +} + +/* 0x8049A7A0 */ void ControllerRumbleMgr::startPattern(const char *pattern, int duration, bool bGrabActive) { + EGG::ControllerRumbleUnit *unit = getUnitFromList(bGrabActive); + if (unit != nullptr) { + unit->startPattern(pattern, duration); + } +} + +/* 0x8049A7F0 */ ControllerRumbleUnit *ControllerRumbleMgr::getUnitFromList(bool bGrabActive) { + void *first = List_GetFirst(&this->mInactiveUnitList); + if (first != nullptr) { + List_Remove(&this->mInactiveUnitList, first); + List_Append(&this->mActiveUnitList, first); + } else if (bGrabActive && (first = List_GetFirst(&this->mActiveUnitList), first != nullptr)) { + List_Remove(&this->mActiveUnitList, first); + List_Append(&this->mActiveUnitList, first); + } + + return static_cast(first); +} } // namespace EGG diff --git a/src/egg/core/eggDisposer.cpp b/src/egg/core/eggDisposer.cpp new file mode 100644 index 00000000..ae6cba5f --- /dev/null +++ b/src/egg/core/eggDisposer.cpp @@ -0,0 +1,19 @@ +#include +#include + +namespace EGG { + +Disposer::Disposer() { + mContainHeap = Heap::findContainHeap(this); + if (mContainHeap) { + mContainHeap->appendDisposer(this); + } +} + +Disposer::~Disposer() { + if (mContainHeap) { + mContainHeap->removeDisposer(this); + } +} + +} // namespace EGG