--- /dev/null
+/*
+ * PicoDrive
+ * (C) notaz, 2006-2010,2013
+ *
+ * This work is licensed under the terms of MAME license.
+ * See COPYING file in the top-level directory.
+ */
+
+#include <string.h>
+#include "pico_int.h"
+#include "cd/cue.h"
+
+unsigned char media_id_header[0x100];
+
+static void strlwr_(char *string)
+{
+ char *p;
+ for (p = string; *p; p++)
+ if ('A' <= *p && *p <= 'Z')
+ *p += 'a' - 'A';
+}
+
+static void get_ext(const char *file, char *ext)
+{
+ const char *p;
+
+ p = file + strlen(file) - 4;
+ if (p < file) p = file;
+ strncpy(ext, p, 4);
+ ext[4] = 0;
+ strlwr_(ext);
+}
+
+static int detect_media(const char *fname)
+{
+ static const short sms_offsets[] = { 0x7ff0, 0x3ff0, 0x1ff0 };
+ static const char *sms_exts[] = { "sms", "gg", "sg" };
+ static const char *md_exts[] = { "gen", "bin", "smd" };
+ char buff0[32], buff[32];
+ unsigned short *d16;
+ pm_file *pmf;
+ char ext[5];
+ int i;
+
+ get_ext(fname, ext);
+
+ // detect wrong extensions
+ if (!strcmp(ext, ".srm") || !strcmp(ext, "s.gz") || !strcmp(ext, ".mds")) // s.gz ~ .mds.gz
+ return PM_BAD_DETECT;
+
+ /* don't believe in extensions, except .cue */
+ if (strcasecmp(ext, ".cue") == 0)
+ return PM_CD;
+
+ pmf = pm_open(fname);
+ if (pmf == NULL)
+ return PM_BAD_DETECT;
+
+ if (pm_read(buff0, 32, pmf) != 32) {
+ pm_close(pmf);
+ return PM_BAD_DETECT;
+ }
+
+ if (strncasecmp("SEGADISCSYSTEM", buff0 + 0x00, 14) == 0 ||
+ strncasecmp("SEGADISCSYSTEM", buff0 + 0x10, 14) == 0) {
+ pm_close(pmf);
+ return PM_CD;
+ }
+
+ /* check for SMD evil */
+ if (pmf->size >= 0x4200 && (pmf->size & 0x3fff) == 0x200) {
+ if (pm_seek(pmf, sms_offsets[0] + 0x200, SEEK_SET) == sms_offsets[0] + 0x200 &&
+ pm_read(buff, 16, pmf) == 16 &&
+ strncmp("TMR SEGA", buff, 8) == 0)
+ goto looks_like_sms;
+
+ /* could parse further but don't bother */
+ goto extension_check;
+ }
+
+ /* MD header? Act as TMSS BIOS here */
+ if (pm_seek(pmf, 0x100, SEEK_SET) == 0x100 && pm_read(buff, 16, pmf) == 16) {
+ if (strncmp(buff, "SEGA", 4) == 0 || strncmp(buff, " SEG", 4) == 0)
+ goto looks_like_md;
+ }
+
+ for (i = 0; i < ARRAY_SIZE(sms_offsets); i++) {
+ if (pm_seek(pmf, sms_offsets[i], SEEK_SET) != sms_offsets[i])
+ continue;
+
+ if (pm_read(buff, 16, pmf) != 16)
+ continue;
+
+ if (strncmp("TMR SEGA", buff, 8) == 0)
+ goto looks_like_sms;
+ }
+
+extension_check:
+ /* probably some headerless thing. Maybe check the extension after all. */
+ for (i = 0; i < ARRAY_SIZE(md_exts); i++)
+ if (strcasecmp(pmf->ext, md_exts[i]) == 0)
+ goto looks_like_md;
+
+ for (i = 0; i < ARRAY_SIZE(sms_exts); i++)
+ if (strcasecmp(pmf->ext, sms_exts[i]) == 0)
+ goto looks_like_sms;
+
+ /* If everything else fails, make a guess on the reset vector */
+ d16 = (unsigned short *)(buff0 + 4);
+ if ((((d16[0] << 16) | d16[1]) & 0xffffff) >= pmf->size) {
+ lprintf("bad MD reset vector, assuming SMS\n");
+ goto looks_like_sms;
+ }
+
+looks_like_md:
+ pm_close(pmf);
+ return PM_MD_CART;
+
+looks_like_sms:
+ pm_close(pmf);
+ return PM_MARK3;
+}
+
+/* checks if fname points to valid MegaCD image */
+int PicoCdCheck(const char *fname_in, int *pregion)
+{
+ const char *fname = fname_in;
+ unsigned char buf[32];
+ pm_file *cd_f;
+ int region = 4; // 1: Japan, 4: US, 8: Europe
+ char ext[5];
+ cue_track_type type = CT_UNKNOWN;
+ cue_data_t *cue_data = NULL;
+
+ get_ext(fname_in, ext);
+ if (strcasecmp(ext, ".cue") == 0) {
+ cue_data = cue_parse(fname_in);
+ if (cue_data != NULL) {
+ fname = cue_data->tracks[1].fname;
+ type = cue_data->tracks[1].type;
+ }
+ else
+ return -1;
+ }
+
+ cd_f = pm_open(fname);
+ if (cue_data != NULL)
+ cue_destroy(cue_data);
+
+ if (cd_f == NULL) return 0; // let the upper level handle this
+
+ if (pm_read(buf, 32, cd_f) != 32) {
+ pm_close(cd_f);
+ return -1;
+ }
+
+ if (!strncasecmp("SEGADISCSYSTEM", (char *)buf+0x00, 14)) {
+ if (type && type != CT_ISO)
+ elprintf(EL_STATUS, ".cue has wrong type: %i", type);
+ type = CT_ISO; // Sega CD (ISO)
+ }
+ if (!strncasecmp("SEGADISCSYSTEM", (char *)buf+0x10, 14)) {
+ if (type && type != CT_BIN)
+ elprintf(EL_STATUS, ".cue has wrong type: %i", type);
+ type = CT_BIN; // Sega CD (BIN)
+ }
+
+ if (type == CT_UNKNOWN) {
+ pm_close(cd_f);
+ return 0;
+ }
+
+ pm_seek(cd_f, (type == CT_ISO) ? 0x100 : 0x110, SEEK_SET);
+ pm_read(media_id_header, sizeof(media_id_header), cd_f);
+
+ /* it seems we have a CD image here. Try to detect region now.. */
+ pm_seek(cd_f, (type == CT_ISO) ? 0x100+0x10B : 0x110+0x10B, SEEK_SET);
+ pm_read(buf, 1, cd_f);
+ pm_close(cd_f);
+
+ if (buf[0] == 0x64) region = 8; // EU
+ if (buf[0] == 0xa1) region = 1; // JAP
+
+ lprintf("detected %s Sega/Mega CD image with %s region\n",
+ type == CT_BIN ? "BIN" : "ISO", region != 4 ? (region == 8 ? "EU" : "JAP") : "USA");
+
+ if (pregion != NULL)
+ *pregion = region;
+
+ return type;
+}
+
+enum media_type_e PicoLoadMedia(const char *filename,
+ const char *carthw_cfg_fname,
+ const char *(*get_bios_filename)(int *region, const char *cd_fname),
+ void (*do_region_override)(const char *media_filename))
+{
+ const char *rom_fname = filename;
+ enum media_type_e media_type;
+ cd_img_type cd_img_type = CIT_NOT_CD;
+ unsigned char *rom_data = NULL;
+ unsigned int rom_size = 0;
+ pm_file *rom = NULL;
+ int cd_region = 0;
+ int ret;
+
+ media_type = detect_media(filename);
+ if (media_type == PM_BAD_DETECT)
+ goto out;
+
+ if ((PicoAHW & PAHW_MCD) && Pico_mcd != NULL)
+ Stop_CD();
+ PicoCartUnload();
+ PicoAHW = 0;
+
+ if (media_type == PM_CD)
+ {
+ // check for MegaCD image
+ cd_img_type = PicoCdCheck(filename, &cd_region);
+ if (cd_img_type >= 0 && cd_img_type != CIT_NOT_CD)
+ {
+ // valid CD image, ask frontend for BIOS..
+ rom_fname = NULL;
+ if (get_bios_filename != NULL)
+ rom_fname = get_bios_filename(&cd_region, filename);
+ if (rom_fname == NULL) {
+ media_type = PM_BAD_CD_NO_BIOS;
+ goto out;
+ }
+
+ PicoAHW |= PAHW_MCD;
+ }
+ else {
+ media_type = PM_BAD_CD;
+ goto out;
+ }
+ }
+ else if (media_type == PM_MARK3) {
+ lprintf("detected SMS ROM\n");
+ PicoAHW = PAHW_SMS;
+ }
+
+ rom = pm_open(rom_fname);
+ if (rom == NULL) {
+ lprintf("Failed to open ROM");
+ media_type = PM_ERROR;
+ goto out;
+ }
+
+ ret = PicoCartLoad(rom, &rom_data, &rom_size, (PicoAHW & PAHW_SMS) ? 1 : 0);
+ pm_close(rom);
+ if (ret != 0) {
+ if (ret == 2) lprintf("Out of memory");
+ else if (ret == 3) lprintf("Read failed");
+ else lprintf("PicoCartLoad() failed.");
+ media_type = PM_ERROR;
+ goto out;
+ }
+
+ // detect wrong files
+ if (strncmp((char *)rom_data, "Pico", 4) == 0) {
+ lprintf("savestate selected?\n");
+ media_type = PM_BAD_DETECT;
+ goto out;
+ }
+
+ if (!(PicoAHW & PAHW_SMS)) {
+ unsigned short *d = (unsigned short *)(rom_data + 4);
+ if ((((d[0] << 16) | d[1]) & 0xffffff) >= (int)rom_size) {
+ lprintf("bad reset vector\n");
+ media_type = PM_BAD_DETECT;
+ goto out;
+ }
+ }
+
+ // load config for this ROM (do this before insert to get correct region)
+ if (!(PicoAHW & PAHW_MCD)) {
+ memcpy(media_id_header, rom_data + 0x100, sizeof(media_id_header));
+ if (do_region_override != NULL)
+ do_region_override(filename);
+ }
+
+ if (PicoCartInsert(rom_data, rom_size, carthw_cfg_fname)) {
+ media_type = PM_ERROR;
+ goto out;
+ }
+ rom_data = NULL; // now belongs to PicoCart
+
+ // insert CD if it was detected
+ if (cd_img_type != CIT_NOT_CD) {
+ ret = Insert_CD(filename, cd_img_type);
+ if (ret != 0) {
+ PicoCartUnload();
+ media_type = PM_BAD_CD;
+ goto out;
+ }
+ }
+
+out:
+ if (rom_data)
+ free(rom_data);
+ return media_type;
+}
+
+// vim:shiftwidth=2:ts=2:expandtab
\r
#include <stdio.h>\r
#include <stdlib.h>\r
+#include <string.h>\r
#include <stdarg.h>\r
#ifndef NO_SYNC\r
#include <unistd.h>\r
\r
#include <pico/pico_int.h>\r
#include <pico/patch.h>\r
-#include <pico/cd/cue.h>\r
\r
\r
#define STATUS_MSG_TIMEOUT 2000\r
static char static_buff[512];\r
const char *rom_fname_reload;\r
char rom_fname_loaded[512];\r
-int rom_loaded = 0;\r
int reset_timing = 0;\r
static unsigned int notice_msg_time; /* when started showing */\r
static char noticeMsg[40];\r
static const char * const biosfiles_eu[] = { "eu_mcd1_9210", "eu_mcd2_9306", "eu_mcd2_9303" };\r
static const char * const biosfiles_jp[] = { "jp_mcd1_9112", "jp_mcd1_9111" };\r
\r
-static int find_bios(int region, const char **bios_file)\r
+static const char *find_bios(int *region, const char *cd_fname)\r
{\r
int i, count;\r
const char * const *files;\r
FILE *f = NULL;\r
+ int ret;\r
+\r
+ // we need to have config loaded at this point\r
+ ret = emu_read_config(cd_fname, 0);\r
+ if (!ret) emu_read_config(NULL, 0);\r
+\r
+ if (PicoRegionOverride) {\r
+ *region = PicoRegionOverride;\r
+ lprintf("override region to %s\n", *region != 4 ?\r
+ (*region == 8 ? "EU" : "JAP") : "USA");\r
+ }\r
\r
- if (region == 4) { // US\r
+ if (*region == 4) { // US\r
files = biosfiles_us;\r
count = sizeof(biosfiles_us) / sizeof(char *);\r
- } else if (region == 8) { // EU\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
+ } else if (*region == 1 || *region == 2) {\r
files = biosfiles_jp;\r
count = sizeof(biosfiles_jp) / sizeof(char *);\r
} else {\r
if (f) {\r
lprintf("using bios: %s\n", static_buff);\r
fclose(f);\r
- if (bios_file)\r
- *bios_file = static_buff;\r
- return 1;\r
+ return static_buff;\r
} else {\r
sprintf(static_buff, "no %s BIOS files found, read docs",\r
- region != 4 ? (region == 8 ? "EU" : "JAP") : "USA");\r
+ *region != 4 ? (*region == 8 ? "EU" : "JAP") : "USA");\r
menu_update_msg(static_buff);\r
- return 0;\r
+ return NULL;\r
}\r
}\r
\r
}\r
*/\r
\r
-static unsigned char id_header[0x100];\r
-\r
-/* checks if fname points to valid MegaCD image */\r
-static int emu_cd_check(int *pregion, const char *fname_in)\r
-{\r
- const char *fname = fname_in;\r
- unsigned char buf[32];\r
- pm_file *cd_f;\r
- int region = 4; // 1: Japan, 4: US, 8: Europe\r
- char ext[5];\r
- cue_track_type type = CT_UNKNOWN;\r
- cue_data_t *cue_data = NULL;\r
-\r
- get_ext(fname_in, ext);\r
- if (strcasecmp(ext, ".cue") == 0) {\r
- cue_data = cue_parse(fname_in);\r
- if (cue_data != NULL) {\r
- 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 == 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 -1;\r
- }\r
-\r
- if (!strncasecmp("SEGADISCSYSTEM", (char *)buf+0x00, 14)) {\r
- if (type && type != CT_ISO)\r
- elprintf(EL_STATUS, ".cue has wrong type: %i", type);\r
- type = CT_ISO; // Sega CD (ISO)\r
- }\r
- if (!strncasecmp("SEGADISCSYSTEM", (char *)buf+0x10, 14)) {\r
- if (type && type != CT_BIN)\r
- elprintf(EL_STATUS, ".cue has wrong type: %i", type);\r
- type = CT_BIN; // Sega CD (BIN)\r
- }\r
-\r
- if (type == CT_UNKNOWN) {\r
- pm_close(cd_f);\r
- return 0;\r
- }\r
-\r
- pm_seek(cd_f, (type == CT_ISO) ? 0x100 : 0x110, SEEK_SET);\r
- pm_read(id_header, sizeof(id_header), cd_f);\r
-\r
- /* it seems we have a CD image here. Try to detect region now.. */\r
- pm_seek(cd_f, (type == CT_ISO) ? 0x100+0x10B : 0x110+0x10B, SEEK_SET);\r
- pm_read(buf, 1, cd_f);\r
- pm_close(cd_f);\r
-\r
- if (buf[0] == 0x64) region = 8; // EU\r
- if (buf[0] == 0xa1) region = 1; // JAP\r
-\r
- lprintf("detected %s Sega/Mega CD image with %s region\n",\r
- type == CT_BIN ? "BIN" : "ISO", region != 4 ? (region == 8 ? "EU" : "JAP") : "USA");\r
-\r
- if (pregion != NULL) *pregion = region;\r
-\r
- return type;\r
-}\r
-\r
-static int detect_media(const char *fname)\r
-{\r
- static const short sms_offsets[] = { 0x7ff0, 0x3ff0, 0x1ff0 };\r
- static const char *sms_exts[] = { "sms", "gg", "sg" };\r
- static const char *md_exts[] = { "gen", "bin", "smd" };\r
- char buff0[32], buff[32];\r
- unsigned short *d16;\r
- pm_file *pmf;\r
- char ext[5];\r
- int i;\r
-\r
- get_ext(fname, ext);\r
-\r
- // detect wrong extensions\r
- if (!strcmp(ext, ".srm") || !strcmp(ext, "s.gz") || !strcmp(ext, ".mds")) // s.gz ~ .mds.gz\r
- return PM_BAD;\r
-\r
- /* don't believe in extensions, except .cue */\r
- if (strcasecmp(ext, ".cue") == 0)\r
- return PM_CD;\r
-\r
- pmf = pm_open(fname);\r
- if (pmf == NULL)\r
- return PM_BAD;\r
-\r
- if (pm_read(buff0, 32, pmf) != 32) {\r
- pm_close(pmf);\r
- return PM_BAD;\r
- }\r
-\r
- if (strncasecmp("SEGADISCSYSTEM", buff0 + 0x00, 14) == 0 ||\r
- strncasecmp("SEGADISCSYSTEM", buff0 + 0x10, 14) == 0) {\r
- pm_close(pmf);\r
- return PM_CD;\r
- }\r
-\r
- /* check for SMD evil */\r
- if (pmf->size >= 0x4200 && (pmf->size & 0x3fff) == 0x200) {\r
- if (pm_seek(pmf, sms_offsets[0] + 0x200, SEEK_SET) == sms_offsets[0] + 0x200 &&\r
- pm_read(buff, 16, pmf) == 16 &&\r
- strncmp("TMR SEGA", buff, 8) == 0)\r
- goto looks_like_sms;\r
-\r
- /* could parse further but don't bother */\r
- goto extension_check;\r
- }\r
-\r
- /* MD header? Act as TMSS BIOS here */\r
- if (pm_seek(pmf, 0x100, SEEK_SET) == 0x100 && pm_read(buff, 16, pmf) == 16) {\r
- if (strncmp(buff, "SEGA", 4) == 0 || strncmp(buff, " SEG", 4) == 0)\r
- goto looks_like_md;\r
- }\r
-\r
- for (i = 0; i < array_size(sms_offsets); i++) {\r
- if (pm_seek(pmf, sms_offsets[i], SEEK_SET) != sms_offsets[i])\r
- continue;\r
-\r
- if (pm_read(buff, 16, pmf) != 16)\r
- continue;\r
-\r
- if (strncmp("TMR SEGA", buff, 8) == 0)\r
- goto looks_like_sms;\r
- }\r
-\r
-extension_check:\r
- /* probably some headerless thing. Maybe check the extension after all. */\r
- for (i = 0; i < array_size(md_exts); i++)\r
- if (strcasecmp(pmf->ext, md_exts[i]) == 0)\r
- goto looks_like_md;\r
-\r
- for (i = 0; i < array_size(sms_exts); i++)\r
- if (strcasecmp(pmf->ext, sms_exts[i]) == 0)\r
- goto looks_like_sms;\r
-\r
- /* If everything else fails, make a guess on the reset vector */\r
- d16 = (unsigned short *)(buff0 + 4);\r
- if ((((d16[0] << 16) | d16[1]) & 0xffffff) >= pmf->size) {\r
- lprintf("bad MD reset vector, assuming SMS\n");\r
- goto looks_like_sms;\r
- }\r
-\r
-looks_like_md:\r
- pm_close(pmf);\r
- return PM_MD_CART;\r
-\r
-looks_like_sms:\r
- pm_close(pmf);\r
- return PM_MARK3;\r
-}\r
-\r
static int extract_text(char *dest, const unsigned char *src, int len, int swab)\r
{\r
char *p = dest;\r
pos = 3;\r
\r
if (!(PicoAHW & PAHW_SMS)) {\r
- pos += extract_text(id_string + pos, id_header + 0x80, 0x0e, swab); // serial\r
+ pos += extract_text(id_string + pos, media_id_header + 0x80, 0x0e, swab); // serial\r
id_string[pos] = '|'; pos++;\r
- pos += extract_text(id_string + pos, id_header + 0xf0, 0x03, swab); // region\r
+ pos += extract_text(id_string + pos, media_id_header + 0xf0, 0x03, swab); // region\r
id_string[pos] = '|'; pos++;\r
- pos += extract_text(id_string + pos, id_header + 0x50, 0x30, swab); // overseas name\r
+ pos += extract_text(id_string + pos, media_id_header + 0x50, 0x30, swab); // overseas name\r
id_string[pos] = 0;\r
if (pos > 5)\r
return id_string;\r
int ret, swab = (PicoAHW & PAHW_MCD) ? 0 : 1;\r
char *s, *d;\r
\r
- ret = extract_text(str150, id_header + 0x50, 0x30, swab); // overseas name\r
+ ret = extract_text(str150, media_id_header + 0x50, 0x30, swab); // overseas name\r
\r
for (s = d = str150 + 1; s < str150+ret; s++)\r
{\r
*d = 0;\r
}\r
\r
-static void shutdown_MCD(void)\r
-{\r
- if ((PicoAHW & PAHW_MCD) && Pico_mcd != NULL)\r
- Stop_CD();\r
- PicoAHW &= ~PAHW_MCD;\r
-}\r
-\r
static void system_announce(void)\r
{\r
const char *sys_name, *tv_standard, *extra = "";\r
emu_status_msg("%s %s / %dFPS%s", tv_standard, sys_name, fps, extra);\r
}\r
\r
-// XXX: portions of this code should move to pico/\r
+static void do_region_override(const char *media_fname)\r
+{\r
+ // we only need to override region if config tells us so\r
+ int ret = emu_read_config(media_fname, 0);\r
+ if (!ret) emu_read_config(NULL, 0);\r
+}\r
+\r
int emu_reload_rom(const char *rom_fname_in)\r
{\r
- unsigned int rom_size = 0;\r
- const char *used_rom_name = NULL;\r
char *rom_fname = NULL;\r
- unsigned char *rom_data = NULL;\r
char ext[5];\r
- pm_file *rom = NULL;\r
- int cd_state = CIT_NOT_CD;\r
- int ret, media_type, cd_region;\r
- int cfg_loaded = 0, bad_rom = 0;\r
+ enum media_type_e media_type;\r
int menu_romload_started = 0;\r
+ char carthw_path[512];\r
int retval = 0;\r
\r
lprintf("emu_ReloadRom(%s)\n", rom_fname_in);\r
if (rom_fname == NULL)\r
return 0;\r
\r
- used_rom_name = rom_fname;\r
get_ext(rom_fname, ext);\r
\r
// early cleanup\r
get_ext(rom_fname, ext);\r
}\r
\r
- media_type = detect_media(rom_fname);\r
- if (media_type == PM_BAD) {\r
- menu_update_msg("Not a ROM/CD img selected.");\r
- goto out;\r
- }\r
-\r
- shutdown_MCD();\r
- PicoCartUnload();\r
- rom_loaded = 0;\r
-\r
- PicoAHW = 0;\r
-\r
- if (media_type == PM_CD)\r
- {\r
- // check for MegaCD image\r
- cd_state = emu_cd_check(&cd_region, rom_fname);\r
- if (cd_state >= 0 && cd_state != CIT_NOT_CD)\r
- {\r
- // valid CD image, check for BIOS..\r
+ menu_romload_prepare(rom_fname); // also CD load\r
+ menu_romload_started = 1;\r
\r
- // we need to have config loaded at this point\r
- ret = emu_read_config(rom_fname, 0);\r
- if (!ret) emu_read_config(NULL, 0);\r
- cfg_loaded = 1;\r
+ emu_make_path(carthw_path, "carthw.cfg", sizeof(carthw_path));\r
\r
- if (PicoRegionOverride) {\r
- cd_region = PicoRegionOverride;\r
- lprintf("override region to %s\n", cd_region != 4 ?\r
- (cd_region == 8 ? "EU" : "JAP") : "USA");\r
- }\r
- if (!find_bios(cd_region, &used_rom_name))\r
- goto out;\r
+ media_type = PicoLoadMedia(rom_fname, carthw_path,\r
+ find_bios, do_region_override);\r
\r
- get_ext(used_rom_name, ext);\r
- PicoAHW |= PAHW_MCD;\r
- }\r
- else {\r
- menu_update_msg("Invalid CD image");\r
- goto out;\r
- }\r
- }\r
- else if (media_type == PM_MARK3) {\r
- lprintf("detected SMS ROM\n");\r
- PicoAHW = PAHW_SMS;\r
- }\r
-\r
- rom = pm_open(used_rom_name);\r
- if (rom == NULL) {\r
- menu_update_msg("Failed to open ROM");\r
+ switch (media_type) {\r
+ case PM_BAD_DETECT:\r
+ menu_update_msg("Not a ROM/CD img selected.");\r
goto out;\r
- }\r
-\r
- menu_romload_prepare(used_rom_name); // also CD load\r
- menu_romload_started = 1;\r
- used_rom_name = NULL; // uses static_buff\r
-\r
- ret = PicoCartLoad(rom, &rom_data, &rom_size, (PicoAHW & PAHW_SMS) ? 1 : 0);\r
- pm_close(rom);\r
- if (ret != 0) {\r
- if (ret == 2) menu_update_msg("Out of memory");\r
- else if (ret == 3) menu_update_msg("Read failed");\r
- else menu_update_msg("PicoCartLoad() failed.");\r
+ case PM_BAD_CD:\r
+ menu_update_msg("Invalid CD image");\r
goto out;\r
- }\r
-\r
- // detect wrong files\r
- if (strncmp((char *)rom_data, "Pico", 4) == 0)\r
- bad_rom = 1;\r
- else if (!(PicoAHW & PAHW_SMS)) {\r
- unsigned short *d = (unsigned short *)(rom_data + 4);\r
- if ((((d[0] << 16) | d[1]) & 0xffffff) >= (int)rom_size) {\r
- lprintf("bad reset vector\n");\r
- bad_rom = 1;\r
- }\r
- }\r
-\r
- if (bad_rom) {\r
- menu_update_msg("Bad ROM detected.");\r
+ case PM_BAD_CD_NO_BIOS:\r
+ // find_bios() prints a message\r
goto out;\r
- }\r
-\r
- // load config for this ROM (do this before insert to get correct region)\r
- if (!(PicoAHW & PAHW_MCD))\r
- memcpy(id_header, rom_data + 0x100, sizeof(id_header));\r
- if (!cfg_loaded) {\r
- ret = emu_read_config(rom_fname, 0);\r
- if (!ret) emu_read_config(NULL, 0);\r
- }\r
-\r
- emu_make_path(static_buff, "carthw.cfg", sizeof(static_buff));\r
- if (PicoCartInsert(rom_data, rom_size, static_buff)) {\r
- menu_update_msg("Failed to load ROM.");\r
+ case PM_ERROR:\r
+ menu_update_msg("Load error");\r
goto out;\r
- }\r
-\r
- // insert CD if it was detected\r
- if (cd_state != CIT_NOT_CD) {\r
- ret = Insert_CD(rom_fname, cd_state);\r
- if (ret != 0) {\r
- PicoCartUnload();\r
- rom_data = NULL; // freed by unload\r
- menu_update_msg("Insert_CD() failed, invalid CD image?");\r
- goto out;\r
- }\r
+ default:\r
+ break;\r
}\r
\r
menu_romload_end();\r
\r
strncpy(rom_fname_loaded, rom_fname, sizeof(rom_fname_loaded)-1);\r
rom_fname_loaded[sizeof(rom_fname_loaded)-1] = 0;\r
- rom_loaded = 1;\r
\r
// load SRAM for this ROM\r
if (currentConfig.EmuOpt & EOPT_EN_SRAM)\r
\r
retval = 1;\r
out:\r
- if (retval == 0 && rom_data)\r
- free(rom_data);\r
if (menu_romload_started)\r
menu_romload_end();\r
free(rom_fname);\r
cd_img_type cd_type;\r
int ret = -1;\r
\r
- cd_type = emu_cd_check(NULL, fname);\r
+ cd_type = PicoCdCheck(fname, NULL);\r
if (cd_type != CIT_NOT_CD)\r
ret = Insert_CD(fname, cd_type);\r
if (ret != 0) {\r