]> git.unchartedbackwaters.co.uk Git - francis/winuae.git/commitdiff
Game ports panel autofire fix
authorToni Wilen <twilen@winuae.net>
Sun, 21 May 2023 15:34:09 +0000 (18:34 +0300)
committerToni Wilen <twilen@winuae.net>
Sun, 21 May 2023 15:34:09 +0000 (18:34 +0300)
inputdevice.cpp

index 0ee78de4c41e13d74b98b10e0f2f22d261e03321..deec09b1f50fafdc27ab14340e33ff548379c707 100644 (file)
@@ -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);
                        }
                }
        }