diff options
Diffstat (limited to 'src/devices/machine/latch8.cpp')
-rw-r--r-- | src/devices/machine/latch8.cpp | 147 |
1 files changed, 41 insertions, 106 deletions
diff --git a/src/devices/machine/latch8.cpp b/src/devices/machine/latch8.cpp index f7e392db05d..ca6d2c9f789 100644 --- a/src/devices/machine/latch8.cpp +++ b/src/devices/machine/latch8.cpp @@ -19,19 +19,10 @@ void latch8_device::update(uint8_t new_val, uint8_t mask) if (m_has_write) { - int i; uint8_t changed = old_val ^ m_value; - for (i=0; i<8; i++) - if (((changed & (1<<i)) != 0)) { - if (i==0 && !m_write_0.isnull()) m_write_0(machine().dummy_space(), m_offset[i] , (m_value >> i) & 1); - if (i==1 && !m_write_1.isnull()) m_write_1(machine().dummy_space(), m_offset[i] , (m_value >> i) & 1); - if (i==2 && !m_write_2.isnull()) m_write_2(machine().dummy_space(), m_offset[i] , (m_value >> i) & 1); - if (i==3 && !m_write_3.isnull()) m_write_3(machine().dummy_space(), m_offset[i] , (m_value >> i) & 1); - if (i==4 && !m_write_4.isnull()) m_write_4(machine().dummy_space(), m_offset[i] , (m_value >> i) & 1); - if (i==5 && !m_write_5.isnull()) m_write_5(machine().dummy_space(), m_offset[i] , (m_value >> i) & 1); - if (i==6 && !m_write_6.isnull()) m_write_6(machine().dummy_space(), m_offset[i] , (m_value >> i) & 1); - if (i==7 && !m_write_7.isnull()) m_write_7(machine().dummy_space(), m_offset[i] , (m_value >> i) & 1); - } + for (int i = 0; i < 8; i++) + if (BIT(changed, i) && !m_write_cb[i].isnull()) + m_write_cb[i](BIT(m_value, i)); } } @@ -49,22 +40,16 @@ READ8_MEMBER( latch8_device::read ) { uint8_t res; - assert(offset == 0); + // FIXME: AM_MIRROR(0xff) doesn't work properly + //assert(offset == 0); res = m_value; if (m_has_read) { - int i; - for (i=0; i<8; i++) + for (int i = 0; i < 8; i++) { - if (i==0 && !m_read_0.isnull()) { res &= ~( 1 << i); res |= ((m_read_0(space, 0, 0xff) >> m_offset[i]) & 0x01) << i; } - if (i==1 && !m_read_1.isnull()) { res &= ~( 1 << i); res |= ((m_read_1(space, 0, 0xff) >> m_offset[i]) & 0x01) << i; } - if (i==2 && !m_read_2.isnull()) { res &= ~( 1 << i); res |= ((m_read_2(space, 0, 0xff) >> m_offset[i]) & 0x01) << i; } - if (i==3 && !m_read_3.isnull()) { res &= ~( 1 << i); res |= ((m_read_3(space, 0, 0xff) >> m_offset[i]) & 0x01) << i; } - if (i==4 && !m_read_4.isnull()) { res &= ~( 1 << i); res |= ((m_read_4(space, 0, 0xff) >> m_offset[i]) & 0x01) << i; } - if (i==5 && !m_read_5.isnull()) { res &= ~( 1 << i); res |= ((m_read_5(space, 0, 0xff) >> m_offset[i]) & 0x01) << i; } - if (i==6 && !m_read_6.isnull()) { res &= ~( 1 << i); res |= ((m_read_6(space, 0, 0xff) >> m_offset[i]) & 0x01) << i; } - if (i==7 && !m_read_7.isnull()) { res &= ~( 1 << i); res |= ((m_read_7(space, 0, 0xff) >> m_offset[i]) & 0x01) << i;} + if (!m_read_cb[i].isnull()) + res = (res & ~(1 << i)) | (m_read_cb[i]() << i); } } return (res & ~m_maskout) ^ m_xorvalue; @@ -92,30 +77,23 @@ WRITE8_MEMBER( latch8_device::reset_w ) /* read bit x */ /* return (latch >> x) & 0x01 */ -uint8_t latch8_device::bitx_r( offs_t offset, int bit) -{ - assert( offset == 0); - - return (m_value >> bit) & 0x01; -} - -READ8_MEMBER( latch8_device::bit0_r) { return bitx_r(offset, 0); } -READ8_MEMBER( latch8_device::bit1_r) { return bitx_r(offset, 1); } -READ8_MEMBER( latch8_device::bit2_r) { return bitx_r(offset, 2); } -READ8_MEMBER( latch8_device::bit3_r) { return bitx_r(offset, 3); } -READ8_MEMBER( latch8_device::bit4_r) { return bitx_r(offset, 4); } -READ8_MEMBER( latch8_device::bit5_r) { return bitx_r(offset, 5); } -READ8_MEMBER( latch8_device::bit6_r) { return bitx_r(offset, 6); } -READ8_MEMBER( latch8_device::bit7_r) { return bitx_r(offset, 7); } - -READ8_MEMBER( latch8_device::bit0_q_r) { return bitx_r(offset, 0) ^ 1; } -READ8_MEMBER( latch8_device::bit1_q_r) { return bitx_r(offset, 1) ^ 1; } -READ8_MEMBER( latch8_device::bit2_q_r) { return bitx_r(offset, 2) ^ 1; } -READ8_MEMBER( latch8_device::bit3_q_r) { return bitx_r(offset, 3) ^ 1; } -READ8_MEMBER( latch8_device::bit4_q_r) { return bitx_r(offset, 4) ^ 1; } -READ8_MEMBER( latch8_device::bit5_q_r) { return bitx_r(offset, 5) ^ 1; } -READ8_MEMBER( latch8_device::bit6_q_r) { return bitx_r(offset, 6) ^ 1; } -READ8_MEMBER( latch8_device::bit7_q_r) { return bitx_r(offset, 7) ^ 1; } +READ_LINE_MEMBER(latch8_device::bit0_r) { return BIT(m_value, 0); } +READ_LINE_MEMBER(latch8_device::bit1_r) { return BIT(m_value, 1); } +READ_LINE_MEMBER(latch8_device::bit2_r) { return BIT(m_value, 2); } +READ_LINE_MEMBER(latch8_device::bit3_r) { return BIT(m_value, 3); } +READ_LINE_MEMBER(latch8_device::bit4_r) { return BIT(m_value, 4); } +READ_LINE_MEMBER(latch8_device::bit5_r) { return BIT(m_value, 5); } +READ_LINE_MEMBER(latch8_device::bit6_r) { return BIT(m_value, 6); } +READ_LINE_MEMBER(latch8_device::bit7_r) { return BIT(m_value, 7); } + +READ_LINE_MEMBER(latch8_device::bit0_q_r) { return BIT(m_value, 0) ^ 1; } +READ_LINE_MEMBER(latch8_device::bit1_q_r) { return BIT(m_value, 1) ^ 1; } +READ_LINE_MEMBER(latch8_device::bit2_q_r) { return BIT(m_value, 2) ^ 1; } +READ_LINE_MEMBER(latch8_device::bit3_q_r) { return BIT(m_value, 3) ^ 1; } +READ_LINE_MEMBER(latch8_device::bit4_q_r) { return BIT(m_value, 4) ^ 1; } +READ_LINE_MEMBER(latch8_device::bit5_q_r) { return BIT(m_value, 5) ^ 1; } +READ_LINE_MEMBER(latch8_device::bit6_q_r) { return BIT(m_value, 6) ^ 1; } +READ_LINE_MEMBER(latch8_device::bit7_q_r) { return BIT(m_value, 7) ^ 1; } /* write bit x from data into bit determined by offset */ /* latch = (latch & ~(1<<offset)) | (((data >> x) & 0x01) << offset) */ @@ -153,24 +131,9 @@ latch8_device::latch8_device(const machine_config &mconfig, const char *tag, dev m_maskout(0), m_xorvalue(0), m_nosync(0), - m_write_0(*this), - m_write_1(*this), - m_write_2(*this), - m_write_3(*this), - m_write_4(*this), - m_write_5(*this), - m_write_6(*this), - m_write_7(*this), - m_read_0(*this), - m_read_1(*this), - m_read_2(*this), - m_read_3(*this), - m_read_4(*this), - m_read_5(*this), - m_read_6(*this), - m_read_7(*this) + m_write_cb{{*this}, {*this}, {*this}, {*this}, {*this}, {*this}, {*this}, {*this}}, + m_read_cb{{*this}, {*this}, {*this}, {*this}, {*this}, {*this}, {*this}, {*this}} { - memset(m_offset, 0, sizeof(m_offset)); } @@ -181,58 +144,30 @@ latch8_device::latch8_device(const machine_config &mconfig, const char *tag, dev void latch8_device::device_validity_check(validity_checker &valid) const { - if (!m_read_0.isnull() && !m_write_0.isnull()) osd_printf_error("Device %s: Bit 0 already has a handler.\n", tag()); - if (!m_read_1.isnull() && !m_write_1.isnull()) osd_printf_error("Device %s: Bit 1 already has a handler.\n", tag()); - if (!m_read_2.isnull() && !m_write_2.isnull()) osd_printf_error("Device %s: Bit 2 already has a handler.\n", tag()); - if (!m_read_3.isnull() && !m_write_3.isnull()) osd_printf_error("Device %s: Bit 3 already has a handler.\n", tag()); - if (!m_read_4.isnull() && !m_write_4.isnull()) osd_printf_error("Device %s: Bit 4 already has a handler.\n", tag()); - if (!m_read_5.isnull() && !m_write_5.isnull()) osd_printf_error("Device %s: Bit 5 already has a handler.\n", tag()); - if (!m_read_6.isnull() && !m_write_6.isnull()) osd_printf_error("Device %s: Bit 6 already has a handler.\n", tag()); - if (!m_read_7.isnull() && !m_write_7.isnull()) osd_printf_error("Device %s: Bit 7 already has a handler.\n", tag()); + for (int i = 0; i < 8; i++) + if (!m_read_cb[i].isnull() && !m_write_cb[i].isnull()) + osd_printf_error("Device %s: Bit %d already has a handler.\n", tag(), i); } + //------------------------------------------------- // device_start - device-specific startup //------------------------------------------------- void latch8_device::device_start() { - m_write_0.resolve(); - m_write_1.resolve(); - m_write_2.resolve(); - m_write_3.resolve(); - m_write_4.resolve(); - m_write_5.resolve(); - m_write_6.resolve(); - m_write_7.resolve(); - - m_read_0.resolve(); - m_read_1.resolve(); - m_read_2.resolve(); - m_read_3.resolve(); - m_read_4.resolve(); - m_read_5.resolve(); - m_read_6.resolve(); - m_read_7.resolve(); - /* setup nodemap */ - if (!m_write_0.isnull()) m_has_write = 1; - if (!m_write_1.isnull()) m_has_write = 1; - if (!m_write_2.isnull()) m_has_write = 1; - if (!m_write_3.isnull()) m_has_write = 1; - if (!m_write_4.isnull()) m_has_write = 1; - if (!m_write_5.isnull()) m_has_write = 1; - if (!m_write_6.isnull()) m_has_write = 1; - if (!m_write_7.isnull()) m_has_write = 1; + for (auto &cb : m_write_cb) + { + if (!cb.isnull()) m_has_write = 1; + cb.resolve(); + } /* setup device read handlers */ - if (!m_read_0.isnull()) m_has_read = 1; - if (!m_read_1.isnull()) m_has_read = 1; - if (!m_read_2.isnull()) m_has_read = 1; - if (!m_read_3.isnull()) m_has_read = 1; - if (!m_read_4.isnull()) m_has_read = 1; - if (!m_read_5.isnull()) m_has_read = 1; - if (!m_read_6.isnull()) m_has_read = 1; - if (!m_read_7.isnull()) m_has_read = 1; + for (auto &cb : m_read_cb) + { + if (!cb.isnull()) m_has_read = 1; + cb.resolve(); + } save_item(NAME(m_value)); } |