summaryrefslogtreecommitdiffstatshomepage
path: root/src/mame/drivers/qix.cpp
blob: 3696c79fcb0399c6937aff2cb5f1b687fc644d76 (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
// license:BSD-3-Clause
// copyright-holders:Aaron Giles, Zsolt Vasvari
// thanks-to: John Butler, Ed Mueller
/***************************************************************************

    Taito Qix hardware

    Games supported:
        * Qix (3 sets)
        * Qix II Tournament
        * Zookeeper (3 sets)
        * Space Dungeon
        * Kram (3 sets, one encrypted)
        * The Electric Yo-Yo (2 sets)
        * Slither (2 sets)
        * Complex X

    Known bugs:
        * none at this time

    Notes:
        * the encrypted version of Kram doesn't have the protection MCU
        * it's not clear what the 16R4 PAL does.
        * Electric Yo-Yo was hanging in attract mode because of a synchronization issue.
          This was fixed by increasing the interleave to 20.
          The reason for the hang was that CPU #2 was reading location $8013 of shared
          RAM after clearing it and before CPU #1 had put the correct value in it.

    TODO:
        * The Kram encryption algorithm is not understood. I merely provide tables to
          decrypt it, derived by comparison with the not encrypted versions.

          According to the QIX and Kram schematics, these games should be using 68A90Es.
          The 6809E has a 'Last Instruction Cycle' pin that is likely tied in with the encryption:
          "LIC is HIGH during the last cycle of every instruction and its transition from
          HIGH to LOW will indicate that the first byte of an opcode will be latched at
          the end of the present bus cycle"

        * I applied the interleave change only to elecyoyo because these games are
          really sensitive to timing, and kram's service mode was disturbed by it (the
          high score and audit pages were broken).

****************************************************************************

    Memory map

****************************************************************************

Video CPU:
----------
All but Zookeeper:

Address          Dir Data     Name        Description
---------------- --- -------- ----------- -----------------------
100000xxxxxxxxxx R/W xxxxxxxx DS0         dual port RAM (shared with video CPU)
100001xxxxxxxxxx R/W xxxxxxxx             local RAM
100010---------x R/W xxxxxxxx DS2         6850 ACIA [1]
100011---------0 R/W -------- DS3         assert FIRQ on video CPU
100011---------1 R/W -------- DS3         FIRQ acknowledge
100100--------xx R/W xxxxxxxx DS4/U20     6821 PIA (sound control / data IRQ)
100101--------xx R/W xxxxxxxx DS5/U11     6821 PIA (coin / player 1 inputs)
100110-1------xx R/W xxxxxxxx DS6/U20     6821 PIA (spare / player 2 inputs)
100110xxxxxxxx-- R/W ----xxxx DS6/U24     PAL 16R4 (purpose unclear)
100111--------xx R/W xxxxxxxx DS7/U30     6821 PIA (player 2 inputs / coin control)
101xxxxxxxxxxxxx R   xxxxxxxx             program ROM
11xxxxxxxxxxxxxx R   xxxxxxxx             program ROM

Zookeeper is almost the same, just the top bit of the address is inverted most of
the time to make space for more ROM.

Address          Dir Data     Name        Description
---------------- --- -------- ----------- -----------------------
000000xxxxxxxxxx R/W xxxxxxxx DS0         dual port RAM (shared with video CPU)
000001xxxxxxxxxx R/W xxxxxxxx             local RAM
000010---------x R/W xxxxxxxx DS2         6850 ACIA [1]
000011---------0 R/W -------- DS3         assert FIRQ on video CPU
000011---------1 R/W -------- DS3         FIRQ acknowledge
000100--------xx R/W xxxxxxxx DS4/U20     6821 PIA (sound control / data IRQ)
000101--------xx R/W xxxxxxxx DS5/U11     6821 PIA (coin / player 1 inputs)
000110-1------xx R/W xxxxxxxx DS6/U20     6821 PIA (spare / player 2 inputs)
100110xxxxxxxx-- R/W ----xxxx DS6/U24     PAL 16R4 (purpose unclear)
000111--------xx R/W xxxxxxxx DS7/U30     6821 PIA (player 2 inputs / coin control)
1xxxxxxxxxxxxxxx R   xxxxxxxx             program ROM

[1] Diagnostic purposes only, not used

Interrupts:
    NMI not connected
    IRQ generated by pia_3
    FIRQ generated by CPU #2


Video CPU:
----------

Address          Dir Data     Name        Description
---------------- --- -------- ----------- -----------------------
0xxxxxxxxxxxxxxx R/W xxxxxxxx             direct video RAM access
100000xxxxxxxxxx R/W xxxxxxxx VS0         dual port RAM (shared with data CPU)
100001xxxxxxxxxx R/W xxxxxxxx VS1         CMOS NVRAM
100010----------   W xxxxxx-- VS2         self test LEDs      [1]
100010----------   W ------xx VS2         palette bank select [1]
100011---------0 R/W -------- VS3         assert FIRQ on data CPU
100011---------1 R/W -------- VS3         FIRQ acknowledge
100100xxxxxxxxxx R/W xxxxxxxx VS4         palette RAM (RRGGBBII)
100101--------00 R/W xxxxxxxx VS5         video RAM access at latched address
100101--------01 R/W xxxxxxxx             video RAM access mask [2]
100101--------1x   W xxxxxxxx VS5         video RAM address latch
100110---------- R   xxxxxxxx VS6         current scanline
100111---------x R/W xxxxxxxx VS7         68A45 video controller
11xxxxxxxxxxxxxx R   xxxxxxxx             program ROMs

Zookeeper has some more ROMs (banked):
100010--------01   W -----x--             ROM bank select [1]
101xxxxxxxxxxxxx R   xxxxxxxx             banked program ROMs

[1] The Zookeeper extension is handled in the ROM expansion board, without
    changes to the main board. This means that the ROM bank select address is
    also a mirror for the LEDs/palette bank latch. That's why they used bit 2,
    this way they could copy the palette bank in the low two bits when changing
    the ROM bank and avoid problems.
[2] Slither only. This hardware feature is NOT present in the Taito games.

Interrupts:
    NMI not connected
    IRQ not connected
    FIRQ generated by CPU #1


Audio CPU:
----------
Slither doesn't have the third CPU and has different audio hardware.

Address          Dir Data     Name        Description
---------------- --- -------- ----------- -----------------------
000000000xxxxxxx R/W xxxxxxxx             6802 internal RAM
0-1-----------xx R/W xxxxxxxx U7          6821 PIA (TMS5200 control) [2]
01------------xx R/W xxxxxxxx U8          6821 PIA (DAC, communication with data CPU)
1100------------                          n.c.
1101xxxxxxxxxxxx R   xxxxxxxx U25         program ROM [1]
1110xxxxxxxxxxxx R   xxxxxxxx U26         program ROM [1]
1111xxxxxxxxxxxx R   xxxxxxxx U27         program ROM [1]

[1] In older games (qix, kram, elecyoyo) ROMs are half size and mapped at E800-FFFF
[2] Not used by any game

Interrupts:
    NMI not connected
    IRQ generated by pia_4

****************************************************************************

    Qix uses two 6809 CPUs: one for data and audio and the other for
    video. Communication between the two CPUs is done using a 4K RAM
    space at $8000 (for ZooKeeper the data cpu maps it at $0000 and the
    video cpu at $8000) which both CPUs have direct access. FIRQs (fast
    interrupts) are generated by each CPU to interrupt the other at
    specific times.

    A third CPU, a 6802, is used for sample playback. It drives an 8-bit
    DAC and according to the schematics a TMS5220 speech chip, which is
    never accessed. ROM u27 is the only code needed. A audio command from
    the data CPU causes an IRQ to fire on the 6802 and the audio playback
    is started.

    The coin door switches and player controls are connected to the CPUs
    by Mototola 6821 PIAs. These devices are memory mapped as shown below.

    The screen is 256x256 with eight bit pixels (64K). The screen is
    divided into two halves each half mapped by the video CPU at
    $0000-$7FFF. The high order bit of the address latch at $9402
    specifies which half of the screen is being accessed.

    Timing is critical in the hardware. Communications between the data,
    video, and audio CPUs are all very sensitive.

    The address latch works as follows. When the video CPU accesses $9400,
    the screen address is computed by using the values at $9402 (high byte)
    and $9403 (low byte) to get a value between $0000-$FFFF. The value at
    that location is either returned or written.

    The scan line at $9800 on the video CPU records where the scan line is
    on the display (0-255). Several places in the ROM code wait until the
    scan line reaches zero before continuing.

****************************************************************************

    QIX NONVOLATILE CMOS MEMORY MAP (CPU #2 -- Video) $8400-$87ff
        $86A9 - $86AA:  When CMOS is valid, these bytes are $55AA
        $86AC - $86C3:  AUDIT TOTALS -- 4 4-bit BCD digits per setting
                        (All totals default to: 0000)
                        $86AC: TOTAL PAID CREDITS
                        $86AE: LEFT COINS
                        $86B0: CENTER COINS
                        $86B2: RIGHT COINS
                        $86B4: PAID CREDITS
                        $86B6: AWARDED CREDITS
                        $86B8: % FREE PLAYS
                        $86BA: MINUTES PLAYED
                        $86BC: MINUTES AWARDED
                        $86BE: % FREE TIME
                        $86C0: AVG. GAME [SEC]
                        $86C2: HIGH SCORES
        $86C4 - $86FF:  High scores -- 10 scores/names, consecutive in memory
                        Six 4-bit BCD digits followed by 3 ascii bytes
                        (Default: 030000 QIX)
        $8700        :  LANGUAGE SELECT (Default: $32)
                        ENGLISH = $32  FRANCAIS = $33  ESPANOL = $34  DEUTSCH = $35
        $87D9 - $87DF:  COIN SLOT PROGRAMMING -- 2 4-bit BCD digits per setting
                        $87D9: STANDARD COINAGE SETTING  (Default: 01)
                        $87DA: COIN MULTIPLIERS LEFT (Default: 01)
                        $87DB: COIN MULTIPLIERS CENTER (Default: 04)
                        $87DC: COIN MULTIPLIERS RIGHT (Default: 01)
                        $87DD: COIN UNITS FOR CREDIT (Default: 01)
                        $87DE: COIN UNITS FOR BONUS (Default: 00)
                        $87DF: MINIMUM COINS (Default: 00)
        $87E0 - $87EA:  LOCATION PROGRAMMING -- 2 4-bit BCD digits per setting
                        $87E0: BACKUP HSTD [0000] (Default: 03)
                        $87E1: MAXIMUM CREDITS (Default: 10)
                        $87E2: NUMBER OF TURNS (Default: 03)
                        $87E3: THRESHOLD (Default: 75)
                        $87E4: TIME LINE (Default: 37)
                        $87E5: DIFFICULTY 1 (Default: 01)
                        $87E6: DIFFICULTY 2 (Default: 01)
                        $87E7: DIFFICULTY 3 (Default: 01)
                        $87E8: DIFFICULTY 4 (Default: 01)
                        $87E9: ATTRACT SOUND (Default: 01)
                        $87EA: TABLE MODE (Default: 00)

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

#include "emu.h"
#include "includes/qix.h"

#include "rendlay.h"
#include "machine/nvram.h"

#include "elecyoyo.lh"



/*************************************
 *
 *  Data CPU memory handlers
 *
 *************************************/

void qix_state::main_map(address_map &map)
{
	map(0x8000, 0x83ff).ram().share("share1");
	map(0x8400, 0x87ff).ram();
	map(0x8800, 0x8bff).nopr();   /* 6850 ACIA */
	map(0x8c00, 0x8c00).mirror(0x3fe).rw(this, FUNC(qix_state::qix_video_firq_r), FUNC(qix_state::qix_video_firq_w));
	map(0x8c01, 0x8c01).mirror(0x3fe).rw(this, FUNC(qix_state::qix_data_firq_ack_r), FUNC(qix_state::qix_data_firq_ack_w));
	map(0x9000, 0x93ff).rw(m_sndpia0, FUNC(pia6821_device::read), FUNC(pia6821_device::write));
	map(0x9400, 0x97ff).r(m_pia0, FUNC(pia6821_device::read)).w(this, FUNC(qix_state::qix_pia_w));
	map(0x9800, 0x9bff).rw(m_pia1, FUNC(pia6821_device::read), FUNC(pia6821_device::write));
	map(0x9c00, 0x9fff).rw(m_pia2, FUNC(pia6821_device::read), FUNC(pia6821_device::write));
	map(0xa000, 0xffff).rom();
}


void qix_state::kram3_main_map(address_map &map)
{
	map(0x8000, 0x83ff).ram().share("share1");
	map(0x8400, 0x87ff).ram();
	map(0x8800, 0x8bff).nopr();   /* 6850 ACIA */
	map(0x8c00, 0x8c00).mirror(0x3fe).rw(this, FUNC(qix_state::qix_video_firq_r), FUNC(qix_state::qix_video_firq_w));
	map(0x8c01, 0x8c01).mirror(0x3fe).rw(this, FUNC(qix_state::qix_data_firq_ack_r), FUNC(qix_state::qix_data_firq_ack_w));
	map(0x9000, 0x93ff).rw(m_sndpia0, FUNC(pia6821_device::read), FUNC(pia6821_device::write));
	map(0x9400, 0x97ff).r(m_pia0, FUNC(pia6821_device::read)).w(this, FUNC(qix_state::qix_pia_w));
	map(0x9800, 0x9bff).rw(m_pia1, FUNC(pia6821_device::read), FUNC(pia6821_device::write));
	map(0x9c00, 0x9fff).rw(m_pia2, FUNC(pia6821_device::read), FUNC(pia6821_device::write));
	map(0xa000, 0xffff).bankr("bank0");
}



void qix_state::zoo_main_map(address_map &map)
{
	map(0x0000, 0x03ff).ram().share("share1");
	map(0x0400, 0x07ff).ram();
	map(0x0800, 0x0bff).nopr();   /* ACIA */
	map(0x0c00, 0x0c00).mirror(0x3fe).rw(this, FUNC(qix_state::qix_video_firq_r), FUNC(qix_state::qix_video_firq_w));
	map(0x0c01, 0x0c01).mirror(0x3fe).rw(this, FUNC(qix_state::qix_data_firq_ack_r), FUNC(qix_state::qix_data_firq_ack_w));
	map(0x1000, 0x13ff).rw(m_sndpia0, FUNC(pia6821_device::read), FUNC(pia6821_device::write));
	map(0x1400, 0x17ff).r(m_pia0, FUNC(pia6821_device::read)).w(this, FUNC(qix_state::qix_pia_w));
	map(0x1800, 0x1bff).rw(m_pia1, FUNC(pia6821_device::read), FUNC(pia6821_device::write));
	map(0x1c00, 0x1fff).rw(m_pia2, FUNC(pia6821_device::read), FUNC(pia6821_device::write));
	map(0x8000, 0xffff).rom();
}



/*************************************
 *
 *  Input port definitions
 *
 *************************************/

#define COIN_PORT \
	PORT_BIT(0x01, IP_ACTIVE_LOW, IPT_SERVICE1 ) PORT_NAME("Test Advance") \
	PORT_BIT(0x02, IP_ACTIVE_LOW, IPT_SERVICE2 ) PORT_NAME("Test Next line") \
	PORT_BIT(0x04, IP_ACTIVE_LOW, IPT_SERVICE3 ) PORT_NAME("Test Slew Up") \
	PORT_BIT(0x08, IP_ACTIVE_LOW, IPT_SERVICE4 ) PORT_NAME("Test Slew Down") \
	PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_COIN1 ) \
	PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_COIN2 ) \
	PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_COIN3 ) \
	PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_TILT )


