1 /***************************************************************************
2
3 Videa Gridlee hardware
4
5 driver by Aaron Giles
6
7 Based on the Bally/Sente SAC system
8
9 ***************************************************************************/
10
11 #include "driver.h"
12 #include "vidhrdw/generic.h"
13
14
15 /*************************************
16 *
17 * Globals
18 *
19 *************************************/
20
21 UINT8 gridlee_cocktail_flip;
22
23
24
25 /*************************************
26 *
27 * Statics
28 *
29 *************************************/
30
31 static UINT8 *local_videoram;
32
33 static UINT8 palettebank_vis;
34
35
36
37 /*************************************
38 *
39 * Color PROM conversion
40 *
41 *************************************/
42
PALETTE_INIT(gridlee)43 PALETTE_INIT( gridlee )
44 {
45 int i;
46
47 for (i = 0; i < Machine->drv->total_colors; i++)
48 {
49 int r = color_prom[0x0000] | (color_prom[0x0000] << 4);
50 int g = color_prom[0x0800] | (color_prom[0x0800] << 4);
51 int b = color_prom[0x1000] | (color_prom[0x1000] << 4);
52 palette_set_color(i,r,g,b);
53 color_prom++;
54 }
55 }
56
57
58
59 /*************************************
60 *
61 * Video system start
62 *
63 *************************************/
64
VIDEO_START(gridlee)65 VIDEO_START( gridlee )
66 {
67 /* allocate a local copy of video RAM */
68 local_videoram = auto_malloc(256 * 256);
69 if (!local_videoram)
70 return 1;
71
72 /* reset the palette */
73 palettebank_vis = 0;
74 return 0;
75 }
76
77
78
79 /*************************************
80 *
81 * Cocktail flip
82 *
83 *************************************/
84
WRITE_HANDLER(gridlee_cocktail_flip_w)85 WRITE_HANDLER( gridlee_cocktail_flip_w )
86 {
87 if (gridlee_cocktail_flip != (data & 1))
88 {
89 force_partial_update(cpu_getscanline() - 1);
90 gridlee_cocktail_flip = data & 1;
91 }
92 }
93
94
95
96 /*************************************
97 *
98 * Video RAM write
99 *
100 *************************************/
101
WRITE_HANDLER(gridlee_videoram_w)102 WRITE_HANDLER( gridlee_videoram_w )
103 {
104 videoram[offset] = data;
105
106 /* expand the two pixel values into two bytes */
107 local_videoram[offset * 2 + 0] = data >> 4;
108 local_videoram[offset * 2 + 1] = data & 15;
109 }
110
111
112
113 /*************************************
114 *
115 * Palette banking
116 *
117 *************************************/
118
WRITE_HANDLER(gridlee_palette_select_w)119 WRITE_HANDLER( gridlee_palette_select_w )
120 {
121 /* update the scanline palette */
122 if (palettebank_vis != (data & 0x3f))
123 {
124 force_partial_update(cpu_getscanline() - 1);
125 palettebank_vis = data & 0x3f;
126 }
127 }
128
129
130
131 /*************************************
132 *
133 * Main screen refresh
134 *
135 *************************************/
136
VIDEO_UPDATE(gridlee)137 VIDEO_UPDATE( gridlee )
138 {
139 pen_t *pens = &Machine->pens[palettebank_vis * 32];
140 int x, y, i;
141
142 /* draw scanlines from the VRAM directly */
143 for (y = cliprect->min_y; y <= cliprect->max_y; y++)
144 {
145 /* non-flipped: draw directly from the bitmap */
146 if (!gridlee_cocktail_flip)
147 draw_scanline8(bitmap, 0, y, 256, &local_videoram[y * 256], pens + 16, -1);
148
149 /* flipped: x-flip the scanline into a temp buffer and draw that */
150 else
151 {
152 int srcy = 239 - y;
153 UINT8 temp[256];
154 int xx;
155
156 for (xx = 0; xx < 256; xx++)
157 temp[xx] = local_videoram[srcy * 256 + 255 - xx];
158 draw_scanline8(bitmap, 0, y, 256, temp, pens + 16, -1);
159 }
160 }
161
162 /* draw the sprite images */
163 for (i = 0; i < 32; i++)
164 {
165 UINT8 *sprite = spriteram + i * 4;
166 UINT8 *src;
167 int image = sprite[0];
168 int ypos = sprite[2] + 17;
169 int xpos = sprite[3];
170
171 /* get a pointer to the source image */
172 src = &memory_region(REGION_GFX1)[64 * image];
173
174 /* loop over y */
175 for (y = 0; y < 16; y++, ypos = (ypos + 1) & 255)
176 {
177 int currxor = 0;
178
179 /* adjust for flip */
180 if (gridlee_cocktail_flip)
181 {
182 ypos = 239 - ypos;
183 currxor = 0xff;
184 }
185
186 if (ypos >= 16 && ypos >= cliprect->min_y && ypos <= cliprect->max_y)
187 {
188 int currx = xpos;
189
190 /* loop over x */
191 for (x = 0; x < 4; x++)
192 {
193 int ipixel = *src++;
194 int left = ipixel >> 4;
195 int right = ipixel & 0x0f;
196
197 /* left pixel */
198 if (left && currx >= 0 && currx < 256)
199 plot_pixel(bitmap, currx ^ currxor, ypos, pens[left]);
200 currx++;
201
202 /* right pixel */
203 if (right && currx >= 0 && currx < 256)
204 plot_pixel(bitmap, currx ^ currxor, ypos, pens[right]);
205 currx++;
206 }
207 }
208 else
209 src += 4;
210
211 /* de-adjust for flip */
212 if (gridlee_cocktail_flip)
213 ypos = 239 - ypos;
214 }
215 }
216 }
217