modernised the YMF262 [smf]

This commit is contained in:
smf- 2013-05-12 20:32:48 +00:00
parent 2b29166ff2
commit b690521bb2
6 changed files with 122 additions and 176 deletions

View File

@ -10,136 +10,136 @@
#include "ymf262.h"
struct ymf262_state
/* IRQ Handler */
static void IRQHandler(void *param,int irq)
{
sound_stream * stream;
emu_timer * timer[2];
void * chip;
const ymf262_interface *intf;
device_t *device;
devcb_resolved_write_line irqhandler;
};
ymf262_device *ymf262 = (ymf262_device *) param;
ymf262->_IRQHandler(irq);
}
INLINE ymf262_state *get_safe_token(device_t *device)
void ymf262_device::_IRQHandler(int irq)
{
assert(device != NULL);
assert(device->type() == YMF262);
return (ymf262_state *)downcast<ymf262_device *>(device)->token();
if (!m_irq_handler.isnull())
m_irq_handler(irq);
}
/* Timer overflow callback from timer.c */
void ymf262_device::device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr)
{
switch(id)
{
case 0:
ymf262_timer_over(m_chip,0);
break;
case 1:
ymf262_timer_over(m_chip,1);
break;
}
}
static void IRQHandler_262(void *param,int irq)
static void timer_handler(void *param, int c, attotime period)
{
ymf262_state *info = (ymf262_state *)param;
if (!info->irqhandler.isnull())
info->irqhandler(irq);
ymf262_device *ymf262 = (ymf262_device *) param;
ymf262->_timer_handler(c, period);
}
static TIMER_CALLBACK( timer_callback_262_0 )
void ymf262_device::_timer_handler(int c, attotime period)
{
ymf262_state *info = (ymf262_state *)ptr;
ymf262_timer_over(info->chip, 0);
}
static TIMER_CALLBACK( timer_callback_262_1 )
{
ymf262_state *info = (ymf262_state *)ptr;
ymf262_timer_over(info->chip, 1);
}
static void timer_handler_262(void *param,int timer, attotime period)
{
ymf262_state *info = (ymf262_state *)param;
if( period == attotime::zero )
{ /* Reset FM Timer */
info->timer[timer]->enable(false);
m_timer[c]->enable(false);
}
else
{ /* Start FM Timer */
info->timer[timer]->adjust(period);
m_timer[c]->adjust(period);
}
}
static STREAM_UPDATE( ymf262_stream_update )
void ymf262_update_request(void *param, int interval)
{
ymf262_state *info = (ymf262_state *)param;
ymf262_update_one(info->chip, outputs, samples);
ymf262_device *ymf262 = (ymf262_device *) param;
ymf262->_ymf262_update_request();
}
static void _stream_update(void *param, int interval)
void ymf262_device::_ymf262_update_request()
{
ymf262_state *info = (ymf262_state *)param;
info->stream->update();
m_stream->update();
}
static DEVICE_START( ymf262 )
{
static const ymf262_interface dummy = { DEVCB_NULL };
ymf262_state *info = get_safe_token(device);
int rate = device->clock()/288;
info->intf = device->static_config() ? (const ymf262_interface *)device->static_config() : &dummy;
info->device = device;
info->irqhandler.resolve(info->intf->irqhandler, *device);
//-------------------------------------------------
// sound_stream_update - handle a stream update
//-------------------------------------------------
void ymf262_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples)
{
ymf262_update_one(m_chip, outputs, samples);
}
//-------------------------------------------------
// device_start - device-specific startup
//-------------------------------------------------
void ymf262_device::device_start()
{
int rate = clock()/288;
m_irq_handler.resolve();
/* stream system initialize */
info->chip = ymf262_init(device,device->clock(),rate);
assert_always(info->chip != NULL, "Error creating YMF262 chip");
m_chip = ymf262_init(this,clock(),rate);
assert_always(m_chip != NULL, "Error creating YMF262 chip");
info->stream = device->machine().sound().stream_alloc(*device,0,4,rate,info,ymf262_stream_update);
m_stream = machine().sound().stream_alloc(*this,0,4,rate);
/* YMF262 setup */
ymf262_set_timer_handler (info->chip, timer_handler_262, info);
ymf262_set_irq_handler (info->chip, IRQHandler_262, info);
ymf262_set_update_handler(info->chip, _stream_update, info);
ymf262_set_timer_handler (m_chip, timer_handler, this);
ymf262_set_irq_handler (m_chip, IRQHandler, this);
ymf262_set_update_handler(m_chip, ymf262_update_request, this);
info->timer[0] = device->machine().scheduler().timer_alloc(FUNC(timer_callback_262_0), info);
info->timer[1] = device->machine().scheduler().timer_alloc(FUNC(timer_callback_262_1), info);
m_timer[0] = timer_alloc(0);
m_timer[1] = timer_alloc(1);
}
static DEVICE_STOP( ymf262 )
//-------------------------------------------------
// device_stop - device-specific stop
//-------------------------------------------------
void ymf262_device::device_stop()
{
ymf262_state *info = get_safe_token(device);
ymf262_shutdown(info->chip);
ymf262_shutdown(m_chip);
}
/* reset */
static DEVICE_RESET( ymf262 )
//-------------------------------------------------
// device_reset - device-specific reset
//-------------------------------------------------
void ymf262_device::device_reset()
{
ymf262_state *info = get_safe_token(device);
ymf262_reset_chip(info->chip);
ymf262_reset_chip(m_chip);
}
READ8_DEVICE_HANDLER( ymf262_r )
READ8_MEMBER( ymf262_device::read )
{
ymf262_state *info = get_safe_token(device);
return ymf262_read(info->chip, offset & 3);
return ymf262_read(m_chip, offset & 3);
}
WRITE8_DEVICE_HANDLER( ymf262_w )
WRITE8_MEMBER( ymf262_device::write )
{
ymf262_state *info = get_safe_token(device);
ymf262_write(info->chip, offset & 3, data);
ymf262_write(m_chip, offset & 3, data);
}
READ8_DEVICE_HANDLER ( ymf262_status_r ) { return ymf262_r(device, space, 0); }
WRITE8_DEVICE_HANDLER( ymf262_register_a_w ) { ymf262_w(device, space, 0, data); }
WRITE8_DEVICE_HANDLER( ymf262_register_b_w ) { ymf262_w(device, space, 2, data); }
WRITE8_DEVICE_HANDLER( ymf262_data_a_w ) { ymf262_w(device, space, 1, data); }
WRITE8_DEVICE_HANDLER( ymf262_data_b_w ) { ymf262_w(device, space, 3, data); }
const device_type YMF262 = &device_creator<ymf262_device>;
ymf262_device::ymf262_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
: device_t(mconfig, YMF262, "YMF262", tag, owner, clock),
device_sound_interface(mconfig, *this)
device_sound_interface(mconfig, *this),
m_irq_handler(*this)
{
m_token = global_alloc_clear(ymf262_state);
}
//-------------------------------------------------
@ -151,40 +151,3 @@ ymf262_device::ymf262_device(const machine_config &mconfig, const char *tag, dev
void ymf262_device::device_config_complete()
{
}
//-------------------------------------------------
// device_start - device-specific startup
//-------------------------------------------------
void ymf262_device::device_start()
{
DEVICE_START_NAME( ymf262 )(this);
}
//-------------------------------------------------
// device_reset - device-specific reset
//-------------------------------------------------
void ymf262_device::device_reset()
{
DEVICE_RESET_NAME( ymf262 )(this);
}
//-------------------------------------------------
// device_stop - device-specific stop
//-------------------------------------------------
void ymf262_device::device_stop()
{
DEVICE_STOP_NAME( ymf262 )(this);
}
//-------------------------------------------------
// sound_stream_update - handle a stream update
//-------------------------------------------------
void ymf262_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples)
{
// should never get here
fatalerror("sound_stream_update called; not applicable to legacy sound devices\n");
}

