ISO loading, menus, LEDs
[libpicofe.git] / gp2x / menu.c
index 7b18517..1232e87 100644 (file)
@@ -562,10 +562,8 @@ static void kc_sel_loop(void)
 \r
 \r
 \r
-\r
-// --------- advanced options ----------\r
-\r
 // order must match that of currentConfig_t\r
+\r
 struct {\r
        int EmuOpt;\r
        int PicoOpt;\r
@@ -576,6 +574,94 @@ struct {
 } tmp_opts;\r
 int tmp_gamma;\r
 \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
+{\r
+       int tl_x = 25, tl_y = 60, y;\r
+\r
+       y = tl_y;\r
+       memset(gp2x_screen, 0, 320*240);\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", (tmp_opts.EmuOpt &0x400)?"ON":"OFF"); // 3\r
+       gp2x_text_out8(tl_x, (y+=10), "CDDA audio (using mp3s)    %s", (tmp_opts.EmuOpt &0x800)?"ON":"OFF"); // 4\r
+       gp2x_text_out8(tl_x, (y+=10), "Done");\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
+                       gp2x_text_out8(tl_x, 220, "Press start to test selected BIOS");\r
+\r
+       gp2x_video_flip();\r
+}\r
+\r
+static void cd_menu_loop_options(void)\r
+{\r
+       int menu_sel = 0, menu_sel_max = 5;\r
+       unsigned long inp = 0;\r
+       char bios_us[32], bios_eu[32], bios_jp[32], *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
+\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
+\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
+\r
+       for(;;)\r
+       {\r
+               draw_cd_menu_options(menu_sel, bios_us, bios_eu, bios_jp);\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: tmp_opts.EmuOpt ^=0x400; break;\r
+                               case  4: return;\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
+                                               strcpy(romFileName, bios);\r
+                                               engineState = PGS_ReloadRom;\r
+                                               return;\r
+                                       }\r
+                                       break;\r
+                               case 1: 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
+                                               strcpy(romFileName, bios);\r
+                                               engineState = PGS_ReloadRom;\r
+                                               return;\r
+                                       }\r
+                                       break;\r
+                       }\r
+               }\r
+       }\r
+}\r
+\r
+\r
+// --------- advanced options ----------\r
+\r
 static void draw_amenu_options(int menu_sel)\r
 {\r
        int tl_x = 25, tl_y = 60, y;\r
@@ -683,11 +769,12 @@ static void draw_menu_options(int menu_sel)
        gp2x_text_out8(tl_x, (y+=10), "Use ARM940 core for sound  %s", (tmp_opts.PicoOpt&0x200)?"ON":"OFF"); // 7\r
        gp2x_text_out8(tl_x, (y+=10), "6 button pad               %s", (tmp_opts.PicoOpt&0x020)?"ON":"OFF"); // 8\r
        gp2x_text_out8(tl_x, (y+=10), "Genesis Region:            %s", region_name(tmp_opts.PicoRegion));\r
-       gp2x_text_out8(tl_x, (y+=10), "Use SRAM savestates        %s", (tmp_opts.EmuOpt &0x001)?"ON":"OFF"); // 10\r
+       gp2x_text_out8(tl_x, (y+=10), "Use SRAM/BRAM savestates   %s", (tmp_opts.EmuOpt &0x001)?"ON":"OFF"); // 10\r
        gp2x_text_out8(tl_x, (y+=10), "Confirm save overwrites    %s", (tmp_opts.EmuOpt &0x200)?"ON":"OFF"); // 11\r
        gp2x_text_out8(tl_x, (y+=10), "Save slot                  %i", state_slot); // 12\r
        gp2x_text_out8(tl_x, (y+=10), "GP2X CPU clocks            %iMhz", tmp_opts.CPUclock);\r
-       gp2x_text_out8(tl_x, (y+=10), "[advanced options]");\r
+       gp2x_text_out8(tl_x, (y+=10), "[Sega/Mega CD options]");\r
+       gp2x_text_out8(tl_x, (y+=10), "[advanced options]");            // 15\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
@@ -726,9 +813,9 @@ static void menu_options_save(void)
        }\r
 }\r
 \r
-static void menu_loop_options(void)\r
+static int menu_loop_options(void)\r
 {\r
-       int menu_sel = 0, menu_sel_max = 15;\r
+       int menu_sel = 0, menu_sel_max = 16;\r
        unsigned long inp = 0;\r
 \r
        if (rom_data) menu_sel_max++;\r
@@ -754,21 +841,27 @@ static void menu_loop_options(void)
                                case  8: tmp_opts.PicoOpt^=0x020; break;\r
                                case 10: tmp_opts.EmuOpt ^=0x001; break;\r
                                case 11: tmp_opts.EmuOpt ^=0x200; break;\r
-                               case 14: amenu_loop_options();    break;\r
-                               case 15: // done (save)\r
+                               case 14: cd_menu_loop_options();\r
+                                       if (engineState == PGS_ReloadRom)\r
+                                               return 0; // test BIOS\r
+                                       break;\r
+                               case 15: amenu_loop_options();    break;\r
+                               case 16: // done (update and write)\r
                                        menu_options_save();\r
-                                       emu_WriteConfig(0);\r
-                                       return;\r
-                               case 16: // done (save for current game)\r
+                                       if (emu_WriteConfig(0)) strcpy(menuErrorMsg, "config saved");\r
+                                       else strcpy(menuErrorMsg, "failed to write config");\r
+                                       return 1;\r
+                               case 17: // done (update and write for current game)\r
                                        menu_options_save();\r
-                                       emu_WriteConfig(1);\r
-                                       return;\r
+                                       if (emu_WriteConfig(1)) strcpy(menuErrorMsg, "config saved");\r
+                                       else strcpy(menuErrorMsg, "failed to write config");\r
+                                       return 1;\r
                        }\r
                }\r
-               if(inp & GP2X_X) return;  // done (no save)\r
+               if(inp & GP2X_X) return 0;  // done (no update or write)\r
                if(inp & GP2X_A) {\r
                        menu_options_save();\r
-                       return;  // done (save)\r
+                       return 0;  // done (update, no write)\r
                }\r
                if(inp & (GP2X_LEFT|GP2X_RIGHT)) { // multi choise\r
                        switch (menu_sel) {\r
@@ -882,7 +975,7 @@ static void draw_menu_root(int menu_sel)
 \r
 static void menu_loop_root(void)\r
 {\r
-       int menu_sel = 4, menu_sel_max = 8, menu_sel_min = 4;\r
+       int ret, menu_sel = 4, menu_sel_max = 8, menu_sel_min = 4;\r
        unsigned long inp = 0;\r
        char curr_path[PATH_MAX], *selfname;\r
        FILE *tstf;\r
@@ -948,13 +1041,14 @@ static void menu_loop_root(void)
                                        selfname = romsel_loop(curr_path);\r
                                        if (selfname) {\r
                                                printf("selected file: %s\n", selfname);\r
-                                               strncpy(currentConfig.lastRomFile, selfname, sizeof(currentConfig.lastRomFile)-1);\r
-                                               currentConfig.lastRomFile[sizeof(currentConfig.lastRomFile)-1] = 0;\r
                                                engineState = PGS_ReloadRom;\r
                                        }\r
                                        return;\r
                                case 5: // options\r
-                                       menu_loop_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
                                        kc_sel_loop();\r