static void coco_vhd_readwrite(UINT8 data) { mame_file *vhdfile; int result; int phyOffset; long nBA = bufferAddress; vhdfile = image_fp(vhd_image()); if (!vhdfile) { vhdStatus = 2; /* No VHD attached */ return; } result = mame_fseek(vhdfile, ((logicalRecordNumber)) * 256, SEEK_SET); if (result < 0) { vhdStatus = 5; /* access denied */ return; } phyOffset = coco3_mmu_translate( (nBA >> 12 ) / 2, nBA % 8192 ); switch(data) { case 0: /* Read sector */ result = mame_fread(vhdfile, &(mess_ram[phyOffset]), 256); if( result != 256 ) { vhdStatus = 5; /* access denied */ return; } vhdStatus = 0; /* Aok */ break; case 1: /* Write Sector */ result = mame_fwrite(vhdfile, &(mess_ram[phyOffset]), 256); if (result != 256) { vhdStatus = 5; /* access denied */ return; } vhdStatus = 0; /* Aok */ break; case 2: /* Flush file cache */ vhdStatus = 0; /* Aok */ break; default: vhdStatus = 0xfe; /* -2, Unknown command */ break; } }
/* ide_hd_load() Load an IDE hard disk image img: parameter passed by the MESS image code to the load function which_bus: IDE bus the drive is attached to (only bus 0 is supported now) which_address: address of the drive on the bus (0->master, 1->slave, only master is supported now) intf: ide_interface required by the idectrl.c core */ int ide_hd_load(mess_image *img, int which_bus, int which_address, struct ide_interface *intf) { assert(which_address == 0); if (device_load_mess_hd(img, image_fp(img)) == INIT_PASS) { ide_controller_init_custom(which_bus, intf, mess_hd_get_chd_file(img)); ide_controller_reset(which_bus); return INIT_PASS; } return INIT_FAIL; }
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 int image_checkhash(mess_image *image) { const game_driver *drv; const struct IODevice *dev; mame_file *file; char hash_string[HASH_BUF_SIZE]; int rc; /* this call should not be made when the image is not loaded */ assert(image->status & (IMAGE_STATUS_ISLOADING | IMAGE_STATUS_ISLOADED)); /* only calculate CRC if it hasn't been calculated, and the open_mode is read only */ if (!image->hash && !image->writeable && !image->created) { /* initialize key variables */ file = image_fp(image); dev = image_device(image); /* do not cause a linear read of 600 megs please */ /* TODO: use SHA/MD5 in the CHD header as the hash */ if (dev->type == IO_CDROM) return FALSE; if (!run_hash(file, dev->partialhash, hash_string, HASH_CRC | HASH_MD5 | HASH_SHA1)) return FALSE; image->hash = image_strdup(image, hash_string); if (!image->hash) return FALSE; /* now read the hash file */ drv = Machine->gamedrv; do { rc = read_hash_config(drv->name, image); drv = mess_next_compatible_driver(drv); } while(rc && drv); } return TRUE; }