View File

@ -3,34 +3,29 @@
#ifndef __262INTF_H__
#define __262INTF_H__
#include "devlegcy.h"
struct ymf262_interface
{
devcb_write_line irqhandler;
};
DECLARE_READ8_DEVICE_HANDLER( ymf262_r );
DECLARE_WRITE8_DEVICE_HANDLER( ymf262_w );
DECLARE_READ8_DEVICE_HANDLER ( ymf262_status_r );
DECLARE_WRITE8_DEVICE_HANDLER( ymf262_register_a_w );
DECLARE_WRITE8_DEVICE_HANDLER( ymf262_register_b_w );
DECLARE_WRITE8_DEVICE_HANDLER( ymf262_data_a_w );
DECLARE_WRITE8_DEVICE_HANDLER( ymf262_data_b_w );
#include "emu.h"
#define MCFG_YMF262_IRQ_HANDLER(_devcb) \
devcb = &ymf262_device::set_irq_handler(*device, DEVCB2_##_devcb);
class ymf262_device : public device_t,
public device_sound_interface
{
public:
ymf262_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
~ymf262_device() { global_free(m_token); }
// access to legacy token
void *token() const { assert(m_token != NULL); return m_token; }
// static configuration helpers
template<class _Object> static devcb2_base &set_irq_handler(device_t &device, _Object object) { return downcast<ymf262_device &>(device).m_irq_handler.set_callback(object); }
DECLARE_READ8_MEMBER( read );
DECLARE_WRITE8_MEMBER( write );
void _IRQHandler(int irq);
void _timer_handler(int c, attotime period);
void _ymf262_update_request();
virtual void device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr);
protected:
// device-level overrides
virtual void device_config_complete();
@ -42,7 +37,10 @@ protected:
virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples);
private:
// internal state
void *m_token;
sound_stream * m_stream;
emu_timer * m_timer[2];
void * m_chip;
devcb2_write_line m_irq_handler;
};
extern const device_type YMF262;

