summaryrefslogtreecommitdiffstatshomepage
path: root/src/mame/audio/leland.cpp
blob: 9fdbb391b760b880c153a04765d7feb588c9de31 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
// license:BSD-3-Clause
// copyright-holders:Aaron Giles,Paul Leaman
/***************************************************************************

    Cinemat/Leland driver

    Leland sound hardware
    driver by Aaron Giles and Paul Leaman

    -------------------------------------------------------------------

    1st generation sound hardware was controlled by the master Z80.
    It drove either an AY-8910/AY-8912 for music. It also had two DACs
    that were driven by the video refresh. At the end of each scanline
    there are 8-bit DAC samples that can be enabled via the output
    ports on the AY-8910. The DACs run at a fixed frequency of 15.3kHz,
    since they are clocked once each scanline.

    -------------------------------------------------------------------

    2nd generation sound hardware was used in Redline Racer. It
    consisted of an 80186 microcontroller driving 8 8-bit DACs. The
    frequency of the DACs were controlled by one of 3 Intel 8254
    programmable interval timers (PITs):

        DAC number  Clock source
        ----------  -----------------
            0       8254 PIT 1 output 0
            1       8254 PIT 1 output 1
            2       8254 PIT 1 output 2
            3       8254 PIT 2 output 0
            4       8254 PIT 2 output 1
            5-7     8254 PIT 3 output 0

    The clock outputs for each DAC can be read, and are polled to
    determine when data should be updated on the chips. The 80186's
    two DMA channels are generally used to drive the first two DACs,
    with the remaining 6 DACs being fed manually via polling.

    -------------------------------------------------------------------

    3rd generation sound hardware appeared in the football games
    (Quarterback, AAFB) and the later games up through Pigout. This
    variant is closely based on the Redline Racer sound system, but
    they took out two of the DACs and replaced them with a higher
    resolution (10-bit) DAC. The driving clocks have been rearranged
    a bit, and the number of PITs reduced from 3 to 2:

        DAC number  Clock source
        ----------  -----------------
            0       8254 PIT 1 output 0
            1       8254 PIT 1 output 1
            2       8254 PIT 1 output 2
            3       8254 PIT 2 output 0
            4       8254 PIT 2 output 1
            5       8254 PIT 2 output 2
            10-bit  80186 timer 0

    Like the 2nd generation board, the first two DACs are driven via
    the DMA channels, and the remaining 5 DACs are polled.

    -------------------------------------------------------------------

    4th generation sound hardware showed up in Ataxx, Indy Heat, and
    World Soccer Finals. For this variant, they removed one more PIT
    and 3 of the 8-bit DACs, and added a YM2151 music chip and an
    externally-fed 8-bit DAC.

        DAC number  Clock source
        ----------  -----------------
            0       8254 PIT 1 output 0
            1       8254 PIT 1 output 1
            2       8254 PIT 1 output 2
            10-bit  80186 timer 0
            ext     80186 timer 1

    The externally driven DACs have registers for a start/stop address
    and triggers to control the clocking.

***************************************************************************/

#include "emu.h"
#include "audio/leland.h"

#include "cpu/z80/z80.h"
#include "sound/volt_reg.h"
#include "speaker.h"

#define LOG_COMM 0
#define LOG_EXTERN 0

/*************************************
 *
 *  2nd-4th generation sound
 *
 *************************************/

WRITE_LINE_MEMBER(leland_80186_sound_device::pit0_2_w)
{
	set_clock_line(2, state);
}

WRITE_LINE_MEMBER(leland_80186_sound_device::pit1_0_w)
{
	set_clock_line(3, state);
}

WRITE_LINE_MEMBER(leland_80186_sound_device::pit1_1_w)
{
	set_clock_line(4, state);
}

WRITE_LINE_MEMBER(leland_80186_sound_device::pit1_2_w)
{
	set_clock_line(5, state);
}

