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 *commando_fgvideoram,*commando_bgvideoram;
15 
16 static struct tilemap *fg_tilemap, *bg_tilemap;
17 
18 
19 
20 /***************************************************************************
21 
22   Callbacks for the TileMap code
23 
24 ***************************************************************************/
25 
get_fg_tile_info(int tile_index)26 static void get_fg_tile_info(int tile_index)
27 {
28 	int code, color;
29 
30 	code = commando_fgvideoram[tile_index];
31 	color = commando_fgvideoram[tile_index + 0x400];
32 	SET_TILE_INFO(
33 			0,
34 			code + ((color & 0xc0) << 2),
35 			color & 0x0f,
36 			TILE_FLIPYX((color & 0x30) >> 4))
37 }
38 
get_bg_tile_info(int tile_index)39 static void get_bg_tile_info(int tile_index)
40 {
41 	int code, color;
42 
43 	code = commando_bgvideoram[tile_index];
44 	color = commando_bgvideoram[tile_index + 0x400];
45 	SET_TILE_INFO(
46 			1,
47 			code + ((color & 0xc0) << 2),
48 			color & 0x0f,
49 			TILE_FLIPYX((color & 0x30) >> 4))
50 }
51 
52 
53 /***************************************************************************
54 
55   Start the video hardware emulation.
56 
57 ***************************************************************************/
58 
VIDEO_START(commando)59 VIDEO_START( commando )
60 {
61 	fg_tilemap = tilemap_create(get_fg_tile_info,tilemap_scan_rows,TILEMAP_TRANSPARENT, 8, 8,32,32);
62 	bg_tilemap = tilemap_create(get_bg_tile_info,tilemap_scan_cols,TILEMAP_OPAQUE,     16,16,32,32);
63 
64 	if (!fg_tilemap || !bg_tilemap)
65 		return 1;
66 
67 	tilemap_set_transparent_pen(fg_tilemap,3);
68 
69 	return 0;
70 }
71 
72 
73 /***************************************************************************
74 
75   Memory handlers
76 
77 ***************************************************************************/
78 
WRITE_HANDLER(commando_fgvideoram_w)79 WRITE_HANDLER( commando_fgvideoram_w )
80 {
81 	commando_fgvideoram[offset] = data;
82 	tilemap_mark_tile_dirty(fg_tilemap,offset & 0x3ff);
83 }
84 
WRITE_HANDLER(commando_bgvideoram_w)85 WRITE_HANDLER( commando_bgvideoram_w )
86 {
87 	commando_bgvideoram[offset] = data;
88 	tilemap_mark_tile_dirty(bg_tilemap,offset & 0x3ff);
89 }
90 
91 
WRITE_HANDLER(commando_scrollx_w)92 WRITE_HANDLER( commando_scrollx_w )
93 {
94 	static unsigned char scroll[2];
95 
96 	scroll[offset] = data;
97 	tilemap_set_scrollx(bg_tilemap,0,scroll[0] | (scroll[1] << 8));
98 }
99 
WRITE_HANDLER(commando_scrolly_w)100 WRITE_HANDLER( commando_scrolly_w )
101 {
102 	static unsigned char scroll[2];
103 
104 	scroll[offset] = data;
105 	tilemap_set_scrolly(bg_tilemap,0,scroll[0] | (scroll[1] << 8));
106 }
107 
108 
WRITE_HANDLER(commando_c804_w)109 WRITE_HANDLER( commando_c804_w )
110 {
111 	/* bits 0 and 1 are coin counters */
112 	coin_counter_w(0, data & 0x01);
113 	coin_counter_w(1, data & 0x02);
114 
115 	/* bit 4 resets the sound CPU */
116 	cpu_set_reset_line(1,(data & 0x10) ? ASSERT_LINE : CLEAR_LINE);
117 
118 	/* bit 7 flips screen */
119 	flip_screen_set(data & 0x80);
120 }
121 
122 
123 
124 /***************************************************************************
125 
126   Display refresh
127 
128 ***************************************************************************/
129 
draw_sprites(struct mame_bitmap * bitmap,const struct rectangle * cliprect)130 static void draw_sprites(struct mame_bitmap *bitmap, const struct rectangle *cliprect)
131 {
132 	int offs;
133 
134 	for (offs = spriteram_size - 4;offs >= 0;offs -= 4)
135 	{
136 		int sx,sy,flipx,flipy,bank,attr;
137 
138 
139 		/* bit 1 of attr is not used */
140 		attr = buffered_spriteram[offs + 1];
141 		sx = buffered_spriteram[offs + 3] - ((attr & 0x01) << 8);
142 		sy = buffered_spriteram[offs + 2];
143 		flipx = attr & 0x04;
144 		flipy = attr & 0x08;
145 		bank = (attr & 0xc0) >> 6;
146 
147 		if (flip_screen)
148 		{
149 			sx = 240 - sx;
150 			sy = 240 - sy;
151 			flipx = !flipx;
152 			flipy = !flipy;
153 		}
154 
155 		if (bank < 3)
156 			drawgfx(bitmap,Machine->gfx[2],
157 					buffered_spriteram[offs] + 256 * bank,
158 					(attr & 0x30) >> 4,
159 					flipx,flipy,
160 					sx,sy,
161 					cliprect,TRANSPARENCY_PEN,15);
162 	}
163 }
164 
VIDEO_UPDATE(commando)165 VIDEO_UPDATE( commando )
166 {
167 	tilemap_draw(bitmap,cliprect,bg_tilemap,0,0);
168 	draw_sprites(bitmap,cliprect);
169 	tilemap_draw(bitmap,cliprect,fg_tilemap,0,0);
170 }
171 
VIDEO_EOF(commando)172 VIDEO_EOF( commando )
173 {
174 	buffer_spriteram_w(0,0);
175 }
176