summaryrefslogtreecommitdiffstats
path: root/src/mame/drivers/xavix.cpp
blob: 9175c1f16df4bdfe560bb976ffd7fcba80129ebc (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
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
// license:BSD-3-Clause
// copyright-holders:David Haywood, Angelo Salese
/***************************************************************************

    Preliminary driver for XaviX TV PNP console and childs (Let's! Play TV Classic)

    CPU is an M6502 derivative with added opcodes for far-call handling

    Notes from http://www.videogameconsolelibrary.com/pg00-xavix.htm#page=reviews (thanks Guru!)
    (** this isn't entirely accurate, XaviX Tennis appears to be Super Xavix, see other notes in driver)

    XaviXPORT arrived on the scene with 3 game titles (XaviX Tennis, XaviX Bowling and XaviX Baseball) using their
    original XaviX Multiprocessor.  This proprietary chip is reported to contain an 8-bit high speed central processing
    unit (6502) at 21 MHz, picture processor, sound processor, DMA controller, 1K bytes high speed RAM, universal timer,
    AD/Converter and I/O device control.  Each cartridge comes with a wireless peripheral to be used with the game (Baseball Bat,
    Tennis Racquet, etc.) that requires "AA" batteries.  The XaviXPORT system retailed for $79.99 USD with the cartridges
    retailing for $49.99 USD.

    The following year at CES 2005, SSD COMPANY LIMITED introduced two new XaviXPORT titles (XaviX Golf and XaviX Bass Fishing) each
    containing the upgraded "Super XaviX".  This new chip is said to sport a 16-bit high central processing unit (65816) at 43 MHz.
    SSD COMPANY LIMITED is already working on their next chip called "XaviX II" that is said to be a 32-bit RISC processor
    with 3D capabilities.

    Notes:
	
	To access service mode in Monster Truck hold Horn and Nitro on startup

	There are multiple revisions of the CPU hardware, the SSD 2000 / SSD 2002 chips definitely add more opcodes
	(thanks to Sean Riddle for this table)

	preliminary list of XaviX software based on various sources (some likely still missing)

	 year		name																							PCB ID		ROM width		TSOP pads   ROM size        SEEPROM				die markings			extra components / notes

	2011		anpan-man kazoku de ikunou mat DX/JoyPalette/Japan												-			-				-			-				-					-						-
	2009		anpan-man pyon-pyon ikunou mat/JoyPalette/Japan													-			-				-			-				-					-						-
	2008		kyuukyoku! kinniku grand slam! SASUKE kanzen seiha/EPOCH/Japan									-			-				-			-				-					-						-
	2007		Tokyo Friend park? perfect! mezase! grand slam!/EPOCH/Japan										-			-				-			-				-					-						-
	2006	1	Let's TV Play series "Kamen Rider Kabuto"�/EPOCH/Japan											-			-				-			-				-					-						-
			2	Let's TV Play series "Bo-kenger"�/EPOCH/Japan													-			-				-			-				-					-						-
			3	Challenge Ai-chan! Exciting Ping-pong�/TAKARATOMY/Japan											-			-				-			-				-					-						-
			4	Sasuke & Sportsman Tournament�/BANDAI/Japan														-			-				-			-				-					-						-
			5	Hyper resque, I am a resque team�/BANDAI/Japan													-			-				-			-				-					-						-
			6	Let's TV Play series "Ultraman"�/BANDAI/Japan													-			-				-			-				-					-						-
			7	Let's TV Play Classic series "Namco Nostalgia 1"�/BANDAI/Japan									CGSJ		x8				48			1M				24LC04										dumped non destructively
			8	Let's TV Play Classic series "Namco Nostalgia 2"�/BANDAI/Japan									CGSJ		x8				48			1M				24LC04				SSD 98 PL7351-181		dumped
			9	Let's TV Play Classic series "Taito Nostalgia 1"�/BANDAI/Japan									CGSJ		x8				48			2M				24LC04										flash, dumped non destructively
			10	Let's TV Play Classic series "Taito Nostalgia 2"�/BANDAI/Japan									CGSJ		x8				48			2M				24LC04										flash, dumped non destructively
			11	Let's play and study! Doraemon Hiragana book�/BANDAI/Japan										-			-				-			-				-					-						-
			12	Scan card! Exciting Stage Soccer.�/EPOCH/Japan													-			-				-			-				-					-						-
			13	Hello Kitty Super TV computer�/EPOCH/Japan														-			-				-			-				-					-						-
			14	Doraemon Super TV computer�/EPOCH/Japan															-			-				-			-				-					-						-
	2005	1	Let's TV Play series "Dragon Ball Z"�/BANDAI/Japan												-			-				-			-				-					-						-
			2	Let's TV Play series "Purikyua"�/BANDAI/Japan													-			-				-			-				-					-						-
			3	Idaten Jump�/TOMY/Japan																			-			-				-			-				-					-						-
			4	Tokyo Friend Park 2 Special�/EPOCH/Japan														-			-				-			-				-					-						-
			5	Masked Rider HIBIKI�/BANDAI/Japan																-			-				-			-				-					-						-
			6	Magic Ranger Battle�/BANDAI/Japan																-			-				-			-				-					-						-
			7	Accessory cartridge for Super TV computer "ECC Junior"/EPOCH/Japan								-			-				-			-				-					-						-
			8	Wild Adventure Mini Golf Game�/Hasbro/USA														MGFA		x8				48			4M				24C04				SSD 98 PL7351-181		dumped
			9	MX DIRT REBEL Game�/Hasbro/USA																	MTXA		x8				48			8M				24C04				SSD 2000 NEC 85605-621	dumped
			10	Dokodemo Doraemon Japan Travel Game DX�/EPOCH/Japan												-			-				-			-				-					-						-
			11	Tomas Plarail�/TOMY/Japan																		-			-				-			-				-					-						-
			12	Thomas TV Personal Computer�/EPOCH/Japan														-			-				-			-				-					-						-
			13	STAR WARS Light Saber Battle�/TOMY/Japan														-			-				-			-				-					-						-
			14	Jala Jaland�/atlus/Japan																		-			-				-			-				-					-						-
			15	Star Wars Lightsaber Battle Game�/Hasbro/USA													SWSA		x8				48			8M				24C02				SSD 2000 NEC 85605-621	dumped
			16	Gururin World�/EPOCH/Japan																		-			-				-			-				-					-						-
			17	Toinohgi Onmyo-daisenki�/BANDAI/Japan															-			-				-			-				-					-						-
	2004	1	Accessory cartridge for Super TV computer "Double mouse party"/EPOCH/Japan						-			-				-			-				-					-						-
			2	Printer for TV computer�/EPOCH/Japan															-			-				-			-				-					-						-
			3	Virtual punching battle of "One Piece"�/BANDAI/Japan											-			-				-			-				-					-						-
			4	Accessory cartridge for Super TV computer "Doraemon"/EPOCH/Japan								-			-				-			-				-					-						-
			5	Accessory cartridge for Super TV computer "Hamutaro"/EPOCH/Japan								-			-				-			-				-					-						-
			6	Super TV computer�/EPOCH/Japan																	-			-				-			-				-					-						-
			7	Super Dash ball�/EPOCH/Japan																	-			-				-			-				-					-						-
			8	Exciting sports Tennis X Fitness�/EPOCH/Japan													-			-				-			-				-					-						-
			9	Accessory memory mascot for TV mail Pc mail cot 2 characters (Putchi, Petchi)�/EPOCH/Japan		-			-				-			-				-					-						-
			10	Accessory memory mascot for TV mail Pc mail cot 2 characters (Charuru, Kurau)�/EPOCH/Japan		-			-				-			-				-					-						-
			11	The Lord of the Rings Warrior of Middle Earth�/Hasbro/USA										LORA		x8				48			8M				24C02				SSD 2000 NEC 85605-621	dumped
			12	Beyblade Arcade Challenge 5-in-1�/Hasbro/USA													-			-				-			-				-					-						-
			13	All star Festival Quize�/EPOCH/Japan															-			-				-			-				-					-						-
			14	e-kara mix�/TAKARA/Japan																		-			-				-			-				-					-						-
			15	Jumping Popira�/TAKARA/Japan																	-			-				-			-				-					-						-
			16	Tour around Japan. I'm a Prarail motorman�/TOMY/Japan											-			-				-			-				-					-						-
			17	TV mail PC "Mercot�/EPOCH/Japan																	-			-				-			-				-					-						-
			18	Play TV Monster Truck�/RADICA/USA																74026		x8				48			4M				none				SSD 98 PL7351-181		dumped
			19	Play TV Madden Football�/RADICA/USA																74021		x8				48			4M				none				SSD 98 PL7351-181		dumped
			20	Play TV SSX Snowboarder (and Snowboarder white?)�/RADICA/USA									74023						none																	have
			21	Disney Princess "Kira-Kira magical lesson"�/TOMY/Japan											-			-				-			-				-					-						-
			22	Mermaid Melody "pichi-pichi Pitch" e-pitch microcomputer pure starter set�/TAKARA/Japan			-			-				-			-				-					-						-
			23	Hello Kitty TV computer�/EPOCH/Japan															-			-				-			-				-					-						-
			24	Gan-Gan Revoultion�/TAKARA/Japan																-			-				-			-				-					-						-
	2003	1	Tokyo Friend Park II�/EPOCH/Japan																-			-				-			-				-					-						-
			2	TV mah-jongg�/EPOCH/Japan																		-			-				-			-				-					-						-
			3	e-kara Web�/TAKARA/Japan																		-			-				-			-				-					-						-
			4	Doraemon TV computer�/EPOCH/Japan																-			-				-			-				-					-						-
			5	Exciting stadium DX, Hansin Tigers version�/EPOCH/Japan											-			-				-			-				-					-						-
			6	Dragon Quest�/SQUARE ENIX/Japan																	-			-				-			-				-					-						-
			7	Croquette! Win a medal!�/EPOCH/Japan															-			-				-			-				-					-						-
			8	Taiko Popira�/TAKARA/Japan																		-			-				-			-				-					-						-
			9	Together Minimoni, Dancing' Stage! plus�/EPOCH/Japan											-			-				-			-				-					-						-
			10	Evio�/TOMY/Japan																				-			-				-			-				-					-						-
			11	Together Minimoni,Jumping Party!�/EPOCH/Japan													-			-				-			-				-					-						-
			12	Hamutaro TV computer�/EPOCH/Japan																-			-				-			-				-					-						-
			13	Jara-Ja Land�/TAKARA/Japan																		-			-				-			-				-					-						-
			14	Tomika, Draiving by Car navigation system�/TOMY/Japan											-			-				-			-				-					-						-
			15	PLAY TV Rescue Heroes�/RADICA/USA																73036		x8				48			2M				none				SSD 98 PL7351-181		dumped
			16	PLAY TV Huntin' 2�/RADICA/USA																	73030		x8				none						none				SSD 98 PL7351-181		have
			17	Let's play Ping-pong. Exciting pingpong2�/EPOCH/Japan											-			-				-			-				-					-						-
			18	Cartridge for Slot machine TV "King of wild animal"�/TAKARA/Japan								-			-				-			-				-					-						-
			19	ChyoroQ "Burning up Racer�/TAKARA/Japan															-			-				-			-				-					-						-
			20	Super shot! Exciting golf�/EPOCH/Japan															-			-				-			-				-					-						-
			21	PichiPichi Pitchi�/TAKARA/Japan																	-			-				-			-				-					-						-
			22	Dual Station�/TAKARA/Japan																		-			-				-			-				-					-						-
			23	Gei-Geki GoGo! Shooting�/TAKARA/Japan															-			-				-			-				-					-						-
			24	Let's fish a big one. Exciting fishing!�/EPOCH/Japan											-			-				-			-				-					-						-
			25	Champion Pinball�/TOMY/Japan																	-			-				-			-				-					-						-
			26	Excite Fishing DX																				EF2J		x8				48			4M				24C08				SSD 98 PL7351-181		dumped
	2002	1	Accessory cartridge for Slot machine "Gin-gin maru TV"�/TAKARA/Japan							-			-				-			-				-					-						-
			2	Wildest computer robot "Daigander" (Korean version)�/TAKARA/Korea								-			-				-			-				-					-						-
			3	Hamutaro's circus�/EPOCH/Japan																	-			-				-			-				-					-						-
			4	Doraemon ,computer megaphone�/EPOCH/Japan														-			-				-			-				-					-						-
			5	Strike! Exciting bowling�/EPOCH/Japan															-			-				-			-				-					-						-
			6	e-kara�/Hasbro/Spain																			-			-				-			-				-					-						-
			7	Starter set for e-kara H.S," Morning sisters"�/TAKARA/Japan										-			-				-			-				-					-						-
			8	e-kara H.S.(headphones set)�/TAKARA/Japan														-			-				-			-				-					-						-
			9	Accessory cartridge for Slot machine TV," Aladdin TV"�/TAKARA/Japan								-			-				-			-				-					-						-
			10	Accessory cartridge for Slot machine TV "Businessman Kintaro/TAKARA/Japan						-			-				-			-				-					-						-
			11	Poko-poko Hammers�/TAKARA/Japan																	-			-				-			-				-					-						-
			12	e-kara N Angel blue special set�/TAKARA/Japan													-			-				-			-				-					-						-
			13	Together Minimoni,Dancing Stage!�/EPOCH/Japan													-			-				-			-				-					-						-
			14	King of shooting�/TOMY/Japan																	-			-				-			-				-					-						-
			15	Knock them out! Exciting boxing�/EPOCH/Japan													-			-				-			-				-					-						-
			16	Popira2�/TAKARA/Japan																			-			-				-			-				-					-						-
			17	Zuba-Zuba Blade�/TAKARA/Japan																	-			-				-			-				-					-						-
			18	Starter set for e-kara N "Morning sisters"�/TAKARA/Japan										-			-				-			-				-					-						-
			19	e-kara�/Hasbro/England																			-			-				-			-				-					-						-
			20	e-kara�/Takara USA/USA																			-			-				-			-				-					-						-
			21	e-kara PLAY TV Soccer�/RADICA/USA																76088500	x8				none						none				SSD 98 PA7351-107		(aka Radica PlayTV Soccer? if so, have)
			22	PLAY TV Jr. Construction�/RADICA/USA															-			-				-			-				-					-						-
			23	PLAY TV Boxing�/RADICA/Japan																	72039		x8				48			2M				none				SSD 98 PA7351-107		dumped
			24	PLAY TV Baseball 2�/RADICA/USA																	72042		x8				48			2M				none				SSD 98 PL7351-181		dumped
			25	Barbie Dance Party�/RADICA/USA,EU																-			-				-			-				-					-						-
			26	Compete! Exciting stadium DX�/EPOCH/Japan														-			-				-			-				-					-						-
			27	e-kara N�/EPOCH/Japan																			-			-				-			-				-					-						-
			28	Who's the ace? Excite Tennis�/EPOCH/Japan														-			-				-			-				-					-						-
			29	Wildest computer robot, "Daigander"�/TAKARA/Japan												-			-				-			-				-					-						-
			30	Cartridge for Slot machine TV "King of wild animal Jr."�/TAKARA/Japan							-			-				-			-				-					-						-
			31	Gachinko Contest! Slot machine TV�/DCT/Japan													-			-				-			-				-					-						-
			32	Beyblade Ultimate shooter�/TAKARA/Japan															-			-				-			-				-					-						-
	2001	1	Ping-pong(Chinese version)�/Tenpon/China														-			-				-			-				-					-						-
			2	TV hockey�/TOMY/Japan																			-			-				-			-				-					-						-
			3	e-kara Morning sisters�/TAKARA/Japan															-			-				-			-				-					-						-
			4	e-kara Duet microphone plus�/TAKARA/Japan														-			-				-			-				-					-						-
			5	e-kara plus�/TAKARA/Japan																		-			-				-			-				-					-						-
			6	Hamutaro, Dancing', Running�/EPOCH/Japan														-			-				-			-				-					-						-
			7	Gin-gin Snowboarders�/TAKARA/Japan																-			-				-			-				-					-						-
			8	Shoot! Exciting striker�/EPOCH/Japan															-			-				-			-				-					-						-
			9	e-kara US version�/TAKARA USA, Hasbro/USA,EU													71076		x8				none		1M									SSD 98 PA7351-107		this one or #20 above?	dumped
			10	Popira Korea version�/SONOKONG/Korea															-			-				-			-				-					-						-
			11	I singer: e-kara Korean version�/SONOKONG/Korea													-			-				-			-				-					-						-
			12	Ms.Comett, Lovely baton�/TAKARA/Japan<															-			-				-			-				-					-						-
			13	Dance Dance revolution family mat�/KONAMI,KONAMI Sports/Japan									-			-				-			-				-					-						-
			14	PLAY TV Card Night�/RADICA/USA																	71063		x8				40			1M				none				SSD 98 PA7351-107		dumped
			15	PLAY TV Bass Fishin'�/RADICA/USA																71008		x8				40			1M				none				SSD 98 PA7351-107		dumped
			16	PLAY TV Snowboarder (blue)�/RADICA/USA															71023		x8				40			1M				none				SSD 98 PL7351-181		dumped
			17	Bistro Kids�/SEGA Toys/Japan																	-			-				-			-				-					-						-
			18	Let's construct the town!�/TAKARA/Japan															-			-				-			-				-					-						-
			19	Let's fish black bass! Exciting Fishing�/EPOCH/Japan											-			-				-			-				-					-						-
			20	Baseball Korean version�/SONOKONG/Korea															-			-				-			-				-					-						-
			21	Ping-pong Korean version�/SONOKONG/Korea														-			-				-			-				-					-						-
			22	e-kara Hello Kitty�/TAKARA/Japan																-			-				-			-				-					-						-
			23	Special box "Morning sisters"�/TAKARA/Japan														-			-				-			-				-					-						-
			24	Gan-Gan Adventure�/TAKARA/Japan																	-			-				-			-				-					-						-
			25	e-kara wireless unit�/TAKARA/Japan																-			-				-			-				-					-						-
			26	Webdiver Gradion�/TAKARA/Japan																	-			-				-			-				-					-						-
			27	black bass tsurouze! Excite Fishing/EPOCH/Japan													-			-				-			-				-					-						-
			28	Hamu-chan's Daishuugou dance surunoda! hasirunoda!/EPOCH/Japan									-			-				-			-				-					-						-
	2000	1	Popira�/TAKARA/Japan																			-			-				-			-				-					-						-
			2	e-kara Duet microphone�/TAKARA/Japan															-			-				-			-				-					-						-
			3	e-kara�/TAKARA/Japan																			-			-				-			-				-					-						-
			4	Let's play ping-pong. Exciting ping-pong�/EPOCH/Japan											-			-				-			-				-					-						-
			5	PLAY TV Huntin' Buckmasters�/RADICA/USA															8074		x8				none						none				SSD 98 PA7351-107		have
			6	PLAY TV Ping Pong�/RADICA/USA,HK,EU																8028		x8				48			1M				none				SSD 97 PA7270-107		dumped
			7	PLAY TV OPUS�/RADICA/USA,EU																		-			-				-			-				-					-						-
			8	PLAY TV Baseball 2�/EPOCH/Japan, HK																-			-				-			-				-					-						-
			9	Let's hit a homerun! Exciting baseball�/RADICA/USA,EU											8017		x8				none						none				SSD 98 PA7351-107		(aka Radica PlayTV Baseball, if so, have)
	1999	1	ABC Jungle Fun Hippo�/Vteck/HK, USA, France														-			-				-			-				-					-						-
	Unknown	1	PLAY TV Football /RADICA/USA																	74021		x8				48			4M				none				SSD 98 PL7351-181		dumped																						
				XaviXTennis																						SGM6446		x16				48			8M				24C08				SSD 2002 NEC 85054-611  dumped
				XaviXBowling																					SGM644C		x16				48																		not dumped		


	TODO: put into above table (XaviXPORT cartridges)

	XaviX Tennis and XaviX Baseball are the simplest: just the CPU, x16 ROM and 24C08 SEEPROM.  Bowling and Boxing also have 4 IR LEDs and a 32x32 sensor.
	XaviX Fishing has ROM, 24C08 and a 24-pin daughterboard with a Nordic nRF24E1 2.4GHz 8051-based SoC.
	All the rest of the carts include an S35390 I2C clock chip with crystal and battery backup, and have two x16 ROM chips, using a 5-pin single-gate inverter to create complementary /OE signals.
	J-MAT, Fitness Exercise, Fitness Challenge and Bike Concept have a 24CS64 SEEPROM.  Bike Concept also has two 74HC14s.
	Fitness Dance has an Atmel H93864C (maybe SEEPROM?) a Microchip DSPIC 33FJ12GP202 and two JRC 2740 dual op amps.
	Music and Circuit has a 24CS64, two UTC324 quad op amps, a 74HC14, a 74HCT04, and an 8-pin SOIC labeled 61545, which is likely an M61545 dual electronic volume control.

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


#include "emu.h"
#include "cpu/m6502/xavix.h"
#include "machine/timer.h"
#include "screen.h"
#include "speaker.h"

// not confirmed for all games
#define MAIN_CLOCK XTAL(21'477'272)

class xavix_state : public driver_device
{
public:
	xavix_state(const machine_config &mconfig, device_type type, const char *tag)
		: driver_device(mconfig, type, tag),
		m_maincpu(*this, "maincpu"),
		m_mainram(*this, "mainram"),
		m_spr_attr0(*this, "spr_attr0"),
		m_spr_attr1(*this, "spr_attr1"),
		m_spr_ypos(*this, "spr_ypos"),
		m_spr_xpos(*this, "spr_xpos"),
		m_spr_addr_lo(*this, "spr_addr_lo"),
		m_spr_addr_md(*this, "spr_addr_md"),
		m_spr_addr_hi(*this, "spr_addr_hi"),
		m_palram1(*this, "palram1"),
		m_palram2(*this, "palram2"),
		m_spr_attra(*this, "spr_attra"),
		m_palette(*this, "palette"),
		m_in0(*this, "IN0"),
		m_in1(*this, "IN1"),
		m_region(*this, "REGION"),
		m_gfxdecode(*this, "gfxdecode"),
		m_alt_addressing(0)
	{ }

	// devices
	required_device<cpu_device> m_maincpu;

	// screen updates
	uint32_t screen_update(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect);

	void xavix(machine_config &config);
	void xavixp(machine_config &config);

	DECLARE_WRITE8_MEMBER(xavix_7900_w);

	DECLARE_WRITE8_MEMBER(dma_trigger_w);
	DECLARE_WRITE8_MEMBER(rom_dmasrc_lo_w);
	DECLARE_WRITE8_MEMBER(rom_dmasrc_md_w);
	DECLARE_WRITE8_MEMBER(rom_dmasrc_hi_w);
	DECLARE_WRITE8_MEMBER(rom_dmadst_lo_w);
	DECLARE_WRITE8_MEMBER(rom_dmadst_hi_w);
	DECLARE_WRITE8_MEMBER(rom_dmalen_lo_w);
	DECLARE_WRITE8_MEMBER(rom_dmalen_hi_w);
	DECLARE_READ8_MEMBER(dma_trigger_r);

	DECLARE_WRITE8_MEMBER(vid_dma_params_1_w);
	DECLARE_WRITE8_MEMBER(vid_dma_params_2_w);
	DECLARE_WRITE8_MEMBER(vid_dma_trigger_w);
	DECLARE_READ8_MEMBER(vid_dma_trigger_r);

	DECLARE_READ8_MEMBER(xavix_io_0_r);
	DECLARE_READ8_MEMBER(xavix_io_1_r);

	DECLARE_WRITE8_MEMBER(irq_enable_w);
	DECLARE_WRITE8_MEMBER(irq_vector0_lo_w);
	DECLARE_WRITE8_MEMBER(irq_vector0_hi_w);
	DECLARE_WRITE8_MEMBER(irq_vector1_lo_w);
	DECLARE_WRITE8_MEMBER(irq_vector1_hi_w);

	DECLARE_READ8_MEMBER(irq_source_r);
	DECLARE_WRITE8_MEMBER(irq_source_w);

	DECLARE_READ8_MEMBER(xavix_6ff0_r);
	DECLARE_WRITE8_MEMBER(xavix_6ff0_w);

	DECLARE_READ8_MEMBER(xavix_6ff8_r);
	DECLARE_WRITE8_MEMBER(xavix_6ff8_w);

	DECLARE_READ8_MEMBER(xavix_75f0_r);
	DECLARE_WRITE8_MEMBER(xavix_75f0_w);

	DECLARE_READ8_MEMBER(xavix_75f1_r);
	DECLARE_WRITE8_MEMBER(xavix_75f1_w);

	DECLARE_READ8_MEMBER(xavix_75f4_r);
	DECLARE_READ8_MEMBER(xavix_75f5_r);
	DECLARE_READ8_MEMBER(xavix_75f6_r);
	DECLARE_WRITE8_MEMBER(xavix_75f6_w);

	DECLARE_WRITE8_MEMBER(xavix_75f7_w);

	DECLARE_READ8_MEMBER(xavix_75f8_r);
	DECLARE_WRITE8_MEMBER(xavix_75f8_w);

	DECLARE_READ8_MEMBER(xavix_75f9_r);
	DECLARE_WRITE8_MEMBER(xavix_75f9_w);

	DECLARE_READ8_MEMBER(xavix_75fa_r);
	DECLARE_WRITE8_MEMBER(xavix_75fa_w);
	DECLARE_READ8_MEMBER(xavix_75fb_r);
	DECLARE_WRITE8_MEMBER(xavix_75fb_w);
	DECLARE_READ8_MEMBER(xavix_75fc_r);
	DECLARE_WRITE8_MEMBER(xavix_75fc_w);
	DECLARE_READ8_MEMBER(xavix_75fd_r);
	DECLARE_WRITE8_MEMBER(xavix_75fd_w);

	DECLARE_WRITE8_MEMBER(xavix_75fe_w);
	DECLARE_WRITE8_MEMBER(xavix_75ff_w);

	DECLARE_WRITE8_MEMBER(xavix_6fc0_w);
	DECLARE_WRITE8_MEMBER(tmap1_regs_w);
	DECLARE_WRITE8_MEMBER(xavix_6fd8_w);
	DECLARE_WRITE8_MEMBER(tmap2_regs_w);
	DECLARE_READ8_MEMBER(tmap2_regs_r);

	DECLARE_READ8_MEMBER(pal_ntsc_r);

	DECLARE_READ8_MEMBER(xavix_4000_r);

	DECLARE_READ8_MEMBER(mult_r);
	DECLARE_WRITE8_MEMBER(mult_param_w);

	INTERRUPT_GEN_MEMBER(interrupt);
	TIMER_DEVICE_CALLBACK_MEMBER(scanline_cb);

	DECLARE_DRIVER_INIT(xavix);
	DECLARE_DRIVER_INIT(taitons1);
	DECLARE_DRIVER_INIT(rad_box);

	void xavix_map(address_map &map);
protected:
	// driver_device overrides
	virtual void machine_start() override;
	virtual void machine_reset() override;

	virtual void video_start() override;

private:
	uint8_t m_rom_dmasrc_lo_data;
	uint8_t m_rom_dmasrc_md_data;
	uint8_t m_rom_dmasrc_hi_data;

	uint8_t m_rom_dmadst_lo_data;
	uint8_t m_rom_dmadst_hi_data;

	uint8_t m_rom_dmalen_lo_data;
	uint8_t m_rom_dmalen_hi_data;

	uint8_t m_irq_enable_data;
	uint8_t m_irq_vector0_lo_data;
	uint8_t m_irq_vector0_hi_data;
	uint8_t m_irq_vector1_lo_data;
	uint8_t m_irq_vector1_hi_data;

	uint8_t m_multparams[3];
	uint8_t m_multresults[2];

	uint8_t m_vid_dma_param1[2];
	uint8_t m_vid_dma_param2[2];

	uint8_t m_tmap1_regs[8];
	uint8_t m_tmap2_regs[8];

	uint8_t m_6ff0;
	uint8_t m_6ff8;

	uint8_t m_75f0;
	uint8_t m_75f1;

	uint8_t m_75f6;
	uint8_t m_75f8;
	uint8_t m_75fa;
	uint8_t m_75fb;
	uint8_t m_75fc;
	uint8_t m_75fd;

	uint8_t get_vectors(int which, int half);

	required_shared_ptr<uint8_t> m_mainram;

	required_shared_ptr<uint8_t> m_spr_attr0;
	required_shared_ptr<uint8_t> m_spr_attr1;
	required_shared_ptr<uint8_t> m_spr_ypos;
	required_shared_ptr<uint8_t> m_spr_xpos;

	required_shared_ptr<uint8_t> m_spr_addr_lo;
	required_shared_ptr<uint8_t> m_spr_addr_md;
	required_shared_ptr<uint8_t> m_spr_addr_hi;

	required_shared_ptr<uint8_t> m_palram1;
	required_shared_ptr<uint8_t> m_palram2;

	required_shared_ptr<uint8_t> m_spr_attra;

	required_device<palette_device> m_palette;

	required_ioport m_in0;
	required_ioport m_in1;
	required_ioport m_region;

	required_device<gfxdecode_device> m_gfxdecode;

	void handle_palette(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect);
	double hue2rgb(double p, double q, double t);
	void draw_tile(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect, int tile, int bpp, int xpos, int ypos, int drawheight, int drawwidth, int flipx, int flipy, int pal, int opaque);
	void draw_tilemap(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect, int which);
	void draw_sprites(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect);

	int m_rgnlen;
	uint8_t* m_rgn;

	// variables used by rendering
	int m_tmp_dataaddress;
	int m_tmp_databit;
	void set_data_address(int address, int bit);
	uint8_t get_next_bit();
	uint8_t get_next_byte();

	int get_current_address_byte();

	int m_alt_addressing;
};

void xavix_state::set_data_address(int address, int bit)
{
	m_tmp_dataaddress = address;
	m_tmp_databit = bit;
}

uint8_t xavix_state::get_next_bit()
{
	uint8_t bit = m_rgn[m_tmp_dataaddress & (m_rgnlen - 1)];
	bit = bit >> m_tmp_databit;
	bit &= 1;

	m_tmp_databit++;

	if (m_tmp_databit == 8)
	{
		m_tmp_databit = 0;
		m_tmp_dataaddress++;
	}

	return bit;
}

uint8_t xavix_state::get_next_byte()
{
	uint8_t dat = 0;
	for (int i = 0; i < 8; i++)
	{
		dat |= (get_next_bit() << i);
	}
	return dat;
}

int xavix_state::get_current_address_byte()
{
	return m_tmp_dataaddress;
}


void xavix_state::video_start()
{
}


double xavix_state::hue2rgb(double p, double q, double t)
{
	if (t < 0) t += 1;
	if (t > 1) t -= 1;
	if (t < 1 / 6.0f) return p + (q - p) * 6 * t;
	if (t < 1 / 2.0f) return q;
	if (t < 2 / 3.0f) return p + (q - p) * (2 / 3.0f - t) * 6;
	return p;
}


void xavix_state::handle_palette(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect)
{
	// not verified
	int offs = 0;
	for (int index = 0; index < 256; index++)
	{
		uint16_t dat = m_palram1[offs];
		dat |= m_palram2[offs]<<8;
		offs++;

		int l_raw = (dat & 0x1f00) >> 8;
		int sl_raw =(dat & 0x00e0) >> 5;
		int h_raw = (dat & 0x001f) >> 0;

		//if (h_raw > 24)
		//  logerror("hraw >24 (%02x)\n", h_raw);

		//if (l_raw > 17)
		//  logerror("lraw >17 (%02x)\n", l_raw);

		//if (sl_raw > 7)
		//  logerror("sl_raw >5 (%02x)\n", sl_raw);

		double l = (double)l_raw / 17.0f;
		double s = (double)sl_raw / 7.0f;
		double h = (double)h_raw / 24.0f;

		double r, g, b;

		if (s == 0) {
			r = g = b = l; // greyscale
		}
		else {
			double q = l < 0.5f ? l * (1 + s) : l + s - l * s;
			double p = 2 * l - q;
			r = hue2rgb(p, q, h + 1 / 3.0f);
			g = hue2rgb(p, q, h);
			b = hue2rgb(p, q, h - 1 / 3.0f);
		}

		int r_real = r * 255.0f;
		int g_real = g * 255.0f;
		int b_real = b * 255.0f;

		m_palette->set_pen_color(index, r_real, g_real, b_real);

	}
}

void xavix_state::draw_tilemap(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect, int which)
{
	int alt_tileaddressing = 0;
	int alt_tileaddressing2 = 0;

	int ydimension = 0;
	int xdimension = 0;
	int ytilesize = 0;
	int xtilesize = 0;
	int offset_multiplier = 0;
	int opaque = 0;

	uint8_t* tileregs;
	address_space& mainspace = m_maincpu->space(AS_PROGRAM);

	if (which == 0)
	{
		tileregs = m_tmap1_regs;
		opaque = 1;
	}
	else
	{
		tileregs = m_tmap2_regs;
		opaque = 0;
	}

	switch (tileregs[0x3] & 0x30)
	{
	case 0x00:
		ydimension = 32;
		xdimension = 32;
		ytilesize = 8;
		xtilesize = 8;
		break;

	case 0x10:
		ydimension = 32;
		xdimension = 16;
		ytilesize = 8;
		xtilesize = 16;
		break;

	case 0x20: // guess
		ydimension = 16;
		xdimension = 32;
		ytilesize = 16;
		xtilesize = 8;
		break;

	case 0x30:
		ydimension = 16;
		xdimension = 16;
		ytilesize = 16;
		xtilesize = 16;
		break;
	}

	offset_multiplier = (ytilesize * xtilesize)/8;

	if (tileregs[0x7] & 0x10)
		alt_tileaddressing = 1;
	else
		alt_tileaddressing = 0;

	if (tileregs[0x7] & 0x02)
		alt_tileaddressing2 = 1;

	static int hackx = 1;

	if (machine().input().code_pressed_once(KEYCODE_Q))
	{
		hackx--;
		printf("%02x\n", hackx);
	}

	if (machine().input().code_pressed_once(KEYCODE_W))
	{
		hackx++;
		printf("%02x\n", hackx);
	}

	if (tileregs[0x7] & 0x80)
	{
		//printf("draw tilemap %d, regs base0 %02x base1 %02x base2 %02x tilesize,bpp %02x scrollx %02x scrolly %02x pal %02x mode %02x\n", which, tileregs[0x0], tileregs[0x1], tileregs[0x2], tileregs[0x3], tileregs[0x4], tileregs[0x5], tileregs[0x6], tileregs[0x7]);

		// there's a tilemap register to specify base in main ram, although in the monster truck test mode it points to an unmapped region
		// and expected a fixed layout, we handle that in the memory map at the moment
		int count;

		count = 0;// ;
		for (int y = 0; y < ydimension; y++)
		{
			for (int x = 0; x < xdimension; x++)
			{
				int bpp, pal, scrolly, scrollx;
				int tile = 0;
				int extraattr = 0;

				// the register being 0 probably isn't the condition here
				if (tileregs[0x0] != 0x00) tile |= mainspace.read_byte((tileregs[0x0] << 8) + count);
				if (tileregs[0x1] != 0x00) tile |= mainspace.read_byte((tileregs[0x1] << 8) + count) << 8;

				// at the very least boxing leaves unwanted bits set in ram after changing between mode 0x8a and 0x82, expecting them to not be used
				if (tileregs[0x7] & 0x08)
					extraattr = mainspace.read_byte((tileregs[0x2] << 8) + count);

				count++;

				bpp = (tileregs[0x3] & 0x0e) >> 1;
				bpp++;
				pal = (tileregs[0x6] & 0xf0) >> 4;
				scrolly = tileregs[0x5];
				scrollx = tileregs[0x4];

				int basereg;
				int flipx = 0;
				int flipy = 0;
				int gfxbase;

				// tile 0 is always skipped, doesn't even point to valid data packets in alt mode
				// this is consistent with the top layer too
				// should we draw as solid in solid layer?
				if (tile == 0)
					continue;

				const int debug_packets = 0;
				int test = 0;

				if (!alt_tileaddressing)
				{
					if (!alt_tileaddressing2)
					{
						basereg = 0;
						gfxbase = (m_spr_attra[(basereg * 2) + 1] << 16) | (m_spr_attra[(basereg * 2)] << 8);

						tile = tile * (offset_multiplier * bpp);
						tile += gfxbase;
					}
					else
					{
						tile = tile * 8;
						basereg = (tile & 0x70000) >> 16;
						tile &= 0xffff;
						gfxbase = (m_spr_attra[(basereg * 2) + 1] << 16) | (m_spr_attra[(basereg * 2)] << 8);
						tile += gfxbase;

						if (tileregs[0x7] & 0x08)
						{
							// make use of the extraattr stuff?
							pal = (extraattr & 0xf0)>>4;
							// low bits are priority?
						}
					}
				}
				else
				{
					if (debug_packets) printf("for tile %04x (at %d %d): ", tile, (((x * 16) + scrollx) & 0xff), (((y * 16) + scrolly) & 0xff));


					basereg = (tile & 0xf000) >> 12;
					tile &= 0x0fff;
					gfxbase = (m_spr_attra[(basereg * 2) + 1] << 16) | (m_spr_attra[(basereg * 2)] << 8);

					tile += gfxbase;
					set_data_address(tile, 0);

					// there seems to be a packet stored before the tile?!
					// the offset used for flipped sprites seems to specifically be changed so that it picks up an extra byte which presumably triggers the flipping
					uint8_t byte1 = 0;
					int done = 0;
					int skip = 0;

					do
					{
						byte1 = get_next_byte();

						if (debug_packets) printf(" %02x, ", byte1);

						if (skip == 1)
						{
							skip = 0;
							//test = 1;
						}
						else if ((byte1 & 0x0f) == 0x01)
						{
							// used
						}
						else if ((byte1 & 0x0f) == 0x03)
						{
							// causes next byte to be skipped??
							skip = 1;
						}
						else if ((byte1 & 0x0f) == 0x05)
						{
							// the upper bits are often 0x00, 0x10, 0x20, 0x30, why?
							flipx = 1;
						}
						else if ((byte1 & 0x0f) == 0x06) // there must be other finish conditions too because sometimes this fails..
						{
							// tile data will follow after this, always?
							pal = (byte1 & 0xf0) >> 4;
							done = 1;
						}
						else if ((byte1 & 0x0f) == 0x07)
						{
							// causes next byte to be skipped??
							skip = 1;
						}
						else if ((byte1 & 0x0f) == 0x09)
						{
							// used
						}
						else if ((byte1 & 0x0f) == 0x0a)
						{
							// not seen
						}
						else if ((byte1 & 0x0f) == 0x0b)
						{
							// used
						}
						else if ((byte1 & 0x0f) == 0x0c)
						{
							// not seen
						}
						else if ((byte1 & 0x0f) == 0x0d)
						{
							// used
						}
						else if ((byte1 & 0x0f) == 0x0e)
						{
							// not seen
						}
						else if ((byte1 & 0x0f) == 0x0f)
						{
							// used
						}

					} while (done == 0);
					if (debug_packets) printf("\n");
					tile = get_current_address_byte();
				}

				if (test == 1) pal = machine().rand() & 0xf;


				draw_tile(screen, bitmap, cliprect, tile, bpp, (x * xtilesize) + scrollx, ((y * ytilesize) - 16) - scrolly, ytilesize, xtilesize, flipx, flipy, pal, opaque);
				draw_tile(screen, bitmap, cliprect, tile, bpp, (x * xtilesize) + scrollx, (((y * ytilesize) - 16) - scrolly) + 256, ytilesize, xtilesize, flipx, flipy, pal, opaque); // wrap-y
				draw_tile(screen, bitmap, cliprect, tile, bpp, ((x * xtilesize) + scrollx) - 256, ((y * ytilesize) - 16) - scrolly, ytilesize, xtilesize, flipx, flipy, pal, opaque); // wrap-x
				draw_tile(screen, bitmap, cliprect, tile, bpp, ((x * xtilesize) + scrollx) - 256, (((y * ytilesize) - 16) - scrolly) + 256, ytilesize, xtilesize, flipx, flipy, pal, opaque); // wrap-y and x
			}
		}
	}
}

void xavix_state::draw_sprites(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect)
{
	//logerror("frame\n");
	// priority doesn't seem to be based on list order, there are bad sprite-sprite priorities with either forward or reverse

	for (int i = 0xff; i >= 0; i--)
	{
		/* attribute 0 bits
		   pppp bbb-    p = palette, b = bpp

		   attribute 1 bits
		   ---- ss-f    s = size, f = flipx
		*/

		int ypos = m_spr_ypos[i];
		int xpos = m_spr_xpos[i];
		int tile = (m_spr_addr_hi[i] << 16) | (m_spr_addr_md[i] << 8) | m_spr_addr_lo[i];
		int attr0 = m_spr_attr0[i];
		int attr1 = m_spr_attr1[i];

		int pal = (attr0 & 0xf0) >> 4;
		int flipx = (attr1 & 0x01);

		int drawheight = 16;
		int drawwidth = 16;

		tile &= (m_rgnlen - 1);

		// taito nostalgia 1 also seems to use a different addressing, is it selectable or is the chip different?
		// taito nost attr1 is 84 / 80 / 88 / 8c for the various elements of the xavix logo.  monster truck uses ec / fc / dc / 4c / 5c / 6c (final 6 sprites ingame are 00 00 f0 f0 f0 f0, radar?)

		if ((attr1 & 0x0c) == 0x0c)
		{
			drawheight = 16;
			drawwidth = 16;
			if (m_alt_addressing == 1)
				tile = tile * 128;
			else if (m_alt_addressing == 2)
				tile = tile * 8;
		}
		else if ((attr1 & 0x0c) == 0x08)
		{
			drawheight = 16;
			drawwidth = 8;
			xpos += 4;
			if (m_alt_addressing == 1)
				tile = tile * 64;
			else if (m_alt_addressing == 2)
				tile = tile * 8;
		}
		else if ((attr1 & 0x0c) == 0x04)
		{
			drawheight = 8;
			drawwidth = 16;
			ypos -= 4;
			if (m_alt_addressing == 1)
				tile = tile * 64;
			else if (m_alt_addressing == 2)
				tile = tile * 8;
		}
		else if ((attr1 & 0x0c) == 0x00)
		{
			drawheight = 8;
			drawwidth = 8;
			xpos += 4;
			ypos -= 4;
			if (m_alt_addressing == 1)
				tile = tile * 32;
			else if (m_alt_addressing == 2)
				tile = tile * 8;
		}

		if (m_alt_addressing != 0)
		{
			int basereg = (tile & 0xf0000) >> 16;
			tile &= 0xffff;
			int gfxbase = (m_spr_attra[(basereg * 2) + 1] << 16) | (m_spr_attra[(basereg * 2)] << 8);
			tile+= gfxbase;
		}

		ypos = 0x100 - ypos;

		xpos -= 136;
		ypos -= 152;

		xpos &= 0xff;
		ypos &= 0xff;

		if (ypos >= 192)
			ypos -= 256;

		int bpp = 1;

		bpp = (attr0 & 0x0e) >> 1;
		bpp += 1;

		draw_tile(screen, bitmap, cliprect, tile, bpp, xpos, ypos, drawheight, drawwidth, flipx, 0, pal, 0);
		draw_tile(screen, bitmap, cliprect, tile, bpp, xpos - 256, ypos, drawheight, drawwidth, flipx, 0, pal, 0); // wrap-x
		draw_tile(screen, bitmap, cliprect, tile, bpp, xpos, ypos - 256, drawheight, drawwidth, flipx, 0, pal, 0); // wrap-y
		draw_tile(screen, bitmap, cliprect, tile, bpp, xpos - 256, ypos - 256, drawheight, drawwidth, flipx, 0, pal, 0); // wrap-x,y

		/*
		if ((m_spr_ypos[i] != 0x81) && (m_spr_ypos[i] != 0x80) && (m_spr_ypos[i] != 0x00))
		{
		    logerror("sprite with enable? %02x attr0 %02x attr1 %02x attr3 %02x attr5 %02x attr6 %02x attr7 %02x\n", m_spr_ypos[i], m_spr_attr0[i], m_spr_attr1[i], m_spr_xpos[i], m_spr_addr_lo[i], m_spr_addr_md[i], m_spr_addr_hi[i] );
		}
		*/
	}
}

