continuing input framework integration
authornotaz <notasas@gmail.com>
Sat, 3 Jan 2009 18:53:35 +0000 (18:53 +0000)
committernotaz <notasas@gmail.com>
Sat, 3 Jan 2009 18:53:35 +0000 (18:53 +0000)
git-svn-id: file:///home/notaz/opt/svn/PicoDrive/platform@631 be3aeb3a-fb24-0410-a615-afba39da0efa

13 files changed:
common/common.h
common/config.c
common/input.c
common/input.h
common/menu.c
gp2x/emu.c
gp2x/menu.c
gp2x/version.h
pandora/Makefile
pandora/emu.c
pandora/main.c
pandora/pandora.c
psp/menu.c

index 6a49bf5..fc657b3 100644 (file)
 #define PBTN_L     GP2X_L
 #define PBTN_R     GP2X_R
 
-int wait_for_input(int interesting);
+/* menu nav */
+#define PBTN_MOK   GP2X_B
+#define PBTN_MBACK GP2X_X
+#define PBTN_MENU  GP2X_SELECT
+
 void gp2x_pd_clone_buffer2(void);
 void menu_darken_bg(void *dst, int pixels, int darker);
 void menu_flip(void);
@@ -24,10 +28,6 @@ void menu_flip(void);
 #define SCREEN_HEIGHT 240
 #define SCREEN_BUFFER gp2x_screen
 
-#define read_buttons(which) \
-       wait_for_input(which)
-#define read_buttons_async(which) \
-       (gp2x_joystick_read(0) & (which))
 #define menu_draw_begin() \
        gp2x_pd_clone_buffer2()
 #define clear_screen() \
@@ -48,7 +48,6 @@ void menu_flip(void);
 #define PBTN_WEST  PBTN_REW
 #define PBTN_EAST  PBTN_FWD
 
-unsigned long wait_for_input(unsigned int interesting);
 void menu_draw_begin(int use_bgbuff);
 void menu_darken_bg(void *dst, const void *src, int pixels, int darker);
 void menu_draw_end(void);
@@ -59,9 +58,6 @@ void menu_draw_end(void);
 extern void *menu_screen;
 extern void *giz_screen;
 
-#define read_buttons(which) \
-       wait_for_input(which)
-#define read_buttons_async(which) 0
 #define menu_draw_begin() \
        menu_draw_begin(1)
 #define clear_screen() \
@@ -80,7 +76,6 @@ extern void *giz_screen;
 #define PBTN_WEST  PBTN_SQUARE
 #define PBTN_EAST  PBTN_CIRCLE
 
-unsigned long wait_for_input(unsigned int interesting, int is_key_config);
 void menu_draw_begin(void);
 void menu_darken_bg(void *dst, const void *src, int pixels, int darker);
 void menu_draw_end(void);
@@ -89,10 +84,6 @@ void menu_draw_end(void);
 #define SCREEN_HEIGHT 272
 #define SCREEN_BUFFER psp_screen
 
-#define read_buttons(which) \
-       wait_for_input(which, 0)
-#define read_buttons_async(which) \
-       (psp_pad_read(0) & (which))
 #define clear_screen() \
        memset(SCREEN_BUFFER, 0, SCREEN_WIDTH*SCREEN_HEIGHT*2)
 #define darken_screen() \
@@ -102,10 +93,6 @@ void menu_draw_end(void);
 
 #elif defined(PANDORA)
 
-// TODO
-
-#include "../gp2x/gp2x.h"
-
 #define PBTN_UP    (1 <<  0)
 #define PBTN_DOWN  (1 <<  1)
 #define PBTN_LEFT  (1 <<  2)
@@ -118,19 +105,21 @@ void menu_draw_end(void);
 #define PBTN_L     (1 <<  8)
 #define PBTN_R     (1 <<  9)
 
-unsigned long wait_for_input(unsigned long interesting);
+/* menu nav */
+#define PBTN_MOK   PBTN_EAST
+#define PBTN_MBACK PBTN_SOUTH
+#define PBTN_MENU  (1 << 10)
+
 void gp2x_pd_clone_buffer2(void);
 void menu_darken_bg(void *dst, int pixels, int darker);
 void menu_flip(void);
 
+extern void *gp2x_screen;
+
 #define SCREEN_WIDTH  800
 #define SCREEN_HEIGHT 480
 #define SCREEN_BUFFER gp2x_screen
 
-#define read_buttons(which) \
-       wait_for_input(which)
-#define read_buttons_async(which) \
-       (gp2x_joystick_read(0) & (which))
 #define menu_draw_begin() \
        gp2x_pd_clone_buffer2()
 #define clear_screen() \
index 9e7b1a7..63c8f00 100644 (file)
@@ -209,16 +209,6 @@ static void custom_write(FILE *f, const menu_entry *me, int no_def)
 }
 
 
-#if PLAT_HAVE_JOY
-static const char *joyKeyNames[32] =
-{
-       "UP", "DOWN", "LEFT", "RIGHT", "b1", "b2", "b3", "b4",
-       "b5",  "b6",  "b7",  "b8",  "b9",  "b10", "b11", "b12",
-       "b13", "b14", "b15", "b16", "b17", "b19", "b19", "b20",
-       "b21", "b22", "b23", "b24", "b25", "b26", "b27", "b28"
-};
-#endif
-
 static void keys_write(FILE *fn, const char *bind_str, int dev_id, const int *binds, int no_defaults)
 {
        char act[48];
@@ -401,7 +391,7 @@ write:
        for (t = 0; t < IN_MAX_DEVS; t++)
        {
                const int  *binds = in_get_dev_binds(t);
-               const char *name =  in_get_dev_name(t);
+               const char *name =  in_get_dev_name(t, 0);
                if (binds == NULL || name == NULL)
                        continue;
 
@@ -412,7 +402,7 @@ write:
        for (t = 0; t < IN_MAX_DEVS; t++)
        {
                const int *binds = in_get_dev_binds(t);
-               const char *name = in_get_dev_name(t);
+               const char *name = in_get_dev_name(t, 0);
                char strbind[16];
                int count;
 
@@ -426,17 +416,6 @@ write:
                keys_write(fn, strbind, t, binds, no_defaults);
        }
 
-#if 0
-       /* old stuff */
-       keys_write(fn, "bind", currentConfig.KeyBinds, defaultConfig.KeyBinds, keyNames, PLAT_MAX_KEYS, no_defaults);
-#if PLAT_HAVE_JOY
-       keys_write(fn, "bind_joy0", currentConfig.JoyBinds[0], defaultConfig.JoyBinds[0], joyKeyNames, 32, 1);
-       keys_write(fn, "bind_joy1", currentConfig.JoyBinds[1], defaultConfig.JoyBinds[1], joyKeyNames, 32, 1);
-       keys_write(fn, "bind_joy2", currentConfig.JoyBinds[2], defaultConfig.JoyBinds[2], joyKeyNames, 32, 1);
-       keys_write(fn, "bind_joy3", currentConfig.JoyBinds[3], defaultConfig.JoyBinds[3], joyKeyNames, 32, 1);
-#endif
-#endif
-
 #ifndef PSP
        if (section == NULL)
                fprintf(fn, "Sound Volume = %i" NL, currentConfig.volume);
@@ -771,42 +750,6 @@ static void keys_parse(const char *key, const char *val, int dev_id)
        }
 
        in_config_bind_key(dev_id, key, binds);
-/*
-       for (t = 0; t < 32; t++)
-       {
-               if (names[t] && strcmp(names[t], var) == 0) break;
-       }
-       if (t == 32)
-       {
-               int len = strlen(var);
-               if (len == 1) t = var[0];
-               else if (len >= 4 && var[0] == '\\' && var[1] == 'x') {
-                       char *p;
-                       t = (int)strtoul(var + 2, &p, 16);
-                       if (*p != 0) t = max_keys; // parse failed
-               }
-               else
-                       t = max_keys; // invalid
-       }
-       if (t < 0 || t >= max_keys) {
-               lprintf("unhandled bind \"%s\"\n", var);
-               return;
-       }
-
-       // unbind old, but only when key is first encountered
-       if (t < 32 && binds == currentConfig.KeyBinds && !(keys_encountered & (1<<t))) {
-               binds[t] = 0;
-               keys_encountered |= 1<<t;
-       }
-*/
-}
-
-
-#define try_joy_parse(num) { \
-       if (strncasecmp(var, "bind_joy"#num " ", 10) == 0) { \
-               keys_parse(var + 10, val, currentConfig.JoyBinds[num], joyKeyNames, 32); \
-               return; \
-       } \
 }
 
 static int get_numvar_num(const char *var)
@@ -846,7 +789,7 @@ static void parse(const char *var, const char *val)
                if (num >= 0 && num < IN_MAX_DEVS)
                        input_dev_map[num] = in_config_parse_dev(val);
                else
-                       printf("failed to parse: %s\n", var);
+                       lprintf("config: failed to parse: %s\n", var);
                return;
        }
 
@@ -855,13 +798,13 @@ static void parse(const char *var, const char *val)
                const char *p = var + 4;
                int num = get_numvar_num(p);
                if (num < 0 || num >= IN_MAX_DEVS) {
-                       printf("failed to parse: %s\n", var);
+                       lprintf("config: failed to parse: %s\n", var);
                        return;
                }
 
                num = input_dev_map[num];
                if (num < 0 || num >= IN_MAX_DEVS) {
-                       printf("invalid device id: %s\n", var);
+                       lprintf("config: invalid device id: %s\n", var);
                        return;
                }
 
@@ -871,13 +814,6 @@ static void parse(const char *var, const char *val)
                return;
        }
 
