new menu option code
authornotaz <notasas@gmail.com>
Sun, 19 Aug 2007 17:06:56 +0000 (17:06 +0000)
committernotaz <notasas@gmail.com>
Sun, 19 Aug 2007 17:06:56 +0000 (17:06 +0000)
git-svn-id: file:///home/notaz/opt/svn/PicoDrive/platform@221 be3aeb3a-fb24-0410-a615-afba39da0efa

gp2x/emu.c
gp2x/menu.c
linux/Makefile
linux/gp2x.c

index 0e1246c..27e9d13 100644 (file)
@@ -62,6 +62,7 @@ static int movie_size = 0;
 unsigned char *framebuff = 0;  // temporary buffer for alt renderer\r
 int state_slot = 0;\r
 int reset_timing = 0;\r
+int config_slot = 0, config_slot_current = 0;\r
 \r
 \r
 // utilities\r
@@ -474,7 +475,7 @@ void scaling_update(void)
 int emu_ReadConfig(int game)\r
 {\r
        FILE *f;\r
-       char cfg[512];\r
+       char cfg[512], extbuf[16];\r
        int bread = 0;\r
 \r
        if (!game)\r
@@ -507,9 +508,19 @@ int emu_ReadConfig(int game)
                currentConfig.PicoCDBuffers = 64;\r
                currentConfig.scaling = 0;\r
                strncpy(cfg, PicoConfigFile, 511);\r
+               if (config_slot != 0)\r
+               {\r
+                       char *p = strrchr(cfg, '.');\r
+                       if (p == NULL) p = cfg + strlen(cfg);\r
+                       sprintf(extbuf, ".%i.pbcfg", config_slot);\r
+                       strncpy(p, extbuf, 511 - (p - cfg));\r
+               }\r
                cfg[511] = 0;\r
        } else {\r
-               romfname_ext(cfg, "cfg/", ".pbcfg");\r
+               if (config_slot != 0)\r
+                    sprintf(extbuf, ".%i.pbcfg", config_slot);\r
+               else strcpy(extbuf, ".pbcfg");\r
+               romfname_ext(cfg, "cfg/", extbuf);\r
                f = fopen(cfg, "rb");\r
                if (!f) romfname_ext(cfg, NULL, ".pbcfg");\r
                else fclose(f);\r
@@ -543,6 +554,7 @@ int emu_ReadConfig(int game)
                currentConfig.KeyBinds[22] = 1<<30; // vol down\r
        }\r
 \r
+       if (bread > 0) config_slot_current = config_slot;\r
        return (bread > 0); // == sizeof(currentConfig));\r
 }\r
 \r
@@ -550,15 +562,25 @@ int emu_ReadConfig(int game)
 int emu_WriteConfig(int game)\r
 {\r
        FILE *f;\r
-       char cfg[512];\r
+       char cfg[512], extbuf[16];\r
        int bwrite = 0;\r
 \r
        if (!game)\r
        {\r
                strncpy(cfg, PicoConfigFile, 511);\r
+               if (config_slot != 0)\r
+               {\r
+                       char *p = strrchr(cfg, '.');\r
+                       if (p == NULL) p = cfg + strlen(cfg);\r
+                       sprintf(extbuf, ".%i.pbcfg", config_slot);\r
+                       strncpy(p, extbuf, 511 - (p - cfg));\r
+               }\r
                cfg[511] = 0;\r
        } else {\r
-               romfname_ext(cfg, "cfg/", ".pbcfg");\r
+               if (config_slot != 0)\r
+                    sprintf(extbuf, ".%i.pbcfg", config_slot);\r
+               else strcpy(extbuf, ".pbcfg");\r
+               romfname_ext(cfg, "cfg/", extbuf);\r
        }\r
 \r
        printf("emu_WriteConfig: %s ", cfg);\r
@@ -578,6 +600,7 @@ int emu_WriteConfig(int game)
        }\r
        printf((bwrite == sizeof(currentConfig)) ? "(ok)\n" : "(failed)\n");\r
 \r
+       if (bwrite == sizeof(currentConfig)) config_slot_current = config_slot;\r
        return (bwrite == sizeof(currentConfig));\r
 }\r
 \r
index 0b8264e..8de891b 100644 (file)
@@ -31,6 +31,7 @@ extern char romFileName[PATH_MAX];
 extern char *rom_data;\r
 extern int  mmuhack_status;\r
 extern int  state_slot;\r
+extern int  config_slot, config_slot_current;\r
 \r
 static char *gp2xKeyNames[] = {\r
        "UP",    "???",    "LEFT", "???",  "DOWN", "???", "RIGHT",    "???",\r
@@ -165,6 +166,175 @@ static void gp2x_smalltext8_lim(int x, int y, const char *texto, int max)
 }\r
 \r
 \r
+typedef enum\r
+{\r
+       MB_NONE = 1,            /* no auto processing */\r
+       MB_ONOFF,               /* ON/OFF setting */\r
+       MB_RANGE,               /* [min-max] setting */\r
+} menu_behavior;\r
+\r
+typedef enum\r
+{\r
+       MA_NONE = 1,\r
+       MA_MAIN_RESUME_GAME,\r
+       MA_MAIN_SAVE_STATE,\r
+       MA_MAIN_LOAD_STATE,\r
+       MA_MAIN_RESET_GAME,\r
+       MA_MAIN_LOAD_ROM,\r
+       MA_MAIN_OPTIONS,\r
+       MA_MAIN_CONTROLS,\r
+       MA_MAIN_CREDITS,\r
+       MA_MAIN_PATCHES,\r
+       MA_MAIN_EXIT,\r
+       MA_OPT_RENDERER,\r
+       MA_OPT_SCALING,\r
+       MA_OPT_ACC_TIMING,\r
+       MA_OPT_ACC_SPRITES,\r
+       MA_OPT_SHOW_FPS,\r
+       MA_OPT_FRAMESKIP,\r
+       MA_OPT_ENABLE_SOUND,\r
+       MA_OPT_SOUND_QUALITY,\r
+       MA_OPT_ARM940_SOUND,\r
+       MA_OPT_6BUTTON_PAD,\r
+       MA_OPT_REGION,\r
+       MA_OPT_SRAM_STATES,\r
+       MA_OPT_CONFIRM_STATES,\r
+       MA_OPT_SAVE_SLOT,\r
+       MA_OPT_CPU_CLOCKS,\r
+       MA_OPT_SCD_OPTS,\r
+       MA_OPT_ADV_OPTS,\r
+       MA_OPT_SAVECFG,\r
+       MA_OPT_SAVECFG_GAME,\r
+       MA_OPT_LOADCFG,\r
+       MA_OPT2_GAMMA,\r
+       MA_OPT2_A_SN_GAMMA,\r
+       MA_OPT2_VSYNC,\r
+       MA_OPT2_ENABLE_Z80,\r
+       MA_OPT2_ENABLE_YM2612,\r
+       MA_OPT2_ENABLE_SN76496,\r
+       MA_OPT2_GZIP_STATES,\r
+       MA_OPT2_NO_LAST_ROM,\r
+       MA_OPT2_RAMTIMINGS,\r
+       MA_OPT2_SQUIDGEHACK,\r
+       MA_OPT2_DONE,\r
+       MA_CDOPT_TESTBIOS_USA,\r
+       MA_CDOPT_TESTBIOS_EUR,\r
+       MA_CDOPT_TESTBIOS_JAP,\r
+       MA_CDOPT_LEDS,\r
+       MA_CDOPT_CDDA,\r
+       MA_CDOPT_PCM,\r
+       MA_CDOPT_READAHEAD,\r
+       MA_CDOPT_SAVERAM,\r
+       MA_CDOPT_SCALEROT_CHIP,\r
+       MA_CDOPT_BETTER_SYNC,\r
+       MA_CDOPT_DONE,\r
+} menu_id;\r
+\r
+typedef struct\r
+{\r
+       char *name;\r
+       menu_behavior beh;\r
+       menu_id id;\r
+       void *var;              /* for on-off settings */\r
+       int mask;\r
+       signed char min;        /* for ranged integer settings, to be sign-extended */\r
+       signed char max;\r
+       char enabled;\r
+} menu_entry;\r
+\r
+static int me_id2offset(const menu_entry *entries, int count, menu_id id)\r
+{\r
+       int i;\r
+       for (i = 0; i < count; i++)\r
+       {\r
+               if (entries[i].id == id) return i;\r
+       }\r
+\r
+       printf("%s: id %i not found\n", __FUNCTION__, id);\r
+       return 0;\r
+}\r
+\r
+static void me_enable(menu_entry *entries, int count, menu_id id, int enable)\r
+{\r
+       int i = me_id2offset(entries, count, id);\r
+       entries[i].enabled = enable;\r
+}\r
+\r
+static int me_count_enabled(const menu_entry *entries, int count)\r
+{\r
+       int i, ret = 0;\r
+\r
+       for (i = 0; i < count; i++)\r
+       {\r
+               if (entries[i].enabled) ret++;\r
+       }\r
+\r
+       return ret;\r
+}\r
+\r
+static menu_id me_index2id(const menu_entry *entries, int count, int index)\r
+{\r
+       int i;\r
+\r
+       for (i = 0; i < count; i++)\r
+       {\r
+               if (entries[i].enabled)\r
+               {\r
+                       if (index == 0) break;\r
+                       index--;\r
+               }\r
+       }\r
+       if (i >= count) i = count - 1;\r
+       return entries[i].id;\r
+}\r
+\r
+typedef void (me_draw_custom_f)(const menu_entry *entry, int x, int y, void *param);\r
+\r
+static 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
+               gp2x_text_out8(x, y1, entries[i].name);\r
+               if (entries[i].beh == MB_ONOFF)\r
+                       gp2x_text_out8(x + 27*8, y1, (*(int *)entries[i].var & entries[i].mask) ? "ON" : "OFF");\r
+               else if (entries[i].beh == MB_RANGE)\r
+                       gp2x_text_out8(x + 27*8, y1, "%i", *(int *)entries[i].var);\r
+               y1 += 10;\r
+       }\r
+}\r
+\r
+static int me_process(menu_entry *entries, int count, menu_id id, int is_next)\r
+{\r
+       int i = me_id2offset(entries, count, id);\r
+       menu_entry *entry = &entries[i];\r
+       switch (entry->beh)\r
+       {\r
+               case MB_ONOFF:\r
+                       *(int *)entry->var ^= entry->mask;\r
+                       return 1;\r
+               case MB_RANGE:\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
+                       return 1;\r
+               default:\r
+                       return 0;\r
+       }\r
+}\r
+\r
+\r
+\r
+\r
 static unsigned long inp_prev = 0;\r
 static int inp_prevjoy = 0;\r
 \r
