summaryrefslogtreecommitdiffstatshomepage
path: root/src/mame/drivers/konamim2.cpp
blob: 28f2ac63b1960b9b267832679e9cf1397b3d47d6 (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
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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
// license:BSD-3-Clause
// copyright-holders:Phil Bennett

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

    Konami M2 hardware

    driver by Phil Bennett

    TODO:
    * Fix Heat of Eleven '98 soft-lock when selecting Japan as a team
    * Fix incorrect speed in Tobe! Polystars
    * Fix texture compression
    * Sort out CD images
    * Fix PowerPC 602 Protection Only mode handling.

    DONE
    * Fix Polystars blending
    * Fix missing music in Polystars
    * Fix music playing too early
    * Fix missing music and sound in Hell Night/Evil Night
    * Fix incorrect speed in Heat of 11 and Total Vice (partially)

    // Polystars/Total Vice
    if (pc == 0x40035958)
        gpr[11] = 1;

    // Everything else
    if (pc == 0x400385c8)
        gpr[11] = 0;




Konami M2 Hardware Overview
Konami, 1997-1998

This hardware is 3DO-based with two IBM Power PC CPUs.

There were only 5 known games on this hardware. They include....

Game                                                 Year    CD Codes                                  Konami Part#
-------------------------------------------------------------------------------------------------------------------
Battle Tryst                                         1998    636JAC02
Evil Night                                           1998    810UBA02
Hell Night (alt. Region title, same as Evil Night)   1998    810EAA02
Heat Of Eleven '98                                   1998    703EAA02
Tobe! Polystars                                      1997    623JAA02                                  003894
Total Vice                                           1997    639UAC01, 639EAD01, 639JAD01, 639AAB01


PCB Layouts
-----------

Top Board

[M]DFUP0882ZAM1
FZ-20B1AK 7BKSA03500 (sticker)
|---------------------------------------------------|
|            |--------------------|    |----------| |
|            |--------------------|    |----------| |
|    2902             |---|  |--------|             |
| AK4309 CY2292S|---| |*2 |  |  3DO   |  |-------|  |
|               |*1 | |---|  |        |  |IBM    |  |
|        18MHz  |---|        |        |  |POWERPC|  |
|                            |        |  |602    |  |
|                            |--------|  |-------|  |
|    D4516161  D4516161                             |
|                                 |---|  |-------|  |
|DSW                    |-------| |*3 |  |IBM    |  |
|                       |       | |---|  |POWERPC|  |
|    D4516161  D4516161 |  *4   |        |602    |  |
|                       |       |        |-------|  |
|                       |-------|                   |
|---------------------------------------------------|
Notes:
      AK4309  - Asahi Kasei Microsystems AK4309-VM Digital to Analog Converter (SOIC24)
      2902    - Japan Radio Co. JRC2902 Quad Operational Amplifier (SOIC14)
      CY2292S - Cypress CY2292S Three-PLL General-Purpose EPROM Programmable Clock Generator (SOIC16)
                XTALIN - 18.000MHz, XTALOUT - 18.000MHz, XBUF - 18.000MHz, CPUCLK - 25.2000MHz
                CLKA - , CLKB -  , CLKC - 16.9345MHz, CLKD -
      3DO     - 9701 B861131 VY21118- CDE2 3DO 02473-001-0F (QFP208)
      *1      - [M] JAPAN ASUKA 9651HX001 044 (QFP44)
      *2      - Motorola MC44200FT
      *3      - [M] BIG BODY 2 BU6244KS 704 157 (QFP56)
      *4      - Unknown BGA chip (Graphics Engine, with heatsink attached)
      DSW     - 2 position DIP switch


Bottom Board

PWB403045B (C) 1997 KONAMI CO., LTD.
|----------------------------------------------------------|
|           CN16    |--------------------|    |----------| |
|LA4705             |--------------------|    |----------| |
|       NJM5532D                    9.83MHz                |
|                                   19.66MHz               |
|J                |--------|   93C46.7K                    |-|
|A                | 058232 |                BOOTROM.8Q     | |
|M                |--------|   |------|                    | |
|M       |------|              |003461|                    | |
|A       |056879|              |      |                    | |CN15
|        |      |              |------|                    | |
| TEST   |------|                                          | |
|                                                          | |
|   DSW                                                    | |
|                                                          |-|
|                                                          |
|----------------------------------------------------------|
Notes:
      056879     - Konami custom IC, location 10E (QFP120)
      058232     - Konami custom ceramic flat pack IC, DAC?
      003461     - Konami custom IC, location 11K (QFP100)
      CN16       - 4 pin connector for CD-DA in from CDROM
      CN15       - Standard (PC-compatible) 40 pin IDE CDROM flat cable connector and 4 pin power plug connector,
                   connected to Panasonic CR-583 8-speed CDROM drive.
      LA4705     - LA4705 Power Amplifier
      DSW        - 8 position dip switch
      BOOTROM.8Q - 16MBit MASKROM. Location 8Q (DIP42)
                   Battle Tryst       - 636A01.8Q
                   Evil Night         -       .8Q
                   Heat Of Eleven '98 -       .8Q
                   Polystars          - 623B01.8Q
                   Total Vice         -       .8Q
      93C46.7K   - 128bytes x8bit Serial EEPROM. Location 7K (DIP8)
                   NOTE! There is very mild protection to stop game-swapping. It is based on the information in the EEPROM
                   being the same as the Time Keeper NVRAM.
                   For example, in Evil Night, the first line of the NVRAM in hex is 474E38313000000019984541410002A601FEFE01
                   Looking at it in ascii:  GN810.....EAA.......
                   Hex 474E383130 = GN810
                   1998 = the year of the game
                   Hex 454141 = EAA (the version = europe english)
                   The numbers after this appear to be unimportant (at least with regards to swapping games anyway).
                   All the other data after the first line is used for high scores tables etc.
                   The important part is that the data in the EEPROM should be the same as the NVRAM, but the EEPROM data
                   is byte-swapped! If the two don't match, the check on 7K or the NVRAM will fail and the PCB will reboot
                   forever.

Some lower boards have two connectors underneath for a protection sub-board or sound board. These are detailed below....

GX636-PWB(A) (C) 1997 KONAMI CO., LTD.
|-------------------------|
| CN4 CN3  |---------|    |
|          |---------|CN2 |
|          PAL            |
|                         |
|             NVRAM       |
|                         |
|          |---------|    |
|          |---------|CN1 |
|-------------------------|
Notes:
      NVRAM  - With Heat of Eleven '98, uses Dallas DS1643 NonVolatile TimeKeeping RAM
               With Battle Tryst, uses ST M48T58Y-70PC1 NonVolatile TimeKeeping RAM
               With Poly Stars, a sub board is not used at all
      PAL    - PALCE16V8Q, stamped 'X636A1'
      CN3    - 4-pin sound cable tied to CN16 (CD-DA Input) on main lower board
      CN4    - 4-pin sound cable tied to CDROM analog audio output connector

GQ639 PWB 403327(A)
|-----------------------------------------|
|       639JAA02.xx                       |
|                                         |
|                                         |
|                   |---------|           |
|                   |---------|           |
|                                         |
|                                         |
|               PAL                       |
|                                         |
|                                         |
|                                         |
|                                         |
|                   |---------|           |
|      YMZ280B      |---------|           |
|                                         |
|      16.9344MHz                         |
|                                         |
|                                         |
|-----------------------------------------|
Notes:
      This PCB is used on Total Vice only.
      639JAA02.xx - 8MBit Sound data ROM (DIP42)
      PAL         - PAL16V8H stampd '       '


PWB0000047043 (C) 1998 KONAMI CO., LTD.
|-----------------------------------------|
| CN4     CN3                             |
|                                         |
|                                         |
|                   |---------|           |
|                   |---------|           |
|        16.9344MHz              M48T58Y  |
|                      PAL                |
|          YMZ280B                        |
|                                         |
|                                         |
|                                         |
|                                         |
|                   |---------|           |
|                   |---------|           |
|                                         |
|                                         |
|                                         |
|              810A03.16H                 |
|-----------------------------------------|
Notes:
      This PCB is used on Evil Night/Hell Night only.
      810A03.16H - 16MBit Sound data ROM (DIP42, byte mode)
      PAL        - PAL16V8H stamped 'N810B1'
      M48T58Y    - ST M48T58Y-70PC1 NonVolatile TimeKeeping RAM
      CN3        - 4-pin sound cable tied to CN16 (CD-DA Input) on main lower board
      CN4        - 4-pin sound cable tied to CDROM analog audio output connector

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

#include "emu.h"
#include "cpu/powerpc/ppc.h"
#include "bus/ata/ataintf.h"
#include "bus/ata/cr589.h"
#include "machine/3dom2.h"
#include "machine/eepromser.h"
#include "machine/timekpr.h"
#include "sound/dac.h"
#include "sound/volt_reg.h"
#include "sound/ymz280b.h"
#include "cdrom.h"
#include "debug/debugcon.h"
#include "debug/debugcmd.h"
#include "debugger.h"
#include "romload.h"
#include "screen.h"
#include "speaker.h"

#define M2_CLOCK        XTAL(66'666'700)

#define ENABLE_SDBG     0


/*************************************
 *
 *  ROM definition(s)
 *
 *************************************/

class konamim2_state : public driver_device
{
public:
	konamim2_state(const machine_config &mconfig, device_type type, const char *tag) :
		driver_device(mconfig, type, tag),
		m_ppc1(*this, "ppc1"),
		m_ppc2(*this, "ppc2"),
		m_bda(*this, "bda"),
		m_cde(*this, "cde"),
		m_eeprom(*this, "eeprom"),
		m_ldac(*this, "ldac"),
		m_rdac(*this, "rdac"),
		m_ata(*this, "ata"),
		m_screen(*this, "screen"),
		m_m48t58(*this, "m48t58"),
		m_ymz280b(*this, "ymz")
	{
	}

	void konamim2(machine_config &config);
	void set_ntsc(machine_config &config);
	void set_ntsc2(machine_config &config);
	void set_arcres(machine_config &config);
	void add_ymz280b(machine_config &config);
	void add_mt48t58(machine_config &config);
	void polystar(machine_config &config);
	void totlvice(machine_config &config);
	void btltryst(machine_config &config);
	void heatof11(machine_config &config);
	void evilngt(machine_config &config);
	void hellngt(machine_config &config);

	static void cr589_config(device_t *device);

	void m2_map(address_map &map);

protected:
	virtual void machine_start() override;
	virtual void machine_reset() override;

	void update_disc();

public:
	DECLARE_WRITE_LINE_MEMBER(ppc1_int);
	DECLARE_WRITE_LINE_MEMBER(ppc2_int);

	void cde_sdbg_out(uint32_t data);

	void ldac_out(uint16_t data);
	void rdac_out(uint16_t data);

	DECLARE_WRITE_LINE_MEMBER(ata_int);

	DECLARE_READ16_MEMBER(konami_io0_r);
	DECLARE_WRITE16_MEMBER(konami_io0_w);
	DECLARE_READ16_MEMBER(konami_sio_r);
	DECLARE_WRITE16_MEMBER(konami_sio_w);
	DECLARE_READ16_MEMBER(konami_io1_r);
	DECLARE_WRITE16_MEMBER(konami_io1_w);
	DECLARE_WRITE16_MEMBER(konami_eeprom_w);

	void init_totlvice();
	void init_btltryst();
	void init_hellngt();

	DECLARE_WRITE16_MEMBER(konami_atapi_unk_w)
	{
		// 8000 = /Reset
		// 4000 = C000 ... DOIO DMA ... 4000
//      m_ata->write_dmack(data & 0x4000 ? ASSERT_LINE : CLEAR_LINE);

		if (!(data & 0x8000))
		{
			logerror("ATAPI RESET!\n");

			// TODO: Do we need any of this?
			update_disc();
		}
	}

	DECLARE_READ16_MEMBER(konami_ide_r)
	{
		return swapendian_int16(m_ata->cs0_r(offset, mem_mask));
	}

	DECLARE_WRITE16_MEMBER(konami_ide_w)
	{
		m_ata->cs0_w(offset, swapendian_int16(data), mem_mask);
	}

private:
	void install_ymz280b();
	void install_m48t58();

	required_device<ppc602_device> m_ppc1;
	optional_device<ppc602_device> m_ppc2;
	required_device<m2_bda_device> m_bda;
	required_device<m2_cde_device> m_cde;
	required_device<eeprom_serial_93cxx_device> m_eeprom;
	required_device<dac_word_interface> m_ldac;
	required_device<dac_word_interface> m_rdac;
	required_device<ata_interface_device> m_ata;
	required_device<screen_device> m_screen;

	optional_device<m48t58_device> m_m48t58;
	optional_device<ymz280b_device> m_ymz280b;

	// ATAPI
	cdrom_file *m_available_cdroms;

	// Konami SIO
	uint16_t    m_sio_data;

	uint32_t    m_ata_int; // TEST
	emu_timer *m_atapi_timer;

	TIMER_CALLBACK_MEMBER( atapi_delay )
	{
		m_atapi_timer->adjust( attotime::never );
		m_ata_int = param;
	}

	void debug_help_command(int ref, const std::vector<std::string> &params);
	void debug_commands(int ref, const std::vector<std::string> &params);

	void dump_task_command(int ref, const std::vector<std::string> &params);
};



/*************************************
 *
 *  Trampolines - Remove ME
 *
 *************************************/

WRITE_LINE_MEMBER(konamim2_state::ppc1_int)
{
	m_ppc1->set_input_line(INPUT_LINE_IRQ0, state ? ASSERT_LINE : CLEAR_LINE);
}

WRITE_LINE_MEMBER(konamim2_state::ppc2_int)
{
	m_ppc2->set_input_line(INPUT_LINE_IRQ0, state ? ASSERT_LINE : CLEAR_LINE);
}

void konamim2_state::cde_sdbg_out(uint32_t data)
{
	if (data == 0xd)
		putc('\n', stdout);
	else if (data != 0)
		putc(data, stdout);

	fflush(stdout);

#if ENABLE_SDBG
	// Dummy write to enable serial out
	if (data == 0x3c)
		m_cde->sdbg_in(space, 0, 0xffffffff);
#endif
}

void konamim2_state::ldac_out(uint16_t data)
{
	m_ldac->write(data);
}

void konamim2_state::rdac_out(uint16_t data)
{
	m_rdac->write(data);
}


/*************************************
 *
 *  ATAPI (Temporary - remove)
 *
 *************************************/

WRITE_LINE_MEMBER( konamim2_state::ata_int )
{
//  m_atapi_timer->adjust( attotime::from_msec(10), state );
	m_ata_int = state;
}


/*************************************
 *
 *  Konami I/O
 *
 *************************************/

READ16_MEMBER( konamim2_state::konami_io0_r )
{
//  printf("IO R: %08X\n", offset);

	switch (offset)
	{
		/*
		    0 =    160
		    1 =     32
		    2 =    -96
		   10 =  -1888
		   FF = -32480

		  100 =    160
		  1FF = -32480

		  200 =    159
		  2FF = -32481

		  300 =    159
		  3FF = -32481

		  400 =    158

		  800 =    156

		  C00 =    154

		  E00
		  F00 =    153

		 1000 =    152
		 2000 =    144
		 4000 =    128
		 8000 =     96

		 E000 =     48
		 F000 =     40
		 FF00 =     33

		 7FFF = -32543
		 FFFF = -32607
		 */
		case 0:
		{
			return swapendian_int16((int16_t)ioport("GUNX1")->read());
		}
		case 1: return 0;
		case 2: return 0; // P3 X?
		case 3: return 0xffff; // ?
		case 4:
		{
			return swapendian_int16((int16_t)ioport("GUNY1")->read());
		}
		case 5: return 0; // P2 Y
		case 6: return 0; // P3 Y?
		case 7: return 0; //??
		case 8: return ioport("P5")->read();
	}

	//return rand();
	return 0;
}

WRITE16_MEMBER( konamim2_state::konami_io0_w )
{
	// 9: 0000, 0xFFF
//  printf("IO W: %08x %08x\n", offset, data);
}

/*
     FEDCBA98 76543210
 0: |........ ........|

 1: |........ ........|

 2: |........ ........|

 3: |........ .......x| Coin 1
    |........ ......x.| Coin 2
    |........ ....x...| Service coin
    |.......x ........| EEPROM D0
    |.....x.. ........| ADC
    |...xx... ........| SIO related? (set to 3 NOTE: Total Vice doesn't like this!)
    |..x..... ........| ATAPI/CD status?

 4: |........ ........| Player 1/2 inputs

 5: |........ ........| Unknown

 6: |........ ........| Unknown

 7: |........ ........| Unknown
*/

READ16_MEMBER( konamim2_state::konami_io1_r )
{
	uint16_t data = 0;

//  printf("%s: PORT R: [%x] MASK:%.8x\n", machine().describe_context(), offset, mem_mask);

	switch (offset)
	{
		case 0:
			data = 0xffff;
			break;

		case 1:
			data = 0xffff;
			break;

		case 2: // DIP switches
			data = ioport("P2")->read();
			break;

		case 3:
		{
			data = ioport("P1")->read();
#if M2_BAD_TIMING
			static uint32_t d = 0;
			data |= d;
			d ^= 0x2000;
#else
			data |= m_ata_int ? 0x2000 : 0;
#endif
			data |= (1 << 10);
			data |= (3 << 11); // TODO: 3 normally
			break;
		}

		case 4: // Buttons
			data = ioport("P4")->read();
			break;

		case 5: // Changing this has a tendency to stop evilngt from booting...
			data = 0xffff;
			break;

		case 6: // Buttons
			data = ioport("P6")->read();
			break;

		case 7:
			data = 0xffff;
			break;

		default:
			logerror("%s: Unknown read: %x\n", machine().describe_context(), offset);
			break;
	}

	return data;
}

WRITE16_MEMBER( konamim2_state::konami_io1_w )
{
	// 0x0200 = ADC?
	// 0x0800 = Coin counter 1
	// 0x1000 = Coin counter 2
	// 0x2000 = CD-MUTE
	// 0x8000 = ?
	logerror("%s: PORT W: [%x] %x, MASK:%.8x\n", machine().describe_context(), offset, data, mem_mask);

//  printf("CDDA is: %s\n", data & 0x2000 ? "ENABLED" : "MUTE");

	machine().bookkeeping().coin_counter_w(0, (data >> 11) & 1);
	machine().bookkeeping().coin_counter_w(1, (data >> 12) & 1);

//  m_cdda->set_output_gain(0, data & 0x2000 ? 1.0 : 0.0);
//  m_cdda->set_output_gain(1, data & 0x2000 ? 1.0 : 0.0);
}



/**************************************
 *
 *  Konami 003461 SIO
 *
 *************************************/

/*
     FEDCBA98 76543210
 0: |xxxxxxxx xxxxxxxx| Data R/W

 1: |........ ........|

 2: |........ ........|

 3: |........ ........|

 4: |........ ........|

 5: |........ ..x.....| Transmit ready

 6: |........ ........|

 7: |xxxxxxxx xxxxxxxx| Register R/W
*/

READ16_MEMBER( konamim2_state::konami_sio_r )
{
	uint16_t data = 0;

	switch (offset)
	{
		case 7:
			data = m_sio_data;
			break;
		//default:
			//logerror("%s: SIO_R: %x %x\n", machine().describe_context(), offset, mem_mask);
	}

	return data;
}

WRITE16_MEMBER( konamim2_state::konami_sio_w )
{
	switch (offset)
	{
		case 7:
			m_sio_data = data;
			break;
		//default:
			//printf("%s: SIO_W: %x %x %x\n", machine().describe_context(), offset, data, mem_mask);
	}
}

// TODO: Use output port
WRITE16_MEMBER( konamim2_state::konami_eeprom_w )
{
	// 3 = CS
	// 2 = CLK
	// 1 = DATA
	// 0 = ? (From Port)
	m_eeprom->cs_write(data & 0x80 ? ASSERT_LINE : CLEAR_LINE);
	m_eeprom->di_write(data & 0x20 ? 1 : 0);
	m_eeprom->clk_write(data & 0x40 ? ASSERT_LINE : CLEAR_LINE);
}



/*************************************
 *
 *  Machine initialization
 *
 *************************************/

void konamim2_state::machine_start()
{
	m_ppc1->ppcdrc_set_options(PPCDRC_COMPATIBLE_OPTIONS);
	m_ppc2->ppcdrc_set_options(PPCDRC_COMPATIBLE_OPTIONS);

	m_ppc1->ppcdrc_add_fastram(m_bda->ram_start(), m_bda->ram_end(), false, m_bda->ram_ptr());
	m_ppc2->ppcdrc_add_fastram(m_bda->ram_start(), m_bda->ram_end(), false, m_bda->ram_ptr());

	m_available_cdroms = cdrom_open(machine().rom_load().get_disk_handle(":cdrom"));

	// TODO: REMOVE
	m_atapi_timer = machine().scheduler().timer_alloc( timer_expired_delegate( FUNC( konamim2_state::atapi_delay ),this ) );
	m_atapi_timer->adjust( attotime::never );

	if (machine().debug_flags & DEBUG_FLAG_ENABLED)
	{
		using namespace std::placeholders;
		machine().debugger().console().register_command("m2", CMDFLAG_NONE, 0, 1, 4, std::bind(&konamim2_state::debug_commands, this, _1, _2));
	}
}

void konamim2_state::machine_reset()
{
	update_disc();
}

void konamim2_state::update_disc()
{
	cdrom_file *new_cdrom = m_available_cdroms;

	atapi_hle_device *image = subdevice<atapi_hle_device>("ata:0:cr589");
	if (image != nullptr)
	{
		void *current_cdrom = nullptr;
		image->GetDevice(&current_cdrom);

		if (current_cdrom != new_cdrom)
		{
			current_cdrom = new_cdrom;

			image->SetDevice(new_cdrom);
		}
	}
	else
	{
		abort();
	}
}

/*************************************
 *
 *  Address map
 *
 *************************************/

void konamim2_state::m2_map(address_map &map)
{
	map(0x20000000, 0x201fffff).rom().region("boot", 0); // BIOBUS Slot 0
	map(0xfff00000, 0xffffffff).rom().region("boot", 0);
	map(0x37400000, 0x37400007).w(FUNC(konamim2_state::konami_eeprom_w)).umask64(0xffff000000000000ULL);
	map(0x37600000, 0x3760000f).w(FUNC(konamim2_state::konami_atapi_unk_w)).umask64(0xffff000000000000ULL);
	map(0x37a00020, 0x37a0003f).rw(FUNC(konamim2_state::konami_io0_r), FUNC(konamim2_state::konami_io0_w));
	map(0x37c00010, 0x37c0001f).rw(FUNC(konamim2_state::konami_sio_r), FUNC(konamim2_state::konami_sio_w));
	map(0x37e00000, 0x37e0000f).rw(FUNC(konamim2_state::konami_io1_r), FUNC(konamim2_state::konami_io1_w));
	map(0x3f000000, 0x3fffffff).rw(FUNC(konamim2_state::konami_ide_r), FUNC(konamim2_state::konami_ide_w));
}



/*************************************
 *
 *  Port definitions
 *
 *************************************/

static INPUT_PORTS_START( konamim2 )
	PORT_START("DSW")
	PORT_DIPNAME( 0x01, 0x00, "Video Res" )
	PORT_DIPSETTING(    0x00, "High Res" )
	PORT_DIPSETTING(    0x01, "Low Res" )

	PORT_START("P1")
	PORT_BIT( 0x0001, IP_ACTIVE_LOW, IPT_COIN1 )
	PORT_BIT( 0x0002, IP_ACTIVE_LOW, IPT_COIN2 )
	PORT_BIT( 0x0004, IP_ACTIVE_LOW, IPT_UNUSED )
	PORT_BIT( 0x0008, IP_ACTIVE_LOW, IPT_UNUSED )
	PORT_BIT( 0x0010, IP_ACTIVE_LOW, IPT_SERVICE1 )
	PORT_BIT( 0x0020, IP_ACTIVE_LOW, IPT_UNUSED )
	PORT_BIT( 0x0040, IP_ACTIVE_LOW, IPT_UNUSED )
	PORT_BIT( 0x0080, IP_ACTIVE_LOW, IPT_UNUSED )
	PORT_BIT( 0x0100, IP_ACTIVE_HIGH, IPT_CUSTOM ) PORT_READ_LINE_DEVICE_MEMBER("eeprom", eeprom_serial_93cxx_device, do_read)
	PORT_BIT( 0x2000, IP_ACTIVE_HIGH, IPT_UNUSED ) // ATAPI?
	PORT_BIT( 0xDE00, IP_ACTIVE_HIGH, IPT_UNUSED )
INPUT_PORTS_END

static INPUT_PORTS_START( btltryst )
	PORT_INCLUDE( konamim2 )

	PORT_MODIFY("DSW")
	PORT_DIPNAME( 0x01, 0x01, "Video Res" )
	PORT_DIPSETTING(    0x00, "High Res" )
	PORT_DIPSETTING(    0x01, "Low Res" )

	PORT_START("P2")
	PORT_DIPNAME( 0x01, 0x01, DEF_STR( Unused ) )
	PORT_DIPSETTING(    0x01, DEF_STR( Off ) )
	PORT_DIPSETTING(    0x00, DEF_STR( On ) )
	PORT_DIPNAME( 0x02, 0x02, DEF_STR( Flip_Screen ) )
	PORT_DIPSETTING(    0x02, DEF_STR( Off ) )
	PORT_DIPSETTING(    0x00, DEF_STR( On ) )
	PORT_DIPNAME( 0x04, 0x04, DEF_STR( Unused ) )
	PORT_DIPSETTING(    0x04, DEF_STR( Off ) )
	PORT_DIPSETTING(    0x00, DEF_STR( On ) )
	PORT_DIPNAME( 0x08, 0x08, DEF_STR( Unused ) )
	PORT_DIPSETTING(    0x08, DEF_STR( Off ) )
	PORT_DIPSETTING(    0x00, DEF_STR( On ) )
	PORT_DIPNAME( 0x10, 0x10, DEF_STR( Unused ) )
	PORT_DIPSETTING(    0x10, DEF_STR( Off ) )
	PORT_DIPSETTING(    0x00, DEF_STR( On ) )
	PORT_DIPNAME( 0x20, 0x20, DEF_STR( Unused ) )
	PORT_DIPSETTING(    0x20, DEF_STR( Off ) )
	PORT_DIPSETTING(    0x00, DEF_STR( On ) )
	PORT_DIPNAME( 0x40, 0x40, DEF_STR( Unused ) )
	PORT_DIPSETTING(    0x40, DEF_STR( Off ) )
	PORT_DIPSETTING(    0x00, DEF_STR( On ) )
	PORT_DIPNAME( 0x80, 0x80, DEF_STR( Unused ) )
	PORT_DIPSETTING(    0x80, DEF_STR( Off ) )
	PORT_DIPSETTING(    0x00, DEF_STR( On ) )

	PORT_START("P4")
	PORT_BIT( 0x0001, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT ) PORT_PLAYER(1)
	PORT_BIT( 0x0002, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT ) PORT_PLAYER(1)
	PORT_BIT( 0x0004, IP_ACTIVE_LOW, IPT_JOYSTICK_UP ) PORT_PLAYER(1)
	PORT_BIT( 0x0008, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN ) PORT_PLAYER(1)
	PORT_BIT( 0x0010, IP_ACTIVE_LOW, IPT_BUTTON1 ) PORT_PLAYER(1)
	PORT_BIT( 0x0020, IP_ACTIVE_LOW, IPT_BUTTON2 ) PORT_PLAYER(1)
	PORT_BIT( 0x0040, IP_ACTIVE_LOW, IPT_BUTTON3 ) PORT_PLAYER(1)
	PORT_BIT( 0x0080, IP_ACTIVE_LOW, IPT_START1 )

	PORT_BIT( 0x0100, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT ) PORT_PLAYER(2)
	PORT_BIT( 0x0200, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT ) PORT_PLAYER(2)
	PORT_BIT( 0x0400, IP_ACTIVE_LOW, IPT_JOYSTICK_UP ) PORT_PLAYER(2)
	PORT_BIT( 0x0800, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN ) PORT_PLAYER(2)
	PORT_BIT( 0x1000, IP_ACTIVE_LOW, IPT_BUTTON1 ) PORT_PLAYER(2)
	PORT_BIT( 0x2000, IP_ACTIVE_LOW, IPT_BUTTON2 ) PORT_PLAYER(2)
	PORT_BIT( 0x4000, IP_ACTIVE_LOW, IPT_BUTTON3 ) PORT_PLAYER(2)
	PORT_BIT( 0x8000, IP_ACTIVE_LOW, IPT_START2 )

	PORT_START("P5")
	PORT_BIT( 0xffff, IP_ACTIVE_LOW, IPT_UNUSED )

	PORT_START("P6")
	PORT_SERVICE_NO_TOGGLE( 0x0004, IP_ACTIVE_LOW )
	PORT_BIT( 0xfffb, IP_ACTIVE_LOW, IPT_UNUSED )
INPUT_PORTS_END

static INPUT_PORTS_START( polystar )
	PORT_INCLUDE( konamim2 )

	PORT_MODIFY("DSW")
	PORT_DIPNAME( 0x01, 0x01, "Video Res" )
	PORT_DIPSETTING(    0x00, "High Res" )
	PORT_DIPSETTING(    0x01, "Low Res" )

	PORT_START("P2")
	PORT_DIPNAME( 0x01, 0x01, "Sound Output" )
	PORT_DIPSETTING(    0x01, "Mono" )
	PORT_DIPSETTING(    0x00, "Stereo" )
	PORT_DIPNAME( 0x02, 0x02, DEF_STR( Flip_Screen ) )
	PORT_DIPSETTING(    0x02, DEF_STR( Off ) )
	PORT_DIPSETTING(    0x00, DEF_STR( On ) )
	PORT_DIPNAME( 0x04, 0x04, DEF_STR( Unused ) )
	PORT_DIPSETTING(    0x04, DEF_STR( Off ) )
	PORT_DIPSETTING(    0x00, DEF_STR( On ) )
	PORT_DIPNAME( 0x08, 0x08, DEF_STR( Unused ) )
	PORT_DIPSETTING(    0x08, DEF_STR( Off ) )
	PORT_DIPSETTING(    0x00, DEF_STR( On ) )
	PORT_DIPNAME( 0x10, 0x10, DEF_STR( Unused ) )
	PORT_DIPSETTING(    0x10, DEF_STR( Off ) )
	PORT_DIPSETTING(    0x00, DEF_STR( On ) )
	PORT_DIPNAME( 0x20, 0x20, DEF_STR( Unused ) )
	PORT_DIPSETTING(    0x20, DEF_STR( Off ) )
	PORT_DIPSETTING(    0x00, DEF_STR( On ) )
	PORT_DIPNAME( 0x40, 0x40, DEF_STR( Unused ) )
	PORT_DIPSETTING(    0x40, DEF_STR( Off ) )
	PORT_DIPSETTING(    0x00, DEF_STR( On ) )
	PORT_DIPNAME( 0x80, 0x80, DEF_STR( Unused ) )
	PORT_DIPSETTING(    0x80, DEF_STR( Off ) )
	PORT_DIPSETTING(    0x00, DEF_STR( On ) )

	PORT_START("P4")
	PORT_BIT( 0x0001, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT ) PORT_PLAYER(1)
	PORT_BIT( 0x0002, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT ) PORT_PLAYER(1)
	PORT_BIT( 0x0004, IP_ACTIVE_LOW, IPT_JOYSTICK_UP ) PORT_PLAYER(1)
	PORT_BIT( 0x0008, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN ) PORT_PLAYER(1)
	PORT_BIT( 0x0010, IP_ACTIVE_LOW, IPT_BUTTON1 ) PORT_PLAYER(1)
	PORT_BIT( 0x0020, IP_ACTIVE_LOW, IPT_BUTTON2 ) PORT_PLAYER(1)
	PORT_BIT( 0x0040, IP_ACTIVE_LOW, IPT_BUTTON3 ) PORT_PLAYER(1)
	PORT_BIT( 0x0080, IP_ACTIVE_LOW, IPT_START1 )

	PORT_BIT( 0x0100, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT ) PORT_PLAYER(2)
	PORT_BIT( 0x0200, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT ) PORT_PLAYER(2)
	PORT_BIT( 0x0400, IP_ACTIVE_LOW, IPT_JOYSTICK_UP ) PORT_PLAYER(2)
	PORT_BIT( 0x0800, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN ) PORT_PLAYER(2)
	PORT_BIT( 0x1000, IP_ACTIVE_LOW, IPT_BUTTON1 ) PORT_PLAYER(2)
	PORT_BIT( 0x2000, IP_ACTIVE_LOW, IPT_BUTTON2 ) PORT_PLAYER(2)
	PORT_BIT( 0x4000, IP_ACTIVE_LOW, IPT_BUTTON3 ) PORT_PLAYER(2)
	PORT_BIT( 0x8000, IP_ACTIVE_LOW, IPT_START2 )

	PORT_START("P5")
	PORT_BIT( 0xffff, IP_ACTIVE_LOW, IPT_UNUSED )

	PORT_START("P6")
	PORT_SERVICE_NO_TOGGLE( 0x0004, IP_ACTIVE_LOW )
INPUT_PORTS_END

static INPUT_PORTS_START( totlvice )
	PORT_INCLUDE( konamim2 )

	PORT_START("P2") // TODO: VERIFY
	PORT_DIPNAME( 0x01, 0x00, "Sound Output" )
	PORT_DIPSETTING(    0x01, "Mono" )
	PORT_DIPSETTING(    0x00, "Stereo" )
	PORT_DIPNAME( 0x02, 0x02, DEF_STR( Flip_Screen ) )
	PORT_DIPSETTING(    0x02, DEF_STR( Off ) )
	PORT_DIPSETTING(    0x00, DEF_STR( On ) )
	PORT_DIPNAME( 0x04, 0x04, DEF_STR( Unused ) )
	PORT_DIPSETTING(    0x04, DEF_STR( Off ) )
	PORT_DIPSETTING(    0x00, DEF_STR( On ) )
	PORT_DIPNAME( 0x08, 0x08, DEF_STR( Unused ) )
	PORT_DIPSETTING(    0x08, DEF_STR( Off ) )
	PORT_DIPSETTING(    0x00, DEF_STR( On ) )
	PORT_DIPNAME( 0x10, 0x10, DEF_STR( Unused ) )
	PORT_DIPSETTING(    0x10, DEF_STR( Off ) )
	PORT_DIPSETTING(    0x00, DEF_STR( On ) )
	PORT_DIPNAME( 0x20, 0x20, DEF_STR( Unused ) )
	PORT_DIPSETTING(    0x20, DEF_STR( Off ) )
	PORT_DIPSETTING(    0x00, DEF_STR( On ) )
	PORT_DIPNAME( 0x40, 0x40, DEF_STR( Unused ) )
	PORT_DIPSETTING(    0x40, DEF_STR( Off ) )
	PORT_DIPSETTING(    0x00, DEF_STR( On ) )
	PORT_DIPNAME( 0x80, 0x80, DEF_STR( Unused ) )
	PORT_DIPSETTING(    0x80, DEF_STR( Off ) )
	PORT_DIPSETTING(    0x00, DEF_STR( On ) )

	PORT_START("P4")
	PORT_BIT( 0x0001, IP_ACTIVE_LOW, IPT_SERVICE2 )
	PORT_BIT( 0x0002, IP_ACTIVE_LOW, IPT_SERVICE3 )
	PORT_BIT( 0x0004, IP_ACTIVE_LOW, IPT_START3 )
	PORT_BIT( 0x0008, IP_ACTIVE_LOW, IPT_COIN3 )
	PORT_BIT( 0x0010, IP_ACTIVE_LOW, IPT_UNUSED )
	PORT_BIT( 0x0020, IP_ACTIVE_LOW, IPT_UNUSED )
	PORT_BIT( 0x0040, IP_ACTIVE_LOW, IPT_UNUSED )
	PORT_BIT( 0x0080, IP_ACTIVE_LOW, IPT_START1 )
	PORT_BIT( 0x0100, IP_ACTIVE_LOW, IPT_UNUSED )
	PORT_BIT( 0x0200, IP_ACTIVE_LOW, IPT_UNUSED )
	PORT_BIT( 0x0400, IP_ACTIVE_LOW, IPT_UNUSED )
	PORT_BIT( 0x0800, IP_ACTIVE_LOW, IPT_UNUSED )
	PORT_BIT( 0x1000, IP_ACTIVE_LOW, IPT_UNUSED )
	PORT_BIT( 0x2000, IP_ACTIVE_LOW, IPT_UNUSED )
	PORT_BIT( 0x4000, IP_ACTIVE_LOW, IPT_UNUSED )
	PORT_BIT( 0x8000, IP_ACTIVE_LOW, IPT_START2 )

	PORT_START("GUNX1")
	PORT_BIT( 0xffff, 0x0000, IPT_LIGHTGUN_X ) PORT_CROSSHAIR(X, 1.0, 0.0, 0) PORT_MINMAX(0, 640) PORT_SENSITIVITY(25) PORT_KEYDELTA(15) PORT_PLAYER(1)

	PORT_START("GUNY1")
	PORT_BIT( 0xffff, 0x0000, IPT_LIGHTGUN_Y ) PORT_CROSSHAIR(Y, 1.0, 0.0, 0) PORT_MINMAX(0, 240) PORT_SENSITIVITY(25) PORT_KEYDELTA(15) PORT_PLAYER(1)

	PORT_START("P5") // Gun switches
	PORT_BIT( 0x00ff, IP_ACTIVE_LOW, IPT_UNUSED )
	PORT_BIT( 0x0100, IP_ACTIVE_LOW, IPT_BUTTON1 ) PORT_PLAYER(1)
	PORT_BIT( 0x0200, IP_ACTIVE_LOW, IPT_BUTTON1 ) PORT_PLAYER(2)
	PORT_BIT( 0x0400, IP_ACTIVE_LOW, IPT_BUTTON1 ) PORT_PLAYER(3)
	PORT_BIT( 0x0800, IP_ACTIVE_LOW, IPT_UNUSED )
	PORT_BIT( 0x1000, IP_ACTIVE_LOW, IPT_BUTTON2 ) PORT_PLAYER(1)
	PORT_BIT( 0x2000, IP_ACTIVE_LOW, IPT_BUTTON2 ) PORT_PLAYER(2)
	PORT_BIT( 0x4000, IP_ACTIVE_LOW, IPT_BUTTON2 ) PORT_PLAYER(3)
	PORT_BIT( 0x8000, IP_ACTIVE_LOW, IPT_UNUSED )

	PORT_START("P6")
	PORT_SERVICE_NO_TOGGLE( 0x0004, IP_ACTIVE_LOW )
	PORT_BIT( 0xfffb, IP_ACTIVE_LOW, IPT_UNUSED )
INPUT_PORTS_END

static INPUT_PORTS_START( heatof11 )
	PORT_INCLUDE( konamim2 )

	PORT_MODIFY("DSW")
	PORT_DIPNAME( 0x01, 0x00, "Video Res" )
	PORT_DIPSETTING(    0x00, "High Res" )
	PORT_DIPSETTING(    0x01, "Low Res" )

	PORT_START("P2")
	PORT_DIPNAME( 0x01, 0x00, DEF_STR( Unused ) )
	PORT_DIPSETTING(    0x01, DEF_STR( Off ) )
	PORT_DIPSETTING(    0x00, DEF_STR( On ) )
	PORT_DIPNAME( 0x02, 0x02, DEF_STR( Flip_Screen ) )
	PORT_DIPSETTING(    0x02, DEF_STR( Off ) )
	PORT_DIPSETTING(    0x00, DEF_STR( On ) )
	PORT_DIPNAME( 0x04, 0x04, DEF_STR( Unused ) )
	PORT_DIPSETTING(    0x04, DEF_STR( Off ) )
	PORT_DIPSETTING(    0x00, DEF_STR( On ) )
	PORT_DIPNAME( 0x08, 0x08, DEF_STR( Unused ) )
	PORT_DIPSETTING(    0x08, DEF_STR( Off ) )
	PORT_DIPSETTING(    0x00, DEF_STR( On ) )
	PORT_DIPNAME( 0x10, 0x10, DEF_STR( Unused ) )
	PORT_DIPSETTING(    0x10, DEF_STR( Off ) )
	PORT_DIPSETTING(    0x00, DEF_STR( On ) )
	PORT_DIPNAME( 0x20, 0x20, DEF_STR( Unused ) )
	PORT_DIPSETTING(    0x20, DEF_STR( Off ) )
	PORT_DIPSETTING(    0x00, DEF_STR( On ) )
	PORT_DIPNAME( 0x40, 0x40, DEF_STR( Unused ) )
	PORT_DIPSETTING(    0x40, DEF_STR( Off ) )
	PORT_DIPSETTING(    0x00, DEF_STR( On ) )
	PORT_DIPNAME( 0x80, 0x80, DEF_STR( Unused ) )
	PORT_DIPSETTING(    0x80, DEF_STR( Off ) )
	PORT_DIPSETTING(    0x00, DEF_STR( On ) )

	PORT_START("P4")
	PORT_BIT( 0x0001, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT ) PORT_PLAYER(1)
	PORT_BIT( 0x0002, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT ) PORT_PLAYER(1)
	PORT_BIT( 0x0004, IP_ACTIVE_LOW, IPT_JOYSTICK_UP ) PORT_PLAYER(1)
	PORT_BIT( 0x0008, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN ) PORT_PLAYER(1)
	PORT_BIT( 0x0010, IP_ACTIVE_LOW, IPT_BUTTON1 ) PORT_PLAYER(1)
	PORT_BIT( 0x0020, IP_ACTIVE_LOW, IPT_BUTTON2 ) PORT_PLAYER(1)
	PORT_BIT( 0x0040, IP_ACTIVE_LOW, IPT_BUTTON3 ) PORT_PLAYER(1)
	PORT_BIT( 0x0080, IP_ACTIVE_LOW, IPT_START1 )

	PORT_BIT( 0x0100, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT ) PORT_PLAYER(2)
	PORT_BIT( 0x0200, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT ) PORT_PLAYER(2)
	PORT_BIT( 0x0400, IP_ACTIVE_LOW, IPT_JOYSTICK_UP ) PORT_PLAYER(2)
	PORT_BIT( 0x0800, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN ) PORT_PLAYER(2)
	PORT_BIT( 0x1000, IP_ACTIVE_LOW, IPT_BUTTON1 ) PORT_PLAYER(2)
	PORT_BIT( 0x2000, IP_ACTIVE_LOW, IPT_BUTTON2 ) PORT_PLAYER(2)
	PORT_BIT( 0x4000, IP_ACTIVE_LOW, IPT_BUTTON3 ) PORT_PLAYER(2)
	PORT_BIT( 0x8000, IP_ACTIVE_LOW, IPT_START2 )

	PORT_START("P5")
	PORT_BIT( 0xffff, IP_ACTIVE_LOW, IPT_UNUSED )

	PORT_START("P6")
	PORT_SERVICE_NO_TOGGLE( 0x0004, IP_ACTIVE_LOW )
INPUT_PORTS_END

static INPUT_PORTS_START( hellngt )
	PORT_INCLUDE( konamim2 )

	PORT_START("P2")
	PORT_DIPNAME( 0x01, 0x01, DEF_STR( Unused ) )
	PORT_DIPSETTING(    0x01, DEF_STR( Off ) )
	PORT_DIPSETTING(    0x00, DEF_STR( On ) )
	PORT_DIPNAME( 0x02, 0x02, DEF_STR( Flip_Screen ) )
	PORT_DIPSETTING(    0x02, DEF_STR( Off ) )
	PORT_DIPSETTING(    0x00, DEF_STR( On ) )
	PORT_DIPNAME( 0x04, 0x04, DEF_STR( Unused ) )
	PORT_DIPSETTING(    0x04, DEF_STR( Off ) )
	PORT_DIPSETTING(    0x00, DEF_STR( On ) )
	PORT_DIPNAME( 0x08, 0x08, DEF_STR( Unused ) )
	PORT_DIPSETTING(    0x08, DEF_STR( Off ) )
	PORT_DIPSETTING(    0x00, DEF_STR( On ) )
	PORT_DIPNAME( 0x10, 0x10, DEF_STR( Unused ) )
	PORT_DIPSETTING(    0x10, DEF_STR( Off ) )
	PORT_DIPSETTING(    0x00, DEF_STR( On ) )
	PORT_DIPNAME( 0x20, 0x20, DEF_STR( Unused ) )
	PORT_DIPSETTING(    0x20, DEF_STR( Off ) )
	PORT_DIPSETTING(    0x00, DEF_STR( On ) )
	PORT_DIPNAME( 0x40, 0x40, DEF_STR( Unused ) )
	PORT_DIPSETTING(    0x40, DEF_STR( Off ) )
	PORT_DIPSETTING(    0x00, DEF_STR( On ) )
	PORT_DIPNAME( 0x80, 0x80, DEF_STR( Unused ) )
	PORT_DIPSETTING(    0x80, DEF_STR( Off ) )
	PORT_DIPSETTING(    0x00, DEF_STR( On ) )

	PORT_START("P4")
	PORT_BIT( 0x0001, IP_ACTIVE_LOW, IPT_SERVICE2 )
	PORT_BIT( 0x0002, IP_ACTIVE_LOW, IPT_SERVICE3 )
	PORT_BIT( 0x0004, IP_ACTIVE_LOW, IPT_START3 )
	PORT_BIT( 0x0008, IP_ACTIVE_LOW, IPT_COIN3 )
	PORT_BIT( 0x0010, IP_ACTIVE_LOW, IPT_UNUSED )
	PORT_BIT( 0x0020, IP_ACTIVE_LOW, IPT_UNUSED )
	PORT_BIT( 0x0040, IP_ACTIVE_LOW, IPT_UNUSED )
	PORT_BIT( 0x0080, IP_ACTIVE_LOW, IPT_START1 )
	PORT_BIT( 0x0100, IP_ACTIVE_LOW, IPT_UNUSED )
	PORT_BIT( 0x0200, IP_ACTIVE_LOW, IPT_UNUSED )
	PORT_BIT( 0x0400, IP_ACTIVE_LOW, IPT_UNUSED )
	PORT_BIT( 0x0800, IP_ACTIVE_LOW, IPT_UNUSED )
	PORT_BIT( 0x1000, IP_ACTIVE_LOW, IPT_UNUSED )
	PORT_BIT( 0x2000, IP_ACTIVE_LOW, IPT_UNUSED )
	PORT_BIT( 0x4000, IP_ACTIVE_LOW, IPT_UNUSED )
	PORT_BIT( 0x8000, IP_ACTIVE_LOW, IPT_START2 )

	PORT_START("GUNX1")
	PORT_BIT( 0xffff, 0x0000, IPT_LIGHTGUN_X ) PORT_CROSSHAIR(X, 1.0, 0.0, 0) PORT_MINMAX( 0, 320*2 ) PORT_SENSITIVITY(25) PORT_KEYDELTA(15) PORT_PLAYER(1)

	PORT_START("GUNY1")
	PORT_BIT( 0xffff, 0x0000, IPT_LIGHTGUN_Y ) PORT_CROSSHAIR(Y, 1.0, 0.0, 0) PORT_MINMAX( 0, 240 ) PORT_SENSITIVITY(25) PORT_KEYDELTA(15) PORT_PLAYER(1)

	PORT_START("P5") // Gun switches
	PORT_BIT( 0x00ff, IP_ACTIVE_LOW, IPT_UNUSED )
	PORT_BIT( 0x0100, IP_ACTIVE_LOW, IPT_BUTTON1 ) PORT_PLAYER(1)
	PORT_BIT( 0x0200, IP_ACTIVE_LOW, IPT_BUTTON1 ) PORT_PLAYER(2)
	PORT_BIT( 0x0400, IP_ACTIVE_LOW, IPT_BUTTON1 ) PORT_PLAYER(3)
	PORT_BIT( 0x0800, IP_ACTIVE_LOW, IPT_UNUSED )
	PORT_BIT( 0x1000, IP_ACTIVE_LOW, IPT_BUTTON2 ) PORT_PLAYER(1)
	PORT_BIT( 0x2000, IP_ACTIVE_LOW, IPT_BUTTON2 ) PORT_PLAYER(2)
	PORT_BIT( 0x4000, IP_ACTIVE_LOW, IPT_BUTTON2 ) PORT_PLAYER(3)
	PORT_BIT( 0x8000, IP_ACTIVE_LOW, IPT_UNUSED )

	PORT_START("P6")
	PORT_SERVICE_NO_TOGGLE( 0x0004, IP_ACTIVE_LOW )
	PORT_BIT( 0xfffb, IP_ACTIVE_LOW, IPT_UNUSED )
INPUT_PORTS_END



/*************************************
 *
 *  Machine driver
 *
 *************************************/

void konamim2_state::cr589_config(device_t *device)
{
	device->subdevice<cdda_device>("cdda")->add_route(0, ":lspeaker", 1.0);
	device->subdevice<cdda_device>("cdda")->add_route(1, ":rspeaker", 1.0);
	device = device->subdevice("cdda");
}

void konamim2_state::konamim2(machine_config &config)
{
	// Basic machine hardware
	PPC602(config, m_ppc1, M2_CLOCK);
	m_ppc1->set_bus_frequency(M2_CLOCK / 2);
	m_ppc1->set_addrmap(AS_PROGRAM, &konamim2_state::m2_map);

	PPC602(config, m_ppc2, M2_CLOCK);
	m_ppc2->set_bus_frequency(M2_CLOCK / 2);
	m_ppc2->set_addrmap(AS_PROGRAM, &konamim2_state::m2_map);

	// M2 hardware
	M2_BDA(config, m_bda, M2_CLOCK, m_ppc1, m_ppc2, m_cde);
	m_bda->set_ram_size(m2_bda_device::RAM_8MB, m2_bda_device::RAM_8MB);
	m_bda->subdevice<m2_powerbus_device>("powerbus")->int_handler().set(FUNC(konamim2_state::ppc1_int));
	m_bda->subdevice<m2_memctl_device>("memctl")->gpio_out_handler<3>().set(FUNC(konamim2_state::ppc2_int)).invert();
	m_bda->subdevice<m2_vdu_device>("vdu")->set_screen("screen");
	m_bda->videores_in().set_ioport("DSW");
	m_bda->ldac_handler().set(FUNC(konamim2_state::ldac_out));
	m_bda->rdac_handler().set(FUNC(konamim2_state::rdac_out));

	M2_CDE(config, m_cde, M2_CLOCK, m_ppc1, m_bda);
	m_cde->int_handler().set(":bda:powerbus", FUNC(m2_powerbus_device::int_line<BDAINT_EXTD4_LINE>));
	m_cde->set_syscfg(SYSCONFIG_ARCADE);
	m_cde->sdbg_out().set(FUNC(konamim2_state::cde_sdbg_out));

	// Common devices
	EEPROM_93C46_16BIT(config, m_eeprom);

	ATA_INTERFACE(config, m_ata, 0);
	m_ata->irq_handler().set(FUNC(konamim2_state::ata_int));

	m_ata->slot(0).option_add("cr589", CR589);
	m_ata->slot(0).set_option_machine_config("cr589", cr589_config);
	m_ata->slot(0).set_default_option("cr589");

	// Video hardware
	SCREEN(config, m_screen, SCREEN_TYPE_RASTER);
	m_screen->set_screen_update("bda:vdu", FUNC(m2_vdu_device::screen_update));

	/* Sound hardware */
	SPEAKER(config, "lspeaker").front_left();
	SPEAKER(config, "rspeaker").front_right();

	// TODO!
	DAC_16BIT_R2R_TWOS_COMPLEMENT(config, m_ldac, 0).add_route(ALL_OUTPUTS, "lspeaker", 1.0);
	DAC_16BIT_R2R_TWOS_COMPLEMENT(config, m_rdac, 0).add_route(ALL_OUTPUTS, "rspeaker", 1.0);

	voltage_regulator_device &vref(VOLTAGE_REGULATOR(config, "vref", 0));
	vref.add_route(0, "ldac", 1.0, DAC_VREF_POS_INPUT);
	vref.add_route(0, "ldac", -1.0, DAC_VREF_NEG_INPUT);
	vref.add_route(0, "rdac", 1.0, DAC_VREF_POS_INPUT);
	vref.add_route(0, "rdac", -1.0, DAC_VREF_NEG_INPUT);
}



/*************************************
 *
 *  Machine fragments
 *
 *************************************/

void konamim2_state::set_ntsc(machine_config &config)
{
//  m_screen->set_raw(11750000, 766, 126, 126+640, 260, 20, 20+240); // TODO
	m_screen->set_refresh_hz(59.360001);
	m_screen->set_size(768, 262);
	m_screen->set_visarea(126, 126+640-1, 20, 20+240-1);
}

void konamim2_state::set_ntsc2(machine_config &config)
{
	//m_screen->set_raw(11750000, 766, 126, 126+640, 260, 20, 20+240); // TODO
	m_screen->set_refresh_hz(59.360001);
	m_screen->set_size(768, 262*2); // TOTAL VICE ONLY WORKS WITH THIS!
	m_screen->set_visarea(126, 126+640-1, 20, 20+240-1);
}

void konamim2_state::set_arcres(machine_config &config)
{
	m_screen->set_raw(16934500, 684, 104, 104+512, 416, 26, 26+384);
}

void konamim2_state::add_ymz280b(machine_config &config)
{
	// TODO: The YMZ280B outputs are actually routed to a speaker in each gun
	YMZ280B(config, m_ymz280b, XTAL(16'934'400));
	m_ymz280b->add_route(0, "lspeaker", 0.5);
	m_ymz280b->add_route(1, "rspeaker", 0.5);
}

void konamim2_state::add_mt48t58(machine_config &config)
{
	M48T58(config, m_m48t58);
}



/*************************************
 *
 *  Machine drivers
 *
 *************************************/

void konamim2_state::polystar(machine_config &config)
{
	konamim2(config);
	m_bda->set_ram_size(m2_bda_device::RAM_4MB, m2_bda_device::RAM_4MB);
	set_ntsc(config);
}

void konamim2_state::totlvice(machine_config &config)
{
	konamim2(config);
	add_ymz280b(config);
//  set_arcres(config);
	set_ntsc2(config);
}

void konamim2_state::btltryst(machine_config &config)
{
	konamim2(config);
	add_mt48t58(config);
	set_ntsc(config);
}

void konamim2_state::heatof11(machine_config &config)
{
	konamim2(config);
	add_mt48t58(config);
	set_arcres(config);
}

void konamim2_state::evilngt(machine_config &config)
{
	konamim2(config);
	add_mt48t58(config);
	add_ymz280b(config);
	set_ntsc(config);
}

void konamim2_state::hellngt(machine_config &config)
{
	konamim2(config);
	add_mt48t58(config);
	add_ymz280b(config);
	set_arcres(config);
}



/*************************************
 *
 *  ROM definition(s)
 *
 *************************************/

ROM_START( polystar )
	ROM_REGION64_BE( 0x200000, "boot", 0 )
	ROM_LOAD16_WORD( "623b01.8q", 0x000000, 0x200000, CRC(bd879f93) SHA1(e2d63bfbd2b15260a2664082652442eadea3eab6) )

	ROM_REGION16_BE( 0x80, "eeprom", 0 ) /* EEPROM default contents */
	ROM_LOAD( "93c46.7k", 0x000000, 0x000080, CRC(fab5a203) SHA1(153e22aa8cfce80b77ba200957685f796fc99b1c) )

	DISK_REGION( "cdrom" ) // Has 1s of silence near the start of the first audio track
	DISK_IMAGE_READONLY( "623jaa02", 0, BAD_DUMP SHA1(e7d9e628a3e0e085e084e4e3630fa5e3a7345547) )
ROM_END

ROM_START( btltryst )
	ROM_REGION64_BE( 0x200000, "boot", 0 )
	ROM_LOAD16_WORD( "636a01.8q", 0x000000, 0x200000, CRC(7b1dc738) SHA1(32ae8e7ddd38fcc70b4410275a2cc5e9a0d7d33b) )

	ROM_REGION16_BE( 0x80, "eeprom", 0 )
	ROM_LOAD( "93c46.7k",  0x000000, 0x000080, CRC(cc2c5640) SHA1(694cf2b3700f52ed80252b013052c90020e58ce6) )

	ROM_REGION( 0x2000, "m48t58", 0 ) /* timekeeper SRAM */
	ROM_LOAD( "m48t58", 0x000000, 0x002000, CRC(71ee073b) SHA1(cc8002d7ee8d1695aebbbb2a3a1e97a7e16948c1) )

	DISK_REGION( "cdrom" )
	DISK_IMAGE_READONLY( "636jac02", 0, SHA1(d36556a3a4b91058100924a9e9f1a58983399c6e) )
ROM_END

#if 0
ROM_START( btltrysta )
	ROM_REGION64_BE( 0x200000, "boot", 0 )
	ROM_LOAD16_WORD( "636a01.8q", 0x000000, 0x200000, CRC(7b1dc738) SHA1(32ae8e7ddd38fcc70b4410275a2cc5e9a0d7d33b) )

	ROM_REGION( 0x2000, "m48t58", 0 ) /* timekeeper SRAM */
	ROM_LOAD( "m48t58y", 0x000000, 0x002000, CRC(8611ff09) SHA1(6410236947d99c552c4a1f7dd5fd8c7a5ae4cba1) )

	DISK_REGION( "cdrom" )
	DISK_IMAGE_READONLY( "636jaa02", 0, SHA1(d36556a3a4b91058100924a9e9f1a58983399c6e) )
ROM_END
#endif

ROM_START( heatof11 )
	ROM_REGION64_BE( 0x200000, "boot", 0 )  /* boot rom */
	ROM_LOAD16_WORD( "636a01.8q", 0x000000, 0x200000, CRC(7b1dc738) SHA1(32ae8e7ddd38fcc70b4410275a2cc5e9a0d7d33b) )

	ROM_REGION16_BE( 0x80, "eeprom", 0 ) /* EEPROM default contents */
	ROM_LOAD( "93c46.7k",  0x000000, 0x000080, CRC(e7029938) SHA1(ae41340dbcb600debe246629dc36fb371d1a5b05) )

	ROM_REGION( 0x2000, "m48t58", 0 ) /* timekeeper SRAM */
	ROM_LOAD( "dallas.5e",  0x000000, 0x002000, CRC(5b74eafd) SHA1(afbf5f1f5a27407fd6f17c764bbb7fae4ab779f5) )

	DISK_REGION( "cdrom" )
	DISK_IMAGE_READONLY( "heatof11", 0, BAD_DUMP SHA1(5a0a2782cd8676d3f6dfad4e0f805b309e230d8b) )
ROM_END

ROM_START( evilngt )
	ROM_REGION64_BE( 0x200000, "boot", 0 )
	ROM_LOAD16_WORD( "636a01.8q", 0x000000, 0x200000, CRC(7b1dc738) SHA1(32ae8e7ddd38fcc70b4410275a2cc5e9a0d7d33b) )

	ROM_REGION16_BE( 0x80, "eeprom", 0 ) /* EEPROM default contents */
	ROM_LOAD( "93c46.7k", 0x000000, 0x000080, CRC(60ae825e) SHA1(fd61db9667c53dd12700a0fe202fcd1e3d35d206) )

	ROM_REGION( 0x2000, "m48t58", 0 ) /* timekeeper SRAM */
	ROM_LOAD( "m48t58y.9n", 0x000000, 0x002000, CRC(e887ca1f) SHA1(54205f01b1ceba1d5f4d979fc30be1add8116e90) )

	ROM_REGION( 0x400000, "ymz", 0 ) /* YMZ280B sound rom on sub board */
	ROM_LOAD( "810a03.16h", 0x000000, 0x400000, CRC(05112d3a) SHA1(0df2a167b7bc08a32d983b71614d59834efbfb59) )

	DISK_REGION( "cdrom" )
	DISK_IMAGE_READONLY( "810uba02", 0, SHA1(e570470c1cbfe187d5bba8125616412f386264ba) )
ROM_END

ROM_START( evilngte )
	ROM_REGION64_BE( 0x200000, "boot", 0 )
	ROM_LOAD16_WORD( "636a01.8q", 0x000000, 0x200000, CRC(7b1dc738) SHA1(32ae8e7ddd38fcc70b4410275a2cc5e9a0d7d33b) )

	ROM_REGION( 0x2000, "m48t58", 0 ) /* timekeeper SRAM */
	ROM_LOAD( "m48t58y.u1", 0x000000, 0x001000, CRC(169bb8f4) SHA1(55c0bafab5d309fe69156489186e232aa87ca0dd) )

	ROM_REGION( 0x400000, "ymz", 0 ) /* YMZ280B sound rom on sub board */
	ROM_LOAD( "810a03.16h", 0x000000, 0x400000, CRC(05112d3a) SHA1(0df2a167b7bc08a32d983b71614d59834efbfb59) )

	// TODO: Add CHD
ROM_END

ROM_START( hellngt )
	ROM_REGION64_BE( 0x200000, "boot", 0 )
	ROM_LOAD16_WORD( "636a01.8q", 0x000000, 0x200000, CRC(7b1dc738) SHA1(32ae8e7ddd38fcc70b4410275a2cc5e9a0d7d33b) )

	ROM_REGION16_BE( 0x80, "eeprom", 0 ) /* EEPROM default contents */
	ROM_LOAD( "93c46.7k",    0x000000, 0x000080, CRC(53b41f68) SHA1(f75f59808a5b04b1e49f2cca0592a2466b82f019) )

	ROM_REGION( 0x2000, "m48t58", 0 )
	ROM_LOAD( "m48t58y.9n",  0x000000, 0x002000, CRC(ff8e78a1) SHA1(02e56f55264dd0bf3a08808726a6366e9cb6031e) )

	ROM_REGION( 0x400000, "ymz", 0 ) /* YMZ280B sound rom on sub board */
	ROM_LOAD( "810a03.16h",  0x000000, 0x400000, CRC(05112d3a) SHA1(0df2a167b7bc08a32d983b71614d59834efbfb59) )

	DISK_REGION( "cdrom" )
	DISK_IMAGE_READONLY( "810eaa02", 0, SHA1(d701b900eddc7674015823b2cb33e887bf107fa8) )
ROM_END

ROM_START( totlvice )
	ROM_REGION64_BE( 0x200000, "boot", 0 )
	ROM_LOAD16_WORD( "623b01.8q", 0x000000, 0x200000, CRC(bd879f93) SHA1(e2d63bfbd2b15260a2664082652442eadea3eab6) )

	ROM_REGION16_BE( 0x80, "eeprom", 0 )
	ROM_LOAD( "93c46.7k", 0x000000, 0x000080, CRC(25aa0bd1) SHA1(cc461e0629ff71c3a868882f1f67af0e19135c1a) )

	ROM_REGION( 0x100000, "ymz", 0 ) /* YMZ280B sound rom on sub board */
	ROM_LOAD( "639jaa02.bin",  0x000000, 0x100000, CRC(c6163818) SHA1(b6f8f2d808b98610becc0a5be5443ece3908df0b) )

	// was converted from the following cue/bin pair, is this sufficient / good for this platform? - there are a lot of audio tracks that need verifying as non-corrupt
	//ROM_LOAD( "TotalVice-GQ639-EBA01.cue",  0, 0x00000555, CRC(55ef2f62) SHA1(8e31b3e62244e6090a93228dae377552340dcdeb) )
	//ROM_LOAD( "TotalVice-GQ639-EBA01.bin",  0, 0x1ec4db10, CRC(5882f8ba) SHA1(e589d500d99d2f4cff4506cd5ac9a5bfc8d30675) )
	DISK_REGION( "cdrom" )
	DISK_IMAGE_READONLY( "639eba01", 0, BAD_DUMP SHA1(d95c13575e015169b126f7e8492d150bd7e5ebda) )
ROM_END

#if 0
// NB: Dumped by Phil, hasn't been converted to CHD yet
ROM_START( totlvicd )
	ROM_REGION64_BE( 0x200000, "boot", 0 )
	ROM_LOAD16_WORD( "623b01.8q", 0x000000, 0x200000, CRC(bd879f93) SHA1(e2d63bfbd2b15260a2664082652442eadea3eab6) )

	ROM_REGION( 0x100000, "ymz", 0 ) /* YMZ280B sound rom on sub board */
	ROM_LOAD( "639jaa02.bin",  0x000000, 0x100000, CRC(c6163818) SHA1(b6f8f2d808b98610becc0a5be5443ece3908df0b) )

	DISK_REGION( "cdrom" )
	DISK_IMAGE_READONLY( "639ead01", 0, SHA1(9d1085281aeb14185e2e78f3f21e7004a591039c) )
ROM_END
#endif

ROM_START( totlvicu )
	ROM_REGION64_BE( 0x200000, "boot", 0 )
	ROM_LOAD16_WORD( "623b01.8q", 0x000000, 0x200000, CRC(bd879f93) SHA1(e2d63bfbd2b15260a2664082652442eadea3eab6) )

	ROM_REGION( 0x100000, "ymz", 0 ) /* YMZ280B sound rom on sub board */
	ROM_LOAD( "639jaa02.bin",  0x000000, 0x100000, CRC(c6163818) SHA1(b6f8f2d808b98610becc0a5be5443ece3908df0b) )

	DISK_REGION( "cdrom" )
	DISK_IMAGE_READONLY( "639uac01", 0, BAD_DUMP SHA1(88431b8a0ce83c156c8b19efbba1af901b859404) )
ROM_END

ROM_START( totlvica )
	ROM_REGION64_BE( 0x200000, "boot", 0 )
	ROM_LOAD16_WORD( "623b01.8q", 0x000000, 0x200000, CRC(bd879f93) SHA1(e2d63bfbd2b15260a2664082652442eadea3eab6) )

	ROM_REGION( 0x100000, "ymz", 0 ) /* YMZ280B sound rom on sub board */
	ROM_LOAD( "639jaa02.bin",  0x000000, 0x100000, CRC(c6163818) SHA1(b6f8f2d808b98610becc0a5be5443ece3908df0b) )

	DISK_REGION( "cdrom" )
	DISK_IMAGE_READONLY( "639aab01", 0, SHA1(34f34b26399cc04ffb0207df69f52eba42892eb6) )
ROM_END

ROM_START( totlvicj )
	ROM_REGION64_BE( 0x200000, "boot", 0 )
	ROM_LOAD16_WORD( "623b01.8q", 0x000000, 0x200000, CRC(bd879f93) SHA1(e2d63bfbd2b15260a2664082652442eadea3eab6) )

	ROM_REGION( 0x100000, "ymz", 0 ) /* YMZ280B sound rom on sub board */
	ROM_LOAD( "639jaa02.bin",  0x000000, 0x100000, CRC(c6163818) SHA1(b6f8f2d808b98610becc0a5be5443ece3908df0b) )

	DISK_REGION( "cdrom" ) // Need a re-image
	DISK_IMAGE_READONLY( "639jad01", 0, BAD_DUMP SHA1(39d41d5a9d1c40636d174c8bb8172b1121e313f8) )
ROM_END

#if 0 // FIXME
ROM_START( 3do_m2 )
	ROM_REGION64_BE( 0x100000, "boot", 0 )
	ROM_SYSTEM_BIOS( 0, "panafz35", "Panasonic FZ-35S (3DO M2)" )
	ROMX_LOAD( "fz35_jpn.bin", 0x000000, 0x100000, CRC(e1c5bfd3) SHA1(0a3e27d672be79eeee1d2dc2da60d82f6eba7934), ROM_BIOS(1) )
ROM_END
#endif

/*************************************
 *
 *  Driver initialization
 *
 *************************************/

void konamim2_state::install_m48t58()
{
	read8sm_delegate read_delegate(*m_m48t58, FUNC(m48t58_device::read));
	write8sm_delegate write_delegate(*m_m48t58, FUNC(m48t58_device::write));

	m_ppc1->space(AS_PROGRAM).install_readwrite_handler(0x36c00000, 0x36c03fff, read_delegate, write_delegate, 0xff00ff00ff00ff00ULL);
	m_ppc2->space(AS_PROGRAM).install_readwrite_handler(0x36c00000, 0x36c03fff, read_delegate, write_delegate, 0xff00ff00ff00ff00ULL);
}

void konamim2_state::install_ymz280b()
{
	read8sm_delegate read_delegate(*m_ymz280b, FUNC(ymz280b_device::read));
	write8sm_delegate write_delegate(*m_ymz280b, FUNC(ymz280b_device::write));

	m_ppc1->space(AS_PROGRAM).install_readwrite_handler(0x3e800000, 0x3e80000f, read_delegate, write_delegate, 0xff00ff0000000000ULL);
	m_ppc2->space(AS_PROGRAM).install_readwrite_handler(0x3e800000, 0x3e80000f, read_delegate, write_delegate, 0xff00ff0000000000ULL);
}

void konamim2_state::init_totlvice()
{
	install_ymz280b();
}

void konamim2_state::init_btltryst()
{
	install_m48t58();
}

void konamim2_state::init_hellngt()
{
	install_m48t58();
	install_ymz280b();
}



/*************************************
 *
 *  Game driver(s)
 *
 *************************************/

GAME( 1997, polystar,  0,        polystar, polystar, konamim2_state, empty_init,    ROT0, "Konami", "Tobe! Polystars (ver JAA)",    MACHINE_IMPERFECT_TIMING | MACHINE_IMPERFECT_SOUND )
GAME( 1997, totlvice,  0,        totlvice, totlvice, konamim2_state, init_totlvice, ROT0, "Konami", "Total Vice (ver EBA)",         MACHINE_IMPERFECT_TIMING )
//GAME( 1997, totlvicd, totlvice, totlvice, totlvice, konamim2_state, init_totlvice, ROT0, "Konami", "Total Vice (ver EAD)",         MACHINE_NOT_WORKING | MACHINE_IMPERFECT_TIMING )
GAME( 1997, totlvicj,  totlvice, totlvice, totlvice, konamim2_state, init_totlvice, ROT0, "Konami", "Total Vice (ver JAD)",         MACHINE_NOT_WORKING | MACHINE_IMPERFECT_TIMING )
GAME( 1997, totlvica,  totlvice, totlvice, totlvice, konamim2_state, init_totlvice, ROT0, "Konami", "Total Vice (ver AAB)",         MACHINE_NOT_WORKING | MACHINE_IMPERFECT_TIMING )
GAME( 1997, totlvicu,  totlvice, totlvice, totlvice, konamim2_state, init_totlvice, ROT0, "Konami", "Total Vice (ver UAC)",         MACHINE_NOT_WORKING | MACHINE_IMPERFECT_TIMING )
GAME( 1998, btltryst,  0,        btltryst, btltryst, konamim2_state, init_btltryst, ROT0, "Konami", "Battle Tryst (ver JAC)",       MACHINE_NOT_WORKING | MACHINE_IMPERFECT_TIMING | MACHINE_IMPERFECT_GRAPHICS )
//GAME( 1998, btltrysta, btltryst, btltryst, btltryst, konamim2_state, init_btltryst, ROT0, "Konami", "Battle Tryst (ver JAA)",       MACHINE_NOT_WORKING | MACHINE_IMPERFECT_TIMING | MACHINE_IMPERFECT_GRAPHICS )
GAME( 1998, heatof11,  0,        heatof11, heatof11, konamim2_state, init_btltryst, ROT0, "Konami", "Heat of Eleven '98 (ver EAA)", MACHINE_NOT_WORKING | MACHINE_IMPERFECT_TIMING | MACHINE_IMPERFECT_GRAPHICS)
GAME( 1998, evilngt,   0,        evilngt,  hellngt,  konamim2_state, init_hellngt,  ROT0, "Konami", "Evil Night (ver UBA)",         MACHINE_IMPERFECT_TIMING )
GAME( 1998, evilngte,  evilngt,  evilngt,  hellngt,  konamim2_state, init_hellngt,  ROT0, "Konami", "Evil Night (ver EAA)",         MACHINE_NOT_WORKING | MACHINE_IMPERFECT_TIMING )
GAME( 1998, hellngt,   evilngt,  hellngt,  hellngt,  konamim2_state, init_hellngt,  ROT0, "Konami", "Hell Night (ver EAA)",         MACHINE_IMPERFECT_TIMING )

//CONS( 199?, 3do_m2,     0,      0,    3do_m2,    m2,    driver_device, 0,      "3DO",  "3DO M2",    MACHINE_NOT_WORKING | MACHINE_IMPERFECT_TIMING | MACHINE_NO_SOUND )


/*************************************
 *
 *  Debugging Aids
 *
 *************************************/

void konamim2_state::debug_help_command(int ref, const std::vector<std::string> &params)
{
	debugger_console &con = machine().debugger().console();

	con.printf("Available M2 commands:\n");
	con.printf("  konm2 dump_task,<address> -- Dump task object at <address>\n");
	con.printf("  konm2 dump_dspp,<address> -- Dump DSPP object at <address>\n");
}

void konamim2_state::debug_commands(int ref, const std::vector<std::string> &params)
{
	if (params.size() < 1)
		return;

	if (params[0] == "help")
		debug_help_command(ref, params);
	else if (params[0] == "dump_task")
		dump_task_command(ref, params);
	else if (params[0] == "dump_dspp")
		subdevice<dspp_device>("bda:dspp")->dump_state();
}

void konamim2_state::dump_task_command(int ref, const std::vector<std::string> &params)
{
	typedef uint32_t   Item;
	typedef uint32_t   m2ptr;

	typedef struct TimerTicks
	{
		uint32_t tt_Hi;
		uint32_t tt_Lo;
	} TimerTicks;

	struct ItemNode
	{
		m2ptr pn_Next;    /* pointer to next in list              */ // 0
		m2ptr pn_Prev;    /* pointer to previous in list          */ // 4
		uint8_t     n_SubsysType;     /* what component manages this node     */ // 8
		uint8_t     n_Type;           /* what type of node for the component  */ // 9
		uint8_t     n_Priority;       /* queueing priority                    */ // A
		uint8_t     n_Flags;          /* misc flags, see below                */ // B
		int32_t     n_Size;           /* total size of node including hdr     */ // C
		m2ptr    pn_Name;           /* name of item, or NULL                */ // 10
		uint8_t     n_Version;        /* version of of this Item              */ // 14
		uint8_t     n_Revision;       /* revision of this Item                */ // 15
		uint8_t     n_Reserved0;      /* reserved for future use              */ // 16
		uint8_t     n_ItemFlags;      /* additional system item flags         */ // 17
		Item      n_Item;           /* Item number representing this struct */ //18
		Item      n_Owner;          /* creator, present owner, disposer     */ // 1C
		m2ptr     pn_Reserved1;      /* reserved for future use              */ // 20
	};

	struct Task
	{
		ItemNode     t;
		m2ptr       pt_ThreadTask;      /* I am a thread of what task?  */
		uint32_t     t_WaitBits;        /* signals being waited for     */
		uint32_t     t_SigBits;         /* signals received             */
		uint32_t     t_AllocatedSigs;   /* signals allocated            */
		m2ptr        pt_StackBase;       /* base of stack                */
		int32_t      t_StackSize;       /* size of stack                */
		uint32_t     t_MaxUSecs;        /* quantum length in usecs      */
		TimerTicks   t_ElapsedTime;     /* time spent running this task */
		uint32_t     t_NumTaskLaunch;   /* # times launched this task   */
		uint32_t     t_Flags;           /* task flags                   */
		Item         t_Module;          /* the module we live within    */
		Item         t_DefaultMsgPort;  /* default task msgport         */
		m2ptr         pt_UserData;        /* user-private data            */
	};

	debugger_console &con = machine().debugger().console();
	address_space &space = m_ppc1->space();
	uint64_t addr;
	offs_t address;

	if (params.size() < 1)
		return;

	if (!machine().debugger().commands().validate_number_parameter(params[1], addr))
		return;

	address = (offs_t)addr;
	address = 0x40FB54E8;
	if (!m_ppc1->translate(AS_PROGRAM, TRANSLATE_READ_DEBUG, address))
	{
		con.printf("Address is unmapped.\n");
		return;
	}

	Task task;

	task.t.pn_Next = space.read_dword(address + offsetof(ItemNode, pn_Next));
	task.t.pn_Prev = space.read_dword(address + offsetof(ItemNode, pn_Prev));
	task.t.n_SubsysType = space.read_byte(address + offsetof(ItemNode, n_SubsysType));
	task.t.n_Type = space.read_byte(address + offsetof(ItemNode, n_Type));
	task.t.n_Priority = space.read_byte(address + offsetof(ItemNode, n_Priority));
	task.t.n_Flags = space.read_byte(address + offsetof(ItemNode, n_Flags));
	task.t.n_Size = space.read_dword(address + offsetof(ItemNode, n_Size));
	task.t.pn_Name = space.read_dword(address + offsetof(ItemNode, pn_Name));

	char name[128];
	char *ptr = name;
	uint32_t nameptr = task.t.pn_Name;

	do
	{
		*ptr = space.read_byte(nameptr++);
	} while (*ptr++ != 0);

	task.t.n_Version = space.read_byte(address + offsetof(ItemNode, n_Version));
	task.t.n_Revision = space.read_byte(address + offsetof(ItemNode, n_Revision));
	task.t.n_Reserved0 = space.read_byte(address + offsetof(ItemNode, n_Reserved0));
	task.t.n_ItemFlags = space.read_byte(address + offsetof(ItemNode, n_ItemFlags));
	task.t.n_Item = space.read_dword(address + offsetof(ItemNode, n_Item));
	task.t.n_Owner = space.read_dword(address + offsetof(ItemNode, n_Owner));
	task.t.pn_Reserved1 = space.read_dword(address + offsetof(ItemNode, pn_Reserved1));

	task.pt_ThreadTask = space.read_dword(address + offsetof(Task, pt_ThreadTask));
	task.t_WaitBits = space.read_dword(address + offsetof(Task, t_WaitBits));
	task.t_SigBits = space.read_dword(address + offsetof(Task, t_SigBits));
	task.t_AllocatedSigs = space.read_dword(address + offsetof(Task, t_AllocatedSigs));
	task.pt_StackBase = space.read_dword(address + offsetof(Task, pt_StackBase));
	task.t_StackSize = space.read_dword(address + offsetof(Task, t_StackSize));
	task.t_MaxUSecs = space.read_dword(address + offsetof(Task, t_MaxUSecs));
	task.t_ElapsedTime.tt_Hi = space.read_dword(address + offsetof(Task, t_ElapsedTime)+0);
	task.t_ElapsedTime.tt_Lo = space.read_dword(address + offsetof(Task, t_ElapsedTime)+4);
	task.t_NumTaskLaunch = space.read_dword(address + offsetof(Task, t_NumTaskLaunch));
	task.t_Flags = space.read_dword(address + offsetof(Task, t_Flags));
	task.t_Module = space.read_dword(address + offsetof(Task, t_Module));
	task.t_DefaultMsgPort = space.read_dword(address + offsetof(Task, t_DefaultMsgPort));
	task.pt_UserData = space.read_dword(address + offsetof(Task, pt_UserData));

//  m2ptr       pt_ThreadTask;      /* I am a thread of what task?  */
//  uint32_t     t_WaitBits;        /* signals being waited for     */
//  uint32_t     t_SigBits;         /* signals received             */
//  uint32_t     t_AllocatedSigs;   /* signals allocated            */
//  m2ptr        pt_StackBase;       /* base of stack                */
//  int32_t      t_StackSize;       /* size of stack                */
//  uint32_t     t_MaxUSecs;        /* quantum length in usecs      */
//  TimerTicks   t_ElapsedTime;     /* time spent running this task */
//  uint32_t     t_NumTaskLaunch;   /* # times launched this task   */
//  uint32_t     t_Flags;           /* task flags                   */
//  Item         t_Module;          /* the module we live within    */
//  Item         t_DefaultMsgPort;  /* default task msgport         */
//  m2ptr         pt_UserData;        /* user-private data            */

	con.printf("**** Task Info @ %08X ****\n", address);
	con.printf("Next:        %08X\n", task.t.pn_Next);
	con.printf("Prev:        %08X\n", task.t.pn_Prev);
	con.printf("SubsysType:  %X\n", task.t.n_SubsysType);
	con.printf("Type:        %X\n", task.t.n_Type);
	con.printf("Priority:    %X\n", task.t.n_Priority);
	con.printf("Flags:       %X\n", task.t.n_Flags);
	con.printf("Size:        %08X\n", task.t.n_Size);
	con.printf("Name:        %s\n", name);
	con.printf("Version:     %X\n", task.t.n_Version);
	con.printf("Revision:    %X\n", task.t.n_Revision);
	con.printf("Reserved0:   %X\n", task.t.n_Reserved0);
	con.printf("ItemFlags:   %X\n", task.t.n_ItemFlags);
	con.printf("Item:        %08X\n", task.t.n_Item);
	con.printf("Owner:       %08X\n", task.t.n_Owner);
	con.printf("Reserved1:   %08X\n", task.t.pn_Reserved1);
	con.printf("ThreadTask:  %08X\n", task.pt_ThreadTask);
	con.printf("WaitBits:    %08X\n", task.t_WaitBits);
	con.printf("SigBits:     %08X\n", task.t_SigBits);
	con.printf("AllocSigs:   %08X\n", task.t_AllocatedSigs);
	con.printf("StackBase:   %08X\n", task.pt_StackBase);
	con.printf("StackSize:   %08X\n", task.t_StackSize);
	con.printf("MaxUSecs:    %08X\n", task.t_MaxUSecs);
	con.printf("ElapsedTime: %016llu\n", (uint64_t)task.t_ElapsedTime.tt_Lo + ((uint64_t)task.t_ElapsedTime.tt_Hi << 32ull));
	con.printf("NumTaskLaunch:  %u\n", task.t_NumTaskLaunch);
	con.printf("Flags:          %08X\n", task.t_Flags);
	con.printf("Module:         %08X\n", task.t_Module);
	con.printf("DefaultMsgPort: %08X\n", task.t_DefaultMsgPort);
	con.printf("UserData:       %08X\n", task.pt_UserData);
	con.printf("\n");
}