summaryrefslogtreecommitdiffstatshomepage
path: root/src/mame/video/tecmo_mix.cpp
blob: ae56f25bbcea39dd37a6e9f427864aad5cbb6988 (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
// license:BSD-3-Clause
// copyright-holders:David Haywood

#include "emu.h"
#include "tecmo_mix.h"


const device_type TECMO_MIXER = &device_creator<tecmo_mix_device>;

tecmo_mix_device::tecmo_mix_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
	: device_t(mconfig, TECMO_MIXER, "Tecmo 16-bit Mixer", tag, owner, clock, "tecmo_mix", __FILE__),
		device_video_interface(mconfig, *this),
		m_sprpri_shift(0),
		m_sprbln_shift(0),
		m_sprcol_shift(0),

		m_spblend_source(0),
		m_fgblend_source(0),

		m_bgblend_comp(0),
		m_fgblend_comp(0),
		m_txblend_comp(0),
		m_spblend_comp(0),

		m_bgregular_comp(0),
		m_fgregular_comp(0),
		m_txregular_comp(0),
		m_spregular_comp(0),

		m_revspritetile(0),
		m_bgpen(0)

{
}


void tecmo_mix_device::device_start()
{
}

void tecmo_mix_device::device_reset()
{
}



void tecmo_mix_device::set_mixer_shifts(device_t &device, int sprpri_shift, int sprbln_shift, int sprcol_shift)
{
	tecmo_mix_device &dev = downcast<tecmo_mix_device &>(device);
	dev.m_sprpri_shift = sprpri_shift;
	dev.m_sprbln_shift = sprbln_shift;
	dev.m_sprcol_shift = sprcol_shift;
}

void tecmo_mix_device::set_blendcols(device_t &device, int bgblend_comp, int fgblend_comp, int txblend_comp, int spblend_comp)
{
	tecmo_mix_device &dev = downcast<tecmo_mix_device &>(device);
	dev.m_bgblend_comp = bgblend_comp;
	dev.m_fgblend_comp = fgblend_comp;
	dev.m_txblend_comp = txblend_comp;
	dev.m_spblend_comp = spblend_comp;
}

void tecmo_mix_device::set_regularcols(device_t &device, int bgregular_comp, int fgregular_comp, int txregular_comp, int spregular_comp)
{
	tecmo_mix_device &dev = downcast<tecmo_mix_device &>(device);
	dev.m_bgregular_comp = bgregular_comp;
	dev.m_fgregular_comp = fgregular_comp;
	dev.m_txregular_comp = txregular_comp;
	dev.m_spregular_comp = spregular_comp;
}

void tecmo_mix_device::set_blendsource(device_t &device, int spblend_source, int fgblend_source)
{
	tecmo_mix_device &dev = downcast<tecmo_mix_device &>(device);
	dev.m_spblend_source = spblend_source;
	dev.m_fgblend_source = fgblend_source;
}

void tecmo_mix_device::set_revspritetile(device_t &device)
{
	tecmo_mix_device &dev = downcast<tecmo_mix_device &>(device);
	dev.m_revspritetile = 3;
}

void tecmo_mix_device::set_bgpen(device_t &device, int bgpen)
{
	tecmo_mix_device &dev = downcast<tecmo_mix_device &>(device);
	dev.m_bgpen = bgpen;
}


void tecmo_mix_device::mix_bitmaps(screen_device &screen, bitmap_rgb32 &bitmap, const rectangle &cliprect, palette_device* palette, bitmap_ind16* bitmap_bg, bitmap_ind16* bitmap_fg, bitmap_ind16* bitmap_tx, bitmap_ind16* bitmap_sp)
{
	//int frame = (screen.frame_number()) & 1;
	// note this game has no tx layer, comments relate to other drivers

	int y, x;
	const pen_t *paldata = palette->pens();

	for (y = cliprect.min_y; y <= cliprect.max_y; y++)
	{
		UINT32 *dd = &bitmap.pix32(y);
		UINT16 *sd2 = &bitmap_sp->pix16(y);
		UINT16 *fg = &bitmap_fg->pix16(y);
		UINT16 *bg = &bitmap_bg->pix16(y);

		for (x = cliprect.min_x; x <= cliprect.max_x; x++)
		{
			UINT16 sprpixel = (sd2[x]);

			UINT16 m_sprpri = (sprpixel >> m_sprpri_shift) & 0x3;
			UINT16 m_sprbln = (sprpixel >> m_sprbln_shift) & 0x1;
			UINT16 m_sprcol = (sprpixel >> m_sprcol_shift) & 0xf;


			sprpixel = (sprpixel & 0xf) | (m_sprcol << 4);

			//sprpixel &= 0xff;

			UINT16 fgpixel = (fg[x]);
			UINT16 fgbln = (fgpixel & 0x0100) >> 8;
			fgpixel &= 0xff;

			UINT16 bgpixel = (bg[x]);
			bgpixel &= 0xff;

			if (sprpixel&0xf)
			{
				if (m_sprpri == (0 ^ m_revspritetile)) // behind all
				{
					if (fgpixel & 0xf) // is the fg used?
					{
						if (fgbln)
						{
							dd[x] = rand();
						}
						else
						{
							// solid FG
							dd[x] = paldata[fgpixel + m_fgregular_comp];
						}
					}
					else if (bgpixel & 0x0f)
					{
						// solid BG
						dd[x] = paldata[bgpixel + m_bgregular_comp];
					}
					else
					{
						if (m_sprbln)
						{ // sprite is blended with bgpen?
							dd[x] = rand();
						}
						else
						{
							// solid sprite
							dd[x] = paldata[sprpixel + m_spregular_comp];
						}

					}
				}
				else  if (m_sprpri == (1 ^ m_revspritetile)) // above bg, behind tx, fg
				{
					if (fgpixel & 0xf) // is the fg used?
					{
						if (fgbln)
						{
							if (m_sprbln)
							{
								// needs if bgpixel & 0xf check?

								// fg is used and blended with sprite, sprite is used and blended with bg?  -- used on 'trail' of ball when ball is under the transparent area
								dd[x] = paldata[bgpixel + m_bgblend_comp] + paldata[sprpixel + m_spblend_source]; // WRONG??
							}
							else
							{
								// fg is used and blended with opaque sprite
								dd[x] = paldata[fgpixel + m_fgblend_source] + paldata[sprpixel + m_spblend_comp];
							}
						}
						else
						{
							// fg is used and opaque
							dd[x] = paldata[fgpixel + m_fgregular_comp];
						}

					}
					else
					{
						if (m_sprbln)
						{
							// needs if bgpixel & 0xf check?

							//fg isn't used, sprite is used and blended with bg? -- used on trail of ball / flippers (looks odd)  -- some ninja gaiden enemy deaths (when behind fg) (looks ok?)  (maybe we need to check for colour saturation?)
							dd[x] = paldata[bgpixel + m_bgblend_comp] + paldata[sprpixel + m_spblend_source];
						}
						else
						{
							// fg isn't used, sprite is used and is opaque
							dd[x] = paldata[sprpixel + m_spregular_comp];
						}
					}


				}
				else if (m_sprpri == (2 ^ m_revspritetile)) // above bg,fg, behind tx
				{
					if (m_sprbln)
					{
						if (fgpixel & 0xf) // is the fg used?
						{
							if (fgbln)
							{
								// blended sprite over blended fg pixel?
								dd[x] =  rand();
							}
							else
							{
								// blended sprite over solid fgpixel?
								dd[x] = paldata[fgpixel + m_fgblend_comp] + paldata[sprpixel + m_spblend_source];
							}
						}
						else // needs if bgpixel & 0xf check?
						{
							// blended sprite over solid bg pixel
							dd[x] = paldata[bgpixel + m_bgblend_comp] + paldata[sprpixel + m_spblend_source];
						//  dd[x] =  rand();
						}



					}
					else
					{
						dd[x] = paldata[sprpixel + m_spregular_comp];
                        //dd[x] = rand();
						// the bad tiles on the wildfang map (shown between levels) are drawn here.. why? looks like they should be transparent? 
						// most wildfang sprites use this and are fine, so what's going wrong?
					}
				}

				else if (m_sprpri == (3 ^ m_revspritetile)) // above all?
				{
					if (m_sprbln)
					{
						// unusued by this game?
						dd[x] = rand();
					}
					else
					{
						dd[x] = paldata[sprpixel + m_spregular_comp];
					}

				}
			}
			else // NON SPRITE CASES
			{
				if (fgpixel & 0x0f)
				{
					if (fgbln)
					{
						// needs if bgpixel & 0xf check?
						dd[x] = paldata[fgpixel + m_fgblend_source] + paldata[bgpixel + m_bgblend_comp];

					}
					else
					{
						dd[x] = paldata[fgpixel + m_fgregular_comp];
					}

				}
				else if (bgpixel & 0x0f)
				{
					dd[x] = paldata[bgpixel + m_bgregular_comp];
				}
				else
				{
					dd[x] = paldata[m_bgpen];// pen 0x200 on raiga  0xb00 on spbactn
				}
			}
		}
	}
}