static bool disk_set_image_index(unsigned int index) { enum cd_img_type cd_type; int ret; if (index >= sizeof(disks) / sizeof(disks[0])) return false; if (disks[index].fname == NULL) { if (log_cb) log_cb(RETRO_LOG_ERROR, "missing disk #%u\n", index); // RetroArch specifies "no disk" with index == count, // so don't fail here.. disk_current_index = index; return true; } if (log_cb) log_cb(RETRO_LOG_INFO, "switching to disk %u: \"%s\"\n", index, disks[index].fname); ret = -1; cd_type = PicoCdCheck(disks[index].fname, NULL); if (cd_type != CIT_NOT_CD) ret = cdd_load(disks[index].fname, cd_type); if (ret != 0) { if (log_cb) log_cb(RETRO_LOG_ERROR, "Load failed, invalid CD image?\n"); return 0; } disk_current_index = index; return true; }
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; enum 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) cdd_unload(); PicoCartUnload(); PicoAHW = 0; PicoQuirks = 0; if (media_type == PM_CD) { // check for MegaCD image cd_img_type = PicoCdCheck(filename, &cd_region); if ((int)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\n"); 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\n"); else if (ret == 3) lprintf("Read failed\n"); else lprintf("PicoCartLoad() failed.\n"); 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 Pico.m.ncart_in = 0; // insert CD if it was detected if (cd_img_type != CIT_NOT_CD) { ret = cdd_load(filename, cd_img_type); if (ret != 0) { PicoCartUnload(); media_type = PM_BAD_CD; goto out; } Pico.m.ncart_in = 1; } if (PicoQuirks & PQUIRK_FORCE_6BTN) PicoSetInputDevice(0, PICO_INPUT_PAD_6BTN); out: if (rom_data) free(rom_data); return media_type; }
/**************************************************************************** * LoadFile * * This function will load a game file into the ROM buffer. * This functions return the actual size of data copied into the buffer * ****************************************************************************/ int LoadFile(int selection) { int size, cd_mode1, filetype; char filename[MAXPATHLEN]; /* file path */ char *filepath = (deviceType == TYPE_RECENT) ? history.entries[selection].filepath : fileDir; /* full filename */ sprintf(filename, "%s%s", filepath, filelist[selection].filename); /* DVD hot swap */ if (!strncmp(filepath, rootdir[TYPE_DVD], strlen(rootdir[TYPE_DVD]))) { /* Check if file is still accessible */ struct stat filestat; if(stat(filename, &filestat) != 0) { /* If not, try to mount DVD */ if (!MountDVD()) return 0; } } /* open message box */ GUI_MsgBoxOpen("Information", "Loading game...", 1); /* no cartridge or CD game loaded */ size = cd_mode1 = 0; /* check if virtual CD tray was open */ if ((system_hw == SYSTEM_MCD) && (cdd.status == CD_OPEN)) { /* swap CD image file in (without changing region, system,...) */ size = cdd_load(filename, (char *)(cdc.ram)); /* check if a cartridge is currently loaded */ if (scd.cartridge.boot) { /* CD Mode 1 */ cd_mode1 = size; } else { /* update game informations from CD image file header */ getrominfo((char *)(cdc.ram)); } } /* no CD image file loaded */ if (!size) { /* close CD tray to force system reset */ cdd.status = NO_DISC; /* load game file */ size = load_rom(filename); } if (size > 0) { /* do not update game basename if a CD was loaded with a cartridge (Mode 1) */ if (cd_mode1) { /* add CD image file to history list */ filetype = 1; } else { /* auto-save previous game state */ slot_autosave(config.s_default,config.s_device); /* update game basename (for screenshot, save & cheat files) */ if (romtype & SYSTEM_SMS) { /* Master System ROM file */ filetype = 2; sprintf(rom_filename,"ms/%s",filelist[selection].filename); } else if (romtype & SYSTEM_GG) { /* Game Gear ROM file */ filetype = 3; sprintf(rom_filename,"gg/%s",filelist[selection].filename); } else if (romtype == SYSTEM_SG) { /* SG-1000 ROM file */ filetype = 4; sprintf(rom_filename,"sg/%s",filelist[selection].filename); } else if (romtype == SYSTEM_MCD) { /* CD image file */ filetype = 1; sprintf(rom_filename,"cd/%s",filelist[selection].filename); } else { /* by default, Genesis ROM file */ filetype = 0; sprintf(rom_filename,"md/%s",filelist[selection].filename); } /* remove file extension */ int i = strlen(rom_filename) - 1; while ((i > 0) && (rom_filename[i] != '.')) i--; if (i > 0) rom_filename[i] = 0; } /* add/move the file to the top of the history. */ history_add_file(filepath, filelist[selection].filename, filetype); /* recent file list may have changed */ if (deviceType == TYPE_RECENT) deviceType = -1; /* close message box */ GUI_MsgBoxClose(); /* valid image has been loaded */ return 1; } GUI_WaitPrompt("Error", "Unable to load game"); return 0; }