1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
|
#include "driver.h"
#include "video/konamiic.h"
static int layer_colorbase[3],sprite_colorbase,bg_colorbase;
static int layerpri[3];
/***************************************************************************
Callbacks for the K052109
***************************************************************************/
static void tile_callback(int layer,int bank,int *code,int *color,int *flags,int *priority)
{
*flags = (*color & 0x80) ? TILE_FLIPX : 0;
*code |= ((*color & 0x03) << 8) | ((*color & 0x10) << 6) | ((*color & 0x0c) << 9) | (bank << 13);
*color = layer_colorbase[layer] + ((*color & 0x60) >> 5);
}
/***************************************************************************
Callbacks for the K053245
***************************************************************************/
static void sprite_callback(int *code,int *color,int *priority_mask)
{
int pri = 0x20 | ((*color & 0x60) >> 2);
if (pri <= layerpri[2]) *priority_mask = 0;
else if (pri > layerpri[2] && pri <= layerpri[1]) *priority_mask = 0xf0;
else if (pri > layerpri[1] && pri <= layerpri[0]) *priority_mask = 0xf0|0xcc;
else *priority_mask = 0xf0|0xcc|0xaa;
*color = sprite_colorbase + (*color & 0x1f);
}
/***************************************************************************
Start the video hardware emulation.
***************************************************************************/
VIDEO_START( surpratk )
{
K053251_vh_start();
K052109_vh_start(machine,REGION_GFX1,NORMAL_PLANE_ORDER,tile_callback);
K053245_vh_start(machine,0,REGION_GFX2,NORMAL_PLANE_ORDER,sprite_callback);
}
/* useful function to sort the three tile layers by priority order */
static void sortlayers(int *layer,int *pri)
{
#define SWAP(a,b) \
if (pri[a] < pri[b]) \
{ \
int t; \
t = pri[a]; pri[a] = pri[b]; pri[b] = t; \
t = layer[a]; layer[a] = layer[b]; layer[b] = t; \
}
SWAP(0,1)
SWAP(0,2)
SWAP(1,2)
}
VIDEO_UPDATE( surpratk )
{
int layer[3];
bg_colorbase = K053251_get_palette_index(K053251_CI0);
sprite_colorbase = K053251_get_palette_index(K053251_CI1);
layer_colorbase[0] = K053251_get_palette_index(K053251_CI2);
layer_colorbase[1] = K053251_get_palette_index(K053251_CI4);
layer_colorbase[2] = K053251_get_palette_index(K053251_CI3);
K052109_tilemap_update();
layer[0] = 0;
layerpri[0] = K053251_get_priority(K053251_CI2);
layer[1] = 1;
layerpri[1] = K053251_get_priority(K053251_CI4);
layer[2] = 2;
layerpri[2] = K053251_get_priority(K053251_CI3);
sortlayers(layer,layerpri);
fillbitmap(priority_bitmap,0,cliprect);
fillbitmap(bitmap,machine->pens[16 * bg_colorbase],cliprect);
tilemap_draw(bitmap,cliprect,K052109_tilemap[layer[0]],0,1);
tilemap_draw(bitmap,cliprect,K052109_tilemap[layer[1]],0,2);
tilemap_draw(bitmap,cliprect,K052109_tilemap[layer[2]],0,4);
K053245_sprites_draw(0,bitmap,cliprect);
return 0;
}
|