static INPUT_PORTS_START( qix )
	PORT_START("P1")    /* PIA 0 Port A (PLAYER 1) */
	PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_JOYSTICK_UP ) PORT_4WAY
	PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT ) PORT_4WAY
	PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN ) PORT_4WAY
	PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT ) PORT_4WAY
	PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_BUTTON2 )
	PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_START2 )
	PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_START1 )
	PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_BUTTON1 )

	PORT_START("COIN")  /* PIA 0 Port B (COIN) */
	COIN_PORT

	PORT_START("SPARE") /* PIA 1 Port A (SPARE) */
	PORT_BIT( 0xff, IP_ACTIVE_LOW, IPT_UNKNOWN )

	PORT_START("IN0")   /* PIA 1 Port B (PLAYER 1/2) */
	PORT_BIT( 0xff, IP_ACTIVE_LOW, IPT_UNKNOWN )

	PORT_START("P2")    /* PIA 2 Port A (PLAYER 2) */
	PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_JOYSTICK_UP ) PORT_4WAY PORT_COCKTAIL
	PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT ) PORT_4WAY PORT_COCKTAIL
	PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN ) PORT_4WAY PORT_COCKTAIL
	PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT ) PORT_4WAY PORT_COCKTAIL
	PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_BUTTON2 ) PORT_COCKTAIL
	PORT_BIT( 0x60, IP_ACTIVE_LOW, IPT_UNKNOWN )
	PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_BUTTON1 ) PORT_COCKTAIL
INPUT_PORTS_END


static INPUT_PORTS_START( sdungeon )
	PORT_START("P1")    /* PIA 0 Port A (PLAYER 1) */
	PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_JOYSTICKLEFT_UP ) PORT_8WAY
	PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_JOYSTICKLEFT_RIGHT ) PORT_8WAY
	PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_JOYSTICKLEFT_DOWN ) PORT_8WAY
	PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_JOYSTICKLEFT_LEFT ) PORT_8WAY
	PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_JOYSTICKRIGHT_UP ) PORT_8WAY
	PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_JOYSTICKRIGHT_RIGHT ) PORT_8WAY
	PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_JOYSTICKRIGHT_DOWN ) PORT_8WAY
	PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_JOYSTICKRIGHT_LEFT ) PORT_8WAY

	PORT_START("COIN")  /* PIA 0 Port B (COIN) */
	COIN_PORT

	PORT_START("SPARE") /* PIA 1 Port A (SPARE) */
	PORT_BIT( 0xff, IP_ACTIVE_LOW, IPT_UNKNOWN )

	PORT_START("IN0")   /* PIA 1 Port B (PLAYER 1/2) */
	PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_START1 )
	PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_START2 )
	PORT_BIT( 0xfc, IP_ACTIVE_LOW, IPT_UNKNOWN )

	PORT_START("P2")    /* PIA 2 Port A (PLAYER 2) */
	PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_JOYSTICKLEFT_UP ) PORT_8WAY PORT_COCKTAIL
	PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_JOYSTICKLEFT_RIGHT ) PORT_8WAY PORT_COCKTAIL
	PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_JOYSTICKLEFT_DOWN ) PORT_8WAY PORT_COCKTAIL
	PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_JOYSTICKLEFT_LEFT ) PORT_8WAY PORT_COCKTAIL
	PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_JOYSTICKRIGHT_UP ) PORT_8WAY PORT_COCKTAIL
	PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_JOYSTICKRIGHT_RIGHT ) PORT_8WAY PORT_COCKTAIL
	PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_JOYSTICKRIGHT_DOWN ) PORT_8WAY PORT_COCKTAIL
	PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_JOYSTICKRIGHT_LEFT ) PORT_8WAY PORT_COCKTAIL
INPUT_PORTS_END


static INPUT_PORTS_START( elecyoyo )
	PORT_START("P1")    /* PIA 0 Port A (PLAYER 1) */
	PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_JOYSTICK_UP ) PORT_4WAY
	PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT ) PORT_4WAY
	PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN ) PORT_4WAY
	PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT ) PORT_4WAY
	PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_UNKNOWN )
	PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_START2 )
	PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_START1 )
	PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_UNKNOWN )

	PORT_START("COIN")  /* PIA 0 Port B (COIN) */
	COIN_PORT

	PORT_START("SPARE") /* PIA 1 Port A (SPARE) */
	PORT_BIT( 0xff, IP_ACTIVE_LOW, IPT_UNKNOWN )

	PORT_START("IN0")   /* PIA 1 Port B (PLAYER 1/2) */
	PORT_BIT( 0xff, IP_ACTIVE_LOW, IPT_UNKNOWN )

	PORT_START("P2")    /* PIA 2 Port A (PLAYER 2) */
	PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_JOYSTICK_UP ) PORT_4WAY PORT_COCKTAIL
	PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT ) PORT_4WAY PORT_COCKTAIL
	PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN ) PORT_4WAY PORT_COCKTAIL
	PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT ) PORT_4WAY PORT_COCKTAIL
	PORT_BIT( 0xf0, IP_ACTIVE_LOW, IPT_UNKNOWN )
INPUT_PORTS_END


static INPUT_PORTS_START( kram )
	PORT_START("P1")    /* PIA 0 Port A (PLAYER 1) */
	PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_JOYSTICK_UP ) PORT_8WAY
	PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT ) PORT_8WAY
	PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN ) PORT_8WAY
	PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT ) PORT_8WAY
	PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_BUTTON2 )
	PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_START2 )
	PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_START1 )
	PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_BUTTON1 )

	PORT_START("COIN")  /* PIA 0 Port B (COIN) */
	COIN_PORT

	PORT_START("SPARE") /* PIA 1 Port A (SPARE) */
	PORT_BIT( 0xff, IP_ACTIVE_LOW, IPT_UNKNOWN )

	PORT_START("IN0")   /* PIA 1 Port B (PLAYER 1/2) */
	PORT_BIT( 0xff, IP_ACTIVE_LOW, IPT_UNKNOWN )

	PORT_START("P2")    /* PIA 2 Port A (PLAYER 2) */
	PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_JOYSTICK_UP ) PORT_8WAY PORT_COCKTAIL
	PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT ) PORT_8WAY PORT_COCKTAIL
	PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN ) PORT_8WAY PORT_COCKTAIL
	PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT ) PORT_8WAY PORT_COCKTAIL
	PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_BUTTON2 ) PORT_COCKTAIL
	PORT_BIT( 0x60, IP_ACTIVE_LOW, IPT_UNKNOWN )
	PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_BUTTON1 ) PORT_COCKTAIL
INPUT_PORTS_END


static INPUT_PORTS_START( zookeep )
	PORT_START("P1")    /* PIA 0 Port A (PLAYER 1) */
	PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_JOYSTICK_UP ) PORT_4WAY
	PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT ) PORT_4WAY
	PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN ) PORT_4WAY
	PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT ) PORT_4WAY
	PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_START1 )
	PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_START2 )
	PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_BUTTON1 )
	PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_UNKNOWN )

	PORT_START("COIN")  /* PIA 0 Port B (COIN) */
	COIN_PORT

	PORT_START("SPARE") /* PIA 1 Port A (SPARE) */
	PORT_BIT( 0xff, IP_ACTIVE_LOW, IPT_UNKNOWN )

	PORT_START("IN0")   /* PIA 1 Port B (PLAYER 1/2) */
	PORT_BIT( 0xff, IP_ACTIVE_LOW, IPT_UNKNOWN )

	PORT_START("P2")    /* PIA 2 Port A (PLAYER 2) */
	PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_JOYSTICK_UP ) PORT_4WAY PORT_COCKTAIL
	PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT ) PORT_4WAY PORT_COCKTAIL
	PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN ) PORT_4WAY PORT_COCKTAIL
	PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT ) PORT_4WAY PORT_COCKTAIL
	PORT_BIT( 0x30, IP_ACTIVE_LOW, IPT_UNKNOWN )
	PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_BUTTON1 ) PORT_COCKTAIL
	PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_UNKNOWN )
INPUT_PORTS_END


static INPUT_PORTS_START( slither )
	PORT_START("P1")    /* PIA 0 Port A (PLAYER 1) */
	PORT_BIT( 0x0f, IP_ACTIVE_LOW, IPT_UNUSED )
	PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_BUTTON2 )
	PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_START2 )
	PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_START1 )
	PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_BUTTON1 )

	PORT_START("COIN")  /* PIA 0 Port B (COIN) */
	PORT_SERVICE(0x01, IP_ACTIVE_LOW )
	PORT_BIT( 0x0e, IP_ACTIVE_LOW, IPT_UNUSED )
	PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_COIN1 )
	PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_COIN2 )
	PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_COIN3 )
	PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_TILT )

	PORT_START("P2")    /* PIA 3 Port A (PLAYER 2) */
	PORT_BIT( 0x0f, IP_ACTIVE_LOW, IPT_UNUSED )
	PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_BUTTON2 ) PORT_COCKTAIL
	PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_START2 ) PORT_COCKTAIL
	PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_START1 ) PORT_COCKTAIL
	PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_BUTTON1 ) PORT_COCKTAIL

	PORT_START("AN0")   /* PIA 1 Port A (TRACKBALL L/R) */
	PORT_BIT( 0xff, 0, IPT_TRACKBALL_X ) PORT_SENSITIVITY(50) PORT_KEYDELTA(10)

	PORT_START("AN1")   /* PIA 2 Port A (TRACKBALL U/D) */
	PORT_BIT( 0xff, 0, IPT_TRACKBALL_Y ) PORT_SENSITIVITY(50) PORT_KEYDELTA(10) PORT_REVERSE

	PORT_START("AN2")   /* PIA 1 Port A (TRACKBALL L/R) */
	PORT_BIT( 0xff, 0, IPT_TRACKBALL_X ) PORT_SENSITIVITY(50) PORT_KEYDELTA(10) PORT_COCKTAIL

	PORT_START("AN3")   /* PIA 2 Port A (TRACKBALL U/D) */
	PORT_BIT( 0xff, 0, IPT_TRACKBALL_Y ) PORT_SENSITIVITY(50) PORT_KEYDELTA(10) PORT_REVERSE PORT_COCKTAIL
INPUT_PORTS_END


static INPUT_PORTS_START( complexx )
	PORT_START("P1")    /* PIA 0 Port A (Left Stick) */
	PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_JOYSTICKLEFT_UP ) PORT_8WAY
	PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_JOYSTICKLEFT_RIGHT ) PORT_8WAY
	PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_JOYSTICKLEFT_DOWN ) PORT_8WAY
	PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_JOYSTICKLEFT_LEFT ) PORT_8WAY
	PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_BUTTON1 )
	PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_START2 )
	PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_START1 )
	PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_UNUSED )

/* 0x80 isn't scanned unless the difficulty in the game is below 4. I
decided not to map this button, so if you set the difficulty that low,
you can't fire. If I do map that button, and you set difficulty below 4
and hit this fire button without pressing the second stick in any
direction it fires up. If you're pressing left it fires right, press
right it fires left and press down it fires down. That's just too wacky.
I gotta think it's not supposed to be hooked up at all and if the
difficulty is that low, you just can't shoot, so I think it should stay
as-is. Tim Lindquist 1-17-03 */

	PORT_START("COIN")  /* PIA 0 Port B (COIN) */
	COIN_PORT

	PORT_START("SPARE") /* PIA 1 Port A (SPARE) */
	PORT_BIT( 0xff, IP_ACTIVE_LOW, IPT_UNKNOWN )

	PORT_START("IN0")   /* PIA 1 Port B (PLAYER 1/2) */
	PORT_BIT( 0xff, IP_ACTIVE_LOW, IPT_UNKNOWN )

	PORT_START("P2")    /* PIA 2 Port A (Right Stick) */
	PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_UNUSED )
	PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_UNUSED )
	PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_UNUSED )
	PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_UNUSED )
	PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_JOYSTICKRIGHT_UP ) PORT_8WAY
	PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_JOYSTICKRIGHT_RIGHT ) PORT_8WAY
	PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_JOYSTICKRIGHT_DOWN ) PORT_8WAY
	PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_JOYSTICKRIGHT_LEFT ) PORT_8WAY
