major menu unification, minor reorganization
authornotaz <notasas@gmail.com>
Mon, 2 Mar 2009 23:13:15 +0000 (23:13 +0000)
committernotaz <notasas@gmail.com>
Mon, 2 Mar 2009 23:13:15 +0000 (23:13 +0000)
git-svn-id: file:///home/notaz/opt/svn/PicoDrive/platform@639 be3aeb3a-fb24-0410-a615-afba39da0efa

21 files changed:
common/config.c
common/emu.c
common/emu.h
common/input.c
common/input.h
common/menu.c
common/menu.h
common/plat.h
common/posix.h [new file with mode: 0644]
gp2x/Makefile
gp2x/emu.c
gp2x/emu.h
gp2x/in_gp2x.c
gp2x/main.c
linux/Makefile
linux/plat.c [new file with mode: 0644]
pandora/emu.c
pandora/main.c
psp/emu.c
psp/emu.h
psp/main.c

index 63c8f00..961ac92 100644 (file)
@@ -21,44 +21,8 @@ static char *mystrip(char *str);
 #include "emu.h"
 #include <pico/pico.h>
 
-extern menu_entry opt_entries[];
-extern menu_entry opt2_entries[];
-extern menu_entry cdopt_entries[];
-extern menu_entry ctrlopt_entries[];
-extern const int opt_entry_count;
-extern const int opt2_entry_count;
-extern const int cdopt_entry_count;
-extern const int ctrlopt_entry_count;
-#ifdef PSP
-extern menu_entry opt3_entries[];
-extern const int opt3_entry_count;
-#endif
-
-static menu_entry *cfg_opts[] =
-{
-       opt_entries,
-       opt2_entries,
-       cdopt_entries,
-       ctrlopt_entries,
-#ifdef PSP
-       opt3_entries,
-#endif
-};
-
-static const int *cfg_opt_counts[] =
-{
-       &opt_entry_count,
-       &opt2_entry_count,
-       &cdopt_entry_count,
-       &ctrlopt_entry_count,
-#ifdef PSP
-       &opt3_entry_count,
-#endif
-};
-
 #define NL "\r\n"
 
-
 static int seek_sect(FILE *f, const char *section)
 {
        char line[128], *tmp;
@@ -82,79 +46,10 @@ static int seek_sect(FILE *f, const char *section)
 
 static void custom_write(FILE *f, const menu_entry *me, int no_def)
 {
-       char *str, str24[24];
+       char str24[24];
 
        switch (me->id)
        {
-               case MA_OPT_RENDERER:
-                       if (no_def && !((defaultConfig.s_PicoOpt^PicoOpt)&POPT_ALT_RENDERER) &&
-                               !((defaultConfig.EmuOpt^currentConfig.EmuOpt)&0x80)) return;
-                       if (PicoOpt&POPT_ALT_RENDERER)
-                               str =
-#ifndef PSP
-                               "8bit "
-#endif
-                               "fast";
-                       else if (currentConfig.EmuOpt&0x80)
-                               str =
-#ifndef PSP
-                               "16bit "
-#endif
-                               "accurate";
-                       else
-                               str = "8bit accurate";
-                       fprintf(f, "Renderer = %s", str);
-                       break;
-
-               case MA_OPT_SCALING:
-                       if (no_def && defaultConfig.scaling == currentConfig.scaling) return;
-#ifdef __GP2X__
-                       switch (currentConfig.scaling) {
-                               default: str = "OFF"; break;
-                               case 1:  str = "hw horizontal";     break;
-                               case 2:  str = "hw horiz. + vert."; break;
-                               case 3:  str = "sw horizontal";     break;
-                       }
-                       fprintf(f, "Scaling = %s", str);
-#endif
-                       break;
-               case MA_OPT_FRAMESKIP:
-                       if (no_def && defaultConfig.Frameskip == currentConfig.Frameskip) return;
-                       if (currentConfig.Frameskip < 0)
-                            strcpy(str24, "Auto");
-                       else sprintf(str24, "%i", currentConfig.Frameskip);
-                       fprintf(f, "Frameskip = %s", str24);
-                       break;
-               case MA_OPT_SOUND_QUALITY:
-                       if (no_def && !((defaultConfig.s_PicoOpt^PicoOpt)&POPT_EN_STEREO) &&
-                               defaultConfig.s_PsndRate == PsndRate) return;
-                       str = (PicoOpt&POPT_EN_STEREO)?"stereo":"mono";
-                       fprintf(f, "Sound Quality = %i %s", PsndRate, str);
-                       break;
-               case MA_OPT_REGION:
-                       if (no_def && defaultConfig.s_PicoRegion == PicoRegionOverride &&
-                               defaultConfig.s_PicoAutoRgnOrder == PicoAutoRgnOrder) return;
-                       strncpy(str24, me_region_name(PicoRegionOverride, PicoAutoRgnOrder), 23); str24[23] = 0;
-                       fprintf(f, "Region = %s", mystrip(str24));
-                       break;
-               case MA_OPT_CONFIRM_STATES:
-                       if (no_def && !((defaultConfig.EmuOpt^currentConfig.EmuOpt)&(5<<9))) return;
-                       switch ((currentConfig.EmuOpt >> 9) & 5) {
-                               default: str = "OFF";    break;
-                               case 1:  str = "writes"; break;
-                               case 4:  str = "loads";  break;
-                               case 5:  str = "both";   break;
-                       }
-                       fprintf(f, "Confirm savestate = %s", str);
-                       break;
-               case MA_OPT_CPU_CLOCKS:
-                       if (no_def && defaultConfig.CPUclock == currentConfig.CPUclock) return;
-#ifdef __GP2X__
-                       fprintf(f, "GP2X CPU clocks = %i", currentConfig.CPUclock);
-#elif defined(PSP)
-                       fprintf(f, "PSP CPU clock = %i", currentConfig.CPUclock);
-#endif
-                       break;
                case MA_OPT2_GAMMA:
                        if (no_def && defaultConfig.gamma == currentConfig.gamma) return;
                        fprintf(f, "Gamma correction = %.3f", (double)currentConfig.gamma / 100.0);
@@ -299,7 +194,7 @@ int config_writesect(const char *fname, const char *section)
        FILE *fo = NULL, *fn = NULL; // old and new
        int no_defaults = 0; // avoid saving defaults
        menu_entry *me;
-       int t, i, tlen, ret;
+       int t, tlen, ret;
        char line[128], *tmp;
 
        if (section != NULL)
@@ -368,30 +263,34 @@ write:
        if (section != NULL)
                fprintf(fn, "[%s]" NL, section);
 
-       for (t = 0; t < sizeof(cfg_opts) / sizeof(cfg_opts[0]); t++)
+       me = me_list_get_first();
+       while (me != NULL)
        {
-               me = cfg_opts[t];
-               tlen = *(cfg_opt_counts[t]);
-               for (i = 0; i < tlen; i++, me++)
-               {
-                       if (!me->need_to_save) continue;
-                       if ((me->beh != MB_ONOFF && me->beh != MB_RANGE) || me->name == NULL)
-                               custom_write(fn, me, no_defaults);
-                       else if (me->beh == MB_ONOFF) {
-                               if (!no_defaults || ((*(int *)me->var ^ default_var(me)) & me->mask))
-                                       fprintf(fn, "%s = %i" NL, me->name, (*(int *)me->var & me->mask) ? 1 : 0);
-                       } else if (me->beh == MB_RANGE) {
-                               if (!no_defaults || (*(int *)me->var ^ default_var(me)))
-                                       fprintf(fn, "%s = %i" NL, me->name, *(int *)me->var);
-                       }
-               }
+               int dummy;
+               if (!me->need_to_save)
+                       goto next;
+               if (me->beh == MB_OPT_ONOFF) {
+                       if (!no_defaults || ((*(int *)me->var ^ default_var(me)) & me->mask))
+                               fprintf(fn, "%s = %i" NL, me->name, (*(int *)me->var & me->mask) ? 1 : 0);
+               } else if (me->beh == MB_OPT_RANGE) {
+                       if (!no_defaults || (*(int *)me->var ^ default_var(me)))
+                               fprintf(fn, "%s = %i" NL, me->name, *(int *)me->var);
+               } else if (me->name != NULL && me->generate_name != NULL) {
+                       strncpy(line, me->generate_name(0, &dummy), sizeof(line));
+                       line[sizeof(line) - 1] = 0;
+                       mystrip(line);
+                       fprintf(fn, "%s = %s" NL, me->name, line);
+               } else
+                       custom_write(fn, me, no_defaults);
+next:
+               me = me_list_get_next();
        }
 
        /* input: save device names */
        for (t = 0; t < IN_MAX_DEVS; t++)
        {
                const int  *binds = in_get_dev_binds(t);
-               const char *name =  in_get_dev_name(t, 0);
+               const char *name =  in_get_dev_name(t, 0, 0);
                if (binds == NULL || name == NULL)
                        continue;
 
@@ -402,7 +301,7 @@ write:
        for (t = 0; t < IN_MAX_DEVS; t++)
        {
                const int *binds = in_get_dev_binds(t);
-               const char *name = in_get_dev_name(t, 0);
+               const char *name = in_get_dev_name(t, 0, 0);
                char strbind[16];
                int count;
 
@@ -449,7 +348,7 @@ int config_writelrom(const char *fname)
        int size;
        FILE *f;
 
-       if (strlen(loadedRomFName) == 0) return -1;
+       if (strlen(rom_fname_loaded) == 0) return -1;
 
        f = fopen(fname, "r");
        if (f != NULL)
@@ -482,7 +381,7 @@ int config_writelrom(const char *fname)
                fwrite(old_data, 1, optr - old_data, f);
                free(old_data);
        }
-       fprintf(f, "LastUsedROM = %s" NL, loadedRomFName);
+       fprintf(f, "LastUsedROM = %s" NL, rom_fname_loaded);
        fclose(f);
        return 0;
 }
@@ -513,9 +412,9 @@ int config_readlrom(const char *fname)
                tmp++;
                mystrip(tmp);
 
-               len = sizeof(loadedRomFName);
-               strncpy(loadedRomFName, tmp, len);
-               loadedRomFName[len-1] = 0;
+               len = sizeof(rom_fname_loaded);
+               strncpy(rom_fname_loaded, tmp, len);
+               rom_fname_loaded[len-1] = 0;
                ret = 0;
                break;
        }
@@ -773,7 +672,7 @@ static unsigned char input_dev_map[IN_MAX_DEVS];
 static void parse(const char *var, const char *val)
 {
        menu_entry *me;
-       int t, i, tlen, tmp, ret = 0;
+       int tmp, ret = 0;
 
        if (strcasecmp(var, "LastUsedROM") == 0)
                return; /* handled elsewhere */
@@ -814,30 +713,30 @@ static void parse(const char *var, const char *val)
                return;
        }
 
-       for (t = 0; t < sizeof(cfg_opts) / sizeof(cfg_opts[0]) && ret == 0; t++)
+       me = me_list_get_first();
+       while (me != NULL && ret == 0)
        {
-               me = cfg_opts[t];
-               tlen = *(cfg_opt_counts[t]);
-               for (i = 0; i < tlen && ret == 0; i++, me++)
-               {
-                       if (!me->need_to_save) continue;
-                       if (me->name != NULL) {
-                               if (strcasecmp(var, me->name) != 0) continue; // surely not this one
-                               if (me->beh == MB_ONOFF) {
-                                       tmp = atoi(val);
-                                       if (tmp) *(int *)me->var |=  me->mask;
-                                       else     *(int *)me->var &= ~me->mask;
-                                       return;
-                               } else if (me->beh == MB_RANGE) {
-                                       tmp = atoi(val);
-                                       if (tmp < me->min) tmp = me->min;
-                                       if (tmp > me->max) tmp = me->max;
-                                       *(int *)me->var = tmp;
-                                       return;
-                               }
+               if (!me->need_to_save)
+                       goto next;
+               if (me->name != NULL && me->name[0] != 0) {
+                       if (strcasecmp(var, me->name) != 0)
+                               goto next; /* surely not this one */
+                       if (me->beh == MB_OPT_ONOFF) {
+                               tmp = atoi(val);
+                               if (tmp) *(int *)me->var |=  me->mask;
+                               else     *(int *)me->var &= ~me->mask;
+                               return;
+                       } else if (me->beh == MB_OPT_RANGE) {
+                               tmp = atoi(val);
+                               if (tmp < me->min) tmp = me->min;
+                               if (tmp > me->max) tmp = me->max;
+                               *(int *)me->var = tmp;
+                               return;
                        }
-                       ret = custom_read(me, var, val);
                }
+               ret = custom_read(me, var, val);
+next:
+               me = me_list_get_next();
        }
        if (!ret) lprintf("config_readsect: unhandled var: \"%s\"\n", var);
 }
index 58fee61..7aac10b 100644 (file)
@@ -16,6 +16,7 @@
 #include "lprintf.h"\r
 #include "config.h"\r
 #include "common.h"\r
+#include "plat.h"\r
 \r
 #include <pico/pico_int.h>\r
 #include <pico/patch.h>\r
 \r
 char *PicoConfigFile = "config.cfg";\r
 currentConfig_t currentConfig, defaultConfig;\r
-int rom_loaded = 0;\r
 char noticeMsg[64] = { 0, };\r
 int state_slot = 0;\r
 int config_slot = 0, config_slot_current = 0;\r
-char loadedRomFName[512] = { 0, };\r
 int kb_combo_keys = 0, kb_combo_acts = 0;      // keys and actions which need button combos\r
 int pico_inp_mode = 0;\r
+int engineState = PGS_Menu;\r
+\r
+/* TODO: len checking */\r
+char rom_fname_reload[512] = { 0, };\r
+char rom_fname_loaded[512] = { 0, };\r
+int rom_loaded = 0;\r
 \r
 unsigned char *movie_data = NULL;\r
 static int movie_size = 0;\r
 \r
-// provided by platform code:\r
-extern void emu_noticeMsgUpdated(void);\r
-extern int  emu_getMainDir(char *dst, int len);\r
-extern void menu_romload_prepare(const char *rom_name);\r
-extern void menu_romload_end(void);\r
-\r
 \r
 // utilities\r
 static void strlwr_(char *string)\r
@@ -492,8 +491,8 @@ int emu_ReloadRom(char *rom_fname)
        if (currentConfig.EmuOpt & EOPT_USE_SRAM)\r
                emu_SaveLoadGame(1, 1);\r
 \r
-       strncpy(loadedRomFName, rom_fname, sizeof(loadedRomFName)-1);\r
-       loadedRomFName[sizeof(loadedRomFName)-1] = 0;\r
+       strncpy(rom_fname_loaded, rom_fname, sizeof(rom_fname_loaded)-1);\r
+       rom_fname_loaded[sizeof(rom_fname_loaded)-1] = 0;\r
        rom_loaded = 1;\r
        return 1;\r
 \r
@@ -518,8 +517,8 @@ static void romfname_ext(char *dst, const char *prefix, const char *ext)
        int prefix_len = 0;\r
 \r
        // make save filename\r
-       p = loadedRomFName+strlen(loadedRomFName)-1;\r
-       for (; p >= loadedRomFName && *p != PATH_SEP_C; p--); p++;\r
+       p = rom_fname_loaded + strlen(rom_fname_loaded) - 1;\r
+       for (; p >= rom_fname_loaded && *p != PATH_SEP_C; p--); p++;\r
        *dst = 0;\r
        if (prefix) {\r
                int len = emu_getMainDir(dst, 512);\r
@@ -527,7 +526,7 @@ static void romfname_ext(char *dst, const char *prefix, const char *ext)
                prefix_len = len + strlen(prefix);\r
        }\r
 #ifdef UIQ3\r
-       else p = loadedRomFName; // backward compatibility\r
+       else p = rom_fname_loaded; // backward compatibility\r
 #endif\r
        strncpy(dst + prefix_len, p, 511-prefix_len);\r
        dst[511-8] = 0;\r
index 15643b9..516c77f 100644 (file)
@@ -50,11 +50,14 @@ extern char noticeMsg[64];
 extern int state_slot;
 extern int config_slot, config_slot_current;
 extern unsigned char *movie_data;
-extern char loadedRomFName[512];               // last loaded ROM filename
 extern int kb_combo_keys, kb_combo_acts;       // keys and actions which need button combos
 extern int pico_inp_mode;
 
+extern char rom_fname_reload[512];             // ROM to try loading on next PGS_ReloadRom
+extern char rom_fname_loaded[512];             // currently loaded ROM filename
+
 // engine states
+extern int engineState;
 enum TPicoGameState {
        PGS_Paused = 1,
        PGS_Running,
index a8bad14..8474f36 100644 (file)
@@ -380,14 +380,14 @@ int in_menu_wait_any(int timeout_ms)
 }
 
 /* wait for menu input, do autorepeat */
-int in_menu_wait(int interesting)
+int in_menu_wait(int interesting, int autorep_delay_ms)
 {
        static int inp_prev = 0;
        static int repeats = 0;
        int ret, release = 0, wait = 666;
 
        if (repeats)
-               wait = 33;
+               wait = autorep_delay_ms;
 
        ret = in_menu_wait_any(wait);
        if (ret == inp_prev)
@@ -439,14 +439,22 @@ int in_get_dev_bind_count(int dev_id)
        return in_bind_count(in_devices[dev_id].drv_id);
 }
 
-const char *in_get_dev_name(int dev_id, int must_be_active)
+const char *in_get_dev_name(int dev_id, int must_be_active, int skip_pfix)
 {
+       const char *name, *tmp;
+
        if (dev_id < 0 || dev_id >= IN_MAX_DEVS)
                return NULL;
 
        if (must_be_active && !in_devices[dev_id].probed)
                return NULL;
-       return in_devices[dev_id].name;
+
+       name = in_devices[dev_id].name;
+       tmp = strchr(name, ':');
+       if (tmp != NULL)
+               name = tmp + 1;
+
+       return name;
 }
 
 /* never returns NULL */
index 85723f1..5e62f59 100644 (file)
@@ -31,7 +31,7 @@ int  in_update(void);
 void in_set_blocking(int is_blocking);
 int  in_update_keycode(int *dev_id, int *is_down, int timeout_ms);
 int  in_menu_wait_any(int timeout_ms);
-int  in_menu_wait(int interesting);
+int  in_menu_wait(int interesting, int autorep_delay_ms);
 int  in_get_dev_bind_count(int dev_id);
 void in_config_start(void);
 int  in_config_parse_dev(const char *dev_name);
@@ -42,5 +42,5 @@ void in_debug_dump(void);
 
 const int  *in_get_dev_binds(int dev_id);
 const int  *in_get_dev_def_binds(int dev_id);
-const char *in_get_dev_name(int dev_id, int must_be_active);
+const char *in_get_dev_name(int dev_id, int must_be_active, int skip_pfix);
 const char *in_get_key_name(int dev_id, int keycode);
index 8674897..e3c8cef 100644 (file)
 #include "input.h"\r
 #include "emu.h"\r
 #include "plat.h"\r
+#include "posix.h"\r
 \r
+#include <pico/pico_int.h>\r
 #include <pico/patch.h>\r
+#include <zlib/zlib.h>\r
 \r
-char menuErrorMsg[64] = { 0, };\r
+#define array_size(x) (sizeof(x) / sizeof(x[0]))\r
 \r
-// PicoPad[] format: MXYZ SACB RLDU\r
-me_bind_action me_ctrl_actions[15] =\r
-{\r
-       { "UP     ", 0x0001 },\r
-       { "DOWN   ", 0x0002 },\r
-       { "LEFT   ", 0x0004 },\r
-       { "RIGHT  ", 0x0008 },\r
-       { "A      ", 0x0040 },\r
-       { "B      ", 0x0010 },\r
-       { "C      ", 0x0020 },\r
-       { "A turbo", 0x4000 },\r
-       { "B turbo", 0x1000 },\r
-       { "C turbo", 0x2000 },\r
-       { "START  ", 0x0080 },\r
-       { "MODE   ", 0x0800 },\r
-       { "X      ", 0x0400 },\r
-       { "Y      ", 0x0200 },\r
-       { "Z      ", 0x0100 }\r
-};\r
+static char static_buff[64];\r
+char menuErrorMsg[64] = { 0, };\r
 \r
 \r
 #ifndef UIQ3\r
@@ -64,7 +50,12 @@ static void text_out16_(int x, int y, const char *text, int color)
                len = 1;\r
        }\r
        else\r
-               len = strlen(text);\r
+       {\r
+               const char *p;\r
+               for (p = text; *p != 0 && *p != '\n'; p++)\r
+                       ;\r
+               len = p - text;\r
+       }\r
 \r
        for (i = 0; i < len; i++)\r
        {\r
@@ -115,7 +106,7 @@ void text_out16(int x, int y, const char *texto, ...)
 }\r
 \r
 \r
-void smalltext_out16(int x, int y, const char *texto, int color)\r
+static void smalltext_out16_(int x, int y, const char *texto, int color)\r
 {\r
        int i;\r
        unsigned char  *src;\r
@@ -147,19 +138,17 @@ void smalltext_out16(int x, int y, const char *texto, int color)
        }\r
 }\r
 \r
-void smalltext_out16_lim(int x, int y, const char *texto, int color, int max)\r
+void smalltext_out16(int x, int y, const char *texto, int color)\r
 {\r
-       char    buffer[SCREEN_WIDTH/6+1];\r
+       char buffer[SCREEN_WIDTH/6+1];\r
 \r
-       strncpy(buffer, texto, SCREEN_WIDTH/6);\r
-       if (max > SCREEN_WIDTH/6) max = SCREEN_WIDTH/6;\r
-       if (max < 0) max = 0;\r
-       buffer[max] = 0;\r
+       strncpy(buffer, texto, sizeof(buffer));\r
+       buffer[sizeof(buffer) - 1] = 0;\r
 \r
-       smalltext_out16(x, y, buffer, color);\r
+       smalltext_out16_(x, y, buffer, color);\r
 }\r
 \r
-void menu_draw_selection(int x, int y, int w)\r
+static void menu_draw_selection(int x, int y, int w)\r
 {\r
        int i, h;\r
        unsigned short *dst, *dest;\r
@@ -253,7 +242,7 @@ void menu_init(void)
 }\r
 \r
 \r
-int me_id2offset(const menu_entry *ent, menu_id id)\r
+static int me_id2offset(const menu_entry *ent, menu_id id)\r
 {\r
        int i;\r
        for (i = 0; ent->name; ent++, i++)\r
@@ -263,13 +252,13 @@ int me_id2offset(const menu_entry *ent, menu_id id)
        return 0;\r
 }\r
 \r
-void me_enable(menu_entry *entries, menu_id id, int enable)\r
+static void me_enable(menu_entry *entries, menu_id id, int enable)\r
 {\r
        int i = me_id2offset(entries, id);\r
        entries[i].enabled = enable;\r
 }\r
 \r
-int me_count(const menu_entry *ent)\r
+static int me_count(const menu_entry *ent)\r
 {\r
        int ret;\r
 \r
@@ -279,54 +268,11 @@ int me_count(const menu_entry *ent)
        return ret;\r
 }\r
 \r
-menu_id me_index2id(const menu_entry *ent, int index)\r
-{\r
-       const menu_entry *last;\r
-\r
-       for (; ent->name; ent++)\r
-       {\r
-               if (ent->enabled)\r
-               {\r
-                       if (index == 0) break;\r
-                       index--;\r
-               }\r
-               last = ent;\r
-       }\r
-       if (ent->name == NULL)\r
-               ent = last;\r
-       return ent->id;\r
-}\r
-\r
-/* TODO rm */\r
-void me_draw(const menu_entry *entries, int count, int x, int y, me_draw_custom_f *cust_draw, void *param)\r
-{\r
-       int i, y1 = y;\r
-\r
-       for (i = 0; i < count; i++)\r
-       {\r
-               if (!entries[i].enabled) continue;\r
-               if (entries[i].name == NULL)\r
-               {\r
-                       if (cust_draw != NULL)\r
-                               cust_draw(&entries[i], x, y1, param);\r
-                       y1 += 10;\r
-                       continue;\r
-               }\r
-               text_out16(x, y1, entries[i].name);\r
-               if (entries[i].beh == MB_OPT_ONOFF)\r
-                       text_out16(x + 27*8, y1, (*(int *)entries[i].var & entries[i].mask) ? "ON" : "OFF");\r
-               else if (entries[i].beh == MB_OPT_RANGE)\r
-                       text_out16(x + 27*8, y1, "%i", *(int *)entries[i].var);\r
-               y1 += 10;\r
-       }\r
-\r
-}\r
-\r
-static void me_draw2(const menu_entry *entries, int sel)\r
+static void me_draw(const menu_entry *entries, int sel)\r
 {\r
        const menu_entry *ent;\r
        int x, y, w = 0, h = 0;\r
-       int opt_offs = 27*8;\r
+       int offs, opt_offs = 27*8;\r
        const char *name;\r
        int asel = 0;\r
        int i, n;\r
@@ -345,7 +291,7 @@ static void me_draw2(const menu_entry *entries, int sel)
                name = NULL;\r
                wt = strlen(ent->name) * 8;     /* FIXME: unhardcode font width */\r
                if (wt == 0 && ent->generate_name)\r
-                       name = ent->generate_name(1);\r
+                       name = ent->generate_name(ent->id, &offs);\r
                if (name != NULL)\r
                        wt = strlen(name) * 8;\r
 \r
@@ -360,11 +306,14 @@ static void me_draw2(const menu_entry *entries, int sel)
                        case MB_OPT_ONOFF:\r
                        case MB_OPT_RANGE: wt += 8*3; break;\r
                        case MB_OPT_CUSTOM:\r
+                       case MB_OPT_CUSTONOFF:\r
+                       case MB_OPT_CUSTRANGE:\r
                                name = NULL;\r
+                               offs = 0;\r
                                if (ent->generate_name != NULL)\r
-                                       name = ent->generate_name(0);\r
+                                       name = ent->generate_name(ent->id, &offs);\r
                                if (name != NULL)\r
-                                       wt += strlen(name) * 8;\r
+                                       wt += (strlen(name) + offs) * 8;\r
                                break;\r
                        }\r
                }\r
