gp2x->common menu migration finished, gp2x now only uses input fwk
[libpicofe.git] / gp2x / emu.c
index 003f173..69a464e 100644 (file)
@@ -16,7 +16,7 @@
 \r
 #include "emu.h"\r
 #include "gp2x.h"\r
-#include "menu.h"\r
+#include "../common/menu.h"\r
 #include "../common/arm_utils.h"\r
 #include "../common/fonts.h"\r
 #include "../common/emu.h"\r
@@ -145,19 +145,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 +402,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 +436,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 +494,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 +547,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 +559,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,16 +568,9 @@ 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
        /* FIXME: player2 */\r
        allActions[0] = in_update();\r
 \r
@@ -599,7 +595,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