#include <xtl.h>
#include "xbinput.h"
#include <string>
#include <vector>
#include <sstream>
#include "D3dx8tex.h"

extern "C" {
	extern unsigned char snesmouse;
}
extern void initKeyboard();
int rumbleDatabasePick = 0;
int rumbleDatabaseDelete = 0;

int TGADatabasePick = 0;
int TGADatabaseDelete = 0;
extern int screenGeneralOptionsTGA;
extern DWORD m_dwNumBulletHoles;
extern std::string RUMBLE_PATH;
extern float imageMovementSpeed;
extern float imageScaleSpeed;
extern int GameNameColor;
extern int GameNameSelectedColor;
int lightGunMode = 0;
extern int FolderColor;
extern int MenuOption;
extern int MenuOptionSelected;
extern "C" int dprintf(char *format, ...);
extern int FontSizeGUI;
extern int FullNameColor;
extern DWORD menuColor[5];
extern void resetKeyBoard();
extern void inputInit();
extern void readInput();
extern int keyBoardDisplay;
extern int screenOptions;
extern "C" {
	unsigned char supressCursor = 0;
}
extern unsigned int gameCRC;
int lgRumble = 1;
extern float zTopBI;// -1.019999f;
extern float zLeftBI;//0.039999f;
extern float zBottomBI;// -2.24f;
extern float zRightBI;//-0.56f
extern float zTop;// -1.019999f;
extern float zLeft;//0.039999f;
extern float zBottom;// -2.24f;
extern float zRight;//-0.56f

int leftRumblelg = 255;
int rightRumblelg = 255;
float timeRumblelg = 0.03f;
#include <string.h>
#include <sstream>
using namespace std;
extern int screenOptionsM;
extern void StartLightGun();
extern int lightGun;
extern int screenOptionsHelp;
int controllerRumbleMenu = 0;
extern int ggCodes[15][8+1+27];
extern int csCodes[15][8+1+27];
extern int Codes[15][8+1+27];
extern const char *S9xGameGenieToRaw (const char *code, unsigned int &address, unsigned char &byte);
int displayRumbleConfig = 0;
int rumbleSlotCount = 0;
extern int screenResize;
extern int screenResizeP;
extern int screenResizeI;
extern int screenResizePB;
extern int screenResizeJ;
extern int zLeftRM;
extern int zTopRM;
int pickRumbleSlot = 0;
extern int keyBoardDraw;
int rumbleType = 0;
extern string GARBAGE_PATH;
char cbuffer[28];
void fixBuffer(int *nbuffer) {
	cbuffer[27] = '\0';
	for(int i = 0; i < 27; i++) {
		cbuffer[i] = ' ';
		if(nbuffer[i] == 16)  cbuffer[i] = 'A'; 
		if(nbuffer[i] == 17)  cbuffer[i] = 'B'; 
		if(nbuffer[i] == 18)  cbuffer[i] = 'C'; 
		if(nbuffer[i] == 19)  cbuffer[i] = 'D'; 
		if(nbuffer[i] == 20)  cbuffer[i] = 'E'; 
		if(nbuffer[i] == 21)  cbuffer[i] = 'F'; 
		if(nbuffer[i] == 22)  cbuffer[i] = 'G'; 
		if(nbuffer[i] == 23)  cbuffer[i] = 'H'; 
		if(nbuffer[i] == 24)  cbuffer[i] = 'I'; 
		if(nbuffer[i] == 25)  cbuffer[i] = 'J'; 
		if(nbuffer[i] == 26)  cbuffer[i] = 'K'; 
		if(nbuffer[i] == 27)  cbuffer[i] = 'L'; 
		if(nbuffer[i] == 28)  cbuffer[i] = 'M'; 
		if(nbuffer[i] == 29)  cbuffer[i] = 'N'; 
		if(nbuffer[i] == 30)  cbuffer[i] = 'O'; 
		if(nbuffer[i] == 31)  cbuffer[i] = 'P'; 
		if(nbuffer[i] == 32)  cbuffer[i] = 'Q'; 
		if(nbuffer[i] == 33)  cbuffer[i] = 'R'; 
		if(nbuffer[i] == 34)  cbuffer[i] = 'S'; 
		if(nbuffer[i] == 35)  cbuffer[i] = 'T'; 
		if(nbuffer[i] == 36)  cbuffer[i] = 'U'; 
		if(nbuffer[i] == 37)  cbuffer[i] = 'V'; 
		if(nbuffer[i] == 38)  cbuffer[i] = 'W'; 
		if(nbuffer[i] == 39)  cbuffer[i] = 'X'; 
		if(nbuffer[i] == 40)  cbuffer[i] = 'Y'; 
		if(nbuffer[i] == 41)  cbuffer[i] = 'Z'; 
		if(nbuffer[i] == 42)  cbuffer[i] = 'a'; 
		if(nbuffer[i] == 43)  cbuffer[i] = 'b'; 
		if(nbuffer[i] == 44)  cbuffer[i] = 'c'; 
		if(nbuffer[i] == 45)  cbuffer[i] = 'd'; 
		if(nbuffer[i] == 46)  cbuffer[i] = 'e'; 
		if(nbuffer[i] == 47)  cbuffer[i] = 'f'; 
		if(nbuffer[i] == 48)  cbuffer[i] = 'g'; 
		if(nbuffer[i] == 49)  cbuffer[i] = 'h'; 
		if(nbuffer[i] == 50)  cbuffer[i] = 'i'; 
		if(nbuffer[i] == 51)  cbuffer[i] = 'j'; 
		if(nbuffer[i] == 52)  cbuffer[i] = 'k'; 
		if(nbuffer[i] == 53)  cbuffer[i] = 'l'; 
		if(nbuffer[i] == 54)  cbuffer[i] = 'm'; 
		if(nbuffer[i] == 55)  cbuffer[i] = 'n'; 
		if(nbuffer[i] == 56)  cbuffer[i] = 'o'; 
		if(nbuffer[i] == 57)  cbuffer[i] = 'p'; 
		if(nbuffer[i] == 58)  cbuffer[i] = 'q'; 
		if(nbuffer[i] == 59)  cbuffer[i] = 'r'; 
		if(nbuffer[i] == 60)  cbuffer[i] = 's'; 
		if(nbuffer[i] == 61)  cbuffer[i] = 't'; 
		if(nbuffer[i] == 62)  cbuffer[i] = 'u'; 
		if(nbuffer[i] == 63)  cbuffer[i] = 'v'; 
		if(nbuffer[i] == 64)  cbuffer[i] = 'w'; 
		if(nbuffer[i] == 65)  cbuffer[i] = 'x'; 
		if(nbuffer[i] == 66)  cbuffer[i] = 'y'; 
		if(nbuffer[i] == 67)  cbuffer[i] = 'z'; 
		if(nbuffer[i] == 68)  cbuffer[i] = '0'; 
		if(nbuffer[i] == 69)  cbuffer[i] = '1'; 
		if(nbuffer[i] == 70)  cbuffer[i] = '2'; 
		if(nbuffer[i] == 71)  cbuffer[i] = '3'; 
		if(nbuffer[i] == 72)  cbuffer[i] = '4'; 
		if(nbuffer[i] == 73)  cbuffer[i] = '5'; 
		if(nbuffer[i] == 74)  cbuffer[i] = '6'; 
		if(nbuffer[i] == 75)  cbuffer[i] = '7'; 
		if(nbuffer[i] == 76)  cbuffer[i] = '8'; 
		if(nbuffer[i] == 77)  cbuffer[i] = '9'; 
		if(nbuffer[i] == 78)  cbuffer[i] = ' '; 
		if(nbuffer[i] == 79)  cbuffer[i] = '_'; 
		if(nbuffer[i] == 80)  cbuffer[i] = '('; 
		if(nbuffer[i] == 81)  cbuffer[i] = ')'; 
		if(nbuffer[i] == 82)  cbuffer[i] = '['; 
		if(nbuffer[i] == 83)  cbuffer[i] = ']'; 
		if(nbuffer[i] == 84)  cbuffer[i] = '{'; 
		if(nbuffer[i] == 85)  cbuffer[i] = '}'; 
		if(nbuffer[i] == 86)  cbuffer[i] = ','; 
		if(nbuffer[i] == 87)  cbuffer[i] = '\''; 
		if(nbuffer[i] == 88)  cbuffer[i] = '|'; 
		if(nbuffer[i] == 89)  cbuffer[i] = '+'; 
		if(nbuffer[i] == 90)  cbuffer[i] = '-'; 
		if(nbuffer[i] == 91)  cbuffer[i] = ':'; 
		if(nbuffer[i] == 92)  cbuffer[i] = '<'; 
		if(nbuffer[i] == 93)  cbuffer[i] = '>'; 
		if(nbuffer[i] == 94)  cbuffer[i] = '.'; 
		if(nbuffer[i] == 95)  cbuffer[i] = ';'; 
		if(nbuffer[i] == 96)  cbuffer[i] = '='; 
		if(nbuffer[i] == 97)  cbuffer[i] = '%'; 
		if(nbuffer[i] == 98)  cbuffer[i] = '~'; 
		if(nbuffer[i] == 99)  cbuffer[i] = '!'; 
		if(nbuffer[i] == 100)  cbuffer[i] = '@'; 
		if(nbuffer[i] == 101)  cbuffer[i] = '#'; 
		if(nbuffer[i] == 102)  cbuffer[i] = '$'; 
		if(nbuffer[i] == 103)  cbuffer[i] = '^'; 
		if(nbuffer[i] == 104)  cbuffer[i] = '&'; 
		if(nbuffer[i] == 105)  cbuffer[i] = '*'; 
		if(nbuffer[i] == 106)  cbuffer[i] = '`'; 
		if(nbuffer[i] == 107)  cbuffer[i] = '\\'; 
		if(nbuffer[i] == 108)  cbuffer[i] = '?'; 
	}

	for(int i = 0; i < 26; i++) {
		if(cbuffer[i] == ' ' && cbuffer[i+1] == ' ') {
			cbuffer[i] = '\0';
			return;
		}
	}
}

int controllerRumblePickMenu = 0;
int rumbleSlot = 0;
struct rumbleSetting { 
	bool isActive; 
	unsigned short address; 
	unsigned char bank; 
	int rumbleType; 
	unsigned char currentValue; 
	unsigned char previousValue; 
	std::string description; 
	int motorOneStrength; 
	int motorTwoStrength; 
	float motorOneTime; 
	float motorTwoTime; 
	int controller; 
	int rumbleCount;
	int rumbleTarget;
}; 
using namespace std;
extern vector<rumbleSetting> rumbleList; 





extern int screenResizeG;
extern int zLeftCO;
extern int zTopCO;
int controllerRumbleConfigMenu = 0;
int controllerType = 0;
extern int inGame;


extern int zLeftTO;
extern int zTopTO;

extern int zLeftCCO;
extern int zTopCCO;
extern int FontCenteredText(WCHAR *,int,int, int);
extern int screenResizeB;
extern int screenResizeA;
extern int screenResizeA2;
extern int screenResizeS;
extern int screenControllerOptions;
extern int screenCheatOptions;
extern XINPUT_STATE g_InputStates[4];
// Global instance of custom gamepad devices
extern XBGAMEPAD g_Gamepads[4];
extern int DisableMenuSounds;
extern void playEffect(int i);
extern  void writeConfig();
int controllerMode = 0;
int controllerMenu = 0;
int controllerTurboMenu;
int controllerTurboSelected = 0;
extern int vSpace;
int mouseDist = 1;
struct playerControl {
	int button_A      ;
	int button_B      ;
	int button_X      ;
	int button_Y      ;
	int button_Start  ;
	int button_Select ;
	int button_Left   ;
	int button_Right  ;
	int button_FastForward  ;
	int button_Rewind  ;
	int button_SaveState  ;
	int button_LoadState  ;
	int button_ShowFPS  ;
	int button_ExitGame  ;

};

playerControl controllers[4];

int controllerSelected  = 0;

extern "C" {
	extern unsigned char Turbo30hz;
}
struct ButtonSet {
	int SNES_Button_A;
	int SNES_Button_B ;
	int SNES_Button_X       ;
	int SNES_Button_Y       ;
	int SNES_Button_Select  ;
	int SNES_Button_Start   ;
	int SNES_Button_Left    ;
	int SNES_Button_Right   ;
	int Button_FastForward  ;
	int Button_Rewind       ;
	int Button_ShowFPS      ;
	int Button_SaveState    ;
	int Button_LoadState    ;
	int Button_ExitGame     ;
};

int turboControllerSelected = 0; 

struct Turbo { 
	int turboA ; 
	int turboB ; 
	int turboX ; 
	int turboY ; 
	int turboL ; 
	int turboR ; 
}; 

Turbo tButtons[4]; //write this to the ini 


int SlowTurbo = 0; //save this t the ini
ButtonSet B[4];
void controllerValueChanged(int controller);

int yO = 0;
int drawC_Count = 0;
extern int FontSetColour(unsigned int colour);
extern int FontText(WCHAR *,int,int, int);

extern void resetMotorOneRumbleTimer();
extern void resetMotorTwoRumbleTimer();
bool rumbleOneInProgress = false;
bool rumbleTwoInProgress = false;
extern float motorOneTime;
extern float motorTwoTime;
unsigned char leftRumble = 0;
unsigned char rightRumble = 0;
int rumbleController = 0;
extern bool MotorOneRumbleOver();
extern bool MotorTwoRumbleOver();


struct fileDisplay {
	string name;
	string path;
	bool isAGame;
	bool isARoot;
	bool isADirectory;
	bool topLevel;
	int soundTrack;
	int song;
	int archive;
};
extern vector<fileDisplay> fileList;
extern int FileMenuSelected;
//extern unsigned  char savePartition;

extern "C" {
	extern int cRumble;
}
extern void stopVibaration() ;
extern unsigned char getRumbleValue(unsigned short address, unsigned char bank);

void stopRumble() {
	rumbleOneInProgress = false;
	rumbleTwoInProgress = false;
	leftRumble = 0;
	rightRumble = 0;
	resetMotorOneRumbleTimer();
	resetMotorTwoRumbleTimer();
	stopVibaration() ;
	rumbleList[cRumble].currentValue = getRumbleValue(rumbleList[cRumble].address, rumbleList[cRumble].bank); 
	rumbleList[cRumble].previousValue = rumbleList[cRumble].currentValue;
	cRumble = 0;
	rumbleController = 0;
}

void SaveRumbleFile(std::string cSum) {
	rumbleOneInProgress = false;
	rumbleTwoInProgress = false;
	leftRumble = 0;
	rightRumble = 0;
	resetMotorOneRumbleTimer();
	resetMotorTwoRumbleTimer();


	FILE* f;
	std::string t = RUMBLE_PATH;
	std::string a = fileList[FileMenuSelected].name;//cSum
	a[a.size()-3] = 'r';
	a[a.size()-2] = 'm';
	a[a.size()-1] = 'b';
	t = t + a;
	f = fopen(t.c_str() , "w+");
	if(f) {

		for(int i = 0; i < 10; i++) {

			fprintf(f, "%d\n", (int)rumbleList[i].isActive);
			fprintf(f, "%d\n", rumbleList[i].address);
			fprintf(f, "%c\n", rumbleList[i].bank);
			fprintf(f, "%d\n", rumbleList[i].rumbleType);
			fprintf(f, "%s\n", rumbleList[i].description.c_str());
			fprintf(f, "%d\n", rumbleList[i].motorOneStrength);
			fprintf(f, "%d\n", rumbleList[i].motorTwoStrength);
			fprintf(f, "%f\n", rumbleList[i].motorOneTime);
			fprintf(f, "%f\n", rumbleList[i].motorTwoTime);
			fprintf(f, "%d\n", rumbleList[i].controller);
			fprintf(f, "%d\n", rumbleList[i].rumbleTarget);
		}
		fclose(f);
	}
}

void LoadRumbleFile(std::string cSum) {
	rumbleList.clear(); 
	for(int i = 0; i < 10; i++) { 
		rumbleSetting r; 
		r.isActive = false; 
		r.address = 0; 
		r.bank = 0; 
		r.rumbleType = 0; 
		r.currentValue = 0; 
		r.previousValue = 0; 
		r.description = "No Description Found" ;
		r.motorOneStrength = 0; 
		r.motorTwoStrength = 0; 
		r.motorOneTime = 0; 
		r.motorTwoTime = 0; 
		r.controller = 0; 
		r.rumbleCount = 0; 
		r.rumbleTarget = 0;
		rumbleList.push_back(r); 
	} 
	rumbleOneInProgress = false;
	rumbleTwoInProgress = false;
	leftRumble = 0;
	rightRumble = 0;
	resetMotorOneRumbleTimer();
	resetMotorTwoRumbleTimer();

	FILE* f;
	std::string t = RUMBLE_PATH;
	std::string a = fileList[FileMenuSelected].name;//cSum



	a[a.size()-3] = 'r';
	a[a.size()-2] = 'm';
	a[a.size()-1] = 'b';
	t = t + a;
	f = fopen(t.c_str() , "r");
	if(!f) {
		SaveRumbleFile(cSum);
		return;
	}

	for(int i = 0; i < 10; i++) {
		char a[100]; for(int t = 0; t < 100; t++) a[t] = '\0'; fgets(a, 100, f);
		rumbleList[i].isActive = (bool)atoi(a);

		char b[100]; for(int t = 0; t < 100; t++) b[t] = '\0'; fgets(b, 100, f);
		rumbleList[i].address  = (unsigned short) atoi(b);

		char c[100]; for(int t = 0; t < 100; t++) c[t] = '\0'; fgets(c, 100, f);
		rumbleList[i].bank = (unsigned char)atoi(c);

		char d[100]; for(int t = 0; t < 100; t++) d[t] = '\0'; fgets(d, 100, f);
		rumbleList[i].rumbleType  = atoi(d);

		char e[100];
		for(int t = 0; t < 100; t++) e[t] = '\0';
		fgets(e, 100, f);
		for(int q = 0; q < 100; q++) 
			if(e[q] == '\n') e[q] = '\0';
		rumbleList[i].description = e;

		char g[100]; for(int t = 0; t < 100; t++) g[t] = '\0'; fgets(g, 100, f);
		rumbleList[i].motorOneStrength  = atoi(g);

		char h[100]; for(int t = 0; t < 100; t++) h[t] = '\0'; fgets(h, 100, f);
		rumbleList[i].motorTwoStrength  = atoi(h);

		char j[100]; for(int t = 0; t < 100; t++) j[t] = '\0'; fgets(j, 100, f);
		rumbleList[i].motorOneTime  = (float) atof(j);

		char k[100]; for(int t = 0; t < 100; t++) k[t] = '\0'; fgets(k, 100, f);
		rumbleList[i].motorTwoTime  = (float) atof(k);

		char m[100]; for(int t = 0; t < 100; t++) m[t] = '\0'; fgets(m, 100, f);
		rumbleList[i].controller  = atoi(m);

		char m3[100]; for(int t = 0; t < 100; t++) m3[t] = '\0'; fgets(m3, 100, f);
		rumbleList[i].rumbleTarget  = atoi(m3);
	}
	fclose(f);
}






void StartRumble(int slot) {
	if(rumbleOneInProgress || rumbleTwoInProgress) return;

	//rumbleList[controllerRumbleMenu].
	//int motorOneStrength; 
	//int motorTwoStrength; 
	//float motorOneTime; 
	//float motorTwoTime; 

	resetMotorOneRumbleTimer();
	resetMotorTwoRumbleTimer();
	rumbleOneInProgress = true;
	rumbleTwoInProgress = true;

	motorOneTime = rumbleList[slot].motorOneTime;
	motorTwoTime = rumbleList[slot].motorTwoTime;
	rumbleController = rumbleList[slot].controller;
	leftRumble = (unsigned char)rumbleList[slot].motorOneStrength;
	rightRumble = (unsigned char)rumbleList[slot].motorTwoStrength;
}

void ProcessRumble() {
	if(MotorOneRumbleOver() && rumbleOneInProgress) {
		rumbleOneInProgress = false;
		leftRumble = 0;

	}
	if(MotorTwoRumbleOver() && rumbleTwoInProgress) {
		rumbleTwoInProgress = false;
		rightRumble = 0;
	}
}












//*************************************************************************
//DRAW

extern int FontSmallText(WCHAR *,int,int, int);
extern int sWidth;
extern int sHeight;
int controllerConfigSelected = 0; //menu item
void drawCDText(char* text) {
	DWORD color = menuColor[MenuOption];

	// WCHAR text2345678_[80]={0};
	// wsprintfW(text2345678_,  L"Option Selected: %d, ShowFPS: %d", controllerConfigSelected, B[0].Button_ShowFPS);
	// FontSetColour(0xffff00);
	// FontText(text2345678_,50,300, 600);



	if(controllerMode == 1 && drawC_Count == controllerTurboMenu) color = menuColor[MenuOptionSelected];
	if(controllerMode == 2 && drawC_Count == controllerConfigSelected) color = menuColor[MenuOptionSelected]; 

	//Draw the text string
	WCHAR text23456789[80]={0};
	//wsprintfW(text2345678_, (LPCWSTR)text);

	for(int i = 0; i < 1000; i++) {
		if(text[i] == '\0') {
			text23456789[i] = '\0';
			break;
		}
		text23456789[i] = text[i];
	}
	FontSetColour(color);
	if(controllerMode == 1)
		FontText(text23456789,390,yO, 600);
	else
		FontText(text23456789,355+zLeftCCO,yO+zTopCCO, 600);
	yO += vSpace;
	drawC_Count++;
}

void drawCText(char* text) {
	DWORD color  = menuColor[MenuOption];

	// WCHAR text2345678_[80]={0};
	// wsprintfW(text2345678_,  L"Option Selected: %d, ShowFPS: %d", controllerConfigSelected, B[0].Button_ShowFPS);
	// FontSetColour(0xffff00);
	// FontText(text2345678_,50,300, 600);


	if(controllerMode == 1 && drawC_Count == controllerTurboMenu) color  = menuColor[MenuOptionSelected];
	if(controllerMode == 2 && drawC_Count == controllerConfigSelected) color  = menuColor[MenuOptionSelected]; 

	//Draw the text string
	WCHAR text23456789[80]={0};
	//wsprintfW(text2345678_, (LPCWSTR)text);

	for(int i = 0; i < 1000; i++) {
		if(text[i] == '\0') {
			text23456789[i] = '\0';
			break;
		}
		text23456789[i] = text[i];
	}
	FontSetColour(color);
	if(controllerMode == 1)
		FontText(text23456789,150,yO, 600);
	else
		FontText(text23456789,155+zLeftCCO,yO+zTopCCO, 600);
	//yO += 20;
	//drawC_Count++;
}

void drawTCDText(char* text) {
	DWORD color = menuColor[MenuOption];

	// WCHAR text2345678_[80]={0};
	// wsprintfW(text2345678_,  L"Option Selected: %d, ShowFPS: %d", controllerConfigSelected, B[0].Button_ShowFPS);
	// FontSetColour(0xffff00);
	// FontText(text2345678_,50,300, 600);



	if(controllerMode == 1 && drawC_Count == controllerTurboMenu) color = menuColor[MenuOptionSelected];
	if(controllerMode == 2 && drawC_Count == controllerConfigSelected) color = menuColor[MenuOptionSelected]; 

	//Draw the text string
	WCHAR text23456789[80]={0};
	//wsprintfW(text2345678_, (LPCWSTR)text);

	for(int i = 0; i < 1000; i++) {
		if(text[i] == '\0') {
			text23456789[i] = '\0';
			break;
		}
		text23456789[i] = text[i];
	}
	FontSetColour(color);
	if(controllerMode == 1)
		FontText(text23456789,390+zLeftTO,yO+zTopTO, 600);
	else
		FontText(text23456789,355,yO, 600);
	yO += vSpace;
	drawC_Count++;
}

void drawTCText(char* text) {
	DWORD color  = menuColor[MenuOption];

	// WCHAR text2345678_[80]={0};
	// wsprintfW(text2345678_,  L"Option Selected: %d, ShowFPS: %d", controllerConfigSelected, B[0].Button_ShowFPS);
	// FontSetColour(0xffff00);
	// FontText(text2345678_,50,300, 600);


	if(controllerMode == 1 && drawC_Count == controllerTurboMenu) color  = menuColor[MenuOptionSelected];
	if(controllerMode == 2 && drawC_Count == controllerConfigSelected) color  = menuColor[MenuOptionSelected]; 

	//Draw the text string
	WCHAR text23456789[80]={0};
	//wsprintfW(text2345678_, (LPCWSTR)text);

	for(int i = 0; i < 1000; i++) {
		if(text[i] == '\0') {
			text23456789[i] = '\0';
			break;
		}
		text23456789[i] = text[i];
	}
	FontSetColour(color);
	if(controllerMode == 1)
		FontText(text23456789,150+zLeftTO,yO+zTopTO, 600);
	else
		FontText(text23456789,155,yO, 600);
	//yO += 20;
	//drawC_Count++;
}

void drawTCRText(char* text) {
	DWORD color  = 0;
	if(controllerRumbleMenu == rumbleSlotCount) color = menuColor[MenuOptionSelected]; else color = menuColor[MenuOption];
	WCHAR text23456789[80]={0};

	for(int i = 0; i < 1000; i++) {
		if(text[i] == '\0') {
			text23456789[i] = '\0';
			break;
		}
		text23456789[i] = text[i];
	}
	FontSetColour(color);
	FontSmallText(text23456789,155+zLeftRM,yO+zTopRM, 600);
	yO += vSpace;
	rumbleSlotCount++;
}


