1 // license:BSD-3-Clause
2 // copyright-holders:K.Wilkins
3 /***************************************************************************
4 
5   Toaplan Slap Fight hardware
6 
7   Functions to emulate the video hardware of the machine
8 
9 ***************************************************************************/
10 
11 #include "emu.h"
12 #include "includes/slapfght.h"
13 
14 
15 /***************************************************************************
16 
17   Callbacks for the TileMap code
18 
19 ***************************************************************************/
20 
TILE_GET_INFO_MEMBER(slapfght_state::get_pf_tile_info)21 TILE_GET_INFO_MEMBER(slapfght_state::get_pf_tile_info)
22 {
23 	/* For Performan only */
24 	int tile = m_videoram[tile_index] | ((m_colorram[tile_index] & 0x03) << 8);
25 	int color = (m_colorram[tile_index] >> 3) & 0x0f;
26 
27 	tileinfo.set(0, tile, color, 0);
28 }
29 
TILE_GET_INFO_MEMBER(slapfght_state::get_pf1_tile_info)30 TILE_GET_INFO_MEMBER(slapfght_state::get_pf1_tile_info)
31 {
32 	int tile = m_videoram[tile_index] | ((m_colorram[tile_index] & 0x0f) << 8);
33 	int color = (m_colorram[tile_index] & 0xf0) >> 4;
34 
35 	tileinfo.set(1, tile, color, 0);
36 }
37 
TILE_GET_INFO_MEMBER(slapfght_state::get_fix_tile_info)38 TILE_GET_INFO_MEMBER(slapfght_state::get_fix_tile_info)
39 {
40 	int tile = m_fixvideoram[tile_index] | ((m_fixcolorram[tile_index] & 0x03) << 8);
41 	int color = (m_fixcolorram[tile_index] & 0xfc) >> 2;
42 
43 	tileinfo.set(0, tile, color, 0);
44 }
45 
46 
47 
48 /***************************************************************************
49 
50   Start the video hardware emulation.
51 
52 ***************************************************************************/
53 
VIDEO_START_MEMBER(slapfght_state,perfrman)54 VIDEO_START_MEMBER(slapfght_state, perfrman)
55 {
56 	m_pf1_tilemap = &machine().tilemap().create(*m_gfxdecode, tilemap_get_info_delegate(*this, FUNC(slapfght_state::get_pf_tile_info)), TILEMAP_SCAN_ROWS, 8, 8, 64, 32);
57 
58 	m_pf1_tilemap->set_transparent_pen(0);
59 }
60 
VIDEO_START_MEMBER(slapfght_state,slapfight)61 VIDEO_START_MEMBER(slapfght_state, slapfight)
62 {
63 	m_pf1_tilemap = &machine().tilemap().create(*m_gfxdecode, tilemap_get_info_delegate(*this, FUNC(slapfght_state::get_pf1_tile_info)), TILEMAP_SCAN_ROWS, 8, 8, 64, 32);
64 	m_fix_tilemap = &machine().tilemap().create(*m_gfxdecode, tilemap_get_info_delegate(*this, FUNC(slapfght_state::get_fix_tile_info)), TILEMAP_SCAN_ROWS, 8, 8, 64, 32);
65 
66 	m_fix_tilemap->set_scrolldy(0, 15);
67 	m_pf1_tilemap->set_scrolldy(0, 14);
68 
69 	m_fix_tilemap->set_transparent_pen(0);
70 }
71 
72 
73 
74 /***************************************************************************
75 
76   Memory handlers
77 
78 ***************************************************************************/
79 
videoram_w(offs_t offset,uint8_t data)80 void slapfght_state::videoram_w(offs_t offset, uint8_t data)
81 {
82 	m_videoram[offset] = data;
83 	m_pf1_tilemap->mark_tile_dirty(offset);
84 }
85 
colorram_w(offs_t offset,uint8_t data)86 void slapfght_state::colorram_w(offs_t offset, uint8_t data)
87 {
88 	m_colorram[offset] = data;
89 	m_pf1_tilemap->mark_tile_dirty(offset);
90 }
91 
fixram_w(offs_t offset,uint8_t data)92 void slapfght_state::fixram_w(offs_t offset, uint8_t data)
93 {
94 	m_fixvideoram[offset] = data;
95 	m_fix_tilemap->mark_tile_dirty(offset);
96 }
97 
fixcol_w(offs_t offset,uint8_t data)98 void slapfght_state::fixcol_w(offs_t offset, uint8_t data)
99 {
100 	m_fixcolorram[offset] = data;
101 	m_fix_tilemap->mark_tile_dirty(offset);
102 }
103 
scrollx_lo_w(uint8_t data)104 void slapfght_state::scrollx_lo_w(uint8_t data)
105 {
106 	m_scrollx_lo = data;
107 }
108 
scrollx_hi_w(uint8_t data)109 void slapfght_state::scrollx_hi_w(uint8_t data)
110 {
111 	m_scrollx_hi = data;
112 }
113 
scrolly_w(uint8_t data)114 void slapfght_state::scrolly_w(uint8_t data)
115 {
116 	m_scrolly = data;
117 }
118 
WRITE_LINE_MEMBER(slapfght_state::flipscreen_w)119 WRITE_LINE_MEMBER(slapfght_state::flipscreen_w)
120 {
121 	flip_screen_set(state ? 0 : 1);
122 }
123 
WRITE_LINE_MEMBER(slapfght_state::palette_bank_w)124 WRITE_LINE_MEMBER(slapfght_state::palette_bank_w)
125 {
126 	m_palette_bank = state;
127 }
128 
129 
130 
131 /***************************************************************************
132 
133   Render the Screen
134 
135 ***************************************************************************/
136 
draw_perfrman_sprites(bitmap_ind16 & bitmap,const rectangle & cliprect,int layer)137 void slapfght_state::draw_perfrman_sprites(bitmap_ind16 &bitmap, const rectangle &cliprect, int layer)
138 {
139 	uint8_t *src = m_spriteram->buffer();
140 
141 	for (int offs = 0; offs < m_spriteram->bytes(); offs += 4)
142 	{
143 		/*
144 		    0: xxxxxxxx - code
145 		    1: xxxxxxxx - x
146 		    2: x....... - priority over backdrop
147 		       .x...... - sprite-sprite priority (see point-pop sprites)
148 		       ..x..... - ?
149 		       ...xx... - no function?
150 		       .....xxx - color
151 		    3: xxxxxxxx - y
152 		*/
153 
154 		int code = src[offs + 0];
155 		int sy = src[offs + 3] - 1;
156 		int sx = src[offs + 1] - 13;
157 		int pri = src[offs + 2] >> 6 & 3;
158 		int color = (src[offs + 2] >> 1 & 3) | (src[offs + 2] << 2 & 4) | (m_palette_bank << 3);
159 		int fx = 0, fy = 0;
160 
161 		if (flip_screen())
162 		{
163 			sy = 256 - sy;
164 			sx = 240 - sx;
165 			fx = fy = 1;
166 		}
167 
168 		if (layer == pri)
169 			m_gfxdecode->gfx(1)->transpen(bitmap, cliprect, code, color, fx, fy, sx, sy, 0);
170 	}
171 }
172 
screen_update_perfrman(screen_device & screen,bitmap_ind16 & bitmap,const rectangle & cliprect)173 uint32_t slapfght_state::screen_update_perfrman(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect)
174 {
175 	m_pf1_tilemap->draw(screen, bitmap, cliprect, TILEMAP_DRAW_OPAQUE);
176 	draw_perfrman_sprites(bitmap, cliprect, 0);
177 	draw_perfrman_sprites(bitmap, cliprect, 1);
178 
179 	m_pf1_tilemap->draw(screen, bitmap, cliprect, 0);
180 	draw_perfrman_sprites(bitmap, cliprect, 2);
181 	draw_perfrman_sprites(bitmap, cliprect, 3);
182 
183 	return 0;
184 }
185 
186 
draw_slapfight_sprites(bitmap_ind16 & bitmap,const rectangle & cliprect)187 void slapfght_state::draw_slapfight_sprites(bitmap_ind16 &bitmap, const rectangle &cliprect)
188 {
189 	uint8_t *src = m_spriteram->buffer();
190 
191 	for (int offs = 0; offs < m_spriteram->bytes(); offs += 4)
192 	{
193 		/*
194 		    0: xxxxxxxx - code low
195 		    1: xxxxxxxx - x low
196 		    2: xx...... - code high
197 		       ..x..... - no function?
198 		       ...xxxx. - color
199 		       .......x - x high
200 		    3: xxxxxxxx - y
201 		*/
202 
203 		int code = src[offs + 0] | ((src[offs + 2] & 0xc0) << 2);
204 		int sy = src[offs + 3];
205 		int sx = (src[offs + 1] | (src[offs + 2] << 8 & 0x100)) - 13;
206 		int color = src[offs + 2] >> 1 & 0xf;
207 		int fx = 0, fy = 0;
208 
209 		if (flip_screen())
210 		{
211 			sy = (238 - sy) & 0xff;
212 			sx = 284 - sx;
213 			fx = fy = 1;
214 		}
215 
216 		m_gfxdecode->gfx(2)->transpen(bitmap, cliprect, code, color, fx, fy, sx, sy, 0);
217 	}
218 }
219 
screen_update_slapfight(screen_device & screen,bitmap_ind16 & bitmap,const rectangle & cliprect)220 uint32_t slapfght_state::screen_update_slapfight(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect)
221 {
222 	m_pf1_tilemap->set_scrollx(m_scrollx_hi << 8 | m_scrollx_lo);
223 	m_pf1_tilemap->set_scrolly(m_scrolly);
224 
225 	m_pf1_tilemap->draw(screen, bitmap, cliprect, 0, 0);
226 	draw_slapfight_sprites(bitmap, cliprect);
227 	m_fix_tilemap->draw(screen, bitmap, cliprect, 0, 0);
228 
229 	return 0;
230 }
231