1 /***************************************************************************
2 
3   vidhrdw.c
4 
5   Functions to emulate the video hardware of the machine.
6 
7 ***************************************************************************/
8 
9 #include "driver.h"
10 #include "vidhrdw/generic.h"
11 
12 UINT8 *tankbatt_bulletsram;
13 size_t tankbatt_bulletsram_size;
14 
15 static struct tilemap *bg_tilemap;
16 
17 /***************************************************************************
18 
19   Convert the color PROMs into a more useable format.
20 
21 ***************************************************************************/
PALETTE_INIT(tankbatt)22 PALETTE_INIT( tankbatt )
23 {
24 	int i;
25 	#define TOTAL_COLORS(gfxn) (Machine->gfx[gfxn]->total_colors * Machine->gfx[gfxn]->color_granularity)
26 	#define COLOR(gfxn,offs) (colortable[Machine->drv->gfxdecodeinfo[gfxn].color_codes_start + offs])
27 
28 	#define RES_1	0xc0 /* this is a guess */
29 	#define RES_2	0x3f /* this is a guess */
30 
31 	/* Stick black in there */
32 	palette_set_color(0,0,0,0);
33 
34 	/* ? Skip the first byte ? */
35 	color_prom++;
36 
37 	for (i = 1;i < Machine->drv->total_colors;i++)
38 	{
39 		int bit0, bit1, bit2, bit3, r, g, b;
40 
41 		bit0 = (*color_prom >> 0) & 0x01; /* intensity */
42 		bit1 = (*color_prom >> 1) & 0x01; /* red */
43 		bit2 = (*color_prom >> 2) & 0x01; /* green */
44 		bit3 = (*color_prom >> 3) & 0x01; /* blue */
45 
46 		/* red component */
47 		r = RES_1 * bit1;
48 		if (bit1) r += RES_2 * bit0;
49 
50 		/* green component */
51 		g = RES_1 * bit2;
52 		if (bit2) g += RES_2 * bit0;
53 
54 		/* blue component */
55 		b = RES_1 * bit3;
56 		if (bit3) b += RES_2 * bit0;
57 
58 		palette_set_color(i,r,g,b);
59 		color_prom += 4;
60 	}
61 
62 	for (i = 0;i < 128;i++)
63 	{
64 		colortable[i++] = 0;
65 		colortable[i] = (i/2) + 1;
66 	}
67 }
68 
WRITE_HANDLER(tankbatt_videoram_w)69 WRITE_HANDLER( tankbatt_videoram_w )
70 {
71 	if (videoram[offset] != data)
72 	{
73 		videoram[offset] = data;
74 		tilemap_mark_tile_dirty(bg_tilemap, offset);
75 	}
76 }
77 
get_bg_tile_info(int tile_index)78 static void get_bg_tile_info(int tile_index)
79 {
80 	int code = videoram[tile_index];
81 	int color = videoram[tile_index] >> 2;
82 
83 	SET_TILE_INFO(0, code, color, 0)
84 }
85 
VIDEO_START(tankbatt)86 VIDEO_START( tankbatt )
87 {
88 	bg_tilemap = tilemap_create(get_bg_tile_info, tilemap_scan_rows,
89 		TILEMAP_OPAQUE, 8, 8, 32, 32);
90 
91 	if ( !bg_tilemap )
92 		return 1;
93 
94 	return 0;
95 }
96 
tankbatt_draw_bullets(struct mame_bitmap * bitmap)97 static void tankbatt_draw_bullets( struct mame_bitmap *bitmap )
98 {
99 	int offs;
100 
101 	for (offs = 0;offs < tankbatt_bulletsram_size;offs += 2)
102 	{
103 		int color = 63;	/* cyan, same color as the tanks */
104 		int x = tankbatt_bulletsram[offs + 1];
105 		int y = 255 - tankbatt_bulletsram[offs] - 2;
106 
107 		drawgfx(bitmap,Machine->gfx[1],
108 			0,	/* this is just a square, generated by the hardware */
109 			color,
110 			0,0,
111 			x,y,
112 			&Machine->visible_area,TRANSPARENCY_NONE,0);
113 	}
114 }
115 
VIDEO_UPDATE(tankbatt)116 VIDEO_UPDATE( tankbatt )
117 {
118 	tilemap_draw(bitmap, &Machine->visible_area, bg_tilemap, 0, 0);
119 	tankbatt_draw_bullets(bitmap);
120 }
121