summaryrefslogtreecommitdiffstatshomepage
path: root/src/lib
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 /src/lib
parent397f54e29a8946041e7f09411f629094b6dff3e5 (diff)
move some not-directly-emulation-related helpers to lib/util, further extricate emu.h from tools (nw)
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/util/coretmpl.h45
-rw-r--r--src/lib/util/disasmintf.h10
2 files changed, 55 insertions, 0 deletions
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