trunk/src/emu/sound/rf5c68.c
| r21204 | r21205 | |
| 6 | 6 | #include "rf5c68.h" |
| 7 | 7 | |
| 8 | 8 | |
| 9 | | #define NUM_CHANNELS (8) |
| 9 | // device type definition |
| 10 | const device_type RF5C68 = &device_creator<rf5c68_device>; |
| 10 | 11 | |
| 11 | 12 | |
| 12 | | struct pcm_channel |
| 13 | | { |
| 14 | | UINT8 enable; |
| 15 | | UINT8 env; |
| 16 | | UINT8 pan; |
| 17 | | UINT8 start; |
| 18 | | UINT32 addr; |
| 19 | | UINT16 step; |
| 20 | | UINT16 loopst; |
| 21 | | }; |
| 13 | //************************************************************************** |
| 14 | // LIVE DEVICE |
| 15 | //************************************************************************** |
| 22 | 16 | |
| 17 | //------------------------------------------------- |
| 18 | // rf5c68_device - constructor |
| 19 | //------------------------------------------------- |
| 23 | 20 | |
| 24 | | struct rf5c68_state |
| 21 | rf5c68_device::rf5c68_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock) |
| 22 | : device_t(mconfig, RF5C68, "RF5C68", tag, owner, clock), |
| 23 | device_sound_interface(mconfig, *this), |
| 24 | m_stream(NULL), |
| 25 | m_cbank(0), |
| 26 | m_wbank(0), |
| 27 | m_enable(0), |
| 28 | m_sample_callback(NULL) |
| 25 | 29 | { |
| 26 | | sound_stream * stream; |
| 27 | | pcm_channel chan[NUM_CHANNELS]; |
| 28 | | UINT8 cbank; |
| 29 | | UINT8 wbank; |
| 30 | | UINT8 enable; |
| 31 | | UINT8 data[0x10000]; |
| 32 | | void (*sample_callback)(device_t* device,int channel); |
| 33 | | device_t* device; |
| 34 | | }; |
| 30 | memset(m_data, 0, sizeof(UINT8)*0x10000); |
| 31 | } |
| 35 | 32 | |
| 36 | 33 | |
| 37 | | INLINE rf5c68_state *get_safe_token(device_t *device) |
| 34 | //------------------------------------------------- |
| 35 | // device_start - device-specific startup |
| 36 | //------------------------------------------------- |
| 37 | |
| 38 | void rf5c68_device::device_start() |
| 38 | 39 | { |
| 39 | | assert(device != NULL); |
| 40 | | assert(device->type() == RF5C68); |
| 41 | | return (rf5c68_state *)downcast<rf5c68_device *>(device)->token(); |
| 40 | const rf5c68_interface* intf = (const rf5c68_interface*)static_config(); |
| 41 | |
| 42 | /* allocate memory for the chip */ |
| 43 | memset(m_data, 0xff, sizeof(m_data)); |
| 44 | |
| 45 | /* allocate the stream */ |
| 46 | m_stream = stream_alloc(0, 2, clock() / 384); |
| 47 | |
| 48 | /* set up callback */ |
| 49 | if(intf != NULL) |
| 50 | m_sample_callback = intf->sample_end_callback; |
| 51 | else |
| 52 | m_sample_callback = NULL; |
| 42 | 53 | } |
| 43 | 54 | |
| 44 | 55 | |
| 45 | | /************************************************/ |
| 46 | | /* RF5C68 stream update */ |
| 47 | | /************************************************/ |
| 56 | //------------------------------------------------- |
| 57 | // sound_stream_update - handle a stream update |
| 58 | //------------------------------------------------- |
| 48 | 59 | |
| 49 | | static STREAM_UPDATE( rf5c68_update ) |
| 60 | void rf5c68_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) |
| 50 | 61 | { |
| 51 | | rf5c68_state *chip = (rf5c68_state *)param; |
| 52 | 62 | stream_sample_t *left = outputs[0]; |
| 53 | 63 | stream_sample_t *right = outputs[1]; |
| 54 | 64 | int i, j; |
| r21204 | r21205 | |
| 58 | 68 | memset(right, 0, samples * sizeof(*right)); |
| 59 | 69 | |
| 60 | 70 | /* bail if not enabled */ |
| 61 | | if (!chip->enable) |
| 71 | if (!m_enable) |
| 62 | 72 | return; |
| 63 | 73 | |
| 64 | 74 | /* loop over channels */ |
| 65 | | for (i = 0; i < NUM_CHANNELS; i++) |
| 75 | for (i = 0; i < RF5C68_NUM_CHANNELS; i++) |
| 66 | 76 | { |
| 67 | | pcm_channel *chan = &chip->chan[i]; |
| 77 | rf5c68_pcm_channel *chan = &m_chan[i]; |
| 68 | 78 | |
| 69 | 79 | /* if this channel is active, accumulate samples */ |
| 70 | 80 | if (chan->enable) |
| r21204 | r21205 | |
| 78 | 88 | int sample; |
| 79 | 89 | |
| 80 | 90 | /* trigger sample callback */ |
| 81 | | if(chip->sample_callback) |
| 91 | if(m_sample_callback) |
| 82 | 92 | { |
| 83 | 93 | if(((chan->addr >> 11) & 0xfff) == 0xfff) |
| 84 | | chip->sample_callback(chip->device,((chan->addr >> 11)/0x2000)); |
| 94 | m_sample_callback(this, ((chan->addr >> 11)/0x2000)); |
| 85 | 95 | } |
| 86 | 96 | |
| 87 | 97 | /* fetch the sample and handle looping */ |
| 88 | | sample = chip->data[(chan->addr >> 11) & 0xffff]; |
| 98 | sample = m_data[(chan->addr >> 11) & 0xffff]; |
| 89 | 99 | if (sample == 0xff) |
| 90 | 100 | { |
| 91 | 101 | chan->addr = chan->loopst << 11; |
| 92 | | sample = chip->data[(chan->addr >> 11) & 0xffff]; |
| 102 | sample = m_data[(chan->addr >> 11) & 0xffff]; |
| 93 | 103 | |
| 94 | 104 | /* if we loop to a loop point, we're effectively dead */ |
| 95 | 105 | if (sample == 0xff) |
| r21204 | r21205 | |
| 131 | 141 | } |
| 132 | 142 | |
| 133 | 143 | |
| 134 | | /************************************************/ |
| 135 | | /* RF5C68 start */ |
| 136 | | /************************************************/ |
| 144 | //------------------------------------------------- |
| 145 | // RF5C68 write register |
| 146 | //------------------------------------------------- |
| 137 | 147 | |
| 138 | | static DEVICE_START( rf5c68 ) |
| 148 | READ8_MEMBER( rf5c68_device::rf5c68_r ) |
| 139 | 149 | { |
| 140 | | const rf5c68_interface* intf = (const rf5c68_interface*)device->static_config(); |
| 141 | | |
| 142 | | /* allocate memory for the chip */ |
| 143 | | rf5c68_state *chip = get_safe_token(device); |
| 144 | | memset(chip->data, 0xff, sizeof(chip->data)); |
| 145 | | |
| 146 | | /* allocate the stream */ |
| 147 | | chip->stream = device->machine().sound().stream_alloc(*device, 0, 2, device->clock() / 384, chip, rf5c68_update); |
| 148 | | |
| 149 | | chip->device = device; |
| 150 | | |
| 151 | | /* set up callback */ |
| 152 | | if(intf != NULL) |
| 153 | | chip->sample_callback = intf->sample_end_callback; |
| 154 | | else |
| 155 | | chip->sample_callback = NULL; |
| 156 | | } |
| 157 | | |
| 158 | | |
| 159 | | /************************************************/ |
| 160 | | /* RF5C68 write register */ |
| 161 | | /************************************************/ |
| 162 | | |
| 163 | | READ8_DEVICE_HANDLER( rf5c68_r ) |
| 164 | | { |
| 165 | | rf5c68_state *chip = get_safe_token(device); |
| 166 | 150 | UINT8 shift; |
| 167 | 151 | |
| 168 | | chip->stream->update(); |
| 152 | m_stream->update(); |
| 169 | 153 | shift = (offset & 1) ? 11 + 8 : 11; |
| 170 | 154 | |
| 171 | | // printf("%08x\n",(chip->chan[(offset & 0x0e) >> 1].addr)); |
| 155 | // printf("%08x\n",(m_chan[(offset & 0x0e) >> 1].addr)); |
| 172 | 156 | |
| 173 | | return (chip->chan[(offset & 0x0e) >> 1].addr) >> (shift); |
| 157 | return (m_chan[(offset & 0x0e) >> 1].addr) >> (shift); |
| 174 | 158 | } |
| 175 | 159 | |
| 176 | | WRITE8_DEVICE_HANDLER( rf5c68_w ) |
| 160 | WRITE8_MEMBER( rf5c68_device::rf5c68_w ) |
| 177 | 161 | { |
| 178 | | rf5c68_state *chip = get_safe_token(device); |
| 179 | | pcm_channel *chan = &chip->chan[chip->cbank]; |
| 162 | rf5c68_pcm_channel *chan = &m_chan[m_cbank]; |
| 180 | 163 | int i; |
| 181 | 164 | |
| 182 | 165 | /* force the stream to update first */ |
| 183 | | chip->stream->update(); |
| 166 | m_stream->update(); |
| 184 | 167 | |
| 185 | 168 | /* switch off the address */ |
| 186 | 169 | switch (offset) |
| r21204 | r21205 | |
| 216 | 199 | break; |
| 217 | 200 | |
| 218 | 201 | case 0x07: /* control reg */ |
| 219 | | chip->enable = (data >> 7) & 1; |
| 202 | m_enable = (data >> 7) & 1; |
| 220 | 203 | if (data & 0x40) |
| 221 | | chip->cbank = data & 7; |
| 204 | m_cbank = data & 7; |
| 222 | 205 | else |
| 223 | | chip->wbank = data & 15; |
| 206 | m_wbank = data & 15; |
| 224 | 207 | break; |
| 225 | 208 | |
| 226 | 209 | case 0x08: /* channel on/off reg */ |
| 227 | 210 | for (i = 0; i < 8; i++) |
| 228 | 211 | { |
| 229 | | chip->chan[i].enable = (~data >> i) & 1; |
| 230 | | if (!chip->chan[i].enable) |
| 231 | | chip->chan[i].addr = chip->chan[i].start << (8 + 11); |
| 212 | m_chan[i].enable = (~data >> i) & 1; |
| 213 | if (!m_chan[i].enable) |
| 214 | m_chan[i].addr = m_chan[i].start << (8 + 11); |
| 232 | 215 | } |
| 233 | 216 | break; |
| 234 | 217 | } |
| 235 | 218 | } |
| 236 | 219 | |
| 237 | 220 | |
| 238 | | /************************************************/ |
| 239 | | /* RF5C68 read memory */ |
| 240 | | /************************************************/ |
| 241 | | |
| 242 | | READ8_DEVICE_HANDLER( rf5c68_mem_r ) |
| 243 | | { |
| 244 | | rf5c68_state *chip = get_safe_token(device); |
| 245 | | return chip->data[chip->wbank * 0x1000 + offset]; |
| 246 | | } |
| 247 | | |
| 248 | | |
| 249 | | /************************************************/ |
| 250 | | /* RF5C68 write memory */ |
| 251 | | /************************************************/ |
| 252 | | |
| 253 | | WRITE8_DEVICE_HANDLER( rf5c68_mem_w ) |
| 254 | | { |
| 255 | | rf5c68_state *chip = get_safe_token(device); |
| 256 | | chip->data[chip->wbank * 0x1000 + offset] = data; |
| 257 | | } |
| 258 | | |
| 259 | | const device_type RF5C68 = &device_creator<rf5c68_device>; |
| 260 | | |
| 261 | | rf5c68_device::rf5c68_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock) |
| 262 | | : device_t(mconfig, RF5C68, "RF5C68", tag, owner, clock), |
| 263 | | device_sound_interface(mconfig, *this) |
| 264 | | { |
| 265 | | m_token = global_alloc_clear(rf5c68_state); |
| 266 | | } |
| 267 | | |
| 268 | 221 | //------------------------------------------------- |
| 269 | | // device_config_complete - perform any |
| 270 | | // operations now that the configuration is |
| 271 | | // complete |
| 222 | // RF5C68 read memory |
| 272 | 223 | //------------------------------------------------- |
| 273 | 224 | |
| 274 | | void rf5c68_device::device_config_complete() |
| 225 | READ8_MEMBER( rf5c68_device::rf5c68_mem_r ) |
| 275 | 226 | { |
| 227 | return m_data[m_wbank * 0x1000 + offset]; |
| 276 | 228 | } |
| 277 | 229 | |
| 278 | | //------------------------------------------------- |
| 279 | | // device_start - device-specific startup |
| 280 | | //------------------------------------------------- |
| 281 | 230 | |
| 282 | | void rf5c68_device::device_start() |
| 283 | | { |
| 284 | | DEVICE_START_NAME( rf5c68 )(this); |
| 285 | | } |
| 286 | | |
| 287 | 231 | //------------------------------------------------- |
| 288 | | // sound_stream_update - handle a stream update |
| 232 | // RF5C68 write memory |
| 289 | 233 | //------------------------------------------------- |
| 290 | 234 | |
| 291 | | void rf5c68_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) |
| 235 | WRITE8_MEMBER( rf5c68_device::rf5c68_mem_w ) |
| 292 | 236 | { |
| 293 | | // should never get here |
| 294 | | fatalerror("sound_stream_update called; not applicable to legacy sound devices\n"); |
| 237 | m_data[m_wbank * 0x1000 + offset] = data; |
| 295 | 238 | } |
trunk/src/emu/sound/tms36xx.c
| r21204 | r21205 | |
| 11 | 11 | /* the frequencies are later adjusted by "* clock / FSCALE" */ |
| 12 | 12 | #define FSCALE 1024 |
| 13 | 13 | |
| 14 | | struct tms_state { |
| 15 | | char *subtype; /* subtype name MM6221AA, TMS3615 or TMS3617 */ |
| 16 | | sound_stream * channel; /* returned by stream_create() */ |
| 17 | | |
| 18 | | int samplerate; /* output sample rate */ |
| 19 | | |
| 20 | | int basefreq; /* chip's base frequency */ |
| 21 | | int octave; /* octave select of the TMS3615 */ |
| 22 | | |
| 23 | | int speed; /* speed of the tune */ |
| 24 | | int tune_counter; /* tune counter */ |
| 25 | | int note_counter; /* note counter */ |
| 26 | | |
| 27 | | int voices; /* active voices */ |
| 28 | | int shift; /* shift toggles between 0 and 6 to allow decaying voices */ |
| 29 | | int vol[12]; /* (decaying) volume of harmonics notes */ |
| 30 | | int vol_counter[12];/* volume adjustment counter */ |
| 31 | | int decay[12]; /* volume adjustment rate - dervied from decay */ |
| 32 | | |
| 33 | | int counter[12]; /* tone frequency counter */ |
| 34 | | int frequency[12]; /* tone frequency */ |
| 35 | | int output; /* output signal bits */ |
| 36 | | int enable; /* mask which harmoics */ |
| 37 | | |
| 38 | | int tune_num; /* tune currently playing */ |
| 39 | | int tune_ofs; /* note currently playing */ |
| 40 | | int tune_max; /* end of tune */ |
| 41 | | |
| 42 | | const tms36xx_interface *intf; |
| 43 | | }; |
| 44 | | |
| 45 | 14 | #define C(n) (int)((FSCALE<<(n-1))*1.18921) /* 2^(3/12) */ |
| 46 | 15 | #define Cx(n) (int)((FSCALE<<(n-1))*1.25992) /* 2^(4/12) */ |
| 47 | 16 | #define D(n) (int)((FSCALE<<(n-1))*1.33484) /* 2^(5/12) */ |
| r21204 | r21205 | |
| 299 | 268 | static const int *const tunes[] = {NULL,tune1,tune2,tune3,tune4}; |
| 300 | 269 | |
| 301 | 270 | #define DECAY(voice) \ |
| 302 | | if( tms->vol[voice] > VMIN ) \ |
| 271 | if( m_vol[voice] > VMIN ) \ |
| 303 | 272 | { \ |
| 304 | 273 | /* decay of first voice */ \ |
| 305 | | tms->vol_counter[voice] -= tms->decay[voice]; \ |
| 306 | | while( tms->vol_counter[voice] <= 0 ) \ |
| 274 | m_vol_counter[voice] -= m_decay[voice]; \ |
| 275 | while( m_vol_counter[voice] <= 0 ) \ |
| 307 | 276 | { \ |
| 308 | | tms->vol_counter[voice] += samplerate; \ |
| 309 | | if( tms->vol[voice]-- <= VMIN ) \ |
| 277 | m_vol_counter[voice] += samplerate; \ |
| 278 | if( m_vol[voice]-- <= VMIN ) \ |
| 310 | 279 | { \ |
| 311 | | tms->frequency[voice] = 0; \ |
| 312 | | tms->vol[voice] = VMIN; \ |
| 280 | m_frequency[voice] = 0; \ |
| 281 | m_vol[voice] = VMIN; \ |
| 313 | 282 | break; \ |
| 314 | 283 | } \ |
| 315 | 284 | } \ |
| 316 | 285 | } |
| 317 | 286 | |
| 318 | 287 | #define RESTART(voice) \ |
| 319 | | if( tunes[tms->tune_num][tms->tune_ofs*6+voice] ) \ |
| 288 | if( tunes[m_tune_num][m_tune_ofs*6+voice] ) \ |
| 320 | 289 | { \ |
| 321 | | tms->frequency[tms->shift+voice] = \ |
| 322 | | tunes[tms->tune_num][tms->tune_ofs*6+voice] * \ |
| 323 | | (tms->basefreq << tms->octave) / FSCALE; \ |
| 324 | | tms->vol[tms->shift+voice] = VMAX; \ |
| 290 | m_frequency[m_shift+voice] = \ |
| 291 | tunes[m_tune_num][m_tune_ofs*6+voice] * \ |
| 292 | (m_basefreq << m_octave) / FSCALE; \ |
| 293 | m_vol[m_shift+voice] = VMAX; \ |
| 325 | 294 | } |
| 326 | 295 | |
| 327 | 296 | #define TONE(voice) \ |
| 328 | | if( (tms->enable & (1<<voice)) && tms->frequency[voice] ) \ |
| 297 | if( (m_enable & (1<<voice)) && m_frequency[voice] ) \ |
| 329 | 298 | { \ |
| 330 | 299 | /* first note */ \ |
| 331 | | tms->counter[voice] -= tms->frequency[voice]; \ |
| 332 | | while( tms->counter[voice] <= 0 ) \ |
| 300 | m_counter[voice] -= m_frequency[voice]; \ |
| 301 | while( m_counter[voice] <= 0 ) \ |
| 333 | 302 | { \ |
| 334 | | tms->counter[voice] += samplerate; \ |
| 335 | | tms->output ^= 1 << voice; \ |
| 303 | m_counter[voice] += samplerate; \ |
| 304 | m_output ^= 1 << voice; \ |
| 336 | 305 | } \ |
| 337 | | if (tms->output & tms->enable & (1 << voice)) \ |
| 338 | | sum += tms->vol[voice]; \ |
| 306 | if (m_output & m_enable & (1 << voice)) \ |
| 307 | sum += m_vol[voice]; \ |
| 339 | 308 | } |
| 340 | 309 | |
| 341 | 310 | |
| 342 | | INLINE tms_state *get_safe_token(device_t *device) |
| 311 | |
| 312 | // device type definition |
| 313 | const device_type TMS36XX = &device_creator<tms36xx_device>; |
| 314 | |
| 315 | |
| 316 | //************************************************************************** |
| 317 | // LIVE DEVICE |
| 318 | //************************************************************************** |
| 319 | |
| 320 | //------------------------------------------------- |
| 321 | // tms36xx_device - constructor |
| 322 | //------------------------------------------------- |
| 323 | |
| 324 | tms36xx_device::tms36xx_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock) |
| 325 | : device_t(mconfig, TMS36XX, "TMS36XX", tag, owner, clock), |
| 326 | device_sound_interface(mconfig, *this), |
| 327 | m_subtype(NULL), |
| 328 | m_channel(NULL), |
| 329 | m_samplerate(0), |
| 330 | m_basefreq(0), |
| 331 | m_octave(0), |
| 332 | m_speed(0), |
| 333 | m_tune_counter(0), |
| 334 | m_note_counter(0), |
| 335 | m_voices(0), |
| 336 | m_shift(0), |
| 337 | m_output(0), |
| 338 | m_enable(0), |
| 339 | m_tune_num(0), |
| 340 | m_tune_ofs(0), |
| 341 | m_tune_max(0), |
| 342 | m_intf(NULL) |
| 343 | 343 | { |
| 344 | | assert(device != NULL); |
| 345 | | assert(device->type() == TMS36XX); |
| 346 | | return (tms_state *)downcast<tms36xx_device *>(device)->token(); |
| 344 | memset(m_vol, 0, sizeof(int)*12); |
| 345 | memset(m_vol_counter, 0, sizeof(int)*12); |
| 346 | memset(m_decay, 0, sizeof(int)*12); |
| 347 | memset(m_counter, 0, sizeof(int)*12); |
| 348 | memset(m_frequency, 0, sizeof(int)*12); |
| 347 | 349 | } |
| 348 | 350 | |
| 349 | 351 | |
| 350 | | static STREAM_UPDATE( tms36xx_sound_update ) |
| 352 | //------------------------------------------------- |
| 353 | // device_start - device-specific startup |
| 354 | //------------------------------------------------- |
| 355 | |
| 356 | void tms36xx_device::device_start() |
| 351 | 357 | { |
| 352 | | tms_state *tms = (tms_state *)param; |
| 353 | | int samplerate = tms->samplerate; |
| 358 | int j; |
| 359 | int enable; |
| 360 | |
| 361 | m_intf = (const tms36xx_interface *)static_config(); |
| 362 | |
| 363 | m_channel = stream_alloc(0, 1, clock() * 64); |
| 364 | m_samplerate = clock() * 64; |
| 365 | m_basefreq = clock(); |
| 366 | enable = 0; |
| 367 | for (j = 0; j < 6; j++) |
| 368 | { |
| 369 | if( m_intf->decay[j] > 0 ) |
| 370 | { |
| 371 | m_decay[j+0] = m_decay[j+6] = VMAX / m_intf->decay[j]; |
| 372 | enable |= 0x41 << j; |
| 373 | } |
| 374 | } |
| 375 | m_speed = (m_intf->speed > 0) ? VMAX / m_intf->speed : VMAX; |
| 376 | tms3617_enable(enable); |
| 377 | |
| 378 | LOG(("TMS36xx samplerate %d\n", m_samplerate)); |
| 379 | LOG(("TMS36xx basefreq %d\n", m_basefreq)); |
| 380 | LOG(("TMS36xx decay %d,%d,%d,%d,%d,%d\n", |
| 381 | m_decay[0], m_decay[1], m_decay[2], |
| 382 | m_decay[3], m_decay[4], m_decay[5])); |
| 383 | LOG(("TMS36xx speed %d\n", m_speed)); |
| 384 | } |
| 385 | |
| 386 | |
| 387 | //------------------------------------------------- |
| 388 | // sound_stream_update - handle a stream update |
| 389 | //------------------------------------------------- |
| 390 | |
| 391 | void tms36xx_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) |
| 392 | { |
| 393 | int samplerate = m_samplerate; |
| 354 | 394 | stream_sample_t *buffer = outputs[0]; |
| 355 | 395 | |
| 356 | 396 | /* no tune played? */ |
| 357 | | if( !tunes[tms->tune_num] || tms->voices == 0 ) |
| 397 | if( !tunes[m_tune_num] || m_voices == 0 ) |
| 358 | 398 | { |
| 359 | 399 | while (--samples >= 0) |
| 360 | 400 | buffer[samples] = 0; |
| r21204 | r21205 | |
| 370 | 410 | DECAY( 6) DECAY( 7) DECAY( 8) DECAY( 9) DECAY(10) DECAY(11) |
| 371 | 411 | |
| 372 | 412 | /* musical note timing */ |
| 373 | | tms->tune_counter -= tms->speed; |
| 374 | | if( tms->tune_counter <= 0 ) |
| 413 | m_tune_counter -= m_speed; |
| 414 | if( m_tune_counter <= 0 ) |
| 375 | 415 | { |
| 376 | | int n = (-tms->tune_counter / samplerate) + 1; |
| 377 | | tms->tune_counter += n * samplerate; |
| 416 | int n = (-m_tune_counter / samplerate) + 1; |
| 417 | m_tune_counter += n * samplerate; |
| 378 | 418 | |
| 379 | | if( (tms->note_counter -= n) <= 0 ) |
| 419 | if( (m_note_counter -= n) <= 0 ) |
| 380 | 420 | { |
| 381 | | tms->note_counter += VMAX; |
| 382 | | if (tms->tune_ofs < tms->tune_max) |
| 421 | m_note_counter += VMAX; |
| 422 | if (m_tune_ofs < m_tune_max) |
| 383 | 423 | { |
| 384 | 424 | /* shift to the other 'bank' of voices */ |
| 385 | | tms->shift ^= 6; |
| 425 | m_shift ^= 6; |
| 386 | 426 | /* restart one 'bank' of voices */ |
| 387 | 427 | RESTART(0) RESTART(1) RESTART(2) |
| 388 | 428 | RESTART(3) RESTART(4) RESTART(5) |
| 389 | | tms->tune_ofs++; |
| 429 | m_tune_ofs++; |
| 390 | 430 | } |
| 391 | 431 | } |
| 392 | 432 | } |
| r21204 | r21205 | |
| 395 | 435 | TONE( 0) TONE( 1) TONE( 2) TONE( 3) TONE( 4) TONE( 5) |
| 396 | 436 | TONE( 6) TONE( 7) TONE( 8) TONE( 9) TONE(10) TONE(11) |
| 397 | 437 | |
| 398 | | *buffer++ = sum / tms->voices; |
| 438 | *buffer++ = sum / m_voices; |
| 399 | 439 | } |
| 400 | 440 | } |
| 401 | 441 | |
| 402 | | static void tms36xx_reset_counters(tms_state *tms) |
| 403 | | { |
| 404 | | tms->tune_counter = 0; |
| 405 | | tms->note_counter = 0; |
| 406 | | memset(tms->vol_counter, 0, sizeof(tms->vol_counter)); |
| 407 | | memset(tms->counter, 0, sizeof(tms->counter)); |
| 408 | | } |
| 409 | 442 | |
| 410 | | void mm6221aa_tune_w(device_t *device, int tune) |
| 411 | | { |
| 412 | | tms_state *tms = get_safe_token(device); |
| 443 | //------------------------------------------------- |
| 444 | // MM6221AA interface functions |
| 445 | //------------------------------------------------- |
| 413 | 446 | |
| 447 | void tms36xx_device::mm6221aa_tune_w(int tune) |
| 448 | { |
| 414 | 449 | /* which tune? */ |
| 415 | 450 | tune &= 3; |
| 416 | | if( tune == tms->tune_num ) |
| 451 | if( tune == m_tune_num ) |
| 417 | 452 | return; |
| 418 | 453 | |
| 419 | | LOG(("%s tune:%X\n", tms->subtype, tune)); |
| 454 | LOG(("%s tune:%X\n", m_subtype, tune)); |
| 420 | 455 | |
| 421 | 456 | /* update the stream before changing the tune */ |
| 422 | | tms->channel->update(); |
| 457 | m_channel->update(); |
| 423 | 458 | |
| 424 | | tms->tune_num = tune; |
| 425 | | tms->tune_ofs = 0; |
| 426 | | tms->tune_max = 96; /* fixed for now */ |
| 459 | m_tune_num = tune; |
| 460 | m_tune_ofs = 0; |
| 461 | m_tune_max = 96; /* fixed for now */ |
| 427 | 462 | } |
| 428 | 463 | |
| 429 | | void tms36xx_note_w(device_t *device, int octave, int note) |
| 430 | | { |
| 431 | | tms_state *tms = get_safe_token(device); |
| 432 | 464 | |
| 465 | //------------------------------------------------- |
| 466 | // TMS3615/17 interface functions |
| 467 | //------------------------------------------------- |
| 468 | |
| 469 | void tms36xx_device::tms36xx_note_w(int octave, int note) |
| 470 | { |
| 433 | 471 | octave &= 3; |
| 434 | 472 | note &= 15; |
| 435 | 473 | |
| 436 | 474 | if (note > 12) |
| 437 | 475 | return; |
| 438 | 476 | |
| 439 | | LOG(("%s octave:%X note:%X\n", tms->subtype, octave, note)); |
| 477 | LOG(("%s octave:%X note:%X\n", m_subtype, octave, note)); |
| 440 | 478 | |
| 441 | 479 | /* update the stream before changing the tune */ |
| 442 | | tms->channel->update(); |
| 480 | m_channel->update(); |
| 443 | 481 | |
| 444 | 482 | /* play a single note from 'tune 4', a list of the 13 tones */ |
| 445 | | tms36xx_reset_counters(tms); |
| 446 | | tms->octave = octave; |
| 447 | | tms->tune_num = 4; |
| 448 | | tms->tune_ofs = note; |
| 449 | | tms->tune_max = note + 1; |
| 483 | tms36xx_reset_counters(); |
| 484 | m_octave = octave; |
| 485 | m_tune_num = 4; |
| 486 | m_tune_ofs = note; |
| 487 | m_tune_max = note + 1; |
| 450 | 488 | } |
| 451 | 489 | |
| 452 | | static void tms3617_enable(tms_state *tms, int enable) |
| 490 | |
| 491 | //------------------------------------------------- |
| 492 | // TMS3617 interface functions |
| 493 | //------------------------------------------------- |
| 494 | |
| 495 | void tms36xx_device::tms3617_enable_w(int enable) |
| 453 | 496 | { |
| 497 | tms3617_enable(enable); |
| 498 | } |
| 499 | |
| 500 | |
| 501 | //------------------------------------------------- |
| 502 | // Locals |
| 503 | //------------------------------------------------- |
| 504 | |
| 505 | void tms36xx_device::tms36xx_reset_counters() |
| 506 | { |
| 507 | m_tune_counter = 0; |
| 508 | m_note_counter = 0; |
| 509 | memset(m_vol_counter, 0, sizeof(m_vol_counter)); |
| 510 | memset(m_counter, 0, sizeof(m_counter)); |
| 511 | } |
| 512 | |
| 513 | |
| 514 | void tms36xx_device::tms3617_enable(int enable) |
| 515 | { |
| 454 | 516 | int i, bits = 0; |
| 455 | 517 | |
| 456 | 518 | /* duplicate the 6 voice enable bits */ |
| 457 | 519 | enable = (enable & 0x3f) | ((enable & 0x3f) << 6); |
| 458 | | if (enable == tms->enable) |
| 520 | if (enable == m_enable) |
| 459 | 521 | return; |
| 460 | 522 | |
| 461 | 523 | /* update the stream before changing the tune */ |
| 462 | | tms->channel->update(); |
| 524 | m_channel->update(); |
| 463 | 525 | |
| 464 | | LOG(("%s enable voices", tms->subtype)); |
| 526 | LOG(("%s enable voices", m_subtype)); |
| 465 | 527 | for (i = 0; i < 6; i++) |
| 466 | 528 | { |
| 467 | 529 | if (enable & (1 << i)) |
| r21204 | r21205 | |
| 480 | 542 | } |
| 481 | 543 | } |
| 482 | 544 | /* set the enable mask and number of active voices */ |
| 483 | | tms->enable = enable; |
| 484 | | tms->voices = bits; |
| 545 | m_enable = enable; |
| 546 | m_voices = bits; |
| 485 | 547 | LOG(("%s\n", bits ? "" : " none")); |
| 486 | 548 | } |
| 487 | | |
| 488 | | void tms3617_enable_w(device_t *device, int enable) |
| 489 | | { |
| 490 | | tms_state *tms = get_safe_token(device); |
| 491 | | tms3617_enable(tms, enable); |
| 492 | | } |
| 493 | | |
| 494 | | static DEVICE_START( tms36xx ) |
| 495 | | { |
| 496 | | int j; |
| 497 | | tms_state *tms = get_safe_token(device); |
| 498 | | int enable; |
| 499 | | |
| 500 | | tms->intf = (const tms36xx_interface *)device->static_config(); |
| 501 | | |
| 502 | | tms->channel = device->machine().sound().stream_alloc(*device, 0, 1, device->clock() * 64, tms, tms36xx_sound_update); |
| 503 | | tms->samplerate = device->clock() * 64; |
| 504 | | tms->basefreq = device->clock(); |
| 505 | | enable = 0; |
| 506 | | for (j = 0; j < 6; j++) |
| 507 | | { |
| 508 | | if( tms->intf->decay[j] > 0 ) |
| 509 | | { |
| 510 | | tms->decay[j+0] = tms->decay[j+6] = VMAX / tms->intf->decay[j]; |
| 511 | | enable |= 0x41 << j; |
| 512 | | } |
| 513 | | } |
| 514 | | tms->speed = (tms->intf->speed > 0) ? VMAX / tms->intf->speed : VMAX; |
| 515 | | tms3617_enable(tms,enable); |
| 516 | | |
| 517 | | LOG(("TMS36xx samplerate %d\n", tms->samplerate)); |
| 518 | | LOG(("TMS36xx basefreq %d\n", tms->basefreq)); |
| 519 | | LOG(("TMS36xx decay %d,%d,%d,%d,%d,%d\n", |
| 520 | | tms->decay[0], tms->decay[1], tms->decay[2], |
| 521 | | tms->decay[3], tms->decay[4], tms->decay[5])); |
| 522 | | LOG(("TMS36xx speed %d\n", tms->speed)); |
| 523 | | } |
| 524 | | |
| 525 | | |
| 526 | | const device_type TMS36XX = &device_creator<tms36xx_device>; |
| 527 | | |
| 528 | | tms36xx_device::tms36xx_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock) |
| 529 | | : device_t(mconfig, TMS36XX, "TMS36XX", tag, owner, clock), |
| 530 | | device_sound_interface(mconfig, *this) |
| 531 | | { |
| 532 | | m_token = global_alloc_clear(tms_state); |
| 533 | | } |
| 534 | | |
| 535 | | //------------------------------------------------- |
| 536 | | // device_config_complete - perform any |
| 537 | | // operations now that the configuration is |
| 538 | | // complete |
| 539 | | //------------------------------------------------- |
| 540 | | |
| 541 | | void tms36xx_device::device_config_complete() |
| 542 | | { |
| 543 | | } |
| 544 | | |
| 545 | | //------------------------------------------------- |
| 546 | | // device_start - device-specific startup |
| 547 | | //------------------------------------------------- |
| 548 | | |
| 549 | | void tms36xx_device::device_start() |
| 550 | | { |
| 551 | | DEVICE_START_NAME( tms36xx )(this); |
| 552 | | } |
| 553 | | |
| 554 | | //------------------------------------------------- |
| 555 | | // sound_stream_update - handle a stream update |
| 556 | | //------------------------------------------------- |
| 557 | | |
| 558 | | void tms36xx_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) |
| 559 | | { |
| 560 | | // should never get here |
| 561 | | fatalerror("sound_stream_update called; not applicable to legacy sound devices\n"); |
| 562 | | } |
trunk/src/emu/sound/tms36xx.h
| r21204 | r21205 | |
| 3 | 3 | #ifndef __TMS36XX_H__ |
| 4 | 4 | #define __TMS36XX_H__ |
| 5 | 5 | |
| 6 | | #include "devlegcy.h" |
| 6 | //************************************************************************** |
| 7 | // INTERFACE CONFIGURATION MACROS |
| 8 | //************************************************************************** |
| 7 | 9 | |
| 8 | | /* subtypes */ |
| 9 | | #define MM6221AA 21 /* Phoenix (fixed melodies) */ |
| 10 | | #define TMS3615 15 /* Naughty Boy, Pleiads (13 notes, one output) */ |
| 11 | | #define TMS3617 17 /* Monster Bash (13 notes, six outputs) */ |
| 10 | #define MCFG_TMS36XX_ADD(_tag, _clock) \ |
| 11 | MCFG_DEVICE_ADD(_tag, TMS36XX, _clock) |
| 12 | #define MCFG_TMS36XX_REPLACE(_tag, _clock) \ |
| 13 | MCFG_DEVICE_REPLACE(_tag, TMS36XX, _clock) |
| 12 | 14 | |
| 13 | | /* The interface structure */ |
| 15 | |
| 16 | //************************************************************************** |
| 17 | // TYPE DEFINITIONS |
| 18 | //************************************************************************** |
| 19 | |
| 20 | // subtypes |
| 21 | #define MM6221AA 21 // Phoenix (fixed melodies) |
| 22 | #define TMS3615 15 // Naughty Boy, Pleiads (13 notes, one output) |
| 23 | #define TMS3617 17 // Monster Bash (13 notes, six outputs) |
| 24 | |
| 25 | |
| 26 | // ======================> tms36xx_interface |
| 27 | |
| 14 | 28 | struct tms36xx_interface |
| 15 | 29 | { |
| 16 | 30 | int subtype; |
| 17 | | double decay[6]; /* decay times for the six harmonic notes */ |
| 18 | | double speed; /* tune speed (meaningful for the TMS3615 only) */ |
| 31 | double decay[6]; // decay times for the six harmonic notes |
| 32 | double speed; // tune speed (meaningful for the TMS3615 only) |
| 19 | 33 | }; |
| 20 | 34 | |
| 21 | | /* MM6221AA interface functions */ |
| 22 | | extern void mm6221aa_tune_w(device_t *device, int tune); |
| 23 | 35 | |
| 24 | | /* TMS3615/17 interface functions */ |
| 25 | | extern void tms36xx_note_w(device_t *device, int octave, int note); |
| 36 | // ======================> tms36xx_device |
| 26 | 37 | |
| 27 | | /* TMS3617 interface functions */ |
| 28 | | extern void tms3617_enable_w(device_t *device, int enable); |
| 29 | | |
| 30 | 38 | class tms36xx_device : public device_t, |
| 31 | | public device_sound_interface |
| 39 | public device_sound_interface |
| 32 | 40 | { |
| 33 | 41 | public: |
| 34 | 42 | tms36xx_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock); |
| 35 | | ~tms36xx_device() { global_free(m_token); } |
| 43 | ~tms36xx_device() { } |
| 36 | 44 | |
| 37 | | // access to legacy token |
| 38 | | void *token() const { assert(m_token != NULL); return m_token; } |
| 39 | 45 | protected: |
| 40 | 46 | // device-level overrides |
| 41 | | virtual void device_config_complete(); |
| 42 | 47 | virtual void device_start(); |
| 43 | 48 | |
| 44 | 49 | // sound stream update overrides |
| 45 | 50 | virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples); |
| 51 | |
| 52 | public: |
| 53 | // MM6221AA interface functions |
| 54 | void mm6221aa_tune_w(int tune); |
| 55 | |
| 56 | // TMS3615/17 interface functions |
| 57 | void tms36xx_note_w(int octave, int note); |
| 58 | |
| 59 | // TMS3617 interface functions |
| 60 | void tms3617_enable_w(int enable); |
| 61 | |
| 46 | 62 | private: |
| 47 | | // internal state |
| 48 | | void *m_token; |
| 63 | void tms36xx_reset_counters(); |
| 64 | void tms3617_enable(int enable); |
| 65 | |
| 66 | private: |
| 67 | char *m_subtype; // subtype name MM6221AA, TMS3615 or TMS3617 |
| 68 | sound_stream *m_channel; // returned by stream_create() |
| 69 | |
| 70 | int m_samplerate; // output sample rate |
| 71 | |
| 72 | int m_basefreq; // chip's base frequency |
| 73 | int m_octave; // octave select of the TMS3615 |
| 74 | |
| 75 | int m_speed; // speed of the tune |
| 76 | int m_tune_counter; // tune counter |
| 77 | int m_note_counter; // note counter |
| 78 | |
| 79 | int m_voices; // active voices |
| 80 | int m_shift; // shift toggles between 0 and 6 to allow decaying voices |
| 81 | int m_vol[12]; // (decaying) volume of harmonics notes |
| 82 | int m_vol_counter[12];// volume adjustment counter |
| 83 | int m_decay[12]; // volume adjustment rate - dervied from decay |
| 84 | |
| 85 | int m_counter[12]; // tone frequency counter |
| 86 | int m_frequency[12]; // tone frequency |
| 87 | int m_output; // output signal bits |
| 88 | int m_enable; // mask which harmoics |
| 89 | |
| 90 | int m_tune_num; // tune currently playing |
| 91 | int m_tune_ofs; // note currently playing |
| 92 | int m_tune_max; // end of tune |
| 93 | |
| 94 | const tms36xx_interface *m_intf; |
| 49 | 95 | }; |
| 50 | 96 | |
| 51 | 97 | extern const device_type TMS36XX; |
trunk/src/mess/drivers/fmtowns.c
| r21204 | r21205 | |
| 2181 | 2181 | AM_RANGE(0xc2100000, 0xc213ffff) AM_ROM AM_REGION("user",0x180000) // FONT ROM |
| 2182 | 2182 | AM_RANGE(0xc2140000, 0xc2141fff) AM_READWRITE8(towns_cmos_r,towns_cmos_w,0xffffffff) // CMOS (mirror?) |
| 2183 | 2183 | AM_RANGE(0xc2180000, 0xc21fffff) AM_ROM AM_REGION("user",0x080000) // F20 ROM |
| 2184 | | AM_RANGE(0xc2200000, 0xc220ffff) AM_DEVREADWRITE8_LEGACY("pcm",rf5c68_mem_r,rf5c68_mem_w,0xffffffff) // WAVE RAM |
| 2184 | AM_RANGE(0xc2200000, 0xc220ffff) AM_DEVREADWRITE8("pcm", rf5c68_device, rf5c68_mem_r, rf5c68_mem_w, 0xffffffff) // WAVE RAM |
| 2185 | 2185 | AM_RANGE(0xfffc0000, 0xffffffff) AM_ROM AM_REGION("user",0x200000) // SYSTEM ROM |
| 2186 | 2186 | ADDRESS_MAP_END |
| 2187 | 2187 | |
| r21204 | r21205 | |
| 2207 | 2207 | AM_RANGE(0x00d00000, 0x00dfffff) AM_RAM // IC Memory Card (is this usable on the Marty?) |
| 2208 | 2208 | AM_RANGE(0x00e80000, 0x00efffff) AM_ROM AM_REGION("user",0x100000) // DIC ROM |
| 2209 | 2209 | AM_RANGE(0x00f00000, 0x00f7ffff) AM_ROM AM_REGION("user",0x180000) // FONT |
| 2210 | | AM_RANGE(0x00f80000, 0x00f8ffff) AM_DEVREADWRITE8_LEGACY("pcm",rf5c68_mem_r,rf5c68_mem_w,0xffffffff) // WAVE RAM |
| 2210 | AM_RANGE(0x00f80000, 0x00f8ffff) AM_DEVREADWRITE8("pcm", rf5c68_device, rf5c68_mem_r, rf5c68_mem_w, 0xffffffff) // WAVE RAM |
| 2211 | 2211 | AM_RANGE(0x00fc0000, 0x00ffffff) AM_ROM AM_REGION("user",0x200000) // SYSTEM ROM |
| 2212 | 2212 | AM_RANGE(0xfffc0000, 0xffffffff) AM_ROM AM_REGION("user",0x200000) // SYSTEM ROM |
| 2213 | 2213 | ADDRESS_MAP_END |
| r21204 | r21205 | |
| 2234 | 2234 | AM_RANGE(0x00e00000, 0x00e7ffff) AM_ROM AM_REGION("user",0x000000) // OS |
| 2235 | 2235 | AM_RANGE(0x00e80000, 0x00efffff) AM_ROM AM_REGION("user",0x100000) // DIC ROM |
| 2236 | 2236 | AM_RANGE(0x00f00000, 0x00f7ffff) AM_ROM AM_REGION("user",0x180000) // FONT |
| 2237 | | AM_RANGE(0x00f80000, 0x00f8ffff) AM_DEVREADWRITE8_LEGACY("pcm",rf5c68_mem_r,rf5c68_mem_w,0xffffffff) // WAVE RAM |
| 2237 | AM_RANGE(0x00f80000, 0x00f8ffff) AM_DEVREADWRITE8("pcm", rf5c68_device, rf5c68_mem_r, rf5c68_mem_w, 0xffffffff) // WAVE RAM |
| 2238 | 2238 | AM_RANGE(0x00fc0000, 0x00ffffff) AM_ROM AM_REGION("user",0x200000) // SYSTEM ROM |
| 2239 | 2239 | AM_RANGE(0xfffc0000, 0xffffffff) AM_ROM AM_REGION("user",0x200000) // SYSTEM ROM |
| 2240 | 2240 | ADDRESS_MAP_END |
| r21204 | r21205 | |
| 2274 | 2274 | AM_RANGE(0x04d8,0x04df) AM_DEVREADWRITE8_LEGACY("fm",ym3438_r,ym3438_w,0x00ff00ff) |
| 2275 | 2275 | AM_RANGE(0x04e0,0x04e3) AM_READWRITE8(towns_volume_r,towns_volume_w,0xffffffff) // R/W -- volume ports |
| 2276 | 2276 | AM_RANGE(0x04e8,0x04ef) AM_READWRITE8(towns_sound_ctrl_r,towns_sound_ctrl_w,0xffffffff) |
| 2277 | | AM_RANGE(0x04f0,0x04fb) AM_DEVWRITE8_LEGACY("pcm",rf5c68_w,0xffffffff) |
| 2277 | AM_RANGE(0x04f0,0x04fb) AM_DEVWRITE8("pcm", rf5c68_device, rf5c68_w, 0xffffffff) |
| 2278 | 2278 | // CRTC / Video |
| 2279 | 2279 | AM_RANGE(0x05c8,0x05cb) AM_READWRITE8(towns_video_5c8_r, towns_video_5c8_w, 0xffffffff) |
| 2280 | 2280 | // System ports |
| r21204 | r21205 | |
| 2793 | 2793 | MCFG_SOUND_ADD("fm", YM3438, 53693100 / 7) // actual clock speed unknown |
| 2794 | 2794 | MCFG_SOUND_CONFIG(ym3438_intf) |
| 2795 | 2795 | MCFG_SOUND_ROUTE(ALL_OUTPUTS, "mono", 0.50) |
| 2796 | | MCFG_SOUND_ADD("pcm", RF5C68, 53693100 / 7) // actual clock speed unknown |
| 2796 | MCFG_RF5C68_ADD("pcm", 53693100 / 7) // actual clock speed unknown |
| 2797 | 2797 | MCFG_SOUND_CONFIG(rf5c68_intf) |
| 2798 | 2798 | MCFG_SOUND_ROUTE(ALL_OUTPUTS, "mono", 1.50) |
| 2799 | 2799 | MCFG_SOUND_ADD("cdda",CDDA,0) |