fname = cue_data->tracks[1].fname;\r
type = cue_data->tracks[1].type;\r
}\r
+ else\r
+ return -1;\r
}\r
\r
cd_f = pm_open(fname);\r
if (cue_data != NULL)\r
cue_destroy(cue_data);\r
\r
- if (!cd_f) return 0; // let the upper level handle this\r
+ if (cd_f == NULL) return 0; // let the upper level handle this\r
\r
if (pm_read(buf, 32, cd_f) != 32) {\r
pm_close(cd_f);\r
- return 0;\r
+ return -1;\r
}\r
\r
if (!strncasecmp("SEGADISCSYSTEM", (char *)buf+0x00, 14)) {\r
char *used_rom_name = romFileName;\r
unsigned char *rom_data = NULL;\r
char ext[5];\r
- pm_file *rom;\r
+ pm_file *rom = NULL;\r
int ret, cd_state, cd_region, cfg_loaded = 0;\r
\r
lprintf("emu_ReloadRom(%s)\n", romFileName);\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
+ sprintf(menuErrorMsg, "Not a ROM/CD selected.");\r
return 0;\r
}\r
\r
\r
// check for MegaCD image\r
cd_state = emu_cdCheck(&cd_region);\r
- if (cd_state != CIT_NOT_CD)\r
+ if (cd_state >= 0 && cd_state != CIT_NOT_CD)\r
{\r
PicoAHW |= PAHW_MCD;\r
// valid CD image, check for BIOS..\r
\r
rom = pm_open(used_rom_name);\r
if (!rom) {\r
- sprintf(menuErrorMsg, "Failed to open rom.");\r
- return 0;\r
+ sprintf(menuErrorMsg, "Failed to open ROM/CD image");\r
+ goto fail;\r
+ }\r
+\r
+ if (cd_state < 0) {\r
+ sprintf(menuErrorMsg, "Invalid CD image");\r
+ goto fail;\r
}\r
\r
menu_romload_prepare(used_rom_name); // also CD load\r
if ( (ret = PicoCartLoad(rom, &rom_data, &rom_size)) ) {\r
sprintf(menuErrorMsg, "PicoCartLoad() failed.");\r
lprintf("%s\n", menuErrorMsg);\r
- pm_close(rom);\r
- menu_romload_end();\r
- return 0;\r
+ goto fail2;\r
}\r
pm_close(rom);\r
+ rom = NULL;\r
\r
// detect wrong files (Pico crashes on very small files), also see if ROM EP is good\r
if (rom_size <= 0x200 || strncmp((char *)rom_data, "Pico", 4) == 0 ||\r
((*(unsigned char *)(rom_data+4)<<16)|(*(unsigned short *)(rom_data+6))) >= (int)rom_size) {\r
if (rom_data) free(rom_data);\r
sprintf(menuErrorMsg, "Not a ROM selected.");\r
- menu_romload_end();\r
- return 0;\r
+ goto fail2;\r
}\r
\r
// load config for this ROM (do this before insert to get correct region)\r
lprintf("PicoCartInsert(%p, %d);\n", rom_data, rom_size);\r
if (PicoCartInsert(rom_data, rom_size)) {\r
sprintf(menuErrorMsg, "Failed to load ROM.");\r
- menu_romload_end();\r
- return 0;\r
+ goto fail2;\r
}\r
\r
// insert CD if it was detected\r
if (ret != 0) {\r
sprintf(menuErrorMsg, "Insert_CD() failed, invalid CD image?");\r
lprintf("%s\n", menuErrorMsg);\r
- menu_romload_end();\r
- return 0;\r
+ goto fail2;\r
}\r
}\r
\r
}\r
\r
// additional movie stuff\r
- if (movie_data) {\r
- if(movie_data[0x14] == '6')\r
+ if (movie_data)\r
+ {\r
+ if (movie_data[0x14] == '6')\r
PicoOpt |= POPT_6BTN_PAD; // 6 button pad\r
else PicoOpt &= ~POPT_6BTN_PAD;\r
PicoOpt |= POPT_DIS_VDP_FIFO; // no VDP fifo timing\r
- if(movie_data[0xF] >= 'A') {\r
- if(movie_data[0x16] & 0x80) {\r
+ if (movie_data[0xF] >= 'A') {\r
+ if (movie_data[0x16] & 0x80) {\r
PicoRegionOverride = 8;\r
} else {\r
PicoRegionOverride = 4;\r
else\r
{\r
PicoOpt &= ~POPT_DIS_VDP_FIFO;\r
- if(Pico.m.pal) {\r
+ if (Pico.m.pal) {\r
strcpy(noticeMsg, "PAL SYSTEM / 50 FPS");\r
} else {\r
strcpy(noticeMsg, "NTSC SYSTEM / 60 FPS");\r
lastRomFile[sizeof(lastRomFile)-1] = 0;\r
rom_loaded = 1;\r
return 1;\r
+\r
+fail2:\r
+ menu_romload_end();\r
+fail:\r
+ if (rom != NULL) pm_close(rom);\r
+ return 0;\r
}\r
\r
\r