src/mess/configms.c
| r2203 | r2204 | |
| 23 | 23 | static void device_dirs_load(int config_type, xml_data_node *parentnode) |
| 24 | 24 | { |
| 25 | 25 | xml_data_node *node; |
| 26 | | const struct IODevice *dev; |
| 26 | const device_config *dev; |
| 27 | const struct IODevice *iodev; |
| 27 | 28 | const device_config *image; |
| 28 | 29 | const char *dev_instance; |
| 29 | 30 | const char *working_directory; |
| r2203 | r2204 | |
| 37 | 38 | |
| 38 | 39 | if (dev_instance != NULL) |
| 39 | 40 | { |
| 40 | | for (dev = mess_device_first_from_machine(Machine); (image == NULL) && (dev != NULL); dev = mess_device_next(dev)) |
| 41 | for (dev = image_device_first(Machine->config); (image == NULL) && (dev != NULL); dev = image_device_next(dev)) |
| 41 | 42 | { |
| 42 | | if (!strcmp(dev_instance, device_instancename(&dev->devclass, dev->index_in_device))) |
| 43 | | image = image_from_device(dev); |
| 43 | iodev = mess_device_from_core_device(dev); |
| 44 | if (iodev != NULL) |
| 45 | { |
| 46 | if (!strcmp(dev_instance, device_instancename(&iodev->devclass, iodev->index_in_device))) |
| 47 | image = dev; |
| 48 | } |
| 44 | 49 | } |
| 45 | 50 | |
| 46 | 51 | if (image != NULL) |
| r2203 | r2204 | |
| 71 | 76 | /* only care about game-specific data */ |
| 72 | 77 | if (config_type == CONFIG_TYPE_GAME) |
| 73 | 78 | { |
| 74 | | for (dev = mess_device_first_from_machine(Machine); dev != NULL; dev = mess_device_next(dev)) |
| 79 | for (image = image_device_first(Machine->config); image != NULL; image = image_device_next(image)) |
| 75 | 80 | { |
| 76 | | image = image_from_device(dev); |
| 81 | dev = mess_device_from_core_device(image); |
| 77 | 82 | dev_instance = device_instancename(&dev->devclass, dev->index_in_device); |
| 78 | 83 | |
| 79 | 84 | node = xml_add_child(parentnode, "device", NULL); |
src/mess/uimess.c
| r2203 | r2204 | |
| 26 | 26 | static int ui_toggle_key = 0; |
| 27 | 27 | |
| 28 | 28 | int toggled = 0; |
| 29 | | const struct IODevice *dev; |
| 29 | const device_config *dev; |
| 30 | 30 | |
| 31 | 31 | /* traditional MESS interface */ |
| 32 | 32 | if (machine->gamedrv->flags & GAME_COMPUTER) |
| r2203 | r2204 | |
| 78 | 78 | } |
| 79 | 79 | |
| 80 | 80 | /* run display routine for device */ |
| 81 | | for (dev = mess_device_first_from_machine(machine); dev != NULL; dev = mess_device_next(dev)) |
| 81 | if (mame_get_phase(machine) == MAME_PHASE_RUNNING) |
| 82 | 82 | { |
| 83 | | if (dev->display != NULL) |
| 83 | for (dev = image_device_first(machine->config); dev != NULL; dev = image_device_next(dev)) |
| 84 | 84 | { |
| 85 | | const device_config *img = image_from_device(dev); |
| 86 | | dev->display(img); |
| 85 | device_display_func display = (device_display_func) device_get_info_fct(dev, DEVINFO_FCT_DISPLAY); |
| 86 | if (display != NULL) |
| 87 | { |
| 88 | display(dev); |
| 89 | } |
| 87 | 90 | } |
| 88 | 91 | } |
| 89 | 92 | } |
| r2203 | r2204 | |
| 99 | 102 | int ui_sprintf_image_info(running_machine *machine, char *buf) |
| 100 | 103 | { |
| 101 | 104 | char *dst = buf; |
| 102 | | const struct IODevice *dev; |
| 105 | const device_config *img; |
| 103 | 106 | |
| 104 | 107 | dst += sprintf(dst, "%s\n\n", machine->gamedrv->description); |
| 105 | 108 | |
| r2203 | r2204 | |
| 109 | 112 | dst += sprintf(dst, "RAM: %s\n\n", ram_string(buf2, mess_ram_size)); |
| 110 | 113 | } |
| 111 | 114 | |
| 112 | | for (dev = mess_device_first_from_machine(machine); dev != NULL; dev = mess_device_next(dev)) |
| 115 | for (img = image_device_first(machine->config); img != NULL; img = image_device_next(img)) |
| 113 | 116 | { |
| 114 | | const device_config *img = image_from_device(dev); |
| 115 | 117 | const char *name = image_filename(img); |
| 116 | 118 | if( name ) |
| 117 | 119 | { |
src/mess/image.c
| r2203 | r2204 | |
| 117 | 117 | { |
| 118 | 118 | int count, indx; |
| 119 | 119 | UINT32 mask, dev_mask = 0, multiple_dev_mask = 0; |
| 120 | | const struct IODevice *dev; |
| 120 | const device_config *dev; |
| 121 | const struct IODevice *iodev; |
| 121 | 122 | size_t private_size; |
| 122 | 123 | image_slot_data *slot; |
| 123 | 124 | |
| r2203 | r2204 | |
| 127 | 128 | |
| 128 | 129 | /* first count all images, and identify multiply defined devices */ |
| 129 | 130 | count = 0; |
| 130 | | for (dev = mess_device_first_from_machine(machine); dev != NULL; dev = mess_device_next(dev)) |
| 131 | for (dev = image_device_first(machine->config); dev != NULL; dev = image_device_next(dev)) |
| 131 | 132 | { |
| 132 | | /* weird check only relevant on the first device */ |
| 133 | | if (dev->index_in_device == 0) |
| 133 | /* weird check only relevant on the first legacy MESS device */ |
| 134 | iodev = mess_device_from_core_device(dev); |
| 135 | if ((iodev != NULL) && (iodev->index_in_device == 0)) |
| 134 | 136 | { |
| 135 | 137 | /* check to see if this device type is used multiple times */ |
| 136 | | mask = 1 << dev->type; |
| 138 | mask = 1 << iodev->type; |
| 137 | 139 | if (dev_mask & mask) |
| 138 | 140 | multiple_dev_mask |= mask; |
| 139 | 141 | else |
| r2203 | r2204 | |
| 156 | 158 | |
| 157 | 159 | /* initialize the devices */ |
| 158 | 160 | indx = 0; |
| 159 | | for (dev = mess_device_first_from_machine(machine); dev != NULL; dev = mess_device_next(dev)) |
| 161 | for (dev = image_device_first(machine->config); dev != NULL; dev = image_device_next(dev)) |
| 160 | 162 | { |
| 161 | 163 | slot = &machine->images_data->slots[indx]; |
| 162 | 164 | |
| 163 | 165 | /* interim changes until we use the normal device->start */ |
| 164 | | ((device_config *) dev->devconfig)->machine = machine; |
| 165 | | ((device_config *) dev->devconfig)->token = (void *) ~0; |
| 166 | ((device_config *) dev)->machine = machine; |
| 167 | ((device_config *) dev)->token = (void *) ~0; |
| 166 | 168 | |
| 167 | 169 | /* create a memory pool */ |
| 168 | 170 | machine->images_data->slots[indx].mempool = pool_alloc(memory_error); |
| 169 | 171 | |
| 170 | 172 | /* setup the device */ |
| 171 | | tagpool_init(&machine->images_data->slots[indx].tagpool); |
| 172 | | machine->images_data->slots[indx].dev = dev->devconfig; |
| 173 | tagpool_init(&slot->tagpool); |
| 174 | machine->images_data->slots[indx].dev = dev; |
| 173 | 175 | |
| 174 | 176 | /* callbacks */ |
| 175 | 177 | slot->load = (device_image_load_func) device_get_info_fct(slot->dev, DEVINFO_FCT_IMAGE_LOAD); |
| r2203 | r2204 | |
| 184 | 186 | indx++; |
| 185 | 187 | |
| 186 | 188 | /* interim changes until we use the normal device->start */ |
| 187 | | ((device_config *) dev->devconfig)->token = NULL; |
| 189 | ((device_config *) dev)->token = NULL; |
| 188 | 190 | } |
| 189 | 191 | |
| 190 | 192 | add_exit_callback(machine, image_exit); |
| r2203 | r2204 | |
| 199 | 201 | |
| 200 | 202 | static void image_exit(running_machine *machine) |
| 201 | 203 | { |
| 202 | | int indx, i; |
| 203 | | image_slot_data *image; |
| 204 | | const struct IODevice *dev; |
| 204 | int i; |
| 205 | image_slot_data *slot; |
| 205 | 206 | |
| 206 | 207 | if (machine->images_data != NULL) |
| 207 | 208 | { |
| r2203 | r2204 | |
| 215 | 216 | image_unload_all(FALSE); |
| 216 | 217 | image_unload_all(TRUE); |
| 217 | 218 | |
| 218 | | indx = 0; |
| 219 | | |
| 220 | | for (dev = mess_device_first_from_machine(machine); dev != NULL; dev = mess_device_next(dev)) |
| 219 | for (i = 0; i < machine->images_data->slot_count; i++) |
| 221 | 220 | { |
| 222 | | /* identify the image */ |
| 223 | | image = &machine->images_data->slots[indx]; |
| 221 | /* identify the image slot */ |
| 222 | slot = &machine->images_data->slots[i]; |
| 224 | 223 | |
| 225 | | /* call the stop handler if appropriate */ |
| 226 | | if (dev->stop != NULL) |
| 227 | | dev->stop(image->dev); |
| 228 | | |
| 229 | 224 | /* free the tagpool */ |
| 230 | | tagpool_exit(&image->tagpool); |
| 225 | tagpool_exit(&slot->tagpool); |
| 231 | 226 | |
| 232 | 227 | /* free the working directory */ |
| 233 | | if (image->working_directory != NULL) |
| 228 | if (slot->working_directory != NULL) |
| 234 | 229 | { |
| 235 | | free(image->working_directory); |
| 236 | | image->working_directory = NULL; |
| 230 | free(slot->working_directory); |
| 231 | slot->working_directory = NULL; |
| 237 | 232 | } |
| 238 | 233 | |
| 239 | 234 | /* free the memory pool */ |
| 240 | | pool_free(image->mempool); |
| 241 | | image->mempool = NULL; |
| 242 | | indx++; |
| 235 | pool_free(slot->mempool); |
| 236 | slot->mempool = NULL; |
| 243 | 237 | } |
| 244 | 238 | |
| 245 | 239 | /* interim hack until we use normal device startup/shutdown */ |
| r2203 | r2204 | |
| 265 | 259 | |
| 266 | 260 | static int is_image_device(const device_config *device) |
| 267 | 261 | { |
| 268 | | return (device->type == MESS_DEVICE) |
| 269 | | || (device_get_info_fct(device, DEVINFO_FCT_IMAGE_LOAD) != NULL) |
| 270 | | || (device_get_info_fct(device, DEVINFO_FCT_IMAGE_CREATE) != NULL) |
| 271 | | || (device_get_info_fct(device, DEVINFO_FCT_IMAGE_UNLOAD) != NULL); |
| 262 | return (device->type == MESS_DEVICE); |
| 272 | 263 | } |
| 273 | 264 | |
| 274 | 265 | |
| r2203 | r2204 | |
| 1767 | 1758 | |
| 1768 | 1759 | const device_config *image_from_devtag_and_index(const char *devtag, int id) |
| 1769 | 1760 | { |
| 1770 | | int indx; |
| 1771 | 1761 | const device_config *image = NULL; |
| 1772 | | const struct IODevice *dev; |
| 1773 | | int device_index; |
| 1762 | const device_config *dev; |
| 1763 | const struct IODevice *iodev; |
| 1774 | 1764 | |
| 1775 | | indx = 0; |
| 1776 | | device_index = 0; |
| 1777 | | for (dev = mess_device_first_from_machine(Machine); dev != NULL; dev = mess_device_next(dev)) |
| 1765 | for (dev = image_device_first(Machine->config); dev != NULL; dev = image_device_next(dev)) |
| 1778 | 1766 | { |
| 1779 | | if (dev->tag && !strcmp(dev->tag, devtag) && (device_index++ == id)) |
| 1767 | iodev = mess_device_from_core_device(dev); |
| 1768 | if ((iodev != NULL) && (iodev->tag != NULL) && !strcmp(iodev->tag, devtag) && (iodev->index_in_device == id)) |
| 1780 | 1769 | { |
| 1781 | | image = dev->devconfig; |
| 1770 | image = dev; |
| 1782 | 1771 | break; |
| 1783 | 1772 | } |
| 1784 | | indx++; |
| 1785 | 1773 | } |
| 1786 | 1774 | |
| 1787 | 1775 | assert(image != NULL); |
| r2203 | r2204 | |
| 1792 | 1780 | |
| 1793 | 1781 | const device_config *image_from_devtype_and_index(iodevice_t type, int id) |
| 1794 | 1782 | { |
| 1795 | | int indx; |
| 1796 | 1783 | const device_config *image = NULL; |
| 1797 | | const struct IODevice *dev; |
| 1798 | | int device_index; |
| 1784 | const device_config *dev; |
| 1785 | const struct IODevice *iodev; |
| 1799 | 1786 | |
| 1800 | 1787 | assert((Machine->images_data->multiple_dev_mask & (1 << type)) == 0); |
| 1801 | 1788 | assert(id < device_count(Machine, type)); |
| 1802 | 1789 | |
| 1803 | | indx = 0; |
| 1804 | | device_index = 0; |
| 1805 | | for (dev = mess_device_first_from_machine(Machine); dev != NULL; dev = mess_device_next(dev)) |
| 1790 | for (dev = image_device_first(Machine->config); dev != NULL; dev = image_device_next(dev)) |
| 1806 | 1791 | { |
| 1807 | | if ((type == dev->type) && (device_index++ == id)) |
| 1792 | iodev = mess_device_from_core_device(dev); |
| 1793 | if ((iodev != NULL) && (type == iodev->type) && (iodev->index_in_device == id)) |
| 1808 | 1794 | { |
| 1809 | | image = dev->devconfig; |
| 1795 | image = dev; |
| 1810 | 1796 | break; |
| 1811 | 1797 | } |
| 1812 | | indx++; |
| 1813 | 1798 | } |
| 1814 | 1799 | |
| 1815 | 1800 | assert(image); |
src/mess/device.c
| r2203 | r2204 | |
| 197 | 197 | |
| 198 | 198 | static DEVICE_START(mess_device) |
| 199 | 199 | { |
| 200 | mess_device_config *mess_device = (mess_device_config *) device->inline_config; |
| 201 | |
| 202 | /* if present, invoke the start handler */ |
| 203 | if (mess_device->io_device.start != NULL) |
| 204 | (*mess_device->io_device.start)(device); |
| 200 | 205 | } |
| 201 | 206 | |
| 202 | 207 | |
| r2203 | r2204 | |
| 225 | 230 | case DEVINFO_FCT_IMAGE_LOAD: info->f = mess_device_get_info_fct(&mess_device->io_device.devclass, MESS_DEVINFO_PTR_LOAD); break; |
| 226 | 231 | case DEVINFO_FCT_IMAGE_CREATE: info->f = mess_device_get_info_fct(&mess_device->io_device.devclass, MESS_DEVINFO_PTR_CREATE); break; |
| 227 | 232 | case DEVINFO_FCT_IMAGE_UNLOAD: info->f = mess_device_get_info_fct(&mess_device->io_device.devclass, MESS_DEVINFO_PTR_UNLOAD); break; |
| 233 | case DEVINFO_FCT_DISPLAY: info->f = mess_device_get_info_fct(&mess_device->io_device.devclass, MESS_DEVINFO_PTR_DISPLAY); break; |
| 228 | 234 | |
| 229 | 235 | /* --- the following bits of info are returned as NULL-terminated strings --- */ |
| 230 | 236 | case DEVINFO_STR_NAME: info->s = "Legacy MESS Device"; break; |
| r2203 | r2204 | |
| 370 | 376 | mess_device->io_device.imgverify = (device_image_verify_func) mess_device_get_info_fct(&mess_device->io_device.devclass, MESS_DEVINFO_PTR_VERIFY); |
| 371 | 377 | mess_device->io_device.partialhash = (device_image_partialhash_func) mess_device_get_info_fct(&mess_device->io_device.devclass, MESS_DEVINFO_PTR_PARTIAL_HASH); |
| 372 | 378 | |
| 373 | | mess_device->io_device.display = (device_display_func) mess_device_get_info_fct(&mess_device->io_device.devclass, MESS_DEVINFO_PTR_DISPLAY); |
| 374 | 379 | mess_device->io_device.name = default_device_name; |
| 375 | 380 | |
| 376 | 381 | mess_device->io_device.createimage_optguide = (const struct OptionGuide *) mess_device_get_info_ptr(&mess_device->io_device.devclass, MESS_DEVINFO_PTR_CREATE_OPTGUIDE); |
| r2203 | r2204 | |
| 483 | 488 | |
| 484 | 489 | /************************************* |
| 485 | 490 | * |
| 486 | | * Device enumeration |
| 487 | | * |
| 488 | | *************************************/ |
| 489 | | |
| 490 | | const struct IODevice *mess_device_first_from_machine(const running_machine *machine) |
| 491 | | { |
| 492 | | const device_config *devconfig; |
| 493 | | devconfig = device_list_first(machine->config->devicelist, MESS_DEVICE); |
| 494 | | return (devconfig != NULL) ? devconfig->inline_config : NULL; |
| 495 | | } |
| 496 | | |
| 497 | | |
| 498 | | |
| 499 | | const struct IODevice *mess_device_next(const struct IODevice *dev) |
| 500 | | { |
| 501 | | const device_config *devconfig; |
| 502 | | devconfig = device_list_next(dev->devconfig, MESS_DEVICE); |
| 503 | | return (devconfig != NULL) ? devconfig->inline_config : NULL; |
| 504 | | } |
| 505 | | |
| 506 | | |
| 507 | | |
| 508 | | /************************************* |
| 509 | | * |
| 510 | 491 | * Device lookup |
| 511 | 492 | * |
| 512 | 493 | *************************************/ |