updated adc1038 to use delegates and inline configs. nw.

This commit is contained in:
Fabio Priuli 2014-04-13 13:12:39 +00:00
parent b58021499c
commit 94220382ed
3 changed files with 41 additions and 65 deletions

View File

@ -14,37 +14,18 @@
const device_type ADC1038 = &device_creator<adc1038_device>;
adc1038_device::adc1038_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
: device_t(mconfig, ADC1038, "ADC1038", tag, owner, clock, "adc1038", __FILE__)
: device_t(mconfig, ADC1038, "ADC1038", tag, owner, clock, "adc1038", __FILE__),
m_gticlub_hack(0)
{
}
//-------------------------------------------------
// device_config_complete - perform any
// operations now that the configuration is
// complete
//-------------------------------------------------
void adc1038_device::device_config_complete()
{
// inherit a copy of the static data
const adc1038_interface *intf = reinterpret_cast<const adc1038_interface *>(static_config());
if (intf != NULL)
*static_cast<adc1038_interface *>(this) = *intf;
// or initialize to defaults if none provided
else
{
input_callback_r = NULL;
}
}
//-------------------------------------------------
// device_start - device-specific startup
//-------------------------------------------------
void adc1038_device::device_start()
{
m_input_callback_r_func = input_callback_r;
m_input_cb.bind_relative_to(*owner());
save_item(NAME(m_cycle));
save_item(NAME(m_clk));
@ -98,7 +79,7 @@ WRITE_LINE_MEMBER( adc1038_device::clk_write )
m_cycle = 0;
/* notice that m_adr is always < 7! */
m_adc_data = m_input_callback_r_func(this, m_adr);
m_adc_data = m_input_cb(m_adr);
}
}
@ -131,7 +112,7 @@ READ_LINE_MEMBER( adc1038_device::sars_read )
m_cycle = 0;
/* notice that m_adr is always < 7! */
m_adc_data = m_input_callback_r_func(this, m_adr);
m_adc_data = m_input_cb(m_adr);
m_sars ^= 1;
return m_sars;

View File

