| 1 | /*************************************************************************** |
| 2 | gpu.h - description |
| 3 | ------------------- |
| 4 | begin : Sun Oct 28 2001 |
| 5 | copyright : (C) 2001 by Pete Bernert |
| 6 | email : BlackDove@addcom.de |
| 7 | ***************************************************************************/ |
| 8 | /*************************************************************************** |
| 9 | * * |
| 10 | * This program is free software; you can redistribute it and/or modify * |
| 11 | * it under the terms of the GNU General Public License as published by * |
| 12 | * the Free Software Foundation; either version 2 of the License, or * |
| 13 | * (at your option) any later version. See also the license.txt file for * |
| 14 | * additional informations. * |
| 15 | * * |
| 16 | ***************************************************************************/ |
| 17 | |
| 18 | #ifndef _PSX_GPU_ |
| 19 | #define _PSX_GPU_ |
| 20 | |
| 21 | #define INFO_TW 0 |
| 22 | #define INFO_DRAWSTART 1 |
| 23 | #define INFO_DRAWEND 2 |
| 24 | #define INFO_DRAWOFF 3 |
| 25 | |
| 26 | #define SHADETEXBIT(x) ((x>>24) & 0x1) |
| 27 | #define SEMITRANSBIT(x) ((x>>25) & 0x1) |
| 28 | #define PSXRGB(r,g,b) ((g<<10)|(b<<5)|r) |
| 29 | |
| 30 | #define DATAREGISTERMODES unsigned short |
| 31 | |
| 32 | #define DR_NORMAL 0 |
| 33 | #define DR_VRAMTRANSFER 1 |
| 34 | |
| 35 | |
| 36 | #define GPUSTATUS_ODDLINES 0x80000000 |
| 37 | #define GPUSTATUS_DMABITS 0x60000000 // Two bits |
| 38 | #define GPUSTATUS_READYFORCOMMANDS 0x10000000 |
| 39 | #define GPUSTATUS_READYFORVRAM 0x08000000 |
| 40 | #define GPUSTATUS_IDLE 0x04000000 |
| 41 | #define GPUSTATUS_DISPLAYDISABLED 0x00800000 |
| 42 | #define GPUSTATUS_INTERLACED 0x00400000 |
| 43 | #define GPUSTATUS_RGB24 0x00200000 |
| 44 | #define GPUSTATUS_PAL 0x00100000 |
| 45 | #define GPUSTATUS_DOUBLEHEIGHT 0x00080000 |
| 46 | #define GPUSTATUS_WIDTHBITS 0x00070000 // Three bits |
| 47 | #define GPUSTATUS_MASKENABLED 0x00001000 |
| 48 | #define GPUSTATUS_MASKDRAWN 0x00000800 |
| 49 | #define GPUSTATUS_DRAWINGALLOWED 0x00000400 |
| 50 | #define GPUSTATUS_DITHER 0x00000200 |
| 51 | |
| 52 | #define GPUIsBusy (lGPUstatusRet &= ~GPUSTATUS_IDLE) |
| 53 | #define GPUIsIdle (lGPUstatusRet |= GPUSTATUS_IDLE) |
| 54 | |
| 55 | #define GPUIsNotReadyForCommands (lGPUstatusRet &= ~GPUSTATUS_READYFORCOMMANDS) |
| 56 | #define GPUIsReadyForCommands (lGPUstatusRet |= GPUSTATUS_READYFORCOMMANDS) |
| 57 | |
| 58 | #define CALLBACK |
| 59 | |
| 60 | #include <stdio.h> |
| 61 | #include <stdlib.h> |
| 62 | #include <string.h> |
| 63 | #include <sys/time.h> |
| 64 | #include <math.h> |
| 65 | #include <stdint.h> |
| 66 | #include <unistd.h> |
| 67 | |
| 68 | ///////////////////////////////////////////////////////////////////////////// |
| 69 | |
| 70 | // byteswappings |
| 71 | |
| 72 | #define SWAP16(x) ({ uint16_t y=(x); (((y)>>8 & 0xff) | ((y)<<8 & 0xff00)); }) |
| 73 | #define SWAP32(x) ({ uint32_t y=(x); (((y)>>24 & 0xfful) | ((y)>>8 & 0xff00ul) | ((y)<<8 & 0xff0000ul) | ((y)<<24 & 0xff000000ul)); }) |
| 74 | |
| 75 | #ifdef __BIG_ENDIAN__ |
| 76 | |
| 77 | // big endian config |
| 78 | #define HOST2LE32(x) SWAP32(x) |
| 79 | #define HOST2BE32(x) (x) |
| 80 | #define LE2HOST32(x) SWAP32(x) |
| 81 | #define BE2HOST32(x) (x) |
| 82 | |
| 83 | #define HOST2LE16(x) SWAP16(x) |
| 84 | #define HOST2BE16(x) (x) |
| 85 | #define LE2HOST16(x) SWAP16(x) |
| 86 | #define BE2HOST16(x) (x) |
| 87 | |
| 88 | #else |
| 89 | |
| 90 | // little endian config |
| 91 | #define HOST2LE32(x) (x) |
| 92 | #define HOST2BE32(x) SWAP32(x) |
| 93 | #define LE2HOST32(x) (x) |
| 94 | #define BE2HOST32(x) SWAP32(x) |
| 95 | |
| 96 | #define HOST2LE16(x) (x) |
| 97 | #define HOST2BE16(x) SWAP16(x) |
| 98 | #define LE2HOST16(x) (x) |
| 99 | #define BE2HOST16(x) SWAP16(x) |
| 100 | |
| 101 | #endif |
| 102 | |
| 103 | #define GETLEs16(X) ((int16_t)GETLE16((uint16_t *)X)) |
| 104 | #define GETLEs32(X) ((int16_t)GETLE32((uint16_t *)X)) |
| 105 | |
| 106 | #define GETLE16(X) LE2HOST16(*(uint16_t *)X) |
| 107 | #define GETLE32_(X) LE2HOST32(*(uint32_t *)X) |
| 108 | #define GETLE16D(X) ({uint32_t val = GETLE32(X); (val<<16 | val >> 16);}) |
| 109 | #define PUTLE16(X, Y) do{*((uint16_t *)X)=HOST2LE16((uint16_t)Y);}while(0) |
| 110 | #define PUTLE32_(X, Y) do{*((uint32_t *)X)=HOST2LE16((uint32_t)Y);}while(0) |
| 111 | #ifdef __arm__ |
| 112 | #define GETLE32(X) (*(uint16_t *)(X)|(((uint16_t *)(X))[1]<<16)) |
| 113 | #define PUTLE32(X, Y) do{uint16_t *p_=(uint16_t *)(X);uint32_t y_=Y;p_[0]=y_;p_[1]=y_>>16;}while(0) |
| 114 | #else |
| 115 | #define GETLE32 GETLE32_ |
| 116 | #define PUTLE32 PUTLE32_ |
| 117 | #endif |
| 118 | |
| 119 | ///////////////////////////////////////////////////////////////////////////// |
| 120 | |
| 121 | typedef struct VRAMLOADTTAG |
| 122 | { |
| 123 | short x; |
| 124 | short y; |
| 125 | short Width; |
| 126 | short Height; |
| 127 | short RowsRemaining; |
| 128 | short ColsRemaining; |
| 129 | unsigned short *ImagePtr; |
| 130 | } VRAMLoad_t; |
| 131 | |
| 132 | ///////////////////////////////////////////////////////////////////////////// |
| 133 | |
| 134 | typedef struct PSXPOINTTAG |
| 135 | { |
| 136 | int32_t x; |
| 137 | int32_t y; |
| 138 | } PSXPoint_t; |
| 139 | |
| 140 | typedef struct PSXSPOINTTAG |
| 141 | { |
| 142 | short x; |
| 143 | short y; |
| 144 | } PSXSPoint_t; |
| 145 | |
| 146 | typedef struct PSXRECTTAG |
| 147 | { |
| 148 | short x0; |
| 149 | short x1; |
| 150 | short y0; |
| 151 | short y1; |
| 152 | } PSXRect_t; |
| 153 | |
| 154 | // linux defines for some windows stuff |
| 155 | |
| 156 | #define FALSE 0 |
| 157 | #define TRUE 1 |
| 158 | #define BOOL unsigned short |
| 159 | #define LOWORD(l) ((unsigned short)(l)) |
| 160 | #define HIWORD(l) ((unsigned short)(((uint32_t)(l) >> 16) & 0xFFFF)) |
| 161 | #define max(a,b) (((a) > (b)) ? (a) : (b)) |
| 162 | #define min(a,b) (((a) < (b)) ? (a) : (b)) |
| 163 | #define DWORD uint32_t |
| 164 | #ifndef __int64 |
| 165 | #define __int64 long long int |
| 166 | #endif |
| 167 | |
| 168 | typedef struct RECTTAG |
| 169 | { |
| 170 | int left; |
| 171 | int top; |
| 172 | int right; |
| 173 | int bottom; |
| 174 | }RECT; |
| 175 | |
| 176 | ///////////////////////////////////////////////////////////////////////////// |
| 177 | |
| 178 | typedef struct TWINTAG |
| 179 | { |
| 180 | PSXRect_t Position; |
| 181 | int xmask, ymask; |
| 182 | } TWin_t; |
| 183 | |
| 184 | ///////////////////////////////////////////////////////////////////////////// |
| 185 | |
| 186 | typedef struct PSXDISPLAYTAG |
| 187 | { |
| 188 | PSXPoint_t DisplayModeNew; |
| 189 | PSXPoint_t DisplayMode; |
| 190 | PSXPoint_t DisplayPosition; |
| 191 | PSXPoint_t DisplayEnd; |
| 192 | |
| 193 | int32_t Double; |
| 194 | int32_t Height; |
| 195 | int32_t PAL; |
| 196 | int32_t InterlacedNew; |
| 197 | int32_t Interlaced; |
| 198 | int32_t RGB24New; |
| 199 | int32_t RGB24; |
| 200 | PSXSPoint_t DrawOffset; |
| 201 | int32_t Disabled; |
| 202 | PSXRect_t Range; |
| 203 | |
| 204 | } PSXDisplay_t; |
| 205 | |
| 206 | ///////////////////////////////////////////////////////////////////////////// |
| 207 | |
| 208 | // draw.c |
| 209 | |
| 210 | extern int32_t GlobalTextAddrX,GlobalTextAddrY,GlobalTextTP; |
| 211 | extern int32_t GlobalTextABR,GlobalTextPAGE; |
| 212 | extern short ly0,lx0,ly1,lx1,ly2,lx2,ly3,lx3; |
| 213 | extern long lLowerpart; |
| 214 | extern BOOL bCheckMask; |
| 215 | extern unsigned short sSetMask; |
| 216 | extern unsigned long lSetMask; |
| 217 | extern short g_m1; |
| 218 | extern short g_m2; |
| 219 | extern short g_m3; |
| 220 | extern short DrawSemiTrans; |
| 221 | |
| 222 | // prim.c |
| 223 | |
| 224 | extern BOOL bUsingTWin; |
| 225 | extern TWin_t TWin; |
| 226 | extern void (*primTableJ[256])(unsigned char *); |
| 227 | extern void (*primTableSkip[256])(unsigned char *); |
| 228 | extern unsigned short usMirror; |
| 229 | extern int iDither; |
| 230 | extern uint32_t dwCfgFixes; |
| 231 | extern uint32_t dwActFixes; |
| 232 | extern int iUseFixes; |
| 233 | extern int iUseDither; |
| 234 | extern BOOL bDoVSyncUpdate; |
| 235 | extern int32_t drawX; |
| 236 | extern int32_t drawY; |
| 237 | extern int32_t drawW; |
| 238 | extern int32_t drawH; |
| 239 | |
| 240 | // gpu.h |
| 241 | |
| 242 | #define OPAQUEON 10 |
| 243 | #define OPAQUEOFF 11 |
| 244 | |
| 245 | #define KEY_RESETTEXSTORE 1 |
| 246 | #define KEY_SHOWFPS 2 |
| 247 | #define KEY_RESETOPAQUE 4 |
| 248 | #define KEY_RESETDITHER 8 |
| 249 | #define KEY_RESETFILTER 16 |
| 250 | #define KEY_RESETADVBLEND 32 |
| 251 | #define KEY_BADTEXTURES 128 |
| 252 | #define KEY_CHECKTHISOUT 256 |
| 253 | |
| 254 | #if !defined(__BIG_ENDIAN__) || defined(__x86_64__) || defined(__i386__) |
| 255 | #ifndef __LITTLE_ENDIAN__ |
| 256 | #define __LITTLE_ENDIAN__ |
| 257 | #endif |
| 258 | #endif |
| 259 | |
| 260 | #ifdef __LITTLE_ENDIAN__ |
| 261 | #define RED(x) (x & 0xff) |
| 262 | #define BLUE(x) ((x>>16) & 0xff) |
| 263 | #define GREEN(x) ((x>>8) & 0xff) |
| 264 | #define COLOR(x) (x & 0xffffff) |
| 265 | #elif defined __BIG_ENDIAN__ |
| 266 | #define RED(x) ((x>>24) & 0xff) |
| 267 | #define BLUE(x) ((x>>8) & 0xff) |
| 268 | #define GREEN(x) ((x>>16) & 0xff) |
| 269 | #define COLOR(x) SWAP32(x & 0xffffff) |
| 270 | #endif |
| 271 | |
| 272 | // gpu.c |
| 273 | |
| 274 | extern VRAMLoad_t VRAMWrite; |
| 275 | extern VRAMLoad_t VRAMRead; |
| 276 | extern DATAREGISTERMODES DataWriteMode; |
| 277 | extern DATAREGISTERMODES DataReadMode; |
| 278 | extern short sDispWidths[]; |
| 279 | extern BOOL bDebugText; |
| 280 | extern PSXDisplay_t PSXDisplay; |
| 281 | extern PSXDisplay_t PreviousPSXDisplay; |
| 282 | extern BOOL bSkipNextFrame; |
| 283 | extern long lGPUstatusRet; |
| 284 | extern unsigned char * psxVSecure; |
| 285 | extern unsigned char * psxVub; |
| 286 | extern signed char * psxVsb; |
| 287 | extern unsigned short * psxVuw; |
| 288 | extern signed short * psxVsw; |
| 289 | extern uint32_t * psxVul; |
| 290 | extern int32_t * psxVsl; |
| 291 | extern unsigned short * psxVuw_eom; |
| 292 | extern BOOL bChangeWinMode; |
| 293 | extern long lSelectedSlot; |
| 294 | extern BOOL bInitCap; |
| 295 | extern DWORD dwLaceCnt; |
| 296 | extern uint32_t lGPUInfoVals[]; |
| 297 | extern uint32_t ulStatusControl[]; |
| 298 | |
| 299 | // fps.c |
| 300 | |
| 301 | extern int UseFrameLimit; |
| 302 | extern int UseFrameSkip; |
| 303 | extern float fFrameRate; |
| 304 | extern int iFrameLimit; |
| 305 | extern float fFrameRateHz; |
| 306 | extern float fps_skip; |
| 307 | extern float fps_cur; |
| 308 | |
| 309 | // draw.c |
| 310 | |
| 311 | void DoBufferSwap(void); |
| 312 | void DoClearScreenBuffer(void); |
| 313 | void DoClearFrontBuffer(void); |
| 314 | unsigned long ulInitDisplay(void); |
| 315 | void CloseDisplay(void); |
| 316 | |
| 317 | struct rearmed_cbs; |
| 318 | extern const struct rearmed_cbs *rcbs; |
| 319 | |
| 320 | #endif |