newstyle key config, code940.bin -> pico940.bin
authornotaz <notasas@gmail.com>
Sun, 19 Aug 2007 20:46:49 +0000 (20:46 +0000)
committernotaz <notasas@gmail.com>
Sun, 19 Aug 2007 20:46:49 +0000 (20:46 +0000)
git-svn-id: file:///home/notaz/opt/svn/PicoDrive/platform@222 be3aeb3a-fb24-0410-a615-afba39da0efa

gp2x/940ctl.c
gp2x/emu.c
gp2x/emu.h
gp2x/main.c
gp2x/menu.c

index 8b3c7fe..54b83b6 100644 (file)
@@ -30,6 +30,7 @@ _940_ctl_t *shared_ctl = 0;
 unsigned char *mp3_mem = 0;\r
 \r
 #define MP3_SIZE_MAX (0x400000 + 0x800000) // 12M\r
+#define CODE940_FILE "pico940.bin"\r
 \r
 int crashed_940 = 0;\r
 \r
@@ -409,14 +410,14 @@ void YM2612Init_940(int baseclock, int rate)
                binpath[1023] = 0;\r
                for (i = strlen(binpath); i > 0; i--)\r
                        if (binpath[i] == '/') { binpath[i] = 0; break; }\r
-               strcat(binpath, "/code940.bin");\r
+               strcat(binpath, "/" CODE940_FILE);\r
 \r
                fp = fopen(binpath, "rb");\r
                if(!fp)\r
                {\r
                        memset(gp2x_screen, 0, 320*240);\r
                        gp2x_text_out8(10, 100, "failed to open required file:");\r
-                       gp2x_text_out8(10, 110, "code940.bin");\r
+                       gp2x_text_out8(10, 110, CODE940_FILE);\r
                        gp2x_video_flip();\r
                        printf("failed to open %s\n", binpath);\r
                        exit(1);\r
index 27e9d13..cb924c3 100644 (file)
 #define OSD_FPS_X 260\r
 #endif\r
 \r
-// PicoPad[] format: SACB RLDU\r
-char *actionNames[] = {\r
-       "UP", "DOWN", "LEFT", "RIGHT", "B", "C", "A", "START",\r
-       0, 0, 0, 0, 0, 0, 0, 0, // Z, Y, X, MODE (enabled only when needed), ?, ?, ?, ?\r
-       0, 0, 0, 0, 0, 0, 0, "ENTER MENU", // player2_flag, ?, ?, ?, ?, ?, ?, menu\r
-       "NEXT SAVE SLOT", "PREV SAVE SLOT", "SWITCH RENDERER", "SAVE STATE",\r
-       "LOAD STATE", "VOLUME UP", "VOLUME DOWN", "DONE"\r
-};\r
 \r
 int engineState;\r
 int select_exits = 0;\r
@@ -319,9 +311,9 @@ int emu_ReloadRom(void)
        }\r
 \r
        // load config for this ROM (do this before insert to get correct region)\r
-       ret = emu_ReadConfig(1);\r
+       ret = emu_ReadConfig(1, 1);\r
        if (!ret)\r
-               emu_ReadConfig(0);\r
+               emu_ReadConfig(0, 1);\r
 \r
        printf("PicoCartInsert(%p, %d);\n", rom_data, rom_size);\r
        if(PicoCartInsert(rom_data, rom_size)) {\r
@@ -472,7 +464,7 @@ void scaling_update(void)
 }\r
 \r
 \r
