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)
This commit is contained in:
AJR 2019-11-14 21:41:21 -05:00
parent d20714babc
commit a71285fbbb
2 changed files with 54 additions and 49 deletions

View File

@ -18,8 +18,8 @@
// DEVICE DEFINITIONS // DEVICE DEFINITIONS
//************************************************************************** //**************************************************************************
DEFINE_DEVICE_TYPE(MM74C922, mm74c922_device, "mm74c922", "MM74C923 16/20-Key Encoder") DEFINE_DEVICE_TYPE(MM74C922, mm74c922_device, "mm74c922", "MM74C923 16-Key Encoder")
decltype(MM74C922) MM74C923 = MM74C922; DEFINE_DEVICE_TYPE(MM74C923, mm74c923_device, "mm74c923", "MM74C923 20-Key Encoder")
@ -32,20 +32,27 @@ decltype(MM74C922) MM74C923 = MM74C922;
// mm74c922_device - constructor // mm74c922_device - constructor
//------------------------------------------------- //-------------------------------------------------
mm74c922_device::mm74c922_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t 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, MM74C922, tag, owner, clock), device_t(mconfig, type, tag, owner, clock),
m_write_da(*this), m_write_da(*this),
m_read_x1(*this), m_read_x{{*this}, {*this}, {*this}, {*this}},
m_read_x2(*this), m_cap_osc(0), m_cap_debounce(0),
m_read_x3(*this), m_max_y(max_y),
m_read_x4(*this), m_inhibit(false),
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_x(0), m_x(0),
m_y(0), m_data(0), m_y(0), m_data(0),
m_da(0), m_da(false),
m_next_da(0), m_scan_timer(nullptr) 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 // resolve callbacks
m_write_da.resolve_safe(); m_write_da.resolve_safe();
m_read_x1.resolve_safe(0); for (auto &read_x : m_read_x)
m_read_x2.resolve_safe(0); read_x.resolve_safe((1 << m_max_y) - 1);
m_read_x3.resolve_safe(0);
m_read_x4.resolve_safe(0);
m_read_x5.resolve_safe(0);
// set initial values // set initial values
change_output_lines(); change_output_lines();
@ -117,7 +121,8 @@ void mm74c922_device::change_output_lines()
LOG("MM74C922 Data Available: %u\n", m_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,24 +147,16 @@ void mm74c922_device::clock_scan_counters()
void mm74c922_device::detect_keypress() void mm74c922_device::detect_keypress()
{ {
uint8_t data = 0xff; assert(m_x >= 0 && m_x < 4);
uint8_t data = m_read_x[m_x]();
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;
}
if (m_inhibit) if (m_inhibit)
{ {
if (BIT(data, m_y)) if (BIT(data, m_y))
{ {
// key released // key released
m_inhibit = 0; m_inhibit = false;
m_next_da = 0; m_next_da = false;
m_data = 0xff; // high-Z m_data = 0xff; // high-Z
LOG("MM74C922 Key Released\n"); LOG("MM74C922 Key Released\n");
@ -172,8 +169,8 @@ void mm74c922_device::detect_keypress()
if (!BIT(data, y)) if (!BIT(data, y))
{ {
// key depressed // key depressed
m_inhibit = 1; m_inhibit = true;
m_next_da = 1; m_next_da = true;
m_y = y; m_y = y;
m_data = (y << 2) | m_x; m_data = (y << 2) | m_x;

View File

@ -52,15 +52,18 @@ public:
void set_cap_debounce(double value) { m_cap_debounce = value; } void set_cap_debounce(double value) { m_cap_debounce = value; }
auto da_wr_callback() { return m_write_da.bind(); } auto da_wr_callback() { return m_write_da.bind(); }
auto x1_rd_callback() { return m_read_x1.bind(); } auto x1_rd_callback() { return m_read_x[0].bind(); }
auto x2_rd_callback() { return m_read_x2.bind(); } auto x2_rd_callback() { return m_read_x[1].bind(); }
auto x3_rd_callback() { return m_read_x3.bind(); } auto x3_rd_callback() { return m_read_x[2].bind(); }
auto x4_rd_callback() { return m_read_x4.bind(); } auto x4_rd_callback() { return m_read_x[3].bind(); }
auto x5_rd_callback() { return m_read_x5.bind(); }
uint8_t read(); uint8_t read();
DECLARE_READ_LINE_MEMBER(da_r) { return m_da; }
protected: 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 // device-level overrides
virtual void device_start() override; virtual void device_start() override;
virtual void device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr) 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(); void detect_keypress();
devcb_write_line m_write_da; devcb_write_line m_write_da;
devcb_read8 m_read_x1; devcb_read8 m_read_x[4];
devcb_read8 m_read_x2;
devcb_read8 m_read_x3;
devcb_read8 m_read_x4;
devcb_read8 m_read_x5;
double m_cap_osc; double m_cap_osc;
double m_cap_debounce; 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_x; // currently scanned column
int m_y; // latched row int m_y; // latched row
uint8_t m_data; // data latch uint8_t m_data; // data latch
int m_da; // data available flag bool m_da; // data available flag
int m_next_da; // next value of data available flag bool m_next_da; // next value of data available flag
// timers // timers
emu_timer *m_scan_timer; // keyboard scan timer 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 // device type definition
DECLARE_DEVICE_TYPE(MM74C922, mm74c922_device) DECLARE_DEVICE_TYPE(MM74C922, mm74c922_device)
DECLARE_DEVICE_TYPE(MM74C923, mm74c922_device) DECLARE_DEVICE_TYPE(MM74C923, mm74c923_device)
#endif // MAME_MACHINE_MM74C922_H #endif // MAME_MACHINE_MM74C922_H