trunk/src/emu/sound/es5506.c
| r26107 | r26108 | |
| 84 | 84 | |
| 85 | 85 | #include "emu.h" |
| 86 | 86 | #include "es5506.h" |
| 87 | | #include "devlegcy.h" |
| 88 | 87 | |
| 89 | 88 | |
| 90 | | |
| 91 | 89 | /********************************************************************************************** |
| 92 | 90 | |
| 93 | 91 | CONSTANTS |
| r26107 | r26108 | |
| 96 | 94 | |
| 97 | 95 | #define LOG_COMMANDS 0 |
| 98 | 96 | #define RAINE_CHECK 0 |
| 99 | | #define MAKE_WAVS 0 |
| 100 | 97 | |
| 101 | 98 | #if MAKE_WAVS |
| 102 | 99 | #include "wavwrite.h" |
| r26107 | r26108 | |
| 130 | 127 | #define CONTROL_STOPMASK (CONTROL_STOP1 | CONTROL_STOP0) |
| 131 | 128 | |
| 132 | 129 | |
| 130 | es550x_device::es550x_device(const machine_config &mconfig, device_type type, const char *name, const char *tag, device_t *owner, UINT32 clock, const char *shortname, const char *source) |
| 131 | : device_t(mconfig, type, name, tag, owner, clock, shortname, source), |
| 132 | device_sound_interface(mconfig, *this), |
| 133 | m_stream(NULL), |
| 134 | m_sample_rate(0), |
| 135 | m_write_latch(0), |
| 136 | m_read_latch(0), |
| 137 | m_master_clock(0), |
| 138 | m_current_page(0), |
| 139 | m_active_voices(0), |
| 140 | m_mode(0), |
| 141 | m_wst(0), |
| 142 | m_wend(0), |
| 143 | m_lrend(0), |
| 144 | m_irqv(0), |
| 145 | m_scratch(NULL), |
| 146 | m_ulaw_lookup(NULL), |
| 147 | m_volume_lookup(NULL), |
| 148 | #if MAKE_WAVS |
| 149 | m_wavraw(NULL), |
| 150 | #endif |
| 151 | m_eslog(NULL) |
| 152 | { |
| 153 | for (int i = 0; i < 4; i++) |
| 154 | { |
| 155 | m_region_base[i] = NULL; |
| 156 | } |
| 157 | } |
| 133 | 158 | |
| 134 | | /********************************************************************************************** |
| 159 | const device_type ES5506 = &device_creator<es5506_device>; |
| 135 | 160 | |
| 136 | | INTERNAL DATA STRUCTURES |
| 161 | es5506_device::es5506_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock) |
| 162 | : es550x_device(mconfig, ES5506, "ES5506", tag, owner, clock, "es5506", __FILE__) |
| 163 | { |
| 164 | } |
| 137 | 165 | |
| 138 | | ***********************************************************************************************/ |
| 166 | //------------------------------------------------- |
| 167 | // device_config_complete - perform any |
| 168 | // operations now that the configuration is |
| 169 | // complete |
| 170 | //------------------------------------------------- |
| 139 | 171 | |
| 140 | | /* struct describing a single playing voice */ |
| 141 | | struct es5506_voice |
| 172 | void es550x_device::device_config_complete() |
| 142 | 173 | { |
| 143 | | /* external state */ |
| 144 | | UINT32 control; /* control register */ |
| 145 | | UINT32 freqcount; /* frequency count register */ |
| 146 | | UINT32 start; /* start register */ |
| 147 | | UINT32 lvol; /* left volume register */ |
| 148 | | UINT32 end; /* end register */ |
| 149 | | UINT32 lvramp; /* left volume ramp register */ |
| 150 | | UINT32 accum; /* accumulator register */ |
| 151 | | UINT32 rvol; /* right volume register */ |
| 152 | | UINT32 rvramp; /* right volume ramp register */ |
| 153 | | UINT32 ecount; /* envelope count register */ |
| 154 | | UINT32 k2; /* k2 register */ |
| 155 | | UINT32 k2ramp; /* k2 ramp register */ |
| 156 | | UINT32 k1; /* k1 register */ |
| 157 | | UINT32 k1ramp; /* k1 ramp register */ |
| 158 | | INT32 o4n1; /* filter storage O4(n-1) */ |
| 159 | | INT32 o3n1; /* filter storage O3(n-1) */ |
| 160 | | INT32 o3n2; /* filter storage O3(n-2) */ |
| 161 | | INT32 o2n1; /* filter storage O2(n-1) */ |
| 162 | | INT32 o2n2; /* filter storage O2(n-2) */ |
| 163 | | INT32 o1n1; /* filter storage O1(n-1) */ |
| 164 | | UINT32 exbank; /* external address bank */ |
| 174 | } |
| 165 | 175 | |
| 166 | | /* internal state */ |
| 167 | | UINT8 index; /* index of this voice */ |
| 168 | | UINT8 filtcount; /* filter count */ |
| 169 | | UINT32 accum_mask; |
| 170 | | }; |
| 176 | void es5506_device::device_config_complete() |
| 177 | { |
| 178 | // inherit a copy of the static data |
| 179 | const es5506_interface *intf = reinterpret_cast<const es5506_interface *>(static_config()); |
| 180 | if (intf != NULL) |
| 181 | *static_cast<es5506_interface *>(this) = *intf; |
| 171 | 182 | |
| 172 | | struct es5506_state |
| 183 | // or initialize to defaults if none provided |
| 184 | else |
| 185 | { |
| 186 | m_region0 = ""; |
| 187 | m_region1 = ""; |
| 188 | m_region2 = ""; |
| 189 | m_region3 = ""; |
| 190 | m_channels = 0; |
| 191 | memset(&m_irq_callback, 0, sizeof(m_irq_callback)); |
| 192 | memset(&m_read_port, 0, sizeof(m_read_port)); |
| 193 | } |
| 194 | } |
| 195 | |
| 196 | //------------------------------------------------- |
| 197 | // device_start - device-specific startup |
| 198 | //------------------------------------------------- |
| 199 | void es550x_device::device_start() |
| 173 | 200 | { |
| 174 | | sound_stream *stream; /* which stream are we using */ |
| 175 | | int sample_rate; /* current sample rate */ |
| 176 | | UINT16 * region_base[4]; /* pointer to the base of the region */ |
| 177 | | UINT32 write_latch; /* currently accumulated data for write */ |
| 178 | | UINT32 read_latch; /* currently accumulated data for read */ |
| 179 | | UINT32 master_clock; /* master clock frequency */ |
| 180 | | devcb_resolved_write_line irq_callback; /* IRQ callback */ |
| 181 | | devcb_resolved_read16 port_read; /* input port read */ |
| 201 | } |
| 182 | 202 | |
| 183 | | UINT8 current_page; /* current register page */ |
| 184 | | UINT8 active_voices; /* number of active voices */ |
| 185 | | UINT8 mode; /* MODE register */ |
| 186 | | UINT8 wst; /* W_ST register */ |
| 187 | | UINT8 wend; /* W_END register */ |
| 188 | | UINT8 lrend; /* LR_END register */ |
| 189 | | UINT8 irqv; /* IRQV register */ |
| 203 | void es5506_device::device_start() |
| 204 | { |
| 205 | int j; |
| 206 | UINT32 accum_mask; |
| 207 | int channels = 1; /* 1 channel by default, for backward compatibility */ |
| 190 | 208 | |
| 191 | | es5506_voice voice[32]; /* the 32 voices */ |
| 209 | /* only override the number of channels if the value is in the valid range 1 .. 6 */ |
| 210 | if (1 <= m_channels && m_channels <= 6) |
| 211 | channels = m_channels; |
| 192 | 212 | |
| 193 | | INT32 * scratch; |
| 213 | /* debugging */ |
| 214 | if (LOG_COMMANDS && !m_eslog) |
| 215 | m_eslog = fopen("es.log", "w"); |
| 194 | 216 | |
| 195 | | INT16 * ulaw_lookup; |
| 196 | | UINT16 * volume_lookup; |
| 197 | | device_t *device; |
| 217 | /* create the stream */ |
| 218 | m_stream = machine().sound().stream_alloc(*this, 0, 2 * channels, clock() / (16*32), this); |
| 198 | 219 | |
| 199 | | int channels; /* the number of output stereo channels: 1..4 for 5505, 1..6 for 5506 */ |
| 220 | /* initialize the regions */ |
| 221 | m_region_base[0] = m_region0 ? (UINT16 *)machine().root_device().memregion(m_region0)->base() : NULL; |
| 222 | m_region_base[1] = m_region1 ? (UINT16 *)machine().root_device().memregion(m_region1)->base() : NULL; |
| 223 | m_region_base[2] = m_region2 ? (UINT16 *)machine().root_device().memregion(m_region2)->base() : NULL; |
| 224 | m_region_base[3] = m_region3 ? (UINT16 *)machine().root_device().memregion(m_region3)->base() : NULL; |
| 200 | 225 | |
| 201 | | #if MAKE_WAVS |
| 202 | | void * wavraw; /* raw waveform */ |
| 203 | | #endif |
| 204 | | }; |
| 226 | /* initialize the rest of the structure */ |
| 227 | m_master_clock = clock(); |
| 228 | m_irq_callback_func.resolve(m_irq_callback, *this); |
| 229 | m_port_read_func.resolve(m_read_port, *this); |
| 230 | m_irqv = 0x80; |
| 231 | m_channels = channels; |
| 205 | 232 | |
| 233 | /* compute the tables */ |
| 234 | compute_tables(); |
| 206 | 235 | |
| 207 | | INLINE es5506_state *get_safe_token(device_t *device) |
| 236 | /* init the voices */ |
| 237 | accum_mask = 0xffffffff; |
| 238 | for (j = 0; j < 32; j++) |
| 239 | { |
| 240 | m_voice[j].index = j; |
| 241 | m_voice[j].control = CONTROL_STOPMASK; |
| 242 | m_voice[j].lvol = 0xffff; |
| 243 | m_voice[j].rvol = 0xffff; |
| 244 | m_voice[j].exbank = 0; |
| 245 | m_voice[j].accum_mask = accum_mask; |
| 246 | } |
| 247 | |
| 248 | /* allocate memory */ |
| 249 | m_scratch = auto_alloc_array_clear(machine(), INT32, 2 * MAX_SAMPLE_CHUNK); |
| 250 | |
| 251 | /* register save */ |
| 252 | save_item(NAME(m_sample_rate)); |
| 253 | save_item(NAME(m_write_latch)); |
| 254 | save_item(NAME(m_read_latch)); |
| 255 | |
| 256 | save_item(NAME(m_current_page)); |
| 257 | save_item(NAME(m_active_voices)); |
| 258 | save_item(NAME(m_mode)); |
| 259 | save_item(NAME(m_wst)); |
| 260 | save_item(NAME(m_wend)); |
| 261 | save_item(NAME(m_lrend)); |
| 262 | save_item(NAME(m_irqv)); |
| 263 | |
| 264 | save_pointer(NAME(m_scratch), 2 * MAX_SAMPLE_CHUNK); |
| 265 | |
| 266 | for (j = 0; j < 32; j++) |
| 267 | { |
| 268 | save_item(NAME(m_voice[j].control), j); |
| 269 | save_item(NAME(m_voice[j].freqcount), j); |
| 270 | save_item(NAME(m_voice[j].start), j); |
| 271 | save_item(NAME(m_voice[j].lvol), j); |
| 272 | save_item(NAME(m_voice[j].end), j); |
| 273 | save_item(NAME(m_voice[j].lvramp), j); |
| 274 | save_item(NAME(m_voice[j].accum), j); |
| 275 | save_item(NAME(m_voice[j].rvol), j); |
| 276 | save_item(NAME(m_voice[j].rvramp), j); |
| 277 | save_item(NAME(m_voice[j].ecount), j); |
| 278 | save_item(NAME(m_voice[j].k2), j); |
| 279 | save_item(NAME(m_voice[j].k2ramp), j); |
| 280 | save_item(NAME(m_voice[j].k1), j); |
| 281 | save_item(NAME(m_voice[j].k1ramp), j); |
| 282 | save_item(NAME(m_voice[j].o4n1), j); |
| 283 | save_item(NAME(m_voice[j].o3n1), j); |
| 284 | save_item(NAME(m_voice[j].o3n2), j); |
| 285 | save_item(NAME(m_voice[j].o2n1), j); |
| 286 | save_item(NAME(m_voice[j].o2n2), j); |
| 287 | save_item(NAME(m_voice[j].o1n1), j); |
| 288 | save_item(NAME(m_voice[j].exbank), j); |
| 289 | save_item(NAME(m_voice[j].filtcount), j); |
| 290 | } |
| 291 | |
| 292 | /* success */ |
| 293 | } |
| 294 | |
| 295 | //------------------------------------------------- |
| 296 | // device_reset - device-specific reset |
| 297 | //------------------------------------------------- |
| 298 | |
| 299 | void es550x_device::device_reset() |
| 208 | 300 | { |
| 209 | | assert(device != NULL); |
| 210 | | assert(device->type() == ES5505 || device->type() == ES5506); |
| 211 | | return (es5506_state *)downcast<es5506_device *>(device)->token(); |
| 212 | 301 | } |
| 213 | 302 | |
| 303 | //------------------------------------------------- |
| 304 | // device_stop - device-specific stop |
| 305 | //------------------------------------------------- |
| 214 | 306 | |
| 307 | void es550x_device::device_stop() |
| 308 | { |
| 309 | /* debugging */ |
| 310 | if (LOG_COMMANDS && m_eslog) |
| 311 | { |
| 312 | fclose(m_eslog); |
| 313 | m_eslog = NULL; |
| 314 | } |
| 215 | 315 | |
| 216 | | /********************************************************************************************** |
| 316 | #if MAKE_WAVS |
| 317 | { |
| 318 | int i; |
| 217 | 319 | |
| 218 | | GLOBAL VARIABLES |
| 320 | for (i = 0; i < MAX_ES5506; i++) |
| 321 | { |
| 322 | if (es5506[i].m_wavraw) |
| 323 | wav_close(es5506[i].m_wavraw); |
| 324 | } |
| 325 | } |
| 326 | #endif |
| 327 | } |
| 219 | 328 | |
| 220 | | ***********************************************************************************************/ |
| 329 | const device_type ES5505 = &device_creator<es5505_device>; |
| 221 | 330 | |
| 222 | | static FILE *eslog; |
| 331 | es5505_device::es5505_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock) |
| 332 | : es550x_device(mconfig, ES5505, "ES5505", tag, owner, clock, "es5505", __FILE__) |
| 333 | { |
| 334 | } |
| 223 | 335 | |
| 336 | //------------------------------------------------- |
| 337 | // device_config_complete - perform any |
| 338 | // operations now that the configuration is |
| 339 | // complete |
| 340 | //------------------------------------------------- |
| 224 | 341 | |
| 342 | void es5505_device::device_config_complete() |
| 343 | { |
| 344 | // inherit a copy of the static data |
| 345 | const es5505_interface *intf = reinterpret_cast<const es5505_interface *>(static_config()); |
| 346 | if (intf != NULL) |
| 347 | *static_cast<es5505_interface *>(this) = *intf; |
| 225 | 348 | |
| 349 | // or initialize to defaults if none provided |
| 350 | else |
| 351 | { |
| 352 | m_es5505_region0 = ""; |
| 353 | m_es5505_region1 = ""; |
| 354 | m_es5505_channels = 0; |
| 355 | memset(&m_es5505_irq_callback, 0, sizeof(m_es5505_irq_callback)); |
| 356 | memset(&m_es5505_read_port, 0, sizeof(m_es5505_read_port)); |
| 357 | } |
| 358 | } |
| 359 | |
| 360 | //------------------------------------------------- |
| 361 | // device_start - device-specific startup |
| 362 | //------------------------------------------------- |
| 363 | |
| 364 | void es5505_device::device_start() |
| 365 | { |
| 366 | int j; |
| 367 | UINT32 accum_mask; |
| 368 | int channels = 1; /* 1 channel by default, for backward compatibility */ |
| 369 | |
| 370 | /* only override the number of channels if the value is in the valid range 1 .. 4 */ |
| 371 | if (1 <= m_es5505_channels && m_es5505_channels <= 4) |
| 372 | channels = m_es5505_channels; |
| 373 | |
| 374 | /* debugging */ |
| 375 | if (LOG_COMMANDS && !m_eslog) |
| 376 | m_eslog = fopen("es.log", "w"); |
| 377 | |
| 378 | /* create the stream */ |
| 379 | m_stream = machine().sound().stream_alloc(*this, 0, 2 * channels, clock() / (16*32), this); |
| 380 | |
| 381 | /* initialize the regions */ |
| 382 | m_region_base[0] = m_es5505_region0 ? (UINT16 *)machine().root_device().memregion(m_es5505_region0)->base() : NULL; |
| 383 | m_region_base[1] = m_es5505_region1 ? (UINT16 *)machine().root_device().memregion(m_es5505_region1)->base() : NULL; |
| 384 | |
| 385 | /* initialize the rest of the structure */ |
| 386 | m_master_clock = clock(); |
| 387 | m_irq_callback_func.resolve(m_es5505_irq_callback, *this); |
| 388 | m_port_read_func.resolve(m_es5505_read_port, *this); |
| 389 | m_irqv = 0x80; |
| 390 | m_es5505_channels = channels; |
| 391 | |
| 392 | /* compute the tables */ |
| 393 | compute_tables(); |
| 394 | |
| 395 | /* init the voices */ |
| 396 | accum_mask = 0x7fffffff; |
| 397 | for (j = 0; j < 32; j++) |
| 398 | { |
| 399 | m_voice[j].index = j; |
| 400 | m_voice[j].control = CONTROL_STOPMASK; |
| 401 | m_voice[j].lvol = 0xffff; |
| 402 | m_voice[j].rvol = 0xffff; |
| 403 | m_voice[j].exbank = 0; |
| 404 | m_voice[j].accum_mask = accum_mask; |
| 405 | } |
| 406 | |
| 407 | /* allocate memory */ |
| 408 | m_scratch = auto_alloc_array_clear(machine(), INT32, 2 * MAX_SAMPLE_CHUNK); |
| 409 | |
| 410 | /* register save */ |
| 411 | save_item(NAME(m_sample_rate)); |
| 412 | save_item(NAME(m_write_latch)); |
| 413 | save_item(NAME(m_read_latch)); |
| 414 | |
| 415 | save_item(NAME(m_current_page)); |
| 416 | save_item(NAME(m_active_voices)); |
| 417 | save_item(NAME(m_mode)); |
| 418 | save_item(NAME(m_wst)); |
| 419 | save_item(NAME(m_wend)); |
| 420 | save_item(NAME(m_lrend)); |
| 421 | save_item(NAME(m_irqv)); |
| 422 | |
| 423 | save_pointer(NAME(m_scratch), 2 * MAX_SAMPLE_CHUNK); |
| 424 | |
| 425 | for (j = 0; j < 32; j++) |
| 426 | { |
| 427 | save_item(NAME(m_voice[j].control), j); |
| 428 | save_item(NAME(m_voice[j].freqcount), j); |
| 429 | save_item(NAME(m_voice[j].start), j); |
| 430 | save_item(NAME(m_voice[j].lvol), j); |
| 431 | save_item(NAME(m_voice[j].end), j); |
| 432 | save_item(NAME(m_voice[j].lvramp), j); |
| 433 | save_item(NAME(m_voice[j].accum), j); |
| 434 | save_item(NAME(m_voice[j].rvol), j); |
| 435 | save_item(NAME(m_voice[j].rvramp), j); |
| 436 | save_item(NAME(m_voice[j].ecount), j); |
| 437 | save_item(NAME(m_voice[j].k2), j); |
| 438 | save_item(NAME(m_voice[j].k2ramp), j); |
| 439 | save_item(NAME(m_voice[j].k1), j); |
| 440 | save_item(NAME(m_voice[j].k1ramp), j); |
| 441 | save_item(NAME(m_voice[j].o4n1), j); |
| 442 | save_item(NAME(m_voice[j].o3n1), j); |
| 443 | save_item(NAME(m_voice[j].o3n2), j); |
| 444 | save_item(NAME(m_voice[j].o2n1), j); |
| 445 | save_item(NAME(m_voice[j].o2n2), j); |
| 446 | save_item(NAME(m_voice[j].o1n1), j); |
| 447 | save_item(NAME(m_voice[j].exbank), j); |
| 448 | save_item(NAME(m_voice[j].filtcount), j); |
| 449 | } |
| 450 | |
| 451 | /* success */ |
| 452 | } |
| 453 | |
| 454 | |
| 226 | 455 | /********************************************************************************************** |
| 227 | 456 | |
| 228 | 457 | update_irq_state -- update the IRQ state |
| 229 | 458 | |
| 230 | 459 | ***********************************************************************************************/ |
| 231 | 460 | |
| 232 | | static void update_irq_state(es5506_state *chip) |
| 461 | |
| 462 | void es550x_device::update_irq_state() |
| 233 | 463 | { |
| 234 | 464 | /* ES5505/6 irq line has been set high - inform the host */ |
| 235 | | if (!chip->irq_callback.isnull()) |
| 236 | | chip->irq_callback(1); /* IRQB set high */ |
| 465 | if (!m_irq_callback_func.isnull()) |
| 466 | m_irq_callback_func(1); /* IRQB set high */ |
| 237 | 467 | } |
| 238 | 468 | |
| 239 | | static void update_internal_irq_state(es5506_state *chip) |
| 469 | void es550x_device::update_internal_irq_state() |
| 240 | 470 | { |
| 241 | 471 | /* Host (cpu) has just read the voice interrupt vector (voice IRQ ack). |
| 242 | 472 | |
| r26107 | r26108 | |
| 247 | 477 | terms they get updated next time generate_samples() is called. |
| 248 | 478 | */ |
| 249 | 479 | |
| 250 | | chip->irqv=0x80; |
| 480 | m_irqv=0x80; |
| 251 | 481 | |
| 252 | | if (!chip->irq_callback.isnull()) |
| 253 | | chip->irq_callback(0); /* IRQB set low */ |
| 482 | if (!m_irq_callback_func.isnull()) |
| 483 | m_irq_callback_func(0); /* IRQB set low */ |
| 254 | 484 | } |
| 255 | 485 | |
| 256 | 486 | /********************************************************************************************** |
| r26107 | r26108 | |
| 259 | 489 | |
| 260 | 490 | ***********************************************************************************************/ |
| 261 | 491 | |
| 262 | | static void compute_tables(es5506_state *chip) |
| 492 | void es550x_device::compute_tables() |
| 263 | 493 | { |
| 264 | 494 | int i; |
| 265 | 495 | |
| 266 | 496 | /* allocate ulaw lookup table */ |
| 267 | | chip->ulaw_lookup = auto_alloc_array(chip->device->machine(), INT16, 1 << ULAW_MAXBITS); |
| 497 | m_ulaw_lookup = auto_alloc_array_clear(machine(), INT16, 1 << ULAW_MAXBITS); |
| 268 | 498 | |
| 269 | 499 | /* generate ulaw lookup table */ |
| 270 | 500 | for (i = 0; i < (1 << ULAW_MAXBITS); i++) |
| r26107 | r26108 | |
| 274 | 504 | UINT32 mantissa = (rawval << 3) & 0xffff; |
| 275 | 505 | |
| 276 | 506 | if (exponent == 0) |
| 277 | | chip->ulaw_lookup[i] = (INT16)mantissa >> 7; |
| 507 | m_ulaw_lookup[i] = (INT16)mantissa >> 7; |
| 278 | 508 | else |
| 279 | 509 | { |
| 280 | 510 | mantissa = (mantissa >> 1) | (~mantissa & 0x8000); |
| 281 | | chip->ulaw_lookup[i] = (INT16)mantissa >> (7 - exponent); |
| 511 | m_ulaw_lookup[i] = (INT16)mantissa >> (7 - exponent); |
| 282 | 512 | } |
| 283 | 513 | } |
| 284 | 514 | |
| 285 | 515 | /* allocate volume lookup table */ |
| 286 | | chip->volume_lookup = auto_alloc_array(chip->device->machine(), UINT16, 4096); |
| 516 | m_volume_lookup = auto_alloc_array_clear(machine(), UINT16, 4096); |
| 287 | 517 | |
| 288 | 518 | /* generate volume lookup table */ |
| 289 | 519 | for (i = 0; i < 4096; i++) |
| r26107 | r26108 | |
| 291 | 521 | UINT8 exponent = i >> 8; |
| 292 | 522 | UINT32 mantissa = (i & 0xff) | 0x100; |
| 293 | 523 | |
| 294 | | chip->volume_lookup[i] = (mantissa << 11) >> (20 - exponent); |
| 524 | m_volume_lookup[i] = (mantissa << 11) >> (20 - exponent); |
| 295 | 525 | } |
| 296 | 526 | } |
| 297 | 527 | |
| r26107 | r26108 | |
| 523 | 753 | |
| 524 | 754 | ***********************************************************************************************/ |
| 525 | 755 | |
| 526 | | static void generate_dummy(es5506_state *chip, es5506_voice *voice, UINT16 *base, INT32 *lbuffer, INT32 *rbuffer, int samples) |
| 756 | void es550x_device::generate_dummy(es550x_voice *voice, UINT16 *base, INT32 *lbuffer, INT32 *rbuffer, int samples) |
| 527 | 757 | { |
| 528 | 758 | UINT32 freqcount = voice->freqcount; |
| 529 | 759 | UINT32 accum = voice->accum & voice->accum_mask; |
| r26107 | r26108 | |
| 584 | 814 | |
| 585 | 815 | ***********************************************************************************************/ |
| 586 | 816 | |
| 587 | | static void generate_ulaw(es5506_state *chip, es5506_voice *voice, UINT16 *base, INT32 *lbuffer, INT32 *rbuffer, int samples) |
| 817 | void es550x_device::generate_ulaw(es550x_voice *voice, UINT16 *base, INT32 *lbuffer, INT32 *rbuffer, int samples) |
| 588 | 818 | { |
| 589 | 819 | UINT32 freqcount = voice->freqcount; |
| 590 | 820 | UINT32 accum = voice->accum & voice->accum_mask; |
| 591 | | INT32 lvol = chip->volume_lookup[voice->lvol >> 4]; |
| 592 | | INT32 rvol = chip->volume_lookup[voice->rvol >> 4]; |
| 821 | INT32 lvol = m_volume_lookup[voice->lvol >> 4]; |
| 822 | INT32 rvol = m_volume_lookup[voice->rvol >> 4]; |
| 593 | 823 | |
| 594 | 824 | /* pre-add the bank offset */ |
| 595 | 825 | base += voice->exbank; |
| r26107 | r26108 | |
| 609 | 839 | INT32 val2 = base[((accum + (1 << 11)) & voice->accum_mask) >> 11]; |
| 610 | 840 | |
| 611 | 841 | /* decompress u-law */ |
| 612 | | val1 = chip->ulaw_lookup[val1 >> (16 - ULAW_MAXBITS)]; |
| 613 | | val2 = chip->ulaw_lookup[val2 >> (16 - ULAW_MAXBITS)]; |
| 842 | val1 = m_ulaw_lookup[val1 >> (16 - ULAW_MAXBITS)]; |
| 843 | val2 = m_ulaw_lookup[val2 >> (16 - ULAW_MAXBITS)]; |
| 614 | 844 | |
| 615 | 845 | /* interpolate */ |
| 616 | 846 | val1 = interpolate(val1, val2, accum); |
| r26107 | r26108 | |
| 623 | 853 | if (voice->ecount != 0) |
| 624 | 854 | { |
| 625 | 855 | update_envelopes(voice, 1); |
| 626 | | lvol = chip->volume_lookup[voice->lvol >> 4]; |
| 627 | | rvol = chip->volume_lookup[voice->rvol >> 4]; |
| 856 | lvol = m_volume_lookup[voice->lvol >> 4]; |
| 857 | rvol = m_volume_lookup[voice->rvol >> 4]; |
| 628 | 858 | } |
| 629 | 859 | |
| 630 | 860 | /* apply volumes and add */ |
| r26107 | r26108 | |
| 647 | 877 | INT32 val2 = base[((accum + (1 << 11)) & voice->accum_mask) >> 11]; |
| 648 | 878 | |
| 649 | 879 | /* decompress u-law */ |
| 650 | | val1 = chip->ulaw_lookup[val1 >> (16 - ULAW_MAXBITS)]; |
| 651 | | val2 = chip->ulaw_lookup[val2 >> (16 - ULAW_MAXBITS)]; |
| 880 | val1 = m_ulaw_lookup[val1 >> (16 - ULAW_MAXBITS)]; |
| 881 | val2 = m_ulaw_lookup[val2 >> (16 - ULAW_MAXBITS)]; |
| 652 | 882 | |
| 653 | 883 | /* interpolate */ |
| 654 | 884 | val1 = interpolate(val1, val2, accum); |
| r26107 | r26108 | |
| 661 | 891 | if (voice->ecount != 0) |
| 662 | 892 | { |
| 663 | 893 | update_envelopes(voice, 1); |
| 664 | | lvol = chip->volume_lookup[voice->lvol >> 4]; |
| 665 | | rvol = chip->volume_lookup[voice->rvol >> 4]; |
| 894 | lvol = m_volume_lookup[voice->lvol >> 4]; |
| 895 | rvol = m_volume_lookup[voice->rvol >> 4]; |
| 666 | 896 | } |
| 667 | 897 | |
| 668 | 898 | /* apply volumes and add */ |
| r26107 | r26108 | |
| 690 | 920 | |
| 691 | 921 | ***********************************************************************************************/ |
| 692 | 922 | |
| 693 | | static void generate_pcm(es5506_state *chip, es5506_voice *voice, UINT16 *base, INT32 *lbuffer, INT32 *rbuffer, int samples) |
| 923 | void es550x_device::generate_pcm(es550x_voice *voice, UINT16 *base, INT32 *lbuffer, INT32 *rbuffer, int samples) |
| 694 | 924 | { |
| 695 | 925 | UINT32 freqcount = voice->freqcount; |
| 696 | 926 | UINT32 accum = voice->accum & voice->accum_mask; |
| 697 | | INT32 lvol = chip->volume_lookup[voice->lvol >> 4]; |
| 698 | | INT32 rvol = chip->volume_lookup[voice->rvol >> 4]; |
| 927 | INT32 lvol = m_volume_lookup[voice->lvol >> 4]; |
| 928 | INT32 rvol = m_volume_lookup[voice->rvol >> 4]; |
| 699 | 929 | |
| 700 | 930 | /* pre-add the bank offset */ |
| 701 | 931 | base += voice->exbank; |
| r26107 | r26108 | |
| 725 | 955 | if (voice->ecount != 0) |
| 726 | 956 | { |
| 727 | 957 | update_envelopes(voice, 1); |
| 728 | | lvol = chip->volume_lookup[voice->lvol >> 4]; |
| 729 | | rvol = chip->volume_lookup[voice->rvol >> 4]; |
| 958 | lvol = m_volume_lookup[voice->lvol >> 4]; |
| 959 | rvol = m_volume_lookup[voice->rvol >> 4]; |
| 730 | 960 | } |
| 731 | 961 | |
| 732 | 962 | /* apply volumes and add */ |
| r26107 | r26108 | |
| 759 | 989 | if (voice->ecount != 0) |
| 760 | 990 | { |
| 761 | 991 | update_envelopes(voice, 1); |
| 762 | | lvol = chip->volume_lookup[voice->lvol >> 4]; |
| 763 | | rvol = chip->volume_lookup[voice->rvol >> 4]; |
| 992 | lvol = m_volume_lookup[voice->lvol >> 4]; |
| 993 | rvol = m_volume_lookup[voice->rvol >> 4]; |
| 764 | 994 | } |
| 765 | 995 | |
| 766 | 996 | /* apply volumes and add */ |
| r26107 | r26108 | |
| 788 | 1018 | |
| 789 | 1019 | ***********************************************************************************************/ |
| 790 | 1020 | |
| 791 | | static void generate_samples(es5506_state *chip, INT32 **outputs, int offset, int samples) |
| 1021 | void es5506_device::generate_samples(INT32 **outputs, int offset, int samples) |
| 792 | 1022 | { |
| 793 | 1023 | int v; |
| 794 | 1024 | |
| r26107 | r26108 | |
| 797 | 1027 | return; |
| 798 | 1028 | |
| 799 | 1029 | /* clear out the accumulators */ |
| 800 | | for (int i = 0; i < chip->channels << 1; i++) |
| 1030 | for (int i = 0; i < m_channels << 1; i++) |
| 801 | 1031 | { |
| 802 | 1032 | memset(outputs[i] + offset, 0, sizeof(INT32) * samples); |
| 803 | 1033 | } |
| 804 | 1034 | |
| 805 | 1035 | /* loop over voices */ |
| 806 | | for (v = 0; v <= chip->active_voices; v++) |
| 1036 | for (v = 0; v <= m_active_voices; v++) |
| 807 | 1037 | { |
| 808 | | es5506_voice *voice = &chip->voice[v]; |
| 809 | | UINT16 *base = chip->region_base[voice->control >> 14]; |
| 1038 | es550x_voice *voice = &m_voice[v]; |
| 1039 | UINT16 *base = m_region_base[voice->control >> 14]; |
| 810 | 1040 | |
| 811 | 1041 | /* special case: if end == start, stop the voice */ |
| 812 | 1042 | if (voice->start == voice->end) |
| 813 | 1043 | voice->control |= CONTROL_STOP0; |
| 814 | 1044 | |
| 815 | 1045 | int voice_channel = (voice->control & CONTROL_CAMASK) >> 10; |
| 816 | | int channel = voice_channel % chip->channels; |
| 1046 | int channel = voice_channel % m_channels; |
| 817 | 1047 | int l = channel << 1; |
| 818 | 1048 | int r = l + 1; |
| 819 | 1049 | INT32 *left = outputs[l] + offset; |
| r26107 | r26108 | |
| 823 | 1053 | if (!base) |
| 824 | 1054 | { |
| 825 | 1055 | logerror("es5506: NULL region base %d\n",voice->control >> 14); |
| 826 | | generate_dummy(chip, voice, base, left, right, samples); |
| 1056 | generate_dummy(voice, base, left, right, samples); |
| 827 | 1057 | } |
| 828 | 1058 | else if (voice->control & 0x2000) |
| 829 | | generate_ulaw(chip, voice, base, left, right, samples); |
| 1059 | generate_ulaw(voice, base, left, right, samples); |
| 830 | 1060 | else |
| 831 | | generate_pcm(chip, voice, base, left, right, samples); |
| 1061 | generate_pcm(voice, base, left, right, samples); |
| 832 | 1062 | |
| 833 | 1063 | /* does this voice have it's IRQ bit raised? */ |
| 834 | 1064 | if (voice->control&CONTROL_IRQ) |
| r26107 | r26108 | |
| 836 | 1066 | logerror("es5506: IRQ raised on voice %d!!\n",v); |
| 837 | 1067 | |
| 838 | 1068 | /* only update voice vector if existing IRQ is acked by host */ |
| 839 | | if (chip->irqv&0x80) |
| 1069 | if (m_irqv&0x80) |
| 840 | 1070 | { |
| 841 | 1071 | /* latch voice number into vector, and set high bit low */ |
| 842 | | chip->irqv=v&0x7f; |
| 1072 | m_irqv=v&0x7f; |
| 843 | 1073 | |
| 844 | 1074 | /* take down IRQ bit on voice */ |
| 845 | 1075 | voice->control&=~CONTROL_IRQ; |
| 846 | 1076 | |
| 847 | 1077 | /* inform host of irq */ |
| 848 | | update_irq_state(chip); |
| 1078 | update_irq_state(); |
| 849 | 1079 | } |
| 850 | 1080 | } |
| 851 | 1081 | } |
| 852 | 1082 | } |
| 853 | 1083 | |
| 854 | | |
| 855 | | |
| 856 | | /********************************************************************************************** |
| 857 | | |
| 858 | | es5506_update -- update the sound chip so that it is in sync with CPU execution |
| 859 | | |
| 860 | | ***********************************************************************************************/ |
| 861 | | |
| 862 | | STREAM_UPDATE( es5506_update ) |
| 1084 | void es5505_device::generate_samples(INT32 **outputs, int offset, int samples) |
| 863 | 1085 | { |
| 864 | | es5506_state *chip = (es5506_state *)param; |
| 1086 | int v; |
| 865 | 1087 | |
| 866 | | #if MAKE_WAVS |
| 867 | | /* start the logging once we have a sample rate */ |
| 868 | | if (chip->sample_rate) |
| 869 | | { |
| 870 | | if (!chip->wavraw) |
| 871 | | chip->wavraw = wav_open("raw.wav", chip->sample_rate, 2); |
| 872 | | } |
| 873 | | #endif |
| 1088 | /* skip if nothing to do */ |
| 1089 | if (!samples) |
| 1090 | return; |
| 874 | 1091 | |
| 875 | | /* loop until all samples are output */ |
| 876 | | int offset = 0; |
| 877 | | while (samples) |
| 1092 | /* clear out the accumulators */ |
| 1093 | for (int i = 0; i < m_es5505_channels << 1; i++) |
| 878 | 1094 | { |
| 879 | | int length = (samples > MAX_SAMPLE_CHUNK) ? MAX_SAMPLE_CHUNK : samples; |
| 880 | | |
| 881 | | generate_samples(chip, outputs, offset, length); |
| 882 | | |
| 883 | | #if MAKE_WAVS |
| 884 | | /* log the raw data */ |
| 885 | | if (chip->wavraw) { |
| 886 | | /* determine left/right source data */ |
| 887 | | INT32 *lsrc = chip->scratch, *rsrc = chip->scratch + length; |
| 888 | | int channel; |
| 889 | | memset(lsrc, 0, sizeof(INT32) * length * 2); |
| 890 | | /* loop over the output channels */ |
| 891 | | for (channel = 0; channel < chip->channels; channel++) { |
| 892 | | INT32 *l = outputs[(channel << 1)] + offset; |
| 893 | | INT32 *r = outputs[(channel << 1) + 1] + offset; |
| 894 | | /* add the current channel's samples to the WAV data */ |
| 895 | | for (samp = 0; samp < length; samp++) { |
| 896 | | lsrc[samp] += l[samp]; |
| 897 | | rsrc[samp] += r[samp]; |
| 898 | | } |
| 899 | | } |
| 900 | | wav_add_data_32lr(chip->wavraw, lsrc, rsrc, length, 4); |
| 901 | | } |
| 902 | | #endif |
| 903 | | |
| 904 | | /* account for these samples */ |
| 905 | | offset += length; |
| 906 | | samples -= length; |
| 1095 | memset(outputs[i] + offset, 0, sizeof(INT32) * samples); |
| 907 | 1096 | } |
| 908 | | } |
| 909 | 1097 | |
| 910 | | |
| 911 | | /********************************************************************************************** |
| 912 | | |
| 913 | | DEVICE_START( es5506 ) -- start emulation of the ES5506 |
| 914 | | |
| 915 | | ***********************************************************************************************/ |
| 916 | | |
| 917 | | static void es5506_start_common(device_t *device, const void *config, device_type sndtype) |
| 918 | | { |
| 919 | | const es5506_interface *intf = (const es5506_interface *)config; |
| 920 | | es5506_state *chip = get_safe_token(device); |
| 921 | | int j; |
| 922 | | UINT32 accum_mask; |
| 923 | | int channels = 1; /* 1 channel by default, for backward compatibility */ |
| 924 | | |
| 925 | | /* only override the number of channels if the value is in the valid range 1 .. 6 */ |
| 926 | | if (1 <= intf->channels && intf->channels <= 6) |
| 927 | | channels = intf->channels; |
| 928 | | |
| 929 | | /* debugging */ |
| 930 | | if (LOG_COMMANDS && !eslog) |
| 931 | | eslog = fopen("es.log", "w"); |
| 932 | | |
| 933 | | /* create the stream */ |
| 934 | | chip->stream = device->machine().sound().stream_alloc(*device, 0, 2 * channels, device->clock() / (16*32), chip, es5506_update); |
| 935 | | |
| 936 | | /* initialize the regions */ |
| 937 | | chip->region_base[0] = intf->region0 ? (UINT16 *)device->machine().root_device().memregion(intf->region0)->base() : NULL; |
| 938 | | chip->region_base[1] = intf->region1 ? (UINT16 *)device->machine().root_device().memregion(intf->region1)->base() : NULL; |
| 939 | | chip->region_base[2] = intf->region2 ? (UINT16 *)device->machine().root_device().memregion(intf->region2)->base() : NULL; |
| 940 | | chip->region_base[3] = intf->region3 ? (UINT16 *)device->machine().root_device().memregion(intf->region3)->base() : NULL; |
| 941 | | |
| 942 | | /* initialize the rest of the structure */ |
| 943 | | chip->device = device; |
| 944 | | chip->master_clock = device->clock(); |
| 945 | | chip->irq_callback.resolve(intf->irq_callback,*device); |
| 946 | | chip->port_read.resolve(intf->read_port,*device); |
| 947 | | chip->irqv = 0x80; |
| 948 | | chip->channels = channels; |
| 949 | | |
| 950 | | /* compute the tables */ |
| 951 | | compute_tables(chip); |
| 952 | | |
| 953 | | /* init the voices */ |
| 954 | | accum_mask = (sndtype == ES5506) ? 0xffffffff : 0x7fffffff; |
| 955 | | for (j = 0; j < 32; j++) |
| 1098 | /* loop over voices */ |
| 1099 | for (v = 0; v <= m_active_voices; v++) |
| 956 | 1100 | { |
| 957 | | chip->voice[j].index = j; |
| 958 | | chip->voice[j].control = CONTROL_STOPMASK; |
| 959 | | chip->voice[j].lvol = 0xffff; |
| 960 | | chip->voice[j].rvol = 0xffff; |
| 961 | | chip->voice[j].exbank = 0; |
| 962 | | chip->voice[j].accum_mask = accum_mask; |
| 963 | | } |
| 1101 | es550x_voice *voice = &m_voice[v]; |
| 1102 | UINT16 *base = m_region_base[voice->control >> 14]; |
| 964 | 1103 | |
| 965 | | /* allocate memory */ |
| 966 | | chip->scratch = auto_alloc_array(device->machine(), INT32, 2 * MAX_SAMPLE_CHUNK); |
| 1104 | /* special case: if end == start, stop the voice */ |
| 1105 | if (voice->start == voice->end) |
| 1106 | voice->control |= CONTROL_STOP0; |
| 967 | 1107 | |
| 968 | | /* register save */ |
| 969 | | device->save_item(NAME(chip->sample_rate)); |
| 970 | | device->save_item(NAME(chip->write_latch)); |
| 971 | | device->save_item(NAME(chip->read_latch)); |
| 1108 | int voice_channel = (voice->control & CONTROL_CAMASK) >> 10; |
| 1109 | int channel = voice_channel % m_es5505_channels; |
| 1110 | int l = channel << 1; |
| 1111 | int r = l + 1; |
| 1112 | INT32 *left = outputs[l] + offset; |
| 1113 | INT32 *right = outputs[r] + offset; |
| 972 | 1114 | |
| 973 | | device->save_item(NAME(chip->current_page)); |
| 974 | | device->save_item(NAME(chip->active_voices)); |
| 975 | | device->save_item(NAME(chip->mode)); |
| 976 | | device->save_item(NAME(chip->wst)); |
| 977 | | device->save_item(NAME(chip->wend)); |
| 978 | | device->save_item(NAME(chip->lrend)); |
| 979 | | device->save_item(NAME(chip->irqv)); |
| 1115 | /* generate from the appropriate source */ |
| 1116 | if (!base) |
| 1117 | { |
| 1118 | logerror("es5506: NULL region base %d\n",voice->control >> 14); |
| 1119 | generate_dummy(voice, base, left, right, samples); |
| 1120 | } |
| 1121 | else if (voice->control & 0x2000) |
| 1122 | generate_ulaw(voice, base, left, right, samples); |
| 1123 | else |
| 1124 | generate_pcm(voice, base, left, right, samples); |
| 980 | 1125 | |
| 981 | | device->save_pointer(NAME(chip->scratch), 2 * MAX_SAMPLE_CHUNK); |
| 1126 | /* does this voice have it's IRQ bit raised? */ |
| 1127 | if (voice->control&CONTROL_IRQ) |
| 1128 | { |
| 1129 | logerror("es5506: IRQ raised on voice %d!!\n",v); |
| 982 | 1130 | |
| 983 | | for (j = 0; j < 32; j++) |
| 984 | | { |
| 985 | | device->save_item(NAME(chip->voice[j].control), j); |
| 986 | | device->save_item(NAME(chip->voice[j].freqcount), j); |
| 987 | | device->save_item(NAME(chip->voice[j].start), j); |
| 988 | | device->save_item(NAME(chip->voice[j].lvol), j); |
| 989 | | device->save_item(NAME(chip->voice[j].end), j); |
| 990 | | device->save_item(NAME(chip->voice[j].lvramp), j); |
| 991 | | device->save_item(NAME(chip->voice[j].accum), j); |
| 992 | | device->save_item(NAME(chip->voice[j].rvol), j); |
| 993 | | device->save_item(NAME(chip->voice[j].rvramp), j); |
| 994 | | device->save_item(NAME(chip->voice[j].ecount), j); |
| 995 | | device->save_item(NAME(chip->voice[j].k2), j); |
| 996 | | device->save_item(NAME(chip->voice[j].k2ramp), j); |
| 997 | | device->save_item(NAME(chip->voice[j].k1), j); |
| 998 | | device->save_item(NAME(chip->voice[j].k1ramp), j); |
| 999 | | device->save_item(NAME(chip->voice[j].o4n1), j); |
| 1000 | | device->save_item(NAME(chip->voice[j].o3n1), j); |
| 1001 | | device->save_item(NAME(chip->voice[j].o3n2), j); |
| 1002 | | device->save_item(NAME(chip->voice[j].o2n1), j); |
| 1003 | | device->save_item(NAME(chip->voice[j].o2n2), j); |
| 1004 | | device->save_item(NAME(chip->voice[j].o1n1), j); |
| 1005 | | device->save_item(NAME(chip->voice[j].exbank), j); |
| 1006 | | device->save_item(NAME(chip->voice[j].filtcount), j); |
| 1007 | | } |
| 1131 | /* only update voice vector if existing IRQ is acked by host */ |
| 1132 | if (m_irqv&0x80) |
| 1133 | { |
| 1134 | /* latch voice number into vector, and set high bit low */ |
| 1135 | m_irqv=v&0x7f; |
| 1008 | 1136 | |
| 1009 | | /* success */ |
| 1010 | | } |
| 1137 | /* take down IRQ bit on voice */ |
| 1138 | voice->control&=~CONTROL_IRQ; |
| 1011 | 1139 | |
| 1012 | | |
| 1013 | | static DEVICE_START( es5506 ) |
| 1014 | | { |
| 1015 | | es5506_start_common(device, device->static_config(), ES5506); |
| 1016 | | } |
| 1017 | | |
| 1018 | | |
| 1019 | | |
| 1020 | | /********************************************************************************************** |
| 1021 | | |
| 1022 | | DEVICE_STOP( es5506 ) -- stop emulation of the ES5506 |
| 1023 | | |
| 1024 | | ***********************************************************************************************/ |
| 1025 | | |
| 1026 | | static DEVICE_STOP( es5506 ) |
| 1027 | | { |
| 1028 | | /* debugging */ |
| 1029 | | if (LOG_COMMANDS && eslog) |
| 1030 | | { |
| 1031 | | fclose(eslog); |
| 1032 | | eslog = NULL; |
| 1140 | /* inform host of irq */ |
| 1141 | update_irq_state(); |
| 1142 | } |
| 1143 | } |
| 1033 | 1144 | } |
| 1034 | | |
| 1035 | | #if MAKE_WAVS |
| 1036 | | { |
| 1037 | | int i; |
| 1038 | | |
| 1039 | | for (i = 0; i < MAX_ES5506; i++) |
| 1040 | | { |
| 1041 | | if (es5506[i].wavraw) |
| 1042 | | wav_close(es5506[i].wavraw); |
| 1043 | | } |
| 1044 | 1145 | } |
| 1045 | | #endif |
| 1046 | | } |
| 1047 | 1146 | |
| 1048 | 1147 | |
| 1049 | 1148 | |
| 1050 | 1149 | /********************************************************************************************** |
| 1051 | 1150 | |
| 1052 | | es5506_reg_write -- handle a write to the selected ES5506 register |
| 1151 | reg_write -- handle a write to the selected ES5506 register |
| 1053 | 1152 | |
| 1054 | 1153 | ***********************************************************************************************/ |
| 1055 | 1154 | |
| 1056 | | INLINE void es5506_reg_write_low(es5506_state *chip, es5506_voice *voice, offs_t offset, UINT32 data) |
| 1155 | inline void es5506_device::reg_write_low(es550x_voice *voice, offs_t offset, UINT32 data) |
| 1057 | 1156 | { |
| 1058 | 1157 | switch (offset) |
| 1059 | 1158 | { |
| 1060 | 1159 | case 0x00/8: /* CR */ |
| 1061 | 1160 | voice->control = data & 0xffff; |
| 1062 | | if (LOG_COMMANDS && eslog) |
| 1063 | | fprintf(eslog, "voice %d, control=%04x\n", chip->current_page & 0x1f, voice->control); |
| 1161 | if (LOG_COMMANDS && m_eslog) |
| 1162 | fprintf(m_eslog, "voice %d, control=%04x\n", m_current_page & 0x1f, voice->control); |
| 1064 | 1163 | break; |
| 1065 | 1164 | |
| 1066 | 1165 | case 0x08/8: /* FC */ |
| 1067 | 1166 | voice->freqcount = data & 0x1ffff; |
| 1068 | | if (LOG_COMMANDS && eslog) |
| 1069 | | fprintf(eslog, "voice %d, freq count=%08x\n", chip->current_page & 0x1f, voice->freqcount); |
| 1167 | if (LOG_COMMANDS && m_eslog) |
| 1168 | fprintf(m_eslog, "voice %d, freq count=%08x\n", m_current_page & 0x1f, voice->freqcount); |
| 1070 | 1169 | break; |
| 1071 | 1170 | |
| 1072 | 1171 | case 0x10/8: /* LVOL */ |
| 1073 | 1172 | voice->lvol = data & 0xffff; |
| 1074 | | if (LOG_COMMANDS && eslog) |
| 1075 | | fprintf(eslog, "voice %d, left vol=%04x\n", chip->current_page & 0x1f, voice->lvol); |
| 1173 | if (LOG_COMMANDS && m_eslog) |
| 1174 | fprintf(m_eslog, "voice %d, left vol=%04x\n", m_current_page & 0x1f, voice->lvol); |
| 1076 | 1175 | break; |
| 1077 | 1176 | |
| 1078 | 1177 | case 0x18/8: /* LVRAMP */ |
| 1079 | 1178 | voice->lvramp = (data & 0xff00) >> 8; |
| 1080 | | if (LOG_COMMANDS && eslog) |
| 1081 | | fprintf(eslog, "voice %d, left vol ramp=%04x\n", chip->current_page & 0x1f, voice->lvramp); |
| 1179 | if (LOG_COMMANDS && m_eslog) |
| 1180 | fprintf(m_eslog, "voice %d, left vol ramp=%04x\n", m_current_page & 0x1f, voice->lvramp); |
| 1082 | 1181 | break; |
| 1083 | 1182 | |
| 1084 | 1183 | case 0x20/8: /* RVOL */ |
| 1085 | 1184 | voice->rvol = data & 0xffff; |
| 1086 | | if (LOG_COMMANDS && eslog) |
| 1087 | | fprintf(eslog, "voice %d, right vol=%04x\n", chip->current_page & 0x1f, voice->rvol); |
| 1185 | if (LOG_COMMANDS && m_eslog) |
| 1186 | fprintf(m_eslog, "voice %d, right vol=%04x\n", m_current_page & 0x1f, voice->rvol); |
| 1088 | 1187 | break; |
| 1089 | 1188 | |
| 1090 | 1189 | case 0x28/8: /* RVRAMP */ |
| 1091 | 1190 | voice->rvramp = (data & 0xff00) >> 8; |
| 1092 | | if (LOG_COMMANDS && eslog) |
| 1093 | | fprintf(eslog, "voice %d, right vol ramp=%04x\n", chip->current_page & 0x1f, voice->rvramp); |
| 1191 | if (LOG_COMMANDS && m_eslog) |
| 1192 | fprintf(m_eslog, "voice %d, right vol ramp=%04x\n", m_current_page & 0x1f, voice->rvramp); |
| 1094 | 1193 | break; |
| 1095 | 1194 | |
| 1096 | 1195 | case 0x30/8: /* ECOUNT */ |
| 1097 | 1196 | voice->ecount = data & 0x1ff; |
| 1098 | 1197 | voice->filtcount = 0; |
| 1099 | | if (LOG_COMMANDS && eslog) |
| 1100 | | fprintf(eslog, "voice %d, envelope count=%04x\n", chip->current_page & 0x1f, voice->ecount); |
| 1198 | if (LOG_COMMANDS && m_eslog) |
| 1199 | fprintf(m_eslog, "voice %d, envelope count=%04x\n", m_current_page & 0x1f, voice->ecount); |
| 1101 | 1200 | break; |
| 1102 | 1201 | |
| 1103 | 1202 | case 0x38/8: /* K2 */ |
| 1104 | 1203 | voice->k2 = data & 0xffff; |
| 1105 | | if (LOG_COMMANDS && eslog) |
| 1106 | | fprintf(eslog, "voice %d, K2=%04x\n", chip->current_page & 0x1f, voice->k2); |
| 1204 | if (LOG_COMMANDS && m_eslog) |
| 1205 | fprintf(m_eslog, "voice %d, K2=%04x\n", m_current_page & 0x1f, voice->k2); |
| 1107 | 1206 | break; |
| 1108 | 1207 | |
| 1109 | 1208 | case 0x40/8: /* K2RAMP */ |
| 1110 | 1209 | voice->k2ramp = ((data & 0xff00) >> 8) | ((data & 0x0001) << 31); |
| 1111 | | if (LOG_COMMANDS && eslog) |
| 1112 | | fprintf(eslog, "voice %d, K2 ramp=%04x\n", chip->current_page & 0x1f, voice->k2ramp); |
| 1210 | if (LOG_COMMANDS && m_eslog) |
| 1211 | fprintf(m_eslog, "voice %d, K2 ramp=%04x\n", m_current_page & 0x1f, voice->k2ramp); |
| 1113 | 1212 | break; |
| 1114 | 1213 | |
| 1115 | 1214 | case 0x48/8: /* K1 */ |
| 1116 | 1215 | voice->k1 = data & 0xffff; |
| 1117 | | if (LOG_COMMANDS && eslog) |
| 1118 | | fprintf(eslog, "voice %d, K1=%04x\n", chip->current_page & 0x1f, voice->k1); |
| 1216 | if (LOG_COMMANDS && m_eslog) |
| 1217 | fprintf(m_eslog, "voice %d, K1=%04x\n", m_current_page & 0x1f, voice->k1); |
| 1119 | 1218 | break; |
| 1120 | 1219 | |
| 1121 | 1220 | case 0x50/8: /* K1RAMP */ |
| 1122 | 1221 | voice->k1ramp = ((data & 0xff00) >> 8) | ((data & 0x0001) << 31); |
| 1123 | | if (LOG_COMMANDS && eslog) |
| 1124 | | fprintf(eslog, "voice %d, K1 ramp=%04x\n", chip->current_page & 0x1f, voice->k1ramp); |
| 1222 | if (LOG_COMMANDS && m_eslog) |
| 1223 | fprintf(m_eslog, "voice %d, K1 ramp=%04x\n", m_current_page & 0x1f, voice->k1ramp); |
| 1125 | 1224 | break; |
| 1126 | 1225 | |
| 1127 | 1226 | case 0x58/8: /* ACTV */ |
| 1128 | 1227 | { |
| 1129 | | chip->active_voices = data & 0x1f; |
| 1130 | | chip->sample_rate = chip->master_clock / (16 * (chip->active_voices + 1)); |
| 1131 | | chip->stream->set_sample_rate(chip->sample_rate); |
| 1228 | m_active_voices = data & 0x1f; |
| 1229 | m_sample_rate = m_master_clock / (16 * (m_active_voices + 1)); |
| 1230 | m_stream->set_sample_rate(m_sample_rate); |
| 1132 | 1231 | |
| 1133 | | if (LOG_COMMANDS && eslog) |
| 1134 | | fprintf(eslog, "active voices=%d, sample_rate=%d\n", chip->active_voices, chip->sample_rate); |
| 1232 | if (LOG_COMMANDS && m_eslog) |
| 1233 | fprintf(m_eslog, "active voices=%d, sample_rate=%d\n", m_active_voices, m_sample_rate); |
| 1135 | 1234 | break; |
| 1136 | 1235 | } |
| 1137 | 1236 | |
| 1138 | 1237 | case 0x60/8: /* MODE */ |
| 1139 | | chip->mode = data & 0x1f; |
| 1238 | m_mode = data & 0x1f; |
| 1140 | 1239 | break; |
| 1141 | 1240 | |
| 1142 | 1241 | case 0x68/8: /* PAR - read only */ |
| r26107 | r26108 | |
| 1144 | 1243 | break; |
| 1145 | 1244 | |
| 1146 | 1245 | case 0x78/8: /* PAGE */ |
| 1147 | | chip->current_page = data & 0x7f; |
| 1246 | m_current_page = data & 0x7f; |
| 1148 | 1247 | break; |
| 1149 | 1248 | } |
| 1150 | 1249 | } |
| 1151 | 1250 | |
| 1152 | | |
| 1153 | | INLINE void es5506_reg_write_high(es5506_state *chip, es5506_voice *voice, offs_t offset, UINT32 data) |
| 1251 | inline void es5506_device::reg_write_high(es550x_voice *voice, offs_t offset, UINT32 data) |
| 1154 | 1252 | { |
| 1155 | 1253 | switch (offset) |
| 1156 | 1254 | { |
| 1157 | 1255 | case 0x00/8: /* CR */ |
| 1158 | 1256 | voice->control = data & 0xffff; |
| 1159 | | if (LOG_COMMANDS && eslog) |
| 1160 | | fprintf(eslog, "voice %d, control=%04x\n", chip->current_page & 0x1f, voice->control); |
| 1257 | if (LOG_COMMANDS && m_eslog) |
| 1258 | fprintf(m_eslog, "voice %d, control=%04x\n", m_current_page & 0x1f, voice->control); |
| 1161 | 1259 | break; |
| 1162 | 1260 | |
| 1163 | 1261 | case 0x08/8: /* START */ |
| 1164 | 1262 | voice->start = data & 0xfffff800; |
| 1165 | | if (LOG_COMMANDS && eslog) |
| 1166 | | fprintf(eslog, "voice %d, loop start=%08x\n", chip->current_page & 0x1f, voice->start); |
| 1263 | if (LOG_COMMANDS && m_eslog) |
| 1264 | fprintf(m_eslog, "voice %d, loop start=%08x\n", m_current_page & 0x1f, voice->start); |
| 1167 | 1265 | break; |
| 1168 | 1266 | |
| 1169 | 1267 | case 0x10/8: /* END */ |
| 1170 | 1268 | voice->end = data & 0xffffff80; |
| 1171 | | if (LOG_COMMANDS && eslog) |
| 1172 | | fprintf(eslog, "voice %d, loop end=%08x\n", chip->current_page & 0x1f, voice->end); |
| 1269 | if (LOG_COMMANDS && m_eslog) |
| 1270 | fprintf(m_eslog, "voice %d, loop end=%08x\n", m_current_page & 0x1f, voice->end); |
| 1173 | 1271 | break; |
| 1174 | 1272 | |
| 1175 | 1273 | case 0x18/8: /* ACCUM */ |
| 1176 | 1274 | voice->accum = data; |
| 1177 | | if (LOG_COMMANDS && eslog) |
| 1178 | | fprintf(eslog, "voice %d, accum=%08x\n", chip->current_page & 0x1f, voice->accum); |
| 1275 | if (LOG_COMMANDS && m_eslog) |
| 1276 | fprintf(m_eslog, "voice %d, accum=%08x\n", m_current_page & 0x1f, voice->accum); |
| 1179 | 1277 | break; |
| 1180 | 1278 | |
| 1181 | 1279 | case 0x20/8: /* O4(n-1) */ |
| 1182 | 1280 | voice->o4n1 = (INT32)(data << 14) >> 14; |
| 1183 | | if (LOG_COMMANDS && eslog) |
| 1184 | | fprintf(eslog, "voice %d, O4(n-1)=%05x\n", chip->current_page & 0x1f, voice->o4n1 & 0x3ffff); |
| 1281 | if (LOG_COMMANDS && m_eslog) |
| 1282 | fprintf(m_eslog, "voice %d, O4(n-1)=%05x\n", m_current_page & 0x1f, voice->o4n1 & 0x3ffff); |
| 1185 | 1283 | break; |
| 1186 | 1284 | |
| 1187 | 1285 | case 0x28/8: /* O3(n-1) */ |
| 1188 | 1286 | voice->o3n1 = (INT32)(data << 14) >> 14; |
| 1189 | | if (LOG_COMMANDS && eslog) |
| 1190 | | fprintf(eslog, "voice %d, O3(n-1)=%05x\n", chip->current_page & 0x1f, voice->o3n1 & 0x3ffff); |
| 1287 | if (LOG_COMMANDS && m_eslog) |
| 1288 | fprintf(m_eslog, "voice %d, O3(n-1)=%05x\n", m_current_page & 0x1f, voice->o3n1 & 0x3ffff); |
| 1191 | 1289 | break; |
| 1192 | 1290 | |
| 1193 | 1291 | case 0x30/8: /* O3(n-2) */ |
| 1194 | 1292 | voice->o3n2 = (INT32)(data << 14) >> 14; |
| 1195 | | if (LOG_COMMANDS && eslog) |
| 1196 | | fprintf(eslog, "voice %d, O3(n-2)=%05x\n", chip->current_page & 0x1f, voice->o3n2 & 0x3ffff); |
| 1293 | if (LOG_COMMANDS && m_eslog) |
| 1294 | fprintf(m_eslog, "voice %d, O3(n-2)=%05x\n", m_current_page & 0x1f, voice->o3n2 & 0x3ffff); |
| 1197 | 1295 | break; |
| 1198 | 1296 | |
| 1199 | 1297 | case 0x38/8: /* O2(n-1) */ |
| 1200 | 1298 | voice->o2n1 = (INT32)(data << 14) >> 14; |
| 1201 | | if (LOG_COMMANDS && eslog) |
| 1202 | | fprintf(eslog, "voice %d, O2(n-1)=%05x\n", chip->current_page & 0x1f, voice->o2n1 & 0x3ffff); |
| 1299 | if (LOG_COMMANDS && m_eslog) |
| 1300 | fprintf(m_eslog, "voice %d, O2(n-1)=%05x\n", m_current_page & 0x1f, voice->o2n1 & 0x3ffff); |
| 1203 | 1301 | break; |
| 1204 | 1302 | |
| 1205 | 1303 | case 0x40/8: /* O2(n-2) */ |
| 1206 | 1304 | voice->o2n2 = (INT32)(data << 14) >> 14; |
| 1207 | | if (LOG_COMMANDS && eslog) |
| 1208 | | fprintf(eslog, "voice %d, O2(n-2)=%05x\n", chip->current_page & 0x1f, voice->o2n2 & 0x3ffff); |
| 1305 | if (LOG_COMMANDS && m_eslog) |
| 1306 | fprintf(m_eslog, "voice %d, O2(n-2)=%05x\n", m_current_page & 0x1f, voice->o2n2 & 0x3ffff); |
| 1209 | 1307 | break; |
| 1210 | 1308 | |
| 1211 | 1309 | case 0x48/8: /* O1(n-1) */ |
| 1212 | 1310 | voice->o1n1 = (INT32)(data << 14) >> 14; |
| 1213 | | if (LOG_COMMANDS && eslog) |
| 1214 | | fprintf(eslog, "voice %d, O1(n-1)=%05x\n", chip->current_page & 0x1f, voice->o1n1 & 0x3ffff); |
| 1311 | if (LOG_COMMANDS && m_eslog) |
| 1312 | fprintf(m_eslog, "voice %d, O1(n-1)=%05x\n", m_current_page & 0x1f, voice->o1n1 & 0x3ffff); |
| 1215 | 1313 | break; |
| 1216 | 1314 | |
| 1217 | 1315 | case 0x50/8: /* W_ST */ |
| 1218 | | chip->wst = data & 0x7f; |
| 1316 | m_wst = data & 0x7f; |
| 1219 | 1317 | break; |
| 1220 | 1318 | |
| 1221 | 1319 | case 0x58/8: /* W_END */ |
| 1222 | | chip->wend = data & 0x7f; |
| 1320 | m_wend = data & 0x7f; |
| 1223 | 1321 | break; |
| 1224 | 1322 | |
| 1225 | 1323 | case 0x60/8: /* LR_END */ |
| 1226 | | chip->lrend = data & 0x7f; |
| 1324 | m_lrend = data & 0x7f; |
| 1227 | 1325 | break; |
| 1228 | 1326 | |
| 1229 | 1327 | case 0x68/8: /* PAR - read only */ |
| r26107 | r26108 | |
| 1231 | 1329 | break; |
| 1232 | 1330 | |
| 1233 | 1331 | case 0x78/8: /* PAGE */ |
| 1234 | | chip->current_page = data & 0x7f; |
| 1332 | m_current_page = data & 0x7f; |
| 1235 | 1333 | break; |
| 1236 | 1334 | } |
| 1237 | 1335 | } |
| 1238 | 1336 | |
| 1239 | | INLINE void es5506_reg_write_test(es5506_state *chip, es5506_voice *voice, offs_t offset, UINT32 data) |
| 1337 | inline void es5506_device::reg_write_test(es550x_voice *voice, offs_t offset, UINT32 data) |
| 1240 | 1338 | { |
| 1241 | 1339 | switch (offset) |
| 1242 | 1340 | { |
| 1243 | 1341 | case 0x00/8: /* CHANNEL 0 LEFT */ |
| 1244 | | if (LOG_COMMANDS && eslog) |
| 1245 | | fprintf(eslog, "Channel 0 left test write %08x\n", data); |
| 1342 | if (LOG_COMMANDS && m_eslog) |
| 1343 | fprintf(m_eslog, "Channel 0 left test write %08x\n", data); |
| 1246 | 1344 | break; |
| 1247 | 1345 | |
| 1248 | 1346 | case 0x08/8: /* CHANNEL 0 RIGHT */ |
| 1249 | | if (LOG_COMMANDS && eslog) |
| 1250 | | fprintf(eslog, "Channel 0 right test write %08x\n", data); |
| 1347 | if (LOG_COMMANDS && m_eslog) |
| 1348 | fprintf(m_eslog, "Channel 0 right test write %08x\n", data); |
| 1251 | 1349 | break; |
| 1252 | 1350 | |
| 1253 | 1351 | case 0x10/8: /* CHANNEL 1 LEFT */ |
| 1254 | | if (LOG_COMMANDS && eslog) |
| 1255 | | fprintf(eslog, "Channel 1 left test write %08x\n", data); |
| 1352 | if (LOG_COMMANDS && m_eslog) |
| 1353 | fprintf(m_eslog, "Channel 1 left test write %08x\n", data); |
| 1256 | 1354 | break; |
| 1257 | 1355 | |
| 1258 | 1356 | case 0x18/8: /* CHANNEL 1 RIGHT */ |
| 1259 | | if (LOG_COMMANDS && eslog) |
| 1260 | | fprintf(eslog, "Channel 1 right test write %08x\n", data); |
| 1357 | if (LOG_COMMANDS && m_eslog) |
| 1358 | fprintf(m_eslog, "Channel 1 right test write %08x\n", data); |
| 1261 | 1359 | break; |
| 1262 | 1360 | |
| 1263 | 1361 | case 0x20/8: /* CHANNEL 2 LEFT */ |
| 1264 | | if (LOG_COMMANDS && eslog) |
| 1265 | | fprintf(eslog, "Channel 2 left test write %08x\n", data); |
| 1362 | if (LOG_COMMANDS && m_eslog) |
| 1363 | fprintf(m_eslog, "Channel 2 left test write %08x\n", data); |
| 1266 | 1364 | break; |
| 1267 | 1365 | |
| 1268 | 1366 | case 0x28/8: /* CHANNEL 2 RIGHT */ |
| 1269 | | if (LOG_COMMANDS && eslog) |
| 1270 | | fprintf(eslog, "Channel 2 right test write %08x\n", data); |
| 1367 | if (LOG_COMMANDS && m_eslog) |
| 1368 | fprintf(m_eslog, "Channel 2 right test write %08x\n", data); |
| 1271 | 1369 | break; |
| 1272 | 1370 | |
| 1273 | 1371 | case 0x30/8: /* CHANNEL 3 LEFT */ |
| 1274 | | if (LOG_COMMANDS && eslog) |
| 1275 | | fprintf(eslog, "Channel 3 left test write %08x\n", data); |
| 1372 | if (LOG_COMMANDS && m_eslog) |
| 1373 | fprintf(m_eslog, "Channel 3 left test write %08x\n", data); |
| 1276 | 1374 | break; |
| 1277 | 1375 | |
| 1278 | 1376 | case 0x38/8: /* CHANNEL 3 RIGHT */ |
| 1279 | | if (LOG_COMMANDS && eslog) |
| 1280 | | fprintf(eslog, "Channel 3 right test write %08x\n", data); |
| 1377 | if (LOG_COMMANDS && m_eslog) |
| 1378 | fprintf(m_eslog, "Channel 3 right test write %08x\n", data); |
| 1281 | 1379 | break; |
| 1282 | 1380 | |
| 1283 | 1381 | case 0x40/8: /* CHANNEL 4 LEFT */ |
| 1284 | | if (LOG_COMMANDS && eslog) |
| 1285 | | fprintf(eslog, "Channel 4 left test write %08x\n", data); |
| 1382 | if (LOG_COMMANDS && m_eslog) |
| 1383 | fprintf(m_eslog, "Channel 4 left test write %08x\n", data); |
| 1286 | 1384 | break; |
| 1287 | 1385 | |
| 1288 | 1386 | case 0x48/8: /* CHANNEL 4 RIGHT */ |
| 1289 | | if (LOG_COMMANDS && eslog) |
| 1290 | | fprintf(eslog, "Channel 4 right test write %08x\n", data); |
| 1387 | if (LOG_COMMANDS && m_eslog) |
| 1388 | fprintf(m_eslog, "Channel 4 right test write %08x\n", data); |
| 1291 | 1389 | break; |
| 1292 | 1390 | |
| 1293 | 1391 | case 0x50/8: /* CHANNEL 5 LEFT */ |
| 1294 | | if (LOG_COMMANDS && eslog) |
| 1295 | | fprintf(eslog, "Channel 5 left test write %08x\n", data); |
| 1392 | if (LOG_COMMANDS && m_eslog) |
| 1393 | fprintf(m_eslog, "Channel 5 left test write %08x\n", data); |
| 1296 | 1394 | break; |
| 1297 | 1395 | |
| 1298 | 1396 | case 0x58/8: /* CHANNEL 6 RIGHT */ |
| 1299 | | if (LOG_COMMANDS && eslog) |
| 1300 | | fprintf(eslog, "Channel 5 right test write %08x\n", data); |
| 1397 | if (LOG_COMMANDS && m_eslog) |
| 1398 | fprintf(m_eslog, "Channel 5 right test write %08x\n", data); |
| 1301 | 1399 | break; |
| 1302 | 1400 | |
| 1303 | 1401 | case 0x60/8: /* EMPTY */ |
| 1304 | | if (LOG_COMMANDS && eslog) |
| 1305 | | fprintf(eslog, "Test write EMPTY %08x\n", data); |
| 1402 | if (LOG_COMMANDS && m_eslog) |
| 1403 | fprintf(m_eslog, "Test write EMPTY %08x\n", data); |
| 1306 | 1404 | break; |
| 1307 | 1405 | |
| 1308 | 1406 | case 0x68/8: /* PAR - read only */ |
| r26107 | r26108 | |
| 1310 | 1408 | break; |
| 1311 | 1409 | |
| 1312 | 1410 | case 0x78/8: /* PAGE */ |
| 1313 | | chip->current_page = data & 0x7f; |
| 1411 | m_current_page = data & 0x7f; |
| 1314 | 1412 | break; |
| 1315 | 1413 | } |
| 1316 | 1414 | } |
| 1317 | 1415 | |
| 1318 | | WRITE8_DEVICE_HANDLER( es5506_w ) |
| 1416 | WRITE8_MEMBER( es5506_device::write ) |
| 1319 | 1417 | { |
| 1320 | | es5506_state *chip = get_safe_token(device); |
| 1321 | | es5506_voice *voice = &chip->voice[chip->current_page & 0x1f]; |
| 1418 | es550x_voice *voice = &m_voice[m_current_page & 0x1f]; |
| 1322 | 1419 | int shift = 8 * (offset & 3); |
| 1323 | 1420 | |
| 1324 | 1421 | /* accumulate the data */ |
| 1325 | | chip->write_latch = (chip->write_latch & ~(0xff000000 >> shift)) | (data << (24 - shift)); |
| 1422 | m_write_latch = (m_write_latch & ~(0xff000000 >> shift)) | (data << (24 - shift)); |
| 1326 | 1423 | |
| 1327 | 1424 | /* wait for a write to complete */ |
| 1328 | 1425 | if (shift != 24) |
| 1329 | 1426 | return; |
| 1330 | 1427 | |
| 1331 | 1428 | /* force an update */ |
| 1332 | | chip->stream->update(); |
| 1429 | m_stream->update(); |
| 1333 | 1430 | |
| 1334 | 1431 | /* switch off the page and register */ |
| 1335 | | if (chip->current_page < 0x20) |
| 1336 | | es5506_reg_write_low(chip, voice, offset / 4, chip->write_latch); |
| 1337 | | else if (chip->current_page < 0x40) |
| 1338 | | es5506_reg_write_high(chip, voice, offset / 4, chip->write_latch); |
| 1432 | if (m_current_page < 0x20) |
| 1433 | reg_write_low(voice, offset / 4, m_write_latch); |
| 1434 | else if (m_current_page < 0x40) |
| 1435 | reg_write_high(voice, offset / 4, m_write_latch); |
| 1339 | 1436 | else |
| 1340 | | es5506_reg_write_test(chip, voice, offset / 4, chip->write_latch); |
| 1437 | reg_write_test(voice, offset / 4, m_write_latch); |
| 1341 | 1438 | |
| 1342 | 1439 | /* clear the write latch when done */ |
| 1343 | | chip->write_latch = 0; |
| 1440 | m_write_latch = 0; |
| 1344 | 1441 | } |
| 1345 | 1442 | |
| 1346 | 1443 | |
| 1347 | 1444 | |
| 1348 | 1445 | /********************************************************************************************** |
| 1349 | 1446 | |
| 1350 | | es5506_reg_read -- read from the specified ES5506 register |
| 1447 | reg_read -- read from the specified ES5506 register |
| 1351 | 1448 | |
| 1352 | 1449 | ***********************************************************************************************/ |
| 1353 | 1450 | |
| 1354 | | INLINE UINT32 es5506_reg_read_low(es5506_state *chip, es5506_voice *voice, offs_t offset) |
| 1451 | inline UINT32 es5506_device::reg_read_low(es550x_voice *voice, offs_t offset) |
| 1355 | 1452 | { |
| 1356 | 1453 | UINT32 result = 0; |
| 1357 | 1454 | |
| r26107 | r26108 | |
| 1402 | 1499 | break; |
| 1403 | 1500 | |
| 1404 | 1501 | case 0x58/8: /* ACTV */ |
| 1405 | | result = chip->active_voices; |
| 1502 | result = m_active_voices; |
| 1406 | 1503 | break; |
| 1407 | 1504 | |
| 1408 | 1505 | case 0x60/8: /* MODE */ |
| 1409 | | result = chip->mode; |
| 1506 | result = m_mode; |
| 1410 | 1507 | break; |
| 1411 | 1508 | |
| 1412 | 1509 | case 0x68/8: /* PAR */ |
| 1413 | | if (!chip->port_read.isnull()) |
| 1414 | | result = chip->port_read(0); |
| 1510 | if (!m_port_read_func.isnull()) |
| 1511 | result = m_port_read_func(0); |
| 1415 | 1512 | break; |
| 1416 | 1513 | |
| 1417 | 1514 | case 0x70/8: /* IRQV */ |
| 1418 | | result = chip->irqv; |
| 1419 | | update_internal_irq_state(chip); |
| 1515 | result = m_irqv; |
| 1516 | update_internal_irq_state(); |
| 1420 | 1517 | break; |
| 1421 | 1518 | |
| 1422 | 1519 | case 0x78/8: /* PAGE */ |
| 1423 | | result = chip->current_page; |
| 1520 | result = m_current_page; |
| 1424 | 1521 | break; |
| 1425 | 1522 | } |
| 1426 | 1523 | return result; |
| 1427 | 1524 | } |
| 1428 | 1525 | |
| 1429 | 1526 | |
| 1430 | | INLINE UINT32 es5506_reg_read_high(es5506_state *chip, es5506_voice *voice, offs_t offset) |
| 1527 | inline UINT32 es5506_device::reg_read_high(es550x_voice *voice, offs_t offset) |
| 1431 | 1528 | { |
| 1432 | 1529 | UINT32 result = 0; |
| 1433 | 1530 | |
| r26107 | r26108 | |
| 1474 | 1571 | break; |
| 1475 | 1572 | |
| 1476 | 1573 | case 0x50/8: /* W_ST */ |
| 1477 | | result = chip->wst; |
| 1574 | result = m_wst; |
| 1478 | 1575 | break; |
| 1479 | 1576 | |
| 1480 | 1577 | case 0x58/8: /* W_END */ |
| 1481 | | result = chip->wend; |
| 1578 | result = m_wend; |
| 1482 | 1579 | break; |
| 1483 | 1580 | |
| 1484 | 1581 | case 0x60/8: /* LR_END */ |
| 1485 | | result = chip->lrend; |
| 1582 | result = m_lrend; |
| 1486 | 1583 | break; |
| 1487 | 1584 | |
| 1488 | 1585 | case 0x68/8: /* PAR */ |
| 1489 | | if (!chip->port_read.isnull()) |
| 1490 | | result = chip->port_read(0); |
| 1586 | if (!m_port_read_func.isnull()) |
| 1587 | result = m_port_read_func(0); |
| 1491 | 1588 | break; |
| 1492 | 1589 | |
| 1493 | 1590 | case 0x70/8: /* IRQV */ |
| 1494 | | result = chip->irqv; |
| 1495 | | update_internal_irq_state(chip); |
| 1591 | result = m_irqv; |
| 1592 | update_internal_irq_state(); |
| 1496 | 1593 | break; |
| 1497 | 1594 | |
| 1498 | 1595 | case 0x78/8: /* PAGE */ |
| 1499 | | result = chip->current_page; |
| 1596 | result = m_current_page; |
| 1500 | 1597 | break; |
| 1501 | 1598 | } |
| 1502 | 1599 | return result; |
| 1503 | 1600 | } |
| 1504 | | |
| 1505 | | INLINE UINT32 es5506_reg_read_test(es5506_state *chip, es5506_voice *voice, offs_t offset) |
| 1601 | inline UINT32 es5506_device::reg_read_test(es550x_voice *voice, offs_t offset) |
| 1506 | 1602 | { |
| 1507 | 1603 | UINT32 result = 0; |
| 1508 | 1604 | |
| 1509 | 1605 | switch (offset) |
| 1510 | 1606 | { |
| 1511 | 1607 | case 0x68/8: /* PAR */ |
| 1512 | | if (!chip->port_read.isnull()) |
| 1513 | | result = chip->port_read(0); |
| 1608 | if (!m_port_read_func.isnull()) |
| 1609 | result = m_port_read_func(0); |
| 1514 | 1610 | break; |
| 1515 | 1611 | |
| 1516 | 1612 | case 0x70/8: /* IRQV */ |
| 1517 | | result = chip->irqv; |
| 1613 | result = m_irqv; |
| 1518 | 1614 | break; |
| 1519 | 1615 | |
| 1520 | 1616 | case 0x78/8: /* PAGE */ |
| 1521 | | result = chip->current_page; |
| 1617 | result = m_current_page; |
| 1522 | 1618 | break; |
| 1523 | 1619 | } |
| 1524 | 1620 | return result; |
| 1525 | 1621 | } |
| 1526 | 1622 | |
| 1527 | | READ8_DEVICE_HANDLER( es5506_r ) |
| 1623 | READ8_MEMBER( es5506_device::read ) |
| 1528 | 1624 | { |
| 1529 | | es5506_state *chip = get_safe_token(device); |
| 1530 | | es5506_voice *voice = &chip->voice[chip->current_page & 0x1f]; |
| 1625 | es550x_voice *voice = &m_voice[m_current_page & 0x1f]; |
| 1531 | 1626 | int shift = 8 * (offset & 3); |
| 1532 | 1627 | |
| 1533 | 1628 | /* only read on offset 0 */ |
| 1534 | 1629 | if (shift != 0) |
| 1535 | | return chip->read_latch >> (24 - shift); |
| 1630 | return m_read_latch >> (24 - shift); |
| 1536 | 1631 | |
| 1537 | | if (LOG_COMMANDS && eslog) |
| 1538 | | fprintf(eslog, "read from %02x/%02x -> ", chip->current_page, offset / 4 * 8); |
| 1632 | if (LOG_COMMANDS && m_eslog) |
| 1633 | fprintf(m_eslog, "read from %02x/%02x -> ", m_current_page, offset / 4 * 8); |
| 1539 | 1634 | |
| 1540 | 1635 | /* force an update */ |
| 1541 | | chip->stream->update(); |
| 1636 | m_stream->update(); |
| 1542 | 1637 | |
| 1543 | 1638 | /* switch off the page and register */ |
| 1544 | | if (chip->current_page < 0x20) |
| 1545 | | chip->read_latch = es5506_reg_read_low(chip, voice, offset / 4); |
| 1546 | | else if (chip->current_page < 0x40) |
| 1547 | | chip->read_latch = es5506_reg_read_high(chip, voice, offset / 4); |
| 1639 | if (m_current_page < 0x20) |
| 1640 | m_read_latch = reg_read_low(voice, offset / 4); |
| 1641 | else if (m_current_page < 0x40) |
| 1642 | m_read_latch = reg_read_high(voice, offset / 4); |
| 1548 | 1643 | else |
| 1549 | | chip->read_latch = es5506_reg_read_test(chip, voice, offset / 4); |
| 1644 | m_read_latch = reg_read_test(voice, offset / 4); |
| 1550 | 1645 | |
| 1551 | | if (LOG_COMMANDS && eslog) |
| 1552 | | fprintf(eslog, "%08x\n", chip->read_latch); |
| 1646 | if (LOG_COMMANDS && m_eslog) |
| 1647 | fprintf(m_eslog, "%08x\n", m_read_latch); |
| 1553 | 1648 | |
| 1554 | 1649 | /* return the high byte */ |
| 1555 | | return chip->read_latch >> 24; |
| 1650 | return m_read_latch >> 24; |
| 1556 | 1651 | } |
| 1557 | 1652 | |
| 1558 | 1653 | |
| 1559 | 1654 | |
| 1560 | | void es5506_voice_bank_w(device_t *device, int voice, int bank) |
| 1655 | void es5506_device::voice_bank_w(int voice, int bank) |
| 1561 | 1656 | { |
| 1562 | | es5506_state *chip = get_safe_token(device); |
| 1563 | | chip->voice[voice].exbank=bank; |
| 1657 | m_voice[voice].exbank=bank; |
| 1564 | 1658 | } |
| 1565 | 1659 | |
| 1566 | 1660 | |
| 1567 | 1661 | /********************************************************************************************** |
| 1568 | 1662 | |
| 1569 | | DEVICE_START( es5505 ) -- start emulation of the ES5505 |
| 1663 | reg_write -- handle a write to the selected ES5505 register |
| 1570 | 1664 | |
| 1571 | 1665 | ***********************************************************************************************/ |
| 1572 | 1666 | |
| 1573 | | static DEVICE_START( es5505 ) |
| 1667 | inline void es5505_device::reg_write_low(es550x_voice *voice, offs_t offset, UINT16 data, UINT16 mem_mask) |
| 1574 | 1668 | { |
| 1575 | | const es5505_interface *intf = (const es5505_interface *)device->static_config(); |
| 1576 | | es5506_interface es5506intf; |
| 1577 | | int channels = 1; /* 1 channel by default, for backward compatibility */ |
| 1578 | | |
| 1579 | | /* only override the number of channels if the value is in the valid range 1 .. 4 */ |
| 1580 | | if (1 <= intf->channels && intf->channels <= 4) |
| 1581 | | channels = intf->channels; |
| 1582 | | |
| 1583 | | memset(&es5506intf, 0, sizeof(es5506intf)); |
| 1584 | | |
| 1585 | | es5506intf.region0 = intf->region0; |
| 1586 | | es5506intf.region1 = intf->region1; |
| 1587 | | es5506intf.channels = channels; |
| 1588 | | es5506intf.irq_callback = intf->irq_callback; |
| 1589 | | es5506intf.read_port = intf->read_port; |
| 1590 | | |
| 1591 | | es5506_start_common(device, &es5506intf, ES5505); |
| 1592 | | } |
| 1593 | | |
| 1594 | | |
| 1595 | | /********************************************************************************************** |
| 1596 | | |
| 1597 | | es5505_reg_write -- handle a write to the selected ES5505 register |
| 1598 | | |
| 1599 | | ***********************************************************************************************/ |
| 1600 | | |
| 1601 | | INLINE void es5505_reg_write_low(es5506_state *chip, es5506_voice *voice, offs_t offset, UINT16 data, UINT16 mem_mask) |
| 1602 | | { |
| 1603 | | running_machine &machine = chip->device->machine(); |
| 1604 | | |
| 1605 | 1669 | switch (offset) |
| 1606 | 1670 | { |
| 1607 | 1671 | case 0x00: /* CR */ |
| r26107 | r26108 | |
| 1622 | 1686 | ((data << 2) & (CONTROL_CA0 | CONTROL_CA1)); |
| 1623 | 1687 | } |
| 1624 | 1688 | |
| 1625 | | if (LOG_COMMANDS && eslog) |
| 1626 | | fprintf(eslog, "%s:voice %d, control=%04x (raw=%04x & %04x)\n", machine.describe_context(), chip->current_page & 0x1f, voice->control, data, mem_mask ^ 0xffff); |
| 1689 | if (LOG_COMMANDS && m_eslog) |
| 1690 | fprintf(m_eslog, "%s:voice %d, control=%04x (raw=%04x & %04x)\n", machine().describe_context(), m_current_page & 0x1f, voice->control, data, mem_mask ^ 0xffff); |
| 1627 | 1691 | break; |
| 1628 | 1692 | |
| 1629 | 1693 | case 0x01: /* FC */ |
| r26107 | r26108 | |
| 1631 | 1695 | voice->freqcount = (voice->freqcount & ~0x001fe) | ((data & 0x00ff) << 1); |
| 1632 | 1696 | if (ACCESSING_BITS_8_15) |
| 1633 | 1697 | voice->freqcount = (voice->freqcount & ~0x1fe00) | ((data & 0xff00) << 1); |
| 1634 | | if (LOG_COMMANDS && eslog) |
| 1635 | | fprintf(eslog, "%s:voice %d, freq count=%08x\n", machine.describe_context(), chip->current_page & 0x1f, voice->freqcount); |
| 1698 | if (LOG_COMMANDS && m_eslog) |
| 1699 | fprintf(m_eslog, "%s:voice %d, freq count=%08x\n", machine().describe_context(), m_current_page & 0x1f, voice->freqcount); |
| 1636 | 1700 | break; |
| 1637 | 1701 | |
| 1638 | 1702 | case 0x02: /* STRT (hi) */ |
| r26107 | r26108 | |
| 1640 | 1704 | voice->start = (voice->start & ~0x03fc0000) | ((data & 0x00ff) << 18); |
| 1641 | 1705 | if (ACCESSING_BITS_8_15) |
| 1642 | 1706 | voice->start = (voice->start & ~0x7c000000) | ((data & 0x1f00) << 18); |
| 1643 | | if (LOG_COMMANDS && eslog) |
| 1644 | | fprintf(eslog, "%s:voice %d, loop start=%08x\n", machine.describe_context(), chip->current_page & 0x1f, voice->start); |
| 1707 | if (LOG_COMMANDS && m_eslog) |
| 1708 | fprintf(m_eslog, "%s:voice %d, loop start=%08x\n", machine().describe_context(), m_current_page & 0x1f, voice->start); |
| 1645 | 1709 | break; |
| 1646 | 1710 | |
| 1647 | 1711 | case 0x03: /* STRT (lo) */ |
| r26107 | r26108 | |
| 1649 | 1713 | voice->start = (voice->start & ~0x00000380) | ((data & 0x00e0) << 2); |
| 1650 | 1714 | if (ACCESSING_BITS_8_15) |
| 1651 | 1715 | voice->start = (voice->start & ~0x0003fc00) | ((data & 0xff00) << 2); |
| 1652 | | if (LOG_COMMANDS && eslog) |
| 1653 | | fprintf(eslog, "%s:voice %d, loop start=%08x\n", machine.describe_context(), chip->current_page & 0x1f, voice->start); |
| 1716 | if (LOG_COMMANDS && m_eslog) |
| 1717 | fprintf(m_eslog, "%s:voice %d, loop start=%08x\n", machine().describe_context(), m_current_page & 0x1f, voice->start); |
| 1654 | 1718 | break; |
| 1655 | 1719 | |
| 1656 | 1720 | case 0x04: /* END (hi) */ |
| r26107 | r26108 | |
| 1661 | 1725 | #if RAINE_CHECK |
| 1662 | 1726 | voice->control |= CONTROL_STOP0; |
| 1663 | 1727 | #endif |
| 1664 | | if (LOG_COMMANDS && eslog) |
| 1665 | | fprintf(eslog, "%s:voice %d, loop end=%08x\n", machine.describe_context(), chip->current_page & 0x1f, voice->end); |
| 1728 | if (LOG_COMMANDS && m_eslog) |
| 1729 | fprintf(m_eslog, "%s:voice %d, loop end=%08x\n", machine().describe_context(), m_current_page & 0x1f, voice->end); |
| 1666 | 1730 | break; |
| 1667 | 1731 | |
| 1668 | 1732 | case 0x05: /* END (lo) */ |
| r26107 | r26108 | |
| 1673 | 1737 | #if RAINE_CHECK |
| 1674 | 1738 | voice->control |= CONTROL_STOP0; |
| 1675 | 1739 | #endif |
| 1676 | | if (LOG_COMMANDS && eslog) |
| 1677 | | fprintf(eslog, "%s:voice %d, loop end=%08x\n", machine.describe_context(), chip->current_page & 0x1f, voice->end); |
| 1740 | if (LOG_COMMANDS && m_eslog) |
| 1741 | fprintf(m_eslog, "%s:voice %d, loop end=%08x\n", machine().describe_context(), m_current_page & 0x1f, voice->end); |
| 1678 | 1742 | break; |
| 1679 | 1743 | |
| 1680 | 1744 | case 0x06: /* K2 */ |
| r26107 | r26108 | |
| 1682 | 1746 | voice->k2 = (voice->k2 & ~0x00f0) | (data & 0x00f0); |
| 1683 | 1747 | if (ACCESSING_BITS_8_15) |
| 1684 | 1748 | voice->k2 = (voice->k2 & ~0xff00) | (data & 0xff00); |
| 1685 | | if (LOG_COMMANDS && eslog) |
| 1686 | | fprintf(eslog, "%s:voice %d, K2=%04x\n", machine.describe_context(), chip->current_page & 0x1f, voice->k2); |
| 1749 | if (LOG_COMMANDS && m_eslog) |
| 1750 | fprintf(m_eslog, "%s:voice %d, K2=%04x\n", machine().describe_context(), m_current_page & 0x1f, voice->k2); |
| 1687 | 1751 | break; |
| 1688 | 1752 | |
| 1689 | 1753 | case 0x07: /* K1 */ |
| r26107 | r26108 | |
| 1691 | 1755 | voice->k1 = (voice->k1 & ~0x00f0) | (data & 0x00f0); |
| 1692 | 1756 | if (ACCESSING_BITS_8_15) |
| 1693 | 1757 | voice->k1 = (voice->k1 & ~0xff00) | (data & 0xff00); |
| 1694 | | if (LOG_COMMANDS && eslog) |
| 1695 | | fprintf(eslog, "%s:voice %d, K1=%04x\n", machine.describe_context(), chip->current_page & 0x1f, voice->k1); |
| 1758 | if (LOG_COMMANDS && m_eslog) |
| 1759 | fprintf(m_eslog, "%s:voice %d, K1=%04x\n", machine().describe_context(), m_current_page & 0x1f, voice->k1); |
| 1696 | 1760 | break; |
| 1697 | 1761 | |
| 1698 | 1762 | case 0x08: /* LVOL */ |
| 1699 | 1763 | if (ACCESSING_BITS_8_15) |
| 1700 | 1764 | voice->lvol = (voice->lvol & ~0xff00) | (data & 0xff00); |
| 1701 | | if (LOG_COMMANDS && eslog) |
| 1702 | | fprintf(eslog, "%s:voice %d, left vol=%04x\n", machine.describe_context(), chip->current_page & 0x1f, voice->lvol); |
| 1765 | if (LOG_COMMANDS && m_eslog) |
| 1766 | fprintf(m_eslog, "%s:voice %d, left vol=%04x\n", machine().describe_context(), m_current_page & 0x1f, voice->lvol); |
| 1703 | 1767 | break; |
| 1704 | 1768 | |
| 1705 | 1769 | case 0x09: /* RVOL */ |
| 1706 | 1770 | if (ACCESSING_BITS_8_15) |
| 1707 | 1771 | voice->rvol = (voice->rvol & ~0xff00) | (data & 0xff00); |
| 1708 | | if (LOG_COMMANDS && eslog) |
| 1709 | | fprintf(eslog, "%s:voice %d, right vol=%04x\n", machine.describe_context(), chip->current_page & 0x1f, voice->rvol); |
| 1772 | if (LOG_COMMANDS && m_eslog) |
| 1773 | fprintf(m_eslog, "%s:voice %d, right vol=%04x\n", machine().describe_context(), m_current_page & 0x1f, voice->rvol); |
| 1710 | 1774 | break; |
| 1711 | 1775 | |
| 1712 | 1776 | case 0x0a: /* ACC (hi) */ |
| r26107 | r26108 | |
| 1714 | 1778 | voice->accum = (voice->accum & ~0x03fc0000) | ((data & 0x00ff) << 18); |
| 1715 | 1779 | if (ACCESSING_BITS_8_15) |
| 1716 | 1780 | voice->accum = (voice->accum & ~0x7c000000) | ((data & 0x1f00) << 18); |
| 1717 | | if (LOG_COMMANDS && eslog) |
| 1718 | | fprintf(eslog, "%s:voice %d, accum=%08x\n", machine.describe_context(), chip->current_page & 0x1f, voice->accum); |
| 1781 | if (LOG_COMMANDS && m_eslog) |
| 1782 | fprintf(m_eslog, "%s:voice %d, accum=%08x\n", machine().describe_context(), m_current_page & 0x1f, voice->accum); |
| 1719 | 1783 | break; |
| 1720 | 1784 | |
| 1721 | 1785 | case 0x0b: /* ACC (lo) */ |
| r26107 | r26108 | |
| 1723 | 1787 | voice->accum = (voice->accum & ~0x000003fc) | ((data & 0x00ff) << 2); |
| 1724 | 1788 | if (ACCESSING_BITS_8_15) |
| 1725 | 1789 | voice->accum = (voice->accum & ~0x0003fc00) | ((data & 0xff00) << 2); |
| 1726 | | if (LOG_COMMANDS && eslog) |
| 1727 | | fprintf(eslog, "%s:voice %d, accum=%08x\n", machine.describe_context(), chip->current_page & 0x1f, voice->accum); |
| 1790 | if (LOG_COMMANDS && m_eslog) |
| 1791 | fprintf(m_eslog, "%s:voice %d, accum=%08x\n", machine().describe_context(), m_current_page & 0x1f, voice->accum); |
| 1728 | 1792 | break; |
| 1729 | 1793 | |
| 1730 | 1794 | case 0x0c: /* unused */ |
| r26107 | r26108 | |
| 1733 | 1797 | case 0x0d: /* ACT */ |
| 1734 | 1798 | if (ACCESSING_BITS_0_7) |
| 1735 | 1799 | { |
| 1736 | | chip->active_voices = data & 0x1f; |
| 1737 | | chip->sample_rate = chip->master_clock / (16 * (chip->active_voices + 1)); |
| 1738 | | chip->stream->set_sample_rate(chip->sample_rate); |
| 1800 | m_active_voices = data & 0x1f; |
| 1801 | m_sample_rate = m_master_clock / (16 * (m_active_voices + 1)); |
| 1802 | m_stream->set_sample_rate(m_sample_rate); |
| 1739 | 1803 | |
| 1740 | | if (LOG_COMMANDS && eslog) |
| 1741 | | fprintf(eslog, "active voices=%d, sample_rate=%d\n", chip->active_voices, chip->sample_rate); |
| 1804 | if (LOG_COMMANDS && m_eslog) |
| 1805 | fprintf(m_eslog, "active voices=%d, sample_rate=%d\n", m_active_voices, m_sample_rate); |
| 1742 | 1806 | } |
| 1743 | 1807 | break; |
| 1744 | 1808 | |
| r26107 | r26108 | |
| 1747 | 1811 | |
| 1748 | 1812 | case 0x0f: /* PAGE */ |
| 1749 | 1813 | if (ACCESSING_BITS_0_7) |
| 1750 | | chip->current_page = data & 0x7f; |
| 1814 | m_current_page = data & 0x7f; |
| 1751 | 1815 | break; |
| 1752 | 1816 | } |
| 1753 | 1817 | } |
| 1754 | 1818 | |
| 1755 | 1819 | |
| 1756 | | INLINE void es5505_reg_write_high(es5506_state *chip, es5506_voice *voice, offs_t offset, UINT16 data, UINT16 mem_mask) |
| 1820 | inline void es5505_device::reg_write_high(es550x_voice *voice, offs_t offset, UINT16 data, UINT16 mem_mask) |
| 1757 | 1821 | { |
| 1758 | | running_machine &machine = chip->device->machine(); |
| 1759 | | |
| 1760 | 1822 | switch (offset) |
| 1761 | 1823 | { |
| 1762 | 1824 | case 0x00: /* CR */ |
| r26107 | r26108 | |
| 1772 | 1834 | voice->control |= ((data >> 2) & CONTROL_LPMASK) | |
| 1773 | 1835 | ((data << 2) & (CONTROL_CA0 | CONTROL_CA1)); |
| 1774 | 1836 | } |
| 1775 | | if (LOG_COMMANDS && eslog) |
| 1776 | | fprintf(eslog, "%s:voice %d, control=%04x (raw=%04x & %04x)\n", machine.describe_context(), chip->current_page & 0x1f, voice->control, data, mem_mask); |
| 1837 | if (LOG_COMMANDS && m_eslog) |
| 1838 | fprintf(m_eslog, "%s:voice %d, control=%04x (raw=%04x & %04x)\n", machine().describe_context(), m_current_page & 0x1f, voice->control, data, mem_mask); |
| 1777 | 1839 | break; |
| 1778 | 1840 | |
| 1779 | 1841 | case 0x01: /* O4(n-1) */ |
| r26107 | r26108 | |
| 1781 | 1843 | voice->o4n1 = (voice->o4n1 & ~0x00ff) | (data & 0x00ff); |
| 1782 | 1844 | if (ACCESSING_BITS_8_15) |
| 1783 | 1845 | voice->o4n1 = (INT16)((voice->o4n1 & ~0xff00) | (data & 0xff00)); |
| 1784 | | if (LOG_COMMANDS && eslog) |
| 1785 | | fprintf(eslog, "%s:voice %d, O4(n-1)=%05x\n", machine.describe_context(), chip->current_page & 0x1f, voice->o4n1 & 0x3ffff); |
| 1846 | if (LOG_COMMANDS && m_eslog) |
| 1847 | fprintf(m_eslog, "%s:voice %d, O4(n-1)=%05x\n", machine().describe_context(), m_current_page & 0x1f, voice->o4n1 & 0x3ffff); |
| 1786 | 1848 | break; |
| 1787 | 1849 | |
| 1788 | 1850 | case 0x02: /* O3(n-1) */ |
| r26107 | r26108 | |
| 1790 | 1852 | voice->o3n1 = (voice->o3n1 & ~0x00ff) | (data & 0x00ff); |
| 1791 | 1853 | if (ACCESSING_BITS_8_15) |
| 1792 | 1854 | voice->o3n1 = (INT16)((voice->o3n1 & ~0xff00) | (data & 0xff00)); |
| 1793 | | if (LOG_COMMANDS && eslog) |
| 1794 | | fprintf(eslog, "%s:voice %d, O3(n-1)=%05x\n", machine.describe_context(), chip->current_page & 0x1f, voice->o3n1 & 0x3ffff); |
| 1855 | if (LOG_COMMANDS && m_eslog) |
| 1856 | fprintf(m_eslog, "%s:voice %d, O3(n-1)=%05x\n", machine().describe_context(), m_current_page & 0x1f, voice->o3n1 & 0x3ffff); |
| 1795 | 1857 | break; |
| 1796 | 1858 | |
| 1797 | 1859 | case 0x03: /* O3(n-2) */ |
| r26107 | r26108 | |
| 1799 | 1861 | voice->o3n2 = (voice->o3n2 & ~0x00ff) | (data & 0x00ff); |
| 1800 | 1862 | if (ACCESSING_BITS_8_15) |
| 1801 | 1863 | voice->o3n2 = (INT16)((voice->o3n2 & ~0xff00) | (data & 0xff00)); |
| 1802 | | if (LOG_COMMANDS && eslog) |
| 1803 | | fprintf(eslog, "%s:voice %d, O3(n-2)=%05x\n", machine.describe_context(), chip->current_page & 0x1f, voice->o3n2 & 0x3ffff); |
| 1864 | if (LOG_COMMANDS && m_eslog) |
| 1865 | fprintf(m_eslog, "%s:voice %d, O3(n-2)=%05x\n", machine().describe_context(), m_current_page & 0x1f, voice->o3n2 & 0x3ffff); |
| 1804 | 1866 | break; |
| 1805 | 1867 | |
| 1806 | 1868 | case 0x04: /* O2(n-1) */ |
| r26107 | r26108 | |
| 1808 | 1870 | voice->o2n1 = (voice->o2n1 & ~0x00ff) | (data & 0x00ff); |
| 1809 | 1871 | if (ACCESSING_BITS_8_15) |
| 1810 | 1872 | voice->o2n1 = (INT16)((voice->o2n1 & ~0xff00) | (data & 0xff00)); |
| 1811 | | if (LOG_COMMANDS && eslog) |
| 1812 | | fprintf(eslog, "%s:voice %d, O2(n-1)=%05x\n", machine.describe_context(), chip->current_page & 0x1f, voice->o2n1 & 0x3ffff); |
| 1873 | if (LOG_COMMANDS && m_eslog) |
| 1874 | fprintf(m_eslog, "%s:voice %d, O2(n-1)=%05x\n", machine().describe_context(), m_current_page & 0x1f, voice->o2n1 & 0x3ffff); |
| 1813 | 1875 | break; |
| 1814 | 1876 | |
| 1815 | 1877 | case 0x05: /* O2(n-2) */ |
| r26107 | r26108 | |
| 1817 | 1879 | voice->o2n2 = (voice->o2n2 & ~0x00ff) | (data & 0x00ff); |
| 1818 | 1880 | if (ACCESSING_BITS_8_15) |
| 1819 | 1881 | voice->o2n2 = (INT16)((voice->o2n2 & ~0xff00) | (data & 0xff00)); |
| 1820 | | if (LOG_COMMANDS && eslog) |
| 1821 | | fprintf(eslog, "%s:voice %d, O2(n-2)=%05x\n", machine.describe_context(), chip->current_page & 0x1f, voice->o2n2 & 0x3ffff); |
| 1882 | if (LOG_COMMANDS && m_eslog) |
| 1883 | fprintf(m_eslog, "%s:voice %d, O2(n-2)=%05x\n", machine().describe_context(), m_current_page & 0x1f, voice->o2n2 & 0x3ffff); |
| 1822 | 1884 | break; |
| 1823 | 1885 | |
| 1824 | 1886 | case 0x06: /* O1(n-1) */ |
| r26107 | r26108 | |
| 1826 | 1888 | voice->o1n1 = (voice->o1n1 & ~0x00ff) | (data & 0x00ff); |
| 1827 | 1889 | if (ACCESSING_BITS_8_15) |
| 1828 | 1890 | voice->o1n1 = (INT16)((voice->o1n1 & ~0xff00) | (data & 0xff00)); |
| 1829 | | if (LOG_COMMANDS && eslog) |
| 1830 | | fprintf(eslog, "%s:voice %d, O1(n-1)=%05x (accum=%08x)\n", machine.describe_context(), chip->current_page & 0x1f, voice->o2n1 & 0x3ffff, voice->accum); |
| 1891 | if (LOG_COMMANDS && m_eslog) |
| 1892 | fprintf(m_eslog, "%s:voice %d, O1(n-1)=%05x (accum=%08x)\n", machine().describe_context(), m_current_page & 0x1f, voice->o2n1 & 0x3ffff, voice->accum); |
| 1831 | 1893 | break; |
| 1832 | 1894 | |
| 1833 | 1895 | case 0x07: |
| r26107 | r26108 | |
| 1841 | 1903 | case 0x0d: /* ACT */ |
| 1842 | 1904 | if (ACCESSING_BITS_0_7) |
| 1843 | 1905 | { |
| 1844 | | chip->active_voices = data & 0x1f; |
| 1845 | | chip->sample_rate = chip->master_clock / (16 * (chip->active_voices + 1)); |
| 1846 | | chip->stream->set_sample_rate(chip->sample_rate); |
| 1906 | m_active_voices = data & 0x1f; |
| 1907 | m_sample_rate = m_master_clock / (16 * (m_active_voices + 1)); |
| 1908 | m_stream->set_sample_rate(m_sample_rate); |
| 1847 | 1909 | |
| 1848 | | if (LOG_COMMANDS && eslog) |
| 1849 | | fprintf(eslog, "active voices=%d, sample_rate=%d\n", chip->active_voices, chip->sample_rate); |
| 1910 | if (LOG_COMMANDS && m_eslog) |
| 1911 | fprintf(m_eslog, "active voices=%d, sample_rate=%d\n", m_active_voices, m_sample_rate); |
| 1850 | 1912 | } |
| 1851 | 1913 | break; |
| 1852 | 1914 | |
| r26107 | r26108 | |
| 1855 | 1917 | |
| 1856 | 1918 | case 0x0f: /* PAGE */ |
| 1857 | 1919 | if (ACCESSING_BITS_0_7) |
| 1858 | | chip->current_page = data & 0x7f; |
| 1920 | m_current_page = data & 0x7f; |
| 1859 | 1921 | break; |
| 1860 | 1922 | } |
| 1861 | 1923 | } |
| 1862 | 1924 | |
| 1863 | 1925 | |
| 1864 | | INLINE void es5505_reg_write_test(es5506_state *chip, es5506_voice *voice, offs_t offset, UINT16 data, UINT16 mem_mask) |
| 1926 | inline void es5505_device::reg_write_test(es550x_voice *voice, offs_t offset, UINT16 data, UINT16 mem_mask) |
| 1865 | 1927 | { |
| 1866 | 1928 | switch (offset) |
| 1867 | 1929 | { |
| r26107 | r26108 | |
| 1876 | 1938 | break; |
| 1877 | 1939 | |
| 1878 | 1940 | case 0x08: /* SERMODE */ |
| 1879 | | chip->mode = data & 0x0007; |
| 1941 | m_mode = data & 0x0007; |
| 1880 | 1942 | break; |
| 1881 | 1943 | |
| 1882 | 1944 | case 0x09: /* PAR */ |
| r26107 | r26108 | |
| 1885 | 1947 | case 0x0d: /* ACT */ |
| 1886 | 1948 | if (ACCESSING_BITS_0_7) |
| 1887 | 1949 | { |
| 1888 | | chip->active_voices = data & 0x1f; |
| 1889 | | chip->sample_rate = chip->master_clock / (16 * (chip->active_voices + 1)); |
| 1890 | | chip->stream->set_sample_rate(chip->sample_rate); |
| 1950 | m_active_voices = data & 0x1f; |
| 1951 | m_sample_rate = m_master_clock / (16 * (m_active_voices + 1)); |
| 1952 | m_stream->set_sample_rate(m_sample_rate); |
| 1891 | 1953 | |
| 1892 | | if (LOG_COMMANDS && eslog) |
| 1893 | | fprintf(eslog, "active voices=%d, sample_rate=%d\n", chip->active_voices, chip->sample_rate); |
| 1954 | if (LOG_COMMANDS && m_eslog) |
| 1955 | fprintf(m_eslog, "active voices=%d, sample_rate=%d\n", m_active_voices, m_sample_rate); |
| 1894 | 1956 | } |
| 1895 | 1957 | break; |
| 1896 | 1958 | |
| r26107 | r26108 | |
| 1899 | 1961 | |
| 1900 | 1962 | case 0x0f: /* PAGE */ |
| 1901 | 1963 | if (ACCESSING_BITS_0_7) |
| 1902 | | chip->current_page = data & 0x7f; |
| 1964 | m_current_page = data & 0x7f; |
| 1903 | 1965 | break; |
| 1904 | 1966 | } |
| 1905 | 1967 | } |
| 1906 | 1968 | |
| 1907 | 1969 | |
| 1908 | | WRITE16_DEVICE_HANDLER( es5505_w ) |
| 1970 | WRITE16_MEMBER( es5505_device::write ) |
| 1909 | 1971 | { |
| 1910 | | es5506_state *chip = get_safe_token(device); |
| 1911 | | es5506_voice *voice = &chip->voice[chip->current_page & 0x1f]; |
| 1972 | es550x_voice *voice = &m_voice[m_current_page & 0x1f]; |
| 1912 | 1973 | |
| 1913 | | // logerror("%s:ES5505 write %02x/%02x = %04x & %04x\n", machine.describe_context(), chip->current_page, offset, data, mem_mask); |
| 1974 | // logerror("%s:ES5505 write %02x/%02x = %04x & %04x\n", machine().describe_context(), m_current_page, offset, data, mem_mask); |
| 1914 | 1975 | |
| 1915 | 1976 | /* force an update */ |
| 1916 | | chip->stream->update(); |
| 1977 | m_stream->update(); |
| 1917 | 1978 | |
| 1918 | 1979 | /* switch off the page and register */ |
| 1919 | | if (chip->current_page < 0x20) |
| 1920 | | es5505_reg_write_low(chip, voice, offset, data, mem_mask); |
| 1921 | | else if (chip->current_page < 0x40) |
| 1922 | | es5505_reg_write_high(chip, voice, offset, data, mem_mask); |
| 1980 | if (m_current_page < 0x20) |
| 1981 | reg_write_low(voice, offset, data, mem_mask); |
| 1982 | else if (m_current_page < 0x40) |
| 1983 | reg_write_high(voice, offset, data, mem_mask); |
| 1923 | 1984 | else |
| 1924 | | es5505_reg_write_test(chip, voice, offset, data, mem_mask); |
| 1985 | reg_write_test(voice, offset, data, mem_mask); |
| 1925 | 1986 | } |
| 1926 | 1987 | |
| 1927 | 1988 | |
| 1928 | 1989 | |
| 1929 | 1990 | /********************************************************************************************** |
| 1930 | 1991 | |
| 1931 | | es5505_reg_read -- read from the specified ES5505 register |
| 1992 | reg_read -- read from the specified ES5505 register |
| 1932 | 1993 | |
| 1933 | 1994 | ***********************************************************************************************/ |
| 1934 | 1995 | |
| 1935 | | INLINE UINT16 es5505_reg_read_low(es5506_state *chip, es5506_voice *voice, offs_t offset) |
| 1996 | inline UINT16 es5505_device::reg_read_low(es550x_voice *voice, offs_t offset) |
| 1936 | 1997 | { |
| 1937 | 1998 | UINT16 result = 0; |
| 1938 | 1999 | |
| r26107 | r26108 | |
| 1994 | 2055 | break; |
| 1995 | 2056 | |
| 1996 | 2057 | case 0x0d: /* ACT */ |
| 1997 | | result = chip->active_voices; |
| 2058 | result = m_active_voices; |
| 1998 | 2059 | break; |
| 1999 | 2060 | |
| 2000 | 2061 | case 0x0e: /* IRQV */ |
| 2001 | | result = chip->irqv; |
| 2002 | | update_internal_irq_state(chip); |
| 2062 | result = m_irqv; |
| 2063 | update_internal_irq_state(); |
| 2003 | 2064 | break; |
| 2004 | 2065 | |
| 2005 | 2066 | case 0x0f: /* PAGE */ |
| 2006 | | result = chip->current_page; |
| 2067 | result = m_current_page; |
| 2007 | 2068 | break; |
| 2008 | 2069 | } |
| 2009 | 2070 | return result; |
| 2010 | 2071 | } |
| 2011 | 2072 | |
| 2012 | 2073 | |
| 2013 | | INLINE UINT16 es5505_reg_read_high(es5506_state *chip, es5506_voice *voice, offs_t offset) |
| 2074 | inline UINT16 es5505_device::reg_read_high(es550x_voice *voice, offs_t offset) |
| 2014 | 2075 | { |
| 2015 | 2076 | UINT16 result = 0; |
| 2016 | 2077 | |
| r26107 | r26108 | |
| 2051 | 2112 | /* want to waste time filtering stopped channels, we just look for a read from */ |
| 2052 | 2113 | /* this register on a stopped voice, and return the raw sample data at the */ |
| 2053 | 2114 | /* accumulator */ |
| 2054 | | if ((voice->control & CONTROL_STOPMASK) && chip->region_base[voice->control >> 14]) |
| 2115 | if ((voice->control & CONTROL_STOPMASK) && m_region_base[voice->control >> 14]) |
| 2055 | 2116 | { |
| 2056 | | voice->o1n1 = chip->region_base[voice->control >> 14][voice->exbank + (voice->accum >> 11)]; |
| 2117 | voice->o1n1 = m_region_base[voice->control >> 14][voice->exbank + (voice->accum >> 11)]; |
| 2057 | 2118 | // logerror("%02x %08x ==> %08x\n",voice->o1n1,voice->control >> 14,voice->exbank + (voice->accum >> 11)); |
| 2058 | 2119 | } |
| 2059 | 2120 | result = voice->o1n1; |
| r26107 | r26108 | |
| 2068 | 2129 | break; |
| 2069 | 2130 | |
| 2070 | 2131 | case 0x0d: /* ACT */ |
| 2071 | | result = chip->active_voices; |
| 2132 | result = m_active_voices; |
| 2072 | 2133 | break; |
| 2073 | 2134 | |
| 2074 | 2135 | case 0x0e: /* IRQV */ |
| 2075 | | result = chip->irqv; |
| 2076 | | update_internal_irq_state(chip); |
| 2136 | result = m_irqv; |
| 2137 | update_internal_irq_state(); |
| 2077 | 2138 | break; |
| 2078 | 2139 | |
| 2079 | 2140 | case 0x0f: /* PAGE */ |
| 2080 | | result = chip->current_page; |
| 2141 | result = m_current_page; |
| 2081 | 2142 | break; |
| 2082 | 2143 | } |
| 2083 | 2144 | return result; |
| 2084 | 2145 | } |
| 2085 | 2146 | |
| 2086 | 2147 | |
| 2087 | | INLINE UINT16 es5505_reg_read_test(es5506_state *chip, es5506_voice *voice, offs_t offset) |
| 2148 | inline UINT16 es5505_device::reg_read_test(es550x_voice *voice, offs_t offset) |
| 2088 | 2149 | { |
| 2089 | 2150 | UINT16 result = 0; |
| 2090 | 2151 | |
| r26107 | r26108 | |
| 2101 | 2162 | break; |
| 2102 | 2163 | |
| 2103 | 2164 | case 0x08: /* SERMODE */ |
| 2104 | | result = chip->mode; |
| 2165 | result = m_mode; |
| 2105 | 2166 | break; |
| 2106 | 2167 | |
| 2107 | 2168 | case 0x09: /* PAR */ |
| 2108 | | if (!chip->port_read.isnull()) |
| 2109 | | result = chip->port_read(0); |
| 2169 | if (!m_port_read_func.isnull()) |
| 2170 | result = m_port_read_func(0); |
| 2110 | 2171 | break; |
| 2111 | 2172 | |
| 2112 | 2173 | case 0x0f: /* PAGE */ |
| 2113 | | result = chip->current_page; |
| 2174 | result = m_current_page; |
| 2114 | 2175 | break; |
| 2115 | 2176 | } |
| 2116 | 2177 | return result; |
| 2117 | 2178 | } |
| 2118 | 2179 | |
| 2119 | 2180 | |
| 2120 | | READ16_DEVICE_HANDLER( es5505_r ) |
| 2181 | READ16_MEMBER( es5505_device::read ) |
| 2121 | 2182 | { |
| 2122 | | es5506_state *chip = get_safe_token(device); |
| 2123 | | es5506_voice *voice = &chip->voice[chip->current_page & 0x1f]; |
| 2183 | es550x_voice *voice = &m_voice[m_current_page & 0x1f]; |
| 2124 | 2184 | UINT16 result = 0; |
| 2125 | 2185 | |
| 2126 | | if (LOG_COMMANDS && eslog) |
| 2127 | | fprintf(eslog, "read from %02x/%02x -> ", chip->current_page, offset); |
| 2186 | if (LOG_COMMANDS && m_eslog) |
| 2187 | fprintf(m_eslog, "read from %02x/%02x -> ", m_current_page, offset); |
| 2128 | 2188 | |
| 2129 | 2189 | /* force an update */ |
| 2130 | | chip->stream->update(); |
| 2190 | m_stream->update(); |
| 2131 | 2191 | |
| 2132 | 2192 | /* switch off the page and register */ |
| 2133 | | if (chip->current_page < 0x20) |
| 2134 | | result = es5505_reg_read_low(chip, voice, offset); |
| 2135 | | else if (chip->current_page < 0x40) |
| 2136 | | result = es5505_reg_read_high(chip, voice, offset); |
| 2193 | if (m_current_page < 0x20) |
| 2194 | result = reg_read_low(voice, offset); |
| 2195 | else if (m_current_page < 0x40) |
| 2196 | result = reg_read_high(voice, offset); |
| 2137 | 2197 | else |
| 2138 | | result = es5505_reg_read_test(chip, voice, offset); |
| 2198 | result = reg_read_test(voice, offset); |
| 2139 | 2199 | |
| 2140 | | if (LOG_COMMANDS && eslog) |
| 2141 | | fprintf(eslog, "%04x (accum=%08x)\n", result, voice->accum); |
| 2200 | if (LOG_COMMANDS && m_eslog) |
| 2201 | fprintf(m_eslog, "%04x (accum=%08x)\n", result, voice->accum); |
| 2142 | 2202 | |
| 2143 | 2203 | /* return the high byte */ |
| 2144 | 2204 | return result; |
| r26107 | r26108 | |
| 2146 | 2206 | |
| 2147 | 2207 | |
| 2148 | 2208 | |
| 2149 | | void es5505_voice_bank_w(device_t *device, int voice, int bank) |
| 2209 | void es5505_device::voice_bank_w(int voice, int bank) |
| 2150 | 2210 | { |
| 2151 | | es5506_state *chip = get_safe_token(device); |
| 2211 | |
| 2152 | 2212 | #if RAINE_CHECK |
| 2153 | | chip->voice[voice].control = CONTROL_STOPMASK; |
| 2213 | m_voice[voice].control = CONTROL_STOPMASK; |
| 2154 | 2214 | #endif |
| 2155 | | chip->voice[voice].exbank=bank; |
| 2215 | m_voice[voice].exbank=bank; |
| 2156 | 2216 | } |
| 2157 | 2217 | |
| 2158 | | const device_type ES5506 = &device_creator<es5506_device>; |
| 2159 | 2218 | |
| 2160 | | es5506_device::es5506_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock) |
| 2161 | | : device_t(mconfig, ES5506, "ES5506", tag, owner, clock, "es5506", __FILE__), |
| 2162 | | device_sound_interface(mconfig, *this) |
| 2163 | | { |
| 2164 | | m_token = global_alloc_clear(es5506_state); |
| 2165 | | } |
| 2166 | | |
| 2167 | | es5506_device::es5506_device(const machine_config &mconfig, device_type type, const char *name, const char *tag, device_t *owner, UINT32 clock, const char *shortname, const char *source) |
| 2168 | | : device_t(mconfig, type, name, tag, owner, clock, shortname, source), |
| 2169 | | device_sound_interface(mconfig, *this) |
| 2170 | | { |
| 2171 | | m_token = global_alloc_clear(es5506_state); |
| 2172 | | } |
| 2173 | | |
| 2174 | 2219 | //------------------------------------------------- |
| 2175 | | // device_config_complete - perform any |
| 2176 | | // operations now that the configuration is |
| 2177 | | // complete |
| 2220 | // sound_stream_update - handle a stream update |
| 2178 | 2221 | //------------------------------------------------- |
| 2179 | 2222 | |
| 2180 | | void es5506_device::device_config_complete() |
| 2223 | void es550x_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) |
| 2181 | 2224 | { |
| 2182 | 2225 | } |
| 2183 | 2226 | |
| 2184 | | //------------------------------------------------- |
| 2185 | | // device_start - device-specific startup |
| 2186 | | //------------------------------------------------- |
| 2187 | | |
| 2188 | | void es5506_device::device_start() |
| 2227 | void es5506_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) |
| 2189 | 2228 | { |
| 2190 | | DEVICE_START_NAME( es5506 )(this); |
| 2191 | | } |
| 2229 | |
| 2230 | #if MAKE_WAVS |
| 2231 | /* start the logging once we have a sample rate */ |
| 2232 | if (m_sample_rate) |
| 2233 | { |
| 2234 | if (!m_wavraw) |
| 2235 | m_wavraw = wav_open("raw.wav", m_sample_rate, 2); |
| 2236 | } |
| 2237 | #endif |
| 2192 | 2238 | |
| 2193 | | //------------------------------------------------- |
| 2194 | | // device_reset - device-specific reset |
| 2195 | | //------------------------------------------------- |
| 2239 | /* loop until all samples are output */ |
| 2240 | int offset = 0; |
| 2241 | while (samples) |
| 2242 | { |
| 2243 | int length = (samples > MAX_SAMPLE_CHUNK) ? MAX_SAMPLE_CHUNK : samples; |
| 2196 | 2244 | |
| 2197 | | void es5506_device::device_reset() |
| 2198 | | { |
| 2199 | | } |
| 2245 | generate_samples(outputs, offset, length); |
| 2200 | 2246 | |
| 2201 | | //------------------------------------------------- |
| 2202 | | // device_stop - device-specific stop |
| 2203 | | //------------------------------------------------- |
| 2247 | #if MAKE_WAVS |
| 2248 | /* log the raw data */ |
| 2249 | if (m_wavraw) { |
| 2250 | /* determine left/right source data */ |
| 2251 | INT32 *lsrc = m_scratch, *rsrc = m_scratch + length; |
| 2252 | int channel; |
| 2253 | memset(lsrc, 0, sizeof(INT32) * length * 2); |
| 2254 | /* loop over the output channels */ |
| 2255 | for (channel = 0; channel < m_channels; channel++) { |
| 2256 | INT32 *l = outputs[(channel << 1)] + offset; |
| 2257 | INT32 *r = outputs[(channel << 1) + 1] + offset; |
| 2258 | /* add the current channel's samples to the WAV data */ |
| 2259 | for (samp = 0; samp < length; samp++) { |
| 2260 | lsrc[samp] += l[samp]; |
| 2261 | rsrc[samp] += r[samp]; |
| 2262 | } |
| 2263 | } |
| 2264 | wav_add_data_32lr(m_wavraw, lsrc, rsrc, length, 4); |
| 2265 | } |
| 2266 | #endif |
| 2204 | 2267 | |
| 2205 | | void es5506_device::device_stop() |
| 2206 | | { |
| 2207 | | DEVICE_STOP_NAME( es5506 )(this); |
| 2268 | /* account for these samples */ |
| 2269 | offset += length; |
| 2270 | samples -= length; |
| 2271 | } |
| 2208 | 2272 | } |
| 2209 | 2273 | |
| 2210 | | //------------------------------------------------- |
| 2211 | | // sound_stream_update - handle a stream update |
| 2212 | | //------------------------------------------------- |
| 2213 | | |
| 2214 | | void es5506_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) |
| 2274 | void es5505_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) |
| 2215 | 2275 | { |
| 2216 | | // should never get here |
| 2217 | | fatalerror("sound_stream_update called; not applicable to legacy sound devices\n"); |
| 2218 | | } |
| 2276 | |
| 2277 | #if MAKE_WAVS |
| 2278 | /* start the logging once we have a sample rate */ |
| 2279 | if (m_sample_rate) |
| 2280 | { |
| 2281 | if (!m_wavraw) |
| 2282 | m_wavraw = wav_open("raw.wav", m_sample_rate, 2); |
| 2283 | } |
| 2284 | #endif |
| 2219 | 2285 | |
| 2220 | | const device_type ES5505 = &device_creator<es5505_device>; |
| 2286 | /* loop until all samples are output */ |
| 2287 | int offset = 0; |
| 2288 | while (samples) |
| 2289 | { |
| 2290 | int length = (samples > MAX_SAMPLE_CHUNK) ? MAX_SAMPLE_CHUNK : samples; |
| 2221 | 2291 | |
| 2222 | | es5505_device::es5505_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock) |
| 2223 | | : es5506_device(mconfig, ES5505, "ES5505", tag, owner, clock, "es5505", __FILE__) |
| 2224 | | { |
| 2225 | | } |
| 2292 | generate_samples(outputs, offset, length); |
| 2226 | 2293 | |
| 2227 | | //------------------------------------------------- |
| 2228 | | // device_start - device-specific startup |
| 2229 | | //------------------------------------------------- |
| 2294 | #if MAKE_WAVS |
| 2295 | /* log the raw data */ |
| 2296 | if (m_wavraw) { |
| 2297 | /* determine left/right source data */ |
| 2298 | INT32 *lsrc = m_scratch, *rsrc = m_scratch + length; |
| 2299 | int channel; |
| 2300 | memset(lsrc, 0, sizeof(INT32) * length * 2); |
| 2301 | /* loop over the output channels */ |
| 2302 | for (channel = 0; channel < m_channels; channel++) { |
| 2303 | INT32 *l = outputs[(channel << 1)] + offset; |
| 2304 | INT32 *r = outputs[(channel << 1) + 1] + offset; |
| 2305 | /* add the current channel's samples to the WAV data */ |
| 2306 | for (samp = 0; samp < length; samp++) { |
| 2307 | lsrc[samp] += l[samp]; |
| 2308 | rsrc[samp] += r[samp]; |
| 2309 | } |
| 2310 | } |
| 2311 | wav_add_data_32lr(m_wavraw, lsrc, rsrc, length, 4); |
| 2312 | } |
| 2313 | #endif |
| 2230 | 2314 | |
| 2231 | | void es5505_device::device_start() |
| 2232 | | { |
| 2233 | | DEVICE_START_NAME( es5505 )(this); |
| 2234 | | } |
| 2315 | /* account for these samples */ |
| 2316 | offset += length; |
| 2317 | samples -= length; |
| 2318 | } |
| 2319 | } |
| | No newline at end of file |