summaryrefslogtreecommitdiffstatshomepage
path: root/src/emu/device.h
diff options
context:
space:
mode:
author Vas Crabb <vas@vastheman.com>2017-05-07 23:18:47 +1000
committer Vas Crabb <vas@vastheman.com>2017-05-14 21:44:11 +1000
commit0f0d39ef81562c75e79176dd3bebb1e491ca39d5 (patch)
tree201cee7fdf55ee800f83859a92efd2cfe66cf2b3 /src/emu/device.h
parente6c4be2b4d71c7a6c95be0bae111eb416ff0f9e7 (diff)
Move static data out of devices into the device types. This is a significant change, so please pay attention.
The core changes are: * Short name, full name and source file are no longer members of device_t, they are part of the device type * MACHINE_COFIG_START no longer needs a driver class * MACHINE_CONFIG_DERIVED_CLASS is no longer necessary * Specify the state class you want in the GAME/COMP/CONS line * The compiler will work out the base class where the driver init member is declared * There is one static device type object per driver rather than one per machine configuration Use DECLARE_DEVICE_TYPE or DECLARE_DEVICE_TYPE_NS to declare device type. * DECLARE_DEVICE_TYPE forward-declares teh device type and class, and declares extern object finders. * DECLARE_DEVICE_TYPE_NS is for devices classes in namespaces - it doesn't forward-declare the device type. Use DEFINE_DEVICE_TYPE or DEFINE_DEVICE_TYPE_NS to define device types. * These macros declare storage for the static data, and instantiate the device type and device finder templates. The rest of the changes are mostly just moving stuff out of headers that shouldn't be there, renaming stuff for consistency, and scoping stuff down where appropriate. Things I've actually messed with substantially: * More descriptive names for a lot of devices * Untangled the fantasy sound from the driver state, which necessitates breaking up sound/flip writes * Changed DECO BSMT2000 ready callback into a device delegate * Untangled Microprose 3D noise from driver state * Used object finders for CoCo multipak, KC85 D002, and Irem sound subdevices * Started to get TI-99 stuff out of the TI-990 directory and arrange bus devices properly * Started to break out common parts of Samsung ARM SoC devices * Turned some of FM, SID, SCSP DSP, EPIC12 and Voodoo cores into something resmbling C++ * Tried to make Z180 table allocation/setup a bit safer * Converted generic keyboard/terminal to not use WRITE8 - space/offset aren't relevant * Dynamically allocate generic terminal buffer so derived devices (e.g. teleprinter) can specify size * Imporved encapsulation of Z80DART channels * Refactored the SPC7110 bit table generator loop to make it more readable * Added wrappers for SNES PPU operations so members can be made protected * Factored out some boilerplate for YM chips with PSG * toaplan2 gfx * stic/intv resolution * Video System video * Out Run/Y-board sprite alignment * GIC video hookup * Amstrad CPC ROM box members * IQ151 ROM cart region * MSX cart IRQ callback resolution time * SMS passthrough control devices starting subslots I've smoke-tested several drivers, but I've probably missed something. Things I've missed will likely blow up spectacularly with failure to bind errors and the like. Let me know if there's more subtle breakage (could have happened in FM or Voodoo). And can everyone please, please try to keep stuff clean. In particular, please stop polluting the global namespace. Keep things out of headers that don't need to be there, and use things that can be scoped down rather than macros. It feels like an uphill battle trying to get this stuff under control while more of it's added.
Diffstat (limited to 'src/emu/device.h')
-rw-r--r--src/emu/device.h127
1 files changed, 84 insertions, 43 deletions
diff --git a/src/emu/device.h b/src/emu/device.h
index b20a545dc46..0eec0db5845 100644
--- a/src/emu/device.h
+++ b/src/emu/device.h
@@ -20,6 +20,7 @@
#include <iterator>
#include <memory>
#include <string>
+#include <type_traits>
#include <typeinfo>
#include <unordered_map>
#include <vector>
@@ -141,59 +142,90 @@ private:
};
-template <class DeviceClass> struct device_tag_struct { typedef DeviceClass type; };
-template <class DriverClass> struct driver_tag_struct { typedef DriverClass type; };
+template <class DeviceClass, char const *ShortName, char const *FullName, char const *Source> struct device_tag_struct { typedef DeviceClass type; };
+template <class DriverClass, char const *ShortName, char const *FullName, char const *Source> struct driver_tag_struct { typedef DriverClass type; };
-template <class DeviceClass> inline device_tag_struct<DeviceClass> device_tag_func() { return device_tag_struct<DeviceClass>{ }; }
-template <class DriverClass> inline driver_tag_struct<DriverClass> driver_tag_func() { return driver_tag_struct<DriverClass>{ }; }
+template <class DeviceClass, char const *ShortName, char const *FullName, char const *Source> auto device_tag_func() { return device_tag_struct<DeviceClass, ShortName, FullName, Source>{ }; };
+template <class DriverClass, char const *ShortName, char const *FullName, char const *Source> auto driver_tag_func() { return driver_tag_struct<DriverClass, ShortName, FullName, Source>{ }; };
class device_type_impl
{
private:
friend class device_registrar;
- typedef std::unique_ptr<device_t> (*create_func)(machine_config const &mconfig, char const *tag, device_t *owner, u32 clock);
+ typedef std::unique_ptr<device_t> (*create_func)(device_type_impl const &type, machine_config const &mconfig, char const *tag, device_t *owner, u32 clock);
device_type_impl(device_type_impl const &) = delete;
device_type_impl(device_type_impl &&) = delete;
device_type_impl &operator=(device_type_impl const &) = delete;
device_type_impl &operator=(device_type_impl &&) = delete;
- // don't make these static member function templates inline
- template <typename DeviceClass> static std::unique_ptr<device_t> create_device(machine_config const &mconfig, char const *tag, device_t *owner, u32 clock);
- template <typename DriverClass> static std::unique_ptr<device_t> create_driver(machine_config const &mconfig, char const *tag, device_t *owner, u32 clock);
+ template <typename DeviceClass>
+ static std::unique_ptr<device_t> create_device(device_type_impl const &type, machine_config const &mconfig, char const *tag, device_t *owner, u32 clock)
+ {
+ return make_unique_clear<DeviceClass>(mconfig, tag, owner, clock);
+ }
+
+ template <typename DriverClass>
+ static std::unique_ptr<device_t> create_driver(device_type_impl const &type, machine_config const &mconfig, char const *tag, device_t *owner, u32 clock)
+ {
+ assert(!owner);
+ assert(!clock);
+
+ return make_unique_clear<DriverClass>(mconfig, type, tag);
+ }
create_func const m_creator;
std::type_info const &m_type;
+ char const *const m_shortname;
+ char const *const m_fullname;
+ char const *const m_source;
+
device_type_impl *m_next;
+ device_type_impl *m_parent = nullptr, *m_left = nullptr, *m_right = nullptr;
+ bool m_colour = false;
public:
device_type_impl(std::nullptr_t)
: m_creator(nullptr)
, m_type(typeid(std::nullptr_t))
+ , m_shortname(nullptr)
+ , m_fullname(nullptr)
+ , m_source(nullptr)
, m_next(nullptr)
{
}
- template <class DeviceClass> device_type_impl(device_tag_struct<DeviceClass> (*)())
+ template <class DeviceClass, char const *ShortName, char const *FullName, char const *Source>
+ device_type_impl(device_tag_struct<DeviceClass, ShortName, FullName, Source> (*)())
: m_creator(&create_device<DeviceClass>)
, m_type(typeid(DeviceClass))
+ , m_shortname(ShortName)
+ , m_fullname(FullName)
+ , m_source(Source)
, m_next(device_registrar::register_device(*this))
{
}
- template <class DriverClass> device_type_impl(driver_tag_struct<DriverClass> (*)())
+ template <class DriverClass, char const *ShortName, char const *FullName, char const *Source>
+ device_type_impl(driver_tag_struct<DriverClass, ShortName, FullName, Source> (*)())
: m_creator(&create_driver<DriverClass>)
, m_type(typeid(DriverClass))
+ , m_shortname(ShortName)
+ , m_fullname(FullName)
+ , m_source(Source)
, m_next(nullptr)
{
}
std::type_info const &type() const { return m_type; }
+ char const *shortname() const { return m_shortname; }
+ char const *fullname() const { return m_fullname; }
+ char const *source() const { return m_source; }
std::unique_ptr<device_t> operator()(machine_config const &mconfig, char const *tag, device_t *owner, u32 clock) const
{
- return m_creator(mconfig, tag, owner, clock);
+ return m_creator(*this, mconfig, tag, owner, clock);
}
explicit operator bool() const { return bool(m_creator); }
@@ -204,35 +236,49 @@ public:
inline device_registrar::const_iterator &device_registrar::const_iterator::operator++() { m_type = m_type->m_next; return *this; }
-
-template <typename DeviceClass>
-std::unique_ptr<device_t> device_type_impl::create_device(machine_config const &mconfig, char const *tag, device_t *owner, u32 clock)
-{
- return make_unique_clear<DeviceClass>(mconfig, tag, owner, clock);
-}
-
-template <typename DriverClass>
-std::unique_ptr<device_t> device_type_impl::create_driver(machine_config const &mconfig, char const *tag, device_t *owner, u32 clock)
-{
- assert(!owner);
- assert(!clock);
-
- // this is not thread-safe
- // we can get away with it because driver creators aren't registered
- // hence all members are initialised with constant values and the race won't cause issues
- static device_type_impl const &driver_type = &driver_tag_func<DriverClass>;
- return make_unique_clear<DriverClass>(mconfig, driver_type, tag);
-}
-
} } // namespace emu::detail
// device types
typedef emu::detail::device_type_impl const &device_type;
-template <class DeviceClass> constexpr auto device_creator = &emu::detail::device_tag_func<DeviceClass>;
-template <class DriverClass> constexpr auto driver_device_creator = &emu::detail::driver_tag_func<DriverClass>;
+typedef std::add_pointer_t<device_type> device_type_ptr;
extern emu::detail::device_registrar const registered_device_types;
+template <typename DeviceClass, char const *ShortName, char const *FullName, char const *Source>
+constexpr auto device_creator = &emu::detail::device_tag_func<DeviceClass, ShortName, FullName, Source>;
+
+template <typename DriverClass, char const *ShortName, char const *FullName, char const *Source>
+constexpr auto driver_device_creator = &emu::detail::driver_tag_func<DriverClass, ShortName, FullName, Source>;
+
+#define DECLARE_DEVICE_TYPE(Type, Class) \
+ extern device_type const Type; \
+ class Class; \
+ extern template class device_finder<Class, false>; \
+ extern template class device_finder<Class, true>;
+
+#define DECLARE_DEVICE_TYPE_NS(Type, Namespace, Class) \
+ extern device_type const Type; \
+ extern template class device_finder<Namespace::Class, false>; \
+ extern template class device_finder<Namespace::Class, true>;
+
+#define DEFINE_DEVICE_TYPE(Type, Class, ShortName, FullName) \
+ namespace { \
+ struct Class##_device_traits { static constexpr char const shortname[] = ShortName, fullname[] = FullName, source[] = __FILE__; }; \
+ constexpr char const Class##_device_traits::shortname[], Class##_device_traits::fullname[], Class##_device_traits::source[]; \
+ } \
+ device_type const Type = device_creator<Class, (Class##_device_traits::shortname), (Class##_device_traits::fullname), (Class##_device_traits::source)>; \
+ template class device_finder<Class, false>; \
+ template class device_finder<Class, true>;
+
+#define DEFINE_DEVICE_TYPE_NS(Type, Namespace, Class, ShortName, FullName) \
+ namespace { \
+ struct Class##_device_traits { static constexpr char const shortname[] = ShortName, fullname[] = FullName, source[] = __FILE__; }; \
+ constexpr char const Class##_device_traits::shortname[], Class##_device_traits::fullname[], Class##_device_traits::source[]; \
+ } \
+ device_type const Type = device_creator<Namespace::Class, (Class##_device_traits::shortname), (Class##_device_traits::fullname), (Class##_device_traits::source)>; \
+ template class device_finder<Namespace::Class, false>; \
+ template class device_finder<Namespace::Class, true>;
+
// exception classes
class device_missing_dependencies : public emu_exception { };
@@ -343,12 +389,10 @@ protected:
device_t(
const machine_config &mconfig,
device_type type,
- const char *name,
const char *tag,
device_t *owner,
- u32 clock,
- const char *shortname,
- const char *source);
+ u32 clock);
+
public:
virtual ~device_t();
@@ -358,10 +402,10 @@ public:
const char *tag() const { return m_tag.c_str(); }
const char *basetag() const { return m_basetag.c_str(); }
device_type type() const { return m_type; }
- const char *name() const { return m_name.c_str(); }
- const char *shortname() const { return m_shortname.c_str(); }
+ 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(); }
- const char *source() const { return m_source.c_str(); }
+ const char *source() const { return m_type.source(); }
device_t *owner() const { return m_owner; }
device_t *next() const { return m_next; }
u32 configured_clock() const { return m_configured_clock; }
@@ -488,10 +532,7 @@ protected:
// core device properties
device_type m_type; // device type
- std::string m_name; // name of the device
- std::string m_shortname; // short name of the device
std::string m_searchpath; // search path, used for media loading
- std::string m_source; // device source file name
// device relationships & interfaces
device_t * m_owner; // device that owns us