summaryrefslogtreecommitdiffstatshomepage
path: root/src/mame/drivers/jalmah.cpp
blob: c0b4fd506989d6d67b7dc46debd32936847f0b30 (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
// license:LGPL-2.1+
// copyright-holders:Angelo Salese, Uki
/*******************************************************************************************

MJ-8956 HW games (c) 1989 Jaleco / NMK / UPL

driver by Angelo Salese, based on early work by David Haywood
Special thanks to Uki and Yasu for the priority system explanation.

Similar to the NMK16 / Jaleco Mega System 1 boards but without sprites.

Notes(general):
-I think that the 0xf0000-0xfffff area is shared with the MCU because:
\-The first version of the MCU programs (daireika/mjzoomin) jump in that area.
  Then the MCU upload a 68k code;the programs are likely to be the same for all the games,
  for example if the program jumps to $f0020 it means a sample request.
\-Input ports located there.Program doesn't check these locations at P.O.S.T. and doesn't
  give any work ram error.
\-Additionally all the games have a MCU protection which involves various RAM areas,
  that controls mahjong panel inputs.Protection is simulated by
  adding a value to these RAM areas according to what button is pressed.

TODO:
- kakumei2: unemulated RNG;
- daireika: the ranking screen on the original pcb shows some hearts instead of the "0".
  Some investigation indicates that the game reads area "fe100" onwards for these to be filled.
  These are likely to be provided by one of the mcu snippets...
- kakumei/kakumei2: has weird text layer strings in test mode (like "#p control panel"),
  unsure if this one is somehow related to the above daireika bug, it's a BTANB or something else.
- Check if urashima has a "mode 3" for the layer 0 tilemap (doesn't seem so);
- There could be timing issues caused by MCU simulation at $80004;
- Imperfect sound banking for 1st MCU version (especially noticeable for daireika);
- suchiesp: I need a side-by-side to understand if the PAL shuffling is correct with the OKI BGM ROM.
- urashima: doesn't use the mega system 1 tilemap devices, MCU might actually be responsible
  for that too (cfr. notes).

Notes (1st MCU ver.):
- $f000e is bogus,maybe the program snippets can modify this value,or the MCU itself can
  do that,returning the contents of D0 register seems enough for now...
  Update: Improved it for the new mcu simulation,now it pulls all the values from 0x00 to
  0x0f, it seems to be a MCU call snippet for the $f0000 work ram;
- $f030e is a mirror for $f000e in urashima.
- I need more space for MCU code...that's why I've used an extra jmp when entering
  into mcu code,so we can debug the first version freely without being teased about
  memory space.
  BTW,the real HW is using a sort of bankswitch or I'm missing something?
- $f0020 is for the sound program,same for all games, for example mjzoomin hasn't any clear
  write to $80040 area and the program jumps to $f0020 when there should be a sample.
- Likewise, D0 upper byte is used, not 100% sure about its meaning (banking? voice channel control?).

============================================================================================
Debug cheats:

-(suchiesp)
*
$fe87e: bonus timer,used as a count-down.
*
$f079a: finish match now
*
During gameplay,set $f0400 to 6 then set $f07d4 to 1 to advance to next
level.
*
$f06a6-$f06c0: Your tiles
$f06c6-$f06e0: COM tiles
---- ---- --xx ----: Defines kind
---- ---- ---- xxxx: Defines number
*
$f0434: priority number

============================================================================================
daireika 68k irq table vectors
lev 1 : 0x64 : 0000 049e -
lev 2 : 0x68 : 0000 04ae -
lev 3 : 0x6c : 0000 049e -
lev 4 : 0x70 : 0000 091a -
lev 5 : 0x74 : 0000 0924 -
lev 6 : 0x78 : 0000 092e -
lev 7 : 0x7c : 0000 0938 -

mjzoomin 68k irq table vectors
lev 1 : 0x64 : 0000 048a -
lev 2 : 0x68 : 0000 049a - vblank
lev 3 : 0x6c : 0000 048a -
lev 4 : 0x70 : 0000 09ba - "write to Text RAM" (?)
lev 5 : 0x74 : 0000 09c4 - "write to Text RAM" (?)
lev 6 : 0x78 : 0000 09ce - "write to Text RAM" (?)
lev 7 : 0x7c : 0000 09d8 - "write to Text RAM" (?)

kakumei/kakumei2/suchiesp 68k irq table vectors
lev 1 : 0x64 : 0000 0506 - rte
lev 2 : 0x68 : 0000 050a - vblank
lev 3 : 0x6c : 0000 051c - rte
lev 4 : 0x70 : 0000 0520 - rte
lev 5 : 0x74 : 0000 0524 - rte
lev 6 : 0x78 : 0000 0524 - rte
lev 7 : 0x7c : 0000 0524 - rte

Board:  MJ-8956

CPU:    68000-8
        M50747 (not dumped)
Sound:  M6295
OSC:    12.000MHz
        4.000MHz


2009-04: Verified DipLocations and Default settings with manual (thanks to Uki)

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

#include "emu.h"
#include "cpu/m68000/m68000.h"
#include "machine/timer.h"
#include "sound/okim6295.h"
#include "video/ms1_tmap.h"
#include "emupal.h"
#include "screen.h"
#include "speaker.h"
#include "tilemap.h"


class jalmah_state : public driver_device
{
public:
	jalmah_state(const machine_config &mconfig, device_type type, const char *tag) :
		driver_device(mconfig, type, tag),
		m_maincpu(*this, "maincpu"),
		m_palette(*this, "palette"),
		m_tmap(*this, "scroll%u", 0),
		m_sharedram(*this, "sharedram"),
		m_prirom(*this, "prirom"),
		m_p1_key_io(*this, "P1_KEY%u", 0U),
		m_p2_key_io(*this, "P2_KEY%u", 0U),
		m_okibank(*this, "okibank"),
		m_system_io(*this, "SYSTEM"),
		m_dsw_io(*this, "DSW")
	{ }

	DECLARE_WRITE8_MEMBER(tilebank_w);
	DECLARE_WRITE8_MEMBER(okirom_w);
	DECLARE_WRITE8_MEMBER(okibank_w);
	DECLARE_WRITE8_MEMBER(flip_screen_w);
	DECLARE_READ16_MEMBER(urashima_mcu_r);
	DECLARE_WRITE16_MEMBER(urashima_mcu_w);
	DECLARE_READ16_MEMBER(daireika_mcu_r);
	DECLARE_WRITE16_MEMBER(daireika_mcu_w);
	DECLARE_READ16_MEMBER(mjzoomin_mcu_r);
	DECLARE_WRITE16_MEMBER(mjzoomin_mcu_w);
	DECLARE_READ16_MEMBER(kakumei_mcu_r);
	DECLARE_READ16_MEMBER(suchiesp_mcu_r);
	void init_suchiesp();
	void init_kakumei();
	void init_urashima();
	void init_kakumei2();
	void init_daireika();
	void init_mjzoomin();
	uint32_t screen_update_jalmah(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect);
	TIMER_DEVICE_CALLBACK_MEMBER(mcu_sim);
	void refresh_priority_system();
	void daireika_mcu_run();
	void mjzoomin_mcu_run();
	void urashima_mcu_run();
	void second_mcu_run();
	void jalmah(machine_config &config);
	void jalmahv1(machine_config &config);
	void jalmah_map(address_map &map);
	void jalmahv1_map(address_map &map);
	void oki_map(address_map &map);
protected:
	virtual void machine_start() override;
	virtual void machine_reset() override;
	virtual void video_start() override;

	required_device<cpu_device> m_maincpu;
	required_device<palette_device> m_palette;
	optional_device_array<megasys1_tilemap_device, 4> m_tmap;

	uint16_t m_tile_bank;
	uint16_t m_pri;
	void mcu_check_test_mode();

private:
	required_shared_ptr<uint16_t> m_sharedram;
	optional_region_ptr<uint8_t> m_prirom;
	required_ioport_array<3> m_p1_key_io;
	optional_ioport_array<3> m_p2_key_io;
	required_memory_bank m_okibank;
	required_ioport m_system_io;
	required_ioport m_dsw_io;
	uint8_t m_layer_prin[4];
	void mcu_fetch_input_polling(required_ioport_array<3> &port, uint16_t workram_offset);

	uint8_t m_mcu_prg;
	int m_respcount;
	uint8_t m_test_mode;
	uint16_t m_prg_prot;
	uint8_t m_oki_rom;
	uint8_t m_oki_bank;
	uint8_t m_oki_za;

	// arbitrary numbering scheme for the MCU sims
	enum {
		URASHIMA_MCU = 0x11,
		DAIREIKA_MCU = 0x12,
		MJZOOMIN_MCU = 0x13,
		KAKUMEI_MCU = 0x21,
		KAKUMEI2_MCU = 0x22,
		SUCHIESP_MCU = 0x23
	};

	// base values for the MCU code snippets (arbitrary)
	enum {
		SNIPPET_PALETTE1 = 0x0000,
		SNIPPET_SOUND = 0x0800,
		SNIPPET_TILE = 0x1000,
		SNIPPET_PALETTE2 = 0x1800,
		SNIPPET_RNG = 0x2000,
		SNIPPET_CLR_LAYER0 = 0x2800,
		SNIPPET_CLR_LAYER1 = 0x2880,
		SNIPPET_CLR_LAYER2 = 0x2900
	};
};

class urashima_state : public jalmah_state
{
public:
	urashima_state(const machine_config &mconfig, device_type type, const char *tag)
		: jalmah_state(mconfig, type, tag),
		  m_videoram(*this, "videoram%u", 0U),
		  m_vreg(*this, "vreg%u", 0U),
		  m_gfxdecode(*this, "gfxdecode")
	{}

	template<int TileChip> DECLARE_READ16_MEMBER(urashima_vregs_r);
	template<int TileChip> DECLARE_WRITE16_MEMBER(urashima_vregs_w);

	template<int TileChip> DECLARE_READ16_MEMBER(urashima_vram_r);
	template<int TileChip> DECLARE_WRITE16_MEMBER(urashima_vram_w);

	DECLARE_WRITE16_MEMBER(urashima_vreg_log_w);
	DECLARE_WRITE8_MEMBER(urashima_priority_w);

	template<int TileChip> TILE_GET_INFO_MEMBER(get_tile_info_urashima);

	void urashima(machine_config &config);
	void urashima_map(address_map &map);

	uint32_t screen_update_urashima(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect);
	DECLARE_WRITE8_MEMBER(urashima_bank_w);

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

private:
	required_shared_ptr_array<uint16_t, 2> m_videoram;
	required_shared_ptr_array<uint16_t, 2> m_vreg;
	required_device<gfxdecode_device> m_gfxdecode;

	tilemap_t *m_layer[2];

	TILEMAP_MAPPER_MEMBER(range0_16x16);
	TILEMAP_MAPPER_MEMBER(range3_8x8);
};

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

Video Hardware start

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

void jalmah_state::video_start()
{
	// ...
}

template<int TileChip>
TILE_GET_INFO_MEMBER(urashima_state::get_tile_info_urashima)
{
	int code = m_videoram[TileChip][tile_index];
	uint16_t tile = code & 0xfff;
	int region = (TileChip == 0) ? m_tile_bank : 3;

	SET_TILE_INFO_MEMBER(region,
			tile,
			code >> 12,
			0);
}

TILEMAP_MAPPER_MEMBER(urashima_state::range0_16x16)
{
	/* logical (col,row) -> memory offset */
	return (row & 0x0f) + ((col & 0xff) << 4) + ((row & 0x70) << 8);
}

TILEMAP_MAPPER_MEMBER(urashima_state::range3_8x8)
{
	return (row & 0x1f) + ((col & 0x3f) * 0x20) + ((row & 0x20) * 0x40);
}

