Modernize adc1038 and adc12138 devices. [Osso]

This commit is contained in:
Andrew Gardner 2013-06-08 16:15:23 +00:00
parent 9eafc98ed9
commit f5ed8617ba
9 changed files with 454 additions and 562 deletions

View File

@ -10,159 +10,12 @@
#include "emu.h"
#include "adc1038.h"
/***************************************************************************
TYPE DEFINITIONS
***************************************************************************/
struct adc1038_state
{
int cycle;
int clk;
int adr;
int data_in;
int data_out;
int adc_data;
int sars;
adc1038_input_read_func input_callback_r;
int gticlub_hack;
};
/*****************************************************************************
INLINE FUNCTIONS
*****************************************************************************/
INLINE adc1038_state *adc1038_get_safe_token( device_t *device )
{
assert(device != NULL);
assert(device->type() == ADC1038);
return (adc1038_state *)downcast<adc1038_device *>(device)->token();
}
INLINE const adc1038_interface *adc1038_get_interface( device_t *device )
{
assert(device != NULL);
assert((device->type() == ADC1038));
return (const adc1038_interface *) device->static_config();
}
/*****************************************************************************
DEVICE HANDLERS
*****************************************************************************/
READ_LINE_DEVICE_HANDLER( adc1038_do_read )
{
adc1038_state *adc1038 = adc1038_get_safe_token(device);
adc1038->data_out = (adc1038->adc_data & 0x200) ? 1 : 0;
adc1038->adc_data <<= 1;
//printf("ADC DO\n");
return adc1038->data_out;
}
WRITE_LINE_DEVICE_HANDLER( adc1038_di_write )
{
adc1038_state *adc1038 = adc1038_get_safe_token(device);
adc1038->data_in = state;
}
WRITE_LINE_DEVICE_HANDLER( adc1038_clk_write )
{
adc1038_state *adc1038 = adc1038_get_safe_token(device);
// GTI Club doesn't sync on SARS
if (adc1038->gticlub_hack)
{
if (adc1038->clk == 0 && state == 0)
{
adc1038->cycle = 0;
/* notice that adc1038->adr is always < 7! */
adc1038->adc_data = adc1038->input_callback_r(device, adc1038->adr);
}
}
if (state == 1)
{
//printf("ADC CLK, DI = %d, cycle = %d\n", adc1038->data_in, adc1038->cycle);
if (adc1038->cycle == 0) // A2
{
adc1038->adr = 0;
adc1038->adr |= (adc1038->data_in << 2);
}
else if (adc1038->cycle == 1) // A1
{
adc1038->adr |= (adc1038->data_in << 1);
}
else if (adc1038->cycle == 2) // A0
{
adc1038->adr |= (adc1038->data_in << 0);
}
adc1038->cycle++;
}
adc1038->clk = state;
}
READ_LINE_DEVICE_HANDLER( adc1038_sars_read )
{
adc1038_state *adc1038 = adc1038_get_safe_token(device);
adc1038->cycle = 0;
/* notice that adc1038->adr is always < 7! */
adc1038->adc_data = adc1038->input_callback_r(device, adc1038->adr);
adc1038->sars ^= 1;
return adc1038->sars;
}
/*****************************************************************************
DEVICE INTERFACE
*****************************************************************************/
static DEVICE_START( adc1038 )
{
adc1038_state *adc1038 = adc1038_get_safe_token(device);
const adc1038_interface *intf = adc1038_get_interface(device);
adc1038->gticlub_hack = intf->gticlub_hack;
adc1038->input_callback_r = intf->input_callback_r;
device->save_item(NAME(adc1038->cycle));
device->save_item(NAME(adc1038->clk));
device->save_item(NAME(adc1038->adr));
device->save_item(NAME(adc1038->data_in));
device->save_item(NAME(adc1038->data_out));
device->save_item(NAME(adc1038->adc_data));
device->save_item(NAME(adc1038->sars));
}
static DEVICE_RESET( adc1038 )
{
adc1038_state *adc1038 = adc1038_get_safe_token(device);
adc1038->cycle = 0;
adc1038->clk = 0;
adc1038->adr = 0;
adc1038->data_in = 0;
adc1038->data_out = 0;
adc1038->adc_data = 0;
adc1038->sars = 1;
}
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, "A/D Converters 1038", tag, owner, clock)
{
m_token = global_alloc_clear(adc1038_state);
}
//-------------------------------------------------
@ -173,6 +26,16 @@ adc1038_device::adc1038_device(const machine_config &mconfig, const char *tag, d
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;
}
}
//-------------------------------------------------
@ -181,7 +44,15 @@ void adc1038_device::device_config_complete()
void adc1038_device::device_start()
{
DEVICE_START_NAME( adc1038 )(this);
m_input_callback_r_func = input_callback_r;
save_item(NAME(m_cycle));
save_item(NAME(m_clk));
save_item(NAME(m_adr));
save_item(NAME(m_data_in));
save_item(NAME(m_data_out));
save_item(NAME(m_adc_data));
save_item(NAME(m_sars));
}
//-------------------------------------------------
@ -190,5 +61,78 @@ void adc1038_device::device_start()
void adc1038_device::device_reset()
{
DEVICE_RESET_NAME( adc1038 )(this);
m_cycle = 0;
m_clk = 0;
m_adr = 0;
m_data_in = 0;
m_data_out = 0;
m_adc_data = 0;
m_sars = 1;
}
/*****************************************************************************
DEVICE HANDLERS
*****************************************************************************/
READ_LINE_MEMBER( adc1038_device::do_read )
{
m_data_out = (m_adc_data & 0x200) ? 1 : 0;
m_adc_data <<= 1;
//printf("ADC DO\n");
return m_data_out;
}
WRITE_LINE_MEMBER( adc1038_device::di_write )
{
m_data_in = state;
}
WRITE_LINE_MEMBER( adc1038_device::clk_write )
{
// GTI Club doesn't sync on SARS
if (m_gticlub_hack)
{
if (m_clk == 0 && state == 0)
{
m_cycle = 0;
/* notice that m_adr is always < 7! */
m_adc_data = m_input_callback_r_func(this, m_adr);
}
}
if (state == 1)
{
//printf("ADC CLK, DI = %d, cycle = %d\n", m_data_in, m_cycle);
if (m_cycle == 0) // A2
{
m_adr = 0;
m_adr |= (m_data_in << 2);
}
else if (m_cycle == 1) // A1
{
m_adr |= (m_data_in << 1);
}
else if (m_cycle == 2) // A0
{
m_adr |= (m_data_in << 0);
}
m_cycle++;
}
m_clk = state;
}
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_sars ^= 1;
return m_sars;
}

