From 9c600695f0ed4456270bf5f1676b8fadaed34127 Mon Sep 17 00:00:00 2001 From: Vas Crabb Date: Tue, 10 Mar 2020 18:21:10 +1100 Subject: (nw) Cleanup on the way: * Add doxygen comments for bit manipulation functions * Add an overload of BIT that works like the AArch64 UBFX instruction * Kill off some of the silly concatenating overloads for emu_file::open * Make searchpath acually useful for devices This is a checkpoint - I'm planning to improve ROM loading behaviour at least a little. --- src/devices/sound/samples.cpp | 10 +- src/emu/config.cpp | 14 +- src/emu/debug/debugcpu.cpp | 4 +- src/emu/device.cpp | 19 ++- src/emu/device.h | 3 +- src/emu/driver.cpp | 55 ++++---- src/emu/driver.h | 8 +- src/emu/drivers/empty.cpp | 2 + src/emu/emucore.h | 1 + src/emu/fileio.cpp | 18 --- src/emu/fileio.h | 3 - src/emu/hashfile.cpp | 12 +- src/emu/machine.h | 2 +- src/emu/mconfig.cpp | 3 - src/emu/render.cpp | 12 +- src/emu/romload.cpp | 268 ++++++++++++++++++++----------------- src/emu/romload.h | 13 +- src/emu/screen.cpp | 9 +- src/emu/softlist_dev.cpp | 2 +- src/emu/video.cpp | 2 +- src/frontend/mame/audit.cpp | 27 ++-- src/frontend/mame/audit.h | 6 +- src/frontend/mame/cheat.cpp | 26 ++-- src/frontend/mame/cheat.h | 16 +-- src/frontend/mame/clifront.cpp | 2 +- src/frontend/mame/language.cpp | 2 +- src/frontend/mame/mameopts.cpp | 2 +- src/frontend/mame/ui/auditmenu.cpp | 2 +- src/frontend/mame/ui/miscmenu.cpp | 26 ++-- src/frontend/mame/ui/optsmenu.cpp | 2 +- src/frontend/mame/ui/selgame.cpp | 10 +- src/frontend/mame/ui/selsoft.cpp | 8 +- src/frontend/mame/ui/ui.cpp | 4 +- src/lib/util/coretmpl.h | 106 +++++++++++++-- src/mame/drivers/chihiro.cpp | 2 +- src/mame/drivers/esq1.cpp | 2 +- src/mame/video/dooyong.cpp | 22 +-- 37 files changed, 407 insertions(+), 318 deletions(-) diff --git a/src/devices/sound/samples.cpp b/src/devices/sound/samples.cpp index f03ee6fe275..82ce481e72e 100644 --- a/src/devices/sound/samples.cpp +++ b/src/devices/sound/samples.cpp @@ -605,7 +605,7 @@ bool samples_device::load_samples() return false; // iterate over ourself - const char *basename = machine().basename(); + const std::string &basename = machine().basename(); samples_iterator iter(*this); const char *altbasename = iter.altbasename(); @@ -618,15 +618,15 @@ bool samples_device::load_samples() { // attempt to open as FLAC first emu_file file(machine().options().sample_path(), OPEN_FLAG_READ); - osd_file::error filerr = file.open(basename, PATH_SEPARATOR, samplename, ".flac"); + osd_file::error filerr = file.open(util::string_format("%s" PATH_SEPARATOR "%s.flac", basename, samplename)); if (filerr != osd_file::error::NONE && altbasename != nullptr) - filerr = file.open(altbasename, PATH_SEPARATOR, samplename, ".flac"); + filerr = file.open(util::string_format("%s" PATH_SEPARATOR "%s.flac", altbasename, samplename)); // if not, try as WAV if (filerr != osd_file::error::NONE) - filerr = file.open(basename, PATH_SEPARATOR, samplename, ".wav"); + filerr = file.open(util::string_format("%s" PATH_SEPARATOR "%s.wav", basename, samplename)); if (filerr != osd_file::error::NONE && altbasename != nullptr) - filerr = file.open(altbasename, PATH_SEPARATOR, samplename, ".wav"); + filerr = file.open(util::string_format("%s" PATH_SEPARATOR "%s.wav", altbasename, samplename)); // if opened, read it if (filerr == osd_file::error::NONE) diff --git a/src/emu/config.cpp b/src/emu/config.cpp index 81a486f73af..19c88f8765d 100644 --- a/src/emu/config.cpp +++ b/src/emu/config.cpp @@ -2,15 +2,17 @@ // copyright-holders:Nicola Salmoria, Aaron Giles /*************************************************************************** - config.c + config.cpp Configuration file I/O. ***************************************************************************/ #include "emu.h" -#include "emuopts.h" -#include "drivenum.h" #include "config.h" + +#include "drivenum.h" +#include "emuopts.h" + #include "xmlfile.h" #define DEBUG_CONFIG 0 @@ -69,7 +71,7 @@ int configuration_manager::load_settings() /* open the config file */ emu_file file(machine().options().ctrlr_path(), OPEN_FLAG_READ); osd_printf_verbose("Attempting to parse: %s.cfg\n",controller); - osd_file::error filerr = file.open(controller, ".cfg"); + osd_file::error filerr = file.open(std::string(controller) + ".cfg"); if (filerr != osd_file::error::NONE) throw emu_fatalerror("Could not load controller file %s.cfg", controller); @@ -87,7 +89,7 @@ int configuration_manager::load_settings() load_xml(file, config_type::DEFAULT); /* finally, load the game-specific file */ - filerr = file.open(machine().basename(), ".cfg"); + filerr = file.open(machine().basename() + ".cfg"); osd_printf_verbose("Attempting to parse: %s.cfg\n",machine().basename()); if (filerr == osd_file::error::NONE) loaded = load_xml(file, config_type::GAME); @@ -115,7 +117,7 @@ void configuration_manager::save_settings() save_xml(file, config_type::DEFAULT); /* finally, save the game-specific file */ - filerr = file.open(machine().basename(), ".cfg"); + filerr = file.open(machine().basename() + ".cfg"); if (filerr == osd_file::error::NONE) save_xml(file, config_type::GAME); diff --git a/src/emu/debug/debugcpu.cpp b/src/emu/debug/debugcpu.cpp index 01e0a91647b..f5fcce1f88b 100644 --- a/src/emu/debug/debugcpu.cpp +++ b/src/emu/debug/debugcpu.cpp @@ -204,7 +204,7 @@ bool debugger_cpu::comment_save() if (found_comments) { emu_file file(m_machine.options().comment_directory(), OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS); - osd_file::error filerr = file.open(m_machine.basename(), ".cmt"); + osd_file::error filerr = file.open(m_machine.basename() + ".cmt"); if (filerr == osd_file::error::NONE) { root->write(file); @@ -230,7 +230,7 @@ bool debugger_cpu::comment_load(bool is_inline) { // open the file emu_file file(m_machine.options().comment_directory(), OPEN_FLAG_READ); - osd_file::error filerr = file.open(m_machine.basename(), ".cmt"); + osd_file::error filerr = file.open(m_machine.basename() + ".cmt"); // if an error, just return false if (filerr != osd_file::error::NONE) diff --git a/src/emu/device.cpp b/src/emu/device.cpp index 055f0707135..84ea4ce04b5 100644 --- a/src/emu/device.cpp +++ b/src/emu/device.cpp @@ -84,7 +84,6 @@ emu::detail::device_registrar const registered_device_types; device_t::device_t(const machine_config &mconfig, device_type type, const char *tag, device_t *owner, u32 clock) : m_type(type) - , m_searchpath(type.shortname()) , m_owner(owner) , m_next(nullptr) @@ -122,6 +121,24 @@ device_t::~device_t() } +//------------------------------------------------- +// searchpath - get the media search path for a +// device +//------------------------------------------------- + +std::vector device_t::searchpath() const +{ + std::vector result; + device_t const *system(owner()); + while (system && !dynamic_cast(system)) + system = system->owner(); + if (system) + result = system->searchpath(); + result.emplace(result.begin(), shortname()); + return result; +} + + //------------------------------------------------- // memregion - return a pointer to the region // info for a given region diff --git a/src/emu/device.h b/src/emu/device.h index d6e35a5c1b7..941be58f798 100644 --- a/src/emu/device.h +++ b/src/emu/device.h @@ -529,7 +529,7 @@ public: device_type type() const { return m_type; } const char *name() const { return m_type.fullname(); } const char *shortname() const { return m_type.shortname(); } - const char *searchpath() const { return m_searchpath.c_str(); } + virtual std::vector searchpath() const; const char *source() const { return m_type.source(); } device_t *owner() const { return m_owner; } device_t *next() const { return m_next; } @@ -798,7 +798,6 @@ protected: // core device properties device_type m_type; // device type - std::string m_searchpath; // search path, used for media loading // device relationships & interfaces device_t * m_owner; // device that owns us diff --git a/src/emu/driver.cpp b/src/emu/driver.cpp index 7093b73615d..6bd504437f8 100644 --- a/src/emu/driver.cpp +++ b/src/emu/driver.cpp @@ -24,10 +24,19 @@ driver_device::driver_device(const machine_config &mconfig, device_type type, const char *tag) : device_t(mconfig, type, tag, nullptr, 0) - , m_system(nullptr) + , m_system(mconfig.gamedrv()) , m_flip_screen_x(0) , m_flip_screen_y(0) { + // set the search path to include all parents and cache it because devices search system paths + m_searchpath.emplace_back(m_system.name); + std::set seen; + for (int ancestor = driver_list::clone(m_system); 0 <= ancestor; ancestor = driver_list::clone(ancestor)) + { + if (!seen.insert(&driver_list::driver(ancestor)).second) + throw emu_fatalerror("driver_device(%s): parent/clone relationships form a loop", m_system.name); + m_searchpath.emplace_back(driver_list::driver(ancestor).name); + } } @@ -40,30 +49,6 @@ driver_device::~driver_device() } -//------------------------------------------------- -// set_game_driver - set the game in the device -// configuration -//------------------------------------------------- - -void driver_device::set_game_driver(const game_driver &game) -{ - assert(!m_system); - - // set the system - m_system = &game; - - // and set the search path to include all parents - m_searchpath = game.name; - std::set seen; - for (int parent = driver_list::clone(game); parent != -1; parent = driver_list::clone(parent)) - { - if (!seen.insert(&driver_list::driver(parent)).second) - throw emu_fatalerror("driver_device::set_game_driver(%s): parent/clone relationships form a loop", game.name); - m_searchpath.append(";").append(driver_list::driver(parent).name); - } -} - - //------------------------------------------------- // static_set_callback - set the a callback in // the device configuration @@ -86,6 +71,16 @@ void driver_device::empty_init() } +//------------------------------------------------- +// searchpath - return cached search path +//------------------------------------------------- + +std::vector driver_device::searchpath() const +{ + return m_searchpath; +} + + //------------------------------------------------- // driver_init - default implementation which // does nothing @@ -183,8 +178,7 @@ void driver_device::video_reset() const tiny_rom_entry *driver_device::device_rom_region() const { - assert(m_system); - return m_system->rom; + return m_system.rom; } @@ -194,8 +188,7 @@ const tiny_rom_entry *driver_device::device_rom_region() const void driver_device::device_add_mconfig(machine_config &config) { - assert(m_system); - m_system->machine_creator(config, *this); + m_system.machine_creator(config, *this); } @@ -206,7 +199,7 @@ void driver_device::device_add_mconfig(machine_config &config) ioport_constructor driver_device::device_input_ports() const { - return m_system->ipt; + return m_system.ipt; } @@ -223,7 +216,7 @@ void driver_device::device_start() throw device_missing_dependencies(); // call the game-specific init - m_system->driver_init(*this); + m_system.driver_init(*this); // finish image devices init process machine().image().postdevice_init(); diff --git a/src/emu/driver.h b/src/emu/driver.h index 0a92151d07c..88363437275 100644 --- a/src/emu/driver.h +++ b/src/emu/driver.h @@ -87,7 +87,7 @@ public: virtual ~driver_device(); // getters - const game_driver &system() const { assert(m_system != nullptr); return *m_system; } + const game_driver &system() const { return m_system; } // indexes into our generic callbacks enum callback_type @@ -100,7 +100,6 @@ public: }; // inline configuration helpers - void set_game_driver(const game_driver &game); static void static_set_callback(device_t &device, callback_type type, driver_callback_delegate callback); // dummy driver_init callback @@ -139,6 +138,8 @@ public: void irq7_line_hold(device_t &device); void irq7_line_assert(device_t &device); + virtual std::vector searchpath() const override; + virtual void driver_init(); protected: @@ -174,7 +175,8 @@ private: void updateflip(); // internal state - const game_driver *m_system; // pointer to the game driver + const game_driver &m_system; // reference to the system description + std::vector m_searchpath; // media search path following parent/clone links driver_callback_delegate m_callbacks[CB_COUNT]; // start/reset callbacks // generic video diff --git a/src/emu/drivers/empty.cpp b/src/emu/drivers/empty.cpp index 4dea1cceb9d..282d6c454e7 100644 --- a/src/emu/drivers/empty.cpp +++ b/src/emu/drivers/empty.cpp @@ -24,6 +24,8 @@ public: void ___empty(machine_config &config); + virtual std::vector searchpath() const override { return std::vector(); } + protected: virtual void machine_start() override { diff --git a/src/emu/emucore.h b/src/emu/emucore.h index 4eef4c19f90..8f0b8d1e150 100644 --- a/src/emu/emucore.h +++ b/src/emu/emucore.h @@ -72,6 +72,7 @@ using osd::s64; // useful utility functions using util::underlying_value; using util::enum_value; +using util::make_bitmask; using util::BIT; using util::bitswap; using util::iabs; diff --git a/src/emu/fileio.cpp b/src/emu/fileio.cpp index bbd1d931f30..53eac8d55cf 100644 --- a/src/emu/fileio.cpp +++ b/src/emu/fileio.cpp @@ -283,24 +283,6 @@ osd_file::error emu_file::open(const std::string &name) return open_next(); } -osd_file::error emu_file::open(const std::string &name1, const std::string &name2) -{ - // concatenate the strings and do a standard open - return open(name1 + name2); -} - -osd_file::error emu_file::open(const std::string &name1, const std::string &name2, const std::string &name3) -{ - // concatenate the strings and do a standard open - return open(name1 + name2 + name3); -} - -osd_file::error emu_file::open(const std::string &name1, const std::string &name2, const std::string &name3, const std::string &name4) -{ - // concatenate the strings and do a standard open - return open(name1 + name2 + name3 + name4); -} - osd_file::error emu_file::open(const std::string &name, u32 crc) { // remember the filename and CRC info diff --git a/src/emu/fileio.h b/src/emu/fileio.h index 26e9fb4e907..ad7ef5028a6 100644 --- a/src/emu/fileio.h +++ b/src/emu/fileio.h @@ -106,9 +106,6 @@ public: // open/close osd_file::error open(const std::string &name); - osd_file::error open(const std::string &name1, const std::string &name2); - osd_file::error open(const std::string &name1, const std::string &name2, const std::string &name3); - osd_file::error open(const std::string &name1, const std::string &name2, const std::string &name3, const std::string &name4); osd_file::error open(const std::string &name, u32 crc); osd_file::error open(const std::string &name1, const std::string &name2, u32 crc); osd_file::error open(const std::string &name1, const std::string &name2, const std::string &name3, u32 crc); diff --git a/src/emu/hashfile.cpp b/src/emu/hashfile.cpp index 6ded9a0e397..32628708271 100644 --- a/src/emu/hashfile.cpp +++ b/src/emu/hashfile.cpp @@ -2,7 +2,7 @@ // copyright-holders:Nathan Woods /********************************************************************* - hashfile.c + hashfile.cpp Code for parsing hash info (*.hsi) files @@ -10,12 +10,16 @@ #include "emu.h" #include "hashfile.h" -#include "pool.h" + +#include "drivenum.h" #include "emuopts.h" + #include "hash.h" -#include "drivenum.h" +#include "pool.h" + #include + /*------------------------------------------------- hashfile_lookup -------------------------------------------------*/ @@ -24,7 +28,7 @@ static bool read_hash_config(const char *hash_path, const util::hash_collection { /* open a file */ emu_file file(hash_path, OPEN_FLAG_READ); - if (file.open(sysname, ".hsi") != osd_file::error::NONE) + if (file.open(std::string(sysname) + ".hsi") != osd_file::error::NONE) { return false; } diff --git a/src/emu/machine.h b/src/emu/machine.h index 69223dd33af..d054ee861c7 100644 --- a/src/emu/machine.h +++ b/src/emu/machine.h @@ -195,7 +195,7 @@ public: bool exit_pending() const { return m_exit_pending; } bool hard_reset_pending() const { return m_hard_reset_pending; } bool ui_active() const { return m_ui_active; } - const char *basename() const { return m_basename.c_str(); } + const std::string &basename() const { return m_basename; } int sample_rate() const { return m_sample_rate; } bool save_or_load_pending() const { return !m_saveload_pending_file.empty(); } diff --git a/src/emu/mconfig.cpp b/src/emu/mconfig.cpp index e80d0594a19..0165978977c 100644 --- a/src/emu/mconfig.cpp +++ b/src/emu/mconfig.cpp @@ -323,9 +323,6 @@ device_t &machine_config::add_device(std::unique_ptr &&device, device_ // allocate the root device directly assert(!m_root_device); m_root_device = std::move(device); - driver_device *driver = dynamic_cast(m_root_device.get()); - if (driver) - driver->set_game_driver(m_gamedrv); m_root_device->add_machine_configuration(*this); return *m_root_device; } diff --git a/src/emu/render.cpp b/src/emu/render.cpp index 6e7067ea30e..e0599e8de91 100644 --- a/src/emu/render.cpp +++ b/src/emu/render.cpp @@ -1533,13 +1533,13 @@ void render_target::load_layout_files(const internal_layout *layoutfile, bool si bool have_artwork = false; // if there's an explicit file, load that first - const char *basename = m_manager.machine().basename(); + const std::string &basename = m_manager.machine().basename(); if (layoutfile) - have_artwork |= load_layout_file(basename, *layoutfile); + have_artwork |= load_layout_file(basename.c_str(), *layoutfile); // if we're only loading this file, we know our final result if (!singlefile) - load_additional_layout_files(basename, have_artwork); + load_additional_layout_files(basename.c_str(), have_artwork); } void render_target::load_layout_files(util::xml::data_node const &rootnode, bool singlefile) @@ -1547,12 +1547,12 @@ void render_target::load_layout_files(util::xml::data_node const &rootnode, bool bool have_artwork = false; // if there's an explicit file, load that first - const char *basename = m_manager.machine().basename(); - have_artwork |= load_layout_file(m_manager.machine().root_device(), basename, rootnode); + const std::string &basename = m_manager.machine().basename(); + have_artwork |= load_layout_file(m_manager.machine().root_device(), basename.c_str(), rootnode); // if we're only loading this file, we know our final result if (!singlefile) - load_additional_layout_files(basename, have_artwork); + load_additional_layout_files(basename.c_str(), have_artwork); } void render_target::load_additional_layout_files(const char *basename, bool have_artwork) diff --git a/src/emu/romload.cpp b/src/emu/romload.cpp index 67ef6cfb6aa..384de899ed6 100644 --- a/src/emu/romload.cpp +++ b/src/emu/romload.cpp @@ -33,8 +33,8 @@ static osd_file::error common_process_file(emu_options &options, const char *location, const char *ext, const rom_entry *romp, emu_file &image_file) { return (location && *location) - ? image_file.open(location, PATH_SEPARATOR, ROM_GETNAME(romp), ext) - : image_file.open(ROM_GETNAME(romp), ext); + ? image_file.open(util::string_format("%s" PATH_SEPARATOR "%s%s", location, ROM_GETNAME(romp), ext)) + : image_file.open(std::string(ROM_GETNAME(romp)) + ext); } std::unique_ptr common_process_file(emu_options &options, const char *location, bool has_crc, u32 crc, const rom_entry *romp, osd_file::error &filerr) @@ -44,12 +44,11 @@ std::unique_ptr common_process_file(emu_options &options, const char * if (has_crc) filerr = image_file->open(location, PATH_SEPARATOR, ROM_GETNAME(romp), crc); else - filerr = image_file->open(location, PATH_SEPARATOR, ROM_GETNAME(romp)); + filerr = image_file->open(util::string_format("%s" PATH_SEPARATOR "%s", location, ROM_GETNAME(romp))); if (filerr != osd_file::error::NONE) - { image_file = nullptr; - } + return image_file; } @@ -304,42 +303,49 @@ void rom_load_manager::fill_random(u8 *base, u32 length) for missing files -------------------------------------------------*/ -void rom_load_manager::handle_missing_file(const rom_entry *romp, std::string tried_file_names, chd_error chderr) +void rom_load_manager::handle_missing_file(const rom_entry *romp, const std::vector &tried_file_names, chd_error chderr) { - if(tried_file_names.length() != 0) - tried_file_names = " (tried in " + tried_file_names + ")"; + std::string tried; + if (!tried_file_names.empty()) + { + tried = " (tried in"; + for (const std::string &path : tried_file_names) + { + tried += ' '; + tried += path; + } + tried += ')'; + } std::string name(ROM_GETNAME(romp)); - bool is_chd = (chderr != CHDERR_NONE); + const bool is_chd(chderr != CHDERR_NONE); if (is_chd) name += ".chd"; - bool is_chd_error = (is_chd && chderr != CHDERR_FILE_NOT_FOUND); + const bool is_chd_error(is_chd && chderr != CHDERR_FILE_NOT_FOUND); if (is_chd_error) m_errorstring.append(string_format("%s CHD ERROR: %s\n", name.c_str(), chd_file::error_string(chderr))); - /* optional files are okay */ if (ROM_ISOPTIONAL(romp)) { + // optional files are okay if (!is_chd_error) - m_errorstring.append(string_format("OPTIONAL %s NOT FOUND%s\n", name.c_str(), tried_file_names.c_str())); + m_errorstring.append(string_format("OPTIONAL %s NOT FOUND%s\n", name, tried)); m_warnings++; } - - /* no good dumps are okay */ else if (util::hash_collection(ROM_GETHASHDATA(romp)).flag(util::hash_collection::FLAG_NO_DUMP)) { + // no good dumps are okay if (!is_chd_error) - m_errorstring.append(string_format("%s NOT FOUND (NO GOOD DUMP KNOWN)%s\n", name, tried_file_names)); + m_errorstring.append(string_format("%s NOT FOUND (NO GOOD DUMP KNOWN)%s\n", name, tried)); m_knownbad++; } - - /* anything else is bad */ else { + // anything else is bad if (!is_chd_error) - m_errorstring.append(string_format("%s NOT FOUND%s\n", name.c_str(), tried_file_names)); + m_errorstring.append(string_format("%s NOT FOUND%s\n", name, tried)); m_errors++; } } @@ -363,43 +369,46 @@ 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(const char *name, u32 explength, const util::hash_collection &hashes) +void rom_load_manager::verify_length_and_hash(emu_file *file, const char *name, u32 explength, const util::hash_collection &hashes) { - /* we've already complained if there is no file */ - if (m_file == nullptr) + // we've already complained if there is no file + if (!file) return; - /* verify length */ - u32 actlength = m_file->size(); + // verify length + u64 const actlength = file->size(); if (explength != actlength) { m_errorstring.append(string_format("%s WRONG LENGTH (expected: %08x found: %08x)\n", name, explength, actlength)); m_warnings++; } - /* If there is no good dump known, write it */ - util::hash_collection &acthashes = m_file->hashes(hashes.hash_types().c_str()); if (hashes.flag(util::hash_collection::FLAG_NO_DUMP)) { + // If there is no good dump known, write it m_errorstring.append(string_format("%s NO GOOD DUMP KNOWN\n", name)); m_knownbad++; } - /* verify checksums */ - else if (hashes != acthashes) - { - /* otherwise, it's just bad */ - util::hash_collection &all_acthashes = acthashes.hash_types() == util::hash_collection::HASH_TYPES_ALL - ? acthashes - : m_file->hashes(util::hash_collection::HASH_TYPES_ALL); - m_errorstring.append(string_format("%s WRONG CHECKSUMS:\n", name)); - dump_wrong_and_correct_checksums(hashes, all_acthashes); - m_warnings++; - } - /* If it matches, but it is actually a bad dump, write it */ - else if (hashes.flag(util::hash_collection::FLAG_BAD_DUMP)) + else { - m_errorstring.append(string_format("%s ROM NEEDS REDUMP\n", name)); - m_knownbad++; + // verify checksums + util::hash_collection const &acthashes = file->hashes(hashes.hash_types().c_str()); + if (hashes != acthashes) + { + // otherwise, it's just bad + util::hash_collection const &all_acthashes = (acthashes.hash_types() == util::hash_collection::HASH_TYPES_ALL) + ? acthashes + : file->hashes(util::hash_collection::HASH_TYPES_ALL); + m_errorstring.append(string_format("%s WRONG CHECKSUMS:\n", name)); + dump_wrong_and_correct_checksums(hashes, all_acthashes); + m_warnings++; + } + else if (hashes.flag(util::hash_collection::FLAG_BAD_DUMP)) + { + // If it matches, but it is actually a bad dump, write it + m_errorstring.append(string_format("%s ROM NEEDS REDUMP\n", name)); + m_knownbad++; + } } } @@ -411,15 +420,14 @@ void rom_load_manager::verify_length_and_hash(const char *name, u32 explength, c void rom_load_manager::display_loading_rom_message(const char *name, bool from_list) { - char buffer[200]; - - if (name != nullptr) - sprintf(buffer, "%s (%d%%)", from_list ? "Loading Software" : "Loading Machine", u32(100 * m_romsloadedsize / m_romstotalsize)); + std::string buffer; + if (name) + buffer = util::string_format("%s (%d%%)", from_list ? "Loading Software" : "Loading Machine", u32(100 * m_romsloadedsize / m_romstotalsize)); else - sprintf(buffer, "Loading Complete"); + buffer = "Loading Complete"; if (!machine().ui().is_menu_active()) - machine().ui().set_startup_text(buffer, false); + machine().ui().set_startup_text(buffer.c_str(), false); } @@ -495,31 +503,30 @@ void rom_load_manager::region_post_process(memory_region *region, bool invert) up the parent and loading by checksum -------------------------------------------------*/ -int rom_load_manager::open_rom_file(const char *regiontag, const rom_entry *romp, std::string &tried_file_names, bool from_list) +std::unique_ptr rom_load_manager::open_rom_file(const char *regiontag, const rom_entry *romp, std::vector &tried_file_names, bool from_list) { osd_file::error filerr = osd_file::error::NOT_FOUND; - u32 romsize = rom_file_size(romp); - tried_file_names = ""; + u32 const romsize = rom_file_size(romp); + tried_file_names.clear(); - /* update status display */ + // update status display display_loading_rom_message(ROM_GETNAME(romp), from_list); - /* extract CRC to use for searching */ + // extract CRC to use for searching u32 crc = 0; - bool has_crc = util::hash_collection(ROM_GETHASHDATA(romp)).crc(crc); - - /* attempt reading up the chain through the parents. It automatically also - attempts any kind of load by checksum supported by the archives. */ - m_file = nullptr; - for (int drv = driver_list::find(machine().system()); m_file == nullptr && drv != -1; drv = driver_list::clone(drv)) { - if (tried_file_names.length() != 0) - tried_file_names += " "; - tried_file_names += driver_list::driver(drv).name; - m_file = common_process_file(machine().options(), driver_list::driver(drv).name, has_crc, crc, romp, filerr); + bool const has_crc = util::hash_collection(ROM_GETHASHDATA(romp)).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 result; + for (int drv = driver_list::find(machine().system()); !result && (0 <= drv); drv = driver_list::clone(drv)) + { + tried_file_names.emplace_back(driver_list::driver(drv).name); + result = common_process_file(machine().options(), driver_list::driver(drv).name, has_crc, crc, romp, filerr); } - /* if the region is load by name, load the ROM from there */ - if (m_file == nullptr && regiontag != nullptr) + // if the region is load by name, load the ROM from there + if (!result && regiontag) { // check if we are dealing with softwarelists. if so, locationtag // is actually a concatenation of: listname + setname + parentname @@ -567,44 +574,47 @@ int rom_load_manager::open_rom_file(const char *regiontag, const rom_entry *romp // - if we are using lists, we have: list/clonename, list/parentname, clonename, parentname if (!is_list) { - tried_file_names += " " + tag1; - m_file = common_process_file(machine().options(), tag1.c_str(), has_crc, crc, romp, filerr); + tried_file_names.emplace_back(tag1); + result = common_process_file(machine().options(), tag1.c_str(), has_crc, crc, romp, filerr); } else { // try to load from list/setname - if ((m_file == nullptr) && (tag2.c_str() != nullptr)) + if (!result && (tag2.c_str() != nullptr)) // FIXME: std::string::c_str will never return nullptr { - tried_file_names += " " + tag2; - m_file = common_process_file(machine().options(), tag2.c_str(), has_crc, crc, romp, filerr); + tried_file_names.emplace_back(tag2); + result = common_process_file(machine().options(), tag2.c_str(), has_crc, crc, romp, filerr); } // try to load from list/parentname - if ((m_file == nullptr) && has_parent && (tag3.c_str() != nullptr)) + if (!result && has_parent && (tag3.c_str() != nullptr)) // FIXME: std::string::c_str will never return nullptr { - tried_file_names += " " + tag3; - m_file = common_process_file(machine().options(), tag3.c_str(), has_crc, crc, romp, filerr); + tried_file_names.emplace_back(tag3); + result = common_process_file(machine().options(), tag3.c_str(), has_crc, crc, romp, filerr); } // try to load from setname - if ((m_file == nullptr) && (tag4.c_str() != nullptr)) + if (!result && (tag4.c_str() != nullptr)) // FIXME: std::string::c_str will never return nullptr { - tried_file_names += " " + tag4; - m_file = common_process_file(machine().options(), tag4.c_str(), has_crc, crc, romp, filerr); + tried_file_names.emplace_back(tag4); + result = common_process_file(machine().options(), tag4.c_str(), has_crc, crc, romp, filerr); } // try to load from parentname - if ((m_file == nullptr) && has_parent && (tag5.c_str() != nullptr)) + if (!result && has_parent && (tag5.c_str() != nullptr)) // FIXME: std::string::c_str will never return nullptr { - tried_file_names += " " + tag5; - m_file = common_process_file(machine().options(), tag5.c_str(), has_crc, crc, romp, filerr); + tried_file_names.emplace_back(tag5); + result = common_process_file(machine().options(), tag5.c_str(), has_crc, crc, romp, filerr); } } } - /* update counters */ + // update counters m_romsloaded++; m_romsloadedsize += romsize; - /* return the result */ - return (filerr == osd_file::error::NONE); + // return the result + if (osd_file::error::NONE != filerr) + return nullptr; + else + return result; } @@ -613,14 +623,12 @@ int rom_load_manager::open_rom_file(const char *regiontag, const rom_entry *romp random data for a nullptr file -------------------------------------------------*/ -int rom_load_manager::rom_fread(u8 *buffer, int length, const rom_entry *parent_region) +int rom_load_manager::rom_fread(emu_file *file, u8 *buffer, int length, const rom_entry *parent_region) { - /* files just pass through */ - if (m_file != nullptr) - return m_file->read(buffer, length); + if (file) // files just pass through + return file->read(buffer, length); - /* otherwise, fill with randomness unless it was already specifically erased */ - else if (!ROMREGION_ISERASE(parent_region)) + if (!ROMREGION_ISERASE(parent_region)) // otherwise, fill with randomness unless it was already specifically erased fill_random(buffer, length); return length; @@ -632,7 +640,7 @@ int rom_load_manager::rom_fread(u8 *buffer, int length, const rom_entry *parent_ entry -------------------------------------------------*/ -int rom_load_manager::read_rom_data(const rom_entry *parent_region, const rom_entry *romp) +int rom_load_manager::read_rom_data(emu_file *file, const rom_entry *parent_region, const rom_entry *romp) { int datashift = ROM_GETBITSHIFT(romp); int datamask = ((1 << ROM_GETBITWIDTH(romp)) - 1) << datashift; @@ -661,7 +669,7 @@ int rom_load_manager::read_rom_data(const rom_entry *parent_region, const rom_en /* special case for simple loads */ if (datamask == 0xff && (groupsize == 1 || !reversed) && skip == 0) - return rom_fread(base, numbytes, parent_region); + return rom_fread(file, base, numbytes, parent_region); /* use a temporary buffer for complex loads */ tempbufsize = std::min(TEMPBUFFER_MAX_SIZE, numbytes); @@ -677,7 +685,7 @@ int rom_load_manager::read_rom_data(const rom_entry *parent_region, const rom_en /* read as much as we can */ LOG(" Reading %X bytes into buffer\n", bytesleft); - if (rom_fread(bufptr, bytesleft, parent_region) != bytesleft) + if (rom_fread(file, bufptr, bytesleft, parent_region) != bytesleft) return 0; numbytes -= bytesleft; @@ -813,13 +821,16 @@ void rom_load_manager::copy_rom_data(const rom_entry *romp) for a region -------------------------------------------------*/ -void rom_load_manager::process_rom_entries(const char *regiontag, const rom_entry *parent_region, const rom_entry *romp, device_t *device, bool from_list) +void rom_load_manager::process_rom_entries(const device_t &device, const char *regiontag, const rom_entry *parent_region, const rom_entry *romp, bool from_list) { u32 lastflags = 0; + std::vector tried_file_names; - /* loop until we hit the end of this region */ + // loop until we hit the end of this region while (!ROMENTRY_ISREGIONEND(romp)) { + tried_file_names.clear(); + if (ROMENTRY_ISCONTINUE(romp)) throw emu_fatalerror("Error in RomModule definition: ROM_CONTINUE not preceded by ROM_LOAD\n"); @@ -831,7 +842,7 @@ void rom_load_manager::process_rom_entries(const char *regiontag, const rom_entr if (ROMENTRY_ISFILL(romp)) { - if (!ROM_GETBIOSFLAGS(romp) || ROM_GETBIOSFLAGS(romp) == device->system_bios()) + if (!ROM_GETBIOSFLAGS(romp) || ROM_GETBIOSFLAGS(romp) == device.system_bios()) fill_rom_data(romp); romp++; @@ -842,27 +853,31 @@ void rom_load_manager::process_rom_entries(const char *regiontag, const rom_entr } else if (ROMENTRY_ISFILE(romp)) { - /* handle files */ - int irrelevantbios = (ROM_GETBIOSFLAGS(romp) != 0 && ROM_GETBIOSFLAGS(romp) != device->system_bios()); - const rom_entry *baserom = romp; + // handle files + bool const irrelevantbios = (ROM_GETBIOSFLAGS(romp) != 0) && (ROM_GETBIOSFLAGS(romp) != device.system_bios()); + rom_entry const *baserom = romp; int explength = 0; - /* open the file if it is a non-BIOS or matches the current BIOS */ + // open the file if it is a non-BIOS or matches the current BIOS LOG("Opening ROM file: %s\n", ROM_GETNAME(romp)); - std::string tried_file_names; - if (!irrelevantbios && !open_rom_file(regiontag, romp, tried_file_names, from_list)) - handle_missing_file(romp, tried_file_names, CHDERR_NONE); + std::unique_ptr file; + if (!irrelevantbios) + { + file = open_rom_file(regiontag, romp, tried_file_names, from_list); + if (!file) + handle_missing_file(romp, tried_file_names, CHDERR_NONE); + } - /* 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 do { rom_entry modified_romp = *romp++; //int readresult; - /* handle flag inheritance */ + // handle flag inheritance if (!ROM_INHERITSFLAGS(&modified_romp)) lastflags = modified_romp.get_flags(); else @@ -870,33 +885,33 @@ void rom_load_manager::process_rom_entries(const char *regiontag, const rom_entr explength += ROM_GETLENGTH(&modified_romp); - /* attempt to read using the modified entry */ + // attempt to read using the modified entry if (!ROMENTRY_ISIGNORE(&modified_romp) && !irrelevantbios) - /*readresult = */read_rom_data(parent_region, &modified_romp); + /*readresult = */read_rom_data(file.get(), parent_region, &modified_romp); } while (ROMENTRY_ISCONTINUE(romp) || ROMENTRY_ISIGNORE(romp)); - /* if this was the first use of this file, verify the length and CRC */ + // if this was the first use of this file, verify the length and CRC if (baserom) { LOG("Verifying length (%X) and checksums\n", explength); - verify_length_and_hash(ROM_GETNAME(baserom), explength, util::hash_collection(ROM_GETHASHDATA(baserom))); + verify_length_and_hash(file.get(), ROM_GETNAME(baserom), explength, util::hash_collection(ROM_GETHASHDATA(baserom))); LOG("Verify finished\n"); } - /* reseek to the start and clear the baserom so we don't reverify */ - if (m_file != nullptr) - m_file->seek(0, SEEK_SET); + // re-seek to the start and clear the baserom so we don't reverify + if (file) + file->seek(0, SEEK_SET); baserom = nullptr; explength = 0; } while (ROMENTRY_ISRELOAD(romp)); - /* close the file */ - if (m_file != nullptr) + // close the file + if (file) { LOG("Closing ROM file\n"); - m_file = nullptr; + file.reset(); } } else @@ -1156,7 +1171,7 @@ void rom_load_manager::process_disk_entries(const char *regiontag, const rom_ent err = chd_error(open_disk_image(machine().options(), &machine().system(), romp, chd->orig_chd(), locationtag)); if (err != CHDERR_NONE) { - handle_missing_file(romp, std::string(), err); + handle_missing_file(romp, std::vector(), err); chd = nullptr; continue; } @@ -1339,7 +1354,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)) - process_rom_entries(locationtag.c_str(), region, region + 1, &device, true); + process_rom_entries(device, locationtag.c_str(), region, region + 1, true); else if (ROMREGION_ISDISKDATA(region)) process_disk_entries(regiontag.c_str(), region, region + 1, locationtag.c_str()); } @@ -1362,6 +1377,7 @@ void rom_load_manager::process_region_list() /* loop until we hit the end */ device_iterator deviter(machine().root_device()); for (device_t &device : deviter) + { for (const rom_entry *region = rom_first_region(device); region != nullptr; region = rom_next_region(region)) { u32 regionlength = ROMREGION_GETLENGTH(region); @@ -1383,39 +1399,39 @@ void rom_load_manager::process_region_list() m_region = machine().memory().region_alloc(regiontag.c_str(), regionlength, width, endianness); LOG("Allocated %X bytes @ %p\n", m_region->bytes(), m_region->base()); - /* clear the region if it's requested */ - if (ROMREGION_ISERASE(region)) + if (ROMREGION_ISERASE(region)) // clear the region if it's requested memset(m_region->base(), ROMREGION_GETERASEVAL(region), m_region->bytes()); - - /* or if it's sufficiently small (<= 4MB) */ - else if (m_region->bytes() <= 0x400000) + else if (m_region->bytes() <= 0x400000) // or if it's sufficiently small (<= 4MB) memset(m_region->base(), 0, m_region->bytes()); - #ifdef MAME_DEBUG - /* if we're debugging, fill region with random data to catch errors */ - else + else // if we're debugging, fill region with random data to catch errors fill_random(m_region->base(), m_region->bytes()); #endif - /* now process the entries in the region */ - process_rom_entries(device.shortname(), region, region + 1, &device, false); + // now process the entries in the region + process_rom_entries(device, device.shortname(), region, region + 1, false); } else if (ROMREGION_ISDISKDATA(region)) + { process_disk_entries(regiontag.c_str(), region, region + 1, nullptr); + } } + } - /* now go back and post-process all the regions */ + // 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)); - /* and finally register all per-game parameters */ + // and finally register all per-game parameters for (device_t &device : deviter) + { for (const rom_entry *param = rom_first_parameter(device); param != nullptr; param = rom_next_parameter(param)) { std::string regiontag = device.subtag(param->name()); machine().parameters().add(regiontag, param->hashdata()); } + } } diff --git a/src/emu/romload.h b/src/emu/romload.h index 55ed3c25978..87f3054326d 100644 --- a/src/emu/romload.h +++ b/src/emu/romload.h @@ -424,18 +424,18 @@ private: void determine_bios_rom(device_t &device, const char *specbios); void count_roms(); void fill_random(u8 *base, u32 length); - void handle_missing_file(const rom_entry *romp, std::string tried_file_names, chd_error chderr); + void handle_missing_file(const rom_entry *romp, const std::vector &tried_file_names, chd_error chderr); void dump_wrong_and_correct_checksums(const util::hash_collection &hashes, const util::hash_collection &acthashes); - void verify_length_and_hash(const char *name, u32 explength, const util::hash_collection &hashes); + void verify_length_and_hash(emu_file *file, const char *name, u32 explength, const util::hash_collection &hashes); void display_loading_rom_message(const char *name, bool from_list); void display_rom_load_results(bool from_list); void region_post_process(memory_region *region, bool invert); - int open_rom_file(const char *regiontag, const rom_entry *romp, std::string &tried_file_names, bool from_list); - int rom_fread(u8 *buffer, int length, const rom_entry *parent_region); - int read_rom_data(const rom_entry *parent_region, const rom_entry *romp); + std::unique_ptr open_rom_file(const char *regiontag, const rom_entry *romp, std::vector &tried_file_names, bool from_list); + int rom_fread(emu_file *file, u8 *buffer, int length, const rom_entry *parent_region); + int read_rom_data(emu_file *file, const rom_entry *parent_region, const rom_entry *romp); void fill_rom_data(const rom_entry *romp); void copy_rom_data(const rom_entry *romp); - void process_rom_entries(const char *regiontag, const rom_entry *parent_region, const rom_entry *romp, device_t *device, bool from_list); + void process_rom_entries(const device_t &device, const char *regiontag, const rom_entry *parent_region, const rom_entry *romp, bool from_list); chd_error open_disk_diff(emu_options &options, const rom_entry *romp, chd_file &source, chd_file &diff_chd); void process_disk_entries(const char *regiontag, const rom_entry *parent_region, const rom_entry *romp, const char *locationtag); void normalize_flags_for_device(const char *rgntag, u8 &width, endianness_t &endian); @@ -454,7 +454,6 @@ private: u64 m_romsloadedsize; // total size of ROMs loaded so far u64 m_romstotalsize; // total size of ROMs to read - std::unique_ptr m_file; /* current file */ std::vector> m_chd_list; /* disks */ memory_region * m_region; // info about current region diff --git a/src/emu/screen.cpp b/src/emu/screen.cpp index 67b9006988d..22a55bdb531 100644 --- a/src/emu/screen.cpp +++ b/src/emu/screen.cpp @@ -1914,17 +1914,14 @@ void screen_device::finalize_burnin() // compute the name and create the file emu_file file(machine().options().snapshot_directory(), OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS); - osd_file::error filerr = file.open(machine().basename(), PATH_SEPARATOR "burnin-", this->tag()+1, ".png") ; + osd_file::error filerr = file.open(util::string_format("%s" PATH_SEPARATOR "burnin-%s.png", machine().basename(), tag() + 1)); if (filerr == osd_file::error::NONE) { png_info pnginfo; - char text[256]; // add two text entries describing the image - sprintf(text,"%s %s", emulator_info::get_appname(), emulator_info::get_build_version()); - pnginfo.add_text("Software", text); - sprintf(text, "%s %s", machine().system().manufacturer, machine().system().type.fullname()); - pnginfo.add_text("System", text); + pnginfo.add_text("Software", util::string_format("%s %s", emulator_info::get_appname(), emulator_info::get_build_version()).c_str()); + pnginfo.add_text("System", util::string_format("%s %s", machine().system().manufacturer, machine().system().type.fullname()).c_str()); // now do the actual work png_write_bitmap(file, &pnginfo, finalmap, 0, nullptr); diff --git a/src/emu/softlist_dev.cpp b/src/emu/softlist_dev.cpp index 08befcd4e9e..9d5e03d9b3a 100644 --- a/src/emu/softlist_dev.cpp +++ b/src/emu/softlist_dev.cpp @@ -282,7 +282,7 @@ void software_list_device::parse() m_errors.clear(); // attempt to open the file - osd_file::error filerr = m_file.open(m_list_name, ".xml"); + const osd_file::error filerr = m_file.open(m_list_name + ".xml"); if (filerr == osd_file::error::NONE) { // parse if no error diff --git a/src/emu/video.cpp b/src/emu/video.cpp index 65ff20473c5..7a498c27c72 100644 --- a/src/emu/video.cpp +++ b/src/emu/video.cpp @@ -1236,7 +1236,7 @@ void video_manager::recompute_speed(const attotime &emutime) { // create a final screenshot emu_file file(machine().options().snapshot_directory(), OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS); - osd_file::error filerr = file.open(machine().basename(), PATH_SEPARATOR "final.png"); + osd_file::error filerr = file.open(machine().basename() + PATH_SEPARATOR "final.png"); if (filerr == osd_file::error::NONE) save_snapshot(nullptr, file); diff --git a/src/frontend/mame/audit.cpp b/src/frontend/mame/audit.cpp index dbba78e20ec..256f9876f1b 100644 --- a/src/frontend/mame/audit.cpp +++ b/src/frontend/mame/audit.cpp @@ -29,7 +29,7 @@ media_auditor::media_auditor(const driver_enumerator &enumerator) : m_enumerator(enumerator) , m_validation(AUDIT_VALIDATE_FULL) - , m_searchpath(nullptr) + , m_searchpath() { } @@ -47,10 +47,6 @@ media_auditor::summary media_auditor::audit_media(const char *validation) // store validation for later m_validation = validation; -// temporary hack until romload is update: get the driver path and support it for -// all searches -const char *driverpath = m_enumerator.config()->root_device().searchpath(); - std::size_t found = 0; std::size_t required = 0; std::size_t shared_found = 0; @@ -60,17 +56,17 @@ const char *driverpath = m_enumerator.config()->root_device().searchpath(); for (device_t &device : device_iterator(m_enumerator.config()->root_device())) { // determine the search path for this source and iterate through the regions - m_searchpath = device.searchpath(); + m_searchpath.clear(); + for (const std::string &path : device.searchpath()) + { + if (!m_searchpath.empty()) + m_searchpath += ';'; + m_searchpath += path; + } // now iterate over regions and ROMs within for (const rom_entry *region = rom_first_region(device); region; region = rom_next_region(region)) { -// temporary hack: add the driver path & region name -std::string combinedpath = util::string_format("%s;%s", device.searchpath(), driverpath); -if (device.shortname()) - combinedpath.append(";").append(device.shortname()); -m_searchpath = combinedpath.c_str(); - for (const rom_entry *rom = rom_first_file(region); rom; rom = rom_next_file(rom)) { char const *const name(ROM_GETNAME(rom)); @@ -166,7 +162,7 @@ media_auditor::summary media_auditor::audit_software(const std::string &list_nam locationtag.append(swinfo->parentname()); combinedpath.append(util::string_format(";%s;%s%s%s", swinfo->parentname(), list_name, PATH_SEPARATOR, swinfo->parentname())); } - m_searchpath = combinedpath.c_str(); + m_searchpath = combinedpath; std::size_t found = 0; std::size_t required = 0; @@ -225,9 +221,9 @@ media_auditor::summary media_auditor::audit_samples() while (path.next(curpath, samplename)) { // attempt to access the file (.flac) or (.wav) - osd_file::error filerr = file.open(curpath, ".flac"); + osd_file::error filerr = file.open(curpath + ".flac"); if (filerr != osd_file::error::NONE) - filerr = file.open(curpath, ".wav"); + filerr = file.open(curpath + ".wav"); if (filerr == osd_file::error::NONE) { @@ -392,6 +388,7 @@ media_auditor::audit_record &media_auditor::audit_one_rom(const rom_entry *rom) file.set_restrict_to_mediapath(true); path_iterator path(m_searchpath); std::string curpath; + // FIXME: needs to be adjusted to match ROM loading behaviour while (path.next(curpath, record.name())) { // open the file if we can diff --git a/src/frontend/mame/audit.h b/src/frontend/mame/audit.h index be6dccf297c..42296d9260b 100644 --- a/src/frontend/mame/audit.h +++ b/src/frontend/mame/audit.h @@ -141,8 +141,8 @@ public: audit_status m_status; // status of audit on this item audit_substatus m_substatus; // finer-detail status const char * m_name; // name of item - uint64_t m_explength; // expected length of item - uint64_t m_length; // actual length of item + uint64_t m_explength; // expected length of item + uint64_t m_length; // actual length of item util::hash_collection m_exphashes; // expected hash data util::hash_collection m_hashes; // actual hash information device_t * m_shared_device; // device that shares the rom @@ -174,7 +174,7 @@ private: record_list m_record_list; const driver_enumerator & m_enumerator; const char * m_validation; - const char * m_searchpath; + std::string m_searchpath; }; diff --git a/src/frontend/mame/cheat.cpp b/src/frontend/mame/cheat.cpp index 38676366a61..e007f0d8372 100644 --- a/src/frontend/mame/cheat.cpp +++ b/src/frontend/mame/cheat.cpp @@ -138,7 +138,7 @@ inline std::string number_and_format::format() const // cheat_parameter - constructor //------------------------------------------------- -cheat_parameter::cheat_parameter(cheat_manager &manager, symbol_table &symbols, const char *filename, util::xml::data_node const ¶mnode) +cheat_parameter::cheat_parameter(cheat_manager &manager, symbol_table &symbols, std::string const &filename, util::xml::data_node const ¶mnode) : m_minval(number_and_format(paramnode.get_attribute_int("min", 0), paramnode.get_attribute_int_format("min"))) , m_maxval(number_and_format(paramnode.get_attribute_int("max", 0), paramnode.get_attribute_int_format("max"))) , m_stepval(number_and_format(paramnode.get_attribute_int("step", 1), paramnode.get_attribute_int_format("step"))) @@ -320,7 +320,7 @@ constexpr int cheat_script::script_entry::MAX_ARGUMENTS; cheat_script::cheat_script( cheat_manager &manager, symbol_table &symbols, - char const *filename, + std::string const &filename, util::xml::data_node const &scriptnode) : m_state(SCRIPT_STATE_RUN) { @@ -398,7 +398,7 @@ void cheat_script::save(emu_file &cheatfile) const cheat_script::script_entry::script_entry( cheat_manager &manager, symbol_table &symbols, - char const *filename, + std::string const &filename, util::xml::data_node const &entrynode, bool isaction) : m_condition(&symbols) @@ -574,7 +574,7 @@ void cheat_script::script_entry::save(emu_file &cheatfile) const // has the correct number and type of arguments //------------------------------------------------- -void cheat_script::script_entry::validate_format(const char *filename, int line) +void cheat_script::script_entry::validate_format(std::string const &filename, int line) { // first count arguments int argsprovided(0); @@ -608,7 +608,7 @@ void cheat_script::script_entry::validate_format(const char *filename, int line) cheat_script::script_entry::output_argument::output_argument( cheat_manager &manager, symbol_table &symbols, - char const *filename, + std::string const &filename, util::xml::data_node const &argnode) : m_expression(&symbols) , m_count(0) @@ -677,7 +677,7 @@ void cheat_script::script_entry::output_argument::save(emu_file &cheatfile) cons // cheat_entry - constructor //------------------------------------------------- -cheat_entry::cheat_entry(cheat_manager &manager, symbol_table &globaltable, const char *filename, util::xml::data_node const &cheatnode) +cheat_entry::cheat_entry(cheat_manager &manager, symbol_table &globaltable, std::string const &filename, util::xml::data_node const &cheatnode) : m_manager(manager) , m_symbols(&manager.machine(), &globaltable) , m_state(SCRIPT_STATE_OFF) @@ -1170,7 +1170,7 @@ void cheat_manager::reload() // have the same shortname if (image.loaded_through_softlist()) { - load_cheats(string_format("%s%s%s", image.software_list_name(), PATH_SEPARATOR, image.basename()).c_str()); + load_cheats(string_format("%s" PATH_SEPARATOR "%s", image.software_list_name(), image.basename())); break; } // else we are loading outside the software list, try to load machine_basename/crc32.xml @@ -1179,7 +1179,7 @@ void cheat_manager::reload() uint32_t crc = image.crc(); if (crc != 0) { - load_cheats(string_format("%s%s%08X", machine().basename(), PATH_SEPARATOR, crc).c_str()); + load_cheats(string_format("%s" PATH_SEPARATOR "%08X", machine().basename(), crc)); break; } } @@ -1201,11 +1201,11 @@ void cheat_manager::reload() // memory to the given filename //------------------------------------------------- -bool cheat_manager::save_all(const char *filename) +bool cheat_manager::save_all(std::string const &filename) { // open the file with the proper name emu_file cheatfile(machine().options().cheat_path(), OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS); - osd_file::error const filerr(cheatfile.open(filename, ".xml")); + osd_file::error const filerr(cheatfile.open(filename + ".xml")); // if that failed, return nothing if (filerr != osd_file::error::NONE) @@ -1392,19 +1392,19 @@ void cheat_manager::frame_update() // and create the cheat entry list //------------------------------------------------- -void cheat_manager::load_cheats(const char *filename) +void cheat_manager::load_cheats(std::string const &filename) { std::string searchstr(machine().options().cheat_path()); std::string curpath; for (path_iterator path(searchstr); path.next(curpath); ) { - searchstr.append(";").append(curpath).append(PATH_SEPARATOR).append("cheat"); + searchstr.append(";").append(curpath).append(PATH_SEPARATOR "cheat"); } emu_file cheatfile(std::move(searchstr), OPEN_FLAG_READ); try { // loop over all instrances of the files found in our search paths - for (osd_file::error filerr = cheatfile.open(filename, ".xml"); filerr == osd_file::error::NONE; filerr = cheatfile.open_next()) + for (osd_file::error filerr = cheatfile.open(filename + ".xml"); filerr == osd_file::error::NONE; filerr = cheatfile.open_next()) { osd_printf_verbose("Loading cheats file from %s\n", cheatfile.fullpath()); diff --git a/src/frontend/mame/cheat.h b/src/frontend/mame/cheat.h index d05890c7152..b6faaa85e80 100644 --- a/src/frontend/mame/cheat.h +++ b/src/frontend/mame/cheat.h @@ -88,7 +88,7 @@ public: cheat_parameter( cheat_manager &manager, symbol_table &symbols, - char const *filename, + std::string const &filename, util::xml::data_node const ¶mnode); // queries @@ -153,7 +153,7 @@ public: cheat_script( cheat_manager &manager, symbol_table &symbols, - char const *filename, + std::string const &filename, util::xml::data_node const &scriptnode); // getters @@ -172,7 +172,7 @@ private: script_entry( cheat_manager &manager, symbol_table &symbols, - char const *filename, + std::string const &filename, util::xml::data_node const &entrynode, bool isaction); @@ -189,7 +189,7 @@ private: output_argument( cheat_manager &manager, symbol_table &symbols, - char const *filename, + std::string const &filename, util::xml::data_node const &argnode); // getters @@ -206,7 +206,7 @@ private: }; // internal helpers - void validate_format(char const *filename, int line); + void validate_format(std::string const &filename, int line); // internal state parsed_expression m_condition; // condition under which this is executed @@ -233,7 +233,7 @@ class cheat_entry { public: // construction/destruction - cheat_entry(cheat_manager &manager, symbol_table &globaltable, const char *filename, util::xml::data_node const &cheatnode); + cheat_entry(cheat_manager &manager, symbol_table &globaltable, std::string const &filename, util::xml::data_node const &cheatnode); ~cheat_entry(); // getters @@ -319,7 +319,7 @@ public: // actions void reload(); - bool save_all(const char *filename); + bool save_all(std::string const &filename); void render_text(mame_ui_manager &mui, render_container &container); // output helpers @@ -333,7 +333,7 @@ public: private: // internal helpers void frame_update(); - void load_cheats(char const *filename); + void load_cheats(std::string const &filename); // internal state running_machine & m_machine; // reference to our machine diff --git a/src/frontend/mame/clifront.cpp b/src/frontend/mame/clifront.cpp index 3a881c1f667..fa63a283465 100644 --- a/src/frontend/mame/clifront.cpp +++ b/src/frontend/mame/clifront.cpp @@ -1650,7 +1650,7 @@ void cli_frontend::execute_commands(const char *exename) { // attempt to open the output file emu_file file(OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS); - if (file.open(emulator_info::get_configname(), ".ini") != osd_file::error::NONE) + if (file.open(std::string(emulator_info::get_configname()) + ".ini") != osd_file::error::NONE) throw emu_fatalerror("Unable to create file %s.ini\n",emulator_info::get_configname()); // generate the updated INI diff --git a/src/frontend/mame/language.cpp b/src/frontend/mame/language.cpp index 2740aed973f..446157e6f19 100644 --- a/src/frontend/mame/language.cpp +++ b/src/frontend/mame/language.cpp @@ -68,7 +68,7 @@ void load_translation(emu_options &m_options) strreplace(name, "(", ""); strreplace(name, ")", ""); emu_file file(m_options.language_path(), OPEN_FLAG_READ); - if (file.open(name, PATH_SEPARATOR "strings.mo") != osd_file::error::NONE) + if (file.open(name + PATH_SEPARATOR "strings.mo") != osd_file::error::NONE) { osd_printf_error("Error opening translation file %s\n", name); return; diff --git a/src/frontend/mame/mameopts.cpp b/src/frontend/mame/mameopts.cpp index 48df66a337e..296d900d679 100644 --- a/src/frontend/mame/mameopts.cpp +++ b/src/frontend/mame/mameopts.cpp @@ -130,7 +130,7 @@ void mame_options::parse_one_ini(emu_options &options, const char *basename, int // open the file; if we fail, that's ok emu_file file(options.ini_path(), OPEN_FLAG_READ); osd_printf_verbose("Attempting load of %s.ini\n", basename); - osd_file::error filerr = file.open(basename, ".ini"); + osd_file::error filerr = file.open(std::string(basename) + ".ini"); if (filerr != osd_file::error::NONE) return; diff --git a/src/frontend/mame/ui/auditmenu.cpp b/src/frontend/mame/ui/auditmenu.cpp index 2289762ae49..32d73b1fadd 100644 --- a/src/frontend/mame/ui/auditmenu.cpp +++ b/src/frontend/mame/ui/auditmenu.cpp @@ -228,7 +228,7 @@ void menu_audit::save_available_machines() { // attempt to open the output file emu_file file(ui().options().ui_path(), OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS); - if (file.open(emulator_info::get_configname(), "_avail.ini") == osd_file::error::NONE) + if (file.open(std::string(emulator_info::get_configname()) + "_avail.ini") == osd_file::error::NONE) { // generate header file.printf("#\n%s%s\n#\n\n", UI_VERSION_TAG, emulator_info::get_bare_build_version()); diff --git a/src/frontend/mame/ui/miscmenu.cpp b/src/frontend/mame/ui/miscmenu.cpp index 55147b020ec..82b7916e3a5 100644 --- a/src/frontend/mame/ui/miscmenu.cpp +++ b/src/frontend/mame/ui/miscmenu.cpp @@ -598,8 +598,8 @@ void menu_export::handle() { // process the menu process_parent(); - const event *menu_event = process(PROCESS_NOIMAGE); - if (menu_event != nullptr && menu_event->itemref != nullptr) + const event *const menu_event = process(PROCESS_NOIMAGE); + if (menu_event && menu_event->itemref) { switch (uintptr_t(menu_event->itemref)) { @@ -609,11 +609,11 @@ void menu_export::handle() { std::string filename("exported"); emu_file infile(ui().options().ui_path(), OPEN_FLAG_READ); - if (infile.open(filename, ".xml") == osd_file::error::NONE) + if (infile.open(filename + ".xml") == osd_file::error::NONE) for (int seq = 0; ; ++seq) { - std::string seqtext = string_format("%s_%04d", filename, seq); - if (infile.open(seqtext, ".xml") != osd_file::error::NONE) + const std::string seqtext = string_format("%s_%04d", filename, seq); + if (infile.open(seqtext + ".xml") != osd_file::error::NONE) { filename = seqtext; break; @@ -622,9 +622,9 @@ void menu_export::handle() // attempt to open the output file emu_file file(ui().options().ui_path(), OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS); - if (file.open(filename, ".xml") == osd_file::error::NONE) + if (file.open(filename + ".xml") == osd_file::error::NONE) { - std::string fullpath(file.fullpath()); + const std::string fullpath(file.fullpath()); file.close(); std::ofstream pfile(fullpath); @@ -654,11 +654,11 @@ void menu_export::handle() { std::string filename("exported"); emu_file infile(ui().options().ui_path(), OPEN_FLAG_READ); - if (infile.open(filename, ".txt") == osd_file::error::NONE) + if (infile.open(filename + ".txt") == osd_file::error::NONE) for (int seq = 0; ; ++seq) { - std::string seqtext = string_format("%s_%04d", filename, seq); - if (infile.open(seqtext, ".txt") != osd_file::error::NONE) + const std::string seqtext = string_format("%s_%04d", filename, seq); + if (infile.open(seqtext + ".txt") != osd_file::error::NONE) { filename = seqtext; break; @@ -667,7 +667,7 @@ void menu_export::handle() // attempt to open the output file emu_file file(ui().options().ui_path(), OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS); - if (file.open(filename, ".txt") == osd_file::error::NONE) + if (file.open(filename + ".txt") == osd_file::error::NONE) { // print the header std::ostringstream buffer; @@ -762,9 +762,9 @@ void menu_machine_configure::handle() { case SAVE: { - std::string filename(m_drv.name); + const std::string filename(m_drv.name); emu_file file(machine().options().ini_path(), OPEN_FLAG_WRITE | OPEN_FLAG_CREATE); - osd_file::error filerr = file.open(filename, ".ini"); + osd_file::error filerr = file.open(filename + ".ini"); if (filerr == osd_file::error::NONE) { std::string inistring = m_opts.output_ini(); diff --git a/src/frontend/mame/ui/optsmenu.cpp b/src/frontend/mame/ui/optsmenu.cpp index 17dddd10c67..98c1936510f 100644 --- a/src/frontend/mame/ui/optsmenu.cpp +++ b/src/frontend/mame/ui/optsmenu.cpp @@ -266,7 +266,7 @@ void menu_game_options::handle_item_event(event const &menu_event) if (machine_filter::CUSTOM == filter.get_type()) { emu_file file(ui().options().ui_path(), OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS); - if (file.open("custom_", emulator_info::get_configname(), "_filter.ini") == osd_file::error::NONE) + if (file.open(util::string_format("custom_%s_filter.ini", emulator_info::get_configname())) == osd_file::error::NONE) { filter.save_ini(file, 0); file.close(); diff --git a/src/frontend/mame/ui/selgame.cpp b/src/frontend/mame/ui/selgame.cpp index 00113d8aeda..6bbe0c874f1 100644 --- a/src/frontend/mame/ui/selgame.cpp +++ b/src/frontend/mame/ui/selgame.cpp @@ -1244,12 +1244,12 @@ render_texture *menu_select_game::get_icon_texture(int linenum, void *selectedre bitmap_argb32 tmp; emu_file snapfile(std::string(m_icon_paths), OPEN_FLAG_READ); - if (snapfile.open(std::string(driver->name), ".ico") == osd_file::error::NONE) + if (snapfile.open(std::string(driver->name) + ".ico") == osd_file::error::NONE) { render_load_ico_highest_detail(snapfile, tmp); snapfile.close(); } - if (!tmp.valid() && cloneof && (snapfile.open(std::string(driver->parent), ".ico") == osd_file::error::NONE)) + if (!tmp.valid() && cloneof && (snapfile.open(std::string(driver->parent) + ".ico") == osd_file::error::NONE)) { render_load_ico_highest_detail(snapfile, tmp); snapfile.close(); @@ -1294,7 +1294,7 @@ bool menu_select_game::load_available_machines() { // try to load available drivers from file emu_file file(ui().options().ui_path(), OPEN_FLAG_READ); - if (file.open(emulator_info::get_configname(), "_avail.ini") != osd_file::error::NONE) + if (file.open(std::string(emulator_info::get_configname()) + "_avail.ini") != osd_file::error::NONE) return false; char rbuf[MAX_CHAR_INFO]; @@ -1347,7 +1347,7 @@ bool menu_select_game::load_available_machines() void menu_select_game::load_custom_filters() { emu_file file(ui().options().ui_path(), OPEN_FLAG_READ); - if (file.open("custom_", emulator_info::get_configname(), "_filter.ini") == osd_file::error::NONE) + if (file.open(util::string_format("custom_%s_filter.ini", emulator_info::get_configname())) == osd_file::error::NONE) { machine_filter::ptr flt(machine_filter::create(file, m_persistent_data.filter_data())); if (flt) @@ -1442,7 +1442,7 @@ void menu_select_game::filter_selected() if (machine_filter::CUSTOM == new_type) { emu_file file(ui().options().ui_path(), OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS); - if (file.open("custom_", emulator_info::get_configname(), "_filter.ini") == osd_file::error::NONE) + if (file.open(util::string_format("custom_%s_filter.ini", emulator_info::get_configname())) == osd_file::error::NONE) { filter.save_ini(file, 0); file.close(); diff --git a/src/frontend/mame/ui/selsoft.cpp b/src/frontend/mame/ui/selsoft.cpp index 3c689d19239..4bbfb6fd294 100644 --- a/src/frontend/mame/ui/selsoft.cpp +++ b/src/frontend/mame/ui/selsoft.cpp @@ -521,7 +521,7 @@ void menu_select_software::load_sw_custom_filters() { // attempt to open the output file emu_file file(ui().options().ui_path(), OPEN_FLAG_READ); - if (file.open("custom_", m_driver.name, "_filter.ini") == osd_file::error::NONE) + if (file.open(util::string_format("custom_%s_filter.ini", m_driver.name)) == osd_file::error::NONE) { software_filter::ptr flt(software_filter::create(file, m_filter_data)); if (flt) @@ -597,12 +597,12 @@ render_texture *menu_select_software::get_icon_texture(int linenum, void *select bitmap_argb32 tmp; emu_file snapfile(std::string(paths->second), OPEN_FLAG_READ); - if (snapfile.open(std::string(swinfo->shortname), ".ico") == osd_file::error::NONE) + if (snapfile.open(std::string(swinfo->shortname) + ".ico") == osd_file::error::NONE) { render_load_ico_highest_detail(snapfile, tmp); snapfile.close(); } - if (!tmp.valid() && !swinfo->parentname.empty() && (snapfile.open(std::string(swinfo->parentname), ".ico") == osd_file::error::NONE)) + if (!tmp.valid() && !swinfo->parentname.empty() && (snapfile.open(std::string(swinfo->parentname) + ".ico") == osd_file::error::NONE)) { render_load_ico_highest_detail(snapfile, tmp); snapfile.close(); @@ -672,7 +672,7 @@ void menu_select_software::filter_selected() if (software_filter::CUSTOM == new_type) { emu_file file(ui().options().ui_path(), OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS); - if (file.open("custom_", m_driver.name, "_filter.ini") == osd_file::error::NONE) + if (file.open(util::string_format("custom_%s_filter.ini", m_driver.name)) == osd_file::error::NONE) { filter.save_ini(file, 0); file.close(); diff --git a/src/frontend/mame/ui/ui.cpp b/src/frontend/mame/ui/ui.cpp index b5b37a3450f..de1a7d5825c 100644 --- a/src/frontend/mame/ui/ui.cpp +++ b/src/frontend/mame/ui/ui.cpp @@ -2129,7 +2129,7 @@ void mame_ui_manager::save_main_option() // attempt to open the main ini file { emu_file file(machine().options().ini_path(), OPEN_FLAG_READ); - if (file.open(emulator_info::get_configname(), ".ini") == osd_file::error::NONE) + if (file.open(std::string(emulator_info::get_configname()) + ".ini") == osd_file::error::NONE) { try { @@ -2159,7 +2159,7 @@ void mame_ui_manager::save_main_option() // attempt to open the output file { emu_file file(machine().options().ini_path(), OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS); - if (file.open(emulator_info::get_configname(), ".ini") == osd_file::error::NONE) + if (file.open(std::string(emulator_info::get_configname()) + ".ini") == osd_file::error::NONE) { // generate the updated INI std::string initext = options.output_ini(); diff --git a/src/lib/util/coretmpl.h b/src/lib/util/coretmpl.h index 8b6bafa30fb..95d8230f565 100644 --- a/src/lib/util/coretmpl.h +++ b/src/lib/util/coretmpl.h @@ -32,15 +32,6 @@ #include #include -// Generate a N-bit mask at compile time. N better be constant. -// Works even for signed types - -template constexpr T make_bitmask(unsigned int N) -{ - return T((N < (8 * sizeof(T)) ? (std::make_unsigned_t(1) << N) : std::make_unsigned_t(0)) - 1); -} - - // ======================> simple_list // a simple_list is a singly-linked list whose 'next' pointer is owned @@ -939,17 +930,108 @@ constexpr typename std::enable_if_t::value && std::is_integral constexpr T make_bitmask(U n) +{ + return T((n < (8 * sizeof(T)) ? (std::make_unsigned_t(1) << n) : std::make_unsigned_t(0)) - 1); +} + + +/// \brief Extract a single bit from an integer +/// +/// Extracts a single bit from an integer into the least significant bit +/// position. +/// +/// \param [in] x The integer to extract the bit from. +/// \param [in] n The bit to extract, where zero is the least +/// significant bit of the input. +/// \return Zero if the specified bit is unset, or one if it is set. +/// \sa bitswap template constexpr T BIT(T x, U n) noexcept { return (x >> n) & T(1); } + +/// \brief Extract a bit field from an integer +/// +/// Extracts and right-aligns a bit field from an integer. +/// +/// \param [in] x The integer to extract the bit field from. +/// \param [in] n The least significant bit position of the field to +/// extract, where zero is the least significant bit of the input. +/// \param [in] w The width of the field to extract in bits. +/// \return The field [n..(n+w-1)] from the input. +/// \sa bitswap +template constexpr T BIT(T x, U n, V w) +{ + return (x >> n) & make_bitmask(w); +} + + +/// \brief Extract and right-align a single bit field +/// +/// This overload is used to terminate a recursive template +/// implementation. It is functionally equivalent to the BIT +/// function for extracting a single bit. +/// +/// \param [in] val The integer to extract the bit from. +/// \param [in] b The bit to extract, where zero is the least +/// significant bit of the input. +/// \return The specified bit of the input extracted to the least +/// significant position. template constexpr T bitswap(T val, U b) noexcept { return BIT(val, b) << 0U; } + +/// \brief Extract bits in arbitrary order +/// +/// Extracts bits from an integer. Specify the bits in the order they +/// should be arranged in the output, from most significant to least +/// significant. The extracted bits will be packed into a right-aligned +/// field in the output. +/// +/// \param [in] val The integer to extract bits from. +/// \param [in] b The first bit to extract from the input +/// extract, where zero is the least significant bit of the input. +/// This bit will appear in the most significant position of the +/// right-aligned output field. +/// \param [in] c The remaining bits to extract, where zero is the +/// least significant bit of the input. +/// \return The extracted bits packed into a right-aligned field. template constexpr T bitswap(T val, U b, V... c) noexcept { return (BIT(val, b) << sizeof...(c)) | bitswap(val, c...); } -// explicit version that checks number of bit position arguments + +/// \brief Extract bits in arbitrary order with explicit count +/// +/// Extracts bits from an integer. Specify the bits in the order they +/// should be arranged in the output, from most significant to least +/// significant. The extracted bits will be packed into a right-aligned +/// field in the output. The number of bits to extract must be supplied +/// as a template argument. +/// +/// A compile error will be generated if the number of bit positions +/// supplied does not match the specified number of bits to extract, or +/// if the output type is too small to hold the extracted bits. This +/// guards against some simple errors. +/// +/// \tparam B The number of bits to extract. Must match the number of +/// bit positions supplied. +/// \param [in] val The integer to extract bits from. +/// \param [in] b Bits to extract, where zero is the least significant +/// bit of the input. Specify bits in the order they should appear in +/// the output field, from most significant to least significant. +/// \return The extracted bits packed into a right-aligned field. template T bitswap(T val, U... b) noexcept { static_assert(sizeof...(b) == B, "wrong number of bits"); @@ -957,6 +1039,8 @@ template T bitswap(T val, U... b) noexce return bitswap(val, b...); } +/// \} + // constexpr absolute value of an integer template diff --git a/src/mame/drivers/chihiro.cpp b/src/mame/drivers/chihiro.cpp index a55d8bb0a18..8bbdd7f4ed0 100644 --- a/src/mame/drivers/chihiro.cpp +++ b/src/mame/drivers/chihiro.cpp @@ -1842,7 +1842,7 @@ void chihiro_state::machine_start() } m_hack_index = -1; for (int a = 1; a < HACK_ITEMS; a++) - if (strcmp(machine().basename(), hacks[a].game_name) == 0) { + if (machine().basename() == hacks[a].game_name) { m_hack_index = a; break; } diff --git a/src/mame/drivers/esq1.cpp b/src/mame/drivers/esq1.cpp index b212bff0c3d..87b2fda19dd 100644 --- a/src/mame/drivers/esq1.cpp +++ b/src/mame/drivers/esq1.cpp @@ -580,7 +580,7 @@ void esq1_state::send_through_panel(uint8_t data) INPUT_CHANGED_MEMBER(esq1_state::key_stroke) { u8 offset = 0; - if (strncmp(machine().basename(), "sq80", 4) == 0) + if (strncmp(machine().basename().c_str(), "sq80", 4) == 0) { if (!kpc_calibrated) { // ack SQ80 keyboard calibration diff --git a/src/mame/video/dooyong.cpp b/src/mame/video/dooyong.cpp index daeb0068293..634b974bed6 100644 --- a/src/mame/video/dooyong.cpp +++ b/src/mame/video/dooyong.cpp @@ -9,11 +9,11 @@ /* These games all have ROM-based tilemaps for the backgrounds, title screens and sometimes "bosses" and special attacks. There are three schemes for tilemap encoding. The scheme is chosen based on the - contents of the tilemap control variables declared above. + contents of the tilemap control variables. Note that although the tilemaps are arbitrarily wide (hundreds of thousands of pixels, depending on the size of the ROM), we only decode a 1024 pixel wide block at a time, and invalidate the tilemap - when the x scroll moves out of range (trying to decode the whole lot + when the X scroll moves out of range (trying to decode the whole lot at once uses hundreds of megabytes of RAM). */ DEFINE_DEVICE_TYPE(DOOYONG_ROM_TILEMAP, dooyong_rom_tilemap_device, "dooyong_rom_tilemap", "Dooyong ROM Tilemap") @@ -80,14 +80,14 @@ void dooyong_rom_tilemap_device::ctrl_w(offs_t offset, u8 data) m_registers[offset] = data; switch (offset) { - case 0: // Low byte of x scroll - scroll tilemap + case 0: // Low byte of X scroll - scroll tilemap m_tilemap->set_scrollx(0, data); break; - case 1: // High byte of x scroll - mark tilemap dirty so new tile gfx will be loaded + case 1: // High byte of X scroll - mark tilemap dirty so new tile gfx will be loaded m_tilemap->mark_all_dirty(); break; - case 3: // Low byte of y scroll - case 4: // High byte of y scroll + case 3: // Low byte of Y scroll + case 4: // High byte of Y scroll m_tilemap->set_scrolly(0, m_registers[3] | (unsigned(m_registers[4]) << 8)); break; case 6: // Tilemap enable and mode control @@ -150,8 +150,8 @@ TILE_GET_INFO_MEMBER(dooyong_rom_tilemap_device::tile_info) // X = x flip // Y = y flip code = (BIT(attr, 15) << 9) | (attr & 0x01ff); - color = (attr >> 11) & 0x0fU; - flags = TILE_FLIPYX((attr >> 9) & 0x03U); + color = BIT(attr, 11, 4); + flags = TILE_FLIPYX(BIT(attr, 9, 2)); } else { // bluehawk/primella/popbingo @@ -171,10 +171,10 @@ TILE_GET_INFO_MEMBER(dooyong_rom_tilemap_device::tile_info) else // just mimic old driver behavior (default configuration) { code = attr & 0x3ff; - color = (attr & 0x3c00) >> 10; + color = BIT(attr, 10, 4); } - flags = TILE_FLIPYX((attr >> 14) & 0x03U); + flags = TILE_FLIPYX(BIT(attr, 14, 2)); } color |= m_palette_bank; @@ -261,5 +261,5 @@ TILE_GET_INFO_MEMBER(dooyong_ram_tilemap_device::tile_info) // c = gfx code // C = color code const u16 attr(m_tileram[tile_index]); - tileinfo.set(m_gfxnum, attr & 0x0fffU, m_palette_bank | ((attr >> 12) & 0x0fU), 0); + tileinfo.set(m_gfxnum, attr & 0x0fffU, m_palette_bank | BIT(attr, 12, 4), 0); } -- cgit v1.2.3