diff --git a/src/devices/cpu/dsp16/dsp16.cpp b/src/devices/cpu/dsp16/dsp16.cpp index a360ec73607..b9948495566 100644 --- a/src/devices/cpu/dsp16/dsp16.cpp +++ b/src/devices/cpu/dsp16/dsp16.cpp @@ -382,7 +382,7 @@ void dsp16_device_base::device_reset() void dsp16_device_base::execute_run() { - if (machine().debug_flags & DEBUG_FLAG_ENABLED) + if (debugger_enabled()) { while (m_core->icount_remaining()) { diff --git a/src/devices/cpu/mcs51/mcs51dasm.h b/src/devices/cpu/mcs51/mcs51dasm.h index 98272befc89..e00c755bb33 100644 --- a/src/devices/cpu/mcs51/mcs51dasm.h +++ b/src/devices/cpu/mcs51/mcs51dasm.h @@ -28,6 +28,9 @@ #pragma once +#include + + class mcs51_disassembler : public util::disasm_interface { public: diff --git a/src/emu/diexec.h b/src/emu/diexec.h index eb99b8241c8..90351a3b4d9 100644 --- a/src/emu/diexec.h +++ b/src/emu/diexec.h @@ -225,6 +225,7 @@ protected: int standard_irq_callback(int irqline); // debugger hooks + bool debugger_enabled() const { return bool(device().machine().debug_flags & DEBUG_FLAG_ENABLED); } void debugger_instruction_hook(offs_t curpc) { if (device().machine().debug_flags & DEBUG_FLAG_CALL_HOOK) diff --git a/src/emu/diimage.cpp b/src/emu/diimage.cpp index bd814953685..1a30cb1d1ad 100644 --- a/src/emu/diimage.cpp +++ b/src/emu/diimage.cpp @@ -85,19 +85,19 @@ image_device_format::~image_device_format() //------------------------------------------------- device_image_interface::device_image_interface(const machine_config &mconfig, device_t &device) - : device_interface(device, "image"), - m_err(), - m_file(), - m_mame_file(), - m_software_part_ptr(nullptr), - m_supported(0), - m_readonly(false), - m_created(false), - m_create_format(0), - m_create_args(nullptr), - m_user_loadable(true), - m_is_loading(false), - m_is_reset_and_loading(false) + : device_interface(device, "image") + , m_err() + , m_file() + , m_mame_file() + , m_software_part_ptr(nullptr) + , m_supported(0) + , m_readonly(false) + , m_created(false) + , m_create_format(0) + , m_create_args(nullptr) + , m_user_loadable(true) + , m_is_loading(false) + , m_is_reset_and_loading(false) { } @@ -430,7 +430,7 @@ const std::string &device_image_interface::working_directory() const software_info *device_image_interface::software_entry() const { - return (m_software_part_ptr == nullptr) ? nullptr : &m_software_part_ptr->info(); + return !m_software_part_ptr ? nullptr : &m_software_part_ptr->info(); } @@ -465,9 +465,9 @@ u32 device_image_interface::get_software_region_length(const char *tag) // image_get_feature //------------------------------------------------- -const char *device_image_interface::get_feature(const char *feature_name) +const char *device_image_interface::get_feature(const char *feature_name) const { - return (m_software_part_ptr == nullptr) ? nullptr : m_software_part_ptr->feature(feature_name); + return !m_software_part_ptr ? nullptr : m_software_part_ptr->feature(feature_name); } diff --git a/src/emu/diimage.h b/src/emu/diimage.h index e58256a4d65..82c3d338a1f 100644 --- a/src/emu/diimage.h +++ b/src/emu/diimage.h @@ -198,7 +198,7 @@ public: u8 *get_software_region(const char *tag); u32 get_software_region_length(const char *tag); - const char *get_feature(const char *feature_name); + const char *get_feature(const char *feature_name) const; bool load_software_region(const char *tag, optional_shared_ptr &ptr); u32 crc(); diff --git a/src/emu/emucore.h b/src/emu/emucore.h index b6d1e7b3154..dda0b3da1ea 100644 --- a/src/emu/emucore.h +++ b/src/emu/emucore.h @@ -67,6 +67,14 @@ using osd::s16; using osd::s32; using osd::s64; +// useful utility functions +using util::underlying_value; +using util::enum_value; +using util::BIT; +using util::bitswap; +using util::iabs; + + // genf is a generic function pointer; cast function pointers to this instead of void * typedef void genf(void); @@ -242,29 +250,6 @@ inline TYPE &operator|=(TYPE &a, TYPE b) { return a = a | b; } #define ENDIAN_VALUE_NE_NNE(endian,neval,nneval) (((endian) == ENDIANNESS_NATIVE) ? (neval) : (nneval)) -// useful functions to deal with bit shuffling encryptions -template constexpr T BIT(T x, U n) { return (x >> n) & T(1); } - -template constexpr T bitswap(T val, U b) -{ - return BIT(val, b) << 0U; -} - -template constexpr T bitswap(T val, U b, V... c) -{ - return (BIT(val, b) << sizeof...(c)) | bitswap(val, c...); -} - -// explicit version that checks number of bit position arguments -template T bitswap(T val, U... b) -{ - static_assert(sizeof...(b) == B, "wrong number of bits"); - static_assert((sizeof(std::remove_reference_t) * 8) >= B, "return type too small for result"); - return bitswap(val, b...); -} - - - //************************************************************************** // EXCEPTION CLASSES //************************************************************************** @@ -343,25 +328,6 @@ inline Dest downcast(Source &src) return static_cast(src); } -// template function which takes a strongly typed enumerator and returns its value as a compile-time constant -template -using enable_enum_t = typename std::enable_if_t::value, typename std::underlying_type_t>; - -template -constexpr inline enable_enum_t -underlying_value(E e) noexcept -{ - return static_cast< typename std::underlying_type::type >( e ); -} - -// template function which takes an integral value and returns its representation as enumerator (even strongly typed) -template -constexpr inline typename std::enable_if_t::value && std::is_integral::value, E> -enum_value(T value) noexcept -{ - return static_cast(value); -} - //************************************************************************** @@ -422,12 +388,4 @@ inline u64 d2u(double d) return u.vv; } - -// constexpr absolute value of an integer -template -constexpr std::enable_if_t::value, T> iabs(T v) -{ - return (v < T(0)) ? -v : v; -} - #endif /* MAME_EMU_EMUCORE_H */ diff --git a/src/emu/emuopts.cpp b/src/emu/emuopts.cpp index 06c816a2ff5..7c5deccbdac 100644 --- a/src/emu/emuopts.cpp +++ b/src/emu/emuopts.cpp @@ -747,9 +747,9 @@ void emu_options::reevaluate_default_card_software() // retrieve info about the device instance auto &slot_opt(slot_option(slot.slot_name())); - // device_slot_interface::get_default_card_software() is essentially a hook - // that lets devices provide a feedback loop to force a specified software - // list entry to be loaded + // device_slot_interface::get_default_card_software() allows a device that + // implements both device_slot_interface and device_image_interface to + // probe an image and specify the card device that should be loaded // // In the repeated cycle of adding slots and slot devices, this gives a chance // for devices to "plug in" default software list items. Of course, the fact @@ -795,10 +795,10 @@ std::string emu_options::get_default_card_software(device_slot_interface &slot) util::hash_collection hashes = image->calculate_hash_on_file(file); return hashfile_extrainfo( - hash_path(), - image->device().mconfig().gamedrv(), - hashes, - extrainfo); + hash_path(), + image->device().mconfig().gamedrv(), + hashes, + extrainfo); }; } diff --git a/src/lib/util/coretmpl.h b/src/lib/util/coretmpl.h index 011fb28264b..8d317db7596 100644 --- a/src/lib/util/coretmpl.h +++ b/src/lib/util/coretmpl.h @@ -937,6 +937,51 @@ private: bool m_empty; }; + +template +using enable_enum_t = typename std::enable_if_t::value, typename std::underlying_type_t >; + +// template function which takes a strongly typed enumerator and returns its value as a compile-time constant +template +constexpr enable_enum_t underlying_value(E e) noexcept +{ + return static_cast >(e); +} + +// template function which takes an integral value and returns its representation as enumerator (even strongly typed) +template +constexpr typename std::enable_if_t::value && std::is_integral::value, E> enum_value(T value) noexcept +{ + return static_cast(value); +} + + +// useful functions to deal with bit shuffling +template constexpr T BIT(T x, U n) noexcept { return (x >> n) & T(1); } + +template constexpr T bitswap(T val, U b) noexcept { return BIT(val, b) << 0U; } + +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 +template T bitswap(T val, U... b) noexcept +{ + static_assert(sizeof...(b) == B, "wrong number of bits"); + static_assert((sizeof(std::remove_reference_t) * 8) >= B, "return type too small for result"); + return bitswap(val, b...); +} + + +// constexpr absolute value of an integer +template +constexpr std::enable_if_t::value, T> iabs(T v) noexcept +{ + return (v < T(0)) ? -v : v; +} + }; // namespace util #endif // MAME_UTIL_CORETMPL_H diff --git a/src/lib/util/disasmintf.h b/src/lib/util/disasmintf.h index 908bd762bdb..bf4022c5a01 100644 --- a/src/lib/util/disasmintf.h +++ b/src/lib/util/disasmintf.h @@ -16,10 +16,20 @@ #include "coretmpl.h" namespace util { + // class implementing a disassembler class disasm_interface { public: + // independence from emu.h + using u8 = osd::u8; + using u16 = osd::u16; + using u32 = osd::u32; + using u64 = osd::u64; + using s8 = osd::s8; + using s16 = osd::s16; + using s32 = osd::s32; + using s64 = osd::s64; using offs_t = u32; // Disassembler constants for the return value diff --git a/src/tools/unidasm.cpp b/src/tools/unidasm.cpp index 72c6f01d876..0c3779f01bc 100644 --- a/src/tools/unidasm.cpp +++ b/src/tools/unidasm.cpp @@ -8,9 +8,11 @@ ****************************************************************************/ -#include "emu.h" +// the disassemblers assume they're in MAME and emu.h is a PCH, so we minimally pander to them +#include "disasmintf.h" -#include +using offs_t = osd::u32; +using util::BIT; #include "cpu/8x300/8x300dasm.h" #include "cpu/adsp2100/2100dasm.h" @@ -147,10 +149,22 @@ #include "cpu/z80/z80dasm.h" #include "cpu/z8000/8000dasm.h" +#include "corefile.h" +#include "corestr.h" +#include "eminline.h" + #include #include +#include #include +#include + +using u8 = util::u8; +using u16 = util::u16; +using u32 = util::u32; +using u64 = util::u64; + // Configuration classes // Selected through dasm name