1 /***************************************************************************
2 
3   Functions to emulate the video hardware of some Toaplan games
4 
5 
6  To Do / Unknowns
7 	-  Hack is needed to reset sound CPU and sound chip when machine
8 		is 'tilted'in Pipi & Bibis. Otherwise sound CPU interferes
9 		with the main CPU test of shared RAM. You get a 'Sub CPU RAM Error'
10 	-  What do Scroll registers 0Eh and 0Fh really do ????
11 	-  Snow Bros 2 sets bit 6 of the sprite X info word during weather
12 		world map, and bits 4, 5 and 6 of the sprite X info word during
13 		the Rabbit boss screen - reasons are unknown.
14 	-  Fourth set of scroll registers have been used for Sprite scroll
15 		though it may not be correct. For most parts this looks right
16 		except for Snow Bros 2 when in the rabbit boss screen (all sprites
17 		jump when big green nasty (which is the foreground layer) comes
18 		in from the left)
19 	-  Teki Paki tests video RAM from address 0 past SpriteRAM to $37ff.
20 		It doesnt seem to use that memory above SpriteRAM for anything though.
21 	-  Teki Paki sprites seem to be three frames ahead of the tile layers.
22 		Since this driver double buffers the sprites, Teki Paki is still
23 		suffering sprite lag (Does it need an extra buffer - quite strange)
24 	-  Batsugun, relationship between the two video controllers (priority
25 		wise) is wrong and unknown.
26 
27  Video RAM address layout:
28 
29 	Bank		  data size of video layer
30 	-----------------------------------------
31 	$0000-07FF	  800h words for background layer
32 	$0800-0FFF	  800h words for foreground layer
33 	$1000-17FF	  800h words for top (text) layer
34 	$1800-1BFF	  400h words for sprites (100 possible sprites)
35 
36 
37 
38  Tile RAM format (each tile takes up 32 bits)
39 
40   0         1         2         3
41   ---- ---- ---- ---- xxxx xxxx xxxx xxxx = Tile number (0 - FFFFh)
42   ---- ---- -xxx xxxx ---- ---- ---- ---- = Color (0 - 7Fh)
43   ---- ---- ?--- ---- ---- ---- ---- ---- = unknown / unused
44   ---- xxxx ---- ---- ---- ---- ---- ---- = Priority (0 - Fh)
45   ???? ---- ---- ---- ---- ---- ---- ---- = unknown / unused / possible flips
46 
47 Sprites are of varying sizes between 8x8 and 128x128 and any size
48 inbetween, in multiples of 8 either way.
49 
50 Here we draw the first 8x8 part of the sprite, then by using the sprite
51 dimensions, we draw the rest of the 8x8 parts to produce the complete
52 sprite.
53 
54 There seems to be sprite buffering - double buffering actually.
55 
56  Sprite RAM format (data for each sprite takes up 4 words)
57 
58   0
59   ---- ----  ---- --xx = top 2 bits of Sprite number
60   ---- ----  xxxx xx-- = Color (0 - 3Fh)
61   ---- xxxx  ---- ---- = Priority (0 - Fh)
62   ---x ----  ---- ---- = Flip X
63   --x- ----  ---- ---- = Flip Y
64   -?-- ----  ---- ---- = unknown / unused
65   x--- ----  ---- ---- = Show sprite ?
66 
67   1
68   xxxx xxxx  xxxx xxxx = Sprite number (top two bits in word 0)
69 
70   2
71   ---- ----  ---- xxxx = Sprite X size (add 1, then multiply by 8)
72   ---- ----  -??? ---- = unknown - used in Snow Bros. 2
73   xxxx xxxx  x--- ---- = X position
74 
75   3
76   ---- ----  ---- xxxx = Sprite Y size (add 1, then multiply by 8)
77   ---- ----  -??? ---- = unknown / unused
78   xxxx xxxx  x--- ---- = Y position
79 
80 
81  Extra-text RAM format (data for each text takes up 2 words)
82 
83 Raizing and Tatsujin2 and Fixeight have extra-text layer.
84 
85   0
86   ---- ---- ---- --xx = top 2 bits of Tile number
87   ---- ---- xxxx xx-- = Color (0 - 3Fh) + 40h
88 
89   1
90   xxxx xxxx xxxx xxxx = Tile number (top two bits in word 0)
91 
92 
93 Scroll Registers (hex) :
94 
95 	00		Background scroll X (X flip off)
96 	01		Background scroll Y (Y flip off)
97 	02		Foreground scroll X (X flip off)
98 	03		Foreground scroll Y (Y flip off)
99 	04		Top (text) scroll X (X flip off)
100 	05		Top (text) scroll Y (Y flip off)
101 	06		Sprites    scroll X (X flip off) ???
102 	07		Sprites    scroll Y (Y flip off) ???
103 	0E		???? Initialise Video controller at startup ????
104 	0F		Scroll update complete ??? (Not used in Ghox and V-Five)
105 
106 	80		Background scroll X (X flip on)
107 	81		Background scroll Y (Y flip on)
108 	82		Foreground scroll X (X flip on)
109 	83		Foreground scroll Y (Y flip on)
110 	84		Top (text) scroll X (X flip on)
111 	85		Top (text) scroll Y (Y flip on)
112 	86		Sprites    scroll X (X flip on) ???
113 	87		Sprites    scroll Y (Y flip on) ???
114 	8F		Same as 0Fh except flip bit is active
115 
116 
117 Scroll Register 0E writes (Video controller inits ?) from different games:
118 
119 Teki-Paki		 | Ghox				| Knuckle Bash	   | Tatsujin 2		  |
120 0003, 0002, 4000 | ????, ????, ???? | 0202, 0203, 4200 | 0003, 0002, 4000 |
121 
122 Dogyuun			 | Batsugun			|
123 0202, 0203, 4200 | 0202, 0203, 4200 |
124 1202, 1203, 5200 | 1202, 1203, 5200 | <--- Second video controller ???
125 
126 Pipi & Bibis	 | Fix Eight		| V-Five		   | Snow Bros. 2	  |
127 0003, 0002, 4000 | 0202, 0203, 4200 | 0202, 0203, 4200 | 0202, 0203, 4200 |
128 
129 ***************************************************************************/
130 
131 #include "driver.h"
132 #include "tilemap.h"
133 
134 
135 
136 #define TOAPLAN2_BG_VRAM_SIZE	0x1000	/* Background RAM size (in bytes) */
137 #define TOAPLAN2_FG_VRAM_SIZE	0x1000	/* Foreground RAM size (in bytes) */
138 #define TOAPLAN2_TOP_VRAM_SIZE	0x1000	/* Top Layer  RAM size (in bytes) */
139 #define TOAPLAN2_SPRITERAM_SIZE	0x0800	/* Sprite	  RAM size (in bytes) */
140 
141 #define TOAPLAN2_TEXT_VRAM_SIZE	0x4000	/* Text Layer RAM size (in bytes) */
142 
143 #define TOAPLAN2_SPRITE_FLIPX 0x1000	/* Sprite flip flags (for screen flip) */
144 #define TOAPLAN2_SPRITE_FLIPY 0x2000
145 
146 #define CPU_2_NONE		0x00
147 #define CPU_2_Z80		0x5a
148 #define CPU_2_HD647180	0xa5
149 #define CPU_2_Zx80		0xff
150 
151 
152 static unsigned char *bgvideoram[2];
153 static unsigned char *fgvideoram[2];
154 static unsigned char *topvideoram[2];
155 static unsigned char *spriteram_now[2];	 /* Sprites to draw this frame */
156 static unsigned char *spriteram_next[2]; /* Sprites to draw next frame */
157 static unsigned char *spriteram_new[2];	 /* Sprites to add to next frame */
158 static int toaplan2_unk_vram;			 /* Video RAM tested but not used (for Teki Paki)*/
159 
160 static int toaplan2_scroll_reg[2];
161 static int toaplan2_voffs[2];
162 static int bg_offs[2];
163 static int fg_offs[2];
164 static int top_offs[2];
165 static int sprite_offs[2];
166 static int bg_scrollx[2];
167 static int bg_scrolly[2];
168 static int fg_scrollx[2];
169 static int fg_scrolly[2];
170 static int top_scrollx[2];
171 static int top_scrolly[2];
172 static int sprite_scrollx[2];
173 static int sprite_scrolly[2];
174 
175 static int display_sp[2] = { 1, 1 };
176 
177 static int sprite_priority[2][16];
178 static int bg_flip[2] = { 0, 0 };
179 static int fg_flip[2] = { 0, 0 };
180 static int top_flip[2] = { 0, 0 };
181 static int sprite_flip[2] = { 0, 0 };
182 
183 extern int toaplan2_sub_cpu;
184 
185 static struct tilemap *top_tilemap[2], *fg_tilemap[2], *bg_tilemap[2];
186 
187 /* Added by Yochizo 2000/08/19 */
188 unsigned char *textvideoram;			 /* Video ram for extra-text-layer */
189 static struct tilemap *text_tilemap;	 /* Tilemap for extra-text-layer */
190 
191 
192 /***************************************************************************
193 
194   Callbacks for the TileMap code
195 
196 ***************************************************************************/
197 
get_top0_tile_info(int tile_index)198 static void get_top0_tile_info(int tile_index)
199 {
200 	int color, tile_number, attrib;
201 	UINT16 *source = (UINT16 *)(topvideoram[0]);
202 
203 	attrib = source[2*tile_index];
204 	tile_number = source[2*tile_index+1];
205 	color = attrib & 0x7f;
206 	SET_TILE_INFO(0,tile_number,color)
207 	tile_info.priority = (attrib & 0x0f00) >> 8;
208 }
209 
get_fg0_tile_info(int tile_index)210 static void get_fg0_tile_info(int tile_index)
211 {
212 	int color, tile_number, attrib;
213 	UINT16 *source = (UINT16 *)(fgvideoram[0]);
214 
215 	attrib = source[2*tile_index];
216 	tile_number = source[2*tile_index+1];
217 	color = attrib & 0x7f;
218 	SET_TILE_INFO(0,tile_number,color)
219 	tile_info.priority = (attrib & 0x0f00) >> 8;
220 }
221 
get_bg0_tile_info(int tile_index)222 static void get_bg0_tile_info(int tile_index)
223 {
224 	int color, tile_number, attrib;
225 	UINT16 *source = (UINT16 *)(bgvideoram[0]);
226 
227 	attrib = source[2*tile_index];
228 	tile_number = source[2*tile_index+1];
229 	color = attrib & 0x7f;
230 	SET_TILE_INFO(0,tile_number,color)
231 	tile_info.priority = (attrib & 0x0f00) >> 8;
232 }
233 
get_top1_tile_info(int tile_index)234 static void get_top1_tile_info(int tile_index)
235 {
236 	int color, tile_number, attrib;
237 	UINT16 *source = (UINT16 *)(topvideoram[1]);
238 
239 	attrib = source[2*tile_index];
240 	tile_number = source[2*tile_index+1];
241 	color = attrib & 0x7f;
242 	SET_TILE_INFO(2,tile_number,color)
243 	tile_info.priority = (attrib & 0x0f00) >> 8;
244 }
245 
get_fg1_tile_info(int tile_index)246 static void get_fg1_tile_info(int tile_index)
247 {
248 	int color, tile_number, attrib;
249 	UINT16 *source = (UINT16 *)(fgvideoram[1]);
250 
251 	attrib = source[2*tile_index];
252 	tile_number = source[2*tile_index+1];
253 	color = attrib & 0x7f;
254 	SET_TILE_INFO(2,tile_number,color)
255 	tile_info.priority = (attrib & 0x0f00) >> 8;
256 }
257 
get_bg1_tile_info(int tile_index)258 static void get_bg1_tile_info(int tile_index)
259 {
260 	int color, tile_number, attrib;
261 	UINT16 *source = (UINT16 *)(bgvideoram[1]);
262 
263 	attrib = source[2*tile_index];
264 	tile_number = source[2*tile_index+1];
265 	color = attrib & 0x7f;
266 	SET_TILE_INFO(2,tile_number,color)
267 	tile_info.priority = (attrib & 0x0f00) >> 8;
268 }
269 
270 /* Added by Yochizo 2000/08/19 */
get_text_tile_info(int tile_index)271 static void get_text_tile_info(int tile_index)
272 {
273 	int color, tile_number, attrib;
274 	UINT16 *source = (UINT16 *)textvideoram;
275 
276 	attrib = source[tile_index];
277 	tile_number = attrib & 0x3ff;
278 	color = ((attrib >> 10) | 0x40) & 0x7f;
279 	SET_TILE_INFO(2,tile_number,color)
280 	tile_info.priority = 0;
281 }
282 
283 /***************************************************************************
284 
285   Start the video hardware emulation.
286 
287 ***************************************************************************/
toaplan2_vh_stop(int controller)288 static void toaplan2_vh_stop(int controller)
289 {
290 	free(     bgvideoram[controller] );
291 	free(     fgvideoram[controller] );
292 	free(    topvideoram[controller] );
293 	free(  spriteram_now[controller] );
294 	free( spriteram_next[controller] );
295 	free(  spriteram_new[controller] );
296 }
toaplan2_0_vh_stop(void)297 void toaplan2_0_vh_stop(void)
298 {
299 	toaplan2_vh_stop(0);
300 }
toaplan2_1_vh_stop(void)301 void toaplan2_1_vh_stop(void)
302 {
303 	toaplan2_vh_stop(1);
304 	toaplan2_vh_stop(0);
305 }
306 
307 
create_tilemaps_0(void)308 static int create_tilemaps_0(void)
309 {
310 	top_tilemap[0] = tilemap_create(get_top0_tile_info,tilemap_scan_rows,TILEMAP_TRANSPARENT,16,16,32,32);
311 	fg_tilemap[0] = tilemap_create(get_fg0_tile_info,tilemap_scan_rows,TILEMAP_TRANSPARENT,16,16,32,32);
312 	bg_tilemap[0] = tilemap_create(get_bg0_tile_info,tilemap_scan_rows,TILEMAP_TRANSPARENT,16,16,32,32);
313 
314 	if (!top_tilemap[0] || !fg_tilemap[0] || !bg_tilemap[0])
315 		return 1;
316 
317 	top_tilemap[0]->transparent_pen = 0;
318 	fg_tilemap[0]->transparent_pen = 0;
319 	bg_tilemap[0]->transparent_pen = 0;
320 
321 	return 0;
322 }
create_tilemaps_1(void)323 static int create_tilemaps_1(void)
324 {
325 	top_tilemap[1] = tilemap_create(get_top1_tile_info,tilemap_scan_rows,TILEMAP_TRANSPARENT,16,16,32,32);
326 	fg_tilemap[1] = tilemap_create(get_fg1_tile_info,tilemap_scan_rows,TILEMAP_TRANSPARENT,16,16,32,32);
327 	bg_tilemap[1] = tilemap_create(get_bg1_tile_info,tilemap_scan_rows,TILEMAP_TRANSPARENT,16,16,32,32);
328 
329 	if (!top_tilemap[1] || !fg_tilemap[1] || !bg_tilemap[1])
330 		return 1;
331 
332 	top_tilemap[1]->transparent_pen = 0;
333 	fg_tilemap[1]->transparent_pen = 0;
334 	bg_tilemap[1]->transparent_pen = 0;
335 
336 	return 0;
337 }
338 
toaplan2_vh_start(int controller)339 static int toaplan2_vh_start(int controller)
340 {
341 	static int error_level = 0;
342 	if ((spriteram_new[controller] = (unsigned char*)malloc(TOAPLAN2_SPRITERAM_SIZE)) == 0)
343 	{
344 		return 1;
345 	}
346 	memset(spriteram_new[controller],0,TOAPLAN2_SPRITERAM_SIZE);
347 
348 	if ((spriteram_next[controller] = (unsigned char*)malloc(TOAPLAN2_SPRITERAM_SIZE)) == 0)
349 	{
350 		free( spriteram_new[controller] );
351 		return 1;
352 	}
353 	memset(spriteram_next[controller],0,TOAPLAN2_SPRITERAM_SIZE);
354 
355 	if ((spriteram_now[controller] = (unsigned char*)malloc(TOAPLAN2_SPRITERAM_SIZE)) == 0)
356 	{
357 		free( spriteram_next[controller] );
358 		free(  spriteram_new[controller] );
359 		return 1;
360 	}
361 	memset(spriteram_now[controller],0,TOAPLAN2_SPRITERAM_SIZE);
362 
363 	if ((topvideoram[controller] = (unsigned char*)malloc(TOAPLAN2_TOP_VRAM_SIZE)) == 0)
364 	{
365 		free(  spriteram_now[controller] );
366 		free( spriteram_next[controller] );
367 		free(  spriteram_new[controller] );
368 		return 1;
369 	}
370 	memset(topvideoram[controller],0,TOAPLAN2_TOP_VRAM_SIZE);
371 
372 	if ((fgvideoram[controller] = (unsigned char*)malloc(TOAPLAN2_FG_VRAM_SIZE)) == 0)
373 	{
374 		free(    topvideoram[controller] );
375 		free(  spriteram_now[controller] );
376 		free( spriteram_next[controller] );
377 		free(  spriteram_new[controller] );
378 		return 1;
379 	}
380 	memset(fgvideoram[controller],0,TOAPLAN2_FG_VRAM_SIZE);
381 
382 	if ((bgvideoram[controller] = (unsigned char*)malloc(TOAPLAN2_BG_VRAM_SIZE)) == 0)
383 	{
384 		free(     fgvideoram[controller] );
385 		free(    topvideoram[controller] );
386 		free(  spriteram_now[controller] );
387 		free( spriteram_next[controller] );
388 		free(  spriteram_new[controller] );
389 		return 1;
390 	}
391 	memset(bgvideoram[controller],0,TOAPLAN2_BG_VRAM_SIZE);
392 
393 	if (controller == 0)
394 	{
395 		error_level |= create_tilemaps_0();
396 	}
397 	if (controller == 1)
398 	{
399 		error_level |= create_tilemaps_1();
400 	}
401 	return error_level;
402 }
toaplan2_0_vh_start(void)403 int toaplan2_0_vh_start(void)
404 {
405 	return toaplan2_vh_start(0);
406 }
toaplan2_1_vh_start(void)407 int toaplan2_1_vh_start(void)
408 {
409 	int error_level = 0;
410 	error_level |= toaplan2_vh_start(0);
411 	error_level |= toaplan2_vh_start(1);
412 	return error_level;
413 }
414 /* Added by Yochizo 2000/08/19 */
raizing_0_vh_start(void)415 int raizing_0_vh_start(void)
416 {
417 	if (toaplan2_vh_start(0))
418 		return 1;
419 	memset(textvideoram,0,TOAPLAN2_TEXT_VRAM_SIZE);
420 	text_tilemap = tilemap_create(get_text_tile_info,tilemap_scan_rows,TILEMAP_TRANSPARENT,8,8,64,64);
421 	if (!text_tilemap)
422 		return 1;
423 	text_tilemap->transparent_pen = 0;
424 	return 0;
425 }
raizing_1_vh_start(void)426 int raizing_1_vh_start(void)
427 {
428 	int error_level = 0;
429 	error_level |= toaplan2_vh_start(0);
430 	error_level |= toaplan2_vh_start(1);
431 	if (error_level)
432 		return 1;
433 	memset(textvideoram,0,TOAPLAN2_TEXT_VRAM_SIZE);
434 	text_tilemap = tilemap_create(get_text_tile_info,tilemap_scan_rows,TILEMAP_TRANSPARENT,8,8,64,64);
435 	if (!text_tilemap)
436 		return 1;
437 	text_tilemap->transparent_pen = 0;
438 	return 0;
439 }
440 
441 
442 
443 /***************************************************************************
444 
445   Video I/O port hardware.
446 
447 ***************************************************************************/
448 
toaplan2_voffs_w(int offset,int data,int controller)449 void toaplan2_voffs_w(int offset, int data, int controller)
450 {
451 	toaplan2_voffs[controller] = data;
452 
453 	/* Layers are seperated by ranges in the offset */
454 	switch (data & 0xfc00)
455 	{
456 		case 0x0400:
457 		case 0x0000:	bg_offs[controller] = (data & 0x7ff) * 2; break;
458 		case 0x0c00:
459 		case 0x0800:	fg_offs[controller] = (data & 0x7ff) * 2; break;
460 		case 0x1400:
461 		case 0x1000:	top_offs[controller] = (data & 0x7ff) * 2; break;
462 		case 0x1800:	sprite_offs[controller] = (data & 0x3ff) * 2; break;
463 		default:		//logerror("Hmmm, unknown video controller %01x layer being selected (%08x)\n",controller,data);
464 						data &= 0x1800;
465 						if ((data & 0x1800) == 0x0000)
466 							bg_offs[controller] = (data & 0x7ff) * 2;
467 						if ((data & 0x1800) == 0x0800)
468 							fg_offs[controller] = (data & 0x7ff) * 2;
469 						if ((data & 0x1800) == 0x1000)
470 							top_offs[controller] = (data & 0x7ff) * 2;
471 						if ((data & 0x1800) == 0x1800)
472 							sprite_offs[controller] = (data & 0x3ff) * 2;
473 						break;
474 	}
475 }
WRITE_HANDLER(toaplan2_0_voffs_w)476 WRITE_HANDLER( toaplan2_0_voffs_w )
477 {
478 	toaplan2_voffs_w(offset, data, 0);
479 }
WRITE_HANDLER(toaplan2_1_voffs_w)480 WRITE_HANDLER( toaplan2_1_voffs_w )
481 {
482 	toaplan2_voffs_w(offset, data, 1);
483 }
484 /* Added by Yochizo 2000/08/19 */
READ_HANDLER(raizing_textram_r)485 READ_HANDLER( raizing_textram_r )
486 {
487 	return READ_WORD(&textvideoram[offset]);
488 }
WRITE_HANDLER(raizing_textram_w)489 WRITE_HANDLER( raizing_textram_w )
490 {
491 	int oldword;
492 	offset &= TOAPLAN2_TEXT_VRAM_SIZE - 1;
493 	oldword = READ_WORD(&textvideoram[offset]);
494 	if (oldword != data){
495 		WRITE_WORD(&textvideoram[offset], data);
496 		tilemap_mark_tile_dirty(text_tilemap,offset / 2);
497 //		tilemap_mark_all_tiles_dirty(text_tilemap);
498 	}
499 }
500 
toaplan2_videoram_r(int offset,int controller)501 int toaplan2_videoram_r(int offset, int controller)
502 {
503 	static int video_data = 0;
504 	int videoram_offset;
505 
506 	switch (toaplan2_voffs[controller] & 0xfc00)
507 	{
508 		case 0x0400:
509 		case 0x0000:
510 				videoram_offset = bg_offs[controller] & (TOAPLAN2_BG_VRAM_SIZE-1);
511 				video_data = READ_WORD (&bgvideoram[controller][videoram_offset]);
512 				bg_offs[controller] += 2;
513 				/*if (bg_offs[controller] > TOAPLAN2_BG_VRAM_SIZE)
514 				{
515 					logerror("Reading %04x from out of range BG Layer address (%08x)  Video controller %01x  !!!\n",video_data,bg_offs[controller],controller);
516 				}*/
517 				break;
518 		case 0x0c00:
519 		case 0x0800:
520 				videoram_offset = fg_offs[controller] & (TOAPLAN2_FG_VRAM_SIZE-1);
521 				video_data = READ_WORD (&fgvideoram[controller][videoram_offset]);
522 				fg_offs[controller] += 2;
523 				/*if (fg_offs[controller] > TOAPLAN2_FG_VRAM_SIZE)
524 				{
525 					logerror("Reading %04x from out of range FG Layer address (%08x)  Video controller %01x  !!!\n",video_data,fg_offs[controller],controller);
526 				}*/
527 				break;
528 		case 0x1400:
529 		case 0x1000:
530 				videoram_offset = top_offs[controller] & (TOAPLAN2_TOP_VRAM_SIZE-1);
531 				video_data = READ_WORD (&topvideoram[controller][videoram_offset]);
532 				top_offs[controller] += 2;
533 				/*if (top_offs[controller] > TOAPLAN2_TOP_VRAM_SIZE)
534 				{
535 					logerror("Reading %04x from out of range TOP Layer address (%08x)  Video controller %01x  !!!\n",video_data,top_offs[controller],controller);
536 				}*/
537 				break;
538 		case 0x1800:
539 				videoram_offset = sprite_offs[controller] & (TOAPLAN2_SPRITERAM_SIZE-1);
540 				video_data = READ_WORD (&spriteram_new[controller][videoram_offset]);
541 				sprite_offs[controller] += 2;
542 				/*if (sprite_offs[controller] > TOAPLAN2_SPRITERAM_SIZE)
543 				{
544 					logerror("Reading %04x from out of range Sprite address (%08x)  Video controller %01x  !!!\n",video_data,sprite_offs[controller],controller);
545 				}*/
546 				break;
547 		default:
548 				video_data = toaplan2_unk_vram;
549 				//logerror("Hmmm, reading %04x from unknown video layer (%08x)  Video controller %01x  !!!\n",video_data,toaplan2_voffs[controller],controller);
550 				break;
551 	}
552 	return video_data;
553 }
READ_HANDLER(toaplan2_0_videoram_r)554 READ_HANDLER( toaplan2_0_videoram_r )
555 {
556 	return toaplan2_videoram_r(offset, 0);
557 }
READ_HANDLER(toaplan2_1_videoram_r)558 READ_HANDLER( toaplan2_1_videoram_r )
559 {
560 	return toaplan2_videoram_r(offset, 1);
561 }
562 
toaplan2_videoram_w(int offset,int data,int controller)563 void toaplan2_videoram_w(int offset, int data, int controller)
564 {
565 	int oldword = 0;
566 	int videoram_offset;
567 	int dirty_cell;
568 
569 	switch (toaplan2_voffs[controller] & 0xfc00)
570 	{
571 		case 0x0400:
572 		case 0x0000:
573 				videoram_offset = bg_offs[controller] & (TOAPLAN2_BG_VRAM_SIZE-1);
574 				oldword = READ_WORD (&bgvideoram[controller][videoram_offset]);
575 				if (data != oldword)
576 				{
577 					WRITE_WORD (&bgvideoram[controller][videoram_offset],data);
578 					dirty_cell = (bg_offs[controller] & (TOAPLAN2_BG_VRAM_SIZE-3))/2;
579 					tilemap_mark_tile_dirty(bg_tilemap[controller],dirty_cell/2);
580 				}
581 				bg_offs[controller] += 2;
582 				/*if (bg_offs[controller] > TOAPLAN2_BG_VRAM_SIZE)
583 				{
584 					logerror("Writing %04x to out of range BG Layer address (%08x)  Video controller %01x  !!!\n",data,bg_offs[controller],controller);
585 				}*/
586 				break;
587 		case 0x0c00:
588 		case 0x0800:
589 				videoram_offset = fg_offs[controller] & (TOAPLAN2_FG_VRAM_SIZE-1);
590 				oldword = READ_WORD (&fgvideoram[controller][videoram_offset]);
591 				if (data != oldword)
592 				{
593 					WRITE_WORD (&fgvideoram[controller][videoram_offset],data);
594 					dirty_cell = (fg_offs[controller] & (TOAPLAN2_FG_VRAM_SIZE-3))/2;
595 					tilemap_mark_tile_dirty(fg_tilemap[controller],dirty_cell/2);
596 				}
597 				fg_offs[controller] += 2;
598 				/*if (fg_offs[controller] > TOAPLAN2_FG_VRAM_SIZE)
599 				{
600 					logerror("Writing %04x to out of range FG Layer address (%08x)  Video controller %01x  !!!\n",data,fg_offs[controller],controller);
601 				}*/
602 				break;
603 		case 0x1400:
604 		case 0x1000:
605 				videoram_offset = top_offs[controller] & (TOAPLAN2_TOP_VRAM_SIZE-1);
606 				oldword = READ_WORD (&topvideoram[controller][videoram_offset]);
607 				if (data != oldword)
608 				{
609 					WRITE_WORD (&topvideoram[controller][videoram_offset],data);
610 					dirty_cell = (top_offs[controller] & (TOAPLAN2_TOP_VRAM_SIZE-3))/2;
611 					tilemap_mark_tile_dirty(top_tilemap[controller],dirty_cell/2);
612 				}
613 				top_offs[controller] += 2;
614 				/*if (top_offs[controller] > TOAPLAN2_TOP_VRAM_SIZE)
615 				{
616 					logerror("Writing %04x to out of range TOP Layer address (%08x)  Video controller %01x  !!!\n",data,top_offs[controller],controller);
617 				}*/
618 				break;
619 		case 0x1800:
620 				videoram_offset = sprite_offs[controller] & (TOAPLAN2_SPRITERAM_SIZE-1);
621 				WRITE_WORD (&spriteram_new[controller][videoram_offset],data);
622 				sprite_offs[controller] += 2;
623 				/*if (sprite_offs[controller] > TOAPLAN2_SPRITERAM_SIZE)
624 				{
625 					logerror("Writing %04x to out of range Sprite address (%08x)  Video controller %01x  !!!\n",data,sprite_offs[controller],controller);
626 				}*/
627 				break;
628 		default:
629 				toaplan2_unk_vram = data;
630 				//logerror("Hmmm, writing %04x to unknown video layer (%08x)  Video controller %01x  \n",toaplan2_unk_vram,toaplan2_voffs[controller],controller);
631 				break;
632 	}
633 }
WRITE_HANDLER(toaplan2_0_videoram_w)634 WRITE_HANDLER( toaplan2_0_videoram_w )
635 {
636 	toaplan2_videoram_w(offset, data, 0);
637 }
WRITE_HANDLER(toaplan2_1_videoram_w)638 WRITE_HANDLER( toaplan2_1_videoram_w )
639 {
640 	toaplan2_videoram_w(offset, data, 1);
641 }
642 
643 
toaplan2_scroll_reg_select_w(int offset,int data,int controller)644 void toaplan2_scroll_reg_select_w(int offset, int data, int controller)
645 {
646 	toaplan2_scroll_reg[controller] = data;
647 	/*if (toaplan2_scroll_reg[controller] & 0xffffff70)
648 	{
649 		logerror("Hmmm, unknown video control register selected (%08x)  Video controller %01x  \n",toaplan2_scroll_reg[controller],controller);
650 	}*/
651 }
WRITE_HANDLER(toaplan2_0_scroll_reg_select_w)652 WRITE_HANDLER( toaplan2_0_scroll_reg_select_w )
653 {
654 	toaplan2_scroll_reg_select_w(offset, data, 0);
655 }
WRITE_HANDLER(toaplan2_1_scroll_reg_select_w)656 WRITE_HANDLER( toaplan2_1_scroll_reg_select_w )
657 {
658 	toaplan2_scroll_reg_select_w(offset, data, 1);
659 }
660 
661 
toaplan2_scroll_reg_data_w(int offset,int data,int controller)662 void toaplan2_scroll_reg_data_w(int offset, int data, int controller)
663 {
664 	/************************************************************************/
665 	/***** X and Y layer flips can be set independantly, so emulate it ******/
666 	/************************************************************************/
667 
668 	switch(toaplan2_scroll_reg[controller])
669 	{
670 		case 0x00:	bg_scrollx[controller] = data - 0x1d6;			/* 1D6h */
671 					bg_flip[controller] &= (~TILEMAP_FLIPX);
672 					tilemap_set_flip(bg_tilemap[controller],bg_flip[controller]);
673 					tilemap_set_scrollx(bg_tilemap[controller],0,bg_scrollx[controller]);
674 					break;
675 		case 0x01:	bg_scrolly[controller] = data - 0x1ef;			/* 1EFh */
676 					bg_flip[controller] &= (~TILEMAP_FLIPY);
677 					tilemap_set_flip(bg_tilemap[controller],bg_flip[controller]);
678 					tilemap_set_scrolly(bg_tilemap[controller],0,bg_scrolly[controller]);
679 					break;
680 		case 0x02:	fg_scrollx[controller] = data - 0x1d8;			/* 1D0h */
681 					fg_flip[controller] &= (~TILEMAP_FLIPX);
682 					tilemap_set_flip(fg_tilemap[controller],fg_flip[controller]);
683 					tilemap_set_scrollx(fg_tilemap[controller],0,fg_scrollx[controller]);
684 					break;
685 		case 0x03:  fg_scrolly[controller] = data - 0x1ef;			/* 1EFh */
686 					fg_flip[controller] &= (~TILEMAP_FLIPY);
687 					tilemap_set_flip(fg_tilemap[controller],fg_flip[controller]);
688 					tilemap_set_scrolly(fg_tilemap[controller],0,fg_scrolly[controller]);
689 					break;
690 		case 0x04:	top_scrollx[controller] = data - 0x1da;			/* 1DAh */
691 					top_flip[controller] &= (~TILEMAP_FLIPX);
692 					tilemap_set_flip(top_tilemap[controller],top_flip[controller]);
693 					tilemap_set_scrollx(top_tilemap[controller],0,top_scrollx[controller]);
694 					break;
695 		case 0x05:	top_scrolly[controller] = data - 0x1ef;			/* 1EFh */
696 					top_flip[controller] &= (~TILEMAP_FLIPY);
697 					tilemap_set_flip(top_tilemap[controller],top_flip[controller]);
698 					tilemap_set_scrolly(top_tilemap[controller],0,top_scrolly[controller]);
699 					break;
700 		case 0x06:	sprite_scrollx[controller] = data - 0x1cc;		/* 1D4h */
701 					if (sprite_scrollx[controller] & 0x80000000) sprite_scrollx[controller] |= 0xfffffe00;
702 					else sprite_scrollx[controller] &= 0x1ff;
703 					sprite_flip[controller] &= (~TOAPLAN2_SPRITE_FLIPX);
704 					break;
705 		case 0x07:	sprite_scrolly[controller] = data - 0x1ef;		/* 1F7h */
706 					if (sprite_scrolly[controller] & 0x80000000) sprite_scrolly[controller] |= 0xfffffe00;
707 					else sprite_scrolly[controller] &= 0x1ff;
708 					sprite_flip[controller] &= (~TOAPLAN2_SPRITE_FLIPY);
709 					break;
710 		case 0x0f:	break;
711 		case 0x80:  bg_scrollx[controller] = data - 0x229;			/* 169h */
712 					bg_flip[controller] |= TILEMAP_FLIPX;
713 					tilemap_set_flip(bg_tilemap[controller],bg_flip[controller]);
714 					tilemap_set_scrollx(bg_tilemap[controller],0,bg_scrollx[controller]);
715 					break;
716 		case 0x81:	bg_scrolly[controller] = data - 0x210;			/* 100h */
717 					bg_flip[controller] |= TILEMAP_FLIPY;
718 					tilemap_set_flip(bg_tilemap[controller],bg_flip[controller]);
719 					tilemap_set_scrolly(bg_tilemap[controller],0,bg_scrolly[controller]);
720 					break;
721 		case 0x82:	fg_scrollx[controller] = data - 0x227;			/* 15Fh */
722 					fg_flip[controller] |= TILEMAP_FLIPX;
723 					tilemap_set_flip(fg_tilemap[controller],fg_flip[controller]);
724 					tilemap_set_scrollx(fg_tilemap[controller],0,fg_scrollx[controller]);
725 					break;
726 		case 0x83:	fg_scrolly[controller] = data - 0x210;			/* 100h */
727 					fg_flip[controller] |= TILEMAP_FLIPY;
728 					tilemap_set_flip(fg_tilemap[controller],fg_flip[controller]);
729 					tilemap_set_scrolly(fg_tilemap[controller],0,fg_scrolly[controller]);
730 					break;
731 		case 0x84:	top_scrollx[controller] = data - 0x225;			/* 165h */
732 					top_flip[controller] |= TILEMAP_FLIPX;
733 					tilemap_set_flip(top_tilemap[controller],top_flip[controller]);
734 					tilemap_set_scrollx(top_tilemap[controller],0,top_scrollx[controller]);
735 					break;
736 		case 0x85:	top_scrolly[controller] = data - 0x210;			/* 100h */
737 					top_flip[controller] |= TILEMAP_FLIPY;
738 					tilemap_set_flip(top_tilemap[controller],top_flip[controller]);
739 					tilemap_set_scrolly(top_tilemap[controller],0,top_scrolly[controller]);
740 					break;
741 		case 0x86:	sprite_scrollx[controller] = data - 0x17b;		/* 17Bh */
742 					if (sprite_scrollx[controller] & 0x80000000) sprite_scrollx[controller] |= 0xfffffe00;
743 					else sprite_scrollx[controller] &= 0x1ff;
744 					sprite_flip[controller] |= TOAPLAN2_SPRITE_FLIPX;
745 					break;
746 		case 0x87:	sprite_scrolly[controller] = data - 0x108;		/* 108h */
747 					if (sprite_scrolly[controller] & 0x80000000) sprite_scrolly[controller] |= 0xfffffe00;
748 					else sprite_scrolly[controller] &= 0x1ff;
749 					sprite_flip[controller] |= TOAPLAN2_SPRITE_FLIPY;
750 					break;
751 		case 0x8f:	break;
752 
753 		case 0x0e:	/******* Initialise video controller register ? *******/
754 					if ((toaplan2_sub_cpu == CPU_2_Z80) && (data == 3))
755 					{
756 						/* HACK! When tilted, sound CPU needs to be reset. */
757 						cpu_set_reset_line(1,PULSE_LINE);
758 						YM3812_sh_reset();
759 					}
760 		default:	//logerror("Hmmm, writing %08x to unknown video control register (%08x)  Video controller %01x  !!!\n",data ,toaplan2_scroll_reg[controller],controller);
761 					break;
762 	}
763 
764 }
WRITE_HANDLER(toaplan2_0_scroll_reg_data_w)765 WRITE_HANDLER( toaplan2_0_scroll_reg_data_w )
766 {
767 	toaplan2_scroll_reg_data_w(offset, data, 0);
768 }
WRITE_HANDLER(toaplan2_1_scroll_reg_data_w)769 WRITE_HANDLER( toaplan2_1_scroll_reg_data_w )
770 {
771 	toaplan2_scroll_reg_data_w(offset, data, 1);
772 }
773 
774 /*************** PIPIBIBI interface into this video driver *****************/
775 
WRITE_HANDLER(pipibibi_scroll_w)776 WRITE_HANDLER( pipibibi_scroll_w )
777 {
778 	int controller = 0;		/* only 1 video controller */
779 
780 	offset /= 2;
781 
782 	switch(offset)
783 	{
784 		case 0x00:	data -= 0x01f; break;
785 		case 0x01:	data += 0x1ef; break;
786 		case 0x02:	data -= 0x01d; break;
787 		case 0x03:	data += 0x1ef; break;
788 		case 0x04:	data -= 0x01b; break;
789 		case 0x05:	data += 0x1ef; break;
790 		case 0x06:	data += 0x1d4; break;
791 		case 0x07:	data += 0x1f7; break;
792 		default:	//logerror("PIPIBIBI writing %04x to unknown scroll register %04x",data, offset);
793 		    break;
794 	}
795 
796 	toaplan2_scroll_reg[controller] = offset;
797 	toaplan2_scroll_reg_data_w(0, data, controller);
798 }
799 
READ_HANDLER(pipibibi_videoram_r)800 READ_HANDLER( pipibibi_videoram_r )
801 {
802 	int controller = 0;		/* only 1 video controller */
803 
804 	offset /= 2;
805 	toaplan2_voffs_w(0, offset, controller);
806 	return toaplan2_videoram_r(0, controller);
807 }
808 
WRITE_HANDLER(pipibibi_videoram_w)809 WRITE_HANDLER( pipibibi_videoram_w)
810 {
811 	int controller = 0;		/* only 1 video controller */
812 
813 	offset /= 2;
814 	toaplan2_voffs_w(0, offset, controller);
815 	toaplan2_videoram_w(0, data, controller);
816 }
817 
READ_HANDLER(pipibibi_spriteram_r)818 READ_HANDLER( pipibibi_spriteram_r )
819 {
820 	int controller = 0;		/* only 1 video controller */
821 
822 	offset /= 2;
823     toaplan2_voffs_w(0, (0x1800 + offset), controller);
824 	return toaplan2_videoram_r(0, controller);
825 }
826 
WRITE_HANDLER(pipibibi_spriteram_w)827 WRITE_HANDLER( pipibibi_spriteram_w )
828 {
829 	int controller = 0;		/* only 1 video controller */
830 
831 	offset /= 2;
832 	toaplan2_voffs_w(0, (0x1800 + offset), controller);
833 	toaplan2_videoram_w(0, data, controller);
834 }
835 
836 
837 
838 /***************************************************************************
839 	Sprite Handlers
840 ***************************************************************************/
841 
mark_sprite_colors(int controller)842 static void mark_sprite_colors(int controller)
843 {
844 	int offs, attrib, sprite, color, i, pal_base;
845 	int sprite_sizex, sprite_sizey, temp_x, temp_y;
846 	int colmask[64];
847 
848 	UINT16 *source = (UINT16 *)(spriteram_now[controller]);
849 
850 	pal_base = Machine->drv->gfxdecodeinfo[ ((controller*2)+1) ].color_codes_start;
851 
852 	for(i=0; i < 64; i++) colmask[i] = 0;
853 
854 	for (offs = 0; offs < (TOAPLAN2_SPRITERAM_SIZE/2); offs += 4)
855 	{
856 		attrib = source[offs];
857 		sprite = source[offs + 1] | ((attrib & 3) << 16);
858 		sprite %= Machine->gfx[ ((controller*2)+1) ]->total_elements;
859 		if (attrib & 0x8000)
860 		{
861 			/* While we're here, mark all priorities used */
862 			sprite_priority[controller][((attrib & 0x0f00) >> 8)] = display_sp[controller];
863 
864 			color = (attrib >> 2) & 0x3f;
865 			sprite_sizex = (source[offs + 2] & 0x0f) + 1;
866 			sprite_sizey = (source[offs + 3] & 0x0f) + 1;
867 
868 			for (temp_y = 0; temp_y < sprite_sizey; temp_y++)
869 			{
870 				for (temp_x = 0; temp_x < sprite_sizex; temp_x++)
871 				{
872 					colmask[color] |= Machine->gfx[ ((controller*2)+1) ]->pen_usage[sprite];
873 					sprite++ ;
874 				}
875 			}
876 		}
877 	}
878 
879 	for (color = 0;color < 64;color++)
880 	{
881 		if ((color == 0) && (colmask[0] & 1))
882 			palette_used_colors[pal_base + 16 * color] = PALETTE_COLOR_TRANSPARENT;
883 		for (i = 1; i < 16; i++)
884 		{
885 			if (colmask[color] & (1 << i))
886 				palette_used_colors[pal_base + 16 * color + i] = PALETTE_COLOR_USED;
887 		}
888 	}
889 }
890 
891 
892 
draw_sprites(struct osd_bitmap * bitmap,int controller,int priority_to_display)893 static void draw_sprites( struct osd_bitmap *bitmap, int controller, int priority_to_display )
894 {
895 	const struct GfxElement *gfx = Machine->gfx[ ((controller*2)+1) ];
896 	const struct rectangle *clip = &Machine->visible_area;
897 
898 	UINT16 *source = (UINT16 *)(spriteram_now[controller]);
899 
900 	int offs;
901 	for (offs = 0; offs < (TOAPLAN2_SPRITERAM_SIZE/2); offs += 4)
902 	{
903 		int attrib, sprite, color, priority, flipx, flipy, sx, sy;
904 		int sprite_sizex, sprite_sizey, temp_x, temp_y, sx_base, sy_base;
905 
906 		attrib = source[offs];
907 		priority = (attrib & 0x0f00) >> 8;
908 
909 		if ((priority == priority_to_display) && (attrib & 0x8000))
910 		{
911 			sprite = ((attrib & 3) << 16) | source[offs + 1] ;	/* 18 bit */
912 			color = (attrib >> 2) & 0x3f;
913 
914 			/****** find out sprite size ******/
915 			sprite_sizex = ((source[offs + 2] & 0x0f) + 1) * 8;
916 			sprite_sizey = ((source[offs + 3] & 0x0f) + 1) * 8;
917 
918 			/****** find position to display sprite ******/
919 			sx_base = (source[offs + 2] >> 7) - sprite_scrollx[controller];
920 			sy_base = (source[offs + 3] >> 7) - sprite_scrolly[controller];
921 
922 			flipx = attrib & TOAPLAN2_SPRITE_FLIPX;
923 			flipy = attrib & TOAPLAN2_SPRITE_FLIPY;
924 
925 			if (flipx)
926 			{
927 				sx_base -= 7;
928 				/****** wrap around sprite position ******/
929 				if (sx_base >= 0x1c0) sx_base -= 0x200;
930 			}
931 			else
932 			{
933 				if (sx_base >= 0x180) sx_base -= 0x200;
934 			}
935 
936 			if (flipy)
937 			{
938 				sy_base -= 7;
939 				if (sy_base >= 0x1c0) sy_base -= 0x200;
940 			}
941 			else
942 			{
943 				if (sy_base >= 0x180) sy_base -= 0x200;
944 			}
945 
946 			/****** flip the sprite layer in any active X or Y flip ******/
947 			if (sprite_flip[controller])
948 			{
949 				if (sprite_flip[controller] & TOAPLAN2_SPRITE_FLIPX)
950 					sx_base = 320 - sx_base;
951 				if (sprite_flip[controller] & TOAPLAN2_SPRITE_FLIPY)
952 					sy_base = 240 - sy_base;
953 			}
954 
955 			/****** cancel flip, if it and sprite layer flip are active ******/
956 			flipx = (flipx ^ (sprite_flip[controller] & TOAPLAN2_SPRITE_FLIPX));
957 			flipy = (flipy ^ (sprite_flip[controller] & TOAPLAN2_SPRITE_FLIPY));
958 
959 			for (temp_y = 0; temp_y < sprite_sizey; temp_y += 8)
960 			{
961 				if (flipy) sy = sy_base - temp_y;
962 				else       sy = sy_base + temp_y;
963 				for (temp_x = 0; temp_x < sprite_sizex; temp_x += 8)
964 				{
965 					if (flipx) sx = sx_base - temp_x;
966 					else       sx = sx_base + temp_x;
967 
968 					drawgfx(bitmap,gfx,sprite,
969 						color,
970 						flipx,flipy,
971 						sx,sy,
972 						clip,TRANSPARENCY_PEN,0);
973 
974 					sprite++ ;
975 				}
976 			}
977 		}
978 	}
979 }
980 
981 /***************************************************************************
982 	Draw the game screen in the given osd_bitmap.
983 ***************************************************************************/
984 
toaplan2_0_vh_screenrefresh(struct osd_bitmap * bitmap,int full_refresh)985 void toaplan2_0_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
986 {
987 	int priority;
988 
989 	for (priority = 0; priority < 16; priority++)
990 		sprite_priority[0][priority] = 0;		/* Clear priorities used list */
991 
992 	tilemap_update(ALL_TILEMAPS);
993 
994 	palette_init_used_colors();
995 	mark_sprite_colors(0);	/* Also mark priorities used */
996 
997 	if (palette_recalc()) tilemap_mark_all_pixels_dirty(ALL_TILEMAPS);
998 
999 	tilemap_render(ALL_TILEMAPS);
1000 
1001 	fillbitmap(bitmap,palette_transparent_pen,&Machine->visible_area);
1002 
1003 	for (priority = 0; priority < 16; priority++)
1004 	{
1005 		tilemap_draw(bitmap,bg_tilemap[0],priority);
1006 		tilemap_draw(bitmap,fg_tilemap[0],priority);
1007 		tilemap_draw(bitmap,top_tilemap[0],priority);
1008 		if (sprite_priority[0][priority])
1009 			draw_sprites(bitmap,0,priority);
1010 	}
1011 }
toaplan2_1_vh_screenrefresh(struct osd_bitmap * bitmap,int full_refresh)1012 void toaplan2_1_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
1013 {
1014 	int priority;
1015 
1016 	for (priority = 0; priority < 16; priority++)
1017 	{
1018 		sprite_priority[0][priority] = 0;		/* Clear priorities used list */
1019 		sprite_priority[1][priority] = 0;		/* Clear priorities used list */
1020 	}
1021 
1022 	tilemap_update(ALL_TILEMAPS);
1023 
1024 	palette_init_used_colors();
1025 	mark_sprite_colors(0);	/* Also mark priorities used */
1026 	mark_sprite_colors(1);	/* Also mark priorities used */
1027 
1028 	if (palette_recalc()) tilemap_mark_all_pixels_dirty(ALL_TILEMAPS);
1029 
1030 	tilemap_render(ALL_TILEMAPS);
1031 
1032 	fillbitmap(bitmap,palette_transparent_pen,&Machine->visible_area);
1033 
1034 	for (priority = 0; priority < 16; priority++)
1035 	{
1036 		tilemap_draw(bitmap,bg_tilemap[1],priority);
1037 		tilemap_draw(bitmap,fg_tilemap[1],priority);
1038 		tilemap_draw(bitmap,top_tilemap[1],priority);
1039 		if (sprite_priority[1][priority])
1040 			draw_sprites(bitmap,1,priority);
1041 	}
1042 	for (priority = 0; priority < 16; priority++)
1043 	{
1044 		tilemap_draw(bitmap,bg_tilemap[0],priority);
1045 		tilemap_draw(bitmap,fg_tilemap[0],priority);
1046 		tilemap_draw(bitmap,top_tilemap[0],priority);
1047 		if (sprite_priority[0][priority])
1048 			draw_sprites(bitmap,0,priority);
1049 	}
1050 }
batsugun_1_vh_screenrefresh(struct osd_bitmap * bitmap,int full_refresh)1051 void batsugun_1_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
1052 {
1053 	int priority;
1054 
1055 	for (priority = 0; priority < 16; priority++)
1056 	{
1057 		sprite_priority[0][priority] = 0;		/* Clear priorities used list */
1058 		sprite_priority[1][priority] = 0;		/* Clear priorities used list */
1059 	}
1060 
1061 	tilemap_update(ALL_TILEMAPS);
1062 
1063 	palette_init_used_colors();
1064 	mark_sprite_colors(0);	/* Also mark priorities used */
1065 	mark_sprite_colors(1);	/* Also mark priorities used */
1066 
1067 	if (palette_recalc()) tilemap_mark_all_pixels_dirty(ALL_TILEMAPS);
1068 
1069 	tilemap_render(ALL_TILEMAPS);
1070 
1071 	fillbitmap(bitmap,palette_transparent_pen,&Machine->visible_area);
1072 
1073 	for (priority = 0; priority < 16; priority++)
1074 	{
1075 		tilemap_draw(bitmap,bg_tilemap[0],priority); /* 2 */
1076 		tilemap_draw(bitmap,bg_tilemap[1],priority);
1077 		tilemap_draw(bitmap,fg_tilemap[1],priority);
1078 		tilemap_draw(bitmap,top_tilemap[1],priority);
1079 		if (sprite_priority[1][priority])
1080 			draw_sprites(bitmap,1,priority);
1081 	}
1082 	for (priority = 0; priority < 16; priority++)
1083 	{
1084 		tilemap_draw(bitmap,fg_tilemap[0],priority);
1085 		tilemap_draw(bitmap,top_tilemap[0],priority);
1086 		if (sprite_priority[0][priority])
1087 			draw_sprites(bitmap,0,priority);
1088 	}
1089 }
1090 /* Added by Yochizo 2000/08/19 */
raizing_0_vh_screenrefresh(struct osd_bitmap * bitmap,int full_refresh)1091 void raizing_0_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
1092 {
1093 	toaplan2_0_vh_screenrefresh(bitmap, full_refresh);
1094 	tilemap_draw(bitmap,text_tilemap,0);
1095 }
raizing_1_vh_screenrefresh(struct osd_bitmap * bitmap,int full_refresh)1096 void raizing_1_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
1097 {
1098 	toaplan2_1_vh_screenrefresh(bitmap, full_refresh);
1099 	tilemap_draw(bitmap,text_tilemap,0);
1100 }
1101 
1102 
toaplan2_0_eof_callback(void)1103 void toaplan2_0_eof_callback(void)
1104 {
1105 	/** Shift sprite RAM buffers  ***  Used to fix sprite lag **/
1106 	memcpy(spriteram_now[0],spriteram_next[0],TOAPLAN2_SPRITERAM_SIZE);
1107 	memcpy(spriteram_next[0],spriteram_new[0],TOAPLAN2_SPRITERAM_SIZE);
1108 }
toaplan2_1_eof_callback(void)1109 void toaplan2_1_eof_callback(void)
1110 {
1111 	/** Shift sprite RAM buffers  ***  Used to fix sprite lag **/
1112 	memcpy(spriteram_now[0],spriteram_next[0],TOAPLAN2_SPRITERAM_SIZE);
1113 	memcpy(spriteram_next[0],spriteram_new[0],TOAPLAN2_SPRITERAM_SIZE);
1114 	memcpy(spriteram_now[1],spriteram_next[1],TOAPLAN2_SPRITERAM_SIZE);
1115 	memcpy(spriteram_next[1],spriteram_new[1],TOAPLAN2_SPRITERAM_SIZE);
1116 }
1117