INPUT_PORTS_END


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

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

    Qix has 6 PIAs on board:

    From the ROM I/O schematic:

    PIA 0 = U11: (mapped to $9400 on the data CPU)
        port A = external input (input_port_0)
        port B = external input (input_port_1) (coin)

    PIA 1 = U20: (mapped to $9800/$9900 on the data CPU)
        port A = external input (input_port_2)
        port B = external input (input_port_3)

    PIA 2 = U30: (mapped to $9c00 on the data CPU)
        port A = external input (input_port_4)
        port B = external output (coin control)


    From the data/sound processor schematic:

    PIA 3 = U20: (mapped to $9000 on the data CPU)
        port A = data CPU to sound CPU communication
        port B = stereo volume control, 2 4-bit values
        CA1 = interrupt signal from sound CPU
        CA2 = interrupt signal to sound CPU
        CB1 = VS input signal (vertical sync)
        CB2 = INV output signal (cocktail flip)
        IRQA = /DINT1 signal
        IRQB = /DINT1 signal

    PIA 4 = U8: (mapped to $4000 on the sound CPU)
        port A = sound CPU to data CPU communication
        port B = DAC value (port B)
        CA1 = interrupt signal from data CPU
        CA2 = interrupt signal to data CPU
        IRQA = /SINT1 signal
        IRQB = /SINT1 signal

    PIA 5 = U7: (never actually used, mapped to $2000 on the sound CPU)
        port A = unused
        port B = sound CPU to TMS5220 communication
        CA1 = interrupt signal from TMS5220
        CA2 = write signal to TMS5220
        CB1 = ready signal from TMS5220
        CB2 = read signal to TMS5220
        IRQA = /SINT2 signal
        IRQB = /SINT2 signal

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

MACHINE_CONFIG_START(qix_state::qix_base)

	/* basic machine hardware */
	MCFG_CPU_ADD("maincpu", MC6809E, MAIN_CLOCK_OSC/4/4)  /* 1.25 MHz */
	MCFG_CPU_PROGRAM_MAP(main_map)

	/* high interleave needed to ensure correct text in service mode */
	/* Zookeeper settings and high score table seem especially sensitive to this */
	MCFG_QUANTUM_PERFECT_CPU("maincpu")

	MCFG_NVRAM_ADD_0FILL("nvram")

	MCFG_DEVICE_ADD("pia0", PIA6821, 0)
	MCFG_PIA_READPA_HANDLER(IOPORT("P1"))
	MCFG_PIA_READPB_HANDLER(IOPORT("COIN"))

	MCFG_DEVICE_ADD("pia1", PIA6821, 0)
	MCFG_PIA_READPA_HANDLER(IOPORT("SPARE"))
	MCFG_PIA_READPB_HANDLER(IOPORT("IN0"))

	MCFG_DEVICE_ADD("pia2", PIA6821, 0)
	MCFG_PIA_READPA_HANDLER(IOPORT("P2"))
	MCFG_PIA_WRITEPB_HANDLER(WRITE8(qix_state, qix_coinctl_w))

	/* video hardware */
	qix_video(config);
MACHINE_CONFIG_END


MACHINE_CONFIG_START(qix_state::qix)
	qix_base(config);
	qix_audio(config);
MACHINE_CONFIG_END

MACHINE_CONFIG_START(qix_state::kram3)
	qix(config);
	MCFG_CPU_MODIFY("maincpu")
	MCFG_CPU_PROGRAM_MAP(kram3_main_map)
	MCFG_MC6809E_LIC_CB(WRITELINE(qix_state, kram3_lic_maincpu_changed))

	kram3_video(config);
MACHINE_CONFIG_END

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

    Games with an MCU need to handle coins differently, and provide
    communication with the MCU

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

MACHINE_CONFIG_START(qix_state::mcu)
	qix(config);

	/* basic machine hardware */

	MCFG_CPU_ADD("mcu", M68705P3, COIN_CLOCK_OSC) /* 1.00 MHz */
	MCFG_M68705_PORTB_R_CB(READ8(qix_state, qix_68705_portB_r))
	MCFG_M68705_PORTC_R_CB(READ8(qix_state, qix_68705_portC_r))
	MCFG_M68705_PORTA_W_CB(WRITE8(qix_state, qix_68705_portA_w))
	MCFG_M68705_PORTB_W_CB(WRITE8(qix_state, qix_68705_portB_w))

	MCFG_MACHINE_START_OVERRIDE(qix_state,qixmcu)

	MCFG_DEVICE_MODIFY("pia0")
	MCFG_PIA_READPB_HANDLER(READ8(qix_state, qixmcu_coin_r))
	MCFG_PIA_WRITEPB_HANDLER(WRITE8(qix_state, qixmcu_coin_w))

	MCFG_DEVICE_MODIFY("pia2")
	MCFG_PIA_WRITEPB_HANDLER(WRITE8(qix_state, qixmcu_coinctrl_w))
MACHINE_CONFIG_END


MACHINE_CONFIG_START(qix_state::zookeep)
	mcu(config);

	/* basic machine hardware */

	MCFG_CPU_MODIFY("maincpu")
	MCFG_CPU_PROGRAM_MAP(zoo_main_map)

	/* video hardware */
	zookeep_video(config);
MACHINE_CONFIG_END



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

    Slither uses 2 SN76489's for sound instead of the 6802+DAC; these
    are accessed via the PIAs.

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

MACHINE_CONFIG_START(qix_state::slither)
	qix_base(config);

	/* basic machine hardware */

	MCFG_CPU_MODIFY("maincpu")
	MCFG_CPU_CLOCK(SLITHER_CLOCK_OSC/4/4)   /* 1.34 MHz */

	MCFG_DEVICE_MODIFY("pia1")
	MCFG_PIA_READPA_HANDLER(READ8(qix_state, slither_trak_lr_r))
	MCFG_PIA_WRITEPB_HANDLER(WRITE8(qix_state, slither_76489_0_w))
	MCFG_PIA_READPB_HANDLER(NOOP)

	MCFG_DEVICE_MODIFY("pia2")
	MCFG_PIA_READPA_HANDLER(READ8(qix_state, slither_trak_ud_r))
	MCFG_PIA_WRITEPB_HANDLER(WRITE8(qix_state, slither_76489_1_w))
	MCFG_PIA_READPB_HANDLER(NOOP)

	/* video hardware */
	slither_video(config);

	/* audio hardware */
	slither_audio(config);
MACHINE_CONFIG_END



/*************************************
 *
 *  ROM definitions
 *
 *************************************/

ROM_START( qix )
	ROM_REGION( 0x10000, "maincpu", 0 )
	ROM_LOAD( "qq12_rev2.u12", 0xc000, 0x0800, CRC(aad35508) SHA1(5fa72e00b4373de21e27a86b49a44a9769f769f4) )
	ROM_LOAD( "qq13_rev2.u13", 0xc800, 0x0800, CRC(46c13504) SHA1(19c084c38b75f14bf5094b317afeecaca6870f7a) )
	ROM_LOAD( "qq14_rev2.u14", 0xd000, 0x0800, CRC(5115e896) SHA1(8359a1700fff7a38e8ea4f92a4f18bc628cf1cb1) )
	ROM_LOAD( "qq15_rev2.u15", 0xd800, 0x0800, CRC(ccd52a1b) SHA1(86d134cd769ef12820638b96a4ffedd8b15dffd2) )
	ROM_LOAD( "qq16_rev2.u16", 0xe000, 0x0800, CRC(cd1c36ee) SHA1(b379b1fe3109947a12c9683cd0c2400c2ee845b3) )
	ROM_LOAD( "qq17_rev2.u17", 0xe800, 0x0800, CRC(1acb682d) SHA1(a2c60964e8d838d09662f8a670c6da41ba850df9) )
	ROM_LOAD( "qq18_rev2.u18", 0xf000, 0x0800, CRC(de77728b) SHA1(8e183bb27858aad9a996e4a2e5a95f0145d1f5b4) )
	ROM_LOAD( "qq19_rev2.u19", 0xf800, 0x0800, CRC(c0994776) SHA1(9452a98c78a038679c4e58f4a9983adb28ea5e78) )

	ROM_REGION( 0x10000, "videocpu", 0 )
	ROM_LOAD( "qq4_rev2.u4",   0xc800, 0x0800, CRC(5b906a09) SHA1(84a2e817d6718e0276fcea702811a91bc054a670) )
	ROM_LOAD( "qq5_rev2.u5",   0xd000, 0x0800, CRC(254a3587) SHA1(66045c71cc1d04d4e03c728e578f570fbf7c650d) )
	ROM_LOAD( "qq6_rev2.u6",   0xd800, 0x0800, CRC(ace30389) SHA1(50c6275d13cfbca7750d5a3e725faedba7574e04) )
	ROM_LOAD( "qq7_rev2.u7",   0xe000, 0x0800, CRC(8ebcfa7c) SHA1(21ccf5e74424ab5470473d1059ee6a43d144f685) )
	ROM_LOAD( "qq8_rev2.u8",   0xe800, 0x0800, CRC(b8a3c8f9) SHA1(32ba771913ef44b1133ecfaedaae7f96dcc84343) )
	ROM_LOAD( "qq9_rev2.u9",   0xf000, 0x0800, CRC(26cbcd55) SHA1(2e55e222f850548cd1d461ab5337e98dd817b567) )
	ROM_LOAD( "qq10_rev2.u10", 0xf800, 0x0800, CRC(568be942) SHA1(8b6a01d983d355a64372fa76af810ab53e09d5df) )

	ROM_REGION( 0x10000, "audiocpu", 0 )
	ROM_LOAD( "qq27.u27", 0xf800, 0x0800, CRC(f3782bd0) SHA1(bfc6d29f9668e02857453e96c005c81568ae931d) )
ROM_END

// original taito board 08-00003-001
ROM_START( qixa )
	ROM_REGION( 0x10000, "maincpu", 0 )
	ROM_LOAD( "u12_", 0xc000, 0x0800, CRC(5adc046d) SHA1(aafd3ae7139a83fe64fc69c771a57fe7ee271469) )
	ROM_LOAD( "u13_", 0xc800, 0x0800, CRC(e63283c6) SHA1(efb6e5c835c0511be024f664cb8d2fcfe8f842f1) )
	ROM_LOAD( "u14_", 0xd000, 0x0800, CRC(a2fd4c28) SHA1(7da8bd1164d8d1a16f0841345ab6d73ae4fde97e) )
	ROM_LOAD( "u15_", 0xd800, 0x0800, CRC(0e5e17d6) SHA1(fd6afe1ef87158868c266a0d39dd894c1f656a1f) )
	ROM_LOAD( "u16_", 0xe000, 0x0800, CRC(6acfa3b8) SHA1(4759c72626cf287b068a1f14eae9fdb210b6ecfa) )
	ROM_LOAD( "u17_", 0xe800, 0x0800, CRC(bc091f21) SHA1(f3db149a794640e0826def688ab19a26750d9f1e) )
	ROM_LOAD( "u18_", 0xf000, 0x0800, CRC(610b19ce) SHA1(6d3d6012a4d0cd3ea82f4ab07582fa262feaaf97) )
	ROM_LOAD( "u19_", 0xf800, 0x0800, CRC(11f957f4) SHA1(5700603b2d50eef6ab32316f59d70782a8ef4a6d) )

	ROM_REGION( 0x10000, "videocpu", 0 )
	ROM_LOAD( "u3_",  0xc000, 0x0800, CRC(79cf997c) SHA1(853cb88d371cd2d47caf60baa795caef9461815c) )
	ROM_LOAD( "u4_",  0xc800, 0x0800, CRC(e5ee74cd) SHA1(10fd95385d0d8667f739fe43a9fb26d2780840f9) )
	ROM_LOAD( "u5_",  0xd000, 0x0800, CRC(4e939d87) SHA1(ca45f212bd419666716685931f18d2990444bb1b) )
	ROM_LOAD( "u6_",  0xd800, 0x0800, CRC(b42ca7d8) SHA1(09907f7c2c5165ce5cdf270c33caafc9e5db534e) )
	ROM_LOAD( "u7_",  0xe000, 0x0800, CRC(d6733019) SHA1(89e9e63c91e044fe1c6ce883e3ec18eec0cb39d3) )
	ROM_LOAD( "u8_",  0xe800, 0x0800, CRC(8cab8fb2) SHA1(4ae58119d24ac70bea2cd4871a21a59ef20f7351) )
	ROM_LOAD( "u9_",  0xf000, 0x0800, CRC(98fbac76) SHA1(5a9b5bdf930dc494cd50059f88256d7e561b4e09) )
	ROM_LOAD( "u10_", 0xf800, 0x0800, CRC(b40f084a) SHA1(16811b8f24b955a72f2a0950e9688cbd0e26afa4) )

	ROM_REGION( 0x10000, "audiocpu", 0 )
	ROM_LOAD( "qq27.u27", 0xf800, 0x0800, CRC(f3782bd0) SHA1(bfc6d29f9668e02857453e96c005c81568ae931d) )
ROM_END

// same set as above, but with larger roms.
// The same ROMs, with different labels, were also found on an original Taito TT Qix 2 PCB set
// Main PCB marked LK070001A LKN00001A and sub PCB marked LK070002 LKN00002
ROM_START( qixb )
	ROM_REGION( 0x10000, "maincpu", 0 )
	ROM_LOAD( "lk14.bin", 0xc000, 0x1000, CRC(6d164986) SHA1(c805abe1a441e10080ceca8ba547835bafb61bcc) ) // LK05.H1 2732
	ROM_LOAD( "lk15.bin", 0xd000, 0x1000, CRC(16c6ce0f) SHA1(b8091d2db476d2acb4b3f0789e1f155336be9b39) ) // LK06.J1 2732
	ROM_LOAD( "lk16.bin", 0xe000, 0x1000, CRC(698b1f9c) SHA1(7e7637ca5985f072e821e16f8b65aedb87df136b) ) // LK07.L1 2732
	ROM_LOAD( "lk17.bin", 0xf000, 0x1000, CRC(7e3adde6) SHA1(dfe66317f87e10919f1ea4b4d565703e73039821) ) // LK08.M1 2732

	ROM_REGION( 0x10000, "videocpu", 0 )
	ROM_LOAD( "lk10.bin", 0xc000, 0x1000, CRC(7eac67d0) SHA1(ca5938422aaa1e380af0afa505876d4682ac69b9) ) // LK01.B1 2732
	ROM_LOAD( "lk11.bin", 0xd000, 0x1000, CRC(90ccbb6a) SHA1(b65592384597dc2aafc02f49b6b6f477c9112580) ) // LK02.D1 2732
	ROM_LOAD( "lk12.bin", 0xe000, 0x1000, CRC(be9b9f7d) SHA1(e681bdb9aa8b8c31af1c14e23d0f420577d6db63) ) // LK03.E1 2732
	ROM_LOAD( "lk13.bin", 0xf000, 0x1000, CRC(51c9853b) SHA1(29a5221f2af866d2ee73110409ecddc2c96404fd) ) // LK04.F1 2732

	ROM_REGION( 0x10000, "audiocpu", 0 )
	ROM_LOAD( "qq27.u27", 0xf800, 0x0800, CRC(f3782bd0) SHA1(bfc6d29f9668e02857453e96c005c81568ae931d) ) // LK09.D2 2716
