1 /*
2 ***********************************************************************************
3 Dark Mist (c)1986  Taito / Seibu
4 driver by
5   David Haywood
6   Nicola Salmoria
7   Tomasz Slanina
8 Main CPU : z80 (with encryption, external to z80)
9 Sound CPU: custom T5182 cpu (like seibu sound system but with internal code)
10 $e000 - coins (two bytes)
11 $e2b7 - player 1 energy
12 TODO:
13  - sprite/bg and sprite/sprite priorities (name entry screen, player on raft)
14  - cocktail mode
15  - unknown bit in sprite attr (there's code used for OR-ing sprite attrib with some
16    value (taken from ram) when one of coords is greater than 256-16 )
17 ***********************************************************************************
18 */
19 
20 #include "driver.h"
21 #include "sndhrdw/t5182.h"
22 #include "vidhrdw/generic.h"
23 #include "decocrpt.h"
24 
25 #define XTAL1  14318180
26 #define XTAL2  18432000
27 #define XTAL3  12000000
28 
29 #define CPU_CLOCK   (XTAL3/2)
30 #define T5182_CLOCK (XTAL1/4)
31 #define YM_CLOCK    (XTAL1/4)
32 
33 READ_HANDLER(darkmist_palette_r);
34 WRITE_HANDLER(darkmist_palette_w);
35 WRITE_HANDLER(darkmist_spritebank_w);
36 VIDEO_START(darkmist);
37 VIDEO_UPDATE(darkmist);
38 PALETTE_INIT(darkmist);
39 
40 unsigned char * darkmist_scroll;
41 unsigned char * darkmist_workram;
42 
43 int darkmist_hw;
44 static int coin_stat=0;
45 
WRITE_HANDLER(darkmist_hw_w)46 static WRITE_HANDLER(darkmist_hw_w)
47 {
48   darkmist_hw=data;
49   cpu_setbank(1,&memory_region(REGION_CPU1)[0x010000+((data&0x80)?0x4000:0)]);
50 }
51 
52 
darkmist_coin_hack(void)53 static void darkmist_coin_hack(void)
54 {
55 
56 	if(input_port_6_r(0)&1)
57 	{
58 		if(coin_stat==0)
59 		{
60 			coin_stat=1;
61 			if(darkmist_workram[0]<9)
62 			{
63 				darkmist_workram[0]++;
64 			}
65 			else
66 			{
67 				if(darkmist_workram[1]<9)
68 				{
69 					darkmist_workram[0]=0;
70 					darkmist_workram[1]++;
71 				}
72 			}
73 		}
74 	}
75 	else
76 	{
77 		coin_stat=0;
78 	}
79 }
80 
81 
82 
MEMORY_READ_START(readmem)83 static MEMORY_READ_START( readmem )
84     { 0x0000, 0x7fff, MRA_ROM },
85 	{ 0x8000, 0xbfff, MRA_BANK1 },
86 	{ 0xc801, 0xc801, input_port_0_r },
87 	{ 0xc802, 0xc802, input_port_1_r },
88 	{ 0xc803, 0xc803, input_port_2_r },
89 	{ 0xc806, 0xc806, input_port_3_r },
90 	{ 0xc807, 0xc807, input_port_4_r },
91 	{ 0xc808, 0xc808, input_port_5_r },
92 	{ 0xd000, 0xd3ff, darkmist_palette_r },
93 	{ 0xd400, 0xd41f, MRA_RAM },
94 	{ 0xd600, 0xd67f, t5182shared_r },
95 	{ 0xd681, 0xd681, t5182_sharedram_semaphore_snd_r },
96 	{ 0xd800, 0xdfff, MRA_RAM },
97 	{ 0xe000, 0xefff, MRA_RAM },
98 	{ 0xf000, 0xffff, MRA_RAM },
99 MEMORY_END
100 
101 static MEMORY_WRITE_START( writemem )
102     { 0x0000, 0x7fff, MWA_ROM },
103 	{ 0xc804, 0xc804, darkmist_hw_w },
104 	{ 0xc805, 0xc805, darkmist_spritebank_w },
105 	{ 0xd000, 0xd3ff, darkmist_palette_w, &paletteram },
106 	{ 0xd400, 0xd41f, MWA_RAM, &darkmist_scroll },
107 	{ 0xd600, 0xd67f, t5182shared_w },
108 	{ 0xd680, 0xd680, t5182_sound_irq_w },
109 	{ 0xd682, 0xd682, t5182_sharedram_semaphore_main_acquire_w },
110 	{ 0xd683, 0xd683, t5182_sharedram_semaphore_main_release_w },
111 	{ 0xd800, 0xdfff, MWA_RAM, &videoram },
112 	{ 0xe000, 0xefff, MWA_RAM, &darkmist_workram },
113 	{ 0xf000, 0xffff, MWA_RAM, &spriteram, &spriteram_size },
114 MEMORY_END
115 
116 
117 INPUT_PORTS_START( darkmist )
118 	PORT_START
119 	PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_JOYSTICK_UP | IPF_8WAY )
120 	PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN | IPF_8WAY )
121 	PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT | IPF_8WAY )
122 	PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT | IPF_8WAY )
123 	PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_BUTTON1 )
124 	PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_BUTTON2 )
125 	PORT_BIT( 0xc0, IP_ACTIVE_LOW, IPT_UNKNOWN )
126 
127 	PORT_START
128 	PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_JOYSTICK_UP | IPF_8WAY| IPF_COCKTAIL )
129 	PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN | IPF_8WAY| IPF_COCKTAIL )
130 	PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT | IPF_8WAY| IPF_COCKTAIL )
131 	PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT | IPF_8WAY| IPF_COCKTAIL )
132 	PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_BUTTON1| IPF_COCKTAIL )
133 	PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_BUTTON2| IPF_COCKTAIL )
134 	PORT_BIT( 0xc0, IP_ACTIVE_LOW, IPT_UNKNOWN )
135 
136 	PORT_START
137 	PORT_DIPNAME( 0x01, 0x01, "2-0" )
138 	PORT_DIPSETTING(    0x01, DEF_STR( No ) )
139 	PORT_DIPSETTING(    0x00, DEF_STR( Yes ) )
140 	PORT_DIPNAME( 0x02, 0x02, "2-1" )
141 	PORT_DIPSETTING(    0x02, DEF_STR( No ) )
142 	PORT_DIPSETTING(    0x00, DEF_STR( Yes ) )
143 	PORT_DIPNAME( 0x04, 0x04, "2-2" )
144 	PORT_DIPSETTING(    0x04, DEF_STR( No ) )
145 	PORT_DIPSETTING(    0x00, DEF_STR( Yes ) )
146 	PORT_BIT_IMPULSE( 0x08, IP_ACTIVE_LOW, IPT_START1, 1 )
147 	PORT_BIT_IMPULSE( 0x10, IP_ACTIVE_LOW, IPT_START2, 1 )
148 	PORT_DIPNAME( 0x20, 0x20, "2-5" )
149 	PORT_DIPSETTING(    0x20, DEF_STR( No ) )
150 	PORT_DIPSETTING(    0x00, DEF_STR( Yes ) )
151 	PORT_DIPNAME( 0x40, 0x40, "2-6" )
152 	PORT_DIPSETTING(    0x40, DEF_STR( No ) )
153 	PORT_DIPSETTING(    0x00, DEF_STR( Yes ) )
154 	PORT_DIPNAME( 0x80, 0x80, "2-7" )
155 	PORT_DIPSETTING(    0x80, DEF_STR( No ) )
156 	PORT_DIPSETTING(    0x00, DEF_STR( Yes ) )
157 
158 	PORT_START
159 	PORT_DIPNAME( 0x07, 0x07, DEF_STR( Coin_A ) )
160 	PORT_DIPSETTING(    0x00, DEF_STR( 5C_1C ) )
161 	PORT_DIPSETTING(    0x04, DEF_STR( 4C_1C ) )
162 	PORT_DIPSETTING(    0x02, DEF_STR( 3C_1C ) )
163 	PORT_DIPSETTING(    0x06, DEF_STR( 2C_1C ) )
164 	PORT_DIPSETTING(    0x07, DEF_STR( 1C_1C ) )
165 	PORT_DIPSETTING(    0x03, DEF_STR( 1C_2C ) )
166 	PORT_DIPSETTING(    0x05, DEF_STR( 1C_3C ) )
167 	PORT_DIPSETTING(    0x01, DEF_STR( 1C_5C ) )
168 	PORT_DIPNAME( 0x18, 0x18, DEF_STR( Coin_B ) )
169 	PORT_DIPSETTING(    0x10, DEF_STR( 2C_1C ) )
170 	PORT_DIPSETTING(    0x18, DEF_STR( 1C_1C ) )
171 	PORT_DIPSETTING(    0x00, DEF_STR( 2C_3C ) )
172 	PORT_DIPSETTING(    0x08, DEF_STR( 1C_2C ) )
173 	PORT_SERVICE( 0x20, IP_ACTIVE_LOW)
174 	PORT_DIPNAME( 0x40, 0x40, DEF_STR( Unknown ) )	/* Listed as "ALWAYS ON" */
175 	PORT_DIPSETTING(    0x40, DEF_STR( Off ) )
176 	PORT_DIPSETTING(    0x00, DEF_STR( On ) )
177 	PORT_DIPNAME( 0x80, 0x80, DEF_STR( Free_Play ) )
178 	PORT_DIPSETTING(    0x80, DEF_STR( No ) )
179 	PORT_DIPSETTING(    0x00, DEF_STR( Yes ) )
180 
181 	PORT_START
182 	PORT_DIPNAME( 0x01, 0x01, DEF_STR( Cabinet ) )
183 	PORT_DIPSETTING(    0x01, DEF_STR( Upright ) )
184 	PORT_DIPSETTING(    0x00, DEF_STR( Cocktail ) )
185 	PORT_DIPNAME( 0x06, 0x06, DEF_STR( Difficulty ) )
186 	PORT_DIPSETTING(    0x06, "Easy" )
187 	PORT_DIPSETTING(    0x04, "Normal" )
188 	PORT_DIPSETTING(    0x02, "Hard" )
189 	PORT_DIPSETTING(    0x00, "Hardest" )
190 	PORT_DIPNAME( 0x18, 0x08, DEF_STR( Lives ) )
191 	PORT_DIPSETTING(    0x18, "1" )
192 	PORT_DIPSETTING(    0x10, "2" )
193 	PORT_DIPSETTING(    0x08, "3" )
194 	PORT_DIPSETTING(    0x00, "4" )
195 	PORT_DIPNAME( 0x60, 0x60, DEF_STR( Bonus_Life ) )
196 	PORT_DIPSETTING(    0x20, "10K / 20K" )
197 	PORT_DIPSETTING(    0x60, "20K / 40K" )
198 	PORT_DIPSETTING(    0x40, "30K / 60K" )
199 	PORT_DIPSETTING(    0x00, "40K / 80K" )
200 	PORT_DIPNAME( 0x80, 0x00, DEF_STR( Demo_Sounds ) )
201 	PORT_DIPSETTING(    0x80, DEF_STR( Off ) )
202 	PORT_DIPSETTING(    0x00, DEF_STR( On ) )
203 
204 
205 	PORT_START
206 	PORT_DIPNAME( 0x01, 0x01, "5-0" )
207 	PORT_DIPSETTING(    0x01, DEF_STR( No ) )
208 	PORT_DIPSETTING(    0x00, DEF_STR( Yes ) )
209 	PORT_DIPNAME( 0x02, 0x02, "5-1" )
210 	PORT_DIPSETTING(    0x02, DEF_STR( No ) )
211 	PORT_DIPSETTING(    0x00, DEF_STR( Yes ) )
212 	PORT_DIPNAME( 0x04, 0x04, "5-2" )
213 	PORT_DIPSETTING(    0x04, DEF_STR( No ) )
214 	PORT_DIPSETTING(    0x00, DEF_STR( Yes ) )
215 	PORT_DIPNAME( 0x08, 0x08, "5-3" )
216 	PORT_DIPSETTING(    0x08, DEF_STR( No ) )
217 	PORT_DIPSETTING(    0x00, DEF_STR( Yes ) )
218 	PORT_DIPNAME( 0x10, 0x10, "5-4" )
219 	PORT_DIPSETTING(    0x10, DEF_STR( No ) )
220 	PORT_DIPSETTING(    0x00, DEF_STR( Yes ) )
221 	PORT_DIPNAME( 0x20, 0x20, "5-5" )
222 	PORT_DIPSETTING(    0x20, DEF_STR( No ) )
223 	PORT_DIPSETTING(    0x00, DEF_STR( Yes ) )
224 	PORT_DIPNAME( 0x40, 0x40, "5-6" )
225 	PORT_DIPSETTING(    0x40, DEF_STR( No ) )
226 	PORT_DIPSETTING(    0x00, DEF_STR( Yes ) )
227 	PORT_DIPNAME( 0x80, 0x80, "5-7" )
228 	PORT_DIPSETTING(    0x80, DEF_STR( No ) )
229 	PORT_DIPSETTING(    0x00, DEF_STR( Yes ) )
230 
231 	PORT_START /* fake port */
232 	PORT_BIT_IMPULSE( 0x01, IP_ACTIVE_HIGH, IPT_COIN1, 1 )
233 
234 INPUT_PORTS_END
235 
236 
237 static struct GfxLayout charlayout =
238 {
239 	8,8,
240 	RGN_FRAC(1,2),
241 	4,
242 	{ 0, 4, RGN_FRAC(1,2)+0, RGN_FRAC(1,2)+4 },
243 
244 	{ 0, 1, 2, 3, 8+0, 8+1, 8+2, 8+3 },
245 	{ 0*16, 1*16, 2*16, 3*16, 4*16, 5*16, 6*16, 7*16 },
246 	16*8
247 };
248 
249 static struct GfxLayout tilelayout =
250 {
251 	16,16,
252 	RGN_FRAC(1,2),
253 	4,
254 	{ 0, 4, RGN_FRAC(1,2)+0, RGN_FRAC(1,2)+4 },
255 
256 
257 	{ 0, 1, 2, 3, 8+0, 8+1, 8+2, 8+3,
258 			16+0, 16+1, 16+2, 16+3, 24+0, 24+1, 24+2, 24+3 },
259 	{ 0*32, 1*32, 2*32, 3*32, 4*32, 5*32, 6*32, 7*32,
260 			8*32, 9*32, 10*32, 11*32, 12*32, 13*32, 14*32, 15*32 },
261 	32*16
262 };
263 
264 
265 static struct GfxDecodeInfo gfxdecodeinfo[] =
266 {
267 	{ REGION_GFX1, 0, &charlayout,  0, 16*4 },
268 	{ REGION_GFX2, 0, &tilelayout,  0, 16*4 },
269 	{ REGION_GFX3, 0, &tilelayout,  0, 16*4 },
270 	{ -1 }
271 };
272 
INTERRUPT_GEN(darkmist_interrupt)273 INTERRUPT_GEN( darkmist_interrupt )
274 {
275 	if(cpu_getiloops())
276 	{
277 	  cpu_set_irq_line_and_vector(0, 0, HOLD_LINE, 0x08);
278 	}
279 	else
280 	{
281       cpu_set_irq_line_and_vector(0, 0, HOLD_LINE, 0x10);
282 	}
283 
284 	darkmist_coin_hack();
285 }
286 
287 static MACHINE_DRIVER_START( darkmist )
288 	/* basic machine hardware */
289 	MDRV_CPU_ADD(Z80,4000000)		 /* ? MHz */
MDRV_CPU_MEMORY(readmem,writemem)290 	MDRV_CPU_MEMORY(readmem, writemem)
291 	MDRV_CPU_VBLANK_INT(darkmist_interrupt,2)
292 
293 	MDRV_FRAMES_PER_SECOND(60)
294 	MDRV_VBLANK_DURATION(DEFAULT_60HZ_VBLANK_DURATION)
295 
296 	/* video hardware */
297 	MDRV_VIDEO_ATTRIBUTES(VIDEO_TYPE_RASTER )
298 	MDRV_SCREEN_SIZE(256, 256)
299 	MDRV_VISIBLE_AREA(0, 256-1, 16, 256-16-1)
300 	MDRV_GFXDECODE(gfxdecodeinfo)
301 	MDRV_PALETTE_LENGTH(0x100+1)
302 	MDRV_PALETTE_INIT(darkmist)
303 	MDRV_COLORTABLE_LENGTH(0x100*4)
304 	MDRV_VIDEO_START(darkmist)
305 	MDRV_VIDEO_UPDATE(darkmist)
306 
307     MDRV_IMPORT_FROM(t5182_audio)
308 MACHINE_DRIVER_END
309 
310 ROM_START( darkmist )
311 	ROM_REGION( 0x18000, REGION_CPU1, 0 )
312 	ROM_LOAD( "dm_15.rom", 0x00000, 0x08000, CRC(21e6503c) SHA1(09174fb424b76f7f2a381297e3420ddd2e76b008) )
313 
314 	ROM_LOAD( "dm_16.rom", 0x10000, 0x08000, CRC(094579d9) SHA1(2449bc9ba38396912ee9b72dd870ea9fcff95776) )
315 
316 	ROM_REGION( 0x10000, REGION_CPU2, 0 ) /* Toshiba T5182 module */
317 	ROM_LOAD( "t5182.rom", 0x0000, 0x2000, CRC(d354c8fc) SHA1(a1c9e1ac293f107f69cc5788cf6abc3db1646e33) )
318 	ROM_LOAD( "dm_17.rom", 0x8000, 0x8000, CRC(7723dcae) SHA1(a0c69e7a7b6fd74f7ed6b9c6419aed94aabcd4b0) )
319 
320 	ROM_REGION( 0x4000, REGION_GFX1, 0 )
321 	ROM_LOAD( "dm_13.rom", 0x00000, 0x02000, CRC(38bb38d9) SHA1(d751990166dd3d503c5de7667679b96210061cd1) )
322 	ROM_LOAD( "dm_14.rom", 0x02000, 0x02000, CRC(ac5a31f3) SHA1(79083390671062be2eab93cc875a0f86d709a963) )
323 
324 	ROM_REGION( 0x40000, REGION_GFX2, 0 )
325 	ROM_LOAD( "dm_05.rom", 0x10000, 0x10000, CRC(ca79a738) SHA1(66a76ea0d8ecc44f6cc77102303df74f40bf6118) )
326 	ROM_LOAD( "dm_01.rom", 0x00000, 0x10000, CRC(652aee6b) SHA1(f4150784f7bd7be83a0041e4c52540aa564062ba) )
327 	ROM_LOAD( "dm_06.rom", 0x30000, 0x10000, CRC(9629ed2c) SHA1(453f6a0b12efdadd7fcbe03ad37afb0afa6be051) )
328 	ROM_LOAD( "dm_02.rom", 0x20000, 0x10000, CRC(e2dd15aa) SHA1(1f3a6a1e1afabfe9dc47549ef13ae7696302ae88) )
329 
330 	ROM_REGION( 0x40000, REGION_GFX3, 0)
331 	ROM_LOAD( "dm_09.rom", 0x00000, 0x10000, CRC(52154b50) SHA1(5ee1a4bcf0752a057b9993b0069d744c35cf55f4) )
332 	ROM_LOAD( "dm_11.rom", 0x10000, 0x08000, CRC(3118e2f9) SHA1(dfd946ea1310851f97d31ce58d8280f2d92b0f59) )
333 	ROM_LOAD( "dm_10.rom", 0x20000, 0x10000, CRC(34fd52b5) SHA1(c4ee464ed79ec91f993b0f894572c0288f0ad1d4) )
334 	ROM_LOAD( "dm_12.rom", 0x30000, 0x08000, CRC(cc4b9839) SHA1(b7e95513d2e06929fed5005caf3bf8c3fba0b597) )
335 
336 	ROM_REGION( 0x8000, REGION_USER1, 0 )
337 	/* BG layer map ( 512x64 )*/
338 	ROM_LOAD( "dm_03.rom", 0x00000, 0x08000, CRC(60b40c2a) SHA1(c046273b15dab95ea4851c26ce941e580fa1b6ec) )
339 
340 	ROM_REGION( 0x8000, REGION_USER2, 0 )
341 	/* BG layer attr ( 512x64 ) */
342 	ROM_LOAD( "dm_04.rom", 0x00000, 0x08000, CRC(d47b8cd9) SHA1(86eb7a5d8ea63c0c91f455b1b8322cc7b9c4a968) )
343 
344 	ROM_REGION( 0x04000, REGION_USER3, 0 )
345 	/* FG layer map ( 64x256 ) */
346 	ROM_LOAD( "dm_07.rom", 0x00000, 0x04000, CRC(889b1277) SHA1(78405110b9cf1ab988c0cbfdb668498dadb41229) )
347 
348 	ROM_REGION( 0x04000, REGION_USER4, 0 )
349 	/* FG layer attr ( 64x256 ) */
350 	ROM_LOAD( "dm_08.rom", 0x00000, 0x04000, CRC(f76f6f46) SHA1(ce1c67dc8976106b24fee8d3a0b9e5deb016a327) )
351 
352 	ROM_REGION( 0x0600, REGION_PROMS, 0 )
353 	/* color lookup tables */
354 	ROM_LOAD( "63s281n.m7",  0x0000, 0x0100, CRC(897ef49f) SHA1(e40c0fb0a68aa91ceaee86e774a428819a4794bb) )
355 	ROM_LOAD( "63s281n.d7",  0x0100, 0x0100, CRC(a9975a96) SHA1(3a34569fc68ac15f91e1e90d4e273f844b315091) )
356 	ROM_LOAD( "63s281n.f11", 0x0200, 0x0100, CRC(8096b206) SHA1(257004aa3501121d058afa6f64b1129303246758) )
357 	ROM_LOAD( "63s281n.j15", 0x0300, 0x0100, CRC(2ea780a4) SHA1(0f8d6791114705e9982f9035f291d2a305b47f0a) )
358 	/* unknown */
359 	ROM_LOAD( "63s281n.l1",  0x0400, 0x0100, CRC(208d17ca) SHA1(a77d56337bcac8d9a7bc3411239dfb3045e069ec) )
360 	ROM_LOAD( "82s129.d11",  0x0500, 0x0100, CRC(866eab0e) SHA1(398ffe2b82b6e2235746fd987d5f5995d7dc8687) )
361 ROM_END
362 
363 
364 static void decrypt_gfx(void)
365 {
366 	UINT8 *buf = malloc(0x40000);
367 	UINT8 *rom;
368 	int size;
369 	int i;
370 
371 	rom = memory_region(REGION_GFX1);
372 	size = memory_region_length(REGION_GFX1);
373 
374 	/* data lines */
375 	for (i = 0;i < size/2;i++)
376 	{
377 		int w1;
378 
379 		w1 = (rom[i + 0*size/2] << 8) + rom[i + 1*size/2];
380 
381 		w1 = BITSWAP16(w1, 9,14,7,2, 6,8,3,15,  10,13,5,12,  0,11,4,1);
382 
383 		buf[i + 0*size/2] = w1 >> 8;
384 		buf[i + 1*size/2] = w1 & 0xff;
385 	}
386 
387 	/* address lines */
388 	for (i = 0;i < size;i++)
389 	{
390 		rom[i] = buf[BITSWAP24(i,23,22,21,20,19,18,17,16,15,14,13,12, 3,2,1, 11,10,9,8, 0, 7,6,5,4)];
391 	}
392 
393 
394 	rom = memory_region(REGION_GFX2);
395 	size = memory_region_length(REGION_GFX2);
396 
397 	/* data lines */
398 	for (i = 0;i < size/2;i++)
399 	{
400 		int w1;
401 
402 		w1 = (rom[i + 0*size/2] << 8) + rom[i + 1*size/2];
403 
404 		w1 = BITSWAP16(w1, 9,14,7,2, 6,8,3,15,  10,13,5,12,  0,11,4,1);
405 
406 		buf[i + 0*size/2] = w1 >> 8;
407 		buf[i + 1*size/2] = w1 & 0xff;
408 	}
409 
410 	/* address lines */
411 	for (i = 0;i < size;i++)
412 	{
413 		rom[i] = buf[BITSWAP24(i,23,22,21,20,19,18,17,16,15,14,13, 5,4,3,2, 12,11,10,9,8, 1,0, 7,6)];
414 	}
415 
416 
417 	rom = memory_region(REGION_GFX3);
418 	size = memory_region_length(REGION_GFX3);
419 
420 	/* data lines */
421 	for (i = 0;i < size/2;i++)
422 	{
423 		int w1;
424 
425 		w1 = (rom[i + 0*size/2] << 8) + rom[i + 1*size/2];
426 
427 		w1 = BITSWAP16(w1, 9,14,7,2, 6,8,3,15,  10,13,5,12,  0,11,4,1);
428 
429 		buf[i + 0*size/2] = w1 >> 8;
430 		buf[i + 1*size/2] = w1 & 0xff;
431 	}
432 
433 	/* address lines */
434 	for (i = 0;i < size;i++)
435 	{
436 		rom[i] = buf[BITSWAP24(i, 23,22,21,20,19,18,17,16,15,14, 12,11,10,9,8, 5,4,3, 13, 7,6, 1,0, 2)];
437 	}
438 
439 	free(buf);
440 }
441 
decrypt_snd(void)442 static void decrypt_snd(void)
443 {
444 	int i;
445 	unsigned char *ROM = memory_region(REGION_CPU2);
446 
447 	for(i=0x8000;i<0x10000;i++)
448 		ROM[i] = BITSWAP8(ROM[i], 7,1,2,3,4,5,6,0);
449 }
450 
451 
DRIVER_INIT(darkmist)452 static DRIVER_INIT(darkmist)
453 {
454 	int i;
455 	unsigned char *ROM = memory_region(REGION_CPU1);
456 	UINT8 *buffer = malloc(0x10000);
457 	UINT8 *decrypt = auto_malloc(0x8000);
458 
459 	decrypt_gfx();
460 
461 	decrypt_snd();
462 
463 	for(i=0;i<0x8000;i++)
464 	{
465 		UINT8 p, d;
466 		p = d = memory_region(REGION_CPU1)[i];
467 
468 		if(((i & 0x20) == 0x00) && ((i & 0x8) != 0))
469 			p ^= 0x20;
470 
471 		if(((i & 0x20) == 0x00) && ((i & 0xa) != 0))
472 			d ^= 0x20;
473 
474 		if(((i & 0x200) == 0x200) && ((i & 0x408) != 0))
475 			p ^= 0x10;
476 
477 		if((i & 0x220) != 0x200)
478 		{
479 			p = BITSWAP8(p, 7,6,5,2,3,4,1,0);
480 			d = BITSWAP8(d, 7,6,5,2,3,4,1,0);
481 		}
482 
483 		memory_region(REGION_CPU1)[i] = d;
484 		decrypt[i] = p;
485 	}
486 
487 
488 	memory_set_opcode_base(0,decrypt);
489 	cpu_setbank(1,&ROM[0x010000]);
490 
491 	/* adr line swaps */
492 	ROM = memory_region(REGION_USER1);
493 	memcpy( buffer, ROM, memory_region_length(REGION_USER1) );
494 
495 	for(i=0;i<memory_region_length(REGION_USER1);i++)
496 	{
497 		ROM[i]=buffer[BITSWAP24(i,23,22,21,20,19,18,17,16,15,6,5,4,3,2,14,13,12,11,8,7,1,0,10,9)];
498 	}
499 
500 	ROM = memory_region(REGION_USER2);
501 	memcpy( buffer, ROM, memory_region_length(REGION_USER2) );
502 	for(i=0;i<memory_region_length(REGION_USER2);i++)
503 	{
504 		ROM[i]=buffer[BITSWAP24(i,23,22,21,20,19,18,17,16,15,6,5,4,3,2,14,13,12,11,8,7,1,0,10,9)];
505 	}
506 
507 	ROM = memory_region(REGION_USER3);
508 	memcpy( buffer, ROM, memory_region_length(REGION_USER3) );
509 	for(i=0;i<memory_region_length(REGION_USER3);i++)
510 	{
511 		ROM[i]=buffer[BITSWAP24(i,23,22,21,20,19,18,17,16,15,14 ,5,4,3,2,11,10,9,8,13,12,1,0,7,6)];
512 	}
513 
514 	ROM = memory_region(REGION_USER4);
515 	memcpy( buffer, ROM, memory_region_length(REGION_USER4) );
516 	for(i=0;i<memory_region_length(REGION_USER4);i++)
517 	{
518 		ROM[i]=buffer[BITSWAP24(i,23,22,21,20,19,18,17,16,15,14 ,5,4,3,2,11,10,9,8,13,12,1,0,7,6)];
519 	}
520 
521 	free(buffer);
522 }
523 
524 GAME( 1986, darkmist, 0, darkmist, darkmist, darkmist, ROT270, "Seibu Kaihatsu (Taito license)", "The Lost Castle in Darkmist" )
525