void drawTCRDTextR(char* text) {
	DWORD color  = 0;
	if(rumbleSlotCount == controllerRumbleConfigMenu) color = menuColor[MenuOptionSelected]; else color = menuColor[MenuOption];
	WCHAR text23456789[80]={0};
	for(int i = 0; i < 1000; i++) {
		if(text[i] == '\0') {
			text23456789[i] = '\0';
			break;
		}
		text23456789[i] = text[i];
	}
	FontSetColour(color);
	FontText(text23456789,375+zLeftRM,yO+zTopRM, 600);
	yO += vSpace;
	rumbleSlotCount++;
}

void drawTCRTextR(char* text) {
	DWORD color  = 0;
	if(rumbleSlotCount == controllerRumbleConfigMenu) color = menuColor[MenuOptionSelected]; else color = menuColor[MenuOption];
	WCHAR text23456789[80]={0};

	for(int i = 0; i < 1000; i++) {
		if(text[i] == '\0') {
			text23456789[i] = '\0';
			break;
		}
		text23456789[i] = text[i];
	}
	FontSetColour(color);
	FontText(text23456789,155+zLeftRM,yO+zTopRM, 600);
}



















void drawTCRTextRP(char* text) {
	DWORD color  = 0;
	color = menuColor[MenuOptionSelected]; 
	WCHAR text23456789[80]={0};

	for(int i = 0; i < 1000; i++) {
		if(text[i] == '\0') {
			text23456789[i] = '\0';
			break;
		}
		text23456789[i] = text[i];
	}
	FontSetColour(color);
	FontSmallText(text23456789,155+zLeftRM,yO+zTopRM, 600);
	yO += vSpace;
	rumbleSlotCount++;
}

void initControllers() {
	for(int i = 0; i < 4; i++) {
		B[i].SNES_Button_A = 1;
		B[i].SNES_Button_B = 0;
		B[i].SNES_Button_X  = 3;
		B[i].SNES_Button_Y  = 2      ;
		B[i].SNES_Button_Select = 4  ;
		B[i].SNES_Button_Start  = 5  ;
		B[i].SNES_Button_Left  = 8   ;
		B[i].SNES_Button_Right  = 9  ;
		B[i].Button_FastForward  = 6 ;
		B[i].Button_Rewind    = 10    ;
		B[i].Button_ShowFPS    = 7  ;
		B[i].Button_SaveState   = -1  ;
		B[i].Button_LoadState   = -1  ;
		B[i].Button_ExitGame     = 11 ;

		tButtons[i].turboA = 0;
		tButtons[i].turboB = 0;
		tButtons[i].turboX = 0;
		tButtons[i].turboY = 0;
		tButtons[i].turboL = 0;
		tButtons[i].turboR = 0;
	}


	for(int i = 0; i < 4; i++) {
		controllers[i].button_A      = XINPUT_GAMEPAD_B;
		controllers[i].button_B      = XINPUT_GAMEPAD_A;
		controllers[i].button_X      = XINPUT_GAMEPAD_Y;
		controllers[i].button_Y      = XINPUT_GAMEPAD_X;
		controllers[i].button_Left   = XINPUT_GAMEPAD_LEFT_TRIGGER;
		controllers[i].button_Right  = XINPUT_GAMEPAD_RIGHT_TRIGGER;

		controllers[i].button_Select = XINPUT_GAMEPAD_BACK;
		controllers[i].button_Start  = XINPUT_GAMEPAD_START;

		controllers[i].button_FastForward = XINPUT_GAMEPAD_WHITE;
		controllers[i].button_Rewind = XINPUT_GAMEPAD_LEFT_THUMB;
		controllers[i].button_LoadState = -1;
		controllers[i].button_SaveState = -1;
		controllers[i].button_ExitGame = XINPUT_GAMEPAD_RIGHT_THUMB;
		controllers[i].button_ShowFPS = XBGAMEPAD_BLACK;
	}


	controllerSelected  = 0;


	//controllerValueChanged(0);
	//controllerValueChanged(1);
	//controllerValueChanged(2);
	//controllerValueChanged(3);
}

void setA(int controller) {
	B[controller].SNES_Button_A = -1;
	if(controllers[controller].button_A == XINPUT_GAMEPAD_A)				B[controller].SNES_Button_A = 0;
	if(controllers[controller].button_A == XINPUT_GAMEPAD_B)				B[controller].SNES_Button_A = 1;
	if(controllers[controller].button_A == XINPUT_GAMEPAD_X)				B[controller].SNES_Button_A = 2;
	if(controllers[controller].button_A == XINPUT_GAMEPAD_Y)				B[controller].SNES_Button_A = 3;
	if(controllers[controller].button_A == XINPUT_GAMEPAD_BACK)				B[controller].SNES_Button_A = 4;
	if(controllers[controller].button_A == XINPUT_GAMEPAD_START)			B[controller].SNES_Button_A = 5;
	if(controllers[controller].button_A == XINPUT_GAMEPAD_WHITE)			B[controller].SNES_Button_A = 6;
	if(controllers[controller].button_A == XINPUT_GAMEPAD_BLACK)			B[controller].SNES_Button_A = 7;
	if(controllers[controller].button_A == XINPUT_GAMEPAD_LEFT_TRIGGER)		B[controller].SNES_Button_A = 8;
	if(controllers[controller].button_A == XINPUT_GAMEPAD_RIGHT_TRIGGER)		B[controller].SNES_Button_A = 9;
	if(controllers[controller].button_A == XINPUT_GAMEPAD_LEFT_THUMB)		B[controller].SNES_Button_A = 10;
	if(controllers[controller].button_A == XINPUT_GAMEPAD_RIGHT_THUMB)		B[controller].SNES_Button_A = 11;


	B[controller].SNES_Button_B = -1;
	if(controllers[controller].button_B == XINPUT_GAMEPAD_A)				B[controller].SNES_Button_B = 0;
	if(controllers[controller].button_B == XINPUT_GAMEPAD_B)				B[controller].SNES_Button_B = 1;
	if(controllers[controller].button_B == XINPUT_GAMEPAD_X)				B[controller].SNES_Button_B = 2;
	if(controllers[controller].button_B == XINPUT_GAMEPAD_Y)				B[controller].SNES_Button_B = 3;
	if(controllers[controller].button_B == XINPUT_GAMEPAD_BACK)				B[controller].SNES_Button_B = 4;
	if(controllers[controller].button_B == XINPUT_GAMEPAD_START)			B[controller].SNES_Button_B = 5;
	if(controllers[controller].button_B == XINPUT_GAMEPAD_WHITE)			B[controller].SNES_Button_B = 6;
	if(controllers[controller].button_B == XINPUT_GAMEPAD_BLACK)			B[controller].SNES_Button_B = 7;
	if(controllers[controller].button_B == XINPUT_GAMEPAD_LEFT_TRIGGER)		B[controller].SNES_Button_B = 8;
	if(controllers[controller].button_B == XINPUT_GAMEPAD_RIGHT_TRIGGER)		B[controller].SNES_Button_B = 9;
	if(controllers[controller].button_B == XINPUT_GAMEPAD_LEFT_THUMB)		B[controller].SNES_Button_B = 10;
	if(controllers[controller].button_B == XINPUT_GAMEPAD_RIGHT_THUMB)		B[controller].SNES_Button_B = 11;

	B[controller].SNES_Button_X = -1;
	if(controllers[controller].button_X == XINPUT_GAMEPAD_A)				B[controller].SNES_Button_X = 0;
	if(controllers[controller].button_X == XINPUT_GAMEPAD_B)				B[controller].SNES_Button_X = 1;
	if(controllers[controller].button_X == XINPUT_GAMEPAD_X)				B[controller].SNES_Button_X = 2;
	if(controllers[controller].button_X == XINPUT_GAMEPAD_Y)				B[controller].SNES_Button_X = 3;
	if(controllers[controller].button_X == XINPUT_GAMEPAD_BACK)				B[controller].SNES_Button_X = 4;
	if(controllers[controller].button_X == XINPUT_GAMEPAD_START)			B[controller].SNES_Button_X = 5;
	if(controllers[controller].button_X == XINPUT_GAMEPAD_WHITE)			B[controller].SNES_Button_X = 6;
	if(controllers[controller].button_X == XINPUT_GAMEPAD_BLACK)			B[controller].SNES_Button_X = 7;
	if(controllers[controller].button_X == XINPUT_GAMEPAD_LEFT_TRIGGER)		B[controller].SNES_Button_X = 8;
	if(controllers[controller].button_X == XINPUT_GAMEPAD_RIGHT_TRIGGER)		B[controller].SNES_Button_X = 9;
	if(controllers[controller].button_X == XINPUT_GAMEPAD_LEFT_THUMB)		B[controller].SNES_Button_X = 10;
	if(controllers[controller].button_X == XINPUT_GAMEPAD_RIGHT_THUMB)		B[controller].SNES_Button_X = 11;

	B[controller].SNES_Button_Y = -1;
	if(controllers[controller].button_Y == XINPUT_GAMEPAD_A)				B[controller].SNES_Button_Y = 0;
	if(controllers[controller].button_Y == XINPUT_GAMEPAD_B)				B[controller].SNES_Button_Y = 1;
	if(controllers[controller].button_Y == XINPUT_GAMEPAD_X)				B[controller].SNES_Button_Y = 2;
	if(controllers[controller].button_Y == XINPUT_GAMEPAD_Y)				B[controller].SNES_Button_Y = 3;
	if(controllers[controller].button_Y == XINPUT_GAMEPAD_BACK)				B[controller].SNES_Button_Y = 4;
	if(controllers[controller].button_Y == XINPUT_GAMEPAD_START)			B[controller].SNES_Button_Y = 5;
	if(controllers[controller].button_Y == XINPUT_GAMEPAD_WHITE)			B[controller].SNES_Button_Y = 6;
	if(controllers[controller].button_Y == XINPUT_GAMEPAD_BLACK)			B[controller].SNES_Button_Y = 7;
	if(controllers[controller].button_Y == XINPUT_GAMEPAD_LEFT_TRIGGER)		B[controller].SNES_Button_Y = 8;
	if(controllers[controller].button_Y == XINPUT_GAMEPAD_RIGHT_TRIGGER)		B[controller].SNES_Button_Y = 9;
	if(controllers[controller].button_Y == XINPUT_GAMEPAD_LEFT_THUMB)		B[controller].SNES_Button_Y = 10;
	if(controllers[controller].button_Y == XINPUT_GAMEPAD_RIGHT_THUMB)		B[controller].SNES_Button_Y = 11;

	B[controller].SNES_Button_Start = -1;
	if(controllers[controller].button_Start == XINPUT_GAMEPAD_A)				B[controller].SNES_Button_Start = 0;
	if(controllers[controller].button_Start == XINPUT_GAMEPAD_B)				B[controller].SNES_Button_Start = 1;
	if(controllers[controller].button_Start == XINPUT_GAMEPAD_X)				B[controller].SNES_Button_Start = 2;
	if(controllers[controller].button_Start == XINPUT_GAMEPAD_Y)				B[controller].SNES_Button_Start = 3;
	if(controllers[controller].button_Start == XINPUT_GAMEPAD_BACK)				B[controller].SNES_Button_Start = 4;
	if(controllers[controller].button_Start == XINPUT_GAMEPAD_START)			B[controller].SNES_Button_Start = 5;
	if(controllers[controller].button_Start == XINPUT_GAMEPAD_WHITE)			B[controller].SNES_Button_Start = 6;
	if(controllers[controller].button_Start == XINPUT_GAMEPAD_BLACK)			B[controller].SNES_Button_Start = 7;
	if(controllers[controller].button_Start == XINPUT_GAMEPAD_LEFT_TRIGGER)		B[controller].SNES_Button_Start = 8;
	if(controllers[controller].button_Start == XINPUT_GAMEPAD_RIGHT_TRIGGER)		B[controller].SNES_Button_Start = 9;
	if(controllers[controller].button_Start == XINPUT_GAMEPAD_LEFT_THUMB)		B[controller].SNES_Button_Start = 10;
	if(controllers[controller].button_Start == XINPUT_GAMEPAD_RIGHT_THUMB)		B[controller].SNES_Button_Start = 11;

	B[controller].SNES_Button_Select = -1;
	if(controllers[controller].button_Select == XINPUT_GAMEPAD_A)				B[controller].SNES_Button_Select = 0;
	if(controllers[controller].button_Select == XINPUT_GAMEPAD_B)				B[controller].SNES_Button_Select = 1;
	if(controllers[controller].button_Select == XINPUT_GAMEPAD_X)				B[controller].SNES_Button_Select = 2;
	if(controllers[controller].button_Select == XINPUT_GAMEPAD_Y)				B[controller].SNES_Button_Select = 3;
	if(controllers[controller].button_Select == XINPUT_GAMEPAD_BACK)				B[controller].SNES_Button_Select = 4;
	if(controllers[controller].button_Select == XINPUT_GAMEPAD_START)			B[controller].SNES_Button_Select = 5;
	if(controllers[controller].button_Select == XINPUT_GAMEPAD_WHITE)			B[controller].SNES_Button_Select = 6;
	if(controllers[controller].button_Select == XINPUT_GAMEPAD_BLACK)			B[controller].SNES_Button_Select = 7;
	if(controllers[controller].button_Select == XINPUT_GAMEPAD_LEFT_TRIGGER)		B[controller].SNES_Button_Select = 8;
	if(controllers[controller].button_Select == XINPUT_GAMEPAD_RIGHT_TRIGGER)		B[controller].SNES_Button_Select = 9;
	if(controllers[controller].button_Select == XINPUT_GAMEPAD_LEFT_THUMB)		B[controller].SNES_Button_Select = 10;
	if(controllers[controller].button_Select == XINPUT_GAMEPAD_RIGHT_THUMB)		B[controller].SNES_Button_Select = 11;

	B[controller].SNES_Button_Left = -1;
	if(controllers[controller].button_Left == XINPUT_GAMEPAD_A)				B[controller].SNES_Button_Left = 0;
	if(controllers[controller].button_Left == XINPUT_GAMEPAD_B)				B[controller].SNES_Button_Left = 1;
	if(controllers[controller].button_Left == XINPUT_GAMEPAD_X)				B[controller].SNES_Button_Left = 2;
	if(controllers[controller].button_Left == XINPUT_GAMEPAD_Y)				B[controller].SNES_Button_Left = 3;
	if(controllers[controller].button_Left == XINPUT_GAMEPAD_BACK)				B[controller].SNES_Button_Left = 4;
	if(controllers[controller].button_Left == XINPUT_GAMEPAD_START)			B[controller].SNES_Button_Left = 5;
	if(controllers[controller].button_Left == XINPUT_GAMEPAD_WHITE)			B[controller].SNES_Button_Left = 6;
	if(controllers[controller].button_Left == XINPUT_GAMEPAD_BLACK)			B[controller].SNES_Button_Left = 7;
	if(controllers[controller].button_Left == XINPUT_GAMEPAD_LEFT_TRIGGER)		B[controller].SNES_Button_Left = 8;
	if(controllers[controller].button_Left == XINPUT_GAMEPAD_RIGHT_TRIGGER)		B[controller].SNES_Button_Left = 9;
	if(controllers[controller].button_Left == XINPUT_GAMEPAD_LEFT_THUMB)		B[controller].SNES_Button_Left = 10;
	if(controllers[controller].button_Left == XINPUT_GAMEPAD_RIGHT_THUMB)		B[controller].SNES_Button_Left = 11;

	B[controller].SNES_Button_Right = -1;
	if(controllers[controller].button_Right == XINPUT_GAMEPAD_A)				B[controller].SNES_Button_Right = 0;
	if(controllers[controller].button_Right == XINPUT_GAMEPAD_B)				B[controller].SNES_Button_Right = 1;
	if(controllers[controller].button_Right == XINPUT_GAMEPAD_X)				B[controller].SNES_Button_Right = 2;
	if(controllers[controller].button_Right == XINPUT_GAMEPAD_Y)				B[controller].SNES_Button_Right = 3;
	if(controllers[controller].button_Right == XINPUT_GAMEPAD_BACK)				B[controller].SNES_Button_Right = 4;
	if(controllers[controller].button_Right == XINPUT_GAMEPAD_START)			B[controller].SNES_Button_Right = 5;
	if(controllers[controller].button_Right == XINPUT_GAMEPAD_WHITE)			B[controller].SNES_Button_Right = 6;
	if(controllers[controller].button_Right == XINPUT_GAMEPAD_BLACK)			B[controller].SNES_Button_Right = 7;
	if(controllers[controller].button_Right == XINPUT_GAMEPAD_LEFT_TRIGGER)		B[controller].SNES_Button_Right = 8;
	if(controllers[controller].button_Right == XINPUT_GAMEPAD_RIGHT_TRIGGER)		B[controller].SNES_Button_Right = 9;
	if(controllers[controller].button_Right == XINPUT_GAMEPAD_LEFT_THUMB)		B[controller].SNES_Button_Right = 10;
	if(controllers[controller].button_Right == XINPUT_GAMEPAD_RIGHT_THUMB)		B[controller].SNES_Button_Right = 11;

	B[controller].Button_FastForward = -1;
	if(controllers[controller].button_FastForward == XINPUT_GAMEPAD_A)				B[controller].Button_FastForward = 0;
	if(controllers[controller].button_FastForward == XINPUT_GAMEPAD_B)				B[controller].Button_FastForward = 1;
	if(controllers[controller].button_FastForward == XINPUT_GAMEPAD_X)				B[controller].Button_FastForward = 2;
	if(controllers[controller].button_FastForward == XINPUT_GAMEPAD_Y)				B[controller].Button_FastForward = 3;
	if(controllers[controller].button_FastForward == XINPUT_GAMEPAD_BACK)			B[controller].Button_FastForward = 4;
	if(controllers[controller].button_FastForward == XINPUT_GAMEPAD_START)			B[controller].Button_FastForward = 5;
	if(controllers[controller].button_FastForward == XINPUT_GAMEPAD_WHITE)			B[controller].Button_FastForward = 6;
	if(controllers[controller].button_FastForward == XINPUT_GAMEPAD_BLACK)			B[controller].Button_FastForward = 7;
	if(controllers[controller].button_FastForward == XINPUT_GAMEPAD_LEFT_TRIGGER)	B[controller].Button_FastForward = 8;
	if(controllers[controller].button_FastForward == XINPUT_GAMEPAD_RIGHT_TRIGGER)	B[controller].Button_FastForward = 9;
	if(controllers[controller].button_FastForward == XINPUT_GAMEPAD_LEFT_THUMB)		B[controller].Button_FastForward = 10;
	if(controllers[controller].button_FastForward == XINPUT_GAMEPAD_RIGHT_THUMB)	B[controller].Button_FastForward = 11;

	B[controller].Button_Rewind = -1;
	if(controllers[controller].button_Rewind == XINPUT_GAMEPAD_A)				B[controller].Button_Rewind = 0;
	if(controllers[controller].button_Rewind == XINPUT_GAMEPAD_B)				B[controller].Button_Rewind = 1;
	if(controllers[controller].button_Rewind == XINPUT_GAMEPAD_X)				B[controller].Button_Rewind = 2;
	if(controllers[controller].button_Rewind == XINPUT_GAMEPAD_Y)				B[controller].Button_Rewind = 3;
	if(controllers[controller].button_Rewind == XINPUT_GAMEPAD_BACK)			B[controller].Button_Rewind = 4;
	if(controllers[controller].button_Rewind == XINPUT_GAMEPAD_START)			B[controller].Button_Rewind = 5;
	if(controllers[controller].button_Rewind == XINPUT_GAMEPAD_WHITE)			B[controller].Button_Rewind = 6;
	if(controllers[controller].button_Rewind == XINPUT_GAMEPAD_BLACK)			B[controller].Button_Rewind = 7;
	if(controllers[controller].button_Rewind == XINPUT_GAMEPAD_LEFT_TRIGGER)	B[controller].Button_Rewind = 8;
	if(controllers[controller].button_Rewind == XINPUT_GAMEPAD_RIGHT_TRIGGER)	B[controller].Button_Rewind = 9;
	if(controllers[controller].button_Rewind == XINPUT_GAMEPAD_LEFT_THUMB)		B[controller].Button_Rewind = 10;
	if(controllers[controller].button_Rewind == XINPUT_GAMEPAD_RIGHT_THUMB)	B[controller].Button_Rewind = 11;

	B[controller].Button_SaveState = -1;
	if(controllers[controller].button_SaveState == XINPUT_GAMEPAD_A)				B[controller].Button_SaveState = 0;
	if(controllers[controller].button_SaveState == XINPUT_GAMEPAD_B)				B[controller].Button_SaveState = 1;
	if(controllers[controller].button_SaveState == XINPUT_GAMEPAD_X)				B[controller].Button_SaveState = 2;
	if(controllers[controller].button_SaveState == XINPUT_GAMEPAD_Y)				B[controller].Button_SaveState = 3;
	if(controllers[controller].button_SaveState == XINPUT_GAMEPAD_BACK)			B[controller].Button_SaveState = 4;
	if(controllers[controller].button_SaveState == XINPUT_GAMEPAD_START)			B[controller].Button_SaveState = 5;
	if(controllers[controller].button_SaveState == XINPUT_GAMEPAD_WHITE)			B[controller].Button_SaveState = 6;
	if(controllers[controller].button_SaveState == XINPUT_GAMEPAD_BLACK)			B[controller].Button_SaveState = 7;
	if(controllers[controller].button_SaveState == XINPUT_GAMEPAD_LEFT_TRIGGER)	B[controller].Button_SaveState = 8;
	if(controllers[controller].button_SaveState == XINPUT_GAMEPAD_RIGHT_TRIGGER)	B[controller].Button_SaveState = 9;
	if(controllers[controller].button_SaveState == XINPUT_GAMEPAD_LEFT_THUMB)		B[controller].Button_SaveState = 10;
	if(controllers[controller].button_SaveState == XINPUT_GAMEPAD_RIGHT_THUMB)	B[controller].Button_SaveState = 11;

	B[controller].Button_LoadState = -1;
	if(controllers[controller].button_LoadState == XINPUT_GAMEPAD_A)				B[controller].Button_LoadState = 0;
	if(controllers[controller].button_LoadState == XINPUT_GAMEPAD_B)				B[controller].Button_LoadState = 1;
	if(controllers[controller].button_LoadState == XINPUT_GAMEPAD_X)				B[controller].Button_LoadState = 2;
	if(controllers[controller].button_LoadState == XINPUT_GAMEPAD_Y)				B[controller].Button_LoadState = 3;
	if(controllers[controller].button_LoadState == XINPUT_GAMEPAD_BACK)			B[controller].Button_LoadState = 4;
	if(controllers[controller].button_LoadState == XINPUT_GAMEPAD_START)			B[controller].Button_LoadState = 5;
	if(controllers[controller].button_LoadState == XINPUT_GAMEPAD_WHITE)			B[controller].Button_LoadState = 6;
	if(controllers[controller].button_LoadState == XINPUT_GAMEPAD_BLACK)			B[controller].Button_LoadState = 7;
	if(controllers[controller].button_LoadState == XINPUT_GAMEPAD_LEFT_TRIGGER)	B[controller].Button_LoadState = 8;
	if(controllers[controller].button_LoadState == XINPUT_GAMEPAD_RIGHT_TRIGGER)	B[controller].Button_LoadState = 9;
	if(controllers[controller].button_LoadState == XINPUT_GAMEPAD_LEFT_THUMB)		B[controller].Button_LoadState = 10;
	if(controllers[controller].button_LoadState == XINPUT_GAMEPAD_RIGHT_THUMB)	B[controller].Button_LoadState = 11;

	B[controller].Button_ExitGame = -1;
	if(controllers[controller].button_ExitGame == XINPUT_GAMEPAD_A)				B[controller].Button_ExitGame = 0;
	if(controllers[controller].button_ExitGame == XINPUT_GAMEPAD_B)				B[controller].Button_ExitGame = 1;
	if(controllers[controller].button_ExitGame == XINPUT_GAMEPAD_X)				B[controller].Button_ExitGame = 2;
	if(controllers[controller].button_ExitGame == XINPUT_GAMEPAD_Y)				B[controller].Button_ExitGame = 3;
	if(controllers[controller].button_ExitGame == XINPUT_GAMEPAD_BACK)			B[controller].Button_ExitGame = 4;
	if(controllers[controller].button_ExitGame == XINPUT_GAMEPAD_START)			B[controller].Button_ExitGame = 5;
	if(controllers[controller].button_ExitGame == XINPUT_GAMEPAD_WHITE)			B[controller].Button_ExitGame = 6;
	if(controllers[controller].button_ExitGame == XINPUT_GAMEPAD_BLACK)			B[controller].Button_ExitGame = 7;
	if(controllers[controller].button_ExitGame == XINPUT_GAMEPAD_LEFT_TRIGGER)	B[controller].Button_ExitGame = 8;
	if(controllers[controller].button_ExitGame == XINPUT_GAMEPAD_RIGHT_TRIGGER)	B[controller].Button_ExitGame = 9;
	if(controllers[controller].button_ExitGame == XINPUT_GAMEPAD_LEFT_THUMB)		B[controller].Button_ExitGame = 10;
	if(controllers[controller].button_ExitGame == XINPUT_GAMEPAD_RIGHT_THUMB)	B[controller].Button_ExitGame = 11;

	B[controller].Button_ShowFPS = -1;
	if(controllers[controller].button_ShowFPS == XBGAMEPAD_A)				B[controller].Button_ShowFPS = 0;
	if(controllers[controller].button_ShowFPS == XBGAMEPAD_B)				B[controller].Button_ShowFPS = 1;
	if(controllers[controller].button_ShowFPS == XBGAMEPAD_X)				B[controller].Button_ShowFPS = 2;
	if(controllers[controller].button_ShowFPS == XBGAMEPAD_Y)				B[controller].Button_ShowFPS = 3;
	if(controllers[controller].button_ShowFPS == XBGAMEPAD_BACK)			B[controller].Button_ShowFPS = 4;
	if(controllers[controller].button_ShowFPS == XBGAMEPAD_START)			B[controller].Button_ShowFPS = 5;
	if(controllers[controller].button_ShowFPS == XBGAMEPAD_WHITE)			B[controller].Button_ShowFPS = 6;
	if(controllers[controller].button_ShowFPS == XBGAMEPAD_BLACK)			B[controller].Button_ShowFPS = 7;
	if(controllers[controller].button_ShowFPS == XBGAMEPAD_LEFT_TRIGGER)	B[controller].Button_ShowFPS = 8;
	if(controllers[controller].button_ShowFPS ==  XBGAMEPAD_RIGHT_TRIGGER)	B[controller].Button_ShowFPS = 9;
	if(controllers[controller].button_ShowFPS == XINPUT_GAMEPAD_LEFT_THUMB)		B[controller].Button_ShowFPS = 10;
	if(controllers[controller].button_ShowFPS == XINPUT_GAMEPAD_RIGHT_THUMB)	B[controller].Button_ShowFPS = 11;
}



