From 919913f118760c0ca41ab63512bd5c106f6fd840 Mon Sep 17 00:00:00 2001 From: Aaron Giles Date: Wed, 27 Apr 2011 05:11:18 +0000 Subject: Collapsed device_config and device_t into one class. Updated all existing modern devices and the legacy wrappers to work in this environment. This in general greatly simplifies writing a modern device. [Aaron Giles] General notes: * some more cleanup probably needs to happen behind this change, but I needed to get it in before the next device modernization or import from MESS :) * new template function device_creator which automatically defines the static function that creates the device; use this instead of creating a static_alloc_device_config function * added device_stop() method which is called at around the time the previous device_t's destructor was called; if you auto_free anything, do it here because the machine is gone when the destructor is called * changed the static_set_* calls to pass a device_t & instead of a device_config * * for many devices, the static config structure member names over- lapped the device's names for devcb_* functions; in these cases the members in the interface were renamed to have a _cb suffix * changed the driver_enumerator to only cache 100 machine_configs because caching them all took a ton of memory; fortunately this implementation detail is completely hidden behind the driver_enumerator interface * got rid of the macros for creating derived classes; doing it manually is now clean enough that it isn't worth hiding the details in a macro --- src/emu/machine/com8116.c | 53 +++++++++++++++++------------------------------ 1 file changed, 19 insertions(+), 34 deletions(-) (limited to 'src/emu/machine/com8116.c') diff --git a/src/emu/machine/com8116.c b/src/emu/machine/com8116.c index 228dde9cf19..b4ab56e8ee7 100644 --- a/src/emu/machine/com8116.c +++ b/src/emu/machine/com8116.c @@ -22,19 +22,20 @@ //************************************************************************** -// GLOBAL VARIABLES +// LIVE DEVICE //************************************************************************** -// devices -const device_type COM8116 = com8116_device_config::static_alloc_device_config; - - +// device type definition +const device_type COM8116 = &device_creator; -//************************************************************************** -// DEVICE CONFIGURATION -//************************************************************************** +//------------------------------------------------- +// com8116_device - constructor +//------------------------------------------------- -GENERIC_DEVICE_CONFIG_SETUP(com8116, "COM8116") +com8116_device::com8116_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock) + : device_t(mconfig, COM8116, "COM8116", tag, owner, clock) +{ +} //------------------------------------------------- @@ -43,7 +44,7 @@ GENERIC_DEVICE_CONFIG_SETUP(com8116, "COM8116") // complete //------------------------------------------------- -void com8116_device_config::device_config_complete() +void com8116_device::device_config_complete() { // inherit a copy of the static data const com8116_interface *intf = reinterpret_cast(static_config()); @@ -53,29 +54,13 @@ void com8116_device_config::device_config_complete() // or initialize to defaults if none provided else { - memset(&m_out_fx4_func, 0, sizeof(m_out_fx4_func)); - memset(&m_out_fr_func, 0, sizeof(m_out_fr_func)); - memset(&m_out_ft_func, 0, sizeof(m_out_ft_func)); + memset(&m_out_fx4_cb, 0, sizeof(m_out_fx4_cb)); + memset(&m_out_fr_cb, 0, sizeof(m_out_fr_cb)); + memset(&m_out_ft_cb, 0, sizeof(m_out_ft_cb)); } } - -//************************************************************************** -// LIVE DEVICE -//************************************************************************** - -//------------------------------------------------- -// com8116_device - constructor -//------------------------------------------------- - -com8116_device::com8116_device(running_machine &_machine, const com8116_device_config &config) - : device_t(_machine, config), - m_config(config) -{ -} - - //------------------------------------------------- // device_start - device-specific startup //------------------------------------------------- @@ -83,9 +68,9 @@ com8116_device::com8116_device(running_machine &_machine, const com8116_device_c void com8116_device::device_start() { // resolve callbacks - devcb_resolve_write_line(&m_out_fx4_func, &m_config.m_out_fx4_func, this); - devcb_resolve_write_line(&m_out_fr_func, &m_config.m_out_fr_func, this); - devcb_resolve_write_line(&m_out_ft_func, &m_config.m_out_ft_func, this); + devcb_resolve_write_line(&m_out_fx4_func, &m_out_fx4_cb, this); + devcb_resolve_write_line(&m_out_fr_func, &m_out_fr_cb, this); + devcb_resolve_write_line(&m_out_ft_func, &m_out_ft_cb, this); // allocate timers m_fx4_timer = timer_alloc(TIMER_FX4); @@ -132,7 +117,7 @@ WRITE8_MEMBER( com8116_device::str_w ) m_fr = data & 0x0f; - m_fr_timer->adjust(attotime::zero, 0, attotime::from_hz(clock() / m_config.m_fr_divisors[m_fr] / 2)); + m_fr_timer->adjust(attotime::zero, 0, attotime::from_hz(clock() / m_fr_divisors[m_fr] / 2)); } @@ -146,5 +131,5 @@ WRITE8_MEMBER( com8116_device::stt_w ) m_ft = data & 0x0f; - m_ft_timer->adjust(attotime::zero, 0, attotime::from_hz(clock() / m_config.m_ft_divisors[m_ft] / 2)); + m_ft_timer->adjust(attotime::zero, 0, attotime::from_hz(clock() / m_ft_divisors[m_ft] / 2)); } -- cgit v1.2.3-70-g09d2