From 1db879e23206c9a2d941c26ca66dc8845a1c105e Mon Sep 17 00:00:00 2001 From: Aaron Giles Date: Mon, 20 Feb 2012 06:06:58 +0000 Subject: [PATCH] Removed rom_source abstraction, which was just mapping to devices anyways. Updated everyone involved to just iterate over devices directly. --- src/emu/audit.c | 119 ++++++++++---------- src/emu/audit.h | 10 +- src/emu/clifront.c | 24 ++-- src/emu/dimemory.c | 7 +- src/emu/imagedev/cartslot.c | 12 +- src/emu/info.c | 219 ++++++++++++++++++------------------ src/emu/info.h | 4 +- src/emu/machine.c | 3 + src/emu/romload.c | 145 +++++++++--------------- src/emu/romload.h | 15 +-- src/emu/validity.c | 9 +- 11 files changed, 261 insertions(+), 306 deletions(-) diff --git a/src/emu/audit.c b/src/emu/audit.c index dfe9e7a0500..676e5e0f487 100644 --- a/src/emu/audit.c +++ b/src/emu/audit.c @@ -77,42 +77,38 @@ media_auditor::summary media_auditor::audit_media(const char *validation) // all searches const char *driverpath = m_enumerator.config().root_device().searchpath(); - // iterate over ROM sources and regions int found = 0; int required = 0; - int sharedFound = 0; - int sharedRequired = 0; + int shared_found = 0; + int shared_required = 0; - for (const rom_source *source = rom_first_source(m_enumerator.config()); source != NULL; source = rom_next_source(*source)) + // iterate over devices and regions + device_iterator deviter(m_enumerator.config().root_device()); + for (device_t *device = deviter.first(); device != NULL; device = deviter.next()) { // determine the search path for this source and iterate through the regions - m_searchpath = source->searchpath(); + m_searchpath = device->searchpath(); // now iterate over regions and ROMs within - for (const rom_entry *region = rom_first_region(*source); region != NULL; region = rom_next_region(region)) + for (const rom_entry *region = rom_first_region(*device); region != NULL; region = rom_next_region(region)) { // temporary hack: add the driver path & region name -astring combinedpath(source->searchpath(), ";", driverpath); -if(source->shortname()) -{ - combinedpath=combinedpath.cat(";"); - combinedpath=combinedpath.cat(source->shortname()); -} +astring combinedpath(device->searchpath(), ";", driverpath); +if (device->shortname()) + combinedpath.cat(";").cat(device->shortname()); m_searchpath = combinedpath; for (const rom_entry *rom = rom_first_file(region); rom; rom = rom_next_file(rom)) { hash_collection hashes(ROM_GETHASHDATA(rom)); - const rom_source *shared_source = find_shared_source(source, hashes, ROM_GETLENGTH(rom)); + device_t *shared_device = find_shared_device(*device, hashes, ROM_GETLENGTH(rom)); // count the number of files with hashes if (!hashes.flag(hash_collection::FLAG_NO_DUMP) && !ROM_ISOPTIONAL(rom)) { required++; - if (shared_source != NULL) - { - sharedRequired++; - } + if (shared_device != NULL) + shared_required++; } // audit a file @@ -127,31 +123,27 @@ m_searchpath = combinedpath; if (record != NULL) { // count the number of files that are found. - if (record->status() == audit_record::STATUS_GOOD || (record->status() == audit_record::STATUS_FOUND_INVALID && find_shared_source(source, record->actual_hashes(), record->actual_length()) == NULL)) + if (record->status() == audit_record::STATUS_GOOD || (record->status() == audit_record::STATUS_FOUND_INVALID && find_shared_device(*device, record->actual_hashes(), record->actual_length()) == NULL)) { found++; - if (shared_source != NULL) - { - sharedFound++; - } + if (shared_device != NULL) + shared_found++; } - record->set_shared_source(shared_source); + record->set_shared_device(shared_device); } } } } // if we only find files that are in the parent & either the set has no unique files or the parent is not found, then assume we don't have the set at all - if (found == sharedFound && required > 0 && (required != sharedRequired || sharedFound == 0)) + if (found == shared_found && required > 0 && (required != shared_required || shared_found == 0)) { m_record_list.reset(); return NOTFOUND; } else if (found == 0 && m_record_list.count() == 0) - { return NONE_NEEDED; - } // return a summary return summarize(m_enumerator.driver().name); @@ -345,9 +337,11 @@ media_auditor::summary media_auditor::summarize(const char *name, astring *strin case audit_record::SUBSTATUS_NOT_FOUND: if (string != NULL) { - const rom_source *shared_source = record->shared_source(); - if (shared_source == NULL) string->catprintf("NOT FOUND\n"); - else string->catprintf("NOT FOUND (%s)\n", shared_source->shortname()); + device_t *shared_device = record->shared_device(); + if (shared_device == NULL) + string->catprintf("NOT FOUND\n"); + else + string->catprintf("NOT FOUND (%s)\n", shared_device->shortname()); } break; @@ -494,43 +488,48 @@ void media_auditor::compute_status(audit_record &record, const rom_entry *rom, b //------------------------------------------------- -// find_shared_source - return the source that +// find_shared_device - return the source that // shares a media entry with the same hashes //------------------------------------------------- -const rom_source *media_auditor::find_shared_source(const rom_source *source, const hash_collection &romhashes, UINT64 romlength) -{ - const rom_source *highest_source = NULL; - if (!romhashes.flag(hash_collection::FLAG_NO_DUMP)) +device_t *media_auditor::find_shared_device(device_t &device, const hash_collection &romhashes, UINT64 romlength) +{ + // doesn't apply to NO_DUMP items + if (romhashes.flag(hash_collection::FLAG_NO_DUMP)) + return NULL; + + // special case for non-root devices + device_t *highest_device = NULL; + if (device.owner() != NULL) { - if (dynamic_cast(source) == NULL) + for (const rom_entry *region = rom_first_region(device); region != NULL; region = rom_next_region(region)) + for (const rom_entry *rom = rom_first_file(region); rom != NULL; rom = rom_next_file(rom)) + if (ROM_GETLENGTH(rom) == romlength) + { + hash_collection hashes(ROM_GETHASHDATA(rom)); + if (hashes == romhashes) + highest_device = &device; + } + } + else + { + // iterate up the parent chain + for (int drvindex = m_enumerator.find(m_enumerator.driver().parent); drvindex != -1; drvindex = m_enumerator.find(m_enumerator.driver(drvindex).parent)) { - for (const rom_entry *region = rom_first_region(*source); region; region = rom_next_region(region)) - for (const rom_entry *rom = rom_first_file(region); rom; rom = rom_next_file(rom)) - if (ROM_GETLENGTH(rom) == romlength) - { - hash_collection hashes(ROM_GETHASHDATA(rom)); - if (hashes == romhashes) - highest_source = source; - } - } - else - { - // iterate up the parent chain - for (int drvindex = m_enumerator.find(m_enumerator.driver().parent); drvindex != -1; drvindex = m_enumerator.find(m_enumerator.driver(drvindex).parent)) - for (const rom_source *source = rom_first_source(m_enumerator.config(drvindex)); source != NULL; source = rom_next_source(*source)) - for (const rom_entry *region = rom_first_region(*source); region; region = rom_next_region(region)) - for (const rom_entry *rom = rom_first_file(region); rom; rom = rom_next_file(rom)) - if (ROM_GETLENGTH(rom) == romlength) - { - hash_collection hashes(ROM_GETHASHDATA(rom)); - if (hashes == romhashes) - highest_source = source; - } + device_iterator deviter(m_enumerator.config().root_device()); + for (device_t *scandevice = deviter.first(); scandevice != NULL; scandevice = deviter.next()) + for (const rom_entry *region = rom_first_region(*scandevice); region; region = rom_next_region(region)) + for (const rom_entry *rom = rom_first_file(region); rom; rom = rom_next_file(rom)) + if (ROM_GETLENGTH(rom) == romlength) + { + hash_collection hashes(ROM_GETHASHDATA(rom)); + if (hashes == romhashes) + highest_device = scandevice; + } } } - return highest_source; + return highest_device; } @@ -546,7 +545,7 @@ audit_record::audit_record(const rom_entry &media, media_type type) m_name(ROM_GETNAME(&media)), m_explength(rom_file_size(&media)), m_length(0), - m_shared_source(NULL) + m_shared_device(NULL) { m_exphashes.from_internal_string(ROM_GETHASHDATA(&media)); } @@ -559,6 +558,6 @@ audit_record::audit_record(const char *name, media_type type) m_name(name), m_explength(0), m_length(0), - m_shared_source(NULL) + m_shared_device(NULL) { } diff --git a/src/emu/audit.h b/src/emu/audit.h index 44190f19557..ee802f94e5f 100644 --- a/src/emu/audit.h +++ b/src/emu/audit.h @@ -114,7 +114,7 @@ public: UINT64 actual_length() const { return m_length; } const hash_collection &expected_hashes() const { return m_exphashes; } const hash_collection &actual_hashes() const { return m_hashes; } - const rom_source *shared_source() const { return m_shared_source; } + device_t *shared_device() const { return m_shared_device; } // setters void set_status(audit_status status, audit_substatus substatus) @@ -129,9 +129,9 @@ public: m_length = length; } - void set_shared_source(const rom_source *shared_source) + void set_shared_device(device_t *shared_device) { - m_shared_source = shared_source; + m_shared_device = shared_device; } private: @@ -145,7 +145,7 @@ private: UINT64 m_length; /* actual length of item */ hash_collection m_exphashes; /* expected hash data */ hash_collection m_hashes; /* actual hash information */ - const rom_source * m_shared_source; /* rom_source that shares the rom */ + device_t * m_shared_device; /* device that shares the rom */ }; @@ -183,7 +183,7 @@ private: audit_record *audit_one_rom(const rom_entry *rom); audit_record *audit_one_disk(const rom_entry *rom); void compute_status(audit_record &record, const rom_entry *rom, bool found); - const rom_source *find_shared_source(const rom_source *source, const hash_collection &romhashes, UINT64 romlength); + device_t *find_shared_device(device_t &device, const hash_collection &romhashes, UINT64 romlength); // internal state simple_list m_record_list; diff --git a/src/emu/clifront.c b/src/emu/clifront.c index 35f4e51372f..1dd301efdfa 100644 --- a/src/emu/clifront.c +++ b/src/emu/clifront.c @@ -463,18 +463,18 @@ void cli_frontend::listcrc(const char *gamename) // iterate through matches, and then through ROMs while (drivlist.next()) - for (const rom_source *source = rom_first_source(drivlist.config()); source != NULL; source = rom_next_source(*source)) - { - bool isdriver = (source == rom_first_source(drivlist.config())); - for (const rom_entry *region = rom_first_region(*source); region; region = rom_next_region(region)) + { + device_iterator deviter(drivlist.config().root_device()); + for (device_t *device = deviter.first(); device != NULL; device = deviter.next()) + for (const rom_entry *region = rom_first_region(*device); region; region = rom_next_region(region)) for (const rom_entry *rom = rom_first_file(region); rom; rom = rom_next_file(rom)) { // if we have a CRC, display it UINT32 crc; if (hash_collection(ROM_GETHASHDATA(rom)).crc(crc)) - mame_printf_info("%08x %-16s \t %-8s \t %s\n", crc, ROM_GETNAME(rom), source->shortname(), isdriver ? drivlist.driver().description : source->name()); + mame_printf_info("%08x %-16s \t %-8s \t %s\n", crc, ROM_GETNAME(rom), device->shortname(), device->name()); } - } + } } @@ -503,8 +503,9 @@ void cli_frontend::listroms(const char *gamename) "Name Size Checksum\n", drivlist.driver().name); // iterate through roms - for (const rom_source *source = rom_first_source(drivlist.config()); source != NULL; source = rom_next_source(*source)) - for (const rom_entry *region = rom_first_region(*source); region; region = rom_next_region(region)) + device_iterator deviter(drivlist.config().root_device()); + for (device_t *device = deviter.first(); device != NULL; device = deviter.next()) + for (const rom_entry *region = rom_first_region(*device); region; region = rom_next_region(region)) for (const rom_entry *rom = rom_first_file(region); rom; rom = rom_next_file(rom)) { // accumulate the total length of all chunks @@ -1649,9 +1650,10 @@ int media_identifier::find_by_hash(const hash_collection &hashes, int length) m_drivlist.reset(); while (m_drivlist.next()) { - // iterate over sources, regions and files within the region */ - for (const rom_source *source = rom_first_source(m_drivlist.config()); source != NULL; source = rom_next_source(*source)) - for (const rom_entry *region = rom_first_region(*source); region != NULL; region = rom_next_region(region)) + // iterate over devices, regions and files within the region */ + device_iterator deviter(m_drivlist.config().root_device()); + for (device_t *device = deviter.first(); device != NULL; device = deviter.next()) + for (const rom_entry *region = rom_first_region(*device); region != NULL; region = rom_next_region(region)) for (const rom_entry *rom = rom_first_file(region); rom != NULL; rom = rom_next_file(rom)) { hash_collection romhashes(ROM_GETHASHDATA(rom)); diff --git a/src/emu/dimemory.c b/src/emu/dimemory.c index 0a806d82341..1f6113937a1 100644 --- a/src/emu/dimemory.c +++ b/src/emu/dimemory.c @@ -301,11 +301,12 @@ void device_memory_interface::interface_validity_check(validity_checker &valid) device().siblingtag(entry_region, entry->m_region); // look for the region - for (const rom_source *source = rom_first_source(device().mconfig()); source != NULL && !found; source = rom_next_source(*source)) - for (const rom_entry *romp = rom_first_region(*source); romp != NULL && !found; romp = rom_next_region(romp)) + device_iterator deviter(device().mconfig().root_device()); + for (device_t *device = deviter.first(); device != NULL; device = deviter.next()) + for (const rom_entry *romp = rom_first_region(*device); romp != NULL && !found; romp = rom_next_region(romp)) { astring fulltag; - rom_region_name(fulltag, &device().mconfig().gamedrv(), source, romp); + rom_region_name(fulltag, *device, romp); if (fulltag == entry_region) { // verify the address range is within the region's bounds diff --git a/src/emu/imagedev/cartslot.c b/src/emu/imagedev/cartslot.c index 47b2f177be1..632da01ce87 100644 --- a/src/emu/imagedev/cartslot.c +++ b/src/emu/imagedev/cartslot.c @@ -171,13 +171,12 @@ int cartslot_image_device::load_cartridge(const rom_entry *romrgn, const rom_ent int cartslot_image_device::process_cartridge(bool load) { - const rom_source *source; const rom_entry *romrgn, *roment; int result = 0; - for (source = rom_first_source(device().machine().config()); source != NULL; source = rom_next_source(*source)) - { - for (romrgn = rom_first_region(*source); romrgn != NULL; romrgn = rom_next_region(romrgn)) + device_iterator deviter(device().mconfig().root_device()); + for (device_t *device = deviter.first(); device != NULL; device = deviter.next()) + for (romrgn = rom_first_region(*device); romrgn != NULL; romrgn = rom_next_region(romrgn)) { roment = romrgn + 1; while(!ROMENTRY_ISREGIONEND(roment)) @@ -185,9 +184,9 @@ int cartslot_image_device::process_cartridge(bool load) if (ROMENTRY_GETTYPE(roment) == ROMENTRYTYPE_CARTRIDGE) { astring regiontag; - device().siblingtag(regiontag, roment->_hashdata); + this->device().siblingtag(regiontag, roment->_hashdata); - if (strcmp(regiontag.cstr(),device().tag())==0) + if (strcmp(regiontag.cstr(),this->device().tag())==0) { result |= load_cartridge(romrgn, roment, load); @@ -199,7 +198,6 @@ int cartslot_image_device::process_cartridge(bool load) roment++; } } - } return IMAGE_INIT_PASS; } diff --git a/src/emu/info.c b/src/emu/info.c index a35474f1e52..98b46075746 100644 --- a/src/emu/info.c +++ b/src/emu/info.c @@ -239,7 +239,8 @@ void info_xml_creator::output(FILE *out) CONFIG_VERSION ); - m_device_used = global_alloc_array_clear(UINT8, m_device_count); + m_device_used.resize(m_device_count); + memset(m_device_used, 0, m_device_count); // iterate through the drivers, outputting one at a time while (m_drivlist.next()) @@ -248,8 +249,6 @@ void info_xml_creator::output(FILE *out) // iterate through the devices, and output their roms output_devices(); - global_free(m_device_used); - // close the top level tag fprintf(m_output, "\n",emulator_info::get_xml_root()); } @@ -266,16 +265,19 @@ void info_xml_creator::output_devices() m_drivlist.next(); machine_config &config = m_drivlist.config(); device_t &owner = config.root_device(); + // check if all are listed, note that empty one is included - bool display_all = driver_list::total() == (m_drivlist.count()+1); - for(int i=0;iconfig_complete(); // print the header and the game name - fprintf(m_output, "\t<%s",emulator_info::get_xml_top()); + fprintf(m_output, "\t<%s", emulator_info::get_xml_top()); fprintf(m_output, " name=\"%s\"", xml_normalize_string(dev->shortname())); fprintf(m_output, " isdevice=\"yes\""); fprintf(m_output, " runnable=\"no\""); @@ -285,15 +287,16 @@ void info_xml_creator::output_devices() if (dev->name() != NULL) fprintf(m_output, "\t\t%s\n", xml_normalize_string(dev->name())); - output_rom(dev); + output_rom(*dev); // close the topmost tag - fprintf(m_output, "\t\n",emulator_info::get_xml_top()); + fprintf(m_output, "\t\n", emulator_info::get_xml_top()); global_free(dev); } } } + //------------------------------------------------- // output_one - print the XML information // for one particular game driver @@ -359,7 +362,7 @@ void info_xml_creator::output_one() // now print various additional information output_bios(); - output_rom(rom_first_source(m_drivlist.config())); + output_rom(m_drivlist.config().root_device()); output_device_roms(); output_sample(); output_chips(); @@ -379,6 +382,7 @@ void info_xml_creator::output_one() fprintf(m_output, "\t\n",emulator_info::get_xml_top()); } + //------------------------------------------------ // output_device_roms - print the device // with roms, if appropriate @@ -386,19 +390,18 @@ void info_xml_creator::output_one() void info_xml_creator::output_device_roms() { - int cnt=0; - for (const rom_source *source = rom_first_source(m_drivlist.config()); source != NULL; source = rom_next_source(*source)) - { - if (cnt!=0) { - fprintf(m_output, "\t\t\n", xml_normalize_string(source->shortname())); - for(int i=0;itype() == *s_devices_sorted[i]) m_device_used[i] = 1; - } + device_iterator deviter(m_drivlist.config().root_device()); + for (device_t *device = deviter.first(); device != NULL; device = deviter.next()) + if (device->owner() != NULL) + { + fprintf(m_output, "\t\t\n", xml_normalize_string(device->shortname())); + for (int devnum = 0; devnum < m_device_count; devnum++) + if (device->type() == *s_devices_sorted[devnum]) + m_device_used[devnum] = 1; } - cnt++; - } } + //------------------------------------------------ // output_sampleof - print the 'sampleof' // attribute, if appropriate @@ -453,98 +456,96 @@ void info_xml_creator::output_bios() // the XML output //------------------------------------------------- -void info_xml_creator::output_rom(const rom_source *source) +void info_xml_creator::output_rom(device_t &device) { // iterate over 3 different ROM "types": BIOS, ROMs, DISKs for (int rom_type = 0; rom_type < 3; rom_type++) - { - for (const rom_entry *region = rom_first_region(*source); region != NULL; region = rom_next_region(region)) - { - bool is_disk = ROMREGION_ISDISKDATA(region); + for (const rom_entry *region = rom_first_region(device); region != NULL; region = rom_next_region(region)) + { + bool is_disk = ROMREGION_ISDISKDATA(region); - // disk regions only work for disks - if ((is_disk && rom_type != 2) || (!is_disk && rom_type == 2)) + // disk regions only work for disks + if ((is_disk && rom_type != 2) || (!is_disk && rom_type == 2)) + continue; + + // iterate through ROM entries + for (const rom_entry *rom = rom_first_file(region); rom != NULL; rom = rom_next_file(rom)) + { + bool is_bios = ROM_GETBIOSFLAGS(rom); + const char *name = ROM_GETNAME(rom); + int offset = ROM_GETOFFSET(rom); + const char *merge_name = NULL; + char bios_name[100]; + + // BIOS ROMs only apply to bioses + if ((is_bios && rom_type != 0) || (!is_bios && rom_type == 0)) continue; - // iterate through ROM entries - for (const rom_entry *rom = rom_first_file(region); rom != NULL; rom = rom_next_file(rom)) + // if we have a valid ROM and we are a clone, see if we can find the parent ROM + hash_collection hashes(ROM_GETHASHDATA(rom)); + if (!hashes.flag(hash_collection::FLAG_NO_DUMP)) + merge_name = get_merge_name(hashes); + + // scan for a BIOS name + bios_name[0] = 0; + if (!is_disk && is_bios) { - bool is_bios = ROM_GETBIOSFLAGS(rom); - const char *name = ROM_GETNAME(rom); - int offset = ROM_GETOFFSET(rom); - const char *merge_name = NULL; - char bios_name[100]; - - // BIOS ROMs only apply to bioses - if ((is_bios && rom_type != 0) || (!is_bios && rom_type == 0)) - continue; - - // if we have a valid ROM and we are a clone, see if we can find the parent ROM - hash_collection hashes(ROM_GETHASHDATA(rom)); - if (!hashes.flag(hash_collection::FLAG_NO_DUMP)) - merge_name = get_merge_name(hashes); - - // scan for a BIOS name - bios_name[0] = 0; - if (!is_disk && is_bios) - { - // scan backwards through the ROM entries - for (const rom_entry *brom = rom - 1; brom != m_drivlist.driver().rom; brom--) - if (ROMENTRY_ISSYSTEM_BIOS(brom)) - { - strcpy(bios_name, ROM_GETNAME(brom)); - break; - } - } - - // opening tag - if (!is_disk) - fprintf(m_output, "\t\t\n"); + // scan backwards through the ROM entries + for (const rom_entry *brom = rom - 1; brom != m_drivlist.driver().rom; brom--) + if (ROMENTRY_ISSYSTEM_BIOS(brom)) + { + strcpy(bios_name, ROM_GETNAME(brom)); + break; + } } + + // opening tag + if (!is_disk) + fprintf(m_output, "\t\t\n"); } - } + } } @@ -1262,13 +1263,14 @@ void info_xml_creator::output_ramoptions() const char *info_xml_creator::get_merge_name(const hash_collection &romhashes) { - const char *merge_name = NULL; // walk the parent chain + const char *merge_name = NULL; for (int clone_of = m_drivlist.find(m_drivlist.driver().parent); clone_of != -1; clone_of = m_drivlist.find(m_drivlist.driver(clone_of).parent)) - + { // look in the parent's ROMs - for (const rom_source *psource = rom_first_source(m_drivlist.config(clone_of,m_lookup_options)); psource != NULL; psource = rom_next_source(*psource)) - for (const rom_entry *pregion = rom_first_region(*psource); pregion != NULL; pregion = rom_next_region(pregion)) + device_iterator deviter(m_drivlist.config(clone_of, m_lookup_options).root_device()); + for (device_t *device = deviter.first(); device != NULL; device = deviter.next()) + for (const rom_entry *pregion = rom_first_region(*device); pregion != NULL; pregion = rom_next_region(pregion)) for (const rom_entry *prom = rom_first_file(pregion); prom != NULL; prom = rom_next_file(prom)) { hash_collection phashes(ROM_GETHASHDATA(prom)); @@ -1279,6 +1281,7 @@ const char *info_xml_creator::get_merge_name(const hash_collection &romhashes) break; } } + } return merge_name; } diff --git a/src/emu/info.h b/src/emu/info.h index 34a1137ff0c..f88bf73f72a 100644 --- a/src/emu/info.h +++ b/src/emu/info.h @@ -62,7 +62,7 @@ private: void output_one(); void output_sampleof(); void output_bios(); - void output_rom(const rom_source *source); + void output_rom(device_t &device); void output_device_roms(); void output_sample(); void output_chips(); @@ -85,7 +85,7 @@ private: // internal state FILE * m_output; driver_enumerator & m_drivlist; - UINT8 * m_device_used; + dynamic_array m_device_used; emu_options m_lookup_options; static const char s_dtd_string[]; diff --git a/src/emu/machine.c b/src/emu/machine.c index 509b9834892..7e6f39e3475 100644 --- a/src/emu/machine.c +++ b/src/emu/machine.c @@ -1083,6 +1083,9 @@ void driver_device::static_set_game(device_t &device, const game_driver &game) // set the short name to the game's name driver.m_shortname = game.name; + + // set the full name to the game's description + driver.m_name = game.description; // and set the search path to include all parents driver.m_searchpath = game.name; diff --git a/src/emu/romload.c b/src/emu/romload.c index c51427f8366..78164fcee0c 100644 --- a/src/emu/romload.c +++ b/src/emu/romload.c @@ -164,54 +164,14 @@ int set_disk_handle(running_machine &machine, const char *region, const char *fu ROM LOADING ***************************************************************************/ -/*------------------------------------------------- - rom_first_source - return pointer to first ROM - source --------------------------------------------------*/ - -const rom_source *rom_first_source(const machine_config &config) -{ - /* look through devices */ - device_iterator iter(config.root_device()); - for (const device_t *device = iter.first(); device != NULL; device = iter.next()) - if (device->rom_region() != NULL) - return device; - - return NULL; -} - - -/*------------------------------------------------- - rom_next_source - return pointer to next ROM - source --------------------------------------------------*/ - -const rom_source *rom_next_source(const rom_source &previous) -{ - /* look for further devices with ROM definitions */ -// fixme: this is awful - device_iterator iter(previous.mconfig().root_device()); - const device_t *device; - for (device = iter.first(); device != NULL; device = iter.next()) - if (device == &previous) - break; - - for (device = iter.next(); device != NULL; device = iter.next()) - if (device->rom_region() != NULL) - return device; - - return NULL; -} - - /*------------------------------------------------- rom_first_region - return pointer to first ROM region -------------------------------------------------*/ -const rom_entry *rom_first_region(const rom_source &source) +const rom_entry *rom_first_region(const device_t &device) { - const rom_entry *romp = source.rom_region(); + const rom_entry *romp = device.rom_region(); return (romp != NULL && !ROMENTRY_ISEND(romp)) ? romp : NULL; } @@ -263,9 +223,9 @@ const rom_entry *rom_next_file(const rom_entry *romp) for a rom region -------------------------------------------------*/ -astring &rom_region_name(astring &result, const game_driver *drv, const rom_source *source, const rom_entry *romp) +astring &rom_region_name(astring &result, const device_t &device, const rom_entry *romp) { - return source->subtag(result, ROM_GETNAME(romp)); + return device.subtag(result, ROM_GETNAME(romp)); } @@ -333,46 +293,45 @@ static void determine_bios_rom(rom_load_data *romdata) romdata->system_bios = 0; - for (const rom_source *source = rom_first_source(romdata->machine().config()); source != NULL; source = rom_next_source(*source)) - { - /* first determine the default BIOS name */ - for (rom = source->rom_region(); !ROMENTRY_ISEND(rom); rom++) - if (ROMENTRY_ISDEFAULT_BIOS(rom)) - defaultname = ROM_GETNAME(rom); + device_t &rootdevice = romdata->machine().config().root_device(); - /* 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]; + /* first determine the default BIOS name */ + for (rom = rootdevice.rom_region(); !ROMENTRY_ISEND(rom); rom++) + if (ROMENTRY_ISDEFAULT_BIOS(rom)) + defaultname = ROM_GETNAME(rom); - /* Allow '-bios n' to still be used */ - sprintf(bios_number, "%d", bios_flags - 1); - if (mame_stricmp(bios_number, specbios) == 0 || mame_stricmp(biosname, specbios) == 0) - romdata->system_bios = bios_flags; - if (defaultname != NULL && mame_stricmp(biosname, defaultname) == 0) - default_no = bios_flags; - bios_count++; - } - - /* if none found, use the default */ - if (romdata->system_bios == 0 && bios_count > 0) + /* look for a BIOS with a matching name */ + for (rom = rootdevice.rom_region(); !ROMENTRY_ISEND(rom); rom++) + if (ROMENTRY_ISSYSTEM_BIOS(rom)) { - /* 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++; - } + const char *biosname = ROM_GETNAME(rom); + int bios_flags = ROM_GETBIOSFLAGS(rom); + char bios_number[20]; - /* set to default */ - romdata->system_bios = default_no; + /* Allow '-bios n' to still be used */ + sprintf(bios_number, "%d", bios_flags - 1); + if (mame_stricmp(bios_number, specbios) == 0 || mame_stricmp(biosname, specbios) == 0) + romdata->system_bios = bios_flags; + if (defaultname != NULL && mame_stricmp(biosname, defaultname) == 0) + default_no = bios_flags; + bios_count++; } - romdata->default_bios = default_no; - LOG(("Using System BIOS: %d\n", romdata->system_bios)); + + /* if none found, use the default */ + if (romdata->system_bios == 0 && bios_count > 0) + { + /* 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; } + romdata->default_bios = default_no; + LOG(("Using System BIOS: %d\n", romdata->system_bios)); } @@ -384,15 +343,15 @@ static void determine_bios_rom(rom_load_data *romdata) static void count_roms(rom_load_data *romdata) { const rom_entry *region, *rom; - const rom_source *source; /* start with 0 */ romdata->romstotal = 0; romdata->romstotalsize = 0; /* loop over regions, then over files */ - 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)) + device_iterator deviter(romdata->machine().config().root_device()); + for (device_t *device = deviter.first(); device != NULL; device = deviter.next()) + for (region = rom_first_region(*device); 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) { @@ -1003,7 +962,6 @@ int open_disk_image(emu_options &options, const game_driver *gamedrv, const rom_ { emu_file image_file(options.media_path(), OPEN_FLAG_READ); const rom_entry *region, *rom; - const rom_source *source; file_error filerr; chd_error err; @@ -1107,8 +1065,9 @@ int open_disk_image(emu_options &options, const game_driver *gamedrv, const rom_ for (int drv = driver_list::find(*gamedrv); drv != -1; drv = driver_list::clone(drv)) { machine_config config(driver_list::driver(drv), options); - 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)) + device_iterator deviter(config.root_device()); + for (device_t *device = deviter.first(); device != NULL; device = deviter.next()) + for (region = rom_first_region(*device); region != NULL; region = rom_next_region(region)) if (ROMREGION_ISDISKDATA(region)) for (rom = rom_first_file(region); rom != NULL; rom = rom_next_file(rom)) @@ -1430,16 +1389,15 @@ void load_software_part_region(device_t *device, char *swlist, char *swname, rom static void process_region_list(rom_load_data *romdata) { astring regiontag; - const rom_source *source; - const rom_entry *region; /* loop until we hit the end */ - 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)) + device_iterator deviter(romdata->machine().root_device()); + for (device_t *device = deviter.first(); device != NULL; device = deviter.next()) + for (const rom_entry *region = rom_first_region(*device); region != NULL; region = rom_next_region(region)) { UINT32 regionlength = ROMREGION_GETLENGTH(region); - rom_region_name(regiontag, &romdata->machine().system(), source, region); + rom_region_name(regiontag, *device, region); LOG(("Processing region \"%s\" (length=%X)\n", regiontag.cstr(), regionlength)); /* the first entry must be a region */ @@ -1472,16 +1430,17 @@ static void process_region_list(rom_load_data *romdata) #endif /* now process the entries in the region */ - process_rom_entries(romdata, (source->shortname()!=NULL) ? source->shortname() : NULL, region, region + 1); + process_rom_entries(romdata, device->shortname(), region, region + 1); } else if (ROMREGION_ISDISKDATA(region)) process_disk_entries(romdata, regiontag, region, region + 1, NULL); } /* now go back and post-process all the regions */ - 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)) { - rom_region_name(regiontag, &romdata->machine().system(), source, region); + for (device_t *device = deviter.first(); device != NULL; device = deviter.next()) + for (const rom_entry *region = rom_first_region(*device); region != NULL; region = rom_next_region(region)) + { + rom_region_name(regiontag, *device, region); region_post_process(romdata, regiontag, ROMREGION_ISINVERTED(region)); } } diff --git a/src/emu/romload.h b/src/emu/romload.h index 108eabd1820..2dfdffe214b 100644 --- a/src/emu/romload.h +++ b/src/emu/romload.h @@ -123,8 +123,6 @@ class machine_config; class emu_options; class chd_file; -typedef device_t rom_source; - struct rom_entry { @@ -284,14 +282,8 @@ file_error common_process_file(emu_options &options, const char *location, bool /* ----- ROM iteration ----- */ -/* return pointer to first ROM source */ -const rom_source *rom_first_source(const machine_config &config); - -/* return pointer to next ROM source */ -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 rom_source &romp); +const rom_entry *rom_first_region(const device_t &romp); /* return pointer to the next ROM region within a source */ const rom_entry *rom_next_region(const rom_entry *romp); @@ -302,14 +294,11 @@ const rom_entry *rom_first_file(const rom_entry *romp); /* return pointer to the next ROM file within a region */ const rom_entry *rom_next_file(const rom_entry *romp); -/* 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 the expected size of a file given the ROM description */ UINT32 rom_file_size(const rom_entry *romp); /* return the appropriate name for a rom region */ -astring &rom_region_name(astring &result, const game_driver *drv, const rom_source *source, const rom_entry *romp); +astring &rom_region_name(astring &result, const device_t &device, const rom_entry *romp); diff --git a/src/emu/validity.c b/src/emu/validity.c index 843f6b08acd..dcfa5465f05 100644 --- a/src/emu/validity.c +++ b/src/emu/validity.c @@ -616,10 +616,11 @@ void validity_checker::validate_driver() void validity_checker::validate_roms() { // iterate, starting with the driver's ROMs and continuing with device ROMs - for (const rom_source *source = rom_first_source(*m_current_config); source != NULL; source = rom_next_source(*source)) + device_iterator deviter(m_current_config->root_device()); + for (device_t *device = deviter.first(); device != NULL; device = deviter.next()) { // for non-root devices, track the current device - m_current_device = (source == &m_current_config->root_device()) ? NULL : source; + m_current_device = (device->owner() == NULL) ? NULL : device; // scan the ROM entries for this device const char *last_region_name = "???"; @@ -628,7 +629,7 @@ void validity_checker::validate_roms() int items_since_region = 1; int last_bios = 0; int total_files = 0; - for (const rom_entry *romp = rom_first_region(*source); !ROMENTRY_ISEND(romp); romp++) + for (const rom_entry *romp = rom_first_region(*device); romp != NULL && !ROMENTRY_ISEND(romp); romp++) { // if this is a region, make sure it's valid, and record the length if (ROMENTRY_ISREGION(romp)) @@ -654,7 +655,7 @@ void validity_checker::validate_roms() // generate the full tag astring fulltag; - rom_region_name(fulltag, m_current_driver, source, romp); + rom_region_name(fulltag, *device, romp); // attempt to add it to the map, reporting duplicates as errors current_length = ROMREGION_GETLENGTH(romp);