1 /***************************************************************************
2
3 Tumblepop Video emulation - Bryan McPhail, mish@tendril.co.uk
4
5 *********************************************************************
6
7 Uses Data East custom chip 55 for backgrounds, custom chip 52 for sprites.
8
9 See Dark Seal & Caveman Ninja drivers for info on these chips.
10
11 Tumblepop is one of few games to take advantage of the playfields ability
12 to switch between 8*8 tiles and 16*16 tiles.
13
14 ***************************************************************************/
15
16 #include "driver.h"
17 #include "vidhrdw/generic.h"
18
19 static unsigned char tumblep_control_0[16];
20 unsigned char *tumblep_pf1_data,*tumblep_pf2_data;
21 static struct tilemap *pf1_tilemap,*pf1_alt_tilemap,*pf2_tilemap;
22 static unsigned char *gfx_base;
23 static int gfx_bank,flipscreen;
24
25 /******************************************************************************/
26
tumblep_mark_sprite_colours(void)27 static void tumblep_mark_sprite_colours(void)
28 {
29 int offs,color,i,pal_base,colmask[16];
30 unsigned int *pen_usage;
31
32 palette_init_used_colors();
33
34 pen_usage=Machine->gfx[3]->pen_usage;
35 pal_base = Machine->drv->gfxdecodeinfo[3].color_codes_start;
36 for (color = 0;color < 16;color++) colmask[color] = 0;
37
38 for (offs = 0;offs < 0x800;offs += 8)
39 {
40 int x,y,sprite,multi;
41
42 sprite = READ_WORD (&spriteram[offs+2]) & 0x3fff;
43 if (!sprite) continue;
44
45 y = READ_WORD(&spriteram[offs]);
46 x = READ_WORD(&spriteram[offs+4]);
47 color = (x >>9) &0xf;
48
49 multi = (1 << ((y & 0x0600) >> 9)) - 1; /* 1x, 2x, 4x, 8x height */
50
51 sprite &= ~multi;
52
53 while (multi >= 0)
54 {
55 colmask[color] |= pen_usage[sprite + multi];
56 multi--;
57 }
58 }
59
60 for (color = 0;color < 16;color++)
61 {
62 for (i = 1;i < 16;i++)
63 {
64 if (colmask[color] & (1 << i))
65 palette_used_colors[pal_base + 16 * color + i] = PALETTE_COLOR_USED;
66 }
67 }
68
69 if (palette_recalc())
70 tilemap_mark_all_pixels_dirty(ALL_TILEMAPS);
71 }
72
tumblep_drawsprites(struct osd_bitmap * bitmap)73 static void tumblep_drawsprites(struct osd_bitmap *bitmap)
74 {
75 int offs;
76
77 for (offs = 0;offs < 0x800;offs += 8)
78 {
79 int x,y,sprite,colour,multi,fx,fy,inc,flash,mult;
80
81 sprite = READ_WORD (&spriteram[offs+2]) & 0x3fff;
82 if (!sprite) continue;
83
84 y = READ_WORD(&spriteram[offs]);
85 flash=y&0x1000;
86 if (flash && (cpu_getcurrentframe() & 1)) continue;
87
88 x = READ_WORD(&spriteram[offs+4]);
89 colour = (x >>9) & 0xf;
90
91 fx = y & 0x2000;
92 fy = y & 0x4000;
93 multi = (1 << ((y & 0x0600) >> 9)) - 1; /* 1x, 2x, 4x, 8x height */
94
95 x = x & 0x01ff;
96 y = y & 0x01ff;
97 if (x >= 320) x -= 512;
98 if (y >= 256) y -= 512;
99 y = 240 - y;
100 x = 304 - x;
101
102 sprite &= ~multi;
103 if (fy)
104 inc = -1;
105 else
106 {
107 sprite += multi;
108 inc = 1;
109 }
110
111 if (flipscreen)
112 {
113 y=240-y;
114 x=304-x;
115 if (fx) fx=0; else fx=1;
116 if (fy) fy=0; else fy=1;
117 mult=16;
118 }
119 else mult=-16;
120
121 while (multi >= 0)
122 {
123 drawgfx(bitmap,Machine->gfx[3],
124 sprite - multi * inc,
125 colour,
126 fx,fy,
127 x,y + mult * multi,
128 &Machine->visible_area,TRANSPARENCY_PEN,0);
129
130 multi--;
131 }
132 }
133 }
134
135 /******************************************************************************/
136
WRITE_HANDLER(tumblep_pf1_data_w)137 WRITE_HANDLER( tumblep_pf1_data_w )
138 {
139 COMBINE_WORD_MEM(&tumblep_pf1_data[offset],data);
140 tilemap_mark_tile_dirty(pf1_tilemap,offset/2);
141 tilemap_mark_tile_dirty(pf1_alt_tilemap,offset/2);
142 }
143
WRITE_HANDLER(tumblep_pf2_data_w)144 WRITE_HANDLER( tumblep_pf2_data_w )
145 {
146 COMBINE_WORD_MEM(&tumblep_pf2_data[offset],data);
147 tilemap_mark_tile_dirty(pf2_tilemap,offset/2);
148 }
149
WRITE_HANDLER(tumblep_control_0_w)150 WRITE_HANDLER( tumblep_control_0_w )
151 {
152 COMBINE_WORD_MEM(&tumblep_control_0[offset],data);
153 }
154
155 /******************************************************************************/
156
tumblep_scan(UINT32 col,UINT32 row,UINT32 num_cols,UINT32 num_rows)157 static UINT32 tumblep_scan(UINT32 col,UINT32 row,UINT32 num_cols,UINT32 num_rows)
158 {
159 /* logical (col,row) -> memory offset */
160 return (col & 0x1f) + ((row & 0x1f) << 5) + ((col & 0x20) << 5);
161 }
162
get_bg_tile_info(int tile_index)163 static void get_bg_tile_info(int tile_index)
164 {
165 int tile,color;
166
167 tile=READ_WORD(&gfx_base[2*tile_index]);
168 color=tile >> 12;
169 tile=tile&0xfff;
170
171 SET_TILE_INFO(gfx_bank,tile,color)
172 }
173
get_fg_tile_info(int tile_index)174 static void get_fg_tile_info(int tile_index)
175 {
176 int tile=READ_WORD(&tumblep_pf1_data[2*tile_index]);
177 int color=tile >> 12;
178
179 tile=tile&0xfff;
180 SET_TILE_INFO(0,tile,color)
181 }
182
tumblep_vh_start(void)183 int tumblep_vh_start(void)
184 {
185 pf1_tilemap = tilemap_create(get_fg_tile_info,tilemap_scan_rows,TILEMAP_TRANSPARENT, 8, 8,64,32);
186 pf1_alt_tilemap = tilemap_create(get_bg_tile_info,tumblep_scan,TILEMAP_TRANSPARENT,16,16,64,32);
187 pf2_tilemap = tilemap_create(get_bg_tile_info,tumblep_scan,TILEMAP_OPAQUE, 16,16,64,32);
188
189 if (!pf1_tilemap || !pf1_alt_tilemap || !pf2_tilemap)
190 return 1;
191
192 pf1_tilemap->transparent_pen = 0;
193 pf1_alt_tilemap->transparent_pen = 0;
194
195 return 0;
196 }
197
198 /******************************************************************************/
199
tumblep_vh_screenrefresh(struct osd_bitmap * bitmap,int full_refresh)200 void tumblep_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
201 {
202 int offs;
203
204 flipscreen=(READ_WORD(&tumblep_control_0[0])&0x80);
205 tilemap_set_flip(ALL_TILEMAPS,flipscreen ? (TILEMAP_FLIPY | TILEMAP_FLIPX) : 0);
206 if (flipscreen) offs=1; else offs=-1;
207
208 tilemap_set_scrollx( pf1_tilemap,0, READ_WORD(&tumblep_control_0[2])+offs );
209 tilemap_set_scrolly( pf1_tilemap,0, READ_WORD(&tumblep_control_0[4]) );
210 tilemap_set_scrollx( pf1_alt_tilemap,0, READ_WORD(&tumblep_control_0[2])+offs );
211 tilemap_set_scrolly( pf1_alt_tilemap,0, READ_WORD(&tumblep_control_0[4]) );
212 tilemap_set_scrollx( pf2_tilemap,0, READ_WORD(&tumblep_control_0[6])+offs );
213 tilemap_set_scrolly( pf2_tilemap,0, READ_WORD(&tumblep_control_0[8]) );
214
215 gfx_bank=1;
216 gfx_base=tumblep_pf2_data;
217 tilemap_update(pf2_tilemap);
218 gfx_bank=2;
219 gfx_base=tumblep_pf1_data;
220 tilemap_update(pf1_alt_tilemap);
221 tilemap_update(pf1_tilemap);
222
223 tumblep_mark_sprite_colours();
224 tilemap_render(ALL_TILEMAPS);
225
226 tilemap_draw(bitmap,pf2_tilemap,0);
227 if (READ_WORD(&tumblep_control_0[0xc])&0x80)
228 tilemap_draw(bitmap,pf1_tilemap,0);
229 else
230 tilemap_draw(bitmap,pf1_alt_tilemap,0);
231 tumblep_drawsprites(bitmap);
232 }
233
tumblepb_vh_screenrefresh(struct osd_bitmap * bitmap,int full_refresh)234 void tumblepb_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
235 {
236 int offs,offs2;
237
238 flipscreen=(READ_WORD(&tumblep_control_0[0])&0x80);
239 tilemap_set_flip(ALL_TILEMAPS,flipscreen ? (TILEMAP_FLIPY | TILEMAP_FLIPX) : 0);
240 if (flipscreen) offs=1; else offs=-1;
241 if (flipscreen) offs2=-3; else offs2=-5;
242
243 tilemap_set_scrollx( pf1_tilemap,0, READ_WORD(&tumblep_control_0[2])+offs2 );
244 tilemap_set_scrolly( pf1_tilemap,0, READ_WORD(&tumblep_control_0[4]) );
245 tilemap_set_scrollx( pf1_alt_tilemap,0, READ_WORD(&tumblep_control_0[2])+offs2 );
246 tilemap_set_scrolly( pf1_alt_tilemap,0, READ_WORD(&tumblep_control_0[4]) );
247 tilemap_set_scrollx( pf2_tilemap,0, READ_WORD(&tumblep_control_0[6])+offs );
248 tilemap_set_scrolly( pf2_tilemap,0, READ_WORD(&tumblep_control_0[8]) );
249
250 gfx_bank=1;
251 gfx_base=tumblep_pf2_data;
252 tilemap_update(pf2_tilemap);
253 gfx_bank=2;
254 gfx_base=tumblep_pf1_data;
255 tilemap_update(pf1_tilemap);
256 tilemap_update(pf1_alt_tilemap);
257
258 tumblep_mark_sprite_colours();
259 tilemap_render(ALL_TILEMAPS);
260
261 tilemap_draw(bitmap,pf2_tilemap,0);
262 if (READ_WORD(&tumblep_control_0[0xc])&0x80)
263 tilemap_draw(bitmap,pf1_tilemap,0);
264 else
265 tilemap_draw(bitmap,pf1_alt_tilemap,0);
266 tumblep_drawsprites(bitmap);
267 }
268