1 /* vidhrdw/angelkds.c - see drivers/angelkds.c for more info */
2
3 /* graphical issues
4
5 enable / disable tilemap bits might be wrong
6
7 */
8
9 #include "driver.h"
10 #include "vidhrdw/generic.h"
11
12
13 static struct tilemap *tx_tilemap,*bgbot_tilemap ,*bgtop_tilemap;
14
15 data8_t *angelkds_txvideoram, *angelkds_bgbotvideoram, *angelkds_bgtopvideoram;
16
17 /*** Text Layer Tilemap
18
19 */
20
21 static int angelkds_txbank;
22
23
get_tx_tile_info(int tile_index)24 static void get_tx_tile_info(int tile_index)
25 {
26 int tileno;
27
28 tileno = angelkds_txvideoram[tile_index] + (angelkds_txbank * 0x100);
29
30 SET_TILE_INFO(0,tileno,0,0)
31 }
32
WRITE_HANDLER(angelkds_txvideoram_w)33 WRITE_HANDLER( angelkds_txvideoram_w )
34 {
35 if (angelkds_txvideoram[offset] != data)
36 {
37 angelkds_txvideoram[offset] = data;
38 tilemap_mark_tile_dirty(tx_tilemap,offset);
39 }
40 }
41
WRITE_HANDLER(angelkds_txbank_write)42 WRITE_HANDLER( angelkds_txbank_write )
43 {
44
45 if (angelkds_txbank != data)
46 {
47 angelkds_txbank = data;
48 tilemap_mark_all_tiles_dirty (tx_tilemap);
49 };
50
51 }
52
53 /*** Top Half Background Tilemap
54
55 */
56
57 static int angelkds_bgtopbank;
58
59
get_bgtop_tile_info(int tile_index)60 static void get_bgtop_tile_info(int tile_index)
61 {
62 int tileno;
63
64 tileno = angelkds_bgtopvideoram[tile_index];
65
66 tileno += angelkds_bgtopbank*0x100 ;
67 SET_TILE_INFO(1,tileno,0,0)
68 }
69
WRITE_HANDLER(angelkds_bgtopvideoram_w)70 WRITE_HANDLER( angelkds_bgtopvideoram_w )
71 {
72 if (angelkds_bgtopvideoram[offset] != data)
73 {
74 angelkds_bgtopvideoram[offset] = data;
75 tilemap_mark_tile_dirty(bgtop_tilemap,offset);
76 }
77 }
78
WRITE_HANDLER(angelkds_bgtopbank_write)79 WRITE_HANDLER( angelkds_bgtopbank_write )
80 {
81
82 if (angelkds_bgtopbank != data)
83 {
84 angelkds_bgtopbank = data;
85 tilemap_mark_all_tiles_dirty (bgtop_tilemap);
86 };
87
88 }
89
WRITE_HANDLER(angelkds_bgtopscroll_write)90 WRITE_HANDLER( angelkds_bgtopscroll_write )
91 {
92 tilemap_set_scrollx(bgtop_tilemap, 0, data );
93 }
94
95 /*** Bottom Half Background Tilemap
96
97 */
98
99 static int angelkds_bgbotbank;
100
get_bgbot_tile_info(int tile_index)101 static void get_bgbot_tile_info(int tile_index)
102 {
103 int tileno;
104
105 tileno = angelkds_bgbotvideoram[tile_index];
106
107 tileno += angelkds_bgbotbank * 0x100 ;
108 SET_TILE_INFO(1,tileno,1,0)
109 }
110
WRITE_HANDLER(angelkds_bgbotvideoram_w)111 WRITE_HANDLER( angelkds_bgbotvideoram_w )
112 {
113 if (angelkds_bgbotvideoram[offset] != data)
114 {
115 angelkds_bgbotvideoram[offset] = data;
116 tilemap_mark_tile_dirty(bgbot_tilemap,offset);
117 }
118 }
119
120
WRITE_HANDLER(angelkds_bgbotbank_write)121 WRITE_HANDLER( angelkds_bgbotbank_write )
122 {
123
124 if (angelkds_bgbotbank != data)
125 {
126 angelkds_bgbotbank = data;
127 tilemap_mark_all_tiles_dirty (bgbot_tilemap);
128 };
129
130 }
131
WRITE_HANDLER(angelkds_bgbotscroll_write)132 WRITE_HANDLER( angelkds_bgbotscroll_write )
133 {
134 tilemap_set_scrollx(bgbot_tilemap, 0, data );
135 }
136
137 UINT8 angelkds_layer_ctrl;
138
WRITE_HANDLER(angelkds_layer_ctrl_write)139 WRITE_HANDLER( angelkds_layer_ctrl_write )
140 {
141 angelkds_layer_ctrl = data;
142 }
143
144 /*** Sprites
145
146 the sprites are similar to the tilemaps in the sense that there is
147 a split down the middle of the screen
148
149 */
150
draw_sprites(struct mame_bitmap * bitmap,const struct rectangle * cliprect,int enable_n)151 static void draw_sprites( struct mame_bitmap *bitmap, const struct rectangle *cliprect, int enable_n)
152 {
153 const UINT8 *source = spriteram;
154 const UINT8 *finish = source+0x0100;
155 const struct GfxElement *gfx = Machine->gfx[2];
156
157 while( source<finish )
158 {
159 /*
160
161 nnnn nnnn - EeFf B?cc - yyyy yyyy - xxxx xxxx
162
163 n = sprite number
164 E = Sprite Enabled in Top Half of Screen
165 e = Sprite Enabled in Bottom Half of Screen
166 F = Flip Y
167 f = Flip X
168 B = Tile Bank
169 ? = unknown, nothing / unused? recheck
170 c = color
171 y = Y position
172 x = X position
173
174 */
175
176
177 UINT16 tile_no = source[0];
178 UINT8 attr = source[1];
179 UINT8 ypos = source[2];
180 UINT8 xpos = source[3];
181
182 UINT8 enable = attr & 0xc0;
183 UINT8 flipx = (attr & 0x10) >> 4;
184 UINT8 flipy = (attr & 0x20) >> 5;
185 UINT8 bank = attr & 0x08;
186 UINT8 color = attr & 0x03;
187
188 if (bank) tile_no +=0x100;
189
190 ypos= 0xff-ypos;
191
192 if (enable & enable_n)
193 {
194 drawgfx(
195 bitmap,
196 gfx,
197 tile_no,
198 color*4,
199 flipx,flipy,
200 xpos,ypos,
201 cliprect,
202 TRANSPARENCY_PEN,15
203 );
204 /* wraparound */
205 if (xpos > 240)
206 drawgfx(
207 bitmap,
208 gfx,
209 tile_no,
210 color*4,
211 flipx,flipy,
212 xpos-256,ypos,
213 cliprect,
214 TRANSPARENCY_PEN,15
215 );
216 /* wraparound */
217 if (ypos > 240)
218 {
219 drawgfx(
220 bitmap,
221 gfx,
222 tile_no,
223 color*4,
224 flipx,flipy,
225 xpos,ypos-256,
226 cliprect,
227 TRANSPARENCY_PEN,15
228 );
229 /* wraparound */
230 if (xpos > 240)
231 drawgfx(
232 bitmap,
233 gfx,
234 tile_no,
235 color*4,
236 flipx,flipy,
237 xpos-256,ypos-256,
238 cliprect,
239 TRANSPARENCY_PEN,15
240 );
241 }
242
243 }
244
245 source+=0x04;
246
247 }
248
249 }
250
251
252 /*** Palette Handling
253
254 4 bits of Red, 4 bits of Green, 4 bits of Blue
255
256 */
257
WRITE_HANDLER(angelkds_paletteram_w)258 WRITE_HANDLER( angelkds_paletteram_w )
259 {
260 int no, r,g,b;
261
262
263 paletteram[offset] = data;
264
265 no=offset & 0xff;
266
267 g = (paletteram[no] & 0xf0)<< 0;
268
269 r = (paletteram[no] & 0x0f) << 4;
270
271 b = (paletteram[no+0x100] & 0x0f) << 4;
272
273 palette_set_color(no,r,g,b);
274 }
275
276 /*** Video Start & Update
277
278 */
279
VIDEO_START(angelkds)280 VIDEO_START( angelkds )
281 {
282
283 tx_tilemap = tilemap_create(get_tx_tile_info,tilemap_scan_rows,TILEMAP_TRANSPARENT, 8, 8,32,32);
284 tilemap_set_transparent_pen(tx_tilemap,0);
285
286 bgbot_tilemap = tilemap_create(get_bgbot_tile_info,tilemap_scan_rows,TILEMAP_TRANSPARENT, 8, 8,32,32);
287 tilemap_set_transparent_pen(bgbot_tilemap,15);
288
289 bgtop_tilemap = tilemap_create(get_bgtop_tile_info,tilemap_scan_rows,TILEMAP_TRANSPARENT, 8, 8,32,32);
290 tilemap_set_transparent_pen(bgtop_tilemap,15);
291
292 return 0;
293 }
294
295 /* enable bits are uncertain */
296
VIDEO_UPDATE(angelkds)297 VIDEO_UPDATE( angelkds )
298 {
299 struct rectangle clip;
300
301 fillbitmap(bitmap,0x3f,cliprect); /* is there a register controling the colour?, we currently use the last colour of the tx palette */
302
303 /* draw top of screen */
304 clip.min_x = 8*0;
305 clip.max_x = 8*16-1;
306 clip.min_y = Machine->visible_area.min_y;
307 clip.max_y = Machine->visible_area.max_y;
308 if ((angelkds_layer_ctrl & 0x80) == 0x00) tilemap_draw(bitmap,&clip,bgtop_tilemap,0,0);
309 draw_sprites(bitmap,&clip, 0x80);
310 if ((angelkds_layer_ctrl & 0x20) == 0x00) tilemap_draw(bitmap,&clip,tx_tilemap,0,0);
311
312 /* draw bottom of screen */
313 clip.min_x = 8*16;
314 clip.max_x = 8*32-1;
315 clip.min_y = Machine->visible_area.min_y;
316 clip.max_y = Machine->visible_area.max_y;
317 if ((angelkds_layer_ctrl & 0x40) == 0x00) tilemap_draw(bitmap,&clip,bgbot_tilemap,0,0);
318 draw_sprites(bitmap,&clip, 0x40);
319 if ((angelkds_layer_ctrl & 0x20) == 0x00) tilemap_draw(bitmap,&clip,tx_tilemap,0,0);
320 }
321