void urashima_state::video_start()
{
	jalmah_state::video_start();

	m_layer[0] = &machine().tilemap().create(*m_gfxdecode, tilemap_get_info_delegate(FUNC(urashima_state::get_tile_info_urashima<0>),this),tilemap_mapper_delegate(FUNC(urashima_state::range0_16x16),this),16,16,256,32);
	// range confirmed with title screen transition in attract mode
	// also it's confirmed to be 64 x 64 with 2nd tier girls stripping
	m_layer[1] = &machine().tilemap().create(*m_gfxdecode, tilemap_get_info_delegate(FUNC(urashima_state::get_tile_info_urashima<1>),this),tilemap_mapper_delegate(FUNC(urashima_state::range3_8x8),this),8,8,64,64);

	for(int i=0;i<2;i++)
		m_layer[i]->set_transparent_pen(15);
}


/***************************************************************************************
The priority system is a combination between one prom and the priority number.
The priority number is a pointer to an array of 16 bytes of the prom ( addresses bits 4-7
0x*0-0x*f). These 16 bytes are read and added and every number is directly hooked up
to the equivalent layer (i.e. read 0 == +1 for the layer 0, read 1 == +1 for the layer 1
etc.)
In the end the final results always are one bit assigned to each priority (i.e. most
priority = 8, then 4, 2 and finally 1).
***************************************************************************************/
void jalmah_state::refresh_priority_system()
{
	uint8_t prinum;
	int i;

	// clear old priority buffer
	for(i=0; i<4; i++)
		m_layer_prin[i] = 0;

	// now read from the Priority PROM and hookup layer priority values accordingly
	for(int i=0; i<0x10; i++)
	{
		prinum = m_prirom[i|(m_pri<<4)];

		if(prinum == 0) { m_layer_prin[0]++; }
		if(prinum == 1) { m_layer_prin[1]++; }
		if(prinum == 2) { m_layer_prin[2]++; }
		if(prinum == 3) { m_layer_prin[3]++; }
	}

	//popmessage("%02x %02x %02x %02x",m_sc0_prin,m_sc1_prin,m_sc2_prin,m_sc3_prin);
}


uint32_t jalmah_state::screen_update_jalmah(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect)
{
	uint8_t cur_prin;
	int layer_num;

	bitmap.fill(m_palette->pen(0xff), cliprect); //selectable by a ram address?

	for(cur_prin=1; cur_prin<=0x8; cur_prin<<=1)
	{
		for(layer_num=0; layer_num<4; layer_num++)
		{
			if(cur_prin == m_layer_prin[layer_num])
				m_tmap[layer_num]->draw(screen,bitmap,cliprect,0,0);
		}
	}

	return 0;
}

uint32_t urashima_state::screen_update_urashima(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect)
{
	rectangle clip;
	uint16_t sx[2],sy[2];

	// reset scroll latches
	sx[0] = sx[1] = sy[0] = sy[1] = 0;

	clip.min_x = cliprect.min_x;
	clip.max_x = cliprect.max_x;

	bitmap.fill(m_palette->pen(0x1ff), cliprect); //selectable by a ram address?

	for(int y = cliprect.min_y; y < cliprect.max_y+1; y++)
	{
		clip.min_y = clip.max_y = y;

		// Urashima tilemaps interrogate the video register area to make row and column scrolling
		// for every scanline the format is:
		// ---- ---- ---- ---- [0] unused?
		// ---- ---- ---- ---x [1] latches new scroll values
		// ---- xxxx xxxx xxxx [2] new scroll x value
		// ---- yyyy yyyy yyyy [3] new scroll y value
		// this is notably used by the big puntos winning animations.
		for(int layer_num=0;layer_num<2;layer_num++)
		{
			// latches fetch go in reverse order when flip screen is enabled
			int y_base = flip_screen() ? 0x3fc-(y*4) : y*4;

			// is there a new latch?
			if(m_vreg[layer_num][1+y_base] & 1)
			{
				sx[layer_num] = m_vreg[layer_num][2+y_base];
				sy[layer_num] = m_vreg[layer_num][3+y_base];
			}

			// set scroll values for this layer
			m_layer[layer_num]->set_scrollx(0,sx[layer_num]);
			m_layer[layer_num]->set_scrolly(0,sy[layer_num]);
		}

		if(m_pri & 1)
		{
			m_layer[0]->draw(screen,bitmap,clip,0,0);
			m_layer[1]->draw(screen,bitmap,clip,0,0);
		}
		else
		{
			m_layer[1]->draw(screen,bitmap,clip,0,0);
			m_layer[0]->draw(screen,bitmap,clip,0,0);
		}
	}

	return 0;
}

WRITE8_MEMBER(jalmah_state::tilebank_w)
{
	/*
	 --xx ---- fg bank (used by suchiesp)
	 ---- xxxx Priority number (trusted,see mjzoomin)
	*/
	if (m_tile_bank != ((data & 0x30) >> 4))
	{
		m_tile_bank = (data & 0x30) >> 4;
		m_tmap[0]->set_tilebank(m_tile_bank);
	}
	if (m_pri != (data & 0x0f))
	{
		m_pri = data & 0x0f;
		refresh_priority_system();
	}
}

WRITE8_MEMBER(urashima_state::urashima_bank_w)
{
	if (m_tile_bank != (data & 0x03))
	{
		m_tile_bank = (data & 0x03);
		m_layer[0]->mark_all_dirty();

		if(m_tile_bank == 3)
			popmessage("layer 0 bank == 3, contact MAMEdev");
	}
}

template<int TileChip>
READ16_MEMBER(urashima_state::urashima_vram_r)
{
	return m_videoram[TileChip][offset];
}

template<int TileChip>
WRITE16_MEMBER(urashima_state::urashima_vram_w)
{
	COMBINE_DATA(&m_videoram[TileChip][offset]);
	m_layer[TileChip]->mark_tile_dirty(offset);
}

template<int TileChip>
READ16_MEMBER(urashima_state::urashima_vregs_r)
{
	return m_vreg[TileChip][offset];
}

template<int TileChip>
WRITE16_MEMBER(urashima_state::urashima_vregs_w)
{
	COMBINE_DATA(&m_vreg[TileChip][offset]);
}

// Urashima Mahjong uses a bigger video register area (mostly mirrored?)
// we use this fallback so that it doesn't pollute logerror and get the info we want
WRITE16_MEMBER(urashima_state::urashima_vreg_log_w)
{
	if(data)
		logerror("Warning vreg write to [%04x] -> %04x\n",offset*2,data);
}

WRITE8_MEMBER(urashima_state::urashima_priority_w)
{
	m_pri = data & 1;
}

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

Protection file start

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

#define MCU_READ(_ioport_, _bit_, _offset_, _retval_) \
	if((0xffff - port[_ioport_]->read()) & _bit_) \
		{ m_sharedram[_offset_] = _retval_; } \


/* RAM-based protection handlings (input) */
// TODO: unemulated polling mode for player 2 ingame, is it even used?
// TODO: urashima (at least) reads upper byte of the workram buffer, perhaps for checking previous frame input
// TODO: RBSDTL in 1st version MCU stands for Bet/Big/Small/Double Up/Take Score/Last Chance
//      (not hooked up cause none of the dumped games actually uses it)
void jalmah_state::mcu_fetch_input_polling(required_ioport_array<3> &port, uint16_t workram_offset)
{
	MCU_READ(1, 0x0001, workram_offset, 0x00);        // FF (correct?)
	MCU_READ(2, 0x0400, workram_offset, 0x01);        // A
	MCU_READ(2, 0x1000, workram_offset, 0x02);        // B
	MCU_READ(2, 0x0200, workram_offset, 0x03);        // C
	MCU_READ(2, 0x0800, workram_offset, 0x04);        // D
	MCU_READ(2, 0x0004, workram_offset, 0x05);        // E
	MCU_READ(2, 0x0010, workram_offset, 0x06);        // F
	MCU_READ(2, 0x0002, workram_offset, 0x07);        // G
	MCU_READ(2, 0x0008, workram_offset, 0x08);        // H
	MCU_READ(1, 0x0400, workram_offset, 0x09);        // I
	MCU_READ(1, 0x1000, workram_offset, 0x0a);        // J
	MCU_READ(1, 0x0200, workram_offset, 0x0b);        // K
	MCU_READ(1, 0x0800, workram_offset, 0x0c);        // L
	MCU_READ(1, 0x0004, workram_offset, 0x0d);        // M
	MCU_READ(1, 0x0010, workram_offset, 0x0e);        // N
	MCU_READ(0, 0x0200, workram_offset, 0x0f);        // RON
	MCU_READ(0, 0x1000, workram_offset, 0x10);        // REACH
	MCU_READ(0, 0x0400, workram_offset, 0x11);        // KAN
	MCU_READ(1, 0x0008, workram_offset, 0x12);        // PON
	MCU_READ(1, 0x0002, workram_offset, 0x13);        // CHI
	MCU_READ(0, 0x0004, workram_offset, 0x14);        // START1

}

void jalmah_state::daireika_mcu_run()
{
	if(m_test_mode)  //service_mode
	{
		for(int keynum = 0; keynum < 3; keynum++)
		{
			m_sharedram[keynum+0] = m_p1_key_io[keynum]->read();
			m_sharedram[keynum+3] = m_p2_key_io[keynum]->read();
		}
	}
	else
	{
		m_sharedram[0x000/2] = 0x0000;
		mcu_fetch_input_polling(m_p1_key_io, 0x000/2);
	}
	m_prg_prot++;
	if(m_prg_prot > 0x10) { m_prg_prot = 0; }
	m_sharedram[0x00e/2] = m_prg_prot;
}

void jalmah_state::mjzoomin_mcu_run()
{
	if(m_test_mode)  //service_mode
	{
		for(int keynum = 0; keynum < 3; keynum++)
		{
			m_sharedram[keynum+0] = m_p1_key_io[keynum]->read();
			m_sharedram[keynum+3] = m_p2_key_io[keynum]->read();
		}
	}
	else
	{
		m_sharedram[0x000/2] = 0x0000;
		mcu_fetch_input_polling(m_p1_key_io, 0x000/2);
	}

	m_sharedram[0x00c/2] = machine().rand() & 0xffff;
	m_prg_prot++;
	if(m_prg_prot > 0x10) { m_prg_prot = 0; }
	m_sharedram[0x00e/2] = m_prg_prot;
}

void jalmah_state::urashima_mcu_run()
{
	if(m_test_mode)  //service_mode
	{
		for(int keynum = 0; keynum < 3; keynum++)
		{
			m_sharedram[0x300/2+keynum+0] = m_p1_key_io[keynum]->read();
			m_sharedram[0x300/2+keynum+3] = m_p2_key_io[keynum]->read();
		}
	}
	else
	{
		m_sharedram[0x300/2] = 0x0000;
		mcu_fetch_input_polling(m_p1_key_io, 0x300/2);
	}
	m_sharedram[0x30c/2] = machine().rand() & 0xffff;
	m_prg_prot++;
	if(m_prg_prot > 0x10) { m_prg_prot = 0; }
	m_sharedram[0x30e/2] = m_prg_prot;
}

void jalmah_state::second_mcu_run()
{
	if(m_test_mode)  //service_mode
	{
		for(int keynum = 0; keynum < 3; keynum++)
			m_sharedram[0x200/2+keynum] = m_p1_key_io[keynum]->read();
	}
	else
	{
		m_sharedram[0x200/2] = 0x0000;
		mcu_fetch_input_polling(m_p1_key_io, 0x200/2);
	}

	m_sharedram[0x20c/2] = machine().rand() & 0xffff; //kakumei2
}

TIMER_DEVICE_CALLBACK_MEMBER(jalmah_state::mcu_sim)
{
	switch(m_mcu_prg)
	{
			case MJZOOMIN_MCU: mjzoomin_mcu_run(); break;
			case DAIREIKA_MCU: daireika_mcu_run(); break;
			case URASHIMA_MCU: urashima_mcu_run(); break;
			case KAKUMEI_MCU:
			case KAKUMEI2_MCU:
			case SUCHIESP_MCU:  second_mcu_run(); break;
	}
}

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

Basic driver start

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