void xavix_state::draw_tile(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect, int tile, int bpp, int xpos, int ypos, int drawheight, int drawwidth, int flipx, int flipy, int pal, int opaque)
{
	// set the address here so we can increment in bits in the draw function
	set_data_address(tile, 0);

	for (int y = 0; y < drawheight; y++)
	{
		int row;
		if (flipy)
		{
			row = ypos + (drawheight-1) - y;
		}
		else
		{
			row = ypos + y;
		}

		for (int x = 0; x < drawwidth; x++)
		{

			int col;

			if (flipx)
			{
				col = xpos + (drawwidth-1) - x;
			}
			else
			{
				col = xpos + x;
			}

			uint8_t dat = 0;

			for (int i = 0; i < bpp; i++)
			{
				dat |= (get_next_bit() << i);
			}

			if ((row >= cliprect.min_y && row <= cliprect.max_y) && (col >= cliprect.min_x && col <= cliprect.max_x))
			{
				uint16_t* rowptr;

				rowptr = &bitmap.pix16(row);

				if (opaque)
				{
					rowptr[col] = (dat + (pal << 4)) & 0xff;
				}
				else
				{
					if (dat)
						rowptr[col] = (dat + (pal << 4)) & 0xff;
				}
			}
		}
	}
}

uint32_t xavix_state::screen_update(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect)
{
	handle_palette(screen, bitmap, cliprect);

	bitmap.fill(0, cliprect);

	draw_tilemap(screen,bitmap,cliprect,0);
	draw_sprites(screen,bitmap,cliprect);
	draw_tilemap(screen,bitmap,cliprect,1);

	return 0;
}