View File

@ -21,7 +21,7 @@ typedef int (*adc1038_input_read_func)(device_t *device, int input);
struct adc1038_interface
{
int gticlub_hack;
int m_gticlub_hack;
adc1038_input_read_func input_callback_r;
};
@ -30,22 +30,35 @@ struct adc1038_interface
MACROS / CONSTANTS
***************************************************************************/
class adc1038_device : public device_t
class adc1038_device : public device_t,
public adc1038_interface
{
public:
adc1038_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
~adc1038_device() { global_free(m_token); }
~adc1038_device() {}
DECLARE_READ_LINE_MEMBER( do_read );
DECLARE_READ_LINE_MEMBER( sars_read );
DECLARE_WRITE_LINE_MEMBER( di_write );
DECLARE_WRITE_LINE_MEMBER( clk_write );
// access to legacy token
void *token() const { assert(m_token != NULL); return m_token; }
protected:
// device-level overrides
virtual void device_config_complete();
virtual void device_start();
virtual void device_reset();
private:
adc1038_input_read_func m_input_callback_r_func;
private:
// internal state
void *m_token;
int m_cycle;
int m_clk;
int m_adr;
int m_data_in;
int m_data_out;
int m_adc_data;
int m_sars;
};
extern const device_type ADC1038;
@ -56,13 +69,4 @@ extern const device_type ADC1038;
MCFG_DEVICE_CONFIG(_config)
/***************************************************************************
DEVICE I/O FUNCTIONS
***************************************************************************/
extern READ_LINE_DEVICE_HANDLER( adc1038_do_read );
extern READ_LINE_DEVICE_HANDLER( adc1038_sars_read );
extern WRITE_LINE_DEVICE_HANDLER( adc1038_di_write );
extern WRITE_LINE_DEVICE_HANDLER( adc1038_clk_write );
#endif /* __ADC1038_H__ */

View File

