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 static struct tilemap *bg_tilemap;
13 
14 /***************************************************************************
15 
16   Convert the color PROMs into a more useable format.
17 
18 ***************************************************************************/
19 
PALETTE_INIT(hanaawas)20 PALETTE_INIT( hanaawas )
21 {
22 	int i;
23 	#define TOTAL_COLORS(gfxn) (Machine->gfx[gfxn]->total_colors * Machine->gfx[gfxn]->color_granularity)
24 	#define COLOR(gfxn,offs) (colortable[Machine->drv->gfxdecodeinfo[gfxn].color_codes_start + offs])
25 
26 
27 	for (i = 0;i < Machine->drv->total_colors;i++)
28 	{
29 		int bit0,bit1,bit2,r,g,b;
30 
31 
32 		/* red component */
33 		bit0 = (*color_prom >> 0) & 0x01;
34 		bit1 = (*color_prom >> 1) & 0x01;
35 		bit2 = (*color_prom >> 2) & 0x01;
36 		r = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
37 		/* green component */
38 		bit0 = (*color_prom >> 3) & 0x01;
39 		bit1 = (*color_prom >> 4) & 0x01;
40 		bit2 = (*color_prom >> 5) & 0x01;
41 		g = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
42 		/* blue component */
43 		bit0 = 0;
44 		bit1 = (*color_prom >> 6) & 0x01;
45 		bit2 = (*color_prom >> 7) & 0x01;
46 		b = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
47 
48 		palette_set_color(i,r,g,b);
49 		color_prom++;
50 	}
51 
52 	color_prom += 0x10;
53 	/* color_prom now points to the beginning of the lookup table */
54 
55 
56 	/* character lookup table.  The 1bpp tiles really only use colors 0-0x0f and the
57 	   3bpp ones 0x10-0x1f */
58 
59 	for (i = 0;i < TOTAL_COLORS(0)/8 ;i++)
60 	{
61 		COLOR(0,i*8+0) = color_prom[i*4+0x00] & 0x0f;
62 		COLOR(0,i*8+1) = color_prom[i*4+0x01] & 0x0f;
63 		COLOR(0,i*8+2) = color_prom[i*4+0x02] & 0x0f;
64 		COLOR(0,i*8+3) = color_prom[i*4+0x03] & 0x0f;
65 		COLOR(0,i*8+4) = color_prom[i*4+0x80] & 0x0f;
66 		COLOR(0,i*8+5) = color_prom[i*4+0x81] & 0x0f;
67 		COLOR(0,i*8+6) = color_prom[i*4+0x82] & 0x0f;
68 		COLOR(0,i*8+7) = color_prom[i*4+0x83] & 0x0f;
69 	}
70 }
71 
WRITE_HANDLER(hanaawas_videoram_w)72 WRITE_HANDLER( hanaawas_videoram_w )
73 {
74 	if (videoram[offset] != data)
75 	{
76 		videoram[offset] = data;
77 		tilemap_mark_tile_dirty(bg_tilemap, offset);
78 	}
79 }
80 
WRITE_HANDLER(hanaawas_colorram_w)81 WRITE_HANDLER( hanaawas_colorram_w )
82 {
83 	if (colorram[offset] != data)
84 	{
85 		colorram[offset] = data;
86 
87 		/* dirty both current and next offsets */
88 		tilemap_mark_tile_dirty(bg_tilemap, offset);
89 		tilemap_mark_tile_dirty(bg_tilemap, (offset + (flip_screen ? -1 : 1)) & 0x03ff);
90 	}
91 }
92 
WRITE_HANDLER(hanaawas_portB_w)93 WRITE_HANDLER( hanaawas_portB_w )
94 {
95 	/* bit 7 is flip screen */
96 	if (flip_screen != (~data & 0x80))
97 	{
98 		flip_screen_set(~data & 0x80);
99 		tilemap_mark_all_tiles_dirty(ALL_TILEMAPS);
100 	}
101 }
102 
get_bg_tile_info(int tile_index)103 static void get_bg_tile_info(int tile_index)
104 {
105 	/* the color is determined by the current color byte, but the bank is via the previous one!!! */
106 	int offset = (tile_index + (flip_screen ? 1 : -1)) & 0x3ff;
107 	int attr = colorram[offset];
108 	int gfxbank = (attr & 0x40) >> 6;
109 	int code = videoram[tile_index] + ((attr & 0x20) << 3);
110 	int color = colorram[tile_index] & 0x1f;
111 
112 	SET_TILE_INFO(gfxbank, code, color, 0)
113 }
114 
VIDEO_START(hanaawas)115 VIDEO_START( hanaawas )
116 {
117 	bg_tilemap = tilemap_create(get_bg_tile_info, tilemap_scan_rows,
118 		TILEMAP_OPAQUE, 8, 8, 32, 32);
119 
120 	if ( !bg_tilemap )
121 		return 1;
122 
123 	return 0;
124 }
125 
VIDEO_UPDATE(hanaawas)126 VIDEO_UPDATE( hanaawas )
127 {
128 	tilemap_draw(bitmap, &Machine->visible_area, bg_tilemap, 0, 0);
129 }
130