trunk/src/mame/video/n64.c
r241380 | r241381 | |
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 "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 | }
|