@ -10,32 +10,26 @@
#ifndef __ADC1038_H__
#define __ADC1038_H__
/***************************************************************************
TYPE DEFINITIONS
***************************************************************************/
typedef int (*adc1038_input_read_func)(device_t *device, int input);
struct adc1038_interface
{
int m_gticlub_hack;
adc1038_input_read_func input_callback_r;
};
typedef device_delegate<int (int input)> adc1038_input_delegate;
#define ADC1038_INPUT_CB(name) int name(int input)
/***************************************************************************
MACROS / CONSTANTS
***************************************************************************/
class adc1038_device : public device_t,
public adc1038_interface
class adc1038_device : public device_t
{
public:
adc1038_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
~adc1038_device() {}
static void set_input_callback(device_t &device, adc1038_input_delegate callback) { downcast<adc1038_device &>(device).m_input_cb = callback; }
static void set_gti_club_hack(device_t &device, int hack) { downcast<adc1038_device &>(device).m_gticlub_hack = hack; }
DECLARE_READ_LINE_MEMBER( do_read );
DECLARE_READ_LINE_MEMBER( sars_read );
DECLARE_WRITE_LINE_MEMBER( di_write );
@ -43,13 +37,10 @@ public:
protected:
// device-level overrides
virtual void device_config_complete();
virtual void device_start();
virtual void device_reset();
adc1038_input_read_func m_input_callback_r_func;
private:
private:
// internal state
int m_cycle;
int m_clk;
@ -58,14 +49,19 @@ protected:
int m_data_out;
int m_adc_data;
int m_sars;
int m_gticlub_hack;
adc1038_input_delegate m_input_cb;
};
extern const device_type ADC1038;
#define MCFG_ADC1038_ADD(_tag, _config) \
MCFG_DEVICE_ADD(_tag, ADC1038, 0) \
MCFG_DEVICE_CONFIG(_config)
#define MCFG_ADC1038_INPUT_CB(_class, _method) \
adc1038_device::set_input_callback(*device, adc1038_input_delegate(&_class::_method, #_class "::" #_method, downcast<_class *>(owner)));
#define MCFG_ADC1038_GTIHACK(_hack) \
adc1038_device::set_gti_club_hack(*device, _hack);
#endif /* __ADC1038_H__ */

View File

@ -248,6 +248,10 @@ public:
m_dsp2(*this, "dsp2"),
m_k056800(*this, "k056800"),
m_adc1038(*this, "adc1038"),
m_analog0(*this, "AN0"),
m_analog1(*this, "AN1"),
m_analog2(*this, "AN2"),
m_analog3(*this, "AN3"),
m_eeprom(*this, "eeprom"),
m_palette(*this, "palette") { }
@ -261,6 +265,7 @@ public:
optional_device<cpu_device> m_dsp2;
required_device<k056800_device> m_k056800;
required_device<adc1038_device> m_adc1038;
required_ioport m_analog0, m_analog1, m_analog2, m_analog3;
required_device<eeprom_serial_93cxx_device> m_eeprom;
required_device<palette_device> m_palette;
@ -293,6 +298,8 @@ public:
INTERRUPT_GEN_MEMBER(gticlub_vblank);
TIMER_CALLBACK_MEMBER(sound_irq);
ADC1038_INPUT_CB(adc1038_input_callback);
UINT32 screen_update_gticlub(screen_device &screen, bitmap_rgb32 &bitmap, const rectangle &cliprect);
UINT32 screen_update_hangplt(screen_device &screen, bitmap_rgb32 &bitmap, const rectangle &cliprect);
@ -750,15 +757,15 @@ INTERRUPT_GEN_MEMBER(gticlub_state::gticlub_vblank)
}
static int adc1038_input_callback( device_t *device, int input )
ADC1038_INPUT_CB(gticlub_state::adc1038_input_callback)
{
int value = 0;
switch (input)
{
case 0: value = device->machine().root_device().ioport("AN0")->read(); break;
case 1: value = device->machine().root_device().ioport("AN1")->read(); break;
case 2: value = device->machine().root_device().ioport("AN2")->read(); break;
case 3: value = device->machine().root_device().ioport("AN3")->read(); break;
case 0: value = m_analog0->read(); break;
case 1: value = m_analog1->read(); break;
case 2: value = m_analog2->read(); break;
case 3: value = m_analog3->read(); break;
case 4: value = 0x000; break;
case 5: value = 0x000; break;
case 6: value = 0x000; break;
@ -768,19 +775,6 @@ static int adc1038_input_callback( device_t *device, int input )
return value;
}
static const adc1038_interface gticlub_adc1038_intf =
{
1,
adc1038_input_callback
};
static const adc1038_interface thunderh_adc1038_intf =
{
0,
adc1038_input_callback
};
MACHINE_RESET_MEMBER(gticlub_state,gticlub)
{
m_dsp->set_input_line(INPUT_LINE_RESET, ASSERT_LINE);
@ -926,7 +920,9 @@ static MACHINE_CONFIG_START( gticlub, gticlub_state )
MCFG_MACHINE_START_OVERRIDE(gticlub_state,gticlub)
MCFG_MACHINE_RESET_OVERRIDE(gticlub_state,gticlub)
MCFG_ADC1038_ADD("adc1038", gticlub_adc1038_intf)
MCFG_DEVICE_ADD("adc1038", ADC1038, 0)
MCFG_ADC1038_INPUT_CB(gticlub_state, adc1038_input_callback)
MCFG_ADC1038_GTIHACK(1)
MCFG_DEVICE_ADD("k056230", K056230, 0)
MCFG_K056230_CPU("maincpu")
@ -966,7 +962,8 @@ MACHINE_CONFIG_END
static MACHINE_CONFIG_DERIVED( thunderh, gticlub )
MCFG_DEVICE_REMOVE("adc1038")
MCFG_ADC1038_ADD("adc1038", thunderh_adc1038_intf)
MCFG_DEVICE_ADD("adc1038", ADC1038, 0)
MCFG_ADC1038_INPUT_CB(gticlub_state, adc1038_input_callback)
MCFG_DEVICE_REMOVE("k056230")
MCFG_DEVICE_ADD("k056230", K056230, 0)
@ -977,7 +974,8 @@ MACHINE_CONFIG_END
static MACHINE_CONFIG_DERIVED( slrasslt, gticlub )
MCFG_DEVICE_REMOVE("adc1038")
MCFG_ADC1038_ADD("adc1038", thunderh_adc1038_intf)
MCFG_DEVICE_ADD("adc1038", ADC1038, 0)
MCFG_ADC1038_INPUT_CB(gticlub_state, adc1038_input_callback)
MCFG_DEVICE_REMOVE("k001604_1")
MCFG_DEVICE_ADD("k001604_1", K001604, 0)
@ -1044,7 +1042,8 @@ static MACHINE_CONFIG_START( hangplt, gticlub_state )
MCFG_MACHINE_START_OVERRIDE(gticlub_state,gticlub)
MCFG_MACHINE_RESET_OVERRIDE(gticlub_state,hangplt)
MCFG_ADC1038_ADD("adc1038", thunderh_adc1038_intf)
MCFG_DEVICE_ADD("adc1038", ADC1038, 0)
MCFG_ADC1038_INPUT_CB(gticlub_state, adc1038_input_callback)
MCFG_DEVICE_ADD("k056230", K056230, 0)
MCFG_K056230_CPU("maincpu")