diff options
Diffstat (limited to 'src/emu/romload.cpp')
-rw-r--r-- | src/emu/romload.cpp | 674 |
1 files changed, 403 insertions, 271 deletions
diff --git a/src/emu/romload.cpp b/src/emu/romload.cpp index a728a6a7660..a429153be3f 100644 --- a/src/emu/romload.cpp +++ b/src/emu/romload.cpp @@ -11,12 +11,19 @@ #include "emu.h" #include "romload.h" -#include "emuopts.h" #include "drivenum.h" +#include "emuopts.h" +#include "fileio.h" +#include "main.h" #include "softlist_dev.h" + #include "ui/uimain.h" +#include "corestr.h" +#include "path.h" + #include <algorithm> +#include <cstdarg> #include <set> @@ -36,6 +43,25 @@ namespace { +/*------------------------------------------------- + debugload - log data to a file +-------------------------------------------------*/ + +void ATTR_PRINTF(1,2) debugload(const char *string, ...) +{ + static int opened = 0; + FILE *const f(fopen("romload.log", opened++ ? "a" : "w")); + if (f) + { + va_list arg; + va_start(arg, string); + vfprintf(f, string, arg); + va_end(arg); + fclose(f); + } +} + + auto next_parent_system(game_driver const &system) { return @@ -47,13 +73,41 @@ auto next_parent_system(game_driver const &system) if (0 > parent) { sys = nullptr; + roms.clear(); + roms.shrink_to_fit(); return nullptr; } else { sys = &driver_list::driver(parent); roms = rom_build_entries(sys->rom); - return &roms[0]; + return &roms.front(); + } + }; +} + + +auto next_parent_device(device_t const &device, emu_options &options) +{ + return + [&options, type = &device.type(), roms = std::vector<rom_entry>()] () mutable -> rom_entry const * + { + if (!type) + return nullptr; + type = type->parent_rom_device_type(); + if (!type) + { + roms.clear(); + roms.shrink_to_fit(); + return nullptr; + } + else + { + machine_config config(GAME_NAME(___empty), options); + machine_config::token const tok(config.begin_configuration(config.root_device())); + roms = config.device_add("_tmp", *type, 0)->rom_region_vector(); + config.device_remove("_tmp"); + return &roms.front(); } }; } @@ -88,7 +142,7 @@ std::vector<std::string> make_software_searchpath(software_list_device &swlist, if (std::find(parents.begin(), parents.end(), i) != parents.end()) break; parents.emplace_back(i); - result.emplace_back(util::string_format("%s" PATH_SEPARATOR "%s", swlist.list_name(), i->shortname())); + result.emplace_back(util::path_concat(swlist.list_name(), i->shortname())); i = i->parentname().empty() ? nullptr : swlist.find(i->parentname()); } @@ -100,28 +154,33 @@ std::vector<std::string> make_software_searchpath(software_list_device &swlist, } -chd_error do_open_disk(const emu_options &options, std::initializer_list<std::reference_wrapper<const std::vector<std::string> > > searchpath, const rom_entry *romp, chd_file &chd, std::function<const rom_entry * ()> next_parent) +std::error_condition do_open_disk( + emu_options const &options, + std::initializer_list<std::reference_wrapper<std::vector<std::string> const> > searchpath, + rom_entry const *romp, + chd_file &chd, + std::function<rom_entry const * ()> next_parent, + chd_file::open_parent_func const &open_parent) { // hashes are fixed, but we might need to try multiple filenames std::set<std::string> tried; - const util::hash_collection hashes(ROM_GETHASHDATA(romp)); + util::hash_collection const hashes(romp->hashdata()); std::string filename, fullpath; - const rom_entry *parent(nullptr); - chd_error result(CHDERR_FILE_NOT_FOUND); - while (romp && (CHDERR_NONE != result)) + rom_entry const *parent(nullptr); + std::error_condition result(std::errc::no_such_file_or_directory); + while (romp && result) { - filename = ROM_GETNAME(romp); - filename.append(".chd"); + filename = romp->name() + ".chd"; if (tried.insert(filename).second) { // piggyback on emu_file to find the disk image file std::unique_ptr<emu_file> imgfile; - for (const std::vector<std::string> &paths : searchpath) + for (std::vector<std::string> const &paths : searchpath) { imgfile.reset(new emu_file(options.media_path(), paths, OPEN_FLAG_READ)); imgfile->set_restrict_to_mediapath(1); - const osd_file::error filerr(imgfile->open(filename, OPEN_FLAG_READ)); - if (osd_file::error::NONE == filerr) + std::error_condition const filerr(imgfile->open(filename, OPEN_FLAG_READ)); + if (!filerr) break; else imgfile.reset(); @@ -132,12 +191,12 @@ chd_error do_open_disk(const emu_options &options, std::initializer_list<std::re { fullpath = imgfile->fullpath(); imgfile.reset(); - result = chd.open(fullpath.c_str()); + result = chd.open(fullpath, false, nullptr, open_parent); } } // walk the parents looking for a CHD with the same hashes but a different name - if (CHDERR_NONE != result) + if (result) { while (romp) { @@ -154,10 +213,7 @@ chd_error do_open_disk(const emu_options &options, std::initializer_list<std::re romp = nullptr; break; } - while (ROMENTRY_ISPARAMETER(parent) || ROMENTRY_ISSYSTEM_BIOS(parent) || ROMENTRY_ISDEFAULT_BIOS(parent)) - ++parent; - if (ROMENTRY_ISEND(parent)) - parent = nullptr; + parent = rom_first_region(parent); } else { @@ -170,7 +226,7 @@ chd_error do_open_disk(const emu_options &options, std::initializer_list<std::re } // try it if it matches the hashes - if (romp && (util::hash_collection(ROM_GETHASHDATA(romp)) == hashes)) + if (romp && (util::hash_collection(romp->hashdata()) == hashes)) break; } } @@ -178,6 +234,46 @@ chd_error do_open_disk(const emu_options &options, std::initializer_list<std::re return result; } + +auto open_parent_disk( + emu_options const &options, + std::initializer_list<std::reference_wrapper<std::vector<std::string> const> > searchpath, + std::function<rom_entry const * ()> const &next_parent) +{ + return + [&options, searchpath, next_parent] (util::sha1_t const &sha1) -> std::unique_ptr<chd_file> + { + util::hash_collection hashes; + hashes.add_sha1(sha1); + std::function<rom_entry const * ()> np(next_parent); // important - copy mutable lambda + for (rom_entry const *parent = np(); parent; parent = np()) + { + parent = rom_first_region(parent); + while (parent) + { + while (parent && !ROMREGION_ISDISKDATA(parent)) + parent = rom_next_region(parent); + if (parent) + { + rom_entry const *romp(rom_first_file(parent)); + while (romp) + { + if (util::hash_collection(romp->hashdata()) == hashes) + { + std::unique_ptr<chd_file> chd(new chd_file); + if (!do_open_disk(options, searchpath, romp, *chd, next_parent, nullptr)) + return chd; + } + romp = rom_next_file(romp); + } + parent = rom_next_region(parent); + } + } + } + return nullptr; + }; +} + } // anonymous namespace @@ -257,7 +353,7 @@ const rom_entry *rom_first_parameter(const device_t &device) const rom_entry *romp = &device.rom_region_vector().front(); while (romp && !ROMENTRY_ISEND(romp) && !ROMENTRY_ISPARAMETER(romp)) romp++; - return (romp != nullptr && !ROMENTRY_ISEND(romp)) ? romp : nullptr; + return (romp && !ROMENTRY_ISEND(romp)) ? romp : nullptr; } @@ -282,17 +378,17 @@ const rom_entry *rom_next_parameter(const rom_entry *romp) u32 rom_file_size(const rom_entry *romp) { - u32 maxlength = 0; + u32 maxlength(0); - /* loop until we run out of reloads */ + // loop until we run out of reloads do { - /* loop until we run out of continues/ignores */ + // loop until we run out of continues/ignores u32 curlength = ROM_GETLENGTH(romp++); while (ROMENTRY_ISCONTINUE(romp) || ROMENTRY_ISIGNORE(romp)) curlength += ROM_GETLENGTH(romp++); - /* track the maximum length */ + // track the maximum length maxlength = std::max(maxlength, curlength); } while (ROMENTRY_ISRELOAD(romp)); @@ -301,27 +397,6 @@ u32 rom_file_size(const rom_entry *romp) } -/*------------------------------------------------- - debugload - log data to a file --------------------------------------------------*/ - -static void CLIB_DECL ATTR_PRINTF(1,2) debugload(const char *string, ...) -{ - static int opened; - va_list arg; - FILE *f; - - f = fopen("romload.log", opened++ ? "a" : "w"); - if (f) - { - va_start(arg, string); - vfprintf(f, string, arg); - va_end(arg); - fclose(f); - } -} - - /*************************************************************************** HARD DISK HANDLING ***************************************************************************/ @@ -331,11 +406,13 @@ static void CLIB_DECL ATTR_PRINTF(1,2) debugload(const char *string, ...) CHD file associated with the given region -------------------------------------------------*/ -chd_file *rom_load_manager::get_disk_handle(const char *region) +chd_file *rom_load_manager::get_disk_handle(std::string_view region) { for (auto &curdisk : m_chd_list) - if (strcmp(curdisk->region(), region) == 0) + { + if (curdisk->region() == region) return &curdisk->chd(); + } return nullptr; } @@ -345,37 +422,36 @@ chd_file *rom_load_manager::get_disk_handle(const char *region) file associated with the given region -------------------------------------------------*/ -int rom_load_manager::set_disk_handle(const char *region, const char *fullpath) +std::error_condition rom_load_manager::set_disk_handle(std::string_view region, std::string_view fullpath) { - auto chd = std::make_unique<open_chd>(region); - auto err = chd->orig_chd().open(fullpath); - if (err == CHDERR_NONE) - m_chd_list.push_back(std::move(chd)); + auto chd(std::make_unique<open_chd>(region)); + std::error_condition const err(chd->orig_chd().open(fullpath)); + if (!err) + m_chd_list.emplace_back(std::move(chd)); return err; } /*------------------------------------------------- determine_bios_rom - determine system_bios - from SystemBios structure and OPTION_BIOS + from SYSTEM_BIOS structure and OPTION_BIOS -------------------------------------------------*/ -void rom_load_manager::determine_bios_rom(device_t &device, const char *specbios) +void rom_load_manager::determine_bios_rom(device_t &device, std::string_view specbios) { // default is applied by the device at config complete time - if (specbios && *specbios && core_stricmp(specbios, "default")) + using namespace std::literals; + if (!specbios.empty() && !util::streqlower(specbios, "default"sv)) { bool found(false); - for (const rom_entry &rom : device.rom_region_vector()) + for (rom_entry const &rom : device.rom_region_vector()) { if (ROMENTRY_ISSYSTEM_BIOS(&rom)) { char const *const biosname = ROM_GETNAME(&rom); int const bios_flags = ROM_GETBIOSFLAGS(&rom); - char bios_number[20]; // Allow '-bios n' to still be used - sprintf(bios_number, "%d", bios_flags - 1); - if (!core_stricmp(bios_number, specbios) || !core_stricmp(biosname, specbios)) + if ((specbios == std::to_string(bios_flags - 1)) || util::streqlower(specbios, biosname)) { found = true; device.set_system_bios(bios_flags); @@ -404,21 +480,29 @@ void rom_load_manager::determine_bios_rom(device_t &device, const char *specbios void rom_load_manager::count_roms() { - const rom_entry *region, *rom; - - /* start with 0 */ + // start with 0 m_romstotal = 0; m_romstotalsize = 0; - /* loop over regions, then over files */ - for (device_t &device : device_iterator(machine().config().root_device())) - for (region = rom_first_region(device); region != nullptr; region = rom_next_region(region)) - for (rom = rom_first_file(region); rom != nullptr; rom = rom_next_file(rom)) - if (ROM_GETBIOSFLAGS(rom) == 0 || ROM_GETBIOSFLAGS(rom) == device.system_bios()) + // loop over regions, and files within regions + for (device_t &device : device_enumerator(machine().config().root_device())) + { + rom_entry const *region(rom_first_region(device)); + while (region) + { + rom_entry const *rom(rom_first_file(region)); + while (rom) + { + if ((ROM_GETBIOSFLAGS(rom) == 0) || (ROM_GETBIOSFLAGS(rom) == device.system_bios())) { m_romstotal++; m_romstotalsize += rom_file_size(rom); } + rom = rom_next_file(rom); + } + region = rom_next_region(region); + } + } } @@ -439,7 +523,7 @@ void rom_load_manager::fill_random(u8 *base, u32 length) for missing files -------------------------------------------------*/ -void rom_load_manager::handle_missing_file(const rom_entry *romp, const std::vector<std::string> &tried_file_names, chd_error chderr) +void rom_load_manager::handle_missing_file(const rom_entry *romp, const std::vector<std::string> &tried_file_names, std::error_condition chderr) { std::string tried; if (!tried_file_names.empty()) @@ -453,15 +537,12 @@ void rom_load_manager::handle_missing_file(const rom_entry *romp, const std::vec tried += ')'; } - std::string name(ROM_GETNAME(romp)); - - const bool is_chd(chderr != CHDERR_NONE); - if (is_chd) - name += ".chd"; + const bool is_chd(chderr); + const std::string name(is_chd ? romp->name() + ".chd" : romp->name()); - const bool is_chd_error(is_chd && chderr != CHDERR_FILE_NOT_FOUND); + const bool is_chd_error(is_chd && (chderr != std::errc::no_such_file_or_directory)); if (is_chd_error) - m_errorstring.append(string_format("%s CHD ERROR: %s\n", name.c_str(), chd_file::error_string(chderr))); + m_errorstring.append(string_format("%s CHD ERROR: %s\n", name, chderr.message())); if (ROM_ISOPTIONAL(romp)) { @@ -470,7 +551,7 @@ void rom_load_manager::handle_missing_file(const rom_entry *romp, const std::vec m_errorstring.append(string_format("OPTIONAL %s NOT FOUND%s\n", name, tried)); m_warnings++; } - else if (util::hash_collection(ROM_GETHASHDATA(romp)).flag(util::hash_collection::FLAG_NO_DUMP)) + else if (util::hash_collection(romp->hashdata()).flag(util::hash_collection::FLAG_NO_DUMP)) { // no good dumps are okay if (!is_chd_error) @@ -495,8 +576,8 @@ void rom_load_manager::handle_missing_file(const rom_entry *romp, const std::vec void rom_load_manager::dump_wrong_and_correct_checksums(const util::hash_collection &hashes, const util::hash_collection &acthashes) { - m_errorstring.append(string_format(" EXPECTED: %s\n", hashes.macro_string().c_str())); - m_errorstring.append(string_format(" FOUND: %s\n", acthashes.macro_string().c_str())); + m_errorstring.append(string_format(" EXPECTED: %s\n", hashes.macro_string())); + m_errorstring.append(string_format(" FOUND: %s\n", acthashes.macro_string())); } @@ -505,14 +586,14 @@ void rom_load_manager::dump_wrong_and_correct_checksums(const util::hash_collect and hash signatures of a file -------------------------------------------------*/ -void rom_load_manager::verify_length_and_hash(emu_file *file, const char *name, u32 explength, const util::hash_collection &hashes) +void rom_load_manager::verify_length_and_hash(emu_file *file, std::string_view name, u32 explength, const util::hash_collection &hashes) { // we've already complained if there is no file if (!file) return; // verify length - u64 const actlength = file->size(); + u64 const actlength(file->size()); if (explength != actlength) { m_errorstring.append(string_format("%s WRONG LENGTH (expected: %08x found: %08x)\n", name, explength, actlength)); @@ -528,7 +609,7 @@ void rom_load_manager::verify_length_and_hash(emu_file *file, const char *name, else { // verify checksums - util::hash_collection const &acthashes = file->hashes(hashes.hash_types().c_str()); + util::hash_collection const &acthashes(file->hashes(hashes.hash_types())); if (hashes != acthashes) { // otherwise, it's just bad @@ -574,19 +655,19 @@ void rom_load_manager::display_loading_rom_message(const char *name, bool from_l void rom_load_manager::display_rom_load_results(bool from_list) { - /* final status display */ + // final status display display_loading_rom_message(nullptr, from_list); - /* if we had errors, they are fatal */ + // if we had errors, they are fatal if (m_errors != 0) { - /* create the error message and exit fatally */ + // create the error message and exit fatally osd_printf_error("%s", m_errorstring); throw emu_fatalerror(EMU_ERR_MISSING_FILES, "Required files are missing, the machine cannot be run."); } - /* if we had warnings, output them, but continue */ - if ((m_warnings) || (m_knownbad)) + // if we had warnings, output them, but continue + if (m_warnings || m_knownbad) { m_errorstring.append("WARNING: the machine might not run correctly."); osd_printf_warning("%s\n", m_errorstring); @@ -602,27 +683,28 @@ void rom_load_manager::display_rom_load_results(bool from_list) void rom_load_manager::region_post_process(memory_region *region, bool invert) { // do nothing if no region - if (region == nullptr) + if (!region) return; - LOG("+ datawidth=%dbit endian=%s\n", region->bitwidth(), - region->endianness() == ENDIANNESS_LITTLE ? "little" : "big"); + LOG("+ datawidth=%dbit endian=%s\n", + region->bitwidth(), + (region->endianness() == ENDIANNESS_LITTLE) ? "little" : "big"); - /* if the region is inverted, do that now */ + // if the region is inverted, do that now if (invert) { LOG("+ Inverting region\n"); - u8 *base = region->base(); + u8 *base(region->base()); for (int i = 0; i < region->bytes(); i++) *base++ ^= 0xff; } - /* swap the endianness if we need to */ - if (region->bytewidth() > 1 && region->endianness() != ENDIANNESS_NATIVE) + // swap the endianness if we need to + int const datawidth(region->bytewidth()); + if ((datawidth > 1) && (region->endianness() != ENDIANNESS_NATIVE)) { LOG("+ Byte swapping region\n"); - int datawidth = region->bytewidth(); - u8 *base = region->base(); + u8 *base(region->base()); for (int i = 0; i < region->bytes(); i += datawidth) { u8 temp[8]; @@ -639,9 +721,13 @@ void rom_load_manager::region_post_process(memory_region *region, bool invert) up the parent and loading by checksum -------------------------------------------------*/ -std::unique_ptr<emu_file> rom_load_manager::open_rom_file(std::initializer_list<std::reference_wrapper<const std::vector<std::string> > > searchpath, const rom_entry *romp, std::vector<std::string> &tried_file_names, bool from_list) +std::unique_ptr<emu_file> rom_load_manager::open_rom_file( + const std::vector<std::string> &searchpath, + const rom_entry *romp, + std::vector<std::string> &tried_file_names, + bool from_list) { - osd_file::error filerr = osd_file::error::NOT_FOUND; + std::error_condition filerr = std::errc::no_such_file_or_directory; u32 const romsize = rom_file_size(romp); tried_file_names.clear(); @@ -650,31 +736,32 @@ std::unique_ptr<emu_file> rom_load_manager::open_rom_file(std::initializer_list< // extract CRC to use for searching u32 crc = 0; - bool const has_crc = util::hash_collection(ROM_GETHASHDATA(romp)).crc(crc); + bool const has_crc = util::hash_collection(romp->hashdata()).crc(crc); // attempt reading up the chain through the parents // it also automatically attempts any kind of load by checksum supported by the archives. - std::unique_ptr<emu_file> result; - for (const std::vector<std::string> &paths : searchpath) - { - result = open_rom_file(paths, tried_file_names, has_crc, crc, ROM_GETNAME(romp), filerr); - if (result) - break; - } + std::unique_ptr<emu_file> result( + open_rom_file(searchpath, tried_file_names, has_crc, crc, ROM_GETNAME(romp), filerr)); // update counters m_romsloaded++; m_romsloadedsize += romsize; // return the result - if (osd_file::error::NONE != filerr) + if (filerr) return nullptr; else return result; } -std::unique_ptr<emu_file> rom_load_manager::open_rom_file(const std::vector<std::string> &paths, std::vector<std::string> &tried, bool has_crc, u32 crc, const std::string &name, osd_file::error &filerr) +std::unique_ptr<emu_file> rom_load_manager::open_rom_file( + const std::vector<std::string> &paths, + std::vector<std::string> &tried, + bool has_crc, + u32 crc, + std::string_view name, + std::error_condition &filerr) { // record the set names we search tried.insert(tried.end(), paths.begin(), paths.end()); @@ -688,7 +775,7 @@ std::unique_ptr<emu_file> rom_load_manager::open_rom_file(const std::vector<std: filerr = result->open(name); // don't return anything if unsuccessful - if (osd_file::error::NONE != filerr) + if (filerr) return nullptr; else return result; @@ -717,50 +804,52 @@ int rom_load_manager::rom_fread(emu_file *file, u8 *buffer, int length, const ro entry -------------------------------------------------*/ -int rom_load_manager::read_rom_data(emu_file *file, const rom_entry *parent_region, const rom_entry *romp) +int rom_load_manager::read_rom_data( + emu_file *file, + memory_region ®ion, + const rom_entry *parent_region, + const rom_entry *romp) { - int datashift = ROM_GETBITSHIFT(romp); - int datamask = ((1 << ROM_GETBITWIDTH(romp)) - 1) << datashift; - int numbytes = ROM_GETLENGTH(romp); - int groupsize = ROM_GETGROUPSIZE(romp); - int skip = ROM_GETSKIPCOUNT(romp); - int reversed = ROM_ISREVERSED(romp); - int numgroups = (numbytes + groupsize - 1) / groupsize; - u8 *base = m_region->base() + ROM_GETOFFSET(romp); - u32 tempbufsize; - int i; + int const datashift(ROM_GETBITSHIFT(romp)); + int const datamask(((1 << ROM_GETBITWIDTH(romp)) - 1) << datashift); + int numbytes(ROM_GETLENGTH(romp)); + int const groupsize(ROM_GETGROUPSIZE(romp)); + int skip(ROM_GETSKIPCOUNT(romp)); + int const reversed(ROM_ISREVERSED(romp)); + int const numgroups((numbytes + groupsize - 1) / groupsize); + u8 *base = region.base() + ROM_GETOFFSET(romp); LOG("Loading ROM data: offs=%X len=%X mask=%02X group=%d skip=%d reverse=%d\n", ROM_GETOFFSET(romp), numbytes, datamask, groupsize, skip, reversed); - /* make sure the length was an even multiple of the group size */ - if (numbytes % groupsize != 0) - osd_printf_warning("Warning in RomModule definition: %s length not an even multiple of group size\n", ROM_GETNAME(romp)); + // make sure the length was a whole multiple of the group size + if ((numbytes % groupsize) != 0) + osd_printf_warning("Warning in RomModule definition: %s length not an even multiple of group size\n", romp->name()); - /* make sure we only fill within the region space */ - if (ROM_GETOFFSET(romp) + numgroups * groupsize + (numgroups - 1) * skip > m_region->bytes()) - throw emu_fatalerror("Error in RomModule definition: %s out of memory region space\n", ROM_GETNAME(romp)); + // make sure we only fill within the region space + if (ROM_GETOFFSET(romp) + numgroups * groupsize + (numgroups - 1) * skip > region.bytes()) + throw emu_fatalerror("Error in RomModule definition: %s out of memory region space\n", romp->name()); - /* make sure the length was valid */ + // make sure the length was valid if (numbytes == 0) - throw emu_fatalerror("Error in RomModule definition: %s has an invalid length\n", ROM_GETNAME(romp)); + throw emu_fatalerror("Error in RomModule definition: %s has an invalid length\n", romp->name()); - /* special case for simple loads */ - if (datamask == 0xff && (groupsize == 1 || !reversed) && skip == 0) + // special case for simple loads + if ((datamask == 0xff) && ((groupsize == 1) || !reversed) && (skip == 0)) return rom_fread(file, base, numbytes, parent_region); - /* use a temporary buffer for complex loads */ - tempbufsize = std::min(TEMPBUFFER_MAX_SIZE, numbytes); - std::vector<u8> tempbuf(tempbufsize); + // use a temporary buffer for complex loads + u32 const tempbufsize(std::min(TEMPBUFFER_MAX_SIZE, numbytes)); + std::unique_ptr<u8 []> const tempbuf(new u8 [tempbufsize]); - /* chunky reads for complex loads */ + // chunky reads for complex loads skip += groupsize; while (numbytes > 0) { - int evengroupcount = (tempbufsize / groupsize) * groupsize; - int bytesleft = (numbytes > evengroupcount) ? evengroupcount : numbytes; - u8 *bufptr = &tempbuf[0]; + int evengroupcount((tempbufsize / groupsize) * groupsize); + int bytesleft((numbytes > evengroupcount) ? evengroupcount : numbytes); + u8 *bufptr(tempbuf.get()); - /* read as much as we can */ + // read as much as we can LOG(" Reading %X bytes into buffer\n", bytesleft); if (rom_fread(file, bufptr, bytesleft, parent_region) != bytesleft) return 0; @@ -768,58 +857,65 @@ int rom_load_manager::read_rom_data(emu_file *file, const rom_entry *parent_regi LOG(" Copying to %p\n", base); - /* unmasked cases */ if (datamask == 0xff) { - /* non-grouped data */ + // unmasked cases if (groupsize == 1) - for (i = 0; i < bytesleft; i++, base += skip) + { + // non-grouped data + for (int i = 0; i < bytesleft; i++, base += skip) *base = *bufptr++; - - /* grouped data -- non-reversed case */ + } else if (!reversed) + { + // grouped data -- non-reversed case while (bytesleft) { - for (i = 0; i < groupsize && bytesleft; i++, bytesleft--) + for (int i = 0; i < groupsize && bytesleft; i++, bytesleft--) base[i] = *bufptr++; base += skip; } - - /* grouped data -- reversed case */ + } else + { + // grouped data -- reversed case while (bytesleft) { - for (i = groupsize - 1; i >= 0 && bytesleft; i--, bytesleft--) + for (int i = groupsize - 1; i >= 0 && bytesleft; i--, bytesleft--) base[i] = *bufptr++; base += skip; } + } } - - /* masked cases */ else { - /* non-grouped data */ + // masked cases if (groupsize == 1) - for (i = 0; i < bytesleft; i++, base += skip) + { + // non-grouped data + for (int i = 0; i < bytesleft; i++, base += skip) *base = (*base & ~datamask) | ((*bufptr++ << datashift) & datamask); - - /* grouped data -- non-reversed case */ + } else if (!reversed) + { + // grouped data -- non-reversed case while (bytesleft) { - for (i = 0; i < groupsize && bytesleft; i++, bytesleft--) + for (int i = 0; i < groupsize && bytesleft; i++, bytesleft--) base[i] = (base[i] & ~datamask) | ((*bufptr++ << datashift) & datamask); base += skip; } - - /* grouped data -- reversed case */ + } else + { + // grouped data -- reversed case while (bytesleft) { - for (i = groupsize - 1; i >= 0 && bytesleft; i--, bytesleft--) + for (int i = groupsize - 1; i >= 0 && bytesleft; i--, bytesleft--) base[i] = (base[i] & ~datamask) | ((*bufptr++ << datashift) & datamask); base += skip; } + } } } @@ -832,14 +928,14 @@ int rom_load_manager::read_rom_data(emu_file *file, const rom_entry *parent_regi fill_rom_data - fill a region of ROM space -------------------------------------------------*/ -void rom_load_manager::fill_rom_data(const rom_entry *romp) +void rom_load_manager::fill_rom_data(memory_region ®ion, const rom_entry *romp) { u32 numbytes = ROM_GETLENGTH(romp); int skip = ROM_GETSKIPCOUNT(romp); - u8 *base = m_region->base() + ROM_GETOFFSET(romp); + u8 *base = region.base() + ROM_GETOFFSET(romp); // make sure we fill within the region space - if (ROM_GETOFFSET(romp) + numbytes > m_region->bytes()) + if (ROM_GETOFFSET(romp) + numbytes > region.bytes()) throw emu_fatalerror("Error in RomModule definition: FILL out of memory region space\n"); // make sure the length was valid @@ -847,7 +943,7 @@ void rom_load_manager::fill_rom_data(const rom_entry *romp) throw emu_fatalerror("Error in RomModule definition: FILL has an invalid length\n"); // for fill bytes, the byte that gets filled is the first byte of the hashdata string - u8 fill_byte = u8(strtol(ROM_GETHASHDATA(romp), nullptr, 0)); + u8 fill_byte = u8(strtol(romp->hashdata().c_str(), nullptr, 0)); // fill the data (filling value is stored in place of the hashdata) if(skip != 0) @@ -864,15 +960,15 @@ void rom_load_manager::fill_rom_data(const rom_entry *romp) copy_rom_data - copy a region of ROM space -------------------------------------------------*/ -void rom_load_manager::copy_rom_data(const rom_entry *romp) +void rom_load_manager::copy_rom_data(memory_region ®ion, const rom_entry *romp) { - u8 *base = m_region->base() + ROM_GETOFFSET(romp); - const char *srcrgntag = ROM_GETNAME(romp); + u8 *base = region.base() + ROM_GETOFFSET(romp); + const std::string &srcrgntag = romp->name(); u32 numbytes = ROM_GETLENGTH(romp); - u32 srcoffs = u32(strtol(ROM_GETHASHDATA(romp), nullptr, 0)); /* srcoffset in place of hashdata */ + u32 srcoffs = u32(strtol(romp->hashdata().c_str(), nullptr, 0)); /* srcoffset in place of hashdata */ /* make sure we copy within the region space */ - if (ROM_GETOFFSET(romp) + numbytes > m_region->bytes()) + if (ROM_GETOFFSET(romp) + numbytes > region.bytes()) throw emu_fatalerror("Error in RomModule definition: COPY out of target memory region space\n"); /* make sure the length was valid */ @@ -880,16 +976,16 @@ void rom_load_manager::copy_rom_data(const rom_entry *romp) throw emu_fatalerror("Error in RomModule definition: COPY has an invalid length\n"); /* make sure the source was valid */ - memory_region *region = machine().root_device().memregion(srcrgntag); - if (region == nullptr) + memory_region *src = machine().root_device().memregion(srcrgntag); + if (!src) throw emu_fatalerror("Error in RomModule definition: COPY from an invalid region\n"); /* make sure we find within the region space */ - if (srcoffs + numbytes > region->bytes()) + if (srcoffs + numbytes > src->bytes()) throw emu_fatalerror("Error in RomModule definition: COPY out of source memory region space\n"); /* fill the data */ - memcpy(base, region->base() + srcoffs, numbytes); + memcpy(base, src->base() + srcoffs, numbytes); } @@ -898,7 +994,13 @@ void rom_load_manager::copy_rom_data(const rom_entry *romp) for a region -------------------------------------------------*/ -void rom_load_manager::process_rom_entries(std::initializer_list<std::reference_wrapper<const std::vector<std::string> > > searchpath, u8 bios, const rom_entry *parent_region, const rom_entry *romp, bool from_list) +void rom_load_manager::process_rom_entries( + const std::vector<std::string> &searchpath, + u8 bios, + memory_region ®ion, + const rom_entry *parent_region, + const rom_entry *romp, + bool from_list) { u32 lastflags = 0; std::vector<std::string> tried_file_names; @@ -920,13 +1022,13 @@ void rom_load_manager::process_rom_entries(std::initializer_list<std::reference_ if (ROMENTRY_ISFILL(romp)) { if (!ROM_GETBIOSFLAGS(romp) || (ROM_GETBIOSFLAGS(romp) == bios)) - fill_rom_data(romp); + fill_rom_data(region, romp); romp++; } else if (ROMENTRY_ISCOPY(romp)) { - copy_rom_data(romp++); + copy_rom_data(region, romp++); } else if (ROMENTRY_ISFILE(romp)) { @@ -942,7 +1044,7 @@ void rom_load_manager::process_rom_entries(std::initializer_list<std::reference_ { file = open_rom_file(searchpath, romp, tried_file_names, from_list); if (!file) - handle_missing_file(romp, tried_file_names, CHDERR_NONE); + handle_missing_file(romp, tried_file_names, std::error_condition()); } // loop until we run out of reloads @@ -964,7 +1066,7 @@ void rom_load_manager::process_rom_entries(std::initializer_list<std::reference_ // attempt to read using the modified entry if (!ROMENTRY_ISIGNORE(&modified_romp) && !irrelevantbios) - /*readresult = */read_rom_data(file.get(), parent_region, &modified_romp); + /*readresult = */read_rom_data(file.get(), region, parent_region, &modified_romp); } while (ROMENTRY_ISCONTINUE(romp) || ROMENTRY_ISIGNORE(romp)); @@ -972,7 +1074,7 @@ void rom_load_manager::process_rom_entries(std::initializer_list<std::reference_ if (baserom) { LOG("Verifying length (%X) and checksums\n", explength); - verify_length_and_hash(file.get(), ROM_GETNAME(baserom), explength, util::hash_collection(ROM_GETHASHDATA(baserom))); + verify_length_and_hash(file.get(), baserom->name(), explength, util::hash_collection(baserom->hashdata())); LOG("Verify finished\n"); } @@ -1003,44 +1105,48 @@ void rom_load_manager::process_rom_entries(std::initializer_list<std::reference_ open_disk_diff - open a DISK diff file -------------------------------------------------*/ -chd_error rom_load_manager::open_disk_diff(emu_options &options, const rom_entry *romp, chd_file &source, chd_file &diff_chd) +std::error_condition rom_load_manager::open_disk_diff( + emu_options &options, + const rom_entry *romp, + chd_file &source, + chd_file &diff_chd) { // TODO: use system name and/or software list name in the path - the current setup doesn't scale - std::string fname = std::string(ROM_GETNAME(romp)).append(".dif"); + std::string fname = romp->name() + ".dif"; - /* try to open the diff */ + // try to open the diff LOG("Opening differencing image file: %s\n", fname.c_str()); emu_file diff_file(options.diff_directory(), OPEN_FLAG_READ | OPEN_FLAG_WRITE); - osd_file::error filerr = diff_file.open(fname); - if (filerr == osd_file::error::NONE) + std::error_condition filerr = diff_file.open(fname); + if (!filerr) { std::string fullpath(diff_file.fullpath()); diff_file.close(); LOG("Opening differencing image file: %s\n", fullpath.c_str()); - return diff_chd.open(fullpath.c_str(), true, &source); + return diff_chd.open(fullpath, true, &source); } - /* didn't work; try creating it instead */ + // didn't work; try creating it instead LOG("Creating differencing image: %s\n", fname.c_str()); diff_file.set_openflags(OPEN_FLAG_READ | OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS); filerr = diff_file.open(fname); - if (filerr == osd_file::error::NONE) + if (!filerr) { std::string fullpath(diff_file.fullpath()); diff_file.close(); - /* create the CHD */ + // create the CHD LOG("Creating differencing image file: %s\n", fullpath.c_str()); chd_codec_type compression[4] = { CHD_CODEC_NONE }; - chd_error err = diff_chd.create(fullpath.c_str(), source.logical_bytes(), source.hunk_bytes(), compression, source); - if (err != CHDERR_NONE) + std::error_condition err = diff_chd.create(fullpath, source.logical_bytes(), source.hunk_bytes(), compression, source); + if (err) return err; return diff_chd.clone_all_metadata(source); } - return CHDERR_FILE_NOT_FOUND; + return std::errc::no_such_file_or_directory; } @@ -1049,41 +1155,55 @@ chd_error rom_load_manager::open_disk_diff(emu_options &options, const rom_entry for a region -------------------------------------------------*/ -void rom_load_manager::process_disk_entries(std::initializer_list<std::reference_wrapper<const std::vector<std::string> > > searchpath, const char *regiontag, const rom_entry *romp, std::function<const rom_entry * ()> next_parent) +void rom_load_manager::process_disk_entries( + search_paths searchpath, + std::string_view regiontag, + rom_entry const *romp, + std::function<rom_entry const * ()> next_parent, + chd_file::open_parent_func const &open_parent) { - /* remove existing disk entries for this region */ - m_chd_list.erase(std::remove_if(m_chd_list.begin(), m_chd_list.end(), - [regiontag] (std::unique_ptr<open_chd> &chd) { return !strcmp(chd->region(), regiontag); }), m_chd_list.end()); + // remove existing disk entries for this region + m_chd_list.erase( + std::remove_if( + m_chd_list.begin(), + m_chd_list.end(), + [®iontag] (std::unique_ptr<open_chd> &chd) { return chd->region() == regiontag; }), + m_chd_list.end()); - /* loop until we hit the end of this region */ + // loop until we hit the end of this region for ( ; !ROMENTRY_ISREGIONEND(romp); romp++) { - /* handle files */ + // handle files if (ROMENTRY_ISFILE(romp)) { - auto chd = std::make_unique<open_chd>(regiontag); - chd_error err; + auto chd(std::make_unique<open_chd>(regiontag)); + std::error_condition err; - /* make the filename of the source */ - const std::string filename = std::string(ROM_GETNAME(romp)).append(".chd"); + // make the filename of the source + std::string const filename(romp->name() + ".chd"); - /* first open the source drive */ - // FIXME: we've lost the ability to search parents here + // first open the reference disk image LOG("Opening disk image: %s\n", filename.c_str()); - err = do_open_disk(machine().options(), searchpath, romp, chd->orig_chd(), next_parent); - if (err != CHDERR_NONE) + err = do_open_disk(machine().options(), searchpath, romp, chd->orig_chd(), next_parent, open_parent); + if (!err && chd->orig_chd().parent_missing()) + err = chd_file::error::REQUIRES_PARENT; + if (err) { - handle_missing_file(romp, std::vector<std::string>(), err); - chd = nullptr; + std::vector<std::string> tried; + for (auto const &paths : searchpath) + { + for (std::string const &path : paths.get()) + tried.emplace_back(path); + } + handle_missing_file(romp, tried, err); + chd.reset(); continue; } - /* get the header and extract the SHA1 */ + // get the header and verify the SHA1 digest util::hash_collection acthashes; acthashes.add_sha1(chd->orig_chd().sha1()); - - /* verify the hash */ - const util::hash_collection hashes(ROM_GETHASHDATA(romp)); + util::hash_collection const hashes(romp->hashdata()); if (hashes != acthashes) { m_errorstring.append(string_format("%s WRONG CHECKSUMS:\n", filename)); @@ -1096,23 +1216,22 @@ void rom_load_manager::process_disk_entries(std::initializer_list<std::reference m_knownbad++; } - /* if not read-only, make the diff file */ + // if not read-only, open or create the diff file if (!DISK_ISREADONLY(romp)) { - /* try to open or create the diff */ err = open_disk_diff(machine().options(), romp, chd->orig_chd(), chd->diff_chd()); - if (err != CHDERR_NONE) + if (err) { - m_errorstring.append(string_format("%s DIFF CHD ERROR: %s\n", filename, chd_file::error_string(err))); + m_errorstring.append(string_format("%s DIFF CHD ERROR: %s\n", filename, err.message())); m_errors++; - chd = nullptr; + chd.reset(); continue; } } - /* we're okay, add to the list of disks */ + // we're okay, add to the list of disks LOG("Assigning to handle %d\n", DISK_GETINDEX(romp)); - m_chd_list.push_back(std::move(chd)); + m_chd_list.emplace_back(std::move(chd)); } } } @@ -1135,7 +1254,11 @@ std::vector<std::string> rom_load_manager::get_software_searchpath(software_list device -------------------------------------------------*/ -chd_error rom_load_manager::open_disk_image(const emu_options &options, const device_t &device, const rom_entry *romp, chd_file &image_chd) +std::error_condition rom_load_manager::open_disk_image( + emu_options &options, + const device_t &device, + const rom_entry *romp, + chd_file &image_chd) { const std::vector<std::string> searchpath(device.searchpath()); @@ -1144,8 +1267,14 @@ chd_error rom_load_manager::open_disk_image(const emu_options &options, const de if (driver) next_parent = next_parent_system(driver->system()); else - next_parent = [] () { return nullptr; }; - return do_open_disk(options, { searchpath }, romp, image_chd, std::move(next_parent)); + next_parent = next_parent_device(device, options); + chd_file::open_parent_func open_parent(open_parent_disk(options, { searchpath }, next_parent)); + std::error_condition const err( + do_open_disk(options, { searchpath }, romp, image_chd, std::move(next_parent), open_parent)); + if (!err && image_chd.parent_missing()) + return chd_file::error::REQUIRES_PARENT; + else + return err; } @@ -1154,12 +1283,24 @@ chd_error rom_load_manager::open_disk_image(const emu_options &options, const de software item -------------------------------------------------*/ -chd_error rom_load_manager::open_disk_image(const emu_options &options, software_list_device &swlist, const software_info &swinfo, const rom_entry *romp, chd_file &image_chd) +std::error_condition rom_load_manager::open_disk_image( + emu_options &options, + software_list_device &swlist, + const software_info &swinfo, + const rom_entry *romp, + chd_file &image_chd) { std::vector<software_info const *> parents; - std::vector<std::string> searchpath = make_software_searchpath(swlist, swinfo, parents); + std::vector<std::string> searchpath(make_software_searchpath(swlist, swinfo, parents)); searchpath.emplace_back(swlist.list_name()); // look for loose disk images in software list directory - return do_open_disk(options, { searchpath }, romp, image_chd, next_parent_software(parents)); + std::function<const rom_entry * ()> next_parent(next_parent_software(parents)); + chd_file::open_parent_func open_parent(open_parent_disk(options, { searchpath }, next_parent)); + std::error_condition const err( + do_open_disk(options, { searchpath }, romp, image_chd, std::move(next_parent), open_parent)); + if (!err && image_chd.parent_missing()) + return chd_file::error::REQUIRES_PARENT; + else + return err; } @@ -1168,7 +1309,7 @@ chd_error rom_load_manager::open_disk_image(const emu_options &options, software flags for the given device -------------------------------------------------*/ -void rom_load_manager::normalize_flags_for_device(const char *rgntag, u8 &width, endianness_t &endian) +void rom_load_manager::normalize_flags_for_device(std::string_view rgntag, u8 &width, endianness_t &endian) { device_t *device = machine().root_device().subdevice(rgntag); device_memory_interface *memory; @@ -1203,13 +1344,13 @@ void rom_load_manager::normalize_flags_for_device(const char *rgntag, u8 &width, /*------------------------------------------------- load_software_part_region - load a software part - This is used by MESS when loading a piece of + This is used by MAME when loading a piece of software. The code should be merged with process_region_list or updated to use a slight more general process_region_list. -------------------------------------------------*/ -void rom_load_manager::load_software_part_region(device_t &device, software_list_device &swlist, const char *swname, const rom_entry *start_region) +void rom_load_manager::load_software_part_region(device_t &device, software_list_device &swlist, std::string_view swname, const rom_entry *start_region) { m_errorstring.clear(); m_softwarningstring.clear(); @@ -1219,19 +1360,18 @@ void rom_load_manager::load_software_part_region(device_t &device, software_list m_romsloadedsize = 0; std::vector<const software_info *> parents; - std::vector<std::string> swsearch, disksearch, devsearch; - const software_info *const swinfo = swlist.find(swname); + std::vector<std::string> swsearch, disksearch; + const software_info *const swinfo = swlist.find(std::string(swname)); if (swinfo) { - // dispay a warning for unsupported software + // display a warning for unsupported software // TODO: list supported clones like we do for machines? - const u32 supported(swinfo->supported()); - if (supported == SOFTWARE_SUPPORTED_PARTIAL) + if (swinfo->supported() == software_support::PARTIALLY_SUPPORTED) { m_errorstring.append(string_format("WARNING: support for software %s (in list %s) is only partial\n", swname, swlist.list_name())); m_softwarningstring.append(string_format("Support for software %s (in list %s) is only partial\n", swname, swlist.list_name())); } - if (supported == SOFTWARE_SUPPORTED_NO) + else if (swinfo->supported() == software_support::UNSUPPORTED) { m_errorstring.append(string_format("WARNING: support for software %s (in list %s) is only preliminary\n", swname, swlist.list_name())); m_softwarningstring.append(string_format("Support for software %s (in list %s) is only preliminary\n", swname, swlist.list_name())); @@ -1249,18 +1389,14 @@ void rom_load_manager::load_software_part_region(device_t &device, software_list // this is convenient for CD-only lists so you don't need an extra level of directories containing one file each disksearch.emplace_back(swlist.list_name()); - // for historical reasons, add the search path for the software list device's owner - const device_t *const listowner = swlist.owner(); - if (listowner) - devsearch = listowner->searchpath(); - // loop until we hit the end std::function<const rom_entry * ()> next_parent; + chd_file::open_parent_func open_parent; for (const rom_entry *region = start_region; region != nullptr; region = rom_next_region(region)) { u32 regionlength = ROMREGION_GETLENGTH(region); - std::string regiontag = device.subtag(ROMREGION_GETTAG(region)); + std::string regiontag = device.subtag(region->name()); LOG("Processing region \"%s\" (length=%X)\n", regiontag.c_str(), regionlength); // the first entry must be a region @@ -1270,25 +1406,25 @@ void rom_load_manager::load_software_part_region(device_t &device, software_list endianness_t endianness = ROMREGION_ISBIGENDIAN(region) ? ENDIANNESS_BIG : ENDIANNESS_LITTLE; u8 width = ROMREGION_GETWIDTH(region) / 8; memory_region *memregion = machine().root_device().memregion(regiontag); - if (memregion != nullptr) + if (memregion) { - normalize_flags_for_device(regiontag.c_str(), width, endianness); + normalize_flags_for_device(regiontag, width, endianness); // clear old region (TODO: should be moved to an image unload function) machine().memory().region_free(memregion->name()); } // remember the base and length - m_region = machine().memory().region_alloc(regiontag.c_str(), regionlength, width, endianness); - LOG("Allocated %X bytes @ %p\n", m_region->bytes(), m_region->base()); + memregion = machine().memory().region_alloc(regiontag, regionlength, width, endianness); + LOG("Allocated %X bytes @ %p\n", memregion->bytes(), memregion->base()); if (ROMREGION_ISERASE(region)) // clear the region if it's requested - memset(m_region->base(), ROMREGION_GETERASEVAL(region), m_region->bytes()); - else if (m_region->bytes() <= 0x400000) // or if it's sufficiently small (<= 4MB) - memset(m_region->base(), 0, m_region->bytes()); + memset(memregion->base(), ROMREGION_GETERASEVAL(region), memregion->bytes()); + else if (memregion->bytes() <= 0x400000) // or if it's sufficiently small (<= 4MB) + memset(memregion->base(), 0, memregion->bytes()); #ifdef MAME_DEBUG else // if we're debugging, fill region with random data to catch errors - fill_random(m_region->base(), m_region->bytes()); + fill_random(memregion->base(), memregion->bytes()); #endif // update total number of roms @@ -1301,10 +1437,7 @@ void rom_load_manager::load_software_part_region(device_t &device, software_list // now process the entries in the region if (ROMREGION_ISROMDATA(region)) { - if (devsearch.empty()) - process_rom_entries({ swsearch }, 0U, region, region + 1, true); - else - process_rom_entries({ swsearch, devsearch }, 0U, region, region + 1, true); + process_rom_entries(swsearch, 0U, *memregion, region, region + 1, true); } else if (ROMREGION_ISDISKDATA(region)) { @@ -1314,17 +1447,15 @@ void rom_load_manager::load_software_part_region(device_t &device, software_list next_parent = next_parent_software(parents); else next_parent = [] () { return nullptr; }; + open_parent = open_parent_disk(machine().options(), { swsearch, disksearch }, next_parent); } - if (devsearch.empty()) - process_disk_entries({ swsearch, disksearch }, regiontag.c_str(), region + 1, next_parent); - else - process_disk_entries({ swsearch, disksearch, devsearch }, regiontag.c_str(), region + 1, next_parent); + process_disk_entries({ swsearch, disksearch }, regiontag, region + 1, next_parent, open_parent); } } // now go back and post-process all the regions for (const rom_entry *region = start_region; region != nullptr; region = rom_next_region(region)) - region_post_process(device.memregion(ROMREGION_GETTAG(region)), ROMREGION_ISINVERTED(region)); + region_post_process(device.memregion(region->name()), ROMREGION_ISINVERTED(region)); // display the results and exit display_rom_load_results(true); @@ -1338,17 +1469,18 @@ void rom_load_manager::load_software_part_region(device_t &device, software_list void rom_load_manager::process_region_list() { // loop until we hit the end - device_iterator deviter(machine().root_device()); + device_enumerator deviter(machine().root_device()); std::vector<std::string> searchpath; for (device_t &device : deviter) { searchpath.clear(); std::function<const rom_entry * ()> next_parent; + chd_file::open_parent_func open_parent; for (const rom_entry *region = rom_first_region(device); region != nullptr; region = rom_next_region(region)) { u32 regionlength = ROMREGION_GETLENGTH(region); - std::string regiontag = device.subtag(ROM_GETNAME(region)); + std::string regiontag = device.subtag(region->name()); LOG("Processing region \"%s\" (length=%X)\n", regiontag.c_str(), regionlength); // the first entry must be a region @@ -1359,26 +1491,26 @@ void rom_load_manager::process_region_list() // if this is a device region, override with the device width and endianness u8 width = ROMREGION_GETWIDTH(region) / 8; endianness_t endianness = ROMREGION_ISBIGENDIAN(region) ? ENDIANNESS_BIG : ENDIANNESS_LITTLE; - normalize_flags_for_device(regiontag.c_str(), width, endianness); + normalize_flags_for_device(regiontag, width, endianness); // remember the base and length - m_region = machine().memory().region_alloc(regiontag.c_str(), regionlength, width, endianness); - LOG("Allocated %X bytes @ %p\n", m_region->bytes(), m_region->base()); + memory_region *const memregion = machine().memory().region_alloc(regiontag, regionlength, width, endianness); + LOG("Allocated %X bytes @ %p\n", memregion->bytes(), memregion->base()); if (ROMREGION_ISERASE(region)) // clear the region if it's requested - memset(m_region->base(), ROMREGION_GETERASEVAL(region), m_region->bytes()); - else if (m_region->bytes() <= 0x400000) // or if it's sufficiently small (<= 4MB) - memset(m_region->base(), 0, m_region->bytes()); + memset(memregion->base(), ROMREGION_GETERASEVAL(region), memregion->bytes()); + else if (memregion->bytes() <= 0x400000) // or if it's sufficiently small (<= 4MB) + memset(memregion->base(), 0, memregion->bytes()); #ifdef MAME_DEBUG else // if we're debugging, fill region with random data to catch errors - fill_random(m_region->base(), m_region->bytes()); + fill_random(memregion->base(), memregion->bytes()); #endif // now process the entries in the region if (searchpath.empty()) searchpath = device.searchpath(); assert(!searchpath.empty()); - process_rom_entries({ searchpath }, device.system_bios(), region, region + 1, false); + process_rom_entries(searchpath, device.system_bios(), *memregion, region, region + 1, false); } else if (ROMREGION_ISDISKDATA(region)) { @@ -1391,9 +1523,10 @@ void rom_load_manager::process_region_list() if (driver) next_parent = next_parent_system(driver->system()); else - next_parent = [] () { return nullptr; }; + next_parent = next_parent_device(device, machine().options()); + open_parent = open_parent_disk(machine().options(), { searchpath }, next_parent); } - process_disk_entries({ searchpath }, regiontag.c_str(), region + 1, next_parent); + process_disk_entries({ searchpath }, regiontag, region + 1, next_parent, open_parent); } } } @@ -1401,7 +1534,7 @@ void rom_load_manager::process_region_list() // now go back and post-process all the regions for (device_t &device : deviter) for (const rom_entry *region = rom_first_region(device); region != nullptr; region = rom_next_region(region)) - region_post_process(device.memregion(ROM_GETNAME(region)), ROMREGION_ISINVERTED(region)); + region_post_process(device.memregion(region->name()), ROMREGION_ISINVERTED(region)); // and finally register all per-game parameters for (device_t &device : deviter) @@ -1430,13 +1563,12 @@ rom_load_manager::rom_load_manager(running_machine &machine) , m_romsloadedsize(0) , m_romstotalsize(0) , m_chd_list() - , m_region(nullptr) , m_errorstring() , m_softwarningstring() { // figure out which BIOS we are using - std::map<std::string, std::string> card_bios; - for (device_t &device : device_iterator(machine.config().root_device())) + std::map<std::string_view, std::string> card_bios; + for (device_t &device : device_enumerator(machine.config().root_device())) { device_slot_interface const *const slot(dynamic_cast<device_slot_interface *>(&device)); if (slot) @@ -1444,7 +1576,7 @@ rom_load_manager::rom_load_manager(running_machine &machine) device_t const *const card(slot->get_card_device()); slot_option const &slot_opt(machine.options().slot_option(slot->slot_name())); if (card && !slot_opt.bios().empty()) - card_bios.emplace(std::make_pair(std::string(card->tag()), slot_opt.bios())); + card_bios.emplace(card->tag(), slot_opt.bios()); } if (device.rom_region()) @@ -1463,7 +1595,7 @@ rom_load_manager::rom_load_manager(running_machine &machine) card_bios.erase(found); } } - determine_bios_rom(device, specbios.c_str()); + determine_bios_rom(device, specbios); } } |