WRITE8_MEMBER(xavix_state::dma_trigger_w)
{
	if (data & 0x01) // namcons2 writes 0x81, most of the time things write 0x01
	{
		logerror("%s: dma_trigger_w (do DMA?) %02x\n", machine().describe_context(), data);

		uint32_t source = (m_rom_dmasrc_hi_data << 16) | (m_rom_dmasrc_md_data << 8) | m_rom_dmasrc_lo_data;
		uint16_t dest = (m_rom_dmadst_hi_data << 8) | m_rom_dmadst_lo_data;
		uint16_t len = (m_rom_dmalen_hi_data << 8) | m_rom_dmalen_lo_data;

		source &= m_rgnlen - 1;
		logerror("  (possible DMA op SRC %08x DST %04x LEN %04x)\n", source, dest, len);

		address_space& destspace = m_maincpu->space(AS_PROGRAM);

		for (int i = 0; i < len; i++)
		{
			uint8_t dat = m_rgn[(source + i) & (m_rgnlen - 1)];
			destspace.write_byte(dest + i, dat);
		}
	}
	else // the interrupt routine writes 0x80 to the trigger, maybe 'clear IRQ?'
	{
		logerror("%s: dma_trigger_w (unknown) %02x\n", machine().describe_context(), data);
	}
}