-#if 0//PLAT_HAVE_JOY
-       try_joy_parse(0)
-       try_joy_parse(1)
-       try_joy_parse(2)
-       try_joy_parse(3)
-#endif
-
        for (t = 0; t < sizeof(cfg_opts) / sizeof(cfg_opts[0]) && ret == 0; t++)
        {
                me = cfg_opts[t];
index 0f850ec..8262e21 100644 (file)
@@ -2,6 +2,7 @@
 #include <stdlib.h>
 #include <string.h>
 
+#include "common.h"
 #include "input.h"
 #include "../linux/in_evdev.h"
 
@@ -195,7 +196,7 @@ void in_set_blocking(int is_blocking)
 
        menu_key_state = 0;
        /* flush events */
-       in_update_keycode(NULL, NULL, 1);
+       in_update_keycode(NULL, NULL, 0);
 }
 
 /* 
@@ -204,7 +205,7 @@ void in_set_blocking(int is_blocking)
  */
 int in_update_keycode(int *dev_id_out, int *is_down_out, int timeout_ms)
 {
-       int result = 0, dev_id, is_down, result_menu;
+       int result = 0, dev_id = 0, is_down, result_menu;
 #ifdef IN_EVDEV
        void **data;
        int i, id = 0, count = 0;
@@ -229,7 +230,7 @@ int in_update_keycode(int *dev_id_out, int *is_down_out, int timeout_ms)
 #endif
 
        /* keep track of menu key state, to allow mixing
-        * in_update_keycode() and in_update_menu() calls */
+        * in_update_keycode() and in_menu_wait_any() calls */
        result_menu = DRV(in_devices[dev_id].drv_id).menu_translate(result);
        if (result_menu != 0) {
                if (is_down)
@@ -245,10 +246,8 @@ int in_update_keycode(int *dev_id_out, int *is_down_out, int timeout_ms)
        return result;
 }
 
-/* 
- * same as above, only return bitfield of BTN_*
- */
-int in_update_menu(int timeout_ms)
+/* same as above, only return bitfield of PBTN_*  */
+int in_menu_wait_any(int timeout_ms)
 {
        int keys_old = menu_key_state;
 
@@ -259,7 +258,7 @@ int in_update_menu(int timeout_ms)
                code = in_update_keycode(&dev_id, &is_down, timeout_ms);
                code = DRV(in_devices[dev_id].drv_id).menu_translate(code);
 
-               if (timeout_ms != 0)
+               if (timeout_ms >= 0)
                        break;
                if (code == 0)
                        continue;
@@ -270,6 +269,45 @@ int in_update_menu(int timeout_ms)
        return menu_key_state;
 }
 
+/* wait for menu input, do autorepeat */
+int in_menu_wait(int interesting)
+{
+       static int inp_prev = 0;
+       static int repeats = 0, wait = 20;
+       int ret = 0, release = 0, i;
+
+       if      (repeats == 2) wait = 3;
+       else if (repeats == 4) wait = 2;
+       else if (repeats == 6) wait = 1;
+
+       for (i = 0; i < wait; i++) {
+               ret = in_menu_wait_any(30);
+               if (ret != inp_prev) break;
+               if (i == 0) repeats++;
+       }
+
+       while (!(ret & interesting)) {
+               ret = in_menu_wait_any(-1);
+               release = 1;
+       }
+
+       if (release || ret != inp_prev) {
+               repeats = 0;
+               wait = 20;
+       }
+       if (wait > 6 && (ret & (PBTN_UP|PBTN_DOWN|PBTN_LEFT|PBTN_RIGHT)))
+               wait = 6;
+       inp_prev = ret;
+
+       // we don't need diagonals in menus
+       if ((ret & PBTN_UP)   && (ret & PBTN_LEFT))  ret &= ~PBTN_LEFT;
+       if ((ret & PBTN_UP)   && (ret & PBTN_RIGHT)) ret &= ~PBTN_RIGHT;
+       if ((ret & PBTN_DOWN) && (ret & PBTN_LEFT))  ret &= ~PBTN_LEFT;
+       if ((ret & PBTN_DOWN) && (ret & PBTN_RIGHT)) ret &= ~PBTN_RIGHT;
+
+       return ret;
+}
+
 const int *in_get_dev_binds(int dev_id)
 {
        if (dev_id < 0 || dev_id >= IN_MAX_DEVS)
@@ -297,11 +335,13 @@ int in_get_dev_bind_count(int dev_id)
        return in_bind_count(in_devices[dev_id].drv_id);
 }
 
-const char *in_get_dev_name(int dev_id)
+const char *in_get_dev_name(int dev_id, int must_be_active)
 {
        if (dev_id < 0 || dev_id >= IN_MAX_DEVS)
                return NULL;
 
+       if (must_be_active && !in_devices[dev_id].probed)
+               return NULL;
        return in_devices[dev_id].name;
 }
 
@@ -580,7 +620,7 @@ int main(void)
        }
 #else
        while (1) {
-               ret = in_update_menu();
+               ret = in_menu_wait_any();
                printf("%08x\n", ret);
        }
 #endif
index 4b8784c..8a1cdea 100644 (file)
@@ -28,7 +28,8 @@ void in_probe(void);
 int  in_update(void);
 void in_set_blocking(int is_blocking);
 int  in_update_keycode(int *dev_id, int *is_down, int timeout_ms);
-int  in_update_menu(int timeout_ms);
+int  in_menu_wait_any(int timeout_ms);
+int  in_menu_wait(int interesting);
 int  in_get_dev_bind_count(int dev_id);
 void in_config_start(void);
 int  in_config_parse_dev(const char *dev_name);
@@ -39,5 +40,5 @@ void in_debug_dump(void);
 
 const int  *in_get_dev_binds(int dev_id);
 const int  *in_get_dev_def_binds(int dev_id);
-const char *in_get_dev_name(int dev_id);
+const char *in_get_dev_name(int dev_id, int must_be_active);
 const char *in_get_key_name(int dev_id, int keycode);
index 611cee9..c3ef87f 100644 (file)
@@ -13,6 +13,7 @@
 #include "readpng.h"\r
 #include "lprintf.h"\r
 #include "common.h"\r
+#include "input.h"\r
 #include "emu.h"\r
 \r
 \r
@@ -350,7 +351,7 @@ static void mplayer_loop(void)
        while (1)\r
        {\r
                PDebugZ80Frame();\r
-               if (read_buttons_async(PBTN_NORTH)) break;\r
+               if (in_menu_wait_any(0) & PBTN_NORTH) break;\r
                emu_waitSound();\r
        }\r
 \r
@@ -429,8 +430,8 @@ void debug_menu_loop(void)
                }\r
                menu_draw_end();\r
 \r
-               inp = read_buttons(PBTN_EAST|PBTN_SOUTH|PBTN_WEST|PBTN_NORTH|PBTN_L|PBTN_R|PBTN_UP|PBTN_DOWN|PBTN_LEFT|PBTN_RIGHT);\r
-               if (inp & PBTN_SOUTH) return;\r
+               inp = in_menu_wait(PBTN_EAST|PBTN_MBACK|PBTN_WEST|PBTN_NORTH|PBTN_L|PBTN_R|PBTN_UP|PBTN_DOWN|PBTN_LEFT|PBTN_RIGHT);\r
+               if (inp & PBTN_MBACK) return;\r
                if (inp & PBTN_L) { mode--; if (mode < 0) mode = 3; }\r
                if (inp & PBTN_R) { mode++; if (mode > 3) mode = 0; }\r
                switch (mode)\r
@@ -438,13 +439,13 @@ void debug_menu_loop(void)
                        case 0:\r
                                if (inp & PBTN_EAST) SekStepM68k();\r
                                if (inp & PBTN_NORTH) {\r
-                                       while (inp & PBTN_NORTH) inp = read_buttons_async(PBTN_NORTH);\r
+                                       while (inp & PBTN_NORTH) inp = in_menu_wait_any(-1);\r
                                        mplayer_loop();\r
                                }\r
                                if ((inp & (PBTN_WEST|PBTN_LEFT)) == (PBTN_WEST|PBTN_LEFT)) {\r
                                        mkdir("dumps", 0777);\r
                                        PDebugDumpMem();\r
-                                       while (inp & PBTN_WEST) inp = read_buttons_async(PBTN_WEST);\r
+                                       while (inp & PBTN_WEST) inp = in_menu_wait_any(-1);\r
                                        dumped = 1;\r
                                }\r
                                break;\r
@@ -458,7 +459,7 @@ void debug_menu_loop(void)
                                        PicoSkipFrame = 1;\r
                                        PicoFrame();\r
                                        PicoSkipFrame = 0;\r
-                                       while (inp & PBTN_EAST) inp = read_buttons_async(PBTN_EAST);\r
+                                       while (inp & PBTN_EAST) inp = in_menu_wait_any(-1);\r
                                }\r
                                break;\r
                        case 3:\r
index a19329d..b9079a9 100644 (file)
@@ -582,12 +582,8 @@ static void updateKeys(void)
        keys2 = keys;\r
 \r
 #if 1\r
