1 /*---
2 
3 Pirates      (c)1994 NIX  (DEC 14 1994 17:32:29) displayed in cabinet test mode
4 Genix Family (c)1994 NIX  (MAY 10 1994 14:21:20) displayed in cabinet test mode
5 driver by David Haywood and Nicola Salmoria
6 
7 TODO:
8 - EEPROM doesn't work. I'm not sure what the program is trying to do.
9   The EEPROM handling might actually be related to the protection which
10   makes the game hang.
11   See pirates_in1_r() for code which would work around the protection,
12   but makes the game periodically hang for a couple of seconds; therefore,
13   for now I'm just patching out the protection check.
14 
15 - Protection is the same in Genix Family
16 
17 -----
18 
19 Here's some info about the dump:
20 
21 Name:            Pirates
22 Manufacturer:    NIX
23 Year:            1994
24 Date Dumped:     14-07-2002 (DD-MM-YYYY)
25 
26 CPU:             68000, possibly at 12mhz (prototype board does have a 16mhz one)
27 SOUND:           OKIM6295
28 GFX:             Unknown
29 
30 CPU Roms at least are the same on the Prototype board (the rest of the roms probably are too)
31 
32 -----
33 
34 Program Roms are Scrambled (Data + Address Lines)
35 P Graphic Roms (Tilemap Tiles) are Scrambled (Data + Address Lines)
36 S Graphic Roms (Sprite Tiles) are Scrambled (Data + Address Lines)
37 OKI Samples Rom is Scrambled (Data + Address Lines)
38 
39 68k interrupts (pirates)
40 lev 1 : 0x64 : 0000 bf84 - vbl?
41 lev 2 : 0x68 : 0000 4bc6 -
42 lev 3 : 0x6c : 0000 3bda -
43 lev 4 : 0x70 : 0000 3bf0 -
44 lev 5 : 0x74 : 0000 3c06 -
45 lev 6 : 0x78 : 0000 3c1c -
46 lev 7 : 0x7c : 0000 3c32 -
47 
48 Inputs mapped by Stephh
49 
50 The game hanging is an interesting issue, the board owner has 2 copies of this game, one a prototype,
51 on the final released version.  The roms on both boards are the same, however the prototype locks up
52 just as it does in Mame at the moment.  The final board does not.  It would appear the prototype
53 board does not have the protection hardware correctly in place
54 
55 
56 PCB Layout (Genix Family) (by Guru)
57 ----------
58 
59 |------------------------------------------------|
60 |     0.31       6116  6116             3.72     |
61 |         M6295  6116  6116             4.71     |
62 |                                       5.70     |
63 |         6264         6116             6.69     |
64 |         6264         6116                      |
65 |                                                |
66 |                                                |
67 | 93C46       Altera  24MHz   Altera             |
68 |             EPM7064         EPM7064            |
69 |                                                |
70 |                                                |
71 |             Altera          Altera  7.34  9.35 |
72 |             EPM7064         EPM7064 8.48 10.49 |
73 |                                                |
74 |        PAL                                     |
75 |                                                |
76 |        68000  1.15  62256  6264                |
77 | 32MHz         2.16  62256  6264                |
78 |               *                                |
79 |------------------------------------------------|
80 
81 Notes:
82       68000 clock: 16.000MHz
83       M6295 clock: 1.33333MHz, Sample Rate: /165
84       VSync: 60Hz
85       HSync: 15.69kHz
86       *    : unknown IC (18 pin DIP, surface scratched off)
87 
88 ---*/
89 
90 #include "driver.h"
91 #include "machine/eeprom.h"
92 
93 extern data16_t *pirates_tx_tileram, *pirates_spriteram;
94 extern data16_t *pirates_fg_tileram,  *pirates_bg_tileram;
95 extern data16_t *pirates_scroll;
96 
97 VIDEO_START(pirates);
98 WRITE16_HANDLER( pirates_tx_tileram_w );
99 WRITE16_HANDLER( pirates_fg_tileram_w );
100 WRITE16_HANDLER( pirates_bg_tileram_w );
101 VIDEO_UPDATE(pirates);
102 
103 
104 
105 static struct EEPROM_interface eeprom_interface =
106 {
107 	6,				/* address bits */
108 	16,				/* data bits */
109 	"*110",			/*  read command */
110 	"*101",			/* write command */
111 	0,				/* erase command */
112 	"*10000xxxx",	/* lock command */
113 	"*10011xxxx"	/* unlock command */
114 };
115 
NVRAM_HANDLER(pirates)116 static NVRAM_HANDLER( pirates )
117 {
118 	if (read_or_write) EEPROM_save(file);
119 	else
120 	{
121 		EEPROM_init(&eeprom_interface);
122 		if (file) EEPROM_load(file);
123 	}
124 }
125 
WRITE16_HANDLER(pirates_out_w)126 static WRITE16_HANDLER( pirates_out_w )
127 {
128 	if (ACCESSING_LSB)
129 	{
130 		/* bits 0-2 control EEPROM */
131 		EEPROM_write_bit(data & 0x04);
132 		EEPROM_set_cs_line((data & 0x01) ? CLEAR_LINE : ASSERT_LINE);
133 		EEPROM_set_clock_line((data & 0x02) ? ASSERT_LINE : CLEAR_LINE);
134 
135 		/* bit 6 selects oki bank */
136 		OKIM6295_set_bank_base(0, (data & 0x40) ? 0x40000 : 0x00000);
137 
138 		/* bit 7 used (function unknown) */
139 	}
140 
141 //	logerror("%06x: out_w %04x\n",activecpu_get_pc(),data);
142 }
143 
READ16_HANDLER(pirates_in1_r)144 static READ16_HANDLER( pirates_in1_r )
145 {
146 //	static int prot = 0xa3;
147 	int bit;
148 
149 //	logerror("%06x: IN1_r\n",activecpu_get_pc());
150 
151 #if 0
152 	/* Pirates protection workaround. It more complicated than this... see code at
153 	   602e and 62a6 */
154 	/* For Genix, see 6576 for setting values and 67c2,d3b4 and dbc2 for tests. */
155 
156 	if (activecpu_get_pc() == 0x6134)
157 	{
158 		bit = prot & 1;
159 		prot = (prot >> 1) | (bit << 7);
160 	}
161 	else if (activecpu_get_pc() == 0x6020)
162 		bit = 0;
163 	else if (activecpu_get_pc() == 0x6168)
164 		bit = 0;
165 	else if (activecpu_get_pc() == 0x61cc)
166 		bit = 1;
167 	else
168 #endif
169 		bit = 1;
170 
171 	/* bit 4 is EEPROM data, bit 7 is protection */
172 	return input_port_1_word_r(0,0) | (EEPROM_read_bit() << 4) | (bit << 7);
173 }
174 
175 
176 
177 /* Memory Maps */
178 
MEMORY_READ16_START(pirates_readmem)179 static MEMORY_READ16_START( pirates_readmem )
180 	{ 0x000000, 0x0fffff, MRA16_ROM },
181 	{ 0x100000, 0x10ffff, MRA16_RAM },
182 	{ 0x300000, 0x300001, input_port_0_word_r },
183 	{ 0x400000, 0x400001, pirates_in1_r },
184 //	{ 0x500000, 0x5007ff, MRA16_RAM },
185 	{ 0x800000, 0x803fff, MRA16_RAM },
186 //	{ 0x900000, 0x903fff, MRA16_RAM },
187 	{ 0xa00000, 0xa00001, OKIM6295_status_0_lsb_r },
188 MEMORY_END
189 
190 static MEMORY_WRITE16_START( pirates_writemem )
191 	{ 0x000000, 0x0fffff, MWA16_ROM },
192 	{ 0x100000, 0x10ffff, MWA16_RAM }, // main ram
193 	{ 0x500000, 0x5007ff, MWA16_RAM, &pirates_spriteram },
194 //	{ 0x500800, 0x50080f, MWA16_RAM },
195 	{ 0x600000, 0x600001, pirates_out_w },
196 	{ 0x700000, 0x700001, MWA16_RAM, &pirates_scroll },	// scroll reg
197 	{ 0x800000, 0x803fff, paletteram16_xRRRRRGGGGGBBBBB_word_w, &paletteram16 },
198 	{ 0x900000, 0x90017f, MWA16_RAM },  // more of tilemaps ?
199 	{ 0x900180, 0x90137f, pirates_tx_tileram_w, &pirates_tx_tileram },
200 	{ 0x901380, 0x902a7f, pirates_fg_tileram_w, &pirates_fg_tileram },
201 //	{ 0x902580, 0x902a7f, MWA16_RAM },  // more of tilemaps ?
202 	{ 0x902a80, 0x904187, pirates_bg_tileram_w, &pirates_bg_tileram },
203 //	{ 0x903c80, 0x904187, MWA16_RAM },  // more of tilemaps ?
204 	{ 0xa00000, 0xa00001, OKIM6295_data_0_lsb_w },
205 MEMORY_END
206 
207 
208 
209 /* Input Ports */
210 
211 INPUT_PORTS_START( pirates )
212 	PORT_START	// IN0 - 0x300000.w
213 	PORT_BIT(  0x0001, IP_ACTIVE_LOW, IPT_JOYSTICK_UP    | IPF_PLAYER1 )
214 	PORT_BIT(  0x0002, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN  | IPF_PLAYER1 )
215 	PORT_BIT(  0x0004, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT  | IPF_PLAYER1 )
216 	PORT_BIT(  0x0008, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT | IPF_PLAYER1 )
217 	PORT_BIT(  0x0010, IP_ACTIVE_LOW, IPT_BUTTON1 | IPF_PLAYER1 )
218 	PORT_BIT(  0x0020, IP_ACTIVE_LOW, IPT_BUTTON2 | IPF_PLAYER1 )
219 	PORT_BIT(  0x0040, IP_ACTIVE_LOW, IPT_BUTTON3 | IPF_PLAYER1 )
220 	PORT_BIT(  0x0080, IP_ACTIVE_LOW, IPT_START1 )
221 	PORT_BIT(  0x0100, IP_ACTIVE_LOW, IPT_JOYSTICK_UP    | IPF_PLAYER2 )
222 	PORT_BIT(  0x0200, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN  | IPF_PLAYER2 )
223 	PORT_BIT(  0x0400, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT  | IPF_PLAYER2 )
224 	PORT_BIT(  0x0800, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT | IPF_PLAYER2 )
225 	PORT_BIT(  0x1000, IP_ACTIVE_LOW, IPT_BUTTON1 | IPF_PLAYER2 )
226 	PORT_BIT(  0x2000, IP_ACTIVE_LOW, IPT_BUTTON2 | IPF_PLAYER2 )
227 	PORT_BIT(  0x4000, IP_ACTIVE_LOW, IPT_BUTTON3 | IPF_PLAYER2 )
228 	PORT_BIT(  0x8000, IP_ACTIVE_LOW, IPT_START2 )
229 
230 	PORT_START	// IN1 - 0x400000.w
231 	PORT_BIT(  0x0001, IP_ACTIVE_LOW, IPT_COIN1 )
232 	PORT_BIT(  0x0002, IP_ACTIVE_LOW, IPT_COIN2 )
233 	PORT_BIT(  0x0004, IP_ACTIVE_LOW, IPT_SERVICE1 )
234 	PORT_BITX( 0x0008, IP_ACTIVE_LOW, IPT_SERVICE, DEF_STR( Service_Mode ), KEYCODE_F2, IP_JOY_NONE )
235 	PORT_BIT(  0x0010, IP_ACTIVE_HIGH,IPT_SPECIAL )		// EEPROM data
236 	PORT_BIT(  0x0020, IP_ACTIVE_HIGH, IPT_UNKNOWN )		// seems checked in "test mode"
237 	PORT_BIT(  0x0040, IP_ACTIVE_HIGH, IPT_UNKNOWN )		// seems checked in "test mode"
238 	PORT_BIT(  0x0080, IP_ACTIVE_HIGH,IPT_SPECIAL )		// protection (see pirates_in1_r)
239 	/* What do these bits do ? */
240 	PORT_BIT(  0x0100, IP_ACTIVE_HIGH, IPT_UNKNOWN )
241 	PORT_BIT(  0x0200, IP_ACTIVE_HIGH, IPT_UNKNOWN )
242 	PORT_BIT(  0x0400, IP_ACTIVE_HIGH, IPT_UNKNOWN )
243 	PORT_BIT(  0x0800, IP_ACTIVE_HIGH, IPT_UNKNOWN )
244 	PORT_BIT(  0x1000, IP_ACTIVE_HIGH, IPT_UNKNOWN )
245 	PORT_BIT(  0x2000, IP_ACTIVE_HIGH, IPT_UNKNOWN )
246 	PORT_BIT(  0x4000, IP_ACTIVE_HIGH, IPT_UNKNOWN )
247 	PORT_BIT(  0x8000, IP_ACTIVE_HIGH, IPT_UNKNOWN )
248 INPUT_PORTS_END
249 
250 
251 
252 static struct GfxLayout charlayout =
253 {
254 	8,8,
255 	RGN_FRAC(1,4),
256 	4,
257 	{ RGN_FRAC(3,4), RGN_FRAC(2,4), RGN_FRAC(1,4), RGN_FRAC(0,4) },
258 	{ 7, 6, 5, 4, 3, 2, 1, 0 },
259 	{ 8*0, 8*1, 8*2, 8*3, 8*4, 8*5, 8*6, 8*7 },
260 	8*8
261 };
262 
263 static struct GfxLayout spritelayout =
264 {
265 	16,16,
266 	RGN_FRAC(1,4),
267 	4,
268 	{ RGN_FRAC(3,4), RGN_FRAC(2,4), RGN_FRAC(1,4), RGN_FRAC(0,4) },
269 	{ 7, 6, 5, 4, 3, 2, 1, 0,
270 	 15,14,13,12,11,10, 9, 8 },
271 	{ 0*16, 1*16, 2*16, 3*16, 4*16, 5*16, 6*16, 7*16,
272 	  8*16, 9*16,10*16,11*16,12*16,13*16,14*16,15*16 },
273 	16*16
274 };
275 
276 static struct GfxDecodeInfo gfxdecodeinfo[] =
277 {
278 
279 	{ REGION_GFX1, 0, &charlayout,   0x0000, 3*128 },
280 	{ REGION_GFX2, 0, &spritelayout, 0x1800,   128 },
281 	{ -1 } /* end of array */
282 };
283 
284 
285 
286 /* Machine Driver + Related bits */
287 
288 static struct OKIM6295interface okim6295_interface =
289 {
290 	1,                  /* 1 chip */
291 	{ 1333333/165 },     /* measured frequency */
292 	{ REGION_SOUND1 },	/* memory region */
293 	{ 100 }
294 };
295 
296 
297 
298 static MACHINE_DRIVER_START( pirates )
299 	MDRV_CPU_ADD(M68000, 16000000) /* 16mhz */
MDRV_CPU_MEMORY(pirates_readmem,pirates_writemem)300 	MDRV_CPU_MEMORY(pirates_readmem,pirates_writemem)
301 	MDRV_CPU_VBLANK_INT(irq1_line_hold,1)
302 
303 	MDRV_FRAMES_PER_SECOND(60)
304 	MDRV_VBLANK_DURATION(DEFAULT_60HZ_VBLANK_DURATION)
305 
306 	MDRV_NVRAM_HANDLER(pirates)
307 
308 	MDRV_GFXDECODE(gfxdecodeinfo)
309 
310 	MDRV_VIDEO_ATTRIBUTES(VIDEO_TYPE_RASTER)
311 	MDRV_SCREEN_SIZE(36*8, 32*8)
312 	MDRV_VISIBLE_AREA(0*8, 36*8-1, 2*8, 30*8-1)
313 	MDRV_PALETTE_LENGTH(0x2000)
314 
315 	MDRV_VIDEO_START(pirates)
316 	MDRV_VIDEO_UPDATE(pirates)
317 
318 	MDRV_SOUND_ADD(OKIM6295, okim6295_interface)
319 MACHINE_DRIVER_END
320 
321 
322 
323 
324 /* Rom Loading */
325 
326 ROM_START( pirates )
327 	ROM_REGION( 0x100000, REGION_CPU1, 0 ) /* 68000 Code (encrypted) */
328 	ROM_LOAD16_BYTE( "r_449b.bin",  0x00000, 0x80000, CRC(224aeeda) SHA1(5b7e47a106af0debf8b07f120571f437ad6ab5c3) )
329 	ROM_LOAD16_BYTE( "l_5c1e.bin",  0x00001, 0x80000, CRC(46740204) SHA1(6f1da3b2cbea25bbfdec74c625c5fb23459b83b6) )
330 
331 	ROM_REGION( 0x200000, REGION_GFX1, 0 ) /* GFX (encrypted) */
332 	ROM_LOAD( "p4_4d48.bin", 0x000000, 0x080000, CRC(89fda216) SHA1(ea31e750460e67a24972b04171230633eb2b6d9d) )
333 	ROM_LOAD( "p2_5d74.bin", 0x080000, 0x080000, CRC(40e069b4) SHA1(515d12cbb29bdbf3f3016e5bbe14941209978095) )
334 	ROM_LOAD( "p1_7b30.bin", 0x100000, 0x080000, CRC(26d78518) SHA1(c293f1194f8ef38241d149cf1db1a511a7fb4936) )
335 	ROM_LOAD( "p8_9f4f.bin", 0x180000, 0x080000, CRC(f31696ea) SHA1(f5ab59e441317b02b615a1cdc6d075c5bdcdea73) )
336 
337 	ROM_REGION( 0x200000, REGION_GFX2, 0 ) /* GFX (encrypted) */
338 	ROM_LOAD( "s1_6e89.bin", 0x000000, 0x080000, CRC(c78a276f) SHA1(d5127593e68f9e8f2878803c652a35a1c6d82b2c) )
339 	ROM_LOAD( "s2_6df3.bin", 0x080000, 0x080000, CRC(9f0bad96) SHA1(b8f910aa259192e261815392f5d7c9c7dabe0b4d) )
340 	ROM_LOAD( "s4_fdcc.bin", 0x100000, 0x080000, CRC(8916ddb5) SHA1(f4f7da831ef929eb7575bbe69eae317f15cfd648) )
341 	ROM_LOAD( "s8_4b7c.bin", 0x180000, 0x080000, CRC(1c41bd2c) SHA1(fba264a3c195f303337223a74cbad5eec5c457ec) )
342 
343 	ROM_REGION( 0x080000, REGION_SOUND1, 0) /* OKI samples (encrypted) */
344 	ROM_LOAD( "s89_49d4.bin", 0x000000, 0x080000, CRC(63a739ec) SHA1(c57f657225e62b3c9c5f0c7185ad7a87794d55f4) )
345 ROM_END
346 
347 ROM_START( genix )
348 	ROM_REGION( 0x100000, REGION_CPU1, 0 ) /* 68000 Code (encrypted) */
349 	ROM_LOAD16_BYTE( "1.15",  0x00000, 0x80000, CRC(d26abfb0) SHA1(4a89ba7504f86cb612796c376f359ab61ec3d902) )
350 	ROM_LOAD16_BYTE( "2.16",  0x00001, 0x80000, CRC(a14a25b4) SHA1(9fa64c6514bdee56b5654b001f8367283b461e8a) )
351 
352 	ROM_REGION( 0x200000, REGION_GFX1, 0 ) /* GFX (encrypted) */
353 	ROM_LOAD( "7.34", 0x000000, 0x040000, CRC(58da8aac) SHA1(bfc8449ba842f8ceac62ebdf6005d8f19d96afa6) )
354 	ROM_LOAD( "9.35", 0x080000, 0x040000, CRC(96bad9a8) SHA1(4e757cca0ab157f0c935087c9702c88741bf7a79) )
355 	ROM_LOAD( "8.48", 0x100000, 0x040000, CRC(0ddc58b6) SHA1(d52437607695ddebfe8494fd214efd20ba72d549) )
356 	ROM_LOAD( "10.49",0x180000, 0x040000, CRC(2be308c5) SHA1(22fc0991557643c22f6763f186b74900a33a39e0) )
357 
358 	ROM_REGION( 0x200000, REGION_GFX2, 0 ) /* GFX (encrypted) */
359 	ROM_LOAD( "6.69", 0x000000, 0x040000, CRC(b8422af7) SHA1(d3290fc6ea2670c445731e2b493205874dc4b319) )
360 	ROM_LOAD( "5.70", 0x080000, 0x040000, CRC(e46125c5) SHA1(73d9a51f30a9c1a8397145d2a4397696ef37f4e5) )
361 	ROM_LOAD( "4.71", 0x100000, 0x040000, CRC(7a8ed21b) SHA1(f380156c44de2fc316f390adee09b6a3cd404dec) )
362 	ROM_LOAD( "3.72", 0x180000, 0x040000, CRC(f78bd6ca) SHA1(c70857b8053f9a6e3e15bbc9f7d13354b0966b30) )
363 
364 	ROM_REGION( 0x080000, REGION_SOUND1, 0) /* OKI samples (encrypted) */
365 	ROM_LOAD( "0.31", 0x000000, 0x080000, CRC(80d087bc) SHA1(04d1aacc273c7ffa57b48bd043d55b5b3d993f74) )
366 ROM_END
367 
368 /* Init */
369 
370 static void pirates_decrypt_68k(void)
371 {
372     int rom_size;
373     UINT16 *buf, *rom;
374     int i;
375 
376     rom_size = memory_region_length(REGION_CPU1);
377 
378     buf = malloc(rom_size);
379 
380     if (!buf) return;
381 
382     rom = (UINT16 *)memory_region(REGION_CPU1);
383     memcpy (buf, rom, rom_size);
384 
385     for (i=0; i<rom_size/2; i++)
386     {
387         int adrl, adrr;
388         unsigned char vl, vr;
389 
390         adrl = BITSWAP24(i,23,22,21,20,19,18,4,8,3,14,2,15,17,0,9,13,10,5,16,7,12,6,1,11);
391         vl = BITSWAP8(buf[adrl],    4,2,7,1,6,5,0,3);
392 
393         adrr = BITSWAP24(i,23,22,21,20,19,18,4,10,1,11,12,5,9,17,14,0,13,6,15,8,3,16,7,2);
394         vr = BITSWAP8(buf[adrr]>>8, 1,4,7,0,3,5,6,2);
395 
396         rom[i] = (vr<<8) | vl;
397     }
398     free (buf);
399 }
400 
pirates_decrypt_p(void)401 static void pirates_decrypt_p(void)
402 {
403     int rom_size;
404     UINT8 *buf, *rom;
405     int i;
406 
407     rom_size = memory_region_length(REGION_GFX1);
408 
409     buf = malloc(rom_size);
410 
411     if (!buf) return;
412 
413     rom = memory_region(REGION_GFX1);
414     memcpy (buf, rom, rom_size);
415 
416     for (i=0; i<rom_size/4; i++)
417     {
418 		int adr = BITSWAP24(i,23,22,21,20,19,18,10,2,5,9,7,13,16,14,11,4,1,6,12,17,3,0,15,8);
419 		rom[adr+0*(rom_size/4)] = BITSWAP8(buf[i+0*(rom_size/4)], 2,3,4,0,7,5,1,6);
420 		rom[adr+1*(rom_size/4)] = BITSWAP8(buf[i+1*(rom_size/4)], 4,2,7,1,6,5,0,3);
421 		rom[adr+2*(rom_size/4)] = BITSWAP8(buf[i+2*(rom_size/4)], 1,4,7,0,3,5,6,2);
422 		rom[adr+3*(rom_size/4)] = BITSWAP8(buf[i+3*(rom_size/4)], 2,3,4,0,7,5,1,6);
423     }
424     free (buf);
425 }
426 
pirates_decrypt_s(void)427 static void pirates_decrypt_s(void)
428 {
429     int rom_size;
430     UINT8 *buf, *rom;
431     int i;
432 
433     rom_size = memory_region_length(REGION_GFX2);
434 
435     buf = malloc(rom_size);
436 
437     if (!buf) return;
438 
439     rom = memory_region(REGION_GFX2);
440     memcpy (buf, rom, rom_size);
441 
442     for (i=0; i<rom_size/4; i++)
443     {
444 		int adr = BITSWAP24(i,23,22,21,20,19,18,17,5,12,14,8,3,0,7,9,16,4,2,6,11,13,1,10,15);
445 		rom[adr+0*(rom_size/4)] = BITSWAP8(buf[i+0*(rom_size/4)], 4,2,7,1,6,5,0,3);
446 		rom[adr+1*(rom_size/4)] = BITSWAP8(buf[i+1*(rom_size/4)], 1,4,7,0,3,5,6,2);
447 		rom[adr+2*(rom_size/4)] = BITSWAP8(buf[i+2*(rom_size/4)], 2,3,4,0,7,5,1,6);
448 		rom[adr+3*(rom_size/4)] = BITSWAP8(buf[i+3*(rom_size/4)], 4,2,7,1,6,5,0,3);
449     }
450     free (buf);
451 }
452 
453 
pirates_decrypt_oki(void)454 static void pirates_decrypt_oki(void)
455 {
456     int rom_size;
457     UINT8 *buf, *rom;
458     int i;
459 
460     rom_size = memory_region_length(REGION_SOUND1);
461 
462     buf = malloc(rom_size);
463 
464     if (!buf) return;
465 
466     rom = memory_region(REGION_SOUND1);
467     memcpy (buf, rom, rom_size);
468 
469     for (i=0; i<rom_size; i++)
470     {
471 		int adr = BITSWAP24(i,23,22,21,20,19,10,16,13,8,4,7,11,14,17,12,6,2,0,5,18,15,3,1,9);
472 		rom[adr] = BITSWAP8(buf[i], 2,3,4,0,7,5,1,6);
473     }
474     free (buf);
475 }
476 
477 
DRIVER_INIT(pirates)478 static DRIVER_INIT( pirates )
479 {
480 	data16_t *rom = (data16_t *)memory_region(REGION_CPU1);
481 
482 	pirates_decrypt_68k();
483 	pirates_decrypt_p();
484 	pirates_decrypt_s();
485 	pirates_decrypt_oki();
486 
487 	/* patch out protection check */
488 	rom[0x62c0/2] = 0x6006; // beq -> bra
489 }
490 
READ16_HANDLER(genix_prot_r)491 static READ16_HANDLER( genix_prot_r ) {	if(!offset)	return 0x0004; else	return 0x0000; }
492 
DRIVER_INIT(genix)493 static DRIVER_INIT( genix )
494 {
495 	pirates_decrypt_68k();
496 	pirates_decrypt_p();
497 	pirates_decrypt_s();
498 	pirates_decrypt_oki();
499 
500 	/* If this value is increased then something has gone wrong and the protection failed */
501 	/* Write-protect it for now */
502 	install_mem_read16_handler (0, 0x109e98, 0x109e9b, genix_prot_r );
503 }
504 
505 
506 /* GAME */
507 
508 GAME( 1994, pirates, 0, pirates, pirates, pirates, 0, "NIX", "Pirates" )
509 GAME( 1994, genix,   0, pirates, pirates, genix,   0, "NIX", "Genix Family" )
510