1 #include "driver.h"
2 #include "vidhrdw/generic.h"
3
4
5 data16_t armedf_vreg;
6
7 data16_t *terraf_text_videoram;
8 data16_t *armedf_bg_videoram;
9 data16_t *armedf_fg_videoram;
10 static data16_t armedf_fg_scrollx,armedf_fg_scrolly;
11
12 data16_t terraf_scroll_msb;
13
14 static struct tilemap *bg_tilemap, *fg_tilemap, *tx_tilemap;
15
16 static int scroll_type,sprite_offy;
17
armedf_setgfxtype(int type)18 void armedf_setgfxtype( int type )
19 {
20 scroll_type = type;
21 }
22
23 /***************************************************************************
24
25 Callbacks for the TileMap code
26
27 ***************************************************************************/
28
armedf_scan(UINT32 col,UINT32 row,UINT32 num_cols,UINT32 num_rows)29 static UINT32 armedf_scan(UINT32 col,UINT32 row,UINT32 num_cols,UINT32 num_rows)
30 { /* col: 0..63; row: 0..31 */
31 switch( scroll_type )
32 {
33 case 1: /* armed formation */
34 return col*32+row;
35
36 case 3: /* legion */
37 return (col&0x1f)*32+row+0x400*(col/32);
38
39 default:
40 return 32*(31-row)+(col&0x1f)+0x400*(col/32);
41 }
42 }
43
get_tx_tile_info(int tile_index)44 static void get_tx_tile_info(int tile_index)
45 {
46 int tile_number = terraf_text_videoram[tile_index]&0xff;
47 int attributes;
48
49 if( scroll_type == 1 )
50 {
51 attributes = terraf_text_videoram[tile_index+0x800]&0xff;
52 }
53 else
54 {
55 attributes = terraf_text_videoram[tile_index+0x400]&0xff;
56 }
57 SET_TILE_INFO(
58 0,
59 tile_number + 256 * (attributes & 0x3),
60 attributes >> 4,
61 0)
62 }
63
get_fg_tile_info(int tile_index)64 static void get_fg_tile_info( int tile_index )
65 {
66 int data = armedf_fg_videoram[tile_index];
67 SET_TILE_INFO(
68 1,
69 data&0x7ff,
70 data>>11,
71 0)
72 }
73
74
get_bg_tile_info(int tile_index)75 static void get_bg_tile_info( int tile_index )
76 {
77 int data = armedf_bg_videoram[tile_index];
78 SET_TILE_INFO(
79 2,
80 data&0x3ff,
81 data>>11,
82 0)
83 }
84
85
86
87 /***************************************************************************
88
89 Start the video hardware emulation.
90
91 ***************************************************************************/
92
VIDEO_START(armedf)93 VIDEO_START( armedf )
94 {
95 if( scroll_type == 4 || /* cclimbr2 */
96 scroll_type == 3 ) /* legion */
97 {
98 sprite_offy = 0;
99 }
100 else
101 {
102 sprite_offy = 128;
103 }
104
105 bg_tilemap = tilemap_create(get_bg_tile_info,tilemap_scan_cols,TILEMAP_OPAQUE,16,16,64,32);
106 fg_tilemap = tilemap_create(get_fg_tile_info,tilemap_scan_cols,TILEMAP_TRANSPARENT,16,16,64,32);
107 tx_tilemap = tilemap_create(get_tx_tile_info,armedf_scan,TILEMAP_TRANSPARENT,8,8,64,32);
108
109 if (!bg_tilemap || !fg_tilemap || !tx_tilemap)
110 return 1;
111
112 tilemap_set_transparent_pen(fg_tilemap,0xf);
113 tilemap_set_transparent_pen(tx_tilemap,0xf);
114
115 if( scroll_type!=1 )
116 {
117 tilemap_set_scrollx(tx_tilemap,0,-128);
118 }
119
120 return 0;
121 }
122
123 /***************************************************************************
124
125 Memory handlers
126
127 ***************************************************************************/
128
WRITE16_HANDLER(armedf_text_videoram_w)129 WRITE16_HANDLER( armedf_text_videoram_w )
130 {
131 int oldword = terraf_text_videoram[offset];
132 COMBINE_DATA(&terraf_text_videoram[offset]);
133 if (oldword != terraf_text_videoram[offset])
134 {
135 if( scroll_type == 1 )
136 {
137 tilemap_mark_tile_dirty(tx_tilemap,offset & 0x7ff);
138 }
139 else
140 {
141 tilemap_mark_tile_dirty(tx_tilemap,offset & 0xbff);
142 }
143 }
144 }
145
146
WRITE16_HANDLER(armedf_fg_videoram_w)147 WRITE16_HANDLER( armedf_fg_videoram_w )
148 {
149 int oldword = armedf_fg_videoram[offset];
150 COMBINE_DATA(&armedf_fg_videoram[offset]);
151 if (oldword != armedf_fg_videoram[offset])
152 tilemap_mark_tile_dirty(fg_tilemap,offset);
153 }
154
WRITE16_HANDLER(armedf_bg_videoram_w)155 WRITE16_HANDLER( armedf_bg_videoram_w )
156 {
157 int oldword = armedf_bg_videoram[offset];
158 COMBINE_DATA(&armedf_bg_videoram[offset]);
159 if (oldword != armedf_bg_videoram[offset])
160 tilemap_mark_tile_dirty(bg_tilemap,offset);
161 }
162
163 static int waiting_msb;
164
WRITE16_HANDLER(terraf_fg_scrollx_w)165 WRITE16_HANDLER( terraf_fg_scrollx_w )
166 {
167 if (ACCESSING_MSB)
168 {
169 armedf_fg_scrollx = data >> 8;
170 waiting_msb = 1;
171 }
172 }
173
WRITE16_HANDLER(terraf_fg_scrolly_w)174 WRITE16_HANDLER( terraf_fg_scrolly_w )
175 {
176 if (ACCESSING_MSB)
177 {
178 if (waiting_msb)
179 terraf_scroll_msb = data >> 8;
180 else
181 armedf_fg_scrolly = data >> 8;
182 }
183 }
184
WRITE16_HANDLER(terraf_fg_scroll_msb_arm_w)185 WRITE16_HANDLER( terraf_fg_scroll_msb_arm_w )
186 {
187 if (ACCESSING_MSB)
188 waiting_msb = 0;
189 }
190
WRITE16_HANDLER(armedf_fg_scrollx_w)191 WRITE16_HANDLER( armedf_fg_scrollx_w )
192 {
193 COMBINE_DATA(&armedf_fg_scrollx);
194 }
195
WRITE16_HANDLER(armedf_fg_scrolly_w)196 WRITE16_HANDLER( armedf_fg_scrolly_w )
197 {
198 COMBINE_DATA(&armedf_fg_scrolly);
199 }
200
WRITE16_HANDLER(armedf_bg_scrollx_w)201 WRITE16_HANDLER( armedf_bg_scrollx_w )
202 {
203 static data16_t scroll;
204 COMBINE_DATA(&scroll);
205 tilemap_set_scrollx(bg_tilemap,0,scroll);
206 }
207
WRITE16_HANDLER(armedf_bg_scrolly_w)208 WRITE16_HANDLER( armedf_bg_scrolly_w )
209 {
210 static data16_t scroll;
211 COMBINE_DATA(&scroll);
212 tilemap_set_scrolly(bg_tilemap,0,scroll);
213 }
214
215
216
217 /***************************************************************************
218
219 Display refresh
220
221 ***************************************************************************/
222
draw_sprites(struct mame_bitmap * bitmap,const struct rectangle * cliprect,int priority)223 static void draw_sprites( struct mame_bitmap *bitmap, const struct rectangle *cliprect, int priority )
224 {
225 int offs;
226
227 for (offs = 0;offs < spriteram_size/2;offs += 4)
228 {
229 int code = buffered_spriteram16[offs+1]; /* ??YX?TTTTTTTTTTT */
230 int flipx = code & 0x2000;
231 int flipy = code & 0x1000;
232 int color = (buffered_spriteram16[offs+2]>>8)&0x1f;
233 int sx = buffered_spriteram16[offs+3];
234 int sy = sprite_offy+240-(buffered_spriteram16[offs+0]&0x1ff);
235
236 if (flip_screen) {
237 sx = 320 - sx + 176; /* don't ask where 176 comes from, just tried it out */
238 sy = 240 - sy + 1; /* don't ask where 1 comes from, just tried it out */
239 flipx = !flipx; /* the values seem to result in pixel-correct placement */
240 flipy = !flipy; /* in all the games supported by this driver */
241 }
242
243 if (((buffered_spriteram16[offs+0] & 0x3000) >> 12) == priority)
244 {
245 drawgfx(bitmap,Machine->gfx[3],
246 code & 0xfff,
247 color,
248 flipx,flipy,
249 sx,sy,
250 cliprect,TRANSPARENCY_PEN,15);
251 }
252 }
253 }
254
255
256
VIDEO_UPDATE(armedf)257 VIDEO_UPDATE( armedf )
258 {
259 int sprite_enable = armedf_vreg & 0x200;
260
261 tilemap_set_enable( bg_tilemap, armedf_vreg&0x800 );
262 tilemap_set_enable( fg_tilemap, armedf_vreg&0x400 );
263 tilemap_set_enable( tx_tilemap, armedf_vreg&0x100 );
264
265 switch (scroll_type)
266 {
267 case 0: /* terra force */
268 tilemap_set_scrollx( fg_tilemap, 0, armedf_fg_scrolly + ((terraf_scroll_msb>>4)&3)*256 );
269 tilemap_set_scrolly( fg_tilemap, 0, armedf_fg_scrollx + ((terraf_scroll_msb)&3)*256 );
270 break;
271
272 case 1: /* armed formation */
273 tilemap_set_scrollx( fg_tilemap, 0, armedf_fg_scrollx );
274 tilemap_set_scrolly( fg_tilemap, 0, armedf_fg_scrolly );
275 break;
276
277 case 2: /* kodure ookami */
278 case 3: /* legion */
279 case 4: /* crazy climber 2 */
280 {
281 int scrollx,scrolly;
282
283 /* scrolling is handled by the protection mcu */
284 scrollx = (terraf_text_videoram[13] & 0xff) | (terraf_text_videoram[14] << 8);
285 scrolly = (terraf_text_videoram[11] & 0xff) | (terraf_text_videoram[12] << 8);
286 tilemap_set_scrollx( fg_tilemap, 0, scrollx);
287 tilemap_set_scrolly( fg_tilemap, 0, scrolly);
288 }
289 break;
290 }
291
292 if( armedf_vreg & 0x0800 )
293 {
294 tilemap_draw( bitmap, cliprect, bg_tilemap, 0, 0);
295 }
296 else
297 {
298 fillbitmap( bitmap, get_black_pen(), cliprect ); /* disabled bg_tilemap - all black? */
299 }
300
301 if( sprite_enable ) draw_sprites( bitmap, cliprect, 2 );
302 tilemap_draw( bitmap, cliprect, fg_tilemap, 0, 0);
303 if( sprite_enable ) draw_sprites( bitmap, cliprect, 1 );
304 tilemap_draw( bitmap, cliprect, tx_tilemap, 0, 0);
305 if( sprite_enable ) draw_sprites( bitmap, cliprect, 0 );
306
307 if( keyboard_pressed(KEYCODE_1 ) ||
308 keyboard_pressed(KEYCODE_2 ) )
309 { /* HACK! wipe the text layer */
310 unsigned i;
311 for( i=0; i<0x800; i++ )
312 {
313 terraf_text_videoram[i] = 0x0;
314 }
315 tilemap_mark_all_tiles_dirty( tx_tilemap );
316 }
317 }
318
VIDEO_EOF(armedf)319 VIDEO_EOF( armedf )
320 {
321 buffer_spriteram16_w(0,0,0);
322 }
323