diff options
author | 2014-03-25 20:13:02 +0000 | |
---|---|---|
committer | 2014-03-25 20:13:02 +0000 | |
commit | 21893cf900b5c71583b9b976bfd7852ab315951b (patch) | |
tree | f67fc028208b253ee19b3f88805d2e102f38567e /src | |
parent | d1d981143db025639d2c41a8e400486b20e78b31 (diff) |
mm74c922: devcb2. (nw)
Diffstat (limited to 'src')
-rw-r--r-- | src/emu/machine/mm74c922.c | 217 | ||||
-rw-r--r-- | src/emu/machine/mm74c922.h | 82 | ||||
-rw-r--r-- | src/mess/drivers/digel804.c | 20 | ||||
-rw-r--r-- | src/mess/drivers/elf.c | 24 |
4 files changed, 153 insertions, 190 deletions
diff --git a/src/emu/machine/mm74c922.c b/src/emu/machine/mm74c922.c index 3f414f89655..fe2d47cf7e4 100644 --- a/src/emu/machine/mm74c922.c +++ b/src/emu/machine/mm74c922.c @@ -30,15 +30,93 @@ const device_type MM74C923 = &device_creator<mm74c922_device>; + //************************************************************************** -// INLINE HELPERS +// LIVE DEVICE //************************************************************************** //------------------------------------------------- +// mm74c922_device - constructor +//------------------------------------------------- + +mm74c922_device::mm74c922_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock) : + device_t(mconfig, MM74C922, "MM74C922", tag, owner, clock, "mm74c922", __FILE__), + 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_max_y(5), // TODO 4 for 74C922, 5 for 74C923 + m_inhibit(0), + m_x(0), + m_y(0), + m_da(0), + m_next_da(0) +{ +} + + +//------------------------------------------------- +// device_start - device-specific startup +//------------------------------------------------- + +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)); + + // 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_da)); + save_item(NAME(m_next_da)); +} + + +//------------------------------------------------- +// device_timer - handler timer events +//------------------------------------------------- + +void mm74c922_device::device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr) +{ + change_output_lines(); + clock_scan_counters(); + detect_keypress(); +} + + +//------------------------------------------------- +// read - +//------------------------------------------------- + +UINT8 mm74c922_device::read() +{ + if (LOG) logerror("MM74C922 '%s' Data Read: %02x\n", tag(), m_data); + + return m_data; +} + + +//------------------------------------------------- // change_output_lines - //------------------------------------------------- -inline void mm74c922_device::change_output_lines() +void mm74c922_device::change_output_lines() { if (m_next_da != m_da) { @@ -46,7 +124,7 @@ inline void mm74c922_device::change_output_lines() if (LOG) logerror("MM74C922 '%s' Data Available: %u\n", tag(), m_da); - m_out_da_func(m_da); + m_write_da(m_da); } } @@ -55,7 +133,7 @@ inline void mm74c922_device::change_output_lines() // clock_scan_counters - //------------------------------------------------- -inline void mm74c922_device::clock_scan_counters() +void mm74c922_device::clock_scan_counters() { if (!m_inhibit) { @@ -66,15 +144,24 @@ inline void mm74c922_device::clock_scan_counters() //------------------------------------------------- -// device_start - device-specific startup +// detect_keypress - //------------------------------------------------- -inline void mm74c922_device::detect_keypress() +void mm74c922_device::detect_keypress() { - if (m_inhibit) + UINT8 data = 0xff; + + switch (m_x) { - UINT8 data = m_in_x_func[m_x](0); + 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 (BIT(data, m_y)) { // key released @@ -87,8 +174,6 @@ inline void mm74c922_device::detect_keypress() } else { - UINT8 data = m_in_x_func[m_x](0); - for (int y = 0; y < m_max_y; y++) { if (!BIT(data, y)) @@ -106,115 +191,3 @@ inline void mm74c922_device::detect_keypress() } } } - - -//************************************************************************** -// LIVE DEVICE -//************************************************************************** - -//------------------------------------------------- -// mm74c922_device - constructor -//------------------------------------------------- - -mm74c922_device::mm74c922_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock) - : device_t(mconfig, MM74C922, "MM74C922", tag, owner, clock, "mm74c922", __FILE__), - m_inhibit(0), - m_x(0), - m_y(0), - m_da(0), - m_next_da(0) -{ -} - - -//------------------------------------------------- -// static_set_config - configuration helper -//------------------------------------------------- - -void mm74c922_device::static_set_config(device_t &device, int max_y) -{ - mm74c922_device &mm74c922 = downcast<mm74c922_device &>(device); - - mm74c922.m_max_y = max_y; -} - - -//------------------------------------------------- -// device_config_complete - perform any -// operations now that the configuration is -// complete -//------------------------------------------------- - -void mm74c922_device::device_config_complete() -{ - // inherit a copy of the static data - const mm74c922_interface *intf = reinterpret_cast<const mm74c922_interface *>(static_config()); - if (intf != NULL) - *static_cast<mm74c922_interface *>(this) = *intf; - - // or initialize to defaults if none provided - else - { - memset(&m_out_da_cb, 0, sizeof(m_out_da_cb)); - memset(&m_in_x1_cb, 0, sizeof(m_in_x1_cb)); - memset(&m_in_x2_cb, 0, sizeof(m_in_x2_cb)); - memset(&m_in_x3_cb, 0, sizeof(m_in_x3_cb)); - memset(&m_in_x4_cb, 0, sizeof(m_in_x4_cb)); - memset(&m_in_x5_cb, 0, sizeof(m_in_x5_cb)); - } -} - - -//------------------------------------------------- -// device_start - device-specific startup -//------------------------------------------------- - -void mm74c922_device::device_start() -{ - // resolve callbacks - m_out_da_func.resolve(m_out_da_cb, *this); - m_in_x_func[0].resolve(m_in_x1_cb, *this); - m_in_x_func[1].resolve(m_in_x2_cb, *this); - m_in_x_func[2].resolve(m_in_x3_cb, *this); - m_in_x_func[3].resolve(m_in_x4_cb, *this); - m_in_x_func[4].resolve(m_in_x5_cb, *this); - - // set initial values - change_output_lines(); - - // allocate timers - m_scan_timer = timer_alloc(); - m_scan_timer->adjust(attotime::zero, 0, attotime::from_hz(50)); - - // 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_da)); - save_item(NAME(m_next_da)); -} - - -//------------------------------------------------- -// device_timer - handler timer events -//------------------------------------------------- - -void mm74c922_device::device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr) -{ - change_output_lines(); - clock_scan_counters(); - detect_keypress(); -} - - -//------------------------------------------------- -// data_out_r - -//------------------------------------------------- - -UINT8 mm74c922_device::data_out_r() -{ - if (LOG) logerror("MM74C922 '%s' Data Read: %02x\n", tag(), m_data); - - return m_data; -} diff --git a/src/emu/machine/mm74c922.h b/src/emu/machine/mm74c922.h index 6cfdf3abde4..477738e0dd6 100644 --- a/src/emu/machine/mm74c922.h +++ b/src/emu/machine/mm74c922.h @@ -46,24 +46,29 @@ // INTERFACE CONFIGURATION MACROS //************************************************************************** -#define MCFG_MM74C922_ADD(_tag, _config) \ - MCFG_DEVICE_ADD(_tag, MM74C922, 0) \ - MCFG_DEVICE_CONFIG(_config) \ - mm74c922_device::static_set_config(*device, 4); +#define MCFG_MM74C922_OSC(_value) \ + mm74c922_device::static_set_cap_osc(*device, _value); +#define MCFG_MM74C922_DEBOUNCE(_value) \ + mm74c922_device::static_set_cap_debounce(*device, _value); -#define MCFG_MM74C923_ADD(_tag, _config) \ - MCFG_DEVICE_ADD(_tag, MM74C923, 0) \ - MCFG_DEVICE_CONFIG(_config) \ - mm74c922_device::static_set_config(*device, 5); +#define MCFG_MM74C922_DA_CALLBACK(_write) \ + devcb = &mm74c922_device::set_da_wr_callback(*device, DEVCB2_##_write); +#define MCFG_MM74C922_X1_CALLBACK(_read) \ + devcb = &mm74c922_device::set_x1_rd_callback(*device, DEVCB2_##_read); -#define MM74C922_INTERFACE(name) \ - const mm74c922_interface (name)= +#define MCFG_MM74C922_X2_CALLBACK(_read) \ + devcb = &mm74c922_device::set_x2_rd_callback(*device, DEVCB2_##_read); +#define MCFG_MM74C922_X3_CALLBACK(_read) \ + devcb = &mm74c922_device::set_x3_rd_callback(*device, DEVCB2_##_read); -#define MM74C923_INTERFACE(name) \ - const mm74c922_interface (name)= +#define MCFG_MM74C922_X4_CALLBACK(_read) \ + devcb = &mm74c922_device::set_x4_rd_callback(*device, DEVCB2_##_read); + +#define MCFG_MM74C922_X5_CALLBACK(_read) \ + devcb = &mm74c922_device::set_x5_rd_callback(*device, DEVCB2_##_read); @@ -71,52 +76,47 @@ // TYPE DEFINITIONS //************************************************************************** -// ======================> mm74c922_interface - -struct mm74c922_interface -{ - double m_cap_osc; - double m_cap_debounce; - - devcb_write_line m_out_da_cb; - - devcb_read8 m_in_x1_cb; - devcb_read8 m_in_x2_cb; - devcb_read8 m_in_x3_cb; - devcb_read8 m_in_x4_cb; - devcb_read8 m_in_x5_cb; -}; - - // ======================> mm74c922_device -class mm74c922_device : public device_t, - public mm74c922_interface +class mm74c922_device : public device_t { public: // construction/destruction mm74c922_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock); - // inline configuration helpers - static void static_set_config(device_t &device, int max_y); + static void static_set_cap_osc(device_t &device, double value) { downcast<mm74c922_device &>(device).m_cap_osc = value; } + static void static_set_cap_debounce(device_t &device, double value) { downcast<mm74c922_device &>(device).m_cap_debounce = value; } - UINT8 data_out_r(); + template<class _Object> static devcb2_base &set_da_wr_callback(device_t &device, _Object object) { return downcast<mm74c922_device &>(device).m_write_da.set_callback(object); } + template<class _Object> static devcb2_base &set_x1_rd_callback(device_t &device, _Object object) { return downcast<mm74c922_device &>(device).m_read_x1.set_callback(object); } + template<class _Object> static devcb2_base &set_x2_rd_callback(device_t &device, _Object object) { return downcast<mm74c922_device &>(device).m_read_x2.set_callback(object); } + template<class _Object> static devcb2_base &set_x3_rd_callback(device_t &device, _Object object) { return downcast<mm74c922_device &>(device).m_read_x3.set_callback(object); } + template<class _Object> static devcb2_base &set_x4_rd_callback(device_t &device, _Object object) { return downcast<mm74c922_device &>(device).m_read_x4.set_callback(object); } + template<class _Object> static devcb2_base &set_x5_rd_callback(device_t &device, _Object object) { return downcast<mm74c922_device &>(device).m_read_x5.set_callback(object); } + + UINT8 read(); protected: // device-level overrides - virtual void device_config_complete(); virtual void device_start(); virtual void device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr); private: - inline void change_output_lines(); - inline void clock_scan_counters(); - inline void detect_keypress(); + void change_output_lines(); + void clock_scan_counters(); + void detect_keypress(); - int m_max_y; + devcb2_write_line m_write_da; + devcb2_read8 m_read_x1; + devcb2_read8 m_read_x2; + devcb2_read8 m_read_x3; + devcb2_read8 m_read_x4; + devcb2_read8 m_read_x5; - devcb_resolved_write_line m_out_da_func; - devcb_resolved_read8 m_in_x_func[5]; + double m_cap_osc; + double m_cap_debounce; + + int m_max_y; int m_inhibit; // scan counter clock inhibit int m_x; // currently scanned column diff --git a/src/mess/drivers/digel804.c b/src/mess/drivers/digel804.c index 6e3d177ab4c..9932b995d8f 100644 --- a/src/mess/drivers/digel804.c +++ b/src/mess/drivers/digel804.c @@ -318,7 +318,7 @@ READ8_MEMBER( digel804_state::ip46 ) // keypad read * this value auto-latches on a key press and remains through multiple reads * this is done by a 74C923 integrated circuit */ - UINT8 kbd = m_kb->data_out_r(); + UINT8 kbd = m_kb->read(); #ifdef PORT46_R_VERBOSE logerror("Digel804: returning %02X for port 46 keypad read\n", kbd); #endif @@ -577,17 +577,6 @@ WRITE_LINE_MEMBER( digel804_state::da_w ) m_maincpu->set_input_line(0, state ? ASSERT_LINE : CLEAR_LINE); m_key_intq = state ? 0 : 1; } -static MM74C923_INTERFACE( digel804_keypad_intf ) -{ - 0, // FIXME - 0, // FIXME - DEVCB_DRIVER_LINE_MEMBER(digel804_state, da_w), - DEVCB_INPUT_PORT("LINE0"), - DEVCB_INPUT_PORT("LINE1"), - DEVCB_INPUT_PORT("LINE2"), - DEVCB_INPUT_PORT("LINE3"), - DEVCB_NULL -}; static MACHINE_CONFIG_START( digel804, digel804_state ) /* basic machine hardware */ @@ -603,7 +592,12 @@ static MACHINE_CONFIG_START( digel804, digel804_state ) MCFG_DEFAULT_LAYOUT(layout_digel804) - MCFG_MM74C923_ADD("74c923", digel804_keypad_intf) + MCFG_DEVICE_ADD("74c923", MM74C923, 0) + MCFG_MM74C922_DA_CALLBACK(WRITELINE(digel804_state, da_w)) + MCFG_MM74C922_X1_CALLBACK(IOPORT("LINE0")) + MCFG_MM74C922_X2_CALLBACK(IOPORT("LINE1")) + MCFG_MM74C922_X3_CALLBACK(IOPORT("LINE2")) + MCFG_MM74C922_X4_CALLBACK(IOPORT("LINE3")) /* acia */ MCFG_DEVICE_ADD("acia", MOS6551, 0) diff --git a/src/mess/drivers/elf.c b/src/mess/drivers/elf.c index 7f1ee2fbc22..2fc17dc1706 100644 --- a/src/mess/drivers/elf.c +++ b/src/mess/drivers/elf.c @@ -182,7 +182,7 @@ WRITE_LINE_MEMBER( elf2_state::da_w ) { /* shift keyboard data to latch */ m_data <<= 4; - m_data |= m_kb->data_out_r() & 0x0f; + m_data |= m_kb->read() & 0x0f; if (LOAD) { @@ -193,18 +193,6 @@ WRITE_LINE_MEMBER( elf2_state::da_w ) } } -static MM74C923_INTERFACE( keyboard_intf ) -{ - CAP_U(0.15), - CAP_U(1), - DEVCB_DRIVER_LINE_MEMBER(elf2_state, da_w), - DEVCB_INPUT_PORT("X1"), - DEVCB_INPUT_PORT("X2"), - DEVCB_INPUT_PORT("X3"), - DEVCB_INPUT_PORT("X4"), - DEVCB_NULL -}; - /* Machine Initialization */ void elf2_state::machine_start() @@ -273,7 +261,15 @@ static MACHINE_CONFIG_START( elf2, elf2_state ) MCFG_CDP1861_SCREEN_ADD(CDP1861_TAG, SCREEN_TAG, XTAL_3_579545MHz/2) /* devices */ - MCFG_MM74C923_ADD(MM74C923_TAG, keyboard_intf) + MCFG_DEVICE_ADD(MM74C923_TAG, MM74C923, 0) + MCFG_MM74C922_OSC(CAP_U(0.15)) + MCFG_MM74C922_DEBOUNCE(CAP_U(1)) + MCFG_MM74C922_DA_CALLBACK(WRITELINE(elf2_state, da_w)) + MCFG_MM74C922_X1_CALLBACK(IOPORT("X1")) + MCFG_MM74C922_X2_CALLBACK(IOPORT("X2")) + MCFG_MM74C922_X3_CALLBACK(IOPORT("X3")) + MCFG_MM74C922_X4_CALLBACK(IOPORT("X4")) + MCFG_DEVICE_ADD(DM9368_H_TAG, DM9368, 0) MCFG_OUTPUT_NAME("digit0") MCFG_DEVICE_ADD(DM9368_L_TAG, DM9368, 0) |