WRITE8_MEMBER(jalmah_state::okirom_w)
{
	m_oki_rom = data & 1;

	/* ZA appears to be related to the banking, or maybe kakumei2 uses PAL shuffling and this is for something else? */
	m_oki_za = (data & 2) ? 1 : 0;

	//memcpy(&oki[0x20000], &oki[(m_oki_rom * 0x80000) + ((m_oki_bank+m_oki_za) * 0x20000) + 0x40000], 0x20000);
	m_okibank->set_entry((m_oki_rom << 2) + (m_oki_bank+m_oki_za));

	//popmessage("PC=%06x %02x %02x %02x %08x",m_maincpu->pc(),m_oki_rom,m_oki_za,m_oki_bank,(m_oki_rom * 0x80000) + ((m_oki_bank+m_oki_za) * 0x20000) + 0x40000);
}

WRITE8_MEMBER(jalmah_state::okibank_w)
{
	m_oki_bank = data & 3;

	//memcpy(&oki[0x20000], &oki[(m_oki_rom * 0x80000) + ((m_oki_bank+m_oki_za) * 0x20000) + 0x40000], 0x20000);
	m_okibank->set_entry((m_oki_rom << 2) + (m_oki_bank+m_oki_za));

	//popmessage("PC=%06x %02x %02x %02x %08x",m_maincpu->pc(),m_oki_rom,m_oki_za,m_oki_bank,(m_oki_rom * 0x80000) + ((m_oki_bank+m_oki_za) * 0x20000) + 0x40000);
}

WRITE8_MEMBER(jalmah_state::flip_screen_w)
{
	/*---- ----x flip screen*/
	flip_screen_set(data & 1);

	if(data & 0xfe)
		popmessage("Flip data %02x, contact MAMEdev",data);
}

void jalmah_state::jalmah_map(address_map &map)
{
	map(0x000000, 0x07ffff).rom();
	map(0x080000, 0x080001).portr("SYSTEM");
	map(0x080002, 0x080003).portr("DSW");
//      0x080004, 0x080005  MCU read, different for each game
	map(0x080011, 0x080011).w(FUNC(jalmah_state::flip_screen_w));
//      0x080012, 0x080013  MCU write related,same for each game
	map(0x080014, 0x080015).noprw(); // MCU handshake
	map(0x080017, 0x080017).w(FUNC(jalmah_state::tilebank_w));
	map(0x080019, 0x080019).w(FUNC(jalmah_state::okibank_w));
	map(0x08001b, 0x08001b).w(FUNC(jalmah_state::okirom_w));
	map(0x080020, 0x080025).rw("scroll0", FUNC(megasys1_tilemap_device::scroll_r), FUNC(megasys1_tilemap_device::scroll_w));
	map(0x080028, 0x08002d).rw("scroll1", FUNC(megasys1_tilemap_device::scroll_r), FUNC(megasys1_tilemap_device::scroll_w));
	map(0x080030, 0x080035).rw("scroll2", FUNC(megasys1_tilemap_device::scroll_r), FUNC(megasys1_tilemap_device::scroll_w));
	map(0x080038, 0x08003d).rw("scroll3", FUNC(megasys1_tilemap_device::scroll_r), FUNC(megasys1_tilemap_device::scroll_w));
	map(0x080041, 0x080041).rw("oki", FUNC(okim6295_device::read), FUNC(okim6295_device::write));
//      0x084000, 0x084001  ?
	map(0x088000, 0x0887ff).ram().w(m_palette, FUNC(palette_device::write16)).share("palette"); /* Palette RAM */
	map(0x090000, 0x093fff).ram().w("scroll0", FUNC(megasys1_tilemap_device::write)).share("scroll0"); // Scroll RAM 0
	map(0x094000, 0x097fff).ram().w("scroll1", FUNC(megasys1_tilemap_device::write)).share("scroll1"); // Scroll RAM 1
	map(0x098000, 0x09bfff).ram().w("scroll2", FUNC(megasys1_tilemap_device::write)).share("scroll2"); // Scroll RAM 2
	map(0x09c000, 0x09ffff).ram().w("scroll3", FUNC(megasys1_tilemap_device::write)).share("scroll3"); // Scroll RAM 3
	map(0x0f0000, 0x0f0fff).ram().share("sharedram");/*shared with MCU*/
	map(0x0f1000, 0x0fffff).ram(); /*Work Ram*/
}

void jalmah_state::jalmahv1_map(address_map &map)
{
	jalmah_map(map);
	map(0x100000, 0x10ffff).ram().region("jmcu_rom", 0); // extended ROM functions (not on real HW)
}

void urashima_state::urashima_map(address_map &map)
{
	map(0x000000, 0x07ffff).rom();
	map(0x080000, 0x080001).portr("SYSTEM");
	map(0x080002, 0x080003).portr("DSW");
//      0x080004, 0x080005  MCU read, different for each game
	map(0x080011, 0x080011).w(FUNC(jalmah_state::flip_screen_w));
//      0x080012, 0x080013  MCU write related, same for each game
	map(0x080014, 0x080015).noprw(); // MCU handshake
/**/map(0x080017, 0x080017).w(FUNC(urashima_state::urashima_priority_w));
	map(0x080019, 0x080019).w(FUNC(jalmah_state::okibank_w));
	map(0x08001b, 0x08001b).w(FUNC(jalmah_state::okirom_w));
/**/map(0x08001c, 0x08001d).ram().w(FUNC(urashima_state::urashima_bank_w)).umask16(0x00ff);
	map(0x080041, 0x080041).rw("oki", FUNC(okim6295_device::read), FUNC(okim6295_device::write));
//      0x084000, 0x084001  ?
	map(0x088000, 0x0887ff).mirror(0x800).ram().w(m_palette, FUNC(palette_device::write16)).share("palette"); /* Palette RAM */
	map(0x090000, 0x093fff).mirror(0x4000).rw(FUNC(urashima_state::urashima_vram_r<0>),FUNC(urashima_state::urashima_vram_w<0>)).share("videoram0");
	map(0x098000, 0x09bfff).noprw(); // unused mirror? set when coin up then never set anymore
	map(0x09c000, 0x09c7ff).rw(FUNC(urashima_state::urashima_vregs_r<0>), FUNC(urashima_state::urashima_vregs_w<0>)).share("vreg0");
	map(0x09c800, 0x09cfff).rw(FUNC(urashima_state::urashima_vregs_r<1>), FUNC(urashima_state::urashima_vregs_w<1>)).share("vreg1");
	map(0x09d000, 0x09dfff).nopr().w(FUNC(urashima_state::urashima_vreg_log_w)); // cleared at POST then unused

	// likely only 0x9e000-0x9ffff is connected (0xa0000-0xa1fff cleared at POST and nowhere else)
	map(0x09e000, 0x09ffff).rw(FUNC(urashima_state::urashima_vram_r<1>),FUNC(urashima_state::urashima_vram_w<1>)).share("videoram1");
	map(0x0a0000, 0x0a1fff).noprw();
	map(0x0f0000, 0x0f0fff).ram().share("sharedram");/*shared with MCU*/
	map(0x0f1000, 0x0fffff).ram(); /*Work Ram*/
	map(0x100000, 0x10ffff).ram().region("jmcu_rom", 0);/*extra RAM for MCU code prg (NOT ON REAL HW!!!)*/
}

void jalmah_state::oki_map(address_map &map)
{
	map(0x00000, 0x1ffff).rom();
	map(0x20000, 0x3ffff).bankr("okibank");
}

static INPUT_PORTS_START( common )
	PORT_START("SYSTEM")
	PORT_BIT( 0x001f, IP_ACTIVE_LOW, IPT_UNKNOWN )
	PORT_BIT( 0x0020, IP_ACTIVE_LOW, IPT_SERVICE1 )
	PORT_BIT( 0x0040, IP_ACTIVE_LOW, IPT_COIN1 )
	PORT_BIT( 0x0080, IP_ACTIVE_LOW, IPT_COIN2 )
	PORT_BIT( 0xff00, IP_ACTIVE_LOW, IPT_UNKNOWN )
INPUT_PORTS_END

static INPUT_PORTS_START( ctrl_mj1 )
	PORT_START("P1_KEY0")
	PORT_BIT( 0x0001, IP_ACTIVE_LOW, IPT_UNKNOWN ) // (S) Small
	PORT_BIT( 0x0004, IP_ACTIVE_LOW, IPT_START1 )
	PORT_BIT( 0x0010, IP_ACTIVE_LOW, IPT_UNKNOWN ) // (R) Bet?
	PORT_BIT( 0x0100, IP_ACTIVE_LOW, IPT_UNKNOWN ) // (B) Big?
	PORT_BIT( 0x0200, IP_ACTIVE_LOW, IPT_MAHJONG_RON )
	PORT_BIT( 0x0400, IP_ACTIVE_LOW, IPT_MAHJONG_KAN )
	PORT_BIT( 0x1000, IP_ACTIVE_LOW, IPT_MAHJONG_REACH )
	PORT_BIT( 0xe8ea, IP_ACTIVE_LOW, IPT_UNUSED )

	PORT_START("P1_KEY1")
	PORT_BIT( 0x0001, IP_ACTIVE_LOW, IPT_MAHJONG_FLIP_FLOP )
	PORT_BIT( 0x0002, IP_ACTIVE_LOW, IPT_MAHJONG_CHI )
	PORT_BIT( 0x0004, IP_ACTIVE_LOW, IPT_MAHJONG_M )
	PORT_BIT( 0x0008, IP_ACTIVE_LOW, IPT_MAHJONG_PON )
	PORT_BIT( 0x0010, IP_ACTIVE_LOW, IPT_MAHJONG_N )
	PORT_BIT( 0x0100, IP_ACTIVE_LOW, IPT_UNKNOWN ) // (D) Double Up
	PORT_BIT( 0x0200, IP_ACTIVE_LOW, IPT_MAHJONG_K )
	PORT_BIT( 0x0400, IP_ACTIVE_LOW, IPT_MAHJONG_I )
	PORT_BIT( 0x0800, IP_ACTIVE_LOW, IPT_MAHJONG_L )
	PORT_BIT( 0x1000, IP_ACTIVE_LOW, IPT_MAHJONG_J )
	PORT_BIT( 0xe0e0, IP_ACTIVE_LOW, IPT_UNUSED )

	PORT_START("P1_KEY2")
	PORT_BIT( 0x0001, IP_ACTIVE_LOW, IPT_UNKNOWN ) // (T) Take Score
	PORT_BIT( 0x0002, IP_ACTIVE_LOW, IPT_MAHJONG_G )
	PORT_BIT( 0x0004, IP_ACTIVE_LOW, IPT_MAHJONG_E )
	PORT_BIT( 0x0008, IP_ACTIVE_LOW, IPT_MAHJONG_H )
	PORT_BIT( 0x0010, IP_ACTIVE_LOW, IPT_MAHJONG_F )
	PORT_BIT( 0x0100, IP_ACTIVE_LOW, IPT_UNKNOWN ) // (L) Last Chance
	PORT_BIT( 0x0200, IP_ACTIVE_LOW, IPT_MAHJONG_C )
	PORT_BIT( 0x0400, IP_ACTIVE_LOW, IPT_MAHJONG_A )
	PORT_BIT( 0x0800, IP_ACTIVE_LOW, IPT_MAHJONG_D )
	PORT_BIT( 0x1000, IP_ACTIVE_LOW, IPT_MAHJONG_B )
	PORT_BIT( 0xe0e0, IP_ACTIVE_LOW, IPT_UNUSED )
INPUT_PORTS_END

