bugfixes, refactoring
[libpicofe.git] / common / emu.c
index 936665b..02640bb 100644 (file)
@@ -41,6 +41,7 @@ char noticeMsg[64];
 int state_slot = 0;\r
 int config_slot = 0, config_slot_current = 0;\r
 char lastRomFile[512];\r
+int kb_combo_keys = 0, kb_combo_acts = 0;      // keys and actions which need button combos\r
 \r
 unsigned char *movie_data = NULL;\r
 static int movie_size = 0;\r
@@ -232,18 +233,20 @@ static int extract_text(char *dest, unsigned char *src, int len, int swab)
 char *emu_makeRomId(void)\r
 {\r
        static char id_string[3+0x11+0x11+0x30+16];\r
-       int pos;\r
+       int pos, swab = 1;\r
 \r
-       if (PicoMCD & 1)\r
-            strcpy(id_string, "CD|");\r
+       if (PicoMCD & 1) {\r
+               strcpy(id_string, "CD|");\r
+               swab = 0;\r
+       }\r
        else strcpy(id_string, "MD|");\r
        pos = 3;\r
 \r
-       pos += extract_text(id_string + pos, id_header + 0x80, 0x0e, 1); // serial\r
+       pos += extract_text(id_string + pos, id_header + 0x80, 0x0e, swab); // serial\r
        id_string[pos] = '|'; pos++;\r
-       pos += extract_text(id_string + pos, id_header + 0xf0, 0x03, 1); // region\r
+       pos += extract_text(id_string + pos, id_header + 0xf0, 0x03, swab); // region\r
        id_string[pos] = '|'; pos++;\r
-       pos += extract_text(id_string + pos, id_header + 0x50, 0x30, 1); // overseas name\r
+       pos += extract_text(id_string + pos, id_header + 0x50, 0x30, swab); // overseas name\r
        id_string[pos] = 0;\r
 \r
        return id_string;\r
@@ -328,6 +331,7 @@ int emu_ReloadRom(void)
        cd_state = emu_cdCheck(&cd_region);\r
        if (cd_state > 0)\r
        {\r
+               PicoMCD |= 1;\r
                // valid CD image, check for BIOS..\r
 \r
                // we need to have config loaded at this point\r
@@ -341,10 +345,10 @@ int emu_ReloadRom(void)
                }\r
                if (!emu_findBios(cd_region, &used_rom_name)) {\r
                        // bios_help() ?\r
+                       PicoMCD &= ~1;\r
                        return 0;\r
                }\r
 \r
-               PicoMCD |= 1;\r
                get_ext(used_rom_name, ext);\r
        }\r
        else\r
@@ -651,6 +655,47 @@ void emu_textOut16(int x, int y, const char *text)
        }\r
 }\r
 \r
+void emu_findKeyBindCombos(void)\r
+{\r
+       int act, u;\r
+\r
+       // find out which keys and actions are combos\r
+       kb_combo_keys = kb_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
+                                       kb_combo_keys |= 1 << u;\r
+                                       kb_combo_acts |= 1 << act;\r
+                               }\r
+                       }\r
+               }\r
+       }\r
+\r
+       // printf("combo keys/acts: %08x %08x\n", kb_combo_keys, kb_combo_acts);\r
+}\r
+\r
 \r
 void emu_updateMovie(void)\r
 {\r
@@ -876,3 +921,4 @@ int emu_SaveLoadGame(int load, int sram)
                return ret;\r
        }\r
 }\r
+\r