~ubuntu-branches/debian/wheezy/mame/wheezy

« back to all changes in this revision

Viewing changes to src/mame/audio/segag80r.c

  • Committer: Bazaar Package Importer
  • Author(s): Jordi Mallach, Emmanuel Kasper, Félix Arreola Rodríguez, Jordi Mallach
  • Date: 2011-05-11 21:06:50 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20110511210650-jizvh8a6x117y9hr
Tags: 0.142-1
[ Emmanuel Kasper ]
* New upstream release
* Set NOWERROR=1 to allow compiling with gcc-4.6
* Remove fix_powerpc_build.patch, as upstream has taken it in this release
* Add gnome-video-arcade front end as a suggested package

[ Félix Arreola Rodríguez ]
* Add kfreebsd-build.patch to quilt series, to fix build on kfreebsd

[ Jordi Mallach ]
* Remove unneeded and bogus addition of --with-quilt to the dh invocation.
* Add Cesare Falco (long time Ubuntu maintainer) to Uploaders, and wrap
  them into multiple lines.

Show diffs side-by-side

added added

removed removed

Lines of Context:
8
8
***************************************************************************/
9
9
 
10
10
#include "emu.h"
11
 
#include "streams.h"
12
11
#include "cpu/mcs48/mcs48.h"
13
12
#include "includes/segag80r.h"
14
13
#include "machine/8255ppi.h"
37
36
 
38
37
/*************************************
39
38
 *
40
 
 *  Local sound states
41
 
 *
42
 
 *************************************/
43
 
 
44
 
static UINT8 sound_state[2];
45
 
static UINT8 sound_rate;
46
 
static UINT16 sound_addr;
47
 
static UINT8 sound_data;
48
 
 
49
 
static UINT8 square_state;
50
 
static UINT8 square_count;
51
 
 
52
 
static emu_timer *sega005_sound_timer;
53
 
static sound_stream *sega005_stream;
54
 
 
55
 
static UINT8 n7751_command;
56
 
static UINT8 n7751_busy;
57
 
 
58
 
 
59
 
 
60
 
/*************************************
61
 
 *
62
39
 *  Astro Blaster sound hardware
63
40
 *
64
41
 *************************************/
228
205
 
229
206
static SOUND_START( astrob )
230
207
{
231
 
        state_save_register_global_array(machine, sound_state);
232
 
        state_save_register_global(machine, sound_rate);
 
208
        segag80r_state *state = machine.driver_data<segag80r_state>();
 
209
        state_save_register_global_array(machine, state->m_sound_state);
 
210
        state_save_register_global(machine, state->m_sound_rate);
233
211
}
234
212
 
235
213
 
242
220
 