WRITE_LINE_MEMBER(leland_80186_sound_device::i80186_tmr0_w)
{
	set_clock_line(6, state);
}

WRITE_LINE_MEMBER(leland_80186_sound_device::i80186_tmr1_w)
{
	if (m_ext_base != nullptr)
	{
		if (state)
		{
			if (m_ext_active && (m_ext_start < m_ext_stop))
			{
				m_dac[3]->write(m_ext_base[m_ext_start]);
				m_ext_start++;
			}
		}
	}
	set_clock_line(7, state);
}

void leland_80186_sound_device::device_add_mconfig(machine_config &config)
{
	I80186(config, m_audiocpu, 16_MHz_XTAL);
	m_audiocpu->set_addrmap(AS_PROGRAM, &leland_80186_sound_device::leland_80186_map_program);
	m_audiocpu->set_addrmap(AS_IO, &leland_80186_sound_device::leland_80186_map_io);
	m_audiocpu->chip_select_callback().set(FUNC(leland_80186_sound_device::peripheral_ctrl));
	m_audiocpu->tmrout0_handler().set(FUNC(leland_80186_sound_device::i80186_tmr0_w));

	SPEAKER(config, "speaker").front_center();
	voltage_regulator_device &vref(VOLTAGE_REGULATOR(config, "vref", 0));
	for (int i = 0; i < 6; i++)
	{
		AD7524(config, m_dac[i], 0).add_route(ALL_OUTPUTS, "speaker", 0.2); // 74hc374.u31..6 + ad7524.u46..51
		DAC_8BIT_BINARY_WEIGHTED(config, m_dacvol[i], 0); // 74hc374.u17..22 + rX2-rX9 (24k,12k,6.2k,3k,1.5k,750,360,160) where X is 0..5
		m_dacvol[i]->add_route(0, m_dac[i], 1.0, DAC_VREF_POS_INPUT);
		m_dacvol[i]->add_route(0, m_dac[i], -1.0, DAC_VREF_NEG_INPUT);
		vref.add_route(0, m_dacvol[i], 1.0, DAC_VREF_POS_INPUT);
	}
	AD7533(config, "dac9", 0).add_route(ALL_OUTPUTS, "speaker", 1.0); // ad7533.u64

	vref.add_route(0, "dac9", 1.0, DAC_VREF_POS_INPUT);
	vref.add_route(0, "dac9", -1.0, DAC_VREF_NEG_INPUT);

	PIT8254(config, m_pit[0], 0);
	m_pit[0]->set_clk<0>(4000000);
	m_pit[0]->out_handler<0>().set(m_audiocpu, FUNC(i80186_cpu_device::drq0_w));
	m_pit[0]->set_clk<1>(4000000);
	m_pit[0]->out_handler<1>().set(m_audiocpu, FUNC(i80186_cpu_device::drq1_w));
	m_pit[0]->set_clk<2>(4000000);
	m_pit[0]->out_handler<2>().set(FUNC(leland_80186_sound_device::pit0_2_w));

	PIT8254(config, m_pit[1], 0);
	m_pit[1]->set_clk<0>(4000000);
	m_pit[1]->out_handler<0>().set(FUNC(leland_80186_sound_device::pit1_0_w));
	m_pit[1]->set_clk<1>(4000000);
	m_pit[1]->out_handler<1>().set(FUNC(leland_80186_sound_device::pit1_1_w));
	m_pit[1]->set_clk<2>(4000000);
	m_pit[1]->out_handler<2>().set(FUNC(leland_80186_sound_device::pit1_2_w));

	GENERIC_LATCH_16(config, m_soundlatch);
}

