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

Contents of /trunk/plugins/zzogl-pg/opengl/Regs.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: 28556 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 "Regs.h"
23 #include "PS2Etypes.h"
24
25 #include "targets.h"
26 #include "ZZoglVB.h"
27 #include "ZZoglDrawing.h"
28
29 #ifdef USE_OLD_REGS
30
31 #ifdef _MSC_VER
32 #pragma warning(disable:4244)
33 #endif
34
35 GIFRegHandler g_GIFPackedRegHandlers[16];
36 GIFRegHandler g_GIFRegHandlers[256];
37 GIFRegHandler g_GIFTempRegHandlers[16] = {0};
38
39 // values for keeping track of changes
40 u32 s_uTex1Data[2][2] = {{0, }};
41 u32 s_uClampData[2] = {0, };
42
43 //u32 results[65535] = {0, };
44
45 // Note that not all the registers are currently handled, even if they write values out.
46 // For reference, I'm starting a list of unhandled flags here. I'm sure I missed some,
47 // so feel free to add to this, or remove ones that are handled that I missed.
48 // Cases where these values are set would be useful, too.
49 //
50 // In GIFRegHandlerFOG, I don't see gs.vertexregs.f being used anywhere afterwards.
51 // GIFRegHandlerTEX1 doesn't look like anything other then mmag and mmin are handled.
52 // This includes:
53 // lcm - the lod (level of detail) calculation method. If 0, it's (log2(1/|Q|)<<L)+K), whereas if it is one, it's just K.
54 // mxl - This is what MIPMAP level we use. The default is 0, and any other level uses miptbp0 & 1 to get the texture width.
55 // mtba - this is the base address specification for MIPMAP level 1+.
56 // l - Yeah, this is for the LOD calculation.
57 // k - This too.
58 // This largely sums up as that we don't support MIPMAP level 1+ (much like GSdx), and LOD.
59 //
60 // In GIFRegHandlerSCANMSK, it doesn't look like gs.smask is used, though it may have been in the old resolve code.
61 // Lets see: 00 is normal drawing, 01 is reserved, 10 prohibits drawing to even y coords, and 11 prohibits drawing to odd y coords.
62 //
63 // In GIFRegHandlerMIPTBP1 & 2, both miptbp0 & miptbp1 look unused, which isn't suprising, given mxl not being checked.
64 //
65 // GIFRegHandlerDIMX doesn't even have any code in it!
66 // This is supposed to read in the matrix for dithering.
67 //
68 // In GIFRegHandlerDTHE, nothing is done with gs.dthe.
69 // This goes right with the last one, because dthe is set to 1 when dithering with the dthe matrix.
70
71 // In GIFRegHandlerCOLCLAMP, gs.colclamp is not used.
72 // This is color clamping on the RGB value. If it's 0, it is set to mask, the lower 8 bits are enabled, and it wraps around. At 1, it is clamped from 0-255.
73
74 //#define SPAM_UNUSED_REGISTERS
75 #ifdef SPAM_UNUSED_REGISTERS
76 #define REG_LOG ZZLog::Error_Log
77 #else
78 #define REG_LOG 0 &&
79 #endif
80
81 void __gifCall GIFPackedRegHandlerNull(const u32* data)
82 {
83 FUNCLOG
84 ZZLog::Debug_Log("Unexpected packed reg handler %8.8lx_%8.8lx %x.", data[0], data[1], data[2]);
85 }
86
87 // All these just call their non-packed equivalent.
88 void __gifCall GIFPackedRegHandlerPRIM(const u32* data) { GIFRegHandlerPRIM(data); }
89
90 template <u32 ctxt>
91 void __gifCall GIFPackedRegHandlerTEX0(const u32* data) { GIFRegHandlerTEX0<ctxt>(data); }
92
93 template <u32 ctxt>
94 void __gifCall GIFPackedRegHandlerCLAMP(const u32* data) { GIFRegHandlerCLAMP<ctxt>(data); }
95
96 void __gifCall GIFPackedRegHandlerXYZF3(const u32* data) { GIFRegHandlerXYZF3(data); }
97 void __gifCall GIFPackedRegHandlerXYZ3(const u32* data) { GIFRegHandlerXYZ3(data); }
98
99 void __gifCall GIFPackedRegHandlerRGBA(const u32* data)
100 {
101 FUNCLOG
102 gs.rgba = (data[0] & 0xff) |
103 ((data[1] & 0xff) << 8) |
104 ((data[2] & 0xff) << 16) |
105 ((data[3] & 0xff) << 24);
106 gs.vertexregs.rgba = gs.rgba;
107 gs.vertexregs.q = gs.q;
108 }
109
110 void __gifCall GIFPackedRegHandlerSTQ(const u32* data)
111 {
112 FUNCLOG
113 // Despite this code generating a warning, it's correct. float -> float reduction. S and Y are missed mantissas.
114 *(u32*)&gs.vertexregs.s = data[0] & 0xffffff00;
115 *(u32*)&gs.vertexregs.t = data[1] & 0xffffff00;
116 *(u32*)&gs.q = data[2];
117 }
118
119 void __gifCall GIFPackedRegHandlerUV(const u32* data)
120 {
121 FUNCLOG
122 gs.vertexregs.u = data[0] & 0x3fff;
123 gs.vertexregs.v = data[1] & 0x3fff;
124 }
125
126 void __gifCall GIFPackedRegHandlerXYZF2(const u32* data)
127 {
128 FUNCLOG
129 GIFPackedXYZF2* r = (GIFPackedXYZF2*)(data);
130 gs.add_vertex(r->X, r->Y,r->Z, r->F);
131
132 ZZKick->KickVertex(((data[3]>>15) & 0x1));
133 }
134
135 void __gifCall GIFPackedRegHandlerXYZ2(const u32* data)
136 {
137 FUNCLOG
138 GIFPackedXYZ2* r = (GIFPackedXYZ2*)(data);
139 gs.add_vertex(r->X, r->Y,r->Z);
140
141 ZZKick->KickVertex(((data[3]>>15) & 0x1));
142 }
143
144 void __gifCall GIFPackedRegHandlerFOG(const u32* data)
145 {
146 FUNCLOG
147 gs.vertexregs.f = (data[3] & 0xff0) >> 4;
148 if (gs.vertexregs.f != 0) REG_LOG("GIFPackedRegHandlerFOG == %d", gs.vertexregs.f);
149 }
150
151 void __gifCall GIFPackedRegHandlerA_D(const u32* data)
152 {
153 FUNCLOG
154
155 if ((data[2] & 0xff) < 100)
156 g_GIFRegHandlers[data[2] & 0xff](data);
157 else
158 GIFRegHandlerNull(data);
159 }
160
161 void __gifCall GIFPackedRegHandlerNOP(const u32* data)
162 {
163 FUNCLOG
164 }
165
166 void __gifCall GIFRegHandlerNull(const u32* data)
167 {
168 FUNCLOG
169 #ifdef _DEBUG
170
171 if ((((uptr)&data[2])&0xffff) == 0) return;
172
173 // 0x7f happens on a lot of games
174 if (data[2] != 0x7f && (data[0] || data[1]))
175 {
176 ZZLog::Debug_Log("Unexpected reg handler %x %x %x.", data[0], data[1], data[2]);
177 }
178
179 #endif
180 }
181
182 void __gifCall GIFRegHandlerPRIM(const u32 *data)
183 {
184 FUNCLOG
185
186 //if (data[0] & ~0x3ff)
187 //{
188 //ZZLog::Warn_Log("Warning: unknown bits in prim %8.8lx_%8.8lx", data[1], data[0]);
189 //}
190
191
192 gs.primC = 0;
193 u16 prim_type = (data[0]) & 0x7;
194 prim->prim = prim_type;
195 gs._prim[0].prim = prim_type;
196 gs._prim[1].prim = prim_type;
197 gs._prim[1]._val = (data[0] >> 3) & 0xff;
198
199 gs.new_tri_fan = !(prim_type ^ PRIM_TRIANGLE_FAN);
200 ZZKick->DirtyValidPrevPrim();
201
202 Prim();
203 }
204
205 void __gifCall GIFRegHandlerRGBAQ(const u32* data)
206 {
207 FUNCLOG
208 gs.rgba = data[0];
209 gs.vertexregs.rgba = data[0];
210 *(u32*)&gs.vertexregs.q = data[1];
211 }
212
213 void __gifCall GIFRegHandlerST(const u32* data)
214 {
215 FUNCLOG
216 *(u32*)&gs.vertexregs.s = data[0] & 0xffffff00;
217 *(u32*)&gs.vertexregs.t = data[1] & 0xffffff00;
218 //*(u32*)&gs.q = data[2];
219 }
220
221 void __gifCall GIFRegHandlerUV(const u32* data)
222 {
223 FUNCLOG
224 gs.vertexregs.u = (data[0]) & 0x3fff;
225 gs.vertexregs.v = (data[0] >> 16) & 0x3fff;
226 }
227
228 void __gifCall GIFRegHandlerXYZF2(const u32* data)
229 {
230 FUNCLOG
231 GIFRegXYZF* r = (GIFRegXYZF*)(data);
232 gs.add_vertex(r->X, r->Y,r->Z, r->F);
233
234 ZZKick->KickVertex(false);
235 }
236
237 void __gifCall GIFRegHandlerXYZ2(const u32* data)
238 {
239 FUNCLOG
240 GIFRegXYZ* r = (GIFRegXYZ*)(data);
241 gs.add_vertex(r->X, r->Y,r->Z);
242
243 ZZKick->KickVertex(false);
244 }
245
246 template <u32 ctxt>
247 void __gifCall GIFRegHandlerTEX0(const u32* data)
248 {
249 FUNCLOG
250
251 if (!NoHighlights(ctxt)) return;
252
253 u32 psm = ZZOglGet_psm_TexBitsFix(data[0]);
254
255 if (m_Blocks[psm].bpp == 0)
256 {
257 // kh and others
258 return;
259 }
260
261 vb[ctxt].uNextTex0Data[0] = data[0];
262 vb[ctxt].uNextTex0Data[1] = data[1];
263 vb[ctxt].bNeedTexCheck = 1;
264
265 // don't update unless necessary
266
267 if (PSMT_ISCLUT(psm))
268 {
269 if (CheckChangeInClut(data[1], psm))
270 {
271 // loading clut, so flush whole texture
272 vb[ctxt].FlushTexData();
273 }
274
275 // check if csa is the same!! (ffx bisaid island, grass)
276 else if ((data[1] & CPSM_CSA_BITMASK) != (vb[ctxt].uCurTex0Data[1] & CPSM_CSA_BITMASK))
277 {
278 Flush(ctxt); // flush any previous entries
279 }
280 }
281 }
282
283 template <u32 ctxt>
284 void __gifCall GIFRegHandlerCLAMP(const u32* data)
285 {
286 FUNCLOG
287
288 if (!NoHighlights(ctxt)) return;
289
290 clampInfo& clamp = vb[ctxt].clamp;
291
292 if ((s_uClampData[ctxt] != data[0]) || (((clamp.minv >> 8) | (clamp.maxv << 2)) != (data[1]&0x0fff)))
293 {
294 Flush(ctxt);
295 s_uClampData[ctxt] = data[0];
296
297 clamp.wms = (data[0]) & 0x3;
298 clamp.wmt = (data[0] >> 2) & 0x3;
299 clamp.minu = (data[0] >> 4) & 0x3ff;
300 clamp.maxu = (data[0] >> 14) & 0x3ff;
301 clamp.minv = ((data[0] >> 24) & 0xff) | ((data[1] & 0x3) << 8);
302 clamp.maxv = (data[1] >> 2) & 0x3ff;
303
304 vb[ctxt].bTexConstsSync = false;
305 }
306 }
307
308 void __gifCall GIFRegHandlerFOG(const u32* data)
309 {
310 FUNCLOG
311 //gs.gsvertex[gs.primIndex].f = (data[1] >> 24); // shift to upper bits
312 gs.vertexregs.f = data[1] >> 24;
313 if (gs.vertexregs.f != 0) REG_LOG("GIFPackedRegHandlerFOG == %d", gs.vertexregs.f);
314
315 }
316
317 void __gifCall GIFRegHandlerXYZF3(const u32* data)
318 {
319 FUNCLOG
320 GIFRegXYZF* r = (GIFRegXYZF*)(data);
321 gs.add_vertex(r->X, r->Y,r->Z, r->F);
322
323 ZZKick->KickVertex(true);
324 }
325
326 void __gifCall GIFRegHandlerXYZ3(const u32* data)
327 {
328 FUNCLOG
329 GIFRegXYZ* r = (GIFRegXYZ*)(data);
330 gs.add_vertex(r->X, r->Y,r->Z);
331
332 ZZKick->KickVertex(true);
333 }
334
335 void __gifCall GIFRegHandlerNOP(const u32* data)
336 {
337 FUNCLOG
338 }
339
340 template <u32 ctxt>
341 void __gifCall GIFRegHandlerTEX1(const u32* data)
342 {
343 FUNCLOG
344
345 if (!NoHighlights(ctxt)) return;
346
347 tex1Info& tex1 = vb[ctxt].tex1;
348
349 if (conf.bilinear == 1 && (tex1.mmag != ((data[0] >> 5) & 0x1) || tex1.mmin != ((data[0] >> 6) & 0x7)))
350 {
351 Flush(ctxt);
352 vb[ctxt].bVarsTexSync = false;
353 }
354
355 tex1.lcm = (data[0]) & 0x1;
356 tex1.mxl = (data[0] >> 2) & 0x7;
357 tex1.mmag = (data[0] >> 5) & 0x1;
358 tex1.mmin = (data[0] >> 6) & 0x7;
359 tex1.mtba = (data[0] >> 9) & 0x1;
360 tex1.l = (data[0] >> 19) & 0x3;
361 tex1.k = (data[1] >> 4) & 0xff;
362
363 #ifdef SPAM_UNUSED_REGISTERS
364 REG_LOG("Lcm = %d, l = %d, k = %d", tex1.lcm, tex1.l, tex1.k);
365 if (tex1.mxl != 0) REG_LOG("MIPMAP level set to %d, which is unsupported.");
366 #endif
367 }
368
369 template <u32 ctxt>
370 void __gifCall GIFRegHandlerTEX2(const u32* data)
371 {
372 FUNCLOG
373
374 tex0Info& tex0 = vb[ctxt].tex0;
375
376 vb[ctxt].FlushTexData();
377
378 u32 psm = ZZOglGet_psm_TexBitsFix(data[0]);
379
380 u32* s_uTex0Data = vb[ctxt].uCurTex0Data;
381
382 // don't update unless necessary
383 // if( ZZOglGet_psm_TexBitsFix(*s_uTex0Data) == ZZOglGet_psm_TexBitsFix(data[0]) ) { // psm is the same
384 if (ZZOglAllExceptClutIsSame(s_uTex0Data, data))
385 {
386 if (!PSMT_ISCLUT(psm)) return;
387
388 // have to write the CLUT again if changed
389 if (ZZOglClutMinusCLDunchanged(s_uTex0Data, data))
390 {
391 tex0.cld = ZZOglGet_cld_TexBits(data[1]);
392
393 if (tex0.cld != 0)
394 {
395 texClutWrite(ctxt);
396 // invalidate to make sure target didn't change!
397 vb[ctxt].bVarsTexSync = false;
398 }
399
400 return;
401 }
402 }
403
404 Flush(ctxt);
405
406 vb[ctxt].bVarsTexSync = false;
407 vb[ctxt].bTexConstsSync = false;
408
409 s_uTex0Data[0] = (s_uTex0Data[0] & ~0x03f00000) | (psm << 20);
410 s_uTex0Data[1] = (s_uTex0Data[1] & 0x1f) | (data[1] & ~0x1f);
411
412 tex0.psm = ZZOglGet_psm_TexBitsFix(data[0]);
413
414 if (PSMT_ISCLUT(tex0.psm)) CluttingForFlushedTex(&tex0, data[1], ctxt);
415 }
416
417 template <u32 ctxt>
418 void __gifCall GIFRegHandlerXYOFFSET(const u32* data)
419 {
420 FUNCLOG
421 vb[ctxt].offset.x = (data[0]) & 0xffff;
422 vb[ctxt].offset.y = (data[1]) & 0xffff;
423
424 // if( !conf.interlace ) {
425 // vb[1].offset.x &= ~15;
426 // vb[1].offset.y &= ~15;
427 // }
428 }
429
430 void __gifCall GIFRegHandlerPRMODECONT(const u32* data)
431 {
432 FUNCLOG
433 gs.prac = data[0] & 0x1;
434 prim = &gs._prim[gs.prac];
435
436 Prim();
437 }
438
439 void __gifCall GIFRegHandlerPRMODE(const u32* data)
440 {
441 FUNCLOG
442 gs._prim[0]._val = (data[0] >> 3) & 0xff;
443
444 if (gs.prac == 0) Prim();
445 }
446
447 void __gifCall GIFRegHandlerTEXCLUT(const u32* data)
448 {
449 FUNCLOG
450
451 vb[0].FlushTexData();
452 vb[1].FlushTexData();
453
454 gs.clut.cbw = ((data[0]) & 0x3f) * 64;
455 gs.clut.cou = ((data[0] >> 6) & 0x3f) * 16;
456 gs.clut.cov = (data[0] >> 12) & 0x3ff;
457 }
458
459 void __gifCall GIFRegHandlerSCANMSK(const u32* data)
460 {
461 FUNCLOG
462 // FlushBoth();
463 // ResolveC(&vb[0]);
464 // ResolveZ(&vb[0]);
465
466 gs.smask = data[0] & 0x3;
467 REG_LOG("Scanmsk == %d", gs.smask);
468 }
469
470 template <u32 ctxt>
471 void __gifCall GIFRegHandlerMIPTBP1(const u32* data)
472 {
473 FUNCLOG
474 miptbpInfo& miptbp0 = vb[ctxt].miptbp0;
475 miptbp0.tbp[0] = (data[0]) & 0x3fff;
476 miptbp0.tbw[0] = (data[0] >> 14) & 0x3f;
477 miptbp0.tbp[1] = ((data[0] >> 20) & 0xfff) | ((data[1] & 0x3) << 12);
478 miptbp0.tbw[1] = (data[1] >> 2) & 0x3f;
479 miptbp0.tbp[2] = (data[1] >> 8) & 0x3fff;
480 miptbp0.tbw[2] = (data[1] >> 22) & 0x3f;
481 #ifdef SPAM_UNUSED_REGISTERS
482 if ((miptbp0.tbp[0] != 0) || (miptbp0.tbp[1] != 0) || (miptbp0.tbp[2] != 0))
483 {
484 REG_LOG("MIPTBP1: 0:%d(%d) 1:%d(%d) 2:%d(%d).", \
485 miptbp0.tbp[0], miptbp0.tbw[0], miptbp0.tbp[1], miptbp0.tbw[1], miptbp0.tbp[2], miptbp0.tbw[2]);
486 }
487 #endif
488 }
489
490 template <u32 ctxt>
491 void __gifCall GIFRegHandlerMIPTBP2(const u32* data)
492 {
493 FUNCLOG
494 miptbpInfo& miptbp1 = vb[ctxt].miptbp1;
495 miptbp1.tbp[0] = (data[0]) & 0x3fff;
496 miptbp1.tbw[0] = (data[0] >> 14) & 0x3f;
497 miptbp1.tbp[1] = ((data[0] >> 20) & 0xfff) | ((data[1] & 0x3) << 12);
498 miptbp1.tbw[1] = (data[1] >> 2) & 0x3f;
499 miptbp1.tbp[2] = (data[1] >> 8) & 0x3fff;
500 miptbp1.tbw[2] = (data[1] >> 22) & 0x3f;
501 #ifdef SPAM_UNUSED_REGISTERS
502 if ((miptbp1.tbp[0] != 0) || (miptbp1.tbp[1] != 0) || (miptbp1.tbp[2] != 0))
503 {
504 REG_LOG("MIPTBP2: 0:%d(%d) 1:%d(%d) 2:%d(%d).", \
505 miptbp1.tbp[0], miptbp1.tbw[0], miptbp1.tbp[1], miptbp1.tbw[1], miptbp1.tbp[2], miptbp1.tbw[2]);
506 }
507 #endif
508 }
509
510 void __gifCall GIFRegHandlerTEXA(const u32* data)
511 {
512 FUNCLOG
513 texaInfo newinfo;
514 newinfo.aem = (data[0] >> 15) & 0x1;
515 newinfo.ta[0] = data[0] & 0xff;
516 newinfo.ta[1] = data[1] & 0xff;
517
518 if (*(u32*)&newinfo != *(u32*)&gs.texa)
519 {
520 FlushBoth();
521
522 *(u32*)&gs.texa = *(u32*) & newinfo;
523
524 gs.texa.fta[0] = newinfo.ta[0] / 255.0f;
525 gs.texa.fta[1] = newinfo.ta[1] / 255.0f;
526
527 vb[0].bTexConstsSync = false;
528 vb[1].bTexConstsSync = false;
529 }
530 }
531
532 void __gifCall GIFRegHandlerFOGCOL(const u32* data)
533 {
534 FUNCLOG
535 SetFogColor(data[0]&0xffffff);
536 }
537
538 void __gifCall GIFRegHandlerTEXFLUSH(const u32* data)
539 {
540 FUNCLOG
541 SetTexFlush();
542 }
543
544 template <u32 ctxt>
545 void __gifCall GIFRegHandlerSCISSOR(const u32* data)
546 {
547 FUNCLOG
548 Rect2& scissor = vb[ctxt].scissor;
549 Rect2 newscissor;
550
551 newscissor.x0 = ((data[0]) & 0x7ff) << 3;
552 newscissor.x1 = ((data[0] >> 16) & 0x7ff) << 3;
553 newscissor.y0 = ((data[1]) & 0x7ff) << 3;
554 newscissor.y1 = ((data[1] >> 16) & 0x7ff) << 3;
555
556 if (newscissor.x1 != scissor.x1 || newscissor.y1 != scissor.y1 ||
557 newscissor.x0 != scissor.x0 || newscissor.y0 != scissor.y0)
558 {
559 Flush(ctxt);
560 scissor = newscissor;
561
562 // flush everything
563 vb[ctxt].bNeedFrameCheck = 1;
564 }
565 }
566
567 template <u32 ctxt>
568 void __gifCall GIFRegHandlerALPHA(const u32* data)
569 {
570 FUNCLOG
571 alphaInfo newalpha;
572 newalpha.abcd = *(u8*)data;
573 newalpha.fix = *(u8*)(data + 1);
574
575 if (*(u16*)&newalpha != *(u16*)&vb[ctxt].alpha)
576 {
577 Flush(ctxt);
578
579 if (newalpha.a == 3) newalpha.a = 0;
580 if (newalpha.b == 3) newalpha.b = 0;
581 if (newalpha.c == 3) newalpha.c = 0;
582 if (newalpha.d == 3) newalpha.d = 0;
583
584 *(u16*)&vb[ctxt].alpha = *(u16*) & newalpha;
585 }
586 }
587
588 void __gifCall GIFRegHandlerDIMX(const u32* data)
589 {
590 FUNCLOG
591 }
592
593 void __gifCall GIFRegHandlerDTHE(const u32* data)
594 {
595 FUNCLOG
596 gs.dthe = data[0] & 0x1;
597 if (gs.dthe != 0) REG_LOG("Dithering set. (but not implemented.)");
598 }
599
600 void __gifCall GIFRegHandlerCOLCLAMP(const u32* data)
601 {
602 FUNCLOG
603 gs.colclamp = data[0] & 0x1;
604 if (gs.colclamp == 0)
605 REG_LOG("COLCLAMP == MASK");
606 else
607 REG_LOG("COLCLAMP == CLAMP");
608 }
609
610 template <u32 ctxt>
611 void __gifCall GIFRegHandlerTEST(const u32* data)
612 {
613 FUNCLOG
614
615 pixTest* test = &vb[ctxt].test;
616
617 if ((*(u32*)test & 0x0007ffff) == (data[0] & 0x0007ffff)) return;
618
619 Flush(ctxt);
620
621 *(u32*)test = data[0];
622
623 // test.ate = (data[0] ) & 0x1;
624 // test.atst = (data[0] >> 1) & 0x7;
625 // test.aref = (data[0] >> 4) & 0xff;
626 // test.afail = (data[0] >> 12) & 0x3;
627 // test.date = (data[0] >> 14) & 0x1;
628 // test.datm = (data[0] >> 15) & 0x1;
629 // test.zte = (data[0] >> 16) & 0x1;
630 // test.ztst = (data[0] >> 17) & 0x3;
631 }
632
633 void __gifCall GIFRegHandlerPABE(const u32* data)
634 {
635 FUNCLOG
636 //SetAlphaChanged(0, GPUREG_PABE);
637 //SetAlphaChanged(1, GPUREG_PABE);
638 FlushBoth();
639
640 gs.pabe = *data & 0x1;
641 }
642
643 template <u32 ctxt>
644 void __gifCall GIFRegHandlerFBA(const u32* data)
645 {
646 FUNCLOG
647
648 FlushBoth();
649
650 vb[ctxt].fba.fba = *data & 0x1;
651 }
652
653 template <u32 ctxt>
654 void __gifCall GIFRegHandlerFRAME(const u32* data)
655 {
656 FUNCLOG
657
658 frameInfo& gsfb = vb[ctxt].gsfb;
659
660 if ((gsfb.fbp == ZZOglGet_fbp_FrameBitsMult(data[0])) &&
661 (gsfb.fbw == ZZOglGet_fbw_FrameBitsMult(data[0])) &&
662 (gsfb.psm == ZZOglGet_psm_FrameBits(data[0])) &&
663 (gsfb.fbm == ZZOglGet_fbm_FrameBits(data[0])))
664 {
665 return;
666 }
667
668 FlushBoth();
669
670 gsfb.fbp = ZZOglGet_fbp_FrameBitsMult(data[0]);
671 gsfb.fbw = ZZOglGet_fbw_FrameBitsMult(data[0]);
672 gsfb.psm = ZZOglGet_psm_FrameBits(data[0]);
673 gsfb.fbm = ZZOglGet_fbm_FrameBitsFix(data[0], data[1]);
674 gsfb.fbh = ZZOglGet_fbh_FrameBitsCalc(data[0]);
675 // gsfb.fbhCalc = gsfb.fbh;
676
677 vb[ctxt].bNeedFrameCheck = 1;
678 }
679
680 template <u32 ctxt>
681 void __gifCall GIFRegHandlerZBUF(const u32* data)
682 {
683 FUNCLOG
684 zbufInfo& zbuf = vb[ctxt].zbuf;
685
686 int psm = (0x30 | ((data[0] >> 24) & 0xf));
687
688 if (zbuf.zbp == (data[0] & 0x1ff) * 32 &&
689 zbuf.psm == psm &&
690 zbuf.zmsk == (data[1] & 0x1))
691 {
692 return;
693 }
694
695 // error detection
696 if (m_Blocks[psm].bpp == 0) return;
697
698 FlushBoth();
699
700 zbuf.zbp = (data[0] & 0x1ff) * 32;
701 zbuf.psm = 0x30 | ((data[0] >> 24) & 0xf);
702 zbuf.zmsk = data[1] & 0x1;
703
704 vb[ctxt].bNeedZCheck = 1;
705 vb[ctxt].zprimmask = 0xffffffff;
706
707 if (zbuf.psm > 0x31) vb[ctxt].zprimmask = 0xffff;
708 }
709
710 void __gifCall GIFRegHandlerBITBLTBUF(const u32* data)
711 {
712 FUNCLOG
713 gs.srcbufnew.bp = ((data[0]) & 0x3fff); // * 64;
714 gs.srcbufnew.bw = ((data[0] >> 16) & 0x3f) * 64;
715 gs.srcbufnew.psm = (data[0] >> 24) & 0x3f;
716 gs.dstbufnew.bp = ((data[1]) & 0x3fff); // * 64;
717 gs.dstbufnew.bw = ((data[1] >> 16) & 0x3f) * 64;
718 gs.dstbufnew.psm = (data[1] >> 24) & 0x3f;
719
720 if (gs.dstbufnew.bw == 0) gs.dstbufnew.bw = 64;
721 }
722
723 void __gifCall GIFRegHandlerTRXPOS(const u32* data)
724 {
725 FUNCLOG
726
727 gs.trxposnew.sx = (data[0]) & 0x7ff;
728 gs.trxposnew.sy = (data[0] >> 16) & 0x7ff;
729 gs.trxposnew.dx = (data[1]) & 0x7ff;
730 gs.trxposnew.dy = (data[1] >> 16) & 0x7ff;
731 gs.trxposnew.dir = (data[1] >> 27) & 0x3;
732 }
733
734 void __gifCall GIFRegHandlerTRXREG(const u32* data)
735 {
736 FUNCLOG
737 gs.imageWtemp = data[0] & 0xfff;
738 gs.imageHtemp = data[1] & 0xfff;
739 }
740
741 void __gifCall GIFRegHandlerTRXDIR(const u32* data)
742 {
743 FUNCLOG
744 // terminate any previous transfers
745
746 switch (gs.imageTransfer)
747 {
748
749 case 0: // host->loc
750 TerminateHostLocal();
751 break;
752
753 case 1: // loc->host
754 TerminateLocalHost();
755 break;
756 }
757
758 gs.srcbuf = gs.srcbufnew;
759
760 gs.dstbuf = gs.dstbufnew;
761 gs.trxpos = gs.trxposnew;
762 gs.imageTransfer = data[0] & 0x3;
763 gs.imageWnew = gs.imageWtemp;
764 gs.imageHnew = gs.imageHtemp;
765
766 if (gs.imageWnew > 0 && gs.imageHnew > 0)
767 {
768 switch (gs.imageTransfer)
769 {
770 case 0: // host->loc
771 InitTransferHostLocal();
772 break;
773
774 case 1: // loc->host
775 InitTransferLocalHost();
776 break;
777
778 case 2:
779 TransferLocalLocal();
780 break;
781
782 case 3:
783 gs.imageTransfer = -1;
784 break;
785
786 default:
787 assert(0);
788 }
789 }
790 else
791 {
792 #if defined(ZEROGS_DEVBUILD)
793 ZZLog::Warn_Log("Dummy transfer.");
794 #endif
795 gs.imageTransfer = -1;
796 }
797 }
798
799 void __gifCall GIFRegHandlerHWREG(const u32* data)
800 {
801 FUNCLOG
802
803 if (gs.imageTransfer == 0)
804 {
805 TransferHostLocal(data, 2);
806 }
807 else
808 {
809 #if defined(ZEROGS_DEVBUILD)
810 ZZLog::Error_Log("ZeroGS: HWREG!? %8.8x_%8.8x", data[0], data[1]);
811 //assert(0);
812 #endif
813 }
814 }
815
816 extern int g_GSMultiThreaded;
817
818 void __gifCall GIFRegHandlerSIGNAL(const u32* data)
819 {
820 FUNCLOG
821
822 if (!g_GSMultiThreaded)
823 {
824 SIGLBLID->SIGID = (SIGLBLID->SIGID & ~data[1]) | (data[0] & data[1]);
825
826 // if (gs.CSRw & 0x1) CSR->SIGNAL = 1;
827 // if (!IMR->SIGMSK && GSirq)
828 // GSirq();
829
830 if (gs.CSRw & 0x1)
831 {
832 CSR->SIGNAL = 1;
833 //gs.CSRw &= ~1;
834 }
835
836 if (!IMR->SIGMSK && GSirq) GSirq();
837 }
838 }
839
840 void __gifCall GIFRegHandlerFINISH(const u32* data)
841 {
842 FUNCLOG
843
844 if (!g_GSMultiThreaded)
845 {
846 if (gs.CSRw & 0x2) CSR->FINISH = 1;
847
848 if (!IMR->FINISHMSK && GSirq) GSirq();
849
850 // if( gs.CSRw & 2 ) {
851 // //gs.CSRw &= ~2;
852 // //CSR->FINISH = 0;
853 //
854 //
855 // }
856 // CSR->FINISH = 1;
857 //
858 // if( !IMR->FINISHMSK && GSirq )
859 // GSirq();
860 }
861 }
862
863 void __gifCall GIFRegHandlerLABEL(const u32* data)
864 {
865 FUNCLOG
866
867 if (!g_GSMultiThreaded)
868 {
869 SIGLBLID->LBLID = (SIGLBLID->LBLID & ~data[1]) | (data[0] & data[1]);
870 }
871 }
872
873
874 void SetMultithreaded()
875 {
876 // Some older versions of PCSX2 didn't properly set the irq callback to NULL
877 // in multithreaded mode (possibly because ZeroGS itself would assert in such
878 // cases), and didn't bind them to a dummy callback either. PCSX2 handles all
879 // IRQs internally when multithreaded anyway -- so let's ignore them here:
880
881 if (g_GSMultiThreaded)
882 {
883 g_GIFRegHandlers[GIF_A_D_REG_SIGNAL] = &GIFRegHandlerNull;
884 g_GIFRegHandlers[GIF_A_D_REG_FINISH] = &GIFRegHandlerNull;
885 g_GIFRegHandlers[GIF_A_D_REG_LABEL] = &GIFRegHandlerNull;
886 }
887 else
888 {
889 g_GIFRegHandlers[GIF_A_D_REG_SIGNAL] = &GIFRegHandlerSIGNAL;
890 g_GIFRegHandlers[GIF_A_D_REG_FINISH] = &GIFRegHandlerFINISH;
891 g_GIFRegHandlers[GIF_A_D_REG_LABEL] = &GIFRegHandlerLABEL;
892 }
893 }
894
895 void ResetRegs()
896 {
897 for (int i = 0; i < 16; i++)
898 {
899 g_GIFPackedRegHandlers[i] = &GIFPackedRegHandlerNull;
900 }
901
902 g_GIFPackedRegHandlers[GIF_REG_PRIM] = &GIFPackedRegHandlerPRIM;
903 g_GIFPackedRegHandlers[GIF_REG_RGBA] = &GIFPackedRegHandlerRGBA;
904 g_GIFPackedRegHandlers[GIF_REG_STQ] = &GIFPackedRegHandlerSTQ;
905 g_GIFPackedRegHandlers[GIF_REG_UV] = &GIFPackedRegHandlerUV;
906 g_GIFPackedRegHandlers[GIF_REG_XYZF2] = &GIFPackedRegHandlerXYZF2;
907 g_GIFPackedRegHandlers[GIF_REG_XYZ2] = &GIFPackedRegHandlerXYZ2;
908 g_GIFPackedRegHandlers[GIF_REG_TEX0_1] = &GIFPackedRegHandlerTEX0<0>;
909 g_GIFPackedRegHandlers[GIF_REG_TEX0_2] = &GIFPackedRegHandlerTEX0<1>;
910 g_GIFPackedRegHandlers[GIF_REG_CLAMP_1] = &GIFPackedRegHandlerCLAMP<0>;
911 g_GIFPackedRegHandlers[GIF_REG_CLAMP_2] = &GIFPackedRegHandlerCLAMP<1>;
912 g_GIFPackedRegHandlers[GIF_REG_FOG] = &GIFPackedRegHandlerFOG;
913 g_GIFPackedRegHandlers[GIF_REG_XYZF3] = &GIFPackedRegHandlerXYZF3;
914 g_GIFPackedRegHandlers[GIF_REG_XYZ3] = &GIFPackedRegHandlerXYZ3;
915 g_GIFPackedRegHandlers[GIF_REG_A_D] = &GIFPackedRegHandlerA_D;
916 g_GIFPackedRegHandlers[GIF_REG_NOP] = &GIFPackedRegHandlerNOP;
917
918 for (int i = 0; i < 256; i++)
919 {
920 g_GIFRegHandlers[i] = &GIFPackedRegHandlerNull;
921 }
922
923 g_GIFRegHandlers[GIF_A_D_REG_PRIM] = &GIFRegHandlerPRIM;
924 g_GIFRegHandlers[GIF_A_D_REG_RGBAQ] = &GIFRegHandlerRGBAQ;
925 g_GIFRegHandlers[GIF_A_D_REG_ST] = &GIFRegHandlerST;
926 g_GIFRegHandlers[GIF_A_D_REG_UV] = &GIFRegHandlerUV;
927 g_GIFRegHandlers[GIF_A_D_REG_XYZF2] = &GIFRegHandlerXYZF2;
928 g_GIFRegHandlers[GIF_A_D_REG_XYZ2] = &GIFRegHandlerXYZ2;
929 g_GIFRegHandlers[GIF_A_D_REG_TEX0_1] = &GIFRegHandlerTEX0<0>;
930 g_GIFRegHandlers[GIF_A_D_REG_TEX0_2] = &GIFRegHandlerTEX0<1>;
931 g_GIFRegHandlers[GIF_A_D_REG_CLAMP_1] = &GIFRegHandlerCLAMP<0>;
932 g_GIFRegHandlers[GIF_A_D_REG_CLAMP_2] = &GIFRegHandlerCLAMP<1>;
933 g_GIFRegHandlers[GIF_A_D_REG_FOG] = &GIFRegHandlerFOG;
934 g_GIFRegHandlers[GIF_A_D_REG_XYZF3] = &GIFRegHandlerXYZF3;
935 g_GIFRegHandlers[GIF_A_D_REG_XYZ3] = &GIFRegHandlerXYZ3;
936 g_GIFRegHandlers[GIF_A_D_REG_NOP] = &GIFRegHandlerNOP;
937 g_GIFRegHandlers[GIF_A_D_REG_TEX1_1] = &GIFRegHandlerTEX1<0>;
938 g_GIFRegHandlers[GIF_A_D_REG_TEX1_2] = &GIFRegHandlerTEX1<1>;
939 g_GIFRegHandlers[GIF_A_D_REG_TEX2_1] = &GIFRegHandlerTEX2<0>;
940 g_GIFRegHandlers[GIF_A_D_REG_TEX2_2] = &GIFRegHandlerTEX2<1>;
941 g_GIFRegHandlers[GIF_A_D_REG_XYOFFSET_1] = &GIFRegHandlerXYOFFSET<0>;
942 g_GIFRegHandlers[GIF_A_D_REG_XYOFFSET_2] = &GIFRegHandlerXYOFFSET<1>;
943 g_GIFRegHandlers[GIF_A_D_REG_PRMODECONT] = &GIFRegHandlerPRMODECONT;
944 g_GIFRegHandlers[GIF_A_D_REG_PRMODE] = &GIFRegHandlerPRMODE;
945 g_GIFRegHandlers[GIF_A_D_REG_TEXCLUT] = &GIFRegHandlerTEXCLUT;
946 g_GIFRegHandlers[GIF_A_D_REG_SCANMSK] = &GIFRegHandlerSCANMSK;
947 g_GIFRegHandlers[GIF_A_D_REG_MIPTBP1_1] = &GIFRegHandlerMIPTBP1<0>;
948 g_GIFRegHandlers[GIF_A_D_REG_MIPTBP1_2] = &GIFRegHandlerMIPTBP1<1>;
949 g_GIFRegHandlers[GIF_A_D_REG_MIPTBP2_1] = &GIFRegHandlerMIPTBP2<0>;
950 g_GIFRegHandlers[GIF_A_D_REG_MIPTBP2_2] = &GIFRegHandlerMIPTBP2<1>;
951 g_GIFRegHandlers[GIF_A_D_REG_TEXA] = &GIFRegHandlerTEXA;
952 g_GIFRegHandlers[GIF_A_D_REG_FOGCOL] = &GIFRegHandlerFOGCOL;
953 g_GIFRegHandlers[GIF_A_D_REG_TEXFLUSH] = &GIFRegHandlerTEXFLUSH;
954 g_GIFRegHandlers[GIF_A_D_REG_SCISSOR_1] = &GIFRegHandlerSCISSOR<0>;
955 g_GIFRegHandlers[GIF_A_D_REG_SCISSOR_2] = &GIFRegHandlerSCISSOR<1>;
956 g_GIFRegHandlers[GIF_A_D_REG_ALPHA_1] = &GIFRegHandlerALPHA<0>;
957 g_GIFRegHandlers[GIF_A_D_REG_ALPHA_2] = &GIFRegHandlerALPHA<1>;
958 g_GIFRegHandlers[GIF_A_D_REG_DIMX] = &GIFRegHandlerDIMX;
959 g_GIFRegHandlers[GIF_A_D_REG_DTHE] = &GIFRegHandlerDTHE;
960 g_GIFRegHandlers[GIF_A_D_REG_COLCLAMP] = &GIFRegHandlerCOLCLAMP;
961 g_GIFRegHandlers[GIF_A_D_REG_TEST_1] = &GIFRegHandlerTEST<0>;
962 g_GIFRegHandlers[GIF_A_D_REG_TEST_2] = &GIFRegHandlerTEST<1>;
963 g_GIFRegHandlers[GIF_A_D_REG_PABE] = &GIFRegHandlerPABE;
964 g_GIFRegHandlers[GIF_A_D_REG_FBA_1] = &GIFRegHandlerFBA<0>;
965 g_GIFRegHandlers[GIF_A_D_REG_FBA_2] = &GIFRegHandlerFBA<1>;
966 g_GIFRegHandlers[GIF_A_D_REG_FRAME_1] = &GIFRegHandlerFRAME<0>;
967 g_GIFRegHandlers[GIF_A_D_REG_FRAME_2] = &GIFRegHandlerFRAME<1>;
968 g_GIFRegHandlers[GIF_A_D_REG_ZBUF_1] = &GIFRegHandlerZBUF<0>;
969 g_GIFRegHandlers[GIF_A_D_REG_ZBUF_2] = &GIFRegHandlerZBUF<1>;
970 g_GIFRegHandlers[GIF_A_D_REG_BITBLTBUF] = &GIFRegHandlerBITBLTBUF;
971 g_GIFRegHandlers[GIF_A_D_REG_TRXPOS] = &GIFRegHandlerTRXPOS;
972 g_GIFRegHandlers[GIF_A_D_REG_TRXREG] = &GIFRegHandlerTRXREG;
973 g_GIFRegHandlers[GIF_A_D_REG_TRXDIR] = &GIFRegHandlerTRXDIR;
974 g_GIFRegHandlers[GIF_A_D_REG_HWREG] = &GIFRegHandlerHWREG;
975 SetMultithreaded();
976 }
977
978 void WriteTempRegs()
979 {
980 memcpy(g_GIFTempRegHandlers, g_GIFPackedRegHandlers, sizeof(g_GIFTempRegHandlers));
981 }
982
983 void SetFrameSkip(bool skip)
984 {
985 if (skip)
986 {
987 g_GIFPackedRegHandlers[GIF_REG_PRIM] = &GIFPackedRegHandlerNOP;
988 g_GIFPackedRegHandlers[GIF_REG_RGBA] = &GIFPackedRegHandlerNOP;
989 g_GIFPackedRegHandlers[GIF_REG_STQ] = &GIFPackedRegHandlerNOP;
990 g_GIFPackedRegHandlers[GIF_REG_UV] = &GIFPackedRegHandlerNOP;
991 g_GIFPackedRegHandlers[GIF_REG_XYZF2] = &GIFPackedRegHandlerNOP;
992 g_GIFPackedRegHandlers[GIF_REG_XYZ2] = &GIFPackedRegHandlerNOP;
993 g_GIFPackedRegHandlers[GIF_REG_CLAMP_1] = &GIFPackedRegHandlerNOP;
994 g_GIFPackedRegHandlers[GIF_REG_CLAMP_2] = &GIFPackedRegHandlerNOP;
995 g_GIFPackedRegHandlers[GIF_REG_FOG] = &GIFPackedRegHandlerNOP;
996 g_GIFPackedRegHandlers[GIF_REG_XYZF3] = &GIFPackedRegHandlerNOP;
997 g_GIFPackedRegHandlers[GIF_REG_XYZ3] = &GIFPackedRegHandlerNOP;
998
999 g_GIFRegHandlers[GIF_A_D_REG_PRIM] = &GIFRegHandlerNOP;
1000 g_GIFRegHandlers[GIF_A_D_REG_RGBAQ] = &GIFRegHandlerNOP;
1001 g_GIFRegHandlers[GIF_A_D_REG_ST] = &GIFRegHandlerNOP;
1002 g_GIFRegHandlers[GIF_A_D_REG_UV] = &GIFRegHandlerNOP;
1003 g_GIFRegHandlers[GIF_A_D_REG_XYZF2] = &GIFRegHandlerNOP;
1004 g_GIFRegHandlers[GIF_A_D_REG_XYZ2] = &GIFRegHandlerNOP;
1005 g_GIFRegHandlers[GIF_A_D_REG_XYZF3] = &GIFRegHandlerNOP;
1006 g_GIFRegHandlers[GIF_A_D_REG_XYZ3] = &GIFRegHandlerNOP;
1007 g_GIFRegHandlers[GIF_A_D_REG_PRMODECONT] = &GIFRegHandlerNOP;
1008 g_GIFRegHandlers[GIF_A_D_REG_PRMODE] = &GIFRegHandlerNOP;
1009 }
1010 else
1011 {
1012 g_GIFPackedRegHandlers[GIF_REG_PRIM] = &GIFPackedRegHandlerPRIM;
1013 g_GIFPackedRegHandlers[GIF_REG_RGBA] = &GIFPackedRegHandlerRGBA;
1014 g_GIFPackedRegHandlers[GIF_REG_STQ] = &GIFPackedRegHandlerSTQ;
1015 g_GIFPackedRegHandlers[GIF_REG_UV] = &GIFPackedRegHandlerUV;
1016 g_GIFPackedRegHandlers[GIF_REG_XYZF2] = &GIFPackedRegHandlerXYZF2;
1017 g_GIFPackedRegHandlers[GIF_REG_XYZ2] = &GIFPackedRegHandlerXYZ2;
1018 g_GIFPackedRegHandlers[GIF_REG_CLAMP_1] = &GIFPackedRegHandlerCLAMP<0>;
1019 g_GIFPackedRegHandlers[GIF_REG_CLAMP_2] = &GIFPackedRegHandlerCLAMP<1>;
1020 g_GIFPackedRegHandlers[GIF_REG_FOG] = &GIFPackedRegHandlerFOG;
1021 g_GIFPackedRegHandlers[GIF_REG_XYZF3] = &GIFPackedRegHandlerXYZF3;
1022 g_GIFPackedRegHandlers[GIF_REG_XYZ3] = &GIFPackedRegHandlerXYZ3;
1023
1024 g_GIFRegHandlers[GIF_A_D_REG_PRIM] = &GIFRegHandlerPRIM;
1025 g_GIFRegHandlers[GIF_A_D_REG_RGBAQ] = &GIFRegHandlerRGBAQ;
1026 g_GIFRegHandlers[GIF_A_D_REG_ST] = &GIFRegHandlerST;
1027 g_GIFRegHandlers[GIF_A_D_REG_UV] = &GIFRegHandlerUV;
1028 g_GIFRegHandlers[GIF_A_D_REG_XYZF2] = &GIFRegHandlerXYZF2;
1029 g_GIFRegHandlers[GIF_A_D_REG_XYZ2] = &GIFRegHandlerXYZ2;
1030 g_GIFRegHandlers[GIF_A_D_REG_XYZF3] = &GIFRegHandlerXYZF3;
1031 g_GIFRegHandlers[GIF_A_D_REG_XYZ3] = &GIFRegHandlerXYZ3;
1032 g_GIFRegHandlers[GIF_A_D_REG_PRMODECONT] = &GIFRegHandlerPRMODECONT;
1033 g_GIFRegHandlers[GIF_A_D_REG_PRMODE] = &GIFRegHandlerPRMODE;
1034 }
1035 }
1036
1037 #endif

  ViewVC Help
Powered by ViewVC 1.1.22