From 04d24d5368efc44da441a43159249862ee5853ce Mon Sep 17 00:00:00 2001 From: Patrick Mackinlay Date: Fri, 24 Mar 2023 17:24:39 +0700 Subject: mc146818: add ds1397 variant --- src/devices/machine/mc146818.cpp | 36 ++++++++++++++++++++++++++++++++++++ src/devices/machine/mc146818.h | 18 ++++++++++++++++++ 2 files changed, 54 insertions(+) diff --git a/src/devices/machine/mc146818.cpp b/src/devices/machine/mc146818.cpp index f1b7ffa97a0..dbe5ab11051 100644 --- a/src/devices/machine/mc146818.cpp +++ b/src/devices/machine/mc146818.cpp @@ -24,6 +24,7 @@ // device type definition DEFINE_DEVICE_TYPE(MC146818, mc146818_device, "mc146818", "MC146818 RTC") DEFINE_DEVICE_TYPE(DS1287, ds1287_device, "ds1287", "DS1287 RTC") +DEFINE_DEVICE_TYPE(DS1397, ds1397_device, "ds1397", "DS1397 RAMified RTC") //------------------------------------------------- // mc146818_device - constructor @@ -49,6 +50,11 @@ ds1287_device::ds1287_device(const machine_config &mconfig, const char *tag, dev { } +ds1397_device::ds1397_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock) + : mc146818_device(mconfig, DS1397, tag, owner, clock) +{ +} + mc146818_device::mc146818_device(const machine_config &mconfig, device_type type, const char *tag, device_t *owner, uint32_t clock) : device_t(mconfig, type, tag, owner, clock), device_nvram_interface(mconfig, *this), @@ -721,3 +727,33 @@ void mc146818_device::internal_write(offs_t offset, uint8_t data) break; } } + +void ds1397_device::device_start() +{ + mc146818_device::device_start(); + + save_item(NAME(m_xram_page)); +} + +void ds1397_device::device_reset() +{ + mc146818_device::device_reset(); + + m_xram_page = 0; +} + +u8 ds1397_device::xram_r(offs_t offset) +{ + if (offset < 0x20) + return m_data[0x40 + m_xram_page * 0x20 + offset]; + else + return m_xram_page; +} + +void ds1397_device::xram_w(offs_t offset, u8 data) +{ + if (offset < 0x20) + m_data[0x40 + m_xram_page * 0x20 + offset] = data; + else + m_xram_page = data & 0x7f; +} diff --git a/src/devices/machine/mc146818.h b/src/devices/machine/mc146818.h index b352c2894e8..6e3fff11fd7 100644 --- a/src/devices/machine/mc146818.h +++ b/src/devices/machine/mc146818.h @@ -181,8 +181,26 @@ public: ds1287_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock); }; +class ds1397_device : public mc146818_device +{ +public: + ds1397_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock); + + virtual void device_start() override; + virtual void device_reset() override; + + u8 xram_r(offs_t offset); + void xram_w(offs_t offset, u8 data); + +protected: + virtual int data_size() const override { return 64 + 4096; } + + u8 m_xram_page; +}; + // device type definition DECLARE_DEVICE_TYPE(MC146818, mc146818_device) DECLARE_DEVICE_TYPE(DS1287, ds1287_device) +DECLARE_DEVICE_TYPE(DS1397, ds1397_device) #endif // MAME_MACHINE_MC146818_H -- cgit v1.2.3