2010-07-10 08:20:50 +00:00
|
|
|
/* ZZ Open GL graphics plugin
|
|
|
|
* Copyright (c)2009-2010 zeydlitz@gmail.com, arcum42@gmail.com
|
|
|
|
* Based on Zerofrog's ZeroGS KOSMOS (c)2005-2008
|
2010-03-19 00:31:15 +00:00
|
|
|
*
|
|
|
|
* 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
|
2010-07-04 22:49:00 +00:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
2010-03-19 00:31:15 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __GS_H__
|
|
|
|
#define __GS_H__
|
|
|
|
|
2010-07-05 13:22:02 +00:00
|
|
|
|
|
|
|
#define USE_OLD_REGS
|
|
|
|
|
2010-04-02 05:53:14 +00:00
|
|
|
#include "Util.h"
|
2010-04-02 06:49:30 +00:00
|
|
|
#include "GifTransfer.h"
|
2010-10-17 10:03:12 +00:00
|
|
|
#include "HostMemory.h"
|
2010-03-19 00:31:15 +00:00
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
2010-09-01 10:28:37 +00:00
|
|
|
extern float fFPS;
|
2010-06-11 11:48:07 +00:00
|
|
|
|
2010-08-14 08:15:19 +00:00
|
|
|
#define MEMORY_END 0x00400000
|
|
|
|
|
2010-09-01 10:28:37 +00:00
|
|
|
extern int g_LastCRC;
|
|
|
|
|
2010-03-19 00:31:15 +00:00
|
|
|
struct Vector_16F
|
|
|
|
{
|
|
|
|
u16 x, y, z, w;
|
|
|
|
};
|
|
|
|
|
|
|
|
// 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;
|
|
|
|
};
|
|
|
|
|
2010-09-01 10:28:37 +00:00
|
|
|
// Almost same as previous, controlled by prim.fst flags
|
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;
|
|
|
|
|
|
|
|
// PSM values
|
|
|
|
// PSM types == Texture Storage Format
|
2010-05-01 22:54:23 +00:00
|
|
|
enum PSM_value
|
|
|
|
{
|
2010-08-18 14:04:10 +00:00
|
|
|
PSMCT32 = 0, // 00 0000
|
|
|
|
PSMCT24 = 1, // 00 0001
|
|
|
|
PSMCT16 = 2, // 00 0010
|
|
|
|
PSMCT16S = 10, // 00 1010
|
|
|
|
PSMT8 = 19, // 01 0011
|
|
|
|
PSMT4 = 20, // 01 0100
|
|
|
|
PSMT8H = 27, // 01 1011
|
|
|
|
PSMT4HL = 36, // 10 0100
|
|
|
|
PSMT4HH = 44, // 10 1100
|
|
|
|
PSMT32Z = 48, // 11 0000
|
|
|
|
PSMT24Z = 49, // 11 0001
|
|
|
|
PSMT16Z = 50, // 11 0010
|
|
|
|
PSMT16SZ = 58, // 11 1010
|
2010-03-19 00:31:15 +00:00
|
|
|
};
|
|
|
|
|
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.
|
2010-09-15 16:54:19 +00:00
|
|
|
// This code returns the same value on Z-textures, so texel storage mode is (BITMODE and !ISZTEX).
|
2010-04-11 08:51:50 +00:00
|
|
|
inline int PSMT_BITMODE(int psm) {return (psm & 0x7);}
|
|
|
|
|
2010-08-14 08:15:19 +00:00
|
|
|
inline int PSMT_BITS_NUM(int psm)
|
|
|
|
{
|
2010-08-18 08:54:16 +00:00
|
|
|
// Treat these as 32 bit.
|
|
|
|
if ((psm == PSMT8H) || (psm == PSMT4HL) || (psm == PSMT4HH))
|
|
|
|
{
|
|
|
|
return 4;
|
|
|
|
}
|
|
|
|
|
2010-08-14 08:15:19 +00:00
|
|
|
switch (PSMT_BITMODE(psm))
|
|
|
|
{
|
|
|
|
case 4:
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
case 3:
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
case 2:
|
|
|
|
return 2;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return 4;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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.
|
2010-10-15 09:32:41 +00:00
|
|
|
// Note: the function only works for clut format. Clut PSM is 4 bits only. The possible value are PSMCT32, PSMCT16, PSMCT16S
|
2010-04-11 08:51:50 +00:00
|
|
|
inline bool PSMT_IS32BIT(int psm) {return !!(psm <= 1);}
|
2010-03-19 00:31:15 +00:00
|
|
|
|
2010-09-15 16:54:19 +00:00
|
|
|
// When color format is RGB24 (PSMCT24) or RGBA16 (PSMCT16 & 16S) alpha value expanded, based on
|
|
|
|
// TEXA register and AEM status.
|
|
|
|
inline int PSMT_ALPHAEXP(int psm) {return (psm == PSMCT24 || psm == PSMCT16 || psm == PSMCT16S);}
|
|
|
|
|
|
|
|
|
2010-08-18 14:04:10 +00:00
|
|
|
// This function updates the 6th and 5th bit of psm
|
|
|
|
// 00 or 11 -> 00 ; 01 -> 10 ; 10 -> 01
|
|
|
|
inline int Switch_Top_Bytes (int X) {
|
|
|
|
if ( ( X & 0x30 ) == 0 )
|
|
|
|
return X;
|
|
|
|
else
|
|
|
|
return (X ^ 0x30);
|
|
|
|
}
|
|
|
|
|
2010-09-15 16:54:19 +00:00
|
|
|
// How many pixel stored in 1 word.
|
|
|
|
// 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.
|
|
|
|
inline int PIXELS_PER_WORD(int psm)
|
|
|
|
{
|
|
|
|
if (psm == PSMT8)
|
|
|
|
return 4;
|
|
|
|
if (psm == PSMT4)
|
|
|
|
return 8;
|
|
|
|
if (PSMT_IS16BIT(psm))
|
|
|
|
return 2;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2010-08-18 14:04:10 +00:00
|
|
|
// Some storage formats could share the same memory block (2 textures in 1 format). This include following combinations:
|
|
|
|
// PSMT24(24Z) with either 8H, 4HL, 4HH and PSMT4HL with PSMT4HH.
|
|
|
|
// We use slightly different versions of this function on comparison with GSDX, Storage format XOR 0x30 made Z-textures
|
|
|
|
// similar to normal ones and change higher bits on short (8 and 4 bits) textures.
|
|
|
|
inline bool PSMT_HAS_SHARED_BITS (int fpsm, int tpsm) {
|
|
|
|
int SUM = Switch_Top_Bytes(fpsm) + Switch_Top_Bytes(tpsm) ;
|
|
|
|
return (SUM == 0x15 || SUM == 0x1D || SUM == 0x2C || SUM == 0x30);
|
|
|
|
}
|
|
|
|
|
2010-09-20 10:09:46 +00:00
|
|
|
// If a clut is in 32-bit color, its size is 4 bytes, and 16-bit clut has a 2 byte size.
|
|
|
|
inline int CLUT_PIXEL_SIZE(int cpsm) {return ((cpsm <= 1) ? 4 : 2); }
|
2010-08-18 14:04:10 +00:00
|
|
|
|
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];
|
2010-09-01 10:28:37 +00:00
|
|
|
|
2010-04-15 22:03:23 +00:00
|
|
|
tex_0_info(u64 data) { _u64 = data; }
|
|
|
|
tex_0_info(u32 data) { _u32[0] = data; _u32[1] = 0; }
|
|
|
|
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-10-16 11:10:48 +00:00
|
|
|
// ZZLog::Debug_Log("psm %d\n", psm);
|
2010-05-01 22:54:23 +00:00
|
|
|
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-10-17 09:07:16 +00:00
|
|
|
bool SaveTexture(const char* filename, u32 textarget, u32 tex, int width, int height);
|
2010-10-18 11:24:40 +00:00
|
|
|
extern void SaveTex(tex0Info* ptex, int usevid);
|
|
|
|
extern char* NamedSaveTex(tex0Info* ptex, int usevid);
|
2010-10-17 09:07:16 +00:00
|
|
|
|
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;
|
2010-07-07 09:59:29 +00:00
|
|
|
#ifdef USE_OLD_REGS
|
2010-03-19 00:31:15 +00:00
|
|
|
int dir;
|
2010-07-07 09:59:29 +00:00
|
|
|
#else
|
|
|
|
int diry;
|
|
|
|
int dirx;
|
|
|
|
#endif
|
2010-03-19 00:31:15 +00:00
|
|
|
} 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-07-11 06:16:16 +00:00
|
|
|
pathInfo path[4];
|
2010-07-10 06:04:32 +00:00
|
|
|
GIFRegDIMX dimx;
|
2010-08-18 08:54:16 +00:00
|
|
|
GSMemory mem;
|
|
|
|
GSClut clut_buffer;
|
2010-09-15 16:54:19 +00:00
|
|
|
int primNext(int inc = 1)
|
|
|
|
{
|
|
|
|
return ((primIndex + inc) % ARRAY_SIZE(gsvertex));
|
|
|
|
}
|
2010-08-18 08:54:16 +00:00
|
|
|
|
2010-07-05 13:22:02 +00:00
|
|
|
void setRGBA(u32 r, u32 g, u32 b, u32 a)
|
|
|
|
{
|
|
|
|
rgba = (r & 0xff) |
|
|
|
|
((g & 0xff) << 8) |
|
|
|
|
((b & 0xff) << 16) |
|
|
|
|
((a & 0xff) << 24);
|
|
|
|
}
|
2010-07-10 06:04:32 +00:00
|
|
|
|
2010-07-10 12:41:49 +00:00
|
|
|
void add_vertex(u16 x, u16 y, u32 z, u16 f)
|
2010-07-10 06:04:32 +00:00
|
|
|
{
|
|
|
|
vertexregs.x = x;
|
|
|
|
vertexregs.y = y;
|
|
|
|
vertexregs.z = z;
|
|
|
|
vertexregs.f = f;
|
|
|
|
gsvertex[primIndex] = vertexregs;
|
2010-09-15 16:54:19 +00:00
|
|
|
primIndex = primNext();
|
2010-07-10 06:04:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void add_vertex(u16 x, u16 y, u32 z)
|
|
|
|
{
|
|
|
|
vertexregs.x = x;
|
|
|
|
vertexregs.y = y;
|
|
|
|
vertexregs.z = z;
|
|
|
|
gsvertex[primIndex] = vertexregs;
|
2010-09-15 16:54:19 +00:00
|
|
|
primIndex = primNext();
|
2010-07-10 06:04:32 +00:00
|
|
|
}
|
2010-03-19 00:31:15 +00:00
|
|
|
} GSinternal;
|
|
|
|
|
|
|
|
extern GSinternal gs;
|
|
|
|
|
2010-09-15 21:26:59 +00:00
|
|
|
// Note the function is used in a template parameter so it must be declared extern
|
|
|
|
// Note2: In this case extern is not compatible with __forceinline so just inline it...
|
|
|
|
extern inline u16 RGBA32to16(u32 c)
|
2010-03-27 01:01:31 +00:00
|
|
|
{
|
|
|
|
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
|
|
|
|
2010-09-16 11:57:25 +00:00
|
|
|
#if 0
|
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))
|
2010-09-16 11:57:25 +00:00
|
|
|
#endif
|
2010-03-19 00:31:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2010-09-15 16:54:19 +00:00
|
|
|
// Get pixel storage format from tex0. Clutted textures store pixels in cpsm format.
|
|
|
|
inline int PIXEL_STORAGE_FORMAT(const tex0Info& tex) {
|
|
|
|
if (PSMT_ISCLUT(tex.psm))
|
|
|
|
return tex.cpsm;
|
|
|
|
else
|
|
|
|
return tex.psm;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If pixel storage format not PSMCT24 ot PSMCT32, then it is 16-bit.
|
|
|
|
// Z-textures have 0x30 upper bits, so we eliminate them by &&(~0x30)
|
|
|
|
inline bool PSMT_ISHALF_STORAGE(const tex0Info& tex0) { return ((PIXEL_STORAGE_FORMAT(tex0) & (~0x30)) > 1); }
|
2010-03-19 00:31:15 +00:00
|
|
|
|
|
|
|
//--------------------------- 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) ;
|
2010-10-16 11:10:48 +00:00
|
|
|
// ZZLog::Debug_Log("result %d", 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-07-19 15:49:30 +00:00
|
|
|
inline bool ZZOglAllExceptClutIsSame(const u32* oldtex, const u32* newtex)
|
2010-05-01 22:54:23 +00:00
|
|
|
{
|
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-07-19 15:49:30 +00:00
|
|
|
inline bool ZZOglClutMinusCLDunchanged(const u32* oldtex, const u32* newtex)
|
2010-05-01 22:54:23 +00:00
|
|
|
{
|
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-07-19 15:49:30 +00:00
|
|
|
inline bool ZZOglClutStorageUnchanged(const u32* oldtex, const u32* newtex)
|
2010-05-01 22:54:23 +00:00
|
|
|
{
|
2010-03-19 00:31:15 +00:00
|
|
|
return ((oldtex[1] & 0x1ff10000) == (newtex[1] & 0x1ff10000));
|
|
|
|
}
|
|
|
|
|
2010-10-17 08:47:31 +00:00
|
|
|
// call to load CLUT data (depending on CLD)
|
|
|
|
void texClutWrite(int ctx);
|
|
|
|
|
|
|
|
// Perform clutting for flushed texture. Better check if it needs a prior call.
|
|
|
|
inline void CluttingForFlushedTex(tex0Info* tex0, u32 Data, int ictx)
|
|
|
|
{
|
|
|
|
tex0->cbp = ZZOglGet_cbp_TexBits(Data);
|
|
|
|
tex0->cpsm = ZZOglGet_cpsm_TexBits(Data);
|
|
|
|
tex0->csm = ZZOglGet_csm_TexBits(Data);
|
|
|
|
tex0->csa = ZZOglGet_csa_TexBits(Data);
|
|
|
|
tex0->cld = ZZOglGet_cld_TexBits(Data);
|
|
|
|
|
|
|
|
texClutWrite(ictx);
|
|
|
|
};
|
|
|
|
|
2010-03-19 00:31:15 +00:00
|
|
|
// CSA and CPSM bitmask 0001 1111 0111 1000 ...
|
|
|
|
// 60 56 52
|
|
|
|
#define CPSM_CSA_BITMASK 0x1f780000
|
|
|
|
#define CPSM_CSA_NOTMASK 0xe0870000
|
|
|
|
|
|
|
|
#endif
|