1 // license:BSD-3-Clause
2 // copyright-holders:Nicola Salmoria
3 
4 #include "emu.h"
5 #include "includes/surpratk.h"
6 #include "screen.h"
7 
8 
9 /***************************************************************************
10 
11   Callbacks for the K052109
12 
13 ***************************************************************************/
14 
K052109_CB_MEMBER(surpratk_state::tile_callback)15 K052109_CB_MEMBER(surpratk_state::tile_callback)
16 {
17 	*flags = (*color & 0x80) ? TILE_FLIPX : 0;
18 	*code |= ((*color & 0x03) << 8) | ((*color & 0x10) << 6) | ((*color & 0x0c) << 9) | (bank << 13);
19 	*color = m_layer_colorbase[layer] + ((*color & 0x60) >> 5);
20 }
21 
22 /***************************************************************************
23 
24   Callbacks for the K053245
25 
26 ***************************************************************************/
27 
K05324X_CB_MEMBER(surpratk_state::sprite_callback)28 K05324X_CB_MEMBER(surpratk_state::sprite_callback)
29 {
30 	int pri = 0x20 | ((*color & 0x60) >> 2);
31 	if (pri <= m_layerpri[2])
32 		*priority = 0;
33 	else if (pri > m_layerpri[2] && pri <= m_layerpri[1])
34 		*priority = 0xf0;
35 	else if (pri > m_layerpri[1] && pri <= m_layerpri[0])
36 		*priority = 0xf0 | 0xcc;
37 	else
38 		*priority = 0xf0 | 0xcc | 0xaa;
39 
40 	*color = m_sprite_colorbase + (*color & 0x1f);
41 }
42 
43 
44 /***************************************************************************
45 
46     Start the video hardware emulation.
47 
48 ***************************************************************************/
49 
screen_update_surpratk(screen_device & screen,bitmap_ind16 & bitmap,const rectangle & cliprect)50 uint32_t surpratk_state::screen_update_surpratk(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect)
51 {
52 	int layer[3], bg_colorbase;
53 
54 	bg_colorbase = m_k053251->get_palette_index(k053251_device::CI0);
55 	m_sprite_colorbase = m_k053251->get_palette_index(k053251_device::CI1);
56 	m_layer_colorbase[0] = m_k053251->get_palette_index(k053251_device::CI2);
57 	m_layer_colorbase[1] = m_k053251->get_palette_index(k053251_device::CI4);
58 	m_layer_colorbase[2] = m_k053251->get_palette_index(k053251_device::CI3);
59 
60 	m_k052109->tilemap_update();
61 
62 	layer[0] = 0;
63 	m_layerpri[0] = m_k053251->get_priority(k053251_device::CI2);
64 	layer[1] = 1;
65 	m_layerpri[1] = m_k053251->get_priority(k053251_device::CI4);
66 	layer[2] = 2;
67 	m_layerpri[2] = m_k053251->get_priority(k053251_device::CI3);
68 
69 	konami_sortlayers3(layer, m_layerpri);
70 
71 	screen.priority().fill(0, cliprect);
72 	bitmap.fill(16 * bg_colorbase, cliprect);
73 	m_k052109->tilemap_draw(screen, bitmap, cliprect, layer[0], 0, 1);
74 	m_k052109->tilemap_draw(screen, bitmap, cliprect, layer[1], 0, 2);
75 	m_k052109->tilemap_draw(screen, bitmap, cliprect, layer[2], 0, 4);
76 
77 	m_k053244->sprites_draw(bitmap, cliprect, screen.priority());
78 	return 0;
79 }
80