src/mess/messopts.c
| r2290 | r2291 | |
| 65 | 65 | for all devices on a driver |
| 66 | 66 | -------------------------------------------------*/ |
| 67 | 67 | |
| 68 | | static void mess_enumerate_devices(core_options *opts, const game_driver *gamedrv, |
| 69 | | void (*proc)(core_options *opts, const game_driver *gamedrv, const mess_device_class *devclass, int device_index, int global_index)) |
| 68 | static void mess_enumerate_devices(core_options *opts, const machine_config *config, const game_driver *gamedrv, |
| 69 | void (*proc)(core_options *opts, const game_driver *gamedrv, const device_config *device, int global_index)) |
| 70 | 70 | { |
| 71 | | struct SystemConfigurationParamBlock cfg; |
| 72 | | device_getinfo_handler handlers[64]; |
| 73 | | int count_overrides[ARRAY_LENGTH(handlers)]; |
| 74 | | int i, j, count, index = 0; |
| 75 | | mess_device_class devclass; |
| 71 | const device_config *device; |
| 72 | int index = 0; |
| 76 | 73 | |
| 77 | | /* retrieve getinfo handlers */ |
| 78 | | memset(&cfg, 0, sizeof(cfg)); |
| 79 | | memset(handlers, 0, sizeof(handlers)); |
| 80 | | cfg.device_slotcount = sizeof(handlers) / sizeof(handlers[0]); |
| 81 | | cfg.device_handlers = handlers; |
| 82 | | cfg.device_countoverrides = count_overrides; |
| 83 | | if (gamedrv->sysconfig_ctor) |
| 84 | | gamedrv->sysconfig_ctor(&cfg); |
| 85 | | |
| 86 | | /* run this on all devices */ |
| 87 | | for (i = 0; handlers[i]; i++) |
| 74 | /* loop on each device instance */ |
| 75 | for (device = image_device_first(config); device != NULL; device = image_device_next(device)) |
| 88 | 76 | { |
| 89 | | /* create the device class */ |
| 90 | | memset(&devclass, 0, sizeof(devclass)); |
| 91 | | devclass.gamedrv = gamedrv; |
| 92 | | devclass.get_info = handlers[i]; |
| 93 | | |
| 94 | | /* how many of this device exist? */ |
| 95 | | count = (int) mess_device_get_info_int(&devclass, MESS_DEVINFO_INT_COUNT); |
| 96 | | |
| 97 | | /* loop on each device instance */ |
| 98 | | for (j = 0; j < count; j++) |
| 99 | | { |
| 100 | | proc(opts, gamedrv, &devclass, j, index++); |
| 101 | | } |
| 77 | proc(opts, gamedrv, device, index++); |
| 102 | 78 | } |
| 103 | 79 | } |
| 104 | 80 | |
| r2290 | r2291 | |
| 110 | 86 | -------------------------------------------------*/ |
| 111 | 87 | |
| 112 | 88 | static void add_device_options_for_device(core_options *opts, const game_driver *gamedrv, |
| 113 | | const mess_device_class *devclass, int device_index, int global_index) |
| 89 | const device_config *device, int global_index) |
| 114 | 90 | { |
| 91 | image_device_info info; |
| 115 | 92 | options_entry this_entry[2]; |
| 116 | | const char *dev_name; |
| 117 | | const char *dev_short_name; |
| 118 | 93 | char dev_full_name[128]; |
| 119 | 94 | |
| 120 | 95 | /* first device? add the header as to be pretty */ |
| r2290 | r2291 | |
| 127 | 102 | } |
| 128 | 103 | |
| 129 | 104 | /* retrieve info about the device instance */ |
| 130 | | dev_name = device_instancename(devclass, device_index); |
| 131 | | dev_short_name = device_briefinstancename(devclass, device_index); |
| 105 | info = image_device_getinfo(device); |
| 132 | 106 | snprintf(dev_full_name, sizeof(dev_full_name) / sizeof(dev_full_name[0]), |
| 133 | | "%s;%s", dev_name, dev_short_name); |
| 107 | "%s;%s", info.instance_name, info.brief_instance_name); |
| 134 | 108 | |
| 135 | 109 | /* add the option */ |
| 136 | 110 | memset(this_entry, 0, sizeof(this_entry)); |
| r2290 | r2291 | |
| 147 | 121 | |
| 148 | 122 | void mess_add_device_options(core_options *opts, const game_driver *driver) |
| 149 | 123 | { |
| 124 | machine_config *config; |
| 125 | |
| 126 | /* create the configuration */ |
| 127 | config = machine_config_alloc_with_mess_devices(driver); |
| 128 | |
| 150 | 129 | /* enumerate our callback for every device */ |
| 151 | | mess_enumerate_devices(opts, driver, add_device_options_for_device); |
| 130 | mess_enumerate_devices(opts, config, driver, add_device_options_for_device); |
| 152 | 131 | |
| 153 | 132 | /* record that we've added device options */ |
| 154 | 133 | options_set_bool(opts, OPTION_ADDED_DEVICE_OPTIONS, TRUE, OPTION_PRIORITY_CMDLINE); |
| 134 | |
| 135 | /* free the configuration */ |
| 136 | machine_config_free(config); |
| 155 | 137 | } |
| 156 | 138 | |
| 157 | 139 | |
| r2290 | r2291 | |
| 204 | 186 | -------------------------------------------------*/ |
| 205 | 187 | |
| 206 | 188 | static void extract_device_options_for_device(core_options *opts, const game_driver *gamedrv, |
| 207 | | const mess_device_class *devclass, int device_index, int global_index) |
| 189 | const device_config *device, int global_index) |
| 208 | 190 | { |
| 209 | | const device_config *image; |
| 210 | | iodevice_t dev_type; |
| 211 | | const char *dev_tag; |
| 212 | | const char *dev_name; |
| 191 | image_device_info info; |
| 213 | 192 | const char *filename; |
| 214 | 193 | |
| 215 | 194 | assert_always(options_get_bool(opts, OPTION_ADDED_DEVICE_OPTIONS), "extract_device_options_for_device() called without device options"); |
| 216 | 195 | |
| 217 | | /* identify the correct image */ |
| 218 | | dev_tag = mess_device_get_info_string(devclass, MESS_DEVINFO_STR_DEV_TAG); |
| 219 | | if (dev_tag != NULL) |
| 220 | | { |
| 221 | | image = image_from_devtag_and_index(Machine, dev_tag, device_index); |
| 222 | | } |
| 223 | | else |
| 224 | | { |
| 225 | | dev_type = (iodevice_t) (int) mess_device_get_info_int(devclass, MESS_DEVINFO_INT_TYPE); |
| 226 | | image = image_from_devtype_and_index(dev_type, device_index); |
| 227 | | } |
| 228 | | |
| 229 | 196 | /* access the filename */ |
| 230 | | filename = image_filename(image); |
| 197 | filename = image_filename(device); |
| 231 | 198 | |
| 232 | | /* identify the option name */ |
| 233 | | dev_name = device_instancename(devclass, device_index); |
| 199 | /* access other info */ |
| 200 | info = image_device_getinfo(device); |
| 234 | 201 | |
| 235 | 202 | /* and set the option */ |
| 236 | | options_set_string(opts, dev_name, filename ? filename : "", OPTION_PRIORITY_CMDLINE); |
| 203 | options_set_string(opts, info.instance_name, filename ? filename : "", OPTION_PRIORITY_CMDLINE); |
| 237 | 204 | } |
| 238 | 205 | |
| 239 | 206 | |
| r2290 | r2291 | |
| 280 | 247 | { |
| 281 | 248 | /* only extract the device options if we've added them */ |
| 282 | 249 | if (options_get_bool(mame_options(), OPTION_ADDED_DEVICE_OPTIONS)) |
| 283 | | mess_enumerate_devices(mame_options(), machine->gamedrv, extract_device_options_for_device); |
| 250 | mess_enumerate_devices(mame_options(), machine->config, machine->gamedrv, extract_device_options_for_device); |
| 284 | 251 | |
| 285 | 252 | /* write the config, if appropriate */ |
| 286 | 253 | if (options_get_bool(mame_options(), OPTION_WRITECONFIG)) |