mc6846_device: converted to devcb2 (nw)

This commit is contained in:
Ivan Vangelista 2014-03-26 17:33:21 +00:00
parent 65fe2c6dd8
commit 8b019898d2
5 changed files with 75 additions and 169 deletions

View File

@ -30,7 +30,7 @@
#define PORT \
((m_pdr & m_ddr) | \
((!m_in_port_func.isnull() ? m_in_port_func( 0 ) : 0) & \
((!m_in_port_cb.isnull() ? m_in_port_cb( 0 ) : 0) & \
~m_ddr))
#define CTO \
@ -44,35 +44,16 @@
const device_type MC6846 = &device_creator<mc6846_device>;
mc6846_device::mc6846_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
: device_t(mconfig, MC6846, "Motorola MC6846 programmable timer", tag, owner, clock, "mc6846", __FILE__)
: device_t(mconfig, MC6846, "Motorola MC6846 programmable timer", tag, owner, clock, "mc6846", __FILE__),
m_out_port_cb(*this),
m_out_cp1_cb(*this),
m_out_cp2_cb(*this),
m_in_port_cb(*this),
m_out_cto_cb(*this),
m_irq_cb(*this)
{
}
//-------------------------------------------------
// device_config_complete - perform any
// operations now that the configuration is
// complete
//-------------------------------------------------
void mc6846_device::device_config_complete()
{
// inherit a copy of the static data
const mc6846_interface *intf = reinterpret_cast<const mc6846_interface *>(static_config());
if (intf != NULL)
*static_cast<mc6846_interface *>(this) = *intf;
// or initialize to defaults if none provided
else
{
memset(&m_out_port_cb, 0, sizeof(m_out_port_cb));
memset(&m_out_cp1_cb, 0, sizeof(m_out_cp1_cb));
memset(&m_out_cp2_cb, 0, sizeof(m_out_cp2_cb));
memset(&m_in_port_cb, 0, sizeof(m_in_port_cb));
memset(&m_out_cto_cb, 0, sizeof(m_out_cto_cb));
memset(&m_irq_cb, 0, sizeof(m_irq_cb));
}
}
//-------------------------------------------------
// device_start - device-specific startup
//-------------------------------------------------
@ -82,18 +63,18 @@ void mc6846_device::device_start()
m_interval = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(mc6846_device::timer_expire), this));
m_one_shot = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(mc6846_device::timer_one_shot), this));
m_out_port_func.resolve(m_out_port_cb, *this); /* 8-bit output */
m_out_cp1_func.resolve(m_out_cp1_cb, *this); /* 1-bit output */
m_out_cp2_func.resolve(m_out_cp2_cb, *this); /* 1-bit output */
m_out_port_cb.resolve(); /* 8-bit output */
m_out_cp1_cb.resolve_safe(); /* 1-bit output */
m_out_cp2_cb.resolve(); /* 1-bit output */
/* CPU read from the outside through chip */
m_in_port_func.resolve(m_in_port_cb, *this); /* 8-bit input */
m_in_port_cb.resolve(); /* 8-bit input */
/* asynchronous timer output to outside world */
m_out_cto_func.resolve(m_out_cto_cb, *this); /* 1-bit output */
m_out_cto_cb.resolve(); /* 1-bit output */
/* timer interrupt */
m_irq_func.resolve(m_irq_cb, *this);
m_irq_cb.resolve();
save_item(NAME(m_csr));
save_item(NAME(m_pcr));
@ -171,14 +152,14 @@ inline void mc6846_device::update_irq()
if ( cif )
{
m_csr |= 0x80;
if ( !m_irq_func.isnull() )
m_irq_func( 1 );
if ( !m_irq_cb.isnull() )
m_irq_cb( 1 );
}
else
{
m_csr &= ~0x80;
if ( !m_irq_func.isnull() )
m_irq_func( 0 );
if ( !m_irq_cb.isnull() )
m_irq_cb( 0 );
}
}
@ -192,8 +173,8 @@ inline void mc6846_device::update_cto()
LOG (( "%f: mc6846 CTO set to %i\n", machine().time().as_double(), cto ));
m_old_cto = cto;
}
if ( !m_out_cto_func.isnull() )
m_out_cto_func( 0, cto );
if ( !m_out_cto_cb.isnull() )
m_out_cto_cb( (offs_t) 0, cto );
}
@ -410,8 +391,8 @@ WRITE8_MEMBER(mc6846_device::write)
if (data & 0x10)
{
m_cp2_cpu = (data >> 3) & 1;
if ( !m_out_cp2_func.isnull() )
m_out_cp2_func( 0, m_cp2_cpu );
if ( !m_out_cp2_cb.isnull() )
m_out_cp2_cb( (offs_t) 0, m_cp2_cpu );
}
else
logerror( "%s mc6846 acknowledge not implemented\n", machine().describe_context() );
@ -423,8 +404,8 @@ WRITE8_MEMBER(mc6846_device::write)
if ( ! (m_pcr & 0x80) )
{
m_ddr = data;
if ( !m_out_port_func.isnull() )
m_out_port_func( 0, m_pdr & m_ddr );
if ( !m_out_port_cb.isnull() )
m_out_port_cb( (offs_t) 0, m_pdr & m_ddr );
}
break;
@ -433,8 +414,8 @@ WRITE8_MEMBER(mc6846_device::write)
if ( ! (m_pcr & 0x80) )
{
m_pdr = data;
if ( !m_out_port_func.isnull() )
m_out_port_func( 0, m_pdr & m_ddr );
if ( !m_out_port_cb.isnull() )
m_out_port_cb( (offs_t) 0, m_pdr & m_ddr );
if ( m_csr1_to_be_cleared && (m_csr & 2) )
{
m_csr &= ~2;

View File

@ -10,33 +10,38 @@
#define MC6846_H
/* ---------- configuration ------------ */
#define MCFG_MC6846_OUT_PORT_CB(_devcb) \
devcb = &mc6846_device::set_out_port_callback(*device, DEVCB2_##_devcb);
struct mc6846_interface
{
/* CPU write to the outside through chip */
devcb_write8 m_out_port_cb; /* 8-bit output */
devcb_write8 m_out_cp1_cb; /* 1-bit output */
devcb_write8 m_out_cp2_cb; /* 1-bit output */
#define MCFG_MC6846_OUT_CP1_CB(_devcb) \
devcb = &mc6846_device::set_out_cp1_callback(*device, DEVCB2_##_devcb);
/* CPU read from the outside through chip */
devcb_read8 m_in_port_cb; /* 8-bit input */
#define MCFG_MC6846_OUT_CP2_CB(_devcb) \
devcb = &mc6846_device::set_out_cp2_callback(*device, DEVCB2_##_devcb);
#define MCFG_MC6846_IN_PORT_CB(_devcb) \
devcb = &mc6846_device::set_in_port_callback(*device, DEVCB2_##_devcb);
/* asynchronous timer output to outside world */
devcb_write8 m_out_cto_cb; /* 1-bit output */
#define MCFG_MC6846_OUT_CTO_CB(_devcb) \
devcb = &mc6846_device::set_out_cto_callback(*device, DEVCB2_##_devcb);
/* timer interrupt */
devcb_write_line m_irq_cb;
};
#define MCFG_MC6846_IRQ_CB(_devcb) \
devcb = &mc6846_device::set_irq_callback(*device, DEVCB2_##_devcb);
class mc6846_device : public device_t,
public mc6846_interface
class mc6846_device : public device_t
{
public:
mc6846_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
~mc6846_device() {}
template<class _Object> static devcb2_base &set_out_port_callback(device_t &device, _Object object) { return downcast<mc6846_device &>(device).m_out_port_cb.set_callback(object); }
template<class _Object> static devcb2_base &set_out_cp1_callback(device_t &device, _Object object) { return downcast<mc6846_device &>(device).m_out_cp1_cb.set_callback(object); }
template<class _Object> static devcb2_base &set_out_cp2_callback(device_t &device, _Object object) { return downcast<mc6846_device &>(device).m_out_cp2_cb.set_callback(object); }
template<class _Object> static devcb2_base &set_in_port_callback(device_t &device, _Object object) { return downcast<mc6846_device &>(device).m_in_port_cb.set_callback(object); }
template<class _Object> static devcb2_base &set_out_cto_callback(device_t &device, _Object object) { return downcast<mc6846_device &>(device).m_out_cto_cb.set_callback(object); }
template<class _Object> static devcb2_base &set_irq_callback(device_t &device, _Object object) { return downcast<mc6846_device &>(device).m_irq_cb.set_callback(object); }
/* interface to CPU via address/data bus*/
DECLARE_READ8_MEMBER(read);
DECLARE_WRITE8_MEMBER(write);
@ -55,7 +60,6 @@ public:
protected:
// device-level overrides
virtual void device_config_complete();
virtual void device_start();
virtual void device_reset();
@ -89,18 +93,18 @@ private:
emu_timer *m_one_shot; /* 1-us x factor one-shot timer */
/* CPU write to the outside through chip */
devcb_resolved_write8 m_out_port_func; /* 8-bit output */
devcb_resolved_write8 m_out_cp1_func; /* 1-bit output */
devcb_resolved_write8 m_out_cp2_func; /* 1-bit output */
devcb2_write8 m_out_port_cb; /* 8-bit output */
devcb2_write8 m_out_cp1_cb; /* 1-bit output */
devcb2_write8 m_out_cp2_cb; /* 1-bit output */
/* CPU read from the outside through chip */
devcb_resolved_read8 m_in_port_func; /* 8-bit input */
devcb2_read8 m_in_port_cb; /* 8-bit input */
/* asynchronous timer output to outside world */
devcb_resolved_write8 m_out_cto_func; /* 1-bit output */
devcb2_write8 m_out_cto_cb; /* 1-bit output */
/* timer interrupt */
devcb_resolved_write_line m_irq_func;
devcb2_write_line m_irq_cb;
int m_old_cif;
int m_old_cto;
@ -116,15 +120,4 @@ private:
extern const device_type MC6846;
#define MCFG_MC6846_ADD(_tag, _intrf) \
MCFG_DEVICE_ADD(_tag, MC6846, 0) \
MCFG_DEVICE_CONFIG(_intrf)
#define MCFG_MC6846_MODIFY(_tag, _intrf) \
MCFG_DEVICE_MODIFY(_tag) \
MCFG_DEVICE_CONFIG(_intrf)
#define MCFG_MC6846_REMOVE(_tag) \
MCFG_DEVICE_REMOVE(_tag)
#endif

View File

@ -693,11 +693,16 @@ static MACHINE_CONFIG_START( to7, thomson_state )
MCFG_CASSETTE_ADD( "cassette", to7_cassette_interface )
/* timer */
MCFG_MC6846_ADD( "mc6846", to7_timer )
MCFG_DEVICE_ADD("mc6846", MC6846, 0)
MCFG_MC6846_OUT_PORT_CB(WRITE8(thomson_state, to7_timer_port_out))
MCFG_MC6846_OUT_CP2_CB(WRITE8(thomson_state, to7_timer_cp2_out))
MCFG_MC6846_IN_PORT_CB(READ8(thomson_state, to7_timer_port_in))
MCFG_MC6846_OUT_CTO_CB(WRITE8(thomson_state, to7_timer_tco_out))
MCFG_MC6846_IRQ_CB(WRITELINE(thomson_state, thom_dev_irq_0))
/* speech synthesis */
MCFG_DEVICE_ADD("mea8000", MEA8000, 0)
MCFG_MEA8000_DAC("speech")
MCFG_DEVICE_ADD("mea8000", MEA8000, 0)
MCFG_MEA8000_DAC("speech")
/* floppy */
MCFG_DEVICE_ADD("mc6843", MC6843, 0)
@ -949,8 +954,9 @@ static MACHINE_CONFIG_DERIVED( to770, to7 )
MCFG_PIA_WRITEPB_HANDLER(WRITE8(thomson_state, to770_sys_portb_out))
MCFG_PIA_CB2_HANDLER(WRITELINE(thomson_state, to770_sys_cb2_out))
MCFG_MC6846_MODIFY( "mc6846", to770_timer )
MCFG_DEVICE_MODIFY("mc6846")
MCFG_MC6846_OUT_PORT_CB(WRITE8(thomson_state, to770_timer_port_out))
MCFG_CARTSLOT_MODIFY("cart")
MCFG_CARTSLOT_INTERFACE("to770_cart")
MCFG_DEVICE_REMOVE("cart_list")
@ -1487,7 +1493,8 @@ static MACHINE_CONFIG_DERIVED( to9, to7 )
MCFG_PIA_CB2_HANDLER(NULL)
MCFG_PIA_IRQA_HANDLER(NULL)
MCFG_MC6846_MODIFY( "mc6846", to9_timer )
MCFG_DEVICE_MODIFY("mc6846")
MCFG_MC6846_OUT_PORT_CB(WRITE8(thomson_state, to9_timer_port_out))
MCFG_CENTRONICS_ADD("centronics", centronics_printers, "image")
MCFG_CENTRONICS_BUSY_HANDLER(WRITELINE(thomson_state, write_centronics_busy))
@ -1711,7 +1718,10 @@ static MACHINE_CONFIG_DERIVED( to8, to7 )
MCFG_CENTRONICS_ADD("centronics", centronics_printers, "image")
MCFG_CENTRONICS_BUSY_HANDLER(WRITELINE(thomson_state, write_centronics_busy))
MCFG_MC6846_MODIFY( "mc6846", to8_timer )
MCFG_DEVICE_MODIFY("mc6846")
MCFG_MC6846_OUT_PORT_CB(WRITE8(thomson_state, to8_timer_port_out))
MCFG_MC6846_OUT_CP2_CB(WRITE8(thomson_state, to8_timer_cp2_out))
MCFG_MC6846_IN_PORT_CB(READ8(thomson_state, to8_timer_port_in))
/* internal ram */
MCFG_RAM_MODIFY(RAM_TAG)
@ -1864,8 +1874,11 @@ static MACHINE_CONFIG_DERIVED( to9p, to7 )
MCFG_CENTRONICS_ADD("centronics", centronics_printers, "image")
MCFG_CENTRONICS_BUSY_HANDLER(WRITELINE(thomson_state, write_centronics_busy))
MCFG_MC6846_MODIFY( "mc6846", to9p_timer )
MCFG_DEVICE_MODIFY("mc6846")
MCFG_MC6846_OUT_PORT_CB(WRITE8(thomson_state, to9p_timer_port_out))
MCFG_MC6846_OUT_CP2_CB(WRITE8(thomson_state, to8_timer_cp2_out))
MCFG_MC6846_IN_PORT_CB(READ8(thomson_state, to9p_timer_port_in))
/* internal ram */
MCFG_RAM_MODIFY(RAM_TAG)
MCFG_RAM_DEFAULT_SIZE("512K")

View File

@ -558,18 +558,6 @@ protected:
void to7_midi_ready_to_send_cb( );
};
/*----------- defined in machine/thomson.c -----------*/
extern const mc6846_interface to7_timer;
extern const mc6846_interface to770_timer;
extern const mc6846_interface to9_timer;
/***************************** TO8 ******************************/
extern const mc6846_interface to8_timer;
extern const mc6846_interface to9p_timer;
/*----------- defined in video/thomson.c -----------*/
/*

View File

@ -508,19 +508,6 @@ WRITE8_MEMBER( thomson_state::to7_timer_tco_out )
}
const mc6846_interface to7_timer =
{
DEVCB_DRIVER_MEMBER(thomson_state, to7_timer_port_out),
DEVCB_NULL,
DEVCB_DRIVER_MEMBER(thomson_state, to7_timer_cp2_out),
DEVCB_DRIVER_MEMBER(thomson_state, to7_timer_port_in),
DEVCB_DRIVER_MEMBER(thomson_state, to7_timer_tco_out),
DEVCB_DRIVER_LINE_MEMBER(thomson_state, thom_dev_irq_0)
};
/* ------------ lightpen automaton ------------ */
@ -1463,19 +1450,6 @@ WRITE8_MEMBER( thomson_state::to770_timer_port_out )
}
const mc6846_interface to770_timer =
{
DEVCB_DRIVER_MEMBER(thomson_state, to770_timer_port_out),
DEVCB_NULL,
DEVCB_DRIVER_MEMBER(thomson_state, to7_timer_cp2_out),
DEVCB_DRIVER_MEMBER(thomson_state, to7_timer_port_in),
DEVCB_DRIVER_MEMBER(thomson_state, to7_timer_tco_out),
DEVCB_DRIVER_LINE_MEMBER(thomson_state, thom_dev_irq_0)
};
/* ------------ gate-array ------------ */
@ -2845,19 +2819,6 @@ WRITE8_MEMBER( thomson_state::to9_timer_port_out )
}
const mc6846_interface to9_timer =
{
DEVCB_DRIVER_MEMBER(thomson_state, to9_timer_port_out),
DEVCB_NULL,
DEVCB_DRIVER_MEMBER(thomson_state, to7_timer_cp2_out),
DEVCB_DRIVER_MEMBER(thomson_state, to7_timer_port_in),
DEVCB_DRIVER_MEMBER(thomson_state, to7_timer_tco_out),
DEVCB_DRIVER_LINE_MEMBER(thomson_state, thom_dev_irq_0)
};
/* ------------ init / reset ------------ */
@ -3847,20 +3808,6 @@ WRITE8_MEMBER( thomson_state::to8_timer_cp2_out )
to7_game_sound_update();
}
const mc6846_interface to8_timer =
{
DEVCB_DRIVER_MEMBER(thomson_state, to8_timer_port_out),
DEVCB_NULL,
DEVCB_DRIVER_MEMBER(thomson_state, to8_timer_cp2_out),
DEVCB_DRIVER_MEMBER(thomson_state, to8_timer_port_in),
DEVCB_DRIVER_MEMBER(thomson_state, to7_timer_tco_out),
DEVCB_DRIVER_LINE_MEMBER(thomson_state, thom_dev_irq_0)
};
/* ------------ lightpen ------------ */
@ -4032,24 +3979,8 @@ WRITE8_MEMBER( thomson_state::to9p_timer_port_out )
to8_update_cart_bank();
}
const mc6846_interface to9p_timer =
{
DEVCB_DRIVER_MEMBER(thomson_state, to9p_timer_port_out),
DEVCB_NULL,
DEVCB_DRIVER_MEMBER(thomson_state, to8_timer_cp2_out),
DEVCB_DRIVER_MEMBER(thomson_state, to9p_timer_port_in),
DEVCB_DRIVER_MEMBER(thomson_state, to7_timer_tco_out),
DEVCB_DRIVER_LINE_MEMBER(thomson_state, thom_dev_irq_0)
};
/* ------------ init / reset ------------ */
MACHINE_RESET_MEMBER( thomson_state, to9p )
{
LOG (( "to9p: machine reset called\n" ));