diff options
| author | 2010-07-17 13:53:22 +0000 | |
|---|---|---|
| committer | 2010-07-17 13:53:22 +0000 | |
| commit | 220497769e945ddeeafca68eecdf13bc020d7835 (patch) | |
| tree | c128fe17616bf644bd68a4ecf57101f74d46d562 /src | |
| parent | 76c8372f256a5d8f907e4ad24694bd617f03d372 (diff) | |
converted mb3773 from a legacy device to a c++ device.
tidied up comments in at28c16
Diffstat (limited to 'src')
| -rw-r--r-- | src/emu/machine/mb3773.c | 176 | ||||
| -rw-r--r-- | src/emu/machine/mb3773.h | 78 | ||||
| -rw-r--r-- | src/mame/drivers/taitogn.c | 2 | ||||
| -rw-r--r-- | src/mame/drivers/zn.c | 2 |
4 files changed, 176 insertions, 82 deletions
diff --git a/src/emu/machine/mb3773.c b/src/emu/machine/mb3773.c index 287679430a2..41ece3de1ba 100644 --- a/src/emu/machine/mb3773.c +++ b/src/emu/machine/mb3773.c @@ -8,110 +8,150 @@ Todo: Calculate the timeout from parameters. - - 2009-06 Converted to be a device - ***************************************************************************/ #include "emu.h" #include "mb3773.h" -/*************************************************************************** - TYPE DEFINITIONS -***************************************************************************/ -typedef struct _mb3773_state mb3773_state; -struct _mb3773_state + +//************************************************************************** +// DEVICE CONFIGURATION +//************************************************************************** + +//------------------------------------------------- +// mb3773_device_config - constructor +//------------------------------------------------- + +mb3773_device_config::mb3773_device_config( const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock ) : + device_config( mconfig, static_alloc_device_config, "MB3773", tag, owner, clock) { - emu_timer *watchdog_timer; - UINT8 ck; -}; +} -/*************************************************************************** - INLINE FUNCTIONS -***************************************************************************/ -INLINE mb3773_state *get_safe_token(running_device *device) + +//------------------------------------------------- +// static_alloc_device_config - allocate a new +// configuration object +//------------------------------------------------- + +device_config *mb3773_device_config::static_alloc_device_config( const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock ) { - assert(device != NULL); - assert((device->type() == MB3773)); - return (mb3773_state *)downcast<legacy_device_base *>(device)->token(); + return global_alloc( mb3773_device_config( mconfig, tag, owner, clock ) ); } -/*************************************************************************** - IMPLEMENTATION -***************************************************************************/ -/*------------------------------------------------- - TIMER_CALLBACK( watchdog_timeout ) --------------------------------------------------*/ -static TIMER_CALLBACK( watchdog_timeout ) +//------------------------------------------------- +// alloc_device - allocate a new device object +//------------------------------------------------- + +device_t *mb3773_device_config::alloc_device( running_machine &machine ) const { - machine->schedule_soft_reset(); + return auto_alloc( &machine, mb3773_device( machine, *this ) ); } -/*------------------------------------------------- - reset_timer --------------------------------------------------*/ -static void reset_timer( running_device *device ) + +//------------------------------------------------- +// device_config_complete - perform any +// operations now that the configuration is +// complete +//------------------------------------------------- + +void mb3773_device_config::device_config_complete() { - mb3773_state *mb3773 = get_safe_token(device); - timer_adjust_oneshot(mb3773->watchdog_timer, ATTOTIME_IN_SEC( 5 ), 0); } -/*------------------------------------------------- - mb3773_set_ck --------------------------------------------------*/ -WRITE8_DEVICE_HANDLER( mb3773_set_ck ) +//------------------------------------------------- +// device_validity_check - perform validity checks +// on this device +//------------------------------------------------- + +bool mb3773_device_config::device_validity_check( const game_driver &driver ) const +{ + return false; +} + + + + +//************************************************************************** +// LIVE DEVICE +//************************************************************************** + +//------------------------------------------------- +// mb3773_device - constructor +//------------------------------------------------- + +mb3773_device::mb3773_device( running_machine &_machine, const mb3773_device_config &config ) : + device_t( _machine, config ), + m_config( config ) { - mb3773_state *mb3773 = get_safe_token(device); - if( data == 0 && mb3773->ck != 0 ) - { - reset_timer(device); - } - mb3773->ck = data; } -/*------------------------------------------------- - DEVICE_START( mb3773 ) --------------------------------------------------*/ -static DEVICE_START( mb3773 ) +//------------------------------------------------- +// device_start - device-specific startup +//------------------------------------------------- + +void mb3773_device::device_start() { - mb3773_state *mb3773 = get_safe_token(device); + m_watchdog_timer = timer_alloc( &m_machine, watchdog_timeout, this ); + reset_timer(); + + state_save_register_device_item( this, 0, m_ck ); +} + - /* create the timer */ - mb3773->watchdog_timer = timer_alloc(device->machine, watchdog_timeout, NULL); - reset_timer(device); +//------------------------------------------------- +// device_reset - device-specific reset +//------------------------------------------------- - /* register for state saving */ - state_save_register_device_item(device, 0, mb3773->ck); +void mb3773_device::device_reset() +{ + m_ck = 0; } -/*------------------------------------------------- - DEVICE_RESET( mb3773 ) --------------------------------------------------*/ -static DEVICE_RESET( mb3773 ) + +//************************************************************************** +// READ/WRITE HANDLERS +//************************************************************************** + +WRITE_LINE_DEVICE_HANDLER( mb3773_set_ck ) +{ + downcast<mb3773_device *>( device )->set_ck( state ); +} + +void mb3773_device::set_ck( int state ) { - mb3773_state *mb3773 = get_safe_token(device); - mb3773->ck = 0; + state &= 1; + + if( state == 0 && m_ck != 0 ) + { + reset_timer(); + } + + m_ck = state; } -/*------------------------------------------------- - DEVICE_GET_INFO( mb3773 ) --------------------------------------------------*/ -static const char DEVTEMPLATE_SOURCE[] = __FILE__; +//************************************************************************** +// INTERNAL HELPERS +//************************************************************************** + +void mb3773_device::reset_timer() +{ + timer_adjust_oneshot( m_watchdog_timer, ATTOTIME_IN_SEC( 5 ), 0 ); +} + +TIMER_CALLBACK( mb3773_device::watchdog_timeout ) +{ + reinterpret_cast<mb3773_device *>(ptr)->m_machine.schedule_soft_reset(); +} -#define DEVTEMPLATE_ID(p,s) p##mb3773##s -#define DEVTEMPLATE_FEATURES DT_HAS_START | DT_HAS_RESET -#define DEVTEMPLATE_NAME "Fujistu MB3773" -#define DEVTEMPLATE_FAMILY "Fujistu Power Supply Monitor" -#include "devtempl.h" -DEFINE_LEGACY_DEVICE(MB3773, mb3773); +const device_type MB3773 = mb3773_device_config::static_alloc_device_config; diff --git a/src/emu/machine/mb3773.h b/src/emu/machine/mb3773.h index a856530b9f7..c1617aa4eae 100644 --- a/src/emu/machine/mb3773.h +++ b/src/emu/machine/mb3773.h @@ -6,26 +6,80 @@ ***************************************************************************/ +#pragma once + #ifndef __MB3773_H__ #define __MB3773_H__ -#include "devlegcy.h" - - -/*************************************************************************** - MACROS / CONSTANTS -***************************************************************************/ -DECLARE_LEGACY_DEVICE(MB3773, mb3773); +//************************************************************************** +// INTERFACE CONFIGURATION MACROS +//************************************************************************** #define MDRV_MB3773_ADD(_tag) \ MDRV_DEVICE_ADD(_tag, MB3773, 0) -/*************************************************************************** - PROTOTYPES -***************************************************************************/ +// ======================> mb3773_device_config + +class mb3773_device_config : + public device_config +{ + friend class mb3773_device; + + // construction/destruction + mb3773_device_config( const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock ); + +public: + // allocators + 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; + +protected: + // device_config overrides + virtual void device_config_complete(); + virtual bool device_validity_check( const game_driver &driver ) const; +}; + + +// ======================> mb3773_device + +class mb3773_device : + public device_t +{ + friend class mb3773_device_config; + + // construction/destruction + mb3773_device( running_machine &_machine, const mb3773_device_config &config ); + +public: + // I/O operations + void set_ck( int state ); + +protected: + // device-level overrides + virtual void device_start(); + virtual void device_reset(); + + // internal helpers + static TIMER_CALLBACK( watchdog_timeout ); + void reset_timer(); + + // internal state + const mb3773_device_config &m_config; + emu_timer *m_watchdog_timer; + int m_ck; +}; + + +// device type definition +extern const device_type MB3773; + + +//************************************************************************** +// READ/WRITE HANDLERS +//************************************************************************** -extern WRITE8_DEVICE_HANDLER( mb3773_set_ck ); +WRITE_LINE_DEVICE_HANDLER( mb3773_set_ck ); -#endif /* __MB3773_H__ */ +#endif diff --git a/src/mame/drivers/taitogn.c b/src/mame/drivers/taitogn.c index 5288435ff58..578789b2a72 100644 --- a/src/mame/drivers/taitogn.c +++ b/src/mame/drivers/taitogn.c @@ -552,7 +552,7 @@ static WRITE32_HANDLER(control_w) COMBINE_DATA(&control); - mb3773_set_ck(mb3773, 0, (control & 0x20) >> 5); + mb3773_set_ck(mb3773, (control & 0x20) >> 5); #if 0 if((p ^ control) & ~0x20) diff --git a/src/mame/drivers/zn.c b/src/mame/drivers/zn.c index b79ad2aa366..99d611070cf 100644 --- a/src/mame/drivers/zn.c +++ b/src/mame/drivers/zn.c @@ -1157,7 +1157,7 @@ static UINT8 *taitofx1_eeprom2 = NULL; static WRITE32_HANDLER( bank_coh1000t_w ) { running_device *mb3773 = space->machine->device("mb3773"); - mb3773_set_ck(mb3773, 0, (data & 0x20) >> 5); + mb3773_set_ck(mb3773, (data & 0x20) >> 5); verboselog( space->machine, 1, "bank_coh1000t_w( %08x, %08x, %08x )\n", offset, data, mem_mask ); memory_set_bankptr(space->machine, "bank1", memory_region( space->machine, "user2" ) + ( ( data & 3 ) * 0x800000 ) ); } |
