Previous 199869 Revisions Next

r26338 Thursday 21st November, 2013 at 16:59:31 UTC by Osso
Modernized the sn76477 sound device (nw)
[src/emu/sound]sn76477.c sn76477.h
[src/mame/audio]8080bw.c astrof.c crbaloon.c laserbat.c mw8080bw.c n8080.c snk6502.c
[src/mame/drivers]8080bw.c astrof.c crbaloon.c dai3wksi.c laserbat.c rotaryf.c route16.c snk6502.c spectra.c toratora.c
[src/mame/includes]8080bw.h astrof.h crbaloon.h laserbat.h mw8080bw.h n8080.h route16.h
[src/mame/machine]mw8080bw.c
[src/mame/video]route16.c
[src/mess/drivers]abc80.c hec2hrp.c interact.c
[src/mess/includes]hec2hrp.h
[src/mess/machine]hec2hrp.c hecdisk2.c
[src/mess/video]hec2video.c

trunk/src/emu/sound/sn76477.c
r26337r26338
3030#include "emu.h"
3131#include "wavwrite.h"
3232#include "sn76477.h"
33#include "devlegcy.h"
3433
3534
3635
r26337r26338
6867
6968#define LOG(n,x) do { if (VERBOSE >= (n)) logerror x; } while (0)
7069
71#define CHECK_CHIP_NUM                  assert(sn != NULL)
70#define CHECK_CHIP_NUM                  assert(this != NULL)
7271#define CHECK_CHIP_NUM_AND_BOOLEAN      CHECK_CHIP_NUM; assert((state & 0x01) == state)
7372#define CHECK_CHIP_NUM_AND_POSITIVE     CHECK_CHIP_NUM; assert(data >= 0.0)
7473#define CHECK_CHIP_NUM_AND_VOLTAGE      CHECK_CHIP_NUM; assert((data >= 0.0) && (data <= 5.0))
r26337r26338
122121   0           /* 9  enable           */
123122};
124123
125#define test_interface empty_empty_interface
124#define test_interface empty_interface
126125
127126#endif
128127
r26337r26338
187186};
188187
189188
189const device_type SN76477 = &device_creator<sn76477_device>;
190190
191/*****************************************************************************
192 *
193 *  State structure
194 *
195 *****************************************************************************/
196
197struct sn76477_state
191sn76477_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)
198237{
199   /* chip's external interface */
200   UINT32 enable;
201   UINT32 envelope_mode;
202   UINT32 vco_mode;
203   UINT32 mixer_mode;
238}
204239
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//-------------------------------------------------
208245
209   double slf_res;
210   double slf_cap;
211   UINT32 slf_cap_voltage_ext;
246void 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;
212253
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}
217285
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//-------------------------------------------------
224289
225   double attack_res;
226   double decay_res;
227   double attack_decay_cap;
228   UINT32 attack_decay_cap_voltage_ext;
290void sn76477_device::device_start()
291{
292   m_channel = machine().sound().stream_alloc(*this, 0, 1, machine().sample_rate(), this);
229293
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   }
233302
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);
237329
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;
240335
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();
244337
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();
249339
250   double attack_decay_cap_voltage;    /* voltage on the attack/decay cap */
340   if (LOG_WAV)
341      open_wav_file();
342}
251343
252   UINT32 rng;                         /* current value of the random number generator */
344//-------------------------------------------------
345//  device_stop - device-specific stop
346//-------------------------------------------------
253347
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
263INLINE sn76477_state *get_safe_token(device_t *device)
348void sn76477_device::device_stop()
264349{
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();
268352}
269353
270354
r26337r26338
298382 *
299383 *****************************************************************************/
300384
301static double compute_one_shot_cap_charging_rate(sn76477_state *sn) /* in V/sec */
385double sn76477_device::compute_one_shot_cap_charging_rate() /* in V/sec */
302386{
303387   /* this formula was derived using the data points below
304388
r26337r26338
315399
316400   double ret = 0;
317401
318   if ((sn->one_shot_res > 0) && (sn->one_shot_cap > 0))
402   if ((m_one_shot_res > 0) && (m_one_shot_cap > 0))
319403   {
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);
321405   }
322   else if (sn->one_shot_cap > 0)
406   else if (m_one_shot_cap > 0)
323407   {
324408      /* if no resistor, there is no current to charge the cap,
325409         effectively making the one-shot time effectively infinite */
326410      ret = +1e-30;
327411   }
328   else if (sn->one_shot_res > 0)
412   else if (m_one_shot_res > 0)
329413   {
330414      /* if no cap, the voltage changes extremely fast,
331415         effectively making the one-shot time 0 */
r26337r26338
336420}
337421
338422
339static double compute_one_shot_cap_discharging_rate(sn76477_state *sn) /* in V/sec */
423double sn76477_device::compute_one_shot_cap_discharging_rate() /* in V/sec */
340424{
341425   /* this formula was derived using the data points below
342426
r26337r26338
349433
350434   double ret = 0;
351435
352   if ((sn->one_shot_res > 0) && (sn->one_shot_cap > 0))
436   if ((m_one_shot_res > 0) && (m_one_shot_cap > 0))
353437   {
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);
355439   }
356   else if (sn->one_shot_res > 0)
440   else if (m_one_shot_res > 0)
357441   {
358442      /* if no cap, the voltage changes extremely fast,
359443         effectively making the one-shot time 0 */
r26337r26338
364448}
365449
366450
367static double compute_slf_cap_charging_rate(sn76477_state *sn) /* in V/sec */
451double sn76477_device::compute_slf_cap_charging_rate() /* in V/sec */
368452{
369453   /* this formula was derived using the data points below
370454
r26337r26338
378462   */
379463   double ret = 0;
380464
381   if ((sn->slf_res > 0) && (sn->slf_cap > 0))
465   if ((m_slf_res > 0) && (m_slf_cap > 0))
382466   {
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);
384468   }
385469
386470   return ret;
387471}
388472
389473
390static double compute_slf_cap_discharging_rate(sn76477_state *sn) /* in V/sec */
474double sn76477_device::compute_slf_cap_discharging_rate() /* in V/sec */
391475{
392476   /* this formula was derived using the data points below
393477
r26337r26338
401485   */
402486   double ret = 0;
403487
404   if ((sn->slf_res > 0) && (sn->slf_cap > 0))
488   if ((m_slf_res > 0) && (m_slf_cap > 0))
405489   {
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);
407491   }
408492
409493   return ret;
410494}
411495
412496
413static double compute_vco_cap_charging_discharging_rate(sn76477_state *sn) /* in V/sec */
497double sn76477_device::compute_vco_cap_charging_discharging_rate() /* in V/sec */
414498{
415499   double ret = 0;
416500
417   if ((sn->vco_res > 0) && (sn->vco_cap > 0))
501   if ((m_vco_res > 0) && (m_vco_cap > 0))
418502   {
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);
420504   }
421505
422506   return ret;
423507}
424508
425509
426static double compute_vco_duty_cycle(sn76477_state *sn) /* no measure, just a number */
510double sn76477_device::compute_vco_duty_cycle() /* no measure, just a number */
427511{
428512   double ret = 0.5;   /* 50% */
429513
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))
431515   {
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));
433517
434518      ret = min(ret, 1);
435519   }
r26337r26338
438522}
439523
440524
441static UINT32 compute_noise_gen_freq(sn76477_state *sn) /* in Hz */
525UINT32 sn76477_device::compute_noise_gen_freq() /* in Hz */
442526{
443527   /* this formula was derived using the data points below
444528
r26337r26338
470554
471555   UINT32 ret = 0;
472556
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))
475559   {
476      ret = 339100000 * pow(sn->noise_clock_res, -0.8849);
560      ret = 339100000 * pow(m_noise_clock_res, -0.8849);
477561   }
478562
479563   return ret;
480564}
481565
482566
483static double compute_noise_filter_cap_charging_rate(sn76477_state *sn) /* in V/sec */
567double sn76477_device::compute_noise_filter_cap_charging_rate() /* in V/sec */
484568{
485569   /* this formula was derived using the data points below
486570
r26337r26338
497581
498582   double ret = 0;
499583
500   if ((sn->noise_filter_res > 0) && (sn->noise_filter_cap > 0))
584   if ((m_noise_filter_res > 0) && (m_noise_filter_cap > 0))
501585   {
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);
503587   }
504   else if (sn->noise_filter_cap > 0)
588   else if (m_noise_filter_cap > 0)
505589   {
506590      /* if no resistor, there is no current to charge the cap,
507591         effectively making the filter's output constants */
508592      ret = +1e-30;
509593   }
510   else if (sn->noise_filter_res > 0)
594   else if (m_noise_filter_res > 0)
511595   {
512596      /* if no cap, the voltage changes extremely fast,
513597         effectively disabling the filter */
r26337r26338
518602}
519603
520604
521static double compute_noise_filter_cap_discharging_rate(sn76477_state *sn) /* in V/sec */
605double sn76477_device::compute_noise_filter_cap_discharging_rate() /* in V/sec */
522606{
523607   /* this formula was derived using the data points below
524608
r26337r26338
535619
536620   double ret = 0;
537621
538   if ((sn->noise_filter_res > 0) && (sn->noise_filter_cap > 0))
622   if ((m_noise_filter_res > 0) && (m_noise_filter_cap > 0))
539623   {
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);
541625   }
542   else if (sn->noise_filter_cap > 0)
626   else if (m_noise_filter_cap > 0)
543627   {
544628      /* if no resistor, there is no current to charge the cap,
545629         effectively making the filter's output constants */
546630      ret = +1e-30;
547631   }
548   else if (sn->noise_filter_res > 0)
632   else if (m_noise_filter_res > 0)
549633   {
550634      /* if no cap, the voltage changes extremely fast,
551635         effectively disabling the filter */
r26337r26338
556640}
557641
558642
559static double compute_attack_decay_cap_charging_rate(sn76477_state *sn)  /* in V/sec */
643double sn76477_device::compute_attack_decay_cap_charging_rate()  /* in V/sec */
560644{
561645   double ret = 0;
562646
563   if ((sn->attack_res > 0) && (sn->attack_decay_cap > 0))
647   if ((m_attack_res > 0) && (m_attack_decay_cap > 0))
564648   {
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);
566650   }
567   else if (sn->attack_decay_cap > 0)
651   else if (m_attack_decay_cap > 0)
568652   {
569653      /* if no resistor, there is no current to charge the cap,
570654         effectively making the attack time infinite */
571655      ret = +1e-30;
572656   }
573   else if (sn->attack_res > 0)
657   else if (m_attack_res > 0)
574658   {
575659      /* if no cap, the voltage changes extremely fast,
576660         effectively making the attack time 0 */
r26337r26338
581665}
582666
583667
584static double compute_attack_decay_cap_discharging_rate(sn76477_state *sn)  /* in V/sec */
668double sn76477_device::compute_attack_decay_cap_discharging_rate()  /* in V/sec */
585669{
586670   double ret = 0;
587671
588   if ((sn->decay_res > 0) && (sn->attack_decay_cap > 0))
672   if ((m_decay_res > 0) && (m_attack_decay_cap > 0))
589673   {
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);
591675   }
592   else if (sn->attack_decay_cap > 0)
676   else if (m_attack_decay_cap > 0)
593677   {
594678      /* if no resistor, there is no current to charge the cap,
595679         effectively making the decay time infinite */
596680      ret = +1e-30;
597681   }
598   else if (sn->attack_res > 0)
682   else if (m_attack_res > 0)
599683   {
600684      /* if no cap, the voltage changes extremely fast,
601685         effectively making the decay time 0 */
r26337r26338
606690}
607691
608692
609static double compute_center_to_peak_voltage_out(sn76477_state *sn)
693double sn76477_device::compute_center_to_peak_voltage_out()
610694{
611695   /* this formula was derived using the data points below
612696
r26337r26338
624708
625709   double ret = 0;
626710
627   if (sn->amplitude_res > 0)
711   if (m_amplitude_res > 0)
628712   {
629      ret = 3.818 * (sn->feedback_res / sn->amplitude_res) + 0.03;
713      ret = 3.818 * (m_feedback_res / m_amplitude_res) + 0.03;
630714   }
631715
632716   return ret;
r26337r26338
640724 *
641725 *****************************************************************************/
642726
643static void log_enable_line(sn76477_state *sn)
727void sn76477_device::log_enable_line()
644728{
645729   static const char *const desc[] =
646730   {
647731      "Enabled", "Inhibited"
648732   };
649733
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]));
651735}
652736
653737
654static void log_mixer_mode(sn76477_state *sn)
738void sn76477_device::log_mixer_mode()
655739{
656740   static const char *const desc[] =
657741   {
r26337r26338
659743      "SLF/Noise", "SLF/VCO/Noise", "SLF/VCO", "Inhibit"
660744   };
661745
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]));
663747}
664748
665749
666static void log_envelope_mode(sn76477_state *sn)
750void sn76477_device::log_envelope_mode()
667751{
668752   static const char *const desc[] =
669753   {
670754      "VCO", "One-Shot", "Mixer Only", "VCO with Alternating Polarity"
671755   };
672756
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]));
674758}
675759
676760
677static void log_vco_mode(sn76477_state *sn)
761void sn76477_device::log_vco_mode()
678762{
679763   static const char *const desc[] =
680764   {
681765      "External (Pin 16)", "Internal (SLF)"
682766   };
683767
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]));
685769}
686770
687771
688static void log_one_shot_time(sn76477_state *sn)
772void sn76477_device::log_one_shot_time()
689773{
690   if (!sn->one_shot_cap_voltage_ext)
774   if (!m_one_shot_cap_voltage_ext)
691775   {
692      if (compute_one_shot_cap_charging_rate(sn) > 0)
776      if (compute_one_shot_cap_charging_rate() > 0)
693777      {
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())));
695779      }
696780      else
697781      {
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()));
699783      }
700784   }
701785   else
702786   {
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));
704788   }
705789}
706790
707791
708static void log_slf_freq(sn76477_state *sn)
792void sn76477_device::log_slf_freq()
709793{
710   if (!sn->slf_cap_voltage_ext)
794   if (!m_slf_cap_voltage_ext)
711795   {
712      if (compute_slf_cap_charging_rate(sn) > 0)
796      if (compute_slf_cap_charging_rate() > 0)
713797      {
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;
716800
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)));
718802      }
719803      else
720804      {
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()));
722806      }
723807   }
724808   else
725809   {
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));
727811   }
728812}
729813
730814
731static void log_vco_pitch_voltage(sn76477_state *sn)
815void sn76477_device::log_vco_pitch_voltage()
732816{
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));
734818}
735819
736820
737static void log_vco_duty_cycle(sn76477_state *sn)
821void sn76477_device::log_vco_duty_cycle()
738822{
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));
740824}
741825
742826
743static void log_vco_freq(sn76477_state *sn)
827void sn76477_device::log_vco_freq()
744828{
745   if (!sn->vco_cap_voltage_ext)
829   if (!m_vco_cap_voltage_ext)
746830   {
747      if (compute_vco_cap_charging_discharging_rate(sn) > 0)
831      if (compute_vco_cap_charging_discharging_rate() > 0)
748832      {
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);
751835
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));
753837      }
754838      else
755839      {
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()));
757841      }
758842   }
759843   else
760844   {
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));
762846   }
763847}
764848
765849
766static void log_vco_ext_voltage(sn76477_state *sn)
850void sn76477_device::log_vco_ext_voltage()
767851{
768   if (sn->vco_voltage <= VCO_MAX_EXT_VOLTAGE)
852   if (m_vco_voltage <= VCO_MAX_EXT_VOLTAGE)
769853   {
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);
772856
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)));
776860   }
777861   else
778862   {
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));
780864   }
781865}
782866
783867
784static void log_noise_gen_freq(sn76477_state *sn)
868void sn76477_device::log_noise_gen_freq()
785869{
786   if (sn->noise_clock_ext)
870   if (m_noise_clock_ext)
787871   {
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()));
789873   }
790874   else
791875   {
792      if (compute_noise_gen_freq(sn) > 0)
876      if (compute_noise_gen_freq() > 0)
793877      {
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()));
795879      }
796880      else
797881      {
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()));
799883      }
800884   }
801885}
802886
803887
804static void log_noise_filter_freq(sn76477_state *sn)
888void sn76477_device::log_noise_filter_freq()
805889{
806   if (!sn->noise_filter_cap_voltage_ext)
890   if (!m_noise_filter_cap_voltage_ext)
807891   {
808      double charging_rate = compute_noise_filter_cap_charging_rate(sn);
892      double charging_rate = compute_noise_filter_cap_charging_rate();
809893
810894      if (charging_rate > 0)
811895      {
r26337r26338
814898            double charging_time = (1 / charging_rate) * NOISE_CAP_VOLTAGE_RANGE;
815899            double discharging_time = (1 / charging_rate) * NOISE_CAP_VOLTAGE_RANGE;
816900
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)));
818902         }
819903         else
820904         {
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()));
822906         }
823907      }
824908      else
825909      {
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()));
827911      }
828912   }
829913   else
830914   {
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));
832916   }
833917}
834918
835919
836static void log_attack_time(sn76477_state *sn)
920void sn76477_device::log_attack_time()
837921{
838   if (!sn->attack_decay_cap_voltage_ext)
922   if (!m_attack_decay_cap_voltage_ext)
839923   {
840      if (compute_attack_decay_cap_charging_rate(sn) > 0)
924      if (compute_attack_decay_cap_charging_rate() > 0)
841925      {
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())));
843927      }
844928      else
845929      {
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()));
847931      }
848932   }
849933   else
850934   {
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));
852936   }
853937}
854938
855939
856static void log_decay_time(sn76477_state *sn)
940void sn76477_device::log_decay_time()
857941{
858   if (!sn->attack_decay_cap_voltage_ext)
942   if (!m_attack_decay_cap_voltage_ext)
859943   {
860      if (compute_attack_decay_cap_discharging_rate(sn) > 0)
944      if (compute_attack_decay_cap_discharging_rate() > 0)
861945      {
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())));
863947      }
864948      else
865949      {
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()));
867951      }
868952   }
869953   else
870954   {
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));
872956   }
873957}
874958
875959
876static void log_voltage_out(sn76477_state *sn)
960void sn76477_device::log_voltage_out()
877961{
878962   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)],
882966         OUT_HIGH_CLIP_THRESHOLD));
883967}
884968
885969
886static void log_complete_state(sn76477_state *sn)
970void sn76477_device::log_complete_state()
887971{
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();
903987}
904988
905989
r26337r26338
911995 *****************************************************************************/
912996
913997
914static void open_wav_file(sn76477_state *sn)
998void sn76477_device::open_wav_file()
915999{
9161000   char wav_file_name[30];
9171001
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);
9201004
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));
9221006}
9231007
9241008
925static void close_wav_file(sn76477_state *sn)
1009void sn76477_device::close_wav_file()
9261010{
927   wav_close(sn->file);
1011   wav_close(m_file);
9281012}
9291013
9301014
931static void add_wav_data(sn76477_state *sn, INT16 data_l, INT16 data_r)
1015void sn76477_device::add_wav_data(INT16 data_l, INT16 data_r)
9321016{
933   wav_add_data_16lr(sn->file, &data_l, &data_r, 1);
1017   wav_add_data_16lr(m_file, &data_l, &data_r, 1);
9341018}
9351019
9361020
r26337r26338
9411025 *
9421026 *****************************************************************************/
9431027
944static void intialize_noise(sn76477_state *sn)
1028void sn76477_device::intialize_noise()
9451029{
946   sn->rng = 0;
1030   m_rng = 0;
9471031}
9481032
9491033
950INLINE UINT32 generate_next_real_noise_bit(sn76477_state *sn)
1034inline UINT32 sn76477_device::generate_next_real_noise_bit()
9511035{
952   UINT32 out = ((sn->rng >> 28) & 1) ^ ((sn->rng >> 0) & 1);
1036   UINT32 out = ((m_rng >> 28) & 1) ^ ((m_rng >> 0) & 1);
9531037
9541038      /* 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)
9561040   {
9571041      out = 1;
9581042   }
9591043
960   sn->rng = (sn->rng >> 1) | (out << 30);
1044   m_rng = (m_rng >> 1) | (out << 30);
9611045
9621046   return out;
9631047}
r26337r26338
9701054 *
9711055 *****************************************************************************/
9721056
973static void _SN76477_enable_w(sn76477_state *sn, UINT32 data)
1057void sn76477_device::_SN76477_enable_w(UINT32 data)
9741058{
975   sn->enable = data;
1059   m_enable = data;
9761060
9771061      /* if falling edge */
978   if (!sn->enable)
1062   if (!m_enable)
9791063   {
9801064      /* start the attack phase */
981      sn->attack_decay_cap_voltage = AD_CAP_VOLTAGE_MIN;
1065      m_attack_decay_cap_voltage = AD_CAP_VOLTAGE_MIN;
9821066
9831067      /* one-shot runs regardless of envelope mode */
984      sn->one_shot_running_ff = 1;
1068      m_one_shot_running_ff = 1;
9851069   }
9861070}
9871071
9881072
989static void SN76477_test_enable_w(sn76477_state *sn, UINT32 data)
1073void sn76477_device::SN76477_test_enable_w(UINT32 data)
9901074{
991   if (data != sn->enable)
1075   if (data != m_enable)
9921076   {
993      sn->channel->update();
1077      m_channel->update();
9941078
995      _SN76477_enable_w(sn, data);
1079      _SN76477_enable_w(data);
9961080
997      log_enable_line(sn);
1081      log_enable_line();
9981082   }
9991083}
10001084
10011085
1002WRITE_LINE_DEVICE_HANDLER( sn76477_enable_w )
1086WRITE_LINE_MEMBER( sn76477_device::enable_w )
10031087{
10041088#if TEST_MODE == 0
1005   sn76477_state *sn = get_safe_token(device);
1006
10071089   CHECK_CHIP_NUM_AND_BOOLEAN;
10081090
1009   SN76477_test_enable_w(sn, state);
1091   SN76477_test_enable_w(state);
10101092#endif
10111093}
10121094
r26337r26338
10181100 *
10191101 *****************************************************************************/
10201102
1021static void _SN76477_mixer_a_w(sn76477_state *sn, UINT32 data)
1103void sn76477_device::_SN76477_mixer_a_w(UINT32 data)
10221104{
1023   sn->mixer_mode = (sn->mixer_mode & ~0x01) | (data << 0);
1105   m_mixer_mode = (m_mixer_mode & ~0x01) | (data << 0);
10241106}
10251107
10261108
1027WRITE_LINE_DEVICE_HANDLER( sn76477_mixer_a_w )
1109WRITE_LINE_MEMBER( sn76477_device::mixer_a_w )
10281110{
10291111#if TEST_MODE == 0
1030   sn76477_state *sn = get_safe_token(device);
1031
10321112   CHECK_CHIP_NUM_AND_BOOLEAN;
10331113
1034   if (state != ((sn->mixer_mode >> 0) & 0x01))
1114   if (state != ((m_mixer_mode >> 0) & 0x01))
10351115   {
1036      sn->channel->update();
1116      m_channel->update();
10371117
1038      _SN76477_mixer_a_w(sn, state);
1118      _SN76477_mixer_a_w(state);
10391119
1040      log_mixer_mode(sn);
1120      log_mixer_mode();
10411121   }
10421122#endif
10431123}
10441124
10451125
1046static void _SN76477_mixer_b_w(sn76477_state *sn, UINT32 data)
1126void sn76477_device::_SN76477_mixer_b_w(UINT32 data)
10471127{
1048   sn->mixer_mode = (sn->mixer_mode & ~0x02) | (data << 1);
1128   m_mixer_mode = (m_mixer_mode & ~0x02) | (data << 1);
10491129}
10501130
10511131
1052WRITE_LINE_DEVICE_HANDLER( sn76477_mixer_b_w )
1132WRITE_LINE_MEMBER( sn76477_device::mixer_b_w )
10531133{
10541134#if TEST_MODE == 0
1055   sn76477_state *sn = get_safe_token(device);
1056
10571135   CHECK_CHIP_NUM_AND_BOOLEAN;
10581136
1059   if (state != ((sn->mixer_mode >> 1) & 0x01))
1137   if (state != ((m_mixer_mode >> 1) & 0x01))
10601138   {
1061      sn->channel->update();
1139      m_channel->update();
10621140
1063      _SN76477_mixer_b_w(sn, state);
1141      _SN76477_mixer_b_w(state);
10641142
1065      log_mixer_mode(sn);
1143      log_mixer_mode();
10661144   }
10671145#endif
10681146}
10691147
10701148
1071static void _SN76477_mixer_c_w(sn76477_state *sn, UINT32 data)
1149void sn76477_device::_SN76477_mixer_c_w(UINT32 data)
10721150{
1073   sn->mixer_mode = (sn->mixer_mode & ~0x04) | (data << 2);
1151   m_mixer_mode = (m_mixer_mode & ~0x04) | (data << 2);
10741152}
10751153
10761154
1077WRITE_LINE_DEVICE_HANDLER( sn76477_mixer_c_w )
1155WRITE_LINE_MEMBER( sn76477_device::mixer_c_w )
10781156{
10791157#if TEST_MODE == 0
1080   sn76477_state *sn = get_safe_token(device);
1081
10821158   CHECK_CHIP_NUM_AND_BOOLEAN;
10831159
1084   if (state != ((sn->mixer_mode >> 2) & 0x01))
1160   if (state != ((m_mixer_mode >> 2) & 0x01))
10851161   {
1086      sn->channel->update();
1162      m_channel->update();
10871163
1088      _SN76477_mixer_c_w(sn, state);
1164      _SN76477_mixer_c_w(state);
10891165
1090      log_mixer_mode(sn);
1166      log_mixer_mode();
10911167   }
10921168#endif
10931169}
r26337r26338
11001176 *
11011177 *****************************************************************************/
11021178
1103static void _SN76477_envelope_1_w(sn76477_state *sn, UINT32 data)
1179void sn76477_device::_SN76477_envelope_1_w(UINT32 data)
11041180{
1105   sn->envelope_mode = (sn->envelope_mode & ~0x01) | (data << 0);
1181   m_envelope_mode = (m_envelope_mode & ~0x01) | (data << 0);
11061182}
11071183
11081184
1109WRITE_LINE_DEVICE_HANDLER( sn76477_envelope_1_w )
1185WRITE_LINE_MEMBER( sn76477_device::envelope_1_w )
11101186{
11111187#if TEST_MODE == 0
1112   sn76477_state *sn = get_safe_token(device);
1113
11141188   CHECK_CHIP_NUM_AND_BOOLEAN;
11151189
1116   if (state != ((sn->envelope_mode >> 0) & 0x01))
1190   if (state != ((m_envelope_mode >> 0) & 0x01))
11171191   {
1118      sn->channel->update();
1192      m_channel->update();
11191193
1120      _SN76477_envelope_1_w(sn, state);
1194      _SN76477_envelope_1_w(state);
11211195
1122      log_envelope_mode(sn);
1196      log_envelope_mode();
11231197   }
11241198#endif
11251199}
11261200
11271201
1128static void _SN76477_envelope_2_w(sn76477_state *sn, UINT32 data)
1202void sn76477_device::_SN76477_envelope_2_w(UINT32 data)
11291203{
1130   sn->envelope_mode = (sn->envelope_mode & ~0x02) | (data << 1);
1204   m_envelope_mode = (m_envelope_mode & ~0x02) | (data << 1);
11311205}
11321206
11331207
1134WRITE_LINE_DEVICE_HANDLER( sn76477_envelope_2_w )
1208WRITE_LINE_MEMBER( sn76477_device::envelope_2_w )
11351209{
11361210#if TEST_MODE == 0
1137   sn76477_state *sn = get_safe_token(device);
1138
11391211   CHECK_CHIP_NUM_AND_BOOLEAN;
11401212
1141   if (state != ((sn->envelope_mode >> 1) & 0x01))
1213   if (state != ((m_envelope_mode >> 1) & 0x01))
11421214   {
1143      sn->channel->update();
1215      m_channel->update();
11441216
1145      _SN76477_envelope_2_w(sn, state);
1217      _SN76477_envelope_2_w(state);
11461218
1147      log_envelope_mode(sn);
1219      log_envelope_mode();
11481220   }
11491221#endif
11501222}
r26337r26338
11571229 *
11581230 *****************************************************************************/
11591231
1160static void _SN76477_vco_w(sn76477_state *sn, UINT32 data)
1232void sn76477_device::_SN76477_vco_w(UINT32 data)
11611233{
1162   sn->vco_mode = data;
1234   m_vco_mode = data;
11631235}
11641236
11651237
1166WRITE_LINE_DEVICE_HANDLER( sn76477_vco_w )
1238WRITE_LINE_MEMBER( sn76477_device::vco_w )
11671239{
11681240#if TEST_MODE == 0
1169   sn76477_state *sn = get_safe_token(device);
1170
11711241   CHECK_CHIP_NUM_AND_BOOLEAN;
11721242
1173   if (state != sn->vco_mode)
1243   if (state != m_vco_mode)
11741244   {
1175      sn->channel->update();
1245      m_channel->update();
11761246
1177      _SN76477_vco_w(sn, state);
1247      _SN76477_vco_w(state);
11781248
1179      log_vco_mode(sn);
1249      log_vco_mode();
11801250   }
11811251#endif
11821252}
r26337r26338
11891259 *
11901260 *****************************************************************************/
11911261
1192static void _SN76477_one_shot_res_w(sn76477_state *sn, double data)
1262void sn76477_device::_SN76477_one_shot_res_w(double data)
11931263{
1194   sn->one_shot_res = data;
1264   m_one_shot_res = data;
11951265}
11961266
11971267
1198void sn76477_one_shot_res_w(device_t *device, double data)
1268void sn76477_device::one_shot_res_w(double data)
11991269{
12001270#if TEST_MODE == 0
1201   sn76477_state *sn = get_safe_token(device);
1202
12031271   CHECK_CHIP_NUM_AND_POSITIVE;
12041272
1205   if (data != sn->one_shot_res)
1273   if (data != m_one_shot_res)
12061274   {
1207      sn->channel->update();
1275      m_channel->update();
12081276
1209      _SN76477_one_shot_res_w(sn, data);
1277      _SN76477_one_shot_res_w(data);
12101278
1211      log_one_shot_time(sn);
1279      log_one_shot_time();
12121280   }
12131281#endif
12141282}
r26337r26338
12211289 *
12221290 *****************************************************************************/
12231291
1224static void _SN76477_one_shot_cap_w(sn76477_state *sn, double data)
1292void sn76477_device::_SN76477_one_shot_cap_w(double data)
12251293{
1226   sn->one_shot_cap = data;
1294   m_one_shot_cap = data;
12271295}
12281296
12291297
1230void sn76477_one_shot_cap_w(device_t *device, double data)
1298void sn76477_device::one_shot_cap_w(double data)
12311299{
12321300#if TEST_MODE == 0
1233   sn76477_state *sn = get_safe_token(device);
1234
12351301   CHECK_CHIP_NUM_AND_POSITIVE;
12361302
1237   if (data != sn->one_shot_cap)
1303   if (data != m_one_shot_cap)
12381304   {
1239      sn->channel->update();
1305      m_channel->update();
12401306
1241      _SN76477_one_shot_cap_w(sn, data);
1307      _SN76477_one_shot_cap_w(data);
12421308
1243      log_one_shot_time(sn);
1309      log_one_shot_time();
12441310   }
12451311#endif
12461312}
r26337r26338
12531319 *
12541320 *****************************************************************************/
12551321
1256void sn76477_one_shot_cap_voltage_w(device_t *device, double data)
1322void sn76477_device::one_shot_cap_voltage_w(double data)
12571323{
12581324#if TEST_MODE == 0
1259   sn76477_state *sn = get_safe_token(device);
1260
12611325   CHECK_CHIP_NUM_AND_CAP_VOLTAGE;
12621326
12631327   if (data == SN76477_EXTERNAL_VOLTAGE_DISCONNECT)
12641328   {
12651329      /* switch to internal, if not already */
1266      if (sn->one_shot_cap_voltage_ext)
1330      if (m_one_shot_cap_voltage_ext)
12671331      {
1268         sn->channel->update();
1332         m_channel->update();
12691333
1270         sn->one_shot_cap_voltage_ext = 0;
1334         m_one_shot_cap_voltage_ext = 0;
12711335
1272         log_one_shot_time(sn);
1336         log_one_shot_time();
12731337      }
12741338   }
12751339   else
12761340   {
12771341      /* 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))
12791343      {
1280         sn->channel->update();
1344         m_channel->update();
12811345
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;
12841348
1285         log_one_shot_time(sn);
1349         log_one_shot_time();
12861350      }
12871351   }
12881352#endif
r26337r26338
12961360 *
12971361 *****************************************************************************/
12981362
1299static void _SN76477_slf_res_w(sn76477_state *sn, double data)
1363void sn76477_device::_SN76477_slf_res_w(double data)
13001364{
1301   sn->slf_res = data;
1365   m_slf_res = data;
13021366}
13031367
13041368
1305void sn76477_slf_res_w(device_t *device, double data)
1369void sn76477_device::slf_res_w(double data)
13061370{
13071371#if TEST_MODE == 0
1308   sn76477_state *sn = get_safe_token(device);
1309
13101372   CHECK_CHIP_NUM_AND_POSITIVE;
13111373
1312   if (data != sn->slf_res)
1374   if (data != m_slf_res)
13131375   {
1314      sn->channel->update();
1376      m_channel->update();
13151377
1316      _SN76477_slf_res_w(sn, data);
1378      _SN76477_slf_res_w(data);
13171379
1318      log_slf_freq(sn);
1380      log_slf_freq();
13191381   }
13201382#endif
13211383}
r26337r26338
13281390 *
13291391 *****************************************************************************/
13301392
1331static void _SN76477_slf_cap_w(sn76477_state *sn, double data)
1393void sn76477_device::_SN76477_slf_cap_w(double data)
13321394{
1333   sn->slf_cap = data;
1395   m_slf_cap = data;
13341396}
13351397
13361398
1337void sn76477_slf_cap_w(device_t *device, double data)
1399void sn76477_device::slf_cap_w(double data)
13381400{
13391401#if TEST_MODE == 0
1340   sn76477_state *sn = get_safe_token(device);
1341
13421402   CHECK_CHIP_NUM_AND_POSITIVE;
13431403
1344   if (data != sn->slf_cap)
1404   if (data != m_slf_cap)
13451405   {
1346      sn->channel->update();
1406      m_channel->update();
13471407
1348      _SN76477_slf_cap_w(sn, data);
1408      _SN76477_slf_cap_w(data);
13491409
1350      log_slf_freq(sn);
1410      log_slf_freq();
13511411   }
13521412#endif
13531413}
r26337r26338
13621422 *
13631423 *****************************************************************************/
13641424
1365void sn76477_slf_cap_voltage_w(device_t *device, double data)
1425void sn76477_device::slf_cap_voltage_w(double data)
13661426{
13671427#if TEST_MODE == 0
1368   sn76477_state *sn = get_safe_token(device);
1369
13701428   CHECK_CHIP_NUM_AND_CAP_VOLTAGE;
13711429
13721430   if (data == SN76477_EXTERNAL_VOLTAGE_DISCONNECT)
13731431   {
13741432      /* switch to internal, if not already */
1375      if (sn->slf_cap_voltage_ext)
1433      if (m_slf_cap_voltage_ext)
13761434      {
1377         sn->channel->update();
1435         m_channel->update();
13781436
1379         sn->slf_cap_voltage_ext = 0;
1437         m_slf_cap_voltage_ext = 0;
13801438
1381         log_slf_freq(sn);
1439         log_slf_freq();
13821440      }
13831441   }
13841442   else
13851443   {
13861444      /* 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))
13881446      {
1389         sn->channel->update();
1447         m_channel->update();
13901448
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;
13931451
1394         log_slf_freq(sn);
1452         log_slf_freq();
13951453      }
13961454   }
13971455#endif
r26337r26338
14051463 *
14061464 *****************************************************************************/
14071465
1408static void _SN76477_vco_res_w(sn76477_state *sn, double data)
1466void sn76477_device::_SN76477_vco_res_w(double data)
14091467{
1410   sn->vco_res = data;
1468   m_vco_res = data;
14111469}
14121470
14131471
1414void sn76477_vco_res_w(device_t *device, double data)
1472void sn76477_device::vco_res_w(double data)
14151473{
14161474#if TEST_MODE == 0
1417   sn76477_state *sn = get_safe_token(device);
1418
14191475   CHECK_CHIP_NUM_AND_POSITIVE;
14201476
1421   if (data != sn->vco_res)
1477   if (data != m_vco_res)
14221478   {
1423      sn->channel->update();
1479      m_channel->update();
14241480
1425      _SN76477_vco_res_w(sn, data);
1481      _SN76477_vco_res_w(data);
14261482
1427      log_vco_freq(sn);
1483      log_vco_freq();
14281484   }
14291485#endif
14301486}
r26337r26338
14371493 *
14381494 *****************************************************************************/
14391495
1440static void _SN76477_vco_cap_w(sn76477_state *sn, double data)
1496void sn76477_device::_SN76477_vco_cap_w(double data)
14411497{
1442   sn->vco_cap = data;
1498   m_vco_cap = data;
14431499}
14441500
14451501
1446void sn76477_vco_cap_w(device_t *device, double data)
1502void sn76477_device::vco_cap_w(double data)
14471503{
14481504#if TEST_MODE == 0
1449   sn76477_state *sn = get_safe_token(device);
1450
14511505   CHECK_CHIP_NUM_AND_POSITIVE;
14521506
1453   if (data != sn->vco_cap)
1507   if (data != m_vco_cap)
14541508   {
1455      sn->channel->update();
1509      m_channel->update();
14561510
1457      _SN76477_vco_cap_w(sn, data);
1511      _SN76477_vco_cap_w(data);
14581512
1459      log_vco_freq(sn);
1513      log_vco_freq();
14601514   }
14611515#endif
14621516}
r26337r26338
14691523 *
14701524 *****************************************************************************/
14711525
1472void sn76477_vco_cap_voltage_w(device_t *device, double data)
1526void sn76477_device::vco_cap_voltage_w(double data)
14731527{
14741528#if TEST_MODE == 0
1475   sn76477_state *sn = get_safe_token(device);
1476
14771529   CHECK_CHIP_NUM_AND_CAP_VOLTAGE;
14781530
14791531   if (data == SN76477_EXTERNAL_VOLTAGE_DISCONNECT)
14801532   {
14811533      /* switch to internal, if not already */
1482      if (sn->vco_cap_voltage_ext)
1534      if (m_vco_cap_voltage_ext)
14831535      {
1484         sn->channel->update();
1536         m_channel->update();
14851537
1486         sn->vco_cap_voltage_ext = 0;
1538         m_vco_cap_voltage_ext = 0;
14871539
1488         log_vco_freq(sn);
1540         log_vco_freq();
14891541      }
14901542   }
14911543   else
14921544   {
14931545      /* 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))
14951547      {
1496         sn->channel->update();
1548         m_channel->update();
14971549
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;
15001552
1501         log_vco_freq(sn);
1553         log_vco_freq();
15021554      }
15031555   }
15041556#endif
r26337r26338
15121564 *
15131565 *****************************************************************************/
15141566
1515static void _SN76477_vco_voltage_w(sn76477_state *sn, double data)
1567void sn76477_device::_SN76477_vco_voltage_w(double data)
15161568{
1517   sn->vco_voltage = data;
1569   m_vco_voltage = data;
15181570}
15191571
15201572
1521void sn76477_vco_voltage_w(device_t *device, double data)
1573void sn76477_device::vco_voltage_w(double data)
15221574{
15231575#if TEST_MODE == 0
1524   sn76477_state *sn = get_safe_token(device);
1525
15261576   CHECK_CHIP_NUM_AND_VOLTAGE;
15271577
1528   if (data != sn->vco_voltage)
1578   if (data != m_vco_voltage)
15291579   {
1530      sn->channel->update();
1580      m_channel->update();
15311581
1532      _SN76477_vco_voltage_w(sn, data);
1582      _SN76477_vco_voltage_w(data);
15331583
1534      log_vco_ext_voltage(sn);
1535      log_vco_duty_cycle(sn);
1584      log_vco_ext_voltage();
1585      log_vco_duty_cycle();
15361586   }
15371587#endif
15381588}
r26337r26338
15451595 *
15461596 *****************************************************************************/
15471597
1548static void _SN76477_pitch_voltage_w(sn76477_state *sn, double data)
1598void sn76477_device::_SN76477_pitch_voltage_w(double data)
15491599{
1550   sn->pitch_voltage = data;
1600   m_pitch_voltage = data;
15511601}
15521602
15531603
1554void sn76477_pitch_voltage_w(device_t *device, double data)
1604void sn76477_device::pitch_voltage_w(double data)
15551605{
15561606#if TEST_MODE == 0
1557   sn76477_state *sn = get_safe_token(device);
1558
15591607   CHECK_CHIP_NUM_AND_VOLTAGE;
15601608
1561   if (data != sn->pitch_voltage)
1609   if (data != m_pitch_voltage)
15621610   {
1563      sn->channel->update();
1611      m_channel->update();
15641612
1565      _SN76477_pitch_voltage_w(sn, data);
1613      _SN76477_pitch_voltage_w(data);
15661614
1567      log_vco_pitch_voltage(sn);
1568      log_vco_duty_cycle(sn);
1615      log_vco_pitch_voltage();
1616      log_vco_duty_cycle();
15691617   }
15701618#endif
15711619}
r26337r26338
15781626 *
15791627 *****************************************************************************/
15801628
1581WRITE_LINE_DEVICE_HANDLER( sn76477_noise_clock_w )
1629WRITE_LINE_MEMBER( sn76477_device::noise_clock_w )
15821630{
15831631#if TEST_MODE == 0
1584   sn76477_state *sn = get_safe_token(device);
1585
15861632   CHECK_CHIP_NUM_AND_BOOLEAN;
15871633
1588   if (state != sn->noise_clock)
1634   if (state != m_noise_clock)
15891635   {
1590      sn->noise_clock = state;
1636      m_noise_clock = state;
15911637
15921638      /* on the rising edge shift generate next value,
15931639         if external control is enabled */
1594      if (sn->noise_clock && sn->noise_clock_ext)
1640      if (m_noise_clock && m_noise_clock_ext)
15951641      {
1596         sn->channel->update();
1642         m_channel->update();
15971643
1598         sn->real_noise_bit_ff = generate_next_real_noise_bit(sn);
1644         m_real_noise_bit_ff = generate_next_real_noise_bit();
15991645      }
16001646   }
16011647#endif
r26337r26338
16091655 *
16101656 *****************************************************************************/
16111657
1612static void _SN76477_noise_clock_res_w(sn76477_state *sn, double data)
1658void sn76477_device::_SN76477_noise_clock_res_w(double data)
16131659{
16141660   if (data == 0)
16151661   {
1616      sn->noise_clock_ext = 1;
1662      m_noise_clock_ext = 1;
16171663   }
16181664   else
16191665   {
1620      sn->noise_clock_ext = 0;
1666      m_noise_clock_ext = 0;
16211667
1622      sn->noise_clock_res = data;
1668      m_noise_clock_res = data;
16231669   }
16241670}
16251671
16261672
1627void sn76477_noise_clock_res_w(device_t *device, double data)
1673void sn76477_device::noise_clock_res_w(double data)
16281674{
16291675#if TEST_MODE == 0
1630   sn76477_state *sn = get_safe_token(device);
1631
16321676   CHECK_CHIP_NUM_AND_POSITIVE;
16331677
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)))
16361680   {
1637      sn->channel->update();
1681      m_channel->update();
16381682
1639      _SN76477_noise_clock_res_w(sn, data);
1683      _SN76477_noise_clock_res_w(data);
16401684
1641      log_noise_gen_freq(sn);
1685      log_noise_gen_freq();
16421686   }
16431687#endif
16441688}
r26337r26338
16511695 *
16521696 *****************************************************************************/
16531697
1654static void _SN76477_noise_filter_res_w(sn76477_state *sn, double data)
1698void sn76477_device::_SN76477_noise_filter_res_w(double data)
16551699{
1656   sn->noise_filter_res = data;
1700   m_noise_filter_res = data;
16571701}
16581702
16591703
1660void sn76477_noise_filter_res_w(device_t *device, double data)
1704void sn76477_device::noise_filter_res_w(double data)
16611705{
16621706#if TEST_MODE == 0
1663   sn76477_state *sn = get_safe_token(device);
1664
16651707   CHECK_CHIP_NUM_AND_POSITIVE;
16661708
1667   if (data != sn->noise_filter_res)
1709   if (data != m_noise_filter_res)
16681710   {
1669      sn->channel->update();
1711      m_channel->update();
16701712
1671      _SN76477_noise_filter_res_w(sn, data);
1713      _SN76477_noise_filter_res_w(data);
16721714
1673      log_noise_filter_freq(sn);
1715      log_noise_filter_freq();
16741716   }
16751717#endif
16761718}
r26337r26338
16831725 *
16841726 *****************************************************************************/
16851727
1686static void _SN76477_noise_filter_cap_w(sn76477_state *sn, double data)
1728void sn76477_device::_SN76477_noise_filter_cap_w(double data)
16871729{
1688   sn->noise_filter_cap = data;
1730   m_noise_filter_cap = data;
16891731}
16901732
16911733
1692void sn76477_noise_filter_cap_w(device_t *device, double data)
1734void sn76477_device::noise_filter_cap_w(double data)
16931735{
16941736#if TEST_MODE == 0
1695   sn76477_state *sn = get_safe_token(device);
1696
16971737   CHECK_CHIP_NUM_AND_POSITIVE;
16981738
1699   if (data != sn->noise_filter_cap)
1739   if (data != m_noise_filter_cap)
17001740   {
1701      sn->channel->update();
1741      m_channel->update();
17021742
1703      _SN76477_noise_filter_cap_w(sn, data);
1743      _SN76477_noise_filter_cap_w(data);
17041744
1705      log_noise_filter_freq(sn);
1745      log_noise_filter_freq();
17061746   }
17071747#endif
17081748}
r26337r26338
17151755 *
17161756 *****************************************************************************/
17171757
1718void sn76477_noise_filter_cap_voltage_w(device_t *device, double data)
1758void sn76477_device::noise_filter_cap_voltage_w(double data)
17191759{
17201760#if TEST_MODE == 0
1721   sn76477_state *sn = get_safe_token(device);
1722
17231761   CHECK_CHIP_NUM_AND_CAP_VOLTAGE;
17241762
17251763   if (data == SN76477_EXTERNAL_VOLTAGE_DISCONNECT)
17261764   {
17271765      /* switch to internal, if not already */
1728      if (sn->noise_filter_cap_voltage_ext)
1766      if (m_noise_filter_cap_voltage_ext)
17291767      {
1730         sn->channel->update();
1768         m_channel->update();
17311769
1732         sn->noise_filter_cap_voltage_ext = 0;
1770         m_noise_filter_cap_voltage_ext = 0;
17331771
1734         log_noise_filter_freq(sn);
1772         log_noise_filter_freq();
17351773      }
17361774   }
17371775   else
17381776   {
17391777      /* 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))
17411779      {
1742         sn->channel->update();
1780         m_channel->update();
17431781
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;
17461784
1747         log_noise_filter_freq(sn);
1785         log_noise_filter_freq();
17481786      }
17491787   }
17501788#endif
r26337r26338
17581796 *
17591797 *****************************************************************************/
17601798
1761static void _SN76477_attack_res_w(sn76477_state *sn, double data)
1799void sn76477_device::_SN76477_attack_res_w(double data)
17621800{
1763   sn->attack_res = data;
1801   m_attack_res = data;
17641802}
17651803
17661804
1767void sn76477_attack_res_w(device_t *device, double data)
1805void sn76477_device::attack_res_w(double data)
17681806{
17691807#if TEST_MODE == 0
1770   sn76477_state *sn = get_safe_token(device);
1771
17721808   CHECK_CHIP_NUM_AND_POSITIVE;
17731809
1774   if (data != sn->attack_res)
1810   if (data != m_attack_res)
17751811   {
1776      sn->channel->update();
1812      m_channel->update();
17771813
1778      _SN76477_attack_res_w(sn, data);
1814      _SN76477_attack_res_w(data);
17791815
1780      log_attack_time(sn);
1816      log_attack_time();
17811817   }
17821818#endif
17831819}
r26337r26338
17901826 *
17911827 *****************************************************************************/
17921828
1793static void _SN76477_decay_res_w(sn76477_state *sn, double data)
1829void sn76477_device::_SN76477_decay_res_w(double data)
17941830{
1795   sn->decay_res = data;
1831   m_decay_res = data;
17961832}
17971833
17981834
1799void sn76477_decay_res_w(device_t *device, double data)
1835void sn76477_device::decay_res_w(double data)
18001836{
18011837#if TEST_MODE == 0
1802   sn76477_state *sn = get_safe_token(device);
1803
18041838   CHECK_CHIP_NUM_AND_POSITIVE;
18051839
1806   if (data != sn->decay_res)
1840   if (data != m_decay_res)
18071841   {
1808      sn->channel->update();
1842      m_channel->update();
18091843
1810      _SN76477_decay_res_w(sn, data);
1844      _SN76477_decay_res_w(data);
18111845
1812      log_decay_time(sn);
1846      log_decay_time();
18131847   }
18141848#endif
18151849}
r26337r26338
18221856 *
18231857 *****************************************************************************/
18241858
1825static void _SN76477_attack_decay_cap_w(sn76477_state *sn, double data)
1859void sn76477_device::_SN76477_attack_decay_cap_w(double data)
18261860{
1827   sn->attack_decay_cap = data;
1861   m_attack_decay_cap = data;
18281862}
18291863
18301864
1831void sn76477_attack_decay_cap_w(device_t *device, double data)
1865void sn76477_device::attack_decay_cap_w(double data)
18321866{
18331867#if TEST_MODE == 0
1834   sn76477_state *sn = get_safe_token(device);
1835
18361868   CHECK_CHIP_NUM_AND_POSITIVE;
18371869
1838   if (data != sn->attack_decay_cap)
1870   if (data != m_attack_decay_cap)
18391871   {
1840      sn->channel->update();
1872      m_channel->update();
18411873
1842      _SN76477_attack_decay_cap_w(sn, data);
1874      _SN76477_attack_decay_cap_w(data);
18431875
1844      log_attack_time(sn);
1845      log_decay_time(sn);
1876      log_attack_time();
1877      log_decay_time();
18461878   }
18471879#endif
18481880}
r26337r26338
18551887 *
18561888 *****************************************************************************/
18571889
1858void sn76477_attack_decay_cap_voltage_w(device_t *device, double data)
1890void sn76477_device::attack_decay_cap_voltage_w(double data)
18591891{
18601892#if TEST_MODE == 0
1861   sn76477_state *sn = get_safe_token(device);
1862
18631893   CHECK_CHIP_NUM_AND_CAP_VOLTAGE;
18641894
18651895   if (data == SN76477_EXTERNAL_VOLTAGE_DISCONNECT)
18661896   {
18671897      /* switch to internal, if not already */
1868      if (sn->attack_decay_cap_voltage_ext)
1898      if (m_attack_decay_cap_voltage_ext)
18691899      {
1870         sn->channel->update();
1900         m_channel->update();
18711901
1872         sn->attack_decay_cap_voltage_ext = 0;
1902         m_attack_decay_cap_voltage_ext = 0;
18731903
1874         log_attack_time(sn);
1875         log_decay_time(sn);
1904         log_attack_time();
1905         log_decay_time();
18761906      }
18771907   }
18781908   else
18791909   {
18801910      /* 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))
18821912      {
1883         sn->channel->update();
1913         m_channel->update();
18841914
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;
18871917
1888         log_attack_time(sn);
1889         log_decay_time(sn);
1918         log_attack_time();
1919         log_decay_time();
18901920      }
18911921   }
18921922#endif
r26337r26338
19001930 *
19011931 *****************************************************************************/
19021932
1903static void _SN76477_amplitude_res_w(sn76477_state *sn, double data)
1933void sn76477_device::_SN76477_amplitude_res_w(double data)
19041934{
1905   sn->amplitude_res = data;
1935   m_amplitude_res = data;
19061936}
19071937
19081938
1909void sn76477_amplitude_res_w(device_t *device, double data)
1939void sn76477_device::amplitude_res_w(double data)
19101940{
19111941#if TEST_MODE == 0
1912   sn76477_state *sn = get_safe_token(device);
1913
19141942   CHECK_CHIP_NUM_AND_POSITIVE;
19151943
1916   if (data != sn->amplitude_res)
1944   if (data != m_amplitude_res)
19171945   {
1918      sn->channel->update();
1946      m_channel->update();
19191947
1920      _SN76477_amplitude_res_w(sn, data);
1948      _SN76477_amplitude_res_w(data);
19211949
1922      log_voltage_out(sn);
1950      log_voltage_out();
19231951   }
19241952#endif
19251953}
r26337r26338
19321960 *
19331961 *****************************************************************************/
19341962
1935static void _SN76477_feedback_res_w(sn76477_state *sn, double data)
1963void sn76477_device::_SN76477_feedback_res_w(double data)
19361964{
1937   sn->feedback_res = data;
1965   m_feedback_res = data;
19381966}
19391967
19401968
1941void sn76477_feedback_res_w(device_t *device, double data)
1969void sn76477_device::feedback_res_w(double data)
19421970{
19431971#if TEST_MODE == 0
1944   sn76477_state *sn = get_safe_token(device);
1945
19461972   CHECK_CHIP_NUM_AND_POSITIVE;
19471973
1948   if (data != sn->feedback_res)
1974   if (data != m_feedback_res)
19491975   {
1950      sn->channel->update();
1976      m_channel->update();
19511977
1952      _SN76477_feedback_res_w(sn, data);
1978      _SN76477_feedback_res_w(data);
19531979
1954      log_voltage_out(sn);
1980      log_voltage_out();
19551981   }
19561982#endif
19571983}
19581984
19591985
1960
19611986/*****************************************************************************
19621987 *
1963 *  Sample generation
1988 *  State saving
19641989 *
19651990 *****************************************************************************/
19661991
1967static STREAM_UPDATE( SN76477_update )
1992void sn76477_device::state_save_register()
19681993{
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
2052void sn76477_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples)
2053{
19692054   double one_shot_cap_charging_step;
19702055   double one_shot_cap_discharging_step;
19712056   double slf_cap_charging_step;
r26337r26338
19832068   double voltage_out;
19842069   double center_to_peak_voltage_out;
19852070
1986   sn76477_state *sn = (sn76477_state *)param;
19872071   stream_sample_t *buffer = outputs[0];
19882072
19892073
19902074#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 */
19922076
19932077   if () && !recursing)
19942078   {
19952079      recursing = 1;
19962080
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);
19992083   }
20002084
20012085   recursing = 0;
20022086#endif
20032087
20042088   /* 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;
20072091
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;
20102094
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;
20142098
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();
20182102
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;
20212105
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();
20232107
20242108
20252109   /* process 'samples' number of samples */
20262110   while (samples--)
20272111   {
20282112      /* update the one-shot cap voltage */
2029      if (!sn->one_shot_cap_voltage_ext)
2113      if (!m_one_shot_cap_voltage_ext)
20302114      {
2031         if (sn->one_shot_running_ff)
2115         if (m_one_shot_running_ff)
20322116         {
20332117            /* 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);
20352119         }
20362120         else
20372121         {
20382122            /* 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);
20402124         }
20412125      }
20422126
2043      if (sn->one_shot_cap_voltage >= ONE_SHOT_CAP_VOLTAGE_MAX)
2127      if (m_one_shot_cap_voltage >= ONE_SHOT_CAP_VOLTAGE_MAX)
20442128      {
2045         sn->one_shot_running_ff = 0;
2129         m_one_shot_running_ff = 0;
20462130      }
20472131
20482132
20492133      /* update the SLF (super low frequency oscillator) */
2050      if (!sn->slf_cap_voltage_ext)
2134      if (!m_slf_cap_voltage_ext)
20512135      {
20522136         /* internal */
2053         if (!sn->slf_out_ff)
2137         if (!m_slf_out_ff)
20542138         {
20552139            /* 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);
20572141         }
20582142         else
20592143         {
20602144            /* 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);
20622146         }
20632147      }
20642148
2065      if (sn->slf_cap_voltage >= SLF_CAP_VOLTAGE_MAX)
2149      if (m_slf_cap_voltage >= SLF_CAP_VOLTAGE_MAX)
20662150      {
2067         sn->slf_out_ff = 1;
2151         m_slf_out_ff = 1;
20682152      }
2069      else if (sn->slf_cap_voltage <= SLF_CAP_VOLTAGE_MIN)
2153      else if (m_slf_cap_voltage <= SLF_CAP_VOLTAGE_MIN)
20702154      {
2071         sn->slf_out_ff = 0;
2155         m_slf_out_ff = 0;
20722156      }
20732157
20742158
20752159      /* update the VCO (voltage controlled oscillator) */
2076      if (sn->vco_mode)
2160      if (m_vco_mode)
20772161      {
20782162         /* 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;
20802164      }
20812165      else
20822166      {
20832167         /* 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;
20852169      }
20862170
2087      if (!sn->vco_cap_voltage_ext)
2171      if (!m_vco_cap_voltage_ext)
20882172      {
2089         if (!sn->vco_out_ff)
2173         if (!m_vco_out_ff)
20902174         {
20912175            /* 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);
20932177         }
20942178         else
20952179         {
20962180            /* 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);
20982182         }
20992183      }
21002184
2101      if (sn->vco_cap_voltage >= vco_cap_voltage_max)
2185      if (m_vco_cap_voltage >= vco_cap_voltage_max)
21022186      {
2103         if (!sn->vco_out_ff)
2187         if (!m_vco_out_ff)
21042188         {
21052189            /* 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;
21072191         }
21082192
2109         sn->vco_out_ff = 1;
2193         m_vco_out_ff = 1;
21102194      }
2111      else if (sn->vco_cap_voltage <= VCO_CAP_VOLTAGE_MIN)
2195      else if (m_vco_cap_voltage <= VCO_CAP_VOLTAGE_MIN)
21122196      {
2113         sn->vco_out_ff = 0;
2197         m_vco_out_ff = 0;
21142198      }
21152199
21162200
21172201      /* 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))
21192203      {
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;
21212205
2122         sn->real_noise_bit_ff = generate_next_real_noise_bit(sn);
2206         m_real_noise_bit_ff = generate_next_real_noise_bit();
21232207      }
21242208
2125      sn->noise_gen_count = sn->noise_gen_count - noise_gen_freq;
2209      m_noise_gen_count = m_noise_gen_count - noise_gen_freq;
21262210
21272211
21282212      /* update the noise filter */
2129      if (!sn->noise_filter_cap_voltage_ext)
2213      if (!m_noise_filter_cap_voltage_ext)
21302214      {
21312215         /* internal */
2132         if (sn->real_noise_bit_ff)
2216         if (m_real_noise_bit_ff)
21332217         {
21342218            /* 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);
21362220         }
21372221         else
21382222         {
21392223            /* 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);
21412225         }
21422226      }
21432227
21442228      /* 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)
21462230      {
2147         sn->filtered_noise_bit_ff = 0;
2231         m_filtered_noise_bit_ff = 0;
21482232      }
2149      else if (sn->noise_filter_cap_voltage <= NOISE_CAP_LOW_THRESHOLD)
2233      else if (m_noise_filter_cap_voltage <= NOISE_CAP_LOW_THRESHOLD)
21502234      {
2151         sn->filtered_noise_bit_ff = 1;
2235         m_filtered_noise_bit_ff = 1;
21522236      }
21532237
21542238
21552239      /* based on the envelope mode figure out the attack/decay phase we are in */
2156      switch (sn->envelope_mode)
2240      switch (m_envelope_mode)
21572241      {
21582242      case 0:     /* VCO */
2159         attack_decay_cap_charging = sn->vco_out_ff;
2243         attack_decay_cap_charging = m_vco_out_ff;
21602244         break;
21612245
21622246      case 1:     /* one-shot */
2163         attack_decay_cap_charging = sn->one_shot_running_ff;
2247         attack_decay_cap_charging = m_one_shot_running_ff;
21642248         break;
21652249
21662250      case 2:
r26337r26338
21692253         break;
21702254
21712255      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;
21732257         break;
21742258      }
21752259
21762260
21772261      /* update a/d cap voltage */
2178      if (!sn->attack_decay_cap_voltage_ext)
2262      if (!m_attack_decay_cap_voltage_ext)
21792263      {
21802264         if (attack_decay_cap_charging)
21812265         {
21822266            if (attack_decay_cap_charging_step > 0)
21832267            {
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);
21852269            }
21862270            else
21872271            {
21882272               /* 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;
21902274            }
21912275         }
21922276         else
r26337r26338
21942278            /* discharging */
21952279            if (attack_decay_cap_discharging_step > 0)
21962280            {
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);
21982282            }
21992283            else
22002284            {
22012285               /* 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;
22032287            }
22042288         }
22052289      }
22062290
22072291
22082292      /* 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))
22102294      {
22112295         UINT32 out;
22122296
22132297         /* enabled */
2214         switch (sn->mixer_mode)
2298         switch (m_mixer_mode)
22152299         {
22162300         case 0:     /* VCO */
2217            out = sn->vco_out_ff;
2301            out = m_vco_out_ff;
22182302            break;
22192303
22202304         case 1:     /* SLF */
2221            out = sn->slf_out_ff;
2305            out = m_slf_out_ff;
22222306            break;
22232307
22242308         case 2:     /* noise */
2225            out = sn->filtered_noise_bit_ff;
2309            out = m_filtered_noise_bit_ff;
22262310            break;
22272311
22282312         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;
22302314            break;
22312315
22322316         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;
22342318            break;
22352319
22362320         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;
22382322            break;
22392323
22402324         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;
22422326            break;
22432327
22442328         case 7:     /* inhibit */
r26337r26338
22502334         /* determine the OUT voltage from the attack/delay cap voltage and clip it */
22512335         if (out)
22522336         {
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)],
22542338            voltage_out = min(voltage_out, OUT_HIGH_CLIP_THRESHOLD);
22552339         }
22562340         else
22572341         {
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)],
22592343            voltage_out = max(voltage_out, OUT_LOW_CLIP_THRESHOLD);
22602344         }
22612345      }
r26337r26338
22772361       */
22782362      *buffer++ = (((voltage_out - OUT_LOW_CLIP_THRESHOLD) / (OUT_CENTER_LEVEL_VOLTAGE - OUT_LOW_CLIP_THRESHOLD)) - 1) * 32767;
22792363
2280      if (LOG_WAV && LOG_WAV_ENABLED_ONLY && !sn->enable)
2364      if (LOG_WAV && LOG_WAV_ENABLED_ONLY && !m_enable)
22812365      {
22822366         INT16 log_data_l;
22832367         INT16 log_data_r;
r26337r26338
22892373            log_data_r = LOG_WAV_GAIN_FACTOR * voltage_out;
22902374            break;
22912375         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;
22942378            break;
22952379         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;
22982382            break;
22992383         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;
23022386            break;
23032387         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;
23062390            break;
23072391         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;
23102394            break;
23112395         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;
23142398            break;
23152399         }
23162400
2317         add_wav_data(sn, log_data_l, log_data_r);
2401         add_wav_data(log_data_l, log_data_r);
23182402      }
23192403   }
23202404}
2321
2322
2323
2324/*****************************************************************************
2325 *
2326 *  State saving
2327 *
2328 *****************************************************************************/
2329
2330static 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
2394static 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
2462static DEVICE_STOP( sn76477 )
2463{
2464   sn76477_state *sn = get_safe_token(device);
2465
2466   if (LOG_WAV)
2467      close_wav_file(sn);
2468}
2469
2470const device_type SN76477 = &device_creator<sn76477_device>;
2471
2472sn76477_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
2485void sn76477_device::device_config_complete()
2486{
2487}
2488
2489//-------------------------------------------------
2490//  device_start - device-specific startup
2491//-------------------------------------------------
2492
2493void sn76477_device::device_start()
2494{
2495   DEVICE_START_NAME( sn76477 )(this);
2496}
2497
2498//-------------------------------------------------
2499//  device_stop - device-specific stop
2500//-------------------------------------------------
2501
2502void sn76477_device::device_stop()
2503{
2504   DEVICE_STOP_NAME( sn76477 )(this);
2505}
2506
2507//-------------------------------------------------
2508//  sound_stream_update - handle a stream update
2509//-------------------------------------------------
2510
2511void 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}
trunk/src/emu/sound/sn76477.h
r26337r26338
5050
5151struct sn76477_interface
5252{
53   double noise_clock_res;
54   double noise_filter_res;
55   double noise_filter_cap;
56   double decay_res;
57   double attack_decay_cap;
58   double attack_res;
59   double amplitude_res;
60   double feedback_res;
61   double vco_voltage;
62   double vco_cap;
63   double vco_res;
64   double pitch_voltage;
65   double slf_res;
66   double slf_cap;
67   double one_shot_cap;
68   double one_shot_res;
69   UINT32 vco;
70   UINT32 mixer_a;
71   UINT32 mixer_b;
72   UINT32 mixer_c;
73   UINT32 envelope_1;
74   UINT32 envelope_2;
75   UINT32 enable;
53   double m_intf_noise_clock_res;
54   double m_intf_noise_filter_res;
55   double m_intf_noise_filter_cap;
56   double m_intf_decay_res;
57   double m_intf_attack_decay_cap;
58   double m_intf_attack_res;
59   double m_intf_amplitude_res;
60   double m_intf_feedback_res;
61   double m_intf_vco_voltage;
62   double m_intf_vco_cap;
63   double m_intf_vco_res;
64   double m_intf_pitch_voltage;
65   double m_intf_slf_res;
66   double m_intf_slf_cap;
67   double m_intf_one_shot_cap;
68   double m_intf_one_shot_res;
69   UINT32 m_intf_vco;
70   UINT32 m_intf_mixer_a;
71   UINT32 m_intf_mixer_b;
72   UINT32 m_intf_mixer_c;
73   UINT32 m_intf_envelope_1;
74   UINT32 m_intf_envelope_2;
75   UINT32 m_intf_enable;
7676};
7777
78
79
80/*****************************************************************************
81 *
82 *  Functions to set a pin's value
83 *
84 *****************************************************************************/
85
86/* these functions take 0 or 1 as a logic input */
87WRITE_LINE_DEVICE_HANDLER( sn76477_enable_w );      /* active LO, 0 = enabled, 1 = disabled */
88WRITE_LINE_DEVICE_HANDLER( sn76477_mixer_a_w );
89WRITE_LINE_DEVICE_HANDLER( sn76477_mixer_b_w );
90WRITE_LINE_DEVICE_HANDLER( sn76477_mixer_c_w );
91WRITE_LINE_DEVICE_HANDLER( sn76477_envelope_1_w );
92WRITE_LINE_DEVICE_HANDLER( sn76477_envelope_2_w );
93WRITE_LINE_DEVICE_HANDLER( sn76477_vco_w );         /* 0 = external, 1 = controlled by SLF */
94WRITE_LINE_DEVICE_HANDLER( sn76477_noise_clock_w ); /* noise clock write, if noise_clock_res = 0 */
95
96/* these functions take a resistor value in Ohms */
97void sn76477_one_shot_res_w(device_t *device, double data);
98void sn76477_slf_res_w(device_t *device, double data);
99void sn76477_vco_res_w(device_t *device, double data);
100void sn76477_noise_clock_res_w(device_t *device, double data);  /* = 0 if the noise gen is clocked via noise_clock */
101void sn76477_noise_filter_res_w(device_t *device, double data);
102void sn76477_decay_res_w(device_t *device, double data);
103void sn76477_attack_res_w(device_t *device, double data);
104void sn76477_amplitude_res_w(device_t *device, double data);
105void sn76477_feedback_res_w(device_t *device, double data);
106
107/* these functions take a capacitor value in Farads or the voltage on it in Volts */
108#define SN76477_EXTERNAL_VOLTAGE_DISCONNECT   (-1.0)    /* indicates that the voltage is internally computed,
109                                                           can be used in all the functions that take a
110                                                           voltage on a capacitor */
111void sn76477_one_shot_cap_w(device_t *device, double data);
112void sn76477_one_shot_cap_voltage_w(device_t *device, double data);
113void sn76477_slf_cap_w(device_t *device, double data);
114void sn76477_slf_cap_voltage_w(device_t *device, double data);
115void sn76477_vco_cap_w(device_t *device, double data);
116void sn76477_vco_cap_voltage_w(device_t *device, double data);
117void sn76477_noise_filter_cap_w(device_t *device, double data);
118void sn76477_noise_filter_cap_voltage_w(device_t *device, double data);
119void sn76477_attack_decay_cap_w(device_t *device, double data);
120void sn76477_attack_decay_cap_voltage_w(device_t *device, double data);
121
122/* these functions take a voltage value in Volts */
123void sn76477_vco_voltage_w(device_t *device, double data);
124void sn76477_pitch_voltage_w(device_t *device, double data);
125
12678class sn76477_device : public device_t,
127                           public device_sound_interface
79                           public device_sound_interface,
80                           public sn76477_interface
12881{
12982public:
13083   sn76477_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
131   ~sn76477_device() { global_free(m_token); }
84   ~sn76477_device() {}
85   
86   /* these functions take 0 or 1 as a logic input */
87   WRITE_LINE_MEMBER( enable_w );      /* active LO, 0 = enabled, 1 = disabled */
88   WRITE_LINE_MEMBER( mixer_a_w );
89   WRITE_LINE_MEMBER( mixer_b_w );
90   WRITE_LINE_MEMBER( mixer_c_w );
91   WRITE_LINE_MEMBER( envelope_1_w );
92   WRITE_LINE_MEMBER( envelope_2_w );
93   WRITE_LINE_MEMBER( vco_w );         /* 0 = external, 1 = controlled by SLF */
94   WRITE_LINE_MEMBER( noise_clock_w ); /* noise clock write, if noise_clock_res = 0 */
13295
133   // access to legacy token
134   void *token() const { assert(m_token != NULL); return m_token; }
96   /* these functions take a resistor value in Ohms */
97   void one_shot_res_w(double data);
98   void slf_res_w(double data);
99   void vco_res_w(double data);
100   void noise_clock_res_w(double data);  /* = 0 if the noise gen is clocked via noise_clock */
101   void noise_filter_res_w(double data);
102   void decay_res_w(double data);
103   void attack_res_w(double data);
104   void amplitude_res_w(double data);
105   void feedback_res_w(double data);
106
107   /* these functions take a capacitor value in Farads or the voltage on it in Volts */
108   #define SN76477_EXTERNAL_VOLTAGE_DISCONNECT   (-1.0)    /* indicates that the voltage is internally computed,
109                                                can be used in all the functions that take a
110                                                voltage on a capacitor */
111   void one_shot_cap_w(double data);
112   void one_shot_cap_voltage_w(double data);
113   void slf_cap_w(double data);
114   void slf_cap_voltage_w(double data);
115   void vco_cap_w(double data);
116   void vco_cap_voltage_w(double data);
117   void noise_filter_cap_w(double data);
118   void noise_filter_cap_voltage_w(double data);
119   void attack_decay_cap_w(double data);
120   void attack_decay_cap_voltage_w(double data);
121
122   /* these functions take a voltage value in Volts */
123   void vco_voltage_w(double data);
124   void pitch_voltage_w(double data);
125
135126protected:
136127   // device-level overrides
137128   virtual void device_config_complete();
r26337r26338
140131
141132   // sound stream update overrides
142133   virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples);
134   
143135private:
136   /* chip's external interface */
137   UINT32 m_enable;
138   UINT32 m_envelope_mode;
139   UINT32 m_vco_mode;
140   UINT32 m_mixer_mode;
141
142   double m_one_shot_res;
143   double m_one_shot_cap;
144   UINT32 m_one_shot_cap_voltage_ext;
145
146   double m_slf_res;
147   double m_slf_cap;
148   UINT32 m_slf_cap_voltage_ext;
149
150   double m_vco_voltage;
151   double m_vco_res;
152   double m_vco_cap;
153   UINT32 m_vco_cap_voltage_ext;
154
155   double m_noise_clock_res;
156   UINT32 m_noise_clock_ext;
157   UINT32 m_noise_clock;
158   double m_noise_filter_res;
159   double m_noise_filter_cap;
160   UINT32 m_noise_filter_cap_voltage_ext;
161
162   double m_attack_res;
163   double m_decay_res;
164   double m_attack_decay_cap;
165   UINT32 m_attack_decay_cap_voltage_ext;
166
167   double m_amplitude_res;
168   double m_feedback_res;
169   double m_pitch_voltage;
170   
144171   // internal state
145   void *m_token;
172   double m_one_shot_cap_voltage;        /* voltage on the one-shot cap */
173   UINT32 m_one_shot_running_ff;         /* 1 = one-shot running, 0 = stopped */
174
175   double m_slf_cap_voltage;             /* voltage on the SLF cap */
176   UINT32 m_slf_out_ff;                  /* output of the SLF */
177
178   double m_vco_cap_voltage;             /* voltage on the VCO cap */
179   UINT32 m_vco_out_ff;                  /* output of the VCO */
180   UINT32 m_vco_alt_pos_edge_ff;         /* keeps track of the # of positive edges for VCO Alt envelope */
181
182   double m_noise_filter_cap_voltage;    /* voltage on the noise filter cap */
183   UINT32 m_real_noise_bit_ff;           /* the current noise bit before filtering */
184   UINT32 m_filtered_noise_bit_ff;       /* the noise bit after filtering */
185   UINT32 m_noise_gen_count;             /* noise freq emulation */
186
187   double m_attack_decay_cap_voltage;    /* voltage on the attack/decay cap */
188
189   UINT32 m_rng;                         /* current value of the random number generator */
190
191   /* others */
192   sound_stream *m_channel;              /* returned by stream_create() */
193   int m_our_sample_rate;                    /* from machine.sample_rate() */
194   
195   wav_file *m_file;                     /* handle of the wave file to produce */
196   
197   double compute_one_shot_cap_charging_rate();
198   double compute_one_shot_cap_discharging_rate();
199   double compute_slf_cap_charging_rate();
200   double compute_slf_cap_discharging_rate();
201   double compute_vco_cap_charging_discharging_rate();
202   double compute_vco_duty_cycle();
203   UINT32 compute_noise_gen_freq();
204   double compute_noise_filter_cap_charging_rate();
205   double compute_noise_filter_cap_discharging_rate();
206   double compute_attack_decay_cap_charging_rate();
207   double compute_attack_decay_cap_discharging_rate();
208   double compute_center_to_peak_voltage_out();
209   
210   void log_enable_line();
211   void log_mixer_mode();
212   void log_envelope_mode();
213   void log_vco_mode();
214   void log_one_shot_time();
215   void log_slf_freq();
216   void log_vco_pitch_voltage();
217   void log_vco_duty_cycle();
218   void log_vco_freq();
219   void log_vco_ext_voltage();
220   void log_noise_gen_freq();
221   void log_noise_filter_freq();
222   void log_attack_time();
223   void log_decay_time();
224   void log_voltage_out();
225   void log_complete_state();
226   
227   void open_wav_file();
228   void close_wav_file();
229   void add_wav_data(INT16 data_l, INT16 data_r);
230   
231   void intialize_noise();
232   inline UINT32 generate_next_real_noise_bit();
233   
234   void state_save_register();
235   
236   void _SN76477_enable_w(UINT32 data);
237   void _SN76477_vco_w(UINT32 data);
238   void _SN76477_mixer_a_w(UINT32 data);
239   void _SN76477_mixer_b_w(UINT32 data);
240   void _SN76477_mixer_c_w(UINT32 data);
241   void _SN76477_envelope_1_w(UINT32 data);
242   void _SN76477_envelope_2_w(UINT32 data);
243   void _SN76477_one_shot_res_w(double data);
244   void _SN76477_one_shot_cap_w(double data);
245   void _SN76477_slf_res_w(double data);
246   void _SN76477_slf_cap_w(double data);
247   void _SN76477_vco_res_w(double data);
248   void _SN76477_vco_cap_w(double data);
249   void _SN76477_vco_voltage_w(double data);
250   void _SN76477_noise_clock_res_w(double data);
251   void _SN76477_noise_filter_res_w(double data);
252   void _SN76477_noise_filter_cap_w(double data);
253   void _SN76477_decay_res_w(double data);
254   void _SN76477_attack_res_w(double data);
255   void _SN76477_attack_decay_cap_w(double data);
256   void _SN76477_amplitude_res_w(double data);
257   void _SN76477_feedback_res_w(double data);
258   void _SN76477_pitch_voltage_w(double data);
259   void SN76477_test_enable_w(UINT32 data);
146260};
147261
148262extern const device_type SN76477;
trunk/src/mess/drivers/hec2hrp.c
r26337r26338
7474#include "imagedev/cassette.h"
7575#include "formats/hect_tap.h"
7676#include "imagedev/printer.h"
77#include "sound/sn76477.h"   /* for sn sound*/
7877#include "sound/wave.h"      /* for K7 sound*/
7978#include "sound/discrete.h"  /* for 1 Bit sound*/
8079#include "machine/upd765.h" /* for floppy disc controller */
trunk/src/mess/drivers/abc80.c
r26337r26338
160160
161161WRITE_LINE_MEMBER( abc80_state::vco_voltage_w )
162162{
163   sn76477_vco_voltage_w(m_psg, state ? 2.5 : 0);
163   m_psg->vco_voltage_w(state ? 2.5 : 0);
164164}
165165
166166
r26337r26338
229229   PORT_DIPUNKNOWN_DIPLOC( 0x80, IP_ACTIVE_LOW, "SW2:8" )
230230
231231   PORT_START("SN76477")
232   PORT_BIT(0x01, IP_ACTIVE_LOW, IPT_SPECIAL) PORT_WRITE_LINE_DEVICE(SN76477_TAG, sn76477_enable_w)
232   PORT_BIT(0x01, IP_ACTIVE_LOW, IPT_SPECIAL) PORT_WRITE_LINE_DEVICE_MEMBER(SN76477_TAG, sn76477_device, enable_w)
233233   PORT_BIT(0x02, IP_ACTIVE_HIGH, IPT_SPECIAL) PORT_WRITE_LINE_DEVICE_MEMBER(DEVICE_SELF, abc80_state, vco_voltage_w)
234   PORT_BIT(0x04, IP_ACTIVE_HIGH, IPT_SPECIAL) PORT_WRITE_LINE_DEVICE(SN76477_TAG, sn76477_vco_w)
235   PORT_BIT(0x08, IP_ACTIVE_HIGH, IPT_SPECIAL) PORT_WRITE_LINE_DEVICE(SN76477_TAG, sn76477_mixer_b_w)
236   PORT_BIT(0x10, IP_ACTIVE_HIGH, IPT_SPECIAL) PORT_WRITE_LINE_DEVICE(SN76477_TAG, sn76477_mixer_a_w)
237   PORT_BIT(0x20, IP_ACTIVE_HIGH, IPT_SPECIAL) PORT_WRITE_LINE_DEVICE(SN76477_TAG, sn76477_mixer_c_w)
238   PORT_BIT(0x40, IP_ACTIVE_HIGH, IPT_SPECIAL) PORT_WRITE_LINE_DEVICE(SN76477_TAG, sn76477_envelope_2_w)
239   PORT_BIT(0x80, IP_ACTIVE_HIGH, IPT_SPECIAL) PORT_WRITE_LINE_DEVICE(SN76477_TAG, sn76477_envelope_1_w)
234   PORT_BIT(0x04, IP_ACTIVE_HIGH, IPT_SPECIAL) PORT_WRITE_LINE_DEVICE_MEMBER(SN76477_TAG, sn76477_device, vco_w)
235   PORT_BIT(0x08, IP_ACTIVE_HIGH, IPT_SPECIAL) PORT_WRITE_LINE_DEVICE_MEMBER(SN76477_TAG, sn76477_device, mixer_b_w)
236   PORT_BIT(0x10, IP_ACTIVE_HIGH, IPT_SPECIAL) PORT_WRITE_LINE_DEVICE_MEMBER(SN76477_TAG, sn76477_device, mixer_a_w)
237   PORT_BIT(0x20, IP_ACTIVE_HIGH, IPT_SPECIAL) PORT_WRITE_LINE_DEVICE_MEMBER(SN76477_TAG, sn76477_device, mixer_c_w)
238   PORT_BIT(0x40, IP_ACTIVE_HIGH, IPT_SPECIAL) PORT_WRITE_LINE_DEVICE_MEMBER(SN76477_TAG, sn76477_device, envelope_2_w)
239   PORT_BIT(0x80, IP_ACTIVE_HIGH, IPT_SPECIAL) PORT_WRITE_LINE_DEVICE_MEMBER(SN76477_TAG, sn76477_device, envelope_1_w)
240240INPUT_PORTS_END
241241
242242
trunk/src/mess/drivers/interact.c
r26337r26338
5555#include "formats/hect_tap.h"
5656#include "imagedev/printer.h"
5757#include "sound/wave.h"      /* for K7 sound*/
58#include "sound/sn76477.h"   /* for sn sound*/
5958#include "sound/discrete.h"  /* for 1 Bit sound*/
6059#include "machine/upd765.h" /* for floppy disc controller */
6160
trunk/src/mess/machine/hecdisk2.c
r26337r26338
1818
1919#include "emu.h"
2020
21#include "sound/sn76477.h"      /* for sn sound*/
2221#include "sound/wave.h"         /* for K7 sound*/
2322#include "sound/discrete.h"     /* for 1 Bit sound*/
2423#include "machine/upd765.h"     /* for floppy disc controller */
trunk/src/mess/machine/hec2hrp.c
r26337r26338
4141#include "emu.h"
4242#include "imagedev/cassette.h"
4343#include "imagedev/printer.h"
44#include "sound/sn76477.h"   /* for sn sound*/
4544#include "sound/wave.h"      /* for K7 sound*/
4645#include "sound/discrete.h"  /* for 1 Bit sound*/
4746#include "machine/upd765.h" /* for floppy disc controller */
r26337r26338
773772void hec2hrp_state::Update_Sound(address_space &space, UINT8 data)
774773{
775774   /* keep device*/
776   device_t *sn76477 = space.machine().device("sn76477");
777
778775   /* MIXER*/
779   sn76477_mixer_a_w(sn76477, ((m_ValMixer & 0x04)==4) ? 1 : 0);
780   sn76477_mixer_b_w(sn76477, ((m_ValMixer & 0x01)==1) ? 1 : 0);
781   sn76477_mixer_c_w(sn76477, ((m_ValMixer & 0x02)==2) ? 1 : 0);/* Revu selon mesure electronique sur HRX*/
776   m_sn->mixer_a_w(((m_ValMixer & 0x04)==4) ? 1 : 0);
777   m_sn->mixer_b_w(((m_ValMixer & 0x01)==1) ? 1 : 0);
778   m_sn->mixer_c_w(((m_ValMixer & 0x02)==2) ? 1 : 0);/* Revu selon mesure electronique sur HRX*/
782779
783780   /* VCO oscillateur*/
784781   if (m_AU[12]==1)
785      sn76477_vco_res_w(      sn76477, m_Pin_Value[18][m_AU[10]]/12.0); /* en non AU11*/
782      m_sn->vco_res_w(m_Pin_Value[18][m_AU[10]]/12.0); /* en non AU11*/
786783   else
787      sn76477_vco_res_w(      sn76477, m_Pin_Value[18][m_AU[10]]); /* en non AU11*/
784      m_sn->vco_res_w(m_Pin_Value[18][m_AU[10]]); /* en non AU11*/
788785
789   sn76477_vco_cap_w(      sn76477, m_Pin_Value[17][m_AU[2 ]]);
790   sn76477_pitch_voltage_w(sn76477, m_Pin_Value[19][m_AU[15]]);
791   sn76477_vco_voltage_w(  sn76477, m_Pin_Value[16][m_AU[15]]);
792   sn76477_vco_w(          sn76477, m_Pin_Value[22][m_AU[12]]); /* VCO Select Ext/SLF*/
786   m_sn->vco_cap_w(m_Pin_Value[17][m_AU[2 ]]);
787   m_sn->pitch_voltage_w(m_Pin_Value[19][m_AU[15]]);
788   m_sn->vco_voltage_w(m_Pin_Value[16][m_AU[15]]);
789   m_sn->vco_w(m_Pin_Value[22][m_AU[12]]); /* VCO Select Ext/SLF*/
793790
794791   /* SLF*/
795   sn76477_slf_res_w( sn76477, m_Pin_Value[20][m_AU[ 9]]);/*AU10*/
796   sn76477_slf_cap_w( sn76477, m_Pin_Value[21][m_AU[1 ]]);
792   m_sn->slf_res_w(m_Pin_Value[20][m_AU[ 9]]);/*AU10*/
793   m_sn->slf_cap_w(m_Pin_Value[21][m_AU[1 ]]);
797794
798795   /* One Shot*/
799   sn76477_one_shot_res_w(sn76477, m_Pin_Value[24][     0]); /* NC*/
800   sn76477_one_shot_cap_w(sn76477, m_Pin_Value[23][m_AU[13]]);
796   m_sn->one_shot_res_w(m_Pin_Value[24][     0]); /* NC*/
797   m_sn->one_shot_cap_w(m_Pin_Value[23][m_AU[13]]);
801798
802799   /* Ampli value*/
803   sn76477_amplitude_res_w(sn76477, m_Pin_Value[11][m_AU[5]]);
800   m_sn->amplitude_res_w(m_Pin_Value[11][m_AU[5]]);
804801
805802   /* Attack / Decay*/
806   sn76477_attack_res_w(sn76477, m_Pin_Value[10][m_AU[ 8]]);
807   sn76477_decay_res_w( sn76477, m_Pin_Value[7 ][m_AU[11]]);/*AU9*/
808   sn76477_attack_decay_cap_w(sn76477, m_Pin_Value[8][m_AU[0]]);
803   m_sn->attack_res_w(m_Pin_Value[10][m_AU[ 8]]);
804   m_sn->decay_res_w(m_Pin_Value[7 ][m_AU[11]]);/*AU9*/
805   m_sn->attack_decay_cap_w(m_Pin_Value[8][m_AU[0]]);
809806
810807   /* Filtre*/
811   sn76477_noise_filter_res_w(sn76477, m_Pin_Value[5][m_AU[4]]);
812   sn76477_noise_filter_cap_w(sn76477, m_Pin_Value[6][m_AU[3]]);
808   m_sn->noise_filter_res_w(m_Pin_Value[5][m_AU[4]]);
809   m_sn->noise_filter_cap_w(m_Pin_Value[6][m_AU[3]]);
813810
814811   /* Clock Extern Noise*/
815   sn76477_noise_clock_res_w(sn76477, m_Pin_Value[4][0]);   /* fix*/
816   sn76477_feedback_res_w(sn76477, m_Pin_Value[12][0]);     /*fix*/
812   m_sn->noise_clock_res_w(m_Pin_Value[4][0]);   /* fix*/
813   m_sn->feedback_res_w(m_Pin_Value[12][0]);     /*fix*/
817814
818815   /*  Envelope*/
819   sn76477_envelope_1_w(sn76477, m_Pin_Value[1 ][m_AU[6]]);
820   sn76477_envelope_2_w(sn76477, m_Pin_Value[28][m_AU[7]]);
816   m_sn->envelope_1_w(m_Pin_Value[1 ][m_AU[6]]);
817   m_sn->envelope_2_w(m_Pin_Value[28][m_AU[7]]);
821818
822819   /* En dernier on lance (ou pas !)*/
823   sn76477_enable_w(sn76477, m_Pin_Value[9][m_AU[14]]);
820   m_sn->enable_w(m_Pin_Value[9][m_AU[14]]);
824821}
825822
826823const sn76477_interface hector_sn76477_interface =
trunk/src/mess/includes/hec2hrp.h
r26337r26338
4141#include "machine/wd17xx.h"
4242#include "imagedev/flopdrv.h"
4343#include "imagedev/cassette.h"
44#include "sound/sn76477.h"   /* for sn sound*/
4445
4546/* Enum status for high memory bank (c000 - ffff)*/
4647enum
r26337r26338
7778      m_hector_videoram(*this,"hector_videoram") ,
7879      m_maincpu(*this, "maincpu"),
7980      m_disc2cpu(*this, "disc2cpu"),
80      m_cassette(*this, "cassette") { }
81      m_cassette(*this, "cassette"),
82      m_sn(*this, "sn76477") { }
8183
8284   optional_shared_ptr<UINT8> m_videoram;
8385   optional_shared_ptr<UINT8> m_hector_videoram;
r26337r26338
148150   required_device<cpu_device> m_maincpu;
149151   optional_device<cpu_device> m_disc2cpu;
150152   required_device<cassette_image_device> m_cassette;
153   required_device<sn76477_device> m_sn;
151154   int isHectorWithDisc2();
152155   int isHectorWithMiniDisc();
153156   int isHectorHR();
trunk/src/mess/video/hec2video.c
r26337r26338
3232*/
3333
3434#include "emu.h"
35#include "sound/sn76477.h"   // for sn sound
3635
3736#include "includes/hec2hrp.h"
3837
trunk/src/mame/drivers/astrof.c
r26337r26338
510510   /* the 74175 outputs all HI's if not otherwise set */
511511   tomahawk_set_video_control_2(0xff);
512512
513   m_sn = machine().device("snsnd");
514
515513   /* register for state saving */
516514   save_item(NAME(m_red_on));
517515   save_item(NAME(m_flipscreen));
trunk/src/mame/drivers/spectra.c
r26337r26338
148148   if (BIT(data, 1)) vco -= 0.625;
149149   if (BIT(data, 2)) vco -= 1.25;
150150   if (BIT(data, 3)) vco -= 2.5;
151   sn76477_vco_voltage_w(m_snsnd, 5.4 - vco);
152   sn76477_enable_w(m_snsnd, !BIT(data, 4)); // strobe: toggles enable
153   sn76477_envelope_1_w(m_snsnd, !BIT(data, 5)); //decay: toggles envelope
154   sn76477_vco_w(m_snsnd, BIT(data, 6)); // "phaser" sound: VCO toggled
155   sn76477_mixer_b_w(m_snsnd, BIT(data, 7)); // "pulse" sound: pins 25 & 27 changed
156   sn76477_mixer_c_w(m_snsnd, BIT(data, 7)); // "pulse" sound: pins 25 & 27 changed
151   m_snsnd->vco_voltage_w(5.4 - vco);
152   m_snsnd->enable_w(!BIT(data, 4)); // strobe: toggles enable
153   m_snsnd->envelope_1_w(!BIT(data, 5)); //decay: toggles envelope
154   m_snsnd->vco_w(BIT(data, 6)); // "phaser" sound: VCO toggled
155   m_snsnd->mixer_b_w(BIT(data, 7)); // "pulse" sound: pins 25 & 27 changed
156   m_snsnd->mixer_c_w(BIT(data, 7)); // "pulse" sound: pins 25 & 27 changed
157157}
158158
159159
trunk/src/mame/drivers/8080bw.c
r26337r26338
24882488{
24892489   /* do nothing for now - different interrupt system */
24902490   m_fleet_step = 3;
2491   m_sn = machine().device("snsnd");
24922491}
24932492
24942493
trunk/src/mame/drivers/crbaloon.c
r26337r26338
155155
156156WRITE8_MEMBER(crbaloon_state::port_sound_w)
157157{
158   device_t *sn = machine().device("snsnd");
159
160158   /* D0 - interrupt enable - also goes to PC3259 as /HTCTRL */
161159   m_irq_mask = data & 0x01;
162160   crbaloon_set_clear_collision_address((data & 0x01) ? TRUE : FALSE);
r26337r26338
168166   crbaloon_audio_set_music_enable(space, 0, (data & 0x04) ? TRUE : FALSE);
169167
170168   /* D3 - EXPLOSION */
171   crbaloon_audio_set_explosion_enable(sn, (data & 0x08) ? TRUE : FALSE);
169   crbaloon_audio_set_explosion_enable((data & 0x08) ? TRUE : FALSE);
172170
173171   /* D4 - BREATH */
174   crbaloon_audio_set_breath_enable(sn, (data & 0x10) ? TRUE : FALSE);
172   crbaloon_audio_set_breath_enable((data & 0x10) ? TRUE : FALSE);
175173
176174   /* D5 - APPEAR */
177   crbaloon_audio_set_appear_enable(sn, (data & 0x20) ? TRUE : FALSE);
175   crbaloon_audio_set_appear_enable((data & 0x20) ? TRUE : FALSE);
178176
179177   /* D6 - unlabeled - laugh enable */
180178   crbaloon_audio_set_laugh_enable(space, 0, (data & 0x40) ? TRUE : FALSE);
trunk/src/mame/drivers/laserbat.c
r26337r26338
2020#include "cpu/m6800/m6800.h"
2121#include "cpu/s2650/s2650.h"
2222#include "machine/6821pia.h"
23#include "sound/sn76477.h"
2423#include "sound/tms3615.h"
2524#include "includes/laserbat.h"
2625
r26337r26338
675674void laserbat_state::machine_start()
676675{
677676   m_pia = machine().device<pia6821_device>("pia");
678   m_sn = machine().device("snsnd");
679677   m_tms1 = machine().device<tms3615_device>("tms1");
680678   m_tms2 = machine().device<tms3615_device>("tms2");
681679
trunk/src/mame/drivers/dai3wksi.c
r26337r26338
5151      : driver_device(mconfig, type, tag),
5252      m_dai3wksi_videoram(*this, "videoram"),
5353      m_maincpu(*this, "maincpu"),
54      m_samples(*this, "samples") { }
54      m_samples(*this, "samples"),
55      m_ic77(*this, "ic77"),
56      m_ic78(*this, "ic78"),
57      m_ic79(*this, "ic79"),
58      m_ic80(*this, "ic80"),
59      m_ic81(*this, "ic81") { }
5560
5661   /* video */
5762   required_shared_ptr<UINT8> m_dai3wksi_videoram;
r26337r26338
7277   UINT32 screen_update_dai3wksi(screen_device &screen, bitmap_rgb32 &bitmap, const rectangle &cliprect);
7378   required_device<cpu_device> m_maincpu;
7479   required_device<samples_device> m_samples;
80   optional_device<sn76477_device> m_ic77;
81   optional_device<sn76477_device> m_ic78;
82   optional_device<sn76477_device> m_ic79;
83   optional_device<sn76477_device> m_ic80;
84   optional_device<sn76477_device> m_ic81;
7585};
7686
7787
r26337r26338
286296
287297WRITE8_MEMBER(dai3wksi_state::dai3wksi_audio_1_w)
288298{
289   device_t *ic79 = machine().device("ic79");
290
291299   machine().sound().system_enable(data & 0x80);
292300
293   sn76477_enable_w(ic79, (~data >> 5) & 0x01);        /* invader movement enable */
294   sn76477_envelope_1_w(ic79, (~data >> 2) & 0x01);    /* invader movement envelope control*/
301   m_ic79->enable_w((~data >> 5) & 0x01);        /* invader movement enable */
302   m_ic79->envelope_1_w((~data >> 2) & 0x01);    /* invader movement envelope control*/
295303}
296304
297305WRITE8_MEMBER(dai3wksi_state::dai3wksi_audio_2_w)
298306{
299   device_t *ic77 = machine().device("ic77");
300   device_t *ic78 = machine().device("ic78");
301   device_t *ic80 = machine().device("ic80");
302
303307   m_dai3wksi_flipscreen =  data & 0x10;
304308   m_dai3wksi_redscreen  = ~data & 0x20;
305309   m_dai3wksi_redterop   =  data & 0x40;
306310
307   sn76477_enable_w(ic77, (~data >> 0) & 0x01);    /* ship movement */
308   sn76477_enable_w(ic78, (~data >> 1) & 0x01);    /* danger text */
311   m_ic77->enable_w((~data >> 0) & 0x01);    /* ship movement */
312   m_ic78->enable_w((~data >> 1) & 0x01);    /* danger text */
309313   /* ic76 - invader hit  (~data >> 2) & 0x01 */
310   sn76477_enable_w(ic80, (~data >> 3) & 0x01);    /* planet explosion */
314   m_ic80->enable_w((~data >> 3) & 0x01);    /* planet explosion */
311315}
312316
313317WRITE8_MEMBER(dai3wksi_state::dai3wksi_audio_3_w)
314318{
315   device_t *ic81 = machine().device("ic81");
316
317   sn76477_enable_w(ic81, (~data >> 2) & 0x01);    /* player shoot enable */
318   sn76477_vco_w(ic81, (~data >> 3) & 0x01);       /* player shoot vco control */
319   m_ic81->enable_w((~data >> 2) & 0x01);    /* player shoot enable */
320   m_ic81->vco_w((~data >> 3) & 0x01);       /* player shoot vco control */
319321}
320322
321323
trunk/src/mame/drivers/toratora.c
r26337r26338
2929   toratora_state(const machine_config &mconfig, device_type type, const char *tag)
3030      : driver_device(mconfig, type, tag),
3131      m_videoram(*this, "videoram"),
32      m_maincpu(*this, "maincpu"){ }
32      m_maincpu(*this, "maincpu"),
33      m_sn1(*this, "sn1"),
34      m_sn2(*this, "sn2"),
35      m_pia_u1(*this, "pia_u1"),
36      m_pia_u2(*this, "pia_u2"),
37      m_pia_u3(*this, "pia_u3") { }
3338
3439   /* memory pointers */
3540   required_shared_ptr<UINT8> m_videoram;
r26337r26338
4146
4247   /* devices */
4348   required_device<cpu_device> m_maincpu;
44   pia6821_device *m_pia_u1;
45   pia6821_device *m_pia_u2;
46   pia6821_device *m_pia_u3;
49   required_device<sn76477_device> m_sn1;
50   required_device<sn76477_device> m_sn2;
51   required_device<pia6821_device> m_pia_u1;
52   required_device<pia6821_device> m_pia_u2;
53   required_device<pia6821_device> m_pia_u3;
4754   DECLARE_WRITE8_MEMBER(clear_tv_w);
4855   DECLARE_READ8_MEMBER(timer_r);
4956   DECLARE_WRITE8_MEMBER(clear_timer_w);
r26337r26338
128135
129136WRITE8_MEMBER(toratora_state::port_b_u1_w)
130137{
131   pia6821_device *pia = machine().device<pia6821_device>("pia_u1");
132   if (pia->port_b_z_mask() & 0x20)
138   if (m_pia_u1->port_b_z_mask() & 0x20)
133139      coin_counter_w(machine(), 0, 1);
134140   else
135141      coin_counter_w(machine(), 0, data & 0x20);
r26337r26338
144150
145151WRITE_LINE_MEMBER(toratora_state::main_cpu_irq)
146152{
147   pia6821_device *pia = machine().device<pia6821_device>("pia_u1");
148   int combined_state = pia->irq_a_state() | pia->irq_b_state();
153   int combined_state = m_pia_u1->irq_a_state() | m_pia_u1->irq_b_state();
149154
150155   logerror("GEN IRQ: %x\n", combined_state);
151156   m_maincpu->set_input_line(0, combined_state ? ASSERT_LINE : CLEAR_LINE);
r26337r26338
218223
219224WRITE8_MEMBER(toratora_state::sn1_port_a_u2_u3_w)
220225{
221   device_t *device = machine().device("sn1");
222   sn76477_vco_voltage_w(device, 2.35 * (data & 0x7f) / 128.0);
223   sn76477_enable_w(device, (data >> 7) & 0x01);
226   m_sn1->vco_voltage_w(2.35 * (data & 0x7f) / 128.0);
227   m_sn1->enable_w((data >> 7) & 0x01);
224228}
225229
226230
227231WRITE8_MEMBER(toratora_state::sn1_port_b_u2_u3_w)
228232{
229   device_t *device = machine().device("sn1");
230233   static const double resistances[] =
231234   {
232235      0,  /* N/C */
r26337r26338
239242      RES_K(47)
240243   };
241244
242   sn76477_mixer_a_w      (device, (data >> 0) & 0x01);
243   sn76477_mixer_b_w      (device, (data >> 1) & 0x01);
244   sn76477_mixer_c_w      (device, (data >> 2) & 0x01);
245   sn76477_envelope_1_w   (device, (data >> 3) & 0x01);
246   sn76477_envelope_2_w   (device, (data >> 4) & 0x01);
247   sn76477_amplitude_res_w(device, resistances[(data >> 5)] * 2);  /* the *2 shouldn't be neccassary, but... */
245   m_sn1->mixer_a_w      ((data >> 0) & 0x01);
246   m_sn1->mixer_b_w      ((data >> 1) & 0x01);
247   m_sn1->mixer_c_w      ((data >> 2) & 0x01);
248   m_sn1->envelope_1_w   ((data >> 3) & 0x01);
249   m_sn1->envelope_2_w   ((data >> 4) & 0x01);
250   m_sn1->amplitude_res_w(resistances[(data >> 5)] * 2);  /* the *2 shouldn't be neccassary, but... */
248251}
249252
250253
251254WRITE_LINE_MEMBER(toratora_state::sn1_ca2_u2_u3_w)
252255{
253   device_t *device = machine().device("sn1");
254   sn76477_vco_w(device, state);
256   m_sn1->vco_w(state);
255257}
256258
257259WRITE8_MEMBER(toratora_state::sn2_port_a_u2_u3_w)
258260{
259   device_t *device = machine().device("sn2");
260   sn76477_vco_voltage_w(device, 2.35 * (data & 0x7f) / 128.0);
261   sn76477_enable_w(device, (data >> 7) & 0x01);
261   m_sn2->vco_voltage_w(2.35 * (data & 0x7f) / 128.0);
262   m_sn2->enable_w((data >> 7) & 0x01);
262263}
263264
264265
265266WRITE8_MEMBER(toratora_state::sn2_port_b_u2_u3_w)
266267{
267   device_t *device = machine().device("sn2");
268268   static const double resistances[] =
269269   {
270270      0,  /* N/C */
r26337r26338
277277      RES_K(47)
278278   };
279279
280   sn76477_mixer_a_w      (device, (data >> 0) & 0x01);
281   sn76477_mixer_b_w      (device, (data >> 1) & 0x01);
282   sn76477_mixer_c_w      (device, (data >> 2) & 0x01);
283   sn76477_envelope_1_w   (device, (data >> 3) & 0x01);
284   sn76477_envelope_2_w   (device, (data >> 4) & 0x01);
285   sn76477_amplitude_res_w(device, resistances[(data >> 5)] * 2);  /* the *2 shouldn't be neccassary, but... */
280   m_sn2->mixer_a_w      ((data >> 0) & 0x01);
281   m_sn2->mixer_b_w      ((data >> 1) & 0x01);
282   m_sn2->mixer_c_w      ((data >> 2) & 0x01);
283   m_sn2->envelope_1_w   ((data >> 3) & 0x01);
284   m_sn2->envelope_2_w   ((data >> 4) & 0x01);
285   m_sn2->amplitude_res_w(resistances[(data >> 5)] * 2);  /* the *2 shouldn't be neccassary, but... */
286286}
287287
288288
289289WRITE_LINE_MEMBER(toratora_state::sn2_ca2_u2_u3_w)
290290{
291   device_t *device = machine().device("sn2");
292   sn76477_vco_w(device, state);
291   m_sn2->vco_w(state);
293292}
294293
295294/*************************************
r26337r26338
426425
427426void toratora_state::machine_start()
428427{
429   m_pia_u1 = machine().device<pia6821_device>("pia_u1");
430   m_pia_u2 = machine().device<pia6821_device>("pia_u2");
431   m_pia_u3 = machine().device<pia6821_device>("pia_u3");
432
433428   save_item(NAME(m_timer));
434429   save_item(NAME(m_last));
435430   save_item(NAME(m_clear_tv));
trunk/src/mame/drivers/rotaryf.c
r26337r26338
111111   if (BIT(rising_bits, 6)) m_samples->start (2, 2);   /* Hit */
112112   if (BIT(rising_bits, 7)) m_samples->start (0, 0);   /* Shoot */
113113
114   sn76477_enable_w(m_sn, (data & 3) ? 1 : 0);     /* Saucer Sound */
114   m_sn->enable_w((data & 3) ? 1 : 0);     /* Saucer Sound */
115115
116116   if (BIT(rising_bits, 4))
117117   {
trunk/src/mame/drivers/route16.c
r26337r26338
7070#include "emu.h"
7171#include "cpu/z80/z80.h"
7272#include "sound/dac.h"
73#include "sound/sn76477.h"
7473#include "sound/ay8910.h"
7574#include "includes/route16.h"
7675
r26337r26338
121120
122121WRITE8_MEMBER(route16_state::stratvox_sn76477_w)
123122{
124   device_t *device = machine().device("snsnd");
125123   /***************************************************************
126124    * AY8910 output bits are connected to...
127125    * 7    - direct: 5V * 30k/(100+30k) = 1.15V - via DAC??
r26337r26338
133131    * 1    - SN76477 vco
134132    * 0    - SN76477 enable
135133    ***************************************************************/
136   sn76477_enable_w(device, (data >> 0) & 1);
137   sn76477_vco_w(device, (data >> 1) & 1);
138   sn76477_envelope_1_w(device, (data >> 2) & 1);
139   sn76477_envelope_2_w(device, (data >> 3) & 1);
140   sn76477_mixer_a_w(device, (data >> 4) & 1);
141   sn76477_mixer_b_w(device, (data >> 5) & 1);
142   sn76477_mixer_c_w(device, (data >> 6) & 1);
134   m_sn->enable_w((data >> 0) & 1);
135   m_sn->vco_w((data >> 1) & 1);
136   m_sn->envelope_1_w((data >> 2) & 1);
137   m_sn->envelope_2_w((data >> 3) & 1);
138   m_sn->mixer_a_w((data >> 4) & 1);
139   m_sn->mixer_b_w((data >> 5) & 1);
140   m_sn->mixer_c_w((data >> 6) & 1);
143141}
144142
145143
trunk/src/mame/drivers/snk6502.c
r26337r26338
281281#include "emu.h"
282282#include "cpu/m6502/m6502.h"
283283#include "video/mc6845.h"
284#include "sound/sn76477.h"
285284#include "sound/samples.h"
286285#include "includes/snk6502.h"
287286
trunk/src/mame/audio/snk6502.c
r26337r26338
1111
1212
1313#include "emu.h"
14#include "sound/sn76477.h"
1514#include "sound/samples.h"
1615#include "includes/snk6502.h"
1716#include "sound/discrete.h"
r26337r26338
771770      }
772771
773772      /* SHOT B */
774      sn76477_enable_w(space.machine().device("sn76477.2"), (data & 0x40) ? 0 : 1);
773      machine().device<sn76477_device>("sn76477.2")->enable_w((data & 0x40) ? 0 : 1);
775774
776775      m_LastPort1 = data;
777776      break;
trunk/src/mame/audio/8080bw.c
r26337r26338
22
33#include "emu.h"
44#include "sound/samples.h"
5#include "sound/sn76477.h"
65#include "sound/discrete.h"
7#include "sound/speaker.h"
86#include "includes/8080bw.h"
97
108
r26337r26338
3331{
3432   UINT8 rising_bits = data & ~m_port_1_last_extra;
3533
36   sn76477_enable_w(m_sn, !(data & 0x01));         /* SAUCER SOUND */
34   m_sn->enable_w(!(data & 0x01));         /* SAUCER SOUND */
3735
3836   if (rising_bits & 0x02) m_samples->start(0, 0);     /* MISSLE SOUND */
3937   if (rising_bits & 0x04) m_samples->start(1, 1);     /* EXPLOSION */
r26337r26338
102100{
103101   UINT8 rising_bits = data & ~m_port_1_last_extra;
104102
105   sn76477_enable_w(m_sn, !(data & 0x01));         /* Saucer Sound */
103   m_sn->enable_w(!(data & 0x01));         /* Saucer Sound */
106104
107105   if (rising_bits & 0x02) m_samples->start(0, 0);     /* Shot Sound */
108106   if (rising_bits & 0x04) m_samples->start(1, 1);     /* Base Hit */
r26337r26338
931929   m_schaser_explosion = BIT(data, 5);
932930   if (m_schaser_explosion)
933931   {
934      sn76477_amplitude_res_w(m_sn, 1.0 / (1.0/RES_K(200) + 1.0/RES_K(68)));
932      m_sn->amplitude_res_w(1.0 / (1.0/RES_K(200) + 1.0/RES_K(68)));
935933   }
936934   else
937935   {
938      sn76477_amplitude_res_w(m_sn, RES_K(200));
936      m_sn->amplitude_res_w(RES_K(200));
939937   }
940   sn76477_enable_w(m_sn, !(m_schaser_effect_555_is_low || m_schaser_explosion));
941   sn76477_one_shot_cap_voltage_w(m_sn, !(m_schaser_effect_555_is_low || m_schaser_explosion) ? 0 : SN76477_EXTERNAL_VOLTAGE_DISCONNECT);
942   sn76477_mixer_b_w(m_sn, m_schaser_explosion);
938   m_sn->enable_w(!(m_schaser_effect_555_is_low || m_schaser_explosion));
939   m_sn->one_shot_cap_voltage_w(!(m_schaser_effect_555_is_low || m_schaser_explosion) ? 0 : SN76477_EXTERNAL_VOLTAGE_DISCONNECT);
940   m_sn->mixer_b_w(m_schaser_explosion);
943941}
944942
945943WRITE8_MEMBER(_8080bw_state::schaser_sh_port_2_w)
r26337r26338
987985         new_time = attotime::never;
988986   }
989987   m_schaser_effect_555_timer->adjust(new_time, effect);
990   sn76477_enable_w(m_sn, !(m_schaser_effect_555_is_low || m_schaser_explosion));
991   sn76477_one_shot_cap_voltage_w(m_sn, !(m_schaser_effect_555_is_low || m_schaser_explosion) ? 0 : SN76477_EXTERNAL_VOLTAGE_DISCONNECT);
988   m_sn->enable_w(!(m_schaser_effect_555_is_low || m_schaser_explosion));
989   m_sn->one_shot_cap_voltage_w(!(m_schaser_effect_555_is_low || m_schaser_explosion) ? 0 : SN76477_EXTERNAL_VOLTAGE_DISCONNECT);
992990}
993991
994992
r26337r26338
11391137      lupin3_step ^= 1;
11401138   }
11411139
1142   sn76477_enable_w(m_sn, data & 0x02 ? 0:1);          /* Helicopter */
1140   m_sn->enable_w(data & 0x02 ? 0:1);          /* Helicopter */
11431141
11441142   if (rising_bits & 0x04) m_samples->start(1, 4);     /* Translocate */
11451143   if (rising_bits & 0x08) m_samples->start(0, 0);     /* Jail */
r26337r26338
12281226   if (rising_bits & 0x01) m_samples->start(1, 6);         /* Ready? , Game Over */
12291227   if (rising_bits & 0x04) m_samples->start(3, 7);         /* Big bird dead */
12301228
1231   sn76477_enable_w(m_sn, data & 0x08 ? 0:1);              /* Big bird */
1229   m_sn->enable_w(data & 0x08 ? 0:1);              /* Big bird */
12321230
12331231   if (rising_bits & 0x10) m_samples->start(2, 7);         /* Game Over */
12341232
r26337r26338
12521250   if (rising_bits & 0x01) m_samples->start(4, 4);         /* Fleet move */
12531251   if (rising_bits & 0x02) m_samples->start(5, 8);         /* Extra Tank */
12541252
1255   sn76477_enable_w(m_sn, data & 0x04 ? 0:1);              /* UFO */
1253   m_sn->enable_w(data & 0x04 ? 0:1);              /* UFO */
12561254
12571255   m_port_1_last_extra = data;
12581256}
r26337r26338
13001298   if (rising_bits & 0x04) m_samples->start(3, 7);     /* Hit UFO */
13011299   if (rising_bits & 0x10) m_samples->start(5, 8);     /* Bonus */
13021300
1303   sn76477_enable_w(m_sn, data & 0x20 ? 0:1);          /* UFO */
1301   m_sn->enable_w(data & 0x20 ? 0:1);          /* UFO */
13041302
13051303   if (rising_bits & 0x40) m_samples->start(1, 1);     /* Death */
13061304   if (rising_bits & 0x80) m_samples->start(2, 2);     /* Hit */
trunk/src/mame/audio/mw8080bw.c
r26337r26338
55****************************************************************************/
66
77#include "emu.h"
8#include "sound/samples.h"
9#include "sound/sn76477.h"
10#include "sound/discrete.h"
118#include "includes/mw8080bw.h"
129
1310
r26337r26338
32833280
32843281   discrete_sound_w(m_discrete, space, SPCENCTR_BONUS_EN, (data >> 4) & 0x01);
32853282
3286   sn76477_enable_w(m_sn, (data >> 5) & 0x01); /* saucer sound */
3283   m_sn->enable_w((data >> 5) & 0x01); /* saucer sound */
32873284
32883285   /* D6 and D7 are not connected */
32893286}
r26337r26338
41744171
41754172WRITE8_MEMBER(mw8080bw_state::invaders_audio_1_w)
41764173{
4177   sn76477_enable_w(m_sn, (~data >> 0) & 0x01);    /* saucer sound */
4174   m_sn->enable_w((~data >> 0) & 0x01);    /* saucer sound */
41784175
41794176   discrete_sound_w(m_discrete, space, INVADERS_NODE(INVADERS_MISSILE_EN, 1), data & 0x02);
41804177   discrete_sound_w(m_discrete, space, INVADERS_NODE(INVADERS_EXPLOSION_EN, 1), data & 0x04);
r26337r26338
48034800
48044801WRITE8_MEMBER(mw8080bw_state::invad2ct_audio_1_w)
48054802{
4806   sn76477_enable_w(m_sn1, (~data >> 0) & 0x01);   /* saucer sound */
4803   m_sn1->enable_w((~data >> 0) & 0x01);   /* saucer sound */
48074804
48084805   discrete_sound_w(m_discrete, space, INVADERS_NODE(INVADERS_MISSILE_EN, 1), data & 0x02);
48094806   discrete_sound_w(m_discrete, space, INVADERS_NODE(INVADERS_EXPLOSION_EN, 1), data & 0x04);
r26337r26338
48274824
48284825WRITE8_MEMBER(mw8080bw_state::invad2ct_audio_3_w)
48294826{
4830   sn76477_enable_w(m_sn2, (~data >> 0) & 0x01);   /* saucer sound */
4827   m_sn2->enable_w((~data >> 0) & 0x01);   /* saucer sound */
48314828
48324829   discrete_sound_w(m_discrete, space, INVADERS_NODE(INVADERS_MISSILE_EN, 2), data & 0x02);
48334830   discrete_sound_w(m_discrete, space, INVADERS_NODE(INVADERS_EXPLOSION_EN, 2), data & 0x04);
trunk/src/mame/audio/laserbat.c
r26337r26338
11#include "emu.h"
2#include "sound/sn76477.h"
32#include "sound/tms3615.h"
43#include "includes/laserbat.h"
54
r26337r26338
5251         break;
5352      }
5453
55      sn76477_noise_filter_res_w(m_sn, noise_filter_res);
56      sn76477_vco_res_w(m_sn, vco_res);
54      m_sn->noise_filter_res_w(noise_filter_res);
55      m_sn->vco_res_w(vco_res);
5756
58      sn76477_enable_w(m_sn, (m_csound1 & 0x08) ? 1 : 0); // AB SOUND
59      sn76477_mixer_b_w(m_sn, (m_csound1 & 0x10) ? 1 : 0); // _VCO/NOISE
57      m_sn->enable_w((m_csound1 & 0x08) ? 1 : 0); // AB SOUND
58      m_sn->mixer_b_w((m_csound1 & 0x10) ? 1 : 0); // _VCO/NOISE
6059
6160      m_degr = (m_csound1 & 0x20) ? 1 : 0;
6261      m_filt = (m_csound1 & 0x40) ? 1 : 0;
r26337r26338
6463      m_us = 0; // sn76477 pin 12
6564   }
6665
67   sn76477_vco_w(m_sn, (data & 0x40) ? 0 : 1);
66   m_sn->vco_w((data & 0x40) ? 0 : 1);
6867
6968   switch((data & 0x1c) >> 2)
7069   {
7170   case 0x00:
72      sn76477_slf_res_w(m_sn, RES_K(27));
71      m_sn->slf_res_w(RES_K(27));
7372      break;
7473   case 0x01:
75      sn76477_slf_res_w(m_sn, RES_K(22));
74      m_sn->slf_res_w(RES_K(22));
7675      break;
7776   case 0x02:
78      sn76477_slf_res_w(m_sn, RES_K(22));
77      m_sn->slf_res_w(RES_K(22));
7978      break;
8079   case 0x03:
81      sn76477_slf_res_w(m_sn, RES_K(12));
80      m_sn->slf_res_w(RES_K(12));
8281      break;
8382   case 0x04: // not connected
8483      break;
trunk/src/mame/audio/astrof.c
r26337r26338
55****************************************************************************/
66
77#include "emu.h"
8#include "sound/samples.h"
9#include "sound/sn76477.h"
108#include "includes/astrof.h"
119
1210
r26337r26338
192190   /* D4 - UFO */
193191
194192   /* D5 - UFO under water */
195   sn76477_enable_w(m_sn, (~data >> 5) & 0x01);
193   m_sn->enable_w((~data >> 5) & 0x01);
196194
197195   /* D6 - explosion */
198196
trunk/src/mame/audio/crbaloon.c
r26337r26338
88
99#include "emu.h"
1010#include "includes/crbaloon.h"
11#include "sound/sn76477.h"
12#include "sound/discrete.h"
1311
1412
1513/* timing sources */
r26337r26338
4240}
4341
4442
45void crbaloon_audio_set_explosion_enable(device_t *sn, int enabled)
43void crbaloon_state::crbaloon_audio_set_explosion_enable(int enabled)
4644{
47   sn76477_enable_w(sn, enabled);
45   m_sn->enable_w(enabled);
4846}
4947
5048
51void crbaloon_audio_set_breath_enable(device_t *sn, int enabled)
49void crbaloon_state::crbaloon_audio_set_breath_enable(int enabled)
5250{
5351   /* changes slf_res to 10k (middle of two 10k resistors)
5452      it also puts a tantal capacitor against GND on the output,
5553      but this section of the schematics is not readable. */
56   sn76477_slf_res_w(sn, enabled ? RES_K(10) : RES_K(20) );
54   m_sn->slf_res_w(enabled ? RES_K(10) : RES_K(20) );
5755}
5856
5957
60void crbaloon_audio_set_appear_enable(device_t *sn, int enabled)
58void crbaloon_state::crbaloon_audio_set_appear_enable(int enabled)
6159{
6260   /* APPEAR is connected to MIXER B */
63   sn76477_mixer_b_w(sn, enabled);
61   m_sn->mixer_b_w(enabled);
6462}
6563
6664
trunk/src/mame/audio/n8080.c
r26337r26338
55***************************************************************************/
66
77#include "emu.h"
8#include "cpu/mcs48/mcs48.h"
9#include "sound/sn76477.h"
10#include "sound/dac.h"
118#include "includes/n8080.h"
129
1310static const double ATTACK_RATE = 10e-6 * 500;
r26337r26338
6966};
7067
7168
72static void spacefev_update_SN76477_status( device_t *sn )
69void n8080_state::spacefev_update_SN76477_status()
7370{
74   n8080_state *state = sn->machine().driver_data<n8080_state>();
7571   double dblR0 = RES_M(1.0);
7672   double dblR1 = RES_M(1.5);
7773
78   if (!state->m_mono_flop[0])
74   if (!m_mono_flop[0])
7975   {
8076      dblR0 = 1 / (1 / RES_K(150) + 1 / dblR0); /* ? */
8177   }
82   if (!state->m_mono_flop[1])
78   if (!m_mono_flop[1])
8379   {
8480      dblR1 = 1 / (1 / RES_K(620) + 1 / dblR1); /* ? */
8581   }
8682
87   sn76477_decay_res_w(sn, dblR0);
83   m_sn->decay_res_w(dblR0);
8884
89   sn76477_vco_res_w(sn, dblR1);
85   m_sn->vco_res_w(dblR1);
9086
91   sn76477_enable_w(sn,
92      !state->m_mono_flop[0] &&
93      !state->m_mono_flop[1] &&
94      !state->m_mono_flop[2]);
87   m_sn->enable_w(
88      !m_mono_flop[0] &&
89      !m_mono_flop[1] &&
90      !m_mono_flop[2]);
9591
96   sn76477_vco_w(sn, state->m_mono_flop[1]);
92   m_sn->vco_w(m_mono_flop[1]);
9793
98   sn76477_mixer_b_w(sn, state->m_mono_flop[0]);
94   m_sn->mixer_b_w(m_mono_flop[0]);
9995}
10096
10197
102static void sheriff_update_SN76477_status( device_t *sn )
98void n8080_state::sheriff_update_SN76477_status()
10399{
104   n8080_state *state = sn->machine().driver_data<n8080_state>();
105   if (state->m_mono_flop[1])
100   if (m_mono_flop[1])
106101   {
107      sn76477_vco_voltage_w(sn, 5);
102      m_sn->vco_voltage_w(5);
108103   }
109104   else
110105   {
111      sn76477_vco_voltage_w(sn, 0);
106      m_sn->vco_voltage_w(0);
112107   }
113108
114   sn76477_enable_w(sn,
115      !state->m_mono_flop[0] &&
116      !state->m_mono_flop[1]);
109   m_sn->enable_w(
110      !m_mono_flop[0] &&
111      !m_mono_flop[1]);
117112
118   sn76477_vco_w(sn, state->m_mono_flop[0]);
113   m_sn->vco_w(m_mono_flop[0]);
119114
120   sn76477_mixer_b_w(sn, !state->m_mono_flop[0]);
115   m_sn->mixer_b_w(!m_mono_flop[0]);
121116}
122117
123118
124static void update_SN76477_status( device_t *device )
119void n8080_state::update_SN76477_status()
125120{
126   n8080_state *state = device->machine().driver_data<n8080_state>();
127   if (state->m_n8080_hardware == 1)
121   if (m_n8080_hardware == 1)
128122   {
129      spacefev_update_SN76477_status(device);
123      spacefev_update_SN76477_status();
130124   }
131   if (state->m_n8080_hardware == 2)
125   if (m_n8080_hardware == 2)
132126   {
133      sheriff_update_SN76477_status(device);
127      sheriff_update_SN76477_status();
134128   }
135129}
136130
137131
138static void start_mono_flop( device_t *sn, int n, attotime expire )
132void n8080_state::start_mono_flop( int n, attotime expire )
139133{
140   n8080_state *state = sn->machine().driver_data<n8080_state>();
141   state->m_mono_flop[n] = 1;
134   m_mono_flop[n] = 1;
142135
143   update_SN76477_status(sn);
136   update_SN76477_status();
144137
145   state->m_sound_timer[n]->adjust(expire, n);
138   m_sound_timer[n]->adjust(expire, n);
146139}
147140
148141
149static void stop_mono_flop( device_t *sn, int n )
142void n8080_state::stop_mono_flop( int n )
150143{
151   n8080_state *state = sn->machine().driver_data<n8080_state>();
152   state->m_mono_flop[n] = 0;
144   m_mono_flop[n] = 0;
153145
154   update_SN76477_status(sn);
146   update_SN76477_status();
155147
156   state->m_sound_timer[n]->adjust(attotime::never, n);
148   m_sound_timer[n]->adjust(attotime::never, n);
157149}
158150
159151
160static TIMER_CALLBACK( stop_mono_flop_callback )
152TIMER_CALLBACK_MEMBER( n8080_state::stop_mono_flop_callback )
161153{
162   stop_mono_flop(machine.device("snsnd"), param);
154   stop_mono_flop(param);
163155}
164156
165157
166static void spacefev_sound_pins_changed( running_machine &machine )
158void n8080_state::spacefev_sound_pins_changed()
167159{
168   device_t *sn = machine.device("snsnd");
169   n8080_state *state = machine.driver_data<n8080_state>();
170   UINT16 changes = ~state->m_curr_sound_pins & state->m_prev_sound_pins;
160   UINT16 changes = ~m_curr_sound_pins & m_prev_sound_pins;
171161
172162   if (changes & (1 << 0x3))
173163   {
174      stop_mono_flop(sn, 1);
164      stop_mono_flop(1);
175165   }
176166   if (changes & ((1 << 0x3) | (1 << 0x6)))
177167   {
178      stop_mono_flop(sn, 2);
168      stop_mono_flop(2);
179169   }
180170   if (changes & (1 << 0x3))
181171   {
182      start_mono_flop(sn, 0, attotime::from_usec(550 * 36 * 100));
172      start_mono_flop(0, attotime::from_usec(550 * 36 * 100));
183173   }
184174   if (changes & (1 << 0x6))
185175   {
186      start_mono_flop(sn, 1, attotime::from_usec(550 * 22 * 33));
176      start_mono_flop(1, attotime::from_usec(550 * 22 * 33));
187177   }
188178   if (changes & (1 << 0x4))
189179   {
190      start_mono_flop(sn, 2, attotime::from_usec(550 * 22 * 33));
180      start_mono_flop(2, attotime::from_usec(550 * 22 * 33));
191181   }
192182   if (changes & ((1 << 0x2) | (1 << 0x3) | (1 << 0x5)))
193183   {
194      generic_pulse_irq_line(machine.device("audiocpu"), 0, 2);
184      generic_pulse_irq_line(m_audiocpu, 0, 2);
195185   }
196186}
197187
198188
199static void sheriff_sound_pins_changed( running_machine &machine )
189void n8080_state::sheriff_sound_pins_changed()
200190{
201   device_t *sn = machine.device("snsnd");
202   n8080_state *state = machine.driver_data<n8080_state>();
203   UINT16 changes = ~state->m_curr_sound_pins & state->m_prev_sound_pins;
191   UINT16 changes = ~m_curr_sound_pins & m_prev_sound_pins;
204192
205193   if (changes & (1 << 0x6))
206194   {
207      stop_mono_flop(sn, 1);
195      stop_mono_flop(1);
208196   }
209197   if (changes & (1 << 0x6))
210198   {
211      start_mono_flop(sn, 0, attotime::from_usec(550 * 33 * 33));
199      start_mono_flop(0, attotime::from_usec(550 * 33 * 33));
212200   }
213201   if (changes & (1 << 0x4))
214202   {
215      start_mono_flop(sn, 1, attotime::from_usec(550 * 33 * 33));
203      start_mono_flop(1, attotime::from_usec(550 * 33 * 33));
216204   }
217205   if (changes & ((1 << 0x2) | (1 << 0x3) | (1 << 0x5)))
218206   {
219      generic_pulse_irq_line(machine.device("audiocpu"), 0, 2);
207      generic_pulse_irq_line(m_audiocpu, 0, 2);
220208   }
221209}
222210
223211
224static void helifire_sound_pins_changed( running_machine &machine )
212void n8080_state::helifire_sound_pins_changed()
225213{
226   n8080_state *state = machine.driver_data<n8080_state>();
227   UINT16 changes = ~state->m_curr_sound_pins & state->m_prev_sound_pins;
214   UINT16 changes = ~m_curr_sound_pins & m_prev_sound_pins;
228215
229216   /* ((state->m_curr_sound_pins >> 0xa) & 1) not emulated */
230217   /* ((state->m_curr_sound_pins >> 0xb) & 1) not emulated */
r26337r26338
232219
233220   if (changes & (1 << 6))
234221   {
235      generic_pulse_irq_line(machine.device("audiocpu"), 0, 2);
222      generic_pulse_irq_line(m_audiocpu, 0, 2);
236223   }
237224}
238225
239226
240static void sound_pins_changed( running_machine &machine )
227void n8080_state::sound_pins_changed()
241228{
242   n8080_state *state = machine.driver_data<n8080_state>();
229   if (m_n8080_hardware == 1)
230      spacefev_sound_pins_changed();
231   if (m_n8080_hardware == 2)
232      sheriff_sound_pins_changed();
233   if (m_n8080_hardware == 3)
234      helifire_sound_pins_changed();
243235
244   if (state->m_n8080_hardware == 1)
245      spacefev_sound_pins_changed(machine);
246   if (state->m_n8080_hardware == 2)
247      sheriff_sound_pins_changed(machine);
248   if (state->m_n8080_hardware == 3)
249      helifire_sound_pins_changed(machine);
250
251   state->m_prev_sound_pins = state->m_curr_sound_pins;
236   m_prev_sound_pins = m_curr_sound_pins;
252237}
253238
254239
255static void delayed_sound_1( running_machine &machine, int data )
240void n8080_state::delayed_sound_1( int data )
256241{
257   n8080_state *state = machine.driver_data<n8080_state>();
258
259   state->m_curr_sound_pins &= ~(
242   m_curr_sound_pins &= ~(
260243      (1 << 0x7) |
261244      (1 << 0x5) |
262245      (1 << 0x6) |
r26337r26338
264247      (1 << 0x4) |
265248      (1 << 0x1));
266249
267   if (~data & 0x01) state->m_curr_sound_pins |= 1 << 0x7;
268   if (~data & 0x02) state->m_curr_sound_pins |= 1 << 0x5; /* pulse */
269   if (~data & 0x04) state->m_curr_sound_pins |= 1 << 0x6; /* pulse */
270   if (~data & 0x08) state->m_curr_sound_pins |= 1 << 0x3; /* pulse (except in Helifire) */
271   if (~data & 0x10) state->m_curr_sound_pins |= 1 << 0x4; /* pulse (except in Helifire) */
272   if (~data & 0x20) state->m_curr_sound_pins |= 1 << 0x1;
250   if (~data & 0x01) m_curr_sound_pins |= 1 << 0x7;
251   if (~data & 0x02) m_curr_sound_pins |= 1 << 0x5; /* pulse */
252   if (~data & 0x04) m_curr_sound_pins |= 1 << 0x6; /* pulse */
253   if (~data & 0x08) m_curr_sound_pins |= 1 << 0x3; /* pulse (except in Helifire) */
254   if (~data & 0x10) m_curr_sound_pins |= 1 << 0x4; /* pulse (except in Helifire) */
255   if (~data & 0x20) m_curr_sound_pins |= 1 << 0x1;
273256
274   if (state->m_n8080_hardware == 1)
257   if (m_n8080_hardware == 1)
275258   {
276      if (data & ~state->m_prev_snd_data & 0x10)
259      if (data & ~m_prev_snd_data & 0x10)
277260      {
278         state->spacefev_start_red_cannon();
261         spacefev_start_red_cannon();
279262      }
280263
281      state->m_spacefev_red_screen = data & 0x08;
264      m_spacefev_red_screen = data & 0x08;
282265   }
283266
284   sound_pins_changed(machine);
267   sound_pins_changed();
285268
286   state->m_prev_snd_data = data;
269   m_prev_snd_data = data;
287270}
288271
289272
290static TIMER_CALLBACK( delayed_sound_1_callback )
273TIMER_CALLBACK_MEMBER( n8080_state::delayed_sound_1_callback )
291274{
292   delayed_sound_1(machine, param);
275   delayed_sound_1(param);
293276}
294277
295278
296static void delayed_sound_2( running_machine &machine, int data )
279void n8080_state::delayed_sound_2( int data )
297280{
298   n8080_state *state = machine.driver_data<n8080_state>();
299
300   state->m_curr_sound_pins &= ~(
281   m_curr_sound_pins &= ~(
301282      (1 << 0x8) |
302283      (1 << 0x9) |
303284      (1 << 0xa) |
r26337r26338
305286      (1 << 0x2) |
306287      (1 << 0xc));
307288
308   if (~data & 0x01) state->m_curr_sound_pins |= 1 << 0x8;
309   if (~data & 0x02) state->m_curr_sound_pins |= 1 << 0x9;
310   if (~data & 0x04) state->m_curr_sound_pins |= 1 << 0xa;
311   if (~data & 0x08) state->m_curr_sound_pins |= 1 << 0xb;
312   if (~data & 0x10) state->m_curr_sound_pins |= 1 << 0x2; /* pulse */
313   if (~data & 0x20) state->m_curr_sound_pins |= 1 << 0xc;
289   if (~data & 0x01) m_curr_sound_pins |= 1 << 0x8;
290   if (~data & 0x02) m_curr_sound_pins |= 1 << 0x9;
291   if (~data & 0x04) m_curr_sound_pins |= 1 << 0xa;
292   if (~data & 0x08) m_curr_sound_pins |= 1 << 0xb;
293   if (~data & 0x10) m_curr_sound_pins |= 1 << 0x2; /* pulse */
294   if (~data & 0x20) m_curr_sound_pins |= 1 << 0xc;
314295
315   if (state->m_n8080_hardware == 1)
316      state->flip_screen_set_no_update(data & 0x20);
317   if (state->m_n8080_hardware == 3)
318      state->m_helifire_flash = data & 0x20;
296   if (m_n8080_hardware == 1)
297      flip_screen_set_no_update(data & 0x20);
298   if (m_n8080_hardware == 3)
299      m_helifire_flash = data & 0x20;
319300
320   sound_pins_changed(machine);
301   sound_pins_changed();
321302}
322303
323304
324static TIMER_CALLBACK( delayed_sound_2_callback )
305TIMER_CALLBACK_MEMBER( n8080_state::delayed_sound_2_callback )
325306{
326   delayed_sound_2(machine, param);
307   delayed_sound_2(param);
327308}
328309
329310
330311WRITE8_MEMBER(n8080_state::n8080_sound_1_w)
331312{
332   machine().scheduler().synchronize(FUNC(delayed_sound_1_callback), data); /* force CPUs to sync */
313   machine().scheduler().synchronize(timer_expired_delegate(FUNC(n8080_state::delayed_sound_1_callback), this), data); /* force CPUs to sync */
333314}
334315
335316WRITE8_MEMBER(n8080_state::n8080_sound_2_w)
336317{
337   machine().scheduler().synchronize(FUNC(delayed_sound_2_callback), data); /* force CPUs to sync */
318   machine().scheduler().synchronize(timer_expired_delegate(FUNC(n8080_state::delayed_sound_2_callback), this), data); /* force CPUs to sync */
338319}
339320
340321
r26337r26338
428409
429410TIMER_DEVICE_CALLBACK_MEMBER(n8080_state::spacefev_vco_voltage_timer)
430411{
431   device_t *sn = machine().device("snsnd");
432412   double voltage = 0;
433413
434414   if (m_mono_flop[2])
r26337r26338
436416      voltage = 5 * (1 - exp(- m_sound_timer[2]->elapsed().as_double() / 0.22));
437417   }
438418
439   sn76477_vco_voltage_w(sn, voltage);
419   m_sn->vco_voltage_w(voltage);
440420}
441421
442422
r26337r26338
457437
458438SOUND_START_MEMBER(n8080_state,spacefev)
459439{
460   m_sound_timer[0] = machine().scheduler().timer_alloc(FUNC(stop_mono_flop_callback));
461   m_sound_timer[1] = machine().scheduler().timer_alloc(FUNC(stop_mono_flop_callback));
462   m_sound_timer[2] = machine().scheduler().timer_alloc(FUNC(stop_mono_flop_callback));
440   m_sound_timer[0] = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(n8080_state::stop_mono_flop_callback), this));
441   m_sound_timer[1] = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(n8080_state::stop_mono_flop_callback), this));
442   m_sound_timer[2] = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(n8080_state::stop_mono_flop_callback), this));
463443
464444   save_item(NAME(m_prev_snd_data));
465445   save_item(NAME(m_prev_sound_pins));
r26337r26338
479459   m_prev_sound_pins = 0;
480460   m_curr_sound_pins = 0;
481461
482   delayed_sound_1(machine(), 0);
483   delayed_sound_2(machine(), 0);
462   delayed_sound_1(0);
463   delayed_sound_2(0);
484464}
485465
486466
487467SOUND_START_MEMBER(n8080_state,sheriff)
488468{
489   m_sound_timer[0] = machine().scheduler().timer_alloc(FUNC(stop_mono_flop_callback));
490   m_sound_timer[1] = machine().scheduler().timer_alloc(FUNC(stop_mono_flop_callback));
469   m_sound_timer[0] = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(n8080_state::stop_mono_flop_callback), this));
470   m_sound_timer[1] = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(n8080_state::stop_mono_flop_callback), this));
491471
492472   save_item(NAME(m_prev_snd_data));
493473   save_item(NAME(m_prev_sound_pins));
r26337r26338
506486   m_prev_sound_pins = 0;
507487   m_curr_sound_pins = 0;
508488
509   delayed_sound_1(machine(), 0);
510   delayed_sound_2(machine(), 0);
489   delayed_sound_1(0);
490   delayed_sound_2(0);
511491}
512492
513493
r26337r26338
533513   m_prev_sound_pins = 0;
534514   m_curr_sound_pins = 0;
535515
536   delayed_sound_1(machine(), 0);
537   delayed_sound_2(machine(), 0);
516   delayed_sound_1(0);
517   delayed_sound_2(0);
538518}
539519
540520
trunk/src/mame/machine/mw8080bw.c
r26337r26338
9494MACHINE_START_MEMBER(mw8080bw_state,mw8080bw)
9595{
9696   mw8080bw_create_interrupt_timer();
97
98   m_sn = machine().device("snsnd");
99   m_sn1 = machine().device("sn1");
100   m_sn2 = machine().device("sn2");
10197}
10298
10399
trunk/src/mame/video/route16.c
r26337r26338
77***************************************************************************/
88
99#include "emu.h"
10#include "sound/sn76477.h"
1110#include "includes/route16.h"
1211
1312
trunk/src/mame/includes/astrof.h
r26337r26338
55****************************************************************************/
66
77#include "sound/samples.h"
8#include "sound/sn76477.h"
89
910class astrof_state : public driver_device
1011{
r26337r26338
1516      m_astrof_color(*this, "astrof_color"),
1617      m_tomahawk_protection(*this, "tomahawk_prot"),
1718      m_maincpu(*this, "maincpu"),
18      m_samples(*this, "samples") { }
19      m_samples(*this, "samples"),
20      m_sn(*this, "snsnd") { }
1921
2022   /* video-related */
2123   required_shared_ptr<UINT8> m_videoram;
r26337r26338
4042   /* devices */
4143   required_device<cpu_device> m_maincpu;
4244   optional_device<samples_device> m_samples;  // astrof & abattle
43   device_t *m_sn; // tomahawk
45   optional_device<sn76477_device> m_sn; // tomahawk
4446   DECLARE_READ8_MEMBER(irq_clear_r);
4547   DECLARE_WRITE8_MEMBER(astrof_videoram_w);
4648   DECLARE_WRITE8_MEMBER(tomahawk_videoram_w);
trunk/src/mame/includes/route16.h
r26337r26338
1#include "sound/sn76477.h"
2
13class route16_state : public driver_device
24{
35public:
r26337r26338
35   route16_state(const machine_config &mconfig, device_type type, const char *tag)
46      : driver_device(mconfig, type, tag),
7      m_sn(*this, "snsnd"),
58      m_sharedram(*this, "sharedram"),
69      m_videoram1(*this, "videoram1"),
710      m_videoram2(*this, "videoram2"){ }
811
12   optional_device<sn76477_device> m_sn;
913   required_shared_ptr<UINT8> m_sharedram;
1014   UINT8 m_ttmahjng_port_select;
trunk/src/mame/includes/mw8080bw.h
r26337r26338
4545      m_discrete(*this, "discrete"),
4646      m_samples(*this, "samples"),
4747      m_samples1(*this, "samples1"),
48      m_samples2(*this, "samples2")
48      m_samples2(*this, "samples2"),
49      m_sn1(*this, "sn1"),
50      m_sn2(*this, "sn2"),
51      m_sn(*this, "snsnd")
4952   { }
5053
5154   /* device/memory pointers */
r26337r26338
8386   optional_device<samples_device> m_samples;
8487   optional_device<samples_device> m_samples1;
8588   optional_device<samples_device> m_samples2;
86   device_t *m_sn1;
87   device_t *m_sn2;
88   device_t *m_sn;
89   optional_device<sn76477_device> m_sn1;
90   optional_device<sn76477_device> m_sn2;
91   optional_device<sn76477_device> m_sn;
8992
9093   DECLARE_READ8_MEMBER(mw8080bw_shift_result_rev_r);
9194   DECLARE_READ8_MEMBER(mw8080bw_reversable_shift_result_r);
trunk/src/mame/includes/8080bw.h
r26337r26338
55****************************************************************************/
66
77#include "includes/mw8080bw.h"
8#include "sound/sn76477.h"
89#include "sound/speaker.h"
910#include "machine/eepromser.h"
1011/* for games in 8080bw.c */
r26337r26338
2021      m_claybust_gun_on(*this, "claybust_gun"),
2122      m_discrete(*this, "discrete"),
2223      m_speaker(*this, "speaker"),
23      m_eeprom(*this, "eeprom")
24      m_eeprom(*this, "eeprom"),
25      m_sn(*this, "snsnd")
2426   { }
2527
2628   /* devices/memory pointers */
r26337r26338
2931   optional_device<discrete_device> m_discrete;
3032   optional_device<speaker_sound_device> m_speaker;
3133   optional_device<eeprom_serial_93cxx_device> m_eeprom;
34   optional_device<sn76477_device> m_sn;
3235
3336
3437   /* misc game specific */
trunk/src/mame/includes/crbaloon.h
r26337r26338
55*************************************************************************/
66
77#include "sound/discrete.h"
8#include "sound/sn76477.h"
89
910#define CRBALOON_MASTER_XTAL    (XTAL_9_987MHz)
1011
r26337r26338
1819      m_colorram(*this, "colorram"),
1920      m_spriteram(*this, "spriteram"),
2021      m_pc3092_data(*this, "pc3092_data"),
21      m_discrete(*this, "discrete"),
22      m_maincpu(*this, "maincpu") { }
22      m_maincpu(*this, "maincpu"),
23      m_sn(*this, "snsnd"),
24      m_discrete(*this, "discrete") { }
2325
2426   required_shared_ptr<UINT8> m_videoram;
2527   required_shared_ptr<UINT8> m_colorram;
2628   required_shared_ptr<UINT8> m_spriteram;
2729   required_shared_ptr<UINT8> m_pc3092_data;
30   required_device<cpu_device> m_maincpu;
31   required_device<sn76477_device> m_sn;
2832   required_device<discrete_device> m_discrete;
2933   UINT16 m_collision_address;
3034   UINT8 m_collision_address_clear;
r26337r26338
5155   void pc3092_reset(void);
5256   void pc3092_update();
5357   void pc3259_update(void);
54   required_device<cpu_device> m_maincpu;
58   void crbaloon_audio_set_explosion_enable(int enabled);
59   void crbaloon_audio_set_breath_enable(int enabled);
60   void crbaloon_audio_set_appear_enable(int enabled);
5561};
5662
5763
5864/*----------- defined in audio/crbaloon.c -----------*/
5965
60void crbaloon_audio_set_explosion_enable(device_t *sn, int enabled);
61void crbaloon_audio_set_breath_enable(device_t *sn, int enabled);
62void crbaloon_audio_set_appear_enable(device_t *sn, int enabled);
6366MACHINE_CONFIG_EXTERN( crbaloon_audio );
trunk/src/mame/includes/laserbat.h
r26337r26338
77#include "machine/6821pia.h"
88#include "sound/ay8910.h"
99#include "machine/s2636.h"
10#include "sound/sn76477.h"
1011
1112class laserbat_state : public driver_device
1213{
r26337r26338
2021      m_ay2(*this, "ay2"),
2122      m_s2636_1(*this, "s2636_1"),
2223      m_s2636_2(*this, "s2636_2"),
23      m_s2636_3(*this, "s2636_3")
24      m_s2636_3(*this, "s2636_3"),
25      m_sn(*this, "snsnd")
2426   {
2527   }
2628
r26337r26338
3234   required_device<s2636_device> m_s2636_1;
3335   required_device<s2636_device> m_s2636_2;
3436   required_device<s2636_device> m_s2636_3;
37   optional_device<sn76477_device> m_sn;
3538
3639   /* video-related */
3740   tilemap_t    *m_bg_tilemap;
r26337r26338
6467
6568   /* device */
6669   pia6821_device *m_pia;
67   device_t *m_sn;
6870   tms3615_device *m_tms1;
6971   tms3615_device *m_tms2;
7072
trunk/src/mame/includes/n8080.h
r26337r26338
1#include "cpu/mcs48/mcs48.h"
12#include "sound/dac.h"
3#include "sound/sn76477.h"
24
35class n8080_state : public driver_device
46{
r26337r26338
810      m_videoram(*this, "videoram"),
911      m_colorram(*this, "colorram"),
1012      m_maincpu(*this, "maincpu"),
11      m_dac(*this, "dac") { }
13      m_audiocpu(*this, "audiocpu"),
14      m_dac(*this, "dac"),
15      m_sn(*this, "snsnd") { }
1216
1317   /* memory pointers */
1418   required_shared_ptr<UINT8> m_videoram;
r26337r26338
4347
4448   /* devices */
4549   required_device<cpu_device> m_maincpu;
50   required_device<cpu_device> m_audiocpu;
4651   required_device<dac_device> m_dac;
52   optional_device<sn76477_device> m_sn;
4753   DECLARE_WRITE8_MEMBER(n8080_shift_bits_w);
4854   DECLARE_WRITE8_MEMBER(n8080_shift_data_w);
4955   DECLARE_READ8_MEMBER(n8080_shift_r);
r26337r26338
9096   TIMER_DEVICE_CALLBACK_MEMBER(helifire_dac_volume_timer);
9197   void spacefev_start_red_cannon(  );
9298   void helifire_next_line(  );
99   void spacefev_update_SN76477_status();
100   void sheriff_update_SN76477_status();
101   void update_SN76477_status();
102   void start_mono_flop( int n, attotime expire );
103   void stop_mono_flop( int n );
104   TIMER_CALLBACK_MEMBER( stop_mono_flop_callback );
105   void spacefev_sound_pins_changed();
106   void sheriff_sound_pins_changed();
107   void helifire_sound_pins_changed();
108   void sound_pins_changed();
109   void delayed_sound_1( int data );
110   TIMER_CALLBACK_MEMBER( delayed_sound_1_callback );
111   void delayed_sound_2( int data );
112   TIMER_CALLBACK_MEMBER( delayed_sound_2_callback );
93113};
94114
95115/*----------- defined in audio/n8080.c -----------*/

Previous 199869 Revisions Next


© 1997-2024 The MAME Team