View File

@ -1,4 +1,3 @@
#include "sound/262intf.h"
#include "sound/2151intf.h"

View File

@ -286,7 +286,7 @@ WRITE8_MEMBER(fuuki32_state::snd_ymf278b_w)
// also write to ymf262
if (offset < 4)
ymf262_w(machine().device("ymf2"), space, offset, data);
machine().device<ymf262_device>("ymf2")->write(space, offset, data);
}
static ADDRESS_MAP_START( fuuki32_sound_map, AS_PROGRAM, 8, fuuki32_state )
@ -576,11 +576,6 @@ static const ymf278b_interface fuuki32_ymf278b_interface =
DEVCB_DRIVER_LINE_MEMBER(fuuki32_state,irqhandler) /* irq */
};
static const ymf262_interface fuuki32_ymf262_interface =
{
DEVCB_NULL /* irq, already hooked up via ymf278b */
};
static MACHINE_CONFIG_START( fuuki32, fuuki32_state )
/* basic machine hardware */
@ -613,7 +608,6 @@ static MACHINE_CONFIG_START( fuuki32, fuuki32_state )
MCFG_SOUND_ROUTE(1, "rspeaker", 0.50)
MCFG_SOUND_ADD("ymf2", YMF262, YMF278B_STD_CLOCK / (19/8.0))
MCFG_SOUND_CONFIG(fuuki32_ymf262_interface)
MCFG_SOUND_ROUTE(0, "lspeaker", 0.40)
MCFG_SOUND_ROUTE(1, "rspeaker", 0.40)
MCFG_SOUND_ROUTE(2, "lspeaker", 0.40)

View File

