Switch to static_set_interface for setting the interface struct in a type-safe

manner.
This commit is contained in:
Aaron Giles 2011-05-03 19:42:31 +00:00
parent 1f5b4919e7
commit 8736e66684
2 changed files with 18 additions and 32 deletions

View File

@ -71,36 +71,19 @@ const device_type PTM6840 = &device_creator<ptm6840_device>;
ptm6840_device::ptm6840_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
: device_t(mconfig, PTM6840, "6840 PTM", tag, owner, clock)
{
memset(static_cast<ptm6840_interface *>(this), 0, sizeof(ptm6840_interface));
}
//-------------------------------------------------
// device_config_complete - perform any
// operations now that the configuration is
// complete
// static_set_interface - set the interface
// struct
//-------------------------------------------------
void ptm6840_device::device_config_complete()
void ptm6840_device::static_set_interface(device_t &device, const ptm6840_interface &interface)
{
// inherit a copy of the static data
const ptm6840_interface *intf = reinterpret_cast<const ptm6840_interface *>(static_config());
if (intf != NULL)
{
*static_cast<ptm6840_interface *>(this) = *intf;
}
// or initialize to defaults if none provided
else
{
m_internal_clock = 0.0;
m_external_clock[0] = 0.0;
m_external_clock[1] = 0.0;
m_external_clock[2] = 0.0;
memset(&m_irq_cb, 0, sizeof(m_irq_cb));
memset(&m_out_cb[0], 0, sizeof(m_out_cb[0]));
memset(&m_out_cb[1], 0, sizeof(m_out_cb[1]));
memset(&m_out_cb[2], 0, sizeof(m_out_cb[2]));
}
ptm6840_device &ptm = downcast<ptm6840_device &>(device);
static_cast<ptm6840_interface &>(ptm) = interface;
}

View File

@ -15,18 +15,19 @@
/***************************************************************************
DEVICE CONFIGURATION MACROS
***************************************************************************/
//**************************************************************************
// DEVICE CONFIGURATION MACROS
//**************************************************************************
#define MCFG_PTM6840_ADD(_tag, _config) \
#define MCFG_PTM6840_ADD(_tag, _interface) \
MCFG_DEVICE_ADD(_tag, PTM6840, 0) \
MCFG_DEVICE_CONFIG(_config)
ptm6840_device::static_set_interface(*device, _interface);
/***************************************************************************
TYPE DEFINITIONS
***************************************************************************/
//**************************************************************************
// TYPE DEFINITIONS
//**************************************************************************
// ======================> ptm6840_interface
@ -50,6 +51,9 @@ public:
// construction/destruction
ptm6840_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
// static configuration helpers
static void static_set_interface(device_t &device, const ptm6840_interface &interface);
int status(int clock) const; // get whether timer is enabled
int irq_state() const; // get IRQ state
UINT16 count(int counter) const; // get counter value
@ -75,7 +79,6 @@ public:
protected:
// device-level overrides
virtual void device_config_complete();
virtual void device_start();
virtual void device_reset();
virtual void device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr);