#ifndef GLOBAL
#define GLOBAL
#include <xtl.h>
#include <string>
#include <vector>
#include <algorithm>
#include <direct.h>
#include <tchar.h>
#include <fstream>
#include "Undocumented.h"
#include "xbinput.h"
#include "XBUtil.h"
#include "XBSound.h"
#include "gameinp.h"
#include <stdlib.h>
#include <sstream>
#include "Mp3Player.h"
#include "custom_launch_params.h"
#include "time.h"
using namespace std;
#define GIT_SWITCH			(0x02)
#define MAIN_MENU 0
#define ROM_SELECT 1
#define FAVORITE_SELECT 2
typedef unsigned char bool8;
typedef unsigned char uint8;
typedef unsigned short uint16;
typedef signed char int8;
typedef short int16;
typedef long int32;
typedef unsigned int uint32;
extern IDirect3D8 *Direct3D;
extern IDirect3DDevice8 *Device;
extern IDirect3DSurface8 *DirectBack;
extern IDirect3DVertexBuffer8 *VertexBuffer;
extern IDirect3DVertexBuffer8 *VertexBufferMenu;
extern IDirect3DVertexBuffer8 *VertexBufferMainMenuOverlay1;
extern IDirect3DVertexBuffer8 *VertexBufferMainMenuOverlay2;
extern IDirect3DVertexBuffer8 *VertexBufferMainMenuOverlay3;
extern IDirect3DVertexBuffer8 *VertexBufferMainMenuOverlay4;
extern IDirect3DVertexBuffer8 *VertexBufferMainMenuOverlay5;
extern IDirect3DVertexBuffer8 *VertexBufferMainMenuOverlay6;
extern IDirect3DVertexBuffer8 *VertexBufferPreview;
extern IDirect3DVertexBuffer8 *VertexBufferPreviewBorder;
extern IDirect3DVertexBuffer8 *VertexBufferPreviewVertical;
extern IDirect3DVertexBuffer8 *VertexBufferPreviewBorderVertical;
extern IDirect3DVertexBuffer8 *VertexBufferInfoBorder;
extern IDirect3DVertexBuffer8 *VertexBufferInfoBorderSimple;
extern IDirect3DVertexBuffer8 *VertexBufferVideoBorder;
extern IDirect3DVertexBuffer8 *VertexBufferDualVideoBorder;
extern IDirect3DVertexBuffer8 *VertexBufferROMBorder;
extern IDirect3DVertexBuffer8 *VertexBufferSelectBorder;
extern IDirect3DVertexBuffer8 *VertexBufferExitGame;
extern IDirect3DVertexBuffer8 *VertexBufferAlternatePreview;
extern IDirect3DVertexBuffer8 *VertexBufferAlternatePreviewBorder;
extern IDirect3DVertexBuffer8 *VertexBufferAlternatePreviewVertical;
extern IDirect3DVertexBuffer8 *VertexBufferAlternatePreviewBorderVertical;
extern IDirect3DVertexBuffer8 *VertexBufferAnimatedLogo;
extern IDirect3DVertexBuffer8 *VertexBufferAnimatedLogoMainMenu;
extern IDirect3DVertexBuffer8 *VertexBufferSplashScreen;
extern IDirect3DVertexBuffer8 *VertexBufferImage;
extern IDirect3DTexture8 *TexMainMenuOverlay;
extern IDirect3DTexture8 *TexScreen;
extern IDirect3DTexture8 *TexROMBrowser;
extern IDirect3DTexture8 *TexOption;
extern IDirect3DTexture8 *TexPreview;
extern IDirect3DTexture8 *TexPreviewBorder;
extern IDirect3DTexture8 *TexInfoBorder;
extern IDirect3DTexture8 *TexInfoBorderSimple;
extern IDirect3DTexture8 *TexVideoBorder;
extern IDirect3DTexture8 *TexROMBorder;
extern IDirect3DTexture8 *TexSelectedBorder;
extern IDirect3DTexture8 *TexAnimatedLogo;
extern IDirect3DTexture8 *TexMainMenu;
extern IDirect3DTexture8 *TexSplashScreen;
extern IDirect3DTexture8 *TexAnimatedLogoMainMenu;
extern IDirect3DTexture8 *TexImage;
extern D3DPRESENT_PARAMETERS d3dpp; 
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 CustomVertex VertexList[4];
extern CustomVertex VertexListMenu[4];
extern CustomVertex VertexListMainMenuOverlay1[4];
extern CustomVertex VertexListMainMenuOverlay2[4];
extern CustomVertex VertexListMainMenuOverlay3[4];
extern CustomVertex VertexListMainMenuOverlay4[4];
extern CustomVertex VertexListMainMenuOverlay5[4];
extern CustomVertex VertexListMainMenuOverlay6[4];
extern CustomVertex VertexListPreview[4];
extern CustomVertex VertexListPreviewBorder[4];
extern CustomVertex VertexListInfoBorder[4];
extern CustomVertex VertexListInfoBorderSimple[4];
extern CustomVertex VertexListVideoBorder[4];
extern CustomVertex VertexListDualVideoBorder[4];
extern CustomVertex VertexListROMBorder[4];
extern CustomVertex VertexListSelectBorder[4];
extern CustomVertex VertexListExitGame[4];
extern CustomVertex VertexListAlternatePreview[4];
extern CustomVertex VertexListAlternatePreviewBorder[4];
extern CustomVertex VertexListAlternatePreviewVertical[4];
extern CustomVertex VertexListAlternatePreviewBorderVertical[4];
extern CustomVertex VertexListAnimatedLogo[4];
extern CustomVertex VertexListAnimatedLogoMainMenu[4];
extern CustomVertex VertexListSplashScreen[4];
extern CustomVertex VertexListPreviewBorderVertical[4];
extern CustomVertex VertexListPreviewVertical[4];
extern CustomVertex VertexListImage[4];
extern int TexWidth;
extern int TexHeight;
struct GameDBEntry {
	std::string name;
	std::string displayName;
	std::string date;
	std::string manufacturer;
	std::string system;
	std::string genre;
	std::string parent;
};
struct guideDBEntry {
	string name;
	string path;
};