WRITE8_MEMBER(xavix_state::rom_dmasrc_lo_w)
{
	logerror("%s: rom_dmasrc_lo_w %02x\n", machine().describe_context(), data);
	m_rom_dmasrc_lo_data = data;
}

WRITE8_MEMBER(xavix_state::rom_dmasrc_md_w)
{
	logerror("%s: rom_dmasrc_md_w %02x\n", machine().describe_context(), data);
	m_rom_dmasrc_md_data = data;
}

WRITE8_MEMBER(xavix_state::rom_dmasrc_hi_w)
{
	logerror("%s: rom_dmasrc_hi_w %02x\n", machine().describe_context(), data);
	m_rom_dmasrc_hi_data = data;
	// this would mean Taito Nostalgia relies on mirroring tho, as it has the high bits set... so could just be wrong
	logerror("  (DMA ROM source of %02x%02x%02x)\n", m_rom_dmasrc_hi_data, m_rom_dmasrc_md_data, m_rom_dmasrc_lo_data);
}

WRITE8_MEMBER(xavix_state::rom_dmadst_lo_w)
{
	logerror("%s: rom_dmadst_lo_w %02x\n", machine().describe_context(), data);
	m_rom_dmadst_lo_data = data;
}

WRITE8_MEMBER(xavix_state::rom_dmadst_hi_w)
{
	logerror("%s: rom_dmadst_hi_w %02x\n", machine().describe_context(), data);
	m_rom_dmadst_hi_data = data;

	logerror("  (DMA dest of %02x%02x)\n", m_rom_dmadst_hi_data, m_rom_dmadst_lo_data);
}

WRITE8_MEMBER(xavix_state::rom_dmalen_lo_w)
{
	logerror("%s: rom_dmalen_lo_w %02x\n", machine().describe_context(), data);
	m_rom_dmalen_lo_data = data;
}

WRITE8_MEMBER(xavix_state::rom_dmalen_hi_w)
{
	logerror("%s: rom_dmalen_hi_w %02x\n", machine().describe_context(), data);
	m_rom_dmalen_hi_data = data;

	logerror("  (DMA len of %02x%02x)\n", m_rom_dmalen_hi_data, m_rom_dmalen_lo_data);
}

READ8_MEMBER(xavix_state::dma_trigger_r)
{
	logerror("%s: dma_trigger_r (operation status?)\n", machine().describe_context());
	return 0x00;
}



WRITE8_MEMBER(xavix_state::irq_enable_w)
{
	logerror("%s: irq_enable_w %02x\n", machine().describe_context(), data);
	m_irq_enable_data = data;
}

WRITE8_MEMBER(xavix_state::irq_vector0_lo_w)
{
	logerror("%s: irq_vector0_lo_w %02x\n", machine().describe_context(), data);
	m_irq_vector0_lo_data = data;
}

WRITE8_MEMBER(xavix_state::irq_vector0_hi_w)
{
	logerror("%s: irq_vector0_hi_w %02x\n", machine().describe_context(), data);
	m_irq_vector0_hi_data = data;
}

WRITE8_MEMBER(xavix_state::irq_vector1_lo_w)
{
	logerror("%s: irq_vector1_lo_w %02x\n", machine().describe_context(), data);
	m_irq_vector1_lo_data = data;
}

WRITE8_MEMBER(xavix_state::irq_vector1_hi_w)
{
	logerror("%s: irq_vector1_hi_w %02x\n", machine().describe_context(), data);
	m_irq_vector1_hi_data = data;
}


WRITE8_MEMBER(xavix_state::xavix_7900_w)
{
	logerror("%s: xavix_7900_w %02x (---FIRST WRITE ON STARTUP---)\n", machine().describe_context(), data);
}



TIMER_DEVICE_CALLBACK_MEMBER(xavix_state::scanline_cb)
{
/*
    int scanline = param;

    if (scanline == 200)
    {
        if (m_irq_enable_data != 0)
            m_maincpu->set_input_line(INPUT_LINE_IRQ0,HOLD_LINE);
    }
*/
}

