move some not-directly-emulation-related helpers to lib/util, further extricate emu.h from tools (nw)

This commit is contained in:
Vas Crabb 2018-04-01 19:10:26 +10:00
parent 397f54e29a
commit 2c340f490e
10 changed files with 108 additions and 77 deletions

View File

@ -382,7 +382,7 @@ void dsp16_device_base::device_reset()
void dsp16_device_base::execute_run() void dsp16_device_base::execute_run()
{ {
if (machine().debug_flags & DEBUG_FLAG_ENABLED) if (debugger_enabled())
{ {
while (m_core->icount_remaining()) while (m_core->icount_remaining())
{ {

View File

@ -28,6 +28,9 @@
#pragma once #pragma once
#include <unordered_map>
class mcs51_disassembler : public util::disasm_interface class mcs51_disassembler : public util::disasm_interface
{ {
public: public:

View File

@ -225,6 +225,7 @@ protected:
int standard_irq_callback(int irqline); int standard_irq_callback(int irqline);
// debugger hooks // debugger hooks
bool debugger_enabled() const { return bool(device().machine().debug_flags & DEBUG_FLAG_ENABLED); }
void debugger_instruction_hook(offs_t curpc) void debugger_instruction_hook(offs_t curpc)
{ {
if (device().machine().debug_flags & DEBUG_FLAG_CALL_HOOK) if (device().machine().debug_flags & DEBUG_FLAG_CALL_HOOK)

View File

@ -85,19 +85,19 @@ image_device_format::~image_device_format()
//------------------------------------------------- //-------------------------------------------------
device_image_interface::device_image_interface(const machine_config &mconfig, device_t &device) device_image_interface::device_image_interface(const machine_config &mconfig, device_t &device)
: device_interface(device, "image"), : device_interface(device, "image")
m_err(), , m_err()
m_file(), , m_file()
m_mame_file(), , m_mame_file()
m_software_part_ptr(nullptr), , m_software_part_ptr(nullptr)
m_supported(0), , m_supported(0)
m_readonly(false), , m_readonly(false)
m_created(false), , m_created(false)
m_create_format(0), , m_create_format(0)
m_create_args(nullptr), , m_create_args(nullptr)
m_user_loadable(true), , m_user_loadable(true)
m_is_loading(false), , m_is_loading(false)
m_is_reset_and_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 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 // 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);
} }

View File

@ -198,7 +198,7 @@ public:
u8 *get_software_region(const char *tag); u8 *get_software_region(const char *tag);
u32 get_software_region_length(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<u8> &ptr); bool load_software_region(const char *tag, optional_shared_ptr<u8> &ptr);
u32 crc(); u32 crc();

View File

@ -67,6 +67,14 @@ using osd::s16;
using osd::s32; using osd::s32;
using osd::s64; 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 * // genf is a generic function pointer; cast function pointers to this instead of void *
typedef void genf(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)) #define ENDIAN_VALUE_NE_NNE(endian,neval,nneval) (((endian) == ENDIANNESS_NATIVE) ? (neval) : (nneval))
// useful functions to deal with bit shuffling encryptions
template <typename T, typename U> constexpr T BIT(T x, U n) { return (x >> n) & T(1); }
template <typename T, typename U> constexpr T bitswap(T val, U b)
{
return BIT(val, b) << 0U;
}
template <typename T, typename U, typename... V> 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 <unsigned B, typename T, typename... U> T bitswap(T val, U... b)
{
static_assert(sizeof...(b) == B, "wrong number of bits");
static_assert((sizeof(std::remove_reference_t<T>) * 8) >= B, "return type too small for result");
return bitswap(val, b...);
}
//************************************************************************** //**************************************************************************
// EXCEPTION CLASSES // EXCEPTION CLASSES
//************************************************************************** //**************************************************************************
@ -343,25 +328,6 @@ inline Dest downcast(Source &src)
return static_cast<Dest>(src); return static_cast<Dest>(src);
} }
// template function which takes a strongly typed enumerator and returns its value as a compile-time constant
template <typename E>
using enable_enum_t = typename std::enable_if_t<std::is_enum<E>::value, typename std::underlying_type_t<E>>;
template <typename E>
constexpr inline enable_enum_t<E>
underlying_value(E e) noexcept
{
return static_cast< typename std::underlying_type<E>::type >( e );
}
// template function which takes an integral value and returns its representation as enumerator (even strongly typed)
template <typename E , typename T>
constexpr inline typename std::enable_if_t<std::is_enum<E>::value && std::is_integral<T>::value, E>
enum_value(T value) noexcept
{
return static_cast<E>(value);
}
//************************************************************************** //**************************************************************************
@ -422,12 +388,4 @@ inline u64 d2u(double d)
return u.vv; return u.vv;
} }
// constexpr absolute value of an integer
template <typename T>
constexpr std::enable_if_t<std::is_signed<T>::value, T> iabs(T v)
{
return (v < T(0)) ? -v : v;
}
#endif /* MAME_EMU_EMUCORE_H */ #endif /* MAME_EMU_EMUCORE_H */

View File

@ -747,9 +747,9 @@ void emu_options::reevaluate_default_card_software()
// retrieve info about the device instance // retrieve info about the device instance
auto &slot_opt(slot_option(slot.slot_name())); auto &slot_opt(slot_option(slot.slot_name()));
// device_slot_interface::get_default_card_software() is essentially a hook // device_slot_interface::get_default_card_software() allows a device that
// that lets devices provide a feedback loop to force a specified software // implements both device_slot_interface and device_image_interface to
// list entry to be loaded // 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 // 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 // for devices to "plug in" default software list items. Of course, the fact

View File

@ -937,6 +937,51 @@ private:
bool m_empty; bool m_empty;
}; };
template <typename E>
using enable_enum_t = typename std::enable_if_t<std::is_enum<E>::value, typename std::underlying_type_t<E> >;
// template function which takes a strongly typed enumerator and returns its value as a compile-time constant
template <typename E>
constexpr enable_enum_t<E> underlying_value(E e) noexcept
{
return static_cast<typename std::underlying_type_t<E> >(e);
}
// template function which takes an integral value and returns its representation as enumerator (even strongly typed)
template <typename E , typename T>
constexpr typename std::enable_if_t<std::is_enum<E>::value && std::is_integral<T>::value, E> enum_value(T value) noexcept
{
return static_cast<E>(value);
}
// useful functions to deal with bit shuffling
template <typename T, typename U> constexpr T BIT(T x, U n) noexcept { return (x >> n) & T(1); }
template <typename T, typename U> constexpr T bitswap(T val, U b) noexcept { return BIT(val, b) << 0U; }
template <typename T, typename U, typename... V> 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 <unsigned B, typename T, typename... U> T bitswap(T val, U... b) noexcept
{
static_assert(sizeof...(b) == B, "wrong number of bits");
static_assert((sizeof(std::remove_reference_t<T>) * 8) >= B, "return type too small for result");
return bitswap(val, b...);
}
// constexpr absolute value of an integer
template <typename T>
constexpr std::enable_if_t<std::is_signed<T>::value, T> iabs(T v) noexcept
{
return (v < T(0)) ? -v : v;
}
}; // namespace util }; // namespace util
#endif // MAME_UTIL_CORETMPL_H #endif // MAME_UTIL_CORETMPL_H

