2 * Glide64 - Glide video plugin for Nintendo 64 emulators.
3 * Copyright (c) 2002 Dave2001
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 //****************************************************************
22 // Glide64 - Glide Plugin for Nintendo 64 emulators (tested mostly with Project64)
23 // Project started on December 29th, 2001
26 // * 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.
27 // * 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.
29 // Official Glide64 development channel: #Glide64 on EFnet
31 // Original author: Dave2001 (Dave2999@hotmail.com)
32 // Other authors: Gonetz, Gugaman
34 //****************************************************************
36 // March 2002 Created by Gonetz (Gonetz@ngs.ru)
37 // Info about this ucode is taken from Daedalus source. Thanks to Daedalus team.
39 //****************************************************************
42 // vertex - loads vertices
45 static void uc3_vertex()
47 DWORD addr
= segoffset(rdp
.cmd1
) & 0x00FFFFFF;
51 rdp
.v0
= v0
= ((rdp
.cmd0
>> 16) & 0xFF)/5; // Current vertex
52 rdp
.vn
= n
= (WORD
)((rdp
.cmd0
&0xFFFF) + 1)/0x210; // Number to copy
54 FRDP ("uc3:vertex v0:%d, n:%d, from: %08lx\n", v0
, n
, addr
);
64 // This is special, not handled in update(), but here
65 // * Matrix Pre-multiplication idea by Gonetz (Gonetz@ngs.ru)
66 if (rdp
.update
& UPDATE_MULT_MAT
)
68 rdp
.update
^= UPDATE_MULT_MAT
;
69 MulMatrices(rdp
.model
, rdp
.proj
, rdp
.combined
);
73 // This is special, not handled in update()
74 if (rdp
.update
& UPDATE_LIGHTS
)
76 rdp
.update
^= UPDATE_LIGHTS
;
78 // Calculate light vectors
79 for (DWORD l
=0; l
<rdp
.num_lights
; l
++)
81 InverseTransformVector(&rdp
.light
[l
].dir_x
, rdp
.light_vector
[l
], rdp
.model
);
82 NormalizeVector (rdp
.light_vector
[l
]);
86 for (i
=0; i
< (n
<<4); i
+=16)
88 VERTEX
*v
= &rdp
.vtx
[v0
+ (i
>>4)];
89 x
= (float)((short*)gfx
.RDRAM
)[(((addr
+i
) >> 1) + 0)^1];
90 y
= (float)((short*)gfx
.RDRAM
)[(((addr
+i
) >> 1) + 1)^1];
91 z
= (float)((short*)gfx
.RDRAM
)[(((addr
+i
) >> 1) + 2)^1];
92 v
->flags
= ((WORD
*)gfx
.RDRAM
)[(((addr
+i
) >> 1) + 3)^1];
93 v
->ou
= (float)((short*)gfx
.RDRAM
)[(((addr
+i
) >> 1) + 4)^1] * rdp
.tiles
[rdp
.cur_tile
].s_scale
;
94 v
->ov
= (float)((short*)gfx
.RDRAM
)[(((addr
+i
) >> 1) + 5)^1] * rdp
.tiles
[rdp
.cur_tile
].t_scale
;
95 v
->a
= ((BYTE
*)gfx
.RDRAM
)[(addr
+i
+ 15)^3];
97 v
->x
= x
*rdp
.combined
[0][0] + y
*rdp
.combined
[1][0] + z
*rdp
.combined
[2][0] + rdp
.combined
[3][0];
98 v
->y
= x
*rdp
.combined
[0][1] + y
*rdp
.combined
[1][1] + z
*rdp
.combined
[2][1] + rdp
.combined
[3][1];
99 v
->z
= x
*rdp
.combined
[0][2] + y
*rdp
.combined
[1][2] + z
*rdp
.combined
[2][2] + rdp
.combined
[3][2];
100 v
->w
= x
*rdp
.combined
[0][3] + y
*rdp
.combined
[1][3] + z
*rdp
.combined
[2][3] + rdp
.combined
[3][3];
102 v
->oow
= 1.0f
/ v
->w
;
103 v
->x_w
= v
->x
* v
->oow
;
104 v
->y_w
= v
->y
* v
->oow
;
105 v
->z_w
= v
->z
* v
->oow
;
108 v
->uv_calculated
= 0xFFFFFFFF;
109 v
->screen_translated
= 0;
110 v
->shade_mods_allowed
= 1;
113 if (v
->x
< -v
->w
) v
->scr_off
|= 1;
114 if (v
->x
> v
->w
) v
->scr_off
|= 2;
115 if (v
->y
< -v
->w
) v
->scr_off
|= 4;
116 if (v
->y
> v
->w
) v
->scr_off
|= 8;
117 if (v
->w
< 0.1f
) v
->scr_off
|= 16;
119 if (rdp
.geom_mode
& 0x00020000)
121 v
->vec
[0] = ((char*)gfx
.RDRAM
)[(addr
+i
+ 12)^3];
122 v
->vec
[1] = ((char*)gfx
.RDRAM
)[(addr
+i
+ 13)^3];
123 v
->vec
[2] = ((char*)gfx
.RDRAM
)[(addr
+i
+ 14)^3];
125 if (rdp
.geom_mode
& 0x80000)
127 else if (rdp
.geom_mode
& 0x40000)
130 NormalizeVector (v
->vec
);
135 v
->r
= ((BYTE
*)gfx
.RDRAM
)[(addr
+i
+ 12)^3];
136 v
->g
= ((BYTE
*)gfx
.RDRAM
)[(addr
+i
+ 13)^3];
137 v
->b
= ((BYTE
*)gfx
.RDRAM
)[(addr
+i
+ 14)^3];
143 // tri1 - renders a triangle
146 static void uc3_tri1()
148 FRDP("uc3:tri1 #%d - %d, %d, %d - %08lx - %08lx\n", rdp
.tri_n
,
149 ((rdp
.cmd1
>> 16) & 0xFF)/5,
150 ((rdp
.cmd1
>> 8) & 0xFF)/5,
151 ((rdp
.cmd1
) & 0xFF)/5, rdp
.cmd0
, rdp
.cmd1
);
154 &rdp
.vtx
[((rdp
.cmd1
>> 16) & 0xFF)/5],
155 &rdp
.vtx
[((rdp
.cmd1
>> 8) & 0xFF)/5],
156 &rdp
.vtx
[(rdp
.cmd1
& 0xFF)/5]
170 static void uc3_tri2 ()
172 FRDP("uc3:tri2 #%d, #%d - %d, %d, %d - %d, %d, %d\n", rdp
.tri_n
, rdp
.tri_n
+1,
173 ((rdp
.cmd0
>> 16) & 0xFF)/5,
174 ((rdp
.cmd0
>> 8) & 0xFF)/5,
175 ((rdp
.cmd0
) & 0xFF)/5,
176 ((rdp
.cmd1
>> 16) & 0xFF)/5,
177 ((rdp
.cmd1
>> 8) & 0xFF)/5,
178 ((rdp
.cmd1
) & 0xFF)/5);
181 &rdp
.vtx
[((rdp
.cmd0
>> 16) & 0xFF)/5],
182 &rdp
.vtx
[((rdp
.cmd0
>> 8) & 0xFF)/5],
183 &rdp
.vtx
[(rdp
.cmd0
& 0xFF)/5],
184 &rdp
.vtx
[((rdp
.cmd1
>> 16) & 0xFF)/5],
185 &rdp
.vtx
[((rdp
.cmd1
>> 8) & 0xFF)/5],
186 &rdp
.vtx
[(rdp
.cmd1
& 0xFF)/5]
214 static void uc3_quad3d()
216 FRDP("uc3:quad3d #%d, #%d\n", rdp
.tri_n
, rdp
.tri_n
+1);
219 &rdp
.vtx
[((rdp
.cmd1
>> 24) & 0xFF)/5],
220 &rdp
.vtx
[((rdp
.cmd1
>> 16) & 0xFF)/5],
221 &rdp
.vtx
[((rdp
.cmd1
>> 8) & 0xFF)/5],
222 &rdp
.vtx
[(rdp
.cmd1
& 0xFF)/5],
223 &rdp
.vtx
[((rdp
.cmd1
>> 24) & 0xFF)/5],
224 &rdp
.vtx
[((rdp
.cmd1
>> 8) & 0xFF)/5],
225 &rdp
.vtx
[((rdp
.cmd1
>> 24) & 0xFF)/5]