From c28fe11f397f5d769fa38e479b68876ecc67845b Mon Sep 17 00:00:00 2001 From: Andrew Gardner Date: Sun, 30 Dec 2012 15:56:01 +0000 Subject: [PATCH] Modernize vrender0 (crystal system) sound device. [Andrew Gardner] --- src/emu/sound/vrender0.c | 175 ++++++++++++++++--------------------- src/emu/sound/vrender0.h | 47 +++++++--- src/mame/drivers/crystal.c | 6 +- 3 files changed, 111 insertions(+), 117 deletions(-) diff --git a/src/emu/sound/vrender0.c b/src/emu/sound/vrender0.c index 23cc7ba0b76..3c5a77c3c87 100644 --- a/src/emu/sound/vrender0.c +++ b/src/emu/sound/vrender0.c @@ -12,30 +12,6 @@ reverb interrupts *************/ -struct vr0_state -{ - UINT32 *TexBase; - UINT32 *FBBase; - UINT32 SOUNDREGS[0x10000/4]; - vr0_interface Intf; - sound_stream * stream; -}; - -INLINE vr0_state *get_safe_token(device_t *device) -{ - assert(device != NULL); - assert(device->type() == VRENDER0); - return (vr0_state *)downcast(device)->token(); -} - -static void VR0_RenderAudio(vr0_state *VR0, int nsamples,stream_sample_t *l,stream_sample_t *r); - -static STREAM_UPDATE( VR0_Update ) -{ - vr0_state *VR0 = (vr0_state *)param; - VR0_RenderAudio(VR0, samples,outputs[0],outputs[1]); -} - //Correct table thanks to Evoga //they left a ulaw<->linear conversion tool inside the roms static const unsigned short ULawTo16[]= @@ -75,16 +51,16 @@ static const unsigned short ULawTo16[]= }; -#define STATUS VR0->SOUNDREGS[0x404/4] -#define CURSADDR(chan) (VR0->SOUNDREGS[(0x20/4)*chan+0x00]) -#define DSADDR(chan) ((VR0->SOUNDREGS[(0x20/4)*chan+0x08/4]>>0)&0xffff) -#define LOOPBEGIN(chan) (VR0->SOUNDREGS[(0x20/4)*chan+0x0c/4]&0x3fffff) -#define LOOPEND(chan) (VR0->SOUNDREGS[(0x20/4)*chan+0x10/4]&0x3fffff) -#define ENVVOL(chan) (VR0->SOUNDREGS[(0x20/4)*chan+0x04/4]&0xffffff) +#define STATUS m_SOUNDREGS[0x404/4] +#define CURSADDR(chan) (m_SOUNDREGS[(0x20/4)*chan+0x00]) +#define DSADDR(chan) ((m_SOUNDREGS[(0x20/4)*chan+0x08/4]>>0)&0xffff) +#define LOOPBEGIN(chan) (m_SOUNDREGS[(0x20/4)*chan+0x0c/4]&0x3fffff) +#define LOOPEND(chan) (m_SOUNDREGS[(0x20/4)*chan+0x10/4]&0x3fffff) +#define ENVVOL(chan) (m_SOUNDREGS[(0x20/4)*chan+0x04/4]&0xffffff) /* -#define GETSOUNDREG16(Chan,Offs) space.read_word(VR0->Intf.reg_base+0x20*Chan+Offs) -#define GETSOUNDREG32(Chan,Offs) space.read_dword(VR0->Intf.reg_base+0x20*Chan+Offs) +#define GETSOUNDREG16(Chan,Offs) space.read_word(m_Intf.reg_base+0x20*Chan+Offs) +#define GETSOUNDREG32(Chan,Offs) space.read_dword(m_Intf.reg_base+0x20*Chan+Offs) #define CURSADDR(chan) GETSOUNDREG32(chan,0x00) #define DSADDR(chan) GETSOUNDREG16(chan,0x08) @@ -92,31 +68,66 @@ static const unsigned short ULawTo16[]= #define LOOPEND(chan) (GETSOUNDREG32(chan,0x10)&0x3fffff) #define ENVVOL(chan) (GETSOUNDREG32(chan,0x04)&0xffffff) */ -void vr0_snd_set_areas(device_t *device,UINT32 *texture,UINT32 *frame) + + + +//************************************************************************** +// LIVE DEVICE +//************************************************************************** + +const device_type VRENDER0 = &device_creator; + +//------------------------------------------------- +// vrender0_device - constructor +//------------------------------------------------- + +vrender0_device::vrender0_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock) + : device_t(mconfig, VRENDER0, "VRender0", tag, owner, clock), + device_sound_interface(mconfig, *this), + m_TexBase(NULL), + m_FBBase(NULL), + m_stream(NULL) { - vr0_state *VR0 = get_safe_token(device); - VR0->TexBase=texture; - VR0->FBBase=frame; } -static DEVICE_START( vrender0 ) + +//------------------------------------------------- +// device_start - device-specific startup +//------------------------------------------------- + +void vrender0_device::device_start() { - const vr0_interface *intf; - vr0_state *VR0 = get_safe_token(device); + const vr0_interface *intf = (const vr0_interface *)static_config(); - intf = (const vr0_interface *)device->static_config(); + memcpy(&(m_Intf),intf,sizeof(vr0_interface)); + memset(m_SOUNDREGS,0,sizeof(m_SOUNDREGS)); - memcpy(&(VR0->Intf),intf,sizeof(vr0_interface)); - memset(VR0->SOUNDREGS,0,sizeof(VR0->SOUNDREGS)); + m_stream = stream_alloc(0, 2, 44100); - VR0->stream = device->machine().sound().stream_alloc(*device, 0, 2, 44100, VR0, VR0_Update); - - device->save_item(NAME(VR0->SOUNDREGS)); + save_item(NAME(m_SOUNDREGS)); } -WRITE32_DEVICE_HANDLER(vr0_snd_write) + +//------------------------------------------------- +// sound_stream_update - handle update requests +// for our sound stream +//------------------------------------------------- + +void vrender0_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) +{ + VR0_RenderAudio(samples, outputs[0], outputs[1]); +} + + + +READ32_MEMBER(vrender0_device::vr0_snd_read) +{ + return m_SOUNDREGS[offset]; +} + + +WRITE32_MEMBER(vrender0_device::vr0_snd_write) { - vr0_state *VR0 = get_safe_token(device); if(offset==0x404/4) { data&=0xffff; @@ -134,34 +145,35 @@ WRITE32_DEVICE_HANDLER(vr0_snd_write) } else { - COMBINE_DATA(&VR0->SOUNDREGS[offset]); + COMBINE_DATA(&m_SOUNDREGS[offset]); } } -READ32_DEVICE_HANDLER(vr0_snd_read) +void vrender0_device::set_areas(UINT32 *texture, UINT32 *frame) { - vr0_state *VR0 = get_safe_token(device); - return VR0->SOUNDREGS[offset]; + m_TexBase=texture; + m_FBBase=frame; } -static void VR0_RenderAudio(vr0_state *VR0, int nsamples,stream_sample_t *l,stream_sample_t *r) + +void vrender0_device::VR0_RenderAudio(int nsamples, stream_sample_t *l, stream_sample_t *r) { INT16 *SAMPLES; UINT32 st=STATUS; signed int lsample=0,rsample=0; - UINT32 CLK=(VR0->SOUNDREGS[0x600/4]>>0)&0xff; - UINT32 NCH=(VR0->SOUNDREGS[0x600/4]>>8)&0xff; - UINT32 CT1=(VR0->SOUNDREGS[0x600/4]>>16)&0xff; - UINT32 CT2=(VR0->SOUNDREGS[0x600/4]>>24)&0xff; + UINT32 CLK=(m_SOUNDREGS[0x600/4]>>0)&0xff; + UINT32 NCH=(m_SOUNDREGS[0x600/4]>>8)&0xff; + UINT32 CT1=(m_SOUNDREGS[0x600/4]>>16)&0xff; + UINT32 CT2=(m_SOUNDREGS[0x600/4]>>24)&0xff; int div; int s; if(CT1&0x20) - SAMPLES=(INT16 *)VR0->TexBase; + SAMPLES=(INT16 *)m_TexBase; else - SAMPLES=(INT16 *)VR0->FBBase; + SAMPLES=(INT16 *)m_FBBase; if(CLK) div=((30<<16)|0x8000)/(CLK+1); @@ -177,9 +189,9 @@ static void VR0_RenderAudio(vr0_state *VR0, int nsamples,stream_sample_t *l,stre signed int sample; UINT32 cur=CURSADDR(i); UINT32 a=LOOPBEGIN(i)+(cur>>10); - UINT8 Mode=VR0->SOUNDREGS[(0x20/4)*i+0x8/4]>>24; - signed int LVOL=VR0->SOUNDREGS[(0x20/4)*i+0xc/4]>>24; - signed int RVOL=VR0->SOUNDREGS[(0x20/4)*i+0x10/4]>>24; + UINT8 Mode=m_SOUNDREGS[(0x20/4)*i+0x8/4]>>24; + signed int LVOL=m_SOUNDREGS[(0x20/4)*i+0xc/4]>>24; + signed int RVOL=m_SOUNDREGS[(0x20/4)*i+0x10/4]>>24; INT32 DSADD=(DSADDR(i)*div)>>16; @@ -236,44 +248,3 @@ static void VR0_RenderAudio(vr0_state *VR0, int nsamples,stream_sample_t *l,stre r[s]=rsample; } } - - -const device_type VRENDER0 = &device_creator; - -vrender0_device::vrender0_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock) - : device_t(mconfig, VRENDER0, "VRender0", tag, owner, clock), - device_sound_interface(mconfig, *this) -{ - m_token = global_alloc_clear(vr0_state); -} - -//------------------------------------------------- -// device_config_complete - perform any -// operations now that the configuration is -// complete -//------------------------------------------------- - -void vrender0_device::device_config_complete() -{ -} - -//------------------------------------------------- -// device_start - device-specific startup -//------------------------------------------------- - -void vrender0_device::device_start() -{ - DEVICE_START_NAME( vrender0 )(this); -} - -//------------------------------------------------- -// sound_stream_update - handle a stream update -//------------------------------------------------- - -void vrender0_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"); -} - - diff --git a/src/emu/sound/vrender0.h b/src/emu/sound/vrender0.h index 444aa547744..064fc359873 100644 --- a/src/emu/sound/vrender0.h +++ b/src/emu/sound/vrender0.h @@ -3,38 +3,61 @@ #ifndef __VRENDER0_H__ #define __VRENDER0_H__ -#include "devlegcy.h" +//************************************************************************** +// INTERFACE CONFIGURATION MACROS +//************************************************************************** + +#define MCFG_SOUND_VRENDER0_ADD(_tag, _clock) \ + MCFG_DEVICE_ADD(_tag, VRENDER0, _clock) \ + +#define MCFG_SOUND_VRENDER0_REPLACE(_tag, _clock) \ + MCFG_DEVICE_REPLACE(_tag, VRENDER0, _clock) \ + + + +//************************************************************************** +// TYPE DEFINITIONS +//************************************************************************** + + +// ======================> vrender0_device struct vr0_interface { UINT32 RegBase; }; -void vr0_snd_set_areas(device_t *device,UINT32 *texture,UINT32 *frame); - -DECLARE_READ32_DEVICE_HANDLER( vr0_snd_read ); -DECLARE_WRITE32_DEVICE_HANDLER( vr0_snd_write ); +void vr0_snd_set_areas(device_t *device, UINT32 *texture, UINT32 *frame); class vrender0_device : public device_t, - public device_sound_interface + public device_sound_interface { public: vrender0_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock); - ~vrender0_device() { global_free(m_token); } + ~vrender0_device() { } - // 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(); // sound stream update overrides virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples); + +public: + DECLARE_READ32_MEMBER( vr0_snd_read ); + DECLARE_WRITE32_MEMBER( vr0_snd_write ); + + void set_areas(UINT32 *texture, UINT32 *frame); + private: - // internal state - void *m_token; + UINT32 *m_TexBase; + UINT32 *m_FBBase; + UINT32 m_SOUNDREGS[0x10000/4]; + sound_stream *m_stream; + vr0_interface m_Intf; + + void VR0_RenderAudio(int nsamples, stream_sample_t *l, stream_sample_t *r); }; extern const device_type VRENDER0; diff --git a/src/mame/drivers/crystal.c b/src/mame/drivers/crystal.c index ee849c108e7..b559b08bbfe 100644 --- a/src/mame/drivers/crystal.c +++ b/src/mame/drivers/crystal.c @@ -510,7 +510,7 @@ static ADDRESS_MAP_START( crystal_mem, AS_PROGRAM, 32, crystal_state ) AM_RANGE(0x03000000, 0x0300ffff) AM_RAM AM_SHARE("vidregs") AM_RANGE(0x03800000, 0x03ffffff) AM_RAM AM_SHARE("textureram") AM_RANGE(0x04000000, 0x047fffff) AM_RAM AM_SHARE("frameram") - AM_RANGE(0x04800000, 0x04800fff) AM_DEVREADWRITE_LEGACY("vrender", vr0_snd_read, vr0_snd_write) + AM_RANGE(0x04800000, 0x04800fff) AM_DEVREADWRITE("vrender", vrender0_device, vr0_snd_read, vr0_snd_write) AM_RANGE(0x05000000, 0x05000003) AM_READWRITE(FlashCmd_r, FlashCmd_w) AM_RANGE(0x05000000, 0x05ffffff) AM_ROMBANK("bank1") @@ -631,7 +631,7 @@ void crystal_state::machine_reset() m_Timer[i]->adjust(attotime::never); } - vr0_snd_set_areas(machine().device("vrender"), m_textureram, m_frameram); + dynamic_cast(machine().device("vrender"))->set_areas(m_textureram, m_frameram); #ifdef IDLE_LOOP_SPEEDUP m_FlipCntRead = 0; #endif @@ -864,7 +864,7 @@ static MACHINE_CONFIG_START( crystal, crystal_state ) MCFG_SPEAKER_STANDARD_STEREO("lspeaker", "rspeaker") - MCFG_SOUND_ADD("vrender", VRENDER0, 0) + MCFG_SOUND_VRENDER0_ADD("vrender", 0) MCFG_SOUND_CONFIG(vr0_config) MCFG_SOUND_ROUTE(0, "lspeaker", 1.0) MCFG_SOUND_ROUTE(1, "rspeaker", 1.0)