extern double slowGuide;
extern int guideGameSelectedText;
extern int guideGameSelected;
extern vector<guideDBEntry> guideDatabase;
extern double analogSpeed;
extern std::vector<GameDBEntry> GameDatabase;
extern std::vector<GameDBEntry> GameDatabaseTemp;
extern std::vector<GameDBEntry> FavoritesDatabase;
extern int GameFavoriteSelected;
static FILE *DebugFile;
extern int MenuSelected;
extern int OptionSelected;
extern int FilterSelected;
extern int OptionGUITextSelected;
extern int OptionControllerSelected;
extern int OptionControllerMacroSelected;
extern int OptionGUISelected;
extern int OptionControllerButtonSelected;
extern bool Emulation;
extern int OptionVideoSelected;
extern int OptionEmulationVideoSelected;
extern int OptionSoundSelected;
extern int OptionEmulationSoundSelected;
extern int GameOptionSelected;
extern int OptionGUIControllerItemsSelected;
extern bool setDisplay;
extern bool m_bVideoModeChanged;
extern bool v720pAvailable;
extern bool v480pAvailable;
extern void ClickSound();
extern bool v1080iAvailable;
extern int sWidth;
extern int sHeight;
extern bool exitGameMenu;
extern int resetGame;
extern int dipSwitches;
extern bool scale;
extern int SaveSlotSelected;
extern int OptionGUIImageSelected;
extern int OptionGUIImageSelectedPage2;
extern bool analogScroll;
extern int controller1Count;
extern int GameInfoDetailSelected;
extern int controller2Count;
extern int controller3Count;
extern int controller4Count;
extern int TurboController;
extern int ATurbo;
extern int BTurbo;
extern int XTurbo;
extern int YTurbo;
extern int WhiteTurbo;
extern int BlackTurbo;
extern int LeftTurbo;
extern int RightTurbo;
extern bool exitEmulation;
extern int ArcadeSettingSelected;
struct Category {
	string name;
	string genre;
};
extern vector<string> FilterItems;
extern vector <string> FilterGenre;
extern vector <string> FilterCompany;
extern vector <string> FilterYear;
extern vector <string> FilterCustom;
extern vector<string> GameInfoDetail;
extern std::vector<string> OptionItems;
extern std::vector<string> OptionVideoItems;
extern std::vector<string> OptionVideoValueItems;
extern std::vector<string> OptionEmulationVideoItems;
extern std::vector<string> OptionEmulationVideoValueItems;
extern std::vector<string> OptionSoundItems;
extern std::vector<string> OptionSoundValueItems;
extern std::vector<string> OptionControllerItems;
extern std::vector<string> OptionControllerMacroItems;
extern std::vector<string> OptionGUIItems;
extern std::vector<string> OptionControllerButtonItems[4];
extern std::vector<string> OptionControllerButtonValueItems[4];
extern std::vector<string> GameOptionItems;
extern std::vector<string> OptionEmulationSoundItems;
extern std::vector<string> OptionEmulationSoundValueItems;
extern std::vector<string> SaveStateItems;
extern std::vector<string> LoadStateItems;
extern std::vector<string> OptionGUITextItems;
extern std::vector<string> OptionGUITextValueItems;
extern std::vector<string> OptionGUITextPage2Items;
extern std::vector<string> OptionGUITextPage2ValueItems;
extern std::vector<string> OptionGUIImageItems;
extern std::vector<string> OptionGUIImageValueItems;
extern std::vector<string> OptionGUIImageItemsPage2;
extern std::vector<string> OptionGUIImageValueItemsPage2;
extern std::vector<string> OptionGUIControllerItems;
extern std::vector<string> guide;
extern int slow;// 0;
extern float zLeftScale;//0;
extern float zRightScale;//0;
extern float zTopScale;//0;
extern float zBottomScale;//0;
extern float leftMove;// 0;
extern float rightMove;// 0;
extern float topMove;// 0;
extern float bottomMove;// 0;
extern int zoomOver;// 0;
extern int OptionGUITextPage2Selected;// 0;
extern float zBaseLeft;//-2.899998;
extern float zBaseRight;//2.809998;
extern float zBaseTop;//-0.620000;
extern float zBaseBottom;//0.580000;
extern float zLeft;//0;
extern float zRight;//0;
extern float zTop;//0;
extern float zBottom;//0;
extern int GameSelected;// 0;
extern bool resumeGUI;// false;
extern WCHAR msg[1024];//{0};
extern int CheatSelected;// 0;
extern int CheatValueSelected;// 0;
extern bool videoRender;// false;
extern string activeMovie;// "";
extern int SetAlpha;// 0;
extern int DebugX;// 40;
extern int DebugY;// 20;
extern int turboControllerSelected;// 0; 
extern float speedROMBrowserLogo;// 0.0095;
extern float distanceROMBrowserLogo;// 0.3;
extern float cMoveROMBrowserLogo;// 0;
extern float lMoveROMBrowserLogo;// -1 * distanceROMBrowserLogo;
extern float rMoveROMBrowserLogo;// distanceROMBrowserLogo;
extern float tMoveROMBrowserLogo;// distanceROMBrowserLogo;
extern float bMoveROMBrowserLogo;// -1 * distanceROMBrowserLogo;
extern float lastTimeROMBrowserLogo;// 0;
extern LARGE_INTEGER ticksPerSecondROMBrowserLogo;
extern LARGE_INTEGER tickROMBrowserLogo;
extern LARGE_INTEGER timeROMBrowserLogo;
extern float lastTimeSplashScreen;// 0;
extern LARGE_INTEGER ticksPerSecondSplashScreen;
extern LARGE_INTEGER tickSplashScreen;
extern LARGE_INTEGER timeSplashScreen;
extern int OptionControllerTurboSelected;// 0;
extern vector<string> OptionControllerTurboItems;
extern vector<string> OptionControllerTurboValueItems;
extern float RotationDegrees;// 0;
struct ArcadeSetting {
	std::string name;
	int code;
	int count;
};
extern std::vector<ArcadeSetting> arcadeSettings;
extern Mp3Player m_mp3player;
extern HANDLE g_hSoundThread;
extern DWORD g_dwSoundThreadId;
extern std::string RomPath1;
extern std::string RomPath2;
extern std::string RomPath3;
extern std::string RomPath4;
extern std::string RomPath5;
extern std::string RomPath6;
extern std::string RomPath7;
extern std::string RomPath8;
extern std::string ArtworkPath1;//"D:\\artwork\\Shots 1";
extern std::string ArtworkPath2;//"D:\\artwork\\Shots 2";
extern std::string ArtworkPath3;//"D:\\artwork\\Shots 3";
extern std::string ArtworkPath4;//"D:\\artwork\\Shots 4";
extern std::string ArtworkPath5;//"D:\\artwork\\Shots 5"; 
extern std::string ArtworkPath6;//"D:\\artwork\\Shots 6"; 
extern std::string ArtworkPath7;//"D:\\artwork\\Shots 7"; 
extern std::string ArtworkPath8;//"D:\\artwork\\Shots 8"; 
extern std::string NVRAMPath;//"D:\\nvram"; 
extern std::string IniPath;//"D:\\ini"; 
extern std::string SaveStatePath;//"D:\\savestates"; 
extern std::string ConfigPath;//"D:\\config";
extern std::string SkinPath;//"arcade";
extern int UsePathINI;// 0;
extern unsigned int m_performanceFreq[2];
extern int CurrentArtwork;// 1;
extern bool PreviewSwitch;// false;
extern int GUIState;// MAIN_MENU;
extern int GameListWidth;//530;
extern int GameListX;//55;
extern int GameListY;//343;
extern int HDMode;//0;
extern int vSpace;//20;
extern int SoftwareFilter;//1;
extern int HardwareFilter;//2;
extern int vsyncEnabled;//1;
extern int AspectCorrect;//0;
extern int dimColor;//1;
extern int pixelRatio;//0;
extern int FlickerFilter;//0;
extern int Soften;//0;
extern int FreeRotate;//0
extern int scrollSpeed;//2;
extern int GameOptionPosX;//470;
extern int GameOptionPosY;//110;
extern float FontSize;//16;
extern int GameListCount;//6;
extern int DefaultController;//0;
extern int MenuSpacing;//401;
extern int MenuPosY;//110;
extern int MenuPosX;//320;
extern int MenuDetailPosX;//74;
extern int MenuDetailPosY;//82;
extern int ROMPosY;//470;
extern float zLeftMenu;//-2.899998;
extern float zRightMenu;//2.809998;
extern float zTopMenu;//-0.620000;
extern float zBottomMenu;//0.580000;
extern float zLeftPreview;//-1.290000;
extern float zRightPreview;//-9.990133;
extern float zTopPreview;//-1.749999;
extern float zBottomPreview;//7.000066;
extern float zLeftPreviewBorder;//-1.290000;
extern float zRightPreviewBorder;//-9.990133;
extern float zTopPreviewBorder;//-1.749999;
extern float zBottomPreviewBorder;//7.000066;
extern float zLeftPreviewVertical;//-1.290000;
extern float zRightPreviewVertical;//-9.990133;
extern float zTopPreviewVertical;//-1.749999;
extern float zBottomPreviewVertical;//7.000066;
extern float zLeftPreviewBorderVertical;//-1.290000;
extern float zRightPreviewBorderVertical;//-9.990133;
extern float zTopPreviewBorderVertical;//-1.749999;
extern float zBottomPreviewBorderVertical;//7.000066;
extern float zLeftInfoBorder;//-1.290000;
extern float zRightInfoBorder;//-9.990133;
extern float zTopInfoBorder;//-1.749999;
extern float zBottomInfoBorder;//7.000066;
extern float zLeftInfoBorderSimple;//-1.290000;
extern float zRightInfoBorderSimple;//-9.990133;
extern float zTopInfoBorderSimple;//-1.749999;
extern float zBottomInfoBorderSimple;//7.000066;
extern float zLeftVideoBorder;//-1.290000;
extern float zRightVideoBorder;//-9.990133;
extern float zTopVideoBorder;//-1.749999;
extern float zBottomVideoBorder;//7.000066;
extern float zLeftROMBorder;//-1.290000;
extern float zRightROMBorder;//-9.990133;
extern float zTopROMBorder;//-1.749999;
extern float zBottomROMBorder;//7.000066;
extern float zLeftSelectBorder;//-1.290000;
extern float zRightSelectBorder;//-9.990133;
extern float zTopSelectBorder;//-1.749999;
extern float zBottomSelectBorder;//7.000066;
extern float zLeftAlternatePreview;//-1.290000;
extern float zRightAlternatePreview;//-9.990133;
extern float zTopAlternatePreview;//-1.749999;
extern float zBottomAlternatePreview;//7.000066;
extern float zLeftAlternatePreviewBorder;//-1.290000;
extern float zRightAlternatePreviewBorder;//-9.990133;
extern float zTopAlternatePreviewBorder;//-1.749999;
extern float zBottomAlternatePreviewBorder;//7.000066;
extern float zLeftAlternatePreviewVertical;//-1.290000;
extern float zRightAlternatePreviewVertical;//-9.990133;
extern float zTopAlternatePreviewVertical;//-1.749999;
extern float zBottomAlternatePreviewVertical;//7.000066;
extern float zLeftAlternatePreviewBorderVertical;//-1.290000;
extern float zRightAlternatePreviewBorderVertical;//-9.990133;
extern float zTopAlternatePreviewBorderVertical;//-1.749999;
extern float zBottomAlternatePreviewBorderVertical;//7.000066;
extern float zLeftAnimatedLogo;//-1.290000;
extern float zRightAnimatedLogo;//-9.990133;
extern float zTopAnimatedLogo;//-1.749999;
extern float zBottomAnimatedLogo;//7.000066;
extern float zLeftAnimatedLogoTemp;//-1.290000;
extern float zRightAnimatedLogoTemp;//-9.990133;
extern float zTopAnimatedLogoTemp;//-1.749999;
extern float zBottomAnimatedLogoTemp;//7.000066;
extern int GameInfoPosX;//337;
extern int GameInfoPosY;//263;
extern float GameInfoFontSize;//16;
extern int GameInfoVSpace;//21;
extern int GameInfoDetailNumLines;//10;
extern int GameInfoDetailPosX;//337;
extern int GameInfoDetailPosY;//263;
extern float GameInfoDetailFontSize;//16;
extern int GameInfoDetailWidth;//200;
extern int GameInfoDetailVSpace;//21;
extern float zLeftExitGame;//0.350000;
extern float zRightExitGame;//-10.370142;
extern float zTopExitGame;//-4.760014;
extern float zBottomExitGame;//5.270026;
extern int zoomSpeed;//25;
extern int GameGuideLines;// 22;
extern int GameGuideColor;// 0;
extern float GameGuideFontSize;// 15;
extern int guideLeft;// 50;
extern int GameGuideWidth;// 590;
extern int GameGuideVSpace;// 20;
extern int gameInfoListWidth;// 200;
extern bool fade;// false;
extern int fadeColor;// 0;
extern int fadeSpeed;// 17;
extern int fadeOption;// 0;
extern int CustomSelected;// 0;
extern int CompanySelected;// 0;
extern int YearSelected;// 0;
extern int GenreSelected;// 0;
extern int CustomSet;// 0;
extern int CompanySet;// 0;
extern int YearSet;// 0;
extern int GenreSet;// 0;
extern int GameInfoEnabled;// 1;
extern int GameInfoDetailEnabled;// 1;
extern int disableMenuSounds;// 0;
extern int turboSpeed;// 7;
extern int BackgroundMusicVolume;// DSBVOLUME_MAX;
extern std::vector<string> MainMenuItems;
extern float speedLogoMainMenu;// 0.0095;
extern float distanceLogoMainMenu;// 0.3;
extern float cMoveLogoMainMenu;// 0;
extern float lMoveLogoMainMenu;// -1 * distanceLogoMainMenu;
extern float rMoveLogoMainMenu;// distanceLogoMainMenu;
extern float tMoveLogoMainMenu;// distanceLogoMainMenu;
extern float bMoveLogoMainMenu;// -1 * distanceLogoMainMenu;
extern float lastTimeLogoMainMenu;// 0;
extern LARGE_INTEGER ticksPerSecondLogoMainMenu;
extern LARGE_INTEGER tickLogoMainMenu;
extern LARGE_INTEGER timeLogoMainMenu;
extern int MainMenuPosY;//110;
extern int MainMenuPosX;//320;
extern int MainMenuVSpace;//20;
extern float MainMenuFontSize;//16;
extern int MainMenuCentered;//0;
extern float zLeftAnimatedLogoMainMenu;//-1.290000;
extern float zRightAnimatedLogoMainMenu;//-9.990133;
extern float zTopAnimatedLogoMainMenu;//-1.749999;
extern float zBottomAnimatedLogoMainMenu;//7.000066;
extern float zLeftAnimatedLogoMainMenuTemp;//-1.290000;
extern float zRightAnimatedLogoMainMenuTemp;//-9.990133;
extern float zTopAnimatedLogoMainMenuTemp;//-1.749999;
extern float zBottomAnimatedLogoMainMenuTemp;//7.000066;
struct Button  {
	std::string name;
	unsigned int code;
	int ControllerButton;
};

