/[pcsx2_0.9.7]/branch/debug/0.X/0.9.X/0.9.7/ramdump-lateset/plugins/zzogl-pg/opengl/Regs.cpp
ViewVC logotype

Contents of /branch/debug/0.X/0.9.X/0.9.7/ramdump-lateset/plugins/zzogl-pg/opengl/Regs.cpp

Parent Directory Parent Directory | Revision Log Revision Log


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

  ViewVC Help
Powered by ViewVC 1.1.22