ISO loading, menus, LEDs
authornotaz <notasas@gmail.com>
Mon, 8 Jan 2007 21:17:08 +0000 (21:17 +0000)
committernotaz <notasas@gmail.com>
Mon, 8 Jan 2007 21:17:08 +0000 (21:17 +0000)
git-svn-id: file:///home/notaz/opt/svn/PicoDrive/platform@16 be3aeb3a-fb24-0410-a615-afba39da0efa

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

index a90d850..666537c 100644 (file)
@@ -96,29 +96,131 @@ static int try_rfn_cut(void)
        return 0;\r
 }\r
 \r
-static void get_ext(char *ext)\r
+static void get_ext(char *file, char *ext)\r
 {\r
        char *p;\r
 \r
-       p = romFileName + strlen(romFileName) - 4;\r
-       if (p < romFileName) p = romFileName;\r
+       p = file + strlen(file) - 4;\r
+       if (p < file) p = file;\r
        strncpy(ext, p, 4);\r
        ext[4] = 0;\r
        strlwr(ext);\r
 }\r
 \r
+char *biosfiles_us[] = { "us_scd2_9306", "SegaCDBIOS9303", "us_scd1_9210" };\r
+char *biosfiles_eu[] = { "eu_mcd2_9306", "eu_mcd2_9303",   "eu_mcd1_9210" };\r
+char *biosfiles_jp[] = { "jp_mcd1_9112", "jp_mcd1_9111" };\r
+\r
+extern char **g_argv;\r
+\r
+int find_bios(int region, char **bios_file)\r
+{\r
+       static char bios_path[1024];\r
+       int i, j, count;\r
+       char **files;\r
+       FILE *f = NULL;\r
+\r
+       if (region == 4) { // US\r
+               files = biosfiles_us;\r
+               count = sizeof(biosfiles_us) / sizeof(char *);\r
+       } else if (region == 8) { // EU\r
+               files = biosfiles_eu;\r
+               count = sizeof(biosfiles_eu) / sizeof(char *);\r
+       } else if (region == 1 || region == 2) {\r
+               files = biosfiles_jp;\r
+               count = sizeof(biosfiles_jp) / sizeof(char *);\r
+       } else {\r
+               return 0;\r
+       }\r
+\r
+       for (i = 0; i < count; i++)\r
+       {\r
+               strncpy(bios_path, g_argv[0], 1023);\r
+               bios_path[1024-32] = 0;\r
+               for (j = strlen(bios_path); j > 0; j--)\r
+                       if (bios_path[j] == '/') { bios_path[j+1] = 0; break; }\r
+               strcat(bios_path, files[i]);\r
+               strcat(bios_path, ".bin");\r
+               f = fopen(bios_path, "rb");\r
+               if (f) break;\r
+\r
+               bios_path[strlen(bios_path) - 4] = 0;\r
+               strcat(bios_path, ".zip");\r
+               f = fopen(bios_path, "rb");\r
+               if (f) break;\r
+       }\r
+\r
+       if (f) {\r
+               printf("using bios: %s\n", bios_path);\r
+               fclose(f);\r
+               if (bios_file) *bios_file = bios_path;\r
+               return 1;\r
+       } else {\r
+               sprintf(menuErrorMsg, "no %s BIOS files found, read docs",\r
+                       region != 4 ? (region == 8 ? "EU" : "JAP") : "USA");\r
+               printf("%s\n", menuErrorMsg);\r
+               return 0;\r
+       }\r
+}\r
+\r
+/* checks if romFileName points to valid MegaCD image\r
+ * if so, checks for suitable BIOS */\r
+static int cd_check(char *ext, char **bios_file)\r
+{\r
+       unsigned char buf[32];\r
+       FILE *cd_f;\r
+       int type = 0, region = 4; // 1: Japan, 4: US, 8: Europe\r
+\r
+       cd_f = fopen(romFileName, "rb");\r
+       if (!cd_f) return 0; // let the upper level handle this\r
+\r
+       if (fread(buf, 1, 32, cd_f) != 32) {\r
+               fclose(cd_f);\r
+               return 0;\r
+       }\r
+\r
+       if (!strncasecmp("SEGADISCSYSTEM", (char *)buf+0x00, 14)) type = 1;       // Sega CD (ISO)\r
+       if (!strncasecmp("SEGADISCSYSTEM", (char *)buf+0x10, 14)) type = 2;       // Sega CD (BIN)\r
+       if (type == 0) {\r
+               fclose(cd_f);\r
+               return 0;\r
+       }\r
+\r
+       /* it seems we have a CD image here. Try to detect region and load a suitable BIOS now.. */\r
+       fseek(cd_f, (type == 1) ? 0x100 : 0x110, SEEK_SET);\r
+       fread(buf, 1, 1, cd_f);\r
+       fclose(cd_f);\r
+\r
+       if (buf[0] == 0x64) region = 4; // EU\r
+       if (buf[0] == 0xa1) region = 1; // JAP\r
+\r
+       printf("detected %s Sega/Mega CD image with %s region\n",\r
+               type == 2 ? "BIN" : "ISO", region != 4 ? (region == 8 ? "EU" : "JAP") : "USA");\r
+\r
+       if (PicoRegionOverride) {\r
+               region = PicoRegionOverride;\r
+               printf("overrided region to %s\n", region != 4 ? (region == 8 ? "EU" : "JAP") : "USA");\r
+       }\r
+\r
+       if(find_bios(region, bios_file))\r
+                return type;   // CD and BIOS detected\r
+\r
+       return -1;              // CD detected but load failed\r
+}\r
+\r
 int emu_ReloadRom(void)\r
 {\r
        unsigned int rom_size = 0;\r
+       char *used_rom_name = romFileName;\r
        char ext[5];\r
        FILE *rom;\r
-       int ret;\r
+       int ret, cd_state;\r
 \r
        printf("emu_ReloadRom(%s)\n", romFileName);\r
 \r
-       // detect wrong extensions\r
-       get_ext(ext);\r
+       get_ext(romFileName, ext);\r
 \r
+       // detect wrong extensions\r
        if(!strcmp(ext, ".srm") || !strcmp(ext, "s.gz") || !strcmp(ext, ".mds")) { // s.gz ~ .mds.gz\r
                sprintf(menuErrorMsg, "Not a ROM selected.");\r
                return 0;\r
@@ -162,10 +264,22 @@ int emu_ReloadRom(void)
                        sprintf(menuErrorMsg, "Could't find a ROM for movie.");\r
                        return 0;\r
                }\r
-               get_ext(ext);\r
+               get_ext(romFileName, ext);\r
        }\r
 \r
