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

Annotation 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 330 - (hide annotations) (download)
Tue Dec 28 04:24:23 2010 UTC (9 years, 10 months ago) by william
File MIME type: text/plain
File size: 23033 byte(s)
merged upstream r4154-r4160
1 william 62 /* 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 william 31 *
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 william 62 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
18 william 31 */
19    
20     #ifndef __GS_H__
21     #define __GS_H__
22    
23 william 62
24     #define USE_OLD_REGS
25    
26 william 31 #include "Util.h"
27     #include "GifTransfer.h"
28 william 314 #include "HostMemory.h"
29 william 31
30 william 62 using namespace std;
31    
32 william 31 extern float fFPS;
33    
34 william 62 extern int g_LastCRC;
35 william 31
36 william 314 struct Vector_16F
37 william 31 {
38 william 314 u16 x, y, z, w;
39 william 62 };
40 william 31
41 william 314 // PS2 vertex
42 william 31
43 william 314 // Almost same as VertexGPU, controlled by prim.fst flags
44 william 31
45 william 314 struct Vertex
46 william 31 {
47 william 314 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 william 31 };
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 william 314 s16 x, y;
62     s16 f, resv0;
63    
64 william 31 // 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 william 314
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 william 31
87 william 314 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 william 31 };
124    
125     extern GSconf conf;
126    
127     // PSM values
128     // PSM types == Texture Storage Format
129     enum PSM_value
130     {
131 william 163 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 william 31 };
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 william 163 // This code returns the same value on Z-textures, so texel storage mode is (BITMODE and !ISZTEX).
149 william 31 inline int PSMT_BITMODE(int psm) {return (psm & 0x7);}
150    
151 william 62 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 william 31 // 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 william 312 // Note: the function only works for clut format. Clut PSM is 4 bits only. The possible value are PSMCT32, PSMCT16, PSMCT16S
199 william 31 inline bool PSMT_IS32BIT(int psm) {return !!(psm <= 1);}
200    
201 william 163 // 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 william 312 // 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 william 163
240 william 31 //----------------------- 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 william 62
363 william 31 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 william 314 // ZZLog::Debug_Log("psm %d\n", psm);
378 william 31 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 william 314 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 william 31 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 william 62 int diry;
468     int dirx;
469 william 31 } trxposInfo;
470    
471     typedef struct
472     {
473     union
474     {
475     struct
476     {
477     u8 a : 2;
478     u8 b : 2;
479     u8 c : 2;
480     u8 d : 2;
481     };
482     u8 abcd;
483     };
484    
485     u8 fix : 8;
486     } alphaInfo;
487    
488     typedef struct
489     {
490     u16 zbp; // u16 address / 64
491     u8 psm;
492     u8 zmsk;
493     } zbufInfo;
494    
495     typedef struct
496     {
497     int fba;
498     } fbaInfo;
499    
500     typedef struct
501     {
502 william 314 Vertex gsvertex[4]; // circular buffer that contains the vertex
503     Vertex gsTriFanVertex; // Base of triangle fan primitive vertex
504     u32 rgba; // global color for flat shading texture
505 william 31 float q;
506 william 314 Vertex vertexregs; // accumulation buffer that collect current vertex data
507 william 31
508     int primC; // number of verts current storing
509     int primIndex; // current prim index
510 william 314 int nTriFanVert; // remember the index of the base of triangle fan
511     int new_tri_fan; // 1 if we process a new triangle fan primitive. 0 otherwise
512 william 31
513     int prac;
514     int dthe;
515     int colclamp;
516     int fogcol;
517     int smask;
518     int pabe;
519     u64 buff[2];
520     int buffsize;
521     int cbp[2]; // internal cbp registers
522    
523     u32 CSRw;
524    
525     primInfo _prim[2];
526     bufInfo srcbuf, srcbufnew;
527     bufInfo dstbuf, dstbufnew;
528    
529     clutInfo clut;
530    
531     texaInfo texa;
532     trxposInfo trxpos, trxposnew;
533    
534     int imageWtemp, imageHtemp;
535    
536     int imageTransfer;
537     int imageWnew, imageHnew, imageX, imageY, imageEndX, imageEndY;
538    
539 william 62 pathInfo path[4];
540     GIFRegDIMX dimx;
541     GSMemory mem;
542     GSClut clut_buffer;
543 william 163 int primNext(int inc = 1)
544     {
545 william 314 // Note: ArraySize(gsvertex) == 2^n => modulo is replaced by an and instruction
546     return ((primIndex + inc) % ArraySize(gsvertex));
547 william 163 }
548 william 62
549 william 314 int primPrev(int dec = 1)
550     {
551     // Note: assert( dec <= ArraySize(gsvertex) );
552     // Note: ArraySize(gsvertex) == 2^n => modulo is replaced by an and instruction
553     return ((primIndex + (ArraySize(gsvertex) - dec)) % ArraySize(gsvertex));
554     }
555    
556 william 62 void setRGBA(u32 r, u32 g, u32 b, u32 a)
557     {
558     rgba = (r & 0xff) |
559     ((g & 0xff) << 8) |
560     ((b & 0xff) << 16) |
561     ((a & 0xff) << 24);
562     }
563    
564 william 314 inline void add_vertex(u16 x, u16 y, u32 z, u16 f)
565 william 62 {
566     vertexregs.x = x;
567     vertexregs.y = y;
568     vertexregs.z = z;
569     vertexregs.f = f;
570 william 314 if (likely(!new_tri_fan)) {
571     gsvertex[primIndex] = vertexregs;
572     } else {
573     gsTriFanVertex = vertexregs;
574     new_tri_fan = false;
575     }
576 william 62 }
577    
578 william 314 inline void add_vertex(u16 x, u16 y, u32 z)
579 william 62 {
580     vertexregs.x = x;
581     vertexregs.y = y;
582     vertexregs.z = z;
583 william 314 if (likely(!new_tri_fan)) {
584     gsvertex[primIndex] = vertexregs;
585     } else {
586     gsTriFanVertex = vertexregs;
587     new_tri_fan = false;
588     }
589 william 62 }
590 william 31 } GSinternal;
591    
592     extern GSinternal gs;
593    
594 william 314 // Note the function is used in a template parameter so it must be declared extern
595     // Note2: In this case extern is not compatible with __forceinline so just inline it...
596     extern inline u16 RGBA32to16(u32 c)
597 william 31 {
598     return (u16)((((c) & 0x000000f8) >> 3) |
599     (((c) & 0x0000f800) >> 6) |
600     (((c) & 0x00f80000) >> 9) |
601     (((c) & 0x80000000) >> 16));
602     }
603    
604     static __forceinline u32 RGBA16to32(u16 c)
605     {
606     return (((c) & 0x001f) << 3) |
607     (((c) & 0x03e0) << 6) |
608     (((c) & 0x7c00) << 9) |
609     (((c) & 0x8000) ? 0xff000000 : 0);
610     }
611    
612 william 312 #if 0
613 william 31 // converts float16 [0,1] to BYTE [0,255] (assumes value is in range, otherwise will take lower 8bits)
614     // f is a u16
615     static __forceinline u16 Float16ToBYTE(u16 f)
616     {
617     //assert( !(f & 0x8000) );
618     if (f & 0x8000) return 0;
619    
620     u16 d = ((((f & 0x3ff) | 0x400) * 255) >> (10 - ((f >> 10) & 0x1f) + 15));
621    
622     return d > 255 ? 255 : d;
623     }
624    
625     static __forceinline u16 Float16ToALPHA(u16 f)
626     {
627     //assert( !(f & 0x8000) );
628     if (f & 0x8000) return 0;
629    
630     // round up instead of down (crash and burn), too much and charlie breaks
631     u16 d = (((((f & 0x3ff) | 0x400)) * 255) >> (10 - ((f >> 10) & 0x1f) + 15));
632    
633     d = (d) >> 1;
634    
635     return d > 255 ? 255 : d;
636     }
637    
638     #ifndef COLOR_ARGB
639     #define COLOR_ARGB(a,r,g,b) \
640     ((u32)((((a)&0xff)<<24)|(((r)&0xff)<<16)|(((g)&0xff)<<8)|((b)&0xff)))
641     #endif
642    
643     // assumes that positive in [1,2] (then extracts fraction by just looking at the specified bits)
644     #define Float16ToBYTE_2(f) ((u8)(*(u16*)&f>>2))
645     #define Float16To5BIT(f) (Float16ToBYTE(f)>>3)
646    
647     #define Float16Alpha(f) (((*(u16*)&f&0x7c00)>=0x3900)?0x8000:0) // alpha is >= 1
648    
649     // converts an array of 4 u16s to a u32 color
650     // f is a pointer to a u16
651     #define Float16ToARGB(f) COLOR_ARGB(Float16ToALPHA(f.w), Float16ToBYTE(f.x), Float16ToBYTE(f.y), Float16ToBYTE(f.z));
652    
653     #define Float16ToARGB16(f) (Float16Alpha(f.w)|(Float16To5BIT(f.x)<<10)|(Float16To5BIT(f.y)<<5)|Float16To5BIT(f.z))
654    
655     // used for Z values
656     #define Float16ToARGB_Z(f) COLOR_ARGB((u32)Float16ToBYTE_2(f.w), Float16ToBYTE_2(f.x), Float16ToBYTE_2(f.y), Float16ToBYTE_2(f.z))
657     #define Float16ToARGB16_Z(f) ((Float16ToBYTE_2(f.y)<<8)|Float16ToBYTE_2(f.z))
658 william 312 #endif
659 william 31
660    
661     inline float Clamp(float fx, float fmin, float fmax)
662     {
663     if (fx < fmin) return fmin;
664    
665     return fx > fmax ? fmax : fx;
666     }
667    
668 william 163 // Get pixel storage format from tex0. Clutted textures store pixels in cpsm format.
669     inline int PIXEL_STORAGE_FORMAT(const tex0Info& tex) {
670     if (PSMT_ISCLUT(tex.psm))
671     return tex.cpsm;
672     else
673     return tex.psm;
674     }
675    
676     // If pixel storage format not PSMCT24 ot PSMCT32, then it is 16-bit.
677     // Z-textures have 0x30 upper bits, so we eliminate them by &&(~0x30)
678     inline bool PSMT_ISHALF_STORAGE(const tex0Info& tex0) { return ((PIXEL_STORAGE_FORMAT(tex0) & (~0x30)) > 1); }
679 william 31
680     //--------------------------- Inlines for bitwise ops
681     //--------------------------- textures
682     // Tex0Info (TEXD_x registers) bits, lower word
683     // The register is really 64-bit, but we use 2 32bit ones to represent it
684     // Obtain tbp0 -- Texture Buffer Base Pointer (Word Address/64) -- from data. Bits 0-13.
685     static __forceinline int ZZOglGet_tbp0_TexBits(u32 data)
686     {
687     //return tex_0_info(data).tbp0;
688     return (data) & 0x3fff;
689     }
690    
691     // Obtain tbw -- Texture Buffer Width (Texels/64) -- from data, do not multiply to 64. Bits 14-19
692     // ( data & 0xfc000 ) >> 14
693     static __forceinline int ZZOglGet_tbw_TexBits(u32 data)
694     {
695     //return tex_0_info(data).tbw;
696     return (data >> 14) & 0x3f;
697     }
698    
699     // Obtain tbw -- Texture Buffer Width (Texels) -- from data, do multiply to 64, never return 0.
700     static __forceinline int ZZOglGet_tbw_TexBitsMult(u32 data)
701     {
702     //return text_0_info(data).tbw_mult();
703     int result = ZZOglGet_tbw_TexBits(data);
704    
705     if (result == 0)
706     return 64;
707     else
708     return (result << 6);
709     }
710    
711     // Obtain psm -- Pixel Storage Format -- from data. Bits 20-25.
712     // (data & 0x3f00000) >> 20
713     static __forceinline int ZZOglGet_psm_TexBits(u32 data)
714     {
715     //return tex_0_info(data).psm;
716     return ((data >> 20) & 0x3f);
717     }
718    
719     // Obtain psm -- Pixel Storage Format -- from data. Bits 20-25. Fix incorrect psm == 9
720     static __forceinline int ZZOglGet_psm_TexBitsFix(u32 data)
721     {
722     //return tex_0_info(data).psm_fix();
723     int result = ZZOglGet_psm_TexBits(data) ;
724 william 314 // ZZLog::Debug_Log("result %d", result);
725 william 31
726     if (result == 9) result = 1;
727    
728     return result;
729     }
730    
731     // Obtain tw -- Texture Width (Width = 2^TW) -- from data. Bits 26-29
732     // (data & 0x3c000000)>>26
733     static __forceinline u16 ZZOglGet_tw_TexBits(u32 data)
734     {
735     //return tex_0_info(data).tw;
736     return ((data >> 26) & 0xf);
737     }
738    
739     // Obtain tw -- Texture Width (Width = TW) -- from data. Width could newer be more than 1024.
740     static __forceinline u16 ZZOglGet_tw_TexBitsExp(u32 data)
741     {
742     //return tex_0_info(data).tw_exp();
743     u16 result = ZZOglGet_tw_TexBits(data);
744    
745     if (result > 10) result = 10;
746    
747     return (1 << result);
748     }
749    
750     // TH set at the border of upper and higher words.
751     // Obtain th -- Texture Height (Height = 2^TH) -- from data. Bits 30-31 lower, 0-1 higher
752     // (dataLO & 0xc0000000) >> 30 + (dataHI & 0x3) * 0x4
753     static __forceinline u16 ZZOglGet_th_TexBits(u32 dataLO, u32 dataHI)
754     {
755     //return tex_0_info(dataLO, dataHI).th;
756     return (((dataLO >> 30) & 0x3) | ((dataHI & 0x3) << 2));
757     }
758    
759     // Obtain th --Texture Height (Height = 2^TH) -- from data. Height could newer be more than 1024.
760     static __forceinline u16 ZZOglGet_th_TexBitsExp(u32 dataLO, u32 dataHI)
761     {
762     //return tex_0_info(dataLO, dataHI).th_exp();
763     u16 result = ZZOglGet_th_TexBits(dataLO, dataHI);
764    
765     if (result > 10) result = 10;
766    
767     return (1 << result);
768     }
769    
770     // Tex0Info bits, higher word.
771     // Obtain tcc -- Texture Color Component 0=RGB, 1=RGBA + use Alpha from TEXA reg when not in PSM -- from data. Bit 3
772     // (data & 0x4)>>2
773     static __forceinline u8 ZZOglGet_tcc_TexBits(u32 data)
774     {
775     //return tex_0_info(0, data).tcc;
776     return ((data >> 2) & 0x1);
777     }
778    
779     // Obtain tfx -- Texture Function (0=modulate, 1=decal, 2=hilight, 3=hilight2) -- from data. Bit 4-5
780     // (data & 0x18)>>3
781     static __forceinline u8 ZZOglGet_tfx_TexBits(u32 data)
782     {
783     //return tex_0_info(0, data).tfx;
784     return ((data >> 3) & 0x3);
785     }
786    
787     // Obtain cbp from data -- Clut Buffer Base Pointer (Address/256) -- Bits 5-18
788     // (data & 0x7ffe0)>>5
789     static __forceinline int ZZOglGet_cbp_TexBits(u32 data)
790     {
791     //return tex_0_info(0, data).cbp;
792     return ((data >> 5) & 0x3fff);
793     }
794    
795     // Obtain cpsm from data -- Clut pixel Storage Format -- Bits 19-22. 22nd is at no use.
796     // (data & 0x700000)>>19
797     // 0000 - psmct32; 0010 - psmct16; 1010 - psmct16s.
798     static __forceinline u8 ZZOglGet_cpsm_TexBits(u32 data)
799     {
800     //return (tex_0_info(0, data).cpsm & 0xe);
801     return ((data >> 19) & 0xe);
802     }
803    
804     // Obtain csm -- I don't know what is it -- from data. Bit 23
805     // (data & 0x800000)>>23
806     // csm is the clut storage mode. 0 for CSM1, 1 for CSM2.
807     static __forceinline u8 ZZOglGet_csm_TexBits(u32 data)
808     {
809     //return tex_0_info(0, data).csm;
810     return ((data >> 23) & 0x1);
811     }
812    
813     // Obtain csa -- -- from data. Bits 24-28
814     // (data & 0x1f000000)>>24
815     static __forceinline u8 ZZOglGet_csa_TexBits(u32 data)
816     {
817     //return tex_0_info(0, data).csa_fix();
818    
819     if ((data & 0x700000) == 0) // it is cpsm < 2 check
820     return ((data >> 24) & 0xf);
821     else
822     return ((data >> 24) & 0x1f);
823     }
824    
825     // Obtain cld -- -- from data. Bits 29-31
826     // (data & 0xe0000000)>>29
827     static __forceinline u8 ZZOglGet_cld_TexBits(u32 data)
828     {
829     //return tex_0_info(0, data).cld;
830     return ((data >> 29) & 0x7);
831     }
832    
833     //-------------------------- frames
834     // FrameInfo bits.
835     // Obtain fbp -- frame Buffer Base Pointer (Word Address/2048) -- from data. Bits 0-15
836     inline int ZZOglGet_fbp_FrameBits(u32 data)
837     {
838     return ((data) & 0x1ff);
839     }
840    
841     // So we got address / 64, henceby frame fbp and tex tbp have the same dimension -- "real address" is x64.
842     inline int ZZOglGet_fbp_FrameBitsMult(u32 data)
843     {
844     return (ZZOglGet_fbp_FrameBits(data) << 5);
845     }
846    
847     // Obtain fbw -- width (Texels/64) -- from data. Bits 16-23
848     inline int ZZOglGet_fbw_FrameBits(u32 data)
849     {
850     return ((data >> 16) & 0x3f);
851     }
852    
853     inline int ZZOglGet_fbw_FrameBitsMult(u32 data)
854     {
855     return (ZZOglGet_fbw_FrameBits(data) << 6);
856     }
857    
858    
859     // Obtain psm -- Pixel Storage Format -- from data. Bits 24-29.
860     // (data & 0x3f000000) >> 24
861     inline int ZZOglGet_psm_FrameBits(u32 data)
862     {
863     return ((data >> 24) & 0x3f);
864     }
865    
866     // Function for calculating overal height from frame data.
867     inline int ZZOgl_fbh_Calc(int fbp, int fbw, int psm)
868     {
869     int fbh = (1024 * 1024 - 64 * fbp) / fbw;
870     fbh &= ~0x1f;
871    
872     if (PSMT_ISHALF(psm)) fbh *= 2;
873     if (fbh > 1024) fbh = 1024;
874    
875 william 62 //ZZLog::Debug_Log("ZZOgl_fbh_Calc: 0x%x", fbh);
876     return fbh;
877 william 31 }
878    
879     inline int ZZOgl_fbh_Calc(frameInfo frame)
880     {
881     return ZZOgl_fbh_Calc(frame.fbp, frame.fbw, frame.psm);
882     }
883    
884     // Calculate fbh from data, It does not set in register
885     inline int ZZOglGet_fbh_FrameBitsCalc(u32 data)
886     {
887     int fbh = 0;
888     int fbp = ZZOglGet_fbp_FrameBits(data);
889     int fbw = ZZOglGet_fbw_FrameBits(data);
890     int psm = ZZOglGet_psm_FrameBits(data);
891    
892     if (fbw > 0) fbh = ZZOgl_fbh_Calc(fbp, fbw, psm) ;
893    
894     return fbh ;
895     }
896    
897     // Obtain fbm -- frame mask -- from data. All higher word.
898     inline u32 ZZOglGet_fbm_FrameBits(u32 data)
899     {
900     return (data);
901     }
902    
903     // Obtain fbm -- frame mask -- from data. All higher word. Fixed from psm == PCMT24 (without alpha)
904     inline u32 ZZOglGet_fbm_FrameBitsFix(u32 dataLO, u32 dataHI)
905     {
906     if (PSMT_BITMODE(ZZOglGet_psm_FrameBits(dataLO)) == 1)
907     return (dataHI | 0xff000000);
908     else
909     return dataHI;
910     }
911    
912     // obtain colormask RED
913     inline u32 ZZOglGet_fbmRed_FrameBits(u32 data)
914     {
915     return (data & 0xff);
916     }
917    
918     // obtain colormask Green
919     inline u32 ZZOglGet_fbmGreen_FrameBits(u32 data)
920     {
921     return ((data >> 8) & 0xff);
922     }
923    
924     // obtain colormask Blue
925     inline u32 ZZOglGet_fbmBlue_FrameBits(u32 data)
926     {
927     return ((data >> 16) & 0xff);
928     }
929    
930     // obtain colormask Alpha
931     inline u32 ZZOglGet_fbmAlpha_FrameBits(u32 data)
932     {
933     return ((data >> 24) & 0xff);
934     }
935    
936     // obtain colormask Alpha
937     inline u32 ZZOglGet_fbmHighByte(u32 data)
938     {
939     return (!!(data & 0x80000000));
940     }
941    
942     //-------------------------- tex0 comparison
943     // Check if old and new tex0 registers have only clut difference
944 william 62 inline bool ZZOglAllExceptClutIsSame(const u32* oldtex, const u32* newtex)
945 william 31 {
946     return ((oldtex[0] == newtex[0]) && ((oldtex[1] & 0x1f) == (newtex[1] & 0x1f)));
947     }
948    
949     // Check if the CLUT registers are same, except CLD
950 william 62 inline bool ZZOglClutMinusCLDunchanged(const u32* oldtex, const u32* newtex)
951 william 31 {
952     return ((oldtex[1] & 0x1fffffe0) == (newtex[1] & 0x1fffffe0));
953     }
954    
955     // Check if CLUT storage mode is not changed (CSA, CSM and CSPM)
956 william 62 inline bool ZZOglClutStorageUnchanged(const u32* oldtex, const u32* newtex)
957 william 31 {
958     return ((oldtex[1] & 0x1ff10000) == (newtex[1] & 0x1ff10000));
959     }
960    
961 william 314 // call to load CLUT data (depending on CLD)
962     void texClutWrite(int ctx);
963    
964     // Perform clutting for flushed texture. Better check if it needs a prior call.
965     inline void CluttingForFlushedTex(tex0Info* tex0, u32 Data, int ictx)
966     {
967     tex0->cbp = ZZOglGet_cbp_TexBits(Data);
968     tex0->cpsm = ZZOglGet_cpsm_TexBits(Data);
969     tex0->csm = ZZOglGet_csm_TexBits(Data);
970     tex0->csa = ZZOglGet_csa_TexBits(Data);
971     tex0->cld = ZZOglGet_cld_TexBits(Data);
972    
973     texClutWrite(ictx);
974     };
975    
976 william 31 // CSA and CPSM bitmask 0001 1111 0111 1000 ...
977     // 60 56 52
978     #define CPSM_CSA_BITMASK 0x1f780000
979     #define CPSM_CSA_NOTMASK 0xe0870000
980    
981     #endif

  ViewVC Help
Powered by ViewVC 1.1.22