void redline_80186_sound_device::device_add_mconfig(machine_config &config)
{
	I80186(config, m_audiocpu, 16_MHz_XTAL);
	m_audiocpu->set_addrmap(AS_PROGRAM, &redline_80186_sound_device::leland_80186_map_program);
	m_audiocpu->set_addrmap(AS_IO, &redline_80186_sound_device::redline_80186_map_io);
	m_audiocpu->chip_select_callback().set(FUNC(leland_80186_sound_device::peripheral_ctrl));

	SPEAKER(config, "speaker").front_center();
	voltage_regulator_device &vref(VOLTAGE_REGULATOR(config, "vref", 0));
	for (int i = 0; i < 8; i++)
	{
		AD7524(config, m_dac[i], 0).add_route(ALL_OUTPUTS, "speaker", 0.2); // unknown DAC
		DAC_8BIT_BINARY_WEIGHTED(config, m_dacvol[i], 0);
		m_dacvol[i]->add_route(0, m_dac[i], 1.0, DAC_VREF_POS_INPUT);
		m_dacvol[i]->add_route(0, m_dac[i], -1.0, DAC_VREF_NEG_INPUT); // unknown DAC
		vref.add_route(0, m_dacvol[i], 1.0, DAC_VREF_POS_INPUT);
	}

	PIT8254(config, m_pit[0], 0);
	m_pit[0]->set_clk<0>(7000000);
	m_pit[0]->out_handler<0>().set(m_audiocpu, FUNC(i80186_cpu_device::drq0_w));
	m_pit[0]->set_clk<1>(7000000);
	m_pit[0]->out_handler<1>().set(m_audiocpu, FUNC(i80186_cpu_device::drq1_w));
	m_pit[0]->set_clk<2>(7000000);
	m_pit[0]->out_handler<2>().set(FUNC(leland_80186_sound_device::pit0_2_w));

	PIT8254(config, m_pit[1], 0);
	m_pit[1]->set_clk<0>(7000000);
	m_pit[1]->out_handler<0>().set(FUNC(leland_80186_sound_device::pit1_0_w));
	m_pit[1]->set_clk<1>(7000000);
	m_pit[1]->out_handler<1>().set(FUNC(leland_80186_sound_device::pit1_1_w));
	m_pit[1]->set_clk<2>(7000000);

	PIT8254(config, m_pit[2], 0);
	m_pit[2]->set_clk<0>(7000000);
	m_pit[2]->out_handler<0>().set(FUNC(leland_80186_sound_device::pit1_2_w));
	m_pit[2]->set_clk<1>(7000000);
	m_pit[2]->set_clk<2>(7000000);

	GENERIC_LATCH_16(config, m_soundlatch);
}

void ataxx_80186_sound_device::device_add_mconfig(machine_config &config)
{
	I80186(config, m_audiocpu, 16_MHz_XTAL);
	m_audiocpu->set_addrmap(AS_PROGRAM, &ataxx_80186_sound_device::leland_80186_map_program);
	m_audiocpu->set_addrmap(AS_IO, &ataxx_80186_sound_device::ataxx_80186_map_io);
	m_audiocpu->chip_select_callback().set(FUNC(leland_80186_sound_device::peripheral_ctrl));
	m_audiocpu->tmrout0_handler().set(FUNC(leland_80186_sound_device::i80186_tmr0_w));

	SPEAKER(config, "speaker").front_center();
	voltage_regulator_device &vref(VOLTAGE_REGULATOR(config, "vref", 0));
	for (int i = 0; i < 4; i++)
	{
		AD7524(config, m_dac[i], 0).add_route(ALL_OUTPUTS, "speaker", 0.2); // unknown DAC
		DAC_8BIT_BINARY_WEIGHTED(config, m_dacvol[i], 0); // unknown DAC
		m_dacvol[i]->add_route(0, m_dac[i], 1.0, DAC_VREF_POS_INPUT);
		m_dacvol[i]->add_route(0, m_dac[i], -1.0, DAC_VREF_NEG_INPUT);
		vref.add_route(0, m_dacvol[i], 1.0, DAC_VREF_POS_INPUT);
	}
	AD7533(config, "dac9", 0).add_route(ALL_OUTPUTS, "speaker", 1.0); // unknown DAC

	vref.add_route(0, "dac9", 1.0, DAC_VREF_POS_INPUT);
	vref.add_route(0, "dac9", -1.0, DAC_VREF_NEG_INPUT);

	PIT8254(config, m_pit[0], 0);
	m_pit[0]->set_clk<0>(4000000);
	m_pit[0]->out_handler<0>().set(m_audiocpu, FUNC(i80186_cpu_device::drq0_w));
	m_pit[0]->set_clk<1>(4000000);
	m_pit[0]->out_handler<1>().set(m_audiocpu, FUNC(i80186_cpu_device::drq1_w));
	m_pit[0]->set_clk<2>(4000000);
	m_pit[0]->out_handler<2>().set(FUNC(leland_80186_sound_device::pit0_2_w));

	GENERIC_LATCH_16(config, m_soundlatch);
}

