1 // license:BSD-3-Clause
2 // copyright-holders:Aaron Giles
3 /***************************************************************************
4 
5     Venture Line Super Rider driver
6 
7 ***************************************************************************/
8 
9 #include "emu.h"
10 #include "includes/suprridr.h"
11 #include "screen.h"
12 
13 
14 /*************************************
15  *
16  *  Tilemap callbacks
17  *
18  *************************************/
19 
TILE_GET_INFO_MEMBER(suprridr_state::get_tile_info)20 TILE_GET_INFO_MEMBER(suprridr_state::get_tile_info)
21 {
22 	uint8_t code = m_bgram[tile_index];
23 	tileinfo.set(0, code, 0, 0);
24 }
25 
26 
TILE_GET_INFO_MEMBER(suprridr_state::get_tile_info2)27 TILE_GET_INFO_MEMBER(suprridr_state::get_tile_info2)
28 {
29 	uint8_t code = m_fgram[tile_index];
30 	tileinfo.set(1, code, 0, 0);
31 }
32 
33 
34 
35 /*************************************
36  *
37  *  Video startup
38  *
39  *************************************/
40 
video_start()41 void suprridr_state::video_start()
42 {
43 	m_fg_tilemap          = &machine().tilemap().create(*m_gfxdecode, tilemap_get_info_delegate(*this, FUNC(suprridr_state::get_tile_info2)), TILEMAP_SCAN_ROWS, 8,8, 32,32);
44 	m_bg_tilemap          = &machine().tilemap().create(*m_gfxdecode, tilemap_get_info_delegate(*this, FUNC(suprridr_state::get_tile_info)),  TILEMAP_SCAN_ROWS, 8,8, 32,32);
45 	m_bg_tilemap_noscroll = &machine().tilemap().create(*m_gfxdecode, tilemap_get_info_delegate(*this, FUNC(suprridr_state::get_tile_info)),  TILEMAP_SCAN_ROWS, 8,8, 32,32);
46 
47 	m_fg_tilemap->set_transparent_pen(0);
48 
49 	save_item(NAME(m_flipx));
50 	save_item(NAME(m_flipy));
51 }
52 
53 
54 
55 /*************************************
56  *
57  *  Color PROM decoding
58  *
59  *************************************/
60 
suprridr_palette(palette_device & palette) const61 void suprridr_state::suprridr_palette(palette_device &palette) const
62 {
63 	uint8_t const *const color_prom = memregion("proms")->base();
64 	for (int i = 0; i < 96; i++)
65 	{
66 		int bit0, bit1, bit2;
67 
68 		// red component
69 		bit0 = BIT(color_prom[i], 0);
70 		bit1 = BIT(color_prom[i], 1);
71 		bit2 = BIT(color_prom[i], 2);
72 		int const r = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
73 
74 		// green component
75 		bit0 = BIT(color_prom[i], 3);
76 		bit1 = BIT(color_prom[i], 4);
77 		bit2 = BIT(color_prom[i], 5);
78 		int const g = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
79 
80 		// blue component
81 		bit0 = BIT(color_prom[i], 6);
82 		bit1 = BIT(color_prom[i], 7);
83 		int const b = 0x4f * bit0 + 0xa8 * bit1;
84 
85 		palette.set_pen_color(i, rgb_t(r, g, b));
86 	}
87 }
88 
89 
90 
91 /*************************************
92  *
93  *  Screen flip/scroll registers
94  *
95  *************************************/
96 
flipx_w(uint8_t data)97 void suprridr_state::flipx_w(uint8_t data)
98 {
99 	m_flipx = data & 1;
100 	machine().tilemap().set_flip_all((m_flipx ? TILEMAP_FLIPX : 0) | (m_flipy ? TILEMAP_FLIPY : 0));
101 }
102 
103 
flipy_w(uint8_t data)104 void suprridr_state::flipy_w(uint8_t data)
105 {
106 	m_flipy = data & 1;
107 	machine().tilemap().set_flip_all((m_flipx ? TILEMAP_FLIPX : 0) | (m_flipy ? TILEMAP_FLIPY : 0));
108 }
109 
110 
fgdisable_w(uint8_t data)111 void suprridr_state::fgdisable_w(uint8_t data)
112 {
113 	m_fg_tilemap->enable(~data & 1);
114 }
115 
116 
fgscrolly_w(uint8_t data)117 void suprridr_state::fgscrolly_w(uint8_t data)
118 {
119 	m_fg_tilemap->set_scrolly(0, data);
120 }
121 
122 
bgscrolly_w(uint8_t data)123 void suprridr_state::bgscrolly_w(uint8_t data)
124 {
125 	m_bg_tilemap->set_scrolly(0, data);
126 }
127 
128 
is_screen_flipped()129 int suprridr_state::is_screen_flipped()
130 {
131 	return m_flipx;  /* or is it flipy? */
132 }
133 
134 
135 
136 /*************************************
137  *
138  *  Video RAM writes
139  *
140  *************************************/
141 
bgram_w(offs_t offset,uint8_t data)142 void suprridr_state::bgram_w(offs_t offset, uint8_t data)
143 {
144 	m_bgram[offset] = data;
145 	m_bg_tilemap->mark_tile_dirty(offset);
146 	m_bg_tilemap_noscroll->mark_tile_dirty(offset);
147 }
148 
149 
fgram_w(offs_t offset,uint8_t data)150 void suprridr_state::fgram_w(offs_t offset, uint8_t data)
151 {
152 	m_fgram[offset] = data;
153 	m_fg_tilemap->mark_tile_dirty(offset);
154 }
155 
156 
157 
158 /*************************************
159  *
160  *  Video refresh
161  *
162  *************************************/
163 
screen_update(screen_device & screen,bitmap_ind16 & bitmap,const rectangle & cliprect)164 uint32_t suprridr_state::screen_update(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect)
165 {
166 	rectangle subclip;
167 	const rectangle &visarea = screen.visible_area();
168 
169 	/* render left 4 columns with no scroll */
170 	subclip = visarea;
171 	subclip.max_x = subclip.min_x + (m_flipx ? 1*8 : 4*8) - 1;
172 	subclip &= cliprect;
173 	m_bg_tilemap_noscroll->draw(screen, bitmap, subclip, 0, 0);
174 
175 	/* render right 1 column with no scroll */
176 	subclip = visarea;
177 	subclip.min_x = subclip.max_x - (m_flipx ? 4*8 : 1*8) + 1;
178 	subclip &= cliprect;
179 	m_bg_tilemap_noscroll->draw(screen, bitmap, subclip, 0, 0);
180 
181 	/* render the middle columns normally */
182 	subclip = visarea;
183 	subclip.min_x += m_flipx ? 1*8 : 4*8;
184 	subclip.max_x -= m_flipx ? 4*8 : 1*8;
185 	subclip &= cliprect;
186 	m_bg_tilemap->draw(screen, bitmap, subclip, 0, 0);
187 
188 	/* render the top layer */
189 	m_fg_tilemap->draw(screen, bitmap, cliprect, 0, 0);
190 
191 	/* draw the sprites */
192 	for (int i = 0; i < 48; i++)
193 	{
194 		int code = (m_spriteram[i*4+1] & 0x3f) | ((m_spriteram[i*4+2] >> 1) & 0x40);
195 		int color = m_spriteram[i*4+2] & 0x7f;
196 		int fx = m_spriteram[i*4+1] & 0x40;
197 		int fy = m_spriteram[i*4+1] & 0x80;
198 		int x = m_spriteram[i*4+3];
199 		int y = 240 - m_spriteram[i*4+0];
200 
201 		if (m_flipx)
202 		{
203 			fx = !fx;
204 			x = 240 - x;
205 		}
206 		if (m_flipy)
207 		{
208 			fy = !fy;
209 			y = 240 - y;
210 		}
211 		m_gfxdecode->gfx(2)->transpen(bitmap,cliprect, code, color, fx, fy, x, y, 0);
212 	}
213 	return 0;
214 }
215