trunk/src/emu/sound/vrender0.c
| r19944 | r19945 | |
| 12 | 12 | interrupts |
| 13 | 13 | *************/ |
| 14 | 14 | |
| 15 | | struct vr0_state |
| 16 | | { |
| 17 | | UINT32 *TexBase; |
| 18 | | UINT32 *FBBase; |
| 19 | | UINT32 SOUNDREGS[0x10000/4]; |
| 20 | | vr0_interface Intf; |
| 21 | | sound_stream * stream; |
| 22 | | }; |
| 23 | | |
| 24 | | INLINE 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 | | |
| 31 | | static void VR0_RenderAudio(vr0_state *VR0, int nsamples,stream_sample_t *l,stream_sample_t *r); |
| 32 | | |
| 33 | | static STREAM_UPDATE( VR0_Update ) |
| 34 | | { |
| 35 | | vr0_state *VR0 = (vr0_state *)param; |
| 36 | | VR0_RenderAudio(VR0, samples,outputs[0],outputs[1]); |
| 37 | | } |
| 38 | | |
| 39 | 15 | //Correct table thanks to Evoga |
| 40 | 16 | //they left a ulaw<->linear conversion tool inside the roms |
| 41 | 17 | static const unsigned short ULawTo16[]= |
| r19944 | r19945 | |
| 75 | 51 | }; |
| 76 | 52 | |
| 77 | 53 | |
| 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) |
| 84 | 60 | |
| 85 | 61 | /* |
| 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) |
| 88 | 64 | |
| 89 | 65 | #define CURSADDR(chan) GETSOUNDREG32(chan,0x00) |
| 90 | 66 | #define DSADDR(chan) GETSOUNDREG16(chan,0x08) |
| r19944 | r19945 | |
| 92 | 68 | #define LOOPEND(chan) (GETSOUNDREG32(chan,0x10)&0x3fffff) |
| 93 | 69 | #define ENVVOL(chan) (GETSOUNDREG32(chan,0x04)&0xffffff) |
| 94 | 70 | */ |
| 95 | | void vr0_snd_set_areas(device_t *device,UINT32 *texture,UINT32 *frame) |
| 71 | |
| 72 | |
| 73 | |
| 74 | //************************************************************************** |
| 75 | // LIVE DEVICE |
| 76 | //************************************************************************** |
| 77 | |
| 78 | const device_type VRENDER0 = &device_creator<vrender0_device>; |
| 79 | |
| 80 | //------------------------------------------------- |
| 81 | // vrender0_device - constructor |
| 82 | //------------------------------------------------- |
| 83 | |
| 84 | vrender0_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) |
| 96 | 90 | { |
| 97 | | vr0_state *VR0 = get_safe_token(device); |
| 98 | | VR0->TexBase=texture; |
| 99 | | VR0->FBBase=frame; |
| 100 | 91 | } |
| 101 | 92 | |
| 102 | | static DEVICE_START( vrender0 ) |
| 93 | |
| 94 | //------------------------------------------------- |
| 95 | // device_start - device-specific startup |
| 96 | //------------------------------------------------- |
| 97 | |
| 98 | void vrender0_device::device_start() |
| 103 | 99 | { |
| 104 | | const vr0_interface *intf; |
| 105 | | vr0_state *VR0 = get_safe_token(device); |
| 100 | const vr0_interface *intf = (const vr0_interface *)static_config(); |
| 106 | 101 | |
| 107 | | intf = (const vr0_interface *)device->static_config(); |
| 102 | memcpy(&(m_Intf),intf,sizeof(vr0_interface)); |
| 103 | memset(m_SOUNDREGS,0,sizeof(m_SOUNDREGS)); |
| 108 | 104 | |
| 109 | | memcpy(&(VR0->Intf),intf,sizeof(vr0_interface)); |
| 110 | | memset(VR0->SOUNDREGS,0,sizeof(VR0->SOUNDREGS)); |
| 105 | m_stream = stream_alloc(0, 2, 44100); |
| 111 | 106 | |
| 112 | | VR0->stream = device->machine().sound().stream_alloc(*device, 0, 2, 44100, VR0, VR0_Update); |
| 107 | save_item(NAME(m_SOUNDREGS)); |
| 108 | } |
| 113 | 109 | |
| 114 | | device->save_item(NAME(VR0->SOUNDREGS)); |
| 110 | |
| 111 | //------------------------------------------------- |
| 112 | // sound_stream_update - handle update requests |
| 113 | // for our sound stream |
| 114 | //------------------------------------------------- |
| 115 | |
| 116 | void 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]); |
| 115 | 119 | } |
| 116 | 120 | |
| 117 | | WRITE32_DEVICE_HANDLER(vr0_snd_write) |
| 121 | |
| 122 | |
| 123 | READ32_MEMBER(vrender0_device::vr0_snd_read) |
| 118 | 124 | { |
| 119 | | vr0_state *VR0 = get_safe_token(device); |
| 125 | return m_SOUNDREGS[offset]; |
| 126 | } |
| 127 | |
| 128 | |
| 129 | WRITE32_MEMBER(vrender0_device::vr0_snd_write) |
| 130 | { |
| 120 | 131 | if(offset==0x404/4) |
| 121 | 132 | { |
| 122 | 133 | data&=0xffff; |
| r19944 | r19945 | |
| 134 | 145 | } |
| 135 | 146 | else |
| 136 | 147 | { |
| 137 | | COMBINE_DATA(&VR0->SOUNDREGS[offset]); |
| 148 | COMBINE_DATA(&m_SOUNDREGS[offset]); |
| 138 | 149 | } |
| 139 | 150 | } |
| 140 | 151 | |
| 141 | 152 | |
| 142 | | READ32_DEVICE_HANDLER(vr0_snd_read) |
| 153 | void vrender0_device::set_areas(UINT32 *texture, UINT32 *frame) |
| 143 | 154 | { |
| 144 | | vr0_state *VR0 = get_safe_token(device); |
| 145 | | return VR0->SOUNDREGS[offset]; |
| 155 | m_TexBase=texture; |
| 156 | m_FBBase=frame; |
| 146 | 157 | } |
| 147 | 158 | |
| 148 | | static void VR0_RenderAudio(vr0_state *VR0, int nsamples,stream_sample_t *l,stream_sample_t *r) |
| 159 | |
| 160 | void vrender0_device::VR0_RenderAudio(int nsamples, stream_sample_t *l, stream_sample_t *r) |
| 149 | 161 | { |
| 150 | 162 | INT16 *SAMPLES; |
| 151 | 163 | UINT32 st=STATUS; |
| 152 | 164 | 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; |
| 157 | 169 | int div; |
| 158 | 170 | int s; |
| 159 | 171 | |
| 160 | 172 | |
| 161 | 173 | if(CT1&0x20) |
| 162 | | SAMPLES=(INT16 *)VR0->TexBase; |
| 174 | SAMPLES=(INT16 *)m_TexBase; |
| 163 | 175 | else |
| 164 | | SAMPLES=(INT16 *)VR0->FBBase; |
| 176 | SAMPLES=(INT16 *)m_FBBase; |
| 165 | 177 | |
| 166 | 178 | if(CLK) |
| 167 | 179 | div=((30<<16)|0x8000)/(CLK+1); |
| r19944 | r19945 | |
| 177 | 189 | signed int sample; |
| 178 | 190 | UINT32 cur=CURSADDR(i); |
| 179 | 191 | 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; |
| 183 | 195 | |
| 184 | 196 | INT32 DSADD=(DSADDR(i)*div)>>16; |
| 185 | 197 | |
| r19944 | r19945 | |
| 236 | 248 | r[s]=rsample; |
| 237 | 249 | } |
| 238 | 250 | } |
| 239 | | |
| 240 | | |
| 241 | | const device_type VRENDER0 = &device_creator<vrender0_device>; |
| 242 | | |
| 243 | | vrender0_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 | | |
| 256 | | void vrender0_device::device_config_complete() |
| 257 | | { |
| 258 | | } |
| 259 | | |
| 260 | | //------------------------------------------------- |
| 261 | | // device_start - device-specific startup |
| 262 | | //------------------------------------------------- |
| 263 | | |
| 264 | | void vrender0_device::device_start() |
| 265 | | { |
| 266 | | DEVICE_START_NAME( vrender0 )(this); |
| 267 | | } |
| 268 | | |
| 269 | | //------------------------------------------------- |
| 270 | | // sound_stream_update - handle a stream update |
| 271 | | //------------------------------------------------- |
| 272 | | |
| 273 | | void 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
| r19944 | r19945 | |
| 3 | 3 | #ifndef __VRENDER0_H__ |
| 4 | 4 | #define __VRENDER0_H__ |
| 5 | 5 | |
| 6 | | #include "devlegcy.h" |
| 7 | 6 | |
| 7 | //************************************************************************** |
| 8 | // INTERFACE CONFIGURATION MACROS |
| 9 | //************************************************************************** |
| 8 | 10 | |
| 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 | |
| 9 | 26 | struct vr0_interface |
| 10 | 27 | { |
| 11 | 28 | UINT32 RegBase; |
| 12 | 29 | }; |
| 13 | 30 | |
| 14 | | void vr0_snd_set_areas(device_t *device,UINT32 *texture,UINT32 *frame); |
| 31 | void vr0_snd_set_areas(device_t *device, UINT32 *texture, UINT32 *frame); |
| 15 | 32 | |
| 16 | | DECLARE_READ32_DEVICE_HANDLER( vr0_snd_read ); |
| 17 | | DECLARE_WRITE32_DEVICE_HANDLER( vr0_snd_write ); |
| 18 | | |
| 19 | 33 | class vrender0_device : public device_t, |
| 20 | | public device_sound_interface |
| 34 | public device_sound_interface |
| 21 | 35 | { |
| 22 | 36 | public: |
| 23 | 37 | vrender0_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock); |
| 24 | | ~vrender0_device() { global_free(m_token); } |
| 38 | ~vrender0_device() { } |
| 25 | 39 | |
| 26 | | // access to legacy token |
| 27 | | void *token() const { assert(m_token != NULL); return m_token; } |
| 28 | 40 | protected: |
| 29 | 41 | // device-level overrides |
| 30 | | virtual void device_config_complete(); |
| 31 | 42 | virtual void device_start(); |
| 32 | 43 | |
| 33 | 44 | // sound stream update overrides |
| 34 | 45 | virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples); |
| 46 | |
| 47 | public: |
| 48 | DECLARE_READ32_MEMBER( vr0_snd_read ); |
| 49 | DECLARE_WRITE32_MEMBER( vr0_snd_write ); |
| 50 | |
| 51 | void set_areas(UINT32 *texture, UINT32 *frame); |
| 52 | |
| 35 | 53 | private: |
| 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); |
| 38 | 61 | }; |
| 39 | 62 | |
| 40 | 63 | extern const device_type VRENDER0; |