1 // license:BSD-3-Clause
2 // copyright-holders:Angelo Salese
3 /**********************************************************************************************
4
5 Mirage Youjuu Mahjongden (c) 1994 Mitchell
6
7 Similar to simpl156.cpp with shifted stuff around.
8
9 TODO:
10 - some unknown writes (irq acks / sprite DMA start presumably);
11
12 Notes:
13 - To enter into full Test Mode you need to keep pressed the Mahjong A key at start-up.
14
15 ===============================================================================================
16
17 Mirage Youjuu Mahjongden
18 (c)1994 Mitchell
19
20 MT4001-2
21 DEC-22V0
22 all custom chips are surface scratched, but I believe they are DECO156 and mates.
23
24 Sound: M6295x2
25 OSC : 28.0000MHz
26
27 MBL-00.7A [2e258b7b]
28
29 MBL-01.11A [895be69a]
30 MBL-02.12A [474f6104]
31
32 MBL-03.10A [4a599703]
33
34 MBL-04.12K [b533123d]
35
36 MR_00-.2A [3a53f33d]
37 MR_01-.3A [a0b758aa]
38
39 ***********************************************************************************************/
40
41 #include "emu.h"
42 #include "cpu/m68000/m68000.h"
43 #include "machine/decocrpt.h"
44 #include "machine/eepromser.h"
45 #include "video/deco16ic.h"
46 #include "sound/okim6295.h"
47 #include "video/bufsprite.h"
48 #include "video/decospr.h"
49 #include "emupal.h"
50 #include "screen.h"
51 #include "speaker.h"
52
53 // mirage_state was also defined in mess/drivers/mirage.c
54 class miragemj_state : public driver_device
55 {
56 public:
miragemj_state(const machine_config & mconfig,device_type type,const char * tag)57 miragemj_state(const machine_config &mconfig, device_type type, const char *tag) :
58 driver_device(mconfig, type, tag),
59 m_maincpu(*this, "maincpu"),
60 m_deco_tilegen(*this, "tilegen"),
61 m_eeprom(*this, "eeprom"),
62 m_oki_sfx(*this, "oki_sfx"),
63 m_oki_bgm(*this, "oki_bgm"),
64 m_spriteram(*this, "spriteram") ,
65 m_pf1_rowscroll(*this, "pf1_rowscroll"),
66 m_pf2_rowscroll(*this, "pf2_rowscroll"),
67 m_sprgen(*this, "spritegen")
68 { }
69
70 void mirage(machine_config &config);
71
72 void init_mirage();
73
74 private:
75 /* misc */
76 uint8_t m_mux_data;
77
78 /* devices */
79 required_device<m68000_device> m_maincpu;
80 required_device<deco16ic_device> m_deco_tilegen;
81 required_device<eeprom_serial_93cxx_device> m_eeprom;
82 required_device<okim6295_device> m_oki_sfx;
83 required_device<okim6295_device> m_oki_bgm;
84 required_device<buffered_spriteram16_device> m_spriteram;
85 /* memory pointers */
86 required_shared_ptr<uint16_t> m_pf1_rowscroll;
87 required_shared_ptr<uint16_t> m_pf2_rowscroll;
88 optional_device<decospr_device> m_sprgen;
89
90 void mjmux_w(uint16_t data);
91 uint16_t mjmux_r();
92 void okim1_rombank_w(uint16_t data);
93 void okim0_rombank_w(uint16_t data);
94 DECOSPR_PRIORITY_CB_MEMBER(pri_callback);
95
96 virtual void machine_start() override;
97 virtual void machine_reset() override;
98 virtual void video_start() override;
99 uint32_t screen_update_mirage(screen_device &screen, bitmap_rgb32 &bitmap, const rectangle &cliprect);
100 DECO16IC_BANK_CB_MEMBER(bank_callback);
101 void mirage_map(address_map &map);
102 };
103
video_start()104 void miragemj_state::video_start()
105 {
106 }
107
screen_update_mirage(screen_device & screen,bitmap_rgb32 & bitmap,const rectangle & cliprect)108 uint32_t miragemj_state::screen_update_mirage(screen_device &screen, bitmap_rgb32 &bitmap, const rectangle &cliprect)
109 {
110 uint16_t flip = m_deco_tilegen->pf_control_r(0);
111
112 flip_screen_set(BIT(flip, 7));
113 m_sprgen->set_flip_screen(BIT(flip, 7));
114
115 m_deco_tilegen->pf_update(m_pf1_rowscroll, m_pf2_rowscroll);
116
117 screen.priority().fill(0, cliprect);
118 bitmap.fill(256, cliprect); /* not verified */
119
120 m_deco_tilegen->tilemap_2_draw(screen, bitmap, cliprect, TILEMAP_DRAW_OPAQUE, 1);
121 m_deco_tilegen->tilemap_1_draw(screen, bitmap, cliprect, 0, 2);
122 m_sprgen->draw_sprites(bitmap, cliprect, m_spriteram->buffer(), 0x400);
123 return 0;
124 }
125
126
mjmux_w(uint16_t data)127 void miragemj_state::mjmux_w(uint16_t data)
128 {
129 m_mux_data = data & 0x1f;
130 }
131
mjmux_r()132 uint16_t miragemj_state::mjmux_r()
133 {
134 switch (m_mux_data & 0x1f)
135 {
136 case 0x01: return ioport("KEY0")->read();
137 case 0x02: return ioport("KEY1")->read();
138 case 0x04: return ioport("KEY2")->read();
139 case 0x08: return ioport("KEY3")->read();
140 case 0x10: return ioport("KEY4")->read();
141 }
142
143 return 0xffff;
144 }
145
okim1_rombank_w(uint16_t data)146 void miragemj_state::okim1_rombank_w(uint16_t data)
147 {
148 m_oki_sfx->set_rom_bank(data & 0x3);
149 }
150
okim0_rombank_w(uint16_t data)151 void miragemj_state::okim0_rombank_w(uint16_t data)
152 {
153 m_eeprom->clk_write(BIT(data, 5) ? ASSERT_LINE : CLEAR_LINE);
154 m_eeprom->di_write(BIT(data, 4));
155 m_eeprom->cs_write(BIT(data, 6) ? ASSERT_LINE : CLEAR_LINE);
156
157 /*bits 4-6 used on POST? */
158 m_oki_bgm->set_rom_bank(data & 0x7);
159 }
160
mirage_map(address_map & map)161 void miragemj_state::mirage_map(address_map &map)
162 {
163 map(0x000000, 0x07ffff).rom();
164 /* tilemaps */
165 map(0x100000, 0x101fff).rw(m_deco_tilegen, FUNC(deco16ic_device::pf1_data_r), FUNC(deco16ic_device::pf1_data_w)); // 0x100000 - 0x101fff tested
166 map(0x102000, 0x103fff).rw(m_deco_tilegen, FUNC(deco16ic_device::pf2_data_r), FUNC(deco16ic_device::pf2_data_w)); // 0x102000 - 0x102fff tested
167 /* linescroll */
168 map(0x110000, 0x110bff).ram().share("pf1_rowscroll");
169 map(0x112000, 0x112bff).ram().share("pf2_rowscroll");
170 map(0x120000, 0x1207ff).ram().share("spriteram");
171 map(0x130000, 0x1307ff).ram().w("palette", FUNC(palette_device::write16)).share("palette");
172 map(0x140000, 0x14000f).rw(m_oki_sfx, FUNC(okim6295_device::read), FUNC(okim6295_device::write)).umask16(0x00ff);
173 map(0x150000, 0x15000f).rw(m_oki_bgm, FUNC(okim6295_device::read), FUNC(okim6295_device::write)).umask16(0x00ff);
174 map(0x160000, 0x160001).nopw();
175 map(0x168000, 0x16800f).w(m_deco_tilegen, FUNC(deco16ic_device::pf_control_w));
176 map(0x16a000, 0x16a001).nopw();
177 map(0x16c000, 0x16c001).w(FUNC(miragemj_state::okim1_rombank_w));
178 map(0x16c002, 0x16c003).w(FUNC(miragemj_state::okim0_rombank_w));
179 map(0x16c004, 0x16c005).w(FUNC(miragemj_state::mjmux_w));
180 map(0x16c006, 0x16c007).r(FUNC(miragemj_state::mjmux_r));
181 map(0x16e000, 0x16e001).nopw();
182 map(0x16e002, 0x16e003).portr("SYSTEM_IN");
183 map(0x170000, 0x173fff).ram();
184 }
185
186
187 static INPUT_PORTS_START( mirage )
188 PORT_START("SYSTEM_IN")
189 PORT_BIT( 0x0001, IP_ACTIVE_LOW, IPT_SERVICE1 )
190 PORT_BIT( 0x0002, IP_ACTIVE_LOW, IPT_COIN1 )
191 PORT_BIT( 0x0004, IP_ACTIVE_LOW, IPT_COIN2 )
192 PORT_SERVICE( 0x0008, IP_ACTIVE_LOW )
193 PORT_BIT( 0x0010, IP_ACTIVE_HIGH, IPT_CUSTOM ) PORT_VBLANK("screen")
194 PORT_BIT( 0x0020, IP_ACTIVE_HIGH, IPT_CUSTOM ) PORT_READ_LINE_DEVICE_MEMBER("eeprom", eeprom_serial_93cxx_device, do_read)
195 PORT_BIT( 0xffc0, IP_ACTIVE_LOW, IPT_UNKNOWN )
196
197 PORT_START("KEY0")
198 PORT_BIT( 0x0001, IP_ACTIVE_LOW, IPT_MAHJONG_A )
199 PORT_BIT( 0x0002, IP_ACTIVE_LOW, IPT_MAHJONG_E )
200 PORT_BIT( 0x0004, IP_ACTIVE_LOW, IPT_MAHJONG_I )
201 PORT_BIT( 0x0008, IP_ACTIVE_LOW, IPT_MAHJONG_M )
202 PORT_BIT( 0x0010, IP_ACTIVE_LOW, IPT_MAHJONG_KAN )
203 PORT_BIT( 0x0020, IP_ACTIVE_LOW, IPT_START1 )
204 PORT_BIT( 0xffc0, IP_ACTIVE_LOW, IPT_UNUSED )
205
206 PORT_START("KEY1")
207 PORT_BIT( 0x0001, IP_ACTIVE_LOW, IPT_MAHJONG_C )
208 PORT_BIT( 0x0002, IP_ACTIVE_LOW, IPT_MAHJONG_G )
209 PORT_BIT( 0x0004, IP_ACTIVE_LOW, IPT_MAHJONG_K )
210 PORT_BIT( 0x0008, IP_ACTIVE_LOW, IPT_MAHJONG_CHI )
211 PORT_BIT( 0x0010, IP_ACTIVE_LOW, IPT_MAHJONG_RON )
212 PORT_BIT( 0xffe0, IP_ACTIVE_LOW, IPT_UNUSED )
213
214 PORT_START("KEY2")
215 PORT_BIT( 0x0008, IP_ACTIVE_LOW, IPT_MAHJONG_FLIP_FLOP )
216 PORT_BIT( 0xfff7, IP_ACTIVE_LOW, IPT_UNUSED )
217
218 PORT_START("KEY3")
219 PORT_BIT( 0x0001, IP_ACTIVE_LOW, IPT_MAHJONG_B )
220 PORT_BIT( 0x0002, IP_ACTIVE_LOW, IPT_MAHJONG_F )
221 PORT_BIT( 0x0004, IP_ACTIVE_LOW, IPT_MAHJONG_J )
222 PORT_BIT( 0x0008, IP_ACTIVE_LOW, IPT_MAHJONG_N )
223 PORT_BIT( 0x0010, IP_ACTIVE_LOW, IPT_MAHJONG_REACH )
224 PORT_BIT( 0xffe0, IP_ACTIVE_LOW, IPT_UNUSED )
225
226 PORT_START("KEY4")
227 PORT_BIT( 0x0001, IP_ACTIVE_LOW, IPT_MAHJONG_D )
228 PORT_BIT( 0x0002, IP_ACTIVE_LOW, IPT_MAHJONG_H )
229 PORT_BIT( 0x0004, IP_ACTIVE_LOW, IPT_MAHJONG_L )
230 PORT_BIT( 0x0008, IP_ACTIVE_LOW, IPT_MAHJONG_PON )
231 PORT_BIT( 0xfff0, IP_ACTIVE_LOW, IPT_UNUSED )
232 INPUT_PORTS_END
233
234
235 static const gfx_layout tile_8x8_layout =
236 {
237 8,8,
238 RGN_FRAC(1,2),
239 4,
240 { RGN_FRAC(1,2)+8,RGN_FRAC(1,2)+0,RGN_FRAC(0,2)+8,RGN_FRAC(0,2)+0 },
241 { STEP8(0,1) },
242 { STEP8(0,8*2) },
243 8*16
244 };
245
246 static const gfx_layout tile_16x16_layout =
247 {
248 16,16,
249 RGN_FRAC(1,2),
250 4,
251 { RGN_FRAC(1,2)+8,RGN_FRAC(1,2)+0,RGN_FRAC(0,2)+8,RGN_FRAC(0,2)+0 },
252 { STEP8(8*2*16,1),STEP8(0,1) },
253 { STEP16(0,8*2) },
254 32*16
255 };
256
257 static GFXDECODE_START( gfx_mirage )
258 GFXDECODE_ENTRY("gfx1", 0, tile_8x8_layout, 0x000, 32) /* Tiles (8x8) */
259 GFXDECODE_ENTRY("gfx1", 0, tile_16x16_layout, 0x000, 32) /* Tiles (16x16) */
260 GFXDECODE_ENTRY("gfx2", 0, tile_16x16_layout, 0x200, 32) /* Sprites (16x16) */
261 GFXDECODE_END
262
263
DECOSPR_PRIORITY_CB_MEMBER(miragemj_state::pri_callback)264 DECOSPR_PRIORITY_CB_MEMBER(miragemj_state::pri_callback)
265 {
266 u32 mask = 0; // above everything
267 if (extpri)
268 mask |= GFX_PMASK_2; // under the uppermost playfield
269
270 return mask;
271 }
272
DECO16IC_BANK_CB_MEMBER(miragemj_state::bank_callback)273 DECO16IC_BANK_CB_MEMBER(miragemj_state::bank_callback)
274 {
275 return ((bank >> 4) & 0x7) * 0x1000;
276 }
277
machine_start()278 void miragemj_state::machine_start()
279 {
280 save_item(NAME(m_mux_data));
281 }
282
machine_reset()283 void miragemj_state::machine_reset()
284 {
285 m_mux_data = 0;
286 }
287
mirage(machine_config & config)288 void miragemj_state::mirage(machine_config &config)
289 {
290 /* basic machine hardware */
291 M68000(config, m_maincpu, 28000000/2);
292 m_maincpu->set_addrmap(AS_PROGRAM, &miragemj_state::mirage_map);
293 m_maincpu->set_vblank_int("screen", FUNC(miragemj_state::irq6_line_hold));
294
295 EEPROM_93C46_16BIT(config, "eeprom"); // 93C45
296
297 /* video hardware */
298 BUFFERED_SPRITERAM16(config, m_spriteram);
299
300 screen_device &screen(SCREEN(config, "screen", SCREEN_TYPE_RASTER));
301 screen.set_refresh_hz(58);
302 screen.set_vblank_time(ATTOSECONDS_IN_USEC(529));
303 screen.set_size(40*8, 32*8);
304 screen.set_visarea(0*8, 40*8-1, 1*8, 31*8-1);
305 screen.set_screen_update(FUNC(miragemj_state::screen_update_mirage));
306 screen.screen_vblank().set(m_spriteram, FUNC(buffered_spriteram16_device::vblank_copy_rising));
307
308 GFXDECODE(config, "gfxdecode", "palette", gfx_mirage);
309 PALETTE(config, "palette").set_format(palette_device::xBGR_555, 1024);
310
311 DECO16IC(config, m_deco_tilegen, 0);
312 m_deco_tilegen->set_pf1_size(DECO_64x32);
313 m_deco_tilegen->set_pf2_size(DECO_64x32);
314 m_deco_tilegen->set_pf1_col_bank(0x00);
315 m_deco_tilegen->set_pf2_col_bank(0x10);
316 m_deco_tilegen->set_pf1_col_mask(0x0f);
317 m_deco_tilegen->set_pf2_col_mask(0x0f);
318 m_deco_tilegen->set_bank1_callback(FUNC(miragemj_state::bank_callback));
319 m_deco_tilegen->set_bank2_callback(FUNC(miragemj_state::bank_callback));
320 m_deco_tilegen->set_pf12_8x8_bank(0);
321 m_deco_tilegen->set_pf12_16x16_bank(1);
322 m_deco_tilegen->set_gfxdecode_tag("gfxdecode");
323
324 DECO_SPRITE(config, m_sprgen, 0);
325 m_sprgen->set_gfx_region(2);
326 m_sprgen->set_pri_callback(FUNC(miragemj_state::pri_callback));
327 m_sprgen->set_gfxdecode_tag("gfxdecode");
328
329 /* sound hardware */
330 SPEAKER(config, "mono").front_center();
331
332 OKIM6295(config, m_oki_bgm, 2000000, okim6295_device::PIN7_HIGH).add_route(ALL_OUTPUTS, "mono", 0.30); // clock frequency & pin 7 not verified
333
334 OKIM6295(config, m_oki_sfx, 1000000, okim6295_device::PIN7_HIGH).add_route(ALL_OUTPUTS, "mono", 0.70); // clock frequency & pin 7 not verified
335 }
336
337
338 ROM_START( mirage )
339 ROM_REGION( 0x80000, "maincpu", 0 ) /* 68000 code */
340 ROM_LOAD16_BYTE( "mr_00-.2a", 0x00000, 0x40000, CRC(3a53f33d) SHA1(0f654021dcd64202b41e0ef5ef3cdf5dd274f8a5) )
CRC(a0b758aa)341 ROM_LOAD16_BYTE( "mr_01-.3a", 0x00001, 0x40000, CRC(a0b758aa) SHA1(7fb5faf6fb57cd72a3ac24b8af1f33e504ac8398) )
342
343 ROM_REGION( 0x100000, "gfx1", 0 ) /* Tiles - Encrypted */
344 ROM_LOAD( "mbl-00.7a", 0x000000, 0x100000, CRC(2e258b7b) SHA1(2dbd7d16a1eda97ae3de149b67e80e511aa9d0ba) )
345
346 ROM_REGION( 0x400000, "gfx2", 0 ) /* Sprites */
347 ROM_LOAD( "mbl-01.11a", 0x200000, 0x200000, CRC(895be69a) SHA1(541d8f37fb4cf99312b80a0eb0d729fbbeab5f4f) )
348 ROM_LOAD( "mbl-02.12a", 0x000000, 0x200000, CRC(474f6104) SHA1(ff81b32b90192c3d5f27c436a9246aa6caaeeeee) )
349
350 ROM_REGION( 0x200000, "oki_bgm_data", 0 )
351 ROM_LOAD( "mbl-03.10a", 0x000000, 0x200000, CRC(4a599703) SHA1(b49e84faa2d6acca952740d30fc8d1a33ac47e79) )
352
353 ROM_REGION( 0x200000, "oki_bgm", 0 )
354 ROM_COPY( "oki_bgm_data", 0x000000, 0x000000, 0x080000 )
355 ROM_COPY( "oki_bgm_data", 0x100000, 0x080000, 0x080000 ) // - banks 2,3 and 4,5 are swapped, PAL address shuffle
356 ROM_COPY( "oki_bgm_data", 0x080000, 0x100000, 0x080000 ) // /
357 ROM_COPY( "oki_bgm_data", 0x180000, 0x180000, 0x080000 )
358
359 ROM_REGION( 0x100000, "oki_sfx", 0 ) /* M6295 samples */
360 ROM_LOAD( "mbl-04.12k", 0x000000, 0x100000, CRC(b533123d) SHA1(2cb2f11331d00c2d282113932ed2836805f4fc6e) )
361 ROM_END
362
363 void miragemj_state::init_mirage()
364 {
365 deco56_decrypt_gfx(machine(), "gfx1");
366 }
367
368 GAME( 1994, mirage, 0, mirage, mirage, miragemj_state, init_mirage, ROT0, "Mitchell", "Mirage Youjuu Mahjongden (Japan)", MACHINE_SUPPORTS_SAVE )
369