@@ -784,36 +954,68 @@ static void kc_sel_loop(void)
 \r
 // --------- sega/mega cd options ----------\r
 \r
-static void draw_cd_menu_options(int menu_sel, char *b_us, char *b_eu, char *b_jp)\r
+menu_entry cdopt_entries[] =\r
 {\r
-       int tl_x = 25, tl_y = 60, y;\r
+       { NULL,                        MB_NONE,  MA_CDOPT_TESTBIOS_USA, NULL, 0, 0, 0, 1 },\r
+       { NULL,                        MB_NONE,  MA_CDOPT_TESTBIOS_EUR, NULL, 0, 0, 0, 1 },\r
+       { NULL,                        MB_NONE,  MA_CDOPT_TESTBIOS_JAP, NULL, 0, 0, 0, 1 },\r
+       { "CD LEDs",                   MB_ONOFF, MA_CDOPT_LEDS,         &currentConfig.EmuOpt,  0x0400, 0, 0, 1 },\r
+       { "CDDA audio (using mp3s)",   MB_ONOFF, MA_CDOPT_CDDA,         &currentConfig.PicoOpt, 0x0800, 0, 0, 1 },\r
+       { "PCM audio",                 MB_ONOFF, MA_CDOPT_PCM,          &currentConfig.PicoOpt, 0x0400, 0, 0, 1 },\r
+       { NULL,                        MB_NONE,  MA_CDOPT_READAHEAD,    NULL, 0, 0, 0, 1 },\r
+       { "SaveRAM cart",              MB_ONOFF, MA_CDOPT_SAVERAM,      &currentConfig.PicoOpt, 0x8000, 0, 0, 1 },\r
+       { "Scale/Rot. fx (slow)",      MB_ONOFF, MA_CDOPT_SCALEROT_CHIP,&currentConfig.PicoOpt, 0x1000, 0, 0, 1 },\r
+       { "Better sync (slow)",        MB_ONOFF, MA_CDOPT_BETTER_SYNC,  &currentConfig.PicoOpt, 0x2000, 0, 0, 1 },\r
+       { "done",                      MB_NONE,  MA_CDOPT_DONE,         NULL, 0, 0, 0, 1 },\r
+};\r
+\r
+#define CDOPT_ENTRY_COUNT (sizeof(cdopt_entries) / sizeof(cdopt_entries[0]))\r
+\r
+\r
+struct bios_names_t\r
+{\r
+       char us[32], eu[32], jp[32];\r
+};\r
+\r
+static void menu_cdopt_cust_draw(const menu_entry *entry, int x, int y, void *param)\r
+{\r
+       struct bios_names_t *bios_names = param;\r
+       char ra_buff[16];\r
+\r
+       switch (entry->id)\r
+       {\r
+               case MA_CDOPT_TESTBIOS_USA: gp2x_text_out8(x, y, "USA BIOS:     %s", bios_names->us); break;\r
+               case MA_CDOPT_TESTBIOS_EUR: gp2x_text_out8(x, y, "EUR BIOS:     %s", bios_names->eu); break;\r
+               case MA_CDOPT_TESTBIOS_JAP: gp2x_text_out8(x, y, "JAP BIOS:     %s", bios_names->jp); break;\r
+               case MA_CDOPT_READAHEAD:\r
+                       if (PicoCDBuffers > 1) sprintf(ra_buff, "%5iK", PicoCDBuffers * 2);\r
+                       else strcpy(ra_buff, "     OFF");\r
+                       gp2x_text_out8(x, y, "ReadAhead buffer      %s", ra_buff);\r
+                       break;\r
+               default:break;\r
+       }\r
+}\r
+\r
+static void draw_cd_menu_options(int menu_sel, struct bios_names_t *bios_names)\r
+{\r
+       int tl_x = 25, tl_y = 60;\r
+       menu_id selected_id;\r
        char ra_buff[16];\r
 \r
        if (PicoCDBuffers > 1) sprintf(ra_buff, "%5iK", PicoCDBuffers * 2);\r
        else strcpy(ra_buff, "     OFF");\r
 \r
-       y = tl_y;\r
-       //memset(gp2x_screen, 0, 320*240);\r
        gp2x_pd_clone_buffer2();\r
 \r
-       gp2x_text_out8(tl_x, y,       "USA BIOS:     %s", b_us); // 0\r
-       gp2x_text_out8(tl_x, (y+=10), "EUR BIOS:     %s", b_eu); // 1\r
-       gp2x_text_out8(tl_x, (y+=10), "JAP BIOS:     %s", b_jp); // 2\r
-       gp2x_text_out8(tl_x, (y+=10), "CD LEDs                    %s", (currentConfig.EmuOpt &0x0400)?"ON":"OFF"); // 3\r
-       gp2x_text_out8(tl_x, (y+=10), "CDDA audio (using mp3s)    %s", (currentConfig.PicoOpt&0x0800)?"ON":"OFF"); // 4\r
-       gp2x_text_out8(tl_x, (y+=10), "PCM audio                  %s", (currentConfig.PicoOpt&0x0400)?"ON":"OFF"); // 5\r
-       gp2x_text_out8(tl_x, (y+=10), "ReadAhead buffer      %s", ra_buff); // 6\r
-       gp2x_text_out8(tl_x, (y+=10), "SaveRAM cart               %s", (currentConfig.PicoOpt&0x8000)?"ON":"OFF"); // 7\r
-       gp2x_text_out8(tl_x, (y+=10), "Scale/Rot. fx (slow)       %s", (currentConfig.PicoOpt&0x1000)?"ON":"OFF"); // 8\r
-       gp2x_text_out8(tl_x, (y+=10), "Better sync (slow)         %s", (currentConfig.PicoOpt&0x2000)?"ON":"OFF"); // 9\r
-       gp2x_text_out8(tl_x, (y+=10), "Done");\r
+       me_draw(cdopt_entries, CDOPT_ENTRY_COUNT, tl_x, tl_y, menu_cdopt_cust_draw, bios_names);\r
 \r
        // draw cursor\r
        gp2x_text_out8(tl_x - 16, tl_y + menu_sel*10, ">");\r
 \r
-       if ((menu_sel == 0 && strcmp(b_us, "NOT FOUND")) ||\r
-               (menu_sel == 1 && strcmp(b_eu, "NOT FOUND")) ||\r
-               (menu_sel == 2 && strcmp(b_jp, "NOT FOUND")))\r
+       selected_id = me_index2id(cdopt_entries, CDOPT_ENTRY_COUNT, menu_sel);\r
+       if ((selected_id == MA_CDOPT_TESTBIOS_USA && strcmp(bios_names->us, "NOT FOUND")) ||\r
+               (selected_id == MA_CDOPT_TESTBIOS_EUR && strcmp(bios_names->eu, "NOT FOUND")) ||\r
+               (selected_id == MA_CDOPT_TESTBIOS_JAP && strcmp(bios_names->jp, "NOT FOUND")))\r
                        gp2x_text_out8(tl_x, 220, "Press start to test selected BIOS");\r
 \r
        gp2x_video_flip2();\r
@@ -824,100 +1026,120 @@ static void cd_menu_loop_options(void)
        static int menu_sel = 0;\r
        int menu_sel_max = 10;\r
        unsigned long inp = 0;\r
-       char bios_us[32], bios_eu[32], bios_jp[32], *bios, *p;\r
+       struct bios_names_t bios_names;\r
+       menu_id selected_id;\r
+       char *bios, *p;\r
 \r
        if (find_bios(4, &bios)) { // US\r
                for (p = bios+strlen(bios)-1; p > bios && *p != '/'; p--); p++;\r
-               strncpy(bios_us, p, 31); bios_us[31] = 0;\r
-       } else  strcpy(bios_us, "NOT FOUND");\r
+               strncpy(bios_names.us, p, sizeof(bios_names.us)); bios_names.us[sizeof(bios_names.us)-1] = 0;\r
+       } else  strcpy(bios_names.us, "NOT FOUND");\r
 \r
        if (find_bios(8, &bios)) { // EU\r
                for (p = bios+strlen(bios)-1; p > bios && *p != '/'; p--); p++;\r
-               strncpy(bios_eu, p, 31); bios_eu[31] = 0;\r
-       } else  strcpy(bios_eu, "NOT FOUND");\r
+               strncpy(bios_names.eu, p, sizeof(bios_names.eu)); bios_names.eu[sizeof(bios_names.eu)-1] = 0;\r
+       } else  strcpy(bios_names.eu, "NOT FOUND");\r
 \r
        if (find_bios(1, &bios)) { // JP\r
                for (p = bios+strlen(bios)-1; p > bios && *p != '/'; p--); p++;\r
-               strncpy(bios_jp, p, 31); bios_jp[31] = 0;\r
-       } else  strcpy(bios_jp, "NOT FOUND");\r
+               strncpy(bios_names.jp, p, sizeof(bios_names.jp)); bios_names.jp[sizeof(bios_names.jp)-1] = 0;\r
+       } else  strcpy(bios_names.jp, "NOT FOUND");\r
 \r
        for(;;)\r
        {\r
-               draw_cd_menu_options(menu_sel, bios_us, bios_eu, bios_jp);\r
+               draw_cd_menu_options(menu_sel, &bios_names);\r
                inp = wait_for_input(GP2X_UP|GP2X_DOWN|GP2X_LEFT|GP2X_RIGHT|GP2X_B|GP2X_X|GP2X_A|GP2X_START);\r
-               if(inp & GP2X_UP  ) { menu_sel--; if (menu_sel < 0) menu_sel = menu_sel_max; }\r
-               if(inp & GP2X_DOWN) { menu_sel++; if (menu_sel > menu_sel_max) menu_sel = 0; }\r
-               if((inp& GP2X_B)||(inp&GP2X_LEFT)||(inp&GP2X_RIGHT)) { // toggleable options\r
-                       switch (menu_sel) {\r
-                               case  3: currentConfig.EmuOpt ^=0x0400; break;\r
-                               case  4: currentConfig.PicoOpt^=0x0800; break;\r
-                               case  5: currentConfig.PicoOpt^=0x0400; break;\r
-                               case  6:\r
-                                       if (inp & GP2X_LEFT) {\r
-                                               PicoCDBuffers >>= 1;\r
-                                               if (PicoCDBuffers < 64) PicoCDBuffers = 0;\r
-                                       } else {\r
-                                               if (PicoCDBuffers < 64) PicoCDBuffers = 64;\r
-                                               else PicoCDBuffers <<= 1;\r
-                                               if (PicoCDBuffers > 8*1024) PicoCDBuffers = 8*1024; // 16M\r
-                                       }\r
-                                       break;\r
-                               case  7: currentConfig.PicoOpt^=0x8000; break;\r
-                               case  8: currentConfig.PicoOpt^=0x1000; break;\r
-                               case  9: currentConfig.PicoOpt^=0x2000; break;\r
-                               case 10: return;\r
+               if (inp & GP2X_UP  ) { menu_sel--; if (menu_sel < 0) menu_sel = menu_sel_max; }\r
+               if (inp & GP2X_DOWN) { menu_sel++; if (menu_sel > menu_sel_max) menu_sel = 0; }\r
+               selected_id = me_index2id(cdopt_entries, CDOPT_ENTRY_COUNT, menu_sel);\r
+               if (inp & (GP2X_LEFT|GP2X_RIGHT)) { // multi choise\r
+                       if (!me_process(cdopt_entries, CDOPT_ENTRY_COUNT, selected_id, (inp&GP2X_RIGHT) ? 1 : 0) &&\r
+                           selected_id == MA_CDOPT_READAHEAD) {\r
+                               if (inp & GP2X_LEFT) {\r
+                                       PicoCDBuffers >>= 1;\r
+                                       if (PicoCDBuffers < 64) PicoCDBuffers = 0;\r
+                               } else {\r
+                                       if (PicoCDBuffers < 64) PicoCDBuffers = 64;\r
+                                       else PicoCDBuffers <<= 1;\r
+                                       if (PicoCDBuffers > 8*1024) PicoCDBuffers = 8*1024; // 16M\r
+                               }\r
                        }\r
                }\r
-               if(inp & (GP2X_X|GP2X_A)) return;\r
-               if(inp &  GP2X_START) { // BIOS testers\r
-                       switch (menu_sel) {\r
-                               case 0: if (find_bios(4, &bios)) { // test US\r
+               if (inp & GP2X_B) { // toggleable options\r
+                       if (!me_process(cdopt_entries, CDOPT_ENTRY_COUNT, selected_id, 1) &&\r
+                           selected_id == MA_CDOPT_DONE) {\r
+                               return;\r
+                       }\r
+               }\r
+               if (inp & GP2X_START) { // BIOS testers\r
+                       switch (selected_id) {\r
+                               case MA_CDOPT_TESTBIOS_USA:\r
+                                       if (find_bios(4, &bios)) { // test US\r
                                                strcpy(romFileName, bios);\r
                                                engineState = PGS_ReloadRom;\r
                                                return;\r
                                        }\r
                                        break;\r
-                               case 1: if (find_bios(8, &bios)) { // test EU\r
+                               case MA_CDOPT_TESTBIOS_EUR:\r
+                                       if (find_bios(8, &bios)) { // test EU\r
                                                strcpy(romFileName, bios);\r
                                                engineState = PGS_ReloadRom;\r
                                                return;\r
                                        }\r
                                        break;\r
-                               case 2: if (find_bios(1, &bios)) { // test JP\r
+                               case MA_CDOPT_TESTBIOS_JAP:\r
+                                       if (find_bios(1, &bios)) { // test JP\r
                                                strcpy(romFileName, bios);\r
                                                engineState = PGS_ReloadRom;\r
                                                return;\r
                                        }\r
                                        break;\r
+                               default:\r
+                                       break;\r
                        }\r
                }\r
+               if (inp & (GP2X_X|GP2X_A)) return;\r
        }\r
 }\r
 \r
 \r
 // --------- advanced options ----------\r
 \r
+menu_entry opt2_entries[] =\r
+{\r
+       { NULL,                        MB_NONE,  MA_OPT2_GAMMA,         NULL, 0, 0, 0, 1 },\r
+       { "A_SN's gamma curve",        MB_ONOFF, MA_OPT2_A_SN_GAMMA,    &currentConfig.EmuOpt, 0x1000, 0, 0, 1 },\r
+       { "Perfecf vsync",             MB_ONOFF, MA_OPT2_VSYNC,         &currentConfig.EmuOpt, 0x2000, 0, 0, 1 },\r
+       { "Emulate Z80",               MB_ONOFF, MA_OPT2_ENABLE_Z80,    &currentConfig.PicoOpt,0x0004, 0, 0, 1 },\r
+       { "Emulate YM2612 (FM)",       MB_ONOFF, MA_OPT2_ENABLE_YM2612, &currentConfig.PicoOpt,0x0001, 0, 0, 1 },\r
+       { "Emulate SN76496 (PSG)",     MB_ONOFF, MA_OPT2_ENABLE_SN76496,&currentConfig.PicoOpt,0x0002, 0, 0, 1 },\r
+       { "gzip savestates",           MB_ONOFF, MA_OPT2_GZIP_STATES,   &currentConfig.EmuOpt, 0x0008, 0, 0, 1 },\r
+       { "Don't save last used ROM",  MB_ONOFF, MA_OPT2_NO_LAST_ROM,   &currentConfig.EmuOpt, 0x0020, 0, 0, 1 },\r
+       { "needs restart:",            MB_NONE,  MA_NONE,               NULL, 0, 0, 0, 1 },\r
+       { "craigix's RAM timings",     MB_ONOFF, MA_OPT2_RAMTIMINGS,    &currentConfig.EmuOpt, 0x0100, 0, 0, 1 },\r
+       { NULL,                        MB_ONOFF, MA_OPT2_SQUIDGEHACK,   &currentConfig.EmuOpt, 0x0010, 0, 0, 1 },\r
+       { "done",                      MB_NONE,  MA_OPT2_DONE,          NULL, 0, 0, 0, 1 },\r
+};\r
+\r
+#define OPT2_ENTRY_COUNT (sizeof(opt2_entries) / sizeof(opt2_entries[0]))\r
+\r
+static void menu_opt2_cust_draw(const menu_entry *entry, int x, int y, void *param)\r
+{\r
+       if (entry->id == MA_OPT2_GAMMA)\r
+               gp2x_text_out8(x, y, "Gamma correction           %i.%02i", currentConfig.gamma / 100, currentConfig.gamma%100);\r
+       else if (entry->id == MA_OPT2_SQUIDGEHACK)\r
+               gp2x_text_out8(x, y, "squidgehack (now %s %s", mmuhack_status ? "active)  " : "inactive)",\r
+                       (currentConfig.EmuOpt&0x0010)?"ON":"OFF");\r
+}\r
+\r
+\r
 static void draw_amenu_options(int menu_sel)\r
 {\r
-       int tl_x = 25, tl_y = 50, y;\r
-       char *mms = mmuhack_status ? "active)  " : "inactive)";\r
+       int tl_x = 25, tl_y = 50;\r
 \r
-       y = tl_y;\r
-       //memset(gp2x_screen, 0, 320*240);\r
        gp2x_pd_clone_buffer2();\r
 \r
-       gp2x_text_out8(tl_x, y,       "Gamma correction           %i.%02i", currentConfig.gamma / 100, currentConfig.gamma%100); // 0\r
-       gp2x_text_out8(tl_x, (y+=10), "A_SN's gamma curve         %s", (currentConfig.EmuOpt &0x1000)?"ON":"OFF");\r
-       gp2x_text_out8(tl_x, (y+=10), "Perfecf vsync              %s", (currentConfig.EmuOpt &0x2000)?"ON":"OFF");\r
-       gp2x_text_out8(tl_x, (y+=10), "Emulate Z80                %s", (currentConfig.PicoOpt&0x0004)?"ON":"OFF");\r
-       gp2x_text_out8(tl_x, (y+=10), "Emulate YM2612 (FM)        %s", (currentConfig.PicoOpt&0x0001)?"ON":"OFF");\r
-       gp2x_text_out8(tl_x, (y+=10), "Emulate SN76496 (PSG)      %s", (currentConfig.PicoOpt&0x0002)?"ON":"OFF"); // 5\r
-       gp2x_text_out8(tl_x, (y+=10), "gzip savestates            %s", (currentConfig.EmuOpt &0x0008)?"ON":"OFF");\r
-       gp2x_text_out8(tl_x, (y+=10), "Don't save last used ROM   %s", (currentConfig.EmuOpt &0x0020)?"ON":"OFF");\r
-       gp2x_text_out8(tl_x, (y+=10), "needs restart:");\r
-       gp2x_text_out8(tl_x, (y+=10), "craigix's RAM timings      %s", (currentConfig.EmuOpt &0x0100)?"ON":"OFF");\r
-       gp2x_text_out8(tl_x, (y+=10), "squidgehack (now %s %s",   mms, (currentConfig.EmuOpt &0x0010)?"ON":"OFF"); // 10\r
-       gp2x_text_out8(tl_x, (y+=10), "Done");\r
+       me_draw(opt2_entries, OPT2_ENTRY_COUNT, tl_x, tl_y, menu_opt2_cust_draw, NULL);\r
 \r
        // draw cursor\r
        gp2x_text_out8(tl_x - 16, tl_y + menu_sel*10, ">");\r
@@ -928,48 +1150,71 @@ static void draw_amenu_options(int menu_sel)
 static void amenu_loop_options(void)\r
 {\r
        static int menu_sel = 0;\r
-       int menu_sel_max = 11;\r
+       int menu_sel_max;\r
        unsigned long inp = 0;\r
+       menu_id selected_id;\r
+\r
+       menu_sel_max = me_count_enabled(opt2_entries, OPT2_ENTRY_COUNT) - 1;\r
 \r
        for(;;)\r
        {\r
                draw_amenu_options(menu_sel);\r
                inp = wait_for_input(GP2X_UP|GP2X_DOWN|GP2X_LEFT|GP2X_RIGHT|GP2X_B|GP2X_X|GP2X_A);\r
-               if(inp & GP2X_UP  ) { menu_sel--; if (menu_sel < 0) menu_sel = menu_sel_max; }\r
-               if(inp & GP2X_DOWN) { menu_sel++; if (menu_sel > menu_sel_max) menu_sel = 0; }\r
-               if((inp& GP2X_B)||(inp&GP2X_LEFT)||(inp&GP2X_RIGHT)) { // toggleable options\r
-                       switch (menu_sel) {\r
-                               case  1: currentConfig.EmuOpt ^=0x1000; break;\r
-                               case  2: currentConfig.EmuOpt ^=0x2000; break;\r
-                               case  3: currentConfig.PicoOpt^=0x0004; break;\r
-                               case  4: currentConfig.PicoOpt^=0x0001; break;\r
-                               case  5: currentConfig.PicoOpt^=0x0002; break;\r
-                               case  6: currentConfig.EmuOpt ^=0x0008; break;\r
-                               case  7: currentConfig.EmuOpt ^=0x0020; break;\r
-                               case  9: currentConfig.EmuOpt ^=0x0100; break;\r
-                               case 10: currentConfig.EmuOpt ^=0x0010; break;\r
-                               case 11: return;\r
+               if (inp & GP2X_UP  ) { menu_sel--; if (menu_sel < 0) menu_sel = menu_sel_max; }\r
+               if (inp & GP2X_DOWN) { menu_sel++; if (menu_sel > menu_sel_max) menu_sel = 0; }\r
+               selected_id = me_index2id(opt2_entries, OPT2_ENTRY_COUNT, menu_sel);\r
+               if (inp & (GP2X_LEFT|GP2X_RIGHT)) { // multi choise\r
+                       if (!me_process(opt2_entries, OPT2_ENTRY_COUNT, selected_id, (inp&GP2X_RIGHT) ? 1 : 0) &&\r
+                           selected_id == MA_OPT2_GAMMA) {\r
+                               while ((inp = gp2x_joystick_read(1)) & (GP2X_LEFT|GP2X_RIGHT)) {\r
+                                       currentConfig.gamma += (inp & GP2X_LEFT) ? -1 : 1;\r
+                                       if (currentConfig.gamma <   1) currentConfig.gamma =   1;\r
+                                       if (currentConfig.gamma > 300) currentConfig.gamma = 300;\r
+                                       draw_amenu_options(menu_sel);\r
+                                       usleep(18*1000);\r
+                               }\r
                        }\r
                }\r
-               if(inp & (GP2X_X|GP2X_A)) return;\r
-               if(inp & (GP2X_LEFT|GP2X_RIGHT)) { // multi choise\r
-                       switch (menu_sel) {\r
-                               case 0:\r
-                                       while ((inp = gp2x_joystick_read(1)) & (GP2X_LEFT|GP2X_RIGHT)) {\r
-                                               currentConfig.gamma += (inp & GP2X_LEFT) ? -1 : 1;\r
-                                               if (currentConfig.gamma <   1) currentConfig.gamma =   1;\r
-                                               if (currentConfig.gamma > 300) currentConfig.gamma = 300;\r
-                                               draw_amenu_options(menu_sel);\r
-                                               usleep(18*1000);\r
-                                       }\r
-                                       break;\r
+               if (inp & GP2X_B) { // toggleable options\r
+                       if (!me_process(opt2_entries, OPT2_ENTRY_COUNT, selected_id, 1) &&\r
+                           selected_id == MA_OPT2_DONE) {\r
+                               return;\r
                        }\r
                }\r
+               if (inp & (GP2X_X|GP2X_A)) return;\r
        }\r
 }\r
 \r
 // -------------- options --------------\r
 \r
+\r
+menu_entry opt_entries[] =\r
+{\r
+       { NULL,                        MB_NONE,  MA_OPT_RENDERER,      NULL, 0, 0, 0, 1 },\r
+       { NULL,                        MB_RANGE, MA_OPT_SCALING,       &currentConfig.scaling, 0, 0, 3, 1 },\r
+       { "Accurate timing (slower)",  MB_ONOFF, MA_OPT_ACC_TIMING,    &currentConfig.PicoOpt, 0x040, 0, 0, 1 },\r
+       { "Accurate sprites (slower)", MB_ONOFF, MA_OPT_ACC_SPRITES,   &currentConfig.PicoOpt, 0x080, 0, 0, 1 },\r
+       { "Show FPS",                  MB_ONOFF, MA_OPT_SHOW_FPS,      &currentConfig.EmuOpt,  0x002, 0, 0, 1 },\r
+       { NULL,                        MB_RANGE, MA_OPT_FRAMESKIP,     &currentConfig.Frameskip, 0, -1, 16, 1 },\r
+       { "Enable sound",              MB_ONOFF, MA_OPT_ENABLE_SOUND,  &currentConfig.EmuOpt,  0x004, 0, 0, 1 },\r
+       { NULL,                        MB_NONE,  MA_OPT_SOUND_QUALITY, NULL, 0, 0, 0, 1 },\r
+       { "Use ARM940 core for sound", MB_ONOFF, MA_OPT_ARM940_SOUND,  &currentConfig.PicoOpt, 0x200, 0, 0, 1 },\r
+       { "6 button pad",              MB_ONOFF, MA_OPT_6BUTTON_PAD,   &currentConfig.PicoOpt, 0x020, 0, 0, 1 },\r
+       { NULL,                        MB_NONE,  MA_OPT_REGION,        NULL, 0, 0, 0, 1 },\r
+       { "Use SRAM/BRAM savestates",  MB_ONOFF, MA_OPT_SRAM_STATES,   &currentConfig.EmuOpt,  0x001, 0, 0, 1 },\r
+       { NULL,                        MB_NONE,  MA_OPT_CONFIRM_STATES,NULL, 0, 0, 0, 1 },\r
+       { "Save slot",                 MB_RANGE, MA_OPT_SAVE_SLOT,     &state_slot, 0, 0, 9, 1 },\r
+       { NULL,                        MB_NONE,  MA_OPT_CPU_CLOCKS,    NULL, 0, 0, 0, 1 },\r
+       { "[Sega/Mega CD options]",    MB_NONE,  MA_OPT_SCD_OPTS,      NULL, 0, 0, 0, 1 },\r
+       { "[advanced options]",        MB_NONE,  MA_OPT_ADV_OPTS,      NULL, 0, 0, 0, 1 },\r
+       { NULL,                        MB_NONE,  MA_OPT_SAVECFG,       NULL, 0, 0, 0, 1 },\r
+       { "Save cfg for current game only",MB_NONE,MA_OPT_SAVECFG_GAME,NULL, 0, 0, 0, 1 },\r
+       { NULL,                        MB_NONE,  MA_OPT_LOADCFG,       NULL, 0, 0, 0, 1 },\r
+};\r
+\r
+#define OPT_ENTRY_COUNT (sizeof(opt_entries) / sizeof(opt_entries[0]))\r
+\r
+\r
 static const char *region_name(unsigned int code)\r
 {\r
        static const char *names[] = { "Auto", "      Japan NTSC", "      Japan PAL", "      USA", "      Europe" };\r
@@ -992,59 +1237,79 @@ static const char *region_name(unsigned int code)
        }\r
 }\r
 \r
-static void draw_menu_options(int menu_sel)\r
+\r
+static void menu_opt_cust_draw(const menu_entry *entry, int x, int y, void *param)\r
 {\r
-       int tl_x = 25, tl_y = 32, y;\r
-       char monostereo[8], strframeskip[8], *strrend, *strscaling, *strssconfirm;\r
-\r
-       strcpy(monostereo, (currentConfig.PicoOpt&0x08)?"stereo":"mono");\r
-       if (currentConfig.Frameskip < 0)\r
-                strcpy(strframeskip, "Auto");\r
-       else sprintf(strframeskip, "%i", currentConfig.Frameskip);\r
-       if (currentConfig.PicoOpt&0x10) {\r
-               strrend = " 8bit fast";\r
-       } else if (currentConfig.EmuOpt&0x80) {\r
-               strrend = "16bit accurate";\r
-       } else {\r
-               strrend = " 8bit accurate";\r
-       }\r
-       switch (currentConfig.scaling) {\r
-               default: strscaling = "            OFF";   break;\r
-               case 1:  strscaling = "hw horizontal";     break;\r
-               case 2:  strscaling = "hw horiz. + vert."; break;\r
-               case 3:  strscaling = "sw horizontal";     break;\r
-       }\r
-       switch ((currentConfig.EmuOpt >> 9) & 5) {\r
-               default: strssconfirm = "OFF";    break;\r
-               case 1:  strssconfirm = "writes"; break;\r
-               case 4:  strssconfirm = "loads";  break;\r
-               case 5:  strssconfirm = "both";   break;\r
+       char *str, str24[24];\r
+\r
+       switch (entry->id)\r
+       {\r
+               case MA_OPT_RENDERER:\r
+                       if (currentConfig.PicoOpt&0x10)\r
+                               str = " 8bit fast";\r
+                       else if (currentConfig.EmuOpt&0x80)\r
+                               str = "16bit accurate";\r
+                       else\r
+                               str = " 8bit accurate";\r
+                       gp2x_text_out8(x, y, "Renderer:            %s", str);\r
+                       break;\r
+               case MA_OPT_SCALING:\r
+                       switch (currentConfig.scaling) {\r
+                               default: str = "            OFF";   break;\r
+                               case 1:  str = "hw horizontal";     break;\r
+                               case 2:  str = "hw horiz. + vert."; break;\r
+                               case 3:  str = "sw horizontal";     break;\r
+                       }\r
+                       gp2x_text_out8(x, y, "Scaling:       %s", str);\r
+                       break;\r
+               case MA_OPT_FRAMESKIP:\r
+                       if (currentConfig.Frameskip < 0)\r
+                            strcpy(str24, "Auto");\r
+                       else sprintf(str24, "%i", currentConfig.Frameskip);\r
+                       gp2x_text_out8(x, y, "Frameskip                  %s", str24);\r
+                       break;\r
+               case MA_OPT_SOUND_QUALITY:\r
+                       str = (currentConfig.PicoOpt&0x08)?"stereo":"mono";\r
+                       gp2x_text_out8(x, y, "Sound Quality:     %5iHz %s", currentConfig.PsndRate, str);\r
+                       break;\r
+               case MA_OPT_REGION:\r
+                       gp2x_text_out8(x, y, "Region:              %s", region_name(currentConfig.PicoRegion));\r
+                       break;\r
+               case MA_OPT_CONFIRM_STATES:\r
+                       switch ((currentConfig.EmuOpt >> 9) & 5) {\r
+                               default: str = "OFF";    break;\r
+                               case 1:  str = "writes"; break;\r
+                               case 4:  str = "loads";  break;\r
+                               case 5:  str = "both";   break;\r
+                       }\r
+                       gp2x_text_out8(x, y, "Confirm savestate          %s", str);\r
+                       break;\r
+               case MA_OPT_CPU_CLOCKS:\r
+                       gp2x_text_out8(x, y, "GP2X CPU clocks            %iMhz", currentConfig.CPUclock);\r
+                       break;\r
+               case MA_OPT_SAVECFG:\r
+                       str24[0] = 0;\r
+                       if (config_slot != 0) sprintf(str24, " (profile: %i)", config_slot);\r
+                       gp2x_text_out8(x, y, "Save cfg as default%s", str24);\r
+                       break;\r
+               case MA_OPT_LOADCFG:\r
+                       gp2x_text_out8(x, y, "Load cfg from profile %i", config_slot);\r
+                       break;\r
+               default:\r
+                       printf("%s: unimplemented (%i)\n", __FUNCTION__, entry->id);\r
+                       break;\r
        }\r
+}\r
+\r
+\r
+\r
+static void draw_menu_options(int menu_sel)\r
+{\r
+       int tl_x = 25, tl_y = 32;\r
 \r
-       y = tl_y;\r
-       //memset(gp2x_screen, 0, 320*240);\r
        gp2x_pd_clone_buffer2();\r
 \r
-       gp2x_text_out8(tl_x, y,       "Renderer:            %s", strrend); // 0\r
-       gp2x_text_out8(tl_x, (y+=10), "Scaling:       %s", strscaling);    // 1\r
-       gp2x_text_out8(tl_x, (y+=10), "Accurate timing (slower)   %s", (currentConfig.PicoOpt&0x040)?"ON":"OFF"); // 2\r
-       gp2x_text_out8(tl_x, (y+=10), "Accurate sprites (slower)  %s", (currentConfig.PicoOpt&0x080)?"ON":"OFF"); // 3\r
-       gp2x_text_out8(tl_x, (y+=10), "Show FPS                   %s", (currentConfig.EmuOpt &0x002)?"ON":"OFF"); // 4\r
-       gp2x_text_out8(tl_x, (y+=10), "Frameskip                  %s", strframeskip);\r
-       gp2x_text_out8(tl_x, (y+=10), "Enable sound               %s", (currentConfig.EmuOpt &0x004)?"ON":"OFF"); // 6\r
-       gp2x_text_out8(tl_x, (y+=10), "Sound Quality:     %5iHz %s",   currentConfig.PsndRate, monostereo);\r
-       gp2x_text_out8(tl_x, (y+=10), "Use ARM940 core for sound  %s", (currentConfig.PicoOpt&0x200)?"ON":"OFF"); // 8\r
-       gp2x_text_out8(tl_x, (y+=10), "6 button pad               %s", (currentConfig.PicoOpt&0x020)?"ON":"OFF"); // 9\r
-       gp2x_text_out8(tl_x, (y+=10), "Region:              %s",       region_name(currentConfig.PicoRegion));\r
-       gp2x_text_out8(tl_x, (y+=10), "Use SRAM/BRAM savestates   %s", (currentConfig.EmuOpt &0x001)?"ON":"OFF"); // 11\r
-       gp2x_text_out8(tl_x, (y+=10), "Confirm savestate          %s", strssconfirm); // 12\r
-       gp2x_text_out8(tl_x, (y+=10), "Save slot                  %i", state_slot); // 13\r
-       gp2x_text_out8(tl_x, (y+=10), "GP2X CPU clocks            %iMhz", currentConfig.CPUclock);\r
-       gp2x_text_out8(tl_x, (y+=10), "[Sega/Mega CD options]");\r
-       gp2x_text_out8(tl_x, (y+=10), "[advanced options]");            // 16\r
-       gp2x_text_out8(tl_x, (y+=10), "Save cfg as default");\r
-       if (rom_data)\r
-               gp2x_text_out8(tl_x, (y+=10), "Save cfg for current game only");\r
+       me_draw(opt_entries, OPT_ENTRY_COUNT, tl_x, tl_y, menu_opt_cust_draw, NULL);\r
 \r
        // draw cursor\r
        gp2x_text_out8(tl_x - 16, tl_y + menu_sel*10, ">");\r
@@ -1106,108 +1371,127 @@ static void menu_options_save(void)
 static int menu_loop_options(void)\r
 {\r
        static int menu_sel = 0;\r
-       int menu_sel_max = 17;\r
+       int menu_sel_max, ret;\r
        unsigned long inp = 0;\r
+       menu_id selected_id;\r
 \r
-       if (rom_data) menu_sel_max++;\r
        currentConfig.PicoOpt = PicoOpt;\r
        currentConfig.PsndRate = PsndRate;\r
        currentConfig.PicoRegion = PicoRegionOverride;\r
 \r
-       for(;;)\r
+       me_enable(opt_entries, OPT_ENTRY_COUNT, MA_OPT_SAVECFG_GAME, rom_data != NULL);\r
+       me_enable(opt_entries, OPT_ENTRY_COUNT, MA_OPT_LOADCFG, config_slot != config_slot_current);\r
+       menu_sel_max = me_count_enabled(opt_entries, OPT_ENTRY_COUNT) - 1;\r
+\r
+       while (1)\r
        {\r
                draw_menu_options(menu_sel);\r
                inp = wait_for_input(GP2X_UP|GP2X_DOWN|GP2X_LEFT|GP2X_RIGHT|GP2X_B|GP2X_X|GP2X_A);\r
-               if(inp & GP2X_UP  ) { menu_sel--; if (menu_sel < 0) menu_sel = menu_sel_max; }\r
-               if(inp & GP2X_DOWN) { menu_sel++; if (menu_sel > menu_sel_max) menu_sel = 0; }\r
-               if((inp& GP2X_B)||(inp&GP2X_LEFT)||(inp&GP2X_RIGHT)) { // toggleable options\r
-                       switch (menu_sel) {\r
-                               case  2: currentConfig.PicoOpt^=0x040; break;\r
-                               case  3: currentConfig.PicoOpt^=0x080; break;\r
-                               case  4: currentConfig.EmuOpt ^=0x002; break;\r
-                               case  6: currentConfig.EmuOpt ^=0x004; break;\r
-                               case  8: currentConfig.PicoOpt^=0x200; break;\r
-                               case  9: currentConfig.PicoOpt^=0x020; break;\r
-                               case 11: currentConfig.EmuOpt ^=0x001; break;\r
-                               case 15: cd_menu_loop_options();\r
-                                       if (engineState == PGS_ReloadRom)\r
-                                               return 0; // test BIOS\r
-                                       break;\r
-                               case 16: amenu_loop_options();    break;\r
-                               case 17: // done (update and write)\r
-                                       menu_options_save();\r
-                                       if (emu_WriteConfig(0)) strcpy(menuErrorMsg, "config saved");\r
-                                       else strcpy(menuErrorMsg, "failed to write config");\r
-                                       return 1;\r
-                               case 18: // done (update and write for current game)\r
-                                       menu_options_save();\r
-                                       if (emu_WriteConfig(1)) strcpy(menuErrorMsg, "config saved");\r
-                                       else strcpy(menuErrorMsg, "failed to write config");\r
-                                       return 1;\r
+               if (inp & GP2X_UP  ) { menu_sel--; if (menu_sel < 0) menu_sel = menu_sel_max; }\r
+               if (inp & GP2X_DOWN) { menu_sel++; if (menu_sel > menu_sel_max) menu_sel = 0; }\r
+               selected_id = me_index2id(opt_entries, OPT_ENTRY_COUNT, menu_sel);\r
+               if (inp & (GP2X_LEFT|GP2X_RIGHT)) { // multi choise\r
+                       if (!me_process(opt_entries, OPT_ENTRY_COUNT, selected_id, (inp&GP2X_RIGHT) ? 1 : 0)) {\r
+                               switch (selected_id) {\r
+                                       case MA_OPT_RENDERER:\r
+                                               if (inp & GP2X_LEFT) {\r
+                                                       if      (  currentConfig.PicoOpt&0x10) currentConfig.PicoOpt&= ~0x10;\r
+                                                       else if (!(currentConfig.EmuOpt &0x80))currentConfig.EmuOpt |=  0x80;\r
+                                                       else if (  currentConfig.EmuOpt &0x80) break;\r
+                                               } else {\r
+                                                       if      (  currentConfig.PicoOpt&0x10) break;\r
+                                                       else if (!(currentConfig.EmuOpt &0x80))currentConfig.PicoOpt|=  0x10;\r
+                                                       else if (  currentConfig.EmuOpt &0x80) currentConfig.EmuOpt &= ~0x80;\r
+                                               }\r
+                                               break;\r
+                                       case MA_OPT_SOUND_QUALITY:\r
+                                               if ((inp & GP2X_RIGHT) && currentConfig.PsndRate == 44100 && !(currentConfig.PicoOpt&0x08)) {\r
+                                                       currentConfig.PsndRate = 8000;  currentConfig.PicoOpt|= 0x08;\r
+                                               } else if ((inp & GP2X_LEFT) && currentConfig.PsndRate == 8000 && (currentConfig.PicoOpt&0x08)) {\r
+                                                       currentConfig.PsndRate = 44100; currentConfig.PicoOpt&=~0x08;\r
+                                               } else currentConfig.PsndRate = sndrate_prevnext(currentConfig.PsndRate, inp & GP2X_RIGHT);\r
+                                               break;\r
+                                       case MA_OPT_REGION:\r
+                                               region_prevnext(inp & GP2X_RIGHT);\r
+                                               break;\r
+                                       case MA_OPT_CONFIRM_STATES: {\r
+                                                        int n = ((currentConfig.EmuOpt>>9)&1) | ((currentConfig.EmuOpt>>10)&2);\r
+                                                        n += (inp & GP2X_LEFT) ? -1 : 1;\r
+                                                        if (n < 0) n = 0; else if (n > 3) n = 3;\r
+                                                        n |= n << 1; n &= ~2;\r
+                                                        currentConfig.EmuOpt &= ~0xa00;\r
+                                                        currentConfig.EmuOpt |= n << 9;\r
+                                                        break;\r
+                                                }\r
+                                       case MA_OPT_SAVE_SLOT:\r
+                                                if (inp & GP2X_RIGHT) {\r
+                                                        state_slot++; if (state_slot > 9) state_slot = 0;\r
+                                                } else {state_slot--; if (state_slot < 0) state_slot = 9;\r
+                                                }\r
+                                                break;\r
+                                       case MA_OPT_CPU_CLOCKS:\r
+                                                while ((inp = gp2x_joystick_read(1)) & (GP2X_LEFT|GP2X_RIGHT)) {\r
+                                                        currentConfig.CPUclock += (inp & GP2X_LEFT) ? -1 : 1;\r
+                                                        if (currentConfig.CPUclock < 1) currentConfig.CPUclock = 1;\r
+                                                        draw_menu_options(menu_sel);\r
+                                                        usleep(50*1000);\r
+                                                }\r
+                                                break;\r
+                                       case MA_OPT_SAVECFG:\r
+                                       case MA_OPT_SAVECFG_GAME:\r
+                                       case MA_OPT_LOADCFG:\r
+                                                config_slot += (inp&GP2X_RIGHT) ? 1 : -1;\r
+                                                if (config_slot > 9) config_slot = 0;\r
+                                                if (config_slot < 0) config_slot = 9;\r
+                                                me_enable(opt_entries, OPT_ENTRY_COUNT, MA_OPT_LOADCFG, config_slot != config_slot_current);\r
+                                                menu_sel_max = me_count_enabled(opt_entries, OPT_ENTRY_COUNT) - 1;\r
+                                                if (menu_sel > menu_sel_max) menu_sel = menu_sel_max;\r
+                                                break;\r
+                                       default:\r
+                                               //printf("%s: something unknown selected (%i)\n", __FUNCTION__, selected_id);\r
+                                               break;\r
+                               }\r
+                       }\r
+               }\r
+               if (inp & GP2X_B) {\r
+                       if (!me_process(opt_entries, OPT_ENTRY_COUNT, selected_id, 1))\r
+                       {\r
+                               switch (selected_id)\r
+                               {\r
+                                       case MA_OPT_SCD_OPTS:\r
+                                               cd_menu_loop_options();\r
+                                               if (engineState == PGS_ReloadRom)\r
+                                                       return 0; // test BIOS\r
+                                               break;\r
+                                       case MA_OPT_ADV_OPTS:\r
+                                               amenu_loop_options();\r
+                                               break;\r
+                                       case MA_OPT_SAVECFG: // done (update and write)\r
+                                               menu_options_save();\r
+                                               if (emu_WriteConfig(0)) strcpy(menuErrorMsg, "config saved");\r
+                                               else strcpy(menuErrorMsg, "failed to write config");\r
+                                               return 1;\r
+                                       case MA_OPT_SAVECFG_GAME: // done (update and write for current game)\r
+                                               menu_options_save();\r
+                                               if (emu_WriteConfig(1)) strcpy(menuErrorMsg, "config saved");\r
+                                               else strcpy(menuErrorMsg, "failed to write config");\r
+                                               return 1;\r
+                                       case MA_OPT_LOADCFG:\r
+                                               ret = emu_ReadConfig(1);\r
+                                               if (!ret) ret = emu_ReadConfig(0);\r
+                                               if (!ret) strcpy(menuErrorMsg, "config loaded");\r
+                                               else      strcpy(menuErrorMsg, "failed to load config");\r
+                                               return 1;\r
+                                       default:\r
+                                               //printf("%s: something unknown selected (%i)\n", __FUNCTION__, selected_id);\r
+                                               break;\r
+                               }\r
                        }\r
                }\r
                if(inp & (GP2X_X|GP2X_A)) {\r
                        menu_options_save();\r
                        return 0;  // done (update, no write)\r
                }\r
-               if(inp & (GP2X_LEFT|GP2X_RIGHT)) { // multi choise\r
-                       switch (menu_sel) {\r
-                               case  0:\r
-                                       if (inp & GP2X_LEFT) {\r
-                                               if      (  currentConfig.PicoOpt&0x10) currentConfig.PicoOpt&= ~0x10;\r
-                                               else if (!(currentConfig.EmuOpt &0x80))currentConfig.EmuOpt |=  0x80;\r
-                                               else if (  currentConfig.EmuOpt &0x80) break;\r
-                                       } else {\r
-                                               if      (  currentConfig.PicoOpt&0x10) break;\r
-                                               else if (!(currentConfig.EmuOpt &0x80))currentConfig.PicoOpt|=  0x10;\r
-                                               else if (  currentConfig.EmuOpt &0x80) currentConfig.EmuOpt &= ~0x80;\r
-                                       }\r
-                                       break;\r
-                               case  1:\r
-                                       currentConfig.scaling += (inp & GP2X_LEFT) ? -1 : 1;\r
-                                       if (currentConfig.scaling < 0) currentConfig.scaling = 0;\r
-                                       if (currentConfig.scaling > 3) currentConfig.scaling = 3;\r
-                                       break;\r
-                               case  5:\r
-                                       currentConfig.Frameskip += (inp & GP2X_LEFT) ? -1 : 1;\r
-                                       if (currentConfig.Frameskip < 0)  currentConfig.Frameskip = -1;\r
-                                       if (currentConfig.Frameskip > 32) currentConfig.Frameskip = 32;\r
-                                       break;\r
-                               case  7:\r
-                                       if ((inp & GP2X_RIGHT) && currentConfig.PsndRate == 44100 && !(currentConfig.PicoOpt&0x08)) {\r
-                                               currentConfig.PsndRate = 8000;  currentConfig.PicoOpt|= 0x08;\r
-                                       } else if ((inp & GP2X_LEFT) && currentConfig.PsndRate == 8000 && (currentConfig.PicoOpt&0x08)) {\r
-                                               currentConfig.PsndRate = 44100; currentConfig.PicoOpt&=~0x08;\r
-                                       } else currentConfig.PsndRate = sndrate_prevnext(currentConfig.PsndRate, inp & GP2X_RIGHT);\r
-                                       break;\r
-                               case 10:\r
-                                       region_prevnext(inp & GP2X_RIGHT);\r
-                                       break;\r
-                               case 12: {\r
-                                       int n = ((currentConfig.EmuOpt>>9)&1) | ((currentConfig.EmuOpt>>10)&2);\r
-                                       n += (inp & GP2X_LEFT) ? -1 : 1;\r
-                                       if (n < 0) n = 0; else if (n > 3) n = 3;\r
-                                       n |= n << 1; n &= ~2;\r
-                                       currentConfig.EmuOpt &= ~0xa00;\r
-                                       currentConfig.EmuOpt |= n << 9;\r
-                                       break;\r
-                               }\r
-                               case 13:\r
-                                       if (inp & GP2X_RIGHT) {\r
-                                               state_slot++; if (state_slot > 9) state_slot = 0;\r
-                                       } else {state_slot--; if (state_slot < 0) state_slot = 9;\r
-                                       }\r
-                                       break;\r
-                               case 14:\r
-                                       while ((inp = gp2x_joystick_read(1)) & (GP2X_LEFT|GP2X_RIGHT)) {\r
-                                               currentConfig.CPUclock += (inp & GP2X_LEFT) ? -1 : 1;\r
-                                               if (currentConfig.CPUclock < 1) currentConfig.CPUclock = 1;\r
-                                               draw_menu_options(menu_sel);\r
-                                               usleep(50*1000);\r
-                                       }\r
-                                       break;\r
-                       }\r
-               }\r
        }\r
 }\r
 \r
@@ -1242,30 +1526,31 @@ static void draw_menu_credits(void)
 \r
 // -------------- root menu --------------\r
 \r
+menu_entry main_entries[] =\r
+{\r
+       { "Resume game",        MB_NONE, MA_MAIN_RESUME_GAME, NULL, 0, 0, 0, 0 },\r
+       { "Save State",         MB_NONE, MA_MAIN_SAVE_STATE,  NULL, 0, 0, 0, 0 },\r
+       { "Load State",         MB_NONE, MA_MAIN_LOAD_STATE,  NULL, 0, 0, 0, 0 },\r
+       { "Reset game",         MB_NONE, MA_MAIN_RESET_GAME,  NULL, 0, 0, 0, 0 },\r
+       { "Load new ROM/ISO",   MB_NONE, MA_MAIN_LOAD_ROM,    NULL, 0, 0, 0, 1 },\r
+       { "Change options",     MB_NONE, MA_MAIN_OPTIONS,     NULL, 0, 0, 0, 1 },\r
+       { "Configure controls", MB_NONE, MA_MAIN_CONTROLS,    NULL, 0, 0, 0, 1 },\r
+       { "Credits",            MB_NONE, MA_MAIN_CREDITS,     NULL, 0, 0, 0, 1 },\r
+       { "Patches / GameGenie",MB_NONE, MA_MAIN_PATCHES,     NULL, 0, 0, 0, 0 },\r
+       { "Exit",               MB_NONE, MA_MAIN_EXIT,        NULL, 0, 0, 0, 1 }\r
+};\r
+\r
+#define MAIN_ENTRY_COUNT (sizeof(main_entries) / sizeof(main_entries[0]))\r
+\r
 static void draw_menu_root(int menu_sel)\r
 {\r
-       int tl_x = 70, tl_y = 70, y;\r
-       //memset(gp2x_screen, 0, 320*240);\r
+       const int tl_x = 70, tl_y = 70;\r
+\r
        gp2x_pd_clone_buffer2();\r
 \r
        gp2x_text_out8(tl_x, 20, "PicoDrive v" VERSION);\r
 \r
-       y = tl_y;\r
-       if (rom_data) {\r
-               gp2x_text_out8(tl_x, y,       "Resume game");\r
-               gp2x_text_out8(tl_x, (y+=10), "Save State");\r
-               gp2x_text_out8(tl_x, (y+=10), "Load State");\r
-               gp2x_text_out8(tl_x, (y+=10), "Reset game");\r
-       } else {\r
-               y += 30;\r
-       }\r
-       gp2x_text_out8(tl_x, (y+=10), "Load new ROM/ISO");\r
-       gp2x_text_out8(tl_x, (y+=10), "Change options");\r
-       gp2x_text_out8(tl_x, (y+=10), "Configure controls");\r
-       gp2x_text_out8(tl_x, (y+=10), "Credits");\r
-       gp2x_text_out8(tl_x, (y+=10), "Exit");\r
-       if (PicoPatches)\r
-               gp2x_text_out8(tl_x, (y+=10), "Patches / GameGenie");\r
+       me_draw(main_entries, MAIN_ENTRY_COUNT, tl_x, tl_y, NULL, NULL);\r
 \r
        // draw cursor\r
        gp2x_text_out8(tl_x - 16, tl_y + menu_sel*10, ">");\r
@@ -1277,8 +1562,8 @@ static void draw_menu_root(int menu_sel)
 \r
 static void menu_loop_root(void)\r
 {\r
-       static int menu_sel = 4;\r
-       int ret, menu_sel_max = 8, menu_sel_min = 4;\r
+       static int menu_sel = 0;\r
+       int ret, menu_sel_max;\r
        unsigned long inp = 0;\r
        char curr_path[PATH_MAX], *selfname;\r
        FILE *tstf;\r
@@ -1293,8 +1578,13 @@ static void menu_loop_root(void)
                getcwd(curr_path, PATH_MAX);\r
        }\r
 \r
-       if (rom_data) menu_sel_min = 0;\r
-       if (PicoPatches) menu_sel_max = 9;\r
+       me_enable(main_entries, MAIN_ENTRY_COUNT, MA_MAIN_RESUME_GAME, rom_data != NULL);\r
+       me_enable(main_entries, MAIN_ENTRY_COUNT, MA_MAIN_SAVE_STATE,  rom_data != NULL);\r
+       me_enable(main_entries, MAIN_ENTRY_COUNT, MA_MAIN_LOAD_STATE,  rom_data != NULL);\r
+       me_enable(main_entries, MAIN_ENTRY_COUNT, MA_MAIN_RESET_GAME,  rom_data != NULL);\r
+       me_enable(main_entries, MAIN_ENTRY_COUNT, MA_MAIN_PATCHES,     PicoPatches != NULL);\r
+\r
+       menu_sel_max = me_count_enabled(main_entries, MAIN_ENTRY_COUNT) - 1;\r
 \r
        /* make sure action buttons are not pressed on entering menu */\r
        draw_menu_root(menu_sel);\r
@@ -1304,8 +1594,8 @@ static void menu_loop_root(void)
        {\r
                draw_menu_root(menu_sel);\r
                inp = wait_for_input(GP2X_UP|GP2X_DOWN|GP2X_B|GP2X_X|GP2X_SELECT|GP2X_L|GP2X_R);\r
-               if(inp & GP2X_UP  )  { menu_sel--; if (menu_sel < menu_sel_min) menu_sel = menu_sel_max; }\r
-               if(inp & GP2X_DOWN)  { menu_sel++; if (menu_sel > menu_sel_max) menu_sel = menu_sel_min; }\r
+               if(inp & GP2X_UP  )  { menu_sel--; if (menu_sel < 0) menu_sel = menu_sel_max; }\r
+               if(inp & GP2X_DOWN)  { menu_sel++; if (menu_sel > menu_sel_max) menu_sel = 0; }\r
                if((inp & (GP2X_L|GP2X_R)) == (GP2X_L|GP2X_R)) debug_menu_loop();\r
                if(inp &(GP2X_SELECT|GP2X_X)){\r
                        if (rom_data) {\r
@@ -1314,16 +1604,17 @@ static void menu_loop_root(void)
                                break;\r
                        }\r
                }\r
-               if(inp & GP2X_B   )  {\r
-                       switch (menu_sel) {\r
-                               case 0: // resume game\r
+               if(inp & GP2X_B)  {\r
+                       switch (me_index2id(main_entries, MAIN_ENTRY_COUNT, menu_sel))\r
+                       {\r
+                               case MA_MAIN_RESUME_GAME:\r
                                        if (rom_data) {\r
                                                while (gp2x_joystick_read(1) & GP2X_B) usleep(50*1000);\r
                                                engineState = PGS_Running;\r
                                                return;\r
                                        }\r
                                        break;\r
-                               case 1: // save state\r
+                               case MA_MAIN_SAVE_STATE:\r
                                        if (rom_data) {\r
                                                if(savestate_menu_loop(0))\r
                                                        continue;\r
@@ -1331,7 +1622,7 @@ static void menu_loop_root(void)
                                                return;\r
                                        }\r
                                        break;\r
-                               case 2: // load state\r
+                               case MA_MAIN_LOAD_STATE:\r
                                        if (rom_data) {\r
                                                if(savestate_menu_loop(1))\r
                                                        continue;\r
@@ -1339,38 +1630,38 @@ static void menu_loop_root(void)
                                                return;\r
                                        }\r
                                        break;\r
-                               case 3: // reset game\r
+                               case MA_MAIN_RESET_GAME:\r
                                        if (rom_data) {\r
                                                emu_ResetGame();\r
                                                engineState = PGS_Running;\r
                                                return;\r
                                        }\r
                                        break;\r
-                               case 4: // select rom\r
+                               case MA_MAIN_LOAD_ROM:\r
                                        selfname = romsel_loop(curr_path);\r
                                        if (selfname) {\r
                                                printf("selected file: %s\n", selfname);\r
                                                engineState = PGS_ReloadRom;\r
                                        }\r
                                        return;\r
-                               case 5: // options\r
+                               case MA_MAIN_OPTIONS:\r
                                        ret = menu_loop_options();\r
                                        if (ret == 1) continue; // status update\r
                                        if (engineState == PGS_ReloadRom)\r
                                                return; // BIOS test\r
                                        break;\r
-                               case 6: // controls\r
+                               case MA_MAIN_CONTROLS:\r
                                        kc_sel_loop();\r
                                        break;\r
-                               case 7: // credits\r
+                               case MA_MAIN_CREDITS:\r
                                        draw_menu_credits();\r
                                        usleep(500*1000);\r
                                        inp = wait_for_input(GP2X_B|GP2X_X);\r
                                        break;\r
-                               case 8: // exit\r
+                               case MA_MAIN_EXIT:\r
                                        engineState = PGS_Quit;\r
                                        return;\r
-                               case 9: // patches/gg\r
+                               case MA_MAIN_PATCHES:\r
                                        if (rom_data && PicoPatches) {\r
                                                patches_menu_loop();\r
                                                PicoPatchApply();\r
@@ -1378,6 +1669,9 @@ static void menu_loop_root(void)
                                                continue;\r
                                        }\r
                                        break;\r
+                               default:\r
+                                       printf("%s: something unknown selected\n", __FUNCTION__);\r
+                                       break;\r
                        }\r
                }\r
                menuErrorMsg[0] = 0; // clear error msg\r
index a01a529..12b8860 100644 (file)
@@ -44,8 +44,7 @@ OBJS += ../../unzip/unzip.o ../../unzip/unzip_stream.o
 OBJS += ../gp2x/mp3.o
 # CPU cores
 DEFINC += -DEMU_M68K
-OBJS += ../../cpu/musashi/m68kcpu.o  ../../cpu/musashi/m68kopac.o ../../cpu/musashi/m68kopdm.o \
-       ../../cpu/musashi/m68kopnz.o ../../cpu/musashi/m68kops.o
+OBJS += ../../cpu/musashi/m68kops.o ../../cpu/musashi/m68kcpu.o
 # mz80
 DEFINC += -D_USE_MZ80
 OBJS += ../../cpu/mz80/mz80.o
index ec8b10e..199d69e 100644 (file)
@@ -385,6 +385,13 @@ void set_gamma(int g100, int A_SNs_curve)
 {
 }
 
+void set_LCD_custom_rate(int rate)
+{
+}
+
+void unset_LCD_custom_rate(void)
+{
+}
 
 /* squidgehack.c */
 int mmuhack(void)