Cleanup of ay8910 this makes move to devcb2 possible, also now

have better idea how to solve legacy STREAM_UPDATE (nw)
This commit is contained in:
Miodrag Milanovic 2014-04-30 14:37:32 +00:00
parent 8b7a48ca8c
commit 2c653877d0
8 changed files with 421 additions and 460 deletions

View File

@ -4,25 +4,25 @@
static void psg_set_clock(void *param, int clock)
{
ym2203_device *ym2203 = (ym2203_device *) param;
ay8910_set_clock_ym(ym2203->_psg(), clock);
ym2203->ay_set_clock(clock);
}
static void psg_write(void *param, int address, int data)
{
ym2203_device *ym2203 = (ym2203_device *) param;
ay8910_write_ym(ym2203->_psg(), address, data);
ym2203->ay8910_write_ym(address, data);
}
static int psg_read(void *param)
{
ym2203_device *ym2203 = (ym2203_device *) param;
return ay8910_read_ym(ym2203->_psg());
return ym2203->ay8910_read_ym();
}
static void psg_reset(void *param)
{
ym2203_device *ym2203 = (ym2203_device *) param;
ay8910_reset_ym(ym2203->_psg());
ym2203->ay8910_reset_ym();
}
static const ssg_callbacks psgintf =
@ -33,11 +33,6 @@ static const ssg_callbacks psgintf =
psg_reset
};
void *ym2203_device::_psg()
{
return m_psg;
}
/* IRQ Handler */
static void IRQHandler(void *param,int irq)
{
@ -99,13 +94,16 @@ void ym2203_device::_ym2203_update_request()
m_stream->update();
}
//-------------------------------------------------
// sound_stream_update - handle a stream update
//-------------------------------------------------
void ym2203_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples)
STREAM_UPDATE( ym2203_device::static_stream_generate )
{
reinterpret_cast<ym2203_device *>(param)->stream_generate(inputs, outputs, samples);
}
void ym2203_device::stream_generate(stream_sample_t **inputs, stream_sample_t **outputs, int samples)
{
ym2203_update_one(m_chip, outputs[0], samples);
}
@ -123,27 +121,18 @@ void ym2203_device::device_post_load()
void ym2203_device::device_start()
{
static const ay8910_interface default_ay8910_config =
{
AY8910_LEGACY_OUTPUT,
AY8910_DEFAULT_LOADS,
DEVCB_NULL, DEVCB_NULL, DEVCB_NULL, DEVCB_NULL
};
ay8910_device::device_start();
int rate = clock()/72; /* ??? */
const ay8910_interface *ay8910_config = m_ay8910_config != NULL ? m_ay8910_config : &default_ay8910_config;
m_irq_handler.resolve();
m_psg = ay8910_start_ym(this, ay8910_config);
assert_always(m_psg != NULL, "Error creating YM2203/AY8910 chip");
/* Timer Handler set */
m_timer[0] = timer_alloc(0);
m_timer[1] = timer_alloc(1);
/* stream system initialize */
m_stream = machine().sound().stream_alloc(*this,0,1,rate);
m_stream = machine().sound().stream_alloc(*this,0,1,rate, this, &ym2203_device::static_stream_generate);
/* Initialize FM emurator */
m_chip = ym2203_init(this,this,clock(),rate,timer_handler,IRQHandler,&psgintf);
@ -157,7 +146,6 @@ void ym2203_device::device_start()
void ym2203_device::device_stop()
{
ym2203_shutdown(m_chip);
ay8910_stop_ym(m_psg);
}
//-------------------------------------------------
@ -203,10 +191,9 @@ WRITE8_MEMBER( ym2203_device::write_port_w )
const device_type YM2203 = &device_creator<ym2203_device>;
ym2203_device::ym2203_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
: device_t(mconfig, YM2203, "YM2203", tag, owner, clock, "ym2203", __FILE__),
device_sound_interface(mconfig, *this),
: ay8910_device(mconfig, YM2203, "YM2203", tag, owner, clock, "ym2203", __FILE__),
m_irq_handler(*this),
m_ay8910_config(NULL)
m_ay8910_config(NULL)
{
}
@ -218,4 +205,15 @@ ym2203_device::ym2203_device(const machine_config &mconfig, const char *tag, dev
void ym2203_device::device_config_complete()
{
static const ay8910_interface default_ay8910_config =
{
AY8910_LEGACY_OUTPUT,
AY8910_DEFAULT_LOADS,
DEVCB_NULL, DEVCB_NULL, DEVCB_NULL, DEVCB_NULL
};
if (m_ay8910_config != NULL)
device_t::static_set_static_config(*this, m_ay8910_config);
else
device_t::static_set_static_config(*this, &(default_ay8910_config));
}

View File

@ -14,8 +14,7 @@ void ym2203_update_request(void *param);
#define MCFG_YM2203_AY8910_INTF(_ay8910_config) \
ym2203_device::set_ay8910_config(*device, _ay8910_config);
class ym2203_device : public device_t,
public device_sound_interface
class ym2203_device : public ay8910_device
{
public:
ym2203_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
@ -32,11 +31,9 @@ public:
DECLARE_WRITE8_MEMBER( control_port_w );
DECLARE_WRITE8_MEMBER( write_port_w );
void *_psg();
void _IRQHandler(int irq);
void _timer_handler(int c,int count,int clock);
void _ym2203_update_request();
protected:
// device-level overrides
virtual void device_config_complete();
@ -46,15 +43,13 @@ protected:
virtual void device_reset();
virtual void device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr);
// sound stream update overrides
virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples);
static STREAM_UPDATE( static_stream_generate );
void stream_generate(stream_sample_t **inputs, stream_sample_t **outputs, int samples);
private:
// internal state
sound_stream * m_stream;
emu_timer * m_timer[2];
void * m_chip;
void * m_psg;
devcb2_write_line m_irq_handler;
const ay8910_interface *m_ay8910_config;
};

