diff options
Diffstat (limited to 'src/devices/machine/mm74c922.cpp')
-rw-r--r-- | src/devices/machine/mm74c922.cpp | 92 |
1 files changed, 45 insertions, 47 deletions
diff --git a/src/devices/machine/mm74c922.cpp b/src/devices/machine/mm74c922.cpp index d3733dc5c60..ee44fb38f87 100644 --- a/src/devices/machine/mm74c922.cpp +++ b/src/devices/machine/mm74c922.cpp @@ -18,9 +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", "MM74C922 16-Key Encoder") +DEFINE_DEVICE_TYPE(MM74C923, mm74c923_device, "mm74c923", "MM74C923 20-Key Encoder") @@ -32,20 +31,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), - 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), +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_x(*this, (1 << max_y) - 1), m_tristate_data(*this, (1 << max_y) - 1), + 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_y(0), + m_data(0), m_next_data(0), + 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) { } @@ -56,36 +62,29 @@ mm74c922_device::mm74c922_device(const machine_config &mconfig, const char *tag, 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); - // set initial values change_output_lines(); // allocate timers - m_scan_timer = timer_alloc(); - m_scan_timer->adjust(attotime::zero, 0, attotime::from_hz(50)); + m_scan_timer = timer_alloc(FUNC(mm74c922_device::perform_scan), this); + m_scan_timer->adjust(attotime::zero, 0, attotime::from_hz(500)); // approximate rate from a 100n capacitor // register for state saving save_item(NAME(m_inhibit)); save_item(NAME(m_x)); save_item(NAME(m_y)); save_item(NAME(m_data)); + save_item(NAME(m_next_data)); save_item(NAME(m_da)); save_item(NAME(m_next_da)); } //------------------------------------------------- -// device_timer - handler timer events +// perform_scan - scan the keyboard matrix //------------------------------------------------- -void mm74c922_device::device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr) +TIMER_CALLBACK_MEMBER(mm74c922_device::perform_scan) { change_output_lines(); clock_scan_counters(); @@ -111,13 +110,21 @@ uint8_t mm74c922_device::read() void mm74c922_device::change_output_lines() { + // clock data latches + if (m_next_data != m_data) + { + m_data = m_next_data; + } + + // clock data available if (m_next_da != m_da) { m_da = m_next_da; LOG("MM74C922 Data Available: %u\n", m_da); - m_write_da(m_da); + // active high output + m_write_da(m_da ? 1 : 0); } } @@ -142,25 +149,17 @@ 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_data = 0xff; // high-Z + m_inhibit = false; + m_next_da = false; + m_next_data = m_tristate_data(); // high-Z LOG("MM74C922 Key Released\n"); } @@ -172,14 +171,13 @@ 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; + m_next_data = (y << 2) | m_x; - LOG("MM74C922 Key Depressed: X %u Y %u = %02x\n", m_x, y, m_data); - return; + LOG("MM74C922 Key Depressed: X %u Y %u = %02x\n", m_x, y, m_next_data); } } } |