summaryrefslogtreecommitdiffstatshomepage
path: root/src/mame/video/namcos2.cpp
blob: 4d2704e162dccd201d1812cd45dc1d0101f52020 (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
// license:BSD-3-Clause
// copyright-holders:K.Wilkins
/* video hardware for Namco System II */

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

void namcos2_state::TilemapCB(uint16_t code, int *tile, int *mask)
{
	*mask = code;
	/* The order of bits needs to be corrected to index the right tile  14 15 11 12 13 */
	*tile = bitswap<16>(code, 13, 12, 11, 15, 14, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0);
}

void namcos2_state::TilemapCB_finalap2(uint16_t code, int *tile, int *mask)
{
	*mask = code;
	*tile = bitswap<15>(code, 13, 12, 11, 14, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0);
}

/**
 * m_gfx_ctrl selects a bank of 128 sprites within spriteram
 *
 * m_gfx_ctrl also supplies palette and priority information that is applied to the output of the
 *            Namco System 2 ROZ chip
 *
 * -xxx ---- ---- ---- roz priority
 * ---- xxxx ---- ---- roz palette
 * ---- ---- xxxx ---- always zero?
 * ---- ---- ---- xxxx sprite bank
 */
READ16_MEMBER(namcos2_state::gfx_ctrl_r)
{
	return m_gfx_ctrl;
}

WRITE16_MEMBER(namcos2_state::gfx_ctrl_w)
{
	COMBINE_DATA(&m_gfx_ctrl);
}

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

READ8_MEMBER(namcos2_state::c116_r)
{
	if ((offset & 0x1800) == 0x1800)
	{
		/* palette register */
		offset &= 0x180f;

		/* registers 6,7: unmapped? */
		if (offset > 0x180b) return 0xff; // fix for finallap boot
	}
	return m_c116->read(space, offset, mem_mask);
}

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

void namcos2_state::create_shadow_table()
{
	/* set table for sprite color == 0x0f */
	for (int i = 0; i < 16 * 256; i++)
	{
		m_c116->shadow_table()[i] = i + 0x2000;
	}
}

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

void namcos2_state::video_start()
{
	create_shadow_table();
}

void namcos2_state::apply_clip(rectangle &clip, const rectangle &cliprect)
{
	clip.min_x = m_c116->get_reg(0) - 0x4a;
	clip.max_x = m_c116->get_reg(1) - 0x4a - 1;
	clip.min_y = m_c116->get_reg(2) - 0x21;
	clip.max_y = m_c116->get_reg(3) - 0x21 - 1;
	/* intersect with master clip rectangle */
	clip &= cliprect;
}

uint32_t namcos2_state::screen_update(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect)
{
	rectangle clip;
	int pri;

	bitmap.fill(m_c116->black_pen(), cliprect);
	apply_clip(clip, cliprect);

	/* HACK: enable ROZ layer only if it has priority > 0 */
	// Phelios contradicts with this so disabled
	// (level 0 ROZ is actually used by stages 2, 3 and 4 at very least)
	//bool roz_enable = ((m_gfx_ctrl & 0x7000) ? true : false);

	for (pri = 0; pri < 16; pri++)
	{
		if ((pri & 1) == 0)
		{
			m_c123tmap->draw(screen, bitmap, clip, pri / 2);

			//if (roz_enable)
			{
				if (((m_gfx_ctrl & 0x7000) >> 12) == pri / 2)
				{
					m_ns2roz->draw_roz(screen, bitmap, clip, m_gfx_ctrl);
				}
			}
			m_ns2sprite->draw_sprites(screen, bitmap, clip, pri / 2, m_gfx_ctrl);
		}
	}
	return 0;
}

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

uint32_t namcos2_state::screen_update_finallap(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect)
{
	rectangle clip;
	int pri;

	bitmap.fill(m_c116->black_pen(), cliprect);
	apply_clip(clip, cliprect);

	for (pri = 0; pri < 16; pri++)
	{
		if ((pri & 1) == 0)
		{
			m_c123tmap->draw(screen, bitmap, clip, pri / 2);
		}
		m_c45_road->draw(bitmap, clip, pri);
		m_ns2sprite->draw_sprites(screen, bitmap, clip, pri, m_gfx_ctrl);
	}
	return 0;
}

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

void namcos2_state::RozCB_luckywld(uint16_t code, int *tile, int *mask, int which)
{
	*mask = code;

	uint16_t mangle = bitswap<11>(code & 0x31ff, 13, 12, 8, 7, 6, 5, 4, 3, 2, 1, 0);
	switch ((code >> 9) & 7)
	{
	case 0x00: mangle += 0x1c00; break; // Plus, NOT OR
	case 0x01: mangle |= 0x0800; break;
	case 0x02: mangle |= 0x0000; break;
	default: break;
	}

	*tile = mangle;
}

void namcos2_state::video_start_luckywld()
{
}

uint32_t namcos2_state::screen_update_luckywld(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect)
{
	rectangle clip;
	int pri;

	bitmap.fill(m_c116->black_pen(), cliprect);
	apply_clip(clip, cliprect);

	for (pri = 0; pri < 16; pri++)
	{
		if ((pri & 1) == 0)
		{
			m_c123tmap->draw(screen, bitmap, clip, pri / 2);
		}
		m_c45_road->draw(bitmap, clip, pri);

		if (m_c169roz)
			m_c169roz->draw(screen, bitmap, clip, pri);

		m_c355spr->draw(screen, bitmap, clip, pri);
	}
	return 0;
}

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

void namcos2_state::video_start_sgunner()
{
}

uint32_t namcos2_state::screen_update_sgunner(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect)
{
	rectangle clip;
	int pri;

	bitmap.fill(m_c116->black_pen(), cliprect);
	apply_clip(clip, cliprect);

	for (pri = 0; pri < 8; pri++)
	{
		m_c123tmap->draw(screen, bitmap, clip, pri);
		m_c355spr->draw(screen, bitmap, clip, pri);
	}
	return 0;
}


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

void namcos2_state::RozCB_metlhawk(uint16_t code, int *tile, int *mask, int which)
{
	*mask = code;
	*tile = bitswap<13>(code & 0x1fff, 11, 10, 9, 12, 8, 7, 6, 5, 4, 3, 2, 1, 0);
}

void namcos2_state::video_start_metlhawk()
{
}

uint32_t namcos2_state::screen_update_metlhawk(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect)
{
	rectangle clip;
	int pri;

	bitmap.fill(m_c116->black_pen(), cliprect);
	apply_clip(clip, cliprect);

	for (pri = 0; pri < 16; pri++)
	{
		if ((pri & 1) == 0)
		{
			m_c123tmap->draw(screen, bitmap, clip, pri / 2);
		}
		m_c169roz->draw(screen, bitmap, clip, pri);
		m_ns2sprite->draw_sprites_metalhawk(screen, bitmap, clip, pri);
	}
	return 0;
}