From 2670db7ca1a6cf5316c490999d5aa832d16d727b Mon Sep 17 00:00:00 2001 From: fgsfds Date: Mon, 21 Aug 2023 00:29:51 +0200 Subject: [PATCH] port: add rstick fields to OSContPad --- include/PR/os_cont.h | 4 ++++ port/src/config.c | 1 + port/src/input.c | 22 ++++++++++++++++------ 3 files changed, 21 insertions(+), 6 deletions(-) diff --git a/include/PR/os_cont.h b/include/PR/os_cont.h index 8f3029b40..5d81bab62 100644 --- a/include/PR/os_cont.h +++ b/include/PR/os_cont.h @@ -61,6 +61,10 @@ typedef struct { s8 stick_x; /* -80 <= stick_x <= 80 */ s8 stick_y; /* -80 <= stick_y <= 80 */ u8 errnum; +#ifndef PLATFORM_N64 + s8 rstick_x; + s8 rstick_y; +#endif } OSContPad; typedef struct { diff --git a/port/src/config.c b/port/src/config.c index 54f429ad4..48009d078 100644 --- a/port/src/config.c +++ b/port/src/config.c @@ -51,6 +51,7 @@ struct configentry { { "Input.RStickScaleX", CONFIG_F32, { .f32val = 1.f } }, { "Input.RStickScaleY", CONFIG_F32, { .f32val = 1.f } }, { "Input.SwapSticks", CONFIG_S32, { .s32val = 1 } }, + { "Input.StickCButtons", CONFIG_S32, { .s32val = 1 } }, { "Input.RumbleScale", CONFIG_F32, { .f32val = 0.333f } }, { "Input.FirstGamepadNum", CONFIG_S32, { .s32val = 0 } }, { "Input.FakeGamepads", CONFIG_S32, { .s32val = 0 } }, diff --git a/port/src/input.c b/port/src/input.c index 379d84d33..a15269e61 100644 --- a/port/src/input.c +++ b/port/src/input.c @@ -16,6 +16,8 @@ #define WHEEL_DN_MASK SDL_BUTTON(VK_MOUSE_WHEEL_DN - VK_MOUSE_BEGIN + 1) static SDL_GameController *pads[INPUT_MAX_CONTROLLERS]; +static s32 rumbleSupported[INPUT_MAX_CONTROLLERS]; + static u32 binds[MAXCONTROLLERS][CK_TOTAL_COUNT][MAX_BINDS]; // [i][CK_][b] = [VK_] static s32 connectedMask = 0; @@ -49,7 +51,7 @@ static s32 deadzone[4] = { DEFAULT_DEADZONE, DEFAULT_DEADZONE_RY, }; -static s32 rumbleSupported[INPUT_MAX_CONTROLLERS]; +static s32 stickCButtons = 1; void inputSetDefaultKeyBinds(void) { @@ -226,6 +228,8 @@ s32 inputInit(void) stickSens[2] = configGetFloat("Input.RStickScaleX", 1.f); stickSens[3] = configGetFloat("Input.RStickScaleY", 1.f); + stickCButtons = configGetInt("Input.StickCButtons", 1); + if (configGetInt("Input.SwapSticks", 1)) { // invert axis map axisMap[0][0] = SDL_CONTROLLER_AXIS_RIGHTX; @@ -305,20 +309,26 @@ s32 inputReadController(s32 idx, OSContPad *npad) rightX = inputAxisScale(rightX, deadzone[axisMap[1][0]], stickSens[axisMap[1][0]]); rightY = inputAxisScale(rightY, deadzone[axisMap[1][1]], stickSens[axisMap[1][1]]); - if (rightX < -0x4000) npad->button |= L_CBUTTONS; - if (rightX > +0x4000) npad->button |= R_CBUTTONS; - if (rightY < -0x4000) npad->button |= U_CBUTTONS; - if (rightY > +0x4000) npad->button |= D_CBUTTONS; + if (stickCButtons) { + if (rightX < -0x4000) npad->button |= L_CBUTTONS; + if (rightX > +0x4000) npad->button |= R_CBUTTONS; + if (rightY < -0x4000) npad->button |= U_CBUTTONS; + if (rightY > +0x4000) npad->button |= D_CBUTTONS; + } if (!npad->stick_x && leftX) { npad->stick_x = leftX / 0x100; } - const s32 stickY = -leftY / 0x100; + s32 stickY = -leftY / 0x100; if (!npad->stick_y && stickY) { npad->stick_y = (stickY == 128) ? 127 : stickY; } + stickY = -rightY / 0x100; + npad->rstick_y = (stickY == 128) ? 127 : stickY; + npad->rstick_x = rightX / 0x100; + return 0; }