trunk/src/emu/sound/sn76477.c
r26337 | r26338 | |
30 | 30 | #include "emu.h" |
31 | 31 | #include "wavwrite.h" |
32 | 32 | #include "sn76477.h" |
33 | | #include "devlegcy.h" |
34 | 33 | |
35 | 34 | |
36 | 35 | |
r26337 | r26338 | |
68 | 67 | |
69 | 68 | #define LOG(n,x) do { if (VERBOSE >= (n)) logerror x; } while (0) |
70 | 69 | |
71 | | #define CHECK_CHIP_NUM assert(sn != NULL) |
| 70 | #define CHECK_CHIP_NUM assert(this != NULL) |
72 | 71 | #define CHECK_CHIP_NUM_AND_BOOLEAN CHECK_CHIP_NUM; assert((state & 0x01) == state) |
73 | 72 | #define CHECK_CHIP_NUM_AND_POSITIVE CHECK_CHIP_NUM; assert(data >= 0.0) |
74 | 73 | #define CHECK_CHIP_NUM_AND_VOLTAGE CHECK_CHIP_NUM; assert((data >= 0.0) && (data <= 5.0)) |
r26337 | r26338 | |
122 | 121 | 0 /* 9 enable */ |
123 | 122 | }; |
124 | 123 | |
125 | | #define test_interface empty_empty_interface |
| 124 | #define test_interface empty_interface |
126 | 125 | |
127 | 126 | #endif |
128 | 127 | |
r26337 | r26338 | |
187 | 186 | }; |
188 | 187 | |
189 | 188 | |
| 189 | const device_type SN76477 = &device_creator<sn76477_device>; |
190 | 190 | |
191 | | /***************************************************************************** |
192 | | * |
193 | | * State structure |
194 | | * |
195 | | *****************************************************************************/ |
196 | | |
197 | | struct sn76477_state |
| 191 | sn76477_device::sn76477_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock) |
| 192 | : device_t(mconfig, SN76477, "SN76477", tag, owner, clock, "sn76477", __FILE__), |
| 193 | device_sound_interface(mconfig, *this), |
| 194 | m_enable(0), |
| 195 | m_envelope_mode(0), |
| 196 | m_vco_mode(0), |
| 197 | m_mixer_mode(0), |
| 198 | m_one_shot_res(0), |
| 199 | m_one_shot_cap(0), |
| 200 | m_one_shot_cap_voltage_ext(0), |
| 201 | m_slf_res(0), |
| 202 | m_slf_cap(0), |
| 203 | m_slf_cap_voltage_ext(0), |
| 204 | m_vco_voltage(0), |
| 205 | m_vco_res(0), |
| 206 | m_vco_cap(0), |
| 207 | m_vco_cap_voltage_ext(0), |
| 208 | m_noise_clock_res(0), |
| 209 | m_noise_clock_ext(0), |
| 210 | m_noise_clock(0), |
| 211 | m_noise_filter_res(0), |
| 212 | m_noise_filter_cap(0), |
| 213 | m_noise_filter_cap_voltage_ext(0), |
| 214 | m_attack_res(0), |
| 215 | m_decay_res(0), |
| 216 | m_attack_decay_cap(0), |
| 217 | m_attack_decay_cap_voltage_ext(0), |
| 218 | m_amplitude_res(0), |
| 219 | m_feedback_res(0), |
| 220 | m_pitch_voltage(0), |
| 221 | m_one_shot_cap_voltage(0), |
| 222 | m_one_shot_running_ff(0), |
| 223 | m_slf_cap_voltage(0), |
| 224 | m_slf_out_ff(0), |
| 225 | m_vco_cap_voltage(0), |
| 226 | m_vco_out_ff(0), |
| 227 | m_vco_alt_pos_edge_ff(0), |
| 228 | m_noise_filter_cap_voltage(0), |
| 229 | m_real_noise_bit_ff(0), |
| 230 | m_filtered_noise_bit_ff(0), |
| 231 | m_noise_gen_count(0), |
| 232 | m_attack_decay_cap_voltage(0), |
| 233 | m_rng(0), |
| 234 | m_channel(NULL), |
| 235 | m_our_sample_rate(0), |
| 236 | m_file(NULL) |
198 | 237 | { |
199 | | /* chip's external interface */ |
200 | | UINT32 enable; |
201 | | UINT32 envelope_mode; |
202 | | UINT32 vco_mode; |
203 | | UINT32 mixer_mode; |
| 238 | } |
204 | 239 | |
205 | | double one_shot_res; |
206 | | double one_shot_cap; |
207 | | UINT32 one_shot_cap_voltage_ext; |
| 240 | //------------------------------------------------- |
| 241 | // device_config_complete - perform any |
| 242 | // operations now that the configuration is |
| 243 | // complete |
| 244 | //------------------------------------------------- |
208 | 245 | |
209 | | double slf_res; |
210 | | double slf_cap; |
211 | | UINT32 slf_cap_voltage_ext; |
| 246 | void sn76477_device::device_config_complete() |
| 247 | { |
| 248 | // inherit a copy of the static data |
| 249 | const sn76477_interface *intf = reinterpret_cast<const sn76477_interface *>(static_config()); |
| 250 | if (intf != NULL) |
| 251 | #if TEST_MODE == 0 |
| 252 | *static_cast<sn76477_interface *>(this) = *intf; |
212 | 253 | |
213 | | double vco_voltage; |
214 | | double vco_res; |
215 | | double vco_cap; |
216 | | UINT32 vco_cap_voltage_ext; |
| 254 | // or initialize to defaults if none provided |
| 255 | else |
| 256 | { |
| 257 | m_intf_noise_clock_res = 0.0; |
| 258 | m_intf_noise_filter_res = 0.0; |
| 259 | m_intf_noise_filter_cap = 0.0; |
| 260 | m_intf_decay_res = 0.0; |
| 261 | m_intf_attack_decay_cap = 0.0; |
| 262 | m_intf_attack_res = 0.0; |
| 263 | m_intf_amplitude_res = 0.0; |
| 264 | m_intf_feedback_res = 0.0; |
| 265 | m_intf_vco_voltage = 0.0; |
| 266 | m_intf_vco_cap = 0.0; |
| 267 | m_intf_vco_res = 0.0; |
| 268 | m_intf_pitch_voltage = 0.0; |
| 269 | m_intf_slf_res = 0.0; |
| 270 | m_intf_slf_cap = 0.0; |
| 271 | m_intf_one_shot_cap = 0.0; |
| 272 | m_intf_one_shot_res = 0.0; |
| 273 | m_intf_vco = 0; |
| 274 | m_intf_mixer_a = 0; |
| 275 | m_intf_mixer_b = 0; |
| 276 | m_intf_mixer_c = 0; |
| 277 | m_intf_envelope_1 = 0; |
| 278 | m_intf_envelope_2 = 0; |
| 279 | m_intf_enable = 0; |
| 280 | } |
| 281 | #else |
| 282 | intf = &test_interface; |
| 283 | #endif |
| 284 | } |
217 | 285 | |
218 | | double noise_clock_res; |
219 | | UINT32 noise_clock_ext; |
220 | | UINT32 noise_clock; |
221 | | double noise_filter_res; |
222 | | double noise_filter_cap; |
223 | | UINT32 noise_filter_cap_voltage_ext; |
| 286 | //------------------------------------------------- |
| 287 | // device_start - device-specific startup |
| 288 | //------------------------------------------------- |
224 | 289 | |
225 | | double attack_res; |
226 | | double decay_res; |
227 | | double attack_decay_cap; |
228 | | UINT32 attack_decay_cap_voltage_ext; |
| 290 | void sn76477_device::device_start() |
| 291 | { |
| 292 | m_channel = machine().sound().stream_alloc(*this, 0, 1, machine().sample_rate(), this); |
229 | 293 | |
230 | | double amplitude_res; |
231 | | double feedback_res; |
232 | | double pitch_voltage; |
| 294 | if (clock() > 0) |
| 295 | { |
| 296 | m_our_sample_rate = clock(); |
| 297 | } |
| 298 | else |
| 299 | { |
| 300 | m_our_sample_rate = machine().sample_rate(); |
| 301 | } |
233 | 302 | |
234 | | /* chip's internal state */ |
235 | | double one_shot_cap_voltage; /* voltage on the one-shot cap */ |
236 | | UINT32 one_shot_running_ff; /* 1 = one-shot running, 0 = stopped */ |
| 303 | intialize_noise(); |
| 304 | |
| 305 | /* set up interface values */ |
| 306 | _SN76477_enable_w(m_intf_enable); |
| 307 | _SN76477_vco_w(m_intf_vco); |
| 308 | _SN76477_mixer_a_w(m_intf_mixer_a); |
| 309 | _SN76477_mixer_b_w(m_intf_mixer_b); |
| 310 | _SN76477_mixer_c_w(m_intf_mixer_c); |
| 311 | _SN76477_envelope_1_w(m_intf_envelope_1); |
| 312 | _SN76477_envelope_2_w(m_intf_envelope_2); |
| 313 | _SN76477_one_shot_res_w(m_intf_one_shot_res); |
| 314 | _SN76477_one_shot_cap_w(m_intf_one_shot_cap); |
| 315 | _SN76477_slf_res_w(m_intf_slf_res); |
| 316 | _SN76477_slf_cap_w(m_intf_slf_cap); |
| 317 | _SN76477_vco_res_w(m_intf_vco_res); |
| 318 | _SN76477_vco_cap_w(m_intf_vco_cap); |
| 319 | _SN76477_vco_voltage_w(m_intf_vco_voltage); |
| 320 | _SN76477_noise_clock_res_w(m_intf_noise_clock_res); |
| 321 | _SN76477_noise_filter_res_w(m_intf_noise_filter_res); |
| 322 | _SN76477_noise_filter_cap_w(m_intf_noise_filter_cap); |
| 323 | _SN76477_decay_res_w(m_intf_decay_res); |
| 324 | _SN76477_attack_res_w(m_intf_attack_res); |
| 325 | _SN76477_attack_decay_cap_w(m_intf_attack_decay_cap); |
| 326 | _SN76477_amplitude_res_w(m_intf_amplitude_res); |
| 327 | _SN76477_feedback_res_w(m_intf_feedback_res); |
| 328 | _SN76477_pitch_voltage_w(m_intf_pitch_voltage); |
237 | 329 | |
238 | | double slf_cap_voltage; /* voltage on the SLF cap */ |
239 | | UINT32 slf_out_ff; /* output of the SLF */ |
| 330 | m_one_shot_cap_voltage = ONE_SHOT_CAP_VOLTAGE_MIN; |
| 331 | m_slf_cap_voltage = SLF_CAP_VOLTAGE_MIN; |
| 332 | m_vco_cap_voltage = VCO_CAP_VOLTAGE_MIN; |
| 333 | m_noise_filter_cap_voltage = NOISE_CAP_VOLTAGE_MIN; |
| 334 | m_attack_decay_cap_voltage = AD_CAP_VOLTAGE_MIN; |
240 | 335 | |
241 | | double vco_cap_voltage; /* voltage on the VCO cap */ |
242 | | UINT32 vco_out_ff; /* output of the VCO */ |
243 | | UINT32 vco_alt_pos_edge_ff; /* keeps track of the # of positive edges for VCO Alt envelope */ |
| 336 | state_save_register(); |
244 | 337 | |
245 | | double noise_filter_cap_voltage; /* voltage on the noise filter cap */ |
246 | | UINT32 real_noise_bit_ff; /* the current noise bit before filtering */ |
247 | | UINT32 filtered_noise_bit_ff; /* the noise bit after filtering */ |
248 | | UINT32 noise_gen_count; /* noise freq emulation */ |
| 338 | log_complete_state(); |
249 | 339 | |
250 | | double attack_decay_cap_voltage; /* voltage on the attack/decay cap */ |
| 340 | if (LOG_WAV) |
| 341 | open_wav_file(); |
| 342 | } |
251 | 343 | |
252 | | UINT32 rng; /* current value of the random number generator */ |
| 344 | //------------------------------------------------- |
| 345 | // device_stop - device-specific stop |
| 346 | //------------------------------------------------- |
253 | 347 | |
254 | | /* others */ |
255 | | sound_stream *channel; /* returned by stream_create() */ |
256 | | int sample_rate; /* from machine.sample_rate() */ |
257 | | device_t *device; |
258 | | |
259 | | wav_file *file; /* handle of the wave file to produce */ |
260 | | }; |
261 | | |
262 | | |
263 | | INLINE sn76477_state *get_safe_token(device_t *device) |
| 348 | void sn76477_device::device_stop() |
264 | 349 | { |
265 | | assert(device != NULL); |
266 | | assert(device->type() == SN76477); |
267 | | return (sn76477_state *)downcast<sn76477_device *>(device)->token(); |
| 350 | if (LOG_WAV) |
| 351 | close_wav_file(); |
268 | 352 | } |
269 | 353 | |
270 | 354 | |
r26337 | r26338 | |
298 | 382 | * |
299 | 383 | *****************************************************************************/ |
300 | 384 | |
301 | | static double compute_one_shot_cap_charging_rate(sn76477_state *sn) /* in V/sec */ |
| 385 | double sn76477_device::compute_one_shot_cap_charging_rate() /* in V/sec */ |
302 | 386 | { |
303 | 387 | /* this formula was derived using the data points below |
304 | 388 | |
r26337 | r26338 | |
315 | 399 | |
316 | 400 | double ret = 0; |
317 | 401 | |
318 | | if ((sn->one_shot_res > 0) && (sn->one_shot_cap > 0)) |
| 402 | if ((m_one_shot_res > 0) && (m_one_shot_cap > 0)) |
319 | 403 | { |
320 | | ret = ONE_SHOT_CAP_VOLTAGE_RANGE / (0.8024 * sn->one_shot_res * sn->one_shot_cap + 0.002079); |
| 404 | ret = ONE_SHOT_CAP_VOLTAGE_RANGE / (0.8024 * m_one_shot_res * m_one_shot_cap + 0.002079); |
321 | 405 | } |
322 | | else if (sn->one_shot_cap > 0) |
| 406 | else if (m_one_shot_cap > 0) |
323 | 407 | { |
324 | 408 | /* if no resistor, there is no current to charge the cap, |
325 | 409 | effectively making the one-shot time effectively infinite */ |
326 | 410 | ret = +1e-30; |
327 | 411 | } |
328 | | else if (sn->one_shot_res > 0) |
| 412 | else if (m_one_shot_res > 0) |
329 | 413 | { |
330 | 414 | /* if no cap, the voltage changes extremely fast, |
331 | 415 | effectively making the one-shot time 0 */ |
r26337 | r26338 | |
336 | 420 | } |
337 | 421 | |
338 | 422 | |
339 | | static double compute_one_shot_cap_discharging_rate(sn76477_state *sn) /* in V/sec */ |
| 423 | double sn76477_device::compute_one_shot_cap_discharging_rate() /* in V/sec */ |
340 | 424 | { |
341 | 425 | /* this formula was derived using the data points below |
342 | 426 | |
r26337 | r26338 | |
349 | 433 | |
350 | 434 | double ret = 0; |
351 | 435 | |
352 | | if ((sn->one_shot_res > 0) && (sn->one_shot_cap > 0)) |
| 436 | if ((m_one_shot_res > 0) && (m_one_shot_cap > 0)) |
353 | 437 | { |
354 | | ret = ONE_SHOT_CAP_VOLTAGE_RANGE / (854.7 * sn->one_shot_cap + 0.00001795); |
| 438 | ret = ONE_SHOT_CAP_VOLTAGE_RANGE / (854.7 * m_one_shot_cap + 0.00001795); |
355 | 439 | } |
356 | | else if (sn->one_shot_res > 0) |
| 440 | else if (m_one_shot_res > 0) |
357 | 441 | { |
358 | 442 | /* if no cap, the voltage changes extremely fast, |
359 | 443 | effectively making the one-shot time 0 */ |
r26337 | r26338 | |
364 | 448 | } |
365 | 449 | |
366 | 450 | |
367 | | static double compute_slf_cap_charging_rate(sn76477_state *sn) /* in V/sec */ |
| 451 | double sn76477_device::compute_slf_cap_charging_rate() /* in V/sec */ |
368 | 452 | { |
369 | 453 | /* this formula was derived using the data points below |
370 | 454 | |
r26337 | r26338 | |
378 | 462 | */ |
379 | 463 | double ret = 0; |
380 | 464 | |
381 | | if ((sn->slf_res > 0) && (sn->slf_cap > 0)) |
| 465 | if ((m_slf_res > 0) && (m_slf_cap > 0)) |
382 | 466 | { |
383 | | ret = SLF_CAP_VOLTAGE_RANGE / (0.5885 * sn->slf_res * sn->slf_cap + 0.001300); |
| 467 | ret = SLF_CAP_VOLTAGE_RANGE / (0.5885 * m_slf_res * m_slf_cap + 0.001300); |
384 | 468 | } |
385 | 469 | |
386 | 470 | return ret; |
387 | 471 | } |
388 | 472 | |
389 | 473 | |
390 | | static double compute_slf_cap_discharging_rate(sn76477_state *sn) /* in V/sec */ |
| 474 | double sn76477_device::compute_slf_cap_discharging_rate() /* in V/sec */ |
391 | 475 | { |
392 | 476 | /* this formula was derived using the data points below |
393 | 477 | |
r26337 | r26338 | |
401 | 485 | */ |
402 | 486 | double ret = 0; |
403 | 487 | |
404 | | if ((sn->slf_res > 0) && (sn->slf_cap > 0)) |
| 488 | if ((m_slf_res > 0) && (m_slf_cap > 0)) |
405 | 489 | { |
406 | | ret = SLF_CAP_VOLTAGE_RANGE / (0.5413 * sn->slf_res * sn->slf_cap + 0.001343); |
| 490 | ret = SLF_CAP_VOLTAGE_RANGE / (0.5413 * m_slf_res * m_slf_cap + 0.001343); |
407 | 491 | } |
408 | 492 | |
409 | 493 | return ret; |
410 | 494 | } |
411 | 495 | |
412 | 496 | |
413 | | static double compute_vco_cap_charging_discharging_rate(sn76477_state *sn) /* in V/sec */ |
| 497 | double sn76477_device::compute_vco_cap_charging_discharging_rate() /* in V/sec */ |
414 | 498 | { |
415 | 499 | double ret = 0; |
416 | 500 | |
417 | | if ((sn->vco_res > 0) && (sn->vco_cap > 0)) |
| 501 | if ((m_vco_res > 0) && (m_vco_cap > 0)) |
418 | 502 | { |
419 | | ret = 0.64 * 2 * VCO_CAP_VOLTAGE_RANGE / (sn->vco_res * sn->vco_cap); |
| 503 | ret = 0.64 * 2 * VCO_CAP_VOLTAGE_RANGE / (m_vco_res * m_vco_cap); |
420 | 504 | } |
421 | 505 | |
422 | 506 | return ret; |
423 | 507 | } |
424 | 508 | |
425 | 509 | |
426 | | static double compute_vco_duty_cycle(sn76477_state *sn) /* no measure, just a number */ |
| 510 | double sn76477_device::compute_vco_duty_cycle() /* no measure, just a number */ |
427 | 511 | { |
428 | 512 | double ret = 0.5; /* 50% */ |
429 | 513 | |
430 | | if ((sn->vco_voltage > 0) && (sn->pitch_voltage != VCO_DUTY_CYCLE_50)) |
| 514 | if ((m_vco_voltage > 0) && (m_pitch_voltage != VCO_DUTY_CYCLE_50)) |
431 | 515 | { |
432 | | ret = max(0.5 * (sn->pitch_voltage / sn->vco_voltage), (VCO_MIN_DUTY_CYCLE / 100.0)); |
| 516 | ret = max(0.5 * (m_pitch_voltage / m_vco_voltage), (VCO_MIN_DUTY_CYCLE / 100.0)); |
433 | 517 | |
434 | 518 | ret = min(ret, 1); |
435 | 519 | } |
r26337 | r26338 | |
438 | 522 | } |
439 | 523 | |
440 | 524 | |
441 | | static UINT32 compute_noise_gen_freq(sn76477_state *sn) /* in Hz */ |
| 525 | UINT32 sn76477_device::compute_noise_gen_freq() /* in Hz */ |
442 | 526 | { |
443 | 527 | /* this formula was derived using the data points below |
444 | 528 | |
r26337 | r26338 | |
470 | 554 | |
471 | 555 | UINT32 ret = 0; |
472 | 556 | |
473 | | if ((sn->noise_clock_res >= NOISE_MIN_CLOCK_RES) && |
474 | | (sn->noise_clock_res <= NOISE_MAX_CLOCK_RES)) |
| 557 | if ((m_noise_clock_res >= NOISE_MIN_CLOCK_RES) && |
| 558 | (m_noise_clock_res <= NOISE_MAX_CLOCK_RES)) |
475 | 559 | { |
476 | | ret = 339100000 * pow(sn->noise_clock_res, -0.8849); |
| 560 | ret = 339100000 * pow(m_noise_clock_res, -0.8849); |
477 | 561 | } |
478 | 562 | |
479 | 563 | return ret; |
480 | 564 | } |
481 | 565 | |
482 | 566 | |
483 | | static double compute_noise_filter_cap_charging_rate(sn76477_state *sn) /* in V/sec */ |
| 567 | double sn76477_device::compute_noise_filter_cap_charging_rate() /* in V/sec */ |
484 | 568 | { |
485 | 569 | /* this formula was derived using the data points below |
486 | 570 | |
r26337 | r26338 | |
497 | 581 | |
498 | 582 | double ret = 0; |
499 | 583 | |
500 | | if ((sn->noise_filter_res > 0) && (sn->noise_filter_cap > 0)) |
| 584 | if ((m_noise_filter_res > 0) && (m_noise_filter_cap > 0)) |
501 | 585 | { |
502 | | ret = NOISE_CAP_VOLTAGE_RANGE / (0.1571 * sn->noise_filter_res * sn->noise_filter_cap + 0.00001430); |
| 586 | ret = NOISE_CAP_VOLTAGE_RANGE / (0.1571 * m_noise_filter_res * m_noise_filter_cap + 0.00001430); |
503 | 587 | } |
504 | | else if (sn->noise_filter_cap > 0) |
| 588 | else if (m_noise_filter_cap > 0) |
505 | 589 | { |
506 | 590 | /* if no resistor, there is no current to charge the cap, |
507 | 591 | effectively making the filter's output constants */ |
508 | 592 | ret = +1e-30; |
509 | 593 | } |
510 | | else if (sn->noise_filter_res > 0) |
| 594 | else if (m_noise_filter_res > 0) |
511 | 595 | { |
512 | 596 | /* if no cap, the voltage changes extremely fast, |
513 | 597 | effectively disabling the filter */ |
r26337 | r26338 | |
518 | 602 | } |
519 | 603 | |
520 | 604 | |
521 | | static double compute_noise_filter_cap_discharging_rate(sn76477_state *sn) /* in V/sec */ |
| 605 | double sn76477_device::compute_noise_filter_cap_discharging_rate() /* in V/sec */ |
522 | 606 | { |
523 | 607 | /* this formula was derived using the data points below |
524 | 608 | |
r26337 | r26338 | |
535 | 619 | |
536 | 620 | double ret = 0; |
537 | 621 | |
538 | | if ((sn->noise_filter_res > 0) && (sn->noise_filter_cap > 0)) |
| 622 | if ((m_noise_filter_res > 0) && (m_noise_filter_cap > 0)) |
539 | 623 | { |
540 | | ret = NOISE_CAP_VOLTAGE_RANGE / (0.1331 * sn->noise_filter_res * sn->noise_filter_cap + 0.00001734); |
| 624 | ret = NOISE_CAP_VOLTAGE_RANGE / (0.1331 * m_noise_filter_res * m_noise_filter_cap + 0.00001734); |
541 | 625 | } |
542 | | else if (sn->noise_filter_cap > 0) |
| 626 | else if (m_noise_filter_cap > 0) |
543 | 627 | { |
544 | 628 | /* if no resistor, there is no current to charge the cap, |
545 | 629 | effectively making the filter's output constants */ |
546 | 630 | ret = +1e-30; |
547 | 631 | } |
548 | | else if (sn->noise_filter_res > 0) |
| 632 | else if (m_noise_filter_res > 0) |
549 | 633 | { |
550 | 634 | /* if no cap, the voltage changes extremely fast, |
551 | 635 | effectively disabling the filter */ |
r26337 | r26338 | |
556 | 640 | } |
557 | 641 | |
558 | 642 | |
559 | | static double compute_attack_decay_cap_charging_rate(sn76477_state *sn) /* in V/sec */ |
| 643 | double sn76477_device::compute_attack_decay_cap_charging_rate() /* in V/sec */ |
560 | 644 | { |
561 | 645 | double ret = 0; |
562 | 646 | |
563 | | if ((sn->attack_res > 0) && (sn->attack_decay_cap > 0)) |
| 647 | if ((m_attack_res > 0) && (m_attack_decay_cap > 0)) |
564 | 648 | { |
565 | | ret = AD_CAP_VOLTAGE_RANGE / (sn->attack_res * sn->attack_decay_cap); |
| 649 | ret = AD_CAP_VOLTAGE_RANGE / (m_attack_res * m_attack_decay_cap); |
566 | 650 | } |
567 | | else if (sn->attack_decay_cap > 0) |
| 651 | else if (m_attack_decay_cap > 0) |
568 | 652 | { |
569 | 653 | /* if no resistor, there is no current to charge the cap, |
570 | 654 | effectively making the attack time infinite */ |
571 | 655 | ret = +1e-30; |
572 | 656 | } |
573 | | else if (sn->attack_res > 0) |
| 657 | else if (m_attack_res > 0) |
574 | 658 | { |
575 | 659 | /* if no cap, the voltage changes extremely fast, |
576 | 660 | effectively making the attack time 0 */ |
r26337 | r26338 | |
581 | 665 | } |
582 | 666 | |
583 | 667 | |
584 | | static double compute_attack_decay_cap_discharging_rate(sn76477_state *sn) /* in V/sec */ |
| 668 | double sn76477_device::compute_attack_decay_cap_discharging_rate() /* in V/sec */ |
585 | 669 | { |
586 | 670 | double ret = 0; |
587 | 671 | |
588 | | if ((sn->decay_res > 0) && (sn->attack_decay_cap > 0)) |
| 672 | if ((m_decay_res > 0) && (m_attack_decay_cap > 0)) |
589 | 673 | { |
590 | | ret = AD_CAP_VOLTAGE_RANGE / (sn->decay_res * sn->attack_decay_cap); |
| 674 | ret = AD_CAP_VOLTAGE_RANGE / (m_decay_res * m_attack_decay_cap); |
591 | 675 | } |
592 | | else if (sn->attack_decay_cap > 0) |
| 676 | else if (m_attack_decay_cap > 0) |
593 | 677 | { |
594 | 678 | /* if no resistor, there is no current to charge the cap, |
595 | 679 | effectively making the decay time infinite */ |
596 | 680 | ret = +1e-30; |
597 | 681 | } |
598 | | else if (sn->attack_res > 0) |
| 682 | else if (m_attack_res > 0) |
599 | 683 | { |
600 | 684 | /* if no cap, the voltage changes extremely fast, |
601 | 685 | effectively making the decay time 0 */ |
r26337 | r26338 | |
606 | 690 | } |
607 | 691 | |
608 | 692 | |
609 | | static double compute_center_to_peak_voltage_out(sn76477_state *sn) |
| 693 | double sn76477_device::compute_center_to_peak_voltage_out() |
610 | 694 | { |
611 | 695 | /* this formula was derived using the data points below |
612 | 696 | |
r26337 | r26338 | |
624 | 708 | |
625 | 709 | double ret = 0; |
626 | 710 | |
627 | | if (sn->amplitude_res > 0) |
| 711 | if (m_amplitude_res > 0) |
628 | 712 | { |
629 | | ret = 3.818 * (sn->feedback_res / sn->amplitude_res) + 0.03; |
| 713 | ret = 3.818 * (m_feedback_res / m_amplitude_res) + 0.03; |
630 | 714 | } |
631 | 715 | |
632 | 716 | return ret; |
r26337 | r26338 | |
640 | 724 | * |
641 | 725 | *****************************************************************************/ |
642 | 726 | |
643 | | static void log_enable_line(sn76477_state *sn) |
| 727 | void sn76477_device::log_enable_line() |
644 | 728 | { |
645 | 729 | static const char *const desc[] = |
646 | 730 | { |
647 | 731 | "Enabled", "Inhibited" |
648 | 732 | }; |
649 | 733 | |
650 | | LOG(1, ("SN76477 '%s': Enable line (9): %d [%s]\n", sn->device->tag(), sn->enable, desc[sn->enable])); |
| 734 | LOG(1, ("SN76477 '%s': Enable line (9): %d [%s]\n", tag(), m_enable, desc[m_enable])); |
651 | 735 | } |
652 | 736 | |
653 | 737 | |
654 | | static void log_mixer_mode(sn76477_state *sn) |
| 738 | void sn76477_device::log_mixer_mode() |
655 | 739 | { |
656 | 740 | static const char *const desc[] = |
657 | 741 | { |
r26337 | r26338 | |
659 | 743 | "SLF/Noise", "SLF/VCO/Noise", "SLF/VCO", "Inhibit" |
660 | 744 | }; |
661 | 745 | |
662 | | LOG(1, ("SN76477 '%s': Mixer mode (25-27): %d [%s]\n", sn->device->tag(), sn->mixer_mode, desc[sn->mixer_mode])); |
| 746 | LOG(1, ("SN76477 '%s': Mixer mode (25-27): %d [%s]\n", tag(), m_mixer_mode, desc[m_mixer_mode])); |
663 | 747 | } |
664 | 748 | |
665 | 749 | |
666 | | static void log_envelope_mode(sn76477_state *sn) |
| 750 | void sn76477_device::log_envelope_mode() |
667 | 751 | { |
668 | 752 | static const char *const desc[] = |
669 | 753 | { |
670 | 754 | "VCO", "One-Shot", "Mixer Only", "VCO with Alternating Polarity" |
671 | 755 | }; |
672 | 756 | |
673 | | LOG(1, ("SN76477 '%s': Envelope mode (1,28): %d [%s]\n", sn->device->tag(), sn->envelope_mode, desc[sn->envelope_mode])); |
| 757 | LOG(1, ("SN76477 '%s': Envelope mode (1,28): %d [%s]\n", tag(), m_envelope_mode, desc[m_envelope_mode])); |
674 | 758 | } |
675 | 759 | |
676 | 760 | |
677 | | static void log_vco_mode(sn76477_state *sn) |
| 761 | void sn76477_device::log_vco_mode() |
678 | 762 | { |
679 | 763 | static const char *const desc[] = |
680 | 764 | { |
681 | 765 | "External (Pin 16)", "Internal (SLF)" |
682 | 766 | }; |
683 | 767 | |
684 | | LOG(1, ("SN76477 '%s': VCO mode (22): %d [%s]\n", sn->device->tag(), sn->vco_mode, desc[sn->vco_mode])); |
| 768 | LOG(1, ("SN76477 '%s': VCO mode (22): %d [%s]\n", tag(), m_vco_mode, desc[m_vco_mode])); |
685 | 769 | } |
686 | 770 | |
687 | 771 | |
688 | | static void log_one_shot_time(sn76477_state *sn) |
| 772 | void sn76477_device::log_one_shot_time() |
689 | 773 | { |
690 | | if (!sn->one_shot_cap_voltage_ext) |
| 774 | if (!m_one_shot_cap_voltage_ext) |
691 | 775 | { |
692 | | if (compute_one_shot_cap_charging_rate(sn) > 0) |
| 776 | if (compute_one_shot_cap_charging_rate() > 0) |
693 | 777 | { |
694 | | LOG(1, ("SN76477 '%s': One-shot time (23,24): %.4f sec\n", sn->device->tag(), ONE_SHOT_CAP_VOLTAGE_RANGE * (1 / compute_one_shot_cap_charging_rate(sn)))); |
| 778 | LOG(1, ("SN76477 '%s': One-shot time (23,24): %.4f sec\n", tag(), ONE_SHOT_CAP_VOLTAGE_RANGE * (1 / compute_one_shot_cap_charging_rate()))); |
695 | 779 | } |
696 | 780 | else |
697 | 781 | { |
698 | | LOG(1, ("SN76477 '%s': One-shot time (23,24): N/A\n", sn->device->tag())); |
| 782 | LOG(1, ("SN76477 '%s': One-shot time (23,24): N/A\n", tag())); |
699 | 783 | } |
700 | 784 | } |
701 | 785 | else |
702 | 786 | { |
703 | | LOG(1, ("SN76477 '%s': One-shot time (23,24): External (cap = %.2fV)\n", sn->device->tag(), sn->one_shot_cap_voltage)); |
| 787 | LOG(1, ("SN76477 '%s': One-shot time (23,24): External (cap = %.2fV)\n", tag(), m_one_shot_cap_voltage)); |
704 | 788 | } |
705 | 789 | } |
706 | 790 | |
707 | 791 | |
708 | | static void log_slf_freq(sn76477_state *sn) |
| 792 | void sn76477_device::log_slf_freq() |
709 | 793 | { |
710 | | if (!sn->slf_cap_voltage_ext) |
| 794 | if (!m_slf_cap_voltage_ext) |
711 | 795 | { |
712 | | if (compute_slf_cap_charging_rate(sn) > 0) |
| 796 | if (compute_slf_cap_charging_rate() > 0) |
713 | 797 | { |
714 | | double charging_time = (1 / compute_slf_cap_charging_rate(sn)) * SLF_CAP_VOLTAGE_RANGE; |
715 | | double discharging_time = (1 / compute_slf_cap_discharging_rate(sn)) * SLF_CAP_VOLTAGE_RANGE; |
| 798 | double charging_time = (1 / compute_slf_cap_charging_rate()) * SLF_CAP_VOLTAGE_RANGE; |
| 799 | double discharging_time = (1 / compute_slf_cap_discharging_rate()) * SLF_CAP_VOLTAGE_RANGE; |
716 | 800 | |
717 | | LOG(1, ("SN76477 '%s': SLF frequency (20,21): %.2f Hz\n", sn->device->tag(), 1 / (charging_time + discharging_time))); |
| 801 | LOG(1, ("SN76477 '%s': SLF frequency (20,21): %.2f Hz\n", tag(), 1 / (charging_time + discharging_time))); |
718 | 802 | } |
719 | 803 | else |
720 | 804 | { |
721 | | LOG(1, ("SN76477 '%s': SLF frequency (20,21): N/A\n", sn->device->tag())); |
| 805 | LOG(1, ("SN76477 '%s': SLF frequency (20,21): N/A\n", tag())); |
722 | 806 | } |
723 | 807 | } |
724 | 808 | else |
725 | 809 | { |
726 | | LOG(1, ("SN76477 '%s': SLF frequency (20,21): External (cap = %.2fV)\n", sn->device->tag(), sn->slf_cap_voltage)); |
| 810 | LOG(1, ("SN76477 '%s': SLF frequency (20,21): External (cap = %.2fV)\n", tag(), m_slf_cap_voltage)); |
727 | 811 | } |
728 | 812 | } |
729 | 813 | |
730 | 814 | |
731 | | static void log_vco_pitch_voltage(sn76477_state *sn) |
| 815 | void sn76477_device::log_vco_pitch_voltage() |
732 | 816 | { |
733 | | LOG(1, ("SN76477 '%s': VCO pitch voltage (19): %.2fV\n", sn->device->tag(), sn->pitch_voltage)); |
| 817 | LOG(1, ("SN76477 '%s': VCO pitch voltage (19): %.2fV\n", tag(), m_pitch_voltage)); |
734 | 818 | } |
735 | 819 | |
736 | 820 | |
737 | | static void log_vco_duty_cycle(sn76477_state *sn) |
| 821 | void sn76477_device::log_vco_duty_cycle() |
738 | 822 | { |
739 | | LOG(1, ("SN76477 '%s': VCO duty cycle (16,19): %.0f%%\n", sn->device->tag(), compute_vco_duty_cycle(sn) * 100.0)); |
| 823 | LOG(1, ("SN76477 '%s': VCO duty cycle (16,19): %.0f%%\n", tag(), compute_vco_duty_cycle() * 100.0)); |
740 | 824 | } |
741 | 825 | |
742 | 826 | |
743 | | static void log_vco_freq(sn76477_state *sn) |
| 827 | void sn76477_device::log_vco_freq() |
744 | 828 | { |
745 | | if (!sn->vco_cap_voltage_ext) |
| 829 | if (!m_vco_cap_voltage_ext) |
746 | 830 | { |
747 | | if (compute_vco_cap_charging_discharging_rate(sn) > 0) |
| 831 | if (compute_vco_cap_charging_discharging_rate() > 0) |
748 | 832 | { |
749 | | double min_freq = compute_vco_cap_charging_discharging_rate(sn) / (2 * VCO_CAP_VOLTAGE_RANGE); |
750 | | double max_freq = compute_vco_cap_charging_discharging_rate(sn) / (2 * VCO_TO_SLF_VOLTAGE_DIFF); |
| 833 | double min_freq = compute_vco_cap_charging_discharging_rate() / (2 * VCO_CAP_VOLTAGE_RANGE); |
| 834 | double max_freq = compute_vco_cap_charging_discharging_rate() / (2 * VCO_TO_SLF_VOLTAGE_DIFF); |
751 | 835 | |
752 | | LOG(1, ("SN76477 '%s': VCO frequency (17,18): %.2f Hz - %.1f Hz\n", sn->device->tag(), min_freq, max_freq)); |
| 836 | LOG(1, ("SN76477 '%s': VCO frequency (17,18): %.2f Hz - %.1f Hz\n", tag(), min_freq, max_freq)); |
753 | 837 | } |
754 | 838 | else |
755 | 839 | { |
756 | | LOG(1, ("SN76477 '%s': VCO frequency (17,18): N/A\n", sn->device->tag())); |
| 840 | LOG(1, ("SN76477 '%s': VCO frequency (17,18): N/A\n", tag())); |
757 | 841 | } |
758 | 842 | } |
759 | 843 | else |
760 | 844 | { |
761 | | LOG(1, ("SN76477 '%s': VCO frequency (17,18): External (cap = %.2fV)\n", sn->device->tag(), sn->vco_cap_voltage)); |
| 845 | LOG(1, ("SN76477 '%s': VCO frequency (17,18): External (cap = %.2fV)\n", tag(), m_vco_cap_voltage)); |
762 | 846 | } |
763 | 847 | } |
764 | 848 | |
765 | 849 | |
766 | | static void log_vco_ext_voltage(sn76477_state *sn) |
| 850 | void sn76477_device::log_vco_ext_voltage() |
767 | 851 | { |
768 | | if (sn->vco_voltage <= VCO_MAX_EXT_VOLTAGE) |
| 852 | if (m_vco_voltage <= VCO_MAX_EXT_VOLTAGE) |
769 | 853 | { |
770 | | double min_freq = compute_vco_cap_charging_discharging_rate(sn) / (2 * VCO_CAP_VOLTAGE_RANGE); |
771 | | double max_freq = compute_vco_cap_charging_discharging_rate(sn) / (2 * VCO_TO_SLF_VOLTAGE_DIFF); |
| 854 | double min_freq = compute_vco_cap_charging_discharging_rate() / (2 * VCO_CAP_VOLTAGE_RANGE); |
| 855 | double max_freq = compute_vco_cap_charging_discharging_rate() / (2 * VCO_TO_SLF_VOLTAGE_DIFF); |
772 | 856 | |
773 | | LOG(1, ("SN76477 '%s': VCO ext. voltage (16): %.2fV (%.2f Hz)\n", sn->device->tag(), |
774 | | sn->vco_voltage, |
775 | | min_freq + ((max_freq - min_freq) * sn->vco_voltage / VCO_MAX_EXT_VOLTAGE))); |
| 857 | LOG(1, ("SN76477 '%s': VCO ext. voltage (16): %.2fV (%.2f Hz)\n", tag(), |
| 858 | m_vco_voltage, |
| 859 | min_freq + ((max_freq - min_freq) * m_vco_voltage / VCO_MAX_EXT_VOLTAGE))); |
776 | 860 | } |
777 | 861 | else |
778 | 862 | { |
779 | | LOG(1, ("SN76477 '%s': VCO ext. voltage (16): %.2fV (saturated, no output)\n", sn->device->tag(), sn->vco_voltage)); |
| 863 | LOG(1, ("SN76477 '%s': VCO ext. voltage (16): %.2fV (saturated, no output)\n", tag(), m_vco_voltage)); |
780 | 864 | } |
781 | 865 | } |
782 | 866 | |
783 | 867 | |
784 | | static void log_noise_gen_freq(sn76477_state *sn) |
| 868 | void sn76477_device::log_noise_gen_freq() |
785 | 869 | { |
786 | | if (sn->noise_clock_ext) |
| 870 | if (m_noise_clock_ext) |
787 | 871 | { |
788 | | LOG(1, ("SN76477 '%s': Noise gen frequency (4): External\n", sn->device->tag())); |
| 872 | LOG(1, ("SN76477 '%s': Noise gen frequency (4): External\n", tag())); |
789 | 873 | } |
790 | 874 | else |
791 | 875 | { |
792 | | if (compute_noise_gen_freq(sn) > 0) |
| 876 | if (compute_noise_gen_freq() > 0) |
793 | 877 | { |
794 | | LOG(1, ("SN76477 '%s': Noise gen frequency (4): %d Hz\n", sn->device->tag(), compute_noise_gen_freq(sn))); |
| 878 | LOG(1, ("SN76477 '%s': Noise gen frequency (4): %d Hz\n", tag(), compute_noise_gen_freq())); |
795 | 879 | } |
796 | 880 | else |
797 | 881 | { |
798 | | LOG(1, ("SN76477 '%s': Noise gen frequency (4): N/A\n", sn->device->tag())); |
| 882 | LOG(1, ("SN76477 '%s': Noise gen frequency (4): N/A\n", tag())); |
799 | 883 | } |
800 | 884 | } |
801 | 885 | } |
802 | 886 | |
803 | 887 | |
804 | | static void log_noise_filter_freq(sn76477_state *sn) |
| 888 | void sn76477_device::log_noise_filter_freq() |
805 | 889 | { |
806 | | if (!sn->noise_filter_cap_voltage_ext) |
| 890 | if (!m_noise_filter_cap_voltage_ext) |
807 | 891 | { |
808 | | double charging_rate = compute_noise_filter_cap_charging_rate(sn); |
| 892 | double charging_rate = compute_noise_filter_cap_charging_rate(); |
809 | 893 | |
810 | 894 | if (charging_rate > 0) |
811 | 895 | { |
r26337 | r26338 | |
814 | 898 | double charging_time = (1 / charging_rate) * NOISE_CAP_VOLTAGE_RANGE; |
815 | 899 | double discharging_time = (1 / charging_rate) * NOISE_CAP_VOLTAGE_RANGE; |
816 | 900 | |
817 | | LOG(1, ("SN76477 '%s': Noise filter frequency (5,6): %.0f Hz\n", sn->device->tag(), 1 / (charging_time + discharging_time))); |
| 901 | LOG(1, ("SN76477 '%s': Noise filter frequency (5,6): %.0f Hz\n", tag(), 1 / (charging_time + discharging_time))); |
818 | 902 | } |
819 | 903 | else |
820 | 904 | { |
821 | | LOG(1, ("SN76477 '%s': Noise filter frequency (5,6): Very Large (Filtering Disabled)\n", sn->device->tag())); |
| 905 | LOG(1, ("SN76477 '%s': Noise filter frequency (5,6): Very Large (Filtering Disabled)\n", tag())); |
822 | 906 | } |
823 | 907 | } |
824 | 908 | else |
825 | 909 | { |
826 | | LOG(1, ("SN76477 '%s': Noise filter frequency (5,6): N/A\n", sn->device->tag())); |
| 910 | LOG(1, ("SN76477 '%s': Noise filter frequency (5,6): N/A\n", tag())); |
827 | 911 | } |
828 | 912 | } |
829 | 913 | else |
830 | 914 | { |
831 | | LOG(1, ("SN76477 '%s': Noise filter frequency (5,6): External (cap = %.2fV)\n", sn->device->tag(), sn->noise_filter_cap)); |
| 915 | LOG(1, ("SN76477 '%s': Noise filter frequency (5,6): External (cap = %.2fV)\n", tag(), m_noise_filter_cap)); |
832 | 916 | } |
833 | 917 | } |
834 | 918 | |
835 | 919 | |
836 | | static void log_attack_time(sn76477_state *sn) |
| 920 | void sn76477_device::log_attack_time() |
837 | 921 | { |
838 | | if (!sn->attack_decay_cap_voltage_ext) |
| 922 | if (!m_attack_decay_cap_voltage_ext) |
839 | 923 | { |
840 | | if (compute_attack_decay_cap_charging_rate(sn) > 0) |
| 924 | if (compute_attack_decay_cap_charging_rate() > 0) |
841 | 925 | { |
842 | | LOG(1, ("SN76477 '%s': Attack time (8,10): %.4f sec\n", sn->device->tag(), AD_CAP_VOLTAGE_RANGE * (1 / compute_attack_decay_cap_charging_rate(sn)))); |
| 926 | LOG(1, ("SN76477 '%s': Attack time (8,10): %.4f sec\n", tag(), AD_CAP_VOLTAGE_RANGE * (1 / compute_attack_decay_cap_charging_rate()))); |
843 | 927 | } |
844 | 928 | else |
845 | 929 | { |
846 | | LOG(1, ("SN76477 '%s': Attack time (8,10): N/A\n", sn->device->tag())); |
| 930 | LOG(1, ("SN76477 '%s': Attack time (8,10): N/A\n", tag())); |
847 | 931 | } |
848 | 932 | } |
849 | 933 | else |
850 | 934 | { |
851 | | LOG(1, ("SN76477 '%s': Attack time (8,10): External (cap = %.2fV)\n", sn->device->tag(), sn->attack_decay_cap_voltage)); |
| 935 | LOG(1, ("SN76477 '%s': Attack time (8,10): External (cap = %.2fV)\n", tag(), m_attack_decay_cap_voltage)); |
852 | 936 | } |
853 | 937 | } |
854 | 938 | |
855 | 939 | |
856 | | static void log_decay_time(sn76477_state *sn) |
| 940 | void sn76477_device::log_decay_time() |
857 | 941 | { |
858 | | if (!sn->attack_decay_cap_voltage_ext) |
| 942 | if (!m_attack_decay_cap_voltage_ext) |
859 | 943 | { |
860 | | if (compute_attack_decay_cap_discharging_rate(sn) > 0) |
| 944 | if (compute_attack_decay_cap_discharging_rate() > 0) |
861 | 945 | { |
862 | | LOG(1, ("SN76477 '%s': Decay time (7,8): %.4f sec\n", sn->device->tag(), AD_CAP_VOLTAGE_RANGE * (1 / compute_attack_decay_cap_discharging_rate(sn)))); |
| 946 | LOG(1, ("SN76477 '%s': Decay time (7,8): %.4f sec\n", tag(), AD_CAP_VOLTAGE_RANGE * (1 / compute_attack_decay_cap_discharging_rate()))); |
863 | 947 | } |
864 | 948 | else |
865 | 949 | { |
866 | | LOG(1, ("SN76477 '%s': Decay time (8,10): N/A\n", sn->device->tag())); |
| 950 | LOG(1, ("SN76477 '%s': Decay time (8,10): N/A\n", tag())); |
867 | 951 | } |
868 | 952 | } |
869 | 953 | else |
870 | 954 | { |
871 | | LOG(1, ("SN76477 '%s': Decay time (7, 8): External (cap = %.2fV)\n", sn->device->tag(), sn->attack_decay_cap_voltage)); |
| 955 | LOG(1, ("SN76477 '%s': Decay time (7, 8): External (cap = %.2fV)\n", tag(), m_attack_decay_cap_voltage)); |
872 | 956 | } |
873 | 957 | } |
874 | 958 | |
875 | 959 | |
876 | | static void log_voltage_out(sn76477_state *sn) |
| 960 | void sn76477_device::log_voltage_out() |
877 | 961 | { |
878 | 962 | LOG(1, ("SN76477 '%s': Voltage OUT range (11,12): %.2fV - %.2fV (clips above %.2fV)\n", |
879 | | sn->device->tag(), |
880 | | OUT_CENTER_LEVEL_VOLTAGE + compute_center_to_peak_voltage_out(sn) * out_neg_gain[(int)(AD_CAP_VOLTAGE_MAX * 10)], |
881 | | OUT_CENTER_LEVEL_VOLTAGE + compute_center_to_peak_voltage_out(sn) * out_pos_gain[(int)(AD_CAP_VOLTAGE_MAX * 10)], |
| 963 | tag(), |
| 964 | OUT_CENTER_LEVEL_VOLTAGE + compute_center_to_peak_voltage_out() * out_neg_gain[(int)(AD_CAP_VOLTAGE_MAX * 10)], |
| 965 | OUT_CENTER_LEVEL_VOLTAGE + compute_center_to_peak_voltage_out() * out_pos_gain[(int)(AD_CAP_VOLTAGE_MAX * 10)], |
882 | 966 | OUT_HIGH_CLIP_THRESHOLD)); |
883 | 967 | } |
884 | 968 | |
885 | 969 | |
886 | | static void log_complete_state(sn76477_state *sn) |
| 970 | void sn76477_device::log_complete_state() |
887 | 971 | { |
888 | | log_enable_line(sn); |
889 | | log_mixer_mode(sn); |
890 | | log_envelope_mode(sn); |
891 | | log_vco_mode(sn); |
892 | | log_one_shot_time(sn); |
893 | | log_slf_freq(sn); |
894 | | log_vco_freq(sn); |
895 | | log_vco_ext_voltage(sn); |
896 | | log_vco_pitch_voltage(sn); |
897 | | log_vco_duty_cycle(sn); |
898 | | log_noise_filter_freq(sn); |
899 | | log_noise_gen_freq(sn); |
900 | | log_attack_time(sn); |
901 | | log_decay_time(sn); |
902 | | log_voltage_out(sn); |
| 972 | log_enable_line(); |
| 973 | log_mixer_mode(); |
| 974 | log_envelope_mode(); |
| 975 | log_vco_mode(); |
| 976 | log_one_shot_time(); |
| 977 | log_slf_freq(); |
| 978 | log_vco_freq(); |
| 979 | log_vco_ext_voltage(); |
| 980 | log_vco_pitch_voltage(); |
| 981 | log_vco_duty_cycle(); |
| 982 | log_noise_filter_freq(); |
| 983 | log_noise_gen_freq(); |
| 984 | log_attack_time(); |
| 985 | log_decay_time(); |
| 986 | log_voltage_out(); |
903 | 987 | } |
904 | 988 | |
905 | 989 | |
r26337 | r26338 | |
911 | 995 | *****************************************************************************/ |
912 | 996 | |
913 | 997 | |
914 | | static void open_wav_file(sn76477_state *sn) |
| 998 | void sn76477_device::open_wav_file() |
915 | 999 | { |
916 | 1000 | char wav_file_name[30]; |
917 | 1001 | |
918 | | sprintf(wav_file_name, LOG_WAV_FILE_NAME, sn->device->tag()); |
919 | | sn->file = wav_open(wav_file_name, sn->sample_rate, 2); |
| 1002 | sprintf(wav_file_name, LOG_WAV_FILE_NAME, tag()); |
| 1003 | m_file = wav_open(wav_file_name, m_our_sample_rate, 2); |
920 | 1004 | |
921 | | LOG(1, ("SN76477 '%s': Logging output: %s\n", sn->device->tag(), wav_file_name)); |
| 1005 | LOG(1, ("SN76477 '%s': Logging output: %s\n", tag(), wav_file_name)); |
922 | 1006 | } |
923 | 1007 | |
924 | 1008 | |
925 | | static void close_wav_file(sn76477_state *sn) |
| 1009 | void sn76477_device::close_wav_file() |
926 | 1010 | { |
927 | | wav_close(sn->file); |
| 1011 | wav_close(m_file); |
928 | 1012 | } |
929 | 1013 | |
930 | 1014 | |
931 | | static void add_wav_data(sn76477_state *sn, INT16 data_l, INT16 data_r) |
| 1015 | void sn76477_device::add_wav_data(INT16 data_l, INT16 data_r) |
932 | 1016 | { |
933 | | wav_add_data_16lr(sn->file, &data_l, &data_r, 1); |
| 1017 | wav_add_data_16lr(m_file, &data_l, &data_r, 1); |
934 | 1018 | } |
935 | 1019 | |
936 | 1020 | |
r26337 | r26338 | |
941 | 1025 | * |
942 | 1026 | *****************************************************************************/ |
943 | 1027 | |
944 | | static void intialize_noise(sn76477_state *sn) |
| 1028 | void sn76477_device::intialize_noise() |
945 | 1029 | { |
946 | | sn->rng = 0; |
| 1030 | m_rng = 0; |
947 | 1031 | } |
948 | 1032 | |
949 | 1033 | |
950 | | INLINE UINT32 generate_next_real_noise_bit(sn76477_state *sn) |
| 1034 | inline UINT32 sn76477_device::generate_next_real_noise_bit() |
951 | 1035 | { |
952 | | UINT32 out = ((sn->rng >> 28) & 1) ^ ((sn->rng >> 0) & 1); |
| 1036 | UINT32 out = ((m_rng >> 28) & 1) ^ ((m_rng >> 0) & 1); |
953 | 1037 | |
954 | 1038 | /* if bits 0-4 and 28 are all zero then force the output to 1 */ |
955 | | if ((sn->rng & 0x1000001f) == 0) |
| 1039 | if ((m_rng & 0x1000001f) == 0) |
956 | 1040 | { |
957 | 1041 | out = 1; |
958 | 1042 | } |
959 | 1043 | |
960 | | sn->rng = (sn->rng >> 1) | (out << 30); |
| 1044 | m_rng = (m_rng >> 1) | (out << 30); |
961 | 1045 | |
962 | 1046 | return out; |
963 | 1047 | } |
r26337 | r26338 | |
970 | 1054 | * |
971 | 1055 | *****************************************************************************/ |
972 | 1056 | |
973 | | static void _SN76477_enable_w(sn76477_state *sn, UINT32 data) |
| 1057 | void sn76477_device::_SN76477_enable_w(UINT32 data) |
974 | 1058 | { |
975 | | sn->enable = data; |
| 1059 | m_enable = data; |
976 | 1060 | |
977 | 1061 | /* if falling edge */ |
978 | | if (!sn->enable) |
| 1062 | if (!m_enable) |
979 | 1063 | { |
980 | 1064 | /* start the attack phase */ |
981 | | sn->attack_decay_cap_voltage = AD_CAP_VOLTAGE_MIN; |
| 1065 | m_attack_decay_cap_voltage = AD_CAP_VOLTAGE_MIN; |
982 | 1066 | |
983 | 1067 | /* one-shot runs regardless of envelope mode */ |
984 | | sn->one_shot_running_ff = 1; |
| 1068 | m_one_shot_running_ff = 1; |
985 | 1069 | } |
986 | 1070 | } |
987 | 1071 | |
988 | 1072 | |
989 | | static void SN76477_test_enable_w(sn76477_state *sn, UINT32 data) |
| 1073 | void sn76477_device::SN76477_test_enable_w(UINT32 data) |
990 | 1074 | { |
991 | | if (data != sn->enable) |
| 1075 | if (data != m_enable) |
992 | 1076 | { |
993 | | sn->channel->update(); |
| 1077 | m_channel->update(); |
994 | 1078 | |
995 | | _SN76477_enable_w(sn, data); |
| 1079 | _SN76477_enable_w(data); |
996 | 1080 | |
997 | | log_enable_line(sn); |
| 1081 | log_enable_line(); |
998 | 1082 | } |
999 | 1083 | } |
1000 | 1084 | |
1001 | 1085 | |
1002 | | WRITE_LINE_DEVICE_HANDLER( sn76477_enable_w ) |
| 1086 | WRITE_LINE_MEMBER( sn76477_device::enable_w ) |
1003 | 1087 | { |
1004 | 1088 | #if TEST_MODE == 0 |
1005 | | sn76477_state *sn = get_safe_token(device); |
1006 | | |
1007 | 1089 | CHECK_CHIP_NUM_AND_BOOLEAN; |
1008 | 1090 | |
1009 | | SN76477_test_enable_w(sn, state); |
| 1091 | SN76477_test_enable_w(state); |
1010 | 1092 | #endif |
1011 | 1093 | } |
1012 | 1094 | |
r26337 | r26338 | |
1018 | 1100 | * |
1019 | 1101 | *****************************************************************************/ |
1020 | 1102 | |
1021 | | static void _SN76477_mixer_a_w(sn76477_state *sn, UINT32 data) |
| 1103 | void sn76477_device::_SN76477_mixer_a_w(UINT32 data) |
1022 | 1104 | { |
1023 | | sn->mixer_mode = (sn->mixer_mode & ~0x01) | (data << 0); |
| 1105 | m_mixer_mode = (m_mixer_mode & ~0x01) | (data << 0); |
1024 | 1106 | } |
1025 | 1107 | |
1026 | 1108 | |
1027 | | WRITE_LINE_DEVICE_HANDLER( sn76477_mixer_a_w ) |
| 1109 | WRITE_LINE_MEMBER( sn76477_device::mixer_a_w ) |
1028 | 1110 | { |
1029 | 1111 | #if TEST_MODE == 0 |
1030 | | sn76477_state *sn = get_safe_token(device); |
1031 | | |
1032 | 1112 | CHECK_CHIP_NUM_AND_BOOLEAN; |
1033 | 1113 | |
1034 | | if (state != ((sn->mixer_mode >> 0) & 0x01)) |
| 1114 | if (state != ((m_mixer_mode >> 0) & 0x01)) |
1035 | 1115 | { |
1036 | | sn->channel->update(); |
| 1116 | m_channel->update(); |
1037 | 1117 | |
1038 | | _SN76477_mixer_a_w(sn, state); |
| 1118 | _SN76477_mixer_a_w(state); |
1039 | 1119 | |
1040 | | log_mixer_mode(sn); |
| 1120 | log_mixer_mode(); |
1041 | 1121 | } |
1042 | 1122 | #endif |
1043 | 1123 | } |
1044 | 1124 | |
1045 | 1125 | |
1046 | | static void _SN76477_mixer_b_w(sn76477_state *sn, UINT32 data) |
| 1126 | void sn76477_device::_SN76477_mixer_b_w(UINT32 data) |
1047 | 1127 | { |
1048 | | sn->mixer_mode = (sn->mixer_mode & ~0x02) | (data << 1); |
| 1128 | m_mixer_mode = (m_mixer_mode & ~0x02) | (data << 1); |
1049 | 1129 | } |
1050 | 1130 | |
1051 | 1131 | |
1052 | | WRITE_LINE_DEVICE_HANDLER( sn76477_mixer_b_w ) |
| 1132 | WRITE_LINE_MEMBER( sn76477_device::mixer_b_w ) |
1053 | 1133 | { |
1054 | 1134 | #if TEST_MODE == 0 |
1055 | | sn76477_state *sn = get_safe_token(device); |
1056 | | |
1057 | 1135 | CHECK_CHIP_NUM_AND_BOOLEAN; |
1058 | 1136 | |
1059 | | if (state != ((sn->mixer_mode >> 1) & 0x01)) |
| 1137 | if (state != ((m_mixer_mode >> 1) & 0x01)) |
1060 | 1138 | { |
1061 | | sn->channel->update(); |
| 1139 | m_channel->update(); |
1062 | 1140 | |
1063 | | _SN76477_mixer_b_w(sn, state); |
| 1141 | _SN76477_mixer_b_w(state); |
1064 | 1142 | |
1065 | | log_mixer_mode(sn); |
| 1143 | log_mixer_mode(); |
1066 | 1144 | } |
1067 | 1145 | #endif |
1068 | 1146 | } |
1069 | 1147 | |
1070 | 1148 | |
1071 | | static void _SN76477_mixer_c_w(sn76477_state *sn, UINT32 data) |
| 1149 | void sn76477_device::_SN76477_mixer_c_w(UINT32 data) |
1072 | 1150 | { |
1073 | | sn->mixer_mode = (sn->mixer_mode & ~0x04) | (data << 2); |
| 1151 | m_mixer_mode = (m_mixer_mode & ~0x04) | (data << 2); |
1074 | 1152 | } |
1075 | 1153 | |
1076 | 1154 | |
1077 | | WRITE_LINE_DEVICE_HANDLER( sn76477_mixer_c_w ) |
| 1155 | WRITE_LINE_MEMBER( sn76477_device::mixer_c_w ) |
1078 | 1156 | { |
1079 | 1157 | #if TEST_MODE == 0 |
1080 | | sn76477_state *sn = get_safe_token(device); |
1081 | | |
1082 | 1158 | CHECK_CHIP_NUM_AND_BOOLEAN; |
1083 | 1159 | |
1084 | | if (state != ((sn->mixer_mode >> 2) & 0x01)) |
| 1160 | if (state != ((m_mixer_mode >> 2) & 0x01)) |
1085 | 1161 | { |
1086 | | sn->channel->update(); |
| 1162 | m_channel->update(); |
1087 | 1163 | |
1088 | | _SN76477_mixer_c_w(sn, state); |
| 1164 | _SN76477_mixer_c_w(state); |
1089 | 1165 | |
1090 | | log_mixer_mode(sn); |
| 1166 | log_mixer_mode(); |
1091 | 1167 | } |
1092 | 1168 | #endif |
1093 | 1169 | } |
r26337 | r26338 | |
1100 | 1176 | * |
1101 | 1177 | *****************************************************************************/ |
1102 | 1178 | |
1103 | | static void _SN76477_envelope_1_w(sn76477_state *sn, UINT32 data) |
| 1179 | void sn76477_device::_SN76477_envelope_1_w(UINT32 data) |
1104 | 1180 | { |
1105 | | sn->envelope_mode = (sn->envelope_mode & ~0x01) | (data << 0); |
| 1181 | m_envelope_mode = (m_envelope_mode & ~0x01) | (data << 0); |
1106 | 1182 | } |
1107 | 1183 | |
1108 | 1184 | |
1109 | | WRITE_LINE_DEVICE_HANDLER( sn76477_envelope_1_w ) |
| 1185 | WRITE_LINE_MEMBER( sn76477_device::envelope_1_w ) |
1110 | 1186 | { |
1111 | 1187 | #if TEST_MODE == 0 |
1112 | | sn76477_state *sn = get_safe_token(device); |
1113 | | |
1114 | 1188 | CHECK_CHIP_NUM_AND_BOOLEAN; |
1115 | 1189 | |
1116 | | if (state != ((sn->envelope_mode >> 0) & 0x01)) |
| 1190 | if (state != ((m_envelope_mode >> 0) & 0x01)) |
1117 | 1191 | { |
1118 | | sn->channel->update(); |
| 1192 | m_channel->update(); |
1119 | 1193 | |
1120 | | _SN76477_envelope_1_w(sn, state); |
| 1194 | _SN76477_envelope_1_w(state); |
1121 | 1195 | |
1122 | | log_envelope_mode(sn); |
| 1196 | log_envelope_mode(); |
1123 | 1197 | } |
1124 | 1198 | #endif |
1125 | 1199 | } |
1126 | 1200 | |
1127 | 1201 | |
1128 | | static void _SN76477_envelope_2_w(sn76477_state *sn, UINT32 data) |
| 1202 | void sn76477_device::_SN76477_envelope_2_w(UINT32 data) |
1129 | 1203 | { |
1130 | | sn->envelope_mode = (sn->envelope_mode & ~0x02) | (data << 1); |
| 1204 | m_envelope_mode = (m_envelope_mode & ~0x02) | (data << 1); |
1131 | 1205 | } |
1132 | 1206 | |
1133 | 1207 | |
1134 | | WRITE_LINE_DEVICE_HANDLER( sn76477_envelope_2_w ) |
| 1208 | WRITE_LINE_MEMBER( sn76477_device::envelope_2_w ) |
1135 | 1209 | { |
1136 | 1210 | #if TEST_MODE == 0 |
1137 | | sn76477_state *sn = get_safe_token(device); |
1138 | | |
1139 | 1211 | CHECK_CHIP_NUM_AND_BOOLEAN; |
1140 | 1212 | |
1141 | | if (state != ((sn->envelope_mode >> 1) & 0x01)) |
| 1213 | if (state != ((m_envelope_mode >> 1) & 0x01)) |
1142 | 1214 | { |
1143 | | sn->channel->update(); |
| 1215 | m_channel->update(); |
1144 | 1216 | |
1145 | | _SN76477_envelope_2_w(sn, state); |
| 1217 | _SN76477_envelope_2_w(state); |
1146 | 1218 | |
1147 | | log_envelope_mode(sn); |
| 1219 | log_envelope_mode(); |
1148 | 1220 | } |
1149 | 1221 | #endif |
1150 | 1222 | } |
r26337 | r26338 | |
1157 | 1229 | * |
1158 | 1230 | *****************************************************************************/ |
1159 | 1231 | |
1160 | | static void _SN76477_vco_w(sn76477_state *sn, UINT32 data) |
| 1232 | void sn76477_device::_SN76477_vco_w(UINT32 data) |
1161 | 1233 | { |
1162 | | sn->vco_mode = data; |
| 1234 | m_vco_mode = data; |
1163 | 1235 | } |
1164 | 1236 | |
1165 | 1237 | |
1166 | | WRITE_LINE_DEVICE_HANDLER( sn76477_vco_w ) |
| 1238 | WRITE_LINE_MEMBER( sn76477_device::vco_w ) |
1167 | 1239 | { |
1168 | 1240 | #if TEST_MODE == 0 |
1169 | | sn76477_state *sn = get_safe_token(device); |
1170 | | |
1171 | 1241 | CHECK_CHIP_NUM_AND_BOOLEAN; |
1172 | 1242 | |
1173 | | if (state != sn->vco_mode) |
| 1243 | if (state != m_vco_mode) |
1174 | 1244 | { |
1175 | | sn->channel->update(); |
| 1245 | m_channel->update(); |
1176 | 1246 | |
1177 | | _SN76477_vco_w(sn, state); |
| 1247 | _SN76477_vco_w(state); |
1178 | 1248 | |
1179 | | log_vco_mode(sn); |
| 1249 | log_vco_mode(); |
1180 | 1250 | } |
1181 | 1251 | #endif |
1182 | 1252 | } |
r26337 | r26338 | |
1189 | 1259 | * |
1190 | 1260 | *****************************************************************************/ |
1191 | 1261 | |
1192 | | static void _SN76477_one_shot_res_w(sn76477_state *sn, double data) |
| 1262 | void sn76477_device::_SN76477_one_shot_res_w(double data) |
1193 | 1263 | { |
1194 | | sn->one_shot_res = data; |
| 1264 | m_one_shot_res = data; |
1195 | 1265 | } |
1196 | 1266 | |
1197 | 1267 | |
1198 | | void sn76477_one_shot_res_w(device_t *device, double data) |
| 1268 | void sn76477_device::one_shot_res_w(double data) |
1199 | 1269 | { |
1200 | 1270 | #if TEST_MODE == 0 |
1201 | | sn76477_state *sn = get_safe_token(device); |
1202 | | |
1203 | 1271 | CHECK_CHIP_NUM_AND_POSITIVE; |
1204 | 1272 | |
1205 | | if (data != sn->one_shot_res) |
| 1273 | if (data != m_one_shot_res) |
1206 | 1274 | { |
1207 | | sn->channel->update(); |
| 1275 | m_channel->update(); |
1208 | 1276 | |
1209 | | _SN76477_one_shot_res_w(sn, data); |
| 1277 | _SN76477_one_shot_res_w(data); |
1210 | 1278 | |
1211 | | log_one_shot_time(sn); |
| 1279 | log_one_shot_time(); |
1212 | 1280 | } |
1213 | 1281 | #endif |
1214 | 1282 | } |
r26337 | r26338 | |
1221 | 1289 | * |
1222 | 1290 | *****************************************************************************/ |
1223 | 1291 | |
1224 | | static void _SN76477_one_shot_cap_w(sn76477_state *sn, double data) |
| 1292 | void sn76477_device::_SN76477_one_shot_cap_w(double data) |
1225 | 1293 | { |
1226 | | sn->one_shot_cap = data; |
| 1294 | m_one_shot_cap = data; |
1227 | 1295 | } |
1228 | 1296 | |
1229 | 1297 | |
1230 | | void sn76477_one_shot_cap_w(device_t *device, double data) |
| 1298 | void sn76477_device::one_shot_cap_w(double data) |
1231 | 1299 | { |
1232 | 1300 | #if TEST_MODE == 0 |
1233 | | sn76477_state *sn = get_safe_token(device); |
1234 | | |
1235 | 1301 | CHECK_CHIP_NUM_AND_POSITIVE; |
1236 | 1302 | |
1237 | | if (data != sn->one_shot_cap) |
| 1303 | if (data != m_one_shot_cap) |
1238 | 1304 | { |
1239 | | sn->channel->update(); |
| 1305 | m_channel->update(); |
1240 | 1306 | |
1241 | | _SN76477_one_shot_cap_w(sn, data); |
| 1307 | _SN76477_one_shot_cap_w(data); |
1242 | 1308 | |
1243 | | log_one_shot_time(sn); |
| 1309 | log_one_shot_time(); |
1244 | 1310 | } |
1245 | 1311 | #endif |
1246 | 1312 | } |
r26337 | r26338 | |
1253 | 1319 | * |
1254 | 1320 | *****************************************************************************/ |
1255 | 1321 | |
1256 | | void sn76477_one_shot_cap_voltage_w(device_t *device, double data) |
| 1322 | void sn76477_device::one_shot_cap_voltage_w(double data) |
1257 | 1323 | { |
1258 | 1324 | #if TEST_MODE == 0 |
1259 | | sn76477_state *sn = get_safe_token(device); |
1260 | | |
1261 | 1325 | CHECK_CHIP_NUM_AND_CAP_VOLTAGE; |
1262 | 1326 | |
1263 | 1327 | if (data == SN76477_EXTERNAL_VOLTAGE_DISCONNECT) |
1264 | 1328 | { |
1265 | 1329 | /* switch to internal, if not already */ |
1266 | | if (sn->one_shot_cap_voltage_ext) |
| 1330 | if (m_one_shot_cap_voltage_ext) |
1267 | 1331 | { |
1268 | | sn->channel->update(); |
| 1332 | m_channel->update(); |
1269 | 1333 | |
1270 | | sn->one_shot_cap_voltage_ext = 0; |
| 1334 | m_one_shot_cap_voltage_ext = 0; |
1271 | 1335 | |
1272 | | log_one_shot_time(sn); |
| 1336 | log_one_shot_time(); |
1273 | 1337 | } |
1274 | 1338 | } |
1275 | 1339 | else |
1276 | 1340 | { |
1277 | 1341 | /* set the voltage on the cap */ |
1278 | | if (!sn->one_shot_cap_voltage_ext || (data != sn->one_shot_cap_voltage)) |
| 1342 | if (!m_one_shot_cap_voltage_ext || (data != m_one_shot_cap_voltage)) |
1279 | 1343 | { |
1280 | | sn->channel->update(); |
| 1344 | m_channel->update(); |
1281 | 1345 | |
1282 | | sn->one_shot_cap_voltage_ext = 1; |
1283 | | sn->one_shot_cap_voltage = data; |
| 1346 | m_one_shot_cap_voltage_ext = 1; |
| 1347 | m_one_shot_cap_voltage = data; |
1284 | 1348 | |
1285 | | log_one_shot_time(sn); |
| 1349 | log_one_shot_time(); |
1286 | 1350 | } |
1287 | 1351 | } |
1288 | 1352 | #endif |
r26337 | r26338 | |
1296 | 1360 | * |
1297 | 1361 | *****************************************************************************/ |
1298 | 1362 | |
1299 | | static void _SN76477_slf_res_w(sn76477_state *sn, double data) |
| 1363 | void sn76477_device::_SN76477_slf_res_w(double data) |
1300 | 1364 | { |
1301 | | sn->slf_res = data; |
| 1365 | m_slf_res = data; |
1302 | 1366 | } |
1303 | 1367 | |
1304 | 1368 | |
1305 | | void sn76477_slf_res_w(device_t *device, double data) |
| 1369 | void sn76477_device::slf_res_w(double data) |
1306 | 1370 | { |
1307 | 1371 | #if TEST_MODE == 0 |
1308 | | sn76477_state *sn = get_safe_token(device); |
1309 | | |
1310 | 1372 | CHECK_CHIP_NUM_AND_POSITIVE; |
1311 | 1373 | |
1312 | | if (data != sn->slf_res) |
| 1374 | if (data != m_slf_res) |
1313 | 1375 | { |
1314 | | sn->channel->update(); |
| 1376 | m_channel->update(); |
1315 | 1377 | |
1316 | | _SN76477_slf_res_w(sn, data); |
| 1378 | _SN76477_slf_res_w(data); |
1317 | 1379 | |
1318 | | log_slf_freq(sn); |
| 1380 | log_slf_freq(); |
1319 | 1381 | } |
1320 | 1382 | #endif |
1321 | 1383 | } |
r26337 | r26338 | |
1328 | 1390 | * |
1329 | 1391 | *****************************************************************************/ |
1330 | 1392 | |
1331 | | static void _SN76477_slf_cap_w(sn76477_state *sn, double data) |
| 1393 | void sn76477_device::_SN76477_slf_cap_w(double data) |
1332 | 1394 | { |
1333 | | sn->slf_cap = data; |
| 1395 | m_slf_cap = data; |
1334 | 1396 | } |
1335 | 1397 | |
1336 | 1398 | |
1337 | | void sn76477_slf_cap_w(device_t *device, double data) |
| 1399 | void sn76477_device::slf_cap_w(double data) |
1338 | 1400 | { |
1339 | 1401 | #if TEST_MODE == 0 |
1340 | | sn76477_state *sn = get_safe_token(device); |
1341 | | |
1342 | 1402 | CHECK_CHIP_NUM_AND_POSITIVE; |
1343 | 1403 | |
1344 | | if (data != sn->slf_cap) |
| 1404 | if (data != m_slf_cap) |
1345 | 1405 | { |
1346 | | sn->channel->update(); |
| 1406 | m_channel->update(); |
1347 | 1407 | |
1348 | | _SN76477_slf_cap_w(sn, data); |
| 1408 | _SN76477_slf_cap_w(data); |
1349 | 1409 | |
1350 | | log_slf_freq(sn); |
| 1410 | log_slf_freq(); |
1351 | 1411 | } |
1352 | 1412 | #endif |
1353 | 1413 | } |
r26337 | r26338 | |
1362 | 1422 | * |
1363 | 1423 | *****************************************************************************/ |
1364 | 1424 | |
1365 | | void sn76477_slf_cap_voltage_w(device_t *device, double data) |
| 1425 | void sn76477_device::slf_cap_voltage_w(double data) |
1366 | 1426 | { |
1367 | 1427 | #if TEST_MODE == 0 |
1368 | | sn76477_state *sn = get_safe_token(device); |
1369 | | |
1370 | 1428 | CHECK_CHIP_NUM_AND_CAP_VOLTAGE; |
1371 | 1429 | |
1372 | 1430 | if (data == SN76477_EXTERNAL_VOLTAGE_DISCONNECT) |
1373 | 1431 | { |
1374 | 1432 | /* switch to internal, if not already */ |
1375 | | if (sn->slf_cap_voltage_ext) |
| 1433 | if (m_slf_cap_voltage_ext) |
1376 | 1434 | { |
1377 | | sn->channel->update(); |
| 1435 | m_channel->update(); |
1378 | 1436 | |
1379 | | sn->slf_cap_voltage_ext = 0; |
| 1437 | m_slf_cap_voltage_ext = 0; |
1380 | 1438 | |
1381 | | log_slf_freq(sn); |
| 1439 | log_slf_freq(); |
1382 | 1440 | } |
1383 | 1441 | } |
1384 | 1442 | else |
1385 | 1443 | { |
1386 | 1444 | /* set the voltage on the cap */ |
1387 | | if (!sn->slf_cap_voltage_ext || (data != sn->slf_cap_voltage)) |
| 1445 | if (!m_slf_cap_voltage_ext || (data != m_slf_cap_voltage)) |
1388 | 1446 | { |
1389 | | sn->channel->update(); |
| 1447 | m_channel->update(); |
1390 | 1448 | |
1391 | | sn->slf_cap_voltage_ext = 1; |
1392 | | sn->slf_cap_voltage = data; |
| 1449 | m_slf_cap_voltage_ext = 1; |
| 1450 | m_slf_cap_voltage = data; |
1393 | 1451 | |
1394 | | log_slf_freq(sn); |
| 1452 | log_slf_freq(); |
1395 | 1453 | } |
1396 | 1454 | } |
1397 | 1455 | #endif |
r26337 | r26338 | |
1405 | 1463 | * |
1406 | 1464 | *****************************************************************************/ |
1407 | 1465 | |
1408 | | static void _SN76477_vco_res_w(sn76477_state *sn, double data) |
| 1466 | void sn76477_device::_SN76477_vco_res_w(double data) |
1409 | 1467 | { |
1410 | | sn->vco_res = data; |
| 1468 | m_vco_res = data; |
1411 | 1469 | } |
1412 | 1470 | |
1413 | 1471 | |
1414 | | void sn76477_vco_res_w(device_t *device, double data) |
| 1472 | void sn76477_device::vco_res_w(double data) |
1415 | 1473 | { |
1416 | 1474 | #if TEST_MODE == 0 |
1417 | | sn76477_state *sn = get_safe_token(device); |
1418 | | |
1419 | 1475 | CHECK_CHIP_NUM_AND_POSITIVE; |
1420 | 1476 | |
1421 | | if (data != sn->vco_res) |
| 1477 | if (data != m_vco_res) |
1422 | 1478 | { |
1423 | | sn->channel->update(); |
| 1479 | m_channel->update(); |
1424 | 1480 | |
1425 | | _SN76477_vco_res_w(sn, data); |
| 1481 | _SN76477_vco_res_w(data); |
1426 | 1482 | |
1427 | | log_vco_freq(sn); |
| 1483 | log_vco_freq(); |
1428 | 1484 | } |
1429 | 1485 | #endif |
1430 | 1486 | } |
r26337 | r26338 | |
1437 | 1493 | * |
1438 | 1494 | *****************************************************************************/ |
1439 | 1495 | |
1440 | | static void _SN76477_vco_cap_w(sn76477_state *sn, double data) |
| 1496 | void sn76477_device::_SN76477_vco_cap_w(double data) |
1441 | 1497 | { |
1442 | | sn->vco_cap = data; |
| 1498 | m_vco_cap = data; |
1443 | 1499 | } |
1444 | 1500 | |
1445 | 1501 | |
1446 | | void sn76477_vco_cap_w(device_t *device, double data) |
| 1502 | void sn76477_device::vco_cap_w(double data) |
1447 | 1503 | { |
1448 | 1504 | #if TEST_MODE == 0 |
1449 | | sn76477_state *sn = get_safe_token(device); |
1450 | | |
1451 | 1505 | CHECK_CHIP_NUM_AND_POSITIVE; |
1452 | 1506 | |
1453 | | if (data != sn->vco_cap) |
| 1507 | if (data != m_vco_cap) |
1454 | 1508 | { |
1455 | | sn->channel->update(); |
| 1509 | m_channel->update(); |
1456 | 1510 | |
1457 | | _SN76477_vco_cap_w(sn, data); |
| 1511 | _SN76477_vco_cap_w(data); |
1458 | 1512 | |
1459 | | log_vco_freq(sn); |
| 1513 | log_vco_freq(); |
1460 | 1514 | } |
1461 | 1515 | #endif |
1462 | 1516 | } |
r26337 | r26338 | |
1469 | 1523 | * |
1470 | 1524 | *****************************************************************************/ |
1471 | 1525 | |
1472 | | void sn76477_vco_cap_voltage_w(device_t *device, double data) |
| 1526 | void sn76477_device::vco_cap_voltage_w(double data) |
1473 | 1527 | { |
1474 | 1528 | #if TEST_MODE == 0 |
1475 | | sn76477_state *sn = get_safe_token(device); |
1476 | | |
1477 | 1529 | CHECK_CHIP_NUM_AND_CAP_VOLTAGE; |
1478 | 1530 | |
1479 | 1531 | if (data == SN76477_EXTERNAL_VOLTAGE_DISCONNECT) |
1480 | 1532 | { |
1481 | 1533 | /* switch to internal, if not already */ |
1482 | | if (sn->vco_cap_voltage_ext) |
| 1534 | if (m_vco_cap_voltage_ext) |
1483 | 1535 | { |
1484 | | sn->channel->update(); |
| 1536 | m_channel->update(); |
1485 | 1537 | |
1486 | | sn->vco_cap_voltage_ext = 0; |
| 1538 | m_vco_cap_voltage_ext = 0; |
1487 | 1539 | |
1488 | | log_vco_freq(sn); |
| 1540 | log_vco_freq(); |
1489 | 1541 | } |
1490 | 1542 | } |
1491 | 1543 | else |
1492 | 1544 | { |
1493 | 1545 | /* set the voltage on the cap */ |
1494 | | if (!sn->vco_cap_voltage_ext || (data != sn->vco_cap_voltage)) |
| 1546 | if (!m_vco_cap_voltage_ext || (data != m_vco_cap_voltage)) |
1495 | 1547 | { |
1496 | | sn->channel->update(); |
| 1548 | m_channel->update(); |
1497 | 1549 | |
1498 | | sn->vco_cap_voltage_ext = 1; |
1499 | | sn->vco_cap_voltage = data; |
| 1550 | m_vco_cap_voltage_ext = 1; |
| 1551 | m_vco_cap_voltage = data; |
1500 | 1552 | |
1501 | | log_vco_freq(sn); |
| 1553 | log_vco_freq(); |
1502 | 1554 | } |
1503 | 1555 | } |
1504 | 1556 | #endif |
r26337 | r26338 | |
1512 | 1564 | * |
1513 | 1565 | *****************************************************************************/ |
1514 | 1566 | |
1515 | | static void _SN76477_vco_voltage_w(sn76477_state *sn, double data) |
| 1567 | void sn76477_device::_SN76477_vco_voltage_w(double data) |
1516 | 1568 | { |
1517 | | sn->vco_voltage = data; |
| 1569 | m_vco_voltage = data; |
1518 | 1570 | } |
1519 | 1571 | |
1520 | 1572 | |
1521 | | void sn76477_vco_voltage_w(device_t *device, double data) |
| 1573 | void sn76477_device::vco_voltage_w(double data) |
1522 | 1574 | { |
1523 | 1575 | #if TEST_MODE == 0 |
1524 | | sn76477_state *sn = get_safe_token(device); |
1525 | | |
1526 | 1576 | CHECK_CHIP_NUM_AND_VOLTAGE; |
1527 | 1577 | |
1528 | | if (data != sn->vco_voltage) |
| 1578 | if (data != m_vco_voltage) |
1529 | 1579 | { |
1530 | | sn->channel->update(); |
| 1580 | m_channel->update(); |
1531 | 1581 | |
1532 | | _SN76477_vco_voltage_w(sn, data); |
| 1582 | _SN76477_vco_voltage_w(data); |
1533 | 1583 | |
1534 | | log_vco_ext_voltage(sn); |
1535 | | log_vco_duty_cycle(sn); |
| 1584 | log_vco_ext_voltage(); |
| 1585 | log_vco_duty_cycle(); |
1536 | 1586 | } |
1537 | 1587 | #endif |
1538 | 1588 | } |
r26337 | r26338 | |
1545 | 1595 | * |
1546 | 1596 | *****************************************************************************/ |
1547 | 1597 | |
1548 | | static void _SN76477_pitch_voltage_w(sn76477_state *sn, double data) |
| 1598 | void sn76477_device::_SN76477_pitch_voltage_w(double data) |
1549 | 1599 | { |
1550 | | sn->pitch_voltage = data; |
| 1600 | m_pitch_voltage = data; |
1551 | 1601 | } |
1552 | 1602 | |
1553 | 1603 | |
1554 | | void sn76477_pitch_voltage_w(device_t *device, double data) |
| 1604 | void sn76477_device::pitch_voltage_w(double data) |
1555 | 1605 | { |
1556 | 1606 | #if TEST_MODE == 0 |
1557 | | sn76477_state *sn = get_safe_token(device); |
1558 | | |
1559 | 1607 | CHECK_CHIP_NUM_AND_VOLTAGE; |
1560 | 1608 | |
1561 | | if (data != sn->pitch_voltage) |
| 1609 | if (data != m_pitch_voltage) |
1562 | 1610 | { |
1563 | | sn->channel->update(); |
| 1611 | m_channel->update(); |
1564 | 1612 | |
1565 | | _SN76477_pitch_voltage_w(sn, data); |
| 1613 | _SN76477_pitch_voltage_w(data); |
1566 | 1614 | |
1567 | | log_vco_pitch_voltage(sn); |
1568 | | log_vco_duty_cycle(sn); |
| 1615 | log_vco_pitch_voltage(); |
| 1616 | log_vco_duty_cycle(); |
1569 | 1617 | } |
1570 | 1618 | #endif |
1571 | 1619 | } |
r26337 | r26338 | |
1578 | 1626 | * |
1579 | 1627 | *****************************************************************************/ |
1580 | 1628 | |
1581 | | WRITE_LINE_DEVICE_HANDLER( sn76477_noise_clock_w ) |
| 1629 | WRITE_LINE_MEMBER( sn76477_device::noise_clock_w ) |
1582 | 1630 | { |
1583 | 1631 | #if TEST_MODE == 0 |
1584 | | sn76477_state *sn = get_safe_token(device); |
1585 | | |
1586 | 1632 | CHECK_CHIP_NUM_AND_BOOLEAN; |
1587 | 1633 | |
1588 | | if (state != sn->noise_clock) |
| 1634 | if (state != m_noise_clock) |
1589 | 1635 | { |
1590 | | sn->noise_clock = state; |
| 1636 | m_noise_clock = state; |
1591 | 1637 | |
1592 | 1638 | /* on the rising edge shift generate next value, |
1593 | 1639 | if external control is enabled */ |
1594 | | if (sn->noise_clock && sn->noise_clock_ext) |
| 1640 | if (m_noise_clock && m_noise_clock_ext) |
1595 | 1641 | { |
1596 | | sn->channel->update(); |
| 1642 | m_channel->update(); |
1597 | 1643 | |
1598 | | sn->real_noise_bit_ff = generate_next_real_noise_bit(sn); |
| 1644 | m_real_noise_bit_ff = generate_next_real_noise_bit(); |
1599 | 1645 | } |
1600 | 1646 | } |
1601 | 1647 | #endif |
r26337 | r26338 | |
1609 | 1655 | * |
1610 | 1656 | *****************************************************************************/ |
1611 | 1657 | |
1612 | | static void _SN76477_noise_clock_res_w(sn76477_state *sn, double data) |
| 1658 | void sn76477_device::_SN76477_noise_clock_res_w(double data) |
1613 | 1659 | { |
1614 | 1660 | if (data == 0) |
1615 | 1661 | { |
1616 | | sn->noise_clock_ext = 1; |
| 1662 | m_noise_clock_ext = 1; |
1617 | 1663 | } |
1618 | 1664 | else |
1619 | 1665 | { |
1620 | | sn->noise_clock_ext = 0; |
| 1666 | m_noise_clock_ext = 0; |
1621 | 1667 | |
1622 | | sn->noise_clock_res = data; |
| 1668 | m_noise_clock_res = data; |
1623 | 1669 | } |
1624 | 1670 | } |
1625 | 1671 | |
1626 | 1672 | |
1627 | | void sn76477_noise_clock_res_w(device_t *device, double data) |
| 1673 | void sn76477_device::noise_clock_res_w(double data) |
1628 | 1674 | { |
1629 | 1675 | #if TEST_MODE == 0 |
1630 | | sn76477_state *sn = get_safe_token(device); |
1631 | | |
1632 | 1676 | CHECK_CHIP_NUM_AND_POSITIVE; |
1633 | 1677 | |
1634 | | if (((data == 0) && !sn->noise_clock_ext) || |
1635 | | ((data != 0) && (data != sn->noise_clock_res))) |
| 1678 | if (((data == 0) && !m_noise_clock_ext) || |
| 1679 | ((data != 0) && (data != m_noise_clock_res))) |
1636 | 1680 | { |
1637 | | sn->channel->update(); |
| 1681 | m_channel->update(); |
1638 | 1682 | |
1639 | | _SN76477_noise_clock_res_w(sn, data); |
| 1683 | _SN76477_noise_clock_res_w(data); |
1640 | 1684 | |
1641 | | log_noise_gen_freq(sn); |
| 1685 | log_noise_gen_freq(); |
1642 | 1686 | } |
1643 | 1687 | #endif |
1644 | 1688 | } |
r26337 | r26338 | |
1651 | 1695 | * |
1652 | 1696 | *****************************************************************************/ |
1653 | 1697 | |
1654 | | static void _SN76477_noise_filter_res_w(sn76477_state *sn, double data) |
| 1698 | void sn76477_device::_SN76477_noise_filter_res_w(double data) |
1655 | 1699 | { |
1656 | | sn->noise_filter_res = data; |
| 1700 | m_noise_filter_res = data; |
1657 | 1701 | } |
1658 | 1702 | |
1659 | 1703 | |
1660 | | void sn76477_noise_filter_res_w(device_t *device, double data) |
| 1704 | void sn76477_device::noise_filter_res_w(double data) |
1661 | 1705 | { |
1662 | 1706 | #if TEST_MODE == 0 |
1663 | | sn76477_state *sn = get_safe_token(device); |
1664 | | |
1665 | 1707 | CHECK_CHIP_NUM_AND_POSITIVE; |
1666 | 1708 | |
1667 | | if (data != sn->noise_filter_res) |
| 1709 | if (data != m_noise_filter_res) |
1668 | 1710 | { |
1669 | | sn->channel->update(); |
| 1711 | m_channel->update(); |
1670 | 1712 | |
1671 | | _SN76477_noise_filter_res_w(sn, data); |
| 1713 | _SN76477_noise_filter_res_w(data); |
1672 | 1714 | |
1673 | | log_noise_filter_freq(sn); |
| 1715 | log_noise_filter_freq(); |
1674 | 1716 | } |
1675 | 1717 | #endif |
1676 | 1718 | } |
r26337 | r26338 | |
1683 | 1725 | * |
1684 | 1726 | *****************************************************************************/ |
1685 | 1727 | |
1686 | | static void _SN76477_noise_filter_cap_w(sn76477_state *sn, double data) |
| 1728 | void sn76477_device::_SN76477_noise_filter_cap_w(double data) |
1687 | 1729 | { |
1688 | | sn->noise_filter_cap = data; |
| 1730 | m_noise_filter_cap = data; |
1689 | 1731 | } |
1690 | 1732 | |
1691 | 1733 | |
1692 | | void sn76477_noise_filter_cap_w(device_t *device, double data) |
| 1734 | void sn76477_device::noise_filter_cap_w(double data) |
1693 | 1735 | { |
1694 | 1736 | #if TEST_MODE == 0 |
1695 | | sn76477_state *sn = get_safe_token(device); |
1696 | | |
1697 | 1737 | CHECK_CHIP_NUM_AND_POSITIVE; |
1698 | 1738 | |
1699 | | if (data != sn->noise_filter_cap) |
| 1739 | if (data != m_noise_filter_cap) |
1700 | 1740 | { |
1701 | | sn->channel->update(); |
| 1741 | m_channel->update(); |
1702 | 1742 | |
1703 | | _SN76477_noise_filter_cap_w(sn, data); |
| 1743 | _SN76477_noise_filter_cap_w(data); |
1704 | 1744 | |
1705 | | log_noise_filter_freq(sn); |
| 1745 | log_noise_filter_freq(); |
1706 | 1746 | } |
1707 | 1747 | #endif |
1708 | 1748 | } |
r26337 | r26338 | |
1715 | 1755 | * |
1716 | 1756 | *****************************************************************************/ |
1717 | 1757 | |
1718 | | void sn76477_noise_filter_cap_voltage_w(device_t *device, double data) |
| 1758 | void sn76477_device::noise_filter_cap_voltage_w(double data) |
1719 | 1759 | { |
1720 | 1760 | #if TEST_MODE == 0 |
1721 | | sn76477_state *sn = get_safe_token(device); |
1722 | | |
1723 | 1761 | CHECK_CHIP_NUM_AND_CAP_VOLTAGE; |
1724 | 1762 | |
1725 | 1763 | if (data == SN76477_EXTERNAL_VOLTAGE_DISCONNECT) |
1726 | 1764 | { |
1727 | 1765 | /* switch to internal, if not already */ |
1728 | | if (sn->noise_filter_cap_voltage_ext) |
| 1766 | if (m_noise_filter_cap_voltage_ext) |
1729 | 1767 | { |
1730 | | sn->channel->update(); |
| 1768 | m_channel->update(); |
1731 | 1769 | |
1732 | | sn->noise_filter_cap_voltage_ext = 0; |
| 1770 | m_noise_filter_cap_voltage_ext = 0; |
1733 | 1771 | |
1734 | | log_noise_filter_freq(sn); |
| 1772 | log_noise_filter_freq(); |
1735 | 1773 | } |
1736 | 1774 | } |
1737 | 1775 | else |
1738 | 1776 | { |
1739 | 1777 | /* set the voltage on the cap */ |
1740 | | if (!sn->noise_filter_cap_voltage_ext || (data != sn->noise_filter_cap_voltage)) |
| 1778 | if (!m_noise_filter_cap_voltage_ext || (data != m_noise_filter_cap_voltage)) |
1741 | 1779 | { |
1742 | | sn->channel->update(); |
| 1780 | m_channel->update(); |
1743 | 1781 | |
1744 | | sn->noise_filter_cap_voltage_ext = 1; |
1745 | | sn->noise_filter_cap_voltage = data; |
| 1782 | m_noise_filter_cap_voltage_ext = 1; |
| 1783 | m_noise_filter_cap_voltage = data; |
1746 | 1784 | |
1747 | | log_noise_filter_freq(sn); |
| 1785 | log_noise_filter_freq(); |
1748 | 1786 | } |
1749 | 1787 | } |
1750 | 1788 | #endif |
r26337 | r26338 | |
1758 | 1796 | * |
1759 | 1797 | *****************************************************************************/ |
1760 | 1798 | |
1761 | | static void _SN76477_attack_res_w(sn76477_state *sn, double data) |
| 1799 | void sn76477_device::_SN76477_attack_res_w(double data) |
1762 | 1800 | { |
1763 | | sn->attack_res = data; |
| 1801 | m_attack_res = data; |
1764 | 1802 | } |
1765 | 1803 | |
1766 | 1804 | |
1767 | | void sn76477_attack_res_w(device_t *device, double data) |
| 1805 | void sn76477_device::attack_res_w(double data) |
1768 | 1806 | { |
1769 | 1807 | #if TEST_MODE == 0 |
1770 | | sn76477_state *sn = get_safe_token(device); |
1771 | | |
1772 | 1808 | CHECK_CHIP_NUM_AND_POSITIVE; |
1773 | 1809 | |
1774 | | if (data != sn->attack_res) |
| 1810 | if (data != m_attack_res) |
1775 | 1811 | { |
1776 | | sn->channel->update(); |
| 1812 | m_channel->update(); |
1777 | 1813 | |
1778 | | _SN76477_attack_res_w(sn, data); |
| 1814 | _SN76477_attack_res_w(data); |
1779 | 1815 | |
1780 | | log_attack_time(sn); |
| 1816 | log_attack_time(); |
1781 | 1817 | } |
1782 | 1818 | #endif |
1783 | 1819 | } |
r26337 | r26338 | |
1790 | 1826 | * |
1791 | 1827 | *****************************************************************************/ |
1792 | 1828 | |
1793 | | static void _SN76477_decay_res_w(sn76477_state *sn, double data) |
| 1829 | void sn76477_device::_SN76477_decay_res_w(double data) |
1794 | 1830 | { |
1795 | | sn->decay_res = data; |
| 1831 | m_decay_res = data; |
1796 | 1832 | } |
1797 | 1833 | |
1798 | 1834 | |
1799 | | void sn76477_decay_res_w(device_t *device, double data) |
| 1835 | void sn76477_device::decay_res_w(double data) |
1800 | 1836 | { |
1801 | 1837 | #if TEST_MODE == 0 |
1802 | | sn76477_state *sn = get_safe_token(device); |
1803 | | |
1804 | 1838 | CHECK_CHIP_NUM_AND_POSITIVE; |
1805 | 1839 | |
1806 | | if (data != sn->decay_res) |
| 1840 | if (data != m_decay_res) |
1807 | 1841 | { |
1808 | | sn->channel->update(); |
| 1842 | m_channel->update(); |
1809 | 1843 | |
1810 | | _SN76477_decay_res_w(sn, data); |
| 1844 | _SN76477_decay_res_w(data); |
1811 | 1845 | |
1812 | | log_decay_time(sn); |
| 1846 | log_decay_time(); |
1813 | 1847 | } |
1814 | 1848 | #endif |
1815 | 1849 | } |
r26337 | r26338 | |
1822 | 1856 | * |
1823 | 1857 | *****************************************************************************/ |
1824 | 1858 | |
1825 | | static void _SN76477_attack_decay_cap_w(sn76477_state *sn, double data) |
| 1859 | void sn76477_device::_SN76477_attack_decay_cap_w(double data) |
1826 | 1860 | { |
1827 | | sn->attack_decay_cap = data; |
| 1861 | m_attack_decay_cap = data; |
1828 | 1862 | } |
1829 | 1863 | |
1830 | 1864 | |
1831 | | void sn76477_attack_decay_cap_w(device_t *device, double data) |
| 1865 | void sn76477_device::attack_decay_cap_w(double data) |
1832 | 1866 | { |
1833 | 1867 | #if TEST_MODE == 0 |
1834 | | sn76477_state *sn = get_safe_token(device); |
1835 | | |
1836 | 1868 | CHECK_CHIP_NUM_AND_POSITIVE; |
1837 | 1869 | |
1838 | | if (data != sn->attack_decay_cap) |
| 1870 | if (data != m_attack_decay_cap) |
1839 | 1871 | { |
1840 | | sn->channel->update(); |
| 1872 | m_channel->update(); |
1841 | 1873 | |
1842 | | _SN76477_attack_decay_cap_w(sn, data); |
| 1874 | _SN76477_attack_decay_cap_w(data); |
1843 | 1875 | |
1844 | | log_attack_time(sn); |
1845 | | log_decay_time(sn); |
| 1876 | log_attack_time(); |
| 1877 | log_decay_time(); |
1846 | 1878 | } |
1847 | 1879 | #endif |
1848 | 1880 | } |
r26337 | r26338 | |
1855 | 1887 | * |
1856 | 1888 | *****************************************************************************/ |
1857 | 1889 | |
1858 | | void sn76477_attack_decay_cap_voltage_w(device_t *device, double data) |
| 1890 | void sn76477_device::attack_decay_cap_voltage_w(double data) |
1859 | 1891 | { |
1860 | 1892 | #if TEST_MODE == 0 |
1861 | | sn76477_state *sn = get_safe_token(device); |
1862 | | |
1863 | 1893 | CHECK_CHIP_NUM_AND_CAP_VOLTAGE; |
1864 | 1894 | |
1865 | 1895 | if (data == SN76477_EXTERNAL_VOLTAGE_DISCONNECT) |
1866 | 1896 | { |
1867 | 1897 | /* switch to internal, if not already */ |
1868 | | if (sn->attack_decay_cap_voltage_ext) |
| 1898 | if (m_attack_decay_cap_voltage_ext) |
1869 | 1899 | { |
1870 | | sn->channel->update(); |
| 1900 | m_channel->update(); |
1871 | 1901 | |
1872 | | sn->attack_decay_cap_voltage_ext = 0; |
| 1902 | m_attack_decay_cap_voltage_ext = 0; |
1873 | 1903 | |
1874 | | log_attack_time(sn); |
1875 | | log_decay_time(sn); |
| 1904 | log_attack_time(); |
| 1905 | log_decay_time(); |
1876 | 1906 | } |
1877 | 1907 | } |
1878 | 1908 | else |
1879 | 1909 | { |
1880 | 1910 | /* set the voltage on the cap */ |
1881 | | if (!sn->attack_decay_cap_voltage_ext || (data != sn->attack_decay_cap_voltage)) |
| 1911 | if (!m_attack_decay_cap_voltage_ext || (data != m_attack_decay_cap_voltage)) |
1882 | 1912 | { |
1883 | | sn->channel->update(); |
| 1913 | m_channel->update(); |
1884 | 1914 | |
1885 | | sn->attack_decay_cap_voltage_ext = 1; |
1886 | | sn->attack_decay_cap_voltage = data; |
| 1915 | m_attack_decay_cap_voltage_ext = 1; |
| 1916 | m_attack_decay_cap_voltage = data; |
1887 | 1917 | |
1888 | | log_attack_time(sn); |
1889 | | log_decay_time(sn); |
| 1918 | log_attack_time(); |
| 1919 | log_decay_time(); |
1890 | 1920 | } |
1891 | 1921 | } |
1892 | 1922 | #endif |
r26337 | r26338 | |
1900 | 1930 | * |
1901 | 1931 | *****************************************************************************/ |
1902 | 1932 | |
1903 | | static void _SN76477_amplitude_res_w(sn76477_state *sn, double data) |
| 1933 | void sn76477_device::_SN76477_amplitude_res_w(double data) |
1904 | 1934 | { |
1905 | | sn->amplitude_res = data; |
| 1935 | m_amplitude_res = data; |
1906 | 1936 | } |
1907 | 1937 | |
1908 | 1938 | |
1909 | | void sn76477_amplitude_res_w(device_t *device, double data) |
| 1939 | void sn76477_device::amplitude_res_w(double data) |
1910 | 1940 | { |
1911 | 1941 | #if TEST_MODE == 0 |
1912 | | sn76477_state *sn = get_safe_token(device); |
1913 | | |
1914 | 1942 | CHECK_CHIP_NUM_AND_POSITIVE; |
1915 | 1943 | |
1916 | | if (data != sn->amplitude_res) |
| 1944 | if (data != m_amplitude_res) |
1917 | 1945 | { |
1918 | | sn->channel->update(); |
| 1946 | m_channel->update(); |
1919 | 1947 | |
1920 | | _SN76477_amplitude_res_w(sn, data); |
| 1948 | _SN76477_amplitude_res_w(data); |
1921 | 1949 | |
1922 | | log_voltage_out(sn); |
| 1950 | log_voltage_out(); |
1923 | 1951 | } |
1924 | 1952 | #endif |
1925 | 1953 | } |
r26337 | r26338 | |
1932 | 1960 | * |
1933 | 1961 | *****************************************************************************/ |
1934 | 1962 | |
1935 | | static void _SN76477_feedback_res_w(sn76477_state *sn, double data) |
| 1963 | void sn76477_device::_SN76477_feedback_res_w(double data) |
1936 | 1964 | { |
1937 | | sn->feedback_res = data; |
| 1965 | m_feedback_res = data; |
1938 | 1966 | } |
1939 | 1967 | |
1940 | 1968 | |
1941 | | void sn76477_feedback_res_w(device_t *device, double data) |
| 1969 | void sn76477_device::feedback_res_w(double data) |
1942 | 1970 | { |
1943 | 1971 | #if TEST_MODE == 0 |
1944 | | sn76477_state *sn = get_safe_token(device); |
1945 | | |
1946 | 1972 | CHECK_CHIP_NUM_AND_POSITIVE; |
1947 | 1973 | |
1948 | | if (data != sn->feedback_res) |
| 1974 | if (data != m_feedback_res) |
1949 | 1975 | { |
1950 | | sn->channel->update(); |
| 1976 | m_channel->update(); |
1951 | 1977 | |
1952 | | _SN76477_feedback_res_w(sn, data); |
| 1978 | _SN76477_feedback_res_w(data); |
1953 | 1979 | |
1954 | | log_voltage_out(sn); |
| 1980 | log_voltage_out(); |
1955 | 1981 | } |
1956 | 1982 | #endif |
1957 | 1983 | } |
1958 | 1984 | |
1959 | 1985 | |
1960 | | |
1961 | 1986 | /***************************************************************************** |
1962 | 1987 | * |
1963 | | * Sample generation |
| 1988 | * State saving |
1964 | 1989 | * |
1965 | 1990 | *****************************************************************************/ |
1966 | 1991 | |
1967 | | static STREAM_UPDATE( SN76477_update ) |
| 1992 | void sn76477_device::state_save_register() |
1968 | 1993 | { |
| 1994 | save_item(NAME(m_enable)); |
| 1995 | save_item(NAME(m_envelope_mode)); |
| 1996 | save_item(NAME(m_vco_mode)); |
| 1997 | save_item(NAME(m_mixer_mode)); |
| 1998 | |
| 1999 | save_item(NAME(m_one_shot_res)); |
| 2000 | save_item(NAME(m_one_shot_cap)); |
| 2001 | save_item(NAME(m_one_shot_cap_voltage_ext)); |
| 2002 | |
| 2003 | save_item(NAME(m_slf_res)); |
| 2004 | save_item(NAME(m_slf_cap)); |
| 2005 | save_item(NAME(m_slf_cap_voltage_ext)); |
| 2006 | |
| 2007 | save_item(NAME(m_vco_voltage)); |
| 2008 | save_item(NAME(m_vco_res)); |
| 2009 | save_item(NAME(m_vco_cap)); |
| 2010 | save_item(NAME(m_vco_cap_voltage_ext)); |
| 2011 | |
| 2012 | save_item(NAME(m_noise_clock_res)); |
| 2013 | save_item(NAME(m_noise_clock_ext)); |
| 2014 | save_item(NAME(m_noise_clock)); |
| 2015 | save_item(NAME(m_noise_filter_res)); |
| 2016 | save_item(NAME(m_noise_filter_cap)); |
| 2017 | save_item(NAME(m_noise_filter_cap_voltage_ext)); |
| 2018 | |
| 2019 | save_item(NAME(m_attack_res)); |
| 2020 | save_item(NAME(m_decay_res)); |
| 2021 | save_item(NAME(m_attack_decay_cap)); |
| 2022 | save_item(NAME(m_attack_decay_cap_voltage_ext)); |
| 2023 | |
| 2024 | save_item(NAME(m_amplitude_res)); |
| 2025 | save_item(NAME(m_feedback_res)); |
| 2026 | save_item(NAME(m_pitch_voltage)); |
| 2027 | |
| 2028 | save_item(NAME(m_one_shot_cap_voltage)); |
| 2029 | save_item(NAME(m_one_shot_running_ff)); |
| 2030 | |
| 2031 | save_item(NAME(m_slf_cap_voltage)); |
| 2032 | save_item(NAME(m_slf_out_ff)); |
| 2033 | |
| 2034 | save_item(NAME(m_vco_cap_voltage)); |
| 2035 | save_item(NAME(m_vco_out_ff)); |
| 2036 | save_item(NAME(m_vco_alt_pos_edge_ff)); |
| 2037 | |
| 2038 | save_item(NAME(m_noise_filter_cap_voltage)); |
| 2039 | save_item(NAME(m_real_noise_bit_ff)); |
| 2040 | save_item(NAME(m_filtered_noise_bit_ff)); |
| 2041 | save_item(NAME(m_noise_gen_count)); |
| 2042 | |
| 2043 | save_item(NAME(m_attack_decay_cap_voltage)); |
| 2044 | |
| 2045 | save_item(NAME(m_rng)); |
| 2046 | } |
| 2047 | |
| 2048 | //------------------------------------------------- |
| 2049 | // sound_stream_update - handle a stream update |
| 2050 | //------------------------------------------------- |
| 2051 | |
| 2052 | void sn76477_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) |
| 2053 | { |
1969 | 2054 | double one_shot_cap_charging_step; |
1970 | 2055 | double one_shot_cap_discharging_step; |
1971 | 2056 | double slf_cap_charging_step; |
r26337 | r26338 | |
1983 | 2068 | double voltage_out; |
1984 | 2069 | double center_to_peak_voltage_out; |
1985 | 2070 | |
1986 | | sn76477_state *sn = (sn76477_state *)param; |
1987 | 2071 | stream_sample_t *buffer = outputs[0]; |
1988 | 2072 | |
1989 | 2073 | |
1990 | 2074 | #if TEST_MODE |
1991 | | static int recursing = 0; /* we need to prevent recursion since enable_w calls device->machine().input().code_pressed_once(KEYCODE_SPACE->update */ |
| 2075 | static int recursing = 0; /* we need to prevent recursion since enable_w calls machine().input().code_pressed_once(KEYCODE_SPACE->update */ |
1992 | 2076 | |
1993 | 2077 | if () && !recursing) |
1994 | 2078 | { |
1995 | 2079 | recursing = 1; |
1996 | 2080 | |
1997 | | device->machine().sound().system_enable(); |
1998 | | SN76477_test_enable_w(sn, !sn->enable); |
| 2081 | machine().sound().system_enable(); |
| 2082 | SN76477_test_enable_w(!m_enable); |
1999 | 2083 | } |
2000 | 2084 | |
2001 | 2085 | recursing = 0; |
2002 | 2086 | #endif |
2003 | 2087 | |
2004 | 2088 | /* compute charging values, doing it here ensures that we always use the latest values */ |
2005 | | one_shot_cap_charging_step = compute_one_shot_cap_charging_rate(sn) / sn->sample_rate; |
2006 | | one_shot_cap_discharging_step = compute_one_shot_cap_discharging_rate(sn) / sn->sample_rate; |
| 2089 | one_shot_cap_charging_step = compute_one_shot_cap_charging_rate() / m_our_sample_rate; |
| 2090 | one_shot_cap_discharging_step = compute_one_shot_cap_discharging_rate() / m_our_sample_rate; |
2007 | 2091 | |
2008 | | slf_cap_charging_step = compute_slf_cap_charging_rate(sn) / sn->sample_rate; |
2009 | | slf_cap_discharging_step = compute_slf_cap_discharging_rate(sn) / sn->sample_rate; |
| 2092 | slf_cap_charging_step = compute_slf_cap_charging_rate() / m_our_sample_rate; |
| 2093 | slf_cap_discharging_step = compute_slf_cap_discharging_rate() / m_our_sample_rate; |
2010 | 2094 | |
2011 | | vco_duty_cycle_multiplier = (1 - compute_vco_duty_cycle(sn)) * 2; |
2012 | | vco_cap_charging_step = compute_vco_cap_charging_discharging_rate(sn) / vco_duty_cycle_multiplier / sn->sample_rate; |
2013 | | vco_cap_discharging_step = compute_vco_cap_charging_discharging_rate(sn) * vco_duty_cycle_multiplier / sn->sample_rate; |
| 2095 | vco_duty_cycle_multiplier = (1 - compute_vco_duty_cycle()) * 2; |
| 2096 | vco_cap_charging_step = compute_vco_cap_charging_discharging_rate() / vco_duty_cycle_multiplier / m_our_sample_rate; |
| 2097 | vco_cap_discharging_step = compute_vco_cap_charging_discharging_rate() * vco_duty_cycle_multiplier / m_our_sample_rate; |
2014 | 2098 | |
2015 | | noise_filter_cap_charging_step = compute_noise_filter_cap_charging_rate(sn) / sn->sample_rate; |
2016 | | noise_filter_cap_discharging_step = compute_noise_filter_cap_discharging_rate(sn) / sn->sample_rate; |
2017 | | noise_gen_freq = compute_noise_gen_freq(sn); |
| 2099 | noise_filter_cap_charging_step = compute_noise_filter_cap_charging_rate() / m_our_sample_rate; |
| 2100 | noise_filter_cap_discharging_step = compute_noise_filter_cap_discharging_rate() / m_our_sample_rate; |
| 2101 | noise_gen_freq = compute_noise_gen_freq(); |
2018 | 2102 | |
2019 | | attack_decay_cap_charging_step = compute_attack_decay_cap_charging_rate(sn) / sn->sample_rate; |
2020 | | attack_decay_cap_discharging_step = compute_attack_decay_cap_discharging_rate(sn) / sn->sample_rate; |
| 2103 | attack_decay_cap_charging_step = compute_attack_decay_cap_charging_rate() / m_our_sample_rate; |
| 2104 | attack_decay_cap_discharging_step = compute_attack_decay_cap_discharging_rate() / m_our_sample_rate; |
2021 | 2105 | |
2022 | | center_to_peak_voltage_out = compute_center_to_peak_voltage_out(sn); |
| 2106 | center_to_peak_voltage_out = compute_center_to_peak_voltage_out(); |
2023 | 2107 | |
2024 | 2108 | |
2025 | 2109 | /* process 'samples' number of samples */ |
2026 | 2110 | while (samples--) |
2027 | 2111 | { |
2028 | 2112 | /* update the one-shot cap voltage */ |
2029 | | if (!sn->one_shot_cap_voltage_ext) |
| 2113 | if (!m_one_shot_cap_voltage_ext) |
2030 | 2114 | { |
2031 | | if (sn->one_shot_running_ff) |
| 2115 | if (m_one_shot_running_ff) |
2032 | 2116 | { |
2033 | 2117 | /* charging */ |
2034 | | sn->one_shot_cap_voltage = min(sn->one_shot_cap_voltage + one_shot_cap_charging_step, ONE_SHOT_CAP_VOLTAGE_MAX); |
| 2118 | m_one_shot_cap_voltage = min(m_one_shot_cap_voltage + one_shot_cap_charging_step, ONE_SHOT_CAP_VOLTAGE_MAX); |
2035 | 2119 | } |
2036 | 2120 | else |
2037 | 2121 | { |
2038 | 2122 | /* discharging */ |
2039 | | sn->one_shot_cap_voltage = max(sn->one_shot_cap_voltage - one_shot_cap_discharging_step, ONE_SHOT_CAP_VOLTAGE_MIN); |
| 2123 | m_one_shot_cap_voltage = max(m_one_shot_cap_voltage - one_shot_cap_discharging_step, ONE_SHOT_CAP_VOLTAGE_MIN); |
2040 | 2124 | } |
2041 | 2125 | } |
2042 | 2126 | |
2043 | | if (sn->one_shot_cap_voltage >= ONE_SHOT_CAP_VOLTAGE_MAX) |
| 2127 | if (m_one_shot_cap_voltage >= ONE_SHOT_CAP_VOLTAGE_MAX) |
2044 | 2128 | { |
2045 | | sn->one_shot_running_ff = 0; |
| 2129 | m_one_shot_running_ff = 0; |
2046 | 2130 | } |
2047 | 2131 | |
2048 | 2132 | |
2049 | 2133 | /* update the SLF (super low frequency oscillator) */ |
2050 | | if (!sn->slf_cap_voltage_ext) |
| 2134 | if (!m_slf_cap_voltage_ext) |
2051 | 2135 | { |
2052 | 2136 | /* internal */ |
2053 | | if (!sn->slf_out_ff) |
| 2137 | if (!m_slf_out_ff) |
2054 | 2138 | { |
2055 | 2139 | /* charging */ |
2056 | | sn->slf_cap_voltage = min(sn->slf_cap_voltage + slf_cap_charging_step, SLF_CAP_VOLTAGE_MAX); |
| 2140 | m_slf_cap_voltage = min(m_slf_cap_voltage + slf_cap_charging_step, SLF_CAP_VOLTAGE_MAX); |
2057 | 2141 | } |
2058 | 2142 | else |
2059 | 2143 | { |
2060 | 2144 | /* discharging */ |
2061 | | sn->slf_cap_voltage = max(sn->slf_cap_voltage - slf_cap_discharging_step, SLF_CAP_VOLTAGE_MIN); |
| 2145 | m_slf_cap_voltage = max(m_slf_cap_voltage - slf_cap_discharging_step, SLF_CAP_VOLTAGE_MIN); |
2062 | 2146 | } |
2063 | 2147 | } |
2064 | 2148 | |
2065 | | if (sn->slf_cap_voltage >= SLF_CAP_VOLTAGE_MAX) |
| 2149 | if (m_slf_cap_voltage >= SLF_CAP_VOLTAGE_MAX) |
2066 | 2150 | { |
2067 | | sn->slf_out_ff = 1; |
| 2151 | m_slf_out_ff = 1; |
2068 | 2152 | } |
2069 | | else if (sn->slf_cap_voltage <= SLF_CAP_VOLTAGE_MIN) |
| 2153 | else if (m_slf_cap_voltage <= SLF_CAP_VOLTAGE_MIN) |
2070 | 2154 | { |
2071 | | sn->slf_out_ff = 0; |
| 2155 | m_slf_out_ff = 0; |
2072 | 2156 | } |
2073 | 2157 | |
2074 | 2158 | |
2075 | 2159 | /* update the VCO (voltage controlled oscillator) */ |
2076 | | if (sn->vco_mode) |
| 2160 | if (m_vco_mode) |
2077 | 2161 | { |
2078 | 2162 | /* VCO is controlled by SLF */ |
2079 | | vco_cap_voltage_max = sn->slf_cap_voltage + VCO_TO_SLF_VOLTAGE_DIFF; |
| 2163 | vco_cap_voltage_max = m_slf_cap_voltage + VCO_TO_SLF_VOLTAGE_DIFF; |
2080 | 2164 | } |
2081 | 2165 | else |
2082 | 2166 | { |
2083 | 2167 | /* VCO is controlled by external voltage */ |
2084 | | vco_cap_voltage_max = sn->vco_voltage + VCO_TO_SLF_VOLTAGE_DIFF; |
| 2168 | vco_cap_voltage_max = m_vco_voltage + VCO_TO_SLF_VOLTAGE_DIFF; |
2085 | 2169 | } |
2086 | 2170 | |
2087 | | if (!sn->vco_cap_voltage_ext) |
| 2171 | if (!m_vco_cap_voltage_ext) |
2088 | 2172 | { |
2089 | | if (!sn->vco_out_ff) |
| 2173 | if (!m_vco_out_ff) |
2090 | 2174 | { |
2091 | 2175 | /* charging */ |
2092 | | sn->vco_cap_voltage = min(sn->vco_cap_voltage + vco_cap_charging_step, vco_cap_voltage_max); |
| 2176 | m_vco_cap_voltage = min(m_vco_cap_voltage + vco_cap_charging_step, vco_cap_voltage_max); |
2093 | 2177 | } |
2094 | 2178 | else |
2095 | 2179 | { |
2096 | 2180 | /* discharging */ |
2097 | | sn->vco_cap_voltage = max(sn->vco_cap_voltage - vco_cap_discharging_step, VCO_CAP_VOLTAGE_MIN); |
| 2181 | m_vco_cap_voltage = max(m_vco_cap_voltage - vco_cap_discharging_step, VCO_CAP_VOLTAGE_MIN); |
2098 | 2182 | } |
2099 | 2183 | } |
2100 | 2184 | |
2101 | | if (sn->vco_cap_voltage >= vco_cap_voltage_max) |
| 2185 | if (m_vco_cap_voltage >= vco_cap_voltage_max) |
2102 | 2186 | { |
2103 | | if (!sn->vco_out_ff) |
| 2187 | if (!m_vco_out_ff) |
2104 | 2188 | { |
2105 | 2189 | /* positive edge */ |
2106 | | sn->vco_alt_pos_edge_ff = !sn->vco_alt_pos_edge_ff; |
| 2190 | m_vco_alt_pos_edge_ff = !m_vco_alt_pos_edge_ff; |
2107 | 2191 | } |
2108 | 2192 | |
2109 | | sn->vco_out_ff = 1; |
| 2193 | m_vco_out_ff = 1; |
2110 | 2194 | } |
2111 | | else if (sn->vco_cap_voltage <= VCO_CAP_VOLTAGE_MIN) |
| 2195 | else if (m_vco_cap_voltage <= VCO_CAP_VOLTAGE_MIN) |
2112 | 2196 | { |
2113 | | sn->vco_out_ff = 0; |
| 2197 | m_vco_out_ff = 0; |
2114 | 2198 | } |
2115 | 2199 | |
2116 | 2200 | |
2117 | 2201 | /* update the noise generator */ |
2118 | | while (!sn->noise_clock_ext && (sn->noise_gen_count <= noise_gen_freq)) |
| 2202 | while (!m_noise_clock_ext && (m_noise_gen_count <= noise_gen_freq)) |
2119 | 2203 | { |
2120 | | sn->noise_gen_count = sn->noise_gen_count + sn->sample_rate; |
| 2204 | m_noise_gen_count = m_noise_gen_count + m_our_sample_rate; |
2121 | 2205 | |
2122 | | sn->real_noise_bit_ff = generate_next_real_noise_bit(sn); |
| 2206 | m_real_noise_bit_ff = generate_next_real_noise_bit(); |
2123 | 2207 | } |
2124 | 2208 | |
2125 | | sn->noise_gen_count = sn->noise_gen_count - noise_gen_freq; |
| 2209 | m_noise_gen_count = m_noise_gen_count - noise_gen_freq; |
2126 | 2210 | |
2127 | 2211 | |
2128 | 2212 | /* update the noise filter */ |
2129 | | if (!sn->noise_filter_cap_voltage_ext) |
| 2213 | if (!m_noise_filter_cap_voltage_ext) |
2130 | 2214 | { |
2131 | 2215 | /* internal */ |
2132 | | if (sn->real_noise_bit_ff) |
| 2216 | if (m_real_noise_bit_ff) |
2133 | 2217 | { |
2134 | 2218 | /* charging */ |
2135 | | sn->noise_filter_cap_voltage = min(sn->noise_filter_cap_voltage + noise_filter_cap_charging_step, NOISE_CAP_VOLTAGE_MAX); |
| 2219 | m_noise_filter_cap_voltage = min(m_noise_filter_cap_voltage + noise_filter_cap_charging_step, NOISE_CAP_VOLTAGE_MAX); |
2136 | 2220 | } |
2137 | 2221 | else |
2138 | 2222 | { |
2139 | 2223 | /* discharging */ |
2140 | | sn->noise_filter_cap_voltage = max(sn->noise_filter_cap_voltage - noise_filter_cap_discharging_step, NOISE_CAP_VOLTAGE_MIN); |
| 2224 | m_noise_filter_cap_voltage = max(m_noise_filter_cap_voltage - noise_filter_cap_discharging_step, NOISE_CAP_VOLTAGE_MIN); |
2141 | 2225 | } |
2142 | 2226 | } |
2143 | 2227 | |
2144 | 2228 | /* check the thresholds */ |
2145 | | if (sn->noise_filter_cap_voltage >= NOISE_CAP_HIGH_THRESHOLD) |
| 2229 | if (m_noise_filter_cap_voltage >= NOISE_CAP_HIGH_THRESHOLD) |
2146 | 2230 | { |
2147 | | sn->filtered_noise_bit_ff = 0; |
| 2231 | m_filtered_noise_bit_ff = 0; |
2148 | 2232 | } |
2149 | | else if (sn->noise_filter_cap_voltage <= NOISE_CAP_LOW_THRESHOLD) |
| 2233 | else if (m_noise_filter_cap_voltage <= NOISE_CAP_LOW_THRESHOLD) |
2150 | 2234 | { |
2151 | | sn->filtered_noise_bit_ff = 1; |
| 2235 | m_filtered_noise_bit_ff = 1; |
2152 | 2236 | } |
2153 | 2237 | |
2154 | 2238 | |
2155 | 2239 | /* based on the envelope mode figure out the attack/decay phase we are in */ |
2156 | | switch (sn->envelope_mode) |
| 2240 | switch (m_envelope_mode) |
2157 | 2241 | { |
2158 | 2242 | case 0: /* VCO */ |
2159 | | attack_decay_cap_charging = sn->vco_out_ff; |
| 2243 | attack_decay_cap_charging = m_vco_out_ff; |
2160 | 2244 | break; |
2161 | 2245 | |
2162 | 2246 | case 1: /* one-shot */ |
2163 | | attack_decay_cap_charging = sn->one_shot_running_ff; |
| 2247 | attack_decay_cap_charging = m_one_shot_running_ff; |
2164 | 2248 | break; |
2165 | 2249 | |
2166 | 2250 | case 2: |
r26337 | r26338 | |
2169 | 2253 | break; |
2170 | 2254 | |
2171 | 2255 | case 3: /* VCO with alternating polarity */ |
2172 | | attack_decay_cap_charging = sn->vco_out_ff && sn->vco_alt_pos_edge_ff; |
| 2256 | attack_decay_cap_charging = m_vco_out_ff && m_vco_alt_pos_edge_ff; |
2173 | 2257 | break; |
2174 | 2258 | } |
2175 | 2259 | |
2176 | 2260 | |
2177 | 2261 | /* update a/d cap voltage */ |
2178 | | if (!sn->attack_decay_cap_voltage_ext) |
| 2262 | if (!m_attack_decay_cap_voltage_ext) |
2179 | 2263 | { |
2180 | 2264 | if (attack_decay_cap_charging) |
2181 | 2265 | { |
2182 | 2266 | if (attack_decay_cap_charging_step > 0) |
2183 | 2267 | { |
2184 | | sn->attack_decay_cap_voltage = min(sn->attack_decay_cap_voltage + attack_decay_cap_charging_step, AD_CAP_VOLTAGE_MAX); |
| 2268 | m_attack_decay_cap_voltage = min(m_attack_decay_cap_voltage + attack_decay_cap_charging_step, AD_CAP_VOLTAGE_MAX); |
2185 | 2269 | } |
2186 | 2270 | else |
2187 | 2271 | { |
2188 | 2272 | /* no attack, voltage to max instantly */ |
2189 | | sn->attack_decay_cap_voltage = AD_CAP_VOLTAGE_MAX; |
| 2273 | m_attack_decay_cap_voltage = AD_CAP_VOLTAGE_MAX; |
2190 | 2274 | } |
2191 | 2275 | } |
2192 | 2276 | else |
r26337 | r26338 | |
2194 | 2278 | /* discharging */ |
2195 | 2279 | if (attack_decay_cap_discharging_step > 0) |
2196 | 2280 | { |
2197 | | sn->attack_decay_cap_voltage = max(sn->attack_decay_cap_voltage - attack_decay_cap_discharging_step, AD_CAP_VOLTAGE_MIN); |
| 2281 | m_attack_decay_cap_voltage = max(m_attack_decay_cap_voltage - attack_decay_cap_discharging_step, AD_CAP_VOLTAGE_MIN); |
2198 | 2282 | } |
2199 | 2283 | else |
2200 | 2284 | { |
2201 | 2285 | /* no decay, voltage to min instantly */ |
2202 | | sn->attack_decay_cap_voltage = AD_CAP_VOLTAGE_MIN; |
| 2286 | m_attack_decay_cap_voltage = AD_CAP_VOLTAGE_MIN; |
2203 | 2287 | } |
2204 | 2288 | } |
2205 | 2289 | } |
2206 | 2290 | |
2207 | 2291 | |
2208 | 2292 | /* mix the output, if enabled, or not saturated by the VCO */ |
2209 | | if (!sn->enable && (sn->vco_cap_voltage <= VCO_CAP_VOLTAGE_MAX)) |
| 2293 | if (!m_enable && (m_vco_cap_voltage <= VCO_CAP_VOLTAGE_MAX)) |
2210 | 2294 | { |
2211 | 2295 | UINT32 out; |
2212 | 2296 | |
2213 | 2297 | /* enabled */ |
2214 | | switch (sn->mixer_mode) |
| 2298 | switch (m_mixer_mode) |
2215 | 2299 | { |
2216 | 2300 | case 0: /* VCO */ |
2217 | | out = sn->vco_out_ff; |
| 2301 | out = m_vco_out_ff; |
2218 | 2302 | break; |
2219 | 2303 | |
2220 | 2304 | case 1: /* SLF */ |
2221 | | out = sn->slf_out_ff; |
| 2305 | out = m_slf_out_ff; |
2222 | 2306 | break; |
2223 | 2307 | |
2224 | 2308 | case 2: /* noise */ |
2225 | | out = sn->filtered_noise_bit_ff; |
| 2309 | out = m_filtered_noise_bit_ff; |
2226 | 2310 | break; |
2227 | 2311 | |
2228 | 2312 | case 3: /* VCO and noise */ |
2229 | | out = sn->vco_out_ff & sn->filtered_noise_bit_ff; |
| 2313 | out = m_vco_out_ff & m_filtered_noise_bit_ff; |
2230 | 2314 | break; |
2231 | 2315 | |
2232 | 2316 | case 4: /* SLF and noise */ |
2233 | | out = sn->slf_out_ff & sn->filtered_noise_bit_ff; |
| 2317 | out = m_slf_out_ff & m_filtered_noise_bit_ff; |
2234 | 2318 | break; |
2235 | 2319 | |
2236 | 2320 | case 5: /* VCO, SLF and noise */ |
2237 | | out = sn->vco_out_ff & sn->slf_out_ff & sn->filtered_noise_bit_ff; |
| 2321 | out = m_vco_out_ff & m_slf_out_ff & m_filtered_noise_bit_ff; |
2238 | 2322 | break; |
2239 | 2323 | |
2240 | 2324 | case 6: /* VCO and SLF */ |
2241 | | out = sn->vco_out_ff & sn->slf_out_ff; |
| 2325 | out = m_vco_out_ff & m_slf_out_ff; |
2242 | 2326 | break; |
2243 | 2327 | |
2244 | 2328 | case 7: /* inhibit */ |
r26337 | r26338 | |
2250 | 2334 | /* determine the OUT voltage from the attack/delay cap voltage and clip it */ |
2251 | 2335 | if (out) |
2252 | 2336 | { |
2253 | | voltage_out = OUT_CENTER_LEVEL_VOLTAGE + center_to_peak_voltage_out * out_pos_gain[(int)(sn->attack_decay_cap_voltage * 10)], |
| 2337 | voltage_out = OUT_CENTER_LEVEL_VOLTAGE + center_to_peak_voltage_out * out_pos_gain[(int)(m_attack_decay_cap_voltage * 10)], |
2254 | 2338 | voltage_out = min(voltage_out, OUT_HIGH_CLIP_THRESHOLD); |
2255 | 2339 | } |
2256 | 2340 | else |
2257 | 2341 | { |
2258 | | voltage_out = OUT_CENTER_LEVEL_VOLTAGE + center_to_peak_voltage_out * out_neg_gain[(int)(sn->attack_decay_cap_voltage * 10)], |
| 2342 | voltage_out = OUT_CENTER_LEVEL_VOLTAGE + center_to_peak_voltage_out * out_neg_gain[(int)(m_attack_decay_cap_voltage * 10)], |
2259 | 2343 | voltage_out = max(voltage_out, OUT_LOW_CLIP_THRESHOLD); |
2260 | 2344 | } |
2261 | 2345 | } |
r26337 | r26338 | |
2277 | 2361 | */ |
2278 | 2362 | *buffer++ = (((voltage_out - OUT_LOW_CLIP_THRESHOLD) / (OUT_CENTER_LEVEL_VOLTAGE - OUT_LOW_CLIP_THRESHOLD)) - 1) * 32767; |
2279 | 2363 | |
2280 | | if (LOG_WAV && LOG_WAV_ENABLED_ONLY && !sn->enable) |
| 2364 | if (LOG_WAV && LOG_WAV_ENABLED_ONLY && !m_enable) |
2281 | 2365 | { |
2282 | 2366 | INT16 log_data_l; |
2283 | 2367 | INT16 log_data_r; |
r26337 | r26338 | |
2289 | 2373 | log_data_r = LOG_WAV_GAIN_FACTOR * voltage_out; |
2290 | 2374 | break; |
2291 | 2375 | case 1: |
2292 | | log_data_l = LOG_WAV_GAIN_FACTOR * sn->enable; |
2293 | | log_data_r = LOG_WAV_GAIN_FACTOR * sn->enable; |
| 2376 | log_data_l = LOG_WAV_GAIN_FACTOR * m_enable; |
| 2377 | log_data_r = LOG_WAV_GAIN_FACTOR * m_enable; |
2294 | 2378 | break; |
2295 | 2379 | case 2: |
2296 | | log_data_l = LOG_WAV_GAIN_FACTOR * sn->one_shot_cap_voltage; |
2297 | | log_data_r = LOG_WAV_GAIN_FACTOR * sn->one_shot_cap_voltage; |
| 2380 | log_data_l = LOG_WAV_GAIN_FACTOR * m_one_shot_cap_voltage; |
| 2381 | log_data_r = LOG_WAV_GAIN_FACTOR * m_one_shot_cap_voltage; |
2298 | 2382 | break; |
2299 | 2383 | case 3: |
2300 | | log_data_l = LOG_WAV_GAIN_FACTOR * sn->attack_decay_cap_voltage; |
2301 | | log_data_r = LOG_WAV_GAIN_FACTOR * sn->attack_decay_cap_voltage; |
| 2384 | log_data_l = LOG_WAV_GAIN_FACTOR * m_attack_decay_cap_voltage; |
| 2385 | log_data_r = LOG_WAV_GAIN_FACTOR * m_attack_decay_cap_voltage; |
2302 | 2386 | break; |
2303 | 2387 | case 4: |
2304 | | log_data_l = LOG_WAV_GAIN_FACTOR * sn->slf_cap_voltage; |
2305 | | log_data_r = LOG_WAV_GAIN_FACTOR * sn->slf_cap_voltage; |
| 2388 | log_data_l = LOG_WAV_GAIN_FACTOR * m_slf_cap_voltage; |
| 2389 | log_data_r = LOG_WAV_GAIN_FACTOR * m_slf_cap_voltage; |
2306 | 2390 | break; |
2307 | 2391 | case 5: |
2308 | | log_data_l = LOG_WAV_GAIN_FACTOR * sn->vco_cap_voltage; |
2309 | | log_data_r = LOG_WAV_GAIN_FACTOR * sn->vco_cap_voltage; |
| 2392 | log_data_l = LOG_WAV_GAIN_FACTOR * m_vco_cap_voltage; |
| 2393 | log_data_r = LOG_WAV_GAIN_FACTOR * m_vco_cap_voltage; |
2310 | 2394 | break; |
2311 | 2395 | case 6: |
2312 | | log_data_l = LOG_WAV_GAIN_FACTOR * sn->noise_filter_cap_voltage; |
2313 | | log_data_r = LOG_WAV_GAIN_FACTOR * sn->noise_filter_cap_voltage; |
| 2396 | log_data_l = LOG_WAV_GAIN_FACTOR * m_noise_filter_cap_voltage; |
| 2397 | log_data_r = LOG_WAV_GAIN_FACTOR * m_noise_filter_cap_voltage; |
2314 | 2398 | break; |
2315 | 2399 | } |
2316 | 2400 | |
2317 | | add_wav_data(sn, log_data_l, log_data_r); |
| 2401 | add_wav_data(log_data_l, log_data_r); |
2318 | 2402 | } |
2319 | 2403 | } |
2320 | 2404 | } |
2321 | | |
2322 | | |
2323 | | |
2324 | | /***************************************************************************** |
2325 | | * |
2326 | | * State saving |
2327 | | * |
2328 | | *****************************************************************************/ |
2329 | | |
2330 | | static void state_save_register(device_t *device, sn76477_state *sn) |
2331 | | { |
2332 | | device->save_item(NAME(sn->enable)); |
2333 | | device->save_item(NAME(sn->envelope_mode)); |
2334 | | device->save_item(NAME(sn->vco_mode)); |
2335 | | device->save_item(NAME(sn->mixer_mode)); |
2336 | | |
2337 | | device->save_item(NAME(sn->one_shot_res)); |
2338 | | device->save_item(NAME(sn->one_shot_cap)); |
2339 | | device->save_item(NAME(sn->one_shot_cap_voltage_ext)); |
2340 | | |
2341 | | device->save_item(NAME(sn->slf_res)); |
2342 | | device->save_item(NAME(sn->slf_cap)); |
2343 | | device->save_item(NAME(sn->slf_cap_voltage_ext)); |
2344 | | |
2345 | | device->save_item(NAME(sn->vco_voltage)); |
2346 | | device->save_item(NAME(sn->vco_res)); |
2347 | | device->save_item(NAME(sn->vco_cap)); |
2348 | | device->save_item(NAME(sn->vco_cap_voltage_ext)); |
2349 | | |
2350 | | device->save_item(NAME(sn->noise_clock_res)); |
2351 | | device->save_item(NAME(sn->noise_clock_ext)); |
2352 | | device->save_item(NAME(sn->noise_clock)); |
2353 | | device->save_item(NAME(sn->noise_filter_res)); |
2354 | | device->save_item(NAME(sn->noise_filter_cap)); |
2355 | | device->save_item(NAME(sn->noise_filter_cap_voltage_ext)); |
2356 | | |
2357 | | device->save_item(NAME(sn->attack_res)); |
2358 | | device->save_item(NAME(sn->decay_res)); |
2359 | | device->save_item(NAME(sn->attack_decay_cap)); |
2360 | | device->save_item(NAME(sn->attack_decay_cap_voltage_ext)); |
2361 | | |
2362 | | device->save_item(NAME(sn->amplitude_res)); |
2363 | | device->save_item(NAME(sn->feedback_res)); |
2364 | | device->save_item(NAME(sn->pitch_voltage)); |
2365 | | |
2366 | | device->save_item(NAME(sn->one_shot_cap_voltage)); |
2367 | | device->save_item(NAME(sn->one_shot_running_ff)); |
2368 | | |
2369 | | device->save_item(NAME(sn->slf_cap_voltage)); |
2370 | | device->save_item(NAME(sn->slf_out_ff)); |
2371 | | |
2372 | | device->save_item(NAME(sn->vco_cap_voltage)); |
2373 | | device->save_item(NAME(sn->vco_out_ff)); |
2374 | | device->save_item(NAME(sn->vco_alt_pos_edge_ff)); |
2375 | | |
2376 | | device->save_item(NAME(sn->noise_filter_cap_voltage)); |
2377 | | device->save_item(NAME(sn->real_noise_bit_ff)); |
2378 | | device->save_item(NAME(sn->filtered_noise_bit_ff)); |
2379 | | device->save_item(NAME(sn->noise_gen_count)); |
2380 | | |
2381 | | device->save_item(NAME(sn->attack_decay_cap_voltage)); |
2382 | | |
2383 | | device->save_item(NAME(sn->rng)); |
2384 | | } |
2385 | | |
2386 | | |
2387 | | |
2388 | | /***************************************************************************** |
2389 | | * |
2390 | | * Sound interface glue functions |
2391 | | * |
2392 | | *****************************************************************************/ |
2393 | | |
2394 | | static DEVICE_START( sn76477 ) |
2395 | | { |
2396 | | sn76477_state *sn = get_safe_token(device); |
2397 | | sn76477_interface *intf; |
2398 | | |
2399 | | |
2400 | | #if TEST_MODE == 0 |
2401 | | intf = (sn76477_interface *)device->static_config(); |
2402 | | #else |
2403 | | intf = &test_interface; |
2404 | | #endif |
2405 | | |
2406 | | |
2407 | | sn->device = device; |
2408 | | |
2409 | | sn->channel = device->machine().sound().stream_alloc(*device, 0, 1, device->machine().sample_rate(), sn, SN76477_update); |
2410 | | |
2411 | | if (device->clock() > 0) |
2412 | | { |
2413 | | sn->sample_rate = device->clock(); |
2414 | | } |
2415 | | else |
2416 | | { |
2417 | | sn->sample_rate = device->machine().sample_rate(); |
2418 | | } |
2419 | | |
2420 | | intialize_noise(sn); |
2421 | | |
2422 | | /* set up interface values */ |
2423 | | _SN76477_enable_w(sn, intf->enable); |
2424 | | _SN76477_vco_w(sn, intf->vco); |
2425 | | _SN76477_mixer_a_w(sn, intf->mixer_a); |
2426 | | _SN76477_mixer_b_w(sn, intf->mixer_b); |
2427 | | _SN76477_mixer_c_w(sn, intf->mixer_c); |
2428 | | _SN76477_envelope_1_w(sn, intf->envelope_1); |
2429 | | _SN76477_envelope_2_w(sn, intf->envelope_2); |
2430 | | _SN76477_one_shot_res_w(sn, intf->one_shot_res); |
2431 | | _SN76477_one_shot_cap_w(sn, intf->one_shot_cap); |
2432 | | _SN76477_slf_res_w(sn, intf->slf_res); |
2433 | | _SN76477_slf_cap_w(sn, intf->slf_cap); |
2434 | | _SN76477_vco_res_w(sn, intf->vco_res); |
2435 | | _SN76477_vco_cap_w(sn, intf->vco_cap); |
2436 | | _SN76477_vco_voltage_w(sn, intf->vco_voltage); |
2437 | | _SN76477_noise_clock_res_w(sn, intf->noise_clock_res); |
2438 | | _SN76477_noise_filter_res_w(sn, intf->noise_filter_res); |
2439 | | _SN76477_noise_filter_cap_w(sn, intf->noise_filter_cap); |
2440 | | _SN76477_decay_res_w(sn, intf->decay_res); |
2441 | | _SN76477_attack_res_w(sn, intf->attack_res); |
2442 | | _SN76477_attack_decay_cap_w(sn, intf->attack_decay_cap); |
2443 | | _SN76477_amplitude_res_w(sn, intf->amplitude_res); |
2444 | | _SN76477_feedback_res_w(sn, intf->feedback_res); |
2445 | | _SN76477_pitch_voltage_w(sn, intf->pitch_voltage); |
2446 | | |
2447 | | sn->one_shot_cap_voltage = ONE_SHOT_CAP_VOLTAGE_MIN; |
2448 | | sn->slf_cap_voltage = SLF_CAP_VOLTAGE_MIN; |
2449 | | sn->vco_cap_voltage = VCO_CAP_VOLTAGE_MIN; |
2450 | | sn->noise_filter_cap_voltage = NOISE_CAP_VOLTAGE_MIN; |
2451 | | sn->attack_decay_cap_voltage = AD_CAP_VOLTAGE_MIN; |
2452 | | |
2453 | | state_save_register(device, sn); |
2454 | | |
2455 | | log_complete_state(sn); |
2456 | | |
2457 | | if (LOG_WAV) |
2458 | | open_wav_file(sn); |
2459 | | } |
2460 | | |
2461 | | |
2462 | | static DEVICE_STOP( sn76477 ) |
2463 | | { |
2464 | | sn76477_state *sn = get_safe_token(device); |
2465 | | |
2466 | | if (LOG_WAV) |
2467 | | close_wav_file(sn); |
2468 | | } |
2469 | | |
2470 | | const device_type SN76477 = &device_creator<sn76477_device>; |
2471 | | |
2472 | | sn76477_device::sn76477_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock) |
2473 | | : device_t(mconfig, SN76477, "SN76477", tag, owner, clock, "sn76477", __FILE__), |
2474 | | device_sound_interface(mconfig, *this) |
2475 | | { |
2476 | | m_token = global_alloc_clear(sn76477_state); |
2477 | | } |
2478 | | |
2479 | | //------------------------------------------------- |
2480 | | // device_config_complete - perform any |
2481 | | // operations now that the configuration is |
2482 | | // complete |
2483 | | //------------------------------------------------- |
2484 | | |
2485 | | void sn76477_device::device_config_complete() |
2486 | | { |
2487 | | } |
2488 | | |
2489 | | //------------------------------------------------- |
2490 | | // device_start - device-specific startup |
2491 | | //------------------------------------------------- |
2492 | | |
2493 | | void sn76477_device::device_start() |
2494 | | { |
2495 | | DEVICE_START_NAME( sn76477 )(this); |
2496 | | } |
2497 | | |
2498 | | //------------------------------------------------- |
2499 | | // device_stop - device-specific stop |
2500 | | //------------------------------------------------- |
2501 | | |
2502 | | void sn76477_device::device_stop() |
2503 | | { |
2504 | | DEVICE_STOP_NAME( sn76477 )(this); |
2505 | | } |
2506 | | |
2507 | | //------------------------------------------------- |
2508 | | // sound_stream_update - handle a stream update |
2509 | | //------------------------------------------------- |
2510 | | |
2511 | | void sn76477_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) |
2512 | | { |
2513 | | // should never get here |
2514 | | fatalerror("sound_stream_update called; not applicable to legacy sound devices\n"); |
2515 | | } |