bugfixes, refactoring
[libpicofe.git] / gp2x / emu.c
index 74bcde8..0375a7f 100644 (file)
@@ -48,7 +48,6 @@ extern int crashed_940;
 static short __attribute__((aligned(4))) sndBuffer[2*44100/50];\r
 static struct timeval noticeMsgTime = { 0, 0 };        // when started showing\r
 static int osd_fps_x;\r
-static int combo_keys = 0, combo_acts = 0;     // keys and actions which need button combos\r
 static int gp2x_old_gamma = 100;\r
 char noticeMsg[64];                    // notice msg to draw\r
 unsigned char *PicoDraw2FB = NULL;  // temporary buffer for alt renderer\r
@@ -98,48 +97,6 @@ void emu_Init(void)
 }\r
 \r
 \r
-static void find_combos(void)\r
-{\r
-       int act, u;\r
-\r
-       // find out which keys and actions are combos\r
-       combo_keys = combo_acts = 0;\r
-       for (act = 0; act < 32; act++)\r
-       {\r
-               int keyc = 0, keyc2 = 0;\r
-               if (act == 16 || act == 17) continue; // player2 flag\r
-               if (act > 17)\r
-               {\r
-                       for (u = 0; u < 32; u++)\r
-                               if (currentConfig.KeyBinds[u] & (1 << act)) keyc++;\r
-               }\r
-               else\r
-               {\r
-                       for (u = 0; u < 32; u++)\r
-                               if ((currentConfig.KeyBinds[u] & 0x30000) == 0 && // pl. 1\r
-                                       (currentConfig.KeyBinds[u] & (1 << act))) keyc++;\r
-                       for (u = 0; u < 32; u++)\r
-                               if ((currentConfig.KeyBinds[u] & 0x30000) == 1 && // pl. 2\r
-                                       (currentConfig.KeyBinds[u] & (1 << act))) keyc2++;\r
-                       if (keyc2 > keyc) keyc = keyc2;\r
-               }\r
-               if (keyc > 1)\r
-               {\r
-                       // loop again and mark those keys and actions as combo\r
-                       for (u = 0; u < 32; u++)\r
-                       {\r
-                               if (currentConfig.KeyBinds[u] & (1 << act)) {\r
-                                       combo_keys |= 1 << u;\r
-                                       combo_acts |= 1 << act;\r
-                               }\r
-                       }\r
-               }\r
-       }\r
-\r
-       // printf("combo keys/acts: %08x %08x\n", combo_keys, combo_acts);\r
-}\r
-\r
-\r
 static void scaling_update(void)\r
 {\r
        PicoOpt &= ~0x4100;\r
@@ -577,23 +534,26 @@ static void updateKeys(void)
 \r
        for (i = 0; i < 32; i++)\r
        {\r
-               if (keys & (1 << i)) {\r
+               if (keys & (1 << i))\r
+               {\r
                        int pl, acts = currentConfig.KeyBinds[i];\r
                        if (!acts) continue;\r
                        pl = (acts >> 16) & 1;\r
-                       if (combo_keys & (1 << i)) {\r
-                               int u = i+1, acts_c = acts & combo_acts;\r
+                       if (kb_combo_keys & (1 << i))\r
+                       {\r
+                               int u, acts_c = acts & kb_combo_acts;\r
                                // let's try to find the other one\r
-                               if (acts_c)\r
-                                       for (; u < 32; u++)\r
-                                               if ( (currentConfig.KeyBinds[u] & acts_c) && (keys & (1 << u)) ) {\r
-                                                       allActions[pl] |= acts_c;\r
+                               if (acts_c) {\r
+                                       for (u = i + 1; u < 32; u++)\r
+                                               if ( (keys & (1 << u)) && (currentConfig.KeyBinds[u] & acts_c) ) {\r
+                                                       allActions[pl] |= acts_c & currentConfig.KeyBinds[u];\r
                                                        keys &= ~((1 << i) | (1 << u));\r
                                                        break;\r
                                                }\r
+                               }\r
                                // add non-combo actions if combo ones were not found\r
                                if (!acts_c || u == 32)\r
-                                       allActions[pl] |= acts & ~combo_acts;\r
+                                       allActions[pl] |= acts & ~kb_combo_acts;\r
                        } else {\r
                                allActions[pl] |= acts;\r
                        }\r
@@ -740,7 +700,7 @@ void emu_Loop(void)
        scaling_update();\r
        Pico.m.dirtyPal = 1;\r
        oldmodes = ((Pico.video.reg[12]&1)<<2) ^ 0xc;\r
-       find_combos();\r
+       emu_findKeyBindCombos();\r
 \r
        // pal/ntsc might have changed, reset related stuff\r
        target_fps = Pico.m.pal ? 50 : 60;\r