From 6c1b85e1aa8b77dbea7fc21f3af165b1e9a5004b Mon Sep 17 00:00:00 2001 From: Fabio Priuli Date: Tue, 4 Jun 2013 10:31:49 +0000 Subject: [PATCH] (MESS) modernized DS1315 clock device. [Fabio Priuli] --- src/mess/machine/coco_fdc.c | 9 +- src/mess/machine/coco_fdc.h | 5 +- src/mess/machine/ds1315.c | 189 +++++++++++++----------------------- src/mess/machine/ds1315.h | 38 +++++--- 4 files changed, 99 insertions(+), 142 deletions(-) diff --git a/src/mess/machine/coco_fdc.c b/src/mess/machine/coco_fdc.c index 16e9bdcd877..3d64d214e3e 100644 --- a/src/mess/machine/coco_fdc.c +++ b/src/mess/machine/coco_fdc.c @@ -71,7 +71,6 @@ #include "imagedev/flopdrv.h" #include "includes/coco.h" #include "machine/wd17xx.h" -#include "machine/ds1315.h" #include "imagedev/flopdrv.h" #include "formats/coco_dsk.h" @@ -207,7 +206,7 @@ void coco_fdc_device::device_start() m_owner = dynamic_cast(owner()); m_drq = 1; m_disto_msm6242 = subdevice(DISTO_TAG); - m_ds1315 = subdevice(CLOUD9_TAG); + m_ds1315 = subdevice(CLOUD9_TAG); m_wd17xx = subdevice(WD_TAG); m_dskreg = 0x00; m_intrq = 0; @@ -359,17 +358,17 @@ READ8_MEMBER(coco_fdc_device::read) case 0x38: /* FF78 */ if (real_time_clock() == RTC_CLOUD9) - ds1315_r_0(m_ds1315, space, offset); + m_ds1315->read_0(space, offset); break; case 0x39: /* FF79 */ if (real_time_clock() == RTC_CLOUD9) - ds1315_r_1(m_ds1315, space, offset); + m_ds1315->read_1(space, offset); break; case 0x3C: /* FF7C */ if (real_time_clock() == RTC_CLOUD9) - result = ds1315_r_data(m_ds1315, space, offset); + result = m_ds1315->read_data(space, offset); break; } return result; diff --git a/src/mess/machine/coco_fdc.h b/src/mess/machine/coco_fdc.h index 7c37ac22679..9b980ba7cd4 100644 --- a/src/mess/machine/coco_fdc.h +++ b/src/mess/machine/coco_fdc.h @@ -6,6 +6,7 @@ #include "emu.h" #include "machine/cococart.h" #include "machine/msm6242.h" +#include "machine/ds1315.h" //************************************************************************** // TYPE DEFINITIONS @@ -58,8 +59,8 @@ protected: UINT8 m_drq : 1; UINT8 m_intrq : 1; - device_t *m_wd17xx; /* WD17xx */ - device_t *m_ds1315; /* DS1315 */ + device_t *m_wd17xx; /* WD17xx */ + ds1315_device *m_ds1315; /* DS1315 */ /* Disto RTC */ msm6242_device *m_disto_msm6242; /* 6242 RTC on Disto interface */ diff --git a/src/mess/machine/ds1315.c b/src/mess/machine/ds1315.c index afb6bddd88f..2a2a47c4e33 100644 --- a/src/mess/machine/ds1315.c +++ b/src/mess/machine/ds1315.c @@ -11,23 +11,43 @@ #include "ds1315.h" #include "coreutil.h" -/*************************************************************************** - TYPE DEFINITIONS -***************************************************************************/ -enum ds1315_mode_t +const device_type DS1315 = &device_creator; + +ds1315_device::ds1315_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock) + : device_t(mconfig, DS1315, "Dallas Semiconductor DS1315", tag, owner, clock) { - DS_SEEK_MATCHING, - DS_CALENDAR_IO -}; +} +//------------------------------------------------- +// device_config_complete - perform any +// operations now that the configuration is +// complete +//------------------------------------------------- -struct ds1315_t +void ds1315_device::device_config_complete() { - int count; - ds1315_mode_t mode; - UINT8 raw_data[8*8]; -}; +} + +//------------------------------------------------- +// device_start - device-specific startup +//------------------------------------------------- + +void ds1315_device::device_start() +{ +} + + +//------------------------------------------------- +// device_reset - device-specific reset +//------------------------------------------------- + +void ds1315_device::device_reset() +{ + memset(m_raw_data, 0, sizeof(m_raw_data)); + m_count = 0; + m_mode = DS_SEEK_MATCHING; +} /*************************************************************************** @@ -47,160 +67,117 @@ static const UINT8 ds1315_pattern[] = }; -/*************************************************************************** - PROTOTYPES -***************************************************************************/ - -static void ds1315_fill_raw_data(device_t *device); -static void ds1315_input_raw_data(device_t *device); - - - -/*************************************************************************** - INLINE FUNCTIONS -***************************************************************************/ - -INLINE ds1315_t *get_token(device_t *device) -{ - assert(device != NULL); - assert(device->type() == DS1315); - return (ds1315_t *) downcast(device)->token(); -} - - /*************************************************************************** IMPLEMENTATION ***************************************************************************/ /*------------------------------------------------- - DEVICE_START( ds1315 ) --------------------------------------------------*/ + read_0 + -------------------------------------------------*/ -static DEVICE_START(ds1315) +READ8_MEMBER( ds1315_device::read_0 ) { - ds1315_t *ds1315 = get_token(device); - - memset(ds1315, 0, sizeof(*ds1315)); - ds1315->count = 0; - ds1315->mode = DS_SEEK_MATCHING; -} - - -/*------------------------------------------------- - DEVICE_START( ds1315 ) --------------------------------------------------*/ - -READ8_DEVICE_HANDLER( ds1315_r_0 ) -{ - ds1315_t *ds1315 = get_token(device); - - if (ds1315_pattern[ds1315->count++] == 0) + if (ds1315_pattern[m_count++] == 0) { - if (ds1315->count == 64) + if (m_count == 64) { /* entire pattern matched */ - ds1315->count = 0; - ds1315->mode = DS_CALENDAR_IO; - ds1315_fill_raw_data(device); + m_count = 0; + m_mode = DS_CALENDAR_IO; + fill_raw_data(); } return 0; } - ds1315->count = 0; - ds1315->mode = DS_SEEK_MATCHING; + m_count = 0; + m_mode = DS_SEEK_MATCHING; return 0; } /*------------------------------------------------- - ds1315_r_1 + read_1 -------------------------------------------------*/ -READ8_DEVICE_HANDLER ( ds1315_r_1 ) +READ8_MEMBER( ds1315_device::read_1 ) { - ds1315_t *ds1315 = get_token(device); - - if (ds1315_pattern[ ds1315->count++ ] == 1) + if (ds1315_pattern[m_count++] == 1) { - ds1315->count %= 64; + m_count %= 64; return 0; } - ds1315->count = 0; - ds1315->mode = DS_SEEK_MATCHING; + m_count = 0; + m_mode = DS_SEEK_MATCHING; return 0; } /*------------------------------------------------- - ds1315_r_data + read_data -------------------------------------------------*/ -READ8_DEVICE_HANDLER ( ds1315_r_data ) +READ8_MEMBER( ds1315_device::read_data ) { UINT8 result; - ds1315_t *ds1315 = get_token(device); - if (ds1315->mode == DS_CALENDAR_IO) + if (m_mode == DS_CALENDAR_IO) { - result = ds1315->raw_data[ ds1315->count++ ]; + result = m_raw_data[m_count++]; - if (ds1315->count == 64) + if (m_count == 64) { - ds1315->mode = DS_SEEK_MATCHING; - ds1315->count = 0; + m_mode = DS_SEEK_MATCHING; + m_count = 0; } return result; } - ds1315->count = 0; + m_count = 0; return 0; } /*------------------------------------------------- - ds1315_w_data + write_data -------------------------------------------------*/ -WRITE8_DEVICE_HANDLER ( ds1315_w_data ) +WRITE8_MEMBER( ds1315_device::write_data ) { - ds1315_t *ds1315 = get_token(device); - - if (ds1315->mode == DS_CALENDAR_IO) + if (m_mode == DS_CALENDAR_IO) { - ds1315->raw_data[ds1315->count++] = data & 0x01; + m_raw_data[m_count++] = data & 0x01; - if (ds1315->count == 64) + if (m_count == 64) { - ds1315->mode = DS_SEEK_MATCHING; - ds1315->count = 0; - ds1315_input_raw_data(device); + m_mode = DS_SEEK_MATCHING; + m_count = 0; + input_raw_data(); } return; } - ds1315->count = 0; + m_count = 0; } /*------------------------------------------------- - ds1315_fill_raw_data + fill_raw_data -------------------------------------------------*/ -static void ds1315_fill_raw_data(device_t *device) +void ds1315_device::fill_raw_data() { /* This routine will (hopefully) call a standard 'C' library routine to get the current date and time and then fill in the raw data struct. */ system_time systime; - ds1315_t *ds1315 = get_token(device); int raw[8], i, j; /* get the current date/time from the core */ - device->machine().current_datetime(systime); + machine().current_datetime(systime); raw[0] = 0; /* tenths and hundreths of seconds are always zero */ raw[1] = dec_2_bcd(systime.local_time.second); @@ -217,7 +194,7 @@ static void ds1315_fill_raw_data(device_t *device) for (i = 0; i < 64; i++) { j = i / 8; - ds1315->raw_data[i] = (raw[j] & 0x0001); + m_raw_data[i] = (raw[j] & 0x0001); raw[j] = raw[j] >> 1; } } @@ -227,7 +204,7 @@ static void ds1315_fill_raw_data(device_t *device) ds1315_input_raw_data -------------------------------------------------*/ -static void ds1315_input_raw_data(device_t *device) +void ds1315_device::input_raw_data() { /* This routine is called when new date and time has been written to the clock chip. Currently we ignore setting the date and time in the clock @@ -238,29 +215,3 @@ static void ds1315_input_raw_data(device_t *device) } -const device_type DS1315 = &device_creator; - -ds1315_device::ds1315_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock) - : device_t(mconfig, DS1315, "Dallas Semiconductor DS1315", tag, owner, clock) -{ - m_token = global_alloc_clear(ds1315_t); -} - -//------------------------------------------------- -// device_config_complete - perform any -// operations now that the configuration is -// complete -//------------------------------------------------- - -void ds1315_device::device_config_complete() -{ -} - -//------------------------------------------------- -// device_start - device-specific startup -//------------------------------------------------- - -void ds1315_device::device_start() -{ - DEVICE_START_NAME( ds1315 )(this); -} diff --git a/src/mess/machine/ds1315.h b/src/mess/machine/ds1315.h index b516d74e2b9..92c6ee1bdf0 100644 --- a/src/mess/machine/ds1315.h +++ b/src/mess/machine/ds1315.h @@ -18,28 +18,43 @@ MACROS ***************************************************************************/ +enum ds1315_mode_t +{ + DS_SEEK_MATCHING, + DS_CALENDAR_IO +}; + + class ds1315_device : public device_t { public: ds1315_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock); - ~ds1315_device() { global_free(m_token); } + ~ds1315_device() {} + + DECLARE_READ8_MEMBER(read_0); + DECLARE_READ8_MEMBER(read_1); + DECLARE_READ8_MEMBER(read_data); + DECLARE_WRITE8_MEMBER(write_data); - // access to legacy token - void *token() const { assert(m_token != NULL); return m_token; } protected: // device-level overrides virtual void device_config_complete(); virtual void device_start(); + virtual void device_reset(); + private: // internal state - void *m_token; + + void fill_raw_data(); + void input_raw_data(); + + int m_count; + ds1315_mode_t m_mode; + UINT8 m_raw_data[8*8]; }; extern const device_type DS1315; - - - /*************************************************************************** DEVICE CONFIGURATION MACROS ***************************************************************************/ @@ -48,13 +63,4 @@ extern const device_type DS1315; MCFG_DEVICE_ADD(_tag, DS1315, 0) -/*************************************************************************** - FUNCTION PROTOTYPES -***************************************************************************/ - -DECLARE_READ8_DEVICE_HANDLER( ds1315_r_0 ); -DECLARE_READ8_DEVICE_HANDLER( ds1315_r_1 ); -DECLARE_READ8_DEVICE_HANDLER( ds1315_r_data ); -DECLARE_WRITE8_DEVICE_HANDLER( ds1315_w_data ); - #endif /* __DS1315_H__ */