@ -20,25 +20,6 @@
TYPE DEFINITIONS
***************************************************************************/
struct adc12138_state
{
adc1213x_input_convert_func input_callback_r;
int cycle;
int data_out;
int data_in;
int conv_mode;
int auto_cal;
int auto_zero;
int acq_time;
int data_out_sign;
int mode;
int input_shift_reg;
int output_shift_reg;
int end_conv;
};
#define ADC1213X_CONV_MODE_12_MSB_FIRST 0
#define ADC1213X_CONV_MODE_16_MSB_FIRST 1
#define ADC1213X_CONV_MODE_12_LSB_FIRST 2
@ -49,309 +30,7 @@ struct adc12138_state
#define ADC1213X_ACQUISITION_TIME_18_CCLK 2
#define ADC1213X_ACQUISITION_TIME_34_CCLK 3
/***************************************************************************
INLINE FUNCTIONS
***************************************************************************/
INLINE adc12138_state *get_safe_token(device_t *device)
{
assert(device != NULL);
assert((device->type() == ADC12130) || (device->type() == ADC12132) || (device->type() == ADC12138));
return (adc12138_state *)downcast<adc12138_device *>(device)->token();
}
INLINE const adc12138_interface *get_interface(device_t *device)
{
assert(device != NULL);
assert((device->type() == ADC12130) || (device->type() == ADC12132) || (device->type() == ADC12138));
return (const adc12138_interface *) device->static_config();
}
/***************************************************************************
IMPLEMENTATION
***************************************************************************/
/*-------------------------------------------------
adc1213x_di_w
-------------------------------------------------*/
WRITE8_DEVICE_HANDLER( adc1213x_di_w )
{
adc12138_state *adc1213x = get_safe_token(device);
adc1213x->data_in = data & 1;
}
/*-------------------------------------------------
adc1213x_convert
-------------------------------------------------*/
static void adc1213x_convert(device_t *device, int channel, int bits16, int lsbfirst)
{
adc12138_state *adc1213x = get_safe_token(device);
int i;
int bits;
int input_value;
double input = 0;
if (bits16)
fatalerror("ADC1213X: 16-bit mode not supported\n");
if (lsbfirst)
fatalerror("ADC1213X: LSB first not supported\n");
switch (channel)
{
case 0x8: // H L L L - CH0 (single-ended)
{
input = adc1213x->input_callback_r(device, 0);
break;
}
case 0xc: // H H L L - CH1 (single-ended)
{
input = adc1213x->input_callback_r(device, 1);
break;
}
case 0x9: // H L L H - CH2 (single-ended)
{
input = adc1213x->input_callback_r(device, 2);
break;
}
case 0xd: // H H L H - CH3 (single-ended)
{
input = adc1213x->input_callback_r(device, 3);
break;
}
case 0xa: // H L H L - CH4 (single-ended)
{
input = adc1213x->input_callback_r(device, 4);
break;
}
case 0xe: // H H H L - CH5 (single-ended)
{
input = adc1213x->input_callback_r(device, 5);
break;
}
case 0xb: // H L H H - CH6 (single-ended)
{
input = adc1213x->input_callback_r(device, 6);
break;
}
case 0xf: // H H H H - CH7 (single-ended)
{
input = adc1213x->input_callback_r(device, 7);
break;
}
default:
{
fatalerror("ADC1213X: unsupported channel %02X\n", channel);
}
}
input_value = (int)(input * 2047.0);
bits = 12;
// sign-extend if needed
if (adc1213x->data_out_sign)
{
input_value = input_value | ((input_value & 0x800) << 1);
bits++;
}
adc1213x->output_shift_reg = 0;
for (i=0; i < bits; i++)
{
if (input_value & (1 << ((bits-1) - i)))
{
adc1213x->output_shift_reg |= (1 << i);
}
}
adc1213x->data_out = adc1213x->output_shift_reg & 1;
adc1213x->output_shift_reg >>= 1;
}
/*-------------------------------------------------
adc1213x_cs_w
-------------------------------------------------*/
WRITE8_DEVICE_HANDLER( adc1213x_cs_w )
{
adc12138_state *adc1213x = get_safe_token(device);
if (data)
{
//printf("ADC: CS\n");
if (adc1213x->cycle >= 7)
{
int mode = adc1213x->input_shift_reg >> (adc1213x->cycle - 8);
switch (mode & 0xf)
{
case 0x0: // X X X X L L L L - 12 or 13 Bit MSB First conversion
{
adc1213x_convert(device, (mode >> 4) & 0xf, 0, 0);
break;
}
case 0x1: // X X X X L L L H - 16 or 17 Bit MSB First conversion
{
adc1213x_convert(device, (mode >> 4) & 0xf, 1, 0);
break;
}
case 0x4: // X X X X L H L L - 12 or 13 Bit LSB First conversion
{
adc1213x_convert(device, (mode >> 4) & 0xf, 0, 1);
break;
}
case 0x5: // X X X X L H L H - 16 or 17 Bit LSB First conversion
{
adc1213x_convert(device, (mode >> 4) & 0xf, 1, 1);
break;
}
default:
{
switch (mode)
{
case 0x08: // L L L L H L L L - Auto cal
{
adc1213x->auto_cal = 1;
break;
}
case 0x0e: // L L L L H H H L - Acquisition time 6 CCLK cycles
{
adc1213x->acq_time = ADC1213X_ACQUISITION_TIME_6_CCLK;
break;
}
case 0x8d: // H L L L H H L H - Data out with sign
{
adc1213x->data_out_sign = 1;
break;
}
case 0x0f: // L L L L H H H H - User mode
{
break;
}
default:
{
fatalerror("ADC1213X: unknown config mode %02X\n", mode);
}
}
break;
}
}
}
adc1213x->cycle = 0;
adc1213x->input_shift_reg = 0;
adc1213x->end_conv = 0;
}
}
/*-------------------------------------------------
adc1213x_sclk_w
-------------------------------------------------*/
WRITE8_DEVICE_HANDLER( adc1213x_sclk_w )
{
adc12138_state *adc1213x = get_safe_token(device);
if (data)
{
//printf("ADC: cycle %d, DI = %d\n", adc1213x->cycle, adc1213x->data_in);
adc1213x->input_shift_reg <<= 1;
adc1213x->input_shift_reg |= adc1213x->data_in;
adc1213x->data_out = adc1213x->output_shift_reg & 1;
adc1213x->output_shift_reg >>= 1;
adc1213x->cycle++;
}
}
/*-------------------------------------------------
adc1213x_conv_w
-------------------------------------------------*/
WRITE8_DEVICE_HANDLER( adc1213x_conv_w )
{
adc12138_state *adc1213x = get_safe_token(device);
adc1213x->end_conv = 1;
}
/*-------------------------------------------------
adc1213x_do_r
-------------------------------------------------*/
READ8_DEVICE_HANDLER( adc1213x_do_r )
{
adc12138_state *adc1213x = get_safe_token(device);
//printf("ADC: DO\n");
return adc1213x->data_out;
}
/*-------------------------------------------------
adc1213x_eoc_r
-------------------------------------------------*/
READ8_DEVICE_HANDLER( adc1213x_eoc_r )
{
adc12138_state *adc1213x = get_safe_token(device);
return adc1213x->end_conv;
}
/*-------------------------------------------------
DEVICE_START( adc1213x )
-------------------------------------------------*/
static DEVICE_START( adc12138 )
{
adc12138_state *adc1213x = get_safe_token(device);
const adc12138_interface *intf = get_interface(device);
/* resolve callbacks */
adc1213x->input_callback_r = intf->input_callback_r;
/* register for state saving */
device->save_item(NAME(adc1213x->cycle));
device->save_item(NAME(adc1213x->data_out));
device->save_item(NAME(adc1213x->data_in));
device->save_item(NAME(adc1213x->conv_mode));
device->save_item(NAME(adc1213x->auto_cal));
device->save_item(NAME(adc1213x->auto_zero));
device->save_item(NAME(adc1213x->acq_time));
device->save_item(NAME(adc1213x->data_out_sign));
device->save_item(NAME(adc1213x->mode));
device->save_item(NAME(adc1213x->input_shift_reg));
device->save_item(NAME(adc1213x->output_shift_reg));
device->save_item(NAME(adc1213x->end_conv));
}
/*-------------------------------------------------
DEVICE_RESET( adc1213x )
-------------------------------------------------*/
static DEVICE_RESET( adc12138 )
{
adc12138_state *adc1213x = get_safe_token(device);
adc1213x->conv_mode = ADC1213X_CONV_MODE_12_MSB_FIRST;
adc1213x->data_out_sign = 1;
adc1213x->auto_cal = 0;
adc1213x->auto_zero = 0;
adc1213x->acq_time = ADC1213X_ACQUISITION_TIME_10_CCLK;
}
const device_type ADC12130 = &device_creator<adc12130_device>;
@ -374,12 +53,10 @@ const device_type ADC12138 = &device_creator<adc12138_device>;
adc12138_device::adc12138_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
: device_t(mconfig, ADC12138, "A/D Converter 12138", tag, owner, clock)
{
m_token = global_alloc_clear(adc12138_state);
}
adc12138_device::adc12138_device(const machine_config &mconfig, device_type type, const char *name, const char *tag, device_t *owner, UINT32 clock)
: device_t(mconfig, type, name, tag, owner, clock)
{
m_token = global_alloc_clear(adc12138_state);
}
//-------------------------------------------------
@ -390,6 +67,16 @@ adc12138_device::adc12138_device(const machine_config &mconfig, device_type type
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;
}
}
//-------------------------------------------------
@ -398,7 +85,22 @@ void adc12138_device::device_config_complete()
void adc12138_device::device_start()
{
DEVICE_START_NAME( adc12138 )(this);
/* resolve callbacks */
m_input_callback_r_func = input_callback_r;
/* register for state saving */
save_item(NAME(m_cycle));
save_item(NAME(m_data_out));
save_item(NAME(m_data_in));
save_item(NAME(m_conv_mode));
save_item(NAME(m_auto_cal));
save_item(NAME(m_auto_zero));
save_item(NAME(m_acq_time));
save_item(NAME(m_data_out_sign));
save_item(NAME(m_mode));
save_item(NAME(m_input_shift_reg));
save_item(NAME(m_output_shift_reg));
save_item(NAME(m_end_conv));
}
//-------------------------------------------------
@ -407,5 +109,241 @@ void adc12138_device::device_start()
void adc12138_device::device_reset()
{
DEVICE_RESET_NAME( adc12138 )(this);
m_conv_mode = ADC1213X_CONV_MODE_12_MSB_FIRST;
m_data_out_sign = 1;
m_auto_cal = 0;
m_auto_zero = 0;
m_acq_time = ADC1213X_ACQUISITION_TIME_10_CCLK;
}
/***************************************************************************
IMPLEMENTATION
***************************************************************************/
/*-------------------------------------------------
di_w
-------------------------------------------------*/
WRITE8_MEMBER( adc12138_device::di_w )
{
m_data_in = data & 1;
}
/*-------------------------------------------------
convert
-------------------------------------------------*/
void adc12138_device::convert(int channel, int bits16, int lsbfirst)
{
int i;
int bits;
int input_value;
double input = 0;
if (bits16)
fatalerror("ADC1213X: 16-bit mode not supported\n");
if (lsbfirst)
fatalerror("ADC1213X: LSB first not supported\n");
switch (channel)
{
case 0x8: // H L L L - CH0 (single-ended)
{
input = m_input_callback_r_func(this, 0);
break;
}
case 0xc: // H H L L - CH1 (single-ended)
{
input = m_input_callback_r_func(this, 1);
break;
}
case 0x9: // H L L H - CH2 (single-ended)
{
input = m_input_callback_r_func(this, 2);
break;
}
case 0xd: // H H L H - CH3 (single-ended)
{
input = m_input_callback_r_func(this, 3);
break;
}
case 0xa: // H L H L - CH4 (single-ended)
{
input = m_input_callback_r_func(this, 4);
break;
}
case 0xe: // H H H L - CH5 (single-ended)
{
input = m_input_callback_r_func(this, 5);
break;
}
case 0xb: // H L H H - CH6 (single-ended)
{
input = m_input_callback_r_func(this, 6);
break;
}
case 0xf: // H H H H - CH7 (single-ended)
{
input = m_input_callback_r_func(this, 7);
break;
}
default:
{
fatalerror("ADC1213X: unsupported channel %02X\n", channel);
}
}
input_value = (int)(input * 2047.0);
bits = 12;
// sign-extend if needed
if (m_data_out_sign)
{
input_value = input_value | ((input_value & 0x800) << 1);
bits++;
}
m_output_shift_reg = 0;
for (i=0; i < bits; i++)
{
if (input_value & (1 << ((bits-1) - i)))
{
m_output_shift_reg |= (1 << i);
}
}
m_data_out = m_output_shift_reg & 1;
m_output_shift_reg >>= 1;
}
/*-------------------------------------------------
cs_w
-------------------------------------------------*/
WRITE8_MEMBER( adc12138_device::cs_w )
{
if (data)
{
//printf("ADC: CS\n");
if (m_cycle >= 7)
{
int mode = m_input_shift_reg >> (m_cycle - 8);
switch (mode & 0xf)
{
case 0x0: // X X X X L L L L - 12 or 13 Bit MSB First conversion
{
convert((mode >> 4) & 0xf, 0, 0);
break;
}
case 0x1: // X X X X L L L H - 16 or 17 Bit MSB First conversion
{
convert((mode >> 4) & 0xf, 1, 0);
break;
}
case 0x4: // X X X X L H L L - 12 or 13 Bit LSB First conversion
{
convert((mode >> 4) & 0xf, 0, 1);
break;
}
case 0x5: // X X X X L H L H - 16 or 17 Bit LSB First conversion
{
convert((mode >> 4) & 0xf, 1, 1);
break;
}
default:
{
switch (mode)
{
case 0x08: // L L L L H L L L - Auto cal
{
m_auto_cal = 1;
break;
}
case 0x0e: // L L L L H H H L - Acquisition time 6 CCLK cycles
{
m_acq_time = ADC1213X_ACQUISITION_TIME_6_CCLK;
break;
}
case 0x8d: // H L L L H H L H - Data out with sign
{
m_data_out_sign = 1;
break;
}
case 0x0f: // L L L L H H H H - User mode
{
break;
}
default:
{
fatalerror("ADC1213X: unknown config mode %02X\n", mode);
}
}
break;
}
}
}
m_cycle = 0;
m_input_shift_reg = 0;
m_end_conv = 0;
}
}
/*-------------------------------------------------
sclk_w
-------------------------------------------------*/
WRITE8_MEMBER( adc12138_device::sclk_w )
{
if (data)
{
//printf("ADC: cycle %d, DI = %d\n", adc1213x->cycle, adc1213x->data_in);
m_input_shift_reg <<= 1;
m_input_shift_reg |= m_data_in;
m_data_out = m_output_shift_reg & 1;
m_output_shift_reg >>= 1;
m_cycle++;
}
}
/*-------------------------------------------------
conv_w
-------------------------------------------------*/
WRITE8_MEMBER( adc12138_device::conv_w )
{
m_end_conv = 1;
}
/*-------------------------------------------------
do_r
-------------------------------------------------*/
READ8_MEMBER( adc12138_device::do_r )
{
//printf("ADC: DO\n");
return m_data_out;
}
/*-------------------------------------------------
eoc_r
-------------------------------------------------*/
READ8_MEMBER( adc12138_device::eoc_r )
{
return m_end_conv;
}