struct Controller {
	std::vector <Button> buttons;
};

extern Controller controllers[4];
extern void ButtonUpdate(int q, int button);
extern void ResizeTexture();
extern int DxSoundPlay();
extern void MakeVertexList();
extern int SegaMain(std::string game);
extern int SetupMatrices();
extern int SetupMatricesEmulation();
extern int FontInit(int i );
extern void SetFontHeight(float v);
extern void InputInit();
extern void ReadInput();
extern int FontSetColour(DWORD colour);
extern int FontText(WCHAR *text,int dx,int dy, int maxWidth);
extern XBGAMEPAD g_Gamepads[4];
extern unsigned char leftAnalog;
extern unsigned char rightAnalog;
extern int MakeVertexListGUI();
extern int FontCenteredText(WCHAR *text,int dx,int dy, int maxWidth);
extern int FontGUI(WCHAR *text,int dx,int dy, int maxWidth);
extern WCHAR* ConvertCharStringToWCHAR(char* q);
extern int MakeScreenShot(char*);
extern int BurnStateSave(TCHAR* szName, int bAll);
extern int BurnStateLoad(TCHAR* szName, int bAll, int (*pLoadGame)());
extern "C" char* BurnDrvGetTextA(unsigned int i);
extern int nAudDSPModule;
extern int nAudSampleRate;
extern void ResetSound();
extern int FontGuideText(WCHAR *text,int dx,int dy, int maxWidth);
extern int nVidImageWidth;		// Memory buffer size
extern int nVidImageHeight;	
extern unsigned char* pVidImage;				// Memory buffer
extern int nVidImagePitch;
extern int FontSmallText(WCHAR *text,int dx,int dy, int maxWidth);
extern void DirectSoundInit();
extern int StatedAuto(int bSave);
extern "C" {
	extern TCHAR* BurnDrvGetText(unsigned int i);
	extern "C" int BurnDrvGetVisibleSize(int* pnWidth, int* pnHeight);
	extern unsigned int nBurnDrvSelect;
	extern unsigned int nBurnDrvCount;
	extern int BurnLibInit();
}

