#pragma once

//#ifdef CALLBACK
//#undef CALLBACK
//#endif
//#define CALLBACK 

#define DATAREGISTERMODES unsigned short
#define DR_NORMAL        0
#define DR_VRAMTRANSFER  1

#define SHADETEXBIT(x) ((x>>24) & 0x1)
#define SEMITRANSBIT(x) ((x>>25) & 0x1)
#define PSXRGB(r,g,b) ((g<<10)|(b<<5)|r)

#define INFO_TW        0
#define INFO_DRAWSTART 1
#define INFO_DRAWEND   2
#define INFO_DRAWOFF   3

typedef struct {
	unsigned int ulFreezeVersion;
	unsigned int ulStatus;
	unsigned int ulControl[256];
	unsigned char psxVRam[1024*512*2];
} GPUFreeze_t;

typedef struct VRAMLOADTTAG
{
 short x;
 short y;
 short Width;
 short Height;
 short RowsRemaining;
 short ColsRemaining;
 unsigned short *ImagePtr;
} VRAMLoad_t;

typedef struct PSXPOINTTAG
{
 long x;
 long y;
} PSXPoint_t;

typedef struct PSXSPOINTTAG
{
 short x;
 short y;
} PSXSPoint_t;

typedef struct PSXRECTTAG
{
 short x0;
 short x1;
 short y0;
 short y1;
} PSXRect_t;

typedef struct PSXDISPLAYTAG
{
 PSXPoint_t  DisplayModeNew;
 PSXPoint_t  DisplayMode;
 PSXPoint_t  DisplayPosition;
 PSXPoint_t  DisplayEnd;
 
 long        Double;
 long        Height;
 long        PAL;
 long        InterlacedNew;
 long        Interlaced;
 long        RGB24New;
 long        RGB24;
 PSXSPoint_t DrawOffset;
 long        Disabled;
 PSXRect_t   Range;

} PSXDisplay_t;


typedef struct TWINTAG
{
 PSXRect_t  Position;
} TWin_t;

/** GPU **/
#define GPUSTATUS_ODDLINES            0x80000000
#define GPUSTATUS_DMABITS             0x60000000 // Two bits
#define GPUSTATUS_READYFORCOMMANDS    0x10000000
#define GPUSTATUS_READYFORVRAM        0x08000000
#define GPUSTATUS_IDLE                0x04000000
#define GPUSTATUS_DISPLAYDISABLED     0x00800000
#define GPUSTATUS_INTERLACED          0x00400000
#define GPUSTATUS_RGB24               0x00200000
#define GPUSTATUS_PAL                 0x00100000
#define GPUSTATUS_DOUBLEHEIGHT        0x00080000
#define GPUSTATUS_WIDTHBITS           0x00070000 // Three bits
#define GPUSTATUS_MASKENABLED         0x00001000
#define GPUSTATUS_MASKDRAWN           0x00000800
#define GPUSTATUS_DRAWINGALLOWED      0x00000400
#define GPUSTATUS_DITHER              0x00000200

#define GPUIsBusy (lGPUstatusRet &= ~GPUSTATUS_IDLE)
#define GPUIsIdle (lGPUstatusRet |= GPUSTATUS_IDLE)

#define GPUIsNotReadyForCommands (lGPUstatusRet &= ~GPUSTATUS_READYFORCOMMANDS)
#define GPUIsReadyForCommands (lGPUstatusRet |= GPUSTATUS_READYFORCOMMANDS)

/** variables **/
extern long           GlobalTextAddrX,GlobalTextAddrY,GlobalTextTP;
extern long           GlobalTextREST,GlobalTextABR,GlobalTextPAGE;
extern PSXDisplay_t   PSXDisplay;

extern void (*primTableJ[256])(unsigned char *);
extern void (*primTableSkip[256])(unsigned char *);

extern unsigned long	dwGPUVersion;
extern int				iGPUHeight;
extern int				iGPUHeightMask;
extern int				GlobalTextIL;
extern long				lGPUstatusRet;
extern short          DrawSemiTrans;
extern short          g_m1;
extern short          g_m2;
extern short          g_m3;
extern short          ly0,lx0,ly1,lx1,ly2,lx2,ly3,lx3;
extern long           lLowerpart;
extern unsigned short sSetMask;
extern unsigned long  lSetMask;
extern BOOL           bCheckMask;
extern unsigned long  lGPUInfoVals[];
extern VRAMLoad_t     VRAMWrite;
extern VRAMLoad_t     VRAMRead;
extern DATAREGISTERMODES DataWriteMode;
extern DATAREGISTERMODES DataReadMode;

extern unsigned char  * psxVSecure;
extern unsigned short * PSXVram;
extern unsigned char  * psxVub;
extern signed char    * psxVsb;
extern unsigned short * psxVuw;
extern signed short   * psxVsw;
extern uint32_t * psxVul;
extern int32_t * psxVsl;
extern unsigned short * psxVuw_eom;
extern int           iTileCheat;


extern long           drawX;
extern long           drawY;
extern long           drawW;
extern long           drawH;
extern BOOL           bUsingTWin;
extern TWin_t         TWin;
extern unsigned short  usMirror;
extern int            iDither;
extern unsigned long  dwCfgFixes;
extern unsigned long  dwActFixes;
extern unsigned long  dwEmuFixes;
extern int            iUseFixes;
extern int            iUseDither;

extern PSXDisplay_t PreviousPSXDisplay;


extern int            UseFrameLimit;
extern int            UseFrameSkip;
extern float          fFrameRate;
extern int            iFrameLimit;
extern float          fFrameRateHz;
extern float          fps_skip;
extern float          fps_cur;
extern int            iFastFwd;