1 /***************************************************************************
2 						WEC Le Mans 24  &   Hot Chase
3 
4 						  (C)   1986 & 1988 Konami
5 
6 					driver by       Luca Elia (l.elia@tin.it)
7 
8 - Note: press F2 to enter service mode -
9 
10 
11 ----------------------------------------------------------------------
12 Hardware                Main    Sub             Sound   Sound Chips
13 ----------------------------------------------------------------------
14 [WEC Le Mans 24]        68000   68000   Z-80    YM2151 YM3012 1x007232
15 
16 [Hot Chase]             68000   68000   68B09E                3x007232
17 
18 [CPU PCB GX763 350861B]
19 	007641  007770  3x007232  051550
20 
21 [VID PCB GX763 350860A AI AM-1]
22 	007634  007635  3x051316  007558  007557
23 ----------------------------------------------------------------------
24 
25 
26 ----------------------------------------------------------------
27 Main CPU                     [WEC Le Mans 24]     [Hot Chase]
28 ----------------------------------------------------------------
29 ROM                R         000000-03ffff        <
30 Work RAM           RW        040000-043fff        040000-063fff*
31 ?                  RW        060000-060007        -
32 Blitter             W        080000-080011        <
33 Page RAM           RW        100000-103fff        -
34 Text RAM           RW        108000-108fff        -
35 Palette RAM        RW        110000-110fff        110000-111fff**
36 Shared RAM         RW        124000-127fff        120000-123fff
37 Sprites RAM        RW        130000-130fff        <
38 Input Ports        RW        1400xx-1400xx        <
39 Background         RW                             100000-100fff
40 Background Ctrl     W        -                    101000-10101f
41 Foreground         RW        -                    102000-102fff
42 Foreground Ctrl     W        -                    103000-10301f
43 
44 * weird    ** only half used
45 
46 
47 ----------------------------------------------------------------
48 Sub CPU                      [WEC Le Mans 24]     [Hot Chase]
49 ----------------------------------------------------------------
50 
51 ROM                R         000000-00ffff        000000-01ffff
52 Work RAM           RW        -                    060000-060fff
53 Road RAM           RW        060000-060fff        020000-020fff
54 Shared RAM         RW        070000-073fff        040000-043fff
55 
56 
57 ---------------------------------------------------------------------------
58 								Game code
59 							[WEC Le Mans 24]
60 ---------------------------------------------------------------------------
61 
62 					Interesting locations (main cpu)
63 					--------------------------------
64 
65 There's some 68000 assembly code in ASCII around d88 :-)
66 
67 040000+
68 7-9                             *** hi score/10 (BCD 3 bytes) ***
69 b-d                             *** score/10 (BCD 3 bytes) ***
70 1a,127806               <- 140011.b
71 1b,127807               <- 140013.b
72 1c,127808               <- 140013.b
73 1d,127809               <- 140015.b
74 1e,12780a               <- 140017.b
75 1f                      <- 140013.b
76 30                              *** credits ***
77 3a,3b,3c,3d             <-140021.b
78 3a = accelerator   3b = ??   3c = steering   3d = table
79 
80 d2.w                    -> 108f24 fg y scroll
81 112.w                   -> 108f26 bg y scroll
82 
83 16c                             influences 140031.b
84 174                             screen address
85 180                             input port selection (->140003.b ->140021.b)
86 181                     ->140005.b
87 185                             bit 7 high -> must copy sprite data to 130000
88 1dc+(1da).w             ->140001.b
89 
90 40a.w,c.w               *** time (BCD) ***
91 411                             EF if brake, 0 otherwise
92 416                             ?
93 419                             gear: 0=lo,1=hi
94 41e.w                   speed related ->127880
95 424.w                   speed BCD
96 43c.w                   accel?
97 440.w                   level?
98 
99 806.w                   scrollx related
100 80e.w                   scrolly related
101 
102 c08.b                   routine select: 1>1e1a4 2>1e1ec 3>1e19e other>1e288 (map screen)
103 
104 117a.b                  selected letter when entering name in hi-scores
105 117e.w                  cycling color in hi-scores
106 
107 12c0.w                  ?time,pos,len related?
108 12c2.w
109 12c4.w
110 12c6.w
111 
112 1400-1bff               color data (0000-1023 chars)
113 1c00-23ff               color data (1024-2047 sprites?)
114 
115 2400                    Sprite data: 40 entries x  4 bytes =  100
116 2800                    Sprite data: 40 entries x 40 bytes = 1000
117 3800                    Sprite data: 40 entries x 10 bytes =  400
118 
119 					Interesting routines (main cpu)
120 					-------------------------------
121 
122 804                     mem test
123 818                     end mem test (cksums at 100, addresses at A90)
124 82c                     other cpu test
125 a0c                     rom test
126 c1a                     prints string (a1)
127 1028                    end test
128 204c                    print 4*3 box of chars to a1, made up from 2 2*6 (a0)=0xLR (Left,Righ index)
129 4e62                    raws in the fourth page of chars
130 6020                    test screen (print)
131 60d6                    test screen
132 62c4                    motor test?
133 6640                    print input port values ( 6698 = scr_disp.w,ip.b,bit.b[+/-] )
134 
135 819c                    prepares sprite data
136 8526                    blitter: 42400->130000
137 800c                    8580    sprites setup on map screen
138 
139 1833a                   cycle cols on hi-scores
140 18514                   hiscores: main loop
141 185e8                   hiscores: wheel selects letter
142 
143 TRAP#0                  prints string: A0-> addr.l, attr.w, (char.b)*, 0
144 
145 IRQs                    [1,3,6]  602
146 IRQs                    [2,7]    1008->12dc      ORI.W    #$2700,(A7) RTE
147 IRQs                    [4]      1004->124c
148 IRQs                    [5]      106c->1222      calls sequence: $3d24 $1984 $28ca $36d2 $3e78
149 
150 
151 					Interesting locations (sub cpu)
152 					-------------------------------
153 
154 					Interesting routines (sub cpu)
155 					------------------------------
156 
157 1028    'wait for command' loop.
158 1138    lev4 irq
159 1192    copies E0*4 bytes: (a1)+ -> (a0)+
160 
161 
162 ---------------------------------------------------------------------------
163 								 Game code
164 								[Hot Chase]
165 ---------------------------------------------------------------------------
166 
167 This game has been probably coded by the same programmers of WEC Le Mans 24
168 It shares some routines and there is the (hidden?) string "WEC 2" somewhere
169 
170 							Main CPU                Sub CPU
171 
172 Interrupts: [1, 7]          FFFFFFFF                FFFFFFFF
173 Interrupts: [2,3,4,5,6]     221c                    1288
174 
175 Self Test:
176  0] pause,120002==55,pause,120002==AA,pause,120002==CC, (on error set bit d7.0)
177  6] 60000-63fff(d7.1),40000-41fff(d7.2)
178  8] 40000/2<-chksum 0-20000(e/o);40004/6<-chksum 20000-2ffff(e/o) (d7.3456)
179  9] chksums from sub cpu: even->40004   odd->(40006)    (d7.78)
180  A] 110000-111fff(even)(d7.9),102000-102fff(odd)(d7.a)
181  C] 100000-100fff(odd)(d7.b),pause,pause,pause
182 10] 120004==0(d7.c),120006==0(d7.d),130000-1307ff(first $A of every $10 bytes only)(d7.e),pause
183 14] 102000<-hw screen+(d7==0)? jmp 1934/1000
184 15] 195c start of game
185 
186 
187 					Interesting locations (main cpu)
188 					--------------------------------
189 
190 60024.b                 <- !140017.b (DSW 1 - coinage)
191 60025.b                 <- !140015.b (DSW 2 - options)
192 6102c.w                 *** time ***
193 
194 					Interesting routines (main cpu)
195 					-------------------------------
196 
197 18d2                    (d7.d6)?print BAD/OK to (a5)+, jmp(D0)
198 1d58                    print d2.w to (a4)+, jmp(a6)
199 580c                    writes at 60000
200 61fc                    print test strings
201 18cbe                   print "game over"
202 
203 
204 ---------------------------------------------------------------------------
205 								   Issues
206 							  [WEC Le Mans 24]
207 ---------------------------------------------------------------------------
208 
209 - The parallactic scrolling is sometimes wrong
210 
211 
212 ---------------------------------------------------------------------------
213 								   Issues
214 								[Hot Chase]
215 ---------------------------------------------------------------------------
216 
217 - Samples pitch is too low
218 - No zoom and rotation of the layers
219 
220 
221 ---------------------------------------------------------------------------
222 							   Common Issues
223 ---------------------------------------------------------------------------
224 
225 - One ROM unused (32K in hotchase, 16K in wecleman)
226 - Incomplete DSWs
227 - Sprite ram is not cleared by the game and no sprite list end-marker
228   is written. We cope with that with an hack in the Blitter but there
229   must be a register to do the trick
230 
231 
232 Revisions:
233 
234 05-05-2002 David Haywood(Haze)
235 - improved Wec Le Mans steering
236 
237 05-01-2002 Hiromitsu Shioya(Shica)
238 - fixed Hot Chase volume and sound interrupt
239 
240 xx-xx-2003 Acho A. Tang
241 [Wec Le Mans 24]
242 - generalized blitter to support Wec Le Mans
243 - emulated custom alpha blending chip used for protection
244 - fixed game color and sound volume
245 - added shadows and sprite-to-sprite priority
246 - added curbs effect
247 - modified zoom equation to close tile gaps
248 - fixed a few tile glitches
249 - converted driver to use RGB direct
250 - cloud transition(needs verification from board owners)
251 - fixed sound banking
252 - source clean-up
253 
254 TODO:
255 - check dust color on title screen(I don't think it should be black)
256 - check brake light(LED) support
257 - check occational off-pitch music and samples(sound interrupt related?)
258 
259 * Sprite, road and sky drawings do not support 32-bit color depth.
260   Certain sprites with incorrect z-value still pop in front of closer
261   billboards and some appear a few pixels off the ground. They could be
262   the game's intrinsic flaws. (reference: www.system16.com)
263 
264 [Hot Chase]
265 - shared changes with Wec Le Mans
266 - removed junk tiles during introduction(needs verification)
267 
268 * Special thanks to Luca Elia for bringing us so many enjoyable games.
269 
270 ***************************************************************************/
271 
272 #include "driver.h"
273 #include "vidhrdw/generic.h"
274 #include "vidhrdw/konamiic.h"
275 #include "cpu/m6809/m6809.h"
276 
277 /* Variables only used here: */
278 static data16_t *sharedram, *blitter_regs;
279 static int multiply_reg[2];
280 static data16_t *wecleman_protection_ram;
281 static int spr_color_offs;
282 
283 /* Variables that vidhrdw has acces to: */
284 int wecleman_selected_ip, wecleman_irqctrl;
285 
286 /* Variables defined in vidhrdw: */
287 extern data16_t *wecleman_videostatus;
288 extern data16_t *wecleman_pageram, *wecleman_txtram, *wecleman_roadram;
289 extern size_t wecleman_roadram_size;
290 extern int wecleman_bgpage[4], wecleman_fgpage[4], *wecleman_gfx16_RAM;
291 
292 /* Functions defined in vidhrdw: */
293 WRITE16_HANDLER( hotchase_paletteram16_SBGRBBBBGGGGRRRR_word_w );
294 WRITE16_HANDLER( wecleman_paletteram16_SSSSBBBBGGGGRRRR_word_w );
295 WRITE16_HANDLER( wecleman_videostatus_w );
296 READ16_HANDLER( wecleman_pageram_r );
297 WRITE16_HANDLER( wecleman_pageram_w );
298 READ16_HANDLER( wecleman_txtram_r );
299 WRITE16_HANDLER( wecleman_txtram_w );
300 VIDEO_UPDATE( wecleman );
301 VIDEO_START( wecleman );
302 VIDEO_UPDATE( hotchase );
303 VIDEO_START( hotchase );
304 
305 
306 /***************************************************************************
307 							Common Routines
308 ***************************************************************************/
309 
READ16_HANDLER(wecleman_protection_r)310 static READ16_HANDLER( wecleman_protection_r )
311 {
312 	int blend, data0, data1, r0, g0, b0, r1, g1, b1;
313 
314 	data0 = wecleman_protection_ram[0];
315 	blend = wecleman_protection_ram[2];
316 	data1 = wecleman_protection_ram[1];
317 	blend &= 0x3ff;
318 
319 	/* a precalculated table will take an astronomical 4096^2(colors) x 1024(steps) x 2(word) bytes*/
320 	r0 = data0;  g0 = data0;  b0 = data0;
321 	r0 &= 0xf;   g0 &= 0xf0;  b0 &= 0xf00;
322 	r1 = data1;  g1 = data1;  b1 = data1;
323 	r1 &= 0xf;   g1 &= 0xf0;  b1 &= 0xf00;
324 	r1 -= r0;    g1 -= g0;    b1 -= b0;
325 	r1 *= blend; g1 *= blend; b1 *= blend;
326 	r1 >>= 10;   g1 >>= 10;   b1 >>= 10;
327 	r0 += r1;    g0 += g1;    b0 += b1;
328 	g0 &= 0xf0;  b0 &= 0xf00;
329 
330 	r0 |= g0;
331 	r0 |= b0;
332 
333 	return(r0);
334 }
335 
WRITE16_HANDLER(wecleman_protection_w)336 static WRITE16_HANDLER( wecleman_protection_w )
337 {
338 	static int state = 0;
339 
340 	if (offset == 2) state = data & 0x2000;
341 	if (!state) COMBINE_DATA(wecleman_protection_ram + offset);
342 }
343 
344 
345 /* Data is read from and written to *sharedram* */
READ16_HANDLER(sharedram_r)346 static READ16_HANDLER( sharedram_r )    { return sharedram[offset]; }
WRITE16_HANDLER(sharedram_w)347 static WRITE16_HANDLER( sharedram_w )   { COMBINE_DATA(&sharedram[offset]); }
348 
349 
350 /* 140005.b (WEC Le Mans 24 Schematics)
351 
352  COMMAND
353  ___|____
354 |   CK  8|--/        7
355 | LS273 7| TV-KILL   6
356 |       6| SCR-VCNT  5
357 |       5| SCR-HCNT  4
358 |   5H  4| SOUND-RST 3
359 |       3| SOUND-ON  2
360 |       2| NSUBRST   1
361 |       1| SUBINT    0
362 |__CLR___|
363 	|
364   NEXRES
365 
366  Schems: SUBRESET does a RST+HALT
367          Sub CPU IRQ 4 generated by SUBINT, no other IRQs
368 */
WRITE16_HANDLER(irqctrl_w)369 static WRITE16_HANDLER( irqctrl_w )
370 {
371 	if (ACCESSING_LSB)
372 	{
373 		/* log_cb(RETRO_LOG_DEBUG, LOGPRE "CPU #0 - PC = %06X - $140005 <- %02X (old value: %02X)\n",activecpu_get_pc(), data&0xFF, old_data&0xFF);*/
374 
375 		/* Bit 0 : SUBINT*/
376 		if ( (wecleman_irqctrl & 1) && (!(data & 1)) )	/* 1->0 transition*/
377 			cpu_set_irq_line(1,4,HOLD_LINE);
378 
379 		/* Bit 1 : NSUBRST*/
380 		if (data & 2)   cpu_set_reset_line(1, CLEAR_LINE  );
381 		else                    cpu_set_reset_line(1, ASSERT_LINE );
382 
383 		/* Bit 2 : SOUND-ON*/
384 		/* Bit 3 : SOUNDRST*/
385 		/* Bit 4 : SCR-HCNT*/
386 		/* Bit 5 : SCR-VCNT*/
387 		/* Bit 6 : TV-KILL*/
388 		wecleman_irqctrl = data;	/* latch the value*/
389 	}
390 }
391 
392 /* 140003.b (usually paired with a write to 140021.b)
393 
394 	Bit:
395 
396 	7-------        ?
397 	-65-----        input selection (0-3)
398 	---43---        ?
399 	-----2--        start light
400 	------10        ? out 1/2
401 
402 */
WRITE16_HANDLER(selected_ip_w)403 static WRITE16_HANDLER( selected_ip_w )
404 {
405 	if (ACCESSING_LSB) wecleman_selected_ip = data & 0xff;	/* latch the value*/
406 }
407 
408 /* $140021.b - Return the previously selected input port's value */
READ16_HANDLER(selected_ip_r)409 static READ16_HANDLER( selected_ip_r )
410 {
411 	switch ( (wecleman_selected_ip >> 5) & 3 )
412 	{												/* From WEC Le Mans Schems:*/
413 		case 0:  return input_port_4_r(offset);		/* Accel - Schems: Accelevr*/
414 		case 1:  return ~0;							/* ????? - Schems: Not Used*/
415 		case 2:  return input_port_5_r(offset);		/* Wheel - Schems: Handlevr*/
416 		case 3:  return ~0;							/* Table - Schems: Turnvr*/
417 
418 		default: return ~0;
419 	}
420 }
421 
422 /* Word Blitter - Copies data around (Work RAM, Sprite RAM etc.)
423                   It's fed with a list of blits to do
424 
425 	Offset:
426 
427 	00.b            ? Number of words - 1 to add to address per transfer
428 	01.b            ? logic function / blit mode
429 	02.w            ? (always 0)
430 	04.l            Source address (Base address of source data)
431 	08.l            List of blits address
432 	0c.l            Destination address
433 	01.b            ? Number of transfers
434 	10.b            Triggers the blit
435 	11.b            Number of words per transfer
436 
437 	The list contains 4 bytes per blit:
438 
439 
440 	Offset:
441 
442 	00.w            ?
443 	02.w            offset from Base address
444 
445 
446 	Note:
447 
448 	Hot Chase explicitly copies color information from sprite parameters back to list[4n+1](byte ptr)
449 	and that tips me off where the colors are actually encoded. List[4n+0] is believed to hold the
450 	sprites' depth value. Wec Le Mans will z-sort the sprites before writing them to video RAM but
451 	the order is not always right. It is possible the video hardware performs additional sorting.
452 
453 	The color code in the original sprite encoding has special meanings on the other hand. I'll take
454 	a shortcut by manually copying list[0] and list[1] to sprite RAM for further process.
455 */
WRITE16_HANDLER(blitter_w)456 static WRITE16_HANDLER( blitter_w )
457 {
458 	COMBINE_DATA(&blitter_regs[offset]);
459 
460 	/* do a blit if $80010.b has been written */
461 	if ( (offset == 0x10/2) && (ACCESSING_MSB) )
462 	{
463 		/* 80000.b = ?? usually 0 - other values: 02 ; 00 - ? logic function ? */
464 		/* 80001.b = ?? usually 0 - other values: 3f ; 01 - ? height ? */
465 		int minterm  = ( blitter_regs[0x0/2] & 0xFF00 ) >> 8;
466 		int list_len = ( blitter_regs[0x0/2] & 0x00FF ) >> 0;
467 
468 		/* 80002.w = ?? always 0 - ? increment per horizontal line ? */
469 		/* no proof at all, it's always 0 */
470 		/*int srcdisp = blitter_regs[0x2/2] & 0xFF00;*/
471 		/*int destdisp = blitter_regs[0x2/2] & 0x00FF;*/
472 
473 		/* 80004.l = source data address */
474 		int src  = ( blitter_regs[0x4/2] << 16 ) + blitter_regs[0x6/2];
475 
476 		/* 80008.l = list of blits address */
477 		int list = ( blitter_regs[0x8/2] << 16 ) + blitter_regs[0xA/2];
478 
479 		/* 8000C.l = destination address */
480 		int dest = ( blitter_regs[0xC/2] << 16 ) + blitter_regs[0xE/2];
481 
482 		/* 80010.b = number of words to move */
483 		int size = ( blitter_regs[0x10/2] ) & 0x00FF;
484 
485 		/* Word aligned transfers only ?? */
486 		src  &= (~1);   list &= (~1);    dest &= (~1);
487 
488 		/* Two minterms / blit modes are used */
489 		if (minterm != 2)
490 		{
491 			/* One single blit */
492 			for ( ; size > 0 ; size--)
493 			{
494 				/* maybe slower than a memcpy but safer (and errors are logged) */
495 				cpu_writemem24bew_word(dest,cpu_readmem24bew_word(src));
496 				src += 2;
497 				dest += 2;
498 			}
499 		}
500 		else
501 		{
502 			/* Number of blits in the list */
503 			for ( ; list_len > 0 ; list_len-- )
504 			{
505 				int i, j, destptr;
506 
507 				/* Read offset of source from the list of blits */
508 				i = src + cpu_readmem24bew_word(list+2);
509 				j = i + (size<<1);
510 				destptr = dest;
511 
512 				for (; i<j; destptr+=2, i+=2)
513 					cpu_writemem24bew_word(destptr, cpu_readmem24bew_word(i));
514 
515 				destptr = dest + 14;
516 				i = cpu_readmem24bew_word(list) + spr_color_offs;
517 				cpu_writemem24bew_word(destptr, i);
518 
519 				dest += 16;
520 				list += 4;
521 			}
522 
523 			/* hack for the blit to Sprites RAM - Sprite list end-marker */
524 			cpu_writemem24bew_word(dest,0xFFFF);
525 		}
526 	}
527 }
528 
529 
530 /***************************************************************************
531 					WEC Le Mans 24 Main CPU Handlers
532 ***************************************************************************/
533 
534 static WRITE16_HANDLER( wecleman_soundlatch_w );
535 
MEMORY_READ16_START(wecleman_readmem)536 static MEMORY_READ16_START( wecleman_readmem )
537 	{ 0x000000, 0x03ffff, MRA16_ROM             },	/* ROM*/
538 	{ 0x040000, 0x043fff, MRA16_RAM             },	/* RAM*/
539 	{ 0x060006, 0x060007, wecleman_protection_r },	/* MCU read*/
540 	{ 0x080000, 0x080011, MRA16_RAM             },	/* Blitter (reading is for debug)*/
541 	{ 0x100000, 0x103fff, MRA16_RAM             },	/* Background Layers*/
542 	{ 0x108000, 0x108fff, MRA16_RAM             },	/* Text Layer*/
543 	{ 0x110000, 0x110fff, MRA16_RAM             },	/* Palette*/
544 	{ 0x124000, 0x127fff, sharedram_r           },	/* Shared with sub CPU*/
545 	{ 0x130000, 0x130fff, MRA16_RAM             },	/* Sprites*/
546 	/* Input Ports:*/
547 	{ 0x140010, 0x140011, input_port_0_word_r },	/* Coins + brake + gear*/
548 	{ 0x140012, 0x140013, input_port_1_word_r },	/* ??*/
549 	{ 0x140014, 0x140015, input_port_2_word_r },	/* DSW*/
550 	{ 0x140016, 0x140017, input_port_3_word_r },	/* DSW*/
551 	{ 0x140020, 0x140021, selected_ip_r       },	/* Accelerator or Wheel or ..*/
552 MEMORY_END
553 
554 static MEMORY_WRITE16_START( wecleman_writemem )
555 	{ 0x000000, 0x03ffff, MWA16_ROM                             },	/* ROM (03c000-03ffff used as RAM sometimes!)*/
556 	{ 0x040494, 0x040495, wecleman_videostatus_w, &wecleman_videostatus },	/* cloud blending control (HACK)*/
557 	{ 0x040000, 0x043fff, MWA16_RAM                             },	/* RAM*/
558 	{ 0x060000, 0x060005, wecleman_protection_w, &wecleman_protection_ram },
559 	{ 0x080000, 0x080011, blitter_w,          &blitter_regs     },	/* Blitter*/
560 	{ 0x100000, 0x103fff, wecleman_pageram_w, &wecleman_pageram },	/* Background Layers*/
561 	{ 0x108000, 0x108fff, wecleman_txtram_w,  &wecleman_txtram  },	/* Text Layer*/
562 	{ 0x110000, 0x110fff, wecleman_paletteram16_SSSSBBBBGGGGRRRR_word_w, &paletteram16 },
563 	{ 0x124000, 0x127fff, sharedram_w,        &sharedram        },	/* Shared with main CPU*/
564 	{ 0x130000, 0x130fff, MWA16_RAM,          &spriteram16,     },	/* Sprites*/
565 	{ 0x140000, 0x140001, wecleman_soundlatch_w                 },	/* To sound CPU*/
566 	{ 0x140002, 0x140003, selected_ip_w                         },	/* Selects accelerator / wheel / ..*/
567 	{ 0x140004, 0x140005, irqctrl_w                             },	/* Main CPU controls the other CPUs*/
568 	{ 0x140006, 0x140007, MWA16_NOP                             },	/* Watchdog reset*/
569 	{ 0x140020, 0x140021, MWA16_RAM                             },	/* Paired with writes to $140003*/
570 	{ 0x140030, 0x140031, MWA16_NOP },	/* toggles between 0 & 1 on hitting bumps and crashes (vibration?)*/
571 MEMORY_END
572 
573 
574 /***************************************************************************
575 						Hot Chase Main CPU Handlers
576 ***************************************************************************/
577 
578 static READ16_HANDLER( hotchase_K051316_0_r )
579 {
580 	return K051316_0_r(offset) & 0xff;
581 }
582 
READ16_HANDLER(hotchase_K051316_1_r)583 static READ16_HANDLER( hotchase_K051316_1_r )
584 {
585 	return K051316_1_r(offset) & 0xff;
586 }
587 
WRITE16_HANDLER(hotchase_K051316_0_w)588 static WRITE16_HANDLER( hotchase_K051316_0_w )
589 {
590 	if (ACCESSING_LSB)      K051316_0_w(offset, data & 0xff);
591 }
592 
WRITE16_HANDLER(hotchase_K051316_1_w)593 static WRITE16_HANDLER( hotchase_K051316_1_w )
594 {
595 	if (ACCESSING_LSB)      K051316_1_w(offset, data & 0xff);
596 }
597 
WRITE16_HANDLER(hotchase_K051316_ctrl_0_w)598 static WRITE16_HANDLER( hotchase_K051316_ctrl_0_w )
599 {
600 	if (ACCESSING_LSB)      K051316_ctrl_0_w(offset, data & 0xff);
601 }
602 
WRITE16_HANDLER(hotchase_K051316_ctrl_1_w)603 static WRITE16_HANDLER( hotchase_K051316_ctrl_1_w )
604 {
605 	if (ACCESSING_LSB)      K051316_ctrl_1_w(offset, data & 0xff);
606 }
607 
608 WRITE16_HANDLER( hotchase_soundlatch_w );
609 
MEMORY_READ16_START(hotchase_readmem)610 static MEMORY_READ16_START( hotchase_readmem )
611 	{ 0x000000, 0x03ffff, MRA16_ROM                         },	/* ROM*/
612 	{ 0x040000, 0x063fff, MRA16_RAM                         },	/* RAM (weird size!?)*/
613 	{ 0x080000, 0x080011, MRA16_RAM                         },	/* Blitter*/
614 	{ 0x100000, 0x100fff, hotchase_K051316_0_r              },	/* Background*/
615 	{ 0x102000, 0x102fff, hotchase_K051316_1_r              },	/* Foreground*/
616 	{ 0x110000, 0x111fff, MRA16_RAM                         },	/* Palette (only the first 2048 colors used)*/
617 	{ 0x120000, 0x123fff, sharedram_r                       },	/* Shared with sub CPU*/
618 	{ 0x130000, 0x130fff, MRA16_RAM                         },	/* Sprites*/
619 	/* Input Ports:*/
620 	{ 0x140006, 0x140007, MRA16_NOP                         },	/* Watchdog reset*/
621 	{ 0x140010, 0x140011, input_port_0_word_r               },	/* Coins + brake + gear*/
622 	{ 0x140012, 0x140013, input_port_1_word_r               },	/* ?? bit 4 from sound cpu*/
623 	{ 0x140014, 0x140015, input_port_2_word_r               },	/* DSW 2*/
624 	{ 0x140016, 0x140017, input_port_3_word_r               },	/* DSW 1*/
625 	{ 0x140020, 0x140021, selected_ip_r                     },	/* Accelerator or Wheel*/
626 	{ 0x140022, 0x140023, MRA16_NOP                         },	/* ??*/
627 MEMORY_END
628 
629 static MEMORY_WRITE16_START( hotchase_writemem )
630 	{ 0x000000, 0x03ffff, MWA16_ROM                 },	/* ROM*/
631 	{ 0x040000, 0x063fff, MWA16_RAM                 },	/* RAM (weird size!?)*/
632 	{ 0x080000, 0x080011, blitter_w, &blitter_regs  },	/* Blitter*/
633 	{ 0x100000, 0x100fff, hotchase_K051316_0_w      },	/* Background*/
634 	{ 0x101000, 0x10101f, hotchase_K051316_ctrl_0_w },	/* Background Ctrl*/
635 	{ 0x102000, 0x102fff, hotchase_K051316_1_w      },	/* Foreground*/
636 	{ 0x103000, 0x10301f, hotchase_K051316_ctrl_1_w },	/* Foreground Ctrl*/
637 	{ 0x110000, 0x111fff, hotchase_paletteram16_SBGRBBBBGGGGRRRR_word_w, &paletteram16 },
638 	{ 0x120000, 0x123fff, sharedram_w, &sharedram   },	/* Shared with sub CPU*/
639 	{ 0x130000, 0x130fff, MWA16_RAM, &spriteram16   },	/* Sprites*/
640 	/* Input Ports:*/
641 	{ 0x140000, 0x140001, hotchase_soundlatch_w     },	/* To sound CPU*/
642 	{ 0x140002, 0x140003, selected_ip_w             },	/* Selects accelerator / wheel /*/
643 	{ 0x140004, 0x140005, irqctrl_w                 },	/* Main CPU controls the other CPUs*/
644 	{ 0x140020, 0x140021, MWA16_NOP                 },	/* Paired with writes to $140003*/
645 	{ 0x140030, 0x140031, MWA16_NOP                 },	/* signal to cabinet vibration motors?*/
646 MEMORY_END
647 
648 
649 /***************************************************************************
650 					WEC Le Mans 24 Sub CPU Handlers
651 ***************************************************************************/
652 
653 static MEMORY_READ16_START( wecleman_sub_readmem )
654 	{ 0x000000, 0x00ffff, MRA16_ROM    },	/* ROM*/
655 	{ 0x060000, 0x060fff, MRA16_RAM    },	/* Road*/
656 	{ 0x070000, 0x073fff, &sharedram_r },	/* RAM (Shared with main CPU)*/
657 MEMORY_END
658 
659 static MEMORY_WRITE16_START( wecleman_sub_writemem )
660 	{ 0x000000, 0x00ffff, MWA16_ROM    },	/* ROM*/
661 	{ 0x060000, 0x060fff, MWA16_RAM, &wecleman_roadram, &wecleman_roadram_size },	/* Road*/
662 	{ 0x070000, 0x073fff, sharedram_w  },	/* RAM (Shared with main CPU)*/
663 MEMORY_END
664 
665 
666 /***************************************************************************
667 						Hot Chase Sub CPU Handlers
668 ***************************************************************************/
669 
670 static MEMORY_READ16_START( hotchase_sub_readmem )
671 	{ 0x000000, 0x01ffff, MRA16_ROM    },	/* ROM*/
672 	{ 0x020000, 0x020fff, MRA16_RAM    },	/* Road*/
673 	{ 0x060000, 0x060fff, MRA16_RAM    },	/* RAM*/
674 	{ 0x040000, 0x043fff, &sharedram_r },	/* Shared with main CPU*/
675 MEMORY_END
676 
677 static MEMORY_WRITE16_START( hotchase_sub_writemem )
678 	{ 0x000000, 0x01ffff, MWA16_ROM    },	/* ROM*/
679 	{ 0x020000, 0x020fff, MWA16_RAM, &wecleman_roadram, &wecleman_roadram_size },	/* Road*/
680 	{ 0x060000, 0x060fff, MWA16_RAM    },	/* RAM*/
681 	{ 0x040000, 0x043fff, sharedram_w  },	/* Shared with main CPU*/
682 MEMORY_END
683 
684 
685 /***************************************************************************
686 					WEC Le Mans 24 Sound CPU Handlers
687 ***************************************************************************/
688 
689 /* 140001.b */
690 WRITE16_HANDLER( wecleman_soundlatch_w )
691 {
692 	if (ACCESSING_LSB)
693 	{
694 		soundlatch_w(0,data & 0xFF);
695 		cpu_set_irq_line(2,0, HOLD_LINE);
696 	}
697 }
698 
699 /* Protection - an external multiplyer connected to the sound CPU */
READ_HANDLER(multiply_r)700 READ_HANDLER( multiply_r )
701 {
702 	return (multiply_reg[0] * multiply_reg[1]) & 0xFF;
703 }
704 
WRITE_HANDLER(multiply_w)705 WRITE_HANDLER( multiply_w )
706 {
707 	multiply_reg[offset] = data;
708 }
709 
710 /*      K007232 registers reminder:
711 
712 [Ch A]  [Ch B]  [Meaning]
713 00      06      address step    (low  byte)
714 01      07      address step    (high byte, max 1)
715 02      08      sample address  (low  byte)
716 03      09      sample address  (mid  byte)
717 04      0a      sample address  (high byte, max 1 -> max rom size: $20000)
718 05      0b      Reading this byte triggers the sample
719 
720 [Ch A & B]
721 0c              volume
722 0d              play sample once or looped (2 channels -> 2 bits (0&1))
723 
724 ** sample playing ends when a byte with bit 7 set is reached **/
725 
WRITE_HANDLER(wecleman_K00723216_bank_w)726 WRITE_HANDLER( wecleman_K00723216_bank_w )
727 {
728 	K007232_set_bank( 0, 0, ~data&1 );	/** (wecleman062gre)*/
729 }
730 
MEMORY_READ_START(wecleman_sound_readmem)731 static MEMORY_READ_START( wecleman_sound_readmem )
732 	{ 0x0000, 0x7fff, MRA_ROM                },	/* ROM*/
733 	{ 0x8000, 0x83ff, MRA_RAM                },	/* RAM*/
734 	{ 0x9000, 0x9000, multiply_r             },	/* Protection*/
735 	{ 0xa000, 0xa000, soundlatch_r           },	/* From main CPU*/
736 	{ 0xb000, 0xb00d, K007232_read_port_0_r  },	/* K007232 (Reading offset 5/b triggers the sample)*/
737 	{ 0xc001, 0xc001, YM2151_status_port_0_r },	/* YM2151*/
738 MEMORY_END
739 
740 static MEMORY_WRITE_START( wecleman_sound_writemem )
741 	{ 0x0000, 0x7fff, MWA_ROM                   },	/* ROM*/
742 	{ 0x8000, 0x83ff, MWA_RAM                   },	/* RAM*/
743 	{ 0x8500, 0x8500, MWA_NOP                   },	/* incresed with speed (global volume)?*/
744 	{ 0x9000, 0x9001, multiply_w                },	/* Protection*/
745 	{ 0x9006, 0x9006, MWA_NOP                   },	/* ?*/
746 	{ 0xb000, 0xb00d, K007232_write_port_0_w    },	/* K007232*/
747 	{ 0xc000, 0xc000, YM2151_register_port_0_w  },	/* YM2151*/
748 	{ 0xc001, 0xc001, YM2151_data_port_0_w      },
749 	{ 0xf000, 0xf000, wecleman_K00723216_bank_w },	/* Samples banking*/
750 MEMORY_END
751 
752 
753 /***************************************************************************
754 						Hot Chase Sound CPU Handlers
755 ***************************************************************************/
756 
757 /* 140001.b */
758 WRITE16_HANDLER( hotchase_soundlatch_w )
759 {
760 	if (ACCESSING_LSB)
761 	{
762 		soundlatch_w(0,data & 0xFF);
763 		cpu_set_irq_line(2,M6809_IRQ_LINE, HOLD_LINE);
764 	}
765 }
766 
767 static struct K007232_interface hotchase_k007232_interface =
768 {
769 	3,
770 	3579545,	/* clock */
771 	{ REGION_SOUND1, REGION_SOUND2, REGION_SOUND3 },
772 	{ K007232_VOL( 20,MIXER_PAN_CENTER, 20,MIXER_PAN_CENTER ),
773 	  K007232_VOL( 20,MIXER_PAN_LEFT,   20,MIXER_PAN_RIGHT  ),
774 	  K007232_VOL( 20,MIXER_PAN_LEFT,   20,MIXER_PAN_RIGHT  ) },
775 	{ 0,0,0 }
776 };
777 
WRITE_HANDLER(hotchase_sound_control_w)778 WRITE_HANDLER( hotchase_sound_control_w )
779 {
780 	int reg[8];
781 
782 	reg[offset] = data;
783 
784 	switch (offset)
785 	{
786 		case 0x0:
787 		case 0x1:
788 		case 0x2:
789 		case 0x3:
790 		case 0x4:
791 		case 0x5:
792 			/* change volume
793 				offset 00000xxx----- channel select (0:channel 0, 1:channel 1)
794 				++------ chip select ( 0:chip 1, 1:chip2, 2:chip3)
795 				data&0x0f left volume  (data>>4)&0x0f right volume
796 			*/
797 		  K007232_set_volume( offset>>1, offset&1,  (data&0x0f) * 0x08, (data>>4) * 0x08 );
798 		  break;
799 
800 		case 0x06:	/* Bankswitch for chips 0 & 1 */
801 		{
802 			int bank0_a = (data >> 1) & 1;
803 			int bank1_a = (data >> 2) & 1;
804 			int bank0_b = (data >> 3) & 1;
805 			int bank1_b = (data >> 4) & 1;
806 			/* bit 6: chip 2 - ch0 ?*/
807 			/* bit 7: chip 2 - ch1 ?*/
808 
809 			K007232_set_bank( 0, bank0_a, bank0_b );
810 			K007232_set_bank( 1, bank1_a, bank1_b );
811 		}
812 		break;
813 
814 		case 0x07:	/* Bankswitch for chip 2 */
815 		{
816 			int bank2_a = (data >> 0) & 7;
817 			int bank2_b = (data >> 3) & 7;
818 
819 			K007232_set_bank( 2, bank2_a, bank2_b );
820 		}
821 		break;
822 	}
823 }
824 
825 /* Read and write handlers for one K007232 chip:
826    even and odd register are mapped swapped */
827 #define HOTCHASE_K007232_RW(_chip_) \
828 READ_HANDLER( hotchase_K007232_##_chip_##_r ) \
829 { \
830 	return K007232_read_port_##_chip_##_r(offset ^ 1); \
831 } \
832 WRITE_HANDLER( hotchase_K007232_##_chip_##_w ) \
833 { \
834 	K007232_write_port_##_chip_##_w(offset ^ 1, data); \
835 } \
836 
837 /* 3 x K007232 */
838 HOTCHASE_K007232_RW(0)
839 HOTCHASE_K007232_RW(1)
840 HOTCHASE_K007232_RW(2)
841 
MEMORY_READ_START(hotchase_sound_readmem)842 static MEMORY_READ_START( hotchase_sound_readmem )
843 	{ 0x0000, 0x07ff, MRA_RAM              },	/* RAM*/
844 	{ 0x1000, 0x100d, hotchase_K007232_0_r },	/* 3 x  K007232*/
845 	{ 0x2000, 0x200d, hotchase_K007232_1_r },
846 	{ 0x3000, 0x300d, hotchase_K007232_2_r },
847 	{ 0x6000, 0x6000, soundlatch_r         },	/* From main CPU (Read on IRQ)*/
848 	{ 0x8000, 0xffff, MRA_ROM              },	/* ROM*/
849 MEMORY_END
850 
851 static MEMORY_WRITE_START( hotchase_sound_writemem )
852 	{ 0x0000, 0x07ff, MWA_RAM                  },	/* RAM*/
853 	{ 0x1000, 0x100d, hotchase_K007232_0_w     },	/* 3 x K007232*/
854 	{ 0x2000, 0x200d, hotchase_K007232_1_w     },
855 	{ 0x3000, 0x300d, hotchase_K007232_2_w     },
856 	{ 0x4000, 0x4007, hotchase_sound_control_w },	/* Sound volume, banking, etc.*/
857 	{ 0x5000, 0x5000, MWA_NOP                  },	/* ? (written with 0 on IRQ, 1 on FIRQ)*/
858 	{ 0x7000, 0x7000, MWA_NOP                  },	/* Command acknowledge ?*/
859 	{ 0x8000, 0xffff, MWA_ROM                  },	/* ROM*/
860 MEMORY_END
861 
862 
863 /***************************************************************************
864 						WEC Le Mans 24 Input Ports
865 ***************************************************************************/
866 
867 INPUT_PORTS_START( wecleman )
868 	PORT_START	/* IN0 - Controls and Coins - $140011.b */
869 	PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_COIN1 )
870 	PORT_BIT( 0x02, IP_ACTIVE_HIGH, IPT_COIN2 )
871 	PORT_SERVICE_NO_TOGGLE( 0x04, IP_ACTIVE_HIGH )
872 	PORT_BIT( 0x08, IP_ACTIVE_HIGH, IPT_SERVICE1 )
873 	PORT_BIT( 0x10, IP_ACTIVE_HIGH, IPT_START1 )
874 	PORT_BITX(0x20, IP_ACTIVE_HIGH, IPT_BUTTON3 | IPF_TOGGLE, "Shift", IP_KEY_DEFAULT, IP_JOY_DEFAULT )
875 	PORT_BITX(0x40, IP_ACTIVE_HIGH, IPT_BUTTON2, "Brake", IP_KEY_DEFAULT, IP_JOY_DEFAULT )
876 	PORT_BIT( 0x80, IP_ACTIVE_HIGH, IPT_UNUSED )
877 
878 	PORT_START	/* IN1 - Motor? - $140013.b */
879 	PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_SERVICE2 )	/* right sw*/
880 	PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_SERVICE3 )	/* left sw*/
881 	PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_SERVICE4 )	/* thermo*/
882 	PORT_BIT( 0x08, IP_ACTIVE_HIGH, IPT_SPECIAL )	/* from sound cpu ?*/
883 	PORT_BIT( 0xf0, IP_ACTIVE_LOW, IPT_UNKNOWN )
884 
885 	PORT_START	/* IN2 - DSW A (Coinage) - $140015.b */
886 	PORT_DIPNAME( 0x0f, 0x0f, DEF_STR( Coin_A ) )
887 	PORT_DIPSETTING(    0x02, DEF_STR( 4C_1C ) )
888 	PORT_DIPSETTING(    0x05, DEF_STR( 3C_1C ) )
889 	PORT_DIPSETTING(    0x08, DEF_STR( 2C_1C ) )
890 	PORT_DIPSETTING(    0x04, DEF_STR( 3C_2C ) )
891 	PORT_DIPSETTING(    0x01, DEF_STR( 4C_3C ) )
892 	PORT_DIPSETTING(    0x0f, DEF_STR( 1C_1C ) )
893 	PORT_DIPSETTING(    0x03, DEF_STR( 3C_4C ) )
894 	PORT_DIPSETTING(    0x07, DEF_STR( 2C_3C ) )
895 	PORT_DIPSETTING(    0x0e, DEF_STR( 1C_2C ) )
896 	PORT_DIPSETTING(    0x06, DEF_STR( 2C_5C ) )
897 	PORT_DIPSETTING(    0x0d, DEF_STR( 1C_3C ) )
898 	PORT_DIPSETTING(    0x0c, DEF_STR( 1C_4C ) )
899 	PORT_DIPSETTING(    0x0b, DEF_STR( 1C_5C ) )
900 	PORT_DIPSETTING(    0x0a, DEF_STR( 1C_6C ) )
901 	PORT_DIPSETTING(    0x09, DEF_STR( 1C_7C ) )
902 	PORT_DIPSETTING(    0x00, DEF_STR( Free_Play ) )
903 	PORT_DIPNAME( 0xf0, 0xf0, DEF_STR( Coin_B ) )
904 	PORT_DIPSETTING(    0x20, DEF_STR( 4C_1C ) )
905 	PORT_DIPSETTING(    0x50, DEF_STR( 3C_1C ) )
906 	PORT_DIPSETTING(    0x80, DEF_STR( 2C_1C ) )
907 	PORT_DIPSETTING(    0x40, DEF_STR( 3C_2C ) )
908 	PORT_DIPSETTING(    0x10, DEF_STR( 4C_3C ) )
909 	PORT_DIPSETTING(    0xf0, DEF_STR( 1C_1C ) )
910 	PORT_DIPSETTING(    0x30, DEF_STR( 3C_4C ) )
911 	PORT_DIPSETTING(    0x70, DEF_STR( 2C_3C ) )
912 	PORT_DIPSETTING(    0xe0, DEF_STR( 1C_2C ) )
913 	PORT_DIPSETTING(    0x60, DEF_STR( 2C_5C ) )
914 	PORT_DIPSETTING(    0xd0, DEF_STR( 1C_3C ) )
915 	PORT_DIPSETTING(    0xc0, DEF_STR( 1C_4C ) )
916 	PORT_DIPSETTING(    0xb0, DEF_STR( 1C_5C ) )
917 	PORT_DIPSETTING(    0xa0, DEF_STR( 1C_6C ) )
918 	PORT_DIPSETTING(    0x90, DEF_STR( 1C_7C ) )
919 
920 	PORT_START	/* IN3 - DSW B (options) - $140017.b */
921 	PORT_DIPNAME( 0x01, 0x01, "Speed Unit" )
922 	PORT_DIPSETTING(    0x01, "km/h" )
923 	PORT_DIPSETTING(    0x00, "mph" )
924 	PORT_DIPNAME( 0x02, 0x02, "Unknown B-1" )	/* single*/
925 	PORT_DIPSETTING(    0x02, DEF_STR( Off ) )
926 	PORT_DIPSETTING(    0x00, DEF_STR( On ) )
927 	PORT_DIPNAME( 0x04, 0x04, "Unknown B-2" )
928 	PORT_DIPSETTING(    0x04, DEF_STR( Off ) )
929 	PORT_DIPSETTING(    0x00, DEF_STR( On ) )
930 	PORT_DIPNAME( 0x18, 0x18, DEF_STR( Difficulty ) )
931 	PORT_DIPSETTING(    0x18, "Easy" )		/* 66 seconds at the start*/
932 	PORT_DIPSETTING(    0x10, "Normal" )	/* 64*/
933 	PORT_DIPSETTING(    0x08, "Hard" )		/* 62*/
934 	PORT_DIPSETTING(    0x00, "Hardest" )	/* 60*/
935 	PORT_DIPNAME( 0x20, 0x00, DEF_STR( Demo_Sounds ) )
936 	PORT_DIPSETTING(    0x20, DEF_STR( Off ) )
937 	PORT_DIPSETTING(    0x00, DEF_STR( On ) )
938 	PORT_DIPNAME( 0x40, 0x40, "Unknown B-6" )
939 	PORT_DIPSETTING(    0x40, DEF_STR( Off ) )
940 	PORT_DIPSETTING(    0x00, DEF_STR( On ) )
941 	PORT_DIPNAME( 0x80, 0x80, "Unknown B-7" )
942 	PORT_DIPSETTING(    0x80, DEF_STR( Off ) )
943 	PORT_DIPSETTING(    0x00, DEF_STR( On ) )
944 
945 	PORT_START	/* IN4 - Accelerator - $140021.b (0) */
946 	PORT_ANALOG( 0xff, 0, IPT_PEDAL, 30, 10, 0, 0x80 )
947 
948 	PORT_START	/* IN5 - Steering Wheel - $140021.b (2) */
949 	PORT_ANALOG( 0xff, 0x80, IPT_AD_STICK_X | IPF_CENTER, 50, 5, 0, 0xff )
950 INPUT_PORTS_END
951 
952 
953 /***************************************************************************
954 							Hot Chase Input Ports
955 ***************************************************************************/
956 
957 INPUT_PORTS_START( hotchase )
958 	PORT_START	/* IN0 - Controls and Coins - $140011.b */
959 	PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_COIN1 )
960 	PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_COIN2 )
961 	PORT_SERVICE_NO_TOGGLE( 0x04, IP_ACTIVE_LOW )
962 	PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_SERVICE1 )
963 	PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_START1 )
964 	PORT_BITX(0x20, IP_ACTIVE_LOW, IPT_BUTTON3 | IPF_TOGGLE, "Shift", IP_KEY_DEFAULT, IP_JOY_DEFAULT )
965 	PORT_BITX(0x40, IP_ACTIVE_LOW, IPT_BUTTON2, "Brake", IP_KEY_DEFAULT, IP_JOY_DEFAULT )
966 	PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_UNUSED )
967 
968 	PORT_START	/* IN1 - Motor? - $140013.b */
969 	PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_SERVICE2 )	/* right sw*/
970 	PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_SERVICE3 )	/* left sw*/
971 	PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_SERVICE4 )	/* thermo*/
972 	PORT_BIT( 0x08, IP_ACTIVE_HIGH, IPT_SPECIAL )	/* from sound cpu ?*/
973 	PORT_BIT( 0xf0, IP_ACTIVE_LOW, IPT_UNKNOWN )
974 
975 	PORT_START	/* IN2 - DSW 2 (options) - $140015.b */
976 	PORT_DIPNAME( 0x01, 0x01, "Unknown 2-0" )	/* single*/
977 	PORT_DIPSETTING(    0x01, DEF_STR( Off ) )
978 	PORT_DIPSETTING(    0x00, DEF_STR( On ) )
979 	PORT_DIPNAME( 0x02, 0x02, "Unknown 2-1" )	/* single (wheel related)*/
980 	PORT_DIPSETTING(    0x02, DEF_STR( Off ) )
981 	PORT_DIPSETTING(    0x00, DEF_STR( On ) )
982 	PORT_DIPNAME( 0x04, 0x04, "Unknown 2-2" )
983 	PORT_DIPSETTING(    0x04, DEF_STR( Off ) )
984 	PORT_DIPSETTING(    0x00, DEF_STR( On ) )
985 	PORT_DIPNAME( 0x18, 0x18, "Unknown 2-3&4" )
986 	PORT_DIPSETTING(    0x18, "0" )
987 	PORT_DIPSETTING(    0x10, "4" )
988 	PORT_DIPSETTING(    0x08, "8" )
989 	PORT_DIPSETTING(    0x00, "c" )
990 	PORT_DIPNAME( 0x20, 0x20, "Unknown 2-5" )	/* single*/
991 	PORT_DIPSETTING(    0x20, DEF_STR( Off ) )
992 	PORT_DIPSETTING(    0x00, DEF_STR( On ) )
993 	/* wheel <-> brake ; accel -> start */
994 	PORT_DIPNAME( 0x40, 0x40, "Unknown 2-6" )	/* single (wheel<->brake)*/
995 	PORT_DIPSETTING(    0x40, DEF_STR( Off ) )
996 	PORT_DIPSETTING(    0x00, DEF_STR( On ) )
997 	PORT_DIPNAME( 0x80, 0x80, "Unknown 2-7" )	/* single*/
998 	PORT_DIPSETTING(    0x80, DEF_STR( Off ) )
999 	PORT_DIPSETTING(    0x00, DEF_STR( On ) )
1000 
1001 	PORT_START	/* IN3 - DSW 1 (Coinage) - $140017.b */
1002 	PORT_DIPNAME( 0x0f, 0x0f, DEF_STR( Coin_A ) )
1003 	PORT_DIPSETTING(    0x02, DEF_STR( 5C_1C ) )
1004 	PORT_DIPSETTING(    0x04, DEF_STR( 4C_1C ) )
1005 	PORT_DIPSETTING(    0x07, DEF_STR( 3C_1C ) )
1006 	PORT_DIPSETTING(    0x0a, DEF_STR( 2C_1C ) )
1007 	PORT_DIPSETTING(    0x01, DEF_STR( 5C_3C ) )
1008 	PORT_DIPSETTING(    0x06, DEF_STR( 3C_2C ) )
1009 	PORT_DIPSETTING(    0x03, DEF_STR( 4C_3C ) )
1010 	PORT_DIPSETTING(    0x0f, DEF_STR( 1C_1C ) )
1011 	PORT_DIPSETTING(    0x05, DEF_STR( 3C_4C ) )
1012 	PORT_DIPSETTING(    0x09, DEF_STR( 2C_3C ) )
1013 	PORT_DIPSETTING(    0x0e, DEF_STR( 1C_2C ) )
1014 	PORT_DIPSETTING(    0x08, DEF_STR( 2C_5C ) )
1015 	PORT_DIPSETTING(    0x0d, DEF_STR( 1C_3C ) )
1016 	PORT_DIPSETTING(    0x0c, DEF_STR( 1C_4C ) )
1017 	PORT_DIPSETTING(    0x0b, DEF_STR( 1C_5C ) )
1018 	PORT_DIPSETTING(    0x00, DEF_STR( Free_Play ) )
1019 	PORT_DIPNAME( 0xf0, 0xf0, DEF_STR( Coin_B ) )
1020 	PORT_DIPSETTING(    0x20, DEF_STR( 5C_1C ) )
1021 	PORT_DIPSETTING(    0x70, DEF_STR( 3C_1C ) )
1022 	PORT_DIPSETTING(    0xa0, DEF_STR( 2C_1C ) )
1023 	PORT_DIPSETTING(    0x10, DEF_STR( 5C_3C ) )
1024 	PORT_DIPSETTING(    0x60, DEF_STR( 3C_2C ) )
1025 	PORT_DIPSETTING(    0x30, DEF_STR( 4C_3C ) )
1026 	PORT_DIPSETTING(    0xf0, DEF_STR( 1C_1C ) )
1027 	PORT_DIPSETTING(    0x50, DEF_STR( 3C_4C ) )
1028 	PORT_DIPSETTING(    0x90, DEF_STR( 2C_3C ) )
1029 	PORT_DIPSETTING(    0xe0, DEF_STR( 1C_2C ) )
1030 	PORT_DIPSETTING(    0x80, DEF_STR( 2C_5C ) )
1031 	PORT_DIPSETTING(    0xd0, DEF_STR( 1C_3C ) )
1032 	PORT_DIPSETTING(    0xc0, DEF_STR( 1C_4C ) )
1033 	PORT_DIPSETTING(    0xb0, DEF_STR( 1C_5C ) )
1034 	PORT_DIPSETTING(    0x00, "1 Coin/99 Credits" )
1035 
1036 	PORT_START	/* IN4 - Accelerator - $140021.b (0) */
1037 	PORT_ANALOG( 0xff, 0, IPT_PEDAL, 30, 10, 0, 0x80 )
1038 
1039 	PORT_START	/* IN5 - Steering Wheel - $140021.b (2) */
1040 	PORT_ANALOG( 0xff, 0x80, IPT_AD_STICK_X | IPF_CENTER, 50, 5, 0, 0xff )
1041 INPUT_PORTS_END
1042 
1043 
1044 /***************************************************************************
1045 							WEC Le Mans 24 Graphics Layout
1046 ***************************************************************************/
1047 
1048 static struct GfxLayout wecleman_bg_layout =
1049 {
1050 	8,8,
1051 	8*0x8000*3/(8*8*3),
1052 	3,
1053 	{ 0,0x8000*8,0x8000*8*2 },
1054 	{0,7,6,5,4,3,2,1},
1055 	{0*8,1*8,2*8,3*8,4*8,5*8,6*8,7*8},
1056 	8*8
1057 };
1058 
1059 /* We draw the road, made of 512 pixel lines, using 64x1 tiles */
1060 static struct GfxLayout wecleman_road_layout =
1061 {
1062 	64,1,
1063 	8*0x4000*3/(64*1*3),
1064 	3,
1065 	{ 0x4000*8*2,0x4000*8*1,0x4000*8*0 },
1066 	{0,7,6,5,4,3,2,1,
1067 	 8,15,14,13,12,11,10,9,
1068 	 16,23,22,21,20,19,18,17,
1069 	 24,31,30,29,28,27,26,25,
1070 
1071 	 0+32,7+32,6+32,5+32,4+32,3+32,2+32,1+32,
1072 	 8+32,15+32,14+32,13+32,12+32,11+32,10+32,9+32,
1073 	 16+32,23+32,22+32,21+32,20+32,19+32,18+32,17+32,
1074 	 24+32,31+32,30+32,29+32,28+32,27+32,26+32,25+32},
1075 	{0},
1076 	64*1
1077 };
1078 
1079 static struct GfxDecodeInfo wecleman_gfxdecodeinfo[] =
1080 {
1081 	/* REGION_GFX1 holds sprite, which are not decoded here*/
1082 	{ REGION_GFX2, 0, &wecleman_bg_layout,   0, 2048/8 },	/* [0] bg + fg + txt*/
1083 	{ REGION_GFX3, 0, &wecleman_road_layout, 0, 2048/8 },	/* [1] road*/
1084 	{ -1 }
1085 };
1086 
1087 
1088 /***************************************************************************
1089 							Hot Chase Graphics Layout
1090 ***************************************************************************/
1091 
1092 /* We draw the road, made of 512 pixel lines, using 64x1 tiles */
1093 /* tiles are doubled horizontally */
1094 static struct GfxLayout hotchase_road_layout =
1095 {
1096 	64,1,
1097 	RGN_FRAC(1,1),
1098 	4,
1099 	{ 0, 1, 2, 3 },
1100 	{ 0*4,0*4,1*4,1*4,2*4,2*4,3*4,3*4,4*4,4*4,5*4,5*4,6*4,6*4,7*4,7*4,
1101 	  8*4,8*4,9*4,9*4,10*4,10*4,11*4,11*4,12*4,12*4,13*4,13*4,14*4,14*4,15*4,15*4,
1102 	 16*4,16*4,17*4,17*4,18*4,18*4,19*4,19*4,20*4,20*4,21*4,21*4,22*4,22*4,23*4,23*4,
1103 	 24*4,24*4,25*4,25*4,26*4,26*4,27*4,27*4,28*4,28*4,29*4,29*4,30*4,30*4,31*4,31*4 },
1104 	{0},
1105 	32*4
1106 };
1107 
1108 static struct GfxDecodeInfo hotchase_gfxdecodeinfo[] =
1109 {
1110 	/* REGION_GFX1 holds sprite, which are not decoded here*/
1111 	/* REGION_GFX2 and 3 are for the 051316*/
1112 	{ REGION_GFX4, 0, &hotchase_road_layout, 0x70*16, 16 },	/* road*/
1113 	{ -1 }
1114 };
1115 
1116 
1117 /***************************************************************************
1118 						WEC Le Mans 24 Hardware Definitions
1119 ***************************************************************************/
1120 
INTERRUPT_GEN(wecleman_interrupt)1121 static INTERRUPT_GEN( wecleman_interrupt )
1122 {
1123 	if (cpu_getiloops() == 0)
1124 		cpu_set_irq_line(0, 4, HOLD_LINE);	/* once */
1125 	else
1126 		cpu_set_irq_line(0, 5, HOLD_LINE);	/* to read input ports */
1127 }
1128 
1129 static struct YM2151interface ym2151_interface =
1130 {
1131 	1,
1132 	3579545,	/* same as sound cpu */
1133 	{ YM3012_VOL(85,MIXER_PAN_LEFT,85,MIXER_PAN_RIGHT) },
1134 	{ 0  }
1135 };
1136 
1137 static struct K007232_interface wecleman_k007232_interface =
1138 {
1139 	1,
1140 	3579545,	/* clock */
1141 	{ REGION_SOUND1 },	/* but the 2 channels use different ROMs !*/
1142 	{ K007232_VOL( 20,MIXER_PAN_LEFT, 20,MIXER_PAN_RIGHT ) },
1143 	{0}
1144 };
1145 
MACHINE_INIT(wecleman)1146 MACHINE_INIT( wecleman )
1147 {
1148 	K007232_set_bank( 0, 0, 1 );
1149 }
1150 
1151 static MACHINE_DRIVER_START( wecleman )
1152 
1153 	/* basic machine hardware */
1154 	MDRV_CPU_ADD(M68000, 10000000)	/* Schems show 10MHz */
MDRV_CPU_MEMORY(wecleman_readmem,wecleman_writemem)1155 	MDRV_CPU_MEMORY(wecleman_readmem,wecleman_writemem)
1156 	MDRV_CPU_VBLANK_INT(wecleman_interrupt,5 + 1)	/* in order to read the inputs once per frame */
1157 
1158 	MDRV_CPU_ADD(M68000, 10000000)	/* Schems show 10MHz */
1159 	MDRV_CPU_MEMORY(wecleman_sub_readmem,wecleman_sub_writemem)
1160 
1161 	/* Schems: can be reset, no nmi, soundlatch, 3.58MHz */
1162 	MDRV_CPU_ADD(Z80, 3579545)
1163 	MDRV_CPU_FLAGS(CPU_AUDIO_CPU)
1164 	MDRV_CPU_MEMORY(wecleman_sound_readmem,wecleman_sound_writemem)
1165 
1166 	MDRV_FRAMES_PER_SECOND(60)
1167 	MDRV_VBLANK_DURATION(DEFAULT_60HZ_VBLANK_DURATION)
1168 	MDRV_INTERLEAVE(100)
1169 
1170 	MDRV_MACHINE_INIT(wecleman)
1171 
1172 	/* video hardware */
1173 	MDRV_VIDEO_ATTRIBUTES(VIDEO_TYPE_RASTER | VIDEO_RGB_DIRECT)
1174 	MDRV_SCREEN_SIZE(320 +16, 224 +16)
1175 	MDRV_VISIBLE_AREA(0 +8, 320-1 +8, 0 +8, 224-1 +8)
1176 	MDRV_GFXDECODE(wecleman_gfxdecodeinfo)
1177 
1178 	MDRV_PALETTE_LENGTH(2048)
1179 
1180 	MDRV_VIDEO_START(wecleman)
1181 	MDRV_VIDEO_UPDATE(wecleman)
1182 
1183 	/* sound hardware */
1184 	MDRV_SOUND_ADD(YM2151, ym2151_interface)
1185 	MDRV_SOUND_ADD(K007232, wecleman_k007232_interface)
1186 MACHINE_DRIVER_END
1187 
1188 
1189 /***************************************************************************
1190 						Hot Chase Hardware Definitions
1191 ***************************************************************************/
1192 
1193 static INTERRUPT_GEN( hotchase_sound_timer )
1194 {
1195 	cpu_set_irq_line( 2, M6809_FIRQ_LINE, PULSE_LINE );
1196 }
1197 
1198 static MACHINE_DRIVER_START( hotchase )
1199 
1200 	/* basic machine hardware */
1201 	MDRV_CPU_ADD(M68000, 10000000)	/* 10 MHz - PCB is drawn in one set's readme */
MDRV_CPU_MEMORY(hotchase_readmem,hotchase_writemem)1202 	MDRV_CPU_MEMORY(hotchase_readmem,hotchase_writemem)
1203 	MDRV_CPU_VBLANK_INT(irq4_line_hold,1)
1204 
1205 	MDRV_CPU_ADD(M68000, 10000000)	/* 10 MHz - PCB is drawn in one set's readme */
1206 	MDRV_CPU_MEMORY(hotchase_sub_readmem,hotchase_sub_writemem)
1207 
1208 	MDRV_CPU_ADD(M6809, 3579545 / 2)
1209 	MDRV_CPU_FLAGS(CPU_AUDIO_CPU)	/* 3.579/2 MHz - PCB is drawn in one set's readme */
1210 	MDRV_CPU_MEMORY(hotchase_sound_readmem,hotchase_sound_writemem)
1211 	MDRV_CPU_PERIODIC_INT( hotchase_sound_timer, 496 )
1212 
1213 	/* Amuse: every 2 ms */
1214 	MDRV_FRAMES_PER_SECOND(60)
1215 	MDRV_VBLANK_DURATION(DEFAULT_60HZ_VBLANK_DURATION)
1216 	MDRV_INTERLEAVE(100)
1217 
1218 	/* video hardware */
1219 	MDRV_VIDEO_ATTRIBUTES(VIDEO_TYPE_RASTER)
1220 	MDRV_SCREEN_SIZE(320, 224)
1221 	MDRV_VISIBLE_AREA(0, 320-1, 0, 224-1)
1222 	MDRV_GFXDECODE(hotchase_gfxdecodeinfo)
1223 	MDRV_PALETTE_LENGTH(2048*2)
1224 
1225 	MDRV_VIDEO_START(hotchase)
1226 	MDRV_VIDEO_UPDATE(hotchase)
1227 
1228 	/* sound hardware */
1229 	MDRV_SOUND_ADD(K007232, hotchase_k007232_interface)
1230 MACHINE_DRIVER_END
1231 
1232 
1233 /***************************************************************************
1234 						WEC Le Mans 24 ROM Definitions
1235 ***************************************************************************/
1236 
1237 ROM_START( wecleman )
1238 
1239 	ROM_REGION( 0x40000, REGION_CPU1, 0 )	/* Main CPU Code */
1240 	ROM_LOAD16_BYTE( "602f08.17h", 0x00000, 0x10000, CRC(493b79d3) SHA1(9625e3b65c211d5081d8ed8977de287eff100842) )
1241 	ROM_LOAD16_BYTE( "602f11.23h", 0x00001, 0x10000, CRC(6bb4f1fa) SHA1(2cfb7885b42b49dab9892e8dfd54914b64eeab06) )
1242 	ROM_LOAD16_BYTE( "602a09.18h", 0x20000, 0x10000, CRC(8a9d756f) SHA1(12605e86ce29e6300b5400720baac7b0293d9e66) )
1243 	ROM_LOAD16_BYTE( "602a10.22h", 0x20001, 0x10000, CRC(569f5001) SHA1(ec2dd331a279083cf847fbbe71c017038a1d562a) )
1244 
1245 	ROM_REGION( 0x10000, REGION_CPU2, 0 )	/* Sub CPU Code */
1246 	ROM_LOAD16_BYTE( "602a06.18a", 0x00000, 0x08000, CRC(e12c0d11) SHA1(991afd48bf1b2c303b975ce80c754e5972c39111) )
1247 	ROM_LOAD16_BYTE( "602a07.20a", 0x00001, 0x08000, CRC(47968e51) SHA1(9b01b2c6a14dd80327a8f66a7f1994471a4bc38e) )
1248 
1249 	ROM_REGION( 0x10000, REGION_CPU3, 0 )	/* Sound CPU Code */
1250 	ROM_LOAD( "602a01.6d",  0x00000, 0x08000, CRC(deafe5f1) SHA1(4cfbe2841233b1222c22160af7287b7a7821c3a0) )
1251 
1252 	ROM_REGION( 0x200000 * 2, REGION_GFX1, 0 )	/* x2, do not dispose, zooming sprites */
1253 	ROM_LOAD( "602a25.12e", 0x000000, 0x20000, CRC(0eacf1f9) SHA1(b4dcd457e68175ffee3da4aff23a241fe33eb500) )
1254 	ROM_LOAD( "602a26.14e", 0x020000, 0x20000, CRC(2182edaf) SHA1(5ae4223a76b3c0be8f66458707f2e6f63fba0b13) )
1255 	ROM_LOAD( "602a27.15e", 0x040000, 0x20000, CRC(b22f08e9) SHA1(1ba99bc4e00e206507e9bfafc989208d6ae6f8a3) )
1256 	ROM_LOAD( "602a28.17e", 0x060000, 0x20000, CRC(5f6741fa) SHA1(9c81634f502da8682673b3b87efe0497af8abbd7) )
1257 	ROM_LOAD( "602a21.6e",  0x080000, 0x20000, CRC(8cab34f1) SHA1(264df01460f44cd5ccdf3c8bd2d3f327874b69ea) )
1258 	ROM_LOAD( "602a22.7e",  0x0a0000, 0x20000, CRC(e40303cb) SHA1(da943437ea2e208ea477f35bb05f77412ecdf9ac) )
1259 	ROM_LOAD( "602a23.9e",  0x0c0000, 0x20000, CRC(75077681) SHA1(32ad10e9e32779c36bb50b402f5c6d941e293942) )
1260 	ROM_LOAD( "602a24.10e", 0x0e0000, 0x20000, CRC(583dadad) SHA1(181ebe87095d739a5903c17ec851864e2275f571) )
1261 	ROM_LOAD( "602a17.12c", 0x100000, 0x20000, CRC(31612199) SHA1(dff58ec3f7d98bfa7e9405f0f23647ff4ecfee62) )
1262 	ROM_LOAD( "602a18.14c", 0x120000, 0x20000, CRC(3f061a67) SHA1(be57c38410c5635311d26afc44b3065e42fa12b7) )
1263 	ROM_LOAD( "602a19.15c", 0x140000, 0x20000, CRC(5915dbc5) SHA1(61ab123c8a4128a18d7eb2cae99ad58203f03ffc) )
1264 	ROM_LOAD( "602a20.17c", 0x160000, 0x20000, CRC(f87e4ef5) SHA1(4c2f0d036925a7ccd32aef3ca12b960a27247bc3) )
1265 	ROM_LOAD( "602a13.6c",  0x180000, 0x20000, CRC(5d3589b8) SHA1(d146cb8511cfe825bdfe8296c7758545542a0faa) )
1266 	ROM_LOAD( "602a14.7c",  0x1a0000, 0x20000, CRC(e3a75f6c) SHA1(80b20323e3560316ffbdafe4fd2f81326e103045) )
1267 	ROM_LOAD( "602a15.9c",  0x1c0000, 0x20000, CRC(0d493c9f) SHA1(02690a1963cadd469bd67cb362384923916900a1) )
1268 	ROM_LOAD( "602a16.10c", 0x1e0000, 0x20000, CRC(b08770b3) SHA1(41871e9261d08fd372b7deb72d939973fb694b54) )
1269 
1270 	ROM_REGION( 0x18000, REGION_GFX2, ROMREGION_DISPOSE )
1271 	ROM_LOAD( "602a31.26g", 0x000000, 0x08000, CRC(01fa40dd) SHA1(2b8aa97f5116f39ae6a8e46f109853d70e370884) )	/* layers*/
1272 	ROM_LOAD( "602a30.24g", 0x008000, 0x08000, CRC(be5c4138) SHA1(7aee2ee17ef3e37399a60d9b019cfa733acbf07b) )
1273 	ROM_LOAD( "602a29.23g", 0x010000, 0x08000, CRC(f1a8d33e) SHA1(ed6531f2fd4ad6835a879e9a5600387d8cad6d17) )
1274 
1275 	ROM_REGION( 0x0c000, REGION_GFX3, ROMREGION_DISPOSE )	/* road */
1276 	ROM_LOAD( "602a04.11e", 0x000000, 0x08000, CRC(ade9f359) SHA1(58db6be6217ed697827015e50e99e58602042a4c) )
1277 	ROM_LOAD( "602a05.13e", 0x008000, 0x04000, CRC(f22b7f2b) SHA1(857389c57552c4e2237cb599f4c68c381430475e) )
1278 
1279 	ROM_REGION( 0x40000, REGION_SOUND1, 0 )	/* Samples (Channel A 0x20000=Channel B) */
1280 	ROM_LOAD( "602a03.10a", 0x00000, 0x20000, CRC(31392b01) SHA1(0424747bc2015c9c93afd20e6a23083c0dcc4fb7) )
1281 	ROM_LOAD( "602a02.8a",  0x20000, 0x20000, CRC(e2be10ae) SHA1(109c31bf7252c83a062d259143cd8299681db778) )
1282 
1283 	ROM_REGION( 0x04000, REGION_USER1, 0 )	/* extra data for road effects? */
1284 	ROM_LOAD( "602a12.1a",  0x000000, 0x04000, CRC(77b9383d) SHA1(7cb970889677704d6324bb64aafc05326c4503ad) )
1285 
1286 ROM_END
1287 
1288 void wecleman_unpack_sprites(void)
1289 {
1290 	const int region       = REGION_GFX1;	/* sprites*/
1291 
1292 	const unsigned int len = memory_region_length(region);
1293 	unsigned char *src     = memory_region(region) + len / 2 - 1;
1294 	unsigned char *dst     = memory_region(region) + len - 1;
1295 
1296 	while(dst > src)
1297 	{
1298 		unsigned char data = *src--;
1299 		if( (data&0xf0) == 0xf0 ) data &= 0x0f;
1300 		if( (data&0x0f) == 0x0f ) data &= 0xf0;
1301 		*dst-- = data & 0xF;    *dst-- = data >> 4;
1302 	}
1303 }
1304 
bitswap(data8_t * src,size_t len,int _14,int _13,int _12,int _11,int _10,int _f,int _e,int _d,int _c,int _b,int _a,int _9,int _8,int _7,int _6,int _5,int _4,int _3,int _2,int _1,int _0)1305 static void bitswap(data8_t *src,size_t len,int _14,int _13,int _12,int _11,int _10,int _f,int _e,int _d,int _c,int _b,int _a,int _9,int _8,int _7,int _6,int _5,int _4,int _3,int _2,int _1,int _0)
1306 {
1307 	data8_t *buffer = malloc(len);
1308 
1309 	if (buffer)
1310 	{
1311 		int i;
1312 
1313 		memcpy(buffer,src,len);
1314 		for (i = 0;i < len;i++)
1315 		{
1316 			src[i] =
1317 				buffer[BITSWAP24(i,23,22,21,_14,_13,_12,_11,_10,_f,_e,_d,_c,_b,_a,_9,_8,_7,_6,_5,_4,_3,_2,_1,_0)];
1318 		}
1319 		free(buffer);
1320 	}
1321 }
1322 
1323 /* Unpack sprites data and do some patching */
DRIVER_INIT(wecleman)1324 DRIVER_INIT( wecleman )
1325 {
1326 	int i;
1327 	unsigned char *RAM;
1328 /*	data16_t *RAM1 = (data16_t *) memory_region(REGION_CPU1);	 // Main CPU patches /*/
1329 /*	RAM1[0x08c2/2] = 0x601e;	*/ /* faster self test*/
1330 
1331 	/* Decode GFX Roms - Compensate for the address lines scrambling */
1332 
1333 	/*  Sprites - decrypting the sprites nearly KILLED ME!
1334 	    It's been the main cause of the delay of this driver ...
1335 	    I hope you'll appreciate this effort!  */
1336 
1337 	/* let's swap even and odd *pixels* of the sprites */
1338 	RAM = memory_region(REGION_GFX1);
1339 	for (i = 0; i < memory_region_length(REGION_GFX1); i ++)
1340 	{
1341 		/* TODO: could be wrong, colors have to be fixed.       */
1342 		/* The only certain thing is that 87 must convert to f0 */
1343 		/* otherwise stray lines appear, made of pens 7 & 8     */
1344 		RAM[i] = BITSWAP8(RAM[i],7,0,1,2,3,4,5,6);
1345 	}
1346 
1347 	bitswap(memory_region(REGION_GFX1), memory_region_length(REGION_GFX1),
1348 			0,1,20,19,18,17,14,9,16,6,4,7,8,15,10,11,13,5,12,3,2);
1349 
1350 	/* Now we can unpack each nibble of the sprites into a pixel (one byte) */
1351 	wecleman_unpack_sprites();
1352 
1353 	/* Bg & Fg & Txt */
1354 	bitswap(memory_region(REGION_GFX2), memory_region_length(REGION_GFX2),
1355 			20,19,18,17,16,15,12,7,14,4,2,5,6,13,8,9,11,3,10,1,0);
1356 
1357 	/* Road */
1358 	bitswap(memory_region(REGION_GFX3), memory_region_length(REGION_GFX3),
1359 			20,19,18,17,16,15,14,7,12,4,2,5,6,13,8,9,11,3,10,1,0);
1360 
1361 	spr_color_offs = 0x40;
1362 }
1363 
1364 
1365 /***************************************************************************
1366 							Hot Chase ROM Definitions
1367 ***************************************************************************/
1368 
1369 ROM_START( hotchase )
1370 	ROM_REGION( 0x40000, REGION_CPU1, 0 )	/* Main Code */
CRC(f34fef0b)1371 	ROM_LOAD16_BYTE( "763k05", 0x000000, 0x010000, CRC(f34fef0b) SHA1(9edaf6da988348cb32d5686fe7a67fb92b1c9777) )
1372 	ROM_LOAD16_BYTE( "763k04", 0x000001, 0x010000, CRC(60f73178) SHA1(49c919d09fa464b205d7eccce337349e3a633a14) )
1373 	ROM_LOAD16_BYTE( "763k03", 0x020000, 0x010000, CRC(28e3a444) SHA1(106b22a3cbe8301eac2e46674a267b96e72ac72f) )
1374 	ROM_LOAD16_BYTE( "763k02", 0x020001, 0x010000, CRC(9510f961) SHA1(45b1920cab08a0dacd044c851d4e7f0cb5772b46) )
1375 
1376 	ROM_REGION( 0x20000, REGION_CPU2, 0 )	/* Sub Code */
1377 	ROM_LOAD16_BYTE( "763k07", 0x000000, 0x010000, CRC(ae12fa90) SHA1(7f76f09916fe152411b5af3c504ee7be07497ef4) )
1378 	ROM_LOAD16_BYTE( "763k06", 0x000001, 0x010000, CRC(b77e0c07) SHA1(98bf492ac889d31419df706029fdf3d51b85c936) )
1379 
1380 	ROM_REGION( 0x10000, REGION_CPU3, 0 )	/* Sound Code */
1381 	ROM_LOAD( "763f01", 0x8000, 0x8000, CRC(4fddd061) SHA1(ff0aa18605612f6102107a6be1f93ae4c5edc84f) )
1382 
1383 	ROM_REGION( 0x300000 * 2, REGION_GFX1, 0 )	/* x2, do not dispose, zooming sprites */
1384 	ROM_LOAD16_WORD_SWAP( "763e17", 0x000000, 0x080000, CRC(8db4e0aa) SHA1(376cb3cae110998f2f9df7e6cdd35c06732fea69) )
1385 	ROM_LOAD16_WORD_SWAP( "763e20", 0x080000, 0x080000, CRC(a22c6fce) SHA1(174fb9c1706c092947bcce386831acd33a237046) )
1386 	ROM_LOAD16_WORD_SWAP( "763e18", 0x100000, 0x080000, CRC(50920d01) SHA1(313c7ecbd154b3f4c96f25c29a7734a9b3facea4) )
1387 	ROM_LOAD16_WORD_SWAP( "763e21", 0x180000, 0x080000, CRC(77e0e93e) SHA1(c8e415438a1f5ad79b10fd3ad5cb22de0d562e5d) )
1388 	ROM_LOAD16_WORD_SWAP( "763e19", 0x200000, 0x080000, CRC(a2622e56) SHA1(0a0ed9713882b987518e6f06a02dba417c1f4f32) )
1389 	ROM_LOAD16_WORD_SWAP( "763e22", 0x280000, 0x080000, CRC(967c49d1) SHA1(01979d216a9fd8085298445ac5f7870d1598db74) )
1390 
1391 	ROM_REGION( 0x20000, REGION_GFX2, 0 )	/* bg */
1392 	ROM_LOAD( "763e14", 0x000000, 0x020000, CRC(60392aa1) SHA1(8499eb40a246587e24f6fd00af2eaa6d75ee6363) )
1393 
1394 	ROM_REGION( 0x10000, REGION_GFX3, 0 )	/* fg (patched) */
1395 	ROM_LOAD( "763a13", 0x000000, 0x010000, CRC(8bed8e0d) SHA1(ccff330abc23fe499e76c16cab5783c3daf155dd) )
1396 
1397 	ROM_REGION( 0x20000, REGION_GFX4, ROMREGION_DISPOSE )	/* road */
1398 	ROM_LOAD( "763e15", 0x000000, 0x020000, CRC(7110aa43) SHA1(639dc002cc1580f0530bb5bb17f574e2258d5954) )
1399 
1400 	ROM_REGION( 0x40000, REGION_SOUND1, 0 )	/* Samples, 2 banks */
1401 	ROM_LOAD( "763e11", 0x000000, 0x040000, CRC(9d99a5a7) SHA1(96e37bbb259e0a91d124c26b6b1a9b70de2e19a4) )
1402 
1403 	ROM_REGION( 0x40000, REGION_SOUND2, 0 )	/* Samples, 2 banks */
1404 	ROM_LOAD( "763e10", 0x000000, 0x040000, CRC(ca409210) SHA1(703d7619c4bd33d2ff5fad127d98c82906fede33) )
1405 
1406 	ROM_REGION( 0x100000, REGION_SOUND3, 0 )	/* Samples, 4 banks for each ROM */
1407 	ROM_LOAD( "763e08", 0x000000, 0x080000, CRC(054a9a63) SHA1(45d7926c9e7af47c041ba9b733e334bccd730a6d) )
1408 	ROM_LOAD( "763e09", 0x080000, 0x080000, CRC(c39857db) SHA1(64b135a9ccf9e1dd50789cdd5c6bc03da8decfd0) )
1409 
1410 	ROM_REGION( 0x08000, REGION_USER1, 0 )	/* extra data for road effects? */
1411 	ROM_LOAD( "763a12", 0x000000, 0x008000, CRC(05f1e553) SHA1(8aaeb7374bd93038c24e6470398936f22cabb0fe) )
1412 ROM_END
1413 
1414 /*      Important: you must leave extra space when listing sprite ROMs
1415 	in a ROM module definition.  This routine unpacks each sprite nibble
1416 	into a byte, doubling the memory consumption. */
1417 
1418 void hotchase_sprite_decode( int num16_banks, int bank_size )
1419 {
1420 	unsigned char *base, *temp;
1421 	int i;
1422 
1423 	base = memory_region(REGION_GFX1);	/* sprites*/
1424 	temp = malloc( bank_size );
1425 	if( !temp ) return;
1426 
1427 	for( i = num16_banks; i >0; i-- ){
1428 		unsigned char *finish   = base + 2*bank_size*i;
1429 		unsigned char *dest     = finish - 2*bank_size;
1430 
1431 		unsigned char *p1 = temp;
1432 		unsigned char *p2 = temp+bank_size/2;
1433 
1434 		unsigned char data;
1435 
1436 		memcpy (temp, base+bank_size*(i-1), bank_size);
1437 
1438 		do {
1439 			data = *p1++;
1440 			if( (data&0xf0) == 0xf0 ) data &= 0x0f;
1441 			if( (data&0x0f) == 0x0f ) data &= 0xf0;
1442 			*dest++ = data >> 4;
1443 			*dest++ = data & 0xF;
1444 			data = *p1++;
1445 			if( (data&0xf0) == 0xf0 ) data &= 0x0f;
1446 			if( (data&0x0f) == 0x0f ) data &= 0xf0;
1447 			*dest++ = data >> 4;
1448 			*dest++ = data & 0xF;
1449 
1450 
1451 			data = *p2++;
1452 			if( (data&0xf0) == 0xf0 ) data &= 0x0f;
1453 			if( (data&0x0f) == 0x0f ) data &= 0xf0;
1454 			*dest++ = data >> 4;
1455 			*dest++ = data & 0xF;
1456 			data = *p2++;
1457 			if( (data&0xf0) == 0xf0 ) data &= 0x0f;
1458 			if( (data&0x0f) == 0x0f ) data &= 0xf0;
1459 			*dest++ = data >> 4;
1460 			*dest++ = data & 0xF;
1461 		} while( dest<finish );
1462 	}
1463 	free( temp );
1464 }
1465 
1466 /* Unpack sprites data and do some patching */
DRIVER_INIT(hotchase)1467 DRIVER_INIT( hotchase )
1468 {
1469 /*	data16_t *RAM1 = (data16_t) memory_region(REGION_CPU1);	 // Main CPU patches /*/
1470 /*	RAM[0x1140/2] = 0x0015; RAM[0x195c/2] = 0x601A;	*/ /* faster self test*/
1471 
1472 	unsigned char *RAM;
1473 
1474 	/* Decode GFX Roms */
1475 
1476 	/* Let's swap even and odd bytes of the sprites gfx roms */
1477 	RAM = memory_region(REGION_GFX1);
1478 
1479 	/* Now we can unpack each nibble of the sprites into a pixel (one byte) */
1480 	hotchase_sprite_decode(3,0x80000*2);	/* num banks, bank len*/
1481 
1482 	/* Let's copy the second half of the fg layer gfx (charset) over the first */
1483 	RAM = memory_region(REGION_GFX3);
1484 	memcpy(&RAM[0], &RAM[0x10000/2], 0x10000/2);
1485 
1486 	spr_color_offs = 0;
1487 }
1488 
1489 
1490 /***************************************************************************
1491 								Game driver(s)
1492 ***************************************************************************/
1493 
1494 GAME( 1986, wecleman, 0, wecleman, wecleman, wecleman, ROT0, "Konami", "WEC Le Mans 24" )
1495 GAME( 1988, hotchase, 0, hotchase, hotchase, hotchase, ROT0, "Konami", "Hot Chase" )
1496