1 /*******************************************************************************
2  WWF Superstars (C) 1989 Technos Japan  (vidhrdw/wwfsstar.c)
3 ********************************************************************************
4  driver by David Haywood
5 
6  see (drivers/wwfsstar.c) for more notes
7 *******************************************************************************/
8 
9 #include "driver.h"
10 #include "vidhrdw/generic.h"
11 
12 data16_t *wwfsstar_fg0_videoram, *wwfsstar_bg0_videoram;
13 extern int wwfsstar_scrollx, wwfsstar_scrolly;
14 static struct tilemap *fg0_tilemap, *bg0_tilemap;
15 
16 /*******************************************************************************
17  Write Handlers
18 ********************************************************************************
19  for writes to Video Ram
20 *******************************************************************************/
21 
WRITE16_HANDLER(wwfsstar_fg0_videoram_w)22 WRITE16_HANDLER( wwfsstar_fg0_videoram_w )
23 {
24 	int oldword = wwfsstar_fg0_videoram[offset];
25 	COMBINE_DATA(&wwfsstar_fg0_videoram[offset]);
26 	if (oldword != wwfsstar_fg0_videoram[offset])
27 		tilemap_mark_tile_dirty(fg0_tilemap,offset/2);
28 }
29 
WRITE16_HANDLER(wwfsstar_bg0_videoram_w)30 WRITE16_HANDLER( wwfsstar_bg0_videoram_w )
31 {
32 	int oldword =wwfsstar_bg0_videoram[offset];
33 	COMBINE_DATA(&wwfsstar_bg0_videoram[offset]);
34 	if (oldword != wwfsstar_bg0_videoram[offset])
35 		tilemap_mark_tile_dirty(bg0_tilemap,offset/2);
36 }
37 
38 /*******************************************************************************
39  Tilemap Related Functions
40 *******************************************************************************/
41 
get_fg0_tile_info(int tile_index)42 static void get_fg0_tile_info(int tile_index)
43 {
44 	/*- FG0 RAM Format -**
45 
46 	  0x1000 sized region (4096 bytes)
47 
48 	  32x32 tilemap, 4 bytes per tile
49 
50 	  ---- ----  CCCC TTTT  ---- ----  TTTT TTTT
51 
52 	  C = Colour Bank (0-15)
53 	  T = Tile Number (0 - 4095)
54 
55 	  other bits unknown / unused
56 
57 	**- End of Comments -*/
58 
59 	data16_t *tilebase;
60 	int tileno;
61 	int colbank;
62 	tilebase =  &wwfsstar_fg0_videoram[tile_index*2];
63 	tileno =  (tilebase[1] & 0x00ff) | ((tilebase[0] & 0x000f) << 8);
64 	colbank = (tilebase[0] & 0x00f0) >> 4;
65 	SET_TILE_INFO(
66 			0,
67 			tileno,
68 			colbank,
69 			0)
70 }
71 
bg0_scan(UINT32 col,UINT32 row,UINT32 num_cols,UINT32 num_rows)72 static UINT32 bg0_scan(UINT32 col,UINT32 row,UINT32 num_cols,UINT32 num_rows)
73 {
74 	return (col & 0x0f) + ((row & 0x0f) << 4) + ((col & 0x10) << 4) + ((row & 0x10) << 5);
75 }
76 
get_bg0_tile_info(int tile_index)77 static void get_bg0_tile_info(int tile_index)
78 {
79 	/*- BG0 RAM Format -**
80 
81 	  0x1000 sized region (4096 bytes)
82 
83 	  32x32 tilemap, 4 bytes per tile
84 
85 	  ---- ----  FCCC TTTT  ---- ----  TTTT TTTT
86 
87 	  C = Colour Bank (0-7)
88 	  T = Tile Number (0 - 4095)
89 	  F = FlipX
90 
91 	  other bits unknown / unused
92 
93 	**- End of Comments -*/
94 
95 	data16_t *tilebase;
96 	int tileno, colbank, flipx;
97 	tilebase =  &wwfsstar_bg0_videoram[tile_index*2];
98 	tileno =  (tilebase[1] & 0x00ff) | ((tilebase[0] & 0x000f) << 8);
99 	colbank = (tilebase[0] & 0x0070) >> 4;
100 	flipx   = (tilebase[0] & 0x0080) >> 7;
101 	SET_TILE_INFO(
102 			2,
103 			tileno,
104 			colbank,
105 			flipx ? TILE_FLIPX : 0)
106 }
107 
108 /*******************************************************************************
109  Sprite Related Functions
110 ********************************************************************************
111  sprite colour marking could probably be improved..
112 *******************************************************************************/
113 
wwfsstar_drawsprites(struct mame_bitmap * bitmap,const struct rectangle * cliprect)114 static void wwfsstar_drawsprites( struct mame_bitmap *bitmap, const struct rectangle *cliprect )
115 {
116 	/*- SPR RAM Format -**
117 
118 	  0x3FF sized region (1024 bytes)
119 
120 	  10 bytes per sprite
121 
122 	  ---- ---- yyyy yyyy ---- ---- CCCC XYLE ---- ---- fFNN NNNN ---- ---- nnnn nnnn ---- ---- xxxx xxxx
123 
124 	  Yy = sprite Y Position
125 	  Xx = sprite X Position
126 	  C  = colour bank
127 	  f  = flip Y
128 	  F  = flip X
129 	  L  = chain sprite (32x16)
130 	  E  = sprite enable
131 	  Nn = Sprite Number
132 
133 	  other bits unused
134 
135 	**- End of Comments -*/
136 
137 	const struct GfxElement *gfx = Machine->gfx[1];
138 	data16_t *source = spriteram16;
139 	data16_t *finish = source + 0x3ff/2;
140 
141 	while (source < finish)
142 	{
143 		int xpos, ypos, colourbank, flipx, flipy, chain, enable, number, count;
144 
145 		enable = (source [1] & 0x0001);
146 
147 		if (enable)
148 		{
149 			ypos = ((source [0] & 0x00ff) | ((source [1] & 0x0004) << 6) );
150 			ypos = (((256 - ypos) & 0x1ff) - 16) ;
151 			xpos = ((source [4] & 0x00ff) | ((source [1] & 0x0008) << 5) );
152 			xpos = (((256 - xpos) & 0x1ff) - 16);
153 			flipx = (source [2] & 0x0080 ) >> 7;
154 			flipy = (source [2] & 0x0040 ) >> 6;
155 			chain = (source [1] & 0x0002 ) >> 1;
156 			chain += 1;
157 			number = (source [3] & 0x00ff) | ((source [2] & 0x003f) << 8);
158 			colourbank = (source [1] & 0x00f0) >> 4;
159 
160 			if (flip_screen)
161 			{
162 				flipy = !flipy;
163 				flipx = !flipx;
164 				ypos=240-ypos;
165 				xpos=240-xpos;
166 			}
167 
168 			for (count=0;count<chain;count++)
169 			{
170 				if (flip_screen)
171 				{
172 					if (!flipy)
173 					{
174 						drawgfx(bitmap,gfx,number+count,colourbank,flipx,flipy,xpos,ypos+16*count,cliprect,TRANSPARENCY_PEN,0);
175 					}
176 					else
177 					{
178 						drawgfx(bitmap,gfx,number+count,colourbank,flipx,flipy,xpos,ypos+(16*(chain-1))-(16*count),cliprect,TRANSPARENCY_PEN,0);
179 					}
180 				}
181 				else
182 				{
183 					if (!flipy)
184 					{
185 						drawgfx(bitmap,gfx,number+count,colourbank,flipx,flipy,xpos,ypos-(16*(chain-1))+(16*count),cliprect,TRANSPARENCY_PEN,0);
186 					}
187 					else
188 					{
189 						drawgfx(bitmap,gfx,number+count,colourbank,flipx,flipy,xpos,ypos-16*count,cliprect,TRANSPARENCY_PEN,0);
190 					}
191 				}
192 			}
193 		}
194 
195 	source+=5;
196 	}
197 }
198 
199 /*******************************************************************************
200  Video Start and Refresh Functions
201 ********************************************************************************
202  Drawing Order is simple
203  BG0 - Back
204  SPR - Middle
205  FG0 - Front
206 *******************************************************************************/
207 
208 
VIDEO_START(wwfsstar)209 VIDEO_START( wwfsstar )
210 {
211 	fg0_tilemap = tilemap_create(get_fg0_tile_info,tilemap_scan_rows,TILEMAP_TRANSPARENT, 8, 8,32,32);
212 	tilemap_set_transparent_pen(fg0_tilemap,0);
213 
214 	bg0_tilemap = tilemap_create(get_bg0_tile_info,bg0_scan,TILEMAP_OPAQUE, 16, 16,32,32);
215 	tilemap_set_transparent_pen(fg0_tilemap,0);
216 
217 	if (!fg0_tilemap || !bg0_tilemap)
218 		return 1;
219 
220 	return 0;
221 }
222 
VIDEO_UPDATE(wwfsstar)223 VIDEO_UPDATE( wwfsstar )
224 {
225 	tilemap_set_scrolly( bg0_tilemap, 0, wwfsstar_scrolly  );
226 	tilemap_set_scrollx( bg0_tilemap, 0, wwfsstar_scrollx  );
227 
228 	tilemap_draw(bitmap,cliprect,bg0_tilemap,0,0);
229 	wwfsstar_drawsprites( bitmap,cliprect );
230 	tilemap_draw(bitmap,cliprect,fg0_tilemap,0,0);
231 }
232