1 #include "driver.h"
2 #include "vidhrdw/generic.h"
3 #include "vidhrdw/konamiic.h"
4 #include "crshrace.h"
5 
6 
7 data16_t *crshrace_videoram1,*crshrace_videoram2;
8 data16_t *crshrace_roz_ctrl1,*crshrace_roz_ctrl2;
9 
10 static int roz_bank,gfxctrl,flipscreen;
11 
12 static struct tilemap *tilemap1,*tilemap2;
13 
14 
15 
16 /***************************************************************************
17 
18   Callbacks for the TileMap code
19 
20 ***************************************************************************/
21 
get_tile_info1(int tile_index)22 static void get_tile_info1(int tile_index)
23 {
24 	int code = crshrace_videoram1[tile_index];
25 
26 	SET_TILE_INFO(1,(code & 0xfff) + (roz_bank << 12),code >> 12,0)
27 }
28 
get_tile_info2(int tile_index)29 static void get_tile_info2(int tile_index)
30 {
31 	int code = crshrace_videoram2[tile_index];
32 
33 	SET_TILE_INFO(0,code,0,0)
34 }
35 
36 
37 /***************************************************************************
38 
39   Start the video hardware emulation.
40 
41 ***************************************************************************/
42 
VIDEO_START(crshrace)43 VIDEO_START( crshrace )
44 {
45 	tilemap1 = tilemap_create(get_tile_info1,tilemap_scan_rows,TILEMAP_TRANSPARENT,16,16,64,64);
46 	tilemap2 = tilemap_create(get_tile_info2,tilemap_scan_rows,TILEMAP_TRANSPARENT, 8, 8,64,64);
47 
48 	if (!tilemap1 || !tilemap2)
49 		return 1;
50 
51 	K053936_wraparound_enable(0, 1);
52 	K053936_set_offset(0, -48, -21);
53 
54 	tilemap_set_transparent_pen(tilemap1,0x0f);
55 	tilemap_set_transparent_pen(tilemap2,0xff);
56 
57 	return 0;
58 }
59 
60 
61 /***************************************************************************
62 
63   Memory handlers
64 
65 ***************************************************************************/
66 
WRITE16_HANDLER(crshrace_videoram1_w)67 WRITE16_HANDLER( crshrace_videoram1_w )
68 {
69 	int oldword = crshrace_videoram1[offset];
70 	COMBINE_DATA(&crshrace_videoram1[offset]);
71 	if (oldword != crshrace_videoram1[offset])
72 		tilemap_mark_tile_dirty(tilemap1,offset);
73 }
74 
WRITE16_HANDLER(crshrace_videoram2_w)75 WRITE16_HANDLER( crshrace_videoram2_w )
76 {
77 	int oldword = crshrace_videoram2[offset];
78 	COMBINE_DATA(&crshrace_videoram2[offset]);
79 	if (oldword != crshrace_videoram2[offset])
80 		tilemap_mark_tile_dirty(tilemap2,offset);
81 }
82 
WRITE16_HANDLER(crshrace_roz_bank_w)83 WRITE16_HANDLER( crshrace_roz_bank_w )
84 {
85 	if (ACCESSING_LSB)
86 	{
87 		if (roz_bank != (data & 0xff))
88 		{
89 			roz_bank = data & 0xff;
90 			tilemap_mark_all_tiles_dirty(tilemap1);
91 		}
92 	}
93 }
94 
95 
WRITE16_HANDLER(crshrace_gfxctrl_w)96 WRITE16_HANDLER( crshrace_gfxctrl_w )
97 {
98 	if (ACCESSING_LSB)
99 	{
100 		gfxctrl = data & 0xdf;
101 		flipscreen = data & 0x20;
102 	}
103 }
104 
105 
106 /***************************************************************************
107 
108   Display refresh
109 
110 ***************************************************************************/
111 
draw_sprites(struct mame_bitmap * bitmap,const struct rectangle * cliprect)112 static void draw_sprites(struct mame_bitmap *bitmap,const struct rectangle *cliprect)
113 {
114 	int offs;
115 
116 
117 	offs = 0;
118 	while (offs < 0x0400 && (buffered_spriteram16[offs] & 0x4000) == 0)
119 	{
120 		int attr_start;
121 		int map_start;
122 		int ox,oy,x,y,xsize,ysize,zoomx,zoomy,flipx,flipy,color;
123 		/* table hand made by looking at the ship explosion in aerofgt attract mode */
124 		/* it's almost a logarithmic scale but not exactly */
125 		int zoomtable[16] = { 0,7,14,20,25,30,34,38,42,46,49,52,54,57,59,61 };
126 
127 		attr_start = 4 * (buffered_spriteram16[offs++] & 0x03ff);
128 
129 		ox = buffered_spriteram16[attr_start + 1] & 0x01ff;
130 		xsize = (buffered_spriteram16[attr_start + 1] & 0x0e00) >> 9;
131 		zoomx = (buffered_spriteram16[attr_start + 1] & 0xf000) >> 12;
132 		oy = buffered_spriteram16[attr_start + 0] & 0x01ff;
133 		ysize = (buffered_spriteram16[attr_start + 0] & 0x0e00) >> 9;
134 		zoomy = (buffered_spriteram16[attr_start + 0] & 0xf000) >> 12;
135 		flipx = buffered_spriteram16[attr_start + 2] & 0x4000;
136 		flipy = buffered_spriteram16[attr_start + 2] & 0x8000;
137 		color = (buffered_spriteram16[attr_start + 2] & 0x1f00) >> 8;
138 		map_start = buffered_spriteram16[attr_start + 3] & 0x7fff;
139 
140 		zoomx = 16 - zoomtable[zoomx]/8;
141 		zoomy = 16 - zoomtable[zoomy]/8;
142 
143 		if (buffered_spriteram16[attr_start + 2] & 0x20ff) color = rand();
144 
145 		for (y = 0;y <= ysize;y++)
146 		{
147 			int sx,sy;
148 
149 			if (flipy) sy = ((oy + zoomy * (ysize - y) + 16) & 0x1ff) - 16;
150 			else sy = ((oy + zoomy * y + 16) & 0x1ff) - 16;
151 
152 			for (x = 0;x <= xsize;x++)
153 			{
154 				int code;
155 
156 				if (flipx) sx = ((ox + zoomx * (xsize - x) + 16) & 0x1ff) - 16;
157 				else sx = ((ox + zoomx * x + 16) & 0x1ff) - 16;
158 
159 				code = buffered_spriteram16_2[map_start & 0x7fff];
160 				map_start++;
161 
162 				if (flipscreen)
163 					drawgfxzoom(bitmap,Machine->gfx[2],
164 							code,
165 							color,
166 							!flipx,!flipy,
167 							304-sx,208-sy,
168 							cliprect,TRANSPARENCY_PEN,15,
169 							0x1000 * zoomx,0x1000 * zoomy);
170 				else
171 					drawgfxzoom(bitmap,Machine->gfx[2],
172 							code,
173 							color,
174 							flipx,flipy,
175 							sx,sy,
176 							cliprect,TRANSPARENCY_PEN,15,
177 							0x1000 * zoomx,0x1000 * zoomy);
178 			}
179 		}
180 	}
181 }
182 
183 
draw_bg(struct mame_bitmap * bitmap,const struct rectangle * cliprect)184 static void draw_bg(struct mame_bitmap *bitmap,const struct rectangle *cliprect)
185 {
186 	tilemap_draw(bitmap,cliprect,tilemap2,0,0);
187 }
188 
189 
draw_fg(struct mame_bitmap * bitmap,const struct rectangle * cliprect)190 static void draw_fg(struct mame_bitmap *bitmap,const struct rectangle *cliprect)
191 {
192 	K053936_0_zoom_draw(bitmap,cliprect,tilemap1,0,0);
193 }
194 
195 
VIDEO_UPDATE(crshrace)196 VIDEO_UPDATE( crshrace )
197 {
198 	if (gfxctrl & 0x04)	/* display disable? */
199 	{
200 		fillbitmap(bitmap,get_black_pen(),cliprect);
201 		return;
202 	}
203 
204 	fillbitmap(bitmap,Machine->pens[0x1ff],cliprect);
205 
206 	switch (gfxctrl & 0xfb)
207 	{
208 		case 0x00:	/* high score screen */
209 			draw_sprites(bitmap,cliprect);
210 			draw_bg(bitmap,cliprect);
211 			draw_fg(bitmap,cliprect);
212 			break;
213 		case 0x01:
214 		case 0x02:
215 			draw_bg(bitmap,cliprect);
216 			draw_fg(bitmap,cliprect);
217 			draw_sprites(bitmap,cliprect);
218 			break;
219 		default:
220 usrintf_showmessage("gfxctrl = %02x",gfxctrl);
221 			break;
222 	}
223 }
224 
VIDEO_EOF(crshrace)225 VIDEO_EOF( crshrace )
226 {
227 	buffer_spriteram16_w(0,0,0);
228 	buffer_spriteram16_2_w(0,0,0);
229 }
230