void wsf_80186_sound_device::device_add_mconfig(machine_config &config)
{
	I80186(config, m_audiocpu, 16_MHz_XTAL);
	m_audiocpu->set_addrmap(AS_PROGRAM, &wsf_80186_sound_device::leland_80186_map_program);
	m_audiocpu->set_addrmap(AS_IO, &wsf_80186_sound_device::ataxx_80186_map_io);
	m_audiocpu->chip_select_callback().set(FUNC(leland_80186_sound_device::peripheral_ctrl));
	m_audiocpu->tmrout0_handler().set(FUNC(leland_80186_sound_device::i80186_tmr0_w));
	m_audiocpu->tmrout1_handler().set(FUNC(leland_80186_sound_device::i80186_tmr1_w));

	SPEAKER(config, "speaker").front_center();
	voltage_regulator_device &vref(VOLTAGE_REGULATOR(config, "vref", 0));
	for (int i = 0; i < 4; i++)
	{
		AD7524(config, m_dac[i], 0).add_route(ALL_OUTPUTS, "speaker", 0.2); // unknown DAC
		DAC_8BIT_BINARY_WEIGHTED(config, m_dacvol[i], 0); // unknown DAC
		m_dacvol[i]->add_route(0, m_dac[i], 1.0, DAC_VREF_POS_INPUT);
		m_dacvol[i]->add_route(0, m_dac[i], -1.0, DAC_VREF_NEG_INPUT); // unknown DAC
		vref.add_route(0, m_dacvol[i], 1.0, DAC_VREF_POS_INPUT);
	}
	AD7533(config, "dac9", 0).add_route(ALL_OUTPUTS, "speaker", 1.0); // unknown DAC
	vref.add_route(0, "dac9", 1.0, DAC_VREF_POS_INPUT);
	vref.add_route(0, "dac9", -1.0, DAC_VREF_NEG_INPUT);

	/* sound hardware */
	YM2151(config, m_ymsnd, 4000000);
	m_ymsnd->add_route(0, "speaker", 0.40);
	m_ymsnd->add_route(1, "speaker", 0.40);

	PIT8254(config, m_pit[0], 0);
	m_pit[0]->set_clk<0>(4000000);
	m_pit[0]->out_handler<0>().set(m_audiocpu, FUNC(i80186_cpu_device::drq0_w));
	m_pit[0]->set_clk<1>(4000000);
	m_pit[0]->out_handler<1>().set(m_audiocpu, FUNC(i80186_cpu_device::drq1_w));
	m_pit[0]->set_clk<2>(4000000);
	m_pit[0]->out_handler<2>().set(FUNC(leland_80186_sound_device::pit0_2_w));

	GENERIC_LATCH_16(config, m_soundlatch);
}


void leland_80186_sound_device::leland_80186_map_program(address_map &map)
{
	map(0x00000, 0x03fff).mirror(0x1c000).ram();
	map(0x20000, 0xfffff).rom().region("audiocpu", 0x20000);
}

