From 3c0a7f75eee6c3524670676c30dd0f7daa239377 Mon Sep 17 00:00:00 2001 From: Toni Wilen Date: Sun, 21 May 2023 18:34:09 +0300 Subject: [PATCH] Game ports panel autofire fix --- inputdevice.cpp | 48 ++++++++++++++++++++++++++++-------------------- 1 file changed, 28 insertions(+), 20 deletions(-) diff --git a/inputdevice.cpp b/inputdevice.cpp index 0ee78de4..deec09b1 100644 --- a/inputdevice.cpp +++ b/inputdevice.cpp @@ -7224,41 +7224,42 @@ static void setjoyinputs (struct uae_prefs *prefs, int port) //write_log (_T("joyinput %d = %p\n"), port, joyinputs[port]); } -static void setautofire (struct uae_input_device *uid, int port, int af) +static void setautofire (struct uae_input_device *uid, int port, int sub, int af, bool set) { const int *afp = af_ports[port]; for (int k = 0; afp[k] >= 0; k++) { for (int i = 0; i < MAX_INPUT_DEVICE_EVENTS; i++) { for (int j = 0; j < MAX_INPUT_SUB_EVENT; j++) { if (uid->eventid[i][j] == afp[k]) { - uid->flags[i][j] &= ~ID_FLAG_AUTOFIRE_MASK; - if (af >= JPORT_AF_NORMAL) - uid->flags[i][j] |= ID_FLAG_AUTOFIRE; - if (af == JPORT_AF_TOGGLE) - uid->flags[i][j] |= ID_FLAG_TOGGLE; - if (af == JPORT_AF_ALWAYS) - uid->flags[i][j] |= ID_FLAG_INVERTTOGGLE; - if (af == JPORT_AF_TOGGLENOAF) - uid->flags[i][j] |= ID_FLAG_INVERT; + if (!set) { + uid->flags[i][j] &= ~ID_FLAG_AUTOFIRE_MASK; + } else { + if (af >= JPORT_AF_NORMAL) + uid->flags[i][j] |= ID_FLAG_AUTOFIRE; + if (af == JPORT_AF_TOGGLE) + uid->flags[i][j] |= ID_FLAG_TOGGLE; + if (af == JPORT_AF_ALWAYS) + uid->flags[i][j] |= ID_FLAG_INVERTTOGGLE; + if (af == JPORT_AF_TOGGLENOAF) + uid->flags[i][j] |= ID_FLAG_INVERT; + } } } } } } -static void setautofires (struct uae_prefs *prefs, int port, int sub, int af) +static void setautofires (struct uae_prefs *prefs, int port, int sub, int af, bool set) { #ifdef RETROPLATFORM // don't override custom AF autofire mappings if (rp_isactive()) return; #endif - if (JSEM_ISCUSTOM(port, sub, prefs)) - return; for (int l = 0; l < MAX_INPUT_DEVICES; l++) { - setautofire(&joysticks[l], port, af); - setautofire(&mice[l], port, af); - setautofire(&keyboards[l], port, af); + setautofire(&joysticks[l], port, sub, af, set); + setautofire(&mice[l], port, sub, af, set); + setautofire(&keyboards[l], port, sub, af, set); } } @@ -7611,11 +7612,18 @@ static void compatibility_copy (struct uae_prefs *prefs, bool gameports) for (int i = 0; i < MAX_JPORTS; i++) { for (int j = 0; j < MAX_JPORT_DEVS; j++) { - if (JSEM_ISCUSTOM(i, j, prefs)) { - inputdevice_parse_jport_custom(prefs, prefs->jports[i].jd[0].id - JSEM_CUSTOM, i, NULL); + if (!JSEM_ISCUSTOM(i, j, prefs) && gameports && prefs->jports[i].jd[j].id >= 0) { + setautofires(prefs, i, j, false, false); } - if (gameports) { - setautofires(prefs, i, j, prefs->jports[i].jd[j].autofire); + } + } + for (int i = 0; i < MAX_JPORTS; i++) { + for (int j = 0; j < MAX_JPORT_DEVS; j++) { + if (JSEM_ISCUSTOM(i, j, prefs)) { + inputdevice_parse_jport_custom(prefs, prefs->jports[i].jd[j].id - JSEM_CUSTOM, i, NULL); + } else if (gameports && prefs->jports[i].jd[j].id >= 0) { + // TODO: handle sub item autofire correctly + setautofires(prefs, i, j, prefs->jports[i].jd[j].autofire, true); } } } -- 2.47.3