the old-new win32 port
[libpicofe.git] / common / menu.c
index 7bf133c..887e0cd 100644 (file)
 #include "plat.h"\r
 #include "posix.h"\r
 #include <version.h>\r
+#include <revision.h>\r
 \r
 #include <pico/pico_int.h>\r
 #include <pico/patch.h>\r
-#include <zlib/zlib.h>\r
-\r
-#define array_size(x) (sizeof(x) / sizeof(x[0]))\r
 \r
 static char static_buff[64];\r
-static char menu_error_msg[64] = { 0, };\r
+char menu_error_msg[64] = { 0, };\r
 static int  menu_error_time = 0;\r
 \r
 #ifndef UIQ3\r
@@ -327,7 +325,7 @@ static int me_count(const menu_entry *ent)
        return ret;\r
 }\r
 \r
-static void me_draw(const menu_entry *entries, int sel)\r
+static void me_draw(const menu_entry *entries, int sel, void (*draw_more)(void))\r
 {\r
        const menu_entry *ent;\r
        int x, y, w = 0, h = 0;\r
@@ -449,11 +447,15 @@ static void me_draw(const menu_entry *entries, int sel)
                        menu_error_msg[0] = 0;\r
        }\r
 \r
+       if (draw_more != NULL)\r
+               draw_more();\r
+\r
        plat_video_menu_end();\r
 }\r
 \r
