From c890838b24262200f1092f3e4bf175435ddcd749 Mon Sep 17 00:00:00 2001 From: Arceveti Date: Fri, 22 Sep 2023 14:25:20 -0700 Subject: [PATCH] Fix controllers on ports other than 0 --- src/game/game_init.c | 6 ++-- src/game/gamecube_controller.c | 61 ++++++++++++++++------------------ 2 files changed, 32 insertions(+), 35 deletions(-) diff --git a/src/game/game_init.c b/src/game/game_init.c index 07600f24..fce97699 100644 --- a/src/game/game_init.c +++ b/src/game/game_init.c @@ -582,7 +582,7 @@ void read_controller_inputs(s32 threadID) { if (threadID == THREAD_5_GAME_LOOP) { osRecvMesg(&gSIEventMesgQueue, &gMainReceivedMesg, OS_MESG_BLOCK); } - osContGetReadDataEx(&gControllerPads[0]); + osContGetReadDataEx(gControllerPads); #if ENABLE_RUMBLE release_rumble_pak_control(); #endif @@ -617,8 +617,8 @@ void read_controller_inputs(s32 threadID) { controller->buttonDown = controllerData->button; adjust_analog_stick(controller); } else { // otherwise, if the controllerData is NULL, 0 out all of the inputs. - controller->rawStickX = 0x0000; - controller->rawStickY = 0x0000; + controller->rawStickX = 0; + controller->rawStickY = 0; controller->buttonPressed = 0x0000; controller->buttonReleased = 0x0000; controller->buttonDown = 0x0000; diff --git a/src/game/gamecube_controller.c b/src/game/gamecube_controller.c index 20f5afb1..32295e61 100644 --- a/src/game/gamecube_controller.c +++ b/src/game/gamecube_controller.c @@ -220,46 +220,43 @@ void osContGetReadDataEx(OSContPadEx* data) { s32 stick_x, stick_y, c_stick_x, c_stick_y; readformatgcn = *(__OSContGCNShortPollFormat*)ptr; data->errno = CHNL_ERR(readformatgcn); - if (data->errno != 0) { + if (data->errno == 0) { + if (!gGamecubeControllerCenters[i].initialized) { + gGamecubeControllerCenters[i].initialized = TRUE; + gGamecubeControllerCenters[i].stick_x = readformatgcn.stick_x; + gGamecubeControllerCenters[i].stick_y = readformatgcn.stick_y; + gGamecubeControllerCenters[i].c_stick_x = readformatgcn.c_stick_x; + gGamecubeControllerCenters[i].c_stick_y = readformatgcn.c_stick_y; + } + + stick_x = CLAMP_S8(((s32)readformatgcn.stick_x) - gGamecubeControllerCenters[i].stick_x); + stick_y = CLAMP_S8(((s32)readformatgcn.stick_y) - gGamecubeControllerCenters[i].stick_y); + data->stick_x = stick_x; + data->stick_y = stick_y; + c_stick_x = CLAMP_S8(((s32)readformatgcn.c_stick_x) - gGamecubeControllerCenters[i].c_stick_x); + c_stick_y = CLAMP_S8(((s32)readformatgcn.c_stick_y) - gGamecubeControllerCenters[i].c_stick_y); + data->c_stick_x = c_stick_x; + data->c_stick_y = c_stick_y; + data->button = __osTranslateGCNButtons(readformatgcn.button, c_stick_x, c_stick_y); + data->l_trig = readformatgcn.l_trig; + data->r_trig = readformatgcn.r_trig; + } else { gGamecubeControllerCenters[i].initialized = FALSE; - continue; } - - if (!gGamecubeControllerCenters[i].initialized) { - gGamecubeControllerCenters[i].initialized = TRUE; - gGamecubeControllerCenters[i].stick_x = readformatgcn.stick_x; - gGamecubeControllerCenters[i].stick_y = readformatgcn.stick_y; - gGamecubeControllerCenters[i].c_stick_x = readformatgcn.c_stick_x; - gGamecubeControllerCenters[i].c_stick_y = readformatgcn.c_stick_y; - } - - stick_x = CLAMP_S8(((s32)readformatgcn.stick_x) - gGamecubeControllerCenters[i].stick_x); - stick_y = CLAMP_S8(((s32)readformatgcn.stick_y) - gGamecubeControllerCenters[i].stick_y); - data->stick_x = stick_x; - data->stick_y = stick_y; - c_stick_x = CLAMP_S8(((s32)readformatgcn.c_stick_x) - gGamecubeControllerCenters[i].c_stick_x); - c_stick_y = CLAMP_S8(((s32)readformatgcn.c_stick_y) - gGamecubeControllerCenters[i].c_stick_y); - data->c_stick_x = c_stick_x; - data->c_stick_y = c_stick_y; - data->button = __osTranslateGCNButtons(readformatgcn.button, c_stick_x, c_stick_y); - data->l_trig = readformatgcn.l_trig; - data->r_trig = readformatgcn.r_trig; ptr += sizeof(__OSContGCNShortPollFormat); } else { readformat = *(__OSContReadFormat*)ptr; data->errno = CHNL_ERR(readformat); - if (data->errno != 0) { - continue; + if (data->errno == 0) { + data->stick_x = readformat.stick_x; + data->stick_y = readformat.stick_y; + data->button = readformat.button; + data->c_stick_x = 0; + data->c_stick_y = 0; + data->l_trig = 0; + data->r_trig = 0; } - - data->stick_x = readformat.stick_x; - data->stick_y = readformat.stick_y; - data->button = readformat.button; - data->c_stick_x = 0; - data->c_stick_y = 0; - data->l_trig = 0; - data->r_trig = 0; ptr += sizeof(__OSContReadFormat); } }