2010-03-19 00:31:15 +00:00
|
|
|
/* ZeroGS KOSMOS
|
|
|
|
* Copyright (C) 2005-2006 zerofrog@gmail.com
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __GS_H__
|
|
|
|
#define __GS_H__
|
|
|
|
|
2010-04-02 05:53:14 +00:00
|
|
|
#include "Util.h"
|
2010-04-02 06:49:30 +00:00
|
|
|
#include "GifTransfer.h"
|
2010-03-19 00:31:15 +00:00
|
|
|
|
|
|
|
extern float fFPS;
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
#ifdef _WIN32
|
2010-04-02 05:53:14 +00:00
|
|
|
#define GL_WIN32_WINDOW
|
2010-03-19 00:31:15 +00:00
|
|
|
#else
|
2010-03-19 02:04:55 +00:00
|
|
|
#define GL_X11_WINDOW
|
2010-04-02 05:53:14 +00:00
|
|
|
#endif
|
2010-03-27 01:01:31 +00:00
|
|
|
|
2010-03-29 20:45:48 +00:00
|
|
|
#undef CreateWindow // Undo Windows.h global namespace pollution
|
|
|
|
|
2010-06-11 11:48:07 +00:00
|
|
|
#ifdef GL_X11_WINDOW
|
|
|
|
#include <X11/extensions/xf86vmode.h>
|
|
|
|
#endif
|
|
|
|
|
2010-03-19 02:04:55 +00:00
|
|
|
class GLWindow
|
|
|
|
{
|
2010-05-01 22:54:23 +00:00
|
|
|
|
2010-03-19 02:04:55 +00:00
|
|
|
private:
|
|
|
|
#ifdef GL_X11_WINDOW
|
|
|
|
Display *glDisplay;
|
|
|
|
Window glWindow;
|
|
|
|
int glScreen;
|
|
|
|
GLXContext context;
|
|
|
|
XSetWindowAttributes attr;
|
|
|
|
XF86VidModeModeInfo deskMode;
|
|
|
|
#endif
|
|
|
|
bool fullScreen, doubleBuffered;
|
|
|
|
s32 x, y;
|
|
|
|
u32 width, height, depth;
|
|
|
|
|
|
|
|
public:
|
2010-03-19 05:24:36 +00:00
|
|
|
void SwapGLBuffers();
|
2010-03-19 02:04:55 +00:00
|
|
|
void SetTitle(char *strtitle);
|
|
|
|
bool CreateWindow(void *pDisplay);
|
2010-03-19 05:24:36 +00:00
|
|
|
bool ReleaseWindow();
|
2010-03-19 02:04:55 +00:00
|
|
|
void CloseWindow();
|
2010-03-19 05:24:36 +00:00
|
|
|
bool DisplayWindow(int _width, int _height);
|
|
|
|
void ResizeCheck();
|
|
|
|
};
|
|
|
|
|
|
|
|
extern GLWindow GLWin;
|
|
|
|
|
2010-03-19 00:31:15 +00:00
|
|
|
struct Vector_16F
|
|
|
|
{
|
|
|
|
u16 x, y, z, w;
|
|
|
|
};
|
|
|
|
|
|
|
|
REG64_(GSReg, BGCOLOR)
|
|
|
|
u32 R:8;
|
|
|
|
u32 G:8;
|
|
|
|
u32 B:8;
|
|
|
|
u32 _PAD1:8;
|
|
|
|
u32 _PAD2:32;
|
|
|
|
REG_END
|
|
|
|
|
|
|
|
REG64_(GSReg, BUSDIR)
|
|
|
|
u32 DIR:1;
|
|
|
|
u32 _PAD1:31;
|
|
|
|
u32 _PAD2:32;
|
|
|
|
REG_END
|
|
|
|
|
|
|
|
REG64_(GSReg, CSR)
|
|
|
|
u32 SIGNAL:1;
|
|
|
|
u32 FINISH:1;
|
|
|
|
u32 HSINT:1;
|
|
|
|
u32 VSINT:1;
|
|
|
|
u32 EDWINT:1;
|
|
|
|
u32 ZERO1:1;
|
|
|
|
u32 ZERO2:1;
|
|
|
|
u32 _PAD1:1;
|
|
|
|
u32 FLUSH:1;
|
|
|
|
u32 RESET:1;
|
|
|
|
u32 _PAD2:2;
|
|
|
|
u32 NFIELD:1;
|
|
|
|
u32 FIELD:1;
|
|
|
|
u32 FIFO:2;
|
|
|
|
u32 REV:8;
|
|
|
|
u32 ID:8;
|
|
|
|
u32 _PAD3:32;
|
|
|
|
REG_END
|
|
|
|
|
|
|
|
REG64_(GSReg, DISPFB) // (-1/2)
|
|
|
|
u32 FBP:9;
|
|
|
|
u32 FBW:6;
|
|
|
|
u32 PSM:5;
|
|
|
|
u32 _PAD:12;
|
|
|
|
u32 DBX:11;
|
|
|
|
u32 DBY:11;
|
|
|
|
u32 _PAD2:10;
|
|
|
|
REG_END
|
|
|
|
|
|
|
|
REG64_(GSReg, DISPLAY) // (-1/2)
|
|
|
|
u32 DX:12;
|
|
|
|
u32 DY:11;
|
|
|
|
u32 MAGH:4;
|
|
|
|
u32 MAGV:2;
|
|
|
|
u32 _PAD:3;
|
|
|
|
u32 DW:12;
|
|
|
|
u32 DH:11;
|
|
|
|
u32 _PAD2:9;
|
|
|
|
REG_END
|
|
|
|
|
|
|
|
REG64_(GSReg, EXTBUF)
|
|
|
|
u32 EXBP:14;
|
|
|
|
u32 EXBW:6;
|
|
|
|
u32 FBIN:2;
|
|
|
|
u32 WFFMD:1;
|
|
|
|
u32 EMODA:2;
|
|
|
|
u32 EMODC:2;
|
|
|
|
u32 _PAD1:5;
|
|
|
|
u32 WDX:11;
|
|
|
|
u32 WDY:11;
|
|
|
|
u32 _PAD2:10;
|
|
|
|
REG_END
|
|
|
|
|
|
|
|
REG64_(GSReg, EXTDATA)
|
|
|
|
u32 SX:12;
|
|
|
|
u32 SY:11;
|
|
|
|
u32 SMPH:4;
|
|
|
|
u32 SMPV:2;
|
|
|
|
u32 _PAD1:3;
|
|
|
|
u32 WW:12;
|
|
|
|
u32 WH:11;
|
|
|
|
u32 _PAD2:9;
|
|
|
|
REG_END
|
|
|
|
|
|
|
|
REG64_(GSReg, EXTWRITE)
|
|
|
|
u32 WRITE;
|
|
|
|
u32 _PAD2:32;
|
|
|
|
REG_END
|
|
|
|
|
|
|
|
REG64_(GSReg, IMR)
|
|
|
|
u32 _PAD1:8;
|
|
|
|
u32 SIGMSK:1;
|
|
|
|
u32 FINISHMSK:1;
|
|
|
|
u32 HSMSK:1;
|
|
|
|
u32 VSMSK:1;
|
|
|
|
u32 EDWMSK:1;
|
|
|
|
u32 _PAD2:19;
|
|
|
|
u32 _PAD3:32;
|
|
|
|
REG_END
|
|
|
|
|
|
|
|
REG64_(GSReg, PMODE)
|
|
|
|
u32 EN1:1;
|
|
|
|
u32 EN2:1;
|
|
|
|
u32 CRTMD:3;
|
|
|
|
u32 MMOD:1;
|
|
|
|
u32 AMOD:1;
|
|
|
|
u32 SLBG:1;
|
|
|
|
u32 ALP:8;
|
|
|
|
u32 _PAD:16;
|
|
|
|
u32 _PAD1:32;
|
|
|
|
REG_END
|
|
|
|
|
|
|
|
REG64_(GSReg, SIGLBLID)
|
|
|
|
u32 SIGID:32;
|
|
|
|
u32 LBLID:32;
|
|
|
|
REG_END
|
|
|
|
|
|
|
|
REG64_(GSReg, SMODE1)
|
|
|
|
u32 RC:3;
|
|
|
|
u32 LC:7;
|
|
|
|
u32 T1248:2;
|
|
|
|
u32 SLCK:1;
|
|
|
|
u32 CMOD:2;
|
|
|
|
u32 EX:1;
|
|
|
|
u32 PRST:1;
|
|
|
|
u32 SINT:1;
|
|
|
|
u32 XPCK:1;
|
|
|
|
u32 PCK2:2;
|
|
|
|
u32 SPML:4;
|
|
|
|
u32 GCONT:1;
|
|
|
|
u32 PHS:1;
|
|
|
|
u32 PVS:1;
|
|
|
|
u32 PEHS:1;
|
|
|
|
u32 PEVS:1;
|
|
|
|
u32 CLKSEL:2;
|
|
|
|
u32 NVCK:1;
|
|
|
|
u32 SLCK2:1;
|
|
|
|
u32 VCKSEL:2;
|
|
|
|
u32 VHP:1;
|
|
|
|
u32 _PAD1:27;
|
|
|
|
REG_END
|
|
|
|
|
|
|
|
REG64_(GSReg, SMODE2)
|
|
|
|
u32 INT:1;
|
|
|
|
u32 FFMD:1;
|
|
|
|
u32 DPMS:2;
|
|
|
|
u32 _PAD2:28;
|
|
|
|
u32 _PAD3:32;
|
|
|
|
REG_END
|
|
|
|
|
|
|
|
REG64_(GSReg, SIGBLID)
|
|
|
|
u32 SIGID;
|
|
|
|
u32 LBLID;
|
|
|
|
REG_END
|
|
|
|
|
|
|
|
extern int g_LastCRC;
|
|
|
|
extern u8* g_pBasePS2Mem;
|
|
|
|
|
|
|
|
#define PMODE ((GSRegPMODE*)(g_pBasePS2Mem+0x0000))
|
|
|
|
#define SMODE1 ((GSRegSMODE1*)(g_pBasePS2Mem+0x0010))
|
|
|
|
#define SMODE2 ((GSRegSMODE2*)(g_pBasePS2Mem+0x0020))
|
|
|
|
// SRFSH
|
|
|
|
#define SYNCH1 ((GSRegSYNCH1*)(g_pBasePS2Mem+0x0040))
|
|
|
|
#define SYNCH2 ((GSRegSYNCH2*)(g_pBasePS2Mem+0x0050))
|
|
|
|
#define SYNCV ((GSRegSYNCV*)(g_pBasePS2Mem+0x0060))
|
|
|
|
#define DISPFB1 ((GSRegDISPFB*)(g_pBasePS2Mem+0x0070))
|
|
|
|
#define DISPLAY1 ((GSRegDISPLAY*)(g_pBasePS2Mem+0x0080))
|
|
|
|
#define DISPFB2 ((GSRegDISPFB*)(g_pBasePS2Mem+0x0090))
|
|
|
|
#define DISPLAY2 ((GSRegDISPLAY*)(g_pBasePS2Mem+0x00a0))
|
|
|
|
#define EXTBUF ((GSRegEXTBUF*)(g_pBasePS2Mem+0x00b0))
|
|
|
|
#define EXTDATA ((GSRegEXTDATA*)(g_pBasePS2Mem+0x00c0))
|
|
|
|
#define EXTWRITE ((GSRegEXTWRITE*)(g_pBasePS2Mem+0x00d0))
|
|
|
|
#define BGCOLOR ((GSRegBGCOLOR*)(g_pBasePS2Mem+0x00e0))
|
|
|
|
#define CSR ((GSRegCSR*)(g_pBasePS2Mem+0x1000))
|
|
|
|
#define IMR ((GSRegIMR*)(g_pBasePS2Mem+0x1010))
|
|
|
|
#define BUSDIR ((GSRegBUSDIR*)(g_pBasePS2Mem+0x1040))
|
|
|
|
#define SIGLBLID ((GSRegSIGBLID*)(g_pBasePS2Mem+0x1080))
|
|
|
|
|
|
|
|
#define GET_GSFPS (((SMODE1->CMOD&1) ? 50 : 60) / (SMODE2->INT ? 1 : 2))
|
|
|
|
|
|
|
|
//
|
|
|
|
// sps2tags.h
|
|
|
|
//
|
|
|
|
#define GET_GIF_REG(tag, reg) \
|
|
|
|
(((tag).ai32[2 + ((reg) >> 3)] >> (((reg) & 7) << 2)) & 0xf)
|
|
|
|
|
|
|
|
// PS2 vertex
|
2010-05-01 22:54:23 +00:00
|
|
|
|
2010-03-19 00:31:15 +00:00
|
|
|
struct VertexGPU
|
|
|
|
{
|
2010-04-25 00:31:27 +00:00
|
|
|
// gained from XYZ2, XYZ3, XYZF2, XYZF3,
|
2010-03-19 00:31:15 +00:00
|
|
|
// X -- bits 0-15, Y-16-31. Z - 32-63 if no F used, 32-55 otherwise, F (fog) - 56-63
|
2010-04-25 00:31:27 +00:00
|
|
|
// X, Y stored in 12d3 format,
|
2010-03-19 00:31:15 +00:00
|
|
|
s16 x, y, f, resv0; // note: xy is 12d3
|
|
|
|
// Vertex color settings. RGB -- luminance of red/green/blue, A -- alpha. 1.0 == 0x80.
|
|
|
|
// Goes grom RGBAQ register, bits 0-7, 8-15, 16-23 and 24-31 accordingly
|
|
|
|
u32 rgba;
|
|
|
|
u32 z;
|
|
|
|
// Texture coordinates. S & T going from ST register (bits 0-31, and 32-63).
|
|
|
|
// Q goes from RGBAQ register, bits 32-63
|
|
|
|
float s, t, q;
|
|
|
|
};
|
|
|
|
|
|
|
|
// Almost same with previous, controlled by prim.fst flagf
|
2010-05-01 22:54:23 +00:00
|
|
|
|
2010-03-19 00:31:15 +00:00
|
|
|
struct Vertex
|
|
|
|
{
|
|
|
|
u16 x, y, f, resv0; // note: xy is 12d3
|
|
|
|
u32 rgba;
|
|
|
|
u32 z;
|
|
|
|
float s, t, q;
|
|
|
|
// Texel coordinate of vertex. Used if prim.fst == 1
|
|
|
|
// Bits 0-14 and 16-30 of UV
|
|
|
|
u16 u, v;
|
|
|
|
};
|
|
|
|
|
|
|
|
extern GSconf conf;
|
|
|
|
extern int ppf;
|
|
|
|
|
|
|
|
// PSM values
|
|
|
|
// PSM types == Texture Storage Format
|
2010-05-01 22:54:23 +00:00
|
|
|
enum PSM_value
|
|
|
|
{
|
2010-03-19 00:31:15 +00:00
|
|
|
PSMCT32 = 0, // 000000
|
|
|
|
PSMCT24 = 1, // 000001
|
|
|
|
PSMCT16 = 2, // 000010
|
|
|
|
PSMCT16S = 10, // 001010
|
|
|
|
PSMT8 = 19, // 010011
|
|
|
|
PSMT4 = 20, // 010100
|
|
|
|
PSMT8H = 27, // 011011
|
|
|
|
PSMT4HL = 36, // 100100
|
|
|
|
PSMT4HH = 44, // 101100
|
|
|
|
PSMT32Z = 48, // 110000
|
|
|
|
PSMT24Z = 49, // 110001
|
|
|
|
PSMT16Z = 50, // 110010
|
|
|
|
PSMT16SZ = 58, // 111010
|
|
|
|
};
|
|
|
|
|
2010-04-11 08:51:50 +00:00
|
|
|
// Check target bit mode. PSMCT32 and 32Z return 0, 24 and 24Z - 1
|
|
|
|
// 16, 16S, 16Z, 16SZ -- 2, PSMT8 and 8H - 3, PSMT4, 4HL, 4HH -- 4.
|
|
|
|
inline int PSMT_BITMODE(int psm) {return (psm & 0x7);}
|
|
|
|
|
2010-03-19 00:31:15 +00:00
|
|
|
// CLUT = Color look up table. Set proper color to table according CLUT table.
|
|
|
|
// Used for PSMT8, PSMT8H, PSMT4, PSMT4HH, PSMT4HL textures
|
2010-04-11 08:51:50 +00:00
|
|
|
inline bool PSMT_ISCLUT(int psm) { return (PSMT_BITMODE(psm) > 2);}
|
2010-03-19 00:31:15 +00:00
|
|
|
|
|
|
|
// PSMCT16, PSMCT16S, PSMT16Z, PSMT16SZ is 16-bit targets and usually there is
|
|
|
|
// two of them in each 32-bit word.
|
2010-04-11 08:51:50 +00:00
|
|
|
inline bool PSMT_IS16BIT(int psm) { return (PSMT_BITMODE(psm) == 2);}
|
2010-03-19 00:31:15 +00:00
|
|
|
|
|
|
|
// PSMT32Z, PSMT24Z, PSMT16Z, PSMT16SZ is Z-buffer textures
|
|
|
|
inline bool PSMT_ISZTEX(int psm) {return ((psm & 0x30) == 0x30);}
|
|
|
|
|
|
|
|
// PSMCT16, PSMCT16S, PSMT8, PSMT8H, PSMT16Z and PSMT16SZ use only half 16 bit per pixel.
|
2010-03-19 04:36:28 +00:00
|
|
|
inline bool PSMT_ISHALF(int psm) {return ((psm & 2) == 2);}
|
2010-03-19 00:31:15 +00:00
|
|
|
|
|
|
|
// PSMT8 and PSMT8H use IDTEX8 CLUT, PSMT4H, PSMT4HL, PSMT4HH -- IDTEX4.
|
|
|
|
// Don't use it on non clut entries, please!
|
|
|
|
inline bool PSMT_IS8CLUT(int psm) {return ((psm & 3) == 3);}
|
|
|
|
|
|
|
|
// PSM16Z and PSMT16SZ use -1 offset to z-buff. Need to check this thesis.
|
|
|
|
inline bool PSMT_IS16Z(int psm) {return ((psm & 0x32) == 0x32);}
|
|
|
|
|
2010-04-11 08:51:50 +00:00
|
|
|
// Check to see if it is 32 bits. According to code comments, anyways.
|
|
|
|
// I'll have to look closer at it, because it'd seem like it'd return true for 24 bits.
|
|
|
|
inline bool PSMT_IS32BIT(int psm) {return !!(psm <= 1);}
|
2010-03-19 00:31:15 +00:00
|
|
|
|
|
|
|
//----------------------- Data from registers -----------------------
|
|
|
|
|
2010-05-01 22:54:23 +00:00
|
|
|
typedef union
|
|
|
|
{
|
2010-03-19 00:31:15 +00:00
|
|
|
s64 SD;
|
|
|
|
u64 UD;
|
|
|
|
s32 SL[2];
|
|
|
|
u32 UL[2];
|
|
|
|
s16 SS[4];
|
|
|
|
u16 US[4];
|
|
|
|
s8 SC[8];
|
|
|
|
u8 UC[8];
|
|
|
|
} reg64;
|
|
|
|
|
|
|
|
/* general purpose regs structs */
|
2010-05-01 22:54:23 +00:00
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
2010-03-19 00:31:15 +00:00
|
|
|
int fbp;
|
|
|
|
int fbw;
|
|
|
|
int fbh;
|
|
|
|
int psm;
|
|
|
|
u32 fbm;
|
|
|
|
} frameInfo;
|
|
|
|
|
|
|
|
// Create frame structure from known data
|
2010-05-01 22:54:23 +00:00
|
|
|
inline frameInfo CreateFrame(int fbp, int fbw, int fbh, int psm, u32 fbm)
|
|
|
|
{
|
2010-03-19 00:31:15 +00:00
|
|
|
frameInfo frame;
|
|
|
|
frame.fbp = fbp;
|
|
|
|
frame.fbw = fbw;
|
|
|
|
frame.fbh = fbh;
|
|
|
|
frame.psm = psm;
|
|
|
|
frame.fbm = fbm;
|
|
|
|
return frame;
|
|
|
|
}
|
|
|
|
|
2010-05-01 22:54:23 +00:00
|
|
|
typedef struct
|
|
|
|
{
|
2010-03-19 00:31:15 +00:00
|
|
|
u16 prim;
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2010-05-01 22:54:23 +00:00
|
|
|
union
|
|
|
|
{
|
|
|
|
struct
|
|
|
|
{
|
2010-03-19 00:31:15 +00:00
|
|
|
u16 iip : 1;
|
|
|
|
u16 tme : 1;
|
|
|
|
u16 fge : 1;
|
|
|
|
u16 abe : 1;
|
|
|
|
u16 aa1 : 1;
|
|
|
|
u16 fst : 1;
|
|
|
|
u16 ctxt : 1;
|
|
|
|
u16 fix : 1;
|
|
|
|
u16 resv : 8;
|
|
|
|
};
|
|
|
|
u16 _val;
|
|
|
|
};
|
|
|
|
} primInfo;
|
|
|
|
|
|
|
|
extern primInfo *prim;
|
|
|
|
|
2010-05-01 22:54:23 +00:00
|
|
|
typedef union
|
|
|
|
{
|
|
|
|
struct
|
|
|
|
{
|
2010-03-19 00:31:15 +00:00
|
|
|
u32 ate : 1;
|
|
|
|
u32 atst : 3;
|
|
|
|
u32 aref : 8;
|
|
|
|
u32 afail : 2;
|
|
|
|
u32 date : 1;
|
|
|
|
u32 datm : 1;
|
|
|
|
u32 zte : 1;
|
|
|
|
u32 ztst : 2;
|
|
|
|
u32 resv : 13;
|
|
|
|
};
|
|
|
|
u32 _val;
|
|
|
|
} pixTest;
|
|
|
|
|
2010-05-01 22:54:23 +00:00
|
|
|
typedef struct
|
|
|
|
{
|
2010-03-19 00:31:15 +00:00
|
|
|
int bp;
|
|
|
|
int bw;
|
|
|
|
int psm;
|
|
|
|
} bufInfo;
|
|
|
|
|
2010-05-01 22:54:23 +00:00
|
|
|
typedef struct
|
|
|
|
{
|
2010-03-19 00:31:15 +00:00
|
|
|
int tbp0;
|
|
|
|
int tbw;
|
|
|
|
int cbp;
|
|
|
|
u16 tw, th;
|
|
|
|
u8 psm;
|
|
|
|
u8 tcc;
|
|
|
|
u8 tfx;
|
|
|
|
u8 cpsm;
|
|
|
|
u8 csm;
|
|
|
|
u8 csa;
|
|
|
|
u8 cld;
|
|
|
|
} tex0Info;
|
|
|
|
|
2010-04-15 22:03:23 +00:00
|
|
|
union tex_0_info
|
|
|
|
{
|
|
|
|
struct
|
|
|
|
{
|
|
|
|
u64 tbp0 : 14;
|
|
|
|
u64 tbw : 6;
|
|
|
|
u64 psm : 6;
|
|
|
|
u64 tw : 4;
|
|
|
|
u64 th : 4;
|
|
|
|
u64 tcc : 1;
|
|
|
|
u64 tfx : 2;
|
|
|
|
u64 cbp : 14;
|
|
|
|
u64 cpsm : 4;
|
|
|
|
u64 csm : 1;
|
|
|
|
u64 csa : 5;
|
|
|
|
u64 cld : 3;
|
|
|
|
};
|
2010-05-01 22:54:23 +00:00
|
|
|
|
2010-04-15 22:03:23 +00:00
|
|
|
u64 _u64;
|
|
|
|
u32 _u32[2];
|
|
|
|
u16 _u16[4];
|
|
|
|
u8 _u8[8];
|
|
|
|
tex_0_info(u64 data) { _u64 = data; }
|
2010-05-01 22:54:23 +00:00
|
|
|
|
2010-04-15 22:03:23 +00:00
|
|
|
tex_0_info(u32 data) { _u32[0] = data; _u32[1] = 0; }
|
2010-05-01 22:54:23 +00:00
|
|
|
|
2010-04-15 22:03:23 +00:00
|
|
|
tex_0_info(u32 data0, u32 data1) { _u32[0] = data0; _u32[1] = data1; }
|
2010-05-01 22:54:23 +00:00
|
|
|
|
2010-04-15 22:03:23 +00:00
|
|
|
u32 tbw_mult()
|
|
|
|
{
|
2010-04-25 00:31:27 +00:00
|
|
|
if (tbw == 0)
|
2010-04-15 22:03:23 +00:00
|
|
|
return 64;
|
2010-04-25 00:31:27 +00:00
|
|
|
else
|
2010-04-30 04:40:31 +00:00
|
|
|
return ((u32)tbw << 6);
|
2010-04-15 22:03:23 +00:00
|
|
|
}
|
2010-05-01 22:54:23 +00:00
|
|
|
|
2010-04-15 22:03:23 +00:00
|
|
|
u32 psm_fix()
|
|
|
|
{
|
2010-05-01 22:54:23 +00:00
|
|
|
// printf ("psm %d\n", psm);
|
|
|
|
if (psm == 9) return 1;
|
|
|
|
|
2010-04-15 22:03:23 +00:00
|
|
|
return psm;
|
|
|
|
}
|
2010-05-01 22:54:23 +00:00
|
|
|
|
2010-04-15 22:03:23 +00:00
|
|
|
u32 tw_exp()
|
|
|
|
{
|
2010-05-01 22:54:23 +00:00
|
|
|
if (tw > 10) return (1 << 10);
|
|
|
|
|
|
|
|
return (1 << tw);
|
2010-04-15 22:03:23 +00:00
|
|
|
}
|
2010-05-01 22:54:23 +00:00
|
|
|
|
2010-04-15 22:03:23 +00:00
|
|
|
u32 th_exp()
|
|
|
|
{
|
2010-05-01 22:54:23 +00:00
|
|
|
if (th > 10) return (1 << 10);
|
|
|
|
|
|
|
|
return (1 << th);
|
2010-04-15 22:03:23 +00:00
|
|
|
}
|
2010-05-01 22:54:23 +00:00
|
|
|
|
2010-04-15 22:03:23 +00:00
|
|
|
u32 cpsm_fix()
|
|
|
|
{
|
|
|
|
return cpsm & 0xe;
|
|
|
|
}
|
2010-05-01 22:54:23 +00:00
|
|
|
|
2010-04-15 22:03:23 +00:00
|
|
|
u32 csa_fix()
|
|
|
|
{
|
|
|
|
if (cpsm < 2)
|
|
|
|
return (csa & 0xf);
|
|
|
|
else
|
|
|
|
return (csa & 0x1f);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2010-03-19 00:31:15 +00:00
|
|
|
#define TEX_MODULATE 0
|
|
|
|
#define TEX_DECAL 1
|
|
|
|
#define TEX_HIGHLIGHT 2
|
|
|
|
#define TEX_HIGHLIGHT2 3
|
|
|
|
|
2010-05-01 22:54:23 +00:00
|
|
|
typedef struct
|
|
|
|
{
|
2010-03-19 00:31:15 +00:00
|
|
|
int lcm;
|
|
|
|
int mxl;
|
|
|
|
int mmag;
|
|
|
|
int mmin;
|
|
|
|
int mtba;
|
|
|
|
int l;
|
|
|
|
int k;
|
|
|
|
} tex1Info;
|
|
|
|
|
2010-05-01 22:54:23 +00:00
|
|
|
typedef struct
|
|
|
|
{
|
2010-03-19 00:31:15 +00:00
|
|
|
int wms;
|
|
|
|
int wmt;
|
|
|
|
int minu;
|
|
|
|
int maxu;
|
|
|
|
int minv;
|
|
|
|
int maxv;
|
|
|
|
} clampInfo;
|
|
|
|
|
2010-05-01 22:54:23 +00:00
|
|
|
typedef struct
|
|
|
|
{
|
2010-03-19 00:31:15 +00:00
|
|
|
int cbw;
|
|
|
|
int cou;
|
|
|
|
int cov;
|
|
|
|
} clutInfo;
|
|
|
|
|
2010-05-01 22:54:23 +00:00
|
|
|
typedef struct
|
|
|
|
{
|
2010-03-19 00:31:15 +00:00
|
|
|
int tbp[3];
|
|
|
|
int tbw[3];
|
|
|
|
} miptbpInfo;
|
|
|
|
|
2010-05-01 22:54:23 +00:00
|
|
|
typedef struct
|
|
|
|
{
|
2010-03-19 00:31:15 +00:00
|
|
|
u16 aem;
|
|
|
|
u8 ta[2];
|
|
|
|
float fta[2];
|
|
|
|
} texaInfo;
|
|
|
|
|
2010-05-01 22:54:23 +00:00
|
|
|
typedef struct
|
|
|
|
{
|
2010-03-19 00:31:15 +00:00
|
|
|
int sx;
|
|
|
|
int sy;
|
|
|
|
int dx;
|
|
|
|
int dy;
|
|
|
|
int dir;
|
|
|
|
} trxposInfo;
|
|
|
|
|
2010-05-01 22:54:23 +00:00
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
union
|
|
|
|
{
|
|
|
|
struct
|
|
|
|
{
|
2010-03-19 00:31:15 +00:00
|
|
|
u8 a : 2;
|
|
|
|
u8 b : 2;
|
|
|
|
u8 c : 2;
|
|
|
|
u8 d : 2;
|
|
|
|
};
|
|
|
|
u8 abcd;
|
|
|
|
};
|
|
|
|
|
|
|
|
u8 fix : 8;
|
|
|
|
} alphaInfo;
|
|
|
|
|
2010-05-01 22:54:23 +00:00
|
|
|
typedef struct
|
|
|
|
{
|
2010-03-19 00:31:15 +00:00
|
|
|
u16 zbp; // u16 address / 64
|
|
|
|
u8 psm;
|
|
|
|
u8 zmsk;
|
|
|
|
} zbufInfo;
|
|
|
|
|
2010-05-01 22:54:23 +00:00
|
|
|
typedef struct
|
|
|
|
{
|
2010-03-19 00:31:15 +00:00
|
|
|
int fba;
|
|
|
|
} fbaInfo;
|
|
|
|
|
2010-05-01 22:54:23 +00:00
|
|
|
typedef struct
|
|
|
|
{
|
2010-03-19 00:31:15 +00:00
|
|
|
Vertex gsvertex[3];
|
|
|
|
u32 rgba;
|
|
|
|
float q;
|
|
|
|
Vertex vertexregs;
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2010-03-19 00:31:15 +00:00
|
|
|
int primC; // number of verts current storing
|
|
|
|
int primIndex; // current prim index
|
|
|
|
int nTriFanVert;
|
|
|
|
|
|
|
|
int prac;
|
|
|
|
int dthe;
|
|
|
|
int colclamp;
|
|
|
|
int fogcol;
|
|
|
|
int smask;
|
|
|
|
int pabe;
|
|
|
|
u64 buff[2];
|
|
|
|
int buffsize;
|
|
|
|
int cbp[2]; // internal cbp registers
|
|
|
|
|
|
|
|
u32 CSRw;
|
|
|
|
|
|
|
|
primInfo _prim[2];
|
|
|
|
bufInfo srcbuf, srcbufnew;
|
|
|
|
bufInfo dstbuf, dstbufnew;
|
|
|
|
|
|
|
|
clutInfo clut;
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2010-03-19 00:31:15 +00:00
|
|
|
texaInfo texa;
|
|
|
|
trxposInfo trxpos, trxposnew;
|
|
|
|
|
|
|
|
int imageWtemp, imageHtemp;
|
|
|
|
|
2010-04-25 00:31:27 +00:00
|
|
|
int imageTransfer;
|
2010-03-19 00:31:15 +00:00
|
|
|
int imageWnew, imageHnew, imageX, imageY, imageEndX, imageEndY;
|
|
|
|
|
2010-04-02 02:44:14 +00:00
|
|
|
pathInfo path[3];
|
2010-03-19 00:31:15 +00:00
|
|
|
|
|
|
|
} GSinternal;
|
|
|
|
|
|
|
|
extern GSinternal gs;
|
|
|
|
|
2010-03-27 01:01:31 +00:00
|
|
|
static __forceinline u16 RGBA32to16(u32 c)
|
|
|
|
{
|
|
|
|
return (u16)((((c) & 0x000000f8) >> 3) |
|
2010-05-01 22:54:23 +00:00
|
|
|
(((c) & 0x0000f800) >> 6) |
|
|
|
|
(((c) & 0x00f80000) >> 9) |
|
|
|
|
(((c) & 0x80000000) >> 16));
|
2010-03-27 01:01:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static __forceinline u32 RGBA16to32(u16 c)
|
|
|
|
{
|
2010-05-01 22:54:23 +00:00
|
|
|
return (((c) & 0x001f) << 3) |
|
|
|
|
(((c) & 0x03e0) << 6) |
|
|
|
|
(((c) & 0x7c00) << 9) |
|
|
|
|
(((c) & 0x8000) ? 0xff000000 : 0);
|
2010-03-27 01:01:31 +00:00
|
|
|
}
|
2010-03-19 00:31:15 +00:00
|
|
|
|
|
|
|
// converts float16 [0,1] to BYTE [0,255] (assumes value is in range, otherwise will take lower 8bits)
|
|
|
|
// f is a u16
|
2010-05-01 22:54:23 +00:00
|
|
|
static __forceinline u16 Float16ToBYTE(u16 f)
|
|
|
|
{
|
2010-03-19 00:31:15 +00:00
|
|
|
//assert( !(f & 0x8000) );
|
2010-05-01 22:54:23 +00:00
|
|
|
if (f & 0x8000) return 0;
|
|
|
|
|
|
|
|
u16 d = ((((f & 0x3ff) | 0x400) * 255) >> (10 - ((f >> 10) & 0x1f) + 15));
|
2010-03-19 00:31:15 +00:00
|
|
|
|
|
|
|
return d > 255 ? 255 : d;
|
|
|
|
}
|
|
|
|
|
2010-05-01 22:54:23 +00:00
|
|
|
static __forceinline u16 Float16ToALPHA(u16 f)
|
|
|
|
{
|
2010-03-19 00:31:15 +00:00
|
|
|
//assert( !(f & 0x8000) );
|
2010-05-01 22:54:23 +00:00
|
|
|
if (f & 0x8000) return 0;
|
2010-03-19 00:31:15 +00:00
|
|
|
|
|
|
|
// round up instead of down (crash and burn), too much and charlie breaks
|
2010-05-01 22:54:23 +00:00
|
|
|
u16 d = (((((f & 0x3ff) | 0x400)) * 255) >> (10 - ((f >> 10) & 0x1f) + 15));
|
|
|
|
|
|
|
|
d = (d) >> 1;
|
|
|
|
|
2010-03-19 00:31:15 +00:00
|
|
|
return d > 255 ? 255 : d;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifndef COLOR_ARGB
|
|
|
|
#define COLOR_ARGB(a,r,g,b) \
|
|
|
|
((u32)((((a)&0xff)<<24)|(((r)&0xff)<<16)|(((g)&0xff)<<8)|((b)&0xff)))
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// assumes that positive in [1,2] (then extracts fraction by just looking at the specified bits)
|
|
|
|
#define Float16ToBYTE_2(f) ((u8)(*(u16*)&f>>2))
|
|
|
|
#define Float16To5BIT(f) (Float16ToBYTE(f)>>3)
|
|
|
|
|
|
|
|
#define Float16Alpha(f) (((*(u16*)&f&0x7c00)>=0x3900)?0x8000:0) // alpha is >= 1
|
|
|
|
|
|
|
|
// converts an array of 4 u16s to a u32 color
|
|
|
|
// f is a pointer to a u16
|
|
|
|
#define Float16ToARGB(f) COLOR_ARGB(Float16ToALPHA(f.w), Float16ToBYTE(f.x), Float16ToBYTE(f.y), Float16ToBYTE(f.z));
|
|
|
|
|
|
|
|
#define Float16ToARGB16(f) (Float16Alpha(f.w)|(Float16To5BIT(f.x)<<10)|(Float16To5BIT(f.y)<<5)|Float16To5BIT(f.z))
|
|
|
|
|
|
|
|
// used for Z values
|
|
|
|
#define Float16ToARGB_Z(f) COLOR_ARGB((u32)Float16ToBYTE_2(f.w), Float16ToBYTE_2(f.x), Float16ToBYTE_2(f.y), Float16ToBYTE_2(f.z))
|
|
|
|
#define Float16ToARGB16_Z(f) ((Float16ToBYTE_2(f.y)<<8)|Float16ToBYTE_2(f.z))
|
|
|
|
|
|
|
|
|
|
|
|
inline float Clamp(float fx, float fmin, float fmax)
|
|
|
|
{
|
2010-05-01 22:54:23 +00:00
|
|
|
if (fx < fmin) return fmin;
|
|
|
|
|
2010-03-19 00:31:15 +00:00
|
|
|
return fx > fmax ? fmax : fx;
|
|
|
|
}
|
|
|
|
|
|
|
|
// PSMT16, 16S have shorter color per pixel, also cluted textures with half storage.
|
2010-05-01 22:54:23 +00:00
|
|
|
inline bool PSMT_ISHALF_STORAGE(const tex0Info& tex0)
|
|
|
|
{
|
2010-03-19 00:31:15 +00:00
|
|
|
if (PSMT_IS16BIT(tex0.psm) || (PSMT_ISCLUT(tex0.psm) && tex0.cpsm > 1))
|
|
|
|
return true;
|
|
|
|
else
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------- Inlines for bitwise ops
|
|
|
|
//--------------------------- textures
|
2010-04-25 00:31:27 +00:00
|
|
|
// Tex0Info (TEXD_x registers) bits, lower word
|
2010-03-19 00:31:15 +00:00
|
|
|
// The register is really 64-bit, but we use 2 32bit ones to represent it
|
|
|
|
// Obtain tbp0 -- Texture Buffer Base Pointer (Word Address/64) -- from data. Bits 0-13.
|
2010-04-25 00:31:27 +00:00
|
|
|
static __forceinline int ZZOglGet_tbp0_TexBits(u32 data)
|
|
|
|
{
|
2010-04-15 22:03:23 +00:00
|
|
|
//return tex_0_info(data).tbp0;
|
2010-05-01 22:54:23 +00:00
|
|
|
return (data) & 0x3fff;
|
2010-03-19 00:31:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Obtain tbw -- Texture Buffer Width (Texels/64) -- from data, do not multiply to 64. Bits 14-19
|
|
|
|
// ( data & 0xfc000 ) >> 14
|
2010-04-25 00:31:27 +00:00
|
|
|
static __forceinline int ZZOglGet_tbw_TexBits(u32 data)
|
|
|
|
{
|
2010-04-15 22:03:23 +00:00
|
|
|
//return tex_0_info(data).tbw;
|
2010-03-19 00:31:15 +00:00
|
|
|
return (data >> 14) & 0x3f;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Obtain tbw -- Texture Buffer Width (Texels) -- from data, do multiply to 64, never return 0.
|
2010-04-25 00:31:27 +00:00
|
|
|
static __forceinline int ZZOglGet_tbw_TexBitsMult(u32 data)
|
|
|
|
{
|
2010-04-15 22:03:23 +00:00
|
|
|
//return text_0_info(data).tbw_mult();
|
2010-03-19 00:31:15 +00:00
|
|
|
int result = ZZOglGet_tbw_TexBits(data);
|
2010-05-01 22:54:23 +00:00
|
|
|
|
2010-04-25 00:31:27 +00:00
|
|
|
if (result == 0)
|
2010-03-19 00:31:15 +00:00
|
|
|
return 64;
|
2010-04-25 00:31:27 +00:00
|
|
|
else
|
2010-03-19 00:31:15 +00:00
|
|
|
return (result << 6);
|
|
|
|
}
|
|
|
|
|
2010-04-25 00:31:27 +00:00
|
|
|
// Obtain psm -- Pixel Storage Format -- from data. Bits 20-25.
|
2010-03-19 00:31:15 +00:00
|
|
|
// (data & 0x3f00000) >> 20
|
2010-04-25 00:31:27 +00:00
|
|
|
static __forceinline int ZZOglGet_psm_TexBits(u32 data)
|
|
|
|
{
|
2010-04-15 22:03:23 +00:00
|
|
|
//return tex_0_info(data).psm;
|
2010-05-01 22:54:23 +00:00
|
|
|
return ((data >> 20) & 0x3f);
|
2010-03-19 00:31:15 +00:00
|
|
|
}
|
|
|
|
|
2010-04-25 00:31:27 +00:00
|
|
|
// Obtain psm -- Pixel Storage Format -- from data. Bits 20-25. Fix incorrect psm == 9
|
|
|
|
static __forceinline int ZZOglGet_psm_TexBitsFix(u32 data)
|
|
|
|
{
|
2010-04-15 22:03:23 +00:00
|
|
|
//return tex_0_info(data).psm_fix();
|
2010-03-19 00:31:15 +00:00
|
|
|
int result = ZZOglGet_psm_TexBits(data) ;
|
|
|
|
// printf ("result %d\n", result);
|
2010-05-01 22:54:23 +00:00
|
|
|
|
|
|
|
if (result == 9) result = 1;
|
|
|
|
|
2010-03-19 00:31:15 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Obtain tw -- Texture Width (Width = 2^TW) -- from data. Bits 26-29
|
|
|
|
// (data & 0x3c000000)>>26
|
2010-04-25 00:31:27 +00:00
|
|
|
static __forceinline u16 ZZOglGet_tw_TexBits(u32 data)
|
|
|
|
{
|
2010-04-15 22:03:23 +00:00
|
|
|
//return tex_0_info(data).tw;
|
2010-05-01 22:54:23 +00:00
|
|
|
return ((data >> 26) & 0xf);
|
2010-03-19 00:31:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Obtain tw -- Texture Width (Width = TW) -- from data. Width could newer be more than 1024.
|
2010-04-25 00:31:27 +00:00
|
|
|
static __forceinline u16 ZZOglGet_tw_TexBitsExp(u32 data)
|
|
|
|
{
|
2010-04-15 22:03:23 +00:00
|
|
|
//return tex_0_info(data).tw_exp();
|
2010-03-19 00:31:15 +00:00
|
|
|
u16 result = ZZOglGet_tw_TexBits(data);
|
2010-05-01 22:54:23 +00:00
|
|
|
|
2010-04-15 22:03:23 +00:00
|
|
|
if (result > 10) result = 10;
|
2010-05-01 22:54:23 +00:00
|
|
|
|
|
|
|
return (1 << result);
|
2010-03-19 00:31:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// TH set at the border of upper and higher words.
|
|
|
|
// Obtain th -- Texture Height (Height = 2^TH) -- from data. Bits 30-31 lower, 0-1 higher
|
|
|
|
// (dataLO & 0xc0000000) >> 30 + (dataHI & 0x3) * 0x4
|
2010-04-25 00:31:27 +00:00
|
|
|
static __forceinline u16 ZZOglGet_th_TexBits(u32 dataLO, u32 dataHI)
|
|
|
|
{
|
2010-04-15 22:03:23 +00:00
|
|
|
//return tex_0_info(dataLO, dataHI).th;
|
2010-03-19 00:31:15 +00:00
|
|
|
return (((dataLO >> 30) & 0x3) | ((dataHI & 0x3) << 2));
|
|
|
|
}
|
|
|
|
|
|
|
|
// Obtain th --Texture Height (Height = 2^TH) -- from data. Height could newer be more than 1024.
|
2010-04-25 00:31:27 +00:00
|
|
|
static __forceinline u16 ZZOglGet_th_TexBitsExp(u32 dataLO, u32 dataHI)
|
|
|
|
{
|
2010-04-15 22:03:23 +00:00
|
|
|
//return tex_0_info(dataLO, dataHI).th_exp();
|
2010-03-19 00:31:15 +00:00
|
|
|
u16 result = ZZOglGet_th_TexBits(dataLO, dataHI);
|
2010-05-01 22:54:23 +00:00
|
|
|
|
2010-04-15 22:03:23 +00:00
|
|
|
if (result > 10) result = 10;
|
2010-05-01 22:54:23 +00:00
|
|
|
|
|
|
|
return (1 << result);
|
2010-03-19 00:31:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Tex0Info bits, higher word.
|
2010-04-15 22:03:23 +00:00
|
|
|
// Obtain tcc -- Texture Color Component 0=RGB, 1=RGBA + use Alpha from TEXA reg when not in PSM -- from data. Bit 3
|
2010-03-19 00:31:15 +00:00
|
|
|
// (data & 0x4)>>2
|
2010-04-25 00:31:27 +00:00
|
|
|
static __forceinline u8 ZZOglGet_tcc_TexBits(u32 data)
|
|
|
|
{
|
2010-04-15 22:03:23 +00:00
|
|
|
//return tex_0_info(0, data).tcc;
|
2010-05-01 22:54:23 +00:00
|
|
|
return ((data >> 2) & 0x1);
|
2010-03-19 00:31:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Obtain tfx -- Texture Function (0=modulate, 1=decal, 2=hilight, 3=hilight2) -- from data. Bit 4-5
|
|
|
|
// (data & 0x18)>>3
|
2010-04-25 00:31:27 +00:00
|
|
|
static __forceinline u8 ZZOglGet_tfx_TexBits(u32 data)
|
|
|
|
{
|
2010-04-15 22:03:23 +00:00
|
|
|
//return tex_0_info(0, data).tfx;
|
2010-05-01 22:54:23 +00:00
|
|
|
return ((data >> 3) & 0x3);
|
2010-03-19 00:31:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Obtain cbp from data -- Clut Buffer Base Pointer (Address/256) -- Bits 5-18
|
|
|
|
// (data & 0x7ffe0)>>5
|
2010-04-25 00:31:27 +00:00
|
|
|
static __forceinline int ZZOglGet_cbp_TexBits(u32 data)
|
|
|
|
{
|
2010-04-15 22:03:23 +00:00
|
|
|
//return tex_0_info(0, data).cbp;
|
2010-05-01 22:54:23 +00:00
|
|
|
return ((data >> 5) & 0x3fff);
|
2010-03-19 00:31:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Obtain cpsm from data -- Clut pixel Storage Format -- Bits 19-22. 22nd is at no use.
|
|
|
|
// (data & 0x700000)>>19
|
2010-04-15 22:03:23 +00:00
|
|
|
// 0000 - psmct32; 0010 - psmct16; 1010 - psmct16s.
|
2010-04-25 00:31:27 +00:00
|
|
|
static __forceinline u8 ZZOglGet_cpsm_TexBits(u32 data)
|
|
|
|
{
|
2010-04-15 22:03:23 +00:00
|
|
|
//return (tex_0_info(0, data).cpsm & 0xe);
|
2010-03-19 00:31:15 +00:00
|
|
|
return ((data >> 19) & 0xe);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Obtain csm -- I don't know what is it -- from data. Bit 23
|
|
|
|
// (data & 0x800000)>>23
|
2010-04-15 22:03:23 +00:00
|
|
|
// csm is the clut storage mode. 0 for CSM1, 1 for CSM2.
|
2010-04-25 00:31:27 +00:00
|
|
|
static __forceinline u8 ZZOglGet_csm_TexBits(u32 data)
|
|
|
|
{
|
2010-04-15 22:03:23 +00:00
|
|
|
//return tex_0_info(0, data).csm;
|
2010-03-19 00:31:15 +00:00
|
|
|
return ((data >> 23) & 0x1);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Obtain csa -- -- from data. Bits 24-28
|
|
|
|
// (data & 0x1f000000)>>24
|
2010-04-25 00:31:27 +00:00
|
|
|
static __forceinline u8 ZZOglGet_csa_TexBits(u32 data)
|
|
|
|
{
|
2010-04-15 22:03:23 +00:00
|
|
|
//return tex_0_info(0, data).csa_fix();
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2010-05-01 22:54:23 +00:00
|
|
|
if ((data & 0x700000) == 0) // it is cpsm < 2 check
|
2010-03-19 00:31:15 +00:00
|
|
|
return ((data >> 24) & 0xf);
|
2010-04-25 00:31:27 +00:00
|
|
|
else
|
2010-03-19 00:31:15 +00:00
|
|
|
return ((data >> 24) & 0x1f);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Obtain cld -- -- from data. Bits 29-31
|
|
|
|
// (data & 0xe0000000)>>29
|
2010-04-25 00:31:27 +00:00
|
|
|
static __forceinline u8 ZZOglGet_cld_TexBits(u32 data)
|
|
|
|
{
|
2010-04-15 22:03:23 +00:00
|
|
|
//return tex_0_info(0, data).cld;
|
2010-05-01 22:54:23 +00:00
|
|
|
return ((data >> 29) & 0x7);
|
2010-03-19 00:31:15 +00:00
|
|
|
}
|
|
|
|
|
2010-04-25 00:31:27 +00:00
|
|
|
//-------------------------- frames
|
2010-03-19 00:31:15 +00:00
|
|
|
// FrameInfo bits.
|
|
|
|
// Obtain fbp -- frame Buffer Base Pointer (Word Address/2048) -- from data. Bits 0-15
|
2010-05-01 22:54:23 +00:00
|
|
|
inline int ZZOglGet_fbp_FrameBits(u32 data)
|
|
|
|
{
|
|
|
|
return ((data) & 0x1ff);
|
2010-03-19 00:31:15 +00:00
|
|
|
}
|
|
|
|
|
2010-05-01 22:54:23 +00:00
|
|
|
// So we got address / 64, henceby frame fbp and tex tbp have the same dimension -- "real address" is x64.
|
|
|
|
inline int ZZOglGet_fbp_FrameBitsMult(u32 data)
|
|
|
|
{
|
2010-03-19 00:31:15 +00:00
|
|
|
return (ZZOglGet_fbp_FrameBits(data) << 5);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Obtain fbw -- width (Texels/64) -- from data. Bits 16-23
|
2010-05-01 22:54:23 +00:00
|
|
|
inline int ZZOglGet_fbw_FrameBits(u32 data)
|
|
|
|
{
|
2010-03-19 00:31:15 +00:00
|
|
|
return ((data >> 16) & 0x3f);
|
|
|
|
}
|
|
|
|
|
2010-05-01 22:54:23 +00:00
|
|
|
inline int ZZOglGet_fbw_FrameBitsMult(u32 data)
|
|
|
|
{
|
2010-03-19 00:31:15 +00:00
|
|
|
return (ZZOglGet_fbw_FrameBits(data) << 6);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Obtain psm -- Pixel Storage Format -- from data. Bits 24-29.
|
|
|
|
// (data & 0x3f000000) >> 24
|
2010-05-01 22:54:23 +00:00
|
|
|
inline int ZZOglGet_psm_FrameBits(u32 data)
|
|
|
|
{
|
|
|
|
return ((data >> 24) & 0x3f);
|
2010-03-19 00:31:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Function for calculating overal height from frame data.
|
2010-05-01 22:54:23 +00:00
|
|
|
inline int ZZOgl_fbh_Calc(int fbp, int fbw, int psm)
|
|
|
|
{
|
|
|
|
int fbh = (1024 * 1024 - 64 * fbp) / fbw;
|
2010-03-19 00:31:15 +00:00
|
|
|
fbh &= ~0x1f;
|
2010-05-01 22:54:23 +00:00
|
|
|
|
|
|
|
if (PSMT_ISHALF(psm)) fbh *= 2;
|
|
|
|
if (fbh > 1024) fbh = 1024;
|
|
|
|
|
2010-06-15 10:32:22 +00:00
|
|
|
//ZZLog::Debug_Log("ZZOgl_fbh_Calc: 0x%x", fbh);
|
|
|
|
return fbh;
|
2010-03-19 00:31:15 +00:00
|
|
|
}
|
2010-05-01 22:54:23 +00:00
|
|
|
|
|
|
|
inline int ZZOgl_fbh_Calc(frameInfo frame)
|
|
|
|
{
|
2010-03-19 00:31:15 +00:00
|
|
|
return ZZOgl_fbh_Calc(frame.fbp, frame.fbw, frame.psm);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Calculate fbh from data, It does not set in register
|
2010-05-01 22:54:23 +00:00
|
|
|
inline int ZZOglGet_fbh_FrameBitsCalc(u32 data)
|
|
|
|
{
|
2010-03-19 00:31:15 +00:00
|
|
|
int fbh = 0;
|
|
|
|
int fbp = ZZOglGet_fbp_FrameBits(data);
|
|
|
|
int fbw = ZZOglGet_fbw_FrameBits(data);
|
|
|
|
int psm = ZZOglGet_psm_FrameBits(data);
|
2010-05-01 22:54:23 +00:00
|
|
|
|
|
|
|
if (fbw > 0) fbh = ZZOgl_fbh_Calc(fbp, fbw, psm) ;
|
|
|
|
|
2010-03-19 00:31:15 +00:00
|
|
|
return fbh ;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Obtain fbm -- frame mask -- from data. All higher word.
|
2010-05-01 22:54:23 +00:00
|
|
|
inline u32 ZZOglGet_fbm_FrameBits(u32 data)
|
|
|
|
{
|
|
|
|
return (data);
|
2010-04-25 00:31:27 +00:00
|
|
|
}
|
2010-03-19 00:31:15 +00:00
|
|
|
|
|
|
|
// Obtain fbm -- frame mask -- from data. All higher word. Fixed from psm == PCMT24 (without alpha)
|
2010-05-01 22:54:23 +00:00
|
|
|
inline u32 ZZOglGet_fbm_FrameBitsFix(u32 dataLO, u32 dataHI)
|
|
|
|
{
|
2010-03-19 00:31:15 +00:00
|
|
|
if (PSMT_BITMODE(ZZOglGet_psm_FrameBits(dataLO)) == 1)
|
|
|
|
return (dataHI | 0xff000000);
|
|
|
|
else
|
|
|
|
return dataHI;
|
|
|
|
}
|
|
|
|
|
|
|
|
// obtain colormask RED
|
2010-05-01 22:54:23 +00:00
|
|
|
inline u32 ZZOglGet_fbmRed_FrameBits(u32 data)
|
|
|
|
{
|
2010-03-19 00:31:15 +00:00
|
|
|
return (data & 0xff);
|
|
|
|
}
|
|
|
|
|
|
|
|
// obtain colormask Green
|
2010-05-01 22:54:23 +00:00
|
|
|
inline u32 ZZOglGet_fbmGreen_FrameBits(u32 data)
|
|
|
|
{
|
2010-03-19 00:31:15 +00:00
|
|
|
return ((data >> 8) & 0xff);
|
|
|
|
}
|
|
|
|
|
|
|
|
// obtain colormask Blue
|
2010-05-01 22:54:23 +00:00
|
|
|
inline u32 ZZOglGet_fbmBlue_FrameBits(u32 data)
|
|
|
|
{
|
2010-03-19 00:31:15 +00:00
|
|
|
return ((data >> 16) & 0xff);
|
|
|
|
}
|
|
|
|
|
|
|
|
// obtain colormask Alpha
|
2010-05-01 22:54:23 +00:00
|
|
|
inline u32 ZZOglGet_fbmAlpha_FrameBits(u32 data)
|
|
|
|
{
|
2010-03-19 00:31:15 +00:00
|
|
|
return ((data >> 24) & 0xff);
|
|
|
|
}
|
|
|
|
|
|
|
|
// obtain colormask Alpha
|
2010-05-01 22:54:23 +00:00
|
|
|
inline u32 ZZOglGet_fbmHighByte(u32 data)
|
|
|
|
{
|
2010-03-19 00:31:15 +00:00
|
|
|
return (!!(data & 0x80000000));
|
|
|
|
}
|
|
|
|
|
|
|
|
//-------------------------- tex0 comparison
|
|
|
|
// Check if old and new tex0 registers have only clut difference
|
2010-05-01 22:54:23 +00:00
|
|
|
inline bool ZZOglAllExceptClutIsSame(u32* oldtex, u32* newtex)
|
|
|
|
{
|
2010-03-19 00:31:15 +00:00
|
|
|
return ((oldtex[0] == newtex[0]) && ((oldtex[1] & 0x1f) == (newtex[1] & 0x1f)));
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check if the CLUT registers are same, except CLD
|
2010-05-01 22:54:23 +00:00
|
|
|
inline bool ZZOglClutMinusCLDunchanged(u32* oldtex, u32* newtex)
|
|
|
|
{
|
2010-03-19 00:31:15 +00:00
|
|
|
return ((oldtex[1] & 0x1fffffe0) == (newtex[1] & 0x1fffffe0));
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check if CLUT storage mode is not changed (CSA, CSM and CSPM)
|
2010-05-01 22:54:23 +00:00
|
|
|
inline bool ZZOglClutStorageUnchanged(u32* oldtex, u32* newtex)
|
|
|
|
{
|
2010-03-19 00:31:15 +00:00
|
|
|
return ((oldtex[1] & 0x1ff10000) == (newtex[1] & 0x1ff10000));
|
|
|
|
}
|
|
|
|
|
|
|
|
// CSA and CPSM bitmask 0001 1111 0111 1000 ...
|
|
|
|
// 60 56 52
|
|
|
|
#define CPSM_CSA_BITMASK 0x1f780000
|
|
|
|
#define CPSM_CSA_NOTMASK 0xe0870000
|
|
|
|
|
|
|
|
#endif
|