src/mess/device.c
| r2270 | r2271 | |
| 48 | 48 | |
| 49 | 49 | |
| 50 | 50 | |
| 51 | | struct Devices |
| 51 | typedef struct _mess_device_type_info mess_device_type_info; |
| 52 | struct _mess_device_type_info |
| 52 | 53 | { |
| 53 | 54 | iodevice_t type; |
| 54 | 55 | const char *name; |
| r2270 | r2271 | |
| 63 | 64 | |
| 64 | 65 | /* The List of Devices, with Associated Names - Be careful to ensure that * |
| 65 | 66 | * this list matches the ENUM from device.h, so searches can use IO_COUNT */ |
| 66 | | static const struct Devices device_info_array[] = |
| 67 | static const mess_device_type_info device_info_array[] = |
| 67 | 68 | { |
| 68 | 69 | { IO_CARTSLOT, "cartridge", "cart" }, /* 0 */ |
| 69 | 70 | { IO_FLOPPY, "floppydisk", "flop" }, /* 1 */ |
| r2270 | r2271 | |
| 87 | 88 | CORE IMPLEMENTATION |
| 88 | 89 | ***************************************************************************/ |
| 89 | 90 | |
| 91 | static const mess_device_type_info *find_device_type(iodevice_t type) |
| 92 | { |
| 93 | int i; |
| 94 | for (i = 0; i < ARRAY_LENGTH(device_info_array); i++) |
| 95 | { |
| 96 | if (device_info_array[i].type == type) |
| 97 | return &device_info_array[i]; |
| 98 | } |
| 99 | return NULL; |
| 100 | } |
| 101 | |
| 102 | |
| 103 | |
| 90 | 104 | const char *device_typename(iodevice_t type) |
| 91 | 105 | { |
| 92 | | assert(type >= 0); |
| 93 | | assert(type < IO_COUNT); |
| 94 | | return device_info_array[type].name; |
| 106 | const mess_device_type_info *info = find_device_type(type); |
| 107 | return (info != NULL) ? info->name : NULL; |
| 95 | 108 | } |
| 96 | 109 | |
| 97 | 110 | |
| 98 | 111 | |
| 99 | 112 | const char *device_brieftypename(iodevice_t type) |
| 100 | 113 | { |
| 101 | | assert(type >= 0); |
| 102 | | assert(type < IO_COUNT); |
| 103 | | return device_info_array[type].shortname; |
| 114 | const mess_device_type_info *info = find_device_type(type); |
| 115 | return (info != NULL) ? info->shortname : NULL; |
| 104 | 116 | } |
| 105 | 117 | |
| 106 | 118 | |
| 107 | 119 | |
| 108 | | int device_typeid(const char *name) |
| 120 | iodevice_t device_typeid(const char *name) |
| 109 | 121 | { |
| 110 | 122 | int i; |
| 111 | 123 | for (i = 0; i < sizeof(device_info_array) / sizeof(device_info_array[0]); i++) |
| 112 | 124 | { |
| 113 | 125 | if (!mame_stricmp(name, device_info_array[i].name) || !mame_stricmp(name, device_info_array[i].shortname)) |
| 114 | | return i; |
| 126 | return device_info_array[i].type; |
| 115 | 127 | } |
| 116 | 128 | return -1; |
| 117 | 129 | } |
| r2270 | r2271 | |
| 714 | 726 | int error = 0; |
| 715 | 727 | int i; |
| 716 | 728 | |
| 717 | | if ((sizeof(device_info_array) / sizeof(device_info_array[0])) != IO_COUNT) |
| 718 | | { |
| 719 | | mame_printf_error("device_info_array array should match size of IO_* enum\n"); |
| 720 | | error = 1; |
| 721 | | } |
| 722 | | |
| 723 | 729 | /* Check the device struct array */ |
| 724 | 730 | for (i = 0; i < sizeof(device_info_array) / sizeof(device_info_array[0]); i++) |
| 725 | 731 | { |
| 726 | | if (device_info_array[i].type != i) |
| 727 | | { |
| 728 | | mame_printf_error("Device struct array order mismatch\n"); |
| 729 | | error = 1; |
| 730 | | break; |
| 731 | | } |
| 732 | | |
| 733 | 732 | if (!device_info_array[i].name) |
| 734 | 733 | { |
| 735 | 734 | mame_printf_error("device_info_array[%d].name appears to be NULL\n", i); |