1 // license:BSD-3-Clause
2 // copyright-holders:Bryan McPhail
3 /***************************************************************************
4 
5   video.c
6 
7   Functions to emulate the video hardware of the machine.
8 
9 ***************************************************************************/
10 
11 #include "emu.h"
12 #include "includes/mainevt.h"
13 #include "screen.h"
14 
15 /***************************************************************************
16 
17   Callbacks for the K052109
18 
19 ***************************************************************************/
20 
K052109_CB_MEMBER(mainevt_state::mainevt_tile_callback)21 K052109_CB_MEMBER(mainevt_state::mainevt_tile_callback)
22 {
23 	static const int layer_colorbase[] = { 0 / 16, 128 / 16, 64 / 16 };
24 
25 	*flags = (*color & 0x02) ? TILE_FLIPX : 0;
26 
27 	/* priority relative to HALF priority sprites */
28 	*priority = (layer == 2) ? (*color & 0x20) >> 5 : 0;
29 	*code |= ((*color & 0x01) << 8) | ((*color & 0x1c) << 7);
30 	*color = layer_colorbase[layer] + ((*color & 0xc0) >> 6);
31 }
32 
K052109_CB_MEMBER(mainevt_state::dv_tile_callback)33 K052109_CB_MEMBER(mainevt_state::dv_tile_callback)
34 {
35 	static const int layer_colorbase[] = { 0 / 16, 0 / 16, 64 / 16 };
36 
37 	/* (color & 0x02) is flip y handled internally by the 052109 */
38 	*code |= ((*color & 0x01) << 8) | ((*color & 0x3c) << 7);
39 	*color = layer_colorbase[layer] + ((*color & 0xc0) >> 6);
40 }
41 
42 
43 /***************************************************************************
44 
45   Callbacks for the K051960
46 
47 ***************************************************************************/
48 
K051960_CB_MEMBER(mainevt_state::mainevt_sprite_callback)49 K051960_CB_MEMBER(mainevt_state::mainevt_sprite_callback)
50 {
51 	enum { sprite_colorbase = 192 / 16 };
52 
53 	/* bit 5 = priority over layer B (has precedence) */
54 	/* bit 6 = HALF priority over layer B (used for crowd when you get out of the ring) */
55 	if (*color & 0x20)
56 		*priority = 0xff00;
57 	else if (*color & 0x40)
58 		*priority = 0xff00 | 0xf0f0;
59 	else
60 		*priority = 0xff00 | 0xf0f0 | 0xcccc;
61 	/* bit 7 is shadow, not used */
62 
63 	*color = sprite_colorbase + (*color & 0x03);
64 }
65 
K051960_CB_MEMBER(mainevt_state::dv_sprite_callback)66 K051960_CB_MEMBER(mainevt_state::dv_sprite_callback)
67 {
68 	enum { sprite_colorbase = 128 / 16 };
69 
70 	// enable shadow if upper bits are 0
71 	*shadow = ((*color & 0xe0) >> 5) == 0;
72 
73 	/* TODO: the priority/shadow handling (bits 5-7) seems to be quite complex (see PROM) */
74 	*color = sprite_colorbase + (*color & 0x07);
75 }
76 
77 
78 /*****************************************************************************/
79 
screen_update_mainevt(screen_device & screen,bitmap_ind16 & bitmap,const rectangle & cliprect)80 uint32_t mainevt_state::screen_update_mainevt(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect)
81 {
82 	m_k052109->tilemap_update();
83 
84 	screen.priority().fill(0, cliprect);
85 	m_k052109->tilemap_draw(screen, bitmap, cliprect, 1, TILEMAP_DRAW_OPAQUE, 1);
86 	m_k052109->tilemap_draw(screen, bitmap, cliprect, 2, 1, 2); /* low priority part of layer */
87 	m_k052109->tilemap_draw(screen, bitmap, cliprect, 2, 0, 4); /* high priority part of layer */
88 	m_k052109->tilemap_draw(screen, bitmap, cliprect, 0, 0, 8);
89 
90 	m_k051960->k051960_sprites_draw(bitmap, cliprect, screen.priority(), -1, -1);
91 	return 0;
92 }
93 
screen_update_dv(screen_device & screen,bitmap_ind16 & bitmap,const rectangle & cliprect)94 uint32_t mainevt_state::screen_update_dv(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect)
95 {
96 	m_k052109->tilemap_update();
97 
98 	m_k052109->tilemap_draw(screen, bitmap, cliprect, 1, TILEMAP_DRAW_OPAQUE, 0);
99 	m_k052109->tilemap_draw(screen, bitmap, cliprect, 2, 0, 0);
100 	m_k051960->k051960_sprites_draw(bitmap, cliprect, screen.priority(), 0, 0);
101 	m_k052109->tilemap_draw(screen, bitmap, cliprect, 0, 0, 0);
102 	return 0;
103 }
104