INTERRUPT_GEN_MEMBER(xavix_state::interrupt)
{
	//  if (m_irq_enable_data != 0)
	//      m_maincpu->set_input_line(INPUT_LINE_IRQ0,HOLD_LINE);

	// this logic is clearly VERY wrong

	if (m_irq_enable_data != 0)
	{
		if (m_6ff8)
			m_maincpu->set_input_line(INPUT_LINE_NMI, PULSE_LINE);
	}
}



READ8_MEMBER(xavix_state::xavix_6ff0_r)
{
	//logerror("%s: xavix_6ff0_r\n", machine().describe_context());
	return m_6ff0;
}

WRITE8_MEMBER(xavix_state::xavix_6ff0_w)
{
	// expected to return data written
	m_6ff0 = data;
	//logerror("%s: xavix_6ff0_w %02x\n", machine().describe_context(), data);
}

READ8_MEMBER(xavix_state::xavix_6ff8_r)
{
	//logerror("%s: xavix_6ff8_r\n", machine().describe_context());
	return m_6ff8;
}

WRITE8_MEMBER(xavix_state::xavix_6ff8_w)
{
	// I think this is something to do with IRQ ack / enable
	m_6ff8 = data;
	logerror("%s: xavix_6ff8_w %02x\n", machine().describe_context(), data);
}

READ8_MEMBER(xavix_state::xavix_75f0_r)
{
	logerror("%s: xavix_75f0_r\n", machine().describe_context());
	return m_75f0;
}

WRITE8_MEMBER(xavix_state::xavix_75f0_w)
{
	// expected to return data written
	m_75f0 = data;
	logerror("%s: xavix_75f0_w %02x\n", machine().describe_context(), data);
}

READ8_MEMBER(xavix_state::xavix_75f1_r)
{
	logerror("%s: xavix_75f1_r\n", machine().describe_context());
	return m_75f1;
}

WRITE8_MEMBER(xavix_state::xavix_75f1_w)
{
	// expected to return data written
	m_75f1 = data;
	logerror("%s: xavix_75f1_w %02x\n", machine().describe_context(), data);
}

READ8_MEMBER(xavix_state::xavix_75f6_r)
{
	logerror("%s: xavix_75f6_w\n", machine().describe_context());
	return m_75f6;
}

WRITE8_MEMBER(xavix_state::xavix_75f6_w)
{
	// expected to return data written
	m_75f6 = data;
	logerror("%s: xavix_75f6_w %02x\n", machine().describe_context(), data);
}

READ8_MEMBER(xavix_state::xavix_75fa_r)
{
	logerror("%s: xavix_75fa_w\n", machine().describe_context());
	return m_75fa;
}

WRITE8_MEMBER(xavix_state::xavix_75fa_w)
{
	// expected to return data written
	m_75fa = data;
	logerror("%s: xavix_75fa_w %02x\n", machine().describe_context(), data);
}

READ8_MEMBER(xavix_state::xavix_75fb_r)
{
	logerror("%s: xavix_75fb_w\n", machine().describe_context());
	return m_75fb;
}

WRITE8_MEMBER(xavix_state::xavix_75fb_w)
{
	// expected to return data written
	m_75fb = data;
	logerror("%s: xavix_75fb_w %02x\n", machine().describe_context(), data);
}

READ8_MEMBER(xavix_state::xavix_75fc_r)
{
	logerror("%s: xavix_75fc_w\n", machine().describe_context());
	return m_75fc;
}

WRITE8_MEMBER(xavix_state::xavix_75fc_w)
{
	// expected to return data written
	m_75fc = data;
	logerror("%s: xavix_75fc_w %02x\n", machine().describe_context(), data);
}

READ8_MEMBER(xavix_state::xavix_75fd_r)
{
	logerror("%s: xavix_75fd_w\n", machine().describe_context());
	return m_75fd;
}

WRITE8_MEMBER(xavix_state::xavix_75fd_w)
{
	// expected to return data written
	m_75fd = data;
	logerror("%s: xavix_75fd_w %02x\n", machine().describe_context(), data);
}





WRITE8_MEMBER(xavix_state::xavix_75f7_w)
{
	logerror("%s: xavix_75f7_w %02x\n", machine().describe_context(), data);
}

READ8_MEMBER(xavix_state::xavix_75f8_r)
{
	logerror("%s: xavix_75f8_r\n", machine().describe_context());
	return m_75f8;
}

WRITE8_MEMBER(xavix_state::xavix_75f8_w)
{
	// expected to return data written
	m_75f8 = data;
	logerror("%s: xavix_75f8_w %02x\n", machine().describe_context(), data);
}

WRITE8_MEMBER(xavix_state::xavix_75f9_w)
{
	logerror("%s: xavix_75f9_w %02x\n", machine().describe_context(), data);
}

WRITE8_MEMBER(xavix_state::xavix_75fe_w)
{
	logerror("%s: xavix_75fe_w %02x\n", machine().describe_context(), data);
}

WRITE8_MEMBER(xavix_state::xavix_75ff_w)
{
	logerror("%s: xavix_75ff_w %02x\n", machine().describe_context(), data);
}

READ8_MEMBER(xavix_state::xavix_75f9_r)
{
	logerror("%s: xavix_75f9_r\n", machine().describe_context());
	return 0x00;
}

READ8_MEMBER(xavix_state::xavix_io_0_r)
{
	return m_in0->read();
}

READ8_MEMBER(xavix_state::xavix_io_1_r)
{
	return m_in1->read();
}

READ8_MEMBER(xavix_state::xavix_75f4_r)
{
	// used with 75f0
	return 0xff;
}

READ8_MEMBER(xavix_state::xavix_75f5_r)
{
	// used with 75f1
	return 0xff;
}

READ8_MEMBER(xavix_state::mult_r)
{
	return m_multresults[offset];
}

WRITE8_MEMBER(xavix_state::mult_param_w)
{
	COMBINE_DATA(&m_multparams[offset]);
	// there are NOPs after one of the writes, so presumably the operation is write triggerd and not intstant
	// see test code at 0184a4 in monster truck

	if (offset == 2)
	{
		// assume 0 is upper bits, might be 'mode' instead, check
		uint16_t param1 = (m_multparams[0]<<8) | (m_multparams[1]);
		uint8_t param2 = (m_multparams[2]);

		uint16_t result =  param1*param2;

		m_multresults[1] = (result>>8)&0xff;
		m_multresults[0] = result&0xff;
	}
}

WRITE8_MEMBER(xavix_state::vid_dma_params_1_w)
{
	m_vid_dma_param1[offset] = data;
}

WRITE8_MEMBER(xavix_state::vid_dma_params_2_w)
{
	m_vid_dma_param2[offset] = data;
}

WRITE8_MEMBER(xavix_state::vid_dma_trigger_w)
{
	uint16_t len = data & 0x07;
	uint16_t src = (m_vid_dma_param1[1]<<8) | m_vid_dma_param1[0];
	uint16_t dst = (m_vid_dma_param2[0]<<8);
	dst += 0x6000;

	uint8_t unk = m_vid_dma_param2[1];

	logerror("%s: vid_dma_trigger_w with trg %02x size %04x src %04x dest %04x unk (%02x)\n", machine().describe_context(), data & 0xf8, len,src,dst,unk);

	if (unk)
	{
		fatalerror("m_vid_dma_param2[1] != 0x00 (is %02x)\n", m_vid_dma_param2[1]);
	}

	if (len == 0x00)
	{
		len = 0x08;
		logerror(" (length was 0x0, assuming 0x8)\n");
	}

	len = len << 8;

	address_space& dmaspace = m_maincpu->space(AS_PROGRAM);

	if (data & 0x40)
	{
		for (int i = 0; i < len; i++)
		{
			uint8_t dat = dmaspace.read_byte(src + i);
			dmaspace.write_byte(dst + i, dat);
		}
	}
}

READ8_MEMBER(xavix_state::vid_dma_trigger_r)
{
	// expects bit 0x40 to clear in most cases
	return 0x00;
}

READ8_MEMBER(xavix_state::pal_ntsc_r)
{
	// only seen 0x10 checked in code
	// in monster truck the tile base address gets set based on this, there are 2 copies of the test screen in rom, one for pal, one for ntsc, see 1854c
	// likewise card night has entirely different tilesets for each region title
	return m_region->read();
}

WRITE8_MEMBER(xavix_state::xavix_6fc0_w) // also related to tilemap 1?
{
	logerror("%s: xavix_6fc0_w data %02x\n", machine().describe_context(), data);
}

WRITE8_MEMBER(xavix_state::tmap1_regs_w)
{
	/*
	   0x0 pointer to address where tile data is
	       it gets set to 0x40 in monster truck test mode, which is outside of ram but test mode requires a fixed 'column scan' layout
	       so that might be special

	   0x1 pointer to middle tile bits (if needed, depends on mode) (usually straight after the ram needed for above)

	   0x2 pointer to tile highest tile bits (if needed, depends on mode) (usually straight after the ram needed for above)

	   0x3 --tt bbb-     - = ?  tt = tile/tilemap size b = bpp    (0x36 xavix logo, 0x3c title screen, 0x36 course select)

	   0x4 and 0x5 are scroll

	   0x6 pppp ----     p = palette  - = ?   (0x02 xavix logo, 0x01 course select)

	   0x7 could be mode (16x16, 8x8 etc.)
	        0x00 is disabled?
	        0x80 means 16x16 tiles
	        0x81 might be 8x8 tiles
	        0x93 course / mode select bg / ingame (weird addressing?)


	 */

	/*
	    6aff base registers
	    -- ingame

	    ae 80
	    02 80
	    02 90
	    02 a0
	    02 b0
	    02 c0
	    02 d0
	    02 e0

	    02 00
	    04 80
	    04 90
	    04 a0
	    04 b0
	    04 c0
	    04 d0
	    04 e0

	    -- menu
	    af 80
	    27 80
	    27 90
	    27 a0
	    27 b0
	    27 c0
	    27 d0
	    27 e0

	    27 00
	    00 80
	    00 90
	    00 a0
	    00 b0
	    00 c0
	    00 d0
	    00 e0
	*/


	if ((offset != 0x4) && (offset != 0x5))
	{
		logerror("%s: tmap1_regs_w offset %02x data %02x\n", machine().describe_context(), offset, data);
	}

	COMBINE_DATA(&m_tmap1_regs[offset]);
}

WRITE8_MEMBER(xavix_state::xavix_6fd8_w) // also related to tilemap 2?
{
	// possibly just a mirror of tmap2_regs_w, at least it writes 0x04 here which would be the correct
	// base address to otherwise write at tmap2_regs_w offset 0
//	tmap2_regs_w(space,offset,data);

	logerror("%s: xavix_6fd8_w data %02x\n", machine().describe_context(), data);
}

WRITE8_MEMBER(xavix_state::tmap2_regs_w)
{
	// same as above but for 2nd tilemap
	if ((offset != 0x4) && (offset != 0x5))
	{
		//logerror("%s: tmap2_regs_w offset %02x data %02x\n", machine().describe_context(), offset, data);
	}

	COMBINE_DATA(&m_tmap2_regs[offset]);
}

READ8_MEMBER(xavix_state::tmap2_regs_r)
{
	// does this return the same data or a status?

	logerror("%s: tmap2_regs_r offset %02x\n", offset, machine().describe_context());
	return m_tmap2_regs[offset];
}

READ8_MEMBER(xavix_state::xavix_4000_r)
{
	if (offset < 0x100)
	{
		return ((offset>>4) | (offset<<4));
	}
	else
	{
		return 0x00;
	}
}

READ8_MEMBER(xavix_state::irq_source_r)
{
	/* the 2nd IRQ routine (regular IRQ, not NMI?) reads here before deciding what to do

	 the following bits have been seen to be checked (active low?)

	  0x40 - Monster Truck - stuff with 6ffb 6fd6 and 6ff8
	  0x20 - most games (but not Monster Truck) - DMA related?
	  0x10 - card night + monster truck - 7c00 related? (increases 16-bit counter in ram stores 0xc1 at 7c00)
	  0x08 - several games - Input related (ADC? - used for analog control on Monster Truck) (uses 7a80 top bit to determine direction, and 7a81 0x08 as an output, presumably to clock)
	  0x04 - Monster Truck - loads/stores 7b81
	*/
	logerror("%s: irq_source_r\n", machine().describe_context());
	return 0xff;
}

WRITE8_MEMBER(xavix_state::irq_source_w)
{
	logerror("%s: irq_source_w %02x\n", machine().describe_context(), data);
	// cleared on startup in monster truck, no purpose?
}


// DATA reads from 0x8000-0xffff are banked by byte 0xff of 'ram' (this is handled in the CPU core)

