Glide Plugin GLES2 port from mupen64plus-ae, but with special FrameSkip code
[mupen64plus-pandora.git] / source / gles2glide64 / src / Glide64 / ucode01.h
CommitLineData
98e75f2d 1/*
2* Glide64 - Glide video plugin for Nintendo 64 emulators.
3* Copyright (c) 2002 Dave2001
4* Copyright (c) 2003-2009 Sergey 'Gonetz' Lipski
5*
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
9* any later version.
10*
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.
15*
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
19*/
20
21//****************************************************************
22//
23// Glide64 - Glide Plugin for Nintendo 64 emulators
24// Project started on December 29th, 2001
25//
26// Authors:
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
31//
32//****************************************************************
33//
34// To modify Glide64:
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.
37//
38//****************************************************************
39
40//
41// vertex - loads vertices
42//
43
44static void uc1_vertex()
45{
46Check_FrameSkip;
47
48 int v0 = (rdp.cmd0 >> 17) & 0x7F; // Current vertex
49 int n = (rdp.cmd0 >> 10) & 0x3F; // Number to copy
50 rsp_vertex(v0, n);
51}
52
53//
54// tri1 - renders a triangle
55//
56
57static void uc1_tri1()
58{
59Check_FrameSkip;
60
61 if (rdp.skip_drawing)
62 {
63 LRDP("uc1:tri1. skipped\n");
64 return;
65 }
66 FRDP("uc1:tri1 #%d - %d, %d, %d - %08lx - %08lx\n", rdp.tri_n,
67 ((rdp.cmd1 >> 17) & 0x7F),
68 ((rdp.cmd1 >> 9) & 0x7F),
69 ((rdp.cmd1 >> 1) & 0x7F), rdp.cmd0, rdp.cmd1);
70
71 VERTEX *v[3] = {
72 &rdp.vtx[(rdp.cmd1 >> 17) & 0x7F],
73 &rdp.vtx[(rdp.cmd1 >> 9) & 0x7F],
74 &rdp.vtx[(rdp.cmd1 >> 1) & 0x7F]
75 };
76
77 rsp_tri1(v);
78}
79
80static void uc1_tri2 ()
81{
82Check_FrameSkip;
83
84 if (rdp.skip_drawing)
85 {
86 LRDP("uc1:tri2. skipped\n");
87 return;
88 }
89 LRDP("uc1:tri2");
90
91 FRDP(" #%d, #%d - %d, %d, %d - %d, %d, %d\n", rdp.tri_n, rdp.tri_n+1,
92 ((rdp.cmd0 >> 17) & 0x7F),
93 ((rdp.cmd0 >> 9) & 0x7F),
94 ((rdp.cmd0 >> 1) & 0x7F),
95 ((rdp.cmd1 >> 17) & 0x7F),
96 ((rdp.cmd1 >> 9) & 0x7F),
97 ((rdp.cmd1 >> 1) & 0x7F));
98
99 VERTEX *v[6] = {
100 &rdp.vtx[(rdp.cmd0 >> 17) & 0x7F],
101 &rdp.vtx[(rdp.cmd0 >> 9) & 0x7F],
102 &rdp.vtx[(rdp.cmd0 >> 1) & 0x7F],
103 &rdp.vtx[(rdp.cmd1 >> 17) & 0x7F],
104 &rdp.vtx[(rdp.cmd1 >> 9) & 0x7F],
105 &rdp.vtx[(rdp.cmd1 >> 1) & 0x7F]
106 };
107
108 rsp_tri2(v);
109}
110
111static void uc1_line3d()
112{
113Check_FrameSkip;
114
115 if (!settings.force_quad3d && ((rdp.cmd1&0xFF000000) == 0) && ((rdp.cmd0&0x00FFFFFF) == 0))
116 {
117 wxUint16 width = (wxUint16)(rdp.cmd1&0xFF) + 3;
118
119 FRDP("uc1:line3d width: %d #%d, #%d - %d, %d\n", width, rdp.tri_n, rdp.tri_n+1,
120 (rdp.cmd1 >> 17) & 0x7F,
121 (rdp.cmd1 >> 9) & 0x7F);
122
123 VERTEX *v[3] = {
124 &rdp.vtx[(rdp.cmd1 >> 17) & 0x7F],
125 &rdp.vtx[(rdp.cmd1 >> 9) & 0x7F],
126 &rdp.vtx[(rdp.cmd1 >> 9) & 0x7F]
127 };
128 wxUint32 cull_mode = (rdp.flags & CULLMASK) >> CULLSHIFT;
129 rdp.flags |= CULLMASK;
130 rdp.update |= UPDATE_CULL_MODE;
131 rsp_tri1(v, width);
132 rdp.flags ^= CULLMASK;
133 rdp.flags |= cull_mode << CULLSHIFT;
134 rdp.update |= UPDATE_CULL_MODE;
135 }
136 else
137 {
138 FRDP("uc1:quad3d #%d, #%d\n", rdp.tri_n, rdp.tri_n+1);
139
140 VERTEX *v[6] = {
141 &rdp.vtx[(rdp.cmd1 >> 25) & 0x7F],
142 &rdp.vtx[(rdp.cmd1 >> 17) & 0x7F],
143 &rdp.vtx[(rdp.cmd1 >> 9) & 0x7F],
144 &rdp.vtx[(rdp.cmd1 >> 1) & 0x7F],
145 &rdp.vtx[(rdp.cmd1 >> 25) & 0x7F],
146 &rdp.vtx[(rdp.cmd1 >> 9) & 0x7F]
147 };
148
149 rsp_tri2(v);
150 }
151}
152
153wxUint32 branch_dl = 0;
154
155static void uc1_rdphalf_1()
156{
157 LRDP("uc1:rdphalf_1\n");
158 branch_dl = rdp.cmd1;
159 rdphalf_1();
160}
161
162static void uc1_branch_z()
163{
164 wxUint32 addr = segoffset(branch_dl);
165 FRDP ("uc1:branch_less_z, addr: %08lx\n", addr);
166 wxUint32 vtx = (rdp.cmd0 & 0xFFF) >> 1;
167 if( fabs(rdp.vtx[vtx].z) <= (rdp.cmd1/*&0xFFFF*/) )
168 {
169 rdp.pc[rdp.pc_i] = addr;
170 }
171}