static INPUT_PORTS_START( ctrl_mj2 )
	PORT_START("P2_KEY0")
	PORT_BIT( 0x0004, IP_ACTIVE_LOW, IPT_START2 )
	PORT_BIT( 0x0200, IP_ACTIVE_LOW, IPT_MAHJONG_RON ) PORT_PLAYER(2)
	PORT_BIT( 0x0400, IP_ACTIVE_LOW, IPT_MAHJONG_KAN ) PORT_PLAYER(2)
	PORT_BIT( 0x1000, IP_ACTIVE_LOW, IPT_MAHJONG_REACH ) PORT_PLAYER(2)
	PORT_BIT( 0xe9fb, IP_ACTIVE_LOW, IPT_UNUSED ) PORT_PLAYER(2)

	PORT_START("P2_KEY1")
	PORT_BIT( 0x0001, IP_ACTIVE_LOW, IPT_MAHJONG_FLIP_FLOP ) PORT_PLAYER(2)
	PORT_BIT( 0x0002, IP_ACTIVE_LOW, IPT_MAHJONG_CHI ) PORT_PLAYER(2)
	PORT_BIT( 0x0004, IP_ACTIVE_LOW, IPT_MAHJONG_M ) PORT_PLAYER(2)
	PORT_BIT( 0x0008, IP_ACTIVE_LOW, IPT_MAHJONG_PON ) PORT_PLAYER(2)
	PORT_BIT( 0x0010, IP_ACTIVE_LOW, IPT_MAHJONG_N ) PORT_PLAYER(2)
	PORT_BIT( 0x0200, IP_ACTIVE_LOW, IPT_MAHJONG_K ) PORT_PLAYER(2)
	PORT_BIT( 0x0400, IP_ACTIVE_LOW, IPT_MAHJONG_I ) PORT_PLAYER(2)
	PORT_BIT( 0x0800, IP_ACTIVE_LOW, IPT_MAHJONG_L ) PORT_PLAYER(2)
	PORT_BIT( 0x1000, IP_ACTIVE_LOW, IPT_MAHJONG_J ) PORT_PLAYER(2)
	PORT_BIT( 0xe1e0, IP_ACTIVE_LOW, IPT_UNUSED )

	PORT_START("P2_KEY2")
	PORT_BIT( 0x0002, IP_ACTIVE_LOW, IPT_MAHJONG_G ) PORT_PLAYER(2)
	PORT_BIT( 0x0004, IP_ACTIVE_LOW, IPT_MAHJONG_E ) PORT_PLAYER(2)
	PORT_BIT( 0x0008, IP_ACTIVE_LOW, IPT_MAHJONG_H ) PORT_PLAYER(2)
	PORT_BIT( 0x0010, IP_ACTIVE_LOW, IPT_MAHJONG_F ) PORT_PLAYER(2)
	PORT_BIT( 0x0200, IP_ACTIVE_LOW, IPT_MAHJONG_C ) PORT_PLAYER(2)
	PORT_BIT( 0x0400, IP_ACTIVE_LOW, IPT_MAHJONG_A ) PORT_PLAYER(2)
	PORT_BIT( 0x0800, IP_ACTIVE_LOW, IPT_MAHJONG_D ) PORT_PLAYER(2)
	PORT_BIT( 0x1000, IP_ACTIVE_LOW, IPT_MAHJONG_B ) PORT_PLAYER(2)
	PORT_BIT( 0xe1e1, IP_ACTIVE_LOW, IPT_UNUSED )
INPUT_PORTS_END

static INPUT_PORTS_START( urashima )
	PORT_INCLUDE( common )
	PORT_INCLUDE( ctrl_mj1 )
	PORT_INCLUDE( ctrl_mj2 )

	PORT_MODIFY("SYSTEM")
	// TODO: this probably sends game in test mode while playing (unemulated)
	PORT_SERVICE( 0x0008, IP_ACTIVE_LOW ) PORT_NAME("Test Button") PORT_CODE(KEYCODE_F1)

	PORT_START("DSW")
	PORT_DIPNAME( 0x0007, 0x0007, DEF_STR( Coinage ) ) PORT_DIPLOCATION("SW2:8,7,6")
	PORT_DIPSETTING(      0x0001, DEF_STR( 4C_1C ) )
	PORT_DIPSETTING(      0x0002, DEF_STR( 3C_1C ) )
	PORT_DIPSETTING(      0x0003, DEF_STR( 2C_1C ) )
	PORT_DIPSETTING(      0x0007, DEF_STR( 1C_1C ) )
	PORT_DIPSETTING(      0x0006, DEF_STR( 1C_2C ) )
	PORT_DIPSETTING(      0x0005, DEF_STR( 1C_3C ) )
	PORT_DIPSETTING(      0x0004, DEF_STR( 1C_4C ) )
	PORT_DIPSETTING(      0x0000, DEF_STR( Free_Play ) )
	PORT_DIPNAME( 0x0018, 0x0018, DEF_STR( Difficulty ) ) PORT_DIPLOCATION("SW2:5,4")
	PORT_DIPSETTING(      0x0010, DEF_STR( Easy ) )
	PORT_DIPSETTING(      0x0018, DEF_STR( Normal ) )
	PORT_DIPSETTING(      0x0008, DEF_STR( Hard ) )
	PORT_DIPSETTING(      0x0000, DEF_STR( Hardest ) )
	PORT_DIPNAME( 0x0020, 0x0020, "Display Tenpai/Noten" ) PORT_DIPLOCATION("SW2:3")
	PORT_DIPSETTING(      0x0020, DEF_STR( No ) )
	PORT_DIPSETTING(      0x0000, DEF_STR( Yes ) )
	PORT_DIPNAME( 0x0040, 0x0040, "Pinfu with Tsumo" ) PORT_DIPLOCATION("SW2:2")
	PORT_DIPSETTING(      0x0000, DEF_STR( No ) )
	PORT_DIPSETTING(      0x0040, DEF_STR( Yes ) )
	PORT_DIPNAME( 0x0080, 0x0080, DEF_STR( Flip_Screen ) ) PORT_DIPLOCATION("SW2:1")
	PORT_DIPSETTING(      0x0080, DEF_STR( Off ) )
	PORT_DIPSETTING(      0x0000, DEF_STR( On ) )
	PORT_DIPNAME( 0x0300, 0x0300, "Number of Chips (Start - Continue)" ) PORT_DIPLOCATION("SW1:8,7")
	PORT_DIPSETTING(      0x0300, "1 - 1" )
	PORT_DIPSETTING(      0x0200, "1 - 2" )
	PORT_DIPSETTING(      0x0100, "2 - 1" )
	PORT_DIPSETTING(      0x0000, "2 - 2" )
	PORT_DIPNAME( 0x0c00, 0x0c00, "Number of Players" ) PORT_DIPLOCATION("SW1:6,5")
	PORT_DIPSETTING(      0x0800, "0" )
	PORT_DIPSETTING(      0x0c00, "1" )
	PORT_DIPSETTING(      0x0400, "2" )
	PORT_DIPSETTING(      0x0000, "4" )
	PORT_DIPNAME( 0x1000, 0x1000, "Chip Added After Win" ) PORT_DIPLOCATION("SW1:4")
	PORT_DIPSETTING(      0x1000, "Less" )
	PORT_DIPSETTING(      0x0000, "More" )
	PORT_DIPUNKNOWN_DIPLOC( 0x2000, 0x2000, "SW1:3" )   // Unused according to the manual
	PORT_DIPUNKNOWN_DIPLOC( 0x4000, 0x4000, "SW1:2" )   // Unused according to the manual
	PORT_DIPNAME( 0x8000, 0x8000, DEF_STR( Service_Mode ) ) PORT_DIPLOCATION("SW1:1")
	PORT_DIPSETTING(      0x8000, DEF_STR( Off ) )
	PORT_DIPSETTING(      0x0000, DEF_STR( On ) )
INPUT_PORTS_END

static INPUT_PORTS_START( daireika )
	PORT_INCLUDE( common )
	PORT_INCLUDE( ctrl_mj1 )
	PORT_INCLUDE( ctrl_mj2 )

	PORT_MODIFY("SYSTEM")
	PORT_SERVICE( 0x0008, IP_ACTIVE_LOW )

	PORT_START("DSW")
	PORT_DIPNAME( 0x0007, 0x0007, DEF_STR( Coinage ) ) PORT_DIPLOCATION("SW2:1,2,3")
	PORT_DIPSETTING(      0x0001, DEF_STR( 4C_1C ) )
	PORT_DIPSETTING(      0x0002, DEF_STR( 3C_1C ) )
	PORT_DIPSETTING(      0x0003, DEF_STR( 2C_1C ) )
	PORT_DIPSETTING(      0x0007, DEF_STR( 1C_1C ) )
	PORT_DIPSETTING(      0x0006, DEF_STR( 1C_2C ) )
	PORT_DIPSETTING(      0x0005, DEF_STR( 1C_3C ) )
	PORT_DIPSETTING(      0x0004, DEF_STR( 1C_4C ) )
	PORT_DIPSETTING(      0x0000, DEF_STR( Free_Play ) )
	PORT_DIPNAME( 0x0018, 0x0018, DEF_STR( Difficulty ) ) PORT_DIPLOCATION("SW2:4,5")
	PORT_DIPSETTING(      0x0018, DEF_STR( Normal ) )
	PORT_DIPSETTING(      0x0010, DEF_STR( Hard ) )
	PORT_DIPSETTING(      0x0008, DEF_STR( Harder ) )
	PORT_DIPSETTING(      0x0000, DEF_STR( Hardest ) )
	PORT_DIPUNKNOWN_DIPLOC( 0x0020, 0x0020, "SW2:6" )   // Unused according to the manual
	PORT_DIPNAME( 0x0040, 0x0040, "Pinfu with Tsumo" ) PORT_DIPLOCATION("SW2:7")
	PORT_DIPSETTING(      0x0000, DEF_STR( No ) )
	PORT_DIPSETTING(      0x0040, DEF_STR( Yes ) )
	PORT_DIPUNKNOWN_DIPLOC( 0x0080, 0x0080, "SW2:8" )   // Unused according to the manual
	PORT_DIPNAME( 0x0300, 0x0300, "Number of Chips (Start - Continue)" ) PORT_DIPLOCATION("SW1:1,2")
	PORT_DIPSETTING(      0x0300, "1 - 1" )
	PORT_DIPSETTING(      0x0200, "1 - 2" )
	PORT_DIPSETTING(      0x0100, "2 - 1" )
	PORT_DIPSETTING(      0x0000, "2 - 2" )
	PORT_DIPUNKNOWN_DIPLOC( 0x0400, 0x0400, "SW1:3" )   // Unused according to the manual
	PORT_DIPUNKNOWN_DIPLOC( 0x0800, 0x0800, "SW1:4" )   // Unused according to the manual
	PORT_DIPUNKNOWN_DIPLOC( 0x1000, 0x1000, "SW1:5" )   // Unused according to the manual
	PORT_DIPUNKNOWN_DIPLOC( 0x2000, 0x2000, "SW1:6" )   // Unused according to the manual
	PORT_DIPUNKNOWN_DIPLOC( 0x4000, 0x4000, "SW1:7" )   // Unused according to the manual
	/* SW1:8 should be "Switch Control Panel" off: no - on : yes -> likely to be controlled by the MCU. */
	PORT_DIPNAME( 0x8000, 0x8000, DEF_STR( Unknown ) ) PORT_DIPLOCATION("SW1:8")
	PORT_DIPSETTING(      0x8000, DEF_STR( Off ) )
	PORT_DIPSETTING(      0x0000, DEF_STR( On ) )
INPUT_PORTS_END

static INPUT_PORTS_START( mjzoomin )
	PORT_INCLUDE( daireika )

	PORT_MODIFY("DSW")
	PORT_DIPNAME( 0x0038, 0x0038, DEF_STR( Difficulty ) ) PORT_DIPLOCATION("SW2:4,5,6")
	PORT_DIPSETTING(      0x0010, "0 (Easy)" )
	PORT_DIPSETTING(      0x0008, "1 (Easier)" )
	PORT_DIPSETTING(      0x0000, "2 (Easiest)" )
	PORT_DIPSETTING(      0x0038, "3 (Normal)" )
	PORT_DIPSETTING(      0x0030, "4 (Little Hard)" )
	PORT_DIPSETTING(      0x0028, "5 (Hard)" )
	PORT_DIPSETTING(      0x0020, "6 (Harder)" )
	PORT_DIPSETTING(      0x0018, "7 (Hardest)" )
	PORT_DIPNAME( 0x0080, 0x0080, DEF_STR( Flip_Screen ) ) PORT_DIPLOCATION("SW2:8")
	PORT_DIPSETTING(      0x0080, DEF_STR( Off ) )
	PORT_DIPSETTING(      0x0000, DEF_STR( On ) )
	PORT_DIPNAME( 0x0300, 0x0300, "Start Score Type" ) PORT_DIPLOCATION("SW1:1,2")
	PORT_DIPSETTING(      0x0300, "1" )
	PORT_DIPSETTING(      0x0200, "2" )
	PORT_DIPSETTING(      0x0100, "3" )
	PORT_DIPSETTING(      0x0000, "4" )
	PORT_DIPUNKNOWN_DIPLOC( 0x0400, 0x0400, "SW1:3" )   // Unused according to the manual
	PORT_DIPUNKNOWN_DIPLOC( 0x0800, 0x0800, "SW1:4" )   // Unused according to the manual
	PORT_DIPUNKNOWN_DIPLOC( 0x1000, 0x1000, "SW1:5" )   // Unused according to the manual
	PORT_DIPNAME( 0x2000, 0x2000, "Item Availability" ) PORT_DIPLOCATION("SW1:6")
	PORT_DIPSETTING(      0x2000, DEF_STR( Normal ) )
	PORT_DIPSETTING(      0x0000, DEF_STR( High ) )
	PORT_DIPUNKNOWN_DIPLOC( 0x4000, 0x4000, "SW1:7" )   // Unused according to the manual
	PORT_DIPUNKNOWN_DIPLOC( 0x8000, 0x8000, "SW1:8" )   // Unused according to the manual