View File

@ -10,30 +10,61 @@
#ifndef __ADC1213X_H__
#define __ADC1213X_H__
#include "devlegcy.h"
/***************************************************************************
TYPE DEFINITIONS
***************************************************************************/
typedef double (*adc1213x_input_convert_func)(device_t *device, UINT8 input);
struct adc12138_interface
{
adc1213x_input_convert_func input_callback_r;
};
/***************************************************************************
MACROS / CONSTANTS
***************************************************************************/
class adc12138_device : public device_t
class adc12138_device : public device_t,
public adc12138_interface
{
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);
~adc12138_device() { global_free(m_token); }
~adc12138_device() {}
DECLARE_WRITE8_MEMBER( di_w );
DECLARE_WRITE8_MEMBER( cs_w );
DECLARE_WRITE8_MEMBER( sclk_w );
DECLARE_WRITE8_MEMBER( conv_w );
DECLARE_READ8_MEMBER( do_r );
DECLARE_READ8_MEMBER( eoc_r );
// access to legacy token
void *token() const { assert(m_token != NULL); return m_token; }
protected:
// device-level overrides
virtual void device_config_complete();
virtual void device_start();
virtual void device_reset();
private:
void convert(int channel, int bits16, int lsbfirst);
adc1213x_input_convert_func m_input_callback_r_func;
private:
// internal state
void *m_token;
int m_cycle;
int m_data_out;
int m_data_in;
int m_conv_mode;
int m_auto_cal;
int m_auto_zero;
int m_acq_time;
int m_data_out_sign;
int m_mode;
int m_input_shift_reg;
int m_output_shift_reg;
int m_end_conv;
};
extern const device_type ADC12138;
@ -67,26 +98,4 @@ extern const device_type ADC12132;
MCFG_DEVICE_CONFIG(_config)
/***************************************************************************
TYPE DEFINITIONS
***************************************************************************/
typedef double (*adc1213x_input_convert_func)(device_t *device, UINT8 input);
struct adc12138_interface
{
adc1213x_input_convert_func input_callback_r;
};
/***************************************************************************
PROTOTYPES
***************************************************************************/
extern DECLARE_WRITE8_DEVICE_HANDLER( adc1213x_di_w );
extern DECLARE_WRITE8_DEVICE_HANDLER( adc1213x_cs_w );
extern DECLARE_WRITE8_DEVICE_HANDLER( adc1213x_sclk_w );
extern DECLARE_WRITE8_DEVICE_HANDLER( adc1213x_conv_w );
extern DECLARE_READ8_DEVICE_HANDLER( adc1213x_do_r );
extern DECLARE_READ8_DEVICE_HANDLER( adc1213x_eoc_r );
#endif /* __ADC1213X_H__ */

