From 688f7513092a13eb0dec4dd960f0ddcdb34639d7 Mon Sep 17 00:00:00 2001 From: Vague Rant Date: Sun, 1 Oct 2023 18:33:39 +1100 Subject: [PATCH] Add shoulder button swap combo (L+R+D-pad Down) --- kernel/BT.c | 32 ++++++++++++++----- .../source/ppc/PADReadGC/source/PADReadGC.c | 12 ++++--- 2 files changed, 31 insertions(+), 13 deletions(-) diff --git a/kernel/BT.c b/kernel/BT.c index 0f4e80ff1..e3e96ccce 100644 --- a/kernel/BT.c +++ b/kernel/BT.c @@ -78,7 +78,8 @@ static const u8 LEDState[] = { 0x10, 0x20, 0x40, 0x80, 0xF0 }; #define C_NSWAP2 (1<<6) #define C_NSWAP3 (1<<7) #define C_ISWAP (1<<8) -#define C_TestSWAP (1<<9) +#define C_ZSWAP (1<<9) +#define C_TestSWAP (1<<10) static const s8 DEADZONE = 0x1A; @@ -119,7 +120,15 @@ static s32 BTHandleData(void *arg,void *buffer,u16 len) if((!(prevButton & BT_BUTTON_SELECT)) && BTPad[chan].button & BT_BUTTON_SELECT) { //dbgprintf("Using %s control scheme\n", (stat->controller & C_SWAP) ? "orginal" : "swapped"); - stat->controller = (stat->controller & C_SWAP) ? (stat->controller & ~C_SWAP) : (stat->controller | C_SWAP); + stat->controller ^= C_SWAP; + sync_after_write(arg, sizeof(struct BTPadStat)); + sync_before_read(arg, sizeof(struct BTPadStat)); + } + if((prevButton & BT_TRIGGER_L) && (prevButton & BT_TRIGGER_R) && + (BTPad[chan].button & BT_TRIGGER_L) && (BTPad[chan].button & BT_TRIGGER_R) && + (BTPad[chan].button & BT_DPAD_DOWN)) + { + stat->controller ^= C_ZSWAP; sync_after_write(arg, sizeof(struct BTPadStat)); sync_before_read(arg, sizeof(struct BTPadStat)); } @@ -167,14 +176,21 @@ static s32 BTHandleData(void *arg,void *buffer,u16 len) if((!(prevButton & BT_BUTTON_SELECT)) && BTPad[chan].button & BT_BUTTON_SELECT) { //dbgprintf("Using %s control scheme\n", (stat->controller & C_SWAP) ? "orginal" : "swapped"); - stat->controller = (stat->controller & C_SWAP) ? (stat->controller & ~C_SWAP) : (stat->controller | C_SWAP); + stat->controller ^= C_SWAP; + sync_after_write(arg, sizeof(struct BTPadStat)); + sync_before_read(arg, sizeof(struct BTPadStat)); + } + if((prevButton & BT_TRIGGER_L) && (prevButton & BT_TRIGGER_R) && (BTPad[chan].button & BT_TRIGGER_L) && (BTPad[chan].button & BT_TRIGGER_R) + && (BTPad[chan].button & BT_DPAD_DOWN)) + { + stat->controller ^= C_ZSWAP; sync_after_write(arg, sizeof(struct BTPadStat)); sync_before_read(arg, sizeof(struct BTPadStat)); } if((!(prevButton & (WM_BUTTON_MINUS << 4))) && BTPad[chan].button & (WM_BUTTON_MINUS << 4)) //wiimote button minus pressed leading edge { //dbgprintf("%s rumble for wiimote\n", (stat->controller & C_RUMBLE_WM) ? "Disabling" : "Enabling"); - stat->controller = (stat->controller & C_RUMBLE_WM) ? (stat->controller & ~C_RUMBLE_WM) : (stat->controller | C_RUMBLE_WM); + stat->controller ^= C_RUMBLE_WM; sync_after_write(arg, sizeof(struct BTPadStat)); sync_before_read(arg, sizeof(struct BTPadStat)); } @@ -274,15 +290,15 @@ static s32 BTHandleData(void *arg,void *buffer,u16 len) break; case NUN_BUTTON_C: if(!(prevButton & NUN_BUTTON_C)) - stat->controller = (stat->controller & C_SWAP) ? (stat->controller & ~C_SWAP) : (stat->controller | C_SWAP); + stat->controller ^= C_SWAP; break; case NUN_BUTTON_Z: if(!(prevButton & NUN_BUTTON_Z)) - stat->controller = (stat->controller & C_ISWAP) ? (stat->controller & ~C_ISWAP) : (stat->controller | C_ISWAP); + stat->controller ^= C_ISWAP; break; case WM_BUTTON_A: if(!(prevButton & WM_BUTTON_A)) - stat->controller = (stat->controller & C_TestSWAP) ? (stat->controller & ~C_TestSWAP) : (stat->controller | C_TestSWAP); + stat->controller ^= C_TestSWAP; break; default: { } } @@ -291,7 +307,7 @@ static s32 BTHandleData(void *arg,void *buffer,u16 len) } if((!(prevButton & WM_BUTTON_TWO)) && BTPad[chan].button & WM_BUTTON_TWO) //wiimote button TWO pressed leading edge { - stat->controller = stat->controller & ~(C_NSWAP1 | C_NSWAP2 | C_NSWAP3 | C_SWAP | C_ISWAP | C_TestSWAP); + stat->controller &= ~(C_NSWAP1 | C_NSWAP2 | C_NSWAP3 | C_SWAP | C_ISWAP | C_ZSWAP | C_TestSWAP); sync_after_write(arg, sizeof(struct BTPadStat)); sync_before_read(arg, sizeof(struct BTPadStat)); } diff --git a/loader/source/ppc/PADReadGC/source/PADReadGC.c b/loader/source/ppc/PADReadGC/source/PADReadGC.c index 4157767ee..095a8fe67 100644 --- a/loader/source/ppc/PADReadGC/source/PADReadGC.c +++ b/loader/source/ppc/PADReadGC/source/PADReadGC.c @@ -64,6 +64,7 @@ const s8 DEADZONE = 0x1A; #define C_NSWAP2 (1<<6) #define C_NSWAP3 (1<<7) #define C_ISWAP (1<<8) +#define C_ZSWAP (1<<9) #define ALIGN32(x) (((u32)x) & (~31)) @@ -830,9 +831,10 @@ u32 PADRead(u32 calledByGame) } else if(BTPad[chan].used & C_CCP) //digital triggers { - if(BTPad[chan].button & BT_TRIGGER_ZL) + u8 swapTriggers = (BTPad[chan].used & C_ZSWAP) != 0; + if(BTPad[chan].button & (swapTriggers ? BT_TRIGGER_L : BT_TRIGGER_ZL)) { - if(BTPad[chan].button & BT_TRIGGER_L) + if(BTPad[chan].button & (swapTriggers ? BT_TRIGGER_ZL : BT_TRIGGER_L)) Pad[chan].triggerLeft = 0x7F; else { @@ -843,9 +845,9 @@ u32 PADRead(u32 calledByGame) else Pad[chan].triggerLeft = 0; - if(BTPad[chan].button & BT_TRIGGER_ZR) + if(BTPad[chan].button & (swapTriggers ? BT_TRIGGER_R : BT_TRIGGER_ZR)) { - if(BTPad[chan].button & BT_TRIGGER_L) + if(BTPad[chan].button & (swapTriggers ? BT_TRIGGER_ZL : BT_TRIGGER_L)) Pad[chan].triggerRight = 0x7F; else { @@ -856,7 +858,7 @@ u32 PADRead(u32 calledByGame) else Pad[chan].triggerRight = 0; - if(BTPad[chan].button & BT_TRIGGER_R) + if(BTPad[chan].button & (swapTriggers ? BT_TRIGGER_ZR : BT_TRIGGER_R)) button |= PAD_TRIGGER_Z; }