From 3a8b89af6334e696cd17cb03d8a4be6540a5a56a Mon Sep 17 00:00:00 2001 From: horkthane <37665479+horkthane@users.noreply.github.com> Date: Thu, 16 Jan 2020 19:23:54 -0500 Subject: [PATCH] Assorted Joystick fixes Implemented use of DirectInput sliders. They were previously lumped in with axis and then not read or used at all. Lots of use of joystick_type == 7 or joystick_type != 7 to detect if the joystick_type was none. Changed this to a define. The text to enumerate the types of joysticks was contained in a numbered LPARAM sheet. Switched to using the name listed in the joystick struct. Joysticks with more than 32 buttons would overflow the plat_joystick_state button array. Added overflow checks. Added a 4 axis 4 button joystick type that Win98 can pick up as a generic 4 axis 4 button controller. --- src/config.c | 6 +-- src/game/gameport.c | 5 ++- src/game/gameport.h | 10 +++++ src/game/joystick_standard.c | 37 +++++++++++++++ src/game/joystick_standard.h | 1 + src/machine/m_amstrad.c | 2 +- src/machine/m_at.c | 2 +- src/machine/m_europc.c | 2 +- src/machine/m_olivetti_m24.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 | 2 +- src/machine/m_xt_laserxt.c | 2 +- src/machine/m_xt_xi8088.c | 2 +- src/pc.c | 2 +- src/win/win_joystick.cpp | 79 ++++++++++++++++++++++----------- src/win/win_joystick_xinput.cpp | 2 +- src/win/win_jsconf.c | 29 +++++++++--- src/win/win_settings.c | 11 ++++- 20 files changed, 151 insertions(+), 51 deletions(-) diff --git a/src/config.c b/src/config.c index a174c2c89..f2b6076c1 100644 --- a/src/config.c +++ b/src/config.c @@ -607,7 +607,7 @@ load_input_devices(void) else mouse_type = 0; - joystick_type = config_get_int(cat, "joystick_type", 7); + joystick_type = config_get_int(cat, "joystick_type", JOYSTICK_TYPE_NONE); for (c=0; cmouse, 2); /* Configure the port for (Bus Mouse Compatible) Mouse. */ b |= 0x01; - } else if (joystick_type != 7) + } else if (joystick_type != JOYSTICK_TYPE_NONE) b |= 0x02; /* enable port as joysticks */ sys->nvr.regs[MRTC_CONF_C] = b; diff --git a/src/machine/m_olivetti_m24.c b/src/machine/m_olivetti_m24.c index 694fec24c..9bb84198f 100644 --- a/src/machine/m_olivetti_m24.c +++ b/src/machine/m_olivetti_m24.c @@ -892,7 +892,7 @@ machine_olim24_init(const machine_t *model) keyboard_set_table(scancode_xt); - if (joystick_type != 7) + if (joystick_type != JOYSTICK_TYPE_NONE) device_add(&gameport_device); /* FIXME: make sure this is correct?? */ diff --git a/src/machine/m_ps1.c b/src/machine/m_ps1.c index 30a610b8b..9ff547d45 100644 --- a/src/machine/m_ps1.c +++ b/src/machine/m_ps1.c @@ -525,7 +525,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 != 7) + if (joystick_type != JOYSTICK_TYPE_NONE) device_add(&gameport_201_device); } diff --git a/src/machine/m_tandy.c b/src/machine/m_tandy.c index 4a578d3b6..bbcf7786c 100644 --- a/src/machine/m_tandy.c +++ b/src/machine/m_tandy.c @@ -1527,7 +1527,7 @@ machine_tandy1k_init(const machine_t *model, int type) device_add(&eep_1000sl2_device); } - if (joystick_type != 7) + if (joystick_type != JOYSTICK_TYPE_NONE) device_add(&gameport_device); eep_data_out = 0x0000; diff --git a/src/machine/m_xt.c b/src/machine/m_xt.c index 0366517d1..c3bf07897 100644 --- a/src/machine/m_xt.c +++ b/src/machine/m_xt.c @@ -26,7 +26,7 @@ machine_xt_common_init(const machine_t *model) device_add(&fdc_xt_device); nmi_init(); - if (joystick_type != 7) + if (joystick_type != JOYSTICK_TYPE_NONE) device_add(&gameport_device); } diff --git a/src/machine/m_xt_compaq.c b/src/machine/m_xt_compaq.c index 6af9079fa..1e312fe10 100644 --- a/src/machine/m_xt_compaq.c +++ b/src/machine/m_xt_compaq.c @@ -55,7 +55,7 @@ machine_xt_compaq_init(const machine_t *model) device_add(&keyboard_xt_compaq_device); device_add(&fdc_xt_device); nmi_init(); - if (joystick_type != 7) + if (joystick_type != JOYSTICK_TYPE_NONE) device_add(&gameport_device); lpt1_remove(); diff --git a/src/machine/m_xt_laserxt.c b/src/machine/m_xt_laserxt.c index 0b06a238b..f8408952e 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 != 7) + if (joystick_type != JOYSTICK_TYPE_NONE) device_add(&gameport_device); laserxt_init(1); diff --git a/src/machine/m_xt_xi8088.c b/src/machine/m_xt_xi8088.c index 101e8a0ae..bd832e96c 100644 --- a/src/machine/m_xt_xi8088.c +++ b/src/machine/m_xt_xi8088.c @@ -175,7 +175,7 @@ machine_xt_xi8088_init(const machine_t *model) nmi_init(); device_add(&ibmat_nvr_device); pic2_init(); - if (joystick_type != 7) + if (joystick_type != JOYSTICK_TYPE_NONE) device_add(&gameport_device); return ret; diff --git a/src/pc.c b/src/pc.c index e2bb17f1a..c1218ac7a 100644 --- a/src/pc.c +++ b/src/pc.c @@ -767,7 +767,7 @@ pc_reset_hard_init(void) /* Reset and reconfigure the Network Card layer. */ network_reset(); - if (joystick_type != 7) + if (joystick_type != JOYSTICK_TYPE_NONE) gameport_update_joystick_type(); ui_sb_update_panes(); diff --git a/src/win/win_joystick.cpp b/src/win/win_joystick.cpp index d073cd37c..499f19903 100644 --- a/src/win/win_joystick.cpp +++ b/src/win/win_joystick.cpp @@ -82,37 +82,54 @@ BOOL CALLBACK DIEnumDeviceObjectsCallback( plat_joystick_t *state = (plat_joystick_t *)pvRef; if (lpddoi->guidType == GUID_XAxis || lpddoi->guidType == GUID_YAxis || lpddoi->guidType == GUID_ZAxis || - lpddoi->guidType == GUID_RxAxis || lpddoi->guidType == GUID_RyAxis || lpddoi->guidType == GUID_RzAxis || - lpddoi->guidType == GUID_Slider) + lpddoi->guidType == GUID_RxAxis || lpddoi->guidType == GUID_RyAxis || lpddoi->guidType == GUID_RzAxis) { - memcpy(state->axis[state->nr_axes].name, lpddoi->tszName, strlen(lpddoi->tszName) + 1); - joystick_log("Axis %i : %s %x %x\n", state->nr_axes, state->axis[state->nr_axes].name, lpddoi->dwOfs, lpddoi->dwType); - if (lpddoi->guidType == GUID_XAxis) - state->axis[state->nr_axes].id = 0; - else if (lpddoi->guidType == GUID_YAxis) - state->axis[state->nr_axes].id = 1; - else if (lpddoi->guidType == GUID_ZAxis) - state->axis[state->nr_axes].id = 2; - else if (lpddoi->guidType == GUID_RxAxis) - state->axis[state->nr_axes].id = 3; - else if (lpddoi->guidType == GUID_RyAxis) - state->axis[state->nr_axes].id = 4; - else if (lpddoi->guidType == GUID_RzAxis) - state->axis[state->nr_axes].id = 5; - state->nr_axes++; + if (state->nr_axes < 8) + {memcpy(state->axis[state->nr_axes].name, lpddoi->tszName, strlen(lpddoi->tszName) + 1); + joystick_log("Axis %i : %s %x %x\n", state->nr_axes, state->axis[state->nr_axes].name, lpddoi->dwOfs, lpddoi->dwType); + if (lpddoi->guidType == GUID_XAxis) + state->axis[state->nr_axes].id = 0; + else if (lpddoi->guidType == GUID_YAxis) + state->axis[state->nr_axes].id = 1; + else if (lpddoi->guidType == GUID_ZAxis) + state->axis[state->nr_axes].id = 2; + else if (lpddoi->guidType == GUID_RxAxis) + state->axis[state->nr_axes].id = 3; + else if (lpddoi->guidType == GUID_RyAxis) + state->axis[state->nr_axes].id = 4; + else if (lpddoi->guidType == GUID_RzAxis) + state->axis[state->nr_axes].id = 5; + state->nr_axes++; + } } else if (lpddoi->guidType == GUID_Button) { - memcpy(state->button[state->nr_buttons].name, lpddoi->tszName, strlen(lpddoi->tszName) + 1); - joystick_log("Button %i : %s %x %x\n", state->nr_buttons, state->button[state->nr_buttons].name, lpddoi->dwOfs, lpddoi->dwType); - state->nr_buttons++; + if (state->nr_buttons < 32) + { + memcpy(state->button[state->nr_buttons].name, lpddoi->tszName, strlen(lpddoi->tszName) + 1); + joystick_log("Button %i : %s %x %x\n", state->nr_buttons, state->button[state->nr_buttons].name, lpddoi->dwOfs, lpddoi->dwType); + state->nr_buttons++; + } } else if (lpddoi->guidType == GUID_POV) { - memcpy(state->pov[state->nr_povs].name, lpddoi->tszName, strlen(lpddoi->tszName) + 1); - joystick_log("POV %i : %s %x %x\n", state->nr_povs, state->pov[state->nr_povs].name, lpddoi->dwOfs, lpddoi->dwType); - state->nr_povs++; - } + if (state->nr_povs < 4) + { + memcpy(state->pov[state->nr_povs].name, lpddoi->tszName, strlen(lpddoi->tszName) + 1); + joystick_log("POV %i : %s %x %x\n", state->nr_povs, state->pov[state->nr_povs].name, lpddoi->dwOfs, lpddoi->dwType); + state->nr_povs++; + } + } + else if (lpddoi->guidType == GUID_Slider) + { + if (state->nr_sliders < 2) + { + memcpy(state->slider[state->nr_sliders].name, lpddoi->tszName, strlen(lpddoi->tszName) + 1); + state->slider[state->nr_sliders].id = state->nr_sliders | SLIDER; + joystick_log("Slider %i : %s %x %x\n", state->nr_sliders, state->slider[state->nr_sliders].name, lpddoi->dwOfs, lpddoi->dwType); + state->nr_sliders++; + } + } return DIENUM_CONTINUE; } @@ -187,7 +204,11 @@ void joystick_init() lpdi_joystick[c]->SetProperty(DIPROP_RANGE, &joy_axis_range.diph); joy_axis_range.diph.dwObj = DIJOFS_RZ; lpdi_joystick[c]->SetProperty(DIPROP_RANGE, &joy_axis_range.diph); - + joy_axis_range.diph.dwObj = DIJOFS_SLIDER(0); + lpdi_joystick[c]->SetProperty(DIPROP_RANGE, &joy_axis_range.diph); + joy_axis_range.diph.dwObj = DIJOFS_SLIDER(1); + lpdi_joystick[c]->SetProperty(DIPROP_RANGE, &joy_axis_range.diph); + if (FAILED(lpdi_joystick[c]->Acquire())) fatal("joystick_init : Acquire failed\n"); } @@ -226,6 +247,10 @@ static int joystick_get_axis(int joystick_nr, int mapping) return 0; else return -cos((2*M_PI * (double)pov) / 36000.0) * 32767; + } + else if (mapping & SLIDER) + { + return plat_joystick_state[joystick_nr].s[mapping & 3]; } else return plat_joystick_state[joystick_nr].a[plat_joystick_state[joystick_nr].axis[mapping].id]; @@ -235,7 +260,7 @@ void joystick_process(void) { int c, d; - if (joystick_type == 7) return; + if (joystick_type == JOYSTICK_TYPE_NONE) return; for (c = 0; c < joysticks_present; c++) { @@ -260,6 +285,8 @@ void joystick_process(void) plat_joystick_state[c].a[3] = joystate.lRx; plat_joystick_state[c].a[4] = joystate.lRy; plat_joystick_state[c].a[5] = joystate.lRz; + plat_joystick_state[c].s[0] = joystate.rglSlider[0]; + plat_joystick_state[c].s[1] = joystate.rglSlider[1]; for (b = 0; b < 16; b++) plat_joystick_state[c].b[b] = joystate.rgbButtons[b] & 0x80; diff --git a/src/win/win_joystick_xinput.cpp b/src/win/win_joystick_xinput.cpp index 6be292c13..237cab23c 100644 --- a/src/win/win_joystick_xinput.cpp +++ b/src/win/win_joystick_xinput.cpp @@ -216,7 +216,7 @@ void joystick_process(void) { int c, d; - if (joystick_type == 7) return; + if (joystick_type == JOYSTICK_TYPE_NONE) return; joystick_poll(); diff --git a/src/win/win_jsconf.c b/src/win/win_jsconf.c index 1ca6f5ef8..0d7474f59 100644 --- a/src/win/win_jsconf.c +++ b/src/win/win_jsconf.c @@ -58,6 +58,10 @@ static void rebuild_axis_button_selections(HWND hdlg) SendMessage(h, CB_ADDSTRING, 0, (LPARAM)(LPCSTR)s); sprintf(s, "%s (Y axis)", plat_joystick_state[joystick-1].pov[d].name); SendMessage(h, CB_ADDSTRING, 0, (LPARAM)(LPCSTR)s); + } + for (d = 0; d < plat_joystick_state[joystick - 1].nr_sliders; d++) + { + SendMessage(h, CB_ADDSTRING, 0, (LPARAM)(LPCSTR)plat_joystick_state[joystick - 1].slider[d].name); } SendMessage(h, CB_SETCURSEL, sel, 0); EnableWindow(h, TRUE); @@ -122,15 +126,23 @@ static int get_axis(HWND hdlg, int id) HWND h = GetDlgItem(hdlg, id); int axis_sel = SendMessage(h, CB_GETCURSEL, 0, 0); int nr_axes = plat_joystick_state[joystick_state[joystick_nr].plat_joystick_nr-1].nr_axes; - + int nr_povs = plat_joystick_state[joystick_state[joystick_nr].plat_joystick_nr - 1].nr_povs; + int nr_sliders = plat_joystick_state[joystick_state[joystick_nr].plat_joystick_nr - 1].nr_sliders; + if (axis_sel < nr_axes) return axis_sel; axis_sel -= nr_axes; - if (axis_sel & 1) - return POV_Y | (axis_sel >> 1); - else - return POV_X | (axis_sel >> 1); + if (axis_sel < nr_povs * 2) + { + if (axis_sel & 1) + return POV_Y | (axis_sel >> 1); + else + return POV_X | (axis_sel >> 1); + } + axis_sel -= nr_povs; + + return SLIDER | (axis_sel >> 1); } static int get_pov(HWND hdlg, int id) @@ -163,6 +175,7 @@ joystickconfig_dlgproc(HWND hdlg, UINT message, WPARAM wParam, LPARAM lParam) int joystick; int nr_axes; int nr_povs; + int nr_sliders; int mapping; switch (message) @@ -186,6 +199,8 @@ joystickconfig_dlgproc(HWND hdlg, UINT message, WPARAM wParam, LPARAM lParam) { nr_axes = plat_joystick_state[joystick-1].nr_axes; nr_povs = plat_joystick_state[joystick-1].nr_povs; + nr_sliders = plat_joystick_state[joystick - 1].nr_sliders; + for (c = 0; c < joystick_get_axis_count(joystick_config_type); c++) { int mapping = joystick_state[joystick_nr].axis_mapping[c]; @@ -195,7 +210,9 @@ joystickconfig_dlgproc(HWND hdlg, UINT message, WPARAM wParam, LPARAM lParam) SendMessage(h, CB_SETCURSEL, nr_axes + (mapping & 3)*2, 0); else if (mapping & POV_Y) SendMessage(h, CB_SETCURSEL, nr_axes + (mapping & 3)*2 + 1, 0); - else + else if (mapping & SLIDER) + SendMessage(h, CB_SETCURSEL, nr_axes + nr_povs * 2 + (mapping & 3), 0); + else SendMessage(h, CB_SETCURSEL, mapping, 0); id += 2; } diff --git a/src/win/win_settings.c b/src/win/win_settings.c index f72ee200d..69f054acd 100644 --- a/src/win/win_settings.c +++ b/src/win/win_settings.c @@ -971,6 +971,7 @@ static BOOL CALLBACK win_settings_input_proc(HWND hdlg, UINT message, WPARAM wParam, LPARAM lParam) { wchar_t str[128]; + char *joy_name; HWND h; int c, d; @@ -1000,9 +1001,15 @@ win_settings_input_proc(HWND hdlg, UINT message, WPARAM wParam, LPARAM lParam) h = GetDlgItem(hdlg, IDC_COMBO_JOYSTICK); c = 0; - while (joystick_get_name(c)) { - SendMessage(h, CB_ADDSTRING, 0, win_get_string(2105 + c)); + joy_name = joystick_get_name(c); + while (joy_name) + { + mbstowcs(str, joy_name, strlen(joy_name) + 1); + SendMessage(h, CB_ADDSTRING, 0, (LPARAM)str); + + // SendMessage(h, CB_ADDSTRING, 0, win_get_string(2105 + c)); c++; + joy_name = joystick_get_name(c); } EnableWindow(h, TRUE); SendMessage(h, CB_SETCURSEL, temp_joystick, 0);