extern void AdvMame2x(const uint8 *srcPtr, uint32 srcPitch, uint8 *dstPtr, uint32 dstPitch, int width, int height);
extern void SuperScale(unsigned short *src,unsigned int srcpitch,
					   unsigned short *dst,unsigned int dstpitch,
					   unsigned short width,unsigned short height);
extern void hq2x(unsigned char *srcPtr, unsigned int srcPitch, unsigned char * /* deltaPtr */,
				 unsigned char *dstPtr, unsigned int dstPitch, int width, int height);
extern int nVidImageBPP;
extern struct GameInp* GameInp;
extern unsigned int nGameInpCount;
extern TCHAR* InputNumToName(unsigned int i);
extern void stopMovie();
extern void drawMovie();
extern bool initMovie(char* name);
extern TCHAR szAppRomPaths[8][260];
extern float fLeft;
extern float fRight;
extern float fTop;
extern float fBottom;
extern float fLeftMenu;
extern float fRightMenu;
extern float fTopMenu;
extern float fBottomMenu;
struct FBACheat {
	string name;
	vector<string> value;
	int enabled;
	int cheat;
};
extern vector<FBACheat> FbaCheats;
extern float fps;
extern "C" {
	extern int CheatEnable(int nCheat, int nOption);
}

extern void DrawCheatMenu();
extern void DrawArcadeSettingsMenu();
extern void DrawCheatDetailMenu();
extern void DrawOptionControllerTurboItem(int MenuItemNumber, char* text, int x, int y);
extern void DrawOptionControllerTurboMenu();
extern void UpdateButtonDescriptions();
extern void SaveControllerIni();
extern void ButtonUpdate(int q, int button);
extern void SetupControllers();
extern void UpdateTurboDescriptions();
extern void LoadControllerIni();
extern void DrawOptionControllerItem(int MenuItemNumber, char* text, int x, int y);
extern void DrawOptionControllerMenu();
extern void OptionControllerMenu();
extern void DrawOptionControllerButtonItem(int MenuItemNumber, char* text, int x, int y);
extern void DrawOptionControllerButtonMenu();
extern void GameOptionInput();
extern void DrawGameOptionItem(int MenuItemNumber, char* text, int x, int y);
extern void DrawGameOptionMenu();
extern void GameOptionMenu();
extern void AddToFavorites();
extern void RemoveFromFavorites();
extern void SaveFavorites();
extern void FavoriteSelectInput();
extern void DrawGameFavoriteList();
extern void DrawFavoriteSelectMenu();
extern void FavoriteSelectMenu();
extern void DrawFilterDetailMenu(int &Selected, vector<string> &Filter);
extern void FilterInput();
extern void DrawFilterItem(int MenuItemNumber, char* text, int x, int y);
extern void DrawFilterMenu();
extern void FilterMenu();
extern void CustomMenu();
extern void CompanyMenu();
extern void YearMenu();
extern void GenreMenu();
extern void LoadGuide(char* p, char* n);
extern void SearchDirectoryText(std::string pathToSearch);
extern void DrawGuide();
extern void GuideListInput();
extern void DrawGameGuideList();
extern void DrawGuideListMenu();
extern void GuideListMenu();
extern void MenuBackground();
extern void ResetAnimatedLogoMainMenu();
extern void MakeVertexListAnimatedLogoMainMenu(bool animate);
extern void MainMenuInput();
extern void DrawMenuItem(int MenuItemNumber, char* text, int x, int y);
extern void DrawMainMenuItem(int MenuItemNumber, char* text, int x, int y);
extern void DrawMainMenu();
extern void MainMenu();
extern void DrawOptionGUIImageItemPage2(int MenuItemNumber, char* text, int x, int y);
extern void DrawOptionGUIImageItemsMenuPage2();
extern void OptionGUIImageItemsInputPage2();
extern void OptionGUIImageItemsInput();
extern void DrawOptionGUIImageItem(int MenuItemNumber, char* text, int x, int y);
extern void DrawOptionGUIImageItemsMenu();
extern void OptionGUIImageItemsMenu();
extern void OptionGUIInput();
extern void DrawOptionGUIItem(int MenuItemNumber, char* text, int x, int y);
extern void DrawOptionGUIMenu();
extern void OptionGUIMenu();
extern void OptionGUITextItemsInput();
extern void DrawOptionGUITextItem(int MenuItemNumber, char* text, int x, int y);
extern void DrawOptionGUITextPage2Item(int MenuItemNumber, char* text, int x, int y);
extern void DrawOptionGUITextItemsMenu();
extern void OptionGUITextItemsMenu();
extern void OptionInput();
extern void DrawOptionItem(int MenuItemNumber, char* text, int x, int y);
extern void DrawOptionMenu();
extern void OptionMenu();
extern void MakeVertexListAnimatedLogo(bool animate);
extern void ROMSelectInput();
extern void DrawGameList();
extern void DrawROMSelectMenu();
extern void ROMSelectMenu();
extern void CreateSaveDirectory(int e);
extern void CreateDirectories(string game);
extern void SaveStateInput();
extern void LoadStateInput();
extern void DrawLoadStateItem(int MenuItemNumber, char* text, int x, int y);
extern void DrawSaveStateItem(int MenuItemNumber, char* text, int x, int y);
extern void DrawSaveStateMenu();
extern void OptionSaveStateMenu();
extern void OptionLoadStateMenu();
extern void OptionSoundInput();
extern void DrawOptionSoundItem(int MenuItemNumber, char* text, int x, int y);
extern void DrawOptionSoundMenu();
extern void OptionEmulationSoundInput();
extern void DrawOptionEmulationSoundItem(int MenuItemNumber, char* text, int x, int y);
extern void DrawOptionEmulationSoundMenu();
extern void OptionSoundMenu();
extern void InitROMSelectEditMenu();
extern void ExitROMSelectEditMenu();
extern void DrawROMSelectEditMenu();
extern void ResetAnimatedLogo();
extern void CyclePreview(int e);
extern void DisplayMessage(char* q);
extern void DisplayCenteredMsg(char* q, int y);
extern void DrawMsg(char* text, int x, int y);
extern void DrawGameInfoItem(char* text, int x, int y);
extern void DrawGameInformationDetail();
extern void DrawGameInformation();	
extern void DrawGameFavoriteInformation();	
extern void SaveGameIni(string e);
extern void LoadGameIni(string e);
extern void SaveScreenIni();
extern void LoadScreenIni();
extern void SaveIni();
extern void SetParameters(FILE* f);
extern void LoadSkinIni(std::string skin);
extern void LoadIni();
extern void ReturnToGUI();
extern void ROMError(char* msg);
extern void OutOfMemory();
extern void SplashScreen();
extern void SaveGameList();
extern void Scan();
extern void UpdatePreview(string game, string parent);
extern void DisplayFreeMemory();
extern void DisplayFPS();
extern void Debug();
extern void DisplayInstructions(char* text);
extern void ZeroTexture();
extern void SetupDefaultPaths();
extern void SetupPath();
extern void MakeVertexListMenu();
extern void MakeVertexListPreviewBorder();
extern void MakeVertexListAlternatePreviewBorder();
extern void MakeVertexListAlternatePreviewBorderVertical();
extern void MakeVertexListInfoBorder();
extern void MakeVertexListInfoBorderSimple();
extern void MakeVertexListVideoBorder();
extern void MakeVertexListROMBorder();
extern void MakeVertexListSelectedBorder();
extern void MakeVertexListPreview();
extern void MakeVertexListAlternatePreview();
extern void MakeVertexListAlternatePreviewVertical();
extern void MakeVertexListExitGame();
extern void MakeVertexList();
extern void InitFilter();
extern void NoFilter();
extern void FilterSuperScale();
extern void FilterAdvancedMame();
extern void FilterHQ2X();
extern void Simple2x(unsigned char *srcPtr, unsigned int srcPitch, unsigned char *,
					 unsigned char *dstPtr, unsigned int dstPitch, int width, int height);
