summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
author Vas Crabb <vas@vastheman.com>2018-04-01 19:10:26 +1000
committer Vas Crabb <vas@vastheman.com>2018-04-01 19:10:26 +1000
commit2c340f490e67efd1ba37312e40b30289c025488b (patch)
tree791cd5adb237d2fb3276d17be80e54fadbd308c9
parent397f54e29a8946041e7f09411f629094b6dff3e5 (diff)
move some not-directly-emulation-related helpers to lib/util, further extricate emu.h from tools (nw)
-rw-r--r--src/devices/cpu/dsp16/dsp16.cpp2
-rw-r--r--src/devices/cpu/mcs51/mcs51dasm.h3
-rw-r--r--src/emu/diexec.h1
-rw-r--r--src/emu/diimage.cpp32
-rw-r--r--src/emu/diimage.h2
-rw-r--r--src/emu/emucore.h58
-rw-r--r--src/emu/emuopts.cpp14
-rw-r--r--src/lib/util/coretmpl.h45
-rw-r--r--src/lib/util/disasmintf.h10
-rw-r--r--src/tools/unidasm.cpp18
10 files changed, 108 insertions, 77 deletions
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 <unordered_map>
+
+
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<u8> &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 <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
//**************************************************************************
@@ -343,25 +328,6 @@ inline Dest downcast(Source &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;
}
-
-// 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 */
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 <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
#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 <ctype.h>
+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 <algorithm>
#include <cstring>
+#include <iostream>
#include <stdexcept>
+#include <ctype.h>
+
+using u8 = util::u8;
+using u16 = util::u16;
+using u32 = util::u32;
+using u64 = util::u64;
+
// Configuration classes
// Selected through dasm name