View File

@ -250,9 +250,16 @@ public:
m_audiocpu(*this, "audiocpu"),
m_dsp(*this, "dsp"),
m_dsp2(*this, "dsp2"),
m_adc1038(*this, "adc1038"),
m_eeprom(*this, "eeprom") { }
required_shared_ptr<UINT32> m_work_ram;
required_device<cpu_device> m_maincpu;
required_device<cpu_device> m_audiocpu;
required_device<cpu_device> m_dsp;
optional_device<cpu_device> m_dsp2;
required_device<adc1038_device> m_adc1038;
required_device<eeprom_device> m_eeprom;
UINT32 *m_sharc_dataram_0;
UINT32 *m_sharc_dataram_1;
DECLARE_WRITE32_MEMBER(paletteram32_w);
@ -278,11 +285,6 @@ public:
DECLARE_MACHINE_RESET(gticlub);
DECLARE_MACHINE_RESET(hangplt);
INTERRUPT_GEN_MEMBER(gticlub_vblank);
required_device<cpu_device> m_maincpu;
required_device<cpu_device> m_audiocpu;
required_device<cpu_device> m_dsp;
optional_device<cpu_device> m_dsp2;
required_device<eeprom_device> m_eeprom;
protected:
virtual void device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr);
@ -363,7 +365,6 @@ static const eeprom_interface eeprom_intf =
READ8_MEMBER(gticlub_state::sysreg_r)
{
static const char *const portnames[] = { "IN0", "IN1", "IN2", "IN3" };
device_t *adc1038 = machine().device("adc1038");
switch (offset)
{
case 0:
@ -372,7 +373,7 @@ READ8_MEMBER(gticlub_state::sysreg_r)
return ioport(portnames[offset])->read();
case 2:
return adc1038_sars_read(adc1038) << 7;
return m_adc1038->sars_read() << 7;
case 4:
{
@ -383,7 +384,7 @@ READ8_MEMBER(gticlub_state::sysreg_r)
// e = EEPROM data out
UINT32 eeprom_bit = (m_eeprom->read_bit() << 1);
UINT32 adc_bit = (adc1038_do_read(adc1038) << 2);
UINT32 adc_bit = (m_adc1038->do_read() << 2);
return (eeprom_bit | adc_bit);
}
@ -396,7 +397,6 @@ READ8_MEMBER(gticlub_state::sysreg_r)
WRITE8_MEMBER(gticlub_state::sysreg_w)
{
device_t *adc1038 = machine().device("adc1038");
switch (offset)
{
case 0:
@ -417,8 +417,8 @@ WRITE8_MEMBER(gticlub_state::sysreg_w)
if (data & 0x40) /* CG Board 0 IRQ Ack */
m_maincpu->set_input_line(INPUT_LINE_IRQ0, CLEAR_LINE);
adc1038_di_write(adc1038, (data >> 0) & 1);
adc1038_clk_write(adc1038, (data >> 1) & 1);
m_adc1038->di_write((data >> 0) & 1);
m_adc1038->clk_write((data >> 1) & 1);
set_cgboard_id((data >> 4) & 0x3);
break;

View File

@ -339,13 +339,23 @@ public:
m_dsp2(*this, "dsp2"),
m_eeprom(*this, "eeprom"),
m_k037122_1(*this, "k037122_1"),
m_k037122_2(*this, "k037122_2" ) { }
m_k037122_2(*this, "k037122_2" ),
m_adc12138(*this, "adc12138") { }
UINT8 m_led_reg0;
UINT8 m_led_reg1;
required_shared_ptr<UINT32> m_workram;
required_shared_ptr<UINT32> m_sharc_dataram0;
optional_shared_ptr<UINT32> m_sharc_dataram1;
required_device<cpu_device> m_maincpu;
required_device<cpu_device> m_audiocpu;
optional_device<cpu_device> m_gn680;
required_device<cpu_device> m_dsp;
optional_device<cpu_device> m_dsp2;
required_device<eeprom_device> m_eeprom;
optional_device<k037122_device> m_k037122_1;
optional_device<k037122_device> m_k037122_2;
required_device<adc12138_device> m_adc12138;
UINT8 *m_jvs_sdata;
UINT32 m_jvs_sdata_ptr;
emu_timer *m_sound_irq_timer;
@ -385,14 +395,6 @@ public:
int jvs_encode_data(UINT8 *in, int length);
int jvs_decode_data(UINT8 *in, UINT8 *out, int length);
void jamma_jvs_cmd_exec();
required_device<cpu_device> m_maincpu;
required_device<cpu_device> m_audiocpu;
optional_device<cpu_device> m_gn680;
required_device<cpu_device> m_dsp;
optional_device<cpu_device> m_dsp2;
required_device<eeprom_device> m_eeprom;
optional_device<k037122_device> m_k037122_1;
optional_device<k037122_device> m_k037122_2;
};
@ -487,7 +489,6 @@ READ8_MEMBER(hornet_state::sysreg_r)
{
UINT8 r = 0;
static const char *const portnames[] = { "IN0", "IN1", "IN2" };
device_t *adc12138 = machine().device("adc12138");
switch (offset)
{
case 0: /* I/O port 0 */
@ -507,7 +508,7 @@ READ8_MEMBER(hornet_state::sysreg_r)
0x01 = ADDO (ADC DO)
*/
r = 0xf0 | (m_eeprom->read_bit() << 3);
r |= adc1213x_do_r(adc12138, space, 0) | (adc1213x_eoc_r(adc12138, space, 0) << 2);
r |= m_adc12138->do_r(space, 0) | (m_adc12138->eoc_r(space, 0) << 2);
break;
case 4: /* I/O port 4 - DIP switches */
@ -519,8 +520,6 @@ READ8_MEMBER(hornet_state::sysreg_r)
WRITE8_MEMBER(hornet_state::sysreg_w)
{
device_t *adc12138 = machine().device("adc12138");
switch (offset)
{
case 0: /* LED Register 0 */
@ -561,10 +560,10 @@ WRITE8_MEMBER(hornet_state::sysreg_w)
0x02 = ADDI (ADC DI)
0x01 = ADDSCLK (ADC SCLK)
*/
adc1213x_cs_w(adc12138, space, 0, (data >> 3) & 0x1);
adc1213x_conv_w(adc12138, space, 0, (data >> 2) & 0x1);
adc1213x_di_w(adc12138, space, 0, (data >> 1) & 0x1);
adc1213x_sclk_w(adc12138, space, 0, data & 0x1);
m_adc12138->cs_w(space, 0, (data >> 3) & 0x1);
m_adc12138->conv_w(space, 0, (data >> 2) & 0x1);
m_adc12138->di_w(space, 0, (data >> 1) & 0x1);
m_adc12138->sclk_w(space, 0, data & 0x1);
m_audiocpu->set_input_line(INPUT_LINE_RESET, (data & 0x80) ? CLEAR_LINE : ASSERT_LINE);
mame_printf_debug("System register 1 = %02X\n", data);

View File

@ -235,11 +235,17 @@ public:
m_maincpu(*this, "maincpu"),
m_audiocpu(*this, "audiocpu"),
m_dsp(*this, "dsp"),
m_k001604(*this, "k001604") { }
m_k001604(*this, "k001604"),
m_adc12138(*this, "adc12138") { }
UINT8 m_led_reg0;
UINT8 m_led_reg1;
required_shared_ptr<UINT32> m_work_ram;
required_device<cpu_device> m_maincpu;
required_device<cpu_device> m_audiocpu;
required_device<cpu_device> m_dsp;
required_device<k001604_device> m_k001604;
required_device<adc12138_device> m_adc12138;
emu_timer *m_sound_irq_timer;
int m_fpga_uploaded;
int m_lanc2_ram_r;
@ -262,10 +268,6 @@ public:
UINT32 screen_update_nwktr(screen_device &screen, bitmap_rgb32 &bitmap, const rectangle &cliprect);
TIMER_CALLBACK_MEMBER(irq_off);
void lanc2_init();
required_device<cpu_device> m_maincpu;
required_device<cpu_device> m_audiocpu;
required_device<cpu_device> m_dsp;
required_device<k001604_device> m_k001604;
};
@ -307,7 +309,6 @@ UINT32 nwktr_state::screen_update_nwktr(screen_device &screen, bitmap_rgb32 &bit
READ32_MEMBER(nwktr_state::sysreg_r)
{
device_t *adc12138 = machine().device("adc12138");
UINT32 r = 0;
if (offset == 0)
{
@ -325,7 +326,7 @@ READ32_MEMBER(nwktr_state::sysreg_r)
}
if (ACCESSING_BITS_0_7)
{
r |= adc1213x_do_r(adc12138, space, 0) | (adc1213x_eoc_r(adc12138, space, 0) << 2);
r |= m_adc12138->do_r(space, 0) | (m_adc12138->eoc_r(space, 0) << 2);
}
}
else if (offset == 1)
@ -340,7 +341,6 @@ READ32_MEMBER(nwktr_state::sysreg_r)
WRITE32_MEMBER(nwktr_state::sysreg_w)
{
device_t *adc12138 = machine().device("adc12138");
if( offset == 0 )
{
if (ACCESSING_BITS_24_31)
@ -362,10 +362,10 @@ WRITE32_MEMBER(nwktr_state::sysreg_w)
int di = (data >> 25) & 0x1;
int sclk = (data >> 24) & 0x1;
adc1213x_cs_w(adc12138, space, 0, cs);
adc1213x_conv_w(adc12138, space, 0, conv);
adc1213x_di_w(adc12138, space, 0, di);
adc1213x_sclk_w(adc12138, space, 0, sclk);
m_adc12138->cs_w(space, 0, cs);
m_adc12138->conv_w(space, 0, conv);
m_adc12138->di_w(space, 0, di);
m_adc12138->sclk_w(space, 0, sclk);
}
if (ACCESSING_BITS_0_7)
{

View File

@ -49,7 +49,7 @@ public:
};
// ======================> gomoku_sound_device
// ======================> flower_sound_device
/* this structure defines the parameters for a channel */

View File

@ -7,8 +7,6 @@
#ifndef __NMK112_H__
#define __NMK112_H__
#include "devlegcy.h"
/***************************************************************************
TYPE DEFINITIONS
***************************************************************************/