-       rom = fopen(romFileName, "rb");\r
+       // check for MegaCD image\r
+       cd_state = cd_check(ext, &used_rom_name);\r
+       if (cd_state > 0) {\r
+               PicoMCD |= 1;\r
+               get_ext(used_rom_name, ext);\r
+       } else if (cd_state == -1) {\r
+               // bios_help() ?\r
+               return 0;\r
+       } else {\r
+               PicoMCD &= ~1;\r
+       }\r
+\r
+       rom = fopen(used_rom_name, "rb");\r
        if(!rom) {\r
                sprintf(menuErrorMsg, "Failed to open rom.");\r
                return 0;\r
@@ -180,9 +294,9 @@ int emu_ReloadRom(void)
        // zipfile support\r
        if(!strcasecmp(ext, ".zip")) {\r
                fclose(rom);\r
-               ret = CartLoadZip(romFileName, &rom_data, &rom_size);\r
+               ret = CartLoadZip(used_rom_name, &rom_data, &rom_size);\r
                if(ret) {\r
-                       if (ret == 4) strcpy(menuErrorMsg, "No ROMs in zip found.");\r
+                       if (ret == 4) strcpy(menuErrorMsg, "No ROMs found in zip.");\r
                        else sprintf(menuErrorMsg, "Unzip failed with code %i", ret);\r
                        printf("%s\n", menuErrorMsg);\r
                        return 0;\r
@@ -206,16 +320,28 @@ int emu_ReloadRom(void)
                return 0;\r
        }\r
 \r
+       // load config for this ROM (do this before insert to get correct region)\r
+       ret = emu_ReadConfig(1);\r
+       if (!ret)\r
+               emu_ReadConfig(0);\r
+\r
        printf("PicoCartInsert(%p, %d);\n", rom_data, rom_size);\r
        if(PicoCartInsert(rom_data, rom_size)) {\r
                sprintf(menuErrorMsg, "Failed to load ROM.");\r
                return 0;\r
        }\r
 \r
-       // load config for this ROM\r
-       ret = emu_ReadConfig(1);\r
-       if (!ret)\r
-               emu_ReadConfig(0);\r
+       Pico.m.frame_count = 0;\r
+\r
+       // insert CD if it was detected\r
+       if (cd_state > 0) {\r
+               ret = Insert_CD(romFileName, cd_state == 2);\r
+               if (ret != 0) {\r
+                       sprintf(menuErrorMsg, "Insert_CD() failed, invalid CD image?");\r
+                       printf("%s\n", menuErrorMsg);\r
+                       return 0;\r
+               }\r
+       }\r
 \r
        // emu_ReadConfig() might have messed currentConfig.lastRomFile\r
        strncpy(currentConfig.lastRomFile, romFileName, sizeof(currentConfig.lastRomFile)-1);\r
@@ -253,8 +379,6 @@ int emu_ReloadRom(void)
        if(currentConfig.EmuOpt & 1)\r
                emu_SaveLoadGame(1, 1);\r
 \r
-       Pico.m.frame_count = 0;\r
-\r
        return 1;\r
 }\r
 \r
@@ -440,19 +564,14 @@ void osd_text(int x, int y, char *text)
        int len = strlen(text)*8;\r
 \r
        if ((PicoOpt&0x10)||!(currentConfig.EmuOpt&0x80)) {\r
-               int *p, i, h, black, white;\r
-               if (PicoOpt&0x10) {\r
-                       black = 0x40404040; white = 0x41;\r
-               } else {\r
-                       black = 0xe0e0e0e0; white = 0xf0;\r
-               }\r
+               int *p, i, h;\r
                x &= ~3; // align x\r
                len = (len+3) >> 2;\r
                for (h = 0; h < 8; h++) {\r
                        p = (int *) ((unsigned char *) gp2x_screen+x+320*(y+h));\r
-                       for (i = len; i; i--, p++) *p = black;\r
+                       for (i = len; i; i--, p++) *p = 0xe0e0e0e0;\r
                }\r
-               gp2x_text_out8_2(x, y, text, white);\r
+               gp2x_text_out8_2(x, y, text, 0xf0);\r
        } else {\r
                int *p, i, h;\r
                x &= ~1; // align x\r
@@ -465,6 +584,33 @@ void osd_text(int x, int y, char *text)
        }\r
 }\r
 \r