ADDRESS_MAP_START(xavix_state::xavix_map)
	AM_RANGE(0x000000, 0x0001ff) AM_RAM
	AM_RANGE(0x000200, 0x003fff) AM_RAM AM_SHARE("mainram")

	// this might not be a real area, the tilemap base register gets set to 0x40 in monster truck service mode, and expects a fixed layout.
	// As that would point at this address maybe said layout is being read from here, or maybe it's just a magic tilemap register value that doesn't read address space at all.
	AM_RANGE(0x004000, 0x0041ff) AM_READ(xavix_4000_r)

	// 6xxx ranges are the video hardware
	// appears to be 256 sprites (shares will be renamed once their purpose is known)
	AM_RANGE(0x006000, 0x0060ff) AM_RAM AM_SHARE("spr_attr0")
	AM_RANGE(0x006100, 0x0061ff) AM_RAM AM_SHARE("spr_attr1")
	AM_RANGE(0x006200, 0x0062ff) AM_RAM AM_SHARE("spr_ypos") // cleared to 0x80 by both games, maybe enable registers?
	AM_RANGE(0x006300, 0x0063ff) AM_RAM AM_SHARE("spr_xpos")
	AM_RANGE(0x006400, 0x0064ff) AM_RAM // 6400 range gets populated in some cases, but it seems to be more like work ram, data doesn't matter and must be ignored?
	AM_RANGE(0x006500, 0x0065ff) AM_RAM AM_SHARE("spr_addr_lo")
	AM_RANGE(0x006600, 0x0066ff) AM_RAM AM_SHARE("spr_addr_md")
	AM_RANGE(0x006700, 0x0067ff) AM_RAM AM_SHARE("spr_addr_hi")
	AM_RANGE(0x006800, 0x0068ff) AM_RAM AM_SHARE("palram1") // written with 6900
	AM_RANGE(0x006900, 0x0069ff) AM_RAM AM_SHARE("palram2") // startup (taitons1)
	AM_RANGE(0x006a00, 0x006a1f) AM_RAM AM_SHARE("spr_attra") // test mode, pass flag 0x20


	AM_RANGE(0x006fc0, 0x006fc0) AM_WRITE(xavix_6fc0_w) // startup (maybe this is a mirror of tmap1_regs_w)

	AM_RANGE(0x006fc8, 0x006fcf) AM_WRITE(tmap1_regs_w) // video registers

	AM_RANGE(0x006fd0, 0x006fd7) AM_READWRITE(tmap2_regs_r, tmap2_regs_w)
	AM_RANGE(0x006fd8, 0x006fd8) AM_WRITE(xavix_6fd8_w) // startup (mirror of tmap2_regs_w?)

	AM_RANGE(0x006fe0, 0x006fe0) AM_READWRITE(vid_dma_trigger_r, vid_dma_trigger_w) // after writing to 6fe1/6fe2 and 6fe5/6fe6 rad_mtrk writes 0x43/0x44 here then polls on 0x40   (see function call at c273) write values are hardcoded, similar code at 18401
	AM_RANGE(0x006fe1, 0x006fe2) AM_WRITE(vid_dma_params_1_w)
	AM_RANGE(0x006fe5, 0x006fe6) AM_WRITE(vid_dma_params_2_w)

	// function in rad_mtrk at 0184b7 uses this
	AM_RANGE(0x006fe8, 0x006fe8) AM_RAM // r/w tested
	AM_RANGE(0x006fe9, 0x006fe9) AM_RAM // r/w tested
	//AM_RANGE(0x006fea, 0x006fea) AM_WRITENOP

	AM_RANGE(0x006ff0, 0x006ff0) AM_READWRITE(xavix_6ff0_r, xavix_6ff0_w) // r/w tested
	//AM_RANGE(0x006ff1, 0x006ff1) AM_WRITENOP // startup - cleared in interrupt 0
	//AM_RANGE(0x006ff2, 0x006ff2) AM_WRITENOP // set to 07 after clearing above things in interrupt 0

	AM_RANGE(0x006ff8, 0x006ff8) AM_READWRITE(xavix_6ff8_r, xavix_6ff8_w) // always seems to be a read/store or read/modify/store
	AM_RANGE(0x006ff9, 0x006ff9) AM_READ(pal_ntsc_r)

	// 7xxx ranges system controller?

	AM_RANGE(0x0075f0, 0x0075f0) AM_READWRITE(xavix_75f0_r, xavix_75f0_w) // r/w tested read/written 8 times in a row
	AM_RANGE(0x0075f1, 0x0075f1) AM_READWRITE(xavix_75f1_r, xavix_75f1_w) // r/w tested read/written 8 times in a row
	AM_RANGE(0x0075f3, 0x0075f3) AM_RAM
	AM_RANGE(0x0075f4, 0x0075f4) AM_READ(xavix_75f4_r) // related to 75f0 (read after writing there - rad_mtrk)
	AM_RANGE(0x0075f5, 0x0075f5) AM_READ(xavix_75f5_r) // related to 75f1 (read after writing there - rad_mtrk)

	// taitons1 after 75f7/75f8
	AM_RANGE(0x0075f6, 0x0075f6) AM_READWRITE(xavix_75f6_r, xavix_75f6_w) // r/w tested
	// taitons1 written as a pair
	AM_RANGE(0x0075f7, 0x0075f7) AM_WRITE(xavix_75f7_w)
	AM_RANGE(0x0075f8, 0x0075f8) AM_READWRITE(xavix_75f8_r, xavix_75f8_w) // r/w tested
	// taitons1 written after 75f6, then read
	AM_RANGE(0x0075f9, 0x0075f9) AM_READWRITE(xavix_75f9_r, xavix_75f9_w)
	// at another time
	AM_RANGE(0x0075fa, 0x0075fa) AM_READWRITE(xavix_75fa_r, xavix_75fa_w) // r/w tested
	AM_RANGE(0x0075fb, 0x0075fb) AM_READWRITE(xavix_75fb_r, xavix_75fb_w) // r/w tested
	AM_RANGE(0x0075fc, 0x0075fc) AM_READWRITE(xavix_75fc_r, xavix_75fc_w) // r/w tested
	AM_RANGE(0x0075fd, 0x0075fd) AM_READWRITE(xavix_75fd_r, xavix_75fd_w) // r/w tested
	AM_RANGE(0x0075fe, 0x0075fe) AM_WRITE(xavix_75fe_w)
	// taitons1 written other 75xx operations
	AM_RANGE(0x0075ff, 0x0075ff) AM_WRITE(xavix_75ff_w)

	//AM_RANGE(0x007810, 0x007810) AM_WRITENOP // startup

	//AM_RANGE(0x007900, 0x007900) AM_WRITE(xavix_7900_w) // startup
	//AM_RANGE(0x007902, 0x007902) AM_WRITENOP // startup

	// DMA trigger for below (written after the others) waits on status of bit 1 in a loop
	AM_RANGE(0x007980, 0x007980) AM_READWRITE(dma_trigger_r, dma_trigger_w)
	// DMA source
	AM_RANGE(0x007981, 0x007981) AM_WRITE(rom_dmasrc_lo_w)
	AM_RANGE(0x007982, 0x007982) AM_WRITE(rom_dmasrc_md_w)
	AM_RANGE(0x007983, 0x007983) AM_WRITE(rom_dmasrc_hi_w)
	// DMA dest
	AM_RANGE(0x007984, 0x007984) AM_WRITE(rom_dmadst_lo_w)
	AM_RANGE(0x007985, 0x007985) AM_WRITE(rom_dmadst_hi_w)
	// DMA length
	AM_RANGE(0x007986, 0x007986) AM_WRITE(rom_dmalen_lo_w)
	AM_RANGE(0x007987, 0x007987) AM_WRITE(rom_dmalen_hi_w)

	// GPIO stuff
	AM_RANGE(0x007a00, 0x007a00) AM_READ(xavix_io_0_r)
	AM_RANGE(0x007a01, 0x007a01) AM_READ(xavix_io_1_r) //AM_WRITENOP // startup (taitons1)
	//AM_RANGE(0x007a02, 0x007a02) AM_WRITENOP // startup, gets set to 20, 7a00 is then also written with 20
	//AM_RANGE(0x007a03, 0x007a03) AM_READNOP AM_WRITENOP // startup (gets set to 84 which is the same as the bits checked on 7a01, possible port direction register?)

	//AM_RANGE(0x007a80, 0x007a80) AM_WRITENOP

	//AM_RANGE(0x007b80, 0x007b80) AM_READNOP
	//AM_RANGE(0x007b81, 0x007b81) AM_WRITENOP // every frame?
	//AM_RANGE(0x007b82, 0x007b82) AM_WRITENOP

	//AM_RANGE(0x007c01, 0x007c01) AM_RAM // r/w tested
	//AM_RANGE(0x007c02, 0x007c02) AM_WRITENOP // once

	// this is a multiplication chip
	AM_RANGE(0x007ff2, 0x007ff4) AM_WRITE(mult_param_w)
	AM_RANGE(0x007ff5, 0x007ff6) AM_READ(mult_r)

	// maybe irq enable, written after below
	AM_RANGE(0x007ff9, 0x007ff9) AM_WRITE(irq_enable_w) // interrupt related, but probalby not a simple 'enable' otherwise interrupts happen before we're ready for them.
	// an IRQ vector (nmi?)
	AM_RANGE(0x007ffa, 0x007ffa) AM_WRITE(irq_vector0_lo_w)
	AM_RANGE(0x007ffb, 0x007ffb) AM_WRITE(irq_vector0_hi_w)

	AM_RANGE(0x007ffc, 0x007ffc) AM_READWRITE(irq_source_r, irq_source_w)

	// an IRQ vector (irq?)
	AM_RANGE(0x007ffe, 0x007ffe) AM_WRITE(irq_vector1_lo_w)
	AM_RANGE(0x007fff, 0x007fff) AM_WRITE(irq_vector1_hi_w)

//  rom is installed in init due to different rom sizes and mirroring required
//  AM_RANGE(0x008000, 0x7fffff) AM_ROM AM_REGION("bios", 0x008000) AM_MIRROR(0x800000) // rad_mtrk relies on rom mirroring
ADDRESS_MAP_END

static INPUT_PORTS_START( xavix )
	PORT_START("IN0")
	PORT_DIPNAME( 0x01, 0x00, "IN0" )
	PORT_DIPSETTING(    0x00, DEF_STR( Off ) )
	PORT_DIPSETTING(    0x01, DEF_STR( On ) )
	PORT_DIPNAME( 0x02, 0x00, DEF_STR( Unknown ) )
	PORT_DIPSETTING(    0x00, DEF_STR( Off ) )
	PORT_DIPSETTING(    0x02, DEF_STR( On ) )
	PORT_DIPNAME( 0x04, 0x00, DEF_STR( Unknown ) )
	PORT_DIPSETTING(    0x00, DEF_STR( Off ) )
	PORT_DIPSETTING(    0x04, DEF_STR( On ) )
	PORT_DIPNAME( 0x08, 0x00, DEF_STR( Unknown ) )
	PORT_DIPSETTING(    0x00, DEF_STR( Off ) )
	PORT_DIPSETTING(    0x08, DEF_STR( On ) )
	PORT_DIPNAME( 0x10, 0x00, DEF_STR( Unknown ) )
	PORT_DIPSETTING(    0x00, DEF_STR( Off ) )
	PORT_DIPSETTING(    0x10, DEF_STR( On ) )
	PORT_DIPNAME( 0x20, 0x00, DEF_STR( Unknown ) )
	PORT_DIPSETTING(    0x00, DEF_STR( Off ) )
	PORT_DIPSETTING(    0x20, DEF_STR( On ) )
	PORT_DIPNAME( 0x40, 0x00, DEF_STR( Unknown ) )
	PORT_DIPSETTING(    0x00, DEF_STR( Off ) )
	PORT_DIPSETTING(    0x40, DEF_STR( On ) )
	PORT_DIPNAME( 0x80, 0x00, DEF_STR( Unknown ) )
	PORT_DIPSETTING(    0x00, DEF_STR( Off ) )
	PORT_DIPSETTING(    0x80, DEF_STR( On ) )

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

	PORT_START("REGION") // PAL/NTSC flag
	PORT_BIT( 0xff, IP_ACTIVE_HIGH, IPT_SPECIAL )
INPUT_PORTS_END

static INPUT_PORTS_START( xavixp )
	PORT_INCLUDE(xavix)

	PORT_MODIFY("REGION") // PAL/NTSC flag
	PORT_BIT( 0xff, IP_ACTIVE_LOW, IPT_SPECIAL )
INPUT_PORTS_END

/* Test mode lists the following

  LED (on power button?)
  Throttle Low
  Throttle High
  Reverse
  NO2
  Steering Left (4 positions)
  Steering Right (4 positions)
  Horn

*/


static INPUT_PORTS_START( rad_mtrk )
	PORT_INCLUDE(xavix)

	PORT_MODIFY("IN0")
	PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_BUTTON5 ) PORT_NAME("Nitro")
	PORT_BIT( 0x04, IP_ACTIVE_HIGH, IPT_BUTTON4 ) PORT_NAME("Throttle High")
	PORT_BIT( 0x08, IP_ACTIVE_HIGH, IPT_BUTTON3 ) PORT_NAME("Throttle Low")
	PORT_BIT( 0x10, IP_ACTIVE_HIGH, IPT_BUTTON2 ) PORT_NAME("Reverse / Back")

	PORT_MODIFY("IN1")
	PORT_BIT( 0x02, IP_ACTIVE_HIGH, IPT_BUTTON1 ) PORT_NAME("Horn")
	PORT_BIT( 0x40, IP_ACTIVE_HIGH, IPT_SERVICE1 ) // some kind of 'power off' (fades screen to black, jumps to an infinite loop) maybe low battery condition or just the power button?