@@ -400,7 +349,7 @@ static void me_draw2(const menu_entry *entries, int sel)
                name = ent->name;\r
                if (strlen(name) == 0) {\r
                        if (ent->generate_name)\r
-                               name = ent->generate_name(1);\r
+                               name = ent->generate_name(ent->id, &offs);\r
                }\r
                if (name != NULL)\r
                        text_out16(x + 16, y, name);\r
@@ -415,39 +364,60 @@ static void me_draw2(const menu_entry *entries, int sel)
                        text_out16(x + 16 + opt_offs, y, "%i", *(int *)ent->var);\r
                        break;\r
                case MB_OPT_CUSTOM:\r
+               case MB_OPT_CUSTONOFF:\r
+               case MB_OPT_CUSTRANGE:\r
                        name = NULL;\r
+                       offs = 0;\r
                        if (ent->generate_name)\r
-                               name = ent->generate_name(0);\r
+                               name = ent->generate_name(ent->id, &offs);\r
                        if (name != NULL)\r
-                               text_out16(x + 16 + opt_offs, y, "%s", name);\r
+                               text_out16(x + 16 + opt_offs + offs * 8, y, "%s", name);\r
                        break;\r
                }\r
 \r
                y += 10;\r
        }\r
 \r
+       /* display message if we have one */\r
+       if (menuErrorMsg[0] != 0) {\r
+               static int msg_redraws = 0;\r
+               if (SCREEN_HEIGHT - h >= 2*10)\r
+                       text_out16(5, 226, menuErrorMsg);\r
+               else\r
+                       lprintf("menu msg doesn't fit!\n");\r
+\r
+               if (++msg_redraws > 4) {\r
+                       menuErrorMsg[0] = 0;\r
+                       msg_redraws = 0;\r
+               }\r
+       }\r
+\r
        plat_video_menu_end();\r
 }\r
 \r
-int me_process(menu_entry *entries, menu_id id, int is_next)\r
+static int me_process(menu_entry *entry, int is_next)\r
 {\r
-       int i = me_id2offset(entries, id);\r
-       menu_entry *entry = &entries[i];\r
        switch (entry->beh)\r
        {\r
                case MB_OPT_ONOFF:\r
+               case MB_OPT_CUSTONOFF:\r
                        *(int *)entry->var ^= entry->mask;\r
                        return 1;\r
                case MB_OPT_RANGE:\r
+               case MB_OPT_CUSTRANGE:\r
                        *(int *)entry->var += is_next ? 1 : -1;\r
-                       if (*(int *)entry->var < (int)entry->min) *(int *)entry->var = (int)entry->min;\r
-                       if (*(int *)entry->var > (int)entry->max) *(int *)entry->var = (int)entry->max;\r
+                       if (*(int *)entry->var < (int)entry->min)\r
+                               *(int *)entry->var = (int)entry->max;\r
+                       if (*(int *)entry->var > (int)entry->max)\r
+                               *(int *)entry->var = (int)entry->min;\r
                        return 1;\r
                default:\r
                        return 0;\r
        }\r
 }\r
 \r
