bugfix, sprites adjustment
[picodrive.git] / platform / gizmondo / menu.c
index bf56c32..33c6fc0 100644 (file)
@@ -45,20 +45,20 @@ static void menu_darken_bg(void *dst, const void *src, int pixels, int darker);
 static void menu_prepare_bg(int use_game_bg);\r
 \r
 static unsigned int inp_prev = 0;\r
-static int inp_prevjoy = 0;\r
 \r
 static unsigned long wait_for_input(unsigned int interesting)\r
 {\r
-       unsigned int ret;\r
-       static int repeats = 0, wait = 50;\r
+       unsigned long ret;\r
+       static int repeats = 0, wait = 20;\r
        int release = 0, i;\r
 \r
-       if (repeats == 2 || repeats == 4) wait /= 2;\r
-       if (repeats == 6) wait = 15;\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 < 6 && inp_prev == Framework_PollGetButtons(); i++) {\r
+       for (i = 0; i < wait && inp_prev == Framework_PollGetButtons(); i++) {\r
                if (i == 0) repeats++;\r
-               Sleep(wait);\r
+               Sleep(30);\r
        }\r
 \r
        while ( !((ret = Framework_PollGetButtons()) & interesting) ) {\r
@@ -68,10 +68,11 @@ static unsigned long wait_for_input(unsigned int interesting)
 \r
        if (release || ret != inp_prev) {\r
                repeats = 0;\r
-               wait = 50;\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
-       inp_prevjoy = 0;\r
 \r
        // we don't need diagonals in menus\r
        if ((ret&BTN_UP)   && (ret&BTN_LEFT))  ret &= ~BTN_LEFT;\r
@@ -92,8 +93,7 @@ static void menu_draw_begin(int use_bgbuff)
 \r
 static void menu_draw_end(void)\r
 {\r
-       Framework2D_WaitVSync();\r
-       giz_screen = Framework2D_LockBuffer();\r
+       giz_screen = Framework2D_LockBuffer(0);\r
        if (giz_screen == NULL)\r
        {\r
                lprintf_al("%s: Framework2D_LockBuffer() returned NULL\n", __FUNCTION__);\r
@@ -102,6 +102,7 @@ static void menu_draw_end(void)
        memcpy32(giz_screen, (int *)menu_screen, 321*240*2/4);\r
        Framework2D_UnlockBuffer();\r
        giz_screen = NULL;\r
+       Framework2D_Flip(1);\r
 }\r
 \r
 \r
@@ -126,7 +127,7 @@ void menu_romload_prepare(const char *rom_name)
        const char *p = rom_name + strlen(rom_name);\r
        while (p > rom_name && *p != '/') p--;\r
 \r
-       if (rom_data == NULL)\r
+       if (!rom_loaded)\r
                memset(menu_screen, 0, 321*240*2);\r
        menu_draw_begin(1);\r
 \r
@@ -160,7 +161,7 @@ struct my_dirent
 static unsigned short file2color(const char *fname)\r
 {\r
        const char *ext = fname + strlen(fname) - 3;\r
-       static const char *rom_exts[]   = { "zip", "bin", "smd", "gen", "iso" };\r
+       static const char *rom_exts[]   = { "zip", "bin", "smd", "gen", "iso", "cso" };\r
        static const char *other_exts[] = { "gmv", "pat" };\r
        int i;\r
 \r
@@ -181,7 +182,7 @@ static void draw_dirlist(char *curdir, struct my_dirent **namelist, int n, int s
 \r
        menu_draw_begin(1);\r
 \r
-       if (rom_data == NULL) {\r
+       if (!rom_loaded) {\r
                menu_darken_bg(menu_screen, menu_screen, 321*240, 0);\r
        }\r
 \r
@@ -264,10 +265,10 @@ static int my_scandir(const char *dir, struct my_dirent ***namelist_out,
        BOOL bRet;\r
 \r
        wdir = malloc(sizeof(wdir[0]) * MAX_PATH);\r
-       if (wdir == NULL) { lprintf_al("%s:%s: OOM\n", __FILE__, __LINE__); goto fail; }\r
+       if (wdir == NULL) { lprintf_al("%s:%i: OOM\n", __FILE__, __LINE__); goto fail; }\r
 \r
        namelist = malloc(sizeof(*namelist) * name_alloc);\r
-       if (namelist == NULL) { lprintf_al("%s:%s: OOM\n", __FILE__, __LINE__); goto fail; }\r
+       if (namelist == NULL) { lprintf_al("%s:%i: OOM\n", __FILE__, __LINE__); goto fail; }\r
 \r
        // try to read first..\r
        len = cstr2wstr(wdir, dir);\r
@@ -312,7 +313,7 @@ static int my_scandir(const char *dir, struct my_dirent ***namelist_out,
                        void *tmp;\r
                        name_alloc *= 2;\r
                        tmp = realloc(namelist, sizeof(*namelist) * name_alloc);\r
-                       if (tmp == NULL) { lprintf_al("%s:%s: OOM\n", __FILE__, __LINE__); goto fail; }\r
+                       if (tmp == NULL) { lprintf_al("%s:%i: OOM\n", __FILE__, __LINE__); goto fail; }\r
                        namelist = tmp;\r
                }\r
 \r
@@ -563,7 +564,7 @@ static void draw_savestate_bg(int slot)
        }\r
 \r
        if (file) {\r
-               if (PicoMCD & 1) {\r
+               if (PicoAHW & 1) {\r
                        PicoCdLoadStateGfx(file);\r
                } else {\r
                        areaSeek(file, 0x10020, SEEK_SET);  // skip header and RAM in state file\r
@@ -577,7 +578,7 @@ static void draw_savestate_bg(int slot)
                areaClose(file);\r
        }\r
 \r
-       emu_forcedFrame();\r
+       emu_forcedFrame(POPT_EN_SOFTSCALE);\r
        menu_prepare_bg(1);\r
 \r
        memcpy(Pico.vram, tmp_vram, sizeof(Pico.vram));\r
@@ -635,6 +636,7 @@ static int savestate_menu_loop(int is_loading)
                if(inp & BTN_PLAY) { // save/load\r
                        if (menu_sel < 10) {\r
                                state_slot = menu_sel;\r
+                               PicoStateProgressCB = emu_stateCb; /* also suitable for menu */\r
                                if (emu_SaveLoadGame(is_loading, 0)) {\r
                                        strcpy(menuErrorMsg, is_loading ? "Load failed" : "Save failed");\r
                                        return 1;\r
@@ -688,9 +690,7 @@ static int count_bound_keys(int action, int pl_idx)
        return keys;\r
 }\r
 \r
-typedef struct { char *name; int mask; } bind_action_t;\r
-\r
-static void draw_key_config(const bind_action_t *opts, int opt_cnt, int player_idx, int sel)\r
+static void draw_key_config(const me_bind_action *opts, int opt_cnt, int player_idx, int sel)\r
 {\r
        int x, y, tl_y = 40, i;\r
 \r
@@ -724,7 +724,7 @@ static void draw_key_config(const bind_action_t *opts, int opt_cnt, int player_i
        menu_draw_end();\r
 }\r
 \r
-static void key_config_loop(const bind_action_t *opts, int opt_cnt, int player_idx)\r
+static void key_config_loop(const me_bind_action *opts, int opt_cnt, int player_idx)\r
 {\r
        int sel = 0, menu_sel_max = opt_cnt, prev_select = 0, i;\r
        unsigned long inp = 0;\r
@@ -778,27 +778,10 @@ static void draw_kc_sel(int menu_sel)
 }\r
 \r
 \r
-// PicoPad[] format: MXYZ SACB RLDU\r
-static bind_action_t ctrl_actions[] =\r
-{\r
-       { "UP     ", 0x001 },\r
-       { "DOWN   ", 0x002 },\r
-       { "LEFT   ", 0x004 },\r
-       { "RIGHT  ", 0x008 },\r
-       { "A      ", 0x040 },\r
-       { "B      ", 0x010 },\r
-       { "C      ", 0x020 },\r
-       { "START  ", 0x080 },\r
-       { "MODE   ", 0x800 },\r
-       { "X      ", 0x400 },\r
-       { "Y      ", 0x200 },\r
-       { "Z      ", 0x100 },\r
-};\r
-\r
 // player2_flag, ?, ?, ?, ?, ?, ?, menu\r
 // "NEXT SAVE SLOT", "PREV SAVE SLOT", "SWITCH RENDERER", "SAVE STATE",\r
 // "LOAD STATE", "VOLUME UP", "VOLUME DOWN", "DONE"\r
-static bind_action_t emuctrl_actions[] =\r
+me_bind_action emuctrl_actions[] =\r
 {\r
        { "Load State     ", 1<<28 },\r
        { "Save State     ", 1<<27 },\r
@@ -807,6 +790,7 @@ static bind_action_t emuctrl_actions[] =
        { "Switch Renderer", 1<<26 },\r
        { "Volume Down    ", 1<<30 },\r
        { "Volume Up      ", 1<<29 },\r
+       { NULL,              0     }\r
 };\r
 \r
 static void kc_sel_loop(void)\r
@@ -823,11 +807,11 @@ static void kc_sel_loop(void)
                if (inp & BTN_DOWN) { menu_sel++; if (menu_sel > menu_sel_max) menu_sel = 0; }\r
                if (inp & BTN_PLAY) {\r
                        switch (menu_sel) {\r
-                               case 0: key_config_loop(ctrl_actions, is_6button ? 12 : 8, 0); return;\r
-                               case 1: key_config_loop(ctrl_actions, is_6button ? 12 : 8, 1); return;\r
+                               case 0: key_config_loop(me_ctrl_actions, is_6button ? 12 : 8, 0); return;\r
+                               case 1: key_config_loop(me_ctrl_actions, is_6button ? 12 : 8, 1); return;\r
                                case 2: key_config_loop(emuctrl_actions,\r
-                                               sizeof(emuctrl_actions)/sizeof(emuctrl_actions[0]), -1); return;\r
-                               case 3: if (rom_data == NULL) emu_WriteConfig(0); return;\r
+                                               sizeof(emuctrl_actions)/sizeof(emuctrl_actions[0]) - 1, -1); return;\r
+                               case 3: if (!rom_loaded) emu_WriteConfig(0); return;\r
                                default: return;\r
                        }\r
                }\r
@@ -940,9 +924,9 @@ static void cd_menu_loop_options(void)
                            selected_id == MA_CDOPT_READAHEAD) {\r
                                if (inp & BTN_LEFT) {\r
                                        PicoCDBuffers >>= 1;\r
-                                       if (PicoCDBuffers < 64) PicoCDBuffers = 0;\r
+                                       if (PicoCDBuffers < 2) PicoCDBuffers = 0;\r
                                } else {\r
-                                       if (PicoCDBuffers < 64) PicoCDBuffers = 64;\r
+                                       if (PicoCDBuffers < 2) PicoCDBuffers = 2;\r
                                        else PicoCDBuffers <<= 1;\r
                                        if (PicoCDBuffers > 8*1024) PicoCDBuffers = 8*1024; // 16M\r
                                }\r
@@ -988,9 +972,11 @@ static void cd_menu_loop_options(void)
 \r
 menu_entry opt2_entries[] =\r
 {\r
+       { "Disable sprite limit",      MB_ONOFF, MA_OPT2_NO_SPRITE_LIM, &PicoOpt, 0x40000, 0, 0, 1, 1 },\r
        { "Emulate Z80",               MB_ONOFF, MA_OPT2_ENABLE_Z80,    &currentConfig.PicoOpt,0x0004, 0, 0, 1 },\r
        { "Emulate YM2612 (FM)",       MB_ONOFF, MA_OPT2_ENABLE_YM2612, &currentConfig.PicoOpt,0x0001, 0, 0, 1 },\r
        { "Emulate SN76496 (PSG)",     MB_ONOFF, MA_OPT2_ENABLE_SN76496,&currentConfig.PicoOpt,0x0002, 0, 0, 1 },\r
+       { "Double buffering",          MB_ONOFF, MA_OPT2_DBLBUFF,       &currentConfig.EmuOpt, 0x8000, 0, 0, 1 },\r
        { "Wait for V-sync (slow)",    MB_ONOFF, MA_OPT2_VSYNC,         &currentConfig.EmuOpt, 0x2000, 0, 0, 1 },\r
        { "gzip savestates",           MB_ONOFF, MA_OPT2_GZIP_STATES,   &currentConfig.EmuOpt, 0x0008, 0, 0, 1 },\r
        { "Don't save last used ROM",  MB_ONOFF, MA_OPT2_NO_LAST_ROM,   &currentConfig.EmuOpt, 0x0020, 0, 0, 1 },\r
@@ -1057,9 +1043,8 @@ static void amenu_loop_options(void)
 menu_entry opt_entries[] =\r
 {\r
        { NULL,                        MB_NONE,  MA_OPT_RENDERER,      NULL, 0, 0, 0, 1 },\r
-       { "Interlaced rend. (faster)", MB_ONOFF, MA_OPT_INTERLACED,    &currentConfig.EmuOpt,  0x4000, 0, 0, 1 },\r
+       { "Scanline mode (faster)",    MB_ONOFF, MA_OPT_INTERLACED,    &currentConfig.EmuOpt,  0x4000, 0, 0, 1 },\r
        { "Scale low res mode",        MB_ONOFF, MA_OPT_SCALING,       &currentConfig.scaling, 0x0001, 0, 3, 1 },\r
-       { "Accurate timing (slower)",  MB_ONOFF, MA_OPT_ACC_TIMING,    &currentConfig.PicoOpt, 0x0040, 0, 0, 1 },\r
        { "Accurate sprites (slower)", MB_ONOFF, MA_OPT_ACC_SPRITES,   &currentConfig.PicoOpt, 0x0080, 0, 0, 1 },\r
        { "Show FPS",                  MB_ONOFF, MA_OPT_SHOW_FPS,      &currentConfig.EmuOpt,  0x0002, 0, 0, 1 },\r
        { NULL,                        MB_RANGE, MA_OPT_FRAMESKIP,     &currentConfig.Frameskip, 0, -1, 16, 1 },\r
@@ -1080,29 +1065,6 @@ menu_entry opt_entries[] =
 #define OPT_ENTRY_COUNT (sizeof(opt_entries) / sizeof(opt_entries[0]))\r
 \r
 \r
-static const char *region_name(unsigned int code)\r
-{\r
-       static const char *names[] = { "Auto", "      Japan NTSC", "      Japan PAL", "      USA", "      Europe" };\r
-       static const char *names_short[] = { "", " JP", " JP", " US", " EU" };\r
-       int u, i = 0;\r
-       if (code) {\r
-               code <<= 1;\r
-               while((code >>= 1)) i++;\r
-               if (i > 4) return "unknown";\r
-               return names[i];\r
-       } else {\r
-               static char name[24];\r
-               strcpy(name, "Auto:");\r
-               for (u = 0; u < 3; u++) {\r
-                       i = 0; code = ((PicoAutoRgnOrder >> u*4) & 0xf) << 1;\r
-                       while((code >>= 1)) i++;\r
-                       strcat(name, names_short[i]);\r
-               }\r
-               return name;\r
-       }\r
-}\r
-\r
-\r
 static void menu_opt_cust_draw(const menu_entry *entry, int x, int y, void *param)\r
 {\r
        char *str, str24[24];\r
@@ -1129,7 +1091,7 @@ static void menu_opt_cust_draw(const menu_entry *entry, int x, int y, void *para
                        text_out16(x, y, "Sound Quality:     %5iHz %s", currentConfig.PsndRate, str);\r
                        break;\r
                case MA_OPT_REGION:\r
-                       text_out16(x, y, "Region:              %s", region_name(currentConfig.PicoRegion));\r
+                       text_out16(x, y, "Region:              %s", me_region_name(PicoRegionOverride, PicoAutoRgnOrder));\r
                        break;\r
                case MA_OPT_CONFIRM_STATES:\r
                        switch ((currentConfig.EmuOpt >> 9) & 5) {\r
@@ -1188,21 +1150,21 @@ static void region_prevnext(int right)
        static int rgn_orders[] = { 0x148, 0x184, 0x814, 0x418, 0x841, 0x481 };\r
        int i;\r
        if (right) {\r
-               if (!currentConfig.PicoRegion) {\r
+               if (!PicoRegionOverride) {\r
                        for (i = 0; i < 6; i++)\r
                                if (rgn_orders[i] == PicoAutoRgnOrder) break;\r
                        if (i < 5) PicoAutoRgnOrder = rgn_orders[i+1];\r
-                       else currentConfig.PicoRegion=1;\r
+                       else PicoRegionOverride=1;\r
                }\r
-               else currentConfig.PicoRegion<<=1;\r
-               if (currentConfig.PicoRegion > 8) currentConfig.PicoRegion = 8;\r
+               else PicoRegionOverride<<=1;\r
+               if (PicoRegionOverride > 8) PicoRegionOverride = 8;\r
        } else {\r
-               if (!currentConfig.PicoRegion) {\r
+               if (!PicoRegionOverride) {\r
                        for (i = 0; i < 6; i++)\r
                                if (rgn_orders[i] == PicoAutoRgnOrder) break;\r
                        if (i > 0) PicoAutoRgnOrder = rgn_orders[i-1];\r
                }\r
-               else currentConfig.PicoRegion>>=1;\r
+               else PicoRegionOverride>>=1;\r
        }\r
 }\r
 \r
@@ -1210,7 +1172,10 @@ static void menu_options_save(void)
 {\r
        PicoOpt = currentConfig.PicoOpt;\r
        PsndRate = currentConfig.PsndRate;\r
-       PicoRegionOverride = currentConfig.PicoRegion;\r
+       if (PicoRegionOverride) {\r
+               // force setting possibly changed..\r
+               Pico.m.pal = (PicoRegionOverride == 2 || PicoRegionOverride == 8) ? 1 : 0;\r
+       }\r
        if (!(PicoOpt & 0x20)) {\r
                // unbind XYZ MODE, just in case\r
                unbind_action(0xf00);\r
@@ -1226,9 +1191,8 @@ static int menu_loop_options(void)
 \r
        currentConfig.PicoOpt = PicoOpt;\r
        currentConfig.PsndRate = PsndRate;\r
-       currentConfig.PicoRegion = PicoRegionOverride;\r
 \r
-       me_enable(opt_entries, OPT_ENTRY_COUNT, MA_OPT_SAVECFG_GAME, rom_data != NULL);\r
+       me_enable(opt_entries, OPT_ENTRY_COUNT, MA_OPT_SAVECFG_GAME, rom_loaded);\r
        me_enable(opt_entries, OPT_ENTRY_COUNT, MA_OPT_LOADCFG, config_slot != config_slot_current);\r
        menu_sel_max = me_count_enabled(opt_entries, OPT_ENTRY_COUNT) - 1;\r
        if (menu_sel > menu_sel_max) menu_sel = menu_sel_max;\r
@@ -1263,7 +1227,7 @@ static int menu_loop_options(void)
                                                        currentConfig.PsndRate =  11025;\r
                                                        currentConfig.PicoOpt |=  8;\r
                                                } else if ((inp & BTN_LEFT) && currentConfig.PsndRate == 11025 &&\r
-                                                               (currentConfig.PicoOpt&0x08) && !(PicoMCD&1))\r
+                                                               (currentConfig.PicoOpt&0x08) && !(PicoAHW&1))\r
                                                {\r
                                                        currentConfig.PsndRate =  44100;\r
                                                        currentConfig.PicoOpt &= ~8;\r
@@ -1350,25 +1314,27 @@ static int menu_loop_options(void)
 \r
 static void draw_menu_credits(void)\r
 {\r
-       int tl_x = 15, tl_y = 64, y;\r
+       int tl_x = 15, tl_y = 56, y;\r
        menu_draw_begin(1);\r
 \r
-       text_out16(tl_x, 20, "PicoDrive v" VERSION " (c) notaz, 2006,2007");\r
-text_out16(tl_x, 30, "rc1");\r
+       text_out16(tl_x, 20, "PicoDrive v" VERSION " (c) notaz, 2006-2008");\r
+\r
        y = tl_y;\r
        text_out16(tl_x, y, "Credits:");\r
-       text_out16(tl_x, (y+=10), "Dave: Cyclone 68000 core,");\r
+       text_out16(tl_x, (y+=10), "fDave: Cyclone 68000 core,");\r
        text_out16(tl_x, (y+=10), "      base code of PicoDrive");\r
        text_out16(tl_x, (y+=10), "Reesy & FluBBa: DrZ80 core");\r
        text_out16(tl_x, (y+=10), "MAME devs: YM2612 and SN76496 cores");\r
-       text_out16(tl_x, (y+=10), "Charles MacDonald: Genesis hw docs");\r
-       text_out16(tl_x, (y+=10), "Stephane Dallongeville:");\r
-       text_out16(tl_x, (y+=10), "      opensource Gens");\r
-       text_out16(tl_x, (y+=10), "Haze: Genesis hw info");\r
        text_out16(tl_x, (y+=10), "Reesy: kgsdk wrapper, sound code");\r
        text_out16(tl_x, (y+=10), "jens.l: gizmondo hardware");\r
        text_out16(tl_x, (y+=10), "ketchupgun: skin design");\r
 \r
+       text_out16(tl_x, (y+=20), "special thanks (for docs, ideas)");\r
+       text_out16(tl_x, (y+=10), " Charles MacDonald, Haze,");\r
+       text_out16(tl_x, (y+=10), " Stephane Dallongeville,");\r
+       text_out16(tl_x, (y+=10), " Lordus, Exophase, Rokas,");\r
+       text_out16(tl_x, (y+=10), " Nemesis, Tasco Deluxe");\r
+\r
        menu_draw_end();\r
 }\r
 \r
@@ -1418,10 +1384,10 @@ static void menu_loop_root(void)
        int ret, menu_sel_max;\r
        unsigned long inp = 0;\r
 \r
-       me_enable(main_entries, MAIN_ENTRY_COUNT, MA_MAIN_RESUME_GAME, rom_data != NULL);\r
-       me_enable(main_entries, MAIN_ENTRY_COUNT, MA_MAIN_SAVE_STATE,  rom_data != NULL);\r
-       me_enable(main_entries, MAIN_ENTRY_COUNT, MA_MAIN_LOAD_STATE,  rom_data != NULL);\r
-       me_enable(main_entries, MAIN_ENTRY_COUNT, MA_MAIN_RESET_GAME,  rom_data != NULL);\r
+       me_enable(main_entries, MAIN_ENTRY_COUNT, MA_MAIN_RESUME_GAME, rom_loaded);\r
+       me_enable(main_entries, MAIN_ENTRY_COUNT, MA_MAIN_SAVE_STATE,  rom_loaded);\r
+       me_enable(main_entries, MAIN_ENTRY_COUNT, MA_MAIN_LOAD_STATE,  rom_loaded);\r
+       me_enable(main_entries, MAIN_ENTRY_COUNT, MA_MAIN_RESET_GAME,  rom_loaded);\r
        me_enable(main_entries, MAIN_ENTRY_COUNT, MA_MAIN_PATCHES,     PicoPatches != NULL);\r
 \r
        menu_sel_max = me_count_enabled(main_entries, MAIN_ENTRY_COUNT) - 1;\r
@@ -1440,7 +1406,7 @@ static void menu_loop_root(void)
                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
-                       if (rom_data) {\r
+                       if (rom_loaded) {\r
                                while (Framework_PollGetButtons() & (BTN_HOME|BTN_STOP)) Sleep(50); // wait until released\r
                                engineState = PGS_Running;\r
                                break;\r
@@ -1450,14 +1416,14 @@ static void menu_loop_root(void)
                        switch (me_index2id(main_entries, MAIN_ENTRY_COUNT, menu_sel))\r
                        {\r
                                case MA_MAIN_RESUME_GAME:\r
-                                       if (rom_data) {\r
+                                       if (rom_loaded) {\r
                                                while (Framework_PollGetButtons() & BTN_PLAY) Sleep(50);\r
                                                engineState = PGS_Running;\r
                                                return;\r
                                        }\r
                                        break;\r
                                case MA_MAIN_SAVE_STATE:\r
-                                       if (rom_data) {\r
+                                       if (rom_loaded) {\r
                                                if(savestate_menu_loop(0))\r
                                                        continue;\r
                                                engineState = PGS_Running;\r
@@ -1465,16 +1431,18 @@ static void menu_loop_root(void)
                                        }\r
                                        break;\r
                                case MA_MAIN_LOAD_STATE:\r
-                                       if (rom_data) {\r
+                                       if (rom_loaded) {\r
                                                if(savestate_menu_loop(1))\r
                                                        continue;\r
+                                               while (Framework_PollGetButtons() & BTN_PLAY) Sleep(50);\r
                                                engineState = PGS_Running;\r
                                                return;\r
                                        }\r
                                        break;\r
                                case MA_MAIN_RESET_GAME:\r
-                                       if (rom_data) {\r
+                                       if (rom_loaded) {\r
                                                emu_ResetGame();\r
+                                               while (Framework_PollGetButtons() & BTN_PLAY) Sleep(50);\r
                                                engineState = PGS_Running;\r
                                                return;\r
                                        }\r
@@ -1516,7 +1484,7 @@ static void menu_loop_root(void)
                                        engineState = PGS_Quit;\r
                                        return;\r
                                case MA_MAIN_PATCHES:\r
-                                       if (rom_data && PicoPatches) {\r
+                                       if (rom_loaded && PicoPatches) {\r
                                                patches_menu_loop();\r
                                                PicoPatchApply();\r
                                                strcpy(menuErrorMsg, "Patches applied");\r
@@ -1562,7 +1530,7 @@ static void menu_prepare_bg(int use_game_bg)
        {\r
                // darken the active framebuffer\r
                if (giz_screen == NULL)\r
-                       giz_screen = Framework2D_LockBuffer();\r
+                       giz_screen = Framework2D_LockBuffer(1);\r
                memset(bg_buffer, 0, 321*8*2);\r
                menu_darken_bg(bg_buffer + 321*8*2, (char *)giz_screen + 321*8*2, 321*224, 1);\r
                memset(bg_buffer + 321*232*2, 0, 321*8*2);\r
@@ -1582,7 +1550,7 @@ static void menu_prepare_bg(int use_game_bg)
 \r
 static void menu_gfx_prepare(void)\r
 {\r
-       menu_prepare_bg(rom_data != NULL);\r
+       menu_prepare_bg(rom_loaded);\r
 \r
        menu_draw_begin(1);\r
        menu_draw_end();\r
@@ -1656,10 +1624,11 @@ int menu_loop_tray(void)
                                case 0: // select image\r
                                        selfname = romsel_loop(curr_path);\r
                                        if (selfname) {\r
-                                               int ret = -1, cd_type;\r
+                                               int ret = -1;\r
+                                               cd_img_type cd_type;\r
                                                cd_type = emu_cdCheck(NULL);\r
-                                               if (cd_type > 0)\r
-                                                       ret = Insert_CD(romFileName, cd_type == 2);\r
+                                               if (cd_type != CIT_NOT_CD)\r
+                                                       ret = Insert_CD(romFileName, cd_type);\r
                                                if (ret != 0) {\r
                                                        sprintf(menuErrorMsg, "Load failed, invalid CD image?");\r
                                                        lprintf("%s\n", menuErrorMsg);\r