INPUT_PORTS_END

static INPUT_PORTS_START( rad_mtrkp )
	PORT_INCLUDE(rad_mtrk)

	PORT_MODIFY("REGION") // PAL/NTSC flag
	PORT_BIT( 0xff, IP_ACTIVE_LOW, IPT_SPECIAL )
INPUT_PORTS_END

static INPUT_PORTS_START( rad_crdn )
	PORT_INCLUDE(xavix)

	PORT_MODIFY("IN0")
	PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_BUTTON1 ) // can press this to get to a game select screen
INPUT_PORTS_END

static INPUT_PORTS_START( rad_crdnp )
	PORT_INCLUDE(rad_crdn)

	PORT_MODIFY("REGION") // PAL/NTSC flag
	PORT_BIT( 0xff, IP_ACTIVE_LOW, IPT_SPECIAL )
INPUT_PORTS_END

static INPUT_PORTS_START( rad_box )
	PORT_INCLUDE(xavix)

	PORT_MODIFY("IN0")
	// 6 types of punch and some navigation controls?
	PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_BUTTON1 ) PORT_NAME("Left Jan")
	PORT_BIT( 0x02, IP_ACTIVE_HIGH, IPT_BUTTON2 ) PORT_NAME("Left Hook")
	PORT_BIT( 0x04, IP_ACTIVE_HIGH, IPT_BUTTON3 ) PORT_NAME("Left Uppercut")
	PORT_BIT( 0x08, IP_ACTIVE_HIGH, IPT_BUTTON4 ) PORT_NAME("Left Jab")
	PORT_BIT( 0x10, IP_ACTIVE_HIGH, IPT_BUTTON5 ) PORT_NAME("Left Hook")
	PORT_BIT( 0x20, IP_ACTIVE_HIGH, IPT_BUTTON6 ) PORT_NAME("Left Uppercut")
	PORT_BIT( 0x40, IP_ACTIVE_HIGH, IPT_JOYSTICK_LEFT )
	PORT_BIT( 0x80, IP_ACTIVE_HIGH, IPT_JOYSTICK_RIGHT )

	PORT_MODIFY("IN1")
	PORT_BIT( 0x08, IP_ACTIVE_HIGH, IPT_BUTTON7 )  PORT_NAME("Block")
	PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_UNKNOWN ) // needs to be high to pass warning screen?
INPUT_PORTS_END

static INPUT_PORTS_START( rad_boxp )
	PORT_INCLUDE(rad_box)

	PORT_MODIFY("REGION") // PAL/NTSC flag
	PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_SPECIAL )
INPUT_PORTS_END


static INPUT_PORTS_START( rad_snow )
	PORT_INCLUDE(xavix)

	PORT_MODIFY("IN0")
	PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_BUTTON1 ) PORT_NAME("Go") // is this a button, or 'up' ?

	PORT_BIT( 0x08, IP_ACTIVE_HIGH, IPT_JOYSTICK_DOWN )
	PORT_BIT( 0x10, IP_ACTIVE_HIGH, IPT_JOYSTICK_LEFT )
	PORT_BIT( 0x20, IP_ACTIVE_HIGH, IPT_JOYSTICK_RIGHT )
INPUT_PORTS_END

static INPUT_PORTS_START( rad_snowp )
	PORT_INCLUDE(rad_snow)

	PORT_MODIFY("REGION") // PAL/NTSC flag
	PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_SPECIAL )
INPUT_PORTS_END

static INPUT_PORTS_START( namcons2 )
	PORT_INCLUDE(xavix)

	PORT_MODIFY("IN0")
	PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_BUTTON1 )
	PORT_BIT( 0x02, IP_ACTIVE_HIGH, IPT_BUTTON2 )
	PORT_BIT( 0x04, IP_ACTIVE_HIGH, IPT_BUTTON3 )
	PORT_BIT( 0x08, IP_ACTIVE_HIGH, IPT_BUTTON4 )
INPUT_PORTS_END

/* correct, 4bpp gfxs */
static const gfx_layout charlayout =
{
	8,8,
	RGN_FRAC(1,1),
	4,
	{ STEP4(0,1) },
	{ 1*4,0*4,3*4,2*4,5*4,4*4,7*4,6*4 },
	{ STEP8(0,4*8) },
	8*8*4
};

static const gfx_layout char16layout =
{
	16,16,
	RGN_FRAC(1,1),
	4,
	{ STEP4(0,1) },
	{ 1*4,0*4,3*4,2*4,5*4,4*4,7*4,6*4, 9*4,8*4,11*4,10*4,13*4,12*4,15*4,14*4   },
	{ STEP16(0,4*16) },
	16*16*4
};

static const gfx_layout charlayout8bpp =
{
	8,8,
	RGN_FRAC(1,1),
	8,
	{ STEP8(0,1) },
	{ STEP8(0,8) },
	{ STEP8(0,8*8) },
	8*8*8
};

static const gfx_layout char16layout8bpp =
{
	16,16,
	RGN_FRAC(1,1),
	8,
	{ STEP8(0,1) },
	{ STEP16(0,8) },
	{ STEP16(0,16*8) },
	16*16*8
};



static GFXDECODE_START( xavix )
	GFXDECODE_ENTRY( "bios", 0, charlayout,   0, 16 )
	GFXDECODE_ENTRY( "bios", 0, char16layout, 0, 16 )
	GFXDECODE_ENTRY( "bios", 0, charlayout8bpp, 0, 1 )
	GFXDECODE_ENTRY( "bios", 0, char16layout8bpp, 0, 1 )
GFXDECODE_END


void xavix_state::machine_start()
{
}

void xavix_state::machine_reset()
{
	m_rom_dmasrc_lo_data = 0;
	m_rom_dmasrc_md_data = 0;
	m_rom_dmasrc_hi_data = 0;

	m_rom_dmadst_lo_data = 0;
	m_rom_dmadst_hi_data = 0;

	m_rom_dmalen_lo_data = 0;
	m_rom_dmalen_hi_data = 0;

	m_irq_enable_data = 0;
	m_irq_vector0_lo_data = 0;
	m_irq_vector0_hi_data = 0;
	m_irq_vector1_lo_data = 0;
	m_irq_vector1_hi_data = 0;

	m_6ff0 = 0;
	m_6ff8 = 0;

	m_75f0 = 0;
	m_75f1 = 0;

	m_75f6 = 0;
	m_75f8 = 0;
	m_75fa = 0;
	m_75fb = 0;
	m_75fc = 0;
	m_75fd = 0;

	for (int i = 0; i < 3; i++)
		m_multparams[i] = 0;

	for (int i = 0; i < 2; i++)
		m_multresults[i] = 0;

	for (int i = 0; i < 2; i++)
	{
		m_vid_dma_param1[i] = 0;
		m_vid_dma_param2[i] = 0;
	}

	for (int i = 0; i < 8; i++)
	{
		m_tmap1_regs[i] = 0;
		m_tmap2_regs[i] = 0;
	}
}

typedef device_delegate<uint8_t (int which, int half)> xavix_interrupt_vector_delegate;

uint8_t xavix_state::get_vectors(int which, int half)
{
//  logerror("get_vectors %d %d\n", which, half);

	if (which == 0) // irq?
	{
		if (half == 0)
			return m_irq_vector0_hi_data;
		else
			return m_irq_vector0_lo_data;
	}
	else
	{
		if (half == 0)
			return m_irq_vector1_hi_data;
		else
			return m_irq_vector1_lo_data;
	}
}

MACHINE_CONFIG_START(xavix_state::xavix)

	/* basic machine hardware */
	MCFG_CPU_ADD("maincpu",XAVIX,MAIN_CLOCK)
	MCFG_CPU_PROGRAM_MAP(xavix_map)
	MCFG_M6502_DISABLE_DIRECT()
	MCFG_CPU_VBLANK_INT_DRIVER("screen", xavix_state,  interrupt)
	MCFG_XAVIX_VECTOR_CALLBACK(xavix_state, get_vectors)

	MCFG_TIMER_DRIVER_ADD_SCANLINE("scantimer", xavix_state, scanline_cb, "screen", 0, 1)


	/* video hardware */
	MCFG_SCREEN_ADD("screen", RASTER)
	MCFG_SCREEN_REFRESH_RATE(60)
	MCFG_SCREEN_VBLANK_TIME(ATTOSECONDS_IN_USEC(2500))
	MCFG_SCREEN_UPDATE_DRIVER(xavix_state, screen_update)
	MCFG_SCREEN_SIZE(32*8, 32*8)
	MCFG_SCREEN_VISIBLE_AREA(1*8, 31*8-1, 0*8, 28*8-1)
	MCFG_SCREEN_PALETTE("palette")

	MCFG_GFXDECODE_ADD("gfxdecode", "palette", xavix)

	MCFG_PALETTE_ADD("palette", 256)

	/* sound hardware */
	MCFG_SPEAKER_STANDARD_MONO("mono")
	// sound is PCM
MACHINE_CONFIG_END


MACHINE_CONFIG_START(xavix_state::xavixp)
	xavix(config);

	MCFG_SCREEN_MODIFY("screen")
	MCFG_SCREEN_REFRESH_RATE(50)
MACHINE_CONFIG_END

DRIVER_INIT_MEMBER(xavix_state,xavix)
{
	m_rgnlen = memregion("bios")->bytes();
	m_rgn = memregion("bios")->base();

	// mirror the rom across the space
	address_space &space = m_maincpu->space(AS_PROGRAM);
	space.install_rom(0x8000, m_rgnlen, ((~(m_rgnlen-1))<<1)&0xffffff, m_rgn+0x8000);
}

DRIVER_INIT_MEMBER(xavix_state, taitons1)
{
	DRIVER_INIT_CALL(xavix);
	m_alt_addressing = 1;
}

DRIVER_INIT_MEMBER(xavix_state, rad_box)
{
	DRIVER_INIT_CALL(xavix);
	m_alt_addressing = 2;
}

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

  Game driver(s)

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

ROM_START( taitons1 )
	ROM_REGION( 0x200000, "bios", ROMREGION_ERASE00 )
	ROM_LOAD( "taitonostalgia1.u3", 0x000000, 0x200000, CRC(25bd8c67) SHA1(a109cd2da6aa4596e3ca3abd1afce2d0001a473f) )
ROM_END

ROM_START( taitons2 )
	ROM_REGION( 0x200000, "bios", ROMREGION_ERASE00 )
	ROM_LOAD( "taitonostalgia2.bin", 0x000000, 0x200000, CRC(d7dbd93d) SHA1(ad96f80d317e7fd64682a1fe406c5ee9dd5eabf9) )
ROM_END

ROM_START( namcons1 )
	ROM_REGION( 0x100000, "bios", ROMREGION_ERASE00 )
	ROM_LOAD( "namconostalgia1.bin", 0x000000, 0x100000, CRC(9bcccccd) SHA1(cf8fe6de76fbd23974f999299db6f558f79c8f22) )
ROM_END

ROM_START( namcons2 )
	ROM_REGION( 0x100000, "bios", ROMREGION_ERASE00 )
	ROM_LOAD( "nostalgia.bin", 0x000000, 0x100000, CRC(03f7f755) SHA1(bdf1b10ab0104ed580951b0c428c4e93e7373afe) )
ROM_END

ROM_START( rad_box )
	ROM_REGION(0x200000, "bios", ROMREGION_ERASE00)
	ROM_LOAD("boxing.bin", 0x000000, 0x200000, CRC(5cd40714) SHA1(165260228c029a9502ca0598c84c24fd9bdeaebe) )
ROM_END

ROM_START( rad_boxp )
	ROM_REGION(0x200000, "bios", ROMREGION_ERASE00)
	ROM_LOAD("boxing.bin", 0x000000, 0x200000, CRC(5cd40714) SHA1(165260228c029a9502ca0598c84c24fd9bdeaebe) )
ROM_END

ROM_START( rad_bass )
	ROM_REGION(0x100000, "bios", ROMREGION_ERASE00)
	ROM_LOAD("bassfishin.bin", 0x000000, 0x100000, CRC(b54eb1c5) SHA1(084faa9349369f2b8846950765f9c8f758db3e9e) )
ROM_END

ROM_START( rad_bassp )
	ROM_REGION(0x100000, "bios", ROMREGION_ERASE00)
	ROM_LOAD("bassfishin.bin", 0x000000, 0x100000, CRC(b54eb1c5) SHA1(084faa9349369f2b8846950765f9c8f758db3e9e) )
ROM_END

ROM_START( rad_snow )
	ROM_REGION(0x100000, "bios", ROMREGION_ERASE00)
	ROM_LOAD("snoblu.bin", 0x000000, 0x100000, CRC(593e40b3) SHA1(03483ac39eddd7746470fb60018e704382b0da59) )