+static void debug_menu_loop(void);\r
+\r
 static void me_loop(menu_entry *menu, int *menu_sel)\r
 {\r
        int ret, inp, sel = *menu_sel, menu_sel_max;\r
@@ -462,20 +432,24 @@ 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_draw2(menu, sel);\r
+       me_draw(menu, sel);\r
        while (in_menu_wait_any(50) & (PBTN_MOK|PBTN_MBACK|PBTN_MENU));\r
 \r
        for (;;)\r
        {\r
-               me_draw2(menu, sel);\r
-               inp = in_menu_wait(PBTN_UP|PBTN_DOWN|PBTN_MOK|PBTN_MBACK|PBTN_MENU|PBTN_L|PBTN_R);\r
+               me_draw(menu, sel);\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
+                       break;\r
+\r
                if (inp & PBTN_UP  ) {\r
                        do {\r
                                sel--;\r
                                if (sel < 0)\r
                                        sel = menu_sel_max;\r
                        }\r
-                       while (!menu[sel].enabled);\r
+                       while (!menu[sel].enabled || !menu[sel].selectable);\r
                }\r
                if (inp & PBTN_DOWN) {\r
                        do {\r
@@ -483,294 +457,1294 @@ static void me_loop(menu_entry *menu, int *menu_sel)
                                if (sel > menu_sel_max)\r
                                        sel = 0;\r
                        }\r
-                       while (!menu[sel].enabled);\r
+                       while (!menu[sel].enabled || !menu[sel].selectable);\r
+               }\r
+\r
+               /* a bit hacky but oh well */\r
+               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
+                               continue;\r
                }\r
-//             if ((inp & (PBTN_L|PBTN_R)) == (PBTN_L|PBTN_R)) debug_menu_loop(); // TODO\r
-               if (inp & (PBTN_MENU|PBTN_MBACK))\r
-                       break;\r
 \r
-               if (inp & PBTN_MOK)\r
+               if (inp & (PBTN_MOK|PBTN_LEFT|PBTN_RIGHT))\r
                {\r
-                       if (menu[sel].submenu_handler != NULL) {\r
-                               ret = menu[sel].submenu_handler(menu[sel].id);\r
+                       if (menu[sel].handler != NULL) {\r
+                               ret = menu[sel].handler(menu[sel].id, inp);\r
                                if (ret) break;\r
+                               menu_sel_max = me_count(menu) - 1; /* might change */\r
                        }\r
                }\r
-//             menuErrorMsg[0] = 0; // TODO: clear error msg\r
        }\r
        *menu_sel = sel;\r
 }\r
 \r
 /* ***************************************** */\r
 \r
-/* TODO s */\r
-int menu_loop_tray(void) { return 0; }\r
-void menu_romload_prepare(const char *rom_name) {}\r
-void menu_romload_end(void) {}\r
-me_bind_action emuctrl_actions[1];\r
-menu_entry opt_entries[1];\r
-menu_entry opt2_entries[1];\r
-menu_entry cdopt_entries[1];\r
-menu_entry ctrlopt_entries[1];\r
-const int opt_entry_count = 0;\r
-const int opt2_entry_count = 0;\r
-const int cdopt_entry_count = 0;\r
-const int ctrlopt_entry_count = 0;\r
-\r
-extern int engineState;\r
-\r
-int savestate_menu_loop(int a) { return 1; }\r
-int menu_loop_options() { return 1; }\r
-void kc_sel_loop() {}\r
-void draw_menu_credits() {}\r
-void patches_menu_loop() {}\r
+static void draw_menu_credits(void)\r
+{\r
+       const char *creds, *p;\r
+       int x, y, h, w, wt;\r
 \r
-// ------------ main menu ------------\r
+       p = creds = plat_get_credits();\r
 \r
-static int main_menu_handler(menu_id id)\r
-{\r
-       int ret;\r
+       for (h = 1, w = 0; *p != 0; h++) {\r
+               for (wt = 0; *p != 0 && *p != '\n'; p++)\r
+                       wt++;\r
 \r
-       switch (id)\r
-       {\r
-       case MA_MAIN_RESUME_GAME:\r
-               if (rom_loaded) {\r
-                       while (in_menu_wait_any(50) & PBTN_MOK);\r
-                       engineState = PGS_Running;\r
-                       return 1;\r
-               }\r
-               break;\r
-       case MA_MAIN_SAVE_STATE:\r
-               if (rom_loaded) {\r
-                       if (savestate_menu_loop(0))\r
-                               break;\r
-                       engineState = PGS_Running;\r
-                       return 1;\r
-               }\r
-               break;\r
-       case MA_MAIN_LOAD_STATE:\r
-               if (rom_loaded) {\r
-                       if (savestate_menu_loop(1))\r
-                               break;\r
-                       while (in_menu_wait_any(50) & PBTN_MOK);\r
-                       engineState = PGS_Running;\r
-                       return 1;\r
-               }\r
-               break;\r
-       case MA_MAIN_RESET_GAME:\r
-               if (rom_loaded) {\r
-                       emu_ResetGame();\r
-                       while (in_menu_wait_any(50) & PBTN_MOK);\r
-                       engineState = PGS_Running;\r
-                       return 1;\r
-               }\r
-               break;\r
-       case MA_MAIN_LOAD_ROM:\r
-               {\r
-/*                     char curr_path[PATH_MAX], *selfname;\r
-                       FILE *tstf;\r
-                       if ( (tstf = fopen(loadedRomFName, "rb")) )\r
-                       {\r
-                               fclose(tstf);\r
-                               strcpy(curr_path, loadedRomFName);\r
-                       }\r
-                       else\r
-                               getcwd(curr_path, PATH_MAX);\r
-                       selfname = romsel_loop(curr_path);\r
-                       if (selfname) {\r
-                               printf("selected file: %s\n", selfname);\r
-                               engineState = PGS_ReloadRom;\r
-                               return;\r
-                       }*/\r
+               if (wt > w)\r
+                       w = wt;\r
+               if (*p == 0)\r
                        break;\r
-               }\r
-       case MA_MAIN_OPTIONS:\r
-               ret = menu_loop_options();\r
-               if (ret == 1) break; // status update\r
-               if (engineState == PGS_ReloadRom)\r
-                       return 1; // BIOS test\r
-               break;\r
-       case MA_MAIN_CONTROLS:\r
-               kc_sel_loop();\r
-               break;\r
-       case MA_MAIN_CREDITS:\r
-               draw_menu_credits();\r
-               usleep(500*1000); /* FIXME */\r
-               in_menu_wait(PBTN_MOK|PBTN_MBACK);\r
-               break;\r
-       case MA_MAIN_EXIT:\r
-               engineState = PGS_Quit;\r
-               return 1;\r
-       case MA_MAIN_PATCHES:\r
-               if (rom_loaded && PicoPatches) {\r
-                       patches_menu_loop();\r
-                       PicoPatchApply();\r
-                       strcpy(menuErrorMsg, "Patches applied");\r
-               }\r
-               break;\r
-       default:\r
-               lprintf("%s: something unknown selected\n", __FUNCTION__);\r
-               break;\r
+               p++;\r
        }\r
 \r
-       return 0;\r
+       x = SCREEN_WIDTH  / 2 - w *  8 / 2;\r
+       y = SCREEN_HEIGHT / 2 - h * 10 / 2;\r
+       if (x < 0) x = 0;\r
+       if (y < 0) y = 0;\r
+\r
+       plat_video_menu_begin();\r
+\r
+       for (p = creds; *p != 0 && y <= SCREEN_HEIGHT - 10; y += 10) {\r
+               text_out16(x, y, p);\r
+\r
+               for (; *p != 0 && *p != '\n'; p++)\r
+                       ;\r
+               if (*p != 0)\r
+                       p++;\r
+       }\r
+\r
+       plat_video_menu_end();\r
 }\r
 \r
-menu_entry e_main_menu[] =\r
+// --------- loading ROM screen ----------\r
+\r
+static int cdload_called = 0;\r
+\r
+static void load_progress_cb(int percent)\r
 {\r
-       mee_submenu_id("Resume game",        MA_MAIN_RESUME_GAME, main_menu_handler),\r
-       mee_submenu_id("Save State",         MA_MAIN_SAVE_STATE,  main_menu_handler),\r
-       mee_submenu_id("Load State",         MA_MAIN_LOAD_STATE,  main_menu_handler),\r
-       mee_submenu_id("Reset game",         MA_MAIN_RESET_GAME,  main_menu_handler),\r
-       mee_submenu_id("Load new ROM/ISO",   MA_MAIN_LOAD_ROM,    main_menu_handler),\r
-       mee_submenu_id("Change options",     MA_MAIN_OPTIONS,     main_menu_handler),\r
-       mee_submenu_id("Credits",            MA_MAIN_CREDITS,     main_menu_handler),\r
-       mee_submenu_id("Patches / GameGenie",MA_MAIN_PATCHES,     main_menu_handler),\r
-       mee_submenu_id("Exit",               MA_MAIN_EXIT,        main_menu_handler),\r
-       mee_end,\r
-};\r
+       int ln, len = percent * SCREEN_WIDTH / 100;\r
+       unsigned short *dst = (unsigned short *)SCREEN_BUFFER + SCREEN_WIDTH * 10 * 2;\r
 \r
-void menu_loop(void)\r
+       if (len > SCREEN_WIDTH)\r
+               len = SCREEN_WIDTH;\r
+       for (ln = 10 - 2; ln > 0; ln--, dst += SCREEN_WIDTH)\r
+               memset(dst, 0xff, len * 2);\r
+       plat_video_menu_end();\r
+}\r
+\r
+static void cdload_progress_cb(int percent)\r
 {\r
-       static int sel = 0;\r
+       int ln, len = percent * SCREEN_WIDTH / 100;\r
+       unsigned short *dst = (unsigned short *)SCREEN_BUFFER + SCREEN_WIDTH * 10 * 2;\r
 \r
-       me_enable(e_main_menu, MA_MAIN_RESUME_GAME, rom_loaded);\r
-       me_enable(e_main_menu, MA_MAIN_SAVE_STATE,  rom_loaded);\r
-       me_enable(e_main_menu, MA_MAIN_LOAD_STATE,  rom_loaded);\r
-       me_enable(e_main_menu, MA_MAIN_RESET_GAME,  rom_loaded);\r
-       me_enable(e_main_menu, MA_MAIN_PATCHES, PicoPatches != NULL);\r
+       memset(dst, 0xff, SCREEN_WIDTH * (10 - 2) * 2);\r
 \r
-       plat_video_menu_enter(rom_loaded);\r
-       in_set_blocking(1);\r
-       me_loop(e_main_menu, &sel);\r
-       in_set_blocking(0);\r
+       smalltext_out16(1, 3 * 10, "Processing CD image / MP3s", 0xffff);\r
+       smalltext_out16(1, 4 * 10, rom_fname_loaded, 0xffff);\r
+       dst += SCREEN_WIDTH * 30;\r
 \r
-       if (rom_loaded) {\r
-               while (in_menu_wait_any(50) & (PBTN_MENU|PBTN_MBACK)); // wait until select is released\r
-               engineState = PGS_Running;\r
-       }\r
+       if (len > SCREEN_WIDTH)\r
+               len = SCREEN_WIDTH;\r
+       for (ln = (10 - 2); ln > 0; ln--, dst += SCREEN_WIDTH)\r
+               memset(dst, 0xff, len * 2);\r
 \r
+       plat_video_menu_end();\r
+       cdload_called = 1;\r
 }\r
 \r
-// ------------ debug menu ------------\r
+void menu_romload_prepare(const char *rom_name)\r
+{\r
+       const char *p = rom_name + strlen(rom_name);\r
 \r
-#include <sys/stat.h>\r
-#include <sys/types.h>\r
+       plat_video_menu_begin();\r
 \r
-#include <pico/pico.h>\r
-#include <pico/debug.h>\r
+       while (p > rom_name && *p != '/')\r
+               p--;\r
 \r
-void SekStepM68k(void);\r
+       /* fill both buffers, callbacks won't update in full */\r
+       smalltext_out16(1, 1, "Loading", 0xffff);\r
+       smalltext_out16(1, 10, p, 0xffff);\r
+       plat_video_menu_end();\r
 \r
-static void mplayer_loop(void)\r
+       smalltext_out16(1, 1, "Loading", 0xffff);\r
+       smalltext_out16(1, 10, p, 0xffff);\r
+       plat_video_menu_end();\r
+\r
+       PicoCartLoadProgressCB = load_progress_cb;\r
+       PicoCDLoadProgressCB = cdload_progress_cb;\r
+       cdload_called = 0;\r
+}\r
+\r
+void menu_romload_end(void)\r
 {\r
-       emu_startSound();\r
+       PicoCartLoadProgressCB = PicoCDLoadProgressCB = NULL;\r
+       smalltext_out16(1, (cdload_called ? 6 : 3) * 10,\r
+               "Starting emulation...", 0xffff);\r
+       plat_video_menu_end();\r
+}\r
 \r
-       while (1)\r
-       {\r
-               PDebugZ80Frame();\r
-               if (in_menu_wait_any(0) & PBTN_NORTH) break;\r
-               emu_waitSound();\r
-       }\r
+// -------------- ROM selector --------------\r
 \r
-       emu_endSound();\r
+// rrrr rggg gggb bbbb\r
+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", "cso", "cue" };\r
+       static const char *other_exts[] = { "gmv", "pat" };\r
+       int i;\r
+\r
+       if (ext < fname) ext = fname;\r
+       for (i = 0; i < array_size(rom_exts); i++)\r
+               if (strcasecmp(ext, rom_exts[i]) == 0) return 0xbdff; // FIXME: mk defines\r
+       for (i = 0; i < array_size(other_exts); i++)\r
+               if (strcasecmp(ext, other_exts[i]) == 0) return 0xaff5;\r
+       return 0xffff;\r
 }\r
 \r
