1 // license:LGPL-2.1+
2 // copyright-holders:Angelo Salese, David Haywood
3 /******************************************************************************************************
4 
5     System H1 (c) 1994 Sega
6 
7     Driver by David Haywood, Angelo Salese and Tomasz Slanina
8     special thanks to Guru for references and HW advices
9 
10     Games on this system include Cool Riders and Aqua Stage.
11 
12     This system is interesting in that it makes use of an RLE compression scheme, which
13     is not something common for Sega hardware, there is a patent for it ( 6,141,122 )
14     http://www.google.com/patents/US6141122
15 
16     TODO:
17     - Understand what the 0x400000c reads on SH-2 really do.
18     - improve sound emulation
19     - i8237 purpose is unknown (missing ROM for comms?).
20     - verify zooming etc. our current algorithm is a bit ugly for text
21 
22 =======================================================================================================
23 
24 Cool Riders
25 Sega 1994
26 
27 This game runs on SYSTEM-H1 hardware. The hardware seems overly complex for a
28 2D bike racing game? The design of the PCB is very similar to vanilla Model 2
29 (i.e. Daytona etc). However instead of fully custom-badged chips, many of the
30 custom chips are off-the-shelf Hitachi/Toshiba gate-arrays.
31 
32 
33 PCB Layouts
34 -----------
35 
36 SYSTEM-H1 ROM BD
37 171-6516C
38 837-9623
39 834-11482 (sticker)
40 |--------------------------------------------------------------|
41 |  IC17            IC18              IC5               IC10    |
42 |                                                              |
43 |  IC15            IC16              IC4               IC9     |
44 |                                                              |
45 |  IC13            IC14              IC3               IC8     |
46 |                                                              |
47 |  IC11            IC12              IC2               IC7     |
48 |                                                              |
49 |  IC31            IC32              IC1               IC6     |
50 |                                                              |
51 |  IC29            IC30                                        |
52 |JP1-JP8                                                       |
53 |  LED    32.500MHz   CN1         JP9-JP12    CN2              |
54 |--------------------------------------------------------------|
55 Notes:
56       CN1/2   - Connectors joining to CPU board
57       JP1-8   - Jumpers to set ROM sizes
58                 JP1-4 set to 1-2
59                 JP5-8 set to 2-3
60       JP9-12  - Jumpers to set ROM sizes
61                 JP9 set to 1-2
62                 JP10-12 open (no jumpers) but JP12 pin 2 tied to JP10 pin 1
63       IC*     - IC29-IC32 are 27C4002 EPROM
64                 IC1-IC10 are DIP42 32M mask ROM
65                 IC11-IC18 are DIP42 16M mask ROM
66 
67 
68 SYSTEM-H1 COMMUNICATION-BD
69 171-6849B
70 837-10942
71 |----------------------------------|
72 |                 CN2              |
73 |       74F74   74F245  MB84256    |
74 |       74F373  74F245  MB84256    |
75 |MB89237A         CN1              |
76 |                                  |
77 |       74F138 74F04   74F125      |
78 |                                  |
79 |       74F157 74F161  74F02       |
80 |                                  |
81 |       74F04  74F74   74F86     TX|
82 |MB89374                           |
83 |       74F02  74F160            RX|
84 |                         SN75179  |
85 |                     JP1 JP2 JP3  |
86 |       LED               CN3      |
87 |----------------------------------|
88 Notes: (All IC's shown)
89       CN1/2   - Connectors joining to CPU board
90       CN3     - Connector joining to Filter board
91       RX/TX   - Optical cable connections for network (not used)
92       JP*     - 3x 2-pin jumpers. JP1 shorted, other jumpers open
93       MB84256 - Fujitsu MB84256 32k x8 SRAM (NDIP28)
94       MB89374 - Fujitsu MB89374 Data Link Controller (SDIP42)
95       MB89237A- Fujitsu MB89237A 8-Bit Proprietary DMAC (?) (DIP40)
96       SN75179 - Texas Instruments SN75179 Differential Driver and Receiver Pair (DIP8)
97 
98 
99 SYSTEM-H1 CPU BD
100 171-6651A
101 837-10389
102 837-11481 (sticker)
103 |--------------------------------------------------------------|
104 |                                                EPR-17662.IC12|
105 |                                                              |
106 |   |--------|    |--------|                                   |
107 |   |SEGA    |    |SEGA    |           FM1208S      SEC_CONN   |
108 |   |315-5758|    |315-5757|       CN2         CN1             |
109 |   |        |    |        |           |------|            CN10|
110 |   |--------|    |--------|           |SH7032|                |
111 |CN8                                   |      |                |
112 |                                      |------|                |
113 |                                                              |
114 |                   PAL1  JP1 JP4 JP6 JP2                      |
115 |                   PAL2   JP3 JP5     MB3771                  |
116 |     28MHz   32MHz              PC910                 A1603C  |
117 |                                               DSW1   DAN803  |
118 |HM5241605                       |--------| |--------| DAP803  |
119 |HM5241605      PAL3             |SEGA    | |SEGA    |         |
120 |                                |315-5687| |315-5687| 315-5649|
121 |                                |        | |        |         |
122 |   |-----|        TMP68HC000N-16|--------| |--------|         |
123 |   |SH2  |                       514270      514270           |
124 |   |     |                         CN12               A1603C  |
125 |CN7|-----|         MB84256            TDA1386   TL062     CN11|
126 |                           22.579MHz   CN14                   |
127 |                   MB84256                                    |
128 |                                                              |
129 |                                      TDA1386   TL062         |
130 |--------------------------------------------------------------|
131 Notes:
132       22.579MHz   - This OSC is tied to pin 1 of a 74AC04 logic chip. The output from that (pin 2) is tied
133                     directly to both 315-5687 chips on pin 14. Therefore the clock input of the YMF292's is 22.579MHz
134       514270      - Hitachi HM514270AJ-7 256k x16 DRAM (SOJ40)
135       68000       - Clock 16.00MHz [32/2]
136       A1603C      - NEC uPA1603C Monolithic N-Channel Power MOS FET Array (DIP16)
137       CN7/8       - Connectors joining to ROM board (above)
138       CN10/11     - Connectors joining to Filter board
139       CN12/14     - Connectors for (possible) extra sound board (not used)
140       DAN803      - Diotec Semiconductor DAN803 Small Signal Diode Array with common anodes (SIL9)
141       DAP803      - Diotec Semiconductor DAP803 Small Signal Diode Array with common cathodes (SIL9)
142       DSW1        - 4-position DIP switch. All OFF
143       EPR-17662   - Toshiba TC57H1025 1M EPROM (DIP40)
144       FM1208S     - RAMTRON FM1208S 4k (512 bytes x8) Nonvolatile Ferroelectric RAM (SOIC24)
145       HM5241605   - Hitachi HM5241605 4M (256k x 16 x 2 banks) SDRAM (SSOP50)
146       JP1-6       - Jumpers. JP2 open. JP5 1-2. All others 2-3
147       MB3771      - Fujitsu MB3771 Master Reset IC (SOIC8)
148       MB84256     - Fujitsu MB84256 32k x8 SRAM (SOP28)
149       PAL1        - GAL16V8B also marked '315-5800' (DIP20)
150       PAL2        - GAL16V8B also marked '315-5802' (DIP20)
151       PAL3        - GAL16V8B also marked '315-5801' (DIP20)
152       PC910       - Sharp PC910 opto-isolator (DIP8)
153       SEC_CONN    - Sega security-board connector (not used)
154       SH7032      - Hitachi HD6417032F20 ROMless SH1 CPU (QFP112). Clock input 16.00MHz on pin 71
155       SH2         - Hitachi HD6417095 SH2 CPU (QFP144). Clock input 28.00MHz on pin 118
156       TDA1386     - Philips TDA1386T Noise Shaping Filter DAC (SOP24)
157       TL062       - Texas Instruments TL062 Low Power JFET Input Operational Amplifier (SOIC8)
158       Sega Custom - 315-5757 (QFP160)
159                     315-5758 (QFP168) also marked 'HG62G035R26F'
160                     315-5649 (QFP100) custom I/O chip (also used on Model 2A/2B/2C, but NOT vanilla Model 2)
161                     315-5687 (QFP128 x2) also marked 'YMF292-F' (also used on Model 2A/2B/2C and ST-V)
162       Syncs       - Horizontal 24.24506kHz
163                     Vertical 57.0426Hz
164 
165 
166 SYSTEM-H1 VIDEO BD
167 171-6514F
168 837-9621
169 |--------------------------------------------------------------|
170 |         CN2                                                  |
171 |                                                           JP4|
172 |                                   |--------|  TC55328 D431008|
173 |      |--------|          HM514270 |SEGA    |  TC55328 D431008|
174 |      |SEGA    |          HM514270 |315-5697|              JP3|
175 |CN1   |315-5691|  TC55328 HM514270 |        |  D431008 D431008|
176 |      |        |  TC55328 HM514270 |--------|  D431008 D431008|
177 |      |--------|                                           JP2|
178 |                                                           JP1|
179 |                                     315-5698   315-5648      |
180 |        |------------|                                        |
181 |        |  SEGA      |      50MHz                             |
182 |        |  315-5692  |               315-5696   315-5648      |
183 |        |            |                                     CN9|
184 |LED     |------------|                                        |
185 |40MHz     |--------|                 315-5696   315-5648      |
186 |          |SEGA    |                                          |
187 |   PAL1   |315-5693|                                          |
188 |CN4       |        |       315-5695  315-5695   315-5648      |
189 ||--------||--------|                                          |
190 ||SEGA    |                                                    |
191 ||315-5694||--------| M5M411860 M5M411860 M5M411860 M5M411860  |
192 ||        ||SEGA    | M5M411860 M5M411860 M5M411860 M5M411860  |
193 ||--------||315-5693| M5M411860 M5M411860 M5M411860 M5M411860  |
194 |   PAL2   |        | M5M411860 M5M411860 M5M411860 M5M411860  |
195 |          |--------|                                          |
196 |--------------------------------------------------------------|
197 Notes:
198       CN9         - Connector joining to Filter board
199       CN1/2/4     - Connectors joining to CPU board
200       JP1/2/3/4   - 4x 3-pin jumpers. All set to 1-2
201       D431008     - NEC D431008 128k x8 SRAM (SOJ32)
202       HM514270    - Hitachi HM514270AJ7 256k x16 DRAM (SOJ40)
203       M5M411860   - Mitsubishi M5M411860TP435SF00-7 DRAM with fast page mode, 64k-words x 18 bits per word (maybe?) (TSOP42)
204       TC55328     - Toshiba TC55328AJ-15 32k x8 SRAM (SOJ24)
205       PAL1        - GAL16V8B also marked '315-5803' (DIP20)
206       PAL2        - GAL16V8B also marked '315-5864' (DIP20)
207       Sega Custom - 315-5648 (QFP64, x4)
208                     315-5691 also marked 'HG62S0791R17F' (QFP208)
209                     315-5692 also marked 'HG51B152FD' (QFP256)
210                     315-5693 also marked 'HG62G019R16F' (QFP168, x3)
211                     315-5694 (QFP208)
212                     315-5695 (QFP100, x2)
213                     315-5696 (QFP120, x2)
214                     315-5697 (QFP208)
215                     315-5698 (QFP144)
216 
217 *******************************************************************************************************
218 
219 Note: This hardware appears to have been designed as a test-bed for a new RLE based compression system
220       used by the zooming sprites.  It is possible that Sega planned on using this for ST-V, but
221       decided against it. Video/CPU part numbers give an interesting insight, since video hardware #
222       sits between Model 1 & Model 2.
223 
224                  Year on
225       System      PCB     PCB #      PALs
226       ---------------------------------------------------------
227       System32    1990    837-7428   315-5441 315-5442
228       SysMulti32  1992    837-8676   315-5596
229       Model 1     1992    837-8886   315-5546 315-5483 315-5484
230       Model 2     1994    837-10071  315-5737 315-5741
231       Model 2A    1994    837-10848  315-5737 315-5815
232       STV         1994    837-10934  315-5833
233 
234       H1 (CPU)    1994    837-10389  315-5800 315-5801 315-5802
235       H1 (Video)  1994    837-9621   315-5803 315-5864
236 
237 
238    NOTE:  While the hardware and title screen might list 1994 as a copyright, MAME uses 1995 due to the
239    abudance of evidence in trade journals and even it's own service manuals showing the year as 1995.
240 
241    References:
242    Arcade game magazine called 'Gamest' show released on 04.28.1995
243    VGL (Ultimate Video Game List published by AMP group) - year is printed as '94(4.95)'
244    Sega Arcade History (published by Enterbrain) is '1995/4'.
245 
246 
247 ******************************************************************************************************/
248 
249 /*
250 
251 some Sprite compression notes from Charles and Andrew
252 
253 OK so here's what we know. Andrew and I were playing with the ROMs and
254 Guru traced out connections on the board at the time:
255 
256 The ten graphics ROMs are IC1-IC10. Each is 16 bits, and all have a
257 common enable and common A20 input. All data lines are unique; nothing
258 is shared.
259 
260 There are two independent address buses:
261 - One drives A0-A19 of IC1-IC5
262 - The other drives A0-A19 of IC6-IC10
263 
264 So the ROMs are arranged as 4,194,304 x 160-bit words (very wide), and
265 are divided into two banks of 2,097,152 x 160-bit words per bank,
266 where the common A20 input selects which bank is currently being used.
267 This bank bit may not come from the graphics hardware and could just
268 be a spare I/O pin on some other chip, we don't know.
269 
270 Then, within the current bank selected, the video chip can generate
271 independent addresses for IC1-5 and IC6-10 in parallel, so that it can
272 read 80 bits from IC1-5 at one address, and 80 bits from IC6-10 at
273 another address simultaneously. Or it can drive the same address and
274 read a 160-bit word at once. Regardless both addresses are restricted
275 to the same bank as defined through A20.
276 
277 */
278 
279 // http://www.nicozon.net/watch/sm7834644  (first part is Aqua Stage video?)
280 // http://www.system16.com/hardware.php?id=841 has a picture of Aqua Stage showing the wide aspect
281 
282 
283 #include "emu.h"
284 #include "cpu/m68000/m68000.h"
285 #include "cpu/sh/sh2.h"
286 #include "machine/nvram.h"
287 #include "machine/timer.h"
288 #include "machine/315_5649.h"
289 #include "sound/scsp.h"
290 #include "emupal.h"
291 #include "rendlay.h"
292 #include "screen.h"
293 #include "speaker.h"
294 
295 #include "aquastge.lh"
296 
297 
298 #define CLIPMAXX_FULL (496-1)
299 #define CLIPMAXY_FULL (384-1)
300 #define CLIPMINX_FULL (0)
301 #define CLIPMINY_FULL (0)
302 
303 
304 class coolridr_state : public driver_device
305 {
306 public:
coolridr_state(const machine_config & mconfig,device_type type,const char * tag)307 	coolridr_state(const machine_config &mconfig, device_type type, const char *tag) :
308 		driver_device(mconfig, type, tag),
309 		m_textBytesToWrite(0x00),
310 		m_blitterSerialCount(0x00),
311 		m_blitterMode(0x00),
312 		m_textOffset(0x0000),
313 		m_maincpu(*this, "maincpu"),
314 		m_subcpu(*this,"sub"),
315 		m_soundcpu(*this,"soundcpu"),
316 		//m_dmac(*this, "i8237"),
317 		m_framebuffer_vram(*this, "fb_vram"),
318 		m_txt_vram(*this, "txt_vram"),
319 		m_txt_blit(*this, "txt_blit"),
320 		m_workram_h(*this, "workrah"),
321 		m_sound_dma(*this, "sound_dma"),
322 		m_soundram(*this, "soundram%u", 1U),
323 		m_rom(*this, "share1"),
324 		m_compressedgfx(*this, "compressedgfx"),
325 		m_io_config(*this, "CONFIG"),
326 		m_gfxdecode(*this, "gfxdecode"),
327 		m_palette(*this, "palette"),
328 		m_screen(*this, "screen")
329 	{
330 	}
331 
332 	// Blitter state
333 	uint16_t m_textBytesToWrite;
334 	int16_t  m_blitterSerialCount;
335 	uint8_t  m_blitterMode;
336 	uint8_t  m_blittype;
337 	uint16_t m_blitterAddr;
338 	uint16_t m_textOffset;
339 	uint32_t m_blitterClearMode;
340 	int16_t  m_blitterClearCount;
341 	std::unique_ptr<pen_t[]> m_fadedpals;
342 
343 	// store the blit params here
344 	uint32_t m_spriteblit[12];
345 	uint32_t m_vregs_address;
346 
347 	uint32_t m_clipvals[2][3];
348 	uint8_t  m_clipblitterMode[2]; // hack
349 
350 	required_device<sh2_device> m_maincpu;
351 	required_device<sh2_device> m_subcpu;
352 	required_device<cpu_device> m_soundcpu;
353 	//required_device<am9517a_device> m_dmac;
354 
355 	required_shared_ptr<uint32_t> m_framebuffer_vram;
356 	required_shared_ptr<uint32_t> m_txt_vram;
357 	required_shared_ptr<uint32_t> m_txt_blit;
358 	required_shared_ptr<uint32_t> m_workram_h;
359 	required_shared_ptr<uint32_t> m_sound_dma;
360 	required_shared_ptr_array<uint16_t, 2> m_soundram;
361 	required_shared_ptr<uint32_t> m_rom;
362 	required_region_ptr<uint8_t> m_compressedgfx;
363 	required_ioport m_io_config;
364 	required_device<gfxdecode_device> m_gfxdecode;
365 	required_device<palette_device> m_palette;
366 	required_device<screen_device> m_screen;
367 
368 	bitmap_ind16 m_temp_bitmap_sprites[2];
369 	//bitmap_ind16 m_zbuffer_bitmap[2];
370 
371 	bitmap_ind16 m_screen_bitmap[2];
372 	uint8_t m_an_mux_data;
373 	uint8_t m_sound_data, m_sound_fifo;
374 
375 	std::unique_ptr<uint16_t[]> m_expanded_10bit_gfx;
376 	std::unique_ptr<uint16_t[]> m_rearranged_16bit_gfx;
377 
378 	uint32_t get_20bit_data(uint32_t romoffset, int _20bitwordnum);
379 	uint16_t get_10bit_data(uint32_t romoffset, int _10bitwordnum);
380 
381 	uint32_t sound_dma_r(offs_t offset);
382 	void sound_dma_w(offs_t offset, uint32_t data, uint32_t mem_mask = ~0);
383 	uint32_t unk_blit_r(offs_t offset);
384 	void unk_blit_w(offs_t offset, uint32_t data, uint32_t mem_mask = ~0);
385 	void blit_mode_w(uint32_t data);
386 	void blit_data_w(address_space &space, uint32_t data);
387 	void fb_mode_w(offs_t offset, uint32_t data, uint32_t mem_mask = ~0);
388 	void fb_data_w(offs_t offset, uint32_t data);
389 
390 	void dma_w(address_space &space, offs_t offset, uint32_t data, uint32_t mem_mask = ~0);
391 	template<int Chip> uint16_t soundram_r(offs_t offset);
392 	template<int Chip> void soundram_w(offs_t offset, uint16_t data, uint16_t mem_mask = ~0);
393 	void lamps_w(uint8_t data);
394 	DECLARE_WRITE_LINE_MEMBER(scsp1_to_sh1_irq);
395 	DECLARE_WRITE_LINE_MEMBER(scsp2_to_sh1_irq);
396 	void sound_to_sh1_w(uint8_t data);
397 	void init_coolridr();
398 	void init_aquastge();
399 	virtual void machine_start() override;
400 	virtual void machine_reset() override;
401 	virtual void video_start() override;
402 
403 	uint32_t m_colbase;
404 
405 	void coolriders_drawgfx_opaque(bitmap_ind16 &dest, const rectangle &cliprect, gfx_element *gfx,
406 		uint32_t code, uint32_t color, int flipx, int flipy, int32_t destx, int32_t desty);
407 
408 	void coolriders_drawgfx_transpen(bitmap_ind16 &dest, const rectangle &cliprect, gfx_element *gfx,
409 		uint32_t code, uint32_t color, int flipx, int flipy, int32_t destx, int32_t desty,
410 		uint32_t transpen);
411 
412 	void draw_bg_coolridr(bitmap_ind16 &bitmap, const rectangle &cliprect, int which);
413 	template<int Screen> uint32_t screen_update(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect);
414 	void blit_current_sprite(address_space &space);
415 	TIMER_DEVICE_CALLBACK_MEMBER(interrupt_main);
416 	TIMER_DEVICE_CALLBACK_MEMBER(interrupt_sub);
417 	void scsp_irq(offs_t offset, uint8_t data);
418 
419 	void dma_transfer( address_space &space, uint16_t dma_index );
420 
421 	int m_debug_randompal;
422 
423 	std::unique_ptr<uint16_t[]> m_vram;
424 	std::unique_ptr<uint8_t[]> m_pcgram;
425 	std::unique_ptr<uint16_t[]> m_palram;
426 	int m_gfx_index;
427 	int m_color_bank;
428 	struct {
429 		uint32_t setting;
430 		uint8_t gradient;
431 	}m_rgb_ctrl[2];
432 	uint32_t m_pen_fill[2];
433 
434 	osd_work_queue *    m_work_queue[2]; // work queue, one per screen
435 	static void *draw_object_threaded(void *param, int threadid);
436 	int m_usethreads;
437 
438 	struct cool_render_object
439 	{
cool_render_objectcoolridr_state::cool_render_object440 		cool_render_object(coolridr_state &s) : state(s), colbase(s.m_colbase)
441 		{
442 			std::copy(std::begin(s.m_spriteblit), std::end(s.m_spriteblit), std::begin(spriteblit));
443 		}
444 
445 		std::unique_ptr<uint8_t []> indirect_tiles;
446 		std::unique_ptr<uint32_t []> indirect_zoom;
447 		uint32_t spriteblit[12];
448 		bitmap_ind16* drawbitmap = nullptr;
449 		//bitmap_ind16* zbitmap = nullptr;
450 		uint16_t zpri = 0;
451 		uint8_t blittype = 0;
452 		coolridr_state& state;
453 		uint32_t clipvals[3];
454 		int screen = 0;
455 		int colbase;
456 	};
457 
458 	std::unique_ptr<std::unique_ptr<cool_render_object> []> m_cool_render_object_list[2];
459 
460 	int m_listcount[2];
461 
462 	// the decode cache mechansim is an optimization
463 	// we know all gfx are in ROM, and that calling the RLE decompression every time they're used is slow, so we cache the decoded tiles
464 	// and objects after they're used, for future re-use, quite handy with a driving game.
465 
466 #define DECODECACHE_NUMOBJECTCACHES (128)
467 
468 #define DECODECACHE_NUMSPRITETILES (16*16)
469 
470 	// decode cache
471 	struct objectcache
472 	{
473 		// these needs to be all the elements actually going to affect the decode of an individual tile for any given object
474 		uint32_t lastromoffset;
475 		uint16_t lastused_flipx;
476 		uint16_t lastused_flipy;
477 		uint32_t lastblit_rotate;
478 		uint32_t lastb1mode;
479 		uint32_t lastb1colorNumber;
480 		uint32_t lastb2colorNumber;
481 		uint32_t lastb2altpenmask;
482 		uint16_t lastused_hCellCount;
483 		uint16_t lastused_vCellCount;
484 		int repeatcount;
485 
486 		struct dectile
487 		{
488 			uint16_t tempshape_multi[16*16];
489 			bool tempshape_multi_decoded;
490 			bool is_blank;
491 		};
492 
493 		dectile tiles[DECODECACHE_NUMSPRITETILES];
494 
495 	};
496 
497 	struct objcachemanager
498 	{
499 		int current_object;
500 		objectcache objcache[DECODECACHE_NUMOBJECTCACHES];
501 
502 		// fallback decode buffer for certain cases (indirect sprites, sprites too big for our buffer..)
503 		uint16_t tempshape[16*16];
504 	};
505 
506 	objcachemanager m_decode[2];
507 	void aquastge(machine_config &config);
508 	void coolridr(machine_config &config);
509 	void coolridr_h1_map(address_map &map);
510 	void aquastge_h1_map(address_map &map);
511 	void aquastge_submap(address_map &map);
512 	void coolridr_submap(address_map &map);
513 	void system_h1_map(address_map &map);
514 	void system_h1_submap(address_map &map);
515 	void system_h1_sound_map(address_map &map);
516 	template<int Chip> void scsp_map(address_map &map);
517 };
518 
519 #define PRINT_BLIT_STUFF \
520 	printf("type blit %08x %08x(%d, %03x) %08x(%02x, %03x) %08x(%06x) %08x(%08x, %d, %d, %d) %08x(%d,%d) %04x %04x %04x %04x %08x %08x %d %d\n", blit0, blit1_unused,b1mode,b1colorNumber, blit2_unused,b2tpen,b2colorNumber, blit3_unused,b3romoffset, blit4_unused, blit4blendlevel, blit_flipy,blit_rotate, blit_flipx, blit5_unused, indirect_tile_enable, indirect_zoom_enable, vCellCount, hCellCount, vZoom, hZoom, blit10, textlookup, vPosition, hPosition);
521 
522 
523 /* video */
524 
525 #define VRAM_SIZE 0x100000
526 
527 static const gfx_layout h1_tile_layout =
528 {
529 	16,16,
530 	0x1000,
531 	8,
532 	{ STEP8(0,1) },
533 	{ STEP16(0,8) },
534 	{ STEP16(0,8*16) },
535 	16*128
536 };
537 
538 
video_start()539 void coolridr_state::video_start()
540 {
541 	/* find first empty slot to decode gfx */
542 	for (m_gfx_index = 0; m_gfx_index < MAX_GFX_ELEMENTS; m_gfx_index++)
543 		if (m_gfxdecode->gfx(m_gfx_index) == nullptr)
544 			break;
545 
546 	m_fadedpals = make_unique_clear<pen_t[]>(0x8000);
547 	m_vram = make_unique_clear<uint16_t[]>(VRAM_SIZE);
548 	m_pcgram = make_unique_clear<uint8_t[]>(VRAM_SIZE);
549 	m_palram = make_unique_clear<uint16_t[]>(VRAM_SIZE);
550 
551 	m_cool_render_object_list[0] = std::make_unique<std::unique_ptr<cool_render_object> []>(1000000);
552 	m_listcount[0] = 0;
553 
554 	m_cool_render_object_list[1] = std::make_unique<std::unique_ptr<cool_render_object> []>(1000000);
555 	m_listcount[1] = 0;
556 
557 	m_screen->register_screen_bitmap(m_temp_bitmap_sprites[0]);
558 	m_screen->register_screen_bitmap(m_temp_bitmap_sprites[1]);
559 	//m_screen->register_screen_bitmap(m_zbuffer_bitmap[0]);
560 	//m_screen->register_screen_bitmap(m_zbuffer_bitmap[1]);
561 
562 	m_screen->register_screen_bitmap(m_screen_bitmap[0]);
563 	m_screen->register_screen_bitmap(m_screen_bitmap[1]);
564 
565 	m_gfxdecode->set_gfx(m_gfx_index, std::make_unique<gfx_element>(m_palette, h1_tile_layout, m_pcgram.get(), 0, 8, 0));
566 
567 	m_debug_randompal = 9;
568 
569 	save_pointer(NAME(m_fadedpals), 0x8000);
570 	save_pointer(NAME(m_vram), VRAM_SIZE);
571 	save_pointer(NAME(m_pcgram), VRAM_SIZE);
572 	save_pointer(NAME(m_palram), VRAM_SIZE);
573 }
574 
575 /*
576     vregs are setted up with one of DMA commands (see below)
577     0x3e09b80 screen 1 base, 0x3e9bc0 screen 2 base
578     [+0x1c] ---- ---- ---- ---- ---- ---- ---- -xxx tile offset start * 0x8000
579     [+0x2c] ---- -xxx xxxx xxxx ---- --yy yyyy yyyy scrolling registers
580     [+0x34] 1111 1111 2222 2222 3333 3333 4444 4444 - Almost surely Sega "map" registers
581     [+0x38] 5555 5555 6666 6666 7777 7777 8888 8888 /
582     [+0x3c] x--- ---- ---- ---- xxxx xxxx xxxx xxxx 0x11b8 on bike select, 0xffffffff otherwise, transparent pen value?
583     (everything else is unknown at current time)
584 */
585 
586 #define COOLRIDERS_DRAWGFX_CORE(PIXEL_TYPE, COOL_PIXEL_OP)                               \
587 do {                                                                                    \
588 	do {                                                                                \
589 		const uint8_t *srcdata;                                                           \
590 		int32_t destendx, destendy;                                                       \
591 		int32_t srcx, srcy;                                                               \
592 		int32_t curx, cury;                                                               \
593 		int32_t dy;                                                                       \
594 																						\
595 		assert(dest.valid());                                                           \
596 		assert(gfx != nullptr);                                                            \
597 		assert(dest.cliprect().contains(cliprect));                                     \
598 		assert(code < gfx->elements());                                             \
599 																						\
600 		/* ignore empty/invalid cliprects */                                            \
601 		if (cliprect.empty())                                                           \
602 			break;                                                                      \
603 																						\
604 		/* compute final pixel in X and exit if we are entirely clipped */              \
605 		destendx = destx + gfx->width() - 1;                                                \
606 		if (destx > cliprect.max_x || destendx < cliprect.min_x)                        \
607 			break;                                                                      \
608 																						\
609 		/* apply left clip */                                                           \
610 		srcx = 0;                                                                       \
611 		if (destx < cliprect.min_x)                                                     \
612 		{                                                                               \
613 			srcx = cliprect.min_x - destx;                                              \
614 			destx = cliprect.min_x;                                                     \
615 		}                                                                               \
616 																						\
617 		/* apply right clip */                                                          \
618 		if (destendx > cliprect.max_x)                                                  \
619 			destendx = cliprect.max_x;                                                  \
620 																						\
621 		/* compute final pixel in Y and exit if we are entirely clipped */              \
622 		destendy = desty + gfx->height() - 1;                                               \
623 		if (desty > cliprect.max_y || destendy < cliprect.min_y)                        \
624 			break;                                                                      \
625 																						\
626 		/* apply top clip */                                                            \
627 		srcy = 0;                                                                       \
628 		if (desty < cliprect.min_y)                                                     \
629 		{                                                                               \
630 			srcy = cliprect.min_y - desty;                                              \
631 			desty = cliprect.min_y;                                                     \
632 		}                                                                               \
633 																						\
634 		/* apply bottom clip */                                                         \
635 		if (destendy > cliprect.max_y)                                                  \
636 			destendy = cliprect.max_y;                                                  \
637 																						\
638 		/* apply X flipping */                                                          \
639 		if (flipx)                                                                      \
640 			srcx = gfx->width() - 1 - srcx;                                             \
641 																						\
642 		/* apply Y flipping */                                                          \
643 		dy = gfx->rowbytes();                                                           \
644 		if (flipy)                                                                      \
645 		{                                                                               \
646 			srcy = gfx->height() - 1 - srcy;                                                \
647 			dy = -dy;                                                                   \
648 		}                                                                               \
649 																						\
650 		/* fetch the source data */                                                     \
651 		srcdata = gfx->get_data(code);                                      \
652 																						\
653 		/* compute how many blocks of 4 pixels we have */                           \
654 		uint32_t numblocks = (destendx + 1 - destx) / 4;                              \
655 		uint32_t leftovers = (destendx + 1 - destx) - 4 * numblocks;                  \
656 																					\
657 		/* adjust srcdata to point to the first source pixel of the row */          \
658 		srcdata += srcy * gfx->rowbytes() + srcx;                                   \
659 																					\
660 		/* non-flipped 8bpp case */                                                 \
661 		if (!flipx)                                                                 \
662 		{                                                                           \
663 			/* iterate over pixels in Y */                                          \
664 			for (cury = desty; cury <= destendy; cury++)                            \
665 			{                                                                       \
666 				PIXEL_TYPE *destptr = &dest.pix(cury, destx);                       \
667 				const uint8_t *srcptr = srcdata;                                    \
668 				srcdata += dy;                                                      \
669 																					\
670 				/* iterate over unrolled blocks of 4 */                             \
671 				for (curx = 0; curx < numblocks; curx++)                            \
672 				{                                                                   \
673 					COOL_PIXEL_OP(destptr[0], srcptr[0]);                           \
674 					COOL_PIXEL_OP(destptr[1], srcptr[1]);                           \
675 					COOL_PIXEL_OP(destptr[2], srcptr[2]);                           \
676 					COOL_PIXEL_OP(destptr[3], srcptr[3]);                           \
677 																					\
678 					srcptr += 4;                                                    \
679 					destptr += 4;                                                   \
680 				}                                                                   \
681 																					\
682 				/* iterate over leftover pixels */                                  \
683 				for (curx = 0; curx < leftovers; curx++)                            \
684 				{                                                                   \
685 					COOL_PIXEL_OP(destptr[0], srcptr[0]);                           \
686 					srcptr++;                                                       \
687 					destptr++;                                                      \
688 				}                                                                   \
689 			}                                                                       \
690 		}                                                                           \
691 																					\
692 		/* flipped 8bpp case */                                                     \
693 		else                                                                        \
694 		{                                                                           \
695 			/* iterate over pixels in Y */                                          \
696 			for (cury = desty; cury <= destendy; cury++)                            \
697 			{                                                                       \
698 				PIXEL_TYPE *destptr = &dest.pix(cury, destx);                       \
699 				const uint8_t *srcptr = srcdata;                                    \
700 				srcdata += dy;                                                      \
701 																					\
702 				/* iterate over unrolled blocks of 4 */                             \
703 				for (curx = 0; curx < numblocks; curx++)                            \
704 				{                                                                   \
705 					COOL_PIXEL_OP(destptr[0], srcptr[ 0]);                    \
706 					COOL_PIXEL_OP(destptr[1], srcptr[-1]);                    \
707 					COOL_PIXEL_OP(destptr[2], srcptr[-2]);                    \
708 					COOL_PIXEL_OP(destptr[3], srcptr[-3]);                    \
709 																					\
710 					srcptr -= 4;                                                    \
711 					destptr += 4;                                                   \
712 				}                                                                   \
713 																					\
714 				/* iterate over leftover pixels */                                  \
715 				for (curx = 0; curx < leftovers; curx++)                            \
716 				{                                                                   \
717 					COOL_PIXEL_OP(destptr[0], srcptr[0]);                     \
718 					srcptr--;                                                       \
719 					destptr++;                                                      \
720 				}                                                                   \
721 			}                                                                       \
722 		}                                                                           \
723 	} while (0);                                                                        \
724 } while (0)
725 
726 
727 #define COOLRIDERS_PIXEL_OP_REMAP_OPAQUE(DEST, SOURCE)                               \
728 do                                                                                  \
729 {                                                                                   \
730 	(DEST) = paldata[SOURCE];                                                       \
731 }                                                                                   \
732 while (0)
733 
734 #define COOLRIDERS_PIXEL_OP_REMAP_TRANSPEN(DEST, SOURCE)                             \
735 do                                                                                  \
736 {                                                                                   \
737 	uint32_t srcdata = (SOURCE);                                                      \
738 	if (srcdata != transpen)                                                        \
739 		(DEST) = paldata[srcdata];                                                  \
740 }                                                                                   \
741 while (0)
742 
743 
744 
coolriders_drawgfx_opaque(bitmap_ind16 & dest,const rectangle & cliprect,gfx_element * gfx,uint32_t code,uint32_t color,int flipx,int flipy,int32_t destx,int32_t desty)745 void coolridr_state::coolriders_drawgfx_opaque(bitmap_ind16 &dest, const rectangle &cliprect, gfx_element *gfx,
746 		uint32_t code, uint32_t color, int flipx, int flipy, int32_t destx, int32_t desty)
747 {
748 	const uint16_t *paldata = &m_palram[gfx->colorbase() + gfx->granularity() * (color % gfx->colors())];
749 	code %= gfx->elements();
750 	COOLRIDERS_DRAWGFX_CORE(uint16_t, COOLRIDERS_PIXEL_OP_REMAP_OPAQUE);
751 }
752 
coolriders_drawgfx_transpen(bitmap_ind16 & dest,const rectangle & cliprect,gfx_element * gfx,uint32_t code,uint32_t color,int flipx,int flipy,int32_t destx,int32_t desty,uint32_t transpen)753 void coolridr_state::coolriders_drawgfx_transpen(bitmap_ind16 &dest, const rectangle &cliprect, gfx_element *gfx,
754 		uint32_t code, uint32_t color, int flipx, int flipy, int32_t destx, int32_t desty,
755 		uint32_t transpen)
756 {
757 	// special case invalid pens to opaque
758 	if (transpen > 0xff)
759 		return coolriders_drawgfx_opaque(dest, cliprect, gfx, code, color, flipx, flipy, destx, desty);
760 
761 	// use pen usage to optimize
762 	code %= gfx->elements();
763 	if (gfx->has_pen_usage())
764 	{
765 		// fully transparent; do nothing
766 		uint32_t usage = gfx->pen_usage(code);
767 		if ((usage & ~(1 << transpen)) == 0)
768 			return;
769 
770 		// fully opaque; draw as such
771 		if ((usage & (1 << transpen)) == 0)
772 			return coolriders_drawgfx_opaque(dest, cliprect, gfx, code, color, flipx, flipy, destx, desty);
773 	}
774 
775 	// render
776 	const uint16_t *paldata = &m_palram[gfx->colorbase() + gfx->granularity() * (color % gfx->colors())] ;
777 	COOLRIDERS_DRAWGFX_CORE(uint16_t, COOLRIDERS_PIXEL_OP_REMAP_TRANSPEN);
778 }
779 
draw_bg_coolridr(bitmap_ind16 & bitmap,const rectangle & cliprect,int which)780 void coolridr_state::draw_bg_coolridr(bitmap_ind16 &bitmap, const rectangle &cliprect, int which)
781 {
782 	int bg_r,bg_g,bg_b;
783 	address_space &space = m_maincpu->space(AS_PROGRAM);
784 
785 	if(m_pen_fill[which])
786 	{
787 #if 0
788 		/* logic here is a bit of a guess. - should probably be 555 like everything else.. or we are going to have to have a rgb32 bitmap? */
789 		bg_r = (((m_pen_fill[which] >> 16) & 0x7f) << 1) | (((m_pen_fill[which] >> 16) & 0x80) >> 7);
790 		bg_g = (((m_pen_fill[which] >> 8) & 0x7f) << 1) | (((m_pen_fill[which] >> 8) & 0x80) >> 7);
791 		bg_b = (((m_pen_fill[which] >> 0) & 0x7f) << 1) | (((m_pen_fill[which] >> 0) & 0x80) >> 7);
792 		bitmap.fill(rgb_t(0xff,bg_r,bg_g,bg_b),cliprect);
793 #endif
794 
795 		bg_r = (((m_pen_fill[which] >> 16) & 0x78) >> 2) | (((m_pen_fill[which] >> 16) & 0x80) >> 7);
796 		bg_g = (((m_pen_fill[which] >> 8) & 0x78) >> 2) | (((m_pen_fill[which] >> 8) & 0x80) >> 7);
797 		bg_b = (((m_pen_fill[which] >> 0) & 0x78) >> 2) | (((m_pen_fill[which] >> 0) & 0x80) >> 7);
798 		bitmap.fill( (bg_r<<10) | (bg_g << 5) | bg_b  ,cliprect);
799 	}
800 	else
801 	{
802 		uint8_t transpen_setting;
803 		gfx_element *gfx = m_gfxdecode->gfx(m_gfx_index);
804 		#define VREG(_offs) \
805 			space.read_dword(m_vregs_address+_offs+which*0x40)
806 
807 		uint16_t const scrollx = (VREG(0x2c) >> 16) & 0x7ff;
808 		uint16_t const scrolly = VREG(0x2c) & 0x3ff;
809 
810 		uint32_t const base_offset = (VREG(0x1c) * 0x8000)/2;
811 		m_color_bank = which * 2;
812 		/* TODO: the whole transpen logic might be incorrect */
813 		transpen_setting = (VREG(0x3c) & 0x80000000) >> 31;
814 		bg_r = (VREG(0x3c) >> 10) & 0x1f;
815 		bg_g = (VREG(0x3c) >> 5) & 0x1f;
816 		bg_b = (VREG(0x3c) >> 0) & 0x1f;
817 
818 		bitmap.fill(VREG(0x3c),cliprect);
819 
820 
821 		uint16_t basey = ((scrolly + cliprect.top()) & 0x3ff) >> 4;
822 		for (int y = cliprect.top() >> 4; y <= (cliprect.bottom() + 15) >> 4; y++)
823 		{
824 			uint16_t basex = ((scrollx + cliprect.left()) & 0x7ff) >> 4;
825 			for (int x = cliprect.left() >> 4; x <= (cliprect.right() + 15) >> 4; x++)
826 			{
827 				uint16_t const vram_data = (m_vram[((basex&0x7f)+((basey&0x3f)*0x80)+base_offset)&0x07ffff] & 0xffff);
828 				uint16_t const color = m_color_bank + ((vram_data & 0x800) >> 11) * 4;
829 				/* bike select enables bits 15-12, pretty sure one of these is tile bank (because there's a solid pen on 0x3ff / 0x7ff). */
830 				uint16_t const tile = (vram_data & 0x7ff) | ((vram_data & 0x8000) >> 4);
831 
832 				coolriders_drawgfx_transpen(bitmap,cliprect,gfx,tile,color,0,0,(x*16)-(scrollx&0xf),(y*16)-(scrolly&0xf),transpen_setting ? -1 : 0);
833 
834 				basex++;
835 			}
836 			basey++;
837 		}
838 	}
839 
840 
841 }
842 
843 template<int Screen>
screen_update(screen_device & screen,bitmap_ind16 & bitmap,const rectangle & cliprect)844 uint32_t coolridr_state::screen_update(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect)
845 {
846 	if(m_rgb_ctrl[Screen].gradient)
847 	{
848 		if( (m_rgb_ctrl[Screen].setting == 0x1240) || (m_rgb_ctrl[Screen].setting == 0x920) || (m_rgb_ctrl[Screen].setting == 0x800) )
849 		{
850 		}
851 		else
852 		{
853 			popmessage("%08x %08x",m_rgb_ctrl[Screen].setting,m_rgb_ctrl[Screen].gradient);
854 		}
855 	}
856 
857 #if 0
858 	if (machine().input().code_pressed_once(KEYCODE_W))
859 	{
860 		m_debug_randompal++;
861 		popmessage("%02x",m_debug_randompal);
862 	}
863 	if (machine().input().code_pressed_once(KEYCODE_Q))
864 	{
865 		m_debug_randompal--;
866 		popmessage("%02x",m_debug_randompal);
867 	}
868 #endif
869 
870 	// there are probably better ways to do this
871 	for (int i = 0; i < 0x8000; i++)
872 	{
873 		int r = (i >> 10)&0x1f;
874 		int g = (i >> 5)&0x1f;
875 		int b = (i >> 0)&0x1f;
876 
877 		if(m_rgb_ctrl[Screen].gradient)
878 		{
879 			/* fade-in / outs */
880 			if(m_rgb_ctrl[Screen].setting == 0x1240)
881 			{
882 				r -= m_rgb_ctrl[Screen].gradient;
883 				g -= m_rgb_ctrl[Screen].gradient;
884 				b -= m_rgb_ctrl[Screen].gradient;
885 				if(r < 0) { r = 0; }
886 				if(g < 0) { g = 0; }
887 				if(b < 0) { b = 0; }
888 			}
889 			else if(m_rgb_ctrl[Screen].setting == 0x920) /* at bike select / outside tunnels, addition */
890 			{
891 				r += m_rgb_ctrl[Screen].gradient;
892 				g += m_rgb_ctrl[Screen].gradient;
893 				b += m_rgb_ctrl[Screen].gradient;
894 				if(r > 0x1f) { r = 0x1f; }
895 				if(g > 0x1f) { g = 0x1f; }
896 				if(b > 0x1f) { b = 0x1f; }
897 			}
898 			else if(m_rgb_ctrl[Screen].setting == 0x800) /* when you get hit TODO: algo might be different. */
899 			{
900 				r += m_rgb_ctrl[Screen].gradient;
901 				g -= m_rgb_ctrl[Screen].gradient;
902 				b -= m_rgb_ctrl[Screen].gradient;
903 				if(r > 0x1f) { r = 0x1f; }
904 				if(g < 0) { g = 0; }
905 				if(b < 0) { b = 0; }
906 			}
907 		}
908 		m_fadedpals[i] = (r<<10|g<<5|b);
909 	}
910 
911 	for (int y = cliprect.top(); y <= cliprect.bottom(); y++)
912 	{
913 		uint16_t const *const linesrc = &m_screen_bitmap[Screen].pix(y);
914 		uint16_t *const linedest = &bitmap.pix(y);
915 
916 		for (int x = cliprect.left(); x<= cliprect.right(); x++)
917 		{
918 			linedest[x] = m_fadedpals[linesrc[x]];
919 		}
920 	}
921 
922 	return 0;
923 }
924 
925 /* end video */
926 
927 
928 #define RLE_BLOCK(writeaddrxor) \
929 	/* skip the decoding if it's the same tile as last time! */ \
930 	if (!current_decoded) \
931 	{ \
932 		lastSpriteNumber = 0xffffffff; /* this optimization is currently broken, so hack it to be disabled here */ \
933 		if (spriteNumber != lastSpriteNumber) \
934 		{ \
935 			blankcount = 256;\
936 			lastSpriteNumber = spriteNumber; \
937 			\
938 			int i = 1;/* skip first 10 bits for now */ \
939 			int data_written = 0; \
940 		\
941 			while (data_written<256) \
942 			{ \
943 		\
944 				const uint16_t compdata = expanded_10bit_gfx[ (b3romoffset) + spriteNumber + i]; \
945 		\
946 				if (((compdata & 0x300) == 0x000) || ((compdata & 0x300) == 0x100)) /* 3bpp */ \
947 				{ \
948 					/* mm ccrr rrr0 */ \
949 					int encodelength = (compdata & 0x03e)>>1; \
950 					const uint16_t rledata =  rearranged_16bit_gfx[color_offs + ((compdata & 0x1c0) >> 6)]; \
951 					/* guess, blank tiles have the following form */ \
952 					/* 00120 (00000024,0) | 010 03f */ \
953 					if (compdata&1) encodelength = 255; \
954 		\
955 					while (data_written<256 && encodelength >=0) \
956 					{ \
957 						tempshape[data_written^writeaddrxor] = rledata; \
958 						if (tempshape[data_written^writeaddrxor]==0x8000) blankcount--; \
959 						encodelength--; \
960 						data_written++; \
961 					} \
962 				} \
963 				else if ((compdata & 0x300) == 0x200) /* 6bpp */ \
964 				{ \
965 					/* mm cccc ccrr */ \
966 					int encodelength = (compdata & 0x003);           \
967 					const uint16_t rledata = rearranged_16bit_gfx[color_offs + ((compdata & 0x0fc) >> 2) + 8]; \
968 					while (data_written<256 && encodelength >=0) \
969 					{ \
970 						tempshape[data_written^writeaddrxor] = rledata; /* + 0x8 crt test, most of red, green, start of blue */ \
971 						if (tempshape[data_written^writeaddrxor]==0x8000) blankcount--; \
972 						encodelength--; \
973 						data_written++; \
974 					} \
975 				} \
976 				else /* 8bpp */ \
977 				{ \
978 					/* mm cccc cccc */ \
979 					uint16_t rawdat = (compdata & 0x0ff); \
980 					if (b1mode && (rawdat > (b2altpenmask + 0x48))) /* does this have to be turned on by b1mode? road ends up with some bad pixels otherwise but maybe the calc is wrong... does it affect the other colour depths too? */ \
981 						tempshape[data_written^writeaddrxor] = rearranged_16bit_gfx[color_offs2 + (rawdat )+0x48]; /* bike wheels + brake light */ \
982 					else \
983 						tempshape[data_written^writeaddrxor] = rearranged_16bit_gfx[color_offs + (rawdat )+0x48]; /* +0x48 crt test end of blue, start of white */ \
984 					if (tempshape[data_written^writeaddrxor]==0x8000) blankcount--; \
985 					data_written++; \
986 				} \
987 		\
988 				i++; \
989 			} \
990 			if (!indirect_tile_enable && size < DECODECACHE_NUMSPRITETILES) \
991 			{ \
992 				object->state.m_decode[screen].objcache[use_object].tiles[v*used_hCellCount + h].tempshape_multi_decoded = true; \
993 				if (blankcount==0) \
994 					object->state.m_decode[screen].objcache[use_object].tiles[v*used_hCellCount + h].is_blank = true; \
995 				else \
996 					object->state.m_decode[screen].objcache[use_object].tiles[v*used_hCellCount + h].is_blank = false; \
997 				/* if (object->screen==0) printf("marking offset %04x as decoded (sprite number %08x ptr %08x)\n", v*used_hCellCount + h, spriteNumber, ((uint64_t)(void*)tempshape)&0xffffffff);*/ \
998 			} \
999 		} \
1000 	}
1001 
1002 
1003 #define CHECK_DECODE \
1004 	if (used_flipy) \
1005 	{ \
1006 		if (used_flipx) \
1007 		{ \
1008 			RLE_BLOCK(0xff) \
1009 		} \
1010 		else \
1011 		{ \
1012 			RLE_BLOCK(0xf0) \
1013 		} \
1014 	} \
1015 	else \
1016 	{   if (used_flipx) \
1017 		{ \
1018 			RLE_BLOCK(0x0f) \
1019 		} \
1020 		else \
1021 		{ \
1022 			RLE_BLOCK(0x00) \
1023 		} \
1024 	} \
1025 	if (!indirect_tile_enable && size < DECODECACHE_NUMSPRITETILES) \
1026 	{ \
1027 		if (object->state.m_decode[screen].objcache[use_object].tiles[v*used_hCellCount + h].is_blank == true) \
1028 				continue; \
1029 	} \
1030 	else \
1031 		if (blankcount==0) continue;
1032 
1033 
1034 #define GET_SPRITE_NUMBER \
1035 	int lookupnum; \
1036 	/* with this bit enabled the tile numbers gets looked up using 'data' (which would be blit11) (eg 03f40000 for startup text) */ \
1037 	/* this allows text strings to be written as 8-bit ascii in one area (using command 0x10), and drawn using multi-width sprites */ \
1038 	if (indirect_tile_enable) \
1039 	{ \
1040 		/* this doesn't handle the various flip modes.. */ \
1041 		lookupnum = object->indirect_tiles[h + (v*used_hCellCount)]; \
1042 	} \
1043 	else \
1044 	{ \
1045 		if (!blit_rotate) \
1046 		{ \
1047 			if (!used_flipy) \
1048 			{ \
1049 				if (!used_flipx) \
1050 					lookupnum = h + (v*used_hCellCount); \
1051 				else \
1052 					lookupnum = (used_hCellCount-h-1) + (v*used_hCellCount); \
1053 			} \
1054 			else \
1055 			{ \
1056 				if (!used_flipx) \
1057 					lookupnum = h + ((used_vCellCount-v-1)*used_hCellCount); \
1058 				else \
1059 					lookupnum = (used_hCellCount-h-1) + ((used_vCellCount-v-1)*used_hCellCount); \
1060 			} \
1061 		} \
1062 		else \
1063 		{ \
1064 			if (!used_flipy) \
1065 			{ \
1066 				if (!used_flipx) \
1067 					lookupnum = v + (h*used_vCellCount); \
1068 				else \
1069 					lookupnum = (used_vCellCount-v-1) + (h*used_vCellCount); \
1070 			} \
1071 			else \
1072 			{ \
1073 				if (!used_flipx) \
1074 					lookupnum = v + ((used_hCellCount-h-1)*used_vCellCount); \
1075 				else \
1076 					lookupnum = (used_vCellCount-v-1) + ((used_hCellCount-h-1)*used_vCellCount); \
1077 			} \
1078 		} \
1079 	} \
1080 	uint32_t spriteNumber = (expanded_10bit_gfx[ (b3romoffset) + (lookupnum<<1) +0 ] << 10) | (expanded_10bit_gfx[ (b3romoffset) + (lookupnum<<1) + 1 ]);
1081 
1082 #define DO_XCLIP_REAL \
1083 	if (drawx>clipmaxX) { break; } \
1084 	if (drawx<clipminX) { drawx++; continue; }
1085 
1086 #define DO_XCLIP_NONE \
1087 	{ \
1088 	}
1089 
1090 
1091 #define GET_CURRENT_LINESCROLLZOOM \
1092 	uint32_t dword = object->indirect_zoom[v*16+realy]; \
1093 	uint16_t hZoomHere = hZoom + (dword>>16); \
1094 	if (!hZoomHere) { drawy++; continue; } \
1095 	/* bit 0x8000 does get set too, but only on some lines, might have another meaning? */ \
1096 	int linescroll = dword&0x7fff; \
1097 	if (linescroll & 0x4000) linescroll -= 0x8000; \
1098 	int hPositionTable = linescroll + hPositionx; \
1099 	/* DON'T use the table hZoom in this calc? (road..) */ \
1100 	int sizex = used_hCellCount * 16 * hZoom; \
1101 	hPositionTable *= 0x40; \
1102 	switch (hOrigin & 3) \
1103 	{ \
1104 	case 0: \
1105 		/* left */ \
1106 		break; \
1107 	case 1: \
1108 		hPositionTable -= sizex / 2; \
1109 		/* middle? */ \
1110 		break; \
1111 	case 2: \
1112 		hPositionTable -= sizex-1; \
1113 		/* right? */ \
1114 		break; \
1115 	case 3: \
1116 		/* invalid? */ \
1117 		break; \
1118 	}
1119 
1120 
1121 
1122 #define YXLOOP \
1123 	int drawy = pixelOffsetY; \
1124 	for (int y = 0; y < blockhigh; y++) \
1125 	{ \
1126 		int realy = ((y*incy)>>21); \
1127 		GET_CURRENT_LINESCROLLZOOM \
1128 		const int pixelOffsetX = ((hPositionTable) + (h* 16 * hZoomHere)) / 0x40; \
1129 		const int pixelOffsetnextX = ((hPositionTable) + ((h+1)* 16 * hZoomHere)) / 0x40; \
1130 		if (drawy>clipmaxY) { break; }; \
1131 		if (drawy<clipminY) { drawy++; continue; }; \
1132 		uint16_t *const line = &drawbitmap->pix(drawy); \
1133 		/* uint16_t *const zline = &object->zbitmap->pix(drawy); */ \
1134 		int blockwide = pixelOffsetnextX-pixelOffsetX; \
1135 		if (pixelOffsetX+blockwide <clipminX) { drawy++; continue; } \
1136 		if (pixelOffsetX>clipmaxX)  { drawy++; continue; } \
1137 		if (pixelOffsetX>=clipminX && pixelOffsetX+blockwide<clipmaxX) \
1138 		{ \
1139 			uint32_t incx = 0x8000000 / hZoomHere; \
1140 			int drawx = pixelOffsetX; \
1141 			for (int x = 0; x < blockwide; x++) \
1142 			{ \
1143 				DO_XCLIP_NONE \
1144 				int realx = ((x*incx)>>21); \
1145 				GET_PIX; \
1146 				DRAW_PIX; \
1147 			} \
1148 		} \
1149 		else \
1150 		{ \
1151 			uint32_t incx = 0x8000000 / hZoomHere; \
1152 			int drawx = pixelOffsetX; \
1153 			for (int x = 0; x < blockwide; x++) \
1154 			{ \
1155 				DO_XCLIP_REAL \
1156 				int realx = ((x*incx)>>21); \
1157 				GET_PIX; \
1158 				DRAW_PIX; \
1159 			} \
1160 		} \
1161 		drawy++; \
1162 	}
1163 
1164 #define YXLOOP_NO_LINEZOOM \
1165 	for (int y = 0; y < blockhigh; y++) \
1166 	{ \
1167 		int realy = ((y*incy)>>21); \
1168 		const int drawy = pixelOffsetY+y; \
1169 		if ((drawy>clipmaxY) || (drawy<clipminY)) continue; \
1170 		uint16_t *const line = &drawbitmap->pix(drawy); \
1171 		/* uint16_t *const zline = &object->zbitmap->pix(drawy); */ \
1172 		int drawx = pixelOffsetX; \
1173 		for (int x = 0; x < blockwide; x++) \
1174 		{ \
1175 			DO_XCLIP \
1176 			int realx = ((x*incx)>>21); \
1177 			GET_PIX; \
1178 			DRAW_PIX \
1179 		} \
1180 	}
1181 
1182 
1183 #define YXLOOP_NO_ZOOM \
1184 	for (int realy = 0; realy < 16; realy++) \
1185 	{ \
1186 		const int drawy = pixelOffsetY+realy; \
1187 		if ((drawy>clipmaxY) || (drawy<clipminY)) continue; \
1188 		uint16_t *const line = &drawbitmap->pix(drawy); \
1189 		/* uint16_t *const zline = &object->zbitmap->pix(drawy); */ \
1190 		int drawx = pixelOffsetX; \
1191 		for (int realx = 0; realx < 16; realx++) \
1192 		{ \
1193 			DO_XCLIP \
1194 			GET_PIX; \
1195 			DRAW_PIX \
1196 		} \
1197 	}
1198 
1199 
1200 /* the two tables that the patent claims are located at:
1201     0x1ec800
1202     0x1f0000
1203     0x3ec800
1204     0x3f0000
1205 of each rom ... ROM 1 + 2 gives the full palette data for each pixel, in even/odd order.
1206 TODO: fix anything that isn't text.
1207 */
1208 
1209 
1210 
1211 
1212 
1213 #define DRAW_PIX \
1214 	/* I think 0x8000 is ALWAYS transparent */ \
1215 	/* values < 0x8000 have no alpha effect to them */ \
1216 	if (pix < 0x8000) \
1217 	{ \
1218 		/*if (object->zpri < zline[drawx])*/ \
1219 		{ \
1220 			{ \
1221 				line[drawx] = pix&0x7fff; \
1222 				/*zline[drawx] = object->zpri;*/ \
1223 			} \
1224 		} \
1225 	} \
1226 	/* values > 0x8000 have blending */ \
1227 	else if (pix > 0x8000) \
1228 	{ \
1229 		/* a blend level of 0x8 (real register value 0x7 but we added one so we can shift instead of divide in code below) seems to be the same as solid, it is set on most parts of the road and during the 'lovemachine' animation in attract when the heart should be hidden */ \
1230 		/* if (object->zpri < zline[drawx]) */ \
1231 		{ \
1232 			if (blit4blendlevelinv==0x0) \
1233 			{ \
1234 				line[drawx] = pix&0x7fff; \
1235 				/* zline[drawx] = object->zpri; */ \
1236 			} \
1237 			else \
1238 			{ \
1239 				uint16_t source = line[drawx]; \
1240 				int src_r = ((source>>10)&0x1f) * blit4blendlevelinv; \
1241 				int src_g = ((source>>5)&0x1f)  * blit4blendlevelinv; \
1242 				int src_b = ((source>>0)&0x1f)  * blit4blendlevelinv; \
1243 				int dest_r = ((pix>>10)&0x1f) * blit4blendlevel; \
1244 				int dest_g = ((pix>>5)&0x1f)  * blit4blendlevel; \
1245 				int dest_b = ((pix>>0)&0x1f)  * blit4blendlevel; \
1246 				line[drawx] = (((src_r+dest_r)>>3)<<10) | (((src_g+dest_g)>>3)<<5) | (((src_b+dest_b)>>3)<<0); \
1247 				/* zline[drawx] = object->zpri; */ \
1248 			} \
1249 		} \
1250 	} \
1251 	drawx++;
1252 
1253 
1254 //object->rearranged_16bit_gfx
1255 //object->expanded_10bit_gfx
1256 
1257 #define GET_PIX_ROTATED \
1258 		uint16_t pix = tempshape[realx*16+realy];
1259 #define GET_PIX_NORMAL \
1260 		uint16_t pix = tempshape[realy*16+realx];
1261 
draw_object_threaded(void * param,int threadid)1262 void *coolridr_state::draw_object_threaded(void *param, int threadid)
1263 {
1264 	const std::unique_ptr<cool_render_object> object(reinterpret_cast<cool_render_object *>(param));
1265 	bitmap_ind16* drawbitmap = object->drawbitmap;
1266 
1267 	/************* object->spriteblit[3] *************/
1268 
1269 	uint32_t blit3_unused = object->spriteblit[3] & 0xffe00000;
1270 	uint32_t b3romoffset = (object->spriteblit[3] & 0x001fffff)*16;
1271 
1272 	if (blit3_unused) printf("unknown bits in blit word %d -  %08x\n", 3, blit3_unused);
1273 
1274 	/************* object->spriteblit[5] *************/
1275 
1276 	uint32_t blit5_unused = object->spriteblit[5]&0xfffefffe;
1277 	// this might enable the text indirection thing?
1278 	int indirect_tile_enable = (object->spriteblit[5] & 0x00010000)>>16;
1279 	int indirect_zoom_enable = (object->spriteblit[5] & 0x00000001);
1280 
1281 
1282 	if (blit5_unused) printf("unknown bits in blit word %d -  %08x\n", 5, blit5_unused);
1283 	// 00010000 (text)
1284 	// 00000001 (other)
1285 
1286 
1287 
1288 
1289 	uint16_t* rearranged_16bit_gfx = object->state.m_rearranged_16bit_gfx.get();
1290 	uint16_t* expanded_10bit_gfx = object->state.m_expanded_10bit_gfx.get();
1291 
1292 	int16_t clipminX = CLIPMINX_FULL;
1293 	int16_t clipmaxX = CLIPMAXX_FULL;
1294 	int16_t clipminY = CLIPMINY_FULL;
1295 	int16_t clipmaxY = CLIPMAXY_FULL;
1296 
1297 
1298 	/************* object->spriteblit[1] *************/
1299 
1300 	// 000u0ccc  - c = colour? u = 0/1
1301 	uint32_t blit1_unused = object->spriteblit[1] & 0xfffef800;
1302 	uint32_t b1mode = (object->spriteblit[1] & 0x00010000)>>16;
1303 	uint32_t b1colorNumber = (object->spriteblit[1] & 0x000007ff);    // Probably more bits
1304 
1305 	if (blit1_unused!=0) printf("blit1 unknown bits set %08x\n", object->spriteblit[1]);
1306 
1307 
1308 	if (b1mode)
1309 	{
1310 	//  b1colorNumber = object->state.machine().rand()&0xfff;
1311 	}
1312 
1313 	/************* object->spriteblit[3] *************/
1314 
1315 	// seems to be more complex than just transparency
1316 	uint32_t blit2_unused = object->spriteblit[2]&0xff80f800;
1317 	uint32_t b2altpenmask = (object->spriteblit[2] & 0x007f0000)>>16;
1318 	uint32_t b2colorNumber = (object->spriteblit[2] & 0x000007ff);
1319 
1320 	if (b2colorNumber != b1colorNumber)
1321 	{
1322 	//  b1colorNumber = machine().rand()&0xfff;
1323 	}
1324 
1325 //  if(b1colorNumber > 0x60 || b2colorNumber)
1326 //      printf("%08x %08x\n",b1colorNumber,b2colorNumber);
1327 
1328 
1329 	if (blit2_unused!=0) printf("blit1 unknown bits set %08x\n", object->spriteblit[2]);
1330 	if (b1mode)
1331 	{
1332 		if (b2altpenmask != 0x7f) printf("b1mode 1, b2altpenmask!=0x7f\n");
1333 	}
1334 	else
1335 	{
1336 		// 0x01/0x02 trips in rare cases (start of one of the attract levels) maybe this is some kind of alpha instead?
1337 		if ((b2altpenmask != 0x00) && (b2altpenmask != 0x01) && (b2altpenmask != 0x02)) printf("b1mode 0, b2altpenmask!=0x00,0x01 or 0x02 (is %02x)\n", b2altpenmask);
1338 	}
1339 		// 00??0uuu
1340 		// ?? seems to be 00 or 7f, set depending on b1mode
1341 		// uuu, at least 11 bits used, maybe 12 usually the same as blit1_unused? leftover?
1342 
1343 
1344 
1345 	/************* object->spriteblit[4] *************/
1346 
1347 	uint32_t blit4_unused = object->spriteblit[4] & 0xf8fefeee;
1348 	uint16_t blit4blendlevel = (object->spriteblit[4] & 0x07000000)>>24;
1349 	uint16_t blit4blendlevelinv = blit4blendlevel^0x7;
1350 	blit4blendlevel+=1; // make our maths easier later (not sure about accuracy)
1351 	//object->zpri = 7-blit4;
1352 	// unknown bits in blit word 4 -  00000010 - australia (and various other times)
1353 
1354 	uint32_t blit_flipx = object->spriteblit[4] & 0x00000001;
1355 	uint32_t blit_flipy = (object->spriteblit[4] & 0x00000100)>>8;
1356 	uint32_t blit_rotate = (object->spriteblit[4] & 0x00010000)>>16;
1357 	//uint32_t b4_unk = object->spriteblit[4] & 0x00000010;
1358 
1359 	if (blit4_unused) printf("unknown bits in blit word %d -  %08x\n", 4, blit4_unused);
1360 
1361 	// ---- -111 ---- ---r ---- ---y ---z ---x
1362 	// 1 = used bits? (unknown purpose.. might be object colour mode)
1363 	// x = x-flip
1364 	// y = y-flip
1365 	// r = rotate 90 degrees
1366 	// z = ??? set very occasionally, often at the start of stages, might relate to the clipping done at the same time?
1367 
1368 	// this might affect blending logic / amount when 0x8000 palette bit is set, and maybe even z-behavior
1369 	// 7 = road, player bike etc.? possibly a 'do not blend' (solid) flag of sorts because the road has 0x8000 palette bit set...
1370 	// 6 = smoke frome player bike, waves on west indies, waterfalls on niagra, occasional bits of road?
1371 	// 5 = clouds
1372 	// 4 = shadows and some HUD elements, occassional bit of road, some firework effects, all bg elements in the coolriders of coolriders (including reaper)
1373 	// 3 = front coloured jets
1374 	// 2 = middle coloured jets
1375 	// 1 = last few coloured trails from the jets at the start, occassional bit of road
1376 	// 0 = some HUD elements, title screen, tunnels? road during coolriders of.. (this doesn't have 0x8000 set)
1377 
1378 
1379 	// note the road always has 0x8000 bit set in the palette.  I *think* this is because they do a gradual blend of some kind between the road types
1380 	//  see the number of transitional road bits which have various values above set
1381 
1382 	if (blit4blendlevel==object->state.m_debug_randompal)
1383 	{
1384 		b1colorNumber = object->state.machine().rand()&0xfff;
1385 	}
1386 
1387 
1388 	/************* object->spriteblit[6] *************/
1389 
1390 	uint16_t vCellCount = (object->spriteblit[6] & 0x03ff0000) >> 16;
1391 	uint16_t hCellCount = (object->spriteblit[6] & 0x000003ff);
1392 
1393 	/************* object->spriteblit[7] *************/
1394 
1395 	uint16_t vOrigin = (object->spriteblit[7] & 0x00030000) >> 16;
1396 	uint16_t hOrigin = (object->spriteblit[7] & 0x00000003);
1397 	uint16_t OriginUnused = (object->spriteblit[7] & 0xfffcfffc);
1398 
1399 	if (blit5_unused) printf("unknown bits in blit word %d -  %08x\n", 7, OriginUnused);
1400 
1401 	//printf("%04x %04x\n", vOrigin, hOrigin);
1402 
1403 	/************* object->spriteblit[8] *************/
1404 
1405 	uint16_t vZoom = (object->spriteblit[8] & 0xffff0000) >> 16;
1406 	uint16_t hZoom = (object->spriteblit[8] & 0x0000ffff);
1407 
1408 	// if we have no vertical zoom value there's no point in going any further
1409 	// because there are no known vertical indirect modes
1410 	if (!vZoom)
1411 		return nullptr;
1412 
1413 	/************* object->spriteblit[9] *************/
1414 
1415 	int vPosition = (object->spriteblit[9] & 0xffff0000) >> 16;
1416 	int hPositionx = (object->spriteblit[9] & 0x0000ffff);
1417 
1418 	if (hPositionx & 0x8000) hPositionx -= 0x10000;
1419 	if (vPosition & 0x8000) vPosition -= 0x10000;
1420 
1421 	/************* object->spriteblit[10] *************/
1422 
1423 	// pointer to per-line zoom and scroll data for sprites
1424 	//uint32_t blit10 = 0; // we've cached the data here already
1425 
1426 	/************* object->spriteblit[11] *************/
1427 
1428 	//uint32_t textlookup = 0; // we've cached the data here already
1429 
1430 	/*
1431 	    sample data from attract mode 'filmstrip'
1432 
1433 	    you can see it's screen regions at least, gets enabled in certain game situations too
1434 	    interestingly there is a bit to determine the screen number this applies to, even if that should already be implied from m_blitterMode
1435 
1436 	    screen 1 clipping(?)
1437 
1438 	    unknown sprite list type 1 - 00000001 003f00f0 027801f7 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1439 	    unknown sprite list type 1 - 00000001 003f00f0 03e001f7 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1440 	    unknown sprite list type 1 - 00000001 003f00f0 000700e3 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1441 	    unknown sprite list type 1 - 00000001 003f00f0 010c01f7 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1442 
1443 	    unknown sprite list type 1 - 00000001 003f00f0 027401f7 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1444 	    unknown sprite list type 1 - 00000001 003f00f0 03dc01f7 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1445 	    unknown sprite list type 1 - 00000001 003f00f0 000700df 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1446 	    unknown sprite list type 1 - 00000001 003f00f0 010801f7 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1447 
1448 	    unknown sprite list type 1 - 00000001 003f00f0 027001f7 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1449 	    unknown sprite list type 1 - 00000001 003f00f0 03d801f7 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1450 	    unknown sprite list type 1 - 00000001 003f00f0 000700db 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1451 	    unknown sprite list type 1 - 00000001 003f00f0 010401f7 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1452 
1453 	    unknown sprite list type 1 - 00000001 003f00f0 019c01f7 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1454 	    unknown sprite list type 1 - 00000001 003f00f0 030401f7 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1455 	    unknown sprite list type 1 - 00000001 003f00f0 00070007 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1456 	    unknown sprite list type 1 - 00000001 003f00f0 0030016f 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1457 
1458 	    screen 2 clipping
1459 
1460 	    unknown sprite list type 1 - 00000001 003f00f0 039803f7 00000207 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1461 	    unknown sprite list type 1 - 00000001 003f00f0 050003f7 00000207 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1462 	    unknown sprite list type 1 - 00000001 003f00f0 02070203 00000207 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1463 	    unknown sprite list type 1 - 00000001 003f00f0 022c036b 00000207 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1464 
1465 	    unknown sprite list type 1 - 00000001 003f00f0 039403f7 00000207 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1466 	    unknown sprite list type 1 - 00000001 003f00f0 04fc03f7 00000207 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1467 	    unknown sprite list type 1 - 00000001 003f00f0 020701ff 00000207 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1468 	    unknown sprite list type 1 - 00000001 003f00f0 02280367 00000207 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1469 
1470 	    unknown sprite list type 1 - 00000001 003f00f0 039003f7 00000207 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1471 	    unknown sprite list type 1 - 00000001 003f00f0 04f803f7 00000207 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1472 	    unknown sprite list type 1 - 00000001 003f00f0 020701fb 00000207 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1473 	    unknown sprite list type 1 - 00000001 003f00f0 02240363 00000207 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1474 
1475 	  NOTE, we only copy across [1] [2] and [3]   as [0] [1] and [2]
1476 	    the 3rd dword seems to be some kind of offset, it's 0x207 on the 2nd screen, and the actual x-clip rects are also higher on that screen?
1477 
1478 	    note this is practically the same format as the sysh1_fb_data_w commands..
1479 
1480 
1481 
1482 	    between stages (screen 1)
1483 	    unknown sprite list type 1 - 00000001 000000a4 000701f7 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1484 	    unknown sprite list type 1 - 00000001 0000017f 000701f7 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1485 	    unknown sprite list type 1 - 00000001 000000a4 000701f7 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1486 	    unknown sprite list type 1 - 00000001 0000017f 000701f7 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1487 	    unknown sprite list type 1 - 00000001 000000a3 000701f7 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1488 	    unknown sprite list type 1 - 00000001 0000017f 000701f7 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1489 	    unknown sprite list type 1 - 00000001 000000a4 000701f7 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1490 	    unknown sprite list type 1 - 00000001 0000017f 000701f7 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1491 	    unknown sprite list type 1 - 00000001 000000a4 000701f7 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1492 	    unknown sprite list type 1 - 00000001 0000017f 000701f7 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1493 	    unknown sprite list type 1 - 00000001 000000a5 000701f7 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1494 	    unknown sprite list type 1 - 00000001 0000017f 000701f7 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1495 	    unknown sprite list type 1 - 00000001 000000a6 000701f7 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1496 	    unknown sprite list type 1 - 00000001 0000017f 000701f7 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1497 	    unknown sprite list type 1 - 00000001 000000a8 000701f7 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1498 	    unknown sprite list type 1 - 00000001 0000017f 000701f7 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1499 	    unknown sprite list type 1 - 00000001 000000a9 000701f7 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1500 	    unknown sprite list type 1 - 00000001 0000017f 000701f7 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1501 	    unknown sprite list type 1 - 00000001 000000ab 000701f7 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1502 	    unknown sprite list type 1 - 00000001 0000017f 000701f7 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1503 	    unknown sprite list type 1 - 00000001 000000ac 000701f7 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1504 	    unknown sprite list type 1 - 00000001 0000017f 000701f7 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1505 	    unknown sprite list type 1 - 00000001 000000ae 000701f7 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1506 	    unknown sprite list type 1 - 00000001 0000017f 000701f7 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1507 	    unknown sprite list type 1 - 00000001 000000af 000701f7 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1508 	    unknown sprite list type 1 - 00000001 0000017f 000701f7 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1509 	    unknown sprite list type 1 - 00000001 000000b1 000701f7 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1510 	    unknown sprite list type 1 - 00000001 0000017f 000701f7 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1511 	    unknown sprite list type 1 - 00000001 000000b2 000701f7 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1512 	    unknown sprite list type 1 - 00000001 0000017f 000701f7 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1513 	    unknown sprite list type 1 - 00000001 000000b3 000701f7 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1514 	    unknown sprite list type 1 - 00000001 0000017f 000701f7 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1515 	    unknown sprite list type 1 - 00000001 000000b5 000701f7 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1516 	    unknown sprite list type 1 - 00000001 0000017f 000701f7 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1517 	    unknown sprite list type 1 - 00000001 000000b6 000701f7 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1518 	    unknown sprite list type 1 - 00000001 0000017f 000701f7 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1519 	    unknown sprite list type 1 - 00000001 000000b8 000701f7 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1520 	    unknown sprite list type 1 - 00000001 0000017f 000701f7 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1521 	    unknown sprite list type 1 - 00000001 000000b9 000701f7 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1522 	    unknown sprite list type 1 - 00000001 0000017f 000701f7 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1523 	    unknown sprite list type 1 - 00000001 000000ba 000701f7 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1524 	    unknown sprite list type 1 - 00000001 0000017f 000701f7 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1525 	    unknown sprite list type 1 - 00000001 000000bc 000701f7 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1526 	    unknown sprite list type 1 - 00000001 0000017f 000701f7 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1527 	    unknown sprite list type 1 - 00000001 000000bd 000701f7 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1528 	    unknown sprite list type 1 - 00000001 0000017f 000701f7 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1529 	    unknown sprite list type 1 - 00000001 000000be 000701f7 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1530 	    unknown sprite list type 1 - 00000001 0000017f 000701f7 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1531 	    unknown sprite list type 1 - 00000001 000000c0 000701f7 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1532 	    unknown sprite list type 1 - 00000001 0000017f 000701f7 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1533 	    unknown sprite list type 1 - 00000001 000000c1 000701f7 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1534 	    unknown sprite list type 1 - 00000001 0000017f 000701f7 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1535 	    unknown sprite list type 1 - 00000001 000000c2 000701f7 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1536 	    unknown sprite list type 1 - 00000001 0000017f 000701f7 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1537 	    unknown sprite list type 1 - 00000001 000000c4 000701f7 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1538 	    unknown sprite list type 1 - 00000001 0000017f 000701f7 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1539 	    unknown sprite list type 1 - 00000001 000000c5 000701f7 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1540 	    unknown sprite list type 1 - 00000001 0000017f 000701f7 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1541 	    unknown sprite list type 1 - 00000001 000000c6 000701f7 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1542 	    unknown sprite list type 1 - 00000001 0000017f 000701f7 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1543 	    unknown sprite list type 1 - 00000001 000000c8 000701f7 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1544 	    unknown sprite list type 1 - 00000001 0000017f 000701f7 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1545 	    unknown sprite list type 1 - 00000001 000000c9 000701f7 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1546 	    unknown sprite list type 1 - 00000001 0000017f 000701f7 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1547 	    unknown sprite list type 1 - 00000001 000000cb 000701f7 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1548 	    unknown sprite list type 1 - 00000001 0000017f 000701f7 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1549 	    unknown sprite list type 1 - 00000001 000000cc 000701f7 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1550 	    unknown sprite list type 1 - 00000001 0000017f 000701f7 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1551 	    unknown sprite list type 1 - 00000001 000000ce 000701f7 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1552 	    unknown sprite list type 1 - 00000001 0000017f 000701f7 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1553 	    unknown sprite list type 1 - 00000001 000000cf 000701f7 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1554 	    unknown sprite list type 1 - 00000001 0000017f 000701f7 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1555 	    unknown sprite list type 1 - 00000001 000000d1 000701f7 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1556 	    unknown sprite list type 1 - 00000001 0000017f 000701f7 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1557 	    unknown sprite list type 1 - 00000001 000000d1 000701f7 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1558 	    unknown sprite list type 1 - 00000001 0000017f 000701f7 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1559 	    unknown sprite list type 1 - 00000001 000000d2 000701f7 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1560 	    unknown sprite list type 1 - 00000001 0000017f 000701f7 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1561 	    unknown sprite list type 1 - 00000001 000000d3 000701f7 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1562 	    unknown sprite list type 1 - 00000001 0000017f 000701f7 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1563 	    unknown sprite list type 1 - 00000001 000000d4 000701f7 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1564 	    unknown sprite list type 1 - 00000001 0000017f 000701f7 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1565 	    unknown sprite list type 1 - 00000001 000000d4 000701f7 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1566 	    unknown sprite list type 1 - 00000001 0000017f 000701f7 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1567 	    unknown sprite list type 1 - 00000001 000000d5 000701f7 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1568 	    unknown sprite list type 1 - 00000001 0000017f 000701f7 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1569 	    unknown sprite list type 1 - 00000001 000000d5 000701f7 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1570 	    unknown sprite list type 1 - 00000001 0000017f 000701f7 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1571 	    unknown sprite list type 1 - 00000001 000000d6 000701f7 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1572 	    unknown sprite list type 1 - 00000001 0000017f 000701f7 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1573 	    unknown sprite list type 1 - 00000001 000000d7 000701f7 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1574 	    unknown sprite list type 1 - 00000001 0000017f 000701f7 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1575 	    unknown sprite list type 1 - 00000001 000000d7 000701f7 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1576 	    unknown sprite list type 1 - 00000001 0000017f 000701f7 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1577 	    unknown sprite list type 1 - 00000001 000000d8 000701f7 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1578 	    unknown sprite list type 1 - 00000001 0000017f 000701f7 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1579 	    unknown sprite list type 1 - 00000001 000000d9 000701f7 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1580 	    unknown sprite list type 1 - 00000001 0000017f 000701f7 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1581 	    unknown sprite list type 1 - 00000001 000000d9 000701f7 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1582 	    unknown sprite list type 1 - 00000001 0000017f 000701f7 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1583 	    unknown sprite list type 1 - 00000001 000000db 000701f7 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1584 	    unknown sprite list type 1 - 00000001 0000017f 000701f7 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1585 	    unknown sprite list type 1 - 00000001 000000db 000701f7 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1586 	    unknown sprite list type 1 - 00000001 0000017f 000701f7 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1587 	    unknown sprite list type 1 - 00000001 000000dc 000701f7 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1588 	    unknown sprite list type 1 - 00000001 0000017f 000701f7 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1589 	    unknown sprite list type 1 - 00000001 000000dd 000701f7 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1590 	    unknown sprite list type 1 - 00000001 0000017f 000701f7 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1591 	    unknown sprite list type 1 - 00000001 000000dd 000701f7 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1592 	    unknown sprite list type 1 - 00000001 0000017f 000701f7 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1593 	    unknown sprite list type 1 - 00000001 000000de 000701f7 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1594 	    unknown sprite list type 1 - 00000001 0000017f 000701f7 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1595 	    unknown sprite list type 1 - 00000001 000000e0 000701f7 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1596 	    unknown sprite list type 1 - 00000001 0000017f 000701f7 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1597 	    unknown sprite list type 1 - 00000001 000000e1 000701f7 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1598 	    unknown sprite list type 1 - 00000001 0000017f 000701f7 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1599 	    unknown sprite list type 1 - 00000001 000000e1 000701f7 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1600 	    unknown sprite list type 1 - 00000001 0000017f 000701f7 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1601 	    unknown sprite list type 1 - 00000001 000000e2 000701f7 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1602 	    unknown sprite list type 1 - 00000001 0000017f 000701f7 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1603 	    unknown sprite list type 1 - 00000001 000000e3 000701f7 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1604 	    unknown sprite list type 1 - 00000001 0000017f 000701f7 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1605 	    unknown sprite list type 1 - 00000001 000000e3 000701f7 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1606 	    unknown sprite list type 1 - 00000001 0000017f 000701f7 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1607 	    unknown sprite list type 1 - 00000001 000000e4 000701f7 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1608 	    unknown sprite list type 1 - 00000001 0000017f 000701f7 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1609 	    unknown sprite list type 1 - 00000001 000000e6 000701f7 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1610 	    unknown sprite list type 1 - 00000001 0000017f 000701f7 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1611 	    unknown sprite list type 1 - 00000001 000000e6 000701f7 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1612 	    unknown sprite list type 1 - 00000001 0000017f 000701f7 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1613 	    unknown sprite list type 1 - 00000001 000000e7 000701f7 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1614 	    unknown sprite list type 1 - 00000001 0000017f 000701f7 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1615 	    unknown sprite list type 1 - 00000001 000000e8 000701f7 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1616 	    unknown sprite list type 1 - 00000001 0000017f 000701f7 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1617 	    unknown sprite list type 1 - 00000001 000000ea 000701f7 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1618 	    unknown sprite list type 1 - 00000001 0000017f 000701f7 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1619 	    unknown sprite list type 1 - 00000001 000000eb 000701f7 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1620 	    unknown sprite list type 1 - 00000001 0000017f 000701f7 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1621 	    unknown sprite list type 1 - 00000001 000000ed 000701f7 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1622 	    unknown sprite list type 1 - 00000001 0000017f 000701f7 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1623 	    unknown sprite list type 1 - 00000001 000000ee 000701f7 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1624 	    unknown sprite list type 1 - 00000001 0000017f 000701f7 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1625 	    unknown sprite list type 1 - 00000001 000000f0 000701f7 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1626 	    unknown sprite list type 1 - 00000001 0000017f 000701f7 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1627 	    unknown sprite list type 1 - 00000001 000000f1 000701f7 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1628 	    unknown sprite list type 1 - 00000001 0000017f 000701f7 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1629 	    unknown sprite list type 1 - 00000001 000000f3 000701f7 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1630 	    unknown sprite list type 1 - 00000001 0000017f 000701f7 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1631 	    unknown sprite list type 1 - 00000001 000000f4 000701f7 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1632 	    unknown sprite list type 1 - 00000001 0000017f 000701f7 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1633 	    unknown sprite list type 1 - 00000001 000000f6 000701f7 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1634 	    unknown sprite list type 1 - 00000001 0000017f 000701f7 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1635 	    unknown sprite list type 1 - 00000001 000000f7 000701f7 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1636 	    unknown sprite list type 1 - 00000001 0000017f 000701f7 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1637 	    unknown sprite list type 1 - 00000001 000000f9 000701f7 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1638 	    unknown sprite list type 1 - 00000001 0000017f 000701f7 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1639 	    unknown sprite list type 1 - 00000001 000000fa 000701f7 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1640 	    unknown sprite list type 1 - 00000001 0000017f 000701f7 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1641 	    unknown sprite list type 1 - 00000001 000000fc 000701f7 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1642 	    unknown sprite list type 1 - 00000001 0000017f 000701f7 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1643 	    unknown sprite list type 1 - 00000001 000000fe 000701f7 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1644 	    unknown sprite list type 1 - 00000001 0000017f 000701f7 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1645 	    unknown sprite list type 1 - 00000001 000000fe 000701f7 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1646 	    unknown sprite list type 1 - 00000001 0000017f 000701f7 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1647 	    unknown sprite list type 1 - 00000001 000000fd 000701f7 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1648 	    unknown sprite list type 1 - 00000001 0000017f 000701f7 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1649 	    unknown sprite list type 1 - 00000001 000000fd 000701f7 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1650 	    unknown sprite list type 1 - 00000001 0000017f 000701f7 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1651 	    unknown sprite list type 1 - 00000001 000000fd 000701f7 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1652 	    unknown sprite list type 1 - 00000001 0000017f 000701f7 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1653 	    unknown sprite list type 1 - 00000001 000000fc 000701f7 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1654 	    unknown sprite list type 1 - 00000001 0000017f 000701f7 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1655 	    unknown sprite list type 1 - 00000001 000000fd 000701f7 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1656 	    unknown sprite list type 1 - 00000001 0000017f 000701f7 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1657 	    unknown sprite list type 1 - 00000001 000000fd 000701f7 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1658 	    unknown sprite list type 1 - 00000001 0000017f 000701f7 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1659 	    unknown sprite list type 1 - 00000001 000000fd 000701f7 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1660 	    unknown sprite list type 1 - 00000001 0000017f 000701f7 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1661 	    unknown sprite list type 1 - 00000001 000000fd 000701f7 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1662 	    unknown sprite list type 1 - 00000001 0000017f 000701f7 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1663 	    unknown sprite list type 1 - 00000001 000000fc 000701f7 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1664 	    unknown sprite list type 1 - 00000001 0000017f 000701f7 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1665 	    unknown sprite list type 1 - 00000001 000000fa 000701f7 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1666 	    unknown sprite list type 1 - 00000001 0000017f 000701f7 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1667 	    unknown sprite list type 1 - 00000001 000000fa 000701f7 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1668 	    unknown sprite list type 1 - 00000001 0000017f 000701f7 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1669 	    unknown sprite list type 1 - 00000001 000000f8 000701f7 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1670 	    unknown sprite list type 1 - 00000001 0000017f 000701f7 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1671 	    unknown sprite list type 1 - 00000001 000000f6 000701f7 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1672 	    unknown sprite list type 1 - 00000001 0000017f 000701f7 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1673 	    unknown sprite list type 1 - 00000001 000000f4 000701f7 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1674 	    unknown sprite list type 1 - 00000001 0000017f 000701f7 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1675 	    unknown sprite list type 1 - 00000001 000000f3 000701f7 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1676 	    unknown sprite list type 1 - 00000001 0000017f 000701f7 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1677 	    unknown sprite list type 1 - 00000001 000000f1 000701f7 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1678 	    unknown sprite list type 1 - 00000001 0000017f 000701f7 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1679 	    unknown sprite list type 1 - 00000001 000000ee 000701f7 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1680 	    unknown sprite list type 1 - 00000001 0000017f 000701f7 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1681 	    unknown sprite list type 1 - 00000001 000000eb 000701f7 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1682 	    unknown sprite list type 1 - 00000001 0000017f 000701f7 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1683 	    unknown sprite list type 1 - 00000001 000000e9 000701f7 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1684 	    unknown sprite list type 1 - 00000001 0000017f 000701f7 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1685 	    unknown sprite list type 1 - 00000001 000000e7 000701f7 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1686 	    unknown sprite list type 1 - 00000001 0000017f 000701f7 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1687 	    unknown sprite list type 1 - 00000001 000000e4 000701f7 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1688 	    unknown sprite list type 1 - 00000001 0000017f 000701f7 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1689 	    unknown sprite list type 1 - 00000001 000000e1 000701f7 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1690 	    unknown sprite list type 1 - 00000001 0000017f 000701f7 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1691 	    unknown sprite list type 1 - 00000001 000000dd 000701f7 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1692 	    unknown sprite list type 1 - 00000001 0000017f 000701f7 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1693 	    unknown sprite list type 1 - 00000001 000000da 000701f7 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1694 	    unknown sprite list type 1 - 00000001 0000017f 000701f7 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1695 	    unknown sprite list type 1 - 00000001 000000d7 000701f7 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1696 	    unknown sprite list type 1 - 00000001 0000017f 000701f7 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1697 	    unknown sprite list type 1 - 00000001 000000d5 000701f7 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1698 	    unknown sprite list type 1 - 00000001 0000017f 000701f7 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1699 
1700 	ending
1701 
1702 	    unknown sprite list type 1 - 00000001 0000017f 000701f7 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1703 	    unknown sprite list type 1 - 00000001 0000017f 000701f7 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1704 	    unknown sprite list type 1 - 00000001 0000017f 000701f7 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1705 	    unknown sprite list type 1 - 00000001 0000017f 000701f7 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1706 	    unknown sprite list type 1 - 00000001 0000017f 000701f7 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1707 	    unknown sprite list type 1 - 00000001 0000017f 000701f7 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1708 	    unknown sprite list type 1 - 00000001 0000017f 000701f7 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1709 
1710 	romania
1711 	    unknown sprite list type 1 - 00000001 00000001 00000001 00000007 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1712 	*/
1713 
1714 	// how does this really work? there's more to it
1715 	// used in film strip attract mode, and between stages
1716 	if (object->clipvals[2] & 0x0000007) // clearly this isn't the enable flag, probably just enabled until next frame / it gets disabled
1717 	{
1718 		// these go negative when things scroll off the left in attract mode
1719 		int16_t minx = ((object->clipvals[1]&0xffff0000)>>16) - (((object->clipvals[2]&0x0000ffff)>>0));
1720 		int16_t maxx = ((object->clipvals[1]&0x0000ffff)>>0)  - (((object->clipvals[2]&0x0000ffff)>>0));
1721 		int16_t miny = ((object->clipvals[0]&0xffff0000)>>16); // maybe subtract the top 16 bits of clipvals[2], but not used?
1722 		int16_t maxy = ((object->clipvals[0]&0x0000ffff)>>0);
1723 
1724 
1725 		clipminX = minx -1;
1726 		if (clipminX<CLIPMINX_FULL) clipminX = CLIPMINX_FULL;
1727 		if (clipminX>CLIPMAXX_FULL) clipminX = CLIPMAXX_FULL;
1728 		clipmaxX = maxx;
1729 		if (clipmaxX<CLIPMINX_FULL) clipmaxX = CLIPMINX_FULL;
1730 		if (clipmaxX>CLIPMAXX_FULL) clipmaxX = CLIPMAXX_FULL;
1731 		if (clipminX>clipmaxX) clipminX = clipmaxX;
1732 
1733 		clipminY = miny -1;
1734 		if (clipminY<CLIPMINY_FULL) clipminY = CLIPMINY_FULL;
1735 		if (clipminY>CLIPMAXY_FULL) clipminY = CLIPMAXY_FULL;
1736 		clipmaxY = maxy;
1737 		if (clipmaxY<CLIPMINY_FULL) clipmaxY = CLIPMINY_FULL;
1738 		if (clipmaxY>CLIPMAXY_FULL) clipmaxY = CLIPMAXY_FULL;
1739 		if (clipminY>clipmaxY) clipminY = clipmaxY;
1740 
1741 
1742 		//b1colorNumber = object->state.machine().rand()&0xfff;
1743 	}
1744 
1745 	/* DRAW */
1746 	uint16_t used_hCellCount = hCellCount;
1747 	uint16_t used_vCellCount = vCellCount;
1748 	uint16_t used_flipx = blit_flipx;
1749 	uint16_t used_flipy = blit_flipy;
1750 
1751 	if (blit_rotate)
1752 	{
1753 		used_hCellCount = vCellCount;
1754 		used_vCellCount = hCellCount;
1755 		used_flipx = blit_flipy;
1756 		used_flipy = blit_flipx;
1757 		// do the zoom params rotate?
1758 	}
1759 
1760 	// SPRITES / BLITS
1761 
1762 	// for text objects this is an address containing the 8-bit tile numbers to use for ASCII text
1763 	// I guess the tiles are decoded by a DMA operation earlier, from the compressed ROM?
1764 
1765 	// we also use this to trigger the actual draw operation
1766 
1767 
1768 
1769 	int size = used_hCellCount * used_vCellCount;
1770 
1771 	uint16_t* tempshape;
1772 	int screen = object->screen;
1773 	int use_object = 0;
1774 
1775 	if (!indirect_tile_enable && size < DECODECACHE_NUMSPRITETILES)
1776 	{
1777 		int found = -1;
1778 
1779 		for (int k=0;k<DECODECACHE_NUMOBJECTCACHES;k++)
1780 		{
1781 			if(((object->state.m_decode[screen].objcache[k].lastromoffset == b3romoffset)) &&
1782 				((object->state.m_decode[screen].objcache[k].lastused_flipx == used_flipx)) &&
1783 				((object->state.m_decode[screen].objcache[k].lastused_flipy == used_flipy)) &&
1784 				((object->state.m_decode[screen].objcache[k].lastblit_rotate == blit_rotate)) &&
1785 				((object->state.m_decode[screen].objcache[k].lastb1mode == b1mode)) &&
1786 				((object->state.m_decode[screen].objcache[k].lastb1colorNumber == b1colorNumber)) &&
1787 				((object->state.m_decode[screen].objcache[k].lastb2colorNumber == b2colorNumber)) &&
1788 				((object->state.m_decode[screen].objcache[k].lastused_hCellCount == used_hCellCount)) &&
1789 				((object->state.m_decode[screen].objcache[k].lastused_vCellCount == used_vCellCount)) &&
1790 				((object->state.m_decode[screen].objcache[k].lastb2altpenmask == b2altpenmask)))
1791 			{
1792 				found = k;
1793 				break;
1794 			}
1795 		}
1796 
1797 		if (found != -1)
1798 		{
1799 			object->state.m_decode[screen].objcache[found].repeatcount++;
1800 			use_object = found;
1801 		}
1802 		else
1803 		{
1804 			use_object = object->state.m_decode[screen].current_object;
1805 
1806 			// dirty the cache
1807 			for (int i=0;i<DECODECACHE_NUMSPRITETILES;i++)
1808 				object->state.m_decode[screen].objcache[use_object].tiles[i].tempshape_multi_decoded = false;
1809 
1810 			object->state.m_decode[screen].objcache[use_object].lastromoffset = b3romoffset;
1811 			object->state.m_decode[screen].objcache[use_object].lastused_flipx = used_flipx;
1812 			object->state.m_decode[screen].objcache[use_object].lastused_flipy = used_flipy;
1813 			object->state.m_decode[screen].objcache[use_object].lastblit_rotate = blit_rotate;
1814 			object->state.m_decode[screen].objcache[use_object].lastb1mode = b1mode;
1815 			object->state.m_decode[screen].objcache[use_object].lastb1colorNumber = b1colorNumber;
1816 			object->state.m_decode[screen].objcache[use_object].lastb2colorNumber = b2colorNumber;
1817 			object->state.m_decode[screen].objcache[use_object].lastused_hCellCount = used_hCellCount;
1818 			object->state.m_decode[screen].objcache[use_object].lastused_vCellCount = used_vCellCount;
1819 			object->state.m_decode[screen].objcache[use_object].lastb2altpenmask = b2altpenmask;
1820 			object->state.m_decode[screen].objcache[use_object].repeatcount = 0;
1821 
1822 			object->state.m_decode[screen].current_object++;
1823 			if (object->state.m_decode[screen].current_object >= DECODECACHE_NUMOBJECTCACHES)
1824 				object->state.m_decode[screen].current_object = 0;
1825 		}
1826 	}
1827 
1828 
1829 
1830 
1831 	int sizey = used_vCellCount * 16 * vZoom;
1832 
1833 	vPosition *= 0x40;
1834 
1835 	switch (vOrigin & 3)
1836 	{
1837 	case 0:
1838 		// top
1839 		break;
1840 	case 1:
1841 		vPosition -= sizey / 2 ;
1842 		// middle?
1843 		break;
1844 	case 2:
1845 		vPosition -= sizey;
1846 		// bottom?
1847 		break;
1848 	case 3:
1849 		// invalid?
1850 		break;
1851 	}
1852 
1853 
1854 
1855 	// Splat some sprites
1856 	for (int v = 0; v < used_vCellCount; v++)
1857 	{
1858 		const int pixelOffsetY = ((vPosition) + (v* 16 * vZoom)) / 0x40;
1859 		const int pixelOffsetnextY = ((vPosition) + ((v+1)* 16 * vZoom)) / 0x40;
1860 
1861 		int blockhigh = pixelOffsetnextY - pixelOffsetY;
1862 
1863 		if (pixelOffsetY+blockhigh<0)
1864 			continue;
1865 
1866 
1867 
1868 		if (pixelOffsetY>clipmaxY)
1869 		{
1870 			v = used_vCellCount;
1871 			continue;
1872 		}
1873 
1874 		// I don't know, the Rainbow is a non-zoomed sprite and won't link unless you move one half
1875 		//  (fixed in the hOrigin handling instead)
1876 		//if (used_flipx)
1877 		//  hPositionx -= 1;
1878 
1879 		int hPosition = 0;
1880 
1881 
1882 
1883 		if (!indirect_zoom_enable)
1884 		{
1885 			int sizex = used_hCellCount * 16 * hZoom;
1886 
1887 			hPosition = hPositionx * 0x40;
1888 
1889 			switch (hOrigin & 3)
1890 			{
1891 			case 0:
1892 				// left
1893 				break;
1894 			case 1:
1895 				hPosition -= sizex / 2;
1896 				// middle?
1897 				break;
1898 			case 2:
1899 				hPosition -= sizex-1;
1900 				// right?
1901 				break;
1902 			case 3:
1903 				// invalid?
1904 				break;
1905 			}
1906 		}
1907 
1908 		uint32_t lastSpriteNumber = 0xffffffff;
1909 		uint16_t blankcount = 0;
1910 		int color_offs = (object->colbase + (b1colorNumber & 0x7ff))*0x40 * 5; /* yes, * 5 */ \
1911 		int color_offs2 = (object->colbase + (b2colorNumber & 0x7ff))*0x40 * 5;
1912 		for (int h = 0; h < used_hCellCount; h++)
1913 		{
1914 			int current_decoded = false;
1915 
1916 			if (!indirect_tile_enable && size < DECODECACHE_NUMSPRITETILES)
1917 			{
1918 				tempshape = object->state.m_decode[screen].objcache[use_object].tiles[v*used_hCellCount + h].tempshape_multi;
1919 				current_decoded = object->state.m_decode[screen].objcache[use_object].tiles[v*used_hCellCount + h].tempshape_multi_decoded;
1920 				/*
1921 				if (object->screen==0)
1922 				{
1923 				    if (current_decoded) printf("setting temp shape to %04x tile is marked as decoded %08x \n", v*used_hCellCount + h, ((uint64_t)(void*)tempshape)&0xffffffff);
1924 				    else printf("setting temp shape to %04x tile is marked as NOT decoded %08x \n", v*used_hCellCount + h, ((uint64_t)(void*)tempshape)&0xffffffff);
1925 				}
1926 				*/
1927 			}
1928 			else
1929 			{
1930 				//if (object->screen==0) printf("using base tempshape\n");
1931 				tempshape = object->state.m_decode[screen].tempshape;
1932 			}
1933 
1934 
1935 
1936 
1937 			uint32_t incy = 0x8000000 / vZoom;
1938 
1939 			// DEBUG: Draw 16x16 block
1940 
1941 			if (indirect_zoom_enable)
1942 			{
1943 				GET_SPRITE_NUMBER
1944 				CHECK_DECODE
1945 
1946 
1947 				if (blit_rotate)
1948 				{
1949 					#define GET_PIX GET_PIX_ROTATED
1950 					YXLOOP
1951 					#undef GET_PIX
1952 				}
1953 				else // no rotate
1954 				{
1955 					#define GET_PIX GET_PIX_NORMAL
1956 					YXLOOP
1957 					#undef GET_PIX
1958 
1959 				}
1960 			}
1961 			else  // no indirect zoom
1962 			{
1963 				if (!hZoom)
1964 				{
1965 					// abort, but make sure we clean up
1966 					goto end;
1967 				}
1968 
1969 				if ((hZoom==0x40) && (vZoom==0x40)) // non-zoomed
1970 				{
1971 					const int pixelOffsetX = ((hPosition/0x40) + (h* 16));
1972 
1973 					if (pixelOffsetX+16 < clipminX)
1974 						continue;
1975 
1976 					if (pixelOffsetX>clipmaxX)
1977 						continue;
1978 
1979 					GET_SPRITE_NUMBER
1980 					CHECK_DECODE
1981 
1982 					if (pixelOffsetX>=clipminX && pixelOffsetX+16<clipmaxX)
1983 					{
1984 						if (blit_rotate)
1985 						{
1986 							#define DO_XCLIP DO_XCLIP_NONE
1987 							#define GET_PIX GET_PIX_ROTATED
1988 							YXLOOP_NO_ZOOM
1989 							#undef GET_PIX
1990 							#undef DO_XCLIP
1991 						}
1992 						else // no rotate
1993 						{
1994 							#define DO_XCLIP DO_XCLIP_NONE
1995 							#define GET_PIX GET_PIX_NORMAL
1996 							YXLOOP_NO_ZOOM
1997 							#undef GET_PIX
1998 							#undef DO_XCLIP
1999 						}
2000 					}
2001 					else
2002 					{
2003 						if (blit_rotate)
2004 						{
2005 							#define DO_XCLIP DO_XCLIP_REAL
2006 							#define GET_PIX GET_PIX_ROTATED
2007 							YXLOOP_NO_ZOOM
2008 							#undef GET_PIX
2009 							#undef DO_XCLIP
2010 						}
2011 						else // no rotate
2012 						{
2013 							#define DO_XCLIP DO_XCLIP_REAL
2014 							#define GET_PIX GET_PIX_NORMAL
2015 							YXLOOP_NO_ZOOM
2016 							#undef GET_PIX
2017 							#undef DO_XCLIP
2018 						}
2019 					}
2020 				}
2021 				else // zoomed
2022 				{
2023 					const int pixelOffsetX = ((hPosition) + (h* 16 * hZoom)) / 0x40;
2024 					const int pixelOffsetnextX = ((hPosition) + ((h+1)* 16 * hZoom)) / 0x40;
2025 
2026 					int blockwide = pixelOffsetnextX-pixelOffsetX;
2027 					uint32_t incx = 0x8000000 / (object->spriteblit[8] & 0x0000ffff);
2028 
2029 					if (pixelOffsetX+blockwide < clipminX)
2030 						continue;
2031 
2032 					if (pixelOffsetX>clipmaxX)
2033 						continue;
2034 
2035 					GET_SPRITE_NUMBER
2036 					CHECK_DECODE
2037 
2038 					if (pixelOffsetX>=clipminX && pixelOffsetX+blockwide<clipmaxX)
2039 					{
2040 						if (blit_rotate)
2041 						{
2042 							#define DO_XCLIP DO_XCLIP_NONE
2043 							#define GET_PIX GET_PIX_ROTATED
2044 							YXLOOP_NO_LINEZOOM
2045 							#undef GET_PIX
2046 							#undef DO_XCLIP
2047 						}
2048 						else // no rotate
2049 						{
2050 							#define DO_XCLIP DO_XCLIP_NONE
2051 							#define GET_PIX GET_PIX_NORMAL
2052 							YXLOOP_NO_LINEZOOM
2053 							#undef GET_PIX
2054 							#undef DO_XCLIP
2055 						}
2056 					}
2057 					else
2058 					{
2059 						if (blit_rotate)
2060 						{
2061 							#define DO_XCLIP DO_XCLIP_REAL
2062 							#define GET_PIX GET_PIX_ROTATED
2063 							YXLOOP_NO_LINEZOOM
2064 							#undef GET_PIX
2065 							#undef DO_XCLIP
2066 						}
2067 						else // no rotate
2068 						{
2069 							#define DO_XCLIP DO_XCLIP_REAL
2070 							#define GET_PIX GET_PIX_NORMAL
2071 							YXLOOP_NO_LINEZOOM
2072 							#undef GET_PIX
2073 							#undef DO_XCLIP
2074 						}
2075 					}
2076 				} // end zoomed
2077 			} // end no indirect zoom
2078 		}
2079 	}
2080 
2081 
2082 
2083 	end:
2084 
2085 	return nullptr;
2086 
2087 }
2088 
2089 
2090 
2091 /* This is a RLE-based sprite blitter (US Patent #6,141,122), very unusual from Sega... */
blit_current_sprite(address_space & space)2092 void coolridr_state::blit_current_sprite(address_space &space)
2093 {
2094 //  const pen_t *clut = &m_palette->pen(0);
2095 
2096 	// Serialized 32-bit words in order of appearance:
2097 	//  0: 00000000 - unknown, 0x00000000 or 0x00000001, 0 seems to be regular sprite, 1 seems to change meaning of below, possible clip area?
2098 	//  1: 00010000 - unknown, color mode? (7bpp select?) set on player bike object
2099 	//  1: 00000xxx - "Color Number" (all bits or just lower 16/8?)
2100 	//  2: 007f0000 - unknown, transpen? set to 0x7f whenever the 'color mode' bit in (1) is set, otherwise 0
2101 	//  2: 00000xxx - unknown, usually a copy of color number, leftover?
2102 	//  3: 001fffff - offset to compressed data? (it's 0 on text objects tho, but maybe the ascii tiles are a special decode to go with the indirect mode)
2103 	//  4: 07000000 - unknown (draw mode?)
2104 	//  4: 00010000 - unknown (set on a few object)
2105 	//  4: 00000100 - y-flip?
2106 	//  4: 00000001 - x-flip?
2107 	//  5: 00010000 - enable indirect text tile lookup
2108 	//  5: 00000001 - enable line-zoom(?) lookup (road)
2109 	//  6: vvvv---- - "Vertical Cell Count"
2110 	//  6: ----hhhh - "Horizontal Cell Count"
2111 	//  7: 00030003 - "Vertical|Horizontal Origin point"
2112 	//  8: 00ff00ff - "Vertical|Horizontal Zoom Ratios"
2113 	//  9: xxxx---- - "Display Vertical Position"
2114 	//  9: ----yyyy - "Display Horizontal Position"
2115 	// 10: 00000000 - unknown : always seems to be zero - NO, for some things (not text) it's also a reference to 3f40000 region like #11
2116 	// 11: ........ - indirect tile mode ram address (used for text)
2117 
2118 
2119 	// first parse the bits
2120 
2121 	/************* m_spriteblit[0] *************/
2122 
2123 	// set to 0x00000001 on some objects during the 'film strip' part of attract, otherwise 0
2124 	// those objects don't seem visible anyway so might have some special meaning
2125 	// this is also set at times during the game
2126 	//
2127 	// the sprites with 1 set appear to have 0x00000000 in everything after the 4th write (blit4 and above)
2128 	// so likely have some other meaning and are NOT regular sprite data
2129 	uint32_t blit0 = m_spriteblit[0];
2130 
2131 	if (blit0==0)
2132 	{
2133 		// normal
2134 	}
2135 	else if (blit0==1)
2136 	{
2137 		if (m_blitterMode&0x80)
2138 		{
2139 			// HACK...
2140 			// the end sequences do this.. 4f / af cliprects
2141 			//(mode 4f) unknown sprite list type 1 - 0054 0105 0059 0198 (00540105 0060019f 00000007)
2142 			//(mode 50) unknown sprite list type 1 - 0000 017f 0000 01f0 (0000017f 000701f7 00000007)
2143 			// THEN writes the sprite that needs to be clipped(!)
2144 			// this ends up disabling the cliprect before the sprite that actually needs it
2145 			//
2146 			// all other cliprect blits seem to be written after mode 50, so this hack just prevents
2147 			// writes with a higher value than the last one from taking effect, fixing the ending...
2148 			// especially noticeable with 'LoveMachine'
2149 			// (mode 4f) unknown sprite list type 1 - 0054 0105 0059 0198 (00540105 0060019f 00000007)
2150 			// (mode 50) unknown sprite list type 1 - 0000 017f 0000 01f0 (0000017f 000701f7 00000007)
2151 			// said ending also ends up drawing a red bar under the image, which isn't clipped out and
2152 			// is sent before the clip window anyway(?)...
2153 
2154 			// lightning also needs clipping (doesn't have the red bar problem)
2155 			// (mode 4f) unknown sprite list type 1 - 0054 0105 0059 0198 (00540105 0060019f 00000007)
2156 
2157 			if (m_clipblitterMode[1] >= m_blitterMode)
2158 			{
2159 				m_clipvals[1][0] = m_spriteblit[1];
2160 				m_clipvals[1][1] = m_spriteblit[2];
2161 				m_clipvals[1][2] = m_spriteblit[3];
2162 				m_clipblitterMode[1] = m_blitterMode;
2163 			}
2164 
2165 		}
2166 		else
2167 		{
2168 			if (m_clipblitterMode[0] >= m_blitterMode)
2169 			{
2170 				m_clipvals[0][0] = m_spriteblit[1];
2171 				m_clipvals[0][1] = m_spriteblit[2];
2172 				m_clipvals[0][2] = m_spriteblit[3];
2173 				m_clipblitterMode[0] = m_blitterMode;
2174 			}
2175 			//printf("(mode %02x) unknown sprite list type 1 - %04x %04x %04x %04x (%08x %08x %08x)\n", m_blitterMode, (m_spriteblit[1]&0xffff0000)>>16,(m_spriteblit[1]&0x0000ffff)>>0, ((m_spriteblit[2]&0xffff0000)>>16)-((m_spriteblit[3]&0x0000ffff)>>0),((m_spriteblit[2]&0x0000ffff)>>0)-((m_spriteblit[3]&0x0000ffff)>>0),    m_spriteblit[1],m_spriteblit[2],m_spriteblit[3]);
2176 
2177 		}
2178 
2179 		// abort early
2180 		return;
2181 	}
2182 	else
2183 	{
2184 		printf("unknown blit0 value %08x\n", blit0);
2185 		// abort early
2186 		return;
2187 	}
2188 
2189 	std::unique_ptr<cool_render_object> testobject(new cool_render_object(*this));
2190 
2191 	// cache some values that are looked up from RAM to be safe.. alternatively we could stall the rendering if they get written to, but they're a direct memory pointer..
2192 	int test_indirect_tile_enable = (m_spriteblit[5] & 0x00010000)>>16;
2193 
2194 	if (test_indirect_tile_enable)
2195 	{
2196 		uint32_t test_textlookup =  m_spriteblit[11];
2197 		uint16_t test_hCellCount = (m_spriteblit[6] & 0x00003ff);
2198 		uint16_t test_vCellCount = (m_spriteblit[6] & 0x03ff0000) >> 16;
2199 		int bytes = test_vCellCount*test_hCellCount;
2200 		testobject->indirect_tiles = std::make_unique<uint8_t []>(bytes);
2201 		for (int i=0;i<bytes;i++)
2202 		{
2203 			testobject->indirect_tiles[i] = space.read_byte(test_textlookup + i);
2204 		}
2205 	}
2206 	else
2207 	{
2208 		testobject->indirect_tiles = nullptr;
2209 	}
2210 
2211 	int test_indirect_zoom_enable = (m_spriteblit[5] & 0x00000001);
2212 	if (test_indirect_zoom_enable)
2213 	{
2214 		uint32_t test_blit10 =  m_spriteblit[10];
2215 		uint16_t test_vCellCount = (m_spriteblit[6] & 0x03ff0000) >> 16;
2216 		int bytes = test_vCellCount * 4 * 16;
2217 		testobject->indirect_zoom = std::make_unique<uint32_t []>(bytes/4);
2218 		for (int i=0;i<bytes/4;i++)
2219 		{
2220 			testobject->indirect_zoom[i] = space.read_dword(test_blit10 + i*4);
2221 		}
2222 	}
2223 	else
2224 	{
2225 		testobject->indirect_zoom = nullptr;
2226 	}
2227 
2228 	testobject->zpri = m_blitterAddr | m_blittype<<12;
2229 	testobject->blittype = m_blittype;
2230 #if 0
2231 	osd_work_queue *queue;
2232 #endif
2233 	// which queue, which bitmap
2234 	if (m_blitterMode == 0x30 || m_blitterMode == 0x40 || m_blitterMode == 0x4f || m_blitterMode == 0x50 || m_blitterMode == 0x60)
2235 	{
2236 		testobject->drawbitmap = &m_temp_bitmap_sprites[0];
2237 		/* testobject->zbitmap = &m_zbuffer_bitmap[0]; */
2238 		// pass these from the type 1 writes
2239 		testobject->clipvals[0] = m_clipvals[0][0];
2240 		testobject->clipvals[1] = m_clipvals[0][1];
2241 		testobject->clipvals[2] = m_clipvals[0][2];
2242 		testobject->screen = 0;
2243 #if 0
2244 		queue = m_work_queue[0];
2245 #endif
2246 	}
2247 	else // 0x90, 0xa0, 0xaf, 0xb0, 0xc0
2248 	{
2249 		testobject->drawbitmap = &m_temp_bitmap_sprites[1];
2250 		/* testobject->zbitmap = &m_zbuffer_bitmap[1]; */
2251 		// pass these from the type 1 writes
2252 		testobject->clipvals[0] = m_clipvals[1][0];
2253 		testobject->clipvals[1] = m_clipvals[1][1];
2254 		testobject->clipvals[2] = m_clipvals[1][2];
2255 		testobject->screen = 1;
2256 #if 0
2257 		queue = m_work_queue[1];
2258 #endif
2259 	}
2260 
2261 #if 0
2262 	if (m_usethreads)
2263 	{
2264 		osd_work_item_queue(queue, draw_object_threaded, testobject.release(), WORK_ITEM_FLAG_AUTO_RELEASE);
2265 	}
2266 	else
2267 	{
2268 		draw_object_threaded(testobject.release(), 0);
2269 	}
2270 #else
2271 
2272 	if (m_blitterMode == 0x30 || m_blitterMode == 0x40 || m_blitterMode == 0x4f || m_blitterMode == 0x50 || m_blitterMode == 0x60)
2273 	{
2274 		if (m_listcount[0]<1000000)
2275 		{
2276 			m_cool_render_object_list[0][m_listcount[0]] =  std::move(testobject);
2277 			m_listcount[0]++;
2278 		}
2279 		else
2280 		{
2281 			popmessage("m_listcount[0] overflow!\n");
2282 		}
2283 	}
2284 	else
2285 	{
2286 		if (m_listcount[1]<1000000)
2287 		{
2288 			m_cool_render_object_list[1][m_listcount[1]] =  std::move(testobject);
2289 			m_listcount[1]++;
2290 		}
2291 		else
2292 		{
2293 			popmessage("m_listcount[1] overflow!\n");
2294 		}
2295 	}
2296 #endif
2297 }
2298 
2299 
blit_mode_w(uint32_t data)2300 void coolridr_state::blit_mode_w(uint32_t data)
2301 {
2302 	m_blitterMode = (data & 0x00ff0000) >> 16;
2303 
2304 
2305 	if (m_blitterMode == 0xf4)
2306 	{
2307 		// Some sort of addressing state.
2308 		// In the case of text, simply writes 4 characters per 32-bit word.
2309 		// These values may be loaded into RAM somewhere as they are written.
2310 		// The number of characters is determined by the upper-most 8 bits.
2311 		m_textBytesToWrite = (data & 0xff000000) >> 24;
2312 		m_textOffset = (data & 0x0000ffff);
2313 		m_blitterSerialCount = 0;
2314 
2315 		// this is ONLY used when there is text on the screen
2316 
2317 		//printf("set mode %08x\n", data);
2318 
2319 
2320 	}
2321 	else if (m_blitterMode == 0x30 || m_blitterMode == 0x40 || m_blitterMode == 0x4f || m_blitterMode == 0x50 || m_blitterMode == 0x60
2322 			|| m_blitterMode == 0x90 || m_blitterMode == 0xa0 || m_blitterMode == 0xaf || m_blitterMode == 0xb0 || m_blitterMode == 0xc0)
2323 	{
2324 		// 4f / af are used to send the clipping window during the end sequence, I don't know if the 'f' bit has any special meaning
2325 		// we need a hack for the blit window to set by them to work at all
2326 
2327 		// The blitter function(s).
2328 		// After this is set a fixed count of 11 32-bit words are sent to the data register.
2329 		// The lower word always seems to be 0x0001 and the upper byte always 0xac.
2330 		m_blitterSerialCount = 0;
2331 
2332 		if (m_blitterMode>=0x80)
2333 			m_blittype = m_blitterMode - 0x90;
2334 		else
2335 			m_blittype = m_blitterMode - 0x30;
2336 
2337 		m_blittype>>=4;
2338 
2339 
2340 		m_blitterAddr = data & 0x00000fff;
2341 
2342 		// maybe it's actually treated like RAM, and blittermode determines the nature of the write (forward inc, backward inc, no inc etc.)
2343 		// the m_blitterAddr when used does increase by 6 each time
2344 
2345 		// not seen this triggered
2346 		if ((data & 0xff000000) != 0xac000000)
2347 			printf("blitter mode set without upper bits equal 0xac000000\n");
2348 
2349 		// i've seen this triggered once or twice
2350 		// might be there are more z-bits, or it's just overflowing when there are too many sprites
2351 		// also set on the 4f/af cliprect during the ending
2352 		//if (data & 0x0000f000)
2353 		//  printf("blitter mode with mask 0x0000f000 (%08x)\n", data & 0x0000f000);
2354 
2355 
2356 
2357 		//if (m_blitterMode<0x80)  printf("blitter set screen %d mode %02x addr? %04x\n", (data&0x00800000)>>23, ((data & 0x00ff0000)>>16)-0x30, data & 0x00000fff);
2358 
2359 		// form 0xacMM-xxx   ac = fixed value for this mode?  MM = modes above.  -xxx = some kind of offset? but it doesn't increment for each blit like the textOffset / paletteOffset stuff, investigate
2360 
2361 	}
2362 	else if (m_blitterMode == 0x10)
2363 	{
2364 		// Could be a full clear of VRAM?
2365 		for(uint32_t vramAddr = 0x3f40000; vramAddr < 0x3f4ffff; vramAddr+=4)
2366 			m_maincpu->space(AS_PROGRAM).write_dword(vramAddr, 0x00000000);
2367 
2368 		m_blitterSerialCount = 0;
2369 	}
2370 	else if (m_blitterMode == 0xe0)
2371 	{
2372 		// uploads palettes...
2373 		// does NOT upload the palette for the WDUD screen when set to US mode this way..
2374 		m_blitterSerialCount = 0;
2375 		m_textOffset = (data & 0x0000ffff);
2376 
2377 	//  printf("set e0 %08x\n", data);
2378 
2379 	}
2380 	else
2381 	{
2382 		printf("set unknown blit mode %02x\n", m_blitterMode);
2383 	}
2384 }
2385 
blit_data_w(address_space & space,uint32_t data)2386 void coolridr_state::blit_data_w(address_space &space, uint32_t data)
2387 {
2388 	if (m_blitterMode == 0xf4)
2389 	{
2390 		// Uploads a series of bytes that index into the encoded sprite table
2391 		const size_t memOffset = 0x03f40000 + m_textOffset + m_blitterSerialCount;
2392 		space.write_dword(memOffset, data);
2393 		m_blitterSerialCount += 0x04;
2394 	}
2395 	else if (m_blitterMode == 0x30 || m_blitterMode == 0x40 || m_blitterMode == 0x4f || m_blitterMode == 0x50 || m_blitterMode == 0x60
2396 			|| m_blitterMode == 0x90 || m_blitterMode == 0xa0 || m_blitterMode == 0xaf || m_blitterMode == 0xb0 || m_blitterMode == 0xc0)
2397 	{
2398 		// Serialized counts
2399 		if (m_blitterSerialCount < 12)
2400 		{
2401 			m_spriteblit[m_blitterSerialCount] = data;
2402 			m_blitterSerialCount++;
2403 		}
2404 		else
2405 		{
2406 			printf("more than 11 dwords (%d) in blit?\n", m_blitterSerialCount);
2407 		}
2408 
2409 		// use the 11th blit write also as the trigger
2410 		if (m_blitterSerialCount == 12)
2411 		{
2412 			blit_current_sprite(space);
2413 		}
2414 
2415 	}
2416 	// ??
2417 	else if (m_blitterMode == 0x10) // at startup
2418 	{
2419 		//printf("blit mode %02x %02x %08x\n", m_blitterMode, m_blitterSerialCount,  data);
2420 		m_blitterSerialCount++;
2421 
2422 		//blit mode 10 00 00000003
2423 		//blit mode 10 01 00000002
2424 		//blit mode 10 02 00007b20  << this is the palette base for the sprites (but not in aquastage where it gets set to 0x210 and colbase is 0?) ( m_colbase )
2425 		//blit mode 10 00 00000002
2426 		//blit mode 10 01 00000001
2427 		//blit mode 10 02 00040204
2428 		//blit mode 10 03 00000000
2429 
2430 	}
2431 	else if (m_blitterMode == 0xe0) // when going into game (in units of 0x10 writes)
2432 	{
2433 		// it writes the palette for the bgs here, with fade effects?
2434 		//  is this the only way for the tile colours to be actually used, or does this just go to memory somewhere too?
2435 		//printf("blit mode %02x %02x %08x\n", m_blitterMode, m_blitterSerialCount,  data);
2436 
2437 		// maybe should write to a different address, see dma hack in other code
2438 		const size_t memOffset = 0x3c00000 + m_textOffset + m_blitterSerialCount;
2439 		space.write_dword(memOffset, data);
2440 		m_blitterSerialCount += 0x04;
2441 
2442 	}
2443 	else
2444 	{
2445 		printf("unk blit mode %02x\n", m_blitterMode);
2446 	}
2447 }
2448 
fb_mode_w(offs_t offset,uint32_t data,uint32_t mem_mask)2449 void coolridr_state::fb_mode_w(offs_t offset, uint32_t data, uint32_t mem_mask)
2450 {
2451 	/*
2452 	This does the fb display/clear phases of blitter data processed in the previous frame.
2453 	And yes, game effectively runs at 30 Hz (because data processing happens on even frames, actual display transfer happens on odd frames).
2454 	screen 1
2455 	8c200000 06
2456 	00000001 07
2457 	0000017f 07 Y range (upper start, lower end)
2458 	000701f7 07 X range (upper start, lower end)
2459 	00000007 07 enable?
2460 	screen 2
2461 	8c800000 06
2462 	00000001 07
2463 	0000017f 07
2464 	020703f7 07
2465 	00000207 07 enable plus clear?
2466 	*/
2467 
2468 	COMBINE_DATA(&m_blitterClearMode);
2469 
2470 /*
2471     if(m_blitterClearMode != 0x8c200000 && m_blitterClearMode != 0x8c800000)
2472         printf("Blitter Clear used with param %08x\n",m_blitterClearMode);
2473 */
2474 
2475 	m_blitterClearCount = 0;
2476 }
2477 
2478 
2479 
2480 
fb_data_w(offs_t offset,uint32_t data)2481 void coolridr_state::fb_data_w(offs_t offset, uint32_t data)
2482 {
2483 	if(m_blitterClearCount == 0)
2484 	{
2485 		if(data != 1)
2486 			printf("Blitter Clear Count == 0 used with param %08x\n",data);
2487 	}
2488 	else if(m_blitterClearCount == 1)
2489 	{
2490 		if(data != 0x17f)
2491 			printf("Blitter Clear Count == 1 used with param %08x\n",data);
2492 	}
2493 	else if(m_blitterClearCount == 2)
2494 	{
2495 		/*
2496 		if(data != 0x000701f7 && m_txt_blit[offset] != 0x020703f7)
2497 		    printf("Blitter Clear Count == 2 used with param %08x\n",data);
2498 		*/
2499 	}
2500 	else if(m_blitterClearCount == 3)
2501 	{
2502 		if(data != 0x00000007 && data != 0x00000207)
2503 			printf("Blitter Clear Count == 3 used with param %08x\n",data);
2504 
2505 		{
2506 			const rectangle& visarea = m_screen->visible_area();
2507 
2508 			if(m_blitterClearMode == 0x8c200000)
2509 			{
2510 				// wait for our sprite rendering to finish
2511 				osd_work_queue_wait(m_work_queue[0], osd_ticks_per_second() * 100);
2512 
2513 				// copy our old buffer to the actual screen
2514 				copybitmap(m_screen_bitmap[0], m_temp_bitmap_sprites[0], 0, 0, 0, 0, visarea);
2515 
2516 
2517 
2518 
2519 				//m_temp_bitmap_sprites[1].fill(0xff000000, visarea);
2520 				// render the tilemap to the backbuffer, ready for having sprites drawn on it
2521 				draw_bg_coolridr(m_temp_bitmap_sprites[0], visarea, 0);
2522 				// wipe the z-buffer ready for the sprites
2523 				/* m_zbuffer_bitmap[0].fill(0xffff, visarea); */
2524 				// almost certainly wrong
2525 				m_clipvals[0][0] = 0;
2526 				m_clipvals[0][1] = 0;
2527 				m_clipvals[0][2] = 0;
2528 				m_clipblitterMode[0] = 0xff;
2529 
2530 				/* bubble sort, might be something better to use instead */
2531 				for (int pass = 0 ; pass < (m_listcount[0] - 1); pass++)
2532 				{
2533 					for (int elem2 = 0 ; elem2 < m_listcount[0] - pass - 1; elem2++)
2534 					{
2535 						if (m_cool_render_object_list[0][elem2]->zpri > m_cool_render_object_list[0][elem2+1]->zpri)
2536 							std::swap(m_cool_render_object_list[0][elem2], m_cool_render_object_list[0][elem2+1]);
2537 					}
2538 				}
2539 
2540 				for (int i=m_listcount[0]-1;i>=0;i--)
2541 				{
2542 					if (m_usethreads)
2543 					{
2544 						osd_work_item_queue(m_work_queue[0], draw_object_threaded, m_cool_render_object_list[0][i].release(), WORK_ITEM_FLAG_AUTO_RELEASE);
2545 					}
2546 					else
2547 					{
2548 						draw_object_threaded((void*)m_cool_render_object_list[0][i].release(), 0);
2549 					}
2550 				}
2551 
2552 				m_listcount[0] = 0;
2553 
2554 
2555 			}
2556 			else if(m_blitterClearMode == 0x8c800000)
2557 			{
2558 				// wait for our sprite rendering to finish
2559 				osd_work_queue_wait(m_work_queue[1], osd_ticks_per_second() * 100);
2560 
2561 				// copy our old buffer to the actual screen
2562 				copybitmap(m_screen_bitmap[1], m_temp_bitmap_sprites[1], 0, 0, 0, 0, visarea);
2563 
2564 
2565 
2566 
2567 				//m_temp_bitmap_sprites[1].fill(0xff000000, visarea);
2568 				// render the tilemap to the backbuffer, ready for having sprites drawn on it
2569 				draw_bg_coolridr(m_temp_bitmap_sprites[1], visarea, 1);
2570 				// wipe the z-buffer ready for the sprites
2571 				/* m_zbuffer_bitmap[1].fill(0xffff, visarea); */
2572 				// almost certainly wrong
2573 				m_clipvals[1][0] = 0;
2574 				m_clipvals[1][1] = 0;
2575 				m_clipvals[1][2] = 0;
2576 				m_clipblitterMode[1] = 0xff;
2577 
2578 				/* bubble sort, might be something better to use instead */
2579 				for (int pass = 0 ; pass < (m_listcount[1] - 1); pass++)
2580 				{
2581 					for (int elem2 = 0 ; elem2 < m_listcount[1] - pass - 1; elem2++)
2582 					{
2583 						if (m_cool_render_object_list[1][elem2]->zpri > m_cool_render_object_list[1][elem2+1]->zpri)
2584 							std::swap(m_cool_render_object_list[1][elem2], m_cool_render_object_list[1][elem2+1]);
2585 					}
2586 				}
2587 
2588 				for (int i=m_listcount[1]-1;i>=0;i--)
2589 				{
2590 					if (m_usethreads)
2591 					{
2592 						osd_work_item_queue(m_work_queue[1], draw_object_threaded, m_cool_render_object_list[1][i].release(), WORK_ITEM_FLAG_AUTO_RELEASE);
2593 					}
2594 					else
2595 					{
2596 						draw_object_threaded((void*)m_cool_render_object_list[1][i].release(), 0);
2597 					}
2598 				}
2599 
2600 				m_listcount[1] = 0;
2601 
2602 			}
2603 
2604 			//printf("frame\n");
2605 		}
2606 	}
2607 	else
2608 	{
2609 		printf("Blitter Clear Count == %02x used with param %08x\n",m_blitterClearCount,m_txt_blit[offset]);
2610 	}
2611 
2612 	m_blitterClearCount++;
2613 }
2614 
unk_blit_r(offs_t offset)2615 uint32_t coolridr_state::unk_blit_r(offs_t offset)
2616 {
2617 //  if(offset == 0x0c/4) // TODO
2618 
2619 	return m_txt_blit[offset];
2620 }
2621 
2622 
unk_blit_w(offs_t offset,uint32_t data,uint32_t mem_mask)2623 void coolridr_state::unk_blit_w(offs_t offset, uint32_t data, uint32_t mem_mask)
2624 {
2625 	COMBINE_DATA(&m_txt_blit[offset]);
2626 
2627 	switch(offset)
2628 	{
2629 		default:
2630 		{
2631 			printf("sysh1_unk_blit_w unhandled offset %04x %08x %08x\n", offset, data, mem_mask);
2632 		}
2633 		break;
2634 
2635 		case 0x01:
2636 		{
2637 			// writes on startup
2638 			// sysh1_unk_blit_w unhandled offset 0001 01010101 ffffffff
2639 		}
2640 		break;
2641 
2642 		case 0x02:
2643 		{
2644 			// writes 3d0dxxxx / 3d0exxxx before a level start.. offset for a transfer read at 0x400000c, stored in work RAM H
2645 
2646 			//printf("sysh1_unk_blit_w unhandled offset %04x %08x %08x\n", offset, data, mem_mask);
2647 
2648 
2649 		}
2650 		break;
2651 
2652 	}
2653 }
2654 
2655 
2656 
dma_transfer(address_space & space,uint16_t dma_index)2657 void coolridr_state::dma_transfer( address_space &space, uint16_t dma_index )
2658 {
2659 	uint32_t src = 0,dst = 0,size = 0;
2660 	uint8_t end_dma_mark;
2661 	uint8_t cmd;
2662 
2663 	end_dma_mark = 0;
2664 
2665 	do{
2666 		cmd = (m_framebuffer_vram[(0+dma_index)/4] & 0xfc000000) >> 24;
2667 
2668 		switch(cmd)
2669 		{
2670 			case 0x00: /* end of list marker */
2671 				//printf("end of list reached\n");
2672 				end_dma_mark = 1;
2673 				break;
2674 			case 0xc0: /* to internal buffer VRAM */
2675 				src = (m_framebuffer_vram[(0+dma_index)/4] & 0x03ffffff);
2676 				dst = (m_framebuffer_vram[(4+dma_index)/4]);
2677 				size = m_framebuffer_vram[(8+dma_index)/4];
2678 				printf("%08x %08x %04x\n",src,dst,size);
2679 
2680 				if(dst & 0xfff00001)
2681 					printf("unk values to %02x dst %08x\n",cmd,dst);
2682 				dst &= 0x000ffffe;
2683 				dst >>= 1;
2684 
2685 				for(int i=0;i<size;i+=2)
2686 				{
2687 					m_vram[dst] = space.read_word(src);
2688 					dst++;
2689 					src+=2;
2690 				}
2691 
2692 				dma_index+=0xc;
2693 				break;
2694 
2695 			case 0xd0: /* to internal buffer PCG */
2696 				src = (m_framebuffer_vram[(0+dma_index)/4] & 0x03ffffff);
2697 				dst = (m_framebuffer_vram[(4+dma_index)/4]);
2698 				size = m_framebuffer_vram[(8+dma_index)/4];
2699 				if(dst & 0xfff00000)
2700 					printf("unk values to %02x dst %08x\n",cmd,dst);
2701 				dst &= 0x000fffff;
2702 
2703 				for(int i=0;i<size;i++)
2704 				{
2705 					m_pcgram[dst] = space.read_byte(src);
2706 					m_gfxdecode->gfx(m_gfx_index)->mark_dirty(dst/256);
2707 					dst++;
2708 					src++;
2709 				}
2710 
2711 				dma_index+=0xc;
2712 				break;
2713 
2714 			case 0xe0: /* to palette RAM */
2715 				src = (m_framebuffer_vram[(0+dma_index)/4] & 0x03ffffff);
2716 				dst = (m_framebuffer_vram[(4+dma_index)/4]);
2717 				size = m_framebuffer_vram[(8+dma_index)/4];
2718 				/* Note: there are also some reads at 0x3e00000. This tells us that the DMA thing actually mirrors at 0x3c00000 too. */
2719 				if(dst & 0xfff00001)
2720 					printf("unk values to %02x dst %08x\n",cmd,dst);
2721 				dst &= 0x000ffffe;
2722 				dst >>= 1;
2723 
2724 				for(int i=0;i<size;i+=2)
2725 				{
2726 					m_palram[dst] = space.read_word(src);
2727 					dst++;
2728 					src+=2;
2729 				}
2730 
2731 				dma_index+=0xc;
2732 				break;
2733 
2734 				break;
2735 			case 0x10: /* sets up look-up for tilemap video registers */
2736 				m_vregs_address = (m_framebuffer_vram[(0+dma_index)/4] & 0x03ffffff);
2737 				dma_index+=4;
2738 				break;
2739 			case 0x04: /* init - value 0x040c80d2 (unknown purpose, slave mode?) */
2740 			case 0x20: /* screen 1 - linescroll/zoom table? (default values) */
2741 			case 0x24: /* screen 2 / */
2742 			case 0x50: /* screen 1 - unknown */
2743 			case 0x54: /* screen 2 / */
2744 				//printf("%02x %08x\n",cmd,m_framebuffer_vram[(0+dma_index)/4]);
2745 				dma_index+=4;
2746 				break;
2747 			case 0x30: /* screen 1 - 0x80 at boot, then 0x808080  */
2748 			case 0x34: /* screen 2 / */
2749 				m_pen_fill[(cmd & 4) >> 2] = m_framebuffer_vram[(0+dma_index)/4] & 0xffffff;
2750 				dma_index+=4;
2751 				break;
2752 			case 0x40: /* screen 1 - almost certainly RGB brightness (at least bits 4 - 0) */
2753 			case 0x44: /* screen 2 / */
2754 				m_rgb_ctrl[(cmd & 4) >> 2].setting = m_framebuffer_vram[(0+dma_index)/4] & 0xffffe0;
2755 				m_rgb_ctrl[(cmd & 4) >> 2].gradient = m_framebuffer_vram[(0+dma_index)/4] & 0x1f;
2756 				dma_index+=4;
2757 				break;
2758 			default:
2759 				printf("%02x %08x\n",cmd,m_framebuffer_vram[(0+dma_index)/4]);
2760 				dma_index+=4;
2761 				break;
2762 		}
2763 
2764 	}while(!end_dma_mark );
2765 }
2766 
dma_w(address_space & space,offs_t offset,uint32_t data,uint32_t mem_mask)2767 void coolridr_state::dma_w(address_space &space, offs_t offset, uint32_t data, uint32_t mem_mask)
2768 {
2769 	COMBINE_DATA(&m_framebuffer_vram[offset]);
2770 
2771 	if(offset*4 == 0x000)
2772 	{
2773 		/* enable */
2774 		if((m_framebuffer_vram[offset] & 0xff000000) == 0x0f000000)
2775 			dma_transfer(space, m_framebuffer_vram[offset] & 0xffff);
2776 	}
2777 }
2778 
2779 
system_h1_map(address_map & map)2780 void coolridr_state::system_h1_map(address_map &map)
2781 {
2782 	map(0x00000000, 0x001fffff).rom().share("share1").nopw();
2783 	map(0x01000000, 0x01ffffff).rom().region("gfx_data", 0x0000000);
2784 
2785 	map(0x03f40000, 0x03f4ffff).ram().share("txt_vram");//text tilemap + "lineram"
2786 	map(0x04000000, 0x0400000f).rw(FUNC(coolridr_state::unk_blit_r), FUNC(coolridr_state::unk_blit_w)).share("txt_blit");
2787 	map(0x04000010, 0x04000013).w(FUNC(coolridr_state::blit_mode_w));
2788 	map(0x04000014, 0x04000017).w(FUNC(coolridr_state::blit_data_w));
2789 	map(0x04000018, 0x0400001b).w(FUNC(coolridr_state::fb_mode_w));
2790 	map(0x0400001c, 0x0400001f).w(FUNC(coolridr_state::fb_data_w));
2791 
2792 	map(0x06000000, 0x060fffff).ram().share("workrah");
2793 	map(0x20000000, 0x201fffff).rom().share("share1");
2794 
2795 	map(0x60000000, 0x600003ff).nopw();
2796 }
2797 
coolridr_h1_map(address_map & map)2798 void coolridr_state::coolridr_h1_map(address_map &map)
2799 {
2800 	system_h1_map(map);
2801 	map(0x03c00000, 0x03c1ffff).mirror(0x00200000).ram().w(FUNC(coolridr_state::dma_w)).share("fb_vram"); /* mostly mapped at 0x03e00000 */
2802 
2803 	map(0x03f00000, 0x03f0ffff).ram().share("share3"); /*Communication area RAM*/
2804 }
2805 
aquastge_h1_map(address_map & map)2806 void coolridr_state::aquastge_h1_map(address_map &map)
2807 {
2808 	system_h1_map(map);
2809 	map(0x03c00000, 0x03c0ffff).mirror(0x00200000).ram().w(FUNC(coolridr_state::dma_w)).share("fb_vram"); /* mostly mapped at 0x03e00000 */
2810 	map(0x03f50000, 0x03f5ffff).ram(); // video registers
2811 	map(0x03e10000, 0x03e1ffff).ram().share("share3"); /*Communication area RAM*/
2812 	map(0x03f00000, 0x03f0ffff).ram();  /*Communication area RAM*/
2813 }
2814 
2815 template<int Chip>
soundram_r(offs_t offset)2816 uint16_t coolridr_state::soundram_r(offs_t offset)
2817 {
2818 	return m_soundram[Chip][offset];
2819 }
2820 
2821 template<int Chip>
soundram_w(offs_t offset,uint16_t data,uint16_t mem_mask)2822 void coolridr_state::soundram_w(offs_t offset, uint16_t data, uint16_t mem_mask)
2823 {
2824 	COMBINE_DATA(&m_soundram[Chip][offset]);
2825 }
2826 
2827 
lamps_w(uint8_t data)2828 void coolridr_state::lamps_w(uint8_t data)
2829 {
2830 	/*
2831 	x--- ---- P2 Music select Lamp
2832 	-x-- ---- P1 Music select Lamp
2833 	--x- ---- P2 Race Leader Lamp
2834 	---x ---- P1 Race Leader Lamp
2835 	---- x--- P2 Start Lamp
2836 	---- -x-- P1 Start Lamp
2837 	---- ---x (used in game?)
2838 	*/
2839 }
2840 
2841 
sound_dma_r(offs_t offset)2842 uint32_t coolridr_state::sound_dma_r(offs_t offset)
2843 {
2844 	if(offset == 8)
2845 	{
2846 		//popmessage("%02x",m_sound_data);
2847 		/*
2848 		Checked in irq routine
2849 		--x- ---- second SCSP
2850 		---x ---- first SCSP
2851 		*/
2852 		return m_sound_data;
2853 	}
2854 
2855 	if(offset == 2 || offset == 6) // DMA status
2856 		return 0;
2857 
2858 	printf("%08x\n",offset);
2859 
2860 	return m_sound_dma[offset];
2861 }
2862 
sound_dma_w(offs_t offset,uint32_t data,uint32_t mem_mask)2863 void coolridr_state::sound_dma_w(offs_t offset, uint32_t data, uint32_t mem_mask)
2864 {
2865 	address_space &main_space = m_maincpu->space(AS_PROGRAM);
2866 	address_space &sound_space = m_soundcpu->space(AS_PROGRAM);
2867 
2868 	//printf("%08x %08x\n",offset*4,m_h1_unk[offset]);
2869 
2870 	if(offset == 8)
2871 	{
2872 		//probably writing to upper word disables m68k, to lower word enables it
2873 		m_soundcpu->set_input_line(INPUT_LINE_RESET, (data) ? ASSERT_LINE : CLEAR_LINE);
2874 		return;
2875 	}
2876 
2877 	if(offset == 2)
2878 	{
2879 		if(data & 1 && (!(m_sound_dma[2] & 1))) // 0 -> 1 transition enables DMA
2880 		{
2881 			uint32_t src = m_sound_dma[0];
2882 			uint32_t dst = m_sound_dma[1];
2883 			uint32_t size = (m_sound_dma[2]>>16)*0x40;
2884 
2885 			//printf("%08x %08x %08x %02x\n",src,dst,size,m_sound_fifo);
2886 
2887 			for(int i = 0;i < size; i+=2)
2888 			{
2889 				sound_space.write_word(dst,main_space.read_word(src));
2890 				src+=2;
2891 				dst+=2;
2892 			}
2893 		}
2894 	}
2895 
2896 	if(offset == 6)
2897 	{
2898 		if(data & 1 && (!(m_sound_dma[6] & 1))) // 0 -> 1 transition enables DMA
2899 		{
2900 			uint32_t src = m_sound_dma[4];
2901 			uint32_t dst = m_sound_dma[5];
2902 			uint32_t size = (m_sound_dma[6]>>16)*0x40;
2903 
2904 			//printf("%08x %08x %08x %02x\n",src,dst,size,m_sound_fifo);
2905 
2906 			for(int i = 0;i < size; i+=2)
2907 			{
2908 				sound_space.write_word(dst,main_space.read_word(src));
2909 				src+=2;
2910 				dst+=2;
2911 			}
2912 		}
2913 	}
2914 
2915 	COMBINE_DATA(&m_sound_dma[offset]);
2916 }
2917 
2918 
2919 
system_h1_submap(address_map & map)2920 void coolridr_state::system_h1_submap(address_map &map)
2921 {
2922 	map(0x00000000, 0x0001ffff).rom(); // note: SH7032 only supports 64KB
2923 
2924 	map(0x01000000, 0x0100ffff).ram(); //communication RAM
2925 
2926 	map(0x03000000, 0x0307ffff).rw(FUNC(coolridr_state::soundram_r<0>), FUNC(coolridr_state::soundram_w<0>)); //.share("soundram1");
2927 	map(0x03100000, 0x03100fff).rw("scsp1", FUNC(scsp_device::read), FUNC(scsp_device::write));
2928 	map(0x03200000, 0x0327ffff).rw(FUNC(coolridr_state::soundram_r<1>), FUNC(coolridr_state::soundram_w<1>)); //.share("soundram2");
2929 	map(0x03300000, 0x03300fff).rw("scsp2", FUNC(scsp_device::read), FUNC(scsp_device::write));
2930 
2931 	map(0x04000000, 0x0400003f).rw(FUNC(coolridr_state::sound_dma_r), FUNC(coolridr_state::sound_dma_w)).share("sound_dma");
2932 //  map(0x04200000, 0x0420003f).ram(); /* unknown */
2933 
2934 	map(0x05000000, 0x05000fff).ram();
2935 //  map(0x05fffe00, 0x05ffffff).rw(FUNC(coolridr_state::sh7032_r), FUNC(coolridr_state::sh7032_w)); // SH-7032H internal i/o
2936 	map(0x06000000, 0x060001ff).ram().share("nvram"); // backup RAM
2937 	map(0x06100000, 0x0610001f).rw("io", FUNC(sega_315_5649_device::read), FUNC(sega_315_5649_device::write)).umask32(0x00ff00ff);
2938 	map(0x06200000, 0x06200fff).ram(); //network related?
2939 	map(0x07ffe000, 0x07ffffff).ram(); // On-Chip RAM (actually mapped at 0x0fffe000-0x0fffffff)
2940 }
2941 
coolridr_submap(address_map & map)2942 void coolridr_state::coolridr_submap(address_map &map)
2943 {
2944 	system_h1_submap(map);
2945 	map(0x05200000, 0x052001ff).ram();
2946 	map(0x05300000, 0x0530ffff).ram().share("share3"); /*Communication area RAM*/
2947 }
2948 
aquastge_submap(address_map & map)2949 void coolridr_state::aquastge_submap(address_map &map)
2950 {
2951 	system_h1_submap(map);
2952 	map(0x05200000, 0x0520ffff).ram();
2953 	map(0x05210000, 0x0521ffff).ram().share("share3"); /*Communication area RAM*/
2954 	map(0x05220000, 0x0537ffff).ram();
2955 	map(0x06000200, 0x06000207).nopw(); // program bug?
2956 }
2957 
2958 /* TODO: what is this for, volume mixing? MIDI? */
sound_to_sh1_w(uint8_t data)2959 void coolridr_state::sound_to_sh1_w(uint8_t data)
2960 {
2961 	m_sound_fifo = data;
2962 }
2963 
system_h1_sound_map(address_map & map)2964 void coolridr_state::system_h1_sound_map(address_map &map)
2965 {
2966 	map(0x000000, 0x07ffff).ram().share("soundram1");
2967 	map(0x100000, 0x100fff).rw("scsp1", FUNC(scsp_device::read), FUNC(scsp_device::write));
2968 	map(0x200000, 0x27ffff).ram().share("soundram2");
2969 	map(0x300000, 0x300fff).rw("scsp2", FUNC(scsp_device::read), FUNC(scsp_device::write));
2970 	map(0x800000, 0x80ffff).mirror(0x200000).ram();
2971 	map(0x900001, 0x900001).w(FUNC(coolridr_state::sound_to_sh1_w));
2972 }
2973 
2974 template<int Chip>
scsp_map(address_map & map)2975 void coolridr_state::scsp_map(address_map &map)
2976 {
2977 	map(0x000000, 0x07ffff).ram().share(m_soundram[Chip]);
2978 }
2979 
2980 
GFXDECODE_START(gfx_coolridr)2981 static GFXDECODE_START( gfx_coolridr )
2982 //  GFXDECODE_ENTRY( nullptr, 0, tiles16x16_layout, 0, 0x100 )
2983 GFXDECODE_END
2984 
2985 
2986 static INPUT_PORTS_START( coolridr )
2987 	PORT_START("IN0")
2988 	PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_COIN1 )    PORT_NAME("P1 Coin")
2989 	PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_COIN2 )    PORT_NAME("P2 Coin")
2990 	PORT_SERVICE_NO_TOGGLE( 0x04, IP_ACTIVE_LOW )
2991 	PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_SERVICE1 ) PORT_NAME("P1 Service Switch")
2992 	PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_START1 )   PORT_NAME("P1 Start")
2993 	PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_START2 )   PORT_NAME("P2 Start")
2994 	PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_SERVICE2 ) PORT_NAME("P2 Service Switch")
2995 	PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_UNUSED )
2996 
2997 	PORT_START("P1")
2998 	PORT_BIT( 0x03, IP_ACTIVE_LOW, IPT_UNUSED )
2999 	PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_BUTTON1 ) PORT_PLAYER(1) PORT_NAME("P1 Music <<") PORT_CODE(KEYCODE_Z)
3000 	PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_BUTTON2 ) PORT_PLAYER(1) PORT_NAME("P1 Music >>") PORT_CODE(KEYCODE_X)
3001 	PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_BUTTON3 ) PORT_PLAYER(1) PORT_NAME("P1 Shift Up")
3002 	PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_BUTTON4 ) PORT_PLAYER(1) PORT_NAME("P1 Shift Down")
3003 	PORT_BIT( 0xc0, IP_ACTIVE_LOW, IPT_UNUSED )
3004 
3005 	PORT_START("P2")
3006 	PORT_BIT( 0x03, IP_ACTIVE_LOW, IPT_UNUSED )
3007 	PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_BUTTON1 ) PORT_PLAYER(2) PORT_NAME("P2 Music <<") PORT_CODE(KEYCODE_N)
3008 	PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_BUTTON2 ) PORT_PLAYER(2) PORT_NAME("P2 Music >>") PORT_CODE(KEYCODE_M)
3009 	PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_BUTTON3 ) PORT_PLAYER(2) PORT_NAME("P2 Shift Up")
3010 	PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_BUTTON4 ) PORT_PLAYER(2) PORT_NAME("P2 Shift Down")
3011 	PORT_BIT( 0xc0, IP_ACTIVE_LOW, IPT_UNUSED )
3012 
3013 	PORT_START("AN0")
3014 	PORT_BIT( 0xff, 0x80, IPT_PADDLE ) PORT_MINMAX(0x00, 0xff) PORT_SENSITIVITY(30) PORT_KEYDELTA(60) PORT_PLAYER(1) PORT_NAME("P1 Handle Bar")
3015 
3016 	PORT_START("AN1")
3017 	PORT_BIT( 0xff, 0x00, IPT_PEDAL )  PORT_MINMAX(0x00, 0xff) PORT_SENSITIVITY(50) PORT_KEYDELTA(60) PORT_PLAYER(1) PORT_NAME("P1 Throttle")   PORT_REVERSE
3018 
3019 	PORT_START("AN2")
3020 	PORT_BIT( 0xff, 0x00, IPT_PEDAL2 ) PORT_MINMAX(0x00, 0xff) PORT_SENSITIVITY(50) PORT_KEYDELTA(60) PORT_PLAYER(1) PORT_NAME("P1 Brake")      PORT_REVERSE
3021 
3022 	PORT_START("AN4")
3023 	PORT_BIT( 0xff, 0x80, IPT_PADDLE ) PORT_MINMAX(0x00, 0xff) PORT_SENSITIVITY(30) PORT_KEYDELTA(60) PORT_PLAYER(2) PORT_NAME("P2 Handle Bar")
3024 
3025 	PORT_START("AN5")
3026 	PORT_BIT( 0xff, 0x00, IPT_PEDAL )  PORT_MINMAX(0x00, 0xff) PORT_SENSITIVITY(50) PORT_KEYDELTA(60) PORT_PLAYER(2) PORT_NAME("P2 Throttle")   PORT_REVERSE
3027 
3028 	PORT_START("AN6")
3029 	PORT_BIT( 0xff, 0x00, IPT_PEDAL2 ) PORT_MINMAX(0x00, 0xff) PORT_SENSITIVITY(50) PORT_KEYDELTA(60) PORT_PLAYER(2) PORT_NAME("P2 Brake")      PORT_REVERSE
3030 
3031 	// driver debug
3032 	PORT_START("CONFIG")
3033 	PORT_CONFNAME( 0x01, 0x01, "Use Threading Code" )
3034 	PORT_CONFSETTING(    0x00, DEF_STR( Off ) )
3035 	PORT_CONFSETTING(    0x01, DEF_STR( On ) )
3036 INPUT_PORTS_END
3037 
3038 static INPUT_PORTS_START( aquastge )
3039 	PORT_START("IN0")
3040 	PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_COIN1 )    PORT_NAME("P1 Coin")
3041 	PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_COIN2 )    PORT_NAME("P2 Coin")
3042 	PORT_SERVICE_NO_TOGGLE( 0x04, IP_ACTIVE_LOW )
3043 	PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_SERVICE1 ) PORT_NAME("P1 Service Switch")
3044 	PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_START1 )   PORT_NAME("P1 Start")
3045 	PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_START2 )   PORT_NAME("P2 Start")
3046 	PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_SERVICE2 ) PORT_NAME("P2 Service Switch")
3047 	PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_UNUSED )
3048 
3049 	PORT_START("IN1")
3050 	PORT_BIT( 0x0f, IP_ACTIVE_LOW, IPT_UNUSED )
3051 	PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN ) PORT_PLAYER(1)
3052 	PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_JOYSTICK_UP )   PORT_PLAYER(1)
3053 	PORT_BIT( 0xc0, IP_ACTIVE_LOW, IPT_UNUSED )
3054 
3055 	// driver debug
3056 	PORT_START("CONFIG")
3057 	PORT_CONFNAME( 0x01, 0x01, "Use Threading Code" )
3058 	PORT_CONFSETTING(    0x00, DEF_STR( Off ) )
3059 	PORT_CONFSETTING(    0x01, DEF_STR( On ) )
3060 INPUT_PORTS_END
3061 
3062 
3063 // IRQs 4 & 6 are valid on SH-2
3064 TIMER_DEVICE_CALLBACK_MEMBER(coolridr_state::interrupt_main)
3065 {
3066 	int scanline = param;
3067 
3068 	if(scanline == 384)
3069 		m_maincpu->set_input_line(4, HOLD_LINE);
3070 
3071 	if(scanline == 0)
3072 		m_maincpu->set_input_line(6, HOLD_LINE);
3073 }
3074 
TIMER_DEVICE_CALLBACK_MEMBER(coolridr_state::interrupt_sub)3075 TIMER_DEVICE_CALLBACK_MEMBER(coolridr_state::interrupt_sub)
3076 {
3077 	int scanline = param;
3078 
3079 	/* 0xa: reads from 0x4000000 (sound irq) */
3080 	/* 0xc: reads from inputs (so presumably V-Blank) */
3081 	/* 0xe: tries to r/w to 0x62***** area (network irq?) */
3082 
3083 	if(scanline == 384)
3084 		m_subcpu->set_input_line(0xc, HOLD_LINE);
3085 }
3086 
3087 
3088 
3089 
3090 #define READ_COMPRESSED_ROM(chip) \
3091 	m_compressedgfx[(chip)*0x400000 + romoffset] << 8 | m_compressedgfx[(chip)*0x0400000 + romoffset +1];
3092 // this helps you feth the 20bit words from an address in the compressed data
get_20bit_data(uint32_t romoffset,int _20bitwordnum)3093 uint32_t coolridr_state::get_20bit_data(uint32_t romoffset, int _20bitwordnum)
3094 {
3095 	uint16_t testvalue, testvalue2;
3096 
3097 	int temp = _20bitwordnum & 3;
3098 	int inc = 0;
3099 	if (_20bitwordnum&4) inc = 5;
3100 
3101 	romoffset += (_20bitwordnum>>3)*2;
3102 
3103 	if (temp==0)
3104 	{
3105 		testvalue  = READ_COMPRESSED_ROM(0+inc);
3106 		testvalue2 = READ_COMPRESSED_ROM(1+inc);
3107 		return (testvalue << 4) | (testvalue2 & 0xf000) >> 12;
3108 	}
3109 	else if (temp==1)
3110 	{
3111 		testvalue  = READ_COMPRESSED_ROM(1+inc);
3112 		testvalue2 = READ_COMPRESSED_ROM(2+inc);
3113 		return ((testvalue & 0x0fff) << 8) | (testvalue2 & 0xff00) >> 8;
3114 	}
3115 	else if (temp==2)
3116 	{
3117 		testvalue  = READ_COMPRESSED_ROM(2+inc);
3118 		testvalue2 = READ_COMPRESSED_ROM(3+inc);
3119 		return ((testvalue & 0x00ff) << 12) | (testvalue2 & 0xfff0) >> 4;
3120 	}
3121 	else // temp == 3
3122 	{
3123 		testvalue  = READ_COMPRESSED_ROM(3+inc);
3124 		testvalue2 = READ_COMPRESSED_ROM(4+inc);
3125 		return ((testvalue & 0x000f) << 16) | (testvalue2);
3126 	}
3127 
3128 }
3129 
get_10bit_data(uint32_t romoffset,int _10bitwordnum)3130 uint16_t coolridr_state::get_10bit_data(uint32_t romoffset, int _10bitwordnum)
3131 {
3132 	uint32_t data = get_20bit_data(romoffset, _10bitwordnum>>1);
3133 	if (_10bitwordnum&1) return data & 0x3ff;
3134 	else return (data>>10) & 0x3ff;
3135 }
3136 
machine_start()3137 void coolridr_state::machine_start()
3138 {
3139 	size_t  size    = m_compressedgfx.length();
3140 
3141 	// we're expanding 10bit packed data to 16bits(10 used)
3142 	m_expanded_10bit_gfx = std::make_unique<uint16_t[]>(((size/10)*16)/2);
3143 
3144 	for (int i=0;i<(0x800000*8)/2;i++)
3145 	{
3146 		m_expanded_10bit_gfx[i] = get_10bit_data( 0, i);
3147 	}
3148 
3149 	// do a rearranged version too with just the 16-bit words in a different order, palettes seem to
3150 	// be referenced this way?!
3151 	m_rearranged_16bit_gfx = std::make_unique<uint16_t[]>(size/2);
3152 
3153 	uint16_t* compressed = (uint16_t*)&m_compressedgfx[0];
3154 	int count = 0;
3155 	for (int i=0;i<size/2/10;i++)
3156 	{
3157 		m_rearranged_16bit_gfx[count+0] = ((compressed[i+((0x0400000/2)*0)]&0x00ff) << 8) | ((compressed[i+((0x0400000/2)*0)]&0xff00) >> 8);
3158 		m_rearranged_16bit_gfx[count+1] = ((compressed[i+((0x0400000/2)*1)]&0x00ff) << 8) | ((compressed[i+((0x0400000/2)*1)]&0xff00) >> 8);
3159 		m_rearranged_16bit_gfx[count+2] = ((compressed[i+((0x0400000/2)*2)]&0x00ff) << 8) | ((compressed[i+((0x0400000/2)*2)]&0xff00) >> 8);
3160 		m_rearranged_16bit_gfx[count+3] = ((compressed[i+((0x0400000/2)*3)]&0x00ff) << 8) | ((compressed[i+((0x0400000/2)*3)]&0xff00) >> 8);
3161 		m_rearranged_16bit_gfx[count+4] = ((compressed[i+((0x0400000/2)*4)]&0x00ff) << 8) | ((compressed[i+((0x0400000/2)*4)]&0xff00) >> 8);
3162 		m_rearranged_16bit_gfx[count+5] = ((compressed[i+((0x0400000/2)*5)]&0x00ff) << 8) | ((compressed[i+((0x0400000/2)*5)]&0xff00) >> 8);
3163 		m_rearranged_16bit_gfx[count+6] = ((compressed[i+((0x0400000/2)*6)]&0x00ff) << 8) | ((compressed[i+((0x0400000/2)*6)]&0xff00) >> 8);
3164 		m_rearranged_16bit_gfx[count+7] = ((compressed[i+((0x0400000/2)*7)]&0x00ff) << 8) | ((compressed[i+((0x0400000/2)*7)]&0xff00) >> 8);
3165 		m_rearranged_16bit_gfx[count+8] = ((compressed[i+((0x0400000/2)*8)]&0x00ff) << 8) | ((compressed[i+((0x0400000/2)*8)]&0xff00) >> 8);
3166 		m_rearranged_16bit_gfx[count+9] = ((compressed[i+((0x0400000/2)*9)]&0x00ff) << 8) | ((compressed[i+((0x0400000/2)*9)]&0xff00) >> 8);
3167 		count+=10;
3168 	}
3169 
3170 
3171 	if (0)
3172 	{
3173 		FILE *fp;
3174 		char filename[256];
3175 		sprintf(filename,"expanded_%s_gfx", machine().system().name);
3176 		fp=fopen(filename, "w+b");
3177 		if (fp)
3178 		{
3179 			for (int i=0;i<(0x800000*8);i++)
3180 			{
3181 				fwrite((uint8_t*)m_expanded_10bit_gfx.get()+(i^1), 1, 1, fp);
3182 			}
3183 			fclose(fp);
3184 
3185 		}
3186 	}
3187 
3188 	m_work_queue[0] = osd_work_queue_alloc(WORK_QUEUE_FLAG_HIGH_FREQ);
3189 	m_work_queue[1] = osd_work_queue_alloc(WORK_QUEUE_FLAG_HIGH_FREQ);
3190 	m_decode[0].current_object = 0;
3191 	m_decode[1].current_object = 0;
3192 
3193 	save_item(NAME(m_sound_data));
3194 	save_item(NAME(m_sound_fifo));
3195 }
3196 
machine_reset()3197 void coolridr_state::machine_reset()
3198 {
3199 	m_soundcpu->set_input_line(INPUT_LINE_RESET, ASSERT_LINE);
3200 
3201 	m_usethreads = m_io_config->read()&1;
3202 }
3203 
scsp_irq(offs_t offset,uint8_t data)3204 void coolridr_state::scsp_irq(offs_t offset, uint8_t data)
3205 {
3206 	m_soundcpu->set_input_line(offset, data);
3207 }
3208 
WRITE_LINE_MEMBER(coolridr_state::scsp1_to_sh1_irq)3209 WRITE_LINE_MEMBER(coolridr_state::scsp1_to_sh1_irq)
3210 {
3211 	m_subcpu->set_input_line(0xe, (state) ? ASSERT_LINE : CLEAR_LINE);
3212 	if(state)
3213 		m_sound_data |= 0x10;
3214 	else
3215 		m_sound_data &= ~0x10;
3216 }
3217 
WRITE_LINE_MEMBER(coolridr_state::scsp2_to_sh1_irq)3218 WRITE_LINE_MEMBER(coolridr_state::scsp2_to_sh1_irq)
3219 {
3220 	m_subcpu->set_input_line(0xe, (state) ? ASSERT_LINE : CLEAR_LINE);
3221 	if(state)
3222 		m_sound_data |= 0x20;
3223 	else
3224 		m_sound_data &= ~0x20;
3225 }
3226 
3227 #define MAIN_CLOCK XTAL(28'636'363)
3228 
coolridr(machine_config & config)3229 void coolridr_state::coolridr(machine_config &config)
3230 {
3231 	SH2(config, m_maincpu, MAIN_CLOCK);  // 28 MHz
3232 	m_maincpu->set_addrmap(AS_PROGRAM, &coolridr_state::coolridr_h1_map);
3233 	TIMER(config, "scantimer").configure_scanline(FUNC(coolridr_state::interrupt_main), "screen", 0, 1);
3234 
3235 	M68000(config, m_soundcpu, 22579000/2); // 22.579 MHz XTAL / 2 = 11.2895 MHz
3236 	m_soundcpu->set_addrmap(AS_PROGRAM, &coolridr_state::system_h1_sound_map);
3237 
3238 	SH1(config, m_subcpu, 16000000);  // SH7032 HD6417032F20!! 16 MHz
3239 	m_subcpu->set_addrmap(AS_PROGRAM, &coolridr_state::coolridr_submap);
3240 	TIMER(config, "scantimer2").configure_scanline(FUNC(coolridr_state::interrupt_sub), "screen", 0, 1);
3241 
3242 	NVRAM(config, "nvram", nvram_device::DEFAULT_ALL_0);
3243 
3244 	sega_315_5649_device &io(SEGA_315_5649(config, "io", 0));
3245 	io.out_pb_callback().set(FUNC(coolridr_state::lamps_w));
3246 	io.in_pc_callback().set_ioport("IN0");
3247 	io.in_pd_callback().set_ioport("P1");
3248 	io.in_pe_callback().set_ioport("P2");
3249 	io.an_port_callback<0>().set_ioport("AN0");
3250 	io.an_port_callback<1>().set_ioport("AN1");
3251 	io.an_port_callback<2>().set_ioport("AN2");
3252 	io.an_port_callback<4>().set_ioport("AN4");
3253 	io.an_port_callback<5>().set_ioport("AN5");
3254 	io.an_port_callback<6>().set_ioport("AN6");
3255 
3256 	GFXDECODE(config, m_gfxdecode, m_palette, gfx_coolridr);
3257 
3258 	SCREEN(config, m_screen, SCREEN_TYPE_RASTER);
3259 	m_screen->set_refresh_hz(60);
3260 	m_screen->set_size(640, 512);
3261 	m_screen->set_visarea(CLIPMINX_FULL,CLIPMAXX_FULL, CLIPMINY_FULL, CLIPMAXY_FULL);
3262 	m_screen->set_screen_update(FUNC(coolridr_state::screen_update<0>));
3263 	m_screen->set_palette(m_palette);
3264 
3265 	screen_device &screen2(SCREEN(config, "screen2", SCREEN_TYPE_RASTER));
3266 	screen2.set_refresh_hz(60);
3267 	screen2.set_size(640, 512);
3268 	screen2.set_visarea(CLIPMINX_FULL,CLIPMAXX_FULL, CLIPMINY_FULL, CLIPMAXY_FULL);
3269 	screen2.set_screen_update(FUNC(coolridr_state::screen_update<1>));
3270 	screen2.set_palette(m_palette);
3271 
3272 	PALETTE(config, m_palette, palette_device::RGB_555);
3273 
3274 	config.set_default_layout(layout_dualhsxs);
3275 
3276 	SPEAKER(config, "lspeaker").front_left();
3277 	SPEAKER(config, "rspeaker").front_right();
3278 
3279 	scsp_device &scsp1(SCSP(config, "scsp1", 22579000)); // 22.579 MHz XTAL
3280 	scsp1.set_addrmap(0, &coolridr_state::scsp_map<0>);
3281 	scsp1.irq_cb().set(FUNC(coolridr_state::scsp_irq));
3282 	scsp1.main_irq_cb().set(FUNC(coolridr_state::scsp1_to_sh1_irq));
3283 	scsp1.add_route(0, "lspeaker", 1.0);
3284 	scsp1.add_route(1, "rspeaker", 1.0);
3285 
3286 	scsp_device &scsp2(SCSP(config, "scsp2", 22579000)); // 22.579 MHz XTAL
3287 	scsp2.set_addrmap(0, &coolridr_state::scsp_map<1>);
3288 	scsp2.main_irq_cb().set(FUNC(coolridr_state::scsp2_to_sh1_irq));
3289 	scsp2.add_route(0, "lspeaker", 1.0);
3290 	scsp2.add_route(1, "rspeaker", 1.0);
3291 }
3292 
aquastge(machine_config & config)3293 void coolridr_state::aquastge(machine_config &config)
3294 {
3295 	coolridr(config);
3296 	m_maincpu->set_addrmap(AS_PROGRAM, &coolridr_state::aquastge_h1_map);
3297 
3298 	m_subcpu->set_addrmap(AS_PROGRAM, &coolridr_state::aquastge_submap);
3299 
3300 	sega_315_5649_device &io(SEGA_315_5649(config.replace(), "io", 0));
3301 	io.in_pc_callback().set_ioport("IN0");
3302 	io.in_pd_callback().set_ioport("IN1");
3303 }
3304 
3305 ROM_START( coolridr )
3306 	ROM_REGION( 0x200000, "maincpu", 0 ) /* SH2 code */
3307 	ROM_LOAD32_WORD_SWAP( "ep17659.30", 0x0000000, 0x080000, CRC(473027b0) SHA1(acaa212869dd79550235171b9f054e82750f74c3) )
3308 	ROM_LOAD32_WORD_SWAP( "ep17658.29", 0x0000002, 0x080000, CRC(7ecfdfcc) SHA1(97cb3e6cf9764c8db06de12e4e958148818ef737) )
3309 	ROM_LOAD32_WORD_SWAP( "ep17661.32", 0x0100000, 0x080000, CRC(81a7d90b) SHA1(99f8c3e75b94dd1b60455c26dc38ce08db82fe32) )
3310 	ROM_LOAD32_WORD_SWAP( "ep17660.31", 0x0100002, 0x080000, CRC(27b7a507) SHA1(4c28b1d18d75630a73194b5d4fd166f3b647c595) )
3311 
3312 	/* Page 12 of the service manual states that these 4 regions are tested, so I believe that they are read by the SH-2 */
3313 	ROM_REGION32_BE( 0x1000000, "gfx_data", 0 ) /* SH2 code */
3314 	ROM_LOAD32_WORD_SWAP( "mp17650.11", 0x0000002, 0x0200000, CRC(0ccc84a1) SHA1(65951685b0c8073f6bd1cf9959e1b4d0fc6031d8) )
3315 	ROM_LOAD32_WORD_SWAP( "mp17651.12", 0x0000000, 0x0200000, CRC(25fd7dde) SHA1(a1c3f3d947ce20fbf61ea7ab235259be9b7d35a8) )
CRC(be9b4d05)3316 	ROM_LOAD32_WORD_SWAP( "mp17652.13", 0x0400002, 0x0200000, CRC(be9b4d05) SHA1(0252ba647434f69d6eacb4efc6f55e6af534c7c5) )
3317 	ROM_LOAD32_WORD_SWAP( "mp17653.14", 0x0400000, 0x0200000, CRC(64d1406d) SHA1(779dbbf42a14a6be1de9afbae5bbb18f8f36ceb3) )
3318 	ROM_LOAD32_WORD_SWAP( "mp17654.15", 0x0800002, 0x0200000, CRC(5dee5cba) SHA1(6e6ec8574bdd35cc27903fc45f0d4a36ce9df103) )
3319 	ROM_LOAD32_WORD_SWAP( "mp17655.16", 0x0800000, 0x0200000, CRC(02903cf2) SHA1(16d555fda144e0f1b62b428e9158a0e8ebf7084e) )
3320 	ROM_LOAD32_WORD_SWAP( "mp17656.17", 0x0c00002, 0x0200000, CRC(945c89e3) SHA1(8776d74f73898d948aae3c446d7c710ad0407603) )
3321 	ROM_LOAD32_WORD_SWAP( "mp17657.18", 0x0c00000, 0x0200000, CRC(74676b1f) SHA1(b4a9003a052bde93bebfa4bef9e8dff65003c3b2) )
3322 
3323 	ROM_REGION( 0x100000, "sub", 0 ) /* SH1 */
3324 	ROM_LOAD16_WORD_SWAP( "ep17662.12", 0x000000, 0x020000,  CRC(50d66b1f) SHA1(f7b7f2f5b403a13b162f941c338a3e1207762a0b) )
3325 
3326 	/* these are compressed sprite data */
3327 	ROM_REGION( 0x2800000, "compressedgfx", ROMREGION_ERASEFF )
3328 	ROM_LOAD16_WORD_SWAP( "mpr-17644.ic5", 0x0000000, 0x0400000, CRC(80199c79) SHA1(e525d8ee9f9176101629853e50cca73b02b16a38) ) // 0004
3329 	ROM_LOAD16_WORD_SWAP( "mpr-17643.ic4", 0x0400000, 0x0400000, CRC(5100f23b) SHA1(659c2300399ff1cbd24fb1eb18cfd6c26e06fd96) ) // 9000
3330 	ROM_LOAD16_WORD_SWAP( "mpr-17642.ic3", 0x0800000, 0x0400000, CRC(1a5bcc73) SHA1(a7df04c0a326323ea185db5f55b3e0449d76c535) ) // 4900
3331 	ROM_LOAD16_WORD_SWAP( "mpr-17641.ic2", 0x0c00000, 0x0400000, CRC(fccc3dae) SHA1(0df7fd8b1110ba9063dc4dc40301267229cb9a35) ) // 0490
3332 	ROM_LOAD16_WORD_SWAP( "mpr-17640.ic1", 0x1000000, 0x0400000, CRC(981e3e69) SHA1(d242055e0359ec4b5fac4676b2f974fbc974cc68) ) // 0049
3333 	ROM_LOAD16_WORD_SWAP( "mpr-17649.ic10",0x1400000, 0x0400000, CRC(618c47ae) SHA1(5b69ad36fcf8e70d34c3b2fc71412ce953c5ceb3) ) // 0004
3334 	ROM_LOAD16_WORD_SWAP( "mpr-17648.ic9", 0x1800000, 0x0400000, CRC(bf184cce) SHA1(62c004ea279f9a649d21426369336c2e1f9d24da) ) // 9000
3335 	ROM_LOAD16_WORD_SWAP( "mpr-17647.ic8", 0x1c00000, 0x0400000, CRC(9dd9330c) SHA1(c91a7f497c1f4bd283bd683b06dff88893724d51) ) // 4900
3336 	ROM_LOAD16_WORD_SWAP( "mpr-17646.ic7", 0x2000000, 0x0400000, CRC(b77eb2ad) SHA1(b832c0f1798aca39adba840d56ae96a75346670a) ) // 0490
3337 	ROM_LOAD16_WORD_SWAP( "mpr-17645.ic6", 0x2400000, 0x0400000, CRC(56968d07) SHA1(e88c3d66ea05affb4681a25d155f097bd1b5a84b) ) // 0049
3338 ROM_END
3339 
3340 /*
3341 Aqua Stage (Coin pusher)
3342 PCB: 833-12000 AQUA STAGE
3343 */
3344 
3345 ROM_START( aquastge )
3346 	ROM_REGION( 0x200000, "maincpu", 0 ) /* SH2 code */
3347 	ROM_LOAD32_WORD_SWAP( "epr-18280.ic30", 0x0000000, 0x080000, CRC(4038352a) SHA1(fe951592e2462c701c740da4ec77435ae3026eab) )
3348 	ROM_LOAD32_WORD_SWAP( "epr-18279.ic29", 0x0000002, 0x080000, CRC(9697cbcd) SHA1(4afa9a3f85b9d4483dafae8a98526ae32abd7103) )
3349 	ROM_LOAD32_WORD_SWAP( "epr-18282.ic32", 0x0100000, 0x080000, CRC(53684dd8) SHA1(59759f6e3f815280a2406cc2133fc46e673cc76a))
3350 	ROM_LOAD32_WORD_SWAP( "epr-18281.ic31", 0x0100002, 0x080000, CRC(f1233190) SHA1(471578c9343ac7198d73bee73975656c52e0bc5d) )
3351 
3352 	/* Page 12 of the service manual states that these 4 regions are tested, so I believe that they are read by the SH-2 */
3353 	ROM_REGION32_BE( 0x1000000, "gfx_data", ROMREGION_ERASEFF ) /* SH2 code */
3354 	ROM_LOAD32_WORD_SWAP( "mpr-18283.ic17", 0x0c00002, 0x0200000, CRC(f42e2e72) SHA1(caf8733b6888ee718032c55f64da14590353517e) )
3355 	ROM_RELOAD(0x0000002, 0x0200000)
3356 	ROM_LOAD32_WORD_SWAP( "mpr-18284.ic18", 0x0c00000, 0x0200000, CRC(5fdf3c1f) SHA1(9976fe4afc3234eecbaf47a2e0f951b6fe1cb5f5) )
3357 	ROM_RELOAD(0x0000000, 0x0200000)
3358 
3359 	ROM_REGION( 0x100000, "sub", 0 ) /* SH1 */
3360 	ROM_LOAD16_WORD_SWAP( "epr-18278.ic12", 0x000000, 0x020000,  CRC(e601132a) SHA1(bed103ef2e0dfa8bb485d93d661142b82c23088b) )
3361 
3362 	/* these are compressed sprite data */
3363 	ROM_REGION( 0x2800000, "compressedgfx", ROMREGION_ERASEFF )
3364 	ROM_LOAD16_WORD_SWAP( "mpr-18289.ic5", 0x0000000, 0x0200000, CRC(fb212692) SHA1(da2f77564e718276c66b0f02e72a97d7b3653c35) ) // 0004
3365 	ROM_LOAD16_WORD_SWAP( "mpr-18288.ic4", 0x0400000, 0x0200000, CRC(558c82ee) SHA1(e2ae4f2e81c7360eedd1b18e36d1f6ca6c015fee) ) // 9000
3366 	ROM_LOAD16_WORD_SWAP( "mpr-18287.ic3", 0x0800000, 0x0200000, CRC(bf8743d8) SHA1(8d0e0691ec062f1939db8f6b75edb92d34417f81) ) // 4900
3367 	ROM_LOAD16_WORD_SWAP( "mpr-18286.ic2", 0x0c00000, 0x0200000, CRC(3eb95e9a) SHA1(d565e5f353327e16f7ead2251fd9a503bf46e210) ) // 0490
3368 	ROM_LOAD16_WORD_SWAP( "mpr-18285.ic1", 0x1000000, 0x0200000, CRC(8390453c) SHA1(e7d3a6579d9805a71b954bb248a2da749e9d9d38) ) // 0049
3369 	ROM_LOAD16_WORD_SWAP( "mpr-18294.ic10",0x1400000, 0x0200000, CRC(341ebd4a) SHA1(9d9a1c09d81a50132edcc18a99266416683f4ff6) ) // 0004
3370 	ROM_LOAD16_WORD_SWAP( "mpr-18293.ic9", 0x1800000, 0x0200000, CRC(f76bc076) SHA1(f5a8f9bd26b2e8533a1fbf8da6938373df971749)) // 9000
3371 	ROM_LOAD16_WORD_SWAP( "mpr-18292.ic8", 0x1c00000, 0x0200000, CRC(59a713f9) SHA1(388b833fa6fb930f26c80674606505ec80668a16) ) // 4900
3372 	ROM_LOAD16_WORD_SWAP( "mpr-18291.ic7", 0x2000000, 0x0200000, CRC(b6c167bd) SHA1(4990bae50e8804b2e1048aa5c64b086e8427073f) ) // 0490
3373 	ROM_LOAD16_WORD_SWAP( "mpr-18290.ic6", 0x2400000, 0x0200000, CRC(11f7adb0) SHA1(a72f9892f93506456edc7ffc66224446a58ca38b) ) // 0049
3374 ROM_END
3375 
3376 
3377 void coolridr_state::init_coolridr()
3378 {
3379 	m_maincpu->sh2drc_set_options(SH2DRC_FASTEST_OPTIONS);
3380 	m_subcpu->sh2drc_set_options(SH2DRC_FASTEST_OPTIONS);
3381 
3382 	m_colbase = 0x7b20;
3383 
3384 	// work around the hack when mapping the workram directly
3385 	m_maincpu->sh2drc_add_fastram(0x06000000, 0x060fffff, 0, &m_workram_h[0]);
3386 	m_maincpu->sh2drc_add_fastram(0x00000000, 0x001fffff, 1, &m_rom[0]);
3387 	m_maincpu->sh2drc_add_fastram(0x20000000, 0x201fffff, 1, &m_rom[0]);
3388 }
3389 
init_aquastge()3390 void coolridr_state::init_aquastge()
3391 {
3392 	m_maincpu->sh2drc_set_options(SH2DRC_FASTEST_OPTIONS);
3393 	m_subcpu->sh2drc_set_options(SH2DRC_FASTEST_OPTIONS);
3394 
3395 	m_colbase = 0;
3396 }
3397 
3398 GAME(  1995, coolridr, 0, coolridr, coolridr, coolridr_state, init_coolridr, ROT0, "Sega", "Cool Riders", MACHINE_IMPERFECT_SOUND | MACHINE_NODEVICE_LAN ) // region is set in test mode, this set is for Japan, USA and Export (all regions)
3399 GAMEL( 1995, aquastge, 0, aquastge, aquastge, coolridr_state, init_aquastge, ROT0, "Sega", "Aqua Stage",  MACHINE_NOT_WORKING, layout_aquastge)
3400