/[pcsx2_0.9.7]/trunk/plugins/zzogl-pg/opengl/GifTransfer.cpp
ViewVC logotype

Contents of /trunk/plugins/zzogl-pg/opengl/GifTransfer.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 280 - (show annotations) (download)
Thu Dec 23 12:02:12 2010 UTC (9 years, 2 months ago) by william
File size: 6010 byte(s)
re-commit (had local access denied errors when committing)
1 /* ZZ Open GL graphics plugin
2 * Copyright (c)2009-2010 zeydlitz@gmail.com, arcum42@gmail.com
3 * Based on Zerofrog's ZeroGS KOSMOS (c)2005-2008
4 *
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
8 * (at your option) any later version.
9 *
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.
14 *
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
18 */
19
20 #include "GS.h"
21 #include "Mem.h"
22 #include "GifTransfer.h"
23
24 #ifdef _DEBUG
25 static int count = 0;
26 #endif
27
28 static int nPath3Hack = 0;
29
30 void CALLBACK GSgetLastTag(u64* ptag)
31 {
32 FUNCLOG
33
34 *(u32*)ptag = nPath3Hack;
35 nPath3Hack = 0;
36 }
37
38 #ifdef _WIN32
39 // for debug assertion checks (thread affinity checks)
40 extern HANDLE g_hCurrentThread;
41 #endif
42
43 __forceinline void gifTransferLog(int index, const u32 *pMem, u32 size)
44 {
45 #ifdef DEBUG_TRANSFER
46
47 if (conf.log)
48 {
49 static int nSaveIndex = 0;
50 ZZLog::Debug_Log("%d: p:%d %x", nSaveIndex++, index + 1, size);
51 int vals[4] = {0};
52
53 for (u32 i = 0; i < size; i++)
54 {
55 for (u32 j = 0; j < 4; ++j)
56 vals[j] ^= pMem[4*i+j];
57 }
58
59 ZZLog::Debug_Log("%x %x %x %x", vals[0], vals[1], vals[2], vals[3]);
60 }
61
62 #endif
63 }
64
65 extern int g_GSMultiThreaded;
66
67 template<int index> void _GSgifTransfer(const u32 *pMem, u32 size)
68 {
69 FUNCLOG
70
71 pathInfo *path = &gs.path[index];
72
73 #ifdef _WIN32
74 assert(g_hCurrentThread == GetCurrentThread());
75 #endif
76
77 #ifdef _DEBUG
78 gifTransferLog(index, pMem, size);
79 #endif
80
81 while (size > 0)
82 {
83 //LOG(_T("Transfer(%08x, %d) START\n"), pMem, size);
84 if (path->nloop == 0)
85 {
86 path->setTag(pMem);
87 pMem += 4;
88 size--;
89
90 // eeuser 7.2.2. GIFtag: "... when NLOOP is 0, the GIF does not output anything, and
91 // values other than the EOP field are disregarded."
92 if (path->nloop > 0)
93 {
94 gs.q = 1.0f;
95
96 if (path->tag.PRE && (path->tag.FLG == GIF_FLG_PACKED))
97 {
98 u32 tagprim = path->tag.PRIM;
99 GIFRegHandlerPRIM((u32*)&tagprim);
100 }
101 }
102 }
103 else
104 {
105 switch (path->mode)
106 {
107 case GIF_FLG_PACKED:
108 {
109 // Needs to be looked at.
110
111 // first try a shortcut for a very common case
112
113 if (path->adonly && size >= path->nloop)
114 {
115 size -= path->nloop;
116
117 do
118 {
119 GIFPackedRegHandlerA_D(pMem);
120
121 pMem += 4; //sizeof(GIFPackedReg)/4;
122 }
123 while(--path->nloop > 0);
124 break;
125 }
126
127 do
128 {
129 u32 reg = path->GetReg();
130 g_GIFPackedRegHandlers[reg](pMem);
131
132 pMem += 4; //sizeof(GIFPackedReg)/4;
133 size--;
134 }
135 while (path->StepReg() && (size > 0));
136
137 break;
138 }
139
140 case GIF_FLG_REGLIST:
141 {
142 // Needs to be looked at.
143 //ZZLog::GS_Log("%8.8x%8.8x %d L", ((u32*)&gs.regs)[1], *(u32*)&gs.regs, path->tag.nreg/4);
144
145 size *= 2;
146
147 do
148 {
149 g_GIFRegHandlers[path->GetReg()](pMem);
150
151 pMem += 2;
152 size--;
153 }
154 while (path->StepReg() && (size > 0));
155
156 if (size & 1) pMem += 2;
157 size /= 2;
158 break;
159 }
160
161 case GIF_FLG_IMAGE: // FROM_VFRAM
162 case GIF_FLG_IMAGE2: // Used in the DirectX version, so we'll use it here too.
163 {
164 int len = min(size, path->nloop);
165 //ZZLog::Error_Log("GIF_FLG_IMAGE(%d)=%d", gs.imageTransfer, len);
166
167 switch (gs.imageTransfer)
168 {
169 case 0:
170 TransferHostLocal(pMem, len * 4);
171 break;
172
173 case 1:
174 // This can't happen; downloads can not be started or performed as part of
175 // a GIFtag operation. They're an entirely separate process that can only be
176 // done through the ReverseFIFO transfer (aka ReadFIFO). --air
177 assert(0);
178 //TransferLocalHost(pMem, len);
179 break;
180
181 case 2:
182 //TransferLocalLocal();
183 break;
184
185 case 3:
186 //assert(0);
187 break;
188
189 default:
190 //assert(0);
191 break;
192 }
193
194 pMem += len * 4;
195
196 path->nloop -= len;
197 size -= len;
198
199 break;
200 }
201
202 default: // GIF_IMAGE
203 ZZLog::GS_Log("*** WARNING **** Unexpected GIFTag flag.");
204 assert(0);
205 path->nloop = 0;
206 break;
207 }
208 }
209
210 if (index == 0)
211 {
212 if (path->tag.EOP && path->nloop == 0)
213 {
214 break;
215 }
216 }
217 }
218
219 // This is the case when not all data was readed from one try: VU1 has too much data.
220 // So we should redo reading from the start.
221 if (index == 0)
222 {
223 if (size == 0 && path->nloop > 0)
224 {
225 if (g_GSMultiThreaded)
226 {
227 path->nloop = 0;
228 }
229 else
230 {
231 _GSgifTransfer<0>(pMem - 0x4000, 0x4000 / 16);
232 }
233 }
234 }
235 }
236
237 void CALLBACK GSgifTransfer1(u32 *pMem, u32 addr)
238 {
239 FUNCLOG
240
241 //ZZLog::GS_Log("GSgifTransfer1 0x%x (mode %d).", addr, path->mode);
242
243 #ifdef _DEBUG
244 ZZLog::Prim_Log("count: %d\n", count);
245 count++;
246 #endif
247
248 _GSgifTransfer<0>((u32*)((u8*)pMem + addr), (0x4000 - addr) / 16);
249 }
250
251 void CALLBACK GSgifTransfer2(u32 *pMem, u32 size)
252 {
253 FUNCLOG
254
255 //ZZLog::GS_Log("GSgifTransfer2 size = %lx (mode %d, gs.path2.tag.nloop = %d).", size, gs.path[1].mode, gs.path[1].tag.nloop);
256
257 _GSgifTransfer<1>(const_cast<u32*>(pMem), size);
258 }
259
260 void CALLBACK GSgifTransfer3(u32 *pMem, u32 size)
261 {
262 FUNCLOG
263
264 //ZZLog::GS_Log("GSgifTransfer3 size = %lx (mode %d, gs.path3.tag.nloop = %d).", size, gs.path[2].mode, gs.path[2].tag.nloop);
265
266 _GSgifTransfer<2>(const_cast<u32*>(pMem), size);
267 }
268
269 void CALLBACK GSgifTransfer(const u32 *pMem, u32 size)
270 {
271 FUNCLOG
272
273 //ZZLog::GS_Log("GSgifTransfer3 size = %lx (mode %d, gs.path3.tag.nloop = %d).", size, gs.path[2].mode, gs.path[2].tag.nloop);
274
275 _GSgifTransfer<3>(pMem, size);
276 }
277
278 void InitPath()
279 {
280 gs.path[0].mode = gs.path[1].mode = gs.path[2].mode = gs.path[3].mode = 0;
281 }
282

  ViewVC Help
Powered by ViewVC 1.1.22