mirror of
https://github.com/holub/mame
synced 2025-10-05 16:50:57 +03:00
adc0808_device: converted to devcb2 and delegates (nw)
This commit is contained in:
parent
7329c4038a
commit
a21e17e8cb
@ -28,6 +28,7 @@ const device_type ADC0808 = &device_creator<adc0808_device>;
|
||||
|
||||
adc0808_device::adc0808_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
|
||||
: device_t(mconfig, ADC0808, "ADC0808", tag, owner, clock, "adc0808", __FILE__),
|
||||
m_out_eoc_cb(*this),
|
||||
m_address(0),
|
||||
m_start(0),
|
||||
m_eoc(0),
|
||||
@ -37,28 +38,6 @@ adc0808_device::adc0808_device(const machine_config &mconfig, const char *tag, d
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------
|
||||
// device_config_complete - perform any
|
||||
// operations now that the configuration is
|
||||
// complete
|
||||
//-------------------------------------------------
|
||||
|
||||
void adc0808_device::device_config_complete()
|
||||
{
|
||||
// inherit a copy of the static data
|
||||
const adc0808_interface *intf = reinterpret_cast<const adc0808_interface *>(static_config());
|
||||
if (intf != NULL)
|
||||
*static_cast<adc0808_interface *>(this) = *intf;
|
||||
|
||||
// or initialize to defaults if none provided
|
||||
else
|
||||
{
|
||||
memset(&m_out_eoc_cb, 0, sizeof(m_out_eoc_cb));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------
|
||||
// device_start - device-specific startup
|
||||
//-------------------------------------------------
|
||||
@ -66,7 +45,17 @@ void adc0808_device::device_config_complete()
|
||||
void adc0808_device::device_start()
|
||||
{
|
||||
// resolve callbacks
|
||||
m_out_eoc_func.resolve(m_out_eoc_cb, *this);
|
||||
m_out_eoc_cb.resolve_safe();
|
||||
m_in_vref_pos_cb.bind_relative_to(*owner());
|
||||
m_in_vref_neg_cb.bind_relative_to(*owner());
|
||||
m_in_in_0_cb.bind_relative_to(*owner());
|
||||
m_in_in_1_cb.bind_relative_to(*owner());
|
||||
m_in_in_2_cb.bind_relative_to(*owner());
|
||||
m_in_in_3_cb.bind_relative_to(*owner());
|
||||
m_in_in_4_cb.bind_relative_to(*owner());
|
||||
m_in_in_5_cb.bind_relative_to(*owner());
|
||||
m_in_in_6_cb.bind_relative_to(*owner());
|
||||
m_in_in_7_cb.bind_relative_to(*owner());
|
||||
|
||||
// allocate timers
|
||||
m_cycle_timer = timer_alloc();
|
||||
@ -98,11 +87,39 @@ void adc0808_device::device_timer(emu_timer &timer, device_timer_id id, int para
|
||||
if (m_bit == 8)
|
||||
{
|
||||
/* sample input */
|
||||
double vref_pos = m_in_vref_pos_func(this);
|
||||
double vref_neg = m_in_vref_neg_func(this);
|
||||
|
||||
double input = m_in_in_func[m_address](this);
|
||||
|
||||
double vref_pos = m_in_vref_pos_cb();
|
||||
double vref_neg = m_in_vref_neg_cb();
|
||||
|
||||
double input = 0;
|
||||
|
||||
switch (m_address)
|
||||
{
|
||||
case 0:
|
||||
input = m_in_in_0_cb();
|
||||
break;
|
||||
case 1:
|
||||
input = m_in_in_1_cb();
|
||||
break;
|
||||
case 2:
|
||||
input = m_in_in_2_cb();
|
||||
break;
|
||||
case 3:
|
||||
input = m_in_in_3_cb();
|
||||
break;
|
||||
case 4:
|
||||
input = m_in_in_4_cb();
|
||||
break;
|
||||
case 5:
|
||||
input = m_in_in_5_cb();
|
||||
break;
|
||||
case 6:
|
||||
input = m_in_in_6_cb();
|
||||
break;
|
||||
case 7:
|
||||
input = m_in_in_7_cb();
|
||||
break;
|
||||
break;
|
||||
}
|
||||
m_sar = (255 * (input - vref_neg)) / (vref_pos - vref_neg);
|
||||
|
||||
/* trigger end of conversion */
|
||||
@ -116,7 +133,7 @@ void adc0808_device::device_timer(emu_timer &timer, device_timer_id id, int para
|
||||
/* set end of conversion pin */
|
||||
if (m_next_eoc != m_eoc)
|
||||
{
|
||||
m_out_eoc_func(m_next_eoc);
|
||||
m_out_eoc_cb(m_next_eoc);
|
||||
m_eoc = m_next_eoc;
|
||||
}
|
||||
}
|
||||
|
@ -55,31 +55,62 @@
|
||||
|
||||
// ======================> adc0808_analog_read
|
||||
|
||||
typedef double (*adc0808_analog_read) (device_t *device);
|
||||
#define ADC0808_ANALOG_READ(name) double name(device_t *device)
|
||||
typedef device_delegate<double ()> adc0808_analog_read_delegate;
|
||||
#define ADC0808_ANALOG_READ_CB(name) double name()
|
||||
|
||||
|
||||
// ======================> adc0808_interface
|
||||
|
||||
struct adc0808_interface
|
||||
{
|
||||
devcb_write_line m_out_eoc_cb;
|
||||
|
||||
adc0808_analog_read m_in_vref_pos_func;
|
||||
adc0808_analog_read m_in_vref_neg_func;
|
||||
|
||||
adc0808_analog_read m_in_in_func[8];
|
||||
};
|
||||
#define MCFG_ADC0808_OUT_EOC_CB(_devcb) \
|
||||
devcb = &adc0808_device::set_out_eoc_callback(*device, DEVCB2_##_devcb);
|
||||
|
||||
#define MCFG_ADC0808_IN_VREF_POS_CB(_class, _method) \
|
||||
adc0808_device::set_in_vref_pos_callback(*device, adc0808_analog_read_delegate(&_class::_method, #_class "::" #_method, downcast<_class *>(owner)));
|
||||
|
||||
#define MCFG_ADC0808_IN_VREF_NEG_CB(_class, _method) \
|
||||
adc0808_device::set_in_vref_neg_callback(*device, adc0808_analog_read_delegate(&_class::_method, #_class "::" #_method, downcast<_class *>(owner)));
|
||||
|
||||
#define MCFG_ADC0808_IN_IN_0_CB(_class, _method) \
|
||||
adc0808_device::set_in_in_0_callback(*device, adc0808_analog_read_delegate(&_class::_method, #_class "::" #_method, downcast<_class *>(owner)));
|
||||
|
||||
#define MCFG_ADC0808_IN_IN_1_CB(_class, _method) \
|
||||
adc0808_device::set_in_in_1_callback(*device, adc0808_analog_read_delegate(&_class::_method, #_class "::" #_method, downcast<_class *>(owner)));
|
||||
|
||||
#define MCFG_ADC0808_IN_IN_2_CB(_class, _method) \
|
||||
adc0808_device::set_in_in_2_callback(*device, adc0808_analog_read_delegate(&_class::_method, #_class "::" #_method, downcast<_class *>(owner)));
|
||||
|
||||
#define MCFG_ADC0808_IN_IN_3_CB(_class, _method) \
|
||||
adc0808_device::set_in_in_3_callback(*device, adc0808_analog_read_delegate(&_class::_method, #_class "::" #_method, downcast<_class *>(owner)));
|
||||
|
||||
#define MCFG_ADC0808_IN_IN_4_CB(_class, _method) \
|
||||
adc0808_device::set_in_in_4_callback(*device, adc0808_analog_read_delegate(&_class::_method, #_class "::" #_method, downcast<_class *>(owner)));
|
||||
|
||||
#define MCFG_ADC0808_IN_IN_5_CB(_class, _method) \
|
||||
adc0808_device::set_in_in_5_callback(*device, adc0808_analog_read_delegate(&_class::_method, #_class "::" #_method, downcast<_class *>(owner)));
|
||||
|
||||
#define MCFG_ADC0808_IN_IN_6_CB(_class, _method) \
|
||||
adc0808_device::set_in_in_6_callback(*device, adc0808_analog_read_delegate(&_class::_method, #_class "::" #_method, downcast<_class *>(owner)));
|
||||
|
||||
#define MCFG_ADC0808_IN_IN_7_CB(_class, _method) \
|
||||
adc0808_device::set_in_in_7_callback(*device, adc0808_analog_read_delegate(&_class::_method, #_class "::" #_method, downcast<_class *>(owner)));
|
||||
|
||||
// ======================> adc0808_device
|
||||
|
||||
class adc0808_device : public device_t,
|
||||
public adc0808_interface
|
||||
class adc0808_device : public device_t
|
||||
{
|
||||
public:
|
||||
// construction/destruction
|
||||
adc0808_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
|
||||
|
||||
template<class _Object> static devcb2_base &set_out_eoc_callback(device_t &device, _Object object) { return downcast<adc0808_device &>(device).m_out_eoc_cb.set_callback(object); }
|
||||
static void set_in_vref_pos_callback(device_t &device, adc0808_analog_read_delegate callback) { downcast<adc0808_device &>(device).m_in_vref_pos_cb = callback; }
|
||||
static void set_in_vref_neg_callback(device_t &device, adc0808_analog_read_delegate callback) { downcast<adc0808_device &>(device).m_in_vref_neg_cb = callback; }
|
||||
static void set_in_in_0_callback(device_t &device, adc0808_analog_read_delegate callback) { downcast<adc0808_device &>(device).m_in_in_0_cb = callback; }
|
||||
static void set_in_in_1_callback(device_t &device, adc0808_analog_read_delegate callback) { downcast<adc0808_device &>(device).m_in_in_1_cb = callback; }
|
||||
static void set_in_in_2_callback(device_t &device, adc0808_analog_read_delegate callback) { downcast<adc0808_device &>(device).m_in_in_2_cb = callback; }
|
||||
static void set_in_in_3_callback(device_t &device, adc0808_analog_read_delegate callback) { downcast<adc0808_device &>(device).m_in_in_3_cb = callback; }
|
||||
static void set_in_in_4_callback(device_t &device, adc0808_analog_read_delegate callback) { downcast<adc0808_device &>(device).m_in_in_4_cb = callback; }
|
||||
static void set_in_in_5_callback(device_t &device, adc0808_analog_read_delegate callback) { downcast<adc0808_device &>(device).m_in_in_5_cb = callback; }
|
||||
static void set_in_in_6_callback(device_t &device, adc0808_analog_read_delegate callback) { downcast<adc0808_device &>(device).m_in_in_6_cb = callback; }
|
||||
static void set_in_in_7_callback(device_t &device, adc0808_analog_read_delegate callback) { downcast<adc0808_device &>(device).m_in_in_7_cb = callback; }
|
||||
|
||||
DECLARE_READ8_MEMBER( data_r );
|
||||
DECLARE_WRITE8_MEMBER( ale_w );
|
||||
@ -88,12 +119,21 @@ public:
|
||||
|
||||
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:
|
||||
devcb_resolved_write_line m_out_eoc_func;
|
||||
devcb2_write_line m_out_eoc_cb;
|
||||
adc0808_analog_read_delegate m_in_vref_pos_cb;
|
||||
adc0808_analog_read_delegate m_in_vref_neg_cb;
|
||||
adc0808_analog_read_delegate m_in_in_0_cb;
|
||||
adc0808_analog_read_delegate m_in_in_1_cb;
|
||||
adc0808_analog_read_delegate m_in_in_2_cb;
|
||||
adc0808_analog_read_delegate m_in_in_3_cb;
|
||||
adc0808_analog_read_delegate m_in_in_4_cb;
|
||||
adc0808_analog_read_delegate m_in_in_5_cb;
|
||||
adc0808_analog_read_delegate m_in_in_6_cb;
|
||||
adc0808_analog_read_delegate m_in_in_7_cb;
|
||||
|
||||
int m_address; // analog channel address
|
||||
int m_start; // start conversion pin
|
||||
|
@ -954,30 +954,21 @@ WRITE_LINE_MEMBER( newbrain_eim_state::adc_eoc_w )
|
||||
m_anint = state;
|
||||
}
|
||||
|
||||
static ADC0808_ANALOG_READ( newbrain_adc_vref_pos_r )
|
||||
ADC0808_ANALOG_READ_CB( newbrain_eim_state::adc_vref_pos_r )
|
||||
{
|
||||
return 5.0;
|
||||
}
|
||||
|
||||
static ADC0808_ANALOG_READ( newbrain_adc_vref_neg_r )
|
||||
ADC0808_ANALOG_READ_CB( newbrain_eim_state::adc_vref_neg_r )
|
||||
{
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
static ADC0808_ANALOG_READ( newbrain_adc_input_r )
|
||||
ADC0808_ANALOG_READ_CB( newbrain_eim_state::adc_input_r )
|
||||
{
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
static ADC0808_INTERFACE( adc_intf )
|
||||
{
|
||||
DEVCB_DRIVER_LINE_MEMBER(newbrain_eim_state, adc_eoc_w),
|
||||
newbrain_adc_vref_pos_r,
|
||||
newbrain_adc_vref_neg_r,
|
||||
{ newbrain_adc_input_r, newbrain_adc_input_r, newbrain_adc_input_r, newbrain_adc_input_r,
|
||||
newbrain_adc_input_r, newbrain_adc_input_r, newbrain_adc_input_r, newbrain_adc_input_r }
|
||||
};
|
||||
|
||||
/* Memory Maps */
|
||||
|
||||
static ADDRESS_MAP_START( newbrain_map, AS_PROGRAM, 8, newbrain_state )
|
||||
@ -1378,7 +1369,18 @@ static MACHINE_CONFIG_DERIVED_CLASS( newbrain_eim, newbrain_a, newbrain_eim_stat
|
||||
MCFG_Z80CTC_ZC2_CB(WRITELINE(newbrain_eim_state, ctc_z2_w))
|
||||
|
||||
MCFG_TIMER_DRIVER_ADD_PERIODIC("z80ctc_c2", newbrain_eim_state, ctc_c2_tick, attotime::from_hz(XTAL_16MHz/4/13))
|
||||
MCFG_ADC0808_ADD(ADC0809_TAG, 500000, adc_intf)
|
||||
MCFG_DEVICE_ADD(ADC0809_TAG, ADC0808, 500000)
|
||||
MCFG_ADC0808_OUT_EOC_CB(WRITELINE(newbrain_eim_state, adc_eoc_w))
|
||||
MCFG_ADC0808_IN_VREF_POS_CB(newbrain_eim_state, adc_vref_pos_r)
|
||||
MCFG_ADC0808_IN_VREF_NEG_CB(newbrain_eim_state, adc_vref_neg_r)
|
||||
MCFG_ADC0808_IN_IN_0_CB(newbrain_eim_state, adc_input_r)
|
||||
MCFG_ADC0808_IN_IN_1_CB(newbrain_eim_state, adc_input_r)
|
||||
MCFG_ADC0808_IN_IN_2_CB(newbrain_eim_state, adc_input_r)
|
||||
MCFG_ADC0808_IN_IN_3_CB(newbrain_eim_state, adc_input_r)
|
||||
MCFG_ADC0808_IN_IN_4_CB(newbrain_eim_state, adc_input_r)
|
||||
MCFG_ADC0808_IN_IN_5_CB(newbrain_eim_state, adc_input_r)
|
||||
MCFG_ADC0808_IN_IN_6_CB(newbrain_eim_state, adc_input_r)
|
||||
MCFG_ADC0808_IN_IN_7_CB(newbrain_eim_state, adc_input_r)
|
||||
|
||||
MCFG_DEVICE_ADD(MC6850_TAG, ACIA6850, 0)
|
||||
MCFG_ACIA6850_TXD_HANDLER(WRITELINE(newbrain_eim_state, acia_tx))
|
||||
|
@ -249,6 +249,10 @@ public:
|
||||
DECLARE_WRITE_LINE_MEMBER( ctc_z2_w );
|
||||
DECLARE_WRITE_LINE_MEMBER( adc_eoc_w );
|
||||
|
||||
ADC0808_ANALOG_READ_CB(adc_vref_pos_r);
|
||||
ADC0808_ANALOG_READ_CB(adc_vref_neg_r);
|
||||
ADC0808_ANALOG_READ_CB(adc_input_r);
|
||||
|
||||
TIMER_DEVICE_CALLBACK_MEMBER(ctc_c2_tick);
|
||||
|
||||
void bankswitch();
|
||||
|
Loading…
Reference in New Issue
Block a user