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

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

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 MIME type: text/plain
File size: 23076 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 #ifndef __GS_H__
21 #define __GS_H__
22
23
24 #define USE_OLD_REGS
25
26 #include "Util.h"
27 #include "GifTransfer.h"
28 #include "HostMemory.h"
29
30 using namespace std;
31
32 extern float fFPS;
33
34 extern int g_LastCRC;
35
36 struct Vector_16F
37 {
38 u16 x, y, z, w;
39 };
40
41 // PS2 vertex
42
43 // Almost same as VertexGPU, controlled by prim.fst flags
44
45 struct Vertex
46 {
47 u16 x, y, f, resv0; // note: xy is 12d3
48 u32 rgba;
49 u32 z;
50 float s, t, q;
51 // Texel coordinate of vertex. Used if prim.fst == 1
52 // Bits 0-14 and 16-30 of UV
53 u16 u, v;
54 };
55
56 struct VertexGPU
57 {
58 // gained from XYZ2, XYZ3, XYZF2, XYZF3,
59 // X -- bits 0-15, Y-16-31. Z - 32-63 if no F used, 32-55 otherwise, F (fog) - 56-63
60 // X, Y stored in 12d3 format,
61 s16 x, y;
62 s16 f, resv0;
63
64 // Vertex color settings. RGB -- luminance of red/green/blue, A -- alpha. 1.0 == 0x80.
65 // Goes grom RGBAQ register, bits 0-7, 8-15, 16-23 and 24-31 accordingly
66 u32 rgba;
67 u32 z;
68 // Texture coordinates. S & T going from ST register (bits 0-31, and 32-63).
69 // Q goes from RGBAQ register, bits 32-63
70 float s, t, q;
71
72 void move_x(Vertex v, int offset)
73 {
74 x = ((((int)v.x - offset) >> 1) & 0xffff);
75 }
76
77 void move_y(Vertex v, int offset)
78 {
79 y = ((((int)v.y - offset) >> 1) & 0xffff);
80 }
81
82 void move_z(Vertex v, int mask)
83 {
84 z = (mask == 0xffff) ? min((u32)0xffff, v.z) : v.z;
85 }
86
87 void move_fog(Vertex v)
88 {
89 f = ((s16)(v).f << 7) | 0x7f;
90 }
91
92 void set_xy(s16 x1, s16 y1)
93 {
94 x = x1;
95 y = y1;
96 }
97 void set_xyz(s16 x1, s16 y1, u32 z1)
98 {
99 x = x1;
100 y = y1;
101 z = z1;
102 }
103
104 void set_st(float s1, float t1)
105 {
106 s = s1;
107 t = t1;
108 }
109
110 void set_stq(float s1, float t1, float q1)
111 {
112 s = s1;
113 t = t1;
114 q = q1;
115 }
116
117 void set_xyzst(s16 x1, s16 y1, u32 z1, float s1, float t1)
118 {
119 set_xyz(x1, y1, z1);
120 set_st(s1, t1);
121 }
122
123 };
124
125 extern GSconf conf;
126
127 // PSM values
128 // PSM types == Texture Storage Format
129 enum PSM_value
130 {
131 PSMCT32 = 0, // 00 0000
132 PSMCT24 = 1, // 00 0001
133 PSMCT16 = 2, // 00 0010
134 PSMCT16S = 10, // 00 1010
135 PSMT8 = 19, // 01 0011
136 PSMT4 = 20, // 01 0100
137 PSMT8H = 27, // 01 1011
138 PSMT4HL = 36, // 10 0100
139 PSMT4HH = 44, // 10 1100
140 PSMT32Z = 48, // 11 0000
141 PSMT24Z = 49, // 11 0001
142 PSMT16Z = 50, // 11 0010
143 PSMT16SZ = 58, // 11 1010
144 };
145
146 // Check target bit mode. PSMCT32 and 32Z return 0, 24 and 24Z - 1
147 // 16, 16S, 16Z, 16SZ -- 2, PSMT8 and 8H - 3, PSMT4, 4HL, 4HH -- 4.
148 // This code returns the same value on Z-textures, so texel storage mode is (BITMODE and !ISZTEX).
149 inline int PSMT_BITMODE(int psm) {return (psm & 0x7);}
150
151 inline int PSMT_BITS_NUM(int psm)
152 {
153 // Treat these as 32 bit.
154 if ((psm == PSMT8H) || (psm == PSMT4HL) || (psm == PSMT4HH))
155 {
156 return 4;
157 }
158
159 switch (PSMT_BITMODE(psm))
160 {
161 case 4:
162 return 0;
163
164 case 3:
165 return 1;
166
167 case 2:
168 return 2;
169
170 default:
171 return 4;
172 }
173 }
174
175 // CLUT = Color look up table. Set proper color to table according CLUT table.
176 // Used for PSMT8, PSMT8H, PSMT4, PSMT4HH, PSMT4HL textures
177 inline bool PSMT_ISCLUT(int psm) { return (PSMT_BITMODE(psm) > 2);}
178
179 // PSMCT16, PSMCT16S, PSMT16Z, PSMT16SZ is 16-bit targets and usually there is
180 // two of them in each 32-bit word.
181 inline bool PSMT_IS16BIT(int psm) { return (PSMT_BITMODE(psm) == 2);}
182
183 // PSMT32Z, PSMT24Z, PSMT16Z, PSMT16SZ is Z-buffer textures
184 inline bool PSMT_ISZTEX(int psm) {return ((psm & 0x30) == 0x30);}
185
186 // PSMCT16, PSMCT16S, PSMT8, PSMT8H, PSMT16Z and PSMT16SZ use only half 16 bit per pixel.
187 inline bool PSMT_ISHALF(int psm) {return ((psm & 2) == 2);}
188
189 // PSMT8 and PSMT8H use IDTEX8 CLUT, PSMT4H, PSMT4HL, PSMT4HH -- IDTEX4.
190 // Don't use it on non clut entries, please!
191 inline bool PSMT_IS8CLUT(int psm) {return ((psm & 3) == 3);}
192
193 // PSM16Z and PSMT16SZ use -1 offset to z-buff. Need to check this thesis.
194 inline bool PSMT_IS16Z(int psm) {return ((psm & 0x32) == 0x32);}
195
196 // Check to see if it is 32 bits. According to code comments, anyways.
197 // I'll have to look closer at it, because it'd seem like it'd return true for 24 bits.
198 // Note: the function only works for clut format. Clut PSM is 4 bits only. The possible value are PSMCT32, PSMCT16, PSMCT16S
199 inline bool PSMT_IS32BIT(int psm) {return !!(psm <= 1);}
200
201 // When color format is RGB24 (PSMCT24) or RGBA16 (PSMCT16 & 16S) alpha value expanded, based on
202 // TEXA register and AEM status.
203 inline int PSMT_ALPHAEXP(int psm) {return (psm == PSMCT24 || psm == PSMCT16 || psm == PSMCT16S);}
204
205
206 // This function updates the 6th and 5th bit of psm
207 // 00 or 11 -> 00 ; 01 -> 10 ; 10 -> 01
208 inline int Switch_Top_Bytes (int X) {
209 if ( ( X & 0x30 ) == 0 )
210 return X;
211 else
212 return (X ^ 0x30);
213 }
214
215 // How many pixel stored in 1 word.
216 // PSMT8 has 4 pixels per 32bit, PSMT4 has 8. All 16-bit textures are 2 pixel per bit. And all others are 1 pixel in texture.
217 inline int PIXELS_PER_WORD(int psm)
218 {
219 if (psm == PSMT8)
220 return 4;
221 if (psm == PSMT4)
222 return 8;
223 if (PSMT_IS16BIT(psm))
224 return 2;
225 return 1;
226 }
227
228 // Some storage formats could share the same memory block (2 textures in 1 format). This include following combinations:
229 // PSMT24(24Z) with either 8H, 4HL, 4HH and PSMT4HL with PSMT4HH.
230 // We use slightly different versions of this function on comparison with GSDX, Storage format XOR 0x30 made Z-textures
231 // similar to normal ones and change higher bits on short (8 and 4 bits) textures.
232 inline bool PSMT_HAS_SHARED_BITS (int fpsm, int tpsm) {
233 int SUM = Switch_Top_Bytes(fpsm) + Switch_Top_Bytes(tpsm) ;
234 return (SUM == 0x15 || SUM == 0x1D || SUM == 0x2C || SUM == 0x30);
235 }
236
237 // If a clut is in 32-bit color, its size is 4 bytes, and 16-bit clut has a 2 byte size.
238 inline int CLUT_PIXEL_SIZE(int cpsm) {return ((cpsm <= 1) ? 4 : 2); }
239
240 //----------------------- Data from registers -----------------------
241
242 typedef union
243 {
244 s64 SD;
245 u64 UD;
246 s32 SL[2];
247 u32 UL[2];
248 s16 SS[4];
249 u16 US[4];
250 s8 SC[8];
251 u8 UC[8];
252 } reg64;
253
254 /* general purpose regs structs */
255
256 typedef struct
257 {
258 int fbp;
259 int fbw;
260 int fbh;
261 int psm;
262 u32 fbm;
263 } frameInfo;
264
265 // Create frame structure from known data
266 inline frameInfo CreateFrame(int fbp, int fbw, int fbh, int psm, u32 fbm)
267 {
268 frameInfo frame;
269 frame.fbp = fbp;
270 frame.fbw = fbw;
271 frame.fbh = fbh;
272 frame.psm = psm;
273 frame.fbm = fbm;
274 return frame;
275 }
276
277 typedef struct
278 {
279 u16 prim;
280
281 union
282 {
283 struct
284 {
285 u16 iip : 1;
286 u16 tme : 1;
287 u16 fge : 1;
288 u16 abe : 1;
289 u16 aa1 : 1;
290 u16 fst : 1;
291 u16 ctxt : 1;
292 u16 fix : 1;
293 u16 resv : 8;
294 };
295 u16 _val;
296 };
297 } primInfo;
298
299 extern primInfo *prim;
300
301 typedef union
302 {
303 struct
304 {
305 u32 ate : 1;
306 u32 atst : 3;
307 u32 aref : 8;
308 u32 afail : 2;
309 u32 date : 1;
310 u32 datm : 1;
311 u32 zte : 1;
312 u32 ztst : 2;
313 u32 resv : 13;
314 };
315 u32 _val;
316 } pixTest;
317
318 typedef struct
319 {
320 int bp;
321 int bw;
322 int psm;
323 } bufInfo;
324
325 typedef struct
326 {
327 int tbp0;
328 int tbw;
329 int cbp;
330 u16 tw, th;
331 u8 psm;
332 u8 tcc;
333 u8 tfx;
334 u8 cpsm;
335 u8 csm;
336 u8 csa;
337 u8 cld;
338 } tex0Info;
339
340 union tex_0_info
341 {
342 struct
343 {
344 u64 tbp0 : 14;
345 u64 tbw : 6;
346 u64 psm : 6;
347 u64 tw : 4;
348 u64 th : 4;
349 u64 tcc : 1;
350 u64 tfx : 2;
351 u64 cbp : 14;
352 u64 cpsm : 4;
353 u64 csm : 1;
354 u64 csa : 5;
355 u64 cld : 3;
356 };
357
358 u64 _u64;
359 u32 _u32[2];
360 u16 _u16[4];
361 u8 _u8[8];
362
363 tex_0_info(u64 data) { _u64 = data; }
364 tex_0_info(u32 data) { _u32[0] = data; _u32[1] = 0; }
365 tex_0_info(u32 data0, u32 data1) { _u32[0] = data0; _u32[1] = data1; }
366
367 u32 tbw_mult()
368 {
369 if (tbw == 0)
370 return 64;
371 else
372 return ((u32)tbw << 6);
373 }
374
375 u32 psm_fix()
376 {
377 // ZZLog::Debug_Log("psm %d\n", psm);
378 if (psm == 9) return 1;
379
380 return psm;
381 }
382
383 u32 tw_exp()
384 {
385 if (tw > 10) return (1 << 10);
386
387 return (1 << tw);
388 }
389
390 u32 th_exp()
391 {
392 if (th > 10) return (1 << 10);
393
394 return (1 << th);
395 }
396
397 u32 cpsm_fix()
398 {
399 return cpsm & 0xe;
400 }
401
402 u32 csa_fix()
403 {
404 if (cpsm < 2)
405 return (csa & 0xf);
406 else
407 return (csa & 0x1f);
408 }
409 };
410
411 #define TEX_MODULATE 0
412 #define TEX_DECAL 1
413 #define TEX_HIGHLIGHT 2
414 #define TEX_HIGHLIGHT2 3
415
416 bool SaveTexture(const char* filename, u32 textarget, u32 tex, int width, int height);
417 extern void SaveTex(tex0Info* ptex, int usevid);
418 extern char* NamedSaveTex(tex0Info* ptex, int usevid);
419
420 typedef struct
421 {
422 int lcm;
423 int mxl;
424 int mmag;
425 int mmin;
426 int mtba;
427 int l;
428 int k;
429 } tex1Info;
430
431 typedef struct
432 {
433 int wms;
434 int wmt;
435 int minu;
436 int maxu;
437 int minv;
438 int maxv;
439 } clampInfo;
440
441 typedef struct
442 {
443 int cbw;
444 int cou;
445 int cov;
446 } clutInfo;
447
448 typedef struct
449 {
450 int tbp[3];
451 int tbw[3];
452 } miptbpInfo;
453
454 typedef struct
455 {
456 u16 aem;
457 u8 ta[2];
458 float fta[2];
459 } texaInfo;
460
461 typedef struct
462 {
463 int sx;
464 int sy;
465 int dx;
466 int dy;
467 #ifdef USE_OLD_REGS
468 int dir;
469 #else
470 int diry;
471 int dirx;
472 #endif
473 } trxposInfo;
474
475 typedef struct
476 {
477 union
478 {
479 struct
480 {
481 u8 a : 2;
482 u8 b : 2;
483 u8 c : 2;
484 u8 d : 2;
485 };
486 u8 abcd;
487 };
488
489 u8 fix : 8;
490 } alphaInfo;
491
492 typedef struct
493 {
494 u16 zbp; // u16 address / 64
495 u8 psm;
496 u8 zmsk;
497 } zbufInfo;
498
499 typedef struct
500 {
501 int fba;
502 } fbaInfo;
503
504 typedef struct
505 {
506 Vertex gsvertex[4]; // circular buffer that contains the vertex
507 Vertex gsTriFanVertex; // Base of triangle fan primitive vertex
508 u32 rgba; // global color for flat shading texture
509 float q;
510 Vertex vertexregs; // accumulation buffer that collect current vertex data
511
512 int primC; // number of verts current storing
513 int primIndex; // current prim index
514 int nTriFanVert; // remember the index of the base of triangle fan
515 int new_tri_fan; // 1 if we process a new triangle fan primitive. 0 otherwise
516
517 int prac;
518 int dthe;
519 int colclamp;
520 int fogcol;
521 int smask;
522 int pabe;
523 u64 buff[2];
524 int buffsize;
525 int cbp[2]; // internal cbp registers
526
527 u32 CSRw;
528
529 primInfo _prim[2];
530 bufInfo srcbuf, srcbufnew;
531 bufInfo dstbuf, dstbufnew;
532
533 clutInfo clut;
534
535 texaInfo texa;
536 trxposInfo trxpos, trxposnew;
537
538 int imageWtemp, imageHtemp;
539
540 int imageTransfer;
541 int imageWnew, imageHnew, imageX, imageY, imageEndX, imageEndY;
542
543 pathInfo path[4];
544 GIFRegDIMX dimx;
545 GSMemory mem;
546 GSClut clut_buffer;
547 int primNext(int inc = 1)
548 {
549 // Note: ArraySize(gsvertex) == 2^n => modulo is replaced by an and instruction
550 return ((primIndex + inc) % ArraySize(gsvertex));
551 }
552
553 int primPrev(int dec = 1)
554 {
555 // Note: assert( dec <= ArraySize(gsvertex) );
556 // Note: ArraySize(gsvertex) == 2^n => modulo is replaced by an and instruction
557 return ((primIndex + (ArraySize(gsvertex) - dec)) % ArraySize(gsvertex));
558 }
559
560 void setRGBA(u32 r, u32 g, u32 b, u32 a)
561 {
562 rgba = (r & 0xff) |
563 ((g & 0xff) << 8) |
564 ((b & 0xff) << 16) |
565 ((a & 0xff) << 24);
566 }
567
568 inline void add_vertex(u16 x, u16 y, u32 z, u16 f)
569 {
570 vertexregs.x = x;
571 vertexregs.y = y;
572 vertexregs.z = z;
573 vertexregs.f = f;
574 if (likely(!new_tri_fan)) {
575 gsvertex[primIndex] = vertexregs;
576 } else {
577 gsTriFanVertex = vertexregs;
578 new_tri_fan = false;
579 }
580 }
581
582 inline void add_vertex(u16 x, u16 y, u32 z)
583 {
584 vertexregs.x = x;
585 vertexregs.y = y;
586 vertexregs.z = z;
587 if (likely(!new_tri_fan)) {
588 gsvertex[primIndex] = vertexregs;
589 } else {
590 gsTriFanVertex = vertexregs;
591 new_tri_fan = false;
592 }
593 }
594 } GSinternal;
595
596 extern GSinternal gs;
597
598 // Note the function is used in a template parameter so it must be declared extern
599 // Note2: In this case extern is not compatible with __forceinline so just inline it...
600 extern inline u16 RGBA32to16(u32 c)
601 {
602 return (u16)((((c) & 0x000000f8) >> 3) |
603 (((c) & 0x0000f800) >> 6) |
604 (((c) & 0x00f80000) >> 9) |
605 (((c) & 0x80000000) >> 16));
606 }
607
608 static __forceinline u32 RGBA16to32(u16 c)
609 {
610 return (((c) & 0x001f) << 3) |
611 (((c) & 0x03e0) << 6) |
612 (((c) & 0x7c00) << 9) |
613 (((c) & 0x8000) ? 0xff000000 : 0);
614 }
615
616 #if 0
617 // converts float16 [0,1] to BYTE [0,255] (assumes value is in range, otherwise will take lower 8bits)
618 // f is a u16
619 static __forceinline u16 Float16ToBYTE(u16 f)
620 {
621 //assert( !(f & 0x8000) );
622 if (f & 0x8000) return 0;
623
624 u16 d = ((((f & 0x3ff) | 0x400) * 255) >> (10 - ((f >> 10) & 0x1f) + 15));
625
626 return d > 255 ? 255 : d;
627 }
628
629 static __forceinline u16 Float16ToALPHA(u16 f)
630 {
631 //assert( !(f & 0x8000) );
632 if (f & 0x8000) return 0;
633
634 // round up instead of down (crash and burn), too much and charlie breaks
635 u16 d = (((((f & 0x3ff) | 0x400)) * 255) >> (10 - ((f >> 10) & 0x1f) + 15));
636
637 d = (d) >> 1;
638
639 return d > 255 ? 255 : d;
640 }
641
642 #ifndef COLOR_ARGB
643 #define COLOR_ARGB(a,r,g,b) \
644 ((u32)((((a)&0xff)<<24)|(((r)&0xff)<<16)|(((g)&0xff)<<8)|((b)&0xff)))
645 #endif
646
647 // assumes that positive in [1,2] (then extracts fraction by just looking at the specified bits)
648 #define Float16ToBYTE_2(f) ((u8)(*(u16*)&f>>2))
649 #define Float16To5BIT(f) (Float16ToBYTE(f)>>3)
650
651 #define Float16Alpha(f) (((*(u16*)&f&0x7c00)>=0x3900)?0x8000:0) // alpha is >= 1
652
653 // converts an array of 4 u16s to a u32 color
654 // f is a pointer to a u16
655 #define Float16ToARGB(f) COLOR_ARGB(Float16ToALPHA(f.w), Float16ToBYTE(f.x), Float16ToBYTE(f.y), Float16ToBYTE(f.z));
656
657 #define Float16ToARGB16(f) (Float16Alpha(f.w)|(Float16To5BIT(f.x)<<10)|(Float16To5BIT(f.y)<<5)|Float16To5BIT(f.z))
658
659 // used for Z values
660 #define Float16ToARGB_Z(f) COLOR_ARGB((u32)Float16ToBYTE_2(f.w), Float16ToBYTE_2(f.x), Float16ToBYTE_2(f.y), Float16ToBYTE_2(f.z))
661 #define Float16ToARGB16_Z(f) ((Float16ToBYTE_2(f.y)<<8)|Float16ToBYTE_2(f.z))
662 #endif
663
664
665 inline float Clamp(float fx, float fmin, float fmax)
666 {
667 if (fx < fmin) return fmin;
668
669 return fx > fmax ? fmax : fx;
670 }
671
672 // Get pixel storage format from tex0. Clutted textures store pixels in cpsm format.
673 inline int PIXEL_STORAGE_FORMAT(const tex0Info& tex) {
674 if (PSMT_ISCLUT(tex.psm))
675 return tex.cpsm;
676 else
677 return tex.psm;
678 }
679
680 // If pixel storage format not PSMCT24 ot PSMCT32, then it is 16-bit.
681 // Z-textures have 0x30 upper bits, so we eliminate them by &&(~0x30)
682 inline bool PSMT_ISHALF_STORAGE(const tex0Info& tex0) { return ((PIXEL_STORAGE_FORMAT(tex0) & (~0x30)) > 1); }
683
684 //--------------------------- Inlines for bitwise ops
685 //--------------------------- textures
686 // Tex0Info (TEXD_x registers) bits, lower word
687 // The register is really 64-bit, but we use 2 32bit ones to represent it
688 // Obtain tbp0 -- Texture Buffer Base Pointer (Word Address/64) -- from data. Bits 0-13.
689 static __forceinline int ZZOglGet_tbp0_TexBits(u32 data)
690 {
691 //return tex_0_info(data).tbp0;
692 return (data) & 0x3fff;
693 }
694
695 // Obtain tbw -- Texture Buffer Width (Texels/64) -- from data, do not multiply to 64. Bits 14-19
696 // ( data & 0xfc000 ) >> 14
697 static __forceinline int ZZOglGet_tbw_TexBits(u32 data)
698 {
699 //return tex_0_info(data).tbw;
700 return (data >> 14) & 0x3f;
701 }
702
703 // Obtain tbw -- Texture Buffer Width (Texels) -- from data, do multiply to 64, never return 0.
704 static __forceinline int ZZOglGet_tbw_TexBitsMult(u32 data)
705 {
706 //return text_0_info(data).tbw_mult();
707 int result = ZZOglGet_tbw_TexBits(data);
708
709 if (result == 0)
710 return 64;
711 else
712 return (result << 6);
713 }
714
715 // Obtain psm -- Pixel Storage Format -- from data. Bits 20-25.
716 // (data & 0x3f00000) >> 20
717 static __forceinline int ZZOglGet_psm_TexBits(u32 data)
718 {
719 //return tex_0_info(data).psm;
720 return ((data >> 20) & 0x3f);
721 }
722
723 // Obtain psm -- Pixel Storage Format -- from data. Bits 20-25. Fix incorrect psm == 9
724 static __forceinline int ZZOglGet_psm_TexBitsFix(u32 data)
725 {
726 //return tex_0_info(data).psm_fix();
727 int result = ZZOglGet_psm_TexBits(data) ;
728 // ZZLog::Debug_Log("result %d", result);
729
730 if (result == 9) result = 1;
731
732 return result;
733 }
734
735 // Obtain tw -- Texture Width (Width = 2^TW) -- from data. Bits 26-29
736 // (data & 0x3c000000)>>26
737 static __forceinline u16 ZZOglGet_tw_TexBits(u32 data)
738 {
739 //return tex_0_info(data).tw;
740 return ((data >> 26) & 0xf);
741 }
742
743 // Obtain tw -- Texture Width (Width = TW) -- from data. Width could newer be more than 1024.
744 static __forceinline u16 ZZOglGet_tw_TexBitsExp(u32 data)
745 {
746 //return tex_0_info(data).tw_exp();
747 u16 result = ZZOglGet_tw_TexBits(data);
748
749 if (result > 10) result = 10;
750
751 return (1 << result);
752 }
753
754 // TH set at the border of upper and higher words.
755 // Obtain th -- Texture Height (Height = 2^TH) -- from data. Bits 30-31 lower, 0-1 higher
756 // (dataLO & 0xc0000000) >> 30 + (dataHI & 0x3) * 0x4
757 static __forceinline u16 ZZOglGet_th_TexBits(u32 dataLO, u32 dataHI)
758 {
759 //return tex_0_info(dataLO, dataHI).th;
760 return (((dataLO >> 30) & 0x3) | ((dataHI & 0x3) << 2));
761 }
762
763 // Obtain th --Texture Height (Height = 2^TH) -- from data. Height could newer be more than 1024.
764 static __forceinline u16 ZZOglGet_th_TexBitsExp(u32 dataLO, u32 dataHI)
765 {
766 //return tex_0_info(dataLO, dataHI).th_exp();
767 u16 result = ZZOglGet_th_TexBits(dataLO, dataHI);
768
769 if (result > 10) result = 10;
770
771 return (1 << result);
772 }
773
774 // Tex0Info bits, higher word.
775 // Obtain tcc -- Texture Color Component 0=RGB, 1=RGBA + use Alpha from TEXA reg when not in PSM -- from data. Bit 3
776 // (data & 0x4)>>2
777 static __forceinline u8 ZZOglGet_tcc_TexBits(u32 data)
778 {
779 //return tex_0_info(0, data).tcc;
780 return ((data >> 2) & 0x1);
781 }
782
783 // Obtain tfx -- Texture Function (0=modulate, 1=decal, 2=hilight, 3=hilight2) -- from data. Bit 4-5
784 // (data & 0x18)>>3
785 static __forceinline u8 ZZOglGet_tfx_TexBits(u32 data)
786 {
787 //return tex_0_info(0, data).tfx;
788 return ((data >> 3) & 0x3);
789 }
790
791 // Obtain cbp from data -- Clut Buffer Base Pointer (Address/256) -- Bits 5-18
792 // (data & 0x7ffe0)>>5
793 static __forceinline int ZZOglGet_cbp_TexBits(u32 data)
794 {
795 //return tex_0_info(0, data).cbp;
796 return ((data >> 5) & 0x3fff);
797 }
798
799 // Obtain cpsm from data -- Clut pixel Storage Format -- Bits 19-22. 22nd is at no use.
800 // (data & 0x700000)>>19
801 // 0000 - psmct32; 0010 - psmct16; 1010 - psmct16s.
802 static __forceinline u8 ZZOglGet_cpsm_TexBits(u32 data)
803 {
804 //return (tex_0_info(0, data).cpsm & 0xe);
805 return ((data >> 19) & 0xe);
806 }
807
808 // Obtain csm -- I don't know what is it -- from data. Bit 23
809 // (data & 0x800000)>>23
810 // csm is the clut storage mode. 0 for CSM1, 1 for CSM2.
811 static __forceinline u8 ZZOglGet_csm_TexBits(u32 data)
812 {
813 //return tex_0_info(0, data).csm;
814 return ((data >> 23) & 0x1);
815 }
816
817 // Obtain csa -- -- from data. Bits 24-28
818 // (data & 0x1f000000)>>24
819 static __forceinline u8 ZZOglGet_csa_TexBits(u32 data)
820 {
821 //return tex_0_info(0, data).csa_fix();
822
823 if ((data & 0x700000) == 0) // it is cpsm < 2 check
824 return ((data >> 24) & 0xf);
825 else
826 return ((data >> 24) & 0x1f);
827 }
828
829 // Obtain cld -- -- from data. Bits 29-31
830 // (data & 0xe0000000)>>29
831 static __forceinline u8 ZZOglGet_cld_TexBits(u32 data)
832 {
833 //return tex_0_info(0, data).cld;
834 return ((data >> 29) & 0x7);
835 }
836
837 //-------------------------- frames
838 // FrameInfo bits.
839 // Obtain fbp -- frame Buffer Base Pointer (Word Address/2048) -- from data. Bits 0-15
840 inline int ZZOglGet_fbp_FrameBits(u32 data)
841 {
842 return ((data) & 0x1ff);
843 }
844
845 // So we got address / 64, henceby frame fbp and tex tbp have the same dimension -- "real address" is x64.
846 inline int ZZOglGet_fbp_FrameBitsMult(u32 data)
847 {
848 return (ZZOglGet_fbp_FrameBits(data) << 5);
849 }
850
851 // Obtain fbw -- width (Texels/64) -- from data. Bits 16-23
852 inline int ZZOglGet_fbw_FrameBits(u32 data)
853 {
854 return ((data >> 16) & 0x3f);
855 }
856
857 inline int ZZOglGet_fbw_FrameBitsMult(u32 data)
858 {
859 return (ZZOglGet_fbw_FrameBits(data) << 6);
860 }
861
862
863 // Obtain psm -- Pixel Storage Format -- from data. Bits 24-29.
864 // (data & 0x3f000000) >> 24
865 inline int ZZOglGet_psm_FrameBits(u32 data)
866 {
867 return ((data >> 24) & 0x3f);
868 }
869
870 // Function for calculating overal height from frame data.
871 inline int ZZOgl_fbh_Calc(int fbp, int fbw, int psm)
872 {
873 int fbh = (1024 * 1024 - 64 * fbp) / fbw;
874 fbh &= ~0x1f;
875
876 if (PSMT_ISHALF(psm)) fbh *= 2;
877 if (fbh > 1024) fbh = 1024;
878
879 //ZZLog::Debug_Log("ZZOgl_fbh_Calc: 0x%x", fbh);
880 return fbh;
881 }
882
883 inline int ZZOgl_fbh_Calc(frameInfo frame)
884 {
885 return ZZOgl_fbh_Calc(frame.fbp, frame.fbw, frame.psm);
886 }
887
888 // Calculate fbh from data, It does not set in register
889 inline int ZZOglGet_fbh_FrameBitsCalc(u32 data)
890 {
891 int fbh = 0;
892 int fbp = ZZOglGet_fbp_FrameBits(data);
893 int fbw = ZZOglGet_fbw_FrameBits(data);
894 int psm = ZZOglGet_psm_FrameBits(data);
895
896 if (fbw > 0) fbh = ZZOgl_fbh_Calc(fbp, fbw, psm) ;
897
898 return fbh ;
899 }
900
901 // Obtain fbm -- frame mask -- from data. All higher word.
902 inline u32 ZZOglGet_fbm_FrameBits(u32 data)
903 {
904 return (data);
905 }
906
907 // Obtain fbm -- frame mask -- from data. All higher word. Fixed from psm == PCMT24 (without alpha)
908 inline u32 ZZOglGet_fbm_FrameBitsFix(u32 dataLO, u32 dataHI)
909 {
910 if (PSMT_BITMODE(ZZOglGet_psm_FrameBits(dataLO)) == 1)
911 return (dataHI | 0xff000000);
912 else
913 return dataHI;
914 }
915
916 // obtain colormask RED
917 inline u32 ZZOglGet_fbmRed_FrameBits(u32 data)
918 {
919 return (data & 0xff);
920 }
921
922 // obtain colormask Green
923 inline u32 ZZOglGet_fbmGreen_FrameBits(u32 data)
924 {
925 return ((data >> 8) & 0xff);
926 }
927
928 // obtain colormask Blue
929 inline u32 ZZOglGet_fbmBlue_FrameBits(u32 data)
930 {
931 return ((data >> 16) & 0xff);
932 }
933
934 // obtain colormask Alpha
935 inline u32 ZZOglGet_fbmAlpha_FrameBits(u32 data)
936 {
937 return ((data >> 24) & 0xff);
938 }
939
940 // obtain colormask Alpha
941 inline u32 ZZOglGet_fbmHighByte(u32 data)
942 {
943 return (!!(data & 0x80000000));
944 }
945
946 //-------------------------- tex0 comparison
947 // Check if old and new tex0 registers have only clut difference
948 inline bool ZZOglAllExceptClutIsSame(const u32* oldtex, const u32* newtex)
949 {
950 return ((oldtex[0] == newtex[0]) && ((oldtex[1] & 0x1f) == (newtex[1] & 0x1f)));
951 }
952
953 // Check if the CLUT registers are same, except CLD
954 inline bool ZZOglClutMinusCLDunchanged(const u32* oldtex, const u32* newtex)
955 {
956 return ((oldtex[1] & 0x1fffffe0) == (newtex[1] & 0x1fffffe0));
957 }
958
959 // Check if CLUT storage mode is not changed (CSA, CSM and CSPM)
960 inline bool ZZOglClutStorageUnchanged(const u32* oldtex, const u32* newtex)
961 {
962 return ((oldtex[1] & 0x1ff10000) == (newtex[1] & 0x1ff10000));
963 }
964
965 // call to load CLUT data (depending on CLD)
966 void texClutWrite(int ctx);
967
968 // Perform clutting for flushed texture. Better check if it needs a prior call.
969 inline void CluttingForFlushedTex(tex0Info* tex0, u32 Data, int ictx)
970 {
971 tex0->cbp = ZZOglGet_cbp_TexBits(Data);
972 tex0->cpsm = ZZOglGet_cpsm_TexBits(Data);
973 tex0->csm = ZZOglGet_csm_TexBits(Data);
974 tex0->csa = ZZOglGet_csa_TexBits(Data);
975 tex0->cld = ZZOglGet_cld_TexBits(Data);
976
977 texClutWrite(ictx);
978 };
979
980 // CSA and CPSM bitmask 0001 1111 0111 1000 ...
981 // 60 56 52
982 #define CPSM_CSA_BITMASK 0x1f780000
983 #define CPSM_CSA_NOTMASK 0xe0870000
984
985 #endif

  ViewVC Help
Powered by ViewVC 1.1.22