+static void cd_leds(void)\r
+{\r
+       static int old_reg = 0;\r
+       if (!((Pico_mcd->s68k_regs[0] ^ old_reg) & 3)) return; // no change\r
+       old_reg = Pico_mcd->s68k_regs[0];\r
+\r
+       if ((PicoOpt&0x10)||!(currentConfig.EmuOpt&0x80)) {\r
+               // 8-bit modes\r
+               unsigned int col_g = (old_reg & 2) ? 0xc0c0c0c0 : 0xe0e0e0e0;\r
+               unsigned int col_r = (old_reg & 1) ? 0xd0d0d0d0 : 0xe0e0e0e0;\r
+               *(unsigned int *)((char *)gp2x_screen + 320*2+306) =\r
+               *(unsigned int *)((char *)gp2x_screen + 320*3+306) =\r
+               *(unsigned int *)((char *)gp2x_screen + 320*4+306) = col_g;\r
+               *(unsigned int *)((char *)gp2x_screen + 320*2+312) =\r
+               *(unsigned int *)((char *)gp2x_screen + 320*3+312) =\r
+               *(unsigned int *)((char *)gp2x_screen + 320*4+312) = col_r;\r
+       } else {\r
+               // 16-bit modes\r
+               unsigned int *p = (unsigned int *)((short *)gp2x_screen + 320*2+306);\r
+               unsigned int col_g = (old_reg & 2) ? 0x06000600 : 0;\r
+               unsigned int col_r = (old_reg & 1) ? 0xc000c000 : 0;\r
+               *p++ = col_g; *p++ = col_g; p++; *p++ = col_r; *p++ = col_r; p += 320/2 - 10/2;\r
+               *p++ = col_g; *p++ = col_g; p++; *p++ = col_r; *p++ = col_r; p += 320/2 - 10/2;\r
+               *p++ = col_g; *p++ = col_g; p++; *p++ = col_r; *p++ = col_r; p += 320/2 - 10/2;\r
+       }\r
+}\r
+\r
 static int EmuScan16(unsigned int num, void *sdata)\r
 {\r
        if (!(Pico.video.reg[1]&8)) num += 8;\r
@@ -486,6 +632,8 @@ static void (*vidCpyM2)(void *dest, void *src) = NULL;
 \r
 static void blit(char *fps, char *notice)\r
 {\r
+       int emu_opt = currentConfig.EmuOpt;\r
+\r
        if (PicoOpt&0x10) {\r
                // 8bit fast renderer\r
                if (Pico.m.dirtyPal) {\r
@@ -495,7 +643,7 @@ static void blit(char *fps, char *notice)
                        gp2x_video_setpalette(localPal, 0x40);\r
                }\r
                vidCpyM2((unsigned char *)gp2x_screen+320*8, framebuff+328*8);\r
-       } else if (!(currentConfig.EmuOpt&0x80)) {\r
+       } else if (!(emu_opt&0x80)) {\r
                // 8bit accurate renderer\r
                if (Pico.m.dirtyPal) {\r
                        Pico.m.dirtyPal = 0;\r
@@ -504,6 +652,8 @@ static void blit(char *fps, char *notice)
                                vidConvCpyRGB32sh(localPal+0x40, Pico.cram, 0x40);\r
                                vidConvCpyRGB32hi(localPal+0x80, Pico.cram, 0x40);\r
                                blockcpy(localPal+0xc0, localPal+0x40, 0x40*4);\r
+                               localPal[0xc0] = 0x0000c000;\r
+                               localPal[0xd0] = 0x00c00000;\r
                                localPal[0xe0] = 0x00000000; // reserved pixels for OSD\r
                                localPal[0xf0] = 0x00ffffff;\r
                                gp2x_video_setpalette(localPal, 0x100);\r
@@ -520,8 +670,10 @@ static void blit(char *fps, char *notice)
        }\r
 \r
        if (notice) osd_text(4, 232, notice);\r
-       if (currentConfig.EmuOpt & 2)\r
+       if (emu_opt & 2)\r
                osd_text(osd_fps_x, 232, fps);\r
+       if ((emu_opt & 0x400) && (PicoMCD & 1))\r
+               cd_leds();\r
 \r
        //gp2x_video_wait_vsync();\r
        gp2x_video_flip();\r
@@ -543,18 +695,14 @@ static void blit(char *fps, char *notice)
 // clears whole screen or just the notice area (in all buffers)\r
 static void clearArea(int full)\r
 {\r
-       if (PicoOpt&0x10) {\r
-               // 8bit fast renderer\r
-               if (full) gp2x_memset_all_buffers(0, 0x40, 320*240);\r
-               else      gp2x_memset_all_buffers(320*232, 0x40, 320*8);\r
-       } else if (currentConfig.EmuOpt&0x80) {\r
+       if ((PicoOpt&0x10)||!(currentConfig.EmuOpt&0x80)) {\r
+               // 8-bit renderers\r
+               if (full) gp2x_memset_all_buffers(0, 0xe0, 320*240);\r
+               else      gp2x_memset_all_buffers(320*232, 0xe0, 320*8);\r
+       } else {\r
                // 16bit accurate renderer\r
                if (full) gp2x_memset_all_buffers(0, 0, 320*240*2);\r
                else      gp2x_memset_all_buffers(320*232*2, 0, 320*8*2);\r
-       } else {\r
-               // 8bit accurate renderer\r
-               if (full) gp2x_memset_all_buffers(0, 0xe0, 320*240);\r
-               else      gp2x_memset_all_buffers(320*232, 0xe0, 320*8);\r
        }\r
 }\r
 \r
@@ -562,27 +710,27 @@ static void clearArea(int full)
 static void vidResetMode(void)\r
 {\r
        if (PicoOpt&0x10) {\r
-               localPal[0x40] = 0;\r
-               localPal[0x41] = 0x00ffffff;\r
                gp2x_video_changemode(8);\r
-               gp2x_video_setpalette(localPal, 0x42);\r
-               gp2x_memset_all_buffers(0, 0x40, 320*240);\r
-               gp2x_video_flip();\r
        } else if (currentConfig.EmuOpt&0x80) {\r
                gp2x_video_changemode(15);\r
                PicoDrawSetColorFormat(1);\r
                PicoScan = EmuScan16;\r
                PicoScan(0, 0);\r
        } else {\r
+               gp2x_video_changemode(8);\r
+               PicoDrawSetColorFormat(2);\r
+               PicoScan = EmuScan8;\r
+               PicoScan(0, 0);\r
+       }\r
+       if ((PicoOpt&0x10)||!(currentConfig.EmuOpt&0x80)) {\r
+               // setup pal for 8-bit modes\r
+               localPal[0xc0] = 0x0000c000; // MCD LEDs\r
+               localPal[0xd0] = 0x00c00000;\r
                localPal[0xe0] = 0x00000000; // reserved pixels for OSD\r
                localPal[0xf0] = 0x00ffffff;\r
-               gp2x_video_changemode(8);\r
                gp2x_video_setpalette(localPal, 0x100);\r
                gp2x_memset_all_buffers(0, 0xe0, 320*240);\r
                gp2x_video_flip();\r
-               PicoDrawSetColorFormat(2);\r
-               PicoScan = EmuScan8;\r
-               PicoScan(0, 0);\r
        }\r
        Pico.m.dirtyPal = 1;\r
        // reset scaling\r
index 33b1ae7..3c90fdc 100644 (file)
@@ -19,7 +19,8 @@ typedef struct {
        char lastRomFile[512];\r
        int EmuOpt;             // LSb->MSb: use_sram, show_fps, enable_sound, gzip_saves,\r
                                        // squidgehack, save_cfg_on_exit, <unused>, 16_bit_mode\r
-                                       // craigix_ram, confirm_save\r
+                                       // craigix_ram, confirm_save, show_cd_leds, enable_cdda\r
+                                       // enable_pcm\r
        int PicoOpt;  // used for config saving only, see Pico.h\r
        int PsndRate; // ditto\r
        int PicoRegion; // ditto\r
@@ -44,3 +45,5 @@ void emu_Loop(void);
 void emu_ResetGame(void);\r
 int  emu_ReadConfig(int game);\r
 int  emu_WriteConfig(int game);\r
+int  find_bios(int region, char **bios_file);\r
+\r
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
index fc6b200..e4d5480 100644 (file)
@@ -30,7 +30,7 @@ OBJS += ../../Pico/Area.o ../../Pico/Cart.o ../../Pico/Utils.o ../../Pico/Memory
                ../../Pico/Pico.o ../../Pico/Sek.o ../../Pico/VideoPort.o ../../Pico/Draw2.o ../../Pico/Draw.o
 # Pico - CD
 OBJS += ../../Pico/cd/Pico.o ../../Pico/cd/Memory.o ../../Pico/cd/Sek.o ../../Pico/cd/LC89510.o \
-               ../../Pico/cd/cd_sys.o
+               ../../Pico/cd/cd_sys.o ../../Pico/cd/cd_file.o
 # Pico - sound
 OBJS += ../../Pico/sound/sound.o ../../Pico/sound/sn76496.o ../../Pico/sound/ym2612.o
 # zlib