refactoring for Wiz port; random cleanups
[libpicofe.git] / gp2x / emu.c
index 237105a..585c1d5 100644 (file)
@@ -16,7 +16,8 @@
 \r
 #include "emu.h"\r
 #include "gp2x.h"\r
-#include "menu.h"\r
+#include "soc.h"\r
+#include "../common/menu.h"\r
 #include "../common/arm_utils.h"\r
 #include "../common/fonts.h"\r
 #include "../common/emu.h"\r
@@ -40,8 +41,6 @@
 #endif\r
 \r
 \r
-int select_exits = 0;\r
-\r
 extern int crashed_940;\r
 \r
 static short __attribute__((aligned(4))) sndBuffer[2*44100/50];\r
@@ -145,19 +144,6 @@ void emu_prepareDefaultConfig(void)
        defaultConfig.Frameskip = -1; // auto\r
        defaultConfig.CPUclock = 200;\r
        defaultConfig.volume = 50;\r
-       defaultConfig.KeyBinds[ 0] = 1<<0; // SACB RLDU\r
-       defaultConfig.KeyBinds[ 4] = 1<<1;\r
-       defaultConfig.KeyBinds[ 2] = 1<<2;\r
-       defaultConfig.KeyBinds[ 6] = 1<<3;\r
-       defaultConfig.KeyBinds[14] = 1<<4;\r
-       defaultConfig.KeyBinds[13] = 1<<5;\r
-       defaultConfig.KeyBinds[12] = 1<<6;\r
-       defaultConfig.KeyBinds[ 8] = 1<<7;\r
-       defaultConfig.KeyBinds[15] = 1<<26; // switch rend\r
-       defaultConfig.KeyBinds[10] = 1<<27; // save state\r
-       defaultConfig.KeyBinds[11] = 1<<28; // load state\r
-       defaultConfig.KeyBinds[23] = 1<<29; // vol up\r
-       defaultConfig.KeyBinds[22] = 1<<30; // vol down\r
        defaultConfig.gamma = 100;\r
        defaultConfig.scaling = 0;\r
        defaultConfig.turbo_rate = 15;\r
@@ -415,7 +401,7 @@ static void emu_msg_tray_open(void)
        gettimeofday(&noticeMsgTime, 0);\r
 }\r
 \r
-static void RunEventsPico(unsigned int events, unsigned int gp2x_keys)\r
+static void RunEventsPico(unsigned int events)\r
 {\r
        int ret, px, py, lim_x;\r
        static int pdown_frames = 0;\r
@@ -449,11 +435,11 @@ static void RunEventsPico(unsigned int events, unsigned int gp2x_keys)
                //      PicoPicohw.pen_pos[0] = PicoPicohw.pen_pos[1] = 0x8000;\r
        }\r
 \r
+       if (PicoPad[0] & 1) pico_pen_y--;\r
+       if (PicoPad[0] & 2) pico_pen_y++;\r
+       if (PicoPad[0] & 4) pico_pen_x--;\r
+       if (PicoPad[0] & 8) pico_pen_x++;\r
        PicoPad[0] &= ~0x0f; // release UDLR\r
-       if (gp2x_keys & GP2X_UP)    pico_pen_y--;\r
-       if (gp2x_keys & GP2X_DOWN)  pico_pen_y++;\r
-       if (gp2x_keys & GP2X_LEFT)  pico_pen_x--;\r
-       if (gp2x_keys & GP2X_RIGHT) pico_pen_x++;\r
 \r
        lim_x = (Pico.video.reg[12]&1) ? 319 : 255;\r
        if (pico_pen_y < 8) pico_pen_y = 8;\r
