1 #define XE_DEBUG 0
2 #define XE_SKIPIDLE 1
3 #define XE_DMADELAY (256)
4 
5 /***************************************************************************
6 
7 	Xexex  (c) 1991 Konami
8 
9 
10 Change Log
11 ----------
12 
13 (ATXXXX03)
14 
15 Hooked up missing memory handler, emulated object DMA, revised IRQ,
16 rewrote the K053250(LVC) effect generator, ported tilemaps to use the
17 K056832 emulation(the K054157 is a complete subset of the K056832),
18 corrected a few K054539 PCM chip misbehaviors, etc.
19 
20 
21 The following bugs appear to be fixed:
22 
23 General:
24 
25 - game doesn't slow down like the arcade
26 	IRQ 5 is the "OBJDMA end interrupt" and shouldn't be triggered
27 	if DMA didn't complete within the frame.
28 
29 	* game speed may not be 100% correct but close to that on the
30 	Gamest video especially in stage 6. Xexex is 384x256 which suggests
31 	an 8Mhz horizontal dotclock and DMA delay can range up to 32.0us(clear)
32 	+ 256.0us(transfer). Increase XE_DMADELAY if emulation runs faster
33 	than the original or use cheat to overclock CPU 0 if you prefer faster
34 	gameplay.
35 
36 - sprite lag, dithering, flicking (DMA)
37 - line effects go out of sync (K053250 also does DMA)
38 - inconsistent reverb (maths bug)
39 - lasers don't change color (IRQ masking)
40 - xexex057gre_1 (delayed sfx, missing speech, Xexexj only: random 1-up note)
41 - xexex057gre_2 (reversed stereo)
42 - xexex065gre (coin up problems, IRQ order)
43 
44 - L1: xexex067gre (tilemap boundary), misaligned bosses (swapXY)
45 - L2: xexex061gre (K054157 offset)
46 - L4: half the foreground missing (LVC no-wraparound)
47 - L5: poly-face boss missing (coordinate masking)
48 - L6: sticky galaxies (LVC scroll bug)
49 - L7: misaligned ship patches (swapXY)
50 
51 
52 Unresolved Issues:
53 
54 - random 1-up notes still pop up in the world version (filtered temporarily)
55 - mono/stereo softdip has no effect (xexex057gre_3, external mixing?)
56 - K053250 shows a one-frame glitch at stage 1 boss (DMA timing?)
57 - stage 3 intro missing alpha effect (known K054338 deficiency)
58 - the stage 4 boss(tentacles) sometimes appears darker (palette update timing?)
59 - the furthest layer in stage 5 shakes when scrolling up or down (needs verification)
60 - Elaine's end-game graphics has wrong masking effect (known non-zoomed pdrawgfx issue)
61 
62 ***************************************************************************/
63 
64 #include "driver.h"
65 #include "state.h"
66 
67 #include "vidhrdw/generic.h"
68 #include "vidhrdw/konamiic.h"
69 #include "cpu/z80/z80.h"
70 #include "machine/eeprom.h"
71 #include "sound/k054539.h"
72 
73 VIDEO_START( xexex );
74 VIDEO_UPDATE( xexex );
75 void xexex_set_alpha(int on);
76 
77 MACHINE_INIT( xexex );
78 
79 static data16_t *xexex_workram;
80 static data16_t cur_control2;
81 static int init_eeprom_count;
82 static int cur_sound_region, xexex_strip0x1a;
83 static int suspension_active, resume_trigger;
84 static void *dmadelay_timer;
85 
86 
87 static struct EEPROM_interface eeprom_interface =
88 {
89 	7,				/* address bits */
90 	8,				/* data bits */
91 	"011000",		/*  read command */
92 	"011100",		/* write command */
93 	"0100100000000",/* erase command */
94 	"0100000000000",/* lock command */
95 	"0100110000000" /* unlock command */
96 };
97 
NVRAM_HANDLER(xexex)98 static NVRAM_HANDLER( xexex )
99 {
100 	if (read_or_write)
101 		EEPROM_save(file);
102 	else
103 	{
104 		EEPROM_init(&eeprom_interface);
105 
106 		if (file)
107 		{
108 			init_eeprom_count = 0;
109 			EEPROM_load(file);
110 		}
111 		else
112 			init_eeprom_count = 10;
113 	}
114 }
115 
116 
117 #if 0 /* (for reference; do not remove)*/
118 
119 /* the interface with the 053247 is weird. The chip can address only 0x1000 bytes */
120 /* of RAM, but they put 0x8000 there. The CPU can access them all. Address lines */
121 /* A1, A5 and A6 don't go to the 053247. */
122 static READ16_HANDLER( K053247_scattered_word_r )
123 {
124 	if (offset & 0x0031)
125 		return spriteram16[offset];
126 	else
127 	{
128 		offset = ((offset & 0x000e) >> 1) | ((offset & 0x3fc0) >> 3);
129 		return K053247_word_r(offset,mem_mask);
130 	}
131 }
132 
133 static WRITE16_HANDLER( K053247_scattered_word_w )
134 {
135 	if (offset & 0x0031)
136 		COMBINE_DATA(spriteram16+offset);
137 	else
138 	{
139 		offset = ((offset & 0x000e) >> 1) | ((offset & 0x3fc0) >> 3);
140 		K053247_word_w(offset,data,mem_mask);
141 	}
142 }
143 
144 #endif
145 
146 
xexex_objdma(int limiter)147 static void xexex_objdma(int limiter)
148 {
149 	static int frame = -1;
150 
151 	int counter, num_inactive;
152 	data16_t *src, *dst;
153 
154 	counter = frame;
155 	frame = cpu_getcurrentframe();
156 	if (limiter && counter == frame) return; /* make sure we only do DMA transfer once per frame*/
157 
158 	K053247_export_config(&dst, 0, 0, 0, &counter);
159 	src = spriteram16;
160 	num_inactive = counter = 256;
161 
162 	do
163 	{
164 		if (*src & 0x8000)
165 		{
166 			dst[0] = src[0x0];  dst[1] = src[0x2];
167 			dst[2] = src[0x4];  dst[3] = src[0x6];
168 			dst[4] = src[0x8];  dst[5] = src[0xa];
169 			dst[6] = src[0xc];  dst[7] = src[0xe];
170 			dst += 8;
171 			num_inactive--;
172 		}
173 		src += 0x40;
174 	}
175 	while (--counter);
176 
177 	if (num_inactive) do { *dst = 0; dst += 8; } while (--num_inactive);
178 }
179 
READ16_HANDLER(spriteram16_mirror_r)180 static READ16_HANDLER( spriteram16_mirror_r )
181 {
182 	return(spriteram16[offset]);
183 }
184 
WRITE16_HANDLER(spriteram16_mirror_w)185 static WRITE16_HANDLER( spriteram16_mirror_w )
186 {
187 	COMBINE_DATA(spriteram16+offset);
188 }
189 
READ16_HANDLER(xexex_waitskip_r)190 static READ16_HANDLER( xexex_waitskip_r )
191 {
192 	if (activecpu_get_pc() == 0x1158)
193 	{
194 		cpu_spinuntil_trigger(resume_trigger);
195 		suspension_active = 1;
196 	}
197 
198 	return(xexex_workram[0x14/2]);
199 }
200 
201 
READ16_HANDLER(control1_r)202 static READ16_HANDLER( control1_r )
203 {
204 	int res;
205 
206 	/* bit 0 is EEPROM data */
207 	/* bit 1 is EEPROM ready */
208 	/* bit 3 is service button */
209 	res = EEPROM_read_bit() | input_port_1_r(0);
210 
211 	if (init_eeprom_count)
212 	{
213 		init_eeprom_count--;
214 		res &= 0xf7;
215 	}
216 
217 	return res;
218 }
219 
parse_control2(void)220 static void parse_control2(void)
221 {
222 	/* bit 0  is data */
223 	/* bit 1  is cs (active low) */
224 	/* bit 2  is clock (active high) */
225 	/* bit 5  is enable irq 6 */
226 	/* bit 6  is enable irq 5 */
227 	/* bit 11 is watchdog */
228 
229 	EEPROM_write_bit(cur_control2 & 0x01);
230 	EEPROM_set_cs_line((cur_control2 & 0x02) ? CLEAR_LINE : ASSERT_LINE);
231 	EEPROM_set_clock_line((cur_control2 & 0x04) ? ASSERT_LINE : CLEAR_LINE);
232 
233 	/* bit 8 = enable sprite ROM reading */
234 	K053246_set_OBJCHA_line((cur_control2 & 0x0100) ? ASSERT_LINE : CLEAR_LINE);
235 
236 	/* bit 9 = disable alpha channel on K054157 plane 0 (under investigation) */
237 	xexex_set_alpha(!(cur_control2 & 0x200));
238 }
239 
READ16_HANDLER(control2_r)240 static READ16_HANDLER( control2_r )
241 {
242 	return cur_control2;
243 }
244 
WRITE16_HANDLER(control2_w)245 static WRITE16_HANDLER( control2_w )
246 {
247 	COMBINE_DATA(&cur_control2);
248 	parse_control2();
249 }
250 
251 
WRITE16_HANDLER(sound_cmd1_w)252 static WRITE16_HANDLER( sound_cmd1_w )
253 {
254 	if(ACCESSING_LSB)
255 	{
256 		/* anyone knows why 0x1a keeps lurking the sound queue in the world version???*/
257 		if (xexex_strip0x1a)
258 			if (soundlatch2_r(0)==1 && data==0x1a) return;
259 
260 		soundlatch_w(0, data & 0xff);
261 	}
262 }
263 
WRITE16_HANDLER(sound_cmd2_w)264 static WRITE16_HANDLER( sound_cmd2_w )
265 {
266 	if (ACCESSING_LSB)
267 	{
268 		soundlatch2_w(0, data & 0xff);
269 	}
270 }
271 
WRITE16_HANDLER(sound_irq_w)272 static WRITE16_HANDLER( sound_irq_w )
273 {
274 	cpu_set_irq_line(1, 0, HOLD_LINE);
275 }
276 
READ16_HANDLER(sound_status_r)277 static READ16_HANDLER( sound_status_r )
278 {
279 	return soundlatch3_r(0);
280 }
281 
reset_sound_region(void)282 static void reset_sound_region(void)
283 {
284 	cpu_setbank(2, memory_region(REGION_CPU2) + 0x10000 + cur_sound_region*0x4000);
285 }
286 
WRITE_HANDLER(sound_bankswitch_w)287 static WRITE_HANDLER( sound_bankswitch_w )
288 {
289 	cur_sound_region = data & 7;
290 	reset_sound_region();
291 }
292 
ym_set_mixing(double left,double right)293 static void ym_set_mixing(double left, double right)
294 {
295 	if(Machine->sample_rate) {
296 		int l = 71*left;
297 		int r = 71*right;
298 		int ch;
299 		for(ch=0; ch<MIXER_MAX_CHANNELS; ch++) {
300 			const char *name = mixer_get_name(ch);
301 			if(name && name[0] == 'Y')
302 				mixer_set_stereo_volume(ch, l, r);
303 		}
304 	}
305 }
306 
dmaend_callback(int data)307 static void dmaend_callback(int data)
308 {
309 	if (cur_control2 & 0x0040)
310 	{
311 		/* foul-proof (CPU0 could be deactivated while we wait)*/
312 		if (suspension_active) { suspension_active = 0; cpu_trigger(resume_trigger); }
313 
314 		/* IRQ 5 is the "object DMA end interrupt" and shouldn't be triggered*/
315 		/* if object data isn't ready for DMA within the frame.*/
316 		cpu_set_irq_line(0, 5, HOLD_LINE);
317 	}
318 }
319 
INTERRUPT_GEN(xexex_interrupt)320 static INTERRUPT_GEN( xexex_interrupt )
321 {
322 	if (suspension_active) { suspension_active = 0; cpu_trigger(resume_trigger); }
323 
324 	switch (cpu_getiloops())
325 	{
326 		case 0:
327 			/* IRQ 6 is for test mode only*/
328 			if (cur_control2 & 0x0020)
329 				cpu_set_irq_line(0, 6, HOLD_LINE);
330 		break;
331 
332 		case 1:
333 			if (K053246_is_IRQ_enabled())
334 			{
335 				/* OBJDMA starts at the beginning of V-blank*/
336 				xexex_objdma(0);
337 
338 				/* schedule DMA end interrupt*/
339 				timer_adjust(dmadelay_timer, TIME_IN_USEC(XE_DMADELAY), 0, 0);
340 			}
341 
342 			/* IRQ 4 is the V-blank interrupt. It controls color, sound and*/
343 			/* vital game logics that shouldn't be interfered by frame-drop.*/
344 			if (cur_control2 & 0x0800)
345 				cpu_set_irq_line(0, 4, HOLD_LINE);
346 		break;
347 	}
348 }
349 
350 
MEMORY_READ16_START(readmem)351 static MEMORY_READ16_START( readmem )
352 	{ 0x000000, 0x07ffff, MRA16_ROM },
353 #if XE_SKIPIDLE
354 	{ 0x080014, 0x080015, xexex_waitskip_r },		/* helps sound CPU by giving back control as early as possible*/
355 #endif
356 	{ 0x080000, 0x08ffff, MRA16_RAM },
357 	{ 0x090000, 0x097fff, MRA16_RAM },				/* K053247 sprite RAM*/
358 	{ 0x098000, 0x09ffff, spriteram16_mirror_r },	/* K053247 sprite RAM mirror read*/
359 	{ 0x0c4000, 0x0c4001, K053246_word_r },			/* Passthrough to sprite roms*/
360 	{ 0x0c6000, 0x0c7fff, K053250_0_ram_r },		/* K053250 "road" RAM*/
361 	{ 0x0c8000, 0x0c800f, K053250_0_r },
362 	{ 0x0d6014, 0x0d6015, sound_status_r },
363 	{ 0x0d6000, 0x0d601f, MRA16_RAM },
364 	{ 0x0da000, 0x0da001, input_port_2_word_r },
365 	{ 0x0da002, 0x0da003, input_port_3_word_r },
366 	{ 0x0dc000, 0x0dc001, input_port_0_word_r },
367 	{ 0x0dc002, 0x0dc003, control1_r },
368 	{ 0x0de000, 0x0de001, control2_r },
369 	{ 0x100000, 0x17ffff, MRA16_ROM },
370 	{ 0x180000, 0x181fff, K056832_ram_word_r },
371 	{ 0x182000, 0x183fff, K056832_ram_word_r },
372 	{ 0x190000, 0x191fff, K056832_rom_word_r },		/* Passthrough to tile roms*/
373 	{ 0x1a0000, 0x1a1fff, K053250_0_rom_r },
374 	{ 0x1b0000, 0x1b1fff, MRA16_RAM },
375 #if XE_DEBUG
376 	{ 0x0c0000, 0x0c003f, K056832_word_r },
377 	{ 0x0c2000, 0x0c2007, K053246_reg_word_r },
378 	{ 0x0ca000, 0x0ca01f, K054338_word_r },
379 	{ 0x0cc000, 0x0cc01f, K053251_lsb_r },
380 	{ 0x0d0000, 0x0d001f, K053252_word_r },
381 	{ 0x0d8000, 0x0d8007, K056832_b_word_r },
382 #endif
383 MEMORY_END
384 
385 static MEMORY_WRITE16_START( writemem )
386 	{ 0x000000, 0x07ffff, MWA16_ROM },					/* main ROM*/
387 	{ 0x080000, 0x08ffff, MWA16_RAM, &xexex_workram },	/* work RAM*/
388 	{ 0x090000, 0x097fff, MWA16_RAM, &spriteram16 },	/* K053247 sprite RAM*/
389 	{ 0x098000, 0x09ffff, spriteram16_mirror_w },		/* K053247 sprite RAM mirror write*/
390 	{ 0x0c0000, 0x0c003f, K056832_word_w },				/* VACSET (K054157)*/
391 	{ 0x0c2000, 0x0c2007, K053246_word_w },				/* OBJSET1*/
392 	{ 0x0c6000, 0x0c7fff, K053250_0_ram_w },			/* K053250 "road" RAM*/
393 	{ 0x0c8000, 0x0c800f, K053250_0_w },				/* background effects generator*/
394 	{ 0x0ca000, 0x0ca01f, K054338_word_w },				/* CLTC*/
395 	{ 0x0cc000, 0x0cc01f, K053251_lsb_w },				/* priority encoder*/
396 	{ 0x0d0000, 0x0d001f, K053252_word_w },				/* CCU*/
397 	{ 0x0d4000, 0x0d4001, sound_irq_w },
398 	{ 0x0d600c, 0x0d600d, sound_cmd1_w },
399 	{ 0x0d600e, 0x0d600f, sound_cmd2_w },
400 	{ 0x0d6000, 0x0d601f, MWA16_RAM },					/* sound regs fall through*/
401 	{ 0x0d8000, 0x0d8007, K056832_b_word_w },			/* VSCCS regs*/
402 	{ 0x0de000, 0x0de001, control2_w },
403 	{ 0x100000, 0x17ffff, MWA16_ROM },
404 	{ 0x180000, 0x181fff, K056832_ram_word_w }, 		/* tilemap RAM*/
405 	{ 0x182000, 0x183fff, K056832_ram_word_w }, 		/* tilemap RAM mirror*/
406 	{ 0x190000, 0x191fff, MWA16_ROM },					/* tile ROM*/
407 	{ 0x1b0000, 0x1b1fff, paletteram16_xrgb_word_w, &paletteram16 },
408 MEMORY_END
409 
410 static MEMORY_READ_START( sound_readmem )
411 	{ 0x0000, 0x7fff, MRA_ROM },
412 	{ 0x8000, 0xbfff, MRA_BANK2 },
413 	{ 0xc000, 0xdfff, MRA_RAM },
414 	{ 0xe000, 0xe22f, K054539_0_r },
415 	{ 0xec01, 0xec01, YM2151_status_port_0_r },
416 	{ 0xf002, 0xf002, soundlatch_r },
417 	{ 0xf003, 0xf003, soundlatch2_r },
418 MEMORY_END
419 
420 static MEMORY_WRITE_START( sound_writemem )
421 	{ 0x0000, 0xbfff, MWA_ROM },
422 	{ 0xc000, 0xdfff, MWA_RAM },
423 	{ 0xe000, 0xe22f, K054539_0_w },
424 	{ 0xec00, 0xec00, YM2151_register_port_0_w },
425 	{ 0xec01, 0xec01, YM2151_data_port_0_w },
426 	{ 0xf000, 0xf000, soundlatch3_w },
427 	{ 0xf800, 0xf800, sound_bankswitch_w },
428 MEMORY_END
429 
430 
431 INPUT_PORTS_START( xexex )
432 	PORT_START
433 	PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_COIN1 )
434 	PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_COIN2 )
435 	PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_UNKNOWN )
436 	PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_UNKNOWN )
437 	PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_SERVICE1 )
438 	PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_SERVICE2 )
439 	PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_UNKNOWN )
440 	PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_UNKNOWN )
441 
442 	PORT_START
443 	PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_SPECIAL )	/* EEPROM data */
444 	PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_SPECIAL )	/* EEPROM ready (always 1) */
445 	PORT_BIT( 0x04, IP_ACTIVE_HIGH, IPT_UNKNOWN )
446 	PORT_BITX(0x08, IP_ACTIVE_LOW, IPT_SERVICE, DEF_STR( Service_Mode ), KEYCODE_F2, IP_JOY_NONE )
447 	PORT_BIT( 0xf0, IP_ACTIVE_HIGH, IPT_UNKNOWN )
448 
449 	PORT_START
450 	PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT  | IPF_8WAY | IPF_PLAYER1 )
451 	PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT | IPF_8WAY | IPF_PLAYER1 )
452 	PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_JOYSTICK_UP    | IPF_8WAY | IPF_PLAYER1 )
453 	PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN  | IPF_8WAY | IPF_PLAYER1 )
454 	PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_BUTTON1 | IPF_PLAYER1 )
455 	PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_BUTTON2 | IPF_PLAYER1 )
456 	PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_UNKNOWN )
457 	PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_START1 )
458 
459 	PORT_START
460 	PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT  | IPF_8WAY | IPF_PLAYER2 )
461 	PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT | IPF_8WAY | IPF_PLAYER2 )
462 	PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_JOYSTICK_UP    | IPF_8WAY | IPF_PLAYER2 )
463 	PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN  | IPF_8WAY | IPF_PLAYER2 )
464 	PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_BUTTON1 | IPF_PLAYER2 )
465 	PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_BUTTON2 | IPF_PLAYER2 )
466 	PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_UNKNOWN )
467 	PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_START2 )
468 INPUT_PORTS_END
469 
470 static struct YM2151interface ym2151_interface =
471 {
472 	1,
473 	4000000,	/* 4Mhz (based on AMUSE)*/
474 	{ YM3012_VOL(50,MIXER_PAN_CENTER,50,MIXER_PAN_CENTER) },
475 	{ 0 }
476 };
477 
478 static struct K054539interface k054539_interface =
479 {
480 	1,			/* 1 chip */
481 	48000,
482 	{ REGION_SOUND1 },
483 	{ { 100, 100 } },
484 	{ ym_set_mixing }
485 };
486 
487 static MACHINE_DRIVER_START( xexex )
488 
489 	/* basic machine hardware */
490 	MDRV_CPU_ADD(M68000, 16000000)	/* 16MHz (32MHz xtal)*/
491 	MDRV_CPU_MEMORY(readmem,writemem)
492 	MDRV_CPU_VBLANK_INT(xexex_interrupt,2)
493 
494 	/* 8MHz (PCB shows one 32MHz/18.432MHz xtal, reference: www.system16.com)*/
495 	/* more likely 32MHz since 18.432MHz yields 4.608MHz(too slow) or 9.216MHz(too fast) with integer divisors*/
496 	MDRV_CPU_ADD(Z80, 8000000)
497 
498 	MDRV_CPU_FLAGS(CPU_AUDIO_CPU)
499 	MDRV_CPU_MEMORY(sound_readmem,sound_writemem)
500 
501 	MDRV_INTERLEAVE(32);
502 	MDRV_FRAMES_PER_SECOND(60)
MDRV_VBLANK_DURATION(DEFAULT_60HZ_VBLANK_DURATION)503 	MDRV_VBLANK_DURATION(DEFAULT_60HZ_VBLANK_DURATION)
504 
505 	MDRV_MACHINE_INIT(xexex)
506 	MDRV_NVRAM_HANDLER(xexex)
507 
508 	/* video hardware */
509 	MDRV_VIDEO_ATTRIBUTES(VIDEO_TYPE_RASTER | VIDEO_NEEDS_6BITS_PER_GUN | VIDEO_RGB_DIRECT | VIDEO_HAS_SHADOWS | VIDEO_HAS_HIGHLIGHTS | VIDEO_UPDATE_BEFORE_VBLANK)
510 	MDRV_SCREEN_SIZE(64*8, 32*8)
511 	MDRV_VISIBLE_AREA(40, 40+384-1, 0, 0+256-1)
512 
513 	MDRV_PALETTE_LENGTH(2048)
514 
515 	MDRV_VIDEO_START(xexex)
516 	MDRV_VIDEO_UPDATE(xexex)
517 
518 	/* sound hardware */
519 	MDRV_SOUND_ATTRIBUTES(SOUND_SUPPORTS_STEREO)
520 	MDRV_SOUND_ADD(YM2151, ym2151_interface)
521 	MDRV_SOUND_ADD(K054539, k054539_interface)
522 MACHINE_DRIVER_END
523 
524 
525 ROM_START( xexex )
526 	ROM_REGION( 0x180000, REGION_CPU1, 0 )
527 	ROM_LOAD16_BYTE( "xex_a01.rom",  0x000000, 0x40000, CRC(3ebcb066) SHA1(83a20433d9fdcc8b8d7133991f9a8164dddb61f3) )
528 	ROM_LOAD16_BYTE( "xex_a02.rom",  0x000001, 0x40000, CRC(36ea7a48) SHA1(34f8046d7ecf5ea66c59c5bc0d7627942c28fd3b) )
529 	ROM_LOAD16_BYTE( "xex_b03.rom",  0x100000, 0x40000, CRC(97833086) SHA1(a564f7b1b52c774d78a59f4418c7ecccaf94ad41) )
530 	ROM_LOAD16_BYTE( "xex_b04.rom",  0x100001, 0x40000, CRC(26ec5dc8) SHA1(9da62683bfa8f16607cbea2d59a1446ec8588c5b) )
531 
532 	ROM_REGION( 0x030000, REGION_CPU2, 0 )
533 	ROM_LOAD( "xex_a05.rom", 0x000000, 0x020000, CRC(0e33d6ec) SHA1(4dd68cb78c779e2d035e43fec35a7672ed1c259b) )
534 	ROM_RELOAD(              0x010000, 0x020000 )
535 
536 	ROM_REGION( 0x200000, REGION_GFX1, 0 )
537 	ROM_LOAD( "xex_b14.rom", 0x000000, 0x100000, CRC(02a44bfa) SHA1(ad95df4dbf8842820ef20f54407870afb6d0e4a3) )
538 	ROM_LOAD( "xex_b13.rom", 0x100000, 0x100000, CRC(633c8eb5) SHA1(a11f78003a1dffe2d8814d368155059719263082) )
539 
540 	ROM_REGION( 0x400000, REGION_GFX2, 0 )
541 	ROM_LOAD( "xex_b12.rom", 0x000000, 0x100000, CRC(08d611b0) SHA1(9cac60131e0411f173acd8ef3f206e5e58a7e5d2) )
542 	ROM_LOAD( "xex_b11.rom", 0x100000, 0x100000, CRC(a26f7507) SHA1(6bf717cb9fcad59a2eafda967f14120b9ebbc8c5) )
543 	ROM_LOAD( "xex_b10.rom", 0x200000, 0x100000, CRC(ee31db8d) SHA1(c41874fb8b401ea9cdd327ee6239b5925418cf7b) )
544 	ROM_LOAD( "xex_b09.rom", 0x300000, 0x100000, CRC(88f072ef) SHA1(7ecc04dbcc29b715117e970cc96e11137a21b83a) )
545 
546 	ROM_REGION( 0x100000, REGION_GFX3, 0 ) /* NOTE: region must be 2xROM size for unpacking*/
547 	ROM_LOAD( "xex_b08.rom", 0x000000, 0x080000, CRC(ca816b7b) SHA1(769ce3700e41200c34adec98598c0fe371fe1e6d) )
548 
549 	ROM_REGION( 0x300000, REGION_SOUND1, 0 )
550 	ROM_LOAD( "xex_b06.rom", 0x000000, 0x200000, CRC(3b12fce4) SHA1(c69172d9965b8da8a539812fac92d5f1a3c80d17) )
551 	ROM_LOAD( "xex_b07.rom", 0x200000, 0x100000, CRC(ec87fe1b) SHA1(ec9823aea5a1fc5c47c8262e15e10b28be87231c) )
552 ROM_END
553 
554 ROM_START( xexexj )
555 	ROM_REGION( 0x180000, REGION_CPU1, 0 )
556 	ROM_LOAD16_BYTE( "067jaa01.16d", 0x000000, 0x40000, CRC(06e99784) SHA1(d53fe3724608992a6938c36aa2719dc545d6b89e) )
557 	ROM_LOAD16_BYTE( "067jaa02.16e", 0x000001, 0x40000, CRC(30ae5bc4) SHA1(60491e31eef64a9206d1372afa32d83c6c0968b3) )
558 	ROM_LOAD16_BYTE( "xex_b03.rom",  0x100000, 0x40000, CRC(97833086) SHA1(a564f7b1b52c774d78a59f4418c7ecccaf94ad41) )
559 	ROM_LOAD16_BYTE( "xex_b04.rom",  0x100001, 0x40000, CRC(26ec5dc8) SHA1(9da62683bfa8f16607cbea2d59a1446ec8588c5b) )
560 
561 	ROM_REGION( 0x030000, REGION_CPU2, 0 )
562 	ROM_LOAD( "067jaa05.4e", 0x000000, 0x020000, CRC(2f4dd0a8) SHA1(bfa76c9c968f1beba648a2911510e3d666a8fe3a) )
563 	ROM_RELOAD(              0x010000, 0x020000 )
564 
565 	ROM_REGION( 0x200000, REGION_GFX1, 0 )
566 	ROM_LOAD( "xex_b14.rom", 0x000000, 0x100000, CRC(02a44bfa) SHA1(ad95df4dbf8842820ef20f54407870afb6d0e4a3) )
567 	ROM_LOAD( "xex_b13.rom", 0x100000, 0x100000, CRC(633c8eb5) SHA1(a11f78003a1dffe2d8814d368155059719263082) )
568 
569 	ROM_REGION( 0x400000, REGION_GFX2, 0 )
570 	ROM_LOAD( "xex_b12.rom", 0x000000, 0x100000, CRC(08d611b0) SHA1(9cac60131e0411f173acd8ef3f206e5e58a7e5d2) )
571 	ROM_LOAD( "xex_b11.rom", 0x100000, 0x100000, CRC(a26f7507) SHA1(6bf717cb9fcad59a2eafda967f14120b9ebbc8c5) )
572 	ROM_LOAD( "xex_b10.rom", 0x200000, 0x100000, CRC(ee31db8d) SHA1(c41874fb8b401ea9cdd327ee6239b5925418cf7b) )
573 	ROM_LOAD( "xex_b09.rom", 0x300000, 0x100000, CRC(88f072ef) SHA1(7ecc04dbcc29b715117e970cc96e11137a21b83a) )
574 
575 	ROM_REGION( 0x100000, REGION_GFX3, 0 ) /* NOTE: region must be 2xROM size for unpacking*/
576 	ROM_LOAD( "xex_b08.rom", 0x000000, 0x080000, CRC(ca816b7b) SHA1(769ce3700e41200c34adec98598c0fe371fe1e6d) )
577 
578 	ROM_REGION( 0x300000, REGION_SOUND1, 0 )
579 	ROM_LOAD( "xex_b06.rom", 0x000000, 0x200000, CRC(3b12fce4) SHA1(c69172d9965b8da8a539812fac92d5f1a3c80d17) )
580 	ROM_LOAD( "xex_b07.rom", 0x200000, 0x100000, CRC(ec87fe1b) SHA1(ec9823aea5a1fc5c47c8262e15e10b28be87231c) )
581 ROM_END
582 
583 MACHINE_INIT( xexex )
584 {
585 	cur_sound_region = 0;
586 	suspension_active = 0;
587 }
588 
DRIVER_INIT(xexex)589 static DRIVER_INIT( xexex )
590 {
591 	if (!strcmp(Machine->gamedrv->name, "xexex"))
592 	{
593 		/* Invulnerability*/
594 /*		*(data16_t *)(memory_region(REGION_CPU1) + 0x648d4) = 0x4a79;*/
595 /*		*(data16_t *)(memory_region(REGION_CPU1) + 0x00008) = 0x5500;*/
596 		xexex_strip0x1a = 1;
597 	}
598 
599 	konami_rom_deinterleave_2(REGION_GFX1);
600 	konami_rom_deinterleave_4(REGION_GFX2);
601 	K053250_unpack_pixels(REGION_GFX3);
602 
603 	state_save_register_UINT16("main", 0, "control2", &cur_control2, 1);
604 	state_save_register_func_postload(parse_control2);
605 	state_save_register_int("main", 0, "sound region", &cur_sound_region);
606 	state_save_register_func_postload(reset_sound_region);
607 
608 	resume_trigger = 1000;
609 
610 	dmadelay_timer = timer_alloc(dmaend_callback);
611 
612 	K054539_init_flags(K054539_REVERSE_STEREO);
613 }
614 
615 
616 GAME( 1991, xexex,  0,     xexex, xexex, xexex, ROT0, "Konami", "Xexex (World)" )
617 GAME( 1991, xexexj, xexex, xexex, xexex, xexex, ROT0, "Konami", "Xexex (Japan)" )
618