mm74c922: devcb2. (nw)

This commit is contained in:
Curt Coder 2014-03-25 20:13:02 +00:00
parent d1d981143d
commit 21893cf900
4 changed files with 161 additions and 198 deletions

View File

@ -30,83 +30,6 @@ const device_type MM74C923 = &device_creator<mm74c922_device>;
//**************************************************************************
// INLINE HELPERS
//**************************************************************************
//-------------------------------------------------
// change_output_lines -
//-------------------------------------------------
inline void mm74c922_device::change_output_lines()
{
if (m_next_da != m_da)
{
m_da = m_next_da;
if (LOG) logerror("MM74C922 '%s' Data Available: %u\n", tag(), m_da);
m_out_da_func(m_da);
}
}
//-------------------------------------------------
// clock_scan_counters -
//-------------------------------------------------
inline void mm74c922_device::clock_scan_counters()
{
if (!m_inhibit)
{
m_x++;
m_x &= 0x03;
}
}
//-------------------------------------------------
// device_start - device-specific startup
//-------------------------------------------------
inline void mm74c922_device::detect_keypress()
{
if (m_inhibit)
{
UINT8 data = m_in_x_func[m_x](0);
if (BIT(data, m_y))
{
// key released
m_inhibit = 0;
m_next_da = 0;
m_data = 0xff; // high-Z
if (LOG) logerror("MM74C922 '%s' Key Released\n", tag());
}
}
else
{
UINT8 data = m_in_x_func[m_x](0);
for (int y = 0; y < m_max_y; y++)
{
if (!BIT(data, y))
{
// key depressed
m_inhibit = 1;
m_next_da = 1;
m_y = y;
m_data = (y << 2) | m_x;
if (LOG) logerror("MM74C922 '%s' Key Depressed: X %u Y %u = %02x\n", tag(), m_x, y, m_data);
return;
}
}
}
}
//**************************************************************************
// LIVE DEVICE
@ -116,55 +39,24 @@ inline void mm74c922_device::detect_keypress()
// 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)
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)
{
}
//-------------------------------------------------
// 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
//-------------------------------------------------
@ -172,12 +64,12 @@ void mm74c922_device::device_config_complete()
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);
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();
@ -209,12 +101,93 @@ void mm74c922_device::device_timer(emu_timer &timer, device_timer_id id, int par
//-------------------------------------------------
// data_out_r -
// read -
//-------------------------------------------------
UINT8 mm74c922_device::data_out_r()
UINT8 mm74c922_device::read()
{
if (LOG) logerror("MM74C922 '%s' Data Read: %02x\n", tag(), m_data);
return m_data;
}
//-------------------------------------------------
// change_output_lines -
//-------------------------------------------------
void mm74c922_device::change_output_lines()
{
if (m_next_da != m_da)
{
m_da = m_next_da;
if (LOG) logerror("MM74C922 '%s' Data Available: %u\n", tag(), m_da);
m_write_da(m_da);
}
}
//-------------------------------------------------
// clock_scan_counters -
//-------------------------------------------------
void mm74c922_device::clock_scan_counters()
{
if (!m_inhibit)
{
m_x++;
m_x &= 0x03;
}
}
//-------------------------------------------------
// detect_keypress -
//-------------------------------------------------
void mm74c922_device::detect_keypress()
{
UINT8 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;
}
if (m_inhibit)
{
if (BIT(data, m_y))
{
// key released
m_inhibit = 0;
m_next_da = 0;
m_data = 0xff; // high-Z
if (LOG) logerror("MM74C922 '%s' Key Released\n", tag());
}
}
else
{
for (int y = 0; y < m_max_y; y++)
{
if (!BIT(data, y))
{
// key depressed
m_inhibit = 1;
m_next_da = 1;
m_y = y;
m_data = (y << 2) | m_x;
if (LOG) logerror("MM74C922 '%s' Key Depressed: X %u Y %u = %02x\n", tag(), m_x, y, m_data);
return;
}
}
}
}

View File

@ -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,53 +76,48 @@
// 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();
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;
double m_cap_osc;
double m_cap_debounce;
int m_max_y;
devcb_resolved_write_line m_out_da_func;
devcb_resolved_read8 m_in_x_func[5];
int m_inhibit; // scan counter clock inhibit
int m_x; // currently scanned column
int m_y; // latched row

View File

@ -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)

View File

@ -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)