PS2Defines.h

00001 /*
00002 * "PS2" Application Framework
00003 *
00004 * University of Abertay Dundee
00005 * May be used for educational purposed only
00006 *
00007 * Author - Dr Henry S Fortuna
00008 *
00009 * $Revision: 1.2 $
00010 * $Date: 2007/08/19 12:45:09 $
00011 *
00012 */
00013 
00014 #ifndef __PS2DEFINES_H__
00015 #define __PS2DEFINES_H__
00016 
00017 // #define _NDEBUG
00018 // #define NDEBUG
00019 
00020 typedef char int8;
00021 typedef unsigned char uint8;
00022 typedef short int16;
00023 typedef unsigned short uint16;
00024 typedef int int32;
00025 typedef unsigned int uint32;
00026 typedef long long int64;
00027 typedef unsigned long long uint64;
00028 typedef int int128 __attribute__ ((mode(TI), aligned(16)));
00029 typedef unsigned int uint128 __attribute__ ((mode(TI), aligned(16)));
00030 
00031 #define KILOBYTES(x) ((x) * 1024)
00032 #define MEGABYTES(x) (KILOBYTES(x) * 1024)
00033 
00034 #define PSMCT32         0
00035 #define PSMT8           0x13
00036 
00037 #define TEXBUF480       (480)
00038 #define TEXBUF496       (496)
00039 
00040 typedef enum GS_DRAWING_PRIMITIVES
00041 {
00042         GS_POINT,
00043         GS_LINE,                
00044         GS_LINESTRIP,   
00045         GS_TRIANGLE,    
00046         GS_TRISTRIP,    
00047         GS_TRIFAN,              
00048         GS_SPRITE               
00049 }GS_DRAWING_PRIMITIVES_t;
00050 
00051 //---------------------------------------------------------------------------
00052 // PRIM Register - Setup Drawing Primitive
00053 //   PRI  - Primitive type
00054 //   IIP  - Shading method (0=flat, 1=gouraud)
00055 //   TME  - Texture mapping (0=off, 1=on)
00056 //   FGE  - Fog (0=off, 1=on)
00057 //   ABE  - Alpha Blending (0=off, 1=on)
00058 //   AA1  - Antialiasing (0=off,1=on)
00059 //   FST  - Texture coordinate specification (0=use ST/RGBAQ register, 1=use UV register)
00060 //                              (UV means no perspective correction, good for 2D)
00061 //   CTXT - Drawing context (0=1, 1=2)
00062 //   FIX  - ?? Fragment value control (use 0)
00063 //---------------------------------------------------------------------------
00064 #define PRIM_POINT                      0
00065 #define PRIM_LINE                       1
00066 #define PRIM_LINE_STRIP         2
00067 #define PRIM_TRI                        3
00068 #define PRIM_TRI_STRIP          4
00069 #define PRIM_TRI_FAN            5
00070 #define PRIM_SPRITE                     6
00071 #define PRIM_IIP_FLAT           0
00072 #define PRIM_IIP_GOURAUD        1
00073 #define PRIM_TME_OFF            0
00074 #define PRIM_TME_ON                     1
00075 #define PRIM_FGE_OFF            0
00076 #define PRIM_FGE_ON                     1
00077 #define PRIM_ABE_OFF            0
00078 #define PRIM_ABE_ON                     1
00079 #define PRIM_AA1_OFF            0
00080 #define PRIM_AA1_ON                     1
00081 #define PRIM_FST_STQ            0
00082 #define PRIM_FST_UV                     1
00083 #define PRIM_CTXT_CONTEXT1      0
00084 #define PRIM_CTXT_CONTEXT2      1
00085 #define PRIM_FIX_NOFIXDDA       0
00086 #define PRIM_FIX_FIXDDA         1
00087 
00088 // VIF codes
00089 #define S_32            0
00090 #define S_16            1
00091 #define S_8                     2
00092 #define V2_32           4
00093 #define V2_16           5
00094 #define V2_8            6
00095 #define V3_32           8
00096 #define V3_16           9
00097 #define V3_8            0xa
00098 #define V4_32           0xc
00099 #define V4_16           0xd
00100 #define V4_8            0xe
00101 #define V4_5            0xf
00102 
00103 #define MSCALL(iInstructionNumber)                                                      ((uint64) ((0x14<<24) | (iInstructionNumber)))
00104 #define MSCNT                                                                                           ((uint64) (0x17 << 24))
00105 #define UNPACK(type, iQuadCount, addr)                                          ((uint64) (((0x60 | (uint32)(type))<<24) | ((iQuadCount)<<16) | (addr)))
00106 #define UNPACK_TO_TOP(type, iQuadCount, addr)                           ((uint64) UNPACK(type, iQuadCount, addr) | (1<<15))
00107 #define UNPACK_UNSIGNED(type, iQuadCount, addr)                         ((uint64) UNPACK(type, iQuadCount, addr) | (1<<14))
00108 #define UNPACK_TO_TOP_UNSIGNED(type, iQuadCount, addr)          ((uint64) UNPACK_TO_TOP(type, iQuadCount, addr) | (1<<14))
00109 #define FLUSH                                                                                           ((uint64) (0x11 << 24))
00110 #define FLUSHE                                                                                          ((uint64) (0x10 << 24))
00111 #define FLUSHA                                                                                          ((uint64) (0x13 << 24))
00112 #define DIRECT(iQuadCount)                                                                      ((uint64) ((0x50<<24) | (iQuadCount)))
00113 #define NOP                                                                                                     ((uint64) (0))
00114 #define MPG(iNumOf64Codes, addr)                                                        ((uint64) ((0x4a<<24) | ((iNumOf64Codes)<<16) | (addr)))
00115 #define STCYCL(WL, CL)                                                                          ((uint64) ((0x1<<24) | ((WL)<<8) | (CL)))
00116 #define OFFSET(offset)                                                                          ((uint64) ((0x2<<24) | (offset)))
00117 #define BASE(base)                                                                                      ((uint64) ((0x3<<24) | (base)))
00118 #define ITOP(val)                                                                                       ((uint64) ((0x4<<24) | (val)))
00119 #define STMOD(mode)                                                                                     ((uint64) ((0x5<<24) | (mode&0x3)))
00120 #define STROW                                                                                           ((uint64) (0x30 << 24))
00121 #define STCOL                                                                                           ((uint64) (0x31 << 24))
00122 #define STMASK                                                                                          ((uint64) (0x20 << 24))
00123 #define MSKPATH3(mask)                                                                          ((uint64) (0x6 << 24) | (mask))
00124 
00125 #define SETMASK                                                                                         ((uint64) 0x10000000)
00126 #define SETIRQ                                                                                          ((uint64) 0x80000000)
00127 
00128 #define ALIGN_QW                        __attribute__((aligned(16)))
00129 #define ALIGN_4QW                       __attribute__((aligned(64)))
00130 #define ALIGN_16QW                      __attribute__((aligned(128)))
00131 
00132 #define GS_BATCH_1(r1)                  ((sps2uint128(1)) | (sps2uint128(r1) << 4))
00133 #define GS_BATCH_2(r1, r2)              ((sps2uint128(2)) | (sps2uint128(r1) << 4) | (sps2uint128(r2) << 8))
00134 #define GS_BATCH_3(r1, r2, r3)  ((sps2uint128(3)) | (sps2uint128(r1) << 4) | (sps2uint128(r2) << 8)  | (sps2uint128(r3) << 12))
00135 #define GS_BATCH_4(r1, r2, r3, r4)      \
00136         ((sps2uint128(4)) | (sps2uint128(r1) << 4) | (sps2uint128(r2) << 8) | (sps2uint128(r3) << 12) | (sps2uint128(r4) << 16))
00137 #define GS_BATCH_5(r1, r2, r3, r4, r5)  \
00138         ((sps2uint128(5)) | (sps2uint128(r1) << 4) | (sps2uint128(r2) << 8) | (sps2uint128(r3) << 12) | (sps2uint128(r4) << 16) \
00139          | (sps2uint128(r5) << 20))
00140 
00141 #define GS_GIFTAG_AUTO(EOP, PRE, PRIM, FLG, BATCH) \
00142         ((sps2uint128(BATCH)<<60) | (sps2uint128(FLG)<<58) | (sps2uint128(PRIM)<<47) | (sps2uint128(PRE)<<46) | (sps2uint128(EOP)<<15))
00143 
00144 #define GS_GIFTAG_BATCH(NLOOP, EOP, PRE, PRIM, FLG, BATCH) \
00145         ((sps2uint128(BATCH)<<60) | (sps2uint128(FLG)<<58) | (sps2uint128(PRIM)<<47) | (sps2uint128(PRE)<<46) | (sps2uint128(EOP)<<15) | (sps2uint128(NLOOP)))
00146 
00147 #define GS_GIFTAG(NLOOP, EOP, PRE, PRIM, FLG, NREG) \
00148         ((uint64(NREG)<<60) | (uint64(FLG)<<58) | (uint64(PRIM)<<47) | (uint64(PRE)<<46) | (EOP<<15) | (NLOOP<<0))
00149 
00150 #define GS_PRIM(PRIM, IIP, TME, FGE, ABE, AA1, FST, CTXT, FIX) \
00151         ((sps2uint128)((FIX<<10)|(CTXT<<9)|(FST<<8)|(AA1<<7)|(ABE<<6)|(FGE<<5)|(TME<<4)|(IIP<<3)|(PRIM)))
00152 
00153 #define AD                                                                                                                                              ((uint64) 0x0e)
00154 
00155 #define ALPHA_1                                                                                                                                 ((uint64) 0x42)
00156 #define ALPHA_2                                                                                                                                 ((uint64) 0x43)
00157 #define ALPHA_SET(A, B, C, D, FIX)                                                                                              ((uint64) (uint64(FIX)<<32) | (D<<6) | (C<<4) | (B<<2) | (A<<0))
00158 
00159 #define TEST_1                                                                                                                                  ((uint64) 0x47)
00160 #define TEST_2                                                                                                                                  ((uint64) 0x48)
00161 #define TEST_SET(ATE, ATST, AREF, AFAIL, DATE, DATM, ZTE, ZTST)                                 ((uint64(ZTST)<<17) | (uint64(ZTE)<<16) | (uint64(DATM)<<15) | (uint64(DATE)<<14) | (uint64(AFAIL)<<12) | (uint64(AREF)<<4) | (uint64(ATST)<<1) | (uint64(ATE)<<0))
00162 
00163 #define TEXA                                                                                                                                    ((uint64) 0x3b)
00164 #define TEXA_SET(TA0, AEM, TA1)                                                                                                 ((uint64(TA1)<<32) | (uint64(AEM)<<15) | (uint64(TA0)<<0))
00165 
00166 #define BITBLTBUF                                                                                                                               ((uint64) 0x50)
00167 #define BITBLTBUF_SET(SBP, SBW, SPSM, DBP, DBW, DPSM)                                                   ((uint64(DPSM)<<56) | (uint64(DBW)<<48) | (uint64(DBP)<<32) | (uint64(SPSM)<<24) | (uint64(SBW)<<16) | (uint64(SBP)<<0))
00168 
00169 #define CLAMP_1                                                                                                                                 ((uint64) 0x08)
00170 #define CLAMP_2                                                                                                                                 ((uint64) 0x09)
00171 #define CLAMP_SET(WMS, WMT, MINU, MAXU, MINV, MAXV)                                                             ((uint64(MAXV)<<34) | (uint64(MINV)<<24) | (uint64(MAXU)<<14) | (uint64(MINU)<<4) | (uint64(WMT)<<2) | (uint64(WMS)<<0))
00172 
00173 #define COLCLAMP                                                                                                                                ((uint64) 0x46)
00174 #define COLCLAMP_SET(CLAMP)                                                                                                             ((uint64) CLAMP&0x1)
00175 
00176 #define FBA_1                                                                                                                                   ((uint64) 0x4a)
00177 #define FBA_2                                                                                                                                   ((uint64) 0x4b)
00178 #define FBA_SET(FBA)                                                                                                                    ((uint64) FBA&0x1)
00179 
00180 #define FOGCOL                                                                                                                                  ((uint64) 0x3d)
00181 #define FOGCOL_SET(FCR, FCG, FCB)                                                                                               ((uint64(FCB&0xff)<<16) | (uint64(FCG&0xff)<<8) | (uint64(FCR&0xff)<<0))
00182 
00183 #define FRAME_1                                                                                                                                 ((uint64) 0x4c)
00184 #define FRAME_2                                                                                                                                 ((uint64) 0x4d)
00185 #define FRAME_SET(FBP, FBW, PSM, FBMSK)                                                                                 ((uint64(FBMSK)<<32) | (uint64(PSM)<<24) | (uint64(FBW)<<16) | uint64(FBP))
00186 
00187 #define TEX0_1                                                                                                                                  ((uint64) 0x06)
00188 #define TEX0_2                                                                                                                                  ((uint64) 0x07)
00189 #define TEX0_SET(TBP0, TBW, PSM, TW, TH, TCC, TFX, CBP, CPSM, CSM, CSA, CLD)    ((uint64(CLD)<<61) | (uint64(CSA)<<56) | (uint64(CSM)<<55) | (uint64(CPSM)<<51) | (uint64(CBP)<<37) | (uint64(TFX)<<35) | (uint64(TCC)<<34) | (uint64(TH)<<30) | (uint64(TW)<<26) | (uint64(PSM)<<20) | (uint64(TBW)<<14) | (uint64(TBP0)<<0))
00190 
00191 #define TEX1_1                                                                                                                                  ((uint64) 0x14)
00192 #define TEX1_2                                                                                                                                  ((uint64) 0x15)
00193 #define TEX1_SET(LCM, MXL, MMAG, MMIN, MTBA, L, K)                                                              ((uint64(K)<<32) | (uint64(L)<<19) | (uint64(MTBA)<<9) | (uint64(MMIN)<<6) | (uint64(MMAG)<<5) | (uint64(MXL)<<2) | (uint64(LCM)<<0))
00194 
00195 #define TEX2_1                                                                                                                                  ((uint64) 0x16)
00196 #define TEX2_2                                                                                                                                  ((uint64) 0x17)
00197 #define TEX2_SET(PSM, CBP, CPSM, CSM, CSA, CLD)                                                                 ((uint64(CLD)<<61) | (uint64(CSA)<<56) | (uint64(CSM)<<55) | (uint64(CPSM)<<51) | (uint64(CBP)<<37) | (uint64(PSM)<<20))
00198 
00199 #define TEXCLUT                                                                                                                                 ((uint64) 0x1c)
00200 #define TEXCLUT_SET(CBW, COU, COV)                                                                                              ((uint64(COV)<<12) | (uint64(COU)<<6) | (uint64(CBW)<<0))
00201 
00202 #define TRXDIR                                                                                                                                  ((uint64) 0x53)
00203 #define TRXDIR_SET(XDIR)                                                                                                                ((uint64) XDIR&0x3)
00204 
00205 #define TRXPOS                                                                                                                                  ((uint64) 0x51)
00206 #define TRXPOS_SET(SSAX, SSAY, DSAX, DSAY, DIR)                                                                 ((uint64(DIR)<<59) | (uint64(DSAY)<<48) | (uint64(DSAX)<<32) | (uint64(SSAY)<<16) | (uint64(SSAX)<<0))
00207 
00208 #define TRXREG                                                                                                                                  ((uint64) 0x52)
00209 #define TRXREG_SET(RRW, RRH)                                                                                                    ((uint64(RRH)<<32) | (uint64(RRW)<<0))
00210 
00211 #define MIPTBP1_1                                                                                                                               ((uint64) 0x34)
00212 #define MIPTBP1_2                                                                                                                               ((uint64) 0x35)
00213 #define MIPTBP1_SET(TBP1, TBW1, TBP2, TBW2, TBP3, TBW3)                                                 ((uint64(TBW3)<<54) | (uint64(TBP3)<<40) | (uint64(TBW2)<<34) | (uint64(TBP2)<<20) | (uint64(TBW1)<<14) | (uint64(TBP1)<<0))
00214 #define MIPTBP2_1                                                                                                                               ((uint64) 0x36)
00215 #define MIPTBP2_2                                                                                                                               ((uint64) 0x37)
00216 #define MIPTBP2_SET(TBP4, TBW4, TBP5, TBW5, TBP6, TBW6)                                                 MIPTBP1_SET(TBP4, TBW4, TBP5, TBW5, TBP6, TBW6)
00217 
00218 #define SCISSOR_1                                                                                                                               ((uint64) 0x40)
00219 #define SCISSOR_2                                                                                                                               ((uint64) 0x41)
00220 #define SCISSOR_SET(SCAX0, SCAX1, SCAY0, SCAY1)                                                                 ((uint64(SCAY1)<<48) | (uint64(SCAY0)<<32) | (uint64(SCAX1)<<16) | (uint64(SCAX0)<<0))
00221 
00222 #define XYOFFSET_1                                                                                                                              ((uint64) 0x18)
00223 #define XYOFFSET_2                                                                                                                              ((uint64) 0x19)
00224 #define XYOFFSET_SET(OFX, OFY)                                                                                                  ((uint64(OFY)<<32) | (uint64(OFX)<<0))
00225 
00226 #define RGBAQ                                                                                                                                   ((uint64) 0x01)
00227 #define RGBAQ_SET(R,G,B,A,Q)                                                                                                    ((uint64(Q)<<32) | (uint64(A)<<24) | (uint64(B)<<16) | (uint64(G)<<8) | (uint64(R)<<0))
00228 
00229 #define ST                                                                                                                                              ((uint64) 0x02)
00230 #define ST_SET(S,T)                                                                                                                             ((uint64(T)<<32) | (uint64(S)<<0))
00231 
00232 #define UV                                                                                                                                              ((uint64) 0x03)
00233 #define UV_SET(U,V)                                                                                                                             ((uint64(V)<<16) | (uint64(U)<<0))
00234 
00235 #define XYZ2                                                                                                                                    ((uint64) 0x05)
00236 #define XYZ2_SET(X, Y, Z)                                                                                                               ((uint64(Z)<<32) | (uint64(Y)<<16) | (uint64(X)<<0))
00237 
00238 #define XYZ3                                                                                                                                    ((uint64) 0x0d)
00239 #define XYZ3_SET(X, Y, Z)                                                                                                               XYZ2_SET(X,Y,Z)
00240 
00241 #define XYZF2                                                                                                                                   ((uint64) 0x04)
00242 #define XYZF2_SET(X, Y, Z, F)                                                                                                   ((uint64(F)<<56) | (uint64(Z)<<32) | (uint64(Y)<<16) | (uint64(X)<<0))
00243 
00244 #define XYZF3                                                                                                                                   ((uint64) 0x0c)
00245 #define XYZF3_SET(X, Y, Z, F)                                                                                                   XYZF2_SET(X,Y,Z,F)
00246 
00247 #define FINISH                                                                                                                                  ((uint64) 0x61)
00248 
00249 #define TEXFLUSH                                                                                                                                ((uint64) 0x3f)
00250 
00251 #define PABE                                                                                                                                    ((uint64) 0x49)
00252 #define PABE_SET(PABE)                                                                                                                  ((uint64) PABE&0x1)
00253 
00254 #define PRIM                                                                                                                                    ((uint64) 0x00)
00255 #define PRIM_SET(PRIM, IIP, TME, FGE, ABE, AA1, FST, CTXT, FIX)                                 (PRMODE_SET(IIP, TME, FGE, ABE, AA1, FST, CTXT, FIX)|PRIM)
00256 
00257 #define PRMODECONT                                                                                                                              ((uint64) 0x1a)
00258 #define PRMODECONT_SET(AC)                                                                                                              ((uint64) AC&0x1)
00259 
00260 #define PRMODE                                                                                                                                  ((uint64) 0x1b)
00261 #define PRMODE_SET(IIP, TME, FGE, ABE, AA1, FST, CTXT, FIX)                                             ((uint64) ((FIX<<10)|(CTXT<<9)|(FST<<8)|(AA1<<7)|(ABE<<6)|(FGE<<5)|(TME<<4)|(IIP<<3)))
00262 
00263 #define LABEL                                                                                                                                   ((uint64) 0x62)
00264 #define LABEL_SET(ID, IDMSK)                                                                                                    ((uint64(IDMSK)<<32) | uint64(ID))
00265 
00266 #define SIGNAL                                                                                                                                  ((uint64) 0x60)
00267 #define SIGNAL_SET(ID, IDMSK)                                                                                                   ((uint64(IDMSK)<<32) | uint64(ID))
00268 
00269 #define ZBUF_1                                                                                                                                  ((uint64) 0x4e)
00270 #define ZBUF_2                                                                                                                                  ((uint64) 0x4f)
00271 #define ZBUF_SET(ZBP, PSM, ZMSK)                                                                                                ((uint64(ZMSK)<<32) | (uint64(PSM)<<24) | (uint64(ZBP)<<0))
00272 
00273 #define HWREG                                                                                                                                   ((uint64) 0x54)
00274 #define HWREG_SET(DATA)                                                                                                                 ((uint64) DATA)
00275 
00276 #define SCANMSK                                                                                                                                 ((uint64) 0x22)
00277 #define SCANMSK_SET(MSK)                                                                                                                ((uint64) (MSK&0x3))
00278 
00279 #define DTHE                                                                                                                                    ((uint64) 0x45)
00280 #define DTHE_SET(DTHE)                                                                                                                  ((uint64) DTHE&0x1)
00281 
00282 #define DIMX                                                                                                                                    ((uint64) 0x44)
00283 #define DIMX_SET(DM00, DM01, DM02, DM03, DM10, DM11, DM12, DM13, DM20, DM21, DM22, DM23, DM30, DM31, DM32, DM33)                ((uint64(DM33&0x7)<<60) | (uint64(DM32&0x7)<<56) | (uint64(DM31&0x7)<<52) | (uint64(DM30&0x7)<<48) | (uint64(DM23&0x7)<<44) | (uint64(DM22&0x7)<<40) | (uint64(DM21&0x7)<<36) | (uint64(DM20&0x7)<<32) | (uint64(DM13&0x7)<<28) | (uint64(DM12&0x7)<<24) | (uint64(DM11&0x7)<<20) | (uint64(DM10&0x7)<<16) | (uint64(DM03&0x7)<<12) | (uint64(DM02&0x7)<<8) | (uint64(DM01&0x7)<<4) | (uint64(DM00&0x7)<<0))
00284 
00285 #define BGCOLOR                                                                                                                                 ((uint64) 0x0e)
00286 #define BGCOLOR_SET(R, G, B)                                                                                                    ((uint64(B)<<16) | (uint64(G)<<8) | (uint64(R)<<0))
00287 
00288 #define PMODE                                                                                                                                   ((uint64) 0x00)
00289 #define PMODE_SET(EN1, EN2, CRTMD, MMOD, AMOD, SLBG, ALP)                                               ((uint64(ALP)<<8) | (uint64(SLBG)<<7) | (uint64(AMOD)<<6) | (uint64(MMOD)<<5) | (uint64(CRTMD)<<2) | (uint64(EN2)<<1) | (uint64(EN1)<<0))       
00290 
00291 #define SMODE2                                                                                                                                  ((uint64) 0x02)
00292 #define SMODE2_SET(INT, FFMD, DPMS)                                                                                             ((uint64(DPMS)<<2) | (uint64(FFMD)<<1) | (uint64(INT)<<0))      
00293 
00294 #define DISPFB1                                                                                                                                 ((uint64) 0x07)
00295 #define DISPFB2                                                                                                                                 ((uint64) 0x09)
00296 #define DISPFB_SET(FBP, FBW, PSM, DBX, DBY)                                                                             ((uint64(DBY)<<43) | (uint64(DBX)<<32) | (uint64(PSM)<<15) | (uint64(FBW)<<9) | (uint64(FBP)<<0))       
00297 
00298 #define DISPLAY1                                                                                                                                ((uint64) 0x08)
00299 #define DISPLAY2                                                                                                                                ((uint64) 0x0a)
00300 #define DISPLAY_SET(DX, DY, MAGH, MAGV, DW, DH)                                                                 ((uint64(DH)<<44) | (uint64(DW)<<32) | (uint64(MAGV)<<27) | (uint64(MAGH)<<23) | (uint64(DY)<<12) | (uint64(DX)<<0))    
00301 
00302 #define PACKED_UV(U, V)                                                                                                                 ((uint64(V)<<32) | (uint64(U)))
00303 #define PACKED_XYZ2(X, Y, Z, ADC)                                                                                               ((uint128(ADC)<<111) | (uint128(Z)<<64) | (uint128(Y)<<32) | (uint128(X)))
00304 #define PACKED_RGBA(R, G, B, A)                                                                                                 ((uint128(A)<<96) | (uint128(B)<<64) | (uint128(G)<<32) | (uint128(R)))
00305 
00306 #endif
00307 

Generated on Sun May 18 21:45:08 2008 for PS2X by  doxygen 1.5.4