-static void draw_text_debug(const char *str, int skip, int from)\r
+static void draw_dirlist(char *curdir, struct dirent **namelist, int n, int sel)\r
 {\r
-       const char *p;\r
-       int len, line;\r
+       int max_cnt, start, i, pos;\r
 \r
-       p = str;\r
-       while (skip-- > 0)\r
-       {\r
-               while (*p && *p != '\n') p++;\r
-               if (*p == 0 || p[1] == 0) return;\r
-               p++;\r
-       }\r
+       max_cnt = SCREEN_HEIGHT / 10;\r
+       start = max_cnt / 2 - sel;\r
+       n--; // exclude current dir (".")\r
 \r
-       str = p;\r
-       for (line = from; line < SCREEN_HEIGHT/10; line++)\r
-       {\r
-               while (*p && *p != '\n') p++;\r
-               len = p - str;\r
-               if (len > 55) len = 55;\r
-               smalltext_out16_lim(1, line*10, str, 0xffff, len);\r
-               if (*p == 0) break;\r
-               p++; str = p;\r
+       plat_video_menu_begin();\r
+\r
+//     if (!rom_loaded)\r
+//             menu_darken_bg(gp2x_screen, 320*240, 0);\r
+\r
+       menu_darken_bg((short *)SCREEN_BUFFER + SCREEN_WIDTH * max_cnt/2 * 10, SCREEN_WIDTH * 8, 0);\r
+\r
+       if (start - 2 >= 0)\r
+               smalltext_out16(14, (start - 2)*10, curdir, 0xffff);\r
+       for (i = 0; i < n; i++) {\r
+               pos = start + i;\r
+               if (pos < 0)  continue;\r
+               if (pos >= max_cnt) break;\r
+               if (namelist[i+1]->d_type == DT_DIR) {\r
+                       smalltext_out16(14,   pos*10, "/", 0xfff6);\r
+                       smalltext_out16(14+6, pos*10, namelist[i+1]->d_name, 0xfff6);\r
+               } else {\r
+                       unsigned short color = file2color(namelist[i+1]->d_name);\r
+                       smalltext_out16(14,   pos*10, namelist[i+1]->d_name, color);\r
+               }\r
        }\r
+       text_out16(5, max_cnt/2 * 10, ">");\r
+       plat_video_menu_end();\r
 }\r
 \r
-static void draw_frame_debug(void)\r
+static int scandir_cmp(const void *p1, const void *p2)\r
 {\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
+       struct dirent **d1 = (struct dirent **)p1, **d2 = (struct dirent **)p2;\r
+       if ((*d1)->d_type == (*d2)->d_type) return alphasort(d1, d2);\r
+       if ((*d1)->d_type == DT_DIR) return -1; // put before\r
+       if ((*d2)->d_type == DT_DIR) return  1;\r
+       return alphasort(d1, d2);\r
+}\r
 \r
-       clear_screen();\r
-       emu_forcedFrame(0);\r
-       smalltext_out16(4, SCREEN_HEIGHT-8, layer_str, 0xffff);\r
+static const char *filter_exts[] = {\r
+       ".mp3", ".MP3", ".srm", ".brm", "s.gz", ".mds", "bcfg", ".txt", ".htm", "html",\r
+       ".jpg", ".gpe"\r
+};\r
+\r
+static int scandir_filter(const struct dirent *ent)\r
+{\r
+       const char *p;\r
+       int i;\r
+\r
+       if (ent == NULL || ent->d_name == NULL) return 0;\r
+       if (strlen(ent->d_name) < 5) return 1;\r
+\r
+       p = ent->d_name + strlen(ent->d_name) - 4;\r
+\r
+       for (i = 0; i < array_size(filter_exts); i++)\r
+               if (strcmp(p, filter_exts[i]) == 0)\r
+                       return 0;\r
+\r
+       return 1;\r
 }\r
 \r
-void debug_menu_loop(void)\r
+static char *menu_loop_romsel(char *curr_path, int len)\r
 {\r
-       int inp, mode = 0;\r
-       int spr_offs = 0, dumped = 0;\r
-       char *tmp;\r
+       struct dirent **namelist;\r
+       int n, inp, sel = 0;\r
+       char *ret = NULL, *fname = NULL;\r
+\r
+rescan:\r
+       // is this a dir or a full path?\r
+       if (!plat_is_dir(curr_path)) {\r
+               char *p = curr_path + strlen(curr_path) - 1;\r
+               for (; p > curr_path && *p != '/'; p--)\r
+                       ;\r
+               *p = 0;\r
+               fname = p+1;\r
+       }\r
 \r
-       while (1)\r
-       {\r
-               switch (mode)\r
-               {\r
-                       case 0: plat_video_menu_begin();\r
-                               tmp = PDebugMain();\r
-                               emu_platformDebugCat(tmp);\r
-                               draw_text_debug(tmp, 0, 0);\r
-                               if (dumped) {\r
-                                       smalltext_out16(SCREEN_WIDTH-6*10, SCREEN_HEIGHT-8, "dumped", 0xffff);\r
-                                       dumped = 0;\r
-                               }\r
-                               break;\r
-                       case 1: draw_frame_debug(); break;\r
-                       case 2: clear_screen();\r
-                               emu_forcedFrame(0);\r
-                               darken_screen();\r
-                               PDebugShowSpriteStats((unsigned short *)SCREEN_BUFFER + (SCREEN_HEIGHT/2 - 240/2)*SCREEN_WIDTH +\r
-                                       SCREEN_WIDTH/2 - 320/2, SCREEN_WIDTH); break;\r
-                       case 3: clear_screen();\r
-                               PDebugShowPalette(SCREEN_BUFFER, SCREEN_WIDTH);\r
-                               PDebugShowSprite((unsigned short *)SCREEN_BUFFER + SCREEN_WIDTH*120+SCREEN_WIDTH/2+16,\r
-                                       SCREEN_WIDTH, spr_offs);\r
-                               draw_text_debug(PDebugSpriteList(), spr_offs, 6);\r
+       n = scandir(curr_path, &namelist, scandir_filter, scandir_cmp);\r
+       if (n < 0) {\r
+               lprintf("menu_loop_romsel failed, dir: %s\n", curr_path);\r
+\r
+               // try root\r
+               getcwd(curr_path, len);\r
+               n = scandir(curr_path, &namelist, scandir_filter, scandir_cmp);\r
+               if (n < 0) {\r
+                       // oops, we failed\r
+                       lprintf("menu_loop_romsel failed, dir: %s\n", curr_path);\r
+                       return NULL;\r
+               }\r
+       }\r
+\r
+       // try to find sel\r
+       if (fname != NULL) {\r
+               int i;\r
+               for (i = 1; i < n; i++) {\r
+                       if (strcmp(namelist[i]->d_name, fname) == 0) {\r
+                               sel = i - 1;\r
                                break;\r
+                       }\r
                }\r
-               plat_video_menu_end();\r
+       }\r
 \r
-               inp = in_menu_wait(PBTN_EAST|PBTN_MBACK|PBTN_WEST|PBTN_NORTH|PBTN_L|PBTN_R|PBTN_UP|PBTN_DOWN|PBTN_LEFT|PBTN_RIGHT);\r
-               if (inp & PBTN_MBACK) return;\r
-               if (inp & PBTN_L) { mode--; if (mode < 0) mode = 3; }\r
-               if (inp & PBTN_R) { mode++; if (mode > 3) mode = 0; }\r
-               switch (mode)\r
+       for (;;)\r
+       {\r
+               draw_dirlist(curr_path, namelist, n, sel);\r
+               inp = in_menu_wait(PBTN_UP|PBTN_DOWN|PBTN_LEFT|PBTN_RIGHT|\r
+                       PBTN_L|PBTN_R|PBTN_WEST|PBTN_MOK|PBTN_MBACK|PBTN_MENU, 33); // TODO L R\r
+               if (inp & PBTN_UP  )  { sel--;   if (sel < 0)   sel = n-2; }\r
+               if (inp & PBTN_DOWN)  { sel++;   if (sel > n-2) sel = 0; }\r
+               if (inp & PBTN_LEFT)  { sel-=10; if (sel < 0)   sel = 0; }\r
+               if (inp & PBTN_L)     { sel-=24; if (sel < 0)   sel = 0; }\r
+               if (inp & PBTN_RIGHT) { sel+=10; if (sel > n-2) sel = n-2; }\r
+               if (inp & PBTN_R)     { sel+=24; if (sel > n-2) sel = n-2; }\r
+               if ((inp & PBTN_MOK) || (inp & (PBTN_MENU|PBTN_WEST)) == (PBTN_MENU|PBTN_WEST)) // enter dir/select || delete\r
                {\r
-                       case 0:\r
-                               if (inp & PBTN_EAST) SekStepM68k();\r
-                               if (inp & PBTN_NORTH) {\r
-                                       while (inp & PBTN_NORTH) inp = in_menu_wait_any(-1);\r
-                                       mplayer_loop();\r
+                       again:\r
+                       if (namelist[sel+1]->d_type == DT_REG)\r
+                       {\r
+                               strcpy(rom_fname_reload, curr_path);\r
+                               strcat(rom_fname_reload, "/");\r
+                               strcat(rom_fname_reload, namelist[sel+1]->d_name);\r
+                               if (inp & PBTN_MOK) { // return sel\r
+                                       ret = rom_fname_reload;\r
+                                       break;\r
                                }\r
-                               if ((inp & (PBTN_WEST|PBTN_LEFT)) == (PBTN_WEST|PBTN_LEFT)) {\r
-                                       mkdir("dumps", 0777);\r
-                                       PDebugDumpMem();\r
-                                       while (inp & PBTN_WEST) inp = in_menu_wait_any(-1);\r
-                                       dumped = 1;\r
+//                             do_delete(rom_fname_reload, namelist[sel+1]->d_name); // TODO\r
+                               if (n > 0) {\r
+                                       while (n--) free(namelist[n]);\r
+                                       free(namelist);\r
+                               }\r
+                               goto rescan;\r
+                       }\r
+                       else if (namelist[sel+1]->d_type == DT_DIR)\r
+                       {\r
+                               int newlen;\r
+                               char *p, *newdir;\r
+                               if (!(inp & PBTN_MOK)) continue;\r
+                               newlen = strlen(curr_path) + strlen(namelist[sel+1]->d_name) + 2;\r
+                               newdir = malloc(newlen);\r
+                               if (strcmp(namelist[sel+1]->d_name, "..") == 0) {\r
+                                       char *start = curr_path;\r
+                                       p = start + strlen(start) - 1;\r
+                                       while (*p == '/' && p > start) p--;\r
+                                       while (*p != '/' && p > start) p--;\r
+                                       if (p <= start) strcpy(newdir, "/");\r
+                                       else { strncpy(newdir, start, p-start); newdir[p-start] = 0; }\r
+                               } else {\r
+                                       strcpy(newdir, curr_path);\r
+                                       p = newdir + strlen(newdir) - 1;\r
+                                       while (*p == '/' && p >= newdir) *p-- = 0;\r
+                                       strcat(newdir, "/");\r
+                                       strcat(newdir, namelist[sel+1]->d_name);\r
                                }\r
+                               ret = menu_loop_romsel(newdir, newlen);\r
+                               free(newdir);\r
                                break;\r
-                       case 1:\r
-                               if (inp & PBTN_LEFT)  PicoDrawMask ^= PDRAW_LAYERB_ON;\r
-                               if (inp & PBTN_RIGHT) PicoDrawMask ^= PDRAW_LAYERA_ON;\r
-                               if (inp & PBTN_DOWN)  PicoDrawMask ^= PDRAW_SPRITES_LOW_ON;\r
+                       }\r
+                       else\r
+                       {\r
+                               // unknown file type, happens on NTFS mounts. Try to guess.\r
+                               FILE *tstf; int tmp;\r
+                               strcpy(rom_fname_reload, curr_path);\r
+                               strcat(rom_fname_reload, "/");\r
+                               strcat(rom_fname_reload, namelist[sel+1]->d_name);\r
+                               tstf = fopen(rom_fname_reload, "rb");\r
+                               if (tstf != NULL)\r
+                               {\r
+                                       if (fread(&tmp, 1, 1, tstf) > 0 || ferror(tstf) == 0)\r
+                                               namelist[sel+1]->d_type = DT_REG;\r
+                                       else    namelist[sel+1]->d_type = DT_DIR;\r
+                                       fclose(tstf);\r
+                                       goto again;\r
+                               }\r
+                       }\r
+               }\r
+               if (inp & PBTN_MBACK)\r
+                       break;\r
+       }\r
+\r
+       if (n > 0) {\r
+               while (n--) free(namelist[n]);\r
+               free(namelist);\r
+       }\r
+\r
+       return ret;\r
+}\r
+\r
+// ------------ patch/gg menu ------------\r
+\r
+static void draw_patchlist(int sel)\r
+{\r
+       int max_cnt, start, i, pos, active;\r
+\r
+       max_cnt = SCREEN_HEIGHT / 10;\r
+       start = max_cnt / 2 - sel;\r
+\r
+       plat_video_menu_begin();\r
+\r
+       for (i = 0; i < PicoPatchCount; i++) {\r
+               pos = start + i;\r
+               if (pos < 0) continue;\r
+               if (pos >= max_cnt) break;\r
+               active = PicoPatches[i].active;\r
+               smalltext_out16(14,     pos*10, active ? "ON " : "OFF", active ? 0xfff6 : 0xffff);\r
+               smalltext_out16(14+6*4, pos*10, PicoPatches[i].name,    active ? 0xfff6 : 0xffff);\r
+       }\r
+       pos = start + i;\r
+       if (pos < max_cnt)\r
+               smalltext_out16(14, pos * 10, "done", 0xffff);\r
+\r
+       text_out16(5, max_cnt / 2 * 10, ">");\r
+       plat_video_menu_end();\r
+}\r
+\r
+static void menu_loop_patches(void)\r
+{\r
+       static int menu_sel = 0;\r
+       int inp;\r
+\r
+       for (;;)\r
+       {\r
+               draw_patchlist(menu_sel);\r
+               inp = in_menu_wait(PBTN_UP|PBTN_DOWN|PBTN_LEFT|PBTN_RIGHT|PBTN_L|PBTN_R|PBTN_MOK|PBTN_MBACK, 33);\r
+               if (inp & PBTN_UP  ) { menu_sel--; if (menu_sel < 0) menu_sel = PicoPatchCount; }\r
+               if (inp & PBTN_DOWN) { menu_sel++; if (menu_sel > PicoPatchCount) menu_sel = 0; }\r
+               if (inp &(PBTN_LEFT|PBTN_L))  { menu_sel-=10; if (menu_sel < 0) menu_sel = 0; }\r
+               if (inp &(PBTN_RIGHT|PBTN_R)) { menu_sel+=10; if (menu_sel > PicoPatchCount) menu_sel = PicoPatchCount; }\r
+               if (inp & PBTN_MOK) { // action\r
+                       if (menu_sel < PicoPatchCount)\r
+                               PicoPatches[menu_sel].active = !PicoPatches[menu_sel].active;\r
+                       else    break;\r
+               }\r
+               if (inp & PBTN_MBACK)\r
+                       break;\r
+       }\r
+}\r
+\r
+// ------------ savestate loader ------------\r
+\r
+static int state_slot_flags = 0;\r
+\r
+static void state_check_slots(void)\r
+{\r
+       int slot;\r
+\r
+       state_slot_flags = 0;\r
+\r
+       for (slot = 0; slot < 10; slot++) {\r
+               if (emu_checkSaveFile(slot))\r
+                       state_slot_flags |= 1 << slot;\r
+       }\r
+}\r
+\r
+static void draw_savestate_bg(int slot)\r
+{\r
+       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
+\r
+       fname = emu_GetSaveFName(1, 0, slot);\r
+       if (!fname) return;\r
+\r
+       tmp_vram = malloc(sizeof(Pico.vram));\r
+       if (tmp_vram == NULL) return;\r
+\r
+       memcpy(tmp_vram, Pico.vram, sizeof(Pico.vram));\r
+       memcpy(tmp_cram, Pico.cram, sizeof(Pico.cram));\r
+       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
+\r
+       /* do a frame and fetch menu bg */\r
+       emu_forcedFrame(POPT_EN_SOFTSCALE);\r
+       plat_video_menu_enter(1);\r
+\r
+       memcpy(Pico.vram, tmp_vram, sizeof(Pico.vram));\r
+       memcpy(Pico.cram, tmp_cram, sizeof(Pico.cram));\r
+       memcpy(Pico.vsram, tmp_vsram, sizeof(Pico.vsram));\r
+       memcpy(&Pico.video, &tmp_pv,  sizeof(Pico.video));\r
+       free(tmp_vram);\r
+}\r
+\r
+static void draw_savestate_menu(int menu_sel, int is_loading)\r
+{\r
+       int i, x, y, w, h;\r
+\r
+       if (state_slot_flags & (1 << menu_sel))\r
+               draw_savestate_bg(menu_sel);\r
+\r
+       w = 13 * 8 + 16;\r
+       h = (1+2+10+1) * 10;\r
+       x = SCREEN_WIDTH / 2 - w / 2;\r
+       if (x < 0) x = 0;\r
+       y = SCREEN_HEIGHT / 2 - h / 2;\r
+       if (y < 0) y = 0;\r
+\r
+       plat_video_menu_begin();\r
+\r
+       text_out16(x, y, is_loading ? "Load state" : "Save state");\r
+       y += 3*10;\r
+\r
+       menu_draw_selection(x - 16, y + menu_sel * 10, 13 * 8 + 4);\r
+\r
+       /* draw all 10 slots */\r
+       y += 10;\r
+       for (i = 0; i < 10; i++, y += 10)\r
+       {\r
+               text_out16(x, y, "SLOT %i (%s)", i, (state_slot_flags & (1 << i)) ? "USED" : "free");\r
+       }\r
+       text_out16(x, y, "back");\r
+\r
+       plat_video_menu_end();\r
+}\r
+\r
+static int menu_loop_savestate(int is_loading)\r
+{\r
+       static int menu_sel = 10;\r
+       int menu_sel_max = 10;\r
+       unsigned long inp = 0;\r
+\r
+       state_check_slots();\r
+\r
+       for (;;)\r
+       {\r
+               draw_savestate_menu(menu_sel, is_loading);\r
+               inp = in_menu_wait(PBTN_UP|PBTN_DOWN|PBTN_MOK|PBTN_MBACK, 100);\r
+               if (inp & PBTN_UP) {\r
+                       do {\r
+                               menu_sel--;\r
+                               if (menu_sel < 0)\r
+                                       menu_sel = menu_sel_max;\r
+                       } while (!(state_slot_flags & (1 << menu_sel)) && menu_sel != menu_sel_max && is_loading);\r
+               }\r
+               if (inp & PBTN_DOWN) {\r
+                       do {\r
+                               menu_sel++;\r
+                               if (menu_sel > menu_sel_max)\r
+                                       menu_sel = 0;\r
+                       } while (!(state_slot_flags & (1 << menu_sel)) && menu_sel != menu_sel_max && is_loading);\r
+               }\r
+               if (inp & PBTN_MOK) { // save/load\r
+                       if (menu_sel < 10) {\r
+                               state_slot = menu_sel;\r
+                               if (emu_SaveLoadGame(is_loading, 0)) {\r
+                                       strcpy(menuErrorMsg, is_loading ? "Load failed" : "Save failed");\r
+                                       return 0;\r
+                               }\r
+                               return 1;\r
+                       }\r
+                       return 0;\r
+               }\r
+               if (inp & PBTN_MBACK)\r
+                       return 0;\r
+       }\r
+}\r
+\r
+// -------------- key config --------------\r
+\r
+static char *action_binds(int player_idx, int action_mask, int dev_id)\r
+{\r
+       const int *binds;\r
+       int k, count;\r
+\r
+       static_buff[0] = 0;\r
+\r
+       binds = in_get_dev_binds(dev_id);\r
+       if (binds == NULL)\r
+               return static_buff;\r
+\r
+       count = in_get_dev_bind_count(dev_id);\r
+       for (k = 0; k < count; k++)\r
+       {\r
+               const char *xname;\r
+               if (!(binds[k] & action_mask))\r
+                       continue;\r
+\r
+               if (player_idx >= 0 && ((binds[k] >> 16) & 3) != player_idx)\r
+                       continue;\r
+\r
+               xname = in_get_key_name(dev_id, k);\r
+               if (static_buff[0])\r
+                       strncat(static_buff, " + ", sizeof(static_buff));\r
+               strncat(static_buff, xname, sizeof(static_buff));\r
+       }\r
+\r
+       return static_buff;\r
+}\r
+\r
+static int count_bound_keys(int dev_id, int action_mask, int player_idx)\r
+{\r
+       const int *binds;\r
+       int k, keys = 0;\r
+       int count;\r
+\r
+       binds = in_get_dev_binds(dev_id);\r
+       if (binds == NULL)\r
+               return 0;\r
+\r
+       count = in_get_dev_bind_count(dev_id);\r
+       for (k = 0; k < count; k++)\r
+       {\r
+               if (!(binds[k] & action_mask))\r
+                       continue;\r
+\r
+               if (player_idx >= 0 && ((binds[k] >> 16) & 3) != player_idx)\r
+                       continue;\r
+\r
+               keys++;\r
+       }\r
+\r
+       return keys;\r
+}\r
+\r
+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
+       int x, y = 30, w, i;\r
+       const char *dev_name;\r
+\r
+       x = SCREEN_WIDTH / 2 - 32*8 / 2;\r
+       if (x < 0) x = 0;\r
+\r
+       plat_video_menu_begin();\r
+       if (player_idx >= 0)\r
+               text_out16(x, 10, "Player %i controls", player_idx + 1);\r
+       else\r
+               text_out16(x, 10, "Emulator controls");\r
+\r
+       menu_draw_selection(x - 16, y + sel*10, (player_idx >= 0) ? 66 : 140);\r
+\r
+       for (i = 0; i < opt_cnt; i++, y+=10)\r
+               text_out16(x, y, "%s : %s", opts[i].name,\r
+                       action_binds(player_idx, opts[i].mask, dev_id));\r
+\r
+       dev_name = in_get_dev_name(dev_id, 1, 1);\r
+       w = strlen(dev_name) * 8;\r
+       if (w < 30 * 8)\r
+               w = 30 * 8;\r
+       if (w > SCREEN_WIDTH)\r
+               w = SCREEN_WIDTH;\r
+\r
+       x = SCREEN_WIDTH / 2 - w / 2;\r
+\r
+       if (dev_count > 1) {\r
+               text_out16(x, SCREEN_HEIGHT - 4*10, "Viewing binds for:");\r
+               text_out16(x, SCREEN_HEIGHT - 3*10, dev_name);\r
+       }\r
+\r
+       if (is_bind)\r
+               text_out16(x, SCREEN_HEIGHT - 2*10, "Press a button to bind/unbind");\r
+       else if (dev_count > 1)\r
+               text_out16(x, SCREEN_HEIGHT - 2*10, "Press left/right for other devs");\r
+\r
+       plat_video_menu_end();\r
+}\r
+\r
+static void key_config_loop(const me_bind_action *opts, int opt_cnt, int player_idx)\r
+{\r
+       int i, sel = 0, menu_sel_max = opt_cnt - 1;\r
+       int dev_id, dev_count, kc, is_down, mkey, unbind;\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
+                       dev_count++;\r
+                       if (dev_id < 0)\r
+                               dev_id = i;\r
+               }\r
+       }\r
+\r
+       if (dev_id == -1) {\r
+               lprintf("no devs, can't do config\n");\r
+               return;\r
+       }\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
+               switch (mkey) {\r
+                       case PBTN_UP:   sel--; if (sel < 0) sel = menu_sel_max; continue;\r
+                       case PBTN_DOWN: sel++; if (sel > menu_sel_max) sel = 0; continue;\r
+                       case PBTN_LEFT:\r
+                               for (i = 0, dev_id--; i < IN_MAX_DEVS; i++, dev_id--) {\r
+                                       if (dev_id < 0)\r
+                                               dev_id = IN_MAX_DEVS - 1;\r
+                                       if (in_get_dev_name(dev_id, 1, 0) != NULL)\r
+                                               break;\r
+                               }\r
+                               continue;\r
+                       case PBTN_RIGHT:\r
+                               for (i = 0, dev_id++; i < IN_MAX_DEVS; i++, dev_id++) {\r
+                                       if (dev_id >= IN_MAX_DEVS)\r
+                                               dev_id = 0;\r
+                                       if (in_get_dev_name(dev_id, 1, 0) != NULL)\r
+                                               break;\r
+                               }\r
+                               continue;\r
+                       case PBTN_MBACK: return;\r
+                       case PBTN_MOK:\r
+                               if (sel >= opt_cnt)\r
+                                       return;\r
+                               while (in_menu_wait_any(30) & PBTN_MOK);\r
+                               break;\r
+                       default:continue;\r
+               }\r
+\r
+               draw_key_config(opts, opt_cnt, player_idx, sel, dev_id, dev_count, 1);\r
+\r
+               /* wait for some up event */\r
+               for (is_down = 1; is_down; )\r
+                       kc = in_update_keycode(&dev_id, &is_down, -1);\r
+\r
+               unbind = count_bound_keys(dev_id, opts[sel].mask, player_idx) >= 2;\r
+\r
+               in_bind_key(dev_id, kc, opts[sel].mask, unbind);\r
+               if (player_idx >= 0) {\r
+                       /* FIXME */\r
+                       in_bind_key(dev_id, kc, 3 << 16, 1);\r
+                       in_bind_key(dev_id, kc, player_idx << 16, 0);\r
+               }\r
+       }\r
+}\r
+\r
+// PicoPad[] format: MXYZ SACB RLDU\r
+me_bind_action me_ctrl_actions[15] =\r
+{\r
+       { "UP     ", 0x0001 },\r
+       { "DOWN   ", 0x0002 },\r
+       { "LEFT   ", 0x0004 },\r
+       { "RIGHT  ", 0x0008 },\r
+       { "A      ", 0x0040 },\r
+       { "B      ", 0x0010 },\r
+       { "C      ", 0x0020 },\r
+       { "A turbo", 0x4000 },\r
+       { "B turbo", 0x1000 },\r
+       { "C turbo", 0x2000 },\r
+       { "START  ", 0x0080 },\r
+       { "MODE   ", 0x0800 },\r
+       { "X      ", 0x0400 },\r
+       { "Y      ", 0x0200 },\r
+       { "Z      ", 0x0100 }\r
+};\r
+\r
+// player2_flag, reserved, ?, ?,\r
+// ?, ?, fast forward, menu\r
+// "NEXT SAVE SLOT", "PREV SAVE SLOT", "SWITCH RENDERER", "SAVE STATE",\r
+// "LOAD STATE", "VOLUME UP", "VOLUME DOWN", "DONE"\r
+me_bind_action emuctrl_actions[] =\r
+{\r
+       { "Load State       ", 1<<28 },\r
+       { "Save State       ", 1<<27 },\r
+       { "Prev Save Slot   ", 1<<25 },\r
+       { "Next Save Slot   ", 1<<24 },\r
+       { "Switch Renderer  ", 1<<26 },\r
+       { "Volume Down      ", 1<<30 },\r
+       { "Volume Up        ", 1<<29 },\r
+       { "Fast forward     ", 1<<22 },\r
+       { "Enter Menu       ", 1<<23 },\r
+       { "Pico Next page   ", 1<<21 },\r
+       { "Pico Prev page   ", 1<<20 },\r
+       { "Pico Switch input", 1<<19 },\r
+       { NULL,                0     }\r
+};\r
+\r
+static int key_config_loop_wrap(menu_id id, int keys)\r
+{\r
+       switch (id) {\r
+               case MA_CTRL_PLAYER1:\r
+                       key_config_loop(me_ctrl_actions, array_size(me_ctrl_actions), 0);\r
+                       break;\r
+               case MA_CTRL_PLAYER2:\r
+                       key_config_loop(me_ctrl_actions, array_size(me_ctrl_actions), 1);\r
+                       break;\r
+               case MA_CTRL_EMU:\r
+                       key_config_loop(emuctrl_actions, array_size(emuctrl_actions) - 1, -1);\r
+                       break;\r
+               default:\r
+                       break;\r
+       }\r
+       return 0;\r
+}\r
+\r
+static const char *mgn_dev_name(menu_id id, int *offs)\r
+{\r
+       const char *name = NULL;\r
+       static int it = 0;\r
+\r
+       if (id == MA_CTRL_DEV_FIRST)\r
+               it = 0;\r
+\r
+       for (; it < IN_MAX_DEVS; it++) {\r
+               name = in_get_dev_name(it, 1, 1);\r
+               if (name != NULL)\r
+                       break;\r
+       }\r
+\r
+       it++;\r
+       return name;\r
+}\r
+\r
+static int mh_saveloadcfg(menu_id id, int keys);\r
+static const char *mgn_savecfg(menu_id id, int *offs);\r
+\r
+static menu_entry e_menu_keyconfig[] =\r
+{\r
+       mee_handler_id("Player 1",          MA_CTRL_PLAYER1,    key_config_loop_wrap),\r
+       mee_handler_id("Player 2",          MA_CTRL_PLAYER2,    key_config_loop_wrap),\r
+       mee_handler_id("Emulator controls", MA_CTRL_EMU,        key_config_loop_wrap),\r
+       mee_onoff     ("6 button pad",      MA_OPT_6BUTTON_PAD, PicoOpt, POPT_6BTN_PAD),\r
+       mee_range     ("Turbo rate",        MA_CTRL_TURBO_RATE, currentConfig.turbo_rate, 1, 30),\r
+       mee_handler_mkname_id(MA_OPT_SAVECFG, mh_saveloadcfg, mgn_savecfg),\r
+       mee_handler_id("Save cfg for loaded game", MA_OPT_SAVECFG_GAME, mh_saveloadcfg),\r
+       mee_label     (""),\r
+       mee_label     ("Input devices:"),\r
+       mee_label_mk  (MA_CTRL_DEV_FIRST, mgn_dev_name),\r
+       mee_label_mk  (MA_CTRL_DEV_NEXT,  mgn_dev_name),\r
+       mee_label_mk  (MA_CTRL_DEV_NEXT,  mgn_dev_name),\r
+       mee_label_mk  (MA_CTRL_DEV_NEXT,  mgn_dev_name),\r
+       mee_label_mk  (MA_CTRL_DEV_NEXT,  mgn_dev_name),\r
+       mee_label_mk  (MA_CTRL_DEV_NEXT,  mgn_dev_name),\r
+       mee_label_mk  (MA_CTRL_DEV_NEXT,  mgn_dev_name),\r
+       mee_end,\r
+};\r
+\r
+static int menu_loop_keyconfig(menu_id id, int keys)\r
+{\r
+       static int sel = 0;\r
+       me_loop(e_menu_keyconfig, &sel);\r
+       return 0;\r
+}\r
+\r
+// ------------ SCD options menu ------------\r
+\r
+static const char *mgn_cdopt_ra(menu_id id, int *offs)\r
+{\r
+       *offs = -5;\r
+       if (PicoCDBuffers <= 0)\r
+               return "     OFF";\r
+       sprintf(static_buff, "%5iK", PicoCDBuffers * 2);\r
+       return static_buff;\r
+}\r
+\r
+static int mh_cdopt_ra(menu_id id, int keys)\r
+{\r
+       if (keys & PBTN_LEFT) {\r
+               PicoCDBuffers >>= 1;\r
+               if (PicoCDBuffers < 2)\r
+                       PicoCDBuffers = 0;\r
+       } else {\r
+               if (PicoCDBuffers <= 0)\r
+                       PicoCDBuffers = 1;\r
+               PicoCDBuffers <<= 1;\r
+               if (PicoCDBuffers > 8*1024)\r
+                       PicoCDBuffers = 8*1024; // 16M\r
+       }\r
+       return 0;\r
+}\r
+\r
+static menu_entry e_menu_cd_options[] =\r
+{\r
+       mee_onoff("CD LEDs",              MA_CDOPT_LEDS,          currentConfig.EmuOpt, 0x0400),\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
+       mee_onoff("SaveRAM cart",         MA_CDOPT_SAVERAM,       PicoOpt, POPT_EN_MCD_RAMCART),\r
+       mee_onoff("Scale/Rot. fx (slow)", MA_CDOPT_SCALEROT_CHIP, PicoOpt, POPT_EN_MCD_GFX),\r
+       mee_onoff("Better sync (slow)",   MA_CDOPT_BETTER_SYNC,   PicoOpt, POPT_EN_MCD_PSYNC),\r
+       mee_end,\r
+};\r
+\r
+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
+       return 0;\r
+}\r
+\r
+// ------------ adv options menu ------------\r
+\r
+// TODO FIXME fix if and mv\r
+static const char *mgn_aopt_sqhack(menu_id id, int *offs)\r
+{\r
+       *offs = -10;\r
+       sprintf(static_buff, "%s, %s", 111 ? "  active" : "inactive",\r
+               (currentConfig.EmuOpt & 0x10) ? "ON" : "OFF");\r
+       return static_buff;\r
+}\r
+\r
+static menu_entry e_menu_adv_options[] =\r
+{\r
+       mee_onoff     ("SRAM/BRAM saves",          MA_OPT_SRAM_STATES,    currentConfig.EmuOpt, EOPT_USE_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_label     ("- needs restart -"),\r
+       mee_onoff     ("craigix's RAM timings",    MA_OPT2_RAMTIMINGS,    currentConfig.EmuOpt, 0x0100),\r
+       mee_onoff_cust("Squidgehack",              MA_OPT2_SQUIDGEHACK,   currentConfig.EmuOpt, 0x0010, mgn_aopt_sqhack),\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_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
+       return 0;\r
+}\r
+\r
+// ------------ gfx options menu ------------\r
+\r
+static const char *mgn_opt_scaling(menu_id id, int *offs)\r
+{\r
+       *offs = -12;\r
+       switch (currentConfig.scaling) {\r
+               default: return "            OFF";\r
+               case 1:  return "hw horizontal";\r
+               case 2:  return "hw horiz. + vert.";\r
+               case 3:  return "sw horizontal";\r
+       }\r
+}\r
+\r
+static const char *mgn_aopt_gamma(menu_id id, int *offs)\r
+{\r
+       sprintf(static_buff, "%i.%02i", currentConfig.gamma / 100, currentConfig.gamma%100);\r
+       return static_buff;\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, 0x1000),\r
+       mee_onoff     ("Perfect vsync",            MA_OPT2_VSYNC,         currentConfig.EmuOpt, 0x2000),\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
+       return 0;\r
+}\r
+\r
+// ------------ options menu ------------\r
+\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
+       int i;\r
+\r
+       for (i = 0; i < 5; i++)\r
+               if (rates[i] == rate) break;\r
+\r
+       i += dir ? 1 : -1;\r
+       if (i > 4) {\r
+               if (!(PicoOpt & POPT_EN_STEREO)) {\r
+                       PicoOpt |= POPT_EN_STEREO;\r
+                       return rates[0];\r
+               }\r
+               return rates[4];\r
+       }\r
+       if (i < 0) {\r
+               if (PicoOpt & POPT_EN_STEREO) {\r
+                       PicoOpt &= ~POPT_EN_STEREO;\r
+                       return rates[4];\r
+               }\r
+               return rates[0];\r
+       }\r
+       return rates[i];\r
+}\r
+\r
+static void region_prevnext(int right)\r
+{\r
+       // jp_ntsc=1, jp_pal=2, usa=4, eu=8\r
+       static const int rgn_orders[] = { 0x148, 0x184, 0x814, 0x418, 0x841, 0x481 };\r
+       int i;\r
+\r
+       if (right) {\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 PicoRegionOverride=1;\r
+               }\r
+               else\r
+                       PicoRegionOverride <<= 1;\r
+               if (PicoRegionOverride > 8)\r
+                       PicoRegionOverride = 8;\r
+       } else {\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\r
+                       PicoRegionOverride >>= 1;\r
+       }\r
+}\r
+\r
+static int mh_opt_misc(menu_id id, int keys)\r
+{\r
+       int i;\r
+\r
+       switch (id) {\r
+       case MA_OPT_SOUND_QUALITY:\r
+               PsndRate = sndrate_prevnext(PsndRate, keys & PBTN_RIGHT);\r
+               break;\r
+       case MA_OPT_REGION:\r
+               region_prevnext(keys & PBTN_RIGHT);\r
+               break;\r
+       case MA_OPT_CONFIRM_STATES:\r
+               i = ((currentConfig.EmuOpt>>9)&1) | ((currentConfig.EmuOpt>>10)&2);\r
+               i += (keys & PBTN_LEFT) ? -1 : 1;\r
+               if (i < 0) i = 0; else if (i > 3) i = 3;\r
+               i |= i << 1; i &= ~2;\r
+               currentConfig.EmuOpt &= ~0xa00;\r
+               currentConfig.EmuOpt |= i << 9;\r
+               break;\r
+       default:\r
+               break;\r
+       }\r
+       return 0;\r
+}\r
+\r
+static int mh_saveloadcfg(menu_id id, int keys)\r
+{\r
+       int ret;\r
+\r
+       if (keys & (PBTN_LEFT|PBTN_RIGHT)) { // multi choice\r
+               config_slot += (keys & PBTN_LEFT) ? -1 : 1;\r
+               if (config_slot < 0) config_slot = 9;\r
+               else if (config_slot > 9) config_slot = 0;\r
+               me_enable(e_menu_options, MA_OPT_LOADCFG, config_slot != config_slot_current);\r
+               return 0;\r
+       }\r
+\r
+       switch (id) {\r
+       case MA_OPT_SAVECFG:\r
+       case MA_OPT_SAVECFG_GAME:\r
+               if (emu_WriteConfig(id == MA_OPT_SAVECFG_GAME ? 1 : 0))\r
+                       strcpy(menuErrorMsg, "config saved");\r
+               else\r
+                       strcpy(menuErrorMsg, "failed to write config");\r
+               break;\r
+       case MA_OPT_LOADCFG:\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
+               break;\r
+       default:\r
+               return 0;\r
+       }\r
+\r
+       return 1;\r
+}\r
+\r
+static const char *mgn_opt_renderer(menu_id id, int *offs)\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
+}\r
+\r
+static const char *mgn_opt_fskip(menu_id id, int *offs)\r
+{\r
+       if (currentConfig.Frameskip < 0)\r
+               return "Auto";\r
+       sprintf(static_buff, "%d", currentConfig.Frameskip);\r
+       return static_buff;\r
+}\r
+\r
+static const char *mgn_opt_sound(menu_id id, int *offs)\r
+{\r
+       const char *str2;\r
+       *offs = -8;\r
+       str2 = (PicoOpt & POPT_EN_STEREO) ? "stereo" : "mono";\r
+       sprintf(static_buff, "%5iHz %s", PsndRate, str2);\r
+       return static_buff;\r
+}\r
+\r
+static const char *mgn_opt_region(menu_id id, int *offs)\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 code = PicoRegionOverride;\r
+       int u, i = 0;\r
+\r
+       *offs = -6;\r
+       if (code) {\r
+               code <<= 1;\r
+               while ((code >>= 1)) i++;\r
+               if (i > 4)\r
+                       return "unknown";\r
+               return names[i];\r
+       } else {\r
+               strcpy(static_buff, "Auto:");\r
+               for (u = 0; u < 3; u++) {\r
+                       code = (PicoAutoRgnOrder >> u*4) & 0xf;\r
+                       for (i = 0; code; code >>= 1, i++)\r
+                               ;\r
+                       strcat(static_buff, names_short[i]);\r
+               }\r
+               return static_buff;\r
+       }\r
+}\r
+\r
+static const char *mgn_opt_c_saves(menu_id id, int *offs)\r
+{\r
+       switch ((currentConfig.EmuOpt >> 9) & 5) {\r
+               default: return "OFF";\r
+               case 1:  return "writes";\r
+               case 4:  return "loads";\r
+               case 5:  return "both";\r
+       }\r
+}\r
+\r
+static const char *mgn_savecfg(menu_id id, int *offs)\r
+{\r
+       strcpy(static_buff, "Save global config");\r
+       if (config_slot != 0)\r
+               sprintf(static_buff + strlen(static_buff), " (profile: %i)", config_slot);\r
+       return static_buff;\r
+}\r
+\r
+static const char *mgn_loadcfg(menu_id id, int *offs)\r
+{\r
+       sprintf(static_buff, "Load cfg from profile %i", config_slot);\r
+       return static_buff;\r
+}\r
+\r
+static menu_entry e_menu_options[] =\r
+{\r
+       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_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
+#if   defined(__GP2X__)\r
+       mee_range     ("GP2X CPU clocks",          MA_OPT_CPU_CLOCKS,    currentConfig.CPUclock, 20, 400),\r
+#elif defined(PSP)\r
+       mee_range     ("PSP CPU clock",            MA_OPT_CPU_CLOCKS,    currentConfig.CPUclock, )\r
+#endif\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_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_end,\r
+};\r
+\r
+static int menu_loop_options(menu_id id, int keys)\r
+{\r
+       static int sel = 0;\r
+\r
+       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
+\r
+       return 0;\r
+}\r
+\r
+// ------------ debug menu ------------\r
+\r
+#include <sys/stat.h>\r
+#include <sys/types.h>\r
+\r
+#include <pico/debug.h>\r
+\r
+extern void SekStepM68k(void);\r
+\r
+static void mplayer_loop(void)\r
+{\r
+       emu_startSound();\r
+\r
+       while (1)\r
+       {\r
+               PDebugZ80Frame();\r
+               if (in_menu_wait_any(0) & PBTN_NORTH) break;\r
+               emu_waitSound();\r
+       }\r
+\r
+       emu_endSound();\r
+}\r
+\r
+static void draw_text_debug(const char *str, int skip, int from)\r
+{\r
+       const char *p;\r
+       int line;\r
+\r
+       p = str;\r
+       while (skip-- > 0)\r
+       {\r
+               while (*p && *p != '\n') p++;\r
+               if (*p == 0 || p[1] == 0) return;\r
+               p++;\r
+       }\r
+\r
+       str = p;\r
+       for (line = from; line < SCREEN_HEIGHT/10; line++)\r
+       {\r
+               while (*p && *p != '\n') p++;\r
+               smalltext_out16(1, line*10, str, 0xffff);\r
+               if (*p == 0) break;\r
+               p++; str = p;\r
+       }\r
+}\r
+\r
+static void draw_frame_debug(void)\r
+{\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
+\r
+       clear_screen();\r
+       emu_forcedFrame(0);\r
+       smalltext_out16(4, SCREEN_HEIGHT-8, layer_str, 0xffff);\r
+}\r
+\r
+static void debug_menu_loop(void)\r
+{\r
+       int inp, mode = 0;\r
+       int spr_offs = 0, dumped = 0;\r
+       char *tmp;\r
+\r
+       while (1)\r
+       {\r
+               switch (mode)\r
+               {\r
+                       case 0: plat_video_menu_begin();\r
+                               tmp = PDebugMain();\r
+                               emu_platformDebugCat(tmp);\r
+                               draw_text_debug(tmp, 0, 0);\r
+                               if (dumped) {\r
+                                       smalltext_out16(SCREEN_WIDTH-6*10, SCREEN_HEIGHT-8, "dumped", 0xffff);\r
+                                       dumped = 0;\r
+                               }\r
+                               break;\r
+                       case 1: draw_frame_debug(); break;\r
+                       case 2: clear_screen();\r
+                               emu_forcedFrame(0);\r
+                               darken_screen();\r
+                               PDebugShowSpriteStats((unsigned short *)SCREEN_BUFFER + (SCREEN_HEIGHT/2 - 240/2)*SCREEN_WIDTH +\r
+                                       SCREEN_WIDTH/2 - 320/2, SCREEN_WIDTH); break;\r
+                       case 3: clear_screen();\r
+                               PDebugShowPalette(SCREEN_BUFFER, SCREEN_WIDTH);\r
+                               PDebugShowSprite((unsigned short *)SCREEN_BUFFER + SCREEN_WIDTH*120+SCREEN_WIDTH/2+16,\r
+                                       SCREEN_WIDTH, spr_offs);\r
+                               draw_text_debug(PDebugSpriteList(), spr_offs, 6);\r
+                               break;\r
+               }\r
+               plat_video_menu_end();\r
+\r
+               inp = in_menu_wait(PBTN_EAST|PBTN_MBACK|PBTN_WEST|PBTN_NORTH|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
+               switch (mode)\r
+               {\r
+                       case 0:\r
+                               if (inp & PBTN_EAST) SekStepM68k();\r
+                               if (inp & PBTN_NORTH) {\r
+                                       while (inp & PBTN_NORTH) inp = in_menu_wait_any(-1);\r
+                                       mplayer_loop();\r
+                               }\r
+                               if ((inp & (PBTN_WEST|PBTN_LEFT)) == (PBTN_WEST|PBTN_LEFT)) {\r
+                                       mkdir("dumps", 0777);\r
+                                       PDebugDumpMem();\r
+                                       while (inp & PBTN_WEST) inp = in_menu_wait_any(-1);\r
+                                       dumped = 1;\r
+                               }\r
+                               break;\r
+                       case 1:\r
+                               if (inp & PBTN_LEFT)  PicoDrawMask ^= PDRAW_LAYERB_ON;\r
+                               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_EAST) {\r
                                        PsndOut = NULL; // just in case\r
@@ -789,32 +1763,177 @@ void debug_menu_loop(void)
        }\r
 }\r
 \r
-#endif // !UIQ3\r
+// ------------ main menu ------------\r
 \r
-// ------------ util ------------\r
+static char *romsel_run(void)\r
+{\r
+       char *ret, *sel_name;\r
+\r
+       sel_name = malloc(sizeof(rom_fname_loaded));\r
+       if (sel_name == NULL)\r
+               return NULL;\r
+       strcpy(sel_name, rom_fname_loaded);\r
+\r
+       ret = menu_loop_romsel(sel_name, sizeof(rom_fname_loaded));\r
+       free(sel_name);\r
+       return ret;\r
+}\r
 \r
-const char *me_region_name(unsigned int code, int auto_order)\r
+static int main_menu_handler(menu_id id, int keys)\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 = ((auto_order >> u*4) & 0xf) << 1;\r
-                       while((code >>= 1)) i++;\r
-                       strcat(name, names_short[i]);\r
+       char *ret_name;\r
+\r
+       switch (id)\r
+       {\r
+       case MA_MAIN_RESUME_GAME:\r
+               if (rom_loaded)\r
+                       return 1;\r
+               break;\r
+       case MA_MAIN_SAVE_STATE:\r
+               if (rom_loaded)\r
+                       return menu_loop_savestate(0);\r
+               break;\r
+       case MA_MAIN_LOAD_STATE:\r
+               if (rom_loaded)\r
+                       return menu_loop_savestate(1);\r
+               break;\r
+       case MA_MAIN_RESET_GAME:\r
+               if (rom_loaded) {\r
+                       emu_ResetGame();\r
+                       return 1;\r
+               }\r
+               break;\r
+       case MA_MAIN_LOAD_ROM:\r
+               ret_name = romsel_run();\r
+               if (ret_name != NULL) {\r
+                       lprintf("selected file: %s\n", ret_name);\r
+                       engineState = PGS_ReloadRom;\r
+                       return 1;\r
+               }\r
+               break;\r
+       case MA_MAIN_CREDITS:\r
+               draw_menu_credits();\r
+               in_menu_wait(PBTN_MOK|PBTN_MBACK, 70);\r
+               break;\r
+       case MA_MAIN_EXIT:\r
+               engineState = PGS_Quit;\r
+               return 1;\r
+       case MA_MAIN_PATCHES:\r
+               if (rom_loaded && PicoPatches) {\r
+                       menu_loop_patches();\r
+                       PicoPatchApply();\r
+                       strcpy(menuErrorMsg, "Patches applied");\r
                }\r
-               return name;\r
+               break;\r
+       default:\r
+               lprintf("%s: something unknown selected\n", __FUNCTION__);\r
+               break;\r
+       }\r
+\r
+       return 0;\r
+}\r
+\r
+static menu_entry e_menu_main[] =\r
+{\r
+       mee_handler_id("Resume game",        MA_MAIN_RESUME_GAME, main_menu_handler),\r
+       mee_handler_id("Save State",         MA_MAIN_SAVE_STATE,  main_menu_handler),\r
+       mee_handler_id("Load State",         MA_MAIN_LOAD_STATE,  main_menu_handler),\r
+       mee_handler_id("Reset game",         MA_MAIN_RESET_GAME,  main_menu_handler),\r
+       mee_handler_id("Load new ROM/ISO",   MA_MAIN_LOAD_ROM,    main_menu_handler),\r
+       mee_handler_id("Change options",     MA_MAIN_OPTIONS,     menu_loop_options),\r
+       mee_handler_id("Configure controls", MA_MAIN_OPTIONS,     menu_loop_keyconfig),\r
+       mee_handler_id("Credits",            MA_MAIN_CREDITS,     main_menu_handler),\r
+       mee_handler_id("Patches / GameGenie",MA_MAIN_PATCHES,     main_menu_handler),\r
+       mee_handler_id("Exit",               MA_MAIN_EXIT,        main_menu_handler),\r
+       mee_end,\r
+};\r
+\r
+void menu_loop(void)\r
+{\r
+       static int sel = 0;\r
+\r
+       me_enable(e_menu_main, MA_MAIN_RESUME_GAME, rom_loaded);\r
+       me_enable(e_menu_main, MA_MAIN_SAVE_STATE,  rom_loaded);\r
+       me_enable(e_menu_main, MA_MAIN_LOAD_STATE,  rom_loaded);\r
+       me_enable(e_menu_main, MA_MAIN_RESET_GAME,  rom_loaded);\r
+       me_enable(e_menu_main, MA_MAIN_PATCHES, PicoPatches != NULL);\r
+\r
+       plat_video_menu_enter(rom_loaded);\r
+       in_set_blocking(1);\r
+       me_loop(e_menu_main, &sel);\r
+       in_set_blocking(0);\r
+\r
+       if (rom_loaded && engineState == PGS_Menu) {\r
+               /* wait until menu, ok, back is released */\r
+               while (in_menu_wait_any(50) & (PBTN_MENU|PBTN_MOK|PBTN_MBACK));\r
+               engineState = PGS_Running;\r
+       }\r
+}\r
+\r
+// --------- CD tray close menu ----------\r
+\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_cdCheck(NULL, ret_name);\r
+       if (cd_type != CIT_NOT_CD)\r
+               ret = Insert_CD(ret_name, cd_type);\r
+       if (ret != 0) {\r
+               sprintf(menuErrorMsg, "Load failed, invalid CD image?");\r
+               lprintf("%s\n", menuErrorMsg);\r
+               return 0;\r
+       }\r
+\r
+       engineState = PGS_RestartRun;\r
+       return 1;\r
+}\r
+\r
+static int mh_tray_nothing(menu_id id, int keys)\r
+{\r
+       return 1;\r
+}\r
+\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  (""),\r
+       mee_label  (""),\r
+       mee_handler("Load CD image",  mh_tray_load_cd),\r
+       mee_handler("Insert nothing", mh_tray_nothing),\r
+};\r
+\r
+int menu_loop_tray(void)\r
+{\r
+       int ret = 1, sel = 0;\r
+\r
+       plat_video_menu_enter(rom_loaded);\r
+\r
+       in_set_blocking(1);\r
+       me_loop(e_menu_tray, &sel);\r
+       in_set_blocking(0);\r
+\r
+       if (engineState != PGS_RestartRun) {\r
+               engineState = PGS_RestartRun;\r
+               ret = 0; /* no CD inserted */\r
        }\r
+\r
+       while (in_menu_wait_any(50) & (PBTN_MENU|PBTN_MOK|PBTN_MBACK));\r
+\r
+       return ret;\r
 }\r
 \r
