2 * Glide64 - Glide video plugin for Nintendo 64 emulators.
3 * Copyright (c) 2002 Dave2001
4 * Copyright (c) 2003-2009 Sergey 'Gonetz' Lipski
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 //****************************************************************
23 // Glide64 - Glide Plugin for Nintendo 64 emulators
24 // Project started on December 29th, 2001
27 // Dave2001, original author, founded the project in 2001, left it in 2002
28 // Gugaman, joined the project in 2002, left it in 2002
29 // Sergey 'Gonetz' Lipski, joined the project in 2002, main author since fall of 2002
30 // Hiroshi 'KoolSmoky' Morii, joined the project in 2007
32 //****************************************************************
35 // * Write your name and (optional)email, commented by your work, so I know who did it, and so that you can find which parts you modified when it comes time to send it to me.
36 // * Do NOT send me the whole project or file that you modified. Take out your modified code sections, and tell me where to put them. If people sent the whole thing, I would have many different versions, but no idea how to combine them all.
38 //****************************************************************
40 static void calc_point_light (VERTEX *v, float * vpos)
44 float light_intensity = 0.0f;
45 register float color[3] = {rdp.light[rdp.num_lights].r, rdp.light[rdp.num_lights].g, rdp.light[rdp.num_lights].b};
46 for (wxUint32 l=0; l<rdp.num_lights; l++)
48 if (rdp.light[l].nonblack)
50 float lvec[3] = {rdp.light[l].x, rdp.light[l].y, rdp.light[l].z};
54 float light_len2 = lvec[0]*lvec[0] + lvec[1]*lvec[1] + lvec[2]*lvec[2];
55 float light_len = sqrtf(light_len2);
56 #ifdef EXTREME_LOGGING
57 FRDP ("calc_point_light: len: %f, len2: %f\n", light_len, light_len2);
59 float at = rdp.light[l].ca + light_len/65535.0f*rdp.light[l].la + light_len2/65535.0f*rdp.light[l].qa;
61 light_intensity = 1/at;//DotProduct (lvec, nvec) / (light_len * normal_len * at);
63 light_intensity = 0.0f;
67 light_intensity = 0.0f;
69 if (light_intensity > 0.0f)
71 color[0] += rdp.light[l].r * light_intensity;
72 color[1] += rdp.light[l].g * light_intensity;
73 color[2] += rdp.light[l].b * light_intensity;
76 if (color[0] > 1.0f) color[0] = 1.0f;
77 if (color[1] > 1.0f) color[1] = 1.0f;
78 if (color[2] > 1.0f) color[2] = 1.0f;
80 v->r = (wxUint8)(color[0]*255.0f);
81 v->g = (wxUint8)(color[1]*255.0f);
82 v->b = (wxUint8)(color[2]*255.0f);
85 static void uc6_obj_rectangle();
87 static void uc2_vertex ()
91 if (!(rdp.cmd0 & 0x00FFFFFF))
97 // This is special, not handled in update(), but here
98 // * Matrix Pre-multiplication idea by Gonetz (Gonetz@ngs.ru)
99 if (rdp.update & UPDATE_MULT_MAT)
101 rdp.update ^= UPDATE_MULT_MAT;
102 MulMatrices(rdp.model, rdp.proj, rdp.combined);
104 if (rdp.update & UPDATE_LIGHTS)
106 rdp.update ^= UPDATE_LIGHTS;
108 // Calculate light vectors
109 for (wxUint32 l=0; l<rdp.num_lights; l++)
111 InverseTransformVector(&rdp.light[l].dir_x, rdp.light_vector[l], rdp.model);
112 NormalizeVector (rdp.light_vector[l]);
116 wxUint32 addr = segoffset(rdp.cmd1);
120 rdp.vn = n = (rdp.cmd0 >> 12) & 0xFF;
121 rdp.v0 = v0 = ((rdp.cmd0 >> 1) & 0x7F) - n;
123 FRDP ("uc2:vertex n: %d, v0: %d, from: %08lx\n", n, v0, addr);
127 RDP_E ("** ERROR: uc2:vertex v0 < 0\n");
128 LRDP("** ERROR: uc2:vertex v0 < 0\n");
132 wxUint32 geom_mode = rdp.geom_mode;
133 if ((settings.hacks&hack_Fzero) && (rdp.geom_mode & 0x40000))
135 if (((short*)gfx.RDRAM)[(((addr) >> 1) + 4)^1] || ((short*)gfx.RDRAM)[(((addr) >> 1) + 5)^1])
136 rdp.geom_mode ^= 0x40000;
139 float32x4_t comb0, comb1, comb2, comb3;
141 comb0 = vld1q_f32(rdp.combined[0]);
142 comb1 = vld1q_f32(rdp.combined[1]);
143 comb2 = vld1q_f32(rdp.combined[2]);
144 comb3 = vld1q_f32(rdp.combined[3]);
146 for (i=0; i < (n<<4); i+=16)
148 VERTEX *v = &rdp.vtx[v0 + (i>>4)];
149 x = (float)((short*)gfx.RDRAM)[(((addr+i) >> 1) + 0)^1];
150 y = (float)((short*)gfx.RDRAM)[(((addr+i) >> 1) + 1)^1];
151 z = (float)((short*)gfx.RDRAM)[(((addr+i) >> 1) + 2)^1];
152 v->flags = ((wxUint16*)gfx.RDRAM)[(((addr+i) >> 1) + 3)^1];
153 v->ou = (float)((short*)gfx.RDRAM)[(((addr+i) >> 1) + 4)^1];
154 v->ov = (float)((short*)gfx.RDRAM)[(((addr+i) >> 1) + 5)^1];
156 v->a = ((wxUint8*)gfx.RDRAM)[(addr+i + 15)^3];
159 v_xyzw = x*comb0+y*comb1+z*comb2+comb3;
160 //vst1q_f32((float*)v, v_xyzw);
166 v->x = x*rdp.combined[0][0] + y*rdp.combined[1][0] + z*rdp.combined[2][0] + rdp.combined[3][0];
167 v->y = x*rdp.combined[0][1] + y*rdp.combined[1][1] + z*rdp.combined[2][1] + rdp.combined[3][1];
168 v->z = x*rdp.combined[0][2] + y*rdp.combined[1][2] + z*rdp.combined[2][2] + rdp.combined[3][2];
169 v->w = x*rdp.combined[0][3] + y*rdp.combined[1][3] + z*rdp.combined[2][3] + rdp.combined[3][3];
172 v->uv_calculated = 0xFFFFFFFF;
173 v->screen_translated = 0;
176 if (fabs(v->w) < 0.001) v->w = 0.001f;
177 v->oow = 1.0f / v->w;
184 v->x_w = v->x * v->oow;
185 v->y_w = v->y * v->oow;
186 v->z_w = v->z * v->oow;
192 if (v->x < -v->w) v->scr_off |= 1;
193 if (v->x > v->w) v->scr_off |= 2;
194 if (v->y < -v->w) v->scr_off |= 4;
195 if (v->y > v->w) v->scr_off |= 8;
196 if (v->w < 0.1f) v->scr_off |= 16;
197 // if (v->z_w > 1.0f) v->scr_off |= 32;
199 if (rdp.geom_mode & 0x00020000)
201 v->vec[0] = ((char*)gfx.RDRAM)[(addr+i + 12)^3];
202 v->vec[1] = ((char*)gfx.RDRAM)[(addr+i + 13)^3];
203 v->vec[2] = ((char*)gfx.RDRAM)[(addr+i + 14)^3];
204 // FRDP("Calc light. x: %f, y: %f z: %f\n", v->vec[0], v->vec[1], v->vec[2]);
205 // if (!(rdp.geom_mode & 0x800000))
207 if (rdp.geom_mode & 0x40000)
209 if (rdp.geom_mode & 0x80000)
212 #ifdef EXTREME_LOGGING
213 FRDP ("calc linear: v%d - u: %f, v: %f\n", i>>4, v->ou, v->ov);
219 #ifdef EXTREME_LOGGING
220 FRDP ("calc sphere: v%d - u: %f, v: %f\n", i>>4, v->ou, v->ov);
225 if (rdp.geom_mode & 0x00400000)
227 float tmpvec[3] = {x, y, z};
228 calc_point_light (v, tmpvec);
232 NormalizeVector (v->vec);
238 v->r = ((wxUint8*)gfx.RDRAM)[(addr+i + 12)^3];
239 v->g = ((wxUint8*)gfx.RDRAM)[(addr+i + 13)^3];
240 v->b = ((wxUint8*)gfx.RDRAM)[(addr+i + 14)^3];
242 #ifdef EXTREME_LOGGING
243 FRDP ("v%d - x: %f, y: %f, z: %f, w: %f, u: %f, v: %f, f: %f, z_w: %f, r=%d, g=%d, b=%d, a=%d\n", i>>4, v->x, v->y, v->z, v->w, v->ou*rdp.tiles[rdp.cur_tile].s_scale, v->ov*rdp.tiles[rdp.cur_tile].t_scale, v->f, v->z_w, v->r, v->g, v->b, v->a);
246 rdp.geom_mode = geom_mode;
249 static void uc2_modifyvtx ()
253 wxUint8 where = (wxUint8)((rdp.cmd0 >> 16) & 0xFF);
254 wxUint16 vtx = (wxUint16)((rdp.cmd0 >> 1) & 0xFFFF);
256 FRDP ("uc2:modifyvtx: vtx: %d, where: 0x%02lx, val: %08lx - ", vtx, where, rdp.cmd1);
257 uc0_modifyvtx(where, vtx, rdp.cmd1);
260 static void uc2_culldl ()
262 wxUint16 vStart = (wxUint16)(rdp.cmd0 & 0xFFFF) >> 1;
263 wxUint16 vEnd = (wxUint16)(rdp.cmd1 & 0xFFFF) >> 1;
265 FRDP ("uc2:culldl start: %d, end: %d\n", vStart, vEnd);
267 if (vEnd < vStart) return;
268 for (wxUint16 i=vStart; i<=vEnd; i++)
271 VERTEX v = &rdp.vtx[i];
272 // Check if completely off the screen (quick frustrum clipping for 90 FOV)
288 #ifdef EXTREME_LOGGING
289 FRDP (" v[%d] = (%02f, %02f, %02f, 0x%02lx)\n", i, rdp.vtx[i].x, rdp.vtx[i].y, rdp.vtx[i].w, rdp.vtx[i].scr_off);
292 cond |= (~rdp.vtx[i].scr_off) & 0x1F;
297 LRDP(" - "); // specify that the enddl is not a real command
301 static void uc6_obj_loadtxtr ();
303 static void uc2_tri1()
307 if ((rdp.cmd0 & 0x00FFFFFF) == 0x17)
312 if (rdp.skip_drawing)
314 LRDP("uc2:tri1. skipped\n");
318 FRDP("uc2:tri1 #%d - %d, %d, %d\n", rdp.tri_n,
319 ((rdp.cmd0 >> 17) & 0x7F),
320 ((rdp.cmd0 >> 9) & 0x7F),
321 ((rdp.cmd0 >> 1) & 0x7F));
324 &rdp.vtx[(rdp.cmd0 >> 17) & 0x7F],
325 &rdp.vtx[(rdp.cmd0 >> 9) & 0x7F],
326 &rdp.vtx[(rdp.cmd0 >> 1) & 0x7F]
332 static void uc6_obj_ldtx_sprite ();
333 static void uc6_obj_ldtx_rect ();
335 static void uc2_quad ()
339 if ((rdp.cmd0 & 0x00FFFFFF) == 0x2F)
341 wxUint32 command = rdp.cmd0>>24;
344 uc6_obj_ldtx_sprite ();
349 uc6_obj_ldtx_rect ();
354 if (rdp.skip_drawing)
356 LRDP("uc2_quad. skipped\n");
362 FRDP(" #%d, #%d - %d, %d, %d - %d, %d, %d\n", rdp.tri_n, rdp.tri_n+1,
363 ((rdp.cmd0 >> 17) & 0x7F),
364 ((rdp.cmd0 >> 9) & 0x7F),
365 ((rdp.cmd0 >> 1) & 0x7F),
366 ((rdp.cmd1 >> 17) & 0x7F),
367 ((rdp.cmd1 >> 9) & 0x7F),
368 ((rdp.cmd1 >> 1) & 0x7F));
371 &rdp.vtx[(rdp.cmd0 >> 17) & 0x7F],
372 &rdp.vtx[(rdp.cmd0 >> 9) & 0x7F],
373 &rdp.vtx[(rdp.cmd0 >> 1) & 0x7F],
374 &rdp.vtx[(rdp.cmd1 >> 17) & 0x7F],
375 &rdp.vtx[(rdp.cmd1 >> 9) & 0x7F],
376 &rdp.vtx[(rdp.cmd1 >> 1) & 0x7F]
382 static void uc6_ldtx_rect_r ();
384 static void uc2_line3d ()
388 if ( (rdp.cmd0&0xFF) == 0x2F )
392 FRDP("uc2:line3d #%d, #%d - %d, %d\n", rdp.tri_n, rdp.tri_n+1,
393 (rdp.cmd0 >> 17) & 0x7F,
394 (rdp.cmd0 >> 9) & 0x7F);
397 &rdp.vtx[(rdp.cmd0 >> 17) & 0x7F],
398 &rdp.vtx[(rdp.cmd0 >> 9) & 0x7F],
399 &rdp.vtx[(rdp.cmd0 >> 9) & 0x7F]
401 wxUint16 width = (wxUint16)(rdp.cmd0 + 3)&0xFF;
402 wxUint32 cull_mode = (rdp.flags & CULLMASK) >> CULLSHIFT;
403 rdp.flags |= CULLMASK;
404 rdp.update |= UPDATE_CULL_MODE;
406 rdp.flags ^= CULLMASK;
407 rdp.flags |= cull_mode << CULLSHIFT;
408 rdp.update |= UPDATE_CULL_MODE;
412 static void uc2_special3 ()
414 LRDP("uc2:special3\n");
417 static void uc2_special2 ()
419 LRDP("uc2:special2\n");
422 static void uc2_dma_io ()
424 LRDP("uc2:dma_io\n");
427 static void uc2_pop_matrix ()
429 FRDP ("uc2:pop_matrix %08lx, %08lx\n", rdp.cmd0, rdp.cmd1);
431 // Just pop the modelview matrix
432 modelview_pop (rdp.cmd1 >> 6);
435 static void uc2_geom_mode ()
437 // Switch around some things
438 wxUint32 clr_mode = (rdp.cmd0 & 0x00DFC9FF) |
439 ((rdp.cmd0 & 0x00000600) << 3) |
440 ((rdp.cmd0 & 0x00200000) >> 12) | 0xFF000000;
441 wxUint32 set_mode = (rdp.cmd1 & 0xFFDFC9FF) |
442 ((rdp.cmd1 & 0x00000600) << 3) |
443 ((rdp.cmd1 & 0x00200000) >> 12);
445 FRDP("uc2:geom_mode c:%08lx, s:%08lx ", clr_mode, set_mode);
447 rdp.geom_mode &= clr_mode;
448 rdp.geom_mode |= set_mode;
450 FRDP ("result:%08lx\n", rdp.geom_mode);
452 if (rdp.geom_mode & 0x00000001) // Z-Buffer enable
454 if (!(rdp.flags & ZBUF_ENABLED))
456 rdp.flags |= ZBUF_ENABLED;
457 rdp.update |= UPDATE_ZBUF_ENABLED;
462 if ((rdp.flags & ZBUF_ENABLED))
464 if (!settings.flame_corona || (rdp.rm != 0x00504341)) //hack for flame's corona
465 rdp.flags ^= ZBUF_ENABLED;
466 rdp.update |= UPDATE_ZBUF_ENABLED;
469 if (rdp.geom_mode & 0x00001000) // Front culling
471 if (!(rdp.flags & CULL_FRONT))
473 rdp.flags |= CULL_FRONT;
474 rdp.update |= UPDATE_CULL_MODE;
479 if (rdp.flags & CULL_FRONT)
481 rdp.flags ^= CULL_FRONT;
482 rdp.update |= UPDATE_CULL_MODE;
485 if (rdp.geom_mode & 0x00002000) // Back culling
487 if (!(rdp.flags & CULL_BACK))
489 rdp.flags |= CULL_BACK;
490 rdp.update |= UPDATE_CULL_MODE;
495 if (rdp.flags & CULL_BACK)
497 rdp.flags ^= CULL_BACK;
498 rdp.update |= UPDATE_CULL_MODE;
503 if (rdp.geom_mode & 0x00010000) // Fog enable
505 if (!(rdp.flags & FOG_ENABLED))
507 rdp.flags |= FOG_ENABLED;
508 rdp.update |= UPDATE_FOG_ENABLED;
513 if (rdp.flags & FOG_ENABLED)
515 rdp.flags ^= FOG_ENABLED;
516 rdp.update |= UPDATE_FOG_ENABLED;
521 static void uc6_obj_rectangle_r ();
523 static void uc2_matrix ()
525 if (!(rdp.cmd0 & 0x00FFFFFF))
527 uc6_obj_rectangle_r();
530 LRDP("uc2:matrix\n");
532 DECLAREALIGN16VAR(m[4][4]);
533 load_matrix(m, segoffset(rdp.cmd1));
535 wxUint8 command = (wxUint8)((rdp.cmd0 ^ 1) & 0xFF);
538 case 0: // modelview mul nopush
539 LRDP("modelview mul\n");
543 case 1: // modelview mul push
544 LRDP("modelview mul push\n");
545 modelview_mul_push (m);
548 case 2: // modelview load nopush
549 LRDP("modelview load\n");
553 case 3: // modelview load push
554 LRDP("modelview load push\n");
555 modelview_load_push (m);
558 case 4: // projection mul nopush
559 case 5: // projection mul push, can't push projection
560 LRDP("projection mul\n");
564 case 6: // projection load nopush
565 case 7: // projection load push, can't push projection
566 LRDP("projection load\n");
571 FRDP_E ("Unknown matrix command, %02lx", command);
572 FRDP ("Unknown matrix command, %02lx", command);
575 #ifdef EXTREME_LOGGING
576 FRDP ("{%f,%f,%f,%f}\n", m[0][0], m[0][1], m[0][2], m[0][3]);
577 FRDP ("{%f,%f,%f,%f}\n", m[1][0], m[1][1], m[1][2], m[1][3]);
578 FRDP ("{%f,%f,%f,%f}\n", m[2][0], m[2][1], m[2][2], m[2][3]);
579 FRDP ("{%f,%f,%f,%f}\n", m[3][0], m[3][1], m[3][2], m[3][3]);
580 FRDP ("\nmodel\n{%f,%f,%f,%f}\n", rdp.model[0][0], rdp.model[0][1], rdp.model[0][2], rdp.model[0][3]);
581 FRDP ("{%f,%f,%f,%f}\n", rdp.model[1][0], rdp.model[1][1], rdp.model[1][2], rdp.model[1][3]);
582 FRDP ("{%f,%f,%f,%f}\n", rdp.model[2][0], rdp.model[2][1], rdp.model[2][2], rdp.model[2][3]);
583 FRDP ("{%f,%f,%f,%f}\n", rdp.model[3][0], rdp.model[3][1], rdp.model[3][2], rdp.model[3][3]);
584 FRDP ("\nproj\n{%f,%f,%f,%f}\n", rdp.proj[0][0], rdp.proj[0][1], rdp.proj[0][2], rdp.proj[0][3]);
585 FRDP ("{%f,%f,%f,%f}\n", rdp.proj[1][0], rdp.proj[1][1], rdp.proj[1][2], rdp.proj[1][3]);
586 FRDP ("{%f,%f,%f,%f}\n", rdp.proj[2][0], rdp.proj[2][1], rdp.proj[2][2], rdp.proj[2][3]);
587 FRDP ("{%f,%f,%f,%f}\n", rdp.proj[3][0], rdp.proj[3][1], rdp.proj[3][2], rdp.proj[3][3]);
591 static void uc2_moveword ()
593 wxUint8 index = (wxUint8)((rdp.cmd0 >> 16) & 0xFF);
594 wxUint16 offset = (wxUint16)(rdp.cmd0 & 0xFFFF);
595 wxUint32 data = rdp.cmd1;
597 FRDP ("uc2:moveword ");
601 // NOTE: right now it's assuming that it sets the integer part first. This could
602 // be easily fixed, but only if i had something to test with.
604 case 0x00: // moveword matrix
606 // do matrix pre-mult so it's re-updated next time
607 if (rdp.update & UPDATE_MULT_MAT)
609 rdp.update ^= UPDATE_MULT_MAT;
610 MulMatrices(rdp.model, rdp.proj, rdp.combined);
613 if (rdp.cmd0 & 0x20) // fractional part
615 int index_x = (rdp.cmd0 & 0x1F) >> 1;
616 int index_y = index_x >> 2;
619 float fpart = (rdp.cmd1>>16)/65536.0f;
620 rdp.combined[index_y][index_x] = (float)(int)rdp.combined[index_y][index_x];
621 rdp.combined[index_y][index_x] += fpart;
623 fpart = (rdp.cmd1&0xFFFF)/65536.0f;
624 rdp.combined[index_y][index_x+1] = (float)(int)rdp.combined[index_y][index_x+1];
625 rdp.combined[index_y][index_x+1] += fpart;
629 int index_x = (rdp.cmd0 & 0x1F) >> 1;
630 int index_y = index_x >> 2;
633 rdp.combined[index_y][index_x] = (short)(rdp.cmd1>>16);
634 rdp.combined[index_y][index_x+1] = (short)(rdp.cmd1&0xFFFF);
642 rdp.num_lights = data / 24;
643 rdp.update |= UPDATE_LIGHTS;
644 FRDP ("numlights: %d\n", rdp.num_lights);
650 rdp.clip_ratio = sqrt((float)rdp.cmd1);
651 rdp.update |= UPDATE_VIEWPORT;
653 FRDP ("mw_clip %08lx, %08lx\n", rdp.cmd0, rdp.cmd1);
656 case 0x06: // moveword SEGMENT
658 FRDP ("SEGMENT %08lx -> seg%d\n", data, offset >> 2);
659 if ((data&BMASK)<BMASK)
660 rdp.segment[(offset >> 2) & 0xF] = data;
667 rdp.fog_multiplier = (short)(rdp.cmd1 >> 16);
668 rdp.fog_offset = (short)(rdp.cmd1 & 0x0000FFFF);
669 FRDP ("fog: multiplier: %f, offset: %f\n", rdp.fog_multiplier, rdp.fog_offset);
671 //offset must be 0 for move_fog, but it can be non zero in Nushi Zuri 64 - Shiokaze ni Notte
672 //low-level display list has setothermode commands in this place, so this is obviously not move_fog.
674 rdp.tlut_mode = (data == 0xffffffff) ? 0 : 2;
678 case 0x0a: // moveword LIGHTCOL
681 FRDP ("lightcol light:%d, %08lx\n", n, data);
683 rdp.light[n].r = (float)((data >> 24) & 0xFF) / 255.0f;
684 rdp.light[n].g = (float)((data >> 16) & 0xFF) / 255.0f;
685 rdp.light[n].b = (float)((data >> 8) & 0xFF) / 255.0f;
686 rdp.light[n].a = 255;
691 RDP_E ("uc2:moveword forcemtx - IGNORED\n");
692 LRDP("forcemtx - IGNORED\n");
696 LRDP("perspnorm - IGNORED\n");
700 FRDP_E("uc2:moveword unknown (index: 0x%08lx, offset 0x%08lx)\n", index, offset);
701 FRDP ("unknown (index: 0x%08lx, offset 0x%08lx)\n", index, offset);
705 static void uc6_obj_movemem ();
707 static void uc2_movemem ()
709 int idx = rdp.cmd0 & 0xFF;
710 wxUint32 addr = segoffset(rdp.cmd1);
711 int ofs = (rdp.cmd0 >> 5) & 0x7F8;
713 FRDP ("uc2:movemem ofs:%d ", ofs);
724 wxUint32 a = addr >> 1;
725 short scale_x = ((short*)gfx.RDRAM)[(a+0)^1] >> 2;
726 short scale_y = ((short*)gfx.RDRAM)[(a+1)^1] >> 2;
727 short scale_z = ((short*)gfx.RDRAM)[(a+2)^1];
728 short trans_x = ((short*)gfx.RDRAM)[(a+4)^1] >> 2;
729 short trans_y = ((short*)gfx.RDRAM)[(a+5)^1] >> 2;
730 short trans_z = ((short*)gfx.RDRAM)[(a+6)^1];
731 rdp.view_scale[0] = scale_x * rdp.scale_x;
732 rdp.view_scale[1] = -scale_y * rdp.scale_y;
733 rdp.view_scale[2] = 32.0f * scale_z;
734 rdp.view_trans[0] = trans_x * rdp.scale_x;
735 rdp.view_trans[1] = trans_y * rdp.scale_y;
736 rdp.view_trans[2] = 32.0f * trans_z;
738 rdp.update |= UPDATE_VIEWPORT;
740 FRDP ("viewport scale(%d, %d, %d), trans(%d, %d, %d), from:%08lx\n", scale_x, scale_y, scale_z,
741 trans_x, trans_y, trans_z, a);
751 char dir_x = ((char*)gfx.RDRAM)[(addr+8)^3];
752 rdp.lookat[n][0] = (float)(dir_x) / 127.0f;
753 char dir_y = ((char*)gfx.RDRAM)[(addr+9)^3];
754 rdp.lookat[n][1] = (float)(dir_y) / 127.0f;
755 char dir_z = ((char*)gfx.RDRAM)[(addr+10)^3];
756 rdp.lookat[n][2] = (float)(dir_z) / 127.0f;
757 rdp.use_lookat = TRUE;
760 if (!dir_x && !dir_y)
761 rdp.use_lookat = FALSE;
763 FRDP("lookat_%d (%f, %f, %f)\n", n, rdp.lookat[n][0], rdp.lookat[n][1], rdp.lookat[n][2]);
770 wxUint8 col = gfx.RDRAM[(addr+0)^3];
771 rdp.light[n].r = (float)col / 255.0f;
772 rdp.light[n].nonblack = col;
773 col = gfx.RDRAM[(addr+1)^3];
774 rdp.light[n].g = (float)col / 255.0f;
775 rdp.light[n].nonblack += col;
776 col = gfx.RDRAM[(addr+2)^3];
777 rdp.light[n].b = (float)col / 255.0f;
778 rdp.light[n].nonblack += col;
779 rdp.light[n].a = 1.0f;
780 // ** Thanks to Icepir8 for pointing this out **
781 // Lighting must be signed byte instead of byte
782 rdp.light[n].dir_x = (float)(((char*)gfx.RDRAM)[(addr+8)^3]) / 127.0f;
783 rdp.light[n].dir_y = (float)(((char*)gfx.RDRAM)[(addr+9)^3]) / 127.0f;
784 rdp.light[n].dir_z = (float)(((char*)gfx.RDRAM)[(addr+10)^3]) / 127.0f;
785 wxUint32 a = addr >> 1;
786 rdp.light[n].x = (float)(((short*)gfx.RDRAM)[(a+4)^1]);
787 rdp.light[n].y = (float)(((short*)gfx.RDRAM)[(a+5)^1]);
788 rdp.light[n].z = (float)(((short*)gfx.RDRAM)[(a+6)^1]);
789 rdp.light[n].ca = (float)(gfx.RDRAM[(addr+3)^3]) / 16.0f;
790 rdp.light[n].la = (float)(gfx.RDRAM[(addr+7)^3]);
791 rdp.light[n].qa = (float)(gfx.RDRAM[(addr+14)^3]) / 8.0f;
792 #ifdef EXTREME_LOGGING
793 FRDP ("light: n: %d, pos: x: %f, y: %f, z: %f, ca: %f, la:%f, qa: %f\n",
794 n, rdp.light[n].x, rdp.light[n].y, rdp.light[n].z, rdp.light[n].ca, rdp.light[n].la, rdp.light[n].qa);
796 FRDP ("light: n: %d, r: %.3f, g: %.3f, b: %.3f. dir: x: %.3f, y: %.3f, z: %.3f\n",
797 n, rdp.light[n].r, rdp.light[n].g, rdp.light[n].b,
798 rdp.light[n].dir_x, rdp.light[n].dir_y, rdp.light[n].dir_z);
804 // do not update the combined matrix!
805 rdp.update &= ~UPDATE_MULT_MAT;
806 load_matrix(rdp.combined, segoffset(rdp.cmd1));
808 #ifdef EXTREME_LOGGING
809 FRDP ("{%f,%f,%f,%f}\n", rdp.combined[0][0], rdp.combined[0][1], rdp.combined[0][2], rdp.combined[0][3]);
810 FRDP ("{%f,%f,%f,%f}\n", rdp.combined[1][0], rdp.combined[1][1], rdp.combined[1][2], rdp.combined[1][3]);
811 FRDP ("{%f,%f,%f,%f}\n", rdp.combined[2][0], rdp.combined[2][1], rdp.combined[2][2], rdp.combined[2][3]);
812 FRDP ("{%f,%f,%f,%f}\n", rdp.combined[3][0], rdp.combined[3][1], rdp.combined[3][2], rdp.combined[3][3]);
818 FRDP ("uc2:matrix unknown (%d)\n", idx);
819 FRDP ("** UNKNOWN %d\n", idx);
823 static void uc2_load_ucode ()
825 LRDP("uc2:load_ucode\n");
828 static void uc2_rdphalf_2 ()
830 LRDP("uc2:rdphalf_2\n");
833 static void uc2_dlist_cnt ()
835 wxUint32 addr = segoffset(rdp.cmd1) & BMASK;
836 int count = rdp.cmd0 & 0x000000FF;
837 FRDP ("dl_count - addr: %08lx, count: %d\n", addr, count);
842 RDP_E ("** DL stack overflow **\n");
843 LRDP("** DL stack overflow **\n");
846 rdp.pc_i ++; // go to the next PC in the stack
847 rdp.pc[rdp.pc_i] = addr; // jump to the address
848 rdp.dl_count = count + 1;