From e09f5ad85c7fdd4132e485bdfa03989c26b9bb99 Mon Sep 17 00:00:00 2001 From: Alexander Babikov Date: Fri, 4 Dec 2020 21:45:09 +0500 Subject: [PATCH 1/3] Give the joystick types internal names --- src/game/gameport.c | 70 ++++++++++++++++++++++++------------ src/include/86box/gameport.h | 2 ++ 2 files changed, 50 insertions(+), 22 deletions(-) diff --git a/src/game/gameport.c b/src/game/gameport.c index 883af2388..dbb95f3ac 100644 --- a/src/game/gameport.c +++ b/src/game/gameport.c @@ -85,17 +85,20 @@ static const joystick_if_t joystick_none = { }; -static const joystick_if_t *joystick_list[] = { - &joystick_standard, - &joystick_standard_4button, - &joystick_standard_6button, - &joystick_standard_8button, - &joystick_4axis_4button, - &joystick_ch_flightstick_pro, - &joystick_sw_pad, - &joystick_tm_fcs, - &joystick_none, - NULL +static const struct { + const char *internal_name; + const joystick_if_t *joystick; +} joysticks[] = { + { "standard_2button", &joystick_standard }, + { "standard_4button", &joystick_standard_4button }, + { "standard_6button", &joystick_standard_6button }, + { "standard_8button", &joystick_standard_8button }, + { "4axis_4button", &joystick_4axis_4button }, + { "ch_flighstick_pro", &joystick_ch_flightstick_pro }, + { "sidewinder_pad", &joystick_sw_pad }, + { "thrustmaster_fcs", &joystick_tm_fcs }, + { "none", &joystick_none }, + { "", NULL } }; static gameport_t *gameport_global = NULL; @@ -103,58 +106,81 @@ static gameport_t *gameport_global = NULL; char * joystick_get_name(int js) { - if (! joystick_list[js]) + if (! joysticks[js].joystick) return(NULL); - return((char *)joystick_list[js]->name); + return((char *)joysticks[js].joystick->name); +} + + +char * +joystick_get_internal_name(int js) +{ + return((char *) joysticks[js].internal_name); +} + + +int +joystick_get_from_internal_name(char *s) +{ + int c = 0; + + while (strlen((char *) joysticks[c].internal_name)) + { + if (!strcmp((char *) joysticks[c].internal_name, s)) + return c; + c++; + } + + return JOYSTICK_TYPE_NONE; } int joystick_get_max_joysticks(int js) { - return(joystick_list[js]->max_joysticks); + return(joysticks[js].joystick->max_joysticks); } int joystick_get_axis_count(int js) { - return(joystick_list[js]->axis_count); + return(joysticks[js].joystick->axis_count); } int joystick_get_button_count(int js) { - return(joystick_list[js]->button_count); + return(joysticks[js].joystick->button_count); } int joystick_get_pov_count(int js) { - return(joystick_list[js]->pov_count); + return(joysticks[js].joystick->pov_count); } char * joystick_get_axis_name(int js, int id) { - return((char *)joystick_list[js]->axis_names[id]); + return((char *)joysticks[js].joystick->axis_names[id]); } char * joystick_get_button_name(int js, int id) { - return((char *)joystick_list[js]->button_names[id]); + return((char *)joysticks[js].joystick->button_names[id]); } char * joystick_get_pov_name(int js, int id) { - return (char *)joystick_list[js]->pov_names[id]; + return (char *)joysticks[js].joystick->pov_names[id]; } @@ -239,7 +265,7 @@ init_common(void) timer_add(&p->axis[2].timer, timer_over, &p->axis[2], 0); timer_add(&p->axis[3].timer, timer_over, &p->axis[3], 0); - p->joystick = joystick_list[joystick_type]; + p->joystick = joysticks[joystick_type].joystick; p->joystick_dat = p->joystick->init(); gameport_global = p; @@ -255,7 +281,7 @@ gameport_update_joystick_type(void) if (p != NULL) { p->joystick->close(p->joystick_dat); - p->joystick = joystick_list[joystick_type]; + p->joystick = joysticks[joystick_type].joystick; p->joystick_dat = p->joystick->init(); } } diff --git a/src/include/86box/gameport.h b/src/include/86box/gameport.h index a91a26232..731caf1a3 100644 --- a/src/include/86box/gameport.h +++ b/src/include/86box/gameport.h @@ -140,6 +140,8 @@ extern void joystick_close(void); extern void joystick_process(void); extern char *joystick_get_name(int js); +extern char *joystick_get_internal_name(int js); +extern int joystick_get_from_internal_name(char *s); extern int joystick_get_max_joysticks(int js); extern int joystick_get_axis_count(int js); extern int joystick_get_button_count(int js); From ddf85533aa27622c3b819b92bb50bbb43f9787a0 Mon Sep 17 00:00:00 2001 From: Alexander Babikov Date: Fri, 4 Dec 2020 21:45:14 +0500 Subject: [PATCH 2/3] Store the joystick type as a string in the config --- src/config.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/config.c b/src/config.c index a2aa1b19d..6efb4eb82 100644 --- a/src/config.c +++ b/src/config.c @@ -1,4 +1,4 @@ -/* +/* * 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 @@ -715,7 +715,19 @@ load_input_devices(void) else mouse_type = 0; - joystick_type = config_get_int(cat, "joystick_type", JOYSTICK_TYPE_NONE); + p = config_get_string(cat, "joystick_type", NULL); + if (p != NULL) { + joystick_type = joystick_get_from_internal_name(p); + if (joystick_type == JOYSTICK_TYPE_NONE) { + /* Try to read an integer for backwards compatibility with old configs */ + c = config_get_int(cat, "joystick_type", JOYSTICK_TYPE_NONE); + if ((c >= 0) && (c <= 8)) + joystick_type = c; + else + joystick_type = JOYSTICK_TYPE_NONE; + } + } else + joystick_type = JOYSTICK_TYPE_NONE; for (c=0; c Date: Fri, 4 Dec 2020 22:05:26 +0500 Subject: [PATCH 3/3] Move the "No joystick" option to the top and get rid of the JOYSTICK_TYPE_NONE macro --- src/config.c | 16 ++++++++-------- src/game/gameport.c | 12 ++++++------ src/include/86box/gameport.h | 1 - src/machine/m_amstrad.c | 2 +- src/machine/m_at.c | 2 +- src/machine/m_europc.c | 2 +- src/machine/m_ps1.c | 2 +- src/machine/m_tandy.c | 2 +- src/machine/m_xt.c | 2 +- src/machine/m_xt_compaq.c | 4 ++-- src/machine/m_xt_laserxt.c | 2 +- src/machine/m_xt_olivetti.c | 6 +++--- src/machine/m_xt_xi8088.c | 2 +- src/pc.c | 2 +- src/win/win_joystick.cpp | 2 +- src/win/win_joystick_xinput.c | 2 +- 16 files changed, 30 insertions(+), 31 deletions(-) diff --git a/src/config.c b/src/config.c index 6efb4eb82..29ecdf6bf 100644 --- a/src/config.c +++ b/src/config.c @@ -718,16 +718,17 @@ load_input_devices(void) p = config_get_string(cat, "joystick_type", NULL); if (p != NULL) { joystick_type = joystick_get_from_internal_name(p); - if (joystick_type == JOYSTICK_TYPE_NONE) { + if (!joystick_type) { /* Try to read an integer for backwards compatibility with old configs */ - c = config_get_int(cat, "joystick_type", JOYSTICK_TYPE_NONE); - if ((c >= 0) && (c <= 8)) - joystick_type = c; + c = config_get_int(cat, "joystick_type", 8); + if ((c >= 0) && (c < 8)) + /* "None" was type 8 instead of 0 previously, shift the number accordingly */ + joystick_type = c + 1; else - joystick_type = JOYSTICK_TYPE_NONE; + joystick_type = 0; } } else - joystick_type = JOYSTICK_TYPE_NONE; + joystick_type = 0; for (c=0; cmouse, 2); /* Configure the port for (Bus Mouse Compatible) Mouse. */ b |= 0x01; - } else if (joystick_type != JOYSTICK_TYPE_NONE) + } else if (joystick_type) b |= 0x02; /* enable port as joysticks */ sys->nvr.regs[MRTC_CONF_C] = b; diff --git a/src/machine/m_ps1.c b/src/machine/m_ps1.c index 539448c2e..ccad28139 100644 --- a/src/machine/m_ps1.c +++ b/src/machine/m_ps1.c @@ -517,7 +517,7 @@ ps1_common_init(const machine_t *model) device_add(&keyboard_ps2_ps1_device); /* Audio uses ports 200h and 202-207h, so only initialize gameport on 201h. */ - if (joystick_type != JOYSTICK_TYPE_NONE) + if (joystick_type) device_add(&gameport_201_device); } diff --git a/src/machine/m_tandy.c b/src/machine/m_tandy.c index f38f60767..470cd099c 100644 --- a/src/machine/m_tandy.c +++ b/src/machine/m_tandy.c @@ -1535,7 +1535,7 @@ machine_tandy1k_init(const machine_t *model, int type) break; } - if (joystick_type != JOYSTICK_TYPE_NONE) + if (joystick_type) device_add(&gameport_device); eep_data_out = 0x0000; diff --git a/src/machine/m_xt.c b/src/machine/m_xt.c index fbf3f0891..ad136f105 100644 --- a/src/machine/m_xt.c +++ b/src/machine/m_xt.c @@ -29,7 +29,7 @@ machine_xt_common_init(const machine_t *model) device_add(&fdc_xt_device); nmi_init(); - if (joystick_type != JOYSTICK_TYPE_NONE) + if (joystick_type) device_add(&gameport_device); } diff --git a/src/machine/m_xt_compaq.c b/src/machine/m_xt_compaq.c index da41a4a41..765c626b2 100644 --- a/src/machine/m_xt_compaq.c +++ b/src/machine/m_xt_compaq.c @@ -56,7 +56,7 @@ machine_xt_compaq_deskpro_init(const machine_t *model) if (fdc_type == FDC_INTERNAL) device_add(&fdc_xt_device); nmi_init(); - if (joystick_type != JOYSTICK_TYPE_NONE) + if (joystick_type) device_add(&gameport_device); lpt1_remove(); @@ -85,7 +85,7 @@ machine_xt_compaq_portable_init(const machine_t *model) if (fdc_type == FDC_INTERNAL) device_add(&fdc_xt_device); nmi_init(); - if (joystick_type != JOYSTICK_TYPE_NONE) + if (joystick_type) device_add(&gameport_device); lpt1_remove(); diff --git a/src/machine/m_xt_laserxt.c b/src/machine/m_xt_laserxt.c index d0b0fdf81..20c0e21ff 100644 --- a/src/machine/m_xt_laserxt.c +++ b/src/machine/m_xt_laserxt.c @@ -171,7 +171,7 @@ machine_xt_lxt3_init(const machine_t *model) device_add(&keyboard_xt_lxt3_device); device_add(&fdc_xt_device); nmi_init(); - if (joystick_type != JOYSTICK_TYPE_NONE) + if (joystick_type) device_add(&gameport_device); laserxt_init(1); diff --git a/src/machine/m_xt_olivetti.c b/src/machine/m_xt_olivetti.c index fec71f8ff..dae03edba 100644 --- a/src/machine/m_xt_olivetti.c +++ b/src/machine/m_xt_olivetti.c @@ -717,7 +717,7 @@ machine_xt_olim24_init(const machine_t *model) /* FIXME: make sure this is correct?? */ device_add(&at_nvr_device); - if (joystick_type != JOYSTICK_TYPE_NONE) + if (joystick_type) device_add(&gameport_device); nmi_init(); @@ -760,7 +760,7 @@ machine_xt_olim240_init(const machine_t *model) if (fdc_type == FDC_INTERNAL) device_add(&fdc_xt_device); - if (joystick_type != JOYSTICK_TYPE_NONE) + if (joystick_type) device_add(&gameport_device); nmi_init(); @@ -833,7 +833,7 @@ machine_xt_olim15_init(const machine_t *model) if (fdc_type == FDC_INTERNAL) device_add(&fdc_xt_device); - if (joystick_type != JOYSTICK_TYPE_NONE) + if (joystick_type) device_add(&gameport_device); nmi_init(); diff --git a/src/machine/m_xt_xi8088.c b/src/machine/m_xt_xi8088.c index 6944d1b3a..39fe5e2cf 100644 --- a/src/machine/m_xt_xi8088.c +++ b/src/machine/m_xt_xi8088.c @@ -177,7 +177,7 @@ machine_xt_xi8088_init(const machine_t *model) nmi_init(); device_add(&ibmat_nvr_device); pic2_init(); - if (joystick_type != JOYSTICK_TYPE_NONE) + if (joystick_type) device_add(&gameport_device); return ret; diff --git a/src/pc.c b/src/pc.c index 31586a4b3..bea9d3781 100644 --- a/src/pc.c +++ b/src/pc.c @@ -809,7 +809,7 @@ pc_reset_hard_init(void) /* Reset and reconfigure the Network Card layer. */ network_reset(); - if (joystick_type != JOYSTICK_TYPE_NONE) + if (joystick_type) gameport_update_joystick_type(); ui_sb_update_panes(); diff --git a/src/win/win_joystick.cpp b/src/win/win_joystick.cpp index 1f9de5ee6..2615092d3 100644 --- a/src/win/win_joystick.cpp +++ b/src/win/win_joystick.cpp @@ -263,7 +263,7 @@ void joystick_process(void) { int c, d; - if (joystick_type == JOYSTICK_TYPE_NONE) return; + if (!joystick_type) return; for (c = 0; c < joysticks_present; c++) { diff --git a/src/win/win_joystick_xinput.c b/src/win/win_joystick_xinput.c index 0e3f5fdce..4b7643c43 100644 --- a/src/win/win_joystick_xinput.c +++ b/src/win/win_joystick_xinput.c @@ -217,7 +217,7 @@ void joystick_process(void) { int c, d; - if (joystick_type == JOYSTICK_TYPE_NONE) return; + if (!joystick_type) return; joystick_poll();