1 /*
2 	Video Hardware for Shoot Out
3 	prom GB09.K6 may be related to background tile-sprite priority
4 */
5 
6 #include "driver.h"
7 #include "vidhrdw/generic.h"
8 
9 static struct tilemap *background, *foreground;
10 extern unsigned char *shootout_textram;
11 
12 
PALETTE_INIT(shootout)13 PALETTE_INIT( shootout )
14 {
15 	int i;
16 
17 
18 	for (i = 0;i < Machine->drv->total_colors;i++)
19 	{
20 		int bit0,bit1,bit2,r,g,b;
21 
22 		/* red component */
23 		bit0 = (color_prom[i] >> 0) & 0x01;
24 		bit1 = (color_prom[i] >> 1) & 0x01;
25 		bit2 = (color_prom[i] >> 2) & 0x01;
26 		r = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
27 		/* green component */
28 		bit0 = (color_prom[i] >> 3) & 0x01;
29 		bit1 = (color_prom[i] >> 4) & 0x01;
30 		bit2 = (color_prom[i] >> 5) & 0x01;
31 		g = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
32 		/* blue component */
33 		bit0 = 0;
34 		bit1 = (color_prom[i] >> 6) & 0x01;
35 		bit2 = (color_prom[i] >> 7) & 0x01;
36 		b = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
37 
38 		palette_set_color(i,r,g,b);
39 	}
40 }
41 
42 
43 
get_bg_tile_info(int tile_index)44 static void get_bg_tile_info(int tile_index){
45 	int attributes = videoram[tile_index+0x400]; /* CCCC -TTT */
46 	int tile_number = videoram[tile_index] + 256*(attributes&7);
47 	int color = attributes>>4;
48 	SET_TILE_INFO(
49 			2,
50 			tile_number,
51 			color,
52 			0)
53 }
54 
get_fg_tile_info(int tile_index)55 static void get_fg_tile_info(int tile_index){
56 	int attributes = shootout_textram[tile_index+0x400]; /* CCCC --TT */
57 	int tile_number = shootout_textram[tile_index] + 256*(attributes&0x3);
58 	int color = attributes>>4;
59 	SET_TILE_INFO(
60 			0,
61 			tile_number,
62 			color,
63 			0)
64 }
65 
WRITE_HANDLER(shootout_videoram_w)66 WRITE_HANDLER( shootout_videoram_w ){
67 	if( videoram[offset]!=data ){
68 		videoram[offset] = data;
69 		tilemap_mark_tile_dirty( background, offset&0x3ff );
70 	}
71 }
WRITE_HANDLER(shootout_textram_w)72 WRITE_HANDLER( shootout_textram_w ){
73 	if( shootout_textram[offset]!=data ){
74 		shootout_textram[offset] = data;
75 		tilemap_mark_tile_dirty( foreground, offset&0x3ff );
76 	}
77 }
78 
VIDEO_START(shootout)79 VIDEO_START( shootout ){
80 	background = tilemap_create(get_bg_tile_info,tilemap_scan_rows,TILEMAP_OPAQUE,8,8,32,32);
81 	foreground = tilemap_create(get_fg_tile_info,tilemap_scan_rows,TILEMAP_TRANSPARENT,8,8,32,32);
82 	if( background && foreground ){
83 		tilemap_set_transparent_pen( foreground, 0 );
84 		return 0;
85 	}
86 	return 1; /* error */
87 }
88 
draw_sprites(struct mame_bitmap * bitmap,const struct rectangle * cliprect,int bank_bits)89 static void draw_sprites( struct mame_bitmap *bitmap, const struct rectangle *cliprect, int bank_bits ){
90 	static int bFlicker;
91 	const struct GfxElement *gfx = Machine->gfx[1];
92 	const UINT8 *source = spriteram+127*4;
93 	int count;
94 
95 	bFlicker = !bFlicker;
96 
97 	for( count=0; count<128; count++ ){
98 		int attributes = source[1];
99 		/*
100 		    76543210
101 			xxx-----	bank
102 			---x----	vertical size
103 			----x---	priority
104 			-----x--	horizontal flip
105 			------x-	flicker
106 			-------x	enable
107 		*/
108 		if ( attributes & 0x01 ){ /* visible */
109 			if( bFlicker || (attributes&0x02)==0 ){
110 				int priority_mask = (attributes&0x08)?0x2:0;
111 				int sx = (240 - source[2])&0xff;
112 				int sy = (240 - source[0])&0xff;
113 				int vx, vy;
114 				int number = source[3] | ((attributes<<bank_bits)&0x700);
115 				int flipx = (attributes & 0x04);
116 				int flipy = 0;
117 
118 				if (flip_screen) {
119 					flipx = !flipx;
120 					flipy = !flipy;
121 				}
122 
123 				if( attributes & 0x10 ){ /* double height */
124 					number = number&(~1);
125 					sy -= 16;
126 
127 					vx = sx;
128 					vy = sy;
129 					if (flip_screen) {
130 						vx = 240 - vx;
131 						vy = 240 - vy;
132 					}
133 
134 					pdrawgfx(bitmap,gfx,
135 						number,
136 						0 /*color*/,
137 						flipx,flipy,
138 						vx,vy,
139 						cliprect,TRANSPARENCY_PEN,0,
140 						priority_mask);
141 
142 					number++;
143 					sy += 16;
144 				}
145 
146 				vx = sx;
147 				vy = sy;
148 				if (flip_screen) {
149 					vx = 240 - vx;
150 					vy = 240 - vy;
151 				}
152 
153 				pdrawgfx(bitmap,gfx,
154 						number,
155 						0 /*color*/,
156 						flipx,flipy,
157 						vx,vy,
158 						cliprect,TRANSPARENCY_PEN,0,
159 						priority_mask);
160 				}
161 		}
162 		source -= 4;
163 	}
164 }
165 
VIDEO_UPDATE(shootout)166 VIDEO_UPDATE( shootout )
167 {
168 	fillbitmap(priority_bitmap,0,cliprect);
169 
170 	tilemap_draw(bitmap,cliprect,background,0,0);
171 	tilemap_draw(bitmap,cliprect,foreground,0,1);
172 	draw_sprites(bitmap,cliprect,3/*bank bits */);
173 }
174 
VIDEO_UPDATE(shootouj)175 VIDEO_UPDATE( shootouj )
176 {
177 	fillbitmap(priority_bitmap,0,cliprect);
178 
179 	tilemap_draw(bitmap,cliprect,background,0,0);
180 	tilemap_draw(bitmap,cliprect,foreground,0,1);
181 	draw_sprites(bitmap,cliprect,2/*bank bits*/);
182 }
183