1 #include "driver.h"
2 #include "vidhrdw/konamiic.h"
3 
4 
5 static int layer_colorbase[3],bg_colorbase,sprite_colorbase;
6 static int layerpri[3];
7 
8 
9 /***************************************************************************
10 
11   Callbacks for the K052109
12 
13 ***************************************************************************/
14 
vendetta_tile_callback(int layer,int bank,int * code,int * color)15 static void vendetta_tile_callback(int layer,int bank,int *code,int *color)
16 {
17 	*code |= ((*color & 0x03) << 8) | ((*color & 0x30) << 6) |
18 			((*color & 0x0c) << 10) | (bank << 14);
19 	*color = layer_colorbase[layer] + ((*color & 0xc0) >> 6);
20 }
21 
esckids_tile_callback(int layer,int bank,int * code,int * color)22 static void esckids_tile_callback(int layer,int bank,int *code,int *color)
23 {
24 	*code |= ((*color & 0x03) << 8) | ((*color & 0x10) << 6) |
25 			((*color & 0x0c) <<  9) | (bank << 13);
26 	*color = layer_colorbase[layer] + ((*color & 0xe0) >>  5);
27 }
28 
29 
30 /***************************************************************************
31 
32   Callbacks for the K053247
33 
34 ***************************************************************************/
35 
sprite_callback(int * code,int * color,int * priority_mask)36 static void sprite_callback(int *code,int *color,int *priority_mask)
37 {
38 	int pri = (*color & 0x03e0) >> 4;	/* ??????? */
39 	if (pri <= layerpri[2])								*priority_mask = 0;
40 	else if (pri > layerpri[2] && pri <= layerpri[1])	*priority_mask = 0xf0;
41 	else if (pri > layerpri[1] && pri <= layerpri[0])	*priority_mask = 0xf0|0xcc;
42 	else 												*priority_mask = 0xf0|0xcc|0xaa;
43 
44 	*color = sprite_colorbase + (*color & 0x001f);
45 }
46 
47 
48 
49 /***************************************************************************
50 
51 	Start the video hardware emulation.
52 
53 ***************************************************************************/
54 
VIDEO_START(vendetta)55 VIDEO_START( vendetta )
56 {
57 	K053251_vh_start();
58 
59 	if (K052109_vh_start(REGION_GFX1,NORMAL_PLANE_ORDER,vendetta_tile_callback))
60 		return 1;
61 	if (K053247_vh_start(REGION_GFX2,53,6,NORMAL_PLANE_ORDER,sprite_callback))
62 		return 1;
63 	return 0;
64 }
65 
VIDEO_START(esckids)66 VIDEO_START( esckids )
67 {
68     K053251_vh_start();
69 
70     if (K052109_vh_start(REGION_GFX1,NORMAL_PLANE_ORDER,esckids_tile_callback))
71 		return 1;
72 	if (K053247_vh_start(REGION_GFX2,101,6,NORMAL_PLANE_ORDER,sprite_callback))
73 		return 1;
74 	return 0;
75 }
76 
77 
78 
79 /***************************************************************************
80 
81   Display refresh
82 
83 ***************************************************************************/
84 
85 /* useful function to sort the three tile layers by priority order */
sortlayers(int * layer,int * pri)86 static void sortlayers(int *layer,int *pri)
87 {
88 #define SWAP(a,b) \
89 	if (pri[a] < pri[b]) \
90 	{ \
91 		int t; \
92 		t = pri[a]; pri[a] = pri[b]; pri[b] = t; \
93 		t = layer[a]; layer[a] = layer[b]; layer[b] = t; \
94 	}
95 
96 	SWAP(0,1)
97 	SWAP(0,2)
98 	SWAP(1,2)
99 }
100 
VIDEO_UPDATE(vendetta)101 VIDEO_UPDATE( vendetta )
102 {
103 	int layer[3];
104 
105 
106 	bg_colorbase       = K053251_get_palette_index(K053251_CI0);
107 	sprite_colorbase   = K053251_get_palette_index(K053251_CI1);
108 	layer_colorbase[0] = K053251_get_palette_index(K053251_CI2);
109 	layer_colorbase[1] = K053251_get_palette_index(K053251_CI3);
110 	layer_colorbase[2] = K053251_get_palette_index(K053251_CI4);
111 
112 	K052109_tilemap_update();
113 
114 	layer[0] = 0;
115 	layerpri[0] = K053251_get_priority(K053251_CI2);
116 	layer[1] = 1;
117 	layerpri[1] = K053251_get_priority(K053251_CI3);
118 	layer[2] = 2;
119 	layerpri[2] = K053251_get_priority(K053251_CI4);
120 
121 	sortlayers(layer,layerpri);
122 
123 	fillbitmap(priority_bitmap,0,cliprect);
124 	tilemap_draw(bitmap,cliprect,K052109_tilemap[layer[0]],TILEMAP_IGNORE_TRANSPARENCY,1);
125 	tilemap_draw(bitmap,cliprect,K052109_tilemap[layer[1]],0,2);
126 	tilemap_draw(bitmap,cliprect,K052109_tilemap[layer[2]],0,4);
127 
128 	K053247_sprites_draw(bitmap,cliprect);
129 }
130