Previous 199869 Revisions Next

r19945 Sunday 30th December, 2012 at 15:56:01 UTC by Andrew Gardner
Modernize vrender0 (crystal system) sound device. [Andrew Gardner]
[src/emu/sound]vrender0.c vrender0.h
[src/mame/drivers]crystal.c

trunk/src/emu/sound/vrender0.c
r19944r19945
1212interrupts
1313*************/
1414
15struct vr0_state
16{
17   UINT32 *TexBase;
18   UINT32 *FBBase;
19   UINT32 SOUNDREGS[0x10000/4];
20   vr0_interface Intf;
21   sound_stream * stream;
22};
23
24INLINE vr0_state *get_safe_token(device_t *device)
25{
26   assert(device != NULL);
27   assert(device->type() == VRENDER0);
28   return (vr0_state *)downcast<vrender0_device *>(device)->token();
29}
30
31static void VR0_RenderAudio(vr0_state *VR0, int nsamples,stream_sample_t *l,stream_sample_t *r);
32
33static STREAM_UPDATE( VR0_Update )
34{
35   vr0_state *VR0 = (vr0_state *)param;
36   VR0_RenderAudio(VR0, samples,outputs[0],outputs[1]);
37}
38
3915//Correct table thanks to Evoga
4016//they left a ulaw<->linear conversion tool inside the roms
4117static const unsigned short ULawTo16[]=
r19944r19945
7551};
7652
7753
78#define STATUS         VR0->SOUNDREGS[0x404/4]
79#define CURSADDR(chan)   (VR0->SOUNDREGS[(0x20/4)*chan+0x00])
80#define DSADDR(chan)   ((VR0->SOUNDREGS[(0x20/4)*chan+0x08/4]>>0)&0xffff)
81#define LOOPBEGIN(chan)   (VR0->SOUNDREGS[(0x20/4)*chan+0x0c/4]&0x3fffff)
82#define LOOPEND(chan)   (VR0->SOUNDREGS[(0x20/4)*chan+0x10/4]&0x3fffff)
83#define ENVVOL(chan)   (VR0->SOUNDREGS[(0x20/4)*chan+0x04/4]&0xffffff)
54#define STATUS         m_SOUNDREGS[0x404/4]
55#define CURSADDR(chan)   (m_SOUNDREGS[(0x20/4)*chan+0x00])
56#define DSADDR(chan)   ((m_SOUNDREGS[(0x20/4)*chan+0x08/4]>>0)&0xffff)
57#define LOOPBEGIN(chan)   (m_SOUNDREGS[(0x20/4)*chan+0x0c/4]&0x3fffff)
58#define LOOPEND(chan)   (m_SOUNDREGS[(0x20/4)*chan+0x10/4]&0x3fffff)
59#define ENVVOL(chan)   (m_SOUNDREGS[(0x20/4)*chan+0x04/4]&0xffffff)
8460
8561/*
86#define GETSOUNDREG16(Chan,Offs) space.read_word(VR0->Intf.reg_base+0x20*Chan+Offs)
87#define GETSOUNDREG32(Chan,Offs) space.read_dword(VR0->Intf.reg_base+0x20*Chan+Offs)
62#define GETSOUNDREG16(Chan,Offs) space.read_word(m_Intf.reg_base+0x20*Chan+Offs)
63#define GETSOUNDREG32(Chan,Offs) space.read_dword(m_Intf.reg_base+0x20*Chan+Offs)
8864
8965#define CURSADDR(chan)  GETSOUNDREG32(chan,0x00)
9066#define DSADDR(chan)    GETSOUNDREG16(chan,0x08)
r19944r19945
9268#define LOOPEND(chan)   (GETSOUNDREG32(chan,0x10)&0x3fffff)
9369#define ENVVOL(chan)    (GETSOUNDREG32(chan,0x04)&0xffffff)
9470*/
95void vr0_snd_set_areas(device_t *device,UINT32 *texture,UINT32 *frame)
71
72
73
74//**************************************************************************
75//  LIVE DEVICE
76//**************************************************************************
77
78const device_type VRENDER0 = &device_creator<vrender0_device>;
79
80//-------------------------------------------------
81//  vrender0_device - constructor
82//-------------------------------------------------
83
84vrender0_device::vrender0_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
85   : device_t(mconfig, VRENDER0, "VRender0", tag, owner, clock),
86     device_sound_interface(mconfig, *this),
87     m_TexBase(NULL),
88     m_FBBase(NULL),
89     m_stream(NULL)
9690{
97   vr0_state *VR0 = get_safe_token(device);
98   VR0->TexBase=texture;
99   VR0->FBBase=frame;
10091}
10192
102static DEVICE_START( vrender0 )
93
94//-------------------------------------------------
95//  device_start - device-specific startup
96//-------------------------------------------------
97
98void vrender0_device::device_start()
10399{
104   const vr0_interface *intf;
105   vr0_state *VR0 = get_safe_token(device);
100   const vr0_interface *intf = (const vr0_interface *)static_config();
106101
107   intf = (const vr0_interface *)device->static_config();
102   memcpy(&(m_Intf),intf,sizeof(vr0_interface));
103   memset(m_SOUNDREGS,0,sizeof(m_SOUNDREGS));
108104
109   memcpy(&(VR0->Intf),intf,sizeof(vr0_interface));
110   memset(VR0->SOUNDREGS,0,sizeof(VR0->SOUNDREGS));
105   m_stream = stream_alloc(0, 2, 44100);
111106
112   VR0->stream = device->machine().sound().stream_alloc(*device, 0, 2, 44100, VR0, VR0_Update);
107   save_item(NAME(m_SOUNDREGS));
108}
113109
114   device->save_item(NAME(VR0->SOUNDREGS));
110
111//-------------------------------------------------
112//  sound_stream_update - handle update requests
113//  for our sound stream
114//-------------------------------------------------
115
116void vrender0_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples)
117{
118   VR0_RenderAudio(samples, outputs[0], outputs[1]);
115119}
116120
117WRITE32_DEVICE_HANDLER(vr0_snd_write)
121
122
123READ32_MEMBER(vrender0_device::vr0_snd_read)
118124{
119   vr0_state *VR0 = get_safe_token(device);
125   return m_SOUNDREGS[offset];
126}
127
128
129WRITE32_MEMBER(vrender0_device::vr0_snd_write)
130{
120131   if(offset==0x404/4)
121132   {
122133      data&=0xffff;
r19944r19945
134145   }
135146   else
136147   {
137      COMBINE_DATA(&VR0->SOUNDREGS[offset]);
148      COMBINE_DATA(&m_SOUNDREGS[offset]);
138149   }
139150}
140151
141152
142READ32_DEVICE_HANDLER(vr0_snd_read)
153void vrender0_device::set_areas(UINT32 *texture, UINT32 *frame)
143154{
144   vr0_state *VR0 = get_safe_token(device);
145   return VR0->SOUNDREGS[offset];
155   m_TexBase=texture;
156   m_FBBase=frame;
146157}
147158
148static void VR0_RenderAudio(vr0_state *VR0, int nsamples,stream_sample_t *l,stream_sample_t *r)
159
160void vrender0_device::VR0_RenderAudio(int nsamples, stream_sample_t *l, stream_sample_t *r)
149161{
150162   INT16 *SAMPLES;
151163   UINT32 st=STATUS;
152164   signed int lsample=0,rsample=0;
153   UINT32 CLK=(VR0->SOUNDREGS[0x600/4]>>0)&0xff;
154   UINT32 NCH=(VR0->SOUNDREGS[0x600/4]>>8)&0xff;
155   UINT32 CT1=(VR0->SOUNDREGS[0x600/4]>>16)&0xff;
156   UINT32 CT2=(VR0->SOUNDREGS[0x600/4]>>24)&0xff;
165   UINT32 CLK=(m_SOUNDREGS[0x600/4]>>0)&0xff;
166   UINT32 NCH=(m_SOUNDREGS[0x600/4]>>8)&0xff;
167   UINT32 CT1=(m_SOUNDREGS[0x600/4]>>16)&0xff;
168   UINT32 CT2=(m_SOUNDREGS[0x600/4]>>24)&0xff;
157169   int div;
158170   int s;
159171
160172
161173   if(CT1&0x20)
162      SAMPLES=(INT16 *)VR0->TexBase;
174      SAMPLES=(INT16 *)m_TexBase;
163175   else
164      SAMPLES=(INT16 *)VR0->FBBase;
176      SAMPLES=(INT16 *)m_FBBase;
165177
166178   if(CLK)
167179      div=((30<<16)|0x8000)/(CLK+1);
r19944r19945
177189         signed int sample;
178190         UINT32 cur=CURSADDR(i);
179191         UINT32 a=LOOPBEGIN(i)+(cur>>10);
180         UINT8 Mode=VR0->SOUNDREGS[(0x20/4)*i+0x8/4]>>24;
181         signed int LVOL=VR0->SOUNDREGS[(0x20/4)*i+0xc/4]>>24;
182         signed int RVOL=VR0->SOUNDREGS[(0x20/4)*i+0x10/4]>>24;
192         UINT8 Mode=m_SOUNDREGS[(0x20/4)*i+0x8/4]>>24;
193         signed int LVOL=m_SOUNDREGS[(0x20/4)*i+0xc/4]>>24;
194         signed int RVOL=m_SOUNDREGS[(0x20/4)*i+0x10/4]>>24;
183195
184196         INT32 DSADD=(DSADDR(i)*div)>>16;
185197
r19944r19945
236248      r[s]=rsample;
237249   }
238250}
239
240
241const device_type VRENDER0 = &device_creator<vrender0_device>;
242
243vrender0_device::vrender0_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
244   : device_t(mconfig, VRENDER0, "VRender0", tag, owner, clock),
245     device_sound_interface(mconfig, *this)
246{
247   m_token = global_alloc_clear(vr0_state);
248}
249
250//-------------------------------------------------
251//  device_config_complete - perform any
252//  operations now that the configuration is
253//  complete
254//-------------------------------------------------
255
256void vrender0_device::device_config_complete()
257{
258}
259
260//-------------------------------------------------
261//  device_start - device-specific startup
262//-------------------------------------------------
263
264void vrender0_device::device_start()
265{
266   DEVICE_START_NAME( vrender0 )(this);
267}
268
269//-------------------------------------------------
270//  sound_stream_update - handle a stream update
271//-------------------------------------------------
272
273void vrender0_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples)
274{
275   // should never get here
276   fatalerror("sound_stream_update called; not applicable to legacy sound devices\n");
277}
278
279
trunk/src/emu/sound/vrender0.h
r19944r19945
33#ifndef __VRENDER0_H__
44#define __VRENDER0_H__
55
6#include "devlegcy.h"
76
7//**************************************************************************
8//  INTERFACE CONFIGURATION MACROS
9//**************************************************************************
810
11#define MCFG_SOUND_VRENDER0_ADD(_tag, _clock) \
12   MCFG_DEVICE_ADD(_tag, VRENDER0, _clock) \
13
14#define MCFG_SOUND_VRENDER0_REPLACE(_tag, _clock) \
15   MCFG_DEVICE_REPLACE(_tag, VRENDER0, _clock) \
16
17
18
19//**************************************************************************
20//  TYPE DEFINITIONS
21//**************************************************************************
22
23
24// ======================> vrender0_device
25
926struct vr0_interface
1027{
1128   UINT32 RegBase;
1229};
1330
14void vr0_snd_set_areas(device_t *device,UINT32 *texture,UINT32 *frame);
31void vr0_snd_set_areas(device_t *device, UINT32 *texture, UINT32 *frame);
1532
16DECLARE_READ32_DEVICE_HANDLER( vr0_snd_read );
17DECLARE_WRITE32_DEVICE_HANDLER( vr0_snd_write );
18
1933class vrender0_device : public device_t,
20                                  public device_sound_interface
34                  public device_sound_interface
2135{
2236public:
2337   vrender0_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
24   ~vrender0_device() { global_free(m_token); }
38   ~vrender0_device() { }
2539
26   // access to legacy token
27   void *token() const { assert(m_token != NULL); return m_token; }
2840protected:
2941   // device-level overrides
30   virtual void device_config_complete();
3142   virtual void device_start();
3243
3344   // sound stream update overrides
3445   virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples);
46
47public:
48   DECLARE_READ32_MEMBER( vr0_snd_read );
49   DECLARE_WRITE32_MEMBER( vr0_snd_write );
50
51   void set_areas(UINT32 *texture, UINT32 *frame);
52
3553private:
36   // internal state
37   void *m_token;
54   UINT32 *m_TexBase;
55   UINT32 *m_FBBase;
56   UINT32 m_SOUNDREGS[0x10000/4];
57   sound_stream *m_stream;
58   vr0_interface m_Intf;
59
60   void VR0_RenderAudio(int nsamples, stream_sample_t *l, stream_sample_t *r);
3861};
3962
4063extern const device_type VRENDER0;
trunk/src/mame/drivers/crystal.c
r19944r19945
510510   AM_RANGE(0x03000000, 0x0300ffff) AM_RAM AM_SHARE("vidregs")
511511   AM_RANGE(0x03800000, 0x03ffffff) AM_RAM AM_SHARE("textureram")
512512   AM_RANGE(0x04000000, 0x047fffff) AM_RAM AM_SHARE("frameram")
513   AM_RANGE(0x04800000, 0x04800fff) AM_DEVREADWRITE_LEGACY("vrender", vr0_snd_read, vr0_snd_write)
513   AM_RANGE(0x04800000, 0x04800fff) AM_DEVREADWRITE("vrender", vrender0_device, vr0_snd_read, vr0_snd_write)
514514
515515   AM_RANGE(0x05000000, 0x05000003) AM_READWRITE(FlashCmd_r, FlashCmd_w)
516516   AM_RANGE(0x05000000, 0x05ffffff) AM_ROMBANK("bank1")
r19944r19945
631631      m_Timer[i]->adjust(attotime::never);
632632   }
633633
634   vr0_snd_set_areas(machine().device("vrender"), m_textureram, m_frameram);
634   dynamic_cast<vrender0_device*>(machine().device("vrender"))->set_areas(m_textureram, m_frameram);
635635#ifdef IDLE_LOOP_SPEEDUP
636636   m_FlipCntRead = 0;
637637#endif
r19944r19945
864864
865865   MCFG_SPEAKER_STANDARD_STEREO("lspeaker", "rspeaker")
866866
867   MCFG_SOUND_ADD("vrender", VRENDER0, 0)
867   MCFG_SOUND_VRENDER0_ADD("vrender", 0)
868868   MCFG_SOUND_CONFIG(vr0_config)
869869   MCFG_SOUND_ROUTE(0, "lspeaker", 1.0)
870870   MCFG_SOUND_ROUTE(1, "rspeaker", 1.0)

Previous 199869 Revisions Next


© 1997-2024 The MAME Team