adc12138: updated to use delegates and slightly reduced tagmap lookups in

hornet and nwk-tr while at it. nw.
This commit is contained in:
Fabio Priuli 2014-04-14 07:13:04 +00:00
parent 35b65418d5
commit d1f6e90a97
4 changed files with 69 additions and 86 deletions

View File

@ -59,27 +59,6 @@ adc12138_device::adc12138_device(const machine_config &mconfig, device_type type
{
}
//-------------------------------------------------
// device_config_complete - perform any
// operations now that the configuration is
// complete
//-------------------------------------------------
void adc12138_device::device_config_complete()
{
// inherit a copy of the static data
const adc12138_interface *intf = reinterpret_cast<const adc12138_interface *>(static_config());
if (intf != NULL)
*static_cast<adc12138_interface *>(this) = *intf;
// or initialize to defaults if none provided
else
{
input_callback_r = NULL;
}
}
//-------------------------------------------------
// device_start - device-specific startup
//-------------------------------------------------
@ -96,7 +75,7 @@ void adc12138_device::device_start()
m_end_conv = 0;
/* resolve callbacks */
m_input_callback_r_func = input_callback_r;
m_ipt_read_cb.bind_relative_to(*owner());
/* register for state saving */
save_item(NAME(m_cycle));
@ -144,7 +123,6 @@ WRITE8_MEMBER( adc12138_device::di_w )
void adc12138_device::convert(int channel, int bits16, int lsbfirst)
{
int i;
int bits;
int input_value;
double input = 0;
@ -159,42 +137,42 @@ void adc12138_device::convert(int channel, int bits16, int lsbfirst)
{
case 0x8: // H L L L - CH0 (single-ended)
{
input = m_input_callback_r_func(this, 0);
input = m_ipt_read_cb(0);
break;
}
case 0xc: // H H L L - CH1 (single-ended)
{
input = m_input_callback_r_func(this, 1);
input = m_ipt_read_cb(1);
break;
}
case 0x9: // H L L H - CH2 (single-ended)
{
input = m_input_callback_r_func(this, 2);
input = m_ipt_read_cb(2);
break;
}
case 0xd: // H H L H - CH3 (single-ended)
{
input = m_input_callback_r_func(this, 3);
input = m_ipt_read_cb(3);
break;
}
case 0xa: // H L H L - CH4 (single-ended)
{
input = m_input_callback_r_func(this, 4);
input = m_ipt_read_cb(4);
break;
}
case 0xe: // H H H L - CH5 (single-ended)
{
input = m_input_callback_r_func(this, 5);
input = m_ipt_read_cb(5);
break;
}
case 0xb: // H L H H - CH6 (single-ended)
{
input = m_input_callback_r_func(this, 6);
input = m_ipt_read_cb(6);
break;
}
case 0xf: // H H H H - CH7 (single-ended)
{
input = m_input_callback_r_func(this, 7);
input = m_ipt_read_cb(7);
break;
}
default:
@ -216,9 +194,9 @@ void adc12138_device::convert(int channel, int bits16, int lsbfirst)
m_output_shift_reg = 0;
for (i=0; i < bits; i++)
for (int i = 0; i < bits; i++)
{
if (input_value & (1 << ((bits-1) - i)))
if (input_value & (1 << ((bits - 1) - i)))
{
m_output_shift_reg |= (1 << i);
}

View File

@ -15,25 +15,22 @@
TYPE DEFINITIONS
***************************************************************************/
typedef double (*adc1213x_input_convert_func)(device_t *device, UINT8 input);
struct adc12138_interface
{
adc1213x_input_convert_func input_callback_r;
};
typedef device_delegate<double (UINT8 input)> adc1213x_ipt_convert_delegate;
#define ADC12138_IPT_CONVERT_CB(name) double name(UINT8 input)
/***************************************************************************
MACROS / CONSTANTS
***************************************************************************/
class adc12138_device : public device_t,
public adc12138_interface
class adc12138_device : public device_t
{
public:
adc12138_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
adc12138_device(const machine_config &mconfig, device_type type, const char *name, const char *tag, device_t *owner, UINT32 clock, const char *shortname, const char *source);
~adc12138_device() {}
static void set_ipt_convert_callback(device_t &device, adc1213x_ipt_convert_delegate callback) { downcast<adc12138_device &>(device).m_ipt_read_cb = callback; }
DECLARE_WRITE8_MEMBER( di_w );
DECLARE_WRITE8_MEMBER( cs_w );
DECLARE_WRITE8_MEMBER( sclk_w );
@ -43,15 +40,14 @@ public:
protected:
// device-level overrides
virtual void device_config_complete();
virtual void device_start();
virtual void device_reset();
void convert(int channel, int bits16, int lsbfirst);
adc1213x_input_convert_func m_input_callback_r_func;
adc1213x_ipt_convert_delegate m_ipt_read_cb;
private:
private:
// internal state
int m_cycle;
int m_data_out;
@ -84,17 +80,8 @@ public:
extern const device_type ADC12132;
#define MCFG_ADC12130_ADD(_tag, _config) \
MCFG_DEVICE_ADD(_tag, ADC12130, 0) \
MCFG_DEVICE_CONFIG(_config)
#define MCFG_ADC12132_ADD(_tag, _config) \
MCFG_DEVICE_ADD(_tag, ADC12132, 0) \
MCFG_DEVICE_CONFIG(_config)
#define MCFG_ADC12138_ADD(_tag, _config) \
MCFG_DEVICE_ADD(_tag, ADC12138, 0) \
MCFG_DEVICE_CONFIG(_config)
#define MCFG_ADC1213X_IPT_CONVERT_CB(_class, _method) \
adc12138_device::set_ipt_convert_callback(*device, adc1213x_ipt_convert_delegate(&_class::_method, #_class "::" #_method, downcast<_class *>(owner)));
#endif /* __ADC1213X_H__ */

View File

@ -341,7 +341,14 @@ public:
m_eeprom(*this, "eeprom"),
m_k037122_1(*this, "k037122_1"),
m_k037122_2(*this, "k037122_2" ),
m_adc12138(*this, "adc12138") { }
m_adc12138(*this, "adc12138"),
m_in0(*this, "IN0"),
m_in1(*this, "IN1"),
m_in2(*this, "IN2"),
m_dsw(*this, "DSW"),
m_eepromout(*this, "EEPROMOUT"),
m_analog1(*this, "ANALOG1"),
m_analog2(*this, "ANALOG2"){ }
// TODO: Needs verification on real hardware
static const int m_sound_timer_usec = 2800;
@ -359,6 +366,8 @@ public:
optional_device<k037122_device> m_k037122_1;
optional_device<k037122_device> m_k037122_2;
required_device<adc12138_device> m_adc12138;
required_ioport m_in0, m_in1, m_in2, m_dsw, m_eepromout;
optional_ioport m_analog1, m_analog2;
emu_timer *m_sound_irq_timer;
UINT8 m_led_reg0;
@ -393,6 +402,7 @@ public:
DECLARE_WRITE_LINE_MEMBER(voodoo_vblank_1);
DECLARE_WRITE16_MEMBER(soundtimer_en_w);
DECLARE_WRITE16_MEMBER(soundtimer_count_w);
ADC12138_IPT_CONVERT_CB(adc12138_input_callback);
DECLARE_DRIVER_INIT(hornet);
DECLARE_DRIVER_INIT(hornet_2board);
@ -498,13 +508,17 @@ UINT32 hornet_state::screen_update_hornet_2board(screen_device &screen, bitmap_r
READ8_MEMBER(hornet_state::sysreg_r)
{
UINT8 r = 0;
static const char *const portnames[] = { "IN0", "IN1", "IN2" };
switch (offset)
{
case 0: /* I/O port 0 */
r = m_in0->read();
break;
case 1: /* I/O port 1 */
r = m_in1->read();
break;
case 2: /* I/O port 2 */
r = ioport(portnames[offset])->read();
r = m_in2->read();
break;
case 3: /* I/O port 3 */
@ -522,7 +536,7 @@ READ8_MEMBER(hornet_state::sysreg_r)
break;
case 4: /* I/O port 4 - DIP switches */
r = ioport("DSW")->read();
r = m_dsw->read();
break;
}
return r;
@ -555,7 +569,7 @@ WRITE8_MEMBER(hornet_state::sysreg_w)
0x02 = LAMP1
0x01 = LAMP0
*/
ioport("EEPROMOUT")->write(data, 0xff);
m_eepromout->write(data, 0xff);
mame_printf_debug("System register 0 = %02X\n", data);
break;
@ -932,22 +946,18 @@ void hornet_state::machine_reset()
membank("bank5")->set_base(usr5);
}
static double adc12138_input_callback( device_t *device, UINT8 input )
ADC12138_IPT_CONVERT_CB(hornet_state::adc12138_input_callback)
{
int value = 0;
switch (input)
{
case 0: value = device->machine().root_device().ioport("ANALOG1")->read(); break;
case 1: value = device->machine().root_device().ioport("ANALOG2")->read(); break;
case 0: value = (m_analog1) ? m_analog1->read() : 0; break;
case 1: value = (m_analog2) ? m_analog2->read() : 0; break;
}
return (double)(value) / 2047.0;
}
static const adc12138_interface hornet_adc_interface = {
adc12138_input_callback
};
static const voodoo_config hornet_voodoo_intf =
{
2, // fbmem;
@ -1009,7 +1019,8 @@ static MACHINE_CONFIG_START( hornet, hornet_state )
MCFG_M48T58_ADD( "m48t58" )
MCFG_ADC12138_ADD( "adc12138", hornet_adc_interface )
MCFG_DEVICE_ADD("adc12138", ADC12138, 0)
MCFG_ADC1213X_IPT_CONVERT_CB(hornet_state, adc12138_input_callback)
MACHINE_CONFIG_END

View File

@ -238,6 +238,15 @@ public:
m_k056800(*this, "k056800"),
m_k001604(*this, "k001604"),
m_adc12138(*this, "adc12138"),
m_in0(*this, "IN0"),
m_in1(*this, "IN1"),
m_in2(*this, "IN2"),
m_dsw(*this, "DSW"),
m_analog1(*this, "ANALOG1"),
m_analog2(*this, "ANALOG2"),
m_analog3(*this, "ANALOG3"),
m_analog4(*this, "ANALOG4"),
m_analog5(*this, "ANALOG5"),
m_palette(*this, "palette") { }
// TODO: Needs verification on real hardware
@ -252,6 +261,7 @@ public:
required_device<k056800_device> m_k056800;
required_device<k001604_device> m_k001604;
required_device<adc12138_device> m_adc12138;
required_ioport m_in0, m_in1, m_in2, m_dsw, m_analog1, m_analog2, m_analog3, m_analog4, m_analog5;
required_device<palette_device> m_palette;
emu_timer *m_sound_irq_timer;
int m_fpga_uploaded;
@ -271,6 +281,8 @@ public:
DECLARE_WRITE16_MEMBER(soundtimer_en_w);
DECLARE_WRITE16_MEMBER(soundtimer_count_w);
DECLARE_WRITE_LINE_MEMBER(voodoo_vblank_0);
ADC12138_IPT_CONVERT_CB(adc12138_input_callback);
TIMER_CALLBACK_MEMBER(sound_irq);
DECLARE_DRIVER_INIT(nwktr);
virtual void machine_start();
@ -282,8 +294,6 @@ public:
WRITE32_MEMBER(nwktr_state::paletteram32_w)
{
COMBINE_DATA(&m_generic_paletteram_32[offset]);
@ -324,15 +334,15 @@ READ32_MEMBER(nwktr_state::sysreg_r)
{
if (ACCESSING_BITS_24_31)
{
r |= ioport("IN0")->read() << 24;
r |= m_in0->read() << 24;
}
if (ACCESSING_BITS_16_23)
{
r |= ioport("IN1")->read() << 16;
r |= m_in1->read() << 16;
}
if (ACCESSING_BITS_8_15)
{
r |= ioport("IN2")->read() << 8;
r |= m_in2->read() << 8;
}
if (ACCESSING_BITS_0_7)
{
@ -343,7 +353,7 @@ READ32_MEMBER(nwktr_state::sysreg_r)
{
if (ACCESSING_BITS_24_31)
{
r |= ioport("DSW")->read() << 24;
r |= m_dsw->read() << 24;
}
}
return r;
@ -689,26 +699,21 @@ static INPUT_PORTS_START( nwktr )
INPUT_PORTS_END
static double adc12138_input_callback( device_t *device, UINT8 input )
ADC12138_IPT_CONVERT_CB(nwktr_state::adc12138_input_callback)
{
int value = 0;
switch (input)
{
case 0: value = device->machine().root_device().ioport("ANALOG1")->read(); break;
case 1: value = device->machine().root_device().ioport("ANALOG2")->read(); break;
case 2: value = device->machine().root_device().ioport("ANALOG3")->read(); break;
case 3: value = device->machine().root_device().ioport("ANALOG4")->read(); break;
case 4: value = device->machine().root_device().ioport("ANALOG5")->read(); break;
case 0: value = m_analog1->read(); break;
case 1: value = m_analog2->read(); break;
case 2: value = m_analog3->read(); break;
case 3: value = m_analog4->read(); break;
case 4: value = m_analog5->read(); break;
}
return (double)(value) / 4095.0;
}
static const adc12138_interface nwktr_adc_interface = {
adc12138_input_callback
};
void nwktr_state::machine_reset()
{
m_dsp->set_input_line(INPUT_LINE_RESET, ASSERT_LINE);
@ -741,7 +746,9 @@ static MACHINE_CONFIG_START( nwktr, nwktr_state )
MCFG_QUANTUM_TIME(attotime::from_hz(9000))
MCFG_M48T58_ADD( "m48t58" )
MCFG_ADC12138_ADD( "adc12138", nwktr_adc_interface )
MCFG_DEVICE_ADD("adc12138", ADC12138, 0)
MCFG_ADC1213X_IPT_CONVERT_CB(nwktr_state, adc12138_input_callback)
MCFG_DEVICE_ADD("k033906_1", K033906, 0)
MCFG_K033906_VOODOO("voodoo")