View File

@ -17,25 +17,25 @@
static void psg_set_clock(void *param, int clock)
{
ym2608_device *ym2608 = (ym2608_device *) param;
ay8910_set_clock_ym(ym2608->_psg(), clock);
ym2608->ay_set_clock(clock);
}
static void psg_write(void *param, int address, int data)
{
ym2608_device *ym2608 = (ym2608_device *) param;
ay8910_write_ym(ym2608->_psg(), address, data);
ym2608->ay8910_write_ym(address, data);
}
static int psg_read(void *param)
{
ym2608_device *ym2608 = (ym2608_device *) param;
return ay8910_read_ym(ym2608->_psg());
return ym2608->ay8910_read_ym();
}
static void psg_reset(void *param)
{
ym2608_device *ym2608 = (ym2608_device *) param;
ay8910_reset_ym(ym2608->_psg());
ym2608->ay8910_reset_ym();
}
static const ssg_callbacks psgintf =
@ -46,11 +46,6 @@ static const ssg_callbacks psgintf =
psg_reset
};
void *ym2608_device::_psg()
{
return m_psg;
}
/* IRQ Handler */
static void IRQHandler(void *param,int irq)
{
@ -116,48 +111,43 @@ void ym2608_device::_ym2608_update_request()
// sound_stream_update - handle a stream update
//-------------------------------------------------
void ym2608_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples)
STREAM_UPDATE( ym2608_device::static_stream_generate )
{
reinterpret_cast<ym2608_device *>(param)->stream_generate(inputs, outputs, samples);
}
void ym2608_device::stream_generate(stream_sample_t **inputs, stream_sample_t **outputs, int samples)
{
ym2608_update_one(m_chip, outputs, samples);
}
void ym2608_device::device_post_load()
{
ym2608_postload(m_chip);
}
//-------------------------------------------------
// device_start - device-specific startup
//-------------------------------------------------
void ym2608_device::device_start()
{
static const ay8910_interface default_ay8910_config =
{
AY8910_LEGACY_OUTPUT | AY8910_SINGLE_OUTPUT,
AY8910_DEFAULT_LOADS,
DEVCB_NULL, DEVCB_NULL, DEVCB_NULL, DEVCB_NULL
};
ay8910_device::device_start();
int rate = clock()/72;
void *pcmbufa;
int pcmsizea;
const ay8910_interface *ay8910_config = m_ay8910_config != NULL ? m_ay8910_config : &default_ay8910_config;
m_irq_handler.resolve();
/* FIXME: Force to use single output */
m_psg = ay8910_start_ym(this, ay8910_config);
assert_always(m_psg != NULL, "Error creating YM2608/AY8910 chip");
/* Timer Handler set */
m_timer[0] = timer_alloc(0);
m_timer[1] = timer_alloc(1);
/* stream system initialize */
m_stream = machine().sound().stream_alloc(*this,0,2,rate);
m_stream = machine().sound().stream_alloc(*this,0,2,rate, this, &ym2608_device::static_stream_generate);
/* setup adpcm buffers */
pcmbufa = *region();
pcmsizea = region()->bytes();
@ -176,7 +166,6 @@ void ym2608_device::device_start()
void ym2608_device::device_stop()
{
ym2608_shutdown(m_chip);
ay8910_stop_ym(m_psg);
}
//-------------------------------------------------
@ -202,8 +191,7 @@ WRITE8_MEMBER( ym2608_device::write )
const device_type YM2608 = &device_creator<ym2608_device>;
ym2608_device::ym2608_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
: device_t(mconfig, YM2608, "YM2608", tag, owner, clock, "ym2608", __FILE__),
device_sound_interface(mconfig, *this),
: ay8910_device(mconfig, YM2608, "YM2608", tag, owner, clock, "ym2608", __FILE__),
m_irq_handler(*this),
m_ay8910_config(NULL)
{
@ -217,6 +205,16 @@ ym2608_device::ym2608_device(const machine_config &mconfig, const char *tag, dev
void ym2608_device::device_config_complete()
{
static const ay8910_interface default_ay8910_config =
{
AY8910_LEGACY_OUTPUT | AY8910_SINGLE_OUTPUT,
AY8910_DEFAULT_LOADS,
DEVCB_NULL, DEVCB_NULL, DEVCB_NULL, DEVCB_NULL
};
if (m_ay8910_config != NULL)
device_t::static_set_static_config(*this, m_ay8910_config);
else
device_t::static_set_static_config(*this, &(default_ay8910_config));
}
ROM_START( ym2608 )

View File

@ -14,8 +14,7 @@ void ym2608_update_request(void *param);
#define MCFG_YM2608_AY8910_INTF(_ay8910_config) \
ym2608_device::set_ay8910_config(*device, _ay8910_config);
class ym2608_device : public device_t,
public device_sound_interface
class ym2608_device : public ay8910_device
{
public:
ym2608_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
@ -27,7 +26,6 @@ public:
DECLARE_READ8_MEMBER( read );
DECLARE_WRITE8_MEMBER( write );
void *_psg();
void _IRQHandler(int irq);
void _timer_handler(int c,int count,int clock);
void _ym2608_update_request();
@ -43,15 +41,13 @@ protected:
virtual void device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr);
// sound stream update overrides
virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples);
static STREAM_UPDATE( static_stream_generate );
void stream_generate(stream_sample_t **inputs, stream_sample_t **outputs, int samples);
private:
// internal state
sound_stream * m_stream;
emu_timer * m_timer[2];
void * m_chip;
void * m_psg;
devcb2_write_line m_irq_handler;
const ay8910_interface *m_ay8910_config;
};

View File

@ -17,25 +17,25 @@
static void psg_set_clock(void *param, int clock)
{
ym2610_device *ym2610 = (ym2610_device *) param;
ay8910_set_clock_ym(ym2610->_psg(), clock);
ym2610->ay_set_clock(clock);
}
static void psg_write(void *param, int address, int data)
{
ym2610_device *ym2610 = (ym2610_device *) param;
ay8910_write_ym(ym2610->_psg(), address, data);
ym2610->ay8910_write_ym(address, data);
}
static int psg_read(void *param)
{
ym2610_device *ym2610 = (ym2610_device *) param;
return ay8910_read_ym(ym2610->_psg());
return ym2610->ay8910_read_ym();
}
static void psg_reset(void *param)
{
ym2610_device *ym2610 = (ym2610_device *) param;
ay8910_reset_ym(ym2610->_psg());
ym2610->ay8910_reset_ym();
}
static const ssg_callbacks psgintf =
@ -46,11 +46,6 @@ static const ssg_callbacks psgintf =
psg_reset
};
void *ym2610_device::_psg()
{
return m_psg;
}
/*------------------------- TM2610 -------------------------------*/
/* IRQ Handler */
static void IRQHandler(void *param,int irq)
@ -116,8 +111,12 @@ void ym2610_device::_ym2610_update_request()
//-------------------------------------------------
// sound_stream_update - handle a stream update
//-------------------------------------------------
STREAM_UPDATE( ym2610_device::static_stream_generate )
{
reinterpret_cast<ym2610_device *>(param)->stream_generate(inputs, outputs, samples);
}
void ym2610_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples)
void ym2610_device::stream_generate(stream_sample_t **inputs, stream_sample_t **outputs, int samples)
{
ym2610_update_one(m_chip, outputs, samples);
}
@ -126,7 +125,7 @@ void ym2610_device::sound_stream_update(sound_stream &stream, stream_sample_t **
// sound_stream_update - handle a stream update
//-------------------------------------------------
void ym2610b_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples)
void ym2610b_device::stream_generate(stream_sample_t **inputs, stream_sample_t **outputs, int samples)
{
ym2610b_update_one(m_chip, outputs, samples);
}
@ -144,28 +143,21 @@ void ym2610_device::device_post_load()
void ym2610_device::device_start()
{
static const ay8910_interface generic_ay8910 =
{
AY8910_LEGACY_OUTPUT | AY8910_SINGLE_OUTPUT,
AY8910_DEFAULT_LOADS,
DEVCB_NULL, DEVCB_NULL, DEVCB_NULL, DEVCB_NULL
};
ay8910_device::device_start();
int rate = clock()/72;
void *pcmbufa,*pcmbufb;
int pcmsizea,pcmsizeb;
astring name;
m_irq_handler.resolve();
m_psg = ay8910_start_ym(this, &generic_ay8910);
assert_always(m_psg != NULL, "Error creating YM2610/AY8910 chip");
/* Timer Handler set */
m_timer[0] = timer_alloc(0);
m_timer[1] = timer_alloc(1);
/* stream system initialize */
m_stream = machine().sound().stream_alloc(*this,0,2,rate);
m_stream = machine().sound().stream_alloc(*this,0,2,rate, this, &ym2610_device::static_stream_generate);
/* setup adpcm buffers */
pcmbufa = *region();
pcmsizea = region()->bytes();
@ -192,7 +184,6 @@ void ym2610_device::device_start()
void ym2610_device::device_stop()
{
ym2610_shutdown(m_chip);
ay8910_stop_ym(m_psg);
}
//-------------------------------------------------
@ -219,15 +210,13 @@ WRITE8_MEMBER( ym2610_device::write )
const device_type YM2610 = &device_creator<ym2610_device>;
ym2610_device::ym2610_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
: device_t(mconfig, YM2610, "YM2610", tag, owner, clock, "ym2610", __FILE__),
device_sound_interface(mconfig, *this),
: ay8910_device(mconfig, YM2610, "YM2610", tag, owner, clock, "ym2610", __FILE__),
m_irq_handler(*this)
{
}
ym2610_device::ym2610_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)
: device_t(mconfig, type, name, tag, owner, clock, shortname, source),
device_sound_interface(mconfig, *this),
: ay8910_device(mconfig, type, name, tag, owner, clock, shortname, source),
m_irq_handler(*this)
{
}
@ -240,6 +229,13 @@ ym2610_device::ym2610_device(const machine_config &mconfig, device_type type, co
void ym2610_device::device_config_complete()
{
static const ay8910_interface generic_ay8910 =
{
AY8910_LEGACY_OUTPUT | AY8910_SINGLE_OUTPUT,
AY8910_DEFAULT_LOADS,
DEVCB_NULL, DEVCB_NULL, DEVCB_NULL, DEVCB_NULL
};
device_t::static_set_static_config(*this, &(generic_ay8910));
}
const device_type YM2610B = &device_creator<ym2610b_device>;

View File

@ -11,8 +11,7 @@ void ym2610_update_request(void *param);
#define MCFG_YM2610_IRQ_HANDLER(_devcb) \
devcb = &ym2610_device::set_irq_handler(*device, DEVCB2_##_devcb);
class ym2610_device : public device_t,
public device_sound_interface
class ym2610_device : public ay8910_device
{
public:
ym2610_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
@ -24,7 +23,6 @@ public:
DECLARE_READ8_MEMBER( read );
DECLARE_WRITE8_MEMBER( write );
void *_psg();
void _IRQHandler(int irq);
void _timer_handler(int c,int count,int clock);
void _ym2610_update_request();
@ -39,8 +37,8 @@ protected:
virtual void device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr);
// sound stream update overrides
virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples);
static STREAM_UPDATE( static_stream_generate );
virtual void stream_generate(stream_sample_t **inputs, stream_sample_t **outputs, int samples);
void * m_chip;
@ -59,8 +57,7 @@ class ym2610b_device : public ym2610_device
public:
ym2610b_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
// sound stream update overrides
virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples);
virtual void stream_generate(stream_sample_t **inputs, stream_sample_t **outputs, int samples);
};
extern const device_type YM2610B;

