trunk/src/mame/video/n64.c
r241381 | r241382 | |
1 | | /******************************************************************************
|
2 | | |
3 | | |
4 | | SGI/Nintendo Reality Display Processor
|
5 | | -------------------
|
6 | | |
7 | | by MooglyGuy
|
8 | | based on initial C code by Ville Linde
|
9 | | contains additional improvements from angrylion, Ziggy, Gonetz and Orkin
|
10 | | |
11 | | |
12 | | *******************************************************************************
|
13 | | |
14 | | STATUS:
|
15 | | |
16 | | Much behavior needs verification against real hardware. Many edge cases must
|
17 | | be verified on real hardware as well.
|
18 | | |
19 | | TODO:
|
20 | | |
21 | | - Further re-work class structure to avoid dependencies
|
22 | | |
23 | | *******************************************************************************/
|
24 | | |
25 | | #include "emu.h"
|
26 | | //#include "includes/n64.h"
|
27 | | #include "video/n64.h"
|
28 | | |
29 | | #define LOG_RDP_EXECUTION 0
|
30 | | |
31 | | static FILE *rdp_exec;
|
32 | | |
33 | | UINT32 n64_rdp::s_special_9bit_clamptable[512];
|
34 | | |
35 | | bool n64_rdp::rdp_range_check(UINT32 addr)
|
36 | | {
|
37 | | if(MiscState.FBSize == 0) return false;
|
38 | | |
39 | | int fbcount = ((MiscState.FBWidth * Scissor.m_yl) << (MiscState.FBSize - 1)) * 3;
|
40 | | int fbaddr = MiscState.FBAddress & 0x007fffff;
|
41 | | if ((addr >= fbaddr) && (addr < (fbaddr + fbcount)))
|
42 | | {
|
43 | | return false;
|
44 | | }
|
45 | | |
46 | | int zbcount = MiscState.FBWidth * Scissor.m_yl * 2;
|
47 | | int zbaddr = MiscState.ZBAddress & 0x007fffff;
|
48 | | if ((addr >= zbaddr) && (addr < (zbaddr + zbcount)))
|
49 | | {
|
50 | | return false;
|
51 | | }
|
52 | | |
53 | | printf("Check failed: %08x vs. %08x-%08x, %08x-%08x (%d, %d)\n", addr, fbaddr, fbaddr + fbcount, zbaddr, zbaddr + zbcount, MiscState.FBWidth, Scissor.m_yl);
|
54 | | fflush(stdout);
|
55 | | return true;
|
56 | | }
|
57 | | |
58 | | /*****************************************************************************/
|
59 | | |
60 | | // The functions in this file should be moved into the parent Processor class.
|
61 | | #include "rdpfiltr.inc"
|
62 | | |
63 | | void n64_rdp::GetAlphaCvg(UINT8 *comb_alpha, rdp_span_aux *userdata, const rdp_poly_state &object)
|
64 | | {
|
65 | | INT32 temp = *comb_alpha;
|
66 | | INT32 temp2 = userdata->CurrentPixCvg;
|
67 | | INT32 temp3 = 0;
|
68 | | |
69 | | if (object.OtherModes.cvg_times_alpha)
|
70 | | {
|
71 | | temp3 = (temp * temp2) + 4;
|
72 | | userdata->CurrentPixCvg = (temp3 >> 8) & 0xf;
|
73 | | }
|
74 | | if (object.OtherModes.alpha_cvg_select)
|
75 | | {
|
76 | | temp = (OtherModes.cvg_times_alpha) ? (temp3 >> 3) : (temp2 << 5);
|
77 | | }
|
78 | | if (temp > 0xff)
|
79 | | {
|
80 | | temp = 0xff;
|
81 | | }
|
82 | | *comb_alpha = temp;
|
83 | | }
|
84 | | |
85 | | /*****************************************************************************/
|
86 | | |
87 | | void n64_rdp::VideoUpdate(n64_periphs *n64, bitmap_rgb32 &bitmap)
|
88 | | {
|
89 | | switch(n64->vi_control & 0x3)
|
90 | | {
|
91 | | case PIXEL_SIZE_16BIT:
|
92 | | VideoUpdate16(n64, bitmap);
|
93 | | break;
|
94 | | |
95 | | case PIXEL_SIZE_32BIT:
|
96 | | VideoUpdate32(n64, bitmap);
|
97 | | break;
|
98 | | |
99 | | default:
|
100 | | //fatalerror("Unsupported framebuffer depth: m_fb_size=%d\n", MiscState.FBSize);
|
101 | | break;
|
102 | | }
|
103 | | }
|
104 | | |
105 | | void n64_rdp::VideoUpdate16(n64_periphs *n64, bitmap_rgb32 &bitmap)
|
106 | | {
|
107 | | //int fsaa = (((n64->vi_control >> 8) & 3) < 2);
|
108 | | //int divot = (n64->vi_control >> 4) & 1;
|
109 | | |
110 | | //UINT32 prev_cvg = 0;
|
111 | | //UINT32 next_cvg = 0;
|
112 | | //int dither_filter = (n64->vi_control >> 16) & 1;
|
113 | | //int vibuffering = ((n64->vi_control & 2) && fsaa && divot);
|
114 | | |
115 | | UINT16 *frame_buffer = (UINT16*)&rdram[(n64->vi_origin & 0xffffff) >> 2];
|
116 | | //UINT32 hb = ((n64->vi_origin & 0xffffff) >> 2) >> 1;
|
117 | | //UINT8* hidden_buffer = &HiddenBits[hb];
|
118 | | |
119 | | INT32 hdiff = (n64->vi_hstart & 0x3ff) - ((n64->vi_hstart >> 16) & 0x3ff);
|
120 | | float hcoeff = ((float)(n64->vi_xscale & 0xfff) / (1 << 10));
|
121 | | UINT32 hres = ((float)hdiff * hcoeff);
|
122 | | INT32 invisiblewidth = n64->vi_width - hres;
|
123 | | |
124 | | INT32 vdiff = ((n64->vi_vstart & 0x3ff) - ((n64->vi_vstart >> 16) & 0x3ff)) >> 1;
|
125 | | float vcoeff = ((float)(n64->vi_yscale & 0xfff) / (1 << 10));
|
126 | | UINT32 vres = ((float)vdiff * vcoeff);
|
127 | | |
128 | | if (vdiff <= 0 || hdiff <= 0)
|
129 | | {
|
130 | | return;
|
131 | | }
|
132 | | |
133 | | if (hres > 640) // Needed by Top Gear Overdrive (E)
|
134 | | {
|
135 | | invisiblewidth += (hres - 640);
|
136 | | hres = 640;
|
137 | | }
|
138 | | |
139 | | if (vres > bitmap.height()) // makes Perfect Dark boot w/o crashing
|
140 | | {
|
141 | | vres = bitmap.height();
|
142 | | }
|
143 | | |
144 | | UINT32 pixels = 0;
|
145 | | |
146 | | if (frame_buffer)
|
147 | | {
|
148 | | for(int j = 0; j < vres; j++)
|
149 | | {
|
150 | | UINT32 *d = &bitmap.pix32(j);
|
151 | | |
152 | | for(int i = 0; i < hres; i++)
|
153 | | {
|
154 | | Color c;
|
155 | | //int r, g, b;
|
156 | | |
157 | | UINT16 pix = frame_buffer[pixels ^ WORD_ADDR_XOR];
|
158 | | //MiscState.CurrentPixCvg = ((pix & 1) << 2) | (hidden_buffer[pixels ^ BYTE_ADDR_XOR] & 3);
|
159 | | |
160 | | //if(divot)
|
161 | | //{
|
162 | | // if(i > 0 && i < (hres - 1))
|
163 | | // {
|
164 | | // prev_cvg = ((frame_buffer[(pixels - 1)^WORD_ADDR_XOR] & 1) << 2) | (hidden_buffer[(pixels - 1)^BYTE_ADDR_XOR] & 3);
|
165 | | // next_cvg = ((frame_buffer[(pixels + 1)^WORD_ADDR_XOR] & 1) << 2) | (hidden_buffer[(pixels + 1)^BYTE_ADDR_XOR] & 3);
|
166 | | // }
|
167 | | //}
|
168 | | c.i.r = ((pix >> 8) & 0xf8) | (pix >> 13);
|
169 | | c.i.g = ((pix >> 3) & 0xf8) | ((pix >> 8) & 0x07);
|
170 | | c.i.b = ((pix << 2) & 0xf8) | ((pix >> 3) & 0x07);
|
171 | | |
172 | | //if(fsaa)
|
173 | | //{
|
174 | | //if (/*!vibuffering &&*/ state->m_rdp.MiscState.CurrentPixCvg < 7 && i > 1 && j > 1 && i < (hres - 2) && j < (vres - 2))
|
175 | | //{
|
176 | | //video_filter16(&c.i.r, &c.i.g, &c.i.b, &frame_buffer[pixels ^ WORD_ADDR_XOR],&hidden_buffer[pixels ^ BYTE_ADDR_XOR], n64->vi_width);
|
177 | | //}
|
178 | | //}
|
179 | | //else if (dither_filter && state->m_rdp.MiscState.CurrentPixCvg == 7 && i > 0 && j > 0 && i < (hres - 1) && j < (vres - 1))
|
180 | | //{
|
181 | | //if (vibuffering)
|
182 | | //{
|
183 | | // restore_filter16_buffer(&r, &g, &b, &ViBuffer[i][j], n64->vi_width);
|
184 | | //}
|
185 | | //else
|
186 | | //{
|
187 | | //restore_filter16(&c.i.r, &c.i.g, &c.i.b, &frame_buffer[pixels ^ WORD_ADDR_XOR], pixels ^ WORD_ADDR_XOR, n64->vi_width);
|
188 | | //}
|
189 | | //}
|
190 | | //if(divot)
|
191 | | //{
|
192 | | //if (i > 0 && i < (hres - 1) && (MiscState.CurrentPixCvg != 7 || prev_cvg != 7 || next_cvg != 7))
|
193 | | //{
|
194 | | //if (vibuffering)
|
195 | | //{
|
196 | | // divot_filter16_buffer(&r, &g, &b, &ViBuffer[i][j]);
|
197 | | //}
|
198 | | //else
|
199 | | //{
|
200 | | //divot_filter16(&c.i.r, &c.i.g, &c.i.b, &frame_buffer[pixels ^ WORD_ADDR_XOR], pixels ^ WORD_ADDR_XOR);
|
201 | | //}
|
202 | | //}
|
203 | | //}
|
204 | | |
205 | | /*
|
206 | | if (gamma_dither)
|
207 | | {
|
208 | | dith = screen.machine().rand() & 0x3f;
|
209 | | }
|
210 | | if (gamma)
|
211 | | {
|
212 | | if (gamma_dither)
|
213 | | {
|
214 | | r = m_gamma_dither_table[(r << 6)|dith];
|
215 | | g = m_gamma_dither_table[(g << 6)|dith];
|
216 | | b = m_gamma_dither_table[(b << 6)|dith];
|
217 | | }
|
218 | | else
|
219 | | {
|
220 | | r = m_gamma_table[r];
|
221 | | g = m_gamma_table[g];
|
222 | | b = m_gamma_table[b];
|
223 | | }
|
224 | | }
|
225 | | else if (gamma_dither)
|
226 | | {
|
227 | | if (r < 255)
|
228 | | r += (dith & 1);
|
229 | | if (g < 255)
|
230 | | g += (dith & 1);
|
231 | | if (b < 255)
|
232 | | b += (dith & 1);
|
233 | | }
|
234 | | */
|
235 | | pixels++;
|
236 | | |
237 | | d[i] = c.c >> 8;//(r << 16) | (g << 8) | b; // Fix me for endianness
|
238 | | }
|
239 | | pixels +=invisiblewidth;
|
240 | | }
|
241 | | }
|
242 | | }
|
243 | | |
244 | | void n64_rdp::VideoUpdate32(n64_periphs *n64, bitmap_rgb32 &bitmap)
|
245 | | {
|
246 | | int gamma = (n64->vi_control >> 3) & 1;
|
247 | | int gamma_dither = (n64->vi_control >> 2) & 1;
|
248 | | //int vibuffering = ((n64->vi_control & 2) && fsaa && divot);
|
249 | | |
250 | | UINT32 *frame_buffer32 = (UINT32*)&rdram[(n64->vi_origin & 0xffffff) >> 2];
|
251 | | |
252 | | const INT32 hdiff = (n64->vi_hstart & 0x3ff) - ((n64->vi_hstart >> 16) & 0x3ff);
|
253 | | const float hcoeff = ((float)(n64->vi_xscale & 0xfff) / (1 << 10));
|
254 | | UINT32 hres = ((float)hdiff * hcoeff);
|
255 | | INT32 invisiblewidth = n64->vi_width - hres;
|
256 | | |
257 | | const INT32 vdiff = ((n64->vi_vstart & 0x3ff) - ((n64->vi_vstart >> 16) & 0x3ff)) >> 1;
|
258 | | const float vcoeff = ((float)(n64->vi_yscale & 0xfff) / (1 << 10));
|
259 | | const UINT32 vres = ((float)vdiff * vcoeff);
|
260 | | |
261 | | if (vdiff <= 0 || hdiff <= 0)
|
262 | | {
|
263 | | return;
|
264 | | }
|
265 | | |
266 | | if (hres > 640) // Needed by Top Gear Overdrive (E)
|
267 | | {
|
268 | | invisiblewidth += (hres - 640);
|
269 | | hres = 640;
|
270 | | }
|
271 | | |
272 | | if (frame_buffer32)
|
273 | | {
|
274 | | for (int j = 0; j < vres; j++)
|
275 | | {
|
276 | | UINT32 *d = &bitmap.pix32(j);
|
277 | | for (int i = 0; i < hres; i++)
|
278 | | {
|
279 | | UINT32 pix = *frame_buffer32++;
|
280 | | if (gamma || gamma_dither)
|
281 | | {
|
282 | | int r = (pix >> 24) & 0xff;
|
283 | | int g = (pix >> 16) & 0xff;
|
284 | | int b = (pix >> 8) & 0xff;
|
285 | | int dith = 0;
|
286 | | if (gamma_dither)
|
287 | | {
|
288 | | dith = GetRandom() & 0x3f;
|
289 | | }
|
290 | | if (gamma)
|
291 | | {
|
292 | | if (gamma_dither)
|
293 | | {
|
294 | | r = m_gamma_dither_table[(r << 6)| dith];
|
295 | | g = m_gamma_dither_table[(g << 6)| dith];
|
296 | | b = m_gamma_dither_table[(b << 6)| dith];
|
297 | | }
|
298 | | else
|
299 | | {
|
300 | | r = m_gamma_table[r];
|
301 | | g = m_gamma_table[g];
|
302 | | b = m_gamma_table[b];
|
303 | | }
|
304 | | }
|
305 | | else if (gamma_dither)
|
306 | | {
|
307 | | if (r < 255)
|
308 | | r += (dith & 1);
|
309 | | if (g < 255)
|
310 | | g += (dith & 1);
|
311 | | if (b < 255)
|
312 | | b += (dith & 1);
|
313 | | }
|
314 | | pix = (r << 24) | (g << 16) | (b << 8);
|
315 | | }
|
316 | | |
317 | | |
318 | | d[i] = (pix >> 8);
|
319 | | }
|
320 | | frame_buffer32 += invisiblewidth;
|
321 | | }
|
322 | | }
|
323 | | }
|
324 | | |
325 | | /*****************************************************************************/
|
326 | | |
327 | | void n64_rdp::TCDivNoPersp(INT32 ss, INT32 st, INT32 sw, INT32* sss, INT32* sst)
|
328 | | {
|
329 | | *sss = (SIGN16(ss)) & 0x1ffff;
|
330 | | *sst = (SIGN16(st)) & 0x1ffff;
|
331 | | }
|
332 | | |
333 | | void n64_rdp::TCDiv(INT32 ss, INT32 st, INT32 sw, INT32* sss, INT32* sst)
|
334 | | {
|
335 | | int w_carry = 0;
|
336 | | if ((sw & 0x8000) || !(sw & 0x7fff))
|
337 | | {
|
338 | | w_carry = 1;
|
339 | | }
|
340 | | |
341 | | sw &= 0x7fff;
|
342 | | |
343 | | int shift;
|
344 | | for (shift = 1; shift <= 14 && !((sw << shift) & 0x8000); shift++);
|
345 | | shift -= 1;
|
346 | | |
347 | | int normout = (sw << shift) & 0x3fff;
|
348 | | int wnorm = (normout & 0xff) << 2;
|
349 | | normout >>= 8;
|
350 | | |
351 | | int temppoint = m_norm_point_rom[normout];
|
352 | | int tempslope = m_norm_slope_rom[normout];
|
353 | | |
354 | | int tlu_rcp = ((-(tempslope * wnorm)) >> 10) + temppoint;
|
355 | | |
356 | | int sprod = SIGN16(ss) * tlu_rcp;
|
357 | | int tprod = SIGN16(st) * tlu_rcp;
|
358 | | int tempmask = ((1 << (shift + 1)) - 1) << (29 - shift);
|
359 | | int shift_value = 13 - shift;
|
360 | | |
361 | | int outofbounds_s = sprod & tempmask;
|
362 | | int outofbounds_t = tprod & tempmask;
|
363 | | if (shift == 0xe)
|
364 | | {
|
365 | | *sss = sprod << 1;
|
366 | | *sst = tprod << 1;
|
367 | | }
|
368 | | else
|
369 | | {
|
370 | | *sss = sprod = (sprod >> shift_value);
|
371 | | *sst = tprod = (tprod >> shift_value);
|
372 | | }
|
373 | | //compute clamp flags
|
374 | | int under_s = 0;
|
375 | | int under_t = 0;
|
376 | | int over_s = 0;
|
377 | | int over_t = 0;
|
378 | | |
379 | | if (outofbounds_s != tempmask && outofbounds_s != 0)
|
380 | | {
|
381 | | if (sprod & (1 << 29))
|
382 | | {
|
383 | | under_s = 1;
|
384 | | }
|
385 | | else
|
386 | | {
|
387 | | over_s = 1;
|
388 | | }
|
389 | | }
|
390 | | |
391 | | if (outofbounds_t != tempmask && outofbounds_t != 0)
|
392 | | {
|
393 | | if (tprod & (1 << 29))
|
394 | | {
|
395 | | under_t = 1;
|
396 | | }
|
397 | | else
|
398 | | {
|
399 | | over_t = 1;
|
400 | | }
|
401 | | }
|
402 | | |
403 | | over_s |= w_carry;
|
404 | | over_t |= w_carry;
|
405 | | |
406 | | *sss = (*sss & 0x1ffff) | (over_s << 18) | (under_s << 17);
|
407 | | *sst = (*sst & 0x1ffff) | (over_t << 18) | (under_t << 17);
|
408 | | }
|
409 | | |
410 | | INT32 n64_rdp::ColorCombinerEquation(INT32 a, INT32 b, INT32 c, INT32 d)
|
411 | | {
|
412 | | a = KURT_AKELEY_SIGN9(a);
|
413 | | b = KURT_AKELEY_SIGN9(b);
|
414 | | c = SIGN9(c);
|
415 | | d = KURT_AKELEY_SIGN9(d);
|
416 | | a = (((a - b) * c) + (d << 8) + 0x80);
|
417 | | a = SIGN17(a) >> 8;
|
418 | | a = s_special_9bit_clamptable[a & 0x1ff];
|
419 | | return a;
|
420 | | }
|
421 | | |
422 | | INT32 n64_rdp::AlphaCombinerEquation(INT32 a, INT32 b, INT32 c, INT32 d)
|
423 | | {
|
424 | | a = KURT_AKELEY_SIGN9(a);
|
425 | | b = KURT_AKELEY_SIGN9(b);
|
426 | | c = SIGN9(c);
|
427 | | d = KURT_AKELEY_SIGN9(d);
|
428 | | a = (((a - b) * c) + (d << 8) + 0x80) >> 8;
|
429 | | a = SIGN9(a);
|
430 | | a = s_special_9bit_clamptable[a & 0x1ff];
|
431 | | return a;
|
432 | | }
|
433 | | |
434 | | void n64_rdp::SetSubAInputRGB(UINT8 **input_r, UINT8 **input_g, UINT8 **input_b, int code, rdp_span_aux *userdata)
|
435 | | {
|
436 | | switch (code & 0xf)
|
437 | | {
|
438 | | case 0: *input_r = &userdata->CombinedColor.i.r; *input_g = &userdata->CombinedColor.i.g; *input_b = &userdata->CombinedColor.i.b; break;
|
439 | | case 1: *input_r = &userdata->Texel0Color.i.r; *input_g = &userdata->Texel0Color.i.g; *input_b = &userdata->Texel0Color.i.b; break;
|
440 | | case 2: *input_r = &userdata->Texel1Color.i.r; *input_g = &userdata->Texel1Color.i.g; *input_b = &userdata->Texel1Color.i.b; break;
|
441 | | case 3: *input_r = &userdata->PrimColor.i.r; *input_g = &userdata->PrimColor.i.g; *input_b = &userdata->PrimColor.i.b; break;
|
442 | | case 4: *input_r = &userdata->ShadeColor.i.r; *input_g = &userdata->ShadeColor.i.g; *input_b = &userdata->ShadeColor.i.b; break;
|
443 | | case 5: *input_r = &userdata->EnvColor.i.r; *input_g = &userdata->EnvColor.i.g; *input_b = &userdata->EnvColor.i.b; break;
|
444 | | case 6: *input_r = &OneColor.i.r; *input_g = &OneColor.i.g; *input_b = &OneColor.i.b; break;
|
445 | | case 7: *input_r = &userdata->NoiseColor.i.r; *input_g = &userdata->NoiseColor.i.g; *input_b = &userdata->NoiseColor.i.b; break;
|
446 | | case 8: case 9: case 10: case 11: case 12: case 13: case 14: case 15:
|
447 | | {
|
448 | | *input_r = &ZeroColor.i.r; *input_g = &ZeroColor.i.g; *input_b = &ZeroColor.i.b; break;
|
449 | | }
|
450 | | }
|
451 | | }
|
452 | | |
453 | | void n64_rdp::SetSubBInputRGB(UINT8 **input_r, UINT8 **input_g, UINT8 **input_b, int code, rdp_span_aux *userdata)
|
454 | | {
|
455 | | switch (code & 0xf)
|
456 | | {
|
457 | | case 0: *input_r = &userdata->CombinedColor.i.r; *input_g = &userdata->CombinedColor.i.g; *input_b = &userdata->CombinedColor.i.b; break;
|
458 | | case 1: *input_r = &userdata->Texel0Color.i.r; *input_g = &userdata->Texel0Color.i.g; *input_b = &userdata->Texel0Color.i.b; break;
|
459 | | case 2: *input_r = &userdata->Texel1Color.i.r; *input_g = &userdata->Texel1Color.i.g; *input_b = &userdata->Texel1Color.i.b; break;
|
460 | | case 3: *input_r = &userdata->PrimColor.i.r; *input_g = &userdata->PrimColor.i.g; *input_b = &userdata->PrimColor.i.b; break;
|
461 | | case 4: *input_r = &userdata->ShadeColor.i.r; *input_g = &userdata->ShadeColor.i.g; *input_b = &userdata->ShadeColor.i.b; break;
|
462 | | case 5: *input_r = &userdata->EnvColor.i.r; *input_g = &userdata->EnvColor.i.g; *input_b = &userdata->EnvColor.i.b; break;
|
463 | | case 6: fatalerror("SET_SUBB_RGB_INPUT: key_center\n");
|
464 | | case 7: *input_r = (UINT8*)&m_k4; *input_g = (UINT8*)&m_k4; *input_b = (UINT8*)&m_k4; break;
|
465 | | case 8: case 9: case 10: case 11: case 12: case 13: case 14: case 15:
|
466 | | {
|
467 | | *input_r = &ZeroColor.i.r; *input_g = &ZeroColor.i.g; *input_b = &ZeroColor.i.b; break;
|
468 | | }
|
469 | | }
|
470 | | }
|
471 | | |
472 | | void n64_rdp::SetMulInputRGB(UINT8 **input_r, UINT8 **input_g, UINT8 **input_b, int code, rdp_span_aux *userdata)
|
473 | | {
|
474 | | switch (code & 0x1f)
|
475 | | {
|
476 | | case 0: *input_r = &userdata->CombinedColor.i.r; *input_g = &userdata->CombinedColor.i.g; *input_b = &userdata->CombinedColor.i.b; break;
|
477 | | case 1: *input_r = &userdata->Texel0Color.i.r; *input_g = &userdata->Texel0Color.i.g; *input_b = &userdata->Texel0Color.i.b; break;
|
478 | | case 2: *input_r = &userdata->Texel1Color.i.r; *input_g = &userdata->Texel1Color.i.g; *input_b = &userdata->Texel1Color.i.b; break;
|
479 | | case 3: *input_r = &userdata->PrimColor.i.r; *input_g = &userdata->PrimColor.i.g; *input_b = &userdata->PrimColor.i.b; break;
|
480 | | case 4: *input_r = &userdata->ShadeColor.i.r; *input_g = &userdata->ShadeColor.i.g; *input_b = &userdata->ShadeColor.i.b; break;
|
481 | | case 5: *input_r = &userdata->EnvColor.i.r; *input_g = &userdata->EnvColor.i.g; *input_b = &userdata->EnvColor.i.b; break;
|
482 | | case 6: *input_r = &userdata->KeyScale.i.r; *input_g = &userdata->KeyScale.i.g; *input_b = &userdata->KeyScale.i.b; break;
|
483 | | case 7: *input_r = &userdata->CombinedColor.i.a; *input_g = &userdata->CombinedColor.i.a; *input_b = &userdata->CombinedColor.i.a; break;
|
484 | | case 8: *input_r = &userdata->Texel0Color.i.a; *input_g = &userdata->Texel0Color.i.a; *input_b = &userdata->Texel0Color.i.a; break;
|
485 | | case 9: *input_r = &userdata->Texel1Color.i.a; *input_g = &userdata->Texel1Color.i.a; *input_b = &userdata->Texel1Color.i.a; break;
|
486 | | case 10: *input_r = &userdata->PrimColor.i.a; *input_g = &userdata->PrimColor.i.a; *input_b = &userdata->PrimColor.i.a; break;
|
487 | | case 11: *input_r = &userdata->ShadeColor.i.a; *input_g = &userdata->ShadeColor.i.a; *input_b = &userdata->ShadeColor.i.a; break;
|
488 | | case 12: *input_r = &userdata->EnvColor.i.a; *input_g = &userdata->EnvColor.i.a; *input_b = &userdata->EnvColor.i.a; break;
|
489 | | case 13: *input_r = &userdata->LODFraction; *input_g = &userdata->LODFraction; *input_b = &userdata->LODFraction; break;
|
490 | | case 14: *input_r = &userdata->PrimLODFraction; *input_g = &userdata->PrimLODFraction; *input_b = &userdata->PrimLODFraction; break;
|
491 | | case 15: *input_r = (UINT8*)&m_k5; *input_g = (UINT8*)&m_k5; *input_b = (UINT8*)&m_k5; break;
|
492 | | case 16: case 17: case 18: case 19: case 20: case 21: case 22: case 23:
|
493 | | case 24: case 25: case 26: case 27: case 28: case 29: case 30: case 31:
|
494 | | {
|
495 | | *input_r = &ZeroColor.i.r; *input_g = &ZeroColor.i.g; *input_b = &ZeroColor.i.b; break;
|
496 | | }
|
497 | | }
|
498 | | }
|
499 | | |
500 | | void n64_rdp::SetAddInputRGB(UINT8 **input_r, UINT8 **input_g, UINT8 **input_b, int code, rdp_span_aux *userdata)
|
501 | | {
|
502 | | switch (code & 0x7)
|
503 | | {
|
504 | | case 0: *input_r = &userdata->CombinedColor.i.r; *input_g = &userdata->CombinedColor.i.g; *input_b = &userdata->CombinedColor.i.b; break;
|
505 | | case 1: *input_r = &userdata->Texel0Color.i.r; *input_g = &userdata->Texel0Color.i.g; *input_b = &userdata->Texel0Color.i.b; break;
|
506 | | case 2: *input_r = &userdata->Texel1Color.i.r; *input_g = &userdata->Texel1Color.i.g; *input_b = &userdata->Texel1Color.i.b; break;
|
507 | | case 3: *input_r = &userdata->PrimColor.i.r; *input_g = &userdata->PrimColor.i.g; *input_b = &userdata->PrimColor.i.b; break;
|
508 | | case 4: *input_r = &userdata->ShadeColor.i.r; *input_g = &userdata->ShadeColor.i.g; *input_b = &userdata->ShadeColor.i.b; break;
|
509 | | case 5: *input_r = &userdata->EnvColor.i.r; *input_g = &userdata->EnvColor.i.g; *input_b = &userdata->EnvColor.i.b; break;
|
510 | | case 6: *input_r = &OneColor.i.r; *input_g = &OneColor.i.g; *input_b = &OneColor.i.b; break;
|
511 | | case 7: *input_r = &ZeroColor.i.r; *input_g = &ZeroColor.i.g; *input_b = &ZeroColor.i.b; break;
|
512 | | }
|
513 | | }
|
514 | | |
515 | | void n64_rdp::SetSubInputAlpha(UINT8 **input, int code, rdp_span_aux *userdata)
|
516 | | {
|
517 | | switch (code & 0x7)
|
518 | | {
|
519 | | case 0: *input = &userdata->CombinedColor.i.a; break;
|
520 | | case 1: *input = &userdata->Texel0Color.i.a; break;
|
521 | | case 2: *input = &userdata->Texel1Color.i.a; break;
|
522 | | case 3: *input = &userdata->PrimColor.i.a; break;
|
523 | | case 4: *input = &userdata->ShadeColor.i.a; break;
|
524 | | case 5: *input = &userdata->EnvColor.i.a; break;
|
525 | | case 6: *input = &OneColor.i.a; break;
|
526 | | case 7: *input = &ZeroColor.i.a; break;
|
527 | | }
|
528 | | }
|
529 | | |
530 | | void n64_rdp::SetMulInputAlpha(UINT8 **input, int code, rdp_span_aux *userdata)
|
531 | | {
|
532 | | switch (code & 0x7)
|
533 | | {
|
534 | | case 0: *input = &userdata->LODFraction; break;
|
535 | | case 1: *input = &userdata->Texel0Color.i.a; break;
|
536 | | case 2: *input = &userdata->Texel1Color.i.a; break;
|
537 | | case 3: *input = &userdata->PrimColor.i.a; break;
|
538 | | case 4: *input = &userdata->ShadeColor.i.a; break;
|
539 | | case 5: *input = &userdata->EnvColor.i.a; break;
|
540 | | case 6: *input = &userdata->PrimLODFraction; break;
|
541 | | case 7: *input = &ZeroColor.i.a; break;
|
542 | | }
|
543 | | }
|
544 | | |
545 | | void n64_rdp::SetBlenderInput(int cycle, int which, UINT8 **input_r, UINT8 **input_g, UINT8 **input_b, UINT8 **input_a, int a, int b, rdp_span_aux *userdata)
|
546 | | {
|
547 | | switch (a & 0x3)
|
548 | | {
|
549 | | case 0:
|
550 | | {
|
551 | | if (cycle == 0)
|
552 | | {
|
553 | | *input_r = &userdata->PixelColor.i.r;
|
554 | | *input_g = &userdata->PixelColor.i.g;
|
555 | | *input_b = &userdata->PixelColor.i.b;
|
556 | | }
|
557 | | else
|
558 | | {
|
559 | | *input_r = &userdata->BlendedPixelColor.i.r;
|
560 | | *input_g = &userdata->BlendedPixelColor.i.g;
|
561 | | *input_b = &userdata->BlendedPixelColor.i.b;
|
562 | | }
|
563 | | break;
|
564 | | }
|
565 | | |
566 | | case 1:
|
567 | | {
|
568 | | *input_r = &userdata->MemoryColor.i.r;
|
569 | | *input_g = &userdata->MemoryColor.i.g;
|
570 | | *input_b = &userdata->MemoryColor.i.b;
|
571 | | break;
|
572 | | }
|
573 | | |
574 | | case 2:
|
575 | | {
|
576 | | *input_r = &userdata->BlendColor.i.r;
|
577 | | *input_g = &userdata->BlendColor.i.g;
|
578 | | *input_b = &userdata->BlendColor.i.b;
|
579 | | break;
|
580 | | }
|
581 | | |
582 | | case 3:
|
583 | | {
|
584 | | *input_r = &userdata->FogColor.i.r;
|
585 | | *input_g = &userdata->FogColor.i.g;
|
586 | | *input_b = &userdata->FogColor.i.b;
|
587 | | break;
|
588 | | }
|
589 | | }
|
590 | | |
591 | | if (which == 0)
|
592 | | {
|
593 | | switch (b & 0x3)
|
594 | | {
|
595 | | case 0: *input_a = &userdata->PixelColor.i.a; break;
|
596 | | case 1: *input_a = &userdata->FogColor.i.a; break;
|
597 | | case 2: *input_a = &userdata->ShadeColor.i.a; break;
|
598 | | case 3: *input_a = &ZeroColor.i.a; break;
|
599 | | }
|
600 | | }
|
601 | | else
|
602 | | {
|
603 | | switch (b & 0x3)
|
604 | | {
|
605 | | case 0: *input_a = &userdata->InvPixelColor.i.a; break;
|
606 | | case 1: *input_a = &userdata->MemoryColor.i.a; break;
|
607 | | case 2: *input_a = &OneColor.i.a; break;
|
608 | | case 3: *input_a = &ZeroColor.i.a; break;
|
609 | | }
|
610 | | }
|
611 | | }
|
612 | | |
613 | | const UINT8 n64_rdp::s_bayer_matrix[16] =
|
614 | | { /* Bayer matrix */
|
615 | | 0, 4, 1, 5,
|
616 | | 6, 2, 7, 3,
|
617 | | 1, 5, 0, 4,
|
618 | | 7, 3, 6, 2
|
619 | | };
|
620 | | |
621 | | const UINT8 n64_rdp::s_magic_matrix[16] =
|
622 | | { /* Magic square matrix */
|
623 | | 0, 6, 1, 7,
|
624 | | 4, 2, 5, 3,
|
625 | | 3, 5, 2, 4,
|
626 | | 7, 1, 6, 0
|
627 | | };
|
628 | | |
629 | | const n64_rdp::ZDecompressEntry n64_rdp::z_dec_table[8] =
|
630 | | {
|
631 | | { 6, 0x00000 },
|
632 | | { 5, 0x20000 },
|
633 | | { 4, 0x30000 },
|
634 | | { 3, 0x38000 },
|
635 | | { 2, 0x3c000 },
|
636 | | { 1, 0x3e000 },
|
637 | | { 0, 0x3f000 },
|
638 | | { 0, 0x3f800 },
|
639 | | };
|
640 | | |
641 | | /*****************************************************************************/
|
642 | | |
643 | | void n64_rdp::z_build_com_table(void)
|
644 | | {
|
645 | | UINT16 altmem = 0;
|
646 | | for(int z = 0; z < 0x40000; z++)
|
647 | | {
|
648 | | switch((z >> 11) & 0x7f)
|
649 | | {
|
650 | | case 0x00:
|
651 | | case 0x01:
|
652 | | case 0x02:
|
653 | | case 0x03:
|
654 | | case 0x04:
|
655 | | case 0x05:
|
656 | | case 0x06:
|
657 | | case 0x07:
|
658 | | case 0x08:
|
659 | | case 0x09:
|
660 | | case 0x0a:
|
661 | | case 0x0b:
|
662 | | case 0x0c:
|
663 | | case 0x0d:
|
664 | | case 0x0e:
|
665 | | case 0x0f:
|
666 | | case 0x10:
|
667 | | case 0x11:
|
668 | | case 0x12:
|
669 | | case 0x13:
|
670 | | case 0x14:
|
671 | | case 0x15:
|
672 | | case 0x16:
|
673 | | case 0x17:
|
674 | | case 0x18:
|
675 | | case 0x19:
|
676 | | case 0x1a:
|
677 | | case 0x1b:
|
678 | | case 0x1c:
|
679 | | case 0x1d:
|
680 | | case 0x1e:
|
681 | | case 0x1f:
|
682 | | case 0x20:
|
683 | | case 0x21:
|
684 | | case 0x22:
|
685 | | case 0x23:
|
686 | | case 0x24:
|
687 | | case 0x25:
|
688 | | case 0x26:
|
689 | | case 0x27:
|
690 | | case 0x28:
|
691 | | case 0x29:
|
692 | | case 0x2a:
|
693 | | case 0x2b:
|
694 | | case 0x2c:
|
695 | | case 0x2d:
|
696 | | case 0x2e:
|
697 | | case 0x2f:
|
698 | | case 0x30:
|
699 | | case 0x31:
|
700 | | case 0x32:
|
701 | | case 0x33:
|
702 | | case 0x34:
|
703 | | case 0x35:
|
704 | | case 0x36:
|
705 | | case 0x37:
|
706 | | case 0x38:
|
707 | | case 0x39:
|
708 | | case 0x3a:
|
709 | | case 0x3b:
|
710 | | case 0x3c:
|
711 | | case 0x3d:
|
712 | | case 0x3e:
|
713 | | case 0x3f:
|
714 | | altmem = (z >> 4) & 0x1ffc;
|
715 | | break;
|
716 | | case 0x40:
|
717 | | case 0x41:
|
718 | | case 0x42:
|
719 | | case 0x43:
|
720 | | case 0x44:
|
721 | | case 0x45:
|
722 | | case 0x46:
|
723 | | case 0x47:
|
724 | | case 0x48:
|
725 | | case 0x49:
|
726 | | case 0x4a:
|
727 | | case 0x4b:
|
728 | | case 0x4c:
|
729 | | case 0x4d:
|
730 | | case 0x4e:
|
731 | | case 0x4f:
|
732 | | case 0x50:
|
733 | | case 0x51:
|
734 | | case 0x52:
|
735 | | case 0x53:
|
736 | | case 0x54:
|
737 | | case 0x55:
|
738 | | case 0x56:
|
739 | | case 0x57:
|
740 | | case 0x58:
|
741 | | case 0x59:
|
742 | | case 0x5a:
|
743 | | case 0x5b:
|
744 | | case 0x5c:
|
745 | | case 0x5d:
|
746 | | case 0x5e:
|
747 | | case 0x5f:
|
748 | | altmem = ((z >> 3) & 0x1ffc) | 0x2000;
|
749 | | break;
|
750 | | case 0x60:
|
751 | | case 0x61:
|
752 | | case 0x62:
|
753 | | case 0x63:
|
754 | | case 0x64:
|
755 | | case 0x65:
|
756 | | case 0x66:
|
757 | | case 0x67:
|
758 | | case 0x68:
|
759 | | case 0x69:
|
760 | | case 0x6a:
|
761 | | case 0x6b:
|
762 | | case 0x6c:
|
763 | | case 0x6d:
|
764 | | case 0x6e:
|
765 | | case 0x6f:
|
766 | | altmem = ((z >> 2) & 0x1ffc) | 0x4000;
|
767 | | break;
|
768 | | case 0x70:
|
769 | | case 0x71:
|
770 | | case 0x72:
|
771 | | case 0x73:
|
772 | | case 0x74:
|
773 | | case 0x75:
|
774 | | case 0x76:
|
775 | | case 0x77:
|
776 | | altmem = ((z >> 1) & 0x1ffc) | 0x6000;
|
777 | | break;
|
778 | | case 0x78://uncompressed z = 0x3c000
|
779 | | case 0x79:
|
780 | | case 0x7a:
|
781 | | case 0x7b:
|
782 | | altmem = (z & 0x1ffc) | 0x8000;
|
783 | | break;
|
784 | | case 0x7c://uncompressed z = 0x3e000
|
785 | | case 0x7d:
|
786 | | altmem = ((z << 1) & 0x1ffc) | 0xa000;
|
787 | | break;
|
788 | | case 0x7e://uncompressed z = 0x3f000
|
789 | | altmem = ((z << 2) & 0x1ffc) | 0xc000;
|
790 | | break;
|
791 | | case 0x7f://uncompressed z = 0x3f000
|
792 | | altmem = ((z << 2) & 0x1ffc) | 0xe000;
|
793 | | break;
|
794 | | }
|
795 | | |
796 | | z_com_table[z] = altmem;
|
797 | | |
798 | | }
|
799 | | }
|
800 | | |
801 | | void n64_rdp::precalc_cvmask_derivatives(void)
|
802 | | {
|
803 | | const UINT8 yarray[16] = {0, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0};
|
804 | | const UINT8 xarray[16] = {0, 3, 2, 2, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0};
|
805 | | |
806 | | for (int i = 0; i < 0x10000; i++)
|
807 | | {
|
808 | | compressed_cvmasks[i] = (i & 1) | ((i & 4) >> 1) | ((i & 0x20) >> 3) | ((i & 0x80) >> 4) |
|
809 | | ((i & 0x100) >> 4) | ((i & 0x400) >> 5) | ((i & 0x2000) >> 7) | ((i & 0x8000) >> 8);
|
810 | | }
|
811 | | |
812 | | for (int i = 0; i < 0x100; i++)
|
813 | | {
|
814 | | UINT16 mask = decompress_cvmask_frombyte(i);
|
815 | | cvarray[i].cvg = cvarray[i].cvbit = 0;
|
816 | | cvarray[i].cvbit = (i >> 7) & 1;
|
817 | | for (int k = 0; k < 8; k++)
|
818 | | {
|
819 | | cvarray[i].cvg += ((i >> k) & 1);
|
820 | | }
|
821 | | |
822 | | UINT16 masky = 0;
|
823 | | for (int k = 0; k < 4; k++)
|
824 | | {
|
825 | | masky |= ((mask & (0xf000 >> (k << 2))) > 0) << k;
|
826 | | }
|
827 | | UINT8 offy = yarray[masky];
|
828 | | |
829 | | UINT16 maskx = (mask & (0xf000 >> (offy << 2))) >> ((offy ^ 3) << 2);
|
830 | | UINT8 offx = xarray[maskx];
|
831 | | |
832 | | cvarray[i].xoff = offx;
|
833 | | cvarray[i].yoff = offy;
|
834 | | }
|
835 | | }
|
836 | | |
837 | | UINT16 n64_rdp::decompress_cvmask_frombyte(UINT8 x)
|
838 | | {
|
839 | | UINT16 y = (x & 1) | ((x & 2) << 1) | ((x & 4) << 3) | ((x & 8) << 4) |
|
840 | | ((x & 0x10) << 4) | ((x & 0x20) << 5) | ((x & 0x40) << 7) | ((x & 0x80) << 8);
|
841 | | return y;
|
842 | | }
|
843 | | |
844 | | void n64_rdp::lookup_cvmask_derivatives(UINT32 mask, UINT8* offx, UINT8* offy, rdp_span_aux *userdata)
|
845 | | {
|
846 | | UINT32 index = compressed_cvmasks[mask];
|
847 | | userdata->CurrentPixCvg = cvarray[index].cvg;
|
848 | | userdata->CurrentCvgBit = cvarray[index].cvbit;
|
849 | | *offx = cvarray[index].xoff;
|
850 | | *offy = cvarray[index].yoff;
|
851 | | }
|
852 | | |
853 | | void n64_rdp::ZStore(const rdp_poly_state &object, UINT32 zcurpixel, UINT32 dzcurpixel, UINT32 z, UINT32 enc)
|
854 | | {
|
855 | | UINT16 zval = z_com_table[z & 0x3ffff]|(enc >> 2);
|
856 | | if(zcurpixel <= MEM16_LIMIT)
|
857 | | {
|
858 | | ((UINT16*)rdram)[zcurpixel ^ WORD_ADDR_XOR] = zval;
|
859 | | }
|
860 | | if(dzcurpixel <= MEM8_LIMIT)
|
861 | | {
|
862 | | HiddenBits[dzcurpixel ^ BYTE_ADDR_XOR] = enc & 3;
|
863 | | }
|
864 | | }
|
865 | | |
866 | | INT32 n64_rdp::NormalizeDZPix(INT32 sum)
|
867 | | {
|
868 | | if (sum & 0xc000)
|
869 | | {
|
870 | | return 0x8000;
|
871 | | }
|
872 | | if (!(sum & 0xffff))
|
873 | | {
|
874 | | return 1;
|
875 | | }
|
876 | | for(int count = 0x2000; count > 0; count >>= 1)
|
877 | | {
|
878 | | if (sum & count)
|
879 | | {
|
880 | | return(count << 1);
|
881 | | }
|
882 | | }
|
883 | | return 0;
|
884 | | }
|
885 | | |
886 | | UINT32 n64_rdp::ZDecompress(UINT32 zcurpixel)
|
887 | | {
|
888 | | UINT32 zb = RREADIDX16(zcurpixel);
|
889 | | CHECK16(zcurpixel);
|
890 | | return z_complete_dec_table[(zb >> 2) & 0x3fff];
|
891 | | }
|
892 | | |
893 | | UINT32 n64_rdp::DZDecompress(UINT32 zcurpixel, UINT32 dzcurpixel)
|
894 | | {
|
895 | | UINT16 zval = RREADIDX16(zcurpixel);
|
896 | | CHECK16(zcurpixel);
|
897 | | UINT8 dzval = (((dzcurpixel) <= 0x7fffff) ? (HiddenBits[(dzcurpixel) ^ BYTE_ADDR_XOR]) : 0);
|
898 | | UINT32 dz_compressed = ((zval & 3) << 2) | (dzval & 3);
|
899 | | return (1 << dz_compressed);
|
900 | | }
|
901 | | |
902 | | UINT32 n64_rdp::DZCompress(UINT32 value)
|
903 | | {
|
904 | | INT32 j = 0;
|
905 | | for (; value > 1; j++, value >>= 1);
|
906 | | return j;
|
907 | | }
|
908 | | |
909 | | void n64_rdp::GetDitherValues(int x, int y, int* cdith, int* adith, const rdp_poly_state& object)
|
910 | | {
|
911 | | int dithindex = ((y & 3) << 2) | (x & 3);
|
912 | | switch((object.OtherModes.rgb_dither_sel << 2) | object.OtherModes.alpha_dither_sel)
|
913 | | {
|
914 | | case 0:
|
915 | | *adith = *cdith = s_magic_matrix[dithindex];
|
916 | | break;
|
917 | | case 1:
|
918 | | *cdith = s_magic_matrix[dithindex];
|
919 | | *adith = (~(*cdith)) & 7;
|
920 | | break;
|
921 | | case 2:
|
922 | | *cdith = s_magic_matrix[dithindex];
|
923 | | *adith = machine().rand() & 7;
|
924 | | break;
|
925 | | case 3:
|
926 | | *cdith = s_magic_matrix[dithindex];
|
927 | | *adith = 0;
|
928 | | break;
|
929 | | case 4:
|
930 | | *adith = *cdith = s_bayer_matrix[dithindex];
|
931 | | break;
|
932 | | case 5:
|
933 | | *cdith = s_bayer_matrix[dithindex];
|
934 | | *adith = (~(*cdith)) & 7;
|
935 | | break;
|
936 | | case 6:
|
937 | | *cdith = s_bayer_matrix[dithindex];
|
938 | | *adith = machine().rand() & 7;
|
939 | | break;
|
940 | | case 7:
|
941 | | *cdith = s_bayer_matrix[dithindex];
|
942 | | *adith = 0;
|
943 | | break;
|
944 | | case 8:
|
945 | | *cdith = machine().rand() & 7;
|
946 | | *adith = s_magic_matrix[dithindex];
|
947 | | break;
|
948 | | case 9:
|
949 | | *cdith = machine().rand() & 7;
|
950 | | *adith = (~s_magic_matrix[dithindex]) & 7;
|
951 | | break;
|
952 | | case 10:
|
953 | | *cdith = machine().rand() & 7;
|
954 | | *adith = (*cdith + 17) & 7;
|
955 | | break;
|
956 | | case 11:
|
957 | | *cdith = machine().rand() & 7;
|
958 | | *adith = 0;
|
959 | | break;
|
960 | | case 12:
|
961 | | *cdith = 0;
|
962 | | *adith = s_bayer_matrix[dithindex];
|
963 | | break;
|
964 | | case 13:
|
965 | | *cdith = 0;
|
966 | | *adith = (~s_bayer_matrix[dithindex]) & 7;
|
967 | | break;
|
968 | | case 14:
|
969 | | *cdith = 0;
|
970 | | *adith = m_machine->rand() & 7;
|
971 | | break;
|
972 | | case 15:
|
973 | | *adith = *cdith = 0;
|
974 | | break;
|
975 | | }
|
976 | | }
|
977 | | |
978 | | INT32 CLAMP(INT32 in, INT32 min, INT32 max)
|
979 | | {
|
980 | | if(in < min) return min;
|
981 | | if(in > max) return max;
|
982 | | return in;
|
983 | | }
|
984 | | |
985 | | bool n64_rdp::ZCompare(UINT32 zcurpixel, UINT32 dzcurpixel, UINT32 sz, UINT16 dzpix, rdp_span_aux *userdata, const rdp_poly_state &object)
|
986 | | {
|
987 | | bool force_coplanar = false;
|
988 | | sz &= 0x3ffff;
|
989 | | |
990 | | UINT32 oz;
|
991 | | UINT32 dzmem;
|
992 | | UINT32 zval;
|
993 | | INT32 rawdzmem;
|
994 | | |
995 | | if (object.OtherModes.z_compare_en)
|
996 | | {
|
997 | | oz = ZDecompress(zcurpixel);
|
998 | | dzmem = DZDecompress(zcurpixel, dzcurpixel);
|
999 | | zval = RREADIDX16(zcurpixel);
|
1000 | | CHECK16(zcurpixel);
|
1001 | | rawdzmem = ((zval & 3) << 2) | ((((dzcurpixel) <= 0x3fffff) ? (HiddenBits[(dzcurpixel) ^ BYTE_ADDR_XOR]) : 0) & 3);
|
1002 | | }
|
1003 | | else
|
1004 | | {
|
1005 | | oz = 0;
|
1006 | | dzmem = 1 << 0xf;
|
1007 | | zval = 0x3;
|
1008 | | rawdzmem = 0xf;
|
1009 | | }
|
1010 | | |
1011 | | userdata->m_dzpix_enc = DZCompress(dzpix & 0xffff);
|
1012 | | userdata->ShiftA = CLAMP(userdata->m_dzpix_enc - rawdzmem, 0, 4);
|
1013 | | userdata->ShiftB = CLAMP(rawdzmem - userdata->m_dzpix_enc, 0, 4);
|
1014 | | |
1015 | | int precision_factor = (zval >> 13) & 0xf;
|
1016 | | if (precision_factor < 3)
|
1017 | | {
|
1018 | | int dzmemmodifier = 16 >> precision_factor;
|
1019 | | if (dzmem == 0x8000)
|
1020 | | {
|
1021 | | force_coplanar = true;
|
1022 | | }
|
1023 | | dzmem <<= 1;
|
1024 | | if (dzmem <= dzmemmodifier)
|
1025 | | {
|
1026 | | dzmem = dzmemmodifier;
|
1027 | | }
|
1028 | | if (!dzmem)
|
1029 | | {
|
1030 | | dzmem = 0xffff;
|
1031 | | }
|
1032 | | }
|
1033 | | if (dzmem > 0x8000)
|
1034 | | {
|
1035 | | dzmem = 0xffff;
|
1036 | | }
|
1037 | | |
1038 | | UINT32 dznew = (dzmem > dzpix) ? dzmem : (UINT32)dzpix;
|
1039 | | UINT32 dznotshift = dznew;
|
1040 | | dznew <<= 3;
|
1041 | | |
1042 | | bool farther = (sz + dznew) >= oz;
|
1043 | | bool infront = sz < oz;
|
1044 | | |
1045 | | if (force_coplanar)
|
1046 | | {
|
1047 | | farther = true;
|
1048 | | }
|
1049 | | |
1050 | | bool overflow = ((userdata->CurrentMemCvg + userdata->CurrentPixCvg) & 8) > 0;
|
1051 | | userdata->BlendEnable = (object.OtherModes.force_blend || (!overflow && object.OtherModes.antialias_en && farther)) ? 1 : 0;
|
1052 | | userdata->PreWrap = overflow;
|
1053 | | |
1054 | | int cvgcoeff = 0;
|
1055 | | UINT32 dzenc = 0;
|
1056 | | |
1057 | | if (object.OtherModes.z_mode == 1 && infront && farther && overflow)
|
1058 | | {
|
1059 | | dzenc = DZCompress(dznotshift & 0xffff);
|
1060 | | cvgcoeff = ((oz >> dzenc) - (sz >> dzenc)) & 0xf;
|
1061 | | userdata->CurrentPixCvg = ((cvgcoeff * userdata->CurrentPixCvg) >> 3) & 0xf;
|
1062 | | }
|
1063 | | |
1064 | | if (!object.OtherModes.z_compare_en)
|
1065 | | {
|
1066 | | return true;
|
1067 | | }
|
1068 | | |
1069 | | INT32 diff = (INT32)sz - (INT32)dznew;
|
1070 | | bool nearer = diff <= (INT32)oz;
|
1071 | | bool max = (oz == 0x3ffff);
|
1072 | | if (force_coplanar)
|
1073 | | {
|
1074 | | nearer = true;
|
1075 | | }
|
1076 | | |
1077 | | switch(object.OtherModes.z_mode)
|
1078 | | {
|
1079 | | case 0:
|
1080 | | return (max || (overflow ? infront : nearer));
|
1081 | | case 1:
|
1082 | | return (max || (overflow ? infront : nearer));
|
1083 | | case 2:
|
1084 | | return (infront || max);
|
1085 | | case 3:
|
1086 | | return (farther && nearer && !max);
|
1087 | | }
|
1088 | | |
1089 | | return false;
|
1090 | | }
|
1091 | | |
1092 | | UINT32 n64_rdp::GetLog2(UINT32 lod_clamp)
|
1093 | | {
|
1094 | | if (lod_clamp < 2)
|
1095 | | {
|
1096 | | return 0;
|
1097 | | }
|
1098 | | else
|
1099 | | {
|
1100 | | for (int i = 7; i > 0; i--)
|
1101 | | {
|
1102 | | if ((lod_clamp >> i) & 1)
|
1103 | | {
|
1104 | | return i;
|
1105 | | }
|
1106 | | }
|
1107 | | }
|
1108 | | |
1109 | | return 0;
|
1110 | | }
|
1111 | | |
1112 | | /*****************************************************************************/
|
1113 | | |
1114 | | UINT32 n64_rdp::ReadData(UINT32 address)
|
1115 | | {
|
1116 | | if (m_status & 0x1) // XBUS_DMEM_DMA enabled
|
1117 | | {
|
1118 | | return rsp_dmem[(address & 0xfff) / 4];
|
1119 | | }
|
1120 | | else
|
1121 | | {
|
1122 | | return rdram[((address & 0xffffff) / 4)];
|
1123 | | }
|
1124 | | }
|
1125 | | |
1126 | | static const char *const image_format[] = { "RGBA", "YUV", "CI", "IA", "I", "???", "???", "???" };
|
1127 | | static const char *const image_size[] = { "4-bit", "8-bit", "16-bit", "32-bit" };
|
1128 | | |
1129 | | static const int rdp_command_length[64] =
|
1130 | | {
|
1131 | | 8, // 0x00, No Op
|
1132 | | 8, // 0x01, ???
|
1133 | | 8, // 0x02, ???
|
1134 | | 8, // 0x03, ???
|
1135 | | 8, // 0x04, ???
|
1136 | | 8, // 0x05, ???
|
1137 | | 8, // 0x06, ???
|
1138 | | 8, // 0x07, ???
|
1139 | | 32, // 0x08, Non-Shaded Triangle
|
1140 | | 32+16, // 0x09, Non-Shaded, Z-Buffered Triangle
|
1141 | | 32+64, // 0x0a, Textured Triangle
|
1142 | | 32+64+16, // 0x0b, Textured, Z-Buffered Triangle
|
1143 | | 32+64, // 0x0c, Shaded Triangle
|
1144 | | 32+64+16, // 0x0d, Shaded, Z-Buffered Triangle
|
1145 | | 32+64+64, // 0x0e, Shaded+Textured Triangle
|
1146 | | 32+64+64+16,// 0x0f, Shaded+Textured, Z-Buffered Triangle
|
1147 | | 8, // 0x10, ???
|
1148 | | 8, // 0x11, ???
|
1149 | | 8, // 0x12, ???
|
1150 | | 8, // 0x13, ???
|
1151 | | 8, // 0x14, ???
|
1152 | | 8, // 0x15, ???
|
1153 | | 8, // 0x16, ???
|
1154 | | 8, // 0x17, ???
|
1155 | | 8, // 0x18, ???
|
1156 | | 8, // 0x19, ???
|
1157 | | 8, // 0x1a, ???
|
1158 | | 8, // 0x1b, ???
|
1159 | | 8, // 0x1c, ???
|
1160 | | 8, // 0x1d, ???
|
1161 | | 8, // 0x1e, ???
|
1162 | | 8, // 0x1f, ???
|
1163 | | 8, // 0x20, ???
|
1164 | | 8, // 0x21, ???
|
1165 | | 8, // 0x22, ???
|
1166 | | 8, // 0x23, ???
|
1167 | | 16, // 0x24, Texture_Rectangle
|
1168 | | 16, // 0x25, Texture_Rectangle_Flip
|
1169 | | 8, // 0x26, Sync_Load
|
1170 | | 8, // 0x27, Sync_Pipe
|
1171 | | 8, // 0x28, Sync_Tile
|
1172 | | 8, // 0x29, Sync_Full
|
1173 | | 8, // 0x2a, Set_Key_GB
|
1174 | | 8, // 0x2b, Set_Key_R
|
1175 | | 8, // 0x2c, Set_Convert
|
1176 | | 8, // 0x2d, Set_Scissor
|
1177 | | 8, // 0x2e, Set_Prim_Depth
|
1178 | | 8, // 0x2f, Set_Other_Modes
|
1179 | | 8, // 0x30, Load_TLUT
|
1180 | | 8, // 0x31, ???
|
1181 | | 8, // 0x32, Set_Tile_Size
|
1182 | | 8, // 0x33, Load_Block
|
1183 | | 8, // 0x34, Load_Tile
|
1184 | | 8, // 0x35, Set_Tile
|
1185 | | 8, // 0x36, Fill_Rectangle
|
1186 | | 8, // 0x37, Set_Fill_Color
|
1187 | | 8, // 0x38, Set_Fog_Color
|
1188 | | 8, // 0x39, Set_Blend_Color
|
1189 | | 8, // 0x3a, Set_Prim_Color
|
1190 | | 8, // 0x3b, Set_Env_Color
|
1191 | | 8, // 0x3c, Set_Combine
|
1192 | | 8, // 0x3d, Set_Texture_Image
|
1193 | | 8, // 0x3e, Set_Mask_Image
|
1194 | | 8 // 0x3f, Set_Color_Image
|
1195 | | };
|
1196 | | |
1197 | | void n64_rdp::Dasm(char *buffer)
|
1198 | | {
|
1199 | | int i;
|
1200 | | int tile;
|
1201 | | const char *format, *size;
|
1202 | | char sl[32], tl[32], sh[32], th[32];
|
1203 | | char s[32], t[32], w[32];
|
1204 | | char dsdx[32], dtdx[32], dwdx[32];
|
1205 | | char dsdy[32], dtdy[32], dwdy[32];
|
1206 | | char dsde[32], dtde[32], dwde[32];
|
1207 | | char yl[32], yh[32], ym[32], xl[32], xh[32], xm[32];
|
1208 | | char dxldy[32], dxhdy[32], dxmdy[32];
|
1209 | | char rt[32], gt[32], bt[32], at[32];
|
1210 | | char drdx[32], dgdx[32], dbdx[32], dadx[32];
|
1211 | | char drdy[32], dgdy[32], dbdy[32], dady[32];
|
1212 | | char drde[32], dgde[32], dbde[32], dade[32];
|
1213 | | UINT32 r,g,b,a;
|
1214 | | |
1215 | | UINT32 cmd[64];
|
1216 | | UINT32 length;
|
1217 | | UINT32 command;
|
1218 | | |
1219 | | length = m_cmd_ptr * 4;
|
1220 | | if (length < 8)
|
1221 | | {
|
1222 | | sprintf(buffer, "ERROR: length = %d\n", length);
|
1223 | | return;
|
1224 | | }
|
1225 | | |
1226 | | cmd[0] = m_cmd_data[m_cmd_cur+0];
|
1227 | | cmd[1] = m_cmd_data[m_cmd_cur+1];
|
1228 | | |
1229 | | tile = (cmd[1] >> 24) & 0x7;
|
1230 | | sprintf(sl, "%4.2f", (float)((cmd[0] >> 12) & 0xfff) / 4.0f);
|
1231 | | sprintf(tl, "%4.2f", (float)((cmd[0] >> 0) & 0xfff) / 4.0f);
|
1232 | | sprintf(sh, "%4.2f", (float)((cmd[1] >> 12) & 0xfff) / 4.0f);
|
1233 | | sprintf(th, "%4.2f", (float)((cmd[1] >> 0) & 0xfff) / 4.0f);
|
1234 | | |
1235 | | format = image_format[(cmd[0] >> 21) & 0x7];
|
1236 | | size = image_size[(cmd[0] >> 19) & 0x3];
|
1237 | | |
1238 | | r = (cmd[1] >> 24) & 0xff;
|
1239 | | g = (cmd[1] >> 16) & 0xff;
|
1240 | | b = (cmd[1] >> 8) & 0xff;
|
1241 | | a = (cmd[1] >> 0) & 0xff;
|
1242 | | |
1243 | | command = (cmd[0] >> 24) & 0x3f;
|
1244 | | switch (command)
|
1245 | | {
|
1246 | | case 0x00: sprintf(buffer, "No Op"); break;
|
1247 | | case 0x08: // Tri_NoShade
|
1248 | | {
|
1249 | | int lft = (command >> 23) & 0x1;
|
1250 | | |
1251 | | if (length != rdp_command_length[command])
|
1252 | | {
|
1253 | | sprintf(buffer, "ERROR: Tri_NoShade length = %d\n", length);
|
1254 | | return;
|
1255 | | }
|
1256 | | |
1257 | | cmd[2] = m_cmd_data[m_cmd_cur+2];
|
1258 | | cmd[3] = m_cmd_data[m_cmd_cur+3];
|
1259 | | cmd[4] = m_cmd_data[m_cmd_cur+4];
|
1260 | | cmd[5] = m_cmd_data[m_cmd_cur+5];
|
1261 | | cmd[6] = m_cmd_data[m_cmd_cur+6];
|
1262 | | cmd[7] = m_cmd_data[m_cmd_cur+7];
|
1263 | | |
1264 | | sprintf(yl, "%4.4f", (float)((cmd[0] >> 0) & 0x1fff) / 4.0f);
|
1265 | | sprintf(ym, "%4.4f", (float)((cmd[1] >> 16) & 0x1fff) / 4.0f);
|
1266 | | sprintf(yh, "%4.4f", (float)((cmd[1] >> 0) & 0x1fff) / 4.0f);
|
1267 | | sprintf(xl, "%4.4f", (float)(cmd[2] / 65536.0f));
|
1268 | | sprintf(dxldy, "%4.4f", (float)(cmd[3] / 65536.0f));
|
1269 | | sprintf(xh, "%4.4f", (float)(cmd[4] / 65536.0f));
|
1270 | | sprintf(dxhdy, "%4.4f", (float)(cmd[5] / 65536.0f));
|
1271 | | sprintf(xm, "%4.4f", (float)(cmd[6] / 65536.0f));
|
1272 | | sprintf(dxmdy, "%4.4f", (float)(cmd[7] / 65536.0f));
|
1273 | | |
1274 | | sprintf(buffer, "Tri_NoShade %d, XL: %s, XM: %s, XH: %s, YL: %s, YM: %s, YH: %s\n", lft, xl,xm,xh,yl,ym,yh);
|
1275 | | break;
|
1276 | | }
|
1277 | | case 0x09: // Tri_NoShadeZ
|
1278 | | {
|
1279 | | int lft = (command >> 23) & 0x1;
|
1280 | | |
1281 | | if (length != rdp_command_length[command])
|
1282 | | {
|
1283 | | sprintf(buffer, "ERROR: Tri_NoShadeZ length = %d\n", length);
|
1284 | | return;
|
1285 | | }
|
1286 | | |
1287 | | cmd[2] = m_cmd_data[m_cmd_cur+2];
|
1288 | | cmd[3] = m_cmd_data[m_cmd_cur+3];
|
1289 | | cmd[4] = m_cmd_data[m_cmd_cur+4];
|
1290 | | cmd[5] = m_cmd_data[m_cmd_cur+5];
|
1291 | | cmd[6] = m_cmd_data[m_cmd_cur+6];
|
1292 | | cmd[7] = m_cmd_data[m_cmd_cur+7];
|
1293 | | |
1294 | | sprintf(yl, "%4.4f", (float)((cmd[0] >> 0) & 0x1fff) / 4.0f);
|
1295 | | sprintf(ym, "%4.4f", (float)((cmd[1] >> 16) & 0x1fff) / 4.0f);
|
1296 | | sprintf(yh, "%4.4f", (float)((cmd[1] >> 0) & 0x1fff) / 4.0f);
|
1297 | | sprintf(xl, "%4.4f", (float)(cmd[2] / 65536.0f));
|
1298 | | sprintf(dxldy, "%4.4f", (float)(cmd[3] / 65536.0f));
|
1299 | | sprintf(xh, "%4.4f", (float)(cmd[4] / 65536.0f));
|
1300 | | sprintf(dxhdy, "%4.4f", (float)(cmd[5] / 65536.0f));
|
1301 | | sprintf(xm, "%4.4f", (float)(cmd[6] / 65536.0f));
|
1302 | | sprintf(dxmdy, "%4.4f", (float)(cmd[7] / 65536.0f));
|
1303 | | |
1304 | | sprintf(buffer, "Tri_NoShadeZ %d, XL: %s, XM: %s, XH: %s, YL: %s, YM: %s, YH: %s\n", lft, xl,xm,xh,yl,ym,yh);
|
1305 | | break;
|
1306 | | }
|
1307 | | case 0x0a: // Tri_Tex
|
1308 | | {
|
1309 | | int lft = (command >> 23) & 0x1;
|
1310 | | |
1311 | | if (length < rdp_command_length[command])
|
1312 | | {
|
1313 | | sprintf(buffer, "ERROR: Tri_Tex length = %d\n", length);
|
1314 | | return;
|
1315 | | }
|
1316 | | |
1317 | | for (i=2; i < 24; i++)
|
1318 | | {
|
1319 | | cmd[i] = m_cmd_data[m_cmd_cur+i];
|
1320 | | }
|
1321 | | |
1322 | | sprintf(yl, "%4.4f", (float)((cmd[0] >> 0) & 0x1fff) / 4.0f);
|
1323 | | sprintf(ym, "%4.4f", (float)((cmd[1] >> 16) & 0x1fff) / 4.0f);
|
1324 | | sprintf(yh, "%4.4f", (float)((cmd[1] >> 0) & 0x1fff) / 4.0f);
|
1325 | | sprintf(xl, "%4.4f", (float)((INT32)cmd[2] / 65536.0f));
|
1326 | | sprintf(dxldy, "%4.4f", (float)((INT32)cmd[3] / 65536.0f));
|
1327 | | sprintf(xh, "%4.4f", (float)((INT32)cmd[4] / 65536.0f));
|
1328 | | sprintf(dxhdy, "%4.4f", (float)((INT32)cmd[5] / 65536.0f));
|
1329 | | sprintf(xm, "%4.4f", (float)((INT32)cmd[6] / 65536.0f));
|
1330 | | sprintf(dxmdy, "%4.4f", (float)((INT32)cmd[7] / 65536.0f));
|
1331 | | |
1332 | | sprintf(s, "%4.4f", (float)(INT32)((cmd[ 8] & 0xffff0000) | ((cmd[12] >> 16) & 0xffff)) / 65536.0f);
|
1333 | | sprintf(t, "%4.4f", (float)(INT32)(((cmd[ 8] & 0xffff) << 16) | (cmd[12] & 0xffff)) / 65536.0f);
|
1334 | | sprintf(w, "%4.4f", (float)(INT32)((cmd[ 9] & 0xffff0000) | ((cmd[13] >> 16) & 0xffff)) / 65536.0f);
|
1335 | | sprintf(dsdx, "%4.4f", (float)(INT32)((cmd[10] & 0xffff0000) | ((cmd[14] >> 16) & 0xffff)) / 65536.0f);
|
1336 | | sprintf(dtdx, "%4.4f", (float)(INT32)(((cmd[10] & 0xffff) << 16) | (cmd[14] & 0xffff)) / 65536.0f);
|
1337 | | sprintf(dwdx, "%4.4f", (float)(INT32)((cmd[11] & 0xffff0000) | ((cmd[15] >> 16) & 0xffff)) / 65536.0f);
|
1338 | | sprintf(dsde, "%4.4f", (float)(INT32)((cmd[16] & 0xffff0000) | ((cmd[20] >> 16) & 0xffff)) / 65536.0f);
|
1339 | | sprintf(dtde, "%4.4f", (float)(INT32)(((cmd[16] & 0xffff) << 16) | (cmd[20] & 0xffff)) / 65536.0f);
|
1340 | | sprintf(dwde, "%4.4f", (float)(INT32)((cmd[17] & 0xffff0000) | ((cmd[21] >> 16) & 0xffff)) / 65536.0f);
|
1341 | | sprintf(dsdy, "%4.4f", (float)(INT32)((cmd[18] & 0xffff0000) | ((cmd[22] >> 16) & 0xffff)) / 65536.0f);
|
1342 | | sprintf(dtdy, "%4.4f", (float)(INT32)(((cmd[18] & 0xffff) << 16) | (cmd[22] & 0xffff)) / 65536.0f);
|
1343 | | sprintf(dwdy, "%4.4f", (float)(INT32)((cmd[19] & 0xffff0000) | ((cmd[23] >> 16) & 0xffff)) / 65536.0f);
|
1344 | | |
1345 | | |
1346 | | buffer+=sprintf(buffer, "Tri_Tex %d, XL: %s, XM: %s, XH: %s, YL: %s, YM: %s, YH: %s\n", lft, xl,xm,xh,yl,ym,yh);
|
1347 | | buffer+=sprintf(buffer, " ");
|
1348 | | buffer+=sprintf(buffer, " S: %s, T: %s, W: %s\n", s, t, w);
|
1349 | | buffer+=sprintf(buffer, " ");
|
1350 | | buffer+=sprintf(buffer, " DSDX: %s, DTDX: %s, DWDX: %s\n", dsdx, dtdx, dwdx);
|
1351 | | buffer+=sprintf(buffer, " ");
|
1352 | | buffer+=sprintf(buffer, " DSDE: %s, DTDE: %s, DWDE: %s\n", dsde, dtde, dwde);
|
1353 | | buffer+=sprintf(buffer, " ");
|
1354 | | buffer+=sprintf(buffer, " DSDY: %s, DTDY: %s, DWDY: %s\n", dsdy, dtdy, dwdy);
|
1355 | | break;
|
1356 | | }
|
1357 | | case 0x0b: // Tri_TexZ
|
1358 | | {
|
1359 | | int lft = (command >> 23) & 0x1;
|
1360 | | |
1361 | | if (length < rdp_command_length[command])
|
1362 | | {
|
1363 | | sprintf(buffer, "ERROR: Tri_TexZ length = %d\n", length);
|
1364 | | return;
|
1365 | | }
|
1366 | | |
1367 | | for (i=2; i < 24; i++)
|
1368 | | {
|
1369 | | cmd[i] = m_cmd_data[m_cmd_cur+i];
|
1370 | | }
|
1371 | | |
1372 | | sprintf(yl, "%4.4f", (float)((cmd[0] >> 0) & 0x1fff) / 4.0f);
|
1373 | | sprintf(ym, "%4.4f", (float)((cmd[1] >> 16) & 0x1fff) / 4.0f);
|
1374 | | sprintf(yh, "%4.4f", (float)((cmd[1] >> 0) & 0x1fff) / 4.0f);
|
1375 | | sprintf(xl, "%4.4f", (float)((INT32)cmd[2] / 65536.0f));
|
1376 | | sprintf(dxldy, "%4.4f", (float)((INT32)cmd[3] / 65536.0f));
|
1377 | | sprintf(xh, "%4.4f", (float)((INT32)cmd[4] / 65536.0f));
|
1378 | | sprintf(dxhdy, "%4.4f", (float)((INT32)cmd[5] / 65536.0f));
|
1379 | | sprintf(xm, "%4.4f", (float)((INT32)cmd[6] / 65536.0f));
|
1380 | | sprintf(dxmdy, "%4.4f", (float)((INT32)cmd[7] / 65536.0f));
|
1381 | | |
1382 | | sprintf(s, "%4.4f", (float)(INT32)((cmd[ 8] & 0xffff0000) | ((cmd[12] >> 16) & 0xffff)) / 65536.0f);
|
1383 | | sprintf(t, "%4.4f", (float)(INT32)(((cmd[ 8] & 0xffff) << 16) | (cmd[12] & 0xffff)) / 65536.0f);
|
1384 | | sprintf(w, "%4.4f", (float)(INT32)((cmd[ 9] & 0xffff0000) | ((cmd[13] >> 16) & 0xffff)) / 65536.0f);
|
1385 | | sprintf(dsdx, "%4.4f", (float)(INT32)((cmd[10] & 0xffff0000) | ((cmd[14] >> 16) & 0xffff)) / 65536.0f);
|
1386 | | sprintf(dtdx, "%4.4f", (float)(INT32)(((cmd[10] & 0xffff) << 16) | (cmd[14] & 0xffff)) / 65536.0f);
|
1387 | | sprintf(dwdx, "%4.4f", (float)(INT32)((cmd[11] & 0xffff0000) | ((cmd[15] >> 16) & 0xffff)) / 65536.0f);
|
1388 | | sprintf(dsde, "%4.4f", (float)(INT32)((cmd[16] & 0xffff0000) | ((cmd[20] >> 16) & 0xffff)) / 65536.0f);
|
1389 | | sprintf(dtde, "%4.4f", (float)(INT32)(((cmd[16] & 0xffff) << 16) | (cmd[20] & 0xffff)) / 65536.0f);
|
1390 | | sprintf(dwde, "%4.4f", (float)(INT32)((cmd[17] & 0xffff0000) | ((cmd[21] >> 16) & 0xffff)) / 65536.0f);
|
1391 | | sprintf(dsdy, "%4.4f", (float)(INT32)((cmd[18] & 0xffff0000) | ((cmd[22] >> 16) & 0xffff)) / 65536.0f);
|
1392 | | sprintf(dtdy, "%4.4f", (float)(INT32)(((cmd[18] & 0xffff) << 16) | (cmd[22] & 0xffff)) / 65536.0f);
|
1393 | | sprintf(dwdy, "%4.4f", (float)(INT32)((cmd[19] & 0xffff0000) | ((cmd[23] >> 16) & 0xffff)) / 65536.0f);
|
1394 | | |
1395 | | |
1396 | | buffer+=sprintf(buffer, "Tri_TexZ %d, XL: %s, XM: %s, XH: %s, YL: %s, YM: %s, YH: %s\n", lft, xl,xm,xh,yl,ym,yh);
|
1397 | | buffer+=sprintf(buffer, " ");
|
1398 | | buffer+=sprintf(buffer, " S: %s, T: %s, W: %s\n", s, t, w);
|
1399 | | buffer+=sprintf(buffer, " ");
|
1400 | | buffer+=sprintf(buffer, " DSDX: %s, DTDX: %s, DWDX: %s\n", dsdx, dtdx, dwdx);
|
1401 | | buffer+=sprintf(buffer, " ");
|
1402 | | buffer+=sprintf(buffer, " DSDE: %s, DTDE: %s, DWDE: %s\n", dsde, dtde, dwde);
|
1403 | | buffer+=sprintf(buffer, " ");
|
1404 | | buffer+=sprintf(buffer, " DSDY: %s, DTDY: %s, DWDY: %s\n", dsdy, dtdy, dwdy);
|
1405 | | break;
|
1406 | | }
|
1407 | | case 0x0c: // Tri_Shade
|
1408 | | {
|
1409 | | int lft = (command >> 23) & 0x1;
|
1410 | | |
1411 | | if (length != rdp_command_length[command])
|
1412 | | {
|
1413 | | sprintf(buffer, "ERROR: Tri_Shade length = %d\n", length);
|
1414 | | return;
|
1415 | | }
|
1416 | | |
1417 | | for (i=2; i < 24; i++)
|
1418 | | {
|
1419 | | cmd[i] = m_cmd_data[i];
|
1420 | | }
|
1421 | | |
1422 | | sprintf(yl, "%4.4f", (float)((cmd[0] >> 0) & 0x1fff) / 4.0f);
|
1423 | | sprintf(ym, "%4.4f", (float)((cmd[1] >> 16) & 0x1fff) / 4.0f);
|
1424 | | sprintf(yh, "%4.4f", (float)((cmd[1] >> 0) & 0x1fff) / 4.0f);
|
1425 | | sprintf(xl, "%4.4f", (float)((INT32)cmd[2] / 65536.0f));
|
1426 | | sprintf(dxldy, "%4.4f", (float)((INT32)cmd[3] / 65536.0f));
|
1427 | | sprintf(xh, "%4.4f", (float)((INT32)cmd[4] / 65536.0f));
|
1428 | | sprintf(dxhdy, "%4.4f", (float)((INT32)cmd[5] / 65536.0f));
|
1429 | | sprintf(xm, "%4.4f", (float)((INT32)cmd[6] / 65536.0f));
|
1430 | | sprintf(dxmdy, "%4.4f", (float)((INT32)cmd[7] / 65536.0f));
|
1431 | | sprintf(rt, "%4.4f", (float)(INT32)((cmd[8] & 0xffff0000) | ((cmd[12] >> 16) & 0xffff)) / 65536.0f);
|
1432 | | sprintf(gt, "%4.4f", (float)(INT32)(((cmd[8] & 0xffff) << 16) | (cmd[12] & 0xffff)) / 65536.0f);
|
1433 | | sprintf(bt, "%4.4f", (float)(INT32)((cmd[9] & 0xffff0000) | ((cmd[13] >> 16) & 0xffff)) / 65536.0f);
|
1434 | | sprintf(at, "%4.4f", (float)(INT32)(((cmd[9] & 0xffff) << 16) | (cmd[13] & 0xffff)) / 65536.0f);
|
1435 | | sprintf(drdx, "%4.4f", (float)(INT32)((cmd[10] & 0xffff0000) | ((cmd[14] >> 16) & 0xffff)) / 65536.0f);
|
1436 | | sprintf(dgdx, "%4.4f", (float)(INT32)(((cmd[10] & 0xffff) << 16) | (cmd[14] & 0xffff)) / 65536.0f);
|
1437 | | sprintf(dbdx, "%4.4f", (float)(INT32)((cmd[11] & 0xffff0000) | ((cmd[15] >> 16) & 0xffff)) / 65536.0f);
|
1438 | | sprintf(dadx, "%4.4f", (float)(INT32)(((cmd[11] & 0xffff) << 16) | (cmd[15] & 0xffff)) / 65536.0f);
|
1439 | | sprintf(drde, "%4.4f", (float)(INT32)((cmd[16] & 0xffff0000) | ((cmd[20] >> 16) & 0xffff)) / 65536.0f);
|
1440 | | sprintf(dgde, "%4.4f", (float)(INT32)(((cmd[16] & 0xffff) << 16) | (cmd[20] & 0xffff)) / 65536.0f);
|
1441 | | sprintf(dbde, "%4.4f", (float)(INT32)((cmd[17] & 0xffff0000) | ((cmd[21] >> 16) & 0xffff)) / 65536.0f);
|
1442 | | sprintf(dade, "%4.4f", (float)(INT32)(((cmd[17] & 0xffff) << 16) | (cmd[21] & 0xffff)) / 65536.0f);
|
1443 | | sprintf(drdy, "%4.4f", (float)(INT32)((cmd[18] & 0xffff0000) | ((cmd[22] >> 16) & 0xffff)) / 65536.0f);
|
1444 | | sprintf(dgdy, "%4.4f", (float)(INT32)(((cmd[18] & 0xffff) << 16) | (cmd[22] & 0xffff)) / 65536.0f);
|
1445 | | sprintf(dbdy, "%4.4f", (float)(INT32)((cmd[19] & 0xffff0000) | ((cmd[23] >> 16) & 0xffff)) / 65536.0f);
|
1446 | | sprintf(dady, "%4.4f", (float)(INT32)(((cmd[19] & 0xffff) << 16) | (cmd[23] & 0xffff)) / 65536.0f);
|
1447 | | |
1448 | | buffer+=sprintf(buffer, "Tri_Shade %d, XL: %s, XM: %s, XH: %s, YL: %s, YM: %s, YH: %s\n", lft, xl,xm,xh,yl,ym,yh);
|
1449 | | buffer+=sprintf(buffer, " ");
|
1450 | | buffer+=sprintf(buffer, " R: %s, G: %s, B: %s, A: %s\n", rt, gt, bt, at);
|
1451 | | buffer+=sprintf(buffer, " ");
|
1452 | | buffer+=sprintf(buffer, " DRDX: %s, DGDX: %s, DBDX: %s, DADX: %s\n", drdx, dgdx, dbdx, dadx);
|
1453 | | buffer+=sprintf(buffer, " ");
|
1454 | | buffer+=sprintf(buffer, " DRDE: %s, DGDE: %s, DBDE: %s, DADE: %s\n", drde, dgde, dbde, dade);
|
1455 | | buffer+=sprintf(buffer, " ");
|
1456 | | buffer+=sprintf(buffer, " DRDY: %s, DGDY: %s, DBDY: %s, DADY: %s\n", drdy, dgdy, dbdy, dady);
|
1457 | | break;
|
1458 | | }
|
1459 | | case 0x0d: // Tri_ShadeZ
|
1460 | | {
|
1461 | | int lft = (command >> 23) & 0x1;
|
1462 | | |
1463 | | if (length != rdp_command_length[command])
|
1464 | | {
|
1465 | | sprintf(buffer, "ERROR: Tri_ShadeZ length = %d\n", length);
|
1466 | | return;
|
1467 | | }
|
1468 | | |
1469 | | for (i=2; i < 24; i++)
|
1470 | | {
|
1471 | | cmd[i] = m_cmd_data[i];
|
1472 | | }
|
1473 | | |
1474 | | sprintf(yl, "%4.4f", (float)((cmd[0] >> 0) & 0x1fff) / 4.0f);
|
1475 | | sprintf(ym, "%4.4f", (float)((cmd[1] >> 16) & 0x1fff) / 4.0f);
|
1476 | | sprintf(yh, "%4.4f", (float)((cmd[1] >> 0) & 0x1fff) / 4.0f);
|
1477 | | sprintf(xl, "%4.4f", (float)((INT32)cmd[2] / 65536.0f));
|
1478 | | sprintf(dxldy, "%4.4f", (float)((INT32)cmd[3] / 65536.0f));
|
1479 | | sprintf(xh, "%4.4f", (float)((INT32)cmd[4] / 65536.0f));
|
1480 | | sprintf(dxhdy, "%4.4f", (float)((INT32)cmd[5] / 65536.0f));
|
1481 | | sprintf(xm, "%4.4f", (float)((INT32)cmd[6] / 65536.0f));
|
1482 | | sprintf(dxmdy, "%4.4f", (float)((INT32)cmd[7] / 65536.0f));
|
1483 | | sprintf(rt, "%4.4f", (float)(INT32)((cmd[8] & 0xffff0000) | ((cmd[12] >> 16) & 0xffff)) / 65536.0f);
|
1484 | | sprintf(gt, "%4.4f", (float)(INT32)(((cmd[8] & 0xffff) << 16) | (cmd[12] & 0xffff)) / 65536.0f);
|
1485 | | sprintf(bt, "%4.4f", (float)(INT32)((cmd[9] & 0xffff0000) | ((cmd[13] >> 16) & 0xffff)) / 65536.0f);
|
1486 | | sprintf(at, "%4.4f", (float)(INT32)(((cmd[9] & 0xffff) << 16) | (cmd[13] & 0xffff)) / 65536.0f);
|
1487 | | sprintf(drdx, "%4.4f", (float)(INT32)((cmd[10] & 0xffff0000) | ((cmd[14] >> 16) & 0xffff)) / 65536.0f);
|
1488 | | sprintf(dgdx, "%4.4f", (float)(INT32)(((cmd[10] & 0xffff) << 16) | (cmd[14] & 0xffff)) / 65536.0f);
|
1489 | | sprintf(dbdx, "%4.4f", (float)(INT32)((cmd[11] & 0xffff0000) | ((cmd[15] >> 16) & 0xffff)) / 65536.0f);
|
1490 | | sprintf(dadx, "%4.4f", (float)(INT32)(((cmd[11] & 0xffff) << 16) | (cmd[15] & 0xffff)) / 65536.0f);
|
1491 | | sprintf(drde, "%4.4f", (float)(INT32)((cmd[16] & 0xffff0000) | ((cmd[20] >> 16) & 0xffff)) / 65536.0f);
|
1492 | | sprintf(dgde, "%4.4f", (float)(INT32)(((cmd[16] & 0xffff) << 16) | (cmd[20] & 0xffff)) / 65536.0f);
|
1493 | | sprintf(dbde, "%4.4f", (float)(INT32)((cmd[17] & 0xffff0000) | ((cmd[21] >> 16) & 0xffff)) / 65536.0f);
|
1494 | | sprintf(dade, "%4.4f", (float)(INT32)(((cmd[17] & 0xffff) << 16) | (cmd[21] & 0xffff)) / 65536.0f);
|
1495 | | sprintf(drdy, "%4.4f", (float)(INT32)((cmd[18] & 0xffff0000) | ((cmd[22] >> 16) & 0xffff)) / 65536.0f);
|
1496 | | sprintf(dgdy, "%4.4f", (float)(INT32)(((cmd[18] & 0xffff) << 16) | (cmd[22] & 0xffff)) / 65536.0f);
|
1497 | | sprintf(dbdy, "%4.4f", (float)(INT32)((cmd[19] & 0xffff0000) | ((cmd[23] >> 16) & 0xffff)) / 65536.0f);
|
1498 | | sprintf(dady, "%4.4f", (float)(INT32)(((cmd[19] & 0xffff) << 16) | (cmd[23] & 0xffff)) / 65536.0f);
|
1499 | | |
1500 | | buffer+=sprintf(buffer, "Tri_ShadeZ %d, XL: %s, XM: %s, XH: %s, YL: %s, YM: %s, YH: %s\n", lft, xl,xm,xh,yl,ym,yh);
|
1501 | | buffer+=sprintf(buffer, " ");
|
1502 | | buffer+=sprintf(buffer, " R: %s, G: %s, B: %s, A: %s\n", rt, gt, bt, at);
|
1503 | | buffer+=sprintf(buffer, " ");
|
1504 | | buffer+=sprintf(buffer, " DRDX: %s, DGDX: %s, DBDX: %s, DADX: %s\n", drdx, dgdx, dbdx, dadx);
|
1505 | | buffer+=sprintf(buffer, " ");
|
1506 | | buffer+=sprintf(buffer, " DRDE: %s, DGDE: %s, DBDE: %s, DADE: %s\n", drde, dgde, dbde, dade);
|
1507 | | buffer+=sprintf(buffer, " ");
|
1508 | | buffer+=sprintf(buffer, " DRDY: %s, DGDY: %s, DBDY: %s, DADY: %s\n", drdy, dgdy, dbdy, dady);
|
1509 | | break;
|
1510 | | }
|
1511 | | case 0x0e: // Tri_TexShade
|
1512 | | {
|
1513 | | int lft = (command >> 23) & 0x1;
|
1514 | | |
1515 | | if (length < rdp_command_length[command])
|
1516 | | {
|
1517 | | sprintf(buffer, "ERROR: Tri_TexShade length = %d\n", length);
|
1518 | | return;
|
1519 | | }
|
1520 | | |
1521 | | for (i=2; i < 40; i++)
|
1522 | | {
|
1523 | | cmd[i] = m_cmd_data[m_cmd_cur+i];
|
1524 | | }
|
1525 | | |
1526 | | sprintf(yl, "%4.4f", (float)((cmd[0] >> 0) & 0x1fff) / 4.0f);
|
1527 | | sprintf(ym, "%4.4f", (float)((cmd[1] >> 16) & 0x1fff) / 4.0f);
|
1528 | | sprintf(yh, "%4.4f", (float)((cmd[1] >> 0) & 0x1fff) / 4.0f);
|
1529 | | sprintf(xl, "%4.4f", (float)((INT32)cmd[2] / 65536.0f));
|
1530 | | sprintf(dxldy, "%4.4f", (float)((INT32)cmd[3] / 65536.0f));
|
1531 | | sprintf(xh, "%4.4f", (float)((INT32)cmd[4] / 65536.0f));
|
1532 | | sprintf(dxhdy, "%4.4f", (float)((INT32)cmd[5] / 65536.0f));
|
1533 | | sprintf(xm, "%4.4f", (float)((INT32)cmd[6] / 65536.0f));
|
1534 | | sprintf(dxmdy, "%4.4f", (float)((INT32)cmd[7] / 65536.0f));
|
1535 | | sprintf(rt, "%4.4f", (float)(INT32)((cmd[8] & 0xffff0000) | ((cmd[12] >> 16) & 0xffff)) / 65536.0f);
|
1536 | | sprintf(gt, "%4.4f", (float)(INT32)(((cmd[8] & 0xffff) << 16) | (cmd[12] & 0xffff)) / 65536.0f);
|
1537 | | sprintf(bt, "%4.4f", (float)(INT32)((cmd[9] & 0xffff0000) | ((cmd[13] >> 16) & 0xffff)) / 65536.0f);
|
1538 | | sprintf(at, "%4.4f", (float)(INT32)(((cmd[9] & 0xffff) << 16) | (cmd[13] & 0xffff)) / 65536.0f);
|
1539 | | sprintf(drdx, "%4.4f", (float)(INT32)((cmd[10] & 0xffff0000) | ((cmd[14] >> 16) & 0xffff)) / 65536.0f);
|
1540 | | sprintf(dgdx, "%4.4f", (float)(INT32)(((cmd[10] & 0xffff) << 16) | (cmd[14] & 0xffff)) / 65536.0f);
|
1541 | | sprintf(dbdx, "%4.4f", (float)(INT32)((cmd[11] & 0xffff0000) | ((cmd[15] >> 16) & 0xffff)) / 65536.0f);
|
1542 | | sprintf(dadx, "%4.4f", (float)(INT32)(((cmd[11] & 0xffff) << 16) | (cmd[15] & 0xffff)) / 65536.0f);
|
1543 | | sprintf(drde, "%4.4f", (float)(INT32)((cmd[16] & 0xffff0000) | ((cmd[20] >> 16) & 0xffff)) / 65536.0f);
|
1544 | | sprintf(dgde, "%4.4f", (float)(INT32)(((cmd[16] & 0xffff) << 16) | (cmd[20] & 0xffff)) / 65536.0f);
|
1545 | | sprintf(dbde, "%4.4f", (float)(INT32)((cmd[17] & 0xffff0000) | ((cmd[21] >> 16) & 0xffff)) / 65536.0f);
|
1546 | | sprintf(dade, "%4.4f", (float)(INT32)(((cmd[17] & 0xffff) << 16) | (cmd[21] & 0xffff)) / 65536.0f);
|
1547 | | sprintf(drdy, "%4.4f", (float)(INT32)((cmd[18] & 0xffff0000) | ((cmd[22] >> 16) & 0xffff)) / 65536.0f);
|
1548 | | sprintf(dgdy, "%4.4f", (float)(INT32)(((cmd[18] & 0xffff) << 16) | (cmd[22] & 0xffff)) / 65536.0f);
|
1549 | | sprintf(dbdy, "%4.4f", (float)(INT32)((cmd[19] & 0xffff0000) | ((cmd[23] >> 16) & 0xffff)) / 65536.0f);
|
1550 | | sprintf(dady, "%4.4f", (float)(INT32)(((cmd[19] & 0xffff) << 16) | (cmd[23] & 0xffff)) / 65536.0f);
|
1551 | | |
1552 | | sprintf(s, "%4.4f", (float)(INT32)((cmd[24] & 0xffff0000) | ((cmd[28] >> 16) & 0xffff)) / 65536.0f);
|
1553 | | sprintf(t, "%4.4f", (float)(INT32)(((cmd[24] & 0xffff) << 16) | (cmd[28] & 0xffff)) / 65536.0f);
|
1554 | | sprintf(w, "%4.4f", (float)(INT32)((cmd[25] & 0xffff0000) | ((cmd[29] >> 16) & 0xffff)) / 65536.0f);
|
1555 | | sprintf(dsdx, "%4.4f", (float)(INT32)((cmd[26] & 0xffff0000) | ((cmd[30] >> 16) & 0xffff)) / 65536.0f);
|
1556 | | sprintf(dtdx, "%4.4f", (float)(INT32)(((cmd[26] & 0xffff) << 16) | (cmd[30] & 0xffff)) / 65536.0f);
|
1557 | | sprintf(dwdx, "%4.4f", (float)(INT32)((cmd[27] & 0xffff0000) | ((cmd[31] >> 16) & 0xffff)) / 65536.0f);
|
1558 | | sprintf(dsde, "%4.4f", (float)(INT32)((cmd[32] & 0xffff0000) | ((cmd[36] >> 16) & 0xffff)) / 65536.0f);
|
1559 | | sprintf(dtde, "%4.4f", (float)(INT32)(((cmd[32] & 0xffff) << 16) | (cmd[36] & 0xffff)) / 65536.0f);
|
1560 | | sprintf(dwde, "%4.4f", (float)(INT32)((cmd[33] & 0xffff0000) | ((cmd[37] >> 16) & 0xffff)) / 65536.0f);
|
1561 | | sprintf(dsdy, "%4.4f", (float)(INT32)((cmd[34] & 0xffff0000) | ((cmd[38] >> 16) & 0xffff)) / 65536.0f);
|
1562 | | sprintf(dtdy, "%4.4f", (float)(INT32)(((cmd[34] & 0xffff) << 16) | (cmd[38] & 0xffff)) / 65536.0f);
|
1563 | | sprintf(dwdy, "%4.4f", (float)(INT32)((cmd[35] & 0xffff0000) | ((cmd[39] >> 16) & 0xffff)) / 65536.0f);
|
1564 | | |
1565 | | |
1566 | | buffer+=sprintf(buffer, "Tri_TexShade %d, XL: %s, XM: %s, XH: %s, YL: %s, YM: %s, YH: %s\n", lft, xl,xm,xh,yl,ym,yh);
|
1567 | | buffer+=sprintf(buffer, " ");
|
1568 | | buffer+=sprintf(buffer, " R: %s, G: %s, B: %s, A: %s\n", rt, gt, bt, at);
|
1569 | | buffer+=sprintf(buffer, " ");
|
1570 | | buffer+=sprintf(buffer, " DRDX: %s, DGDX: %s, DBDX: %s, DADX: %s\n", drdx, dgdx, dbdx, dadx);
|
1571 | | buffer+=sprintf(buffer, " ");
|
1572 | | buffer+=sprintf(buffer, " DRDE: %s, DGDE: %s, DBDE: %s, DADE: %s\n", drde, dgde, dbde, dade);
|
1573 | | buffer+=sprintf(buffer, " ");
|
1574 | | buffer+=sprintf(buffer, " DRDY: %s, DGDY: %s, DBDY: %s, DADY: %s\n", drdy, dgdy, dbdy, dady);
|
1575 | | |
1576 | | buffer+=sprintf(buffer, " ");
|
1577 | | buffer+=sprintf(buffer, " S: %s, T: %s, W: %s\n", s, t, w);
|
1578 | | buffer+=sprintf(buffer, " ");
|
1579 | | buffer+=sprintf(buffer, " DSDX: %s, DTDX: %s, DWDX: %s\n", dsdx, dtdx, dwdx);
|
1580 | | buffer+=sprintf(buffer, " ");
|
1581 | | buffer+=sprintf(buffer, " DSDE: %s, DTDE: %s, DWDE: %s\n", dsde, dtde, dwde);
|
1582 | | buffer+=sprintf(buffer, " ");
|
1583 | | buffer+=sprintf(buffer, " DSDY: %s, DTDY: %s, DWDY: %s\n", dsdy, dtdy, dwdy);
|
1584 | | break;
|
1585 | | }
|
1586 | | case 0x0f: // Tri_TexShadeZ
|
1587 | | {
|
1588 | | int lft = (command >> 23) & 0x1;
|
1589 | | |
1590 | | if (length < rdp_command_length[command])
|
1591 | | {
|
1592 | | sprintf(buffer, "ERROR: Tri_TexShadeZ length = %d\n", length);
|
1593 | | return;
|
1594 | | }
|
1595 | | |
1596 | | for (i=2; i < 40; i++)
|
1597 | | {
|
1598 | | cmd[i] = m_cmd_data[m_cmd_cur+i];
|
1599 | | }
|
1600 | | |
1601 | | sprintf(yl, "%4.4f", (float)((cmd[0] >> 0) & 0x1fff) / 4.0f);
|
1602 | | sprintf(ym, "%4.4f", (float)((cmd[1] >> 16) & 0x1fff) / 4.0f);
|
1603 | | sprintf(yh, "%4.4f", (float)((cmd[1] >> 0) & 0x1fff) / 4.0f);
|
1604 | | sprintf(xl, "%4.4f", (float)((INT32)cmd[2] / 65536.0f));
|
1605 | | sprintf(dxldy, "%4.4f", (float)((INT32)cmd[3] / 65536.0f));
|
1606 | | sprintf(xh, "%4.4f", (float)((INT32)cmd[4] / 65536.0f));
|
1607 | | sprintf(dxhdy, "%4.4f", (float)((INT32)cmd[5] / 65536.0f));
|
1608 | | sprintf(xm, "%4.4f", (float)((INT32)cmd[6] / 65536.0f));
|
1609 | | sprintf(dxmdy, "%4.4f", (float)((INT32)cmd[7] / 65536.0f));
|
1610 | | sprintf(rt, "%4.4f", (float)(INT32)((cmd[8] & 0xffff0000) | ((cmd[12] >> 16) & 0xffff)) / 65536.0f);
|
1611 | | sprintf(gt, "%4.4f", (float)(INT32)(((cmd[8] & 0xffff) << 16) | (cmd[12] & 0xffff)) / 65536.0f);
|
1612 | | sprintf(bt, "%4.4f", (float)(INT32)((cmd[9] & 0xffff0000) | ((cmd[13] >> 16) & 0xffff)) / 65536.0f);
|
1613 | | sprintf(at, "%4.4f", (float)(INT32)(((cmd[9] & 0xffff) << 16) | (cmd[13] & 0xffff)) / 65536.0f);
|
1614 | | sprintf(drdx, "%4.4f", (float)(INT32)((cmd[10] & 0xffff0000) | ((cmd[14] >> 16) & 0xffff)) / 65536.0f);
|
1615 | | sprintf(dgdx, "%4.4f", (float)(INT32)(((cmd[10] & 0xffff) << 16) | (cmd[14] & 0xffff)) / 65536.0f);
|
1616 | | sprintf(dbdx, "%4.4f", (float)(INT32)((cmd[11] & 0xffff0000) | ((cmd[15] >> 16) & 0xffff)) / 65536.0f);
|
1617 | | sprintf(dadx, "%4.4f", (float)(INT32)(((cmd[11] & 0xffff) << 16) | (cmd[15] & 0xffff)) / 65536.0f);
|
1618 | | sprintf(drde, "%4.4f", (float)(INT32)((cmd[16] & 0xffff0000) | ((cmd[20] >> 16) & 0xffff)) / 65536.0f);
|
1619 | | sprintf(dgde, "%4.4f", (float)(INT32)(((cmd[16] & 0xffff) << 16) | (cmd[20] & 0xffff)) / 65536.0f);
|
1620 | | sprintf(dbde, "%4.4f", (float)(INT32)((cmd[17] & 0xffff0000) | ((cmd[21] >> 16) & 0xffff)) / 65536.0f);
|
1621 | | sprintf(dade, "%4.4f", (float)(INT32)(((cmd[17] & 0xffff) << 16) | (cmd[21] & 0xffff)) / 65536.0f);
|
1622 | | sprintf(drdy, "%4.4f", (float)(INT32)((cmd[18] & 0xffff0000) | ((cmd[22] >> 16) & 0xffff)) / 65536.0f);
|
1623 | | sprintf(dgdy, "%4.4f", (float)(INT32)(((cmd[18] & 0xffff) << 16) | (cmd[22] & 0xffff)) / 65536.0f);
|
1624 | | sprintf(dbdy, "%4.4f", (float)(INT32)((cmd[19] & 0xffff0000) | ((cmd[23] >> 16) & 0xffff)) / 65536.0f);
|
1625 | | sprintf(dady, "%4.4f", (float)(INT32)(((cmd[19] & 0xffff) << 16) | (cmd[23] & 0xffff)) / 65536.0f);
|
1626 | | |
1627 | | sprintf(s, "%4.4f", (float)(INT32)((cmd[24] & 0xffff0000) | ((cmd[28] >> 16) & 0xffff)) / 65536.0f);
|
1628 | | sprintf(t, "%4.4f", (float)(INT32)(((cmd[24] & 0xffff) << 16) | (cmd[28] & 0xffff)) / 65536.0f);
|
1629 | | sprintf(w, "%4.4f", (float)(INT32)((cmd[25] & 0xffff0000) | ((cmd[29] >> 16) & 0xffff)) / 65536.0f);
|
1630 | | sprintf(dsdx, "%4.4f", (float)(INT32)((cmd[26] & 0xffff0000) | ((cmd[30] >> 16) & 0xffff)) / 65536.0f);
|
1631 | | sprintf(dtdx, "%4.4f", (float)(INT32)(((cmd[26] & 0xffff) << 16) | (cmd[30] & 0xffff)) / 65536.0f);
|
1632 | | sprintf(dwdx, "%4.4f", (float)(INT32)((cmd[27] & 0xffff0000) | ((cmd[31] >> 16) & 0xffff)) / 65536.0f);
|
1633 | | sprintf(dsde, "%4.4f", (float)(INT32)((cmd[32] & 0xffff0000) | ((cmd[36] >> 16) & 0xffff)) / 65536.0f);
|
1634 | | sprintf(dtde, "%4.4f", (float)(INT32)(((cmd[32] & 0xffff) << 16) | (cmd[36] & 0xffff)) / 65536.0f);
|
1635 | | sprintf(dwde, "%4.4f", (float)(INT32)((cmd[33] & 0xffff0000) | ((cmd[37] >> 16) & 0xffff)) / 65536.0f);
|
1636 | | sprintf(dsdy, "%4.4f", (float)(INT32)((cmd[34] & 0xffff0000) | ((cmd[38] >> 16) & 0xffff)) / 65536.0f);
|
1637 | | sprintf(dtdy, "%4.4f", (float)(INT32)(((cmd[34] & 0xffff) << 16) | (cmd[38] & 0xffff)) / 65536.0f);
|
1638 | | sprintf(dwdy, "%4.4f", (float)(INT32)((cmd[35] & 0xffff0000) | ((cmd[39] >> 16) & 0xffff)) / 65536.0f);
|
1639 | | |
1640 | | |
1641 | | buffer+=sprintf(buffer, "Tri_TexShadeZ %d, XL: %s, XM: %s, XH: %s, YL: %s, YM: %s, YH: %s\n", lft, xl,xm,xh,yl,ym,yh);
|
1642 | | buffer+=sprintf(buffer, " ");
|
1643 | | buffer+=sprintf(buffer, " R: %s, G: %s, B: %s, A: %s\n", rt, gt, bt, at);
|
1644 | | buffer+=sprintf(buffer, " ");
|
1645 | | buffer+=sprintf(buffer, " DRDX: %s, DGDX: %s, DBDX: %s, DADX: %s\n", drdx, dgdx, dbdx, dadx);
|
1646 | | buffer+=sprintf(buffer, " ");
|
1647 | | buffer+=sprintf(buffer, " DRDE: %s, DGDE: %s, DBDE: %s, DADE: %s\n", drde, dgde, dbde, dade);
|
1648 | | buffer+=sprintf(buffer, " ");
|
1649 | | buffer+=sprintf(buffer, " DRDY: %s, DGDY: %s, DBDY: %s, DADY: %s\n", drdy, dgdy, dbdy, dady);
|
1650 | | |
1651 | | buffer+=sprintf(buffer, " ");
|
1652 | | buffer+=sprintf(buffer, " S: %s, T: %s, W: %s\n", s, t, w);
|
1653 | | buffer+=sprintf(buffer, " ");
|
1654 | | buffer+=sprintf(buffer, " DSDX: %s, DTDX: %s, DWDX: %s\n", dsdx, dtdx, dwdx);
|
1655 | | buffer+=sprintf(buffer, " ");
|
1656 | | buffer+=sprintf(buffer, " DSDE: %s, DTDE: %s, DWDE: %s\n", dsde, dtde, dwde);
|
1657 | | buffer+=sprintf(buffer, " ");
|
1658 | | buffer+=sprintf(buffer, " DSDY: %s, DTDY: %s, DWDY: %s\n", dsdy, dtdy, dwdy);
|
1659 | | break;
|
1660 | | }
|
1661 | | case 0x24:
|
1662 | | case 0x25:
|
1663 | | {
|
1664 | | if (length < 16)
|
1665 | | {
|
1666 | | sprintf(buffer, "ERROR: Texture_Rectangle length = %d\n", length);
|
1667 | | return;
|
1668 | | }
|
1669 | | cmd[2] = m_cmd_data[m_cmd_cur+2];
|
1670 | | cmd[3] = m_cmd_data[m_cmd_cur+3];
|
1671 | | sprintf(s, "%4.4f", (float)(INT16)((cmd[2] >> 16) & 0xffff) / 32.0f);
|
1672 | | sprintf(t, "%4.4f", (float)(INT16)((cmd[2] >> 0) & 0xffff) / 32.0f);
|
1673 | | sprintf(dsdx, "%4.4f", (float)(INT16)((cmd[3] >> 16) & 0xffff) / 1024.0f);
|
1674 | | sprintf(dtdy, "%4.4f", (float)(INT16)((cmd[3] >> 16) & 0xffff) / 1024.0f);
|
1675 | | |
1676 | | if (command == 0x24)
|
1677 | | sprintf(buffer, "Texture_Rectangle %d, %s, %s, %s, %s, %s, %s, %s, %s", tile, sh, th, sl, tl, s, t, dsdx, dtdy);
|
1678 | | else
|
1679 | | sprintf(buffer, "Texture_Rectangle_Flip %d, %s, %s, %s, %s, %s, %s, %s, %s", tile, sh, th, sl, tl, s, t, dsdx, dtdy);
|
1680 | | |
1681 | | break;
|
1682 | | }
|
1683 | | case 0x26: sprintf(buffer, "Sync_Load"); break;
|
1684 | | case 0x27: sprintf(buffer, "Sync_Pipe"); break;
|
1685 | | case 0x28: sprintf(buffer, "Sync_Tile"); break;
|
1686 | | case 0x29: sprintf(buffer, "Sync_Full"); break;
|
1687 | | case 0x2d: sprintf(buffer, "Set_Scissor %s, %s, %s, %s", sl, tl, sh, th); break;
|
1688 | | case 0x2e: sprintf(buffer, "Set_Prim_Depth %04X, %04X", (cmd[1] >> 16) & 0xffff, cmd[1] & 0xffff); break;
|
1689 | | case 0x2f: sprintf(buffer, "Set_Other_Modes %08X %08X", cmd[0], cmd[1]); break;
|
1690 | | case 0x30: sprintf(buffer, "Load_TLUT %d, %s, %s, %s, %s", tile, sl, tl, sh, th); break;
|
1691 | | case 0x32: sprintf(buffer, "Set_Tile_Size %d, %s, %s, %s, %s", tile, sl, tl, sh, th); break;
|
1692 | | case 0x33: sprintf(buffer, "Load_Block %d, %03X, %03X, %03X, %03X", tile, (cmd[0] >> 12) & 0xfff, cmd[0] & 0xfff, (cmd[1] >> 12) & 0xfff, cmd[1] & 0xfff); break;
|
1693 | | case 0x34: sprintf(buffer, "Load_Tile %d, %s, %s, %s, %s", tile, sl, tl, sh, th); break;
|
1694 | | case 0x35: sprintf(buffer, "Set_Tile %d, %s, %s, %d, %04X", tile, format, size, ((cmd[0] >> 9) & 0x1ff) * 8, (cmd[0] & 0x1ff) * 8); break;
|
1695 | | case 0x36: sprintf(buffer, "Fill_Rectangle %s, %s, %s, %s", sh, th, sl, tl); break;
|
1696 | | case 0x37: sprintf(buffer, "Set_Fill_Color R: %d, G: %d, B: %d, A: %d", r, g, b, a); break;
|
1697 | | case 0x38: sprintf(buffer, "Set_Fog_Color R: %d, G: %d, B: %d, A: %d", r, g, b, a); break;
|
1698 | | case 0x39: sprintf(buffer, "Set_Blend_Color R: %d, G: %d, B: %d, A: %d", r, g, b, a); break;
|
1699 | | case 0x3a: sprintf(buffer, "Set_Prim_Color %d, %d, R: %d, G: %d, B: %d, A: %d", (cmd[0] >> 8) & 0x1f, cmd[0] & 0xff, r, g, b, a); break;
|
1700 | | case 0x3b: sprintf(buffer, "Set_Env_Color R: %d, G: %d, B: %d, A: %d", r, g, b, a); break;
|
1701 | | case 0x3c: sprintf(buffer, "Set_Combine %08X %08X", cmd[0], cmd[1]); break;
|
1702 | | case 0x3d: sprintf(buffer, "Set_Texture_Image %s, %s, %d, %08X", format, size, (cmd[0] & 0x1ff)+1, cmd[1]); break;
|
1703 | | case 0x3e: sprintf(buffer, "Set_Mask_Image %08X", cmd[1]); break;
|
1704 | | case 0x3f: sprintf(buffer, "Set_Color_Image %s, %s, %d, %08X", format, size, (cmd[0] & 0x1ff)+1, cmd[1]); break;
|
1705 | | default: sprintf(buffer, "??? (%08X %08X)", cmd[0], cmd[1]); break;
|
1706 | | }
|
1707 | | }
|
1708 | | |
1709 | | /*****************************************************************************/
|
1710 | | |
1711 | | static UINT32 rightcvghex(UINT32 x, UINT32 fmask)
|
1712 | | {
|
1713 | | UINT32 stickybit = ((x >> 1) & 0x1fff) > 0;
|
1714 | | UINT32 covered = ((x >> 14) & 3) + stickybit;
|
1715 | | covered = (0xf0 >> covered) & 0xf;
|
1716 | | return (covered & fmask);
|
1717 | | }
|
1718 | | |
1719 | | static UINT32 leftcvghex(UINT32 x, UINT32 fmask)
|
1720 | | {
|
1721 | | UINT32 stickybit = ((x >> 1) & 0x1fff) > 0;
|
1722 | | UINT32 covered = ((x >> 14) & 3) + stickybit;
|
1723 | | covered = 0xf >> covered;
|
1724 | | return (covered & fmask);
|
1725 | | }
|
1726 | | |
1727 | | static INT32 CLIP(INT32 value,INT32 min,INT32 max)
|
1728 | | {
|
1729 | | if (value < min)
|
1730 | | {
|
1731 | | return min;
|
1732 | | }
|
1733 | | else if (value > max)
|
1734 | | {
|
1735 | | return max;
|
1736 | | }
|
1737 | | else
|
1738 | | {
|
1739 | | return value;
|
1740 | | }
|
1741 | | }
|
1742 | | |
1743 | | void n64_rdp::compute_cvg_noflip(extent_t *Spans, INT32* majorx, INT32* minorx, INT32* majorxint, INT32* minorxint, INT32 scanline, INT32 yh, INT32 yl, INT32 base)
|
1744 | | {
|
1745 | | INT32 purgestart = 0xfff;
|
1746 | | INT32 purgeend = 0;
|
1747 | | bool writablescanline = !(scanline & ~0x3ff);
|
1748 | | INT32 scanlinespx = scanline << 2;
|
1749 | | |
1750 | | if (!writablescanline) return;
|
1751 | | |
1752 | | for(int i = 0; i < 4; i++)
|
1753 | | {
|
1754 | | if (minorxint[i] < purgestart)
|
1755 | | {
|
1756 | | purgestart = minorxint[i];
|
1757 | | }
|
1758 | | if (majorxint[i] > purgeend)
|
1759 | | {
|
1760 | | purgeend = majorxint[i];
|
1761 | | }
|
1762 | | }
|
1763 | | |
1764 | | purgestart = CLIP(purgestart, 0, 1023);
|
1765 | | purgeend = CLIP(purgeend, 0, 1023);
|
1766 | | INT32 length = purgeend - purgestart;
|
1767 | | |
1768 | | if (length < 0) return;
|
1769 | | |
1770 | | rdp_span_aux *userdata = (rdp_span_aux*)Spans[scanline - base].userdata;
|
1771 | | memset(&userdata->m_cvg[purgestart], 0, (length + 1) << 1);
|
1772 | | |
1773 | | for(int i = 0; i < 4; i++)
|
1774 | | {
|
1775 | | INT32 minorcur = minorx[i];
|
1776 | | INT32 majorcur = majorx[i];
|
1777 | | INT32 minorcurint = minorxint[i];
|
1778 | | INT32 majorcurint = majorxint[i];
|
1779 | | length = majorcurint - minorcurint;
|
1780 | | |
1781 | | INT32 fmask = (i & 1) ? 5 : 0xa;
|
1782 | | INT32 maskshift = (i ^ 3) << 2;
|
1783 | | INT32 fmaskshifted = fmask << maskshift;
|
1784 | | INT32 fleft = CLIP(minorcurint + 1, 0, 647);
|
1785 | | INT32 fright = CLIP(majorcurint - 1, 0, 647);
|
1786 | | bool valid_y = ((scanlinespx + i) >= yh && (scanlinespx + i) < yl);
|
1787 | | if (valid_y && length >= 0)
|
1788 | | {
|
1789 | | if (minorcurint != majorcurint)
|
1790 | | {
|
1791 | | if (!(minorcurint & ~0x3ff))
|
1792 | | {
|
1793 | | userdata->m_cvg[minorcurint] |= (leftcvghex(minorcur, fmask) << maskshift);
|
1794 | | }
|
1795 | | if (!(majorcurint & ~0x3ff))
|
1796 | | {
|
1797 | | userdata->m_cvg[majorcurint] |= (rightcvghex(majorcur, fmask) << maskshift);
|
1798 | | }
|
1799 | | }
|
1800 | | else
|
1801 | | {
|
1802 | | if (!(majorcurint & ~0x3ff))
|
1803 | | {
|
1804 | | INT32 samecvg = leftcvghex(minorcur, fmask) & rightcvghex(majorcur, fmask);
|
1805 | | userdata->m_cvg[majorcurint] |= (samecvg << maskshift);
|
1806 | | }
|
1807 | | }
|
1808 | | for (; fleft <= fright; fleft++)
|
1809 | | {
|
1810 | | userdata->m_cvg[fleft] |= fmaskshifted;
|
1811 | | }
|
1812 | | }
|
1813 | | }
|
1814 | | }
|
1815 | | |
1816 | | void n64_rdp::compute_cvg_flip(extent_t *Spans, INT32* majorx, INT32* minorx, INT32* majorxint, INT32* minorxint, INT32 scanline, INT32 yh, INT32 yl, INT32 base)
|
1817 | | {
|
1818 | | INT32 purgestart = 0xfff;
|
1819 | | INT32 purgeend = 0;
|
1820 | | bool writablescanline = !(scanline & ~0x3ff);
|
1821 | | INT32 scanlinespx = scanline << 2;
|
1822 | | |
1823 | | if(!writablescanline) return;
|
1824 | | |
1825 | | for(int i = 0; i < 4; i++)
|
1826 | | {
|
1827 | | if (majorxint[i] < purgestart)
|
1828 | | {
|
1829 | | purgestart = majorxint[i];
|
1830 | | }
|
1831 | | if (minorxint[i] > purgeend)
|
1832 | | {
|
1833 | | purgeend = minorxint[i];
|
1834 | | }
|
1835 | | }
|
1836 | | |
1837 | | purgestart = CLIP(purgestart, 0, 1023);
|
1838 | | purgeend = CLIP(purgeend, 0, 1023);
|
1839 | | |
1840 | | int length = purgeend - purgestart;
|
1841 | | |
1842 | | if (length < 0) return;
|
1843 | | |
1844 | | rdp_span_aux *userdata = (rdp_span_aux*)Spans[scanline - base].userdata;
|
1845 | | memset(&userdata->m_cvg[purgestart], 0, (length + 1) << 1);
|
1846 | | |
1847 | | for(int i = 0; i < 4; i++)
|
1848 | | {
|
1849 | | INT32 minorcur = minorx[i];
|
1850 | | INT32 majorcur = majorx[i];
|
1851 | | INT32 minorcurint = minorxint[i];
|
1852 | | INT32 majorcurint = majorxint[i];
|
1853 | | length = minorcurint - majorcurint;
|
1854 | | |
1855 | | INT32 fmask = (i & 1) ? 5 : 0xa;
|
1856 | | INT32 maskshift = (i ^ 3) << 2;
|
1857 | | INT32 fmaskshifted = fmask << maskshift;
|
1858 | | INT32 fleft = CLIP(majorcurint + 1, 0, 647);
|
1859 | | INT32 fright = CLIP(minorcurint - 1, 0, 647);
|
1860 | | bool valid_y = ((scanlinespx + i) >= yh && (scanlinespx + i) < yl);
|
1861 | | if (valid_y && length >= 0)
|
1862 | | {
|
1863 | | if (minorcurint != majorcurint)
|
1864 | | {
|
1865 | | if (!(minorcurint & ~0x3ff))
|
1866 | | {
|
1867 | | userdata->m_cvg[minorcurint] |= (rightcvghex(minorcur, fmask) << maskshift);
|
1868 | | }
|
1869 | | if (!(majorcurint & ~0x3ff))
|
1870 | | {
|
1871 | | userdata->m_cvg[majorcurint] |= (leftcvghex(majorcur, fmask) << maskshift);
|
1872 | | }
|
1873 | | }
|
1874 | | else
|
1875 | | {
|
1876 | | if (!(majorcurint & ~0x3ff))
|
1877 | | {
|
1878 | | INT32 samecvg = rightcvghex(minorcur, fmask) & leftcvghex(majorcur, fmask);
|
1879 | | userdata->m_cvg[majorcurint] |= (samecvg << maskshift);
|
1880 | | }
|
1881 | | }
|
1882 | | for (; fleft <= fright; fleft++)
|
1883 | | {
|
1884 | | userdata->m_cvg[fleft] |= fmaskshifted;
|
1885 | | }
|
1886 | | }
|
1887 | | }
|
1888 | | }
|
1889 | | |
1890 | | void n64_rdp::DrawTriangle(bool shade, bool texture, bool zbuffer, bool rect)
|
1891 | | {
|
1892 | | UINT32 *cmd_data = rect ? m_temp_rect_data : m_cmd_data;
|
1893 | | UINT32 fifo_index = rect ? 0 : m_cmd_cur;
|
1894 | | UINT32 w1 = cmd_data[fifo_index + 0];
|
1895 | | UINT32 w2 = cmd_data[fifo_index + 1];
|
1896 | | |
1897 | | int flip = (w1 & 0x00800000) ? 1 : 0;
|
1898 | | MiscState.MaxLevel = ((w1 >> 19) & 7);
|
1899 | | int tilenum = (w1 >> 16) & 0x7;
|
1900 | | |
1901 | | int dsdiff = 0, dtdiff = 0, dwdiff = 0, drdiff = 0, dgdiff = 0, dbdiff = 0, dadiff = 0, dzdiff = 0;
|
1902 | | int dsdeh = 0, dtdeh = 0, dwdeh = 0, drdeh = 0, dgdeh = 0, dbdeh = 0, dadeh = 0, dzdeh = 0;
|
1903 | | int dsdxh = 0, dtdxh = 0, dwdxh = 0, drdxh = 0, dgdxh = 0, dbdxh = 0, dadxh = 0, dzdxh = 0;
|
1904 | | int dsdyh = 0, dtdyh = 0, dwdyh = 0, drdyh = 0, dgdyh = 0, dbdyh = 0, dadyh = 0, dzdyh = 0;
|
1905 | | |
1906 | | INT32 maxxmx = 0; // maxxmx / minxhx very opaque names, consider re-naming
|
1907 | | INT32 minxmx = 0;
|
1908 | | INT32 maxxhx = 0;
|
1909 | | INT32 minxhx = 0;
|
1910 | | |
1911 | | int shade_base = fifo_index + 8;
|
1912 | | int texture_base = fifo_index + 8;
|
1913 | | int zbuffer_base = fifo_index + 8;
|
1914 | | if(shade)
|
1915 | | {
|
1916 | | texture_base += 16;
|
1917 | | zbuffer_base += 16;
|
1918 | | }
|
1919 | | if(texture)
|
1920 | | {
|
1921 | | zbuffer_base += 16;
|
1922 | | }
|
1923 | | |
1924 | | UINT32 w3 = cmd_data[fifo_index + 2];
|
1925 | | UINT32 w4 = cmd_data[fifo_index + 3];
|
1926 | | UINT32 w5 = cmd_data[fifo_index + 4];
|
1927 | | UINT32 w6 = cmd_data[fifo_index + 5];
|
1928 | | UINT32 w7 = cmd_data[fifo_index + 6];
|
1929 | | UINT32 w8 = cmd_data[fifo_index + 7];
|
1930 | | |
1931 | | INT32 yl = (w1 & 0x3fff);
|
1932 | | INT32 ym = ((w2 >> 16) & 0x3fff);
|
1933 | | INT32 yh = ((w2 >> 0) & 0x3fff);
|
1934 | | INT32 xl = (INT32)(w3 & 0x3fffffff);
|
1935 | | INT32 xh = (INT32)(w5 & 0x3fffffff);
|
1936 | | INT32 xm = (INT32)(w7 & 0x3fffffff);
|
1937 | | // Inverse slopes in 16.16 format
|
1938 | | INT32 dxldy = (INT32)(w4);
|
1939 | | INT32 dxhdy = (INT32)(w6);
|
1940 | | INT32 dxmdy = (INT32)(w8);
|
1941 | | |
1942 | | if (yl & 0x2000) yl |= 0xffffc000;
|
1943 | | if (ym & 0x2000) ym |= 0xffffc000;
|
1944 | | if (yh & 0x2000) yh |= 0xffffc000;
|
1945 | | |
1946 | | if (xl & 0x20000000) xl |= 0xc0000000;
|
1947 | | if (xm & 0x20000000) xm |= 0xc0000000;
|
1948 | | if (xh & 0x20000000) xh |= 0xc0000000;
|
1949 | | |
1950 | | int r = (cmd_data[shade_base+0 ] & 0xffff0000) | ((cmd_data[shade_base+4 ] >> 16) & 0x0000ffff);
|
1951 | | int g = ((cmd_data[shade_base+0 ] << 16) & 0xffff0000) | (cmd_data[shade_base+4 ] & 0x0000ffff);
|
1952 | | int b = (cmd_data[shade_base+1 ] & 0xffff0000) | ((cmd_data[shade_base+5 ] >> 16) & 0x0000ffff);
|
1953 | | int a = ((cmd_data[shade_base+1 ] << 16) & 0xffff0000) | (cmd_data[shade_base+5 ] & 0x0000ffff);
|
1954 | | int drdx = (cmd_data[shade_base+2 ] & 0xffff0000) | ((cmd_data[shade_base+6 ] >> 16) & 0x0000ffff);
|
1955 | | int dgdx = ((cmd_data[shade_base+2 ] << 16) & 0xffff0000) | (cmd_data[shade_base+6 ] & 0x0000ffff);
|
1956 | | int dbdx = (cmd_data[shade_base+3 ] & 0xffff0000) | ((cmd_data[shade_base+7 ] >> 16) & 0x0000ffff);
|
1957 | | int dadx = ((cmd_data[shade_base+3 ] << 16) & 0xffff0000) | (cmd_data[shade_base+7 ] & 0x0000ffff);
|
1958 | | int drde = (cmd_data[shade_base+8 ] & 0xffff0000) | ((cmd_data[shade_base+12] >> 16) & 0x0000ffff);
|
1959 | | int dgde = ((cmd_data[shade_base+8 ] << 16) & 0xffff0000) | (cmd_data[shade_base+12] & 0x0000ffff);
|
1960 | | int dbde = (cmd_data[shade_base+9 ] & 0xffff0000) | ((cmd_data[shade_base+13] >> 16) & 0x0000ffff);
|
1961 | | int dade = ((cmd_data[shade_base+9 ] << 16) & 0xffff0000) | (cmd_data[shade_base+13] & 0x0000ffff);
|
1962 | | int drdy = (cmd_data[shade_base+10] & 0xffff0000) | ((cmd_data[shade_base+14] >> 16) & 0x0000ffff);
|
1963 | | int dgdy = ((cmd_data[shade_base+10] << 16) & 0xffff0000) | (cmd_data[shade_base+14] & 0x0000ffff);
|
1964 | | int dbdy = (cmd_data[shade_base+11] & 0xffff0000) | ((cmd_data[shade_base+15] >> 16) & 0x0000ffff);
|
1965 | | int dady = ((cmd_data[shade_base+11] << 16) & 0xffff0000) | (cmd_data[shade_base+15] & 0x0000ffff);
|
1966 | | int s = (cmd_data[texture_base+0 ] & 0xffff0000) | ((cmd_data[texture_base+4 ] >> 16) & 0x0000ffff);
|
1967 | | int t = ((cmd_data[texture_base+0 ] << 16) & 0xffff0000) | (cmd_data[texture_base+4 ] & 0x0000ffff);
|
1968 | | int w = (cmd_data[texture_base+1 ] & 0xffff0000) | ((cmd_data[texture_base+5 ] >> 16) & 0x0000ffff);
|
1969 | | int dsdx = (cmd_data[texture_base+2 ] & 0xffff0000) | ((cmd_data[texture_base+6 ] >> 16) & 0x0000ffff);
|
1970 | | int dtdx = ((cmd_data[texture_base+2 ] << 16) & 0xffff0000) | (cmd_data[texture_base+6 ] & 0x0000ffff);
|
1971 | | int dwdx = (cmd_data[texture_base+3 ] & 0xffff0000) | ((cmd_data[texture_base+7 ] >> 16) & 0x0000ffff);
|
1972 | | int dsde = (cmd_data[texture_base+8 ] & 0xffff0000) | ((cmd_data[texture_base+12] >> 16) & 0x0000ffff);
|
1973 | | int dtde = ((cmd_data[texture_base+8 ] << 16) & 0xffff0000) | (cmd_data[texture_base+12] & 0x0000ffff);
|
1974 | | int dwde = (cmd_data[texture_base+9 ] & 0xffff0000) | ((cmd_data[texture_base+13] >> 16) & 0x0000ffff);
|
1975 | | int dsdy = (cmd_data[texture_base+10] & 0xffff0000) | ((cmd_data[texture_base+14] >> 16) & 0x0000ffff);
|
1976 | | int dtdy = ((cmd_data[texture_base+10] << 16) & 0xffff0000) | (cmd_data[texture_base+14] & 0x0000ffff);
|
1977 | | int dwdy = (cmd_data[texture_base+11] & 0xffff0000) | ((cmd_data[texture_base+15] >> 16) & 0x0000ffff);
|
1978 | | int z = cmd_data[zbuffer_base+0];
|
1979 | | int dzdx = cmd_data[zbuffer_base+1];
|
1980 | | int dzde = cmd_data[zbuffer_base+2];
|
1981 | | int dzdy = cmd_data[zbuffer_base+3];
|
1982 | | |
1983 | | int dzdy_dz = (dzdy >> 16) & 0xffff;
|
1984 | | int dzdx_dz = (dzdx >> 16) & 0xffff;
|
1985 | | |
1986 | | extent_t Spans[2048];
|
1987 | | |
1988 | | SpanBase.m_span_drdy = drdy;
|
1989 | | SpanBase.m_span_dgdy = dgdy;
|
1990 | | SpanBase.m_span_dbdy = dbdy;
|
1991 | | SpanBase.m_span_dady = dady;
|
1992 | | SpanBase.m_span_dzdy = OtherModes.z_source_sel ? 0 : dzdy;
|
1993 | | |
1994 | | UINT32 temp_dzpix = ((dzdy_dz & 0x8000) ? ((~dzdy_dz) & 0x7fff) : dzdy_dz) + ((dzdx_dz & 0x8000) ? ((~dzdx_dz) & 0x7fff) : dzdx_dz);
|
1995 | | SpanBase.m_span_dr = drdx & ~0x1f;
|
1996 | | SpanBase.m_span_dg = dgdx & ~0x1f;
|
1997 | | SpanBase.m_span_db = dbdx & ~0x1f;
|
1998 | | SpanBase.m_span_da = dadx & ~0x1f;
|
1999 | | SpanBase.m_span_ds = dsdx;
|
2000 | | SpanBase.m_span_dt = dtdx;
|
2001 | | SpanBase.m_span_dw = dwdx;
|
2002 | | SpanBase.m_span_dz = OtherModes.z_source_sel ? 0 : dzdx;
|
2003 | | SpanBase.m_span_dymax = 0;
|
2004 | | SpanBase.m_span_dzpix = NormalizeDZPix(temp_dzpix & 0xffff) & 0xffff;
|
2005 | | |
2006 | | int xleft_inc = (dxmdy >> 2) & ~1;
|
2007 | | int xright_inc = (dxhdy >> 2) & ~1;
|
2008 | | |
2009 | | int xright = xh & ~1;
|
2010 | | int xleft = xm & ~1;
|
2011 | | |
2012 | | int sign_dxhdy = (dxhdy & 0x80000000) ? 1 : 0;
|
2013 | | int do_offset = !(sign_dxhdy ^ (flip));
|
2014 | | |
2015 | | if (do_offset)
|
2016 | | {
|
2017 | | dsdeh = dsde >> 9; dsdyh = dsdy >> 9;
|
2018 | | dtdeh = dtde >> 9; dtdyh = dtdy >> 9;
|
2019 | | dwdeh = dwde >> 9; dwdyh = dwdy >> 9;
|
2020 | | drdeh = drde >> 9; drdyh = drdy >> 9;
|
2021 | | dgdeh = dgde >> 9; dgdyh = dgdy >> 9;
|
2022 | | dbdeh = dbde >> 9; dbdyh = dbdy >> 9;
|
2023 | | dadeh = dade >> 9; dadyh = dady >> 9;
|
2024 | | dzdeh = dzde >> 9; dzdyh = dzdy >> 9;
|
2025 | | |
2026 | | dsdiff = (dsdeh << 8) + (dsdeh << 7) - (dsdyh << 8) - (dsdyh << 7);
|
2027 | | dtdiff = (dtdeh << 8) + (dtdeh << 7) - (dtdyh << 8) - (dtdyh << 7);
|
2028 | | dwdiff = (dwdeh << 8) + (dwdeh << 7) - (dwdyh << 8) - (dwdyh << 7);
|
2029 | | drdiff = (drdeh << 8) + (drdeh << 7) - (drdyh << 8) - (drdyh << 7);
|
2030 | | dgdiff = (dgdeh << 8) + (dgdeh << 7) - (dgdyh << 8) - (dgdyh << 7);
|
2031 | | dbdiff = (dbdeh << 8) + (dbdeh << 7) - (dbdyh << 8) - (dbdyh << 7);
|
2032 | | dadiff = (dadeh << 8) + (dadeh << 7) - (dadyh << 8) - (dadyh << 7);
|
2033 | | dzdiff = (dzdeh << 8) + (dzdeh << 7) - (dzdyh << 8) - (dzdyh << 7);
|
2034 | | }
|
2035 | | else
|
2036 | | {
|
2037 | | dsdiff = dtdiff = dwdiff = drdiff = dgdiff = dbdiff = dadiff = dzdiff = 0;
|
2038 | | }
|
2039 | | |
2040 | | dsdxh = dsdx >> 8;
|
2041 | | dtdxh = dtdx >> 8;
|
2042 | | dwdxh = dwdx >> 8;
|
2043 | | drdxh = drdx >> 8;
|
2044 | | dgdxh = dgdx >> 8;
|
2045 | | dbdxh = dbdx >> 8;
|
2046 | | dadxh = dadx >> 8;
|
2047 | | dzdxh = dzdx >> 8;
|
2048 | | |
2049 | | INT32 ycur = yh & ~3;
|
2050 | | INT32 ylfar = yl | 3;
|
2051 | | INT32 ldflag = (sign_dxhdy ^ flip) ? 0 : 3;
|
2052 | | INT32 majorx[4];
|
2053 | | INT32 minorx[4];
|
2054 | | INT32 majorxint[4];
|
2055 | | INT32 minorxint[4];
|
2056 | | bool valid_y = true;
|
2057 | | |
2058 | | int xfrac = ((xright >> 8) & 0xff);
|
2059 | | |
2060 | | int clipy1 = Scissor.m_yh;
|
2061 | | int clipy2 = Scissor.m_yl;
|
2062 | | |
2063 | | // Trivial reject
|
2064 | | if((ycur >> 2) >= clipy2 && (ylfar >> 2) >= clipy2)
|
2065 | | {
|
2066 | | return;
|
2067 | | }
|
2068 | | if((ycur >> 2) < clipy1 && (ylfar >> 2) < clipy1)
|
2069 | | {
|
2070 | | return;
|
2071 | | }
|
2072 | | |
2073 | | bool new_object = true;
|
2074 | | rdp_poly_state *object = NULL;
|
2075 | | bool valid = false;
|
2076 | | |
2077 | | if(flip)
|
2078 | | {
|
2079 | | for (int k = ycur; k <= ylfar; k++)
|
2080 | | {
|
2081 | | if (k == ym)
|
2082 | | {
|
2083 | | xleft = xl & ~1;
|
2084 | | xleft_inc = (dxldy >> 2) & ~1;
|
2085 | | }
|
2086 | | |
2087 | | int xstart = xleft >> 16; // 319
|
2088 | | int xend = xright >> 16; // 0
|
2089 | | int j = k >> 2;
|
2090 | | int spanidx = (k - ycur) >> 2;
|
2091 | | int spix = k & 3;
|
2092 | | valid_y = !(k < yh || k >= yl);
|
2093 | | |
2094 | | if (spanidx >= 0 && spanidx < 2048)
|
2095 | | {
|
2096 | | majorxint[spix] = xend; // 0
|
2097 | | minorxint[spix] = xstart; // 319
|
2098 | | majorx[spix] = xright; // 0x00000000
|
2099 | | minorx[spix] = xleft; // 0x013f0000
|
2100 | | |
2101 | | if (spix == 0)
|
2102 | | {
|
2103 | | maxxmx = 0;
|
2104 | | minxhx = 0xfff;
|
2105 | | }
|
2106 | | |
2107 | | if (valid_y)
|
2108 | | {
|
2109 | | maxxmx = (xstart > maxxmx) ? xstart : maxxmx;
|
2110 | | minxhx = (xend < minxhx) ? xend : minxhx;
|
2111 | | }
|
2112 | | |
2113 | | if (spix == 0)
|
2114 | | {
|
2115 | | if(new_object)
|
2116 | | {
|
2117 | | object = &object_data_alloc();
|
2118 | | memcpy(object->m_tmem, m_tmem, 0x1000);
|
2119 | | new_object = false;
|
2120 | | }
|
2121 | | |
2122 | | Spans[spanidx].userdata = (void*)((UINT8*)AuxBuf + AuxBufPtr);
|
2123 | | AuxBufPtr += sizeof(rdp_span_aux);
|
2124 | | |
2125 | | if(AuxBufPtr >= EXTENT_AUX_COUNT)
|
2126 | | {
|
2127 | | fatalerror("n64_rdp::DrawTriangle: span aux buffer overflow\n");
|
2128 | | }
|
2129 | | |
2130 | | rdp_span_aux *userdata = (rdp_span_aux*)Spans[spanidx].userdata;
|
2131 | | valid = true;
|
2132 | | |
2133 | | userdata->m_tmem = object->m_tmem;
|
2134 | | |
2135 | | userdata->BlendColor = BlendColor;
|
2136 | | userdata->PrimColor = PrimColor;
|
2137 | | userdata->EnvColor = EnvColor;
|
2138 | | userdata->FogColor = FogColor;
|
2139 | | userdata->KeyScale = KeyScale;
|
2140 | | userdata->LODFraction = LODFraction;
|
2141 | | userdata->PrimLODFraction = PrimLODFraction;
|
2142 | | |
2143 | | userdata->ColorInputs.combiner_rgbsub_a_r[0] = userdata->ColorInputs.combiner_rgbsub_a_r[1] = &OneColor.i.r;
|
2144 | | userdata->ColorInputs.combiner_rgbsub_a_g[0] = userdata->ColorInputs.combiner_rgbsub_a_g[1] = &OneColor.i.g;
|
2145 | | userdata->ColorInputs.combiner_rgbsub_a_b[0] = userdata->ColorInputs.combiner_rgbsub_a_b[1] = &OneColor.i.b;
|
2146 | | userdata->ColorInputs.combiner_rgbsub_b_r[0] = userdata->ColorInputs.combiner_rgbsub_b_r[1] = &OneColor.i.r;
|
2147 | | userdata->ColorInputs.combiner_rgbsub_b_g[0] = userdata->ColorInputs.combiner_rgbsub_b_g[1] = &OneColor.i.g;
|
2148 | | userdata->ColorInputs.combiner_rgbsub_b_b[0] = userdata->ColorInputs.combiner_rgbsub_b_b[1] = &OneColor.i.b;
|
2149 | | userdata->ColorInputs.combiner_rgbmul_r[0] = userdata->ColorInputs.combiner_rgbmul_r[1] = &OneColor.i.r;
|
2150 | | userdata->ColorInputs.combiner_rgbmul_g[0] = userdata->ColorInputs.combiner_rgbmul_g[1] = &OneColor.i.g;
|
2151 | | userdata->ColorInputs.combiner_rgbmul_b[0] = userdata->ColorInputs.combiner_rgbmul_b[1] = &OneColor.i.b;
|
2152 | | userdata->ColorInputs.combiner_rgbadd_r[0] = userdata->ColorInputs.combiner_rgbadd_r[1] = &OneColor.i.r;
|
2153 | | userdata->ColorInputs.combiner_rgbadd_g[0] = userdata->ColorInputs.combiner_rgbadd_g[1] = &OneColor.i.g;
|
2154 | | userdata->ColorInputs.combiner_rgbadd_b[0] = userdata->ColorInputs.combiner_rgbadd_b[1] = &OneColor.i.b;
|
2155 | | userdata->ColorInputs.combiner_alphasub_a[0] = userdata->ColorInputs.combiner_alphasub_a[1] = &OneColor.i.a;
|
2156 | | userdata->ColorInputs.combiner_alphasub_b[0] = userdata->ColorInputs.combiner_alphasub_b[1] = &OneColor.i.a;
|
2157 | | userdata->ColorInputs.combiner_alphamul[0] = userdata->ColorInputs.combiner_alphamul[1] = &OneColor.i.a;
|
2158 | | userdata->ColorInputs.combiner_alphaadd[0] = userdata->ColorInputs.combiner_alphaadd[1] = &OneColor.i.a;
|
2159 | | |
2160 | | userdata->ColorInputs.blender1a_r[0] = userdata->ColorInputs.blender1a_r[1] = &userdata->PixelColor.i.r;
|
2161 | | userdata->ColorInputs.blender1a_g[0] = userdata->ColorInputs.blender1a_g[1] = &userdata->PixelColor.i.g;
|
2162 | | userdata->ColorInputs.blender1a_b[0] = userdata->ColorInputs.blender1a_b[1] = &userdata->PixelColor.i.b;
|
2163 | | userdata->ColorInputs.blender1b_a[0] = userdata->ColorInputs.blender1b_a[1] = &userdata->PixelColor.i.a;
|
2164 | | userdata->ColorInputs.blender2a_r[0] = userdata->ColorInputs.blender2a_r[1] = &userdata->PixelColor.i.r;
|
2165 | | userdata->ColorInputs.blender2a_g[0] = userdata->ColorInputs.blender2a_g[1] = &userdata->PixelColor.i.g;
|
2166 | | userdata->ColorInputs.blender2a_b[0] = userdata->ColorInputs.blender2a_b[1] = &userdata->PixelColor.i.b;
|
2167 | | userdata->ColorInputs.blender2b_a[0] = userdata->ColorInputs.blender2b_a[1] = &userdata->PixelColor.i.a;
|
2168 | | |
2169 | | // Setup blender data for this scanline
|
2170 | | SetBlenderInput(0, 0, &userdata->ColorInputs.blender1a_r[0],
|
2171 | | &userdata->ColorInputs.blender1a_g[0],
|
2172 | | &userdata->ColorInputs.blender1a_b[0],
|
2173 | | &userdata->ColorInputs.blender1b_a[0], OtherModes.blend_m1a_0, OtherModes.blend_m1b_0, userdata);
|
2174 | | SetBlenderInput(0, 1, &userdata->ColorInputs.blender2a_r[0],
|
2175 | | &userdata->ColorInputs.blender2a_g[0],
|
2176 | | &userdata->ColorInputs.blender2a_b[0],
|
2177 | | &userdata->ColorInputs.blender2b_a[0], OtherModes.blend_m2a_0, OtherModes.blend_m2b_0, userdata);
|
2178 | | SetBlenderInput(1, 0, &userdata->ColorInputs.blender1a_r[1],
|
2179 | | &userdata->ColorInputs.blender1a_g[1],
|
2180 | | &userdata->ColorInputs.blender1a_b[1],
|
2181 | | &userdata->ColorInputs.blender1b_a[1], OtherModes.blend_m1a_1, OtherModes.blend_m1b_1, userdata);
|
2182 | | SetBlenderInput(1, 1, &userdata->ColorInputs.blender2a_r[1],
|
2183 | | &userdata->ColorInputs.blender2a_g[1],
|
2184 | | &userdata->ColorInputs.blender2a_b[1],
|
2185 | | &userdata->ColorInputs.blender2b_a[1], OtherModes.blend_m2a_1, OtherModes.blend_m2b_1, userdata);
|
2186 | | |
2187 | | // Setup color combiner data for this scanline
|
2188 | | SetSubAInputRGB(&userdata->ColorInputs.combiner_rgbsub_a_r[0], &userdata->ColorInputs.combiner_rgbsub_a_g[0], &userdata->ColorInputs.combiner_rgbsub_a_b[0], m_combine.sub_a_rgb0, userdata);
|
2189 | | SetSubBInputRGB(&userdata->ColorInputs.combiner_rgbsub_b_r[0], &userdata->ColorInputs.combiner_rgbsub_b_g[0], &userdata->ColorInputs.combiner_rgbsub_b_b[0], m_combine.sub_b_rgb0, userdata);
|
2190 | | SetMulInputRGB(&userdata->ColorInputs.combiner_rgbmul_r[0], &userdata->ColorInputs.combiner_rgbmul_g[0], &userdata->ColorInputs.combiner_rgbmul_b[0], m_combine.mul_rgb0, userdata);
|
2191 | | SetAddInputRGB(&userdata->ColorInputs.combiner_rgbadd_r[0], &userdata->ColorInputs.combiner_rgbadd_g[0], &userdata->ColorInputs.combiner_rgbadd_b[0], m_combine.add_rgb0, userdata);
|
2192 | | SetSubInputAlpha(&userdata->ColorInputs.combiner_alphasub_a[0], m_combine.sub_a_a0, userdata);
|
2193 | | SetSubInputAlpha(&userdata->ColorInputs.combiner_alphasub_b[0], m_combine.sub_b_a0, userdata);
|
2194 | | SetMulInputAlpha(&userdata->ColorInputs.combiner_alphamul[0], m_combine.mul_a0, userdata);
|
2195 | | SetSubInputAlpha(&userdata->ColorInputs.combiner_alphaadd[0], m_combine.add_a0, userdata);
|
2196 | | |
2197 | | SetSubAInputRGB(&userdata->ColorInputs.combiner_rgbsub_a_r[1], &userdata->ColorInputs.combiner_rgbsub_a_g[1], &userdata->ColorInputs.combiner_rgbsub_a_b[1], m_combine.sub_a_rgb1, userdata);
|
2198 | | SetSubBInputRGB(&userdata->ColorInputs.combiner_rgbsub_b_r[1], &userdata->ColorInputs.combiner_rgbsub_b_g[1], &userdata->ColorInputs.combiner_rgbsub_b_b[1], m_combine.sub_b_rgb1, userdata);
|
2199 | | SetMulInputRGB(&userdata->ColorInputs.combiner_rgbmul_r[1], &userdata->ColorInputs.combiner_rgbmul_g[1], &userdata->ColorInputs.combiner_rgbmul_b[1], m_combine.mul_rgb1, userdata);
|
2200 | | SetAddInputRGB(&userdata->ColorInputs.combiner_rgbadd_r[1], &userdata->ColorInputs.combiner_rgbadd_g[1], &userdata->ColorInputs.combiner_rgbadd_b[1], m_combine.add_rgb1, userdata);
|
2201 | | SetSubInputAlpha(&userdata->ColorInputs.combiner_alphasub_a[1], m_combine.sub_a_a1, userdata);
|
2202 | | SetSubInputAlpha(&userdata->ColorInputs.combiner_alphasub_b[1], m_combine.sub_b_a1, userdata);
|
2203 | | SetMulInputAlpha(&userdata->ColorInputs.combiner_alphamul[1], m_combine.mul_a1, userdata);
|
2204 | | SetSubInputAlpha(&userdata->ColorInputs.combiner_alphaadd[1], m_combine.add_a1, userdata);
|
2205 | | }
|
2206 | | |
2207 | | if (spix == 3)
|
2208 | | {
|
2209 | | Spans[spanidx].startx = maxxmx;
|
2210 | | Spans[spanidx].stopx = minxhx;
|
2211 | | compute_cvg_flip(Spans, majorx, minorx, majorxint, minorxint, j, yh, yl, ycur >> 2);
|
2212 | | }
|
2213 | | |
2214 | | if (spix == ldflag)
|
2215 | | {
|
2216 | | ((rdp_span_aux*)Spans[spanidx].userdata)->m_unscissored_rx = xend;
|
2217 | | xfrac = ((xright >> 8) & 0xff);
|
2218 | | Spans[spanidx].param[SPAN_R].start = ((r >> 9) << 9) + drdiff - (xfrac * drdxh);
|
2219 | | Spans[spanidx].param[SPAN_G].start = ((g >> 9) << 9) + dgdiff - (xfrac * dgdxh);
|
2220 | | Spans[spanidx].param[SPAN_B].start = ((b >> 9) << 9) + dbdiff - (xfrac * dbdxh);
|
2221 | | Spans[spanidx].param[SPAN_A].start = ((a >> 9) << 9) + dadiff - (xfrac * dadxh);
|
2222 | | Spans[spanidx].param[SPAN_S].start = (((s >> 9) << 9) + dsdiff - (xfrac * dsdxh)) & ~0x1f;
|
2223 | | Spans[spanidx].param[SPAN_T].start = (((t >> 9) << 9) + dtdiff - (xfrac * dtdxh)) & ~0x1f;
|
2224 | | Spans[spanidx].param[SPAN_W].start = (((w >> 9) << 9) + dwdiff - (xfrac * dwdxh)) & ~0x1f;
|
2225 | | Spans[spanidx].param[SPAN_Z].start = ((z >> 9) << 9) + dzdiff - (xfrac * dzdxh);
|
2226 | | }
|
2227 | | }
|
2228 | | |
2229 | | if (spix == 3)
|
2230 | | {
|
2231 | | r += drde;
|
2232 | | g += dgde;
|
2233 | | b += dbde;
|
2234 | | a += dade;
|
2235 | | s += dsde;
|
2236 | | t += dtde;
|
2237 | | w += dwde;
|
2238 | | z += dzde;
|
2239 | | }
|
2240 | | |
2241 | | xleft += xleft_inc;
|
2242 | | xright += xright_inc;
|
2243 | | }
|
2244 | | }
|
2245 | | else
|
2246 | | {
|
2247 | | for (int k = ycur; k <= ylfar; k++)
|
2248 | | {
|
2249 | | if (k == ym)
|
2250 | | {
|
2251 | | xleft = xl & ~1;
|
2252 | | xleft_inc = (dxldy >> 2) & ~1;
|
2253 | | }
|
2254 | | |
2255 | | int xstart = xleft >> 16;
|
2256 | | int xend = xright >> 16;
|
2257 | | int j = k >> 2;
|
2258 | | int spanidx = j - (ycur >> 2);
|
2259 | | int spix = k & 3;
|
2260 | | valid_y = !(k < yh || k >= yl);
|
2261 | | |
2262 | | if (k >= 0 && k < 0x1000)
|
2263 | | {
|
2264 | | majorxint[spix] = xend;
|
2265 | | minorxint[spix] = xstart;
|
2266 | | majorx[spix] = xright;
|
2267 | | minorx[spix] = xleft;
|
2268 | | |
2269 | | if (spix == 0)
|
2270 | | {
|
2271 | | maxxhx = 0;
|
2272 | | minxmx = 0xfff;
|
2273 | | }
|
2274 | | |
2275 | | if (valid_y)
|
2276 | | {
|
2277 | | minxmx = (xstart < minxmx) ? xstart : minxmx;
|
2278 | | maxxhx = (xend > maxxhx) ? xend : maxxhx;
|
2279 | | }
|
2280 | | |
2281 | | if (spix == 0)
|
2282 | | {
|
2283 | | if(new_object)
|
2284 | | {
|
2285 | | object = &object_data_alloc();
|
2286 | | memcpy(object->m_tmem, m_tmem, 0x1000);
|
2287 | | new_object = false;
|
2288 | | }
|
2289 | | |
2290 | | Spans[spanidx].userdata = (void*)((UINT8*)AuxBuf + AuxBufPtr);
|
2291 | | valid = true;
|
2292 | | AuxBufPtr += sizeof(rdp_span_aux);
|
2293 | | |
2294 | | if(AuxBufPtr >= EXTENT_AUX_COUNT)
|
2295 | | {
|
2296 | | fatalerror("n64_rdp::DrawTriangle: span aux buffer overflow\n");
|
2297 | | }
|
2298 | | |
2299 | | rdp_span_aux *userdata = (rdp_span_aux*)Spans[spanidx].userdata;
|
2300 | | userdata->m_tmem = object->m_tmem;
|
2301 | | |
2302 | | userdata->BlendColor = BlendColor;
|
2303 | | userdata->PrimColor = PrimColor;
|
2304 | | userdata->EnvColor = EnvColor;
|
2305 | | userdata->FogColor = FogColor;
|
2306 | | userdata->KeyScale = KeyScale;
|
2307 | | userdata->LODFraction = LODFraction;
|
2308 | | userdata->PrimLODFraction = PrimLODFraction;
|
2309 | | |
2310 | | userdata->ColorInputs.combiner_rgbsub_a_r[0] = userdata->ColorInputs.combiner_rgbsub_a_r[1] = &OneColor.i.r;
|
2311 | | userdata->ColorInputs.combiner_rgbsub_a_g[0] = userdata->ColorInputs.combiner_rgbsub_a_g[1] = &OneColor.i.g;
|
2312 | | userdata->ColorInputs.combiner_rgbsub_a_b[0] = userdata->ColorInputs.combiner_rgbsub_a_b[1] = &OneColor.i.b;
|
2313 | | userdata->ColorInputs.combiner_rgbsub_b_r[0] = userdata->ColorInputs.combiner_rgbsub_b_r[1] = &OneColor.i.r;
|
2314 | | userdata->ColorInputs.combiner_rgbsub_b_g[0] = userdata->ColorInputs.combiner_rgbsub_b_g[1] = &OneColor.i.g;
|
2315 | | userdata->ColorInputs.combiner_rgbsub_b_b[0] = userdata->ColorInputs.combiner_rgbsub_b_b[1] = &OneColor.i.b;
|
2316 | | userdata->ColorInputs.combiner_rgbmul_r[0] = userdata->ColorInputs.combiner_rgbmul_r[1] = &OneColor.i.r;
|
2317 | | userdata->ColorInputs.combiner_rgbmul_g[0] = userdata->ColorInputs.combiner_rgbmul_g[1] = &OneColor.i.g;
|
2318 | | userdata->ColorInputs.combiner_rgbmul_b[0] = userdata->ColorInputs.combiner_rgbmul_b[1] = &OneColor.i.b;
|
2319 | | userdata->ColorInputs.combiner_rgbadd_r[0] = userdata->ColorInputs.combiner_rgbadd_r[1] = &OneColor.i.r;
|
2320 | | userdata->ColorInputs.combiner_rgbadd_g[0] = userdata->ColorInputs.combiner_rgbadd_g[1] = &OneColor.i.g;
|
2321 | | userdata->ColorInputs.combiner_rgbadd_b[0] = userdata->ColorInputs.combiner_rgbadd_b[1] = &OneColor.i.b;
|
2322 | | userdata->ColorInputs.combiner_alphasub_a[0] = userdata->ColorInputs.combiner_alphasub_a[1] = &OneColor.i.a;
|
2323 | | userdata->ColorInputs.combiner_alphasub_b[0] = userdata->ColorInputs.combiner_alphasub_b[1] = &OneColor.i.a;
|
2324 | | userdata->ColorInputs.combiner_alphamul[0] = userdata->ColorInputs.combiner_alphamul[1] = &OneColor.i.a;
|
2325 | | userdata->ColorInputs.combiner_alphaadd[0] = userdata->ColorInputs.combiner_alphaadd[1] = &OneColor.i.a;
|
2326 | | |
2327 | | userdata->ColorInputs.blender1a_r[0] = userdata->ColorInputs.blender1a_r[1] = &userdata->PixelColor.i.r;
|
2328 | | userdata->ColorInputs.blender1a_g[0] = userdata->ColorInputs.blender1a_g[1] = &userdata->PixelColor.i.g;
|
2329 | | userdata->ColorInputs.blender1a_b[0] = userdata->ColorInputs.blender1a_b[1] = &userdata->PixelColor.i.b;
|
2330 | | userdata->ColorInputs.blender1b_a[0] = userdata->ColorInputs.blender1b_a[1] = &userdata->PixelColor.i.a;
|
2331 | | userdata->ColorInputs.blender2a_r[0] = userdata->ColorInputs.blender2a_r[1] = &userdata->PixelColor.i.r;
|
2332 | | userdata->ColorInputs.blender2a_g[0] = userdata->ColorInputs.blender2a_g[1] = &userdata->PixelColor.i.g;
|
2333 | | userdata->ColorInputs.blender2a_b[0] = userdata->ColorInputs.blender2a_b[1] = &userdata->PixelColor.i.b;
|
2334 | | userdata->ColorInputs.blender2b_a[0] = userdata->ColorInputs.blender2b_a[1] = &userdata->PixelColor.i.a;
|
2335 | | |
2336 | | // Setup blender data for this scanline
|
2337 | | SetBlenderInput(0, 0, &userdata->ColorInputs.blender1a_r[0],
|
2338 | | &userdata->ColorInputs.blender1a_g[0],
|
2339 | | &userdata->ColorInputs.blender1a_b[0],
|
2340 | | &userdata->ColorInputs.blender1b_a[0], OtherModes.blend_m1a_0, OtherModes.blend_m1b_0, userdata);
|
2341 | | SetBlenderInput(0, 1, &userdata->ColorInputs.blender2a_r[0],
|
2342 | | &userdata->ColorInputs.blender2a_g[0],
|
2343 | | &userdata->ColorInputs.blender2a_b[0],
|
2344 | | &userdata->ColorInputs.blender2b_a[0], OtherModes.blend_m2a_0, OtherModes.blend_m2b_0, userdata);
|
2345 | | SetBlenderInput(1, 0, &userdata->ColorInputs.blender1a_r[1],
|
2346 | | &userdata->ColorInputs.blender1a_g[1],
|
2347 | | &userdata->ColorInputs.blender1a_b[1],
|
2348 | | &userdata->ColorInputs.blender1b_a[1], OtherModes.blend_m1a_1, OtherModes.blend_m1b_1, userdata);
|
2349 | | SetBlenderInput(1, 1, &userdata->ColorInputs.blender2a_r[1],
|
2350 | | &userdata->ColorInputs.blender2a_g[1],
|
2351 | | &userdata->ColorInputs.blender2a_b[1],
|
2352 | | &userdata->ColorInputs.blender2b_a[1], OtherModes.blend_m2a_1, OtherModes.blend_m2b_1, userdata);
|
2353 | | |
2354 | | // Setup color combiner data for this scanline
|
2355 | | SetSubAInputRGB(&userdata->ColorInputs.combiner_rgbsub_a_r[0], &userdata->ColorInputs.combiner_rgbsub_a_g[0], &userdata->ColorInputs.combiner_rgbsub_a_b[0], m_combine.sub_a_rgb0, userdata);
|
2356 | | SetSubBInputRGB(&userdata->ColorInputs.combiner_rgbsub_b_r[0], &userdata->ColorInputs.combiner_rgbsub_b_g[0], &userdata->ColorInputs.combiner_rgbsub_b_b[0], m_combine.sub_b_rgb0, userdata);
|
2357 | | SetMulInputRGB(&userdata->ColorInputs.combiner_rgbmul_r[0], &userdata->ColorInputs.combiner_rgbmul_g[0], &userdata->ColorInputs.combiner_rgbmul_b[0], m_combine.mul_rgb0, userdata);
|
2358 | | SetAddInputRGB(&userdata->ColorInputs.combiner_rgbadd_r[0], &userdata->ColorInputs.combiner_rgbadd_g[0], &userdata->ColorInputs.combiner_rgbadd_b[0], m_combine.add_rgb0, userdata);
|
2359 | | SetSubInputAlpha(&userdata->ColorInputs.combiner_alphasub_a[0], m_combine.sub_a_a0, userdata);
|
2360 | | SetSubInputAlpha(&userdata->ColorInputs.combiner_alphasub_b[0], m_combine.sub_b_a0, userdata);
|
2361 | | SetMulInputAlpha(&userdata->ColorInputs.combiner_alphamul[0], m_combine.mul_a0, userdata);
|
2362 | | SetSubInputAlpha(&userdata->ColorInputs.combiner_alphaadd[0], m_combine.add_a0, userdata);
|
2363 | | |
2364 | | SetSubAInputRGB(&userdata->ColorInputs.combiner_rgbsub_a_r[1], &userdata->ColorInputs.combiner_rgbsub_a_g[1], &userdata->ColorInputs.combiner_rgbsub_a_b[1], m_combine.sub_a_rgb1, userdata);
|
2365 | | SetSubBInputRGB(&userdata->ColorInputs.combiner_rgbsub_b_r[1], &userdata->ColorInputs.combiner_rgbsub_b_g[1], &userdata->ColorInputs.combiner_rgbsub_b_b[1], m_combine.sub_b_rgb1, userdata);
|
2366 | | SetMulInputRGB(&userdata->ColorInputs.combiner_rgbmul_r[1], &userdata->ColorInputs.combiner_rgbmul_g[1], &userdata->ColorInputs.combiner_rgbmul_b[1], m_combine.mul_rgb1, userdata);
|
2367 | | SetAddInputRGB(&userdata->ColorInputs.combiner_rgbadd_r[1], &userdata->ColorInputs.combiner_rgbadd_g[1], &userdata->ColorInputs.combiner_rgbadd_b[1], m_combine.add_rgb1, userdata);
|
2368 | | SetSubInputAlpha(&userdata->ColorInputs.combiner_alphasub_a[1], m_combine.sub_a_a1, userdata);
|
2369 | | SetSubInputAlpha(&userdata->ColorInputs.combiner_alphasub_b[1], m_combine.sub_b_a1, userdata);
|
2370 | | SetMulInputAlpha(&userdata->ColorInputs.combiner_alphamul[1], m_combine.mul_a1, userdata);
|
2371 | | SetSubInputAlpha(&userdata->ColorInputs.combiner_alphaadd[1], m_combine.add_a1, userdata);
|
2372 | | }
|
2373 | | |
2374 | | if (spix == 3)
|
2375 | | {
|
2376 | | Spans[spanidx].startx = minxmx;
|
2377 | | Spans[spanidx].stopx = maxxhx;
|
2378 | | compute_cvg_noflip(Spans, majorx, minorx, majorxint, minorxint, j, yh, yl, ycur >> 2);
|
2379 | | }
|
2380 | | |
2381 | | if (spix == ldflag)
|
2382 | | {
|
2383 | | ((rdp_span_aux*)Spans[spanidx].userdata)->m_unscissored_rx = xend;
|
2384 | | xfrac = ((xright >> 8) & 0xff);
|
2385 | | Spans[spanidx].param[SPAN_R].start = ((r >> 9) << 9) + drdiff - (xfrac * drdxh);
|
2386 | | Spans[spanidx].param[SPAN_G].start = ((g >> 9) << 9) + dgdiff - (xfrac * dgdxh);
|
2387 | | Spans[spanidx].param[SPAN_B].start = ((b >> 9) << 9) + dbdiff - (xfrac * dbdxh);
|
2388 | | Spans[spanidx].param[SPAN_A].start = ((a >> 9) << 9) + dadiff - (xfrac * dadxh);
|
2389 | | Spans[spanidx].param[SPAN_S].start = (((s >> 9) << 9) + dsdiff - (xfrac * dsdxh)) & ~0x1f;
|
2390 | | Spans[spanidx].param[SPAN_T].start = (((t >> 9) << 9) + dtdiff - (xfrac * dtdxh)) & ~0x1f;
|
2391 | | Spans[spanidx].param[SPAN_W].start = (((w >> 9) << 9) + dwdiff - (xfrac * dwdxh)) & ~0x1f;
|
2392 | | Spans[spanidx].param[SPAN_Z].start = ((z >> 9) << 9) + dzdiff - (xfrac * dzdxh);
|
2393 | | }
|
2394 | | }
|
2395 | | |
2396 | | if (spix == 3)
|
2397 | | {
|
2398 | | r += drde;
|
2399 | | g += dgde;
|
2400 | | b += dbde;
|
2401 | | a += dade;
|
2402 | | s += dsde;
|
2403 | | t += dtde;
|
2404 | | w += dwde;
|
2405 | | z += dzde;
|
2406 | | }
|
2407 | | xleft += xleft_inc;
|
2408 | | xright += xright_inc;
|
2409 | | }
|
2410 | | }
|
2411 | | |
2412 | | if(!new_object && valid)
|
2413 | | {
|
2414 | | RenderSpans(yh >> 2, yl >> 2, tilenum, flip ? true : false, Spans, rect, object);
|
2415 | | }
|
2416 | | |
2417 | | //wait("DrawTriangle");
|
2418 | | }
|
2419 | | |
2420 | | /*****************************************************************************/
|
2421 | | |
2422 | | ////////////////////////
|
2423 | | // FB ACCESSORS
|
2424 | | ////////////////////////
|
2425 | | void n64_rdp::_Write16Bit_Cvg0_Blend(UINT32 curpixel, UINT32 r, UINT32 g, UINT32 b, rdp_span_aux *userdata, const rdp_poly_state &object)
|
2426 | | {
|
2427 | | UINT32 fb = (object.MiscState.FBAddress >> 1) + curpixel;
|
2428 | | UINT32 hb = fb;
|
2429 | | |
2430 | | UINT16 finalcolor = ((r >> 3) << 11) | ((g >> 3) << 6) | ((b >> 3) << 1);
|
2431 | | UINT32 finalcvg = 0;
|
2432 | | |
2433 | | if (object.OtherModes.color_on_cvg && !userdata->PreWrap)
|
2434 | | {
|
2435 | | finalcolor = RREADIDX16(fb) & 0xfffe;
|
2436 | | CHECK16(fb);
|
2437 | | }
|
2438 | | |
2439 | | finalcvg = userdata->CurrentPixCvg + userdata->CurrentMemCvg;
|
2440 | | if (finalcvg & 8)
|
2441 | | {
|
2442 | | finalcvg = 7;
|
2443 | | }
|
2444 | | RWRITEIDX16(fb, finalcolor | ((finalcvg >> 2) & 1));
|
2445 | | HWRITEADDR8(hb, finalcvg & 3);
|
2446 | | }
|
2447 | | |
2448 | | void n64_rdp::_Write16Bit_Cvg0_NoBlend(UINT32 curpixel, UINT32 r, UINT32 g, UINT32 b, rdp_span_aux *userdata, const rdp_poly_state &object)
|
2449 | | {
|
2450 | | UINT32 fb = (object.MiscState.FBAddress >> 1) + curpixel;
|
2451 | | UINT32 hb = fb;
|
2452 | | |
2453 | | UINT16 finalcolor = ((r >> 3) << 11) | ((g >> 3) << 6) | ((b >> 3) << 1);
|
2454 | | UINT32 finalcvg = 0;
|
2455 | | |
2456 | | if (object.OtherModes.color_on_cvg && !userdata->PreWrap)
|
2457 | | {
|
2458 | | finalcolor = RREADIDX16(fb) & 0xfffe;
|
2459 | | CHECK16(fb);
|
2460 | | }
|
2461 | | |
2462 | | finalcvg = (userdata->CurrentPixCvg - 1) & 7;
|
2463 | | RWRITEIDX16(fb, finalcolor | ((finalcvg >> 2) & 1));
|
2464 | | HWRITEADDR8(hb, finalcvg & 3);
|
2465 | | }
|
2466 | | |
2467 | | void n64_rdp::_Write16Bit_Cvg1(UINT32 curpixel, UINT32 r, UINT32 g, UINT32 b, rdp_span_aux *userdata, const rdp_poly_state &object)
|
2468 | | {
|
2469 | | UINT32 fb = (object.MiscState.FBAddress >> 1) + curpixel;
|
2470 | | UINT32 hb = fb;
|
2471 | | |
2472 | | UINT16 finalcolor = ((r >> 3) << 11) | ((g >> 3) << 6) | ((b >> 3) << 1);
|
2473 | | UINT32 finalcvg = 0;
|
2474 | | |
2475 | | if (object.OtherModes.color_on_cvg && !userdata->PreWrap)
|
2476 | | {
|
2477 | | finalcolor = RREADIDX16(fb) & 0xfffe;
|
2478 | | CHECK16(fb);
|
2479 | | }
|
2480 | | |
2481 | | finalcvg = (userdata->CurrentPixCvg + userdata->CurrentMemCvg) & 7;
|
2482 | | RWRITEIDX16(fb, finalcolor | ((finalcvg >> 2) & 1));
|
2483 | | HWRITEADDR8(hb, finalcvg & 3);
|
2484 | | }
|
2485 | | |
2486 | | void n64_rdp::_Write16Bit_Cvg2(UINT32 curpixel, UINT32 r, UINT32 g, UINT32 b, rdp_span_aux *userdata, const rdp_poly_state &object)
|
2487 | | {
|
2488 | | UINT32 fb = (object.MiscState.FBAddress >> 1) + curpixel;
|
2489 | | UINT32 hb = fb;
|
2490 | | |
2491 | | UINT16 finalcolor = ((r >> 3) << 11) | ((g >> 3) << 6) | ((b >> 3) << 1);
|
2492 | | |
2493 | | if (object.OtherModes.color_on_cvg && !userdata->PreWrap)
|
2494 | | {
|
2495 | | finalcolor = RREADIDX16(fb) & 0xfffe;
|
2496 | | CHECK16(fb);
|
2497 | | }
|
2498 | | |
2499 | | RWRITEIDX16(fb, finalcolor | 1);
|
2500 | | HWRITEADDR8(hb, 3);
|
2501 | | }
|
2502 | | |
2503 | | void n64_rdp::_Write16Bit_Cvg3(UINT32 curpixel, UINT32 r, UINT32 g, UINT32 b, rdp_span_aux *userdata, const rdp_poly_state &object)
|
2504 | | {
|
2505 | | UINT32 fb = (object.MiscState.FBAddress >> 1) + curpixel;
|
2506 | | UINT32 hb = fb;
|
2507 | | |
2508 | | UINT16 finalcolor = ((r >> 3) << 11) | ((g >> 3) << 6) | ((b >> 3) << 1);
|
2509 | | |
2510 | | if (object.OtherModes.color_on_cvg && !userdata->PreWrap)
|
2511 | | {
|
2512 | | finalcolor = RREADIDX16(fb) & 0xfffe;
|
2513 | | CHECK16(fb);
|
2514 | | }
|
2515 | | |
2516 | | RWRITEIDX16(fb, finalcolor | ((userdata->CurrentMemCvg >> 2) & 1));
|
2517 | | HWRITEADDR8(hb, userdata->CurrentMemCvg & 3);
|
2518 | | }
|
2519 | | |
2520 | | void n64_rdp::_Write32Bit_Cvg0_Blend(UINT32 curpixel, UINT32 r, UINT32 g, UINT32 b, rdp_span_aux *userdata, const rdp_poly_state &object)
|
2521 | | {
|
2522 | | UINT32 fb = (object.MiscState.FBAddress >> 2) + curpixel;
|
2523 | | UINT32 finalcolor = (r << 24) | (g << 16) | (b << 8);//cvg as 3 MSBs of alpha channel;
|
2524 | | UINT32 finalcvg = 0;
|
2525 | | |
2526 | | if (object.OtherModes.color_on_cvg && !userdata->PreWrap)
|
2527 | | {
|
2528 | | finalcolor = RREADIDX32(fb) & 0xffffff00;
|
2529 | | CHECK32(fb);
|
2530 | | }
|
2531 | | |
2532 | | finalcvg = userdata->CurrentPixCvg + userdata->CurrentMemCvg;
|
2533 | | if (finalcvg & 8)
|
2534 | | {
|
2535 | | finalcvg = 7;
|
2536 | | }
|
2537 | | RWRITEIDX32(fb, finalcolor | (finalcvg << 5));
|
2538 | | }
|
2539 | | |
2540 | | void n64_rdp::_Write32Bit_Cvg0_NoBlend(UINT32 curpixel, UINT32 r, UINT32 g, UINT32 b, rdp_span_aux *userdata, const rdp_poly_state &object)
|
2541 | | {
|
2542 | | UINT32 fb = (object.MiscState.FBAddress >> 2) + curpixel;
|
2543 | | UINT32 finalcolor = (r << 24) | (g << 16) | (b << 8);//cvg as 3 MSBs of alpha channel;
|
2544 | | UINT32 finalcvg = 0;
|
2545 | | |
2546 | | if (object.OtherModes.color_on_cvg && !userdata->PreWrap)
|
2547 | | {
|
2548 | | finalcolor = RREADIDX32(fb) & 0xffffff00;
|
2549 | | CHECK32(fb);
|
2550 | | }
|
2551 | | |
2552 | | finalcvg = (userdata->CurrentPixCvg - 1) & 7;
|
2553 | | RWRITEIDX32(fb, finalcolor | (finalcvg << 5));
|
2554 | | }
|
2555 | | |
2556 | | void n64_rdp::_Write32Bit_Cvg1(UINT32 curpixel, UINT32 r, UINT32 g, UINT32 b, rdp_span_aux *userdata, const rdp_poly_state &object)
|
2557 | | {
|
2558 | | UINT32 fb = (object.MiscState.FBAddress >> 2) + curpixel;
|
2559 | | UINT32 finalcolor = (r << 24) | (g << 16) | (b << 8);//cvg as 3 MSBs of alpha channel;
|
2560 | | UINT32 finalcvg = 0;
|
2561 | | |
2562 | | if (object.OtherModes.color_on_cvg && !userdata->PreWrap)
|
2563 | | {
|
2564 | | finalcolor = RREADIDX32(fb) & 0xffffff00;
|
2565 | | CHECK32(fb);
|
2566 | | }
|
2567 | | |
2568 | | finalcvg = (userdata->CurrentPixCvg + userdata->CurrentMemCvg) & 7;
|
2569 | | finalcolor |= (finalcvg << 5);
|
2570 | | RWRITEIDX32(fb, finalcolor);
|
2571 | | }
|
2572 | | |
2573 | | void n64_rdp::_Write32Bit_Cvg2(UINT32 curpixel, UINT32 r, UINT32 g, UINT32 b, rdp_span_aux *userdata, const rdp_poly_state &object)
|
2574 | | {
|
2575 | | UINT32 fb = (object.MiscState.FBAddress >> 2) + curpixel;
|
2576 | | UINT32 finalcolor = (r << 24) | (g << 16) | (b << 8);//cvg as 3 MSBs of alpha channel;
|
2577 | | |
2578 | | if (object.OtherModes.color_on_cvg && !userdata->PreWrap)
|
2579 | | {
|
2580 | | finalcolor = RREADIDX32(fb) & 0xffffff00;
|
2581 | | CHECK32(fb);
|
2582 | | }
|
2583 | | |
2584 | | RWRITEIDX32(fb, finalcolor | 0xE0);
|
2585 | | }
|
2586 | | |
2587 | | void n64_rdp::_Write32Bit_Cvg3(UINT32 curpixel, UINT32 r, UINT32 g, UINT32 b, rdp_span_aux *userdata, const rdp_poly_state &object)
|
2588 | | {
|
2589 | | UINT32 fb = (object.MiscState.FBAddress >> 2) + curpixel;
|
2590 | | UINT32 finalcolor = (r << 24) | (g << 16) | (b << 8);//cvg as 3 MSBs of alpha channel;
|
2591 | | |
2592 | | if (object.OtherModes.color_on_cvg && !userdata->PreWrap)
|
2593 | | {
|
2594 | | finalcolor = RREADIDX32(fb) & 0xffffff00;
|
2595 | | CHECK32(fb);
|
2596 | | }
|
2597 | | |
2598 | | RWRITEIDX32(fb, finalcolor | (userdata->CurrentMemCvg << 5));
|
2599 | | }
|
2600 | | |
2601 | | |
2602 | | void n64_rdp::_Read16Bit_ImgRead0(UINT32 curpixel, rdp_span_aux *userdata, const rdp_poly_state &object)
|
2603 | | {
|
2604 | | UINT16 fword = RREADIDX16((object.MiscState.FBAddress >> 1) + curpixel);
|
2605 | | CHECK16((object.MiscState.FBAddress >> 1) + curpixel);
|
2606 | | userdata->MemoryColor.i.r = GETHICOL(fword);
|
2607 | | userdata->MemoryColor.i.g = GETMEDCOL(fword);
|
2608 | | userdata->MemoryColor.i.b = GETLOWCOL(fword);
|
2609 | | userdata->MemoryColor.i.a = 0xff;
|
2610 | | userdata->CurrentMemCvg = 7;
|
2611 | | }
|
2612 | | |
2613 | | void n64_rdp::_Read16Bit_ImgRead1(UINT32 curpixel, rdp_span_aux *userdata, const rdp_poly_state &object)
|
2614 | | {
|
2615 | | UINT16 fword = RREADIDX16((object.MiscState.FBAddress >> 1) + curpixel);
|
2616 | | CHECK16((object.MiscState.FBAddress >> 1) + curpixel);
|
2617 | | UINT8 hbyte = HREADADDR8((object.MiscState.FBAddress >> 1) + curpixel);
|
2618 | | userdata->MemoryColor.i.r = GETHICOL(fword);
|
2619 | | userdata->MemoryColor.i.g = GETMEDCOL(fword);
|
2620 | | userdata->MemoryColor.i.b = GETLOWCOL(fword);
|
2621 | | userdata->MemoryColor.i.a = userdata->CurrentMemCvg << 5;
|
2622 | | userdata->CurrentMemCvg = ((fword & 1) << 2) | (hbyte & 3);
|
2623 | | }
|
2624 | | |
2625 | | void n64_rdp::_Read32Bit_ImgRead0(UINT32 curpixel, rdp_span_aux *userdata, const rdp_poly_state &object)
|
2626 | | {
|
2627 | | UINT32 mem = RREADIDX32((object.MiscState.FBAddress >> 2) + curpixel);
|
2628 | | CHECK32((object.MiscState.FBAddress >> 2) + curpixel);
|
2629 | | userdata->MemoryColor.i.r = (mem >> 24) & 0xff;
|
2630 | | userdata->MemoryColor.i.g = (mem >> 16) & 0xff;
|
2631 | | userdata->MemoryColor.i.b = (mem >> 8) & 0xff;
|
2632 | | userdata->MemoryColor.i.a = 0xff;
|
2633 | | userdata->CurrentMemCvg = 7;
|
2634 | | }
|
2635 | | |
2636 | | void n64_rdp::_Read32Bit_ImgRead1(UINT32 curpixel, rdp_span_aux *userdata, const rdp_poly_state &object)
|
2637 | | {
|
2638 | | UINT32 mem = RREADIDX32((object.MiscState.FBAddress >> 2) + curpixel);
|
2639 | | CHECK32((object.MiscState.FBAddress >> 2) + curpixel);
|
2640 | | userdata->MemoryColor.i.r = (mem >> 24) & 0xff;
|
2641 | | userdata->MemoryColor.i.g = (mem >> 16) & 0xff;
|
2642 | | userdata->MemoryColor.i.b = (mem >> 8) & 0xff;
|
2643 | | userdata->MemoryColor.i.a = (mem) & 0xff;
|
2644 | | userdata->CurrentMemCvg = (mem >> 5) & 7;
|
2645 | | }
|
2646 | | |
2647 | | void n64_rdp::_Copy16Bit(UINT32 curpixel, UINT32 r, UINT32 g, UINT32 b, int CurrentPixCvg, const rdp_poly_state &object)
|
2648 | | {
|
2649 | | UINT16 val = ((r >> 3) << 11) | ((g >> 3) << 6) | ((b >> 3) << 1) | ((CurrentPixCvg >> 2) & 1);
|
2650 | | RWRITEIDX16((object.MiscState.FBAddress >> 1) + curpixel, val);
|
2651 | | HWRITEADDR8((object.MiscState.FBAddress >> 1) + curpixel, CurrentPixCvg & 3);
|
2652 | | CHECK16((object.MiscState.FBAddress >> 1) + curpixel);
|
2653 | | }
|
2654 | | |
2655 | | void n64_rdp::_Copy32Bit(UINT32 curpixel, UINT32 r, UINT32 g, UINT32 b, int CurrentPixCvg, const rdp_poly_state &object)
|
2656 | | {
|
2657 | | UINT32 val = (r << 24) | (g << 16) | (b << 8) | (CurrentPixCvg << 5);
|
2658 | | RWRITEIDX32((object.MiscState.FBAddress >> 2) + curpixel, val);
|
2659 | | CHECK32((object.MiscState.FBAddress >> 2) + curpixel);
|
2660 | | }
|
2661 | | |
2662 | | |
2663 | | void n64_rdp::_Fill16Bit(UINT32 curpixel, const rdp_poly_state &object)
|
2664 | | {
|
2665 | | UINT16 val;
|
2666 | | if (curpixel & 1)
|
2667 | | {
|
2668 | | val = object.FillColor & 0xffff;
|
2669 | | }
|
2670 | | else
|
2671 | | {
|
2672 | | val = (object.FillColor >> 16) & 0xffff;
|
2673 | | }
|
2674 | | RWRITEIDX16((object.MiscState.FBAddress >> 1) + curpixel, val);
|
2675 | | CHECK16((object.MiscState.FBAddress >> 1) + curpixel);
|
2676 | | HWRITEADDR8((object.MiscState.FBAddress >> 1) + curpixel, ((val & 1) << 1) | (val & 1));
|
2677 | | }
|
2678 | | |
2679 | | void n64_rdp::_Fill32Bit(UINT32 curpixel, const rdp_poly_state &object)
|
2680 | | {
|
2681 | | UINT32 FillColor = object.FillColor;
|
2682 | | RWRITEIDX32((object.MiscState.FBAddress >> 2) + curpixel, FillColor);
|
2683 | | CHECK32((object.MiscState.FBAddress >> 2) + curpixel);
|
2684 | | HWRITEADDR8((object.MiscState.FBAddress >> 1) + (curpixel << 1), (FillColor & 0x10000) ? 3 : 0);
|
2685 | | HWRITEADDR8((object.MiscState.FBAddress >> 1) + (curpixel << 1) + 1, (FillColor & 0x1) ? 3 : 0);
|
2686 | | }
|
2687 | | |
2688 | | ////////////////////////
|
2689 | | // RDP COMMANDS
|
2690 | | ////////////////////////
|
2691 | | void n64_rdp::Triangle(bool shade, bool texture, bool zbuffer)
|
2692 | | {
|
2693 | | DrawTriangle(shade, texture, zbuffer, false);
|
2694 | | m_pipe_clean = false;
|
2695 | | //wait();
|
2696 | | }
|
2697 | | |
2698 | | void n64_rdp::CmdTriangle(UINT32 w1, UINT32 w2)
|
2699 | | {
|
2700 | | Triangle(false, false, false);
|
2701 | | }
|
2702 | | |
2703 | | void n64_rdp::CmdTriangleZ(UINT32 w1, UINT32 w2)
|
2704 | | {
|
2705 | | Triangle(false, false, true);
|
2706 | | }
|
2707 | | |
2708 | | void n64_rdp::CmdTriangleT(UINT32 w1, UINT32 w2)
|
2709 | | {
|
2710 | | Triangle(false, true, false);
|
2711 | | }
|
2712 | | |
2713 | | void n64_rdp::CmdTriangleTZ(UINT32 w1, UINT32 w2)
|
2714 | | {
|
2715 | | Triangle(false, true, true);
|
2716 | | }
|
2717 | | |
2718 | | void n64_rdp::CmdTriangleS(UINT32 w1, UINT32 w2)
|
2719 | | {
|
2720 | | Triangle(true, false, false);
|
2721 | | }
|
2722 | | |
2723 | | void n64_rdp::CmdTriangleSZ(UINT32 w1, UINT32 w2)
|
2724 | | {
|
2725 | | Triangle(true, false, true);
|
2726 | | }
|
2727 | | |
2728 | | void n64_rdp::CmdTriangleST(UINT32 w1, UINT32 w2)
|
2729 | | {
|
2730 | | Triangle(true, true, false);
|
2731 | | }
|
2732 | | |
2733 | | void n64_rdp::CmdTriangleSTZ(UINT32 w1, UINT32 w2)
|
2734 | | {
|
2735 | | Triangle(true, true, true);
|
2736 | | }
|
2737 | | |
2738 | | void n64_rdp::CmdTexRect(UINT32 w1, UINT32 w2)
|
2739 | | {
|
2740 | | //if(m_pending_mode_block) { wait("Block on pending mode-change"); m_pending_mode_block = false; }
|
2741 | | |
2742 | | UINT32 *data = m_cmd_data + m_cmd_cur;
|
2743 | | |
2744 | | UINT32 w3 = data[2];
|
2745 | | UINT32 w4 = data[3];
|
2746 | | |
2747 | | UINT32 tilenum = (w2 >> 24) & 0x7;
|
2748 | | UINT32 xl = (w1 >> 12) & 0xfff;
|
2749 | | UINT32 yl = (w1 >> 0) & 0xfff;
|
2750 | | UINT32 xh = (w2 >> 12) & 0xfff;
|
2751 | | UINT32 yh = (w2 >> 0) & 0xfff;
|
2752 | | INT32 s = (w3 >> 16) & 0xffff;
|
2753 | | INT32 t = (w3 >> 0) & 0xffff;
|
2754 | | INT32 dsdx = (w4 >> 16) & 0xffff;
|
2755 | | INT32 dtdy = (w4 >> 0) & 0xffff;
|
2756 | | |
2757 | | dsdx = SIGN16(dsdx);
|
2758 | | dtdy = SIGN16(dtdy);
|
2759 | | |
2760 | | if (OtherModes.cycle_type == CYCLE_TYPE_FILL || OtherModes.cycle_type == CYCLE_TYPE_COPY)
|
2761 | | {
|
2762 | | yl |= 3;
|
2763 | | }
|
2764 | | |
2765 | | UINT32 xlint = (xl >> 2) & 0x3ff;
|
2766 | | UINT32 xhint = (xh >> 2) & 0x3ff;
|
2767 | | |
2768 | | UINT32* ewdata = m_temp_rect_data;
|
2769 | | ewdata[0] = (0x24 << 24) | ((0x80 | tilenum) << 16) | yl; // command, flipped, tile, yl
|
2770 | | ewdata[1] = (yl << 16) | yh; // ym, yh
|
2771 | | ewdata[2] = (xlint << 16) | ((xl & 3) << 14); // xl, xl frac
|
2772 | | ewdata[3] = 0; // dxldy, dxldy frac
|
2773 | | ewdata[4] = (xhint << 16) | ((xh & 3) << 14); // xh, xh frac
|
2774 | | ewdata[5] = 0; // dxhdy, dxhdy frac
|
2775 | | ewdata[6] = (xlint << 16) | ((xl & 3) << 14); // xm, xm frac
|
2776 | | ewdata[7] = 0; // dxmdy, dxmdy frac
|
2777 | | memset(&ewdata[8], 0, 16 * sizeof(UINT32)); // shade
|
2778 | | ewdata[24] = (s << 16) | t; // s, t
|
2779 | | ewdata[25] = 0; // w
|
2780 | | ewdata[26] = ((dsdx >> 5) << 16); // dsdx, dtdx
|
2781 | | ewdata[27] = 0; // dwdx
|
2782 | | ewdata[28] = 0; // s frac, t frac
|
2783 | | ewdata[29] = 0; // w frac
|
2784 | | ewdata[30] = ((dsdx & 0x1f) << 11) << 16; // dsdx frac, dtdx frac
|
2785 | | ewdata[31] = 0; // dwdx frac
|
2786 | | ewdata[32] = (dtdy >> 5) & 0xffff;//dsde, dtde
|
2787 | | ewdata[33] = 0;//dwde
|
2788 | | ewdata[34] = (dtdy >> 5) & 0xffff;//dsdy, dtdy
|
2789 | | ewdata[35] = 0;//dwdy
|
2790 | | ewdata[36] = (dtdy & 0x1f) << 11;//dsde frac, dtde frac
|
2791 | | ewdata[37] = 0;//dwde frac
|
2792 | | ewdata[38] = (dtdy & 0x1f) << 11;//dsdy frac, dtdy frac
|
2793 | | ewdata[39] = 0;//dwdy frac
|
2794 | | memset(&ewdata[40], 0, 4 * sizeof(UINT32));//depth
|
2795 | | |
2796 | | DrawTriangle(true, true, false, true);
|
2797 | | }
|
2798 | | |
2799 | | void n64_rdp::CmdTexRectFlip(UINT32 w1, UINT32 w2)
|
2800 | | {
|
2801 | | //if(m_pending_mode_block) { wait("Block on pending mode-change"); m_pending_mode_block = false; }
|
2802 | | |
2803 | | UINT32 *data = m_cmd_data + m_cmd_cur;
|
2804 | | |
2805 | | UINT32 w3 = data[2];
|
2806 | | UINT32 w4 = data[3];
|
2807 | | |
2808 | | UINT32 tilenum = (w2 >> 24) & 0x7;
|
2809 | | UINT32 xl = (w1 >> 12) & 0xfff;
|
2810 | | UINT32 yl = (w1 >> 0) & 0xfff;
|
2811 | | UINT32 xh = (w2 >> 12) & 0xfff;
|
2812 | | UINT32 yh = (w2 >> 0) & 0xfff;
|
2813 | | INT32 s = (w3 >> 16) & 0xffff;
|
2814 | | INT32 t = (w3 >> 0) & 0xffff;
|
2815 | | INT32 dsdx = (w4 >> 16) & 0xffff;
|
2816 | | INT32 dtdy = (w4 >> 0) & 0xffff;
|
2817 | | |
2818 | | dsdx = SIGN16(dsdx);
|
2819 | | dtdy = SIGN16(dtdy);
|
2820 | | |
2821 | | if (OtherModes.cycle_type == CYCLE_TYPE_FILL || OtherModes.cycle_type == CYCLE_TYPE_COPY)
|
2822 | | {
|
2823 | | yl |= 3;
|
2824 | | }
|
2825 | | |
2826 | | UINT32 xlint = (xl >> 2) & 0x3ff;
|
2827 | | UINT32 xhint = (xh >> 2) & 0x3ff;
|
2828 | | |
2829 | | UINT32* ewdata = m_temp_rect_data;
|
2830 | | ewdata[0] = (0x25 << 24) | ((0x80 | tilenum) << 16) | yl;//command, flipped, tile, yl
|
2831 | | ewdata[1] = (yl << 16) | yh;//ym, yh
|
2832 | | ewdata[2] = (xlint << 16) | ((xl & 3) << 14);//xl, xl frac
|
2833 | | ewdata[3] = 0;//dxldy, dxldy frac
|
2834 | | ewdata[4] = (xhint << 16) | ((xh & 3) << 14);//xh, xh frac
|
2835 | | ewdata[5] = 0;//dxhdy, dxhdy frac
|
2836 | | ewdata[6] = (xlint << 16) | ((xl & 3) << 14);//xm, xm frac
|
2837 | | ewdata[7] = 0;//dxmdy, dxmdy frac
|
2838 | | memset(&ewdata[8], 0, 16 * sizeof(UINT32));//shade
|
2839 | | ewdata[24] = (s << 16) | t;//s, t
|
2840 | | ewdata[25] = 0;//w
|
2841 | | ewdata[26] = (dtdy >> 5) & 0xffff;//dsdx, dtdx
|
2842 | | ewdata[27] = 0;//dwdx
|
2843 | | ewdata[28] = 0;//s frac, t frac
|
2844 | | ewdata[29] = 0;//w frac
|
2845 | | ewdata[30] = ((dtdy & 0x1f) << 11);//dsdx frac, dtdx frac
|
2846 | | ewdata[31] = 0;//dwdx frac
|
2847 | | ewdata[32] = (dsdx >> 5) << 16;//dsde, dtde
|
2848 | | ewdata[33] = 0;//dwde
|
2849 | | ewdata[34] = (dsdx >> 5) << 16;//dsdy, dtdy
|
2850 | | ewdata[35] = 0;//dwdy
|
2851 | | ewdata[36] = (dsdx & 0x1f) << 27;//dsde frac, dtde frac
|
2852 | | ewdata[37] = 0;//dwde frac
|
2853 | | ewdata[38] = (dsdx & 0x1f) << 27;//dsdy frac, dtdy frac
|
2854 | | ewdata[39] = 0;//dwdy frac
|
2855 | | memset(&ewdata[40], 0, 4 * sizeof(UINT32));//depth
|
2856 | | |
2857 | | DrawTriangle(true, true, false, true);
|
2858 | | }
|
2859 | | |
2860 | | void n64_rdp::CmdSyncLoad(UINT32 w1, UINT32 w2)
|
2861 | | {
|
2862 | | //wait("SyncLoad");
|
2863 | | }
|
2864 | | |
2865 | | void n64_rdp::CmdSyncPipe(UINT32 w1, UINT32 w2)
|
2866 | | {
|
2867 | | //wait("SyncPipe");
|
2868 | | }
|
2869 | | |
2870 | | void n64_rdp::CmdSyncTile(UINT32 w1, UINT32 w2)
|
2871 | | {
|
2872 | | //wait("SyncTile");
|
2873 | | }
|
2874 | | |
2875 | | void n64_rdp::CmdSyncFull(UINT32 w1, UINT32 w2)
|
2876 | | {
|
2877 | | //wait("SyncFull");
|
2878 | | dp_full_sync(*m_machine);
|
2879 | | }
|
2880 | | |
2881 | | void n64_rdp::CmdSetKeyGB(UINT32 w1, UINT32 w2)
|
2882 | | {
|
2883 | | KeyScale.i.b = w2 & 0xff;
|
2884 | | KeyScale.i.g = (w2 >> 16) & 0xff;
|
2885 | | }
|
2886 | | |
2887 | | void n64_rdp::CmdSetKeyR(UINT32 w1, UINT32 w2)
|
2888 | | {
|
2889 | | KeyScale.i.r = w2 & 0xff;
|
2890 | | }
|
2891 | | |
2892 | | void n64_rdp::CmdSetFillColor32(UINT32 w1, UINT32 w2)
|
2893 | | {
|
2894 | | //wait("SetFillColor");
|
2895 | | FillColor = w2;
|
2896 | | }
|
2897 | | |
2898 | | void n64_rdp::CmdSetConvert(UINT32 w1, UINT32 w2)
|
2899 | | {
|
2900 | | if(!m_pipe_clean) { m_pipe_clean = true; wait("SetConvert"); }
|
2901 | | INT32 k0 = (w1 >> 13) & 0xff;
|
2902 | | INT32 k1 = (w1 >> 4) & 0xff;
|
2903 | | INT32 k2 = ((w1 & 7) << 5) | ((w2 >> 27) & 0x1f);
|
2904 | | INT32 k3 = (w2 >> 18) & 0xff;
|
2905 | | INT32 k4 = (w2 >> 9) & 0xff;
|
2906 | | INT32 k5 = w2 & 0xff;
|
2907 | | k0 = ((w1 >> 21) & 1) ? (-(0x100 - k0)) : k0;
|
2908 | | k1 = ((w1 >> 12) & 1) ? (-(0x100 - k1)) : k1;
|
2909 | | k2 = (w1 & 0xf) ? (-(0x100 - k2)) : k2;
|
2910 | | k3 = ((w2 >> 26) & 1) ? (-(0x100 - k3)) : k3;
|
2911 | | k4 = ((w2 >> 17) & 1) ? (-(0x100 - k4)) : k4;
|
2912 | | k5 = ((w2 >> 8) & 1) ? (-(0x100 - k5)) : k5;
|
2913 | | SetYUVFactors(k0, k1, k2, k3, k4, k5);
|
2914 | | }
|
2915 | | |
2916 | | void n64_rdp::CmdSetScissor(UINT32 w1, UINT32 w2)
|
2917 | | {
|
2918 | | Scissor.m_xh = ((w1 >> 12) & 0xfff) >> 2;
|
2919 | | Scissor.m_yh = ((w1 >> 0) & 0xfff) >> 2;
|
2920 | | Scissor.m_xl = ((w2 >> 12) & 0xfff) >> 2;
|
2921 | | Scissor.m_yl = ((w2 >> 0) & 0xfff) >> 2;
|
2922 | | |
2923 | | // TODO: handle f & o?
|
2924 | | }
|
2925 | | |
2926 | | void n64_rdp::CmdSetPrimDepth(UINT32 w1, UINT32 w2)
|
2927 | | {
|
2928 | | MiscState.PrimitiveZ = (UINT16)(w2 >> 16) & 0x7fff;
|
2929 | | MiscState.PrimitiveDZ = (UINT16)(w1);
|
2930 | | }
|
2931 | | |
2932 | | void n64_rdp::CmdSetOtherModes(UINT32 w1, UINT32 w2)
|
2933 | | {
|
2934 | | //wait("SetOtherModes");
|
2935 | | OtherModes.cycle_type = (w1 >> 20) & 0x3; // 01
|
2936 | | OtherModes.persp_tex_en = (w1 & 0x80000) ? 1 : 0; // 1
|
2937 | | OtherModes.detail_tex_en = (w1 & 0x40000) ? 1 : 0; // 0
|
2938 | | OtherModes.sharpen_tex_en = (w1 & 0x20000) ? 1 : 0; // 0
|
2939 | | OtherModes.tex_lod_en = (w1 & 0x10000) ? 1 : 0; // 0
|
2940 | | OtherModes.en_tlut = (w1 & 0x08000) ? 1 : 0; // 0
|
2941 | | OtherModes.tlut_type = (w1 & 0x04000) ? 1 : 0; // 0
|
2942 | | OtherModes.sample_type = (w1 & 0x02000) ? 1 : 0; // 1
|
2943 | | OtherModes.mid_texel = (w1 & 0x01000) ? 1 : 0; // 0
|
2944 | | OtherModes.bi_lerp0 = (w1 & 0x00800) ? 1 : 0; // 1
|
2945 | | OtherModes.bi_lerp1 = (w1 & 0x00400) ? 1 : 0; // 1
|
2946 | | OtherModes.convert_one = (w1 & 0x00200) ? 1 : 0; // 0
|
2947 | | OtherModes.key_en = (w1 & 0x00100) ? 1 : 0; // 0
|
2948 | | OtherModes.rgb_dither_sel = (w1 >> 6) & 0x3; // 00
|
2949 | | OtherModes.alpha_dither_sel = (w1 >> 4) & 0x3; // 01
|
2950 | | OtherModes.blend_m1a_0 = (w2 >> 30) & 0x3; // 11
|
2951 | | OtherModes.blend_m1a_1 = (w2 >> 28) & 0x3; // 00
|
2952 | | OtherModes.blend_m1b_0 = (w2 >> 26) & 0x3; // 10
|
2953 | | OtherModes.blend_m1b_1 = (w2 >> 24) & 0x3; // 00
|
2954 | | OtherModes.blend_m2a_0 = (w2 >> 22) & 0x3; // 00
|
2955 | | OtherModes.blend_m2a_1 = (w2 >> 20) & 0x3; // 01
|
2956 | | OtherModes.blend_m2b_0 = (w2 >> 18) & 0x3; // 00
|
2957 | | OtherModes.blend_m2b_1 = (w2 >> 16) & 0x3; // 01
|
2958 | | OtherModes.force_blend = (w2 >> 14) & 1; // 0
|
2959 | | OtherModes.alpha_cvg_select = (w2 >> 13) & 1; // 1
|
2960 | | OtherModes.cvg_times_alpha = (w2 >> 12) & 1; // 0
|
2961 | | OtherModes.z_mode = (w2 >> 10) & 0x3; // 00
|
2962 | | OtherModes.cvg_dest = (w2 >> 8) & 0x3; // 00
|
2963 | | OtherModes.color_on_cvg = (w2 >> 7) & 1; // 0
|
2964 | | OtherModes.image_read_en = (w2 >> 6) & 1; // 1
|
2965 | | OtherModes.z_update_en = (w2 >> 5) & 1; // 1
|
2966 | | OtherModes.z_compare_en = (w2 >> 4) & 1; // 1
|
2967 | | OtherModes.antialias_en = (w2 >> 3) & 1; // 1
|
2968 | | OtherModes.z_source_sel = (w2 >> 2) & 1; // 0
|
2969 | | OtherModes.dither_alpha_en = (w2 >> 1) & 1; // 0
|
2970 | | OtherModes.alpha_compare_en = (w2) & 1; // 0
|
2971 | | }
|
2972 | | |
2973 | | void n64_rdp::CmdLoadTLUT(UINT32 w1, UINT32 w2)
|
2974 | | {
|
2975 | | //wait("LoadTLUT");
|
2976 | | N64Tile* tile = m_tiles;
|
2977 | | |
2978 | | int tilenum = (w2 >> 24) & 0x7;
|
2979 | | int sl = tile[tilenum].sl = ((w1 >> 12) & 0xfff);
|
2980 | | int tl = tile[tilenum].tl = w1 & 0xfff;
|
2981 | | int sh = tile[tilenum].sh = ((w2 >> 12) & 0xfff);
|
2982 | | int th = tile[tilenum].th = w2 & 0xfff;
|
2983 | | |
2984 | | if (tl != th)
|
2985 | | {
|
2986 | | fatalerror("Load tlut: tl=%d, th=%d\n",tl,th);
|
2987 | | }
|
2988 | | |
2989 | | int count = (sh >> 2) - (sl >> 2) + 1;
|
2990 | | count <<= 2;
|
2991 | | |
2992 | | switch (MiscState.TISize)
|
2993 | | {
|
2994 | | case PIXEL_SIZE_16BIT:
|
2995 | | {
|
2996 | | if (tile[tilenum].tmem < 256)
|
2997 | | {
|
2998 | | fatalerror("rdp_load_tlut: loading tlut into low half at %d qwords\n",tile[tilenum].tmem);
|
2999 | | }
|
3000 | | UINT32 srcstart = (MiscState.TIAddress + (tl >> 2) * (MiscState.TIWidth << 1) + (sl >> 1)) >> 1;
|
3001 | | UINT16 *dst = GetTMEM16();
|
3002 | | UINT32 dststart = tile[tilenum].tmem << 2;
|
3003 | | |
3004 | | for (int i = 0; i < count; i += 4)
|
3005 | | {
|
3006 | | if (dststart < 2048)
|
3007 | | {
|
3008 | | dst[dststart] = U_RREADIDX16(srcstart);
|
3009 | | dst[dststart + 1] = dst[dststart];
|
3010 | | dst[dststart + 2] = dst[dststart];
|
3011 | | dst[dststart + 3] = dst[dststart];
|
3012 | | dststart += 4;
|
3013 | | srcstart += 1;
|
3014 | | }
|
3015 | | }
|
3016 | | break;
|
3017 | | }
|
3018 | | default: fatalerror("RDP: load_tlut: size = %d\n", MiscState.TISize);
|
3019 | | }
|
3020 | | }
|
3021 | | |
3022 | | void n64_rdp::CmdSetTileSize(UINT32 w1, UINT32 w2)
|
3023 | | {
|
3024 | | //wait("SetTileSize");
|
3025 | | |
3026 | | const int tilenum = (w2 >> 24) & 0x7;
|
3027 | | |
3028 | | m_tiles[tilenum].sl = (w1 >> 12) & 0xfff;
|
3029 | | m_tiles[tilenum].tl = (w1 >> 0) & 0xfff;
|
3030 | | m_tiles[tilenum].sh = (w2 >> 12) & 0xfff;
|
3031 | | m_tiles[tilenum].th = (w2 >> 0) & 0xfff;
|
3032 | | }
|
3033 | | |
3034 | | void n64_rdp::CmdLoadBlock(UINT32 w1, UINT32 w2)
|
3035 | | {
|
3036 | | //wait("LoadBlock");
|
3037 | | N64Tile* tile = m_tiles;
|
3038 | | |
3039 | | int tilenum = (w2 >> 24) & 0x7;
|
3040 | | UINT16* tc = GetTMEM16();
|
3041 | | |
3042 | | UINT16 sl, sh, tl;
|
3043 | | tile[tilenum].sl = sl = ((w1 >> 12) & 0xfff);
|
3044 | | tile[tilenum].tl = tl = ((w1 >> 0) & 0xfff);
|
3045 | | tile[tilenum].sh = sh = ((w2 >> 12) & 0xfff);
|
3046 | | UINT16 dxt = ((w2 >> 0) & 0xfff);
|
3047 | | |
3048 | | if (sh < sl)
|
3049 | | {
|
3050 | | fatalerror("load_block: sh < sl\n");
|
3051 | | }
|
3052 | | |
3053 | | INT32 width = (sh - sl) + 1;
|
3054 | | |
3055 | | width = (width << MiscState.TISize) >> 1;
|
3056 | | if (width & 7)
|
3057 | | {
|
3058 | | width = (width & ~7) + 8;
|
3059 | | }
|
3060 | | width >>= 3;
|
3061 | | |
3062 | | UINT32 tb = tile[tilenum].tmem << 2;
|
3063 | | |
3064 | | int tiwinwords = MiscState.TIWidth;
|
3065 | | UINT32 slinwords = sl;
|
3066 | | |
3067 | | tiwinwords = (tiwinwords << MiscState.TISize) >> 2;
|
3068 | | slinwords = (slinwords << MiscState.TISize) >> 2;
|
3069 | | |
3070 | | int ptr = 0, srcptr = 0;
|
3071 | | UINT16 first, sec;
|
3072 | | UINT32 src = (MiscState.TIAddress >> 1) + (tl * tiwinwords) + slinwords;
|
3073 | | |
3074 | | if (dxt != 0)
|
3075 | | {
|
3076 | | int j = 0;
|
3077 | | int t = 0;
|
3078 | | int oldt = 0;
|
3079 | | |
3080 | | if (tile[tilenum].size != PIXEL_SIZE_32BIT && tile[tilenum].format != FORMAT_YUV)
|
3081 | | {
|
3082 | | for (int i = 0; i < width; i ++)
|
3083 | | {
|
3084 | | oldt = t;
|
3085 | | t = ((j >> 11) & 1) ? WORD_XOR_DWORD_SWAP : WORD_ADDR_XOR;
|
3086 | | if (t != oldt)
|
3087 | | {
|
3088 | | i += tile[tilenum].line;
|
3089 | | }
|
3090 | | |
3091 | | ptr = tb + (i << 2);
|
3092 | | srcptr = src + (i << 2);
|
3093 | | |
3094 | | tc[(ptr ^ t) & 0x7ff] = U_RREADIDX16(srcptr);
|
3095 | | tc[((ptr + 1) ^ t) & 0x7ff] = U_RREADIDX16(srcptr + 1);
|
3096 | | tc[((ptr + 2) ^ t) & 0x7ff] = U_RREADIDX16(srcptr + 2);
|
3097 | | tc[((ptr + 3) ^ t) & 0x7ff] = U_RREADIDX16(srcptr + 3);
|
3098 | | j += dxt;
|
3099 | | }
|
3100 | | }
|
3101 | | else if (tile[tilenum].format == FORMAT_YUV)
|
3102 | | {
|
3103 | | for (int i = 0; i < width; i ++)
|
3104 | | {
|
3105 | | oldt = t;
|
3106 | | t = ((j >> 11) & 1) ? WORD_XOR_DWORD_SWAP : WORD_ADDR_XOR;
|
3107 | | if (t != oldt)
|
3108 | | {
|
3109 | | i += tile[tilenum].line;
|
3110 | | }
|
3111 | | |
3112 | | ptr = ((tb + (i << 1)) ^ t) & 0x3ff;
|
3113 | | srcptr = src + (i << 2);
|
3114 | | |
3115 | | first = U_RREADIDX16(srcptr);
|
3116 | | sec = U_RREADIDX16(srcptr + 1);
|
3117 | | tc[ptr] = ((first >> 8) << 8) | (sec >> 8);
|
3118 | | tc[ptr | 0x400] = ((first & 0xff) << 8) | (sec & 0xff);
|
3119 | | |
3120 | | ptr = ((tb + (i << 1) + 1) ^ t) & 0x3ff;
|
3121 | | first = U_RREADIDX16(srcptr + 2);
|
3122 | | sec = U_RREADIDX16(srcptr + 3);
|
3123 | | tc[ptr] = ((first >> 8) << 8) | (sec >> 8);
|
3124 | | tc[ptr | 0x400] = ((first & 0xff) << 8) | (sec & 0xff);
|
3125 | | |
3126 | | j += dxt;
|
3127 | | }
|
3128 | | }
|
3129 | | else
|
3130 | | {
|
3131 | | for (int i = 0; i < width; i ++)
|
3132 | | {
|
3133 | | oldt = t;
|
3134 | | t = ((j >> 11) & 1) ? WORD_XOR_DWORD_SWAP : WORD_ADDR_XOR;
|
3135 | | if (t != oldt)
|
3136 | | i += tile[tilenum].line;
|
3137 | | |
3138 | | ptr = ((tb + (i << 1)) ^ t) & 0x3ff;
|
3139 | | srcptr = src + (i << 2);
|
3140 | | tc[ptr] = U_RREADIDX16(srcptr);
|
3141 | | tc[ptr | 0x400] = U_RREADIDX16(srcptr + 1);
|
3142 | | |
3143 | | ptr = ((tb + (i << 1) + 1) ^ t) & 0x3ff;
|
3144 | | tc[ptr] = U_RREADIDX16(srcptr + 2);
|
3145 | | tc[ptr | 0x400] = U_RREADIDX16(srcptr + 3);
|
3146 | | |
3147 | | j += dxt;
|
3148 | | }
|
3149 | | }
|
3150 | | tile[tilenum].th = tl + (j >> 11);
|
3151 | | }
|
3152 | | else
|
3153 | | {
|
3154 | | if (tile[tilenum].size != PIXEL_SIZE_32BIT && tile[tilenum].format != FORMAT_YUV)
|
3155 | | {
|
3156 | | for (int i = 0; i < width; i ++)
|
3157 | | {
|
3158 | | ptr = tb + (i << 2);
|
3159 | | srcptr = src + (i << 2);
|
3160 | | tc[(ptr ^ WORD_ADDR_XOR) & 0x7ff] = U_RREADIDX16(srcptr);
|
3161 | | tc[((ptr + 1) ^ WORD_ADDR_XOR) & 0x7ff] = U_RREADIDX16(srcptr + 1);
|
3162 | | tc[((ptr + 2) ^ WORD_ADDR_XOR) & 0x7ff] = U_RREADIDX16(srcptr + 2);
|
3163 | | tc[((ptr + 3) ^ WORD_ADDR_XOR) & 0x7ff] = U_RREADIDX16(srcptr + 3);
|
3164 | | }
|
3165 | | }
|
3166 | | else if (tile[tilenum].format == FORMAT_YUV)
|
3167 | | {
|
3168 | | for (int i = 0; i < width; i ++)
|
3169 | | {
|
3170 | | ptr = ((tb + (i << 1)) ^ WORD_ADDR_XOR) & 0x3ff;
|
3171 | | srcptr = src + (i << 2);
|
3172 | | first = U_RREADIDX16(srcptr);
|
3173 | | sec = U_RREADIDX16(srcptr + 1);
|
3174 | | tc[ptr] = ((first >> 8) << 8) | (sec >> 8);//UV pair
|
3175 | | tc[ptr | 0x400] = ((first & 0xff) << 8) | (sec & 0xff);
|
3176 | | |
3177 | | ptr = ((tb + (i << 1) + 1) ^ WORD_ADDR_XOR) & 0x3ff;
|
3178 | | first = U_RREADIDX16(srcptr + 2);
|
3179 | | sec = U_RREADIDX16(srcptr + 3);
|
3180 | | tc[ptr] = ((first >> 8) << 8) | (sec >> 8);
|
3181 | | tc[ptr | 0x400] = ((first & 0xff) << 8) | (sec & 0xff);
|
3182 | | }
|
3183 | | }
|
3184 | | else
|
3185 | | {
|
3186 | | for (int i = 0; i < width; i ++)
|
3187 | | {
|
3188 | | ptr = ((tb + (i << 1)) ^ WORD_ADDR_XOR) & 0x3ff;
|
3189 | | srcptr = src + (i << 2);
|
3190 | | tc[ptr] = U_RREADIDX16(srcptr);
|
3191 | | tc[ptr | 0x400] = U_RREADIDX16(srcptr + 1);
|
3192 | | |
3193 | | ptr = ((tb + (i << 1) + 1) ^ WORD_ADDR_XOR) & 0x3ff;
|
3194 | | tc[ptr] = U_RREADIDX16(srcptr + 2);
|
3195 | | tc[ptr | 0x400] = U_RREADIDX16(srcptr + 3);
|
3196 | | }
|
3197 | | }
|
3198 | | tile[tilenum].th = tl;
|
3199 | | }
|
3200 | | }
|
3201 | | |
3202 | | void n64_rdp::CmdLoadTile(UINT32 w1, UINT32 w2)
|
3203 | | {
|
3204 | | //wait("LoadTile");
|
3205 | | N64Tile* tile = m_tiles;
|
3206 | | int tilenum = (w2 >> 24) & 0x7;
|
3207 | | |
3208 | | tile[tilenum].sl = ((w1 >> 12) & 0xfff);
|
3209 | | tile[tilenum].tl = ((w1 >> 0) & 0xfff);
|
3210 | | tile[tilenum].sh = ((w2 >> 12) & 0xfff);
|
3211 | | tile[tilenum].th = ((w2 >> 0) & 0xfff);
|
3212 | | |
3213 | | UINT16 sl = tile[tilenum].sl >> 2;
|
3214 | | UINT16 tl = tile[tilenum].tl >> 2;
|
3215 | | UINT16 sh = tile[tilenum].sh >> 2;
|
3216 | | UINT16 th = tile[tilenum].th >> 2;
|
3217 | | |
3218 | | INT32 width = (sh - sl) + 1;
|
3219 | | INT32 height = (th - tl) + 1;
|
3220 | | /*
|
3221 | | int topad;
|
3222 | | if (MiscState.TISize < 3)
|
3223 | | {
|
3224 | | topad = (width * MiscState.TISize) & 0x7;
|
3225 | | }
|
3226 | | else
|
3227 | | {
|
3228 | | topad = (width << 2) & 0x7;
|
3229 | | }
|
3230 | | topad = 0; // ????
|
3231 | | */
|
3232 | | switch (MiscState.TISize)
|
3233 | | {
|
3234 | | case PIXEL_SIZE_8BIT:
|
3235 | | {
|
3236 | | UINT32 src = MiscState.TIAddress;
|
3237 | | UINT8 *tc = GetTMEM();
|
3238 | | int tb = tile[tilenum].tmem << 3;
|
3239 | | |
3240 | | for (int j = 0; j < height; j++)
|
3241 | | {
|
3242 | | int tline = tb + ((tile[tilenum].line << 3) * j);
|
3243 | | int s = ((j + tl) * MiscState.TIWidth) + sl;
|
3244 | | |
3245 | | int xorval8 = ((j & 1) ? BYTE_XOR_DWORD_SWAP : BYTE_ADDR_XOR);
|
3246 | | for (int i = 0; i < width; i++)
|
3247 | | {
|
3248 | | tc[((tline + i) ^ xorval8) & 0xfff] = U_RREADADDR8(src + s + i);
|
3249 | | }
|
3250 | | }
|
3251 | | break;
|
3252 | | }
|
3253 | | case PIXEL_SIZE_16BIT:
|
3254 | | {
|
3255 | | UINT32 src = MiscState.TIAddress >> 1;
|
3256 | | UINT16 *tc = GetTMEM16();
|
3257 | | UINT16 yuvword;
|
3258 | | |
3259 | | if (tile[tilenum].format != FORMAT_YUV)
|
3260 | | {
|
3261 | | for (int j = 0; j < height; j++)
|
3262 | | {
|
3263 | | int tb = tile[tilenum].tmem << 2;
|
3264 | | int tline = tb + ((tile[tilenum].line << 2) * j);
|
3265 | | int s = ((j + tl) * MiscState.TIWidth) + sl;
|
3266 | | int xorval16 = (j & 1) ? WORD_XOR_DWORD_SWAP : WORD_ADDR_XOR;
|
3267 | | |
3268 | | for (int i = 0; i < width; i++)
|
3269 | | {
|
3270 | | UINT32 taddr = (tline + i) ^ xorval16;
|
3271 | | tc[taddr & 0x7ff] = U_RREADIDX16(src + s + i);
|
3272 | | }
|
3273 | | }
|
3274 | | }
|
3275 | | else
|
3276 | | {
|
3277 | | for (int j = 0; j < height; j++)
|
3278 | | {
|
3279 | | int tb = tile[tilenum].tmem << 3;
|
3280 | | int tline = tb + ((tile[tilenum].line << 3) * j);
|
3281 | | int s = ((j + tl) * MiscState.TIWidth) + sl;
|
3282 | | int xorval8 = (j & 1) ? BYTE_XOR_DWORD_SWAP : BYTE_ADDR_XOR;
|
3283 | | |
3284 | | for (int i = 0; i < width; i++)
|
3285 | | {
|
3286 | | UINT32 taddr = ((tline + i) ^ xorval8) & 0x7ff;
|
3287 | | yuvword = U_RREADIDX16(src + s + i);
|
3288 | | GetTMEM()[taddr] = yuvword >> 8;
|
3289 | | GetTMEM()[taddr | 0x800] = yuvword & 0xff;
|
3290 | | }
|
3291 | | }
|
3292 | | }
|
3293 | | break;
|
3294 | | }
|
3295 | | case PIXEL_SIZE_32BIT:
|
3296 | | {
|
3297 | | UINT32 src = MiscState.TIAddress >> 2;
|
3298 | | UINT16 *tc16 = GetTMEM16();
|
3299 | | int tb = (tile[tilenum].tmem << 2);
|
3300 | | |
3301 | | for (int j = 0; j < height; j++)
|
3302 | | {
|
3303 | | int tline = tb + ((tile[tilenum].line << 2) * j);
|
3304 | | |
3305 | | int s = ((j + tl) * MiscState.TIWidth) + sl;
|
3306 | | int xorval32cur = (j & 1) ? WORD_XOR_DWORD_SWAP : WORD_ADDR_XOR;
|
3307 | | for (int i = 0; i < width; i++)
|
3308 | | {
|
3309 | | UINT32 c = U_RREADIDX32(src + s + i);
|
3310 | | UINT32 ptr = ((tline + i) ^ xorval32cur) & 0x3ff;
|
3311 | | tc16[ptr] = c >> 16;
|
3312 | | tc16[ptr | 0x400] = c & 0xffff;
|
3313 | | }
|
3314 | | }
|
3315 | | break;
|
3316 | | }
|
3317 | | |
3318 | | default: fatalerror("RDP: load_tile: size = %d\n", MiscState.TISize);
|
3319 | | }
|
3320 | | }
|
3321 | | |
3322 | | void n64_rdp::CmdSetTile(UINT32 w1, UINT32 w2)
|
3323 | | {
|
3324 | | //wait("SetTile");
|
3325 | | |
3326 | | int tilenum = (w2 >> 24) & 0x7;
|
3327 | | N64Tile* tex_tile = &m_tiles[tilenum];
|
3328 | | |
3329 | | tex_tile->format = (w1 >> 21) & 0x7;
|
3330 | | tex_tile->size = (w1 >> 19) & 0x3;
|
3331 | | tex_tile->line = (w1 >> 9) & 0x1ff;
|
3332 | | tex_tile->tmem = (w1 >> 0) & 0x1ff;
|
3333 | | tex_tile->palette = (w2 >> 20) & 0xf;
|
3334 | | tex_tile->ct = (w2 >> 19) & 0x1;
|
3335 | | tex_tile->mt = (w2 >> 18) & 0x1;
|
3336 | | tex_tile->mask_t = (w2 >> 14) & 0xf;
|
3337 | | tex_tile->shift_t = (w2 >> 10) & 0xf;
|
3338 | | tex_tile->cs = (w2 >> 9) & 0x1;
|
3339 | | tex_tile->ms = (w2 >> 8) & 0x1;
|
3340 | | tex_tile->mask_s = (w2 >> 4) & 0xf;
|
3341 | | tex_tile->shift_s = (w2 >> 0) & 0xf;
|
3342 | | |
3343 | | if (tex_tile->format == FORMAT_I && tex_tile->size > PIXEL_SIZE_8BIT)
|
3344 | | {
|
3345 | | tex_tile->format = FORMAT_RGBA; // Used by Supercross 2000 (in-game)
|
3346 | | }
|
3347 | | if (tex_tile->format == FORMAT_CI && tex_tile->size > PIXEL_SIZE_8BIT)
|
3348 | | {
|
3349 | | tex_tile->format = FORMAT_RGBA; // Used by Clay Fighter - Sculptor's Cut
|
3350 | | }
|
3351 | | |
3352 | | if (tex_tile->format == FORMAT_RGBA && tex_tile->size < PIXEL_SIZE_16BIT)
|
3353 | | {
|
3354 | | tex_tile->format = FORMAT_CI; // Used by Exterem-G2, Madden Football 64, and Rat Attack
|
3355 | | }
|
3356 | | |
3357 | | //m_pending_mode_block = true;
|
3358 | | }
|
3359 | | |
3360 | | void n64_rdp::CmdFillRect(UINT32 w1, UINT32 w2)
|
3361 | | {
|
3362 | | //if(m_pending_mode_block) { wait("Block on pending mode-change"); m_pending_mode_block = false; }
|
3363 | | |
3364 | | UINT32 xl = (w1 >> 12) & 0xfff;
|
3365 | | UINT32 yl = (w1 >> 0) & 0xfff;
|
3366 | | UINT32 xh = (w2 >> 12) & 0xfff;
|
3367 | | UINT32 yh = (w2 >> 0) & 0xfff;
|
3368 | | |
3369 | | if (OtherModes.cycle_type == CYCLE_TYPE_FILL || OtherModes.cycle_type == CYCLE_TYPE_COPY)
|
3370 | | {
|
3371 | | yl |= 3;
|
3372 | | }
|
3373 | | |
3374 | | UINT32 xlint = (xl >> 2) & 0x3ff;
|
3375 | | UINT32 xhint = (xh >> 2) & 0x3ff;
|
3376 | | |
3377 | | UINT32* ewdata = m_temp_rect_data;
|
3378 | | ewdata[0] = (0x3680 << 16) | yl;//command, flipped, tile, yl
|
3379 | | ewdata[1] = (yl << 16) | yh;//ym, yh
|
3380 | | ewdata[2] = (xlint << 16) | ((xl & 3) << 14);//xl, xl frac
|
3381 | | ewdata[3] = 0;//dxldy, dxldy frac
|
3382 | | ewdata[4] = (xhint << 16) | ((xh & 3) << 14);//xh, xh frac
|
3383 | | ewdata[5] = 0;//dxhdy, dxhdy frac
|
3384 | | ewdata[6] = (xlint << 16) | ((xl & 3) << 14);//xm, xm frac
|
3385 | | ewdata[7] = 0;//dxmdy, dxmdy frac
|
3386 | | memset(&ewdata[8], 0, 36 * sizeof(UINT32));//shade, texture, depth
|
3387 | | |
3388 | | DrawTriangle(false, false, false, true);
|
3389 | | }
|
3390 | | |
3391 | | void n64_rdp::CmdSetFogColor(UINT32 w1, UINT32 w2)
|
3392 | | {
|
3393 | | FogColor.c = w2;
|
3394 | | }
|
3395 | | |
3396 | | void n64_rdp::CmdSetBlendColor(UINT32 w1, UINT32 w2)
|
3397 | | {
|
3398 | | BlendColor.c = w2;
|
3399 | | }
|
3400 | | |
3401 | | void n64_rdp::CmdSetPrimColor(UINT32 w1, UINT32 w2)
|
3402 | | {
|
3403 | | MiscState.MinLevel = (w1 >> 8) & 0x1f;
|
3404 | | PrimLODFraction = w1 & 0xff;
|
3405 | | PrimColor.c = w2;
|
3406 | | }
|
3407 | | |
3408 | | void n64_rdp::CmdSetEnvColor(UINT32 w1, UINT32 w2)
|
3409 | | {
|
3410 | | EnvColor.c = w2;
|
3411 | | }
|
3412 | | |
3413 | | void n64_rdp::CmdSetCombine(UINT32 w1, UINT32 w2)
|
3414 | | {
|
3415 | | m_combine.sub_a_rgb0 = (w1 >> 20) & 0xf;
|
3416 | | m_combine.mul_rgb0 = (w1 >> 15) & 0x1f;
|
3417 | | m_combine.sub_a_a0 = (w1 >> 12) & 0x7;
|
3418 | | m_combine.mul_a0 = (w1 >> 9) & 0x7;
|
3419 | | m_combine.sub_a_rgb1 = (w1 >> 5) & 0xf;
|
3420 | | m_combine.mul_rgb1 = (w1 >> 0) & 0x1f;
|
3421 | | |
3422 | | m_combine.sub_b_rgb0 = (w2 >> 28) & 0xf;
|
3423 | | m_combine.sub_b_rgb1 = (w2 >> 24) & 0xf;
|
3424 | | m_combine.sub_a_a1 = (w2 >> 21) & 0x7;
|
3425 | | m_combine.mul_a1 = (w2 >> 18) & 0x7;
|
3426 | | m_combine.add_rgb0 = (w2 >> 15) & 0x7;
|
3427 | | m_combine.sub_b_a0 = (w2 >> 12) & 0x7;
|
3428 | | m_combine.add_a0 = (w2 >> 9) & 0x7;
|
3429 | | m_combine.add_rgb1 = (w2 >> 6) & 0x7;
|
3430 | | m_combine.sub_b_a1 = (w2 >> 3) & 0x7;
|
3431 | | m_combine.add_a1 = (w2 >> 0) & 0x7;
|
3432 | | }
|
3433 | | |
3434 | | void n64_rdp::CmdSetTextureImage(UINT32 w1, UINT32 w2)
|
3435 | | {
|
3436 | | MiscState.TIFormat = (w1 >> 21) & 0x7;
|
3437 | | MiscState.TISize = (w1 >> 19) & 0x3;
|
3438 | | MiscState.TIWidth = (w1 & 0x3ff) + 1;
|
3439 | | MiscState.TIAddress = w2 & 0x01ffffff;
|
3440 | | }
|
3441 | | |
3442 | | void n64_rdp::CmdSetMaskImage(UINT32 w1, UINT32 w2)
|
3443 | | {
|
3444 | | //wait("SetMaskImage");
|
3445 | | |
3446 | | MiscState.ZBAddress = w2 & 0x01ffffff;
|
3447 | | }
|
3448 | | |
3449 | | void n64_rdp::CmdSetColorImage(UINT32 w1, UINT32 w2)
|
3450 | | {
|
3451 | | //wait("SetColorImage");
|
3452 | | |
3453 | | MiscState.FBFormat = (w1 >> 21) & 0x7;
|
3454 | | MiscState.FBSize = (w1 >> 19) & 0x3;
|
3455 | | MiscState.FBWidth = (w1 & 0x3ff) + 1;
|
3456 | | MiscState.FBAddress = w2 & 0x01ffffff;
|
3457 | | |
3458 | | if (MiscState.FBFormat < 2 || MiscState.FBFormat > 32) // Jet Force Gemini sets the format to 4, Intensity. Protection?
|
3459 | | {
|
3460 | | MiscState.FBFormat = 2;
|
3461 | | }
|
3462 | | }
|
3463 | | |
3464 | | UINT32 n64_rdp::AddRightCvg(UINT32 x, UINT32 k)
|
3465 | | {
|
3466 | | //#undef FULL_SUBPIXELS
|
3467 | | #define FULL_SUBPIXELS
|
3468 | | UINT32 coveredsubpixels=((x >> 14) & 3);
|
3469 | | if (!(x & 0xffff))
|
3470 | | {
|
3471 | | return 0;
|
3472 | | }
|
3473 | | #ifdef FULL_SUBPIXELS
|
3474 | | if (!coveredsubpixels)
|
3475 | | {
|
3476 | | return 0;
|
3477 | | }
|
3478 | | if (!(k & 1))
|
3479 | | {
|
3480 | | return (coveredsubpixels<3) ? 1 : 2;
|
3481 | | }
|
3482 | | else
|
3483 | | {
|
3484 | | return (coveredsubpixels<2) ? 0 : 1;
|
3485 | | }
|
3486 | | #endif
|
3487 | | if (!(k & 1))
|
3488 | | {
|
3489 | | return (coveredsubpixels<2) ? 1 : 2;
|
3490 | | }
|
3491 | | else
|
3492 | | {
|
3493 | | if (coveredsubpixels<1)
|
3494 | | {
|
3495 | | return 0;
|
3496 | | }
|
3497 | | else if (coveredsubpixels<3)
|
3498 | | {
|
3499 | | return 1;
|
3500 | | }
|
3501 | | else
|
3502 | | {
|
3503 | | return 2;
|
3504 | | }
|
3505 | | }
|
3506 | | }
|
3507 | | |
3508 | | UINT32 n64_rdp::AddLeftCvg(UINT32 x, UINT32 k)
|
3509 | | {
|
3510 | | UINT32 coveredsubpixels = 3 - ((x >> 14) & 3);
|
3511 | | if (!(x & 0xffff))
|
3512 | | {
|
3513 | | return 2;
|
3514 | | }
|
3515 | | #ifdef FULL_SUBPIXELS
|
3516 | | if (!coveredsubpixels)
|
3517 | | {
|
3518 | | return 0;
|
3519 | | }
|
3520 | | if (!(k & 1))
|
3521 | | {
|
3522 | | return (coveredsubpixels<2) ? 0 : 1;
|
3523 | | }
|
3524 | | else
|
3525 | | {
|
3526 | | return (coveredsubpixels<3) ? 1 : 2;
|
3527 | | }
|
3528 | | #endif
|
3529 | | if (k & 1)
|
3530 | | {
|
3531 | | return (coveredsubpixels<2) ? 1 : 2;
|
3532 | | }
|
3533 | | else
|
3534 | | {
|
3535 | | if (coveredsubpixels < 1)
|
3536 | | {
|
3537 | | return 0;
|
3538 | | }
|
3539 | | else if (coveredsubpixels < 3)
|
3540 | | {
|
3541 | | return 1;
|
3542 | | }
|
3543 | | else
|
3544 | | {
|
3545 | | return 2;
|
3546 | | }
|
3547 | | }
|
3548 | | }
|
3549 | | |
3550 | | /*****************************************************************************/
|
3551 | | |
3552 | | void n64_rdp::CmdInvalid(UINT32 w1, UINT32 w2)
|
3553 | | {
|
3554 | | fatalerror("n64_rdp::Invalid: %d, %08x %08x\n", (w1 >> 24) & 0x3f, w1, w2);
|
3555 | | }
|
3556 | | |
3557 | | void n64_rdp::CmdNoOp(UINT32 w1, UINT32 w2)
|
3558 | | {
|
3559 | | // Do nothing
|
3560 | | }
|
3561 | | |
3562 | | |
3563 | | void n64_rdp::ProcessList()
|
3564 | | {
|
3565 | | INT32 length = m_end - m_current;
|
3566 | | |
3567 | | if(length < 0)
|
3568 | | {
|
3569 | | m_current = m_end;
|
3570 | | return;
|
3571 | | }
|
3572 | | |
3573 | | // load command data
|
3574 | | for(int i = 0; i < length; i += 4)
|
3575 | | {
|
3576 | | m_cmd_data[m_cmd_ptr++] = ReadData((m_current & 0x1fffffff) + i);
|
3577 | | }
|
3578 | | |
3579 | | m_current = m_end;
|
3580 | | |
3581 | | UINT32 cmd = (m_cmd_data[0] >> 24) & 0x3f;
|
3582 | | UINT32 cmd_length = (m_cmd_ptr + 1) * 4;
|
3583 | | |
3584 | | SetStatusReg(GetStatusReg() &~ DP_STATUS_FREEZE);
|
3585 | | |
3586 | | // check if more data is needed
|
3587 | | if (cmd_length < rdp_command_length[cmd])
|
3588 | | {
|
3589 | | return;
|
3590 | | }
|
3591 | | |
3592 | | while (m_cmd_cur < m_cmd_ptr)
|
3593 | | {
|
3594 | | cmd = (m_cmd_data[m_cmd_cur] >> 24) & 0x3f;
|
3595 | | |
3596 | | if (((m_cmd_ptr - m_cmd_cur) * 4) < rdp_command_length[cmd])
|
3597 | | {
|
3598 | | return;
|
3599 | | //fatalerror("rdp_process_list: not enough rdp command data: cur = %d, ptr = %d, expected = %d\n", m_cmd_cur, m_cmd_ptr, rdp_command_length[cmd]);
|
3600 | | }
|
3601 | | |
3602 | | if (LOG_RDP_EXECUTION)
|
3603 | | {
|
3604 | | char string[4000];
|
3605 | | Dasm(string);
|
3606 | | |
3607 | | fprintf(rdp_exec, "%08X: %08X %08X %s\n", m_start+(m_cmd_cur * 4), m_cmd_data[m_cmd_cur+0], m_cmd_data[m_cmd_cur+1], string);
|
3608 | | fflush(rdp_exec);
|
3609 | | }
|
3610 | | |
3611 | | // execute the command
|
3612 | | UINT32 w1 = m_cmd_data[m_cmd_cur+0];
|
3613 | | UINT32 w2 = m_cmd_data[m_cmd_cur+1];
|
3614 | | |
3615 | | switch(cmd)
|
3616 | | {
|
3617 | | case 0x00: CmdNoOp(w1, w2); break;
|
3618 | | |
3619 | | case 0x08: CmdTriangle(w1, w2); break;
|
3620 | | case 0x09: CmdTriangleZ(w1, w2); break;
|
3621 | | case 0x0a: CmdTriangleT(w1, w2); break;
|
3622 | | case 0x0b: CmdTriangleTZ(w1, w2); break;
|
3623 | | case 0x0c: CmdTriangleS(w1, w2); break;
|
3624 | | case 0x0d: CmdTriangleSZ(w1, w2); break;
|
3625 | | case 0x0e: CmdTriangleST(w1, w2); break;
|
3626 | | case 0x0f: CmdTriangleSTZ(w1, w2); break;
|
3627 | | |
3628 | | case 0x24: CmdTexRect(w1, w2); break;
|
3629 | | case 0x25: CmdTexRectFlip(w1, w2); break;
|
3630 | | |
3631 | | case 0x26: CmdSyncLoad(w1, w2); break;
|
3632 | | case 0x27: CmdSyncPipe(w1, w2); break;
|
3633 | | case 0x28: CmdSyncTile(w1, w2); break;
|
3634 | | case 0x29: CmdSyncFull(w1, w2); break;
|
3635 | | |
3636 | | case 0x2a: CmdSetKeyGB(w1, w2); break;
|
3637 | | case 0x2b: CmdSetKeyR(w1, w2); break;
|
3638 | | |
3639 | | case 0x2c: CmdSetConvert(w1, w2); break;
|
3640 | | case 0x3c: CmdSetCombine(w1, w2); break;
|
3641 | | case 0x2d: CmdSetScissor(w1, w2); break;
|
3642 | | case 0x2e: CmdSetPrimDepth(w1, w2); break;
|
3643 | | case 0x2f: CmdSetOtherModes(w1, w2); break;
|
3644 | | |
3645 | | case 0x30: CmdLoadTLUT(w1, w2); break;
|
3646 | | case 0x33: CmdLoadBlock(w1, w2); break;
|
3647 | | case 0x34: CmdLoadTile(w1, w2); break;
|
3648 | | |
3649 | | case 0x32: CmdSetTileSize(w1, w2); break;
|
3650 | | case 0x35: CmdSetTile(w1, w2); break;
|
3651 | | |
3652 | | case 0x36: CmdFillRect(w1, w2); break;
|
3653 | | |
3654 | | case 0x37: CmdSetFillColor32(w1, w2); break;
|
3655 | | case 0x38: CmdSetFogColor(w1, w2); break;
|
3656 | | case 0x39: CmdSetBlendColor(w1, w2); break;
|
3657 | | case 0x3a: CmdSetPrimColor(w1, w2); break;
|
3658 | | case 0x3b: CmdSetEnvColor(w1, w2); break;
|
3659 | | |
3660 | | case 0x3d: CmdSetTextureImage(w1, w2); break;
|
3661 | | case 0x3e: CmdSetMaskImage(w1, w2); break;
|
3662 | | case 0x3f: CmdSetColorImage(w1, w2); break;
|
3663 | | }
|
3664 | | |
3665 | | m_cmd_cur += rdp_command_length[cmd] / 4;
|
3666 | | };
|
3667 | | m_cmd_ptr = 0;
|
3668 | | m_cmd_cur = 0;
|
3669 | | |
3670 | | m_start = m_current = m_end;
|
3671 | | }
|
3672 | | |
3673 | | /*****************************************************************************/
|
3674 | | |
3675 | | n64_rdp::n64_rdp(n64_state &state) : poly_manager<UINT32, rdp_poly_state, 8, 32000>(state.machine())
|
3676 | | {
|
3677 | | AuxBufPtr = 0;
|
3678 | | AuxBuf = NULL;
|
3679 | | m_pipe_clean = true;
|
3680 | | |
3681 | | m_pending_mode_block = false;
|
3682 | | |
3683 | | m_cmd_ptr = 0;
|
3684 | | m_cmd_cur = 0;
|
3685 | | |
3686 | | m_start = 0;
|
3687 | | m_end = 0;
|
3688 | | m_current = 0;
|
3689 | | m_status = 0x88;
|
3690 | | |
3691 | | for (int i = 0; i < 8; i++)
|
3692 | | {
|
3693 | | m_tiles[i].num = i;
|
3694 | | }
|
3695 | | |
3696 | | OneColor.c = 0xffffffff;
|
3697 | | ZeroColor.c = 0x00000000;
|
3698 | | |
3699 | | m_tmem = NULL;
|
3700 | | |
3701 | | m_machine = NULL;
|
3702 | | |
3703 | | //memset(m_hidden_bits, 3, 8388608);
|
3704 | | |
3705 | | PrimLODFraction = 0;
|
3706 | | |
3707 | | for (int i = 0; i < 256; i++)
|
3708 | | {
|
3709 | | m_gamma_table[i] = sqrt((float)(i << 6));
|
3710 | | m_gamma_table[i] <<= 1;
|
3711 | | }
|
3712 | | |
3713 | | for (int i = 0; i < 0x4000; i++)
|
3714 | | {
|
3715 | | m_gamma_dither_table[i] = sqrt((float)i);
|
3716 | | m_gamma_dither_table[i] <<= 1;
|
3717 | | }
|
3718 | | |
3719 | | z_build_com_table();
|
3720 | | |
3721 | | for (int i = 0; i < 0x4000; i++)
|
3722 | | {
|
3723 | | UINT32 exponent = (i >> 11) & 7;
|
3724 | | UINT32 mantissa = i & 0x7ff;
|
3725 | | z_complete_dec_table[i] = ((mantissa << z_dec_table[exponent].shift) + z_dec_table[exponent].add) & 0x3fffff;
|
3726 | | }
|
3727 | | |
3728 | | precalc_cvmask_derivatives();
|
3729 | | |
3730 | | for(int i = 0; i < 0x200; i++)
|
3731 | | {
|
3732 | | switch((i >> 7) & 3)
|
3733 | | {
|
3734 | | case 0:
|
3735 | | case 1:
|
3736 | | s_special_9bit_clamptable[i] = i & 0xff;
|
3737 | | break;
|
3738 | | case 2:
|
3739 | | s_special_9bit_clamptable[i] = 0xff;
|
3740 | | break;
|
3741 | | case 3:
|
3742 | | s_special_9bit_clamptable[i] = 0;
|
3743 | | break;
|
3744 | | }
|
3745 | | }
|
3746 | | |
3747 | | for(int i = 0; i < 32; i++)
|
3748 | | {
|
3749 | | ReplicatedRGBA[i] = (i << 3) | ((i >> 2) & 7);
|
3750 | | }
|
3751 | | |
3752 | | _Write[0] = &n64_rdp::_Write16Bit_Cvg0_NoBlend;
|
3753 | | _Write[1] = &n64_rdp::_Write16Bit_Cvg0_Blend;
|
3754 | | _Write[2] = &n64_rdp::_Write16Bit_Cvg1;
|
3755 | | _Write[3] = &n64_rdp::_Write16Bit_Cvg1;
|
3756 | | _Write[4] = &n64_rdp::_Write16Bit_Cvg2;
|
3757 | | _Write[5] = &n64_rdp::_Write16Bit_Cvg2;
|
3758 | | _Write[6] = &n64_rdp::_Write16Bit_Cvg3;
|
3759 | | _Write[7] = &n64_rdp::_Write16Bit_Cvg3;
|
3760 | | _Write[8] = &n64_rdp::_Write32Bit_Cvg0_NoBlend;
|
3761 | | _Write[9] = &n64_rdp::_Write32Bit_Cvg0_Blend;
|
3762 | | _Write[10] = &n64_rdp::_Write32Bit_Cvg1;
|
3763 | | _Write[11] = &n64_rdp::_Write32Bit_Cvg1;
|
3764 | | _Write[12] = &n64_rdp::_Write32Bit_Cvg2;
|
3765 | | _Write[13] = &n64_rdp::_Write32Bit_Cvg2;
|
3766 | | _Write[14] = &n64_rdp::_Write32Bit_Cvg3;
|
3767 | | _Write[15] = &n64_rdp::_Write32Bit_Cvg3;
|
3768 | | |
3769 | | _Read[0] = &n64_rdp::_Read16Bit_ImgRead0;
|
3770 | | _Read[1] = &n64_rdp::_Read16Bit_ImgRead1;
|
3771 | | _Read[2] = &n64_rdp::_Read32Bit_ImgRead0;
|
3772 | | _Read[3] = &n64_rdp::_Read32Bit_ImgRead1;
|
3773 | | |
3774 | | _Copy[0] = &n64_rdp::_Copy16Bit;
|
3775 | | _Copy[1] = &n64_rdp::_Copy32Bit;
|
3776 | | |
3777 | | _Fill[0] = &n64_rdp::_Fill16Bit;
|
3778 | | _Fill[1] = &n64_rdp::_Fill32Bit;
|
3779 | | }
|
3780 | | |
3781 | | void n64_state::video_start()
|
3782 | | {
|
3783 | | m_rdp = auto_alloc(machine(), n64_rdp(*this));
|
3784 | | |
3785 | | m_rdp->SetMachine(machine());
|
3786 | | m_rdp->InitInternalState();
|
3787 | | |
3788 | | m_rdp->Blender.SetMachine(machine());
|
3789 | | m_rdp->Blender.SetProcessor(m_rdp);
|
3790 | | |
3791 | | m_rdp->TexPipe.SetMachine(machine());
|
3792 | | |
3793 | | m_rdp->AuxBuf = auto_alloc_array_clear(machine(), UINT8, EXTENT_AUX_COUNT);
|
3794 | | |
3795 | | if (LOG_RDP_EXECUTION)
|
3796 | | {
|
3797 | | rdp_exec = fopen("rdp_execute.txt", "wt");
|
3798 | | }
|
3799 | | }
|
3800 | | |
3801 | | UINT32 n64_state::screen_update_n64(screen_device &screen, bitmap_rgb32 &bitmap, const rectangle &cliprect)
|
3802 | | {
|
3803 | | n64_periphs *n64 = machine().device<n64_periphs>("rcp");
|
3804 | | m_rdp->visarea = screen.visible_area();
|
3805 | | |
3806 | | //UINT16 *frame_buffer = (UINT16*)&rdram[(n64->vi_origin & 0xffffff) >> 2];
|
3807 | | //UINT8 *cvg_buffer = &m_rdp.HiddenBits[((n64->vi_origin & 0xffffff) >> 2) >> 1];
|
3808 | | //int vibuffering = ((n64->vi_control & 2) && fsaa && divot);
|
3809 | | |
3810 | | //vibuffering = 0; // Disabled for now
|
3811 | | |
3812 | | /*
|
3813 | | if (vibuffering && ((n64->vi_control & 3) == 2))
|
3814 | | {
|
3815 | | if (frame_buffer)
|
3816 | | {
|
3817 | | for (j=0; j < vres; j++)
|
3818 | | {
|
3819 | | for (i=0; i < hres; i++)
|
3820 | | {
|
3821 | | UINT16 pix;
|
3822 | | pix = frame_buffer[pixels ^ WORD_ADDR_XOR];
|
3823 | | curpixel_cvg = ((pix & 1) << 2) | (cvg_buffer[pixels ^ BYTE_ADDR_XOR] & 3); // Reuse of this variable
|
3824 | | if (curpixel_cvg < 7 && i > 1 && j > 1 && i < (hres - 2) && j < (vres - 2) && fsaa)
|
3825 | | {
|
3826 | | newc = video_filter16(&frame_buffer[pixels ^ WORD_ADDR_XOR], &cvg_buffer[pixels ^ BYTE_ADDR_XOR], n64->vi_width);
|
3827 | | ViBuffer[i][j] = newc;
|
3828 | | }
|
3829 | | else
|
3830 | | {
|
3831 | | newc.i.r = ((pix >> 8) & 0xf8) | (pix >> 13);
|
3832 | | newc.i.g = ((pix >> 3) & 0xf8) | ((pix >> 8) & 0x07);
|
3833 | | newc.i.b = ((pix << 2) & 0xf8) | ((pix >> 3) & 0x07);
|
3834 | | ViBuffer[i][j] = newc;
|
3835 | | }
|
3836 | | pixels++;
|
3837 | | }
|
3838 | | pixels += invisiblewidth;
|
3839 | | }
|
3840 | | }
|
3841 | | }
|
3842 | | */
|
3843 | | |
3844 | | m_rdp->wait();
|
3845 | | m_rdp->AuxBufPtr = 0;
|
3846 | | |
3847 | | if (n64->vi_blank)
|
3848 | | {
|
3849 | | bitmap.fill(0, m_rdp->visarea);
|
3850 | | return 0;
|
3851 | | }
|
3852 | | |
3853 | | m_rdp->VideoUpdate(n64, bitmap);
|
3854 | | |
3855 | | return 0;
|
3856 | | }
|
| 1 | /****************************************************************************** |
| 2 | |
| 3 | |
| 4 | SGI/Nintendo Reality Display Processor |
| 5 | ------------------- |
| 6 | |
| 7 | by MooglyGuy |
| 8 | based on initial C code by Ville Linde |
| 9 | contains additional improvements from angrylion, Ziggy, Gonetz and Orkin |
| 10 | |
| 11 | |
| 12 | ******************************************************************************* |
| 13 | |
| 14 | STATUS: |
| 15 | |
| 16 | Much behavior needs verification against real hardware. Many edge cases must |
| 17 | be verified on real hardware as well. |
| 18 | |
| 19 | TODO: |
| 20 | |
| 21 | - Further re-work class structure to avoid dependencies |
| 22 | |
| 23 | *******************************************************************************/ |
| 24 | |
| 25 | #include "emu.h" |
| 26 | #include "video/n64.h" |
| 27 | |
| 28 | #define LOG_RDP_EXECUTION 0 |
| 29 | |
| 30 | static FILE *rdp_exec; |
| 31 | |
| 32 | UINT32 n64_rdp::s_special_9bit_clamptable[512]; |
| 33 | |
| 34 | bool n64_rdp::rdp_range_check(UINT32 addr) |
| 35 | { |
| 36 | if(MiscState.FBSize == 0) return false; |
| 37 | |
| 38 | int fbcount = ((MiscState.FBWidth * Scissor.m_yl) << (MiscState.FBSize - 1)) * 3; |
| 39 | int fbaddr = MiscState.FBAddress & 0x007fffff; |
| 40 | if ((addr >= fbaddr) && (addr < (fbaddr + fbcount))) |
| 41 | { |
| 42 | return false; |
| 43 | } |
| 44 | |
| 45 | int zbcount = MiscState.FBWidth * Scissor.m_yl * 2; |
| 46 | int zbaddr = MiscState.ZBAddress & 0x007fffff; |
| 47 | if ((addr >= zbaddr) && (addr < (zbaddr + zbcount))) |
| 48 | { |
| 49 | return false; |
| 50 | } |
| 51 | |
| 52 | printf("Check failed: %08x vs. %08x-%08x, %08x-%08x (%d, %d)\n", addr, fbaddr, fbaddr + fbcount, zbaddr, zbaddr + zbcount, MiscState.FBWidth, Scissor.m_yl); |
| 53 | fflush(stdout); |
| 54 | return true; |
| 55 | } |
| 56 | |
| 57 | /*****************************************************************************/ |
| 58 | |
| 59 | // The functions in this file should be moved into the parent Processor class. |
| 60 | #include "rdpfiltr.inc" |
| 61 | |
| 62 | void n64_rdp::GetAlphaCvg(UINT8 *comb_alpha, rdp_span_aux *userdata, const rdp_poly_state &object) |
| 63 | { |
| 64 | INT32 temp = *comb_alpha; |
| 65 | INT32 temp2 = userdata->CurrentPixCvg; |
| 66 | INT32 temp3 = 0; |
| 67 | |
| 68 | if (object.OtherModes.cvg_times_alpha) |
| 69 | { |
| 70 | temp3 = (temp * temp2) + 4; |
| 71 | userdata->CurrentPixCvg = (temp3 >> 8) & 0xf; |
| 72 | } |
| 73 | if (object.OtherModes.alpha_cvg_select) |
| 74 | { |
| 75 | temp = (OtherModes.cvg_times_alpha) ? (temp3 >> 3) : (temp2 << 5); |
| 76 | } |
| 77 | if (temp > 0xff) |
| 78 | { |
| 79 | temp = 0xff; |
| 80 | } |
| 81 | *comb_alpha = temp; |
| 82 | } |
| 83 | |
| 84 | /*****************************************************************************/ |
| 85 | |
| 86 | void n64_rdp::VideoUpdate(n64_periphs *n64, bitmap_rgb32 &bitmap) |
| 87 | { |
| 88 | switch(n64->vi_control & 0x3) |
| 89 | { |
| 90 | case PIXEL_SIZE_16BIT: |
| 91 | VideoUpdate16(n64, bitmap); |
| 92 | break; |
| 93 | |
| 94 | case PIXEL_SIZE_32BIT: |
| 95 | VideoUpdate32(n64, bitmap); |
| 96 | break; |
| 97 | |
| 98 | default: |
| 99 | //fatalerror("Unsupported framebuffer depth: m_fb_size=%d\n", MiscState.FBSize); |
| 100 | break; |
| 101 | } |
| 102 | } |
| 103 | |
| 104 | void n64_rdp::VideoUpdate16(n64_periphs *n64, bitmap_rgb32 &bitmap) |
| 105 | { |
| 106 | //int fsaa = (((n64->vi_control >> 8) & 3) < 2); |
| 107 | //int divot = (n64->vi_control >> 4) & 1; |
| 108 | |
| 109 | //UINT32 prev_cvg = 0; |
| 110 | //UINT32 next_cvg = 0; |
| 111 | //int dither_filter = (n64->vi_control >> 16) & 1; |
| 112 | //int vibuffering = ((n64->vi_control & 2) && fsaa && divot); |
| 113 | |
| 114 | UINT16 *frame_buffer = (UINT16*)&rdram[(n64->vi_origin & 0xffffff) >> 2]; |
| 115 | //UINT32 hb = ((n64->vi_origin & 0xffffff) >> 2) >> 1; |
| 116 | //UINT8* hidden_buffer = &HiddenBits[hb]; |
| 117 | |
| 118 | INT32 hdiff = (n64->vi_hstart & 0x3ff) - ((n64->vi_hstart >> 16) & 0x3ff); |
| 119 | float hcoeff = ((float)(n64->vi_xscale & 0xfff) / (1 << 10)); |
| 120 | UINT32 hres = ((float)hdiff * hcoeff); |
| 121 | INT32 invisiblewidth = n64->vi_width - hres; |
| 122 | |
| 123 | INT32 vdiff = ((n64->vi_vstart & 0x3ff) - ((n64->vi_vstart >> 16) & 0x3ff)) >> 1; |
| 124 | float vcoeff = ((float)(n64->vi_yscale & 0xfff) / (1 << 10)); |
| 125 | UINT32 vres = ((float)vdiff * vcoeff); |
| 126 | |
| 127 | if (vdiff <= 0 || hdiff <= 0) |
| 128 | { |
| 129 | return; |
| 130 | } |
| 131 | |
| 132 | if (hres > 640) // Needed by Top Gear Overdrive (E) |
| 133 | { |
| 134 | invisiblewidth += (hres - 640); |
| 135 | hres = 640; |
| 136 | } |
| 137 | |
| 138 | if (vres > bitmap.height()) // makes Perfect Dark boot w/o crashing |
| 139 | { |
| 140 | vres = bitmap.height(); |
| 141 | } |
| 142 | |
| 143 | UINT32 pixels = 0; |
| 144 | |
| 145 | if (frame_buffer) |
| 146 | { |
| 147 | for(int j = 0; j < vres; j++) |
| 148 | { |
| 149 | UINT32 *d = &bitmap.pix32(j); |
| 150 | |
| 151 | for(int i = 0; i < hres; i++) |
| 152 | { |
| 153 | Color c; |
| 154 | //int r, g, b; |
| 155 | |
| 156 | UINT16 pix = frame_buffer[pixels ^ WORD_ADDR_XOR]; |
| 157 | //MiscState.CurrentPixCvg = ((pix & 1) << 2) | (hidden_buffer[pixels ^ BYTE_ADDR_XOR] & 3); |
| 158 | |
| 159 | //if(divot) |
| 160 | //{ |
| 161 | // if(i > 0 && i < (hres - 1)) |
| 162 | // { |
| 163 | // prev_cvg = ((frame_buffer[(pixels - 1)^WORD_ADDR_XOR] & 1) << 2) | (hidden_buffer[(pixels - 1)^BYTE_ADDR_XOR] & 3); |
| 164 | // next_cvg = ((frame_buffer[(pixels + 1)^WORD_ADDR_XOR] & 1) << 2) | (hidden_buffer[(pixels + 1)^BYTE_ADDR_XOR] & 3); |
| 165 | // } |
| 166 | //} |
| 167 | c.i.r = ((pix >> 8) & 0xf8) | (pix >> 13); |
| 168 | c.i.g = ((pix >> 3) & 0xf8) | ((pix >> 8) & 0x07); |
| 169 | c.i.b = ((pix << 2) & 0xf8) | ((pix >> 3) & 0x07); |
| 170 | |
| 171 | //if(fsaa) |
| 172 | //{ |
| 173 | //if (/*!vibuffering &&*/ state->m_rdp.MiscState.CurrentPixCvg < 7 && i > 1 && j > 1 && i < (hres - 2) && j < (vres - 2)) |
| 174 | //{ |
| 175 | //video_filter16(&c.i.r, &c.i.g, &c.i.b, &frame_buffer[pixels ^ WORD_ADDR_XOR],&hidden_buffer[pixels ^ BYTE_ADDR_XOR], n64->vi_width); |
| 176 | //} |
| 177 | //} |
| 178 | //else if (dither_filter && state->m_rdp.MiscState.CurrentPixCvg == 7 && i > 0 && j > 0 && i < (hres - 1) && j < (vres - 1)) |
| 179 | //{ |
| 180 | //if (vibuffering) |
| 181 | //{ |
| 182 | // restore_filter16_buffer(&r, &g, &b, &ViBuffer[i][j], n64->vi_width); |
| 183 | //} |
| 184 | //else |
| 185 | //{ |
| 186 | //restore_filter16(&c.i.r, &c.i.g, &c.i.b, &frame_buffer[pixels ^ WORD_ADDR_XOR], pixels ^ WORD_ADDR_XOR, n64->vi_width); |
| 187 | //} |
| 188 | //} |
| 189 | //if(divot) |
| 190 | //{ |
| 191 | //if (i > 0 && i < (hres - 1) && (MiscState.CurrentPixCvg != 7 || prev_cvg != 7 || next_cvg != 7)) |
| 192 | //{ |
| 193 | //if (vibuffering) |
| 194 | //{ |
| 195 | // divot_filter16_buffer(&r, &g, &b, &ViBuffer[i][j]); |
| 196 | //} |
| 197 | //else |
| 198 | //{ |
| 199 | //divot_filter16(&c.i.r, &c.i.g, &c.i.b, &frame_buffer[pixels ^ WORD_ADDR_XOR], pixels ^ WORD_ADDR_XOR); |
| 200 | //} |
| 201 | //} |
| 202 | //} |
| 203 | |
| 204 | /* |
| 205 | if (gamma_dither) |
| 206 | { |
| 207 | dith = screen.machine().rand() & 0x3f; |
| 208 | } |
| 209 | if (gamma) |
| 210 | { |
| 211 | if (gamma_dither) |
| 212 | { |
| 213 | r = m_gamma_dither_table[(r << 6)|dith]; |
| 214 | g = m_gamma_dither_table[(g << 6)|dith]; |
| 215 | b = m_gamma_dither_table[(b << 6)|dith]; |
| 216 | } |
| 217 | else |
| 218 | { |
| 219 | r = m_gamma_table[r]; |
| 220 | g = m_gamma_table[g]; |
| 221 | b = m_gamma_table[b]; |
| 222 | } |
| 223 | } |
| 224 | else if (gamma_dither) |
| 225 | { |
| 226 | if (r < 255) |
| 227 | r += (dith & 1); |
| 228 | if (g < 255) |
| 229 | g += (dith & 1); |
| 230 | if (b < 255) |
| 231 | b += (dith & 1); |
| 232 | } |
| 233 | */ |
| 234 | pixels++; |
| 235 | |
| 236 | d[i] = c.c >> 8;//(r << 16) | (g << 8) | b; // Fix me for endianness |
| 237 | } |
| 238 | pixels +=invisiblewidth; |
| 239 | } |
| 240 | } |
| 241 | } |
| 242 | |
| 243 | void n64_rdp::VideoUpdate32(n64_periphs *n64, bitmap_rgb32 &bitmap) |
| 244 | { |
| 245 | int gamma = (n64->vi_control >> 3) & 1; |
| 246 | int gamma_dither = (n64->vi_control >> 2) & 1; |
| 247 | //int vibuffering = ((n64->vi_control & 2) && fsaa && divot); |
| 248 | |
| 249 | UINT32 *frame_buffer32 = (UINT32*)&rdram[(n64->vi_origin & 0xffffff) >> 2]; |
| 250 | |
| 251 | const INT32 hdiff = (n64->vi_hstart & 0x3ff) - ((n64->vi_hstart >> 16) & 0x3ff); |
| 252 | const float hcoeff = ((float)(n64->vi_xscale & 0xfff) / (1 << 10)); |
| 253 | UINT32 hres = ((float)hdiff * hcoeff); |
| 254 | INT32 invisiblewidth = n64->vi_width - hres; |
| 255 | |
| 256 | const INT32 vdiff = ((n64->vi_vstart & 0x3ff) - ((n64->vi_vstart >> 16) & 0x3ff)) >> 1; |
| 257 | const float vcoeff = ((float)(n64->vi_yscale & 0xfff) / (1 << 10)); |
| 258 | const UINT32 vres = ((float)vdiff * vcoeff); |
| 259 | |
| 260 | if (vdiff <= 0 || hdiff <= 0) |
| 261 | { |
| 262 | return; |
| 263 | } |
| 264 | |
| 265 | if (hres > 640) // Needed by Top Gear Overdrive (E) |
| 266 | { |
| 267 | invisiblewidth += (hres - 640); |
| 268 | hres = 640; |
| 269 | } |
| 270 | |
| 271 | if (frame_buffer32) |
| 272 | { |
| 273 | for (int j = 0; j < vres; j++) |
| 274 | { |
| 275 | UINT32 *d = &bitmap.pix32(j); |
| 276 | for (int i = 0; i < hres; i++) |
| 277 | { |
| 278 | UINT32 pix = *frame_buffer32++; |
| 279 | if (gamma || gamma_dither) |
| 280 | { |
| 281 | int r = (pix >> 24) & 0xff; |
| 282 | int g = (pix >> 16) & 0xff; |
| 283 | int b = (pix >> 8) & 0xff; |
| 284 | int dith = 0; |
| 285 | if (gamma_dither) |
| 286 | { |
| 287 | dith = GetRandom() & 0x3f; |
| 288 | } |
| 289 | if (gamma) |
| 290 | { |
| 291 | if (gamma_dither) |
| 292 | { |
| 293 | r = m_gamma_dither_table[(r << 6)| dith]; |
| 294 | g = m_gamma_dither_table[(g << 6)| dith]; |
| 295 | b = m_gamma_dither_table[(b << 6)| dith]; |
| 296 | } |
| 297 | else |
| 298 | { |
| 299 | r = m_gamma_table[r]; |
| 300 | g = m_gamma_table[g]; |
| 301 | b = m_gamma_table[b]; |
| 302 | } |
| 303 | } |
| 304 | else if (gamma_dither) |
| 305 | { |
| 306 | if (r < 255) |
| 307 | r += (dith & 1); |
| 308 | if (g < 255) |
| 309 | g += (dith & 1); |
| 310 | if (b < 255) |
| 311 | b += (dith & 1); |
| 312 | } |
| 313 | pix = (r << 24) | (g << 16) | (b << 8); |
| 314 | } |
| 315 | |
| 316 | |
| 317 | d[i] = (pix >> 8); |
| 318 | } |
| 319 | frame_buffer32 += invisiblewidth; |
| 320 | } |
| 321 | } |
| 322 | } |
| 323 | |
| 324 | /*****************************************************************************/ |
| 325 | |
| 326 | void n64_rdp::TCDivNoPersp(INT32 ss, INT32 st, INT32 sw, INT32* sss, INT32* sst) |
| 327 | { |
| 328 | *sss = (SIGN16(ss)) & 0x1ffff; |
| 329 | *sst = (SIGN16(st)) & 0x1ffff; |
| 330 | } |
| 331 | |
| 332 | void n64_rdp::TCDiv(INT32 ss, INT32 st, INT32 sw, INT32* sss, INT32* sst) |
| 333 | { |
| 334 | int w_carry = 0; |
| 335 | if ((sw & 0x8000) || !(sw & 0x7fff)) |
| 336 | { |
| 337 | w_carry = 1; |
| 338 | } |
| 339 | |
| 340 | sw &= 0x7fff; |
| 341 | |
| 342 | int shift; |
| 343 | for (shift = 1; shift <= 14 && !((sw << shift) & 0x8000); shift++); |
| 344 | shift -= 1; |
| 345 | |
| 346 | int normout = (sw << shift) & 0x3fff; |
| 347 | int wnorm = (normout & 0xff) << 2; |
| 348 | normout >>= 8; |
| 349 | |
| 350 | int temppoint = m_norm_point_rom[normout]; |
| 351 | int tempslope = m_norm_slope_rom[normout]; |
| 352 | |
| 353 | int tlu_rcp = ((-(tempslope * wnorm)) >> 10) + temppoint; |
| 354 | |
| 355 | int sprod = SIGN16(ss) * tlu_rcp; |
| 356 | int tprod = SIGN16(st) * tlu_rcp; |
| 357 | int tempmask = ((1 << (shift + 1)) - 1) << (29 - shift); |
| 358 | int shift_value = 13 - shift; |
| 359 | |
| 360 | int outofbounds_s = sprod & tempmask; |
| 361 | int outofbounds_t = tprod & tempmask; |
| 362 | if (shift == 0xe) |
| 363 | { |
| 364 | *sss = sprod << 1; |
| 365 | *sst = tprod << 1; |
| 366 | } |
| 367 | else |
| 368 | { |
| 369 | *sss = sprod = (sprod >> shift_value); |
| 370 | *sst = tprod = (tprod >> shift_value); |
| 371 | } |
| 372 | //compute clamp flags |
| 373 | int under_s = 0; |
| 374 | int under_t = 0; |
| 375 | int over_s = 0; |
| 376 | int over_t = 0; |
| 377 | |
| 378 | if (outofbounds_s != tempmask && outofbounds_s != 0) |
| 379 | { |
| 380 | if (sprod & (1 << 29)) |
| 381 | { |
| 382 | under_s = 1; |
| 383 | } |
| 384 | else |
| 385 | { |
| 386 | over_s = 1; |
| 387 | } |
| 388 | } |
| 389 | |
| 390 | if (outofbounds_t != tempmask && outofbounds_t != 0) |
| 391 | { |
| 392 | if (tprod & (1 << 29)) |
| 393 | { |
| 394 | under_t = 1; |
| 395 | } |
| 396 | else |
| 397 | { |
| 398 | over_t = 1; |
| 399 | } |
| 400 | } |
| 401 | |
| 402 | over_s |= w_carry; |
| 403 | over_t |= w_carry; |
| 404 | |
| 405 | *sss = (*sss & 0x1ffff) | (over_s << 18) | (under_s << 17); |
| 406 | *sst = (*sst & 0x1ffff) | (over_t << 18) | (under_t << 17); |
| 407 | } |
| 408 | |
| 409 | INT32 n64_rdp::ColorCombinerEquation(INT32 a, INT32 b, INT32 c, INT32 d) |
| 410 | { |
| 411 | a = KURT_AKELEY_SIGN9(a); |
| 412 | b = KURT_AKELEY_SIGN9(b); |
| 413 | c = SIGN9(c); |
| 414 | d = KURT_AKELEY_SIGN9(d); |
| 415 | a = (((a - b) * c) + (d << 8) + 0x80); |
| 416 | a = SIGN17(a) >> 8; |
| 417 | a = s_special_9bit_clamptable[a & 0x1ff]; |
| 418 | return a; |
| 419 | } |
| 420 | |
| 421 | INT32 n64_rdp::AlphaCombinerEquation(INT32 a, INT32 b, INT32 c, INT32 d) |
| 422 | { |
| 423 | a = KURT_AKELEY_SIGN9(a); |
| 424 | b = KURT_AKELEY_SIGN9(b); |
| 425 | c = SIGN9(c); |
| 426 | d = KURT_AKELEY_SIGN9(d); |
| 427 | a = (((a - b) * c) + (d << 8) + 0x80) >> 8; |
| 428 | a = SIGN9(a); |
| 429 | a = s_special_9bit_clamptable[a & 0x1ff]; |
| 430 | return a; |
| 431 | } |
| 432 | |
| 433 | void n64_rdp::SetSubAInputRGB(UINT8 **input_r, UINT8 **input_g, UINT8 **input_b, int code, rdp_span_aux *userdata) |
| 434 | { |
| 435 | switch (code & 0xf) |
| 436 | { |
| 437 | case 0: *input_r = &userdata->CombinedColor.i.r; *input_g = &userdata->CombinedColor.i.g; *input_b = &userdata->CombinedColor.i.b; break; |
| 438 | case 1: *input_r = &userdata->Texel0Color.i.r; *input_g = &userdata->Texel0Color.i.g; *input_b = &userdata->Texel0Color.i.b; break; |
| 439 | case 2: *input_r = &userdata->Texel1Color.i.r; *input_g = &userdata->Texel1Color.i.g; *input_b = &userdata->Texel1Color.i.b; break; |
| 440 | case 3: *input_r = &userdata->PrimColor.i.r; *input_g = &userdata->PrimColor.i.g; *input_b = &userdata->PrimColor.i.b; break; |
| 441 | case 4: *input_r = &userdata->ShadeColor.i.r; *input_g = &userdata->ShadeColor.i.g; *input_b = &userdata->ShadeColor.i.b; break; |
| 442 | case 5: *input_r = &userdata->EnvColor.i.r; *input_g = &userdata->EnvColor.i.g; *input_b = &userdata->EnvColor.i.b; break; |
| 443 | case 6: *input_r = &OneColor.i.r; *input_g = &OneColor.i.g; *input_b = &OneColor.i.b; break; |
| 444 | case 7: *input_r = &userdata->NoiseColor.i.r; *input_g = &userdata->NoiseColor.i.g; *input_b = &userdata->NoiseColor.i.b; break; |
| 445 | case 8: case 9: case 10: case 11: case 12: case 13: case 14: case 15: |
| 446 | { |
| 447 | *input_r = &ZeroColor.i.r; *input_g = &ZeroColor.i.g; *input_b = &ZeroColor.i.b; break; |
| 448 | } |
| 449 | } |
| 450 | } |
| 451 | |
| 452 | void n64_rdp::SetSubBInputRGB(UINT8 **input_r, UINT8 **input_g, UINT8 **input_b, int code, rdp_span_aux *userdata) |
| 453 | { |
| 454 | switch (code & 0xf) |
| 455 | { |
| 456 | case 0: *input_r = &userdata->CombinedColor.i.r; *input_g = &userdata->CombinedColor.i.g; *input_b = &userdata->CombinedColor.i.b; break; |
| 457 | case 1: *input_r = &userdata->Texel0Color.i.r; *input_g = &userdata->Texel0Color.i.g; *input_b = &userdata->Texel0Color.i.b; break; |
| 458 | case 2: *input_r = &userdata->Texel1Color.i.r; *input_g = &userdata->Texel1Color.i.g; *input_b = &userdata->Texel1Color.i.b; break; |
| 459 | case 3: *input_r = &userdata->PrimColor.i.r; *input_g = &userdata->PrimColor.i.g; *input_b = &userdata->PrimColor.i.b; break; |
| 460 | case 4: *input_r = &userdata->ShadeColor.i.r; *input_g = &userdata->ShadeColor.i.g; *input_b = &userdata->ShadeColor.i.b; break; |
| 461 | case 5: *input_r = &userdata->EnvColor.i.r; *input_g = &userdata->EnvColor.i.g; *input_b = &userdata->EnvColor.i.b; break; |
| 462 | case 6: fatalerror("SET_SUBB_RGB_INPUT: key_center\n"); |
| 463 | case 7: *input_r = (UINT8*)&m_k4; *input_g = (UINT8*)&m_k4; *input_b = (UINT8*)&m_k4; break; |
| 464 | case 8: case 9: case 10: case 11: case 12: case 13: case 14: case 15: |
| 465 | { |
| 466 | *input_r = &ZeroColor.i.r; *input_g = &ZeroColor.i.g; *input_b = &ZeroColor.i.b; break; |
| 467 | } |
| 468 | } |
| 469 | } |
| 470 | |
| 471 | void n64_rdp::SetMulInputRGB(UINT8 **input_r, UINT8 **input_g, UINT8 **input_b, int code, rdp_span_aux *userdata) |
| 472 | { |
| 473 | switch (code & 0x1f) |
| 474 | { |
| 475 | case 0: *input_r = &userdata->CombinedColor.i.r; *input_g = &userdata->CombinedColor.i.g; *input_b = &userdata->CombinedColor.i.b; break; |
| 476 | case 1: *input_r = &userdata->Texel0Color.i.r; *input_g = &userdata->Texel0Color.i.g; *input_b = &userdata->Texel0Color.i.b; break; |
| 477 | case 2: *input_r = &userdata->Texel1Color.i.r; *input_g = &userdata->Texel1Color.i.g; *input_b = &userdata->Texel1Color.i.b; break; |
| 478 | case 3: *input_r = &userdata->PrimColor.i.r; *input_g = &userdata->PrimColor.i.g; *input_b = &userdata->PrimColor.i.b; break; |
| 479 | case 4: *input_r = &userdata->ShadeColor.i.r; *input_g = &userdata->ShadeColor.i.g; *input_b = &userdata->ShadeColor.i.b; break; |
| 480 | case 5: *input_r = &userdata->EnvColor.i.r; *input_g = &userdata->EnvColor.i.g; *input_b = &userdata->EnvColor.i.b; break; |
| 481 | case 6: *input_r = &userdata->KeyScale.i.r; *input_g = &userdata->KeyScale.i.g; *input_b = &userdata->KeyScale.i.b; break; |
| 482 | case 7: *input_r = &userdata->CombinedColor.i.a; *input_g = &userdata->CombinedColor.i.a; *input_b = &userdata->CombinedColor.i.a; break; |
| 483 | case 8: *input_r = &userdata->Texel0Color.i.a; *input_g = &userdata->Texel0Color.i.a; *input_b = &userdata->Texel0Color.i.a; break; |
| 484 | case 9: *input_r = &userdata->Texel1Color.i.a; *input_g = &userdata->Texel1Color.i.a; *input_b = &userdata->Texel1Color.i.a; break; |
| 485 | case 10: *input_r = &userdata->PrimColor.i.a; *input_g = &userdata->PrimColor.i.a; *input_b = &userdata->PrimColor.i.a; break; |
| 486 | case 11: *input_r = &userdata->ShadeColor.i.a; *input_g = &userdata->ShadeColor.i.a; *input_b = &userdata->ShadeColor.i.a; break; |
| 487 | case 12: *input_r = &userdata->EnvColor.i.a; *input_g = &userdata->EnvColor.i.a; *input_b = &userdata->EnvColor.i.a; break; |
| 488 | case 13: *input_r = &userdata->LODFraction; *input_g = &userdata->LODFraction; *input_b = &userdata->LODFraction; break; |
| 489 | case 14: *input_r = &userdata->PrimLODFraction; *input_g = &userdata->PrimLODFraction; *input_b = &userdata->PrimLODFraction; break; |
| 490 | case 15: *input_r = (UINT8*)&m_k5; *input_g = (UINT8*)&m_k5; *input_b = (UINT8*)&m_k5; break; |
| 491 | case 16: case 17: case 18: case 19: case 20: case 21: case 22: case 23: |
| 492 | case 24: case 25: case 26: case 27: case 28: case 29: case 30: case 31: |
| 493 | { |
| 494 | *input_r = &ZeroColor.i.r; *input_g = &ZeroColor.i.g; *input_b = &ZeroColor.i.b; break; |
| 495 | } |
| 496 | } |
| 497 | } |
| 498 | |
| 499 | void n64_rdp::SetAddInputRGB(UINT8 **input_r, UINT8 **input_g, UINT8 **input_b, int code, rdp_span_aux *userdata) |
| 500 | { |
| 501 | switch (code & 0x7) |
| 502 | { |
| 503 | case 0: *input_r = &userdata->CombinedColor.i.r; *input_g = &userdata->CombinedColor.i.g; *input_b = &userdata->CombinedColor.i.b; break; |
| 504 | case 1: *input_r = &userdata->Texel0Color.i.r; *input_g = &userdata->Texel0Color.i.g; *input_b = &userdata->Texel0Color.i.b; break; |
| 505 | case 2: *input_r = &userdata->Texel1Color.i.r; *input_g = &userdata->Texel1Color.i.g; *input_b = &userdata->Texel1Color.i.b; break; |
| 506 | case 3: *input_r = &userdata->PrimColor.i.r; *input_g = &userdata->PrimColor.i.g; *input_b = &userdata->PrimColor.i.b; break; |
| 507 | case 4: *input_r = &userdata->ShadeColor.i.r; *input_g = &userdata->ShadeColor.i.g; *input_b = &userdata->ShadeColor.i.b; break; |
| 508 | case 5: *input_r = &userdata->EnvColor.i.r; *input_g = &userdata->EnvColor.i.g; *input_b = &userdata->EnvColor.i.b; break; |
| 509 | case 6: *input_r = &OneColor.i.r; *input_g = &OneColor.i.g; *input_b = &OneColor.i.b; break; |
| 510 | case 7: *input_r = &ZeroColor.i.r; *input_g = &ZeroColor.i.g; *input_b = &ZeroColor.i.b; break; |
| 511 | } |
| 512 | } |
| 513 | |
| 514 | void n64_rdp::SetSubInputAlpha(UINT8 **input, int code, rdp_span_aux *userdata) |
| 515 | { |
| 516 | switch (code & 0x7) |
| 517 | { |
| 518 | case 0: *input = &userdata->CombinedColor.i.a; break; |
| 519 | case 1: *input = &userdata->Texel0Color.i.a; break; |
| 520 | case 2: *input = &userdata->Texel1Color.i.a; break; |
| 521 | case 3: *input = &userdata->PrimColor.i.a; break; |
| 522 | case 4: *input = &userdata->ShadeColor.i.a; break; |
| 523 | case 5: *input = &userdata->EnvColor.i.a; break; |
| 524 | case 6: *input = &OneColor.i.a; break; |
| 525 | case 7: *input = &ZeroColor.i.a; break; |
| 526 | } |
| 527 | } |
| 528 | |
| 529 | void n64_rdp::SetMulInputAlpha(UINT8 **input, int code, rdp_span_aux *userdata) |
| 530 | { |
| 531 | switch (code & 0x7) |
| 532 | { |
| 533 | case 0: *input = &userdata->LODFraction; break; |
| 534 | case 1: *input = &userdata->Texel0Color.i.a; break; |
| 535 | case 2: *input = &userdata->Texel1Color.i.a; break; |
| 536 | case 3: *input = &userdata->PrimColor.i.a; break; |
| 537 | case 4: *input = &userdata->ShadeColor.i.a; break; |
| 538 | case 5: *input = &userdata->EnvColor.i.a; break; |
| 539 | case 6: *input = &userdata->PrimLODFraction; break; |
| 540 | case 7: *input = &ZeroColor.i.a; break; |
| 541 | } |
| 542 | } |
| 543 | |
| 544 | void n64_rdp::SetBlenderInput(int cycle, int which, UINT8 **input_r, UINT8 **input_g, UINT8 **input_b, UINT8 **input_a, int a, int b, rdp_span_aux *userdata) |
| 545 | { |
| 546 | switch (a & 0x3) |
| 547 | { |
| 548 | case 0: |
| 549 | { |
| 550 | if (cycle == 0) |
| 551 | { |
| 552 | *input_r = &userdata->PixelColor.i.r; |
| 553 | *input_g = &userdata->PixelColor.i.g; |
| 554 | *input_b = &userdata->PixelColor.i.b; |
| 555 | } |
| 556 | else |
| 557 | { |
| 558 | *input_r = &userdata->BlendedPixelColor.i.r; |
| 559 | *input_g = &userdata->BlendedPixelColor.i.g; |
| 560 | *input_b = &userdata->BlendedPixelColor.i.b; |
| 561 | } |
| 562 | break; |
| 563 | } |
| 564 | |
| 565 | case 1: |
| 566 | { |
| 567 | *input_r = &userdata->MemoryColor.i.r; |
| 568 | *input_g = &userdata->MemoryColor.i.g; |
| 569 | *input_b = &userdata->MemoryColor.i.b; |
| 570 | break; |
| 571 | } |
| 572 | |
| 573 | case 2: |
| 574 | { |
| 575 | *input_r = &userdata->BlendColor.i.r; |
| 576 | *input_g = &userdata->BlendColor.i.g; |
| 577 | *input_b = &userdata->BlendColor.i.b; |
| 578 | break; |
| 579 | } |
| 580 | |
| 581 | case 3: |
| 582 | { |
| 583 | *input_r = &userdata->FogColor.i.r; |
| 584 | *input_g = &userdata->FogColor.i.g; |
| 585 | *input_b = &userdata->FogColor.i.b; |
| 586 | break; |
| 587 | } |
| 588 | } |
| 589 | |
| 590 | if (which == 0) |
| 591 | { |
| 592 | switch (b & 0x3) |
| 593 | { |
| 594 | case 0: *input_a = &userdata->PixelColor.i.a; break; |
| 595 | case 1: *input_a = &userdata->FogColor.i.a; break; |
| 596 | case 2: *input_a = &userdata->ShadeColor.i.a; break; |
| 597 | case 3: *input_a = &ZeroColor.i.a; break; |
| 598 | } |
| 599 | } |
| 600 | else |
| 601 | { |
| 602 | switch (b & 0x3) |
| 603 | { |
| 604 | case 0: *input_a = &userdata->InvPixelColor.i.a; break; |
| 605 | case 1: *input_a = &userdata->MemoryColor.i.a; break; |
| 606 | case 2: *input_a = &OneColor.i.a; break; |
| 607 | case 3: *input_a = &ZeroColor.i.a; break; |
| 608 | } |
| 609 | } |
| 610 | } |
| 611 | |
| 612 | const UINT8 n64_rdp::s_bayer_matrix[16] = |
| 613 | { /* Bayer matrix */ |
| 614 | 0, 4, 1, 5, |
| 615 | 6, 2, 7, 3, |
| 616 | 1, 5, 0, 4, |
| 617 | 7, 3, 6, 2 |
| 618 | }; |
| 619 | |
| 620 | const UINT8 n64_rdp::s_magic_matrix[16] = |
| 621 | { /* Magic square matrix */ |
| 622 | 0, 6, 1, 7, |
| 623 | 4, 2, 5, 3, |
| 624 | 3, 5, 2, 4, |
| 625 | 7, 1, 6, 0 |
| 626 | }; |
| 627 | |
| 628 | const n64_rdp::ZDecompressEntry n64_rdp::z_dec_table[8] = |
| 629 | { |
| 630 | { 6, 0x00000 }, |
| 631 | { 5, 0x20000 }, |
| 632 | { 4, 0x30000 }, |
| 633 | { 3, 0x38000 }, |
| 634 | { 2, 0x3c000 }, |
| 635 | { 1, 0x3e000 }, |
| 636 | { 0, 0x3f000 }, |
| 637 | { 0, 0x3f800 }, |
| 638 | }; |
| 639 | |
| 640 | /*****************************************************************************/ |
| 641 | |
| 642 | void n64_rdp::z_build_com_table(void) |
| 643 | { |
| 644 | UINT16 altmem = 0; |
| 645 | for(int z = 0; z < 0x40000; z++) |
| 646 | { |
| 647 | switch((z >> 11) & 0x7f) |
| 648 | { |
| 649 | case 0x00: |
| 650 | case 0x01: |
| 651 | case 0x02: |
| 652 | case 0x03: |
| 653 | case 0x04: |
| 654 | case 0x05: |
| 655 | case 0x06: |
| 656 | case 0x07: |
| 657 | case 0x08: |
| 658 | case 0x09: |
| 659 | case 0x0a: |
| 660 | case 0x0b: |
| 661 | case 0x0c: |
| 662 | case 0x0d: |
| 663 | case 0x0e: |
| 664 | case 0x0f: |
| 665 | case 0x10: |
| 666 | case 0x11: |
| 667 | case 0x12: |
| 668 | case 0x13: |
| 669 | case 0x14: |
| 670 | case 0x15: |
| 671 | case 0x16: |
| 672 | case 0x17: |
| 673 | case 0x18: |
| 674 | case 0x19: |
| 675 | case 0x1a: |
| 676 | case 0x1b: |
| 677 | case 0x1c: |
| 678 | case 0x1d: |
| 679 | case 0x1e: |
| 680 | case 0x1f: |
| 681 | case 0x20: |
| 682 | case 0x21: |
| 683 | case 0x22: |
| 684 | case 0x23: |
| 685 | case 0x24: |
| 686 | case 0x25: |
| 687 | case 0x26: |
| 688 | case 0x27: |
| 689 | case 0x28: |
| 690 | case 0x29: |
| 691 | case 0x2a: |
| 692 | case 0x2b: |
| 693 | case 0x2c: |
| 694 | case 0x2d: |
| 695 | case 0x2e: |
| 696 | case 0x2f: |
| 697 | case 0x30: |
| 698 | case 0x31: |
| 699 | case 0x32: |
| 700 | case 0x33: |
| 701 | case 0x34: |
| 702 | case 0x35: |
| 703 | case 0x36: |
| 704 | case 0x37: |
| 705 | case 0x38: |
| 706 | case 0x39: |
| 707 | case 0x3a: |
| 708 | case 0x3b: |
| 709 | case 0x3c: |
| 710 | case 0x3d: |
| 711 | case 0x3e: |
| 712 | case 0x3f: |
| 713 | altmem = (z >> 4) & 0x1ffc; |
| 714 | break; |
| 715 | case 0x40: |
| 716 | case 0x41: |
| 717 | case 0x42: |
| 718 | case 0x43: |
| 719 | case 0x44: |
| 720 | case 0x45: |
| 721 | case 0x46: |
| 722 | case 0x47: |
| 723 | case 0x48: |
| 724 | case 0x49: |
| 725 | case 0x4a: |
| 726 | case 0x4b: |
| 727 | case 0x4c: |
| 728 | case 0x4d: |
| 729 | case 0x4e: |
| 730 | case 0x4f: |
| 731 | case 0x50: |
| 732 | case 0x51: |
| 733 | case 0x52: |
| 734 | case 0x53: |
| 735 | case 0x54: |
| 736 | case 0x55: |
| 737 | case 0x56: |
| 738 | case 0x57: |
| 739 | case 0x58: |
| 740 | case 0x59: |
| 741 | case 0x5a: |
| 742 | case 0x5b: |
| 743 | case 0x5c: |
| 744 | case 0x5d: |
| 745 | case 0x5e: |
| 746 | case 0x5f: |
| 747 | altmem = ((z >> 3) & 0x1ffc) | 0x2000; |
| 748 | break; |
| 749 | case 0x60: |
| 750 | case 0x61: |
| 751 | case 0x62: |
| 752 | case 0x63: |
| 753 | case 0x64: |
| 754 | case 0x65: |
| 755 | case 0x66: |
| 756 | case 0x67: |
| 757 | case 0x68: |
| 758 | case 0x69: |
| 759 | case 0x6a: |
| 760 | case 0x6b: |
| 761 | case 0x6c: |
| 762 | case 0x6d: |
| 763 | case 0x6e: |
| 764 | case 0x6f: |
| 765 | altmem = ((z >> 2) & 0x1ffc) | 0x4000; |
| 766 | break; |
| 767 | case 0x70: |
| 768 | case 0x71: |
| 769 | case 0x72: |
| 770 | case 0x73: |
| 771 | case 0x74: |
| 772 | case 0x75: |
| 773 | case 0x76: |
| 774 | case 0x77: |
| 775 | altmem = ((z >> 1) & 0x1ffc) | 0x6000; |
| 776 | break; |
| 777 | case 0x78://uncompressed z = 0x3c000 |
| 778 | case 0x79: |
| 779 | case 0x7a: |
| 780 | case 0x7b: |
| 781 | altmem = (z & 0x1ffc) | 0x8000; |
| 782 | break; |
| 783 | case 0x7c://uncompressed z = 0x3e000 |
| 784 | case 0x7d: |
| 785 | altmem = ((z << 1) & 0x1ffc) | 0xa000; |
| 786 | break; |
| 787 | case 0x7e://uncompressed z = 0x3f000 |
| 788 | altmem = ((z << 2) & 0x1ffc) | 0xc000; |
| 789 | break; |
| 790 | case 0x7f://uncompressed z = 0x3f000 |
| 791 | altmem = ((z << 2) & 0x1ffc) | 0xe000; |
| 792 | break; |
| 793 | } |
| 794 | |
| 795 | z_com_table[z] = altmem; |
| 796 | |
| 797 | } |
| 798 | } |
| 799 | |
| 800 | void n64_rdp::precalc_cvmask_derivatives(void) |
| 801 | { |
| 802 | const UINT8 yarray[16] = {0, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0}; |
| 803 | const UINT8 xarray[16] = {0, 3, 2, 2, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0}; |
| 804 | |
| 805 | for (int i = 0; i < 0x10000; i++) |
| 806 | { |
| 807 | compressed_cvmasks[i] = (i & 1) | ((i & 4) >> 1) | ((i & 0x20) >> 3) | ((i & 0x80) >> 4) | |
| 808 | ((i & 0x100) >> 4) | ((i & 0x400) >> 5) | ((i & 0x2000) >> 7) | ((i & 0x8000) >> 8); |
| 809 | } |
| 810 | |
| 811 | for (int i = 0; i < 0x100; i++) |
| 812 | { |
| 813 | UINT16 mask = decompress_cvmask_frombyte(i); |
| 814 | cvarray[i].cvg = cvarray[i].cvbit = 0; |
| 815 | cvarray[i].cvbit = (i >> 7) & 1; |
| 816 | for (int k = 0; k < 8; k++) |
| 817 | { |
| 818 | cvarray[i].cvg += ((i >> k) & 1); |
| 819 | } |
| 820 | |
| 821 | UINT16 masky = 0; |
| 822 | for (int k = 0; k < 4; k++) |
| 823 | { |
| 824 | masky |= ((mask & (0xf000 >> (k << 2))) > 0) << k; |
| 825 | } |
| 826 | UINT8 offy = yarray[masky]; |
| 827 | |
| 828 | UINT16 maskx = (mask & (0xf000 >> (offy << 2))) >> ((offy ^ 3) << 2); |
| 829 | UINT8 offx = xarray[maskx]; |
| 830 | |
| 831 | cvarray[i].xoff = offx; |
| 832 | cvarray[i].yoff = offy; |
| 833 | } |
| 834 | } |
| 835 | |
| 836 | UINT16 n64_rdp::decompress_cvmask_frombyte(UINT8 x) |
| 837 | { |
| 838 | UINT16 y = (x & 1) | ((x & 2) << 1) | ((x & 4) << 3) | ((x & 8) << 4) | |
| 839 | ((x & 0x10) << 4) | ((x & 0x20) << 5) | ((x & 0x40) << 7) | ((x & 0x80) << 8); |
| 840 | return y; |
| 841 | } |
| 842 | |
| 843 | void n64_rdp::lookup_cvmask_derivatives(UINT32 mask, UINT8* offx, UINT8* offy, rdp_span_aux *userdata) |
| 844 | { |
| 845 | UINT32 index = compressed_cvmasks[mask]; |
| 846 | userdata->CurrentPixCvg = cvarray[index].cvg; |
| 847 | userdata->CurrentCvgBit = cvarray[index].cvbit; |
| 848 | *offx = cvarray[index].xoff; |
| 849 | *offy = cvarray[index].yoff; |
| 850 | } |
| 851 | |
| 852 | void n64_rdp::ZStore(const rdp_poly_state &object, UINT32 zcurpixel, UINT32 dzcurpixel, UINT32 z, UINT32 enc) |
| 853 | { |
| 854 | UINT16 zval = z_com_table[z & 0x3ffff]|(enc >> 2); |
| 855 | if(zcurpixel <= MEM16_LIMIT) |
| 856 | { |
| 857 | ((UINT16*)rdram)[zcurpixel ^ WORD_ADDR_XOR] = zval; |
| 858 | } |
| 859 | if(dzcurpixel <= MEM8_LIMIT) |
| 860 | { |
| 861 | HiddenBits[dzcurpixel ^ BYTE_ADDR_XOR] = enc & 3; |
| 862 | } |
| 863 | } |
| 864 | |
| 865 | INT32 n64_rdp::NormalizeDZPix(INT32 sum) |
| 866 | { |
| 867 | if (sum & 0xc000) |
| 868 | { |
| 869 | return 0x8000; |
| 870 | } |
| 871 | if (!(sum & 0xffff)) |
| 872 | { |
| 873 | return 1; |
| 874 | } |
| 875 | for(int count = 0x2000; count > 0; count >>= 1) |
| 876 | { |
| 877 | if (sum & count) |
| 878 | { |
| 879 | return(count << 1); |
| 880 | } |
| 881 | } |
| 882 | return 0; |
| 883 | } |
| 884 | |
| 885 | UINT32 n64_rdp::ZDecompress(UINT32 zcurpixel) |
| 886 | { |
| 887 | UINT32 zb = RREADIDX16(zcurpixel); |
| 888 | CHECK16(zcurpixel); |
| 889 | return z_complete_dec_table[(zb >> 2) & 0x3fff]; |
| 890 | } |
| 891 | |
| 892 | UINT32 n64_rdp::DZDecompress(UINT32 zcurpixel, UINT32 dzcurpixel) |
| 893 | { |
| 894 | UINT16 zval = RREADIDX16(zcurpixel); |
| 895 | CHECK16(zcurpixel); |
| 896 | UINT8 dzval = (((dzcurpixel) <= 0x7fffff) ? (HiddenBits[(dzcurpixel) ^ BYTE_ADDR_XOR]) : 0); |
| 897 | UINT32 dz_compressed = ((zval & 3) << 2) | (dzval & 3); |
| 898 | return (1 << dz_compressed); |
| 899 | } |
| 900 | |
| 901 | UINT32 n64_rdp::DZCompress(UINT32 value) |
| 902 | { |
| 903 | INT32 j = 0; |
| 904 | for (; value > 1; j++, value >>= 1); |
| 905 | return j; |
| 906 | } |
| 907 | |
| 908 | void n64_rdp::GetDitherValues(int x, int y, int* cdith, int* adith, const rdp_poly_state& object) |
| 909 | { |
| 910 | int dithindex = ((y & 3) << 2) | (x & 3); |
| 911 | switch((object.OtherModes.rgb_dither_sel << 2) | object.OtherModes.alpha_dither_sel) |
| 912 | { |
| 913 | case 0: |
| 914 | *adith = *cdith = s_magic_matrix[dithindex]; |
| 915 | break; |
| 916 | case 1: |
| 917 | *cdith = s_magic_matrix[dithindex]; |
| 918 | *adith = (~(*cdith)) & 7; |
| 919 | break; |
| 920 | case 2: |
| 921 | *cdith = s_magic_matrix[dithindex]; |
| 922 | *adith = machine().rand() & 7; |
| 923 | break; |
| 924 | case 3: |
| 925 | *cdith = s_magic_matrix[dithindex]; |
| 926 | *adith = 0; |
| 927 | break; |
| 928 | case 4: |
| 929 | *adith = *cdith = s_bayer_matrix[dithindex]; |
| 930 | break; |
| 931 | case 5: |
| 932 | *cdith = s_bayer_matrix[dithindex]; |
| 933 | *adith = (~(*cdith)) & 7; |
| 934 | break; |
| 935 | case 6: |
| 936 | *cdith = s_bayer_matrix[dithindex]; |
| 937 | *adith = machine().rand() & 7; |
| 938 | break; |
| 939 | case 7: |
| 940 | *cdith = s_bayer_matrix[dithindex]; |
| 941 | *adith = 0; |
| 942 | break; |
| 943 | case 8: |
| 944 | *cdith = machine().rand() & 7; |
| 945 | *adith = s_magic_matrix[dithindex]; |
| 946 | break; |
| 947 | case 9: |
| 948 | *cdith = machine().rand() & 7; |
| 949 | *adith = (~s_magic_matrix[dithindex]) & 7; |
| 950 | break; |
| 951 | case 10: |
| 952 | *cdith = machine().rand() & 7; |
| 953 | *adith = (*cdith + 17) & 7; |
| 954 | break; |
| 955 | case 11: |
| 956 | *cdith = machine().rand() & 7; |
| 957 | *adith = 0; |
| 958 | break; |
| 959 | case 12: |
| 960 | *cdith = 0; |
| 961 | *adith = s_bayer_matrix[dithindex]; |
| 962 | break; |
| 963 | case 13: |
| 964 | *cdith = 0; |
| 965 | *adith = (~s_bayer_matrix[dithindex]) & 7; |
| 966 | break; |
| 967 | case 14: |
| 968 | *cdith = 0; |
| 969 | *adith = m_machine->rand() & 7; |
| 970 | break; |
| 971 | case 15: |
| 972 | *adith = *cdith = 0; |
| 973 | break; |
| 974 | } |
| 975 | } |
| 976 | |
| 977 | INT32 CLAMP(INT32 in, INT32 min, INT32 max) |
| 978 | { |
| 979 | if(in < min) return min; |
| 980 | if(in > max) return max; |
| 981 | return in; |
| 982 | } |
| 983 | |
| 984 | bool n64_rdp::ZCompare(UINT32 zcurpixel, UINT32 dzcurpixel, UINT32 sz, UINT16 dzpix, rdp_span_aux *userdata, const rdp_poly_state &object) |
| 985 | { |
| 986 | bool force_coplanar = false; |
| 987 | sz &= 0x3ffff; |
| 988 | |
| 989 | UINT32 oz; |
| 990 | UINT32 dzmem; |
| 991 | UINT32 zval; |
| 992 | INT32 rawdzmem; |
| 993 | |
| 994 | if (object.OtherModes.z_compare_en) |
| 995 | { |
| 996 | oz = ZDecompress(zcurpixel); |
| 997 | dzmem = DZDecompress(zcurpixel, dzcurpixel); |
| 998 | zval = RREADIDX16(zcurpixel); |
| 999 | CHECK16(zcurpixel); |
| 1000 | rawdzmem = ((zval & 3) << 2) | ((((dzcurpixel) <= 0x3fffff) ? (HiddenBits[(dzcurpixel) ^ BYTE_ADDR_XOR]) : 0) & 3); |
| 1001 | } |
| 1002 | else |
| 1003 | { |
| 1004 | oz = 0; |
| 1005 | dzmem = 1 << 0xf; |
| 1006 | zval = 0x3; |
| 1007 | rawdzmem = 0xf; |
| 1008 | } |
| 1009 | |
| 1010 | userdata->m_dzpix_enc = DZCompress(dzpix & 0xffff); |
| 1011 | userdata->ShiftA = CLAMP(userdata->m_dzpix_enc - rawdzmem, 0, 4); |
| 1012 | userdata->ShiftB = CLAMP(rawdzmem - userdata->m_dzpix_enc, 0, 4); |
| 1013 | |
| 1014 | int precision_factor = (zval >> 13) & 0xf; |
| 1015 | if (precision_factor < 3) |
| 1016 | { |
| 1017 | int dzmemmodifier = 16 >> precision_factor; |
| 1018 | if (dzmem == 0x8000) |
| 1019 | { |
| 1020 | force_coplanar = true; |
| 1021 | } |
| 1022 | dzmem <<= 1; |
| 1023 | if (dzmem <= dzmemmodifier) |
| 1024 | { |
| 1025 | dzmem = dzmemmodifier; |
| 1026 | } |
| 1027 | if (!dzmem) |
| 1028 | { |
| 1029 | dzmem = 0xffff; |
| 1030 | } |
| 1031 | } |
| 1032 | if (dzmem > 0x8000) |
| 1033 | { |
| 1034 | dzmem = 0xffff; |
| 1035 | } |
| 1036 | |
| 1037 | UINT32 dznew = (dzmem > dzpix) ? dzmem : (UINT32)dzpix; |
| 1038 | UINT32 dznotshift = dznew; |
| 1039 | dznew <<= 3; |
| 1040 | |
| 1041 | bool farther = (sz + dznew) >= oz; |
| 1042 | bool infront = sz < oz; |
| 1043 | |
| 1044 | if (force_coplanar) |
| 1045 | { |
| 1046 | farther = true; |
| 1047 | } |
| 1048 | |
| 1049 | bool overflow = ((userdata->CurrentMemCvg + userdata->CurrentPixCvg) & 8) > 0; |
| 1050 | userdata->BlendEnable = (object.OtherModes.force_blend || (!overflow && object.OtherModes.antialias_en && farther)) ? 1 : 0; |
| 1051 | userdata->PreWrap = overflow; |
| 1052 | |
| 1053 | int cvgcoeff = 0; |
| 1054 | UINT32 dzenc = 0; |
| 1055 | |
| 1056 | if (object.OtherModes.z_mode == 1 && infront && farther && overflow) |
| 1057 | { |
| 1058 | dzenc = DZCompress(dznotshift & 0xffff); |
| 1059 | cvgcoeff = ((oz >> dzenc) - (sz >> dzenc)) & 0xf; |
| 1060 | userdata->CurrentPixCvg = ((cvgcoeff * userdata->CurrentPixCvg) >> 3) & 0xf; |
| 1061 | } |
| 1062 | |
| 1063 | if (!object.OtherModes.z_compare_en) |
| 1064 | { |
| 1065 | return true; |
| 1066 | } |
| 1067 | |
| 1068 | INT32 diff = (INT32)sz - (INT32)dznew; |
| 1069 | bool nearer = diff <= (INT32)oz; |
| 1070 | bool max = (oz == 0x3ffff); |
| 1071 | if (force_coplanar) |
| 1072 | { |
| 1073 | nearer = true; |
| 1074 | } |
| 1075 | |
| 1076 | switch(object.OtherModes.z_mode) |
| 1077 | { |
| 1078 | case 0: |
| 1079 | return (max || (overflow ? infront : nearer)); |
| 1080 | case 1: |
| 1081 | return (max || (overflow ? infront : nearer)); |
| 1082 | case 2: |
| 1083 | return (infront || max); |
| 1084 | case 3: |
| 1085 | return (farther && nearer && !max); |
| 1086 | } |
| 1087 | |
| 1088 | return false; |
| 1089 | } |
| 1090 | |
| 1091 | UINT32 n64_rdp::GetLog2(UINT32 lod_clamp) |
| 1092 | { |
| 1093 | if (lod_clamp < 2) |
| 1094 | { |
| 1095 | return 0; |
| 1096 | } |
| 1097 | else |
| 1098 | { |
| 1099 | for (int i = 7; i > 0; i--) |
| 1100 | { |
| 1101 | if ((lod_clamp >> i) & 1) |
| 1102 | { |
| 1103 | return i; |
| 1104 | } |
| 1105 | } |
| 1106 | } |
| 1107 | |
| 1108 | return 0; |
| 1109 | } |
| 1110 | |
| 1111 | /*****************************************************************************/ |
| 1112 | |
| 1113 | UINT32 n64_rdp::ReadData(UINT32 address) |
| 1114 | { |
| 1115 | if (m_status & 0x1) // XBUS_DMEM_DMA enabled |
| 1116 | { |
| 1117 | return rsp_dmem[(address & 0xfff) / 4]; |
| 1118 | } |
| 1119 | else |
| 1120 | { |
| 1121 | return rdram[((address & 0xffffff) / 4)]; |
| 1122 | } |
| 1123 | } |
| 1124 | |
| 1125 | static const char *const image_format[] = { "RGBA", "YUV", "CI", "IA", "I", "???", "???", "???" }; |
| 1126 | static const char *const image_size[] = { "4-bit", "8-bit", "16-bit", "32-bit" }; |
| 1127 | |
| 1128 | static const int rdp_command_length[64] = |
| 1129 | { |
| 1130 | 8, // 0x00, No Op |
| 1131 | 8, // 0x01, ??? |
| 1132 | 8, // 0x02, ??? |
| 1133 | 8, // 0x03, ??? |
| 1134 | 8, // 0x04, ??? |
| 1135 | 8, // 0x05, ??? |
| 1136 | 8, // 0x06, ??? |
| 1137 | 8, // 0x07, ??? |
| 1138 | 32, // 0x08, Non-Shaded Triangle |
| 1139 | 32+16, // 0x09, Non-Shaded, Z-Buffered Triangle |
| 1140 | 32+64, // 0x0a, Textured Triangle |
| 1141 | 32+64+16, // 0x0b, Textured, Z-Buffered Triangle |
| 1142 | 32+64, // 0x0c, Shaded Triangle |
| 1143 | 32+64+16, // 0x0d, Shaded, Z-Buffered Triangle |
| 1144 | 32+64+64, // 0x0e, Shaded+Textured Triangle |
| 1145 | 32+64+64+16,// 0x0f, Shaded+Textured, Z-Buffered Triangle |
| 1146 | 8, // 0x10, ??? |
| 1147 | 8, // 0x11, ??? |
| 1148 | 8, // 0x12, ??? |
| 1149 | 8, // 0x13, ??? |
| 1150 | 8, // 0x14, ??? |
| 1151 | 8, // 0x15, ??? |
| 1152 | 8, // 0x16, ??? |
| 1153 | 8, // 0x17, ??? |
| 1154 | 8, // 0x18, ??? |
| 1155 | 8, // 0x19, ??? |
| 1156 | 8, // 0x1a, ??? |
| 1157 | 8, // 0x1b, ??? |
| 1158 | 8, // 0x1c, ??? |
| 1159 | 8, // 0x1d, ??? |
| 1160 | 8, // 0x1e, ??? |
| 1161 | 8, // 0x1f, ??? |
| 1162 | 8, // 0x20, ??? |
| 1163 | 8, // 0x21, ??? |
| 1164 | 8, // 0x22, ??? |
| 1165 | 8, // 0x23, ??? |
| 1166 | 16, // 0x24, Texture_Rectangle |
| 1167 | 16, // 0x25, Texture_Rectangle_Flip |
| 1168 | 8, // 0x26, Sync_Load |
| 1169 | 8, // 0x27, Sync_Pipe |
| 1170 | 8, // 0x28, Sync_Tile |
| 1171 | 8, // 0x29, Sync_Full |
| 1172 | 8, // 0x2a, Set_Key_GB |
| 1173 | 8, // 0x2b, Set_Key_R |
| 1174 | 8, // 0x2c, Set_Convert |
| 1175 | 8, // 0x2d, Set_Scissor |
| 1176 | 8, // 0x2e, Set_Prim_Depth |
| 1177 | 8, // 0x2f, Set_Other_Modes |
| 1178 | 8, // 0x30, Load_TLUT |
| 1179 | 8, // 0x31, ??? |
| 1180 | 8, // 0x32, Set_Tile_Size |
| 1181 | 8, // 0x33, Load_Block |
| 1182 | 8, // 0x34, Load_Tile |
| 1183 | 8, // 0x35, Set_Tile |
| 1184 | 8, // 0x36, Fill_Rectangle |
| 1185 | 8, // 0x37, Set_Fill_Color |
| 1186 | 8, // 0x38, Set_Fog_Color |
| 1187 | 8, // 0x39, Set_Blend_Color |
| 1188 | 8, // 0x3a, Set_Prim_Color |
| 1189 | 8, // 0x3b, Set_Env_Color |
| 1190 | 8, // 0x3c, Set_Combine |
| 1191 | 8, // 0x3d, Set_Texture_Image |
| 1192 | 8, // 0x3e, Set_Mask_Image |
| 1193 | 8 // 0x3f, Set_Color_Image |
| 1194 | }; |
| 1195 | |
| 1196 | void n64_rdp::Dasm(char *buffer) |
| 1197 | { |
| 1198 | int i; |
| 1199 | int tile; |
| 1200 | const char *format, *size; |
| 1201 | char sl[32], tl[32], sh[32], th[32]; |
| 1202 | char s[32], t[32], w[32]; |
| 1203 | char dsdx[32], dtdx[32], dwdx[32]; |
| 1204 | char dsdy[32], dtdy[32], dwdy[32]; |
| 1205 | char dsde[32], dtde[32], dwde[32]; |
| 1206 | char yl[32], yh[32], ym[32], xl[32], xh[32], xm[32]; |
| 1207 | char dxldy[32], dxhdy[32], dxmdy[32]; |
| 1208 | char rt[32], gt[32], bt[32], at[32]; |
| 1209 | char drdx[32], dgdx[32], dbdx[32], dadx[32]; |
| 1210 | char drdy[32], dgdy[32], dbdy[32], dady[32]; |
| 1211 | char drde[32], dgde[32], dbde[32], dade[32]; |
| 1212 | UINT32 r,g,b,a; |
| 1213 | |
| 1214 | UINT32 cmd[64]; |
| 1215 | UINT32 length; |
| 1216 | UINT32 command; |
| 1217 | |
| 1218 | length = m_cmd_ptr * 4; |
| 1219 | if (length < 8) |
| 1220 | { |
| 1221 | sprintf(buffer, "ERROR: length = %d\n", length); |
| 1222 | return; |
| 1223 | } |
| 1224 | |
| 1225 | cmd[0] = m_cmd_data[m_cmd_cur+0]; |
| 1226 | cmd[1] = m_cmd_data[m_cmd_cur+1]; |
| 1227 | |
| 1228 | tile = (cmd[1] >> 24) & 0x7; |
| 1229 | sprintf(sl, "%4.2f", (float)((cmd[0] >> 12) & 0xfff) / 4.0f); |
| 1230 | sprintf(tl, "%4.2f", (float)((cmd[0] >> 0) & 0xfff) / 4.0f); |
| 1231 | sprintf(sh, "%4.2f", (float)((cmd[1] >> 12) & 0xfff) / 4.0f); |
| 1232 | sprintf(th, "%4.2f", (float)((cmd[1] >> 0) & 0xfff) / 4.0f); |
| 1233 | |
| 1234 | format = image_format[(cmd[0] >> 21) & 0x7]; |
| 1235 | size = image_size[(cmd[0] >> 19) & 0x3]; |
| 1236 | |
| 1237 | r = (cmd[1] >> 24) & 0xff; |
| 1238 | g = (cmd[1] >> 16) & 0xff; |
| 1239 | b = (cmd[1] >> 8) & 0xff; |
| 1240 | a = (cmd[1] >> 0) & 0xff; |
| 1241 | |
| 1242 | command = (cmd[0] >> 24) & 0x3f; |
| 1243 | switch (command) |
| 1244 | { |
| 1245 | case 0x00: sprintf(buffer, "No Op"); break; |
| 1246 | case 0x08: // Tri_NoShade |
| 1247 | { |
| 1248 | int lft = (command >> 23) & 0x1; |
| 1249 | |
| 1250 | if (length != rdp_command_length[command]) |
| 1251 | { |
| 1252 | sprintf(buffer, "ERROR: Tri_NoShade length = %d\n", length); |
| 1253 | return; |
| 1254 | } |
| 1255 | |
| 1256 | cmd[2] = m_cmd_data[m_cmd_cur+2]; |
| 1257 | cmd[3] = m_cmd_data[m_cmd_cur+3]; |
| 1258 | cmd[4] = m_cmd_data[m_cmd_cur+4]; |
| 1259 | cmd[5] = m_cmd_data[m_cmd_cur+5]; |
| 1260 | cmd[6] = m_cmd_data[m_cmd_cur+6]; |
| 1261 | cmd[7] = m_cmd_data[m_cmd_cur+7]; |
| 1262 | |
| 1263 | sprintf(yl, "%4.4f", (float)((cmd[0] >> 0) & 0x1fff) / 4.0f); |
| 1264 | sprintf(ym, "%4.4f", (float)((cmd[1] >> 16) & 0x1fff) / 4.0f); |
| 1265 | sprintf(yh, "%4.4f", (float)((cmd[1] >> 0) & 0x1fff) / 4.0f); |
| 1266 | sprintf(xl, "%4.4f", (float)(cmd[2] / 65536.0f)); |
| 1267 | sprintf(dxldy, "%4.4f", (float)(cmd[3] / 65536.0f)); |
| 1268 | sprintf(xh, "%4.4f", (float)(cmd[4] / 65536.0f)); |
| 1269 | sprintf(dxhdy, "%4.4f", (float)(cmd[5] / 65536.0f)); |
| 1270 | sprintf(xm, "%4.4f", (float)(cmd[6] / 65536.0f)); |
| 1271 | sprintf(dxmdy, "%4.4f", (float)(cmd[7] / 65536.0f)); |
| 1272 | |
| 1273 | sprintf(buffer, "Tri_NoShade %d, XL: %s, XM: %s, XH: %s, YL: %s, YM: %s, YH: %s\n", lft, xl,xm,xh,yl,ym,yh); |
| 1274 | break; |
| 1275 | } |
| 1276 | case 0x09: // Tri_NoShadeZ |
| 1277 | { |
| 1278 | int lft = (command >> 23) & 0x1; |
| 1279 | |
| 1280 | if (length != rdp_command_length[command]) |
| 1281 | { |
| 1282 | sprintf(buffer, "ERROR: Tri_NoShadeZ length = %d\n", length); |
| 1283 | return; |
| 1284 | } |
| 1285 | |
| 1286 | cmd[2] = m_cmd_data[m_cmd_cur+2]; |
| 1287 | cmd[3] = m_cmd_data[m_cmd_cur+3]; |
| 1288 | cmd[4] = m_cmd_data[m_cmd_cur+4]; |
| 1289 | cmd[5] = m_cmd_data[m_cmd_cur+5]; |
| 1290 | cmd[6] = m_cmd_data[m_cmd_cur+6]; |
| 1291 | cmd[7] = m_cmd_data[m_cmd_cur+7]; |
| 1292 | |
| 1293 | sprintf(yl, "%4.4f", (float)((cmd[0] >> 0) & 0x1fff) / 4.0f); |
| 1294 | sprintf(ym, "%4.4f", (float)((cmd[1] >> 16) & 0x1fff) / 4.0f); |
| 1295 | sprintf(yh, "%4.4f", (float)((cmd[1] >> 0) & 0x1fff) / 4.0f); |
| 1296 | sprintf(xl, "%4.4f", (float)(cmd[2] / 65536.0f)); |
| 1297 | sprintf(dxldy, "%4.4f", (float)(cmd[3] / 65536.0f)); |
| 1298 | sprintf(xh, "%4.4f", (float)(cmd[4] / 65536.0f)); |
| 1299 | sprintf(dxhdy, "%4.4f", (float)(cmd[5] / 65536.0f)); |
| 1300 | sprintf(xm, "%4.4f", (float)(cmd[6] / 65536.0f)); |
| 1301 | sprintf(dxmdy, "%4.4f", (float)(cmd[7] / 65536.0f)); |
| 1302 | |
| 1303 | sprintf(buffer, "Tri_NoShadeZ %d, XL: %s, XM: %s, XH: %s, YL: %s, YM: %s, YH: %s\n", lft, xl,xm,xh,yl,ym,yh); |
| 1304 | break; |
| 1305 | } |
| 1306 | case 0x0a: // Tri_Tex |
| 1307 | { |
| 1308 | int lft = (command >> 23) & 0x1; |
| 1309 | |
| 1310 | if (length < rdp_command_length[command]) |
| 1311 | { |
| 1312 | sprintf(buffer, "ERROR: Tri_Tex length = %d\n", length); |
| 1313 | return; |
| 1314 | } |
| 1315 | |
| 1316 | for (i=2; i < 24; i++) |
| 1317 | { |
| 1318 | cmd[i] = m_cmd_data[m_cmd_cur+i]; |
| 1319 | } |
| 1320 | |
| 1321 | sprintf(yl, "%4.4f", (float)((cmd[0] >> 0) & 0x1fff) / 4.0f); |
| 1322 | sprintf(ym, "%4.4f", (float)((cmd[1] >> 16) & 0x1fff) / 4.0f); |
| 1323 | sprintf(yh, "%4.4f", (float)((cmd[1] >> 0) & 0x1fff) / 4.0f); |
| 1324 | sprintf(xl, "%4.4f", (float)((INT32)cmd[2] / 65536.0f)); |
| 1325 | sprintf(dxldy, "%4.4f", (float)((INT32)cmd[3] / 65536.0f)); |
| 1326 | sprintf(xh, "%4.4f", (float)((INT32)cmd[4] / 65536.0f)); |
| 1327 | sprintf(dxhdy, "%4.4f", (float)((INT32)cmd[5] / 65536.0f)); |
| 1328 | sprintf(xm, "%4.4f", (float)((INT32)cmd[6] / 65536.0f)); |
| 1329 | sprintf(dxmdy, "%4.4f", (float)((INT32)cmd[7] / 65536.0f)); |
| 1330 | |
| 1331 | sprintf(s, "%4.4f", (float)(INT32)((cmd[ 8] & 0xffff0000) | ((cmd[12] >> 16) & 0xffff)) / 65536.0f); |
| 1332 | sprintf(t, "%4.4f", (float)(INT32)(((cmd[ 8] & 0xffff) << 16) | (cmd[12] & 0xffff)) / 65536.0f); |
| 1333 | sprintf(w, "%4.4f", (float)(INT32)((cmd[ 9] & 0xffff0000) | ((cmd[13] >> 16) & 0xffff)) / 65536.0f); |
| 1334 | sprintf(dsdx, "%4.4f", (float)(INT32)((cmd[10] & 0xffff0000) | ((cmd[14] >> 16) & 0xffff)) / 65536.0f); |
| 1335 | sprintf(dtdx, "%4.4f", (float)(INT32)(((cmd[10] & 0xffff) << 16) | (cmd[14] & 0xffff)) / 65536.0f); |
| 1336 | sprintf(dwdx, "%4.4f", (float)(INT32)((cmd[11] & 0xffff0000) | ((cmd[15] >> 16) & 0xffff)) / 65536.0f); |
| 1337 | sprintf(dsde, "%4.4f", (float)(INT32)((cmd[16] & 0xffff0000) | ((cmd[20] >> 16) & 0xffff)) / 65536.0f); |
| 1338 | sprintf(dtde, "%4.4f", (float)(INT32)(((cmd[16] & 0xffff) << 16) | (cmd[20] & 0xffff)) / 65536.0f); |
| 1339 | sprintf(dwde, "%4.4f", (float)(INT32)((cmd[17] & 0xffff0000) | ((cmd[21] >> 16) & 0xffff)) / 65536.0f); |
| 1340 | sprintf(dsdy, "%4.4f", (float)(INT32)((cmd[18] & 0xffff0000) | ((cmd[22] >> 16) & 0xffff)) / 65536.0f); |
| 1341 | sprintf(dtdy, "%4.4f", (float)(INT32)(((cmd[18] & 0xffff) << 16) | (cmd[22] & 0xffff)) / 65536.0f); |
| 1342 | sprintf(dwdy, "%4.4f", (float)(INT32)((cmd[19] & 0xffff0000) | ((cmd[23] >> 16) & 0xffff)) / 65536.0f); |
| 1343 | |
| 1344 | |
| 1345 | buffer+=sprintf(buffer, "Tri_Tex %d, XL: %s, XM: %s, XH: %s, YL: %s, YM: %s, YH: %s\n", lft, xl,xm,xh,yl,ym,yh); |
| 1346 | buffer+=sprintf(buffer, " "); |
| 1347 | buffer+=sprintf(buffer, " S: %s, T: %s, W: %s\n", s, t, w); |
| 1348 | buffer+=sprintf(buffer, " "); |
| 1349 | buffer+=sprintf(buffer, " DSDX: %s, DTDX: %s, DWDX: %s\n", dsdx, dtdx, dwdx); |
| 1350 | buffer+=sprintf(buffer, " "); |
| 1351 | buffer+=sprintf(buffer, " DSDE: %s, DTDE: %s, DWDE: %s\n", dsde, dtde, dwde); |
| 1352 | buffer+=sprintf(buffer, " "); |
| 1353 | buffer+=sprintf(buffer, " DSDY: %s, DTDY: %s, DWDY: %s\n", dsdy, dtdy, dwdy); |
| 1354 | break; |
| 1355 | } |
| 1356 | case 0x0b: // Tri_TexZ |
| 1357 | { |
| 1358 | int lft = (command >> 23) & 0x1; |
| 1359 | |
| 1360 | if (length < rdp_command_length[command]) |
| 1361 | { |
| 1362 | sprintf(buffer, "ERROR: Tri_TexZ length = %d\n", length); |
| 1363 | return; |
| 1364 | } |
| 1365 | |
| 1366 | for (i=2; i < 24; i++) |
| 1367 | { |
| 1368 | cmd[i] = m_cmd_data[m_cmd_cur+i]; |
| 1369 | } |
| 1370 | |
| 1371 | sprintf(yl, "%4.4f", (float)((cmd[0] >> 0) & 0x1fff) / 4.0f); |
| 1372 | sprintf(ym, "%4.4f", (float)((cmd[1] >> 16) & 0x1fff) / 4.0f); |
| 1373 | sprintf(yh, "%4.4f", (float)((cmd[1] >> 0) & 0x1fff) / 4.0f); |
| 1374 | sprintf(xl, "%4.4f", (float)((INT32)cmd[2] / 65536.0f)); |
| 1375 | sprintf(dxldy, "%4.4f", (float)((INT32)cmd[3] / 65536.0f)); |
| 1376 | sprintf(xh, "%4.4f", (float)((INT32)cmd[4] / 65536.0f)); |
| 1377 | sprintf(dxhdy, "%4.4f", (float)((INT32)cmd[5] / 65536.0f)); |
| 1378 | sprintf(xm, "%4.4f", (float)((INT32)cmd[6] / 65536.0f)); |
| 1379 | sprintf(dxmdy, "%4.4f", (float)((INT32)cmd[7] / 65536.0f)); |
| 1380 | |
| 1381 | sprintf(s, "%4.4f", (float)(INT32)((cmd[ 8] & 0xffff0000) | ((cmd[12] >> 16) & 0xffff)) / 65536.0f); |
| 1382 | sprintf(t, "%4.4f", (float)(INT32)(((cmd[ 8] & 0xffff) << 16) | (cmd[12] & 0xffff)) / 65536.0f); |
| 1383 | sprintf(w, "%4.4f", (float)(INT32)((cmd[ 9] & 0xffff0000) | ((cmd[13] >> 16) & 0xffff)) / 65536.0f); |
| 1384 | sprintf(dsdx, "%4.4f", (float)(INT32)((cmd[10] & 0xffff0000) | ((cmd[14] >> 16) & 0xffff)) / 65536.0f); |
| 1385 | sprintf(dtdx, "%4.4f", (float)(INT32)(((cmd[10] & 0xffff) << 16) | (cmd[14] & 0xffff)) / 65536.0f); |
| 1386 | sprintf(dwdx, "%4.4f", (float)(INT32)((cmd[11] & 0xffff0000) | ((cmd[15] >> 16) & 0xffff)) / 65536.0f); |
| 1387 | sprintf(dsde, "%4.4f", (float)(INT32)((cmd[16] & 0xffff0000) | ((cmd[20] >> 16) & 0xffff)) / 65536.0f); |
| 1388 | sprintf(dtde, "%4.4f", (float)(INT32)(((cmd[16] & 0xffff) << 16) | (cmd[20] & 0xffff)) / 65536.0f); |
| 1389 | sprintf(dwde, "%4.4f", (float)(INT32)((cmd[17] & 0xffff0000) | ((cmd[21] >> 16) & 0xffff)) / 65536.0f); |
| 1390 | sprintf(dsdy, "%4.4f", (float)(INT32)((cmd[18] & 0xffff0000) | ((cmd[22] >> 16) & 0xffff)) / 65536.0f); |
| 1391 | sprintf(dtdy, "%4.4f", (float)(INT32)(((cmd[18] & 0xffff) << 16) | (cmd[22] & 0xffff)) / 65536.0f); |
| 1392 | sprintf(dwdy, "%4.4f", (float)(INT32)((cmd[19] & 0xffff0000) | ((cmd[23] >> 16) & 0xffff)) / 65536.0f); |
| 1393 | |
| 1394 | |
| 1395 | buffer+=sprintf(buffer, "Tri_TexZ %d, XL: %s, XM: %s, XH: %s, YL: %s, YM: %s, YH: %s\n", lft, xl,xm,xh,yl,ym,yh); |
| 1396 | buffer+=sprintf(buffer, " "); |
| 1397 | buffer+=sprintf(buffer, " S: %s, T: %s, W: %s\n", s, t, w); |
| 1398 | buffer+=sprintf(buffer, " "); |
| 1399 | buffer+=sprintf(buffer, " DSDX: %s, DTDX: %s, DWDX: %s\n", dsdx, dtdx, dwdx); |
| 1400 | buffer+=sprintf(buffer, " "); |
| 1401 | buffer+=sprintf(buffer, " DSDE: %s, DTDE: %s, DWDE: %s\n", dsde, dtde, dwde); |
| 1402 | buffer+=sprintf(buffer, " "); |
| 1403 | buffer+=sprintf(buffer, " DSDY: %s, DTDY: %s, DWDY: %s\n", dsdy, dtdy, dwdy); |
| 1404 | break; |
| 1405 | } |
| 1406 | case 0x0c: // Tri_Shade |
| 1407 | { |
| 1408 | int lft = (command >> 23) & 0x1; |
| 1409 | |
| 1410 | if (length != rdp_command_length[command]) |
| 1411 | { |
| 1412 | sprintf(buffer, "ERROR: Tri_Shade length = %d\n", length); |
| 1413 | return; |
| 1414 | } |
| 1415 | |
| 1416 | for (i=2; i < 24; i++) |
| 1417 | { |
| 1418 | cmd[i] = m_cmd_data[i]; |
| 1419 | } |
| 1420 | |
| 1421 | sprintf(yl, "%4.4f", (float)((cmd[0] >> 0) & 0x1fff) / 4.0f); |
| 1422 | sprintf(ym, "%4.4f", (float)((cmd[1] >> 16) & 0x1fff) / 4.0f); |
| 1423 | sprintf(yh, "%4.4f", (float)((cmd[1] >> 0) & 0x1fff) / 4.0f); |
| 1424 | sprintf(xl, "%4.4f", (float)((INT32)cmd[2] / 65536.0f)); |
| 1425 | sprintf(dxldy, "%4.4f", (float)((INT32)cmd[3] / 65536.0f)); |
| 1426 | sprintf(xh, "%4.4f", (float)((INT32)cmd[4] / 65536.0f)); |
| 1427 | sprintf(dxhdy, "%4.4f", (float)((INT32)cmd[5] / 65536.0f)); |
| 1428 | sprintf(xm, "%4.4f", (float)((INT32)cmd[6] / 65536.0f)); |
| 1429 | sprintf(dxmdy, "%4.4f", (float)((INT32)cmd[7] / 65536.0f)); |
| 1430 | sprintf(rt, "%4.4f", (float)(INT32)((cmd[8] & 0xffff0000) | ((cmd[12] >> 16) & 0xffff)) / 65536.0f); |
| 1431 | sprintf(gt, "%4.4f", (float)(INT32)(((cmd[8] & 0xffff) << 16) | (cmd[12] & 0xffff)) / 65536.0f); |
| 1432 | sprintf(bt, "%4.4f", (float)(INT32)((cmd[9] & 0xffff0000) | ((cmd[13] >> 16) & 0xffff)) / 65536.0f); |
| 1433 | sprintf(at, "%4.4f", (float)(INT32)(((cmd[9] & 0xffff) << 16) | (cmd[13] & 0xffff)) / 65536.0f); |
| 1434 | sprintf(drdx, "%4.4f", (float)(INT32)((cmd[10] & 0xffff0000) | ((cmd[14] >> 16) & 0xffff)) / 65536.0f); |
| 1435 | sprintf(dgdx, "%4.4f", (float)(INT32)(((cmd[10] & 0xffff) << 16) | (cmd[14] & 0xffff)) / 65536.0f); |
| 1436 | sprintf(dbdx, "%4.4f", (float)(INT32)((cmd[11] & 0xffff0000) | ((cmd[15] >> 16) & 0xffff)) / 65536.0f); |
| 1437 | sprintf(dadx, "%4.4f", (float)(INT32)(((cmd[11] & 0xffff) << 16) | (cmd[15] & 0xffff)) / 65536.0f); |
| 1438 | sprintf(drde, "%4.4f", (float)(INT32)((cmd[16] & 0xffff0000) | ((cmd[20] >> 16) & 0xffff)) / 65536.0f); |
| 1439 | sprintf(dgde, "%4.4f", (float)(INT32)(((cmd[16] & 0xffff) << 16) | (cmd[20] & 0xffff)) / 65536.0f); |
| 1440 | sprintf(dbde, "%4.4f", (float)(INT32)((cmd[17] & 0xffff0000) | ((cmd[21] >> 16) & 0xffff)) / 65536.0f); |
| 1441 | sprintf(dade, "%4.4f", (float)(INT32)(((cmd[17] & 0xffff) << 16) | (cmd[21] & 0xffff)) / 65536.0f); |
| 1442 | sprintf(drdy, "%4.4f", (float)(INT32)((cmd[18] & 0xffff0000) | ((cmd[22] >> 16) & 0xffff)) / 65536.0f); |
| 1443 | sprintf(dgdy, "%4.4f", (float)(INT32)(((cmd[18] & 0xffff) << 16) | (cmd[22] & 0xffff)) / 65536.0f); |
| 1444 | sprintf(dbdy, "%4.4f", (float)(INT32)((cmd[19] & 0xffff0000) | ((cmd[23] >> 16) & 0xffff)) / 65536.0f); |
| 1445 | sprintf(dady, "%4.4f", (float)(INT32)(((cmd[19] & 0xffff) << 16) | (cmd[23] & 0xffff)) / 65536.0f); |
| 1446 | |
| 1447 | buffer+=sprintf(buffer, "Tri_Shade %d, XL: %s, XM: %s, XH: %s, YL: %s, YM: %s, YH: %s\n", lft, xl,xm,xh,yl,ym,yh); |
| 1448 | buffer+=sprintf(buffer, " "); |
| 1449 | buffer+=sprintf(buffer, " R: %s, G: %s, B: %s, A: %s\n", rt, gt, bt, at); |
| 1450 | buffer+=sprintf(buffer, " "); |
| 1451 | buffer+=sprintf(buffer, " DRDX: %s, DGDX: %s, DBDX: %s, DADX: %s\n", drdx, dgdx, dbdx, dadx); |
| 1452 | buffer+=sprintf(buffer, " "); |
| 1453 | buffer+=sprintf(buffer, " DRDE: %s, DGDE: %s, DBDE: %s, DADE: %s\n", drde, dgde, dbde, dade); |
| 1454 | buffer+=sprintf(buffer, " "); |
| 1455 | buffer+=sprintf(buffer, " DRDY: %s, DGDY: %s, DBDY: %s, DADY: %s\n", drdy, dgdy, dbdy, dady); |
| 1456 | break; |
| 1457 | } |
| 1458 | case 0x0d: // Tri_ShadeZ |
| 1459 | { |
| 1460 | int lft = (command >> 23) & 0x1; |
| 1461 | |
| 1462 | if (length != rdp_command_length[command]) |
| 1463 | { |
| 1464 | sprintf(buffer, "ERROR: Tri_ShadeZ length = %d\n", length); |
| 1465 | return; |
| 1466 | } |
| 1467 | |
| 1468 | for (i=2; i < 24; i++) |
| 1469 | { |
| 1470 | cmd[i] = m_cmd_data[i]; |
| 1471 | } |
| 1472 | |
| 1473 | sprintf(yl, "%4.4f", (float)((cmd[0] >> 0) & 0x1fff) / 4.0f); |
| 1474 | sprintf(ym, "%4.4f", (float)((cmd[1] >> 16) & 0x1fff) / 4.0f); |
| 1475 | sprintf(yh, "%4.4f", (float)((cmd[1] >> 0) & 0x1fff) / 4.0f); |
| 1476 | sprintf(xl, "%4.4f", (float)((INT32)cmd[2] / 65536.0f)); |
| 1477 | sprintf(dxldy, "%4.4f", (float)((INT32)cmd[3] / 65536.0f)); |
| 1478 | sprintf(xh, "%4.4f", (float)((INT32)cmd[4] / 65536.0f)); |
| 1479 | sprintf(dxhdy, "%4.4f", (float)((INT32)cmd[5] / 65536.0f)); |
| 1480 | sprintf(xm, "%4.4f", (float)((INT32)cmd[6] / 65536.0f)); |
| 1481 | sprintf(dxmdy, "%4.4f", (float)((INT32)cmd[7] / 65536.0f)); |
| 1482 | sprintf(rt, "%4.4f", (float)(INT32)((cmd[8] & 0xffff0000) | ((cmd[12] >> 16) & 0xffff)) / 65536.0f); |
| 1483 | sprintf(gt, "%4.4f", (float)(INT32)(((cmd[8] & 0xffff) << 16) | (cmd[12] & 0xffff)) / 65536.0f); |
| 1484 | sprintf(bt, "%4.4f", (float)(INT32)((cmd[9] & 0xffff0000) | ((cmd[13] >> 16) & 0xffff)) / 65536.0f); |
| 1485 | sprintf(at, "%4.4f", (float)(INT32)(((cmd[9] & 0xffff) << 16) | (cmd[13] & 0xffff)) / 65536.0f); |
| 1486 | sprintf(drdx, "%4.4f", (float)(INT32)((cmd[10] & 0xffff0000) | ((cmd[14] >> 16) & 0xffff)) / 65536.0f); |
| 1487 | sprintf(dgdx, "%4.4f", (float)(INT32)(((cmd[10] & 0xffff) << 16) | (cmd[14] & 0xffff)) / 65536.0f); |
| 1488 | sprintf(dbdx, "%4.4f", (float)(INT32)((cmd[11] & 0xffff0000) | ((cmd[15] >> 16) & 0xffff)) / 65536.0f); |
| 1489 | sprintf(dadx, "%4.4f", (float)(INT32)(((cmd[11] & 0xffff) << 16) | (cmd[15] & 0xffff)) / 65536.0f); |
| 1490 | sprintf(drde, "%4.4f", (float)(INT32)((cmd[16] & 0xffff0000) | ((cmd[20] >> 16) & 0xffff)) / 65536.0f); |
| 1491 | sprintf(dgde, "%4.4f", (float)(INT32)(((cmd[16] & 0xffff) << 16) | (cmd[20] & 0xffff)) / 65536.0f); |
| 1492 | sprintf(dbde, "%4.4f", (float)(INT32)((cmd[17] & 0xffff0000) | ((cmd[21] >> 16) & 0xffff)) / 65536.0f); |
| 1493 | sprintf(dade, "%4.4f", (float)(INT32)(((cmd[17] & 0xffff) << 16) | (cmd[21] & 0xffff)) / 65536.0f); |
| 1494 | sprintf(drdy, "%4.4f", (float)(INT32)((cmd[18] & 0xffff0000) | ((cmd[22] >> 16) & 0xffff)) / 65536.0f); |
| 1495 | sprintf(dgdy, "%4.4f", (float)(INT32)(((cmd[18] & 0xffff) << 16) | (cmd[22] & 0xffff)) / 65536.0f); |
| 1496 | sprintf(dbdy, "%4.4f", (float)(INT32)((cmd[19] & 0xffff0000) | ((cmd[23] >> 16) & 0xffff)) / 65536.0f); |
| 1497 | sprintf(dady, "%4.4f", (float)(INT32)(((cmd[19] & 0xffff) << 16) | (cmd[23] & 0xffff)) / 65536.0f); |
| 1498 | |
| 1499 | buffer+=sprintf(buffer, "Tri_ShadeZ %d, XL: %s, XM: %s, XH: %s, YL: %s, YM: %s, YH: %s\n", lft, xl,xm,xh,yl,ym,yh); |
| 1500 | buffer+=sprintf(buffer, " "); |
| 1501 | buffer+=sprintf(buffer, " R: %s, G: %s, B: %s, A: %s\n", rt, gt, bt, at); |
| 1502 | buffer+=sprintf(buffer, " "); |
| 1503 | buffer+=sprintf(buffer, " DRDX: %s, DGDX: %s, DBDX: %s, DADX: %s\n", drdx, dgdx, dbdx, dadx); |
| 1504 | buffer+=sprintf(buffer, " "); |
| 1505 | buffer+=sprintf(buffer, " DRDE: %s, DGDE: %s, DBDE: %s, DADE: %s\n", drde, dgde, dbde, dade); |
| 1506 | buffer+=sprintf(buffer, " "); |
| 1507 | buffer+=sprintf(buffer, " DRDY: %s, DGDY: %s, DBDY: %s, DADY: %s\n", drdy, dgdy, dbdy, dady); |
| 1508 | break; |
| 1509 | } |
| 1510 | case 0x0e: // Tri_TexShade |
| 1511 | { |
| 1512 | int lft = (command >> 23) & 0x1; |
| 1513 | |
| 1514 | if (length < rdp_command_length[command]) |
| 1515 | { |
| 1516 | sprintf(buffer, "ERROR: Tri_TexShade length = %d\n", length); |
| 1517 | return; |
| 1518 | } |
| 1519 | |
| 1520 | for (i=2; i < 40; i++) |
| 1521 | { |
| 1522 | cmd[i] = m_cmd_data[m_cmd_cur+i]; |
| 1523 | } |
| 1524 | |
| 1525 | sprintf(yl, "%4.4f", (float)((cmd[0] >> 0) & 0x1fff) / 4.0f); |
| 1526 | sprintf(ym, "%4.4f", (float)((cmd[1] >> 16) & 0x1fff) / 4.0f); |
| 1527 | sprintf(yh, "%4.4f", (float)((cmd[1] >> 0) & 0x1fff) / 4.0f); |
| 1528 | sprintf(xl, "%4.4f", (float)((INT32)cmd[2] / 65536.0f)); |
| 1529 | sprintf(dxldy, "%4.4f", (float)((INT32)cmd[3] / 65536.0f)); |
| 1530 | sprintf(xh, "%4.4f", (float)((INT32)cmd[4] / 65536.0f)); |
| 1531 | sprintf(dxhdy, "%4.4f", (float)((INT32)cmd[5] / 65536.0f)); |
| 1532 | sprintf(xm, "%4.4f", (float)((INT32)cmd[6] / 65536.0f)); |
| 1533 | sprintf(dxmdy, "%4.4f", (float)((INT32)cmd[7] / 65536.0f)); |
| 1534 | sprintf(rt, "%4.4f", (float)(INT32)((cmd[8] & 0xffff0000) | ((cmd[12] >> 16) & 0xffff)) / 65536.0f); |
| 1535 | sprintf(gt, "%4.4f", (float)(INT32)(((cmd[8] & 0xffff) << 16) | (cmd[12] & 0xffff)) / 65536.0f); |
| 1536 | sprintf(bt, "%4.4f", (float)(INT32)((cmd[9] & 0xffff0000) | ((cmd[13] >> 16) & 0xffff)) / 65536.0f); |
| 1537 | sprintf(at, "%4.4f", (float)(INT32)(((cmd[9] & 0xffff) << 16) | (cmd[13] & 0xffff)) / 65536.0f); |
| 1538 | sprintf(drdx, "%4.4f", (float)(INT32)((cmd[10] & 0xffff0000) | ((cmd[14] >> 16) & 0xffff)) / 65536.0f); |
| 1539 | sprintf(dgdx, "%4.4f", (float)(INT32)(((cmd[10] & 0xffff) << 16) | (cmd[14] & 0xffff)) / 65536.0f); |
| 1540 | sprintf(dbdx, "%4.4f", (float)(INT32)((cmd[11] & 0xffff0000) | ((cmd[15] >> 16) & 0xffff)) / 65536.0f); |
| 1541 | sprintf(dadx, "%4.4f", (float)(INT32)(((cmd[11] & 0xffff) << 16) | (cmd[15] & 0xffff)) / 65536.0f); |
| 1542 | sprintf(drde, "%4.4f", (float)(INT32)((cmd[16] & 0xffff0000) | ((cmd[20] >> 16) & 0xffff)) / 65536.0f); |
| 1543 | sprintf(dgde, "%4.4f", (float)(INT32)(((cmd[16] & 0xffff) << 16) | (cmd[20] & 0xffff)) / 65536.0f); |
| 1544 | sprintf(dbde, "%4.4f", (float)(INT32)((cmd[17] & 0xffff0000) | ((cmd[21] >> 16) & 0xffff)) / 65536.0f); |
| 1545 | sprintf(dade, "%4.4f", (float)(INT32)(((cmd[17] & 0xffff) << 16) | (cmd[21] & 0xffff)) / 65536.0f); |
| 1546 | sprintf(drdy, "%4.4f", (float)(INT32)((cmd[18] & 0xffff0000) | ((cmd[22] >> 16) & 0xffff)) / 65536.0f); |
| 1547 | sprintf(dgdy, "%4.4f", (float)(INT32)(((cmd[18] & 0xffff) << 16) | (cmd[22] & 0xffff)) / 65536.0f); |
| 1548 | sprintf(dbdy, "%4.4f", (float)(INT32)((cmd[19] & 0xffff0000) | ((cmd[23] >> 16) & 0xffff)) / 65536.0f); |
| 1549 | sprintf(dady, "%4.4f", (float)(INT32)(((cmd[19] & 0xffff) << 16) | (cmd[23] & 0xffff)) / 65536.0f); |
| 1550 | |
| 1551 | sprintf(s, "%4.4f", (float)(INT32)((cmd[24] & 0xffff0000) | ((cmd[28] >> 16) & 0xffff)) / 65536.0f); |
| 1552 | sprintf(t, "%4.4f", (float)(INT32)(((cmd[24] & 0xffff) << 16) | (cmd[28] & 0xffff)) / 65536.0f); |
| 1553 | sprintf(w, "%4.4f", (float)(INT32)((cmd[25] & 0xffff0000) | ((cmd[29] >> 16) & 0xffff)) / 65536.0f); |
| 1554 | sprintf(dsdx, "%4.4f", (float)(INT32)((cmd[26] & 0xffff0000) | ((cmd[30] >> 16) & 0xffff)) / 65536.0f); |
| 1555 | sprintf(dtdx, "%4.4f", (float)(INT32)(((cmd[26] & 0xffff) << 16) | (cmd[30] & 0xffff)) / 65536.0f); |
| 1556 | sprintf(dwdx, "%4.4f", (float)(INT32)((cmd[27] & 0xffff0000) | ((cmd[31] >> 16) & 0xffff)) / 65536.0f); |
| 1557 | sprintf(dsde, "%4.4f", (float)(INT32)((cmd[32] & 0xffff0000) | ((cmd[36] >> 16) & 0xffff)) / 65536.0f); |
| 1558 | sprintf(dtde, "%4.4f", (float)(INT32)(((cmd[32] & 0xffff) << 16) | (cmd[36] & 0xffff)) / 65536.0f); |
| 1559 | sprintf(dwde, "%4.4f", (float)(INT32)((cmd[33] & 0xffff0000) | ((cmd[37] >> 16) & 0xffff)) / 65536.0f); |
| 1560 | sprintf(dsdy, "%4.4f", (float)(INT32)((cmd[34] & 0xffff0000) | ((cmd[38] >> 16) & 0xffff)) / 65536.0f); |
| 1561 | sprintf(dtdy, "%4.4f", (float)(INT32)(((cmd[34] & 0xffff) << 16) | (cmd[38] & 0xffff)) / 65536.0f); |
| 1562 | sprintf(dwdy, "%4.4f", (float)(INT32)((cmd[35] & 0xffff0000) | ((cmd[39] >> 16) & 0xffff)) / 65536.0f); |
| 1563 | |
| 1564 | |
| 1565 | buffer+=sprintf(buffer, "Tri_TexShade %d, XL: %s, XM: %s, XH: %s, YL: %s, YM: %s, YH: %s\n", lft, xl,xm,xh,yl,ym,yh); |
| 1566 | buffer+=sprintf(buffer, " "); |
| 1567 | buffer+=sprintf(buffer, " R: %s, G: %s, B: %s, A: %s\n", rt, gt, bt, at); |
| 1568 | buffer+=sprintf(buffer, " "); |
| 1569 | buffer+=sprintf(buffer, " DRDX: %s, DGDX: %s, DBDX: %s, DADX: %s\n", drdx, dgdx, dbdx, dadx); |
| 1570 | buffer+=sprintf(buffer, " "); |
| 1571 | buffer+=sprintf(buffer, " DRDE: %s, DGDE: %s, DBDE: %s, DADE: %s\n", drde, dgde, dbde, dade); |
| 1572 | buffer+=sprintf(buffer, " "); |
| 1573 | buffer+=sprintf(buffer, " DRDY: %s, DGDY: %s, DBDY: %s, DADY: %s\n", drdy, dgdy, dbdy, dady); |
| 1574 | |
| 1575 | buffer+=sprintf(buffer, " "); |
| 1576 | buffer+=sprintf(buffer, " S: %s, T: %s, W: %s\n", s, t, w); |
| 1577 | buffer+=sprintf(buffer, " "); |
| 1578 | buffer+=sprintf(buffer, " DSDX: %s, DTDX: %s, DWDX: %s\n", dsdx, dtdx, dwdx); |
| 1579 | buffer+=sprintf(buffer, " "); |
| 1580 | buffer+=sprintf(buffer, " DSDE: %s, DTDE: %s, DWDE: %s\n", dsde, dtde, dwde); |
| 1581 | buffer+=sprintf(buffer, " "); |
| 1582 | buffer+=sprintf(buffer, " DSDY: %s, DTDY: %s, DWDY: %s\n", dsdy, dtdy, dwdy); |
| 1583 | break; |
| 1584 | } |
| 1585 | case 0x0f: // Tri_TexShadeZ |
| 1586 | { |
| 1587 | int lft = (command >> 23) & 0x1; |
| 1588 | |
| 1589 | if (length < rdp_command_length[command]) |
| 1590 | { |
| 1591 | sprintf(buffer, "ERROR: Tri_TexShadeZ length = %d\n", length); |
| 1592 | return; |
| 1593 | } |
| 1594 | |
| 1595 | for (i=2; i < 40; i++) |
| 1596 | { |
| 1597 | cmd[i] = m_cmd_data[m_cmd_cur+i]; |
| 1598 | } |
| 1599 | |
| 1600 | sprintf(yl, "%4.4f", (float)((cmd[0] >> 0) & 0x1fff) / 4.0f); |
| 1601 | sprintf(ym, "%4.4f", (float)((cmd[1] >> 16) & 0x1fff) / 4.0f); |
| 1602 | sprintf(yh, "%4.4f", (float)((cmd[1] >> 0) & 0x1fff) / 4.0f); |
| 1603 | sprintf(xl, "%4.4f", (float)((INT32)cmd[2] / 65536.0f)); |
| 1604 | sprintf(dxldy, "%4.4f", (float)((INT32)cmd[3] / 65536.0f)); |
| 1605 | sprintf(xh, "%4.4f", (float)((INT32)cmd[4] / 65536.0f)); |
| 1606 | sprintf(dxhdy, "%4.4f", (float)((INT32)cmd[5] / 65536.0f)); |
| 1607 | sprintf(xm, "%4.4f", (float)((INT32)cmd[6] / 65536.0f)); |
| 1608 | sprintf(dxmdy, "%4.4f", (float)((INT32)cmd[7] / 65536.0f)); |
| 1609 | sprintf(rt, "%4.4f", (float)(INT32)((cmd[8] & 0xffff0000) | ((cmd[12] >> 16) & 0xffff)) / 65536.0f); |
| 1610 | sprintf(gt, "%4.4f", (float)(INT32)(((cmd[8] & 0xffff) << 16) | (cmd[12] & 0xffff)) / 65536.0f); |
| 1611 | sprintf(bt, "%4.4f", (float)(INT32)((cmd[9] & 0xffff0000) | ((cmd[13] >> 16) & 0xffff)) / 65536.0f); |
| 1612 | sprintf(at, "%4.4f", (float)(INT32)(((cmd[9] & 0xffff) << 16) | (cmd[13] & 0xffff)) / 65536.0f); |
| 1613 | sprintf(drdx, "%4.4f", (float)(INT32)((cmd[10] & 0xffff0000) | ((cmd[14] >> 16) & 0xffff)) / 65536.0f); |
| 1614 | sprintf(dgdx, "%4.4f", (float)(INT32)(((cmd[10] & 0xffff) << 16) | (cmd[14] & 0xffff)) / 65536.0f); |
| 1615 | sprintf(dbdx, "%4.4f", (float)(INT32)((cmd[11] & 0xffff0000) | ((cmd[15] >> 16) & 0xffff)) / 65536.0f); |
| 1616 | sprintf(dadx, "%4.4f", (float)(INT32)(((cmd[11] & 0xffff) << 16) | (cmd[15] & 0xffff)) / 65536.0f); |
| 1617 | sprintf(drde, "%4.4f", (float)(INT32)((cmd[16] & 0xffff0000) | ((cmd[20] >> 16) & 0xffff)) / 65536.0f); |
| 1618 | sprintf(dgde, "%4.4f", (float)(INT32)(((cmd[16] & 0xffff) << 16) | (cmd[20] & 0xffff)) / 65536.0f); |
| 1619 | sprintf(dbde, "%4.4f", (float)(INT32)((cmd[17] & 0xffff0000) | ((cmd[21] >> 16) & 0xffff)) / 65536.0f); |
| 1620 | sprintf(dade, "%4.4f", (float)(INT32)(((cmd[17] & 0xffff) << 16) | (cmd[21] & 0xffff)) / 65536.0f); |
| 1621 | sprintf(drdy, "%4.4f", (float)(INT32)((cmd[18] & 0xffff0000) | ((cmd[22] >> 16) & 0xffff)) / 65536.0f); |
| 1622 | sprintf(dgdy, "%4.4f", (float)(INT32)(((cmd[18] & 0xffff) << 16) | (cmd[22] & 0xffff)) / 65536.0f); |
| 1623 | sprintf(dbdy, "%4.4f", (float)(INT32)((cmd[19] & 0xffff0000) | ((cmd[23] >> 16) & 0xffff)) / 65536.0f); |
| 1624 | sprintf(dady, "%4.4f", (float)(INT32)(((cmd[19] & 0xffff) << 16) | (cmd[23] & 0xffff)) / 65536.0f); |
| 1625 | |
| 1626 | sprintf(s, "%4.4f", (float)(INT32)((cmd[24] & 0xffff0000) | ((cmd[28] >> 16) & 0xffff)) / 65536.0f); |
| 1627 | sprintf(t, "%4.4f", (float)(INT32)(((cmd[24] & 0xffff) << 16) | (cmd[28] & 0xffff)) / 65536.0f); |
| 1628 | sprintf(w, "%4.4f", (float)(INT32)((cmd[25] & 0xffff0000) | ((cmd[29] >> 16) & 0xffff)) / 65536.0f); |
| 1629 | sprintf(dsdx, "%4.4f", (float)(INT32)((cmd[26] & 0xffff0000) | ((cmd[30] >> 16) & 0xffff)) / 65536.0f); |
| 1630 | sprintf(dtdx, "%4.4f", (float)(INT32)(((cmd[26] & 0xffff) << 16) | (cmd[30] & 0xffff)) / 65536.0f); |
| 1631 | sprintf(dwdx, "%4.4f", (float)(INT32)((cmd[27] & 0xffff0000) | ((cmd[31] >> 16) & 0xffff)) / 65536.0f); |
| 1632 | sprintf(dsde, "%4.4f", (float)(INT32)((cmd[32] & 0xffff0000) | ((cmd[36] >> 16) & 0xffff)) / 65536.0f); |
| 1633 | sprintf(dtde, "%4.4f", (float)(INT32)(((cmd[32] & 0xffff) << 16) | (cmd[36] & 0xffff)) / 65536.0f); |
| 1634 | sprintf(dwde, "%4.4f", (float)(INT32)((cmd[33] & 0xffff0000) | ((cmd[37] >> 16) & 0xffff)) / 65536.0f); |
| 1635 | sprintf(dsdy, "%4.4f", (float)(INT32)((cmd[34] & 0xffff0000) | ((cmd[38] >> 16) & 0xffff)) / 65536.0f); |
| 1636 | sprintf(dtdy, "%4.4f", (float)(INT32)(((cmd[34] & 0xffff) << 16) | (cmd[38] & 0xffff)) / 65536.0f); |
| 1637 | sprintf(dwdy, "%4.4f", (float)(INT32)((cmd[35] & 0xffff0000) | ((cmd[39] >> 16) & 0xffff)) / 65536.0f); |
| 1638 | |
| 1639 | |
| 1640 | buffer+=sprintf(buffer, "Tri_TexShadeZ %d, XL: %s, XM: %s, XH: %s, YL: %s, YM: %s, YH: %s\n", lft, xl,xm,xh,yl,ym,yh); |
| 1641 | buffer+=sprintf(buffer, " "); |
| 1642 | buffer+=sprintf(buffer, " R: %s, G: %s, B: %s, A: %s\n", rt, gt, bt, at); |
| 1643 | buffer+=sprintf(buffer, " "); |
| 1644 | buffer+=sprintf(buffer, " DRDX: %s, DGDX: %s, DBDX: %s, DADX: %s\n", drdx, dgdx, dbdx, dadx); |
| 1645 | buffer+=sprintf(buffer, " "); |
| 1646 | buffer+=sprintf(buffer, " DRDE: %s, DGDE: %s, DBDE: %s, DADE: %s\n", drde, dgde, dbde, dade); |
| 1647 | buffer+=sprintf(buffer, " "); |
| 1648 | buffer+=sprintf(buffer, " DRDY: %s, DGDY: %s, DBDY: %s, DADY: %s\n", drdy, dgdy, dbdy, dady); |
| 1649 | |
| 1650 | buffer+=sprintf(buffer, " "); |
| 1651 | buffer+=sprintf(buffer, " S: %s, T: %s, W: %s\n", s, t, w); |
| 1652 | buffer+=sprintf(buffer, " "); |
| 1653 | buffer+=sprintf(buffer, " DSDX: %s, DTDX: %s, DWDX: %s\n", dsdx, dtdx, dwdx); |
| 1654 | buffer+=sprintf(buffer, " "); |
| 1655 | buffer+=sprintf(buffer, " DSDE: %s, DTDE: %s, DWDE: %s\n", dsde, dtde, dwde); |
| 1656 | buffer+=sprintf(buffer, " "); |
| 1657 | buffer+=sprintf(buffer, " DSDY: %s, DTDY: %s, DWDY: %s\n", dsdy, dtdy, dwdy); |
| 1658 | break; |
| 1659 | } |
| 1660 | case 0x24: |
| 1661 | case 0x25: |
| 1662 | { |
| 1663 | if (length < 16) |
| 1664 | { |
| 1665 | sprintf(buffer, "ERROR: Texture_Rectangle length = %d\n", length); |
| 1666 | return; |
| 1667 | } |
| 1668 | cmd[2] = m_cmd_data[m_cmd_cur+2]; |
| 1669 | cmd[3] = m_cmd_data[m_cmd_cur+3]; |
| 1670 | sprintf(s, "%4.4f", (float)(INT16)((cmd[2] >> 16) & 0xffff) / 32.0f); |
| 1671 | sprintf(t, "%4.4f", (float)(INT16)((cmd[2] >> 0) & 0xffff) / 32.0f); |
| 1672 | sprintf(dsdx, "%4.4f", (float)(INT16)((cmd[3] >> 16) & 0xffff) / 1024.0f); |
| 1673 | sprintf(dtdy, "%4.4f", (float)(INT16)((cmd[3] >> 16) & 0xffff) / 1024.0f); |
| 1674 | |
| 1675 | if (command == 0x24) |
| 1676 | sprintf(buffer, "Texture_Rectangle %d, %s, %s, %s, %s, %s, %s, %s, %s", tile, sh, th, sl, tl, s, t, dsdx, dtdy); |
| 1677 | else |
| 1678 | sprintf(buffer, "Texture_Rectangle_Flip %d, %s, %s, %s, %s, %s, %s, %s, %s", tile, sh, th, sl, tl, s, t, dsdx, dtdy); |
| 1679 | |
| 1680 | break; |
| 1681 | } |
| 1682 | case 0x26: sprintf(buffer, "Sync_Load"); break; |
| 1683 | case 0x27: sprintf(buffer, "Sync_Pipe"); break; |
| 1684 | case 0x28: sprintf(buffer, "Sync_Tile"); break; |
| 1685 | case 0x29: sprintf(buffer, "Sync_Full"); break; |
| 1686 | case 0x2d: sprintf(buffer, "Set_Scissor %s, %s, %s, %s", sl, tl, sh, th); break; |
| 1687 | case 0x2e: sprintf(buffer, "Set_Prim_Depth %04X, %04X", (cmd[1] >> 16) & 0xffff, cmd[1] & 0xffff); break; |
| 1688 | case 0x2f: sprintf(buffer, "Set_Other_Modes %08X %08X", cmd[0], cmd[1]); break; |
| 1689 | case 0x30: sprintf(buffer, "Load_TLUT %d, %s, %s, %s, %s", tile, sl, tl, sh, th); break; |
| 1690 | case 0x32: sprintf(buffer, "Set_Tile_Size %d, %s, %s, %s, %s", tile, sl, tl, sh, th); break; |
| 1691 | case 0x33: sprintf(buffer, "Load_Block %d, %03X, %03X, %03X, %03X", tile, (cmd[0] >> 12) & 0xfff, cmd[0] & 0xfff, (cmd[1] >> 12) & 0xfff, cmd[1] & 0xfff); break; |
| 1692 | case 0x34: sprintf(buffer, "Load_Tile %d, %s, %s, %s, %s", tile, sl, tl, sh, th); break; |
| 1693 | case 0x35: sprintf(buffer, "Set_Tile %d, %s, %s, %d, %04X", tile, format, size, ((cmd[0] >> 9) & 0x1ff) * 8, (cmd[0] & 0x1ff) * 8); break; |
| 1694 | case 0x36: sprintf(buffer, "Fill_Rectangle %s, %s, %s, %s", sh, th, sl, tl); break; |
| 1695 | case 0x37: sprintf(buffer, "Set_Fill_Color R: %d, G: %d, B: %d, A: %d", r, g, b, a); break; |
| 1696 | case 0x38: sprintf(buffer, "Set_Fog_Color R: %d, G: %d, B: %d, A: %d", r, g, b, a); break; |
| 1697 | case 0x39: sprintf(buffer, "Set_Blend_Color R: %d, G: %d, B: %d, A: %d", r, g, b, a); break; |
| 1698 | case 0x3a: sprintf(buffer, "Set_Prim_Color %d, %d, R: %d, G: %d, B: %d, A: %d", (cmd[0] >> 8) & 0x1f, cmd[0] & 0xff, r, g, b, a); break; |
| 1699 | case 0x3b: sprintf(buffer, "Set_Env_Color R: %d, G: %d, B: %d, A: %d", r, g, b, a); break; |
| 1700 | case 0x3c: sprintf(buffer, "Set_Combine %08X %08X", cmd[0], cmd[1]); break; |
| 1701 | case 0x3d: sprintf(buffer, "Set_Texture_Image %s, %s, %d, %08X", format, size, (cmd[0] & 0x1ff)+1, cmd[1]); break; |
| 1702 | case 0x3e: sprintf(buffer, "Set_Mask_Image %08X", cmd[1]); break; |
| 1703 | case 0x3f: sprintf(buffer, "Set_Color_Image %s, %s, %d, %08X", format, size, (cmd[0] & 0x1ff)+1, cmd[1]); break; |
| 1704 | default: sprintf(buffer, "??? (%08X %08X)", cmd[0], cmd[1]); break; |
| 1705 | } |
| 1706 | } |
| 1707 | |
| 1708 | /*****************************************************************************/ |
| 1709 | |
| 1710 | static UINT32 rightcvghex(UINT32 x, UINT32 fmask) |
| 1711 | { |
| 1712 | UINT32 stickybit = ((x >> 1) & 0x1fff) > 0; |
| 1713 | UINT32 covered = ((x >> 14) & 3) + stickybit; |
| 1714 | covered = (0xf0 >> covered) & 0xf; |
| 1715 | return (covered & fmask); |
| 1716 | } |
| 1717 | |
| 1718 | static UINT32 leftcvghex(UINT32 x, UINT32 fmask) |
| 1719 | { |
| 1720 | UINT32 stickybit = ((x >> 1) & 0x1fff) > 0; |
| 1721 | UINT32 covered = ((x >> 14) & 3) + stickybit; |
| 1722 | covered = 0xf >> covered; |
| 1723 | return (covered & fmask); |
| 1724 | } |
| 1725 | |
| 1726 | static INT32 CLIP(INT32 value,INT32 min,INT32 max) |
| 1727 | { |
| 1728 | if (value < min) |
| 1729 | { |
| 1730 | return min; |
| 1731 | } |
| 1732 | else if (value > max) |
| 1733 | { |
| 1734 | return max; |
| 1735 | } |
| 1736 | else |
| 1737 | { |
| 1738 | return value; |
| 1739 | } |
| 1740 | } |
| 1741 | |
| 1742 | void n64_rdp::compute_cvg_noflip(extent_t *Spans, INT32* majorx, INT32* minorx, INT32* majorxint, INT32* minorxint, INT32 scanline, INT32 yh, INT32 yl, INT32 base) |
| 1743 | { |
| 1744 | INT32 purgestart = 0xfff; |
| 1745 | INT32 purgeend = 0; |
| 1746 | bool writablescanline = !(scanline & ~0x3ff); |
| 1747 | INT32 scanlinespx = scanline << 2; |
| 1748 | |
| 1749 | if (!writablescanline) return; |
| 1750 | |
| 1751 | for(int i = 0; i < 4; i++) |
| 1752 | { |
| 1753 | if (minorxint[i] < purgestart) |
| 1754 | { |
| 1755 | purgestart = minorxint[i]; |
| 1756 | } |
| 1757 | if (majorxint[i] > purgeend) |
| 1758 | { |
| 1759 | purgeend = majorxint[i]; |
| 1760 | } |
| 1761 | } |
| 1762 | |
| 1763 | purgestart = CLIP(purgestart, 0, 1023); |
| 1764 | purgeend = CLIP(purgeend, 0, 1023); |
| 1765 | INT32 length = purgeend - purgestart; |
| 1766 | |
| 1767 | if (length < 0) return; |
| 1768 | |
| 1769 | rdp_span_aux *userdata = (rdp_span_aux*)Spans[scanline - base].userdata; |
| 1770 | memset(&userdata->m_cvg[purgestart], 0, (length + 1) << 1); |
| 1771 | |
| 1772 | for(int i = 0; i < 4; i++) |
| 1773 | { |
| 1774 | INT32 minorcur = minorx[i]; |
| 1775 | INT32 majorcur = majorx[i]; |
| 1776 | INT32 minorcurint = minorxint[i]; |
| 1777 | INT32 majorcurint = majorxint[i]; |
| 1778 | length = majorcurint - minorcurint; |
| 1779 | |
| 1780 | INT32 fmask = (i & 1) ? 5 : 0xa; |
| 1781 | INT32 maskshift = (i ^ 3) << 2; |
| 1782 | INT32 fmaskshifted = fmask << maskshift; |
| 1783 | INT32 fleft = CLIP(minorcurint + 1, 0, 647); |
| 1784 | INT32 fright = CLIP(majorcurint - 1, 0, 647); |
| 1785 | bool valid_y = ((scanlinespx + i) >= yh && (scanlinespx + i) < yl); |
| 1786 | if (valid_y && length >= 0) |
| 1787 | { |
| 1788 | if (minorcurint != majorcurint) |
| 1789 | { |
| 1790 | if (!(minorcurint & ~0x3ff)) |
| 1791 | { |
| 1792 | userdata->m_cvg[minorcurint] |= (leftcvghex(minorcur, fmask) << maskshift); |
| 1793 | } |
| 1794 | if (!(majorcurint & ~0x3ff)) |
| 1795 | { |
| 1796 | userdata->m_cvg[majorcurint] |= (rightcvghex(majorcur, fmask) << maskshift); |
| 1797 | } |
| 1798 | } |
| 1799 | else |
| 1800 | { |
| 1801 | if (!(majorcurint & ~0x3ff)) |
| 1802 | { |
| 1803 | INT32 samecvg = leftcvghex(minorcur, fmask) & rightcvghex(majorcur, fmask); |
| 1804 | userdata->m_cvg[majorcurint] |= (samecvg << maskshift); |
| 1805 | } |
| 1806 | } |
| 1807 | for (; fleft <= fright; fleft++) |
| 1808 | { |
| 1809 | userdata->m_cvg[fleft] |= fmaskshifted; |
| 1810 | } |
| 1811 | } |
| 1812 | } |
| 1813 | } |
| 1814 | |
| 1815 | void n64_rdp::compute_cvg_flip(extent_t *Spans, INT32* majorx, INT32* minorx, INT32* majorxint, INT32* minorxint, INT32 scanline, INT32 yh, INT32 yl, INT32 base) |
| 1816 | { |
| 1817 | INT32 purgestart = 0xfff; |
| 1818 | INT32 purgeend = 0; |
| 1819 | bool writablescanline = !(scanline & ~0x3ff); |
| 1820 | INT32 scanlinespx = scanline << 2; |
| 1821 | |
| 1822 | if(!writablescanline) return; |
| 1823 | |
| 1824 | for(int i = 0; i < 4; i++) |
| 1825 | { |
| 1826 | if (majorxint[i] < purgestart) |
| 1827 | { |
| 1828 | purgestart = majorxint[i]; |
| 1829 | } |
| 1830 | if (minorxint[i] > purgeend) |
| 1831 | { |
| 1832 | purgeend = minorxint[i]; |
| 1833 | } |
| 1834 | } |
| 1835 | |
| 1836 | purgestart = CLIP(purgestart, 0, 1023); |
| 1837 | purgeend = CLIP(purgeend, 0, 1023); |
| 1838 | |
| 1839 | int length = purgeend - purgestart; |
| 1840 | |
| 1841 | if (length < 0) return; |
| 1842 | |
| 1843 | rdp_span_aux *userdata = (rdp_span_aux*)Spans[scanline - base].userdata; |
| 1844 | memset(&userdata->m_cvg[purgestart], 0, (length + 1) << 1); |
| 1845 | |
| 1846 | for(int i = 0; i < 4; i++) |
| 1847 | { |
| 1848 | INT32 minorcur = minorx[i]; |
| 1849 | INT32 majorcur = majorx[i]; |
| 1850 | INT32 minorcurint = minorxint[i]; |
| 1851 | INT32 majorcurint = majorxint[i]; |
| 1852 | length = minorcurint - majorcurint; |
| 1853 | |
| 1854 | INT32 fmask = (i & 1) ? 5 : 0xa; |
| 1855 | INT32 maskshift = (i ^ 3) << 2; |
| 1856 | INT32 fmaskshifted = fmask << maskshift; |
| 1857 | INT32 fleft = CLIP(majorcurint + 1, 0, 647); |
| 1858 | INT32 fright = CLIP(minorcurint - 1, 0, 647); |
| 1859 | bool valid_y = ((scanlinespx + i) >= yh && (scanlinespx + i) < yl); |
| 1860 | if (valid_y && length >= 0) |
| 1861 | { |
| 1862 | if (minorcurint != majorcurint) |
| 1863 | { |
| 1864 | if (!(minorcurint & ~0x3ff)) |
| 1865 | { |
| 1866 | userdata->m_cvg[minorcurint] |= (rightcvghex(minorcur, fmask) << maskshift); |
| 1867 | } |
| 1868 | if (!(majorcurint & ~0x3ff)) |
| 1869 | { |
| 1870 | userdata->m_cvg[majorcurint] |= (leftcvghex(majorcur, fmask) << maskshift); |
| 1871 | } |
| 1872 | } |
| 1873 | else |
| 1874 | { |
| 1875 | if (!(majorcurint & ~0x3ff)) |
| 1876 | { |
| 1877 | INT32 samecvg = rightcvghex(minorcur, fmask) & leftcvghex(majorcur, fmask); |
| 1878 | userdata->m_cvg[majorcurint] |= (samecvg << maskshift); |
| 1879 | } |
| 1880 | } |
| 1881 | for (; fleft <= fright; fleft++) |
| 1882 | { |
| 1883 | userdata->m_cvg[fleft] |= fmaskshifted; |
| 1884 | } |
| 1885 | } |
| 1886 | } |
| 1887 | } |
| 1888 | |
| 1889 | void n64_rdp::DrawTriangle(bool shade, bool texture, bool zbuffer, bool rect) |
| 1890 | { |
| 1891 | UINT32 *cmd_data = rect ? m_temp_rect_data : m_cmd_data; |
| 1892 | UINT32 fifo_index = rect ? 0 : m_cmd_cur; |
| 1893 | UINT32 w1 = cmd_data[fifo_index + 0]; |
| 1894 | UINT32 w2 = cmd_data[fifo_index + 1]; |
| 1895 | |
| 1896 | int flip = (w1 & 0x00800000) ? 1 : 0; |
| 1897 | MiscState.MaxLevel = ((w1 >> 19) & 7); |
| 1898 | int tilenum = (w1 >> 16) & 0x7; |
| 1899 | |
| 1900 | int dsdiff = 0, dtdiff = 0, dwdiff = 0, drdiff = 0, dgdiff = 0, dbdiff = 0, dadiff = 0, dzdiff = 0; |
| 1901 | int dsdeh = 0, dtdeh = 0, dwdeh = 0, drdeh = 0, dgdeh = 0, dbdeh = 0, dadeh = 0, dzdeh = 0; |
| 1902 | int dsdxh = 0, dtdxh = 0, dwdxh = 0, drdxh = 0, dgdxh = 0, dbdxh = 0, dadxh = 0, dzdxh = 0; |
| 1903 | int dsdyh = 0, dtdyh = 0, dwdyh = 0, drdyh = 0, dgdyh = 0, dbdyh = 0, dadyh = 0, dzdyh = 0; |
| 1904 | |
| 1905 | INT32 maxxmx = 0; // maxxmx / minxhx very opaque names, consider re-naming |
| 1906 | INT32 minxmx = 0; |
| 1907 | INT32 maxxhx = 0; |
| 1908 | INT32 minxhx = 0; |
| 1909 | |
| 1910 | int shade_base = fifo_index + 8; |
| 1911 | int texture_base = fifo_index + 8; |
| 1912 | int zbuffer_base = fifo_index + 8; |
| 1913 | if(shade) |
| 1914 | { |
| 1915 | texture_base += 16; |
| 1916 | zbuffer_base += 16; |
| 1917 | } |
| 1918 | if(texture) |
| 1919 | { |
| 1920 | zbuffer_base += 16; |
| 1921 | } |
| 1922 | |
| 1923 | UINT32 w3 = cmd_data[fifo_index + 2]; |
| 1924 | UINT32 w4 = cmd_data[fifo_index + 3]; |
| 1925 | UINT32 w5 = cmd_data[fifo_index + 4]; |
| 1926 | UINT32 w6 = cmd_data[fifo_index + 5]; |
| 1927 | UINT32 w7 = cmd_data[fifo_index + 6]; |
| 1928 | UINT32 w8 = cmd_data[fifo_index + 7]; |
| 1929 | |
| 1930 | INT32 yl = (w1 & 0x3fff); |
| 1931 | INT32 ym = ((w2 >> 16) & 0x3fff); |
| 1932 | INT32 yh = ((w2 >> 0) & 0x3fff); |
| 1933 | INT32 xl = (INT32)(w3 & 0x3fffffff); |
| 1934 | INT32 xh = (INT32)(w5 & 0x3fffffff); |
| 1935 | INT32 xm = (INT32)(w7 & 0x3fffffff); |
| 1936 | // Inverse slopes in 16.16 format |
| 1937 | INT32 dxldy = (INT32)(w4); |
| 1938 | INT32 dxhdy = (INT32)(w6); |
| 1939 | INT32 dxmdy = (INT32)(w8); |
| 1940 | |
| 1941 | if (yl & 0x2000) yl |= 0xffffc000; |
| 1942 | if (ym & 0x2000) ym |= 0xffffc000; |
| 1943 | if (yh & 0x2000) yh |= 0xffffc000; |
| 1944 | |
| 1945 | if (xl & 0x20000000) xl |= 0xc0000000; |
| 1946 | if (xm & 0x20000000) xm |= 0xc0000000; |
| 1947 | if (xh & 0x20000000) xh |= 0xc0000000; |
| 1948 | |
| 1949 | int r = (cmd_data[shade_base+0 ] & 0xffff0000) | ((cmd_data[shade_base+4 ] >> 16) & 0x0000ffff); |
| 1950 | int g = ((cmd_data[shade_base+0 ] << 16) & 0xffff0000) | (cmd_data[shade_base+4 ] & 0x0000ffff); |
| 1951 | int b = (cmd_data[shade_base+1 ] & 0xffff0000) | ((cmd_data[shade_base+5 ] >> 16) & 0x0000ffff); |
| 1952 | int a = ((cmd_data[shade_base+1 ] << 16) & 0xffff0000) | (cmd_data[shade_base+5 ] & 0x0000ffff); |
| 1953 | int drdx = (cmd_data[shade_base+2 ] & 0xffff0000) | ((cmd_data[shade_base+6 ] >> 16) & 0x0000ffff); |
| 1954 | int dgdx = ((cmd_data[shade_base+2 ] << 16) & 0xffff0000) | (cmd_data[shade_base+6 ] & 0x0000ffff); |
| 1955 | int dbdx = (cmd_data[shade_base+3 ] & 0xffff0000) | ((cmd_data[shade_base+7 ] >> 16) & 0x0000ffff); |
| 1956 | int dadx = ((cmd_data[shade_base+3 ] << 16) & 0xffff0000) | (cmd_data[shade_base+7 ] & 0x0000ffff); |
| 1957 | int drde = (cmd_data[shade_base+8 ] & 0xffff0000) | ((cmd_data[shade_base+12] >> 16) & 0x0000ffff); |
| 1958 | int dgde = ((cmd_data[shade_base+8 ] << 16) & 0xffff0000) | (cmd_data[shade_base+12] & 0x0000ffff); |
| 1959 | int dbde = (cmd_data[shade_base+9 ] & 0xffff0000) | ((cmd_data[shade_base+13] >> 16) & 0x0000ffff); |
| 1960 | int dade = ((cmd_data[shade_base+9 ] << 16) & 0xffff0000) | (cmd_data[shade_base+13] & 0x0000ffff); |
| 1961 | int drdy = (cmd_data[shade_base+10] & 0xffff0000) | ((cmd_data[shade_base+14] >> 16) & 0x0000ffff); |
| 1962 | int dgdy = ((cmd_data[shade_base+10] << 16) & 0xffff0000) | (cmd_data[shade_base+14] & 0x0000ffff); |
| 1963 | int dbdy = (cmd_data[shade_base+11] & 0xffff0000) | ((cmd_data[shade_base+15] >> 16) & 0x0000ffff); |
| 1964 | int dady = ((cmd_data[shade_base+11] << 16) & 0xffff0000) | (cmd_data[shade_base+15] & 0x0000ffff); |
| 1965 | int s = (cmd_data[texture_base+0 ] & 0xffff0000) | ((cmd_data[texture_base+4 ] >> 16) & 0x0000ffff); |
| 1966 | int t = ((cmd_data[texture_base+0 ] << 16) & 0xffff0000) | (cmd_data[texture_base+4 ] & 0x0000ffff); |
| 1967 | int w = (cmd_data[texture_base+1 ] & 0xffff0000) | ((cmd_data[texture_base+5 ] >> 16) & 0x0000ffff); |
| 1968 | int dsdx = (cmd_data[texture_base+2 ] & 0xffff0000) | ((cmd_data[texture_base+6 ] >> 16) & 0x0000ffff); |
| 1969 | int dtdx = ((cmd_data[texture_base+2 ] << 16) & 0xffff0000) | (cmd_data[texture_base+6 ] & 0x0000ffff); |
| 1970 | int dwdx = (cmd_data[texture_base+3 ] & 0xffff0000) | ((cmd_data[texture_base+7 ] >> 16) & 0x0000ffff); |
| 1971 | int dsde = (cmd_data[texture_base+8 ] & 0xffff0000) | ((cmd_data[texture_base+12] >> 16) & 0x0000ffff); |
| 1972 | int dtde = ((cmd_data[texture_base+8 ] << 16) & 0xffff0000) | (cmd_data[texture_base+12] & 0x0000ffff); |
| 1973 | int dwde = (cmd_data[texture_base+9 ] & 0xffff0000) | ((cmd_data[texture_base+13] >> 16) & 0x0000ffff); |
| 1974 | int dsdy = (cmd_data[texture_base+10] & 0xffff0000) | ((cmd_data[texture_base+14] >> 16) & 0x0000ffff); |
| 1975 | int dtdy = ((cmd_data[texture_base+10] << 16) & 0xffff0000) | (cmd_data[texture_base+14] & 0x0000ffff); |
| 1976 | int dwdy = (cmd_data[texture_base+11] & 0xffff0000) | ((cmd_data[texture_base+15] >> 16) & 0x0000ffff); |
| 1977 | int z = cmd_data[zbuffer_base+0]; |
| 1978 | int dzdx = cmd_data[zbuffer_base+1]; |
| 1979 | int dzde = cmd_data[zbuffer_base+2]; |
| 1980 | int dzdy = cmd_data[zbuffer_base+3]; |
| 1981 | |
| 1982 | int dzdy_dz = (dzdy >> 16) & 0xffff; |
| 1983 | int dzdx_dz = (dzdx >> 16) & 0xffff; |
| 1984 | |
| 1985 | extent_t Spans[2048]; |
| 1986 | |
| 1987 | SpanBase.m_span_drdy = drdy; |
| 1988 | SpanBase.m_span_dgdy = dgdy; |
| 1989 | SpanBase.m_span_dbdy = dbdy; |
| 1990 | SpanBase.m_span_dady = dady; |
| 1991 | SpanBase.m_span_dzdy = OtherModes.z_source_sel ? 0 : dzdy; |
| 1992 | |
| 1993 | UINT32 temp_dzpix = ((dzdy_dz & 0x8000) ? ((~dzdy_dz) & 0x7fff) : dzdy_dz) + ((dzdx_dz & 0x8000) ? ((~dzdx_dz) & 0x7fff) : dzdx_dz); |
| 1994 | SpanBase.m_span_dr = drdx & ~0x1f; |
| 1995 | SpanBase.m_span_dg = dgdx & ~0x1f; |
| 1996 | SpanBase.m_span_db = dbdx & ~0x1f; |
| 1997 | SpanBase.m_span_da = dadx & ~0x1f; |
| 1998 | SpanBase.m_span_ds = dsdx; |
| 1999 | SpanBase.m_span_dt = dtdx; |
| 2000 | SpanBase.m_span_dw = dwdx; |
| 2001 | SpanBase.m_span_dz = OtherModes.z_source_sel ? 0 : dzdx; |
| 2002 | SpanBase.m_span_dymax = 0; |
| 2003 | SpanBase.m_span_dzpix = NormalizeDZPix(temp_dzpix & 0xffff) & 0xffff; |
| 2004 | |
| 2005 | int xleft_inc = (dxmdy >> 2) & ~1; |
| 2006 | int xright_inc = (dxhdy >> 2) & ~1; |
| 2007 | |
| 2008 | int xright = xh & ~1; |
| 2009 | int xleft = xm & ~1; |
| 2010 | |
| 2011 | int sign_dxhdy = (dxhdy & 0x80000000) ? 1 : 0; |
| 2012 | int do_offset = !(sign_dxhdy ^ (flip)); |
| 2013 | |
| 2014 | if (do_offset) |
| 2015 | { |
| 2016 | dsdeh = dsde >> 9; dsdyh = dsdy >> 9; |
| 2017 | dtdeh = dtde >> 9; dtdyh = dtdy >> 9; |
| 2018 | dwdeh = dwde >> 9; dwdyh = dwdy >> 9; |
| 2019 | drdeh = drde >> 9; drdyh = drdy >> 9; |
| 2020 | dgdeh = dgde >> 9; dgdyh = dgdy >> 9; |
| 2021 | dbdeh = dbde >> 9; dbdyh = dbdy >> 9; |
| 2022 | dadeh = dade >> 9; dadyh = dady >> 9; |
| 2023 | dzdeh = dzde >> 9; dzdyh = dzdy >> 9; |
| 2024 | |
| 2025 | dsdiff = (dsdeh << 8) + (dsdeh << 7) - (dsdyh << 8) - (dsdyh << 7); |
| 2026 | dtdiff = (dtdeh << 8) + (dtdeh << 7) - (dtdyh << 8) - (dtdyh << 7); |
| 2027 | dwdiff = (dwdeh << 8) + (dwdeh << 7) - (dwdyh << 8) - (dwdyh << 7); |
| 2028 | drdiff = (drdeh << 8) + (drdeh << 7) - (drdyh << 8) - (drdyh << 7); |
| 2029 | dgdiff = (dgdeh << 8) + (dgdeh << 7) - (dgdyh << 8) - (dgdyh << 7); |
| 2030 | dbdiff = (dbdeh << 8) + (dbdeh << 7) - (dbdyh << 8) - (dbdyh << 7); |
| 2031 | dadiff = (dadeh << 8) + (dadeh << 7) - (dadyh << 8) - (dadyh << 7); |
| 2032 | dzdiff = (dzdeh << 8) + (dzdeh << 7) - (dzdyh << 8) - (dzdyh << 7); |
| 2033 | } |
| 2034 | else |
| 2035 | { |
| 2036 | dsdiff = dtdiff = dwdiff = drdiff = dgdiff = dbdiff = dadiff = dzdiff = 0; |
| 2037 | } |
| 2038 | |
| 2039 | dsdxh = dsdx >> 8; |
| 2040 | dtdxh = dtdx >> 8; |
| 2041 | dwdxh = dwdx >> 8; |
| 2042 | drdxh = drdx >> 8; |
| 2043 | dgdxh = dgdx >> 8; |
| 2044 | dbdxh = dbdx >> 8; |
| 2045 | dadxh = dadx >> 8; |
| 2046 | dzdxh = dzdx >> 8; |
| 2047 | |
| 2048 | INT32 ycur = yh & ~3; |
| 2049 | INT32 ylfar = yl | 3; |
| 2050 | INT32 ldflag = (sign_dxhdy ^ flip) ? 0 : 3; |
| 2051 | INT32 majorx[4]; |
| 2052 | INT32 minorx[4]; |
| 2053 | INT32 majorxint[4]; |
| 2054 | INT32 minorxint[4]; |
| 2055 | bool valid_y = true; |
| 2056 | |
| 2057 | int xfrac = ((xright >> 8) & 0xff); |
| 2058 | |
| 2059 | int clipy1 = Scissor.m_yh; |
| 2060 | int clipy2 = Scissor.m_yl; |
| 2061 | |
| 2062 | // Trivial reject |
| 2063 | if((ycur >> 2) >= clipy2 && (ylfar >> 2) >= clipy2) |
| 2064 | { |
| 2065 | return; |
| 2066 | } |
| 2067 | if((ycur >> 2) < clipy1 && (ylfar >> 2) < clipy1) |
| 2068 | { |
| 2069 | return; |
| 2070 | } |
| 2071 | |
| 2072 | bool new_object = true; |
| 2073 | rdp_poly_state *object = NULL; |
| 2074 | bool valid = false; |
| 2075 | |
| 2076 | if(flip) |
| 2077 | { |
| 2078 | for (int k = ycur; k <= ylfar; k++) |
| 2079 | { |
| 2080 | if (k == ym) |
| 2081 | { |
| 2082 | xleft = xl & ~1; |
| 2083 | xleft_inc = (dxldy >> 2) & ~1; |
| 2084 | } |
| 2085 | |
| 2086 | int xstart = xleft >> 16; // 319 |
| 2087 | int xend = xright >> 16; // 0 |
| 2088 | int j = k >> 2; |
| 2089 | int spanidx = (k - ycur) >> 2; |
| 2090 | int spix = k & 3; |
| 2091 | valid_y = !(k < yh || k >= yl); |
| 2092 | |
| 2093 | if (spanidx >= 0 && spanidx < 2048) |
| 2094 | { |
| 2095 | majorxint[spix] = xend; // 0 |
| 2096 | minorxint[spix] = xstart; // 319 |
| 2097 | majorx[spix] = xright; // 0x00000000 |
| 2098 | minorx[spix] = xleft; // 0x013f0000 |
| 2099 | |
| 2100 | if (spix == 0) |
| 2101 | { |
| 2102 | maxxmx = 0; |
| 2103 | minxhx = 0xfff; |
| 2104 | } |
| 2105 | |
| 2106 | if (valid_y) |
| 2107 | { |
| 2108 | maxxmx = (xstart > maxxmx) ? xstart : maxxmx; |
| 2109 | minxhx = (xend < minxhx) ? xend : minxhx; |
| 2110 | } |
| 2111 | |
| 2112 | if (spix == 0) |
| 2113 | { |
| 2114 | if(new_object) |
| 2115 | { |
| 2116 | object = &object_data_alloc(); |
| 2117 | memcpy(object->m_tmem, m_tmem, 0x1000); |
| 2118 | new_object = false; |
| 2119 | } |
| 2120 | |
| 2121 | Spans[spanidx].userdata = (void*)((UINT8*)AuxBuf + AuxBufPtr); |
| 2122 | AuxBufPtr += sizeof(rdp_span_aux); |
| 2123 | |
| 2124 | if(AuxBufPtr >= EXTENT_AUX_COUNT) |
| 2125 | { |
| 2126 | fatalerror("n64_rdp::DrawTriangle: span aux buffer overflow\n"); |
| 2127 | } |
| 2128 | |
| 2129 | rdp_span_aux *userdata = (rdp_span_aux*)Spans[spanidx].userdata; |
| 2130 | valid = true; |
| 2131 | |
| 2132 | userdata->m_tmem = object->m_tmem; |
| 2133 | |
| 2134 | userdata->BlendColor = BlendColor; |
| 2135 | userdata->PrimColor = PrimColor; |
| 2136 | userdata->EnvColor = EnvColor; |
| 2137 | userdata->FogColor = FogColor; |
| 2138 | userdata->KeyScale = KeyScale; |
| 2139 | userdata->LODFraction = LODFraction; |
| 2140 | userdata->PrimLODFraction = PrimLODFraction; |
| 2141 | |
| 2142 | userdata->ColorInputs.combiner_rgbsub_a_r[0] = userdata->ColorInputs.combiner_rgbsub_a_r[1] = &OneColor.i.r; |
| 2143 | userdata->ColorInputs.combiner_rgbsub_a_g[0] = userdata->ColorInputs.combiner_rgbsub_a_g[1] = &OneColor.i.g; |
| 2144 | userdata->ColorInputs.combiner_rgbsub_a_b[0] = userdata->ColorInputs.combiner_rgbsub_a_b[1] = &OneColor.i.b; |
| 2145 | userdata->ColorInputs.combiner_rgbsub_b_r[0] = userdata->ColorInputs.combiner_rgbsub_b_r[1] = &OneColor.i.r; |
| 2146 | userdata->ColorInputs.combiner_rgbsub_b_g[0] = userdata->ColorInputs.combiner_rgbsub_b_g[1] = &OneColor.i.g; |
| 2147 | userdata->ColorInputs.combiner_rgbsub_b_b[0] = userdata->ColorInputs.combiner_rgbsub_b_b[1] = &OneColor.i.b; |
| 2148 | userdata->ColorInputs.combiner_rgbmul_r[0] = userdata->ColorInputs.combiner_rgbmul_r[1] = &OneColor.i.r; |
| 2149 | userdata->ColorInputs.combiner_rgbmul_g[0] = userdata->ColorInputs.combiner_rgbmul_g[1] = &OneColor.i.g; |
| 2150 | userdata->ColorInputs.combiner_rgbmul_b[0] = userdata->ColorInputs.combiner_rgbmul_b[1] = &OneColor.i.b; |
| 2151 | userdata->ColorInputs.combiner_rgbadd_r[0] = userdata->ColorInputs.combiner_rgbadd_r[1] = &OneColor.i.r; |
| 2152 | userdata->ColorInputs.combiner_rgbadd_g[0] = userdata->ColorInputs.combiner_rgbadd_g[1] = &OneColor.i.g; |
| 2153 | userdata->ColorInputs.combiner_rgbadd_b[0] = userdata->ColorInputs.combiner_rgbadd_b[1] = &OneColor.i.b; |
| 2154 | userdata->ColorInputs.combiner_alphasub_a[0] = userdata->ColorInputs.combiner_alphasub_a[1] = &OneColor.i.a; |
| 2155 | userdata->ColorInputs.combiner_alphasub_b[0] = userdata->ColorInputs.combiner_alphasub_b[1] = &OneColor.i.a; |
| 2156 | userdata->ColorInputs.combiner_alphamul[0] = userdata->ColorInputs.combiner_alphamul[1] = &OneColor.i.a; |
| 2157 | userdata->ColorInputs.combiner_alphaadd[0] = userdata->ColorInputs.combiner_alphaadd[1] = &OneColor.i.a; |
| 2158 | |
| 2159 | userdata->ColorInputs.blender1a_r[0] = userdata->ColorInputs.blender1a_r[1] = &userdata->PixelColor.i.r; |
| 2160 | userdata->ColorInputs.blender1a_g[0] = userdata->ColorInputs.blender1a_g[1] = &userdata->PixelColor.i.g; |
| 2161 | userdata->ColorInputs.blender1a_b[0] = userdata->ColorInputs.blender1a_b[1] = &userdata->PixelColor.i.b; |
| 2162 | userdata->ColorInputs.blender1b_a[0] = userdata->ColorInputs.blender1b_a[1] = &userdata->PixelColor.i.a; |
| 2163 | userdata->ColorInputs.blender2a_r[0] = userdata->ColorInputs.blender2a_r[1] = &userdata->PixelColor.i.r; |
| 2164 | userdata->ColorInputs.blender2a_g[0] = userdata->ColorInputs.blender2a_g[1] = &userdata->PixelColor.i.g; |
| 2165 | userdata->ColorInputs.blender2a_b[0] = userdata->ColorInputs.blender2a_b[1] = &userdata->PixelColor.i.b; |
| 2166 | userdata->ColorInputs.blender2b_a[0] = userdata->ColorInputs.blender2b_a[1] = &userdata->PixelColor.i.a; |
| 2167 | |
| 2168 | // Setup blender data for this scanline |
| 2169 | SetBlenderInput(0, 0, &userdata->ColorInputs.blender1a_r[0], |
| 2170 | &userdata->ColorInputs.blender1a_g[0], |
| 2171 | &userdata->ColorInputs.blender1a_b[0], |
| 2172 | &userdata->ColorInputs.blender1b_a[0], OtherModes.blend_m1a_0, OtherModes.blend_m1b_0, userdata); |
| 2173 | SetBlenderInput(0, 1, &userdata->ColorInputs.blender2a_r[0], |
| 2174 | &userdata->ColorInputs.blender2a_g[0], |
| 2175 | &userdata->ColorInputs.blender2a_b[0], |
| 2176 | &userdata->ColorInputs.blender2b_a[0], OtherModes.blend_m2a_0, OtherModes.blend_m2b_0, userdata); |
| 2177 | SetBlenderInput(1, 0, &userdata->ColorInputs.blender1a_r[1], |
| 2178 | &userdata->ColorInputs.blender1a_g[1], |
| 2179 | &userdata->ColorInputs.blender1a_b[1], |
| 2180 | &userdata->ColorInputs.blender1b_a[1], OtherModes.blend_m1a_1, OtherModes.blend_m1b_1, userdata); |
| 2181 | SetBlenderInput(1, 1, &userdata->ColorInputs.blender2a_r[1], |
| 2182 | &userdata->ColorInputs.blender2a_g[1], |
| 2183 | &userdata->ColorInputs.blender2a_b[1], |
| 2184 | &userdata->ColorInputs.blender2b_a[1], OtherModes.blend_m2a_1, OtherModes.blend_m2b_1, userdata); |
| 2185 | |
| 2186 | // Setup color combiner data for this scanline |
| 2187 | SetSubAInputRGB(&userdata->ColorInputs.combiner_rgbsub_a_r[0], &userdata->ColorInputs.combiner_rgbsub_a_g[0], &userdata->ColorInputs.combiner_rgbsub_a_b[0], m_combine.sub_a_rgb0, userdata); |
| 2188 | SetSubBInputRGB(&userdata->ColorInputs.combiner_rgbsub_b_r[0], &userdata->ColorInputs.combiner_rgbsub_b_g[0], &userdata->ColorInputs.combiner_rgbsub_b_b[0], m_combine.sub_b_rgb0, userdata); |
| 2189 | SetMulInputRGB(&userdata->ColorInputs.combiner_rgbmul_r[0], &userdata->ColorInputs.combiner_rgbmul_g[0], &userdata->ColorInputs.combiner_rgbmul_b[0], m_combine.mul_rgb0, userdata); |
| 2190 | SetAddInputRGB(&userdata->ColorInputs.combiner_rgbadd_r[0], &userdata->ColorInputs.combiner_rgbadd_g[0], &userdata->ColorInputs.combiner_rgbadd_b[0], m_combine.add_rgb0, userdata); |
| 2191 | SetSubInputAlpha(&userdata->ColorInputs.combiner_alphasub_a[0], m_combine.sub_a_a0, userdata); |
| 2192 | SetSubInputAlpha(&userdata->ColorInputs.combiner_alphasub_b[0], m_combine.sub_b_a0, userdata); |
| 2193 | SetMulInputAlpha(&userdata->ColorInputs.combiner_alphamul[0], m_combine.mul_a0, userdata); |
| 2194 | SetSubInputAlpha(&userdata->ColorInputs.combiner_alphaadd[0], m_combine.add_a0, userdata); |
| 2195 | |
| 2196 | SetSubAInputRGB(&userdata->ColorInputs.combiner_rgbsub_a_r[1], &userdata->ColorInputs.combiner_rgbsub_a_g[1], &userdata->ColorInputs.combiner_rgbsub_a_b[1], m_combine.sub_a_rgb1, userdata); |
| 2197 | SetSubBInputRGB(&userdata->ColorInputs.combiner_rgbsub_b_r[1], &userdata->ColorInputs.combiner_rgbsub_b_g[1], &userdata->ColorInputs.combiner_rgbsub_b_b[1], m_combine.sub_b_rgb1, userdata); |
| 2198 | SetMulInputRGB(&userdata->ColorInputs.combiner_rgbmul_r[1], &userdata->ColorInputs.combiner_rgbmul_g[1], &userdata->ColorInputs.combiner_rgbmul_b[1], m_combine.mul_rgb1, userdata); |
| 2199 | SetAddInputRGB(&userdata->ColorInputs.combiner_rgbadd_r[1], &userdata->ColorInputs.combiner_rgbadd_g[1], &userdata->ColorInputs.combiner_rgbadd_b[1], m_combine.add_rgb1, userdata); |
| 2200 | SetSubInputAlpha(&userdata->ColorInputs.combiner_alphasub_a[1], m_combine.sub_a_a1, userdata); |
| 2201 | SetSubInputAlpha(&userdata->ColorInputs.combiner_alphasub_b[1], m_combine.sub_b_a1, userdata); |
| 2202 | SetMulInputAlpha(&userdata->ColorInputs.combiner_alphamul[1], m_combine.mul_a1, userdata); |
| 2203 | SetSubInputAlpha(&userdata->ColorInputs.combiner_alphaadd[1], m_combine.add_a1, userdata); |
| 2204 | } |
| 2205 | |
| 2206 | if (spix == 3) |
| 2207 | { |
| 2208 | Spans[spanidx].startx = maxxmx; |
| 2209 | Spans[spanidx].stopx = minxhx; |
| 2210 | compute_cvg_flip(Spans, majorx, minorx, majorxint, minorxint, j, yh, yl, ycur >> 2); |
| 2211 | } |
| 2212 | |
| 2213 | if (spix == ldflag) |
| 2214 | { |
| 2215 | ((rdp_span_aux*)Spans[spanidx].userdata)->m_unscissored_rx = xend; |
| 2216 | xfrac = ((xright >> 8) & 0xff); |
| 2217 | Spans[spanidx].param[SPAN_R].start = ((r >> 9) << 9) + drdiff - (xfrac * drdxh); |
| 2218 | Spans[spanidx].param[SPAN_G].start = ((g >> 9) << 9) + dgdiff - (xfrac * dgdxh); |
| 2219 | Spans[spanidx].param[SPAN_B].start = ((b >> 9) << 9) + dbdiff - (xfrac * dbdxh); |
| 2220 | Spans[spanidx].param[SPAN_A].start = ((a >> 9) << 9) + dadiff - (xfrac * dadxh); |
| 2221 | Spans[spanidx].param[SPAN_S].start = (((s >> 9) << 9) + dsdiff - (xfrac * dsdxh)) & ~0x1f; |
| 2222 | Spans[spanidx].param[SPAN_T].start = (((t >> 9) << 9) + dtdiff - (xfrac * dtdxh)) & ~0x1f; |
| 2223 | Spans[spanidx].param[SPAN_W].start = (((w >> 9) << 9) + dwdiff - (xfrac * dwdxh)) & ~0x1f; |
| 2224 | Spans[spanidx].param[SPAN_Z].start = ((z >> 9) << 9) + dzdiff - (xfrac * dzdxh); |
| 2225 | } |
| 2226 | } |
| 2227 | |
| 2228 | if (spix == 3) |
| 2229 | { |
| 2230 | r += drde; |
| 2231 | g += dgde; |
| 2232 | b += dbde; |
| 2233 | a += dade; |
| 2234 | s += dsde; |
| 2235 | t += dtde; |
| 2236 | w += dwde; |
| 2237 | z += dzde; |
| 2238 | } |
| 2239 | |
| 2240 | xleft += xleft_inc; |
| 2241 | xright += xright_inc; |
| 2242 | } |
| 2243 | } |
| 2244 | else |
| 2245 | { |
| 2246 | for (int k = ycur; k <= ylfar; k++) |
| 2247 | { |
| 2248 | if (k == ym) |
| 2249 | { |
| 2250 | xleft = xl & ~1; |
| 2251 | xleft_inc = (dxldy >> 2) & ~1; |
| 2252 | } |
| 2253 | |
| 2254 | int xstart = xleft >> 16; |
| 2255 | int xend = xright >> 16; |
| 2256 | int j = k >> 2; |
| 2257 | int spanidx = j - (ycur >> 2); |
| 2258 | int spix = k & 3; |
| 2259 | valid_y = !(k < yh || k >= yl); |
| 2260 | |
| 2261 | if (k >= 0 && k < 0x1000) |
| 2262 | { |
| 2263 | majorxint[spix] = xend; |
| 2264 | minorxint[spix] = xstart; |
| 2265 | majorx[spix] = xright; |
| 2266 | minorx[spix] = xleft; |
| 2267 | |
| 2268 | if (spix == 0) |
| 2269 | { |
| 2270 | maxxhx = 0; |
| 2271 | minxmx = 0xfff; |
| 2272 | } |
| 2273 | |
| 2274 | if (valid_y) |
| 2275 | { |
| 2276 | minxmx = (xstart < minxmx) ? xstart : minxmx; |
| 2277 | maxxhx = (xend > maxxhx) ? xend : maxxhx; |
| 2278 | } |
| 2279 | |
| 2280 | if (spix == 0) |
| 2281 | { |
| 2282 | if(new_object) |
| 2283 | { |
| 2284 | object = &object_data_alloc(); |
| 2285 | memcpy(object->m_tmem, m_tmem, 0x1000); |
| 2286 | new_object = false; |
| 2287 | } |
| 2288 | |
| 2289 | Spans[spanidx].userdata = (void*)((UINT8*)AuxBuf + AuxBufPtr); |
| 2290 | valid = true; |
| 2291 | AuxBufPtr += sizeof(rdp_span_aux); |
| 2292 | |
| 2293 | if(AuxBufPtr >= EXTENT_AUX_COUNT) |
| 2294 | { |
| 2295 | fatalerror("n64_rdp::DrawTriangle: span aux buffer overflow\n"); |
| 2296 | } |
| 2297 | |
| 2298 | rdp_span_aux *userdata = (rdp_span_aux*)Spans[spanidx].userdata; |
| 2299 | userdata->m_tmem = object->m_tmem; |
| 2300 | |
| 2301 | userdata->BlendColor = BlendColor; |
| 2302 | userdata->PrimColor = PrimColor; |
| 2303 | userdata->EnvColor = EnvColor; |
| 2304 | userdata->FogColor = FogColor; |
| 2305 | userdata->KeyScale = KeyScale; |
| 2306 | userdata->LODFraction = LODFraction; |
| 2307 | userdata->PrimLODFraction = PrimLODFraction; |
| 2308 | |
| 2309 | userdata->ColorInputs.combiner_rgbsub_a_r[0] = userdata->ColorInputs.combiner_rgbsub_a_r[1] = &OneColor.i.r; |
| 2310 | userdata->ColorInputs.combiner_rgbsub_a_g[0] = userdata->ColorInputs.combiner_rgbsub_a_g[1] = &OneColor.i.g; |
| 2311 | userdata->ColorInputs.combiner_rgbsub_a_b[0] = userdata->ColorInputs.combiner_rgbsub_a_b[1] = &OneColor.i.b; |
| 2312 | userdata->ColorInputs.combiner_rgbsub_b_r[0] = userdata->ColorInputs.combiner_rgbsub_b_r[1] = &OneColor.i.r; |
| 2313 | userdata->ColorInputs.combiner_rgbsub_b_g[0] = userdata->ColorInputs.combiner_rgbsub_b_g[1] = &OneColor.i.g; |
| 2314 | userdata->ColorInputs.combiner_rgbsub_b_b[0] = userdata->ColorInputs.combiner_rgbsub_b_b[1] = &OneColor.i.b; |
| 2315 | userdata->ColorInputs.combiner_rgbmul_r[0] = userdata->ColorInputs.combiner_rgbmul_r[1] = &OneColor.i.r; |
| 2316 | userdata->ColorInputs.combiner_rgbmul_g[0] = userdata->ColorInputs.combiner_rgbmul_g[1] = &OneColor.i.g; |
| 2317 | userdata->ColorInputs.combiner_rgbmul_b[0] = userdata->ColorInputs.combiner_rgbmul_b[1] = &OneColor.i.b; |
| 2318 | userdata->ColorInputs.combiner_rgbadd_r[0] = userdata->ColorInputs.combiner_rgbadd_r[1] = &OneColor.i.r; |
| 2319 | userdata->ColorInputs.combiner_rgbadd_g[0] = userdata->ColorInputs.combiner_rgbadd_g[1] = &OneColor.i.g; |
| 2320 | userdata->ColorInputs.combiner_rgbadd_b[0] = userdata->ColorInputs.combiner_rgbadd_b[1] = &OneColor.i.b; |
| 2321 | userdata->ColorInputs.combiner_alphasub_a[0] = userdata->ColorInputs.combiner_alphasub_a[1] = &OneColor.i.a; |
| 2322 | userdata->ColorInputs.combiner_alphasub_b[0] = userdata->ColorInputs.combiner_alphasub_b[1] = &OneColor.i.a; |
| 2323 | userdata->ColorInputs.combiner_alphamul[0] = userdata->ColorInputs.combiner_alphamul[1] = &OneColor.i.a; |
| 2324 | userdata->ColorInputs.combiner_alphaadd[0] = userdata->ColorInputs.combiner_alphaadd[1] = &OneColor.i.a; |
| 2325 | |
| 2326 | userdata->ColorInputs.blender1a_r[0] = userdata->ColorInputs.blender1a_r[1] = &userdata->PixelColor.i.r; |
| 2327 | userdata->ColorInputs.blender1a_g[0] = userdata->ColorInputs.blender1a_g[1] = &userdata->PixelColor.i.g; |
| 2328 | userdata->ColorInputs.blender1a_b[0] = userdata->ColorInputs.blender1a_b[1] = &userdata->PixelColor.i.b; |
| 2329 | userdata->ColorInputs.blender1b_a[0] = userdata->ColorInputs.blender1b_a[1] = &userdata->PixelColor.i.a; |
| 2330 | userdata->ColorInputs.blender2a_r[0] = userdata->ColorInputs.blender2a_r[1] = &userdata->PixelColor.i.r; |
| 2331 | userdata->ColorInputs.blender2a_g[0] = userdata->ColorInputs.blender2a_g[1] = &userdata->PixelColor.i.g; |
| 2332 | userdata->ColorInputs.blender2a_b[0] = userdata->ColorInputs.blender2a_b[1] = &userdata->PixelColor.i.b; |
| 2333 | userdata->ColorInputs.blender2b_a[0] = userdata->ColorInputs.blender2b_a[1] = &userdata->PixelColor.i.a; |
| 2334 | |
| 2335 | // Setup blender data for this scanline |
| 2336 | SetBlenderInput(0, 0, &userdata->ColorInputs.blender1a_r[0], |
| 2337 | &userdata->ColorInputs.blender1a_g[0], |
| 2338 | &userdata->ColorInputs.blender1a_b[0], |
| 2339 | &userdata->ColorInputs.blender1b_a[0], OtherModes.blend_m1a_0, OtherModes.blend_m1b_0, userdata); |
| 2340 | SetBlenderInput(0, 1, &userdata->ColorInputs.blender2a_r[0], |
| 2341 | &userdata->ColorInputs.blender2a_g[0], |
| 2342 | &userdata->ColorInputs.blender2a_b[0], |
| 2343 | &userdata->ColorInputs.blender2b_a[0], OtherModes.blend_m2a_0, OtherModes.blend_m2b_0, userdata); |
| 2344 | SetBlenderInput(1, 0, &userdata->ColorInputs.blender1a_r[1], |
| 2345 | &userdata->ColorInputs.blender1a_g[1], |
| 2346 | &userdata->ColorInputs.blender1a_b[1], |
| 2347 | &userdata->ColorInputs.blender1b_a[1], OtherModes.blend_m1a_1, OtherModes.blend_m1b_1, userdata); |
| 2348 | SetBlenderInput(1, 1, &userdata->ColorInputs.blender2a_r[1], |
| 2349 | &userdata->ColorInputs.blender2a_g[1], |
| 2350 | &userdata->ColorInputs.blender2a_b[1], |
| 2351 | &userdata->ColorInputs.blender2b_a[1], OtherModes.blend_m2a_1, OtherModes.blend_m2b_1, userdata); |
| 2352 | |
| 2353 | // Setup color combiner data for this scanline |
| 2354 | SetSubAInputRGB(&userdata->ColorInputs.combiner_rgbsub_a_r[0], &userdata->ColorInputs.combiner_rgbsub_a_g[0], &userdata->ColorInputs.combiner_rgbsub_a_b[0], m_combine.sub_a_rgb0, userdata); |
| 2355 | SetSubBInputRGB(&userdata->ColorInputs.combiner_rgbsub_b_r[0], &userdata->ColorInputs.combiner_rgbsub_b_g[0], &userdata->ColorInputs.combiner_rgbsub_b_b[0], m_combine.sub_b_rgb0, userdata); |
| 2356 | SetMulInputRGB(&userdata->ColorInputs.combiner_rgbmul_r[0], &userdata->ColorInputs.combiner_rgbmul_g[0], &userdata->ColorInputs.combiner_rgbmul_b[0], m_combine.mul_rgb0, userdata); |
| 2357 | SetAddInputRGB(&userdata->ColorInputs.combiner_rgbadd_r[0], &userdata->ColorInputs.combiner_rgbadd_g[0], &userdata->ColorInputs.combiner_rgbadd_b[0], m_combine.add_rgb0, userdata); |
| 2358 | SetSubInputAlpha(&userdata->ColorInputs.combiner_alphasub_a[0], m_combine.sub_a_a0, userdata); |
| 2359 | SetSubInputAlpha(&userdata->ColorInputs.combiner_alphasub_b[0], m_combine.sub_b_a0, userdata); |
| 2360 | SetMulInputAlpha(&userdata->ColorInputs.combiner_alphamul[0], m_combine.mul_a0, userdata); |
| 2361 | SetSubInputAlpha(&userdata->ColorInputs.combiner_alphaadd[0], m_combine.add_a0, userdata); |
| 2362 | |
| 2363 | SetSubAInputRGB(&userdata->ColorInputs.combiner_rgbsub_a_r[1], &userdata->ColorInputs.combiner_rgbsub_a_g[1], &userdata->ColorInputs.combiner_rgbsub_a_b[1], m_combine.sub_a_rgb1, userdata); |
| 2364 | SetSubBInputRGB(&userdata->ColorInputs.combiner_rgbsub_b_r[1], &userdata->ColorInputs.combiner_rgbsub_b_g[1], &userdata->ColorInputs.combiner_rgbsub_b_b[1], m_combine.sub_b_rgb1, userdata); |
| 2365 | SetMulInputRGB(&userdata->ColorInputs.combiner_rgbmul_r[1], &userdata->ColorInputs.combiner_rgbmul_g[1], &userdata->ColorInputs.combiner_rgbmul_b[1], m_combine.mul_rgb1, userdata); |
| 2366 | SetAddInputRGB(&userdata->ColorInputs.combiner_rgbadd_r[1], &userdata->ColorInputs.combiner_rgbadd_g[1], &userdata->ColorInputs.combiner_rgbadd_b[1], m_combine.add_rgb1, userdata); |
| 2367 | SetSubInputAlpha(&userdata->ColorInputs.combiner_alphasub_a[1], m_combine.sub_a_a1, userdata); |
| 2368 | SetSubInputAlpha(&userdata->ColorInputs.combiner_alphasub_b[1], m_combine.sub_b_a1, userdata); |
| 2369 | SetMulInputAlpha(&userdata->ColorInputs.combiner_alphamul[1], m_combine.mul_a1, userdata); |
| 2370 | SetSubInputAlpha(&userdata->ColorInputs.combiner_alphaadd[1], m_combine.add_a1, userdata); |
| 2371 | } |
| 2372 | |
| 2373 | if (spix == 3) |
| 2374 | { |
| 2375 | Spans[spanidx].startx = minxmx; |
| 2376 | Spans[spanidx].stopx = maxxhx; |
| 2377 | compute_cvg_noflip(Spans, majorx, minorx, majorxint, minorxint, j, yh, yl, ycur >> 2); |
| 2378 | } |
| 2379 | |
| 2380 | if (spix == ldflag) |
| 2381 | { |
| 2382 | ((rdp_span_aux*)Spans[spanidx].userdata)->m_unscissored_rx = xend; |
| 2383 | xfrac = ((xright >> 8) & 0xff); |
| 2384 | Spans[spanidx].param[SPAN_R].start = ((r >> 9) << 9) + drdiff - (xfrac * drdxh); |
| 2385 | Spans[spanidx].param[SPAN_G].start = ((g >> 9) << 9) + dgdiff - (xfrac * dgdxh); |
| 2386 | Spans[spanidx].param[SPAN_B].start = ((b >> 9) << 9) + dbdiff - (xfrac * dbdxh); |
| 2387 | Spans[spanidx].param[SPAN_A].start = ((a >> 9) << 9) + dadiff - (xfrac * dadxh); |
| 2388 | Spans[spanidx].param[SPAN_S].start = (((s >> 9) << 9) + dsdiff - (xfrac * dsdxh)) & ~0x1f; |
| 2389 | Spans[spanidx].param[SPAN_T].start = (((t >> 9) << 9) + dtdiff - (xfrac * dtdxh)) & ~0x1f; |
| 2390 | Spans[spanidx].param[SPAN_W].start = (((w >> 9) << 9) + dwdiff - (xfrac * dwdxh)) & ~0x1f; |
| 2391 | Spans[spanidx].param[SPAN_Z].start = ((z >> 9) << 9) + dzdiff - (xfrac * dzdxh); |
| 2392 | } |
| 2393 | } |
| 2394 | |
| 2395 | if (spix == 3) |
| 2396 | { |
| 2397 | r += drde; |
| 2398 | g += dgde; |
| 2399 | b += dbde; |
| 2400 | a += dade; |
| 2401 | s += dsde; |
| 2402 | t += dtde; |
| 2403 | w += dwde; |
| 2404 | z += dzde; |
| 2405 | } |
| 2406 | xleft += xleft_inc; |
| 2407 | xright += xright_inc; |
| 2408 | } |
| 2409 | } |
| 2410 | |
| 2411 | if(!new_object && valid) |
| 2412 | { |
| 2413 | RenderSpans(yh >> 2, yl >> 2, tilenum, flip ? true : false, Spans, rect, object); |
| 2414 | } |
| 2415 | |
| 2416 | //wait("DrawTriangle"); |
| 2417 | } |
| 2418 | |
| 2419 | /*****************************************************************************/ |
| 2420 | |
| 2421 | //////////////////////// |
| 2422 | // FB ACCESSORS |
| 2423 | //////////////////////// |
| 2424 | void n64_rdp::_Write16Bit_Cvg0_Blend(UINT32 curpixel, UINT32 r, UINT32 g, UINT32 b, rdp_span_aux *userdata, const rdp_poly_state &object) |
| 2425 | { |
| 2426 | UINT32 fb = (object.MiscState.FBAddress >> 1) + curpixel; |
| 2427 | UINT32 hb = fb; |
| 2428 | |
| 2429 | UINT16 finalcolor = ((r >> 3) << 11) | ((g >> 3) << 6) | ((b >> 3) << 1); |
| 2430 | UINT32 finalcvg = 0; |
| 2431 | |
| 2432 | if (object.OtherModes.color_on_cvg && !userdata->PreWrap) |
| 2433 | { |
| 2434 | finalcolor = RREADIDX16(fb) & 0xfffe; |
| 2435 | CHECK16(fb); |
| 2436 | } |
| 2437 | |
| 2438 | finalcvg = userdata->CurrentPixCvg + userdata->CurrentMemCvg; |
| 2439 | if (finalcvg & 8) |
| 2440 | { |
| 2441 | finalcvg = 7; |
| 2442 | } |
| 2443 | RWRITEIDX16(fb, finalcolor | ((finalcvg >> 2) & 1)); |
| 2444 | HWRITEADDR8(hb, finalcvg & 3); |
| 2445 | } |
| 2446 | |
| 2447 | void n64_rdp::_Write16Bit_Cvg0_NoBlend(UINT32 curpixel, UINT32 r, UINT32 g, UINT32 b, rdp_span_aux *userdata, const rdp_poly_state &object) |
| 2448 | { |
| 2449 | UINT32 fb = (object.MiscState.FBAddress >> 1) + curpixel; |
| 2450 | UINT32 hb = fb; |
| 2451 | |
| 2452 | UINT16 finalcolor = ((r >> 3) << 11) | ((g >> 3) << 6) | ((b >> 3) << 1); |
| 2453 | UINT32 finalcvg = 0; |
| 2454 | |
| 2455 | if (object.OtherModes.color_on_cvg && !userdata->PreWrap) |
| 2456 | { |
| 2457 | finalcolor = RREADIDX16(fb) & 0xfffe; |
| 2458 | CHECK16(fb); |
| 2459 | } |
| 2460 | |
| 2461 | finalcvg = (userdata->CurrentPixCvg - 1) & 7; |
| 2462 | RWRITEIDX16(fb, finalcolor | ((finalcvg >> 2) & 1)); |
| 2463 | HWRITEADDR8(hb, finalcvg & 3); |
| 2464 | } |
| 2465 | |
| 2466 | void n64_rdp::_Write16Bit_Cvg1(UINT32 curpixel, UINT32 r, UINT32 g, UINT32 b, rdp_span_aux *userdata, const rdp_poly_state &object) |
| 2467 | { |
| 2468 | UINT32 fb = (object.MiscState.FBAddress >> 1) + curpixel; |
| 2469 | UINT32 hb = fb; |
| 2470 | |
| 2471 | UINT16 finalcolor = ((r >> 3) << 11) | ((g >> 3) << 6) | ((b >> 3) << 1); |
| 2472 | UINT32 finalcvg = 0; |
| 2473 | |
| 2474 | if (object.OtherModes.color_on_cvg && !userdata->PreWrap) |
| 2475 | { |
| 2476 | finalcolor = RREADIDX16(fb) & 0xfffe; |
| 2477 | CHECK16(fb); |
| 2478 | } |
| 2479 | |
| 2480 | finalcvg = (userdata->CurrentPixCvg + userdata->CurrentMemCvg) & 7; |
| 2481 | RWRITEIDX16(fb, finalcolor | ((finalcvg >> 2) & 1)); |
| 2482 | HWRITEADDR8(hb, finalcvg & 3); |
| 2483 | } |
| 2484 | |
| 2485 | void n64_rdp::_Write16Bit_Cvg2(UINT32 curpixel, UINT32 r, UINT32 g, UINT32 b, rdp_span_aux *userdata, const rdp_poly_state &object) |
| 2486 | { |
| 2487 | UINT32 fb = (object.MiscState.FBAddress >> 1) + curpixel; |
| 2488 | UINT32 hb = fb; |
| 2489 | |
| 2490 | UINT16 finalcolor = ((r >> 3) << 11) | ((g >> 3) << 6) | ((b >> 3) << 1); |
| 2491 | |
| 2492 | if (object.OtherModes.color_on_cvg && !userdata->PreWrap) |
| 2493 | { |
| 2494 | finalcolor = RREADIDX16(fb) & 0xfffe; |
| 2495 | CHECK16(fb); |
| 2496 | } |
| 2497 | |
| 2498 | RWRITEIDX16(fb, finalcolor | 1); |
| 2499 | HWRITEADDR8(hb, 3); |
| 2500 | } |
| 2501 | |
| 2502 | void n64_rdp::_Write16Bit_Cvg3(UINT32 curpixel, UINT32 r, UINT32 g, UINT32 b, rdp_span_aux *userdata, const rdp_poly_state &object) |
| 2503 | { |
| 2504 | UINT32 fb = (object.MiscState.FBAddress >> 1) + curpixel; |
| 2505 | UINT32 hb = fb; |
| 2506 | |
| 2507 | UINT16 finalcolor = ((r >> 3) << 11) | ((g >> 3) << 6) | ((b >> 3) << 1); |
| 2508 | |
| 2509 | if (object.OtherModes.color_on_cvg && !userdata->PreWrap) |
| 2510 | { |
| 2511 | finalcolor = RREADIDX16(fb) & 0xfffe; |
| 2512 | CHECK16(fb); |
| 2513 | } |
| 2514 | |
| 2515 | RWRITEIDX16(fb, finalcolor | ((userdata->CurrentMemCvg >> 2) & 1)); |
| 2516 | HWRITEADDR8(hb, userdata->CurrentMemCvg & 3); |
| 2517 | } |
| 2518 | |
| 2519 | void n64_rdp::_Write32Bit_Cvg0_Blend(UINT32 curpixel, UINT32 r, UINT32 g, UINT32 b, rdp_span_aux *userdata, const rdp_poly_state &object) |
| 2520 | { |
| 2521 | UINT32 fb = (object.MiscState.FBAddress >> 2) + curpixel; |
| 2522 | UINT32 finalcolor = (r << 24) | (g << 16) | (b << 8);//cvg as 3 MSBs of alpha channel; |
| 2523 | UINT32 finalcvg = 0; |
| 2524 | |
| 2525 | if (object.OtherModes.color_on_cvg && !userdata->PreWrap) |
| 2526 | { |
| 2527 | finalcolor = RREADIDX32(fb) & 0xffffff00; |
| 2528 | CHECK32(fb); |
| 2529 | } |
| 2530 | |
| 2531 | finalcvg = userdata->CurrentPixCvg + userdata->CurrentMemCvg; |
| 2532 | if (finalcvg & 8) |
| 2533 | { |
| 2534 | finalcvg = 7; |
| 2535 | } |
| 2536 | RWRITEIDX32(fb, finalcolor | (finalcvg << 5)); |
| 2537 | } |
| 2538 | |
| 2539 | void n64_rdp::_Write32Bit_Cvg0_NoBlend(UINT32 curpixel, UINT32 r, UINT32 g, UINT32 b, rdp_span_aux *userdata, const rdp_poly_state &object) |
| 2540 | { |
| 2541 | UINT32 fb = (object.MiscState.FBAddress >> 2) + curpixel; |
| 2542 | UINT32 finalcolor = (r << 24) | (g << 16) | (b << 8);//cvg as 3 MSBs of alpha channel; |
| 2543 | UINT32 finalcvg = 0; |
| 2544 | |
| 2545 | if (object.OtherModes.color_on_cvg && !userdata->PreWrap) |
| 2546 | { |
| 2547 | finalcolor = RREADIDX32(fb) & 0xffffff00; |
| 2548 | CHECK32(fb); |
| 2549 | } |
| 2550 | |
| 2551 | finalcvg = (userdata->CurrentPixCvg - 1) & 7; |
| 2552 | RWRITEIDX32(fb, finalcolor | (finalcvg << 5)); |
| 2553 | } |
| 2554 | |
| 2555 | void n64_rdp::_Write32Bit_Cvg1(UINT32 curpixel, UINT32 r, UINT32 g, UINT32 b, rdp_span_aux *userdata, const rdp_poly_state &object) |
| 2556 | { |
| 2557 | UINT32 fb = (object.MiscState.FBAddress >> 2) + curpixel; |
| 2558 | UINT32 finalcolor = (r << 24) | (g << 16) | (b << 8);//cvg as 3 MSBs of alpha channel; |
| 2559 | UINT32 finalcvg = 0; |
| 2560 | |
| 2561 | if (object.OtherModes.color_on_cvg && !userdata->PreWrap) |
| 2562 | { |
| 2563 | finalcolor = RREADIDX32(fb) & 0xffffff00; |
| 2564 | CHECK32(fb); |
| 2565 | } |
| 2566 | |
| 2567 | finalcvg = (userdata->CurrentPixCvg + userdata->CurrentMemCvg) & 7; |
| 2568 | finalcolor |= (finalcvg << 5); |
| 2569 | RWRITEIDX32(fb, finalcolor); |
| 2570 | } |
| 2571 | |
| 2572 | void n64_rdp::_Write32Bit_Cvg2(UINT32 curpixel, UINT32 r, UINT32 g, UINT32 b, rdp_span_aux *userdata, const rdp_poly_state &object) |
| 2573 | { |
| 2574 | UINT32 fb = (object.MiscState.FBAddress >> 2) + curpixel; |
| 2575 | UINT32 finalcolor = (r << 24) | (g << 16) | (b << 8);//cvg as 3 MSBs of alpha channel; |
| 2576 | |
| 2577 | if (object.OtherModes.color_on_cvg && !userdata->PreWrap) |
| 2578 | { |
| 2579 | finalcolor = RREADIDX32(fb) & 0xffffff00; |
| 2580 | CHECK32(fb); |
| 2581 | } |
| 2582 | |
| 2583 | RWRITEIDX32(fb, finalcolor | 0xE0); |
| 2584 | } |
| 2585 | |
| 2586 | void n64_rdp::_Write32Bit_Cvg3(UINT32 curpixel, UINT32 r, UINT32 g, UINT32 b, rdp_span_aux *userdata, const rdp_poly_state &object) |
| 2587 | { |
| 2588 | UINT32 fb = (object.MiscState.FBAddress >> 2) + curpixel; |
| 2589 | UINT32 finalcolor = (r << 24) | (g << 16) | (b << 8);//cvg as 3 MSBs of alpha channel; |
| 2590 | |
| 2591 | if (object.OtherModes.color_on_cvg && !userdata->PreWrap) |
| 2592 | { |
| 2593 | finalcolor = RREADIDX32(fb) & 0xffffff00; |
| 2594 | CHECK32(fb); |
| 2595 | } |
| 2596 | |
| 2597 | RWRITEIDX32(fb, finalcolor | (userdata->CurrentMemCvg << 5)); |
| 2598 | } |
| 2599 | |
| 2600 | |
| 2601 | void n64_rdp::_Read16Bit_ImgRead0(UINT32 curpixel, rdp_span_aux *userdata, const rdp_poly_state &object) |
| 2602 | { |
| 2603 | UINT16 fword = RREADIDX16((object.MiscState.FBAddress >> 1) + curpixel); |
| 2604 | CHECK16((object.MiscState.FBAddress >> 1) + curpixel); |
| 2605 | userdata->MemoryColor.i.r = GETHICOL(fword); |
| 2606 | userdata->MemoryColor.i.g = GETMEDCOL(fword); |
| 2607 | userdata->MemoryColor.i.b = GETLOWCOL(fword); |
| 2608 | userdata->MemoryColor.i.a = 0xff; |
| 2609 | userdata->CurrentMemCvg = 7; |
| 2610 | } |
| 2611 | |
| 2612 | void n64_rdp::_Read16Bit_ImgRead1(UINT32 curpixel, rdp_span_aux *userdata, const rdp_poly_state &object) |
| 2613 | { |
| 2614 | UINT16 fword = RREADIDX16((object.MiscState.FBAddress >> 1) + curpixel); |
| 2615 | CHECK16((object.MiscState.FBAddress >> 1) + curpixel); |
| 2616 | UINT8 hbyte = HREADADDR8((object.MiscState.FBAddress >> 1) + curpixel); |
| 2617 | userdata->MemoryColor.i.r = GETHICOL(fword); |
| 2618 | userdata->MemoryColor.i.g = GETMEDCOL(fword); |
| 2619 | userdata->MemoryColor.i.b = GETLOWCOL(fword); |
| 2620 | userdata->MemoryColor.i.a = userdata->CurrentMemCvg << 5; |
| 2621 | userdata->CurrentMemCvg = ((fword & 1) << 2) | (hbyte & 3); |
| 2622 | } |
| 2623 | |
| 2624 | void n64_rdp::_Read32Bit_ImgRead0(UINT32 curpixel, rdp_span_aux *userdata, const rdp_poly_state &object) |
| 2625 | { |
| 2626 | UINT32 mem = RREADIDX32((object.MiscState.FBAddress >> 2) + curpixel); |
| 2627 | CHECK32((object.MiscState.FBAddress >> 2) + curpixel); |
| 2628 | userdata->MemoryColor.i.r = (mem >> 24) & 0xff; |
| 2629 | userdata->MemoryColor.i.g = (mem >> 16) & 0xff; |
| 2630 | userdata->MemoryColor.i.b = (mem >> 8) & 0xff; |
| 2631 | userdata->MemoryColor.i.a = 0xff; |
| 2632 | userdata->CurrentMemCvg = 7; |
| 2633 | } |
| 2634 | |
| 2635 | void n64_rdp::_Read32Bit_ImgRead1(UINT32 curpixel, rdp_span_aux *userdata, const rdp_poly_state &object) |
| 2636 | { |
| 2637 | UINT32 mem = RREADIDX32((object.MiscState.FBAddress >> 2) + curpixel); |
| 2638 | CHECK32((object.MiscState.FBAddress >> 2) + curpixel); |
| 2639 | userdata->MemoryColor.i.r = (mem >> 24) & 0xff; |
| 2640 | userdata->MemoryColor.i.g = (mem >> 16) & 0xff; |
| 2641 | userdata->MemoryColor.i.b = (mem >> 8) & 0xff; |
| 2642 | userdata->MemoryColor.i.a = (mem) & 0xff; |
| 2643 | userdata->CurrentMemCvg = (mem >> 5) & 7; |
| 2644 | } |
| 2645 | |
| 2646 | void n64_rdp::_Copy16Bit(UINT32 curpixel, UINT32 r, UINT32 g, UINT32 b, int CurrentPixCvg, const rdp_poly_state &object) |
| 2647 | { |
| 2648 | UINT16 val = ((r >> 3) << 11) | ((g >> 3) << 6) | ((b >> 3) << 1) | ((CurrentPixCvg >> 2) & 1); |
| 2649 | RWRITEIDX16((object.MiscState.FBAddress >> 1) + curpixel, val); |
| 2650 | HWRITEADDR8((object.MiscState.FBAddress >> 1) + curpixel, CurrentPixCvg & 3); |
| 2651 | CHECK16((object.MiscState.FBAddress >> 1) + curpixel); |
| 2652 | } |
| 2653 | |
| 2654 | void n64_rdp::_Copy32Bit(UINT32 curpixel, UINT32 r, UINT32 g, UINT32 b, int CurrentPixCvg, const rdp_poly_state &object) |
| 2655 | { |
| 2656 | UINT32 val = (r << 24) | (g << 16) | (b << 8) | (CurrentPixCvg << 5); |
| 2657 | RWRITEIDX32((object.MiscState.FBAddress >> 2) + curpixel, val); |
| 2658 | CHECK32((object.MiscState.FBAddress >> 2) + curpixel); |
| 2659 | } |
| 2660 | |
| 2661 | |
| 2662 | void n64_rdp::_Fill16Bit(UINT32 curpixel, const rdp_poly_state &object) |
| 2663 | { |
| 2664 | UINT16 val; |
| 2665 | if (curpixel & 1) |
| 2666 | { |
| 2667 | val = object.FillColor & 0xffff; |
| 2668 | } |
| 2669 | else |
| 2670 | { |
| 2671 | val = (object.FillColor >> 16) & 0xffff; |
| 2672 | } |
| 2673 | RWRITEIDX16((object.MiscState.FBAddress >> 1) + curpixel, val); |
| 2674 | CHECK16((object.MiscState.FBAddress >> 1) + curpixel); |
| 2675 | HWRITEADDR8((object.MiscState.FBAddress >> 1) + curpixel, ((val & 1) << 1) | (val & 1)); |
| 2676 | } |
| 2677 | |
| 2678 | void n64_rdp::_Fill32Bit(UINT32 curpixel, const rdp_poly_state &object) |
| 2679 | { |
| 2680 | UINT32 FillColor = object.FillColor; |
| 2681 | RWRITEIDX32((object.MiscState.FBAddress >> 2) + curpixel, FillColor); |
| 2682 | CHECK32((object.MiscState.FBAddress >> 2) + curpixel); |
| 2683 | HWRITEADDR8((object.MiscState.FBAddress >> 1) + (curpixel << 1), (FillColor & 0x10000) ? 3 : 0); |
| 2684 | HWRITEADDR8((object.MiscState.FBAddress >> 1) + (curpixel << 1) + 1, (FillColor & 0x1) ? 3 : 0); |
| 2685 | } |
| 2686 | |
| 2687 | //////////////////////// |
| 2688 | // RDP COMMANDS |
| 2689 | //////////////////////// |
| 2690 | void n64_rdp::Triangle(bool shade, bool texture, bool zbuffer) |
| 2691 | { |
| 2692 | DrawTriangle(shade, texture, zbuffer, false); |
| 2693 | m_pipe_clean = false; |
| 2694 | //wait(); |
| 2695 | } |
| 2696 | |
| 2697 | void n64_rdp::CmdTriangle(UINT32 w1, UINT32 w2) |
| 2698 | { |
| 2699 | Triangle(false, false, false); |
| 2700 | } |
| 2701 | |
| 2702 | void n64_rdp::CmdTriangleZ(UINT32 w1, UINT32 w2) |
| 2703 | { |
| 2704 | Triangle(false, false, true); |
| 2705 | } |
| 2706 | |
| 2707 | void n64_rdp::CmdTriangleT(UINT32 w1, UINT32 w2) |
| 2708 | { |
| 2709 | Triangle(false, true, false); |
| 2710 | } |
| 2711 | |
| 2712 | void n64_rdp::CmdTriangleTZ(UINT32 w1, UINT32 w2) |
| 2713 | { |
| 2714 | Triangle(false, true, true); |
| 2715 | } |
| 2716 | |
| 2717 | void n64_rdp::CmdTriangleS(UINT32 w1, UINT32 w2) |
| 2718 | { |
| 2719 | Triangle(true, false, false); |
| 2720 | } |
| 2721 | |
| 2722 | void n64_rdp::CmdTriangleSZ(UINT32 w1, UINT32 w2) |
| 2723 | { |
| 2724 | Triangle(true, false, true); |
| 2725 | } |
| 2726 | |
| 2727 | void n64_rdp::CmdTriangleST(UINT32 w1, UINT32 w2) |
| 2728 | { |
| 2729 | Triangle(true, true, false); |
| 2730 | } |
| 2731 | |
| 2732 | void n64_rdp::CmdTriangleSTZ(UINT32 w1, UINT32 w2) |
| 2733 | { |
| 2734 | Triangle(true, true, true); |
| 2735 | } |
| 2736 | |
| 2737 | void n64_rdp::CmdTexRect(UINT32 w1, UINT32 w2) |
| 2738 | { |
| 2739 | //if(m_pending_mode_block) { wait("Block on pending mode-change"); m_pending_mode_block = false; } |
| 2740 | |
| 2741 | UINT32 *data = m_cmd_data + m_cmd_cur; |
| 2742 | |
| 2743 | UINT32 w3 = data[2]; |
| 2744 | UINT32 w4 = data[3]; |
| 2745 | |
| 2746 | UINT32 tilenum = (w2 >> 24) & 0x7; |
| 2747 | UINT32 xl = (w1 >> 12) & 0xfff; |
| 2748 | UINT32 yl = (w1 >> 0) & 0xfff; |
| 2749 | UINT32 xh = (w2 >> 12) & 0xfff; |
| 2750 | UINT32 yh = (w2 >> 0) & 0xfff; |
| 2751 | INT32 s = (w3 >> 16) & 0xffff; |
| 2752 | INT32 t = (w3 >> 0) & 0xffff; |
| 2753 | INT32 dsdx = (w4 >> 16) & 0xffff; |
| 2754 | INT32 dtdy = (w4 >> 0) & 0xffff; |
| 2755 | |
| 2756 | dsdx = SIGN16(dsdx); |
| 2757 | dtdy = SIGN16(dtdy); |
| 2758 | |
| 2759 | if (OtherModes.cycle_type == CYCLE_TYPE_FILL || OtherModes.cycle_type == CYCLE_TYPE_COPY) |
| 2760 | { |
| 2761 | yl |= 3; |
| 2762 | } |
| 2763 | |
| 2764 | UINT32 xlint = (xl >> 2) & 0x3ff; |
| 2765 | UINT32 xhint = (xh >> 2) & 0x3ff; |
| 2766 | |
| 2767 | UINT32* ewdata = m_temp_rect_data; |
| 2768 | ewdata[0] = (0x24 << 24) | ((0x80 | tilenum) << 16) | yl; // command, flipped, tile, yl |
| 2769 | ewdata[1] = (yl << 16) | yh; // ym, yh |
| 2770 | ewdata[2] = (xlint << 16) | ((xl & 3) << 14); // xl, xl frac |
| 2771 | ewdata[3] = 0; // dxldy, dxldy frac |
| 2772 | ewdata[4] = (xhint << 16) | ((xh & 3) << 14); // xh, xh frac |
| 2773 | ewdata[5] = 0; // dxhdy, dxhdy frac |
| 2774 | ewdata[6] = (xlint << 16) | ((xl & 3) << 14); // xm, xm frac |
| 2775 | ewdata[7] = 0; // dxmdy, dxmdy frac |
| 2776 | memset(&ewdata[8], 0, 16 * sizeof(UINT32)); // shade |
| 2777 | ewdata[24] = (s << 16) | t; // s, t |
| 2778 | ewdata[25] = 0; // w |
| 2779 | ewdata[26] = ((dsdx >> 5) << 16); // dsdx, dtdx |
| 2780 | ewdata[27] = 0; // dwdx |
| 2781 | ewdata[28] = 0; // s frac, t frac |
| 2782 | ewdata[29] = 0; // w frac |
| 2783 | ewdata[30] = ((dsdx & 0x1f) << 11) << 16; // dsdx frac, dtdx frac |
| 2784 | ewdata[31] = 0; // dwdx frac |
| 2785 | ewdata[32] = (dtdy >> 5) & 0xffff;//dsde, dtde |
| 2786 | ewdata[33] = 0;//dwde |
| 2787 | ewdata[34] = (dtdy >> 5) & 0xffff;//dsdy, dtdy |
| 2788 | ewdata[35] = 0;//dwdy |
| 2789 | ewdata[36] = (dtdy & 0x1f) << 11;//dsde frac, dtde frac |
| 2790 | ewdata[37] = 0;//dwde frac |
| 2791 | ewdata[38] = (dtdy & 0x1f) << 11;//dsdy frac, dtdy frac |
| 2792 | ewdata[39] = 0;//dwdy frac |
| 2793 | memset(&ewdata[40], 0, 4 * sizeof(UINT32));//depth |
| 2794 | |
| 2795 | DrawTriangle(true, true, false, true); |
| 2796 | } |
| 2797 | |
| 2798 | void n64_rdp::CmdTexRectFlip(UINT32 w1, UINT32 w2) |
| 2799 | { |
| 2800 | //if(m_pending_mode_block) { wait("Block on pending mode-change"); m_pending_mode_block = false; } |
| 2801 | |
| 2802 | UINT32 *data = m_cmd_data + m_cmd_cur; |
| 2803 | |
| 2804 | UINT32 w3 = data[2]; |
| 2805 | UINT32 w4 = data[3]; |
| 2806 | |
| 2807 | UINT32 tilenum = (w2 >> 24) & 0x7; |
| 2808 | UINT32 xl = (w1 >> 12) & 0xfff; |
| 2809 | UINT32 yl = (w1 >> 0) & 0xfff; |
| 2810 | UINT32 xh = (w2 >> 12) & 0xfff; |
| 2811 | UINT32 yh = (w2 >> 0) & 0xfff; |
| 2812 | INT32 s = (w3 >> 16) & 0xffff; |
| 2813 | INT32 t = (w3 >> 0) & 0xffff; |
| 2814 | INT32 dsdx = (w4 >> 16) & 0xffff; |
| 2815 | INT32 dtdy = (w4 >> 0) & 0xffff; |
| 2816 | |
| 2817 | dsdx = SIGN16(dsdx); |
| 2818 | dtdy = SIGN16(dtdy); |
| 2819 | |
| 2820 | if (OtherModes.cycle_type == CYCLE_TYPE_FILL || OtherModes.cycle_type == CYCLE_TYPE_COPY) |
| 2821 | { |
| 2822 | yl |= 3; |
| 2823 | } |
| 2824 | |
| 2825 | UINT32 xlint = (xl >> 2) & 0x3ff; |
| 2826 | UINT32 xhint = (xh >> 2) & 0x3ff; |
| 2827 | |
| 2828 | UINT32* ewdata = m_temp_rect_data; |
| 2829 | ewdata[0] = (0x25 << 24) | ((0x80 | tilenum) << 16) | yl;//command, flipped, tile, yl |
| 2830 | ewdata[1] = (yl << 16) | yh;//ym, yh |
| 2831 | ewdata[2] = (xlint << 16) | ((xl & 3) << 14);//xl, xl frac |
| 2832 | ewdata[3] = 0;//dxldy, dxldy frac |
| 2833 | ewdata[4] = (xhint << 16) | ((xh & 3) << 14);//xh, xh frac |
| 2834 | ewdata[5] = 0;//dxhdy, dxhdy frac |
| 2835 | ewdata[6] = (xlint << 16) | ((xl & 3) << 14);//xm, xm frac |
| 2836 | ewdata[7] = 0;//dxmdy, dxmdy frac |
| 2837 | memset(&ewdata[8], 0, 16 * sizeof(UINT32));//shade |
| 2838 | ewdata[24] = (s << 16) | t;//s, t |
| 2839 | ewdata[25] = 0;//w |
| 2840 | ewdata[26] = (dtdy >> 5) & 0xffff;//dsdx, dtdx |
| 2841 | ewdata[27] = 0;//dwdx |
| 2842 | ewdata[28] = 0;//s frac, t frac |
| 2843 | ewdata[29] = 0;//w frac |
| 2844 | ewdata[30] = ((dtdy & 0x1f) << 11);//dsdx frac, dtdx frac |
| 2845 | ewdata[31] = 0;//dwdx frac |
| 2846 | ewdata[32] = (dsdx >> 5) << 16;//dsde, dtde |
| 2847 | ewdata[33] = 0;//dwde |
| 2848 | ewdata[34] = (dsdx >> 5) << 16;//dsdy, dtdy |
| 2849 | ewdata[35] = 0;//dwdy |
| 2850 | ewdata[36] = (dsdx & 0x1f) << 27;//dsde frac, dtde frac |
| 2851 | ewdata[37] = 0;//dwde frac |
| 2852 | ewdata[38] = (dsdx & 0x1f) << 27;//dsdy frac, dtdy frac |
| 2853 | ewdata[39] = 0;//dwdy frac |
| 2854 | memset(&ewdata[40], 0, 4 * sizeof(UINT32));//depth |
| 2855 | |
| 2856 | DrawTriangle(true, true, false, true); |
| 2857 | } |
| 2858 | |
| 2859 | void n64_rdp::CmdSyncLoad(UINT32 w1, UINT32 w2) |
| 2860 | { |
| 2861 | //wait("SyncLoad"); |
| 2862 | } |
| 2863 | |
| 2864 | void n64_rdp::CmdSyncPipe(UINT32 w1, UINT32 w2) |
| 2865 | { |
| 2866 | //wait("SyncPipe"); |
| 2867 | } |
| 2868 | |
| 2869 | void n64_rdp::CmdSyncTile(UINT32 w1, UINT32 w2) |
| 2870 | { |
| 2871 | //wait("SyncTile"); |
| 2872 | } |
| 2873 | |
| 2874 | void n64_rdp::CmdSyncFull(UINT32 w1, UINT32 w2) |
| 2875 | { |
| 2876 | //wait("SyncFull"); |
| 2877 | dp_full_sync(*m_machine); |
| 2878 | } |
| 2879 | |
| 2880 | void n64_rdp::CmdSetKeyGB(UINT32 w1, UINT32 w2) |
| 2881 | { |
| 2882 | KeyScale.i.b = w2 & 0xff; |
| 2883 | KeyScale.i.g = (w2 >> 16) & 0xff; |
| 2884 | } |
| 2885 | |
| 2886 | void n64_rdp::CmdSetKeyR(UINT32 w1, UINT32 w2) |
| 2887 | { |
| 2888 | KeyScale.i.r = w2 & 0xff; |
| 2889 | } |
| 2890 | |
| 2891 | void n64_rdp::CmdSetFillColor32(UINT32 w1, UINT32 w2) |
| 2892 | { |
| 2893 | //wait("SetFillColor"); |
| 2894 | FillColor = w2; |
| 2895 | } |
| 2896 | |
| 2897 | void n64_rdp::CmdSetConvert(UINT32 w1, UINT32 w2) |
| 2898 | { |
| 2899 | if(!m_pipe_clean) { m_pipe_clean = true; wait("SetConvert"); } |
| 2900 | INT32 k0 = (w1 >> 13) & 0xff; |
| 2901 | INT32 k1 = (w1 >> 4) & 0xff; |
| 2902 | INT32 k2 = ((w1 & 7) << 5) | ((w2 >> 27) & 0x1f); |
| 2903 | INT32 k3 = (w2 >> 18) & 0xff; |
| 2904 | INT32 k4 = (w2 >> 9) & 0xff; |
| 2905 | INT32 k5 = w2 & 0xff; |
| 2906 | k0 = ((w1 >> 21) & 1) ? (-(0x100 - k0)) : k0; |
| 2907 | k1 = ((w1 >> 12) & 1) ? (-(0x100 - k1)) : k1; |
| 2908 | k2 = (w1 & 0xf) ? (-(0x100 - k2)) : k2; |
| 2909 | k3 = ((w2 >> 26) & 1) ? (-(0x100 - k3)) : k3; |
| 2910 | k4 = ((w2 >> 17) & 1) ? (-(0x100 - k4)) : k4; |
| 2911 | k5 = ((w2 >> 8) & 1) ? (-(0x100 - k5)) : k5; |
| 2912 | SetYUVFactors(k0, k1, k2, k3, k4, k5); |
| 2913 | } |
| 2914 | |
| 2915 | void n64_rdp::CmdSetScissor(UINT32 w1, UINT32 w2) |
| 2916 | { |
| 2917 | Scissor.m_xh = ((w1 >> 12) & 0xfff) >> 2; |
| 2918 | Scissor.m_yh = ((w1 >> 0) & 0xfff) >> 2; |
| 2919 | Scissor.m_xl = ((w2 >> 12) & 0xfff) >> 2; |
| 2920 | Scissor.m_yl = ((w2 >> 0) & 0xfff) >> 2; |
| 2921 | |
| 2922 | // TODO: handle f & o? |
| 2923 | } |
| 2924 | |
| 2925 | void n64_rdp::CmdSetPrimDepth(UINT32 w1, UINT32 w2) |
| 2926 | { |
| 2927 | MiscState.PrimitiveZ = (UINT16)(w2 >> 16) & 0x7fff; |
| 2928 | MiscState.PrimitiveDZ = (UINT16)(w1); |
| 2929 | } |
| 2930 | |
| 2931 | void n64_rdp::CmdSetOtherModes(UINT32 w1, UINT32 w2) |
| 2932 | { |
| 2933 | //wait("SetOtherModes"); |
| 2934 | OtherModes.cycle_type = (w1 >> 20) & 0x3; // 01 |
| 2935 | OtherModes.persp_tex_en = (w1 & 0x80000) ? 1 : 0; // 1 |
| 2936 | OtherModes.detail_tex_en = (w1 & 0x40000) ? 1 : 0; // 0 |
| 2937 | OtherModes.sharpen_tex_en = (w1 & 0x20000) ? 1 : 0; // 0 |
| 2938 | OtherModes.tex_lod_en = (w1 & 0x10000) ? 1 : 0; // 0 |
| 2939 | OtherModes.en_tlut = (w1 & 0x08000) ? 1 : 0; // 0 |
| 2940 | OtherModes.tlut_type = (w1 & 0x04000) ? 1 : 0; // 0 |
| 2941 | OtherModes.sample_type = (w1 & 0x02000) ? 1 : 0; // 1 |
| 2942 | OtherModes.mid_texel = (w1 & 0x01000) ? 1 : 0; // 0 |
| 2943 | OtherModes.bi_lerp0 = (w1 & 0x00800) ? 1 : 0; // 1 |
| 2944 | OtherModes.bi_lerp1 = (w1 & 0x00400) ? 1 : 0; // 1 |
| 2945 | OtherModes.convert_one = (w1 & 0x00200) ? 1 : 0; // 0 |
| 2946 | OtherModes.key_en = (w1 & 0x00100) ? 1 : 0; // 0 |
| 2947 | OtherModes.rgb_dither_sel = (w1 >> 6) & 0x3; // 00 |
| 2948 | OtherModes.alpha_dither_sel = (w1 >> 4) & 0x3; // 01 |
| 2949 | OtherModes.blend_m1a_0 = (w2 >> 30) & 0x3; // 11 |
| 2950 | OtherModes.blend_m1a_1 = (w2 >> 28) & 0x3; // 00 |
| 2951 | OtherModes.blend_m1b_0 = (w2 >> 26) & 0x3; // 10 |
| 2952 | OtherModes.blend_m1b_1 = (w2 >> 24) & 0x3; // 00 |
| 2953 | OtherModes.blend_m2a_0 = (w2 >> 22) & 0x3; // 00 |
| 2954 | OtherModes.blend_m2a_1 = (w2 >> 20) & 0x3; // 01 |
| 2955 | OtherModes.blend_m2b_0 = (w2 >> 18) & 0x3; // 00 |
| 2956 | OtherModes.blend_m2b_1 = (w2 >> 16) & 0x3; // 01 |
| 2957 | OtherModes.force_blend = (w2 >> 14) & 1; // 0 |
| 2958 | OtherModes.alpha_cvg_select = (w2 >> 13) & 1; // 1 |
| 2959 | OtherModes.cvg_times_alpha = (w2 >> 12) & 1; // 0 |
| 2960 | OtherModes.z_mode = (w2 >> 10) & 0x3; // 00 |
| 2961 | OtherModes.cvg_dest = (w2 >> 8) & 0x3; // 00 |
| 2962 | OtherModes.color_on_cvg = (w2 >> 7) & 1; // 0 |
| 2963 | OtherModes.image_read_en = (w2 >> 6) & 1; // 1 |
| 2964 | OtherModes.z_update_en = (w2 >> 5) & 1; // 1 |
| 2965 | OtherModes.z_compare_en = (w2 >> 4) & 1; // 1 |
| 2966 | OtherModes.antialias_en = (w2 >> 3) & 1; // 1 |
| 2967 | OtherModes.z_source_sel = (w2 >> 2) & 1; // 0 |
| 2968 | OtherModes.dither_alpha_en = (w2 >> 1) & 1; // 0 |
| 2969 | OtherModes.alpha_compare_en = (w2) & 1; // 0 |
| 2970 | } |
| 2971 | |
| 2972 | void n64_rdp::CmdLoadTLUT(UINT32 w1, UINT32 w2) |
| 2973 | { |
| 2974 | //wait("LoadTLUT"); |
| 2975 | N64Tile* tile = m_tiles; |
| 2976 | |
| 2977 | int tilenum = (w2 >> 24) & 0x7; |
| 2978 | int sl = tile[tilenum].sl = ((w1 >> 12) & 0xfff); |
| 2979 | int tl = tile[tilenum].tl = w1 & 0xfff; |
| 2980 | int sh = tile[tilenum].sh = ((w2 >> 12) & 0xfff); |
| 2981 | int th = tile[tilenum].th = w2 & 0xfff; |
| 2982 | |
| 2983 | if (tl != th) |
| 2984 | { |
| 2985 | fatalerror("Load tlut: tl=%d, th=%d\n",tl,th); |
| 2986 | } |
| 2987 | |
| 2988 | int count = (sh >> 2) - (sl >> 2) + 1; |
| 2989 | count <<= 2; |
| 2990 | |
| 2991 | switch (MiscState.TISize) |
| 2992 | { |
| 2993 | case PIXEL_SIZE_16BIT: |
| 2994 | { |
| 2995 | if (tile[tilenum].tmem < 256) |
| 2996 | { |
| 2997 | fatalerror("rdp_load_tlut: loading tlut into low half at %d qwords\n",tile[tilenum].tmem); |
| 2998 | } |
| 2999 | UINT32 srcstart = (MiscState.TIAddress + (tl >> 2) * (MiscState.TIWidth << 1) + (sl >> 1)) >> 1; |
| 3000 | UINT16 *dst = GetTMEM16(); |
| 3001 | UINT32 dststart = tile[tilenum].tmem << 2; |
| 3002 | |
| 3003 | for (int i = 0; i < count; i += 4) |
| 3004 | { |
| 3005 | if (dststart < 2048) |
| 3006 | { |
| 3007 | dst[dststart] = U_RREADIDX16(srcstart); |
| 3008 | dst[dststart + 1] = dst[dststart]; |
| 3009 | dst[dststart + 2] = dst[dststart]; |
| 3010 | dst[dststart + 3] = dst[dststart]; |
| 3011 | dststart += 4; |
| 3012 | srcstart += 1; |
| 3013 | } |
| 3014 | } |
| 3015 | break; |
| 3016 | } |
| 3017 | default: fatalerror("RDP: load_tlut: size = %d\n", MiscState.TISize); |
| 3018 | } |
| 3019 | } |
| 3020 | |
| 3021 | void n64_rdp::CmdSetTileSize(UINT32 w1, UINT32 w2) |
| 3022 | { |
| 3023 | //wait("SetTileSize"); |
| 3024 | |
| 3025 | const int tilenum = (w2 >> 24) & 0x7; |
| 3026 | |
| 3027 | m_tiles[tilenum].sl = (w1 >> 12) & 0xfff; |
| 3028 | m_tiles[tilenum].tl = (w1 >> 0) & 0xfff; |
| 3029 | m_tiles[tilenum].sh = (w2 >> 12) & 0xfff; |
| 3030 | m_tiles[tilenum].th = (w2 >> 0) & 0xfff; |
| 3031 | } |
| 3032 | |
| 3033 | void n64_rdp::CmdLoadBlock(UINT32 w1, UINT32 w2) |
| 3034 | { |
| 3035 | //wait("LoadBlock"); |
| 3036 | N64Tile* tile = m_tiles; |
| 3037 | |
| 3038 | int tilenum = (w2 >> 24) & 0x7; |
| 3039 | UINT16* tc = GetTMEM16(); |
| 3040 | |
| 3041 | UINT16 sl, sh, tl; |
| 3042 | tile[tilenum].sl = sl = ((w1 >> 12) & 0xfff); |
| 3043 | tile[tilenum].tl = tl = ((w1 >> 0) & 0xfff); |
| 3044 | tile[tilenum].sh = sh = ((w2 >> 12) & 0xfff); |
| 3045 | UINT16 dxt = ((w2 >> 0) & 0xfff); |
| 3046 | |
| 3047 | if (sh < sl) |
| 3048 | { |
| 3049 | fatalerror("load_block: sh < sl\n"); |
| 3050 | } |
| 3051 | |
| 3052 | INT32 width = (sh - sl) + 1; |
| 3053 | |
| 3054 | width = (width << MiscState.TISize) >> 1; |
| 3055 | if (width & 7) |
| 3056 | { |
| 3057 | width = (width & ~7) + 8; |
| 3058 | } |
| 3059 | width >>= 3; |
| 3060 | |
| 3061 | UINT32 tb = tile[tilenum].tmem << 2; |
| 3062 | |
| 3063 | int tiwinwords = MiscState.TIWidth; |
| 3064 | UINT32 slinwords = sl; |
| 3065 | |
| 3066 | tiwinwords = (tiwinwords << MiscState.TISize) >> 2; |
| 3067 | slinwords = (slinwords << MiscState.TISize) >> 2; |
| 3068 | |
| 3069 | int ptr = 0, srcptr = 0; |
| 3070 | UINT16 first, sec; |
| 3071 | UINT32 src = (MiscState.TIAddress >> 1) + (tl * tiwinwords) + slinwords; |
| 3072 | |
| 3073 | if (dxt != 0) |
| 3074 | { |
| 3075 | int j = 0; |
| 3076 | int t = 0; |
| 3077 | int oldt = 0; |
| 3078 | |
| 3079 | if (tile[tilenum].size != PIXEL_SIZE_32BIT && tile[tilenum].format != FORMAT_YUV) |
| 3080 | { |
| 3081 | for (int i = 0; i < width; i ++) |
| 3082 | { |
| 3083 | oldt = t; |
| 3084 | t = ((j >> 11) & 1) ? WORD_XOR_DWORD_SWAP : WORD_ADDR_XOR; |
| 3085 | if (t != oldt) |
| 3086 | { |
| 3087 | i += tile[tilenum].line; |
| 3088 | } |
| 3089 | |
| 3090 | ptr = tb + (i << 2); |
| 3091 | srcptr = src + (i << 2); |
| 3092 | |
| 3093 | tc[(ptr ^ t) & 0x7ff] = U_RREADIDX16(srcptr); |
| 3094 | tc[((ptr + 1) ^ t) & 0x7ff] = U_RREADIDX16(srcptr + 1); |
| 3095 | tc[((ptr + 2) ^ t) & 0x7ff] = U_RREADIDX16(srcptr + 2); |
| 3096 | tc[((ptr + 3) ^ t) & 0x7ff] = U_RREADIDX16(srcptr + 3); |
| 3097 | j += dxt; |
| 3098 | } |
| 3099 | } |
| 3100 | else if (tile[tilenum].format == FORMAT_YUV) |
| 3101 | { |
| 3102 | for (int i = 0; i < width; i ++) |
| 3103 | { |
| 3104 | oldt = t; |
| 3105 | t = ((j >> 11) & 1) ? WORD_XOR_DWORD_SWAP : WORD_ADDR_XOR; |
| 3106 | if (t != oldt) |
| 3107 | { |
| 3108 | i += tile[tilenum].line; |
| 3109 | } |
| 3110 | |
| 3111 | ptr = ((tb + (i << 1)) ^ t) & 0x3ff; |
| 3112 | srcptr = src + (i << 2); |
| 3113 | |
| 3114 | first = U_RREADIDX16(srcptr); |
| 3115 | sec = U_RREADIDX16(srcptr + 1); |
| 3116 | tc[ptr] = ((first >> 8) << 8) | (sec >> 8); |
| 3117 | tc[ptr | 0x400] = ((first & 0xff) << 8) | (sec & 0xff); |
| 3118 | |
| 3119 | ptr = ((tb + (i << 1) + 1) ^ t) & 0x3ff; |
| 3120 | first = U_RREADIDX16(srcptr + 2); |
| 3121 | sec = U_RREADIDX16(srcptr + 3); |
| 3122 | tc[ptr] = ((first >> 8) << 8) | (sec >> 8); |
| 3123 | tc[ptr | 0x400] = ((first & 0xff) << 8) | (sec & 0xff); |
| 3124 | |
| 3125 | j += dxt; |
| 3126 | } |
| 3127 | } |
| 3128 | else |
| 3129 | { |
| 3130 | for (int i = 0; i < width; i ++) |
| 3131 | { |
| 3132 | oldt = t; |
| 3133 | t = ((j >> 11) & 1) ? WORD_XOR_DWORD_SWAP : WORD_ADDR_XOR; |
| 3134 | if (t != oldt) |
| 3135 | i += tile[tilenum].line; |
| 3136 | |
| 3137 | ptr = ((tb + (i << 1)) ^ t) & 0x3ff; |
| 3138 | srcptr = src + (i << 2); |
| 3139 | tc[ptr] = U_RREADIDX16(srcptr); |
| 3140 | tc[ptr | 0x400] = U_RREADIDX16(srcptr + 1); |
| 3141 | |
| 3142 | ptr = ((tb + (i << 1) + 1) ^ t) & 0x3ff; |
| 3143 | tc[ptr] = U_RREADIDX16(srcptr + 2); |
| 3144 | tc[ptr | 0x400] = U_RREADIDX16(srcptr + 3); |
| 3145 | |
| 3146 | j += dxt; |
| 3147 | } |
| 3148 | } |
| 3149 | tile[tilenum].th = tl + (j >> 11); |
| 3150 | } |
| 3151 | else |
| 3152 | { |
| 3153 | if (tile[tilenum].size != PIXEL_SIZE_32BIT && tile[tilenum].format != FORMAT_YUV) |
| 3154 | { |
| 3155 | for (int i = 0; i < width; i ++) |
| 3156 | { |
| 3157 | ptr = tb + (i << 2); |
| 3158 | srcptr = src + (i << 2); |
| 3159 | tc[(ptr ^ WORD_ADDR_XOR) & 0x7ff] = U_RREADIDX16(srcptr); |
| 3160 | tc[((ptr + 1) ^ WORD_ADDR_XOR) & 0x7ff] = U_RREADIDX16(srcptr + 1); |
| 3161 | tc[((ptr + 2) ^ WORD_ADDR_XOR) & 0x7ff] = U_RREADIDX16(srcptr + 2); |
| 3162 | tc[((ptr + 3) ^ WORD_ADDR_XOR) & 0x7ff] = U_RREADIDX16(srcptr + 3); |
| 3163 | } |
| 3164 | } |
| 3165 | else if (tile[tilenum].format == FORMAT_YUV) |
| 3166 | { |
| 3167 | for (int i = 0; i < width; i ++) |
| 3168 | { |
| 3169 | ptr = ((tb + (i << 1)) ^ WORD_ADDR_XOR) & 0x3ff; |
| 3170 | srcptr = src + (i << 2); |
| 3171 | first = U_RREADIDX16(srcptr); |
| 3172 | sec = U_RREADIDX16(srcptr + 1); |
| 3173 | tc[ptr] = ((first >> 8) << 8) | (sec >> 8);//UV pair |
| 3174 | tc[ptr | 0x400] = ((first & 0xff) << 8) | (sec & 0xff); |
| 3175 | |
| 3176 | ptr = ((tb + (i << 1) + 1) ^ WORD_ADDR_XOR) & 0x3ff; |
| 3177 | first = U_RREADIDX16(srcptr + 2); |
| 3178 | sec = U_RREADIDX16(srcptr + 3); |
| 3179 | tc[ptr] = ((first >> 8) << 8) | (sec >> 8); |
| 3180 | tc[ptr | 0x400] = ((first & 0xff) << 8) | (sec & 0xff); |
| 3181 | } |
| 3182 | } |
| 3183 | else |
| 3184 | { |
| 3185 | for (int i = 0; i < width; i ++) |
| 3186 | { |
| 3187 | ptr = ((tb + (i << 1)) ^ WORD_ADDR_XOR) & 0x3ff; |
| 3188 | srcptr = src + (i << 2); |
| 3189 | tc[ptr] = U_RREADIDX16(srcptr); |
| 3190 | tc[ptr | 0x400] = U_RREADIDX16(srcptr + 1); |
| 3191 | |
| 3192 | ptr = ((tb + (i << 1) + 1) ^ WORD_ADDR_XOR) & 0x3ff; |
| 3193 | tc[ptr] = U_RREADIDX16(srcptr + 2); |
| 3194 | tc[ptr | 0x400] = U_RREADIDX16(srcptr + 3); |
| 3195 | } |
| 3196 | } |
| 3197 | tile[tilenum].th = tl; |
| 3198 | } |
| 3199 | } |
| 3200 | |
| 3201 | void n64_rdp::CmdLoadTile(UINT32 w1, UINT32 w2) |
| 3202 | { |
| 3203 | //wait("LoadTile"); |
| 3204 | N64Tile* tile = m_tiles; |
| 3205 | int tilenum = (w2 >> 24) & 0x7; |
| 3206 | |
| 3207 | tile[tilenum].sl = ((w1 >> 12) & 0xfff); |
| 3208 | tile[tilenum].tl = ((w1 >> 0) & 0xfff); |
| 3209 | tile[tilenum].sh = ((w2 >> 12) & 0xfff); |
| 3210 | tile[tilenum].th = ((w2 >> 0) & 0xfff); |
| 3211 | |
| 3212 | UINT16 sl = tile[tilenum].sl >> 2; |
| 3213 | UINT16 tl = tile[tilenum].tl >> 2; |
| 3214 | UINT16 sh = tile[tilenum].sh >> 2; |
| 3215 | UINT16 th = tile[tilenum].th >> 2; |
| 3216 | |
| 3217 | INT32 width = (sh - sl) + 1; |
| 3218 | INT32 height = (th - tl) + 1; |
| 3219 | /* |
| 3220 | int topad; |
| 3221 | if (MiscState.TISize < 3) |
| 3222 | { |
| 3223 | topad = (width * MiscState.TISize) & 0x7; |
| 3224 | } |
| 3225 | else |
| 3226 | { |
| 3227 | topad = (width << 2) & 0x7; |
| 3228 | } |
| 3229 | topad = 0; // ???? |
| 3230 | */ |
| 3231 | switch (MiscState.TISize) |
| 3232 | { |
| 3233 | case PIXEL_SIZE_8BIT: |
| 3234 | { |
| 3235 | UINT32 src = MiscState.TIAddress; |
| 3236 | UINT8 *tc = GetTMEM(); |
| 3237 | int tb = tile[tilenum].tmem << 3; |
| 3238 | |
| 3239 | for (int j = 0; j < height; j++) |
| 3240 | { |
| 3241 | int tline = tb + ((tile[tilenum].line << 3) * j); |
| 3242 | int s = ((j + tl) * MiscState.TIWidth) + sl; |
| 3243 | |
| 3244 | int xorval8 = ((j & 1) ? BYTE_XOR_DWORD_SWAP : BYTE_ADDR_XOR); |
| 3245 | for (int i = 0; i < width; i++) |
| 3246 | { |
| 3247 | tc[((tline + i) ^ xorval8) & 0xfff] = U_RREADADDR8(src + s + i); |
| 3248 | } |
| 3249 | } |
| 3250 | break; |
| 3251 | } |
| 3252 | case PIXEL_SIZE_16BIT: |
| 3253 | { |
| 3254 | UINT32 src = MiscState.TIAddress >> 1; |
| 3255 | UINT16 *tc = GetTMEM16(); |
| 3256 | UINT16 yuvword; |
| 3257 | |
| 3258 | if (tile[tilenum].format != FORMAT_YUV) |
| 3259 | { |
| 3260 | for (int j = 0; j < height; j++) |
| 3261 | { |
| 3262 | int tb = tile[tilenum].tmem << 2; |
| 3263 | int tline = tb + ((tile[tilenum].line << 2) * j); |
| 3264 | int s = ((j + tl) * MiscState.TIWidth) + sl; |
| 3265 | int xorval16 = (j & 1) ? WORD_XOR_DWORD_SWAP : WORD_ADDR_XOR; |
| 3266 | |
| 3267 | for (int i = 0; i < width; i++) |
| 3268 | { |
| 3269 | UINT32 taddr = (tline + i) ^ xorval16; |
| 3270 | tc[taddr & 0x7ff] = U_RREADIDX16(src + s + i); |
| 3271 | } |
| 3272 | } |
| 3273 | } |
| 3274 | else |
| 3275 | { |
| 3276 | for (int j = 0; j < height; j++) |
| 3277 | { |
| 3278 | int tb = tile[tilenum].tmem << 3; |
| 3279 | int tline = tb + ((tile[tilenum].line << 3) * j); |
| 3280 | int s = ((j + tl) * MiscState.TIWidth) + sl; |
| 3281 | int xorval8 = (j & 1) ? BYTE_XOR_DWORD_SWAP : BYTE_ADDR_XOR; |
| 3282 | |
| 3283 | for (int i = 0; i < width; i++) |
| 3284 | { |
| 3285 | UINT32 taddr = ((tline + i) ^ xorval8) & 0x7ff; |
| 3286 | yuvword = U_RREADIDX16(src + s + i); |
| 3287 | GetTMEM()[taddr] = yuvword >> 8; |
| 3288 | GetTMEM()[taddr | 0x800] = yuvword & 0xff; |
| 3289 | } |
| 3290 | } |
| 3291 | } |
| 3292 | break; |
| 3293 | } |
| 3294 | case PIXEL_SIZE_32BIT: |
| 3295 | { |
| 3296 | UINT32 src = MiscState.TIAddress >> 2; |
| 3297 | UINT16 *tc16 = GetTMEM16(); |
| 3298 | int tb = (tile[tilenum].tmem << 2); |
| 3299 | |
| 3300 | for (int j = 0; j < height; j++) |
| 3301 | { |
| 3302 | int tline = tb + ((tile[tilenum].line << 2) * j); |
| 3303 | |
| 3304 | int s = ((j + tl) * MiscState.TIWidth) + sl; |
| 3305 | int xorval32cur = (j & 1) ? WORD_XOR_DWORD_SWAP : WORD_ADDR_XOR; |
| 3306 | for (int i = 0; i < width; i++) |
| 3307 | { |
| 3308 | UINT32 c = U_RREADIDX32(src + s + i); |
| 3309 | UINT32 ptr = ((tline + i) ^ xorval32cur) & 0x3ff; |
| 3310 | tc16[ptr] = c >> 16; |
| 3311 | tc16[ptr | 0x400] = c & 0xffff; |
| 3312 | } |
| 3313 | } |
| 3314 | break; |
| 3315 | } |
| 3316 | |
| 3317 | default: fatalerror("RDP: load_tile: size = %d\n", MiscState.TISize); |
| 3318 | } |
| 3319 | } |
| 3320 | |
| 3321 | void n64_rdp::CmdSetTile(UINT32 w1, UINT32 w2) |
| 3322 | { |
| 3323 | //wait("SetTile"); |
| 3324 | |
| 3325 | int tilenum = (w2 >> 24) & 0x7; |
| 3326 | N64Tile* tex_tile = &m_tiles[tilenum]; |
| 3327 | |
| 3328 | tex_tile->format = (w1 >> 21) & 0x7; |
| 3329 | tex_tile->size = (w1 >> 19) & 0x3; |
| 3330 | tex_tile->line = (w1 >> 9) & 0x1ff; |
| 3331 | tex_tile->tmem = (w1 >> 0) & 0x1ff; |
| 3332 | tex_tile->palette = (w2 >> 20) & 0xf; |
| 3333 | tex_tile->ct = (w2 >> 19) & 0x1; |
| 3334 | tex_tile->mt = (w2 >> 18) & 0x1; |
| 3335 | tex_tile->mask_t = (w2 >> 14) & 0xf; |
| 3336 | tex_tile->shift_t = (w2 >> 10) & 0xf; |
| 3337 | tex_tile->cs = (w2 >> 9) & 0x1; |
| 3338 | tex_tile->ms = (w2 >> 8) & 0x1; |
| 3339 | tex_tile->mask_s = (w2 >> 4) & 0xf; |
| 3340 | tex_tile->shift_s = (w2 >> 0) & 0xf; |
| 3341 | |
| 3342 | if (tex_tile->format == FORMAT_I && tex_tile->size > PIXEL_SIZE_8BIT) |
| 3343 | { |
| 3344 | tex_tile->format = FORMAT_RGBA; // Used by Supercross 2000 (in-game) |
| 3345 | } |
| 3346 | if (tex_tile->format == FORMAT_CI && tex_tile->size > PIXEL_SIZE_8BIT) |
| 3347 | { |
| 3348 | tex_tile->format = FORMAT_RGBA; // Used by Clay Fighter - Sculptor's Cut |
| 3349 | } |
| 3350 | |
| 3351 | if (tex_tile->format == FORMAT_RGBA && tex_tile->size < PIXEL_SIZE_16BIT) |
| 3352 | { |
| 3353 | tex_tile->format = FORMAT_CI; // Used by Exterem-G2, Madden Football 64, and Rat Attack |
| 3354 | } |
| 3355 | |
| 3356 | //m_pending_mode_block = true; |
| 3357 | } |
| 3358 | |
| 3359 | void n64_rdp::CmdFillRect(UINT32 w1, UINT32 w2) |
| 3360 | { |
| 3361 | //if(m_pending_mode_block) { wait("Block on pending mode-change"); m_pending_mode_block = false; } |
| 3362 | |
| 3363 | UINT32 xl = (w1 >> 12) & 0xfff; |
| 3364 | UINT32 yl = (w1 >> 0) & 0xfff; |
| 3365 | UINT32 xh = (w2 >> 12) & 0xfff; |
| 3366 | UINT32 yh = (w2 >> 0) & 0xfff; |
| 3367 | |
| 3368 | if (OtherModes.cycle_type == CYCLE_TYPE_FILL || OtherModes.cycle_type == CYCLE_TYPE_COPY) |
| 3369 | { |
| 3370 | yl |= 3; |
| 3371 | } |
| 3372 | |
| 3373 | UINT32 xlint = (xl >> 2) & 0x3ff; |
| 3374 | UINT32 xhint = (xh >> 2) & 0x3ff; |
| 3375 | |
| 3376 | UINT32* ewdata = m_temp_rect_data; |
| 3377 | ewdata[0] = (0x3680 << 16) | yl;//command, flipped, tile, yl |
| 3378 | ewdata[1] = (yl << 16) | yh;//ym, yh |
| 3379 | ewdata[2] = (xlint << 16) | ((xl & 3) << 14);//xl, xl frac |
| 3380 | ewdata[3] = 0;//dxldy, dxldy frac |
| 3381 | ewdata[4] = (xhint << 16) | ((xh & 3) << 14);//xh, xh frac |
| 3382 | ewdata[5] = 0;//dxhdy, dxhdy frac |
| 3383 | ewdata[6] = (xlint << 16) | ((xl & 3) << 14);//xm, xm frac |
| 3384 | ewdata[7] = 0;//dxmdy, dxmdy frac |
| 3385 | memset(&ewdata[8], 0, 36 * sizeof(UINT32));//shade, texture, depth |
| 3386 | |
| 3387 | DrawTriangle(false, false, false, true); |
| 3388 | } |
| 3389 | |
| 3390 | void n64_rdp::CmdSetFogColor(UINT32 w1, UINT32 w2) |
| 3391 | { |
| 3392 | FogColor.c = w2; |
| 3393 | } |
| 3394 | |
| 3395 | void n64_rdp::CmdSetBlendColor(UINT32 w1, UINT32 w2) |
| 3396 | { |
| 3397 | BlendColor.c = w2; |
| 3398 | } |
| 3399 | |
| 3400 | void n64_rdp::CmdSetPrimColor(UINT32 w1, UINT32 w2) |
| 3401 | { |
| 3402 | MiscState.MinLevel = (w1 >> 8) & 0x1f; |
| 3403 | PrimLODFraction = w1 & 0xff; |
| 3404 | PrimColor.c = w2; |
| 3405 | } |
| 3406 | |
| 3407 | void n64_rdp::CmdSetEnvColor(UINT32 w1, UINT32 w2) |
| 3408 | { |
| 3409 | EnvColor.c = w2; |
| 3410 | } |
| 3411 | |
| 3412 | void n64_rdp::CmdSetCombine(UINT32 w1, UINT32 w2) |
| 3413 | { |
| 3414 | m_combine.sub_a_rgb0 = (w1 >> 20) & 0xf; |
| 3415 | m_combine.mul_rgb0 = (w1 >> 15) & 0x1f; |
| 3416 | m_combine.sub_a_a0 = (w1 >> 12) & 0x7; |
| 3417 | m_combine.mul_a0 = (w1 >> 9) & 0x7; |
| 3418 | m_combine.sub_a_rgb1 = (w1 >> 5) & 0xf; |
| 3419 | m_combine.mul_rgb1 = (w1 >> 0) & 0x1f; |
| 3420 | |
| 3421 | m_combine.sub_b_rgb0 = (w2 >> 28) & 0xf; |
| 3422 | m_combine.sub_b_rgb1 = (w2 >> 24) & 0xf; |
| 3423 | m_combine.sub_a_a1 = (w2 >> 21) & 0x7; |
| 3424 | m_combine.mul_a1 = (w2 >> 18) & 0x7; |
| 3425 | m_combine.add_rgb0 = (w2 >> 15) & 0x7; |
| 3426 | m_combine.sub_b_a0 = (w2 >> 12) & 0x7; |
| 3427 | m_combine.add_a0 = (w2 >> 9) & 0x7; |
| 3428 | m_combine.add_rgb1 = (w2 >> 6) & 0x7; |
| 3429 | m_combine.sub_b_a1 = (w2 >> 3) & 0x7; |
| 3430 | m_combine.add_a1 = (w2 >> 0) & 0x7; |
| 3431 | } |
| 3432 | |
| 3433 | void n64_rdp::CmdSetTextureImage(UINT32 w1, UINT32 w2) |
| 3434 | { |
| 3435 | MiscState.TIFormat = (w1 >> 21) & 0x7; |
| 3436 | MiscState.TISize = (w1 >> 19) & 0x3; |
| 3437 | MiscState.TIWidth = (w1 & 0x3ff) + 1; |
| 3438 | MiscState.TIAddress = w2 & 0x01ffffff; |
| 3439 | } |
| 3440 | |
| 3441 | void n64_rdp::CmdSetMaskImage(UINT32 w1, UINT32 w2) |
| 3442 | { |
| 3443 | //wait("SetMaskImage"); |
| 3444 | |
| 3445 | MiscState.ZBAddress = w2 & 0x01ffffff; |
| 3446 | } |
| 3447 | |
| 3448 | void n64_rdp::CmdSetColorImage(UINT32 w1, UINT32 w2) |
| 3449 | { |
| 3450 | //wait("SetColorImage"); |
| 3451 | |
| 3452 | MiscState.FBFormat = (w1 >> 21) & 0x7; |
| 3453 | MiscState.FBSize = (w1 >> 19) & 0x3; |
| 3454 | MiscState.FBWidth = (w1 & 0x3ff) + 1; |
| 3455 | MiscState.FBAddress = w2 & 0x01ffffff; |
| 3456 | |
| 3457 | if (MiscState.FBFormat < 2 || MiscState.FBFormat > 32) // Jet Force Gemini sets the format to 4, Intensity. Protection? |
| 3458 | { |
| 3459 | MiscState.FBFormat = 2; |
| 3460 | } |
| 3461 | } |
| 3462 | |
| 3463 | UINT32 n64_rdp::AddRightCvg(UINT32 x, UINT32 k) |
| 3464 | { |
| 3465 | //#undef FULL_SUBPIXELS |
| 3466 | #define FULL_SUBPIXELS |
| 3467 | UINT32 coveredsubpixels=((x >> 14) & 3); |
| 3468 | if (!(x & 0xffff)) |
| 3469 | { |
| 3470 | return 0; |
| 3471 | } |
| 3472 | #ifdef FULL_SUBPIXELS |
| 3473 | if (!coveredsubpixels) |
| 3474 | { |
| 3475 | return 0; |
| 3476 | } |
| 3477 | if (!(k & 1)) |
| 3478 | { |
| 3479 | return (coveredsubpixels<3) ? 1 : 2; |
| 3480 | } |
| 3481 | else |
| 3482 | { |
| 3483 | return (coveredsubpixels<2) ? 0 : 1; |
| 3484 | } |
| 3485 | #endif |
| 3486 | if (!(k & 1)) |
| 3487 | { |
| 3488 | return (coveredsubpixels<2) ? 1 : 2; |
| 3489 | } |
| 3490 | else |
| 3491 | { |
| 3492 | if (coveredsubpixels<1) |
| 3493 | { |
| 3494 | return 0; |
| 3495 | } |
| 3496 | else if (coveredsubpixels<3) |
| 3497 | { |
| 3498 | return 1; |
| 3499 | } |
| 3500 | else |
| 3501 | { |
| 3502 | return 2; |
| 3503 | } |
| 3504 | } |
| 3505 | } |
| 3506 | |
| 3507 | UINT32 n64_rdp::AddLeftCvg(UINT32 x, UINT32 k) |
| 3508 | { |
| 3509 | UINT32 coveredsubpixels = 3 - ((x >> 14) & 3); |
| 3510 | if (!(x & 0xffff)) |
| 3511 | { |
| 3512 | return 2; |
| 3513 | } |
| 3514 | #ifdef FULL_SUBPIXELS |
| 3515 | if (!coveredsubpixels) |
| 3516 | { |
| 3517 | return 0; |
| 3518 | } |
| 3519 | if (!(k & 1)) |
| 3520 | { |
| 3521 | return (coveredsubpixels<2) ? 0 : 1; |
| 3522 | } |
| 3523 | else |
| 3524 | { |
| 3525 | return (coveredsubpixels<3) ? 1 : 2; |
| 3526 | } |
| 3527 | #endif |
| 3528 | if (k & 1) |
| 3529 | { |
| 3530 | return (coveredsubpixels<2) ? 1 : 2; |
| 3531 | } |
| 3532 | else |
| 3533 | { |
| 3534 | if (coveredsubpixels < 1) |
| 3535 | { |
| 3536 | return 0; |
| 3537 | } |
| 3538 | else if (coveredsubpixels < 3) |
| 3539 | { |
| 3540 | return 1; |
| 3541 | } |
| 3542 | else |
| 3543 | { |
| 3544 | return 2; |
| 3545 | } |
| 3546 | } |
| 3547 | } |
| 3548 | |
| 3549 | /*****************************************************************************/ |
| 3550 | |
| 3551 | void n64_rdp::CmdInvalid(UINT32 w1, UINT32 w2) |
| 3552 | { |
| 3553 | fatalerror("n64_rdp::Invalid: %d, %08x %08x\n", (w1 >> 24) & 0x3f, w1, w2); |
| 3554 | } |
| 3555 | |
| 3556 | void n64_rdp::CmdNoOp(UINT32 w1, UINT32 w2) |
| 3557 | { |
| 3558 | // Do nothing |
| 3559 | } |
| 3560 | |
| 3561 | |
| 3562 | void n64_rdp::ProcessList() |
| 3563 | { |
| 3564 | INT32 length = m_end - m_current; |
| 3565 | |
| 3566 | if(length < 0) |
| 3567 | { |
| 3568 | m_current = m_end; |
| 3569 | return; |
| 3570 | } |
| 3571 | |
| 3572 | // load command data |
| 3573 | for(int i = 0; i < length; i += 4) |
| 3574 | { |
| 3575 | m_cmd_data[m_cmd_ptr++] = ReadData((m_current & 0x1fffffff) + i); |
| 3576 | } |
| 3577 | |
| 3578 | m_current = m_end; |
| 3579 | |
| 3580 | UINT32 cmd = (m_cmd_data[0] >> 24) & 0x3f; |
| 3581 | UINT32 cmd_length = (m_cmd_ptr + 1) * 4; |
| 3582 | |
| 3583 | SetStatusReg(GetStatusReg() &~ DP_STATUS_FREEZE); |
| 3584 | |
| 3585 | // check if more data is needed |
| 3586 | if (cmd_length < rdp_command_length[cmd]) |
| 3587 | { |
| 3588 | return; |
| 3589 | } |
| 3590 | |
| 3591 | while (m_cmd_cur < m_cmd_ptr) |
| 3592 | { |
| 3593 | cmd = (m_cmd_data[m_cmd_cur] >> 24) & 0x3f; |
| 3594 | |
| 3595 | if (((m_cmd_ptr - m_cmd_cur) * 4) < rdp_command_length[cmd]) |
| 3596 | { |
| 3597 | return; |
| 3598 | //fatalerror("rdp_process_list: not enough rdp command data: cur = %d, ptr = %d, expected = %d\n", m_cmd_cur, m_cmd_ptr, rdp_command_length[cmd]); |
| 3599 | } |
| 3600 | |
| 3601 | if (LOG_RDP_EXECUTION) |
| 3602 | { |
| 3603 | char string[4000]; |
| 3604 | Dasm(string); |
| 3605 | |
| 3606 | fprintf(rdp_exec, "%08X: %08X %08X %s\n", m_start+(m_cmd_cur * 4), m_cmd_data[m_cmd_cur+0], m_cmd_data[m_cmd_cur+1], string); |
| 3607 | fflush(rdp_exec); |
| 3608 | } |
| 3609 | |
| 3610 | // execute the command |
| 3611 | UINT32 w1 = m_cmd_data[m_cmd_cur+0]; |
| 3612 | UINT32 w2 = m_cmd_data[m_cmd_cur+1]; |
| 3613 | |
| 3614 | switch(cmd) |
| 3615 | { |
| 3616 | case 0x00: CmdNoOp(w1, w2); break; |
| 3617 | |
| 3618 | case 0x08: CmdTriangle(w1, w2); break; |
| 3619 | case 0x09: CmdTriangleZ(w1, w2); break; |
| 3620 | case 0x0a: CmdTriangleT(w1, w2); break; |
| 3621 | case 0x0b: CmdTriangleTZ(w1, w2); break; |
| 3622 | case 0x0c: CmdTriangleS(w1, w2); break; |
| 3623 | case 0x0d: CmdTriangleSZ(w1, w2); break; |
| 3624 | case 0x0e: CmdTriangleST(w1, w2); break; |
| 3625 | case 0x0f: CmdTriangleSTZ(w1, w2); break; |
| 3626 | |
| 3627 | case 0x24: CmdTexRect(w1, w2); break; |
| 3628 | case 0x25: CmdTexRectFlip(w1, w2); break; |
| 3629 | |
| 3630 | case 0x26: CmdSyncLoad(w1, w2); break; |
| 3631 | case 0x27: CmdSyncPipe(w1, w2); break; |
| 3632 | case 0x28: CmdSyncTile(w1, w2); break; |
| 3633 | case 0x29: CmdSyncFull(w1, w2); break; |
| 3634 | |
| 3635 | case 0x2a: CmdSetKeyGB(w1, w2); break; |
| 3636 | case 0x2b: CmdSetKeyR(w1, w2); break; |
| 3637 | |
| 3638 | case 0x2c: CmdSetConvert(w1, w2); break; |
| 3639 | case 0x3c: CmdSetCombine(w1, w2); break; |
| 3640 | case 0x2d: CmdSetScissor(w1, w2); break; |
| 3641 | case 0x2e: CmdSetPrimDepth(w1, w2); break; |
| 3642 | case 0x2f: CmdSetOtherModes(w1, w2); break; |
| 3643 | |
| 3644 | case 0x30: CmdLoadTLUT(w1, w2); break; |
| 3645 | case 0x33: CmdLoadBlock(w1, w2); break; |
| 3646 | case 0x34: CmdLoadTile(w1, w2); break; |
| 3647 | |
| 3648 | case 0x32: CmdSetTileSize(w1, w2); break; |
| 3649 | case 0x35: CmdSetTile(w1, w2); break; |
| 3650 | |
| 3651 | case 0x36: CmdFillRect(w1, w2); break; |
| 3652 | |
| 3653 | case 0x37: CmdSetFillColor32(w1, w2); break; |
| 3654 | case 0x38: CmdSetFogColor(w1, w2); break; |
| 3655 | case 0x39: CmdSetBlendColor(w1, w2); break; |
| 3656 | case 0x3a: CmdSetPrimColor(w1, w2); break; |
| 3657 | case 0x3b: CmdSetEnvColor(w1, w2); break; |
| 3658 | |
| 3659 | case 0x3d: CmdSetTextureImage(w1, w2); break; |
| 3660 | case 0x3e: CmdSetMaskImage(w1, w2); break; |
| 3661 | case 0x3f: CmdSetColorImage(w1, w2); break; |
| 3662 | } |
| 3663 | |
| 3664 | m_cmd_cur += rdp_command_length[cmd] / 4; |
| 3665 | }; |
| 3666 | m_cmd_ptr = 0; |
| 3667 | m_cmd_cur = 0; |
| 3668 | |
| 3669 | m_start = m_current = m_end; |
| 3670 | } |
| 3671 | |
| 3672 | /*****************************************************************************/ |
| 3673 | |
| 3674 | n64_rdp::n64_rdp(n64_state &state) : poly_manager<UINT32, rdp_poly_state, 8, 32000>(state.machine()) |
| 3675 | { |
| 3676 | AuxBufPtr = 0; |
| 3677 | AuxBuf = NULL; |
| 3678 | m_pipe_clean = true; |
| 3679 | |
| 3680 | m_pending_mode_block = false; |
| 3681 | |
| 3682 | m_cmd_ptr = 0; |
| 3683 | m_cmd_cur = 0; |
| 3684 | |
| 3685 | m_start = 0; |
| 3686 | m_end = 0; |
| 3687 | m_current = 0; |
| 3688 | m_status = 0x88; |
| 3689 | |
| 3690 | for (int i = 0; i < 8; i++) |
| 3691 | { |
| 3692 | m_tiles[i].num = i; |
| 3693 | } |
| 3694 | |
| 3695 | OneColor.c = 0xffffffff; |
| 3696 | ZeroColor.c = 0x00000000; |
| 3697 | |
| 3698 | m_tmem = NULL; |
| 3699 | |
| 3700 | m_machine = NULL; |
| 3701 | |
| 3702 | //memset(m_hidden_bits, 3, 8388608); |
| 3703 | |
| 3704 | PrimLODFraction = 0; |
| 3705 | |
| 3706 | for (int i = 0; i < 256; i++) |
| 3707 | { |
| 3708 | m_gamma_table[i] = sqrt((float)(i << 6)); |
| 3709 | m_gamma_table[i] <<= 1; |
| 3710 | } |
| 3711 | |
| 3712 | for (int i = 0; i < 0x4000; i++) |
| 3713 | { |
| 3714 | m_gamma_dither_table[i] = sqrt((float)i); |
| 3715 | m_gamma_dither_table[i] <<= 1; |
| 3716 | } |
| 3717 | |
| 3718 | z_build_com_table(); |
| 3719 | |
| 3720 | for (int i = 0; i < 0x4000; i++) |
| 3721 | { |
| 3722 | UINT32 exponent = (i >> 11) & 7; |
| 3723 | UINT32 mantissa = i & 0x7ff; |
| 3724 | z_complete_dec_table[i] = ((mantissa << z_dec_table[exponent].shift) + z_dec_table[exponent].add) & 0x3fffff; |
| 3725 | } |
| 3726 | |
| 3727 | precalc_cvmask_derivatives(); |
| 3728 | |
| 3729 | for(int i = 0; i < 0x200; i++) |
| 3730 | { |
| 3731 | switch((i >> 7) & 3) |
| 3732 | { |
| 3733 | case 0: |
| 3734 | case 1: |
| 3735 | s_special_9bit_clamptable[i] = i & 0xff; |
| 3736 | break; |
| 3737 | case 2: |
| 3738 | s_special_9bit_clamptable[i] = 0xff; |
| 3739 | break; |
| 3740 | case 3: |
| 3741 | s_special_9bit_clamptable[i] = 0; |
| 3742 | break; |
| 3743 | } |
| 3744 | } |
| 3745 | |
| 3746 | for(int i = 0; i < 32; i++) |
| 3747 | { |
| 3748 | ReplicatedRGBA[i] = (i << 3) | ((i >> 2) & 7); |
| 3749 | } |
| 3750 | |
| 3751 | _Write[0] = &n64_rdp::_Write16Bit_Cvg0_NoBlend; |
| 3752 | _Write[1] = &n64_rdp::_Write16Bit_Cvg0_Blend; |
| 3753 | _Write[2] = &n64_rdp::_Write16Bit_Cvg1; |
| 3754 | _Write[3] = &n64_rdp::_Write16Bit_Cvg1; |
| 3755 | _Write[4] = &n64_rdp::_Write16Bit_Cvg2; |
| 3756 | _Write[5] = &n64_rdp::_Write16Bit_Cvg2; |
| 3757 | _Write[6] = &n64_rdp::_Write16Bit_Cvg3; |
| 3758 | _Write[7] = &n64_rdp::_Write16Bit_Cvg3; |
| 3759 | _Write[8] = &n64_rdp::_Write32Bit_Cvg0_NoBlend; |
| 3760 | _Write[9] = &n64_rdp::_Write32Bit_Cvg0_Blend; |
| 3761 | _Write[10] = &n64_rdp::_Write32Bit_Cvg1; |
| 3762 | _Write[11] = &n64_rdp::_Write32Bit_Cvg1; |
| 3763 | _Write[12] = &n64_rdp::_Write32Bit_Cvg2; |
| 3764 | _Write[13] = &n64_rdp::_Write32Bit_Cvg2; |
| 3765 | _Write[14] = &n64_rdp::_Write32Bit_Cvg3; |
| 3766 | _Write[15] = &n64_rdp::_Write32Bit_Cvg3; |
| 3767 | |
| 3768 | _Read[0] = &n64_rdp::_Read16Bit_ImgRead0; |
| 3769 | _Read[1] = &n64_rdp::_Read16Bit_ImgRead1; |
| 3770 | _Read[2] = &n64_rdp::_Read32Bit_ImgRead0; |
| 3771 | _Read[3] = &n64_rdp::_Read32Bit_ImgRead1; |
| 3772 | |
| 3773 | _Copy[0] = &n64_rdp::_Copy16Bit; |
| 3774 | _Copy[1] = &n64_rdp::_Copy32Bit; |
| 3775 | |
| 3776 | _Fill[0] = &n64_rdp::_Fill16Bit; |
| 3777 | _Fill[1] = &n64_rdp::_Fill32Bit; |
| 3778 | } |
| 3779 | |
| 3780 | void n64_state::video_start() |
| 3781 | { |
| 3782 | m_rdp = auto_alloc(machine(), n64_rdp(*this)); |
| 3783 | |
| 3784 | m_rdp->SetMachine(machine()); |
| 3785 | m_rdp->InitInternalState(); |
| 3786 | |
| 3787 | m_rdp->Blender.SetMachine(machine()); |
| 3788 | m_rdp->Blender.SetProcessor(m_rdp); |
| 3789 | |
| 3790 | m_rdp->TexPipe.SetMachine(machine()); |
| 3791 | |
| 3792 | m_rdp->AuxBuf = auto_alloc_array_clear(machine(), UINT8, EXTENT_AUX_COUNT); |
| 3793 | |
| 3794 | if (LOG_RDP_EXECUTION) |
| 3795 | { |
| 3796 | rdp_exec = fopen("rdp_execute.txt", "wt"); |
| 3797 | } |
| 3798 | } |
| 3799 | |
| 3800 | UINT32 n64_state::screen_update_n64(screen_device &screen, bitmap_rgb32 &bitmap, const rectangle &cliprect) |
| 3801 | { |
| 3802 | n64_periphs *n64 = machine().device<n64_periphs>("rcp"); |
| 3803 | m_rdp->visarea = screen.visible_area(); |
| 3804 | |
| 3805 | //UINT16 *frame_buffer = (UINT16*)&rdram[(n64->vi_origin & 0xffffff) >> 2]; |
| 3806 | //UINT8 *cvg_buffer = &m_rdp.HiddenBits[((n64->vi_origin & 0xffffff) >> 2) >> 1]; |
| 3807 | //int vibuffering = ((n64->vi_control & 2) && fsaa && divot); |
| 3808 | |
| 3809 | //vibuffering = 0; // Disabled for now |
| 3810 | |
| 3811 | /* |
| 3812 | if (vibuffering && ((n64->vi_control & 3) == 2)) |
| 3813 | { |
| 3814 | if (frame_buffer) |
| 3815 | { |
| 3816 | for (j=0; j < vres; j++) |
| 3817 | { |
| 3818 | for (i=0; i < hres; i++) |
| 3819 | { |
| 3820 | UINT16 pix; |
| 3821 | pix = frame_buffer[pixels ^ WORD_ADDR_XOR]; |
| 3822 | curpixel_cvg = ((pix & 1) << 2) | (cvg_buffer[pixels ^ BYTE_ADDR_XOR] & 3); // Reuse of this variable |
| 3823 | if (curpixel_cvg < 7 && i > 1 && j > 1 && i < (hres - 2) && j < (vres - 2) && fsaa) |
| 3824 | { |
| 3825 | newc = video_filter16(&frame_buffer[pixels ^ WORD_ADDR_XOR], &cvg_buffer[pixels ^ BYTE_ADDR_XOR], n64->vi_width); |
| 3826 | ViBuffer[i][j] = newc; |
| 3827 | } |
| 3828 | else |
| 3829 | { |
| 3830 | newc.i.r = ((pix >> 8) & 0xf8) | (pix >> 13); |
| 3831 | newc.i.g = ((pix >> 3) & 0xf8) | ((pix >> 8) & 0x07); |
| 3832 | newc.i.b = ((pix << 2) & 0xf8) | ((pix >> 3) & 0x07); |
| 3833 | ViBuffer[i][j] = newc; |
| 3834 | } |
| 3835 | pixels++; |
| 3836 | } |
| 3837 | pixels += invisiblewidth; |
| 3838 | } |
| 3839 | } |
| 3840 | } |
| 3841 | */ |
| 3842 | |
| 3843 | m_rdp->wait(); |
| 3844 | m_rdp->AuxBufPtr = 0; |
| 3845 | |
| 3846 | if (n64->vi_blank) |
| 3847 | { |
| 3848 | bitmap.fill(0, m_rdp->visarea); |
| 3849 | return 0; |
| 3850 | } |
| 3851 | |
| 3852 | m_rdp->VideoUpdate(n64, bitmap); |
| 3853 | |
| 3854 | return 0; |
| 3855 | } |