1 /***************************************************************************
2 
3 	breakthru:vidhrdw.c
4 
5 ***************************************************************************/
6 
7 #include "driver.h"
8 #include "vidhrdw/generic.h"
9 
10 
11 unsigned char *brkthru_scroll;
12 unsigned char *brkthru_videoram;
13 size_t brkthru_videoram_size;
14 static int bgscroll;
15 static int bgbasecolor;
16 static int flipscreen;
17 
18 static struct tilemap *fg_tilemap;
19 static struct tilemap *bg_tilemap;
20 
21 
22 /***************************************************************************
23 
24   Convert the color PROMs into a more useable format.
25 
26   Break Thru has one 256x8 and one 256x4 palette PROMs.
27   I don't know for sure how the palette PROMs are connected to the RGB
28   output, but it's probably the usual:
29 
30   bit 7 -- 220 ohm resistor  -- GREEN
31         -- 470 ohm resistor  -- GREEN
32         -- 1  kohm resistor  -- GREEN
33         -- 2.2kohm resistor  -- GREEN
34         -- 220 ohm resistor  -- RED
35         -- 470 ohm resistor  -- RED
36         -- 1  kohm resistor  -- RED
37   bit 0 -- 2.2kohm resistor  -- RED
38 
39   bit 3 -- 220 ohm resistor  -- BLUE
40         -- 470 ohm resistor  -- BLUE
41         -- 1  kohm resistor  -- BLUE
42   bit 0 -- 2.2kohm resistor  -- BLUE
43 
44 ***************************************************************************/
PALETTE_INIT(brkthru)45 PALETTE_INIT( brkthru )
46 {
47 	int i;
48 
49 
50 	for (i = 0;i < Machine->drv->total_colors;i++)
51 	{
52 		int bit0,bit1,bit2,bit3,r,g,b;
53 
54 
55 		bit0 = (color_prom[0] >> 0) & 0x01;
56 		bit1 = (color_prom[0] >> 1) & 0x01;
57 		bit2 = (color_prom[0] >> 2) & 0x01;
58 		bit3 = (color_prom[0] >> 3) & 0x01;
59 		r = 0x0e * bit0 + 0x1f * bit1 + 0x43 * bit2 + 0x8f * bit3;
60 		bit0 = (color_prom[0] >> 4) & 0x01;
61 		bit1 = (color_prom[0] >> 5) & 0x01;
62 		bit2 = (color_prom[0] >> 6) & 0x01;
63 		bit3 = (color_prom[0] >> 7) & 0x01;
64 		g = 0x0e * bit0 + 0x1f * bit1 + 0x43 * bit2 + 0x8f * bit3;
65 		bit0 = (color_prom[Machine->drv->total_colors] >> 0) & 0x01;
66 		bit1 = (color_prom[Machine->drv->total_colors] >> 1) & 0x01;
67 		bit2 = (color_prom[Machine->drv->total_colors] >> 2) & 0x01;
68 		bit3 = (color_prom[Machine->drv->total_colors] >> 3) & 0x01;
69 		b = 0x0e * bit0 + 0x1f * bit1 + 0x43 * bit2 + 0x8f * bit3;
70 
71 		palette_set_color(i,r,g,b);
72 
73 		color_prom++;
74 	}
75 }
76 
77 
78 
79 /***************************************************************************
80 
81   Start the video hardware emulation.
82 
83 ***************************************************************************/
84 
get_bg_tile_info(int tile_index)85 static void get_bg_tile_info(int tile_index)
86 {
87 	/* BG RAM format
88 		0         1
89 		---- -c-- ---- ---- = Color
90 		---- --xx xxxx xxxx = Code
91 	*/
92 
93 	int code = (videoram[tile_index*2] | ((videoram[tile_index*2+1]) << 8)) & 0x3ff;
94 	int region = 1 + (code >> 7);
95 	int colour = bgbasecolor + ((videoram[tile_index*2+1] & 0x04) >> 2);
96 
97 	SET_TILE_INFO(region, code & 0x7f,colour,0)
98 }
99 
WRITE_HANDLER(brkthru_bgram_w)100 WRITE_HANDLER( brkthru_bgram_w )
101 {
102 	if (videoram[offset] != data)
103 	{
104 		videoram[offset] = data;
105 		tilemap_mark_tile_dirty(bg_tilemap,offset/2);
106 	}
107 }
108 
109 
get_fg_tile_info(int tile_index)110 static void get_fg_tile_info(int tile_index)
111 {
112 	data8_t code = brkthru_videoram[tile_index];
113 	SET_TILE_INFO(0, code, 0, 0)
114 }
115 
WRITE_HANDLER(brkthru_fgram_w)116 WRITE_HANDLER( brkthru_fgram_w )
117 {
118 	if (brkthru_videoram[offset] != data)
119 	{
120 		brkthru_videoram[offset] = data;
121 		tilemap_mark_tile_dirty(fg_tilemap,offset);
122 	}
123 }
124 
VIDEO_START(brkthru)125 VIDEO_START( brkthru )
126 {
127 	fg_tilemap = tilemap_create(get_fg_tile_info,tilemap_scan_rows,TILEMAP_TRANSPARENT,8,8,32,32);
128 	bg_tilemap = tilemap_create(get_bg_tile_info,tilemap_scan_cols,TILEMAP_TRANSPARENT,16,16,32,16);
129 
130 	if (!fg_tilemap)
131 		return 1;
132 
133 	if (!bg_tilemap)
134 		return 1;
135 
136 	tilemap_set_transparent_pen( fg_tilemap, 0 );
137 	tilemap_set_transparent_pen( bg_tilemap, 0 );
138 
139 	return 0;
140 }
141 
142 
143 
WRITE_HANDLER(brkthru_1800_w)144 WRITE_HANDLER( brkthru_1800_w )
145 {
146 	if (offset == 0)	/* low 8 bits of scroll */
147 		bgscroll = (bgscroll & 0x100) | data;
148 	else if (offset == 1)
149 	{
150 		int bankaddress;
151 		unsigned char *RAM = memory_region(REGION_CPU1);
152 
153 
154 		/* bit 0-2 = ROM bank select */
155 		bankaddress = 0x10000 + (data & 0x07) * 0x2000;
156 		cpu_setbank(1,&RAM[bankaddress]);
157 
158 		/* bit 3-5 = background tiles color code */
159 		if (((data & 0x38) >> 2) != bgbasecolor)
160 		{
161 			bgbasecolor = (data & 0x38) >> 2;
162 			tilemap_mark_all_tiles_dirty (bg_tilemap);
163 		}
164 
165 		/* bit 6 = screen flip */
166 		if (flipscreen != (data & 0x40))
167 		{
168 			flipscreen = data & 0x40;
169 			tilemap_set_flip(bg_tilemap,flipscreen ? (TILEMAP_FLIPY | TILEMAP_FLIPX) : 0);
170 			tilemap_set_flip(fg_tilemap,flipscreen ? (TILEMAP_FLIPY | TILEMAP_FLIPX) : 0);
171 
172 		}
173 
174 		/* bit 7 = high bit of scroll */
175 		bgscroll = (bgscroll & 0xff) | ((data & 0x80) << 1);
176 	}
177 }
178 
179 
180 #if 0
181 static void show_register( struct mame_bitmap *bitmap, int x, int y, unsigned long data )
182 {
183 	int n;
184 
185 	for( n=0; n<4; n++ ){
186 		drawgfx( bitmap, Machine->uifont,
187 			"0123456789abcdef"[(data>>(12-4*n))&0xf],
188 			0,
189 			1,0,
190 			y, x + n*8,
191 			0,TRANSPARENCY_NONE,0);
192 	}
193 }
194 #endif
195 
196 /***************************************************************************
197 
198   Draw the game screen in the given mame_bitmap.
199   Do NOT call osd_update_display() from this function, it will be called by
200   the main emulation engine.
201 
202 ***************************************************************************/
203 
brkthru_drawsprites(struct mame_bitmap * bitmap,const struct rectangle * cliprect,int prio)204 static void brkthru_drawsprites( struct mame_bitmap *bitmap, const struct rectangle *cliprect, int prio )
205 	{
206 	int offs;
207 	/* Draw the sprites. Note that it is important to draw them exactly in this */
208 	/* order, to have the correct priorities. */
209 
210 	/* Sprite RAM format
211 		0         1         2         3
212 		ccc- ---- ---- ---- ---- ---- ---- ---- = Color
213 		---d ---- ---- ---- ---- ---- ---- ---- = Double Size
214 		---- p--- ---- ---- ---- ---- ---- ---- = Priority
215 		---- -bb- ---- ---- ---- ---- ---- ---- = Bank
216 		---- ---e ---- ---- ---- ---- ---- ---- = Enable/Disable
217 		---- ---- ssss ssss ---- ---- ---- ---- = Sprite code
218 		---- ---- ---- ---- yyyy yyyy ---- ---- = Y position
219 		---- ---- ---- ---- ---- ---- xxxx xxxx = X position
220 	*/
221 
222 	for (offs = 0;offs < spriteram_size; offs += 4)
223 	{
224 		if ((spriteram[offs] & 0x09) == prio)	/* Enable && Low Priority */
225 		{
226 			int sx,sy,code,color;
227 
228 			sx = 240 - spriteram[offs+3];
229 			if (sx < -7) sx += 256;
230 			sy = 240 - spriteram[offs+2];
231 			code = spriteram[offs+1] + 128 * (spriteram[offs] & 0x06);
232 			color = (spriteram[offs] & 0xe0) >> 5;
233 			if (flipscreen)
234 			{
235 				sx = 240 - sx;
236 				sy = 240 - sy;
237 			}
238 
239 			if (spriteram[offs] & 0x10)	/* double height */
240 			{
241 				drawgfx(bitmap,Machine->gfx[9],
242 						code & ~1,
243 						color,
244 						flipscreen,flipscreen,
245 						sx,flipscreen? sy + 16 : sy - 16,
246 						&Machine->visible_area,TRANSPARENCY_PEN,0);
247 				drawgfx(bitmap,Machine->gfx[9],
248 						code | 1,
249 						color,
250 						flipscreen,flipscreen,
251 						sx,sy,
252 						&Machine->visible_area,TRANSPARENCY_PEN,0);
253 
254 				/* redraw with wraparound */
255 				drawgfx(bitmap,Machine->gfx[9],
256 						code & ~1,
257 						color,
258 						flipscreen,flipscreen,
259 						sx,(flipscreen? sy + 16 : sy - 16) + 256,
260 						&Machine->visible_area,TRANSPARENCY_PEN,0);
261 				drawgfx(bitmap,Machine->gfx[9],
262 						code | 1,
263 						color,
264 						flipscreen,flipscreen,
265 						sx,sy + 256,
266 						&Machine->visible_area,TRANSPARENCY_PEN,0);
267 
268 			}
269 			else
270 			{
271 				drawgfx(bitmap,Machine->gfx[9],
272 						code,
273 						color,
274 						flipscreen,flipscreen,
275 						sx,sy,
276 						&Machine->visible_area,TRANSPARENCY_PEN,0);
277 
278 				/* redraw with wraparound */
279 				drawgfx(bitmap,Machine->gfx[9],
280 						code,
281 						color,
282 						flipscreen,flipscreen,
283 						sx,sy + 256,
284 						&Machine->visible_area,TRANSPARENCY_PEN,0);
285 
286 			}
287 			}
288 		}
289 	}
290 
VIDEO_UPDATE(brkthru)291 VIDEO_UPDATE( brkthru )
292 	{
293 	tilemap_set_scrollx(bg_tilemap,0, bgscroll);
294 	tilemap_draw(bitmap,cliprect,bg_tilemap,TILEMAP_IGNORE_TRANSPARENCY,0);
295 
296 	/* low priority sprites */
297 	brkthru_drawsprites(bitmap, cliprect, 0x01 );
298 
299 	/* draw background over low priority sprites */
300 	tilemap_draw(bitmap,cliprect,bg_tilemap,0,0);
301 
302 	/* high priority sprites */
303 	brkthru_drawsprites(bitmap, cliprect, 0x09 );
304 
305 	/* fg layer */
306 	tilemap_draw(bitmap,cliprect,fg_tilemap,0,0);
307 
308 /*	show_register(bitmap,8,8,(unsigned long)flipscreen); */
309 
310 }
311