+#endif // !UIQ3\r
+\r
+// ------------ util ------------\r
+\r
 /* TODO: rename */\r
 void menu_darken_bg(void *dst, int pixels, int darker)\r
 {\r
@@ -838,3 +1957,49 @@ void menu_darken_bg(void *dst, int pixels, int darker)
        }\r
 }\r
 \r
+/* hidden options for config engine only */\r
+static menu_entry e_menu_hidden[] =\r
+{\r
+       mee_onoff("Accurate sprites", MA_OPT_ACC_SPRITES, PicoOpt, 0x080),\r
+       mee_end,\r
+};\r
+\r
+static menu_entry *e_menu_table[] =\r
+{\r
+       e_menu_options,\r
+       e_menu_gfx_options,\r
+       e_menu_adv_options,\r
+       e_menu_cd_options,\r
+       e_menu_keyconfig,\r
+       e_menu_hidden,\r
+};\r
+\r
+static menu_entry *me_list_table = NULL;\r
+static menu_entry *me_list_i = NULL;\r
+\r
+menu_entry *me_list_get_first(void)\r
+{\r
+       me_list_table = me_list_i = e_menu_table[0];\r
+       return me_list_i;\r
+}\r
+\r
+menu_entry *me_list_get_next(void)\r
+{\r
+       int i;\r
+\r
+       me_list_i++;\r
+       if (me_list_i->name != NULL)\r
+               return me_list_i;\r
+\r
+       for (i = 0; i < array_size(e_menu_table); i++)\r
+               if (me_list_table == e_menu_table[i])\r
+                       break;\r
+\r
+       if (i + 1 < array_size(e_menu_table))\r
+               me_list_table = me_list_i = e_menu_table[i + 1];\r
+       else\r
+               me_list_table = me_list_i = NULL;\r
+\r
+       return me_list_i;\r
+}\r
+\r
index 0227d52..c4aaaf0 100644 (file)
@@ -4,9 +4,6 @@
 void menu_init(void);
 void text_out16(int x, int y, const char *texto, ...);
 void smalltext_out16(int x, int y, const char *texto, int color);
