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
13
14 unsigned char *finalizr_scroll;
15 unsigned char *finalizr_videoram2,*finalizr_colorram2;
16 static int spriterambank,charbank;
17
18
19
PALETTE_INIT(finalizr)20 PALETTE_INIT( finalizr )
21 {
22 int i;
23 #define TOTAL_COLORS(gfxn) (Machine->gfx[gfxn]->total_colors * Machine->gfx[gfxn]->color_granularity)
24 #define COLOR(gfxn,offs) (colortable[Machine->drv->gfxdecodeinfo[gfxn].color_codes_start + offs])
25
26
27 for (i = 0;i < Machine->drv->total_colors;i++)
28 {
29 int bit0,bit1,bit2,bit3,r,g,b;
30
31
32 /* red component */
33 bit0 = (color_prom[0] >> 0) & 0x01;
34 bit1 = (color_prom[0] >> 1) & 0x01;
35 bit2 = (color_prom[0] >> 2) & 0x01;
36 bit3 = (color_prom[0] >> 3) & 0x01;
37 r = 0x0e * bit0 + 0x1f * bit1 + 0x43 * bit2 + 0x8f * bit3;
38 /* green component */
39 bit0 = (color_prom[0] >> 4) & 0x01;
40 bit1 = (color_prom[0] >> 5) & 0x01;
41 bit2 = (color_prom[0] >> 6) & 0x01;
42 bit3 = (color_prom[0] >> 7) & 0x01;
43 g = 0x0e * bit0 + 0x1f * bit1 + 0x43 * bit2 + 0x8f * bit3;
44 /* blue component */
45 bit0 = (color_prom[Machine->drv->total_colors] >> 0) & 0x01;
46 bit1 = (color_prom[Machine->drv->total_colors] >> 1) & 0x01;
47 bit2 = (color_prom[Machine->drv->total_colors] >> 2) & 0x01;
48 bit3 = (color_prom[Machine->drv->total_colors] >> 3) & 0x01;
49 b = 0x0e * bit0 + 0x1f * bit1 + 0x43 * bit2 + 0x8f * bit3;
50
51 palette_set_color(i,r,g,b);
52 color_prom++;
53 }
54
55 color_prom += Machine->drv->total_colors;
56 /* color_prom now points to the beginning of the lookup tables */
57
58 for (i = 0;i < TOTAL_COLORS(1);i++)
59 {
60 if (*color_prom & 0x0f) COLOR(1,i) = *color_prom & 0x0f;
61 else COLOR(1,i) = 0;
62 color_prom++;
63 }
64 for (i = 0;i < TOTAL_COLORS(0);i++)
65 {
66 COLOR(0,i) = (*(color_prom++) & 0x0f) + 0x10;
67 }
68 }
69
VIDEO_START(finalizr)70 VIDEO_START( finalizr )
71 {
72 dirtybuffer = 0;
73 tmpbitmap = 0;
74
75 if ((dirtybuffer = auto_malloc(videoram_size)) == 0)
76 return 1;
77 memset(dirtybuffer,1,videoram_size);
78
79 if ((tmpbitmap = auto_bitmap_alloc(256,256)) == 0)
80 return 1;
81
82 return 0;
83 }
84
85
86
WRITE_HANDLER(finalizr_videoctrl_w)87 WRITE_HANDLER( finalizr_videoctrl_w )
88 {
89 if (charbank != (data & 3))
90 {
91 charbank = data & 3;
92 memset(dirtybuffer,1,videoram_size);
93 }
94
95 spriterambank = data & 8;
96
97 /* other bits unknown */
98 }
99
100
101
102 /***************************************************************************
103
104 Draw the game screen in the given mame_bitmap.
105 Do NOT call osd_update_display() from this function, it will be called by
106 the main emulation engine.
107
108 ***************************************************************************/
VIDEO_UPDATE(finalizr)109 VIDEO_UPDATE( finalizr )
110 {
111 int offs;
112
113
114 /* for every character in the Video RAM, check if it has been modified */
115 /* since last time and update it accordingly. */
116 for (offs = videoram_size - 1;offs >= 0;offs--)
117 {
118 if (dirtybuffer[offs])
119 {
120 int sx,sy;
121
122
123 dirtybuffer[offs] = 0;
124
125 sx = offs % 32;
126 sy = offs / 32;
127
128 drawgfx(tmpbitmap,Machine->gfx[0],
129 videoram[offs] + ((colorram[offs] & 0xc0) << 2) + (charbank<<10),
130 (colorram[offs] & 0x0f),
131 colorram[offs] & 0x10,colorram[offs] & 0x20,
132 8*sx,8*sy,
133 0,TRANSPARENCY_NONE,0);
134 }
135 }
136
137
138 /* copy the temporary bitmap to the screen */
139 {
140 int scroll;
141
142
143 scroll = -*finalizr_scroll + 16;
144
145 copyscrollbitmap(bitmap,tmpbitmap,1,&scroll,0,0,&Machine->visible_area,TRANSPARENCY_NONE,0);
146 }
147
148
149 /* Draw the sprites. */
150 {
151 unsigned char *sr;
152
153
154 if (spriterambank != 0)
155 sr = spriteram_2;
156 else sr = spriteram;
157
158 for (offs = 0;offs < spriteram_size;offs += 5)
159 {
160 int sx,sy,flipx,flipy,code,color;
161
162
163 sx = 16 + sr[offs+3] - ((sr[offs+4] & 0x01) << 8);
164 sy = sr[offs+2];
165 flipx = sr[offs+4] & 0x20;
166 flipy = sr[offs+4] & 0x40;
167 code = sr[offs] + ((sr[offs+1] & 0x0f) << 8);
168 color = ((sr[offs+1] & 0xf0)>>4);
169
170 /* (sr[offs+4] & 0x02) is used, meaning unknown*/
171
172 switch (sr[offs+4] & 0x1c)
173 {
174 case 0x10: /* 32x32? */
175 case 0x14: /* ? */
176 case 0x18: /* ? */
177 case 0x1c: /* ? */
178 drawgfx(bitmap,Machine->gfx[1],
179 code,
180 color,
181 flipx,flipy,
182 flipx?sx+16:sx,flipy?sy+16:sy,
183 &Machine->visible_area,TRANSPARENCY_PEN,0);
184 drawgfx(bitmap,Machine->gfx[1],
185 code + 1,
186 color,
187 flipx,flipy,
188 flipx?sx:sx+16,flipy?sy+16:sy,
189 &Machine->visible_area,TRANSPARENCY_PEN,0);
190 drawgfx(bitmap,Machine->gfx[1],
191 code + 2,
192 color,
193 flipx,flipy,
194 flipx?sx+16:sx,flipy?sy:sy+16,
195 &Machine->visible_area,TRANSPARENCY_PEN,0);
196 drawgfx(bitmap,Machine->gfx[1],
197 code + 3,
198 color,
199 flipx,flipy,
200 flipx?sx:sx+16,flipy?sy:sy+16,
201 &Machine->visible_area,TRANSPARENCY_PEN,0);
202 break;
203
204 case 0x00: /* 16x16 */
205 drawgfx(bitmap,Machine->gfx[1],
206 code,
207 color,
208 flipx,flipy,
209 sx,sy,
210 &Machine->visible_area,TRANSPARENCY_PEN,0);
211 break;
212
213 case 0x04: /* 16x8 */
214 code = ((code & 0x3ff) << 2) | ((code & 0xc00) >> 10);
215 drawgfx(bitmap,Machine->gfx[2],
216 code & ~1,
217 color,
218 flipx,flipy,
219 flipx?sx+8:sx,sy,
220 &Machine->visible_area,TRANSPARENCY_PEN,0);
221 drawgfx(bitmap,Machine->gfx[2],
222 code | 1,
223 color,
224 flipx,flipy,
225 flipx?sx:sx+8,sy,
226 &Machine->visible_area,TRANSPARENCY_PEN,0);
227 break;
228
229 case 0x08: /* 8x16 */
230 code = ((code & 0x3ff) << 2) | ((code & 0xc00) >> 10);
231 drawgfx(bitmap,Machine->gfx[2],
232 code & ~2,
233 color,
234 flipx,flipy,
235 sx,flipy?sy+8:sy,
236 &Machine->visible_area,TRANSPARENCY_PEN,0);
237 drawgfx(bitmap,Machine->gfx[2],
238 code | 2,
239 color,
240 flipx,flipy,
241 sx,flipy?sy:sy+8,
242 &Machine->visible_area,TRANSPARENCY_PEN,0);
243 break;
244
245 case 0x0c: /* 8x8 */
246 code = ((code & 0x3ff) << 2) | ((code & 0xc00) >> 10);
247 drawgfx(bitmap,Machine->gfx[2],
248 code,
249 color,
250 flipx,flipy,
251 sx,sy,
252 &Machine->visible_area,TRANSPARENCY_PEN,0);
253 break;
254 }
255 }
256 }
257
258 for (offs = videoram_size - 1;offs >= 0;offs--)
259 {
260 int sx,sy;
261
262
263 sx = offs % 32;
264 if (sx < 6)
265 {
266 if (sx >= 3) sx += 30;
267 sy = offs / 32;
268
269 drawgfx(bitmap,Machine->gfx[0],
270 finalizr_videoram2[offs] + ((finalizr_colorram2[offs] & 0xc0) << 2),
271 (finalizr_colorram2[offs] & 0x0f),
272 finalizr_colorram2[offs] & 0x10,finalizr_colorram2[offs] & 0x20,
273 8*sx,8*sy,
274 &Machine->visible_area,TRANSPARENCY_NONE,0);
275 }
276 }
277 }
278