static int device_load_cassette(mess_image *image) { casserr_t err; int cassette_flags; struct mess_cassetteimg *tag; const struct IODevice *dev; const struct CassetteFormat **formats; const struct CassetteOptions *create_opts; const char *extension; int is_writable; tag = get_cassimg(image); /* figure out the cassette format */ dev = device_find(Machine->devices, IO_CASSETTE); formats = device_get_info_ptr(&dev->devclass, DEVINFO_PTR_CASSETTE_FORMATS); if (image_has_been_created(image)) { /* creating an image */ create_opts = (const struct CassetteOptions *) device_get_info_ptr(&dev->devclass, DEVINFO_PTR_CASSETTE_OPTIONS); err = cassette_create(image, &mess_ioprocs, &wavfile_format, create_opts, CASSETTE_FLAG_READWRITE|CASSETTE_FLAG_SAVEONEXIT, &tag->cassette); if (err) goto error; } else { /* opening an image */ do { is_writable = image_is_writable(image); cassette_flags = is_writable ? (CASSETTE_FLAG_READWRITE|CASSETTE_FLAG_SAVEONEXIT) : CASSETTE_FLAG_READONLY; extension = image_filetype(image); err = cassette_open_choices(image, &mess_ioprocs, extension, formats, cassette_flags, &tag->cassette); /* this is kind of a hack */ if (err && is_writable) image_make_readonly(image); } while(err && is_writable); if (err) goto error; } /* set to default state, but only change the UI state */ cassette_change_state(image, get_default_state(dev), CASSETTE_MASK_UISTATE); /* reset the position */ tag->position = 0.0; tag->position_time = timer_get_time(); return INIT_PASS; error: return INIT_FAIL; }
static int internal_load_mess_hd(mess_image *image, const char *metadata) { int err = 0; struct mess_hd *hd; chd_file *chd; int is_writeable; int id = image_index_in_device(image); hd = get_drive(image); /* open the CHD file */ do { is_writeable = image_is_writable(image); chd = chd_open_ref(image, is_writeable, NULL); if (!chd) { err = chd_get_last_error(); /* special case; if we get CHDERR_FILE_NOT_WRITEABLE, make the * image read only and repeat */ if (err == CHDERR_FILE_NOT_WRITEABLE) image_make_readonly(image); } } while(!chd && is_writeable && (err == CHDERR_FILE_NOT_WRITEABLE)); if (!chd) goto error; /* if we created the image and hence, have metadata to set, set the metadata */ if (metadata) { err = chd_set_metadata(chd, HARD_DISK_STANDARD_METADATA, 0, metadata, strlen(metadata) + 1); if (err != CHDERR_NONE) goto error; } /* open the hard disk file */ hd->hard_disk_handle = hard_disk_open(chd); if (!hd->hard_disk_handle) goto error; drive_handles[id] = hd->hard_disk_handle; return INIT_PASS; error: if (chd) chd_close(chd); err = chd_get_last_error(); if (err) image_seterror(image, IMAGE_ERROR_UNSPECIFIED, chd_get_error_string(err)); return INIT_FAIL; }
static int internal_floppy_device_load(mess_image *image, mame_file *file, int create_format, option_resolution *create_args) { floperr_t err; struct mess_flopimg *flopimg; const struct IODevice *dev; const struct FloppyFormat *floppy_options; int floppy_flags, i; const char *extension; /* look up instance data */ flopimg = get_flopimg(image); /* figure out the floppy options */ dev = image_device(image); floppy_options = device_get_info_ptr(&dev->devclass, DEVINFO_PTR_FLOPPY_OPTIONS); if (image_has_been_created(image)) { /* creating an image */ assert(create_format >= 0); err = floppy_create(file, &mess_ioprocs, &floppy_options[create_format], create_args, &flopimg->floppy); if (err) goto error; } else { /* opening an image */ floppy_flags = image_is_writable(image) ? FLOPPY_FLAGS_READWRITE : FLOPPY_FLAGS_READONLY; extension = image_filetype(image); err = floppy_open_choices(file, &mess_ioprocs, extension, floppy_options, floppy_flags, &flopimg->floppy); if (err) goto error; } /* if we can get head and track counts, then set the geometry accordingly */ if (floppy_callbacks(flopimg->floppy)->get_heads_per_disk && floppy_callbacks(flopimg->floppy)->get_tracks_per_disk) { floppy_drive_set_geometry_absolute(image, floppy_get_tracks_per_disk(flopimg->floppy), floppy_get_heads_per_disk(flopimg->floppy)); } return INIT_PASS; error: for (i = 0; i < sizeof(errmap) / sizeof(errmap[0]); i++) { if (err == errmap[i].ferr) image_seterror(image, errmap[i].ierr, errmap[i].message); } return INIT_FAIL; }
int apple525_read_status(void) { int i, count, result = 0; mess_image *image; count = device_count_tag(Machine->devices, APPLE525TAG); for (i = 0; i < count; i++) { if (apple525_enable_mask & (1 << i)) { image = image_from_devtag_and_index(APPLE525TAG, i); if (image && !image_is_writable(image)) result = 1; } } return result; }
/* attempt to insert a disk into the drive specified with id */ int device_load_basicdsk_floppy(mess_image *image) { basicdsk *w = get_basicdsk(image); w->image_file = image; w->mode = image_is_writable(image); /* this will be setup in the set_geometry function */ w->ddam_map = NULL; /* the following line is unsafe, but floppy_drives_init assumes we start on track 0, so we need to reflect this */ w->track = 0; floppy_drive_set_disk_image_interface(image, &basicdsk_floppy_interface); return INIT_PASS; }
static chd_interface_file *mess_chd_open(const char *filename, const char *mode) { mess_image *img = decode_image_ref(filename); /* used when experimenting with CHDs */ if (USE_CHD_OPEN && !img) return (chd_interface_file *) mame_fopen(NULL, filename, FILETYPE_IMAGE, 0); /* invalid "file name"? */ assert(img); /* read-only fp? */ if (!image_is_writable(img) && !(mode[0] == 'r' && !strchr(mode, '+'))) return NULL; /* otherwise return file pointer */ return (chd_interface_file *) image_fp(img); }
static chd_interface_file *mess_chd_open(const char *filename, const char *mode) { mame_file_error filerr; mess_image *image = decode_image_ref(filename); /* used when experimenting with CHDs */ if (USE_CHD_OPEN && !image) { mame_file *file; filerr = mame_fopen(SEARCHPATH_IMAGE, filename, OPEN_FLAG_READ, &file); return (chd_interface_file *) file; } /* invalid "file name"? */ if (!image) return NULL; /* read-only fp? */ if (!image_is_writable(image) && !(mode[0] == 'r' && !strchr(mode, '+'))) return NULL; /* otherwise return file pointer */ return (chd_interface_file *) image; }