src/mess/image.c
| r2322 | r2323 | |
| 379 | 379 | extensions used by a device |
| 380 | 380 | -------------------------------------------------*/ |
| 381 | 381 | |
| 382 | | static void get_device_file_extensions(const device_config *device, char *buffer, size_t buffer_len) |
| 382 | static void get_device_file_extensions(const device_config *device, |
| 383 | char *buffer, size_t buffer_len) |
| 383 | 384 | { |
| 384 | 385 | const char *file_extensions; |
| 385 | 386 | char *s; |
| r2322 | r2323 | |
| 401 | 402 | |
| 402 | 403 | |
| 403 | 404 | /*------------------------------------------------- |
| 405 | get_device_instance_name - retrieves the device |
| 406 | instance name or brief instance name |
| 407 | -------------------------------------------------*/ |
| 408 | |
| 409 | static void get_device_instance_name(const machine_config *config, const device_config *device, |
| 410 | char *buffer, size_t buffer_len, iodevice_t type, UINT32 state, const char *(*get_dev_typename)(iodevice_t)) |
| 411 | { |
| 412 | const char *result; |
| 413 | const device_config *that_device; |
| 414 | int count, index; |
| 415 | |
| 416 | /* retrieve info about the device instance */ |
| 417 | result = device_get_info_string_offline(device, state); |
| 418 | if (result != NULL) |
| 419 | { |
| 420 | /* we got info directly */ |
| 421 | snprintf(buffer, buffer_len, "%s", result); |
| 422 | } |
| 423 | else |
| 424 | { |
| 425 | /* not specified? default to device names based on the device type */ |
| 426 | result = get_dev_typename(type); |
| 427 | |
| 428 | /* are there multiple devices of the same type */ |
| 429 | count = 0; |
| 430 | index = -1; |
| 431 | for (that_device = image_device_first(config); that_device != NULL; that_device = image_device_next(that_device)) |
| 432 | { |
| 433 | if (device == that_device) |
| 434 | index = count; |
| 435 | if (device_get_info_int_offline(device, DEVINFO_INT_IMAGE_TYPE) == type) |
| 436 | count++; |
| 437 | } |
| 438 | |
| 439 | /* need to number if there is more than one device */ |
| 440 | if (that_device != NULL) |
| 441 | snprintf(buffer, buffer_len, "%s #%d", result, index + 1); |
| 442 | else |
| 443 | snprintf(buffer, buffer_len, "%s", result); |
| 444 | } |
| 445 | } |
| 446 | |
| 447 | |
| 448 | |
| 449 | /*------------------------------------------------- |
| 404 | 450 | image_device_getinfo - returns info on a device; |
| 405 | 451 | can be called by front end code |
| 406 | 452 | -------------------------------------------------*/ |
| 407 | 453 | |
| 408 | 454 | image_device_info image_device_getinfo(const machine_config *config, const device_config *device) |
| 409 | 455 | { |
| 410 | | const struct IODevice *iodev; |
| 411 | | const char *s; |
| 412 | 456 | image_device_info info; |
| 413 | 457 | |
| 414 | 458 | /* sanity checks */ |
| r2322 | r2323 | |
| 432 | 476 | /* retrieve file extensions */ |
| 433 | 477 | get_device_file_extensions(device, info.file_extensions, ARRAY_LENGTH(info.file_extensions)); |
| 434 | 478 | |
| 435 | | iodev = mess_device_from_core_device(device); |
| 436 | | if (iodev != NULL) |
| 437 | | { |
| 438 | | /* retrieve instance name */ |
| 439 | | s = device_instancename(&iodev->devclass, iodev->index_in_device); |
| 440 | | snprintf(info.instance_name, ARRAY_LENGTH(info.instance_name), "%s", s); |
| 479 | /* retrieve instance name */ |
| 480 | get_device_instance_name(config, device, info.instance_name, ARRAY_LENGTH(info.instance_name), |
| 481 | info.type, DEVINFO_STR_IMAGE_INSTANCE_NAME, device_typename); |
| 441 | 482 | |
| 442 | | /* retrieve brief instance name */ |
| 443 | | s = device_briefinstancename(&iodev->devclass, iodev->index_in_device); |
| 444 | | snprintf(info.brief_instance_name, ARRAY_LENGTH(info.brief_instance_name), "%s", s); |
| 445 | | } |
| 483 | /* retrieve brief instance name */ |
| 484 | get_device_instance_name(config, device, info.brief_instance_name, ARRAY_LENGTH(info.brief_instance_name), |
| 485 | info.type, DEVINFO_STR_IMAGE_BRIEF_INSTANCE_NAME, device_brieftypename); |
| 446 | 486 | |
| 447 | 487 | return info; |
| 448 | 488 | } |
src/mess/device.c
| r2322 | r2323 | |
| 130 | 130 | |
| 131 | 131 | |
| 132 | 132 | |
| 133 | | static const char *internal_device_instancename(const mess_device_class *devclass, int id, |
| 134 | | UINT32 base, const char *(*get_dev_typename)(iodevice_t)) |
| 135 | | { |
| 136 | | iodevice_t type; |
| 137 | | int count; |
| 138 | | const char *result; |
| 139 | | char *s; |
| 140 | | |
| 141 | | /* retrieve info about the device instance */ |
| 142 | | result = mess_device_get_info_string(devclass, base + id); |
| 143 | | if (!result) |
| 144 | | { |
| 145 | | /* not specified? default to device names based on the device type */ |
| 146 | | type = (iodevice_t) (int) mess_device_get_info_int(devclass, MESS_DEVINFO_INT_TYPE); |
| 147 | | count = (int) mess_device_get_info_int(devclass, MESS_DEVINFO_INT_COUNT); |
| 148 | | result = get_dev_typename(type); |
| 149 | | |
| 150 | | /* need to number if there is more than one device */ |
| 151 | | if (count > 1) |
| 152 | | { |
| 153 | | s = device_temp_str(); |
| 154 | | sprintf(s, "%s%d", result, id + 1); |
| 155 | | result = s; |
| 156 | | } |
| 157 | | } |
| 158 | | return result; |
| 159 | | } |
| 160 | | |
| 161 | | |
| 162 | | |
| 163 | | const char *device_instancename(const mess_device_class *devclass, int id) |
| 164 | | { |
| 165 | | return internal_device_instancename(devclass, id, MESS_DEVINFO_STR_NAME, device_typename); |
| 166 | | } |
| 167 | | |
| 168 | | |
| 169 | | |
| 170 | | const char *device_briefinstancename(const mess_device_class *devclass, int id) |
| 171 | | { |
| 172 | | return internal_device_instancename(devclass, id, MESS_DEVINFO_STR_SHORT_NAME, device_brieftypename); |
| 173 | | } |
| 174 | | |
| 175 | | |
| 176 | | |
| 177 | 133 | /************************************* |
| 178 | 134 | * |
| 179 | 135 | * Device structure construction and destruction |
| r2322 | r2323 | |
| 298 | 254 | case DEVINFO_STR_SOURCE_FILE: info->s = __FILE__; break; |
| 299 | 255 | case DEVINFO_STR_CREDITS: info->s = "Copyright the MESS Team"; break; |
| 300 | 256 | case DEVINFO_STR_IMAGE_FILE_EXTENSIONS: info->s = mess_device_get_info_string(&mess_device->io_device.devclass, MESS_DEVINFO_STR_FILE_EXTENSIONS); break; |
| 257 | case DEVINFO_STR_IMAGE_INSTANCE_NAME: info->s = mess_device_get_info_string(&mess_device->io_device.devclass, MESS_DEVINFO_STR_NAME); break; |
| 258 | case DEVINFO_STR_IMAGE_BRIEF_INSTANCE_NAME: info->s = mess_device_get_info_string(&mess_device->io_device.devclass, MESS_DEVINFO_STR_SHORT_NAME); break; |
| 301 | 259 | } |
| 302 | 260 | } |
| 303 | 261 | |