38
37
/*************************************
42
*************************************/
44
static UINT8 sound_state[2];
45
static UINT8 sound_rate;
46
static UINT16 sound_addr;
47
static UINT8 sound_data;
49
static UINT8 square_state;
50
static UINT8 square_count;
52
static emu_timer *sega005_sound_timer;
53
static sound_stream *sega005_stream;
55
static UINT8 n7751_command;
56
static UINT8 n7751_busy;
60
/*************************************
62
39
* Astro Blaster sound hardware
64
41
*************************************/
229
206
static SOUND_START( astrob )
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);
243
221
WRITE8_HANDLER( astrob_sound_w )
223
segag80r_state *state = space->machine().driver_data<segag80r_state>();
245
224
static const float attack_resistor[10] =
247
226
120.0f, 82.0f, 62.0f, 56.0f, 47.0f, 39.0f, 33.0f, 27.0f, 24.0f, 22.0f
249
device_t *samples = space->machine->device("samples");
228
device_t *samples = space->machine().device("samples");
250
229
float freq_factor;
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;
306
285
if ((diff & 0x08) && !(data & 0x08)) sample_start(samples, 8, 13, FALSE);
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;
312
if (!(data & 0x20)) sound_rate = 0;
291
if (!(data & 0x20)) state->m_sound_rate = 0;
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;
330
309
/* adjust the sample rate of invader sounds based the sound_rate */
331
310
/* this is an approximation */
462
441
static SOUND_START( sega005 )
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);
479
459
static WRITE8_DEVICE_HANDLER( sega005_sound_a_w )
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;
485
466
/* LARGE EXPL: channel 0 */
486
467
if ((diff & 0x01) && !(data & 0x01)) sample_start(samples, 0, 0, FALSE);
510
INLINE void sega005_update_sound_data(running_machine *machine)
491
INLINE void sega005_update_sound_data(running_machine &machine)
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;
515
//mame_printf_debug(" [%03X] = %02X\n", sound_addr, newval);
497
//mame_printf_debug(" [%03X] = %02X\n", state->m_sound_addr, newval);
517
499
/* latch the new value */
500
state->m_sound_data = newval;
520
502
/* if bit 5 goes high, we reset the timer */
521
503
if ((diff & 0x20) && !(newval & 0x20))
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);
527
509
/* if bit 5 goes low, we start the timer again */
528
510
if ((diff & 0x20) && (newval & 0x20))
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));
536
518
static WRITE8_DEVICE_HANDLER( sega005_sound_b_w )
520
segag80r_state *state = device->machine().driver_data<segag80r_state>();
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
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;
547
530
//mame_printf_debug("sound[%d] = %02X\n", 1, data);
549
532
/* force a stream update */
550
stream_update(sega005_stream);
533
state->m_sega005_stream->update();
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);
555
538
/* reset both sound address and square wave counters */
541
state->m_sound_addr &= 0x780;
542
state->m_square_state = 0;
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);
566
549
/* update the sound data */
567
sega005_update_sound_data(device->machine);
550
sega005_update_sound_data(device->machine());
578
561
static DEVICE_START( sega005_sound )
580
running_machine *machine = device->machine;
563
segag80r_state *state = device->machine().driver_data<segag80r_state>();
564
running_machine &machine = device->machine();
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);
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));
588
572
/* set the initial sound data */
573
state->m_sound_data = 0x00;
590
574
sega005_update_sound_data(machine);
608
592
static STREAM_UPDATE( sega005_stream_update )
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();
613
598
/* no implementation yet */
614
599
for (i = 0; i < samples; i++)
616
if (!(sound_state[1] & 0x10) && (++square_count & 0xff) == 0)
601
if (!(state->m_sound_state[1] & 0x10) && (++state->m_square_count & 0xff) == 0)
618
square_count = sound_prom[sound_data & 0x1f];
603
state->m_square_count = sound_prom[state->m_sound_data & 0x1f];
620
605
/* hack - the RC should filter this out */
621
if (square_count != 0xff)
606
if (state->m_square_count != 0xff)
607
state->m_square_state += 2;
625
outputs[0][i] = (square_state & 2) ? 0x7fff : 0x0000;
610
outputs[0][i] = (state->m_square_state & 2) ? 0x7fff : 0x0000;
630
615
static TIMER_CALLBACK( sega005_auto_timer )
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))
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);
707
694
WRITE8_HANDLER( spaceod_sound_w )
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;
813
801
*************************************/
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)
876
864
static SOUND_START( monsterb )
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);
892
881
static WRITE8_DEVICE_HANDLER( monsterb_sound_a_w )
894
device_t *tms = device->machine->device("music");
883
device_t *tms = device->machine().device("music");
897
886
/* Lower four data lines get decoded into 13 control lines */
898
887
tms36xx_note_w(tms, 0, data & 15);
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);
913
902
static WRITE8_DEVICE_HANDLER( monsterb_sound_b_w )
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;
919
909
/* SHOT: channel 0 */
920
910
if ((diff & 0x01) && !(data & 0x01)) sample_start(samples, 0, 0, FALSE);
936
926
static READ8_DEVICE_HANDLER( n7751_status_r )
938
return n7751_busy << 4;
928
segag80r_state *state = device->machine().driver_data<segag80r_state>();
929
return state->m_n7751_busy << 4;
942
933
static WRITE8_DEVICE_HANDLER( n7751_command_w )
935
segag80r_state *state = device->machine().driver_data<segag80r_state>();
945
937
Z80 7751 control port
947
939
D0-D2 = connected to 7751 port C
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));
956
948
static WRITE8_DEVICE_HANDLER( n7751_rom_control_w )
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 */
965
sound_addr = (sound_addr & ~0x00f) | ((data & 0x0f) << 0);
958
state->m_sound_addr = (state->m_sound_addr & ~0x00f) | ((data & 0x0f) << 0);
969
sound_addr = (sound_addr & ~0x0f0) | ((data & 0x0f) << 4);
962
state->m_sound_addr = (state->m_sound_addr & ~0x0f0) | ((data & 0x0f) << 4);
973
sound_addr = (sound_addr & ~0xf00) | ((data & 0x0f) << 8);
966
state->m_sound_addr = (state->m_sound_addr & ~0xf00) | ((data & 0x0f) << 8);
970
state->m_sound_addr &= 0xfff;
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;
990
983
static READ8_HANDLER( n7751_rom_r )
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];
997
991
static READ8_HANDLER( n7751_command_r )
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);
1005
1000
static WRITE8_DEVICE_HANDLER( n7751_p2_w )
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);
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;