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 UINT8 *zodiack_videoram2;
13 UINT8 *zodiack_attributesram;
14 UINT8 *zodiack_bulletsram;
15 size_t zodiack_bulletsram_size;
16
17 extern int percuss_hardware;
18
19 static struct tilemap *bg_tilemap, *fg_tilemap;
20
WRITE_HANDLER(zodiack_videoram_w)21 WRITE_HANDLER( zodiack_videoram_w )
22 {
23 if (videoram[offset] != data)
24 {
25 videoram[offset] = data;
26 tilemap_mark_tile_dirty(fg_tilemap, offset);
27 }
28 }
29
WRITE_HANDLER(zodiack_videoram2_w)30 WRITE_HANDLER( zodiack_videoram2_w )
31 {
32 if (zodiack_videoram2[offset] != data)
33 {
34 zodiack_videoram2[offset] = data;
35 tilemap_mark_tile_dirty(bg_tilemap, offset);
36 }
37 }
38
WRITE_HANDLER(zodiack_attributes_w)39 WRITE_HANDLER( zodiack_attributes_w )
40 {
41 if ((offset & 1) && zodiack_attributesram[offset] != data)
42 {
43 int i;
44
45 for (i = offset / 2;i < videoram_size; i += 32)
46 {
47 tilemap_mark_tile_dirty(bg_tilemap, i);
48 tilemap_mark_tile_dirty(fg_tilemap, i);
49 }
50 }
51
52 zodiack_attributesram[offset] = data;
53 }
54
WRITE_HANDLER(zodiack_flipscreen_w)55 WRITE_HANDLER( zodiack_flipscreen_w )
56 {
57 if (flip_screen != (~data & 0x01))
58 {
59 flip_screen_set(~data & 0x01);
60 tilemap_mark_all_tiles_dirty(ALL_TILEMAPS);
61 }
62 }
63
PALETTE_INIT(zodiack)64 PALETTE_INIT( zodiack )
65 {
66 int i;
67
68 #define TOTAL_COLORS(gfxn) (Machine->gfx[gfxn]->total_colors * Machine->gfx[gfxn]->color_granularity)
69 #define COLOR(gfxn,offs) (colortable[Machine->drv->gfxdecodeinfo[gfxn].color_codes_start + offs])
70
71 /* first, the character/sprite palette */
72 for (i = 0;i < Machine->drv->total_colors-1; i++)
73 {
74 int bit0,bit1,bit2,r,g,b;
75
76 /* red component */
77
78 bit0 = (*color_prom >> 0) & 0x01;
79 bit1 = (*color_prom >> 1) & 0x01;
80 bit2 = (*color_prom >> 2) & 0x01;
81
82 r = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
83
84 /* green component */
85
86 bit0 = (*color_prom >> 3) & 0x01;
87 bit1 = (*color_prom >> 4) & 0x01;
88 bit2 = (*color_prom >> 5) & 0x01;
89
90 g = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
91
92 /* blue component */
93
94 bit0 = 0;
95 bit1 = (*color_prom >> 6) & 0x01;
96 bit2 = (*color_prom >> 7) & 0x01;
97
98 b = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
99
100 palette_set_color(i,r,g,b);
101
102 color_prom++;
103 }
104
105 /* white for bullets */
106
107 palette_set_color(Machine->drv->total_colors-1,0xff,0xff,0xff);
108
109 for (i = 0;i < TOTAL_COLORS(0);i+=2)
110 {
111 COLOR(0,i ) = (32 + (i / 2));
112 COLOR(0,i+1) = (40 + (i / 2));
113 }
114
115 for (i = 0;i < TOTAL_COLORS(3);i++)
116 {
117 if ((i & 3) == 0) COLOR(3,i) = 0;
118 }
119
120 /* bullet */
121 COLOR(2, 0) = 0;
122 COLOR(2, 1) = 48;
123 }
124
get_bg_tile_info(int tile_index)125 static void get_bg_tile_info(int tile_index)
126 {
127 int code = zodiack_videoram2[tile_index];
128 int color = (zodiack_attributesram[2 * (tile_index % 32) + 1] >> 4) & 0x07;
129
130 SET_TILE_INFO(0, code, color, 0)
131 }
132
get_fg_tile_info(int tile_index)133 static void get_fg_tile_info(int tile_index)
134 {
135 int code = videoram[tile_index];
136 int color = zodiack_attributesram[2 * (tile_index % 32) + 1] & 0x07;
137
138 SET_TILE_INFO(3, code, color, 0)
139 }
140
VIDEO_START(zodiack)141 VIDEO_START( zodiack )
142 {
143 bg_tilemap = tilemap_create(get_bg_tile_info, tilemap_scan_rows,
144 TILEMAP_OPAQUE, 8, 8, 32, 32);
145
146 if ( !bg_tilemap )
147 return 1;
148
149 fg_tilemap = tilemap_create(get_fg_tile_info, tilemap_scan_rows,
150 TILEMAP_TRANSPARENT, 8, 8, 32, 32);
151
152 if ( !fg_tilemap )
153 return 1;
154
155 tilemap_set_transparent_pen(fg_tilemap, 0);
156 tilemap_set_scroll_cols(fg_tilemap, 32);
157
158 flip_screen = 0;
159
160 return 0;
161 }
162
zodiack_draw_bullets(struct mame_bitmap * bitmap)163 static void zodiack_draw_bullets( struct mame_bitmap *bitmap )
164 {
165 int offs;
166
167 for (offs = 0; offs < zodiack_bulletsram_size; offs += 4)
168 {
169 int x, y;
170
171 x = zodiack_bulletsram[offs + 3] + Machine->drv->gfxdecodeinfo[2].gfxlayout->width;
172 y = 255 - zodiack_bulletsram[offs + 1];
173
174 if (flip_screen && percuss_hardware)
175 {
176 y = 255 - y;
177 }
178
179 drawgfx(
180 bitmap,
181 Machine->gfx[2],
182 0, /* this is just a dot, generated by the hardware */
183 0,
184 0,0,
185 x,y,
186 &Machine->visible_area,TRANSPARENCY_PEN,0);
187 }
188 }
189
zodiack_draw_sprites(struct mame_bitmap * bitmap)190 static void zodiack_draw_sprites( struct mame_bitmap *bitmap )
191 {
192 int offs;
193
194 for (offs = spriteram_size - 4; offs >= 0; offs -= 4)
195 {
196 int flipx, flipy, sx, sy, spritecode;
197
198 sx = 240 - spriteram[offs + 3];
199 sy = 240 - spriteram[offs];
200 flipx = !(spriteram[offs + 1] & 0x40);
201 flipy = spriteram[offs + 1] & 0x80;
202 spritecode = spriteram[offs + 1] & 0x3f;
203
204 if (flip_screen && percuss_hardware)
205 {
206 sy = 240 - sy;
207 flipy = !flipy;
208 }
209
210 drawgfx(bitmap, Machine->gfx[1],
211 spritecode,
212 spriteram[offs + 2] & 0x07,
213 flipx, flipy,
214 sx, sy,
215 /*flip_screen[0] ? &spritevisibleareaflipx : &spritevisiblearea,TRANSPARENCY_PEN,0);*/
216 /*&spritevisiblearea,TRANSPARENCY_PEN,0);*/
217 &Machine->visible_area, TRANSPARENCY_PEN, 0);
218 }
219 }
220
VIDEO_UPDATE(zodiack)221 VIDEO_UPDATE( zodiack )
222 {
223 int i;
224
225 for (i = 0; i < 32; i++)
226 {
227 tilemap_set_scrolly(fg_tilemap, i, zodiack_attributesram[i * 2]);
228 }
229
230 tilemap_draw(bitmap, &Machine->visible_area, bg_tilemap, 0, 0);
231 tilemap_draw(bitmap, &Machine->visible_area, fg_tilemap, 0, 0);
232 zodiack_draw_bullets(bitmap);
233 zodiack_draw_sprites(bitmap);
234 }
235