extern void FilterSimple2X();
extern void DirectScreen();
extern void ResizeTexture();
extern void DrawBackground();
extern void SetHardwareFilter();
extern void CheckForHDTVResolutions();
extern void StartHDMode(); 
extern void RestoreResolution();
extern void SetFlickerSoft();
extern void OptionVideoInput();
extern void OptionEmulationVideoInput();
extern void DrawOptionVideoItem(int MenuItemNumber, char* text, int x, int y);
extern void DrawOptionEmulationVideoItem(int MenuItemNumber, char* text, int x, int y);
extern void DrawOptionVideoMenu();
extern void OptionVideoMenu();
extern void OptionVideoScaleInput();
extern void DrawOptionVideoScaleMenu();
extern void OptionVideoScaleMenu();
extern void Init();
extern void UpdateGUI();
extern void RunGUI();
extern string ConvertIntToString(int n);
extern WCHAR* ConvertCharStringToWCHAR(char* q);
extern std::string GetFileString(FILE* f);
extern int GetFileInteger(FILE * f);
extern float GetFileFloat(FILE * f);
extern float freeMemory();
extern void* osd_malloc(int n);
extern int AnimateSplashScreen();
extern bool LoadGameList();
extern "C" int dprintf(char *format, ...);
extern HRESULT Mount(const char* szDrive, char* szDevice);
extern HRESULT Unmount(const char* szDrive);
extern bool OptionControllerButtonInput();
extern DWORD WINAPI Mp3player_ThreadFunc( LPVOID lpParam );
extern DWORD WINAPI Mp3player_ThreadFuncSplash( LPVOID lpParam );
extern bool BuildFavorites();
extern int DirectInit();
extern bool OptionControllerInput();
extern void ControllerInit();
extern void UpdateTurboButtons();
extern int PreviewSwitchValid();
extern LARGE_INTEGER ticksPerSecondPreviewSwitch;
extern LARGE_INTEGER tickPreviewSwitch;
extern LARGE_INTEGER timePreviewSwitch;
extern float lastTimePreviewSwitch;
extern LARGE_INTEGER ticksPerSecondDelay;
extern LARGE_INTEGER tickDelay;
extern LARGE_INTEGER timeDelay;
extern float lastTimeDelay;
extern int CommandLineLaunch;
extern bool AlternatePreviewVerticalResize;
extern bool AlternatePreviewBorderVerticalResize;
extern bool PreviewVerticalResize;
extern bool PreviewBorderVerticalResize;
extern bool PreviewResize;
extern bool PreviewBorderResize;
extern bool AlternatePreviewResize;
extern bool AlternatePreviewBorderResize;
extern bool GameInfoDetailResize;
extern bool GameInfoResize;
extern bool VideoResize;
extern CUSTOM_LAUNCH_DATA g_launchData;
extern int g_autoLaunchGame;
extern void MakeVertexListPreviewVertical();
extern void MakeVertexListPreviewBorderVertical();
extern int CursorSpeed;
extern int DelayValid();
extern int ScrollSpeed;
extern int ScrollSpeedCount;
extern void CancelSound();
extern void ConfirmSound();
extern int AnimateROMBrowserLogoTimer();
extern void SetDelay();
extern void SetDelayGuwange();
extern unsigned int SourceWidth;
extern unsigned int SourceHeight;
extern void DrawROMList(int Mode);
struct Macro {
	bool enabled;
	int buttonSet;
	std::vector<int> buttons;
	std::string desc;
};
extern std::vector<Macro> MacroSet[4];
extern void DrawOptionControllerMacroItem(int MenuItemNumber, char* text, int x, int y);
extern void DrawOptionControllerMacroMenu();
extern bool OptionMacroInput();
extern void DrawMacroMenu();
extern int MacroSelected;
extern bool OptionControllerMacroInput();
extern int MacroModSelected;
extern Mp3Player m_mp3playerSplash;
extern HANDLE g_hSoundThreadSplash;
extern DWORD g_dwSoundThreadIdSplash;
extern unsigned int m_performanceFreqSplash[2];
extern bool SplashFinshed;
extern int SkinSelected;
extern vector<string> Skin;
extern bool SkinMenuInput();
extern void BuildSkins();
extern void DrawSkinMenu();
extern void OptionGUIImageItemsMenuPage2();
extern void OptionGUITextItemsMenuPage2();
extern void GameListAdjust();
extern void MainMenuAdjust();
extern void MenuDetailAdjust();
extern void GameOptionAdjust();
extern void MenuAdjust();
extern void ROMAdjust();
extern void GameInfoAdjust();
extern void GameInfoDetailAdjust();
extern void BackgroundAdjust();
extern void PreviewAdjust();
extern void ExitGameAdjust();
extern void MovieAdjust();
extern void MainMenuMovieAdjust();
extern void PreviewBorderAdjust();
extern void InfoBorderAdjust();
extern void VideoBorderAdjust();
extern void ROMBorderAdjust();
extern void SelectBorderAdjust();
extern void AlternatePreviewAdjust();
extern void AlternatePreviewBorderAdjust();
extern void AnimatedLogoAdjust();
extern void AnimatedLogoMainMenuAdjust();
extern void InfoBorderSimpleAdjust();
extern void AlternatePreviewVerticalAdjust();
extern void AlternatePreviewBorderVerticalAdjust();
extern void PreviewVerticalAdjust();
extern void PreviewBorderVerticalAdjust();
extern void playEffect(int i);
extern void updateEffect();
extern void effectInit();
extern string ConvertFloatToString(float n);
extern bool FPS;
extern void SetRenderStates();
extern void ScanlinesTV(unsigned char *srcPtr, unsigned int srcPitch, unsigned char * /* deltaPtr */,
				 unsigned char *dstPtr, unsigned int dstPitch, int width, int height);
