use system's zlib
[picodrive.git] / platform / gizmondo / menu.c
index edd7ef0..dd6740a 100644 (file)
@@ -1,7 +1,10 @@
-// (c) Copyright 2006,2007 notaz, All rights reserved.\r
-// Free for non-commercial use.\r
-\r
-// For commercial use, separate licencing terms must be obtained.\r
+/*\r
+ * PicoDrive\r
+ * (C) notaz, 2006-2008\r
+ *\r
+ * This work is licensed under the terms of MAME license.\r
+ * See COPYING file in the top-level directory.\r
+ */\r
 \r
 // don't like to use loads of #ifdefs, so duplicating GP2X code\r
 // horribly instead\r
 #include "../common/menu.h"\r
 #include "../common/emu.h"\r
 #include "../common/readpng.h"\r
+#include "../common/input.h"\r
 #include "version.h"\r
 \r
 #include <pico/pico_int.h>\r
 #include <pico/patch.h>\r
-#include <zlib/zlib.h>\r
+#include <zlib.h>\r
 \r
 \r
 #define gizKeyUnkn "???"\r
@@ -47,44 +51,6 @@ static void menu_prepare_bg(int use_game_bg);
 \r
 static unsigned int inp_prev = 0;\r
 \r
-unsigned long wait_for_input(unsigned int interesting)\r
-{\r
-       unsigned long ret;\r
-       static int repeats = 0, wait = 20;\r
-       int 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 && inp_prev == Framework_PollGetButtons(); i++) {\r
-               if (i == 0) repeats++;\r
-               Sleep(30);\r
-       }\r
-\r
-       while ( !((ret = Framework_PollGetButtons()) & interesting) ) {\r
-               Sleep(50);\r
-               release = 1;\r
-       }\r
-\r
-       if (release || ret != inp_prev) {\r
-               repeats = 0;\r
-               wait = 20;\r
-       }\r
-       if (wait > 6 && (ret&(BTN_UP|BTN_LEFT|BTN_DOWN|BTN_RIGHT|BTN_L|BTN_R)))\r
-               wait = 6;\r
-       inp_prev = ret;\r
-\r
-       // we don't need diagonals in menus\r
-       if ((ret&BTN_UP)   && (ret&BTN_LEFT))  ret &= ~BTN_LEFT;\r
-       if ((ret&BTN_UP)   && (ret&BTN_RIGHT)) ret &= ~BTN_RIGHT;\r
-       if ((ret&BTN_DOWN) && (ret&BTN_LEFT))  ret &= ~BTN_LEFT;\r
-       if ((ret&BTN_DOWN) && (ret&BTN_RIGHT)) ret &= ~BTN_RIGHT;\r
-\r
-       return ret;\r
-}\r
-\r
-\r
 void menu_draw_begin(int use_bgbuff)\r
 {\r
        if (use_bgbuff)\r
@@ -386,14 +352,14 @@ static char *romsel_loop(char *curr_path)
        for (;;)\r
        {\r
                draw_dirlist(curr_path, namelist, n, sel);\r
-               inp = wait_for_input(BTN_UP|BTN_DOWN|BTN_LEFT|BTN_RIGHT|BTN_L|BTN_R|BTN_PLAY|BTN_STOP);\r
-               if(inp & BTN_UP  )  { sel--;   if (sel < 0)   sel = n-2; }\r
-               if(inp & BTN_DOWN)  { sel++;   if (sel > n-2) sel = 0; }\r
-               if(inp & BTN_LEFT)  { sel-=10; if (sel < 0)   sel = 0; }\r
-               if(inp & BTN_L)     { sel-=24; if (sel < 0)   sel = 0; }\r
-               if(inp & BTN_RIGHT) { sel+=10; if (sel > n-2) sel = n-2; }\r
-               if(inp & BTN_R)     { sel+=24; if (sel > n-2) sel = n-2; }\r
-               if(inp & BTN_PLAY)     { // enter dir/select\r
+               inp = in_menu_wait(PBTN_UP|PBTN_DOWN|PBTN_LEFT|PBTN_RIGHT|PBTN_L|PBTN_R|PBTN_PLAY|PBTN_STOP);\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_PLAY)     { // enter dir/select\r
                        if (namelist[sel+1]->d_type == DT_REG) {\r
                                strcpy(romFileName, curr_path);\r
                                strcat(romFileName, "/");\r
@@ -422,7 +388,7 @@ static char *romsel_loop(char *curr_path)
                                break;\r
                        }\r
                }\r
-               if(inp & BTN_STOP) break; // cancel\r
+               if(inp & PBTN_STOP) break; // cancel\r
        }\r
 \r
        if (n > 0) {\r
@@ -473,17 +439,17 @@ static void patches_menu_loop(void)
        for(;;)\r
        {\r
                draw_patchlist(menu_sel);\r
-               inp = wait_for_input(BTN_UP|BTN_DOWN|BTN_LEFT|BTN_RIGHT|BTN_L|BTN_R|BTN_PLAY|BTN_STOP);\r
-               if(inp & BTN_UP  ) { menu_sel--; if (menu_sel < 0) menu_sel = PicoPatchCount; }\r
-               if(inp & BTN_DOWN) { menu_sel++; if (menu_sel > PicoPatchCount) menu_sel = 0; }\r
-               if(inp &(BTN_LEFT|BTN_L))  { menu_sel-=10; if (menu_sel < 0) menu_sel = 0; }\r
-               if(inp &(BTN_RIGHT|BTN_R)) { menu_sel+=10; if (menu_sel > PicoPatchCount) menu_sel = PicoPatchCount; }\r
-               if(inp & BTN_PLAY) { // action\r
+               inp = in_menu_wait(PBTN_UP|PBTN_DOWN|PBTN_LEFT|PBTN_RIGHT|PBTN_L|PBTN_R|PBTN_PLAY|PBTN_STOP);\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_PLAY) { // action\r
                        if (menu_sel < PicoPatchCount)\r
                                PicoPatches[menu_sel].active = !PicoPatches[menu_sel].active;\r
                        else    return;\r
                }\r
-               if(inp & BTN_STOP) return;\r
+               if(inp & PBTN_STOP) return;\r
        }\r
 \r
 }\r
@@ -593,18 +559,18 @@ static int savestate_menu_loop(int is_loading)
        for(;;)\r
        {\r
                draw_savestate_menu(menu_sel, is_loading);\r
-               inp = wait_for_input(BTN_UP|BTN_DOWN|BTN_PLAY|BTN_STOP);\r
-               if(inp & BTN_UP  ) {\r
+               inp = in_menu_wait(PBTN_UP|PBTN_DOWN|PBTN_PLAY|PBTN_STOP);\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 & BTN_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 & BTN_PLAY) { // save/load\r
+               if(inp & PBTN_PLAY) { // save/load\r
                        if (menu_sel < 10) {\r
                                state_slot = menu_sel;\r
                                PicoStateProgressCB = emu_stateCb; /* also suitable for menu */\r
@@ -615,7 +581,7 @@ static int savestate_menu_loop(int is_loading)
                                return 0;\r
                        } else  return 1;\r
                }\r
-               if(inp & BTN_STOP) return 1;\r
+               if(inp & PBTN_STOP) return 1;\r
        }\r
 }\r
 \r
@@ -703,22 +669,22 @@ 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);\r
-               inp = wait_for_input(CONFIGURABLE_KEYS|BTN_HOME);\r
-               if (!(inp & BTN_HOME)) {\r
+               inp = in_menu_wait(CONFIGURABLE_KEYS|PBTN_HOME);\r
+               if (!(inp & PBTN_HOME)) {\r
                        prev_select = 0;\r
-                       if(inp & BTN_UP  ) { sel--; if (sel < 0) sel = menu_sel_max; continue; }\r
-                       if(inp & BTN_DOWN) { sel++; if (sel > menu_sel_max) sel = 0; continue; }\r
+                       if(inp & PBTN_UP  ) { sel--; if (sel < 0) sel = menu_sel_max; continue; }\r
+                       if(inp & PBTN_DOWN) { sel++; if (sel > menu_sel_max) sel = 0; continue; }\r
                }\r
                if (sel >= opt_cnt) {\r
-                       if (inp & (BTN_PLAY|BTN_STOP)) break;\r
+                       if (inp & (PBTN_PLAY|PBTN_STOP)) break;\r
                        else continue;\r
                }\r
                // if we are here, we want to bind/unbind something\r
-               if ((inp & BTN_HOME) && !prev_select)\r
+               if ((inp & PBTN_HOME) && !prev_select)\r
                        unbind_action(opts[sel].mask);\r
-               prev_select = inp & BTN_HOME;\r
+               prev_select = inp & PBTN_HOME;\r
                inp &= CONFIGURABLE_KEYS;\r
-               inp &= ~BTN_HOME;\r
+               inp &= ~PBTN_HOME;\r
                for (i = 0; i < 32; i++)\r
                        if (inp & (1 << i)) {\r
                                if (count_bound_keys(opts[sel].mask, player_idx) >= 2)\r
@@ -783,13 +749,13 @@ static void kc_sel_loop(void)
        while (1)\r
        {\r
                draw_kc_sel(menu_sel);\r
-               inp = wait_for_input(BTN_UP|BTN_DOWN|BTN_PLAY|BTN_STOP);\r
+               inp = in_menu_wait(PBTN_UP|PBTN_DOWN|PBTN_PLAY|PBTN_STOP);\r
                selected_id = me_index2id(ctrlopt_entries, CTRLOPT_ENTRY_COUNT, menu_sel);\r
-               if (inp & (BTN_LEFT|BTN_RIGHT)) // multi choise\r
-                       me_process(ctrlopt_entries, CTRLOPT_ENTRY_COUNT, selected_id, (inp&BTN_RIGHT) ? 1 : 0);\r
-               if (inp & BTN_UP  ) { menu_sel--; if (menu_sel < 0) menu_sel = menu_sel_max; }\r
-               if (inp & BTN_DOWN) { menu_sel++; if (menu_sel > menu_sel_max) menu_sel = 0; }\r
-               if (inp & BTN_PLAY) {\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_PLAY) {\r
                        int is_6button = PicoOpt & 0x020;\r
                        switch (selected_id) {\r
                                case MA_CTRL_PLAYER1: key_config_loop(me_ctrl_actions, is_6button ? 15 : 11, 0); return;\r
@@ -800,7 +766,7 @@ static void kc_sel_loop(void)
                                default: return;\r
                        }\r
                }\r
-               if (inp & BTN_STOP) return;\r
+               if (inp & PBTN_STOP) return;\r
        }\r
 }\r
 \r
@@ -904,14 +870,14 @@ static void cd_menu_loop_options(void)
        for(;;)\r
        {\r
                draw_cd_menu_options(menu_sel, &bios_names);\r
-               inp = wait_for_input(BTN_UP|BTN_DOWN|BTN_LEFT|BTN_RIGHT|BTN_PLAY|BTN_STOP|BTN_REW);\r
-               if (inp & BTN_UP  ) { menu_sel--; if (menu_sel < 0) menu_sel = menu_sel_max; }\r
-               if (inp & BTN_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_PLAY|PBTN_STOP|PBTN_REW);\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 & (BTN_LEFT|BTN_RIGHT)) { // multi choise\r
-                       if (!me_process(cdopt_entries, CDOPT_ENTRY_COUNT, selected_id, (inp&BTN_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 & BTN_LEFT) {\r
+                               if (inp & PBTN_LEFT) {\r
                                        PicoCDBuffers >>= 1;\r
                                        if (PicoCDBuffers < 2) PicoCDBuffers = 0;\r
                                } else {\r
@@ -921,7 +887,7 @@ static void cd_menu_loop_options(void)
                                }\r
                        }\r
                }\r
-               if (inp & BTN_PLAY) { // toggleable options\r
+               if (inp & PBTN_PLAY) { // toggleable options\r
                        if (!me_process(cdopt_entries, CDOPT_ENTRY_COUNT, selected_id, 1) &&\r
                            selected_id == MA_CDOPT_DONE) {\r
                                return;\r
@@ -952,7 +918,7 @@ static void cd_menu_loop_options(void)
                                        break;\r
                        }\r
                }\r
-               if (inp & (BTN_STOP|BTN_REW)) return;\r
+               if (inp & (PBTN_STOP|PBTN_REW)) return;\r
        }\r
 }\r
 \r
@@ -1003,15 +969,15 @@ static void amenu_loop_options(void)
        for(;;)\r
        {\r
                draw_amenu_options(menu_sel);\r
-               inp = wait_for_input(BTN_UP|BTN_DOWN|BTN_LEFT|BTN_RIGHT|BTN_PLAY|BTN_STOP|BTN_REW);\r
-               if (inp & BTN_UP  ) { menu_sel--; if (menu_sel < 0) menu_sel = menu_sel_max; }\r
-               if (inp & BTN_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_PLAY|PBTN_STOP|PBTN_REW);\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 & (BTN_LEFT|BTN_RIGHT)) { // multi choise\r
-                       if (!me_process(opt2_entries, OPT2_ENTRY_COUNT, selected_id, (inp&BTN_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 = Framework_PollGetButtons()) & (BTN_LEFT|BTN_RIGHT)) {\r
-                                       currentConfig.gamma += (inp & BTN_LEFT) ? -1 : 1;\r
+                               while ((inp = Framework_PollGetButtons()) & (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
@@ -1019,13 +985,13 @@ static void amenu_loop_options(void)
                                }\r
                        }\r
                }\r
-               if (inp & BTN_PLAY) { // toggleable options\r
+               if (inp & PBTN_PLAY) { // 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 & (BTN_STOP|BTN_REW)) return;\r
+               if (inp & (PBTN_STOP|PBTN_REW)) return;\r
        }\r
 }\r
 \r
@@ -1187,15 +1153,15 @@ static int menu_loop_options(void)
        while (1)\r
        {\r
                draw_menu_options(menu_sel);\r
-               inp = wait_for_input(BTN_UP|BTN_DOWN|BTN_LEFT|BTN_RIGHT|BTN_PLAY|BTN_STOP|BTN_REW);\r
-               if (inp & BTN_UP  ) { menu_sel--; if (menu_sel < 0) menu_sel = menu_sel_max; }\r
-               if (inp & BTN_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_PLAY|PBTN_STOP|PBTN_REW);\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 & (BTN_LEFT|BTN_RIGHT)) { // multi choise\r
-                       if (!me_process(opt_entries, OPT_ENTRY_COUNT, selected_id, (inp&BTN_RIGHT) ? 1 : 0)) {\r
+               if (inp & (PBTN_LEFT|PBTN_RIGHT)) { // multi choise\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 & BTN_LEFT) {\r
+                                               if (inp & PBTN_LEFT) {\r
                                                        if ((PicoOpt&0x10) || !(currentConfig.EmuOpt &0x80)) {\r
                                                                PicoOpt&= ~0x10;\r
                                                                currentConfig.EmuOpt |=  0x80;\r
@@ -1208,25 +1174,25 @@ static int menu_loop_options(void)
                                                }\r
                                                break;\r
                                        case MA_OPT_SOUND_QUALITY:\r
-                                               if ((inp & BTN_RIGHT) && PsndRate == 44100 &&\r
+                                               if ((inp & PBTN_RIGHT) && PsndRate == 44100 &&\r
                                                                !(PicoOpt&0x08))\r
                                                {\r
                                                        PsndRate =  11025;\r
                                                        PicoOpt |=  8;\r
-                                               } else if ((inp & BTN_LEFT) && PsndRate == 11025 &&\r
+                                               } else if ((inp & PBTN_LEFT) && PsndRate == 11025 &&\r
                                                                (PicoOpt&0x08) && !(PicoAHW&1))\r
                                                {\r
                                                        PsndRate =  44100;\r
                                                        PicoOpt &= ~8;\r
                                                } else\r
-                                                       PsndRate = sndrate_prevnext(PsndRate, inp & BTN_RIGHT);\r
+                                                       PsndRate = sndrate_prevnext(PsndRate, inp & PBTN_RIGHT);\r
                                                break;\r
                                        case MA_OPT_REGION:\r
-                                               region_prevnext(inp & BTN_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 & BTN_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
@@ -1234,7 +1200,7 @@ static int menu_loop_options(void)
                                                         break;\r
                                                 }\r
                                        case MA_OPT_SAVE_SLOT:\r
-                                                if (inp & BTN_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
@@ -1242,7 +1208,7 @@ static int menu_loop_options(void)
                                        case MA_OPT_SAVECFG:\r
                                        case MA_OPT_SAVECFG_GAME:\r
                                        case MA_OPT_LOADCFG:\r
-                                                config_slot += (inp&BTN_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
@@ -1255,7 +1221,7 @@ static int menu_loop_options(void)
                                }\r
                        }\r
                }\r
-               if (inp & BTN_PLAY) {\r
+               if (inp & PBTN_PLAY) {\r
                        if (!me_process(opt_entries, OPT_ENTRY_COUNT, selected_id, 1))\r
                        {\r
                                switch (selected_id)\r
@@ -1290,7 +1256,7 @@ static int menu_loop_options(void)
                                }\r
                        }\r
                }\r
-               if(inp & (BTN_STOP|BTN_REW)) {\r
+               if(inp & (PBTN_STOP|PBTN_REW)) {\r
                        menu_options_save();\r
                        return 0;  // done (update, no write)\r
                }\r
@@ -1383,28 +1349,28 @@ static void menu_loop_root(void)
        /* make sure action buttons are not pressed on entering menu */\r
        draw_menu_root(menu_sel);\r
 \r
-       while (Framework_PollGetButtons() & (BTN_PLAY|BTN_STOP|BTN_HOME)) Sleep(50);\r
+       while (Framework_PollGetButtons() & (PBTN_PLAY|PBTN_STOP|PBTN_HOME)) Sleep(50);\r
 \r
        for (;;)\r
        {\r
                draw_menu_root(menu_sel);\r
-               inp = wait_for_input(BTN_UP|BTN_DOWN|BTN_PLAY|BTN_STOP|BTN_HOME|BTN_L|BTN_R);\r
-               if(inp & BTN_UP  )  { menu_sel--; if (menu_sel < 0) menu_sel = menu_sel_max; }\r
-               if(inp & BTN_DOWN)  { menu_sel++; if (menu_sel > menu_sel_max) menu_sel = 0; }\r
-               if((inp & (BTN_L|BTN_R)) == (BTN_L|BTN_R)) debug_menu_loop();\r
-               if( inp & (BTN_HOME|BTN_STOP)) {\r
+               inp = in_menu_wait(PBTN_UP|PBTN_DOWN|PBTN_PLAY|PBTN_STOP|PBTN_HOME|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_HOME|PBTN_STOP)) {\r
                        if (rom_loaded) {\r
-                               while (Framework_PollGetButtons() & (BTN_HOME|BTN_STOP)) Sleep(50); // wait until released\r
+                               while (Framework_PollGetButtons() & (PBTN_HOME|PBTN_STOP)) Sleep(50); // wait until released\r
                                engineState = PGS_Running;\r
                                break;\r
                        }\r
                }\r
-               if(inp & BTN_PLAY)  {\r
+               if(inp & PBTN_PLAY)  {\r
                        switch (me_index2id(main_entries, MAIN_ENTRY_COUNT, menu_sel))\r
                        {\r
                                case MA_MAIN_RESUME_GAME:\r
                                        if (rom_loaded) {\r
-                                               while (Framework_PollGetButtons() & BTN_PLAY) Sleep(50);\r
+                                               while (Framework_PollGetButtons() & PBTN_PLAY) Sleep(50);\r
                                                engineState = PGS_Running;\r
                                                return;\r
                                        }\r
@@ -1421,7 +1387,7 @@ static void menu_loop_root(void)
                                        if (rom_loaded) {\r
                                                if(savestate_menu_loop(1))\r
                                                        continue;\r
-                                               while (Framework_PollGetButtons() & BTN_PLAY) Sleep(50);\r
+                                               while (Framework_PollGetButtons() & PBTN_PLAY) Sleep(50);\r
                                                engineState = PGS_Running;\r
                                                return;\r
                                        }\r
@@ -1429,7 +1395,7 @@ static void menu_loop_root(void)
                                case MA_MAIN_RESET_GAME:\r
                                        if (rom_loaded) {\r
                                                emu_ResetGame();\r
-                                               while (Framework_PollGetButtons() & BTN_PLAY) Sleep(50);\r
+                                               while (Framework_PollGetButtons() & PBTN_PLAY) Sleep(50);\r
                                                engineState = PGS_Running;\r
                                                return;\r
                                        }\r
@@ -1465,7 +1431,7 @@ static void menu_loop_root(void)
                                case MA_MAIN_CREDITS:\r
                                        draw_menu_credits();\r
                                        Sleep(500);\r
-                                       inp = wait_for_input(BTN_PLAY|BTN_STOP);\r
+                                       inp = in_menu_wait(PBTN_PLAY|PBTN_STOP);\r
                                        break;\r
                                case MA_MAIN_EXIT:\r
                                        engineState = PGS_Quit;\r
@@ -1598,15 +1564,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 (Framework_PollGetButtons() & BTN_PLAY) Sleep(50);\r
+       while (Framework_PollGetButtons() & PBTN_PLAY) Sleep(50);\r
 \r
        for (;;)\r
        {\r
                draw_menu_tray(menu_sel);\r
-               inp = wait_for_input(BTN_UP|BTN_DOWN|BTN_PLAY);\r
-               if(inp & BTN_UP  )  { menu_sel--; if (menu_sel < 0) menu_sel = menu_sel_max; }\r
-               if(inp & BTN_DOWN)  { menu_sel++; if (menu_sel > menu_sel_max) menu_sel = 0; }\r
-               if(inp & BTN_PLAY   )  {\r
+               inp = in_menu_wait(PBTN_UP|PBTN_DOWN|PBTN_PLAY);\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_PLAY)  {\r
                        switch (menu_sel) {\r
                                case 0: // select image\r
                                        selfname = romsel_loop(curr_path);\r