summaryrefslogtreecommitdiffstatshomepage
path: root/src/mame/video/punchout.cpp
blob: fa3285eaa40e8750b23fa2b12338886f28b7d2fe (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
// license:BSD-3-Clause
// copyright-holders:Nicola Salmoria
/***************************************************************************

  video.c

  Functions to emulate the video hardware of the machine.

***************************************************************************/

#include "emu.h"
#include "includes/punchout.h"


/***************************************************************************

  Start the video hardware emulation.

***************************************************************************/

TILE_GET_INFO_MEMBER(punchout_state::top_get_info)
{
	int attr = m_bg_top_videoram[tile_index*2 + 1];
	int code = m_bg_top_videoram[tile_index*2] + ((attr & 0x03) << 8);
	int color = ((attr & 0x7c) >> 2);
	int flipx = attr & 0x80;
	SET_TILE_INFO_MEMBER(0, code, color, flipx ? TILE_FLIPX : 0);
}

TILE_GET_INFO_MEMBER(punchout_state::armwrest_top_get_info)
{
	int attr = m_bg_top_videoram[tile_index*2 + 1];
	int code = m_bg_top_videoram[tile_index*2] + ((attr & 0x03) << 8) + ((attr & 0x80) << 3);
	int color = ((attr & 0x7c) >> 2);
	SET_TILE_INFO_MEMBER(0, code, color, 0);
}

TILE_GET_INFO_MEMBER(punchout_state::bot_get_info)
{
	int attr = m_bg_bot_videoram[tile_index*2 + 1];
	int code = m_bg_bot_videoram[tile_index*2] + ((attr & 0x03) << 8);
	int color = ((attr & 0x7c) >> 2);
	int flipx = attr & 0x80;
	SET_TILE_INFO_MEMBER(1, code, color, flipx ? TILE_FLIPX : 0);
}

TILE_GET_INFO_MEMBER(punchout_state::armwrest_bot_get_info)
{
	int attr = m_bg_bot_videoram[tile_index*2 + 1];
	int code = m_bg_bot_videoram[tile_index*2] + ((attr & 0x03) << 8);
	int color = ((attr & 0x7c) >> 2) + 0x40;
	int flipx = attr & 0x80;
	SET_TILE_INFO_MEMBER(0, code, color, flipx ? TILE_FLIPX : 0);
}

TILE_GET_INFO_MEMBER(punchout_state::bs1_get_info)
{
	int attr = m_spr1_videoram[tile_index*4 + 3];
	int code = m_spr1_videoram[tile_index*4] + ((m_spr1_videoram[tile_index*4 + 1] & 0x1f) << 8);
	int color = attr & 0x1f;
	int flipx = attr & 0x80;
	SET_TILE_INFO_MEMBER(2, code, color, flipx ? TILE_FLIPX : 0);
}

TILE_GET_INFO_MEMBER(punchout_state::bs2_get_info)
{
	int attr = m_spr2_videoram[tile_index*4 + 3];
	int code = m_spr2_videoram[tile_index*4] + ((m_spr2_videoram[tile_index*4 + 1] & 0x0f) << 8);
	int color = attr & 0x3f;
	int flipx = attr & 0x80;
	SET_TILE_INFO_MEMBER(3, code, color, flipx ? TILE_FLIPX : 0);
}

TILE_GET_INFO_MEMBER(punchout_state::armwrest_fg_get_info)
{
	int attr = m_armwrest_fg_videoram[tile_index*2 + 1];
	int code = m_armwrest_fg_videoram[tile_index*2] + 256 * (attr & 0x07);
	int color = ((attr & 0xf8) >> 3);
	int flipx = attr & 0x80;
	SET_TILE_INFO_MEMBER(1, code, color, flipx ? TILE_FLIPX : 0);
}

TILEMAP_MAPPER_MEMBER(punchout_state::armwrest_bs1_scan)
{
	int halfcols = num_cols/2;
	return (col/halfcols)*(halfcols*num_rows) + row*halfcols + col%halfcols;
}

TILEMAP_MAPPER_MEMBER(punchout_state::armwrest_bs1_scan_flipx)
{
	int halfcols = num_cols/2;
	col ^=0x10;
	return (col/halfcols)*(halfcols*num_rows) + row*halfcols + col%halfcols;
}


void punchout_state::video_start()
{
	m_bg_top_tilemap = &machine().tilemap().create(*m_gfxdecode, tilemap_get_info_delegate(*this, FUNC(punchout_state::top_get_info)), TILEMAP_SCAN_ROWS,  8,8, 32,32);
	m_bg_bot_tilemap = &machine().tilemap().create(*m_gfxdecode, tilemap_get_info_delegate(*this, FUNC(punchout_state::bot_get_info)), TILEMAP_SCAN_ROWS,  8,8, 64,32);
	m_bg_bot_tilemap->set_scroll_rows(32);

	m_spr1_tilemap = &machine().tilemap().create(*m_gfxdecode, tilemap_get_info_delegate(*this, FUNC(punchout_state::bs1_get_info)), TILEMAP_SCAN_ROWS,  8,8, 16,32);
	m_spr2_tilemap = &machine().tilemap().create(*m_gfxdecode, tilemap_get_info_delegate(*this, FUNC(punchout_state::bs2_get_info)), TILEMAP_SCAN_ROWS,  8,8, 16,32);

	m_fg_tilemap = nullptr;

	m_spr1_tilemap->set_transparent_pen(0x07);
	m_spr2_tilemap->set_transparent_pen(0x03);
}


VIDEO_START_MEMBER(punchout_state,armwrest)
{
	m_bg_top_tilemap = &machine().tilemap().create(*m_gfxdecode, tilemap_get_info_delegate(*this, FUNC(punchout_state::armwrest_top_get_info)), TILEMAP_SCAN_ROWS,  8,8, 32,32);
	m_bg_bot_tilemap = &machine().tilemap().create(*m_gfxdecode, tilemap_get_info_delegate(*this, FUNC(punchout_state::armwrest_bot_get_info)), TILEMAP_SCAN_ROWS,  8,8, 32,32);

	m_spr1_tilemap = &machine().tilemap().create(*m_gfxdecode, tilemap_get_info_delegate(*this, FUNC(punchout_state::bs1_get_info)), tilemap_mapper_delegate(*this, FUNC(punchout_state::armwrest_bs1_scan)),  8,8, 32,16);
	m_spr1_tilemap_flipx = &machine().tilemap().create(*m_gfxdecode, tilemap_get_info_delegate(*this, FUNC(punchout_state::bs1_get_info)), tilemap_mapper_delegate(*this, FUNC(punchout_state::armwrest_bs1_scan_flipx)),  8,8, 32,16);
	m_spr2_tilemap = &machine().tilemap().create(*m_gfxdecode, tilemap_get_info_delegate(*this, FUNC(punchout_state::bs2_get_info)), TILEMAP_SCAN_ROWS,  8,8, 16,32);
	m_fg_tilemap = &machine().tilemap().create(*m_gfxdecode, tilemap_get_info_delegate(*this, FUNC(punchout_state::armwrest_fg_get_info)), TILEMAP_SCAN_ROWS,  8,8, 32,32);

	m_spr1_tilemap->set_transparent_pen(0x07);
	m_spr1_tilemap_flipx->set_transparent_pen(0x07);
	m_spr2_tilemap->set_transparent_pen(0x03);
	m_fg_tilemap->set_transparent_pen(0x07);
}



WRITE8_MEMBER(punchout_state::punchout_bg_top_videoram_w)
{
	m_bg_top_videoram[offset] = data;
	m_bg_top_tilemap->mark_tile_dirty(offset/2);
}

WRITE8_MEMBER(punchout_state::punchout_bg_bot_videoram_w)
{
	m_bg_bot_videoram[offset] = data;
	m_bg_bot_tilemap->mark_tile_dirty(offset/2);
}

WRITE8_MEMBER(punchout_state::armwrest_fg_videoram_w)
{
	m_armwrest_fg_videoram[offset] = data;
	m_fg_tilemap->mark_tile_dirty(offset/2);
}

WRITE8_MEMBER(punchout_state::punchout_spr1_videoram_w)
{
	m_spr1_videoram[offset] = data;
	m_spr1_tilemap->mark_tile_dirty(offset/4);
	if (m_spr1_tilemap_flipx)
		m_spr1_tilemap_flipx->mark_tile_dirty(offset/4);
}

WRITE8_MEMBER(punchout_state::punchout_spr2_videoram_w)
{
	m_spr2_videoram[offset] = data;
	m_spr2_tilemap->mark_tile_dirty(offset/4);
}



void punchout_state::draw_big_sprite(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect, int palette)
{
	int zoom;

	zoom = m_spr1_ctrlram[0] + 256 * (m_spr1_ctrlram[1] & 0x0f);
	if (zoom)
	{
		int sx,sy;
		uint32_t startx,starty;
		int incxx,incyy;

		sx = 4096 - (m_spr1_ctrlram[2] + 256 * (m_spr1_ctrlram[3] & 0x0f));
		if (sx > 4096-4*127) sx -= 4096;

		sy = -(m_spr1_ctrlram[4] + 256 * (m_spr1_ctrlram[5] & 1));
		if (sy <= -256 + zoom/0x40) sy += 512;
		sy += 12;

		incxx = zoom << 6;
		incyy = zoom << 6;

		startx = -sx * 0x4000;
		starty = -sy * 0x10000;
		startx += 3740 * zoom;  /* adjustment to match the screen shots */
		starty -= 178 * zoom;   /* and make the hall of fame picture nice */

		if (m_spr1_ctrlram[6] & 1)   /* flip x */
		{
			startx = ((16 * 8) << 16) - startx - 1;
			incxx = -incxx;
		}

		m_spr1_tilemap->set_palette_offset(0x100 * palette);

		m_spr1_tilemap->draw_roz(screen, bitmap, cliprect,
			startx,starty + 0x200*(2) * zoom,
			incxx,0,0,incyy,    /* zoom, no rotation */
			0,  /* no wraparound */
			0,0);
	}
}


void punchout_state::armwrest_draw_big_sprite(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect, int palette)
{
	int zoom;

	zoom = m_spr1_ctrlram[0] + 256 * (m_spr1_ctrlram[1] & 0x0f);
	if (zoom)
	{
		int sx,sy;
		uint32_t startx,starty;
		int incxx,incyy;
		tilemap_t *_tilemap;

		sx = 4096 - (m_spr1_ctrlram[2] + 256 * (m_spr1_ctrlram[3] & 0x0f));
		if (sx > 2048) sx -= 4096;

		sy = -(m_spr1_ctrlram[4] + 256 * (m_spr1_ctrlram[5] & 1));
		if (sy <= -256 + zoom/0x40) sy += 512;
		sy += 12;

		incxx = zoom << 6;
		incyy = zoom << 6;

		startx = -sx * 0x4000;
		starty = -sy * 0x10000;
		startx += 3740 * zoom;  /* adjustment to match the screen shots */
		starty -= 178 * zoom;   /* and make the hall of fame picture nice */

		if (m_spr1_ctrlram[6] & 1)   /* flip x */
		{
			_tilemap = m_spr1_tilemap_flipx;
			startx = ((32 * 8) << 16) - startx - 1;
			incxx = -incxx;
		}
		else
			_tilemap = m_spr1_tilemap;

		_tilemap->set_palette_offset(0x100 * palette);

		_tilemap->draw_roz(screen, bitmap, cliprect,
			startx,starty + 0x200*(2) * zoom,
			incxx,0,0,incyy,    /* zoom, no rotation */
			0,  /* no wraparound */
			0,0);
	}
}

void punchout_state::drawbs2(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect)
{
	int sx,sy;
	int incxx;

	sx = 512 - (m_spr2_ctrlram[0] + 256 * (m_spr2_ctrlram[1] & 1));
	if (sx > 512-127) sx -= 512;
	sx -= 55;   /* adjustment to match the screen shots */

	sy = -m_spr2_ctrlram[2] + 256 * (m_spr2_ctrlram[3] & 1);
	sy += 3;    /* adjustment to match the screen shots */

	sx = -sx << 16;
	sy = -sy << 16;

	if (m_spr2_ctrlram[4] & 1)   /* flip x */
	{
		sx = ((16 * 8) << 16) - sx - 1;
		incxx = -1;
	}
	else
		incxx = 1;

	// this tilemap doesn't actually zoom, but draw_roz is the only way to draw it without wraparound
	m_spr2_tilemap->draw_roz(screen, bitmap, cliprect,
		sx, sy, incxx << 16, 0, 0, 1 << 16,
		0, 0, 0);
}



void punchout_state::punchout_copy_top_palette(int bank)
{
	int i;
	const uint8_t *color_prom = memregion("proms")->base();

	// top monitor palette
	for (i = 0; i < 0x100; i++)
	{
		int base = 0x100 * bank;
		int r, g, b;

		r = 255 - pal4bit(color_prom[i + 0x000 + base]);
		g = 255 - pal4bit(color_prom[i + 0x200 + base]);
		b = 255 - pal4bit(color_prom[i + 0x400 + base]);

		m_palette->set_pen_color(i, rgb_t(r, g, b)); // pink labeled color proms
		//m_palette->set_pen_color(i ^ 0xff, rgb_t(r, g, b)); // in case of white labeled color proms
	}
}

void punchout_state::punchout_copy_bot_palette(int bank)
{
	int i;
	const uint8_t *color_prom = memregion("proms")->base() + 0x600;

	// bottom monitor palette
	for (i = 0; i < 0x100; i++)
	{
		int base = 0x100 * bank;
		int r, g, b;

		r = 255 - pal4bit(color_prom[i + 0x000 + base]);
		g = 255 - pal4bit(color_prom[i + 0x200 + base]);
		b = 255 - pal4bit(color_prom[i + 0x400 + base]);

		m_palette->set_pen_color(i + 0x100, rgb_t(r, g, b)); // pink labeled color proms
		//m_palette->set_pen_color((i ^ 0xff) + 0x100, rgb_t(r, g, b)); // in case of white labeled color proms
	}
}


uint32_t punchout_state::screen_update_punchout_top(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect)
{
	punchout_copy_top_palette(BIT(*m_palettebank,1));

	m_bg_top_tilemap->draw(screen, bitmap, cliprect, 0, 0);

	if (m_spr1_ctrlram[7] & 1)  /* display in top monitor */
		draw_big_sprite(screen, bitmap, cliprect, 0);

	return 0;
}

uint32_t punchout_state::screen_update_punchout_bottom(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect)
{
	int offs;

	punchout_copy_bot_palette(BIT(*m_palettebank,0));

	/* copy the character mapped graphics */
	for (offs = 0;offs < 32;offs++)
		m_bg_bot_tilemap->set_scrollx(offs, 58 + m_bg_bot_videoram[2*offs] + 256 * (m_bg_bot_videoram[2*offs + 1] & 0x01));

	m_bg_bot_tilemap->draw(screen, bitmap, cliprect, 0, 0);

	if (m_spr1_ctrlram[7] & 2)  /* display in bottom monitor */
		draw_big_sprite(screen, bitmap, cliprect, 1);
	drawbs2(screen, bitmap, cliprect);

	return 0;
}


uint32_t punchout_state::screen_update_armwrest_top(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect)
{
	punchout_copy_top_palette(BIT(*m_palettebank,1));

	m_bg_top_tilemap->draw(screen, bitmap, cliprect, 0, 0);

	if (m_spr1_ctrlram[7] & 1)  /* display in top monitor */
		armwrest_draw_big_sprite(screen, bitmap, cliprect, 0);

	return 0;
}

uint32_t punchout_state::screen_update_armwrest_bottom(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect)
{
	punchout_copy_bot_palette(BIT(*m_palettebank,0));

	m_bg_bot_tilemap->draw(screen, bitmap, cliprect, 0, 0);

	if (m_spr1_ctrlram[7] & 2)  /* display in bottom monitor */
		armwrest_draw_big_sprite(screen, bitmap, cliprect, 1);
	drawbs2(screen, bitmap, cliprect);

	m_fg_tilemap->draw(screen, bitmap, cliprect, 0, 0);

	return 0;
}