From 2193938266bf41a4df104bf47bea94ce2f61568f Mon Sep 17 00:00:00 2001 From: Jasmine Iwanek Date: Sun, 5 Oct 2025 23:49:16 -0400 Subject: [PATCH] A little more progress towards dual gameport support (#6284) --- src/config.c | 30 ++++--- src/game/joystick_ch_flightstick_pro.c | 43 +++++---- src/game/joystick_standard.c | 120 ++++++++++++++----------- src/game/joystick_sw_pad.c | 24 +++-- src/game/joystick_tm_fcs.c | 51 ++++++----- 5 files changed, 153 insertions(+), 115 deletions(-) diff --git a/src/config.c b/src/config.c index 102f9de97..a06d9e8b4 100644 --- a/src/config.c +++ b/src/config.c @@ -639,25 +639,27 @@ load_input_devices(void) } else joystick_type[joy_insn] = JS_TYPE_NONE; + uint8_t gp = 0; + for (int js = 0; js < joystick_get_max_joysticks(joystick_type[joy_insn]); js++) { sprintf(temp, "joystick_%i_nr", js); - joystick_state[0][js].plat_joystick_nr = ini_section_get_int(cat, temp, 0); + joystick_state[gp][js].plat_joystick_nr = ini_section_get_int(cat, temp, 0); - if (joystick_state[0][js].plat_joystick_nr) { + if (joystick_state[gp][js].plat_joystick_nr) { for (int axis_nr = 0; axis_nr < joystick_get_axis_count(joystick_type[joy_insn]); axis_nr++) { sprintf(temp, "joystick_%i_axis_%i", js, axis_nr); - joystick_state[0][js].axis_mapping[axis_nr] = ini_section_get_int(cat, temp, axis_nr); + joystick_state[gp][js].axis_mapping[axis_nr] = ini_section_get_int(cat, temp, axis_nr); } for (int button_nr = 0; button_nr < joystick_get_button_count(joystick_type[joy_insn]); button_nr++) { sprintf(temp, "joystick_%i_button_%i", js, button_nr); - joystick_state[0][js].button_mapping[button_nr] = ini_section_get_int(cat, temp, button_nr); + joystick_state[gp][js].button_mapping[button_nr] = ini_section_get_int(cat, temp, button_nr); } for (int pov_nr = 0; pov_nr < joystick_get_pov_count(joystick_type[joy_insn]); pov_nr++) { sprintf(temp, "joystick_%i_pov_%i", js, pov_nr); p = ini_section_get_string(cat, temp, "0, 0"); - joystick_state[0][js].pov_mapping[pov_nr][0] = joystick_state[0][js].pov_mapping[pov_nr][1] = 0; - sscanf(p, "%i, %i", &joystick_state[0][js].pov_mapping[pov_nr][0], - &joystick_state[0][js].pov_mapping[pov_nr][1]); + joystick_state[gp][js].pov_mapping[pov_nr][0] = joystick_state[gp][js].pov_mapping[pov_nr][1] = 0; + sscanf(p, "%i, %i", &joystick_state[gp][js].pov_mapping[pov_nr][0], + &joystick_state[gp][js].pov_mapping[pov_nr][1]); } } } @@ -2728,25 +2730,27 @@ save_input_devices(void) } } } else { + uint8_t gp = 0; + ini_section_set_string(cat, "joystick_type", joystick_get_internal_name(joystick_type[joy_insn])); for (int js = 0; js < joystick_get_max_joysticks(joystick_type[joy_insn]); js++) { sprintf(tmp2, "joystick_%i_nr", js); - ini_section_set_int(cat, tmp2, joystick_state[0][js].plat_joystick_nr); + ini_section_set_int(cat, tmp2, joystick_state[gp][js].plat_joystick_nr); - if (joystick_state[0][js].plat_joystick_nr) { + if (joystick_state[gp][js].plat_joystick_nr) { for (int axis_nr = 0; axis_nr < joystick_get_axis_count(joystick_type[joy_insn]); axis_nr++) { sprintf(tmp2, "joystick_%i_axis_%i", js, axis_nr); - ini_section_set_int(cat, tmp2, joystick_state[0][js].axis_mapping[axis_nr]); + ini_section_set_int(cat, tmp2, joystick_state[gp][js].axis_mapping[axis_nr]); } for (int button_nr = 0; button_nr < joystick_get_button_count(joystick_type[joy_insn]); button_nr++) { sprintf(tmp2, "joystick_%i_button_%i", js, button_nr); - ini_section_set_int(cat, tmp2, joystick_state[0][js].button_mapping[button_nr]); + ini_section_set_int(cat, tmp2, joystick_state[gp][js].button_mapping[button_nr]); } for (int pov_nr = 0; pov_nr < joystick_get_pov_count(joystick_type[joy_insn]); pov_nr++) { sprintf(tmp2, "joystick_%i_pov_%i", js, pov_nr); - sprintf(temp, "%i, %i", joystick_state[0][js].pov_mapping[pov_nr][0], - joystick_state[0][js].pov_mapping[pov_nr][1]); + sprintf(temp, "%i, %i", joystick_state[gp][js].pov_mapping[pov_nr][0], + joystick_state[gp][js].pov_mapping[pov_nr][1]); ini_section_set_string(cat, tmp2, temp); } } diff --git a/src/game/joystick_ch_flightstick_pro.c b/src/game/joystick_ch_flightstick_pro.c index b3d4e0ef5..834aa8a99 100644 --- a/src/game/joystick_ch_flightstick_pro.c +++ b/src/game/joystick_ch_flightstick_pro.c @@ -58,25 +58,26 @@ ch_flightstick_pro_close(UNUSED(void *priv)) static uint8_t ch_flightstick_pro_read(UNUSED(void *priv)) { + uint8_t gp = 0; uint8_t ret = 0xf0; - if (JOYSTICK_PRESENT(0, 0)) { - if (joystick_state[0][0].button[0]) + if (JOYSTICK_PRESENT(gp, 0)) { + if (joystick_state[gp][0].button[0]) ret &= ~0x10; - if (joystick_state[0][0].button[1]) + if (joystick_state[gp][0].button[1]) ret &= ~0x20; - if (joystick_state[0][0].button[2]) + if (joystick_state[gp][0].button[2]) ret &= ~0x40; - if (joystick_state[0][0].button[3]) + if (joystick_state[gp][0].button[3]) ret &= ~0x80; - if (joystick_state[0][0].pov[0] != -1) { - if (joystick_state[0][0].pov[0] > 315 || joystick_state[0][0].pov[0] < 45) + if (joystick_state[gp][0].pov[0] != -1) { + if (joystick_state[gp][0].pov[0] > 315 || joystick_state[gp][0].pov[0] < 45) ret &= ~0xf0; - else if (joystick_state[0][0].pov[0] >= 45 && joystick_state[0][0].pov[0] < 135) + else if (joystick_state[gp][0].pov[0] >= 45 && joystick_state[gp][0].pov[0] < 135) ret &= ~0xb0; - else if (joystick_state[0][0].pov[0] >= 135 && joystick_state[0][0].pov[0] < 225) + else if (joystick_state[gp][0].pov[0] >= 135 && joystick_state[gp][0].pov[0] < 225) ret &= ~0x70; - else if (joystick_state[0][0].pov[0] >= 225 && joystick_state[0][0].pov[0] < 315) + else if (joystick_state[gp][0].pov[0] >= 225 && joystick_state[gp][0].pov[0] < 315) ret &= ~0x30; } } @@ -93,18 +94,20 @@ ch_flightstick_pro_write(UNUSED(void *priv)) static int ch_flightstick_pro_read_axis(UNUSED(void *priv), int axis) { - if (!JOYSTICK_PRESENT(0, 0)) + uint8_t gp = 0; + + if (!JOYSTICK_PRESENT(gp, 0)) return AXIS_NOT_PRESENT; switch (axis) { case 0: - return joystick_state[0][0].axis[0]; + return joystick_state[gp][0].axis[0]; case 1: - return joystick_state[0][0].axis[1]; + return joystick_state[gp][0].axis[1]; case 2: return 0; case 3: - return joystick_state[0][0].axis[2]; + return joystick_state[gp][0].axis[2]; default: return 0; } @@ -113,18 +116,20 @@ ch_flightstick_pro_read_axis(UNUSED(void *priv), int axis) static int ch_flightstick_pro_ch_pedals_read_axis(UNUSED(void *priv), int axis) { - if (!JOYSTICK_PRESENT(0, 0)) + uint8_t gp = 0; + + if (!JOYSTICK_PRESENT(gp, 0)) return AXIS_NOT_PRESENT; switch (axis) { case 0: - return joystick_state[0][0].axis[0]; + return joystick_state[gp][0].axis[0]; case 1: - return joystick_state[0][0].axis[1]; + return joystick_state[gp][0].axis[1]; case 2: - return joystick_state[0][0].axis[3]; + return joystick_state[gp][0].axis[3]; case 3: - return joystick_state[0][0].axis[2]; + return joystick_state[gp][0].axis[2]; default: return 0; } diff --git a/src/game/joystick_standard.c b/src/game/joystick_standard.c index fa83826da..5e0268d6b 100644 --- a/src/game/joystick_standard.c +++ b/src/game/joystick_standard.c @@ -10,7 +10,6 @@ * * Authors: Miran Grca, * Sarah Walker, - * Miran Grca, * Jasmine Iwanek, * * Copyright 2016-2018 Miran Grca. @@ -61,19 +60,20 @@ joystick_standard_close(UNUSED(void *priv)) static uint8_t joystick_standard_read(UNUSED(void *priv)) { + uint8_t gp = 0; uint8_t ret = 0xf0; - if (JOYSTICK_PRESENT(0, 0)) { - if (joystick_state[0][0].button[0]) + if (JOYSTICK_PRESENT(gp, 0)) { + if (joystick_state[gp][0].button[0]) ret &= ~0x10; - if (joystick_state[0][0].button[1]) + if (joystick_state[gp][0].button[1]) ret &= ~0x20; } - if (JOYSTICK_PRESENT(0, 1)) { - if (joystick_state[0][1].button[0]) + if (JOYSTICK_PRESENT(gp, 1)) { + if (joystick_state[gp][1].button[0]) ret &= ~0x40; - if (joystick_state[0][1].button[1]) + if (joystick_state[gp][1].button[1]) ret &= ~0x80; } @@ -83,16 +83,17 @@ joystick_standard_read(UNUSED(void *priv)) static uint8_t joystick_standard_read_4button(UNUSED(void *priv)) { + uint8_t gp = 0; uint8_t ret = 0xf0; - if (JOYSTICK_PRESENT(0, 0)) { - if (joystick_state[0][0].button[0]) + if (JOYSTICK_PRESENT(gp, 0)) { + if (joystick_state[gp][0].button[0]) ret &= ~0x10; - if (joystick_state[0][0].button[1]) + if (joystick_state[gp][0].button[1]) ret &= ~0x20; - if (joystick_state[0][0].button[2]) + if (joystick_state[gp][0].button[2]) ret &= ~0x40; - if (joystick_state[0][0].button[3]) + if (joystick_state[gp][0].button[3]) ret &= ~0x80; } @@ -108,23 +109,25 @@ joystick_standard_write(UNUSED(void *priv)) static int joystick_standard_read_axis(UNUSED(void *priv), int axis) { + uint8_t gp = 0; + switch (axis) { case 0: - if (!JOYSTICK_PRESENT(0, 0)) + if (!JOYSTICK_PRESENT(gp, 0)) return AXIS_NOT_PRESENT; - return joystick_state[0][0].axis[0]; + return joystick_state[gp][0].axis[0]; case 1: - if (!JOYSTICK_PRESENT(0, 0)) + if (!JOYSTICK_PRESENT(gp, 0)) return AXIS_NOT_PRESENT; - return joystick_state[0][0].axis[1]; + return joystick_state[gp][0].axis[1]; case 2: - if (!JOYSTICK_PRESENT(0, 1)) + if (!JOYSTICK_PRESENT(gp, 1)) return AXIS_NOT_PRESENT; - return joystick_state[0][1].axis[0]; + return joystick_state[gp][1].axis[0]; case 3: - if (!JOYSTICK_PRESENT(0, 1)) + if (!JOYSTICK_PRESENT(gp, 1)) return AXIS_NOT_PRESENT; - return joystick_state[0][1].axis[1]; + return joystick_state[gp][1].axis[1]; default: return 0; } @@ -133,14 +136,16 @@ joystick_standard_read_axis(UNUSED(void *priv), int axis) static int joystick_standard_read_axis_4button(UNUSED(void *priv), int axis) { - if (!JOYSTICK_PRESENT(0, 0)) + uint8_t gp = 0; + + if (!JOYSTICK_PRESENT(gp, 0)) return AXIS_NOT_PRESENT; switch (axis) { case 0: - return joystick_state[0][0].axis[0]; + return joystick_state[gp][0].axis[0]; case 1: - return joystick_state[0][0].axis[1]; + return joystick_state[gp][0].axis[1]; case 2: case 3: default: @@ -153,24 +158,26 @@ joystick_standard_read_axis_4button(UNUSED(void *priv), int axis) static int joystick_standard_read_axis_with_pov(UNUSED(void *priv), int axis) { - if (!JOYSTICK_PRESENT(0, 0)) + uint8_t gp = 0; + + if (!JOYSTICK_PRESENT(gp, 0)) return AXIS_NOT_PRESENT; switch (axis) { case 0: // X-axis - return joystick_state[0][0].axis[0]; + return joystick_state[gp][0].axis[0]; case 1: // Y-axis - return joystick_state[0][0].axis[1]; + return joystick_state[gp][0].axis[1]; case 2: // POV Hat (mapped to the 3rd logical axis, index 2) - if (joystick_state[0][0].pov[0] == -1) + if (joystick_state[gp][0].pov[0] == -1) return 32767; // Centered/No input (as per tm_fcs_rcs_read_axis example) - if (joystick_state[0][0].pov[0] > 315 || joystick_state[0][0].pov[0] < 45) + if (joystick_state[gp][0].pov[0] > 315 || joystick_state[gp][0].pov[0] < 45) return -32768; // Up - if (joystick_state[0][0].pov[0] >= 45 && joystick_state[0][0].pov[0] < 135) + if (joystick_state[gp][0].pov[0] >= 45 && joystick_state[gp][0].pov[0] < 135) return -16384; // Up-Right (example value, matches tm_fcs_rcs_read_axis) - if (joystick_state[0][0].pov[0] >= 135 && joystick_state[0][0].pov[0] < 225) + if (joystick_state[gp][0].pov[0] >= 135 && joystick_state[gp][0].pov[0] < 225) return 0; // Right/Left (example, matches tm_fcs_rcs_read_axis) - if (joystick_state[0][0].pov[0] >= 225 && joystick_state[0][0].pov[0] < 315) + if (joystick_state[gp][0].pov[0] >= 225 && joystick_state[gp][0].pov[0] < 315) return 16384; // Down-Left (example value, matches tm_fcs_rcs_read_axis) return 0; // Fallback case 3: // This case might be used for a Z-axis if present, or can return 0 if not. @@ -185,16 +192,19 @@ joystick_standard_read_axis_with_pov(UNUSED(void *priv), int axis) static int joystick_standard_read_axis_3axis(UNUSED(void *priv), int axis) { - if (!JOYSTICK_PRESENT(0, 0)) + uint8_t gp = 0; + uint8_t js = 0; + + if (!JOYSTICK_PRESENT(gp, 0)) return AXIS_NOT_PRESENT; switch (axis) { case 0: - return joystick_state[0][0].axis[0]; + return joystick_state[gp][0].axis[0]; case 1: - return joystick_state[0][0].axis[1]; + return joystick_state[gp][0].axis[1]; case 2: - return joystick_state[0][0].axis[2]; + return joystick_state[gp][0].axis[2]; case 3: default: return 0; @@ -204,18 +214,20 @@ joystick_standard_read_axis_3axis(UNUSED(void *priv), int axis) static int joystick_standard_read_axis_4axis(UNUSED(void *priv), int axis) { - if (!JOYSTICK_PRESENT(0, 0)) + uint8_t gp = 0; + + if (!JOYSTICK_PRESENT(gp, 0)) return AXIS_NOT_PRESENT; switch (axis) { case 0: - return joystick_state[0][0].axis[0]; + return joystick_state[gp][0].axis[0]; case 1: - return joystick_state[0][0].axis[1]; + return joystick_state[gp][0].axis[1]; case 2: - return joystick_state[0][0].axis[2]; + return joystick_state[gp][0].axis[2]; case 3: - return joystick_state[0][0].axis[3]; + return joystick_state[gp][0].axis[3]; default: return 0; } @@ -224,18 +236,20 @@ joystick_standard_read_axis_4axis(UNUSED(void *priv), int axis) static int joystick_standard_read_axis_6button(UNUSED(void *priv), int axis) { - if (!JOYSTICK_PRESENT(0, 0)) + uint8_t gp = 0; + + if (!JOYSTICK_PRESENT(gp, 0)) return AXIS_NOT_PRESENT; switch (axis) { case 0: - return joystick_state[0][0].axis[0]; + return joystick_state[gp][0].axis[0]; case 1: - return joystick_state[0][0].axis[1]; + return joystick_state[gp][0].axis[1]; case 2: - return joystick_state[0][0].button[4] ? -32767 : 32768; + return joystick_state[gp][0].button[4] ? -32767 : 32768; case 3: - return joystick_state[0][0].button[5] ? -32767 : 32768; + return joystick_state[gp][0].button[5] ? -32767 : 32768; default: return 0; } @@ -243,24 +257,26 @@ joystick_standard_read_axis_6button(UNUSED(void *priv), int axis) static int joystick_standard_read_axis_8button(UNUSED(void *priv), int axis) { - if (!JOYSTICK_PRESENT(0, 0)) + uint8_t gp = 0; + + if (!JOYSTICK_PRESENT(gp, 0)) return AXIS_NOT_PRESENT; switch (axis) { case 0: - return joystick_state[0][0].axis[0]; + return joystick_state[gp][0].axis[0]; case 1: - return joystick_state[0][0].axis[1]; + return joystick_state[gp][0].axis[1]; case 2: - if (joystick_state[0][0].button[4]) + if (joystick_state[gp][0].button[4]) return -32767; - if (joystick_state[0][0].button[6]) + if (joystick_state[gp][0].button[6]) return 32768; return 0; case 3: - if (joystick_state[0][0].button[5]) + if (joystick_state[gp][0].button[5]) return -32767; - if (joystick_state[0][0].button[7]) + if (joystick_state[gp][0].button[7]) return 32768; return 0; default: diff --git a/src/game/joystick_sw_pad.c b/src/game/joystick_sw_pad.c index 7c1d4910b..c0d280de1 100644 --- a/src/game/joystick_sw_pad.c +++ b/src/game/joystick_sw_pad.c @@ -31,9 +31,11 @@ * * Authors: Miran Grca, * Sarah Walker, + * Jasmine Iwanek, * * Copyright 2016-2018 Miran Grca. * Copyright 2008-2018 Sarah Walker. + * Copyright 2021-2025 Jasmine Iwanek. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -136,10 +138,11 @@ sw_close(void *priv) static uint8_t sw_read(void *priv) { + uint8_t gp = 0; sw_data *sw = (sw_data *) priv; uint8_t temp = 0; - if (!JOYSTICK_PRESENT(0, 0)) + if (!JOYSTICK_PRESENT(gp, 0)) return 0xff; if (timer_is_enabled(&sw->poll_timer)) { @@ -162,10 +165,11 @@ sw_read(void *priv) static void sw_write(void *priv) { + uint8_t gp = 0; sw_data *sw = (sw_data *) priv; int64_t time_since_last = timer_get_remaining_us(&sw->trigger_timer); - if (!JOYSTICK_PRESENT(0, 0)) + if (!JOYSTICK_PRESENT(gp, 0)) return; if (!sw->poll_left) { @@ -191,20 +195,20 @@ sw_write(void *priv) for (uint8_t js = 0; js < 4; js++) { uint16_t data = 0x3fff; - if (!JOYSTICK_PRESENT(0, js)) + if (!JOYSTICK_PRESENT(gp, js)) break; - if (joystick_state[0][js].axis[1] < -16383) + if (joystick_state[gp][js].axis[1] < -16383) data &= ~1; - if (joystick_state[0][js].axis[1] > 16383) + if (joystick_state[gp][js].axis[1] > 16383) data &= ~2; - if (joystick_state[0][js].axis[0] > 16383) + if (joystick_state[gp][js].axis[0] > 16383) data &= ~4; - if (joystick_state[0][js].axis[0] < -16383) + if (joystick_state[gp][js].axis[0] < -16383) data &= ~8; for (uint8_t button_nr = 0; button_nr < 10; button_nr++) { - if (joystick_state[0][js].button[button_nr]) + if (joystick_state[gp][js].button[button_nr]) data &= ~(1 << (button_nr + 4)); } @@ -228,7 +232,9 @@ sw_write(void *priv) static int sw_read_axis(UNUSED(void *priv), UNUSED(int axis)) { - if (!JOYSTICK_PRESENT(0, 0)) + uint8_t gp = 0; + + if (!JOYSTICK_PRESENT(gp, 0)) return AXIS_NOT_PRESENT; return 0; /*No analogue support on Sidewinder game pad*/ diff --git a/src/game/joystick_tm_fcs.c b/src/game/joystick_tm_fcs.c index 6c1176a42..c8368612d 100644 --- a/src/game/joystick_tm_fcs.c +++ b/src/game/joystick_tm_fcs.c @@ -10,9 +10,11 @@ * * Authors: Miran Grca, * Sarah Walker, + * Jasmine Iwanek, * * Copyright 2016-2018 Miran Grca. * Copyright 2008-2018 Sarah Walker. + * Copyright 2021-2025 Jasmine IWanek. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -58,16 +60,17 @@ tm_fcs_close(UNUSED(void *priv)) static uint8_t tm_fcs_read(UNUSED(void *priv)) { + uint8_t gp = 0; uint8_t ret = 0xf0; - if (JOYSTICK_PRESENT(0, 0)) { - if (joystick_state[0][0].button[0]) + if (JOYSTICK_PRESENT(gp, 0)) { + if (joystick_state[gp][0].button[0]) ret &= ~0x10; - if (joystick_state[0][0].button[1]) + if (joystick_state[gp][0].button[1]) ret &= ~0x20; - if (joystick_state[0][0].button[2]) + if (joystick_state[gp][0].button[2]) ret &= ~0x40; - if (joystick_state[0][0].button[3]) + if (joystick_state[gp][0].button[3]) ret &= ~0x80; } @@ -83,26 +86,28 @@ tm_fcs_write(UNUSED(void *priv)) static int tm_fcs_read_axis(UNUSED(void *priv), int axis) { - if (!JOYSTICK_PRESENT(0, 0)) + uint8_t gp= 0; + + if (!JOYSTICK_PRESENT(gp, 0)) return AXIS_NOT_PRESENT; switch (axis) { case 0: - return joystick_state[0][0].axis[0]; + return joystick_state[gp][0].axis[0]; case 1: - return joystick_state[0][0].axis[1]; + return joystick_state[gp][0].axis[1]; case 2: return 0; case 3: - if (joystick_state[0][0].pov[0] == -1) + if (joystick_state[gp][0].pov[0] == -1) return 32767; - if (joystick_state[0][0].pov[0] > 315 || joystick_state[0][0].pov[0] < 45) + if (joystick_state[gp][0].pov[0] > 315 || joystick_state[gp][0].pov[0] < 45) return -32768; - if (joystick_state[0][0].pov[0] >= 45 && joystick_state[0][0].pov[0] < 135) + if (joystick_state[gp][0].pov[0] >= 45 && joystick_state[gp][0].pov[0] < 135) return -16384; - if (joystick_state[0][0].pov[0] >= 135 && joystick_state[0][0].pov[0] < 225) + if (joystick_state[gp][0].pov[0] >= 135 && joystick_state[gp][0].pov[0] < 225) return 0; - if (joystick_state[0][0].pov[0] >= 225 && joystick_state[0][0].pov[0] < 315) + if (joystick_state[gp][0].pov[0] >= 225 && joystick_state[gp][0].pov[0] < 315) return 16384; return 0; default: @@ -113,26 +118,28 @@ tm_fcs_read_axis(UNUSED(void *priv), int axis) static int tm_fcs_rcs_read_axis(UNUSED(void *priv), int axis) { - if (!JOYSTICK_PRESENT(0, 0)) + uint8_t gp = 0; + + if (!JOYSTICK_PRESENT(gp, 0)) return AXIS_NOT_PRESENT; switch (axis) { case 0: - return joystick_state[0][0].axis[0]; + return joystick_state[gp][0].axis[0]; case 1: - return joystick_state[0][0].axis[1]; + return joystick_state[gp][0].axis[1]; case 2: - return joystick_state[0][0].axis[2]; + return joystick_state[gp][0].axis[2]; case 3: - if (joystick_state[0][0].pov[0] == -1) + if (joystick_state[gp][0].pov[0] == -1) return 32767; - if (joystick_state[0][0].pov[0] > 315 || joystick_state[0][0].pov[0] < 45) + if (joystick_state[gp][0].pov[0] > 315 || joystick_state[gp][0].pov[0] < 45) return -32768; - if (joystick_state[0][0].pov[0] >= 45 && joystick_state[0][0].pov[0] < 135) + if (joystick_state[gp][0].pov[0] >= 45 && joystick_state[gp][0].pov[0] < 135) return -16384; - if (joystick_state[0][0].pov[0] >= 135 && joystick_state[0][0].pov[0] < 225) + if (joystick_state[gp][0].pov[0] >= 135 && joystick_state[gp][0].pov[0] < 225) return 0; - if (joystick_state[0][0].pov[0] >= 225 && joystick_state[0][0].pov[0] < 315) + if (joystick_state[gp][0].pov[0] >= 225 && joystick_state[gp][0].pov[0] < 315) return 16384; return 0; default: