diff options
author | Angelo Salese <angelosa@users.noreply.github.com> | 2011-12-19 14:43:23 +0000 |
---|---|---|
committer | Angelo Salese <angelosa@users.noreply.github.com> | 2011-12-19 14:43:23 +0000 |
commit | d3a97c7d2e49fb810ec2df7ce938ba178c285608 (patch) | |
tree | 34931cf53c2a6499b25ba6080c6fdc686964c2cc /src/emu/machine/msm6242.c | |
parent | 8683ea6d017f043c85c547ab046e3fa93cbb9368 (diff) |
Modernized MSM6242 RTC device [Angelo Salese]
Diffstat (limited to 'src/emu/machine/msm6242.c')
-rw-r--r-- | src/emu/machine/msm6242.c | 150 |
1 files changed, 69 insertions, 81 deletions
diff --git a/src/emu/machine/msm6242.c b/src/emu/machine/msm6242.c index 8ba28098905..a3ad9541f31 100644 --- a/src/emu/machine/msm6242.c +++ b/src/emu/machine/msm6242.c @@ -28,37 +28,76 @@ enum MSM6242_REG_CF }; +//************************************************************************** +// GLOBAL VARIABLES +//************************************************************************** -typedef struct _msm6242_t msm6242_t; -struct _msm6242_t +// device type definition +const device_type msm6242 = &device_creator<msm6242_device>; + + +//************************************************************************** +// LIVE DEVICE +//************************************************************************** + +//------------------------------------------------- +// xxx_device - constructor +//------------------------------------------------- + +msm6242_device::msm6242_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock) + : device_t(mconfig, msm6242, "msm6242", tag, owner, clock) { - UINT8 reg[3]; - system_time hold_time; -}; +} + + +//------------------------------------------------- +// device_validity_check - perform validity checks +// on this device +//------------------------------------------------- + +bool msm6242_device::device_validity_check(emu_options &options, const game_driver &driver) const +{ + bool error = false; + return error; +} + +//------------------------------------------------- +// device_start - device-specific startup +//------------------------------------------------- -/* makes sure that the passed in device is the right type */ -INLINE msm6242_t *get_safe_token(device_t *device) +void msm6242_device::device_start() { - assert(device != NULL); - assert(device->type() == MSM6242); + reg[0] = 0; + reg[1] = 0; + reg[2] = 0; + memset(&hold_time, 0, sizeof(system_time)); +} + - return (msm6242_t *)downcast<legacy_device_base *>(device)->token(); +//------------------------------------------------- +// device_reset - device-specific reset +//------------------------------------------------- + +void msm6242_device::device_reset() +{ } +//************************************************************************** +// READ/WRITE HANDLERS +//************************************************************************** -READ8_DEVICE_HANDLER( msm6242_r ) +READ8_MEMBER( msm6242_device::read ) { system_time curtime, *systime = &curtime; - msm6242_t *msm6242 = get_safe_token(device); - if (msm6242->reg[0] & 1) /* if HOLD is set, use the hold time */ + if (reg[0] & 1) /* if HOLD is set, use the hold time */ { - systime = &msm6242->hold_time; + systime = &hold_time; } else /* otherwise, use the current time */ { - device->machine().current_datetime(curtime); + machine().current_datetime(curtime); } switch(offset) @@ -74,7 +113,7 @@ READ8_DEVICE_HANDLER( msm6242_r ) int pm = 0; /* check for 12/24 hour mode */ - if ((msm6242->reg[2] & 0x04) == 0) /* 12 hour mode? */ + if ((reg[2] & 0x04) == 0) /* 12 hour mode? */ { if (hour >= 12) pm = 1; @@ -98,107 +137,56 @@ READ8_DEVICE_HANDLER( msm6242_r ) case MSM6242_REG_Y1: return systime->local_time.year % 10; case MSM6242_REG_Y10: return (systime->local_time.year % 100) / 10; case MSM6242_REG_W: return systime->local_time.weekday; - case MSM6242_REG_CD: return msm6242->reg[0]; - case MSM6242_REG_CE: return msm6242->reg[1]; - case MSM6242_REG_CF: return msm6242->reg[2]; + case MSM6242_REG_CD: return reg[0]; + case MSM6242_REG_CE: return reg[1]; + case MSM6242_REG_CF: return reg[2]; } - logerror("%s: MSM6242 unmapped offset %02x read\n", device->machine().describe_context(), offset); + logerror("%s: MSM6242 unmapped offset %02x read\n", machine().describe_context(), offset); return 0; } - -WRITE8_DEVICE_HANDLER( msm6242_w ) +WRITE8_MEMBER( msm6242_device::write ) { - msm6242_t *msm6242 = get_safe_token(device); - switch(offset) { case MSM6242_REG_CD: { - msm6242->reg[0] = data & 0x0f; + reg[0] = data & 0x0f; if (data & 1) /* was Hold set? */ { - device->machine().current_datetime(msm6242->hold_time); + machine().current_datetime(hold_time); } return; } - case MSM6242_REG_CE: msm6242->reg[1] = data & 0x0f; return; + case MSM6242_REG_CE: reg[1] = data & 0x0f; return; case MSM6242_REG_CF: { /* the 12/24 mode bit can only be changed while REST is 1 */ - if ((data ^ msm6242->reg[2]) & 0x04) + if ((data ^ reg[2]) & 0x04) { - msm6242->reg[2] = (msm6242->reg[2] & 0x04) | (data & ~0x04); + reg[2] = (reg[2] & 0x04) | (data & ~0x04); - if (msm6242->reg[2] & 1) - msm6242->reg[2] = (msm6242->reg[2] & ~0x04) | (data & 0x04); + if (reg[2] & 1) + reg[2] = (reg[2] & ~0x04) | (data & 0x04); } else { - msm6242->reg[2] = data & 0x0f; + reg[2] = data & 0x0f; } return; } } - logerror("%s: MSM6242 unmapped offset %02x written with %02x\n", device->machine().describe_context(), offset, data); + logerror("%s: MSM6242 unmapped offset %02x written with %02x\n", machine().describe_context(), offset, data); } -static DEVICE_START( msm6242 ) -{ - msm6242_t *msm6242 = get_safe_token(device); - - msm6242->reg[0] = 0; - msm6242->reg[1] = 0; - msm6242->reg[2] = 0; - memset(&msm6242->hold_time, 0, sizeof(system_time)); -} - - -DEVICE_GET_INFO( msm6242 ) -{ - switch (state) - { - /* --- the following bits of info are returned as 64-bit signed integers --- */ - case DEVINFO_INT_TOKEN_BYTES: info->i = sizeof(msm6242_t); break; - case DEVINFO_INT_INLINE_CONFIG_BYTES: info->i = 0; break; - - /* --- the following bits of info are returned as pointers to data or functions --- */ - case DEVINFO_FCT_START: info->start = DEVICE_START_NAME(msm6242); break; - case DEVINFO_FCT_STOP: /* Nothing */ break; - case DEVINFO_FCT_RESET: /* Nothing */ break; - - /* --- the following bits of info are returned as NULL-terminated strings --- */ - case DEVINFO_STR_NAME: strcpy(info->s, "OKI MSM6242"); break; - case DEVINFO_STR_FAMILY: strcpy(info->s, "MSM6242 RTC"); break; - case DEVINFO_STR_VERSION: strcpy(info->s, "1.00"); break; - case DEVINFO_STR_SOURCE_FILE: strcpy(info->s, __FILE__); break; - case DEVINFO_STR_CREDITS: strcpy(info->s, "Copyright Nicola Salmoria and the MAME Team"); break; - } -} - -#if 0 -READ16_HANDLER( msm6242_lsb_r ) -{ - return msm6242_r(space, offset); -} - -WRITE16_HANDLER( msm6242_lsb_w ) -{ - if (ACCESSING_BITS_0_7) - msm6242_w(space, offset, data); -} -#endif - - -DEFINE_LEGACY_DEVICE(MSM6242, msm6242); |