@ -345,7 +345,7 @@ ADDRESS_MAP_END
static ADDRESS_MAP_START( io_map, AS_IO, 8, tecmosys_state )
ADDRESS_MAP_GLOBAL_MASK(0xff)
AM_RANGE(0x00, 0x03) AM_DEVREADWRITE_LEGACY("ymf", ymf262_r, ymf262_w)
AM_RANGE(0x00, 0x03) AM_DEVREADWRITE("ymf", ymf262_device, read, write)
AM_RANGE(0x10, 0x10) AM_DEVREADWRITE("oki", okim6295_device, read, write)
AM_RANGE(0x20, 0x20) AM_WRITE(tecmosys_oki_bank_w)
AM_RANGE(0x30, 0x30) AM_WRITE(tecmosys_z80_bank_w)
@ -438,11 +438,6 @@ WRITE_LINE_MEMBER(tecmosys_state::sound_irq)
m_audiocpu->set_input_line(0, state ? ASSERT_LINE : CLEAR_LINE);
}
static const ymf262_interface tecmosys_ymf262_interface =
{
DEVCB_DRIVER_LINE_MEMBER(tecmosys_state,sound_irq) /* irq */
};
void tecmosys_state::machine_start()
{
membank("bank1")->configure_entries(0, 16, memregion("audiocpu")->base(), 0x4000);
@ -479,7 +474,7 @@ static MACHINE_CONFIG_START( deroon, tecmosys_state )
MCFG_SPEAKER_STANDARD_STEREO("lspeaker", "rspeaker")
MCFG_SOUND_ADD("ymf", YMF262, XTAL_14_31818MHz)
MCFG_SOUND_CONFIG(tecmosys_ymf262_interface)
MCFG_YMF262_IRQ_HANDLER(WRITELINE(tecmosys_state, sound_irq))
MCFG_SOUND_ROUTE(0, "lspeaker", 1.00)
MCFG_SOUND_ROUTE(1, "rspeaker", 1.00)
MCFG_SOUND_ROUTE(2, "lspeaker", 1.00)

View File

@ -66,11 +66,6 @@ static const ym3812_interface pc_ym3812_interface =
DEVCB_NULL
};
static const ymf262_interface pc_ymf262_interface =
{
DEVCB_NULL
};
static SLOT_INTERFACE_START(midiin_slot)
SLOT_INTERFACE("midiin", MIDIIN_PORT)
SLOT_INTERFACE_END
@ -133,7 +128,6 @@ MACHINE_CONFIG_END
static MACHINE_CONFIG_FRAGMENT( sblaster_16_config )
MCFG_SPEAKER_STANDARD_STEREO("lspeaker", "rspeaker")
MCFG_SOUND_ADD("ymf262", YMF262, ymf262_StdClock)
MCFG_SOUND_CONFIG(pc_ymf262_interface)
MCFG_SOUND_ROUTE(0, "lspeaker", 1.00)
MCFG_SOUND_ROUTE(1, "rspeaker", 1.00)
MCFG_SOUND_ROUTE(2, "lspeaker", 1.00)
@ -1164,17 +1158,18 @@ isa16_sblaster16_device::isa16_sblaster16_device(const machine_config &mconfig,
void sb8_device::device_start()
{
m_isa->install_device( 0x0200, 0x0207, 0, 0, read8_delegate(FUNC(pc_joy_device::joy_port_r), subdevice<pc_joy_device>("pc_joy")), write8_delegate(FUNC(pc_joy_device::joy_port_w), subdevice<pc_joy_device>("pc_joy")));
m_isa->install_device( 0x0226, 0x0227, 0, 0, read8_delegate(FUNC(sb_device::dsp_reset_r), this), write8_delegate(FUNC(sb_device::dsp_reset_w), this));
m_isa->install_device( 0x022a, 0x022b, 0, 0, read8_delegate(FUNC(sb_device::dsp_data_r), this), write8_delegate(FUNC(sb_device::dsp_data_w), this) );
m_isa->install_device( 0x022c, 0x022d, 0, 0, read8_delegate(FUNC(sb_device::dsp_wbuf_status_r), this), write8_delegate(FUNC(sb_device::dsp_cmd_w), this) );
m_isa->install_device( 0x022e, 0x022f, 0, 0, read8_delegate(FUNC(sb_device::dsp_rbuf_status_r), this), write8_delegate(FUNC(sb_device::dsp_rbuf_status_w), this) );
m_isa->install_device(0x0200, 0x0207, 0, 0, read8_delegate(FUNC(pc_joy_device::joy_port_r), subdevice<pc_joy_device>("pc_joy")), write8_delegate(FUNC(pc_joy_device::joy_port_w), subdevice<pc_joy_device>("pc_joy")));
m_isa->install_device(0x0226, 0x0227, 0, 0, read8_delegate(FUNC(sb_device::dsp_reset_r), this), write8_delegate(FUNC(sb_device::dsp_reset_w), this));
m_isa->install_device(0x022a, 0x022b, 0, 0, read8_delegate(FUNC(sb_device::dsp_data_r), this), write8_delegate(FUNC(sb_device::dsp_data_w), this) );
m_isa->install_device(0x022c, 0x022d, 0, 0, read8_delegate(FUNC(sb_device::dsp_wbuf_status_r), this), write8_delegate(FUNC(sb_device::dsp_cmd_w), this) );
m_isa->install_device(0x022e, 0x022f, 0, 0, read8_delegate(FUNC(sb_device::dsp_rbuf_status_r), this), write8_delegate(FUNC(sb_device::dsp_rbuf_status_w), this) );
if(m_dsp.version >= 0x0301)
{
//m_isa->install_device(0x0224, 0x0225, 0, 0, read8_delegate(FUNC(sb8_device::mixer_r), this), write8_delegate(FUNC(sb8_device::mixer_w), this));
m_isa->install_device(subdevice("ymf262"), 0x0388, 0x038b, 0, 0, FUNC(ymf262_r), FUNC(ymf262_w) );
m_isa->install_device(subdevice("ymf262"), 0x0220, 0x0223, 0, 0, FUNC(ymf262_r), FUNC(ymf262_w) );
m_isa->install_device(subdevice("ymf262"), 0x0228, 0x0229, 0, 0, FUNC(ymf262_r), FUNC(ymf262_w) );
ymf262_device *ymf262 = subdevice<ymf262_device>("ymf262");
m_isa->install_device(0x0388, 0x038b, 0, 0, read8_delegate(FUNC(ymf262_device::read), ymf262), write8_delegate(FUNC(ymf262_device::write), ymf262));
m_isa->install_device(0x0220, 0x0223, 0, 0, read8_delegate(FUNC(ymf262_device::read), ymf262), write8_delegate(FUNC(ymf262_device::write), ymf262));
m_isa->install_device(0x0228, 0x0229, 0, 0, read8_delegate(FUNC(ymf262_device::read), ymf262), write8_delegate(FUNC(ymf262_device::write), ymf262));
}
else
{
@ -1222,16 +1217,18 @@ void isa8_sblaster1_5_device::device_start()
void sb16_device::device_start()
{
m_isa->install_device( 0x0200, 0x0207, 0, 0, read8_delegate(FUNC(pc_joy_device::joy_port_r), subdevice<pc_joy_device>("pc_joy")), write8_delegate(FUNC(pc_joy_device::joy_port_w), subdevice<pc_joy_device>("pc_joy")));
m_isa->install_device( 0x0224, 0x0225, 0, 0, read8_delegate(FUNC(sb16_device::mixer_r), this), write8_delegate(FUNC(sb16_device::mixer_w), this));
m_isa->install_device( 0x0226, 0x0227, 0, 0, read8_delegate(FUNC(sb_device::dsp_reset_r), this), write8_delegate(FUNC(sb_device::dsp_reset_w), this));
m_isa->install_device( 0x022a, 0x022b, 0, 0, read8_delegate(FUNC(sb_device::dsp_data_r), this), write8_delegate(FUNC(sb_device::dsp_data_w), this) );
m_isa->install_device( 0x022c, 0x022d, 0, 0, read8_delegate(FUNC(sb_device::dsp_wbuf_status_r), this), write8_delegate(FUNC(sb_device::dsp_cmd_w), this) );
m_isa->install_device( 0x022e, 0x022f, 0, 0, read8_delegate(FUNC(sb_device::dsp_rbuf_status_r), this), write8_delegate(FUNC(sb_device::dsp_rbuf_status_w), this) );
m_isa->install_device( 0x0330, 0x0331, 0, 0, read8_delegate(FUNC(sb16_device::mpu401_r), this), write8_delegate(FUNC(sb16_device::mpu401_w), this));
m_isa->install_device(subdevice("ymf262"), 0x0388, 0x038b, 0, 0, FUNC(ymf262_r), FUNC(ymf262_w) );
m_isa->install_device(subdevice("ymf262"), 0x0220, 0x0223, 0, 0, FUNC(ymf262_r), FUNC(ymf262_w) );
m_isa->install_device(subdevice("ymf262"), 0x0228, 0x0229, 0, 0, FUNC(ymf262_r), FUNC(ymf262_w) );
ymf262_device *ymf262 = subdevice<ymf262_device>("ymf262");
m_isa->install_device(0x0200, 0x0207, 0, 0, read8_delegate(FUNC(pc_joy_device::joy_port_r), subdevice<pc_joy_device>("pc_joy")), write8_delegate(FUNC(pc_joy_device::joy_port_w), subdevice<pc_joy_device>("pc_joy")));
m_isa->install_device(0x0224, 0x0225, 0, 0, read8_delegate(FUNC(sb16_device::mixer_r), this), write8_delegate(FUNC(sb16_device::mixer_w), this));
m_isa->install_device(0x0226, 0x0227, 0, 0, read8_delegate(FUNC(sb_device::dsp_reset_r), this), write8_delegate(FUNC(sb_device::dsp_reset_w), this));
m_isa->install_device(0x022a, 0x022b, 0, 0, read8_delegate(FUNC(sb_device::dsp_data_r), this), write8_delegate(FUNC(sb_device::dsp_data_w), this) );
m_isa->install_device(0x022c, 0x022d, 0, 0, read8_delegate(FUNC(sb_device::dsp_wbuf_status_r), this), write8_delegate(FUNC(sb_device::dsp_cmd_w), this) );
m_isa->install_device(0x022e, 0x022f, 0, 0, read8_delegate(FUNC(sb_device::dsp_rbuf_status_r), this), write8_delegate(FUNC(sb_device::dsp_rbuf_status_w), this) );
m_isa->install_device(0x0330, 0x0331, 0, 0, read8_delegate(FUNC(sb16_device::mpu401_r), this), write8_delegate(FUNC(sb16_device::mpu401_w), this));
m_isa->install_device(0x0388, 0x038b, 0, 0, read8_delegate(FUNC(ymf262_device::read), ymf262), write8_delegate(FUNC(ymf262_device::write), ymf262));
m_isa->install_device(0x0220, 0x0223, 0, 0, read8_delegate(FUNC(ymf262_device::read), ymf262), write8_delegate(FUNC(ymf262_device::write), ymf262));
m_isa->install_device(0x0228, 0x0229, 0, 0, read8_delegate(FUNC(ymf262_device::read), ymf262), write8_delegate(FUNC(ymf262_device::write), ymf262));
m_timer = timer_alloc(0, NULL);