INPUT_PORTS_END

static INPUT_PORTS_START( kakumei )
	PORT_INCLUDE( common )
	PORT_INCLUDE( ctrl_mj1 )

	PORT_MODIFY("P1_KEY1")
	PORT_BIT( 0x0001, IP_ACTIVE_LOW, IPT_MAHJONG_FLIP_FLOP ) PORT_NAME("P1 Mahjong Flip Flop")  PORT_CODE(KEYCODE_2)

	PORT_START("DSW")
	PORT_DIPNAME( 0x0001, 0x0001, DEF_STR( Flip_Screen ) ) PORT_DIPLOCATION("SW2:1")
	PORT_DIPSETTING(      0x0001, DEF_STR( Off ) )
	PORT_DIPSETTING(      0x0000, DEF_STR( On ) )
	PORT_DIPUNUSED_DIPLOC( 0x0002, 0x0002, "SW2:2" )   // Unused according to the manual
	PORT_SERVICE_DIPLOC( 0x0004, IP_ACTIVE_LOW, "SW2:3" )
	PORT_DIPUNUSED_DIPLOC( 0x0008, 0x0008, "SW2:4" )   // Unused according to the manual
	PORT_DIPUNUSED_DIPLOC( 0x0010, 0x0010, "SW2:5" )   // Unused according to the manual
	PORT_DIPUNUSED_DIPLOC( 0x0020, 0x0020, "SW2:6" )   // Unused according to the manual
	PORT_DIPUNUSED_DIPLOC( 0x0040, 0x0040, "SW2:7" )   // Unused according to the manual
	PORT_DIPUNUSED_DIPLOC( 0x0080, 0x0080, "SW2:8" )   // Unused according to the manual
	PORT_DIPNAME( 0x0700, 0x0700, DEF_STR( Coinage ) ) PORT_DIPLOCATION("SW1:1,2,3")
	PORT_DIPSETTING(      0x0100, DEF_STR( 4C_1C ) )
	PORT_DIPSETTING(      0x0200, DEF_STR( 3C_1C ) )
	PORT_DIPSETTING(      0x0300, DEF_STR( 2C_1C ) )
	PORT_DIPSETTING(      0x0700, DEF_STR( 1C_1C ) )
	PORT_DIPSETTING(      0x0600, DEF_STR( 1C_2C ) )
	PORT_DIPSETTING(      0x0500, DEF_STR( 1C_3C ) )
	PORT_DIPSETTING(      0x0400, DEF_STR( 1C_4C ) )
	PORT_DIPSETTING(      0x0000, "1 Coin / 99 Credits" )   // Free Play according to the manual
	PORT_DIPNAME( 0x1800, 0x1800, DEF_STR( Difficulty ) ) PORT_DIPLOCATION("SW1:4,5")
	PORT_DIPSETTING(      0x1800, DEF_STR( Easy ) )
	PORT_DIPSETTING(      0x1000, DEF_STR( Normal ) )
	PORT_DIPSETTING(      0x0800, DEF_STR( Hard ) )
	PORT_DIPSETTING(      0x0000, DEF_STR( Hardest ) )
	PORT_DIPUNUSED_DIPLOC( 0x2000, 0x2000, "SW1:6" )   // Unused according to the manual
	PORT_DIPUNUSED_DIPLOC( 0x4000, 0x4000, "SW1:7" )   // Unused according to the manual
	PORT_DIPUNUSED_DIPLOC( 0x8000, 0x8000, "SW1:8" )   // Unused according to the manual
INPUT_PORTS_END

static INPUT_PORTS_START( kakumei2 )
	PORT_INCLUDE( common )
	PORT_INCLUDE( ctrl_mj1 )

	PORT_MODIFY("P1_KEY1")
	PORT_BIT( 0x0001, IP_ACTIVE_LOW, IPT_MAHJONG_FLIP_FLOP ) PORT_NAME("P1 Mahjong Flip Flop")  PORT_CODE(KEYCODE_2)

	PORT_START("DSW")
	PORT_DIPUNKNOWN_DIPLOC( 0x0001, 0x0001, "SW2:1" )   // Unused according to the manual
	PORT_DIPUNKNOWN_DIPLOC( 0x0002, 0x0002, "SW2:2" )   // Unused according to the manual
	PORT_SERVICE_DIPLOC( 0x0004, IP_ACTIVE_LOW, "SW2:3" )
	PORT_DIPUNKNOWN_DIPLOC( 0x0008, 0x0008, "SW2:4" )   // Unused according to the manual
	PORT_DIPNAME( 0x0010, 0x0000, DEF_STR( Demo_Sounds ) ) PORT_DIPLOCATION("SW2:5")    // Should default to OFF according to manual
	PORT_DIPSETTING(      0x0010, DEF_STR( Off ) )
	PORT_DIPSETTING(      0x0000, DEF_STR( On ) )
	PORT_DIPUNKNOWN_DIPLOC( 0x0020, 0x0020, "SW2:6" )   // Unused according to the manual
	PORT_DIPUNKNOWN_DIPLOC( 0x0040, 0x0040, "SW2:7" )   // Unused according to the manual
	PORT_DIPUNKNOWN_DIPLOC( 0x0080, 0x0080, "SW2:8" )   // Unused according to the manual
	PORT_DIPNAME( 0x0700, 0x0700, DEF_STR( Coinage ) ) PORT_DIPLOCATION("SW1:1,2,3")
	PORT_DIPSETTING(      0x0100, DEF_STR( 4C_1C ) )
	PORT_DIPSETTING(      0x0200, DEF_STR( 3C_1C ) )
	PORT_DIPSETTING(      0x0300, DEF_STR( 2C_1C ) )
	PORT_DIPSETTING(      0x0700, DEF_STR( 1C_1C ) )
	PORT_DIPSETTING(      0x0600, DEF_STR( 1C_2C ) )
	PORT_DIPSETTING(      0x0500, DEF_STR( 1C_3C ) )
	PORT_DIPSETTING(      0x0400, DEF_STR( 1C_4C ) )
	PORT_DIPSETTING(      0x0000, "1 Coin / 99 Credits" )   // Free Play according to the manual
	PORT_DIPNAME( 0x1800, 0x1800, DEF_STR( Difficulty ) ) PORT_DIPLOCATION("SW1:4,5")
	PORT_DIPSETTING(      0x1000, DEF_STR( Easy ) )
	PORT_DIPSETTING(      0x1800, DEF_STR( Normal ) )
	PORT_DIPSETTING(      0x0800, DEF_STR( Hard ) )
	PORT_DIPSETTING(      0x0000, DEF_STR( Hardest ) )
	PORT_DIPUNKNOWN_DIPLOC( 0x2000, 0x2000, "SW1:6" )   // Unused according to the manual
	PORT_DIPNAME( 0x4000, 0x4000, "Pinfu with Tsumo" ) PORT_DIPLOCATION("SW1:7")
	PORT_DIPSETTING(      0x0000, DEF_STR( No ) )
	PORT_DIPSETTING(      0x4000, DEF_STR( Yes ) )
	PORT_DIPNAME( 0x8000, 0x8000, DEF_STR( Flip_Screen ) ) PORT_DIPLOCATION("SW1:8")
	PORT_DIPSETTING(      0x8000, DEF_STR( Off ) )
	PORT_DIPSETTING(      0x0000, DEF_STR( On ) )
INPUT_PORTS_END

static INPUT_PORTS_START( suchiesp )
	PORT_INCLUDE( kakumei2 )

	PORT_MODIFY("DSW")
	PORT_DIPNAME( 0x1800, 0x1800, DEF_STR( Difficulty ) ) PORT_DIPLOCATION("SW1:4,5")
	PORT_DIPSETTING(      0x1800, DEF_STR( Easy ) )
	PORT_DIPSETTING(      0x1000, DEF_STR( Normal ) )
	PORT_DIPSETTING(      0x0800, DEF_STR( Hard ) )
	PORT_DIPSETTING(      0x0000, DEF_STR( Hardest ) )
	PORT_DIPNAME( 0x2000, 0x2000, "Campaign Mode" ) PORT_DIPLOCATION("SW1:6")
	PORT_DIPSETTING(      0x0000, DEF_STR( No ) )
	PORT_DIPSETTING(      0x2000, DEF_STR( Yes ) )
INPUT_PORTS_END

// check if we are into service or normal mode
// TODO: this should be set via internal work RAM buffer
void jalmah_state::mcu_check_test_mode()
{
	m_respcount = 0;

	switch(m_mcu_prg)
	{
		case MJZOOMIN_MCU:
		case DAIREIKA_MCU:
			m_test_mode = (ioport("SYSTEM")->read() & 0x0008) ? 0 : 1;
			break;
		case URASHIMA_MCU:
			m_test_mode = ((~(ioport("SYSTEM")->read()) & 0x0008) || (~(ioport("DSW")->read()) & 0x8000)) ? (1) : (0);
			break;
		case KAKUMEI_MCU:
		case KAKUMEI2_MCU:
		case SUCHIESP_MCU:
			m_test_mode = (ioport("DSW")->read() & 0x0004) ? (0) : (1);
			break;
	}
}

void jalmah_state::machine_start()
{
	const int okimax = (memregion("oki")->bytes() - 0x40000) / 0x20000;
	m_okibank->configure_entries(0,okimax,memregion("oki")->base() + 0x40000,0x20000);

	save_item(NAME(m_respcount));
	save_item(NAME(m_test_mode));
	save_item(NAME(m_prg_prot));
	save_item(NAME(m_oki_rom));
	save_item(NAME(m_oki_bank));
	save_item(NAME(m_oki_za));
}

void jalmah_state::machine_reset()
{
	m_pri = 0;
	refresh_priority_system();

	mcu_check_test_mode();
}

void urashima_state::machine_reset()
{
//  m_pri = 0;

	// initialize tilemap vram to sane defaults (test mode cares)
	for(int i=0;i<0x4000/2;i++)
		m_videoram[0][i] = 0xffff;

	for(int i=0;i<0x2000/2;i++)
		m_videoram[1][i] = 0xffff;

	mcu_check_test_mode();
}

void jalmah_state::jalmah(machine_config &config)
{
	M68000(config, m_maincpu, 12000000/2); // assume same as Mega System 1
	m_maincpu->set_addrmap(AS_PROGRAM, &jalmah_state::jalmah_map);
	m_maincpu->set_vblank_int("screen", FUNC(jalmah_state::irq2_line_hold));

	//M50747 MCU

	MEGASYS1_TILEMAP(config, m_tmap[0], m_palette, 0x0000);
	MEGASYS1_TILEMAP(config, m_tmap[1], m_palette, 0x0100);
	MEGASYS1_TILEMAP(config, m_tmap[2], m_palette, 0x0200);
	MEGASYS1_TILEMAP(config, m_tmap[3], m_palette, 0x0300);

	screen_device &screen(SCREEN(config, "screen", SCREEN_TYPE_RASTER));
	screen.set_raw(12000000/2,406,0,256,263,16,240); // assume same as nmk16 & mega system 1
	screen.set_screen_update(FUNC(jalmah_state::screen_update_jalmah));
	screen.set_palette(m_palette);

	PALETTE(config, m_palette).set_format(palette_device::RRRRGGGGBBBBRGBx, 0x400);

	TIMER(config, "mcusim").configure_periodic(FUNC(jalmah_state::mcu_sim), attotime::from_hz(10000));

	SPEAKER(config, "mono").front_center();
	okim6295_device &oki(OKIM6295(config, "oki", 4000000, okim6295_device::PIN7_LOW));
	oki.set_addrmap(0, &jalmah_state::oki_map);
	oki.add_route(ALL_OUTPUTS, "mono", 0.5);
}

