summaryrefslogtreecommitdiffstatshomepage
path: root/src/devices
diff options
context:
space:
mode:
author AJR <ajrhacker@users.noreply.github.com>2019-11-14 21:41:21 -0500
committer AJR <ajrhacker@users.noreply.github.com>2019-11-14 21:42:58 -0500
commita71285fbbb45dd9bcfafffea4f42450224838b35 (patch)
treed0f2926850c1e860e8fe2e177d5b653baa9ebf7c /src/devices
parentd20714babc89319636cde4fcf78d54e604ddc16a (diff)
mm74c922: Device overhaul (nw)
- Separate MM74C922 and MM74C923 device types - Add line read handler for data available output - Use array for read callbacks and provide more sensible default value than 0 - Eliminate read_x5 callback (no such line on either MM74C922 or MM74C923)
Diffstat (limited to 'src/devices')
-rw-r--r--src/devices/machine/mm74c922.cpp63
-rw-r--r--src/devices/machine/mm74c922.h40
2 files changed, 54 insertions, 49 deletions
diff --git a/src/devices/machine/mm74c922.cpp b/src/devices/machine/mm74c922.cpp
index d3733dc5c60..13f15907838 100644
--- a/src/devices/machine/mm74c922.cpp
+++ b/src/devices/machine/mm74c922.cpp
@@ -18,8 +18,8 @@
// DEVICE DEFINITIONS
//**************************************************************************
-DEFINE_DEVICE_TYPE(MM74C922, mm74c922_device, "mm74c922", "MM74C923 16/20-Key Encoder")
-decltype(MM74C922) MM74C923 = MM74C922;
+DEFINE_DEVICE_TYPE(MM74C922, mm74c922_device, "mm74c922", "MM74C923 16-Key Encoder")
+DEFINE_DEVICE_TYPE(MM74C923, mm74c923_device, "mm74c923", "MM74C923 20-Key Encoder")
@@ -32,20 +32,27 @@ decltype(MM74C922) MM74C923 = MM74C922;
// mm74c922_device - constructor
//-------------------------------------------------
-mm74c922_device::mm74c922_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock) :
- device_t(mconfig, MM74C922, tag, owner, clock),
+mm74c922_device::mm74c922_device(const machine_config &mconfig, device_type type, const char *tag, device_t *owner, uint32_t clock, int max_y) :
+ device_t(mconfig, type, tag, owner, clock),
m_write_da(*this),
- m_read_x1(*this),
- m_read_x2(*this),
- m_read_x3(*this),
- m_read_x4(*this),
- m_read_x5(*this), m_cap_osc(0), m_cap_debounce(0),
- m_max_y(5), // TODO 4 for 74C922, 5 for 74C923
- m_inhibit(0),
+ m_read_x{{*this}, {*this}, {*this}, {*this}},
+ m_cap_osc(0), m_cap_debounce(0),
+ m_max_y(max_y),
+ m_inhibit(false),
m_x(0),
m_y(0), m_data(0),
- m_da(0),
- m_next_da(0), m_scan_timer(nullptr)
+ m_da(false),
+ m_next_da(false), m_scan_timer(nullptr)
+{
+}
+
+mm74c922_device::mm74c922_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock) :
+ mm74c922_device(mconfig, MM74C922, tag, owner, clock, 4)
+{
+}
+
+mm74c923_device::mm74c923_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock) :
+ mm74c922_device(mconfig, MM74C923, tag, owner, clock, 5)
{
}
@@ -58,11 +65,8 @@ void mm74c922_device::device_start()
{
// resolve callbacks
m_write_da.resolve_safe();
- m_read_x1.resolve_safe(0);
- m_read_x2.resolve_safe(0);
- m_read_x3.resolve_safe(0);
- m_read_x4.resolve_safe(0);
- m_read_x5.resolve_safe(0);
+ for (auto &read_x : m_read_x)
+ read_x.resolve_safe((1 << m_max_y) - 1);
// set initial values
change_output_lines();
@@ -117,7 +121,8 @@ void mm74c922_device::change_output_lines()
LOG("MM74C922 Data Available: %u\n", m_da);
- m_write_da(m_da);
+ // active high output
+ m_write_da(m_da ? 1 : 0);
}
}
@@ -142,24 +147,16 @@ void mm74c922_device::clock_scan_counters()
void mm74c922_device::detect_keypress()
{
- uint8_t data = 0xff;
-
- switch (m_x)
- {
- case 0: data = m_read_x1(0); break;
- case 1: data = m_read_x2(0); break;
- case 2: data = m_read_x3(0); break;
- case 3: data = m_read_x4(0); break;
- case 4: data = m_read_x5(0); break;
- }
+ assert(m_x >= 0 && m_x < 4);
+ uint8_t data = m_read_x[m_x]();
if (m_inhibit)
{
if (BIT(data, m_y))
{
// key released
- m_inhibit = 0;
- m_next_da = 0;
+ m_inhibit = false;
+ m_next_da = false;
m_data = 0xff; // high-Z
LOG("MM74C922 Key Released\n");
@@ -172,8 +169,8 @@ void mm74c922_device::detect_keypress()
if (!BIT(data, y))
{
// key depressed
- m_inhibit = 1;
- m_next_da = 1;
+ m_inhibit = true;
+ m_next_da = true;
m_y = y;
m_data = (y << 2) | m_x;
diff --git a/src/devices/machine/mm74c922.h b/src/devices/machine/mm74c922.h
index dce81dd40dc..fd4ca3de9c6 100644
--- a/src/devices/machine/mm74c922.h
+++ b/src/devices/machine/mm74c922.h
@@ -52,15 +52,18 @@ public:
void set_cap_debounce(double value) { m_cap_debounce = value; }
auto da_wr_callback() { return m_write_da.bind(); }
- auto x1_rd_callback() { return m_read_x1.bind(); }
- auto x2_rd_callback() { return m_read_x2.bind(); }
- auto x3_rd_callback() { return m_read_x3.bind(); }
- auto x4_rd_callback() { return m_read_x4.bind(); }
- auto x5_rd_callback() { return m_read_x5.bind(); }
+ auto x1_rd_callback() { return m_read_x[0].bind(); }
+ auto x2_rd_callback() { return m_read_x[1].bind(); }
+ auto x3_rd_callback() { return m_read_x[2].bind(); }
+ auto x4_rd_callback() { return m_read_x[3].bind(); }
uint8_t read();
+ DECLARE_READ_LINE_MEMBER(da_r) { return m_da; }
+
protected:
+ mm74c922_device(const machine_config &mconfig, device_type type, const char *tag, device_t *owner, uint32_t clock, int max_y);
+
// device-level overrides
virtual void device_start() override;
virtual void device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr) override;
@@ -71,33 +74,38 @@ private:
void detect_keypress();
devcb_write_line m_write_da;
- devcb_read8 m_read_x1;
- devcb_read8 m_read_x2;
- devcb_read8 m_read_x3;
- devcb_read8 m_read_x4;
- devcb_read8 m_read_x5;
+ devcb_read8 m_read_x[4];
double m_cap_osc;
double m_cap_debounce;
- int m_max_y;
+ const int m_max_y;
- int m_inhibit; // scan counter clock inhibit
+ bool m_inhibit; // scan counter clock inhibit
int m_x; // currently scanned column
int m_y; // latched row
- uint8_t m_data; // data latch
+ uint8_t m_data; // data latch
- int m_da; // data available flag
- int m_next_da; // next value of data available flag
+ bool m_da; // data available flag
+ bool m_next_da; // next value of data available flag
// timers
emu_timer *m_scan_timer; // keyboard scan timer
};
+// ======================> mm74c923_device
+
+class mm74c923_device : public mm74c922_device
+{
+public:
+ // construction/destruction
+ mm74c923_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock);
+};
+
// device type definition
DECLARE_DEVICE_TYPE(MM74C922, mm74c922_device)
-DECLARE_DEVICE_TYPE(MM74C923, mm74c922_device)
+DECLARE_DEVICE_TYPE(MM74C923, mm74c923_device)
#endif // MAME_MACHINE_MM74C922_H