ROM_END


ROM_START( qixo ) /* ROMs might have the "QX" game prefix instead of "QU" this is verified */
	ROM_REGION( 0x10000, "maincpu", 0 )
	ROM_LOAD( "qu12", 0xc000, 0x0800, CRC(1c55b44d) SHA1(6385e5e484e24cf396c14de86344170639c3cc65) )
	ROM_LOAD( "qu13", 0xc800, 0x0800, CRC(20279e8c) SHA1(722da239636de3fe40318768ddbe687b19afcdb6) )
	ROM_LOAD( "qu14", 0xd000, 0x0800, CRC(bafe3ce3) SHA1(648a54545a1b545c82c0ace5eb1ce17af5ea7391) )
	/* d800-dfff empty */
	ROM_LOAD( "qu16", 0xe000, 0x0800, CRC(db560753) SHA1(4acbe17f1e555f45606ddec197c5ab691ff46d39) ) /* The QX version labels this rom as QX16-1 */
	ROM_LOAD( "qu17", 0xe800, 0x0800, CRC(8c7aeed8) SHA1(b7da2b0f34f72f9853cdf6ce55e604b09fcf4728) )
	ROM_LOAD( "qu18", 0xf000, 0x0800, CRC(353be980) SHA1(a50e02fcc69771a13b238aa0e8dc3c56b01a58d5) )
	ROM_LOAD( "qu19", 0xf800, 0x0800, CRC(f46a69ca) SHA1(dacb53c0318445da3fbb86f9a45914c5b7a4c4a1) ) /* The QX version labels this rom as QX19-1 */

	ROM_REGION( 0x10000, "videocpu", 0 )
	ROM_LOAD( "qu3",  0xc000, 0x0800, CRC(8b4c0ef0) SHA1(6d18d1052f342e3b3313f2174b20f2a179e2c6bd) )
	ROM_LOAD( "qu4",  0xc800, 0x0800, CRC(66a5c260) SHA1(8cce71bcd3a432650f0d0c94f3a2151ba8154220) )
	ROM_LOAD( "qu5",  0xd000, 0x0800, CRC(70160ea3) SHA1(a411130c5c669a181564369a8921b26e0f0b5450) )
	/* d800-dfff empty */
	ROM_LOAD( "qu7",  0xe000, 0x0800, CRC(d6733019) SHA1(89e9e63c91e044fe1c6ce883e3ec18eec0cb39d3) )
	ROM_LOAD( "qu8",  0xe800, 0x0800, CRC(66870dcc) SHA1(9f926390f5ce86d7c1bf55b75dbfb34119425c46) )
	ROM_LOAD( "qu9",  0xf000, 0x0800, CRC(c99bf94d) SHA1(7b6fa6e1cf0f131909d44694c261b1cc2de65003) )
	ROM_LOAD( "qu10", 0xf800, 0x0800, CRC(88b45037) SHA1(e2e5fefe377def3f784026b921527898af8b83a9) )

	ROM_REGION( 0x10000, "audiocpu", 0 )
	ROM_LOAD( "qu27.u27", 0xf800, 0x0800, CRC(f3782bd0) SHA1(bfc6d29f9668e02857453e96c005c81568ae931d) )
ROM_END



ROM_START( qix2 )
	ROM_REGION( 0x10000, "maincpu", 0 )
	ROM_LOAD( "u12.rmb", 0xc000, 0x0800, CRC(484280fd) SHA1(a60c1a278e519721294b2486dc817d248d19c3be) )
	ROM_LOAD( "u13.rmb", 0xc800, 0x0800, CRC(3d089fcb) SHA1(f4f31134c9c15160d2d15cb41296dfec6f2dfe37) )
	ROM_LOAD( "u14.rmb", 0xd000, 0x0800, CRC(362123a9) SHA1(3e2a853f6960f2d5fdcdef8dec8ccf5aad449548) )
	ROM_LOAD( "u15.rmb", 0xd800, 0x0800, CRC(60f3913d) SHA1(a97b658fe2c58b00c2749072828b2e0032894915) )
	ROM_LOAD( "u16.rmb", 0xe000, 0x0800, CRC(cc139e34) SHA1(0ed3e7179b0cbaa31fa91e1ed862b86f5032919a) )
	ROM_LOAD( "u17.rmb", 0xe800, 0x0800, CRC(cf31dc49) SHA1(71c089d827ab61ba69e5e95b7e53220763786df9) )
	ROM_LOAD( "u18.rmb", 0xf000, 0x0800, CRC(1f91ed7a) SHA1(85bb5370a244719663a4f859f66860613aa2b86e) )
	ROM_LOAD( "u19.rmb", 0xf800, 0x0800, CRC(68e8d5a6) SHA1(d09252c393be2fdaf3b9b9f477c79f721d15943f) )

	ROM_REGION( 0x10000, "videocpu", 0 )
	ROM_LOAD( "u3.rmb",  0xc000, 0x0800, CRC(19cebaca) SHA1(7d7e79ab0920952cf7618567c9c65397535b6d4f) )
	ROM_LOAD( "u4.rmb",  0xc800, 0x0800, CRC(6cfb4185) SHA1(6545dece8eaeb716877aa6e7b24c21f6e5991451) )
	ROM_LOAD( "u5.rmb",  0xd000, 0x0800, CRC(948f53f3) SHA1(db6eddec8ba41335316d80b6f97e932bf91139af) )
	ROM_LOAD( "u6.rmb",  0xd800, 0x0800, CRC(8630120e) SHA1(14a020fd1bff4acbb034883e33130adda85884e5) )
	ROM_LOAD( "u7.rmb",  0xe000, 0x0800, CRC(bad037c9) SHA1(17218c31895b1547b71d2d9d2b6a93d2e5d73bdd) )
	ROM_LOAD( "u8.rmb",  0xe800, 0x0800, CRC(3159bc00) SHA1(479a69bfe5af48d5ce63978265ce59f79c25749f) )
	ROM_LOAD( "u9.rmb",  0xf000, 0x0800, CRC(e80e9b1d) SHA1(66ef22a26df3f766ae813213473b9ac4b35b01f6) )
	ROM_LOAD( "u10.rmb", 0xf800, 0x0800, CRC(9a55d360) SHA1(fc5f8c853dcc573f6b36dbdd63e5d1edba88bce1) )

	ROM_REGION( 0x10000, "audiocpu", 0 )
	ROM_LOAD( "u27",     0xf800, 0x0800, CRC(f3782bd0) SHA1(bfc6d29f9668e02857453e96c005c81568ae931d) )
ROM_END


ROM_START( sdungeon )
	ROM_REGION( 0x10000, "maincpu", 0 )
	ROM_LOAD( "sd14.u14", 0xa000, 0x1000, CRC(7024b55a) SHA1(1e21cb2a9cba8c0a3684e137ff78d4b331d86922) )
	ROM_LOAD( "sd15.u15", 0xb000, 0x1000, CRC(a3ac9040) SHA1(f033c21983e87688884180c2336d766a0fa49765) )
	ROM_LOAD( "sd16.u16", 0xc000, 0x1000, CRC(cc20b580) SHA1(53e34405f1f39bce305f199d09d3a32c10c0c616) )
	ROM_LOAD( "sd17.u17", 0xd000, 0x1000, CRC(4663e4b8) SHA1(519b0e730db2047ebe2cce0953eda53e851f8fac) )
	ROM_LOAD( "sd18.u18", 0xe000, 0x1000, CRC(7ef1ffc0) SHA1(eca49a916b6b51b91ed45ff89bb37a67fee7db0e) )
	ROM_LOAD( "sd19.u19", 0xf000, 0x1000, CRC(7b20b7ac) SHA1(554e29adc75cc465ea603a628f9d60d6d903e7ab) )

	ROM_REGION( 0x10000, "videocpu", 0 )
	ROM_LOAD( "sd05.u5",  0xa000, 0x1000, CRC(0b2bf48e) SHA1(51bfb35521864f09a20b38aeeb98ab1399d139a5) )
	ROM_LOAD( "sd06.u6",  0xb000, 0x1000, CRC(f86db512) SHA1(7e7ae64db7821f18a5eefdcc7a2e1abc37abd3ac) )
	ROM_LOAD( "sd07.u7",  0xc000, 0x1000, CRC(7b796831) SHA1(cd3d8975e99886f51b27530f0e261f749aadee73) )
	ROM_LOAD( "sd08.u8",  0xd000, 0x1000, CRC(5fbe7068) SHA1(2884909156179b81181b908431de15a7c586f619) )
	ROM_LOAD( "sd09.u9",  0xe000, 0x1000, CRC(89bc51ea) SHA1(57ad4806f0b39af3b3cde91cef16234fc82f21d0) )
	ROM_LOAD( "sd10.u10", 0xf000, 0x1000, CRC(754de734) SHA1(a37b8362a592f5d1c0aeaa525fc003f6060fc12b) )

	ROM_REGION( 0x10000, "audiocpu", 0 )
	ROM_LOAD( "sd26.u26", 0xf000, 0x0800, CRC(3df8630d) SHA1(5f87c4d49799d424ce36469bf2b36b14c782fcd8) )
	ROM_LOAD( "sd27.u27", 0xf800, 0x0800, CRC(0386f351) SHA1(24ba6aba7c62c313397d743d18093c646f4a6526) )

	ROM_REGION( 0x0800, "mcu", 0 )
	ROM_LOAD( "sd101",    0x0000, 0x0800, CRC(e255af9a) SHA1(2410d3b7dec8e72a93d71c824c9403a6d96b9e8c) )
ROM_END

// same as above but uses larger ROMs
ROM_START( sdungeona )
	ROM_REGION( 0x10000, "maincpu", 0 )
	ROM_LOAD( "1514.1j", 0xa000, 0x2000, CRC(8fe3e3c6) SHA1(f60acf7d2096a17726e89fee532fc68218657269) )
	ROM_LOAD( "1716.1k", 0xc000, 0x2000, CRC(9976fe14) SHA1(759e966abaa3dd458c3d3f9ce5ef6abfec196d28) )
	ROM_LOAD( "1819.1l", 0xe000, 0x2000, CRC(d56a40b0) SHA1(5b98e99938b6a394abca336995959cd97a55ddf7) )

	ROM_REGION( 0x10000, "videocpu", 0 )
	ROM_LOAD("65.1h",    0xa000, 0x2000, CRC(4b567837) SHA1(985e75829779cac366e57996016e5f949e1202c7) )
	ROM_LOAD("87.1f",    0xc000, 0x2000, CRC(9298778b) SHA1(26c4dfd932e55e2525e46be8f58f26c67970d2bd) )
	ROM_LOAD("109.1e",   0xe000, 0x2000, CRC(7437a6f1) SHA1(232fefb28c55338e5f3fed213ee94f44816241a0) )

	ROM_REGION( 0x10000, "audiocpu", 0 )
	ROM_LOAD( "2627.2d", 0xf000, 0x1000, CRC(1f830dff) SHA1(05b99d941d8fa53a4a9f9eb82e31d493d21d0f6f) )

	ROM_REGION( 0x0800, "mcu", 0 )
	ROM_LOAD( "sd101",   0x0000, 0x0800, CRC(e255af9a) SHA1(2410d3b7dec8e72a93d71c824c9403a6d96b9e8c) )
ROM_END

ROM_START( elecyoyo )
	ROM_REGION( 0x10000, "maincpu", 0 )
	ROM_LOAD( "yy14",   0xa000, 0x1000, CRC(0d2edcb9) SHA1(36e1a1aa81111f38e1c06a8174e7de406478cc67) )
	ROM_LOAD( "yy15",   0xb000, 0x1000, CRC(a91f01e3) SHA1(7818299d25a0816b856e83fae02d8019e5e8b4a3) )
	ROM_LOAD( "yy16-1", 0xc000, 0x1000, CRC(2710f360) SHA1(4a6210b07618fba261c38b7bf9a779598dd6bb3c) )
	ROM_LOAD( "yy17",   0xd000, 0x1000, CRC(25fd489d) SHA1(ca7b8d1bcbc223fc0706c8f2e9f02821519b75e4) )
	ROM_LOAD( "yy18",   0xe000, 0x1000, CRC(0b6661c0) SHA1(3e24acbfea1a3b83223d780ea34c83759a751175) )
	ROM_LOAD( "yy19-1", 0xf000, 0x1000, CRC(95b8b244) SHA1(2852dcfc6a638118ee7fe60b957d8aa9a5a8984c) )

	ROM_REGION( 0x10000, "videocpu", 0 )
	ROM_LOAD( "yy5",    0xa000, 0x1000, CRC(3793fec5) SHA1(d31f3ba6364755c98beb814b5e7d5541e8b4e1a0) )
	ROM_LOAD( "yy6",    0xb000, 0x1000, CRC(2e8b1265) SHA1(6fb67b6a5b627bcbd10c72ac8c9e4d9f4dd7860f) )
	ROM_LOAD( "yy7",    0xc000, 0x1000, CRC(20f93411) SHA1(126c27442a4e35d054a236c41930603241d08ccf) )
	ROM_LOAD( "yy8",    0xd000, 0x1000, CRC(926f90c8) SHA1(dbdfc0e9184a4d9d44d04fdb8fed19b35a8edadc) )
	ROM_LOAD( "yy9",    0xe000, 0x1000, CRC(2f999480) SHA1(582baf285cadf8431ff80f5b63a02fbbefb62e45) )
	ROM_LOAD( "yy10",   0xf000, 0x1000, CRC(b31d20e2) SHA1(e2ba4e6b81a02c3c02353774eb63a72cdfe5f2c3) )

	ROM_REGION( 0x10000, "audiocpu", 0 )
	ROM_LOAD( "yy27",   0xf800, 0x0800, CRC(5a2aa0f3) SHA1(16c7c2db39f33ea3506e07312352ccbfe5528fbd) )

	ROM_REGION( 0x0800, "mcu", 0 )
	ROM_LOAD( "yy101",  0x0000, 0x0800, CRC(3cf13038) SHA1(29c1b309d9046087a50ca78a5f7cba694271af26) )