void leland_80186_sound_device::ataxx_80186_map_io(address_map &map)
{
}

void redline_80186_sound_device::redline_80186_map_io(address_map &map)
{
	map(0x0000, 0xffff).w(FUNC(redline_80186_sound_device::redline_dac_w));
}


void leland_80186_sound_device::leland_80186_map_io(address_map &map)
{
	map(0x0000, 0xffff).w(FUNC(leland_80186_sound_device::dac_w));
}

/*************************************
 *
 *  Sound initialization
 *
 *************************************/

void leland_80186_sound_device::device_start()
{
	// register for savestates
	save_item(NAME(m_peripheral));
	save_item(NAME(m_last_control));
	save_item(NAME(m_clock_active));
	save_item(NAME(m_clock_tick));
	save_item(NAME(m_sound_command));
	save_item(NAME(m_sound_response));
	save_item(NAME(m_ext_start));
	save_item(NAME(m_ext_stop));
	save_item(NAME(m_ext_active));

	// zerofill
	m_peripheral = 0;
	m_last_control = 0;
	m_clock_active = 0;
	m_clock_tick = 0;
	m_sound_command = 0;
	m_sound_response = 0;
	m_ext_start = 0;
	m_ext_stop = 0;
	m_ext_active = 0;
}

void leland_80186_sound_device::device_reset()
{
	m_last_control = 0xf8;
	m_clock_active = 0;
	m_clock_tick = 0;
	m_ext_start = 0;
	m_ext_stop = 0;
	m_ext_active = 0;
	if (m_type == TYPE_WSF)
		m_dacvol[3]->write(0xff);  //TODO: determine how to set this if at all
}

DEFINE_DEVICE_TYPE(LELAND_80186, leland_80186_sound_device, "leland_80186_sound", "80186 DAC (Leland)")

leland_80186_sound_device::leland_80186_sound_device(const machine_config &mconfig, const char *tag, device_t *owner, u32 clock)
	: leland_80186_sound_device(mconfig, LELAND_80186, tag, owner, clock)
{
	m_type = TYPE_LELAND;
}

leland_80186_sound_device::leland_80186_sound_device(const machine_config &mconfig, device_type type, const char *tag, device_t *owner, u32 clock)
	: device_t(mconfig, type, tag, owner, clock)
	, m_soundlatch(*this, "soundlatch")
	, m_dac(*this, "dac%u", 1U)
	, m_dac9(*this, "dac9")
	, m_dacvol(*this, "dac%uvol", 1U)
	, m_pit(*this, "pit%u", 0U)
	, m_audiocpu(*this, "audiocpu")
	, m_ymsnd(*this, "ymsnd")
	, m_master(*this, finder_base::DUMMY_TAG)
	, m_ext_base(*this, "ext")
{
}

DEFINE_DEVICE_TYPE(REDLINE_80186, redline_80186_sound_device, "redline_80186_sound", "80186 DAC (Redline Racer)")

redline_80186_sound_device::redline_80186_sound_device(const machine_config &mconfig, const char *tag, device_t *owner, u32 clock)
	: leland_80186_sound_device(mconfig, REDLINE_80186, tag, owner, clock)
{
	m_type = TYPE_REDLINE;
}

DEFINE_DEVICE_TYPE(ATAXX_80186, ataxx_80186_sound_device, "ataxx_80186_sound", "80186 DAC (Ataxx)")

ataxx_80186_sound_device::ataxx_80186_sound_device(const machine_config &mconfig, const char *tag, device_t *owner, u32 clock)
	: leland_80186_sound_device(mconfig, ATAXX_80186, tag, owner, clock)
{
	m_type = TYPE_ATAXX;
}

DEFINE_DEVICE_TYPE(WSF_80186, wsf_80186_sound_device, "wsf_80186_sound", "80186 DAC (WSF)")

