diff --git a/src/game/joystick_ch_flightstick_pro.c b/src/game/joystick_ch_flightstick_pro.c index 4d8a4cf29..cefb86e73 100644 --- a/src/game/joystick_ch_flightstick_pro.c +++ b/src/game/joystick_ch_flightstick_pro.c @@ -44,34 +44,7 @@ #include <86box/timer.h> #include <86box/gameport.h> #include <86box/plat_unused.h> - -static void * -ch_flightstick_pro_init(void) -{ - return NULL; -} - -static void -ch_flightstick_pro_close(UNUSED(void *priv)) -{ - // -} - -static uint8_t -ch_flightstick_read(UNUSED(void *priv)) -{ - uint8_t ret = 0xf0; - uint8_t gp = 0; - - if (JOYSTICK_PRESENT(gp, 0)) { - if (joystick_state[gp][0].button[0]) - ret &= ~0x10; - if (joystick_state[gp][0].button[1]) - ret &= ~0x20; - } - - return ret; -} +#include <86box/joystick.h> static uint8_t ch_flightstick_pro_read(UNUSED(void *priv)) @@ -169,71 +142,15 @@ ch_virtual_pilot_pro_read(UNUSED(void *priv)) return ret; } -static void -ch_flightstick_pro_write(UNUSED(void *priv)) -{ - // -} - -static int -ch_flightstick_pro_read_axis(UNUSED(void *priv), int axis) -{ - uint8_t gp = 0; - - if (!JOYSTICK_PRESENT(gp, 0)) - return AXIS_NOT_PRESENT; - - switch (axis) { - case 0: - return joystick_state[gp][0].axis[0]; - case 1: - return joystick_state[gp][0].axis[1]; - case 2: - return 0; - case 3: - return joystick_state[gp][0].axis[2]; - default: - return 0; - } -} - -static int -ch_flightstick_pro_ch_pedals_read_axis(UNUSED(void *priv), int axis) -{ - uint8_t gp = 0; - - if (!JOYSTICK_PRESENT(gp, 0)) - return AXIS_NOT_PRESENT; - - switch (axis) { - case 0: - return joystick_state[gp][0].axis[0]; - case 1: - return joystick_state[gp][0].axis[1]; - case 2: - return joystick_state[gp][0].axis[3]; - case 3: - return joystick_state[gp][0].axis[2]; - default: - return 0; - } -} - -static void -ch_flightstick_pro_a0_over(UNUSED(void *priv)) -{ - // -} - const joystick_t joystick_ch_flightstick = { .name = "CH Flightstick", .internal_name = "ch_flightstick", - .init = ch_flightstick_pro_init, - .close = ch_flightstick_pro_close, - .read = ch_flightstick_read, - .write = ch_flightstick_pro_write, - .read_axis = ch_flightstick_pro_read_axis, - .a0_over = ch_flightstick_pro_a0_over, + .init = joystick_standard_init, + .close = joystick_standard_close, + .read = joystick_standard_read_2button, + .write = joystick_standard_write, + .read_axis = joystick_standard_read_axis_3axis_throttle, + .a0_over = joystick_standard_a0_over, .axis_count = 3, .button_count = 2, .pov_count = 0, @@ -246,12 +163,12 @@ const joystick_t joystick_ch_flightstick = { const joystick_t joystick_ch_flightstick_ch_pedals = { .name = "CH Flightstick + CH Pedals", .internal_name = "ch_flightstick_ch_pedals", - .init = ch_flightstick_pro_init, - .close = ch_flightstick_pro_close, - .read = ch_flightstick_read, - .write = ch_flightstick_pro_write, - .read_axis = ch_flightstick_pro_ch_pedals_read_axis, - .a0_over = ch_flightstick_pro_a0_over, + .init = joystick_standard_init, + .close = joystick_standard_close, + .read = joystick_standard_read_2button, + .write = joystick_standard_write, + .read_axis = joystick_standard_read_axis_4axis, + .a0_over = joystick_standard_a0_over, .axis_count = 4, .button_count = 2, .pov_count = 0, @@ -264,12 +181,12 @@ const joystick_t joystick_ch_flightstick_ch_pedals = { const joystick_t joystick_ch_flightstick_ch_pedals_pro = { .name = "CH Flightstick + CH Pedals Pro", .internal_name = "ch_flightstick_ch_pedals_pro", - .init = ch_flightstick_pro_init, - .close = ch_flightstick_pro_close, - .read = ch_flightstick_read, - .write = ch_flightstick_pro_write, - .read_axis = ch_flightstick_pro_ch_pedals_read_axis, - .a0_over = ch_flightstick_pro_a0_over, + .init = joystick_standard_init, + .close = joystick_standard_close, + .read = joystick_standard_read_2button, + .write = joystick_standard_write, + .read_axis = joystick_standard_read_axis_4axis, + .a0_over = joystick_standard_a0_over, .axis_count = 4, .button_count = 2, .pov_count = 0, @@ -282,12 +199,12 @@ const joystick_t joystick_ch_flightstick_ch_pedals_pro = { const joystick_t joystick_ch_flightstick_pro = { .name = "CH Flightstick Pro", .internal_name = "ch_flightstick_pro", - .init = ch_flightstick_pro_init, - .close = ch_flightstick_pro_close, + .init = joystick_standard_init, + .close = joystick_standard_close, .read = ch_flightstick_pro_read, - .write = ch_flightstick_pro_write, - .read_axis = ch_flightstick_pro_read_axis, - .a0_over = ch_flightstick_pro_a0_over, + .write = joystick_standard_write, + .read_axis = joystick_standard_read_axis_3axis_throttle, + .a0_over = joystick_standard_a0_over, .axis_count = 3, .button_count = 4, .pov_count = 1, @@ -300,12 +217,12 @@ const joystick_t joystick_ch_flightstick_pro = { const joystick_t joystick_ch_flightstick_pro_ch_pedals = { .name = "CH Flightstick Pro + CH Pedals", .internal_name = "ch_flightstick_pro_ch_pedals", - .init = ch_flightstick_pro_init, - .close = ch_flightstick_pro_close, + .init = joystick_standard_init, + .close = joystick_standard_close, .read = ch_flightstick_pro_read, - .write = ch_flightstick_pro_write, - .read_axis = ch_flightstick_pro_ch_pedals_read_axis, - .a0_over = ch_flightstick_pro_a0_over, + .write = joystick_standard_write, + .read_axis = joystick_standard_read_axis_4axis, + .a0_over = joystick_standard_a0_over, .axis_count = 4, .button_count = 4, .pov_count = 1, @@ -318,12 +235,12 @@ const joystick_t joystick_ch_flightstick_pro_ch_pedals = { const joystick_t joystick_ch_flightstick_pro_ch_pedals_pro = { .name = "CH Flightstick Pro + CH Pedals Pro", .internal_name = "ch_flightstick_pro_ch_pedals_pro", - .init = ch_flightstick_pro_init, - .close = ch_flightstick_pro_close, + .init = joystick_standard_init, + .close = joystick_standard_close, .read = ch_flightstick_pro_read, - .write = ch_flightstick_pro_write, - .read_axis = ch_flightstick_pro_ch_pedals_read_axis, - .a0_over = ch_flightstick_pro_a0_over, + .write = joystick_standard_write, + .read_axis = joystick_standard_read_axis_4axis, + .a0_over = joystick_standard_a0_over, .axis_count = 4, .button_count = 4, .pov_count = 1, @@ -336,12 +253,12 @@ const joystick_t joystick_ch_flightstick_pro_ch_pedals_pro = { const joystick_t joystick_ch_virtual_pilot = { .name = "CH Virtual Pilot", .internal_name = "ch_virtual_pilot", - .init = ch_flightstick_pro_init, - .close = ch_flightstick_pro_close, - .read = ch_flightstick_read, - .write = ch_flightstick_pro_write, - .read_axis = ch_flightstick_pro_read_axis, - .a0_over = ch_flightstick_pro_a0_over, + .init = joystick_standard_init, + .close = joystick_standard_close, + .read = joystick_standard_read_2button, + .write = joystick_standard_write, + .read_axis = joystick_standard_read_axis_3axis_throttle, + .a0_over = joystick_standard_a0_over, .axis_count = 3, .button_count = 2, .pov_count = 0, @@ -354,12 +271,12 @@ const joystick_t joystick_ch_virtual_pilot = { const joystick_t joystick_ch_virtual_pilot_ch_pedals = { .name = "CH Virtual Pilot + CH Pedals", .internal_name = "ch_virtual_pilot_ch_pedals", - .init = ch_flightstick_pro_init, - .close = ch_flightstick_pro_close, - .read = ch_flightstick_read, - .write = ch_flightstick_pro_write, - .read_axis = ch_flightstick_pro_ch_pedals_read_axis, - .a0_over = ch_flightstick_pro_a0_over, + .init = joystick_standard_init, + .close = joystick_standard_close, + .read = joystick_standard_read_2button, + .write = joystick_standard_write, + .read_axis = joystick_standard_read_axis_4axis, + .a0_over = joystick_standard_a0_over, .axis_count = 4, .button_count = 2, .pov_count = 0, @@ -372,12 +289,12 @@ const joystick_t joystick_ch_virtual_pilot_ch_pedals = { const joystick_t joystick_ch_virtual_pilot_ch_pedals_pro = { .name = "CH Virtual Pilot + CH Pedals Pro", .internal_name = "ch_virtual_pilot_ch_pedals_pro", - .init = ch_flightstick_pro_init, - .close = ch_flightstick_pro_close, - .read = ch_flightstick_read, - .write = ch_flightstick_pro_write, - .read_axis = ch_flightstick_pro_ch_pedals_read_axis, - .a0_over = ch_flightstick_pro_a0_over, + .init = joystick_standard_init, + .close = joystick_standard_close, + .read = joystick_standard_read_2button, + .write = joystick_standard_write, + .read_axis = joystick_standard_read_axis_4axis, + .a0_over = joystick_standard_a0_over, .axis_count = 4, .button_count = 2, .pov_count = 0, @@ -390,12 +307,12 @@ const joystick_t joystick_ch_virtual_pilot_ch_pedals_pro = { const joystick_t joystick_ch_virtual_pilot_pro = { .name = "CH Virtual Pilot Pro", .internal_name = "ch_virtual_pilot_pro", - .init = ch_flightstick_pro_init, - .close = ch_flightstick_pro_close, + .init = joystick_standard_init, + .close = joystick_standard_close, .read = ch_virtual_pilot_pro_read, - .write = ch_flightstick_pro_write, - .read_axis = ch_flightstick_pro_read_axis, - .a0_over = ch_flightstick_pro_a0_over, + .write = joystick_standard_write, + .read_axis = joystick_standard_read_axis_3axis_throttle, + .a0_over = joystick_standard_a0_over, .axis_count = 3, .button_count = 6, .pov_count = 2, @@ -408,12 +325,12 @@ const joystick_t joystick_ch_virtual_pilot_pro = { const joystick_t joystick_ch_virtual_pilot_pro_ch_pedals = { .name = "CH Virtual Pilot Pro + CH Pedals", .internal_name = "ch_virtual_pilot_pro_ch_pedals", - .init = ch_flightstick_pro_init, - .close = ch_flightstick_pro_close, + .init = joystick_standard_init, + .close = joystick_standard_close, .read = ch_virtual_pilot_pro_read, - .write = ch_flightstick_pro_write, - .read_axis = ch_flightstick_pro_ch_pedals_read_axis, - .a0_over = ch_flightstick_pro_a0_over, + .write = joystick_standard_write, + .read_axis = joystick_standard_read_axis_4axis, + .a0_over = joystick_standard_a0_over, .axis_count = 4, .button_count = 6, .pov_count = 2, @@ -426,12 +343,12 @@ const joystick_t joystick_ch_virtual_pilot_pro_ch_pedals = { const joystick_t joystick_ch_virtual_pilot_pro_ch_pedals_pro = { .name = "CH Virtual Pilot Pro + CH Pedals Pro", .internal_name = "ch_virtual_pilot_pro_ch_pedals_pro", - .init = ch_flightstick_pro_init, - .close = ch_flightstick_pro_close, + .init = joystick_standard_init, + .close = joystick_standard_close, .read = ch_virtual_pilot_pro_read, - .write = ch_flightstick_pro_write, - .read_axis = ch_flightstick_pro_ch_pedals_read_axis, - .a0_over = ch_flightstick_pro_a0_over, + .write = joystick_standard_write, + .read_axis = joystick_standard_read_axis_4axis, + .a0_over = joystick_standard_a0_over, .axis_count = 4, .button_count = 6, .pov_count = 2, diff --git a/src/game/joystick_standard.c b/src/game/joystick_standard.c index c0497b05a..a9e3da402 100644 --- a/src/game/joystick_standard.c +++ b/src/game/joystick_standard.c @@ -45,13 +45,13 @@ #include <86box/gameport.h> #include <86box/plat_unused.h> -static void * +void * joystick_standard_init(void) { return NULL; } -static void +void joystick_standard_close(UNUSED(void *priv)) { // @@ -101,6 +101,22 @@ joystick_standard_read(UNUSED(void *priv)) return ret; } +uint8_t +joystick_standard_read_2button(UNUSED(void *priv)) +{ + uint8_t gp = 0; + uint8_t ret = 0xf0; + + if (JOYSTICK_PRESENT(gp, 0)) { + if (joystick_state[gp][0].button[0]) + ret &= ~0x10; + if (joystick_state[gp][0].button[1]) + ret &= ~0x20; + } + + return ret; +} + static uint8_t joystick_standard_read_3button(UNUSED(void *priv)) { @@ -119,7 +135,7 @@ joystick_standard_read_3button(UNUSED(void *priv)) return ret; } -static uint8_t +uint8_t joystick_standard_read_4button(UNUSED(void *priv)) { uint8_t gp = 0; @@ -139,7 +155,7 @@ joystick_standard_read_4button(UNUSED(void *priv)) return ret; } -static void +void joystick_standard_write(UNUSED(void *priv)) { // @@ -275,7 +291,7 @@ joystick_standard_read_axis_3axis(UNUSED(void *priv), int axis) } } -static int +int joystick_standard_read_axis_3axis_throttle(UNUSED(void *priv), int axis) { uint8_t gp = 0; @@ -296,7 +312,7 @@ joystick_standard_read_axis_3axis_throttle(UNUSED(void *priv), int axis) } } -static int +int joystick_standard_read_axis_4axis(UNUSED(void *priv), int axis) { uint8_t gp = 0; @@ -369,7 +385,7 @@ joystick_standard_read_axis_8button(UNUSED(void *priv), int axis) } } -static void +void joystick_standard_a0_over(UNUSED(void *priv)) { // @@ -506,7 +522,7 @@ const joystick_t joystick_3axis_2button = { .internal_name = "3axis_2button", .init = joystick_standard_init, .close = joystick_standard_close, - .read = joystick_standard_read, + .read = joystick_standard_read_2button, .write = joystick_standard_write, .read_axis = joystick_standard_read_axis_3axis_throttle, .a0_over = joystick_standard_a0_over, @@ -560,7 +576,7 @@ const joystick_t joystick_4axis_2button = { .internal_name = "4axis_2button", .init = joystick_standard_init, .close = joystick_standard_close, - .read = joystick_standard_read, + .read = joystick_standard_read_2button, .write = joystick_standard_write, .read_axis = joystick_standard_read_axis_4axis, .a0_over = joystick_standard_a0_over, @@ -759,7 +775,7 @@ const joystick_t joystick_2button_yoke_throttle = { .internal_name = "2button_yoke_throttle", .init = joystick_standard_init, .close = joystick_standard_close, - .read = joystick_standard_read, + .read = joystick_standard_read_2button, .write = joystick_standard_write, .read_axis = joystick_standard_read_axis_3axis_throttle, .a0_over = joystick_standard_a0_over, @@ -813,7 +829,7 @@ const joystick_t joystick_steering_wheel_2_button = { .internal_name = "steering_wheel_2_button", .init = joystick_standard_init, .close = joystick_standard_close, - .read = joystick_standard_read, + .read = joystick_standard_read_2button, .write = joystick_standard_write, .read_axis = joystick_standard_read_axis_3axis, .a0_over = joystick_standard_a0_over, diff --git a/src/game/joystick_tm_fcs.c b/src/game/joystick_tm_fcs.c index 93f54db36..1f420ef0c 100644 --- a/src/game/joystick_tm_fcs.c +++ b/src/game/joystick_tm_fcs.c @@ -44,44 +44,7 @@ #include <86box/timer.h> #include <86box/gameport.h> #include <86box/plat_unused.h> - -static void * -tm_fcs_init(void) -{ - return NULL; -} - -static void -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(gp, 0)) { - if (joystick_state[gp][0].button[0]) - ret &= ~0x10; - if (joystick_state[gp][0].button[1]) - ret &= ~0x20; - if (joystick_state[gp][0].button[2]) - ret &= ~0x40; - if (joystick_state[gp][0].button[3]) - ret &= ~0x80; - } - - return ret; -} - -static void -tm_fcs_write(UNUSED(void *priv)) -{ - // -} +#include <86box/joystick.h> static int tm_fcs_read_axis(UNUSED(void *priv), int axis) @@ -96,8 +59,6 @@ tm_fcs_read_axis(UNUSED(void *priv), int axis) return joystick_state[gp][0].axis[0]; case 1: return joystick_state[gp][0].axis[1]; - case 2: - return 0; case 3: if (joystick_state[gp][0].pov[0] == -1) return 32767; @@ -110,6 +71,7 @@ tm_fcs_read_axis(UNUSED(void *priv), int axis) if (joystick_state[gp][0].pov[0] >= 225 && joystick_state[gp][0].pov[0] < 315) return 16384; return 0; + case 2: default: return 0; } @@ -147,21 +109,15 @@ tm_fcs_rcs_read_axis(UNUSED(void *priv), int axis) } } -static void -tm_fcs_a0_over(UNUSED(void *priv)) -{ - // -} - const joystick_t joystick_tm_fcs = { .name = "Thrustmaster Flight Control System", .internal_name = "thrustmaster_fcs", - .init = tm_fcs_init, - .close = tm_fcs_close, - .read = tm_fcs_read, - .write = tm_fcs_write, + .init = joystick_standard_init, + .close = joystick_standard_close, + .read = joystick_standard_read_4button, + .write = joystick_standard_write, .read_axis = tm_fcs_read_axis, - .a0_over = tm_fcs_a0_over, + .a0_over = joystick_standard_a0_over, .axis_count = 2, .button_count = 4, .pov_count = 1, @@ -174,12 +130,12 @@ const joystick_t joystick_tm_fcs = { const joystick_t joystick_tm_fcs_rcs = { .name = "Thrustmaster FCS + Rudder Control System", .internal_name = "thrustmaster_fcs_rcs", - .init = tm_fcs_init, - .close = tm_fcs_close, - .read = tm_fcs_read, - .write = tm_fcs_write, + .init = joystick_standard_init, + .close = joystick_standard_close, + .read = joystick_standard_read_4button, + .write = joystick_standard_write, .read_axis = tm_fcs_rcs_read_axis, - .a0_over = tm_fcs_a0_over, + .a0_over = joystick_standard_a0_over, .axis_count = 3, .button_count = 4, .pov_count = 1, diff --git a/src/include/86box/joystick.h b/src/include/86box/joystick.h new file mode 100644 index 000000000..c8cbf32d1 --- /dev/null +++ b/src/include/86box/joystick.h @@ -0,0 +1,27 @@ +/* + * 86Box A hypervisor and IBM PC system emulator that specializes in + * running old operating systems and software designed for IBM + * PC systems and compatibles from 1981 through fairly recent + * system designs based on the PCI bus. + * + * This file is part of the 86Box distribution. + * + * Definitions for the analog joystick handlers. + * + * Authors: Jasmine Iwanek, + * + * Copyright 2025 Jasmine Iwanek. + */ +#ifndef EMU_JOYSTICK_H +#define EMU_JOYSTICK_H + +void *joystick_standard_init(void); +void joystick_standard_close(UNUSED(void *priv)); +uint8_t joystick_standard_read_2button(UNUSED(void *priv)); +uint8_t joystick_standard_read_4button(UNUSED(void *priv)); +void joystick_standard_write(UNUSED(void *priv)); +int joystick_standard_read_axis_3axis_throttle(UNUSED(void *priv), int axis); +int joystick_standard_read_axis_4axis(UNUSED(void *priv), int axis); +void joystick_standard_a0_over(UNUSED(void *priv)); + +#endif /*EMU_JOYSTICK_H*/