extern "C" void __cdecl Init_2xSaIMMX(unsigned int BitFormat);
extern void _2xSaI(unsigned char *srcPtr, unsigned int srcPitch, unsigned char *deltaPtr,
						unsigned char *dstPtr, unsigned int dstPitch, int width, int height);
extern void Super2xSaI(uint8 *srcPtr, uint32 srcPitch, uint8 *deltaPtr, uint8 *dstPtr, uint32 dstPitch, int width, int height);
extern void SuperEagle(uint8 *srcPtr, uint32 srcPitch, uint8 *deltaPtr, uint8 *dstPtr, uint32 dstPitch, int width, int height);
extern unsigned char* _2xSaiBuffer;
extern void SuperScale75(unsigned short *src,unsigned int srcpitch,unsigned short *dst,unsigned int dstpitch,unsigned short width,unsigned short height);
extern "C" int nInterpolation;
extern "C" int nFMInterpolation;	
extern void (*renderMethod[10])();
extern float zLeft0;
extern float zRight0;
extern float zTop0;
extern float zBottom0;
extern float zLeft90;
extern float zRight90;
extern float zTop90;
extern float zBottom90;
extern float zLeft180;
extern float zRight180;
extern float zTop180;
extern float zBottom180;
extern float zLeft270;
extern float zRight270;
extern float zTop270;
extern float zBottom270;
extern void ExitGameAdjust90();
extern void ExitGameAdjust180();
extern void ExitGameAdjust270();
//extern void SetMainMenu();
extern void MainMenuOverlay1Adjust();
extern void MainMenuOverlay2Adjust();
extern void MainMenuOverlay3Adjust();
extern void MainMenuOverlay4Adjust();
extern void MainMenuOverlay5Adjust();
extern void MainMenuOverlay6Adjust();
extern void MakeVertexListMainMenuOverlay1();
extern void MakeVertexListMainMenuOverlay2();
extern void MakeVertexListMainMenuOverlay3();
extern void MakeVertexListMainMenuOverlay4();
extern void MakeVertexListMainMenuOverlay5();
extern void MakeVertexListMainMenuOverlay6();
extern float zLeftMainMenuOverlay1;
extern float zRightMainMenuOverlay1;
extern float zTopMainMenuOverlay1;
extern float zBottomMainMenuOverlay1;
extern float zLeftMainMenuOverlay2;
extern float zRightMainMenuOverlay2;
extern float zTopMainMenuOverlay2;
extern float zBottomMainMenuOverlay2;
extern float zLeftMainMenuOverlay3;
extern float zRightMainMenuOverlay3;
extern float zTopMainMenuOverlay3;
extern float zBottomMainMenuOverlay3;
extern float zLeftMainMenuOverlay4;
extern float zRightMainMenuOverlay4;
extern float zTopMainMenuOverlay4;
extern float zBottomMainMenuOverlay4;
extern float zLeftMainMenuOverlay5;
extern float zRightMainMenuOverlay5;
extern float zTopMainMenuOverlay5;
extern float zBottomMainMenuOverlay5;
extern float zLeftMainMenuOverlay6;
extern float zRightMainMenuOverlay6;
extern float zTopMainMenuOverlay6;
extern float zBottomMainMenuOverlay6;
extern void OptionGUIImageItemsMenuPage3();
extern std::vector<string> OptionGUIImageItemsPage3;
extern std::vector<string> OptionGUIImageValueItemsPage3;
extern int OptionGUIImageSelectedPage3;
extern void DrawOptionGUIImageItemPage3();
extern float fDualLeft;
extern float fDualRight;
extern float fDualTop;
extern float fDualBottom;
extern float zLeftDualVideoBorder;
extern float zRightDualVideoBorder;
extern float zTopDualVideoBorder;
extern float zBottomDualVideoBorder;
extern void DualMovieAdjust();
extern void DualVideoBorderAdjust();
extern bool DualVideoResize;
extern bool DualVideoBorderResize;
extern void MakeVertexListDualVideoBorder();
extern std::string HiScorePath;
extern void Present();
extern LARGE_INTEGER ScreenSaverDelay;
extern float ScreenSaverLastTimeDelay;
extern void ResetScreenSaver();
extern void FBACrashed();
extern int DxSoundStop();
extern int screenSaverTime;
extern std::string VideoPath;
extern unsigned char SNKBIOS;
extern void OptionScreen();
extern bool setDisplay;
extern void Present();
extern int FlickerFilter;
extern int Soften;
extern int HiScoreSaving;
extern unsigned char CPS1Difficulty;
extern unsigned char CPS1FreePlay;
extern int DisplayMode;
extern void CheckFilter(int i);
extern int MovieEnabled;
extern int MainMenuMovieSwitchEnabled;
extern int MovieSound;
extern unsigned int AnalogSpeed;
extern bool SetDips;
struct DIPItem {
	string description;
	vector<string> valueDescription;
	vector<unsigned char> value;
	vector<int> enabled;
	vector<unsigned char> mask;
};