-       {\r
-               /* FIXME: combos */\r
-               int acts = in_update();\r
-               int pl = (acts >> 16) & 1;\r
-               allActions[pl] |= acts;\r
-       }\r
+       /* FIXME: combos, player2 */\r
+       allActions[0] = in_update();\r
 #else\r
        for (i = 0; i < 32; i++)\r
        {\r
index 0b3187c..94d1183 100644 (file)
@@ -42,45 +42,6 @@ const char * const keyNames[] = {
 void menu_darken_bg(void *dst, int pixels, int darker);\r
 static void menu_prepare_bg(int use_game_bg);\r
 \r
-/* wait for input, do autorepeat */\r
-int wait_for_input(int interesting)\r
-{\r
-       static int inp_prev = 0;\r
-       static int repeats = 0, wait = 20;\r
-       int ret, release = 0, i;\r
-\r
-       if      (repeats == 2) wait = 3;\r
-       else if (repeats == 4) wait = 2;\r
-       else if (repeats == 6) wait = 1;\r
-\r
-       for (i = 0; i < wait; i++) {\r
-               ret = in_update_menu(30);\r
-               if (ret != inp_prev) break;\r
-               if (i == 0) repeats++;\r
-       }\r
-\r
-       while (!(ret & interesting)) {\r
-               ret = in_update_menu(0);\r
-               release = 1;\r
-       }\r
-\r
-       if (release || ret != inp_prev) {\r
-               repeats = 0;\r
-               wait = 20;\r
-       }\r
-       if (wait > 6 && (ret & (PBTN_UP|PBTN_DOWN|PBTN_LEFT|PBTN_RIGHT)))\r
-               wait = 6;\r
-       inp_prev = ret;\r
-\r
-       // we don't need diagonals in menus\r
-       if ((ret & PBTN_UP)   && (ret & PBTN_LEFT))  ret &= ~PBTN_LEFT;\r
-       if ((ret & PBTN_UP)   && (ret & PBTN_RIGHT)) ret &= ~PBTN_RIGHT;\r
-       if ((ret & PBTN_DOWN) && (ret & PBTN_LEFT))  ret &= ~PBTN_LEFT;\r
-       if ((ret & PBTN_DOWN) && (ret & PBTN_RIGHT)) ret &= ~PBTN_RIGHT;\r
-\r
-       return ret;\r
-}\r
-\r
 void menu_flip(void)\r
 {\r
        gp2x_video_flush_cache();\r
@@ -247,8 +208,8 @@ static void do_delete(const char *fpath, const char *fname)
        menu_flip();\r
 \r
 \r
-       while (gp2x_joystick_read(1) & (GP2X_A|GP2X_SELECT)) usleep(50*1000);\r
-       inp = wait_for_input(GP2X_Y|GP2X_X);\r
+       while (in_menu_wait_any(50) & (PBTN_WEST|PBTN_MENU));\r
+       inp = in_menu_wait(GP2X_Y|PBTN_MBACK);  /* FIXME */\r
        if (inp & GP2X_Y)\r
                remove(fpath);\r
 }\r
@@ -298,14 +259,14 @@ rescan:
        for (;;)\r
        {\r
                draw_dirlist(curr_path, namelist, n, sel);\r
-               inp = wait_for_input(GP2X_UP|GP2X_DOWN|GP2X_LEFT|GP2X_RIGHT|GP2X_L|GP2X_R|GP2X_A|GP2X_B|GP2X_X|GP2X_SELECT);\r
-               if(inp & GP2X_UP  )  { sel--;   if (sel < 0)   sel = n-2; }\r
-               if(inp & GP2X_DOWN)  { sel++;   if (sel > n-2) sel = 0; }\r
-               if(inp & GP2X_LEFT)  { sel-=10; if (sel < 0)   sel = 0; }\r
-               if(inp & GP2X_L)     { sel-=24; if (sel < 0)   sel = 0; }\r
-               if(inp & GP2X_RIGHT) { sel+=10; if (sel > n-2) sel = n-2; }\r
-               if(inp & GP2X_R)     { sel+=24; if (sel > n-2) sel = n-2; }\r
-               if ((inp & GP2X_B) || (inp & (GP2X_SELECT|GP2X_A)) == (GP2X_SELECT|GP2X_A)) // enter dir/select || delete\r
+               inp = in_menu_wait(PBTN_UP|PBTN_DOWN|PBTN_LEFT|PBTN_RIGHT|PBTN_L|PBTN_R|PBTN_WEST|PBTN_MOK|PBTN_MBACK|PBTN_MENU);\r
+               if(inp & PBTN_UP  )  { sel--;   if (sel < 0)   sel = n-2; }\r
+               if(inp & PBTN_DOWN)  { sel++;   if (sel > n-2) sel = 0; }\r
+               if(inp & PBTN_LEFT)  { sel-=10; if (sel < 0)   sel = 0; }\r
+               if(inp & PBTN_L)     { sel-=24; if (sel < 0)   sel = 0; }\r
+               if(inp & PBTN_RIGHT) { sel+=10; if (sel > n-2) sel = n-2; }\r
+               if(inp & PBTN_R)     { sel+=24; if (sel > n-2) sel = n-2; }\r
+               if ((inp & PBTN_MOK) || (inp & (PBTN_MENU|PBTN_WEST)) == (PBTN_MENU|PBTN_WEST)) // enter dir/select || delete\r
                {\r
                        again:\r
                        if (namelist[sel+1]->d_type == DT_REG)\r
@@ -313,7 +274,7 @@ rescan:
                                strcpy(romFileName, curr_path);\r
                                strcat(romFileName, "/");\r
                                strcat(romFileName, namelist[sel+1]->d_name);\r
-                               if (inp & GP2X_B) { // return sel\r
+                               if (inp & PBTN_MOK) { // return sel\r
                                        ret = romFileName;\r
                                        break;\r
                                }\r
@@ -328,7 +289,7 @@ rescan:
                        {\r
                                int newlen;\r
                                char *p, *newdir;\r
-                               if (!(inp & GP2X_B)) continue;\r
+                               if (!(inp & PBTN_MOK)) continue;\r
                                newlen = strlen(curr_path) + strlen(namelist[sel+1]->d_name) + 2;\r
                                newdir = malloc(newlen);\r
                                if (strcmp(namelist[sel+1]->d_name, "..") == 0) {\r
@@ -367,7 +328,7 @@ rescan:
                                }\r
                        }\r
                }\r
-               if(inp & GP2X_X) break; // cancel\r
+               if(inp & PBTN_MBACK) break; // cancel\r
        }\r
 \r
        if (n > 0) {\r
@@ -412,17 +373,17 @@ static void patches_menu_loop(void)
        for(;;)\r
        {\r
                draw_patchlist(menu_sel);\r
-               inp = wait_for_input(GP2X_UP|GP2X_DOWN|GP2X_LEFT|GP2X_RIGHT|GP2X_L|GP2X_R|GP2X_B|GP2X_X);\r
-               if(inp & GP2X_UP  ) { menu_sel--; if (menu_sel < 0) menu_sel = PicoPatchCount; }\r
-               if(inp & GP2X_DOWN) { menu_sel++; if (menu_sel > PicoPatchCount) menu_sel = 0; }\r
-               if(inp &(GP2X_LEFT|GP2X_L))  { menu_sel-=10; if (menu_sel < 0) menu_sel = 0; }\r
-               if(inp &(GP2X_RIGHT|GP2X_R)) { menu_sel+=10; if (menu_sel > PicoPatchCount) menu_sel = PicoPatchCount; }\r
-               if(inp & GP2X_B) { // action\r
+               inp = in_menu_wait(PBTN_UP|PBTN_DOWN|PBTN_LEFT|PBTN_RIGHT|PBTN_L|PBTN_R|PBTN_MOK|PBTN_MBACK);\r
+               if(inp & PBTN_UP  ) { menu_sel--; if (menu_sel < 0) menu_sel = PicoPatchCount; }\r
+               if(inp & PBTN_DOWN) { menu_sel++; if (menu_sel > PicoPatchCount) menu_sel = 0; }\r
+               if(inp &(PBTN_LEFT|PBTN_L))  { menu_sel-=10; if (menu_sel < 0) menu_sel = 0; }\r
+               if(inp &(PBTN_RIGHT|PBTN_R)) { menu_sel+=10; if (menu_sel > PicoPatchCount) menu_sel = PicoPatchCount; }\r
+               if(inp & PBTN_MOK) { // action\r
                        if (menu_sel < PicoPatchCount)\r
                                PicoPatches[menu_sel].active = !PicoPatches[menu_sel].active;\r
                        else    return;\r
                }\r
-               if(inp & GP2X_X) return;\r
+               if(inp & PBTN_MBACK) return;\r
        }\r
 \r
 }\r
@@ -532,18 +493,18 @@ static int savestate_menu_loop(int is_loading)
        for(;;)\r
        {\r
                draw_savestate_menu(menu_sel, is_loading);\r
-               inp = wait_for_input(GP2X_UP|GP2X_DOWN|GP2X_B|GP2X_X);\r
-               if(inp & GP2X_UP  ) {\r
+               inp = in_menu_wait(PBTN_UP|PBTN_DOWN|PBTN_MOK|PBTN_MBACK);\r
+               if(inp & PBTN_UP  ) {\r
                        do {\r
                                menu_sel--; if (menu_sel < 0) menu_sel = menu_sel_max;\r
                        } while (!(state_slot_flags & (1 << menu_sel)) && menu_sel != menu_sel_max && is_loading);\r
                }\r
-               if(inp & GP2X_DOWN) {\r
+               if(inp & PBTN_DOWN) {\r
                        do {\r
                                menu_sel++; if (menu_sel > menu_sel_max) menu_sel = 0;\r
                        } while (!(state_slot_flags & (1 << menu_sel)) && menu_sel != menu_sel_max && is_loading);\r
                }\r
-               if(inp & GP2X_B) { // save/load\r
+               if(inp & PBTN_MOK) { // save/load\r
                        if (menu_sel < 10) {\r
                                state_slot = menu_sel;\r
                                if (emu_SaveLoadGame(is_loading, 0)) {\r
@@ -553,26 +514,12 @@ static int savestate_menu_loop(int is_loading)
                                return 0;\r
                        } else  return 1;\r
                }\r
-               if(inp & GP2X_X) return 1;\r
+               if(inp & PBTN_MBACK) return 1;\r
        }\r
 }\r
 \r
 // -------------- key config --------------\r
 \r
-static char *usb_joy_key_name(int joy, int num)\r
-{\r
-       static char name[16];\r
-       switch (num)\r
-       {\r
-               case 0: sprintf(name, "Joy%i UP", joy); break;\r
-               case 1: sprintf(name, "Joy%i DOWN", joy); break;\r
-               case 2: sprintf(name, "Joy%i LEFT", joy); break;\r
-               case 3: sprintf(name, "Joy%i RIGHT", joy); break;\r
-               default:sprintf(name, "Joy%i b%i", joy, num-3); break;\r
-       }\r
-       return name;\r
-}\r
-\r
 static char *action_binds(int player_idx, int action_mask)\r
 {\r
        static char strkeys[32];\r
@@ -609,33 +556,6 @@ static char *action_binds(int player_idx, int action_mask)
                        d_prev = d;\r
                }\r
        }\r
-#if 0\r
-       for (i = 0; i < 32; i++) // i is key index\r
-       {\r
-               if (currentConfig.KeyBinds[i] & action_mask)\r
-               {\r
-                       if (player_idx >= 0 && ((currentConfig.KeyBinds[i] >> 16) & 3) != player_idx) continue;\r
-                       if (strkeys[0]) { strcat(strkeys, " + "); strcat(strkeys, keyNames[i]); break; }\r
-                       else strcpy(strkeys, keyNames[i]);\r
-               }\r
-       }\r
-       for (joy = 0; joy < num_of_joys; joy++)\r
-       {\r
-               for (i = 0; i < 32; i++)\r
-               {\r
-                       if (currentConfig.JoyBinds[joy][i] & action_mask)\r
-                       {\r
-                               if (player_idx >= 0 && ((currentConfig.JoyBinds[joy][i] >> 16) & 3) != player_idx) continue;\r
-                               if (strkeys[0]) {\r
-                                       strcat(strkeys, ", "); strcat(strkeys, usb_joy_key_name(joy + 1, i));\r
-                                       break;\r
-                               }\r
-                               else strcpy(strkeys, usb_joy_key_name(joy + 1, i));\r
-                       }\r
-               }\r
-       }\r
-#endif\r
-\r
 \r
        // limit..\r
        strkeys[20] = 0;\r
@@ -737,25 +657,25 @@ static void key_config_loop(const me_bind_action *opts, int opt_cnt, int player_
        for (;;)\r
        {\r
                draw_key_config(opts, opt_cnt, player_idx, sel, 0);\r
-               mkey = wait_for_input(PBTN_UP|PBTN_DOWN|PBTN_SOUTH|PBTN_EAST);\r
+               mkey = in_menu_wait(PBTN_UP|PBTN_DOWN|PBTN_MBACK|PBTN_MOK);\r
                switch (mkey) {\r
                        case PBTN_UP:   sel--; if (sel < 0) sel = menu_sel_max; continue;\r
                        case PBTN_DOWN: sel++; if (sel > menu_sel_max) sel = 0; continue;\r
-                       case PBTN_SOUTH:\r
-                               if (sel >= opt_cnt)\r
-                                       return;\r
-                               continue;\r
-                       case PBTN_EAST:\r
+                       case PBTN_MBACK: return;\r
+                       case PBTN_MOK:\r
                                if (sel >= opt_cnt)\r
                                        return;\r
+                               while (in_menu_wait_any(30) & PBTN_MOK);\r
                                break;\r
                        default:continue;\r
                }\r
 \r
                draw_key_config(opts, opt_cnt, player_idx, sel, 1);\r
-               //inp = wait_for_input_usbjoy(CONFIGURABLE_KEYS, &joy);\r
-               for (is_down = 0; is_down == 0; )\r
-                       kc = in_update_keycode(&dev_id, &is_down, 0);\r
+\r
+               /* wait for some up event */\r
+               for (is_down = 1; is_down; ) {\r
+                       kc = in_update_keycode(&dev_id, &is_down, -1);\r
+               }\r
 \r
                unbind = count_bound_keys(dev_id, opts[sel].mask, player_idx) >= 2;\r
 \r
@@ -795,14 +715,16 @@ static void draw_kc_sel(int menu_sel)
        me_draw(ctrlopt_entries, ctrlopt_entry_count, tl_x, tl_y, NULL, NULL);\r
 \r
        tl_x = 25;\r
-       text_out16(tl_x, (y=130), "USB joys detected:");\r
-       if (num_of_joys > 0) {\r
-               for (i = 0; i < num_of_joys; i++) {\r
-                       strncpy(joyname, joy_name(joys[i]), 33); joyname[33] = 0;\r
-                       text_out16(tl_x, (y+=10), "%i: %s", i+1, joyname);\r
-               }\r
-       } else {\r
-               text_out16(tl_x, (y+=10), "none");\r
+       text_out16(tl_x, (y=130), "Input devices:");\r
+       for (i = 0; i < IN_MAX_DEVS && y < 230; i++) {\r
+               const char *tmp, *name = in_get_dev_name(i, 1);\r
+               if (name == NULL)\r
+                       continue;\r
+               tmp = strchr(name, ':');\r
+               if (tmp != NULL)\r
+                       name = tmp + 1;\r
+               strncpy(joyname, name, 33); joyname[33] = 0;\r
+               text_out16(tl_x, (y+=10), "%i: %s", i, joyname);\r
        }\r
 \r
        menu_flip();\r
@@ -839,13 +761,13 @@ static void kc_sel_loop(void)
        while (1)\r
        {\r
                draw_kc_sel(menu_sel);\r
-               inp = wait_for_input(GP2X_UP|GP2X_DOWN|GP2X_RIGHT|GP2X_LEFT|GP2X_B|GP2X_X);\r
+               inp = in_menu_wait(PBTN_UP|PBTN_DOWN|PBTN_RIGHT|PBTN_LEFT|PBTN_MOK|PBTN_MBACK);\r
                selected_id = me_index2id(ctrlopt_entries, CTRLOPT_ENTRY_COUNT, menu_sel);\r
-               if (inp & (GP2X_LEFT|GP2X_RIGHT)) // multi choise\r
-                       me_process(ctrlopt_entries, CTRLOPT_ENTRY_COUNT, selected_id, (inp&GP2X_RIGHT) ? 1 : 0);\r
-               if (inp & GP2X_UP  ) { menu_sel--; if (menu_sel < 0) menu_sel = menu_sel_max; }\r
-               if (inp & GP2X_DOWN) { menu_sel++; if (menu_sel > menu_sel_max) menu_sel = 0; }\r
-               if (inp & GP2X_B) {\r
+               if (inp & (PBTN_LEFT|PBTN_RIGHT)) // multi choise\r
+                       me_process(ctrlopt_entries, CTRLOPT_ENTRY_COUNT, selected_id, (inp&PBTN_RIGHT) ? 1 : 0);\r
+               if (inp & PBTN_UP  ) { menu_sel--; if (menu_sel < 0) menu_sel = menu_sel_max; }\r
+               if (inp & PBTN_DOWN) { menu_sel++; if (menu_sel > menu_sel_max) menu_sel = 0; }\r
+               if (inp & PBTN_MOK) {\r
                        int is_6button = PicoOpt & POPT_6BTN_PAD;\r
                        switch (selected_id) {\r
                                case MA_CTRL_PLAYER1: key_config_loop(me_ctrl_actions, is_6button ? 15 : 11, 0); return;\r
@@ -856,7 +778,7 @@ static void kc_sel_loop(void)
                                default: return;\r
                        }\r
                }\r
-               if (inp & GP2X_X) return;\r
+               if (inp & PBTN_MBACK) return;\r
        }\r
 }\r
 \r
@@ -957,14 +879,14 @@ static void cd_menu_loop_options(void)
        for(;;)\r
        {\r
                draw_cd_menu_options(menu_sel, &bios_names);\r
-               inp = wait_for_input(GP2X_UP|GP2X_DOWN|GP2X_LEFT|GP2X_RIGHT|GP2X_B|GP2X_X|GP2X_A|GP2X_START);\r
-               if (inp & GP2X_UP  ) { menu_sel--; if (menu_sel < 0) menu_sel = menu_sel_max; }\r
-               if (inp & GP2X_DOWN) { menu_sel++; if (menu_sel > menu_sel_max) menu_sel = 0; }\r
+               inp = in_menu_wait(PBTN_UP|PBTN_DOWN|PBTN_LEFT|PBTN_RIGHT|PBTN_MOK|PBTN_MBACK|GP2X_START); /* FIXME */\r
+               if (inp & PBTN_UP  ) { menu_sel--; if (menu_sel < 0) menu_sel = menu_sel_max; }\r
+               if (inp & PBTN_DOWN) { menu_sel++; if (menu_sel > menu_sel_max) menu_sel = 0; }\r
                selected_id = me_index2id(cdopt_entries, CDOPT_ENTRY_COUNT, menu_sel);\r
-               if (inp & (GP2X_LEFT|GP2X_RIGHT)) { // multi choise\r
-                       if (!me_process(cdopt_entries, CDOPT_ENTRY_COUNT, selected_id, (inp&GP2X_RIGHT) ? 1 : 0) &&\r
+               if (inp & (PBTN_LEFT|PBTN_RIGHT)) { // multi choise\r
+                       if (!me_process(cdopt_entries, CDOPT_ENTRY_COUNT, selected_id, (inp&PBTN_RIGHT) ? 1 : 0) &&\r
                            selected_id == MA_CDOPT_READAHEAD) {\r
-                               if (inp & GP2X_LEFT) {\r
+                               if (inp & PBTN_LEFT) {\r
                                        PicoCDBuffers >>= 1;\r
                                        if (PicoCDBuffers < 2) PicoCDBuffers = 0;\r
                                } else {\r
@@ -974,7 +896,7 @@ static void cd_menu_loop_options(void)
                                }\r
                        }\r
                }\r
-               if (inp & GP2X_B) { // toggleable options\r
+               if (inp & PBTN_MOK) { // toggleable options\r
                        if (!me_process(cdopt_entries, CDOPT_ENTRY_COUNT, selected_id, 1) &&\r
                            selected_id == MA_CDOPT_DONE) {\r
                                return;\r
@@ -1007,7 +929,7 @@ static void cd_menu_loop_options(void)
                                        break;\r
                        }\r
                }\r
-               if (inp & (GP2X_X|GP2X_A)) return;\r
+               if (inp & PBTN_MBACK) return;\r
        }\r
 }\r
 \r
@@ -1071,29 +993,28 @@ static void amenu_loop_options(void)
        for(;;)\r
        {\r
                draw_amenu_options(menu_sel);\r
-               inp = wait_for_input(GP2X_UP|GP2X_DOWN|GP2X_LEFT|GP2X_RIGHT|GP2X_B|GP2X_X|GP2X_A);\r
-               if (inp & GP2X_UP  ) { menu_sel--; if (menu_sel < 0) menu_sel = menu_sel_max; }\r
-               if (inp & GP2X_DOWN) { menu_sel++; if (menu_sel > menu_sel_max) menu_sel = 0; }\r
+               inp = in_menu_wait(PBTN_UP|PBTN_DOWN|PBTN_LEFT|PBTN_RIGHT|PBTN_MOK|PBTN_MBACK);\r
+               if (inp & PBTN_UP  ) { menu_sel--; if (menu_sel < 0) menu_sel = menu_sel_max; }\r
+               if (inp & PBTN_DOWN) { menu_sel++; if (menu_sel > menu_sel_max) menu_sel = 0; }\r
                selected_id = me_index2id(opt2_entries, OPT2_ENTRY_COUNT, menu_sel);\r
-               if (inp & (GP2X_LEFT|GP2X_RIGHT)) { // multi choise\r
-                       if (!me_process(opt2_entries, OPT2_ENTRY_COUNT, selected_id, (inp&GP2X_RIGHT) ? 1 : 0) &&\r
+               if (inp & (PBTN_LEFT|PBTN_RIGHT)) { // multi choise\r
+                       if (!me_process(opt2_entries, OPT2_ENTRY_COUNT, selected_id, (inp&PBTN_RIGHT) ? 1 : 0) &&\r
                            selected_id == MA_OPT2_GAMMA) {\r
-                               while ((inp = gp2x_joystick_read(1)) & (GP2X_LEFT|GP2X_RIGHT)) {\r
-                                       currentConfig.gamma += (inp & GP2X_LEFT) ? -1 : 1;\r
+                               while ((inp = in_menu_wait_any(20)) & (PBTN_LEFT|PBTN_RIGHT)) {\r
+                                       currentConfig.gamma += (inp & PBTN_LEFT) ? -1 : 1;\r
                                        if (currentConfig.gamma <   1) currentConfig.gamma =   1;\r
                                        if (currentConfig.gamma > 300) currentConfig.gamma = 300;\r
                                        draw_amenu_options(menu_sel);\r
-                                       usleep(18*1000);\r
                                }\r
                        }\r
                }\r
-               if (inp & GP2X_B) { // toggleable options\r
+               if (inp & PBTN_MOK) { // toggleable options\r
                        if (!me_process(opt2_entries, OPT2_ENTRY_COUNT, selected_id, 1) &&\r
                            selected_id == MA_OPT2_DONE) {\r
                                return;\r
                        }\r
                }\r
-               if (inp & (GP2X_X|GP2X_A)) return;\r
+               if (inp & PBTN_MBACK) return;\r
        }\r
 }\r
 \r
@@ -1268,15 +1189,15 @@ static int menu_loop_options(void)
        while (1)\r
        {\r
                draw_menu_options(menu_sel);\r
-               inp = wait_for_input(GP2X_UP|GP2X_DOWN|GP2X_LEFT|GP2X_RIGHT|GP2X_B|GP2X_X|GP2X_A);\r
-               if (inp & GP2X_UP  ) { menu_sel--; if (menu_sel < 0) menu_sel = menu_sel_max; }\r
-               if (inp & GP2X_DOWN) { menu_sel++; if (menu_sel > menu_sel_max) menu_sel = 0; }\r
+               inp = in_menu_wait(PBTN_UP|PBTN_DOWN|PBTN_LEFT|PBTN_RIGHT|PBTN_MOK|PBTN_MBACK);\r
+               if (inp & PBTN_UP  ) { menu_sel--; if (menu_sel < 0) menu_sel = menu_sel_max; }\r
+               if (inp & PBTN_DOWN) { menu_sel++; if (menu_sel > menu_sel_max) menu_sel = 0; }\r
                selected_id = me_index2id(opt_entries, OPT_ENTRY_COUNT, menu_sel);\r
-               if (inp & (GP2X_LEFT|GP2X_RIGHT)) { // multi choice\r
-                       if (!me_process(opt_entries, OPT_ENTRY_COUNT, selected_id, (inp&GP2X_RIGHT) ? 1 : 0)) {\r
+               if (inp & (PBTN_LEFT|PBTN_RIGHT)) { // multi choice\r
+                       if (!me_process(opt_entries, OPT_ENTRY_COUNT, selected_id, (inp&PBTN_RIGHT) ? 1 : 0)) {\r
                                switch (selected_id) {\r
                                        case MA_OPT_RENDERER:\r
-                                               if (inp & GP2X_LEFT) {\r
+                                               if (inp & PBTN_LEFT) {\r
                                                        if      (PicoOpt&0x10) PicoOpt&= ~0x10;\r
                                                        else if (!(currentConfig.EmuOpt &0x80))currentConfig.EmuOpt |=  0x80;\r
                                                        else if (  currentConfig.EmuOpt &0x80) break;\r
@@ -1287,18 +1208,18 @@ static int menu_loop_options(void)
                                                }\r
                                                break;\r
                                        case MA_OPT_SOUND_QUALITY:\r
-                                               if ((inp & GP2X_RIGHT) && PsndRate == 44100 && !(PicoOpt&0x08)) {\r
+                                               if ((inp & PBTN_RIGHT) && PsndRate == 44100 && !(PicoOpt&0x08)) {\r
                                                        PsndRate = 8000; PicoOpt|= 0x08;\r
-                                               } else if ((inp & GP2X_LEFT) && PsndRate == 8000 && (PicoOpt&0x08)) {\r
+                                               } else if ((inp & PBTN_LEFT) && PsndRate == 8000 && (PicoOpt&0x08)) {\r
                                                        PsndRate = 44100; PicoOpt&=~0x08;\r
-                                               } else  PsndRate = sndrate_prevnext(PsndRate, inp & GP2X_RIGHT);\r
+                                               } else  PsndRate = sndrate_prevnext(PsndRate, inp & PBTN_RIGHT);\r
                                                break;\r
                                        case MA_OPT_REGION:\r
-                                               region_prevnext(inp & GP2X_RIGHT);\r
+                                               region_prevnext(inp & PBTN_RIGHT);\r
                                                break;\r
                                        case MA_OPT_CONFIRM_STATES: {\r
                                                         int n = ((currentConfig.EmuOpt>>9)&1) | ((currentConfig.EmuOpt>>10)&2);\r
-                                                        n += (inp & GP2X_LEFT) ? -1 : 1;\r
+                                                        n += (inp & PBTN_LEFT) ? -1 : 1;\r
                                                         if (n < 0) n = 0; else if (n > 3) n = 3;\r
                                                         n |= n << 1; n &= ~2;\r
                                                         currentConfig.EmuOpt &= ~0xa00;\r
@@ -1306,23 +1227,22 @@ static int menu_loop_options(void)
                                                         break;\r
                                                 }\r
                                        case MA_OPT_SAVE_SLOT:\r
-                                                if (inp & GP2X_RIGHT) {\r
+                                                if (inp & PBTN_RIGHT) {\r
                                                         state_slot++; if (state_slot > 9) state_slot = 0;\r
                                                 } else {state_slot--; if (state_slot < 0) state_slot = 9;\r
                                                 }\r
                                                 break;\r
                                        case MA_OPT_CPU_CLOCKS:\r
-                                                while ((inp = gp2x_joystick_read(1)) & (GP2X_LEFT|GP2X_RIGHT)) {\r
-                                                        currentConfig.CPUclock += (inp & GP2X_LEFT) ? -1 : 1;\r
+                                                while ((inp = in_menu_wait_any(50)) & (PBTN_LEFT|PBTN_RIGHT)) {\r
+                                                        currentConfig.CPUclock += (inp & PBTN_LEFT) ? -1 : 1;\r
                                                         if (currentConfig.CPUclock < 1) currentConfig.CPUclock = 1;\r
                                                         draw_menu_options(menu_sel);\r
-                                                        usleep(50*1000);\r
                                                 }\r
                                                 break;\r
                                        case MA_OPT_SAVECFG:\r
                                        case MA_OPT_SAVECFG_GAME:\r
                                        case MA_OPT_LOADCFG:\r
-                                                config_slot += (inp&GP2X_RIGHT) ? 1 : -1;\r
+                                                config_slot += (inp&PBTN_RIGHT) ? 1 : -1;\r
                                                 if (config_slot > 9) config_slot = 0;\r
                                                 if (config_slot < 0) config_slot = 9;\r
                                                 me_enable(opt_entries, OPT_ENTRY_COUNT, MA_OPT_LOADCFG, config_slot != config_slot_current);\r
@@ -1335,7 +1255,7 @@ static int menu_loop_options(void)
                                }\r
                        }\r
                }\r
-               if (inp & GP2X_B) {\r
+               if (inp & PBTN_MOK) {\r
                        if (!me_process(opt_entries, OPT_ENTRY_COUNT, selected_id, 1))\r
                        {\r
                                switch (selected_id)\r
@@ -1370,7 +1290,7 @@ static int menu_loop_options(void)
                                }\r
                        }\r
                }\r
-               if(inp & (GP2X_X|GP2X_A)) {\r
+               if(inp & PBTN_MBACK) {\r
                        menu_options_save();\r
                        return 0;  // done (update, no write)\r
                }\r
@@ -1464,28 +1384,28 @@ static void menu_loop_root(void)
 \r
        /* make sure action buttons are not pressed on entering menu */\r
        draw_menu_root(menu_sel);\r
-       while (gp2x_joystick_read(1) & (GP2X_B|GP2X_X|GP2X_SELECT)) usleep(50*1000);\r
+       while (in_menu_wait_any(50) & (PBTN_MOK|PBTN_MBACK|PBTN_MENU));\r
 \r
        for (;;)\r
        {\r
                draw_menu_root(menu_sel);\r
-               inp = wait_for_input(GP2X_UP|GP2X_DOWN|GP2X_B|GP2X_X|GP2X_SELECT|GP2X_L|GP2X_R);\r
-               if(inp & GP2X_UP  )  { menu_sel--; if (menu_sel < 0) menu_sel = menu_sel_max; }\r
-               if(inp & GP2X_DOWN)  { menu_sel++; if (menu_sel > menu_sel_max) menu_sel = 0; }\r
-               if((inp & (GP2X_L|GP2X_R)) == (GP2X_L|GP2X_R)) debug_menu_loop();\r
-               if(inp &(GP2X_SELECT|GP2X_X)){\r
+               inp = in_menu_wait(PBTN_UP|PBTN_DOWN|PBTN_MOK|PBTN_MBACK|PBTN_MENU|PBTN_L|PBTN_R);\r
+               if(inp & PBTN_UP  )  { menu_sel--; if (menu_sel < 0) menu_sel = menu_sel_max; }\r
+               if(inp & PBTN_DOWN)  { menu_sel++; if (menu_sel > menu_sel_max) menu_sel = 0; }\r
+               if((inp & (PBTN_L|PBTN_R)) == (PBTN_L|PBTN_R)) debug_menu_loop();\r
+               if(inp &(PBTN_MENU|PBTN_MBACK)){\r
                        if (rom_loaded) {\r
-                               while (gp2x_joystick_read(1) & (GP2X_SELECT|GP2X_X)) usleep(50*1000); // wait until select is released\r
+                               while (in_menu_wait_any(50) & (PBTN_MENU|PBTN_MBACK)); // wait until select is released\r
                                engineState = PGS_Running;\r
                                break;\r
                        }\r
                }\r
-               if(inp & GP2X_B)  {\r
+               if(inp & PBTN_MOK)  {\r
                        switch (me_index2id(main_entries, MAIN_ENTRY_COUNT, menu_sel))\r
                        {\r
                                case MA_MAIN_RESUME_GAME:\r
                                        if (rom_loaded) {\r
-                                               while (gp2x_joystick_read(1) & GP2X_B) usleep(50*1000);\r
+                                               while (in_menu_wait_any(50) & PBTN_MOK);\r
                                                engineState = PGS_Running;\r
                                                return;\r
                                        }\r
@@ -1502,7 +1422,7 @@ static void menu_loop_root(void)
                                        if (rom_loaded) {\r
                                                if(savestate_menu_loop(1))\r
                                                        continue;\r
-                                               while (gp2x_joystick_read(1) & GP2X_B) usleep(50*1000);\r
+                                               while (in_menu_wait_any(50) & PBTN_MOK);\r
                                                engineState = PGS_Running;\r
                                                return;\r
                                        }\r
@@ -1510,7 +1430,7 @@ static void menu_loop_root(void)
                                case MA_MAIN_RESET_GAME:\r
                                        if (rom_loaded) {\r
                                                emu_ResetGame();\r
-                                               while (gp2x_joystick_read(1) & GP2X_B) usleep(50*1000);\r
+                                               while (in_menu_wait_any(50) & PBTN_MOK);\r
                                                engineState = PGS_Running;\r
                                                return;\r
                                        }\r
@@ -1546,7 +1466,7 @@ static void menu_loop_root(void)
                                case MA_MAIN_CREDITS:\r
                                        draw_menu_credits();\r
                                        usleep(500*1000);\r
-                                       inp = wait_for_input(GP2X_B|GP2X_X);\r
+                                       inp = in_menu_wait(PBTN_MOK|PBTN_MBACK);\r
                                        break;\r
                                case MA_MAIN_EXIT:\r
                                        engineState = PGS_Quit;\r
@@ -1676,15 +1596,15 @@ int menu_loop_tray(void)
 \r
        /* make sure action buttons are not pressed on entering menu */\r
        draw_menu_tray(menu_sel);\r
-       while (gp2x_joystick_read(1) & GP2X_B) usleep(50*1000);\r
+       while (in_menu_wait_any(50) & PBTN_MOK);\r
 \r
        for (;;)\r
        {\r
                draw_menu_tray(menu_sel);\r
-               inp = wait_for_input(GP2X_UP|GP2X_DOWN|GP2X_B);\r
-               if(inp & GP2X_UP  )  { menu_sel--; if (menu_sel < 0) menu_sel = menu_sel_max; }\r
-               if(inp & GP2X_DOWN)  { menu_sel++; if (menu_sel > menu_sel_max) menu_sel = 0; }\r
-               if(inp & GP2X_B   )  {\r
+               inp = in_menu_wait(PBTN_UP|PBTN_DOWN|PBTN_MOK);\r
+               if(inp & PBTN_UP  )  { menu_sel--; if (menu_sel < 0) menu_sel = menu_sel_max; }\r
+               if(inp & PBTN_DOWN)  { menu_sel++; if (menu_sel > menu_sel_max) menu_sel = 0; }\r
+               if(inp & PBTN_MOK   )  {\r
                        switch (menu_sel) {\r
                                case 0: // select image\r
                                        selfname = romsel_loop(curr_path);\r
index f4019d9..fd2082f 100644 (file)
@@ -1,2 +1,2 @@
-#define VERSION "1.51b"\r
+#define VERSION "1.52"\r
 \r
index 045fd52..a8f552c 100644 (file)
@@ -29,7 +29,7 @@ else
 use_cyclone = 1\r
 endif\r
 \r
-DEFINC = -I../.. -I. -DARM -DPANDORA\r
+DEFINC = -I../.. -I. -DARM -DPANDORA -DIN_EVDEV\r
 COPT_COMMON = -Wall -Winline -mcpu=cortex-a8 -mtune=cortex-a8 -march=armv7-a -I$(LIBROOT)/include\r
 ifeq ($(DEBUG),)\r
 COPT_COMMON += -O2 # -ftracer -fstrength-reduce -fomit-frame-pointer -fstrict-aliasing -ffast-math\r
@@ -57,7 +57,8 @@ OBJS += pandora.o main.o emu.o asm_utils.o platform/gp2x/menu.o
 # common\r
 OBJS += platform/common/emu.o platform/common/menu.o platform/common/fonts.o platform/common/config.o \\r
        platform/common/arm_utils.o platform/common/mp3_helix.o platform/common/arm_linux.o \\r
-       platform/common/readpng.o platform/linux/usbjoy.o platform/linux/sndout_oss.o\r
+       platform/common/readpng.o platform/common/input.o platform/linux/in_evdev.o \\r
+       platform/linux/sndout_oss.o\r
 \r
 # Pico\r
 ifeq "$(amalgamate)" "1"\r
@@ -131,7 +132,7 @@ include ../common/common_arm.mak
 \r
 PicoDrive : $(OBJS) ../common/helix/$(CROSS)helix-mp3.a\r
        @echo ">>>" $@\r
-       $(CC) -o $@ $(CFLAGS) $^ -lm -Wl,-Map=PicoDrive.map -lpng -L$(LIBROOT)/lib\r
+       $(CC) -o $@ $(CFLAGS) $^ -lm -Wl,-Map=PicoDrive.map -lpng -L$(LIBROOT)/lib -static\r
 ifeq ($(DEBUG),)\r
        $(STRIP) $@\r
 endif\r
index 0b55405..8bc76be 100644 (file)
 \r
 #include "../gp2x/emu.h"\r
 #include "../gp2x/menu.h"\r
+#include "../gp2x/gp2x.h"\r
 #include "../common/arm_utils.h"\r
 #include "../common/fonts.h"\r
 #include "../common/emu.h"\r
 #include "../common/config.h"\r
 #include "../common/common.h"\r
-#include "../linux/usbjoy.h"\r
+#include "../common/input.h"\r
 #include "../linux/sndout_oss.h"\r
 #include "asm_utils.h"\r
 \r
@@ -475,6 +476,7 @@ static void emu_msg_tray_open(void)
        gettimeofday(&noticeMsgTime, 0);\r
 }\r
 \r
+#if 0\r
 static void RunEventsPico(unsigned int events, unsigned int gp2x_keys)\r
 {\r
        int ret, px, py, lim_x;\r
@@ -526,6 +528,7 @@ static void RunEventsPico(unsigned int events, unsigned int gp2x_keys)
        PicoPicohw.pen_pos[0] += 0x3c;\r
        PicoPicohw.pen_pos[1] = pico_inp_mode == 1 ? (0x2f8 + pico_pen_y) : (0x1fc + pico_pen_y);\r
 }\r
+#endif\r
 \r
 static void update_volume(int has_changed, int is_up)\r
 {\r
@@ -569,6 +572,7 @@ static void RunEvents(unsigned int which)
                if ( emu_checkSaveFile(state_slot) &&\r
                                (( (which & 0x1000) && (currentConfig.EmuOpt & 0x800)) ||   // load\r
                                 (!(which & 0x1000) && (currentConfig.EmuOpt & 0x200))) ) { // save\r
+#if 0\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
@@ -577,6 +581,7 @@ static void RunEvents(unsigned int which)
                        while ( gp2x_joystick_read(1) & (GP2X_X|GP2X_Y) ) // wait for release\r
                                usleep(50*1024);\r
                        clearArea(0);\r
+#endif\r
                }\r
                if (do_it) {\r
                        osd_text(4, SCREEN_HEIGHT-16, (which & 0x1000) ? "LOADING GAME" : "SAVING GAME");\r
@@ -625,63 +630,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
-       int joy, i;\r
-\r
-       keys = gp2x_joystick_read(0);\r
-       if (keys & GP2X_SELECT) {\r
-               engineState = select_exits ? PGS_Quit : PGS_Menu;\r
-               // wait until select is released, so menu would not resume game\r
-               while (gp2x_joystick_read(1) & GP2X_SELECT) usleep(50*1000);\r
-       }\r
-\r
-       keys &= CONFIGURABLE_KEYS;\r
-       keys2 = keys;\r
-\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
 \r
-       // add joy inputs\r
-       if (num_of_joys > 0)\r
-       {\r
-               usbjoy_update();\r
-               for (joy = 0; joy < num_of_joys; joy++) {\r
-                       int btns = usbjoy_check2(joy);\r
-                       for (i = 0; i < 32; i++) {\r
-                               if (btns & (1 << i)) {\r
-                                       int acts = currentConfig.JoyBinds[joy][i];\r
-                                       int pl = (acts >> 16) & 1;\r
-                                       allActions[pl] |= acts;\r
-                               }\r
-                       }\r
-               }\r
-       }\r
+       /* FIXME: combos, player2 */\r
+       allActions[0] = in_update();\r
 \r
        PicoPad[0] = allActions[0] & 0xfff;\r
        PicoPad[1] = allActions[1] & 0xfff;\r
@@ -703,8 +656,10 @@ static void updateKeys(void)
 \r
        events &= ~prevEvents;\r
 \r
+/*\r
        if (PicoAHW == PAHW_PICO)\r
                RunEventsPico(events, keys);\r
+*/\r
        if (events) RunEvents(events);\r
        if (movie_data) emu_updateMovie();\r
 \r
@@ -785,10 +740,46 @@ static void simpleWait(int thissec, int lim_time)
        }\r
 }\r
 \r
+void emu_startSound(void)\r
+{\r
+       static int PsndRate_old = 0, PicoOpt_old = 0, pal_old = 0;\r
+       int target_fps = Pico.m.pal ? 50 : 60;\r
+\r
+       PsndOut = NULL;\r
+\r
+       if (currentConfig.EmuOpt & 4)\r
+       {\r
+               int snd_excess_add;\r
+               if (PsndRate != PsndRate_old || (PicoOpt&0x20b) != (PicoOpt_old&0x20b) || Pico.m.pal != pal_old)\r
+                       PsndRerate(Pico.m.frame_count ? 1 : 0);\r
+\r
+               snd_excess_add = ((PsndRate - PsndLen*target_fps)<<16) / target_fps;\r
+               printf("starting audio: %i len: %i (ex: %04x) stereo: %i, pal: %i\n",\r
+                       PsndRate, PsndLen, snd_excess_add, (PicoOpt&8)>>3, Pico.m.pal);\r
+               sndout_oss_start(PsndRate, 16, (PicoOpt&8)>>3);\r
+               sndout_oss_setvol(currentConfig.volume, currentConfig.volume);\r
+               PicoWriteSound = updateSound;\r
+               update_volume(0, 0);\r
+               memset(sndBuffer, 0, sizeof(sndBuffer));\r
+               PsndOut = sndBuffer;\r
+               PsndRate_old = PsndRate;\r
+               PicoOpt_old  = PicoOpt;\r
+               pal_old = Pico.m.pal;\r
+       }\r
+}\r
+\r
+void emu_endSound(void)\r
+{\r
+}\r
+\r
+/* wait until we can write more sound */\r
+void emu_waitSound(void)\r
+{\r
+       // don't need to do anything, writes will block by themselves\r
+}\r
 \r
 void emu_Loop(void)\r
 {\r
-       static int PsndRate_old = 0, PicoOpt_old = 0, pal_old = 0;\r
        char fpsbuff[24]; // fps count c string\r
        struct timeval tval; // timing\r
        int pframes_done, pframes_shown, pthissec; // "period" frames, used for sync\r
@@ -811,28 +802,7 @@ void emu_Loop(void)
        target_frametime = 1000000/target_fps;\r
        reset_timing = 1;\r
 \r
-       // prepare sound stuff\r
-       if (currentConfig.EmuOpt & 4)\r
-       {\r
-               int snd_excess_add;\r
-               if (PsndRate != PsndRate_old || (PicoOpt&0x20b) != (PicoOpt_old&0x20b) || Pico.m.pal != pal_old)\r
-                       PsndRerate(Pico.m.frame_count ? 1 : 0);\r
-\r
-               snd_excess_add = ((PsndRate - PsndLen*target_fps)<<16) / target_fps;\r
-               printf("starting audio: %i len: %i (ex: %04x) stereo: %i, pal: %i\n",\r
-                       PsndRate, PsndLen, snd_excess_add, (PicoOpt&8)>>3, Pico.m.pal);\r
-               sndout_oss_start(PsndRate, 16, (PicoOpt&8)>>3);\r
-               sndout_oss_setvol(currentConfig.volume, currentConfig.volume);\r
-               PicoWriteSound = updateSound;\r
-               update_volume(0, 0);\r
-               memset(sndBuffer, 0, sizeof(sndBuffer));\r
-               PsndOut = sndBuffer;\r
-               PsndRate_old = PsndRate;\r
-               PicoOpt_old  = PicoOpt;\r
-               pal_old = Pico.m.pal;\r
-       } else {\r
-               PsndOut = NULL;\r
-       }\r
+       emu_startSound();\r
 \r
        // prepare CD buffer\r
        if (PicoAHW & PAHW_MCD) PicoCDBufferInit();\r
index 5fecb4a..4690f06 100644 (file)
@@ -15,6 +15,7 @@
 #include "../common/menu.h"\r
 #include "../common/emu.h"\r
 #include "../common/config.h"\r
+#include "../common/input.h"\r
 #include "../gp2x/emu.h"\r
 #include "../gp2x/version.h"\r
 \r
@@ -77,10 +78,13 @@ int main(int argc, char *argv[])
 {\r
        g_argv = argv;\r
 \r
+       in_init();\r
        emu_prepareDefaultConfig();\r
        emu_ReadConfig(0, 0);\r
        config_readlrom(PicoConfigFile);\r
 \r
+       in_probe();\r
+       in_debug_dump();\r
        gp2x_init();\r
        emu_Init();\r
        menu_init();\r
index b72d8b6..6c33e6c 100644 (file)
@@ -12,7 +12,6 @@
 #include <errno.h>\r
 \r
 #include "../gp2x/gp2x.h"\r
-#include "../linux/usbjoy.h"\r
 #include "../linux/sndout_oss.h"\r
 #include "../common/arm_linux.h"\r
 \r
@@ -87,22 +86,6 @@ void gp2x_pd_clone_buffer2(void)
        memset(gp2x_screen, 0, 800*480*2);\r
 }\r
 \r
-\r
-unsigned long gp2x_joystick_read(int allow_usb_joy)\r
-{\r
-       unsigned long value = 0;\r
-       int i;\r
-\r
-       if (allow_usb_joy && num_of_joys > 0) {\r
-               // check the usb joy as well..\r
-               usbjoy_update();\r
-               for (i = 0; i < num_of_joys; i++)\r
-                       value |= usbjoy_check(i);\r
-       }\r
-\r
-       return value;\r
-}\r
-\r
 // FIXME\r
 #if 0\r
 static int touchcal[7] = { 6203, 0, -1501397, 0, -4200, 16132680, 65536 };\r
@@ -180,9 +163,6 @@ void gp2x_init(void)
        // snd\r
        sndout_oss_init();\r
 \r
-       /* init usb joys -GnoStiC */\r
-       usbjoy_init();\r
-\r
        printf("exitting init()\n"); fflush(stdout);\r
 }\r
 \r
@@ -196,7 +176,6 @@ void gp2x_deinit(void)
        if (fbdev >= 0)    close(fbdev);\r
 \r
        sndout_oss_exit();\r
-       usbjoy_deinit();\r
 \r
        printf("all done");\r
 }\r
index 68b55b4..2c6c7fd 100644 (file)
@@ -25,6 +25,7 @@
 #include "../common/emu.h"
 #include "../common/readpng.h"
 #include "../common/lprintf.h"
+#include "../common/input.h"
 #include "version.h"
 
 #include <pico/pico_int.h>
@@ -49,49 +50,6 @@ static void menu_prepare_bg(int use_game_bg, int use_fg);
 
 static unsigned int inp_prev = 0;
 
-unsigned long wait_for_input(unsigned int interesting, int is_key_config)
-{
-       unsigned int ret;
-       static int repeats = 0, wait = 20;
-       int release = 0, count, i;
-
-       if (!is_key_config)
-               interesting |= (interesting & 0xf0) << 24; // also use analog
-
-       if      (repeats == 2) wait = 3;
-       else if (repeats == 4) wait = 2;
-       else if (repeats == 6) wait = 1;
-
-       for (i = 0; i < wait && inp_prev == psp_pad_read(1); i++) {
-               if (i == 0) repeats++;
-               psp_msleep(30);
-       }
-
-       for (count = 0; !((ret = psp_pad_read(1)) & interesting) && count < 100; count++) {
-               psp_msleep(50);
-               release = 1;
-       }
-
-       if (release || ret != inp_prev) {
-               repeats = 0;
-               wait = 20;
-       }
-       inp_prev = ret;
-
-       if (!is_key_config)
-               ret |= (ret & 0xf0000000) >> 24; // use analog as d-pad
-       if (wait > 6 && (ret&(PBTN_UP|PBTN_LEFT|PBTN_DOWN|PBTN_RIGHT|PBTN_L|PBTN_R)))
-               wait = 6;
-
-       // we don't need diagonals in menus
-       if ((ret&PBTN_UP)   && (ret&PBTN_LEFT))  ret &= ~PBTN_LEFT;
-       if ((ret&PBTN_UP)   && (ret&PBTN_RIGHT)) ret &= ~PBTN_RIGHT;
-       if ((ret&PBTN_DOWN) && (ret&PBTN_LEFT))  ret &= ~PBTN_LEFT;
-       if ((ret&PBTN_DOWN) && (ret&PBTN_RIGHT)) ret &= ~PBTN_RIGHT;
-
-       return ret;
-}
-
 void menu_draw_begin(void)
 {
        // short *src = (short *)bg_buffer, *dst = (short *)menu_screen;
@@ -384,7 +342,7 @@ static char *romsel_loop(char *curr_path)
        for (;;)
        {
                draw_dirlist(curr_path, namelist, n, sel);
-               inp = wait_for_input(PBTN_UP|PBTN_DOWN|PBTN_LEFT|PBTN_RIGHT|PBTN_L|PBTN_R|PBTN_X|PBTN_CIRCLE, 0);
+               inp = in_menu_wait(PBTN_UP|PBTN_DOWN|PBTN_LEFT|PBTN_RIGHT|PBTN_L|PBTN_R|PBTN_X|PBTN_CIRCLE, 0);
                if(inp & PBTN_UP  )  { sel--;   if (sel < 0)   sel = n-2; }
                if(inp & PBTN_DOWN)  { sel++;   if (sel > n-2) sel = 0; }
                if(inp & PBTN_LEFT)  { sel-=10; if (sel < 0)   sel = 0; }
@@ -469,7 +427,7 @@ static void patches_menu_loop(void)
        for(;;)
        {
                draw_patchlist(menu_sel);
-               inp = wait_for_input(PBTN_UP|PBTN_DOWN|PBTN_LEFT|PBTN_RIGHT|PBTN_L|PBTN_R|PBTN_X|PBTN_CIRCLE, 0);
+               inp = in_menu_wait(PBTN_UP|PBTN_DOWN|PBTN_LEFT|PBTN_RIGHT|PBTN_L|PBTN_R|PBTN_X|PBTN_CIRCLE, 0);
                if(inp & PBTN_UP  ) { menu_sel--; if (menu_sel < 0) menu_sel = PicoPatchCount; }
                if(inp & PBTN_DOWN) { menu_sel++; if (menu_sel > PicoPatchCount) menu_sel = 0; }
                if(inp &(PBTN_LEFT|PBTN_L))  { menu_sel-=10; if (menu_sel < 0) menu_sel = 0; }
@@ -599,7 +557,7 @@ static int savestate_menu_loop(int is_loading)
        for(;;)
        {
                draw_savestate_menu(menu_sel, is_loading);
-               inp = wait_for_input(PBTN_UP|PBTN_DOWN|PBTN_X|PBTN_CIRCLE, 0);
+               inp = in_menu_wait(PBTN_UP|PBTN_DOWN|PBTN_X|PBTN_CIRCLE, 0);
                if(inp & PBTN_UP  ) {
                        do {
                                menu_sel--; if (menu_sel < 0) menu_sel = menu_sel_max;
@@ -713,7 +671,7 @@ static void key_config_loop(const me_bind_action *opts, int opt_cnt, int player_
        for (;;)
        {
                draw_key_config(opts, opt_cnt, player_idx, sel);
-               inp = wait_for_input(CONFIGURABLE_KEYS|PBTN_SELECT, 1);
+               inp = in_menu_wait(CONFIGURABLE_KEYS|PBTN_SELECT, 1);
                if (!(inp & PBTN_SELECT)) {
                        prev_select = 0;
                        if(inp & PBTN_UP  ) { sel--; if (sel < 0) sel = menu_sel_max; continue; }
@@ -795,7 +753,7 @@ static void kc_sel_loop(void)
        while (1)
        {
                draw_kc_sel(menu_sel);
-               inp = wait_for_input(PBTN_UP|PBTN_DOWN|PBTN_LEFT|PBTN_RIGHT|PBTN_X|PBTN_CIRCLE, 0);
+               inp = in_menu_wait(PBTN_UP|PBTN_DOWN|PBTN_LEFT|PBTN_RIGHT|PBTN_X|PBTN_CIRCLE, 0);
                selected_id = me_index2id(ctrlopt_entries, CTRLOPT_ENTRY_COUNT, menu_sel);
                if (inp & (PBTN_LEFT|PBTN_RIGHT)) // multi choise
                        me_process(ctrlopt_entries, CTRLOPT_ENTRY_COUNT, selected_id, (inp&PBTN_RIGHT) ? 1 : 0);
@@ -918,7 +876,7 @@ static void cd_menu_loop_options(void)
        for (;;)
        {
                draw_cd_menu_options(menu_sel, &bios_names);
-               inp = wait_for_input(PBTN_UP|PBTN_DOWN|PBTN_LEFT|PBTN_RIGHT|PBTN_X|PBTN_CIRCLE|PBTN_START, 0);
+               inp = in_menu_wait(PBTN_UP|PBTN_DOWN|PBTN_LEFT|PBTN_RIGHT|PBTN_X|PBTN_CIRCLE|PBTN_START, 0);
                if (inp & PBTN_UP  ) { menu_sel--; if (menu_sel < 0) menu_sel = menu_sel_max; }
                if (inp & PBTN_DOWN) { menu_sel++; if (menu_sel > menu_sel_max) menu_sel = 0; }
                selected_id = me_index2id(cdopt_entries, CDOPT_ENTRY_COUNT, menu_sel);
@@ -1081,7 +1039,7 @@ static void dispmenu_loop_options(void)
        for (;;)
        {
                draw_dispmenu_options(menu_sel);
-               inp = wait_for_input(PBTN_UP|PBTN_DOWN|PBTN_LEFT|PBTN_RIGHT|PBTN_X|PBTN_CIRCLE, 0);
+               inp = in_menu_wait(PBTN_UP|PBTN_DOWN|PBTN_LEFT|PBTN_RIGHT|PBTN_X|PBTN_CIRCLE, 0);
                if (inp & PBTN_UP  ) { menu_sel--; if (menu_sel < 0) menu_sel = menu_sel_max; }
                if (inp & PBTN_DOWN) { menu_sel++; if (menu_sel > menu_sel_max) menu_sel = 0; }
                selected_id = me_index2id(opt3_entries, OPT3_ENTRY_COUNT, menu_sel);
@@ -1195,7 +1153,7 @@ static void amenu_loop_options(void)
        for(;;)
        {
                draw_amenu_options(menu_sel);
-               inp = wait_for_input(PBTN_UP|PBTN_DOWN|PBTN_LEFT|PBTN_RIGHT|PBTN_X|PBTN_CIRCLE, 0);
+               inp = in_menu_wait(PBTN_UP|PBTN_DOWN|PBTN_LEFT|PBTN_RIGHT|PBTN_X|PBTN_CIRCLE, 0);
                if (inp & PBTN_UP  ) { menu_sel--; if (menu_sel < 0) menu_sel = menu_sel_max; }
                if (inp & PBTN_DOWN) { menu_sel++; if (menu_sel > menu_sel_max) menu_sel = 0; }
                selected_id = me_index2id(opt2_entries, OPT2_ENTRY_COUNT, menu_sel);
@@ -1375,7 +1333,7 @@ static int menu_loop_options(void)
        while (1)
        {
                draw_menu_options(menu_sel);
-               inp = wait_for_input(PBTN_UP|PBTN_DOWN|PBTN_LEFT|PBTN_RIGHT|PBTN_X|PBTN_CIRCLE, 0);
+               inp = in_menu_wait(PBTN_UP|PBTN_DOWN|PBTN_LEFT|PBTN_RIGHT|PBTN_X|PBTN_CIRCLE, 0);
                if (inp & PBTN_UP  ) { menu_sel--; if (menu_sel < 0) menu_sel = menu_sel_max; }
                if (inp & PBTN_DOWN) { menu_sel++; if (menu_sel > menu_sel_max) menu_sel = 0; }
                selected_id = me_index2id(opt_entries, OPT_ENTRY_COUNT, menu_sel);
@@ -1581,7 +1539,7 @@ static void menu_loop_root(void)
        for (;;)
        {
                draw_menu_root(menu_sel);
-               inp = wait_for_input(PBTN_UP|PBTN_DOWN|PBTN_X|PBTN_CIRCLE|PBTN_SELECT|PBTN_L|PBTN_R, 0);
+               inp = in_menu_wait(PBTN_UP|PBTN_DOWN|PBTN_X|PBTN_CIRCLE|PBTN_SELECT|PBTN_L|PBTN_R, 0);
                if(inp & PBTN_UP  )  { menu_sel--; if (menu_sel < 0) menu_sel = menu_sel_max; }
                if(inp & PBTN_DOWN)  { menu_sel++; if (menu_sel > menu_sel_max) menu_sel = 0; }
                if((inp & (PBTN_L|PBTN_R)) == (PBTN_L|PBTN_R)) debug_menu_loop();
@@ -1661,7 +1619,7 @@ static void menu_loop_root(void)
                                        psp_msleep(500);
                                        inp = 0;
                                        while (!(inp & (PBTN_X|PBTN_CIRCLE)))
-                                               inp = wait_for_input(PBTN_X|PBTN_CIRCLE, 0);
+                                               inp = in_menu_wait(PBTN_X|PBTN_CIRCLE, 0);
                                        break;
                                case MA_MAIN_EXIT:
                                        engineState = PGS_Quit;
@@ -1794,7 +1752,7 @@ int menu_loop_tray(void)
        for (;;)
        {
                draw_menu_tray(menu_sel);
-               inp = wait_for_input(PBTN_UP|PBTN_DOWN|PBTN_CIRCLE, 0);
+               inp = in_menu_wait(PBTN_UP|PBTN_DOWN|PBTN_CIRCLE, 0);
                if(inp & PBTN_UP  )  { menu_sel--; if (menu_sel < 0) menu_sel = menu_sel_max; }
                if(inp & PBTN_DOWN)  { menu_sel++; if (menu_sel > menu_sel_max) menu_sel = 0; }
                if(inp & PBTN_CIRCLE)  {