1 /***************************************************************************
2
3 stadhero video emulation - Bryan McPhail, mish@tendril.co.uk
4
5 *********************************************************************
6
7 MXC-06 chip to produce sprites, see dec0.c
8 BAC-06 chip for background?
9
10 ***************************************************************************/
11
12 #include "driver.h"
13 #include "vidhrdw/generic.h"
14
15 unsigned char *stadhero_pf1_data,*stadhero_pf2_data;
16 static unsigned char *stadhero_pf2_dirty;
17 static struct osd_bitmap *stadhero_pf2_bitmap;
18
19 static unsigned char stadhero_pf2_control_0[8];
20 static unsigned char stadhero_pf2_control_1[8];
21
22 /******************************************************************************/
23
stadhero_drawsprites(struct osd_bitmap * bitmap,int pri_mask,int pri_val)24 static void stadhero_drawsprites(struct osd_bitmap *bitmap,int pri_mask,int pri_val)
25 {
26 int offs;
27
28 for (offs = 0;offs < 0x800;offs += 8)
29 {
30 int x,y,sprite,colour,multi,fx,fy,inc,flash;
31
32 y = READ_WORD(&spriteram[offs]);
33 if ((y&0x8000) == 0) continue;
34
35 x = READ_WORD(&spriteram[offs+4]);
36 colour = x >> 12;
37 if ((colour & pri_mask) != pri_val) continue;
38
39 flash=x&0x800;
40 if (flash && (cpu_getcurrentframe() & 1)) continue;
41
42 fx = y & 0x2000;
43 fy = y & 0x4000;
44 multi = (1 << ((y & 0x1800) >> 11)) - 1; /* 1x, 2x, 4x, 8x height */
45 /* multi = 0 1 3 7 */
46
47 sprite = READ_WORD (&spriteram[offs+2]) & 0x0fff;
48
49 x = x & 0x01ff;
50 y = y & 0x01ff;
51 if (x >= 256) x -= 512;
52 if (y >= 256) y -= 512;
53 x = 240 - x;
54 y = 240 - y;
55
56 if (x>256) continue; /* Speedup */
57
58 sprite &= ~multi;
59 if (fy)
60 inc = -1;
61 else
62 {
63 sprite += multi;
64 inc = 1;
65 }
66
67 while (multi >= 0)
68 {
69 drawgfx(bitmap,Machine->gfx[2],
70 sprite - multi * inc,
71 colour,
72 fx,fy,
73 x,y - 16 * multi,
74 &Machine->visible_area,TRANSPARENCY_PEN,0);
75
76 multi--;
77 }
78 }
79 }
80
81 /******************************************************************************/
82
stadhero_pf2_update(void)83 static void stadhero_pf2_update(void)
84 {
85 int offs,mx,my,color,tile,quarter;
86 int offsetx[16],offsety[16];
87
88 offsetx[0]=0; offsety[0]=0;
89 offsetx[1]=0; offsety[1]=256;
90 offsetx[2]=0; offsety[2]=512;
91 offsetx[3]=0; offsety[3]=768;
92
93 offsetx[4]=256; offsety[4]=0;
94 offsetx[5]=256; offsety[5]=256;
95 offsetx[6]=256; offsety[6]=512;
96 offsetx[7]=256; offsety[7]=768;
97
98 offsetx[8]=512; offsety[8]=0;
99 offsetx[9]=512; offsety[9]=256;
100 offsetx[10]=512; offsety[10]=512;
101 offsetx[11]=512; offsety[11]=768;
102
103 offsetx[12]=768; offsety[12]=0;
104 offsetx[13]=768; offsety[13]=256;
105 offsetx[14]=768; offsety[14]=512;
106 offsetx[15]=768; offsety[15]=768;
107
108 for (quarter = 0;quarter < 16;quarter++)
109 {
110 mx = -1;
111 my = 0;
112
113 for (offs = 0x200 * quarter; offs < 0x200 * quarter + 0x200;offs += 2)
114 {
115 mx++;
116 if (mx == 16)
117 {
118 mx = 0;
119 my++;
120 }
121
122 if (stadhero_pf2_dirty[offs])
123 {
124 stadhero_pf2_dirty[offs] = 0;
125 tile = READ_WORD(&stadhero_pf2_data[offs]);
126 color = (tile & 0xf000) >> 12;
127
128 drawgfx(stadhero_pf2_bitmap,Machine->gfx[1],
129 tile & 0x0fff,
130 color,
131 0,0,
132 16*mx + offsetx[quarter],16*my + offsety[quarter],
133 0,TRANSPARENCY_NONE,0);
134 }
135 }
136 }
137 }
138
139 /******************************************************************************/
140
stadhero_pf2_draw(struct osd_bitmap * bitmap)141 void stadhero_pf2_draw(struct osd_bitmap *bitmap)
142 {
143 int scrolly,scrollx;
144
145 scrollx = - READ_WORD(&stadhero_pf2_control_1[0]);
146 scrolly = - READ_WORD(&stadhero_pf2_control_1[2]);
147
148 copyscrollbitmap(bitmap,stadhero_pf2_bitmap,1,&scrollx,1,&scrolly,&Machine->visible_area,TRANSPARENCY_NONE,0);
149 }
150
151 /******************************************************************************/
152
stadhero_vh_screenrefresh(struct osd_bitmap * bitmap,int full_refresh)153 void stadhero_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
154 {
155 int offs;
156 int color,code,i;
157 int colmask[16];
158 int pal_base;
159 int mx,my,tile;
160
161 palette_init_used_colors();
162
163 pal_base = Machine->drv->gfxdecodeinfo[0].color_codes_start;
164 for (color = 0;color < 16;color++) colmask[color] = 0;
165 for (offs = 0; offs < 0x800;offs += 2)
166 {
167 code = READ_WORD(&stadhero_pf1_data[offs]);
168 color = (code & 0xf000) >> 12;
169 code &= 0x0fff;
170 colmask[color] |= Machine->gfx[0]->pen_usage[code];
171 }
172
173 for (color = 0;color < 16;color++)
174 {
175 if (colmask[color] & (1 << 0))
176 palette_used_colors[pal_base + 8 * color] = PALETTE_COLOR_TRANSPARENT;
177 for (i = 1;i < 8;i++)
178 {
179 if (colmask[color] & (1 << i))
180 palette_used_colors[pal_base + 8 * color + i] = PALETTE_COLOR_USED;
181 }
182 }
183
184 pal_base = Machine->drv->gfxdecodeinfo[1].color_codes_start;
185 for (color = 0;color < 16;color++) colmask[color] = 0;
186 for (offs = 0; offs < 0x2000;offs += 2)
187 {
188 code = READ_WORD(&stadhero_pf2_data[offs]);
189 color = (code & 0xf000) >> 12;
190 code &= 0x0fff;
191 colmask[color] |= Machine->gfx[1]->pen_usage[code];
192 }
193
194 for (color = 0;color < 16;color++)
195 {
196 for (i = 0;i < 8;i++)
197 {
198 if (colmask[color] & (1 << i))
199 palette_used_colors[pal_base + 8 * color + i] = PALETTE_COLOR_USED;
200 }
201 }
202
203 pal_base = Machine->drv->gfxdecodeinfo[2].color_codes_start;
204 for (color = 0;color < 16;color++) colmask[color] = 0;
205 for (offs = 0;offs < 0x800;offs += 8)
206 {
207 int x,y,sprite,multi;
208
209 y = READ_WORD(&spriteram[offs]);
210 if ((y&0x8000) == 0) continue;
211
212 x = READ_WORD(&spriteram[offs+4]);
213 color = (x & 0xf000) >> 12;
214
215 multi = (1 << ((y & 0x1800) >> 11)) - 1; /* 1x, 2x, 4x, 8x height */
216 /* multi = 0 1 3 7 */
217
218 sprite = READ_WORD (&spriteram[offs+2]) & 0x0fff;
219 sprite &= ~multi;
220
221 while (multi >= 0)
222 {
223 colmask[color] |= Machine->gfx[2]->pen_usage[sprite + multi];
224 multi--;
225 }
226 }
227
228 for (color = 0;color < 16;color++)
229 {
230 for (i = 1;i < 16;i++)
231 {
232 if (colmask[color] & (1 << i))
233 palette_used_colors[pal_base + 16 * color + i] = PALETTE_COLOR_USED;
234 }
235 }
236
237 if (palette_recalc())
238 {
239 memset(stadhero_pf2_dirty,1,0x2000);
240 }
241
242 stadhero_pf2_update();
243 stadhero_pf2_draw(bitmap);
244
245 stadhero_drawsprites(bitmap,0x00,0x00);
246
247 for (offs = 0x800 - 2;offs >= 0;offs -= 2)
248 {
249 tile=READ_WORD(&stadhero_pf1_data[offs]);
250
251 if (!tile) continue;
252
253 color=tile>>12;
254 mx = (offs/2) % 32;
255 my = (offs/2) / 32;
256
257 drawgfx(bitmap,Machine->gfx[0],
258 tile&0xfff,color,0,0,8*mx,8*my,
259 &Machine->visible_area,TRANSPARENCY_PEN,0);
260 }
261 }
262
263 /******************************************************************************/
264
WRITE_HANDLER(stadhero_pf1_data_w)265 WRITE_HANDLER( stadhero_pf1_data_w )
266 {
267 COMBINE_WORD_MEM(&stadhero_pf1_data[offset],data);
268 }
269
READ_HANDLER(stadhero_pf1_data_r)270 READ_HANDLER( stadhero_pf1_data_r )
271 {
272 return READ_WORD(&stadhero_pf1_data[offset]);
273 }
274
WRITE_HANDLER(stadhero_pf2_control_0_w)275 WRITE_HANDLER( stadhero_pf2_control_0_w )
276 {
277 COMBINE_WORD_MEM(&stadhero_pf2_control_0[offset],data);
278 }
279
WRITE_HANDLER(stadhero_pf2_control_1_w)280 WRITE_HANDLER( stadhero_pf2_control_1_w )
281 {
282 COMBINE_WORD_MEM(&stadhero_pf2_control_1[offset],data);
283 }
284
WRITE_HANDLER(stadhero_pf2_data_w)285 WRITE_HANDLER( stadhero_pf2_data_w )
286 {
287 int oldword = READ_WORD(&stadhero_pf2_data[offset]);
288 int newword = COMBINE_WORD(oldword,data);
289
290 if (oldword != newword)
291 {
292 WRITE_WORD(&stadhero_pf2_data[offset],newword);
293 stadhero_pf2_dirty[offset] = 1;
294 }
295 }
296
READ_HANDLER(stadhero_pf2_data_r)297 READ_HANDLER( stadhero_pf2_data_r )
298 {
299 return READ_WORD(&stadhero_pf2_data[offset]);
300 }
301
302 /******************************************************************************/
303
stadhero_vh_stop(void)304 void stadhero_vh_stop (void)
305 {
306 bitmap_free(stadhero_pf2_bitmap);
307 free(stadhero_pf2_dirty);
308 }
309
stadhero_vh_start(void)310 int stadhero_vh_start (void)
311 {
312 if ((stadhero_pf2_bitmap = bitmap_alloc(1024,1024)) == 0) {
313 stadhero_vh_stop ();
314 return 1;
315 }
316
317 stadhero_pf2_dirty = (unsigned char*)malloc(0x2000);
318 memset(stadhero_pf2_dirty,1,0x2000);
319 return 0;
320 }
321
322 /******************************************************************************/
323