From e4d8baf401de8c6027dfbbaaaf8bf106c0c5b4d2 Mon Sep 17 00:00:00 2001 From: Aaron Giles Date: Fri, 3 Sep 2010 05:21:46 +0000 Subject: [PATCH] Changed driver_device to expose the game_driver's ROMs through the device interface. This means all ROMs are now exposed via devices, and thus the process of enumerating ROMs gets simpler. Changed all instances of temporarily allocating machine_config objects to just put them on the stack for simplicity, letting the destructor handle the cleanup work automatically. Changed machine_config constructor to take a game_driver, from which the machine_config constructor is obtained. This also means the resulting machine_config holds a reference to the game_driver. Changed running_machine constructor to no longer take a game_driver, since the game_driver is now obtainable via the machine_config. --- src/emu/audit.c | 43 ++++---- src/emu/clifront.c | 57 ++++------ src/emu/dimemory.c | 10 +- src/emu/emuopts.c | 8 +- src/emu/info.c | 54 +++++----- src/emu/machine.c | 26 +++-- src/emu/machine.h | 11 +- src/emu/mame.c | 22 ++-- src/emu/mconfig.c | 11 +- src/emu/mconfig.h | 5 +- src/emu/romload.c | 154 ++++++++++----------------- src/emu/romload.h | 8 +- src/emu/validity.c | 259 +++++++++++++++++++++------------------------ src/emu/validity.h | 2 +- 14 files changed, 309 insertions(+), 361 deletions(-) diff --git a/src/emu/audit.c b/src/emu/audit.c index 65738fd3094..adcbffa302b 100644 --- a/src/emu/audit.c +++ b/src/emu/audit.c @@ -56,7 +56,7 @@ INLINE void set_status(audit_record *record, UINT8 status, UINT8 substatus) int audit_images(core_options *options, const game_driver *gamedrv, UINT32 validation, audit_record **audit) { - machine_config *config = global_alloc(machine_config(gamedrv->machine_config)); + machine_config config(*gamedrv); const rom_entry *region, *rom; const rom_source *source; audit_record *record; @@ -67,10 +67,10 @@ int audit_images(core_options *options, const game_driver *gamedrv, UINT32 valid /* determine the number of records we will generate */ records = 0; - for (source = rom_first_source(gamedrv, config); source != NULL; source = rom_next_source(gamedrv, config, source)) + bool source_is_gamedrv = true; + for (source = rom_first_source(config); source != NULL; source = rom_next_source(*source)) { - int source_is_gamedrv = rom_source_is_gamedrv(gamedrv, source); - for (region = rom_first_region(gamedrv, source); region != NULL; region = rom_next_region(region)) + for (region = rom_first_region(*source); region != NULL; region = rom_next_region(region)) for (rom = rom_first_file(region); rom != NULL; rom = rom_next_file(rom)) if (ROMREGION_ISROMDATA(region) || ROMREGION_ISDISKDATA(region)) { @@ -83,6 +83,8 @@ int audit_images(core_options *options, const game_driver *gamedrv, UINT32 valid } records++; } + + source_is_gamedrv = false; } if (records > 0) @@ -92,10 +94,10 @@ int audit_images(core_options *options, const game_driver *gamedrv, UINT32 valid record = *audit; /* iterate over ROM sources and regions */ - for (source = rom_first_source(gamedrv, config); source != NULL; source = rom_next_source(gamedrv, config, source)) + bool source_is_gamedrv = true; + for (source = rom_first_source(config); source != NULL; source = rom_next_source(*source)) { - int source_is_gamedrv = rom_source_is_gamedrv(gamedrv, source); - for (region = rom_first_region(gamedrv, source); region != NULL; region = rom_next_region(region)) + for (region = rom_first_region(*source); region != NULL; region = rom_next_region(region)) { const char *regiontag = ROMREGION_ISLOADBYNAME(region) ? ROM_GETNAME(region) : NULL; for (rom = rom_first_file(region); rom; rom = rom_next_file(rom)) @@ -123,6 +125,7 @@ int audit_images(core_options *options, const game_driver *gamedrv, UINT32 valid record++; } } + source_is_gamedrv = false; } } @@ -134,7 +137,6 @@ int audit_images(core_options *options, const game_driver *gamedrv, UINT32 valid records = 0; } - global_free(config); return records; } @@ -146,14 +148,14 @@ int audit_images(core_options *options, const game_driver *gamedrv, UINT32 valid int audit_samples(core_options *options, const game_driver *gamedrv, audit_record **audit) { - machine_config *config = global_alloc(machine_config(gamedrv->machine_config)); + machine_config config(*gamedrv); audit_record *record; int records = 0; int sampnum; /* count the number of sample records attached to this driver */ const device_config_sound_interface *sound = NULL; - for (bool gotone = config->m_devicelist.first(sound); gotone; gotone = sound->next(sound)) + for (bool gotone = config.m_devicelist.first(sound); gotone; gotone = sound->next(sound)) if (sound->devconfig().type() == SAMPLES) { const samples_interface *intf = (const samples_interface *)sound->devconfig().static_config(); @@ -176,7 +178,7 @@ int audit_samples(core_options *options, const game_driver *gamedrv, audit_recor record = *audit; /* now iterate over sample entries */ - for (bool gotone = config->m_devicelist.first(sound); gotone; gotone = sound->next(sound)) + for (bool gotone = config.m_devicelist.first(sound); gotone; gotone = sound->next(sound)) if (sound->devconfig().type() == SAMPLES) { const samples_interface *intf = (const samples_interface *)sound->devconfig().static_config(); @@ -219,7 +221,6 @@ int audit_samples(core_options *options, const game_driver *gamedrv, audit_recor } skip: - global_free(config); return records; } @@ -524,18 +525,20 @@ static int rom_used_by_parent(const game_driver *gamedrv, const rom_entry *romen /* iterate up the parent chain */ for (drv = driver_get_clone(gamedrv); drv != NULL; drv = driver_get_clone(drv)) { + machine_config config(*drv); const rom_entry *region; const rom_entry *rom; /* see if the parent has the same ROM or not */ - for (region = rom_first_region(drv, NULL); region; region = rom_next_region(region)) - for (rom = rom_first_file(region); rom; rom = rom_next_file(rom)) - if (hash_data_is_equal(ROM_GETHASHDATA(rom), hash, 0)) - { - if (parent != NULL) - *parent = drv; - return TRUE; - } + for (const rom_source *source = rom_first_source(config); source != NULL; source = rom_next_source(*source)) + for (region = rom_first_region(*source); region; region = rom_next_region(region)) + for (rom = rom_first_file(region); rom; rom = rom_next_file(rom)) + if (hash_data_is_equal(ROM_GETHASHDATA(rom), hash, 0)) + { + if (parent != NULL) + *parent = drv; + return TRUE; + } } return FALSE; diff --git a/src/emu/clifront.c b/src/emu/clifront.c index d6be94c8ea3..5e3a4e1f7ff 100644 --- a/src/emu/clifront.c +++ b/src/emu/clifront.c @@ -508,13 +508,13 @@ int cli_info_listcrc(core_options *options, const char *gamename) for (drvindex = 0; drivers[drvindex] != NULL; drvindex++) if (mame_strwildcmp(gamename, drivers[drvindex]->name) == 0) { - machine_config *config = global_alloc(machine_config(drivers[drvindex]->machine_config)); + machine_config config(*drivers[drvindex]); const rom_entry *region, *rom; const rom_source *source; /* iterate over sources, regions, and then ROMs within the region */ - for (source = rom_first_source(drivers[drvindex], config); source != NULL; source = rom_next_source(drivers[drvindex], config, source)) - for (region = rom_first_region(drivers[drvindex], source); region; region = rom_next_region(region)) + for (source = rom_first_source(config); source != NULL; source = rom_next_source(*source)) + for (region = rom_first_region(*source); region; region = rom_next_region(region)) for (rom = rom_first_file(region); rom; rom = rom_next_file(rom)) { char hashbuf[HASH_BUF_SIZE]; @@ -525,7 +525,6 @@ int cli_info_listcrc(core_options *options, const char *gamename) } count++; - global_free(config); } /* return an error if none found */ @@ -546,7 +545,7 @@ int cli_info_listroms(core_options *options, const char *gamename) for (drvindex = 0; drivers[drvindex] != NULL; drvindex++) if (mame_strwildcmp(gamename, drivers[drvindex]->name) == 0) { - machine_config *config = global_alloc(machine_config(drivers[drvindex]->machine_config)); + machine_config config(*drivers[drvindex]); const rom_entry *region, *rom; const rom_source *source; @@ -557,8 +556,8 @@ int cli_info_listroms(core_options *options, const char *gamename) "Name Size Checksum\n", drivers[drvindex]->name); /* iterate over sources, regions and then ROMs within the region */ - for (source = rom_first_source(drivers[drvindex], config); source != NULL; source = rom_next_source(drivers[drvindex], config, source)) - for (region = rom_first_region(drivers[drvindex], source); region != NULL; region = rom_next_region(region)) + for (source = rom_first_source(config); source != NULL; source = rom_next_source(*source)) + for (region = rom_first_region(*source); region != NULL; region = rom_next_region(region)) for (rom = rom_first_file(region); rom != NULL; rom = rom_next_file(rom)) { const char *name = ROM_GETNAME(rom); @@ -596,7 +595,6 @@ int cli_info_listroms(core_options *options, const char *gamename) } count++; - global_free(config); } return (count > 0) ? MAMERR_NONE : MAMERR_NO_SUCH_GAME; @@ -617,11 +615,11 @@ int cli_info_listsamples(core_options *options, const char *gamename) for (drvindex = 0; drivers[drvindex] != NULL; drvindex++) if (mame_strwildcmp(gamename, drivers[drvindex]->name) == 0) { - machine_config *config = global_alloc(machine_config(drivers[drvindex]->machine_config)); + machine_config config(*drivers[drvindex]); const device_config_sound_interface *sound = NULL; /* find samples interfaces */ - for (bool gotone = config->m_devicelist.first(sound); gotone; gotone = sound->next(sound)) + for (bool gotone = config.m_devicelist.first(sound); gotone; gotone = sound->next(sound)) if (sound->devconfig().type() == SAMPLES) { const char *const *samplenames = ((const samples_interface *)sound->devconfig().static_config())->samplenames; @@ -634,7 +632,6 @@ int cli_info_listsamples(core_options *options, const char *gamename) } count++; - global_free(config); } return (count > 0) ? MAMERR_NONE : MAMERR_NO_SUCH_GAME; @@ -656,7 +653,7 @@ int cli_info_listdevices(core_options *options, const char *gamename) for (drvindex = 0; drivers[drvindex] != NULL; drvindex++) if (mame_strwildcmp(gamename, drivers[drvindex]->name) == 0) { - machine_config *config = global_alloc(machine_config(drivers[drvindex]->machine_config)); + machine_config config(*drivers[drvindex]); const device_config *devconfig; if (count != 0) @@ -664,7 +661,7 @@ int cli_info_listdevices(core_options *options, const char *gamename) printf("Driver %s (%s):\n", drivers[drvindex]->name, drivers[drvindex]->description); /* iterate through devices */ - for (devconfig = config->m_devicelist.first(); devconfig != NULL; devconfig = devconfig->next()) + for (devconfig = config.m_devicelist.first(); devconfig != NULL; devconfig = devconfig->next()) { printf(" %s ('%s')", devconfig->name(), devconfig->tag()); @@ -682,7 +679,6 @@ int cli_info_listdevices(core_options *options, const char *gamename) } count++; - global_free(config); } return (count > 0) ? MAMERR_NONE : MAMERR_NO_SUCH_GAME; @@ -794,9 +790,9 @@ static int info_listsoftware(core_options *options, const char *gamename) if ( mame_strwildcmp( gamename, drivers[drvindex]->name ) == 0 ) { /* allocate the machine config */ - machine_config *config = global_alloc(machine_config(drivers[drvindex]->machine_config)); + machine_config config(*drivers[drvindex]); - for (const device_config *dev = config->m_devicelist.first(SOFTWARE_LIST); dev != NULL; dev = dev->typenext()) + for (const device_config *dev = config.m_devicelist.first(SOFTWARE_LIST); dev != NULL; dev = dev->typenext()) { software_list_config *swlist = (software_list_config *)downcast(dev)->inline_config(); @@ -806,9 +802,6 @@ static int info_listsoftware(core_options *options, const char *gamename) nr_lists++; } } - - /* free the machine config */ - global_free(config); } } @@ -855,9 +848,9 @@ static int info_listsoftware(core_options *options, const char *gamename) if ( mame_strwildcmp( gamename, drivers[drvindex]->name ) == 0 ) { /* allocate the machine config */ - machine_config *config = global_alloc(machine_config(drivers[drvindex]->machine_config)); + machine_config config(*drivers[drvindex]); - for (const device_config *dev = config->m_devicelist.first(SOFTWARE_LIST); dev != NULL; dev = dev->typenext()) + for (const device_config *dev = config.m_devicelist.first(SOFTWARE_LIST); dev != NULL; dev = dev->typenext()) { software_list_config *swlist = (software_list_config *)downcast(dev)->inline_config(); @@ -964,8 +957,6 @@ static int info_listsoftware(core_options *options, const char *gamename) } } } - - global_free(config); } } @@ -988,9 +979,9 @@ static void softlist_match_roms(core_options *options, const char *hash, int len /* iterate over drivers */ for (drvindex = 0; drivers[drvindex] != NULL; drvindex++) { - machine_config *config = global_alloc(machine_config(drivers[drvindex]->machine_config)); + machine_config config(*drivers[drvindex]); - for (const device_config *dev = config->m_devicelist.first(SOFTWARE_LIST); dev != NULL; dev = dev->typenext()) + for (const device_config *dev = config.m_devicelist.first(SOFTWARE_LIST); dev != NULL; dev = dev->typenext()) { software_list_config *swlist = (software_list_config *)downcast(dev)->inline_config(); @@ -1027,8 +1018,6 @@ static void softlist_match_roms(core_options *options, const char *hash, int len } } } - - global_free(config); } } @@ -1042,7 +1031,6 @@ static int info_listmedia(core_options *options, const char *gamename) { int count = 0, devcount; int drvindex; - machine_config *config; const device_config_image_interface *dev = NULL; const char *src; const char *driver_name; @@ -1058,13 +1046,13 @@ static int info_listmedia(core_options *options, const char *gamename) if (mame_strwildcmp(gamename, drivers[drvindex]->name) == 0) { /* allocate the machine config */ - config = global_alloc(machine_config(drivers[drvindex]->machine_config)); + machine_config config(*drivers[drvindex]); driver_name = drivers[drvindex]->name; devcount = 0; - for (bool gotone = config->m_devicelist.first(dev); gotone; gotone = dev->next(dev)) + for (bool gotone = config.m_devicelist.first(dev); gotone; gotone = dev->next(dev)) { src = downcast(dev)->file_extensions(); name = downcast(dev)->instance_name(); @@ -1089,7 +1077,6 @@ static int info_listmedia(core_options *options, const char *gamename) printf("%-13s(none)\n",driver_name); count++; - global_free(config); } if (!count) @@ -1447,13 +1434,13 @@ static void match_roms(core_options *options, const char *hash, int length, int /* iterate over drivers */ for (drvindex = 0; drivers[drvindex] != NULL; drvindex++) { - machine_config *config = global_alloc(machine_config(drivers[drvindex]->machine_config)); + machine_config config(*drivers[drvindex]); const rom_entry *region, *rom; const rom_source *source; /* iterate over sources, regions and files within the region */ - for (source = rom_first_source(drivers[drvindex], config); source != NULL; source = rom_next_source(drivers[drvindex], config, source)) - for (region = rom_first_region(drivers[drvindex], source); region; region = rom_next_region(region)) + for (source = rom_first_source(config); source != NULL; source = rom_next_source(*source)) + for (region = rom_first_region(*source); region; region = rom_next_region(region)) for (rom = rom_first_file(region); rom; rom = rom_next_file(rom)) if (hash_data_is_equal(hash, ROM_GETHASHDATA(rom), 0)) { @@ -1465,8 +1452,6 @@ static void match_roms(core_options *options, const char *hash, int length, int mame_printf_info("= %s%-20s %-10s %s\n", baddump ? "(BAD) " : "", ROM_GETNAME(rom), drivers[drvindex]->name, drivers[drvindex]->description); (*found)++; } - - global_free(config); } softlist_match_roms( options, hash, length, found ); diff --git a/src/emu/dimemory.c b/src/emu/dimemory.c index 8bce0c07ccb..4e36a84fc7c 100644 --- a/src/emu/dimemory.c +++ b/src/emu/dimemory.c @@ -248,8 +248,8 @@ bool device_config_memory_interface::interface_validity_check(const game_driver { // look for the region bool found = false; - for (const rom_source *source = rom_first_source(&driver, &m_machine_config); source != NULL && !found; source = rom_next_source(&driver, &m_machine_config, source)) - for (const rom_entry *romp = rom_first_region(&driver, source); !ROMENTRY_ISEND(romp) && !found; romp++) + for (const rom_source *source = rom_first_source(m_machine_config); source != NULL && !found; source = rom_next_source(*source)) + for (const rom_entry *romp = rom_first_region(*source); !ROMENTRY_ISEND(romp) && !found; romp++) { const char *regiontag = ROMREGION_GETTAG(romp); if (regiontag != NULL) @@ -295,11 +295,11 @@ bool device_config_memory_interface::interface_validity_check(const game_driver // } // validate bank and share tags - if (entry->m_read.m_type == AMH_BANK && !validate_tag(&driver, "bank", entry->m_read.m_tag)) + if (entry->m_read.m_type == AMH_BANK && !validate_tag(driver, "bank", entry->m_read.m_tag)) error = true ; - if (entry->m_write.m_type == AMH_BANK && !validate_tag(&driver, "bank", entry->m_write.m_tag)) + if (entry->m_write.m_type == AMH_BANK && !validate_tag(driver, "bank", entry->m_write.m_tag)) error = true; - if (entry->m_share != NULL && !validate_tag(&driver, "share", entry->m_share)) + if (entry->m_share != NULL && !validate_tag(driver, "share", entry->m_share)) error = true; } diff --git a/src/emu/emuopts.c b/src/emu/emuopts.c index 2d69a3db0cd..3b99d0a02ea 100644 --- a/src/emu/emuopts.c +++ b/src/emu/emuopts.c @@ -232,15 +232,14 @@ const char *image_get_device_option(device_image_interface *image) void image_add_device_options(core_options *opts, const game_driver *driver) { int index = 0; - machine_config *config; const device_config_image_interface *image = NULL; /* create the configuration */ - config = global_alloc(machine_config(driver->machine_config)); + machine_config config(*driver); /* enumerate our callback for every device */ /* loop on each device instance */ - for (bool gotone = config->m_devicelist.first(image); gotone; gotone = image->next(image)) + for (bool gotone = config.m_devicelist.first(image); gotone; gotone = image->next(image)) { options_entry entry[2]; astring dev_full_name; @@ -267,9 +266,6 @@ void image_add_device_options(core_options *opts, const game_driver *driver) /* record that we've added device options */ options_set_bool(opts, OPTION_ADDED_DEVICE_OPTIONS, TRUE, OPTION_PRIORITY_CMDLINE); - - /* free the configuration */ - global_free(config); } /*------------------------------------------------- diff --git a/src/emu/info.c b/src/emu/info.c index 0360d1d7cbe..9a3fda2ae5b 100644 --- a/src/emu/info.c +++ b/src/emu/info.c @@ -39,7 +39,7 @@ public: const game_driver *drv; machine_config mconfig; - parent_info(const game_driver *drv) : mconfig(drv->machine_config) + parent_info(const game_driver *drv) : mconfig(*drv) { this->drv = drv; } @@ -458,14 +458,13 @@ static const char *get_merge_name(const rom_entry *rom, int parents, const paren for (parent = 0; parent < parents; ++parent) { - const game_driver *clone_of = pinfoarray[parent]->drv; const machine_config *pconfig = &pinfoarray[parent]->mconfig; const rom_source *psource; const rom_entry *pregion, *prom; /* scan the clone_of ROM for a matching ROM entry */ - for (psource = rom_first_source(clone_of, pconfig); psource != NULL; psource = rom_next_source(clone_of, pconfig, psource)) - for (pregion = rom_first_region(clone_of, psource); pregion != NULL; pregion = rom_next_region(pregion)) + for (psource = rom_first_source(*pconfig); psource != NULL; psource = rom_next_source(*psource)) + for (pregion = rom_first_region(*psource); pregion != NULL; pregion = rom_next_region(pregion)) for (prom = rom_first_file(pregion); prom != NULL; prom = rom_next_file(prom)) if (hash_data_is_equal(ROM_GETHASHDATA(rom), ROM_GETHASHDATA(prom), 0)) { @@ -484,7 +483,7 @@ static const char *get_merge_name(const rom_entry *rom, int parents, const paren the XML output -------------------------------------------------*/ -static void print_game_rom(FILE *out, const game_driver *game, const machine_config *config) +static void print_game_rom(FILE *out, const game_driver *game, const machine_config &config) { const game_driver *clone_of = driver_get_clone(game); int rom_type; @@ -504,8 +503,8 @@ static void print_game_rom(FILE *out, const game_driver *game, const machine_con const rom_entry *region; /* iterate over ROM sources: first the game, then any devices */ - for (source = rom_first_source(game, config); source != NULL; source = rom_next_source(game, config, source)) - for (region = rom_first_region(game, source); region != NULL; region = rom_next_region(region)) + for (source = rom_first_source(config); source != NULL; source = rom_next_source(*source)) + for (region = rom_first_region(*source); region != NULL; region = rom_next_region(region)) { int is_disk = ROMREGION_ISDISKDATA(region); const rom_entry *rom; @@ -611,11 +610,11 @@ static void print_game_rom(FILE *out, const game_driver *game, const machine_con attribute, if appropriate -------------------------------------------------*/ -static void print_game_sampleof(FILE *out, const game_driver *game, const machine_config *config) +static void print_game_sampleof(FILE *out, const game_driver *game, const machine_config &config) { const device_config_sound_interface *sound = NULL; - for (bool gotone = config->m_devicelist.first(sound); gotone; gotone = sound->next(sound)) + for (bool gotone = config.m_devicelist.first(sound); gotone; gotone = sound->next(sound)) if (sound->devconfig().type() == SAMPLES) { const char *const *samplenames = ((const samples_interface *)sound->devconfig().static_config())->samplenames; @@ -642,12 +641,12 @@ static void print_game_sampleof(FILE *out, const game_driver *game, const machin samples referenced by a game_driver -------------------------------------------------*/ -static void print_game_sample(FILE *out, const game_driver *game, const machine_config *config) +static void print_game_sample(FILE *out, const game_driver *game, const machine_config &config) { const device_config_sound_interface *sound = NULL; /* iterate over sound chips looking for samples */ - for (bool gotone = config->m_devicelist.first(sound); gotone; gotone = sound->next(sound)) + for (bool gotone = config.m_devicelist.first(sound); gotone; gotone = sound->next(sound)) if (sound->devconfig().type() == SAMPLES) { const char *const *samplenames = ((const samples_interface *)sound->devconfig().static_config())->samplenames; @@ -685,11 +684,11 @@ static void print_game_sample(FILE *out, const game_driver *game, const machine_ sound chips used by a game -------------------------------------------------*/ -static void print_game_chips(FILE *out, const game_driver *game, const machine_config *config) +static void print_game_chips(FILE *out, const game_driver *game, const machine_config &config) { /* iterate over CPUs */ const device_config_execute_interface *exec = NULL; - for (bool gotone = config->m_devicelist.first(exec); gotone; gotone = exec->next(exec)) + for (bool gotone = config.m_devicelist.first(exec); gotone; gotone = exec->next(exec)) { fprintf(out, "\t\tm_devicelist.first(sound); gotone; gotone = sound->next(sound)) + for (bool gotone = config.m_devicelist.first(sound); gotone; gotone = sound->next(sound)) { fprintf(out, "\t\tm_devicelist.first(sound)) + if (!config.m_devicelist.first(sound)) speakers = 0; fprintf(out, "\t\t\n", speakers); @@ -820,7 +819,7 @@ static void print_game_sound(FILE *out, const game_driver *game, const machine_c print_game_driver - print driver status -------------------------------------------------*/ -static void print_game_driver(FILE *out, const game_driver *game, const machine_config *config) +static void print_game_driver(FILE *out, const game_driver *game, const machine_config &config) { fprintf(out, "\t\tm_total_colors); + fprintf(out, " palettesize=\"%d\"", config.m_total_colors); fprintf(out, "/>\n"); } @@ -918,13 +917,13 @@ static void print_game_categories(FILE *out, const game_driver *game, const iopo image devices -------------------------------------------------*/ -static void print_game_images(FILE *out, const game_driver *game, const machine_config *config) +static void print_game_images(FILE *out, const game_driver *game, const machine_config &config) { const device_config_image_interface *dev = NULL; const char *name; const char *shortname; - for (bool gotone = config->m_devicelist.first(dev); gotone; gotone = dev->next(dev)) + for (bool gotone = config.m_devicelist.first(dev); gotone; gotone = dev->next(dev)) { /* print out device type */ fprintf(out, "\t\timage_type_name())); @@ -971,9 +970,9 @@ static void print_game_images(FILE *out, const game_driver *game, const machine_ for all known software lists for this system -------------------------------------------------*/ -static void print_game_software_list(FILE *out, const game_driver *game, const machine_config *config) +static void print_game_software_list(FILE *out, const game_driver *game, const machine_config &config) { - for (const device_config *dev = config->m_devicelist.first(SOFTWARE_LIST); dev != NULL; dev = dev->typenext()) + for (const device_config *dev = config.m_devicelist.first(SOFTWARE_LIST); dev != NULL; dev = dev->typenext()) { software_list_config *swlist = (software_list_config *)downcast(dev)->inline_config(); @@ -996,7 +995,7 @@ static void print_game_software_list(FILE *out, const game_driver *game, const m static void print_game_info(FILE *out, const game_driver *game) { const game_driver *clone_of; - machine_config *config; + machine_config config(*game); ioport_list portlist; const char *start; @@ -1005,7 +1004,6 @@ static void print_game_info(FILE *out, const game_driver *game) return; /* start tracking resources and allocate the machine and input configs */ - config = global_alloc(machine_config(game->machine_config)); input_port_list_init(portlist, game->ipt, NULL, 0, FALSE); /* print the header and the game name */ @@ -1070,8 +1068,6 @@ static void print_game_info(FILE *out, const game_driver *game) /* close the topmost tag */ fprintf(out, "\t\n"); - - global_free(config); } diff --git a/src/emu/machine.c b/src/emu/machine.c index fc6b1124196..ec3659b8b32 100644 --- a/src/emu/machine.c +++ b/src/emu/machine.c @@ -138,14 +138,14 @@ static char giant_string_buffer[65536] = { 0 }; // running_machine - constructor //------------------------------------------------- -running_machine::running_machine(const game_driver &driver, const machine_config &_config, core_options &options, bool exit_to_game_select) +running_machine::running_machine(const machine_config &_config, core_options &options, bool exit_to_game_select) : m_regionlist(m_respool), m_devicelist(m_respool), config(&_config), m_config(_config), firstcpu(NULL), - gamedrv(&driver), - m_game(driver), + gamedrv(&_config.gamedrv()), + m_game(_config.gamedrv()), primary_screen(NULL), palette(NULL), pens(NULL), @@ -177,7 +177,7 @@ running_machine::running_machine(const game_driver &driver, const machine_config m_logerror_list(NULL), m_scheduler(*this), m_options(options), - m_basename(driver.name), + m_basename(_config.gamedrv().name), m_current_phase(MACHINE_PHASE_PREINIT), m_paused(false), m_hard_reset_pending(false), @@ -190,7 +190,7 @@ running_machine::running_machine(const game_driver &driver, const machine_config m_saveload_schedule_time(attotime_zero), m_saveload_searchpath(NULL), m_rand_seed(0x9d14abd7), - m_driver_data(NULL) + m_driver_device(NULL) { memset(gfx, 0, sizeof(gfx)); memset(&generic, 0, sizeof(generic)); @@ -201,12 +201,11 @@ running_machine::running_machine(const game_driver &driver, const machine_config device_config *config = m_config.m_devicelist.find("root"); if (config == NULL) throw emu_fatalerror("Machine configuration missing driver_device"); - driver_device_config_base::static_set_game(config, &driver); // attach this machine to all the devices in the configuration m_devicelist.import_config_list(m_config.m_devicelist, *this); - m_driver_data = device("root"); - assert(m_driver_data != NULL); + m_driver_device = device("root"); + assert(m_driver_device != NULL); // find devices primary_screen = screen_first(*this); @@ -1013,6 +1012,17 @@ void driver_device_config_base::static_set_video_update(device_config *device, v } +//------------------------------------------------- +// rom_region - return a pointer to the ROM +// regions specified for the current game +//------------------------------------------------- + +const rom_entry *driver_device_config_base::rom_region() const +{ + return m_game->rom; +} + + //************************************************************************** // DRIVER DEVICE diff --git a/src/emu/machine.h b/src/emu/machine.h index 4fcd397d5cd..47a72d65e39 100644 --- a/src/emu/machine.h +++ b/src/emu/machine.h @@ -338,7 +338,7 @@ class running_machine : public bindable_object public: // construction/destruction - running_machine(const game_driver &driver, const machine_config &config, core_options &options, bool exit_to_game_select = false); + running_machine(const machine_config &config, core_options &options, bool exit_to_game_select = false); ~running_machine(); // fetch items by name @@ -456,8 +456,10 @@ public: debug_view_manager * m_debug_view; // internal data from debugvw.c // driver-specific information + driver_device *driver_data() const { return m_driver_device; } + template - T *driver_data() const { return downcast(m_driver_data); } + T *driver_data() const { return downcast(m_driver_device); } private: void start(); @@ -521,7 +523,7 @@ private: // base time time_t m_base_time; - driver_device * m_driver_data; // drivers can hang data off of here instead of using globals + driver_device * m_driver_device; }; @@ -558,6 +560,9 @@ public: static void static_set_video_update(device_config *device, video_update_func callback); protected: + // optional information overrides + virtual const rom_entry *rom_region() const; + // internal state const game_driver * m_game; // pointer to the game driver diff --git a/src/emu/mame.c b/src/emu/mame.c index 618ac880086..3ece8d55ec3 100644 --- a/src/emu/mame.c +++ b/src/emu/mame.c @@ -189,10 +189,10 @@ int mame_execute(core_options *options) } // create the machine configuration - const machine_config *config = global_alloc(machine_config(driver->machine_config)); + const machine_config *config = global_alloc(machine_config(*driver)); // create the machine structure and driver - running_machine *machine = global_alloc(running_machine(*driver, *config, *options, started_empty)); + running_machine *machine = global_alloc(running_machine(*config, *options, started_empty)); // looooong term: remove this global_machine = machine; @@ -519,7 +519,6 @@ void mame_parse_ini_files(core_options *options, const game_driver *driver) #ifndef MESS const game_driver *parent = driver_get_clone(driver); const game_driver *gparent = (parent != NULL) ? driver_get_clone(parent) : NULL; - machine_config *config; /* parse "vertical.ini" or "horizont.ini" */ if (driver->flags & ORIENTATION_SWAP_XY) @@ -528,14 +527,15 @@ void mame_parse_ini_files(core_options *options, const game_driver *driver) parse_ini_file(options, "horizont", OPTION_PRIORITY_ORIENTATION_INI); /* parse "vector.ini" for vector games */ - config = global_alloc(machine_config(driver->machine_config)); - for (const screen_device_config *devconfig = screen_first(*config); devconfig != NULL; devconfig = screen_next(devconfig)) - if (devconfig->screen_type() == SCREEN_TYPE_VECTOR) - { - parse_ini_file(options, "vector", OPTION_PRIORITY_VECTOR_INI); - break; - } - global_free(config); + { + machine_config config(*driver); + for (const screen_device_config *devconfig = screen_first(config); devconfig != NULL; devconfig = screen_next(devconfig)) + if (devconfig->screen_type() == SCREEN_TYPE_VECTOR) + { + parse_ini_file(options, "vector", OPTION_PRIORITY_VECTOR_INI); + break; + } + } /* next parse "source/.ini"; if that doesn't exist, try .ini */ astring sourcename; diff --git a/src/emu/mconfig.c b/src/emu/mconfig.c index cc40d2e46e1..ad9537ca4ed 100644 --- a/src/emu/mconfig.c +++ b/src/emu/mconfig.c @@ -49,7 +49,7 @@ // machine_config - constructor //------------------------------------------------- -machine_config::machine_config(machine_config_constructor constructor) +machine_config::machine_config(const game_driver &gamedrv) : m_minimum_quantum(attotime_zero), m_perfect_cpu_quantum(NULL), m_watchdog_vblank_count(0), @@ -60,10 +60,17 @@ machine_config::machine_config(machine_config_constructor constructor) m_gfxdecodeinfo(NULL), m_total_colors(0), m_default_layout(NULL), + m_gamedrv(gamedrv), m_parse_level(0) { // construct the config - (*constructor)(*this, NULL); + (*gamedrv.machine_config)(*this, NULL); + + // when finished, set the game driver + device_config *config = m_devicelist.find("root"); + if (config == NULL) + throw emu_fatalerror("Machine configuration missing driver_device"); + driver_device_config_base::static_set_game(config, &gamedrv); // process any device-specific machine configurations for (device_config *devconfig = m_devicelist.first(); devconfig != NULL; devconfig = devconfig->next()) diff --git a/src/emu/mconfig.h b/src/emu/mconfig.h index fa3cce8bab1..0359594a95f 100644 --- a/src/emu/mconfig.h +++ b/src/emu/mconfig.h @@ -124,8 +124,10 @@ class machine_config friend class running_machine; public: - machine_config(machine_config_constructor constructor); + machine_config(const game_driver &gamedrv); ~machine_config(); + + const game_driver &gamedrv() const { return m_gamedrv; } attotime m_minimum_quantum; // minimum scheduling quantum const char * m_perfect_cpu_quantum; // tag of CPU to use for "perfect" scheduling @@ -149,6 +151,7 @@ public: device_config *device_find(device_config *owner, const char *tag); private: + const game_driver & m_gamedrv; int m_parse_level; // nested parsing level }; diff --git a/src/emu/romload.c b/src/emu/romload.c index bdad2e7eae0..01f68e26f5b 100644 --- a/src/emu/romload.c +++ b/src/emu/romload.c @@ -137,39 +137,18 @@ void set_disk_handle(running_machine *machine, const char *region, mame_file *fi ROM LOADING ***************************************************************************/ -/*------------------------------------------------- - rom_source_is_gamedrv - return TRUE if the - given rom_source refers to the game driver - itself --------------------------------------------------*/ - -int rom_source_is_gamedrv(const game_driver *drv, const rom_source *source) -{ - return ((const game_driver *)source == drv); -} - - /*------------------------------------------------- rom_first_source - return pointer to first ROM source -------------------------------------------------*/ -const rom_source *rom_first_source(const game_driver *drv, const machine_config *config) +const rom_source *rom_first_source(const machine_config &config) { - const device_config *devconfig; + /* look through devices */ + for (const device_config *devconfig = config.m_devicelist.first(); devconfig != NULL; devconfig = devconfig->next()) + if (devconfig->rom_region() != NULL) + return devconfig; - /* if the driver has a ROM pointer, that's what we want */ - if (drv->rom != NULL) - return (rom_source *)drv; - - /* otherwise, look through devices */ - if (config != NULL) - for (devconfig = config->m_devicelist.first(); devconfig != NULL; devconfig = devconfig->next()) - { - const rom_entry *devromp = devconfig->rom_region(); - if (devromp != NULL) - return (rom_source *)devconfig; - } return NULL; } @@ -179,23 +158,13 @@ const rom_source *rom_first_source(const game_driver *drv, const machine_config source -------------------------------------------------*/ -const rom_source *rom_next_source(const game_driver *drv, const machine_config *config, const rom_source *previous) +const rom_source *rom_next_source(const rom_source &previous) { - const device_config *devconfig; - - /* if the previous was the driver, we want the first device */ - if (rom_source_is_gamedrv(drv, previous)) - devconfig = (config != NULL) ? config->m_devicelist.first() : NULL; - else - devconfig = ((const device_config *)previous)->next(); - /* look for further devices with ROM definitions */ - for ( ; devconfig != NULL; devconfig = devconfig->next()) - { - const rom_entry *devromp = devconfig->rom_region(); - if (devromp != NULL) + for (const device_config *devconfig = previous.next(); devconfig != NULL; devconfig = devconfig->next()) + if (devconfig->rom_region() != NULL) return (rom_source *)devconfig; - } + return NULL; } @@ -205,15 +174,9 @@ const rom_source *rom_next_source(const game_driver *drv, const machine_config * region -------------------------------------------------*/ -const rom_entry *rom_first_region(const game_driver *drv, const rom_source *source) +const rom_entry *rom_first_region(const rom_source &source) { - const rom_entry *romp; - - if (source == NULL || rom_source_is_gamedrv(drv, source)) - romp = drv->rom; - else - romp = ((const device_config *)source)->rom_region(); - + const rom_entry *romp = source.rom_region(); return (romp != NULL && !ROMENTRY_ISEND(romp)) ? romp : NULL; } @@ -267,14 +230,7 @@ const rom_entry *rom_next_file(const rom_entry *romp) astring &rom_region_name(astring &result, const game_driver *drv, const rom_source *source, const rom_entry *romp) { - if (rom_source_is_gamedrv(drv, source)) - result.cpy(ROMREGION_GETTAG(romp)); - else - { - const device_config *devconfig = (const device_config *)source; - result.printf("%s:%s", devconfig->tag(), ROMREGION_GETTAG(romp)); - } - return result; + return source->subtag(result, ROMREGION_GETTAG(romp)); } @@ -342,43 +298,46 @@ static void determine_bios_rom(rom_load_data *romdata) romdata->system_bios = 0; - /* first determine the default BIOS name */ - for (rom = romdata->machine->gamedrv->rom; !ROMENTRY_ISEND(rom); rom++) - if (ROMENTRY_ISDEFAULT_BIOS(rom)) - defaultname = ROM_GETNAME(rom); - - /* look for a BIOS with a matching name */ - for (rom = romdata->machine->gamedrv->rom; !ROMENTRY_ISEND(rom); rom++) - if (ROMENTRY_ISSYSTEM_BIOS(rom)) - { - const char *biosname = ROM_GETNAME(rom); - int bios_flags = ROM_GETBIOSFLAGS(rom); - char bios_number[20]; - - /* Allow '-bios n' to still be used */ - sprintf(bios_number, "%d", bios_flags - 1); - if (strcmp(bios_number, specbios) == 0 || strcmp(biosname, specbios) == 0) - romdata->system_bios = bios_flags; - if (defaultname != NULL && strcmp(biosname, defaultname) == 0) - default_no = bios_flags; - bios_count++; - } - - /* if none found, use the default */ - if (romdata->system_bios == 0 && bios_count > 0) + for (const rom_source *source = rom_first_source(*romdata->machine->config); source != NULL; source = rom_next_source(*source)) { - /* if we got neither an empty string nor 'default' then warn the user */ - if (specbios[0] != 0 && strcmp(specbios, "default") != 0 && romdata != NULL) + /* first determine the default BIOS name */ + for (rom = source->rom_region(); !ROMENTRY_ISEND(rom); rom++) + if (ROMENTRY_ISDEFAULT_BIOS(rom)) + defaultname = ROM_GETNAME(rom); + + /* look for a BIOS with a matching name */ + for (rom = source->rom_region(); !ROMENTRY_ISEND(rom); rom++) + if (ROMENTRY_ISSYSTEM_BIOS(rom)) + { + const char *biosname = ROM_GETNAME(rom); + int bios_flags = ROM_GETBIOSFLAGS(rom); + char bios_number[20]; + + /* Allow '-bios n' to still be used */ + sprintf(bios_number, "%d", bios_flags - 1); + if (strcmp(bios_number, specbios) == 0 || strcmp(biosname, specbios) == 0) + romdata->system_bios = bios_flags; + if (defaultname != NULL && strcmp(biosname, defaultname) == 0) + default_no = bios_flags; + bios_count++; + } + + /* if none found, use the default */ + if (romdata->system_bios == 0 && bios_count > 0) { - romdata->errorstring.catprintf("%s: invalid bios\n", specbios); - romdata->warnings++; + /* if we got neither an empty string nor 'default' then warn the user */ + if (specbios[0] != 0 && strcmp(specbios, "default") != 0 && romdata != NULL) + { + romdata->errorstring.catprintf("%s: invalid bios\n", specbios); + romdata->warnings++; + } + + /* set to default */ + romdata->system_bios = default_no; } - /* set to default */ - romdata->system_bios = default_no; + LOG(("Using System BIOS: %d\n", romdata->system_bios)); } - - LOG(("Using System BIOS: %d\n", romdata->system_bios)); } @@ -397,8 +356,8 @@ static void count_roms(rom_load_data *romdata) romdata->romstotalsize = 0; /* loop over regions, then over files */ - for (source = rom_first_source(romdata->machine->gamedrv, romdata->machine->config); source != NULL; source = rom_next_source(romdata->machine->gamedrv, romdata->machine->config, source)) - for (region = rom_first_region(romdata->machine->gamedrv, source); region != NULL; region = rom_next_region(region)) + for (source = rom_first_source(*romdata->machine->config); source != NULL; source = rom_next_source(*source)) + for (region = rom_first_region(*source); region != NULL; region = rom_next_region(region)) for (rom = rom_first_file(region); rom != NULL; rom = rom_next_file(rom)) if (ROM_GETBIOSFLAGS(rom) == 0 || ROM_GETBIOSFLAGS(rom) == romdata->system_bios) { @@ -1045,8 +1004,10 @@ chd_error open_disk_image_options(core_options *options, const game_driver *game /* otherwise, look at our parents for a CHD with an identical checksum */ /* and try to open that */ for (drv = gamedrv; drv != NULL; drv = driver_get_clone(drv)) - for (source = rom_first_source(drv, NULL); source != NULL; source = rom_next_source(drv, NULL, source)) - for (region = rom_first_region(drv, source); region != NULL; region = rom_next_region(region)) + { + machine_config config(*drv); + for (source = rom_first_source(config); source != NULL; source = rom_next_source(*source)) + for (region = rom_first_region(*source); region != NULL; region = rom_next_region(region)) if (ROMREGION_ISDISKDATA(region)) for (rom = rom_first_file(region); rom != NULL; rom = rom_next_file(rom)) @@ -1081,6 +1042,7 @@ chd_error open_disk_image_options(core_options *options, const game_driver *game *image_file = NULL; } } + } return err; } @@ -1344,8 +1306,8 @@ static void process_region_list(rom_load_data *romdata) const rom_entry *region; /* loop until we hit the end */ - for (source = rom_first_source(romdata->machine->gamedrv, romdata->machine->config); source != NULL; source = rom_next_source(romdata->machine->gamedrv, romdata->machine->config, source)) - for (region = rom_first_region(romdata->machine->gamedrv, source); region != NULL; region = rom_next_region(region)) + for (source = rom_first_source(*romdata->machine->config); source != NULL; source = rom_next_source(*source)) + for (region = rom_first_region(*source); region != NULL; region = rom_next_region(region)) { UINT32 regionlength = ROMREGION_GETLENGTH(region); UINT32 regionflags = ROMREGION_GETFLAGS(region); @@ -1388,8 +1350,8 @@ static void process_region_list(rom_load_data *romdata) } /* now go back and post-process all the regions */ - for (source = rom_first_source(romdata->machine->gamedrv, romdata->machine->config); source != NULL; source = rom_next_source(romdata->machine->gamedrv, romdata->machine->config, source)) - for (region = rom_first_region(romdata->machine->gamedrv, source); region != NULL; region = rom_next_region(region)) + for (source = rom_first_source(*romdata->machine->config); source != NULL; source = rom_next_source(*source)) + for (region = rom_first_region(*source); region != NULL; region = rom_next_region(region)) region_post_process(romdata, ROMREGION_GETTAG(region)); } diff --git a/src/emu/romload.h b/src/emu/romload.h index e66a0d04c7d..06deed4980e 100644 --- a/src/emu/romload.h +++ b/src/emu/romload.h @@ -123,7 +123,7 @@ enum TYPE DEFINITIONS ***************************************************************************/ -typedef struct _rom_source rom_source; +typedef device_config rom_source; struct rom_entry @@ -282,13 +282,13 @@ int rom_load_warnings(running_machine *machine); /* ----- ROM iteration ----- */ /* return pointer to first ROM source */ -const rom_source *rom_first_source(const game_driver *drv, const machine_config *config); +const rom_source *rom_first_source(const machine_config &config); /* return pointer to next ROM source */ -const rom_source *rom_next_source(const game_driver *drv, const machine_config *config, const rom_source *previous); +const rom_source *rom_next_source(const rom_source &previous); /* return pointer to the first ROM region within a source */ -const rom_entry *rom_first_region(const game_driver *drv, const rom_source *romp); +const rom_entry *rom_first_region(const rom_source &romp); /* return pointer to the next ROM region within a source */ const rom_entry *rom_next_region(const rom_entry *romp); diff --git a/src/emu/validity.c b/src/emu/validity.c index e305c94286b..567b33d7ba2 100644 --- a/src/emu/validity.c +++ b/src/emu/validity.c @@ -86,7 +86,7 @@ INLINE const char *input_port_string_from_index(UINT32 index) meets the general requirements -------------------------------------------------*/ -bool validate_tag(const game_driver *driver, const char *object, const char *tag) +bool validate_tag(const game_driver &driver, const char *object, const char *tag) { const char *validchars = "abcdefghijklmnopqrstuvwxyz0123456789_.:"; const char *begin = strrchr(tag, ':'); @@ -100,7 +100,7 @@ bool validate_tag(const game_driver *driver, const char *object, const char *tag strcmp(tag, "left") == 0 || strcmp(tag, "right") == 0) { - mame_printf_error("%s: %s has invalid generic tag '%s'\n", driver->source_file, driver->name, tag); + mame_printf_error("%s: %s has invalid generic tag '%s'\n", driver.source_file, driver.name, tag); error = true; } @@ -108,19 +108,19 @@ bool validate_tag(const game_driver *driver, const char *object, const char *tag { if (*p != tolower((UINT8)*p)) { - mame_printf_error("%s: %s has %s with tag '%s' containing upper-case characters\n", driver->source_file, driver->name, object, tag); + mame_printf_error("%s: %s has %s with tag '%s' containing upper-case characters\n", driver.source_file, driver.name, object, tag); error = true; break; } if (*p == ' ') { - mame_printf_error("%s: %s has %s with tag '%s' containing spaces\n", driver->source_file, driver->name, object, tag); + mame_printf_error("%s: %s has %s with tag '%s' containing spaces\n", driver.source_file, driver.name, object, tag); error = true; break; } if (strchr(validchars, *p) == NULL) { - mame_printf_error("%s: %s has %s with tag '%s' containing invalid character '%c'\n", driver->source_file, driver->name, object, tag, *p); + mame_printf_error("%s: %s has %s with tag '%s' containing invalid character '%c'\n", driver.source_file, driver.name, object, tag, *p); error = true; break; } @@ -133,17 +133,17 @@ bool validate_tag(const game_driver *driver, const char *object, const char *tag if (strlen(begin) == 0) { - mame_printf_error("%s: %s has %s with 0-length tag\n", driver->source_file, driver->name, object); + mame_printf_error("%s: %s has %s with 0-length tag\n", driver.source_file, driver.name, object); error = true; } if (strlen(begin) < MIN_TAG_LENGTH) { - mame_printf_error("%s: %s has %s with tag '%s' < %d characters\n", driver->source_file, driver->name, object, tag, MIN_TAG_LENGTH); + mame_printf_error("%s: %s has %s with tag '%s' < %d characters\n", driver.source_file, driver.name, object, tag, MIN_TAG_LENGTH); error = true; } if (strlen(begin) > MAX_TAG_LENGTH) { - mame_printf_error("%s: %s has %s with tag '%s' > %d characters\n", driver->source_file, driver->name, object, tag, MAX_TAG_LENGTH); + mame_printf_error("%s: %s has %s with tag '%s' > %d characters\n", driver.source_file, driver.name, object, tag, MAX_TAG_LENGTH); error = true; } @@ -314,9 +314,9 @@ static bool validate_inlines(void) information -------------------------------------------------*/ -static bool validate_driver(int drivnum, const machine_config *config, game_driver_map &names, game_driver_map &descriptions) +static bool validate_driver(const machine_config &config, game_driver_map &names, game_driver_map &descriptions) { - const game_driver *driver = drivers[drivnum]; + const game_driver &driver = config.gamedrv(); const game_driver *clone_of; const char *compatible_with; const game_driver *other_drv; @@ -326,24 +326,24 @@ static bool validate_driver(int drivnum, const machine_config *config, game_driv enum { NAME_LEN_PARENT = 8, NAME_LEN_CLONE = 16 }; /* check for duplicate names */ - if (names.add(driver->name, driver, FALSE) == TMERR_DUPLICATE) + if (names.add(driver.name, &driver, FALSE) == TMERR_DUPLICATE) { - const game_driver *match = names.find(driver->name); - mame_printf_error("%s: %s is a duplicate name (%s, %s)\n", driver->source_file, driver->name, match->source_file, match->name); + const game_driver *match = names.find(driver.name); + mame_printf_error("%s: %s is a duplicate name (%s, %s)\n", driver.source_file, driver.name, match->source_file, match->name); error = true; } /* check for duplicate descriptions */ - if (descriptions.add(driver->description, driver, FALSE) == TMERR_DUPLICATE) + if (descriptions.add(driver.description, &driver, FALSE) == TMERR_DUPLICATE) { - const game_driver *match = descriptions.find(driver->description); - mame_printf_error("%s: %s is a duplicate description (%s, %s)\n", driver->source_file, driver->description, match->source_file, match->description); + const game_driver *match = descriptions.find(driver.description); + mame_printf_error("%s: %s is a duplicate description (%s, %s)\n", driver.source_file, driver.description, match->source_file, match->description); error = true; } /* determine the clone */ - is_clone = (strcmp(driver->parent, "0") != 0); - clone_of = driver_get_clone(driver); + is_clone = (strcmp(driver.parent, "0") != 0); + clone_of = driver_get_clone(&driver); if (clone_of && (clone_of->flags & GAME_IS_BIOS_ROOT)) is_clone = false; @@ -351,66 +351,66 @@ static bool validate_driver(int drivnum, const machine_config *config, game_driv /* (100 is arbitrary, but tries to avoid tiny.mak dependencies) */ if (driver_list_get_count(drivers) > 100 && !clone_of && is_clone) { - mame_printf_error("%s: %s is a non-existant clone\n", driver->source_file, driver->parent); + mame_printf_error("%s: %s is a non-existant clone\n", driver.source_file, driver.parent); error = true; } /* look for recursive cloning */ - if (clone_of == driver) + if (clone_of == &driver) { - mame_printf_error("%s: %s is set as a clone of itself\n", driver->source_file, driver->name); + mame_printf_error("%s: %s is set as a clone of itself\n", driver.source_file, driver.name); error = true; } /* look for clones that are too deep */ if (clone_of != NULL && (clone_of = driver_get_clone(clone_of)) != NULL && (clone_of->flags & GAME_IS_BIOS_ROOT) == 0) { - mame_printf_error("%s: %s is a clone of a clone\n", driver->source_file, driver->name); + mame_printf_error("%s: %s is a clone of a clone\n", driver.source_file, driver.name); error = true; } /* make sure the driver name is 8 chars or less */ - if ((is_clone && strlen(driver->name) > NAME_LEN_CLONE) || ((!is_clone) && strlen(driver->name) > NAME_LEN_PARENT)) + if ((is_clone && strlen(driver.name) > NAME_LEN_CLONE) || ((!is_clone) && strlen(driver.name) > NAME_LEN_PARENT)) { - mame_printf_error("%s: %s %s driver name must be %d characters or less\n", driver->source_file, driver->name, + mame_printf_error("%s: %s %s driver name must be %d characters or less\n", driver.source_file, driver.name, is_clone ? "clone" : "parent", is_clone ? NAME_LEN_CLONE : NAME_LEN_PARENT); error = true; } /* make sure the year is only digits, '?' or '+' */ - for (s = driver->year; *s; s++) + for (s = driver.year; *s; s++) if (!isdigit((UINT8)*s) && *s != '?' && *s != '+') { - mame_printf_error("%s: %s has an invalid year '%s'\n", driver->source_file, driver->name, driver->year); + mame_printf_error("%s: %s has an invalid year '%s'\n", driver.source_file, driver.name, driver.year); error = true; break; } /* normalize driver->compatible_with */ - compatible_with = driver->compatible_with; + compatible_with = driver.compatible_with; if ((compatible_with != NULL) && !strcmp(compatible_with, "0")) compatible_with = NULL; /* check for this driver being compatible with a non-existant driver */ - if ((compatible_with != NULL) && (driver_get_name(driver->compatible_with) == NULL)) + if ((compatible_with != NULL) && (driver_get_name(driver.compatible_with) == NULL)) { - mame_printf_error("%s: is compatible with %s, which is not in drivers[]\n", driver->name, driver->compatible_with); + mame_printf_error("%s: is compatible with %s, which is not in drivers[]\n", driver.name, driver.compatible_with); error = true; } /* check for clone_of and compatible_with being specified at the same time */ - if ((driver_get_clone(driver) != NULL) && (compatible_with != NULL)) + if ((driver_get_clone(&driver) != NULL) && (compatible_with != NULL)) { - mame_printf_error("%s: both compatible_with and clone_of are specified\n", driver->name); + mame_printf_error("%s: both compatible_with and clone_of are specified\n", driver.name); error = true; } /* find any recursive dependencies on the current driver */ - for (other_drv = driver_get_compatible(driver); other_drv != NULL; other_drv = driver_get_compatible(other_drv)) + for (other_drv = driver_get_compatible(&driver); other_drv != NULL; other_drv = driver_get_compatible(other_drv)) { - if (driver == other_drv) + if (&driver == other_drv) { - mame_printf_error("%s: recursive compatibility\n", driver->name); + mame_printf_error("%s: recursive compatibility\n", driver.name); error = true; break; } @@ -418,9 +418,9 @@ static bool validate_driver(int drivnum, const machine_config *config, game_driv /* make sure sound-less drivers are flagged */ const device_config_sound_interface *sound; - if ((driver->flags & GAME_IS_BIOS_ROOT) == 0 && !config->m_devicelist.first(sound) && (driver->flags & GAME_NO_SOUND) == 0 && (driver->flags & GAME_NO_SOUND_HW) == 0) + if ((driver.flags & GAME_IS_BIOS_ROOT) == 0 && !config.m_devicelist.first(sound) && (driver.flags & GAME_NO_SOUND) == 0 && (driver.flags & GAME_NO_SOUND_HW) == 0) { - mame_printf_error("%s: %s missing GAME_NO_SOUND flag\n", driver->source_file, driver->name); + mame_printf_error("%s: %s missing GAME_NO_SOUND flag\n", driver.source_file, driver.name); error = true; } @@ -432,9 +432,9 @@ static bool validate_driver(int drivnum, const machine_config *config, game_driv validate_roms - validate ROM definitions -------------------------------------------------*/ -static bool validate_roms(int drivnum, const machine_config *config, region_array *rgninfo, game_driver_map &roms) +static bool validate_roms(const machine_config &config, region_array *rgninfo, game_driver_map &roms) { - const game_driver *driver = drivers[drivnum]; + const game_driver &driver = config.gamedrv(); int bios_flags = 0, last_bios = 0; const char *last_rgnname = "???"; const char *last_name = "???"; @@ -442,25 +442,11 @@ static bool validate_roms(int drivnum, const machine_config *config, region_arra int items_since_region = 1; bool error = false; - /* check for duplicate ROM entries */ -/* - if (driver->rom != NULL && (driver->flags & GAME_NO_STANDALONE) == 0) - { - char romaddr[20]; - sprintf(romaddr, "%p", driver->rom); - if (roms.add(romaddr, driver, FALSE) == TMERR_DUPLICATE) - { - const game_driver *match = roms.find(romaddr); - mame_printf_error("%s: %s uses the same ROM set as (%s, %s)\n", driver->source_file, driver->description, match->source_file, match->name); - error = true; - } - } -*/ /* iterate, starting with the driver's ROMs and continuing with device ROMs */ - for (const rom_source *source = rom_first_source(driver, config); source != NULL; source = rom_next_source(driver, config, source)) + for (const rom_source *source = rom_first_source(config); source != NULL; source = rom_next_source(*source)) { /* scan the ROM entries */ - for (const rom_entry *romp = rom_first_region(driver, source); !ROMENTRY_ISEND(romp); romp++) + for (const rom_entry *romp = rom_first_region(*source); !ROMENTRY_ISEND(romp); romp++) { /* if this is a region, make sure it's valid, and record the length */ if (ROMENTRY_ISREGION(romp)) @@ -469,7 +455,7 @@ static bool validate_roms(int drivnum, const machine_config *config, region_arra /* if we haven't seen any items since the last region, print a warning */ if (items_since_region == 0) - mame_printf_warning("%s: %s has empty ROM region '%s' (warning)\n", driver->source_file, driver->name, last_rgnname); + mame_printf_warning("%s: %s has empty ROM region '%s' (warning)\n", driver.source_file, driver.name, last_rgnname); items_since_region = (ROMREGION_ISERASE(romp) || ROMREGION_ISDISKDATA(romp)) ? 1 : 0; currgn = NULL; last_rgnname = regiontag; @@ -477,14 +463,14 @@ static bool validate_roms(int drivnum, const machine_config *config, region_arra /* check for a valid tag */ if (regiontag == NULL) { - mame_printf_error("%s: %s has NULL ROM_REGION tag\n", driver->source_file, driver->name); + mame_printf_error("%s: %s has NULL ROM_REGION tag\n", driver.source_file, driver.name); error = true; } /* load by name entries must be 8 characters or less */ else if (ROMREGION_ISLOADBYNAME(romp) && strlen(regiontag) > 8) { - mame_printf_error("%s: %s has load-by-name region '%s' with name >8 characters\n", driver->source_file, driver->name, regiontag); + mame_printf_error("%s: %s has load-by-name region '%s' with name >8 characters\n", driver.source_file, driver.name, regiontag); error = true; } @@ -494,7 +480,7 @@ static bool validate_roms(int drivnum, const machine_config *config, region_arra astring fulltag; /* iterate over all regions found so far */ - rom_region_name(fulltag, driver, source, romp); + rom_region_name(fulltag, &driver, source, romp); for (int rgnnum = 0; rgnnum < ARRAY_LENGTH(rgninfo->entries); rgnnum++) { /* stop when we hit an empty */ @@ -509,7 +495,7 @@ static bool validate_roms(int drivnum, const machine_config *config, region_arra /* fail if we hit a duplicate */ if (fulltag == rgninfo->entries[rgnnum].tag) { - mame_printf_error("%s: %s has duplicate ROM_REGION tag '%s'\n", driver->source_file, driver->name, fulltag.cstr()); + mame_printf_error("%s: %s has duplicate ROM_REGION tag '%s'\n", driver.source_file, driver.name, fulltag.cstr()); error = true; break; } @@ -528,7 +514,7 @@ static bool validate_roms(int drivnum, const machine_config *config, region_arra if (last_bios+1 != bios_flags) { const char *name = ROM_GETNAME(romp); - mame_printf_error("%s: %s has non-sequential bios %s\n", driver->source_file, driver->name, name); + mame_printf_error("%s: %s has non-sequential bios %s\n", driver.source_file, driver.name, name); error = true; } last_bios = bios_flags; @@ -549,7 +535,7 @@ static bool validate_roms(int drivnum, const machine_config *config, region_arra for (s = last_name; *s; s++) if (tolower((UINT8)*s) != *s) { - mame_printf_error("%s: %s has upper case ROM name %s\n", driver->source_file, driver->name, last_name); + mame_printf_error("%s: %s has upper case ROM name %s\n", driver.source_file, driver.name, last_name); error = true; break; } @@ -558,7 +544,7 @@ static bool validate_roms(int drivnum, const machine_config *config, region_arra hash = ROM_GETHASHDATA(romp); if (!hash_verify_string(hash)) { - mame_printf_error("%s: rom '%s' has an invalid hash string '%s'\n", driver->name, last_name, hash); + mame_printf_error("%s: rom '%s' has an invalid hash string '%s'\n", driver.name, last_name, hash); error = true; } } @@ -574,7 +560,7 @@ static bool validate_roms(int drivnum, const machine_config *config, region_arra if (ROM_GETOFFSET(romp) + ROM_GETLENGTH(romp) > currgn->length) { - mame_printf_error("%s: %s has ROM %s extending past the defined memory region\n", driver->source_file, driver->name, last_name); + mame_printf_error("%s: %s has ROM %s extending past the defined memory region\n", driver.source_file, driver.name, last_name); error = true; } } @@ -582,7 +568,7 @@ static bool validate_roms(int drivnum, const machine_config *config, region_arra /* final check for empty regions */ if (items_since_region == 0) - mame_printf_warning("%s: %s has empty ROM region (warning)\n", driver->source_file, driver->name); + mame_printf_warning("%s: %s has empty ROM region (warning)\n", driver.source_file, driver.name); } return error; @@ -594,20 +580,20 @@ static bool validate_roms(int drivnum, const machine_config *config, region_arra configurations -------------------------------------------------*/ -static bool validate_display(int drivnum, const machine_config *config) +static bool validate_display(const machine_config &config) { - const game_driver *driver = drivers[drivnum]; + const game_driver &driver = config.gamedrv(); bool palette_modes = false; bool error = false; - for (const screen_device_config *scrconfig = screen_first(*config); scrconfig != NULL; scrconfig = screen_next(scrconfig)) + for (const screen_device_config *scrconfig = screen_first(config); scrconfig != NULL; scrconfig = screen_next(scrconfig)) if (scrconfig->format() == BITMAP_FORMAT_INDEXED16) palette_modes = true; /* check for empty palette */ - if (palette_modes && config->m_total_colors == 0) + if (palette_modes && config.m_total_colors == 0) { - mame_printf_error("%s: %s has zero palette entries\n", driver->source_file, driver->name); + mame_printf_error("%s: %s has zero palette entries\n", driver.source_file, driver.name); error = true; } @@ -620,23 +606,23 @@ static bool validate_display(int drivnum, const machine_config *config) configuration -------------------------------------------------*/ -static bool validate_gfx(int drivnum, const machine_config *config, region_array *rgninfo) +static bool validate_gfx(const machine_config &config, region_array *rgninfo) { - const game_driver *driver = drivers[drivnum]; + const game_driver &driver = config.gamedrv(); bool error = false; int gfxnum; /* bail if no gfx */ - if (!config->m_gfxdecodeinfo) + if (!config.m_gfxdecodeinfo) return false; /* iterate over graphics decoding entries */ - for (gfxnum = 0; gfxnum < MAX_GFX_ELEMENTS && config->m_gfxdecodeinfo[gfxnum].gfxlayout != NULL; gfxnum++) + for (gfxnum = 0; gfxnum < MAX_GFX_ELEMENTS && config.m_gfxdecodeinfo[gfxnum].gfxlayout != NULL; gfxnum++) { - const gfx_decode_entry *gfx = &config->m_gfxdecodeinfo[gfxnum]; + const gfx_decode_entry *gfx = &config.m_gfxdecodeinfo[gfxnum]; const char *region = gfx->memory_region; - int xscale = (config->m_gfxdecodeinfo[gfxnum].xscale == 0) ? 1 : config->m_gfxdecodeinfo[gfxnum].xscale; - int yscale = (config->m_gfxdecodeinfo[gfxnum].yscale == 0) ? 1 : config->m_gfxdecodeinfo[gfxnum].yscale; + int xscale = (config.m_gfxdecodeinfo[gfxnum].xscale == 0) ? 1 : config.m_gfxdecodeinfo[gfxnum].xscale; + int yscale = (config.m_gfxdecodeinfo[gfxnum].yscale == 0) ? 1 : config.m_gfxdecodeinfo[gfxnum].yscale; const gfx_layout *gl = gfx->gfxlayout; int israw = (gl->planeoffset[0] == GFX_RAW); int planes = gl->planes; @@ -655,7 +641,7 @@ static bool validate_gfx(int drivnum, const machine_config *config, region_array /* stop if we hit an empty */ if (!rgninfo->entries[rgnnum].tag) { - mame_printf_error("%s: %s has gfx[%d] referencing non-existent region '%s'\n", driver->source_file, driver->name, gfxnum, region); + mame_printf_error("%s: %s has gfx[%d] referencing non-existent region '%s'\n", driver.source_file, driver.name, gfxnum, region); error = true; break; } @@ -686,7 +672,7 @@ static bool validate_gfx(int drivnum, const machine_config *config, region_array /* if not, this is an error */ if ((start + len) / 8 > avail) { - mame_printf_error("%s: %s has gfx[%d] extending past allocated memory of region '%s'\n", driver->source_file, driver->name, gfxnum, region); + mame_printf_error("%s: %s has gfx[%d] extending past allocated memory of region '%s'\n", driver.source_file, driver.name, gfxnum, region); error = true; } } @@ -699,13 +685,13 @@ static bool validate_gfx(int drivnum, const machine_config *config, region_array { if (total != RGN_FRAC(1,1)) { - mame_printf_error("%s: %s has gfx[%d] with unsupported layout total\n", driver->source_file, driver->name, gfxnum); + mame_printf_error("%s: %s has gfx[%d] with unsupported layout total\n", driver.source_file, driver.name, gfxnum); error = true; } if (xscale != 1 || yscale != 1) { - mame_printf_error("%s: %s has gfx[%d] with unsupported xscale/yscale\n", driver->source_file, driver->name, gfxnum); + mame_printf_error("%s: %s has gfx[%d] with unsupported xscale/yscale\n", driver.source_file, driver.name, gfxnum); error = true; } } @@ -713,13 +699,13 @@ static bool validate_gfx(int drivnum, const machine_config *config, region_array { if (planes > MAX_GFX_PLANES) { - mame_printf_error("%s: %s has gfx[%d] with invalid planes\n", driver->source_file, driver->name, gfxnum); + mame_printf_error("%s: %s has gfx[%d] with invalid planes\n", driver.source_file, driver.name, gfxnum); error = true; } if (xscale * width > MAX_ABS_GFX_SIZE || yscale * height > MAX_ABS_GFX_SIZE) { - mame_printf_error("%s: %s has gfx[%d] with invalid xscale/yscale\n", driver->source_file, driver->name, gfxnum); + mame_printf_error("%s: %s has gfx[%d] with invalid xscale/yscale\n", driver.source_file, driver.name, gfxnum); error = true; } } @@ -735,13 +721,13 @@ static bool validate_gfx(int drivnum, const machine_config *config, region_array strings -------------------------------------------------*/ -static int get_defstr_index(int_map &defstr_map, const char *name, const game_driver *driver, bool *error) +static int get_defstr_index(int_map &defstr_map, const char *name, const game_driver &driver, bool *error) { /* check for strings that should be DEF_STR */ int strindex = defstr_map.find(name); if (strindex != 0 && name != input_port_string_from_index(strindex) && error != NULL) { - mame_printf_error("%s: %s must use DEF_STR( %s )\n", driver->source_file, driver->name, name); + mame_printf_error("%s: %s must use DEF_STR( %s )\n", driver.source_file, driver.name, name); *error = true; } @@ -754,7 +740,7 @@ static int get_defstr_index(int_map &defstr_map, const char *name, const game_dr analog input field -------------------------------------------------*/ -static void validate_analog_input_field(const input_field_config *field, const game_driver *driver, bool *error) +static void validate_analog_input_field(const input_field_config *field, const game_driver &driver, bool *error) { INT32 analog_max = field->max; INT32 analog_min = field->min; @@ -769,7 +755,7 @@ static void validate_analog_input_field(const input_field_config *field, const g /* positional port size must fit in bits used */ if (((field->mask >> shift) + 1) < field->max) { - mame_printf_error("%s: %s has an analog port with a positional port size bigger then the mask size\n", driver->source_file, driver->name); + mame_printf_error("%s: %s has an analog port with a positional port size bigger then the mask size\n", driver.source_file, driver.name); *error = true; } } @@ -778,7 +764,7 @@ static void validate_analog_input_field(const input_field_config *field, const g /* only positional controls use PORT_WRAPS */ if (field->flags & ANALOG_FLAG_WRAPS) { - mame_printf_error("%s: %s only positional analog ports use PORT_WRAPS\n", driver->source_file, driver->name); + mame_printf_error("%s: %s only positional analog ports use PORT_WRAPS\n", driver.source_file, driver.name); *error = true; } } @@ -786,14 +772,14 @@ static void validate_analog_input_field(const input_field_config *field, const g /* analog ports must have a valid sensitivity */ if (field->sensitivity == 0) { - mame_printf_error("%s: %s has an analog port with zero sensitivity\n", driver->source_file, driver->name); + mame_printf_error("%s: %s has an analog port with zero sensitivity\n", driver.source_file, driver.name); *error = true; } /* check that the default falls in the bitmask range */ if (field->defvalue & ~field->mask) { - mame_printf_error("%s: %s has an analog port with a default value out of the bitmask range\n", driver->source_file, driver->name); + mame_printf_error("%s: %s has an analog port with a default value out of the bitmask range\n", driver.source_file, driver.name); *error = true; } @@ -813,7 +799,7 @@ static void validate_analog_input_field(const input_field_config *field, const g /* check that the default falls in the MINMAX range */ if (default_value < analog_min || default_value > analog_max) { - mame_printf_error("%s: %s has an analog port with a default value out PORT_MINMAX range\n", driver->source_file, driver->name); + mame_printf_error("%s: %s has an analog port with a default value out PORT_MINMAX range\n", driver.source_file, driver.name); *error = true; } @@ -821,14 +807,14 @@ static void validate_analog_input_field(const input_field_config *field, const g /* we use the unadjusted min for testing */ if (field->min & ~field->mask || analog_max & ~field->mask) { - mame_printf_error("%s: %s has an analog port with a PORT_MINMAX value out of the bitmask range\n", driver->source_file, driver->name); + mame_printf_error("%s: %s has an analog port with a PORT_MINMAX value out of the bitmask range\n", driver.source_file, driver.name); *error = true; } /* absolute analog ports do not use PORT_RESET */ if (field->flags & ANALOG_FLAG_RESET) { - mame_printf_error("%s: %s - absolute analog ports do not use PORT_RESET\n", driver->source_file, driver->name); + mame_printf_error("%s: %s - absolute analog ports do not use PORT_RESET\n", driver.source_file, driver.name); *error = true; } } @@ -842,7 +828,7 @@ static void validate_analog_input_field(const input_field_config *field, const g /* relative devices do not use PORT_MINMAX */ if (field->min != 0 || field->max != field->mask) { - mame_printf_error("%s: %s - relative ports do not use PORT_MINMAX\n", driver->source_file, driver->name); + mame_printf_error("%s: %s - relative ports do not use PORT_MINMAX\n", driver.source_file, driver.name); *error = true; } @@ -850,7 +836,7 @@ static void validate_analog_input_field(const input_field_config *field, const g /* the counter is at 0 on power up */ if (field->defvalue != 0) { - mame_printf_error("%s: %s - relative ports do not use a default value other then 0\n", driver->source_file, driver->name); + mame_printf_error("%s: %s - relative ports do not use a default value other then 0\n", driver.source_file, driver.name); *error = true; } } @@ -863,7 +849,7 @@ static void validate_analog_input_field(const input_field_config *field, const g setting -------------------------------------------------*/ -static void validate_dip_settings(const input_field_config *field, const game_driver *driver, int_map &defstr_map, bool *error) +static void validate_dip_settings(const input_field_config *field, const game_driver &driver, int_map &defstr_map, bool *error) { const char *demo_sounds = input_port_string_from_index(INPUT_STRING_Demo_Sounds); const char *flipscreen = input_port_string_from_index(INPUT_STRING_Flip_Screen); @@ -883,21 +869,21 @@ static void validate_dip_settings(const input_field_config *field, const game_dr /* make sure demo sounds default to on */ if (field->name == demo_sounds && strindex == INPUT_STRING_On && field->defvalue != setting->value) { - mame_printf_error("%s: %s Demo Sounds must default to On\n", driver->source_file, driver->name); + mame_printf_error("%s: %s Demo Sounds must default to On\n", driver.source_file, driver.name); *error = true; } /* check for bad demo sounds options */ if (field->name == demo_sounds && (strindex == INPUT_STRING_Yes || strindex == INPUT_STRING_No)) { - mame_printf_error("%s: %s has wrong Demo Sounds option %s (must be Off/On)\n", driver->source_file, driver->name, setting->name); + mame_printf_error("%s: %s has wrong Demo Sounds option %s (must be Off/On)\n", driver.source_file, driver.name, setting->name); *error = true; } /* check for bad flip screen options */ if (field->name == flipscreen && (strindex == INPUT_STRING_Yes || strindex == INPUT_STRING_No)) { - mame_printf_error("%s: %s has wrong Flip Screen option %s (must be Off/On)\n", driver->source_file, driver->name, setting->name); + mame_printf_error("%s: %s has wrong Flip Screen option %s (must be Off/On)\n", driver.source_file, driver.name, setting->name); *error = true; } @@ -909,21 +895,21 @@ static void validate_dip_settings(const input_field_config *field, const game_dr /* check for inverted off/on dispswitch order */ if (strindex == INPUT_STRING_On && next_strindex == INPUT_STRING_Off) { - mame_printf_error("%s: %s has inverted Off/On dipswitch order\n", driver->source_file, driver->name); + mame_printf_error("%s: %s has inverted Off/On dipswitch order\n", driver.source_file, driver.name); *error = true; } /* check for inverted yes/no dispswitch order */ else if (strindex == INPUT_STRING_Yes && next_strindex == INPUT_STRING_No) { - mame_printf_error("%s: %s has inverted No/Yes dipswitch order\n", driver->source_file, driver->name); + mame_printf_error("%s: %s has inverted No/Yes dipswitch order\n", driver.source_file, driver.name); *error = true; } /* check for inverted upright/cocktail dispswitch order */ else if (strindex == INPUT_STRING_Cocktail && next_strindex == INPUT_STRING_Upright) { - mame_printf_error("%s: %s has inverted Upright/Cocktail dipswitch order\n", driver->source_file, driver->name); + mame_printf_error("%s: %s has inverted Upright/Cocktail dipswitch order\n", driver.source_file, driver.name); *error = true; } @@ -931,7 +917,7 @@ static void validate_dip_settings(const input_field_config *field, const game_dr else if (strindex >= INPUT_STRING_9C_1C && strindex <= INPUT_STRING_1C_9C && next_strindex >= INPUT_STRING_9C_1C && next_strindex <= INPUT_STRING_1C_9C && strindex >= next_strindex && memcmp(&setting->condition, &setting->next->condition, sizeof(setting->condition)) == 0) { - mame_printf_error("%s: %s has unsorted coinage %s > %s\n", driver->source_file, driver->name, setting->name, setting->next->name); + mame_printf_error("%s: %s has unsorted coinage %s > %s\n", driver.source_file, driver.name, setting->name, setting->next->name); coin_error = *error = true; } } @@ -942,7 +928,7 @@ static void validate_dip_settings(const input_field_config *field, const game_dr { int entry; - mame_printf_error("%s: %s proper coin sort order should be:\n", driver->source_file, driver->name); + mame_printf_error("%s: %s proper coin sort order should be:\n", driver.source_file, driver.name); for (entry = 0; entry < ARRAY_LENGTH(coin_list); entry++) if (coin_list[entry]) mame_printf_error("%s\n", input_port_string_from_index(INPUT_STRING_9C_1C + entry)); @@ -954,25 +940,25 @@ static void validate_dip_settings(const input_field_config *field, const game_dr validate_inputs - validate input configuration -------------------------------------------------*/ -static bool validate_inputs(int drivnum, const machine_config *config, int_map &defstr_map, ioport_list &portlist) +static bool validate_inputs(const machine_config &config, int_map &defstr_map, ioport_list &portlist) { const input_port_config *scanport; const input_port_config *port; const input_field_config *field; - const game_driver *driver = drivers[drivnum]; + const game_driver &driver = config.gamedrv(); int empty_string_found = FALSE; char errorbuf[1024]; bool error = false; /* skip if no ports */ - if (driver->ipt == NULL) + if (driver.ipt == NULL) return FALSE; /* allocate the input ports */ - input_port_list_init(portlist, driver->ipt, errorbuf, sizeof(errorbuf), FALSE); + input_port_list_init(portlist, driver.ipt, errorbuf, sizeof(errorbuf), FALSE); if (errorbuf[0] != 0) { - mame_printf_error("%s: %s has input port errors:\n%s\n", driver->source_file, driver->name, errorbuf); + mame_printf_error("%s: %s has input port errors:\n%s\n", driver.source_file, driver.name, errorbuf); error = true; } @@ -982,7 +968,7 @@ static bool validate_inputs(int drivnum, const machine_config *config, int_map & for (scanport = port->next(); scanport != NULL; scanport = scanport->next()) if (scanport->tag != NULL && strcmp(port->tag, scanport->tag) == 0) { - mame_printf_error("%s: %s has a duplicate input port tag '%s'\n", driver->source_file, driver->name, port->tag); + mame_printf_error("%s: %s has a duplicate input port tag '%s'\n", driver.source_file, driver.name, port->tag); error = true; } @@ -1003,7 +989,7 @@ static bool validate_inputs(int drivnum, const machine_config *config, int_map & /* dip switch fields must have a name */ if (field->name == NULL) { - mame_printf_error("%s: %s has a DIP switch name or setting with no name\n", driver->source_file, driver->name); + mame_printf_error("%s: %s has a DIP switch name or setting with no name\n", driver.source_file, driver.name); error = true; } @@ -1014,7 +1000,7 @@ static bool validate_inputs(int drivnum, const machine_config *config, int_map & /* look for invalid (0) types which should be mapped to IPT_OTHER */ if (field->type == IPT_INVALID) { - mame_printf_error("%s: %s has an input port with an invalid type (0); use IPT_OTHER instead\n", driver->source_file, driver->name); + mame_printf_error("%s: %s has an input port with an invalid type (0); use IPT_OTHER instead\n", driver.source_file, driver.name); error = true; } @@ -1024,21 +1010,21 @@ static bool validate_inputs(int drivnum, const machine_config *config, int_map & /* check for empty string */ if (field->name[0] == 0 && !empty_string_found) { - mame_printf_error("%s: %s has an input with an empty string\n", driver->source_file, driver->name); + mame_printf_error("%s: %s has an input with an empty string\n", driver.source_file, driver.name); empty_string_found = error = true; } /* check for trailing spaces */ if (field->name[0] != 0 && field->name[strlen(field->name) - 1] == ' ') { - mame_printf_error("%s: %s input '%s' has trailing spaces\n", driver->source_file, driver->name, field->name); + mame_printf_error("%s: %s input '%s' has trailing spaces\n", driver.source_file, driver.name, field->name); error = true; } /* check for invalid UTF-8 */ if (!utf8_is_valid_string(field->name)) { - mame_printf_error("%s: %s input '%s' has invalid characters\n", driver->source_file, driver->name, field->name); + mame_printf_error("%s: %s input '%s' has invalid characters\n", driver.source_file, driver.name, field->name); error = true; } @@ -1057,7 +1043,7 @@ static bool validate_inputs(int drivnum, const machine_config *config, int_map & /* if none, error */ if (scanport == NULL) { - mame_printf_error("%s: %s has a condition referencing non-existent input port tag '%s'\n", driver->source_file, driver->name, field->condition.tag); + mame_printf_error("%s: %s has a condition referencing non-existent input port tag '%s'\n", driver.source_file, driver.name, field->condition.tag); error = true; } } @@ -1074,7 +1060,7 @@ static bool validate_inputs(int drivnum, const machine_config *config, int_map & /* if none, error */ if (scanport == NULL) { - mame_printf_error("%s: %s has a condition referencing non-existent input port tag '%s'\n", driver->source_file, driver->name, setting->condition.tag); + mame_printf_error("%s: %s has a condition referencing non-existent input port tag '%s'\n", driver.source_file, driver.name, setting->condition.tag); error = true; } } @@ -1082,7 +1068,6 @@ static bool validate_inputs(int drivnum, const machine_config *config, int_map & error = error || validate_natural_keyboard_statics(); - /* free the config */ return error; } @@ -1092,27 +1077,27 @@ static bool validate_inputs(int drivnum, const machine_config *config, int_map & checks -------------------------------------------------*/ -static bool validate_devices(int drivnum, const machine_config *config, const ioport_list &portlist, region_array *rgninfo) +static bool validate_devices(const machine_config &config, const ioport_list &portlist, region_array *rgninfo) { bool error = false; - const game_driver *driver = drivers[drivnum]; + const game_driver &driver = config.gamedrv(); - for (const device_config *devconfig = config->m_devicelist.first(); devconfig != NULL; devconfig = devconfig->next()) + for (const device_config *devconfig = config.m_devicelist.first(); devconfig != NULL; devconfig = devconfig->next()) { /* validate the device tag */ if (!validate_tag(driver, devconfig->name(), devconfig->tag())) error = true; /* look for duplicates */ - for (const device_config *scanconfig = config->m_devicelist.first(); scanconfig != devconfig; scanconfig = scanconfig->next()) + for (const device_config *scanconfig = config.m_devicelist.first(); scanconfig != devconfig; scanconfig = scanconfig->next()) if (strcmp(scanconfig->tag(), devconfig->tag()) == 0) { - mame_printf_warning("%s: %s has multiple devices with the tag '%s'\n", driver->source_file, driver->name, devconfig->tag()); + mame_printf_warning("%s: %s has multiple devices with the tag '%s'\n", driver.source_file, driver.name, devconfig->tag()); break; } /* check for device-specific validity check */ - if (devconfig->validity_check(*driver)) + if (devconfig->validity_check(driver)) error = true; } @@ -1135,7 +1120,7 @@ bool mame_validitychecks(const game_driver *curdriver) osd_ticks_t input_checks = 0; osd_ticks_t device_checks = 0; - int drivnum, strnum; + int strnum; bool error = false; UINT16 lsbtest; UINT8 a, b; @@ -1187,61 +1172,57 @@ bool mame_validitychecks(const game_driver *curdriver) prep += get_profile_ticks(); /* iterate over all drivers */ - for (drivnum = 0; drivers[drivnum]; drivnum++) + for (int drivnum = 0; drivers[drivnum]; drivnum++) { - const game_driver *driver = drivers[drivnum]; - machine_config *config = NULL; + const game_driver &driver = *drivers[drivnum]; ioport_list portlist; region_array rgninfo; /* non-debug builds only care about games in the same driver */ - if (curdriver != NULL && strcmp(curdriver->source_file, driver->source_file) != 0) + if (curdriver != NULL && strcmp(curdriver->source_file, driver.source_file) != 0) continue; try { /* expand the machine driver */ expansion -= get_profile_ticks(); - config = global_alloc(machine_config(driver->machine_config)); + machine_config config(driver); expansion += get_profile_ticks(); /* validate the driver entry */ driver_checks -= get_profile_ticks(); - error = validate_driver(drivnum, config, names, descriptions) || error; + error = validate_driver(config, names, descriptions) || error; driver_checks += get_profile_ticks(); /* validate the ROM information */ rom_checks -= get_profile_ticks(); - error = validate_roms(drivnum, config, &rgninfo, roms) || error; + error = validate_roms(config, &rgninfo, roms) || error; rom_checks += get_profile_ticks(); /* validate input ports */ input_checks -= get_profile_ticks(); - error = validate_inputs(drivnum, config, defstr, portlist) || error; + error = validate_inputs(config, defstr, portlist) || error; input_checks += get_profile_ticks(); /* validate the display */ display_checks -= get_profile_ticks(); - error = validate_display(drivnum, config) || error; + error = validate_display(config) || error; display_checks += get_profile_ticks(); /* validate the graphics decoding */ gfx_checks -= get_profile_ticks(); - error = validate_gfx(drivnum, config, &rgninfo) || error; + error = validate_gfx(config, &rgninfo) || error; gfx_checks += get_profile_ticks(); /* validate devices */ device_checks -= get_profile_ticks(); - error = validate_devices(drivnum, config, portlist, &rgninfo) || error; + error = validate_devices(config, portlist, &rgninfo) || error; device_checks += get_profile_ticks(); } catch (emu_fatalerror &err) { - global_free(config); - throw emu_fatalerror("Validating %s (%s): %s", driver->name, driver->source_file, err.string()); + throw emu_fatalerror("Validating %s (%s): %s", driver.name, driver.source_file, err.string()); } - - global_free(config); } #if (REPORT_TIMES) diff --git a/src/emu/validity.h b/src/emu/validity.h index b70739658a8..39013d674e7 100644 --- a/src/emu/validity.h +++ b/src/emu/validity.h @@ -15,6 +15,6 @@ #define __VALIDITY_H__ bool mame_validitychecks(const game_driver *driver); -bool validate_tag(const game_driver *driver, const char *object, const char *tag); +bool validate_tag(const game_driver &driver, const char *object, const char *tag); #endif