243
221
WRITE8_HANDLER( astrob_sound_w )
244
222
{
 
223
        segag80r_state *state = space->machine().driver_data<segag80r_state>();
245
224
        static const float attack_resistor[10] =
246
225
        {
247
226
                120.0f, 82.0f, 62.0f, 56.0f, 47.0f, 39.0f, 33.0f, 27.0f, 24.0f, 22.0f
248
227
        };
249
 
        device_t *samples = space->machine->device("samples");
 
228
        device_t *samples = space->machine().device("samples");
250
229
        float freq_factor;
251
230
 
252
 
        UINT8 diff = data ^ sound_state[offset];
253
 
        sound_state[offset] = data;
 
231
        UINT8 diff = data ^ state->m_sound_state[offset];
 
232
        state->m_sound_state[offset] = data;
254
233
 
255
234
        switch (offset)
256
235
        {
276
255
                        if ((data & 0x10) && sample_playing(samples, 4)) sample_stop(samples, 4);
277
256
 
278
257
                        /* MUTE */
279
 
                        sound_global_enable(space->machine, !(data & 0x20));
 
258
                        space->machine().sound().system_mute(data & 0x20);
280
259
 
281
260
                        /* REFILL: channel 5 */
282
261
                        if (!(data & 0x40) && !sample_playing(samples, 5)) sample_start(samples, 5, 9, FALSE);
306
285
                        if ((diff & 0x08) && !(data & 0x08)) sample_start(samples, 8, 13, FALSE);
307
286
 
308
287
                        /* ATTACK RATE */
309
 
                        if ((diff & 0x10) && !(data & 0x10)) sound_rate = (sound_rate + 1) % 10;
 
288
                        if ((diff & 0x10) && !(data & 0x10)) state->m_sound_rate = (state->m_sound_rate + 1) % 10;
310
289
 
311
290
                        /* RATE RESET */
312
 
                        if (!(data & 0x20)) sound_rate = 0;
 
291
                        if (!(data & 0x20)) state->m_sound_rate = 0;
313
292
 
314
293
                        /* BONUS: channel 9 */
315
294
                        if ((diff & 0x40) && !(data & 0x40)) sample_start(samples, 9, 14, FALSE);
325
304
        /* account for the fact that frequency goes up as CV goes down */
326
305
        /* WARP is already taken into account by the differing samples above */
327
306
        freq_factor  = (11.5f - 8.163f) * (-22.0f / attack_resistor[0]) + 8.163f;
328
 
        freq_factor /= (11.5f - 8.163f) * (-22.0f / attack_resistor[sound_rate]) + 8.163f;
 
307
        freq_factor /= (11.5f - 8.163f) * (-22.0f / attack_resistor[state->m_sound_rate]) + 8.163f;
329
308
 
330
309
        /* adjust the sample rate of invader sounds based the sound_rate */
331
310
        /* this is an approximation */
461
440
 
462
441
static SOUND_START( sega005 )
463
442
{
464
 
        state_save_register_global_array(machine, sound_state);
465
 
        state_save_register_global(machine, sound_addr);
466
 
        state_save_register_global(machine, sound_data);
467
 
        state_save_register_global(machine, square_state);
468
 
        state_save_register_global(machine, square_count);
 
443
        segag80r_state *state = machine.driver_data<segag80r_state>();
 
444
        state_save_register_global_array(machine, state->m_sound_state);
 
445
        state_save_register_global(machine, state->m_sound_addr);
 
446
        state_save_register_global(machine, state->m_sound_data);
 
447
        state_save_register_global(machine, state->m_square_state);
 
448
        state_save_register_global(machine, state->m_square_count);
469
449
}
470
450
 
471
451
 
478
458
 
479
459
static WRITE8_DEVICE_HANDLER( sega005_sound_a_w )
480
460
{
481
 
        device_t *samples = device->machine->device("samples");
482
 
        UINT8 diff = data ^ sound_state[0];
483
 
        sound_state[0] = data;
 
461
        segag80r_state *state = device->machine().driver_data<segag80r_state>();
 
462
        device_t *samples = device->machine().device("samples");
 
463
        UINT8 diff = data ^ state->m_sound_state[0];
 
464
        state->m_sound_state[0] = data;
484
465
 
485
466
        /* LARGE EXPL: channel 0 */
486
467
        if ((diff & 0x01) && !(data & 0x01)) sample_start(samples, 0, 0, FALSE);
507
488
}
508
489
 
509
490
 
510
 
INLINE void sega005_update_sound_data(running_machine *machine)
 
491
INLINE void sega005_update_sound_data(running_machine &machine)
511
492
{
512
 
        UINT8 newval = machine->region("005")->base()[sound_addr];
513
 
        UINT8 diff = newval ^ sound_data;
 
493
        segag80r_state *state = machine.driver_data<segag80r_state>();
 
494
        UINT8 newval = machine.region("005")->base()[state->m_sound_addr];
 
495
        UINT8 diff = newval ^ state->m_sound_data;
514
496
 
515
 
        //mame_printf_debug("  [%03X] = %02X\n", sound_addr, newval);
 
497
        //mame_printf_debug("  [%03X] = %02X\n", state->m_sound_addr, newval);
516
498
 
517
499
        /* latch the new value */
518
 
        sound_data = newval;
 
500
        state->m_sound_data = newval;
519
501
 
520
502
        /* if bit 5 goes high, we reset the timer */
521
503
        if ((diff & 0x20) && !(newval & 0x20))
522
504
        {
523
505
                //mame_printf_debug("Stopping timer\n");
524
 
                timer_adjust_oneshot(sega005_sound_timer, attotime_never, 0);
 
506
                state->m_sega005_sound_timer->adjust(attotime::never);
525
507
        }
526
508
 
527
509
        /* if bit 5 goes low, we start the timer again */
528
510
        if ((diff & 0x20) && (newval & 0x20))
529
511
        {
530
512
                //mame_printf_debug("Starting timer\n");
531
 
                timer_adjust_periodic(sega005_sound_timer, ATTOTIME_IN_HZ(SEGA005_555_TIMER_FREQ), 0, ATTOTIME_IN_HZ(SEGA005_555_TIMER_FREQ));
 
513
                state->m_sega005_sound_timer->adjust(attotime::from_hz(SEGA005_555_TIMER_FREQ), 0, attotime::from_hz(SEGA005_555_TIMER_FREQ));
532
514
        }
533
515
}
534
516
 
535
517
 
536
518
static WRITE8_DEVICE_HANDLER( sega005_sound_b_w )
537
519
{
 
520
        segag80r_state *state = device->machine().driver_data<segag80r_state>();
538
521
        /*
539
522
           D6: manual timer clock (0->1)
540
523
           D5: 0 = manual timer, 1 = auto timer
541
524
           D4: 1 = hold/reset address counter to 0
542
525
        D3-D0: upper 4 bits of ROM address
543
526
    */
544
 
        UINT8 diff = data ^ sound_state[1];
545
 
        sound_state[1] = data;
 
527
        UINT8 diff = data ^ state->m_sound_state[1];
 
528
        state->m_sound_state[1] = data;
546
529
 
547
530
        //mame_printf_debug("sound[%d] = %02X\n", 1, data);
548
531
 
549
532
        /* force a stream update */
550
 
        stream_update(sega005_stream);
 
533
        state->m_sega005_stream->update();
551
534
 
552
535
        /* ROM address */
553
 
        sound_addr = ((data & 0x0f) << 7) | (sound_addr & 0x7f);
 
536
        state->m_sound_addr = ((data & 0x0f) << 7) | (state->m_sound_addr & 0x7f);
554
537
 
555
538
        /* reset both sound address and square wave counters */
556
539
        if (data & 0x10)
557
540
        {
558
 
                sound_addr &= 0x780;
559
 
                square_state = 0;
 
541
                state->m_sound_addr &= 0x780;
 
542
                state->m_square_state = 0;
560
543
        }
561
544
 
562
545
        /* manual clock */
563
546
        if ((diff & 0x40) && (data & 0x40) && !(data & 0x20) && !(data & 0x10))
564
 
                sound_addr = (sound_addr & 0x780) | ((sound_addr + 1) & 0x07f);
 
547
                state->m_sound_addr = (state->m_sound_addr & 0x780) | ((state->m_sound_addr + 1) & 0x07f);
565
548
 
566
549
        /* update the sound data */
567
 
        sega005_update_sound_data(device->machine);
 
550
        sega005_update_sound_data(device->machine());
568
551
}
569
552
 
570
553
 
577
560
 
578
561
static DEVICE_START( sega005_sound )
579
562
{
580
 
        running_machine *machine = device->machine;
 
563
        segag80r_state *state = device->machine().driver_data<segag80r_state>();
 
564
        running_machine &machine = device->machine();
581
565
 
582
566
        /* create the stream */
583
 
        sega005_stream = stream_create(device, 0, 1, SEGA005_COUNTER_FREQ, NULL, sega005_stream_update);
 
567
        state->m_sega005_stream = device->machine().sound().stream_alloc(*device, 0, 1, SEGA005_COUNTER_FREQ, NULL, sega005_stream_update);
584
568
 
585
569
        /* create a timer for the 555 */
586
 
        sega005_sound_timer = timer_alloc(machine, sega005_auto_timer, NULL);
 
570
        state->m_sega005_sound_timer = machine.scheduler().timer_alloc(FUNC(sega005_auto_timer));
587
571
 
588
572
        /* set the initial sound data */
589
 
        sound_data = 0x00;
 
573
        state->m_sound_data = 0x00;
590
574
        sega005_update_sound_data(machine);
591
575
}
592
576
 
607
591
 
608
592
static STREAM_UPDATE( sega005_stream_update )
609
593
{
610
 
        const UINT8 *sound_prom = device->machine->region("proms")->base();
 
594
        segag80r_state *state = device->machine().driver_data<segag80r_state>();
 
595
        const UINT8 *sound_prom = device->machine().region("proms")->base();
611
596
        int i;
612
597
 
613
598
        /* no implementation yet */
614
599
        for (i = 0; i < samples; i++)
615
600
        {
616
 
                if (!(sound_state[1] & 0x10) && (++square_count & 0xff) == 0)
 
601
                if (!(state->m_sound_state[1] & 0x10) && (++state->m_square_count & 0xff) == 0)
617
602
                {
618
 
                        square_count = sound_prom[sound_data & 0x1f];
 
603
                        state->m_square_count = sound_prom[state->m_sound_data & 0x1f];
619
604
 
620
605
                        /* hack - the RC should filter this out */
621
 
                        if (square_count != 0xff)
622
 
                                square_state += 2;
 
606
                        if (state->m_square_count != 0xff)
 
607
                                state->m_square_state += 2;
623
608
                }
624
609
 
625
 
                outputs[0][i] = (square_state & 2) ? 0x7fff : 0x0000;
 
610
                outputs[0][i] = (state->m_square_state & 2) ? 0x7fff : 0x0000;
626
611
        }
627
612
}
628
613
 
629
614
 
630
615
static TIMER_CALLBACK( sega005_auto_timer )
631
616
{
 
617
        segag80r_state *state = machine.driver_data<segag80r_state>();
632
618
        /* force an update then clock the sound address if not held in reset */
633
 
        stream_update(sega005_stream);
634
 
        if ((sound_state[1] & 0x20) && !(sound_state[1] & 0x10))
 
619
        state->m_sega005_stream->update();
 
620
        if ((state->m_sound_state[1] & 0x20) && !(state->m_sound_state[1] & 0x10))
635
621
        {
636
 
                sound_addr = (sound_addr & 0x780) | ((sound_addr + 1) & 0x07f);
 
622
                state->m_sound_addr = (state->m_sound_addr & 0x780) | ((state->m_sound_addr + 1) & 0x07f);
637
623
                sega005_update_sound_data(machine);
638
624
        }
639
625
}
693
679
 
694
680
static SOUND_START( spaceod )
695
681
{
696
 
        state_save_register_global_array(machine, sound_state);
 
682
        segag80r_state *state = machine.driver_data<segag80r_state>();
 
683
        state_save_register_global_array(machine, state->m_sound_state);
697
684
}
698
685
 
699
686
 
706
693
 
707
694
WRITE8_HANDLER( spaceod_sound_w )
708
695
{
709
 
        device_t *samples = space->machine->device("samples");
710
 
        UINT8 diff = data ^ sound_state[offset];
711
 
        sound_state[offset] = data;
 
696
        segag80r_state *state = space->machine().driver_data<segag80r_state>();
 
697
        device_t *samples = space->machine().device("samples");
 
698
        UINT8 diff = data ^ state->m_sound_state[offset];
 
699
        state->m_sound_state[offset] = data;
712
700
 
713
701
        switch (offset)
714
702
        {
812
800
 *
813
801
 *************************************/
814
802
 
815
 
static ADDRESS_MAP_START( monsterb_7751_portmap, ADDRESS_SPACE_IO, 8 )
 
803
static ADDRESS_MAP_START( monsterb_7751_portmap, AS_IO, 8 )
816
804
        AM_RANGE(MCS48_PORT_T1,   MCS48_PORT_T1) AM_READ(n7751_t1_r)
817
805
        AM_RANGE(MCS48_PORT_P2,   MCS48_PORT_P2) AM_READ(n7751_command_r)
818
806
        AM_RANGE(MCS48_PORT_BUS,  MCS48_PORT_BUS) AM_READ(n7751_rom_r)
875
863
 
876
864
static SOUND_START( monsterb )
877
865
{
878
 
        state_save_register_global_array(machine, sound_state);
879
 
        state_save_register_global(machine, sound_addr);
880
 
        state_save_register_global(machine, n7751_command);
881
 
        state_save_register_global(machine, n7751_busy);
 
866
        segag80r_state *state = machine.driver_data<segag80r_state>();
 
867
        state_save_register_global_array(machine, state->m_sound_state);
 
868
        state_save_register_global(machine, state->m_sound_addr);
 
869
        state_save_register_global(machine, state->m_n7751_command);
 
870
        state_save_register_global(machine, state->m_n7751_busy);
882
871
}
883
872
 
884
873
 
891
880
 
892
881
static WRITE8_DEVICE_HANDLER( monsterb_sound_a_w )
893
882
{
894
 
        device_t *tms = device->machine->device("music");
 
883
        device_t *tms = device->machine().device("music");
895
884
        int enable_val;
896
885
 
897
886
        /* Lower four data lines get decoded into 13 control lines */
898
887
        tms36xx_note_w(tms, 0, data & 15);
899
888
 
900
889
        /* Top four data lines address an 82S123 ROM that enables/disables voices */
901
 
        enable_val = device->machine->region("prom")->base()[(data & 0xF0) >> 4];
 
890
        enable_val = device->machine().region("prom")->base()[(data & 0xF0) >> 4];
902
891
        tms3617_enable_w(tms, enable_val >> 2);
903
892
}
904
893
 
912
901
 
913
902
static WRITE8_DEVICE_HANDLER( monsterb_sound_b_w )
914
903
{
915
 
        device_t *samples = device->machine->device("samples");
916
 
        UINT8 diff = data ^ sound_state[1];
917
 
        sound_state[1] = data;
 
904
        segag80r_state *state = device->machine().driver_data<segag80r_state>();
 
905
        device_t *samples = device->machine().device("samples");
 
906
        UINT8 diff = data ^ state->m_sound_state[1];
 
907
        state->m_sound_state[1] = data;
918
908
 
919
909
        /* SHOT: channel 0 */
920
910
        if ((diff & 0x01) && !(data & 0x01)) sample_start(samples, 0, 0, FALSE);
935
925
 
936
926
static READ8_DEVICE_HANDLER( n7751_status_r )
937
927
{
938
 
        return n7751_busy << 4;
 
928
        segag80r_state *state = device->machine().driver_data<segag80r_state>();
 
929
        return state->m_n7751_busy << 4;
939
930
}
940
931
 
941
932
 
942
933
static WRITE8_DEVICE_HANDLER( n7751_command_w )
943
934
{
 
935
        segag80r_state *state = device->machine().driver_data<segag80r_state>();
944
936
        /*
945
937
        Z80 7751 control port
946
938
 
947
939
        D0-D2 = connected to 7751 port C
948
940
        D3    = /INT line
949
941
    */
950
 
        n7751_command = data & 0x07;
951
 
        cputag_set_input_line(device->machine, "audiocpu", 0, ((data & 0x08) == 0) ? ASSERT_LINE : CLEAR_LINE);
952
 
        cpuexec_boost_interleave(device->machine, attotime_zero, ATTOTIME_IN_USEC(100));
 
942
        state->m_n7751_command = data & 0x07;
 
943
        cputag_set_input_line(device->machine(), "audiocpu", 0, ((data & 0x08) == 0) ? ASSERT_LINE : CLEAR_LINE);
 
944
        device->machine().scheduler().boost_interleave(attotime::zero, attotime::from_usec(100));
953
945
}
954
946
 
955
947
 
956
948
static WRITE8_DEVICE_HANDLER( n7751_rom_control_w )
957
949
{
 
950
        segag80r_state *state = device->machine().driver_data<segag80r_state>();
958
951
        /* P4 - address lines 0-3 */
959
952
        /* P5 - address lines 4-7 */
960
953
        /* P6 - address lines 8-11 */
962
955
        switch (offset)
963
956
        {
964
957
                case 0:
965
 
                        sound_addr = (sound_addr & ~0x00f) | ((data & 0x0f) << 0);
 
958
                        state->m_sound_addr = (state->m_sound_addr & ~0x00f) | ((data & 0x0f) << 0);
966
959
                        break;
967
960
 
968
961
                case 1:
969
 
                        sound_addr = (sound_addr & ~0x0f0) | ((data & 0x0f) << 4);
 
962
                        state->m_sound_addr = (state->m_sound_addr & ~0x0f0) | ((data & 0x0f) << 4);
970
963
                        break;
971
964
 
972
965
                case 2:
973
 
                        sound_addr = (sound_addr & ~0xf00) | ((data & 0x0f) << 8);
 
966
                        state->m_sound_addr = (state->m_sound_addr & ~0xf00) | ((data & 0x0f) << 8);
974
967
                        break;
975
968
 
976
969
                case 3:
977
 
                        sound_addr &= 0xfff;
 
970
                        state->m_sound_addr &= 0xfff;
978
971
                        {
979
 
                                int numroms = device->machine->region("n7751")->bytes() / 0x1000;
980
 
                                if (!(data & 0x01) && numroms >= 1) sound_addr |= 0x0000;
981
 
                                if (!(data & 0x02) && numroms >= 2) sound_addr |= 0x1000;
982
 
                                if (!(data & 0x04) && numroms >= 3) sound_addr |= 0x2000;
983
 
                                if (!(data & 0x08) && numroms >= 4) sound_addr |= 0x3000;
 
972
                                int numroms = device->machine().region("n7751")->bytes() / 0x1000;
 
973
                                if (!(data & 0x01) && numroms >= 1) state->m_sound_addr |= 0x0000;
 
974
                                if (!(data & 0x02) && numroms >= 2) state->m_sound_addr |= 0x1000;
 
975
                                if (!(data & 0x04) && numroms >= 3) state->m_sound_addr |= 0x2000;
 
976
                                if (!(data & 0x08) && numroms >= 4) state->m_sound_addr |= 0x3000;
984
977
                        }
985
978
                        break;
986
979
        }
989
982
 
990
983
static READ8_HANDLER( n7751_rom_r )
991
984
{
 
985
        segag80r_state *state = space->machine().driver_data<segag80r_state>();
992
986
        /* read from BUS */
993
 
        return space->machine->region("n7751")->base()[sound_addr];
 
987
        return space->machine().region("n7751")->base()[state->m_sound_addr];
994
988
}
995
989
 
996
990
 
997
991
static READ8_HANDLER( n7751_command_r )
998
992
{
 
993
        segag80r_state *state = space->machine().driver_data<segag80r_state>();
999
994
        /* read from P2 - 8255's PC0-2 connects to 7751's S0-2 (P24-P26 on an 8048) */
1000
995
        /* bit 0x80 is an alternate way to control the sample on/off; doesn't appear to be used */
1001
 
        return 0x80 | ((n7751_command & 0x07) << 4);
 
996
        return 0x80 | ((state->m_n7751_command & 0x07) << 4);
1002
997
}
1003
998
 
1004
999
 
1005
1000
static WRITE8_DEVICE_HANDLER( n7751_p2_w )
1006
1001
{
 
1002
        segag80r_state *state = device->machine().driver_data<segag80r_state>();
1007
1003
        /* write to P2; low 4 bits go to 8243 */
1008
1004
        i8243_p2_w(device, offset, data & 0x0f);
1009
1005
 
1010
1006
        /* output of bit $80 indicates we are ready (1) or busy (0) */
1011
1007
        /* no other outputs are used */
1012
 
        n7751_busy = data >> 7;
 
1008
        state->m_n7751_busy = data >> 7;
1013
1009
}
1014
1010
 
1015
1011