-void smalltext_out16_lim(int x, int y, const char *texto, int color, int max);
-void menu_draw_selection(int x, int y, int w);
-void debug_menu_loop(void);
 
 extern char menuErrorMsg[64];
 
@@ -15,7 +12,9 @@ typedef enum
        MB_NONE = 1,            /* no auto processing */
        MB_OPT_ONOFF,           /* ON/OFF setting */
        MB_OPT_RANGE,           /* [min-max] setting */
-       MB_OPT_CUSTOM,
+       MB_OPT_CUSTOM,          /* custom value */
+       MB_OPT_CUSTONOFF,
+       MB_OPT_CUSTRANGE,
 } menu_behavior;
 
 typedef enum
@@ -97,6 +96,8 @@ typedef enum
        MA_CTRL_PLAYER2,
        MA_CTRL_EMU,
        MA_CTRL_TURBO_RATE,
+       MA_CTRL_DEV_FIRST,
+       MA_CTRL_DEV_NEXT,
        MA_CTRL_DONE,
 } menu_id;
 
@@ -107,22 +108,47 @@ typedef struct
        menu_id id;
        void *var;              /* for on-off/range settings */
        int mask;               /* bit to toggle for on/off */
-       signed char min;        /* for ranged integer settings, to be sign-extended */
-       signed char max;
-       char enabled;
-       char need_to_save;
-       int (*submenu_handler)(menu_id id);
-       const char * (*generate_name)(int is_left);
+       signed short min;       /* for ranged integer settings, to be sign-extended */
+       signed short max;
+       int enabled:1;
+       int need_to_save:1;
+       int selectable:1;
+       int (*handler)(menu_id id, int keys);
+       const char * (*generate_name)(menu_id id, int *offs);
 } menu_entry;
 
