From 3c4c946e666f71db6f105aede69871219246fa48 Mon Sep 17 00:00:00 2001 From: Angelo Salese Date: Tue, 22 Nov 2011 22:41:02 +0000 Subject: [PATCH] svn add the files ... --- .gitattributes | 2 + src/emu/machine/v3021.c | 190 ++++++++++++++++++++++++++++++++++++++++ src/emu/machine/v3021.h | 77 ++++++++++++++++ 3 files changed, 269 insertions(+) create mode 100644 src/emu/machine/v3021.c create mode 100644 src/emu/machine/v3021.h diff --git a/.gitattributes b/.gitattributes index 443c3c59b8b..b99916facae 100644 --- a/.gitattributes +++ b/.gitattributes @@ -974,6 +974,8 @@ src/emu/machine/upd4701.c svneol=native#text/plain src/emu/machine/upd4701.h svneol=native#text/plain src/emu/machine/upd7201.c svneol=native#text/plain src/emu/machine/upd7201.h svneol=native#text/plain +src/emu/machine/v3021.c svneol=native#text/plain +src/emu/machine/v3021.h svneol=native#text/plain src/emu/machine/wd17xx.c svneol=native#text/plain src/emu/machine/wd17xx.h svneol=native#text/plain src/emu/machine/wd33c93.c svneol=native#text/plain diff --git a/src/emu/machine/v3021.c b/src/emu/machine/v3021.c new file mode 100644 index 00000000000..9ab6c2b05e7 --- /dev/null +++ b/src/emu/machine/v3021.c @@ -0,0 +1,190 @@ +/*************************************************************************** + + v3021.c + + EM Microelectronic-Marin SA Ultra Low Power 32kHz CMOS RTC (DIP8) + + Serial Real Time Clock + + - very preliminary, borrowed from hard-coded PGM implementation. + +***************************************************************************/ + +#include "emu.h" +#include "machine/v3021.h" + + + +//************************************************************************** +// GLOBAL VARIABLES +//************************************************************************** + +// device type definition +const device_type v3021 = &device_creator; + + +//************************************************************************** +// LIVE DEVICE +//************************************************************************** + +//------------------------------------------------- +// rtc9701_device - constructor +//------------------------------------------------- + +v3021_device::v3021_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock) + : device_t(mconfig, v3021, "v3021", tag, owner, clock) +{ + +} + +void v3021_device::timer_callback() +{ + static const UINT8 dpm[12] = { 0x31, 0x28, 0x31, 0x30, 0x31, 0x30, 0x31, 0x31, 0x30, 0x31, 0x30, 0x31 }; + int dpm_count; + + m_rtc.sec++; + + if((m_rtc.sec & 0x0f) >= 0x0a) { m_rtc.sec+=0x10; m_rtc.sec&=0xf0; } + if((m_rtc.sec & 0xf0) >= 0x60) { m_rtc.min++; m_rtc.sec = 0; } + if((m_rtc.min & 0x0f) >= 0x0a) { m_rtc.min+=0x10; m_rtc.min&=0xf0; } + if((m_rtc.min & 0xf0) >= 0x60) { m_rtc.hour++; m_rtc.min = 0; } + if((m_rtc.hour & 0x0f) >= 0x0a) { m_rtc.hour+=0x10; m_rtc.hour&=0xf0; } + if((m_rtc.hour & 0xff) >= 0x24) { m_rtc.day++; m_rtc.wday<<=1; m_rtc.hour = 0; } + if(m_rtc.wday & 0x80) { m_rtc.wday = 1; } + if((m_rtc.day & 0x0f) >= 0x0a) { m_rtc.day+=0x10; m_rtc.day&=0xf0; } + + /* TODO: crude leap year support */ + dpm_count = (m_rtc.month & 0xf) + (((m_rtc.month & 0x10) >> 4)*10)-1; + + if(((m_rtc.year % 4) == 0) && m_rtc.month == 2) + { + if((m_rtc.day & 0xff) >= dpm[dpm_count]+1+1) + { m_rtc.month++; m_rtc.day = 0x01; } + } + else if((m_rtc.day & 0xff) >= dpm[dpm_count]+1){ m_rtc.month++; m_rtc.day = 0x01; } + if((m_rtc.month & 0x0f) >= 0x0a) { m_rtc.month = 0x10; } + if(m_rtc.month >= 0x13) { m_rtc.year++; m_rtc.month = 1; } + if((m_rtc.year & 0x0f) >= 0x0a) { m_rtc.year+=0x10; m_rtc.year&=0xf0; } + if((m_rtc.year & 0xf0) >= 0xa0) { m_rtc.year = 0; } //2000-2099 possible timeframe +} + +TIMER_CALLBACK( v3021_device::rtc_inc_callback ) +{ + reinterpret_cast(ptr)->timer_callback(); +} + +//------------------------------------------------- +// device_validity_check - perform validity checks +// on this device +//------------------------------------------------- + +bool v3021_device::device_validity_check(emu_options &options, const game_driver &driver) const +{ + bool error = false; + return error; +} + +//------------------------------------------------- +// device_start - device-specific startup +//------------------------------------------------- + +void v3021_device::device_start() +{ + /* let's call the timer callback every second */ + if(clock() >= XTAL_32_768kHz) + machine().scheduler().timer_pulse(attotime::from_hz(clock() / XTAL_32_768kHz), FUNC(rtc_inc_callback), 0, (void *)this); + + system_time systime; + machine().base_datetime(systime); + + m_rtc.day = ((systime.local_time.mday / 10)<<4) | ((systime.local_time.mday % 10) & 0xf); + m_rtc.month = (((systime.local_time.month+1) / 10) << 4) | (((systime.local_time.month+1) % 10) & 0xf); + m_rtc.wday = 1 << systime.local_time.weekday; + m_rtc.year = (((systime.local_time.year % 100)/10)<<4) | ((systime.local_time.year % 10) & 0xf); + m_rtc.hour = ((systime.local_time.hour / 10)<<4) | ((systime.local_time.hour % 10) & 0xf); + m_rtc.min = ((systime.local_time.minute / 10)<<4) | ((systime.local_time.minute % 10) & 0xf); + m_rtc.sec = ((systime.local_time.second / 10)<<4) | ((systime.local_time.second % 10) & 0xf); +} + + +//------------------------------------------------- +// device_reset - device-specific reset +//------------------------------------------------- + +void v3021_device::device_reset() +{ +} + + +//************************************************************************** +// READ/WRITE HANDLERS +//************************************************************************** + +READ8_MEMBER( v3021_device::read ) +{ + UINT8 calr = (m_cal_val & m_cal_mask) ? 1 : 0; + + m_cal_mask <<= 1; + return calr; +} + +WRITE8_MEMBER( v3021_device::write ) +{ + //pgm_state *state = space->machine().driver_data(); + + //space->machine().base_datetime(state->m_systime); + + m_cal_com <<= 1; + m_cal_com |= data & 1; + ++m_cal_cnt; + + if (m_cal_cnt == 4) + { + m_cal_mask = 1; + m_cal_val = 1; + m_cal_cnt = 0; + + switch (m_cal_com & 0xf) + { + case 1: case 3: case 5: case 7: case 9: case 0xb: case 0xd: + m_cal_val++; + break; + + case 0: + m_cal_val = (m_rtc.wday); //?? + break; + + case 2: //Hours + m_cal_val = (m_rtc.hour); + break; + + case 4: //Seconds + m_cal_val = (m_rtc.sec); + break; + + case 6: //Month + m_cal_val = (m_rtc.month); //?? not bcd in MVS + break; + + case 8: + m_cal_val = 0; //Controls blinking speed, maybe milliseconds + break; + + case 0xa: //Day + m_cal_val = (m_rtc.day); + break; + + case 0xc: //Minute + m_cal_val = (m_rtc.min); + break; + + case 0xe: //Year + m_cal_val = (m_rtc.year % 100); + break; + + case 0xf: //Load Date + //space->machine().base_datetime(m_systime); + break; + } + } +} diff --git a/src/emu/machine/v3021.h b/src/emu/machine/v3021.h new file mode 100644 index 00000000000..dcb401cc9e0 --- /dev/null +++ b/src/emu/machine/v3021.h @@ -0,0 +1,77 @@ +/*************************************************************************** + + v3021.h + + EM Microelectronic-Marin SA Ultra Low Power 32kHz CMOS RTC (DIP8) + + Serial Real Time Clock + +***************************************************************************/ + +#pragma once + +#ifndef __rtc9701DEV_H__ +#define __rtc9701DEV_H__ + + + +//************************************************************************** +// INTERFACE CONFIGURATION MACROS +//************************************************************************** + +#define MCFG_V3021_ADD(_tag, _clock ) \ + MCFG_DEVICE_ADD(_tag, v3021, _clock) \ + + +//************************************************************************** +// TYPE DEFINITIONS +//************************************************************************** + +typedef struct +{ + UINT8 sec, min, hour, day, wday, month, year; +} rtc_regs_t; + + +// ======================> v3021_device + +class v3021_device : public device_t +{ +public: + // construction/destruction + v3021_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock); + + // I/O operations + DECLARE_WRITE8_MEMBER( write ); + DECLARE_READ8_MEMBER( read ); + void timer_callback(); + +protected: + // device-level overrides + virtual bool device_validity_check(emu_options &options, const game_driver &driver) const; + virtual void device_start(); + virtual void device_reset(); + + inline UINT8 rtc_read(UINT8 offset); + inline void rtc_write(UINT8 offset,UINT8 data); + + static TIMER_CALLBACK( rtc_inc_callback ); + + UINT8 m_cal_mask,m_cal_com,m_cal_cnt,m_cal_val; + + rtc_regs_t m_rtc; +}; + + +// device type definition +extern const device_type v3021; + + + +//************************************************************************** +// GLOBAL VARIABLES +//************************************************************************** + + + +#endif