src/mess/image.c
| r2294 | r2295 | |
| 92 | 92 | |
| 93 | 93 | |
| 94 | 94 | /*************************************************************************** |
| 95 | INLINE FUNCTIONS |
| 96 | ***************************************************************************/ |
| 97 | |
| 98 | /*------------------------------------------------- |
| 99 | device_get_info_int_offline - return an integer |
| 100 | state value from an allocated device; can be |
| 101 | called offline |
| 102 | -------------------------------------------------*/ |
| 103 | |
| 104 | INLINE INT64 device_get_info_int_offline(const device_config *device, UINT32 state) |
| 105 | { |
| 106 | deviceinfo info; |
| 107 | |
| 108 | assert(device != NULL); |
| 109 | assert(device->type != NULL); |
| 110 | assert(state >= DEVINFO_INT_FIRST && state <= DEVINFO_INT_LAST); |
| 111 | |
| 112 | /* retrieve the value */ |
| 113 | info.i = 0; |
| 114 | (*device->type)(device, state, &info); |
| 115 | return info.i; |
| 116 | } |
| 117 | |
| 118 | |
| 119 | |
| 120 | /*------------------------------------------------- |
| 121 | device_get_info_fct_offline - return an integer |
| 122 | state value from an allocated device; can be |
| 123 | called offline |
| 124 | -------------------------------------------------*/ |
| 125 | |
| 126 | INLINE genf *device_get_info_fct_offline(const device_config *device, UINT32 state) |
| 127 | { |
| 128 | deviceinfo info; |
| 129 | |
| 130 | assert(device != NULL); |
| 131 | assert(device->type != NULL); |
| 132 | assert(state >= DEVINFO_FCT_FIRST && state <= DEVINFO_FCT_LAST); |
| 133 | |
| 134 | /* retrieve the value */ |
| 135 | info.f = 0; |
| 136 | (*device->type)(device, state, &info); |
| 137 | return info.f; |
| 138 | } |
| 139 | |
| 140 | |
| 141 | |
| 142 | /*************************************************************************** |
| 95 | 143 | CORE IMPLEMENTATION |
| 96 | 144 | ***************************************************************************/ |
| 97 | 145 | |
| r2294 | r2295 | |
| 210 | 258 | |
| 211 | 259 | static int is_image_device(const device_config *device) |
| 212 | 260 | { |
| 213 | | return (device->type == MESS_DEVICE); |
| 261 | return (device->type == MESS_DEVICE) |
| 262 | || (device_get_info_int_offline(device, DEVINFO_INT_IMAGE_READABLE) != 0) |
| 263 | || (device_get_info_int_offline(device, DEVINFO_INT_IMAGE_WRITEABLE) != 0); |
| 214 | 264 | } |
| 215 | 265 | |
| 216 | 266 | |
| r2294 | r2295 | |
| 285 | 335 | |
| 286 | 336 | memset(&info, 0, sizeof(info)); |
| 287 | 337 | |
| 338 | /* retrieve type */ |
| 339 | info.type = (iodevice_t) (int) device_get_info_int_offline(device, DEVINFO_INT_IMAGE_TYPE); |
| 340 | |
| 341 | /* retrieve flags */ |
| 342 | info.readable = device_get_info_int_offline(device, DEVINFO_INT_IMAGE_READABLE) ? 1 : 0; |
| 343 | info.writeable = device_get_info_int_offline(device, DEVINFO_INT_IMAGE_WRITEABLE) ? 1 : 0; |
| 344 | info.creatable = device_get_info_int_offline(device, DEVINFO_INT_IMAGE_CREATABLE) ? 1 : 0; |
| 345 | info.must_be_loaded = device_get_info_int_offline(device, DEVINFO_INT_IMAGE_MUST_BE_LOADED) ? 1 : 0; |
| 346 | |
| 288 | 347 | iodev = mess_device_from_core_device(device); |
| 289 | 348 | if (iodev != NULL) |
| 290 | 349 | { |
| 291 | | /* retrieve type */ |
| 292 | | info.type = iodev->type; |
| 293 | | |
| 294 | | /* retrieve flags */ |
| 295 | | info.readable = iodev->readable; |
| 296 | | info.writeable = iodev->writeable; |
| 297 | | info.creatable = iodev->creatable; |
| 298 | | info.must_be_loaded = iodev->must_be_loaded; |
| 299 | | info.uses_partial_hash = iodev->partialhash != NULL; |
| 300 | | |
| 301 | 350 | /* retrieve name */ |
| 302 | 351 | s = (*iodev->name)(iodev, iodev->index_in_device, info.name, ARRAY_LENGTH(info.name)); |
| 303 | 352 | if (s != info.name) |
| r2294 | r2295 | |
| 364 | 413 | void image_device_compute_hash(char *dest, const device_config *device, |
| 365 | 414 | const void *data, size_t length, unsigned int functions) |
| 366 | 415 | { |
| 367 | | deviceinfo info; |
| 368 | 416 | device_image_partialhash_func partialhash; |
| 369 | 417 | |
| 370 | 418 | /* retrieve the partial hash func */ |
| 371 | | info.f = 0; |
| 372 | | (*device->type)(device, DEVINFO_FCT_IMAGE_PARTIAL_HASH, &info); |
| 373 | | partialhash = (device_image_partialhash_func) info.f; |
| 419 | partialhash = (device_image_partialhash_func) device_get_info_fct_offline(device, DEVINFO_FCT_IMAGE_PARTIAL_HASH); |
| 374 | 420 | |
| 375 | 421 | /* compute the hash */ |
| 376 | 422 | if (partialhash != NULL) |
src/mess/image.h
| r2294 | r2295 | |
| 65 | 65 | unsigned int writeable : 1; |
| 66 | 66 | unsigned int creatable : 1; |
| 67 | 67 | unsigned int must_be_loaded : 1; |
| 68 | | unsigned int uses_partial_hash : 1; |
| 69 | 68 | char name[62]; |
| 70 | 69 | char file_extensions[32]; |
| 71 | 70 | char instance_name[32]; |
| r2294 | r2295 | |
| 79 | 78 | /* state constants specific for mountable images */ |
| 80 | 79 | enum |
| 81 | 80 | { |
| 81 | /* --- the following bits of info are returned as integers --- */ |
| 82 | DEVINFO_INT_IMAGE_FIRST = DEVINFO_INT_FIRST + 0x7000, |
| 83 | DEVINFO_INT_IMAGE_TYPE, |
| 84 | DEVINFO_INT_IMAGE_READABLE, |
| 85 | DEVINFO_INT_IMAGE_WRITEABLE, |
| 86 | DEVINFO_INT_IMAGE_CREATABLE, |
| 87 | DEVINFO_INT_IMAGE_MUST_BE_LOADED, |
| 88 | DEVINFO_INT_IMAGE_LAST = DEVINFO_INT_IMAGE_FIRST + 0x0fff, |
| 89 | |
| 82 | 90 | /* --- the following bits of info are returned as pointers to functions --- */ |
| 83 | 91 | DEVINFO_FCT_IMAGE_FIRST = DEVINFO_FCT_FIRST + 0x7000, |
| 84 | 92 | DEVINFO_FCT_IMAGE_LOAD, /* R/O: device_load_handler */ |
| r2294 | r2295 | |
| 86 | 94 | DEVINFO_FCT_IMAGE_UNLOAD, /* R/O: device_unload_handler */ |
| 87 | 95 | DEVINFO_FCT_DISPLAY, /* R/O: device_display_func */ |
| 88 | 96 | DEVINFO_FCT_IMAGE_PARTIAL_HASH, /* R/O: device_image_partialhash_func */ |
| 89 | | DEVINFO_FCT_IMAGE_LAST = DEVINFO_FCT_FIRST + 0x0fff |
| 97 | DEVINFO_FCT_IMAGE_LAST = DEVINFO_FCT_FIRST + 0x0fff, |
| 98 | |
| 99 | /* --- the following bits of info are returned as NULL-terminated strings --- */ |
| 100 | DEVINFO_STR_IMAGE_FIRST = DEVINFO_STR_FIRST + 0x7000, |
| 101 | DEVINFO_STR_IMAGE_FILE_EXTENSIONS, |
| 102 | DEVINFO_STR_IMAGE_LAST = DEVINFO_STR_IMAGE_FIRST + 0x0fff |
| 90 | 103 | }; |
| 91 | 104 | |
| 92 | 105 | |
src/mess/device.c
| r2294 | r2295 | |
| 267 | 267 | case DEVINFO_INT_INLINE_CONFIG_BYTES: info->i = sizeof(mess_device_config); break; |
| 268 | 268 | case DEVINFO_INT_TOKEN_BYTES: info->i = sizeof(mess_device_token); break; |
| 269 | 269 | case DEVINFO_INT_CLASS: info->i = DEVICE_CLASS_OTHER; break; |
| 270 | case DEVINFO_INT_IMAGE_READABLE: info->i = mess_device->io_device.readable; break; |
| 271 | case DEVINFO_INT_IMAGE_WRITEABLE: info->i = mess_device->io_device.writeable; break; |
| 272 | case DEVINFO_INT_IMAGE_CREATABLE: info->i = mess_device->io_device.creatable; break; |
| 273 | case DEVINFO_INT_IMAGE_MUST_BE_LOADED: info->i = mess_device_get_info_int(&mess_device->io_device.devclass, MESS_DEVINFO_INT_MUST_BE_LOADED); break; |
| 270 | 274 | |
| 271 | 275 | /* --- the following bits of info are returned as pointers to data or functions --- */ |
| 272 | 276 | case DEVINFO_FCT_SET_INFO: /* Nothing */ break; |
| r2294 | r2295 | |
| 415 | 419 | mess_device->io_device.file_extensions = file_extensions; |
| 416 | 420 | |
| 417 | 421 | mess_device->io_device.reset_on_load = mess_device_get_info_int(&mess_device->io_device.devclass, MESS_DEVINFO_INT_RESET_ON_LOAD) ? 1 : 0; |
| 418 | | mess_device->io_device.must_be_loaded = mess_device_get_info_int(&mess_device->io_device.devclass, MESS_DEVINFO_INT_MUST_BE_LOADED) ? 1 : 0; |
| 419 | 422 | mess_device->io_device.load_at_init = mess_device_get_info_int(&mess_device->io_device.devclass, MESS_DEVINFO_INT_LOAD_AT_INIT) ? 1 : 0; |
| 420 | 423 | |
| 421 | 424 | mess_device->io_device.start = (device_start_func) mess_device_get_info_fct(&mess_device->io_device.devclass, MESS_DEVINFO_PTR_START); |