View File

@ -16,10 +16,20 @@
#include "coretmpl.h" #include "coretmpl.h"
namespace util { namespace util {
// class implementing a disassembler // class implementing a disassembler
class disasm_interface class disasm_interface
{ {
public: 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; using offs_t = u32;
// Disassembler constants for the return value // Disassembler constants for the return value

View File

@ -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 <ctype.h> using offs_t = osd::u32;
using util::BIT;
#include "cpu/8x300/8x300dasm.h" #include "cpu/8x300/8x300dasm.h"
#include "cpu/adsp2100/2100dasm.h" #include "cpu/adsp2100/2100dasm.h"
@ -147,10 +149,22 @@
#include "cpu/z80/z80dasm.h" #include "cpu/z80/z80dasm.h"
#include "cpu/z8000/8000dasm.h" #include "cpu/z8000/8000dasm.h"
#include "corefile.h"
#include "corestr.h"
#include "eminline.h"
#include <algorithm> #include <algorithm>
#include <cstring> #include <cstring>
#include <iostream>
#include <stdexcept> #include <stdexcept>
#include <ctype.h>
using u8 = util::u8;
using u16 = util::u16;
using u32 = util::u32;
using u64 = util::u64;
// Configuration classes // Configuration classes
// Selected through dasm name // Selected through dasm name