-int emu_ReadConfig(int game)\r
+int emu_ReadConfig(int game, int no_defaults)\r
 {\r
        FILE *f;\r
        char cfg[512], extbuf[16];\r
@@ -480,33 +472,36 @@ int emu_ReadConfig(int game)
 \r
        if (!game)\r
        {\r
-               // set default config\r
-               memset(&currentConfig, 0, sizeof(currentConfig));\r
-               currentConfig.lastRomFile[0] = 0;\r
-               currentConfig.EmuOpt  = 0x1f | 0x600; // | confirm_save, cd_leds\r
-               currentConfig.PicoOpt = 0x0f | 0xe00; // | use_940, cd_pcm, cd_cdda\r
-               currentConfig.PsndRate = 22050; // 44100;\r
-               currentConfig.PicoRegion = 0; // auto\r
-               currentConfig.PicoAutoRgnOrder = 0x184; // US, EU, JP\r
-               currentConfig.Frameskip = -1; // auto\r
-               currentConfig.CPUclock = 200;\r
-               currentConfig.volume = 50;\r
-               currentConfig.KeyBinds[ 0] = 1<<0; // SACB RLDU\r
-               currentConfig.KeyBinds[ 4] = 1<<1;\r
-               currentConfig.KeyBinds[ 2] = 1<<2;\r
-               currentConfig.KeyBinds[ 6] = 1<<3;\r
-               currentConfig.KeyBinds[14] = 1<<4;\r
-               currentConfig.KeyBinds[13] = 1<<5;\r
-               currentConfig.KeyBinds[12] = 1<<6;\r
-               currentConfig.KeyBinds[ 8] = 1<<7;\r
-               currentConfig.KeyBinds[15] = 1<<26; // switch rend\r
-               currentConfig.KeyBinds[10] = 1<<27; // save state\r
-               currentConfig.KeyBinds[11] = 1<<28; // load state\r
-               currentConfig.KeyBinds[23] = 1<<29; // vol up\r
-               currentConfig.KeyBinds[22] = 1<<30; // vol down\r
-               currentConfig.gamma = 100;\r
-               currentConfig.PicoCDBuffers = 64;\r
-               currentConfig.scaling = 0;\r
+               if (!no_defaults)\r
+               {\r
+                       // set default config\r
+                       memset(&currentConfig, 0, sizeof(currentConfig));\r
+                       currentConfig.lastRomFile[0] = 0;\r
+                       currentConfig.EmuOpt  = 0x1f | 0x600; // | confirm_save, cd_leds\r
+                       currentConfig.PicoOpt = 0x0f | 0xe00; // | use_940, cd_pcm, cd_cdda\r
+                       currentConfig.PsndRate = 22050; // 44100;\r
+                       currentConfig.PicoRegion = 0; // auto\r
+                       currentConfig.PicoAutoRgnOrder = 0x184; // US, EU, JP\r
+                       currentConfig.Frameskip = -1; // auto\r
+                       currentConfig.CPUclock = 200;\r
+                       currentConfig.volume = 50;\r
+                       currentConfig.KeyBinds[ 0] = 1<<0; // SACB RLDU\r
+                       currentConfig.KeyBinds[ 4] = 1<<1;\r
+                       currentConfig.KeyBinds[ 2] = 1<<2;\r
+                       currentConfig.KeyBinds[ 6] = 1<<3;\r
+                       currentConfig.KeyBinds[14] = 1<<4;\r
+                       currentConfig.KeyBinds[13] = 1<<5;\r
+                       currentConfig.KeyBinds[12] = 1<<6;\r
+                       currentConfig.KeyBinds[ 8] = 1<<7;\r
+                       currentConfig.KeyBinds[15] = 1<<26; // switch rend\r
+                       currentConfig.KeyBinds[10] = 1<<27; // save state\r
+                       currentConfig.KeyBinds[11] = 1<<28; // load state\r
+                       currentConfig.KeyBinds[23] = 1<<29; // vol up\r
+                       currentConfig.KeyBinds[22] = 1<<30; // vol down\r
+                       currentConfig.gamma = 100;\r
+                       currentConfig.PicoCDBuffers = 64;\r
+                       currentConfig.scaling = 0;\r
+               }\r
                strncpy(cfg, PicoConfigFile, 511);\r
                if (config_slot != 0)\r
                {\r
@@ -539,10 +534,6 @@ int emu_ReadConfig(int game)
        PicoRegionOverride = currentConfig.PicoRegion;\r
        PicoAutoRgnOrder = currentConfig.PicoAutoRgnOrder;\r
        PicoCDBuffers = currentConfig.PicoCDBuffers;\r
-       if (PicoOpt & 0x20) {\r
-               actionNames[ 8] = "Z"; actionNames[ 9] = "Y";\r
-               actionNames[10] = "X"; actionNames[11] = "MODE";\r
-       }\r
        scaling_update();\r
        // some sanity checks\r
        if (currentConfig.CPUclock < 10 || currentConfig.CPUclock > 4096) currentConfig.CPUclock = 200;\r
index 17e855b..55bb53e 100644 (file)
@@ -47,7 +47,7 @@ void emu_Deinit(void);
 int  emu_SaveLoadGame(int load, int sram);\r
 void emu_Loop(void);\r
 void emu_ResetGame(void);\r
-int  emu_ReadConfig(int game);\r
+int  emu_ReadConfig(int game, int no_defaults);\r
 int  emu_WriteConfig(int game);\r
 char *emu_GetSaveFName(int load, int is_sram, int slot);\r
 int  emu_check_save_file(int slot);\r
index 4d8317e..d6438f6 100644 (file)
@@ -79,7 +79,7 @@ int main(int argc, char *argv[])
 {\r
        g_argv = argv;\r
 \r
-       emu_ReadConfig(0);\r
+       emu_ReadConfig(0, 0);\r
        gp2x_init();\r
        if (currentConfig.EmuOpt&0x10) {\r
                int ret = mmuhack();\r
index 8de891b..9b51d7c 100644 (file)
@@ -1,4 +1,4 @@
-// (c) Copyright 2006 notaz, All rights reserved.\r
+// (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
@@ -26,7 +26,6 @@
 #error "need d_type for file browser\r
 #endif\r
 \r
-extern char *actionNames[];\r
 extern char romFileName[PATH_MAX];\r
 extern char *rom_data;\r
 extern int  mmuhack_status;\r
@@ -817,17 +816,17 @@ static char *usb_joy_key_name(int joy, int num)
        return name;\r
 }\r
 \r
-static void draw_key_config(int curr_act, int is_p2)\r
+static char *action_binds(int player_idx, int action_mask)\r
 {\r
-       char strkeys[32*5];\r
+       static char strkeys[32*5];\r
        int joy, i;\r
 \r
        strkeys[0] = 0;\r
-       for (i = 0; i < 32; i++)\r
+       for (i = 0; i < 32; i++) // i is key index\r
        {\r
-               if (currentConfig.KeyBinds[i] & (1 << curr_act))\r
+               if (currentConfig.KeyBinds[i] & action_mask)\r
                {\r
-                       if (curr_act < 16 && (currentConfig.KeyBinds[i] & (1 << 16)) != (is_p2 << 16)) continue;\r
+                       if (player_idx >= 0 && ((currentConfig.KeyBinds[i] >> 16) & 3) != player_idx) continue;\r
                        if (strkeys[0]) { strcat(strkeys, " + "); strcat(strkeys, gp2xKeyNames[i]); break; }\r
                        else strcpy(strkeys, gp2xKeyNames[i]);\r
                }\r
@@ -836,9 +835,9 @@ static void draw_key_config(int curr_act, int is_p2)
        {\r
                for (i = 0; i < 32; i++)\r
                {\r
-                       if (currentConfig.JoyBinds[joy][i] & (1 << curr_act))\r
+                       if (currentConfig.JoyBinds[joy][i] & action_mask)\r
                        {\r
-                               if (curr_act < 16 && (currentConfig.JoyBinds[joy][i] & (1 << 16)) != (is_p2 << 16)) continue;\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
@@ -848,51 +847,122 @@ static void draw_key_config(int curr_act, int is_p2)
                }\r
        }\r
 \r
-       //memset(gp2x_screen, 0, 320*240);\r
+       return strkeys;\r
+}\r
+\r
+static void unbind_action(int action)\r
+{\r
+       int i, u;\r
+\r
+       for (i = 0; i < 32; i++)\r
+               currentConfig.KeyBinds[i] &= ~action;\r
+       for (u = 0; u < 4; u++)\r
+               for (i = 0; i < 32; i++)\r
+                       currentConfig.JoyBinds[u][i] &= ~action;\r
+}\r
+\r
+static int count_bound_keys(int action, int joy)\r
+{\r
+       int i, keys = 0;\r
+\r
+       if (joy)\r
+       {\r
+               for (i = 0; i < 32; i++)\r
+                       if (currentConfig.JoyBinds[joy-1][i] & action) keys++;\r
+       }\r
+       else\r
+       {\r
+               for (i = 0; i < 32; i++)\r
+                       if (currentConfig.KeyBinds[i] & action) keys++;\r
+       }\r
+       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
+{\r
+       int x, y, tl_y = 40, i;\r
+\r
        gp2x_pd_clone_buffer2();\r
-       gp2x_text_out8(60, 40, "Action: %s", actionNames[curr_act]);\r
-       gp2x_text_out8(60, 60, "Keys: %s", strkeys);\r
+       if (player_idx >= 0) {\r
+               gp2x_text_out8(80, 20, "Player %i controls", player_idx + 1);\r
+               x = 100;\r
+       } else {\r
+               gp2x_text_out8(80, 20, "Emulator controls");\r
+               x = 40;\r
+       }\r
+\r
+       y = tl_y;\r
+       for (i = 0; i < opt_cnt; i++, y+=10)\r
+               gp2x_text_out8(x, y, "%s : %s", opts[i].name, action_binds(player_idx, opts[i].mask));\r
+\r
+       gp2x_text_out8(x, y, "Done");\r
 \r
-       gp2x_text_out8(30, 180, "Use SELECT to change action");\r
-       gp2x_text_out8(30, 190, "Press a key to bind/unbind");\r
-       gp2x_text_out8(30, 200, "Select \"Done\" action and");\r
-       gp2x_text_out8(30, 210, "  press any key to finish");\r
+       // draw cursor\r
+       gp2x_text_out8(x - 16, tl_y + sel*10, ">");\r
+\r
+       if (sel < opt_cnt) {\r
+               gp2x_text_out8(30, 190, "Press a button to bind/unbind");\r
+               gp2x_text_out8(30, 200, "Use SELECT to clear");\r
+               gp2x_text_out8(30, 210, "To bind UP/DOWN, hold SELECT");\r
+               gp2x_text_out8(30, 220, "Select \"Done\" to exit");\r
+       } else {\r
+               gp2x_text_out8(30, 200, "Use Options -> Save cfg");\r
+               gp2x_text_out8(30, 210, "to save controls");\r
+               gp2x_text_out8(30, 220, "Press B or X to exit");\r
+       }\r
        gp2x_video_flip2();\r
 }\r
 \r
-static void key_config_loop(int is_p2)\r
+static void key_config_loop(const bind_action_t *opts, int opt_cnt, int player_idx)\r
 {\r
-       int curr_act = 0, joy = 0, i;\r
+       int joy = 0, sel = 0, menu_sel_max = opt_cnt, prev_select = 0, i;\r
        unsigned long inp = 0;\r
 \r
        for (;;)\r
        {\r
-               draw_key_config(curr_act, is_p2);\r
+               draw_key_config(opts, opt_cnt, player_idx, sel);\r
                inp = wait_for_input_usbjoy(CONFIGURABLE_KEYS, &joy);\r
                // printf("got %08lX from joy %i\n", inp, joy);\r
                if (joy == 0) {\r
-                       if (inp & GP2X_SELECT) {\r
-                               curr_act++;\r
-                               while (!actionNames[curr_act] && curr_act < 32) curr_act++;\r
-                               if (curr_act > 31) curr_act = 0;\r
+                       if (!(inp & GP2X_SELECT)) {\r
+                               prev_select = 0;\r
+                               if(inp & GP2X_UP  ) { sel--; if (sel < 0) sel = menu_sel_max; continue; }\r
+                               if(inp & GP2X_DOWN) { sel++; if (sel > menu_sel_max) sel = 0; continue; }\r
                        }\r
+                       if (sel >= opt_cnt) {\r
+                               if (inp & (GP2X_B|GP2X_X)) break;\r
+                               else continue;\r
+                       }\r
+                       // if we are here, we want to bind/unbind something\r
+                       if ((inp & GP2X_SELECT) && !prev_select)\r
+                               unbind_action(opts[sel].mask);\r
+                       prev_select = inp & GP2X_SELECT;\r
                        inp &= CONFIGURABLE_KEYS;\r
                        inp &= ~GP2X_SELECT;\r
-               }\r
-               if (curr_act == 31 && inp) break;\r
-               if (joy == 0) {\r
                        for (i = 0; i < 32; i++)\r
                                if (inp & (1 << i)) {\r
-                                       currentConfig.KeyBinds[i] ^= (1 << curr_act);\r
-                                       if (is_p2) currentConfig.KeyBinds[i] |=  (1 << 16); // player 2 flag\r
-                                       else       currentConfig.KeyBinds[i] &= ~(1 << 16);\r
+                                       if (count_bound_keys(opts[sel].mask, 0) >= 2)\r
+                                            currentConfig.KeyBinds[i] &= ~opts[sel].mask; // allow to unbind only\r
+                                       else currentConfig.KeyBinds[i] ^=  opts[sel].mask;\r
+                                       if (player_idx >= 0) {\r
+                                               currentConfig.KeyBinds[i] &= ~(3 << 16);\r
+                                               currentConfig.KeyBinds[i] |= player_idx << 16;\r
+                                       }\r
                                }\r
-               } else {\r
+               }\r
+               else if (sel < opt_cnt)\r
+               {\r
                        for (i = 0; i < 32; i++)\r
                                if (inp & (1 << i)) {\r
-                                       currentConfig.JoyBinds[joy-1][i] ^= (1 << curr_act);\r
-                                       if (is_p2) currentConfig.JoyBinds[joy-1][i] |=  (1 << 16);\r
-                                       else       currentConfig.JoyBinds[joy-1][i] &= ~(1 << 16);\r
+                                       if (count_bound_keys(opts[sel].mask, joy) >= 1) // disallow combos for usbjoy\r
+                                            currentConfig.JoyBinds[joy-1][i] &= ~opts[sel].mask;\r
+                                       else currentConfig.JoyBinds[joy-1][i] ^=  opts[sel].mask;\r
+                                       if (player_idx >= 0) {\r
+                                               currentConfig.JoyBinds[joy-1][i] &= ~(3 << 16);\r
+                                               currentConfig.JoyBinds[joy-1][i] |= player_idx << 16;\r
+                                       }\r
                                }\r
                }\r
        }\r
@@ -904,10 +974,10 @@ static void draw_kc_sel(int menu_sel)
        char joyname[36];\r
 \r
        y = tl_y;\r
-       //memset(gp2x_screen, 0, 320*240);\r
        gp2x_pd_clone_buffer2();\r
        gp2x_text_out8(tl_x, y,       "Player 1");\r
        gp2x_text_out8(tl_x, (y+=10), "Player 2");\r
+       gp2x_text_out8(tl_x, (y+=10), "Emulator controls");\r
        gp2x_text_out8(tl_x, (y+=10), "Done");\r
 \r
        // draw cursor\r
@@ -924,34 +994,69 @@ static void draw_kc_sel(int menu_sel)
                gp2x_text_out8(tl_x, (y+=10), "none");\r
        }\r
 \r
-\r
        gp2x_video_flip2();\r
 }\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
+{\r
+       { "Volume Down    ", 1<<30 },\r
+       { "Volume Up      ", 1<<29 },\r
+       { "Load State     ", 1<<28 },\r
+       { "Save State     ", 1<<27 },\r
+       { "Switch Renderer", 1<<26 },\r
+       { "Prev Save Slot ", 1<<25 },\r
+       { "Next Save Slot ", 1<<24 },\r
+       { "Enter Menu     ", 1<<23 },\r
+};\r
+\r
 static void kc_sel_loop(void)\r
 {\r
-       int menu_sel = 2, menu_sel_max = 2;\r
+       int menu_sel = 3, menu_sel_max = 3;\r
        unsigned long inp = 0;\r
+       int is_6button = currentConfig.PicoOpt & 0x020;\r
 \r
-       for(;;)\r
+       while (1)\r
        {\r
                draw_kc_sel(menu_sel);\r
                inp = wait_for_input(GP2X_UP|GP2X_DOWN|GP2X_B|GP2X_X);\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 & 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
                        switch (menu_sel) {\r
-                               case 0: key_config_loop(0); return;\r
-                               case 1: key_config_loop(1); return;\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 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
                                default: return;\r
                        }\r
                }\r
-               if(inp & GP2X_X) return;\r
+               if (inp & GP2X_X) return;\r
        }\r
 }\r
 \r
 \r
-\r
 // --------- sega/mega cd options ----------\r
 \r
 menu_entry cdopt_entries[] =\r
@@ -1359,11 +1464,9 @@ static void menu_options_save(void)
        PicoOpt = currentConfig.PicoOpt;\r
        PsndRate = currentConfig.PsndRate;\r
        PicoRegionOverride = currentConfig.PicoRegion;\r
-       if (PicoOpt & 0x20) {\r
-               actionNames[ 8] = "Z"; actionNames[ 9] = "Y";\r
-               actionNames[10] = "X"; actionNames[11] = "MODE";\r
-       } else {\r
-               actionNames[8] = actionNames[9] = actionNames[10] = actionNames[11] = 0;\r
+       if (!(PicoOpt & 0x20)) {\r
+               // unbind XYZ MODE, just in case\r
+               unbind_action(0xf00);\r
        }\r
        scaling_update();\r
 }\r
@@ -1382,6 +1485,7 @@ static int menu_loop_options(void)
        me_enable(opt_entries, OPT_ENTRY_COUNT, MA_OPT_SAVECFG_GAME, rom_data != NULL);\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
 \r
        while (1)\r
        {\r
@@ -1477,9 +1581,9 @@ static int menu_loop_options(void)
                                                else strcpy(menuErrorMsg, "failed to write config");\r
                                                return 1;\r
                                        case MA_OPT_LOADCFG:\r
-                                               ret = emu_ReadConfig(1);\r
-                                               if (!ret) ret = emu_ReadConfig(0);\r
-                                               if (!ret) strcpy(menuErrorMsg, "config loaded");\r
+                                               ret = emu_ReadConfig(1, 1);\r
+                                               if (!ret) ret = emu_ReadConfig(0, 1);\r
+                                               if (ret)  strcpy(menuErrorMsg, "config loaded");\r
                                                else      strcpy(menuErrorMsg, "failed to load config");\r
                                                return 1;\r
                                        default:\r
@@ -1585,6 +1689,7 @@ static void menu_loop_root(void)
        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
+       if (menu_sel > menu_sel_max) menu_sel = menu_sel_max;\r
 \r
        /* make sure action buttons are not pressed on entering menu */\r
        draw_menu_root(menu_sel);\r