Skip to content

Commit

Permalink
Add shoulder button swap combo (L+R+D-pad Down)
Browse files Browse the repository at this point in the history
  • Loading branch information
vaguerant committed Oct 1, 2023
1 parent 8b14080 commit 688f751
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 13 deletions.
32 changes: 24 additions & 8 deletions kernel/BT.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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));
}
Expand Down Expand Up @@ -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));
}
Expand Down Expand Up @@ -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: { }
}
Expand All @@ -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));
}
Expand Down
12 changes: 7 additions & 5 deletions loader/source/ppc/PADReadGC/source/PADReadGC.c
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand Down Expand Up @@ -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
{
Expand All @@ -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
{
Expand All @@ -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;
}

Expand Down

0 comments on commit 688f751

Please sign in to comment.