void controllerValueChanged(int controller) {
	controllers[controller].button_A =  B[controller].SNES_Button_A;
	if(B[controller].SNES_Button_A == 0) controllers[controller].button_A = XINPUT_GAMEPAD_A;
	if(B[controller].SNES_Button_A == 1) controllers[controller].button_A = XINPUT_GAMEPAD_B;
	if(B[controller].SNES_Button_A == 2) controllers[controller].button_A = XINPUT_GAMEPAD_X;
	if(B[controller].SNES_Button_A == 3) controllers[controller].button_A = XINPUT_GAMEPAD_Y;
	if(B[controller].SNES_Button_A == 4) controllers[controller].button_A = XINPUT_GAMEPAD_BACK;
	if(B[controller].SNES_Button_A == 5) controllers[controller].button_A = XINPUT_GAMEPAD_START;
	if(B[controller].SNES_Button_A == 6) controllers[controller].button_A = XINPUT_GAMEPAD_WHITE;
	if(B[controller].SNES_Button_A == 7) controllers[controller].button_A = XINPUT_GAMEPAD_BLACK;
	if(B[controller].SNES_Button_A == 8) controllers[controller].button_A = XINPUT_GAMEPAD_LEFT_TRIGGER;
	if(B[controller].SNES_Button_A == 9) controllers[controller].button_A = XINPUT_GAMEPAD_RIGHT_TRIGGER;
	if(B[controller].SNES_Button_A == 10) controllers[controller].button_A = XINPUT_GAMEPAD_LEFT_THUMB;
	if(B[controller].SNES_Button_A == 11) controllers[controller].button_A = XINPUT_GAMEPAD_RIGHT_THUMB;

	controllers[controller].button_B =  B[controller].SNES_Button_B;
	if(B[controller].SNES_Button_B == 0) controllers[controller].button_B = XINPUT_GAMEPAD_A;
	if(B[controller].SNES_Button_B == 1) controllers[controller].button_B = XINPUT_GAMEPAD_B;
	if(B[controller].SNES_Button_B == 2) controllers[controller].button_B = XINPUT_GAMEPAD_X;
	if(B[controller].SNES_Button_B == 3) controllers[controller].button_B = XINPUT_GAMEPAD_Y;
	if(B[controller].SNES_Button_B == 4) controllers[controller].button_B = XINPUT_GAMEPAD_BACK;
	if(B[controller].SNES_Button_B == 5) controllers[controller].button_B = XINPUT_GAMEPAD_START;
	if(B[controller].SNES_Button_B == 6) controllers[controller].button_B = XINPUT_GAMEPAD_WHITE;
	if(B[controller].SNES_Button_B == 7) controllers[controller].button_B = XINPUT_GAMEPAD_BLACK;
	if(B[controller].SNES_Button_B == 8) controllers[controller].button_B = XINPUT_GAMEPAD_LEFT_TRIGGER;
	if(B[controller].SNES_Button_B == 9) controllers[controller].button_B = XINPUT_GAMEPAD_RIGHT_TRIGGER;
	if(B[controller].SNES_Button_B == 10) controllers[controller].button_B = XINPUT_GAMEPAD_LEFT_THUMB;
	if(B[controller].SNES_Button_B == 11) controllers[controller].button_B = XINPUT_GAMEPAD_RIGHT_THUMB;

	controllers[controller].button_X =  B[controller].SNES_Button_X;
	if(B[controller].SNES_Button_X == 0) controllers[controller].button_X = XINPUT_GAMEPAD_A;
	if(B[controller].SNES_Button_X == 1) controllers[controller].button_X = XINPUT_GAMEPAD_B;
	if(B[controller].SNES_Button_X == 2) controllers[controller].button_X = XINPUT_GAMEPAD_X;
	if(B[controller].SNES_Button_X == 3) controllers[controller].button_X = XINPUT_GAMEPAD_Y;
	if(B[controller].SNES_Button_X == 4) controllers[controller].button_X = XINPUT_GAMEPAD_BACK;
	if(B[controller].SNES_Button_X == 5) controllers[controller].button_X = XINPUT_GAMEPAD_START;
	if(B[controller].SNES_Button_X == 6) controllers[controller].button_X = XINPUT_GAMEPAD_WHITE;
	if(B[controller].SNES_Button_X == 7) controllers[controller].button_X = XINPUT_GAMEPAD_BLACK;
	if(B[controller].SNES_Button_X == 8) controllers[controller].button_X = XINPUT_GAMEPAD_LEFT_TRIGGER;
	if(B[controller].SNES_Button_X == 9) controllers[controller].button_X = XINPUT_GAMEPAD_RIGHT_TRIGGER;
	if(B[controller].SNES_Button_X == 10) controllers[controller].button_X = XINPUT_GAMEPAD_LEFT_THUMB;
	if(B[controller].SNES_Button_X == 11) controllers[controller].button_X = XINPUT_GAMEPAD_RIGHT_THUMB;

	controllers[controller].button_Y =  B[controller].SNES_Button_Y;
	if(B[controller].SNES_Button_Y == 0) controllers[controller].button_Y = XINPUT_GAMEPAD_A;
	if(B[controller].SNES_Button_Y == 1) controllers[controller].button_Y = XINPUT_GAMEPAD_B;
	if(B[controller].SNES_Button_Y == 2) controllers[controller].button_Y = XINPUT_GAMEPAD_X;
	if(B[controller].SNES_Button_Y == 3) controllers[controller].button_Y = XINPUT_GAMEPAD_Y;
	if(B[controller].SNES_Button_Y == 4) controllers[controller].button_Y = XINPUT_GAMEPAD_BACK;
	if(B[controller].SNES_Button_Y == 5) controllers[controller].button_Y = XINPUT_GAMEPAD_START;
	if(B[controller].SNES_Button_Y == 6) controllers[controller].button_Y = XINPUT_GAMEPAD_WHITE;
	if(B[controller].SNES_Button_Y == 7) controllers[controller].button_Y = XINPUT_GAMEPAD_BLACK;
	if(B[controller].SNES_Button_Y == 8) controllers[controller].button_Y = XINPUT_GAMEPAD_LEFT_TRIGGER;
	if(B[controller].SNES_Button_Y == 9) controllers[controller].button_Y = XINPUT_GAMEPAD_RIGHT_TRIGGER;
	if(B[controller].SNES_Button_Y == 10) controllers[controller].button_Y = XINPUT_GAMEPAD_LEFT_THUMB;
	if(B[controller].SNES_Button_Y == 11) controllers[controller].button_Y = XINPUT_GAMEPAD_RIGHT_THUMB; 

	controllers[controller].button_Select =  B[controller].SNES_Button_Select; 
	if(B[controller].SNES_Button_Select == 0) controllers[controller].button_Select = XINPUT_GAMEPAD_A;
	if(B[controller].SNES_Button_Select == 1) controllers[controller].button_Select = XINPUT_GAMEPAD_B;
	if(B[controller].SNES_Button_Select == 2) controllers[controller].button_Select = XINPUT_GAMEPAD_X;
	if(B[controller].SNES_Button_Select == 3) controllers[controller].button_Select = XINPUT_GAMEPAD_Y;
	if(B[controller].SNES_Button_Select == 4) controllers[controller].button_Select = XINPUT_GAMEPAD_BACK;
	if(B[controller].SNES_Button_Select == 5) controllers[controller].button_Select = XINPUT_GAMEPAD_START;
	if(B[controller].SNES_Button_Select == 6) controllers[controller].button_Select = XINPUT_GAMEPAD_WHITE;
	if(B[controller].SNES_Button_Select == 7) controllers[controller].button_Select = XINPUT_GAMEPAD_BLACK;
	if(B[controller].SNES_Button_Select == 8) controllers[controller].button_Select = XINPUT_GAMEPAD_LEFT_TRIGGER;
	if(B[controller].SNES_Button_Select == 9) controllers[controller].button_Select = XINPUT_GAMEPAD_RIGHT_TRIGGER;
	if(B[controller].SNES_Button_Select == 10) controllers[controller].button_Select = XINPUT_GAMEPAD_LEFT_THUMB;
	if(B[controller].SNES_Button_Select == 11) controllers[controller].button_Select = XINPUT_GAMEPAD_RIGHT_THUMB;

	controllers[controller].button_Start =  B[controller].SNES_Button_Start;
	if(B[controller].SNES_Button_Start == 0) controllers[controller].button_Start = XINPUT_GAMEPAD_A;
	if(B[controller].SNES_Button_Start == 1) controllers[controller].button_Start = XINPUT_GAMEPAD_B;
	if(B[controller].SNES_Button_Start == 2) controllers[controller].button_Start = XINPUT_GAMEPAD_X;
	if(B[controller].SNES_Button_Start == 3) controllers[controller].button_Start = XINPUT_GAMEPAD_Y;
	if(B[controller].SNES_Button_Start == 4) controllers[controller].button_Start = XINPUT_GAMEPAD_BACK;
	if(B[controller].SNES_Button_Start == 5) controllers[controller].button_Start = XINPUT_GAMEPAD_START;
	if(B[controller].SNES_Button_Start == 6) controllers[controller].button_Start = XINPUT_GAMEPAD_WHITE;
	if(B[controller].SNES_Button_Start == 7) controllers[controller].button_Start = XINPUT_GAMEPAD_BLACK;
	if(B[controller].SNES_Button_Start == 8) controllers[controller].button_Start = XINPUT_GAMEPAD_LEFT_TRIGGER;
	if(B[controller].SNES_Button_Start == 9) controllers[controller].button_Start = XINPUT_GAMEPAD_RIGHT_TRIGGER;
	if(B[controller].SNES_Button_Start == 10) controllers[controller].button_Start = XINPUT_GAMEPAD_LEFT_THUMB;
	if(B[controller].SNES_Button_Start == 11) controllers[controller].button_Start = XINPUT_GAMEPAD_RIGHT_THUMB;


	controllers[controller].button_Left =  B[controller].SNES_Button_Left;    
	if(B[controller].SNES_Button_Left == 0) controllers[controller].button_Left = XINPUT_GAMEPAD_A;
	if(B[controller].SNES_Button_Left == 1) controllers[controller].button_Left = XINPUT_GAMEPAD_B;
	if(B[controller].SNES_Button_Left == 2) controllers[controller].button_Left = XINPUT_GAMEPAD_X;
	if(B[controller].SNES_Button_Left == 3) controllers[controller].button_Left = XINPUT_GAMEPAD_Y;
	if(B[controller].SNES_Button_Left == 4) controllers[controller].button_Left = XINPUT_GAMEPAD_BACK;
	if(B[controller].SNES_Button_Left == 5) controllers[controller].button_Left = XINPUT_GAMEPAD_START;
	if(B[controller].SNES_Button_Left == 6) controllers[controller].button_Left = XINPUT_GAMEPAD_WHITE;
	if(B[controller].SNES_Button_Left == 7) controllers[controller].button_Left = XINPUT_GAMEPAD_BLACK;
	if(B[controller].SNES_Button_Left == 8) controllers[controller].button_Left = XINPUT_GAMEPAD_LEFT_TRIGGER;
	if(B[controller].SNES_Button_Left == 9) controllers[controller].button_Left = XINPUT_GAMEPAD_RIGHT_TRIGGER;
	if(B[controller].SNES_Button_Left == 10) controllers[controller].button_Left = XINPUT_GAMEPAD_LEFT_THUMB;
	if(B[controller].SNES_Button_Left == 11) controllers[controller].button_Left = XINPUT_GAMEPAD_RIGHT_THUMB;

	controllers[controller].button_Right =  B[controller].SNES_Button_Right;
	if(B[controller].SNES_Button_Right == 0) controllers[controller].button_Right = XINPUT_GAMEPAD_A;
	if(B[controller].SNES_Button_Right == 1) controllers[controller].button_Right = XINPUT_GAMEPAD_B;
	if(B[controller].SNES_Button_Right == 2) controllers[controller].button_Right = XINPUT_GAMEPAD_X;
	if(B[controller].SNES_Button_Right == 3) controllers[controller].button_Right = XINPUT_GAMEPAD_Y;
	if(B[controller].SNES_Button_Right == 4) controllers[controller].button_Right = XINPUT_GAMEPAD_BACK;
	if(B[controller].SNES_Button_Right == 5) controllers[controller].button_Right = XINPUT_GAMEPAD_START;
	if(B[controller].SNES_Button_Right == 6) controllers[controller].button_Right = XINPUT_GAMEPAD_WHITE;
	if(B[controller].SNES_Button_Right == 7) controllers[controller].button_Right = XINPUT_GAMEPAD_BLACK;
	if(B[controller].SNES_Button_Right == 8) controllers[controller].button_Right = XINPUT_GAMEPAD_LEFT_TRIGGER;
	if(B[controller].SNES_Button_Right == 9) controllers[controller].button_Right = XINPUT_GAMEPAD_RIGHT_TRIGGER;
	if(B[controller].SNES_Button_Right == 10) controllers[controller].button_Right = XINPUT_GAMEPAD_LEFT_THUMB;
	if(B[controller].SNES_Button_Right == 11) controllers[controller].button_Right = XINPUT_GAMEPAD_RIGHT_THUMB;


	if(controller == 0) {
		controllers[controller].button_FastForward =  B[controller].Button_FastForward; 
		if(B[controller].Button_FastForward == 0) controllers[controller].button_FastForward = XINPUT_GAMEPAD_A;
		if(B[controller].Button_FastForward == 1) controllers[controller].button_FastForward = XINPUT_GAMEPAD_B;
		if(B[controller].Button_FastForward == 2) controllers[controller].button_FastForward = XINPUT_GAMEPAD_X;
		if(B[controller].Button_FastForward == 3) controllers[controller].button_FastForward = XINPUT_GAMEPAD_Y;
		if(B[controller].Button_FastForward == 4) controllers[controller].button_FastForward = XINPUT_GAMEPAD_BACK;
		if(B[controller].Button_FastForward == 5) controllers[controller].button_FastForward = XINPUT_GAMEPAD_START;
		if(B[controller].Button_FastForward == 6) controllers[controller].button_FastForward = XINPUT_GAMEPAD_WHITE;
		if(B[controller].Button_FastForward == 7) controllers[controller].button_FastForward = XINPUT_GAMEPAD_BLACK;
		if(B[controller].Button_FastForward == 8) controllers[controller].button_FastForward = XINPUT_GAMEPAD_LEFT_TRIGGER;
		if(B[controller].Button_FastForward == 9) controllers[controller].button_FastForward = XINPUT_GAMEPAD_RIGHT_TRIGGER;
		if(B[controller].Button_FastForward == 10) controllers[controller].button_FastForward = XINPUT_GAMEPAD_LEFT_THUMB;
		if(B[controller].Button_FastForward == 11) controllers[controller].button_FastForward = XINPUT_GAMEPAD_RIGHT_THUMB;

		controllers[controller].button_Rewind =  B[controller].Button_Rewind;
		if(B[controller].Button_Rewind == 0) controllers[controller].button_Rewind = XINPUT_GAMEPAD_A;
		if(B[controller].Button_Rewind == 1) controllers[controller].button_Rewind = XINPUT_GAMEPAD_B;
		if(B[controller].Button_Rewind == 2) controllers[controller].button_Rewind = XINPUT_GAMEPAD_X;
		if(B[controller].Button_Rewind == 3) controllers[controller].button_Rewind = XINPUT_GAMEPAD_Y;
		if(B[controller].Button_Rewind == 4) controllers[controller].button_Rewind = XINPUT_GAMEPAD_BACK;
		if(B[controller].Button_Rewind == 5) controllers[controller].button_Rewind = XINPUT_GAMEPAD_START;
		if(B[controller].Button_Rewind == 6) controllers[controller].button_Rewind = XINPUT_GAMEPAD_WHITE;
		if(B[controller].Button_Rewind == 7) controllers[controller].button_Rewind = XINPUT_GAMEPAD_BLACK;
		if(B[controller].Button_Rewind == 8) controllers[controller].button_Rewind = XINPUT_GAMEPAD_LEFT_TRIGGER;
		if(B[controller].Button_Rewind == 9) controllers[controller].button_Rewind = XINPUT_GAMEPAD_RIGHT_TRIGGER;
		if(B[controller].Button_Rewind == 10) controllers[controller].button_Rewind = XINPUT_GAMEPAD_LEFT_THUMB;
		if(B[controller].Button_Rewind == 11) controllers[controller].button_Rewind = XINPUT_GAMEPAD_RIGHT_THUMB;


		controllers[controller].button_ShowFPS =  B[controller].Button_ShowFPS; 
		if(B[controller].Button_ShowFPS == 0) controllers[controller].button_ShowFPS = XBGAMEPAD_A;
		if(B[controller].Button_ShowFPS == 1) controllers[controller].button_ShowFPS = XBGAMEPAD_B;
		if(B[controller].Button_ShowFPS == 2) controllers[controller].button_ShowFPS = XBGAMEPAD_X;
		if(B[controller].Button_ShowFPS == 3) controllers[controller].button_ShowFPS = XBGAMEPAD_Y;
		if(B[controller].Button_ShowFPS == 4) controllers[controller].button_ShowFPS = XBGAMEPAD_BACK;
		if(B[controller].Button_ShowFPS == 5) controllers[controller].button_ShowFPS = XBGAMEPAD_START;
		if(B[controller].Button_ShowFPS == 6) controllers[controller].button_ShowFPS = XBGAMEPAD_WHITE;
		if(B[controller].Button_ShowFPS == 7) controllers[controller].button_ShowFPS = XBGAMEPAD_BLACK;
		if(B[controller].Button_ShowFPS == 8) controllers[controller].button_ShowFPS = XBGAMEPAD_LEFT_TRIGGER;
		if(B[controller].Button_ShowFPS == 9) controllers[controller].button_ShowFPS = XBGAMEPAD_RIGHT_TRIGGER;
		if(B[controller].Button_ShowFPS == 10) controllers[controller].button_ShowFPS = XINPUT_GAMEPAD_LEFT_THUMB;
		if(B[controller].Button_ShowFPS == 11) controllers[controller].button_ShowFPS = XINPUT_GAMEPAD_RIGHT_THUMB;

		controllers[controller].button_SaveState =  B[controller].Button_SaveState;
		if(B[controller].Button_SaveState == 0) controllers[controller].button_SaveState = XINPUT_GAMEPAD_A;
		if(B[controller].Button_SaveState == 1) controllers[controller].button_SaveState = XINPUT_GAMEPAD_B;
		if(B[controller].Button_SaveState == 2) controllers[controller].button_SaveState = XINPUT_GAMEPAD_X;
		if(B[controller].Button_SaveState == 3) controllers[controller].button_SaveState = XINPUT_GAMEPAD_Y;
		if(B[controller].Button_SaveState == 4) controllers[controller].button_SaveState = XINPUT_GAMEPAD_BACK;
		if(B[controller].Button_SaveState == 5) controllers[controller].button_SaveState = XINPUT_GAMEPAD_START;
		if(B[controller].Button_SaveState == 6) controllers[controller].button_SaveState = XINPUT_GAMEPAD_WHITE;
		if(B[controller].Button_SaveState == 7) controllers[controller].button_SaveState = XINPUT_GAMEPAD_BLACK;
		if(B[controller].Button_SaveState == 8) controllers[controller].button_SaveState = XINPUT_GAMEPAD_LEFT_TRIGGER;
		if(B[controller].Button_SaveState == 9) controllers[controller].button_SaveState = XINPUT_GAMEPAD_RIGHT_TRIGGER;
		if(B[controller].Button_SaveState == 10) controllers[controller].button_SaveState = XINPUT_GAMEPAD_LEFT_THUMB;
		if(B[controller].Button_SaveState == 11) controllers[controller].button_SaveState = XINPUT_GAMEPAD_RIGHT_THUMB;

		controllers[controller].button_LoadState =  B[controller].Button_LoadState;
		if(B[controller].Button_LoadState == 0) controllers[controller].button_LoadState = XINPUT_GAMEPAD_A;
		if(B[controller].Button_LoadState == 1) controllers[controller].button_LoadState = XINPUT_GAMEPAD_B;
		if(B[controller].Button_LoadState == 2) controllers[controller].button_LoadState = XINPUT_GAMEPAD_X;
		if(B[controller].Button_LoadState == 3) controllers[controller].button_LoadState = XINPUT_GAMEPAD_Y;
		if(B[controller].Button_LoadState == 4) controllers[controller].button_LoadState = XINPUT_GAMEPAD_BACK;
		if(B[controller].Button_LoadState == 5) controllers[controller].button_LoadState = XINPUT_GAMEPAD_START;
		if(B[controller].Button_LoadState == 6) controllers[controller].button_LoadState = XINPUT_GAMEPAD_WHITE;
		if(B[controller].Button_LoadState == 7) controllers[controller].button_LoadState = XINPUT_GAMEPAD_BLACK;
		if(B[controller].Button_LoadState == 8) controllers[controller].button_LoadState = XINPUT_GAMEPAD_LEFT_TRIGGER;
		if(B[controller].Button_LoadState == 9) controllers[controller].button_LoadState = XINPUT_GAMEPAD_RIGHT_TRIGGER;
		if(B[controller].Button_LoadState == 10) controllers[controller].button_LoadState = XINPUT_GAMEPAD_LEFT_THUMB;
		if(B[controller].Button_LoadState == 11) controllers[controller].button_LoadState = XINPUT_GAMEPAD_RIGHT_THUMB;

		controllers[controller].button_ExitGame =  B[controller].Button_ExitGame;
		if(B[controller].Button_ExitGame == 0) controllers[controller].button_ExitGame = XINPUT_GAMEPAD_A;
		if(B[controller].Button_ExitGame == 1) controllers[controller].button_ExitGame = XINPUT_GAMEPAD_B;
		if(B[controller].Button_ExitGame == 2) controllers[controller].button_ExitGame = XINPUT_GAMEPAD_X;
		if(B[controller].Button_ExitGame == 3) controllers[controller].button_ExitGame = XINPUT_GAMEPAD_Y;
		if(B[controller].Button_ExitGame == 4) controllers[controller].button_ExitGame = XINPUT_GAMEPAD_BACK;
		if(B[controller].Button_ExitGame == 5) controllers[controller].button_ExitGame = XINPUT_GAMEPAD_START;
		if(B[controller].Button_ExitGame == 6) controllers[controller].button_ExitGame = XINPUT_GAMEPAD_WHITE;
		if(B[controller].Button_ExitGame == 7) controllers[controller].button_ExitGame = XINPUT_GAMEPAD_BLACK;
		if(B[controller].Button_ExitGame == 8) controllers[controller].button_ExitGame = XINPUT_GAMEPAD_LEFT_TRIGGER;
		if(B[controller].Button_ExitGame == 9) controllers[controller].button_ExitGame = XINPUT_GAMEPAD_RIGHT_TRIGGER;
		if(B[controller].Button_ExitGame == 10) controllers[controller].button_ExitGame = XINPUT_GAMEPAD_LEFT_THUMB;
		if(B[controller].Button_ExitGame == 11) controllers[controller].button_ExitGame = XINPUT_GAMEPAD_RIGHT_THUMB;
	}

}
int fastTurbo = 0;
void drawTurboMenu() {
	if(turboControllerSelected == 0)  { drawTCText("SNES Controller:"); drawTCDText("1"); }
	if(turboControllerSelected == 1)  { drawTCText("SNES Controller:"); drawTCDText("2"); }
	if(turboControllerSelected == 2)  { drawTCText("SNES Controller:"); drawTCDText("3"); }
	if(turboControllerSelected == 3)  { drawTCText("SNES Controller:"); drawTCDText("4"); }

	if(turboControllerSelected == 0) {
		if(tButtons[0].turboA == 0) {drawTCText("SNES Button A Turbo:"); drawTCDText("Off"); }
		if(tButtons[0].turboA == 1) {drawTCText("SNES Button A Turbo:"); drawTCDText("On"); }

		if(tButtons[0].turboB == 0) {drawTCText("SNES Button B Turbo:"); drawTCDText("Off"); }
		if(tButtons[0].turboB == 1) {drawTCText("SNES Button B Turbo:"); drawTCDText("On"); }

		if(tButtons[0].turboX == 0) {drawTCText("SNES Button X Turbo:"); drawTCDText("Off"); }
		if(tButtons[0].turboX == 1) {drawTCText("SNES Button X Turbo:"); drawTCDText("On"); }

		if(tButtons[0].turboY == 0) {drawTCText("SNES Button Y Turbo:"); drawTCDText("Off"); }
		if(tButtons[0].turboY == 1) {drawTCText("SNES Button Y Turbo:"); drawTCDText("On"); }

		if(tButtons[0].turboL == 0) {drawTCText("SNES Button Left Turbo:"); drawTCDText("Off"); }
		if(tButtons[0].turboL == 1) {drawTCText("SNES Button Left Turbo:"); drawTCDText("On"); }

		if(tButtons[0].turboR == 0) {drawTCText("SNES Button Right Turbo:"); drawTCDText("Off"); }
		if(tButtons[0].turboR == 1) {drawTCText("SNES Button Right Turbo:"); drawTCDText("On"); }
	}

	if(turboControllerSelected == 1) {
		if(tButtons[1].turboA == 0) {drawTCText("SNES Button A Turbo:"); drawTCDText("Off"); }
		if(tButtons[1].turboA == 1) {drawTCText("SNES Button A Turbo:"); drawTCDText("On"); }

		if(tButtons[1].turboB == 0) {drawTCText("SNES Button B Turbo:"); drawTCDText("Off"); }
		if(tButtons[1].turboB == 1) {drawTCText("SNES Button B Turbo:"); drawTCDText("On"); }

		if(tButtons[1].turboX == 0) {drawTCText("SNES Button X Turbo:"); drawTCDText("Off"); }
		if(tButtons[1].turboX == 1) {drawTCText("SNES Button X Turbo:"); drawTCDText("On"); }

		if(tButtons[1].turboY == 0) {drawTCText("SNES Button Y Turbo:"); drawTCDText("Off"); }
		if(tButtons[1].turboY == 1) {drawTCText("SNES Button Y Turbo:"); drawTCDText("On"); }

		if(tButtons[1].turboL == 0) {drawTCText("SNES Button Left Turbo:"); drawTCDText("Off"); }
		if(tButtons[1].turboL == 1) {drawTCText("SNES Button Left Turbo:"); drawTCDText("On"); }

		if(tButtons[1].turboR == 0) {drawTCText("SNES Button Right Turbo:"); drawTCDText("Off"); }
		if(tButtons[1].turboR == 1) {drawTCText("SNES Button Right Turbo:"); drawTCDText("On"); }
	}

	if(turboControllerSelected == 2) {
		if(tButtons[2].turboA == 0) {drawTCText("SNES Button A Turbo:"); drawTCDText("Off"); }
		if(tButtons[2].turboA == 1) {drawTCText("SNES Button A Turbo:"); drawTCDText("On"); }

		if(tButtons[2].turboB == 0) {drawTCText("SNES Button B Turbo:"); drawTCDText("Off"); }
		if(tButtons[2].turboB == 1) {drawTCText("SNES Button B Turbo:"); drawTCDText("On"); }

		if(tButtons[2].turboX == 0) {drawTCText("SNES Button X Turbo:"); drawTCDText("Off"); }
		if(tButtons[2].turboX == 1) {drawTCText("SNES Button X Turbo:"); drawTCDText("On"); }

		if(tButtons[2].turboY == 0) {drawTCText("SNES Button Y Turbo:"); drawTCDText("Off"); }
		if(tButtons[2].turboY == 1) {drawTCText("SNES Button Y Turbo:"); drawTCDText("On"); }

		if(tButtons[2].turboL == 0) {drawTCText("SNES Button Left Turbo:"); drawTCDText("Off"); }
		if(tButtons[2].turboL == 1) {drawTCText("SNES Button Left Turbo:"); drawTCDText("On"); }

		if(tButtons[2].turboR == 0) {drawTCText("SNES Button Right Turbo:"); drawTCDText("Off"); }
		if(tButtons[2].turboR == 1) {drawTCText("SNES Button Right Turbo:"); drawTCDText("On"); }
	}

	if(turboControllerSelected == 3) {
		if(tButtons[3].turboA == 0) {drawTCText("SNES Button A Turbo:"); drawTCDText("Off"); }
		if(tButtons[3].turboA == 1) {drawTCText("SNES Button A Turbo:"); drawTCDText("On"); }

		if(tButtons[3].turboB == 0) {drawTCText("SNES Button B Turbo:"); drawTCDText("Off"); }
		if(tButtons[3].turboB == 1) {drawTCText("SNES Button B Turbo:"); drawTCDText("On"); }

		if(tButtons[3].turboX == 0) {drawTCText("SNES Button X Turbo:"); drawTCDText("Off"); }
		if(tButtons[3].turboX == 1) {drawTCText("SNES Button X Turbo:"); drawTCDText("On"); }

		if(tButtons[3].turboY == 0) {drawTCText("SNES Button Y Turbo:"); drawTCDText("Off"); }
		if(tButtons[3].turboY == 1) {drawTCText("SNES Button Y Turbo:"); drawTCDText("On"); }

		if(tButtons[3].turboL == 0) {drawTCText("SNES Button Left Turbo:"); drawTCDText("Off"); }
		if(tButtons[3].turboL == 1) {drawTCText("SNES Button Left Turbo:"); drawTCDText("On"); }

		if(tButtons[3].turboR == 0) {drawTCText("SNES Button Right Turbo:"); drawTCDText("Off"); }
		if(tButtons[3].turboR == 1) {drawTCText("SNES Button Right Turbo:"); drawTCDText("On"); }
	}
	if(fastTurbo == 0) {drawTCText("Turbo Speed:"); drawTCDText("60 Times Per Second"); }
	if(fastTurbo == 1) {drawTCText("Turbo Speed:"); drawTCDText("30 Times Per Second"); }
}


