diff options
Diffstat (limited to 'src/devices/machine/latch8.cpp')
-rw-r--r-- | src/devices/machine/latch8.cpp | 76 |
1 files changed, 37 insertions, 39 deletions
diff --git a/src/devices/machine/latch8.cpp b/src/devices/machine/latch8.cpp index 7b10bed2df6..2bb8e1ddbb0 100644 --- a/src/devices/machine/latch8.cpp +++ b/src/devices/machine/latch8.cpp @@ -13,7 +13,7 @@ void latch8_device::update(uint8_t new_val, uint8_t mask) { - uint8_t old_val = m_value; + const uint8_t old_val = m_value; m_value = (m_value & ~mask) | (new_val & mask); @@ -21,33 +21,31 @@ void latch8_device::update(uint8_t new_val, uint8_t mask) { uint8_t changed = old_val ^ m_value; for (int i = 0; i < 8; i++) - if (BIT(changed, i) && !m_write_cb[i].isnull()) + if (BIT(changed, i)) m_write_cb[i](BIT(m_value, i)); } } TIMER_CALLBACK_MEMBER( latch8_device::timerproc ) { - uint8_t new_val = param & 0xFF; - uint8_t mask = param >> 8; + const uint8_t new_val = param & 0xff; + const uint8_t mask = param >> 8; - update( new_val, mask); + update(new_val, mask); } /* ----------------------------------------------------------------------- */ -READ8_MEMBER( latch8_device::read ) +uint8_t latch8_device::read(offs_t offset) { - uint8_t res; - assert(offset == 0); - res = m_value; + uint8_t res = m_value; if (m_has_read) { for (int i = 0; i < 8; i++) { - if (!m_read_cb[i].isnull()) + if (!m_read_cb[i].isunset()) res = (res & ~(1 << i)) | (m_read_cb[i]() << i); } } @@ -55,33 +53,33 @@ READ8_MEMBER( latch8_device::read ) } -WRITE8_MEMBER( latch8_device::write ) +void latch8_device::write(offs_t offset, uint8_t data) { assert(offset == 0); if (m_nosync != 0xff) - machine().scheduler().synchronize(timer_expired_delegate(FUNC(latch8_device::timerproc),this), (0xFF << 8) | data); + machine().scheduler().synchronize(timer_expired_delegate(FUNC(latch8_device::timerproc),this), (0xff << 8) | data); else - update(data, 0xFF); + update(data, 0xff); } -WRITE8_MEMBER( latch8_device::reset_w ) +void latch8_device::reset_w(offs_t offset, uint8_t data) { assert(offset == 0); m_value = 0; } -/* write bit x from data into bit determined by offset */ -/* latch = (latch & ~(1<<offset)) | (((data >> x) & 0x01) << offset) */ +// write bit x from data into bit determined by offset +// latch = (latch & ~(1<<offset)) | (((data >> x) & 0x01) << offset) -void latch8_device::bitx_w(int bit, offs_t offset, uint8_t data) +template <int Bit> inline void latch8_device::bitx_w(offs_t offset, uint8_t data) { - uint8_t mask = (1<<offset); - uint8_t masked_data = (((data >> bit) & 0x01) << offset); + const uint8_t mask = 1 << offset; + const uint8_t masked_data = BIT(data, Bit) << offset; - assert( offset < 8); + assert(offset < 8); /* No need to synchronize ? */ if (m_nosync & mask) @@ -90,27 +88,27 @@ void latch8_device::bitx_w(int bit, offs_t offset, uint8_t data) machine().scheduler().synchronize(timer_expired_delegate(FUNC(latch8_device::timerproc),this), (mask << 8) | masked_data); } -WRITE8_MEMBER( latch8_device::bit0_w ) { bitx_w(0, offset, data); } -WRITE8_MEMBER( latch8_device::bit1_w ) { bitx_w(1, offset, data); } -WRITE8_MEMBER( latch8_device::bit2_w ) { bitx_w(2, offset, data); } -WRITE8_MEMBER( latch8_device::bit3_w ) { bitx_w(3, offset, data); } -WRITE8_MEMBER( latch8_device::bit4_w ) { bitx_w(4, offset, data); } -WRITE8_MEMBER( latch8_device::bit5_w ) { bitx_w(5, offset, data); } -WRITE8_MEMBER( latch8_device::bit6_w ) { bitx_w(6, offset, data); } -WRITE8_MEMBER( latch8_device::bit7_w ) { bitx_w(7, offset, data); } +void latch8_device::bit0_w(offs_t offset, uint8_t data) { bitx_w<0>(offset, data); } +void latch8_device::bit1_w(offs_t offset, uint8_t data) { bitx_w<1>(offset, data); } +void latch8_device::bit2_w(offs_t offset, uint8_t data) { bitx_w<2>(offset, data); } +void latch8_device::bit3_w(offs_t offset, uint8_t data) { bitx_w<3>(offset, data); } +void latch8_device::bit4_w(offs_t offset, uint8_t data) { bitx_w<4>(offset, data); } +void latch8_device::bit5_w(offs_t offset, uint8_t data) { bitx_w<5>(offset, data); } +void latch8_device::bit6_w(offs_t offset, uint8_t data) { bitx_w<6>(offset, data); } +void latch8_device::bit7_w(offs_t offset, uint8_t data) { bitx_w<7>(offset, data); } DEFINE_DEVICE_TYPE(LATCH8, latch8_device, "latch8", "8-bit latch") latch8_device::latch8_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock) : device_t(mconfig, LATCH8, tag, owner, clock) + , m_write_cb(*this) + , m_read_cb(*this, 0) , m_value(0) - , m_has_write(0) - , m_has_read(0) + , m_has_write(false) + , m_has_read(false) , m_maskout(0) , m_xorvalue(0) , m_nosync(0) - , m_write_cb{{*this}, {*this}, {*this}, {*this}, {*this}, {*this}, {*this}, {*this}} - , m_read_cb{{*this}, {*this}, {*this}, {*this}, {*this}, {*this}, {*this}, {*this}} { } @@ -123,7 +121,7 @@ latch8_device::latch8_device(const machine_config &mconfig, const char *tag, dev void latch8_device::device_validity_check(validity_checker &valid) const { for (int i = 0; i < 8; i++) - if (!m_read_cb[i].isnull() && !m_write_cb[i].isnull()) + if (!m_read_cb[i].isunset() && !m_write_cb[i].isunset()) osd_printf_error("Device %s: Bit %d already has a handler.\n", tag(), i); } @@ -133,18 +131,18 @@ void latch8_device::device_validity_check(validity_checker &valid) const void latch8_device::device_start() { - /* setup nodemap */ + // setup nodemap for (auto &cb : m_write_cb) { - if (!cb.isnull()) m_has_write = 1; - cb.resolve(); + if (!cb.isunset()) + m_has_write = true; } - /* setup device read handlers */ + // setup device read handlers for (auto &cb : m_read_cb) { - if (!cb.isnull()) m_has_read = 1; - cb.resolve(); + if (!cb.isunset()) + m_has_read = true; } save_item(NAME(m_value)); |