summaryrefslogtreecommitdiffstatshomepage
path: root/src/devices/machine/74157.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/devices/machine/74157.cpp')
-rw-r--r--src/devices/machine/74157.cpp88
1 files changed, 86 insertions, 2 deletions
diff --git a/src/devices/machine/74157.cpp b/src/devices/machine/74157.cpp
index 7320c97ba91..863861ef94f 100644
--- a/src/devices/machine/74157.cpp
+++ b/src/devices/machine/74157.cpp
@@ -33,6 +33,8 @@ ls157_device::ls157_device(const machine_config &mconfig, const char *tag, devic
ls157_device::ls157_device(const machine_config &mconfig, device_type type, const char *tag, device_t *owner, u32 clock)
: device_t(mconfig, type, tag, owner, clock)
+ , m_a_in_cb(*this)
+ , m_b_in_cb(*this)
, m_out_cb(*this)
{
m_a = 0;
@@ -50,6 +52,8 @@ ls157_device::ls157_device(const machine_config &mconfig, device_type type, cons
void ls157_device::device_start()
{
// resolve callbacks
+ m_a_in_cb.resolve();
+ m_b_in_cb.resolve();
m_out_cb.resolve_safe();
// register items for save state
@@ -156,6 +160,54 @@ void ls157_device::interleave_w(u8 data)
}
+//-------------------------------------------------
+// aN_w -- update one bit of first data input
+//-------------------------------------------------
+
+WRITE_LINE_MEMBER(ls157_device::a0_w) { write_a_bit(0, state); }
+WRITE_LINE_MEMBER(ls157_device::a1_w) { write_a_bit(1, state); }
+WRITE_LINE_MEMBER(ls157_device::a2_w) { write_a_bit(2, state); }
+WRITE_LINE_MEMBER(ls157_device::a3_w) { write_a_bit(3, state); }
+
+void ls157_device::write_a_bit(int bit, bool state)
+{
+ if (BIT(m_a, bit) != state)
+ {
+ if (state)
+ m_a |= (1 << bit);
+ else
+ m_a &= ~(1 << bit);
+
+ if (!m_strobe && !m_select)
+ m_out_cb(m_a);
+ }
+}
+
+
+//-------------------------------------------------
+// bN_w -- update one bit of second data input
+//-------------------------------------------------
+
+WRITE_LINE_MEMBER(ls157_device::b0_w) { write_b_bit(0, state); }
+WRITE_LINE_MEMBER(ls157_device::b1_w) { write_b_bit(1, state); }
+WRITE_LINE_MEMBER(ls157_device::b2_w) { write_b_bit(2, state); }
+WRITE_LINE_MEMBER(ls157_device::b3_w) { write_b_bit(3, state); }
+
+void ls157_device::write_b_bit(int bit, bool state)
+{
+ if (BIT(m_b, bit) != state)
+ {
+ if (state)
+ m_b |= (1 << bit);
+ else
+ m_b &= ~(1 << bit);
+
+ if (!m_strobe && m_select)
+ m_out_cb(m_b);
+ }
+}
+
+
//**************************************************************************
// CONTROL LINE INPUTS
//**************************************************************************
@@ -188,7 +240,7 @@ WRITE_LINE_MEMBER(ls157_device::strobe_w)
if (m_strobe)
m_out_cb(0);
else
- m_out_cb(m_select ? m_b : m_a);
+ update_output();
}
}
@@ -203,7 +255,39 @@ void ls157_device::update_output()
// S high, strobe low: Y1-Y4 = B1-B4
// S low, strobe low: Y1-Y4 = A1-A4
if (!m_strobe)
- m_out_cb(m_select ? m_b : m_a);
+ {
+ if (m_select)
+ m_out_cb(m_b_in_cb.isnull() ? m_b : (m_b_in_cb() & 0xf));
+ else
+ m_out_cb(m_a_in_cb.isnull() ? m_a : (m_a_in_cb() & 0xf));
+ }
+}
+
+
+//**************************************************************************
+// DATA OUTPUTS
+//**************************************************************************
+
+READ8_MEMBER(ls157_device::output_r)
+{
+ if (m_strobe)
+ return 0;
+ else if (m_select)
+ return m_b_in_cb.isnull() ? m_b : (m_b_in_cb() & 0xf);
+ else
+ return m_a_in_cb.isnull() ? m_a : (m_a_in_cb() & 0xf);
+}
+
+
+//**************************************************************************
+// 74HC157 DEVICE
+//**************************************************************************
+
+DEFINE_DEVICE_TYPE(HC157, hc157_device, "74hc157", "74HC157 Quad 2-to-1 Multiplexer")
+
+hc157_device::hc157_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock)
+ : ls157_device(mconfig, HC157, tag, owner, clock)
+{
}