1 // license:BSD-3-Clause
2 // copyright-holders:David Haywood, Nicola Salmoria, Tomasz Slanina
3 /*
4 ***********************************************************************************
5 Dark Mist (c)1986  Taito / Seibu
6 
7 driver by
8 
9   David Haywood
10   Nicola Salmoria
11   Tomasz Slanina
12 
13 Main CPU : z80 (with encryption, external to z80)
14 Sound CPU: custom T5182 cpu (like seibu sound system but with internal code)
15 
16 The SEI8608B sound board, which features the T5182 "CPU CUSTOM" and YM2151, also
17 has unpopulated locations for a 76489AN, 2x MSM5205, 2x 27512 EPROM (presumably
18 for ADPCM samples), and additional TTL chips to support all these.
19 
20 $e000 - coins (two bytes)
21 $e2b7 - player 1 energy
22 
23 TODO:
24  - when player soaks in water, color pen used is wrong (entry 1 at 0xf500 should be 0x0c and instead is 0x14), might be btanb?
25  - cocktail mode
26  - unknown bit in sprite attr (there's code used for OR-ing sprite attrib with some
27    value (taken from ram) when one of coords is greater than 256-16 )
28 ***********************************************************************************
29 */
30 
31 #include "emu.h"
32 #include "includes/darkmist.h"
33 #include "cpu/z80/z80.h"
34 #include "speaker.h"
35 
machine_start()36 void darkmist_state::machine_start()
37 {
38 	membank("bank1")->configure_entries(0, 2, memregion("maincpu")->base() + 0x10000, 0x4000);
39 }
40 
hw_w(uint8_t data)41 void darkmist_state::hw_w(uint8_t data)
42 {
43 	m_hw=data;
44 	membank("bank1")->set_entry((data&0x80)?1:0);
45 }
46 
memmap(address_map & map)47 void darkmist_state::memmap(address_map &map)
48 {
49 	map(0x0000, 0x7fff).rom();
50 	map(0x8000, 0xbfff).bankr("bank1");
51 	map(0xc801, 0xc801).portr("P1");
52 	map(0xc802, 0xc802).portr("P2");
53 	map(0xc803, 0xc803).portr("START");
54 	map(0xc804, 0xc804).w(FUNC(darkmist_state::hw_w));
55 	map(0xc805, 0xc805).writeonly().share("spritebank");
56 	map(0xc806, 0xc806).portr("DSW1");
57 	map(0xc807, 0xc807).portr("DSW2");
58 	map(0xc808, 0xc808).portr("UNK");
59 	map(0xd000, 0xd0ff).ram().w(m_palette, FUNC(palette_device::write_indirect)).share("palette");
60 	map(0xd200, 0xd2ff).ram().w(m_palette, FUNC(palette_device::write_indirect_ext)).share("palette_ext");
61 	map(0xd400, 0xd41f).ram().share("scroll");
62 	map(0xd600, 0xd67f).rw(m_t5182, FUNC(t5182_device::sharedram_r), FUNC(t5182_device::sharedram_w));
63 	map(0xd680, 0xd680).w(m_t5182, FUNC(t5182_device::sound_irq_w));
64 	map(0xd681, 0xd681).r(m_t5182, FUNC(t5182_device::sharedram_semaphore_snd_r));
65 	map(0xd682, 0xd682).w(m_t5182, FUNC(t5182_device::sharedram_semaphore_main_acquire_w));
66 	map(0xd683, 0xd683).w(m_t5182, FUNC(t5182_device::sharedram_semaphore_main_release_w));
67 	map(0xd800, 0xdfff).ram().w(FUNC(darkmist_state::tx_vram_w)).share("videoram");
68 	map(0xe000, 0xefff).ram().share("workram");
69 	map(0xf000, 0xffff).ram().share("spriteram");
70 }
71 
decrypted_opcodes_map(address_map & map)72 void darkmist_state::decrypted_opcodes_map(address_map &map)
73 {
74 	map(0x0000, 0x7fff).rom().share("decrypted_opcodes");
75 	map(0x8000, 0xbfff).bankr("bank1");
76 }
77 
78 static INPUT_PORTS_START( darkmist )
79 	PORT_START("P1")
80 	PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_JOYSTICK_UP ) PORT_8WAY
81 	PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN ) PORT_8WAY
82 	PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT ) PORT_8WAY
83 	PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT ) PORT_8WAY
84 	PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_BUTTON1 )
85 	PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_BUTTON2 )
86 	PORT_BIT( 0xc0, IP_ACTIVE_LOW, IPT_UNKNOWN )
87 
88 	PORT_START("P2")
89 	PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_JOYSTICK_UP ) PORT_8WAY PORT_COCKTAIL
90 	PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN ) PORT_8WAY PORT_COCKTAIL
91 	PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT ) PORT_8WAY PORT_COCKTAIL
92 	PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT ) PORT_8WAY PORT_COCKTAIL
93 	PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_BUTTON1 ) PORT_COCKTAIL
94 	PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_BUTTON2 ) PORT_COCKTAIL
95 	PORT_BIT( 0xc0, IP_ACTIVE_LOW, IPT_UNKNOWN )
96 
97 	PORT_START("START")
98 	PORT_DIPNAME( 0x01, 0x01, "2-0" )
99 	PORT_DIPSETTING(    0x01, DEF_STR( No ) )
100 	PORT_DIPSETTING(    0x00, DEF_STR( Yes ) )
101 	PORT_DIPNAME( 0x02, 0x02, "2-1" )
102 	PORT_DIPSETTING(    0x02, DEF_STR( No ) )
103 	PORT_DIPSETTING(    0x00, DEF_STR( Yes ) )
104 	PORT_DIPNAME( 0x04, 0x04, "2-2" )
105 	PORT_DIPSETTING(    0x04, DEF_STR( No ) )
106 	PORT_DIPSETTING(    0x00, DEF_STR( Yes ) )
107 	PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_START1 ) PORT_IMPULSE(1)
108 	PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_START2 ) PORT_IMPULSE(1)
109 	PORT_DIPNAME( 0x20, 0x20, "2-5" )
110 	PORT_DIPSETTING(    0x20, DEF_STR( No ) )
111 	PORT_DIPSETTING(    0x00, DEF_STR( Yes ) )
112 	PORT_DIPNAME( 0x40, 0x40, "2-6" )
113 	PORT_DIPSETTING(    0x40, DEF_STR( No ) )
114 	PORT_DIPSETTING(    0x00, DEF_STR( Yes ) )
115 	PORT_DIPNAME( 0x80, 0x80, "2-7" )
116 	PORT_DIPSETTING(    0x80, DEF_STR( No ) )
117 	PORT_DIPSETTING(    0x00, DEF_STR( Yes ) )
118 
119 	PORT_START("DSW1")
120 	PORT_DIPNAME( 0x07, 0x07, DEF_STR( Coin_A ) ) PORT_DIPLOCATION("SW1:1,2,3")
121 	PORT_DIPSETTING(    0x00, DEF_STR( 5C_1C ) )
122 	PORT_DIPSETTING(    0x04, DEF_STR( 4C_1C ) )
123 	PORT_DIPSETTING(    0x02, DEF_STR( 3C_1C ) )
124 	PORT_DIPSETTING(    0x06, DEF_STR( 2C_1C ) )
125 	PORT_DIPSETTING(    0x07, DEF_STR( 1C_1C ) )
126 	PORT_DIPSETTING(    0x03, DEF_STR( 1C_2C ) )
127 	PORT_DIPSETTING(    0x05, DEF_STR( 1C_3C ) )
128 	PORT_DIPSETTING(    0x01, DEF_STR( 1C_5C ) )
129 	PORT_DIPNAME( 0x18, 0x18, DEF_STR( Coin_B ) ) PORT_DIPLOCATION("SW1:4,5")
130 	PORT_DIPSETTING(    0x10, DEF_STR( 2C_1C ) )
131 	PORT_DIPSETTING(    0x18, DEF_STR( 1C_1C ) )
132 	PORT_DIPSETTING(    0x00, DEF_STR( 2C_3C ) )
133 	PORT_DIPSETTING(    0x08, DEF_STR( 1C_2C ) )
134 	PORT_SERVICE_DIPLOC( 0x20, IP_ACTIVE_LOW, "SW1:6" )
135 	PORT_DIPNAME( 0x40, 0x40, DEF_STR( Unknown ) ) PORT_DIPLOCATION("SW1:7")    /* Listed as "ALWAYS ON" */
136 	PORT_DIPSETTING(    0x40, DEF_STR( Off ) )
137 	PORT_DIPSETTING(    0x00, DEF_STR( On ) )
138 	PORT_DIPNAME( 0x80, 0x80, DEF_STR( Free_Play ) ) PORT_DIPLOCATION("SW1:8")
139 	PORT_DIPSETTING(    0x80, DEF_STR( No ) )
140 	PORT_DIPSETTING(    0x00, DEF_STR( Yes ) )
141 
142 	PORT_START("DSW2")
143 	PORT_DIPNAME( 0x01, 0x01, DEF_STR( Cabinet ) ) PORT_DIPLOCATION("SW2:1")
144 	PORT_DIPSETTING(    0x01, DEF_STR( Upright ) )
145 	PORT_DIPSETTING(    0x00, DEF_STR( Cocktail ) )
146 	PORT_DIPNAME( 0x06, 0x06, DEF_STR( Difficulty ) ) PORT_DIPLOCATION("SW2:2,3")
147 	PORT_DIPSETTING(    0x06, DEF_STR( Easy ) )
148 	PORT_DIPSETTING(    0x04, DEF_STR( Normal ) )
149 	PORT_DIPSETTING(    0x02, DEF_STR( Hard ) )
150 	PORT_DIPSETTING(    0x00, DEF_STR( Hardest ) )
151 	PORT_DIPNAME( 0x18, 0x18, DEF_STR( Lives ) ) PORT_DIPLOCATION("SW2:4,5")
152 	PORT_DIPSETTING(    0x18, "1" )
153 	PORT_DIPSETTING(    0x10, "2" )
154 	PORT_DIPSETTING(    0x08, "3" )
155 	PORT_DIPSETTING(    0x00, "4" )
156 	PORT_DIPNAME( 0x60, 0x60, DEF_STR( Bonus_Life ) ) PORT_DIPLOCATION("SW2:6,7")
157 	PORT_DIPSETTING(    0x20, "10K / 20K" )
158 	PORT_DIPSETTING(    0x60, "20K / 40K" )
159 	PORT_DIPSETTING(    0x40, "30K / 60K" )
160 	PORT_DIPSETTING(    0x00, "40K / 80K" )
161 	PORT_DIPNAME( 0x80, 0x00, DEF_STR( Demo_Sounds ) ) PORT_DIPLOCATION("SW2:8")
162 	PORT_DIPSETTING(    0x80, DEF_STR( Off ) )
163 	PORT_DIPSETTING(    0x00, DEF_STR( On ) )
164 
165 
166 	PORT_START("UNK")
167 	PORT_DIPNAME( 0x01, 0x01, "5-0" )
168 	PORT_DIPSETTING(    0x01, DEF_STR( No ) )
169 	PORT_DIPSETTING(    0x00, DEF_STR( Yes ) )
170 	PORT_DIPNAME( 0x02, 0x02, "5-1" )
171 	PORT_DIPSETTING(    0x02, DEF_STR( No ) )
172 	PORT_DIPSETTING(    0x00, DEF_STR( Yes ) )
173 	PORT_DIPNAME( 0x04, 0x04, "5-2" )
174 	PORT_DIPSETTING(    0x04, DEF_STR( No ) )
175 	PORT_DIPSETTING(    0x00, DEF_STR( Yes ) )
176 	PORT_DIPNAME( 0x08, 0x08, "5-3" )
177 	PORT_DIPSETTING(    0x08, DEF_STR( No ) )
178 	PORT_DIPSETTING(    0x00, DEF_STR( Yes ) )
179 	PORT_DIPNAME( 0x10, 0x10, "5-4" )
180 	PORT_DIPSETTING(    0x10, DEF_STR( No ) )
181 	PORT_DIPSETTING(    0x00, DEF_STR( Yes ) )
182 	PORT_DIPNAME( 0x20, 0x20, "5-5" )
183 	PORT_DIPSETTING(    0x20, DEF_STR( No ) )
184 	PORT_DIPSETTING(    0x00, DEF_STR( Yes ) )
185 	PORT_DIPNAME( 0x40, 0x40, "5-6" )
186 	PORT_DIPSETTING(    0x40, DEF_STR( No ) )
187 	PORT_DIPSETTING(    0x00, DEF_STR( Yes ) )
188 	PORT_DIPNAME( 0x80, 0x80, "5-7" )
189 	PORT_DIPSETTING(    0x80, DEF_STR( No ) )
190 	PORT_DIPSETTING(    0x00, DEF_STR( Yes ) )
191 
192 INPUT_PORTS_END
193 
194 static const gfx_layout charlayout =
195 {
196 	8,8,
197 	RGN_FRAC(1,2),
198 	4,
199 	{ 0, 4, RGN_FRAC(1,2)+0, RGN_FRAC(1,2)+4 },
200 
201 	{ 0, 1, 2, 3, 8+0, 8+1, 8+2, 8+3 },
202 	{ 0*16, 1*16, 2*16, 3*16, 4*16, 5*16, 6*16, 7*16 },
203 	16*8
204 };
205 
206 static const gfx_layout tilelayout =
207 {
208 	16,16,
209 	RGN_FRAC(1,2),
210 	4,
211 	{ 0, 4, RGN_FRAC(1,2)+0, RGN_FRAC(1,2)+4 },
212 
213 
214 	{ 0, 1, 2, 3, 8+0, 8+1, 8+2, 8+3,
215 			16+0, 16+1, 16+2, 16+3, 24+0, 24+1, 24+2, 24+3 },
216 	{ 0*32, 1*32, 2*32, 3*32, 4*32, 5*32, 6*32, 7*32,
217 			8*32, 9*32, 10*32, 11*32, 12*32, 13*32, 14*32, 15*32 },
218 	32*16
219 };
220 
221 
222 static GFXDECODE_START( gfx_darkmist )
223 	GFXDECODE_ENTRY( "tx_gfx", 0, charlayout,  0x300, 16 )
224 	GFXDECODE_ENTRY( "bg_gfx", 0, tilelayout,  0x000, 16 )
225 	GFXDECODE_ENTRY( "fg_gfx", 0, tilelayout,  0x100, 16 )
226 	GFXDECODE_ENTRY( "spr_gfx", 0, tilelayout, 0x200, 16 )
227 GFXDECODE_END
228 
TIMER_DEVICE_CALLBACK_MEMBER(darkmist_state::scanline)229 TIMER_DEVICE_CALLBACK_MEMBER(darkmist_state::scanline)
230 {
231 	int scanline = param;
232 
233 	if(scanline == 240) // vblank-out irq
234 		m_maincpu->set_input_line_and_vector(0, HOLD_LINE,0xd7); /* Z80 - RST 10h */
235 
236 	if(scanline == 0) // vblank-in irq
237 		m_maincpu->set_input_line_and_vector(0, HOLD_LINE,0xcf); /* Z80 - RST 08h */
238 }
239 
240 
241 
darkmist(machine_config & config)242 void darkmist_state::darkmist(machine_config &config)
243 {
244 	/* basic machine hardware */
245 	Z80(config, m_maincpu, 4000000);         /* ? MHz */
246 	m_maincpu->set_addrmap(AS_PROGRAM, &darkmist_state::memmap);
247 	m_maincpu->set_addrmap(AS_OPCODES, &darkmist_state::decrypted_opcodes_map);
248 	TIMER(config, "scantimer").configure_scanline(FUNC(darkmist_state::scanline), "screen", 0, 1);
249 
250 	T5182(config, m_t5182, 0);
251 
252 	/* video hardware */
253 	SCREEN(config, m_screen, SCREEN_TYPE_RASTER);
254 	m_screen->set_refresh_hz(60);
255 	m_screen->set_vblank_time(ATTOSECONDS_IN_USEC(0));
256 	m_screen->set_size(256, 256);
257 	m_screen->set_visarea(0, 256-1, 16, 256-16-1);
258 	m_screen->set_screen_update(FUNC(darkmist_state::screen_update));
259 	m_screen->set_palette(m_palette);
260 
261 	GFXDECODE(config, m_gfxdecode, m_palette, gfx_darkmist);
262 	PALETTE(config, m_palette, FUNC(darkmist_state::darkmist_palette));
263 	m_palette->set_format(palette_device::xRGB_444, 0x100*4);
264 	m_palette->set_indirect_entries(256+1);
265 
266 	/* sound hardware */
267 	SPEAKER(config, "mono").front_center();
268 
269 	ym2151_device &ymsnd(YM2151(config, "ymsnd", 14318180/4));    /* 3.579545 MHz */
270 	ymsnd.irq_handler().set(m_t5182, FUNC(t5182_device::ym2151_irq_handler));
271 	ymsnd.add_route(0, "mono", 1.0);
272 	ymsnd.add_route(1, "mono", 1.0);
273 }
274 
275 ROM_START( darkmist )
276 	ROM_REGION( 0x18000, "maincpu", 0 )
277 	ROM_LOAD( "dm_15.rom", 0x00000, 0x08000, CRC(21e6503c) SHA1(09174fb424b76f7f2a381297e3420ddd2e76b008) )
278 
279 	ROM_LOAD( "dm_16.rom", 0x10000, 0x08000, CRC(094579d9) SHA1(2449bc9ba38396912ee9b72dd870ea9fcff95776) )
280 
281 	ROM_REGION( 0x8000, "t5182_z80", 0 ) /* Toshiba T5182 external ROM */
282 	ROM_LOAD( "dm_17.rom", 0x0000, 0x8000, CRC(7723dcae) SHA1(a0c69e7a7b6fd74f7ed6b9c6419aed94aabcd4b0) )
283 
284 	ROM_REGION( 0x4000, "tx_gfx", 0 )
285 	ROM_LOAD( "dm_13.rom", 0x00000, 0x02000, CRC(38bb38d9) SHA1(d751990166dd3d503c5de7667679b96210061cd1) )
CRC(ac5a31f3)286 	ROM_LOAD( "dm_14.rom", 0x02000, 0x02000, CRC(ac5a31f3) SHA1(79083390671062be2eab93cc875a0f86d709a963) )
287 
288 	ROM_REGION( 0x20000, "fg_gfx", 0 )
289 	ROM_LOAD( "dm_05.rom", 0x00000, 0x10000, CRC(ca79a738) SHA1(66a76ea0d8ecc44f6cc77102303df74f40bf6118) )
290 	ROM_LOAD( "dm_06.rom", 0x10000, 0x10000, CRC(9629ed2c) SHA1(453f6a0b12efdadd7fcbe03ad37afb0afa6be051) )
291 
292 	ROM_REGION( 0x20000, "bg_gfx", 0 )
293 	ROM_LOAD( "dm_01.rom", 0x00000, 0x10000, CRC(652aee6b) SHA1(f4150784f7bd7be83a0041e4c52540aa564062ba) )
294 	ROM_LOAD( "dm_02.rom", 0x10000, 0x10000, CRC(e2dd15aa) SHA1(1f3a6a1e1afabfe9dc47549ef13ae7696302ae88) )
295 
296 	ROM_REGION( 0x40000, "spr_gfx", 0)
297 	ROM_LOAD( "dm_09.rom", 0x00000, 0x10000, CRC(52154b50) SHA1(5ee1a4bcf0752a057b9993b0069d744c35cf55f4) )
298 	ROM_LOAD( "dm_11.rom", 0x10000, 0x08000, CRC(3118e2f9) SHA1(dfd946ea1310851f97d31ce58d8280f2d92b0f59) )
299 	ROM_LOAD( "dm_10.rom", 0x20000, 0x10000, CRC(34fd52b5) SHA1(c4ee464ed79ec91f993b0f894572c0288f0ad1d4) )
300 	ROM_LOAD( "dm_12.rom", 0x30000, 0x08000, CRC(cc4b9839) SHA1(b7e95513d2e06929fed5005caf3bf8c3fba0b597) )
301 
302 	ROM_REGION( 0x10000, "bg_map", 0 )
303 	/* BG layer map ( 512x64 )*/
304 	ROM_LOAD16_BYTE( "dm_03.rom", 0x00000, 0x08000, CRC(60b40c2a) SHA1(c046273b15dab95ea4851c26ce941e580fa1b6ec) )
305 	ROM_LOAD16_BYTE( "dm_04.rom", 0x00001, 0x08000, CRC(d47b8cd9) SHA1(86eb7a5d8ea63c0c91f455b1b8322cc7b9c4a968) )
306 
307 	ROM_REGION( 0x08000, "fg_map", 0 )
308 	/* FG layer map ( 64x256 ) */
309 	ROM_LOAD16_BYTE( "dm_07.rom", 0x00000, 0x04000, CRC(889b1277) SHA1(78405110b9cf1ab988c0cbfdb668498dadb41229) )
310 	ROM_LOAD16_BYTE( "dm_08.rom", 0x00001, 0x04000, CRC(f76f6f46) SHA1(ce1c67dc8976106b24fee8d3a0b9e5deb016a327) )
311 
312 	ROM_REGION( 0x0100, "bg_clut", 0 )
313 	ROM_LOAD( "63s281n.m7",  0x0000, 0x0100, CRC(897ef49f) SHA1(e40c0fb0a68aa91ceaee86e774a428819a4794bb) )
314 	ROM_REGION( 0x0100, "fg_clut", 0 )
315 	ROM_LOAD( "63s281n.d7",  0x0000, 0x0100, CRC(a9975a96) SHA1(3a34569fc68ac15f91e1e90d4e273f844b315091) )
316 	ROM_REGION( 0x0100, "spr_clut", 0 )
317 	ROM_LOAD( "63s281n.f11", 0x0000, 0x0100, CRC(8096b206) SHA1(257004aa3501121d058afa6f64b1129303246758) )
318 	ROM_REGION( 0x0100, "tx_clut", 0 )
319 	ROM_LOAD( "63s281n.j15", 0x0000, 0x0100, CRC(2ea780a4) SHA1(0f8d6791114705e9982f9035f291d2a305b47f0a) )
320 
321 
322 	ROM_REGION( 0x0200, "proms", 0 ) // unknown PROMs
323 	ROM_LOAD( "63s281n.l1",  0x0000, 0x0100, CRC(208d17ca) SHA1(a77d56337bcac8d9a7bc3411239dfb3045e069ec) )
324 	ROM_LOAD( "82s129.d11",  0x0100, 0x0100, CRC(866eab0e) SHA1(398ffe2b82b6e2235746fd987d5f5995d7dc8687) )
325 ROM_END
326 
327 
328 
329 
330 void darkmist_state::decrypt_fgbgtiles(uint8_t* rom, int size)
331 {
332 	std::vector<uint8_t> buf(0x40000);
333 	/* data lines */
334 	for (int i = 0;i < size/2;i++)
335 	{
336 		int w1;
337 
338 		w1 = (rom[i + 0*size/2] << 8) + rom[i + 1*size/2];
339 
340 		w1 = bitswap<16>(w1, 9,14,7,2, 6,8,3,15,  10,13,5,12,  0,11,4,1);
341 
342 		buf[i + 0*size/2] = w1 >> 8;
343 		buf[i + 1*size/2] = w1 & 0xff;
344 	}
345 
346 	/* address lines */
347 	for (int i = 0;i < size;i++)
348 	{
349 		rom[i] = buf[bitswap<24>(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)];
350 	}
351 }
352 
353 
354 
decrypt_gfx()355 void darkmist_state::decrypt_gfx()
356 {
357 	std::vector<uint8_t> buf(0x40000);
358 	uint8_t *rom;
359 	int size;
360 	int i;
361 
362 	rom = memregion("tx_gfx")->base();
363 	size = memregion("tx_gfx")->bytes();
364 
365 	/* data lines */
366 	for (i = 0;i < size/2;i++)
367 	{
368 		int w1;
369 
370 		w1 = (rom[i + 0*size/2] << 8) + rom[i + 1*size/2];
371 
372 		w1 = bitswap<16>(w1, 9,14,7,2, 6,8,3,15,  10,13,5,12,  0,11,4,1);
373 
374 		buf[i + 0*size/2] = w1 >> 8;
375 		buf[i + 1*size/2] = w1 & 0xff;
376 	}
377 
378 	/* address lines */
379 	for (i = 0;i < size;i++)
380 	{
381 		rom[i] = buf[bitswap<24>(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)];
382 	}
383 
384 	decrypt_fgbgtiles(memregion("bg_gfx")->base(), memregion("bg_gfx")->bytes());
385 	decrypt_fgbgtiles(memregion("fg_gfx")->base(), memregion("fg_gfx")->bytes());
386 
387 
388 	rom = memregion("spr_gfx")->base();
389 	size = memregion("spr_gfx")->bytes();
390 
391 	/* data lines */
392 	for (i = 0;i < size/2;i++)
393 	{
394 		int w1;
395 
396 		w1 = (rom[i + 0*size/2] << 8) + rom[i + 1*size/2];
397 
398 		w1 = bitswap<16>(w1, 9,14,7,2, 6,8,3,15,  10,13,5,12,  0,11,4,1);
399 
400 		buf[i + 0*size/2] = w1 >> 8;
401 		buf[i + 1*size/2] = w1 & 0xff;
402 	}
403 
404 	/* address lines */
405 	for (i = 0;i < size;i++)
406 	{
407 		rom[i] = buf[bitswap<24>(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)];
408 	}
409 }
410 
decrypt_snd()411 void darkmist_state::decrypt_snd()
412 {
413 	uint8_t *ROM = memregion("t5182_z80")->base();
414 
415 	for (int i = 0x0000; i < 0x8000; i++)
416 		ROM[i] = bitswap<8>(ROM[i], 7, 1, 2, 3, 4, 5, 6, 0);
417 }
418 
init_darkmist()419 void darkmist_state::init_darkmist()
420 {
421 	uint8_t *ROM = memregion("maincpu")->base();
422 	std::vector<uint8_t> buffer(0x10000);
423 
424 	decrypt_gfx();
425 
426 	decrypt_snd();
427 
428 	for (int i = 0; i < 0x8000; i++)
429 	{
430 		uint8_t p = ROM[i];
431 		uint8_t d = p;
432 
433 		if(((i & 0x20) == 0x00) && ((i & 0x8) != 0))
434 			p ^= 0x20;
435 
436 		if(((i & 0x20) == 0x00) && ((i & 0xa) != 0))
437 			d ^= 0x20;
438 
439 		if(((i & 0x200) == 0x200) && ((i & 0x408) != 0))
440 			p ^= 0x10;
441 
442 		if((i & 0x220) != 0x200)
443 		{
444 			p = bitswap<8>(p, 7,6,5,2,3,4,1,0);
445 			d = bitswap<8>(d, 7,6,5,2,3,4,1,0);
446 		}
447 
448 		ROM[i] = d;
449 		m_decrypted_opcodes[i] = p;
450 	}
451 
452 	membank("bank1")->set_base(&ROM[0x010000]);
453 
454 	/* adr line swaps */
455 	ROM = memregion("bg_map")->base();
456 	int len = memregion("bg_map")->bytes();
457 	memcpy( &buffer[0], ROM, len );
458 
459 	for (int i = 0; i < len; i++)
460 	{
461 		ROM[i]=buffer[bitswap<24>(i,23,22,21,20,19,18,17,16,7,6,5,4,3,15,14,13,12,9,8,2,1,11,10, 0)];
462 	}
463 
464 
465 	ROM = memregion("fg_map")->base();
466 	len = memregion("fg_map")->bytes();
467 	memcpy( &buffer[0], ROM, len );
468 	for (int i = 0; i < len; i++)
469 	{
470 		ROM[i]=buffer[bitswap<24>(i,23,22,21,20,19,18,17,16,15 ,6,5,4,3,12,11,10,9,14,13,2,1,8,7 ,0  )];
471 	}
472 
473 }
474 
475 GAME( 1986, darkmist, 0, darkmist, darkmist, darkmist_state, init_darkmist, ROT270, "Seibu Kaihatsu (Taito license)", "The Lost Castle In Darkmist", MACHINE_NO_COCKTAIL | MACHINE_SUPPORTS_SAVE )
476