1 /***************************************************************************
2 
3 	Prehistoric Isle video routines
4 
5 	Emulation by Bryan McPhail, mish@tendril.co.uk
6 
7 ***************************************************************************/
8 
9 #include "driver.h"
10 #include "vidhrdw/generic.h"
11 
12 
13 UINT16 *prehisle_bg_videoram16;
14 
15 static int invert_controls;
16 
17 static struct tilemap *bg2_tilemap, *bg_tilemap, *fg_tilemap;
18 
19 
WRITE16_HANDLER(prehisle_bg_videoram16_w)20 WRITE16_HANDLER( prehisle_bg_videoram16_w )
21 {
22 	UINT16 oldword = prehisle_bg_videoram16[offset];
23 	COMBINE_DATA(&prehisle_bg_videoram16[offset]);
24 	if (oldword != prehisle_bg_videoram16[offset])
25 	{
26 		tilemap_mark_tile_dirty(bg_tilemap, offset);
27 	}
28 }
29 
WRITE16_HANDLER(prehisle_fg_videoram16_w)30 WRITE16_HANDLER( prehisle_fg_videoram16_w )
31 {
32 	UINT16 oldword = videoram16[offset];
33 	COMBINE_DATA(&videoram16[offset]);
34 	if (oldword != videoram16[offset])
35 	{
36 		tilemap_mark_tile_dirty(fg_tilemap, offset);
37 	}
38 }
39 
READ16_HANDLER(prehisle_control16_r)40 READ16_HANDLER( prehisle_control16_r )
41 {
42 	switch (offset)
43 	{
44 	case 0x08: return readinputport(1);						// Player 2
45 	case 0x10: return readinputport(2);						// Coins, Tilt, Service
46 	case 0x20: return readinputport(0) ^ invert_controls;	// Player 1
47 	case 0x21: return readinputport(3);						// DIPs
48 	case 0x22: return readinputport(4);						// DIPs + VBLANK
49 	default: return 0;
50 	}
51 }
52 
WRITE16_HANDLER(prehisle_control16_w)53 WRITE16_HANDLER( prehisle_control16_w )
54 {
55 	int scroll;
56 
57 	COMBINE_DATA(&scroll);
58 
59 	switch (offset)
60 	{
61 	case 0x00: tilemap_set_scrolly(bg_tilemap, 0, scroll); break;
62 	case 0x08: tilemap_set_scrollx(bg_tilemap, 0, scroll); break;
63 	case 0x10: tilemap_set_scrolly(bg2_tilemap, 0, scroll); break;
64 	case 0x18: tilemap_set_scrollx(bg2_tilemap, 0, scroll); break;
65 	case 0x23: invert_controls = data ? 0xff : 0x00; break;
66 	case 0x30: flip_screen_set(data & 0x01); break;
67 	}
68 }
69 
get_bg2_tile_info(int tile_index)70 static void get_bg2_tile_info(int tile_index)
71 {
72 	UINT8 *tilerom = memory_region(REGION_GFX5);
73 
74 	int offs = tile_index * 2;
75 	int attr = tilerom[offs + 1] + (tilerom[offs] << 8);
76 	int code = (attr & 0x7ff) | 0x800;
77 	int color = attr >> 12;
78 	int flags = (attr & 0x800) ? TILE_FLIPX : 0;
79 
80 	SET_TILE_INFO(1, code, color, flags)
81 }
82 
get_bg_tile_info(int tile_index)83 static void get_bg_tile_info(int tile_index)
84 {
85 	int attr = prehisle_bg_videoram16[tile_index];
86 	int code = attr & 0x7ff;
87 	int color = attr >> 12;
88 	int flags = (attr & 0x800) ? TILE_FLIPY : 0;
89 
90 	SET_TILE_INFO(2, code, color, flags)
91 }
92 
get_fg_tile_info(int tile_index)93 static void get_fg_tile_info(int tile_index)
94 {
95 	int attr = videoram16[tile_index];
96 	int code = attr & 0xfff;
97 	int color = attr >> 12;
98 
99 	SET_TILE_INFO(0, code, color, 0)
100 }
101 
VIDEO_START(prehisle)102 VIDEO_START( prehisle )
103 {
104 	bg2_tilemap = tilemap_create(get_bg2_tile_info, tilemap_scan_cols,
105 		TILEMAP_OPAQUE, 16, 16, 1024, 32);
106 
107 	if ( !bg2_tilemap )
108 		return 1;
109 
110 	bg_tilemap = tilemap_create(get_bg_tile_info, tilemap_scan_cols,
111 		TILEMAP_TRANSPARENT, 16, 16, 256, 32);
112 
113 	if ( !bg_tilemap )
114 		return 1;
115 
116 	fg_tilemap = tilemap_create(get_fg_tile_info, tilemap_scan_rows,
117 		TILEMAP_TRANSPARENT, 8, 8, 32, 32);
118 
119 	if ( !fg_tilemap )
120 		return 1;
121 
122 	tilemap_set_transparent_pen(bg_tilemap, 15);
123 	tilemap_set_transparent_pen(fg_tilemap, 15);
124 
125 	return 0;
126 }
127 
prehisle_draw_sprites(struct mame_bitmap * bitmap,const struct rectangle * cliprect)128 static void prehisle_draw_sprites( struct mame_bitmap *bitmap, const struct rectangle *cliprect )
129 {
130 	int offs;
131 
132 	for (offs = 0; offs < 1024; offs += 4)
133 	{
134 		int attr = spriteram16[offs + 2];
135 		int code = attr & 0x1fff;
136 		int color = spriteram16[offs + 3] >> 12;
137 		int flipx = attr & 0x4000;
138 		int flipy = attr & 0x8000;
139 		int sx = spriteram16[offs + 1];
140 		int sy = spriteram16[offs];
141 
142 		if (sx & 0x200) sx = -(0xff - (sx & 0xff));	// wraparound
143 
144 		if (flip_screen)
145 		{
146 			sx = 240 - sx;
147 			sy = 240 - sy;
148 			flipx = !flipx;
149 			flipy = !flipy;
150 		}
151 
152 		drawgfx(bitmap, Machine->gfx[3], code, color, flipx, flipy, sx, sy,
153 			cliprect, TRANSPARENCY_PEN, 15);
154 	}
155 }
156 
VIDEO_UPDATE(prehisle)157 VIDEO_UPDATE( prehisle )
158 {
159 	tilemap_draw(bitmap, cliprect, bg2_tilemap, 0, 0);
160 	tilemap_draw(bitmap, cliprect, bg_tilemap, 0, 0);
161 	prehisle_draw_sprites(bitmap, cliprect);
162 	tilemap_draw(bitmap, cliprect, fg_tilemap, 0, 0);
163 }
164