void drawRumbleSlotMenu() {
	rumbleSlotCount = 0;
	drawTCRText("Rumble Setting: 1"); 
	drawTCRText("Rumble Setting: 2"); 
	drawTCRText("Rumble Setting: 3");
	drawTCRText("Rumble Setting: 4"); 
	drawTCRText("Rumble Setting: 5"); 
	drawTCRText("Rumble Setting: 6"); 
	drawTCRText("Rumble Setting: 7"); 
	drawTCRText("Rumble Setting: 8"); 
	drawTCRText("Rumble Setting: 9"); 
	drawTCRText("Rumble Setting: 10"); 

}




void drawRumbleConfig() {
	rumbleSlotCount = 0; 
	yO = 110;
	std::ostringstream drq0;
	drq0 << hex << rumbleList[controllerRumbleMenu].address;
	std::string drw0 = drq0.str();
	std::string a = "Address: 0x";
	std::string b = a + drw0.c_str();
	std::string c = b + ". Description: ";
	std::string d = c + rumbleList[controllerRumbleMenu].description;
	std::string t =d;
	WCHAR abbatext2345[280]={0};
	for(int r = 0; r < 1024; r++) {
		if((t.c_str())[r] == '\0') {
			abbatext2345[r] = '\0';
			break;
		}
		abbatext2345[r] = (t.c_str())[r];
	}
	FontSetColour(0xffff00);
	FontSmallText(abbatext2345,sWidth/2,yO+zTopRM, 600);


	yO = 150;
	if(rumbleList[controllerRumbleMenu].isActive) {
		drawTCRTextR("Force Feedback:"); drawTCRDTextR("On"); 
	} else {
		drawTCRTextR("Force Feedback:"); drawTCRDTextR("Off");
	}

	if(rumbleList[controllerRumbleMenu].controller == 0) { drawTCRTextR("Rumble Location:"); drawTCRDTextR("Controller 1"); } 
	if(rumbleList[controllerRumbleMenu].controller == 1) { drawTCRTextR("Rumble Location:"); drawTCRDTextR("Controller 2"); } 
	if(rumbleList[controllerRumbleMenu].controller == 2) { drawTCRTextR("Rumble Location:"); drawTCRDTextR("Controller 3"); } 
	if(rumbleList[controllerRumbleMenu].controller == 3) { drawTCRTextR("Rumble Location:"); drawTCRDTextR("Controller 4"); } 
	if(rumbleList[controllerRumbleMenu].rumbleType == 0) { drawTCRTextR("Rumble Start/Stop:"); drawTCRDTextR("Change/Timeout "); } 
	if(rumbleList[controllerRumbleMenu].rumbleType == 1) { drawTCRTextR("Rumble Start/Stop:"); drawTCRDTextR("Decrease/Timeout"); } 
	if(rumbleList[controllerRumbleMenu].rumbleType == 2) { drawTCRTextR("Rumble Start/Stop:"); drawTCRDTextR("Increase/Timeout"); } 

	if(rumbleList[controllerRumbleMenu].rumbleType == 3) { drawTCRTextR("Rumble Start/Stop:"); drawTCRDTextR("Change/Change"); } 
	if(rumbleList[controllerRumbleMenu].rumbleType == 4) { drawTCRTextR("Rumble Start/Stop:"); drawTCRDTextR("Change/Decrease"); } 
	if(rumbleList[controllerRumbleMenu].rumbleType == 5) { drawTCRTextR("Rumble Start/Stop:"); drawTCRDTextR("Change/Increase"); } 

	if(rumbleList[controllerRumbleMenu].rumbleType == 6) { drawTCRTextR("Rumble Start/Stop:"); drawTCRDTextR("Decrease/Change"); } 
	if(rumbleList[controllerRumbleMenu].rumbleType == 7) { drawTCRTextR("Rumble Start/Stop:"); drawTCRDTextR("Decrease/Decrease"); } 
	if(rumbleList[controllerRumbleMenu].rumbleType == 8) { drawTCRTextR("Rumble Start/Stop:"); drawTCRDTextR("Decrease/Increase"); } 

	if(rumbleList[controllerRumbleMenu].rumbleType == 9) { drawTCRTextR("Rumble Start/Stop:"); drawTCRDTextR("Increase/Change"); } 
	if(rumbleList[controllerRumbleMenu].rumbleType == 10) { drawTCRTextR("Rumble Start/Stop:"); drawTCRDTextR("Increase/Decrease"); } 
	if(rumbleList[controllerRumbleMenu].rumbleType == 11) { drawTCRTextR("Rumble Start/Stop:"); drawTCRDTextR("Increase/Increase"); } 

	std::ostringstream ddrq0;
	ddrq0 << rumbleList[controllerRumbleMenu].motorOneStrength;
	std::string ddrw0 = ddrq0.str();
	drawTCRTextR("Motor One Strength:"); drawTCRDTextR((char*)ddrw0.c_str()); 

	std::ostringstream fddrq0;
	fddrq0 << rumbleList[controllerRumbleMenu].motorOneTime;
	std::string fddrw0 = fddrq0.str();
	drawTCRTextR("Motor One Rumble Time:"); drawTCRDTextR((char*)fddrw0.c_str()); 

	std::ostringstream hddrq0;
	hddrq0 << rumbleList[controllerRumbleMenu].motorTwoStrength;
	std::string hddrw0 = hddrq0.str();
	drawTCRTextR("Motor Two Strength:"); drawTCRDTextR((char*)hddrw0.c_str()); 

	std::ostringstream hhfddrq0;
	hhfddrq0 << rumbleList[controllerRumbleMenu].motorTwoTime;
	std::string hhfddrw0 = hhfddrq0.str();
	drawTCRTextR("Motor Two Rumble Time:"); drawTCRDTextR((char*)hhfddrw0.c_str()); 


	std::ostringstream ghhfddrq0;
	ghhfddrq0 << rumbleList[controllerRumbleMenu].rumbleTarget;
	std::string ghhfddrw0 = ghhfddrq0.str();
	drawTCRTextR("Rumbles to Skip:"); drawTCRDTextR((char*)ghhfddrw0.c_str()); 



	drawTCRTextR("Change Address To Monitor"); drawTCRDTextR(""); 
	drawTCRTextR("Edit Rumble Description"); drawTCRDTextR("");
	drawTCRTextR("Test Rumble Setting"); drawTCRDTextR(""); 


	drawTCRTextR(""); drawTCRDTextR(""); 


	std::string tg = "Right Thumbstick Up/Down = fast value increase/decrease";

	WCHAR gabbatext2345[280]={0};
	for(int r = 0; r < 1024; r++) {
		if((tg.c_str())[r] == '\0') {
			gabbatext2345[r] = '\0';
			break;
		}
		gabbatext2345[r] = (tg.c_str())[r];
	}
	FontSetColour(0xffff00);
	FontSmallText(gabbatext2345,sWidth/2,yO+zTopRM, 600);


}


void drawRumblePick() {
	rumbleSlotCount = 0; 
	if(rumbleSlot == 0) {drawTCRTextRP("Cheat Search Code Slot: 1"); }
	if(rumbleSlot == 1) {drawTCRTextRP("Cheat Search Code Slot: 2"); }
	if(rumbleSlot == 2) {drawTCRTextRP("Cheat Search Code Slot: 3"); }
	if(rumbleSlot == 3) {drawTCRTextRP("Cheat Search Code Slot: 4"); }
	if(rumbleSlot == 4) {drawTCRTextRP("Cheat Search Code Slot: 5"); }
	if(rumbleSlot == 5) {drawTCRTextRP("Cheat Search Code Slot: 6"); }
	if(rumbleSlot == 6) {drawTCRTextRP("Cheat Search Code Slot: 7"); }
	if(rumbleSlot == 7) {drawTCRTextRP("Cheat Search Code Slot: 8"); }
	if(rumbleSlot == 8) {drawTCRTextRP("Cheat Search Code Slot: 9"); }
	if(rumbleSlot == 9) {drawTCRTextRP("Cheat Search Code Slot: 10"); }
	if(rumbleSlot == 10) {drawTCRTextRP("Cheat Search Code Slot: 11"); }
	if(rumbleSlot == 11) {drawTCRTextRP("Cheat Search Code Slot: 12"); }
	if(rumbleSlot == 12) {drawTCRTextRP("Cheat Search Code Slot: 13"); }
	if(rumbleSlot == 13) {drawTCRTextRP("Cheat Search Code Slot: 14"); }
	if(rumbleSlot == 14) {drawTCRTextRP("Cheat Search Code Slot: 15");}
}


void controllerTurboCheck() {
	if(g_Gamepads[0].Event == XBGAMEPAD_B) {
		if(DisableMenuSounds == 0) playEffect(1);
		controllerMode = 0;
		return;  
	}

	if (g_Gamepads[0].Event == XBGAMEPAD_DPAD_DOWN)  {  
		if(DisableMenuSounds == 0) playEffect(0);	
		controllerTurboMenu++; if(controllerTurboMenu > 7) controllerTurboMenu = 0; 
	}  

	if (g_Gamepads[0].Event == XBGAMEPAD_DPAD_UP)  {  
		if(DisableMenuSounds == 0) playEffect(0);	
		controllerTurboMenu--; if(controllerTurboMenu < 0) controllerTurboMenu = 7; 
	}  

	if(g_Gamepads[0].Event == XBGAMEPAD_A) {
		if(DisableMenuSounds == 0) playEffect(2);

		if(controllerTurboMenu == 0) {turboControllerSelected++; if(turboControllerSelected > 3) turboControllerSelected = 0;}
		if(controllerTurboMenu == 1) {tButtons[turboControllerSelected].turboA++; tButtons[turboControllerSelected].turboA &= 1; }
		if(controllerTurboMenu == 2) {tButtons[turboControllerSelected].turboB++; tButtons[turboControllerSelected].turboB &= 1; }
		if(controllerTurboMenu == 3) {tButtons[turboControllerSelected].turboX++; tButtons[turboControllerSelected].turboX &= 1; }
		if(controllerTurboMenu == 4) {tButtons[turboControllerSelected].turboY++; tButtons[turboControllerSelected].turboY &= 1; }
		if(controllerTurboMenu == 5) {tButtons[turboControllerSelected].turboL++; tButtons[turboControllerSelected].turboL &= 1; }
		if(controllerTurboMenu == 6) {tButtons[turboControllerSelected].turboR++; tButtons[turboControllerSelected].turboR &= 1; }
		if(controllerTurboMenu == 7) {fastTurbo++; fastTurbo &= 1; Turbo30hz = fastTurbo; }
	} 
}
int rumbleGameSelected = 0;
int TGAGameSelected = 0;
void controllerRumbleCheck() {
	if(g_Gamepads[0].Event == XBGAMEPAD_B) {
		if(DisableMenuSounds == 0) playEffect(1);
		controllerMode = 0;
		return;  
	}

	if (g_Gamepads[0].Event == XBGAMEPAD_DPAD_DOWN)  {  
		if(DisableMenuSounds == 0) playEffect(0);	
		controllerRumbleMenu++; if(controllerRumbleMenu > 9) controllerRumbleMenu = 0; 
	}  

	if (g_Gamepads[0].Event == XBGAMEPAD_DPAD_UP)  {  
		if(DisableMenuSounds == 0) playEffect(0);	
		controllerRumbleMenu--; if(controllerRumbleMenu < 0) controllerRumbleMenu = 9; 
	}  

	if(g_Gamepads[0].Event == XBGAMEPAD_A) {
		if(DisableMenuSounds == 0) playEffect(2);
		displayRumbleConfig = 1;
		controllerRumbleConfigMenu = 0;
	} 
}

double slowRumble = 0;
int rumbleDBGameSelected = 0;
struct rumbleDBEntry {
	string name;
	string path;
	bool rumbleFound;
	//vector<rumbleSetting> rumbles;
};
vector<rumbleDBEntry> rumbleDatabase;

double slowTGA = 0;
int TGADBGameSelected = 0;
struct TGADBEntry {
	string name;
	string path;
	bool isAGame;
	bool isARoot;
	bool isADirectory;
	bool topLevel;
	int soundTrack;
	int song;
	int archive;
};
vector<string> TGADirectories;
vector<TGADBEntry> TGADatabase;

void clearTGAList() {
	TGADatabase.clear();
}

extern unsigned char leftAnalog;
extern unsigned char rightAnalog;
extern float scrollSpeed;

void clearRumbleList() {
	rumbleDatabase.clear();
}

#include <string>
#include <vector>
#include <algorithm>
using namespace std;

bool operator<(const rumbleDBEntry &l, const rumbleDBEntry &r) {
	std::string a = l.name;
	std::string b = r.name;
	transform(a.begin(), a.end(), a.begin(), tolower);
	transform(b.begin(), b.end(), b.begin(), tolower);
	if(a < b) return true; else return false;
}

bool operator<(const TGADBEntry &l, const TGADBEntry &r) {
	std::string a = l.name;
	std::string b = r.name;
	transform(a.begin(), a.end(), a.begin(), tolower);
	transform(b.begin(), b.end(), b.begin(), tolower);
	if(a < b) return true; else return false;
}
bool checkRumbleFile(string path) {
	vector<rumbleSetting> rumbleList; 
	rumbleList.clear(); 
	for(int i = 0; i < 10; i++) { 
		rumbleSetting r; 
		r.isActive = false; 
		r.address = 0; 
		r.bank = 0; 
		r.rumbleType = 0; 
		r.currentValue = 0; 
		r.previousValue = 0; 
		r.description = "No Description Found" ;
		r.motorOneStrength = 0; 
		r.motorTwoStrength = 0; 
		r.motorOneTime = 0; 
		r.motorTwoTime = 0; 
		r.controller = 0; 
		r.rumbleCount = 0; 
		r.rumbleTarget = 0;
		rumbleList.push_back(r); 
	} 

	FILE* f;
	f = fopen(path.c_str() , "r");
	if(!f) {
		return false;
	}

	for(int i = 0; i < 10; i++) {
		char a[100]; for(int t = 0; t < 100; t++) a[t] = '\0'; fgets(a, 100, f);
		rumbleList[i].isActive = (bool)atoi(a);

		char b[100]; for(int t = 0; t < 100; t++) b[t] = '\0'; fgets(b, 100, f);
		rumbleList[i].address  = (unsigned short) atoi(b);

		char c[100]; for(int t = 0; t < 100; t++) c[t] = '\0'; fgets(c, 100, f);
		rumbleList[i].bank = (unsigned char)atoi(c);

		char d[100]; for(int t = 0; t < 100; t++) d[t] = '\0'; fgets(d, 100, f);
		rumbleList[i].rumbleType  = atoi(d);

		char e[100];
		for(int t = 0; t < 100; t++) e[t] = '\0';
		fgets(e, 100, f);
		for(int q = 0; q < 100; q++) 
			if(e[q] == '\n') e[q] = '\0';
		rumbleList[i].description = e;

		char g[100]; for(int t = 0; t < 100; t++) g[t] = '\0'; fgets(g, 100, f);
		rumbleList[i].motorOneStrength  = atoi(g);

		char h[100]; for(int t = 0; t < 100; t++) h[t] = '\0'; fgets(h, 100, f);
		rumbleList[i].motorTwoStrength  = atoi(h);

		char j[100]; for(int t = 0; t < 100; t++) j[t] = '\0'; fgets(j, 100, f);
		rumbleList[i].motorOneTime  = (float) atof(j);

		char k[100]; for(int t = 0; t < 100; t++) k[t] = '\0'; fgets(k, 100, f);
		rumbleList[i].motorTwoTime  = (float) atof(k);

		char m[100]; for(int t = 0; t < 100; t++) m[t] = '\0'; fgets(m, 100, f);
		rumbleList[i].controller  = atoi(m);

		char m3[100]; for(int t = 0; t < 100; t++) m3[t] = '\0'; fgets(m3, 100, f);
		rumbleList[i].rumbleTarget  = atoi(m3);
	}
	fclose(f);


	for(int i = 0; i < 10; i++) {
		if(rumbleList[i].isActive || rumbleList[i].address != 0 || rumbleList[i].bank != 0 || rumbleList[i].rumbleType != 0
			|| rumbleList[i].motorOneStrength != 0 || rumbleList[i].controller != 0
			|| rumbleList[i].motorTwoStrength != 0 || rumbleList[i].rumbleTarget != 0
			|| rumbleList[i].motorOneTime != 0 || rumbleList[i].motorTwoTime != 0)
			return true;
	}



	return false;
}


