Added DECLARE/DEFINE_TRIVIAL_DERIVED_DEVICE macros to simplify the

definition of devices that are based off of a parent device, but which
differ in name and a single parameter.

Added a UINT32 param to the device_config constructor to facilitate
the use of the new macros.
This commit is contained in:
Aaron Giles 2010-09-09 05:23:01 +00:00
parent 58f4f9025b
commit dbd3f07184
2 changed files with 36 additions and 2 deletions

View File

@ -285,7 +285,7 @@ bool device_config_interface::interface_validity_check(const game_driver &driver
// device configuration // device configuration
//------------------------------------------------- //-------------------------------------------------
device_config::device_config(const machine_config &mconfig, device_type type, const char *name, const char *tag, const device_config *owner, UINT32 clock) device_config::device_config(const machine_config &mconfig, device_type type, const char *name, const char *tag, const device_config *owner, UINT32 clock, UINT32 param)
: m_next(NULL), : m_next(NULL),
m_owner(const_cast<device_config *>(owner)), m_owner(const_cast<device_config *>(owner)),
m_interface_list(NULL), m_interface_list(NULL),

View File

@ -58,6 +58,40 @@
// shorthand for accessing devices by machine/type/tag // shorthand for accessing devices by machine/type/tag
#define devtag_reset(mach,tag) (mach)->device(tag)->reset() #define devtag_reset(mach,tag) (mach)->device(tag)->reset()
// often derived devices need only a different name and a simple parameter to differentiate them
// these are provided as macros because you can't pass string literals to templates, annoyingly enough
// use this to declare the existence of a derived device in the header file
#define DECLARE_TRIVIAL_DERIVED_DEVICE(_ConfigClass, _ConfigBase, _DeviceClass, _DeviceBase) \
typedef _DeviceBase _DeviceClass; \
class _ConfigClass; \
\
class _ConfigClass : public _ConfigBase \
{ \
protected: \
_ConfigClass(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock, UINT32 param = 0); \
\
public: \
static device_config *static_alloc_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock); \
virtual device_t *alloc_device(running_machine &machine) const; \
}; \
// use this macro to define the actual implementation in the source file
#define DEFINE_TRIVIAL_DERIVED_DEVICE(_ConfigClass, _ConfigBase, _DeviceClass, _DeviceBase, _Name, _Param) \
_ConfigClass::_ConfigClass(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock, UINT32 param) \
: _ConfigBase(mconfig, static_alloc_device_config, _Name, tag, owner, clock, param) \
{ \
} \
\
device_config *_ConfigClass::static_alloc_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock) \
{ \
return global_alloc(_ConfigClass(mconfig, tag, owner, clock, _Param)); \
} \
\
device_t *_ConfigClass::alloc_device(running_machine &machine) const \
{ \
return auto_alloc(&machine, _DeviceClass(machine, *this)); \
} \
//************************************************************************** //**************************************************************************
@ -218,7 +252,7 @@ class device_config
protected: protected:
// construction/destruction // construction/destruction
device_config(const machine_config &mconfig, device_type type, const char *name, const char *tag, const device_config *owner, UINT32 clock); device_config(const machine_config &mconfig, device_type type, const char *name, const char *tag, const device_config *owner, UINT32 clock, UINT32 param = 0);
virtual ~device_config(); virtual ~device_config();
public: public: