src/mess/image.c
| r2190 | r2191 | |
| 38 | 38 | object_pool *mempool; |
| 39 | 39 | const device_config *dev; |
| 40 | 40 | |
| 41 | /* callbacks */ |
| 42 | device_image_load_func load; |
| 43 | device_image_create_func create; |
| 44 | device_image_unload_func unload; |
| 45 | |
| 41 | 46 | /* error related info */ |
| 42 | 47 | image_error_t err; |
| 43 | 48 | char *err_message; |
| r2190 | r2191 | |
| 114 | 119 | UINT32 mask, dev_mask = 0, multiple_dev_mask = 0; |
| 115 | 120 | const struct IODevice *dev; |
| 116 | 121 | size_t private_size; |
| 122 | image_slot_data *slot; |
| 117 | 123 | |
| 124 | /* sanity checks */ |
| 125 | assert(DEVINFO_FCT_IMAGE_FIRST > DEVINFO_FCT_FIRST); |
| 126 | assert(DEVINFO_FCT_IMAGE_LAST < DEVINFO_FCT_DEVICE_SPECIFIC); |
| 127 | |
| 118 | 128 | /* first count all images, and identify multiply defined devices */ |
| 119 | 129 | count = 0; |
| 120 | 130 | for (dev = mess_device_first_from_machine(machine); dev != NULL; dev = mess_device_next(dev)) |
| r2190 | r2191 | |
| 148 | 158 | indx = 0; |
| 149 | 159 | for (dev = mess_device_first_from_machine(machine); dev != NULL; dev = mess_device_next(dev)) |
| 150 | 160 | { |
| 151 | | /* interim change until we use the normal device->start */ |
| 161 | slot = &machine->images_data->slots[indx]; |
| 162 | |
| 163 | /* interim changes until we use the normal device->start */ |
| 152 | 164 | ((device_config *) dev->devconfig)->machine = machine; |
| 165 | ((device_config *) dev->devconfig)->token = (void *) ~0; |
| 153 | 166 | |
| 154 | 167 | /* create a memory pool */ |
| 155 | 168 | machine->images_data->slots[indx].mempool = pool_alloc(memory_error); |
| r2190 | r2191 | |
| 158 | 171 | tagpool_init(&machine->images_data->slots[indx].tagpool); |
| 159 | 172 | machine->images_data->slots[indx].dev = dev->devconfig; |
| 160 | 173 | |
| 174 | /* callbacks */ |
| 175 | slot->load = (device_image_load_func) device_get_info_fct(slot->dev, DEVINFO_FCT_IMAGE_LOAD); |
| 176 | slot->create = (device_image_create_func) device_get_info_fct(slot->dev, DEVINFO_FCT_IMAGE_CREATE); |
| 177 | slot->unload = (device_image_unload_func) device_get_info_fct(slot->dev, DEVINFO_FCT_IMAGE_UNLOAD); |
| 178 | |
| 179 | /* invoke start, if present */ |
| 161 | 180 | if (dev->start != NULL) |
| 162 | 181 | { |
| 163 | | dev->start(machine->images_data->slots[indx].dev); |
| 182 | dev->start(slot->dev); |
| 164 | 183 | } |
| 165 | 184 | indx++; |
| 185 | |
| 186 | /* interim changes until we use the normal device->start */ |
| 187 | ((device_config *) dev->devconfig)->token = NULL; |
| 166 | 188 | } |
| 167 | 189 | |
| 168 | 190 | add_exit_callback(machine, image_exit); |
| r2190 | r2191 | |
| 659 | 681 | } |
| 660 | 682 | |
| 661 | 683 | /* call device load or create */ |
| 662 | | if (image_has_been_created(image) && (iodev->create != NULL)) |
| 684 | if (image_has_been_created(image) && (slot->create != NULL)) |
| 663 | 685 | { |
| 664 | | err = iodev->create(image, create_format, create_args); |
| 686 | err = slot->create(image, create_format, create_args); |
| 665 | 687 | if (err) |
| 666 | 688 | { |
| 667 | 689 | if (!slot->err) |
| r2190 | r2191 | |
| 669 | 691 | goto done; |
| 670 | 692 | } |
| 671 | 693 | } |
| 672 | | else if (iodev->load != NULL) |
| 694 | else if (slot->load != NULL) |
| 673 | 695 | { |
| 674 | 696 | /* using device load */ |
| 675 | | err = iodev->load(image); |
| 697 | err = slot->load(image); |
| 676 | 698 | if (err) |
| 677 | 699 | { |
| 678 | 700 | if (!slot->err) |
| r2190 | r2191 | |
| 762 | 784 | |
| 763 | 785 | /* call the unload function */ |
| 764 | 786 | iodev = mess_device_from_core_device(image->dev); |
| 765 | | if (iodev->unload != NULL) |
| 766 | | iodev->unload(image->dev); |
| 787 | if (image->unload != NULL) |
| 788 | image->unload(image->dev); |
| 767 | 789 | |
| 768 | 790 | image_clear(image); |
| 769 | 791 | image_clear_error(image); |
src/mess/image.h
| r2190 | r2191 | |
| 6 | 6 | |
| 7 | 7 | ****************************************************************************/ |
| 8 | 8 | |
| 9 | | #ifndef IMAGE_H |
| 10 | | #define IMAGE_H |
| 9 | #ifndef __IMAGE_H__ |
| 10 | #define __IMAGE_H__ |
| 11 | 11 | |
| 12 | 12 | #include <stdlib.h> |
| 13 | |
| 13 | 14 | #include "fileio.h" |
| 14 | 15 | #include "utils.h" |
| 15 | 16 | #include "opresolv.h" |
| 16 | 17 | #include "device.h" |
| 17 | 18 | #include "osdmess.h" |
| 18 | 19 | |
| 20 | |
| 21 | |
| 22 | /*************************************************************************** |
| 23 | CONSTANTS |
| 24 | ***************************************************************************/ |
| 25 | |
| 19 | 26 | typedef enum |
| 20 | 27 | { |
| 21 | 28 | IMAGE_ERROR_SUCCESS, |
| r2190 | r2191 | |
| 32 | 39 | typedef struct _images_private images_private; |
| 33 | 40 | |
| 34 | 41 | |
| 42 | /* state constants specific for mountable images */ |
| 43 | enum |
| 44 | { |
| 45 | /* --- the following bits of info are returned as pointers to functions --- */ |
| 46 | DEVINFO_FCT_IMAGE_FIRST = DEVINFO_FCT_FIRST + 0x7000, |
| 47 | DEVINFO_FCT_IMAGE_LOAD, /* R/O: device_load_handler */ |
| 48 | DEVINFO_FCT_IMAGE_CREATE, /* R/O: device_create_handler */ |
| 49 | DEVINFO_FCT_IMAGE_UNLOAD, /* R/O: device_unload_handler */ |
| 50 | DEVINFO_FCT_IMAGE_LAST = DEVINFO_FCT_FIRST + 0x0fff |
| 51 | }; |
| 35 | 52 | |
| 53 | |
| 54 | |
| 55 | |
| 36 | 56 | /**************************************************************************** |
| 37 | 57 | A const device_config pointer represents one device entry; this could be an instance |
| 38 | 58 | of a floppy drive or a printer. The defining property is that either at |
| r2190 | r2191 | |
| 222 | 242 | #define DEVICE_IMAGE_UNLOAD_NAME(name) device_unload_##name |
| 223 | 243 | #define DEVICE_IMAGE_UNLOAD(name) void DEVICE_IMAGE_UNLOAD_NAME(name)(const device_config *image) |
| 224 | 244 | |
| 225 | | #endif /* IMAGE_H */ |
| 245 | #endif /* __IMAGE_H__ */ |
src/mess/device.c
| r2190 | r2191 | |
| 209 | 209 | |
| 210 | 210 | DEVICE_GET_INFO(mess_device) |
| 211 | 211 | { |
| 212 | mess_device_config *mess_device = (device != NULL) ? (mess_device_config *) device->inline_config : NULL; |
| 213 | |
| 212 | 214 | switch (state) |
| 213 | 215 | { |
| 214 | 216 | /* --- the following bits of info are returned as 64-bit signed integers --- */ |
| r2190 | r2191 | |
| 221 | 223 | case DEVINFO_FCT_START: info->start = DEVICE_START_NAME(mess_device); break; |
| 222 | 224 | case DEVINFO_FCT_STOP: /* Nothing */ break; |
| 223 | 225 | case DEVINFO_FCT_RESET: /* Nothing */ break; |
| 226 | case DEVINFO_FCT_IMAGE_LOAD: info->f = mess_device_get_info_fct(&mess_device->io_device.devclass, MESS_DEVINFO_PTR_LOAD); break; |
| 227 | case DEVINFO_FCT_IMAGE_CREATE: info->f = mess_device_get_info_fct(&mess_device->io_device.devclass, MESS_DEVINFO_PTR_CREATE); break; |
| 228 | case DEVINFO_FCT_IMAGE_UNLOAD: info->f = mess_device_get_info_fct(&mess_device->io_device.devclass, MESS_DEVINFO_PTR_UNLOAD); break; |
| 224 | 229 | |
| 225 | 230 | /* --- the following bits of info are returned as NULL-terminated strings --- */ |
| 226 | 231 | case DEVINFO_STR_NAME: info->s = "Legacy MESS Device"; break; |
| r2190 | r2191 | |
| 363 | 368 | |
| 364 | 369 | mess_device->io_device.start = (device_start_func) mess_device_get_info_fct(&mess_device->io_device.devclass, MESS_DEVINFO_PTR_START); |
| 365 | 370 | mess_device->io_device.stop = (device_stop_func) mess_device_get_info_fct(&mess_device->io_device.devclass, MESS_DEVINFO_PTR_STOP); |
| 366 | | mess_device->io_device.load = (device_image_load_func) mess_device_get_info_fct(&mess_device->io_device.devclass, MESS_DEVINFO_PTR_LOAD); |
| 367 | | mess_device->io_device.create = (device_image_create_func) mess_device_get_info_fct(&mess_device->io_device.devclass, MESS_DEVINFO_PTR_CREATE); |
| 368 | | mess_device->io_device.unload = (device_image_unload_func) mess_device_get_info_fct(&mess_device->io_device.devclass, MESS_DEVINFO_PTR_UNLOAD); |
| 369 | 371 | mess_device->io_device.imgverify = (device_image_verify_func) mess_device_get_info_fct(&mess_device->io_device.devclass, MESS_DEVINFO_PTR_VERIFY); |
| 370 | 372 | mess_device->io_device.partialhash = (device_image_partialhash_func) mess_device_get_info_fct(&mess_device->io_device.devclass, MESS_DEVINFO_PTR_PARTIAL_HASH); |
| 371 | 373 | |