ROM_END


ROM_START( elecyoyo2 )
	ROM_REGION( 0x10000, "maincpu", 0 )
	ROM_LOAD( "yy14",  0xa000, 0x1000, CRC(0d2edcb9) SHA1(36e1a1aa81111f38e1c06a8174e7de406478cc67) )
	ROM_LOAD( "yy15",  0xb000, 0x1000, CRC(a91f01e3) SHA1(7818299d25a0816b856e83fae02d8019e5e8b4a3) )
	ROM_LOAD( "yy16",  0xc000, 0x1000, CRC(cab19f3a) SHA1(df41649a800b77f046edb6623f65d100f6a8ef5f) )
	ROM_LOAD( "yy17",  0xd000, 0x1000, CRC(25fd489d) SHA1(ca7b8d1bcbc223fc0706c8f2e9f02821519b75e4) )
	ROM_LOAD( "yy18",  0xe000, 0x1000, CRC(0b6661c0) SHA1(3e24acbfea1a3b83223d780ea34c83759a751175) )
	ROM_LOAD( "yy19",  0xf000, 0x1000, CRC(d0215d2e) SHA1(816131bc272252df6cea1b84a42750a71ce4f427) )

	ROM_REGION( 0x10000, "videocpu", 0 )
	ROM_LOAD( "yy5",   0xa000, 0x1000, CRC(3793fec5) SHA1(d31f3ba6364755c98beb814b5e7d5541e8b4e1a0) )
	ROM_LOAD( "yy6",   0xb000, 0x1000, CRC(2e8b1265) SHA1(6fb67b6a5b627bcbd10c72ac8c9e4d9f4dd7860f) )
	ROM_LOAD( "yy7",   0xc000, 0x1000, CRC(20f93411) SHA1(126c27442a4e35d054a236c41930603241d08ccf) )
	ROM_LOAD( "yy8",   0xd000, 0x1000, CRC(926f90c8) SHA1(dbdfc0e9184a4d9d44d04fdb8fed19b35a8edadc) )
	ROM_LOAD( "yy9",   0xe000, 0x1000, CRC(2f999480) SHA1(582baf285cadf8431ff80f5b63a02fbbefb62e45) )
	ROM_LOAD( "yy10",  0xf000, 0x1000, CRC(b31d20e2) SHA1(e2ba4e6b81a02c3c02353774eb63a72cdfe5f2c3) )

	ROM_REGION( 0x10000, "audiocpu", 0 )
	ROM_LOAD( "yy27",  0xf800, 0x0800, CRC(5a2aa0f3) SHA1(16c7c2db39f33ea3506e07312352ccbfe5528fbd) )

	ROM_REGION( 0x0800, "mcu", 0 )
	ROM_LOAD( "yy101", 0x0000, 0x0800, CRC(3cf13038) SHA1(29c1b309d9046087a50ca78a5f7cba694271af26) )
ROM_END


ROM_START( kram )
	ROM_REGION( 0x10000, "maincpu", 0 )
	ROM_LOAD( "ks14-1", 0xa000, 0x1000, CRC(fe69ac79) SHA1(6df0f98e6c0901c058123988bf22a6dd9f0a1fac) )
	ROM_LOAD( "ks15",   0xb000, 0x1000, CRC(4b2c175e) SHA1(4f9d4dcc78a12e994d499b182c8229d5fa63b805) )
	ROM_LOAD( "ks16",   0xc000, 0x1000, CRC(9500a05d) SHA1(18e0107111f79ba5dc6d568e3a6e7e7778955d0b) )
	ROM_LOAD( "ks17",   0xd000, 0x1000, CRC(c752a3a1) SHA1(1d03ea97b9ca6fa3d4c43ac867ab737439d987af) )
	ROM_LOAD( "ks18",   0xe000, 0x1000, CRC(79158b03) SHA1(0d4873471b5b7ace0de8ec421ff3d74650790f7e) )
	ROM_LOAD( "ks19-1", 0xf000, 0x1000, CRC(759ea6ce) SHA1(7962f713dd93c73475fa1f64635d8e965336484b) )

	ROM_REGION( 0x10000, "videocpu", 0 )
	ROM_LOAD( "ks5",    0xa000, 0x1000, CRC(1c472080) SHA1(a85400be562ef6b817f8a654f29d966d3a198ab4) )
	ROM_LOAD( "ks6",    0xb000, 0x1000, CRC(b8926622) SHA1(e25a8b2ff192f6ab0328fd7b3c58d638342f79e2) )
	ROM_LOAD( "ks7",    0xc000, 0x1000, CRC(c98a7485) SHA1(e310d53ae65d456e12a2475e9ac578592b0e82ba) )
	ROM_LOAD( "ks8",    0xd000, 0x1000, CRC(1127c4e4) SHA1(d78a8a964aac29fb71a55acf7956355724a234eb) )
	ROM_LOAD( "ks9",    0xe000, 0x1000, CRC(d3bc8b5e) SHA1(2c5b882c54bdb48f9a76abfe734b99390b89d76c) )
	ROM_LOAD( "ks10",   0xf000, 0x1000, CRC(e0426444) SHA1(3c4ea66f8ee907452e67aeb7cfaa15bee02b004b) )

	ROM_REGION( 0x10000, "audiocpu", 0 )
	ROM_LOAD( "ks27",   0xf800, 0x0800, CRC(c46530c8) SHA1(d2df3f2228a5cff7d7b04b5bbbc4820d2fe84d8d) )

	ROM_REGION( 0x0800, "mcu", 0 )
	ROM_LOAD( "ks101.dat", 0x0000, 0x0800, CRC(e53d97b7) SHA1(acfc3a5c5e73bd2d37e04ac357043b708d1982de) )
ROM_END


ROM_START( kram2 )
	ROM_REGION( 0x10000, "maincpu", 0 )
	ROM_LOAD( "ks14", 0xa000, 0x1000, CRC(a2eac1ff) SHA1(128f83b1760492cbb272828ad8c67ea9a5db862a) )
	ROM_LOAD( "ks15", 0xb000, 0x1000, CRC(4b2c175e) SHA1(4f9d4dcc78a12e994d499b182c8229d5fa63b805) )
	ROM_LOAD( "ks16", 0xc000, 0x1000, CRC(9500a05d) SHA1(18e0107111f79ba5dc6d568e3a6e7e7778955d0b) )
	ROM_LOAD( "ks17", 0xd000, 0x1000, CRC(c752a3a1) SHA1(1d03ea97b9ca6fa3d4c43ac867ab737439d987af) )
	ROM_LOAD( "ks18", 0xe000, 0x1000, CRC(79158b03) SHA1(0d4873471b5b7ace0de8ec421ff3d74650790f7e) )
	ROM_LOAD( "ks19", 0xf000, 0x1000, CRC(053c5e09) SHA1(cd6e5b54abf73c1ccf318ca18fceb56b51a3847f) )

	ROM_REGION( 0x10000, "videocpu", 0 )
	ROM_LOAD( "ks5",  0xa000, 0x1000, CRC(1c472080) SHA1(a85400be562ef6b817f8a654f29d966d3a198ab4) )
	ROM_LOAD( "ks6",  0xb000, 0x1000, CRC(b8926622) SHA1(e25a8b2ff192f6ab0328fd7b3c58d638342f79e2) )
	ROM_LOAD( "ks7",  0xc000, 0x1000, CRC(c98a7485) SHA1(e310d53ae65d456e12a2475e9ac578592b0e82ba) )
	ROM_LOAD( "ks8",  0xd000, 0x1000, CRC(1127c4e4) SHA1(d78a8a964aac29fb71a55acf7956355724a234eb) )
	ROM_LOAD( "ks9",  0xe000, 0x1000, CRC(d3bc8b5e) SHA1(2c5b882c54bdb48f9a76abfe734b99390b89d76c) )
	ROM_LOAD( "ks10", 0xf000, 0x1000, CRC(e0426444) SHA1(3c4ea66f8ee907452e67aeb7cfaa15bee02b004b) )

	ROM_REGION( 0x10000, "audiocpu", 0 )
	ROM_LOAD( "ks27", 0xf800, 0x0800, CRC(c46530c8) SHA1(d2df3f2228a5cff7d7b04b5bbbc4820d2fe84d8d) )

	ROM_REGION( 0x0800, "mcu", 0 )
	ROM_LOAD( "ks101.dat", 0x0000, 0x0800, CRC(e53d97b7) SHA1(acfc3a5c5e73bd2d37e04ac357043b708d1982de) )
ROM_END


ROM_START( kram3 )
	ROM_REGION( 0x10000, "maincpu", 0 ) /* encrypted */
	ROM_LOAD( "kr-u14", 0xa000, 0x1000, CRC(02c1bd1e) SHA1(5f13f32ca2da0e93ed43b052c8c33af9ac67cb6c) )
	ROM_LOAD( "kr-u15", 0xb000, 0x1000, CRC(46b3ff33) SHA1(7db45971972df144a21fee4cc015b0190b502e12) )
	ROM_LOAD( "kr-u16", 0xc000, 0x1000, CRC(f202b9cf) SHA1(baf27507611c3029e2dfb1a4ff86e6fe17171246) )
	ROM_LOAD( "kr-u17", 0xd000, 0x1000, CRC(257cea23) SHA1(f9503c4a0f94d35a55033c02dda4d03737eedb90) )
	ROM_LOAD( "kr-u18", 0xe000, 0x1000, CRC(da3aed8c) SHA1(0107d58fa006a39b47513381aead760190abef35) )
	ROM_LOAD( "kr-u19", 0xf000, 0x1000, CRC(496ab571) SHA1(30e12b31ffd70a8a1ce23c845e89170ca3cabaa5) )

	ROM_REGION( 2*0x10000, "videocpu", 0 )  /* encrypted */
	ROM_LOAD( "kr-u5",  0xa000, 0x1000, CRC(9e63c2bc) SHA1(f61a2b93ed322b62818f31fddb324c666380eff7) )
	ROM_LOAD( "kr-u6",  0xb000, 0x1000, CRC(a0ff1244) SHA1(5bc3f3f8caac0dfc8c1381d34e5b8ef5c8202982) )
	ROM_LOAD( "kr-u7",  0xc000, 0x1000, CRC(20a15024) SHA1(094951c4cd06e32af2cb2faec04c31d55ade6b7b) )
	ROM_LOAD( "ks8",    0xd000, 0x1000, CRC(1127c4e4) SHA1(d78a8a964aac29fb71a55acf7956355724a234eb) )
	ROM_LOAD( "ks9",    0xe000, 0x1000, CRC(d3bc8b5e) SHA1(2c5b882c54bdb48f9a76abfe734b99390b89d76c) )
	ROM_LOAD( "kr-u10", 0xf000, 0x1000, CRC(0a8adbd8) SHA1(8ab806108c68aa2740d9e157dd215b371e81c482) )

	ROM_REGION( 0x10000, "audiocpu", 0 )
	ROM_LOAD( "ks27",   0xf800, 0x0800, CRC(c46530c8) SHA1(d2df3f2228a5cff7d7b04b5bbbc4820d2fe84d8d) )
ROM_END


ROM_START( zookeep ) // note on the zookeeper boardset Taito USA made very sure that every ROM has the same name as the socket it is in!
	ROM_REGION( 0x10000, "maincpu", 0 ) // roms on the 'SDU board'
	ROM_LOAD( "za12.u12",    0x8000, 0x1000, CRC(4e40d8dc) SHA1(dd7923dcb55a2a1ae0f2029caf5a8904a9ebe8b1) )
	ROM_LOAD( "za13.u13",    0x9000, 0x1000, CRC(eebd5248) SHA1(ebe7f8c436bfefa4236f603fbcbd38d2f4cfd2bd) )
	ROM_LOAD( "za14.u14",    0xa000, 0x1000, CRC(fab43297) SHA1(daa5a780bc9f171da0f6db5319b1519caa09c6c9) )
	ROM_LOAD( "za15.u15",    0xb000, 0x1000, CRC(ef8cd67c) SHA1(f3a2e12ccfa45eb77c2a6e0d9cc0601b99273fd3) )
	ROM_LOAD( "za16.u16",    0xc000, 0x1000, CRC(ccfc15bc) SHA1(56ac6e89825fcde9cf7aeb5d0765a02f5474174a) )
	ROM_LOAD( "za17.u17",    0xd000, 0x1000, CRC(358013f4) SHA1(dd3fae69bf460f89c71e7c78d229dd86605c5950) )
	ROM_LOAD( "za18.u18",    0xe000, 0x1000, CRC(37886afe) SHA1(a0cc902b2d253466e21c4fbf9d3339069fe79ebe) )
	ROM_LOAD( "za19.u19",    0xf000, 0x1000, CRC(bbfb30d9) SHA1(bc6bd5525b159bee7b08b6967cd3088b7bd10fee) )

	ROM_REGION( 0x12000, "videocpu", 0 ) // roms on the 08-00112-001 'video rom expansion' PCB
	ROM_LOAD( "za5.u5",  0x0a000, 0x1000, CRC(dc0c3cbd) SHA1(8335cd91bbacc680a3a98a5242d4cb5a6f61b2b5) )
	ROM_LOAD( "za3.u3",  0x10000, 0x1000, CRC(cc4d0aee) SHA1(05c0025e96b432088b46100051a2c780e46b7457) )
	ROM_LOAD( "za6.u6",  0x0b000, 0x1000, CRC(27c787dd) SHA1(1142790d875573d0c39d846aba4b06946fd2bc88) )
	ROM_LOAD( "za4.u4",  0x11000, 0x1000, CRC(ec3b10b1) SHA1(44303ab923d776052ca4d2d09a6a4315d67adc4b) )

	ROM_LOAD( "za7.u7",  0x0c000, 0x1000, CRC(1479f480) SHA1(bd0e9eead0f1213eb3b9653c73257bc704346ab0) )
	ROM_LOAD( "za8.u8",  0x0d000, 0x1000, CRC(4c96cdb2) SHA1(67e506462317d882c4e5c2e16318411d4958ac63) )
	ROM_LOAD( "za9.u9",  0x0e000, 0x1000, CRC(a4f7d9e0) SHA1(a958b4d305bb397aa46d8fdab9dc7e472237ca11) )
	ROM_LOAD( "za10.u10", 0x0f000, 0x1000, CRC(05df1a5a) SHA1(30797838c25cca038023c188cd9fa45277c4190d) )

	ROM_REGION( 0x10000, "audiocpu", 0 ) // roms on the 'SDU board'
	ROM_LOAD( "za25.u25", 0xd000, 0x1000, CRC(779b8558) SHA1(7312e63c23d92c9c52e93cc445a718bc8fe35a0a) )
	ROM_LOAD( "za26.u26", 0xe000, 0x1000, CRC(60a810ce) SHA1(d97e5acea0ef1c208f8e5e95024c83dd6bc9b028) )
	ROM_LOAD( "za27.u27", 0xf000, 0x1000, CRC(99ed424e) SHA1(e4e543dcb77f153aeb78904d11b95381d039299e) )

	ROM_REGION( 0x0800, "mcu", 0 ) // mc68705p3, this is on its own pcb between the coin inputs and the main pcb
	ROM_LOAD( "za_coin.bin", 0x0000, 0x0800, CRC(364d3557) SHA1(049d0759750c576187053306e07984b1e5877df7) )