ROM_END

ROM_START( rad_snowp )
	ROM_REGION(0x100000, "bios", ROMREGION_ERASE00)
	ROM_LOAD("snoblu.bin", 0x000000, 0x100000, CRC(593e40b3) SHA1(03483ac39eddd7746470fb60018e704382b0da59) )
ROM_END


ROM_START( rad_ping )
	ROM_REGION( 0x100000, "bios", ROMREGION_ERASE00 )
	ROM_LOAD( "pingpong.bin", 0x000000, 0x100000, CRC(629f7f47) SHA1(2bb19fd202f1e6c319d2f7d18adbfed8a7669235) )
ROM_END

ROM_START( rad_crdn )
	ROM_REGION( 0x100000, "bios", ROMREGION_ERASE00 )
	ROM_LOAD( "cardnight.bin", 0x000000, 0x100000, CRC(d19eba08) SHA1(cedb9fe785f2a559f518a1d8ecf80d500ddc63c7) )
ROM_END

ROM_START( rad_crdnp )
	ROM_REGION( 0x100000, "bios", ROMREGION_ERASE00 )
	ROM_LOAD( "cardnight.bin", 0x000000, 0x100000, CRC(d19eba08) SHA1(cedb9fe785f2a559f518a1d8ecf80d500ddc63c7) )
ROM_END

ROM_START( rad_bb2 )
	ROM_REGION( 0x200000, "bios", ROMREGION_ERASE00 )
	ROM_LOAD( "baseball2.bin", 0x000000, 0x200000, CRC(bdbf6202) SHA1(18d5cc2d77cbb734629a7a5b6e0f419d21beedbd) )
ROM_END

ROM_START( rad_mtrk )
	ROM_REGION( 0x400000, "bios", ROMREGION_ERASE00 )
	ROM_LOAD( "monstertruck.bin", 0x000000, 0x400000, CRC(dccda0a7) SHA1(7953cf29643672f8367639555b797c20bb533eab) )
ROM_END

ROM_START( rad_mtrkp ) // rom was dumped from NTSC unit, assuming to be the same
	ROM_REGION( 0x400000, "bios", ROMREGION_ERASE00 )
	ROM_LOAD( "monstertruck.bin", 0x000000, 0x400000, CRC(dccda0a7) SHA1(7953cf29643672f8367639555b797c20bb533eab) )
ROM_END


ROM_START( rad_madf )
	ROM_REGION(0x400000, "bios", ROMREGION_ERASE00)
	ROM_LOAD("madden.bin", 0x000000, 0x400000, CRC(e972fdcf) SHA1(52001316254880755da959c3441d232fd2c72c7a) )
ROM_END

ROM_START( rad_fb )
	ROM_REGION(0x400000, "bios", ROMREGION_ERASE00)
	ROM_LOAD("rfootball.bin", 0x000000, 0x400000, CRC(025e0cb4) SHA1(60ce363de236d5119d078e346ad5d2ae50dbc7e1) )
ROM_END

ROM_START( epo_efdx )
	ROM_REGION(0x400000, "bios", ROMREGION_ERASE00)
	ROM_LOAD("excitefishing.bin", 0x000000, 0x400000, CRC(9c85b261) SHA1(6a363faed2ec89c5176e46554a98ca1e20132579) )
ROM_END

ROM_START( rad_rh )
	ROM_REGION(0x200000, "bios", ROMREGION_ERASE00)
	ROM_LOAD("rescueheroes.bin", 0x000000, 0x200000, CRC(38c391a7) SHA1(120334d4ce89d98438c2a35bf7e53af5096cc878) )
ROM_END

/*
	There's more code in here than in the 'eka_strt' set, but all it seems to do is display an 'insert cartridge' message,
	however eka_strt also seems a complete program in it's own right, it's unclear if it can see any of the data from this
	ROM.

	(TODO: turn the cartridges into a software list once the mapping is properly understood)
*/

ROM_START( eka_base )
	ROM_REGION( 0x100000, "bios", ROMREGION_ERASE00 )
	ROM_LOAD( "ekara.bin", 0x000000, 0x100000, CRC(9b27c4a2) SHA1(d75dda7434933135d2f7e353840a9384e9a0d586) )
ROM_END

ROM_START( eka_strt )
	ROM_REGION( 0x080000, "bios", ROMREGION_ERASE00 )
	ROM_LOAD( "ekarastartcart.bin", 0x000000, 0x080000, CRC(8c12c0c2) SHA1(8cc1b098894af25a4bfccada884125b66f5fe8b2) )
ROM_END

ROM_START( has_wamg )
	ROM_REGION( 0x400000, "bios", ROMREGION_ERASE00 )
	ROM_LOAD( "minigolf.bin", 0x000000, 0x400000, CRC(35cee2ad) SHA1(c7344e8ba336bc329638485ea571cd731ebf7649) )
ROM_END

/* Standalone TV Games */

CONS( 2006, taitons1,  0,          0,  xavix,  xavix,    xavix_state, taitons1, "Bandai / SSD Company LTD / Taito", "Let's! TV Play Classic - Taito Nostalgia 1", MACHINE_IS_SKELETON )

CONS( 2006, taitons2,  0,          0,  xavix,  namcons2, xavix_state, xavix,    "Bandai / SSD Company LTD / Taito", "Let's! TV Play Classic - Taito Nostalgia 2", MACHINE_IS_SKELETON )

CONS( 2006, namcons1,  0,          0,  xavix,  namcons2, xavix_state, taitons1, "Bandai / SSD Company LTD / Namco", "Let's! TV Play Classic - Namco Nostalgia 1", MACHINE_IS_SKELETON )

CONS( 2006, namcons2,  0,          0,  xavix,  namcons2, xavix_state, taitons1, "Bandai / SSD Company LTD / Namco", "Let's! TV Play Classic - Namco Nostalgia 2", MACHINE_IS_SKELETON )

CONS( 2000, rad_ping,  0,          0,  xavix,  xavix,    xavix_state, xavix,    "Radica / SSD Company LTD / Simmer Technology", "Play TV Ping Pong", MACHINE_IS_SKELETON ) // "Simmer Technology" is also known as "Hummer Technology Co., Ltd"

CONS( 2003, rad_mtrk,  0,          0,  xavix,  rad_mtrk, xavix_state, xavix,    "Radica / SSD Company LTD",                     "Play TV Monster Truck (NTSC)", MACHINE_IS_SKELETON )
CONS( 2003, rad_mtrkp, rad_mtrk,   0,  xavixp, rad_mtrkp,xavix_state, xavix,    "Radica / SSD Company LTD",                     "ConnecTV Monster Truck (PAL)", MACHINE_IS_SKELETON )

CONS( 200?, rad_box,   0,          0,  xavix,  rad_box,  xavix_state, rad_box,  "Radica / SSD Company LTD",                     "Play TV Boxing (NTSC)", MACHINE_IS_SKELETON)
CONS( 200?, rad_boxp,  rad_box,    0,  xavixp, rad_boxp, xavix_state, rad_box,  "Radica / SSD Company LTD",                     "ConnecTV Boxing (PAL)", MACHINE_IS_SKELETON)
 
CONS( 200?, rad_crdn,  0,          0,  xavix,  rad_crdn, xavix_state, rad_box,  "Radica / SSD Company LTD",                     "Play TV Card Night (NTSC)", MACHINE_IS_SKELETON)
CONS( 200?, rad_crdnp, rad_crdn,   0,  xavixp, rad_crdnp,xavix_state, rad_box,  "Radica / SSD Company LTD",                     "ConnecTV Card Night (PAL)", MACHINE_IS_SKELETON)

CONS( 2002, rad_bb2,   0,          0,  xavix,  xavix,    xavix_state, xavix,    "Radica / SSD Company LTD",                     "Play TV Baseball 2", MACHINE_IS_SKELETON ) // contains string "Radica RBB2 V1.0"

CONS( 2001, rad_bass,  0,          0,  xavix,  xavix,    xavix_state, rad_box,  "Radica / SSD Company LTD",                     "Play TV Bass Fishin' (NTSC)", MACHINE_IS_SKELETON)
CONS( 2001, rad_bassp, rad_bass,   0,  xavixp, xavixp,   xavix_state, rad_box,  "Radica / SSD Company LTD",                     "ConnecTV Bass Fishin' (PAL)", MACHINE_IS_SKELETON)

// there is another 'Snowboarder' with a white coloured board, it appears to be a newer game closer to 'SSX Snowboarder' but without the SSX license.
CONS( 2001, rad_snow,  0,          0,  xavix,  rad_snow, xavix_state, rad_box,  "Radica / SSD Company LTD",                     "Play TV Snowboarder (Blue) (NTSC)", MACHINE_IS_SKELETON)
CONS( 2001, rad_snowp, rad_snow,   0,  xavixp, rad_snowp,xavix_state, rad_box,  "Radica / SSD Company LTD",                     "ConnecTV Snowboarder (Blue) (PAL)", MACHINE_IS_SKELETON)

CONS( 2003, rad_madf,  0,          0,  xavix,  xavix,  xavix_state, taitons1,  "Radica / SSD Company LTD",                     "EA Sports Madden Football (NTSC)", MACHINE_IS_SKELETON) // no Play TV branding, USA only release?

CONS( 200?, rad_fb,    0,          0,  xavix,  xavix,  xavix_state, taitons1,  "Radica / SSD Company LTD",                     "Play TV Football (NTSC)", MACHINE_IS_SKELETON) // USA only release? doesn't change logo for PAL

CONS( 200?, rad_rh,    0,          0,  xavix,  xavix,  xavix_state, taitons1,  "Radioa / Fisher-Price / SSD Company LTD",      "Play TV Rescue Heroes", MACHINE_IS_SKELETON)

CONS( 200?, epo_efdx,  0,          0,  xavix,  xavix,  xavix_state, taitons1,  "Epoch / SSD Company LTD",                      "Excite Fishing DX (Japan)", MACHINE_IS_SKELETON)

CONS( 200?, has_wamg,  0,          0,  xavix,  xavix,  xavix_state, rad_box,   "Hasbro / Milton Bradley / SSD Company LTD",    "TV Wild Adventure Mini Golf", MACHINE_IS_SKELETON)

CONS (200?, eka_base,  0,          0,  xavix,  xavix,  xavix_state, xavix,     "Takara / SSD Company LTD",                     "e-kara", MACHINE_IS_SKELETON)

CONS (200?, eka_strt,  0,          0,   xavix,  xavix,  xavix_state, xavix,    "Takara / SSD Company LTD",                     "e-kara Starter", MACHINE_IS_SKELETON)

/* The 'XaviXPORT' isn't a real console, more of a TV adapter, all the actual hardware (CPU including video hw, sound hw) is in the cartridges and controllers
   and can vary between games, see notes at top of driver.
*/

ROM_START( xavtenni )
	ROM_REGION( 0x800000, "bios", ROMREGION_ERASE00 )
	ROM_LOAD( "xavixtennis.bin", 0x000000, 0x800000, CRC(23a1d918) SHA1(2241c59e8ea8328013e55952ebf9060ea0a4675b) )
ROM_END

/* Tiger games have extended opcodes too */


ROM_START( ttv_sw )
	ROM_REGION( 0x800000, "bios", ROMREGION_ERASE00 )
	ROM_LOAD( "jedi.bin", 0x000000, 0x800000, CRC(51cae5fd) SHA1(1ed8d556f31b4182259ca8c766d60c824d8d9744) )
ROM_END

ROM_START( ttv_lotr )
	ROM_REGION( 0x800000, "bios", ROMREGION_ERASE00 )
	ROM_LOAD( "lotr.bin", 0x000000, 0x800000, CRC(a034ecd5) SHA1(264a9d4327af0a075841ad6129db67d82cf741f1) )
ROM_END

ROM_START( ttv_mx )
	ROM_REGION( 0x800000, "bios", ROMREGION_ERASE00 )
	ROM_LOAD( "mxdirtrebel.bin", 0x000000, 0x800000, CRC(e64bf1a1) SHA1(137f97d7d857697a13e0c8984509994dc7bc5fc5) )
ROM_END


CONS( 2004, xavtenni,  0,   0,  xavix,  xavix, xavix_state, xavix, "SSD Company LTD",         "XaviX Tennis (XaviXPORT)", MACHINE_IS_SKELETON )

CONS( 2005, ttv_sw,    0,   0,  xavix,  xavix, xavix_state, xavix, "Tiger / SSD Company LTD", "Star Wars Saga Edition - Lightsaber Battle Game", MACHINE_IS_SKELETON )
CONS( 2005, ttv_lotr,  0,   0,  xavix,  xavix, xavix_state, xavix, "Tiger / SSD Company LTD", "Lord Of The Rings - Warrior of Middle-Earth", MACHINE_IS_SKELETON )
CONS( 2005, ttv_mx,    0,   0,  xavix,  xavix, xavix_state, xavix, "Tiger / SSD Company LTD", "MX Dirt Rebel", MACHINE_IS_SKELETON )