-static int me_process(menu_entry *entry, int is_next)\r
+static int me_process(menu_entry *entry, int is_next, int is_lr)\r
 {\r
+       int c;\r
        switch (entry->beh)\r
        {\r
                case MB_OPT_ONOFF:\r
@@ -462,7 +464,8 @@ static int me_process(menu_entry *entry, int is_next)
                        return 1;\r
                case MB_OPT_RANGE:\r
                case MB_OPT_CUSTRANGE:\r
-                       *(int *)entry->var += is_next ? 1 : -1;\r
+                       c = is_lr ? 10 : 1;\r
+                       *(int *)entry->var += is_next ? c : -c;\r
                        if (*(int *)entry->var < (int)entry->min)\r
                                *(int *)entry->var = (int)entry->max;\r
                        if (*(int *)entry->var > (int)entry->max)\r
@@ -475,12 +478,12 @@ static int me_process(menu_entry *entry, int is_next)
 \r
 static void debug_menu_loop(void);\r
 \r
-static void me_loop(menu_entry *menu, int *menu_sel)\r
+static void me_loop(menu_entry *menu, int *menu_sel, void (*draw_more)(void))\r
 {\r
        int ret, inp, sel = *menu_sel, menu_sel_max;\r
 \r
        menu_sel_max = me_count(menu) - 1;\r
-       if (menu_sel_max < 1) {\r
+       if (menu_sel_max < 0) {\r
                lprintf("no enabled menu entries\n");\r
                return;\r
        }\r
@@ -489,12 +492,12 @@ static void me_loop(menu_entry *menu, int *menu_sel)
                sel++;\r
 \r
        /* make sure action buttons are not pressed on entering menu */\r
-       me_draw(menu, sel);\r
+       me_draw(menu, sel, NULL);\r
        while (in_menu_wait_any(50) & (PBTN_MOK|PBTN_MBACK|PBTN_MENU));\r
 \r
        for (;;)\r
        {\r
-               me_draw(menu, sel);\r
+               me_draw(menu, sel, draw_more);\r
                inp = in_menu_wait(PBTN_UP|PBTN_DOWN|PBTN_LEFT|PBTN_RIGHT|\r
                                        PBTN_MOK|PBTN_MBACK|PBTN_MENU|PBTN_L|PBTN_R, 70);\r
                if (inp & (PBTN_MENU|PBTN_MBACK))\r
@@ -521,8 +524,9 @@ static void me_loop(menu_entry *menu, int *menu_sel)
                if ((inp & (PBTN_L|PBTN_R)) == (PBTN_L|PBTN_R))\r
                        debug_menu_loop();\r
 \r
-               if (inp & (PBTN_LEFT|PBTN_RIGHT)) { /* multi choice */\r
-                       if (me_process(&menu[sel], (inp & PBTN_RIGHT) ? 1 : 0))\r
+               if (inp & (PBTN_LEFT|PBTN_RIGHT|PBTN_L|PBTN_R)) { /* multi choice */\r
+                       if (me_process(&menu[sel], (inp & (PBTN_RIGHT|PBTN_R)) ? 1 : 0,\r
+                                               inp & (PBTN_L|PBTN_R)))\r
                                continue;\r
                }\r
 \r
@@ -540,6 +544,9 @@ static void me_loop(menu_entry *menu, int *menu_sel)
 \r
 /* ***************************************** */\r
 \r
+/* platform specific options and handlers */\r
+#include "../gp2x/menu.c"\r
+\r
 static void draw_menu_credits(void)\r
 {\r
        const char *creds, *p;\r
@@ -593,7 +600,7 @@ static void load_progress_cb(int percent)
        plat_video_menu_end();\r
 }\r
 \r
-static void cdload_progress_cb(int percent)\r
+static void cdload_progress_cb(const char *fname, int percent)\r
 {\r
        int ln, len = percent * g_screen_width / 100;\r
        unsigned short *dst = (unsigned short *)g_screen_ptr + g_screen_width * 10 * 2;\r
@@ -601,7 +608,7 @@ static void cdload_progress_cb(int percent)
        memset(dst, 0xff, g_screen_width * (me_sfont_h - 2) * 2);\r
 \r
        smalltext_out16(1, 3 * me_sfont_h, "Processing CD image / MP3s", 0xffff);\r
-       smalltext_out16(1, 4 * me_sfont_h, rom_fname_loaded, 0xffff);\r
+       smalltext_out16(1, 4 * me_sfont_h, fname, 0xffff);\r
        dst += g_screen_width * me_sfont_h * 3;\r
 \r
        if (len > g_screen_width)\r
@@ -638,7 +645,8 @@ void menu_romload_prepare(const char *rom_name)
 \r
 void menu_romload_end(void)\r
 {\r
-       PicoCartLoadProgressCB = PicoCDLoadProgressCB = NULL;\r
+       PicoCartLoadProgressCB = NULL;\r
+       PicoCDLoadProgressCB = NULL;\r
        smalltext_out16(1, (cdload_called ? 6 : 3) * me_sfont_h,\r
                "Starting emulation...", 0xffff);\r
        plat_video_menu_end();\r
@@ -806,6 +814,11 @@ rescan:
                }\r
        }\r
 \r
+       /* make sure action buttons are not pressed on entering menu */\r
+       draw_dirlist(curr_path, namelist, n, sel);\r
+       while (in_menu_wait_any(50) & (PBTN_MOK|PBTN_MBACK|PBTN_MENU))\r
+               ;\r
+\r
        for (;;)\r
        {\r
                draw_dirlist(curr_path, namelist, n, sel);\r
@@ -962,8 +975,8 @@ static void draw_savestate_bg(int slot)
        struct PicoVideo tmp_pv;\r
        unsigned short tmp_cram[0x40];\r
        unsigned short tmp_vsram[0x40];\r
-       void *tmp_vram, *file;\r
-       char *fname;\r
+       void *tmp_vram;\r
+       const char *fname;\r
 \r
        fname = emu_get_save_fname(1, 0, slot);\r
        if (!fname) return;\r
@@ -976,28 +989,7 @@ static void draw_savestate_bg(int slot)
        memcpy(tmp_vsram, Pico.vsram, sizeof(Pico.vsram));\r
        memcpy(&tmp_pv, &Pico.video, sizeof(Pico.video));\r
 \r
-       if (strcmp(fname + strlen(fname) - 3, ".gz") == 0) {\r
-               file = gzopen(fname, "rb");\r
-               emu_setSaveStateCbs(1);\r
-       } else {\r
-               file = fopen(fname, "rb");\r
-               emu_setSaveStateCbs(0);\r
-       }\r
-\r
-       if (file) {\r
-               if (PicoAHW & PAHW_MCD) {\r
-                       PicoCdLoadStateGfx(file);\r
-               } else {\r
-                       areaSeek(file, 0x10020, SEEK_SET);  // skip header and RAM in state file\r
-                       areaRead(Pico.vram, 1, sizeof(Pico.vram), file);\r
-                       areaSeek(file, 0x2000, SEEK_CUR);\r
-                       areaRead(Pico.cram, 1, sizeof(Pico.cram), file);\r
-                       areaRead(Pico.vsram, 1, sizeof(Pico.vsram), file);\r
-                       areaSeek(file, 0x221a0, SEEK_SET);\r
-                       areaRead(&Pico.video, 1, sizeof(Pico.video), file);\r
-               }\r
-               areaClose(file);\r
-       }\r
+       PicoStateLoadVDP(fname);\r
 \r
        /* do a frame and fetch menu bg */\r
        pemu_forced_frame(POPT_EN_SOFTSCALE);\r
@@ -1049,6 +1041,9 @@ static int menu_loop_savestate(int is_loading)
 \r
        state_check_slots();\r
 \r
+       if (!(state_slot_flags & (1 << menu_sel)) && is_loading)\r
+               menu_sel = menu_sel_max;\r
+\r
        for (;;)\r
        {\r
                draw_savestate_menu(menu_sel, is_loading);\r
@@ -1151,6 +1146,7 @@ static int count_bound_keys(int dev_id, int action_mask, int bindtype)
 static void draw_key_config(const me_bind_action *opts, int opt_cnt, int player_idx,\r
                int sel, int dev_id, int dev_count, int is_bind)\r
 {\r
+       char buff[64], buff2[32];\r
        const char *dev_name;\r
        int x, y, w, i;\r
 \r
@@ -1182,15 +1178,19 @@ static void draw_key_config(const me_bind_action *opts, int opt_cnt, int player_
 \r
        x = g_screen_width / 2 - w / 2;\r
 \r
-       if (dev_count > 1) {\r
-               text_out16(x, g_screen_height - 4 * me_mfont_h, "Viewing binds for:");\r
-               text_out16(x, g_screen_height - 3 * me_mfont_h, dev_name);\r
+       if (!is_bind) {\r
+               snprintf(buff2, sizeof(buff2), "%s", in_get_key_name(-1, -PBTN_MOK));\r
+               snprintf(buff, sizeof(buff), "%s - bind, %s - clear", buff2,\r
+                               in_get_key_name(-1, -PBTN_MA2));\r
+               text_out16(x, g_screen_height - 4 * me_mfont_h, buff);\r
        }\r
+       else\r
+               text_out16(x, g_screen_height - 4 * me_mfont_h, "Press a button to bind/unbind");\r
 \r
-       if (is_bind)\r
-               text_out16(x, g_screen_height - 2 * me_mfont_h, "Press a button to bind/unbind");\r
-       else if (dev_count > 1)\r
+       if (dev_count > 1) {\r
+               text_out16(x, g_screen_height - 3 * me_mfont_h, dev_name);\r
                text_out16(x, g_screen_height - 2 * me_mfont_h, "Press left/right for other devs");\r
+       }\r
 \r
        plat_video_menu_end();\r
 }\r
@@ -1199,7 +1199,7 @@ static void key_config_loop(const me_bind_action *opts, int opt_cnt, int player_
 {\r
        int i, sel = 0, menu_sel_max = opt_cnt - 1;\r
        int dev_id, dev_count, kc, is_down, mkey;\r
-       int unbind, bindtype, mask;\r
+       int unbind, bindtype, mask_shift;\r
 \r
        for (i = 0, dev_id = -1, dev_count = 0; i < IN_MAX_DEVS; i++) {\r
                if (in_get_dev_name(i, 1, 0) != NULL) {\r
@@ -1214,10 +1214,15 @@ static void key_config_loop(const me_bind_action *opts, int opt_cnt, int player_
                return;\r
        }\r
 \r
+       mask_shift = 0;\r
+       if (player_idx == 1)\r
+               mask_shift = 16;\r
+       bindtype = player_idx >= 0 ? IN_BINDTYPE_PLAYER12 : IN_BINDTYPE_EMU;\r
+\r
        for (;;)\r
        {\r
                draw_key_config(opts, opt_cnt, player_idx, sel, dev_id, dev_count, 0);\r
-               mkey = in_menu_wait(PBTN_UP|PBTN_DOWN|PBTN_LEFT|PBTN_RIGHT|PBTN_MBACK|PBTN_MOK, 100);\r
+               mkey = in_menu_wait(PBTN_UP|PBTN_DOWN|PBTN_LEFT|PBTN_RIGHT|PBTN_MBACK|PBTN_MOK|PBTN_MA2, 100);\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
@@ -1243,6 +1248,9 @@ static void key_config_loop(const me_bind_action *opts, int opt_cnt, int player_
                                        return;\r
                                while (in_menu_wait_any(30) & PBTN_MOK);\r
                                break;\r
+                       case PBTN_MA2:\r
+                               in_unbind_all(dev_id, opts[sel].mask << mask_shift, bindtype);\r
+                               continue;\r
                        default:continue;\r
                }\r
 \r
@@ -1252,12 +1260,7 @@ static void key_config_loop(const me_bind_action *opts, int opt_cnt, int player_
                for (is_down = 1; is_down; )\r
                        kc = in_update_keycode(&dev_id, &is_down, -1);\r
 \r
-               bindtype = player_idx >= 0 ? IN_BINDTYPE_PLAYER12 : IN_BINDTYPE_EMU;\r
-               mask = opts[sel].mask;\r
-               if (player_idx == 1)\r
-                       mask <<= 16;\r
-\r
-               i = count_bound_keys(dev_id, mask, bindtype);\r
+               i = count_bound_keys(dev_id, opts[sel].mask << mask_shift, bindtype);\r
                unbind = (i > 0);\r
 \r
                /* allow combos if device supports them */\r
@@ -1265,7 +1268,7 @@ static void key_config_loop(const me_bind_action *opts, int opt_cnt, int player_
                                in_get_dev_info(dev_id, IN_INFO_DOES_COMBOS))\r
                        unbind = 0;\r
 \r
-               in_bind_key(dev_id, kc, bindtype, mask, unbind);\r
+               in_bind_key(dev_id, kc, opts[sel].mask << mask_shift, bindtype, unbind);\r
        }\r
 }\r
 \r
@@ -1369,7 +1372,9 @@ static menu_entry e_menu_keyconfig[] =
 static int menu_loop_keyconfig(menu_id id, int keys)\r
 {\r
        static int sel = 0;\r
-       me_loop(e_menu_keyconfig, &sel);\r
+\r
+       me_enable(e_menu_keyconfig, MA_OPT_SAVECFG_GAME, rom_loaded);\r
+       me_loop(e_menu_keyconfig, &sel, NULL);\r
        return 0;\r
 }\r
 \r
@@ -1402,7 +1407,7 @@ static int mh_cdopt_ra(menu_id id, int keys)
 \r
 static menu_entry e_menu_cd_options[] =\r
 {\r
-       mee_onoff("CD LEDs",              MA_CDOPT_LEDS,          currentConfig.EmuOpt, 0x0400),\r
+       mee_onoff("CD LEDs",              MA_CDOPT_LEDS,          currentConfig.EmuOpt, EOPT_EN_CD_LEDS),\r
        mee_onoff("CDDA audio",           MA_CDOPT_CDDA,          PicoOpt, POPT_EN_MCD_CDDA),\r
        mee_onoff("PCM audio",            MA_CDOPT_PCM,           PicoOpt, POPT_EN_MCD_PCM),\r
        mee_cust ("ReadAhead buffer",     MA_CDOPT_READAHEAD,     mh_cdopt_ra, mgn_cdopt_ra),\r
@@ -1415,7 +1420,22 @@ static menu_entry e_menu_cd_options[] =
 static int menu_loop_cd_options(menu_id id, int keys)\r
 {\r
        static int sel = 0;\r
-       me_loop(e_menu_cd_options, &sel);\r
+       me_loop(e_menu_cd_options, &sel, NULL);\r
+       return 0;\r
+}\r
+\r
+// ------------ 32X options menu ------------\r
+\r
+static menu_entry e_menu_32x_options[] =\r
+{\r
+       mee_onoff("32X enabled",          MA_32XOPT_ENABLE_32X,   PicoOpt, POPT_EN_32X),\r
+       mee_onoff("PWM sound",            MA_32XOPT_PWM,          PicoOpt, POPT_EN_PWM),\r
+};\r
+\r
+static int menu_loop_32x_options(menu_id id, int keys)\r
+{\r
+       static int sel = 0;\r
+       me_loop(e_menu_32x_options, &sel, NULL);\r
        return 0;\r
 }\r
 \r
@@ -1425,58 +1445,43 @@ static menu_entry e_menu_adv_options[] =
 {\r
        mee_onoff     ("SRAM/BRAM saves",          MA_OPT_SRAM_STATES,    currentConfig.EmuOpt, EOPT_EN_SRAM),\r
        mee_onoff     ("Disable sprite limit",     MA_OPT2_NO_SPRITE_LIM, PicoOpt, POPT_DIS_SPRITE_LIM),\r
-       mee_onoff     ("Use second CPU for sound", MA_OPT_ARM940_SOUND,   PicoOpt, POPT_EXT_FM),\r
        mee_onoff     ("Emulate Z80",              MA_OPT2_ENABLE_Z80,    PicoOpt, POPT_EN_Z80),\r
        mee_onoff     ("Emulate YM2612 (FM)",      MA_OPT2_ENABLE_YM2612, PicoOpt, POPT_EN_FM),\r
        mee_onoff     ("Emulate SN76496 (PSG)",    MA_OPT2_ENABLE_SN76496,PicoOpt, POPT_EN_PSG),\r
        mee_onoff     ("gzip savestates",          MA_OPT2_GZIP_STATES,   currentConfig.EmuOpt, EOPT_GZIP_SAVES),\r
        mee_onoff     ("Don't save last used ROM", MA_OPT2_NO_LAST_ROM,   currentConfig.EmuOpt, EOPT_NO_AUTOSVCFG),\r
-       mee_onoff     ("RAM overclock",            MA_OPT2_RAMTIMINGS,    currentConfig.EmuOpt, EOPT_RAM_TIMINGS),\r
-       mee_onoff     ("MMU hack",                 MA_OPT2_SQUIDGEHACK,   currentConfig.EmuOpt, EOPT_MMUHACK),\r
-       mee_onoff     ("SVP dynarec",              MA_OPT2_SVP_DYNAREC,   PicoOpt, POPT_EN_SVP_DRC),\r
        mee_onoff     ("Disable idle loop patching",MA_OPT2_NO_IDLE_LOOPS,PicoOpt, POPT_DIS_IDLE_DET),\r
+       mee_onoff     ("Disable frame limiter",    MA_OPT2_NO_FRAME_LIMIT,currentConfig.EmuOpt, EOPT_NO_FRMLIMIT),\r
+       MENU_GP2X_OPTIONS_ADV\r
        mee_end,\r
 };\r
 \r
 static int menu_loop_adv_options(menu_id id, int keys)\r
 {\r
        static int sel = 0;\r
-       me_loop(e_menu_adv_options, &sel);\r
+       me_loop(e_menu_adv_options, &sel, NULL);\r
        return 0;\r
 }\r
 \r
 // ------------ gfx options menu ------------\r
 \r
-static const char *mgn_opt_scaling(menu_id id, int *offs)\r
-{\r
-       *offs = -13;\r
-       switch (currentConfig.scaling) {\r
-               default:               return "             OFF";\r
-               case EOPT_SCALE_HW_H:  return "   hw horizontal";\r
-               case EOPT_SCALE_HW_HV: return "hw horiz. + vert";\r
-               case EOPT_SCALE_SW_H:  return "   sw horizontal";\r
-       }\r
-}\r
-\r
-static const char *mgn_aopt_gamma(menu_id id, int *offs)\r
+static int mh_opt_render(menu_id id, int keys)\r
 {\r
-       sprintf(static_buff, "%i.%02i", currentConfig.gamma / 100, currentConfig.gamma%100);\r
-       return static_buff;\r
+       plat_video_toggle_renderer((keys & PBTN_RIGHT) ? 1 : 0, 0, 1);\r
+       return 0;\r
 }\r
 \r
 static menu_entry e_menu_gfx_options[] =\r
 {\r
-       mee_range_cust("Scaling",                  MA_OPT_SCALING,        currentConfig.scaling, 0, 3, mgn_opt_scaling),\r
-       mee_range_cust("Gamma correction",         MA_OPT2_GAMMA,         currentConfig.gamma, 1, 300, mgn_aopt_gamma),\r
-       mee_onoff     ("A_SN's gamma curve",       MA_OPT2_A_SN_GAMMA,    currentConfig.EmuOpt, EOPT_A_SN_GAMMA),\r
-       mee_onoff     ("Perfect vsync",            MA_OPT2_VSYNC,         currentConfig.EmuOpt, EOPT_PSYNC),\r
+       mee_cust      ("Renderer",                 MA_OPT_RENDERER,       mh_opt_render, mgn_opt_renderer),\r
+       MENU_GP2X_OPTIONS_GFX\r
        mee_end,\r
 };\r
 \r
 static int menu_loop_gfx_options(menu_id id, int keys)\r
 {\r
        static int sel = 0;\r
-       me_loop(e_menu_gfx_options, &sel);\r
+       me_loop(e_menu_gfx_options, &sel, NULL);\r
        return 0;\r
 }\r
 \r
@@ -1484,20 +1489,6 @@ static int menu_loop_gfx_options(menu_id id, int keys)
 \r
 static menu_entry e_menu_options[];\r
 \r
-/* TODO: move to plat */\r
-static int mh_opt_render(menu_id id, int keys)\r
-{\r
-       if (keys & PBTN_LEFT) {\r
-               if      (PicoOpt&0x10) PicoOpt&= ~0x10;\r
-               else if (!(currentConfig.EmuOpt &0x80))currentConfig.EmuOpt |=  0x80;\r
-       } else {\r
-               if      (PicoOpt&0x10) return 0;\r
-               else if (!(currentConfig.EmuOpt &0x80))PicoOpt|=  0x10;\r
-               else if (  currentConfig.EmuOpt &0x80) currentConfig.EmuOpt &= ~0x80;\r
-       }\r
-       return 0;\r
-}\r
-\r
 static int sndrate_prevnext(int rate, int dir)\r
 {\r
        static const int rates[] = { 8000, 11025, 16000, 22050, 44100 };\r
@@ -1610,15 +1601,11 @@ static int mh_saveloadcfg(menu_id id, int keys)
        return 1;\r
 }\r
 \r
-static const char *mgn_opt_renderer(menu_id id, int *offs)\r
+static int mh_restore_defaults(menu_id id, int keys)\r
 {\r
-       *offs = -6;\r
-       if (PicoOpt & POPT_ALT_RENDERER)\r
-               return " 8bit fast";\r
-       else if (currentConfig.EmuOpt & 0x80)\r
-               return "16bit accurate";\r
-       else\r
-               return " 8bit accurate";\r
+       emu_set_defconfig();\r
+       me_update_msg("defaults restored");\r
+       return 1;\r
 }\r
 \r
 static const char *mgn_opt_fskip(menu_id id, int *offs)\r
@@ -1693,18 +1680,19 @@ static menu_entry e_menu_options[] =
        mee_range     ("Save slot",                MA_OPT_SAVE_SLOT,     state_slot, 0, 9),\r
        mee_range_cust("Frameskip",                MA_OPT_FRAMESKIP,     currentConfig.Frameskip, -1, 16, mgn_opt_fskip),\r
        mee_cust      ("Region",                   MA_OPT_REGION,        mh_opt_misc, mgn_opt_region),\r
-       mee_cust      ("Renderer",                 MA_OPT_RENDERER,      mh_opt_render, mgn_opt_renderer),\r
-       mee_onoff     ("Show FPS",                 MA_OPT_SHOW_FPS,      currentConfig.EmuOpt, 0x002),\r
-       mee_onoff     ("Enable sound",             MA_OPT_ENABLE_SOUND,  currentConfig.EmuOpt, 0x004),\r
+       mee_onoff     ("Show FPS",                 MA_OPT_SHOW_FPS,      currentConfig.EmuOpt, EOPT_SHOW_FPS),\r
+       mee_onoff     ("Enable sound",             MA_OPT_ENABLE_SOUND,  currentConfig.EmuOpt, EOPT_EN_SOUND),\r
        mee_cust      ("Sound Quality",            MA_OPT_SOUND_QUALITY, mh_opt_misc, mgn_opt_sound),\r
        mee_cust      ("Confirm savestate",        MA_OPT_CONFIRM_STATES,mh_opt_misc, mgn_opt_c_saves),\r
        mee_range     (cpu_clk_name,               MA_OPT_CPU_CLOCKS,    currentConfig.CPUclock, 20, 900),\r
        mee_handler   ("[Display options]",        menu_loop_gfx_options),\r
-       mee_handler   ("[Advanced options]",       menu_loop_adv_options),\r
        mee_handler   ("[Sega/Mega CD options]",   menu_loop_cd_options),\r
+       mee_handler   ("[32X options]",            menu_loop_32x_options),\r
+       mee_handler   ("[Advanced options]",       menu_loop_adv_options),\r
        mee_handler_mkname_id(MA_OPT_SAVECFG, mh_saveloadcfg, mgn_savecfg),\r
        mee_handler_id("Save cfg for current game only", MA_OPT_SAVECFG_GAME, mh_saveloadcfg),\r
        mee_handler_mkname_id(MA_OPT_LOADCFG, mh_saveloadcfg, mgn_loadcfg),\r
+       mee_handler   ("Restore defaults",         mh_restore_defaults),\r
        mee_end,\r
 };\r
 \r
@@ -1715,11 +1703,7 @@ static int menu_loop_options(menu_id id, int keys)
        me_enable(e_menu_options, MA_OPT_SAVECFG_GAME, rom_loaded);\r
        me_enable(e_menu_options, MA_OPT_LOADCFG, config_slot != config_slot_current);\r
 \r
-       me_loop(e_menu_options, &sel);\r
-\r
-       if (PicoRegionOverride)\r
-               // force setting possibly changed..\r
-               Pico.m.pal = (PicoRegionOverride == 2 || PicoRegionOverride == 8) ? 1 : 0;\r
+       me_loop(e_menu_options, &sel, NULL);\r
 \r
        return 0;\r
 }\r
@@ -1772,17 +1756,24 @@ static void draw_text_debug(const char *str, int skip, int from)
        }\r
 }\r
 \r
+#ifdef __GNUC__\r
+#define COMPILER "gcc " __VERSION__\r
+#else\r
+#define COMPILER\r
+#endif\r
+\r
 static void draw_frame_debug(void)\r
 {\r
-       char layer_str[48] = "layers:             ";\r
+       char layer_str[48] = "layers:                   ";\r
        if (PicoDrawMask & PDRAW_LAYERB_ON)      memcpy(layer_str +  8, "B", 1);\r
        if (PicoDrawMask & PDRAW_LAYERA_ON)      memcpy(layer_str + 10, "A", 1);\r
        if (PicoDrawMask & PDRAW_SPRITES_LOW_ON) memcpy(layer_str + 12, "spr_lo", 6);\r
        if (PicoDrawMask & PDRAW_SPRITES_HI_ON)  memcpy(layer_str + 19, "spr_hi", 6);\r
+       if (PicoDrawMask & PDRAW_32X_ON)         memcpy(layer_str + 26, "32x", 4);\r
 \r
        memset(g_screen_ptr, 0, g_screen_width * g_screen_height * 2);\r
        pemu_forced_frame(0);\r
-       smalltext_out16(4, 1, "build: " __DATE__ " " __TIME__, 0xffff);\r
+       smalltext_out16(4, 1, "build: r" REVISION "  "__DATE__ " " __TIME__ " " COMPILER, 0xffff);\r
        smalltext_out16(4, g_screen_height - me_sfont_h, layer_str, 0xffff);\r
 }\r
 \r
@@ -1818,19 +1809,23 @@ static void debug_menu_loop(void)
                                        g_screen_width, spr_offs);\r
                                draw_text_debug(PDebugSpriteList(), spr_offs, 6);\r
                                break;\r
+                       case 4: plat_video_menu_begin();\r
+                               tmp = PDebug32x();\r
+                               draw_text_debug(tmp, 0, 0);\r
+                               break;\r
                }\r
                plat_video_menu_end();\r
 \r
                inp = in_menu_wait(PBTN_MOK|PBTN_MBACK|PBTN_MA2|PBTN_MA3|PBTN_L|PBTN_R |\r
                                        PBTN_UP|PBTN_DOWN|PBTN_LEFT|PBTN_RIGHT, 70);\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
+               if (inp & PBTN_L) { mode--; if (mode < 0) mode = 4; }\r
+               if (inp & PBTN_R) { mode++; if (mode > 4) mode = 0; }\r
                switch (mode)\r
                {\r
                        case 0:\r
                                if (inp & PBTN_MOK)\r
-                                       SekStepM68k();\r
+                                       PDebugCPUStep();\r
                                if (inp & PBTN_MA3) {\r
                                        while (inp & PBTN_MA3)\r
                                                inp = in_menu_wait_any(-1);\r
@@ -1848,6 +1843,7 @@ static void debug_menu_loop(void)
                                if (inp & PBTN_RIGHT) PicoDrawMask ^= PDRAW_LAYERA_ON;\r
                                if (inp & PBTN_DOWN)  PicoDrawMask ^= PDRAW_SPRITES_LOW_ON;\r
                                if (inp & PBTN_UP)    PicoDrawMask ^= PDRAW_SPRITES_HI_ON;\r
+                               if (inp & PBTN_MA2)   PicoDrawMask ^= PDRAW_32X_ON;\r
                                if (inp & PBTN_MOK) {\r
                                        PsndOut = NULL; // just in case\r
                                        PicoSkipFrame = 1;\r
@@ -1966,13 +1962,14 @@ void menu_loop(void)
 \r
        plat_video_menu_enter(rom_loaded);\r
        in_set_blocking(1);\r
-       me_loop(e_menu_main, &sel);\r
+       me_loop(e_menu_main, &sel, menu_main_plat_draw);\r
 \r
        if (rom_loaded) {\r
                if (engineState == PGS_Menu)\r
                        engineState = PGS_Running;\r
                /* wait until menu, ok, back is released */\r
-               while (in_menu_wait_any(50) & (PBTN_MENU|PBTN_MOK|PBTN_MBACK));\r
+               while (in_menu_wait_any(50) & (PBTN_MENU|PBTN_MOK|PBTN_MBACK))\r
+                       ;\r
        }\r
 \r
        in_set_blocking(0);\r
@@ -1982,24 +1979,14 @@ void menu_loop(void)
 \r
 static int mh_tray_load_cd(menu_id id, int keys)\r
 {\r
-       cd_img_type cd_type;\r
        char *ret_name;\r
-       int ret = -1;\r
 \r
        ret_name = romsel_run();\r
        if (ret_name == NULL)\r
                return 0;\r
 \r
-       cd_type = emu_cd_check(NULL, ret_name);\r
-       if (cd_type != CIT_NOT_CD)\r
-               ret = Insert_CD(ret_name, cd_type);\r
-       if (ret != 0) {\r
-               me_update_msg("Load failed, invalid CD image?");\r
-               return 0;\r
-       }\r
-\r
        engineState = PGS_RestartRun;\r
-       return 1;\r
+       return emu_swap_cd(ret_name);\r
 }\r
 \r
 static int mh_tray_nothing(menu_id id, int keys)\r
@@ -2009,12 +1996,12 @@ static int mh_tray_nothing(menu_id id, int keys)
 \r
 static menu_entry e_menu_tray[] =\r
 {\r
-       mee_label  ("The unit is about to"),\r
-       mee_label  ("close the CD tray."),\r
+       mee_label  ("The CD tray has opened."),\r
        mee_label  (""),\r
        mee_label  (""),\r
        mee_handler("Load CD image",  mh_tray_load_cd),\r
        mee_handler("Insert nothing", mh_tray_nothing),\r
+       mee_end,\r
 };\r
 \r
 int menu_loop_tray(void)\r
@@ -2024,7 +2011,7 @@ int menu_loop_tray(void)
        plat_video_menu_enter(rom_loaded);\r
 \r
        in_set_blocking(1);\r
-       me_loop(e_menu_tray, &sel);\r
+       me_loop(e_menu_tray, &sel, NULL);\r
 \r
        if (engineState != PGS_RestartRun) {\r
                engineState = PGS_RestartRun;\r
@@ -2050,13 +2037,17 @@ void me_update_msg(const char *msg)
 \r
 // ------------ util ------------\r
 \r
-/* wiz for now, probably extend later */\r
+/* GP2X/wiz for now, probably extend later */\r
 void menu_plat_setup(int is_wiz)\r
 {\r
        int i;\r
 \r
-       if (!is_wiz)\r
+       if (!is_wiz) {\r
+               me_enable(e_menu_gfx_options, MA_OPT_TEARING_FIX, 0);\r
+               i = me_id2offset(e_menu_gfx_options, MA_OPT_TEARING_FIX);\r
+               e_menu_gfx_options[i].need_to_save = 0;\r
                return;\r
+       }\r
 \r
        me_enable(e_menu_adv_options, MA_OPT_ARM940_SOUND, 0);\r
        me_enable(e_menu_gfx_options, MA_OPT2_GAMMA, 0);\r
@@ -2064,6 +2055,8 @@ void menu_plat_setup(int is_wiz)
 \r
        i = me_id2offset(e_menu_gfx_options, MA_OPT_SCALING);\r
        e_menu_gfx_options[i].max = 1;  /* only off and sw */\r
+       i = me_id2offset(e_menu_gfx_options, MA_OPT_ARM940_SOUND);\r
+       e_menu_gfx_options[i].need_to_save = 0;\r
 }\r
 \r
 /* TODO: rename */\r
@@ -2102,6 +2095,7 @@ static menu_entry *e_menu_table[] =
        e_menu_gfx_options,\r
        e_menu_adv_options,\r
        e_menu_cd_options,\r
+       e_menu_32x_options,\r
        e_menu_keyconfig,\r
        e_menu_hidden,\r
 };\r