ROM_END


ROM_START( zookeep2 )
	ROM_REGION( 0x10000, "maincpu", 0 ) // roms on the 'SDU board'
	ROM_LOAD( "za12.u12",    0x8000, 0x1000, CRC(4e40d8dc) SHA1(dd7923dcb55a2a1ae0f2029caf5a8904a9ebe8b1) )
	ROM_LOAD( "za13.u13",    0x9000, 0x1000, CRC(eebd5248) SHA1(ebe7f8c436bfefa4236f603fbcbd38d2f4cfd2bd) )
	ROM_LOAD( "za14.u14",    0xa000, 0x1000, CRC(fab43297) SHA1(daa5a780bc9f171da0f6db5319b1519caa09c6c9) )
	ROM_LOAD( "za15.u15",    0xb000, 0x1000, CRC(ef8cd67c) SHA1(f3a2e12ccfa45eb77c2a6e0d9cc0601b99273fd3) )
	ROM_LOAD( "za16.u16",    0xc000, 0x1000, CRC(ccfc15bc) SHA1(56ac6e89825fcde9cf7aeb5d0765a02f5474174a) )
	ROM_LOAD( "za17.u17",    0xd000, 0x1000, CRC(358013f4) SHA1(dd3fae69bf460f89c71e7c78d229dd86605c5950) )
	ROM_LOAD( "za18.u18",    0xe000, 0x1000, CRC(37886afe) SHA1(a0cc902b2d253466e21c4fbf9d3339069fe79ebe) )
	ROM_LOAD( "za19.red.u19", 0xf000, 0x1000, CRC(ec01760e) SHA1(169ab9d3a0abe325d960f9ed358258b3d6fcd4be) ) // ?updated? rom?

	ROM_REGION( 0x12000, "videocpu", 0 ) // roms on the 08-00112-001 'video rom expansion' PCB
	ROM_LOAD( "za5.u5",  0x0a000, 0x1000, CRC(dc0c3cbd) SHA1(8335cd91bbacc680a3a98a5242d4cb5a6f61b2b5) )
	ROM_LOAD( "za3.u3",  0x10000, 0x1000, CRC(cc4d0aee) SHA1(05c0025e96b432088b46100051a2c780e46b7457) )
	ROM_LOAD( "za6.u6",  0x0b000, 0x1000, CRC(27c787dd) SHA1(1142790d875573d0c39d846aba4b06946fd2bc88) )
	ROM_LOAD( "za4.u4",  0x11000, 0x1000, CRC(ec3b10b1) SHA1(44303ab923d776052ca4d2d09a6a4315d67adc4b) )

	ROM_LOAD( "za7.u7",  0x0c000, 0x1000, CRC(1479f480) SHA1(bd0e9eead0f1213eb3b9653c73257bc704346ab0) )
	ROM_LOAD( "za8.u8",  0x0d000, 0x1000, CRC(4c96cdb2) SHA1(67e506462317d882c4e5c2e16318411d4958ac63) )
	ROM_LOAD( "za9.u9",  0x0e000, 0x1000, CRC(a4f7d9e0) SHA1(a958b4d305bb397aa46d8fdab9dc7e472237ca11) )
	ROM_LOAD( "za10.u10", 0x0f000, 0x1000, CRC(05df1a5a) SHA1(30797838c25cca038023c188cd9fa45277c4190d) )

	ROM_REGION( 0x10000, "audiocpu", 0 ) // roms on the 'SDU board'
	ROM_LOAD( "za25.u25", 0xd000, 0x1000, CRC(779b8558) SHA1(7312e63c23d92c9c52e93cc445a718bc8fe35a0a) )
	ROM_LOAD( "za26.u26", 0xe000, 0x1000, CRC(60a810ce) SHA1(d97e5acea0ef1c208f8e5e95024c83dd6bc9b028) )
	ROM_LOAD( "za27.u27", 0xf000, 0x1000, CRC(99ed424e) SHA1(e4e543dcb77f153aeb78904d11b95381d039299e) )

	ROM_REGION( 0x0800, "mcu", 0 ) // mc68705p3, this is on its own pcb between the coin inputs and the main pcb
	ROM_LOAD( "za_coin.bin", 0x0000, 0x0800, CRC(364d3557) SHA1(049d0759750c576187053306e07984b1e5877df7) )
ROM_END


ROM_START( zookeep3 )
	ROM_REGION( 0x10000, "maincpu", 0 ) // roms on the 'SDU board'
	ROM_LOAD( "za12.u12",    0x8000, 0x1000, CRC(4e40d8dc) SHA1(dd7923dcb55a2a1ae0f2029caf5a8904a9ebe8b1) )
	ROM_LOAD( "za13.u13",    0x9000, 0x1000, CRC(eebd5248) SHA1(ebe7f8c436bfefa4236f603fbcbd38d2f4cfd2bd) )
	ROM_LOAD( "za14.u14",    0xa000, 0x1000, CRC(fab43297) SHA1(daa5a780bc9f171da0f6db5319b1519caa09c6c9) )
	ROM_LOAD( "za15.u15",    0xb000, 0x1000, CRC(ef8cd67c) SHA1(f3a2e12ccfa45eb77c2a6e0d9cc0601b99273fd3) )
	ROM_LOAD( "za16.u16",    0xc000, 0x1000, CRC(ccfc15bc) SHA1(56ac6e89825fcde9cf7aeb5d0765a02f5474174a) )
	ROM_LOAD( "za17.u17",    0xd000, 0x1000, CRC(358013f4) SHA1(dd3fae69bf460f89c71e7c78d229dd86605c5950) )
	ROM_LOAD( "za18.u18",    0xe000, 0x1000, CRC(37886afe) SHA1(a0cc902b2d253466e21c4fbf9d3339069fe79ebe) )
	ROM_LOAD( "za19.u19",    0xf000, 0x1000, CRC(bbfb30d9) SHA1(bc6bd5525b159bee7b08b6967cd3088b7bd10fee) )

	ROM_REGION( 0x12000, "videocpu", 0 ) // roms on the 08-00112-001 'video rom expansion' PCB
	ROM_LOAD( "za5.u5",  0x0a000, 0x1000, CRC(dc0c3cbd) SHA1(8335cd91bbacc680a3a98a5242d4cb5a6f61b2b5) )
	ROM_LOAD( "za3.u3",  0x10000, 0x1000, CRC(cc4d0aee) SHA1(05c0025e96b432088b46100051a2c780e46b7457) )
	ROM_LOAD( "za6.u6",  0x0b000, 0x1000, CRC(27c787dd) SHA1(1142790d875573d0c39d846aba4b06946fd2bc88) )
	ROM_LOAD( "za4.u4",  0x11000, 0x1000, CRC(ec3b10b1) SHA1(44303ab923d776052ca4d2d09a6a4315d67adc4b) )

	ROM_LOAD( "za7.u7",  0x0c000, 0x1000, CRC(1479f480) SHA1(bd0e9eead0f1213eb3b9653c73257bc704346ab0) )
	ROM_LOAD( "za8.u8",  0x0d000, 0x1000, CRC(4c96cdb2) SHA1(67e506462317d882c4e5c2e16318411d4958ac63) )
	ROM_LOAD( "zv35.9.u9",  0x0e000, 0x1000, CRC(d14123b7) SHA1(5d35bffd2203225937bb83598ffdc31a46a1dbca) )
	ROM_LOAD( "zv36.10.u10", 0x0f000, 0x1000, CRC(23705777) SHA1(952cd8d9ee00268bff2022b2428b1dbfab061254) )

	ROM_REGION( 0x10000, "audiocpu", 0 ) // roms on the 'SDU board'
	ROM_LOAD( "za25.u25",    0xd000, 0x1000, CRC(779b8558) SHA1(7312e63c23d92c9c52e93cc445a718bc8fe35a0a) )
	ROM_LOAD( "za26.u26",    0xe000, 0x1000, CRC(60a810ce) SHA1(d97e5acea0ef1c208f8e5e95024c83dd6bc9b028) )
	ROM_LOAD( "za27.u27",    0xf000, 0x1000, CRC(99ed424e) SHA1(e4e543dcb77f153aeb78904d11b95381d039299e) )

	ROM_REGION( 0x0800, "mcu", 0 ) // mc68705p3, this is on its own pcb between the coin inputs and the main pcb
	ROM_LOAD( "za_coin.bin", 0x0000, 0x0800, CRC(364d3557) SHA1(049d0759750c576187053306e07984b1e5877df7) )
ROM_END


ROM_START( slither )
	ROM_REGION( 0x10000, "maincpu", 0 )
	ROM_LOAD( "u31.cpu", 0xd800, 0x0800, CRC(3dfff970) SHA1(ee50840e26aa7be226dbe9a32a8344bb75b8de07) )
	ROM_LOAD( "u30.cpu", 0xe000, 0x0800, CRC(8cbc5af8) SHA1(3d563d0bbbce007bd6db6d620e1b0996c67029f6) )
	ROM_LOAD( "u29.cpu", 0xe800, 0x0800, CRC(98c14510) SHA1(7a39b4b691883ad5d079a5c199b93986071c4a49) )
	ROM_LOAD( "u28.cpu", 0xf000, 0x0800, CRC(2762f612) SHA1(2f094832b199d8514ed04c517fca828c75ac7bfa) )
	ROM_LOAD( "u27.cpu", 0xf800, 0x0800, CRC(9306d5b1) SHA1(e5a2c613b1e083b70d63e24dd45472364930398a) )

	ROM_REGION( 0x10000, "videocpu", 0 )
	ROM_LOAD( "u41.cpu", 0xd000, 0x0800, CRC(e4c60a57) SHA1(5ce9fe3d84b7a5ded372f5c3fc14a335a37ad472) )
	ROM_LOAD( "u40.cpu", 0xd800, 0x0800, CRC(5dcec622) SHA1(4c00b91106d1e505bdbd3aefb46bfb1a17f14fc1) )
	ROM_LOAD( "u39.cpu", 0xe000, 0x0800, CRC(69829c2a) SHA1(5ea1f7e6db2b2cebab8663f7a05496f2e13131f9) )
	ROM_LOAD( "u38.cpu", 0xe800, 0x0800, CRC(6adc64c6) SHA1(0502fa9f793a246ade30d506cce62c5d9b773952) )
	ROM_LOAD( "u37.cpu", 0xf000, 0x0800, CRC(55d31c96) SHA1(cf04b30369407dd9a8f0ef5850fdc13d13a7d56d) )
	ROM_LOAD( "u36.cpu", 0xf800, 0x0800, CRC(d5ffc013) SHA1(d278c0a6be86010cdf4b18afc5099dfd39f26523) )
ROM_END


ROM_START( slithera )
	ROM_REGION( 0x10000, "maincpu", 0 )
	ROM_LOAD( "u31.cpu", 0xd800, 0x0800, CRC(3dfff970) SHA1(ee50840e26aa7be226dbe9a32a8344bb75b8de07) )
	ROM_LOAD( "u30.cpu", 0xe000, 0x0800, CRC(8cbc5af8) SHA1(3d563d0bbbce007bd6db6d620e1b0996c67029f6) )
	ROM_LOAD( "u29.cpu", 0xe800, 0x0800, CRC(98c14510) SHA1(7a39b4b691883ad5d079a5c199b93986071c4a49) )
	ROM_LOAD( "u28.cpu", 0xf000, 0x0800, CRC(2762f612) SHA1(2f094832b199d8514ed04c517fca828c75ac7bfa) )
	ROM_LOAD( "u27.cpu", 0xf800, 0x0800, CRC(9306d5b1) SHA1(e5a2c613b1e083b70d63e24dd45472364930398a) )

	ROM_REGION( 0x10000, "videocpu", 0 )
	ROM_LOAD( "u41.cpu", 0xd000, 0x0800, CRC(e4c60a57) SHA1(5ce9fe3d84b7a5ded372f5c3fc14a335a37ad472) )
	ROM_LOAD( "u40.cpu", 0xd800, 0x0800, CRC(5dcec622) SHA1(4c00b91106d1e505bdbd3aefb46bfb1a17f14fc1) )
	ROM_LOAD( "u39.cpu", 0xe000, 0x0800, CRC(69829c2a) SHA1(5ea1f7e6db2b2cebab8663f7a05496f2e13131f9) )
	ROM_LOAD( "u38a.cpu",0xe800, 0x0800, CRC(423adfef) SHA1(f10ca9acf31e602a77b011b002bd53cebf5ba502) )
	ROM_LOAD( "u37.cpu", 0xf000, 0x0800, CRC(55d31c96) SHA1(cf04b30369407dd9a8f0ef5850fdc13d13a7d56d) )
	ROM_LOAD( "u36a.cpu",0xf800, 0x0800, CRC(5ac4e244) SHA1(077bf6f3cb98c3f7845393fb57a080d5bdfc2920) )
