1 // license:BSD-3-Clause
2 // copyright-holders:Zsolt Vasvari
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/funkybee.h"
13 
funkybee_palette(palette_device & palette) const14 void funkybee_state::funkybee_palette(palette_device &palette) const
15 {
16 	const uint8_t *color_prom = memregion("proms")->base();
17 
18 	// first, the character/sprite palette
19 	for (int i = 0; i < 32; i++)
20 	{
21 		int bit0, bit1, bit2;
22 
23 		// red component
24 		bit0 = BIT(*color_prom, 0);
25 		bit1 = BIT(*color_prom, 1);
26 		bit2 = BIT(*color_prom, 2);
27 		int const r = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
28 		// green component
29 		bit0 = BIT(*color_prom, 3);
30 		bit1 = BIT(*color_prom, 4);
31 		bit2 = BIT(*color_prom, 5);
32 		int const g = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
33 		// blue component
34 		bit0 = 0;
35 		bit1 = BIT(*color_prom, 6);
36 		bit2 = BIT(*color_prom, 7);
37 		int const b = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
38 
39 		palette.set_pen_color(i, rgb_t(r, g, b));
40 		color_prom++;
41 	}
42 }
43 
funkybee_videoram_w(offs_t offset,uint8_t data)44 void funkybee_state::funkybee_videoram_w(offs_t offset, uint8_t data)
45 {
46 	m_videoram[offset] = data;
47 	m_bg_tilemap->mark_tile_dirty(offset);
48 }
49 
funkybee_colorram_w(offs_t offset,uint8_t data)50 void funkybee_state::funkybee_colorram_w(offs_t offset, uint8_t data)
51 {
52 	m_colorram[offset] = data;
53 	m_bg_tilemap->mark_tile_dirty(offset);
54 }
55 
WRITE_LINE_MEMBER(funkybee_state::gfx_bank_w)56 WRITE_LINE_MEMBER(funkybee_state::gfx_bank_w)
57 {
58 	m_gfx_bank = state;
59 	machine().tilemap().mark_all_dirty();
60 }
61 
funkybee_scroll_w(uint8_t data)62 void funkybee_state::funkybee_scroll_w(uint8_t data)
63 {
64 	m_bg_tilemap->set_scrollx(0, flip_screen() ? -data : data);
65 }
66 
WRITE_LINE_MEMBER(funkybee_state::flipscreen_w)67 WRITE_LINE_MEMBER(funkybee_state::flipscreen_w)
68 {
69 	flip_screen_set(state);
70 }
71 
TILE_GET_INFO_MEMBER(funkybee_state::get_bg_tile_info)72 TILE_GET_INFO_MEMBER(funkybee_state::get_bg_tile_info)
73 {
74 	int code = m_videoram[tile_index] + ((m_colorram[tile_index] & 0x80) << 1);
75 	int color = m_colorram[tile_index] & 0x03;
76 
77 	tileinfo.set(m_gfx_bank, code, color, 0);
78 }
79 
TILEMAP_MAPPER_MEMBER(funkybee_state::funkybee_tilemap_scan)80 TILEMAP_MAPPER_MEMBER(funkybee_state::funkybee_tilemap_scan)
81 {
82 	/* logical (col,row) -> memory offset */
83 	return 256 * row + col;
84 }
85 
video_start()86 void funkybee_state::video_start()
87 {
88 	m_bg_tilemap = &machine().tilemap().create(*m_gfxdecode, tilemap_get_info_delegate(*this, FUNC(funkybee_state::get_bg_tile_info)), tilemap_mapper_delegate(*this, FUNC(funkybee_state::funkybee_tilemap_scan)), 8, 8, 32, 32);
89 }
90 
draw_sprites(bitmap_ind16 & bitmap,const rectangle & cliprect)91 void funkybee_state::draw_sprites( bitmap_ind16 &bitmap, const rectangle &cliprect )
92 {
93 	int offs;
94 
95 	for (offs = 0x0f; offs >= 0; offs--)
96 	{
97 		int offs2 = offs + 0x1e00;
98 		int attr = m_videoram[offs2];
99 		int code = (attr >> 2) | ((attr & 2) << 5);
100 		int color = m_colorram[offs2 + 0x10];
101 		int flipx = 0;
102 		int flipy = attr & 0x01;
103 		int sx = m_videoram[offs2 + 0x10];
104 		int sy = 224 - m_colorram[offs2];
105 
106 		if (flip_screen())
107 		{
108 			sy += 32;
109 			flipx = !flipx;
110 		}
111 
112 		m_gfxdecode->gfx(2 + m_gfx_bank)->transpen(bitmap,cliprect,
113 			code, color,
114 			flipx, flipy,
115 			sx, sy, 0);
116 	}
117 }
118 
draw_columns(bitmap_ind16 & bitmap,const rectangle & cliprect)119 void funkybee_state::draw_columns( bitmap_ind16 &bitmap, const rectangle &cliprect )
120 {
121 	int offs;
122 
123 	for (offs = 0x1f; offs >= 0; offs--)
124 	{
125 		int const flip = flip_screen();
126 		int code = m_videoram[0x1c00 + offs];
127 		int color = m_colorram[0x1f10] & 0x03;
128 		int sx = flip ? m_videoram[0x1f1f] : m_videoram[0x1f10];
129 		int sy = offs * 8;
130 
131 		if (flip)
132 			sy = 248 - sy;
133 
134 		m_gfxdecode->gfx(m_gfx_bank)->transpen(bitmap,cliprect,
135 				code, color,
136 				flip, flip,
137 				sx, sy,0);
138 
139 		code = m_videoram[0x1d00 + offs];
140 		color = m_colorram[0x1f11] & 0x03;
141 		sx = flip ? m_videoram[0x1f1e] : m_videoram[0x1f11];
142 		sy = offs * 8;
143 
144 		if (flip)
145 			sy = 248 - sy;
146 
147 		m_gfxdecode->gfx(m_gfx_bank)->transpen(bitmap,cliprect,
148 				code, color,
149 				flip, flip,
150 				sx, sy,0);
151 	}
152 }
153 
screen_update_funkybee(screen_device & screen,bitmap_ind16 & bitmap,const rectangle & cliprect)154 uint32_t funkybee_state::screen_update_funkybee(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect)
155 {
156 	m_bg_tilemap->draw(screen, bitmap, cliprect, 0, 0);
157 	draw_sprites(bitmap, cliprect);
158 	draw_columns(bitmap, cliprect);
159 	return 0;
160 }
161