src/emu/machine/scsihd.c
| r14061 | r14062 | |
| 15 | 15 | UINT32 lba; |
| 16 | 16 | UINT32 blocks; |
| 17 | 17 | int sectorbytes; |
| 18 | chd_file *handle; |
| 18 | 19 | hard_disk_file *disk; |
| 19 | | bool is_file; |
| 20 | bool is_image_device; |
| 20 | 21 | } SCSIHd; |
| 21 | 22 | |
| 22 | 23 | |
| r14061 | r14062 | |
| 253 | 254 | our_this->blocks = 0; |
| 254 | 255 | our_this->sectorbytes = 512; |
| 255 | 256 | |
| 257 | // Attempt to register save state entry after state registration is closed! |
| 256 | 258 | state_save_register_item( machine, "scsihd", diskregion, 0, our_this->lba ); |
| 257 | 259 | state_save_register_item( machine, "scsihd", diskregion, 0, our_this->blocks ); |
| 258 | | |
| 259 | | if (machine.device( diskregion )) { |
| 260 | | our_this->is_file = TRUE; |
| 261 | | our_this->disk = machine.device<harddisk_image_device>(diskregion)->get_hard_disk_file(); |
| 262 | | } else { |
| 260 | |
| 261 | // try to locate the CHD from a DISK_REGION |
| 262 | our_this->handle = get_disk_handle(machine, diskregion); |
| 263 | our_this->disk = hard_disk_open(our_this->handle); |
| 264 | our_this->is_image_device = false; |
| 265 | |
| 266 | if (our_this->disk == NULL) |
| 267 | { |
| 268 | // try to locate the CHD from an image device |
| 269 | harddisk_image_device *image_device = machine.device<harddisk_image_device>(diskregion); |
| 270 | |
| 271 | if (image_device != NULL) |
| 272 | { |
| 273 | our_this->handle = image_device->get_chd_file(); |
| 274 | our_this->disk = hard_disk_open(our_this->handle); |
| 275 | our_this->is_image_device = true; |
| 276 | } |
| 277 | } |
| 278 | |
| 279 | if (our_this->disk == NULL) |
| 280 | { |
| 281 | // try to locate the CHD from an image subdevice |
| 263 | 282 | for (device_t *device = machine.devicelist().first(); device != NULL; device = device->next()) |
| 264 | 283 | { |
| 265 | | if (device->subdevice(diskregion)) { |
| 266 | | our_this->is_file = TRUE; |
| 267 | | our_this->disk = device->subdevice<harddisk_image_device>(diskregion)->get_hard_disk_file(); |
| 284 | if (device->subdevice(diskregion) != NULL) |
| 285 | { |
| 286 | our_this->handle = device->subdevice<harddisk_image_device>(diskregion)->get_chd_file(); |
| 287 | our_this->disk = hard_disk_open(our_this->handle); |
| 288 | our_this->is_image_device = true; |
| 268 | 289 | } |
| 269 | 290 | } |
| 270 | | |
| 271 | | if (!our_this->disk) |
| 272 | | { |
| 273 | | our_this->is_file = FALSE; |
| 274 | | our_this->disk = hard_disk_open(get_disk_handle( machine, diskregion )); |
| 275 | | } |
| 276 | 291 | } |
| 277 | | |
| 278 | | if (!our_this->disk) |
| 292 | |
| 293 | if (our_this->disk != NULL) |
| 279 | 294 | { |
| 280 | | logerror("SCSIHD: no HD found!\n"); |
| 295 | // get hard disk sector size from CHD metadata |
| 296 | const hard_disk_info *hdinfo = hard_disk_get_info(our_this->disk); |
| 297 | our_this->sectorbytes = hdinfo->sectorbytes; |
| 281 | 298 | } |
| 282 | 299 | else |
| 283 | 300 | { |
| 284 | | const hard_disk_info *hdinfo = hard_disk_get_info(our_this->disk); |
| 285 | | our_this->sectorbytes = hdinfo->sectorbytes; |
| 301 | logerror("SCSIHD: no HD found!\n"); |
| 286 | 302 | } |
| 287 | 303 | } |
| 288 | 304 | |
| 289 | 305 | static void scsihd_delete_instance( SCSIInstance *scsiInstance ) |
| 290 | 306 | { |
| 291 | 307 | SCSIHd *our_this = (SCSIHd *)SCSIThis( &SCSIClassHARDDISK, scsiInstance ); |
| 292 | | if (!our_this->is_file) { |
| 308 | if (!our_this->is_image_device) { |
| 293 | 309 | if( our_this->disk ) |
| 294 | 310 | { |
| 295 | 311 | hard_disk_close( our_this->disk ); |