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 #include "vidhrdw/konamiic.h"
12 
13 
14 unsigned char ajax_priority;
15 static int layer_colorbase[3],sprite_colorbase,zoom_colorbase;
16 
17 
18 /***************************************************************************
19 
20   Callbacks for the K052109
21 
22 ***************************************************************************/
23 
tile_callback(int layer,int bank,int * code,int * color)24 static void tile_callback(int layer,int bank,int *code,int *color)
25 {
26 	*code |= ((*color & 0x0f) << 8) | (bank << 12);
27 	*color = layer_colorbase[layer] + ((*color & 0xf0) >> 4);
28 }
29 
30 
31 /***************************************************************************
32 
33   Callbacks for the K051960
34 
35 ***************************************************************************/
36 
sprite_callback(int * code,int * color,int * priority,int * shadow)37 static void sprite_callback(int *code,int *color,int *priority,int *shadow)
38 {
39 	/* priority bits:
40 	   4 over zoom (0 = have priority)
41 	   5 over B    (0 = have priority)
42 	   6 over A    (1 = have priority)
43 	   never over F
44 	*/
45 	*priority = 0xff00;							/* F = 8 */
46 	if ( *color & 0x10) *priority |= 0xf0f0;	/* Z = 4 */
47 	if (~*color & 0x40) *priority |= 0xcccc;	/* A = 2 */
48 	if ( *color & 0x20) *priority |= 0xaaaa;	/* B = 1 */
49 	*color = sprite_colorbase + (*color & 0x0f);
50 }
51 
52 
53 /***************************************************************************
54 
55   Callbacks for the K051316
56 
57 ***************************************************************************/
58 
zoom_callback(int * code,int * color)59 static void zoom_callback(int *code,int *color)
60 {
61 	*code |= ((*color & 0x07) << 8);
62 	*color = zoom_colorbase + ((*color & 0x08) >> 3);
63 }
64 
65 
66 /***************************************************************************
67 
68 	Start the video hardware emulation.
69 
70 ***************************************************************************/
71 
ajax_vh_start(void)72 int ajax_vh_start( void )
73 {
74 	layer_colorbase[0] = 64;
75 	layer_colorbase[1] = 0;
76 	layer_colorbase[2] = 32;
77 	sprite_colorbase = 16;
78 	zoom_colorbase = 6;	/* == 48 since it's 7-bit graphics */
79 	if (K052109_vh_start(REGION_GFX1,NORMAL_PLANE_ORDER,tile_callback))
80 		return 1;
81 	if (K051960_vh_start(REGION_GFX2,NORMAL_PLANE_ORDER,sprite_callback))
82 	{
83 		K052109_vh_stop();
84 		return 1;
85 	}
86 	if (K051316_vh_start_0(REGION_GFX3,7,zoom_callback))
87 	{
88 		K052109_vh_stop();
89 		K051960_vh_stop();
90 		return 1;
91 	}
92 
93 	return 0;
94 }
95 
ajax_vh_stop(void)96 void ajax_vh_stop( void )
97 {
98 	K052109_vh_stop();
99 	K051960_vh_stop();
100 	K051316_vh_stop_0();
101 }
102 
103 
104 
105 /***************************************************************************
106 
107 	Display Refresh
108 
109 ***************************************************************************/
110 
ajax_vh_screenrefresh(struct osd_bitmap * bitmap,int fullrefresh)111 void ajax_vh_screenrefresh( struct osd_bitmap *bitmap, int fullrefresh )
112 {
113 	K052109_tilemap_update();
114 	K051316_tilemap_update_0();
115 
116 	palette_init_used_colors();
117 	K051960_mark_sprites_colors();
118 	/* set back pen for the zoom layer */
119 	palette_used_colors[(zoom_colorbase + 0) * 128] = PALETTE_COLOR_TRANSPARENT;
120 	palette_used_colors[(zoom_colorbase + 1) * 128] = PALETTE_COLOR_TRANSPARENT;
121 	if (palette_recalc())
122 		tilemap_mark_all_pixels_dirty(ALL_TILEMAPS);
123 
124 	tilemap_render(ALL_TILEMAPS);
125 
126 	fillbitmap(priority_bitmap,0,NULL);
127 
128 	fillbitmap(bitmap,Machine->pens[0],&Machine->visible_area);
129 	K052109_tilemap_draw(bitmap,2,1<<16);
130 	if (ajax_priority)
131 	{
132 		/* basic layer order is B, zoom, A, F */
133 		K051316_zoom_draw_0(bitmap,4);
134 		K052109_tilemap_draw(bitmap,1,2<<16);
135 	}
136 	else
137 	{
138 		/* basic layer order is B, A, zoom, F */
139 		K052109_tilemap_draw(bitmap,1,2<<16);
140 		K051316_zoom_draw_0(bitmap,4);
141 	}
142 	K052109_tilemap_draw(bitmap,0,8<<16);
143 
144 	K051960_sprites_draw(bitmap,-1,-1);
145 }
146