File diff suppressed because it is too large Load Diff

View File

@ -72,6 +72,9 @@ YMZ294: 0 I/O port
#define YM2149_PIN26_LOW (0x10)
#define AY8910_NUM_CHANNELS 3
struct ay8910_interface
{
int flags; /* Flags */
@ -82,17 +85,6 @@ struct ay8910_interface
devcb_write8 portBwrite;
};
/*********** An interface for SSG of YM2203 ***********/
void *ay8910_start_ym(device_t *device, const ay8910_interface *intf);
void ay8910_stop_ym(void *chip);
void ay8910_reset_ym(void *chip);
void ay8910_set_clock_ym(void *chip, int clock);
void ay8910_set_volume(void *chip ,int channel, int volume);
void ay8910_write_ym(void *chip, int addr, int data);
int ay8910_read_ym(void *chip);
class ay8910_device : public device_t,
public device_sound_interface
{
@ -114,20 +106,65 @@ public:
DECLARE_WRITE8_MEMBER( address_data_w );
void set_volume(int channel,int volume);
void ay_set_clock(int clock);
struct ay_ym_param
{
double r_up;
double r_down;
int res_count;
double res[32];
};
void ay8910_write_ym(int addr, int data);
int ay8910_read_ym();
void ay8910_reset_ym();
protected:
// device-level overrides
virtual void device_config_complete();
virtual void device_start();
virtual void device_stop();
virtual void device_reset();
inline UINT16 mix_3D();
void ay8910_write_reg(int r, int v);
void build_mixer_table();
void ay8910_statesave();
// sound stream update overrides
virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples);
// internal state
const ay8910_interface *m_ay8910_config;
void *m_psg;
int m_streams;
int m_ready;
sound_stream *m_channel;
const ay8910_interface *m_intf;
INT32 m_register_latch;
UINT8 m_regs[16];
INT32 m_last_enable;
INT32 m_count[AY8910_NUM_CHANNELS];
UINT8 m_output[AY8910_NUM_CHANNELS];
UINT8 m_prescale_noise;
INT32 m_count_noise;
INT32 m_count_env;
INT8 m_env_step;
UINT32 m_env_volume;
UINT8 m_hold,m_alternate,m_attack,m_holding;
INT32 m_rng;
UINT8 m_env_step_mask;
/* init parameters ... */
int m_step;
int m_zero_is_off;
UINT8 m_vol_enabled[AY8910_NUM_CHANNELS];
const ay_ym_param *m_par;
const ay_ym_param *m_par_env;
INT32 m_vol_table[AY8910_NUM_CHANNELS][16];
INT32 m_env_table[AY8910_NUM_CHANNELS][32];
INT32 m_vol3d_table[8*32*32*32];
devcb_resolved_read8 m_portAread;
devcb_resolved_read8 m_portBread;
devcb_resolved_write8 m_portAwrite;
devcb_resolved_write8 m_portBwrite;
};
extern const device_type AY8910;
@ -173,9 +210,6 @@ class ym2149_device : public ay8910_device
public:
ym2149_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
ym2149_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);
protected:
// device-level overrides
virtual void device_start();
};
extern const device_type YM2149;