wsf_80186_sound_device::wsf_80186_sound_device(const machine_config &mconfig, const char *tag, device_t *owner, u32 clock)
	: leland_80186_sound_device(mconfig, WSF_80186, tag, owner, clock)
{
	m_type = TYPE_WSF;
}

void leland_80186_sound_device::peripheral_ctrl(offs_t offset, u16 data)
{
	switch (offset)
	{
		case 2:
			m_peripheral = data;
			break;

		case 4:
		{
			u32 temp = (m_peripheral & 0xffc0) << 4;
			if (data & 0x0040)
			{
				m_audiocpu->space(AS_PROGRAM).install_readwrite_handler(temp, temp + 0x2ff, read16s_delegate(*this, FUNC(leland_80186_sound_device::peripheral_r)), write16s_delegate(*this, FUNC(leland_80186_sound_device::peripheral_w)));
			}
			else
			{
				temp &= 0xffff;
				m_audiocpu->space(AS_IO).install_readwrite_handler(temp, temp + 0x2ff, read16s_delegate(*this, FUNC(leland_80186_sound_device::peripheral_r)), write16s_delegate(*this, FUNC(leland_80186_sound_device::peripheral_w)));
			}
			break;
		}

		default:
			break;
	}
}

/*************************************
 *
 *  External 80186 control
 *
 *************************************/

void leland_80186_sound_device::leland_80186_control_w(u8 data)
{
	/* see if anything changed */
	int diff = (m_last_control ^ data) & 0xf8;
	if (diff == 0)
		return;
	m_last_control = data;

	if (LOG_COMM)
	{
		logerror("%s:80186 control = %02X", machine().describe_context(), data);
		if (!(data & 0x80)) logerror("  /RESET");
		if (!(data & 0x40)) logerror("  ZNMI");
		if (!(data & 0x20)) logerror("  INT0");
		if (!(data & 0x10)) logerror("  /TEST");
		if (!(data & 0x08)) logerror("  INT1");
		logerror("\n");
	}

	/* /RESET */
	m_audiocpu->set_input_line(INPUT_LINE_RESET, (data & 0x80) ? CLEAR_LINE : ASSERT_LINE);
	m_audiocpu->set_input_line(INPUT_LINE_TEST, (data & 0x10) ? CLEAR_LINE : ASSERT_LINE);

	/* /NMI */
/*  If the master CPU doesn't get a response by the time it's ready to send
    the next command, it uses an NMI to force the issue; unfortunately, this
    seems to really screw up the sound system. It turns out it's better to
    just wait for the original interrupt to occur naturally */
/*  m_audiocpu->set_input_line(INPUT_LINE_NMI, (data & 0x40) ? CLEAR_LINE : ASSERT_LINE);*/

	/* INT0 */
	m_audiocpu->int0_w(data & 0x20);
	/* INT1 */
	m_audiocpu->int1_w(data & 0x08);
	/* handle reset here */
	if ((diff & 0x80) && (data & 0x80))
		reset();
}



/*************************************
 *
 *  Sound command handling
 *
 *************************************/

void leland_80186_sound_device::command_lo_w(u8 data)
{
	if (LOG_COMM) logerror("%s:Write sound command latch lo = %02X\n", machine().describe_context(), data);
	m_sound_command = (m_sound_command & 0xff00) | data;
	m_soundlatch->write(m_sound_command);
}


void leland_80186_sound_device::command_hi_w(u8 data)
{
	if (LOG_COMM) logerror("%s:Write sound command latch hi = %02X\n", machine().describe_context(), data);
	m_sound_command = (m_sound_command & 0x00ff) | (data << 8);
	m_soundlatch->write(m_sound_command);
}




/*************************************
 *
 *  Sound response handling
 *
 *************************************/

