Cd *cf_parse (char *name, int *format) { FILE *fp = NULL; Cd *cd = NULL; if (UNKNOWN == *format) if (UNKNOWN == (*format = cf_format_from_suffix(name))) { fprintf(stderr, "%s: unknown format\n", name); return NULL; } if (0 == strcmp("-", name)) { fp = stdin; } else if (NULL == (fp = fopen(name, "r"))) { fprintf(stderr, "%s: error opening file\n", name); return NULL; } switch (*format) { case CUE: cd = cue_parse(fp); break; case TOC: cd = toc_parse(fp); break; } if(stdin != fp) fclose(fp); return cd; }
PICO_INTERNAL int Load_CD_Image(const char *cd_img_name, cd_img_type type) { int i, j, num_track, Cur_LBA, index, ret; int iso_name_len, missed, cd_img_sectors; _scd_track *Tracks = Pico_mcd->TOC.Tracks; char tmp_name[256], tmp_ext[10], tmp_ext_u[10]; cue_data_t *cue_data = NULL; pm_file *pmf; static const char *exts[] = { "%02d.mp3", " %02d.mp3", "-%02d.mp3", "_%02d.mp3", " - %02d.mp3", "%d.mp3", " %d.mp3", "-%d.mp3", "_%d.mp3", " - %d.mp3", }; if (PicoCDLoadProgressCB != NULL) PicoCDLoadProgressCB(cd_img_name, 1); Unload_ISO(); /* is this a .cue? */ cue_data = cue_parse(cd_img_name); if (cue_data != NULL) { cd_img_name = cue_data->tracks[1].fname; Tracks[0].ftype = cue_data->tracks[1].type; } else Tracks[0].ftype = type == CIT_BIN ? CT_BIN : CT_ISO; Tracks[0].F = pmf = pm_open(cd_img_name); if (Tracks[0].F == NULL) { Tracks[0].ftype = 0; Tracks[0].Length = 0; if (cue_data != NULL) cue_destroy(cue_data); return -1; } if (Tracks[0].ftype == CT_ISO) cd_img_sectors = pmf->size >>= 11; // size in sectors else cd_img_sectors = pmf->size /= 2352;
/* 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; // opens a cue, or searches for one cue_data = cue_parse(fname_in); if (cue_data != NULL) { fname = cue_data->tracks[1].fname; type = cue_data->tracks[1].type; } else { get_ext(fname_in, ext); if (strcasecmp(ext, ".cue") == 0) 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; }