1 /***************************************************************************
2 
3   vidhrdw.c
4 
5   Functions to emulate the video hardware of the machine.
6 
7 ***************************************************************************/
8 
9 #include "driver.h"
10 #include "vidhrdw/generic.h"
11 
12 static int gfx_bank;
13 
14 static struct tilemap *bg_tilemap;
15 
16 /***************************************************************************
17 
18   Convert the color PROMs into a more useable format.
19 
20 ***************************************************************************/
PALETTE_INIT(exctsccr)21 PALETTE_INIT( exctsccr )
22 {
23 	int i,idx;
24 	#define TOTAL_COLORS(gfxn) (Machine->gfx[gfxn]->total_colors * Machine->gfx[gfxn]->color_granularity)
25 	#define COLOR(gfxn,offs) (colortable[Machine->drv->gfxdecodeinfo[gfxn].color_codes_start + offs])
26 
27 	for (i = 0;i < Machine->drv->total_colors;i++)
28 	{
29 		int bit0,bit1,bit2,r,g,b;
30 
31 		bit0 = (color_prom[i] >> 0) & 0x01;
32 		bit1 = (color_prom[i] >> 1) & 0x01;
33 		bit2 = (color_prom[i] >> 2) & 0x01;
34 		r = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
35 		bit0 = (color_prom[i] >> 3) & 0x01;
36 		bit1 = (color_prom[i] >> 4) & 0x01;
37 		bit2 = (color_prom[i] >> 5) & 0x01;
38 		g = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
39 		bit0 = 0;
40 		bit1 = (color_prom[i] >> 6) & 0x01;
41 		bit2 = (color_prom[i] >> 7) & 0x01;
42 		b = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
43 
44 		palette_set_color(i,r,g,b);
45 	}
46 
47 	color_prom += Machine->drv->total_colors;
48 
49 	/* characters */
50 	idx = 0;
51 	for (i = 0;i < 32;i++)
52 	{
53 		COLOR(0,idx++) = color_prom[256+0+(i*4)];
54 		COLOR(0,idx++) = color_prom[256+1+(i*4)];
55 		COLOR(0,idx++) = color_prom[256+2+(i*4)];
56 		COLOR(0,idx++) = color_prom[256+3+(i*4)];
57 		COLOR(0,idx++) = color_prom[256+128+0+(i*4)];
58 		COLOR(0,idx++) = color_prom[256+128+1+(i*4)];
59 		COLOR(0,idx++) = color_prom[256+128+2+(i*4)];
60 		COLOR(0,idx++) = color_prom[256+128+3+(i*4)];
61 	}
62 
63 	/* sprites */
64 
65 	idx=0;
66 
67 	for (i = 0;i < 15*16;i++)
68 	{
69 		if ( (i%16) < 8 )
70 		{
71 			COLOR(2,idx) = color_prom[i]+16;
72 			idx++;
73 		}
74 	}
75 	for (i = 15*16;i < 16*16;i++)
76 	{
77 		if ( (i%16) > 7 )
78 		{
79 			COLOR(2,idx) = color_prom[i]+16;
80 			idx++;
81 		}
82 	}
83 	for (i = 16;i < 32;i++)
84 	{
85 		COLOR(2,idx++) = color_prom[256+0+(i*4)]+16;
86 		COLOR(2,idx++) = color_prom[256+1+(i*4)]+16;
87 		COLOR(2,idx++) = color_prom[256+2+(i*4)]+16;
88 		COLOR(2,idx++) = color_prom[256+3+(i*4)]+16;
89 		COLOR(2,idx++) = color_prom[256+128+0+(i*4)]+16;
90 		COLOR(2,idx++) = color_prom[256+128+1+(i*4)]+16;
91 		COLOR(2,idx++) = color_prom[256+128+2+(i*4)]+16;
92 		COLOR(2,idx++) = color_prom[256+128+3+(i*4)]+16;
93 	}
94 
95 	/* Patch for goalkeeper */
96 	COLOR(2,29*8+7) = 16;
97 
98 }
99 
exctsccr_fm_callback(int param)100 static void exctsccr_fm_callback( int param )
101 {
102 	cpu_set_irq_line_and_vector( 1, 0, HOLD_LINE, 0xff );
103 }
104 
WRITE_HANDLER(exctsccr_videoram_w)105 WRITE_HANDLER( exctsccr_videoram_w )
106 {
107 	if (videoram[offset] != data)
108 	{
109 		videoram[offset] = data;
110 		tilemap_mark_tile_dirty(bg_tilemap, offset);
111 	}
112 }
113 
WRITE_HANDLER(exctsccr_colorram_w)114 WRITE_HANDLER( exctsccr_colorram_w )
115 {
116 	if (colorram[offset] != data)
117 	{
118 		colorram[offset] = data;
119 		tilemap_mark_tile_dirty(bg_tilemap, offset);
120 	}
121 }
122 
WRITE_HANDLER(exctsccr_gfx_bank_w)123 WRITE_HANDLER( exctsccr_gfx_bank_w )
124 {
125 	if (gfx_bank != (data & 0x01))
126 	{
127 		gfx_bank = data & 0x01;
128 		tilemap_mark_all_tiles_dirty(ALL_TILEMAPS);
129 	}
130 }
131 
WRITE_HANDLER(exctsccr_flipscreen_w)132 WRITE_HANDLER( exctsccr_flipscreen_w )
133 {
134 	if (flip_screen != data)
135 	{
136 		flip_screen_set(data);
137 		tilemap_mark_all_tiles_dirty(ALL_TILEMAPS);
138 	}
139 }
140 
get_bg_tile_info(int tile_index)141 static void get_bg_tile_info(int tile_index)
142 {
143 	int code = videoram[tile_index];
144 	int color = colorram[tile_index] & 0x1f;
145 
146 	SET_TILE_INFO(gfx_bank, code, color, 0)
147 }
148 
VIDEO_START(exctsccr)149 VIDEO_START( exctsccr )
150 {
151 	bg_tilemap = tilemap_create(get_bg_tile_info, tilemap_scan_rows,
152 		TILEMAP_OPAQUE, 8, 8, 32, 32);
153 
154 	if ( !bg_tilemap )
155 		return 1;
156 
157 	timer_pulse( TIME_IN_HZ( 75.0 ), 0, exctsccr_fm_callback ); /* updates fm */
158 
159 	return 0;
160 }
161 
exctsccr_draw_sprites(struct mame_bitmap * bitmap)162 static void exctsccr_draw_sprites( struct mame_bitmap *bitmap ) {
163 	int offs;
164 	UINT8 *OBJ1, *OBJ2;
165 
166 	OBJ1 = videoram;
167 	OBJ2 = &(spriteram[0x20]);
168 
169 	for ( offs = 0x0e; offs >= 0; offs -= 2 ) {
170 		int sx,sy,code,bank,flipx,flipy,color;
171 
172 		sx = 256 - OBJ2[offs+1];
173 		sy = OBJ2[offs] - 16;
174 
175 		code = ( OBJ1[offs] >> 2 ) & 0x3f;
176 		flipx = ( OBJ1[offs] ) & 0x01;
177 		flipy = ( OBJ1[offs] ) & 0x02;
178 		color = ( OBJ1[offs+1] ) & 0x1f;
179 		bank = 2;
180 		bank += ( ( OBJ1[offs+1] >> 4 ) & 1 );
181 
182 		drawgfx(bitmap,Machine->gfx[bank],
183 				code,
184 				color,
185 				flipx, flipy,
186 				sx,sy,
187 				&Machine->visible_area,
188 				TRANSPARENCY_PEN,0);
189 	}
190 
191 	OBJ1 = &(memory_region(REGION_CPU1)[0x8800]);
192 	OBJ2 = spriteram;
193 
194 	for ( offs = 0x0e; offs >= 0; offs -= 2 ) {
195 		int sx,sy,code,bank,flipx,flipy,color;
196 
197 		sx = 256 - OBJ2[offs+1];
198 		sy = OBJ2[offs] - 16;
199 
200 		code = ( OBJ1[offs] >> 2 ) & 0x3f;
201 		flipx = ( OBJ1[offs] ) & 0x01;
202 		flipy = ( OBJ1[offs] ) & 0x02;
203 		color = ( OBJ1[offs+1] ) & 0x1f;
204 		bank = 3;
205 
206 		if ( color == 0 )
207 			continue;
208 
209 		if ( color < 0x10 )
210 			bank++;
211 
212 		if ( color > 0x10 && color < 0x17 )
213 		{
214 			drawgfx(bitmap,Machine->gfx[4],
215 				code,
216 				0x0e,
217 				flipx, flipy,
218 				sx,sy,
219 				&Machine->visible_area,
220 				TRANSPARENCY_PEN,0);
221 
222 			color += 6;
223 		}
224 		if ( color==0x1d && gfx_bank==1 )
225 		{
226 			drawgfx(bitmap,Machine->gfx[3],
227 				code,
228 				color,
229 				flipx, flipy,
230 				sx,sy,
231 				&Machine->visible_area,
232 				TRANSPARENCY_PEN,0);
233 			drawgfx(bitmap,Machine->gfx[4],
234 				code,
235 				color,
236 				flipx, flipy,
237 				sx,sy,
238 				&Machine->visible_area,
239 				TRANSPARENCY_COLOR, 16);
240 
241 		} else
242 		{
243 		drawgfx(bitmap,Machine->gfx[bank],
244 				code,
245 				color,
246 				flipx, flipy,
247 				sx,sy,
248 				&Machine->visible_area,
249 				TRANSPARENCY_PEN,0);
250 		}
251 	}
252 }
253 
VIDEO_UPDATE(exctsccr)254 VIDEO_UPDATE( exctsccr )
255 {
256 	tilemap_draw(bitmap, &Machine->visible_area, bg_tilemap, 0, 0);
257 	exctsccr_draw_sprites( bitmap );
258 }
259