ROM_END

ROM_START( complexx )
	ROM_REGION( 0x10000, "maincpu", 0 )
	ROM_LOAD( "cx14.bin", 0xa000, 0x1000, CRC(f123a0de) SHA1(fbb64c33d01031e9da78e725dbdaf87d6e33e23c) )
	ROM_LOAD( "cx15.bin", 0xb000, 0x1000, CRC(0fcb966f) SHA1(f7ea6f0ce356629b8133214c7b2e5ede41c54e6c) )
	ROM_LOAD( "cx16.bin", 0xc000, 0x1000, CRC(aa11e0e3) SHA1(4c0b4fc61c682d501ec3dffd7e324d4dc16425a7) )
	ROM_LOAD( "cx17.bin", 0xd000, 0x1000, CRC(f610856e) SHA1(a01edb705cf7c321800c2739beaee584bfc37270) )
	ROM_LOAD( "cx18.bin", 0xe000, 0x1000, CRC(8f8c3984) SHA1(4cfc83c7a972eeb6e386c9f663388b57c1ebfd00) )
	ROM_LOAD( "cx19.bin", 0xf000, 0x1000, CRC(13af3ba8) SHA1(79ce3dce960d89161db89821d9b211ffd1d399d7) )

	ROM_REGION( 0x10000, "videocpu", 0 )
	ROM_LOAD( "cx5.bin",  0xa000, 0x1000, CRC(62a2b87b) SHA1(eeecdfd3eeba15cd93d1514132919fdc9254c1cb) )
	ROM_LOAD( "cx6.bin",  0xb000, 0x1000, CRC(dfa7c088) SHA1(626cae67db85ab8f87c59f5945032b4cb6683c8b) )
	ROM_LOAD( "cx7.bin",  0xc000, 0x1000, CRC(c8bd6759) SHA1(5e2debc2f5acf5c14da2d0c3daf49a0f63ade07b) )
	ROM_LOAD( "cx8.bin",  0xd000, 0x1000, CRC(14a57221) SHA1(21e0ac7db246cc0a23f0992e6568a9e737db725a) )
	ROM_LOAD( "cx9.bin",  0xe000, 0x1000, CRC(fc2d4a9f) SHA1(ce16cafe09e2a4411bfe3063136507e649ac7870) )
	ROM_LOAD( "cx10.bin", 0xf000, 0x1000, CRC(96e0c1ad) SHA1(4e67b46cc21b4b3e3259d34c618c6d4e4bb1ae78) )

	ROM_REGION( 0x10000, "audiocpu", 0 )
	ROM_LOAD( "cx26.bin",    0xe000, 0x1000, CRC(f4f19c9b) SHA1(d14ae6b59016c428a7e08862f1a4ec89f4eac4fb) )
	ROM_LOAD( "cx27.bin",    0xf000, 0x1000, CRC(7e177328) SHA1(bd3d361bb44341a01a8d118a682ad4efa19be8ff) )
ROM_END



/*************************************
 *
 *  Game-specific initialization
 *
 *************************************/

// 99 means the value is unknown
static const uint8_t xor1_table[] =
{
	99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,
	99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,
	99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,
	99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,
	99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,
	99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,
	99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,
	99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,
	99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,
	99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,
	99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,
	99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,
	99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,
	99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,
	99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,
	99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,
	12, 3,15, 7,12, 7,99, 7,12,11,11,11,12, 8, 7, 8, 3,13,11,11, 4,15, 8, 6,12,99, 3, 3, 0,12, 7,13,
	 3,13, 3, 3,12, 7, 8,99,13,99,11, 3,99, 8, 7, 8,13,11,11, 3, 3,15, 8, 6,12, 3, 3, 3, 0,12, 7,13,
	13,10,10,10,13, 7, 8, 7, 2, 3,13, 3, 2, 8, 7, 8, 2, 2, 2, 2,13,15, 8, 6,13,10, 6, 0, 3,12, 7,13,
	13, 2, 2, 2, 2, 7, 8, 7,13, 0,14, 0,13, 8, 7, 8,13, 0, 6,10,13,15, 8, 6,12, 3, 3, 3,12,12, 7,13,
	13,11,11,11, 4, 7, 8, 7,12, 3, 3, 3,12, 8, 7, 8,13,11,11,11, 4,15, 8, 6, 4,11,11,11, 0,12, 7,13,
	 3, 3,13, 3, 3, 7, 8, 7,13, 2, 2, 2,13, 8, 7, 8,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,
	99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,
	99,99,99,99,99,99,99,99,99, 3, 3,13, 2,99, 7,99, 6, 0,13, 0, 6,15, 8, 6,10,10,10,10,10,12, 7,13,
	10,14, 8,10,10, 7, 8, 7,14, 6, 6, 6,14, 8, 7, 8,14, 6, 6, 6,10,15, 8, 6,14, 6, 6, 6, 6,12, 7,13,
	14, 6, 6, 6,10, 7, 8, 7,14, 6, 6, 6, 6, 8, 7, 8,14, 6, 6, 6, 6,15, 8, 6,14, 6, 6, 6, 6, 8, 7, 8,
	14, 2, 2, 2,14, 7, 8, 7, 2, 6,14, 6, 2, 8, 7, 8, 2, 2, 2, 2,14,15, 8, 6,14, 2, 2,10, 6,12, 7,13,
	14, 2, 2, 2, 2, 7, 8, 7,14, 6,14, 6,14, 8, 7, 8,14,10, 2, 2,14,15, 8, 6,14, 6, 6, 6,14,12, 7,13,
	14, 6,99, 6,14, 7, 8, 7,14, 6, 6,14, 2, 8,99, 8,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,
	99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,
	99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,
	99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,
	 2, 3,99, 1, 7, 5, 4,10, 6, 2, 8,11, 0, 1,12, 6, 6,10,12, 7, 7, 6,99, 1,14,10,12, 0,99, 8, 1, 9,
	 3,15,12, 4,99, 0,11, 3,13, 1, 9, 5,11,15,10, 2, 8, 5,15, 4, 2, 9, 3,14,13,11,12,15, 6,11, 5,13,
	 2,15, 2, 1, 7, 4,12, 8, 6,11, 8,10, 0, 3, 7, 6, 6,10,12, 7, 7, 6, 9, 1,14,10,12, 0,14, 8, 5, 2,
	14,15,12, 4, 0, 0,11, 3,13, 1,14, 5,15,15,10, 2, 8, 5, 9, 4, 2, 8, 3,14,13,11,12,13, 6,11,13, 2,
	13, 9, 9,12,13,12, 9,12,12,15,15, 8, 8,15,12,12,13,15,14,15,14, 2,13,12, 2,14,14,13,14,14,14,14,
	 2, 2, 6, 1,10, 6, 7, 6, 9,11, 5, 0, 5, 9, 0,10,11, 3, 0, 1,10, 6, 4, 7, 5, 9, 7, 7, 2, 0, 4,10,
	 0, 5, 9, 5, 7, 6, 1, 3,11, 4, 2, 4,10, 3, 0,10, 6, 4, 7,11, 2, 1, 1, 9, 3,11, 8, 3, 3, 3, 3, 9,
	 5, 5, 9, 5, 7, 6, 1, 3,11, 4, 2, 4,10, 3, 0,10, 6, 4, 7,11, 2, 1, 1, 9, 3,11, 8, 3, 3,99, 3,99,
	 2, 3,99, 1, 6,99, 4, 5,10, 2, 8, 1, 2, 5,15, 0,11, 3, 4, 1, 6, 7, 4, 6,10,11, 8, 9, 6, 7,12, 8,
	 2,13, 1, 6, 7, 4, 5,10,11,11,14,14, 7,13,12,13, 8, 3, 0, 1, 6, 8, 5, 9,10,11, 8, 9,14, 7, 4, 5,
	15, 8, 9,14,15,12,13, 2, 3, 3,15, 6, 8,11, 9,12, 0, 3, 0, 1,15, 7,10, 5,99,11, 0,13,14,15,12,13,
	15,12, 1,99, 7, 4, 5,10,11, 3, 0, 1, 6, 7, 4, 5, 8,13, 0, 1, 6, 7, 4, 5,10, 2, 6, 7, 4, 5,10,11,
	 4, 3,99, 1,99, 7, 4, 5,10,10, 9,12,99,10, 9, 3,11,99,99, 1,14,99,99,13,99,15,12, 9,14,15,12,13,
	 9, 3, 0,99, 6, 7, 4, 5,10, 1, 6, 7, 4, 5,10,11,11, 2, 3, 0, 1, 6,99, 4, 5, 2,10,11, 8, 9,14,15,
	14, 8, 9,14,15,12,13, 2, 3, 8, 9,14,15,12,13, 2, 0,11, 8, 9,14,15,12,13,99, 2,12,13, 2, 3, 0, 1,
	 8,11, 8, 9,14,15,12,13, 2,10, 0, 1, 6, 7, 4, 5, 3, 9,14,15,12,13, 2, 3, 0, 2, 8, 9,14,15,12,13,
	11, 3, 0, 1, 5,99,12,13,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,13, 5,99,15,12,13,
	 2,13,13, 9, 9,14, 2,15,15,15,14,12, 9, 2, 9, 3, 2, 3, 0, 1, 6, 7, 4, 5,10, 2, 8,12,14,12,12,13,
	14, 3, 0, 1, 6, 7, 4, 5,10, 2, 3, 0, 1, 6, 7, 4, 5,10, 2, 0, 1, 6, 7, 4, 5,10, 2, 8, 8, 8,13,15,
	11, 3, 0, 1, 6, 7, 4, 5,10, 2, 3, 0, 1, 6, 7, 4, 5,10, 2, 0, 1, 6, 7, 4, 5,10,99, 2, 2, 2, 3, 5,
	 2, 3, 0, 1, 2,11, 2,13,99, 2, 2, 9,14,15,12,13, 2,99,99, 1, 2,14,99, 2,10,11, 2, 2,14,15,12,99,
	 2, 2, 2, 2, 2, 8, 5,99, 2, 2, 2, 2, 2, 7, 4, 5,99,99,99,99,99, 6,99,99, 2, 2, 2, 2, 2, 7,99, 8,
	 2,99, 2,99,99, 2, 2, 2,99,99,99,99,99,99,99,99, 4, 2, 2,99, 2, 2,99, 2, 2, 2, 3, 6, 8,11, 9,12,
	15,13, 2, 2, 2, 2,99, 2, 2, 2, 2,14, 7,13,12,13, 2, 2, 2, 2, 2, 2,99, 2, 2, 2, 8, 1, 2, 5,15, 0,
	99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99, 2, 8, 9,14,15,12,13, 2, 3, 0, 2,15, 2, 2, 2, 2,
	 2, 2, 1, 6, 7, 4, 5,10,11, 8, 2, 2, 2, 9, 2, 2,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,
	99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,
	99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,
	99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,
	99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,
	99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,
	99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,
};

