1 /***************************************************************************
2 
3   vidhrdw.c
4 
5   Functions to emulate the video hardware of the machine.
6 
7 ***************************************************************************/
8 
9 #include "driver.h"
10 
11 
12 data8_t *espial_videoram;
13 data8_t *espial_colorram;
14 data8_t *espial_attributeram;
15 data8_t *espial_scrollram;
16 data8_t *espial_spriteram_1;
17 data8_t *espial_spriteram_2;
18 data8_t *espial_spriteram_3;
19 
20 static int flipscreen;
21 static struct tilemap *tilemap;
22 
23 
24 /***************************************************************************
25 
26   Convert the color PROMs into a more useable format.
27 
28   Espial has two 256x4 palette PROMs.
29 
30   I don't know for sure how the palette PROMs are connected to the RGB
31   output, but it's probably the usual:
32 
33   bit 3 -- 220 ohm resistor  -- BLUE
34         -- 470 ohm resistor  -- BLUE
35         -- 220 ohm resistor  -- GREEN
36   bit 0 -- 470 ohm resistor  -- GREEN
37   bit 3 -- 1  kohm resistor  -- GREEN
38         -- 220 ohm resistor  -- RED
39         -- 470 ohm resistor  -- RED
40   bit 0 -- 1  kohm resistor  -- RED
41 
42 ***************************************************************************/
PALETTE_INIT(espial)43 PALETTE_INIT( espial )
44 {
45 	int i;
46 
47 
48 	for (i = 0;i < Machine->drv->total_colors;i++)
49 	{
50 		int bit0,bit1,bit2,r,g,b;
51 
52 
53 		/* red component */
54 		bit0 = (color_prom[i] >> 0) & 0x01;
55 		bit1 = (color_prom[i] >> 1) & 0x01;
56 		bit2 = (color_prom[i] >> 2) & 0x01;
57 		r = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
58 		/* green component */
59 		bit0 = (color_prom[i] >> 3) & 0x01;
60 		bit1 = (color_prom[i + Machine->drv->total_colors] >> 0) & 0x01;
61 		bit2 = (color_prom[i + Machine->drv->total_colors] >> 1) & 0x01;
62 		g = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
63 		/* blue component */
64 		bit0 = 0;
65 		bit1 = (color_prom[i + Machine->drv->total_colors] >> 2) & 0x01;
66 		bit2 = (color_prom[i + Machine->drv->total_colors] >> 3) & 0x01;
67 		b = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
68 
69 		palette_set_color(i,r,g,b);
70 	}
71 }
72 
73 
74 
75 /***************************************************************************
76 
77   Callbacks for the TileMap code
78 
79 ***************************************************************************/
80 
get_tile_info(int tile_index)81 static void get_tile_info(int tile_index)
82 {
83 	data8_t code = espial_videoram[tile_index];
84 	data8_t col = espial_colorram[tile_index];
85 	data8_t attr = espial_attributeram[tile_index];
86 	SET_TILE_INFO(0,
87 				  code | ((attr & 0x03) << 8),
88 				  col & 0x3f,
89 				  TILE_FLIPYX(attr >> 2))
90 }
91 
92 
93 
94 /*************************************
95  *
96  *	Video system start
97  *
98  *************************************/
99 
VIDEO_START(espial)100 VIDEO_START( espial )
101 {
102 	tilemap = tilemap_create(get_tile_info,tilemap_scan_rows,TILEMAP_OPAQUE,8,8,32,32);
103 
104 	if (!tilemap)
105 		return 1;
106 
107 	tilemap_set_scroll_cols(tilemap, 32);
108 
109 	return 0;
110 }
111 
VIDEO_START(netwars)112 VIDEO_START( netwars )
113 {
114 	/* Net Wars has a tile map that's twice as big as Espial's */
115 	tilemap = tilemap_create(get_tile_info,tilemap_scan_rows,TILEMAP_OPAQUE,8,8,32,64);
116 
117 	if (!tilemap)
118 		return 1;
119 
120 	tilemap_set_scroll_cols(tilemap, 32);
121 	tilemap_set_scrolldy(tilemap, 0, 0x100);
122 
123 	return 0;
124 }
125 
126 
127 /*************************************
128  *
129  *	Memory handlers
130  *
131  *************************************/
132 
WRITE_HANDLER(espial_videoram_w)133 WRITE_HANDLER( espial_videoram_w )
134 {
135 	if (espial_videoram[offset] != data)
136 	{
137 		espial_videoram[offset] = data;
138 		tilemap_mark_tile_dirty(tilemap, offset);
139 	}
140 }
141 
142 
WRITE_HANDLER(espial_colorram_w)143 WRITE_HANDLER( espial_colorram_w )
144 {
145 	if (espial_colorram[offset] != data)
146 	{
147 		espial_colorram[offset] = data;
148 		tilemap_mark_tile_dirty(tilemap, offset);
149 	}
150 }
151 
152 
WRITE_HANDLER(espial_attributeram_w)153 WRITE_HANDLER( espial_attributeram_w )
154 {
155 	if (espial_attributeram[offset] != data)
156 	{
157 		espial_attributeram[offset] = data;
158 		tilemap_mark_tile_dirty(tilemap, offset);
159 	}
160 }
161 
162 
WRITE_HANDLER(espial_scrollram_w)163 WRITE_HANDLER( espial_scrollram_w )
164 {
165 	espial_scrollram[offset] = data;
166 	tilemap_set_scrolly(tilemap, offset, data);
167 }
168 
169 
WRITE_HANDLER(espial_flipscreen_w)170 WRITE_HANDLER( espial_flipscreen_w )
171 {
172 	flipscreen = data;
173 
174 	tilemap_set_flip(0, flipscreen ? TILEMAP_FLIPX | TILEMAP_FLIPY : 0);
175 }
176 
177 
178 /*************************************
179  *
180  *	Video update
181  *
182  *************************************/
183 
draw_sprites(struct mame_bitmap * bitmap,const struct rectangle * cliprect)184 static void draw_sprites(struct mame_bitmap *bitmap, const struct rectangle *cliprect)
185 {
186 	int offs;
187 
188 
189 	/* Note that it is important to draw them exactly in this */
190 	/* order, to have the correct priorities. */
191 	for (offs = 0;offs < 16;offs++)
192 	{
193 		int sx,sy,code,color,flipx,flipy;
194 
195 
196 		sx = espial_spriteram_1[offs + 16];
197 		sy = espial_spriteram_2[offs];
198 		code = espial_spriteram_1[offs] >> 1;
199 		color = espial_spriteram_2[offs + 16];
200 		flipx = espial_spriteram_3[offs] & 0x04;
201 		flipy = espial_spriteram_3[offs] & 0x08;
202 
203 		if (flipscreen)
204 		{
205 			flipx = !flipx;
206 			flipy = !flipy;
207 		}
208 		else
209 		{
210 			sy = 240 - sy;
211 		}
212 
213 		if (espial_spriteram_1[offs] & 1)	/* double height */
214 		{
215 			if (flipscreen)
216 			{
217 				drawgfx(bitmap,Machine->gfx[1],
218 						code,color,
219 						flipx,flipy,
220 						sx,sy + 16,
221 						cliprect,TRANSPARENCY_PEN,0);
222 				drawgfx(bitmap,Machine->gfx[1],
223 						code + 1,
224 						color,
225 						flipx,flipy,
226 						sx,sy,
227 						cliprect,TRANSPARENCY_PEN,0);
228 			}
229 			else
230 			{
231 				drawgfx(bitmap,Machine->gfx[1],
232 						code,color,
233 						flipx,flipy,
234 						sx,sy - 16,
235 						cliprect,TRANSPARENCY_PEN,0);
236 				drawgfx(bitmap,Machine->gfx[1],
237 						code + 1,color,
238 						flipx,flipy,
239 						sx,sy,
240 						cliprect,TRANSPARENCY_PEN,0);
241 			}
242 		}
243 		else
244 		{
245 			drawgfx(bitmap,Machine->gfx[1],
246 					code,color,
247 					flipx,flipy,
248 					sx,sy,
249 					cliprect,TRANSPARENCY_PEN,0);
250 		}
251 	}
252 }
253 
254 
VIDEO_UPDATE(espial)255 VIDEO_UPDATE( espial )
256 {
257 	tilemap_draw(bitmap,cliprect,tilemap,0,0);
258 
259 	draw_sprites(bitmap, cliprect);
260 }
261