From 0990b9df663b0cee40bb7b142bbdf32383b51a23 Mon Sep 17 00:00:00 2001 From: AJR Date: Wed, 5 Jun 2019 23:51:47 -0400 Subject: ds1386: Make initialization of RTC registers from system time actually work; adopt more useful default value for command register hp16500b: Add DS1286 (nw) --- src/devices/machine/ds1386.cpp | 54 +++++++++++++++++------------------------- src/devices/machine/ds1386.h | 11 +++++++-- 2 files changed, 31 insertions(+), 34 deletions(-) (limited to 'src/devices/machine') diff --git a/src/devices/machine/ds1386.cpp b/src/devices/machine/ds1386.cpp index a5319451e8d..0f430413017 100644 --- a/src/devices/machine/ds1386.cpp +++ b/src/devices/machine/ds1386.cpp @@ -34,6 +34,7 @@ DEFINE_DEVICE_TYPE(DS1386_32K, ds1386_32k_device, "ds1386_32k", "DS1386-32K RAMi ds1386_device::ds1386_device(const machine_config &mconfig, device_type type, const char *tag, device_t *owner, uint32_t clock, size_t size) : device_t(mconfig, type, tag, owner, clock) , device_nvram_interface(mconfig, *this) + , device_rtc_interface(mconfig, *this) , m_tod_alarm(0) , m_watchdog_alarm(0) , m_square(1) @@ -120,48 +121,36 @@ void ds1386_device::device_start() m_intb_timer= timer_alloc(INTB_TIMER); m_intb_timer->adjust(attotime::never); - set_current_time(); - // state saving save_item(NAME(m_tod_alarm)); save_item(NAME(m_watchdog_alarm)); save_item(NAME(m_square)); m_ram = std::make_unique(m_ram_size); - memset(&m_ram[0], 0, m_ram_size); -} - -void ds1386_device::device_reset() -{ - m_tod_alarm = 0; - m_watchdog_alarm = 0; - m_square = 1; - - safe_inta_cb(0); - safe_intb_cb(0); - safe_sqw_cb(1); - - m_clock_timer->adjust(attotime::from_hz(100), 0, attotime::from_hz(100)); - m_square_timer->adjust(attotime::never); - m_watchdog_timer->adjust(attotime::never); - - set_current_time(); + save_pointer(NAME(m_ram), m_ram_size); } -void ds1386_device::set_current_time() +void ds1386_device::rtc_clock_updated(int year, int month, int day, int day_of_week, int hour, int minute, int second) { - system_time systime; - machine().base_datetime(systime); - m_hundredths = 0; - m_seconds = time_helper::make_bcd(systime.local_time.second); - m_minutes = time_helper::make_bcd(systime.local_time.minute); - m_hours = time_helper::make_bcd(systime.local_time.hour); - m_days = time_helper::make_bcd(systime.local_time.weekday + 1); - m_date = time_helper::make_bcd(systime.local_time.mday); - m_months_enables = time_helper::make_bcd(systime.local_time.month + 1); - m_years = time_helper::make_bcd(systime.local_time.year % 100); + m_seconds = time_helper::make_bcd(second); + m_minutes = time_helper::make_bcd(minute); + if (m_hours & HOURS_12_24) + { + if (hour >= 12) + m_hours = time_helper::make_bcd(hour == 12 ? 12 : hour - 12) | HOURS_12_24 | HOURS_AM_PM; + else + m_hours = time_helper::make_bcd(hour == 0 ? 12 : hour) | HOURS_12_24; + } + else + m_hours = time_helper::make_bcd(hour); + m_days = time_helper::make_bcd(day_of_week); + m_date = time_helper::make_bcd(second); + m_months_enables = (time_helper::make_bcd(month) & 0x1f) | (m_months_enables & 0xc0); + m_years = time_helper::make_bcd(year); + + copy_registers_to_ram(); } void ds1386_device::time_of_day_alarm() @@ -419,7 +408,8 @@ void ds1386_device::check_tod_alarm() void ds1386_device::nvram_default() { - memset(&m_ram[0], 0, m_ram_size); + std::fill_n(&m_ram[0], m_ram_size, 0); + m_ram[REGISTER_COMMAND] = COMMAND_TE | COMMAND_WAM | COMMAND_TDM; } void ds1386_device::nvram_read(emu_file &file) diff --git a/src/devices/machine/ds1386.h b/src/devices/machine/ds1386.h index 032e7d73eb0..17e01b9f458 100644 --- a/src/devices/machine/ds1386.h +++ b/src/devices/machine/ds1386.h @@ -74,8 +74,11 @@ #pragma once +#include "dirtc.h" + class ds1386_device : public device_t, - public device_nvram_interface + public device_nvram_interface, + public device_rtc_interface { public: auto inta() { return m_inta_cb.bind(); } @@ -122,7 +125,6 @@ protected: // device-level overrides virtual void device_start() override; - virtual void device_reset() override; virtual void device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr) override; // device_nvram_interface overrides @@ -130,6 +132,11 @@ protected: virtual void nvram_read(emu_file &file) override; virtual void nvram_write(emu_file &file) override; + // device_rtc_interface overrides + virtual bool rtc_feature_y2k() const override { return false; } + virtual bool rtc_feature_leap_year() const override { return true; } + virtual void rtc_clock_updated(int year, int month, int day, int day_of_week, int hour, int minute, int second) override; + static constexpr device_timer_id CLOCK_TIMER = 0; static constexpr device_timer_id SQUAREWAVE_TIMER = 1; static constexpr device_timer_id WATCHDOG_TIMER = 2; -- cgit v1.2.3-70-g09d2