static GFXDECODE_START( gfx_urashima )
	GFXDECODE_ENTRY( "scroll0", 0, gfx_8x8x4_col_2x2_group_packed_msb, 0x100, 16 )
	GFXDECODE_ENTRY( "scroll1", 0, gfx_8x8x4_col_2x2_group_packed_msb, 0x100, 16 )
	GFXDECODE_ENTRY( "scroll2", 0, gfx_8x8x4_col_2x2_group_packed_msb, 0x100, 16 )
	GFXDECODE_ENTRY( "scroll3", 0, gfx_8x8x4_packed_msb,               0x000, 16 )
GFXDECODE_END

void jalmah_state::jalmahv1(machine_config &config)
{
	jalmah(config);

	m_maincpu->set_addrmap(AS_PROGRAM, &jalmah_state::jalmahv1_map);
}

void urashima_state::urashima(machine_config &config)
{
	jalmah(config);

	m_maincpu->set_addrmap(AS_PROGRAM, &urashima_state::urashima_map);

	// Urashima seems to use an earlier version of the Jaleco tilemaps (without range etc.)
	// and with per-scanline video registers
	config.device_remove("scroll0");
	config.device_remove("scroll1");
	config.device_remove("scroll2");
	config.device_remove("scroll3");

	GFXDECODE(config, "gfxdecode", m_palette, gfx_urashima);

	subdevice<screen_device>("screen")->set_screen_update(FUNC(urashima_state::screen_update_urashima));
}

// fake ROM containing 68k snippets
// the original MCU actually uploads these into shared work ram area
// we actually compile it using EASy68k tool
#define LOAD_FAKE_MCU_ROM \
	ROM_REGION( 0x10000, "jmcu_rom", 0 ) \
	ROM_LOAD16_WORD_SWAP( "mcu.bin", 0, 0x10000, BAD_DUMP CRC(35425d2f) SHA1(9a9914d4e50a665d4eb0efb80552f357fc719e7e)) \


/*

Urashima Mahjong
(c) 1989 UPL

*/

ROM_START ( urashima )
	ROM_REGION( 0x80000, "maincpu", 0 )     /* 68000 code */
	ROM_LOAD16_BYTE( "um-2.15d",  0x00000, 0x20000, CRC(a90a47e3) SHA1(2f912001e9177cce8c3795f3d299115b80fdca4e) )
	ROM_RELOAD(                   0x40000, 0x20000 )
	ROM_LOAD16_BYTE( "um-1.15c",  0x00001, 0x20000, CRC(5f5c8f39) SHA1(cef663965c3112f87788d6a871e609c0b10ef9a2) )
	ROM_RELOAD(                   0x40001, 0x20000 )

	ROM_REGION( 0x1000, "mcu", 0 ) /* M50747 MCU Code */
	ROM_LOAD( "m50747", 0x0000, 0x1000, NO_DUMP )

	LOAD_FAKE_MCU_ROM

	ROM_REGION( 0x140000, "oki", ROMREGION_ERASEFF ) /* Samples */
	ROM_LOAD( "um-3.22c",      0x40000, 0x80000, CRC(9fd8c8fa) SHA1(0346f74c03a4daa7a84b64c9edf0e54297c82fd9) )
	ROM_COPY( "oki" ,          0x40000, 0x00000, 0x40000 )

	// 16x16 tiles
	// layer 0 bankswitches tiles 0x800-0xfff by reading following two roms.
	// we copy them into three regions for simplicity in tilemap code.
	ROM_REGION( 0x080000, "gfx1", 0 )
	ROM_LOAD( "um-6.2l",    0x000000, 0x080000, CRC(076be5b5) SHA1(77444025f149a960137d3c79abecf9b30defa341) )

	ROM_REGION( 0x080000, "gfx2", 0 )
	ROM_LOAD( "um-7.4l",    0x000000, 0x080000, CRC(d2a68cfb) SHA1(eb6cb1fad306b697b2035a31ad48e8996722a032) )

	ROM_REGION( 0x080000, "scroll0", 0 )
	ROM_COPY( "gfx1" , 0x000000, 0x000000, 0x80000 )

	ROM_REGION( 0x080000, "scroll1", 0 )
	ROM_COPY( "gfx1",  0x000000, 0x000000, 0x40000 )
	ROM_COPY( "gfx2",  0x000000, 0x040000, 0x40000 )

	ROM_REGION( 0x080000, "scroll2", 0 )
	ROM_COPY( "gfx1",  0x000000, 0x000000, 0x40000 )
	ROM_COPY( "gfx2",  0x040000, 0x040000, 0x40000 )

	ROM_REGION( 0x020000, "scroll3", 0 )
	// 8x8 tiles
	ROM_LOAD( "um-5.22j",       0x000000, 0x020000, CRC(991776a2) SHA1(56740553d7d26aaeb9bec8557727030950bb01f7) )

	ROM_REGION( 0x240, "proms", 0 ) /* Misc PROMs (unknown) */
	ROM_LOAD( "um-10.2b",      0x0000, 0x0100, CRC(cfdbb86c) SHA1(588822f6308a860937349c9106c2b4b1a75823ec) )
	ROM_LOAD( "um-11.2c",      0x0100, 0x0100, CRC(ff5660cf) SHA1(a4635dcf9d6dd637ea4f36f1ad233db0bd039731) )
	ROM_LOAD( "um-12.20c",     0x0200, 0x0020, CRC(bdb66b02) SHA1(8755244de638d7e835e35e08c62b0612958e6ca5) )
	ROM_LOAD( "um-13.10l",     0x0220, 0x0020, CRC(4ce07ec0) SHA1(5f5744ddc7f258307f036fde4c0a8e6271b2d1f9) )
ROM_END

/*

Mahjong Daireikai (JPN Ver.)
(c)1989 Jaleco / NMK

*/

ROM_START( daireika )
	ROM_REGION( 0x80000, "maincpu", 0 ) /* 68000 Code */
	ROM_LOAD16_BYTE( "mj1.bin", 0x00001, 0x20000, CRC(3b4e8357) SHA1(1ad3e40ec6b6ff4f1c9c09d7b530f67b460151d8) )
	ROM_RELOAD(                 0x40001, 0x20000 )
	ROM_LOAD16_BYTE( "mj2.bin", 0x00000, 0x20000, CRC(c54d2f9b) SHA1(d59fc5a9e5bbb96b3b6a43378f4f2215c368b671) )
	ROM_RELOAD(                 0x40000, 0x20000 )

	ROM_REGION( 0x1000, "mcu", 0 ) /* M50747 MCU Code */
	ROM_LOAD( "m50747", 0x0000, 0x1000, NO_DUMP )

	LOAD_FAKE_MCU_ROM

	ROM_REGION( 0x140000, "oki", ROMREGION_ERASEFF ) /* Samples */
	ROM_LOAD( "mj3.bin", 0x40000, 0x80000, CRC(65bb350c) SHA1(e77866f2d612a0973adc616717e7c89a37d6c48e) )
	ROM_COPY( "oki" ,    0x40000, 0x00000, 0x40000 )

	ROM_REGION( 0x80000, "scroll0", 0 ) /* BG3 */
	ROM_LOAD( "mj10.bin", 0x00000, 0x80000, CRC(1f5509a5) SHA1(4dcdee0e159956cf73f5f85ce278479be2a9ca9f) )

	ROM_REGION( 0x40000, "scroll1", 0 ) /* BG2 */
//  ROM_COPY( "scroll3",     0x20000, 0x20000, 0x20000 )/*mj10.bin*/
	ROM_LOAD( "mj11.bin", 0x00000, 0x20000, CRC(14867c51) SHA1(b282b5048a55c9ad72ceb0d23f010a0fee78704f) )
	ROM_LOAD( "mj12.bin", 0x20000, 0x20000, CRC(236f809f) SHA1(9e15dd8a810a9d4f7f75f084d6bd277ea7d0e40a) )

	ROM_REGION( 0x10000, "scroll2", 0 ) /* BG1 */
	ROM_LOAD( "mj13.bin", 0x00000, 0x10000, CRC(c54bca14) SHA1(ee9c99858817aedd70bd6266b7a71c3c5ad00607) )

	ROM_REGION( 0x20000, "scroll3", 0 ) /* BG0 */
	ROM_LOAD( "mj14.bin", 0x00000, 0x10000, CRC(c84c5577) SHA1(6437368d3be39739d62158590ecd373aa070a9b2) )
	ROM_COPY( "scroll2",     0x00000, 0x10000, 0x10000 )

	ROM_REGION( 0x100, "prirom", 0 ) /* Priority PROM */
	ROM_LOAD( "mj15.bpr", 0x000, 0x100, CRC(ebac41f9) SHA1(9d1629d977849663392cbf03a3ddf76665f88608) )

	ROM_REGION( 0x120, "proms", 0 ) /* Misc PROMs (unknown) */
	ROM_LOAD( "mj16.bpr", 0x000, 0x100, CRC(8d5dc1f6) SHA1(9f723e7cd44f8c09ec30b04725644346484ec753) )
	ROM_LOAD( "mj17.bpr", 0x100, 0x020, CRC(a17c3e8a) SHA1(d7969fad7cec9c792c53aa457f4ad764a727e0a5) )
ROM_END

/*

Mahjong Channel Zoom In (JPN Ver.)
(c)1990 Jaleco

*/

ROM_START( mjzoomin )
	ROM_REGION( 0x80000, "maincpu", 0 ) /* 68000 Code */
	ROM_LOAD16_BYTE( "zoomin-1.bin", 0x00001, 0x20000, CRC(b8b04d30) SHA1(abb163a9965421b4d92114bba974ccb13bb57f5a) )
	ROM_RELOAD(                      0x40001, 0x20000 )
	ROM_LOAD16_BYTE( "zoomin-2.bin", 0x00000, 0x20000, CRC(c7eb982c) SHA1(9006ded2aa1fef38bde114110d76b20747c32658) )
	ROM_RELOAD(                      0x40000, 0x20000 )

	ROM_REGION( 0x1000, "mcu", 0 ) /* M50747 MCU Code */
	ROM_LOAD( "m50747", 0x0000, 0x1000, NO_DUMP )

	LOAD_FAKE_MCU_ROM

	ROM_REGION( 0x140000, "oki", ROMREGION_ERASEFF ) /* Samples */
	ROM_LOAD( "zoomin-3.bin", 0x40000, 0x80000, CRC(07d7b8cd) SHA1(e05ce80ffb945b04f93f8c49d0c840b0bff6310b) )
	ROM_COPY( "oki" ,         0x40000, 0x00000, 0x40000 )

	ROM_REGION( 0x80000, "scroll0", 0 )
	ROM_LOAD( "zoomin10.bin", 0x00000, 0x80000, CRC(40aec575) SHA1(ef7a3c7a94523c5967ab774936b873c9629e0e44) )

	ROM_REGION( 0x40000, "scroll1", 0 )
	ROM_LOAD( "zoomin12.bin", 0x00000, 0x40000, CRC(b0b94554) SHA1(10490b7475810910140ce075e62f604b914e5511) )

	ROM_REGION( 0x20000, "scroll2", 0 )
	ROM_LOAD( "zoomin13.bin", 0x00000, 0x20000, CRC(888d79fe) SHA1(eb9671d4c7608edd1231dc0cae47aab2430cbd66) )

	ROM_REGION( 0x20000, "scroll3", 0 )
	ROM_LOAD( "zoomin14.bin", 0x00000, 0x20000, CRC(4e32aa45) SHA1(450a3449ca8b4f0dfe8b62cceaee9366eaf3dc3d) )

	ROM_REGION( 0x100, "prirom", 0 ) /* Priority PROM */
	ROM_LOAD( "mj15.bpr", 0x000, 0x100, CRC(ebac41f9) SHA1(9d1629d977849663392cbf03a3ddf76665f88608) )

	ROM_REGION( 0x120, "proms", 0 ) /* Misc PROMs (unknown) */
	ROM_LOAD( "mj16.bpr", 0x000, 0x100, CRC(8d5dc1f6) SHA1(9f723e7cd44f8c09ec30b04725644346484ec753) )
	ROM_LOAD( "mj17.bpr", 0x100, 0x020, CRC(a17c3e8a) SHA1(d7969fad7cec9c792c53aa457f4ad764a727e0a5) )
