src/mess/mess.c
| r2209 | r2210 | |
| 102 | 102 | |
| 103 | 103 | |
| 104 | 104 | /*------------------------------------------------- |
| 105 | | devices_init - initialize devices for a specific |
| 105 | mess_predevice_init - initialize devices for a specific |
| 106 | 106 | running_machine |
| 107 | 107 | -------------------------------------------------*/ |
| 108 | 108 | |
| 109 | | void devices_init(running_machine *machine) |
| 109 | void mess_predevice_init(running_machine *machine) |
| 110 | 110 | { |
| 111 | | const struct IODevice *dev; |
| 112 | | int result = INIT_FAIL; |
| 113 | | const char *image_name; |
| 114 | | const device_config *image; |
| 115 | | |
| 116 | 111 | /* initialize natural keyboard support */ |
| 117 | 112 | inputx_init(machine); |
| 118 | 113 | |
| r2209 | r2210 | |
| 121 | 116 | |
| 122 | 117 | /* initialize RAM code */ |
| 123 | 118 | ram_init(machine->gamedrv); |
| 119 | } |
| 124 | 120 | |
| 121 | |
| 122 | |
| 123 | /*------------------------------------------------- |
| 124 | mess_postdevice_init - initialize devices for a specific |
| 125 | running_machine |
| 126 | -------------------------------------------------*/ |
| 127 | |
| 128 | void mess_postdevice_init(running_machine *machine) |
| 129 | { |
| 130 | const struct IODevice *dev; |
| 131 | int result = INIT_FAIL; |
| 132 | const char *image_name; |
| 133 | const device_config *image; |
| 134 | |
| 125 | 135 | /* init all devices */ |
| 126 | 136 | image_init(machine); |
| 127 | 137 | |
src/mess/image.c
| r2209 | r2210 | |
| 19 | 19 | #include "unzip.h" |
| 20 | 20 | #include "devices/flopdrv.h" |
| 21 | 21 | #include "utils.h" |
| 22 | | #include "tagpool.h" |
| 23 | 22 | #include "hashfile.h" |
| 24 | 23 | #include "mamecore.h" |
| 25 | 24 | #include "messopts.h" |
| r2209 | r2210 | |
| 34 | 33 | struct _image_slot_data |
| 35 | 34 | { |
| 36 | 35 | /* variables that persist across image mounts */ |
| 37 | | tag_pool tagpool; |
| 38 | 36 | object_pool *mempool; |
| 39 | 37 | const device_config *dev; |
| 40 | 38 | |
| r2209 | r2210 | |
| 162 | 160 | { |
| 163 | 161 | slot = &machine->images_data->slots[indx]; |
| 164 | 162 | |
| 165 | | /* interim changes until we use the normal device->start */ |
| 166 | | ((device_config *) dev)->machine = machine; |
| 167 | | ((device_config *) dev)->token = (void *) ~0; |
| 168 | | |
| 169 | 163 | /* create a memory pool */ |
| 170 | | machine->images_data->slots[indx].mempool = pool_alloc(memory_error); |
| 164 | slot->mempool = pool_alloc(memory_error); |
| 171 | 165 | |
| 172 | 166 | /* setup the device */ |
| 173 | | tagpool_init(&slot->tagpool); |
| 174 | 167 | machine->images_data->slots[indx].dev = dev; |
| 175 | 168 | |
| 176 | 169 | /* callbacks */ |
| r2209 | r2210 | |
| 178 | 171 | slot->create = (device_image_create_func) device_get_info_fct(slot->dev, DEVINFO_FCT_IMAGE_CREATE); |
| 179 | 172 | slot->unload = (device_image_unload_func) device_get_info_fct(slot->dev, DEVINFO_FCT_IMAGE_UNLOAD); |
| 180 | 173 | |
| 181 | | /* invoke start, if present */ |
| 182 | | if (dev->start != NULL) |
| 183 | | { |
| 184 | | dev->start(slot->dev); |
| 185 | | } |
| 186 | 174 | indx++; |
| 187 | | |
| 188 | | /* interim changes until we use the normal device->start */ |
| 189 | | ((device_config *) dev)->token = NULL; |
| 190 | 175 | } |
| 191 | 176 | |
| 192 | 177 | add_exit_callback(machine, image_exit); |
| r2209 | r2210 | |
| 206 | 191 | |
| 207 | 192 | if (machine->images_data != NULL) |
| 208 | 193 | { |
| 209 | | /* interim hack until we use normal device startup/shutdown */ |
| 210 | | for (i = 0; i < machine->images_data->slot_count; i++) |
| 211 | | { |
| 212 | | ((device_config *) machine->images_data->slots[i].dev)->machine = machine; |
| 213 | | } |
| 214 | | |
| 215 | 194 | /* unload all devices */ |
| 216 | 195 | image_unload_all(FALSE); |
| 217 | 196 | image_unload_all(TRUE); |
| r2209 | r2210 | |
| 221 | 200 | /* identify the image slot */ |
| 222 | 201 | slot = &machine->images_data->slots[i]; |
| 223 | 202 | |
| 224 | | /* free the tagpool */ |
| 225 | | tagpool_exit(&slot->tagpool); |
| 226 | | |
| 227 | 203 | /* free the working directory */ |
| 228 | 204 | if (slot->working_directory != NULL) |
| 229 | 205 | { |
| r2209 | r2210 | |
| 236 | 212 | slot->mempool = NULL; |
| 237 | 213 | } |
| 238 | 214 | |
| 239 | | /* interim hack until we use normal device startup/shutdown */ |
| 240 | | for (i = 0; i < machine->images_data->slot_count; i++) |
| 241 | | { |
| 242 | | ((device_config *) machine->images_data->slots[i].dev)->machine = NULL; |
| 243 | | } |
| 244 | | |
| 245 | 215 | machine->images_data = NULL; |
| 246 | 216 | } |
| 247 | 217 | } |
| r2209 | r2210 | |
| 964 | 934 | |
| 965 | 935 | |
| 966 | 936 | /**************************************************************************** |
| 967 | | Tag management functions. |
| 968 | | |
| 969 | | When devices have private data structures that need to be associated with a |
| 970 | | device, it is recommended that image_alloctag() be called in the device |
| 971 | | init function. If the allocation succeeds, then a pointer will be returned |
| 972 | | to a block of memory of the specified size that will last for the lifetime |
| 973 | | of the emulation. This pointer can be retrieved with image_lookuptag(). |
| 974 | | |
| 975 | | Note that since image_lookuptag() is used to index preallocated blocks of |
| 976 | | memory, image_lookuptag() cannot fail legally. In fact, an assert will be |
| 977 | | raised if this happens |
| 978 | | ****************************************************************************/ |
| 979 | | |
| 980 | | void *image_alloctag(const device_config *image, const char *tag, size_t size) |
| 981 | | { |
| 982 | | image_slot_data *slot = find_image_slot(image); |
| 983 | | void *ptr = tagpool_alloc(&slot->tagpool, tag, size); |
| 984 | | if (ptr == NULL) |
| 985 | | { |
| 986 | | memory_error("Out of memory"); |
| 987 | | } |
| 988 | | return ptr; |
| 989 | | } |
| 990 | | |
| 991 | | |
| 992 | | |
| 993 | | void *image_lookuptag(const device_config *image, const char *tag) |
| 994 | | { |
| 995 | | image_slot_data *slot = find_image_slot(image); |
| 996 | | return tagpool_lookup(&slot->tagpool, tag); |
| 997 | | } |
| 998 | | |
| 999 | | |
| 1000 | | |
| 1001 | | /**************************************************************************** |
| 1002 | 937 | Hash info loading |
| 1003 | 938 | |
| 1004 | 939 | If the hash is not checked and the relevant info not loaded, force that info |
src/mess/image.h
| r2209 | r2210 | |
| 102 | 102 | |
| 103 | 103 | |
| 104 | 104 | /**************************************************************************** |
| 105 | | Tag management functions. |
| 106 | | |
| 107 | | When devices have private data structures that need to be associated with a |
| 108 | | device, it is recommended that image_alloctag() be called in the device |
| 109 | | init function. If the allocation succeeds, then a pointer will be returned |
| 110 | | to a block of memory of the specified size that will last for the lifetime |
| 111 | | of the emulation. This pointer can be retrieved with image_lookuptag(). |
| 112 | | |
| 113 | | Note that since image_lookuptag() is used to index preallocated blocks of |
| 114 | | memory, image_lookuptag() cannot fail legally. In fact, an assert will be |
| 115 | | raised if this happens |
| 116 | | ****************************************************************************/ |
| 117 | | |
| 118 | | void *image_alloctag(const device_config *img, const char *tag, size_t size); |
| 119 | | void *image_lookuptag(const device_config *img, const char *tag); |
| 120 | | |
| 121 | | |
| 122 | | |
| 123 | | /**************************************************************************** |
| 124 | 105 | Accessor functions |
| 125 | 106 | |
| 126 | 107 | These provide information about the device; and about the mounted image |
src/mess/device.c
| r2209 | r2210 | |
| 12 | 12 | #include "mslegacy.h" |
| 13 | 13 | #include "driver.h" |
| 14 | 14 | #include "pool.h" |
| 15 | #include "tagpool.h" |
| 15 | 16 | |
| 16 | 17 | |
| 17 | 18 | |
| r2209 | r2210 | |
| 38 | 39 | |
| 39 | 40 | |
| 40 | 41 | |
| 42 | typedef struct _mess_device_token mess_device_token; |
| 43 | struct _mess_device_token |
| 44 | { |
| 45 | tag_pool tagpool; |
| 46 | }; |
| 47 | |
| 48 | |
| 49 | |
| 41 | 50 | struct Devices |
| 42 | 51 | { |
| 43 | 52 | iodevice_t type; |
| r2209 | r2210 | |
| 198 | 207 | static DEVICE_START(mess_device) |
| 199 | 208 | { |
| 200 | 209 | mess_device_config *mess_device = (mess_device_config *) device->inline_config; |
| 210 | mess_device_token *token = (mess_device_token *) device->token; |
| 201 | 211 | |
| 212 | /* initialize the tag pool */ |
| 213 | tagpool_init(&token->tagpool); |
| 214 | |
| 202 | 215 | /* if present, invoke the start handler */ |
| 203 | 216 | if (mess_device->io_device.start != NULL) |
| 204 | 217 | (*mess_device->io_device.start)(device); |
| r2209 | r2210 | |
| 207 | 220 | |
| 208 | 221 | |
| 209 | 222 | /*------------------------------------------------- |
| 223 | DEVICE_STOP(mess_device) - device stop |
| 224 | callback |
| 225 | -------------------------------------------------*/ |
| 226 | |
| 227 | static DEVICE_STOP(mess_device) |
| 228 | { |
| 229 | mess_device_config *mess_device = (mess_device_config *) device->inline_config; |
| 230 | mess_device_token *token = (mess_device_token *) device->token; |
| 231 | |
| 232 | /* if present, invoke the stop handler */ |
| 233 | if (mess_device->io_device.stop != NULL) |
| 234 | (*mess_device->io_device.stop)(device); |
| 235 | |
| 236 | /* tear down the tag pool */ |
| 237 | tagpool_exit(&token->tagpool); |
| 238 | } |
| 239 | |
| 240 | |
| 241 | |
| 242 | /*------------------------------------------------- |
| 210 | 243 | DEVICE_GET_INFO(mess_device) - device get info |
| 211 | 244 | callback |
| 212 | 245 | -------------------------------------------------*/ |
| r2209 | r2210 | |
| 219 | 252 | { |
| 220 | 253 | /* --- the following bits of info are returned as 64-bit signed integers --- */ |
| 221 | 254 | case DEVINFO_INT_INLINE_CONFIG_BYTES: info->i = sizeof(mess_device_config); break; |
| 222 | | case DEVINFO_INT_TOKEN_BYTES: info->i = 1; break; |
| 255 | case DEVINFO_INT_TOKEN_BYTES: info->i = sizeof(mess_device_token); break; |
| 223 | 256 | case DEVINFO_INT_CLASS: info->i = DEVICE_CLASS_OTHER; break; |
| 224 | 257 | |
| 225 | 258 | /* --- the following bits of info are returned as pointers to data or functions --- */ |
| 226 | 259 | case DEVINFO_FCT_SET_INFO: /* Nothing */ break; |
| 227 | 260 | case DEVINFO_FCT_START: info->start = DEVICE_START_NAME(mess_device); break; |
| 228 | | case DEVINFO_FCT_STOP: /* Nothing */ break; |
| 261 | case DEVINFO_FCT_STOP: info->stop = DEVICE_STOP_NAME(mess_device); break; |
| 229 | 262 | case DEVINFO_FCT_RESET: /* Nothing */ break; |
| 230 | 263 | case DEVINFO_FCT_IMAGE_LOAD: info->f = mess_device_get_info_fct(&mess_device->io_device.devclass, MESS_DEVINFO_PTR_LOAD); break; |
| 231 | 264 | case DEVINFO_FCT_IMAGE_CREATE: info->f = mess_device_get_info_fct(&mess_device->io_device.devclass, MESS_DEVINFO_PTR_CREATE); break; |
| r2209 | r2210 | |
| 557 | 590 | |
| 558 | 591 | /************************************* |
| 559 | 592 | * |
| 593 | * Tag management |
| 594 | * |
| 595 | *************************************/ |
| 596 | |
| 597 | static mess_device_token *get_token(const device_config *device) |
| 598 | { |
| 599 | assert(device->type == MESS_DEVICE); |
| 600 | return (mess_device_token *) device->token; |
| 601 | } |
| 602 | |
| 603 | |
| 604 | |
| 605 | void *image_alloctag(const device_config *device, const char *tag, size_t size) |
| 606 | { |
| 607 | void *ptr = tagpool_alloc(&get_token(device)->tagpool, tag, size); |
| 608 | if (ptr == NULL) |
| 609 | { |
| 610 | fatalerror("Out of memory"); |
| 611 | } |
| 612 | return ptr; |
| 613 | } |
| 614 | |
| 615 | |
| 616 | |
| 617 | void *image_lookuptag(const device_config *device, const char *tag) |
| 618 | { |
| 619 | return tagpool_lookup(&get_token(device)->tagpool, tag); |
| 620 | } |
| 621 | |
| 622 | |
| 623 | |
| 624 | /************************************* |
| 625 | * |
| 560 | 626 | * Diagnostics |
| 561 | 627 | * |
| 562 | 628 | *************************************/ |