-#define mee_submenu_id(name, id, handler) \
-       { name, MB_NONE, id, NULL, 0, 0, 0, 1, 0, handler, NULL }
+#define mee_handler_id(name, id, handler) \
+       { name, MB_NONE, id, NULL, 0, 0, 0, 1, 0, 1, handler, NULL }
 
-#define mee_submenu(name, handler) \
-       mee_submenu_id(name, MA_NONE, handler)
+#define mee_handler(name, handler) \
+       mee_handler_id(name, MA_NONE, handler)
+
+#define mee_handler_mkname_id(id, handler, name_func) \
+       { "", MB_NONE, id, NULL, 0, 0, 0, 1, 0, 1, handler, name_func }
+
+#define mee_label(name) \
+       { name, MB_NONE, MA_NONE, NULL, 0, 0, 0, 1, 0, 0, NULL, NULL }
+
+#define mee_label_mk(id, name_func) \
+       { "", MB_NONE, id, NULL, 0, 0, 0, 1, 0, 0, NULL, name_func }
+
+#define mee_onoff(name, id, var, mask) \
+       { name, MB_OPT_ONOFF, id, &(var), mask, 0, 0, 1, 1, 1, NULL, NULL }
+
+#define mee_range(name, id, var, min, max) \
+       { name, MB_OPT_RANGE, id, &(var), 0, min, max, 1, 1, 1, NULL, NULL }
+
+#define mee_cust(name, id, handler, name_func) \
+       { name, MB_OPT_CUSTOM, id, NULL, 0, 0, 0, 1, 1, 1, handler, name_func }
+
+#define mee_onoff_cust(name, id, var, mask, name_func) \
+       { name, MB_OPT_CUSTONOFF, id, &(var), mask, 0, 0, 1, 1, 1, NULL, name_func }
+
+#define mee_range_cust(name, id, var, min, max, name_func) \
+       { name, MB_OPT_CUSTRANGE, id, &(var), 0, min, max, 1, 1, 1, NULL, name_func }
 
 #define mee_end \