ROM_END

/*

Mahjong Kakumei (JPN Ver.)
(c)1990 Jaleco


*/

ROM_START( kakumei )
	ROM_REGION( 0x80000, "maincpu", 0 ) /* 68000 Code */
	ROM_LOAD16_BYTE( "mj-re-1.bin", 0x00001, 0x20000, CRC(b90215be) SHA1(10384237f734836acefb4b5f53a6ddd9054d63ff) )
	ROM_RELOAD(                     0x40001, 0x20000 )
	ROM_LOAD16_BYTE( "mj-re-2.bin", 0x00000, 0x20000, CRC(37eff266) SHA1(1d9e88c0270daadfafff1f73eb617e77b1d199d6) )
	ROM_RELOAD(                     0x40000, 0x20000 )

	ROM_REGION( 0x1000, "mcu", 0 ) /* M50747 MCU Code */
	ROM_LOAD( "m50747", 0x0000, 0x1000, NO_DUMP )

	ROM_REGION( 0x140000, "oki", ROMREGION_ERASEFF ) /* Samples */
	ROM_LOAD( "rom3.bin", 0x00000, 0x40000, CRC(c9b7a526) SHA1(edec57e66d4ff601c8fdef7b1405af84a3f3d883) )
	ROM_RELOAD(           0x40000, 0x40000 )

	ROM_REGION( 0x80000, "scroll0", 0 )
	ROM_LOAD( "rom10.bin", 0x00000, 0x80000, CRC(88366377) SHA1(163a08415a631c8a09a0a55bc2819988d850f2ad) )

	ROM_REGION( 0x40000, "scroll1", 0 )
	ROM_LOAD( "rom12.bin", 0x00000, 0x40000, CRC(31620a61) SHA1(11593ca7760e1a628e63aa48d9ad3800cf7af275) )

	ROM_REGION( 0x20000, "scroll2", 0 )
	ROM_LOAD( "rom13.bin", 0x00000, 0x20000, CRC(9bef4fc2) SHA1(6598ab9dba513efcda01e47cc7752b47a97f2c6a) )

	ROM_REGION( 0x20000, "scroll3", 0 )
	ROM_LOAD( "rom14.bin", 0x00000, 0x20000, CRC(63e88dd6) SHA1(58734c8caf1b1ddc4cf0437ffd8109292b76c4e1) )

	ROM_REGION( 0x100, "prirom", 0 ) /* Priority PROM */
	ROM_LOAD( "mj15.bpr", 0x000, 0x100, CRC(ebac41f9) SHA1(9d1629d977849663392cbf03a3ddf76665f88608) )

	ROM_REGION( 0x120, "proms", 0 ) /* Misc PROMs (unknown) */
	ROM_LOAD( "mj16.bpr", 0x000, 0x100, CRC(8d5dc1f6) SHA1(9f723e7cd44f8c09ec30b04725644346484ec753) )
	ROM_LOAD( "mj17.bpr", 0x100, 0x020, CRC(a17c3e8a) SHA1(d7969fad7cec9c792c53aa457f4ad764a727e0a5) )
ROM_END

/*

Mahjong Kakumei2 Princess League (JPN Ver.)
(c)1992 Jaleco

*/

ROM_START( kakumei2 )
	ROM_REGION( 0x80000, "maincpu", 0 ) /* 68000 Code */
	ROM_LOAD16_BYTE( "mj-8956.1", 0x00001, 0x40000, CRC(db4ce32f) SHA1(1ae13627b9922143f462b1c3bbed87374f6e1667) )
	ROM_LOAD16_BYTE( "mj-8956.2", 0x00000, 0x40000, CRC(0f942507) SHA1(7ec2fbeb9a34dfc80c4df3de8397388db13f5c7c) )

	ROM_REGION( 0x1000, "mcu", 0 ) /* M50747 MCU Code */
	ROM_LOAD( "m50747", 0x0000, 0x1000, NO_DUMP )

	ROM_REGION( 0x140000, "oki", ROMREGION_ERASEFF ) /* Samples */
	ROM_LOAD( "92000-01.3", 0x040000, 0x80000, CRC(4b0ed440) SHA1(11961d217a41f92b60d5083a5e346c245f7db620) )
	ROM_COPY( "oki" ,       0x040000, 0x00000, 0x40000 )

	ROM_REGION( 0x80000, "scroll0", 0 )
	ROM_LOAD( "92000-02.10", 0x00000, 0x80000, CRC(338fa9b2) SHA1(05ba4b3c44249cf92be238bf53d6345dc49b0881) )

	ROM_REGION( 0x40000, "scroll1", 0 )
	ROM_LOAD( "mj-8956.12", 0x00000, 0x40000, CRC(4a088f69) SHA1(468c446d1f345dfd628cdd66ca71cf82e02abe6f) )

	ROM_REGION( 0x20000, "scroll2", 0 )
	ROM_LOAD( "mj-8956.13", 0x00000, 0x20000, CRC(afe93cf4) SHA1(1973dc5821c6df68e20f8a84b5c9ae281dd3f85f) )

	ROM_REGION( 0x20000, "scroll3", 0 )
	ROM_LOAD( "mj-8956.14", 0x00000, 0x20000, CRC(2b2fe999) SHA1(d9d601e2c008791f5bff6e7b1340f754dd094201) )

	ROM_REGION( 0x100, "prirom", 0 ) /* Priority PROM */
	ROM_LOAD( "mj15.bpr", 0x000, 0x100, CRC(ebac41f9) SHA1(9d1629d977849663392cbf03a3ddf76665f88608) )

	ROM_REGION( 0x120, "proms", 0 ) /* Misc PROMs (unknown) */
	ROM_LOAD( "mj16.bpr", 0x000, 0x100, CRC(8d5dc1f6) SHA1(9f723e7cd44f8c09ec30b04725644346484ec753) )
	ROM_LOAD( "mj17.bpr", 0x100, 0x020, CRC(a17c3e8a) SHA1(d7969fad7cec9c792c53aa457f4ad764a727e0a5) )
ROM_END

/*

Idol Janshi Su-Chi-Pi Special
(c)Jaleco 1994

CPU  : M68000P10
Sound: OKI M6295
OSC  : 12.000MHz 4.000MHz

MJ-8956
YSP-40101 171

1.bin - Main program ver.1.2 (27c2001)
2.bin - Main program ver.1.2 (27c2001)

3.bin - Sound data (27c4000)
4.bin - Sound data (27c4000)

7.bin  (27c4000) \
8.bin  (27c4000) |
9.bin  (27c4000) |
10.bin (27c4000) |
                 |- Graphics
12.bin (27c2001) |
                 |
13.bin (27c1001) |
                 |
14.bin (27c1001) /

pr92000a.prm (82s129) \
pr92000b.prm (82s129) |- Not dumped
pr93035.prm  (82s123) /

Custom chips:
GS-9000406 9345K5005 (80pin QFP) x4
GS-9000404 9248EP004 (44pin QFP)

Other chips:
MO-92000 (64pin DIP)
NEC D65012GF303 9050KX016 (80pin QFP) x4

*/

ROM_START( suchiesp )
	ROM_REGION( 0x80000, "maincpu", 0 ) /* 68000 Code */
	ROM_LOAD16_BYTE( "1.bin", 0x00001, 0x40000, CRC(e37cc745) SHA1(73b3314d27a0332068e0d2bbc08d7401e371da1b) )
	ROM_LOAD16_BYTE( "2.bin", 0x00000, 0x40000, CRC(42ecf88a) SHA1(7bb85470bc9f94c867646afeb91c4730599ea299) )

	ROM_REGION( 0x1000, "mcu", 0 ) /* M50747 MCU Code */
	ROM_LOAD( "m50747", 0x0000, 0x1000, NO_DUMP )

	ROM_REGION( 0x100000, "oki_data", ROMREGION_ERASEFF ) /* Samples */
	ROM_LOAD( "3.bin", 0x00000, 0x80000, CRC(691b5387) SHA1(b8bc9f904eab7653566042b18d89276d537ba586) )
	ROM_LOAD( "4.bin", 0x80000, 0x80000, CRC(3fe932a1) SHA1(9e768b901738ee9eba207a67c4fd19efb0035a68) )

	ROM_REGION( 0x140000, "oki", ROMREGION_ERASEFF ) /* Samples */
	ROM_COPY( "oki_data" , 0x000000, 0x000000+0x00000, 0x40000 )

	/* PAL address shuffling for the BGM data (TODO: check this with a side-by-side test)*/
	ROM_COPY( "oki_data" , 0x20000, 0x000000+0x40000, 0x20000 ) // 0
	ROM_COPY( "oki_data" , 0x40000, 0x020000+0x40000, 0x20000 ) // 1
	ROM_COPY( "oki_data" , 0x60000, 0x040000+0x40000, 0x20000 ) // 2
	ROM_COPY( "oki_data" , 0x000000, 0x060000+0x40000, 0x20000 ) // 3

	ROM_COPY( "oki_data" , 0x80000, 0x080000+0x40000, 0x40000 )
	ROM_COPY( "oki_data" , 0xc0000, 0x0c0000+0x40000, 0x40000 )

	ROM_REGION( 0x200000, "scroll0", 0 )
	ROM_LOAD( "7.bin",  0x000000, 0x80000, CRC(18caf6f3) SHA1(3df6b257867487adcba1a05c8745413d9a15c3d7) )
	ROM_LOAD( "8.bin",  0x080000, 0x80000, CRC(0403399a) SHA1(8d39a68b3a1a431afe93ff485e837389a4502d0c) )
	ROM_LOAD( "9.bin",  0x100000, 0x80000, CRC(8a348246) SHA1(13516c48bdbe8d78e7517473ef2835a4dea2ce93) )
	ROM_LOAD( "10.bin", 0x180000, 0x80000, CRC(2b0d1afd) SHA1(40009b450901567052aa63c4629a2f7a10343e63) )

	ROM_REGION( 0x40000, "scroll1", 0 )
	ROM_LOAD( "12.bin", 0x00000, 0x40000, CRC(146596eb) SHA1(f85e92e6dc9ebef5e67d28f1d450225cd2a2abaa) )

	ROM_REGION( 0x20000, "scroll2", 0 )
	ROM_LOAD( "13.bin", 0x00000, 0x20000, CRC(99466044) SHA1(ca31b58a5d4656f95d80ddb9bc1f9a53f5f2446c) )

	ROM_REGION( 0x20000, "scroll3", 0 )
	ROM_LOAD( "14.bin", 0x00000, 0x20000, CRC(e465a540) SHA1(10e19599ab90b0c0b6ef6ee41f16620bd1ba6800) )

	ROM_REGION( 0x100, "prirom", 0 ) /* Priority PROM */
	ROM_LOAD( "mj15.bpr", 0x000, 0x100, CRC(ebac41f9) SHA1(9d1629d977849663392cbf03a3ddf76665f88608) )

	ROM_REGION( 0x120, "proms", 0 ) /* Misc PROMs (unknown) */
	ROM_LOAD( "mj16.bpr", 0x000, 0x100, CRC(8d5dc1f6) SHA1(9f723e7cd44f8c09ec30b04725644346484ec753) )
	ROM_LOAD( "pr93035.17", 0x100, 0x020, CRC(ab28ae42) SHA1(e05652c4bd5db4c7d7a1bfdeb63841e8b019f24c) )
