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

konamigx and zr107 while at it. nw.
This commit is contained in:
Fabio Priuli 2014-04-14 09:43:48 +00:00
parent 8e6d64c060
commit e4ec4b0ffb
7 changed files with 78 additions and 47 deletions

View File

@ -98,6 +98,9 @@ void adc083x_device::device_start()
{
clear_sars();
/* resolve callbacks */
m_input_callback.bind_relative_to(*owner());
/* register for state saving */
save_item( NAME(m_cs) );
save_item( NAME(m_clk) );
@ -178,8 +181,8 @@ UINT8 adc083x_device::conversion()
int negative_channel = ADC083X_AGND;
double positive = 0;
double negative = 0;
double gnd = m_input_callback( this, ADC083X_AGND );
double vref = m_input_callback( this, ADC083X_VREF );
double gnd = m_input_callback(ADC083X_AGND);
double vref = m_input_callback(ADC083X_VREF);
if( type() == ADC0831 )
{
@ -225,12 +228,12 @@ UINT8 adc083x_device::conversion()
if( positive_channel != ADC083X_AGND )
{
positive = m_input_callback( this, positive_channel ) - gnd;
positive = m_input_callback(positive_channel) - gnd;
}
if( negative_channel != ADC083X_AGND )
{
negative = m_input_callback( this, negative_channel ) - gnd;
negative = m_input_callback(negative_channel) - gnd;
}
result = (int) ( ( ( positive - negative ) * 255 ) / vref );

View File

@ -15,10 +15,11 @@
TYPE DEFINITIONS
***************************************************************************/
typedef double (*adc083x_input_callback)(device_t *device, UINT8 input);
typedef device_delegate<double (UINT8 input)> adc083x_input_delegate;
#define ADC083X_INPUT_CB(name) double name(UINT8 input)
#define MCFG_ADC083X_INPUT_CALLBACK(input_callback) \
adc083x_device::set_input_callback(*device, input_callback);
#define MCFG_ADC083X_INPUT_CB(_class, _method) \
adc083x_device::set_input_callback(*device, adc083x_input_delegate(&_class::_method, #_class "::" #_method, downcast<_class *>(owner)));
/***************************************************************************
CONSTANTS
@ -46,7 +47,7 @@ public:
adc083x_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);
// static configuration helpers
static void set_input_callback(device_t &device, adc083x_input_callback input_callback) { downcast<adc083x_device &>(device).m_input_callback = input_callback; }
static void set_input_callback(device_t &device, adc083x_input_delegate input_callback) { downcast<adc083x_device &>(device).m_input_callback = input_callback; }
DECLARE_WRITE_LINE_MEMBER( cs_write );
DECLARE_WRITE_LINE_MEMBER( clk_write );
@ -81,7 +82,7 @@ private:
INT32 m_bit;
INT32 m_output;
adc083x_input_callback m_input_callback;
adc083x_input_delegate m_input_callback;
};
class adc0831_device : public adc083x_device

View File

@ -102,7 +102,6 @@
#include "sound/k056800.h"
#include "sound/k054539.h"
#include "includes/konamigx.h"
#include "machine/adc083x.h"
#include "rendlay.h"
#define GX_DEBUG 0
@ -463,7 +462,7 @@ WRITE32_MEMBER(konamigx_state::eeprom_w)
bit 0: eeprom data
*/
ioport("EEPROMOUT")->write(odata, 0xff);
m_eepromout->write(odata, 0xff);
konamigx_wrport1_0 = odata;
}
@ -708,14 +707,14 @@ TIMER_DEVICE_CALLBACK_MEMBER(konamigx_state::konamigx_hbinterrupt)
/* National Semiconductor ADC0834 4-channel serial ADC emulation */
static double adc0834_callback( device_t *device, UINT8 input )
ADC083X_INPUT_CB(konamigx_state::adc0834_callback)
{
switch (input)
{
case ADC083X_CH0:
return (double)(5 * device->machine().root_device().ioport("AN0")->read()) / 255.0; // steer
return (double)(5 * m_an0->read()) / 255.0; // steer
case ADC083X_CH1:
return (double)(5 * device->machine().root_device().ioport("AN1")->read()) / 255.0; // gas
return (double)(5 * m_an1->read()) / 255.0; // gas
case ADC083X_VREF:
return 5;
}
@ -725,16 +724,16 @@ static double adc0834_callback( device_t *device, UINT8 input )
READ32_MEMBER(konamigx_state::le2_gun_H_r)
{
int p1x = ioport("LIGHT0_X")->read()*290/0xff+20;
int p2x = ioport("LIGHT1_X")->read()*290/0xff+20;
int p1x = m_light0_x->read()*290/0xff+20;
int p2x = m_light1_x->read()*290/0xff+20;
return (p1x<<16)|p2x;
}
READ32_MEMBER(konamigx_state::le2_gun_V_r)
{
int p1y = ioport("LIGHT0_Y")->read()*224/0xff;
int p2y = ioport("LIGHT1_Y")->read()*224/0xff;
int p1y = m_light0_y->read()*224/0xff;
int p2y = m_light1_y->read()*224/0xff;
// make "off the bottom" reload too
if (p1y >= 0xdf) p1y = 0;
@ -1700,7 +1699,7 @@ static MACHINE_CONFIG_DERIVED( opengolf, konamigx )
MCFG_CPU_PROGRAM_MAP(gx_type1_map)
MCFG_DEVICE_ADD("adc0834", ADC0834, 0)
MCFG_ADC083X_INPUT_CALLBACK(adc0834_callback)
MCFG_ADC083X_INPUT_CB(konamigx_state, adc0834_callback)
MACHINE_CONFIG_END
static MACHINE_CONFIG_DERIVED( racinfrc, konamigx )
@ -1714,7 +1713,7 @@ static MACHINE_CONFIG_DERIVED( racinfrc, konamigx )
MCFG_CPU_PROGRAM_MAP(gx_type1_map)
MCFG_DEVICE_ADD("adc0834", ADC0834, 0)
MCFG_ADC083X_INPUT_CALLBACK(adc0834_callback)
MCFG_ADC083X_INPUT_CB(konamigx_state, adc0834_callback)
MACHINE_CONFIG_END
static MACHINE_CONFIG_DERIVED( gxtype3, konamigx )

View File

@ -451,6 +451,7 @@ public:
DECLARE_WRITE8_MEMBER( dmx_output_callback );
DECLARE_WRITE8_MEMBER( mamboagg_output_callback );
DECLARE_WRITE8_MEMBER( punchmania_output_callback );
ADC083X_INPUT_CB(analogue_inputs_callback);
void cdrom_dma_read( UINT32 *ram, UINT32 n_address, INT32 n_size );
void cdrom_dma_write( UINT32 *ram, UINT32 n_address, INT32 n_size );
@ -1680,10 +1681,9 @@ WRITE_LINE_MEMBER( ksys573_state::mamboagg_lamps_b5 )
/* punch mania */
static double punchmania_inputs_callback( device_t *device, UINT8 input )
ADC083X_INPUT_CB(konami573_cassette_xi_device::punchmania_inputs_callback)
{
ksys573_state *state = device->machine().driver_data<ksys573_state>();
ksys573_state *state = machine().driver_data<ksys573_state>();
double *pad_position = state->m_pad_position;
int pads = state->m_pads->read();
for( int i = 0; i < 6; i++ )
@ -1719,7 +1719,7 @@ static double punchmania_inputs_callback( device_t *device, UINT8 input )
static MACHINE_CONFIG_FRAGMENT( punchmania_cassette_install )
MCFG_DEVICE_MODIFY( "adc0838" )
MCFG_ADC083X_INPUT_CALLBACK( punchmania_inputs_callback )
MCFG_ADC083X_INPUT_CB( konami573_cassette_xi_device, punchmania_inputs_callback )
MACHINE_CONFIG_END
@ -1987,20 +1987,18 @@ READ16_MEMBER( ksys573_state::gunmania_r )
/* ADC0834 Interface */
static double analogue_inputs_callback( device_t *device, UINT8 input )
ADC083X_INPUT_CB(ksys573_state::analogue_inputs_callback)
{
ksys573_state *state = device->machine().driver_data<ksys573_state>();
switch( input )
{
case ADC083X_CH0:
return (double)( 5 * state->m_analog0->read() ) / 255.0;
return (double)( 5 * m_analog0->read() ) / 255.0;
case ADC083X_CH1:
return (double)( 5 * state->m_analog1->read() ) / 255.0;
return (double)( 5 * m_analog1->read() ) / 255.0;
case ADC083X_CH2:
return (double)( 5 * state->m_analog2->read() ) / 255.0;
return (double)( 5 * m_analog2->read() ) / 255.0;
case ADC083X_CH3:
return (double)( 5 * state->m_analog3->read() ) / 255.0;
return (double)( 5 * m_analog3->read() ) / 255.0;
case ADC083X_AGND:
return 0;
case ADC083X_VREF:
@ -2076,7 +2074,7 @@ static MACHINE_CONFIG_START( konami573, ksys573_state )
MCFG_M48T58_ADD( "m48t58" )
MCFG_DEVICE_ADD( "adc0834", ADC0834, 0 )
MCFG_ADC083X_INPUT_CALLBACK( analogue_inputs_callback )
MCFG_ADC083X_INPUT_CB( ksys573_state, analogue_inputs_callback )
MACHINE_CONFIG_END
// Variants with additional digital sound board

View File

@ -191,6 +191,16 @@ public:
m_k056800(*this, "k056800"),
m_k056832(*this, "k056832"),
m_workram(*this, "workram"),
m_in0(*this, "IN0"),
m_in1(*this, "IN1"),
m_in2(*this, "IN2"),
m_in3(*this, "IN3"),
m_in4(*this, "IN4"),
m_out4(*this, "OUT4"),
m_eepromout(*this, "EEPROMOUT"),
m_analog1(*this, "ANALOG1"),
m_analog2(*this, "ANALOG2"),
m_analog3(*this, "ANALOG3"),
m_palette(*this, "palette") { }
required_device<cpu_device> m_maincpu;
@ -200,6 +210,7 @@ public:
required_device<k056800_device> m_k056800;
optional_device<k056832_device> m_k056832;
optional_shared_ptr<UINT32> m_workram;
required_ioport m_in0, m_in1, m_in2, m_in3, m_in4, m_out4, m_eepromout, m_analog1, m_analog2, m_analog3;
required_device<palette_device> m_palette;
UINT32 *m_sharc_dataram;
@ -229,6 +240,7 @@ public:
UINT32 screen_update_jetwave(screen_device &screen, bitmap_rgb32 &bitmap, const rectangle &cliprect);
INTERRUPT_GEN_MEMBER(zr107_vblank);
WRITE_LINE_MEMBER(k054539_irq_gen);
ADC083X_INPUT_CB(adc0838_callback);
protected:
virtual void machine_start();
@ -316,18 +328,24 @@ UINT32 zr107_state::screen_update_zr107(screen_device &screen, bitmap_rgb32 &bit
READ8_MEMBER(zr107_state::sysreg_r)
{
UINT32 r = 0;
static const char *const portnames[] = { "IN0", "IN1", "IN2", "IN3", "IN4" };
switch (offset)
{
case 0: /* I/O port 0 */
case 1: /* I/O port 1 */
case 2: /* I/O port 2 */
case 3: /* System Port 0 */
case 4: /* System Port 1 */
r = ioport(portnames[offset])->read();
r = m_in0->read();
break;
case 1: /* I/O port 1 */
r = m_in1->read();
break;
case 2: /* I/O port 2 */
r = m_in2->read();
break;
case 3: /* System Port 0 */
r = m_in3->read();
break;
case 4: /* System Port 1 */
r = m_in4->read();
break;
case 5: /* Parallel data port */
break;
}
@ -361,7 +379,7 @@ WRITE8_MEMBER(zr107_state::sysreg_w)
0x02 = EEPCLK
0x01 = EEPDI
*/
ioport("EEPROMOUT")->write(data & 0x07, 0xff);
m_eepromout->write(data & 0x07, 0xff);
m_audiocpu->set_input_line(INPUT_LINE_RESET, (data & 0x10) ? CLEAR_LINE : ASSERT_LINE);
mame_printf_debug("System register 0 = %02X\n", data);
break;
@ -382,7 +400,7 @@ WRITE8_MEMBER(zr107_state::sysreg_w)
if (data & 0x40) /* CG Board 0 IRQ Ack */
m_maincpu->set_input_line(INPUT_LINE_IRQ0, CLEAR_LINE);
set_cgboard_id((data >> 4) & 3);
ioport("OUT4")->write(data, 0xff);
m_out4->write(data, 0xff);
mame_printf_debug("System register 1 = %02X\n", data);
break;
@ -675,16 +693,16 @@ INPUT_PORTS_END
/* ADC0838 Interface */
static double adc0838_callback( device_t *device, UINT8 input )
ADC083X_INPUT_CB(zr107_state::adc0838_callback)
{
switch (input)
{
case ADC083X_CH0:
return (double)(5 * device->machine().root_device().ioport("ANALOG1")->read()) / 255.0;
return (double)(5 * m_analog1->read()) / 255.0;
case ADC083X_CH1:
return (double)(5 * device->machine().root_device().ioport("ANALOG2")->read()) / 255.0;
return (double)(5 * m_analog2->read()) / 255.0;
case ADC083X_CH2:
return (double)(5 * device->machine().root_device().ioport("ANALOG3")->read()) / 255.0;
return (double)(5 * m_analog3->read()) / 255.0;
case ADC083X_CH3:
return 0;
case ADC083X_COM:
@ -791,7 +809,7 @@ static MACHINE_CONFIG_START( zr107, zr107_state )
MCFG_SOUND_ROUTE(1, "rspeaker", 0.75)
MCFG_DEVICE_ADD("adc0838", ADC0838, 0)
MCFG_ADC083X_INPUT_CALLBACK(adc0838_callback)
MCFG_ADC083X_INPUT_CB(zr107_state, adc0838_callback)
MACHINE_CONFIG_END
@ -855,7 +873,7 @@ static MACHINE_CONFIG_START( jetwave, zr107_state )
MCFG_SOUND_ROUTE(1, "rspeaker", 0.75)
MCFG_DEVICE_ADD("adc0838", ADC0838, 0)
MCFG_ADC083X_INPUT_CALLBACK(adc0838_callback)
MCFG_ADC083X_INPUT_CB(zr107_state, adc0838_callback)
MACHINE_CONFIG_END
/*****************************************************************************/

View File

@ -1,6 +1,7 @@
#include "sound/k056800.h"
#include "sound/k054539.h"
#include "cpu/tms57002/tms57002.h"
#include "machine/adc083x.h"
#include "video/k054156_k054157_k056832.h"
#include "video/k053246_k053247_k055673.h"
#include "video/k055555.h"
@ -29,6 +30,13 @@ public:
m_k056800(*this, "k056800"),
m_k054539_1(*this,"k054539_1"),
m_k054539_2(*this,"k054539_2"),
m_an0(*this, "AN0"),
m_an1(*this, "AN1"),
m_light0_x(*this, "LIGHT0_X"),
m_light0_y(*this, "LIGHT0_Y"),
m_light1_x(*this, "LIGHT1_X"),
m_light1_y(*this, "LIGHT1_Y"),
m_eepromout(*this, "EEPROMOUT"),
m_gfxdecode(*this, "gfxdecode"),
m_screen(*this, "screen"),
m_palette(*this, "palette")
@ -52,6 +60,7 @@ public:
optional_device<k056800_device> m_k056800;
optional_device<k054539_device> m_k054539_1;
optional_device<k054539_device> m_k054539_2;
optional_ioport m_an0, m_an1, m_light0_x, m_light0_y, m_light1_x, m_light1_y, m_eepromout;
required_device<gfxdecode_device> m_gfxdecode;
required_device<screen_device> m_screen;
required_device<palette_device> m_palette;
@ -119,6 +128,7 @@ public:
TIMER_CALLBACK_MEMBER(dmaend_callback);
TIMER_CALLBACK_MEMBER(boothack_callback);
TIMER_DEVICE_CALLBACK_MEMBER(konamigx_hbinterrupt);
ADC083X_INPUT_CB(adc0834_callback);
void _gxcommoninitnosprites(running_machine &machine);
void _gxcommoninit(running_machine &machine);

View File

@ -80,6 +80,8 @@ public:
virtual DECLARE_READ_LINE_MEMBER(read_line_adc083x_sars);
virtual DECLARE_WRITE_LINE_MEMBER(write_line_d5);
ADC083X_INPUT_CB(punchmania_inputs_callback);
protected:
virtual machine_config_constructor device_mconfig_additions() const;