Previous 199869 Revisions Next

r31820 Thursday 28th August, 2014 at 16:09:41 UTC by Osso
cinemat.c: moved audio functions to the driver class (nw)
[src/mame/audio]cinemat.c
[src/mame/includes]cinemat.h

trunk/src/mame/audio/cinemat.c
r31819r31820
2424#include "cpu/z80/z80daisy.h"
2525#include "machine/z80ctc.h"
2626#include "includes/cinemat.h"
27#include "sound/samples.h"
2827
2928
3029/*************************************
r31819r31820
3938#define SOUNDVAL_RISING_EDGE(bit)       RISING_EDGE(bit, bits_changed, sound_val)
4039#define SOUNDVAL_FALLING_EDGE(bit)      FALLING_EDGE(bit, bits_changed, sound_val)
4140
42#define SHIFTREG_RISING_EDGE(bit)       RISING_EDGE(bit, (state->m_last_shift ^ state->m_current_shift), state->m_current_shift)
43#define SHIFTREG_FALLING_EDGE(bit)      FALLING_EDGE(bit, (state->m_last_shift ^ state->m_current_shift), state->m_current_shift)
41#define SHIFTREG_RISING_EDGE(bit)       RISING_EDGE(bit, (m_last_shift ^ m_current_shift), m_current_shift)
42#define SHIFTREG_FALLING_EDGE(bit)      FALLING_EDGE(bit, (m_last_shift ^ m_current_shift), m_current_shift)
4443
45#define SHIFTREG2_RISING_EDGE(bit)      RISING_EDGE(bit, (state->m_last_shift2 ^ state->m_current_shift), state->m_current_shift)
46#define SHIFTREG2_FALLING_EDGE(bit)     FALLING_EDGE(bit, (state->m_last_shift2 ^ state->m_current_shift), state->m_current_shift)
44#define SHIFTREG2_RISING_EDGE(bit)      RISING_EDGE(bit, (m_last_shift2 ^ m_current_shift), m_current_shift)
45#define SHIFTREG2_FALLING_EDGE(bit)     FALLING_EDGE(bit, (m_last_shift2 ^ m_current_shift), m_current_shift)
4746
4847
4948/*************************************
r31819r31820
6160
6261   /* if something changed, call the sound subroutine */
6362   if ((m_sound_control != oldval) && m_sound_handler)
64      (*m_sound_handler)(machine(), m_sound_control, m_sound_control ^ oldval);
63      (this->*m_sound_handler)(m_sound_control, m_sound_control ^ oldval);
6564}
6665
6766
r31819r31820
8887}
8988
9089
91static void generic_init(running_machine &machine, void (*callback)(running_machine &,UINT8, UINT8))
90void cinemat_state::generic_init(sound_func sound_handler)
9291{
93   cinemat_state *state = machine.driver_data<cinemat_state>();
94
9592   /* set the sound handler */
96   state->m_sound_handler = callback;
93   m_sound_handler = sound_handler;
9794
9895   /* reset sound control */
99   state->m_sound_control = 0x9f;
96   m_sound_control = 0x9f;
10097
10198   /* reset shift register values */
102   state->m_current_shift = 0xffff;
103   state->m_last_shift = 0xffff;
104   state->m_last_shift2 = 0xffff;
99   m_current_shift = 0xffff;
100   m_last_shift = 0xffff;
101   m_last_shift2 = 0xffff;
105102
106103   /* reset frame counters */
107   state->m_last_frame = 0;
104   m_last_frame = 0;
108105
109106   /* reset Star Castle pitch */
110   state->m_current_pitch = 0x10000;
107   m_current_pitch = 0x10000;
111108}
112109
113110
r31819r31820
138135   spacewar_sample_names
139136};
140137
141static void spacewar_sound_w(running_machine &machine, UINT8 sound_val, UINT8 bits_changed)
138void cinemat_state::spacewar_sound_w(UINT8 sound_val, UINT8 bits_changed)
142139{
143   samples_device *samples = machine.device<samples_device>("samples");
144
145140   /* Explosion - rising edge */
146141   if (SOUNDVAL_RISING_EDGE(0x01))
147      samples->start(0, (machine.rand() & 1) ? 0 : 6);
142      m_samples->start(0, (machine().rand() & 1) ? 0 : 6);
148143
149144   /* Fire sound - rising edge */
150145   if (SOUNDVAL_RISING_EDGE(0x02))
151      samples->start(1, (machine.rand() & 1) ? 1 : 7);
146      m_samples->start(1, (machine().rand() & 1) ? 1 : 7);
152147
153148   /* Player 1 thrust - 0=on, 1=off */
154149   if (SOUNDVAL_FALLING_EDGE(0x04))
155      samples->start(3, 3, true);
150      m_samples->start(3, 3, true);
156151   if (SOUNDVAL_RISING_EDGE(0x04))
157      samples->stop(3);
152      m_samples->stop(3);
158153
159154   /* Player 2 thrust - 0=on, 1-off */
160155   if (SOUNDVAL_FALLING_EDGE(0x08))
161      samples->start(4, 4, true);
156      m_samples->start(4, 4, true);
162157   if (SOUNDVAL_RISING_EDGE(0x08))
163      samples->stop(4);
158      m_samples->stop(4);
164159
165160   /* Mute - 0=off, 1=on */
166161   if (SOUNDVAL_FALLING_EDGE(0x10))
167      samples->start(2, 2, true); /* play idle sound */
162      m_samples->start(2, 2, true); /* play idle sound */
168163   if (SOUNDVAL_RISING_EDGE(0x10))
169164   {
170165      int i;
r31819r31820
172167      /* turn off all but the idle sound */
173168      for (i = 0; i < 5; i++)
174169         if (i != 2)
175            samples->stop(i);
170            m_samples->stop(i);
176171
177172      /* Pop when board is shut off */
178      samples->start(2, 5);
173      m_samples->start(2, 5);
179174   }
180175}
181176
182177SOUND_RESET_MEMBER( cinemat_state, spacewar )
183178{
184   generic_init(machine(), spacewar_sound_w);
179   generic_init(&cinemat_state::spacewar_sound_w);
185180}
186181
187182MACHINE_CONFIG_FRAGMENT( spacewar_sound )
r31819r31820
216211   barrier_sample_names
217212};
218213
219static void barrier_sound_w(running_machine &machine, UINT8 sound_val, UINT8 bits_changed)
214void cinemat_state::barrier_sound_w(UINT8 sound_val, UINT8 bits_changed)
220215{
221   samples_device *samples = machine.device<samples_device>("samples");
222
223216   /* Player die - rising edge */
224217   if (SOUNDVAL_RISING_EDGE(0x01))
225      samples->start(0, 0);
218      m_samples->start(0, 0);
226219
227220   /* Player move - falling edge */
228221   if (SOUNDVAL_FALLING_EDGE(0x02))
229      samples->start(1, 1);
222      m_samples->start(1, 1);
230223
231224   /* Enemy move - falling edge */
232225   if (SOUNDVAL_FALLING_EDGE(0x04))
233      samples->start(2, 2);
226      m_samples->start(2, 2);
234227}
235228
236229SOUND_RESET_MEMBER( cinemat_state, barrier )
237230{
238   generic_init(machine(), barrier_sound_w);
231   generic_init(&cinemat_state::barrier_sound_w);
239232}
240233
241234MACHINE_CONFIG_FRAGMENT( barrier_sound )
r31819r31820
268261   speedfrk_sample_names
269262};
270263
271static void speedfrk_sound_w(running_machine &machine, UINT8 sound_val, UINT8 bits_changed)
264void cinemat_state::speedfrk_sound_w(UINT8 sound_val, UINT8 bits_changed)
272265{
273   cinemat_state *state = machine.driver_data<cinemat_state>();
274   samples_device *samples = machine.device<samples_device>("samples");
275
276266   /* on the falling edge of bit 0x08, clock the inverse of bit 0x04 into the top of the shiftreg */
277267   if (SOUNDVAL_FALLING_EDGE(0x08))
278268   {
279      state->m_current_shift = ((state->m_current_shift >> 1) & 0x7fff) | ((~sound_val << 13) & 1);
269      m_current_shift = ((m_current_shift >> 1) & 0x7fff) | ((~sound_val << 13) & 1);
280270      /* high 12 bits control the frequency - counts from value to $FFF, carry triggers */
281271      /* another counter */
282272
r31819r31820
285275
286276   /* off-road - 1=on, 0=off */
287277   if (SOUNDVAL_RISING_EDGE(0x10))
288      samples->start(0, 0, true);
278      m_samples->start(0, 0, true);
289279   if (SOUNDVAL_FALLING_EDGE(0x10))
290      samples->stop(0);
280      m_samples->stop(0);
291281
292282   /* start LED is controlled by bit 0x02 */
293   set_led_status(machine, 0, ~sound_val & 0x02);
283   set_led_status(machine(), 0, ~sound_val & 0x02);
294284}
295285
296286SOUND_RESET_MEMBER( cinemat_state, speedfrk )
297287{
298   generic_init(machine(), speedfrk_sound_w);
288   generic_init(&cinemat_state::speedfrk_sound_w);
299289}
300290
301291MACHINE_CONFIG_FRAGMENT( speedfrk_sound )
r31819r31820
333323   starhawk_sample_names
334324};
335325
336static void starhawk_sound_w(running_machine &machine, UINT8 sound_val, UINT8 bits_changed)
326void cinemat_state::starhawk_sound_w(UINT8 sound_val, UINT8 bits_changed)
337327{
338   samples_device *samples = machine.device<samples_device>("samples");
339
340328   /* explosion - falling edge */
341329   if (SOUNDVAL_FALLING_EDGE(0x01))
342      samples->start(0, 0);
330      m_samples->start(0, 0);
343331
344332   /* right laser - falling edge */
345333   if (SOUNDVAL_FALLING_EDGE(0x02))
346      samples->start(1, 1);
334      m_samples->start(1, 1);
347335
348336   /* left laser - falling edge */
349337   if (SOUNDVAL_FALLING_EDGE(0x04))
350      samples->start(2, 2);
338      m_samples->start(2, 2);
351339
352340   /* K - 0=on, 1=off */
353341   if (SOUNDVAL_FALLING_EDGE(0x08))
354      samples->start(3, 3, true);
342      m_samples->start(3, 3, true);
355343   if (SOUNDVAL_RISING_EDGE(0x08))
356      samples->stop(3);
344      m_samples->stop(3);
357345
358346   /* master - 0=on, 1=off */
359347   if (SOUNDVAL_FALLING_EDGE(0x10))
360      samples->start(4, 4, true);
348      m_samples->start(4, 4, true);
361349   if (SOUNDVAL_RISING_EDGE(0x10))
362      samples->stop(4);
350      m_samples->stop(4);
363351
364352   /* K exit - 1=on, 0=off */
365353   if (SOUNDVAL_RISING_EDGE(0x80))
366      samples->start(3, 5, true);
354      m_samples->start(3, 5, true);
367355   if (SOUNDVAL_FALLING_EDGE(0x80))
368      samples->stop(3);
356      m_samples->stop(3);
369357}
370358
371359SOUND_RESET_MEMBER( cinemat_state, starhawk )
372360{
373   generic_init(machine(), starhawk_sound_w);
361   generic_init(&cinemat_state::starhawk_sound_w);
374362}
375363
376364MACHINE_CONFIG_FRAGMENT( starhawk_sound )
r31819r31820
408396   sundance_sample_names
409397};
410398
411static void sundance_sound_w(running_machine &machine, UINT8 sound_val, UINT8 bits_changed)
399void cinemat_state::sundance_sound_w(UINT8 sound_val, UINT8 bits_changed)
412400{
413   samples_device *samples = machine.device<samples_device>("samples");
414
415401   /* bong - falling edge */
416402   if (SOUNDVAL_FALLING_EDGE(0x01))
417      samples->start(0, 0);
403      m_samples->start(0, 0);
418404
419405   /* whoosh - falling edge */
420406   if (SOUNDVAL_FALLING_EDGE(0x02))
421      samples->start(1, 1);
407      m_samples->start(1, 1);
422408
423409   /* explosion - falling edge */
424410   if (SOUNDVAL_FALLING_EDGE(0x04))
425      samples->start(2, 2);
411      m_samples->start(2, 2);
426412
427413   /* ping - falling edge */
428414   if (SOUNDVAL_FALLING_EDGE(0x08))
429      samples->start(3, 3);
415      m_samples->start(3, 3);
430416
431417   /* ping - falling edge */
432418   if (SOUNDVAL_FALLING_EDGE(0x10))
433      samples->start(4, 4);
419      m_samples->start(4, 4);
434420
435421   /* hatch - falling edge */
436422   if (SOUNDVAL_FALLING_EDGE(0x80))
437      samples->start(5, 5);
423      m_samples->start(5, 5);
438424}
439425
440426SOUND_RESET_MEMBER( cinemat_state, sundance )
441427{
442   generic_init(machine(), sundance_sound_w);
428   generic_init(&cinemat_state::sundance_sound_w);
443429}
444430
445431MACHINE_CONFIG_FRAGMENT( sundance_sound )
r31819r31820
477463   tailg_sample_names
478464};
479465
480static void tailg_sound_w(running_machine &machine, UINT8 sound_val, UINT8 bits_changed)
466void cinemat_state::tailg_sound_w(UINT8 sound_val, UINT8 bits_changed)
481467{
482   cinemat_state *state = machine.driver_data<cinemat_state>();
483468   /* the falling edge of bit 0x10 clocks bit 0x08 into the mux selected by bits 0x07 */
484469   if (SOUNDVAL_FALLING_EDGE(0x10))
485470   {
486      samples_device *samples = machine.device<samples_device>("samples");
487
488471      /* update the shift register (actually just a simple mux) */
489      state->m_current_shift = (state->m_current_shift & ~(1 << (sound_val & 7))) | (((sound_val >> 3) & 1) << (sound_val & 7));
472      m_current_shift = (m_current_shift & ~(1 << (sound_val & 7))) | (((sound_val >> 3) & 1) << (sound_val & 7));
490473
491474      /* explosion - falling edge */
492475      if (SHIFTREG_FALLING_EDGE(0x01))
493         samples->start(0, 0);
476         m_samples->start(0, 0);
494477
495478      /* rumble - 0=on, 1=off */
496479      if (SHIFTREG_FALLING_EDGE(0x02))
497         samples->start(1, 1, true);
480         m_samples->start(1, 1, true);
498481      if (SHIFTREG_RISING_EDGE(0x02))
499         samples->stop(1);
482         m_samples->stop(1);
500483
501484      /* laser - 0=on, 1=off */
502485      if (SHIFTREG_FALLING_EDGE(0x04))
503         samples->start(2, 2, true);
486         m_samples->start(2, 2, true);
504487      if (SHIFTREG_RISING_EDGE(0x04))
505         samples->stop(2);
488         m_samples->stop(2);
506489
507490      /* shield - 0=on, 1=off */
508491      if (SHIFTREG_FALLING_EDGE(0x08))
509         samples->start(3, 3, true);
492         m_samples->start(3, 3, true);
510493      if (SHIFTREG_RISING_EDGE(0x08))
511         samples->stop(3);
494         m_samples->stop(3);
512495
513496      /* bounce - falling edge */
514497      if (SHIFTREG_FALLING_EDGE(0x10))
515         samples->start(4, 4);
498         m_samples->start(4, 4);
516499
517500      /* hyperspace - falling edge */
518501      if (SHIFTREG_FALLING_EDGE(0x20))
519         samples->start(5, 5);
502         m_samples->start(5, 5);
520503
521504      /* LED */
522      set_led_status(machine, 0, state->m_current_shift & 0x40);
505      set_led_status(machine(), 0, m_current_shift & 0x40);
523506
524507      /* remember the previous value */
525      state->m_last_shift = state->m_current_shift;
508      m_last_shift = m_current_shift;
526509   }
527510}
528511
529512SOUND_RESET_MEMBER( cinemat_state, tailg )
530513{
531   generic_init(machine(), tailg_sound_w);
514   generic_init(&cinemat_state::tailg_sound_w);
532515}
533516
534517MACHINE_CONFIG_FRAGMENT( tailg_sound )
r31819r31820
565548   warrior_sample_names
566549};
567550
568static void warrior_sound_w(running_machine &machine, UINT8 sound_val, UINT8 bits_changed)
551void cinemat_state::warrior_sound_w(UINT8 sound_val, UINT8 bits_changed)
569552{
570   samples_device *samples = machine.device<samples_device>("samples");
571
572553   /* normal level - 0=on, 1=off */
573554   if (SOUNDVAL_FALLING_EDGE(0x01))
574      samples->start(0, 0, true);
555      m_samples->start(0, 0, true);
575556   if (SOUNDVAL_RISING_EDGE(0x01))
576      samples->stop(0);
557      m_samples->stop(0);
577558
578559   /* hi level - 0=on, 1=off */
579560   if (SOUNDVAL_FALLING_EDGE(0x02))
580      samples->start(1, 1, true);
561      m_samples->start(1, 1, true);
581562   if (SOUNDVAL_RISING_EDGE(0x02))
582      samples->stop(1);
563      m_samples->stop(1);
583564
584565   /* explosion - falling edge */
585566   if (SOUNDVAL_FALLING_EDGE(0x04))
586      samples->start(2, 2);
567      m_samples->start(2, 2);
587568
588569   /* fall - falling edge */
589570   if (SOUNDVAL_FALLING_EDGE(0x08))
590      samples->start(3, 3);
571      m_samples->start(3, 3);
591572
592573   /* appear - falling edge */
593574   if (SOUNDVAL_FALLING_EDGE(0x10))
594      samples->start(4, 4);
575      m_samples->start(4, 4);
595576}
596577
597578SOUND_RESET_MEMBER( cinemat_state, warrior )
598579{
599   generic_init(machine(), warrior_sound_w);
580   generic_init(&cinemat_state::warrior_sound_w);
600581}
601582
602583MACHINE_CONFIG_FRAGMENT( warrior_sound )
r31819r31820
635616   armora_sample_names
636617};
637618
638static void armora_sound_w(running_machine &machine, UINT8 sound_val, UINT8 bits_changed)
619void cinemat_state::armora_sound_w(UINT8 sound_val, UINT8 bits_changed)
639620{
640   cinemat_state *state = machine.driver_data<cinemat_state>();
641   samples_device *samples = machine.device<samples_device>("samples");
642
643621   /* on the rising edge of bit 0x10, clock bit 0x80 into the shift register */
644622   if (SOUNDVAL_RISING_EDGE(0x10))
645      state->m_current_shift = ((state->m_current_shift >> 1) & 0x7f) | (sound_val & 0x80);
623      m_current_shift = ((m_current_shift >> 1) & 0x7f) | (sound_val & 0x80);
646624
647625   /* execute on the rising edge of bit 0x01 */
648626   if (SOUNDVAL_RISING_EDGE(0x01))
r31819r31820
651629
652630      /* lo explosion - falling edge */
653631      if (SHIFTREG_FALLING_EDGE(0x10))
654         samples->start(0, 0);
632         m_samples->start(0, 0);
655633
656634      /* jeep fire - falling edge */
657635      if (SHIFTREG_FALLING_EDGE(0x20))
658         samples->start(1, 1);
636         m_samples->start(1, 1);
659637
660638      /* hi explosion - falling edge */
661639      if (SHIFTREG_FALLING_EDGE(0x40))
662         samples->start(2, 2);
640         m_samples->start(2, 2);
663641
664642      /* tank fire - falling edge */
665643      if (SHIFTREG_FALLING_EDGE(0x80))
666         samples->start(3, 3);
644         m_samples->start(3, 3);
667645
668646      /* remember the previous value */
669      state->m_last_shift = state->m_current_shift;
647      m_last_shift = m_current_shift;
670648   }
671649
672650   /* tank sound - 0=on, 1=off */
673651   /* still not totally correct - should be multiple speeds based on remaining bits in shift reg */
674652   if (SOUNDVAL_FALLING_EDGE(0x02))
675      samples->start(4, 4, true);
653      m_samples->start(4, 4, true);
676654   if (SOUNDVAL_RISING_EDGE(0x02))
677      samples->stop(4);
655      m_samples->stop(4);
678656
679657   /* beep sound - 0=on, 1=off */
680658   if (SOUNDVAL_FALLING_EDGE(0x04))
681      samples->start(5, 5, true);
659      m_samples->start(5, 5, true);
682660   if (SOUNDVAL_RISING_EDGE(0x04))
683      samples->stop(5);
661      m_samples->stop(5);
684662
685663   /* chopper sound - 0=on, 1=off */
686664   if (SOUNDVAL_FALLING_EDGE(0x08))
687      samples->start(6, 6, true);
665      m_samples->start(6, 6, true);
688666   if (SOUNDVAL_RISING_EDGE(0x08))
689      samples->stop(6);
667      m_samples->stop(6);
690668}
691669
692670SOUND_RESET_MEMBER( cinemat_state, armora )
693671{
694   generic_init(machine(), armora_sound_w);
672   generic_init(&cinemat_state::armora_sound_w);
695673}
696674
697675MACHINE_CONFIG_FRAGMENT( armora_sound )
r31819r31820
736714   ripoff_sample_names
737715};
738716
739static void ripoff_sound_w(running_machine &machine, UINT8 sound_val, UINT8 bits_changed)
717void cinemat_state::ripoff_sound_w(UINT8 sound_val, UINT8 bits_changed)
740718{
741   cinemat_state *state = machine.driver_data<cinemat_state>();
742   samples_device *samples = machine.device<samples_device>("samples");
743
744719   /* on the rising edge of bit 0x02, clock bit 0x01 into the shift register */
745720   if (SOUNDVAL_RISING_EDGE(0x02))
746      state->m_current_shift = ((state->m_current_shift >> 1) & 0x7f) | ((sound_val << 7) & 0x80);
721      m_current_shift = ((m_current_shift >> 1) & 0x7f) | ((sound_val << 7) & 0x80);
747722
748723   /* execute on the rising edge of bit 0x04 */
749724   if (SOUNDVAL_RISING_EDGE(0x04))
750725   {
751726      /* background - 0=on, 1=off, selected by bits 0x38 */
752      if ((((state->m_current_shift ^ state->m_last_shift) & 0x38) && !(state->m_current_shift & 0x04)) || SHIFTREG_FALLING_EDGE(0x04))
753         samples->start(5, 5 + ((state->m_current_shift >> 5) & 7), true);
727      if ((((m_current_shift ^ m_last_shift) & 0x38) && !(m_current_shift & 0x04)) || SHIFTREG_FALLING_EDGE(0x04))
728         m_samples->start(5, 5 + ((m_current_shift >> 5) & 7), true);
754729      if (SHIFTREG_RISING_EDGE(0x04))
755         samples->stop(5);
730         m_samples->stop(5);
756731
757732      /* beep - falling edge */
758733      if (SHIFTREG_FALLING_EDGE(0x02))
759         samples->start(0, 0);
734         m_samples->start(0, 0);
760735
761736      /* motor - 0=on, 1=off */
762737      if (SHIFTREG_FALLING_EDGE(0x01))
763         samples->start(1, 1, true);
738         m_samples->start(1, 1, true);
764739      if (SHIFTREG_RISING_EDGE(0x01))
765         samples->stop(1);
740         m_samples->stop(1);
766741
767742      /* remember the previous value */
768      state->m_last_shift = state->m_current_shift;
743      m_last_shift = m_current_shift;
769744   }
770745
771746   /* torpedo - falling edge */
772747   if (SOUNDVAL_FALLING_EDGE(0x08))
773      samples->start(2, 2);
748      m_samples->start(2, 2);
774749
775750   /* laser - falling edge */
776751   if (SOUNDVAL_FALLING_EDGE(0x10))
777      samples->start(3, 3);
752      m_samples->start(3, 3);
778753
779754   /* explosion - falling edge */
780755   if (SOUNDVAL_FALLING_EDGE(0x80))
781      samples->start(4, 4);
756      m_samples->start(4, 4);
782757}
783758
784759SOUND_RESET_MEMBER( cinemat_state, ripoff )
785760{
786   generic_init(machine(), ripoff_sound_w);
761   generic_init(&cinemat_state::ripoff_sound_w);
787762}
788763
789764MACHINE_CONFIG_FRAGMENT( ripoff_sound )
r31819r31820
823798   starcas_sample_names
824799};
825800
826static void starcas_sound_w(running_machine &machine, UINT8 sound_val, UINT8 bits_changed)
801void cinemat_state::starcas_sound_w(UINT8 sound_val, UINT8 bits_changed)
827802{
828   cinemat_state *state = machine.driver_data<cinemat_state>();
829   samples_device *samples = machine.device<samples_device>("samples");
830803   UINT32 target_pitch;
831804
832805   /* on the rising edge of bit 0x10, clock bit 0x80 into the shift register */
833806   if (SOUNDVAL_RISING_EDGE(0x10))
834      state->m_current_shift = ((state->m_current_shift >> 1) & 0x7f) | (sound_val & 0x80);
807      m_current_shift = ((m_current_shift >> 1) & 0x7f) | (sound_val & 0x80);
835808
836809   /* execute on the rising edge of bit 0x01 */
837810   if (SOUNDVAL_RISING_EDGE(0x01))
838811   {
839812      /* fireball - falling edge */
840813      if (SHIFTREG_FALLING_EDGE(0x80))
841         samples->start(0, 0);
814         m_samples->start(0, 0);
842815
843816      /* shield hit - falling edge */
844817      if (SHIFTREG_FALLING_EDGE(0x40))
845         samples->start(1, 1);
818         m_samples->start(1, 1);
846819
847820      /* star sound - 0=off, 1=on */
848821      if (SHIFTREG_RISING_EDGE(0x20))
849         samples->start(2, 2, true);
822         m_samples->start(2, 2, true);
850823      if (SHIFTREG_FALLING_EDGE(0x20))
851         samples->stop(2);
824         m_samples->stop(2);
852825
853826      /* thrust sound - 1=off, 0=on*/
854827      if (SHIFTREG_FALLING_EDGE(0x10))
855         samples->start(3, 3, true);
828         m_samples->start(3, 3, true);
856829      if (SHIFTREG_RISING_EDGE(0x10))
857         samples->stop(3);
830         m_samples->stop(3);
858831
859832      /* drone - 1=off, 0=on */
860833      if (SHIFTREG_FALLING_EDGE(0x08))
861         samples->start(4, 4, true);
834         m_samples->start(4, 4, true);
862835      if (SHIFTREG_RISING_EDGE(0x08))
863         samples->stop(4);
836         m_samples->stop(4);
864837
865838      /* latch the drone pitch */
866      target_pitch = (state->m_current_shift & 7) + ((state->m_current_shift & 2) << 2);
839      target_pitch = (m_current_shift & 7) + ((m_current_shift & 2) << 2);
867840      target_pitch = 0x5800 + (target_pitch << 12);
868841
869842      /* once per frame slide the pitch toward the target */
870      if (machine.first_screen()->frame_number() > state->m_last_frame)
843      if (m_screen->frame_number() > m_last_frame)
871844      {
872         if (state->m_current_pitch > target_pitch)
873            state->m_current_pitch -= 225;
874         if (state->m_current_pitch < target_pitch)
875            state->m_current_pitch += 150;
876         samples->set_frequency(4, state->m_current_pitch);
877         state->m_last_frame = machine.first_screen()->frame_number();
845         if (m_current_pitch > target_pitch)
846            m_current_pitch -= 225;
847         if (m_current_pitch < target_pitch)
848            m_current_pitch += 150;
849         m_samples->set_frequency(4, m_current_pitch);
850         m_last_frame = m_screen->frame_number();
878851      }
879852
880853      /* remember the previous value */
881      state->m_last_shift = state->m_current_shift;
854      m_last_shift = m_current_shift;
882855   }
883856
884857   /* loud explosion - falling edge */
885858   if (SOUNDVAL_FALLING_EDGE(0x02))
886      samples->start(5, 5);
859      m_samples->start(5, 5);
887860
888861   /* soft explosion - falling edge */
889862   if (SOUNDVAL_FALLING_EDGE(0x04))
890      samples->start(6, 6);
863      m_samples->start(6, 6);
891864
892865   /* player fire - falling edge */
893866   if (SOUNDVAL_FALLING_EDGE(0x08))
894      samples->start(7, 7);
867      m_samples->start(7, 7);
895868}
896869
897870SOUND_RESET_MEMBER( cinemat_state, starcas )
898871{
899   generic_init(machine(), starcas_sound_w);
872   generic_init(&cinemat_state::starcas_sound_w);
900873}
901874
902875MACHINE_CONFIG_FRAGMENT( starcas_sound )
r31819r31820
936909   solarq_sample_names
937910};
938911
939static void solarq_sound_w(running_machine &machine, UINT8 sound_val, UINT8 bits_changed)
912void cinemat_state::solarq_sound_w(UINT8 sound_val, UINT8 bits_changed)
940913{
941   cinemat_state *state = machine.driver_data<cinemat_state>();
942   samples_device *samples = machine.device<samples_device>("samples");
943
944914   /* on the rising edge of bit 0x10, clock bit 0x80 into the shift register */
945915   if (SOUNDVAL_RISING_EDGE(0x10))
946      state->m_current_shift = ((state->m_current_shift >> 1) & 0x7fff) | ((sound_val << 8) & 0x8000);
916      m_current_shift = ((m_current_shift >> 1) & 0x7fff) | ((sound_val << 8) & 0x8000);
947917
948918   /* execute on the rising edge of bit 0x02 */
949919   if (SOUNDVAL_RISING_EDGE(0x02))
950920   {
951921      /* only the upper 8 bits matter */
952      state->m_current_shift >>= 8;
922      m_current_shift >>= 8;
953923
954924      /* loud explosion - falling edge */
955925      if (SHIFTREG_FALLING_EDGE(0x80))
956         samples->start(0, 0);
926         m_samples->start(0, 0);
957927
958928      /* soft explosion - falling edge */
959929      if (SHIFTREG_FALLING_EDGE(0x40))
960         samples->start(1, 1);
930         m_samples->start(1, 1);
961931
962932      /* thrust - 0=on, 1=off */
963933      if (SHIFTREG_FALLING_EDGE(0x20))
964934      {
965         state->m_target_volume = 1.0;
966         if (!samples->playing(2))
967            samples->start(2, 2, true);
935         m_target_volume = 1.0;
936         if (!m_samples->playing(2))
937            m_samples->start(2, 2, true);
968938      }
969939      if (SHIFTREG_RISING_EDGE(0x20))
970         state->m_target_volume = 0;
940         m_target_volume = 0;
971941
972942      /* ramp the thrust volume */
973      if (samples->playing(2) && machine.first_screen()->frame_number() > state->m_last_frame)
943      if (m_samples->playing(2) && m_screen->frame_number() > m_last_frame)
974944      {
975         if (state->m_current_volume > state->m_target_volume)
976            state->m_current_volume -= 0.078f;
977         if (state->m_current_volume < state->m_target_volume)
978            state->m_current_volume += 0.078f;
979         if (state->m_current_volume > 0)
980            samples->set_volume(2, state->m_current_volume);
945         if (m_current_volume > m_target_volume)
946            m_current_volume -= 0.078f;
947         if (m_current_volume < m_target_volume)
948            m_current_volume += 0.078f;
949         if (m_current_volume > 0)
950            m_samples->set_volume(2, m_current_volume);
981951         else
982            samples->stop(2);
983         state->m_last_frame = machine.first_screen()->frame_number();
952            m_samples->stop(2);
953         m_last_frame = m_screen->frame_number();
984954      }
985955
986956      /* fire - falling edge */
987957      if (SHIFTREG_FALLING_EDGE(0x10))
988         samples->start(3, 3);
958         m_samples->start(3, 3);
989959
990960      /* capture - falling edge */
991961      if (SHIFTREG_FALLING_EDGE(0x08))
992         samples->start(4, 4);
962         m_samples->start(4, 4);
993963
994964      /* nuke - 1=on, 0=off */
995965      if (SHIFTREG_RISING_EDGE(0x04))
996         samples->start(5, 5, true);
966         m_samples->start(5, 5, true);
997967      if (SHIFTREG_FALLING_EDGE(0x04))
998         samples->stop(5);
968         m_samples->stop(5);
999969
1000970      /* photon - falling edge */
1001971      if (SHIFTREG_FALLING_EDGE(0x02))
1002         samples->start(6, 6);
972         m_samples->start(6, 6);
1003973
1004974      /* remember the previous value */
1005      state->m_last_shift = state->m_current_shift;
975      m_last_shift = m_current_shift;
1006976   }
1007977
1008978   /* clock music data on the rising edge of bit 0x01 */
r31819r31820
1012982
1013983      /* start/stop the music sample on the high bit */
1014984      if (SHIFTREG2_RISING_EDGE(0x8000))
1015         samples->start(7, 7, true);
985         m_samples->start(7, 7, true);
1016986      if (SHIFTREG2_FALLING_EDGE(0x8000))
1017         samples->stop(7);
987         m_samples->stop(7);
1018988
1019989      /* set the frequency */
1020      freq = 56818.181818 / (4096 - (state->m_current_shift & 0xfff));
1021      samples->set_frequency(7, 44100 * freq / 1050);
990      freq = 56818.181818 / (4096 - (m_current_shift & 0xfff));
991      m_samples->set_frequency(7, 44100 * freq / 1050);
1022992
1023993      /* set the volume */
1024      vol = (~state->m_current_shift >> 12) & 7;
1025      samples->set_volume(7, vol / 7.0);
994      vol = (~m_current_shift >> 12) & 7;
995      m_samples->set_volume(7, vol / 7.0);
1026996
1027997      /* remember the previous value */
1028      state->m_last_shift2 = state->m_current_shift;
998      m_last_shift2 = m_current_shift;
1029999   }
10301000}
10311001
10321002SOUND_RESET_MEMBER( cinemat_state, solarq )
10331003{
1034   generic_init(machine(), solarq_sound_w);
1004   generic_init(&cinemat_state::solarq_sound_w);
10351005}
10361006
10371007MACHINE_CONFIG_FRAGMENT( solarq_sound )
r31819r31820
10751045   boxingb_sample_names
10761046};
10771047
1078static void boxingb_sound_w(running_machine &machine, UINT8 sound_val, UINT8 bits_changed)
1048void cinemat_state::boxingb_sound_w(UINT8 sound_val, UINT8 bits_changed)
10791049{
1080   cinemat_state *state = machine.driver_data<cinemat_state>();
1081   samples_device *samples = machine.device<samples_device>("samples");
1082
10831050   /* on the rising edge of bit 0x10, clock bit 0x80 into the shift register */
10841051   if (SOUNDVAL_RISING_EDGE(0x10))
1085      state->m_current_shift = ((state->m_current_shift >> 1) & 0x7fff) | ((sound_val << 8) & 0x8000);
1052      m_current_shift = ((m_current_shift >> 1) & 0x7fff) | ((sound_val << 8) & 0x8000);
10861053
10871054   /* execute on the rising edge of bit 0x02 */
10881055   if (SOUNDVAL_RISING_EDGE(0x02))
10891056   {
10901057      /* only the upper 8 bits matter */
1091      state->m_current_shift >>= 8;
1058      m_current_shift >>= 8;
10921059
10931060      /* soft explosion - falling edge */
10941061      if (SHIFTREG_FALLING_EDGE(0x80))
1095         samples->start(0, 0);
1062         m_samples->start(0, 0);
10961063
10971064      /* loud explosion - falling edge */
10981065      if (SHIFTREG_FALLING_EDGE(0x40))
1099         samples->start(1, 1);
1066         m_samples->start(1, 1);
11001067
11011068      /* chirping birds - 0=on, 1=off */
11021069      if (SHIFTREG_FALLING_EDGE(0x20))
1103         samples->start(2, 2);
1070         m_samples->start(2, 2);
11041071      if (SHIFTREG_RISING_EDGE(0x20))
1105         samples->stop(2);
1072         m_samples->stop(2);
11061073
11071074      /* egg cracking - falling edge */
11081075      if (SHIFTREG_FALLING_EDGE(0x10))
1109         samples->start(3, 3);
1076         m_samples->start(3, 3);
11101077
11111078      /* bug pushing A - rising edge */
11121079      if (SHIFTREG_RISING_EDGE(0x08))
1113         samples->start(4, 4);
1080         m_samples->start(4, 4);
11141081
11151082      /* bug pushing B - rising edge */
11161083      if (SHIFTREG_RISING_EDGE(0x04))
1117         samples->start(5, 5);
1084         m_samples->start(5, 5);
11181085
11191086      /* bug dying - falling edge */
11201087      if (SHIFTREG_FALLING_EDGE(0x02))
1121         samples->start(6, 6);
1088         m_samples->start(6, 6);
11221089
11231090      /* beetle on screen - falling edge */
11241091      if (SHIFTREG_FALLING_EDGE(0x01))
1125         samples->start(7, 7);
1092         m_samples->start(7, 7);
11261093
11271094      /* remember the previous value */
1128      state->m_last_shift = state->m_current_shift;
1095      m_last_shift = m_current_shift;
11291096   }
11301097
11311098   /* clock music data on the rising edge of bit 0x01 */
r31819r31820
11351102
11361103      /* start/stop the music sample on the high bit */
11371104      if (SHIFTREG2_RISING_EDGE(0x8000))
1138         samples->start(8, 8, true);
1105         m_samples->start(8, 8, true);
11391106      if (SHIFTREG2_FALLING_EDGE(0x8000))
1140         samples->stop(8);
1107         m_samples->stop(8);
11411108
11421109      /* set the frequency */
1143      freq = 56818.181818 / (4096 - (state->m_current_shift & 0xfff));
1144      samples->set_frequency(8, 44100 * freq / 1050);
1110      freq = 56818.181818 / (4096 - (m_current_shift & 0xfff));
1111      m_samples->set_frequency(8, 44100 * freq / 1050);
11451112
11461113      /* set the volume */
1147      vol = (~state->m_current_shift >> 12) & 3;
1148      samples->set_volume(8, vol / 3.0);
1114      vol = (~m_current_shift >> 12) & 3;
1115      m_samples->set_volume(8, vol / 3.0);
11491116
11501117      /* cannon - falling edge */
11511118      if (SHIFTREG2_RISING_EDGE(0x4000))
1152         samples->start(9, 9);
1119         m_samples->start(9, 9);
11531120
11541121      /* remember the previous value */
1155      state->m_last_shift2 = state->m_current_shift;
1122      m_last_shift2 = m_current_shift;
11561123   }
11571124
11581125   /* bounce - rising edge */
11591126   if (SOUNDVAL_RISING_EDGE(0x04))
1160      samples->start(10, 10);
1127      m_samples->start(10, 10);
11611128
11621129   /* bell - falling edge */
11631130   if (SOUNDVAL_RISING_EDGE(0x08))
1164      samples->start(11, 11);
1131      m_samples->start(11, 11);
11651132}
11661133
11671134SOUND_RESET_MEMBER( cinemat_state, boxingb )
11681135{
1169   generic_init(machine(), boxingb_sound_w);
1136   generic_init(&cinemat_state::boxingb_sound_w);
11701137}
11711138
11721139MACHINE_CONFIG_FRAGMENT( boxingb_sound )
r31819r31820
12061173   wotw_sample_names
12071174};
12081175
1209static void wotw_sound_w(running_machine &machine, UINT8 sound_val, UINT8 bits_changed)
1176void cinemat_state::wotw_sound_w(UINT8 sound_val, UINT8 bits_changed)
12101177{
1211   cinemat_state *state = machine.driver_data<cinemat_state>();
1212   samples_device *samples = machine.device<samples_device>("samples");
12131178   UINT32 target_pitch;
12141179
12151180   /* on the rising edge of bit 0x10, clock bit 0x80 into the shift register */
12161181   if (SOUNDVAL_RISING_EDGE(0x10))
1217      state->m_current_shift = ((state->m_current_shift >> 1) & 0x7f) | (sound_val & 0x80);
1182      m_current_shift = ((m_current_shift >> 1) & 0x7f) | (sound_val & 0x80);
12181183
12191184   /* execute on the rising edge of bit 0x01 */
12201185   if (SOUNDVAL_RISING_EDGE(0x01))
12211186   {
12221187      /* fireball - falling edge */
12231188      if (SHIFTREG_FALLING_EDGE(0x80))
1224         samples->start(0, 0);
1189         m_samples->start(0, 0);
12251190
12261191      /* shield hit - falling edge */
12271192      if (SHIFTREG_FALLING_EDGE(0x40))
1228         samples->start(1, 1);
1193         m_samples->start(1, 1);
12291194
12301195      /* star sound - 0=off, 1=on */
12311196      if (SHIFTREG_RISING_EDGE(0x20))
1232         samples->start(2, 2, true);
1197         m_samples->start(2, 2, true);
12331198      if (SHIFTREG_FALLING_EDGE(0x20))
1234         samples->stop(2);
1199         m_samples->stop(2);
12351200
12361201      /* thrust sound - 1=off, 0=on*/
12371202      if (SHIFTREG_FALLING_EDGE(0x10))
1238         samples->start(3, 3, true);
1203         m_samples->start(3, 3, true);
12391204      if (SHIFTREG_RISING_EDGE(0x10))
1240         samples->stop(3);
1205         m_samples->stop(3);
12411206
12421207      /* drone - 1=off, 0=on */
12431208      if (SHIFTREG_FALLING_EDGE(0x08))
1244         samples->start(4, 4, true);
1209         m_samples->start(4, 4, true);
12451210      if (SHIFTREG_RISING_EDGE(0x08))
1246         samples->stop(4);
1211         m_samples->stop(4);
12471212
12481213      /* latch the drone pitch */
1249      target_pitch = (state->m_current_shift & 7) + ((state->m_current_shift & 2) << 2);
1214      target_pitch = (m_current_shift & 7) + ((m_current_shift & 2) << 2);
12501215      target_pitch = 0x10000 + (target_pitch << 12);
12511216
12521217      /* once per frame slide the pitch toward the target */
1253      if (machine.first_screen()->frame_number() > state->m_last_frame)
1218      if (m_screen->frame_number() > m_last_frame)
12541219      {
1255         if (state->m_current_pitch > target_pitch)
1256            state->m_current_pitch -= 300;
1257         if (state->m_current_pitch < target_pitch)
1258            state->m_current_pitch += 200;
1259         samples->set_frequency(4, state->m_current_pitch);
1260         state->m_last_frame = machine.first_screen()->frame_number();
1220         if (m_current_pitch > target_pitch)
1221            m_current_pitch -= 300;
1222         if (m_current_pitch < target_pitch)
1223            m_current_pitch += 200;
1224         m_samples->set_frequency(4, m_current_pitch);
1225         m_last_frame = m_screen->frame_number();
12611226      }
12621227
12631228      /* remember the previous value */
1264      state->m_last_shift = state->m_current_shift;
1229      m_last_shift = m_current_shift;
12651230   }
12661231
12671232   /* loud explosion - falling edge */
12681233   if (SOUNDVAL_FALLING_EDGE(0x02))
1269      samples->start(5, 5);
1234      m_samples->start(5, 5);
12701235
12711236   /* soft explosion - falling edge */
12721237   if (SOUNDVAL_FALLING_EDGE(0x04))
1273      samples->start(6, 6);
1238      m_samples->start(6, 6);
12741239
12751240   /* player fire - falling edge */
12761241   if (SOUNDVAL_FALLING_EDGE(0x08))
1277      samples->start(7, 7);
1242      m_samples->start(7, 7);
12781243}
12791244
12801245SOUND_RESET_MEMBER( cinemat_state, wotw )
12811246{
1282   generic_init(machine(), wotw_sound_w);
1247   generic_init(&cinemat_state::wotw_sound_w);
12831248}
12841249
12851250MACHINE_CONFIG_FRAGMENT( wotw_sound )
r31819r31820
12991264 *
13001265 *************************************/
13011266
1302static TIMER_CALLBACK( synced_sound_w )
1267TIMER_CALLBACK_MEMBER( cinemat_state::synced_sound_w )
13031268{
1304   cinemat_state *state = machine.driver_data<cinemat_state>();
1305   state->m_sound_fifo[state->m_sound_fifo_in] = param;
1306   state->m_sound_fifo_in = (state->m_sound_fifo_in + 1) % 16;
1269   m_sound_fifo[m_sound_fifo_in] = param;
1270   m_sound_fifo_in = (m_sound_fifo_in + 1) % 16;
13071271}
13081272
13091273
1310static void demon_sound_w(running_machine &machine, UINT8 sound_val, UINT8 bits_changed)
1274void cinemat_state::demon_sound_w(UINT8 sound_val, UINT8 bits_changed)
13111275{
13121276   /* all inputs are inverted */
13131277   sound_val = ~sound_val;
13141278
13151279   /* watch for a 0->1 edge on bit 4 ("shift in") to clock in the new data */
13161280   if ((bits_changed & 0x10) && (sound_val & 0x10))
1317      machine.scheduler().synchronize(FUNC(synced_sound_w), sound_val & 0x0f);
1281      machine().scheduler().synchronize(timer_expired_delegate(FUNC(cinemat_state::synced_sound_w), this), sound_val & 0x0f);
13181282}
13191283
13201284
r31819r31820
13571321SOUND_RESET_MEMBER( cinemat_state, demon )
13581322{
13591323   /* generic init */
1360   generic_init(machine(), demon_sound_w);
1324   generic_init(&cinemat_state::demon_sound_w);
13611325
13621326   /* reset the FIFO */
13631327   m_sound_fifo_in = m_sound_fifo_out = 0;
r31819r31820
14381402WRITE8_MEMBER(cinemat_state::qb3_sound_w)
14391403{
14401404   UINT16 rega = m_maincpu->state_int(CCPU_A);
1441   demon_sound_w(machine(), 0x00 | (~rega & 0x0f), 0x10);
1405   demon_sound_w(0x00 | (~rega & 0x0f), 0x10);
14421406}
14431407
14441408
trunk/src/mame/includes/cinemat.h
r31819r31820
77*************************************************************************/
88
99#include "sound/ay8910.h"
10#include "sound/samples.h"
1011#include "video/vector.h"
1112
1213class cinemat_state : public driver_device
r31819r31820
1617      : driver_device(mconfig, type, tag),
1718      m_maincpu(*this, "maincpu"),
1819      m_ay1(*this, "ay1"),
20      m_samples(*this, "samples"),
1921      m_vector(*this, "vector"),
20      m_rambase(*this, "rambase"),
21      m_screen(*this, "screen") { }
22      m_screen(*this, "screen"),
23      m_rambase(*this, "rambase") { }
2224
2325   required_device<ccpu_cpu_device> m_maincpu;
2426   optional_device<ay8910_device> m_ay1;
27   optional_device<samples_device> m_samples;
2528   required_device<vector_device> m_vector;
29   required_device<screen_device> m_screen;
2630   optional_shared_ptr<UINT16> m_rambase;
27   required_device<screen_device> m_screen;
2831
29   UINT8 m_sound_control;
30   void (*m_sound_handler)(running_machine &,UINT8 sound_val, UINT8 bits_changed);
32   typedef void (cinemat_state::*sound_func)(UINT8 sound_val, UINT8 bits_changed);
33   
34   sound_func m_sound_handler;
35   UINT8 m_sound_control;   
3136   UINT32 m_current_shift;
3237   UINT32 m_last_shift;
3338   UINT32 m_last_shift2;
r31819r31820
100105   DECLARE_READ8_MEMBER(sound_portb_r);
101106   DECLARE_WRITE8_MEMBER(sound_portb_w);
102107   DECLARE_WRITE8_MEMBER(sound_output_w);
108   TIMER_CALLBACK_MEMBER(synced_sound_w);
109   void generic_init(sound_func sound_handler);
103110   void cinemat_vector_callback(INT16 sx, INT16 sy, INT16 ex, INT16 ey, UINT8 shift);
111   void spacewar_sound_w(UINT8 sound_val, UINT8 bits_changed);
112   void barrier_sound_w(UINT8 sound_val, UINT8 bits_changed);
113   void speedfrk_sound_w(UINT8 sound_val, UINT8 bits_changed);
114   void starhawk_sound_w(UINT8 sound_val, UINT8 bits_changed);
115   void sundance_sound_w(UINT8 sound_val, UINT8 bits_changed);
116   void tailg_sound_w(UINT8 sound_val, UINT8 bits_changed);
117   void warrior_sound_w(UINT8 sound_val, UINT8 bits_changed);
118   void armora_sound_w(UINT8 sound_val, UINT8 bits_changed);
119   void ripoff_sound_w(UINT8 sound_val, UINT8 bits_changed);
120   void starcas_sound_w(UINT8 sound_val, UINT8 bits_changed);
121   void solarq_sound_w(UINT8 sound_val, UINT8 bits_changed);
122   void boxingb_sound_w(UINT8 sound_val, UINT8 bits_changed);
123   void wotw_sound_w(UINT8 sound_val, UINT8 bits_changed);
124   void demon_sound_w(UINT8 sound_val, UINT8 bits_changed);
104125};
105126
106127/*----------- defined in audio/cinemat.c -----------*/

Previous 199869 Revisions Next


© 1997-2024 The MAME Team