From d25721b3f33ed83274a9a98b82605eeff0724e07 Mon Sep 17 00:00:00 2001 From: Dirk Best Date: Tue, 3 Jan 2017 01:09:26 +0100 Subject: [PATCH] gen_latch: Invert logic (latch_read -> latch_written). Also fixes initial callback after start. --- src/devices/machine/gen_latch.cpp | 43 +++++++++++++++++++------------ src/devices/machine/gen_latch.h | 7 ++--- 2 files changed, 30 insertions(+), 20 deletions(-) diff --git a/src/devices/machine/gen_latch.cpp b/src/devices/machine/gen_latch.cpp index 7be65c67943..f41f6df5fca 100644 --- a/src/devices/machine/gen_latch.cpp +++ b/src/devices/machine/gen_latch.cpp @@ -26,7 +26,7 @@ const device_type GENERIC_LATCH_16 = &device_creator; generic_latch_base_device::generic_latch_base_device(const machine_config &mconfig, device_type type, const char *name, const char *tag, device_t *owner, u32 clock, const char *shortname, const char *source) : device_t(mconfig, type, name, tag, owner, clock, shortname, source), - m_latch_read(false), + m_latch_written(false), m_data_pending_cb(*this) { } @@ -38,7 +38,16 @@ generic_latch_base_device::generic_latch_base_device(const machine_config &mconf void generic_latch_base_device::device_start() { m_data_pending_cb.resolve_safe(); - save_item(NAME(m_latch_read)); + save_item(NAME(m_latch_written)); +} + +//------------------------------------------------- +// device_reset - device-specific reset +//------------------------------------------------- + +void generic_latch_base_device::device_reset() +{ + m_latch_written = false; } //------------------------------------------------- @@ -48,20 +57,20 @@ void generic_latch_base_device::device_start() READ_LINE_MEMBER(generic_latch_base_device::pending_r) { - return !m_latch_read; + return m_latch_written ? 1 : 0; } //------------------------------------------------- -// set_latch_read - helper to signal that latch -// has been read or is waiting to be read +// set_latch_written - helper to signal that latch +// has been written or has been read //------------------------------------------------- -void generic_latch_base_device::set_latch_read(bool latch_read) +void generic_latch_base_device::set_latch_written(bool latch_written) { - if (m_latch_read != latch_read) + if (m_latch_written != latch_written) { - m_latch_read = latch_read; - m_data_pending_cb(!latch_read); + m_latch_written = latch_written; + m_data_pending_cb(latch_written ? 1 : 0); } } @@ -77,7 +86,7 @@ generic_latch_8_device::generic_latch_8_device(const machine_config &mconfig, co READ8_MEMBER( generic_latch_8_device::read ) { - set_latch_read(true); + set_latch_written(false); return m_latched_value; } @@ -115,13 +124,13 @@ void generic_latch_8_device::sync_callback(void *ptr, s32 param) { u8 value = param; - // if the latch hasn't been read and the value is changed, log a warning - if (!is_latch_read() && m_latched_value != value) + // if the latch has been written and the value is changed, log a warning + if (is_latch_written() && m_latched_value != value) logerror("Warning: latch written before being read. Previous: %02x, new: %02x\n", m_latched_value, value); // store the new value and mark it not read m_latched_value = value; - set_latch_read(false); + set_latch_written(true); } //------------------------------------------------- @@ -147,7 +156,7 @@ generic_latch_16_device::generic_latch_16_device(const machine_config &mconfig, READ16_MEMBER( generic_latch_16_device::read ) { - set_latch_read(true); + set_latch_written(false); return m_latched_value; } @@ -185,13 +194,13 @@ void generic_latch_16_device::sync_callback(void *ptr, s32 param) { u16 value = param; - // if the latch hasn't been read and the value is changed, log a warning - if (!is_latch_read() && m_latched_value != value) + // if the latch has been written and the value is changed, log a warning + if (is_latch_written() && m_latched_value != value) logerror("Warning: latch written before being read. Previous: %02x, new: %02x\n", m_latched_value, value); // store the new value and mark it not read m_latched_value = value; - set_latch_read(false); + set_latch_written(true); } //------------------------------------------------- diff --git a/src/devices/machine/gen_latch.h b/src/devices/machine/gen_latch.h index 4cfa73a1c4c..2c000d2fce7 100644 --- a/src/devices/machine/gen_latch.h +++ b/src/devices/machine/gen_latch.h @@ -46,12 +46,13 @@ public: protected: virtual void device_start() override; + virtual void device_reset() override; - bool is_latch_read() const { return m_latch_read; } - void set_latch_read(bool latch_read); + bool is_latch_written() const { return m_latch_written; } + void set_latch_written(bool latch_written); private: - bool m_latch_read; + bool m_latch_written; devcb_write_line m_data_pending_cb; };