ROM_END


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

MCU code snippets

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

READ16_MEMBER(jalmah_state::urashima_mcu_r)
{
	static const int resp[] = { 0x99, 0xd8, 0x00,
							0x2a, 0x6a, 0x00,
							0x9c, 0xd8, 0x00,
							0x2f, 0x6f, 0x00,
							0x22, 0x62, 0x00,
							0x25, 0x65, 0x00,
							0x23, 0x63, 0x00,
							0x3e, 0x7e, 0x00,
							0x35, 0x75, 0x00,
							0x21, 0x61, 0x00 };
	int res;

	res = resp[m_respcount++];
	if (m_respcount >= ARRAY_LENGTH(resp)) m_respcount = 0;

//  logerror("%s: mcu_r %02x\n",machine().dscribe_context(),res);

	return res;
}

#define MCU_JMP(_workram_,_data_) \
	m_sharedram[_workram_]   = 0x4ef9; \
	m_sharedram[_workram_+1] = 0x0010; \
	m_sharedram[_workram_+2] = _data_; \


/*
data value is REQ under mjzoomin video test menu. Is it related to the MCU?
*/
WRITE16_MEMBER(jalmah_state::urashima_mcu_w)
{
	if(ACCESSING_BITS_0_7 && data)
	{
		/*******************************************************
		1st M68k code uploaded by the MCU (sound prg)
		*******************************************************/
		MCU_JMP(0x320/2,SNIPPET_SOUND);
		/*******************************************************
		1st alt M68k code uploaded by the MCU (Input test mode)
		*******************************************************/
		/*similar to mjzoomin but with offset summed with 0x300?*/
		/*tx scrollx = $200*/
		m_sharedram[0x03c6/2] = 0x6008; //bra $+10
		MCU_JMP(0x3d0/2,SNIPPET_PALETTE1);

		/*******************************************************
		2nd M68k code uploaded by the MCU (tile upload)
		*******************************************************/
		MCU_JMP(0x3ca/2,SNIPPET_TILE);

		/*******************************************************
		3rd M68k code uploaded by the MCU (palette upload)
		*******************************************************/
		MCU_JMP(0x3c0/2,SNIPPET_PALETTE2);
	}
}

READ16_MEMBER(jalmah_state::daireika_mcu_r)
{
	static const int resp[] = { 0x99, 0xd8, 0x00,
							0x2a, 0x6a, 0x00,
							0x9c, 0xd8, 0x00,
							0x2f, 0x6f, 0x00,
							0x22, 0x62, 0x00,
							0x25, 0x65, 0x00,
							0x23, 0x63, 0x00,
							0x3e, 0x7e, 0x00,
							0x35, 0x75, 0x00,
							0x21, 0x61, 0x00 };
	int res;

	res = resp[m_respcount++];
	if (m_respcount >= ARRAY_LENGTH(resp)) m_respcount = 0;

//  logerror("%s: mcu_r %02x\n",machine().describe_context(),res);

	return res;
}

WRITE16_MEMBER(jalmah_state::daireika_mcu_w)
{
	if(ACCESSING_BITS_0_7 && data)
	{
		/*******************************************************
		1st M68k code uploaded by the MCU.
		random number generator (guess)
		*******************************************************/
		MCU_JMP(0x0140/2,SNIPPET_RNG);

		/*******************************************************
		2nd M68k code uploaded by the MCU. (sound playback)
		*******************************************************/
		MCU_JMP(0x0020/2,SNIPPET_SOUND);

		/*******************************************************
		3rd M68k code uploaded by the MCU.
		see mjzoomin_mcu_w
		*******************************************************/
		m_sharedram[0x00c6/2] = 0x6008; //bra +$8, we need this due of clash with SNIPPET_TILE
		MCU_JMP(0x00d0/2,SNIPPET_PALETTE1);

		/*******************************************************
		4th M68k code uploaded by the MCU
		They seem video code cleaning functions
		*******************************************************/
		MCU_JMP(0x100/2,SNIPPET_CLR_LAYER0);
		MCU_JMP(0x108/2,SNIPPET_CLR_LAYER1);
		MCU_JMP(0x110/2,SNIPPET_CLR_LAYER2);

		/* layer 3 clear function is already in 68k ROM program???*/
		m_sharedram[0x0126/2] = 0x4ef9;
		m_sharedram[0x0128/2] = 0x0000;
		m_sharedram[0x012a/2] = 0x2684;

		/*******************************************************
		5th M68k code uploaded by the MCU (palette upload)
		*******************************************************/
		MCU_JMP(0x00c0/2,SNIPPET_PALETTE2);

		/*******************************************************
		6th M68k code uploaded by the MCU (tile upload)
		*******************************************************/
		MCU_JMP(0x00ca/2,SNIPPET_TILE);
	}
}

READ16_MEMBER(jalmah_state::mjzoomin_mcu_r)
{
	static const int resp[] = { 0x9c, 0xd8, 0x00,
							0x2a, 0x6a, 0x00,
							0x99, 0xd8, 0x00,
							0x2f, 0x6f, 0x00,
							0x22, 0x62, 0x00,
							0x25, 0x65, 0x00,
							0x35, 0x75, 0x00,
							0x36, 0x36, 0x00,
							0x21, 0x61, 0x00 };
	int res;

	res = resp[m_respcount++];
	if (m_respcount >= ARRAY_LENGTH(resp)) m_respcount = 0;

//  logerror("%04x: mcu_r %02x\n",machine().describe_context(),res);

	return res;
}

/*
data value is REQ under mjzoomin video test menu.It is related to the MCU?
*/
WRITE16_MEMBER(jalmah_state::mjzoomin_mcu_w)
{
	if(ACCESSING_BITS_0_7 && data)
	{
		/******************************************************
		1st M68k code uploaded by the MCU(Service Mode PC=2a56).
		Program passes some parameters before entering into
		the sub-routine (jsr)
		D1 = 0xf
		A0 = 1026e
		A1 = 88600
		(A0) is the vector number for take the real palette
		address.
		******************************************************/
		MCU_JMP(0x00c6/2,SNIPPET_PALETTE1);

		/*******************************************************
		2nd M68k code uploaded by the MCU (Sound read/write)
		(Note:copied from suchiesp,check here the sound banking)
		*******************************************************/
		MCU_JMP(0x0020/2,SNIPPET_SOUND);

		/*******************************************************
		3rd M68k code uploaded by the MCU (in-game palette upload)
		*******************************************************/
		MCU_JMP(0x00c0/2,SNIPPET_PALETTE2);
	}
}

READ16_MEMBER(jalmah_state::kakumei_mcu_r)
{
	static const int resp[] = { 0x8a, 0xd8, 0x00,
							0x3c, 0x7c, 0x00,
							0x99, 0xd8, 0x00,
							0x25, 0x65, 0x00,
							0x36, 0x76, 0x00,
							0x35, 0x75, 0x00,
							0x2f, 0x6f, 0x00,
							0x31, 0x71, 0x00,
							0x3e, 0x7e, 0x00 };
	int res;

	res = resp[m_respcount++];
	if (m_respcount >= ARRAY_LENGTH(resp)) m_respcount = 0;

//  popmessage("%s: mcu_r %02x",machine().describe_context(),res);

	return res;
}

READ16_MEMBER(jalmah_state::suchiesp_mcu_r)
{
	static const int resp[] = { 0x8a, 0xd8, 0x00,
							0x3c, 0x7c, 0x00,
							0x99, 0xd8, 0x00,
							0x25, 0x65, 0x00,
							0x36, 0x76, 0x00,
							0x35, 0x75, 0x00,
							0x2f, 0x6f, 0x00,
							0x31, 0x71, 0x00,
							0x3e, 0x7e, 0x00 };
	int res;

	res = resp[m_respcount++];
	if (m_respcount >= ARRAY_LENGTH(resp)) m_respcount = 0;

//  popmessage("%s: mcu_r %02x",machine().describe_context(),res);

	return res;
}

void jalmah_state::init_urashima()
{
	m_maincpu->space(AS_PROGRAM).install_read_handler(0x80004, 0x80005, read16_delegate(FUNC(jalmah_state::urashima_mcu_r), this));
	m_maincpu->space(AS_PROGRAM).install_write_handler(0x80012, 0x80013, write16_delegate(FUNC(jalmah_state::urashima_mcu_w), this));

	m_mcu_prg = URASHIMA_MCU;
}

void jalmah_state::init_daireika()
{
	m_maincpu->space(AS_PROGRAM).install_read_handler(0x80004, 0x80005, read16_delegate(FUNC(jalmah_state::daireika_mcu_r), this));
	m_maincpu->space(AS_PROGRAM).install_write_handler(0x80012, 0x80013, write16_delegate(FUNC(jalmah_state::daireika_mcu_w), this));

	m_mcu_prg = DAIREIKA_MCU;
}

void jalmah_state::init_mjzoomin()
{
	m_maincpu->space(AS_PROGRAM).install_read_handler(0x80004, 0x80005, read16_delegate(FUNC(jalmah_state::mjzoomin_mcu_r), this));
	m_maincpu->space(AS_PROGRAM).install_write_handler(0x80012, 0x80013, write16_delegate(FUNC(jalmah_state::mjzoomin_mcu_w), this));

	m_mcu_prg = MJZOOMIN_MCU;
}

void jalmah_state::init_kakumei()
{
	m_maincpu->space(AS_PROGRAM).install_read_handler(0x80004, 0x80005, read16_delegate(FUNC(jalmah_state::kakumei_mcu_r), this));

	m_mcu_prg = KAKUMEI_MCU;
}

void jalmah_state::init_kakumei2()
{
	m_maincpu->space(AS_PROGRAM).install_read_handler(0x80004, 0x80005, read16_delegate(FUNC(jalmah_state::kakumei_mcu_r), this));

	m_mcu_prg = KAKUMEI2_MCU;
}

void jalmah_state::init_suchiesp()
{
	m_maincpu->space(AS_PROGRAM).install_read_handler(0x80004, 0x80005, read16_delegate(FUNC(jalmah_state::suchiesp_mcu_r), this));

	m_mcu_prg = SUCHIESP_MCU;
}

/*First version of the MCU*/
GAME( 1989, urashima, 0, urashima,  urashima, urashima_state, init_urashima, ROT0, "UPL",          "Otogizoushi Urashima Mahjong (Japan)",         MACHINE_IMPERFECT_GRAPHICS | MACHINE_IMPERFECT_SOUND | MACHINE_UNEMULATED_PROTECTION )
GAME( 1989, daireika, 0, jalmahv1,    daireika, jalmah_state,   init_daireika, ROT0, "Jaleco / NMK", "Mahjong Daireikai (Japan)",                    MACHINE_IMPERFECT_GRAPHICS | MACHINE_IMPERFECT_SOUND | MACHINE_UNEMULATED_PROTECTION )
GAME( 1990, mjzoomin, 0, jalmahv1,    mjzoomin, jalmah_state,   init_mjzoomin, ROT0, "Jaleco",       "Mahjong Channel Zoom In (Japan)",              MACHINE_IMPERFECT_GRAPHICS | MACHINE_IMPERFECT_SOUND | MACHINE_UNEMULATED_PROTECTION )
/*Second version of the MCU*/
GAME( 1990, kakumei,  0, jalmah,    kakumei,  jalmah_state,   init_kakumei,  ROT0, "Jaleco",       "Mahjong Kakumei (Japan)",                      MACHINE_IMPERFECT_GRAPHICS )
GAME( 1992, kakumei2, 0, jalmah,    kakumei2, jalmah_state,   init_kakumei2, ROT0, "Jaleco",       "Mahjong Kakumei 2 - Princess League (Japan)",  MACHINE_IMPERFECT_GRAPHICS | MACHINE_UNEMULATED_PROTECTION )
GAME( 1993, suchiesp, 0, jalmah,    suchiesp, jalmah_state,   init_suchiesp, ROT0, "Jaleco",       "Idol Janshi Suchie-Pai Special (Japan)",       MACHINE_IMPERFECT_GRAPHICS )