@@ -507,15 +493,31 @@ static void RunEvents(unsigned int which)
        {\r
                int do_it = 1;\r
                if ( emu_checkSaveFile(state_slot) &&\r
-                               (( (which & 0x1000) && (currentConfig.EmuOpt & 0x800)) ||   // load\r
-                                (!(which & 0x1000) && (currentConfig.EmuOpt & 0x200))) ) { // save\r
-                       unsigned long keys;\r
-                       blit("", (which & 0x1000) ? "LOAD STATE? (Y=yes, X=no)" : "OVERWRITE SAVE? (Y=yes, X=no)");\r
-                       while ( !((keys = gp2x_joystick_read(1)) & (GP2X_X|GP2X_Y)) )\r
-                               usleep(50*1024);\r
-                       if (keys & GP2X_X) do_it = 0;\r
-                       while ( gp2x_joystick_read(1) & (GP2X_X|GP2X_Y) ) // wait for release\r
-                               usleep(50*1024);\r
+                               (( (which & 0x1000) && (currentConfig.EmuOpt & 0x800)) || // load\r
+                                (!(which & 0x1000) && (currentConfig.EmuOpt & 0x200))) ) // save\r
+               {\r
+                       const char *nm;\r
+                       char tmp[64];\r
+                       int keys, len;\r
+\r
+                       strcpy(tmp, (which & 0x1000) ? "LOAD STATE? " : "OVERWRITE SAVE? ");\r
+                       len = strlen(tmp);\r
+                       nm = in_get_key_name(-1, -PBTN_MA3);\r
+                       snprintf(tmp + len, sizeof(tmp) - len, "(%s=yes, ", nm);\r
+                       len = strlen(tmp);\r
+                       nm = in_get_key_name(-1, -PBTN_MBACK);\r
+                       snprintf(tmp + len, sizeof(tmp) - len, "%s=no)", nm);\r
+\r
+                       blit("", tmp);\r
+\r
+                       in_set_blocking(1);\r
+                       while (in_menu_wait_any(50) & (PBTN_MA3|PBTN_MBACK));   // wait for release\r
+                       while ( !((keys = in_menu_wait_any(50)) & (PBTN_MA3|PBTN_MBACK)) ); // .. press\r
+                       if (keys & PBTN_MBACK)\r
+                               do_it = 0;\r
+                       while (in_menu_wait_any(50) & (PBTN_MA3|PBTN_MBACK));   // .. release\r
+                       in_set_blocking(0);\r
+\r
                        clearArea(0);\r
                }\r
                if (do_it) {\r
@@ -544,7 +546,7 @@ static void RunEvents(unsigned int which)
                        strcpy(noticeMsg, " 8bit accurate renderer");\r
                }\r
 \r
-               gettimeofday(&noticeMsgTime, 0);\r
+               emu_noticeMsgUpdated();\r
        }\r
        if (which & 0x0300)\r
        {\r
@@ -556,7 +558,7 @@ static void RunEvents(unsigned int which)
                        if(state_slot > 9) state_slot = 0;\r
                }\r
                sprintf(noticeMsg, "SAVE SLOT %i [%s]", state_slot, emu_checkSaveFile(state_slot) ? "USED" : "FREE");\r
-               gettimeofday(&noticeMsgTime, 0);\r
+               emu_noticeMsgUpdated();\r
        }\r
        if (which & 0x0080) {\r
                engineState = PGS_Menu;\r
@@ -565,48 +567,11 @@ static void RunEvents(unsigned int which)
 \r
 static void updateKeys(void)\r
 {\r
-       unsigned int keys, keys2, allActions[2] = { 0, 0 }, events;\r
+       unsigned int allActions[2] = { 0, 0 }, events;\r
        static unsigned int prevEvents = 0;\r
 \r
-       keys = gp2x_joystick_read(0);\r
-       if (keys & GP2X_SELECT)\r
-               engineState = select_exits ? PGS_Quit : PGS_Menu;\r
-\r
-       keys &= CONFIGURABLE_KEYS;\r
-       keys2 = keys;\r
-\r
-#if 1\r
-       /* FIXME: combos, player2 */\r
+       /* FIXME: player2 */\r
        allActions[0] = in_update();\r
-#else\r
-       for (i = 0; i < 32; i++)\r
-       {\r
-               if (keys2 & (1 << i))\r
-               {\r
-                       int pl, acts = currentConfig.KeyBinds[i];\r
-                       if (!acts) continue;\r
-                       pl = (acts >> 16) & 1;\r
-                       if (kb_combo_keys & (1 << i))\r
-                       {\r
-                               int u = i+1, 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 ( (keys2 & (1 << u)) && (currentConfig.KeyBinds[u] & acts_c) ) {\r
-                                                       allActions[pl] |= acts_c & currentConfig.KeyBinds[u];\r
-                                                       keys2 &= ~((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 & ~kb_combo_acts;\r
-                       } else {\r
-                               allActions[pl] |= acts;\r
-                       }\r
-               }\r
-       }\r
-#endif\r
 \r
        PicoPad[0] = allActions[0] & 0xfff;\r
        PicoPad[1] = allActions[1] & 0xfff;\r
@@ -629,7 +594,7 @@ static void updateKeys(void)
        events &= ~prevEvents;\r
 \r
        if (PicoAHW == PAHW_PICO)\r
-               RunEventsPico(events, keys);\r
+               RunEventsPico(events);\r
        if (events) RunEvents(events);\r
        if (movie_data) emu_updateMovie();\r
 \r
@@ -834,7 +799,6 @@ void emu_Loop(void)
        scaling_update();\r
        Pico.m.dirtyPal = 1;\r
        oldmodes = ((Pico.video.reg[12]&1)<<2) ^ 0xc;\r
-       emu_findKeyBindCombos();\r
 \r
        // pal/ntsc might have changed, reset related stuff\r
        target_fps = Pico.m.pal ? 50 : 60;\r
@@ -1052,7 +1016,7 @@ const char *plat_get_credits(void)
                "Reesy & FluBBa: DrZ80 core\n"\r
                "MAME devs: YM2612 and SN76496 cores\n"\r
                "rlyeh and others: minimal SDK\n"\r
-               "Squidge: squidgehack\n"\r
+               "Squidge: mmuhack\n"\r
                "Dzz: ARM940 sample\n"\r
                "GnoStiC / Puck2099: USB joy code\n"\r
                "craigix: GP2X hardware\n"\r