From 4e2d2885bc21618f6dd0301c7389164c1bbc1fc1 Mon Sep 17 00:00:00 2001 From: cadmic Date: Fri, 2 Feb 2024 09:25:44 -0800 Subject: [PATCH] Match retail padmgr.c and sys_rumble.c (#1693) * Match retail padmgr.c * Match retail sys_rumble.c * Poke jenkins --- include/macros.h | 3 +-- include/ultra64/motor.h | 2 +- src/code/padmgr.c | 31 ++++++++++++++++++------------- src/code/sys_rumble.c | 2 ++ src/libultra/io/motor.c | 2 +- 5 files changed, 23 insertions(+), 17 deletions(-) diff --git a/include/macros.h b/include/macros.h index 8fa1dc6e40..8820c0769e 100644 --- a/include/macros.h +++ b/include/macros.h @@ -117,14 +117,13 @@ #endif #if OOT_DEBUG - #define LOG(exp, value, format, file, line) \ do { \ LogUtils_LogThreadId(file, line); \ osSyncPrintf(exp " = " format "\n", value); \ } while (0) #else -#define LOG(exp, value, format, file, line) (void)0 +#define LOG(exp, value, format, file, line) (void)(value) #endif #define LOG_STRING(string, file, line) LOG(#string, string, "%s", file, line) diff --git a/include/ultra64/motor.h b/include/ultra64/motor.h index 6f584fefd6..6fa7170183 100644 --- a/include/ultra64/motor.h +++ b/include/ultra64/motor.h @@ -9,7 +9,7 @@ #define osMotorStart(x) __osMotorAccess((x), MOTOR_START) #define osMotorStop(x) __osMotorAccess((x), MOTOR_STOP) -s32 __osMotorAccess(OSPfs* pfs, u32 vibrate); +s32 __osMotorAccess(OSPfs* pfs, s32 vibrate); s32 osMotorInit(OSMesgQueue* ctrlrqueue, OSPfs* pfs, s32 channel); #endif diff --git a/src/code/padmgr.c b/src/code/padmgr.c index 7258f0b7ee..74ca9bd4f6 100644 --- a/src/code/padmgr.c +++ b/src/code/padmgr.c @@ -32,7 +32,7 @@ #include "terminal.h" #define PADMGR_LOG(controllerNum, msg) \ - if (1) { \ + if (OOT_DEBUG) { \ PRINTF(VT_FGCOL(YELLOW)); \ /* padmgr: Controller %d: %s */ \ PRINTF("padmgr: %dコン: %s\n", (controllerNum) + 1, (msg)); \ @@ -66,7 +66,11 @@ s32 gPadMgrLogSeverity = LOG_SEVERITY_CRITICAL; * @see PadMgr_ReleaseSerialEventQueue */ OSMesgQueue* PadMgr_AcquireSerialEventQueue(PadMgr* padMgr) { - OSMesgQueue* serialEventQueue = NULL; + OSMesgQueue* serialEventQueue; + +#if OOT_DEBUG + serialEventQueue = NULL; +#endif if (gPadMgrLogSeverity >= LOG_SEVERITY_VERBOSE) { // "serialMsgQ Waiting for lock" @@ -135,13 +139,10 @@ void PadMgr_UnlockPadData(PadMgr* padMgr) { void PadMgr_UpdateRumble(PadMgr* padMgr) { static u32 sRumbleErrorCount = 0; // original name: "errcnt" static u32 sRumbleUpdateCounter; - s32 motorStart = MOTOR_START; // required for matching? - s32 triedRumbleComm; - OSMesgQueue* serialEventQueue = PadMgr_AcquireSerialEventQueue(padMgr); - s32 ret; s32 i; - - triedRumbleComm = false; + s32 ret; + OSMesgQueue* serialEventQueue = PadMgr_AcquireSerialEventQueue(padMgr); + s32 triedRumbleComm = false; for (i = 0; i < MAXCONTROLLERS; i++) { if (padMgr->ctrlrIsConnected[i]) { @@ -153,9 +154,7 @@ void PadMgr_UpdateRumble(PadMgr* padMgr) { // "Rumble pack brrr" PADMGR_LOG(i, "振動パック ぶるぶるぶるぶる"); - // This should be the osMotorStart macro, however the temporary variable motorStart is - // currently required for matching - if (__osMotorAccess(&padMgr->rumblePfs[i], motorStart) != 0) { + if (osMotorStart(&padMgr->rumblePfs[i]) != 0) { padMgr->pakType[i] = CONT_PAK_NONE; // "A communication error has occurred with the vibration pack" @@ -186,7 +185,7 @@ void PadMgr_UpdateRumble(PadMgr* padMgr) { } } else { if (padMgr->pakType[i] != CONT_PAK_NONE) { - if (padMgr->pakType[i] == CONT_PAK_RUMBLE) { + if (padMgr->pakType[i] == CONT_PAK_RUMBLE || !OOT_DEBUG) { // "It seems that a vibration pack was pulled out" PADMGR_LOG(i, "振動パックが抜かれたようです"); padMgr->pakType[i] = CONT_PAK_NONE; @@ -352,9 +351,9 @@ void PadMgr_UpdateInputs(PadMgr* padMgr) { } void PadMgr_HandleRetrace(PadMgr* padMgr) { - s32 i; OSMesgQueue* serialEventQueue = PadMgr_AcquireSerialEventQueue(padMgr); u32 mask; + s32 i; // Begin reading controller data osContStartReadData(serialEventQueue); @@ -368,6 +367,12 @@ void PadMgr_HandleRetrace(PadMgr* padMgr) { osRecvMesg(serialEventQueue, NULL, OS_MESG_BLOCK); osContGetReadData(padMgr->pads); +#if !OOT_DEBUG + // Clear controllers 2 and 4 + bzero(&padMgr->pads[1], sizeof(OSContPad)); + bzero(&padMgr->pads[3], sizeof(OSContPad)); +#endif + // If resetting, clear all controllers if (padMgr->isResetting) { bzero(padMgr->pads, sizeof(padMgr->pads)); diff --git a/src/code/sys_rumble.c b/src/code/sys_rumble.c index 8991f26cbe..fdb204af57 100644 --- a/src/code/sys_rumble.c +++ b/src/code/sys_rumble.c @@ -147,5 +147,7 @@ void RumbleMgr_Init(RumbleMgr* rumbleMgr) { } void RumbleMgr_Destroy(RumbleMgr* rumbleMgr) { +#if OOT_DEBUG bzero(rumbleMgr, sizeof(RumbleMgr)); +#endif } diff --git a/src/libultra/io/motor.c b/src/libultra/io/motor.c index b63dd38f51..252e93875a 100644 --- a/src/libultra/io/motor.c +++ b/src/libultra/io/motor.c @@ -4,7 +4,7 @@ OSPifRam __MotorDataBuf[MAXCONTROLLERS]; -s32 __osMotorAccess(OSPfs* pfs, u32 vibrate) { +s32 __osMotorAccess(OSPfs* pfs, s32 vibrate) { s32 i; s32 ret; u8* ptr = (u8*)&__MotorDataBuf[pfs->channel];