1 #include "driver.h"
2 #include "vidhrdw/generic.h"
3 
4 unsigned char *blktiger_txvideoram;
5 
6 #define BGRAM_BANK_SIZE 0x1000
7 #define BGRAM_BANKS 4
8 
9 static int blktiger_scroll_bank;
10 static unsigned char *scroll_ram;
11 static int screen_layout;
12 static int chon,objon,bgon;
13 
14 static struct tilemap *tx_tilemap,*bg_tilemap8x4,*bg_tilemap4x8;
15 
16 
17 /***************************************************************************
18 
19   Callbacks for the TileMap code
20 
21 ***************************************************************************/
22 
bg8x4_scan(UINT32 col,UINT32 row,UINT32 num_cols,UINT32 num_rows)23 static UINT32 bg8x4_scan(UINT32 col,UINT32 row,UINT32 num_cols,UINT32 num_rows)
24 {
25 	/* logical (col,row) -> memory offset */
26 	return (col & 0x0f) + ((row & 0x0f) << 4) + ((col & 0x70) << 4) + ((row & 0x30) << 7);
27 }
28 
bg4x8_scan(UINT32 col,UINT32 row,UINT32 num_cols,UINT32 num_rows)29 static UINT32 bg4x8_scan(UINT32 col,UINT32 row,UINT32 num_cols,UINT32 num_rows)
30 {
31 	/* logical (col,row) -> memory offset */
32 	return (col & 0x0f) + ((row & 0x0f) << 4) + ((col & 0x30) << 4) + ((row & 0x70) << 6);
33 }
34 
get_bg_tile_info(int tile_index)35 static void get_bg_tile_info(int tile_index)
36 {
37 	/* the tile priority table is a guess compiled by looking at the game. It
38 	   was not derived from a PROM so it could be wrong. */
39 	static int split_table[16] =
40 	{
41 		3,3,0,0,
42 		0,0,0,0,
43 		0,0,0,0,
44 		0,0,0,0
45 	};
46 	unsigned char attr = scroll_ram[2*tile_index + 1];
47 	int color = (attr & 0x78) >> 3;
48 	SET_TILE_INFO(
49 			1,
50 			scroll_ram[2*tile_index] + ((attr & 0x07) << 8),
51 			color,
52 			TILE_SPLIT(split_table[color]) | ((attr & 0x80) ? TILE_FLIPX : 0))
53 }
54 
get_tx_tile_info(int tile_index)55 static void get_tx_tile_info(int tile_index)
56 {
57 	unsigned char attr = blktiger_txvideoram[tile_index + 0x400];
58 	SET_TILE_INFO(
59 			0,
60 			blktiger_txvideoram[tile_index] + ((attr & 0xe0) << 3),
61 			attr & 0x1f,
62 			0)
63 }
64 
65 
66 /***************************************************************************
67 
68   Start the video hardware emulation.
69 
70 ***************************************************************************/
71 
VIDEO_START(blktiger)72 VIDEO_START( blktiger )
73 {
74 	scroll_ram = auto_malloc(BGRAM_BANK_SIZE * BGRAM_BANKS);
75 
76 	tx_tilemap =    tilemap_create(get_tx_tile_info,tilemap_scan_rows,TILEMAP_TRANSPARENT,8,8,32,32);
77 	bg_tilemap8x4 = tilemap_create(get_bg_tile_info,bg8x4_scan,       TILEMAP_SPLIT,   16,16,128,64);
78 	bg_tilemap4x8 = tilemap_create(get_bg_tile_info,bg4x8_scan,       TILEMAP_SPLIT,   16,16,64,128);
79 
80 	if (!scroll_ram || !tx_tilemap || !bg_tilemap8x4 || !bg_tilemap4x8)
81 		return 1;
82 
83 	tilemap_set_transparent_pen(tx_tilemap,3);
84 
85 	tilemap_set_transmask(bg_tilemap8x4,0,0xffff,0x8000);	/* split type 0 is totally transparent in front half */
86 	tilemap_set_transmask(bg_tilemap8x4,1,0xfff0,0x800f);	/* split type 1 has pens 4-15 transparent in front half */
87 	tilemap_set_transmask(bg_tilemap8x4,2,0xff00,0x80ff);	/* split type 1 has pens 8-15 transparent in front half */
88 	tilemap_set_transmask(bg_tilemap8x4,3,0xf000,0x8fff);	/* split type 1 has pens 12-15 transparent in front half */
89 	tilemap_set_transmask(bg_tilemap4x8,0,0xffff,0x8000);
90 	tilemap_set_transmask(bg_tilemap4x8,1,0xfff0,0x800f);
91 	tilemap_set_transmask(bg_tilemap4x8,2,0xff00,0x80ff);
92 	tilemap_set_transmask(bg_tilemap4x8,3,0xf000,0x8fff);
93 
94 	return 0;
95 }
96 
97 
98 
99 /***************************************************************************
100 
101   Memory handlers
102 
103 ***************************************************************************/
104 
WRITE_HANDLER(blktiger_txvideoram_w)105 WRITE_HANDLER( blktiger_txvideoram_w )
106 {
107 	if (blktiger_txvideoram[offset] != data)
108 	{
109 		blktiger_txvideoram[offset] = data;
110 		tilemap_mark_tile_dirty(tx_tilemap,offset & 0x3ff);
111 	}
112 }
113 
READ_HANDLER(blktiger_bgvideoram_r)114 READ_HANDLER( blktiger_bgvideoram_r )
115 {
116 	return scroll_ram[offset + blktiger_scroll_bank];
117 }
118 
WRITE_HANDLER(blktiger_bgvideoram_w)119 WRITE_HANDLER( blktiger_bgvideoram_w )
120 {
121 	offset += blktiger_scroll_bank;
122 
123 	if (scroll_ram[offset] != data)
124 	{
125 		scroll_ram[offset] = data;
126 		tilemap_mark_tile_dirty(bg_tilemap8x4,offset/2);
127 		tilemap_mark_tile_dirty(bg_tilemap4x8,offset/2);
128 	}
129 }
130 
WRITE_HANDLER(blktiger_bgvideoram_bank_w)131 WRITE_HANDLER( blktiger_bgvideoram_bank_w )
132 {
133 	blktiger_scroll_bank = (data % BGRAM_BANKS) * BGRAM_BANK_SIZE;
134 }
135 
136 
WRITE_HANDLER(blktiger_scrolly_w)137 WRITE_HANDLER( blktiger_scrolly_w )
138 {
139 	static unsigned char scroll[2];
140 	int scrolly;
141 
142 	scroll[offset] = data;
143 	scrolly = scroll[0] | (scroll[1] << 8);
144 	tilemap_set_scrolly(bg_tilemap8x4,0,scrolly);
145 	tilemap_set_scrolly(bg_tilemap4x8,0,scrolly);
146 }
147 
WRITE_HANDLER(blktiger_scrollx_w)148 WRITE_HANDLER( blktiger_scrollx_w )
149 {
150 	static unsigned char scroll[2];
151 	int scrollx;
152 
153 	scroll[offset] = data;
154 	scrollx = scroll[0] | (scroll[1] << 8);
155 	tilemap_set_scrollx(bg_tilemap8x4,0,scrollx);
156 	tilemap_set_scrollx(bg_tilemap4x8,0,scrollx);
157 }
158 
159 
WRITE_HANDLER(blktiger_video_control_w)160 WRITE_HANDLER( blktiger_video_control_w )
161 {
162 	/* bits 0 and 1 are coin counters */
163 	coin_counter_w(0,data & 1);
164 	coin_counter_w(1,data & 2);
165 
166 	/* bit 5 resets the sound CPU */
167 	cpu_set_reset_line(1,(data & 0x20) ? ASSERT_LINE : CLEAR_LINE);
168 
169 	/* bit 6 flips screen */
170 	flip_screen_set(data & 0x40);
171 
172 	/* bit 7 enables characters? Just a guess */
173 	chon = ~data & 0x80;
174 }
175 
WRITE_HANDLER(blktiger_video_enable_w)176 WRITE_HANDLER( blktiger_video_enable_w )
177 {
178 	/* not sure which is which, but I think that bit 1 and 2 enable background and sprites */
179 	/* bit 1 enables bg ? */
180 	bgon = ~data & 0x02;
181 
182 	/* bit 2 enables sprites ? */
183 	objon = ~data & 0x04;
184 }
185 
WRITE_HANDLER(blktiger_screen_layout_w)186 WRITE_HANDLER( blktiger_screen_layout_w )
187 {
188 	screen_layout = data;
189 	tilemap_set_enable(bg_tilemap8x4, screen_layout);
190 	tilemap_set_enable(bg_tilemap4x8,!screen_layout);
191 }
192 
193 
194 
195 /***************************************************************************
196 
197   Display refresh
198 
199 ***************************************************************************/
200 
draw_sprites(struct mame_bitmap * bitmap,const struct rectangle * cliprect)201 static void draw_sprites(struct mame_bitmap *bitmap, const struct rectangle *cliprect)
202 {
203 	int offs;
204 
205 	/* Draw the sprites. */
206 	for (offs = spriteram_size - 4;offs >= 0;offs -= 4)
207 	{
208 		int attr = buffered_spriteram[offs+1];
209 		int sx = buffered_spriteram[offs + 3] - ((attr & 0x10) << 4);
210 		int sy = buffered_spriteram[offs + 2];
211 		int code = buffered_spriteram[offs] | ((attr & 0xe0) << 3);
212 		int color = attr & 0x07;
213 		int flipx = attr & 0x08;
214 
215 		if (flip_screen)
216 		{
217 			sx = 240 - sx;
218 			sy = 240 - sy;
219 			flipx = !flipx;
220 		}
221 
222 		drawgfx(bitmap,Machine->gfx[2],
223 				code,
224 				color,
225 				flipx,flip_screen,
226 				sx,sy,
227 				cliprect,TRANSPARENCY_PEN,15);
228 	}
229 }
230 
VIDEO_UPDATE(blktiger)231 VIDEO_UPDATE( blktiger )
232 {
233 	fillbitmap(bitmap,Machine->pens[1023],cliprect);
234 
235 	if (bgon)
236 		tilemap_draw(bitmap,cliprect,screen_layout ? bg_tilemap8x4 : bg_tilemap4x8,TILEMAP_BACK,0);
237 
238 	if (objon)
239 		draw_sprites(bitmap,cliprect);
240 
241 	if (bgon)
242 		tilemap_draw(bitmap,cliprect,screen_layout ? bg_tilemap8x4 : bg_tilemap4x8,TILEMAP_FRONT,0);
243 
244 	if (chon)
245 		tilemap_draw(bitmap,cliprect,tx_tilemap,0,0);
246 }
247 
VIDEO_EOF(blktiger)248 VIDEO_EOF( blktiger )
249 {
250 	buffer_spriteram_w(0,0);
251 }
252