void leland_80186_sound_device::delayed_response_r(void *ptr, int param)
{
	int checkpc = param;
	int pc = m_master->pc();
	int oldaf = m_master->state_int(Z80_AF);

	/* This is pretty cheesy, but necessary. Since the CPUs run in round-robin order,
	   synchronizing on the write to this register from the slave side does nothing.
	   In order to make sure the master CPU get the real response, we synchronize on
	   the read. However, the value we returned the first time around may not be
	   accurate, so after the system has synced up, we go back into the master CPUs
	   state and put the proper value into the A register. */
	if (pc == checkpc)
	{
		if (LOG_COMM) logerror("(Updated sound response latch to %02X)\n", m_sound_response);

		oldaf = (oldaf & 0x00ff) | (m_sound_response << 8);
		m_master->set_state_int(Z80_AF, oldaf);
	}
	else if(LOG_COMM)
		logerror("ERROR: delayed_response_r - current PC = %04X, checkPC = %04X\n", pc, checkpc);
}


u8 leland_80186_sound_device::response_r()
{
	offs_t pc = m_master->pcbase();

	if (LOG_COMM) logerror("%04X:Read sound response latch = %02X\n", pc, m_sound_response);

	/* synchronize the response */
	machine().scheduler().synchronize(timer_expired_delegate(FUNC(leland_80186_sound_device::delayed_response_r), this), pc + 2);
	return m_sound_response;
}



/*************************************
 *
 *  Low-level DAC I/O
 *
 *************************************/

void leland_80186_sound_device::dac_w(offs_t offset, u16 data, u16 mem_mask)
{
	int dac = offset & 7;

	/* handle value changes */
	if (ACCESSING_BITS_0_7)
	{
		if ((offset & 0x60) == 0x40)
			m_audiocpu->drq0_w(CLEAR_LINE);
		else if ((offset & 0x60) == 0x60)
			m_audiocpu->drq1_w(CLEAR_LINE);

		m_dac[dac]->write(data & 0xff);

		set_clock_line(dac, 0);
	}

	/* handle volume changes */
	if (ACCESSING_BITS_8_15)
	{
		m_dacvol[dac]->write(data >> 8);
	}
}


void redline_80186_sound_device::redline_dac_w(offs_t offset, u16 data)
{
	data = (data & 0xff) | (offset << 8);
	offset = ((offset >> 8) & 7) | ((offset & 0x2000) ? 0x40 : 0) | ((offset & 0x800) ? 0x20 : 0);
	dac_w(offset, data, 0xffff);
}

void leland_80186_sound_device::ataxx_dac_control(offs_t offset, u16 data, u16 mem_mask)
{
	if (ACCESSING_BITS_0_7)
	{
		/* handle common offsets */
		switch (offset & 0x1f)
		{
		case 0x00:
			dac_w(0x40, data, 0x00ff);
			return;
		case 0x01:
			dac_w(0x61, data, 0x00ff);
			return;
		case 0x02:
			dac_w(2, data, 0x00ff);
			return;
		case 0x03:
			m_dacvol[0]->write((data & 7) << 5);
			m_dacvol[1]->write(((data >> 3) & 7) << 5);
			m_dacvol[2]->write(((data >> 6) & 3) << 6);
			return;
		}
	}

	/* if we have a YM2151 (and an external DAC), handle those offsets */
	switch (m_type)
	{
	case TYPE_WSF:
		switch (offset)
		{
		case 0x04:
			m_ext_active = 1;
			if (LOG_EXTERN) logerror("External DAC active\n");
			return;
		case 0x05:
			m_ext_active = 0;
			if (LOG_EXTERN) logerror("External DAC inactive\n");
			return;
		case 0x06:
			m_ext_start >>= 4;
			COMBINE_DATA(&m_ext_start);
			m_ext_start <<= 4;
			if (LOG_EXTERN) logerror("External DAC start = %05X\n", m_ext_start);
			return;
		case 0x07:
			m_ext_stop >>= 4;
			COMBINE_DATA(&m_ext_stop);
			m_ext_stop <<= 4;
			if (LOG_EXTERN) logerror("External DAC stop = %05X\n", m_ext_stop);
			return;
		}
		break;
	}

	logerror("%s:Unexpected peripheral write %d/%02X = %02X\n", machine().describe_context(), 5, offset, data);
}