static const uint8_t xor2_table[] =
{
	99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,
	99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,
	99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,
	99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,
	99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,
	99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,
	99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,
	99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,
	99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,
	99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,
	99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,
	99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,
	99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,
	99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,
	99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,
	99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,
	 9,99,15, 7,15, 7,99, 7, 5,10, 2,10, 5,99, 7, 8,14, 5, 6,14, 1, 7,10, 0, 1,14,14, 6, 8, 8, 5,15,
	14, 5,14, 6, 9, 7, 8,99, 5,99, 6, 6, 6, 8, 7, 8,13, 2, 2,10, 2, 7,10, 0, 1,14,14, 7,13, 8, 5,15,
	13, 2,10, 2,13, 7, 8, 7, 2,14, 5,14, 2, 8, 7, 8, 8, 6, 6,14, 1, 7,10, 0, 5,10,11, 0,14, 8,99,15,
	13, 6,14, 6,14, 7, 8, 7, 5,10, 2,10, 5, 8, 7, 8,13, 2, 2,10, 5, 7,10, 0, 1,14,14, 6, 9, 8, 5,15,
	13, 2,10, 2,10, 7, 8, 7, 1,14, 7, 8, 7, 8, 7, 8,13, 2, 3, 8, 6, 7,10, 0, 0,14,14, 6, 9, 8, 5,15,
	10, 2,13, 2,99, 7, 8, 7, 1,14,99,14, 1, 8, 7, 8,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,
	99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,
	99,99,99,99,99,99,99,99,99,14,99,13, 2,99, 7,99,10, 2, 5,10, 2, 7,10, 0, 2,10,10, 2,10, 8, 5,15,
	10, 3, 8, 2,10, 7, 8, 7, 5,11, 3,11, 5, 8, 7, 8,13, 7, 7,15, 0, 7,10, 0, 5,14,14, 6,14, 8, 5,15,
	13, 6,14, 6, 9, 7, 8, 7, 5,15, 7,14, 6, 8, 7, 8,13, 3, 3,10, 2, 7,10, 0, 5,14,14, 7,13, 8, 7, 8,
	13, 3,11, 3,13, 7, 8, 7, 2,14, 5,14, 2, 8, 7, 8,12, 6, 6,14, 5, 7,10, 0, 5,11,11, 0,14, 8, 5,15,
	13, 6,14, 6,14, 7, 8, 7, 5,10, 3,10, 5, 8, 7, 8,13, 2, 3, 8, 5, 7,10, 0, 5,14,14, 6,13, 8, 5,15,
	13, 3,11, 3,11, 7, 8, 7, 5,99, 6,13, 6, 8, 7, 8,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,
	99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,
	99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,
	99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,
	 8,99, 9, 1, 1, 9, 1, 9, 9, 1,13, 1, 3,11,10,10, 5, 5,12,13, 4,12,12, 4,99,12, 3,12,11, 2, 2, 3,
	 0,12, 0,13, 0, 5, 4,12, 4,13,10, 5,11,10, 2, 2, 4,12, 9, 4,13, 9, 5, 8, 8,13, 3, 0, 3, 2,10,13,
	 8, 5,14, 8, 8, 8, 9, 8, 0, 8, 7, 0, 3, 3, 2,10,15,15, 6, 7,14, 6, 6,14,14, 6, 3, 6,11, 2, 3,11,
	 1, 6, 0, 7, 0,15,14, 6,99, 7, 2,15, 3,10,10, 2,14, 6, 0,14, 7, 1,15, 8, 1, 7, 3, 7, 3, 2, 2, 2,
	 8, 3,10, 3, 2, 6, 9, 9, 0, 9, 3, 8, 4, 0,10, 5, 7, 6, 2,10, 1, 8, 4,15, 8, 8,11,11, 7, 4, 4, 7,
	 2, 8,12,14, 6, 6,14, 0, 6,14, 6, 5, 9, 9,12, 9, 2,10,10, 2,10,10, 2, 2,10,10,13, 1, 4, 9,14, 5,
	 6,12,15,15, 7,15,13, 5, 7, 4,13, 7,15,12,15,12, 5,13, 4, 4, 7, 7, 4,12,15,13,14, 6, 6, 6, 6, 5,
	 5, 0,99, 3,11, 3,99, 9,11, 8, 1,11, 3,99, 3, 0, 9,99, 8, 8,11,11, 8, 0, 3, 1, 2, 6, 6, 6, 6,99,
	99, 1,99, 1, 1, 1, 1, 1, 1, 4,99, 0, 6, 0, 1, 0, 1,11, 3,11,11,11,11, 2,11,11,11,11, 3, 3,11, 3,
	 1, 0, 7, 7, 7, 7, 7, 7, 7, 9, 7, 0, 0, 7, 1, 1, 7,10,10,10,10, 2, 3, 3,10,10,10,10,10, 2, 2, 2,
	 0, 6, 6, 6, 6, 6, 6, 7, 7, 9, 7, 0, 0, 0, 1, 7, 7, 3, 3, 3,11,10, 2,10,99, 3,11,10,99, 3, 3, 3,
	 5, 5, 5, 5, 5, 5, 5, 5, 5,15,15,15,15,15,15,15, 5,11, 9, 9, 9, 9, 9, 9, 9,10,13,13,13,13,13,13,
	99, 6,99, 6, 6, 6,99, 6, 6, 8, 7, 0,99, 0, 0, 0, 6,99,99, 2,99,99,99,99,11,10,10, 2, 2, 2, 2, 2,
	 5, 4, 4, 4, 4, 4, 4, 4, 4,14,14,14,14,14,14,14, 4, 8, 8, 8, 8, 8, 8, 8, 8,99,12,12,12,12,12,12,
	 5, 4, 4, 4, 4, 4, 4, 5, 5,14,14,14,14, 0,14,15, 5, 8, 8, 8, 8, 8, 8, 8, 9, 2,12,12,13,13,13,13,
	 9,15,15,15,15,15,15,15,12,15,12,12,12,12,12,12,12, 9, 9, 9, 9, 9,14,14,14,11,13,13,13,13,13,13,
	99,11,11,11,99,14,99,14,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99, 8,10,99, 8, 8, 8,99,
	 2, 3, 2, 2, 0, 6, 3, 2,99, 0,99, 3, 6, 0,99, 6, 6, 2,99, 2, 2, 2, 2, 2, 2,10, 2, 0,99, 2, 6, 6,
	 2, 3, 3, 3, 3, 3, 3, 3, 3,11, 0, 0, 0, 0, 0, 0, 0, 0, 8, 6, 6, 6, 6, 6, 6, 6,14, 3, 6, 0,99, 6,
	 2, 7, 7, 7, 7, 7, 7, 7, 7,15, 1, 1, 1, 1, 1, 1, 1, 1, 9, 4, 4, 4, 4, 4, 4, 4,99, 7, 1, 4, 4,11,
	 2, 2, 2, 2, 2, 2, 2, 5,99, 2, 2, 2,99, 2, 2,99, 3,99, 3,99,12,15, 2, 2, 3, 3,99, 2, 3, 3, 3,99,
	99, 2, 2,99, 2, 2, 3,99,99, 2, 2, 2, 2, 2, 2,99,99,99,99,99,99, 3,99, 2, 2, 2, 2, 2,99, 3, 2, 3,
	 8,99,99, 2, 2,99, 2,99,99,99,99,99,99,99,99,99, 8,99, 2, 2,99, 2,99, 2, 2, 2, 8, 8, 8, 8, 9,15,
	 8, 8, 2, 2, 2, 2, 2, 2, 2,99,99, 8, 8,15, 9, 9, 2, 2, 2, 2, 2, 2,99, 2, 2, 2, 9, 8,14, 8,99, 8,
	99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99, 2,12,12,12,12,12,12,13,13,13, 2,13, 2, 2, 2, 2,
	 2, 2,13,13,13,13,13,13,13,13, 2, 2, 2,99, 2, 2,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,
	99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,
	99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,
	99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,
	99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,
	99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,
	99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,11, 6,99,
};

int qix_state::kram3_permut1(int idx, int value)
{
	switch (idx)
	{
		default:
		case 0: return bitswap<8>(value, 7,6,5,4, 3,2,1,0);
		case 1: return bitswap<8>(value, 7,6,5,4, 0,3,2,1);
		case 2: return bitswap<8>(value, 7,6,5,4, 1,0,3,2);
		case 3: return bitswap<8>(value, 7,6,5,4, 2,3,0,1);
	}
}

int qix_state::kram3_permut2(int tbl_index, int idx, const uint8_t *xor_table)
{
	int xorval = 0;

	if (idx == 0 || idx == 3)
	{
		xorval = xor_table[tbl_index];

		// handle missing values in table
		if (xorval == 99)
			return xorval;
	}

	xorval ^= 0x02;

	if (idx == 3)
		xorval = bitswap<8>(xorval, 7,6,5,4, 0,2,3,1);

	return xorval;
}

int qix_state::kram3_decrypt(int address, int value)
{
	int indx1 = (BIT(address,1) << 1) | BIT(address,5);
	int indx2 = (BIT(address,7) << 1) | BIT(address,3);

	int bits1 = ((value & 0x10) >> 1) | ((value & 0x07) >> 0);
	int bits2 = ((value & 0xe0) >> 4) | ((value & 0x08) >> 3);

	int tbl_index = ((address & 0x7f00) >> 4) | (BIT(address,6) << 3) | (BIT(address,4) << 2) | (BIT(address,2) << 1) | (BIT(address,0) << 0);

	int xor1 = kram3_permut2(tbl_index, indx1, xor1_table);
	int xor2 = kram3_permut2(tbl_index, indx2, xor2_table);

	// handle missing values in table
	if (xor1 == 99 || xor2 == 99)
		return 99;

	bits1 = kram3_permut1(indx1, bits1);
	bits2 = kram3_permut1(indx2, bits2);

	bits1 ^= xor1;
	bits2 ^= xor2;

	return ((bits2 & 0xe) << 4) | ((bits1 & 0x8) << 1) | ((bits2 & 0x1) << 3) | ((bits1 & 0x7) << 0);
}

DRIVER_INIT_MEMBER(qix_state,kram3)
{
	//const uint8_t *patch;
	uint8_t *rom, *decrypted;
	int i;

	assert(m_bank0);
	assert(m_bank1);

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

	The encryption algorithm is only partially understood.

	We are currently using two incomplete 2048-nibble tables to get a address
	 dependant xor.

	One important thing to note is that for 6809 instructions that take two
	opcodes (that is, 10 xx and 11 xx) only the first opcode is encrypted, not the
	second. This is different from how the Konami-1 CPU works, where both opcodes
	are encrypted.

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

	i = 0;
	//patch = memregion("user1")->base();
	rom = memregion("maincpu")->base();
	decrypted = auto_alloc_array(machine(), uint8_t, 0x6000);

	memcpy(decrypted,&rom[0xa000],0x6000);
	for (i = 0xa000; i < 0x10000; ++i)
	{
		decrypted[i-0xa000] = kram3_decrypt(i, rom[i]);
	}

	m_bank0->configure_entry(0, memregion("maincpu")->base() + 0xa000);
	m_bank0->configure_entry(1, decrypted);
	m_bank0->set_entry(0);

	i = 0;
	//patch = memregion("user2")->base();
	rom = memregion("videocpu")->base();
	decrypted = auto_alloc_array(machine(), uint8_t, 0x6000);

	memcpy(decrypted,&rom[0xa000],0x6000);
	for (i = 0xa000; i < 0x10000; ++i)
	{
		decrypted[i-0xa000] = kram3_decrypt(i, rom[i]);
	}

	m_bank1->configure_entry(0, memregion("videocpu")->base() + 0xa000);
	m_bank1->configure_entry(1, decrypted);
	m_bank1->set_entry(0);
}

WRITE_LINE_MEMBER(qix_state::kram3_lic_maincpu_changed)
{
	m_bank0->set_entry( state ? 1 : 0 );
}

WRITE_LINE_MEMBER(qix_state::kram3_lic_videocpu_changed)
{
	m_bank1->set_entry( state ? 1 : 0 );
}


DRIVER_INIT_MEMBER(qix_state,zookeep)
{
	/* configure the banking */
	membank("bank1")->configure_entry(0, memregion("videocpu")->base() + 0xa000);
	membank("bank1")->configure_entry(1, memregion("videocpu")->base() + 0x10000);
	membank("bank1")->set_entry(0);
}


DRIVER_INIT_MEMBER(qix_state,slither)
{
}



/*************************************
 *
 *  Game drivers
 *
 *************************************/

GAME( 1981, qix,      0,        qix,      qix,      qix_state, 0,        ROT270, "Taito America Corporation", "Qix (Rev 2)", MACHINE_SUPPORTS_SAVE ) // newest set?  closest to 'qix2'
GAME( 1981, qixa,     qix,      qix,      qix,      qix_state, 0,        ROT270, "Taito America Corporation", "Qix (set 2, smaller roms)", MACHINE_SUPPORTS_SAVE )
GAME( 1981, qixb,     qix,      qix,      qix,      qix_state, 0,        ROT270, "Taito America Corporation", "Qix (set 2, larger roms)", MACHINE_SUPPORTS_SAVE )
GAME( 1981, qixo,     qix,      qix,      qix,      qix_state, 0,        ROT270, "Taito America Corporation", "Qix (set 3, earlier)", MACHINE_SUPPORTS_SAVE ) // oldest set / prototype? has incorrect spelling 'deutch' and doesn't allow language selection to be changed
GAME( 1981, qix2,     qix,      qix,      qix,      qix_state, 0,        ROT270, "Taito America Corporation", "Qix II (Tournament)", MACHINE_SUPPORTS_SAVE )
GAME( 1981, sdungeon, 0,        mcu,      sdungeon, qix_state, 0,        ROT270, "Taito America Corporation", "Space Dungeon", MACHINE_SUPPORTS_SAVE ) // actually released July 1982
GAME( 1981, sdungeona, sdungeon,mcu,      sdungeon, qix_state, 0,        ROT270, "Taito America Corporation", "Space Dungeon (larger roms)", MACHINE_SUPPORTS_SAVE ) // same as above but uses larger ROMs
GAMEL(1982, elecyoyo, 0,        mcu,      elecyoyo, qix_state, 0,        ROT270, "Taito America Corporation", "The Electric Yo-Yo (set 1)", MACHINE_SUPPORTS_SAVE, layout_elecyoyo )
GAMEL(1982, elecyoyo2,elecyoyo, mcu,      elecyoyo, qix_state, 0,        ROT270, "Taito America Corporation", "The Electric Yo-Yo (set 2)", MACHINE_SUPPORTS_SAVE, layout_elecyoyo )
GAME( 1982, kram,     0,        mcu,      kram,     qix_state, 0,        ROT0,   "Taito America Corporation", "Kram (set 1)", MACHINE_SUPPORTS_SAVE )
GAME( 1982, kram2,    kram,     mcu,      kram,     qix_state, 0,        ROT0,   "Taito America Corporation", "Kram (set 2)", MACHINE_SUPPORTS_SAVE )
GAME( 1982, kram3,    kram,     kram3,    kram,     qix_state, kram3,    ROT0,   "Taito America Corporation", "Kram (encrypted)", MACHINE_UNEMULATED_PROTECTION | MACHINE_SUPPORTS_SAVE )
GAME( 1982, zookeep,  0,        zookeep,  zookeep,  qix_state, zookeep,  ROT0,   "Taito America Corporation", "Zoo Keeper (set 1)", MACHINE_SUPPORTS_SAVE )
GAME( 1982, zookeep2, zookeep,  zookeep,  zookeep,  qix_state, zookeep,  ROT0,   "Taito America Corporation", "Zoo Keeper (set 2)", MACHINE_SUPPORTS_SAVE )
GAME( 1982, zookeep3, zookeep,  zookeep,  zookeep,  qix_state, zookeep,  ROT0,   "Taito America Corporation", "Zoo Keeper (set 3)", MACHINE_SUPPORTS_SAVE )
GAME( 1982, slither,  0,        slither,  slither,  qix_state, slither,  ROT270, "Century II", "Slither (set 1)", MACHINE_SUPPORTS_SAVE )
GAME( 1982, slithera, slither,  slither,  slither,  qix_state, slither,  ROT270, "Century II", "Slither (set 2)", MACHINE_SUPPORTS_SAVE )
GAME( 1984, complexx, 0,        qix,      complexx, qix_state, 0,        ROT270, "Taito America Corporation", "Complex X", MACHINE_SUPPORTS_SAVE )