psptypes.h

Go to the documentation of this file.
00001 /*
00002  * PSP Software Development Kit - http://www.pspdev.org
00003  * -----------------------------------------------------------------------
00004  * Licensed under the BSD license, see LICENSE in PSPSDK root for details.
00005  *
00006  * psptypes.h - Commonly used typedefs.
00007  *
00008  * Copyright (c) 2005 Marcus R. Brown <mrbrown@ocgnet.org>
00009  * Copyright (c) 2005 James Forshaw <tyranid@gmail.com>
00010  * Copyright (c) 2005 John Kelley <ps2dev@kelley.ca>
00011  *
00012  * $Id: psptypes.h 2312 2007-09-09 15:02:23Z chip $
00013  */
00014 
00015 /* Note: Some of the structures, types, and definitions in this file were
00016    extrapolated from symbolic debugging information found in the Japanese
00017    version of Puzzle Bobble. */
00018 
00019 #ifndef _PSPTYPES_H_
00020 #define _PSPTYPES_H_ 1
00021 
00022 #include <stdint.h>
00023 
00024 #ifdef __cplusplus
00025 extern "C" {
00026 #endif
00027 
00028 #ifndef NULL
00029 #ifdef __cplusplus
00030 #define NULL    0
00031 #else
00032 #define NULL    ((void *) 0)
00033 #endif /* __cplusplus */
00034 #endif
00035 
00036 /* Legacy ps2dev types. */
00037 #ifndef PSP_LEGACY_TYPES_DEFINED
00038 #define PSP_LEGACY_TYPES_DEFINED
00039 typedef uint8_t                         u8;
00040 typedef uint16_t                        u16;
00041 
00042 typedef uint32_t                        u32;
00043 typedef uint64_t                        u64;
00044 
00045 typedef int8_t                          s8;
00046 typedef int16_t                         s16;
00047 
00048 typedef int32_t                         s32;
00049 typedef int64_t                         s64;
00050 #endif
00051 
00052 #ifndef PSP_LEGACY_VOLATILE_TYPES_DEFINED
00053 #define PSP_LEGACY_VOLATILE_TYPES_DEFINED
00054 typedef volatile uint8_t                vu8;
00055 typedef volatile uint16_t               vu16;
00056 
00057 typedef volatile uint32_t               vu32;
00058 typedef volatile uint64_t               vu64;
00059 
00060 typedef volatile int8_t                 vs8;
00061 typedef volatile int16_t                vs16;
00062 
00063 typedef volatile int32_t                vs32;
00064 typedef volatile int64_t                vs64;
00065 #endif
00066 
00067 /* MIPS-like accessor macros. */
00068 static __inline__ u8  _lb(u32 addr) { return *(vu8 *)addr; }
00069 static __inline__ u16 _lh(u32 addr) { return *(vu16 *)addr; }
00070 static __inline__ u32 _lw(u32 addr) { return *(vu32 *)addr; }
00071 static __inline__ u64 _ld(u32 addr) { return *(vu64 *)addr; }
00072 
00073 static __inline__ void _sb(u8 val, u32 addr) { *(vu8 *)addr = val; }
00074 static __inline__ void _sh(u16 val, u32 addr) { *(vu16 *)addr = val; }
00075 static __inline__ void _sw(u32 val, u32 addr) { *(vu32 *)addr = val; }
00076 static __inline__ void _sd(u64 val, u32 addr) { *(vu64 *)addr = val; }
00077 
00078 /* SCE types. */
00079 typedef unsigned char SceUChar8;
00080 typedef uint16_t SceUShort16;
00081 typedef uint32_t SceUInt32;
00082 typedef uint64_t SceUInt64;
00083 typedef uint64_t SceULong64;
00084 /*typedef unsigned int SceULong128 __attribute__((mode(TI)));*/
00085 
00086 typedef char SceChar8;
00087 typedef int16_t SceShort16;
00088 typedef int32_t SceInt32;
00089 typedef int64_t SceInt64;
00090 typedef int64_t SceLong64;
00091 /*typedef int SceLong128 __attribute__((mode(TI)));*/
00092 
00093 typedef float SceFloat;
00094 typedef float SceFloat32;
00095 
00096 typedef short unsigned int SceWChar16;
00097 typedef unsigned int SceWChar32;
00098 
00099 typedef int SceBool;
00100 
00101 typedef void SceVoid;
00102 typedef void * ScePVoid;
00103 
00104 
00105 /* PSP types. */
00106 
00107 /* Rectangles. */
00108 typedef struct ScePspSRect {
00109         short int       x;
00110         short int       y;
00111         short int       w;
00112         short int       h;
00113 } ScePspSRect;
00114 
00115 typedef struct ScePspIRect {
00116         int     x;
00117         int     y;
00118         int     w;
00119         int     h;
00120 } ScePspIRect;
00121 
00122 typedef struct ScePspL64Rect {
00123         SceLong64       x;
00124         SceLong64       y;
00125         SceLong64       w;
00126         SceLong64       h;
00127 } ScePspL64Rect;
00128 
00129 typedef struct ScePspFRect {
00130         float   x;
00131         float   y;
00132         float   w;
00133         float   h;
00134 } ScePspFRect;
00135 
00136 /* 2D vectors. */
00137 typedef struct ScePspSVector2 {
00138         short int       x;
00139         short int       y;
00140 } ScePspSVector2;
00141 
00142 typedef struct ScePspIVector2 {
00143         int     x;
00144         int     y;
00145 } ScePspIVector2;
00146 
00147 typedef struct ScePspL64Vector2 {
00148         SceLong64       x;
00149         SceLong64       y;
00150 } ScePspL64Vector2;
00151 
00152 typedef struct ScePspFVector2 {
00153         float   x;
00154         float   y;
00155 } ScePspFVector2;
00156 
00157 typedef union ScePspVector2 {
00158         ScePspFVector2  fv;
00159         ScePspIVector2  iv;
00160         float                   f[2];
00161         int                     i[2];
00162 } ScePspVector2;
00163 
00164 /* 3D vectors. */
00165 typedef struct ScePspSVector3 {
00166         short int       x;
00167         short int       y;
00168         short int       z;
00169 } ScePspSVector3;
00170 
00171 typedef struct ScePspIVector3 {
00172         int     x;
00173         int     y;
00174         int     z;
00175 } ScePspIVector3;
00176 
00177 typedef struct ScePspL64Vector3 {
00178         SceLong64       x;
00179         SceLong64       y;
00180         SceLong64       z;
00181 } ScePspL64Vector3;
00182 
00183 typedef struct ScePspFVector3 {
00184         float   x;
00185         float   y;
00186         float   z;
00187 } ScePspFVector3;
00188 
00189 typedef union ScePspVector3 {
00190         ScePspFVector3  fv;
00191         ScePspIVector3  iv;
00192         float                   f[3];
00193         int                     i[3];
00194 } ScePspVector3;
00195 
00196 /* 4D vectors. */
00197 typedef struct ScePspSVector4 {
00198         short int       x;
00199         short int       y;
00200         short int       z;
00201         short int       w;
00202 } ScePspSVector4;
00203 
00204 typedef struct ScePspIVector4 {
00205         int     x;
00206         int     y;
00207         int     z;
00208         int     w;
00209 } ScePspIVector4;
00210 
00211 typedef struct ScePspL64Vector4 {
00212         SceLong64       x;
00213         SceLong64       y;
00214         SceLong64       z;
00215         SceLong64       w;
00216 } ScePspL64Vector4;
00217 
00218 typedef struct ScePspFVector4 {
00219         float   x;
00220         float   y;
00221         float   z;
00222         float   w;
00223 } ScePspFVector4 __attribute__((aligned(16)));
00224 
00225 typedef struct ScePspFVector4Unaligned {
00226         float   x;
00227         float   y;
00228         float   z;
00229         float   w;
00230 } ScePspFVector4Unaligned;
00231 
00232 typedef union ScePspVector4 {
00233         ScePspFVector4  fv;
00234         ScePspIVector4  iv;
00235 /*      SceULong128     qw;*/   /* Missing compiler support. */
00236         float                   f[4];
00237         int                     i[4];
00238 } ScePspVector4 __attribute__((aligned(16)));
00239 
00240 /* 2D matrix types. */
00241 typedef struct ScePspIMatrix2 {
00242         ScePspIVector2  x;
00243         ScePspIVector2  y;
00244 } ScePspIMatrix2;
00245 
00246 typedef struct ScePspFMatrix2 {
00247         ScePspFVector2  x;
00248         ScePspFVector2  y;
00249 } ScePspFMatrix2;
00250 
00251 typedef union ScePspMatrix2 {
00252         ScePspFMatrix2  fm;
00253         ScePspIMatrix2  im;
00254         ScePspFVector2  fv[2];
00255         ScePspIVector2  iv[2];
00256         ScePspVector2   v[2];
00257 /*      SceULong128     qw[2];*/        /* Missing compiler support. */
00258         float                   f[2][2];
00259         int                     i[2][2];
00260 } ScePspMatrix2;
00261 
00262 /* 3D matrix types. */
00263 typedef struct ScePspIMatrix3 {
00264         ScePspIVector3  x;
00265         ScePspIVector3  y;
00266         ScePspIVector3  z;
00267 } ScePspIMatrix3;
00268 
00269 typedef struct ScePspFMatrix3 {
00270         ScePspFVector3  x;
00271         ScePspFVector3  y;
00272         ScePspFVector3  z;
00273 } ScePspFMatrix3;
00274 
00275 typedef union ScePspMatrix3 {
00276         ScePspFMatrix3  fm;
00277         ScePspIMatrix3  im;
00278         ScePspFVector3  fv[3];
00279         ScePspIVector3  iv[3];
00280         ScePspVector3   v[3];
00281 /*      SceULong128     qw[3];*/        /* Missing compiler support. */
00282         float                   f[3][3];
00283         int                     i[3][3];
00284 } ScePspMatrix3;
00285 
00286 /* 4D matrix types. */
00287 typedef struct ScePspIMatrix4 {
00288         ScePspIVector4  x;
00289         ScePspIVector4  y;
00290         ScePspIVector4  z;
00291         ScePspIVector4  w;
00292 } ScePspIMatrix4 __attribute__((aligned(16)));
00293 
00294 typedef struct ScePspIMatrix4Unaligned {
00295         ScePspIVector4  x;
00296         ScePspIVector4  y;
00297         ScePspIVector4  z;
00298         ScePspIVector4  w;
00299 } ScePspIMatrix4Unaligned;
00300 
00301 typedef struct ScePspFMatrix4 {
00302         ScePspFVector4  x;
00303         ScePspFVector4  y;
00304         ScePspFVector4  z;
00305         ScePspFVector4  w;
00306 } ScePspFMatrix4 __attribute__((aligned(16)));
00307 
00308 typedef struct ScePspFMatrix4Unaligned {
00309         ScePspFVector4  x;
00310         ScePspFVector4  y;
00311         ScePspFVector4  z;
00312         ScePspFVector4  w;
00313 } ScePspFMatrix4Unaligned;
00314 
00315 typedef union ScePspMatrix4 {
00316         ScePspFMatrix4  fm;
00317         ScePspIMatrix4  im;
00318         ScePspFVector4  fv[4];
00319         ScePspIVector4  iv[4];
00320         ScePspVector4   v[4];
00321 /*      SceULong128     qw[4];*/        /* Missing compiler support. */
00322         float                   f[4][4];
00323         int                     i[4][4];
00324 } ScePspMatrix4;
00325 
00326 /* Quaternions. */
00327 typedef struct ScePspFQuaternion {
00328         float   x;
00329         float   y;
00330         float   z;
00331         float   w;
00332 } ScePspFQuaternion __attribute__((aligned(16)));
00333 
00334 typedef struct ScePspFQuaternionUnaligned {
00335         float   x;
00336         float   y;
00337         float   z;
00338         float   w;
00339 } ScePspFQuaternionUnaligned;
00340 
00341 /* Colors and pixel formats. */
00342 typedef struct ScePspFColor {
00343         float   r;
00344         float   g;
00345         float   b;
00346         float   a;
00347 } ScePspFColor __attribute__((aligned(16)));
00348 
00349 typedef struct ScePspFColorUnaligned {
00350         float   r;
00351         float   g;
00352         float   b;
00353         float   a;
00354 } ScePspFColorUnaligned;
00355 
00356 typedef unsigned int ScePspRGBA8888;
00357 typedef unsigned short ScePspRGBA4444;
00358 typedef unsigned short ScePspRGBA5551;
00359 typedef unsigned short ScePspRGB565;
00360 
00361 /* Unions for converting between types. */
00362 typedef union ScePspUnion32 {
00363         unsigned int    ui;
00364         int                     i;
00365         unsigned short  us[2];
00366         short int               s[2];
00367         unsigned char   uc[4];
00368         char                    c[4];
00369         float                   f;
00370         ScePspRGBA8888  rgba8888;
00371         ScePspRGBA4444  rgba4444[2];
00372         ScePspRGBA5551  rgba5551[2];
00373         ScePspRGB565    rgb565[2];
00374 } ScePspUnion32;
00375 
00376 typedef union ScePspUnion64 {
00377         SceULong64              ul;
00378         SceLong64               l;
00379         unsigned int    ui[2];
00380         int                     i[2];
00381         unsigned short  us[4];
00382         short int               s[4];
00383         unsigned char   uc[8];
00384         char                    c[8];
00385         float                   f[2];
00386         ScePspSRect     sr;
00387         ScePspSVector4  sv;
00388         ScePspRGBA8888  rgba8888[2];
00389         ScePspRGBA4444  rgba4444[4];
00390         ScePspRGBA5551  rgba5551[4];
00391         ScePspRGB565    rgb565[4];
00392 } ScePspUnion64;
00393 
00394 typedef union ScePspUnion128 {
00395 /*      SceULong128     qw;*/   /* Missing compiler support. */
00396 /*      SceULong128     uq;*/
00397 /*      SceLong128      q;*/
00398         SceULong64              ul[2];
00399         SceLong64               l[2];
00400         unsigned int    ui[4];
00401         int                     i[4];
00402         unsigned short  us[8];
00403         short int               s[8];
00404         unsigned char   uc[16];
00405         char                    c[16];
00406         float                   f[4];
00407         ScePspFRect     fr;
00408         ScePspIRect     ir;
00409         ScePspFVector4  fv;
00410         ScePspIVector4  iv;
00411         ScePspFQuaternion fq;
00412         ScePspFColor    fc;
00413         ScePspRGBA8888  rgba8888[4];
00414         ScePspRGBA4444  rgba4444[8];
00415         ScePspRGBA5551  rgba5551[8];
00416         ScePspRGB565    rgb565[8];
00417 } ScePspUnion128 __attribute__((aligned(16)));
00418 
00419 /* Date and time. */
00420 typedef struct ScePspDateTime {
00421         unsigned short  year;
00422         unsigned short  month;
00423         unsigned short  day;
00424         unsigned short  hour;
00425         unsigned short  minute;
00426         unsigned short  second;
00427         unsigned int    microsecond;
00428 } ScePspDateTime;
00429 
00430 #ifdef __cplusplus
00431 }
00432 #endif
00433 
00434 #endif /* _PSPTYPES_H_ */