1 /* vidhrdw/tbowl.c */
2 
3 /* see drivers/tbowl.c for more info */
4 
5 #include "driver.h"
6 #include "vidhrdw/generic.h"
7 
8 static struct tilemap *tx_tilemap, *bg_tilemap, *bg2_tilemap;
9 data8_t *tbowl_txvideoram, *tbowl_bgvideoram, *tbowl_bg2videoram;
10 data8_t *tbowl_spriteram;
11 
12 /*** Tilemap Stuff
13 
14 ***/
15 
16 static UINT16 tbowl_xscroll;
17 static UINT16 tbowl_yscroll;
18 
19 static UINT16 tbowl_bg2xscroll;
20 static UINT16 tbowl_bg2yscroll;
21 
22 /* Foreground Layer (tx) Tilemap */
23 
get_tx_tile_info(int tile_index)24 static void get_tx_tile_info(int tile_index)
25 {
26 	int tileno;
27 	int col;
28 
29 	tileno = tbowl_txvideoram[tile_index] | ((tbowl_txvideoram[tile_index+0x800] & 0x07) << 8);
30 	col = (tbowl_txvideoram[tile_index+0x800] & 0xf0) >> 4;
31 
32 	SET_TILE_INFO(0,tileno,col,0)
33 }
34 
WRITE_HANDLER(tbowl_txvideoram_w)35 WRITE_HANDLER( tbowl_txvideoram_w )
36 {
37 	if (tbowl_txvideoram[offset] != data)
38 	{
39 		tbowl_txvideoram[offset] = data;
40 		tilemap_mark_tile_dirty(tx_tilemap,offset & 0x7ff);
41 	}
42 }
43 
44 /* Bottom BG Layer (bg) Tilemap */
45 
get_bg_tile_info(int tile_index)46 static void get_bg_tile_info(int tile_index)
47 {
48 	int tileno;
49 	int col;
50 
51 	tileno = tbowl_bgvideoram[tile_index] | ((tbowl_bgvideoram[tile_index+0x1000] & 0x0f) << 8);
52 	col = (tbowl_bgvideoram[tile_index+0x1000] & 0xf0) >> 4;
53 
54 	SET_TILE_INFO(1,tileno,col,0)
55 }
56 
WRITE_HANDLER(tbowl_bg2videoram_w)57 WRITE_HANDLER( tbowl_bg2videoram_w )
58 {
59 	if (tbowl_bg2videoram[offset] != data)
60 	{
61 		tbowl_bg2videoram[offset] = data;
62 		tilemap_mark_tile_dirty(bg2_tilemap,offset & 0xfff);
63 	}
64 }
65 
WRITE_HANDLER(tbowl_bgxscroll_lo)66 WRITE_HANDLER (tbowl_bgxscroll_lo)
67 {
68 tbowl_xscroll = (tbowl_xscroll & 0xff00) | data;
69 tilemap_set_scrollx(bg_tilemap, 0, tbowl_xscroll );
70 }
71 
WRITE_HANDLER(tbowl_bgxscroll_hi)72 WRITE_HANDLER (tbowl_bgxscroll_hi)
73 {
74 tbowl_xscroll = (tbowl_xscroll & 0x00ff) | (data << 8);
75 tilemap_set_scrollx(bg_tilemap, 0, tbowl_xscroll );
76 }
77 
WRITE_HANDLER(tbowl_bgyscroll_lo)78 WRITE_HANDLER (tbowl_bgyscroll_lo)
79 {
80 tbowl_yscroll = (tbowl_yscroll & 0xff00) | data;
81 tilemap_set_scrolly(bg_tilemap, 0, tbowl_yscroll );
82 }
83 
WRITE_HANDLER(tbowl_bgyscroll_hi)84 WRITE_HANDLER (tbowl_bgyscroll_hi)
85 {
86 tbowl_yscroll = (tbowl_yscroll & 0x00ff) | (data << 8);
87 tilemap_set_scrolly(bg_tilemap, 0, tbowl_yscroll );
88 }
89 
90 /* Middle BG Layer (bg2) Tilemaps */
91 
get_bg2_tile_info(int tile_index)92 static void get_bg2_tile_info(int tile_index)
93 {
94 	int tileno;
95 	int col;
96 
97 	tileno = tbowl_bg2videoram[tile_index] | ((tbowl_bg2videoram[tile_index+0x1000] & 0x0f) << 8);
98 	tileno ^= 0x400;
99 	col = (tbowl_bg2videoram[tile_index+0x1000] & 0xf0) >> 4;
100 
101 	SET_TILE_INFO(2,tileno,col,0)
102 }
103 
WRITE_HANDLER(tbowl_bgvideoram_w)104 WRITE_HANDLER( tbowl_bgvideoram_w )
105 {
106 	if (tbowl_bgvideoram[offset] != data)
107 	{
108 		tbowl_bgvideoram[offset] = data;
109 		tilemap_mark_tile_dirty(bg_tilemap,offset & 0xfff);
110 	}
111 }
112 
WRITE_HANDLER(tbowl_bg2xscroll_lo)113 WRITE_HANDLER (tbowl_bg2xscroll_lo)
114 {
115 tbowl_bg2xscroll = (tbowl_bg2xscroll & 0xff00) | data;
116 tilemap_set_scrollx(bg2_tilemap, 0, tbowl_bg2xscroll );
117 }
118 
WRITE_HANDLER(tbowl_bg2xscroll_hi)119 WRITE_HANDLER (tbowl_bg2xscroll_hi)
120 {
121 tbowl_bg2xscroll = (tbowl_bg2xscroll & 0x00ff) | (data << 8);
122 tilemap_set_scrollx(bg2_tilemap, 0, tbowl_bg2xscroll );
123 }
124 
WRITE_HANDLER(tbowl_bg2yscroll_lo)125 WRITE_HANDLER (tbowl_bg2yscroll_lo)
126 {
127 tbowl_bg2yscroll = (tbowl_bg2yscroll & 0xff00) | data;
128 tilemap_set_scrolly(bg2_tilemap, 0, tbowl_bg2yscroll );
129 }
130 
WRITE_HANDLER(tbowl_bg2yscroll_hi)131 WRITE_HANDLER (tbowl_bg2yscroll_hi)
132 {
133 tbowl_bg2yscroll = (tbowl_bg2yscroll & 0x00ff) | (data << 8);
134 tilemap_set_scrolly(bg2_tilemap, 0, tbowl_bg2yscroll );
135 }
136 
draw_sprites(struct mame_bitmap * bitmap,const struct rectangle * cliprect)137 static void draw_sprites(struct mame_bitmap *bitmap,const struct rectangle *cliprect)
138 {
139 	int offs;
140 	const UINT8 layout[8][8] =
141 	{
142 		{0,1,4,5,16,17,20,21},
143 		{2,3,6,7,18,19,22,23},
144 		{8,9,12,13,24,25,28,29},
145 		{10,11,14,15,26,27,30,31},
146 		{32,33,36,37,48,49,52,53},
147 		{34,35,38,39,50,51,54,55},
148 		{40,41,44,45,56,57,60,61},
149 		{42,43,46,47,58,59,62,63}
150 	};
151 
152 	for (offs = 0;offs < 0x800;offs += 8)
153 	{
154 		if (tbowl_spriteram[offs+0] & 0x80)	/* enable */
155 		{
156 			int code,color,sizex,sizey,flipx,flipy,xpos,ypos;
157 			int x,y;/*,priority,priority_mask;*/
158 
159 			code = (tbowl_spriteram[offs+2])+(tbowl_spriteram[offs+1]<<8);
160 			color = (tbowl_spriteram[offs+3])&0x1f;
161 			sizex = 1 << ((tbowl_spriteram[offs+0] & 0x03) >> 0);
162 			sizey = 1 << ((tbowl_spriteram[offs+0] & 0x0c) >> 2);
163 
164 			flipx = (tbowl_spriteram[offs+0])&0x20;
165 			flipy = 0;
166 			xpos = (tbowl_spriteram[offs+6])+((tbowl_spriteram[offs+4]&0x03)<<8);
167 			ypos = (tbowl_spriteram[offs+5])+((tbowl_spriteram[offs+4]&0x10)<<4);
168 
169 			/* bg: 1; fg:2; text: 4 */
170 
171 			for (y = 0;y < sizey;y++)
172 			{
173 				for (x = 0;x < sizex;x++)
174 				{
175 					int sx = xpos + 8*(flipx?(sizex-1-x):x);
176 					int sy = ypos + 8*(flipy?(sizey-1-y):y);
177 					drawgfx(bitmap,Machine->gfx[3],
178 							code + layout[y][x],
179 							color,
180 							flipx,flipy,
181 							sx,sy,
182 							cliprect,TRANSPARENCY_PEN,0 );
183 
184 					/* wraparound */
185 					drawgfx(bitmap,Machine->gfx[3],
186 							code + layout[y][x],
187 							color,
188 							flipx,flipy,
189 							sx,sy-0x200,
190 							cliprect,TRANSPARENCY_PEN,0 );
191 
192 					/* wraparound */
193 					drawgfx(bitmap,Machine->gfx[3],
194 							code + layout[y][x],
195 							color,
196 							flipx,flipy,
197 							sx-0x400,sy,
198 							cliprect,TRANSPARENCY_PEN,0 );
199 
200 					/* wraparound */
201 					drawgfx(bitmap,Machine->gfx[3],
202 							code + layout[y][x],
203 							color,
204 							flipx,flipy,
205 							sx-0x400,sy-0x200,
206 							cliprect,TRANSPARENCY_PEN,0 );
207 
208 
209 
210 				}
211 			}
212 		}
213 	}
214 
215 }
216 
217 
218 /*** Video Start / Update ***/
219 
VIDEO_START(tbowl)220 VIDEO_START( tbowl )
221 {
222 	tx_tilemap = tilemap_create(get_tx_tile_info,tilemap_scan_rows,TILEMAP_TRANSPARENT, 8, 8,64,32);
223 	bg_tilemap = tilemap_create(get_bg_tile_info,tilemap_scan_rows,TILEMAP_TRANSPARENT, 16, 16,128,32);
224 	bg2_tilemap = tilemap_create(get_bg2_tile_info,tilemap_scan_rows,TILEMAP_TRANSPARENT, 16, 16,128,32);
225 
226 	if (!tx_tilemap || !bg_tilemap || !bg2_tilemap)
227 		return 1;
228 
229 	tilemap_set_transparent_pen(tx_tilemap,0);
230 	tilemap_set_transparent_pen(bg_tilemap,0);
231 	tilemap_set_transparent_pen(bg2_tilemap,0);
232 
233 	return 0;
234 }
235 
236 
VIDEO_UPDATE(tbowl)237 VIDEO_UPDATE( tbowl )
238 {
239 	fillbitmap(bitmap,0x100,cliprect); /* is there a register controling the colour? looks odd when screen is blank */
240 	tilemap_draw(bitmap,cliprect,bg_tilemap,0,0);
241 	draw_sprites(bitmap,cliprect);
242 	tilemap_draw(bitmap,cliprect,bg2_tilemap,0,0);
243 	tilemap_draw(bitmap,cliprect,tx_tilemap,0,0);
244 }
245