-
Notifications
You must be signed in to change notification settings - Fork 1.9k
/
dcs.cpp
2695 lines (2234 loc) · 80.7 KB
/
dcs.cpp
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
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// license:BSD-3-Clause
// copyright-holders:Aaron Giles
/***************************************************************************
Midway DCS Audio Board
****************************************************************************
There are several variations of this board, which was in use by
Midway and eventually Atari for almost 10 years.
DCS ROM-based mono:
* ADSP-2105 @ 10MHz
* single channel output
* 2k external shared program/data RAM
* ROM-based, up to 8MB total
* used in:
Mortal Kombat 2 (1993)
Cruisin' USA (1994)
Revolution X (1994)
Killer Instinct (1994)
Killer Instinct 2 (1995)
Cruisin' World (1996)
Offroad Challenge (1997)
* 8k external shared program/data RAM
* used in:
Mortal Kombat 3 (1994)
Ultimate Mortal Kombat 3 (1994)
2 On 2 Open Ice Challenge (1995)
WWF Wrestlemania (1995)
NBA Hangtime (1996)
NBA Maximum Hangtime (1996)
Rampage World Tour (1997)
DCS2 RAM-based stereo (Seattle):
* ADSP-2115 @ 16MHz
* dual channel output (stereo)
* SDRC ASIC for RAM/ROM access
* RAM-based, 2MB total
* used in:
War Gods (1995)
Wayne Gretzky's 3D Hockey (1996)
Mace: The Dark Age (1996)
Biofreaks (1997)
NFL Blitz (1997)
California Speed (1998)
Vapor TRX (1998)
NFL Blitz '99 (1998)
CarnEvil (1998)
Hyperdrive (1998)
NFL Blitz 2000 Gold (1999)
DCS2 ROM-based stereo (Zeus):
* ADSP-2104 @ 16MHz
* dual channel output (stereo)
* SDRC ASIC for RAM/ROM access
* ROM-based, up to 16MB total
* used in:
Mortal Kombat 4 (1997)
Invasion (1999)
Cruisin' Exotica (1999)
The Grid (2001)
DCS2 RAM-based stereo (Vegas):
* ADSP-2104 @ 16MHz
* dual channel output (stereo)
* SDRC ASIC for RAM/ROM access
* RAM-based, 4MB total
* used in:
Gauntlet Legends (1998)
Tenth Degree (1998)
Gauntlet Dark Legacy (1999)
War: The Final Assault (1999)
DCS2 RAM-based stereo (DSIO):
* ADSP-2181 @ 16.667MHz
* dual channel output (stereo)
* custom ASIC for RAM/ROM access
* RAM-based, 4MB total
* used in:
Road Burners (1999)
DCS2 RAM-based multi-channel (Denver):
* ADSP-2181 @ 16.667MHz
* 2-6 channel output
* custom ASIC for RAM/ROM access
* RAM-based, 4MB total
* used in:
San Francisco Rush: 2049 (1998)
Unknown other DCS boards:
* NBA Jam Extreme
* NBA Showtime
* NBA Showtime / NFL Blitz 2000 Gold
* Cart Fury
*****************************************************************************
SDRC (Sound DRAM Control) ASIC
* Boot ROM = 32k x 8
* Data ROM = Up to 16MB ROM (4 chip selects)
* SRAM = 32k x 24 or 8k x 24
* common map:
PGM 0800-0fff -> RAM 4800-4fff
PGM 1000-1fff -> RAM 5000-5fff
PGM 2000-2fff -> RAM 6000-6fff
PGM 3000-3fff -> RAM 7000-7fff
* bank = 0:
DATA 0800-0fff -> RAM 0800-0fff
DATA 1000-17ff -> RAM 0000-07ff
DATA 1800-1fff -> RAM 1800-1fff
DATA 2000-27ff -> RAM 1000-17ff
DATA 2800-2fff -> RAM 2800-2fff
DATA 3000-37ff -> RAM 2000-27ff
* bank = 1:
DATA 0800-0fff -> unmapped
DATA 1000-17ff -> unmapped
DATA 1800-1fff -> RAM 3800-3fff
DATA 2000-27ff -> RAM 3000-37ff
DATA 2800-2fff -> RAM 2800-2fff
DATA 3000-37ff -> RAM 2000-27ff
0480 (reset = XXX0 0X00 0X00 XX00)
15:13 = SMODE (write only)
12 = SM_BK (SRAM bank: 0 or 1)
11 = SM_EN (SRAM enable: 0=disabled, 1=enabled)
9:7 = ROM_PG (ROM page select: 0-7)
5 = ROM_MS (ROM memory select: 0=boot memory, 1=data memory)
4 = ROM_SZ (ROM area size: 0=4k words, 1=1k words)
1:0 = ROM_ST (ROM memory start: 0=0000, 1=3000, 2=3400, 3=none)
0481 (reset = 000X 00X0 0X00 XX00)
15 = AREF_ACT (read only, 1=DRAM auto refresh in progress)
14 = /MUTE (mute output)
13 = /LED (LED output)
11:10 = /RES_TFS (Reset TFS outputs: low bit = channel 1&2, high = channel 3&4)
8 = TFS_INV (TFS output polarity: 0=same, 1=inverted)
7 = DM_3WS (DRAM wait states: 0=2, 1=3)
5:4 = DM_REF (DRAM refresh: 0=disabled, 1=manual, 2=auto, 3=auto 2x)
1:0 = DM_ST (DRAM memory start: 0=none, 1=0000, 2=3000, 3=3400)
0482 (reset = XXX0 0000 0000 0000)
10:0 = DM_PG[10..0] (DRAM page)
12:0 = EPM_PG[12..0] (EPROM page [low 10 bits used for 4k pages])
0483 (reset = 1010 0000 1000 0001)
15:8 = SDRC_ID[7..0] (revision: 5A = ASIC version, A0 = FPGA version)
7 = SEC_D7
6 = SEC_D[6..1]
0 = SEC_D0
****************************************************************************/
#include "emu.h"
#include "dcs.h"
#define LOG_DCS_TRANSFERS (1U << 1)
#define LOG_DCS_IO (1U << 2)
#define VERBOSE (LOG_GENERAL)
#include "logmacro.h"
#define ENABLE_HLE_TRANSFERS (1)
/*************************************
*
* Constants
*
*************************************/
static constexpr uint16_t LCTRL_OUTPUT_EMPTY = 0x400;
static constexpr uint16_t LCTRL_INPUT_EMPTY = 0x800;
static constexpr const char *const denver_regname[4] = { "SDRC_ROM", "SDRC_IO", "RAM_PAGE", "VER/FIFO_RESET" };
#define IS_OUTPUT_EMPTY() (m_latch_control & LCTRL_OUTPUT_EMPTY)
#define IS_OUTPUT_FULL() (!(m_latch_control & LCTRL_OUTPUT_EMPTY))
#define SET_OUTPUT_EMPTY() (m_latch_control |= LCTRL_OUTPUT_EMPTY)
#define SET_OUTPUT_FULL() (m_latch_control &= ~LCTRL_OUTPUT_EMPTY)
#define IS_INPUT_EMPTY() (m_latch_control & LCTRL_INPUT_EMPTY)
#define IS_INPUT_FULL() (!(m_latch_control & LCTRL_INPUT_EMPTY))
#define SET_INPUT_EMPTY() (m_latch_control |= LCTRL_INPUT_EMPTY)
#define SET_INPUT_FULL() (m_latch_control &= ~LCTRL_INPUT_EMPTY)
// These are some of the control registers. We don't use them all
enum
{
IDMA_CONTROL_REG = 0, // 3fe0
BDMA_INT_ADDR_REG, // 3fe1
BDMA_EXT_ADDR_REG, // 3fe2
BDMA_CONTROL_REG, // 3fe3
BDMA_WORD_COUNT_REG, // 3fe4
PROG_FLAG_DATA_REG, // 3fe5
PROG_FLAG_CONTROL_REG, // 3fe6
S1_AUTOBUF_REG = 15, // 3fef
S1_RFSDIV_REG, // 3ff0
S1_SCLKDIV_REG, // 3ff1
S1_CONTROL_REG, // 3ff2
S0_AUTOBUF_REG, // 3ff3
S0_RFSDIV_REG, // 3ff4
S0_SCLKDIV_REG, // 3ff5
S0_CONTROL_REG, // 3ff6
S0_MCTXLO_REG, // 3ff7
S0_MCTXHI_REG, // 3ff8
S0_MCRXLO_REG, // 3ff9
S0_MCRXHI_REG, // 3ffa
TIMER_SCALE_REG, // 3ffb
TIMER_COUNT_REG, // 3ffc
TIMER_PERIOD_REG, // 3ffd
WAITSTATES_REG, // 3ffe
SYSCONTROL_REG // 3fff
};
// these macros are used to reference the SDRC ASIC
#define SDRC_ROM_ST ((m_sdrc.reg[0] >> 0) & 3) // 0=0000, 1=3000, 2=3400, 3=none
#define SDRC_ROM_SZ ((m_sdrc.reg[0] >> 4) & 1) // 0=4k, 1=1k
#define SDRC_ROM_MS ((m_sdrc.reg[0] >> 5) & 1) // 0=/BMS, 1=/DMS
#define SDRC_ROM_PG ((m_sdrc.reg[0] >> 7) & 7)
#define SDRC_SM_EN ((m_sdrc.reg[0] >> 11) & 1)
#define SDRC_SM_BK ((m_sdrc.reg[0] >> 12) & 1)
#define SDRC_SMODE ((m_sdrc.reg[0] >> 13) & 7)
#define SDRC_DM_ST ((m_sdrc.reg[1] >> 0) & 3) // 0=none, 1=0000, 2=3000, 3=3400
#define SDRC_DM_REF ((m_sdrc.reg[1] >> 4) & 3)
#define SDRC_DM_3WS ((m_sdrc.reg[1] >> 7) & 1)
#define SDRC_TFS_INV ((m_sdrc.reg[1] >> 8) & 1)
#define SDRC_RES_TFS ((m_sdrc.reg[1] >> 10) & 3)
#define SDRC_LED ((m_sdrc.reg[1] >> 13) & 1)
#define SDRC_MUTE ((m_sdrc.reg[1] >> 14) & 1)
#define SDRC_AREF_ACT ((m_sdrc.reg[1] >> 15) & 1)
#define SDRC_DM_PG ((m_sdrc.reg[2] >> 0) & 0x7ff)
#define SDRC_EPM_PG ((m_sdrc.reg[2] >> 0) & 0x1fff)
// these macros are used to reference the DSIO ASIC
#define DSIO_EMPTY_FIFO ((m_dsio.reg[1] >> 0) & 1)
#define DSIO_CUR_OUTPUT ((m_dsio.reg[1] >> 4) & 1)
#define DSIO_RES_TFS ((m_dsio.reg[1] >> 10) & 1)
#define DSIO_LED ((m_dsio.reg[1] >> 13) & 1)
#define DSIO_MUTE ((m_dsio.reg[1] >> 14) & 1)
#define DSIO_DM_PG ((m_dsio.reg[2] >> 0) & 0x1fff)
static constexpr int DSIO_BANK_END = 0x3ff;
// these macros are used to reference the DENVER ASIC
#define DENV_DSP_SPEED ((m_dsio.reg[1] >> 2) & 3) // read only: 1=33.33MHz
#define DENV_RES_TFS ((m_dsio.reg[1] >> 10) & 1)
#define DENV_CHANNELS ((m_dsio.reg[1] >> 11) & 3) // 0=2ch, 1=4ch, 2=6ch
#define DENV_LED ((m_dsio.reg[1] >> 13) & 1)
#define DENV_MUTE ((m_dsio.reg[1] >> 14) & 1)
#define DENV_DM_PG ((m_dsio.reg[2] >> 0) & 0x1fff)
static constexpr int DENV_NUM_BANK = 0x800;
/*************************************
*
* Original DCS Memory Maps
*
*************************************/
// DCS 2k memory map
void dcs_audio_device::dcs_2k_program_map(address_map &map)
{
map(0x0000, 0x03ff).ram().share(m_internal_program_ram);
map(0x0800, 0x0fff).ram().share(m_external_program_ram);
map(0x1000, 0x17ff).ram().share(m_external_program_ram);
map(0x1800, 0x1fff).ram().share(m_external_program_ram);
}
void dcs_audio_device::dcs_2k_data_map(address_map &map)
{
map(0x0000, 0x07ff).mirror(0x1800).rw(FUNC(dcs_audio_device::dcs_dataram_r), FUNC(dcs_audio_device::dcs_dataram_w));
map(0x2000, 0x2fff).bankr(m_data_bank);
map(0x3000, 0x33ff).w(FUNC(dcs_audio_device::dcs_data_bank_select_w));
map(0x3400, 0x37ff).rw(FUNC(dcs_audio_device::input_latch_r), FUNC(dcs_audio_device::output_latch_w));
map(0x3800, 0x39ff).ram();
map(0x3fe0, 0x3fff).rw(FUNC(dcs_audio_device::adsp_control_r), FUNC(dcs_audio_device::adsp_control_w));
}
// DCS 2k with UART memory map
void dcs_audio_device::dcs_2k_uart_data_map(address_map &map)
{
map(0x0000, 0x07ff).mirror(0x1800).rw(FUNC(dcs_audio_device::dcs_dataram_r), FUNC(dcs_audio_device::dcs_dataram_w));
map(0x2000, 0x2fff).bankr(m_data_bank);
map(0x3000, 0x33ff).w(FUNC(dcs_audio_device::dcs_data_bank_select_w));
map(0x3400, 0x3402).noprw(); // UART (ignored)
map(0x3403, 0x3403).rw(FUNC(dcs_audio_device::input_latch_r), FUNC(dcs_audio_device::output_latch_w));
map(0x3404, 0x3405).noprw(); // UART (ignored)
map(0x3800, 0x39ff).ram().share(m_iram);
map(0x3fe0, 0x3fff).rw(FUNC(dcs_audio_device::adsp_control_r), FUNC(dcs_audio_device::adsp_control_w));
}
// DCS 8k memory map
void dcs_audio_device::dcs_8k_program_map(address_map &map)
{
map(0x0000, 0x03ff).ram().share(m_internal_program_ram);
map(0x0800, 0x1fff).ram().share(m_external_program_ram);
map(0x3000, 0x3003).rw(FUNC(dcs_audio_device::input_latch32_r), FUNC(dcs_audio_device::output_latch32_w)); // why?
}
void dcs_audio_device::dcs_8k_data_map(address_map &map)
{
map(0x0000, 0x07ff).ram();
map(0x0800, 0x1fff).rw(FUNC(dcs_audio_device::dcs_dataram_r), FUNC(dcs_audio_device::dcs_dataram_w));
map(0x2000, 0x2fff).bankr(m_data_bank);
map(0x3000, 0x3000).w(FUNC(dcs_audio_device::dcs_data_bank_select_w));
map(0x3400, 0x3403).rw(FUNC(dcs_audio_device::input_latch_r), FUNC(dcs_audio_device::output_latch_w)); // mk3 etc. need this
map(0x3800, 0x39ff).ram().share(m_iram);
map(0x3fe0, 0x3fff).rw(FUNC(dcs_audio_device::adsp_control_r), FUNC(dcs_audio_device::adsp_control_w));
}
// Williams WPC DCS/Security Pinball
void dcs_audio_device::dcs_wpc_program_map(address_map &map)
{
map(0x0000, 0x03ff).ram().share(m_internal_program_ram);
map(0x1000, 0x3fff).ram().share(m_external_program_ram);
}
void dcs_audio_wpc_device::dcs_wpc_data_map(address_map &map)
{
map(0x0000, 0x07ff).bankr(m_data_bank);
map(0x1000, 0x2fff).rw(FUNC(dcs_audio_wpc_device::dcs_dataram_r), FUNC(dcs_audio_wpc_device::dcs_dataram_w));
map(0x3000, 0x3000).w(FUNC(dcs_audio_wpc_device::dcs_data_bank_select_w));
map(0x3100, 0x3100).w(FUNC(dcs_audio_wpc_device::dcs_data_bank_select2_w));
map(0x3300, 0x3303).rw(FUNC(dcs_audio_wpc_device::input_latch_r), FUNC(dcs_audio_wpc_device::output_latch_w));
map(0x3800, 0x39ff).ram().share(m_iram);
map(0x3fe0, 0x3fff).rw(FUNC(dcs_audio_wpc_device::adsp_control_r), FUNC(dcs_audio_wpc_device::adsp_control_w));
}
/*************************************
*
* DCS2 Memory Maps
*
*************************************/
void dcs_audio_device::dcs2_2115_program_map(address_map &map)
{
map.unmap_value_high();
map(0x0000, 0x03ff).ram().share(m_internal_program_ram);
}
void dcs_audio_device::dcs2_2104_program_map(address_map &map)
{
map.unmap_value_high();
map(0x0000, 0x01ff).ram().share(m_internal_program_ram);
}
void dcs_audio_device::dcs2_2115_data_map(address_map &map)
{
map.unmap_value_high();
map(0x0400, 0x0400).rw(FUNC(dcs_audio_device::input_latch_r), FUNC(dcs_audio_device::input_latch_ack_w));
map(0x0401, 0x0401).w(FUNC(dcs_audio_device::output_latch_w));
map(0x0402, 0x0402).rw(FUNC(dcs_audio_device::output_control_r), FUNC(dcs_audio_device::output_control_w));
map(0x0403, 0x0403).r(FUNC(dcs_audio_device::latch_status_r));
map(0x0404, 0x0407).r(FUNC(dcs_audio_device::fifo_input_r));
map(0x0480, 0x0483).rw(FUNC(dcs_audio_device::sdrc_r), FUNC(dcs_audio_device::sdrc_w));
map(0x3800, 0x39ff).ram().share(m_iram);
map(0x3fe0, 0x3fff).rw(FUNC(dcs_audio_device::adsp_control_r), FUNC(dcs_audio_device::adsp_control_w));
}
void dcs_audio_device::dcs2_2104_data_map(address_map &map)
{
map.unmap_value_high();
map(0x0400, 0x0400).rw(FUNC(dcs_audio_device::input_latch_r), FUNC(dcs_audio_device::input_latch_ack_w));
map(0x0401, 0x0401).w(FUNC(dcs_audio_device::output_latch_w));
map(0x0402, 0x0402).rw(FUNC(dcs_audio_device::output_control_r), FUNC(dcs_audio_device::output_control_w));
map(0x0403, 0x0403).r(FUNC(dcs_audio_device::latch_status_r));
map(0x0404, 0x0407).r(FUNC(dcs_audio_device::fifo_input_r));
map(0x0480, 0x0483).rw(FUNC(dcs_audio_device::sdrc_r), FUNC(dcs_audio_device::sdrc_w));
map(0x3800, 0x39ff).ram().share(m_iram);
map(0x3fe0, 0x3fff).rw(FUNC(dcs_audio_device::adsp_control_r), FUNC(dcs_audio_device::adsp_control_w));
}
/*************************************
*
* DSIO Memory Maps
*
*************************************/
void dcs_audio_device::dsio_program_map(address_map &map)
{
map.unmap_value_high();
map(0x0000, 0x3fff).ram().share(m_internal_program_ram);
}
void dcs_audio_device::dsio_data_map(address_map &map)
{
map.unmap_value_high();
map(0x0000, 0x1fff).m(m_ram_map, FUNC(address_map_bank_device::amap16));
map(0x2000, 0x3fdf).ram().share(m_internal_data_ram);
map(0x3fe0, 0x3fff).rw(FUNC(dcs_audio_device::adsp_control_r), FUNC(dcs_audio_device::adsp_control_w));
}
void dcs_audio_device::dsio_rambank_map(address_map &map)
{
map(0x0000, 0x1fff).ram();
map(0x2000, 0x3fff).bankrw(m_data_bank);
}
void dcs_audio_device::dsio_io_map(address_map &map)
{
map.unmap_value_high();
map(0x0400, 0x0400).rw(FUNC(dcs_audio_device::input_latch_r), FUNC(dcs_audio_device::input_latch_ack_w));
map(0x0401, 0x0401).w(FUNC(dcs_audio_device::output_latch_w));
map(0x0402, 0x0402).rw(FUNC(dcs_audio_device::output_control_r), FUNC(dcs_audio_device::output_control_w));
map(0x0403, 0x0403).r(FUNC(dcs_audio_device::latch_status_r));
map(0x0404, 0x0407).r(FUNC(dcs_audio_device::fifo_input_r));
map(0x0480, 0x0483).rw(FUNC(dcs_audio_device::dsio_r), FUNC(dcs_audio_device::dsio_w));
}
/*************************************
*
* Denver Memory Maps
*
*************************************/
void dcs_audio_device::denver_program_map(address_map &map)
{
map.unmap_value_high();
map(0x0000, 0x3fff).ram().share(m_internal_program_ram);
}
void dcs_audio_device::denver_data_map(address_map &map)
{
map.unmap_value_high();
map(0x0000, 0x1fff).m(m_ram_map, FUNC(address_map_bank_device::amap16));
map(0x2000, 0x3fdf).ram().share(m_internal_data_ram);
map(0x3fe0, 0x3fff).rw(FUNC(dcs_audio_device::adsp_control_r), FUNC(dcs_audio_device::adsp_control_w));
}
void dcs_audio_device::denver_rambank_map(address_map &map)
{
map(0x0000, 0x3fff).ram();
map(0x4000, 0x7fff).bankrw(m_data_bank);
}
void dcs_audio_device::denver_io_map(address_map &map)
{
map.unmap_value_high();
map(0x0400, 0x0400).rw(FUNC(dcs_audio_device::input_latch_r), FUNC(dcs_audio_device::input_latch_ack_w));
map(0x0401, 0x0401).w(FUNC(dcs_audio_device::output_latch_w));
map(0x0402, 0x0402).rw(FUNC(dcs_audio_device::output_control_r), FUNC(dcs_audio_device::output_control_w));
map(0x0403, 0x0403).r(FUNC(dcs_audio_device::latch_status_r));
map(0x0404, 0x0407).r(FUNC(dcs_audio_device::fifo_input_r));
map(0x0480, 0x0483).rw(FUNC(dcs_audio_device::denver_r), FUNC(dcs_audio_device::denver_w));
}
/*************************************
*
* ADSP booting
*
*************************************/
void dcs_audio_device::dcs_boot()
{
switch (m_rev)
{
// rev 1/1.5: use the last set data bank to boot from
case REV_DCS1:
case REV_DCS1P5:
{
// determine the base
// max_banks = m_bootrom.length() / 0x1000;
uint16_t const *const base = &m_bootrom[(m_sounddata_bank * 0x1000) % m_bootrom.length()];
// convert from 16-bit data to 8-bit data and boot
uint8_t buffer[0x1000];
for (int i = 0; i < 0x1000; i++)
{
buffer[i] = base[i];
}
assert(m_internal_program_ram);
m_cpu->load_boot_data(buffer, &m_internal_program_ram[0]);
break;
}
// rev 2: use the ROM page in the SDRC to boot from
case REV_DCS2:
{
// determine the base
uint16_t* base;
if (m_bootrom.target() == m_sounddata)
{
// EPROM case: page is selected from the page register
base = &m_bootrom[(SDRC_EPM_PG * 0x1000) % m_bootrom.length()];
}
else
{
// DRAM case: page is selected from the ROM page register
base = &m_bootrom[(SDRC_ROM_PG * 0x1000) % m_bootrom.length()];
}
// convert from 16-bit data to 8-bit data and boot
uint8_t buffer[0x1000];
for (int i = 0; i < 0x1000; i++)
{
buffer[i] = base[i];
}
assert(m_internal_program_ram);
m_cpu->load_boot_data(buffer, &m_internal_program_ram[0]);
break;
}
// rev 3/4: HALT the ADSP-2181 until program is downloaded via IDMA
case REV_DSIO:
case REV_DENV:
m_cpu->set_input_line(INPUT_LINE_HALT, ASSERT_LINE);
m_dsio.start_on_next_write = 0;
break;
}
}
/*************************************
*
* System reset
*
*************************************/
TIMER_CALLBACK_MEMBER( dcs_audio_device::dcs_reset )
{
LOGMASKED(LOG_DCS_IO, "dcs_reset\n");
// reset the memory banking
switch (m_rev)
{
// rev 1/1.5: just reset the bank to 0
case REV_DCS1:
case REV_DCS1P5:
m_sounddata_bank = 0;
m_data_bank->set_entry(0);
break;
// rev 2: reset the SDRC ASIC
case REV_DCS2:
sdrc_reset();
break;
// rev 3: reset the DSIO ASIC
case REV_DSIO:
dsio_reset();
break;
// rev 4: reset the Denver ASIC
case REV_DENV:
denver_reset();
break;
}
// initialize our state structure and install the transmit callback
m_size = 0;
m_incs = 0;
m_ireg = 0;
// initialize the ADSP control regs
memset(m_control_regs, 0, sizeof(m_control_regs));
// clear all interrupts
m_cpu->set_input_line(ADSP2105_IRQ0, CLEAR_LINE);
m_cpu->set_input_line(ADSP2105_IRQ1, CLEAR_LINE);
m_cpu->set_input_line(ADSP2105_IRQ2, CLEAR_LINE);
// initialize the comm bits
SET_INPUT_EMPTY();
SET_OUTPUT_EMPTY();
if (!m_last_input_empty && !m_input_empty_cb.isnull())
m_input_empty_cb(m_last_input_empty = 1);
if (m_last_output_full && !m_output_full_cb.isnull())
m_output_full_cb(m_last_output_full = 0);
// boot
dcs_boot();
// reset timers
m_timer_ignore = false;
m_timer_enable = 0;
m_timer_scale = 1;
m_internal_timer->reset();
// reset the HLE transfer states
m_transfer.dcs_state = m_transfer.state = 0;
}
/*************************************
*
* System setup
*
*************************************/
void dcs_audio_device::dcs_register_state()
{
save_item(NAME(m_sdrc.reg));
save_item(NAME(m_sdrc.seed));
save_item(NAME(m_dsio.reg));
save_item(NAME(m_dsio.start_on_next_write));
save_item(NAME(m_dsio.channelbits));
save_item(NAME(m_channels));
save_item(NAME(m_size));
save_item(NAME(m_incs));
save_item(NAME(m_ireg));
save_item(NAME(m_ireg_base));
save_item(NAME(m_control_regs));
save_item(NAME(m_sounddata_bank));
save_item(NAME(m_dmovlay_val));
save_item(NAME(m_auto_ack));
save_item(NAME(m_latch_control));
save_item(NAME(m_input_data));
save_item(NAME(m_output_data));
save_item(NAME(m_output_control));
save_item(NAME(m_output_control_cycles));
save_item(NAME(m_last_output_full));
save_item(NAME(m_last_input_empty));
save_item(NAME(m_progflags));
save_item(NAME(m_timer_enable));
save_item(NAME(m_timer_ignore));
save_item(NAME(m_timer_start_cycles));
save_item(NAME(m_timer_start_count));
save_item(NAME(m_timer_scale));
save_item(NAME(m_timer_period));
save_item(NAME(m_timers_fired));
save_item(NAME(m_transfer.dcs_state));
save_item(NAME(m_transfer.state));
save_item(NAME(m_transfer.start));
save_item(NAME(m_transfer.stop));
save_item(NAME(m_transfer.type));
save_item(NAME(m_transfer.temp));
save_item(NAME(m_transfer.writes_left));
save_item(NAME(m_transfer.sum));
save_item(NAME(m_transfer.fifo_entries));
save_item(NAME(m_polling_value));
save_item(NAME(m_polling32_value));
if (m_sram != nullptr)
save_pointer(NAME(m_sram), 0x8000*4 / sizeof(m_sram[0]));
if (m_rev == REV_DCS2)
machine().save().register_postload(save_prepost_delegate(FUNC(dcs_audio_device::sdrc_remap_memory), this));
if (m_rev == REV_DENV)
machine().save().register_postload(save_prepost_delegate(FUNC(dcs_audio_device::denver_postload), this));
}
void dcs_audio_device::denver_postload()
{
m_data_bank->set_entry(DENV_DM_PG % m_sounddata_banks);
dmovlay_remap_memory();
denver_alloc_dmadac();
install_speedup();
}
//-------------------------------------------------
// dcs_audio_device - constructor
//-------------------------------------------------
dcs_audio_device::dcs_audio_device(const machine_config &mconfig, device_type type, const char *tag, device_t *owner, uint32_t clock, int rev, int outputs) :
device_t(mconfig, type, tag, owner, clock),
device_mixer_interface(mconfig, *this, outputs),
m_maincpu(*this, finder_base::DUMMY_TAG),
m_reg_timer(*this, "dcs_reg_timer"),
m_sport0_timer(*this, "dcs_sport0_timer"),
m_internal_timer(*this, "dcs_int_timer"),
m_ram_map(*this, "data_map_bank"),
m_bootrom(*this, DEVICE_SELF),
m_internal_program_ram(*this, "dcsint"),
m_external_program_ram(*this, "dcsext"),
m_internal_data_ram(*this, "dcsint_data"),
m_iram(*this, "iram"),
m_data_bank(*this, "databank"),
m_rom_page(*this, "rompage"),
m_dram_page(*this, "drampage"),
m_cpu(nullptr),
m_program(nullptr),
m_data(nullptr),
m_rev(rev),
m_polling_offset(0),
m_polling_count(0),
m_channels(0),
m_size(0),
m_incs(0),
m_ireg(0),
m_ireg_base(0),
m_sounddata(nullptr),
m_sounddata_words(0),
m_sounddata_banks(0),
m_sounddata_bank(0),
m_auto_ack(0),
m_latch_control(0),
m_input_data(0),
m_output_data(0),
m_output_control(0),
m_output_control_cycles(0),
m_last_output_full(0),
m_last_input_empty(0),
m_progflags(0),
m_output_full_cb(*this),
m_input_empty_cb(*this),
m_fifo_data_r(*this),
m_fifo_status_r(*this),
m_fifo_reset_w(*this),
m_timer_enable(0),
m_timer_ignore(false),
m_timer_start_cycles(0),
m_timer_start_count(0),
m_timer_scale(0),
m_timer_period(0),
m_timers_fired(0),
m_sram(nullptr),
m_dram_in_mb(0)
{
m_dmadac[0] = m_dmadac[1] = m_dmadac[2] = m_dmadac[3] = m_dmadac[4] = m_dmadac[5] = nullptr;
memset(m_control_regs, 0, sizeof(m_control_regs));
memset(&m_sdrc, 0, sizeof(m_sdrc));
memset(&m_dsio, 0, sizeof(m_dsio));
memset(&m_transfer, 0, sizeof(m_transfer));
}
void dcs_audio_device::device_reset()
{
dcs_reset(0);
m_s1_ack_timer->adjust(attotime::never);
m_s1_ack2_timer->adjust(attotime::never);
m_s2_ack_timer->adjust(attotime::never);
}
void dcs_audio_device::device_start()
{
m_sram = nullptr;
// find the DCS CPU and the sound ROMs
m_cpu = subdevice<adsp21xx_device>("dcs");
if (m_cpu != nullptr && !m_cpu->started())
throw device_missing_dependencies();
m_program = &m_cpu->space(AS_PROGRAM);
m_data = &m_cpu->space(AS_DATA);
m_channels = 1;
m_dmadac[0] = subdevice<dmadac_sound_device>("dac");
// configure boot and sound ROMs
m_sounddata = m_bootrom.target();
m_sounddata_words = m_bootrom.length();
if (m_rev == REV_DCS1)
{
m_sounddata_banks = m_sounddata_words / 0x1000;
m_data_bank->configure_entries(0, m_sounddata_banks, m_sounddata, 0x1000*2);
}
else
{
m_sounddata_banks = m_sounddata_words / 0x800;
m_data_bank->configure_entries(0, m_sounddata_banks, m_sounddata, 0x800*2);
}
// allocate timers
m_s1_ack_timer = timer_alloc(FUNC(dcs_audio_device::s1_ack_callback1), this);
m_s1_ack2_timer = timer_alloc(FUNC(dcs_audio_device::s1_ack_callback2), this);
m_s2_ack_timer = timer_alloc(FUNC(dcs_audio_device::s2_ack_callback), this);
// non-RAM based automatically acks
m_auto_ack = true;
// register for save states
dcs_register_state();
// reset the system
dcs_reset(0);
}
void dcs2_audio_device::device_start()
{
int soundbank_words;
// find the DCS CPU and the sound ROMs
m_cpu = subdevice<adsp21xx_device>("dcs2");
m_rev = REV_DCS2;
soundbank_words = 0x1000;
if (m_cpu == nullptr)
{
m_cpu = subdevice<adsp21xx_device>("dsio");
m_rev = REV_DSIO;
soundbank_words = DSIO_BANK_END + 1;
}
if (m_cpu == nullptr)
{
m_cpu = subdevice<adsp21xx_device>("denver");
m_rev = REV_DENV;
soundbank_words = ((m_dram_in_mb << 20) / 2) / DENV_NUM_BANK;
}
if (m_cpu != nullptr && !m_cpu->started())
throw device_missing_dependencies();
m_program = &m_cpu->space(AS_PROGRAM);
m_data = &m_cpu->space(AS_DATA);
m_channels = 2;
m_dmadac[0] = subdevice<dmadac_sound_device>("dac1");
m_dmadac[1] = subdevice<dmadac_sound_device>("dac2");
// supports both RAM and ROM variants
if (m_dram_in_mb != 0)
{
m_sounddata_words = (m_dram_in_mb << 20) / 2;
m_sounddata_ptr = std::make_unique<uint16_t[]>(m_sounddata_words);
m_sounddata = m_sounddata_ptr.get();
save_pointer(NAME(m_sounddata), m_sounddata_words);
}
else
{
m_sounddata = m_bootrom.target();
m_sounddata_words = m_bootrom.length();
}
m_sounddata_banks = m_sounddata_words / soundbank_words;
if (m_rev != REV_DCS2)
{
if (m_ram_map)
m_ram_map->set_bank(0);
m_data_bank->configure_entries(0, m_sounddata_banks, m_sounddata, soundbank_words * 2);
LOG("device_start: audio ram banks: %x size: %x\n", m_sounddata_banks, soundbank_words);
}
// allocate memory for the SRAM
m_sram = std::make_unique<uint16_t[]>(0x8000*4/2);
// we don't do auto-ack by default
m_auto_ack = false;
// install the speedup handler
install_speedup();
// allocate a watchdog timer for HLE transfers
m_transfer.hle_enabled = (ENABLE_HLE_TRANSFERS && m_dram_in_mb != 0 && m_rev < REV_DSIO);
if (m_transfer.hle_enabled)
m_transfer.watchdog = subdevice<timer_device>("dcs_hle_timer");
// allocate timers
m_s1_ack_timer = timer_alloc(FUNC(dcs2_audio_device::s1_ack_callback1), this);
m_s1_ack2_timer = timer_alloc(FUNC(dcs2_audio_device::s1_ack_callback2), this);
m_s2_ack_timer = timer_alloc(FUNC(dcs2_audio_device::s2_ack_callback), this);
// register for save states
dcs_register_state();
// reset the system
dcs_reset(0);
}
void dcs_audio_device::install_speedup()
{
if (m_polling_offset)
{
if (m_rev < REV_DSIO)
{
m_cpu->space(AS_DATA).install_read_handler(m_polling_offset, m_polling_offset, read16mo_delegate(*this, FUNC(dcs_audio_device::dcs_polling_r)));
m_cpu->space(AS_DATA).install_write_handler(m_polling_offset, m_polling_offset, write16s_delegate(*this, FUNC(dcs_audio_device::dcs_polling_w)));
}
else
{
// ADSP 2181 (DSIO and DENVER) use program memory
m_cpu->space(AS_PROGRAM).install_read_handler(m_polling_offset, m_polling_offset, read32mo_delegate(*this, FUNC(dcs_audio_device::dcs_polling32_r)));
m_cpu->space(AS_PROGRAM).install_write_handler(m_polling_offset, m_polling_offset, write32s_delegate(*this, FUNC(dcs_audio_device::dcs_polling32_w)));
// DSIO and DENVER poll in two spots. This offset covers all three machines (mwskins, sf2049, roadburn).
m_cpu->space(AS_PROGRAM).install_read_handler(m_polling_offset + 9, m_polling_offset + 9, read32mo_delegate(*this, FUNC(dcs_audio_device::dcs_polling32_r)));
m_cpu->space(AS_PROGRAM).install_write_handler(m_polling_offset + 9, m_polling_offset + 9, write32s_delegate(*this, FUNC(dcs_audio_device::dcs_polling32_w)));
}
}
}
void dcs_audio_device::set_auto_ack(int state)
{
m_auto_ack = state;
}
/*************************************
*
* Original DCS read/write handlers
*
*************************************/
uint16_t dcs_audio_device::dcs_dataram_r(offs_t offset)
{
assert(m_external_program_ram != nullptr);
return m_external_program_ram[offset] >> 8;
}
void dcs_audio_device::dcs_dataram_w(offs_t offset, uint16_t data, uint16_t mem_mask)
{
assert(m_external_program_ram != nullptr);
uint16_t val = m_external_program_ram[offset] >> 8;
COMBINE_DATA(&val);
m_external_program_ram[offset] = (val << 8) | (m_external_program_ram[offset] & 0x0000ff);
}
void dcs_audio_device::dcs_data_bank_select_w(uint16_t data)
{
if (m_rev != REV_DCS1P5)
m_sounddata_bank = data & 0x7ff;
else
m_sounddata_bank = (m_sounddata_bank & 0xff00) | (data & 0xff);
m_data_bank->set_entry(m_sounddata_bank % m_sounddata_banks);
// bit 11 = sound board led
#if 0
if (m_rev != REV_DCS1P5)
output().set_led_value(2, data & 0x800);
#endif
}
void dcs_audio_device::dcs_data_bank_select2_w(uint16_t data)
{
m_sounddata_bank = (m_sounddata_bank & 0x00ff) | ((data & 0x01) << 8) | ((data & 0xfc) << 7);
m_data_bank->set_entry(m_sounddata_bank % m_sounddata_banks);
}
/*************************************
*
* SDRC ASIC Memory handling
*
*************************************/
void dcs_audio_device::sdrc_update_bank_pointers()
{
if (SDRC_SM_EN != 0)
{
int const pagesize = (SDRC_ROM_SZ == 0 && SDRC_ROM_ST != 0) ? 4096 : 1024;
// update the bank pointer based on whether we are ROM-based or RAM-based
if (m_bootrom.target() == m_sounddata)
{
// ROM-based; use the memory page to select from ROM
if (SDRC_ROM_MS == 1 && SDRC_ROM_ST != 3)
{
m_rom_page->set_base(&m_sounddata[(SDRC_EPM_PG * pagesize) % m_sounddata_words]);
}
}
else
{
// RAM-based; use the ROM page to select from ROM, and the memory page to select from RAM
if (SDRC_ROM_MS == 1 && SDRC_ROM_ST != 3)
{
m_rom_page->set_base(&m_bootrom[(SDRC_ROM_PG * 4096 /*pagesize*/) % m_bootrom.length()]);
}
if (SDRC_DM_ST != 0)
{
m_dram_page->set_base(&m_sounddata[(SDRC_DM_PG * 1024) % m_sounddata_words]);
}
}
}
}
void dcs_audio_device::sdrc_remap_memory()
{
if (SDRC_SM_EN == 0)
{
// if SRAM disabled, clean it out
m_program->unmap_readwrite(0x0800, 0x3fff);
m_data->unmap_readwrite(0x0800, 0x37ff);
}
else
{
// otherwise, map the SRAM
// first start with a clean program map
m_program->install_ram(0x0800, 0x3fff, &m_sram[0x4800]);