struct DIPSetting {
	int dipID;
	unsigned char value;
	vector<DIPItem> dipItems;
};

extern vector<DIPSetting> arcradeSettings;

struct DipSwitchSetting {
		string description;
		string value;
};

extern vector <DipSwitchSetting> DipSwitchSettings;
extern int DipSwitchSelected;
extern void SetDip(char* description, char* value);
extern int DipEnabled;
extern int GeneralOptionsSelected;
extern vector<string> GeneralOptionsSettings;
extern vector<string> GeneralOptionsValueSettings;
extern unsigned short CPUSpeed;
extern "C" int nBurnCPUSpeedAdjust;
extern bool delay;
extern unsigned char SNKBIOS;
extern int neoGeoFree;
extern int bAlwaysDrawFrames;
extern int HighlightParent;
extern float zTopBI;// -1.019999f;
extern float zLeftBI;//0.039999f;
extern float zBottomBI;// -2.24f;
extern float zRightBI;//-0.56f
extern double slowImage;
extern int ImageDBGameSelected;
extern int DrawImageMenu;
extern int ImageList;
extern int ImageSelected;
extern int ImageListDelete;
extern int ImageGameSelected;
extern float imageMovementSpeed;
extern float imageScaleSpeed;

struct ImageDBEntry {
	string name;
	string path;
	bool isAGame;
	bool isARoot;
	bool isADirectory;
	bool topLevel;
};

extern vector<string> ImageDirectories;
extern vector<ImageDBEntry> ImageDatabase;
extern int PauseGame;
extern void ImageSelectedMenu(char* gameName);
extern void DrawArcadeInfo();
extern float XBINPUT_DEADZONE;
extern string MainMenuVideoPath0;
extern string MainMenuVideoPath1;
extern string MainMenuVideoPath2;
extern string MainMenuVideoPath3;
extern string MainMenuVideoPath4;
extern string MainMenuVideoPath5;
extern void GenerateDat();
#endif