/*************************************
 *
 *  Peripheral chip dispatcher
 *
 *************************************/

u16 leland_80186_sound_device::peripheral_r(offs_t offset, u16 mem_mask)
{
	int select = offset / 0x40;
	offset &= 0x3f;

	switch (select)
	{
		case 0:
			/* we have to return 0 periodically so that they handle interrupts */
			//if ((++m_clock_tick & 7) == 0)
			//  return 0;

			/* if we've filled up all the active channels, we can give this CPU a rest */
			/* until the next interrupt */
			if (m_type != TYPE_REDLINE)
				return ((m_clock_active >> 1) & 0x3e);
			else
				return ((m_clock_active << 1) & 0x7e);

		case 1:
			if (LOG_COMM) logerror("%s:Read sound command latch = %02X\n", machine().describe_context(), m_soundlatch->read());
			return m_soundlatch->read();

		case 2:
			if (ACCESSING_BITS_0_7)
				return m_pit[0]->read(offset & 3);
			break;

		case 3:
			if (m_type <= TYPE_REDLINE)
			{
				if (ACCESSING_BITS_0_7)
					return m_pit[1]->read(offset & 3);
			}
			else if (m_type == TYPE_WSF)
				return m_ymsnd->read(offset);
			break;

		case 4:
			if (m_type == TYPE_REDLINE)
			{
				if (ACCESSING_BITS_0_7)
					return m_pit[2]->read(offset & 3);
			}
			else
				logerror("%s:Unexpected peripheral read %d/%02X\n", machine().describe_context(), select, offset*2);
			break;

		default:
			logerror("%s:Unexpected peripheral read %d/%02X\n", machine().describe_context(), select, offset*2);
			break;
	}
	return 0xffff;
}


void leland_80186_sound_device::peripheral_w(offs_t offset, u16 data, u16 mem_mask)
{
	int select = offset / 0x40;
	offset &= 0x3f;

	switch (select)
	{
		case 1:
			if (LOG_COMM) logerror("%s:Write sound response latch = %02X\n", machine().describe_context(), data);
			m_sound_response = data;
			break;

		case 2:
			if (ACCESSING_BITS_0_7)
				m_pit[0]->write(offset & 3, data);
			break;

		case 3:
			if (m_type <= TYPE_REDLINE)
			{
				if (ACCESSING_BITS_0_7)
					m_pit[1]->write(offset & 3, data);
			}
			else if(m_type == TYPE_WSF)
				m_ymsnd->write(offset, data);
			break;

		case 4:
			if (m_type == TYPE_REDLINE)
			{
				if (ACCESSING_BITS_0_7)
					m_pit[2]->write(offset & 3, data);
			}
			else if (mem_mask == 0xffff)
			{
				m_dac9->write(data);
				set_clock_line(6, 0);
			}
			break;

		case 5: /* Ataxx/WSF/Indy Heat only */
			if (m_type > TYPE_REDLINE)
				ataxx_dac_control(offset, data, mem_mask);
			break;

		default:
			logerror("%s:Unexpected peripheral write %d/%02X = %02X\n", machine().describe_context(), select, offset, data);
			break;
	}
}



/*************************************
 *
 *  Game-specific handlers
 *
 *************************************/

void leland_80186_sound_device::ataxx_80186_control_w(u8 data)
{
	/* compute the bit-shuffled variants of the bits and then write them */
	int modified =  ((data & 0x01) << 7) |
					((data & 0x02) << 5) |
					((data & 0x04) << 3) |
					((data & 0x08) << 1);
	leland_80186_control_w(modified);
}