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 // Oct 2002 Created by Gonetz (Gonetz@ngs.ru)
41 // Info about this ucode is taken from TR64 OGL plugin. Thanks, Icepir8!
42 // Oct 2003 Modified by Gonetz (Gonetz@ngs.ru)
43 // Bugs fixed with help from glN64 sources. Thanks, Orkin!
44 //****************************************************************
46 wxUint32 pd_col_addr = 0;
48 static void uc7_colorbase ()
50 LRDP("uc7_colorbase\n");
51 pd_col_addr = segoffset(rdp.cmd1);
68 static void uc7_vertex ()
72 if (rdp.update & UPDATE_MULT_MAT)
74 rdp.update ^= UPDATE_MULT_MAT;
75 MulMatrices(rdp.model, rdp.proj, rdp.combined);
78 // This is special, not handled in update()
79 if (rdp.update & UPDATE_LIGHTS)
81 rdp.update ^= UPDATE_LIGHTS;
83 // Calculate light vectors
84 for (wxUint32 l=0; l<rdp.num_lights; l++)
86 InverseTransformVector(&rdp.light[l].dir_x, rdp.light_vector[l], rdp.model);
87 NormalizeVector (rdp.light_vector[l]);
91 wxUint32 addr = segoffset(rdp.cmd1);
95 rdp.v0 = v0 = (rdp.cmd0 & 0x0F0000) >> 16;
96 rdp.vn = n = ((rdp.cmd0 & 0xF00000) >> 20) + 1;
98 FRDP ("uc7:vertex n: %d, v0: %d, from: %08lx\n", n, v0, addr);
100 vtx_uc7 *vertex = (vtx_uc7 *)&gfx.RDRAM[addr];
102 for(i = 0; i < n; i++)
104 VERTEX *v = &rdp.vtx[v0 + i];
105 x = (float)vertex->x;
106 y = (float)vertex->y;
107 z = (float)vertex->z;
109 v->ou = (float)vertex->s;
110 v->ov = (float)vertex->t;
113 #ifdef EXTREME_LOGGING
114 // FRDP ("before: v%d - x: %f, y: %f, z: %f, flags: %04lx, ou: %f, ov: %f\n", i>>4, x, y, z, v->flags, v->ou, v->ov);
117 v->x = x*rdp.combined[0][0] + y*rdp.combined[1][0] + z*rdp.combined[2][0] + rdp.combined[3][0];
118 v->y = x*rdp.combined[0][1] + y*rdp.combined[1][1] + z*rdp.combined[2][1] + rdp.combined[3][1];
119 v->z = x*rdp.combined[0][2] + y*rdp.combined[1][2] + z*rdp.combined[2][2] + rdp.combined[3][2];
120 v->w = x*rdp.combined[0][3] + y*rdp.combined[1][3] + z*rdp.combined[2][3] + rdp.combined[3][3];
123 if (fabs(v->w) < 0.001) v->w = 0.001f;
124 v->oow = 1.0f / v->w;
125 v->x_w = v->x * v->oow;
126 v->y_w = v->y * v->oow;
127 v->z_w = v->z * v->oow;
129 v->uv_calculated = 0xFFFFFFFF;
130 v->screen_translated = 0;
133 if (v->x < -v->w) v->scr_off |= 1;
134 if (v->x > v->w) v->scr_off |= 2;
135 if (v->y < -v->w) v->scr_off |= 4;
136 if (v->y > v->w) v->scr_off |= 8;
137 if (v->w < 0.1f) v->scr_off |= 16;
139 wxUint8 *color = &gfx.RDRAM[pd_col_addr + (vertex->idx & 0xff)];
144 if (rdp.geom_mode & 0x00020000)
146 v->vec[0] = (char)color[3];
147 v->vec[1] = (char)color[2];
148 v->vec[2] = (char)color[1];
150 if (rdp.geom_mode & 0x80000)
153 #ifdef EXTREME_LOGGING
154 FRDP ("calc linear: v%d - u: %f, v: %f\n", i>>4, v->ou, v->ov);
157 else if (rdp.geom_mode & 0x40000)
160 #ifdef EXTREME_LOGGING
161 FRDP ("calc sphere: v%d - u: %f, v: %f\n", i>>4, v->ou, v->ov);
165 NormalizeVector (v->vec);
175 #ifdef EXTREME_LOGGING
176 FRDP ("v%d - x: %f, y: %f, z: %f, w: %f, u: %f, v: %f\n", i>>4, v->x, v->y, v->z, v->w, v->ou, v->ov);