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; }