
#include <stdio.h>



#include <xtl.h>

#include <d3dx8.h>



#define PI 3.14159265f

#define RELEASE(x) if (x) x->Release();  x=NULL;

#ifdef _XBOX
#define HOME "d:\\"
#else
#define HOME ".\\"
#endif
extern bool fastScroll;
extern int gamesFound;
extern int scrollCount;
extern bool down;
extern int nFilter;
extern int buttonPressed;
// Emu.cpp
extern unsigned short *EmuScreen;
extern float scaleZ;
extern float scaleZ2;
extern float leftX;
extern float rightX;
extern float topY;
extern float bottomY;

extern int sWidth;
extern int sHeight;
extern LPDIRECT3DTEXTURE8 TexMenu;
extern LPDIRECT3DTEXTURE8 TexPreview;
extern LPDIRECT3DTEXTURE8 TexPreview2;
extern LPDIRECT3DTEXTURE8 TexPreviewMedia;
extern IDirect3DTexture8 *TexScreen;
extern IDirect3DTexture8 *TexScreenShot;
extern IDirect3DTexture8 *TexResize;
extern IDirect3DTexture8 *TexController;
extern IDirect3DTexture8 *TexHelp;
extern IDirect3DTexture8 *TexSplash;
extern IDirect3DTexture8 *TexSplashFinal;
extern IDirect3DTexture8 *TexPreviewBorder;
extern IDirect3DTexture8 *TexJBoxArt;
extern IDirect3DTexture8 *TexStatePreview;
extern IDirect3DTexture8 *TexGUIPreview;
extern IDirect3DTexture8 *TexNoStatePreview;
extern IDirect3DTexture8 *TexNoBox;
extern IDirect3DTexture8 *TexMainMenu;
extern IDirect3DTexture8 *TexPreviewResize;

extern IDirect3DTexture8 *TexImage;

extern D3DPRESENT_PARAMETERS d3dpp; 

extern int GameNameColor;
extern int GameNameSelectedColor;
extern int FolderColor;
extern int MenuOption;
extern int MenuOptionSelected;
extern int FontSizeGUI;
extern int FullNameColor;
extern DWORD menuColor[5];
extern int DisableMenuSounds;

extern "C" {
extern unsigned char FPSAtStart;
extern unsigned char FPSOn;
extern unsigned char KeyLoadState;
extern unsigned char KeySaveState;

}
extern unsigned char* keys;
extern int MapControllers;
extern int ShowFPS;
extern int DisableMenuSounds;


extern int EmuWidth,EmuHeight;
int EmuInit();
void EmuExit();
int EmuRomLoad(char *name);
int EmuFrame();

struct CustomVertex
{
  float x,y,z; // Vertex cordinates
  unsigned int colour;
  float u,v; // Texture coordinates
};
#define D3DFVF_CUSTOMVERTEX (D3DFVF_XYZ|D3DFVF_DIFFUSE|D3DFVF_TEX1)
extern IDirect3DVertexBuffer8 *VertexBufferLinear;
extern IDirect3DVertexBuffer8 *VertexBufferResize;
extern IDirect3DVertexBuffer8 *VertexBufferController;
extern IDirect3DVertexBuffer8 *VertexBufferOptions;

// Input.cpp
//struct Input
//{
//  short axis[4];
//  unsigned char button[16];
//  unsigned char held[16]; // How long has the button been held
 // char repeat[16]; // Auto-repeat
//};
//extern struct Input Inp;
//int InputInit();
//void InputExit();
//int InputUpdate();
//int InputLightCal(int cx,int cy,int ux,int uy);

// LightCal.cpp
//int LightCalReset();
//int LightCalUpdate();
//int LightCalRender();
int ModeUpdate();

// Loop.cpp
extern char LoopQuit;
extern int LoopMode;

int LoopInit();
void LoopExit();
int LoopCode();
extern bool menuChanged;
// Main.cpp
extern HWND FrameWnd;
extern int MainWidth,MainHeight;
extern char AppName[];


