src/mess/mesvalid.c
| r1328 | r1329 | |
| 14 | 14 | #include "inputx.h" |
| 15 | 15 | |
| 16 | 16 | |
| 17 | /************************************* |
| 18 | * |
| 19 | * Validate devices |
| 20 | * |
| 21 | *************************************/ |
| 22 | |
| 17 | 23 | static int validate_device(const device_class *devclass) |
| 18 | 24 | { |
| 19 | 25 | int error = 0; |
| r1328 | r1329 | |
| 178 | 184 | |
| 179 | 185 | |
| 180 | 186 | |
| 187 | static int validate_driver_devices(const game_driver *drv) |
| 188 | { |
| 189 | int error = 0; |
| 190 | int i; |
| 191 | struct SystemConfigurationParamBlock cfg; |
| 192 | device_getinfo_handler handlers[64]; |
| 193 | device_class devclass; |
| 194 | int count_overrides[sizeof(handlers) / sizeof(handlers[0])]; |
| 195 | |
| 196 | if (drv->sysconfig_ctor) |
| 197 | { |
| 198 | memset(&cfg, 0, sizeof(cfg)); |
| 199 | memset(handlers, 0, sizeof(handlers)); |
| 200 | cfg.device_slotcount = sizeof(handlers) / sizeof(handlers[0]); |
| 201 | cfg.device_handlers = handlers; |
| 202 | cfg.device_countoverrides = count_overrides; |
| 203 | drv->sysconfig_ctor(&cfg); |
| 204 | |
| 205 | for (i = 0; handlers[i]; i++) |
| 206 | { |
| 207 | devclass.gamedrv = drv; |
| 208 | devclass.get_info = handlers[i]; |
| 209 | |
| 210 | error = validate_device(&devclass) || error; |
| 211 | } |
| 212 | } |
| 213 | return error; |
| 214 | } |
| 215 | |
| 216 | |
| 217 | |
| 218 | /************************************* |
| 219 | * |
| 220 | * Validate compatibility chain |
| 221 | * |
| 222 | *************************************/ |
| 223 | |
| 224 | static int validate_compatibility_chain(const game_driver *drv) |
| 225 | { |
| 226 | int error = 0; |
| 227 | const game_driver *next_drv; |
| 228 | const game_driver *other_drv; |
| 229 | const char *compatible_with; |
| 230 | |
| 231 | /* normalize drv->compatible_with */ |
| 232 | compatible_with = drv->compatible_with; |
| 233 | if ((compatible_with != NULL) && !strcmp(compatible_with, "0")) |
| 234 | compatible_with = NULL; |
| 235 | |
| 236 | /* check for this driver being compatible with a non-existant driver */ |
| 237 | if ((compatible_with != NULL) && (driver_get_name(drv->compatible_with) == NULL)) |
| 238 | { |
| 239 | mame_printf_error("%s: is compatible with %s, which is not in drivers[]\n", drv->name, drv->compatible_with); |
| 240 | error = 1; |
| 241 | } |
| 242 | |
| 243 | /* check for clone_of and compatible_with being specified at the same time */ |
| 244 | if ((driver_get_clone(drv) != NULL) && (compatible_with != NULL)) |
| 245 | { |
| 246 | mame_printf_error("%s: both compatible_with and clone_of are specified\n", drv->name); |
| 247 | error = 1; |
| 248 | } |
| 249 | |
| 250 | /* look for recursive compatibility */ |
| 251 | while(!error && (drv != NULL)) |
| 252 | { |
| 253 | /* identify the next driver */ |
| 254 | next_drv = mess_next_compatible_driver(drv); |
| 255 | |
| 256 | /* find any recursive dependencies on the current driver */ |
| 257 | for (other_drv = next_drv; other_drv != NULL; other_drv = mess_next_compatible_driver(other_drv)) |
| 258 | { |
| 259 | if (drv == other_drv) |
| 260 | { |
| 261 | mame_printf_error("%s: recursive compatibility\n", drv->name); |
| 262 | error = 1; |
| 263 | break; |
| 264 | } |
| 265 | } |
| 266 | |
| 267 | /* advance to next driver */ |
| 268 | drv = next_drv; |
| 269 | } |
| 270 | |
| 271 | return error; |
| 272 | } |
| 273 | |
| 274 | |
| 275 | |
| 276 | |
| 277 | /************************************* |
| 278 | * |
| 279 | * MESS validity checks |
| 280 | * |
| 281 | *************************************/ |
| 282 | |
| 181 | 283 | int mess_validitychecks(void) |
| 182 | 284 | { |
| 183 | | int i, j; |
| 285 | int i; |
| 184 | 286 | int error = 0; |
| 185 | 287 | iodevice_t devtype; |
| 186 | | const struct IODevice *devices; |
| 187 | 288 | const char *name; |
| 188 | 289 | input_port_entry *inputports = NULL; |
| 189 | 290 | extern int device_valididtychecks(void); |
| 190 | 291 | extern const char *mess_default_text[]; |
| 191 | | struct SystemConfigurationParamBlock cfg; |
| 192 | | device_getinfo_handler handlers[64]; |
| 193 | | int count_overrides[sizeof(handlers) / sizeof(handlers[0])]; |
| 194 | | device_class devclass; |
| 195 | 292 | |
| 196 | 293 | /* make sure that all of the UI_* strings are set for all devices */ |
| 197 | 294 | for (devtype = 0; devtype < IO_COUNT; devtype++) |
| r1328 | r1329 | |
| 207 | 304 | /* MESS specific driver validity checks */ |
| 208 | 305 | for (i = 0; drivers[i]; i++) |
| 209 | 306 | { |
| 210 | | devices = devices_allocate(drivers[i]); |
| 211 | | |
| 212 | | /* make sure that there are no clones that reference nonexistant drivers */ |
| 213 | | if (driver_get_clone(drivers[i])) |
| 214 | | { |
| 215 | | if (driver_get_name(drivers[i]->compatible_with) != NULL) |
| 216 | | { |
| 217 | | mame_printf_error("%s: both compatible_with and clone_of are specified\n", drivers[i]->name); |
| 218 | | error = 1; |
| 219 | | } |
| 220 | | |
| 221 | | for (j = 0; drivers[j]; j++) |
| 222 | | { |
| 223 | | if (driver_get_clone(drivers[i]) == drivers[j]) |
| 224 | | break; |
| 225 | | } |
| 226 | | if (!drivers[j]) |
| 227 | | { |
| 228 | | mame_printf_error("%s: is a clone of %s, which is not in drivers[]\n", drivers[i]->name, driver_get_clone(drivers[i])->name); |
| 229 | | error = 1; |
| 230 | | } |
| 231 | | } |
| 232 | | |
| 233 | | /* make sure that there are no clones that reference nonexistant drivers */ |
| 234 | | if (driver_get_name(drivers[i]->compatible_with) != NULL) |
| 235 | | { |
| 236 | | for (j = 0; drivers[j]; j++) |
| 237 | | { |
| 238 | | if (driver_get_name(drivers[i]->compatible_with) == drivers[j]) |
| 239 | | break; |
| 240 | | } |
| 241 | | if (!drivers[j]) |
| 242 | | { |
| 243 | | mame_printf_error("%s: is compatible with %s, which is not in drivers[]\n", drivers[i]->name, drivers[i]->compatible_with); |
| 244 | | error = 1; |
| 245 | | } |
| 246 | | } |
| 247 | | |
| 248 | 307 | /* check devices */ |
| 249 | | if (drivers[i]->sysconfig_ctor) |
| 250 | | { |
| 251 | | memset(&cfg, 0, sizeof(cfg)); |
| 252 | | memset(handlers, 0, sizeof(handlers)); |
| 253 | | cfg.device_slotcount = sizeof(handlers) / sizeof(handlers[0]); |
| 254 | | cfg.device_handlers = handlers; |
| 255 | | cfg.device_countoverrides = count_overrides; |
| 256 | | drivers[i]->sysconfig_ctor(&cfg); |
| 308 | error = validate_driver_devices(drivers[i]) || error; |
| 257 | 309 | |
| 258 | | for (j = 0; handlers[j]; j++) |
| 259 | | { |
| 260 | | devclass.gamedrv = drivers[i]; |
| 261 | | devclass.get_info = handlers[j]; |
| 310 | /* check compatibility chain */ |
| 311 | error = validate_compatibility_chain(drivers[i]) || error; |
| 262 | 312 | |
| 263 | | if (validate_device(&devclass)) |
| 264 | | error = 1; |
| 265 | | } |
| 266 | | } |
| 267 | | |
| 268 | 313 | /* check system config */ |
| 269 | 314 | ram_option_count(drivers[i]); |
| 270 | 315 | |
| 271 | 316 | /* make sure that our input system likes this driver */ |
| 272 | | if (inputx_validitycheck(drivers[i], &inputports)) |
| 273 | | error = 1; |
| 274 | | |
| 275 | | devices_free(devices); |
| 276 | | devices = NULL; |
| 317 | error = inputx_validitycheck(drivers[i], &inputports) || error; |
| 277 | 318 | } |
| 278 | 319 | |
| 279 | 320 | /* call other validity checks */ |
| 280 | | if (inputx_validitycheck(NULL, &inputports)) |
| 281 | | error = 1; |
| 282 | | if (device_valididtychecks()) |
| 283 | | error = 1; |
| 321 | error = inputx_validitycheck(NULL, &inputports) || error; |
| 322 | error = device_valididtychecks() || error; |
| 284 | 323 | |
| 285 | | /* now that we are completed, re-expand the actual driver to compensate |
| 286 | | * for the tms9928a hack */ |
| 287 | | if (Machine && Machine->gamedrv) |
| 288 | | { |
| 289 | | machine_config drv; |
| 290 | | expand_machine_driver(Machine->gamedrv->drv, &drv); |
| 291 | | } |
| 292 | | |
| 293 | 324 | return error; |
| 294 | 325 | } |