From 487e5a198aa92a261a8375eae1559697659b151e Mon Sep 17 00:00:00 2001 From: Jasmine Iwanek Date: Sun, 19 Dec 2021 18:18:01 -0500 Subject: [PATCH] Add more generic joysticks 3axis, 2 button 3axis, 4 button standardize naming --- src/game/gameport.c | 16 +++--- src/game/joystick_standard.c | 70 +++++++++++++++++++++++---- src/game/joystick_sw_pad.c | 6 +-- src/include/86box/joystick_standard.h | 10 ++-- 4 files changed, 79 insertions(+), 23 deletions(-) diff --git a/src/game/gameport.c b/src/game/gameport.c index a8a2e685b..c4e33f20b 100644 --- a/src/game/gameport.c +++ b/src/game/gameport.c @@ -80,16 +80,18 @@ static const struct { const char *internal_name; const joystick_if_t *joystick; } joysticks[] = { - { "none", &joystick_none }, - { "standard_2button", &joystick_standard }, - { "standard_4button", &joystick_standard_4button }, - { "standard_6button", &joystick_standard_6button }, - { "standard_8button", &joystick_standard_8button }, - { "4axis_4button", &joystick_4axis_4button }, + { "none", &joystick_none }, + { "2axis_2button", &joystick_2axis_2button }, + { "2axis_4button", &joystick_2axis_4button }, + { "2axis_6button", &joystick_2axis_6button }, + { "2axis_8button", &joystick_2axis_8button }, + { "3axis_2button", &joystick_3axis_2button }, + { "3axis_4button", &joystick_3axis_4button }, + { "4axis_4button", &joystick_4axis_4button }, { "ch_flighstick_pro", &joystick_ch_flightstick_pro }, { "sidewinder_pad", &joystick_sw_pad }, { "thrustmaster_fcs", &joystick_tm_fcs }, - { "", NULL } + { "", NULL } }; static joystick_instance_t *joystick_instance = NULL; diff --git a/src/game/joystick_standard.c b/src/game/joystick_standard.c index e72d066cb..75e2ecdf3 100644 --- a/src/game/joystick_standard.c +++ b/src/game/joystick_standard.c @@ -145,6 +145,26 @@ static int joystick_standard_read_axis_4button(void *p, int axis) } } +static int joystick_standard_read_axis_3axis(void *p, int axis) +{ + if (!JOYSTICK_PRESENT(0)) + return AXIS_NOT_PRESENT; + + switch (axis) + { + case 0: + return joystick_state[0].axis[0]; + case 1: + return joystick_state[0].axis[1]; + case 2: + return joystick_state[0].axis[2]; + case 3: + return 0; + default: + return 0; + } +} + static int joystick_standard_read_axis_4axis(void *p, int axis) { if (!JOYSTICK_PRESENT(0)) @@ -216,9 +236,9 @@ static void joystick_standard_a0_over(void *p) { } -const joystick_if_t joystick_standard = +const joystick_if_t joystick_2axis_2button = { - "Standard 2-button joystick(s)", + "2-axis, 2-button joystick(s)", joystick_standard_init, joystick_standard_close, joystick_standard_read, @@ -232,9 +252,9 @@ const joystick_if_t joystick_standard = {"X axis", "Y axis"}, {"Button 1", "Button 2"} }; -const joystick_if_t joystick_standard_4button = +const joystick_if_t joystick_2axis_4button = { - "Standard 4-button joystick", + "2-axis, 4-button joystick", joystick_standard_init, joystick_standard_close, joystick_standard_read_4button, @@ -248,9 +268,41 @@ const joystick_if_t joystick_standard_4button = {"X axis", "Y axis"}, {"Button 1", "Button 2", "Button 3", "Button 4"} }; +const joystick_if_t joystick_3axis_2button = +{ + "3-axis, 2-button joystick", + joystick_standard_init, + joystick_standard_close, + joystick_standard_read, + joystick_standard_write, + joystick_standard_read_axis_3axis, + joystick_standard_a0_over, + 3, + 2, + 0, + 1, + {"X axis", "Y axis", "Z axis"}, + {"Button 1", "Button 2"} +}; +const joystick_if_t joystick_3axis_4button = +{ + "3-axis, 4-button joystick", + joystick_standard_init, + joystick_standard_close, + joystick_standard_read_4button, + joystick_standard_write, + joystick_standard_read_axis_3axis, + joystick_standard_a0_over, + 3, + 4, + 0, + 1, + {"X axis", "Y axis", "Z axis"}, + {"Button 1", "Button 2", "Button 3", "Button 4"} +}; const joystick_if_t joystick_4axis_4button = { - "4-axis 4-button joystick", + "4-axis, 4-button joystick", joystick_standard_init, joystick_standard_close, joystick_standard_read_4button, @@ -264,9 +316,9 @@ const joystick_if_t joystick_4axis_4button = {"X axis", "Y axis", "Z axis", "zX axis"}, {"Button 1", "Button 2", "Button 3", "Button 4"} }; -const joystick_if_t joystick_standard_6button = +const joystick_if_t joystick_2axis_6button = { - "Standard 6-button joystick", + "2-axis, 6-button joystick", joystick_standard_init, joystick_standard_close, joystick_standard_read_4button, @@ -280,9 +332,9 @@ const joystick_if_t joystick_standard_6button = {"X axis", "Y axis"}, {"Button 1", "Button 2", "Button 3", "Button 4", "Button 5", "Button 6"} }; -const joystick_if_t joystick_standard_8button = +const joystick_if_t joystick_2axis_8button = { - "Standard 8-button joystick", + "2-axis, 8-button joystick", joystick_standard_init, joystick_standard_close, joystick_standard_read_4button, diff --git a/src/game/joystick_sw_pad.c b/src/game/joystick_sw_pad.c index b42f0d55a..172b6826d 100644 --- a/src/game/joystick_sw_pad.c +++ b/src/game/joystick_sw_pad.c @@ -15,7 +15,7 @@ * connected * - Packet preceeded by high data (currently 50us), and * followed by low data (currently 160us) - timings are - * probably wrong, but good enoughfor everything I've tried + * probably wrong, but good enough for everything I've tried * - Analog inputs are only used to time ID packet request. * If A0 timing out is followed after ~64us by another 0x201 * write then an ID packet is triggered @@ -259,7 +259,7 @@ static void sw_a0_over(void *p) { sw_data *sw = (sw_data *)p; - timer_set_delay_u64(&sw->trigger_timer, TIMER_USEC * 10000); + timer_set_delay_u64(&sw->trigger_timer, TIMER_USEC * 10000); } const joystick_if_t joystick_sw_pad = @@ -273,7 +273,7 @@ const joystick_if_t joystick_sw_pad = sw_a0_over, 2, 10, - 0, + 0, 4, {"X axis", "Y axis"}, {"A", "B", "C", "X", "Y", "Z", "L", "R", "Start", "M"} diff --git a/src/include/86box/joystick_standard.h b/src/include/86box/joystick_standard.h index eb35c384b..9bc86b204 100644 --- a/src/include/86box/joystick_standard.h +++ b/src/include/86box/joystick_standard.h @@ -35,8 +35,10 @@ * USA. */ -extern const joystick_if_t joystick_standard; -extern const joystick_if_t joystick_standard_4button; +extern const joystick_if_t joystick_2axis_2button; +extern const joystick_if_t joystick_2axis_4button; +extern const joystick_if_t joystick_3axis_2button; +extern const joystick_if_t joystick_3axis_4button; extern const joystick_if_t joystick_4axis_4button; -extern const joystick_if_t joystick_standard_6button; -extern const joystick_if_t joystick_standard_8button; +extern const joystick_if_t joystick_2axis_6button; +extern const joystick_if_t joystick_2axis_8button;