diff options
| author | Tharo <17233964+Thar0@users.noreply.github.com> | 2022-09-03 01:52:13 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-09-03 02:52:13 +0200 |
| commit | 6b77ddba5ae0941c10c58260c44270dfcb88e182 (patch) | |
| tree | 824d27ec4e9d60eca657b2739c8ddf7fab17a90d /include | |
| parent | c0cf83a814d13a9a07a2ca260203134fc4c5b735 (diff) | |
More documentation for padmgr.c (#1336)
* More documentation for padmgr.c
* Update comments
* Further suggested changes
* Suggested changes
* LOG_SEVERITY_INFO -> LOG_SEVERITY_CRITICAL
* Adjust PadMgr_RequestPadData comment
* Avoid array notation for args, adjust comment, rename the FaultMgr padInput field to inputs to better reflect it's an array
Diffstat (limited to 'include')
| -rw-r--r-- | include/fault.h | 10 | ||||
| -rw-r--r-- | include/functions.h | 15 | ||||
| -rw-r--r-- | include/irqmgr.h | 3 | ||||
| -rw-r--r-- | include/padmgr.h | 63 | ||||
| -rw-r--r-- | include/variables.h | 3 | ||||
| -rw-r--r-- | include/z64.h | 2 |
6 files changed, 57 insertions, 39 deletions
diff --git a/include/fault.h b/include/fault.h index 642d581d8..511d3516f 100644 --- a/include/fault.h +++ b/include/fault.h @@ -1,6 +1,7 @@ #ifndef FAULT_H #define FAULT_H +#include "ultra64.h" #include "padmgr.h" // These are the same as the 3-bit ansi color codes @@ -69,7 +70,7 @@ void FaultDrawer_DrawText(s32 x, s32 y, const char* fmt, ...); typedef struct FaultMgr { /* 0x000 */ OSThread thread; - /* 0x1B0 */ u8 unk_1B0[0x600]; + /* 0x1B0 */ char unk_1B0[0x600]; // probably an unused internal thread stack for `Fault_ClientRunTask`/`clientThreadSp` /* 0x7B0 */ OSMesgQueue queue; /* 0x7C8 */ OSMesg msg; /* 0x7CC */ u8 exit; @@ -77,12 +78,11 @@ typedef struct FaultMgr { /* 0x7CE */ u8 faultHandlerEnabled; /* 0x7CF */ u8 autoScroll; /* 0x7D0 */ OSThread* faultedThread; - /* 0x7D4 */ void (*padCallback)(Input*); + /* 0x7D4 */ void (*padCallback)(Input* inputs); /* 0x7D8 */ FaultClient* clients; /* 0x7DC */ FaultAddrConvClient* addrConvClients; - /* 0x7E0 */ u8 unk_7E0[4]; - /* 0x7E4 */ Input padInput; - /* 0x7FC */ u16 colors[36]; + /* 0x7E0 */ char unk_7E0[0x4]; + /* 0x7E4 */ Input inputs[MAXCONTROLLERS]; /* 0x844 */ void* fb; /* 0x848 */ void* clientThreadSp; } FaultMgr; // size = 0x850 diff --git a/include/functions.h b/include/functions.h index e7ba5818c..8df78a215 100644 --- a/include/functions.h +++ b/include/functions.h @@ -1574,21 +1574,6 @@ void ListAlloc_Free(ListAlloc* this, void* data); void ListAlloc_FreeAll(ListAlloc* this); void Main_LogSystemHeap(void); void Main(void* arg); -OSMesgQueue* PadMgr_LockSerialMesgQueue(PadMgr* padMgr); -void PadMgr_UnlockSerialMesgQueue(PadMgr* padMgr, OSMesgQueue* serialEventQueue); -void PadMgr_LockPadData(PadMgr* padMgr); -void PadMgr_UnlockPadData(PadMgr* padMgr); -void PadMgr_RumbleControl(PadMgr* padMgr); -void PadMgr_RumbleStop(PadMgr* padMgr); -void PadMgr_RumbleReset(PadMgr* padMgr); -void PadMgr_RumbleSet(PadMgr* padMgr, u8* ctrlrRumbles); -void PadMgr_ProcessInputs(PadMgr* padMgr); -void PadMgr_HandleRetraceMsg(PadMgr* padMgr); -void PadMgr_HandlePreNMI(PadMgr* padMgr); -// This function must remain commented out, because it is called incorrectly in -// fault.c (actual bug in game), and the compiler notices and won't compile it -// void PadMgr_RequestPadData(PadMgr* padmgr, Input* inputs, s32 mode); -void PadMgr_Init(PadMgr* padMgr, OSMesgQueue* serialEventQueue, IrqMgr* irqMgr, OSId id, OSPri priority, void* stack); void SpeedMeter_InitImpl(SpeedMeter* this, u32 arg1, u32 y); void SpeedMeter_Init(SpeedMeter* this); void SpeedMeter_Destroy(SpeedMeter* this); diff --git a/include/irqmgr.h b/include/irqmgr.h index e1b3befbc..69a749a49 100644 --- a/include/irqmgr.h +++ b/include/irqmgr.h @@ -43,4 +43,7 @@ void IrqMgr_Init(IrqMgr* irqMgr, void* stack, OSPri pri, u8 retraceCount); void IrqMgr_AddClient(IrqMgr* irqMgr, IrqMgrClient* client, OSMesgQueue* msgQueue); void IrqMgr_RemoveClient(IrqMgr* irqMgr, IrqMgrClient* client); +extern vu32 gIrqMgrResetStatus; +extern volatile OSTime gIrqMgrRetraceTime; + #endif diff --git a/include/padmgr.h b/include/padmgr.h index 52f6f08ee..bddb136eb 100644 --- a/include/padmgr.h +++ b/include/padmgr.h @@ -1,8 +1,15 @@ #ifndef PADMGR_H #define PADMGR_H +#include "ultra64.h" #include "irqmgr.h" +typedef enum { + CONT_PAK_NONE, + CONT_PAK_RUMBLE, + CONT_PAK_OTHER +} ControllerPakType; + typedef struct { /* 0x00 */ OSContPad cur; /* 0x06 */ OSContPad prev; @@ -11,9 +18,9 @@ typedef struct { } Input; // size = 0x18 typedef struct PadMgr { - /* 0x0000 */ OSContStatus padStatus[4]; - /* 0x0010 */ OSMesg serialLockMsgBuf[1]; - /* 0x0014 */ OSMesg lockMsgBuf[1]; + /* 0x0000 */ OSContStatus padStatus[MAXCONTROLLERS]; + /* 0x0010 */ OSMesg serialMsg; + /* 0x0014 */ OSMesg lockMsg; /* 0x0018 */ OSMesg interruptMsgBuf[4]; /* 0x0028 */ OSMesgQueue serialLockQueue; /* 0x0040 */ OSMesgQueue lockQueue; @@ -21,20 +28,46 @@ typedef struct PadMgr { /* 0x0070 */ IrqMgrClient irqClient; /* 0x0078 */ IrqMgr* irqMgr; /* 0x0080 */ OSThread thread; - /* 0x0230 */ Input inputs[4]; - /* 0x0290 */ OSContPad pads[4]; + /* 0x0230 */ Input inputs[MAXCONTROLLERS]; + /* 0x0290 */ OSContPad pads[MAXCONTROLLERS]; /* 0x02A8 */ vu8 validCtrlrsMask; /* 0x02A9 */ u8 nControllers; - /* 0x02AA */ u8 ctrlrIsConnected[4]; // "Key_switch" originally - /* 0x02AE */ u8 pakType[4]; // 1 if rumble pack, 2 if mempak? - /* 0x02B2 */ vu8 rumbleEnable[4]; - /* 0x02B6 */ u8 rumbleCounter[4]; // not clear exact meaning - /* 0x02BC */ OSPfs pfs[4]; - /* 0x045C */ vu8 rumbleOffFrames; - /* 0x045D */ vu8 rumbleOnFrames; - /* 0x045E */ u8 preNMIShutdown; - /* 0x0460 */ void (*retraceCallback)(struct PadMgr* padmgr, s32 unk464); - /* 0x0464 */ u32 retraceCallbackValue; + /* 0x02AA */ u8 ctrlrIsConnected[MAXCONTROLLERS]; + /* 0x02AE */ u8 pakType[MAXCONTROLLERS]; + /* 0x02B2 */ vu8 rumbleEnable[MAXCONTROLLERS]; + /* 0x02B6 */ u8 rumbleTimer[MAXCONTROLLERS]; + /* 0x02BC */ OSPfs rumblePfs[MAXCONTROLLERS]; + /* 0x045C */ vu8 rumbleOffTimer; // amount of VI retraces to not rumble for, takes priority over rumbleOnTimer + /* 0x045D */ vu8 rumbleOnTimer; // amount of VI retraces to rumble for + /* 0x045E */ u8 isResetting; + /* 0x0460 */ void (*retraceCallback)(struct PadMgr* padMgr, s32 arg); + /* 0x0464 */ s32 retraceCallbackValue; } PadMgr; // size = 0x468 +extern PadMgr gPadMgr; + +// Initialization + +void PadMgr_Init(PadMgr* padMgr, OSMesgQueue* serialEventQueue, IrqMgr* irqMgr, OSId id, OSPri priority, void* stack); + +// Fetching inputs + +// This function cannot be prototyped here without AVOID_UB because it is called incorrectly in fault.c (see bug in +// `Fault_PadCallback`) +#ifdef AVOID_UB +void PadMgr_RequestPadData(PadMgr* padmgr, Input* inputs, s32 gameRequest); +#endif + +// For internal use by Controller Pak systems + +OSMesgQueue* PadMgr_AcquireSerialEventQueue(PadMgr* padMgr); +void PadMgr_ReleaseSerialEventQueue(PadMgr* padMgr, OSMesgQueue* serialEventQueue); + +// Rumble + +void PadMgr_RumbleStop(PadMgr* padMgr); +void PadMgr_RumbleReset(PadMgr* padMgr); +void PadMgr_RumbleSetSingle(PadMgr* padMgr, u32 port, u32 rumble); +void PadMgr_RumbleSet(PadMgr* padMgr, u8* enable); + #endif diff --git a/include/variables.h b/include/variables.h index 79b17f5ce..a5808eb50 100644 --- a/include/variables.h +++ b/include/variables.h @@ -110,8 +110,6 @@ extern s32 gScreenHeight; extern Mtx gMtxClear; extern MtxF gMtxFClear; extern u32 gIsCtrlr2Valid; -extern vu32 gIrqMgrResetStatus; -extern volatile OSTime gIrqMgrRetraceTime; extern s16* gWaveSamples[9]; extern f32 gBendPitchOneOctaveFrequencies[256]; extern f32 gBendPitchTwoSemitonesFrequencies[256]; @@ -193,7 +191,6 @@ extern s32 gTrnsnUnkState; extern Color_RGBA8_u32 D_801614B0; extern PreNmiBuff* gAppNmiBufferPtr; extern Scheduler gScheduler; -extern PadMgr gPadMgr; extern u32 gSegments[NUM_SEGMENTS]; extern volatile OSTime D_8016A520; extern volatile OSTime D_8016A528; diff --git a/include/z64.h b/include/z64.h index 6fb89528a..7128cd1b2 100644 --- a/include/z64.h +++ b/include/z64.h @@ -1060,7 +1060,7 @@ typedef struct GameState { /* 0x08 */ GameStateFunc destroy; // "cleanup" /* 0x0C */ GameStateFunc init; /* 0x10 */ u32 size; - /* 0x14 */ Input input[4]; + /* 0x14 */ Input input[MAXCONTROLLERS]; /* 0x74 */ TwoHeadArena tha; /* 0x84 */ GameAlloc alloc; /* 0x98 */ u32 running; |