-       { NULL, 0, 0, NULL, 0, 0, 0, 0, 0, NULL, NULL }
+       { NULL, 0, 0, NULL, 0, 0, 0, 0, 0, 0, NULL, NULL }
 
 typedef struct
 {
@@ -133,18 +159,8 @@ typedef struct
 extern me_bind_action me_ctrl_actions[15];
 extern me_bind_action emuctrl_actions[];       // platform code
 
-
-typedef void (me_draw_custom_f)(const menu_entry *entry, int x, int y, void *param);
-
-/* TODO: move? */
-int     me_id2offset(const menu_entry *entries, menu_id id);
-void    me_enable(menu_entry *entries, menu_id id, int enable);
-int     me_count_enabled(const menu_entry *ent);
-menu_id me_index2id(const menu_entry *entries, int index);
-void    me_draw(const menu_entry *entries, int count, int x, int y, me_draw_custom_f *cust_draw, void *param);
-int     me_process(menu_entry *entries, menu_id id, int is_next);
-
-const char *me_region_name(unsigned int code, int auto_order);
+menu_entry *me_list_get_first(void);
+menu_entry *me_list_get_next(void);
 
 void menu_darken_bg(void *dst, int pixels, int darker);
 
index 35ceaeb..27f331f 100644 (file)
@@ -1,22 +1,32 @@
-/* stuff to be implemented by platform code */
-
 #ifdef __cplusplus
 extern "C" {
 #endif
 
-extern const char * const keyNames[];
+/* stuff to be implemented by platform code */
+/* TODO rename all these */
+extern const char * const keyNames[]; // TODO rm
 void  emu_prepareDefaultConfig(void);
 void  emu_platformDebugCat(char *str);
 void  emu_forcedFrame(int opts);
 void  emu_startSound(void);
 void  emu_endSound(void);
 void  emu_waitSound(void);
+void  emu_ResetGame(void); // TODO mv rm?
+
+void emu_noticeMsgUpdated(void);
+int  emu_getMainDir(char *dst, int len);
+void menu_romload_prepare(const char *rom_name);
+void menu_romload_end(void);
 
 /* menu: enter (switch bpp, etc), begin/end drawing */
 void plat_video_menu_enter(int is_rom_loaded);
 void plat_video_menu_begin(void);
 void plat_video_menu_end(void);
 
+int  plat_is_dir(const char *path);
+
+const char *plat_get_credits(void);
+
 #ifdef __cplusplus
 } // extern "C"
 #endif
diff --git a/common/posix.h b/common/posix.h
new file mode 100644 (file)
index 0000000..9100141
--- /dev/null
@@ -0,0 +1,13 @@
+/* define POSIX stuff: dirent, scandir, getcwd */
+#if defined(__linux__)
+
+#include <dirent.h>
+#include <unistd.h>
+
+#else
+
+#error "must define dirent"
+
+#endif
+
+
index ed4f928..625e679 100644 (file)
@@ -31,7 +31,7 @@ else
 use_cyclone = 1\r
 endif\r
 \r
-DEFINC = -I../.. -I. -DARM -D__GP2X__ # -DBENCHMARK\r
+DEFINC = -I../.. -I. -DARM -D__GP2X__ -DIN_GP2X # -DBENCHMARK\r
 COPT_COMMON = -static -Wall -Winline\r
 ifeq ($(DEBUG),)\r
 COPT_COMMON += -O3 -ftracer -fstrength-reduce -fomit-frame-pointer -fstrict-aliasing -ffast-math\r
@@ -54,14 +54,15 @@ LD = $(CROSS)ld
 OBJCOPY = $(CROSS)objcopy\r
 \r
 # frontend\r
-OBJS += main.o menu.o gp2x.o emu.o squidgehack.o cpuctrl.o\r
+OBJS += main.o gp2x.o emu.o in_gp2x.o squidgehack.o cpuctrl.o\r
 # 940 core control\r
 OBJS += 940ctl.o\r
 \r
 # common\r
 OBJS += platform/common/emu.o platform/common/menu.o platform/common/fonts.o platform/common/config.o \\r
        platform/common/arm_utils.o platform/common/arm_linux.o platform/common/readpng.o \\r
-       platform/common/mp3_helix.o platform/linux/usbjoy.o platform/linux/sndout_oss.o\r
+       platform/common/mp3_helix.o platform/common/input.o platform/linux/usbjoy.o \\r
+       platform/linux/sndout_oss.o platform/linux/plat.o\r
 \r
 # Pico\r
 ifeq "$(amalgamate)" "1"\r
index b9079a9..f5052db 100644 (file)
@@ -25,6 +25,7 @@
 #include "../common/input.h"\r
 #include "../linux/sndout_oss.h"\r
 #include "cpuctrl.h"\r
+#include "version.h"\r
 \r
 #include <pico/pico_int.h>\r
 #include <pico/patch.h>\r
 #endif\r
 \r
 \r
-int engineState;\r
 int select_exits = 0;\r
 \r
-char romFileName[PATH_MAX];\r
-\r
 extern int crashed_940;\r
 \r
 static short __attribute__((aligned(4))) sndBuffer[2*44100/50];\r
@@ -1065,3 +1063,24 @@ void emu_ResetGame(void)
        reset_timing = 1;\r
 }\r
 \r
+const char *plat_get_credits(void)\r
+{\r
+       return "PicoDrive v" VERSION " (c) notaz, 2006-2009\n\n\n"\r
+               "Credits:\n"\r
+               "fDave: Cyclone 68000 core,\n"\r
+               "      base code of PicoDrive\n"\r
+               "Reesy & FluBBa: DrZ80 core\n"\r
+               "MAME devs: YM2612 and SN76496 cores\n"\r
+               "rlyeh and others: minimal SDK\n"\r
+               "Squidge: squidgehack\n"\r
+               "Dzz: ARM940 sample\n"\r
+               "GnoStiC / Puck2099: USB joy code\n"\r
+               "craigix: GP2X hardware\n"\r
+               "ketchupgun: skin design\n"\r
+               "\n"\r
+               "special thanks (for docs, ideas):\n"\r
+               " Charles MacDonald, Haze,\n"\r
+               " Stephane Dallongeville,\n"\r
+               " Lordus, Exophase, Rokas,\n"\r
+               " Nemesis, Tasco Deluxe";\r
+}\r
index 21190c0..20342d1 100644 (file)
@@ -4,14 +4,9 @@
 // For commercial use, separate licencing terms must be obtained.\r
 \r
 \r
-extern char romFileName[];\r
-extern int engineState;\r
-\r
-\r
 void emu_Init(void);\r
 void emu_Deinit(void);\r
 void emu_Loop(void);\r
-void emu_ResetGame(void);\r
 \r
 void osd_text(int x, int y, const char *text);\r
 \r
index 489bbf7..78ee92e 100644 (file)
@@ -103,7 +103,9 @@ static int in_gp2x_menu_translate(int keycode)
                case BTN_RIGHT: return PBTN_RIGHT;
                case BTN_B:     return PBTN_MOK;
                case BTN_X:     return PBTN_MBACK;
-               case BTN_START: return PBTN_MENU;
+               case BTN_SELECT:return PBTN_MENU;
+               case BTN_L:     return PBTN_L;
+               case BTN_R:     return PBTN_R;
                default:        return 0;
        }
 }
index d8d82af..95a181c 100644 (file)
@@ -16,6 +16,7 @@
 #include "../common/emu.h"\r
 #include "../common/config.h"\r
 #include "../common/input.h"\r
+#include "../common/plat.h"\r
 #include "emu.h"\r
 #include "940ctl.h"\r
 #include "version.h"\r
@@ -61,9 +62,9 @@ void parse_cmd_line(int argc, char *argv[])
                } else {\r
                        /* External Frontend: ROM Name */\r
                        FILE *f;\r
-                       strncpy(romFileName, argv[x], PATH_MAX);\r
-                       romFileName[PATH_MAX-1] = 0;\r
-                       f = fopen(romFileName, "rb");\r
+                       strncpy(rom_fname_reload, argv[x], PATH_MAX);\r
+                       rom_fname_reload[PATH_MAX-1] = 0;\r
+                       f = fopen(rom_fname_reload, "rb");\r
                        if (f) fclose(f);\r
                        else unrecognized = 1;\r
                        engineState = PGS_ReloadRom;\r
@@ -122,7 +123,7 @@ int main(int argc, char *argv[])
 \r
        if (engineState == PGS_ReloadRom)\r
        {\r
-               if (emu_ReloadRom(romFileName)) {\r
+               if (emu_ReloadRom(rom_fname_reload)) {\r
                        engineState = PGS_Running;\r
                        if (load_state_slot >= 0) {\r
                                state_slot = load_state_slot;\r
@@ -140,7 +141,7 @@ int main(int argc, char *argv[])
                                break;\r
 \r
                        case PGS_ReloadRom:\r
-                               if (emu_ReloadRom(romFileName))\r
+                               if (emu_ReloadRom(rom_fname_reload))\r
                                        engineState = PGS_Running;\r
                                else {\r
                                        printf("PGS_ReloadRom == 0\n");\r
index f7b6827..006e982 100644 (file)
@@ -28,7 +28,7 @@ LDFLAGS += `pkg-config --libs gthread-2.0`
 
 # frontend
 OBJS += platform/gp2x/main.o platform/gp2x/emu.o platform/gp2x/plat.o usbjoy.o blit.o \
-               in_evdev.o sndout_oss.o gp2x.o 940ctl_ym2612.o log_io.o
+               in_evdev.o plat.o sndout_oss.o gp2x.o 940ctl_ym2612.o log_io.o
 # platform/gp2x/menu.o
 
 ifeq "$(fake_in_gp2x)" "1"
diff --git a/linux/plat.c b/linux/plat.c
new file mode 100644 (file)
index 0000000..102af6e
--- /dev/null
@@ -0,0 +1,14 @@
+#include <dirent.h>
+#include "../common/plat.h"
+
+
+int plat_is_dir(const char *path)
+{
+       DIR *dir;
+       if ((dir = opendir(path))) {
+               closedir(dir);
+               return 1;
+       }
+       return 0;
+}
+
index 8bc76be..2d06d98 100644 (file)
 #endif\r
 \r
 \r
-int engineState;\r
 int select_exits = 0;\r
 \r
-char romFileName[PATH_MAX];\r
-\r
 static short __attribute__((aligned(4))) sndBuffer[2*44100/50];\r
 static struct timeval noticeMsgTime = { 0, 0 };        // when started showing\r
 static int osd_fps_x;\r
index 4690f06..51f7f8e 100644 (file)
@@ -50,9 +50,9 @@ void parse_cmd_line(int argc, char *argv[])
                } else {\r
                        /* External Frontend: ROM Name */\r
                        FILE *f;\r
-                       strncpy(romFileName, argv[x], PATH_MAX);\r
-                       romFileName[PATH_MAX-1] = 0;\r
-                       f = fopen(romFileName, "rb");\r
+                       strncpy(rom_fname_reload, argv[x], PATH_MAX);\r
+                       rom_fname_reload[PATH_MAX-1] = 0;\r
+                       f = fopen(rom_fname_reload, "rb");\r
                        if (f) fclose(f);\r
                        else unrecognized = 1;\r
                        engineState = PGS_ReloadRom;\r
@@ -96,7 +96,7 @@ int main(int argc, char *argv[])
 \r
        if (engineState == PGS_ReloadRom)\r
        {\r
-               if (emu_ReloadRom(romFileName)) {\r
+               if (emu_ReloadRom(rom_fname_reload)) {\r
                        engineState = PGS_Running;\r
                        if (load_state_slot >= 0) {\r
                                state_slot = load_state_slot;\r
@@ -114,7 +114,7 @@ int main(int argc, char *argv[])
                                break;\r
 \r
                        case PGS_ReloadRom:\r
-                               if (emu_ReloadRom(romFileName))\r
+                               if (emu_ReloadRom(rom_fname_reload))\r
                                        engineState = PGS_Running;\r
                                else {\r
                                        printf("PGS_ReloadRom == 0\n");\r
index a9acac7..bbf07e5 100644 (file)
--- a/psp/emu.c
+++ b/psp/emu.c
@@ -33,9 +33,8 @@ int sceAudio_E0727056(int volume, void *buffer);      // blocking output
 int sceAudioOutput2GetRestSample();
 
 
-char romFileName[PATH_MAX];
 unsigned char *PicoDraw2FB = (unsigned char *)VRAM_CACHED_STUFF + 8; // +8 to be able to skip border with 1 quadword..
-int engineState = PGS_Menu, engineStateSuspend;
+int engineStateSuspend;
 
 static unsigned int noticeMsgTime = 0;
 int reset_timing = 0; // do we need this?
@@ -1127,13 +1126,13 @@ void emu_HandleResume(void)
        // reopen first CD track
        if (Pico_mcd->TOC.Tracks[0].F != NULL)
        {
-               char *fname = romFileName;
-               int len = strlen(romFileName);
+               char *fname = rom_fname_reload;
+               int len = strlen(rom_fname_reload);
                cue_data_t *cue_data = NULL;
 
                if (len > 4 && strcasecmp(fname + len - 4,  ".cue") == 0)
                {
-                       cue_data = cue_parse(romFileName);
+                       cue_data = cue_parse(rom_fname_reload);
                        if (cue_data != NULL)
                                fname = cue_data->tracks[1].fname;
                }
index fc0a36f..dc53ac1 100644 (file)
--- a/psp/emu.h
+++ b/psp/emu.h
@@ -4,10 +4,7 @@
 // For commercial use, separate licencing terms must be obtained.
 
 
-
-extern char romFileName[];
-extern int engineState, engineStateSuspend;
-
+extern int engineStateSuspend;
 
 void emu_Init(void);
 void emu_Deinit(void);
index e0698d5..e96eacc 100644 (file)
@@ -23,7 +23,7 @@
 
 void dummy(void)
 {
-       engineState = atoi(romFileName);
+       engineState = atoi(rom_fname_reload);
        setbuf(NULL, NULL);
        getenv(NULL);
 }
@@ -52,13 +52,13 @@ int pico_main(void)
 #ifndef GPROF
                                menu_loop();
 #else
-                               strcpy(romFileName, loadedRomFName);
+                               strcpy(rom_fname_reload, rom_fname_loaded);
                                engineState = PGS_ReloadRom;
 #endif
                                break;
 
                        case PGS_ReloadRom:
-                               if (emu_ReloadRom(romFileName)) {
+                               if (emu_ReloadRom(rom_fname_reload)) {
                                        engineState = PGS_Running;
                                        if (mp3_last_error != 0)
                                                engineState = PGS_Menu; // send to menu to display mp3 error