gen_latch: Invert logic (latch_read -> latch_written).

Also fixes initial callback after start.
This commit is contained in:
Dirk Best 2017-01-03 01:09:26 +01:00
parent 3d59f6fc1b
commit d25721b3f3
2 changed files with 30 additions and 20 deletions

View File

@ -26,7 +26,7 @@ const device_type GENERIC_LATCH_16 = &device_creator<generic_latch_16_device>;
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) : 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), device_t(mconfig, type, name, tag, owner, clock, shortname, source),
m_latch_read(false), m_latch_written(false),
m_data_pending_cb(*this) 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() void generic_latch_base_device::device_start()
{ {
m_data_pending_cb.resolve_safe(); 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) 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 // set_latch_written - helper to signal that latch
// has been read or is waiting to be read // 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_latch_written = latch_written;
m_data_pending_cb(!latch_read); 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 ) READ8_MEMBER( generic_latch_8_device::read )
{ {
set_latch_read(true); set_latch_written(false);
return m_latched_value; return m_latched_value;
} }
@ -115,13 +124,13 @@ void generic_latch_8_device::sync_callback(void *ptr, s32 param)
{ {
u8 value = param; u8 value = param;
// if the latch hasn't been read and the value is changed, log a warning // if the latch has been written and the value is changed, log a warning
if (!is_latch_read() && m_latched_value != value) if (is_latch_written() && m_latched_value != value)
logerror("Warning: latch written before being read. Previous: %02x, new: %02x\n", 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 // store the new value and mark it not read
m_latched_value = value; 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 ) READ16_MEMBER( generic_latch_16_device::read )
{ {
set_latch_read(true); set_latch_written(false);
return m_latched_value; return m_latched_value;
} }
@ -185,13 +194,13 @@ void generic_latch_16_device::sync_callback(void *ptr, s32 param)
{ {
u16 value = param; u16 value = param;
// if the latch hasn't been read and the value is changed, log a warning // if the latch has been written and the value is changed, log a warning
if (!is_latch_read() && m_latched_value != value) if (is_latch_written() && m_latched_value != value)
logerror("Warning: latch written before being read. Previous: %02x, new: %02x\n", 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 // store the new value and mark it not read
m_latched_value = value; m_latched_value = value;
set_latch_read(false); set_latch_written(true);
} }
//------------------------------------------------- //-------------------------------------------------

View File

@ -46,12 +46,13 @@ public:
protected: protected:
virtual void device_start() override; virtual void device_start() override;
virtual void device_reset() override;
bool is_latch_read() const { return m_latch_read; } bool is_latch_written() const { return m_latch_written; }
void set_latch_read(bool latch_read); void set_latch_written(bool latch_written);
private: private:
bool m_latch_read; bool m_latch_written;
devcb_write_line m_data_pending_cb; devcb_write_line m_data_pending_cb;
}; };