1 /***************************************************************************
2 
3  *****************************
4  *** NINJA KID II hardware ***		(by Roberto Ventura)
5  *****************************
6 
7 Game authors:
8 Game design:    Tsutomu Fuzisawa
9 Program design: Satoru Kinjo
10 Char. design:   Tsutomu Fizisawa
11 Char. design:   Akemi Tsunoda
12 Sound compose:  Tsutomu Fuzisawa
13 Bgm create:     Mecano Associate
14 Data make:      Takashi Hayashi
15 
16 General aspect.
17 
18 The game is driven by a fast Z80 CPU.
19 Screen resolution is 256x192.
20 768 colors on screen.
21 96 sprites.
22 
23 Rom Contents:
24 
25 NK2_01.ROM              Main CPU program ROM
26 NK2_02.ROM              CPU banked data ROM 0 (banks 0 and 1)
27 NK2_03.ROM              CPU banked data ROM 1 (banks 2 and 3)
28 NK2_04.ROM              CPU banked data ROM 2 (banks 4 and 5)
29 NK2_05.ROM              CPU banked data ROM 3 (banks 6 and 7)
30 NK2_06.ROM              Sound CPU program ROM (encrypted)
31 NK2_07.ROM              Sprites data ROM 1
32 NK2_08.ROM              Sprites data ROM 0
33 NK2_09.ROM              Raw PCM samples (complete?)
34 NK2_10.ROM              Background data ROM 1
35 NK2_11.ROM              Background data ROM 0
36 NK2_12.ROM              Foreground data ROM
37 
38 *** MEMORY MAP ***
39 
40 0000-7fff       Main CPU ROM
41 8000-bfff       Banked CPU ROM
42 c000-c7ff       I/O
43 c800-cdff       Color RAM
44 d000-d7ff       "FRONT" tile map
45 d800-dfff       "BACK" tile map
46 e000-efff       Main RAM
47 f400-f7ff	??? screen frame ???
48 f800-f9ff	CPU Stack
49 fa00-ffff       Sprite registers (misc RAM)
50 
51 
52 1) CPU
53 
54 1 OSC 12 MHz
55 1 OSC 5 MHz
56 2 YM 2203C.......CaBBe!.
57 
58 The Z80 runs in IM0,the game expects execution of RST10 each
59 frame.
60 
61 Game level maps,additional code and data are available to main
62 program via CPU banking at lacations 8000-bf00
63 
64 The encryption scheme for ROM 6(alternate version) is very simple,
65 I was surprised by such a large ROM (64k) for sound.
66 The first half contains opcodes only (see machine 1 pin)
67 while the second 32k chunk is for immediate data.
68 Opcode and Data keep their relative positions as well.
69 
70 
71 
72 2) I/O
73 
74 c000    "KEYCOIN" button
75 
76         76543210
77         || |  ||
78         || |  |^-COIN 1
79         || |  ^--COIN 2
80         || ^-----TEST MODE (on the fly,to be pressed during boot)
81         |^-------START 1
82         ^--------START 2
83 
84 
85 c001	"PAD1"
86 c002	"PAD2"
87 
88         76543210
89           ||||||
90           |||||^-RIGHT
91           ||||^--LEFT
92           |||^---DOWN
93           ||^----UP
94           |^-----FIRE 0
95           ^------FIRE 1
96 
97 
98 c003    "DIPSW1"
99 
100         76543210
101         ||||||||
102         |||||||^-UNUSED?
103         ||||||^-->EXTRA
104         |||||^--->LIVES
105         ||||^----CONTINUE MODE
106         |||^-----DEMO SOUND
107         ||^------NORMAL/HARD
108         |^-------LIVES 3/4
109         ^--------ENGLISH/JAP
110 
111 
112 c004    "DIPSW2"
113 
114         76543210
115         ||||||||
116         |||||||^-TEST MODE
117         ||||||^--TABLE/UPRIGHT
118         |||||^---"CREDIT SERVICE"
119         ||||^---->
120         |||^----->>
121         ||^------>>> coin/credit configurations
122         |^------->>
123         ^-------->
124 
125 c200	Sound command?
126 	This byte is written when game plays sound effects...
127 	it is set when music or sound effects (both pcm and fm) are triggered;
128 	I guess it is read by another CPU,then.
129 
130 c201	Unknown,but used.
131 
132 c202    Bank selector (0 to 7)
133 
134 c203    Sprite 'overdraw'
135         this is the most interesting feature of the game,when set
136         the sprites drawn in the previous frame remain on the
137         screen,so the game can perform special effects such as the
138         'close up' when you die or the "infinite balls" appearing
139         when an extra weapon is collected.
140         Appears to work like a xor mask,a sprite removes older
141         sprite 'bitmap' when present;other memory locations connected to
142 	this function may be f400-f7ff...should be investigated more.
143         -mmmh... I believe this is sci-fiction for a non-bitmap game...
144 
145 C208    Scroll X  0-7
146 
147 C209    Scroll X  MSB
148 
149 C20A    Scroll Y  0-7
150 
151 C20B    Scroll Y  MSB
152 
153 C20C    Background ENABLE
154         when set to zero the background is totally black,but
155         sprites are drawn correctly.
156 
157 
158 3) COLOR RAM
159 
160 The palette system is dynamic,the game can show up to 768 different
161 colors on screen.
162 
163 Palette depth is 12 bits as usual,two consecutive bytes are used for each
164 color code.
165 
166 format: RRRRGGGGBBBB0000
167 
168 Colors are organized in palettes,since graphics is 4 bits (16 colors)
169 each palette takes 32 bytes,the three different layers,BACK,SPRITES and
170 FRONT don't share any color,each has its own 256 color space,hence the
171 768 colors on screen.
172 
173 c800-c9ff       Background palettes
174 ca00-cbff       Sprites palettes
175 cc00-cdff       Foreground palettes
176 
177 
178 4) TILE-BASED LAYERS
179 
180 The tile format for background and foreground is the same,the
181 only difference is that background tiles are 16x16 pixels while foreground
182 tiles are only 8x8.
183 
184 Background virtual screen is 512x512 pixels scrollable.
185 
186 Two consecutive tiles bytes identify one tile.
187 
188         O7 O6 O5 O4 O3 O2 O1 O0         gfx Offset
189         O9 O8 FY FX C3 C2 C1 C0         Attibute
190 
191         O= GFX offset (1024 tiles)
192         F= Flip X and Y
193         C= Color palette selector
194 
195 
196 5) SPRITES
197 
198 Five bytes identify each sprite,but the registers actually used
199 are placed at intervals of 16.
200 Some of the remaining bytes are used (e.g. fa00),their meaning is totally
201 unknown to me,they seem to be related to the surprising additional sprite
202 feature of the game,but maybe they're just random writes in RAM.
203 
204 The first sprite data is located at fa0b,then fa1b and so on.
205 
206 
207 0b      Y7 Y6 Y5 Y4 Y3 Y2 Y1 Y0         Y coord
208 0c      X7 X6 X5 X4 X3 X2 X1 X0         X coord
209 0d      O9 O8 FY FX -- -- EN X8         hi gfx - FLIP - Enable - hi X
210 0e      O7 O6 O5 O4 O3 O2 O1 O0         gfx - offset
211 0f      -- -- -- -- C3 C2 C1 C0         color
212 
213         Y= Y coordinate
214         X= X coordinate (X8 is used to clip sprite on the left)
215         O= Gfx offset (1024 sprites)
216         F= Flip
217        EN= Enable (this is maybe the Y8 coordinate bit,but it isn't set
218            accordingly in the test mode
219         C= Color palette selector
220 
221 ***************************************************************************/
222 
223 
224 #include "driver.h"
225 #include "vidhrdw/generic.h"
226 
227 WRITE_HANDLER( ninjakd2_bgvideoram_w );
228 WRITE_HANDLER( ninjakd2_fgvideoram_w );
229 WRITE_HANDLER( ninjakd2_sprite_overdraw_w );
230 WRITE_HANDLER( ninjakd2_background_enable_w );
231 VIDEO_START( ninjakd2 );
232 VIDEO_UPDATE( ninjakd2 );
233 
234 extern unsigned char 	*ninjakd2_scrolly_ram;
235 extern unsigned char 	*ninjakd2_scrollx_ram;
236 extern unsigned char 	*ninjakd2_bgenable_ram;
237 extern unsigned char 	*ninjakd2_spoverdraw_ram;
238 extern unsigned char 	*ninjakd2_background_videoram;
239 extern unsigned char 	*ninjakd2_foreground_videoram;
240 extern size_t ninjakd2_backgroundram_size;
241 extern size_t ninjakd2_foregroundram_size;
242 
243 static int ninjakd2_bank_latch = 255;
244 
245 
246 
ninjakd2_init_samples(const struct MachineSound * msound)247 int ninjakd2_init_samples(const struct MachineSound *msound)
248 {
249 	int i,n;
250 	unsigned char *source = memory_region(REGION_SOUND1);
251 	struct GameSamples *samples;
252 	int sample_info [9][2] = { {0x0000,0x0A00},{0x0A00,0x1D00},{0x2700,0x1700},
253 	{0x3E00,0x1500},{0x5300,0x0B00},{0x5E00,0x0A00},{0x6800,0x0E00},{0x7600,0x1E00},{0xF000,0x0400} };
254 
255 	if ((Machine->samples = auto_malloc(sizeof(struct GameSamples) + 9 * sizeof(struct GameSample *))) == NULL)
256 		return 1;
257 
258 	samples = Machine->samples;
259 	samples->total = 8;
260 
261 	for (i=0;i<8;i++)
262 	{
263 		if ((samples->sample[i] = auto_malloc(sizeof(struct GameSample) + (sample_info[i][1]))) == NULL)
264 			return 1;
265 
266 		samples->sample[i]->length = sample_info[i][1];
267 		samples->sample[i]->smpfreq = 16000;	/* 16 kHz */
268 		samples->sample[i]->resolution = 8;
269 		for (n=0; n<sample_info[i][1]; n++)
270 			samples->sample[i]->data[n] = source[sample_info[i][0]+n] ^ 0x80;
271 	}
272 
273 	/*	The samples are now ready to be used.  They are a 8 bit, 16 kHz samples. 	 */
274 
275 	return 0;
276 }
277 
278 
INTERRUPT_GEN(ninjakd2_interrupt)279 INTERRUPT_GEN( ninjakd2_interrupt )
280 {
281 	cpu_set_irq_line_and_vector(0, 0, HOLD_LINE, 0xd7);	/* RST 10h */
282 }
283 
READ_HANDLER(ninjakd2_bankselect_r)284 READ_HANDLER( ninjakd2_bankselect_r )
285 {
286 	return ninjakd2_bank_latch;
287 }
288 
WRITE_HANDLER(ninjakd2_bankselect_w)289 WRITE_HANDLER( ninjakd2_bankselect_w )
290 {
291 	unsigned char *RAM = memory_region(REGION_CPU1);
292 	int bankaddress;
293 
294 	if (data != ninjakd2_bank_latch)
295 	{
296 		ninjakd2_bank_latch = data;
297 
298 		bankaddress = 0x10000 + ((data & 0x7) * 0x4000);
299 		cpu_setbank(1,&RAM[bankaddress]);	 /* Select 8 banks of 16k */
300 	}
301 }
302 
WRITE_HANDLER(ninjakd2_pcm_play_w)303 WRITE_HANDLER( ninjakd2_pcm_play_w )
304 {
305 	int i;
306 	int sample_no[9] = { 0x00,0x0A,0x27,0x3E,0x53,0x5E,0x68,0x76,0xF0 };
307 
308 	for(i=0;i<9;i++)
309 	 if (sample_no[i]==data) break;
310 
311 	if (i==8)
312 		sample_stop(0);
313 	else
314 		sample_start(0,i,0);
315 }
316 
MEMORY_READ_START(readmem)317 static MEMORY_READ_START( readmem )
318 	{ 0x0000, 0x7fff, MRA_ROM },
319 	{ 0x8000, 0xbfff, MRA_BANK1 },
320 	{ 0xc000, 0xc000, input_port_2_r },
321 	{ 0xc001, 0xc001, input_port_0_r },
322 	{ 0xc002, 0xc002, input_port_1_r },
323 	{ 0xc003, 0xc003, input_port_3_r },
324 	{ 0xc004, 0xc004, input_port_4_r },
325 	{ 0xc200, 0xc200, MRA_RAM },
326 	{ 0xc201, 0xc201, MRA_RAM },		// unknown but used
327 	{ 0xc202, 0xc202, ninjakd2_bankselect_r },
328 	{ 0xc203, 0xc203, MRA_RAM },
329 	{ 0xc208, 0xc209, MRA_RAM },
330 	{ 0xc20a, 0xc20b, MRA_RAM },
331 	{ 0xc20c, 0xc20c, MRA_RAM },
332 	{ 0xc800, 0xffff, MRA_RAM },
333 MEMORY_END
334 
335 
336 static MEMORY_WRITE_START( writemem )
337 	{ 0x0000, 0xbfff, MWA_ROM },
338 	{ 0xc200, 0xc200, soundlatch_w },
339 	{ 0xc201, 0xc201, MWA_RAM },		// unknown but used
340 	{ 0xc202, 0xc202, ninjakd2_bankselect_w },
341 	{ 0xc203, 0xc203, ninjakd2_sprite_overdraw_w, &ninjakd2_spoverdraw_ram },
342 	{ 0xc208, 0xc209, MWA_RAM, &ninjakd2_scrollx_ram },
343 	{ 0xc20a, 0xc20b, MWA_RAM, &ninjakd2_scrolly_ram },
344 	{ 0xc20c, 0xc20c, ninjakd2_background_enable_w, &ninjakd2_bgenable_ram },
345 	{ 0xc800, 0xcdff, paletteram_RRRRGGGGBBBBxxxx_swap_w, &paletteram },
346 	{ 0xd000, 0xd7ff, ninjakd2_fgvideoram_w, &ninjakd2_foreground_videoram, &ninjakd2_foregroundram_size },
347 	{ 0xd800, 0xdfff, ninjakd2_bgvideoram_w, &ninjakd2_background_videoram, &ninjakd2_backgroundram_size },
348 	{ 0xe000, 0xf9ff, MWA_RAM },
349 	{ 0xfa00, 0xffff, MWA_RAM, &spriteram, &spriteram_size },
350 MEMORY_END
351 
352 
353 static MEMORY_READ_START( snd_readmem )
354 	{ 0x0000, 0xbfff, MRA_ROM },
355 	{ 0xc000, 0xc7ff, MRA_RAM },
356 	{ 0xe000, 0xe000, soundlatch_r },
357 	{ 0xefee, 0xefee, MRA_NOP },
358 MEMORY_END
359 
360 
361 static MEMORY_WRITE_START( snd_writemem )
362 	{ 0x0000, 0xbfff, MWA_ROM },
363 	{ 0xc000, 0xc7ff, MWA_RAM },
364 	{ 0xf000, 0xf000, ninjakd2_pcm_play_w },	/* PCM SAMPLE OFFSET*256 */
365 	{ 0xeff5, 0xeff6, MWA_NOP },			/* SAMPLE FREQUENCY ??? */
366 	{ 0xefee, 0xefee, MWA_NOP },			/* CHIP COMMAND ?? */
367 MEMORY_END
368 
369 static PORT_WRITE_START( snd_writeport )
370 	{ 0x0000, 0x0000, YM2203_control_port_0_w },
371 	{ 0x0001, 0x0001, YM2203_write_port_0_w },
372 	{ 0x0080, 0x0080, YM2203_control_port_1_w },
373 	{ 0x0081, 0x0081, YM2203_write_port_1_w },
374 PORT_END
375 
376 
377 
378 INPUT_PORTS_START( ninjakd2 )
379     PORT_START
380     PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT )
381     PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT )
382     PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN )
383     PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_JOYSTICK_UP )
384     PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_BUTTON1 )
385     PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_BUTTON2 )
386     PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_UNKNOWN )
387     PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_UNKNOWN )
388 
389     PORT_START    /* player 2 controls */
390     PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT | IPF_COCKTAIL )
391     PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT  | IPF_COCKTAIL )
392     PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN  | IPF_COCKTAIL )
393     PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_JOYSTICK_UP    | IPF_COCKTAIL )
394     PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_BUTTON1 | IPF_COCKTAIL )
395     PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_BUTTON2 | IPF_COCKTAIL )
396     PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_UNKNOWN )
397     PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_UNKNOWN )
398 
399     PORT_START
400     PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_START1 )
401     PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_START2 )
402     PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_UNKNOWN )
403     PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_UNKNOWN )
404     PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_SERVICE )	/* keep pressed during boot to enter service mode */
405     PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_UNKNOWN )
406     PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_COIN1 )
407     PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_COIN2 )
408 
409     PORT_START  /* dsw0 */
410     PORT_DIPNAME( 0x01, 0x01, DEF_STR( Unknown ) )
411     PORT_DIPSETTING(    0x01, DEF_STR( Off ) )
412     PORT_DIPSETTING(    0x00, DEF_STR( On ) )
413     PORT_DIPNAME( 0x06, 0x06, DEF_STR( Bonus_Life ) )
414     PORT_DIPSETTING(    0x04, "20000 50000" )
415     PORT_DIPSETTING(    0x06, "30000 50000" )
416     PORT_DIPSETTING(    0x02, "50000 100000" )
417     PORT_DIPSETTING(    0x00, "None" )
418     PORT_DIPNAME( 0x08, 0x08, "Allow Continue" )
419     PORT_DIPSETTING(    0x00, DEF_STR( No ) )
420     PORT_DIPSETTING(    0x08, DEF_STR( Yes )  )
421     PORT_DIPNAME( 0x10, 0x00, DEF_STR( Demo_Sounds ) )
422     PORT_DIPSETTING(    0x10, DEF_STR( Off ) )
423     PORT_DIPSETTING(    0x00, DEF_STR( On )  )
424     PORT_DIPNAME( 0x20, 0x20, DEF_STR( Difficulty ) )
425     PORT_DIPSETTING(    0x20, "Normal" )
426     PORT_DIPSETTING(    0x00, "Hard" )
427     PORT_DIPNAME( 0x40, 0x40, DEF_STR( Lives ) )
428     PORT_DIPSETTING(    0x40, "3" )
429     PORT_DIPSETTING(    0x00, "4" )
430     PORT_DIPNAME( 0x80, 0x00, "Language" )
431     PORT_DIPSETTING(    0x00, "English" )
432     PORT_DIPSETTING(    0x80, "Japanese" )
433 
434     PORT_START  /* dsw1 */
435 	PORT_SERVICE( 0x01, IP_ACTIVE_LOW )
436     PORT_DIPNAME( 0x02, 0x00, DEF_STR( Cabinet ) )
437     PORT_DIPSETTING(    0x00, DEF_STR( Upright ) )
438     PORT_DIPSETTING(    0x02, DEF_STR( Cocktail ) )
439     PORT_DIPNAME( 0x04, 0x00, "Credit Service" )
440     PORT_DIPSETTING(    0x00, DEF_STR( Off ) )
441     PORT_DIPSETTING(    0x04, DEF_STR( On ) )
442     PORT_DIPNAME( 0x18, 0x18, DEF_STR( Coin_B ) )
443     PORT_DIPSETTING(    0x00, DEF_STR( 2C_1C ) )
444     PORT_DIPSETTING(    0x18, DEF_STR( 1C_1C ) )
445     PORT_DIPSETTING(    0x10, DEF_STR( 1C_2C ) )
446     PORT_DIPSETTING(    0x08, DEF_STR( 1C_3C ) )
447     PORT_DIPNAME( 0xe0, 0xe0, DEF_STR( Coin_A ) )
448     PORT_DIPSETTING(    0x00, DEF_STR( 5C_1C ) )
449     PORT_DIPSETTING(    0x20, DEF_STR( 4C_1C ) )
450     PORT_DIPSETTING(    0x40, DEF_STR( 3C_1C ) )
451     PORT_DIPSETTING(    0x60, DEF_STR( 2C_1C ) )
452     PORT_DIPSETTING(    0xe0, DEF_STR( 1C_1C ) )
453     PORT_DIPSETTING(    0xc0, DEF_STR( 1C_2C ) )
454     PORT_DIPSETTING(    0xa0, DEF_STR( 1C_3C ) )
455     PORT_DIPSETTING(    0x80, DEF_STR( 1C_4C ) )
456 INPUT_PORTS_END
457 
458 
459 
460 static struct GfxLayout charlayout =
461 {
462 	8,8,     /* 8*8 characters */
463 	1024,    /* 1024 characters */
464 	4,       /* 4 bits per pixel */
465 	{0,1,2,3 }, /* the bitplanes are packed in one nibble */
466 	{0, 4, 16384*8+0, 16384*8+4, 8, 12, 16384*8+8, 16384*8+12 },
467 	{16*0, 16*1, 16*2, 16*3, 16*4, 16*5, 16*6, 16*7 },
468 	8*16
469 };
470 
471 static struct GfxLayout spritelayout =
472 {
473 	16,16,   /* 16*16 characters */
474 	1024,    /* 1024 sprites */
475 	4,       /* 4 bits per pixel */
476 	{0,1,2,3}, /* the bitplanes are packed in one nibble */
477 	{0,  4,  65536*8+0,  65536*8+4,  8, 12,  65536*8+8, 65536*8+12,
478 		16*8+0, 16*8+4, 16*8+65536*8+0, 16*8+65536*8+4, 16*8+8, 16*8+12, 16*8+65536*8+8, 16*8+65536*8+12},
479 	{16*0, 16*1, 16*2, 16*3, 16*4, 16*5, 16*6, 16*7,
480 		32*8+16*0, 32*8+16*1, 32*8+16*2, 32*8+16*3, 32*8+16*4, 32*8+16*5, 32*8+16*6, 32*8+16*7},
481 	8*64
482 };
483 
484 static struct GfxDecodeInfo gfxdecodeinfo[] =
485 {
486 	{ REGION_GFX1, 0, &spritelayout,  0*16, 16 },
487 	{ REGION_GFX2, 0, &spritelayout, 16*16, 16 },
488 	{ REGION_GFX3, 0, &charlayout,   32*16, 16 },
489 	{ -1 } /* end of array */
490 };
491 
492 static struct Samplesinterface samples_interface =
493 {
494 	1,	/* 1 channel */
495 	25	/* volume */
496 };
497 
498 static struct CustomSound_interface custom_interface =
499 {
500 	ninjakd2_init_samples,
501 	0,
502 	0
503 };
504 
505 /* handler called by the 2203 emulator when the internal timers cause an IRQ */
irqhandler(int irq)506 static void irqhandler(int irq)
507 {
508 	cpu_set_irq_line(1,0,irq ? ASSERT_LINE : CLEAR_LINE);
509 }
510 
511 static struct YM2203interface ym2203_interface =
512 {
513 	2, 	 /* 2 chips */
514 	1500000, /* 12000000/8 MHz */
515 	{ YM2203_VOL(25,25), YM2203_VOL(25,25) },
516 	{ 0 },
517 	{ 0 },
518 	{ 0 },
519 	{ 0 },
520 	{ irqhandler }
521 };
522 
523 
524 static MACHINE_DRIVER_START( ninjakd2 )
525 
526 	/* basic machine hardware */
527 	MDRV_CPU_ADD(Z80, 6000000)		/* 12000000/2 ??? */
MDRV_CPU_MEMORY(readmem,writemem)528 	MDRV_CPU_MEMORY(readmem,writemem)	/* very sensitive to these settings */
529 	MDRV_CPU_VBLANK_INT(ninjakd2_interrupt,1)
530 
531 	MDRV_FRAMES_PER_SECOND(60)
532 	MDRV_VBLANK_DURATION(10000)
533 
534 	/* video hardware */
535 	MDRV_VIDEO_ATTRIBUTES(VIDEO_TYPE_RASTER)
536 	MDRV_SCREEN_SIZE(32*8, 32*8)
537 	MDRV_VISIBLE_AREA(0*8, 32*8-1, 4*8, 28*8-1)
538 	MDRV_GFXDECODE(gfxdecodeinfo)
539 	MDRV_PALETTE_LENGTH(768)
540 
541 	MDRV_VIDEO_START(ninjakd2)
542 	MDRV_VIDEO_UPDATE(ninjakd2)
543 
544 	/* sound hardware */
545 	MDRV_SOUND_ADD(YM2203, ym2203_interface)
546 MACHINE_DRIVER_END
547 
548 
549 static MACHINE_DRIVER_START( ninjak2a )
550 
551 	/* basic machine hardware */
552 	MDRV_CPU_ADD(Z80, 6000000)		/* 12000000/2 ??? */
553 	MDRV_CPU_MEMORY(readmem,writemem)	/* very sensitive to these settings */
554 	MDRV_CPU_VBLANK_INT(ninjakd2_interrupt,1)
555 
556 	MDRV_CPU_ADD(Z80, 4000000)
557 	MDRV_CPU_FLAGS(CPU_AUDIO_CPU)		/* 12000000/3 ??? */
558 	MDRV_CPU_MEMORY(snd_readmem,snd_writemem)
559 	MDRV_CPU_PORTS(0,snd_writeport)
560 
561 	MDRV_FRAMES_PER_SECOND(60)
562 	MDRV_VBLANK_DURATION(10000)
563 	MDRV_INTERLEAVE(10)
564 
565 	/* video hardware */
566 	MDRV_VIDEO_ATTRIBUTES(VIDEO_TYPE_RASTER)
567 	MDRV_SCREEN_SIZE(32*8, 32*8)
568 	MDRV_VISIBLE_AREA(0*8, 32*8-1, 4*8, 28*8-1)
569 	MDRV_GFXDECODE(gfxdecodeinfo)
570 	MDRV_PALETTE_LENGTH(768)
571 
572 	MDRV_VIDEO_START(ninjakd2)
573 	MDRV_VIDEO_UPDATE(ninjakd2)
574 
575 	/* sound hardware */
576 	MDRV_SOUND_ADD(YM2203, ym2203_interface)
577 	MDRV_SOUND_ADD(SAMPLES, samples_interface)
578 	MDRV_SOUND_ADD(CUSTOM, custom_interface)
579 MACHINE_DRIVER_END
580 
581 
582 
583 ROM_START( ninjakd2 )
584 	ROM_REGION( 0x30000, REGION_CPU1, 0 )
585 	ROM_LOAD( "nk2_01.rom",   0x00000, 0x8000, CRC(3cdbb906) SHA1(f48f82528b5fc581ee3b1ccd0ef9cdecc7249bb3) )
586 	ROM_LOAD( "nk2_02.rom",   0x10000, 0x8000, CRC(b5ce9a1a) SHA1(295a7e1d41e1a8ee45f1250086a0c9314837eded) )
587 	ROM_LOAD( "nk2_03.rom",   0x18000, 0x8000, CRC(ad275654) SHA1(7d29a17132adb19aeee9b98be5b76bd6e91f308e) )
588 	ROM_LOAD( "nk2_04.rom",   0x20000, 0x8000, CRC(e7692a77) SHA1(84beb8b02c564bffa9cc00313214e8f109bd40f9) )
589 	ROM_LOAD( "nk2_05.rom",   0x28000, 0x8000, CRC(5dac9426) SHA1(0916cddbbe1e93c32b96fe28e145d34b2a892e80) )
590 
591 	ROM_REGION( 0x10000, REGION_CPU2, 0 )
592 	ROM_LOAD( "nk2_06.rom",   0x0000, 0x10000, CRC(d3a18a79) SHA1(e4df713f89d8a8b43ef831b14864c50ec9b53f0b) )  // sound z80 code encrypted
593 
594 	ROM_REGION( 0x20000, REGION_GFX1, ROMREGION_DISPOSE )
595 	ROM_LOAD( "nk2_11.rom",   0x00000, 0x4000, CRC(41a714b3) SHA1(b05f48d71a9837914c12c13e0b479c8a6dc8c25e) )	/* background tiles */
596 	ROM_CONTINUE(             0x10000, 0x4000)
597 	ROM_CONTINUE(             0x04000, 0x4000)
598 	ROM_CONTINUE(             0x14000, 0x4000)
599 	ROM_LOAD( "nk2_10.rom",   0x08000, 0x4000, CRC(c913c4ab) SHA1(f822c5621b3e32c1a284f6367bdcace81c1c74b3) )
600 	ROM_CONTINUE(             0x18000, 0x4000)
601 	ROM_CONTINUE(             0x0c000, 0x4000)
602 	ROM_CONTINUE(             0x1c000, 0x4000)
603 
604 	ROM_REGION( 0x20000, REGION_GFX2, ROMREGION_DISPOSE )
605 	ROM_LOAD( "nk2_08.rom",   0x00000, 0x4000, CRC(1b79c50a) SHA1(8954bc51cb9fbbe16b09381f35c84ccc56a803f3) )	/* sprites tiles */
606 	ROM_CONTINUE(             0x10000, 0x4000)
607 	ROM_CONTINUE(             0x04000, 0x4000)
608 	ROM_CONTINUE(             0x14000, 0x4000)
609 	ROM_LOAD( "nk2_07.rom",   0x08000, 0x4000, CRC(0be5cd13) SHA1(8f94a8fef6668aaf13329715fee81302dbd6c685) )
610 	ROM_CONTINUE(             0x18000, 0x4000)
611 	ROM_CONTINUE(             0x0c000, 0x4000)
612 	ROM_CONTINUE(             0x1c000, 0x4000)
613 
614 	ROM_REGION( 0x08000, REGION_GFX3, ROMREGION_DISPOSE )
615 	ROM_LOAD( "nk2_12.rom",   0x00000, 0x02000, CRC(db5657a9) SHA1(abbb033edb9a5a0c66ee5981d1e4df1ab334a82d) )	/* foreground tiles */
616 	ROM_CONTINUE(             0x04000, 0x02000)
617 	ROM_CONTINUE(             0x02000, 0x02000)
618 	ROM_CONTINUE(             0x06000, 0x02000)
619 
620 	ROM_REGION( 0x10000, REGION_SOUND1, 0 )
621 	ROM_LOAD( "nk2_09.rom",   0x0000, 0x10000, CRC(c1d2d170) SHA1(0f325815086fde90fd85360d3660042b0b68ba96) )	/* raw pcm samples */
622 ROM_END
623 
624 ROM_START( ninjak2a )
625 	ROM_REGION( 0x30000, REGION_CPU1, 0 )
626 	ROM_LOAD( "nk2_01.bin",   0x00000, 0x8000, CRC(e6adca65) SHA1(33d483dde0853f37455cde32b461f4e919601b4b) )
627 	ROM_LOAD( "nk2_02.bin",   0x10000, 0x8000, CRC(d9284bd1) SHA1(e790fb1a718a1f7997931f2f390fe053655f231d) )
628 	ROM_LOAD( "nk2_03.rom",   0x18000, 0x8000, CRC(ad275654) SHA1(7d29a17132adb19aeee9b98be5b76bd6e91f308e) )
629 	ROM_LOAD( "nk2_04.rom",   0x20000, 0x8000, CRC(e7692a77) SHA1(84beb8b02c564bffa9cc00313214e8f109bd40f9) )
630 	ROM_LOAD( "nk2_05.bin",   0x28000, 0x8000, CRC(960725fb) SHA1(160c8bfaf089cbeeef2023f12379793079bff93b) )
631 
632 	ROM_REGION( 2*0x10000, REGION_CPU2, 0 )	/* 64k for code + 64k for decrypted opcodes */
633 	ROM_LOAD( "nk2_06.bin",   0x10000, 0x8000, CRC(7bfe6c9e) SHA1(aef8cbeb0024939bf65f77113a5cf777f6613722) )	/* decrypted opcodes */
634 	ROM_CONTINUE(             0x00000, 0x8000 )				/* decrypted data */
635 
636 	ROM_REGION( 0x20000, REGION_GFX1, ROMREGION_DISPOSE )
637 	ROM_LOAD( "nk2_11.rom",   0x00000, 0x4000, CRC(41a714b3) SHA1(b05f48d71a9837914c12c13e0b479c8a6dc8c25e) )	/* background tiles */
638 	ROM_CONTINUE(             0x10000, 0x4000)
639 	ROM_CONTINUE(             0x04000, 0x4000)
640 	ROM_CONTINUE(             0x14000, 0x4000)
641 	ROM_LOAD( "nk2_10.rom",   0x08000, 0x4000, CRC(c913c4ab) SHA1(f822c5621b3e32c1a284f6367bdcace81c1c74b3) )
642 	ROM_CONTINUE(             0x18000, 0x4000)
643 	ROM_CONTINUE(             0x0c000, 0x4000)
644 	ROM_CONTINUE(             0x1c000, 0x4000)
645 
646 	ROM_REGION( 0x20000, REGION_GFX2, ROMREGION_DISPOSE )
647 	ROM_LOAD( "nk2_08.rom",   0x00000, 0x4000, CRC(1b79c50a) SHA1(8954bc51cb9fbbe16b09381f35c84ccc56a803f3) )	/* sprites tiles */
648 	ROM_CONTINUE(             0x10000, 0x4000)
649 	ROM_CONTINUE(             0x04000, 0x4000)
650 	ROM_CONTINUE(             0x14000, 0x4000)
651 	ROM_LOAD( "nk2_07.rom",   0x08000, 0x4000, CRC(0be5cd13) SHA1(8f94a8fef6668aaf13329715fee81302dbd6c685) )
652 	ROM_CONTINUE(             0x18000, 0x4000)
653 	ROM_CONTINUE(             0x0c000, 0x4000)
654 	ROM_CONTINUE(             0x1c000, 0x4000)
655 
656 	ROM_REGION( 0x08000, REGION_GFX3, ROMREGION_DISPOSE )
657 	ROM_LOAD( "nk2_12.rom",   0x00000, 0x02000, CRC(db5657a9) SHA1(abbb033edb9a5a0c66ee5981d1e4df1ab334a82d) )	/* foreground tiles */
658 	ROM_CONTINUE(             0x04000, 0x02000)
659 	ROM_CONTINUE(             0x02000, 0x02000)
660 	ROM_CONTINUE(             0x06000, 0x02000)
661 
662 	ROM_REGION( 0x10000, REGION_SOUND1, 0 )
663 	ROM_LOAD( "nk2_09.rom",   0x0000, 0x10000, CRC(c1d2d170) SHA1(0f325815086fde90fd85360d3660042b0b68ba96) )	/* raw pcm samples */
664 ROM_END
665 
666 ROM_START( ninjak2b )
667 	ROM_REGION( 0x30000, REGION_CPU1, 0 )
668 	ROM_LOAD( "1.3s",         0x00000, 0x8000, CRC(cb4f4624) SHA1(4fc66641adc0a2c0eca332f27c5777df62fa507b) )
669 	ROM_LOAD( "2.3q",         0x10000, 0x8000, CRC(0ad0c100) SHA1(c5bbc107ba07bd6950bb4d7377e827c084b8229b) )
670 	ROM_LOAD( "nk2_03.rom",   0x18000, 0x8000, CRC(ad275654) SHA1(7d29a17132adb19aeee9b98be5b76bd6e91f308e) )
671 	ROM_LOAD( "nk2_04.rom",   0x20000, 0x8000, CRC(e7692a77) SHA1(84beb8b02c564bffa9cc00313214e8f109bd40f9) )
672 	ROM_LOAD( "nk2_05.rom",   0x28000, 0x8000, CRC(5dac9426) SHA1(0916cddbbe1e93c32b96fe28e145d34b2a892e80) )
673 
674 	ROM_REGION( 2*0x10000, REGION_CPU2, 0 )	/* 64k for code + 64k for decrypted opcodes */
675 	ROM_LOAD( "nk2_06.bin",   0x10000, 0x8000, CRC(7bfe6c9e) SHA1(aef8cbeb0024939bf65f77113a5cf777f6613722) )	/* decrypted opcodes */
676 	ROM_CONTINUE(             0x00000, 0x8000 )				/* decrypted data */
677 
678 	ROM_REGION( 0x20000, REGION_GFX1, ROMREGION_DISPOSE )
679 	ROM_LOAD( "nk2_11.rom",   0x00000, 0x4000, CRC(41a714b3) SHA1(b05f48d71a9837914c12c13e0b479c8a6dc8c25e) )	/* background tiles */
680 	ROM_CONTINUE(             0x10000, 0x4000)
681 	ROM_CONTINUE(             0x04000, 0x4000)
682 	ROM_CONTINUE(             0x14000, 0x4000)
683 	ROM_LOAD( "nk2_10.rom",   0x08000, 0x4000, CRC(c913c4ab) SHA1(f822c5621b3e32c1a284f6367bdcace81c1c74b3) )
684 	ROM_CONTINUE(             0x18000, 0x4000)
685 	ROM_CONTINUE(             0x0c000, 0x4000)
686 	ROM_CONTINUE(             0x1c000, 0x4000)
687 
688 	ROM_REGION( 0x20000, REGION_GFX2, ROMREGION_DISPOSE )
689 	ROM_LOAD( "nk2_08.rom",   0x00000, 0x4000, CRC(1b79c50a) SHA1(8954bc51cb9fbbe16b09381f35c84ccc56a803f3) )	/* sprites tiles */
690 	ROM_CONTINUE(             0x10000, 0x4000)
691 	ROM_CONTINUE(             0x04000, 0x4000)
692 	ROM_CONTINUE(             0x14000, 0x4000)
693 	ROM_LOAD( "nk2_07.rom",   0x08000, 0x4000, CRC(0be5cd13) SHA1(8f94a8fef6668aaf13329715fee81302dbd6c685) )
694 	ROM_CONTINUE(             0x18000, 0x4000)
695 	ROM_CONTINUE(             0x0c000, 0x4000)
696 	ROM_CONTINUE(             0x1c000, 0x4000)
697 
698 	ROM_REGION( 0x08000, REGION_GFX3, ROMREGION_DISPOSE )
699 	ROM_LOAD( "nk2_12.rom",   0x00000, 0x02000, CRC(db5657a9) SHA1(abbb033edb9a5a0c66ee5981d1e4df1ab334a82d) )	/* foreground tiles */
700 	ROM_CONTINUE(             0x04000, 0x02000)
701 	ROM_CONTINUE(             0x02000, 0x02000)
702 	ROM_CONTINUE(             0x06000, 0x02000)
703 
704 	ROM_REGION( 0x10000, REGION_SOUND1, 0 )
705 	ROM_LOAD( "nk2_09.rom",   0x0000, 0x10000, CRC(c1d2d170) SHA1(0f325815086fde90fd85360d3660042b0b68ba96) )	/* raw pcm samples */
706 ROM_END
707 
708 ROM_START( rdaction )
709 	ROM_REGION( 0x30000, REGION_CPU1, 0 )
710 	ROM_LOAD( "1.3u",  	      0x00000, 0x8000, CRC(5c475611) SHA1(2da88a95b5d68b259c8ae48af1438a82a1d601c1) )
711 	ROM_LOAD( "2.3s",         0x10000, 0x8000, CRC(a1e23bd2) SHA1(c3b6574dc9fa66b4f41c37754a0d20a865f8bc28) )
712 	ROM_LOAD( "nk2_03.rom",   0x18000, 0x8000, CRC(ad275654) SHA1(7d29a17132adb19aeee9b98be5b76bd6e91f308e) )
713 	ROM_LOAD( "nk2_04.rom",   0x20000, 0x8000, CRC(e7692a77) SHA1(84beb8b02c564bffa9cc00313214e8f109bd40f9) )
714 	ROM_LOAD( "nk2_05.bin",   0x28000, 0x8000, CRC(960725fb) SHA1(160c8bfaf089cbeeef2023f12379793079bff93b) )
715 
716 	ROM_REGION( 2*0x10000, REGION_CPU2, 0 )	/* 64k for code + 64k for decrypted opcodes */
717 	ROM_LOAD( "nk2_06.bin",   0x10000, 0x8000, CRC(7bfe6c9e) SHA1(aef8cbeb0024939bf65f77113a5cf777f6613722) )	/* decrypted opcodes */
718 	ROM_CONTINUE(             0x00000, 0x8000 )				/* decrypted data */
719 
720 	ROM_REGION( 0x20000, REGION_GFX1, ROMREGION_DISPOSE )
721 	ROM_LOAD( "nk2_11.rom",   0x00000, 0x4000, CRC(41a714b3) SHA1(b05f48d71a9837914c12c13e0b479c8a6dc8c25e) )	/* background tiles */
722 	ROM_CONTINUE(             0x10000, 0x4000)
723 	ROM_CONTINUE(             0x04000, 0x4000)
724 	ROM_CONTINUE(             0x14000, 0x4000)
725 	ROM_LOAD( "nk2_10.rom",   0x08000, 0x4000, CRC(c913c4ab) SHA1(f822c5621b3e32c1a284f6367bdcace81c1c74b3) )
726 	ROM_CONTINUE(             0x18000, 0x4000)
727 	ROM_CONTINUE(             0x0c000, 0x4000)
728 	ROM_CONTINUE(             0x1c000, 0x4000)
729 
730 	ROM_REGION( 0x20000, REGION_GFX2, ROMREGION_DISPOSE )
731 	ROM_LOAD( "nk2_08.rom",   0x00000, 0x4000, CRC(1b79c50a) SHA1(8954bc51cb9fbbe16b09381f35c84ccc56a803f3) )	/* sprites tiles */
732 	ROM_CONTINUE(             0x10000, 0x4000)
733 	ROM_CONTINUE(             0x04000, 0x4000)
734 	ROM_CONTINUE(             0x14000, 0x4000)
735 	ROM_LOAD( "nk2_07.rom",   0x08000, 0x4000, CRC(0be5cd13) SHA1(8f94a8fef6668aaf13329715fee81302dbd6c685) )
736 	ROM_CONTINUE(             0x18000, 0x4000)
737 	ROM_CONTINUE(             0x0c000, 0x4000)
738 	ROM_CONTINUE(             0x1c000, 0x4000)
739 
740 	ROM_REGION( 0x08000, REGION_GFX3, ROMREGION_DISPOSE )
741 	ROM_LOAD( "12.5n",        0x00000, 0x02000, CRC(0936b365) SHA1(3705f42b76ab474357e77c1a9b8e3755c7ab2c0c) )	/* foreground tiles */
742 	ROM_CONTINUE(             0x04000, 0x02000)
743 	ROM_CONTINUE(             0x02000, 0x02000)
744 	ROM_CONTINUE(             0x06000, 0x02000)
745 
746 	ROM_REGION( 0x10000, REGION_SOUND1, 0 )
747 	ROM_LOAD( "nk2_09.rom",   0x0000, 0x10000, CRC(c1d2d170) SHA1(0f325815086fde90fd85360d3660042b0b68ba96) )	/* raw pcm samples */
748 ROM_END
749 
750 
751 
752 DRIVER_INIT( ninjak2a )
753 {
754 	unsigned char *rom = memory_region(REGION_CPU2);
755 	int diff = memory_region_length(REGION_CPU2) / 2;
756 
757 	memory_set_opcode_base(1,rom+diff);
758 }
759 
760 
761 
762 GAMEX(1987, ninjakd2, 0,        ninjakd2, ninjakd2, 0,        ROT0, "UPL", "Ninja-Kid II (set 1)", GAME_NO_SOUND )	/* sound program is encrypted */
763 GAME( 1987, ninjak2a, ninjakd2, ninjak2a, ninjakd2, ninjak2a, ROT0, "UPL", "Ninja-Kid II (set 2)" )
764 GAME( 1987, ninjak2b, ninjakd2, ninjak2a, ninjakd2, ninjak2a, ROT0, "UPL", "Ninja-Kid II (set 3)" )
765 GAME( 1987, rdaction, ninjakd2, ninjak2a, ninjakd2, ninjak2a, ROT0, "UPL (World Games license)", "Rad Action" )
766