void searchDirectoryTGA(std::string pathToSearch) {
	/*for(int i = 0; i < f.name.size(); i++) {
	if((   (f.name.c_str())[i] == '.' 
	&& (f.name.c_str())[i+1] == 'p' 
	&& (f.name.c_str())[i+2] == 'n' 
	&& (f.name.c_str())[i+3] == 'g' 
	&& (f.name.c_str())[i+4] == '\0') 
	) {
	f.name[i] = '\0';
	break;
	}
	}*/
	TGADatabase.clear();
	dprintf("Path: %s\n", pathToSearch.c_str());
	TGAGameSelected = 0;
	std::string path1 = pathToSearch;// + "*";
	std::string path2("*");
	std::string path = path1 + path2;
	HANDLE find=NULL;
	WIN32_FIND_DATA wfd;
	dprintf("Path Q: %s\n", pathToSearch.c_str());
	memset(&wfd,0,sizeof(wfd));
	find=FindFirstFile(path.c_str(),&wfd);

	if (find ==INVALID_HANDLE_VALUE){ //Empty directory
		TGADBEntry t, t2;
		t.name = "No Image files were found";
		t.path = "";
		t.isADirectory = false;
		t.archive = 0;
		t.song = 0;
		t.soundTrack = 0;
		t.topLevel = false;
		t.isAGame = false;
		t.isARoot = false;
		TGADatabase.push_back(t);
		return;
	}
	
	do {
		if(!(wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) {
			//Not a folder		 
			std::string fileFound(wfd.cFileName);

			int r1 = fileFound.find(".png", 0);
			int r2 = fileFound.find(".PNG", 0);
			int r3 = fileFound.find(".jpg", 0);
			int r4 = fileFound.find(".JPG", 0);
			int r5 = fileFound.find(".dds", 0);
			int r6 = fileFound.find(".DDS", 0);
			int r7 = fileFound.find(".tga", 0);
			int r8 = fileFound.find(".TGA", 0);

			if( r1 != string::npos || r2 != string::npos ||
				r3 != string::npos || r4 != string::npos ||
				r5 != string::npos || r6 != string::npos |
				r7 != string::npos || r8 != string::npos) {
					TGADBEntry f;
					f.name = fileFound;
					f.path = pathToSearch + fileFound;
					f.isADirectory = false;
					TGADatabase.push_back(f);	
				}
		}
		else {
			std::string folderName(wfd.cFileName);
			folderName = "<" + folderName + ">"; 

			TGADBEntry d;
			d.archive = 0;
			d.name = folderName;
			std::string folderNameNoBrackets(wfd.cFileName);
			d.path = pathToSearch +  folderNameNoBrackets + "\\";
			d.isAGame = false;
			d.isARoot = false;
			d.isADirectory = true;
			d.topLevel = false;
			dprintf("Directory Name: %s\n", (char*)d.name.c_str());
			dprintf("Directory Path: %s\n", (char*)d.path.c_str());
			TGADatabase.push_back(d);
		}
	} while (FindNextFile(find,&wfd) !=0);
	//sort(guideDatabase.begin(), guideDatabase.end());
	sort(TGADatabase.begin(), TGADatabase.end());
}
void searchDirectoryRumble(std::string pathToSearch) {
	std::string path1 = pathToSearch;// + "*";
	std::string path2("*");
	std::string path = path1 + path2;
	HANDLE find=NULL;
	WIN32_FIND_DATA wfd;
	memset(&wfd,0,sizeof(wfd));
	find=FindFirstFile(path.c_str(),&wfd);

	if (find ==INVALID_HANDLE_VALUE){ //Empty directory
		rumbleDBEntry t, t2;
		t.name = "No rumble files were found in D:\\rumble";
		t.path = "";
		t.rumbleFound = false;
		rumbleDatabase.push_back(t);
		return;
	}
	do {
		if(!(wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) {
			//Not a folder		 
			std::string fileFound(wfd.cFileName);

			int r = fileFound.find(".rmb", 0);

			if(r != string::npos) {
				rumbleDBEntry f;
				f.name = fileFound;
				for(int i = 0; i < f.name.size(); i++) {
					if((   (f.name.c_str())[i] == '.' 
						&& (f.name.c_str())[i+1] == 'r' 
						&& (f.name.c_str())[i+2] == 'm' 
						&& (f.name.c_str())[i+3] == 'b' 
						&& (f.name.c_str())[i+4] == '\0') 
						) {
							f.name[i] = '\0';
							break;
						}
				}
				f.path = pathToSearch + fileFound;
				f.rumbleFound = checkRumbleFile(f.path);
				rumbleDatabase.push_back(f);	
			}
		}
	} while (FindNextFile(find,&wfd) !=0);
	//sort(guideDatabase.begin(), guideDatabase.end());
	sort(rumbleDatabase.begin(), rumbleDatabase.end());
}

void buildTGAList() {
	TGADatabase.clear();
	TGADirectories.clear();
	searchDirectoryTGA("D:\\Images\\");
	TGADirectories.push_back("D:\\Images\\");
}
void buildRumbleList() {
	/*rumbleDatabase.clear();

	rumbleDBEntry game;

	for(int i = 0; i < 100; i++) {
	char b[133];
	itoa(i, b, 10);
	game.name = "Super Mario World ";
	game.name += b;
	rumbleDatabase.push_back(game);
	}*/

	rumbleDatabase.clear();
	searchDirectoryRumble("D:\\rumble\\");


}

void controllerRumbleDatabaseCheck() {

	if( g_Gamepads[0].bAnalogButtons[XINPUT_GAMEPAD_LEFT_TRIGGER]) {
		if(slowRumble >= 1)  { 
			slowRumble = 0;
		}
		if(leftAnalog == 255)
			slowRumble = scrollSpeed;
		else
			slowRumble += ((float)leftAnalog/255.0f);
		rumbleGameSelected-=((int)slowRumble); if(rumbleGameSelected < 0) rumbleGameSelected = 0;

	}

	if( g_Gamepads[0].bAnalogButtons[XINPUT_GAMEPAD_RIGHT_TRIGGER]) {
		if(slowRumble >= 1) { 
			slowRumble = 0; 
		} 
		if(rightAnalog == 255)
			slowRumble = scrollSpeed;
		else
			slowRumble += ((float)rightAnalog/255.0f);
		rumbleGameSelected+=((int)slowRumble); if(rumbleGameSelected >= rumbleDatabase.size()) rumbleGameSelected = rumbleDatabase.size() - 1;

	}

	if (g_Gamepads[0].Event == XBGAMEPAD_DPAD_UP)  {  
		if(DisableMenuSounds == 0 && rumbleGameSelected != 0) playEffect(0);
		rumbleGameSelected--; if(rumbleGameSelected < 0) rumbleGameSelected = 0;
	}  

	if (g_Gamepads[0].Event == XBGAMEPAD_DPAD_DOWN)  {  
		if(DisableMenuSounds == 0 && (rumbleGameSelected != (rumbleDatabase.size() - 1))) playEffect(0);	
		rumbleGameSelected++; if(rumbleGameSelected >= rumbleDatabase.size()) rumbleGameSelected = rumbleDatabase.size() - 1;
	}  



	if(g_Gamepads[0].Event == XBGAMEPAD_B) {
		if(DisableMenuSounds == 0) playEffect(1);
		controllerMode = 0;
		clearRumbleList();
		return;  
	}

	if(g_Gamepads[0].Event == XBGAMEPAD_A) {
		if(DisableMenuSounds == 0) playEffect(2);
		/*displayRumbleConfig = 1;
		controllerRumbleConfigMenu = 0;*/
		rumbleDatabasePick = 1;
	} 

	if(g_Gamepads[0].Event == XBGAMEPAD_BLACK) {
		if(DisableMenuSounds == 0) playEffect(2);
		/*displayRumbleConfig = 1;
		controllerRumbleConfigMenu = 0;*/
		rumbleDatabaseDelete = 1;
	} 

}

extern LPDIRECT3DTEXTURE8 TexImage;
extern LPDIRECT3DTEXTURE8 TexScreen;
extern LPDIRECT3DTEXTURE8 TexScreenShot;
extern LPDIRECT3DTEXTURE8 TexGUIPreview;
extern LPDIRECT3DTEXTURE8 TexController;
extern IDirect3DDevice8 *Device;
void controllerTGADatabaseCheck() {

	if( g_Gamepads[0].bAnalogButtons[XINPUT_GAMEPAD_LEFT_TRIGGER]) {
		if(slowTGA >= 1)  { 
			slowTGA = 0;
		}
		if(leftAnalog == 255)
			slowTGA = scrollSpeed;
		else
			slowTGA += ((float)leftAnalog/255.0f);
		TGAGameSelected-=((int)slowTGA); if(TGAGameSelected < 0) TGAGameSelected = 0;
		return;
	}

	if( g_Gamepads[0].bAnalogButtons[XINPUT_GAMEPAD_RIGHT_TRIGGER]) {
		if(slowTGA >= 1) { 
			slowTGA = 0; 
		} 
		if(rightAnalog == 255)
			slowTGA = scrollSpeed;
		else
			slowTGA += ((float)rightAnalog/255.0f);
		TGAGameSelected+=((int)slowTGA); if(TGAGameSelected >= TGADatabase.size()) TGAGameSelected = TGADatabase.size() - 1;
		return;
	}

	if (g_Gamepads[0].Event == XBGAMEPAD_DPAD_UP)  {  
		if(DisableMenuSounds == 0 && TGAGameSelected != 0) playEffect(0);
		TGAGameSelected--; if(TGAGameSelected < 0) TGAGameSelected = 0;
		return;

	}  

	if (g_Gamepads[0].Event == XBGAMEPAD_DPAD_DOWN)  {  
		if(DisableMenuSounds == 0 && (TGAGameSelected != (TGADatabase.size() - 1))) playEffect(0);	
		TGAGameSelected++; if(TGAGameSelected >= TGADatabase.size()) TGAGameSelected = TGADatabase.size() - 1;
		return;
	}  




	if(g_Gamepads[0].Event == XBGAMEPAD_B) {
		if(TGADirectories.size() == 1) {
			if(DisableMenuSounds == 0) playEffect(1);
			//controllerMode = 0;weqweew
			screenOptions     = 1;
			screenGeneralOptionsTGA = 0;
			clearTGAList();
			return;  
		}
		else {
			if(DisableMenuSounds == 0) playEffect(2);
			TGADirectories.erase(TGADirectories.begin() + (TGADirectories.size() - 1), TGADirectories.begin() + (TGADirectories.size() - 1) + 1);
			string q = TGADirectories[TGADirectories.size() - 1];
			searchDirectoryTGA(q);
		}
	}

	if(g_Gamepads[0].Event == XBGAMEPAD_A) {
		if(DisableMenuSounds == 0) playEffect(2);
		/*displayTGAConfig = 1;
		controllerTGAConfigMenu = 0;*/
		dprintf("TGAGameSelected: %d\n", TGAGameSelected);
		dprintf("TGADatabase[TGAGameSelected].name: %s\n", (char*)TGADatabase[TGAGameSelected].name.c_str());
		dprintf("TGADatabase[TGAGameSelected].path: %s\n", (char*)TGADatabase[TGAGameSelected].path.c_str());
		dprintf("TGADatabase[TGAGameSelected].Directory: %d\n", (int)TGADatabase[TGAGameSelected].isADirectory);
		if(TGADatabase[TGAGameSelected].isADirectory) {
			TGADirectories.push_back(TGADatabase[TGAGameSelected].path);
			searchDirectoryTGA(TGADatabase[TGAGameSelected].path);
			return;
		}
		TGADatabasePick = 1;
		screenGeneralOptionsTGA = 0;

		//if(TexScreen) { TexScreen->Release(); TexScreen = NULL; }
		if(TexScreenShot) { TexScreenShot->Release(); TexScreenShot = NULL; }

		if(TexController) {
			TexController->Release();
			TexController = NULL;
		}
		if(TexImage) {TexImage->Release();TexImage = NULL;}

		DWORD dwTexWidth  = 0;//desc.Width;
		DWORD dwTexHeight = 0;//desc.Height;
		D3DXIMAGE_INFO           pSrcInfo;
		if(FAILED(D3DXCreateTextureFromFileEx(Device, 
			TGADatabase[TGAGameSelected].path.c_str(), 
			32, //Width:D3DX_DEFAULT = Take from file 
			32, //Height:D3DX_DEFAULT = Take from file
			1,            //MipLevels
			0,            //Usage, Is this to be used as a Render Target? 0 == No
			D3DFMT_UNKNOWN, //32-bit with Alpha, everything should support this
			D3DPOOL_MANAGED,//Pool, let D3D Manage our memory
			D3DX_DEFAULT, D3DX_DEFAULT,
			0,            //Disable ColourKey
			&pSrcInfo,         //SourceInfo, returns extra info if we want it (we don't)
			NULL,         //Palette:We're not using one
			&TexImage ))) {
				return;
			}
			//D3DSURFACE_DESC desc;
			//TexImage->GetLevelDesc( 0, &desc );
			dwTexWidth  = pSrcInfo.Width;
			dwTexHeight = pSrcInfo.Height;
			//dprintf("Width: %d\n", dwTexWidth);
			//dprintf("Height: %d\n", dwTexHeight);
			if(TexImage) {TexImage->Release();TexImage = NULL;}


			if(FAILED(D3DXCreateTextureFromFileEx(Device, 
				TGADatabase[TGAGameSelected].path.c_str(), 
				D3DX_DEFAULT, 
				D3DX_DEFAULT,
				1,            //MipLevels
				0,            //Usage, Is this to be used as a Render Target? 0 == No
				D3DFMT_UNKNOWN, //32-bit with Alpha, everything should support this
				D3DPOOL_MANAGED,//Pool, let D3D Manage our memory
				D3DX_DEFAULT, D3DX_DEFAULT,
				0,            //Disable ColourKey
				NULL,         //SourceInfo, returns extra info if we want it (we don't)
				NULL,         //Palette:We're not using one
				&TexImage ))) {
					if(TexImage) {TexImage->Release();TexImage = NULL;}
					if(dwTexWidth > dwTexHeight) {
						//dwTexWidth  = 1024;
						//dwTexHeight = 768;
						if(FAILED(D3DXCreateTextureFromFileEx(Device, 
							TGADatabase[TGAGameSelected].path.c_str(), 
							1024, //Width:D3DX_DEFAULT = Take from file 
							768, //Height:D3DX_DEFAULT = Take from file
							1,            //MipLevels
							0,            //Usage, Is this to be used as a Render Target? 0 == No
							D3DFMT_UNKNOWN, //32-bit with Alpha, everything should support this
							D3DPOOL_MANAGED,//Pool, let D3D Manage our memory
							D3DX_DEFAULT, D3DX_DEFAULT,
							0,            //Disable ColourKey
							NULL,         //SourceInfo, returns extra info if we want it (we don't)
							NULL,         //Palette:We're not using one
							&TexImage ))) {
								//dwTexWidth  = 800;
								//dwTexHeight = 600;
								if(TexImage) {TexImage->Release();TexImage = NULL;}
								if(FAILED(D3DXCreateTextureFromFileEx(Device, 
									TGADatabase[TGAGameSelected].path.c_str(), 
									800, //Width:D3DX_DEFAULT = Take from file 
									600, //Height:D3DX_DEFAULT = Take from file
									1,            //MipLevels
									0,            //Usage, Is this to be used as a Render Target? 0 == No
									D3DFMT_UNKNOWN, //32-bit with Alpha, everything should support this
									D3DPOOL_MANAGED,//Pool, let D3D Manage our memory
									D3DX_DEFAULT, D3DX_DEFAULT,
									0,            //Disable ColourKey
									NULL,         //SourceInfo, returns extra info if we want it (we don't)
									NULL,         //Palette:We're not using one
									&TexImage ))) {
										//dwTexWidth  = 640;
										//dwTexHeight = 480;
										if(TexImage) {TexImage->Release();TexImage = NULL;}
										if(FAILED(D3DXCreateTextureFromFileEx(Device, 
											TGADatabase[TGAGameSelected].path.c_str(), 
											640, //Width:D3DX_DEFAULT = Take from file 
											480, //Height:D3DX_DEFAULT = Take from file
											1,            //MipLevels
											0,            //Usage, Is this to be used as a Render Target? 0 == No
											D3DFMT_UNKNOWN, //32-bit with Alpha, everything should support this
											D3DPOOL_MANAGED,//Pool, let D3D Manage our memory
											D3DX_DEFAULT, D3DX_DEFAULT,
											0,            //Disable ColourKey
											NULL,         //SourceInfo, returns extra info if we want it (we don't)
											NULL,         //Palette:We're not using one
											&TexImage ))) {
												dwTexWidth  = 320;
												dwTexHeight = 240;
												if(TexImage) {TexImage->Release();TexImage = NULL;}
												if(FAILED(D3DXCreateTextureFromFileEx(Device, 
													TGADatabase[TGAGameSelected].path.c_str(), 
													320, //Width:D3DX_DEFAULT = Take from file 
													240, //Height:D3DX_DEFAULT = Take from file
													1,            //MipLevels
													0,            //Usage, Is this to be used as a Render Target? 0 == No
													D3DFMT_UNKNOWN, //32-bit with Alpha, everything should support this
													D3DPOOL_MANAGED,//Pool, let D3D Manage our memory
													D3DX_DEFAULT, D3DX_DEFAULT,
													0,            //Disable ColourKey
													NULL,         //SourceInfo, returns extra info if we want it (we don't)
													NULL,         //Palette:We're not using one
													&TexImage ))) {
														if(TexImage) {TexImage->Release();TexImage = NULL;}
														return;
													}
											}
									}
							}

					}
					else {

						//dwTexWidth  = 768;
						//dwTexHeight = 1024;
						if(FAILED(D3DXCreateTextureFromFileEx(Device, 
							TGADatabase[TGAGameSelected].path.c_str(), 
							768, //Width:D3DX_DEFAULT = Take from file 
							1024, //Height:D3DX_DEFAULT = Take from file
							1,            //MipLevels
							0,            //Usage, Is this to be used as a Render Target? 0 == No
							D3DFMT_UNKNOWN, //32-bit with Alpha, everything should support this
							D3DPOOL_MANAGED,//Pool, let D3D Manage our memory
							D3DX_DEFAULT, D3DX_DEFAULT,
							0,            //Disable ColourKey
							NULL,         //SourceInfo, returns extra info if we want it (we don't)
							NULL,         //Palette:We're not using one
							&TexImage ))) {
								//dwTexWidth  = 600;
								//dwTexHeight = 800;
								if(TexImage) {TexImage->Release();TexImage = NULL;}
								if(FAILED(D3DXCreateTextureFromFileEx(Device, 
									TGADatabase[TGAGameSelected].path.c_str(), 
									600, //Width:D3DX_DEFAULT = Take from file 
									800, //Height:D3DX_DEFAULT = Take from file
									1,            //MipLevels
									0,            //Usage, Is this to be used as a Render Target? 0 == No
									D3DFMT_UNKNOWN, //32-bit with Alpha, everything should support this
									D3DPOOL_MANAGED,//Pool, let D3D Manage our memory
									D3DX_DEFAULT, D3DX_DEFAULT,
									0,            //Disable ColourKey
									NULL,         //SourceInfo, returns extra info if we want it (we don't)
									NULL,         //Palette:We're not using one
									&TexImage ))) {
										//dwTexWidth  = 480;
										//dwTexHeight = 640;
										if(TexImage) {TexImage->Release();TexImage = NULL;}
										if(FAILED(D3DXCreateTextureFromFileEx(Device, 
											TGADatabase[TGAGameSelected].path.c_str(), 
											480, //Width:D3DX_DEFAULT = Take from file 
											640, //Height:D3DX_DEFAULT = Take from file
											1,            //MipLevels
											0,            //Usage, Is this to be used as a Render Target? 0 == No
											D3DFMT_UNKNOWN, //32-bit with Alpha, everything should support this
											D3DPOOL_MANAGED,//Pool, let D3D Manage our memory
											D3DX_DEFAULT, D3DX_DEFAULT,
											0,            //Disable ColourKey
											NULL,         //SourceInfo, returns extra info if we want it (we don't)
											NULL,         //Palette:We're not using one
											&TexImage ))) {
												//dwTexWidth  = 240;
												//dwTexHeight = 320;
												if(TexImage) {TexImage->Release();TexImage = NULL;}
												if(FAILED(D3DXCreateTextureFromFileEx(Device, 
													TGADatabase[TGAGameSelected].path.c_str(), 
													240, //Width:D3DX_DEFAULT = Take from file 
													320, //Height:D3DX_DEFAULT = Take from file
													1,            //MipLevels
													0,            //Usage, Is this to be used as a Render Target? 0 == No
													D3DFMT_UNKNOWN, //32-bit with Alpha, everything should support this
													D3DPOOL_MANAGED,//Pool, let D3D Manage our memory
													D3DX_DEFAULT, D3DX_DEFAULT,
													0,            //Disable ColourKey
													NULL,         //SourceInfo, returns extra info if we want it (we don't)
													NULL,         //Palette:We're not using one
													&TexImage ))) {
														if(TexImage) {TexImage->Release();TexImage = NULL;}
														return;
													}
											}
									}
							}

					}

				}

				if(TexImage) {
					//D3DSURFACE_DESC desc;
					//TexImage->GetLevelDesc( 0, &desc );
					//dwTexWidth  = desc.Width;
					//dwTexHeight = desc.Height;
					zTopBI = 9.44;
					zLeftBI =	-12.8;
					zRightBI = -12.8 + (((float)dwTexWidth/ (float)sWidth ) * (12.8f * 2.0f));
					zBottomBI = 9.44 - (((float)dwTexHeight / (float)sHeight) * (9.44f * 2.0f));
					
					
					
					/*
					if (g_Gamepads[0].fY2 < 0) { 
						float w = zRightBI - zLeftBI;
						float h = zTopBI - zBottomBI;
						zRightBI-= w * 0.01f; zBottomBI+= h * 0.01f; 

					}// Left
					if (g_Gamepads[0].fY2 > 0) {
						float w = zRightBI - zLeftBI;
						float h = zTopBI - zBottomBI;
						zRightBI+=w * 0.01f; zBottomBI-=h * 0.01f; 
					}// Right
					*/
					if(zBottomBI < -9.44) {
						while(zBottomBI < -9.44) {
							float w2 = zRightBI - zLeftBI;
							float h2 = zTopBI - zBottomBI;
							zRightBI-=w2 * 0.01f; zBottomBI+=h2 * 0.01f; 
						}
					}
					else {
						while(zBottomBI >= -9.44) {
							float w2 = zRightBI - zLeftBI;
							float h2 = zTopBI - zBottomBI;
							zRightBI+=w2 * 0.01f; zBottomBI-=h2 * 0.01f; 
						}
					}
					float w = zRightBI - zLeftBI;
					float h = zTopBI - zBottomBI;
					zTopBI = 0 +  (h / 2);
					zBottomBI = zTopBI - h;
					zLeftBI =	0 - ((w) / 2);
					zRightBI = zLeftBI + w;
				}
				return;
	} 

	if(g_Gamepads[0].Event == XBGAMEPAD_BLACK) {
		if(DisableMenuSounds == 0) playEffect(2);
		/*displayTGAConfig = 1;
		controllerTGAConfigMenu = 0;*/
		TGADatabaseDelete = 1;
		screenGeneralOptionsTGA = 0;
		return;
	} 

}
extern LPDIRECT3DTEXTURE8 TexImage;
extern float zTopBI;// -1.019999f;
extern float zLeftBI ;//0.039999f;
extern float zBottomBI;// -2.24f;
extern float zRightBI;//-0.56f;
extern char skinPath[512];
void imageDelete() {
	if(g_Gamepads[0].Event == XBGAMEPAD_B) {
		if(DisableMenuSounds == 0) playEffect(1);
		TGADatabaseDelete = 0;
		screenGeneralOptionsTGA = 1;
		return;          
	}
	if(g_Gamepads[0].Event == XBGAMEPAD_Y) {
		if(DisableMenuSounds == 0) playEffect(1);

		std::string a = GARBAGE_PATH;//
		std::string newName = a + TGADatabase[TGAGameSelected].name.c_str();
		newName += ".png";
		int r = MoveFileEx(TGADatabase[TGAGameSelected].path.c_str(),  newName.c_str(), MOVEFILE_COPY_ALLOWED);
		TGADatabaseDelete = 0;
		screenGeneralOptionsTGA = 1;
		buildTGAList();
		return;
	}
}

void imageControl() {
	if(g_Gamepads[0].Event == XBGAMEPAD_B) {
		if(DisableMenuSounds == 0) playEffect(1);
		TGADatabasePick = 0;
		screenGeneralOptionsTGA = 1;
		if(TexImage) {
			TexImage->Release();
			TexImage = NULL;
		}

		//Device->CreateTexture(640, 480, 0, 0L, D3DFMT_LIN_R5G6B5, D3DPOOL_DEFAULT, &TexScreen);
		Device->CreateTexture(640, 480, 0, 0L, D3DFMT_LIN_R5G6B5, D3DPOOL_DEFAULT, &TexScreenShot);

		std::string a10 = "D:\\skins\\";
		a10 += skinPath;
		a10 += "\\";
		a10 += "controller.png";
		D3DXCreateTextureFromFileEx(Device, 
			a10.c_str(), 
			D3DX_DEFAULT, //Width:D3DX_DEFAULT = Take from file 
			D3DX_DEFAULT, //Height:D3DX_DEFAULT = Take from file
			1,            //MipLevels
			0,            //Usage, Is this to be used as a Render Target? 0 == No
			D3DFMT_A8R8G8B8, //32-bit with Alpha, everything should support this
			D3DPOOL_MANAGED,//Pool, let D3D Manage our memory
			D3DX_DEFAULT, //Filter:Default filtering
			D3DX_DEFAULT, //MipFilter, used for filtering mipmaps
			0,            //Disable ColourKey
			NULL,         //SourceInfo, returns extra info if we want it (we don't)
			NULL,         //Palette:We're not using one
			&TexController );
		return;          
	} 


	if (g_Gamepads[0].fY1 > 0) {zTopBI+=imageMovementSpeed;  zBottomBI+=imageMovementSpeed; }// Up
	if (g_Gamepads[0].fY1 < 0) {zTopBI-=imageMovementSpeed;  zBottomBI-=imageMovementSpeed; } // Down
	if (g_Gamepads[0].fX1 < 0) {zLeftBI-=imageMovementSpeed; zRightBI-=imageMovementSpeed; } // Left
	if (g_Gamepads[0].fX1 > 0) {zLeftBI+=imageMovementSpeed; zRightBI+=imageMovementSpeed; }// Right

	//if (g_Gamepads[0].fY2 > 0) { zBottomBI-=0.1f; zRightBI-=0.1f; }// Up
	//if (g_Gamepads[0].fY2 < 0) zBottomBI-=0.1f; // Down
	if (g_Gamepads[0].fY2 < 0) { 
		float w = zRightBI - zLeftBI;
		float h = zTopBI - zBottomBI;
		zRightBI-= w * imageScaleSpeed; zBottomBI+= h * imageScaleSpeed; 

	}// Left
	if (g_Gamepads[0].fY2 > 0) {
		float w = zRightBI - zLeftBI;
		float h = zTopBI - zBottomBI;
		zRightBI+=w * imageScaleSpeed; zBottomBI-=h * imageScaleSpeed; 
	}// Right

}
void controllerMenuCheck() {
	if(g_Gamepads[0].Event == XBGAMEPAD_B) {
		if(DisableMenuSounds == 0) playEffect(1);
		screenControllerOptions = 0;
		screenOptions     = 1;
		screenResize = 0;
		screenResizeP = 0;
		screenResizeI = 0;
		screenResizePB = 0;

		screenResizeJ = 0;
		screenResizeG = 0;
		screenResizeB = 0;
		screenResizeA = 0;
		screenResizeA2 = 0;
		screenOptionsM = 0;
		screenOptionsHelp = 0;
		screenResizeS = 0;
		writeConfig();
		controllerMode = 0;
		return;  
	}

	if (g_Gamepads[0].Event == XBGAMEPAD_DPAD_DOWN)  {  
		if(DisableMenuSounds == 0) playEffect(0);	
		controllerMenu++; 
		if(inGame == 1) {
			if(controllerMenu >12) controllerMenu = 0;
		}
		else {
			if(controllerMenu >10) controllerMenu = 0;
		}
	}  

	if (g_Gamepads[0].Event == XBGAMEPAD_DPAD_UP)  {  
		if(DisableMenuSounds == 0) playEffect(0);	

		if(inGame == 1) {
			controllerMenu--; if(controllerMenu < 0) controllerMenu = 12; 
		}
		else {
			controllerMenu--; if(controllerMenu < 0) controllerMenu = 10; 
		}
	}

	if(g_Gamepads[0].Event == XBGAMEPAD_A) {
		if(DisableMenuSounds == 0) playEffect(2);
		if(controllerMenu == 0) { //button configuration
			controllerMode = 2;
		}


		if(controllerMenu == 1) {//turbo
			controllerMode = 1;   
		}

		if(controllerMenu == 2) {
			controllerType++; if(controllerType > 2) { controllerType = 0;  }

			if(controllerType == 0) snesmouse = controllerType;
			if(controllerType == 1) snesmouse = controllerType;
			if(controllerType == 2) snesmouse = 3;
		}

		if(controllerMenu == 3) {
			mouseDist++; if(mouseDist > 10) mouseDist = 1;
		}


		if(controllerMenu == 4 && inGame == 1) {
			controllerMode = 4;
			buildRumbleList();
		}

		if(controllerMenu == 5 && inGame == 1) {
			controllerMode = 3;
		}
		if(controllerMenu == 6 && inGame == 1) {
			lightGun = 1;
			m_dwNumBulletHoles = 0;
			//StartLightGun();
			return;
		}

		if(controllerMenu == 7 && inGame == 1) {
			if(lightGunMode == 0)
				lightGunMode = 1;
			else
				lightGunMode = 0;
			return;
		}

		if(controllerMenu == 8 && inGame == 1) {
			if(supressCursor == 0)
				supressCursor = 1;
			else
				supressCursor = 0;
			return;
		}
		if(controllerMenu == 9 && inGame == 1) {
			if(lgRumble == 0)
				lgRumble = 1;
			else
				lgRumble = 0;
			return;
		}

		if(controllerMenu == 10 && inGame == 1) {
			leftRumblelg++;
			if(leftRumblelg > 255)
				leftRumblelg = 0;
			return;
		}
		if(controllerMenu == 11 && inGame == 1) {
			rightRumblelg++;
			if(rightRumblelg > 255)
				rightRumblelg = 0;
			return;
		}
		if(controllerMenu == 12 && inGame == 1) {
			timeRumblelg+=0.01;
			if(timeRumblelg > 1)
				timeRumblelg = 0.01;
			return;
		}



		if(controllerMenu == 4 && inGame == 0) {
			lightGun = 1;
			m_dwNumBulletHoles = 0;
			//StartLightGun();
			return;
		}

		if(controllerMenu == 5 && inGame == 0) {
			if(lightGunMode == 0)
				lightGunMode = 1;
			else
				lightGunMode = 0;
			return;
		}
		if(controllerMenu == 6 && inGame == 0) {
			if(supressCursor == 0)
				supressCursor = 1;
			else
				supressCursor = 0;
			return;
		}
		if(controllerMenu == 7 && inGame == 0) {
			if(lgRumble == 0)
				lgRumble = 1;
			else
				lgRumble = 0;
			return;
		}
		if(controllerMenu == 8 && inGame == 0) {
			leftRumblelg++;
			if(leftRumblelg > 255)
				leftRumblelg = 0;
			return;
		}
		if(controllerMenu == 9 && inGame == 0) {
			rightRumblelg++;
			if(rightRumblelg > 255)
				rightRumblelg = 0;
			return;
		}
		if(controllerMenu == 10 && inGame == 0) {
			timeRumblelg+=0.01;
			if(timeRumblelg > 1)
				timeRumblelg = 0.01;
			return;
		}



	} 

	if(g_Gamepads[0].Event == XBGAMEPAD_X) {
		if(DisableMenuSounds == 0) playEffect(2);

		if(controllerMenu == 2) {
			controllerType--; if(controllerType < 0) { controllerType = 2;  }

			if(controllerType == 0) snesmouse = controllerType;
			if(controllerType == 1) snesmouse = controllerType;
			if(controllerType == 2) snesmouse = 3;
		}

		if(controllerMenu == 3) {
			mouseDist--; if(mouseDist < 1) mouseDist = 10;
		}

		if(controllerMenu == 10 && inGame == 1) {
			leftRumblelg--;
			if(leftRumblelg < 0)
				leftRumblelg = 255;
			return;
		}
		if(controllerMenu == 11 && inGame == 1) {
			rightRumblelg--;
			if(rightRumblelg < 0)
				rightRumblelg = 255;
			return;
		}
		if(controllerMenu == 12 && inGame == 1) {
			timeRumblelg-=0.01;
			if(timeRumblelg < 0)
				timeRumblelg = 1;
			return;
		}


		if(controllerMenu == 8 && inGame == 0) {
			leftRumblelg--;
			if(leftRumblelg < 0)
				leftRumblelg = 255;
			return;
		}
		if(controllerMenu == 9 && inGame == 0) {
			rightRumblelg--;
			if(rightRumblelg < 0)
				rightRumblelg = 255;
			return;
		}
		if(controllerMenu == 10 && inGame == 0) {
			timeRumblelg-=0.01;
			if(timeRumblelg < 0)
				timeRumblelg = 1;
			return;
		}
	} 
}

void checkControllerConfig() {

	if(rumbleDatabasePick == 1) {
		if(g_Gamepads[0].Event == XBGAMEPAD_B) {
			if(DisableMenuSounds == 0) playEffect(1);
			rumbleDatabasePick = 0;
			controllerMode = 4;
			return;          
		} 

		if(g_Gamepads[0].Event == XBGAMEPAD_Y) {
			if(DisableMenuSounds == 0) playEffect(1);

			rumbleList.clear(); 
			for(int i = 0; i < 10; i++) { 
				rumbleSetting r; 
				r.isActive = false; 
				r.address = 0; 
				r.bank = 0; 
				r.rumbleType = 0; 
				r.currentValue = 0; 
				r.previousValue = 0; 
				r.description = "No Description Found" ;
				r.motorOneStrength = 0; 
				r.motorTwoStrength = 0; 
				r.motorOneTime = 0; 
				r.motorTwoTime = 0; 
				r.controller = 0; 
				r.rumbleCount = 0; 
				r.rumbleTarget = 0;
				rumbleList.push_back(r); 
			} 
			rumbleOneInProgress = false;
			rumbleTwoInProgress = false;
			leftRumble = 0;
			rightRumble = 0;
			resetMotorOneRumbleTimer();
			resetMotorTwoRumbleTimer();

			FILE* f = fopen(rumbleDatabase[rumbleGameSelected].path.c_str() , "r");
			if(!f) {
				return;
			}

			for(int i = 0; i < 10; i++) {
				char a[100]; for(int t = 0; t < 100; t++) a[t] = '\0'; fgets(a, 100, f);
				rumbleList[i].isActive = (bool)atoi(a);

				char b[100]; for(int t = 0; t < 100; t++) b[t] = '\0'; fgets(b, 100, f);
				rumbleList[i].address  = (unsigned short) atoi(b);

				char c[100]; for(int t = 0; t < 100; t++) c[t] = '\0'; fgets(c, 100, f);
				rumbleList[i].bank = (unsigned char)atoi(c);

				char d[100]; for(int t = 0; t < 100; t++) d[t] = '\0'; fgets(d, 100, f);
				rumbleList[i].rumbleType  = atoi(d);

				char e[100];
				for(int t = 0; t < 100; t++) e[t] = '\0';
				fgets(e, 100, f);
				for(int q = 0; q < 100; q++) 
					if(e[q] == '\n') e[q] = '\0';
				rumbleList[i].description = e;

				char g[100]; for(int t = 0; t < 100; t++) g[t] = '\0'; fgets(g, 100, f);
				rumbleList[i].motorOneStrength  = atoi(g);

				char h[100]; for(int t = 0; t < 100; t++) h[t] = '\0'; fgets(h, 100, f);
				rumbleList[i].motorTwoStrength  = atoi(h);

				char j[100]; for(int t = 0; t < 100; t++) j[t] = '\0'; fgets(j, 100, f);
				rumbleList[i].motorOneTime  = (float) atof(j);

				char k[100]; for(int t = 0; t < 100; t++) k[t] = '\0'; fgets(k, 100, f);
				rumbleList[i].motorTwoTime  = (float) atof(k);

				char m[100]; for(int t = 0; t < 100; t++) m[t] = '\0'; fgets(m, 100, f);
				rumbleList[i].controller  = atoi(m);

				char m3[100]; for(int t = 0; t < 100; t++) m3[t] = '\0'; fgets(m3, 100, f);
				rumbleList[i].rumbleTarget  = atoi(m3);
			}
			fclose(f);

			SaveRumbleFile("");
			rumbleDatabasePick = 0;
			controllerMode = 4;
			buildRumbleList();
		}

		return;
	}

	if(rumbleDatabaseDelete == 1) {
		if(g_Gamepads[0].Event == XBGAMEPAD_B) {
			if(DisableMenuSounds == 0) playEffect(1);
			rumbleDatabaseDelete = 0;
			controllerMode = 4;
			return;          
		} 

		if(g_Gamepads[0].Event == XBGAMEPAD_Y) {
			if(DisableMenuSounds == 0) playEffect(1);

			std::string a = GARBAGE_PATH;//
			std::string newName = a + rumbleDatabase[rumbleGameSelected].name.c_str();
			newName += ".rmb";
			int r = MoveFileEx(rumbleDatabase[rumbleGameSelected].path.c_str(),  newName.c_str(), MOVEFILE_COPY_ALLOWED);
			rumbleDatabaseDelete = 0;
			controllerMode = 4;
			buildRumbleList();
			return;
		}
		return;
	}

	if(pickRumbleSlot == 1) {
		if(g_Gamepads[0].Event == XBGAMEPAD_B) {
			if(DisableMenuSounds == 0) playEffect(1);
			pickRumbleSlot = 0;
			return;          
		} 

		if(g_Gamepads[0].Event == XBGAMEPAD_Y) {
			if(DisableMenuSounds == 0) playEffect(1);
			pickRumbleSlot = 0;
			unsigned short address  = (csCodes[rumbleSlot][2] << 12) | (csCodes[rumbleSlot][3] << 8) | (csCodes[rumbleSlot][4] << 4) | (csCodes[rumbleSlot][5]);
			unsigned char  bank     = (csCodes[rumbleSlot][0] << 4)  |  csCodes[rumbleSlot][1];
			rumbleList[controllerRumbleMenu].address = address ;
			rumbleList[controllerRumbleMenu].bank = bank;

			int buffer[27];
			for(int i = 0; i < 27; i++) {
				buffer[i] = csCodes[rumbleSlot][8+1+i];
			}
			fixBuffer(buffer);
			rumbleList[controllerRumbleMenu].description = cbuffer;
		}
		//Update the rumble vector with the new choice of address/bank/banksize
		if(g_Gamepads[0].Event == XBGAMEPAD_A) {
			if(DisableMenuSounds == 0) playEffect(2);
			// if(controllerRumblePickMenu == 0) {rumbleType++; if(rumbleType > 2) rumbleType = 0; }
			rumbleSlot++;
			if(rumbleSlot > 14)
				rumbleSlot = 0; 
			return;
		}

		if(g_Gamepads[0].Event == XBGAMEPAD_X) {
			if(DisableMenuSounds == 0) playEffect(2);
			// if(controllerRumblePickMenu == 0) {rumbleType--; if(rumbleType < 0) rumbleType = 2; }
			rumbleSlot--;
			if(rumbleSlot < 0) 
				rumbleSlot = 14; 
			return;
		}

		return;
	}

	if(displayRumbleConfig == 1) {
		if(g_Gamepads[0].Event == XBGAMEPAD_B) {
			if(DisableMenuSounds == 0) playEffect(1);
			displayRumbleConfig = 0;
			//Save the rumble file
			std::stringstream a;
			a << gameCRC;
			std::string cSum;
			a >> cSum;
			SaveRumbleFile(cSum);
			return;          
		} 

		if (g_Gamepads[0].fY2 > 0) {
			//  if(controllerRumbleConfigMenu == 0) {if(rumbleList[controllerRumbleMenu].isActive) rumbleList[controllerRumbleMenu].isActive = false; else rumbleList[controllerRumbleMenu].isActive = true; }
			//   if(controllerRumbleConfigMenu == 1) {rumbleList[controllerRumbleMenu].controller++; if(rumbleList[controllerRumbleMenu].controller > 3) rumbleList[controllerRumbleMenu].controller = 0; }
			//   if(controllerRumbleConfigMenu == 2) {rumbleList[controllerRumbleMenu].rumbleType++; if(rumbleList[controllerRumbleMenu].rumbleType > 2) rumbleList[controllerRumbleMenu].rumbleType = 0; }
			if(controllerRumbleConfigMenu == 3) {rumbleList[controllerRumbleMenu].motorOneStrength++; if(rumbleList[controllerRumbleMenu].motorOneStrength > 255) rumbleList[controllerRumbleMenu].motorOneStrength = 0; }
			if(controllerRumbleConfigMenu == 4) {rumbleList[controllerRumbleMenu].motorOneTime+=0.01f; if(rumbleList[controllerRumbleMenu].motorOneTime > 10.0f) rumbleList[controllerRumbleMenu].motorOneTime = 0;}
			if(controllerRumbleConfigMenu == 5) {rumbleList[controllerRumbleMenu].motorTwoStrength++; if(rumbleList[controllerRumbleMenu].motorTwoStrength > 255) rumbleList[controllerRumbleMenu].motorTwoStrength = 0; }
			if(controllerRumbleConfigMenu == 6) {rumbleList[controllerRumbleMenu].motorTwoTime+=0.01f; if(rumbleList[controllerRumbleMenu].motorTwoTime > 10.0f) rumbleList[controllerRumbleMenu].motorTwoTime = 0;}
			//  if(controllerRumbleConfigMenu == 7) {rumbleList[controllerRumbleMenu].rumbleTarget++; if(rumbleList[controllerRumbleMenu].rumbleTarget > 15) rumbleList[controllerRumbleMenu].rumbleTarget = 0; }

		}// Up


		if (g_Gamepads[0].fY2 < 0) {
			//   if(controllerRumbleConfigMenu == 0) {if(rumbleList[controllerRumbleMenu].isActive) rumbleList[controllerRumbleMenu].isActive = false; else rumbleList[controllerRumbleMenu].isActive = true; }
			//	   if(controllerRumbleConfigMenu == 1) {rumbleList[controllerRumbleMenu].controller--; if(rumbleList[controllerRumbleMenu].controller < 0) rumbleList[controllerRumbleMenu].controller = 3; }
			//	   if(controllerRumbleConfigMenu == 2) {rumbleList[controllerRumbleMenu].rumbleType--; if(rumbleList[controllerRumbleMenu].rumbleType < 0) rumbleList[controllerRumbleMenu].rumbleType = 2; }
			if(controllerRumbleConfigMenu == 3) {rumbleList[controllerRumbleMenu].motorOneStrength--; if(rumbleList[controllerRumbleMenu].motorOneStrength < 0) rumbleList[controllerRumbleMenu].motorOneStrength = 255; }
			if(controllerRumbleConfigMenu == 4) {rumbleList[controllerRumbleMenu].motorOneTime-=0.01f; if(rumbleList[controllerRumbleMenu].motorOneTime < 0) rumbleList[controllerRumbleMenu].motorOneTime = 10.0f;}
			if(controllerRumbleConfigMenu == 5) {rumbleList[controllerRumbleMenu].motorTwoStrength--; if(rumbleList[controllerRumbleMenu].motorTwoStrength < 0) rumbleList[controllerRumbleMenu].motorTwoStrength = 255; }
			if(controllerRumbleConfigMenu == 6) {rumbleList[controllerRumbleMenu].motorTwoTime-=0.01f; if(rumbleList[controllerRumbleMenu].motorTwoTime < 0) rumbleList[controllerRumbleMenu].motorTwoTime = 10.0f;}
			//    if(controllerRumbleConfigMenu == 7) {rumbleList[controllerRumbleMenu].rumbleTarget--; if(rumbleList[controllerRumbleMenu].rumbleTarget < 0) rumbleList[controllerRumbleMenu].rumbleTarget = 15; }
			//   if(controllerRumbleConfigMenu == 8) {pickRumbleSlot = 1;  controllerRumblePickMenu = 0;}


		} // Down

		if (g_Gamepads[0].Event == XBGAMEPAD_DPAD_DOWN)  {  
			if(DisableMenuSounds == 0) playEffect(0);	
			controllerRumbleConfigMenu++; 
			if(controllerRumbleConfigMenu > 10) controllerRumbleConfigMenu = 0;
		}  

		if (g_Gamepads[0].Event == XBGAMEPAD_DPAD_UP)  {  
			if(DisableMenuSounds == 0) playEffect(0);	
			controllerRumbleConfigMenu--; 
			if(controllerRumbleConfigMenu < 0) controllerRumbleConfigMenu = 10;
		}  

		if(g_Gamepads[0].Event == XBGAMEPAD_A) {
			if(DisableMenuSounds == 0) playEffect(2);
			if(controllerRumbleConfigMenu == 0) {
				if(rumbleList[controllerRumbleMenu].isActive) 
					rumbleList[controllerRumbleMenu].isActive = false; 
				else 
					rumbleList[controllerRumbleMenu].isActive = true;
			}
			if(controllerRumbleConfigMenu == 1) {rumbleList[controllerRumbleMenu].controller++; if(rumbleList[controllerRumbleMenu].controller > 3) rumbleList[controllerRumbleMenu].controller = 0; }
			if(controllerRumbleConfigMenu == 2) {rumbleList[controllerRumbleMenu].rumbleType++; if(rumbleList[controllerRumbleMenu].rumbleType > 11) rumbleList[controllerRumbleMenu].rumbleType = 0; }
			if(controllerRumbleConfigMenu == 3) {rumbleList[controllerRumbleMenu].motorOneStrength++; if(rumbleList[controllerRumbleMenu].motorOneStrength > 255) rumbleList[controllerRumbleMenu].motorOneStrength = 0; }
			if(controllerRumbleConfigMenu == 4) {rumbleList[controllerRumbleMenu].motorOneTime+=0.01f; if(rumbleList[controllerRumbleMenu].motorOneTime > 10.0f) rumbleList[controllerRumbleMenu].motorOneTime = 0;}
			if(controllerRumbleConfigMenu == 5) {rumbleList[controllerRumbleMenu].motorTwoStrength++; if(rumbleList[controllerRumbleMenu].motorTwoStrength > 255) rumbleList[controllerRumbleMenu].motorTwoStrength = 0; }
			if(controllerRumbleConfigMenu == 6) {rumbleList[controllerRumbleMenu].motorTwoTime+=0.01f; if(rumbleList[controllerRumbleMenu].motorTwoTime > 10.0f) rumbleList[controllerRumbleMenu].motorTwoTime = 0;}
			if(controllerRumbleConfigMenu == 7) {rumbleList[controllerRumbleMenu].rumbleTarget++; if(rumbleList[controllerRumbleMenu].rumbleTarget > 15) rumbleList[controllerRumbleMenu].rumbleTarget = 0; }

			if(controllerRumbleConfigMenu == 8) {pickRumbleSlot = 1;  controllerRumblePickMenu = 0;}
			if(controllerRumbleConfigMenu == 9) { 
				keyBoardDisplay = 1;
				initKeyboard();
				resetKeyBoard();
				keyBoardDraw  = 1; 
			}


			if(controllerRumbleConfigMenu == 10) { StartRumble(controllerRumbleMenu); }
		}

		if(g_Gamepads[0].Event == XBGAMEPAD_X) {
			if(DisableMenuSounds == 0) playEffect(2);
			if(controllerRumbleConfigMenu == 0) {if(rumbleList[controllerRumbleMenu].isActive) rumbleList[controllerRumbleMenu].isActive = false; else rumbleList[controllerRumbleMenu].isActive = true; }
			if(controllerRumbleConfigMenu == 1) {rumbleList[controllerRumbleMenu].controller--; if(rumbleList[controllerRumbleMenu].controller < 0) rumbleList[controllerRumbleMenu].controller = 3; }
			if(controllerRumbleConfigMenu == 2) {rumbleList[controllerRumbleMenu].rumbleType--; if(rumbleList[controllerRumbleMenu].rumbleType < 0) rumbleList[controllerRumbleMenu].rumbleType = 11; }
			if(controllerRumbleConfigMenu == 3) {rumbleList[controllerRumbleMenu].motorOneStrength--; if(rumbleList[controllerRumbleMenu].motorOneStrength < 0) rumbleList[controllerRumbleMenu].motorOneStrength = 255; }
			if(controllerRumbleConfigMenu == 4) {rumbleList[controllerRumbleMenu].motorOneTime-=0.01f; if(rumbleList[controllerRumbleMenu].motorOneTime < 0) rumbleList[controllerRumbleMenu].motorOneTime = 10.0f;}
			if(controllerRumbleConfigMenu == 5) {rumbleList[controllerRumbleMenu].motorTwoStrength--; if(rumbleList[controllerRumbleMenu].motorTwoStrength < 0) rumbleList[controllerRumbleMenu].motorTwoStrength = 255; }
			if(controllerRumbleConfigMenu == 6) {rumbleList[controllerRumbleMenu].motorTwoTime-=0.01f; if(rumbleList[controllerRumbleMenu].motorTwoTime < 0) rumbleList[controllerRumbleMenu].motorTwoTime = 10.0f;}
			if(controllerRumbleConfigMenu == 7) {rumbleList[controllerRumbleMenu].rumbleTarget--; if(rumbleList[controllerRumbleMenu].rumbleTarget < 0) rumbleList[controllerRumbleMenu].rumbleTarget = 15; }
			if(controllerRumbleConfigMenu == 8) {pickRumbleSlot = 1;  controllerRumblePickMenu = 0;}
			if(controllerRumbleConfigMenu == 9) { StartRumble(controllerRumbleMenu); }
		}

		return;
	}
	if(controllerMode == 0) {
		controllerMenuCheck();
		return;
	}

	if(controllerMode == 1) {
		controllerTurboCheck();
		return;
	}

	if(controllerMode == 3) {
		controllerRumbleCheck();
		return;
	}

	if(controllerMode == 4) {
		controllerRumbleDatabaseCheck();
		return;
	}


	if(g_Gamepads[0].Event == XBGAMEPAD_B) {
		if(DisableMenuSounds == 0) playEffect(1);
		controllerMode = 0;
		return;          
	} 

	if (g_Gamepads[0].Event == XBGAMEPAD_DPAD_DOWN)  {  
		if(DisableMenuSounds == 0) playEffect(0);	
		controllerConfigSelected++; 
	}  

	if (g_Gamepads[0].Event == XBGAMEPAD_DPAD_UP)  {  
		if(DisableMenuSounds == 0) playEffect(0);	
		controllerConfigSelected--; 
	}  


	if(controllerSelected == 0) {
		if(controllerConfigSelected > 14) controllerConfigSelected = 0;
		if(controllerConfigSelected < 0)  controllerConfigSelected = 14;     
	}
	else {
		if(controllerConfigSelected > 8) controllerConfigSelected = 0;
		if(controllerConfigSelected < 0) controllerConfigSelected = 8; 
	}

	if(g_Gamepads[0].Event == XBGAMEPAD_A) {
		if(DisableMenuSounds == 0) playEffect(2);
		if(controllerConfigSelected == 0) {   controllerSelected++; if(controllerSelected > 3) controllerSelected = 0; } 
		if(controllerConfigSelected == 1) {   B[controllerSelected].SNES_Button_A++;      if(B[controllerSelected].SNES_Button_A > 11)      B[controllerSelected].SNES_Button_A = -1;  }  
		if(controllerConfigSelected == 2) {   B[controllerSelected].SNES_Button_B++;      if(B[controllerSelected].SNES_Button_B > 11)      B[controllerSelected].SNES_Button_B = -1; } 
		if(controllerConfigSelected == 3) {   B[controllerSelected].SNES_Button_X++;      if(B[controllerSelected].SNES_Button_X > 11)      B[controllerSelected].SNES_Button_X = -1; } 
		if(controllerConfigSelected == 4) {   B[controllerSelected].SNES_Button_Y++;      if(B[controllerSelected].SNES_Button_Y > 11)      B[controllerSelected].SNES_Button_Y = -1; } 
		if(controllerConfigSelected == 5) {   B[controllerSelected].SNES_Button_Select++; if(B[controllerSelected].SNES_Button_Select > 11) B[controllerSelected].SNES_Button_Select = -1; } 
		if(controllerConfigSelected == 6) {   B[controllerSelected].SNES_Button_Start++;  if(B[controllerSelected].SNES_Button_Start > 11)  B[controllerSelected].SNES_Button_Start = -1; } 
		if(controllerConfigSelected == 7) {   B[controllerSelected].SNES_Button_Left++;   if(B[controllerSelected].SNES_Button_Left > 11)   B[controllerSelected].SNES_Button_Left = -1; } 
		if(controllerConfigSelected == 8) {   B[controllerSelected].SNES_Button_Right++;  if(B[controllerSelected].SNES_Button_Right > 11)  B[controllerSelected].SNES_Button_Right = -1; }  

		if(controllerSelected == 0) {
			if(controllerConfigSelected == 9)  {   B[controllerSelected].Button_FastForward++; if(B[controllerSelected].Button_FastForward > 11)  B[controllerSelected].Button_FastForward = -1; }
			if(controllerConfigSelected == 10) {   B[controllerSelected].Button_Rewind++;      if(B[controllerSelected].Button_Rewind > 11)       B[controllerSelected].Button_Rewind = -1; }
			if(controllerConfigSelected == 11) {   B[controllerSelected].Button_ShowFPS++;     if(B[controllerSelected].Button_ShowFPS > 11)      B[controllerSelected].Button_ShowFPS = -1; }
			if(controllerConfigSelected == 12) {   B[controllerSelected].Button_SaveState++;   if(B[controllerSelected].Button_SaveState > 11)    B[controllerSelected].Button_SaveState = -1; }
			if(controllerConfigSelected == 13) {   B[controllerSelected].Button_LoadState++;   if(B[controllerSelected].Button_LoadState > 11)    B[controllerSelected].Button_LoadState = -1; }
			if(controllerConfigSelected == 14) {   B[controllerSelected].Button_ExitGame++;    if(B[controllerSelected].Button_ExitGame > 11)     B[controllerSelected].Button_ExitGame = -1; }
		}
		controllerValueChanged(controllerSelected);
	}
} 



void drawRumbleList() {
	int yDB = 110;
	DWORD color;
	int start = 0;

	if(rumbleGameSelected > 7 && (rumbleDatabase.size() > 15)) {
		start += (rumbleGameSelected  - 7);
	}

	if((rumbleGameSelected > ((rumbleDatabase.size()-1) - 7)) && (rumbleDatabase.size() > 15)) {
		start = (rumbleDatabase.size() - 15);
	}

	for(int i = start; i <  start +15; i++) {
		if(i == rumbleDatabase.size()) return;
		if(i ==rumbleGameSelected) color = 0xffff00; else color = 0xffffff; 
		WCHAR atext2345[1024]={0};

		if(rumbleDatabase[i].rumbleFound && i != rumbleGameSelected)
			color = 0x00FF00;

		std::string t = ((rumbleDBEntry)rumbleDatabase[i]).name;
		for(int r = 0; r < 1024; r++) {
			if((t.c_str())[r] == '\0') {
				atext2345[r] = '\0';
				break;
			}
			atext2345[r] = (t.c_str())[r];
		}
		FontSetColour(color);
		FontSmallText(atext2345,sWidth/2,yDB, 600);
		yDB+=20;
	}
}
void drawTGAList() {
	int yDB = 110;
	DWORD color;
	int start = 0;

	if(TGAGameSelected > 7 && (TGADatabase.size() > 15)) {
		start += (TGAGameSelected  - 7);
	}

	if((TGAGameSelected > ((TGADatabase.size()-1) - 7)) && (TGADatabase.size() > 15)) {
		start = (TGADatabase.size() - 15);
	}

	for(int i = start; i <  start +15; i++) {
		if(i == TGADatabase.size()) return;
		if(i ==TGAGameSelected) color = 0xffff00; else color = 0xffffff; 
		WCHAR atext2345[1024]={0};

		//if(TGADatabase[i].TGAFound && i != TGAGameSelected)
		//	color = 0x00FF00;

		std::string t = ((TGADBEntry)TGADatabase[i]).name;
		for(int r = 0; r < 1024; r++) {
			if((t.c_str())[r] == '\0') {
				atext2345[r] = '\0';
				break;
			}
			atext2345[r] = (t.c_str())[r];
		}
		FontSetColour(color);
		FontSmallText(atext2345,sWidth/2,yDB, 600);
		yDB+=20;
	}
}



void drawControllerMenu() {

	if(rumbleDatabasePick == 1) {
		drawC_Count = 0;
		yO = 110;


		WCHAR text2345q[280]={0};
		wsprintfW(text2345q,L"This will replace the current rumble settings with the");
		FontSetColour(0xffff00);
		FontSmallText(text2345q,sWidth/2,90, 600);	

		WCHAR text2345qq[280]={0};
		wsprintfW(text2345qq,L"ones from the selected game.");
		FontSetColour(0xffff00);
		FontSmallText(text2345qq,sWidth/2,110, 600);	


		WCHAR text2345[280]={0};
		wsprintfW(text2345,L"Press \"B\" to cancel or press \"Y\" to confirm.");
		FontSetColour(0xffff00);
		FontSmallText(text2345,sWidth/2,230, 600);	

		return;

	}

	if(rumbleDatabaseDelete == 1) {
		drawC_Count = 0;
		yO = 110;


		WCHAR text2345q[280]={0};
		wsprintfW(text2345q,L"Delete force feedback file?");
		FontSetColour(0xffff00);
		FontSmallText(text2345q,sWidth/2,90, 600);	

		WCHAR text2345[280]={0};
		wsprintfW(text2345,L"Press \"B\" to cancel or press \"Y\" to confirm.");
		FontSetColour(0xffff00);
		FontSmallText(text2345,sWidth/2,230, 600);	

		return;

	}


	if(pickRumbleSlot == 1) {
		drawC_Count = 0;
		yO = 110;
		WCHAR text2345[280]={0};
		wsprintfW(text2345,L"Press \"B\" to cancel or press \"Y\" to confirm selection.");
		//wsprintfW(text2345,L"Press \"B\" to cancel.");
		FontSetColour(0xffff00);
		FontSmallText(text2345,sWidth/2,70, 600);	




		drawRumblePick();


		/*WCHAR text2345o[280]={0};
		wsprintfW(text2345o,L"Press \"Y\" to confirm the change.");
		FontSetColour(0xffff00);
		FontSmallText(text2345o,250,(480-90), 600);	*/


		return;

	}


	if(displayRumbleConfig == 1) {
		drawC_Count = 0;

		yO = 110;
		/*WCHAR text2345[280]={0};
		wsprintfW(text2345,L"Press \"B\" to exit.");
		FontSetColour(0xffff00);
		FontSmallText(text2345,sWidth/2,70, 600);	*/

		drawRumbleConfig();

		if(rumbleOneInProgress || rumbleTwoInProgress) {
			ProcessRumble();
		}

		return;
	}
	if(controllerMode == 0) {
		/*	WCHAR text2345[280]={0};
		wsprintfW(text2345,L"Press \"B\" to exit.");
		FontSetColour(0xffff00);
		FontSmallText(text2345,sWidth/2,70, 600);	
		*/
		DWORD color = 0xffffff;
		if(controllerMenu == 0) color = menuColor[MenuOptionSelected]; else color = menuColor[MenuOption]; 
		WCHAR atext2345[280]={0};
		wsprintfW(atext2345,L"Button Configuration");
		FontSetColour(color);
		FontCenteredText(atext2345,640/2+zLeftCO,150+zTopCO, 600);

		if(controllerMenu == 1) color = menuColor[MenuOptionSelected]; else color = menuColor[MenuOption];
		WCHAR datext2345[280]={0};
		wsprintfW(datext2345,L"Turbo Settings");
		FontSetColour(color);
		FontCenteredText(datext2345,640/2+zLeftCO,170+zTopCO, 600);

		if(controllerMenu == 2) color = menuColor[MenuOptionSelected]; else color = menuColor[MenuOption];


		if(controllerType == 0) {
			WCHAR wdatext2345[280]={0};
			wsprintfW(wdatext2345,L"Controller Type: Joypad");
			FontSetColour(color);
			FontCenteredText(wdatext2345,640/2+zLeftCO,190+zTopCO, 600);
		}
		if(controllerType == 1) {
			WCHAR wdatext2345[280]={0};
			wsprintfW(wdatext2345,L"Controller Type: Mouse Port 1");
			FontSetColour(color);
			FontCenteredText(wdatext2345,640/2+zLeftCO,190+zTopCO, 600);
		}
		if(controllerType == 2) {
			WCHAR wdatext2345[280]={0};
			wsprintfW(wdatext2345,L"Controller Type: Super Scope");
			FontSetColour(color);
			FontCenteredText(wdatext2345,640/2+zLeftCO,190+zTopCO, 600);

			//WCHAR wdatext2345[280]={0};
			//wsprintfW(wdatext2345,L"Controller Type: Mouse Port 2");
			//FontSetColour(color);
			//FontCenteredText(wdatext2345,640/2+zLeftCO,190+zTopCO, 600);
		}

		if(controllerMenu == 3) color = menuColor[MenuOptionSelected]; else color = menuColor[MenuOption];
		if(mouseDist == 1) {
			WCHAR wdatext2345[280]={0};
			wsprintfW(wdatext2345,L"Super Scope/Mouse Speed: 1");
			FontSetColour(color);
			FontCenteredText(wdatext2345,640/2+zLeftCO,210+zTopCO, 600);
		}
		if(mouseDist == 2) {
			WCHAR wdatext2345[280]={0};
			wsprintfW(wdatext2345,L"Super Scope/Mouse Speed: 2");
			FontSetColour(color);
			FontCenteredText(wdatext2345,640/2+zLeftCO,210+zTopCO, 600);
		}
		if(mouseDist == 3) {
			WCHAR wdatext2345[280]={0};
			wsprintfW(wdatext2345,L"Super Scope/Mouse Speed: 3");
			FontSetColour(color);
			FontCenteredText(wdatext2345,640/2+zLeftCO,210+zTopCO, 600);
		}
		if(mouseDist == 4) {
			WCHAR wdatext2345[280]={0};
			wsprintfW(wdatext2345,L"Super Scope/Mouse Speed: 4");
			FontSetColour(color);
			FontCenteredText(wdatext2345,640/2+zLeftCO,210+zTopCO, 600);
		}
		if(mouseDist == 5) {
			WCHAR wdatext2345[280]={0};
			wsprintfW(wdatext2345,L"Super Scope/Mouse Speed: 5");
			FontSetColour(color);
			FontCenteredText(wdatext2345,640/2+zLeftCO,210+zTopCO, 600);
		}
		if(mouseDist == 6) {
			WCHAR wdatext2345[280]={0};
			wsprintfW(wdatext2345,L"Super Scope/Mouse Speed: 6");
			FontSetColour(color);
			FontCenteredText(wdatext2345,640/2+zLeftCO,210+zTopCO, 600);
		}
		if(mouseDist == 7) {
			WCHAR wdatext2345[280]={0};
			wsprintfW(wdatext2345,L"Super Scope/Mouse Speed: 7");
			FontSetColour(color);
			FontCenteredText(wdatext2345,640/2+zLeftCO,210+zTopCO, 600);
		}
		if(mouseDist == 8) {
			WCHAR wdatext2345[280]={0};
			wsprintfW(wdatext2345,L"Super Scope/Mouse Speed: 8");
			FontSetColour(color);
			FontCenteredText(wdatext2345,640/2+zLeftCO,210+zTopCO, 600);
		}
		if(mouseDist == 9) {
			WCHAR wdatext2345[280]={0};
			wsprintfW(wdatext2345,L"Super Scope/Mouse Speed: 9");
			FontSetColour(color);
			FontCenteredText(wdatext2345,640/2+zLeftCO,210+zTopCO, 600);
		}
		if(mouseDist == 10) {
			WCHAR wdatext2345[280]={0};
			wsprintfW(wdatext2345,L"Super Scope/Mouse Speed: 10");
			FontSetColour(color);
			FontCenteredText(wdatext2345,640/2+zLeftCO,210+zTopCO, 600);
		}


		if(inGame == 1) {
			if(controllerMenu == 4) color = menuColor[MenuOptionSelected]; else color = menuColor[MenuOption];
			WCHAR datext2345[280]={0};
			wsprintfW(datext2345,L"Force Feedback Database");
			FontSetColour(color);
			FontCenteredText(datext2345,640/2+zLeftCO,230+zTopCO, 600);

			if(controllerMenu == 5) color = menuColor[MenuOptionSelected]; else color = menuColor[MenuOption];
			WCHAR datext2345q[280]={0};
			wsprintfW(datext2345q,L"Force Feedback Configuration");
			FontSetColour(color);
			FontCenteredText(datext2345q,640/2+zLeftCO,250+zTopCO, 600);

			if(controllerMenu == 6) color = menuColor[MenuOptionSelected]; else color = menuColor[MenuOption];
			WCHAR jdatext2345[280]={0};
			wsprintfW(jdatext2345,L"Light Gun Configuration");
			FontSetColour(color);
			FontCenteredText(jdatext2345,640/2+zLeftCO,270+zTopCO, 600);

			if(controllerMenu == 7) color = menuColor[MenuOptionSelected]; else color = menuColor[MenuOption];
			if(lightGunMode == 0) {
				WCHAR wdatext2345[280]={0};
				wsprintfW(wdatext2345,L"Super Scope Control: Xbox Gamepad");
				FontSetColour(color);
				FontCenteredText(wdatext2345,640/2+zLeftCO,290+zTopCO, 600);	
			}
			else  {
				WCHAR wdatext2345[280]={0};
				wsprintfW(wdatext2345,L"Super Scope Control: Xbox Lightgun");
				FontSetColour(color);
				FontCenteredText(wdatext2345,640/2+zLeftCO,290+zTopCO, 600);
			}

			if(controllerMenu == 8) color = menuColor[MenuOptionSelected]; else color = menuColor[MenuOption];
			if(supressCursor == 0) {
				WCHAR wdatext2345[280]={0};
				wsprintfW(wdatext2345,L"Lightgun Crosshair: On");
				FontSetColour(color);
				FontCenteredText(wdatext2345,640/2+zLeftCO,310+zTopCO, 600);	
			}
			else  {
				WCHAR wdatext2345[280]={0};
				wsprintfW(wdatext2345,L"Lightgun Crosshair: Off");
				FontSetColour(color);
				FontCenteredText(wdatext2345,640/2+zLeftCO,310+zTopCO, 600);
			}
			if(controllerMenu == 9) color = menuColor[MenuOptionSelected]; else color = menuColor[MenuOption];
			if(lgRumble== 0) {
				WCHAR wdatext2345[280]={0};
				wsprintfW(wdatext2345,L"Lightgun Force Feedback: Off");
				FontSetColour(color);
				FontCenteredText(wdatext2345,640/2+zLeftCO,330+zTopCO, 600);	
			}
			else  {
				WCHAR wdatext2345[280]={0};
				wsprintfW(wdatext2345,L"Lightgun Force Feedback: On");
				FontSetColour(color);
				FontCenteredText(wdatext2345,640/2+zLeftCO,330+zTopCO, 600);
			}




			if(controllerMenu == 10) color = menuColor[MenuOptionSelected]; else color = menuColor[MenuOption];
			std::ostringstream ddrq0;
			ddrq0 << leftRumblelg;
			std::string ddrw0 = ddrq0.str();
			std::string text = "Lightgun Motor One Strength: ";
			text += ddrw0.c_str();
			WCHAR text23456789[80]={0};
			for(int i = 0; i < 1000; i++) {
				if(text[i] == '\0') {
					text23456789[i] = '\0';
					break;
				}
				text23456789[i] = text[i];
			}
			FontSetColour(color);
			FontCenteredText(text23456789,640/2+zLeftCO,350+zTopCO, 600);



			if(controllerMenu == 11) color = menuColor[MenuOptionSelected]; else color = menuColor[MenuOption];
			std::ostringstream fddrq0;
			fddrq0 << rightRumblelg;
			std::string fddrw0 = fddrq0.str();
			text = "Lightgun Motor Two Strength: ";
			text += fddrw0.c_str();
			WCHAR atext23456789[80]={0};
			for(int i = 0; i < 1000; i++) {
				if(text[i] == '\0') {
					atext23456789[i] = '\0';
					break;
				}
				atext23456789[i] = text[i];
			}
			FontSetColour(color);
			FontCenteredText(atext23456789,640/2+zLeftCO,370+zTopCO, 600);



			if(controllerMenu == 12) color = menuColor[MenuOptionSelected]; else color = menuColor[MenuOption];
			std::ostringstream gddrq0;
			gddrq0 << timeRumblelg;
			std::string gddrw0 = gddrq0.str();
			text = "Lightgun Rumble Time: ";
			text += gddrw0.c_str();
			WCHAR satext23456789[80]={0};
			for(int i = 0; i < 1000; i++) {
				if(text[i] == '\0') {
					satext23456789[i] = '\0';
					break;
				}
				satext23456789[i] = text[i];
			}
			FontSetColour(color);
			FontCenteredText(satext23456789,640/2+zLeftCO,390+zTopCO, 600);



		}
		else {
			if(controllerMenu == 4) color = menuColor[MenuOptionSelected]; else color = menuColor[MenuOption];
			WCHAR jdatext2345[280]={0};
			wsprintfW(jdatext2345,L"Light Gun Configuration");
			FontSetColour(color);
			FontCenteredText(jdatext2345,640/2+zLeftCO,230+zTopCO, 600);

			if(controllerMenu == 5) color = menuColor[MenuOptionSelected]; else color = menuColor[MenuOption];
			if(lightGunMode == 0) {
				WCHAR wdatext2345[280]={0};
				wsprintfW(wdatext2345,L"Super Scope Control: Xbox Gamepad");
				FontSetColour(color);
				FontCenteredText(wdatext2345,640/2+zLeftCO,250+zTopCO, 600);	
			}
			else  {
				WCHAR wdatext2345[280]={0};
				wsprintfW(wdatext2345,L"Super Scope Control: Xbox Lightgun");
				FontSetColour(color);
				FontCenteredText(wdatext2345,640/2+zLeftCO,250+zTopCO, 600);
			}
			if(controllerMenu == 6) color = menuColor[MenuOptionSelected]; else color = menuColor[MenuOption];
			if(supressCursor == 0) {
				WCHAR wdatext2345[280]={0};
				wsprintfW(wdatext2345,L"Lightgun Crosshair: On");
				FontSetColour(color);
				FontCenteredText(wdatext2345,640/2+zLeftCO,270+zTopCO, 600);	
			}
			else  {
				WCHAR wdatext2345[280]={0};
				wsprintfW(wdatext2345,L"Lightgun Crosshair: Off");
				FontSetColour(color);
				FontCenteredText(wdatext2345,640/2+zLeftCO,270+zTopCO, 600);
			}

			if(controllerMenu == 7) color = menuColor[MenuOptionSelected]; else color = menuColor[MenuOption];
			if(lgRumble== 0) {
				WCHAR wdatext2345[280]={0};
				wsprintfW(wdatext2345,L"Lightgun Force Feedback: Off");
				FontSetColour(color);
				FontCenteredText(wdatext2345,640/2+zLeftCO,290+zTopCO, 600);	
			}
			else  {
				WCHAR wdatext2345[280]={0};
				wsprintfW(wdatext2345,L"Lightgun Force Feedback: On");
				FontSetColour(color);
				FontCenteredText(wdatext2345,640/2+zLeftCO,290+zTopCO, 600);
			}
			if(controllerMenu == 8) color = menuColor[MenuOptionSelected]; else color = menuColor[MenuOption];
			std::ostringstream ddrq0;
			ddrq0 << leftRumblelg;
			std::string ddrw0 = ddrq0.str();
			std::string text = "Lightgun Motor One Strength: ";
			text += ddrw0.c_str();
			WCHAR text23456789[80]={0};
			for(int i = 0; i < 1000; i++) {
				if(text[i] == '\0') {
					text23456789[i] = '\0';
					break;
				}
				text23456789[i] = text[i];
			}
			FontSetColour(color);
			FontCenteredText(text23456789,640/2+zLeftCO,310+zTopCO, 600);



			if(controllerMenu ==9) color = menuColor[MenuOptionSelected]; else color = menuColor[MenuOption];
			std::ostringstream fddrq0;
			fddrq0 << rightRumblelg;
			std::string fddrw0 = fddrq0.str();
			text = "Lightgun Motor Two Strength: ";
			text += fddrw0.c_str();
			WCHAR atext23456789[80]={0};
			for(int i = 0; i < 1000; i++) {
				if(text[i] == '\0') {
					atext23456789[i] = '\0';
					break;
				}
				atext23456789[i] = text[i];
			}
			FontSetColour(color);
			FontCenteredText(atext23456789,640/2+zLeftCO,330+zTopCO, 600);



			if(controllerMenu == 10) color = menuColor[MenuOptionSelected]; else color = menuColor[MenuOption];
			std::ostringstream gddrq0;
			gddrq0 << timeRumblelg;
			std::string gddrw0 = gddrq0.str();
			text = "Lightgun Rumble Time: ";
			text += gddrw0.c_str();
			WCHAR satext23456789[80]={0};
			for(int i = 0; i < 1000; i++) {
				if(text[i] == '\0') {
					satext23456789[i] = '\0';
					break;
				}
				satext23456789[i] = text[i];
			}
			FontSetColour(color);
			FontCenteredText(satext23456789,640/2+zLeftCO,350+zTopCO, 600);


		}





		return;
	}

	if(controllerMode == 1) {
		drawC_Count = 0;

		yO = 110;
		/*WCHAR text2345[280]={0};
		wsprintfW(text2345,L"Press \"B\" to exit.");
		FontSetColour(0xffff00);
		FontSmallText(text2345,sWidth/2,70, 600);	*/

		drawTurboMenu();

		return;
	}

	if(controllerMode == 3) {
		drawC_Count = 0;

		yO = 110;
		/*WCHAR text2345[280]={0};
		wsprintfW(text2345,L"Press \"B\" to exit.");
		FontSetColour(0xffff00);
		FontSmallText(text2345,sWidth/2,70, 600);	*/

		drawRumbleSlotMenu();

		return;
	}

	if(controllerMode == 4) {
		drawC_Count = 0;

		yO = 110;
		/*WCHAR text2345[280]={0};
		wsprintfW(text2345,L"Press \"B\" to exit.");
		FontSetColour(0xffff00);
		FontSmallText(text2345,sWidth/2,70, 600);	*/

		drawRumbleList();

		return;
	}
	/*WCHAR text2345[280]={0};
	wsprintfW(text2345,L"Press \"B\" to exit.");
	FontSetColour(0xffff00);
	FontSmallText(text2345,260,70, 600);	*/

	drawC_Count = 0;
	yO = 120;

	if(controllerSelected == 0)  { drawCText("SNES Controller:"); drawCDText("1"); }
	if(controllerSelected == 1)  { drawCText("SNES Controller:"); drawCDText("2"); }
	if(controllerSelected == 2)  { drawCText("SNES Controller:"); drawCDText("3"); }
	if(controllerSelected == 3)  { drawCText("SNES Controller:"); drawCDText("4"); }

	if(controllers[controllerSelected].button_A == -1) {                          drawCText("SNES Button A: "); drawCDText("Not Assigned");} 
	if(controllers[controllerSelected].button_A == XINPUT_GAMEPAD_A) {             drawCText("SNES Button A: "); drawCDText("Xbox A"); }
	if(controllers[controllerSelected].button_A == XINPUT_GAMEPAD_B) {             drawCText("SNES Button A: "); drawCDText("Xbox B");}
	if(controllers[controllerSelected].button_A == XINPUT_GAMEPAD_X) {             drawCText("SNES Button A: "); drawCDText("Xbox X");}
	if(controllers[controllerSelected].button_A == XINPUT_GAMEPAD_Y) {             drawCText("SNES Button A: "); drawCDText("Xbox Y");}
	if(controllers[controllerSelected].button_A == XINPUT_GAMEPAD_BACK) {          drawCText("SNES Button A: "); drawCDText("Xbox Back");}
	if(controllers[controllerSelected].button_A == XINPUT_GAMEPAD_START) {         drawCText("SNES Button A: "); drawCDText("Xbox Start");}
	if(controllers[controllerSelected].button_A == XINPUT_GAMEPAD_WHITE) {         drawCText("SNES Button A: "); drawCDText("Xbox White");}
	if(controllers[controllerSelected].button_A == XINPUT_GAMEPAD_BLACK) {         drawCText("SNES Button A: "); drawCDText("Xbox Black");}
	if(controllers[controllerSelected].button_A == XINPUT_GAMEPAD_LEFT_TRIGGER) {  drawCText("SNES Button A: "); drawCDText("Xbox Left Trigger");}
	if(controllers[controllerSelected].button_A == XINPUT_GAMEPAD_RIGHT_TRIGGER) { drawCText("SNES Button A: "); drawCDText("Xbox Right Trigger");} 
	if(controllers[controllerSelected].button_A == XINPUT_GAMEPAD_RIGHT_THUMB) {  drawCText("SNES Button A: "); drawCDText("Xbox Right Analog Click");} 
	if(controllers[controllerSelected].button_A == XINPUT_GAMEPAD_LEFT_THUMB) {   drawCText("SNES Button A: "); drawCDText("Xbox Left Analog Click");}

	if(controllers[controllerSelected].button_B == -1) {                    drawCText("SNES Button B: "); drawCDText("Not Assigned"); } 
	if(controllers[controllerSelected].button_B == XINPUT_GAMEPAD_A) {             drawCText("SNES Button B: "); drawCDText("Xbox A"); }
	if(controllers[controllerSelected].button_B == XINPUT_GAMEPAD_B) {             drawCText("SNES Button B: "); drawCDText("Xbox B");}
	if(controllers[controllerSelected].button_B == XINPUT_GAMEPAD_X) {             drawCText("SNES Button B: "); drawCDText("Xbox X");}
	if(controllers[controllerSelected].button_B == XINPUT_GAMEPAD_Y) {             drawCText("SNES Button B: "); drawCDText("Xbox Y");}
	if(controllers[controllerSelected].button_B == XINPUT_GAMEPAD_BACK) {          drawCText("SNES Button B: "); drawCDText("Xbox Back");}
	if(controllers[controllerSelected].button_B == XINPUT_GAMEPAD_START) {         drawCText("SNES Button B: "); drawCDText("Xbox Start");}
	if(controllers[controllerSelected].button_B == XINPUT_GAMEPAD_WHITE) {         drawCText("SNES Button B: "); drawCDText("Xbox White");}
	if(controllers[controllerSelected].button_B == XINPUT_GAMEPAD_BLACK) {         drawCText("SNES Button B: "); drawCDText("Xbox Black");}
	if(controllers[controllerSelected].button_B == XINPUT_GAMEPAD_LEFT_TRIGGER) {  drawCText("SNES Button B: "); drawCDText("Xbox Left Trigger");}
	if(controllers[controllerSelected].button_B == XINPUT_GAMEPAD_RIGHT_TRIGGER) { drawCText("SNES Button B: "); drawCDText("Xbox Right Trigger");} 
	if(controllers[controllerSelected].button_B == XINPUT_GAMEPAD_RIGHT_THUMB) {  drawCText("SNES Button B: "); drawCDText("Xbox Right Analog Click");} 
	if(controllers[controllerSelected].button_B == XINPUT_GAMEPAD_LEFT_THUMB) {   drawCText("SNES Button B: "); drawCDText("Xbox Left Analog Click");}

	if(controllers[controllerSelected].button_X == -1) {                          drawCText("SNES Button X: "); drawCDText("Not Assigned"); } 
	if(controllers[controllerSelected].button_X == XINPUT_GAMEPAD_A) {             drawCText("SNES Button X: "); drawCDText("Xbox A"); }
	if(controllers[controllerSelected].button_X == XINPUT_GAMEPAD_B) {             drawCText("SNES Button X: "); drawCDText("Xbox B");}
	if(controllers[controllerSelected].button_X == XINPUT_GAMEPAD_X) {             drawCText("SNES Button X: "); drawCDText("Xbox X");}
	if(controllers[controllerSelected].button_X == XINPUT_GAMEPAD_Y) {             drawCText("SNES Button X: "); drawCDText("Xbox Y");}
	if(controllers[controllerSelected].button_X == XINPUT_GAMEPAD_BACK) {          drawCText("SNES Button X: "); drawCDText("Xbox Back");}
	if(controllers[controllerSelected].button_X == XINPUT_GAMEPAD_START) {         drawCText("SNES Button X: "); drawCDText("Xbox Start");}
	if(controllers[controllerSelected].button_X == XINPUT_GAMEPAD_WHITE) {         drawCText("SNES Button X: "); drawCDText("Xbox White");}
	if(controllers[controllerSelected].button_X == XINPUT_GAMEPAD_BLACK) {         drawCText("SNES Button X: "); drawCDText("Xbox Black");}
	if(controllers[controllerSelected].button_X == XINPUT_GAMEPAD_LEFT_TRIGGER) {  drawCText("SNES Button X: "); drawCDText("Xbox Left Trigger");}
	if(controllers[controllerSelected].button_X == XINPUT_GAMEPAD_RIGHT_TRIGGER) { drawCText("SNES Button X: "); drawCDText("Xbox Right Trigger");}
	if(controllers[controllerSelected].button_X == XINPUT_GAMEPAD_RIGHT_THUMB) {  drawCText("SNES Button X: "); drawCDText("Xbox Right Analog Click");} 
	if(controllers[controllerSelected].button_X == XINPUT_GAMEPAD_LEFT_THUMB) {   drawCText("SNES Button X: "); drawCDText("Xbox Left Analog Click");}

	if(controllers[controllerSelected].button_Y == -1) {                    drawCText("SNES Button Y: "); drawCDText("Not Assigned"); } 
	if(controllers[controllerSelected].button_Y == XINPUT_GAMEPAD_A) {             drawCText("SNES Button Y: "); drawCDText("Xbox A"); }
	if(controllers[controllerSelected].button_Y == XINPUT_GAMEPAD_B) {             drawCText("SNES Button Y: "); drawCDText("Xbox B");}
	if(controllers[controllerSelected].button_Y == XINPUT_GAMEPAD_X) {             drawCText("SNES Button Y: "); drawCDText("Xbox X");}
	if(controllers[controllerSelected].button_Y == XINPUT_GAMEPAD_Y) {             drawCText("SNES Button Y: "); drawCDText("Xbox Y");}
	if(controllers[controllerSelected].button_Y == XINPUT_GAMEPAD_BACK) {          drawCText("SNES Button Y: "); drawCDText("Xbox Back");}
	if(controllers[controllerSelected].button_Y == XINPUT_GAMEPAD_START) {         drawCText("SNES Button Y: "); drawCDText("Xbox Start");}
	if(controllers[controllerSelected].button_Y == XINPUT_GAMEPAD_WHITE) {         drawCText("SNES Button Y: "); drawCDText("Xbox White");}
	if(controllers[controllerSelected].button_Y == XINPUT_GAMEPAD_BLACK) {         drawCText("SNES Button Y: "); drawCDText("Xbox Black");}
	if(controllers[controllerSelected].button_Y == XINPUT_GAMEPAD_LEFT_TRIGGER) {  drawCText("SNES Button Y: "); drawCDText("Xbox Left Trigger");}
	if(controllers[controllerSelected].button_Y == XINPUT_GAMEPAD_RIGHT_TRIGGER) { drawCText("SNES Button Y: "); drawCDText("Xbox Right Trigger");} 
	if(controllers[controllerSelected].button_Y == XINPUT_GAMEPAD_RIGHT_THUMB) {  drawCText("SNES Button Y: "); drawCDText("Xbox Right Analog Click");} 
	if(controllers[controllerSelected].button_Y == XINPUT_GAMEPAD_LEFT_THUMB) {   drawCText("SNES Button Y: "); drawCDText("Xbox Left Analog Click");} 

	if(controllers[controllerSelected].button_Select == -1) {                    drawCText("SNES Button Select: "); drawCDText("Not Assigned"); } 
	if(controllers[controllerSelected].button_Select == XINPUT_GAMEPAD_A) {             drawCText("SNES Button Select: "); drawCDText("Xbox A"); }
	if(controllers[controllerSelected].button_Select == XINPUT_GAMEPAD_B) {             drawCText("SNES Button Select: "); drawCDText("Xbox B");}
	if(controllers[controllerSelected].button_Select == XINPUT_GAMEPAD_X) {             drawCText("SNES Button Select: "); drawCDText("Xbox X");}
	if(controllers[controllerSelected].button_Select == XINPUT_GAMEPAD_Y) {             drawCText("SNES Button Select: "); drawCDText("Xbox Y");}
	if(controllers[controllerSelected].button_Select == XINPUT_GAMEPAD_BACK) {          drawCText("SNES Button Select: "); drawCDText("Xbox Back");}
	if(controllers[controllerSelected].button_Select == XINPUT_GAMEPAD_START) {         drawCText("SNES Button Select: "); drawCDText("Xbox Start");}
	if(controllers[controllerSelected].button_Select == XINPUT_GAMEPAD_WHITE) {         drawCText("SNES Button Select: "); drawCDText("Xbox White");}
	if(controllers[controllerSelected].button_Select == XINPUT_GAMEPAD_BLACK) {         drawCText("SNES Button Select: "); drawCDText("Xbox Black");}
	if(controllers[controllerSelected].button_Select == XINPUT_GAMEPAD_LEFT_TRIGGER) {  drawCText("SNES Button Select: "); drawCDText("Xbox Left Trigger");}
	if(controllers[controllerSelected].button_Select == XINPUT_GAMEPAD_RIGHT_TRIGGER) { drawCText("SNES Button Select: "); drawCDText("Xbox Right Trigger");}  
	if(controllers[controllerSelected].button_Select == XINPUT_GAMEPAD_RIGHT_THUMB) {  drawCText("SNES Button Select: "); drawCDText("Xbox Right Analog Click");} 
	if(controllers[controllerSelected].button_Select == XINPUT_GAMEPAD_LEFT_THUMB) {   drawCText("SNES Button Select: "); drawCDText("Xbox Left Analog Click");}   

	if(controllers[controllerSelected].button_Start == -1) {                    drawCText("SNES Button Start: "); drawCDText("Not Assigned"); } 
	if(controllers[controllerSelected].button_Start == XINPUT_GAMEPAD_A) {             drawCText("SNES Button Start: "); drawCDText("Xbox A"); }
	if(controllers[controllerSelected].button_Start == XINPUT_GAMEPAD_B) {             drawCText("SNES Button Start: "); drawCDText("Xbox B");}
	if(controllers[controllerSelected].button_Start == XINPUT_GAMEPAD_X) {             drawCText("SNES Button Start: "); drawCDText("Xbox X");}
	if(controllers[controllerSelected].button_Start == XINPUT_GAMEPAD_Y) {             drawCText("SNES Button Start: "); drawCDText("Xbox Y");}
	if(controllers[controllerSelected].button_Start == XINPUT_GAMEPAD_BACK) {          drawCText("SNES Button Start: "); drawCDText("Xbox Back");}
	if(controllers[controllerSelected].button_Start == XINPUT_GAMEPAD_START) {         drawCText("SNES Button Start: "); drawCDText("Xbox Start");}
	if(controllers[controllerSelected].button_Start == XINPUT_GAMEPAD_WHITE) {         drawCText("SNES Button Start: "); drawCDText("Xbox White");}
	if(controllers[controllerSelected].button_Start == XINPUT_GAMEPAD_BLACK) {         drawCText("SNES Button Start: "); drawCDText("Xbox Black");}
	if(controllers[controllerSelected].button_Start == XINPUT_GAMEPAD_LEFT_TRIGGER) {  drawCText("SNES Button Start: "); drawCDText("Xbox Left Trigger");}
	if(controllers[controllerSelected].button_Start == XINPUT_GAMEPAD_RIGHT_TRIGGER) { drawCText("SNES Button Start: "); drawCDText("Xbox Right Trigger");} 
	if(controllers[controllerSelected].button_Start == XINPUT_GAMEPAD_RIGHT_THUMB) {  drawCText("SNES Button Start: "); drawCDText("Xbox Right Analog Click");} 
	if(controllers[controllerSelected].button_Start == XINPUT_GAMEPAD_LEFT_THUMB) {   drawCText("SNES Button Start: "); drawCDText("Xbox Left Analog Click");}

	if(controllers[controllerSelected].button_Left == -1) {                    drawCText("SNES Button Left: "); drawCDText("Not Assigned"); } 
	if(controllers[controllerSelected].button_Left == XINPUT_GAMEPAD_A) {             drawCText("SNES Button Left: "); drawCDText("Xbox A"); }
	if(controllers[controllerSelected].button_Left == XINPUT_GAMEPAD_B) {             drawCText("SNES Button Left: "); drawCDText("Xbox B");}
	if(controllers[controllerSelected].button_Left == XINPUT_GAMEPAD_X) {             drawCText("SNES Button Left: "); drawCDText("Xbox X");}
	if(controllers[controllerSelected].button_Left == XINPUT_GAMEPAD_Y) {             drawCText("SNES Button Left: "); drawCDText("Xbox Y");}
	if(controllers[controllerSelected].button_Left == XINPUT_GAMEPAD_BACK) {          drawCText("SNES Button Left: "); drawCDText("Xbox Back");}
	if(controllers[controllerSelected].button_Left == XINPUT_GAMEPAD_START) {         drawCText("SNES Button Left: "); drawCDText("Xbox Start");}
	if(controllers[controllerSelected].button_Left == XINPUT_GAMEPAD_WHITE) {         drawCText("SNES Button Left: "); drawCDText("Xbox White");}
	if(controllers[controllerSelected].button_Left == XINPUT_GAMEPAD_BLACK) {         drawCText("SNES Button Left: "); drawCDText("Xbox Black");}
	if(controllers[controllerSelected].button_Left == XINPUT_GAMEPAD_LEFT_TRIGGER) {  drawCText("SNES Button Left: "); drawCDText("Xbox Left Trigger");}
	if(controllers[controllerSelected].button_Left == XINPUT_GAMEPAD_RIGHT_TRIGGER) { drawCText("SNES Button Left: "); drawCDText("Xbox Right Trigger");}
	if(controllers[controllerSelected].button_Left == XINPUT_GAMEPAD_RIGHT_THUMB) {  drawCText("SNES Button Left: "); drawCDText("Xbox Right Analog Click");} 
	if(controllers[controllerSelected].button_Left == XINPUT_GAMEPAD_LEFT_THUMB) {   drawCText("SNES Button Left: "); drawCDText("Xbox Left Analog Click");}

	if(controllers[controllerSelected].button_Right == -1) {                    drawCText("SNES Button Right: "); drawCDText("Not Assigned"); } 
	if(controllers[controllerSelected].button_Right == XINPUT_GAMEPAD_A) {             drawCText("SNES Button Right: "); drawCDText("Xbox A"); }
	if(controllers[controllerSelected].button_Right == XINPUT_GAMEPAD_B) {             drawCText("SNES Button Right: "); drawCDText("Xbox B");}
	if(controllers[controllerSelected].button_Right == XINPUT_GAMEPAD_X) {             drawCText("SNES Button Right: "); drawCDText("Xbox X");}
	if(controllers[controllerSelected].button_Right == XINPUT_GAMEPAD_Y) {             drawCText("SNES Button Right: "); drawCDText("Xbox Y");}
	if(controllers[controllerSelected].button_Right == XINPUT_GAMEPAD_BACK) {          drawCText("SNES Button Right: "); drawCDText("Xbox Back");}
	if(controllers[controllerSelected].button_Right == XINPUT_GAMEPAD_START) {         drawCText("SNES Button Right: "); drawCDText("Xbox Start");}
	if(controllers[controllerSelected].button_Right == XINPUT_GAMEPAD_WHITE) {         drawCText("SNES Button Right: "); drawCDText("Xbox White");}
	if(controllers[controllerSelected].button_Right == XINPUT_GAMEPAD_BLACK) {         drawCText("SNES Button Right: "); drawCDText("Xbox Black");}
	if(controllers[controllerSelected].button_Right == XINPUT_GAMEPAD_LEFT_TRIGGER) {  drawCText("SNES Button Right: "); drawCDText("Xbox Left Trigger");}
	if(controllers[controllerSelected].button_Right == XINPUT_GAMEPAD_RIGHT_TRIGGER) { drawCText("SNES Button Right: "); drawCDText("Xbox Right Trigger");}  
	if(controllers[controllerSelected].button_Right == XINPUT_GAMEPAD_RIGHT_THUMB) {  drawCText("SNES Button Right: "); drawCDText("Xbox Right Analog Click");} 
	if(controllers[controllerSelected].button_Right == XINPUT_GAMEPAD_LEFT_THUMB) {   drawCText("SNES Button Right: "); drawCDText("Xbox Left Analog Click");}

	if(controllerSelected == 0) {
		//yO += vSpace;
		if(controllers[controllerSelected].button_FastForward == -1) {                    drawCText("Fast Forward: "); drawCDText("Not Assigned"); } 
		if(controllers[controllerSelected].button_FastForward == XINPUT_GAMEPAD_A) {             drawCText("Fast Forward: "); drawCDText("Xbox A"); }
		if(controllers[controllerSelected].button_FastForward == XINPUT_GAMEPAD_B) {             drawCText("Fast Forward: "); drawCDText("Xbox B");}
		if(controllers[controllerSelected].button_FastForward == XINPUT_GAMEPAD_X) {             drawCText("Fast Forward: "); drawCDText("Xbox X");}
		if(controllers[controllerSelected].button_FastForward == XINPUT_GAMEPAD_Y) {             drawCText("Fast Forward: "); drawCDText("Xbox Y");}
		if(controllers[controllerSelected].button_FastForward == XINPUT_GAMEPAD_BACK) {          drawCText("Fast Forward: "); drawCDText("Xbox Back");}
		if(controllers[controllerSelected].button_FastForward == XINPUT_GAMEPAD_START) {         drawCText("Fast Forward: "); drawCDText("Xbox Start");}
		if(controllers[controllerSelected].button_FastForward == XINPUT_GAMEPAD_WHITE) {         drawCText("Fast Forward: "); drawCDText("Xbox White");}
		if(controllers[controllerSelected].button_FastForward == XINPUT_GAMEPAD_BLACK) {         drawCText("Fast Forward: "); drawCDText("Xbox Black");}
		if(controllers[controllerSelected].button_FastForward == XINPUT_GAMEPAD_LEFT_TRIGGER) {  drawCText("Fast Forward: "); drawCDText("Xbox Left Trigger");}
		if(controllers[controllerSelected].button_FastForward == XINPUT_GAMEPAD_RIGHT_TRIGGER) { drawCText("Fast Forward: "); drawCDText("Xbox Right Trigger");}  
		if(controllers[controllerSelected].button_FastForward == XINPUT_GAMEPAD_RIGHT_THUMB) {  drawCText("Fast Forward: "); drawCDText("Xbox Right Analog Click");} 
		if(controllers[controllerSelected].button_FastForward == XINPUT_GAMEPAD_LEFT_THUMB) {   drawCText("Fast Forward: "); drawCDText("Xbox Left Analog Click");} 

		if(controllers[controllerSelected].button_Rewind == -1) {                    drawCText("Rewind: "); drawCDText("Not Assigned"); } 
		if(controllers[controllerSelected].button_Rewind == XINPUT_GAMEPAD_A) {             drawCText("Rewind: "); drawCDText("Xbox A"); }
		if(controllers[controllerSelected].button_Rewind == XINPUT_GAMEPAD_B) {             drawCText("Rewind: "); drawCDText("Xbox B");}
		if(controllers[controllerSelected].button_Rewind == XINPUT_GAMEPAD_X) {             drawCText("Rewind: "); drawCDText("Xbox X");}
		if(controllers[controllerSelected].button_Rewind == XINPUT_GAMEPAD_Y) {             drawCText("Rewind: "); drawCDText("Xbox Y");}
		if(controllers[controllerSelected].button_Rewind == XINPUT_GAMEPAD_BACK) {          drawCText("Rewind: "); drawCDText("Xbox Back");}
		if(controllers[controllerSelected].button_Rewind == XINPUT_GAMEPAD_START) {         drawCText("Rewind: "); drawCDText("Xbox Start");}
		if(controllers[controllerSelected].button_Rewind == XINPUT_GAMEPAD_WHITE) {         drawCText("Rewind: "); drawCDText("Xbox White");}
		if(controllers[controllerSelected].button_Rewind == XINPUT_GAMEPAD_BLACK) {         drawCText("Rewind: "); drawCDText("Xbox Black");}
		if(controllers[controllerSelected].button_Rewind == XINPUT_GAMEPAD_LEFT_TRIGGER) {  drawCText("Rewind: "); drawCDText("Xbox Left Trigger");}
		if(controllers[controllerSelected].button_Rewind == XINPUT_GAMEPAD_RIGHT_TRIGGER) { drawCText("Rewind: "); drawCDText("Xbox Right Trigger");} 
		if(controllers[controllerSelected].button_Rewind == XINPUT_GAMEPAD_RIGHT_THUMB) {  drawCText("Rewind: "); drawCDText("Xbox Right Analog Click");} 
		if(controllers[controllerSelected].button_Rewind == XINPUT_GAMEPAD_LEFT_THUMB) {   drawCText("Rewind: "); drawCDText("Xbox Left Analog Click");}    

		if(controllers[controllerSelected].button_ShowFPS == -1) {                           drawCText("FPS Display Toggle: "); drawCDText("Not Assigned"); } 
		if(controllers[controllerSelected].button_ShowFPS == XBGAMEPAD_A) {             drawCText("FPS Display Toggle: "); drawCDText("Xbox A"); }
		if(controllers[controllerSelected].button_ShowFPS == XBGAMEPAD_B) {             drawCText("FPS Display Toggle: "); drawCDText("Xbox B");}
		if(controllers[controllerSelected].button_ShowFPS == XBGAMEPAD_X) {             drawCText("FPS Display Toggle: "); drawCDText("Xbox X");}
		if(controllers[controllerSelected].button_ShowFPS == XBGAMEPAD_Y) {             drawCText("FPS Display Toggle: "); drawCDText("Xbox Y");}
		if(controllers[controllerSelected].button_ShowFPS == XBGAMEPAD_BACK) {          drawCText("FPS Display Toggle: "); drawCDText("Xbox Back");}
		if(controllers[controllerSelected].button_ShowFPS == XBGAMEPAD_START) {         drawCText("FPS Display Toggle: "); drawCDText("Xbox Start");}
		if(controllers[controllerSelected].button_ShowFPS == XBGAMEPAD_WHITE) {         drawCText("FPS Display Toggle: "); drawCDText("Xbox White");}
		if(controllers[controllerSelected].button_ShowFPS == XBGAMEPAD_BLACK) {         drawCText("FPS Display Toggle: "); drawCDText("Xbox Black");}
		if(controllers[controllerSelected].button_ShowFPS == XBGAMEPAD_LEFT_TRIGGER) {  drawCText("FPS Display Toggle: "); drawCDText("Xbox Left Trigger");}
		if(controllers[controllerSelected].button_ShowFPS == XBGAMEPAD_RIGHT_TRIGGER) { drawCText("FPS Display Toggle: "); drawCDText("Xbox Right Trigger");}
		if(controllers[controllerSelected].button_ShowFPS == XINPUT_GAMEPAD_RIGHT_THUMB) {  drawCText("FPS Display Toggle: "); drawCDText("Xbox Right Analog Click");} 
		if(controllers[controllerSelected].button_ShowFPS == XINPUT_GAMEPAD_LEFT_THUMB) {   drawCText("FPS Display Toggle: "); drawCDText("Xbox Left Analog Click");} 

		if(controllers[controllerSelected].button_SaveState == -1) {                    drawCText("Save State: "); drawCDText("Not Assigned"); } 
		if(controllers[controllerSelected].button_SaveState == XINPUT_GAMEPAD_A) {             drawCText("Save State: "); drawCDText("Xbox A"); }
		if(controllers[controllerSelected].button_SaveState == XINPUT_GAMEPAD_B) {             drawCText("Save State: "); drawCDText("Xbox B");}
		if(controllers[controllerSelected].button_SaveState == XINPUT_GAMEPAD_X) {             drawCText("Save State: "); drawCDText("Xbox X");}
		if(controllers[controllerSelected].button_SaveState == XINPUT_GAMEPAD_Y) {             drawCText("Save State: "); drawCDText("Xbox Y");}
		if(controllers[controllerSelected].button_SaveState == XINPUT_GAMEPAD_BACK) {          drawCText("Save State: "); drawCDText("Xbox Back");}
		if(controllers[controllerSelected].button_SaveState == XINPUT_GAMEPAD_START) {         drawCText("Save State: "); drawCDText("Xbox Start");}
		if(controllers[controllerSelected].button_SaveState == XINPUT_GAMEPAD_WHITE) {         drawCText("Save State: "); drawCDText("Xbox White");}
		if(controllers[controllerSelected].button_SaveState == XINPUT_GAMEPAD_BLACK) {         drawCText("Save State: "); drawCDText("Xbox Black");}
		if(controllers[controllerSelected].button_SaveState == XINPUT_GAMEPAD_LEFT_TRIGGER) {  drawCText("Save State: "); drawCDText("Xbox Left Trigger");}
		if(controllers[controllerSelected].button_SaveState == XINPUT_GAMEPAD_RIGHT_TRIGGER) { drawCText("Save State: "); drawCDText("Xbox Right Trigger");}
		if(controllers[controllerSelected].button_SaveState == XINPUT_GAMEPAD_RIGHT_THUMB) {    drawCText("Save State: "); drawCDText("Xbox Right Analog Click");} 
		if(controllers[controllerSelected].button_SaveState == XINPUT_GAMEPAD_LEFT_THUMB) {     drawCText("Save State: "); drawCDText("Xbox Left Analog Click");}    

		if(controllers[controllerSelected].button_LoadState == -1) {                    drawCText("Load State: "); drawCDText("Not Assigned"); } 
		if(controllers[controllerSelected].button_LoadState == XINPUT_GAMEPAD_A) {             drawCText("Load State: "); drawCDText("Xbox A"); }
		if(controllers[controllerSelected].button_LoadState == XINPUT_GAMEPAD_B) {             drawCText("Load State: "); drawCDText("Xbox B");}
		if(controllers[controllerSelected].button_LoadState == XINPUT_GAMEPAD_X) {             drawCText("Load State: "); drawCDText("Xbox X");}
		if(controllers[controllerSelected].button_LoadState == XINPUT_GAMEPAD_Y) {             drawCText("Load State: "); drawCDText("Xbox Y");}
		if(controllers[controllerSelected].button_LoadState == XINPUT_GAMEPAD_BACK) {          drawCText("Load State: "); drawCDText("Xbox Back");}
		if(controllers[controllerSelected].button_LoadState == XINPUT_GAMEPAD_START) {         drawCText("Load State: "); drawCDText("Xbox Start");}
		if(controllers[controllerSelected].button_LoadState == XINPUT_GAMEPAD_WHITE) {         drawCText("Load State: "); drawCDText("Xbox White");}
		if(controllers[controllerSelected].button_LoadState == XINPUT_GAMEPAD_BLACK) {         drawCText("Load State: "); drawCDText("Xbox Black");}
		if(controllers[controllerSelected].button_LoadState == XINPUT_GAMEPAD_LEFT_TRIGGER) {  drawCText("Load State: "); drawCDText("Xbox Left Trigger");}
		if(controllers[controllerSelected].button_LoadState == XINPUT_GAMEPAD_RIGHT_TRIGGER) { drawCText("Load State: "); drawCDText("Xbox Right Trigger");}  
		if(controllers[controllerSelected].button_LoadState == XINPUT_GAMEPAD_RIGHT_THUMB) {  drawCText("Load State: "); drawCDText("Xbox Right Analog Click");} 
		if(controllers[controllerSelected].button_LoadState == XINPUT_GAMEPAD_LEFT_THUMB) {   drawCText("Load State: "); drawCDText("Xbox Left Analog Click");}      

		if(controllers[controllerSelected].button_ExitGame == -1) {                          drawCText("Exit Game: "); drawCDText("Not Assigned"); } 
if(controllers[controllerSelected].button_ExitGame == XINPUT_GAMEPAD_A) {             drawCText("Exit Game: "); drawCDText("Xbox A"); }
		if(controllers[controllerSelected].button_ExitGame == XINPUT_GAMEPAD_B) {             drawCText("Exit Game: "); drawCDText("Xbox B");}
		if(controllers[controllerSelected].button_ExitGame == XINPUT_GAMEPAD_X) {             drawCText("Exit Game: "); drawCDText("Xbox X");}
		if(controllers[controllerSelected].button_ExitGame == XINPUT_GAMEPAD_Y) {             drawCText("Exit Game: "); drawCDText("Xbox Y");}
		if(controllers[controllerSelected].button_ExitGame == XINPUT_GAMEPAD_BACK) {          drawCText("Exit Game: "); drawCDText("Xbox Back");}
		if(controllers[controllerSelected].button_ExitGame == XINPUT_GAMEPAD_START) {         drawCText("Exit Game: "); drawCDText("Xbox Start");}
		if(controllers[controllerSelected].button_ExitGame == XINPUT_GAMEPAD_WHITE) {         drawCText("Exit Game: "); drawCDText("Xbox White");}
		if(controllers[controllerSelected].button_ExitGame == XINPUT_GAMEPAD_BLACK) {         drawCText("Exit Game: "); drawCDText("Xbox Black");}
		if(controllers[controllerSelected].button_ExitGame == XINPUT_GAMEPAD_LEFT_TRIGGER) {  drawCText("Exit Game: "); drawCDText("Xbox Left Trigger");}
		if(controllers[controllerSelected].button_ExitGame == XINPUT_GAMEPAD_RIGHT_TRIGGER) { drawCText("Exit Game: "); drawCDText("Xbox Right Trigger");} 
		if(controllers[controllerSelected].button_ExitGame == XINPUT_GAMEPAD_RIGHT_THUMB) {  drawCText("Exit Game: "); drawCDText("Xbox Right Analog Click");} 
		if(controllers[controllerSelected].button_ExitGame == XINPUT_GAMEPAD_LEFT_THUMB) {   drawCText("Exit Game: "); drawCDText("Xbox Left Analog Click");}                            

	}
}

extern "C" {
	void loadZRumble() {
		stringstream a;
		a << gameCRC;
		string cSum;
		a >> cSum;
		LoadRumbleFile(cSum);
	}
}

