src/mess/image.c
| r2226 | r2227 | |
| 74 | 74 | |
| 75 | 75 | struct _images_private |
| 76 | 76 | { |
| 77 | | UINT32 multiple_dev_mask; |
| 78 | 77 | int slot_count; |
| 79 | 78 | image_slot_data slots[1]; |
| 80 | 79 | }; |
| r2226 | r2227 | |
| 114 | 113 | void image_init(running_machine *machine) |
| 115 | 114 | { |
| 116 | 115 | int count, indx; |
| 117 | | UINT32 mask, dev_mask = 0, multiple_dev_mask = 0; |
| 118 | 116 | const device_config *dev; |
| 119 | | const struct IODevice *iodev; |
| 120 | 117 | size_t private_size; |
| 121 | 118 | image_slot_data *slot; |
| 122 | 119 | |
| r2226 | r2227 | |
| 125 | 122 | assert(DEVINFO_FCT_IMAGE_LAST < DEVINFO_FCT_DEVICE_SPECIFIC); |
| 126 | 123 | |
| 127 | 124 | /* first count all images, and identify multiply defined devices */ |
| 128 | | count = 0; |
| 129 | | for (dev = image_device_first(machine->config); dev != NULL; dev = image_device_next(dev)) |
| 130 | | { |
| 131 | | /* weird check only relevant on the first legacy MESS device */ |
| 132 | | iodev = mess_device_from_core_device(dev); |
| 133 | | if ((iodev != NULL) && (iodev->index_in_device == 0)) |
| 134 | | { |
| 135 | | /* check to see if this device type is used multiple times */ |
| 136 | | mask = 1 << iodev->type; |
| 137 | | if (dev_mask & mask) |
| 138 | | multiple_dev_mask |= mask; |
| 139 | | else |
| 140 | | dev_mask |= mask; |
| 141 | | } |
| 125 | count = image_device_count(machine->config); |
| 142 | 126 | |
| 143 | | /* increment the count */ |
| 144 | | count++; |
| 145 | | } |
| 146 | | |
| 147 | 127 | /* allocate the private structure */ |
| 148 | 128 | private_size = sizeof(*machine->images_data) + ((count - 1) |
| 149 | 129 | * sizeof(machine->images_data->slots[0])); |
| r2226 | r2227 | |
| 151 | 131 | memset(machine->images_data, '\0', private_size); |
| 152 | 132 | |
| 153 | 133 | /* some setup */ |
| 154 | | machine->images_data->multiple_dev_mask = multiple_dev_mask; |
| 155 | 134 | machine->images_data->slot_count = count; |
| 156 | 135 | |
| 157 | 136 | /* initialize the devices */ |
src/mess/device.c
| r2226 | r2227 | |
| 681 | 681 | const device_config *dev; |
| 682 | 682 | const struct IODevice *iodev; |
| 683 | 683 | |
| 684 | | assert((Machine->images_data->multiple_dev_mask & (1 << type)) == 0); |
| 685 | 684 | assert(id < device_count(Machine, type)); |
| 686 | 685 | |
| 687 | 686 | for (dev = device_list_first(Machine->config->devicelist, MESS_DEVICE); dev != NULL; dev = device_list_next(dev, MESS_DEVICE)) |
| r2226 | r2227 | |
| 689 | 688 | iodev = mess_device_from_core_device(dev); |
| 690 | 689 | if ((type == iodev->type) && (iodev->index_in_device == id)) |
| 691 | 690 | { |
| 691 | /* if 'image' is not null, that means that there are multiple devices of this iodevice_t type */ |
| 692 | assert(image == NULL); |
| 693 | |
| 692 | 694 | image = dev; |
| 693 | 695 | break; |
| 694 | 696 | } |
| 695 | 697 | } |
| 696 | 698 | |
| 697 | | assert(image); |
| 699 | /* by calling this function, the caller assumes that there will be a matching device */ |
| 700 | assert(image != NULL); |
| 698 | 701 | return image; |
| 699 | 702 | } |
| 700 | 703 | |