/[pcsx2_0.9.7]/branch/debug/0.X/0.9.X/0.9.7/r3113/plugins/zerogs/dx/GS.h
ViewVC logotype

Contents of /branch/debug/0.X/0.9.X/0.9.7/r3113/plugins/zerogs/dx/GS.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 171 - (show annotations) (download)
Mon Sep 13 16:38:21 2010 UTC (10 years, 2 months ago) by william
File MIME type: text/plain
File size: 13606 byte(s)
fix warnings

1 /* ZeroGS
2 * Copyright (C) 2005-2006 zerofrog@gmail.com
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 */
18
19 #ifndef __GS_H__
20 #define __GS_H__
21
22 #include <stdio.h>
23 #include <malloc.h>
24
25 #define GSdefs
26 #include "PS2Edefs.h"
27
28 #ifdef _WIN32
29
30 #include <windows.h>
31 #include <windowsx.h>
32
33 extern HWND GShwnd;
34
35 #else
36
37 #include <X11/Xlib.h>
38 #include <X11/Xutil.h>
39 #include <X11/keysym.h>
40 #include <gtk/gtk.h>
41
42 #define __inline inline
43
44 typedef int BOOL;
45
46 #define max(a,b) (((a) > (b)) ? (a) : (b))
47 #define min(a,b) (((a) < (b)) ? (a) : (b))
48
49 #endif
50
51 #if defined(_MSC_VER)
52 #define FASTCALL(fn) __fastcall fn
53 #else
54
55 #ifdef __x86_64
56 #define FASTCALL(fn) fn
57 #else
58 #define FASTCALL(fn) __attribute__((fastcall)) fn
59 #endif
60 #endif
61
62 struct Vector_16F
63 {
64 u16 x, y, z, w;
65 };
66
67
68 /////////////////////
69 // define when releasing
70 // The only code that uses it is commented out!
71 //#define ZEROGS_CACHEDCLEAR // much better performance
72 //#define RELEASE_TO_PUBLIC
73
74 #if defined(ZEROGS_DEVBUILD)
75 #define GS_LOG __Log
76 #else
77 #define GS_LOG 0&&
78 #endif
79
80 #define ERROR_LOG __LogToConsole
81 #define DEBUG_LOG printf
82
83 #ifdef RELEASE_TO_PUBLIC
84 #define WARN_LOG 0&&
85 #define PRIM_LOG 0&&
86 #else
87 #define WARN_LOG printf
88 #define PRIM_LOG if (conf.log & 0x00000010) GS_LOG
89 #endif
90
91 #ifndef GREG_LOG
92 #define GREG_LOG 0&&
93 #endif
94 #ifndef PRIM_LOG
95 #define PRIM_LOG 0&&
96 #endif
97 #ifndef WARN_LOG
98 #define WARN_LOG 0&&
99 #endif
100
101 #define REG64(name) \
102 union name \
103 { \
104 u64 i64; \
105 u32 ai32[2]; \
106 struct { \
107
108 #define REG128(name)\
109 union name \
110 { \
111 u64 ai64[2]; \
112 u32 ai32[4]; \
113 struct { \
114
115 #define REG64_(prefix, name) REG64(prefix##name)
116 #define REG128_(prefix, name) REG128(prefix##name)
117
118 #define REG_END }; };
119 #define REG_END2 };
120
121 #define REG64_SET(name) \
122 union name \
123 { \
124 u64 i64; \
125 u32 ai32[2]; \
126
127 #define REG128_SET(name)\
128 union name \
129 { \
130 u64 ai64[2]; \
131 u32 ai32[4]; \
132
133 #define REG_SET_END };
134
135 REG64_(GSReg, BGCOLOR)
136 u32 R:8;
137 u32 G:8;
138 u32 B:8;
139 u32 _PAD1:8;
140 u32 _PAD2:32;
141 REG_END
142
143 REG64_(GSReg, BUSDIR)
144 u32 DIR:1;
145 u32 _PAD1:31;
146 u32 _PAD2:32;
147 REG_END
148
149 REG64_(GSReg, CSR)
150 u32 SIGNAL:1;
151 u32 FINISH:1;
152 u32 HSINT:1;
153 u32 VSINT:1;
154 u32 EDWINT:1;
155 u32 ZERO1:1;
156 u32 ZERO2:1;
157 u32 _PAD1:1;
158 u32 FLUSH:1;
159 u32 RESET:1;
160 u32 _PAD2:2;
161 u32 NFIELD:1;
162 u32 FIELD:1;
163 u32 FIFO:2;
164 u32 REV:8;
165 u32 ID:8;
166 u32 _PAD3:32;
167 REG_END
168
169 REG64_(GSReg, DISPFB) // (-1/2)
170 u32 FBP:9;
171 u32 FBW:6;
172 u32 PSM:5;
173 u32 _PAD:12;
174 u32 DBX:11;
175 u32 DBY:11;
176 u32 _PAD2:10;
177 REG_END
178
179 REG64_(GSReg, DISPLAY) // (-1/2)
180 u32 DX:12;
181 u32 DY:11;
182 u32 MAGH:4;
183 u32 MAGV:2;
184 u32 _PAD:3;
185 u32 DW:12;
186 u32 DH:11;
187 u32 _PAD2:9;
188 REG_END
189
190 REG64_(GSReg, EXTBUF)
191 u32 EXBP:14;
192 u32 EXBW:6;
193 u32 FBIN:2;
194 u32 WFFMD:1;
195 u32 EMODA:2;
196 u32 EMODC:2;
197 u32 _PAD1:5;
198 u32 WDX:11;
199 u32 WDY:11;
200 u32 _PAD2:10;
201 REG_END
202
203 REG64_(GSReg, EXTDATA)
204 u32 SX:12;
205 u32 SY:11;
206 u32 SMPH:4;
207 u32 SMPV:2;
208 u32 _PAD1:3;
209 u32 WW:12;
210 u32 WH:11;
211 u32 _PAD2:9;
212 REG_END
213
214 REG64_(GSReg, EXTWRITE)
215 u32 WRITE;
216 u32 _PAD2:32;
217 REG_END
218
219 REG64_(GSReg, IMR)
220 u32 _PAD1:8;
221 u32 SIGMSK:1;
222 u32 FINISHMSK:1;
223 u32 HSMSK:1;
224 u32 VSMSK:1;
225 u32 EDWMSK:1;
226 u32 _PAD2:19;
227 u32 _PAD3:32;
228 REG_END
229
230 REG64_(GSReg, PMODE)
231 u32 EN1:1;
232 u32 EN2:1;
233 u32 CRTMD:3;
234 u32 MMOD:1;
235 u32 AMOD:1;
236 u32 SLBG:1;
237 u32 ALP:8;
238 u32 _PAD:16;
239 u32 _PAD1:32;
240 REG_END
241
242 REG64_(GSReg, SIGLBLID)
243 u32 SIGID:32;
244 u32 LBLID:32;
245 REG_END
246
247 REG64_(GSReg, SMODE1)
248 u32 RC:3;
249 u32 LC:7;
250 u32 T1248:2;
251 u32 SLCK:1;
252 u32 CMOD:2;
253 u32 EX:1;
254 u32 PRST:1;
255 u32 SINT:1;
256 u32 XPCK:1;
257 u32 PCK2:2;
258 u32 SPML:4;
259 u32 GCONT:1;
260 u32 PHS:1;
261 u32 PVS:1;
262 u32 PEHS:1;
263 u32 PEVS:1;
264 u32 CLKSEL:2;
265 u32 NVCK:1;
266 u32 SLCK2:1;
267 u32 VCKSEL:2;
268 u32 VHP:1;
269 u32 _PAD1:27;
270 REG_END
271
272 REG64_(GSReg, SMODE2)
273 u32 INT:1;
274 u32 FFMD:1;
275 u32 DPMS:2;
276 u32 _PAD2:28;
277 u32 _PAD3:32;
278 REG_END
279
280 REG64_(GSReg, SIGBLID)
281 u32 SIGID;
282 u32 LBLID;
283 REG_END
284
285 extern int g_LastCRC;
286 extern u8* g_pBasePS2Mem;
287 #define PMODE ((GSRegPMODE*)(g_pBasePS2Mem+0x0000))
288 #define SMODE1 ((GSRegSMODE1*)(g_pBasePS2Mem+0x0010))
289 #define SMODE2 ((GSRegSMODE2*)(g_pBasePS2Mem+0x0020))
290 // SRFSH
291 #define SYNCH1 ((GSRegSYNCH1*)(g_pBasePS2Mem+0x0040))
292 #define SYNCH2 ((GSRegSYNCH2*)(g_pBasePS2Mem+0x0050))
293 #define SYNCV ((GSRegSYNCV*)(g_pBasePS2Mem+0x0060))
294 #define DISPFB1 ((GSRegDISPFB*)(g_pBasePS2Mem+0x0070))
295 #define DISPLAY1 ((GSRegDISPLAY*)(g_pBasePS2Mem+0x0080))
296 #define DISPFB2 ((GSRegDISPFB*)(g_pBasePS2Mem+0x0090))
297 #define DISPLAY2 ((GSRegDISPLAY*)(g_pBasePS2Mem+0x00a0))
298 #define EXTBUF ((GSRegEXTBUF*)(g_pBasePS2Mem+0x00b0))
299 #define EXTDATA ((GSRegEXTDATA*)(g_pBasePS2Mem+0x00c0))
300 #define EXTWRITE ((GSRegEXTWRITE*)(g_pBasePS2Mem+0x00d0))
301 #define BGCOLOR ((GSRegBGCOLOR*)(g_pBasePS2Mem+0x00e0))
302 #define CSR ((GSRegCSR*)(g_pBasePS2Mem+0x1000))
303 #define IMR ((GSRegIMR*)(g_pBasePS2Mem+0x1010))
304 #define BUSDIR ((GSRegBUSDIR*)(g_pBasePS2Mem+0x1040))
305 #define SIGLBLID ((GSRegSIGBLID*)(g_pBasePS2Mem+0x1080))
306
307 #define GET_GSFPS (((SMODE1->CMOD&1) ? 50 : 60) / (SMODE2->INT ? 1 : 2))
308
309 //
310 // sps2tags.h
311 //
312 #ifdef _M_AMD64
313 #define GET_GIF_REG(tag, reg) \
314 (((tag).ai64[1] >> ((reg) << 2)) & 0xf)
315 #else
316 #define GET_GIF_REG(tag, reg) \
317 (((tag).ai32[2 + ((reg) >> 3)] >> (((reg) & 7) << 2)) & 0xf)
318 #endif
319
320 //
321 // GIFTag
322 REG128(GIFTag)
323 u32 NLOOP:15;
324 u32 EOP:1;
325 u32 _PAD1:16;
326 u32 _PAD2:14;
327 u32 PRE:1;
328 u32 PRIM:11;
329 u32 FLG:2; // enum GIF_FLG
330 u32 NREG:4;
331 u64 REGS:64;
332 REG_END
333
334 typedef struct {
335 int x, y, w, h;
336 } Rect;
337
338 typedef struct {
339 int x, y;
340 } Point;
341
342 typedef struct {
343 int x0, y0;
344 int x1, y1;
345 } Rect2;
346
347 typedef struct {
348 int x, y, c;
349 } PointC;
350
351 #define GSOPTION_FULLSCREEN 0x2
352 #define GSOPTION_BMPSNAP 0x4
353 #define GSOPTION_CAPTUREAVI 0x8
354
355 #define GSOPTION_WINDIMS 0x70
356 #define GSOPTION_WIN640 0x00
357 #define GSOPTION_WIN800 0x10
358 #define GSOPTION_WIN1024 0x20
359 #define GSOPTION_WIN1280 0x30
360 #define GSOPTION_WIN960W 0x40
361 #define GSOPTION_WIN1280W 0x50
362 #define GSOPTION_WIN1920W 0x60
363
364 #define GSOPTION_WIREFRAME 0x100
365 #define GSOPTION_WIDESCREEN 0x200
366 #define GSOPTION_LOADED 0x8000
367
368 typedef struct {
369 u8 mrtdepth; // write color in render target
370 u8 interlace;
371 u8 aa; // antialiasing 0 - off, 1 - 2x, 2 - 4x
372 u8 bilinear; // set to enable bilinear support
373 u32 options;
374 u32 gamesettings; // default game settings
375 int width, height;
376 int winstyle; // window style before full screen
377 #ifdef GS_LOG
378 u32 log;
379 #endif
380 } GSconf;
381
382 #define VERTEXGPU \
383 union \
384 { \
385 struct \
386 { \
387 u16 x, y, f, resv0; /* note: xy is 12d3*/ \
388 u32 rgba; \
389 u32 z; \
390 }; \
391 }; \
392 \
393 float s, t, q; \
394
395 typedef struct {
396 s16 x, y, f, resv0; /* note: xy is 12d3*/ \
397 u32 rgba;
398 u32 z;
399 float s, t, q;
400 } VertexGPU;
401
402 typedef struct {
403 VERTEXGPU
404 u16 u, v;
405 } Vertex;
406
407 extern int g_GameSettings;
408 extern GSconf conf;
409 extern int ppf;
410
411 #define PSMCT32 0
412 #define PSMCT24 1
413 #define PSMCT16 2
414 #define PSMCT16S 10
415 #define PSMT8 19
416 #define PSMT4 20
417 #define PSMT8H 27
418 #define PSMT4HL 36
419 #define PSMT4HH 44
420 #define PSMT32Z 48
421 #define PSMT24Z 49
422 #define PSMT16Z 50
423 #define PSMT16SZ 58
424
425 #define PSMT_ISCLUT(psm) (((psm)&0x7)>2)
426 #define PSMT_IS16BIT(psm) (((psm)&7)==2||((psm)&7)==10)
427
428 typedef struct {
429 int nloop;
430 int eop;
431 int nreg;
432 } tagInfo;
433
434 typedef union {
435 s64 SD;
436 u64 UD;
437 s32 SL[2];
438 u32 UL[2];
439 s16 SS[4];
440 u16 US[4];
441 s8 SC[8];
442 u8 UC[8];
443 } reg64;
444
445 /* general purpose regs structs */
446 typedef struct {
447 int fbp;
448 int fbw;
449 int fbh;
450 int psm;
451 u32 fbm;
452 } frameInfo;
453
454 typedef struct {
455 u16 prim;
456
457 union {
458 struct {
459 u16 iip : 1;
460 u16 tme : 1;
461 u16 fge : 1;
462 u16 abe : 1;
463 u16 aa1 : 1;
464 u16 fst : 1;
465 u16 ctxt : 1;
466 u16 fix : 1;
467 u16 resv : 8;
468 };
469 u16 _val;
470 };
471 } primInfo;
472
473 extern primInfo *prim;
474
475 typedef union {
476 struct {
477 u32 ate : 1;
478 u32 atst : 3;
479 u32 aref : 8;
480 u32 afail : 2;
481 u32 date : 1;
482 u32 datm : 1;
483 u32 zte : 1;
484 u32 ztst : 2;
485 u32 resv : 13;
486 };
487 u32 _val;
488 } pixTest;
489
490 typedef struct {
491 int bp;
492 int bw;
493 int psm;
494 } bufInfo;
495
496 typedef struct {
497 int tbp0;
498 int tbw;
499 int cbp;
500 u16 tw, th;
501 u8 psm;
502 u8 tcc;
503 u8 tfx;
504 u8 cpsm;
505 u8 csm;
506 u8 csa;
507 u8 cld;
508 } tex0Info;
509
510 #define TEX_MODULATE 0
511 #define TEX_DECAL 1
512 #define TEX_HIGHLIGHT 2
513 #define TEX_HIGHLIGHT2 3
514
515 typedef struct {
516 int lcm;
517 int mxl;
518 int mmag;
519 int mmin;
520 int mtba;
521 int l;
522 int k;
523 } tex1Info;
524
525 typedef struct {
526 int wms;
527 int wmt;
528 int minu;
529 int maxu;
530 int minv;
531 int maxv;
532 } clampInfo;
533
534 typedef struct {
535 int cbw;
536 int cou;
537 int cov;
538 } clutInfo;
539
540 typedef struct {
541 int tbp[3];
542 int tbw[3];
543 } miptbpInfo;
544
545 typedef struct {
546 u16 aem;
547 u8 ta[2];
548 float fta[2];
549 } texaInfo;
550
551 typedef struct {
552 int sx;
553 int sy;
554 int dx;
555 int dy;
556 int dir;
557 } trxposInfo;
558
559 typedef struct {
560 union {
561 struct {
562 u8 a : 2;
563 u8 b : 2;
564 u8 c : 2;
565 u8 d : 2;
566 };
567 u8 abcd;
568 };
569
570 u8 fix : 8;
571 } alphaInfo;
572
573 typedef struct {
574 u16 zbp; // word address / 64
575 u8 psm;
576 u8 zmsk;
577 } zbufInfo;
578
579 typedef struct {
580 int fba;
581 } fbaInfo;
582
583 typedef struct {
584 int mode;
585 int regn;
586 u64 regs;
587 tagInfo tag;
588 } pathInfo;
589
590 typedef struct {
591 Vertex gsvertex[3];
592 u32 rgba;
593 float q;
594 Vertex vertexregs;
595
596 int primC; // number of verts current storing
597 int primIndex; // current prim index
598 int nTriFanVert;
599
600 int prac;
601 int dthe;
602 int colclamp;
603 int fogcol;
604 int smask;
605 int pabe;
606 u64 buff[2];
607 int buffsize;
608 int cbp[2]; // internal cbp registers
609
610 u32 CSRw;
611
612 primInfo _prim[2];
613 bufInfo srcbuf, srcbufnew;
614 bufInfo dstbuf, dstbufnew;
615
616 clutInfo clut;
617
618 texaInfo texa;
619 trxposInfo trxpos, trxposnew;
620
621 int imageWtemp, imageHtemp;
622
623 int imageTransfer;
624 int imageWnew, imageHnew, imageX, imageY, imageEndX, imageEndY;
625
626 pathInfo path1;
627 pathInfo path2;
628 pathInfo path3;
629
630 } GSinternal;
631
632 extern GSinternal gs;
633
634 extern FILE *gsLog;
635
636 void __Log(const char *fmt, ...);
637 void __LogToConsole(const char *fmt, ...);
638
639 void LoadConfig();
640 void SaveConfig();
641
642 extern void (*GSirq)();
643
644 void *SysLoadLibrary(char *lib); // Loads Library
645 void *SysLoadSym(void *lib, char *sym); // Loads Symbol from Library
646 char *SysLibError(); // Gets previous error loading sysbols
647 void SysCloseLibrary(void *lib); // Closes Library
648 void SysMessage(char *fmt, ...);
649
650 extern "C" void * memcpy_amd(void *dest, const void *src, size_t n);
651 extern "C" u8 memcmp_mmx(const void *dest, const void *src, int n);
652
653 template <typename T>
654 class CInterfacePtr
655 {
656 public:
657 inline CInterfacePtr() : ptr(NULL) {}
658 inline explicit CInterfacePtr(T* newptr) : ptr(newptr) { if ( ptr != NULL ) ptr->AddRef(); }
659 inline ~CInterfacePtr() { if( ptr != NULL ) ptr->Release(); }
660
661 inline T* operator* () { assert( ptr != NULL); return *ptr; }
662 inline T* operator->() { return ptr; }
663 inline T* get() { return ptr; }
664
665 inline void release() {
666 if( ptr != NULL ) { ptr->Release(); ptr = NULL; }
667 }
668
669 inline operator T*() { return ptr; }
670
671 inline bool operator==(T* rhs) { return ptr == rhs; }
672 inline bool operator!=(T* rhs) { return ptr != rhs; }
673
674 inline CInterfacePtr& operator= (T* newptr) {
675 if( ptr != NULL ) ptr->Release();
676 ptr = newptr;
677
678 if( ptr != NULL ) ptr->AddRef();
679 return *this;
680 }
681
682 private:
683 T* ptr;
684 };
685
686 #define RGBA32to16(c) \
687 (u16)((((c) & 0x000000f8) >> 3) | \
688 (((c) & 0x0000f800) >> 6) | \
689 (((c) & 0x00f80000) >> 9) | \
690 (((c) & 0x80000000) >> 16)) \
691
692 #define RGBA16to32(c) \
693 (((c) & 0x001f) << 3) | \
694 (((c) & 0x03e0) << 6) | \
695 (((c) & 0x7c00) << 9) | \
696 (((c) & 0x8000) ? 0xff000000 : 0) \
697
698 // converts float16 [0,1] to BYTE [0,255] (assumes value is in range, otherwise will take lower 8bits)
699 // f is a u16
700 __forceinline u16 Float16ToBYTE(u16 f) {
701 //assert( !(f & 0x8000) );
702 if( f & 0x8000 ) return 0;
703
704 u16 d = ((((f&0x3ff)|0x400)*255)>>(10-((f>>10)&0x1f)+15));
705 return d > 255 ? 255 : d;
706 }
707
708 __forceinline u16 Float16ToALPHA(u16 f) {
709 //assert( !(f & 0x8000) );
710 if( f & 0x8000 ) return 0;
711
712 // round up instead of down (crash and burn), too much and charlie breaks
713 u16 d = (((((f&0x3ff)|0x400))*255)>>(10-((f>>10)&0x1f)+15));
714 d = (d)>>1;
715 return d > 255 ? 255 : d;
716 }
717
718 #ifndef COLOR_ARGB
719 #define COLOR_ARGB(a,r,g,b) \
720 ((u32)((((a)&0xff)<<24)|(((r)&0xff)<<16)|(((g)&0xff)<<8)|((b)&0xff)))
721 #endif
722
723 // assumes that positive in [1,2] (then extracts fraction by just looking at the specified bits)
724 #define Float16ToBYTE_2(f) ((u8)(*(u16*)&f>>2))
725 #define Float16To5BIT(f) (Float16ToBYTE((u16)f)>>3)
726
727 #define Float16Alpha(f) (((*(u16*)&f&0x7c00)>=0x3900)?0x8000:0) // alpha is >= 1
728
729 // converts an array of 4 u16s to a u32 color
730 // f is a pointer to a u16
731 #define Float16ToARGB(f) COLOR_ARGB(Float16ToALPHA((u16)f.w), Float16ToBYTE((u16)f.x), Float16ToBYTE((u16)f.y), Float16ToBYTE((u16)f.z));
732
733 #define Float16ToARGB16(f) (Float16Alpha((u16)f.w)|(Float16To5BIT((u16)f.x)<<10)|(Float16To5BIT((u16)f.y)<<5)|Float16To5BIT((u16)f.z))
734
735 // used for Z values
736 #define Float16ToARGB_Z(f) COLOR_ARGB(Float16ToBYTE_2((u16)f.w), Float16ToBYTE_2((u16)f.x), Float16ToBYTE_2((u16)f.y), Float16ToBYTE_2((u16)f.z))
737 #define Float16ToARGB16_Z(f) ((Float16ToBYTE_2((u16)f.y)<<8)|Float16ToBYTE_2((u16)f.z))
738
739
740 inline float Clamp(float fx, float fmin, float fmax)
741 {
742 if( fx < fmin ) return fmin;
743 return fx > fmax ? fmax : fx;
744 }
745
746 #include <string>
747
748 extern std::string s_strIniPath;
749
750 #endif

  ViewVC Help
Powered by ViewVC 1.1.22