// Rom.cpp
extern bool useNoRom;
extern void checkGeneralOptions();
// --------------------------------------------
// Direct.cpp
extern IDirect3DDevice8 *Device;
extern IDirect3DSurface8 *DirectBack; // Back Buffer
int DirectInit();
int DirectClear(unsigned int colour);
int DirectScreen();
int DirectPresent();
void DirectExit();
extern int selected;
extern int checkA();
// DSound.cpp:
int DSoundInit();
void DSoundExit();
int DSoundUpdate();
extern short *DSoundNext; // Buffer for next sound data to put in loop
extern int DSoundSeg; // Seg length in samples

// Font.cpp
int FontInit(int i);
void FontExit();
int FontSetColour(unsigned int colour);
int FontText(WCHAR *,int,int, int);
int FontSmallSetColour(unsigned int colour);
int FontSmallText(WCHAR *,int,int, int);

extern int HardwareFilter;
extern int FlickerFilter;
extern int SoundFrequency;
extern int Soften;
extern int SoundInterpolation;
extern int LowPassFilter;
extern int DisableSaveStates;
extern int inGame;
extern int optionSelected;
extern int optionSelectedM;
extern int SurroundSound;

// TexScreen.cpp
extern IDirect3DTexture8 *TexScreen;
extern IDirect3DTexture8 *TexScreenShot;
extern LPDIRECT3DTEXTURE8 TexMenu;
extern LPDIRECT3DTEXTURE8 TexPreview;
extern LPDIRECT3DTEXTURE8 TexPreview2;
extern LPDIRECT3DTEXTURE8 TexPreviewMedia;
extern LPDIRECT3DTEXTURE8 TexResize;
extern LPDIRECT3DTEXTURE8 TexController;
extern LPDIRECT3DTEXTURE8 TexHelp;
extern LPDIRECT3DTEXTURE8 TexSplash;
extern LPDIRECT3DTEXTURE8 TexSplashFinal;
extern LPDIRECT3DTEXTURE8 TexPreviewBorder;
extern LPDIRECT3DTEXTURE8 TexLogo;
extern LPDIRECT3DTEXTURE8 TexLogo2;
extern IDirect3DTexture8 *TexJBoxArt;
extern IDirect3DTexture8 *TexStatePreview;
extern IDirect3DTexture8 *TexGUIPreview;
extern IDirect3DTexture8 *TexNoStatePreview;
extern IDirect3DTexture8 *TexNoBox;
extern IDirect3DTexture8 *TexMainMenu;
extern IDirect3DTexture8 *TexPreviewResize;
extern IDirect3DTexture8 *TexImage;
extern int FontCenteredText(WCHAR *,int,int, int);
extern LPDIRECT3DTEXTURE8 TexStationary_0;
extern LPDIRECT3DTEXTURE8 TexStationary_1;
extern LPDIRECT3DTEXTURE8 TexStationary_2;
extern LPDIRECT3DTEXTURE8 TexStationary_3;
extern LPDIRECT3DTEXTURE8 TexStationary_4;
extern LPDIRECT3DTEXTURE8 TexStationary_5;
extern LPDIRECT3DTEXTURE8 TexStationary_6;
extern LPDIRECT3DTEXTURE8 TexStationary_7;
extern LPDIRECT3DTEXTURE8 TexStationary_8;
extern LPDIRECT3DTEXTURE8 TexStationary_9;
extern LPDIRECT3DTEXTURE8 TexStationary_10;
extern LPDIRECT3DTEXTURE8 TexStationary_11;
extern LPDIRECT3DTEXTURE8 TexStationary_12;
extern LPDIRECT3DTEXTURE8 TexStationary_13;
extern LPDIRECT3DTEXTURE8 TexStationary_14;

extern LPDIRECT3DTEXTURE8 TexStationary_15;
extern LPDIRECT3DTEXTURE8 TexStationary_16;
extern LPDIRECT3DTEXTURE8 TexStationary_17;
extern int TexWidth,TexHeight;
int TexScreenInit(char* path);
void TexScreenExit();
int TexScreenSwizzle();
int TexScreenLinear();
