1 /***************************************************************************
2 
3 						  -= ESD 16 Bit Games =-
4 
5 					driver by	Luca Elia (l.elia@tin.it)
6 
7 
8 Note:	if MAME_DEBUG is defined, pressing Z with:
9 
10 		Q / W			Shows Layer 0 / 1
11 		A				Shows Sprites
12 
13 		Keys can be used together!
14 
15 
16 	[ 2 Scrolling Layers ]
17 
18 		Tile Size:				8 x 8 x 8
19 		Color Codes:			1 per Layer
20 		Layer Size (tiles) :	128 x 64
21 		Layer Size (pixels):	1024 x 512
22 
23 	[ 256 Sprites ]
24 
25 		Sprites are made of 16 x 16 x 5 tiles. Size can vary from 1 to
26 		8 tiles vertically, while their width is always 1 tile.
27 
28 	[ Priorities ]
29 
30 		The game only uses this scheme:
31 
32 		Back -> Front:	Layer 0, Layer 1, Sprites
33 
34 ***************************************************************************/
35 
36 #include "driver.h"
37 #include "vidhrdw/generic.h"
38 
39 /* Variables needed by drivers: */
40 
41 data16_t *esd16_vram_0, *esd16_scroll_0;
42 data16_t *esd16_vram_1, *esd16_scroll_1;
43 
44 /*extern data16_t *head_unknown1;*/
45 extern data16_t *head_layersize;
46 static int esd16_tilemap0_color = 0;
47 
48 /*
49 extern data16_t *head_unknown3;
50 extern data16_t *head_unknown4;
51 extern data16_t *head_unknown5;
52 */
53 
54 /* Functions defined in vidhrdw: */
55 
56 WRITE16_HANDLER( esd16_vram_0_w );
57 WRITE16_HANDLER( esd16_vram_1_w );
58 
59 VIDEO_START( esd16 );
60 VIDEO_UPDATE( esd16 );
61 
62 
63 /***************************************************************************
64 
65 									Tilemaps
66 
67 	Offset: 	Bits:					Value:
68 
69 		0.w								Code
70 
71 	No color code:	layer 0 (backmost) usues the second 256 colors,
72 					layer 1 the first 256.
73 
74 ***************************************************************************/
75 
76 struct tilemap *esdtilemap_0, *esdtilemap_1, *esdtilemap_0_16x16, *esdtilemap_1_16x16;
77 
get_tile_info_0(int tile_index)78 static void get_tile_info_0(int tile_index)
79 {
80 	data16_t code = esd16_vram_0[tile_index];
81 	SET_TILE_INFO(
82 			1,
83 			code,
84 			esd16_tilemap0_color,
85 			0)
86 }
87 
get_tile_info_0_16x16(int tile_index)88 static void get_tile_info_0_16x16(int tile_index)
89 {
90 	data16_t code = esd16_vram_0[tile_index];
91 	SET_TILE_INFO(
92 			2,
93 			code,
94 			esd16_tilemap0_color,
95 			0)
96 }
97 
get_tile_info_1(int tile_index)98 static void get_tile_info_1(int tile_index)
99 {
100 	data16_t code = esd16_vram_1[tile_index];
101 	SET_TILE_INFO(
102 			1,
103 			code,
104 			0,
105 			0)
106 }
107 
get_tile_info_1_16x16(int tile_index)108 static void get_tile_info_1_16x16(int tile_index)
109 {
110 	data16_t code = esd16_vram_1[tile_index];
111 	SET_TILE_INFO(
112 			2,
113 			code,
114 			0,
115 			0)
116 }
117 
WRITE16_HANDLER(esd16_vram_0_w)118 WRITE16_HANDLER( esd16_vram_0_w )
119 {
120 	data16_t old_data	=	esd16_vram_0[offset];
121 	data16_t new_data	=	COMBINE_DATA(&esd16_vram_0[offset]);
122 	if (old_data != new_data)	{
123 		tilemap_mark_tile_dirty(esdtilemap_0,      offset);
124 		tilemap_mark_tile_dirty(esdtilemap_0_16x16,offset);
125 	}
126 }
127 
WRITE16_HANDLER(esd16_vram_1_w)128 WRITE16_HANDLER( esd16_vram_1_w )
129 {
130 	data16_t old_data	=	esd16_vram_1[offset];
131 	data16_t new_data	=	COMBINE_DATA(&esd16_vram_1[offset]);
132 	if (old_data != new_data)
133 	{
134 		tilemap_mark_tile_dirty(esdtilemap_1,      offset);
135 		tilemap_mark_tile_dirty(esdtilemap_1_16x16,offset);
136 	}
137 }
138 
WRITE16_HANDLER(esd16_tilemap0_color_w)139 WRITE16_HANDLER( esd16_tilemap0_color_w )
140 {
141 	esd16_tilemap0_color = data & 3;
142 	tilemap_mark_all_tiles_dirty(esdtilemap_0);
143 	tilemap_mark_all_tiles_dirty(esdtilemap_0_16x16);
144 
145 	flip_screen_set(data & 0x80);
146 }
147 
148 
149 
150 /***************************************************************************
151 
152 
153 							Video Hardware Init
154 
155 
156 ***************************************************************************/
157 
158 
VIDEO_START(esd16)159 VIDEO_START( esd16 )
160 {
161 	esdtilemap_0 = tilemap_create(	get_tile_info_0, tilemap_scan_rows,
162 								TILEMAP_OPAQUE,		8,8,	0x80,0x40);
163 
164 	esdtilemap_0_16x16 = tilemap_create(	get_tile_info_0_16x16, tilemap_scan_rows,
165 								TILEMAP_OPAQUE,		16,16,	0x40,0x40);
166 
167 	esdtilemap_1 = tilemap_create(	get_tile_info_1, tilemap_scan_rows,
168 								TILEMAP_TRANSPARENT,	8,8,	0x80,0x40);
169 
170 	/* hedpanic changes tilemap 1 to 16x16 at various times */
171 	esdtilemap_1_16x16 = tilemap_create(	get_tile_info_1_16x16, tilemap_scan_rows,
172 								TILEMAP_TRANSPARENT,	16,16,	0x40,0x40);
173 
174 	if ( !esdtilemap_0 || !esdtilemap_1 || !esdtilemap_0_16x16 || !esdtilemap_1_16x16 )
175 		return 1;
176 
177 	tilemap_set_scrolldx(esdtilemap_0, -0x60 + 2, -0x60     );
178 	tilemap_set_scrolldx(esdtilemap_1, -0x60    , -0x60 + 2 );
179 	tilemap_set_scrolldx(esdtilemap_0_16x16, -0x60 +2 , -0x60  );
180 	tilemap_set_scrolldx(esdtilemap_1_16x16, -0x60    , -0x60 + 2 );
181 
182 	tilemap_set_transparent_pen(esdtilemap_1,      0x00);
183 	tilemap_set_transparent_pen(esdtilemap_1_16x16,0x00);
184 
185 	return 0;
186 }
187 
188 
189 
190 
191 /***************************************************************************
192 
193 								Sprites Drawing
194 
195 	Offset: 	Bits:					Value:
196 
197 		0.w		fedc b--- ---- ----
198 				---- -a9- ---- ----		Y Size: (1 << N) Tiles
199 				---- ---8 7654 3210		Y (Signed, Bottom-Up)
200 
201 		2.w								Code
202 
203 		4.w		fed- ---- ---- ----
204 				---c ---- ---- ----		Color?
205 				---- ba9- ---- ----		Color
206 				---- ---8 7654 3210		X (Signed)
207 
208 		6.w		fedc ba9- ---- ----
209 				---- ---8 ---- ----		? 1 (Display Sprite?)
210 				---- ---- 7654 3210
211 
212 - To Do: Flip X&Y ? They seem unused.
213 
214 ***************************************************************************/
215 
esd16_draw_sprites(struct mame_bitmap * bitmap,const struct rectangle * cliprect)216 static void esd16_draw_sprites(struct mame_bitmap *bitmap, const struct rectangle *cliprect)
217 {
218 	int offs;
219 
220 	int max_x = 319;
221 	int max_y = 255;
222 
223 	for ( offs = spriteram_size/2 - 8/2; offs >= 0 ; offs -= 8/2 )
224 	{
225 		int y, starty, endy, incy;
226 
227 		int	sy		=	spriteram16[ offs + 0 ];
228 		int	code	=	spriteram16[ offs + 1 ];
229 		int	sx		=	spriteram16[ offs + 2 ];
230 		int	attr	=	spriteram16[ offs + 3 ];
231 
232 		int dimy	=	1 << ((sy >> 9) & 3);
233 
234 		int	flipx	=	sy & 0x2000;
235 		int	flipy	=	attr & 0x0000;
236 		int flash   =   sy & 0x1000;
237 
238 		int color	=	(sx >> 9) & 0xf;
239 
240 		int pri_mask;
241 
242 		if (flash && (cpu_getcurrentframe() & 1)) continue;
243 
244 		if(sx & 0x8000)
245 			pri_mask = 0xfe; /* under "tilemap 1" */
246 		else
247 			pri_mask = 0; /* above everything */
248 
249 		sx	=	sx & 0x1ff;
250 		if (sx >= 0x180)	sx -= 0x200;
251 
252 		sy	 =	0x100 - ((sy & 0xff)  - (sy & 0x100));
253 		sy	-=	dimy*16;
254 
255 		if (flip_screen)
256 		{	flipx = !flipx;		sx = max_x - sx -    1 * 16 + 2;	/* small offset */
257 			flipy = !flipy;		sy = max_y - sy - dimy * 16;	}
258 
259 		if (flipy)	{	starty = sy+(dimy-1)*16;	endy = sy-16;		incy = -16;	}
260 		else		{	starty = sy;				endy = sy+dimy*16;	incy = +16;	}
261 
262 		for (y = starty ; y != endy ; y += incy)
263 		{
264 			pdrawgfx(bitmap,Machine->gfx[0],
265 					code++,
266 					color,
267 					flipx, flipy,
268 					sx, y,
269 					&Machine->visible_area,TRANSPARENCY_PEN,0,pri_mask);
270 		}
271 	}
272 }
273 
274 
275 /* note, check if i can re-merge this with the other or if its really different */
hedpanic_draw_sprites(struct mame_bitmap * bitmap,const struct rectangle * cliprect)276 static void hedpanic_draw_sprites(struct mame_bitmap *bitmap, const struct rectangle *cliprect)
277 {
278 	int offs;
279 
280 	int max_x = 319;
281 	int max_y = 255;
282 
283 	for ( offs = spriteram_size/2 - 8/2; offs >= 0 ; offs -= 8/2 )
284 	{
285 		int y, starty, endy, incy;
286 
287 		int	sy		=	spriteram16[ offs + 0 ];
288 		int	code	=	spriteram16[ offs + 1 ];
289 		int	sx		=	spriteram16[ offs + 2 ];
290 /*      int attr    =   spriteram16[ offs + 3 ]; */
291 
292 		int dimy	=	1 << ((sy >> 9) & 3);
293 
294 		int	flipx	=	sy & 0x2000;
295 		int	flipy	=	sy & 0x0000;
296 		int flash   =   sy & 0x1000;
297 
298 		int color	=	(sx >> 9) & 0xf;
299 
300 		int pri_mask;
301 
302 		if (flash && (cpu_getcurrentframe() & 1)) continue;
303 
304 		if(sx & 0x8000)
305 			pri_mask = 0xfffe; /* under "tilemap 1" */
306 		else
307 			pri_mask = 0; /* above everything */
308 
309 		sx	=	sx & 0x1ff;
310 		if (sx >= 0x180)	sx -= 0x200;
311 
312 		sy &= 0x1ff;
313 
314 		sx -= 24;
315 
316 		sy = 0x1ff-sy;
317 
318 		if (flip_screen)
319 		{	flipx = !flipx;		sx = max_x - sx -    1 * 16 + 2;	/* small offset */
320 			flipy = !flipy;		sy = max_y - sy - dimy * 16;	}
321 
322 		if (flipy)	{	starty = sy+(dimy-1)*16;	endy = sy-16;		incy = -16;	}
323 		else		{	starty = sy-dimy*16;				endy = sy;	incy = +16;	}
324 
325 		for (y = starty ; y != endy ; y += incy)
326 		{
327 			pdrawgfx(bitmap,Machine->gfx[0],
328 					code++,
329 					color,
330 					flipx, flipy,
331 					sx, y,
332 					&Machine->visible_area,TRANSPARENCY_PEN,0,pri_mask);
333 		}
334 	}
335 }
336 
337 
338 
339 
340 /***************************************************************************
341 
342 
343 								Screen Drawing
344 
345 
346 ***************************************************************************/
347 
VIDEO_UPDATE(esd16)348 VIDEO_UPDATE( esd16 )
349 {
350 	fillbitmap(priority_bitmap,    0, cliprect);
351 
352 	tilemap_set_scrollx(esdtilemap_0, 0, esd16_scroll_0[0]);
353 	tilemap_set_scrolly(esdtilemap_0, 0, esd16_scroll_0[1]);
354 
355 	tilemap_set_scrollx(esdtilemap_1, 0, esd16_scroll_1[0]);
356 	tilemap_set_scrolly(esdtilemap_1, 0, esd16_scroll_1[1]);
357 
358 	tilemap_draw(bitmap,cliprect,esdtilemap_0,0,0);
359 	tilemap_draw(bitmap,cliprect,esdtilemap_1,0,1);
360 	esd16_draw_sprites(bitmap,cliprect);
361 }
362 
363 
VIDEO_UPDATE(hedpanic)364 VIDEO_UPDATE( hedpanic )
365 {
366 	tilemap_set_scrollx(esdtilemap_0, 0, esd16_scroll_0[0]);
367 	tilemap_set_scrolly(esdtilemap_0, 0, esd16_scroll_0[1]);
368 
369 	fillbitmap(priority_bitmap,    0, cliprect);
370 
371 	if (head_layersize[0] & 0x0001)
372 	{
373 		tilemap_set_scrollx(esdtilemap_0_16x16, 0, esd16_scroll_0[0]);
374 		tilemap_set_scrolly(esdtilemap_0_16x16, 0, esd16_scroll_0[1]);
375 		tilemap_draw(bitmap,cliprect,esdtilemap_0_16x16,0,0);
376 	}
377 	else
378 	{
379 		tilemap_set_scrollx(esdtilemap_0, 0, esd16_scroll_0[0]);
380 		tilemap_set_scrolly(esdtilemap_0, 0, esd16_scroll_0[1]);
381 		tilemap_draw(bitmap,cliprect,esdtilemap_0,0,0);
382 	}
383 
384 	if (head_layersize[0]&0x0002)
385 	{
386 		tilemap_set_scrollx(esdtilemap_1_16x16, 0, esd16_scroll_1[0]);
387 		tilemap_set_scrolly(esdtilemap_1_16x16, 0, esd16_scroll_1[1]);
388 		tilemap_draw(bitmap,cliprect,esdtilemap_1_16x16,0,1);
389 	}
390 	else
391 	{
392 		tilemap_set_scrollx(esdtilemap_1, 0, esd16_scroll_1[0]);
393 		tilemap_set_scrolly(esdtilemap_1, 0, esd16_scroll_1[1]);
394 		tilemap_draw(bitmap,cliprect,esdtilemap_1,0,1);
395 	}
396 
397 	hedpanic_draw_sprites(bitmap,cliprect);
398 }
399 
400 
VIDEO_UPDATE(hedpanio)401 VIDEO_UPDATE( hedpanio )
402 {
403 	fillbitmap(priority_bitmap,    0, cliprect);
404 
405 	if (head_layersize[0]&0x0001)
406 	{
407 		tilemap_set_scrollx(esdtilemap_0_16x16, 0, esd16_scroll_0[0]);
408 		tilemap_set_scrolly(esdtilemap_0_16x16, 0, esd16_scroll_0[1]);
409 		tilemap_draw(bitmap,cliprect,esdtilemap_0_16x16,0,0);
410 	}
411 	else
412 	{
413 		tilemap_set_scrollx(esdtilemap_0, 0, esd16_scroll_0[0]);
414 		tilemap_set_scrolly(esdtilemap_0, 0, esd16_scroll_0[1]);
415 		tilemap_draw(bitmap,cliprect,esdtilemap_0,0,0);
416 	}
417 
418 	if (head_layersize[0]&0x0002)
419 	{
420 		tilemap_set_scrollx(esdtilemap_1_16x16, 0, esd16_scroll_1[0]);
421 		tilemap_set_scrolly(esdtilemap_1_16x16, 0, esd16_scroll_1[1]);
422 		tilemap_draw(bitmap,cliprect,esdtilemap_1_16x16,0,1);
423 	}
424 	else
425 	{
426 		tilemap_set_scrollx(esdtilemap_1, 0, esd16_scroll_1[0]);
427 		tilemap_set_scrolly(esdtilemap_1, 0, esd16_scroll_1[1]);
428 		tilemap_draw(bitmap,cliprect,esdtilemap_1,0,1);
429 	}
430 
431 	esd16_draw_sprites(bitmap,cliprect);
432 }
433