bool useNoRom = true;
#include "app.h"
extern void drawStateOptions();
IDirect3D8 *Direct3D=NULL;
IDirect3DDevice8 *Device=NULL;
IDirect3DSurface8 *DirectBack=NULL; // Back Buffer
extern int vSpace;
float nudgex=0.0f,nudgey=0.0f;
IDirect3DVertexBuffer8 *VertexBuffer=NULL;
extern "C" int dprintf(char *format, ...);
IDirect3DVertexBuffer8 *AnimatedVertexBuffer=NULL;
IDirect3DVertexBuffer8 *StationaryAnimatedVertexBuffer=NULL;
IDirect3DVertexBuffer8 *VertexBufferPreview=NULL;
IDirect3DVertexBuffer8 *VertexBufferImage=NULL;
IDirect3DVertexBuffer8 *VertexBufferPreviewGP=NULL;
IDirect3DVertexBuffer8 *VertexBufferMPL=NULL;
IDirect3DVertexBuffer8 *VertexBufferPreviewBorder=NULL;
extern int screenGeneralOptionsGGText;
int dimColor = 0;

extern void drawGeneralOptionsGGText();
IDirect3DVertexBuffer8 *VertexBufferPreviewB=NULL;
IDirect3DVertexBuffer8 *VertexBufferPreview2=NULL;
IDirect3DVertexBuffer8 *VertexBufferLinear=NULL;
IDirect3DVertexBuffer8 *VertexBufferResize=NULL;
extern int screenGeneralOptionsTGA;
extern int screenMPOptions;
extern int gameGuideLines ;
extern int gameGuideColor ;
extern int gameGuideFontSize ;
extern int screenResizeGP;
extern void drawMovie();

extern int fontType;
extern int archiveMode;
extern void changePreviewUp();
extern int vsyncEnabled;
extern int screenResizeMPL;
extern void drawGeneralOptionsGG();
extern int keyBoardDraw;
extern void drawXKeyboard();
IDirect3DVertexBuffer8 *VertexBufferOptions=NULL;
extern int musicPlayer;
extern int gFont;
extern int tvMode;
extern void drawTGAList();
extern void drawKeyboard();
extern int screenGeneralOptionsMP;
IDirect3DVertexBuffer8 *VertexBufferController=NULL;
extern int analogStill;
extern int yO;
int screenResizeMovie = 0; 
extern void drawMPOptionsMenu();
int lightGun = 0;
extern LPDIRECTSOUND8  m_pDSound ;  
extern HRESULT XBSound_DrawLevelMeters( LPDIRECTSOUND8 pDSound, 
									   FLOAT fLeft, FLOAT fTop,
									   FLOAT fWidth, FLOAT fHeight );
extern HRESULT ProcessLightGun();
extern HRESULT LightGunRender();

extern int getAnalog();
extern void drawRumbleConfig();
int confirmDelete = 0;
extern int favorites;
int favoriteAdd = 0;
extern int FileMenuSelected;
#include <vector>
int flipScreen = 0;
using namespace std;
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 vSpace;
extern  int oldScreenShot ;
extern void changePreview() ;
int screenShotSlot  = 4; //in game slot
extern int screenShotSlotAuto;
float leftX = 0;
extern void vkDraw();
extern int screenShotSlot;
extern int animateScreenShot();
float rightX = 0;
extern int  automaticScreenShotSwitching;
extern float lastTimeScreenShotSwitch ;
extern float currentTimeScreenShotSwitch ;
extern LARGE_INTEGER ticksPerSecondScreenShotSwitch;
extern LARGE_INTEGER tickScreenShotSwitch;   // A point in time
extern LARGE_INTEGER timeScreenShotSwitch;   // For converting tick into real time


extern int fadeSpeed;
extern char skinPath[512];
int animationFrames = 8;//zelda has 8 frames
extern int repeatAnimation;
int aRun = 0;
extern int x2;
extern int y2;
#include "FileMenu.h"
extern int selected;
extern int  gamesFound;
extern int lastChoice;
extern int screenResizeE;
extern int showBorder;
extern int controllerMode;
extern void drawControllerMenu();
int fadeOption = 0;
float topY = 0;
int cDist = 100;
float bottomY = 0;
extern int zLeftEO;
extern int zTopEO;
extern int TGADatabaseDelete;
extern int zLeftCO;
extern int zTopCO;

extern int zLeftTO;
extern int zTopTO;
int nFilter = 0;
extern int fontResizeR;//rombrowser
extern int fontResizeF;//full filename
extern int fontResizeV;//video
extern int fontResizeRumble;//video
extern int fontResizeS;//sound
extern int fontResizeG;//General Options
extern int fontResizeCD;//General Options
extern int fontResizeM;//main menu
extern int fontResizeEO;//emulator options menu
extern int fontResizeCO;//controller options menu
extern int fontResizeTO;//controller Turbo options menu
extern int fontResizeCCO;//controller config options menu
extern int fontResizeGT;//GUI Text
extern int fontResizeIT;//GUI Text
extern int fontResizeCC;//Cheat Code Text
extern int fontResizeClip;//clipping
extern int zLeftIT;
extern int zTopIT;

extern int zLeftCC;
extern int zTopCC;
extern void drawListOfArchiveGames();
extern int zLeftMM;
extern int zTopMM;
extern int MenuRender();
extern int saveStateLoad;
extern int saveStateSave;
extern float animationSpeed;
extern int transparency;
float zTopJ = 1.729998f;
float zLeftJ = 3.619997f;
float zBottomJ = -0.809991f;
float zRightJ = -2.649951f;
extern int x;
extern int y;
extern int w;
extern int h;
float zTopG = 0;
float zLeftG = 0;
float zBottomG = 0;
float zRightG = 0;


float zTopB =0;// -1.019999f;
float zLeftB = 0;//0.039999f;
float zBottomB =0;// -2.24f;
float zRightB = 0;//-0.56f;

float zTopBI =0;// -1.019999f;
float zLeftBI = 0;//0.039999f;
float zBottomBI =0;// -2.24f;
float zRightBI = 0;//-0.56f
extern void drawGameGuideList();

extern int controllerRumbleConfigMenu;

extern int splash;
float zTopA =2.892500f;
float zLeftA =-6.282444f;
float zBottomA = 6.267534f;
float zRightA = -6.187536f;

float zTopA2 =2.892500f;
float zLeftA2 =-6.282444f;
float zBottomA2 = 6.267534f;
float zRightA2 = -6.187536f;


float zTopAR =2.892500f;
float zLeftAR =-6.282444f;
float zBottomAR = 6.267534f;
float zRightAR = -6.187536f;
extern void drawListOfHeats() ;
float zTopA2R =2.892500f;
float zLeftA2R =-6.282444f;
float zBottomA2R = 6.267534f;
float zRightA2R = -6.187536f;

float zTopS = -13.619988f;
float zLeftS = -17.359997f;
float zBottomS = -6.339995f;
float zRightS = -27.600075f;

int fadeColor = 255;
int fadeColor2 = 0;
extern int screenResize;
extern int screenResizeP;
extern int screenResizeI;
extern int screenResizePB;
extern int screenResizeJ;
extern int screenResizeG;
extern int screenResizeB;
extern int screenResizeA;
extern int screenResizeA2;
extern int screenOptionsM;
extern int screenOptionsHelp;
extern int screenResizeS;
extern int TGADatabasePick;
#define D3DFVF_CUSTOMVERTEX (D3DFVF_XYZ|D3DFVF_DIFFUSE|D3DFVF_TEX1)

CustomVertex VertexList[4];
CustomVertex AnimatedVertexList[4];
CustomVertex StationaryAnimatedVertexList[4];
CustomVertex VertexListPreview[4];
CustomVertex VertexListImage[4];
CustomVertex VertexListPreviewGP[4];
CustomVertex VertexListPreviewB[4];
CustomVertex VertexListPreviewBorder[4];
CustomVertex VertexListPreview2[4];
CustomVertex VertexListLinear[4];
CustomVertex VertexListResize[4];
CustomVertex VertexListController[4];
CustomVertex VertexListOptions[4];
extern int screenControllerOptions;
extern int screenCheatOptions;
extern void oneByteDraw();
extern int screenVideoOptions ;
extern int screenSoundOptions ;
extern int screenLightGunOptions ;
extern int screenGeneralOptions ;
extern int screenGeneralOptionsGG ;
extern int screenGUIOptions ;
extern int screenOptions ;
bool videoRender = false;
extern void drawGeneralOptions();
void DirectExit()
{
	FontExit();
	TexScreenExit();

	RELEASE(VertexBuffer)
		RELEASE(VertexBufferPreview)
		RELEASE(VertexBufferImage)
		RELEASE(VertexBufferPreviewBorder)
		RELEASE(VertexBufferPreviewB)
		RELEASE(VertexBufferPreview2)
		RELEASE(VertexBufferLinear)
		RELEASE(VertexBufferResize)
		RELEASE(VertexBufferController)
		RELEASE(VertexBufferOptions)
		RELEASE(DirectBack)
		RELEASE(Device)
		RELEASE(Direct3D)
}


extern float zTop;
extern float zLeft;
extern float zRight;
extern float zBottom;

extern float zTopP;
extern float zLeftP;
extern float zRightP;
extern float zBottomP;

extern float zTopGP;
extern float zLeftGP;
extern float zRightGP;
extern float zBottomGP;

extern float zTopMPL;
extern float zLeftMPL;
extern float zRightMPL;
extern float zBottomMPL;

extern float zTopPB;
extern float zLeftPB;
extern float zRightPB;
extern float zBottomPB;



extern int zTopHT;
extern int zLeftHT;

int lC = 86;
int rC = 109;
int lCWidth = 563;
int rCHeight = 394;



int guideGameSelectedText = 7;

#include <string>
#include <vector>
using namespace std;
vector<string> guide;
vector<string> guideFile;
#include <fstream>
#include <algorithm>
extern string BOOKMARK_PATH;

void saveBookMark(char* n) {
	std::string path = BOOKMARK_PATH;
	std::string path2 = n;
	std::string path3 = ".bkm";
	std::string path4 = path + path2 + path3;
	FILE* f;
	//dprintf("Creating bookmark file: %s, %d\n", path4.c_str(), guideGameSelectedText);
	f = fopen(path4.c_str() , "w+");
	fprintf(f, "Bookmark=%d\n", guideGameSelectedText);
	fclose(f);
}

void loadGuide(char* p, char* n) {
	

	std::string path = BOOKMARK_PATH;
	std::string path2 = n;
	std::string path3 = ".bkm";
	std::string path4 = path + path2 + path3;

	FILE* f2;
	f2 = fopen(path4.c_str() , "r");
	//dprintf("Loading bookmark file: %s\n", path4.c_str()); 


	if(f2) {
		dprintf("Loaded bookmark file\n");
		char a[100];
		fgets(a,100, f2);
		for(int i = 0; i < 100; i++) {
			if(a[i] == '=') {
				guideGameSelectedText = (int) atoi(&a[i+1]);
				break;
			}
		}
		dprintf("gameSelectedText: %d\n",guideGameSelectedText);
		fclose(f2);
	}
	else {
		dprintf("Couldn't load bookmark file\n");
		guideGameSelectedText = 0;
	}
	
	




	

	guide.clear();
	//guideGameSelectedText = 0;

	ifstream f(p);
	while(!f.eof()) {
		char line[2048];
		for(int i = 0; i < 2048; i++) line[i] = '\0';
		f.getline(line, 2048);
		
		string t = line;
		for(int i = 0; i < t.size(); i++) {
			if((t.c_str())[i] == '\t') t[i] = ' ';
			if((t.c_str())[i] == 0xAF) t[i] = '-';
		}
		guide.push_back(t);
	}
	f.close();
}

void loadFile(char* p) {
	guideFile.clear();
	//guideGameSelectedText = 0;

	ifstream f(p);
	while(!f.eof()) {
			char line[2048];
			for(int i = 0; i < 2048; i++) line[i] = '\0';
			f.getline(line, 2048);
			
			string t = line;
			for(int i = 0; i < t.size(); i++) {
				if((t.c_str())[i] == '\t') t[i] = ' ';
				if((t.c_str())[i] == 0xAF) t[i] = '-';
			}
			guideFile.push_back(t);
	}

}

extern int zLeftCD;
extern int zTopCD;
int guideLeft = 50;


//extern int gameGuideLines ;
//extern int gameGuideColor ;
//extern int gameGuideFontSize ;

extern int FontGuideText(WCHAR *text,int dx,int dy, int maxWidth);
void drawGuide() {
	int yDB = 50;
	DWORD color;
	int start = 0;

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

	int aSelected = guideGameSelectedText;
	int bSizeMinus7 = ((guide.size()-1) - 7);
	if((aSelected > bSizeMinus7) && (guide.size() > 15)) {

		start = (guide.size() - 15);
	}

	if(gameGuideColor == 0)
		color = 0x00ff00; 
	else
		color = 0xffffff; 
	for(int i = start; i <  start + gameGuideLines; i++) {
		if(i == guide.size()) { return; }
		WCHAR atext2345[2048]={0};
		std::string t = guide[i];
		for(int r = 0; r < 2048; r++) {
			if((t.c_str())[r] == '\0') {
				atext2345[r] = '\0';
				break;
			} 
			atext2345[r] = (t.c_str())[r]; 
		}
		FontSetColour(color);
		FontGuideText(atext2345,guideLeft,yDB, 1920);
		yDB+=vSpace;
	}
}


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

void loadHelp() {
	return;
	FILE* f;
	std::string t = "D:\\docs\\ZsnexBox.txt";
	f = fopen(t.c_str() , "r");

	if(f == NULL) {
		std::string a = "Help file: \"ZsnexBox.txt\" was not found in the docs folder";
		help.push_back(a);
		return;
	}

	while(true) {
		char line[512];
		if(fgets(line,512, f) == NULL) {
			break;
		}
		else {
			std::string a = line;
			help.push_back(a);
		}
	}
	fclose(f);
}


void clearHelp() {
	help.clear();
}

extern int drawMP_Count;
extern int yMP;
extern void drawMPSText(char* text) ;
extern void drawMPText(char* text) ;
extern int screenGeneralOptionsMP;

void drawHelpMenu() {
	screenGeneralOptionsMP = 1;
    drawMP_Count = 0;
    yMP = 130;
	drawMPSText("Controls"); drawMPText("");
	drawMPSText("Frequently Asked Questions"); drawMPText("");
	drawMPSText("Release Notes"); drawMPText("");
	drawMPSText("About"); drawMPText("");
	screenGeneralOptionsMP = 0;


//rtretrete


	/*int qSet = 0;
	int xO = 640/2;
	int yO = 130;
	int oSpace = vSpace;
	unsigned int c = 0x00ffffff;


	for(int i = 0; i < help.size(); i++) {
		WCHAR texta32345678_[512]={0};

		for(int j = 0 ; j < 512; j++) {
			if((help[i].c_str())[j] == '\0') {
				texta32345678_[j] = (help[i].c_str())[j];
				break;
			}

			if((help[i].c_str())[j] == '\'') 
				texta32345678_[j] = '\'';
			else if ((help[i].c_str())[j] == '"')
				texta32345678_[j] = '\"';
			else if ((help[i].c_str())[j] == '\n')
				texta32345678_[j] = ' ';
			else if ((help[i].c_str())[j] == '\t')
				texta32345678_[j] = ' ';
			else if ((help[i].c_str())[j] == '\\')
				texta32345678_[j] = '\\';
			else
				texta32345678_[j] = (help[i].c_str())[j];
		}		

		if((texta32345678_[0] == 'Q' && texta32345678_[1] == ':') || qSet == 1) {
			qSet = 1;
			if((texta32345678_[0] == 'A' && texta32345678_[1] == ':')) {
				qSet = 0;
				FontSetColour(c);
			}
			else {
				FontSetColour(0xff00ff00);
			}
		}
		else {
			FontSetColour(c);
		}


		if((texta32345678_[0] == 'F' && 
			texta32345678_[1] == 'r' &&
			texta32345678_[2] == 'e' &&
			texta32345678_[3] == 'q' &&
			texta32345678_[4] == 'u' &&
			texta32345678_[5] == 'e' &&
			texta32345678_[6] == 'n' &&
			texta32345678_[7] == 't' &&
			texta32345678_[8] == 'l' &&
			texta32345678_[9] == 'y' &&
			texta32345678_[10] == ' '))
		{
			FontSetColour(0xffffff00);
		}

		if((texta32345678_[0] == 'C' && 
			texta32345678_[1] == 'o' &&
			texta32345678_[2] == 'n' &&
			texta32345678_[3] == 't' &&
			texta32345678_[4] == 'r' &&
			texta32345678_[5] == 'o' &&
			texta32345678_[6] == 'l' &&
			texta32345678_[7] == 's' &&
			texta32345678_[8] == ' ' &&
			texta32345678_[9] == '-' &&
			texta32345678_[10] == ' '))
		{
			FontSetColour(0xffffff00);
		}

		FontText(texta32345678_,xO+zLeftHT,yO+zTopHT, -1);
		yO += oSpace;
	}
*/

}


void makeVertexListResize() {
	rightX = 0;//-2.7999999f;
	leftX = 0;//2.999999f;
	topY = 0;//-4.0f;
	bottomY = 0;//4.0f;
	scaleZ =0;

	struct CustomVertex *vert=NULL,*pv=NULL;
	float dist=0.0f;
	float scalex=0.0f,scaley=0.0f;
	unsigned int colour=0xffffff;

	if(dimColor && screenResize == 1)colour=0x545454;
	float right=0.0f,bottom=0.0f;
	if(screenResizeS == 1 || screenResizeP == 1 || screenResizeI == 1 || screenResizeJ == 1 || screenResizeG == 1 || screenResizeA == 1  || screenResizeB == 1 || screenResizeMPL == 1 || screenResizePB == 1) colour = 0x545454;


	//if (LoopMode!=8) colour=0x102040;

	dist=10.0; scalex=dist*1.3333f; scaley=dist;

	//scalex*=640.0f/(float)640;
	//scaley*=480.0f/(float)480;


	dist += scaleZ;

	vert=VertexListResize;

	// Put the vertices for the corners of the screen:
	pv=vert;
	pv->z=dist;
	pv->x=-scalex + zLeft; pv->y=scaley + zTop;
	pv->colour=colour; pv++;

	*pv=vert[0]; pv->x= scalex  + zRight; pv->y= scaley + zTop; pv++;
	*pv=vert[0]; pv->x=-scalex  + zLeft; pv->y=-scaley  + zBottom; pv++;
	*pv=vert[0]; pv->x= scalex  + zRight; pv->y=-scaley + zBottom; pv++;

	// Find where the screen images ends on the texture
	right = 1.0f;//(float)EmuWidth /(float)TexWidth;
	bottom= 1.0f;//(float)EmuHeight/(float)TexHeight;

	// Write texture coordinates:
	pv=vert;
	pv->u=0.0f;  pv->v=0.00f;  pv++;
	pv->u=right; pv->v=0.00f;  pv++;
	pv->u=0.0f;  pv->v=bottom; pv++;
	pv->u=right; pv->v=bottom; pv++;

}

void makeVertexListResizeP() {
	rightX = -2.7999999f;
	leftX = 2.999999f;
	topY = -2.0f;
	bottomY = 2.0f;
	scaleZ = -0.9f;

	struct CustomVertex *vert=NULL,*pv=NULL;
	float dist=0.0f;
	float scalex=0.0f,scaley=0.0f;
	unsigned int colour=0xffffff;
	float right=0.0f,bottom=0.0f;
	if(screenResizeS == 1 || screenResizeP == 1 || screenResizeI == 1 || screenResizeJ == 1 || screenResizeG == 1 || screenResizeA == 1  || screenResizeB == 1 || screenResizeMPL == 1 || screenResizePB == 1) colour = 0x545454;

	//if (LoopMode!=8) colour=0x102040;

	dist=10.0; scalex=dist*1.3333f; scaley=dist;

	//scalex*=640.0f/(float)640;
	//scaley*=480.0f/(float)480;


	dist += scaleZ;

	vert=VertexList;

	// Put the vertices for the corners of the screen:
	pv=vert;
	pv->z=dist;
	pv->x=-scalex + leftX + zLeftG; 
	pv->y=scaley + topY  + zTopG;
	pv->colour=colour;
	pv++;

	*pv=vert[0];
	pv->x= scalex + rightX + zRightG; 
	pv->y= scaley + topY + zTopG; 
	pv++;

	*pv=vert[0]; 
	pv->x=-scalex + leftX + zLeftG; 
	pv->y=-scaley + bottomY + zBottomG; 
	pv++;

	*pv=vert[0]; 
	pv->x= scalex + rightX + zRightG; 
	pv->y=-scaley + bottomY + zBottomG; 
	pv++;

	// Find where the screen images ends on the texture
	right = 1;//(float)EmuWidth /(float)TexWidth;
	bottom= 1;//(float)EmuHeight/(float)TexHeight;

	// Write texture coordinates:
	pv=vert;
	pv->u=0.0f;  pv->v=0.00f;  pv++;
	pv->u=right; pv->v=0.00f;  pv++;
	pv->u=0.0f;  pv->v=bottom; pv++;
	pv->u=right; pv->v=bottom; pv++;






	//PREVIEW-----------------------------------------------------------
	dist=10.0f; scalex=dist*1.3333f; scaley=dist;
	vert=VertexListPreview;

	dist += 1.5;//scaleZ2;
	//dist += scaleZ;
	// Put the vertices for the corners of the screen:
	pv=vert;


	pv->z=dist;
	pv->x= -0.1f + 0.2f + zLeftP; 
	pv->y=5.4f+1.25f + zTopP;// + topY;
	pv->colour=0xffffffff; 
	pv++;

	*pv=vert[0]; 
	pv->x= 12.1f + zRightP;// + rightX; 
	pv->y= 5.4f+1.25f + zTopP;//+ topY; 
	pv++;

	*pv=vert[0];
	pv->x=-0.1f + 0.2f + zLeftP; 
	pv->y=-4.0+1.25f + zBottomP;// + bottomY; 
	pv++;

	*pv=vert[0]; 
	pv->x= 12.1f  + zRightP;// + rightX; 
	pv->y=-4.0+1.25f + zBottomP;// + bottomY; 
	pv++;

	// Find where the screen images ends on the texture
	right = 1;//(float)EmuWidth /(float)TexWidth;
	bottom= 1;//(float)EmuHeight/(float)TexHeight;

	// Write texture coordinates:
	pv=vert;
	pv->u=0.0f;  pv->v=0.00f;  pv++;
	pv->u=right; pv->v=0.00f;  pv++;
	pv->u=0.0f;  pv->v=bottom; pv++;
	pv->u=right; pv->v=bottom; pv++;
	return;

}


void makeVertexListImage() {
	struct CustomVertex *vert=NULL,*pv=NULL;
	
	vert=VertexListImage;
	pv=vert;
	pv->z=10;
	pv->x= zLeftBI; 
	pv->y=zTopBI;// + topY;
	pv->colour=0xffffffff; 
	pv++;

	*pv=vert[0]; 
	pv->x= zRightBI;// + rightX; 
	pv->y=  zTopBI;//+ topY; 
	pv++;

	*pv=vert[0];
	pv->x=zLeftBI; 
	pv->y=zBottomBI;// + bottomY; 
	pv++;

	*pv=vert[0]; 
	pv->x=  zRightBI;// + rightX; 
	pv->y=zBottomBI;// + bottomY; 
	pv++;


	float right=0.0f,bottom=0.0f;
	// Find where the screen images ends on the texture
	right = 1;//(float)EmuWidth /(float)TexWidth;
	bottom= 1;//(float)EmuHeight/(float)TexHeight;

	// Write texture coordinates:
	pv=vert;
	pv->u=0.0f;  pv->v=0.00f;  pv++;
	pv->u=right; pv->v=0.00f;  pv++;
	pv->u=0.0f;  pv->v=bottom; pv++;
	pv->u=right; pv->v=bottom; pv++;
	return;
}

void makeVertexListResizeGP() {
	rightX = -2.7999999f;
	leftX = 2.999999f;
	topY = -2.0f;
	bottomY = 2.0f;
	scaleZ = -0.9f;

	struct CustomVertex *vert=NULL,*pv=NULL;
	float dist=0.0f;
	float scalex=0.0f,scaley=0.0f;
	unsigned int colour=0xffffff;
	float right=0.0f,bottom=0.0f;
	if(screenResizeS == 1 || screenResizeP == 1 || screenResizeI == 1 || screenResizeJ == 1 || screenResizeG == 1 || screenResizeA == 1  || screenResizeB == 1 || screenResizeGP == 1 || screenResizeMPL == 1 || screenResizePB == 1) colour = 0x545454;

	//if (LoopMode!=8) colour=0x102040;

	dist=10.0; scalex=dist*1.3333f; scaley=dist;

	//scalex*=640.0f/(float)640;
	//scaley*=480.0f/(float)480;


	dist += scaleZ;

	vert=VertexList;

	// Put the vertices for the corners of the screen:
	pv=vert;
	pv->z=dist;
	pv->x=-scalex + leftX + zLeftG; 
	pv->y=scaley + topY  + zTopG;
	pv->colour=colour;
	pv++;

	*pv=vert[0];
	pv->x= scalex + rightX + zRightG; 
	pv->y= scaley + topY + zTopG; 
	pv++;

	*pv=vert[0]; 
	pv->x=-scalex + leftX + zLeftG; 
	pv->y=-scaley + bottomY + zBottomG; 
	pv++;

	*pv=vert[0]; 
	pv->x= scalex + rightX + zRightG; 
	pv->y=-scaley + bottomY + zBottomG; 
	pv++;

	// Find where the screen images ends on the texture
	right = 1;//(float)EmuWidth /(float)TexWidth;
	bottom= 1;//(float)EmuHeight/(float)TexHeight;

	// Write texture coordinates:
	pv=vert;
	pv->u=0.0f;  pv->v=0.00f;  pv++;
	pv->u=right; pv->v=0.00f;  pv++;
	pv->u=0.0f;  pv->v=bottom; pv++;
	pv->u=right; pv->v=bottom; pv++;






	//PREVIEW-----------------------------------------------------------
	dist=10.0f; scalex=dist*1.3333f; scaley=dist;
	vert=VertexListPreviewGP;

	dist += 1.5;//scaleZ2;
	//dist += scaleZ;
	// Put the vertices for the corners of the screen:
	pv=vert;


	pv->z=dist;
	pv->x= -0.1f + 0.2f + zLeftGP; 
	pv->y=5.4f+1.25f + zTopGP;// + topY;
	pv->colour=0xffffffff; 
	pv++;

	*pv=vert[0]; 
	pv->x= 12.1f + zRightGP;// + rightX; 
	pv->y= 5.4f+1.25f + zTopGP;//+ topY; 
	pv++;

	*pv=vert[0];
	pv->x=-0.1f + 0.2f + zLeftGP; 
	pv->y=-4.0+1.25f + zBottomGP;// + bottomY; 
	pv++;

	*pv=vert[0]; 
	pv->x= 12.1f  + zRightGP;// + rightX; 
	pv->y=-4.0+1.25f + zBottomGP;// + bottomY; 
	pv++;

	// Find where the screen images ends on the texture
	right = 1;//(float)EmuWidth /(float)TexWidth;
	bottom= 1;//(float)EmuHeight/(float)TexHeight;

	// Write texture coordinates:
	pv=vert;
	pv->u=0.0f;  pv->v=0.00f;  pv++;
	pv->u=right; pv->v=0.00f;  pv++;
	pv->u=0.0f;  pv->v=bottom; pv++;
	pv->u=right; pv->v=bottom; pv++;
	return;

}


void makeVertexListResizeJ() {
	rightX = -2.7999999f;
	leftX = 2.999999f;
	topY = -2.0f;
	bottomY = 2.0f;
	scaleZ = -0.9f;

	struct CustomVertex *vert=NULL,*pv=NULL;
	float dist=0.0f;
	float scalex=0.0f,scaley=0.0f;
	unsigned int colour=0xffffff;
	float right=0.0f,bottom=0.0f;
	if(screenResizeS == 1 || screenResizeP == 1 || screenResizeI == 1 || screenResizeJ == 1 || fontResizeEO == 1 || fontResizeClip == 1  || fontResizeCCO == 1 || fontResizeTO == 1 || fontResizeCO == 1 || fontResizeR == 1 || fontResizeF == 1 || screenResizeA == 1  || screenResizeB == 1 || screenResizeMPL == 1 || screenResizePB == 1) colour = 0x545454;

	//if (LoopMode!=8) colour=0x102040;

	dist=10.0; scalex=dist*1.3333f; scaley=dist;

	//scalex*=640.0f/(float)640;
	//scaley*=480.0f/(float)480;


	dist += scaleZ;

	vert=VertexList;

	// Put the vertices for the corners of the screen:
	pv=vert;
	pv->z=dist;
	pv->x=-scalex + leftX + zLeftG; 
	pv->y=scaley + topY  + zTopG;
	pv->colour=colour;
	pv++;

	*pv=vert[0];
	pv->x= scalex + rightX + zRightG; 
	pv->y= scaley + topY + zTopG; 
	pv++;

	*pv=vert[0]; 
	pv->x=-scalex + leftX + zLeftG; 
	pv->y=-scaley + bottomY + zBottomG; 
	pv++;

	*pv=vert[0]; 
	pv->x= scalex + rightX + zRightG; 
	pv->y=-scaley + bottomY + zBottomG; 
	pv++;

	// Find where the screen images ends on the texture
	right = 1;//(float)EmuWidth /(float)TexWidth;
	bottom= 1;//(float)EmuHeight/(float)TexHeight;

	// Write texture coordinates:
	pv=vert;
	pv->u=0.0f;  pv->v=0.00f;  pv++;
	pv->u=right; pv->v=0.00f;  pv++;
	pv->u=0.0f;  pv->v=bottom; pv++;
	pv->u=right; pv->v=bottom; pv++;






	//PREVIEW-----------------------------------------------------------
	dist=10.0f; scalex=dist*1.3333f; scaley=dist;
	vert=VertexListPreview;

	dist += 1.5;//scaleZ2;
	//dist += scaleZ;
	// Put the vertices for the corners of the screen:
	pv=vert;


	pv->z=dist;
	pv->x= -0.1f + 0.2f + zLeftJ; 
	pv->y=5.4f+1.25f + zTopJ;// + topY;
	pv->colour=0xffffffff; 
	pv++;

	*pv=vert[0]; 
	pv->x= 12.1f + zRightJ;// + rightX; 
	pv->y= 5.4f+1.25f + zTopJ;//+ topY; 
	pv++;

	*pv=vert[0];
	pv->x=-0.1f + 0.2f + zLeftJ; 
	pv->y=-4.0+1.25f + zBottomJ;// + bottomY; 
	pv++;

	*pv=vert[0]; 
	pv->x= 12.1f  + zRightJ;// + rightX; 
	pv->y=-4.0+1.25f + zBottomJ;// + bottomY; 
	pv++;

	// Find where the screen images ends on the texture
	right = 1;//(float)EmuWidth /(float)TexWidth;
	bottom= 1;//(float)EmuHeight/(float)TexHeight;

	// Write texture coordinates:
	pv=vert;
	pv->u=0.0f;  pv->v=0.00f;  pv++;
	pv->u=right; pv->v=0.00f;  pv++;
	pv->u=0.0f;  pv->v=bottom; pv++;
	pv->u=right; pv->v=bottom; pv++;
	return;

}

void makeVertexListResizeB() {
	scaleZ = -0.9f;
	struct CustomVertex *vert=NULL,*pv=NULL;
	float dist=0.0f;
	float scalex=0.0f,scaley=0.0f;
	unsigned int colour=0xffffff;
	float right=0.0f,bottom=0.0f;
	if(screenResizeS == 1 || screenResizeP == 1 || screenResizeI == 1 || screenResizeJ == 1 || screenResizeA == 1  || screenResizeB == 1 || screenResizeMPL == 1 || screenResizePB == 1) colour = 0x545454;

	//PREVIEW-----------------------------------------------------------
	dist=10.0f; scalex=dist*1.3333f; scaley=dist;
	vert=VertexListPreviewB;

	//dist += 1.5;//scaleZ2;
	dist += scaleZ;
	// Put the vertices for the corners of the screen:
	pv=vert;


	pv->z=dist;
	pv->x= zLeftB; 
	pv->y=zTopB;// + topY;
	pv->colour=0xffffffff; 
	pv++;

	*pv=vert[0]; 
	pv->x= zRightB;// + rightX; 
	pv->y=  zTopB;//+ topY; 
	pv++;

	*pv=vert[0];
	pv->x=zLeftB; 
	pv->y=zBottomB;// + bottomY; 
	pv++;

	*pv=vert[0]; 
	pv->x=  zRightB;// + rightX; 
	pv->y=zBottomB;// + bottomY; 
	pv++;

	// Find where the screen images ends on the texture
	right = 1;//(float)EmuWidth /(float)TexWidth;
	bottom= 1;//(float)EmuHeight/(float)TexHeight;

	// Write texture coordinates:
	pv=vert;
	pv->u=0.0f;  pv->v=0.00f;  pv++;
	pv->u=right; pv->v=0.00f;  pv++;
	pv->u=0.0f;  pv->v=bottom; pv++;
	pv->u=right; pv->v=bottom; pv++;
	return;

}


void makeVertexListResizePB() {
	rightX = -2.7999999f;
	leftX = 2.999999f;
	topY = -2.0f;
	bottomY = 2.0f;
	scaleZ = -0.9f;

	struct CustomVertex *vert=NULL,*pv=NULL;
	float dist=0.0f;
	float scalex=0.0f,scaley=0.0f;
	unsigned int colour=0xffffff;
	float right=0.0f,bottom=0.0f;
	if(screenResizeS == 1 || screenResizeP == 1 || screenResizeI == 1 || screenResizeJ == 1 || screenResizeA == 1  || screenResizeB == 1 || screenResizeMPL == 1 || screenResizePB == 1) colour = 0x545454;

	//if (LoopMode!=8) colour=0x102040;

	dist=10.0; scalex=dist*1.3333f; scaley=dist;

	//scalex*=640.0f/(float)640;
	//scaley*=480.0f/(float)480;


	dist += scaleZ;

	vert=VertexList;

	// Put the vertices for the corners of the screen:
	pv=vert;
	pv->z=dist;
	pv->x=-scalex + leftX + zLeftG; 
	pv->y=scaley + topY  + zTopG;
	pv->colour=colour;
	pv++;

	*pv=vert[0];
	pv->x= scalex + rightX + zRightG; 
	pv->y= scaley + topY + zTopG; 
	pv->colour=colour; 
	pv++;

	*pv=vert[0]; 
	pv->x=-scalex + leftX + zLeftG; 
	pv->y=-scaley + bottomY + zBottomG; 
	pv->colour=colour; 
	pv++;

	*pv=vert[0]; 
	pv->x= scalex + rightX + zRightG; 
	pv->y=-scaley + bottomY + zBottomG; 
	pv->colour=colour; 
	pv++;

	// Find where the screen images ends on the texture
	right = 1;//(float)EmuWidth /(float)TexWidth;
	bottom= 1;//(float)EmuHeight/(float)TexHeight;

	// Write texture coordinates:
	pv=vert;
	pv->u=0.0f;  pv->v=0.00f;  pv++;
	pv->u=right; pv->v=0.00f;  pv++;
	pv->u=0.0f;  pv->v=bottom; pv++;
	pv->u=right; pv->v=bottom; pv++;

	float resize = 1.0f;
	dist=10.0f; scalex=dist*1.3333f; scaley=dist;
	vert=VertexListPreviewGP;

	dist += 1.5;//scaleZ2;
	//dist += scaleZ;
	// Put the vertices for the corners of the screen:
	pv=vert;

	pv->z=dist;
	pv->x= (-0.1f + 0.2f + zLeftGP) * resize; 
	pv->y=5.4f+1.25f + zTopGP;// + topY;
	pv->colour=0xffffffff; 
	pv++;

	*pv=vert[0]; 
	pv->x= (12.1f + zRightGP) * resize;// + rightX; 
	pv->y= 5.4f+1.25f + zTopGP;//+ topY; 
	pv->colour=0xffffffff; 
	pv++;

	*pv=vert[0];
	pv->x=(-0.1f + 0.2f + zLeftGP) * resize; 
	pv->y=-4.0+1.25f + zBottomGP;// + bottomY; 
	pv->colour=0xffffffff; 
	pv++;

	*pv=vert[0]; 
	pv->x= (12.1f  + zRightGP) * resize;// + rightX; 
	pv->y=-4.0+1.25f + zBottomGP;// + bottomY; 
	pv->colour=0xffffffff; 
	pv++;

	// Find where the screen images ends on the texture
	right = 1;//(float)EmuWidth /(float)TexWidth;
	bottom= 1;//(float)EmuHeight/(float)TexHeight;

	// Write texture coordinates:
	pv=vert;
	pv->u=0.0f;  pv->v=0.00f;  pv++;
	pv->u=right; pv->v=0.00f;  pv++;
	pv->u=0.0f;  pv->v=bottom; pv++;
	pv->u=right; pv->v=bottom; pv++;

	return;
}





void makeVertexListOptions() {
	rightX = -2.7999999f;
	leftX = 2.999999f;
	topY = -2.0f;
	bottomY = 2.0f;
	scaleZ = -0.9f;

	struct CustomVertex *vert=NULL,*pv=NULL;
	float dist=0.0f;
	float scalex=0.0f,scaley=0.0f;
	unsigned int colour=0xffffff;
	float right=0.0f,bottom=0.0f;

	//if (LoopMode!=8) colour=0x102040;

	dist=10.0; scalex=dist*1.3333f; scaley=dist;

	//scalex*=640.0f/(float)640;
	//scaley*=480.0f/(float)480;


	dist += scaleZ;

	vert=VertexListOptions;

	// Put the vertices for the corners of the screen:



	pv=vert;
	pv->z=dist;
	pv->x=-scalex + leftX + zLeftG; 
	pv->y=scaley + topY  + zTopG;
	pv->colour=colour;
	pv++;

	*pv=vert[0];
	pv->x= scalex + rightX + zRightG; 
	pv->y= scaley + topY + zTopG; 
	pv++;

	*pv=vert[0]; 
	pv->x=-scalex + leftX + zLeftG; 
	pv->y=-scaley + bottomY + zBottomG; 
	pv++;

	*pv=vert[0]; 
	pv->x= scalex + rightX + zRightG; 
	pv->y=-scaley + bottomY + zBottomG; 
	pv++;

	// Find where the screen images ends on the texture
	right = 1;//(float)EmuWidth /(float)TexWidth;
	bottom= 1;//(float)EmuHeight/(float)TexHeight;

	// Write texture coordinates:
	pv=vert;
	pv->u=0.0f;  pv->v=0.00f;  pv++;
	pv->u=right; pv->v=0.00f;  pv++;
	pv->u=0.0f;  pv->v=bottom; pv++;
	pv->u=right; pv->v=bottom; pv++;

}

void makeVertexListController() {
	rightX = -2.7999999f;
	leftX = 2.999999f;
	topY = -2.0f;
	bottomY = 2.0f;
	scaleZ = -0.9f;

	struct CustomVertex *vert=NULL,*pv=NULL;
	float dist=0.0f;
	float scalex=0.0f,scaley=0.0f;
	unsigned int colour=0x00ffffff;

	colour |= fadeColor << 24;
	float right=0.0f,bottom=0.0f;
	if(screenResizeS == 1 || screenResizeP == 1 || screenResizeI == 1 || screenResizeJ == 1 || fontResizeM == 1 || screenResizeA == 1  || screenResizeA2 == 1  || screenResizeB == 1 || screenResizeMPL == 1 || screenResizePB == 1) colour = 0x545454;

	//if (LoopMode!=8) colour=0x102040;

	dist=10.0; scalex=dist*1.3333f; scaley=dist;

	//scalex*=640.0f/(float)640;
	//scaley*=480.0f/(float)480;


	dist += scaleZ;

	vert=VertexListController;

	// Put the vertices for the corners of the screen:



	pv=vert;
	pv->z=dist;
	pv->x=-scalex + leftX + zLeftG; 
	pv->y=scaley + topY  + zTopG;
	pv->colour=colour;
	pv++;

	*pv=vert[0];
	pv->x= scalex + rightX + zRightG; 
	pv->y= scaley + topY + zTopG; 
	pv++;

	*pv=vert[0]; 
	pv->x=-scalex + leftX + zLeftG; 
	pv->y=-scaley + bottomY + zBottomG; 
	pv++;

	*pv=vert[0]; 
	pv->x= scalex + rightX + zRightG; 
	pv->y=-scaley + bottomY + zBottomG; 
	pv++;

	// Find where the screen images ends on the texture
	right = 1;//(float)EmuWidth /(float)TexWidth;
	bottom= 1;//(float)EmuHeight/(float)TexHeight;

	// Write texture coordinates:
	pv=vert;
	pv->u=0.0f;  pv->v=0.00f;  pv++;
	pv->u=right; pv->v=0.00f;  pv++;
	pv->u=0.0f;  pv->v=bottom; pv++;
	pv->u=right; pv->v=bottom; pv++;

}

void makeVertexListController2() {
	rightX = -2.7999999f;
	leftX = 2.999999f;
	topY = -2.0f;
	bottomY = 2.0f;
	scaleZ = -0.9f;

	struct CustomVertex *vert=NULL,*pv=NULL;
	float dist=0.0f;
	float scalex=0.0f,scaley=0.0f;
	unsigned int colour=0xffffffff;

	//colour |= fadeColor << 24;
	float right=0.0f,bottom=0.0f;
	if(screenResizeS == 1 || screenResizeP == 1 || screenResizeI == 1 || screenResizeJ == 1 || fontResizeM == 1 || screenResizeA == 1  || screenResizeB == 1 || screenResizeMPL == 1 || screenResizePB == 1) colour = 0x545454;

	//if (LoopMode!=8) colour=0x102040;

	dist=10.0; scalex=dist*1.3333f; scaley=dist;

	//scalex*=640.0f/(float)640;
	//scaley*=480.0f/(float)480;


	dist += scaleZ;

	vert=VertexListController;

	// Put the vertices for the corners of the screen:



	pv=vert;
	pv->z=dist;
	pv->x=-scalex + leftX + zLeftG; 
	pv->y=scaley + topY  + zTopG;
	pv->colour=colour;
	pv++;

	*pv=vert[0];
	pv->x= scalex + rightX + zRightG; 
	pv->y= scaley + topY + zTopG; 
	pv++;

	*pv=vert[0]; 
	pv->x=-scalex + leftX + zLeftG; 
	pv->y=-scaley + bottomY + zBottomG; 
	pv++;

	*pv=vert[0]; 
	pv->x= scalex + rightX + zRightG; 
	pv->y=-scaley + bottomY + zBottomG; 
	pv++;

	// Find where the screen images ends on the texture
	right = 1;//(float)EmuWidth /(float)TexWidth;
	bottom= 1;//(float)EmuHeight/(float)TexHeight;

	// Write texture coordinates:
	pv=vert;
	pv->u=0.0f;  pv->v=0.00f;  pv++;
	pv->u=right; pv->v=0.00f;  pv++;
	pv->u=0.0f;  pv->v=bottom; pv++;
	pv->u=right; pv->v=bottom; pv++;

}
extern int stransparency;
void makeVertexListControllerS() {
	rightX = -2.7999999f;
	leftX = 2.999999f;
	topY = -2.0f;
	bottomY = 2.0f;
	scaleZ = -0.9f;

	struct CustomVertex *vert=NULL,*pv=NULL;
	float dist=0.0f;
	float scalex=0.0f,scaley=0.0f;
	unsigned int colour=0xffffff;

	colour=0x00ffffff;
	//1111 1111;
	colour |= (stransparency << 24);


	float right=0.0f,bottom=0.0f;
	//if(screenResizeS == 1 || screenResizeP == 1 || screenResizeJ == 1 || screenResizeA == 1  || screenResizeB == 1 || screenResizePB == 1) colour = 0x545454;

	//if (LoopMode!=8) colour=0x102040;

	dist=10.0; scalex=dist*1.3333f; scaley=dist;

	//scalex*=640.0f/(float)640;
	//scaley*=480.0f/(float)480;


	dist += scaleZ;

	vert=VertexListController;

	// Put the vertices for the corners of the screen:



	pv=vert;
	pv->z=dist;
	pv->x=-scalex + leftX + zLeftG; 
	pv->y=scaley + topY  + zTopG;
	pv->colour=colour;
	pv++;

	*pv=vert[0];
	pv->x= scalex + rightX + zRightG; 
	pv->y= scaley + topY + zTopG; 
	pv++;

	*pv=vert[0]; 
	pv->x=-scalex + leftX + zLeftG; 
	pv->y=-scaley + bottomY + zBottomG; 
	pv++;

	*pv=vert[0]; 
	pv->x= scalex + rightX + zRightG; 
	pv->y=-scaley + bottomY + zBottomG; 
	pv++;

	// Find where the screen images ends on the texture
	right = 1;//(float)EmuWidth /(float)TexWidth;
	bottom= 1;//(float)EmuHeight/(float)TexHeight;

	// Write texture coordinates:
	pv=vert;
	pv->u=0.0f;  pv->v=0.00f;  pv++;
	pv->u=right; pv->v=0.00f;  pv++;
	pv->u=0.0f;  pv->v=bottom; pv++;
	pv->u=right; pv->v=bottom; pv++;

}
void makeVertexListLinearDark() {
	rightX = 0;//-2.7999999f;
	leftX = 0;//2.999999f;
	topY = 0;//-4.0f;
	bottomY = 0;//4.0f;
	scaleZ = -0.9f;

	struct CustomVertex *vert=NULL,*pv=NULL;
	float dist=0.0f;
	float scalex=0.0f,scaley=0.0f;
	unsigned int colour=0xffffff;
	//colour /= 2;
	float right=0.0f,bottom=0.0f;


	//if (LoopMode!=8) colour=0x102040;

	dist=10.0; scalex=dist*1.3333f; scaley=dist;

	//scalex*=640.0f/(float)640;
	//scaley*=480.0f/(float)480;


	dist += scaleZ;

	vert=VertexListLinear;

	// Put the vertices for the corners of the screen:



	pv=vert;
	pv->z=dist;
	pv->x=-scalex + zLeft; pv->y=scaley  + zTop;
	pv->colour=colour; pv++;

	*pv=vert[0]; pv->x= scalex + zRight; pv->y= scaley  + zTop; pv++;
	*pv=vert[0]; pv->x=-scalex + zLeft; pv->y=-scaley + zBottom; pv++;
	*pv=vert[0]; pv->x= scalex + zRight; pv->y=-scaley  + zBottom; pv++;

	// Find where the screen images ends on the texture
	right = 640.0f;//(float)EmuWidth /(float)TexWidth;
	bottom= 480.0f;//(float)EmuHeight/(float)TexHeight;

	// Write texture coordinates:
	pv=vert;
	pv->u=0.0f;  pv->v=0.00f;  pv++;
	pv->u=right; pv->v=0.00f;  pv++;
	pv->u=0.0f;  pv->v=bottom; pv++;
	pv->u=right; pv->v=bottom; pv++;

}

void makeVertexListLinear() {
	rightX = 0;//-2.7999999f;
	leftX = 0;//2.999999f;
	topY = 0;//-4.0f;
	bottomY = 0;//4.0f;
	scaleZ = -0.9f;

	struct CustomVertex *vert=NULL,*pv=NULL;
	float dist=0.0f;
	float scalex=0.0f,scaley=0.0f;
	unsigned int colour=0xffffff;
	if(dimColor && screenResize == 1)colour=0x545454;
	float right=0.0f,bottom=0.0f;


	//if (LoopMode!=8) colour=0x102040;

	dist=10.0; scalex=dist*1.3333f; scaley=dist;

	//scalex*=640.0f/(float)640;
	//scaley*=480.0f/(float)480;


	dist += scaleZ;

	vert=VertexListLinear;

	// Put the vertices for the corners of the screen:



	pv=vert;
	pv->z=dist;
	pv->x=-scalex + zLeft;
	pv->y=scaley + zTop;
	pv->colour=colour; pv++;

	*pv=vert[0]; pv->x= scalex  + zRight; pv->y= scaley + zTop; pv++;
	*pv=vert[0]; pv->x=-scalex  + zLeft; pv->y=-scaley  + zBottom; pv++;
	*pv=vert[0]; pv->x= scalex  + zRight; pv->y=-scaley +  zBottom; pv++;

	// Find where the screen images ends on the texture
	right = 640.0f;//(float)EmuWidth /(float)TexWidth;
	bottom= 480.0f;//(float)EmuHeight/(float)TexHeight;

	// Write texture coordinates:
	pv=vert;

	if(flipScreen == 1) {
		pv->u=right;//0.0f;  
		pv->v=0.00f; 
		pv++;
		
		pv->u=0;//right; 
		pv->v=0.00f;  

		pv++;
		pv->u=right;//0.0f;  
		pv->v=bottom; 
		pv++;

		pv->u=0;//right; 
		pv->v=bottom; 
	//pv++;
	}
	else {
		pv->u=0.0f;  
		pv->v=0.00f; 
		pv++;
		
		pv->u=right; 
		pv->v=0.00f;  

		pv++;
		pv->u=0.0f;  
		pv->v=bottom; 
		pv++;

		pv->u=right; 
		pv->v=bottom; 
	}
	
	
	
	
	/*
	pv->u=0.0f;  
	pv->v=0.00f; 
	pv++;
	
	pv->u=right; 
	pv->v=0.00f;  

	pv++;
	pv->u=0.0f;  
	pv->v=bottom; 
	pv++;

	pv->u=right; 
	pv->v=bottom; 
	*/

}

float    zLeftScale=0;
float 	zRightScale=0;
float 	zTopScale=0;
float 	zBottomScale=0;

int firstExit = 0;
//vert=VertexListPreview2;
// Find where the screen images ends on the texture
//right = 640.0f;//(float)EmuWidth /(float)TexWidth;
//bottom= 480.0f;//(float)EmuHeight/(float)TexHeight;

float leftMove = 0;
float rightMove = 0;
float topMove = 0;
float bottomMove = 0;
int zoomOver = 0;
void makeVertexListExitGame() {
	if(inGame == 0) return;


	scaleZ = -0.9f;

	struct CustomVertex *vert=NULL,*pv=NULL;
	float dist=0.0f;
	float scalex=0.0f,scaley=0.0f;
	unsigned int colour=0xffffff;
	float right=0.0f,bottom=0.0f;

	dist=10.0; scalex=dist*1.3333f; scaley=dist;
	dist += scaleZ;
	vert=VertexListPreview2;


	if((zLeftScale) >= zLeftB) { zLeftScale = zLeftB; zoomOver++; }
	if((zLeftScale) < zLeftB) {
		zLeftScale += leftMove;
		if((zLeftScale) >= zLeftB) {
			zLeftScale = zLeftB;
			zoomOver++;
		}
	}

	if((zRightScale) <= zRightB) { zRightScale = zRightB; zoomOver++; }
	if((zRightScale) > zRightB) {
		zRightScale -= rightMove;
		if((zRightScale) <= zRightB) {
			zRightScale = zRightB; 
			zoomOver++;
		}
	}

	if((zTopScale) <= zTopB) { zTopScale = zTopB; zoomOver++; }
	if((zTopScale) > zTopB) {
		zTopScale -= topMove;
		if((zTopScale) <= zTopB) {
			zoomOver++;
			zTopScale = zTopB;
		}
	}

	if((zBottomScale) >= zBottomB) { zBottomScale = zBottomB; zoomOver++; }
	if((zBottomScale) < zBottomB) {
		zBottomScale += bottomMove;
		if((zBottomScale) >= zBottomB) {
			zBottomScale = zBottomB;
			zoomOver++;
		}
	}



	pv=vert;
	pv->z=dist;
	pv->x=zLeftScale;
	pv->y=zTopScale;
	pv->colour=colour; pv++;

	*pv=vert[0]; pv->x=  zRightScale; pv->y=  zTopScale; pv++;
	*pv=vert[0]; pv->x=zLeftScale; pv->y=zBottomScale; pv++;
	*pv=vert[0]; pv->x= zRightScale; pv->y=zBottomScale; pv++;


	// Find where the screen images ends on the texture
	right = 640.0f;//(float)EmuWidth /(float)TexWidth;
	bottom= 480.0f;//(float)EmuHeight/(float)TexHeight;

	// Write texture coordinates:
	pv=vert;
	pv->u=0.0f;  pv->v=0.00f;  pv++;
	pv->u=right; pv->v=0.00f;  pv++;
	pv->u=0.0f;  pv->v=bottom; pv++;
	pv->u=right; pv->v=bottom; pv++;
	return;

}

float zA = 0;

float distA = 0.0095;
float minA = -0.20;
float maxA = -0.80f;

float cMove = -0.5;
float lMove = -1 * distA;
float rMove = distA;
float tMove = distA;
float bMove = -1 * distA;
extern int animateFrame();
void makeAnimatedVertexList() {
	rightX = -2.7999999f;
	leftX = 2.999999f;
	topY = -2.0f;
	bottomY = 2.0f;
	scaleZ = -0.9f;

	struct CustomVertex *vert=NULL,*pv=NULL;
	float dist=0.0f;
	float scalex=0.0f,scaley=0.0f;
//	unsigned int colour=0xffffff;
	float right=0.0f,bottom=0.0f;

	//PREVIEW-----------------------------------------------------------
	dist=10.0f; scalex=dist*1.3333f; scaley=dist;
	vert=AnimatedVertexList;

	if(screenResizeA == 0) {
		if(animateFrame() == 1) {

			zLeftA += lMove;
			zRightA += rMove;
			zTopA += tMove;
			zBottomA += bMove;
			cMove += distA;

			if(cMove >= minA || cMove <= maxA) {
				cMove = -0.5;
				lMove = -lMove;
				rMove = -rMove;
				tMove = -tMove;
				bMove = -bMove;
			}
		}
	}

	dist += 1.5;//scaleZ2;
	//dist += scaleZ;
	// Put the vertices for the corners of the screen:
	pv=vert;


	pv->z=dist;
	pv->x= -0.1f + 0.2f + zLeftA; 
	pv->y=5.4f+1.25f + zTopA;// + topY;
	pv->colour=0xffffffff; 
	pv++;

	*pv=vert[0]; 
	pv->x= 12.1f + zRightA;// + rightX; 
	pv->y= 5.4f+1.25f + zTopA;//+ topY; 
	pv++;

	*pv=vert[0];
	pv->x=-0.1f + 0.2f + zLeftA; 
	pv->y=-4.0+1.25f + zBottomA;// + bottomY; 
	pv++;

	*pv=vert[0]; 
	pv->x= 12.1f  + zRightA;// + rightX; 
	pv->y=-4.0+1.25f + zBottomA;// + bottomY; 
	pv++;

	// Find where the screen images ends on the texture
	right = 1;//(float)EmuWidth /(float)TexWidth;
	bottom= 1;//(float)EmuHeight/(float)TexHeight;

	// Write texture coordinates:
	pv=vert;
	pv->u=0.0f;  pv->v=0.00f;  pv++;
	pv->u=right; pv->v=0.00f;  pv++;
	pv->u=0.0f;  pv->v=bottom; pv++;
	pv->u=right; pv->v=bottom; pv++;
	return;

}




float distA2 = 0.0095;
float minA2 = -0.20;
float maxA2 = -0.80f;

float cMoveR = -0.5;
float lMoveR = -1 * distA2;
float rMoveR = distA2;
float tMoveR = distA2;
float bMoveR = -1 * distA2;
extern int animateFramej();
extern LARGE_INTEGER ticksPerSecondj;
void makeAnimatedVertexListR() {
	rightX = -2.7999999f;
	leftX = 2.999999f;
	topY = -2.0f;
	bottomY = 2.0f;
	scaleZ = -0.9f;

	struct CustomVertex *vert=NULL,*pv=NULL;
	float dist=0.0f;
	float scalex=0.0f,scaley=0.0f;
	float right=0.0f,bottom=0.0f;

	//PREVIEW-----------------------------------------------------------
	dist=10.0f; scalex=dist*1.3333f; scaley=dist;
	vert=AnimatedVertexList;

	if(screenResizeA2 == 0) {
		if(animateFramej() == 1) {

			zLeftAR += lMoveR;
			zRightAR += rMoveR;
			zTopAR += tMoveR;
			zBottomAR += bMoveR;
			cMoveR += distA2;

			if(cMoveR >= minA2 || cMoveR <= maxA2) {
				cMoveR = -0.5;
				lMoveR = -lMoveR;
				rMoveR = -rMoveR;
				tMoveR = -tMoveR;
				bMoveR = -bMoveR;
			}
		}
	}

	dist += 1.5;//scaleZ2;
	//dist += scaleZ;
	// Put the vertices for the corners of the screen:
	pv=vert;


	pv->z=dist;
	pv->x= -0.1f + 0.2f + zLeftAR; 
	pv->y=5.4f+1.25f + zTopAR;// + topY;
	pv->colour=0xffffffff; 
	pv++;

	*pv=vert[0]; 
	pv->x= 12.1f + zRightAR;// + rightX; 
	pv->y= 5.4f+1.25f + zTopAR;//+ topY; 
	pv++;

	*pv=vert[0];
	pv->x=-0.1f + 0.2f + zLeftAR; 
	pv->y=-4.0+1.25f + zBottomAR;// + bottomY; 
	pv++;

	*pv=vert[0]; 
	pv->x= 12.1f  + zRightAR;// + rightX; 
	pv->y=-4.0+1.25f + zBottomAR;// + bottomY; 
	pv++;

	// Find where the screen images ends on the texture
	right = 1;//(float)EmuWidth /(float)TexWidth;
	bottom= 1;//(float)EmuHeight/(float)TexHeight;

	// Write texture coordinates:
	pv=vert;
	pv->u=0.0f;  pv->v=0.00f;  pv++;
	pv->u=right; pv->v=0.00f;  pv++;
	pv->u=0.0f;  pv->v=bottom; pv++;
	pv->u=right; pv->v=bottom; pv++;
	return;

}




extern float getLightGunY();
extern float getLightGunX();
extern int mX;
extern int mY;
extern int oldmX;
extern int oldmY;
extern "C" {
	extern unsigned char mousexloc;
	extern unsigned char mouseyloc;
}
void drawLightgunInfo() {
	return;
}





void makePB() {
	rightX = -2.7999999f;
	leftX = 2.999999f;
	topY = -2.0f;
	bottomY = 2.0f;
	scaleZ = -0.9f;

	struct CustomVertex *vert=NULL,*pv=NULL;
	float dist=0.0f;
	float scalex=0.0f,scaley=0.0f;
	float right=0.0f,bottom=0.0f;
	dist=10.0f; scalex=dist*1.3333f; scaley=dist;
	vert=VertexListPreviewBorder;

	dist += 1.5;//scaleZ2;
	//dist += scaleZ;
	// Put the vertices for the corners of the screen:
	pv=vert;


	pv->z=dist;
	pv->x= -0.1f + 0.2f + zLeftPB; 
	pv->y=5.4f+1.25f + zTopPB;// + topY;
	pv->colour=0xffffffff; 
	pv++;

	*pv=vert[0]; 
	pv->x= 12.1f + zRightPB;// + rightX; 
	pv->y= 5.4f+1.25f + zTopPB;//+ topY; 
	pv->colour=0xffffffff; 
	pv++;

	*pv=vert[0];
	pv->x=-0.1f + 0.2f + zLeftPB; 
	pv->y=-4.0+1.25f + zBottomPB;// + bottomY; 
	pv->colour=0xffffffff; 
	pv++;

	*pv=vert[0]; 
	pv->x= 12.1f  + zRightPB;// + rightX; 
	pv->y=-4.0+1.25f + zBottomPB;// + bottomY; 
	pv->colour=0xffffffff; 
	pv++;

	// Find where the screen images ends on the texture
	right = 1;//(float)EmuWidth /(float)TexWidth;
	bottom= 1;//(float)EmuHeight/(float)TexHeight;

	// Write texture coordinates:
	pv=vert;
	pv->u=0.0f;  pv->v=0.00f;  pv++;
	pv->u=right; pv->v=0.00f;  pv++;
	pv->u=0.0f;  pv->v=bottom; pv++;
	pv->u=right; pv->v=bottom; pv++;
}


void makeStationaryAnimatedVertexList() {
	rightX = -2.7999999f;
	leftX = 2.999999f;
	topY = -2.0f;
	bottomY = 2.0f;
	scaleZ = -0.9f;

	struct CustomVertex *vert=NULL,*pv=NULL;
	float dist=0.0f;
	float scalex=0.0f,scaley=0.0f;
	float right=0.0f,bottom=0.0f;

	//PREVIEW-----------------------------------------------------------
	dist=10.0f; scalex=dist*1.3333f; scaley=dist;
	vert=StationaryAnimatedVertexList;
	dist += 1.5;//scaleZ2;
	//dist += scaleZ;
	// Put the vertices for the corners of the screen:
	pv=vert;


	pv->z=dist;
	pv->x= -0.1f + 0.2f + zLeftS + zA; 
	pv->y=5.4f+1.25f + zTopS;// + topY;
	pv->colour=0xffffffff; 
	pv++;

	*pv=vert[0]; 
	pv->x= 12.1f + (zRightS) + zA;// + rightX; 
	pv->y= 5.4f+1.25f + zTopS;//+ topY; 
	pv++;

	*pv=vert[0];
	pv->x=-0.1f + 0.2f + zLeftS + zA; 
	pv->y=-4.0+1.25f + zBottomS;// + bottomY; 
	pv++;

	*pv=vert[0]; 
	pv->x= 12.1f  + (zRightS)+ zA;// + rightX; 
	pv->y=-4.0+1.25f + zBottomS;// + bottomY; 
	pv++;

	// Find where the screen images ends on the texture
	right = 1;//(float)EmuWidth /(float)TexWidth;
	bottom= 1;//(float)EmuHeight/(float)TexHeight;

	// Write texture coordinates:
	pv=vert;
	pv->u=0.0f;  pv->v=0.00f;  pv++;
	pv->u=right; pv->v=0.00f;  pv++;
	pv->u=0.0f;  pv->v=bottom; pv++;
	pv->u=right; pv->v=bottom; pv++;
	return;

}

extern int showTransparency;
extern int transparency;
int MakeVertexList()
{
	rightX = -2.7999999f;
	leftX = 2.999999f;
	topY = -2.0f;
	bottomY = 2.0f;
	scaleZ = -0.9f;

	struct CustomVertex *vert=NULL,*pv=NULL;
	float dist=0.0f;
	float scalex=0.0f,scaley=0.0f;
	unsigned int colour=0x00ffffff;
	colour |= fadeColor2 << 24;
	float right=0.0f,bottom=0.0f;

	//if (LoopMode!=8) colour=0x102040;

	dist=10.0; scalex=dist*1.3333f; scaley=dist;

	//scalex*=640.0f/(float)640;
	//scaley*=480.0f/(float)480;


	dist += scaleZ;

	vert=VertexList;

	// Put the vertices for the corners of the screen:
	pv=vert;

	pv->z=dist;
	pv->x=-scalex + leftX + zLeftG; 
	pv->y=scaley + topY  + zTopG;
	pv->colour=colour;
	pv++;

	*pv=vert[0];
	pv->x= scalex + rightX + zRightG; 
	pv->y= scaley + topY + zTopG; 
	pv++;

	*pv=vert[0]; 
	pv->x=-scalex + leftX + zLeftG; 
	pv->y=-scaley + bottomY + zBottomG; 
	pv++;

	*pv=vert[0]; 
	pv->x= scalex + rightX + zRightG; 
	pv->y=-scaley + bottomY + zBottomG; 
	pv++;

	// Find where the screen images ends on the texture
	right = 1;//(float)EmuWidth /(float)TexWidth;
	bottom= 1;//(float)EmuHeight/(float)TexHeight;

	// Write texture coordinates:
	pv=vert;
	pv->u=0.0f;  pv->v=0.00f;  pv++;
	pv->u=right; pv->v=0.00f;  pv++;
	pv->u=0.0f;  pv->v=bottom; pv++;
	pv->u=right; pv->v=bottom; pv++;

	//PREVIEW-----------------------------------------------------------


	float resize = 1.0f;


	if(useNoRom == false) {
		D3DSURFACE_DESC desc;
		TexPreview->GetLevelDesc( 0, &desc );
		DWORD dwTexWidth  = desc.Width;
		DWORD dwTexHeight = desc.Height;
		if(showTransparency) { 
			colour=0x00ffffff;//0xc8ffffff
			//1111 1111;
			colour |= (transparency << 24);
		}
		else {
			colour=0xffffffff;
		}
		if(dwTexWidth < dwTexHeight) {
			dist=10.0f; scalex=dist*1.3333f; scaley=dist;
			vert=VertexListPreview;


			dist += 1.5;//scaleZ2;
			//dist += scaleZ;
			// Put the vertices for the corners of the screen:
			pv=vert;

			pv->z=dist;
			pv->x= (-0.1f + 0.2f + zLeftJ) * resize; 
			pv->y=5.4f+1.25f + zTopJ;// + topY;
			pv->colour=colour; 
			pv++;

			*pv=vert[0]; 
			pv->x= (12.1f + zRightJ) * resize;// + rightX; 
			pv->y= 5.4f+1.25f + zTopJ;//+ topY; 
			pv->colour=colour; 
			pv++;

			*pv=vert[0];
			pv->x=(-0.1f + 0.2f + zLeftJ) * resize; 
			pv->y=-4.0+1.25f + zBottomJ;// + bottomY; 
			pv->colour=colour; 
			pv++;

			*pv=vert[0]; 
			pv->x= (12.1f  + zRightJ) * resize;// + rightX; 
			pv->y=-4.0+1.25f + zBottomJ;// + bottomY; 
			pv->colour=colour; 
			pv++;

			// Find where the screen images ends on the texture
			right = 1;//(float)EmuWidth /(float)TexWidth;
			bottom= 1;//(float)EmuHeight/(float)TexHeight;

			// Write texture coordinates:
			pv=vert;
			pv->u=0.0f;  pv->v=0.00f;  pv++;
			pv->u=right; pv->v=0.00f;  pv++;
			pv->u=0.0f;  pv->v=bottom; pv++;
			pv->u=right; pv->v=bottom; pv++;
			return 0;	

		}
		else {
			dist=10.0f; scalex=dist*1.3333f; scaley=dist;
			vert=VertexListPreview;

			dist += 1.5;//scaleZ2;
			//dist += scaleZ;
			// Put the vertices for the corners of the screen:
			pv=vert;

			pv->z=dist;
			pv->x= (-0.1f + 0.2f + zLeftP) * resize; 
			pv->y=5.4f+1.25f + zTopP;// + topY;
			pv->colour=colour; 
			pv++;

			*pv=vert[0]; 
			pv->x= (12.1f + zRightP) * resize;// + rightX; 
			pv->y= 5.4f+1.25f + zTopP;//+ topY; 
			pv->colour=colour; 
			pv++;

			*pv=vert[0];
			pv->x=(-0.1f + 0.2f + zLeftP) * resize; 
			pv->y=-4.0+1.25f + zBottomP;// + bottomY; 
			pv->colour=colour; 
			pv++;

			*pv=vert[0]; 
			pv->x= (12.1f  + zRightP) * resize;// + rightX; 
			pv->y=-4.0+1.25f + zBottomP;// + bottomY; 
			pv->colour=colour; 
			pv++;

			// Find where the screen images ends on the texture
			right = 1;//(float)EmuWidth /(float)TexWidth;
			bottom= 1;//(float)EmuHeight/(float)TexHeight;

			// Write texture coordinates:
			pv=vert;
			pv->u=0.0f;  pv->v=0.00f;  pv++;
			pv->u=right; pv->v=0.00f;  pv++;
			pv->u=0.0f;  pv->v=bottom; pv++;
			pv->u=right; pv->v=bottom; pv++;
			return 0;
		}
	}


	dist=10.0f; scalex=dist*1.3333f; scaley=dist;
	vert=VertexListPreview;

	dist += 1.5;//scaleZ2;
	//dist += scaleZ;
	// Put the vertices for the corners of the screen:
	pv=vert;


	pv->z=dist;
	pv->x= (-0.1f + 0.2f + zLeftP) * resize; 
	pv->y=5.4f+1.25f + zTopP;// + topY;
	pv->colour=colour; 
	pv++;

	*pv=vert[0]; 
	pv->x= (12.1f + zRightP) * resize;// + rightX; 
	pv->y= 5.4f+1.25f + zTopP;//+ topY; 
	pv++;

	*pv=vert[0];
	pv->x=(-0.1f + 0.2f + zLeftP) * resize; 
	pv->y=-4.0+1.25f + zBottomP;// + bottomY; 
	pv++;

	*pv=vert[0]; 
	pv->x= (12.1f  + zRightP) * resize;// + rightX; 
	pv->y=-4.0+1.25f + zBottomP;// + bottomY; 
	pv++;

	// Find where the screen images ends on the texture
	right = 1;//(float)EmuWidth /(float)TexWidth;
	bottom= 1;//(float)EmuHeight/(float)TexHeight;

	// Write texture coordinates:
	pv=vert;
	pv->u=0.0f;  pv->v=0.00f;  pv++;
	pv->u=right; pv->v=0.00f;  pv++;
	pv->u=0.0f;  pv->v=bottom; pv++;
	pv->u=right; pv->v=bottom; pv++;












	dist=10.0f; scalex=dist*1.3333f; scaley=dist;
	vert=VertexListPreviewBorder;

	dist += 1.5;//scaleZ2;
	//dist += scaleZ;
	// Put the vertices for the corners of the screen:
	pv=vert;


	pv->z=dist;
	pv->x= -0.1f + 0.2f + zLeftPB; 
	pv->y=5.4f+1.25f + zTopPB;// + topY;
	pv->colour=0xffffffff; 
	pv++;

	*pv=vert[0]; 
	pv->x= 12.1f + zRightPB;// + rightX; 
	pv->y= 5.4f+1.25f + zTopPB;//+ topY; 
	pv->colour=0xffffffff; 
	pv++;

	*pv=vert[0];
	pv->x=-0.1f + 0.2f + zLeftPB; 
	pv->y=-4.0+1.25f + zBottomPB;// + bottomY; 
	pv->colour=0xffffffff; 
	pv++;

	*pv=vert[0]; 
	pv->x= 12.1f  + zRightPB;// + rightX; 
	pv->y=-4.0+1.25f + zBottomPB;// + bottomY; 
	pv->colour=0xffffffff; 
	pv++;

	// Find where the screen images ends on the texture
	right = 1;//(float)EmuWidth /(float)TexWidth;
	bottom= 1;//(float)EmuHeight/(float)TexHeight;

	// Write texture coordinates:
	pv=vert;
	pv->u=0.0f;  pv->v=0.00f;  pv++;
	pv->u=right; pv->v=0.00f;  pv++;
	pv->u=0.0f;  pv->v=bottom; pv++;
	pv->u=right; pv->v=bottom; pv++;




	makeVertexListLinear();
	makeVertexListResize();
	makeVertexListController();
	makeVertexListOptions();

	return 0;
}

int DirectClear(unsigned int colour)
{
	Device->Clear(0,NULL,D3DCLEAR_TARGET,0x0,1.0f,0);
	return 0;
}
extern int showAvailMemory;
extern void showMemory();
int DirectPresent()
{
	//showMemory();
	if(showAvailMemory) showMemory();
	Device->Present(NULL,NULL,NULL,NULL);
#ifdef _XBOX  

#endif
	return 0;
}

int SetupMatrices()
{
	D3DXVECTOR3 eye ( 0.0f, 0.0f, 0.0f );
	D3DXVECTOR3 look( 0.0f, 0.0f, 0.0f );
	D3DXVECTOR3 up  ( 0.0f, 1.0f, 0.0f );
	D3DXMATRIX mat;
	memset(&mat,0,sizeof(mat));
	mat.m[0][0]=mat.m[1][1]=mat.m[2][2]=mat.m[3][3]=1.0f;

	Device->SetTransform(D3DTS_WORLD,&mat);

	look.x= 0;//(float)Inp.axis[2]/2457.6f;
	look.y= 0;//(float)Inp.axis[3]/2457.6f;
	look.z=10.0f;

	// Nudge pixels to the centre of each screen pixel:
	nudgex=13.3333f/(float)(MainWidth <<1);
	nudgey=10.0000f/(float)(MainHeight<<1);
	eye.x +=nudgex; eye.y +=nudgey;
	look.x+=nudgex; look.y+=nudgey;

	D3DXMatrixLookAtLH(&mat,&eye,&look,&up);
	Device->SetTransform(D3DTS_VIEW,&mat);

	D3DXMatrixPerspectiveFovLH(&mat, 0.5f*PI, 1.3333f, 0.2f, 1000.0f);
	Device->SetTransform(D3DTS_PROJECTION,&mat);


	/*D3DXMATRIX ortho;
	D3DXMATRIX identity;
	D3DXMatrixOrthoLH(&ortho, sWidth, sHeight, 0, 1);
	D3DXMatrixIdentity(&identity);
	Device->SetTransform(D3DTS_PROJECTION,&ortho);
	Device->SetTransform(D3DTS_WORLD,&identity);
	Device->SetTransform(D3DTS_VIEW,&identity);*/



	return 0;
}



void setTextureMode() {
	Device->SetTextureStageState( 0, D3DTSS_COLOROP,   D3DTOP_MODULATE );
	Device->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE );
	Device->SetTextureStageState( 0, D3DTSS_COLORARG2, D3DTA_DIFFUSE );
	Device->SetTextureStageState( 0, D3DTSS_ALPHAOP,   D3DTOP_MODULATE );
	Device->SetTextureStageState( 0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE );
	Device->SetTextureStageState( 0, D3DTSS_ALPHAARG2, D3DTA_DIFFUSE );
	Device->SetTextureStageState( 1, D3DTSS_COLOROP,   D3DTOP_DISABLE );
	Device->SetTextureStageState( 1, D3DTSS_ALPHAOP,   D3DTOP_DISABLE );
	Device->SetTextureStageState( 0, D3DTSS_ADDRESSU,  D3DTADDRESS_CLAMP );
	Device->SetTextureStageState( 0, D3DTSS_ADDRESSV,  D3DTADDRESS_CLAMP );
	Device->SetRenderState( D3DRS_ZENABLE,      FALSE );
	Device->SetRenderState( D3DRS_FOGENABLE,    FALSE );
	Device->SetRenderState( D3DRS_FOGTABLEMODE, D3DFOG_NONE );
	Device->SetRenderState( D3DRS_FILLMODE,     D3DFILL_SOLID );
	Device->SetRenderState( D3DRS_CULLMODE,     D3DCULL_CCW );
	Device->SetRenderState( D3DRS_SRCBLEND,  D3DBLEND_SRCALPHA );
	Device->SetRenderState( D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA );
	Device->SetVertexShader( D3DFVF_XYZRHW|D3DFVF_DIFFUSE|D3DFVF_TEX1);
}


extern void resumeMusic();
struct CustomVertex *vertResize=NULL;
struct CustomVertex *vertController=NULL;
struct CustomVertex *vertOptions=NULL;
struct CustomVertex *vertScreen=NULL;

extern unsigned char SoftwareFilter;
extern "C" {
	extern unsigned char Surround;
}

int HardwareFilter = 2;
int FlickerFilter = 0;
int SoundFrequency = 0;
int Soften = 0;
int SoundInterpolation = 0;
int LowPassFilter = 0;
int DisableSaveStates = 0;
int inGame = 0;
int optionSelected = 6;
int optionSelectedM = 0;
int SurroundSound = 0;
unsigned char *lock=NULL;

float freeMemory() {
	MEMORYSTATUS stat;
	// Get the memory status.
	GlobalMemoryStatus( &stat );
	return (((float)stat.dwAvailPhys) / 1000000);
}
void showMemory() {
	int xO = 255;
	int yO = 40;
	MEMORYSTATUS stat;
	// Get the memory status.
	GlobalMemoryStatus( &stat );
	WCHAR text23456789_[80]={0};
	float t = (((float)stat.dwAvailPhys) / 1000000);
	wsprintfW(text23456789_, L"Free Memory: %4f MB", t);
	FontSetColour(0xffffff);
	FontSmallText(text23456789_,xO,yO, 600);
	yO+=vSpace;
	return;
}
extern int Disable34;

extern "C" {
	extern unsigned char ForceROMTiming;
}

int DisableMenuSounds = 0;
int MapControllers = 0;
int ShowFPS = 0;
extern void drawControllerMenu();
extern void drawVideoOptionsMenu();
extern void drawSoundOptionsMenu();
extern void drawCheatOptionsMenu();
extern float getVolume();
extern void drawGUIOptions();
extern int showAvailMemory;
extern bool useNoBox;
extern bool useNoState;
extern int animateStationaryFrame();
extern int animateStationaryFrame2();
int currentStationaryFrame = 0;
int errorFound = 0;
std::string errorMessage;

int firstFrame = 0;
int DirectScreen()
{


	

	makePB();
	setTextureMode();
	Device->SetRenderState(D3DRS_LIGHTING,0); // Turn off lighting
	SetupMatrices();

	if(splash == 1) {
		unsigned char *lock=NULL;
		setTextureMode();
		if(firstFrame == 1) {
			makeVertexListController();
			VertexBufferController->Lock(0,sizeof(VertexList),&lock,0); if (lock==NULL) return 1;
			memcpy(lock,VertexListController,sizeof(VertexList));
			VertexBufferController->Unlock();
			Device->SetTexture(0,TexMainMenu); 
			Device->SetStreamSource(0,VertexBufferController,sizeof(CustomVertex));
			Device->SetVertexShader(D3DFVF_CUSTOMVERTEX);
			Device->DrawPrimitive(D3DPT_TRIANGLESTRIP,0,2);


			Device->SetRenderState(D3DRS_ALPHABLENDENABLE,TRUE);
			makeVertexListControllerS();
			VertexBufferController->Lock(0,sizeof(VertexList),&lock,0); if (lock==NULL) return 1;
			memcpy(lock,VertexListController,sizeof(VertexList));
			VertexBufferController->Unlock();
			Device->SetTexture(0,TexSplashFinal); 
			Device->SetStreamSource(0,VertexBufferController,sizeof(CustomVertex));
			Device->SetVertexShader(D3DFVF_CUSTOMVERTEX);
			Device->DrawPrimitive(D3DPT_TRIANGLESTRIP,0,2);
			Device->SetRenderState(D3DRS_ALPHABLENDENABLE,FALSE);
		}
		else {
			Device->SetTexture(0,TexSplash); 
			Device->SetStreamSource(0,VertexBufferController,sizeof(CustomVertex));
			Device->SetVertexShader(D3DFVF_CUSTOMVERTEX);
			Device->DrawPrimitive(D3DPT_TRIANGLESTRIP,0,2);
		}
		return 0;
	}

	
	if(screenControllerOptions == 1) {
		makeVertexListController();
		unsigned char *lock=NULL;
		setTextureMode();
		makeVertexListController();
		VertexBufferController->Lock(0,sizeof(VertexList),&lock,0); if (lock==NULL) return 1;
		memcpy(lock,VertexListController,sizeof(VertexList));
		VertexBufferController->Unlock();
		Device->SetTexture(0,TexController); 
		Device->SetStreamSource(0,VertexBufferController,sizeof(CustomVertex));
		Device->SetVertexShader(D3DFVF_CUSTOMVERTEX);
		Device->DrawPrimitive(D3DPT_TRIANGLESTRIP,0,2);
		drawControllerMenu();
		return 0;
	}

	if(screenVideoOptions == 1) {
		unsigned char *lock=NULL;
		setTextureMode();
		makeVertexListController();
		VertexBufferController->Lock(0,sizeof(VertexList),&lock,0); if (lock==NULL) return 1;
		memcpy(lock,VertexListController,sizeof(VertexList));
		VertexBufferController->Unlock();
		Device->SetTexture(0,TexController); 
		Device->SetStreamSource(0,VertexBufferController,sizeof(CustomVertex));
		Device->SetVertexShader(D3DFVF_CUSTOMVERTEX);
		Device->DrawPrimitive(D3DPT_TRIANGLESTRIP,0,2);
		drawVideoOptionsMenu();
		return 0;
	}

	if(screenCheatOptions == 1) {
		unsigned char *lock=NULL;
		setTextureMode();
		makeVertexListController();
		VertexBufferController->Lock(0,sizeof(VertexList),&lock,0); if (lock==NULL) return 1;
		memcpy(lock,VertexListController,sizeof(VertexList));
		VertexBufferController->Unlock();
		Device->SetTexture(0,TexController); 
		Device->SetStreamSource(0,VertexBufferController,sizeof(CustomVertex));
		Device->SetVertexShader(D3DFVF_CUSTOMVERTEX);
		Device->DrawPrimitive(D3DPT_TRIANGLESTRIP,0,2);
		drawCheatOptionsMenu();
		return 0;
	}


	if(archiveMode == 1) {
		unsigned char *lock=NULL;
		setTextureMode();
		makeVertexListController();
		VertexBufferController->Lock(0,sizeof(VertexList),&lock,0); if (lock==NULL) return 1;
		memcpy(lock,VertexListController,sizeof(VertexList));
		VertexBufferController->Unlock();
		Device->SetTexture(0,TexController); 
		Device->SetStreamSource(0,VertexBufferController,sizeof(CustomVertex));
		Device->SetVertexShader(D3DFVF_CUSTOMVERTEX);
		Device->DrawPrimitive(D3DPT_TRIANGLESTRIP,0,2);
		/*WCHAR text2345[280]={0};
		wsprintfW(text2345,L"Press \"B\" to exit.");
		FontSetColour(0xffff00);
		FontSmallText(text2345,sWidth/2,70, 600);	*/
		drawListOfArchiveGames();
		
		return 0;
	}

	if(screenSoundOptions == 1) {
		unsigned char *lock=NULL;
		setTextureMode();
		makeVertexListController();
		VertexBufferController->Lock(0,sizeof(VertexList),&lock,0); if (lock==NULL) return 1;
		memcpy(lock,VertexListController,sizeof(VertexList));
		VertexBufferController->Unlock();
		Device->SetTexture(0,TexController); 
		Device->SetStreamSource(0,VertexBufferController,sizeof(CustomVertex));
		Device->SetVertexShader(D3DFVF_CUSTOMVERTEX);
		Device->DrawPrimitive(D3DPT_TRIANGLESTRIP,0,2);

		drawSoundOptionsMenu();
		return 0;
	}

	if(screenMPOptions == 1) {
		unsigned char *lock=NULL;
		setTextureMode();
		makeVertexListController();
		VertexBufferController->Lock(0,sizeof(VertexList),&lock,0); if (lock==NULL) return 1;
		memcpy(lock,VertexListController,sizeof(VertexList));
		VertexBufferController->Unlock();
		Device->SetTexture(0,TexController); 
		Device->SetStreamSource(0,VertexBufferController,sizeof(CustomVertex));
		Device->SetVertexShader(D3DFVF_CUSTOMVERTEX);
		Device->DrawPrimitive(D3DPT_TRIANGLESTRIP,0,2);

		drawMPOptionsMenu();
		return 0;
	}

	if(screenGeneralOptions == 1) {
		unsigned char *lock=NULL;
		setTextureMode();
		makeVertexListController();
		VertexBufferController->Lock(0,sizeof(VertexList),&lock,0); if (lock==NULL) return 1;
		memcpy(lock,VertexListController,sizeof(VertexList));
		VertexBufferController->Unlock();
		Device->SetTexture(0,TexController); 
		Device->SetStreamSource(0,VertexBufferController,sizeof(CustomVertex));
		Device->SetVertexShader(D3DFVF_CUSTOMVERTEX);
		Device->DrawPrimitive(D3DPT_TRIANGLESTRIP,0,2);

		drawGeneralOptions();
		return 0;
	}

	if(screenGeneralOptionsGG == 1) {
		unsigned char *lock=NULL;
		setTextureMode();
		makeVertexListController();
		VertexBufferController->Lock(0,sizeof(VertexList),&lock,0); if (lock==NULL) return 1;
		memcpy(lock,VertexListController,sizeof(VertexList));
		VertexBufferController->Unlock();
		Device->SetTexture(0,TexController); 
		Device->SetStreamSource(0,VertexBufferController,sizeof(CustomVertex));
		Device->SetVertexShader(D3DFVF_CUSTOMVERTEX);
		Device->DrawPrimitive(D3DPT_TRIANGLESTRIP,0,2);

		drawGeneralOptionsGG();
		return 0;
	}


	if(screenGeneralOptionsTGA == 1) {
		unsigned char *lock=NULL;
		setTextureMode();
		makeVertexListController();
		VertexBufferController->Lock(0,sizeof(VertexList),&lock,0); if (lock==NULL) return 1;
		memcpy(lock,VertexListController,sizeof(VertexList));
		VertexBufferController->Unlock();
		Device->SetTexture(0,TexController); 
		Device->SetStreamSource(0,VertexBufferController,sizeof(CustomVertex));
		Device->SetVertexShader(D3DFVF_CUSTOMVERTEX);
		Device->DrawPrimitive(D3DPT_TRIANGLESTRIP,0,2);

		drawTGAList();
		return 0;
	}

	
	if(screenGeneralOptionsGGText == 1) {
		/*unsigned char *lock=NULL;
		setTextureMode();
		makeVertexListController();
		VertexBufferController->Lock(0,sizeof(VertexList),&lock,0); if (lock==NULL) return 1;
		memcpy(lock,VertexListController,sizeof(VertexList));
		VertexBufferController->Unlock();
		Device->SetTexture(0,TexController); 
		Device->SetStreamSource(0,VertexBufferController,sizeof(CustomVertex));
		Device->SetVertexShader(D3DFVF_CUSTOMVERTEX);
		Device->DrawPrimitive(D3DPT_TRIANGLESTRIP,0,2);*/

		drawGeneralOptionsGGText();
		return 0;
	}
	if(screenGeneralOptionsMP == 1) {
		unsigned char *lock=NULL;
		setTextureMode();
		makeVertexListController();
		VertexBufferController->Lock(0,sizeof(VertexList),&lock,0); if (lock==NULL) return 1;
		memcpy(lock,VertexListController,sizeof(VertexList));
		VertexBufferController->Unlock();
		Device->SetTexture(0,TexController); 
		Device->SetStreamSource(0,VertexBufferController,sizeof(CustomVertex));
		Device->SetVertexShader(D3DFVF_CUSTOMVERTEX);
		Device->DrawPrimitive(D3DPT_TRIANGLESTRIP,0,2);
		drawMPOptionsMenu();
		//Fade overlay
		Device->SetRenderState(D3DRS_ALPHABLENDENABLE,TRUE);
		if(fadeColor > 0) {
				fadeColor -=fadeSpeed;
				if(fadeColor < fadeSpeed) fadeColor = 0;
		}
		makeVertexListController();
		VertexBufferController->Lock(0,sizeof(VertexList),&lock,0); if (lock==NULL) return 1;
		memcpy(lock,VertexListController,sizeof(VertexList));
		VertexBufferController->Unlock();
		Device->SetTexture(0,TexMainMenu); 
		Device->SetStreamSource(0,VertexBufferController,sizeof(CustomVertex));
		Device->SetVertexShader(D3DFVF_CUSTOMVERTEX);
		Device->DrawPrimitive(D3DPT_TRIANGLESTRIP,0,2);
		Device->SetRenderState(D3DRS_ALPHABLENDENABLE,FALSE);
		return 0;
	}

	if(screenGUIOptions == 1) {
		unsigned char *lock=NULL;
		setTextureMode();
		makeVertexListController2();
		VertexBufferController->Lock(0,sizeof(VertexList),&lock,0); if (lock==NULL) return 1;
		memcpy(lock,VertexListController,sizeof(VertexList));
		VertexBufferController->Unlock();
		Device->SetTexture(0,TexController); 
		Device->SetStreamSource(0,VertexBufferController,sizeof(CustomVertex));
		Device->SetVertexShader(D3DFVF_CUSTOMVERTEX);
		Device->DrawPrimitive(D3DPT_TRIANGLESTRIP,0,2);


		makeVertexListController();
		Device->SetRenderState(D3DRS_ALPHABLENDENABLE,TRUE);
		if(fadeColor > 0) {
			fadeColor -=fadeSpeed;
			if(fadeColor < fadeSpeed) fadeColor = 0;
		}
		makeVertexListController();
		VertexBufferController->Lock(0,sizeof(VertexList),&lock,0); if (lock==NULL) return 1;
		memcpy(lock,VertexListController,sizeof(VertexList));
		VertexBufferController->Unlock();
		Device->SetTexture(0,TexMainMenu); 
		Device->SetStreamSource(0,VertexBufferController,sizeof(CustomVertex));
		Device->SetVertexShader(D3DFVF_CUSTOMVERTEX);
		Device->DrawPrimitive(D3DPT_TRIANGLESTRIP,0,2);
		Device->SetRenderState(D3DRS_ALPHABLENDENABLE,FALSE);

		if(gFont == 5) {
			unsigned char *lock=NULL;
			makeVertexListResizeB();
			setTextureMode();

			Device->SetRenderState(D3DRS_ALPHABLENDENABLE,TRUE);

			VertexBufferPreviewB->Lock(0,sizeof(VertexList),&lock,0); if (lock==NULL) return 1;
			memcpy(lock,VertexListPreviewB,sizeof(VertexList));
			VertexBufferPreviewB->Unlock();

			Device->SetTexture(0,TexGUIPreview);
			Device->SetStreamSource(0,VertexBufferPreviewB,sizeof(CustomVertex));
			Device->SetVertexShader(D3DFVF_CUSTOMVERTEX);
			Device->DrawPrimitive(D3DPT_TRIANGLESTRIP,0,2);

			Device->SetRenderState(D3DRS_ALPHABLENDENABLE,FALSE);

		}

		drawGUIOptions();
		return 0;
	}

	if(saveStateLoad == 1 || saveStateSave == 1) {
		unsigned char *lock=NULL;
		setTextureMode();
		makeVertexListController();
		VertexBufferController->Lock(0,sizeof(VertexList),&lock,0); if (lock==NULL) return 1;
		memcpy(lock,VertexListController,sizeof(VertexList));
		VertexBufferController->Unlock();
		Device->SetTexture(0,TexController); 
		Device->SetStreamSource(0,VertexBufferController,sizeof(CustomVertex));
		Device->SetVertexShader(D3DFVF_CUSTOMVERTEX);
		Device->DrawPrimitive(D3DPT_TRIANGLESTRIP,0,2);

		makeVertexListResizeB();
		setTextureMode();

		Device->SetRenderState(D3DRS_ALPHABLENDENABLE,TRUE);

		VertexBufferPreviewB->Lock(0,sizeof(VertexList),&lock,0); if (lock==NULL) return 1;
		memcpy(lock,VertexListPreviewB,sizeof(VertexList));
		VertexBufferPreviewB->Unlock();

		if(useNoState == false)
			Device->SetTexture(0,TexStatePreview);
		else
			Device->SetTexture(0,TexPreview2);

		Device->SetStreamSource(0,VertexBufferPreviewB,sizeof(CustomVertex));
		Device->SetVertexShader(D3DFVF_CUSTOMVERTEX);
		Device->DrawPrimitive(D3DPT_TRIANGLESTRIP,0,2);

		Device->SetRenderState(D3DRS_ALPHABLENDENABLE,FALSE);

		drawStateOptions();
		return 0;
	}

	if(screenOptionsM == 1) {
		unsigned char *lock=NULL;
		setTextureMode();
		makeVertexListController();
		VertexBufferController->Lock(0,sizeof(VertexList),&lock,0); if (lock==NULL) return 1;
		memcpy(lock,VertexListController,sizeof(VertexList));
		VertexBufferController->Unlock();
		Device->SetTexture(0,TexMainMenu); 
		Device->SetStreamSource(0,VertexBufferController,sizeof(CustomVertex));
		Device->SetVertexShader(D3DFVF_CUSTOMVERTEX);
		Device->DrawPrimitive(D3DPT_TRIANGLESTRIP,0,2);

		//drawn animated logo
		Device->SetRenderState(D3DRS_ALPHABLENDENABLE,TRUE);
		makeAnimatedVertexList();
		AnimatedVertexBuffer->Lock(0,sizeof(VertexList),&lock,0); if (lock==NULL) return 1;
		memcpy(lock,AnimatedVertexList,sizeof(VertexList));
		AnimatedVertexBuffer->Unlock();
		Device->SetTexture(0,TexLogo);
		Device->SetStreamSource(0,AnimatedVertexBuffer,sizeof(CustomVertex));
		Device->SetVertexShader(D3DFVF_CUSTOMVERTEX);
		Device->DrawPrimitive(D3DPT_TRIANGLESTRIP,0,2);
		Device->SetRenderState(D3DRS_ALPHABLENDENABLE,FALSE);

		int xO = 640/2;
		int yO = 160;
		int oSpace = vSpace;
		unsigned int c = 0x00ffffff;
		if(optionSelectedM == 0) c = menuColor[MenuOptionSelected]; else c = menuColor[MenuOption];
		WCHAR text345678_[80]={0};
		wsprintfW(text345678_,L"Select Game");
		FontSetColour(c);
		FontCenteredText(text345678_,xO+zLeftMM,yO+zTopMM, 600);
		yO += oSpace;

		if(optionSelectedM == 1) c = menuColor[MenuOptionSelected]; else c = menuColor[MenuOption];
		WCHAR stext345678_[80]={0};
		wsprintfW(stext345678_,L"Favorite Games");
		FontSetColour(c);
		FontCenteredText(stext345678_,xO+zLeftMM,yO+zTopMM, 600);
		yO += oSpace;

		if(optionSelectedM == 2) c = menuColor[MenuOptionSelected]; else c = menuColor[MenuOption];
		WCHAR kaaaatext345678_[80]={0};
		wsprintfW(kaaaatext345678_,L"Music Player");
		FontSetColour(c);
		FontCenteredText(kaaaatext345678_,xO+zLeftMM,yO+zTopMM, 600);
		yO += oSpace;

		if(optionSelectedM == 3) c = menuColor[MenuOptionSelected]; else c = menuColor[MenuOption];
		WCHAR atext345678_[80]={0};
		wsprintfW(atext345678_,L"Options");
		FontSetColour(c);
		FontCenteredText(atext345678_,xO+zLeftMM,yO+zTopMM, 600);
		yO += oSpace;


		if(optionSelectedM == 4) c = menuColor[MenuOptionSelected]; else c = menuColor[MenuOption];
		WCHAR faaatext345678_[80]={0};
		wsprintfW(faaatext345678_,L"Help");
		FontSetColour(c);
		FontCenteredText(faaatext345678_,xO+zLeftMM,yO+zTopMM, 600);
		yO += oSpace;


		if(optionSelectedM == 5) c = menuColor[MenuOptionSelected]; else c = menuColor[MenuOption];
		WCHAR aaaatext345678_[80]={0};
		wsprintfW(aaaatext345678_,L"Exit");
		FontSetColour(c);
		FontCenteredText(aaaatext345678_,xO+zLeftMM,yO+zTopMM, 600);
		yO += oSpace;
		
		if(fadeOption == 0) {
			Device->SetRenderState(D3DRS_ALPHABLENDENABLE,TRUE);
			if(fadeColor2 > 0) {
				fadeColor2 -=fadeSpeed;
				if(fadeColor2 < fadeSpeed) fadeColor2 = 0;
			}
			MakeVertexList();
			setTextureMode();
			VertexBuffer->Lock(0,sizeof(VertexList),&lock,0); if (lock==NULL) return 1;
			memcpy(lock,VertexList,sizeof(VertexList));
			VertexBuffer->Unlock();
			Device->SetTexture(0,TexMenu);
			Device->SetStreamSource(0,VertexBuffer,sizeof(CustomVertex));
			Device->SetVertexShader(D3DFVF_CUSTOMVERTEX);
			Device->DrawPrimitive(D3DPT_TRIANGLESTRIP,0,2);
			Device->SetRenderState(D3DRS_ALPHABLENDENABLE,FALSE);
		}
		else {
			Device->SetRenderState(D3DRS_ALPHABLENDENABLE,TRUE);
			if(fadeColor2 > 0) {
				fadeColor2 -=fadeSpeed;
				if(fadeColor2 < fadeSpeed) fadeColor2 = 0;
			}
			MakeVertexList();
			setTextureMode();
			VertexBuffer->Lock(0,sizeof(VertexList),&lock,0); if (lock==NULL) return 1;
			memcpy(lock,VertexList,sizeof(VertexList));
			VertexBuffer->Unlock();

			if(fadeOption == 2)
				Device->SetTexture(0,TexHelp);
			else
				Device->SetTexture(0,TexController);
			Device->SetStreamSource(0,VertexBuffer,sizeof(CustomVertex));
			Device->SetVertexShader(D3DFVF_CUSTOMVERTEX);
			Device->DrawPrimitive(D3DPT_TRIANGLESTRIP,0,2);
			Device->SetRenderState(D3DRS_ALPHABLENDENABLE,FALSE);
		}

		
		return 0;
	}

	if(screenOptions == 1) {

		unsigned char *lock=NULL;
		setTextureMode();
		makeVertexListController2();
		VertexBufferController->Lock(0,sizeof(VertexList),&lock,0); if (lock==NULL) return 1;
		memcpy(lock,VertexListController,sizeof(VertexList));
		VertexBufferController->Unlock();
		Device->SetTexture(0,TexController); 
		Device->SetStreamSource(0,VertexBufferController,sizeof(CustomVertex));
		Device->SetVertexShader(D3DFVF_CUSTOMVERTEX);
		Device->DrawPrimitive(D3DPT_TRIANGLESTRIP,0,2);

		if(inGame == 1) {
			makeVertexListExitGame();
			VertexBufferPreview2->Lock(0,sizeof(VertexListPreview2),&lock,0); if (lock==NULL) return 1;
			memcpy(lock,VertexListPreview2,sizeof(VertexListPreview2));
			VertexBufferPreview2->Unlock();
			Device->SetTexture(0,TexScreen);
			Device->SetStreamSource(0,VertexBufferPreview2,sizeof(CustomVertex));
			Device->SetVertexShader(D3DFVF_CUSTOMVERTEX);
			Device->DrawPrimitive(D3DPT_TRIANGLESTRIP,0,2);
		}


		int xO = 640/2;
		int yO = 130;
		int oSpace = vSpace;
		unsigned int c = 0x00ffffff;

		if(zoomOver >= 4) {
			/*WCHAR text2345[280]={0};
			wsprintfW(text2345,L"Press \"B\" to exit.");
			FontSetColour(0xffff00);
			FontSmallText(text2345,sWidth/2,70, 600);	*/
		}
		if(inGame == 1) {
			if(zoomOver >= 4) {
				xO = 150;
				yO = 120;
				if(optionSelected == 0) c = menuColor[MenuOptionSelected]; else c = menuColor[MenuOption];
				WCHAR text345678_[80]={0};
				wsprintfW(text345678_,L"Return to Game");
				FontSetColour(c);
				FontText(text345678_,xO+zLeftIT,yO+zTopIT, 600);
				yO += oSpace;

				if(optionSelected == 1) c = menuColor[MenuOptionSelected]; else c = menuColor[MenuOption];
				WCHAR atextb345678_[80]={0};
				wsprintfW(atextb345678_,L"Reset Game");
				FontSetColour(c);
				FontText(atextb345678_,xO+zLeftIT,yO+zTopIT, 600);
				yO += oSpace;

				if(optionSelected == 2) c = menuColor[MenuOptionSelected]; else c = menuColor[MenuOption];
				
				WCHAR texta345678_[80]={0};
				wsprintfW(texta345678_,L"Save State");
				FontSetColour(c);
				FontText(texta345678_,xO+zLeftIT,yO+zTopIT, 600);
				yO += oSpace;

				if(optionSelected == 3) c = menuColor[MenuOptionSelected]; else c = menuColor[MenuOption];
				
				WCHAR textb345678_[80]={0};
				wsprintfW(textb345678_,L"Load State");
				FontSetColour(c);
				FontText(textb345678_,xO+zLeftIT,yO+zTopIT, 600);
				yO += oSpace;

				if(optionSelected == 4) c = menuColor[MenuOptionSelected]; else c = menuColor[MenuOption];
				
				WCHAR aatextb345678_[80]={0};
				wsprintfW(aatextb345678_,L"Take Screenshot");
				FontSetColour(c);
				FontText(aatextb345678_,xO+zLeftIT,yO+zTopIT, 600);
				yO += oSpace;

				if(optionSelected == 5) c = menuColor[MenuOptionSelected]; else c = menuColor[MenuOption];
				
				WCHAR aaatextb345678_[80]={0};
				wsprintfW(aaatextb345678_,L"Cheat Codes");
				FontSetColour(c);
				FontText(aaatextb345678_,xO+zLeftIT,yO+zTopIT, 600);
				yO += oSpace;

				//Vido Options menu
				if(optionSelected == 6)c = menuColor[MenuOptionSelected]; else c = menuColor[MenuOption];
				WCHAR texta12345678_[80]={0};
				wsprintfW(texta12345678_,L"Video Options");
				FontSetColour(c);
				FontText(texta12345678_,xO+zLeftIT,yO+zTopIT, 600);
				yO += oSpace;

				//Sound Options menu
				if(optionSelected == 7) c = menuColor[MenuOptionSelected]; else c = menuColor[MenuOption];
				WCHAR texta22345678_[80]={0};
				wsprintfW(texta22345678_,L"Sound Options");
				FontSetColour(c);
				FontText(texta22345678_,xO+zLeftIT,yO+zTopIT, 600);
				yO += oSpace;

				//Controller Config
				if(optionSelected == 8) c = menuColor[MenuOptionSelected]; else c = menuColor[MenuOption];
				WCHAR texta32345678_[80]={0};
				wsprintfW(texta32345678_,L"Controller Options");
				FontSetColour(c);
				FontText(texta32345678_,xO+zLeftIT,yO+zTopIT, 600);
				yO += oSpace;

				//General Options
				if(optionSelected == 9) c = menuColor[MenuOptionSelected]; else c = menuColor[MenuOption];
				WCHAR texta42345678_[80]={0};
				wsprintfW(texta42345678_,L"General Options");
				FontSetColour(c);
				FontText(texta42345678_,xO+zLeftIT,yO+zTopIT, 600);
				yO += oSpace;

				if(optionSelected == 10) c = menuColor[MenuOptionSelected]; else c = menuColor[MenuOption];
				WCHAR gtexta42345678_[80]={0};
				wsprintfW(gtexta42345678_,L"Load Game Guide");
				FontSetColour(c);
				FontText(gtexta42345678_,xO+zLeftIT,yO+zTopIT, 600);
				yO += oSpace;

				if(optionSelected == 11) c = menuColor[MenuOptionSelected]; else c = menuColor[MenuOption];
				WCHAR gtexta42345678__[80]={0};
				wsprintfW(gtexta42345678__,L"Load Image");
				FontSetColour(c);
				FontText(gtexta42345678__,xO+zLeftIT,yO+zTopIT, 600);
				yO += oSpace;

				if(optionSelected == 12) c = menuColor[MenuOptionSelected]; else c = menuColor[MenuOption];
				WCHAR text245678_[80]={0};
				wsprintfW(text245678_,L"Exit Game");
				FontSetColour(c);
				FontText(text245678_,xO+zLeftIT,yO+zTopIT, 600);
				yO += oSpace;

				if(showAvailMemory) {
					showMemory();
				}

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


			if(optionSelected == 6) c = menuColor[MenuOptionSelected]; else c = menuColor[MenuOption];
			WCHAR texta12345678_[80]={0};
			wsprintfW(texta12345678_,L"Video Options");
			FontSetColour(c);
			FontCenteredText(texta12345678_,xO+zLeftEO,yO+zTopEO, 600);
			yO += oSpace;

			//Sound Options menu
			if(optionSelected == 7) c = menuColor[MenuOptionSelected]; else c = menuColor[MenuOption];
			WCHAR texta22345678_[80]={0};
			wsprintfW(texta22345678_,L"Sound Options");
			FontSetColour(c);
			FontCenteredText(texta22345678_,xO+zLeftEO,yO+zTopEO, 600);
			yO += oSpace;


			//Controller Config
			if(optionSelected == 8) c = menuColor[MenuOptionSelected]; else c = menuColor[MenuOption];
			WCHAR texta32345678_[80]={0};
			wsprintfW(texta32345678_,L"Controller Options");
			FontSetColour(c);
			FontCenteredText(texta32345678_,xO+zLeftEO,yO+zTopEO, 600);
			yO += oSpace;

			//General Options
			if(optionSelected == 9) c = menuColor[MenuOptionSelected]; else c = menuColor[MenuOption];
			WCHAR texta42345678_[80]={0};
			wsprintfW(texta42345678_,L"General Options");
			FontSetColour(c);
			FontCenteredText(texta42345678_,xO+zLeftEO,yO+zTopEO, 600);
			yO += oSpace;

			if(optionSelected == 10) c = menuColor[MenuOptionSelected]; else c = menuColor[MenuOption];
			WCHAR htexta42345678_[80]={0};
			wsprintfW(htexta42345678_,L"GUI Options");
			FontSetColour(c);
			FontCenteredText(htexta42345678_,xO+zLeftEO,yO+zTopEO, 600);
			yO += oSpace;

			//Sound Options menu
			if(optionSelected == 11) c = menuColor[MenuOptionSelected]; else c = menuColor[MenuOption];
			WCHAR texta22345678f_[80]={0};
			wsprintfW(texta22345678f_,L"Music Player Options");
			FontSetColour(c);
			FontCenteredText(texta22345678f_,xO+zLeftEO,yO+zTopEO, 600);
			yO += oSpace;


			//Fade overlay
			Device->SetRenderState(D3DRS_ALPHABLENDENABLE,TRUE);
			if(fadeColor > 0) {
				fadeColor -=fadeSpeed;
				if(fadeColor < fadeSpeed) fadeColor = 0;
			}
			makeVertexListController();
			VertexBufferController->Lock(0,sizeof(VertexList),&lock,0); if (lock==NULL) return 1;
			memcpy(lock,VertexListController,sizeof(VertexList));
			VertexBufferController->Unlock();
			Device->SetTexture(0,TexMainMenu); 
			Device->SetStreamSource(0,VertexBufferController,sizeof(CustomVertex));
			Device->SetVertexShader(D3DFVF_CUSTOMVERTEX);
			Device->DrawPrimitive(D3DPT_TRIANGLESTRIP,0,2);

			Device->SetRenderState(D3DRS_ALPHABLENDENABLE,FALSE);
		}
		return 0;    
	}



	if(screenResize == 1) {
		unsigned char *lock=NULL;
		setTextureMode();


		makeVertexListResize();
		VertexBufferResize->Lock(0,sizeof(VertexList),&lock,0); if (lock==NULL) return 1;
		memcpy(lock,VertexListResize,sizeof(VertexList));
		VertexBufferResize->Unlock();

		//makeVertexListLinearDark();
		makeVertexListLinear();
		VertexBufferLinear->Lock(0,sizeof(VertexList),&lock,0); if (lock==NULL) return 1;
		memcpy(lock,VertexListLinear,sizeof(VertexList));
		VertexBufferLinear->Unlock();

		if(inGame == 0) { 
			Device->SetTexture(0,TexResize); 
			Device->SetStreamSource(0,VertexBufferResize,sizeof(CustomVertex));
			Device->SetVertexShader(D3DFVF_CUSTOMVERTEX);
			Device->DrawPrimitive(D3DPT_TRIANGLESTRIP,0,2);
			WCHAR text234567[280]={0};
			wsprintfW(text234567,L"Align the RED border with the edges of the screen "); //to get a non stretched aspect ratio");
			FontSetColour(0xffff00);
			FontText(text234567,100,175, 600);	

			WCHAR text234567_[280]={0};
			wsprintfW(text234567_,L"to get a non stretched display."); //to get a non stretched aspect ratio");
			FontSetColour(0xffff00);
			FontText(text234567_,100,200, 600);	


			WCHAR text23456[280]={0};
			wsprintfW(text23456,L"Align the BLUE border with the edges of the screen ");//to get a stretched aspect ratio");
			FontSetColour(0xffff00);
			FontText(text23456,100,250, 600);	

			WCHAR text23456_[280]={0};
			wsprintfW(text23456_,L"to get a stretched display.");//to get a stretched aspect ratio");
			FontSetColour(0xffff00);
			FontText(text23456_,100,275, 600);





		}
		else  {
			Device->SetTexture(0,TexScreen);
			Device->SetStreamSource(0,VertexBufferLinear,sizeof(CustomVertex));
			Device->SetVertexShader(D3DFVF_CUSTOMVERTEX);
			Device->DrawPrimitive(D3DPT_TRIANGLESTRIP,0,2);
		}

		//WCHAR text234567__[280]={0};
		//wsprintfW(text234567__,L"Use the left and right analog sticks to resize/move the screen. "); //to get a non stretched aspect ratio");
		//FontSetColour(0xffffff);
		//FontText(text234567__,100,75, 600);	

		WCHAR textXL[280]={0};
		wsprintfW(textXL,L"X: %f", zLeft);
		FontSetColour(0xffffff);
		FontText(textXL,200,75, 600);

		WCHAR textYT[280]={0};
		wsprintfW(textYT,L"Y: %f", zTop);
		FontSetColour(0xffffff);
		FontText(textYT,200,95, 600);


		WCHAR textXR[280]={0};
		//wsprintfW(textXR,L"Width: %f", (sWidth + (zRight - zLeft)));
		wsprintfW(textXR,L"Width: %f", (sWidth + (zRight)));
		FontSetColour(0xffffff);
		FontText(textXR,325,75, 600);

		WCHAR textYB[280]={0};
		//wsprintfW(textYB,L"Height: %f", ((sHeight + (zBottom - zTop))));
		wsprintfW(textYB,L"Height: %f", ((sHeight + (zBottom))));
		FontSetColour(0xffffff);
		FontText(textYB,325, 95, 600);



		//192
		//y -36


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

		return 0;

	}




	if(screenResizeP == 1) {
		unsigned char *lock=NULL;
		setTextureMode();
		makeVertexListResizeP();
		VertexBuffer->Lock(0,sizeof(VertexList),&lock,0); if (lock==NULL) return 1;
		memcpy(lock,VertexList,sizeof(VertexList));
		VertexBuffer->Unlock();
		Device->SetTexture(0,TexMenu);
		Device->SetStreamSource(0,VertexBuffer,sizeof(CustomVertex));
		Device->SetVertexShader(D3DFVF_CUSTOMVERTEX);
		Device->DrawPrimitive(D3DPT_TRIANGLESTRIP,0,2);


		VertexBufferPreview->Lock(0,sizeof(VertexList),&lock,0); if (lock==NULL) return 1;
		memcpy(lock,VertexListPreview,sizeof(VertexList));
		VertexBufferPreview->Unlock();
		Device->SetTexture(0,TexPreviewResize);
		Device->SetStreamSource(0,VertexBufferPreview,sizeof(CustomVertex));
		Device->SetVertexShader(D3DFVF_CUSTOMVERTEX);
		Device->DrawPrimitive(D3DPT_TRIANGLESTRIP,0,2);

		Device->SetRenderState(D3DRS_ALPHABLENDENABLE,TRUE);
		VertexBufferPreviewBorder->Lock(0,sizeof(VertexList),&lock,0); if (lock==NULL) return 1;
		memcpy(lock,VertexListPreviewBorder,sizeof(VertexList));
		VertexBufferPreviewBorder->Unlock();
		Device->SetTexture(0,TexPreviewBorder);
		Device->SetStreamSource(0,VertexBufferPreviewBorder,sizeof(CustomVertex));
		Device->SetVertexShader(D3DFVF_CUSTOMVERTEX);
		Device->DrawPrimitive(D3DPT_TRIANGLESTRIP,0,2);
		Device->SetRenderState(D3DRS_ALPHABLENDENABLE,FALSE);



		WCHAR text2345o[280]={0};
		wsprintfW(text2345o,L"Use the left and right analog sticks to adjust the image.");
		FontSetColour(0xffff00);
		FontSmallText(text2345o,250,406, 600);	

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


	if(screenResizeMovie == 1) {
		
		unsigned char *lock=NULL;
		setTextureMode();
		makeVertexListResizeP();
		VertexBuffer->Lock(0,sizeof(VertexList),&lock,0); if (lock==NULL) return 1;
		memcpy(lock,VertexList,sizeof(VertexList));
		VertexBuffer->Unlock();
		Device->SetTexture(0,TexMenu);
		Device->SetStreamSource(0,VertexBuffer,sizeof(CustomVertex));
		Device->SetVertexShader(D3DFVF_CUSTOMVERTEX);
		Device->DrawPrimitive(D3DPT_TRIANGLESTRIP,0,2);


		VertexBufferPreview->Lock(0,sizeof(VertexList),&lock,0); if (lock==NULL) return 1;
		memcpy(lock,VertexListPreview,sizeof(VertexList));
		VertexBufferPreview->Unlock();
		Device->SetTexture(0,TexPreviewResize);
		Device->SetStreamSource(0,VertexBufferPreview,sizeof(CustomVertex));
		Device->SetVertexShader(D3DFVF_CUSTOMVERTEX);
		Device->DrawPrimitive(D3DPT_TRIANGLESTRIP,0,2);

		Device->SetRenderState(D3DRS_ALPHABLENDENABLE,TRUE);
		VertexBufferPreviewBorder->Lock(0,sizeof(VertexList),&lock,0); if (lock==NULL) return 1;
		memcpy(lock,VertexListPreviewBorder,sizeof(VertexList));
		VertexBufferPreviewBorder->Unlock();
		Device->SetTexture(0,TexPreviewBorder);
		Device->SetStreamSource(0,VertexBufferPreviewBorder,sizeof(CustomVertex));
		Device->SetVertexShader(D3DFVF_CUSTOMVERTEX);
		Device->DrawPrimitive(D3DPT_TRIANGLESTRIP,0,2);
		Device->SetRenderState(D3DRS_ALPHABLENDENABLE,FALSE);

		drawMovie();

		WCHAR text2345o[280]={0};
		wsprintfW(text2345o,L"Use the left and right analog sticks to adjust the image.");
		FontSetColour(0xffff00);
		FontSmallText(text2345o,250,406, 600);	
		
		
		

		return 0;
	}

	/*if(screenResizeI == 1) {

	}*/



	if(screenResizeGP == 1) {
		unsigned char *lock=NULL;
		setTextureMode();
		makeVertexListResizeGP();
		VertexBuffer->Lock(0,sizeof(VertexList),&lock,0); if (lock==NULL) return 1;
		memcpy(lock,VertexList,sizeof(VertexList));
		VertexBuffer->Unlock();
		Device->SetTexture(0,TexMenu);
		Device->SetStreamSource(0,VertexBuffer,sizeof(CustomVertex));
		Device->SetVertexShader(D3DFVF_CUSTOMVERTEX);
		Device->DrawPrimitive(D3DPT_TRIANGLESTRIP,0,2);


		Device->SetRenderState(D3DRS_ALPHABLENDENABLE,TRUE);
		VertexBufferPreviewGP->Lock(0,sizeof(VertexList),&lock,0); if (lock==NULL) return 1;
		memcpy(lock,VertexListPreviewGP,sizeof(VertexList));
		VertexBufferPreviewGP->Unlock();
		Device->SetTexture(0,TexPreviewMedia);
		Device->SetStreamSource(0,VertexBufferPreviewGP,sizeof(CustomVertex));
		Device->SetVertexShader(D3DFVF_CUSTOMVERTEX);
		Device->DrawPrimitive(D3DPT_TRIANGLESTRIP,0,2);
		Device->SetRenderState(D3DRS_ALPHABLENDENABLE,FALSE);


		WCHAR text2345o[280]={0};
		wsprintfW(text2345o,L"Use the left and right analog sticks to adjust the image.");
		FontSetColour(0xffff00);
		FontSmallText(text2345o,250,406, 600);	

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

	if(screenResizeE == 1) {
		unsigned char *lock=NULL;
		setTextureMode();
		makeVertexListController();
		VertexBufferController->Lock(0,sizeof(VertexList),&lock,0); if (lock==NULL) return 1;
		memcpy(lock,VertexListController,sizeof(VertexList));
		VertexBufferController->Unlock();
		Device->SetTexture(0,TexController); 
		Device->SetStreamSource(0,VertexBufferController,sizeof(CustomVertex));
		Device->SetVertexShader(D3DFVF_CUSTOMVERTEX);
		Device->DrawPrimitive(D3DPT_TRIANGLESTRIP,0,2);


		Device->SetRenderState(D3DRS_ALPHABLENDENABLE,TRUE);
		if(fadeColor > 0) {
			fadeColor -=fadeSpeed;
			if(fadeColor < fadeSpeed) fadeColor = 0;
		}
		makeVertexListController();
		VertexBufferController->Lock(0,sizeof(VertexList),&lock,0); if (lock==NULL) return 1;
		memcpy(lock,VertexListController,sizeof(VertexList));
		VertexBufferController->Unlock();
		Device->SetTexture(0,TexMainMenu); 
		Device->SetStreamSource(0,VertexBufferController,sizeof(CustomVertex));
		Device->SetVertexShader(D3DFVF_CUSTOMVERTEX);
		Device->DrawPrimitive(D3DPT_TRIANGLESTRIP,0,2);

		Device->SetRenderState(D3DRS_ALPHABLENDENABLE,FALSE);

		WCHAR text2345o[280]={0};
		wsprintfW(text2345o,L"Press \"Y\" to exit ZsnexBox.");
		FontSetColour(0xffff00);
		FontSmallText(text2345o,250,480/2, 600);	

		/*WCHAR text2345[280]={0};
		wsprintfW(text2345,L"Press \"B\" to Cancel.");
		FontSetColour(0xffff00);
		FontSmallText(text2345,250,((480/2)-20), 600);		*/
		return 0;
	}


	if(screenResizePB == 1) {
		unsigned char *lock=NULL;
		setTextureMode();
		makeVertexListResizePB();
		VertexBuffer->Lock(0,sizeof(VertexList),&lock,0); if (lock==NULL) return 1;
		memcpy(lock,VertexList,sizeof(VertexList));
		VertexBuffer->Unlock();
		Device->SetTexture(0,TexMenu);
		Device->SetStreamSource(0,VertexBuffer,sizeof(CustomVertex));
		Device->SetVertexShader(D3DFVF_CUSTOMVERTEX);
		Device->DrawPrimitive(D3DPT_TRIANGLESTRIP,0,2);



		//draw the screenshot at the current values
		VertexBufferPreview->Lock(0,sizeof(VertexList),&lock,0); if (lock==NULL) return 1;
		memcpy(lock,VertexListPreview,sizeof(VertexList));
		VertexBufferPreview->Unlock();
		Device->SetTexture(0,TexPreviewResize);
		Device->SetStreamSource(0,VertexBufferPreview,sizeof(CustomVertex));
		Device->SetVertexShader(D3DFVF_CUSTOMVERTEX);
		Device->DrawPrimitive(D3DPT_TRIANGLESTRIP,0,2);



		Device->SetRenderState(D3DRS_ALPHABLENDENABLE,TRUE);
		VertexBufferPreviewBorder->Lock(0,sizeof(VertexList),&lock,0); if (lock==NULL) return 1;
		memcpy(lock,VertexListPreviewBorder,sizeof(VertexList));
		VertexBufferPreviewBorder->Unlock();
		Device->SetTexture(0,TexPreviewBorder);
		Device->SetStreamSource(0,VertexBufferPreviewBorder,sizeof(CustomVertex));
		Device->SetVertexShader(D3DFVF_CUSTOMVERTEX);
		Device->DrawPrimitive(D3DPT_TRIANGLESTRIP,0,2);
		Device->SetRenderState(D3DRS_ALPHABLENDENABLE,FALSE);


		WCHAR text2345o[280]={0};
		wsprintfW(text2345o,L"Use the left and right analog sticks to adjust the image.");
		FontSetColour(0xffff00);
		FontSmallText(text2345o,250,406, 600);	

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


	if(screenResizeMPL == 1) {
		unsigned char *lock=NULL;
		setTextureMode();
		makeVertexListResizePB();
		VertexBuffer->Lock(0,sizeof(VertexList),&lock,0); if (lock==NULL) return 1;
		memcpy(lock,VertexList,sizeof(VertexList));
		VertexBuffer->Unlock();
		Device->SetTexture(0,TexMenu);
		Device->SetStreamSource(0,VertexBuffer,sizeof(CustomVertex));
		Device->SetVertexShader(D3DFVF_CUSTOMVERTEX);
		Device->DrawPrimitive(D3DPT_TRIANGLESTRIP,0,2);



		//draw the screenshot at the current values
		Device->SetRenderState(D3DRS_ALPHABLENDENABLE,TRUE);
		VertexBufferPreviewGP->Lock(0,sizeof(VertexList),&lock,0); if (lock==NULL) return 1;
		memcpy(lock,VertexListPreviewGP,sizeof(VertexList));
		VertexBufferPreviewGP->Unlock();
		Device->SetTexture(0,TexPreviewMedia);
		Device->SetStreamSource(0,VertexBufferPreviewGP,sizeof(CustomVertex));
		Device->SetVertexShader(D3DFVF_CUSTOMVERTEX);
		Device->DrawPrimitive(D3DPT_TRIANGLESTRIP,0,2);
		Device->SetRenderState(D3DRS_ALPHABLENDENABLE,FALSE);




		XBSound_DrawLevelMeters( m_pDSound, 40+360.0f+zLeftMPL, 5+125.0f+zTopMPL, 110.0f+zRightMPL, 75.0f-25+40+zBottomMPL );


		WCHAR text2345o[280]={0};
		wsprintfW(text2345o,L"Use the left and right analog sticks to adjust the image.");
		FontSetColour(0xffff00);
		FontSmallText(text2345o,250,406, 600);	

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

	if(TGADatabasePick == 1) {
		
		if(TexImage) {
			unsigned char *lock=NULL;
				makeVertexListImage();
				setTextureMode();

				Device->SetRenderState(D3DRS_ALPHABLENDENABLE,TRUE);

				VertexBufferImage->Lock(0,sizeof(VertexList),&lock,0); if (lock==NULL) return 1;
				memcpy(lock,VertexListImage,sizeof(VertexList));
				VertexBufferImage->Unlock();

				Device->SetTexture(0,TexImage);
				Device->SetStreamSource(0,VertexBufferImage,sizeof(CustomVertex));
				Device->SetVertexShader(D3DFVF_CUSTOMVERTEX);
				Device->DrawPrimitive(D3DPT_TRIANGLESTRIP,0,2);

				Device->SetRenderState(D3DRS_ALPHABLENDENABLE,FALSE);



		//	zTopBI = 0;
		//	zLeftBI =	0;
		//	zBottomBI = 2;//(float)sHeight / (float)dwTexHeight;
		//	zRightBI = 2;

			
			//WCHAR textXL[280]={0};
			//wsprintfW(textXL,L"zTopBI: %f", zTopBI);
			//FontSetColour(0xffffff);
			//FontText(textXL,200,75, 600);

			//WCHAR textYT[280]={0};
			//wsprintfW(textYT,L"zLeftBI: %f",zLeftBI);
			//FontSetColour(0xffffff);
			//FontText(textYT,200,95, 600);

			//WCHAR textXR[280]={0};
			////wsprintfW(textXR,L"Width: %f", (sWidth + (zRight - zLeft)));
			//wsprintfW(textXR,L"zBottomBI: %f", zBottomBI);
			//FontSetColour(0xffffff);
			//FontText(textXR,325,75, 600);

			//WCHAR textYB[280]={0};
			////wsprintfW(textYB,L"Height: %f", ((sHeight + (zBottom - zTop))));
			//wsprintfW(textYB,L"zRightBI: %f", zRightBI);
			//FontSetColour(0xffffff);
			//FontText(textYB,325, 95, 600);

		


			/*WCHAR text2345[280]={0};
			wsprintfW(text2345,L"Press \"B\" to exit");
			FontSetColour(0xffff00);
			FontSmallText(text2345,sWidth/2,406, 600);	*/
		}
		else {
			WCHAR text2345q[280]={0};
			wsprintfW(text2345q,L"Not enough free memory");
			FontSetColour(0xffff00);
			FontSmallText(text2345q,sWidth/2,200, 600);	

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

	if(TGADatabaseDelete == 1) {
		unsigned char *lock=NULL;
		setTextureMode();
		makeVertexListController();
		VertexBufferController->Lock(0,sizeof(VertexList),&lock,0); if (lock==NULL) return 1;
		memcpy(lock,VertexListController,sizeof(VertexList));
		VertexBufferController->Unlock();
		Device->SetTexture(0,TexController); 
		Device->SetStreamSource(0,VertexBufferController,sizeof(CustomVertex));
		Device->SetVertexShader(D3DFVF_CUSTOMVERTEX);
		Device->DrawPrimitive(D3DPT_TRIANGLESTRIP,0,2);
		//drawC_Count = 0;
        //yO = 110;
		

		WCHAR text2345q[280]={0};
		wsprintfW(text2345q,L"Delete image 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 0;
	
	}
	if(screenResizeJ == 1) {
		unsigned char *lock=NULL;
		setTextureMode();
		makeVertexListResizeJ();
		VertexBuffer->Lock(0,sizeof(VertexList),&lock,0); if (lock==NULL) return 1;
		memcpy(lock,VertexList,sizeof(VertexList));
		VertexBuffer->Unlock();
		Device->SetTexture(0,TexMenu);
		Device->SetStreamSource(0,VertexBuffer,sizeof(CustomVertex));
		Device->SetVertexShader(D3DFVF_CUSTOMVERTEX);
		Device->DrawPrimitive(D3DPT_TRIANGLESTRIP,0,2);


		VertexBufferPreview->Lock(0,sizeof(VertexList),&lock,0); if (lock==NULL) return 1;
		memcpy(lock,VertexListPreview,sizeof(VertexList));
		VertexBufferPreview->Unlock();
		Device->SetTexture(0,TexJBoxArt);
		Device->SetStreamSource(0,VertexBufferPreview,sizeof(CustomVertex));
		Device->SetVertexShader(D3DFVF_CUSTOMVERTEX);
		Device->DrawPrimitive(D3DPT_TRIANGLESTRIP,0,2);


		WCHAR text2345o[280]={0};
		wsprintfW(text2345o,L"Use the left and right analog sticks to adjust the image.");
		FontSetColour(0xffff00);
		FontSmallText(text2345o,250,406, 600);	

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

	if(fontResizeR == 1) {
		unsigned char *lock=NULL;
		setTextureMode();
		makeVertexListResizeJ();
		VertexBuffer->Lock(0,sizeof(VertexList),&lock,0); if (lock==NULL) return 1;
		memcpy(lock,VertexList,sizeof(VertexList));
		VertexBuffer->Unlock();
		Device->SetTexture(0,TexMenu);
		Device->SetStreamSource(0,VertexBuffer,sizeof(CustomVertex));
		Device->SetVertexShader(D3DFVF_CUSTOMVERTEX);
		Device->DrawPrimitive(D3DPT_TRIANGLESTRIP,0,2);


		MenuRender();


		WCHAR text2345o[280]={0};
		wsprintfW(text2345o,L"Use the left analog stick to adjust the text.");
		FontSetColour(0xffff00);
		FontSmallText(text2345o,250,(480-90), 600);	

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

	if(fontResizeF == 1) {
		unsigned char *lock=NULL;
		setTextureMode();
		makeVertexListResizeJ();
		VertexBuffer->Lock(0,sizeof(VertexList),&lock,0); if (lock==NULL) return 1;
		memcpy(lock,VertexList,sizeof(VertexList));
		VertexBuffer->Unlock();
		Device->SetTexture(0,TexMenu);
		Device->SetStreamSource(0,VertexBuffer,sizeof(CustomVertex));
		Device->SetVertexShader(D3DFVF_CUSTOMVERTEX);
		Device->DrawPrimitive(D3DPT_TRIANGLESTRIP,0,2);


		MenuRender();


		WCHAR text2345o[280]={0};
		wsprintfW(text2345o,L"Use the left analog stick to adjust the text.");
		FontSetColour(0xffff00);
		FontSmallText(text2345o,250,(480-90), 600);	

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

	if(fontResizeV == 1) {
		unsigned char *lock=NULL;
		setTextureMode();
		makeVertexListController();
		VertexBufferController->Lock(0,sizeof(VertexList),&lock,0); if (lock==NULL) return 1;
		memcpy(lock,VertexListController,sizeof(VertexList));
		VertexBufferController->Unlock();
		Device->SetTexture(0,TexController); 
		Device->SetStreamSource(0,VertexBufferController,sizeof(CustomVertex));
		Device->SetVertexShader(D3DFVF_CUSTOMVERTEX);
		Device->DrawPrimitive(D3DPT_TRIANGLESTRIP,0,2);


		drawVideoOptionsMenu();


		WCHAR text2345o[280]={0};
		wsprintfW(text2345o,L"Use the left analog stick to adjust the text.");
		FontSetColour(0xffff00);
		FontSmallText(text2345o,250,(480-90), 600);	

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

	if(fontResizeRumble == 1) {
		unsigned char *lock=NULL;
		setTextureMode();
		makeVertexListController();
		VertexBufferController->Lock(0,sizeof(VertexList),&lock,0); if (lock==NULL) return 1;
		memcpy(lock,VertexListController,sizeof(VertexList));
		VertexBufferController->Unlock();
		Device->SetTexture(0,TexController); 
		Device->SetStreamSource(0,VertexBufferController,sizeof(CustomVertex));
		Device->SetVertexShader(D3DFVF_CUSTOMVERTEX);
		Device->DrawPrimitive(D3DPT_TRIANGLESTRIP,0,2);
		yO = 110;
		controllerRumbleConfigMenu = 0;
		drawRumbleConfig();
		WCHAR text2345o[280]={0};
		wsprintfW(text2345o,L"Use the left analog stick to adjust the text.");
		FontSetColour(0xffff00);
		FontSmallText(text2345o,250,(480-90), 600);	
		return 0;
	}

	if(fontResizeGT == 1) {
		unsigned char *lock=NULL;
		setTextureMode();
		makeVertexListController();
		VertexBufferController->Lock(0,sizeof(VertexList),&lock,0); if (lock==NULL) return 1;
		memcpy(lock,VertexListController,sizeof(VertexList));
		VertexBufferController->Unlock();
		Device->SetTexture(0,TexController); 
		Device->SetStreamSource(0,VertexBufferController,sizeof(CustomVertex));
		Device->SetVertexShader(D3DFVF_CUSTOMVERTEX);
		Device->DrawPrimitive(D3DPT_TRIANGLESTRIP,0,2);


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

		gFont = 1;
		drawGUIOptions();


		WCHAR text2345o[280]={0};
		wsprintfW(text2345o,L"Use the left analog stick to adjust the text.");
		FontSetColour(0xffff00);
		FontSmallText(text2345o,250,(480-90), 600);	

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


	if(fontResizeIT == 1) {
		unsigned char *lock=NULL;
		setTextureMode();
		makeVertexListController();
		VertexBufferController->Lock(0,sizeof(VertexList),&lock,0); if (lock==NULL) return 1;
		memcpy(lock,VertexListController,sizeof(VertexList));
		VertexBufferController->Unlock();
		Device->SetTexture(0,TexController); 
		Device->SetStreamSource(0,VertexBufferController,sizeof(CustomVertex));
		Device->SetVertexShader(D3DFVF_CUSTOMVERTEX);
		Device->DrawPrimitive(D3DPT_TRIANGLESTRIP,0,2);

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

		int xO = 640/2;
		int yO = 130;
		int oSpace = vSpace;
		unsigned int c = 0x00ffffff;

		xO = 150;
		yO = 120;

		//yO -= 20;
		if(optionSelected == 0) c = menuColor[MenuOptionSelected]; else c = menuColor[MenuOption];
		
		WCHAR text345678_[80]={0};
		wsprintfW(text345678_,L"Return to Game");
		FontSetColour(c);
		FontText(text345678_,xO+zLeftIT,yO+zTopIT, 600);
		yO += oSpace;

		if(optionSelected == 1) c = menuColor[MenuOptionSelected]; else c = menuColor[MenuOption];
		
		WCHAR atextb345678_[80]={0};
		wsprintfW(atextb345678_,L"Reset Game");
		FontSetColour(c);
		FontText(atextb345678_,xO+zLeftIT,yO+zTopIT, 600);
		yO += oSpace;

		if(optionSelected == 2) c = menuColor[MenuOptionSelected]; else c = menuColor[MenuOption];
		
		WCHAR texta345678_[80]={0};
		wsprintfW(texta345678_,L"Save State");
		FontSetColour(c);
		FontText(texta345678_,xO+zLeftIT,yO+zTopIT, 600);
		yO += oSpace;

		if(optionSelected == 3) c = menuColor[MenuOptionSelected]; else c = menuColor[MenuOption];
		
		WCHAR textb345678_[80]={0};
		wsprintfW(textb345678_,L"Load State");
		FontSetColour(c);
		FontText(textb345678_,xO+zLeftIT,yO+zTopIT, 600);
		yO += oSpace;

		if(optionSelected == 4) c = menuColor[MenuOptionSelected]; else c = menuColor[MenuOption];
		
		WCHAR aatextb345678_[80]={0};
		wsprintfW(aatextb345678_,L"Take Screenshot");
		FontSetColour(c);
		FontText(aatextb345678_,xO+zLeftIT,yO+zTopIT, 600);
		yO += oSpace;

		if(optionSelected == 5) c = menuColor[MenuOptionSelected]; else c = menuColor[MenuOption];
		
		WCHAR aaatextb345678_[80]={0};
		wsprintfW(aaatextb345678_,L"Cheat Codes");
		FontSetColour(c);
		FontText(aaatextb345678_,xO+zLeftIT,yO+zTopIT, 600);
		yO += oSpace;

		//Vido Options menu
		if(optionSelected == 6)c = menuColor[MenuOptionSelected]; else c = menuColor[MenuOption];
		WCHAR texta12345678_[80]={0};
		wsprintfW(texta12345678_,L"Video Options");
		FontSetColour(c);
		FontText(texta12345678_,xO+zLeftIT,yO+zTopIT, 600);
		yO += oSpace;

		//Sound Options menu
		if(optionSelected == 7) c = menuColor[MenuOptionSelected]; else c = menuColor[MenuOption];
		WCHAR texta22345678_[80]={0};
		wsprintfW(texta22345678_,L"Sound Options");
		FontSetColour(c);
		FontText(texta22345678_,xO+zLeftIT,yO+zTopIT, 600);
		yO += oSpace;

		//Controller Config
		if(optionSelected == 8) c = menuColor[MenuOptionSelected]; else c = menuColor[MenuOption];
		WCHAR texta32345678_[80]={0};
		wsprintfW(texta32345678_,L"Controller Options");
		FontSetColour(c);
		FontText(texta32345678_,xO+zLeftIT,yO+zTopIT, 600);
		yO += oSpace;

		//General Options
		if(optionSelected == 9) c = menuColor[MenuOptionSelected]; else c = menuColor[MenuOption];
		WCHAR texta42345678_[80]={0};
		wsprintfW(texta42345678_,L"General Options");
		FontSetColour(c);
		FontText(texta42345678_,xO+zLeftIT,yO+zTopIT, 600);
		yO += oSpace;

		if(optionSelected == 10) c = menuColor[MenuOptionSelected]; else c = menuColor[MenuOption];
		WCHAR gtexta42345678_[80]={0};
		wsprintfW(gtexta42345678_,L"Load Game Guide");
		FontSetColour(c);
		FontText(gtexta42345678_,xO+zLeftIT,yO+zTopIT, 600);
		yO += oSpace;

		if(optionSelected == 11) c = menuColor[MenuOptionSelected]; else c = menuColor[MenuOption];
		WCHAR gtexta42345678__[80]={0};
		wsprintfW(gtexta42345678__,L"Load Image");
		FontSetColour(c);
		FontText(gtexta42345678__,xO+zLeftIT,yO+zTopIT, 600);
		yO += oSpace;

		if(optionSelected == 12) c = menuColor[MenuOptionSelected]; else c = menuColor[MenuOption];
		WCHAR text245678_[80]={0};
		wsprintfW(text245678_,L"Exit Game");
		FontSetColour(c);
		FontText(text245678_,xO+zLeftIT,yO+zTopIT, 600);
		yO += oSpace;







		WCHAR text2345o[280]={0};
		wsprintfW(text2345o,L"Use the left analog stick to adjust the text.");
		FontSetColour(0xffff00);
		FontSmallText(text2345o,250,(480-90), 600);	

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

	if(fontResizeEO == 1) {
		unsigned char *lock=NULL;
		setTextureMode();
		makeVertexListController();
		VertexBufferController->Lock(0,sizeof(VertexList),&lock,0); if (lock==NULL) return 1;
		memcpy(lock,VertexListController,sizeof(VertexList));
		VertexBufferController->Unlock();
		Device->SetTexture(0,TexController); 
		Device->SetStreamSource(0,VertexBufferController,sizeof(CustomVertex));
		Device->SetVertexShader(D3DFVF_CUSTOMVERTEX);
		Device->DrawPrimitive(D3DPT_TRIANGLESTRIP,0,2);

		int xO = 640/2;
		int yO = 130;
		int oSpace = vSpace;
		unsigned int c = 0x00ffffff;

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

		//Vido Options menu
		if(optionSelected == 6) c = menuColor[MenuOptionSelected]; else c = menuColor[MenuOption];
		WCHAR texta12345678_[80]={0};
		wsprintfW(texta12345678_,L"Video Options");
		FontSetColour(c);
		FontCenteredText(texta12345678_,xO+zLeftEO,yO+zTopEO, 600);
		yO += oSpace;

		//Sound Options menu
		if(optionSelected == 7) c = menuColor[MenuOptionSelected]; else c = menuColor[MenuOption];
		WCHAR texta22345678_[80]={0};
		wsprintfW(texta22345678_,L"Sound Options");
		FontSetColour(c);
		FontCenteredText(texta22345678_,xO+zLeftEO,yO+zTopEO, 600);
		yO += oSpace;


		//Controller Config
		if(optionSelected == 8) c = menuColor[MenuOptionSelected]; else c = menuColor[MenuOption];
		WCHAR texta32345678_[80]={0};
		wsprintfW(texta32345678_,L"Controller Options");
		FontSetColour(c);
		FontCenteredText(texta32345678_,xO+zLeftEO,yO+zTopEO, 600);
		yO += oSpace;

		//General Options
		if(optionSelected == 9) c = menuColor[MenuOptionSelected]; else c = menuColor[MenuOption];
		WCHAR texta42345678_[80]={0};
		wsprintfW(texta42345678_,L"General Options");
		FontSetColour(c);
		FontCenteredText(texta42345678_,xO+zLeftEO,yO+zTopEO, 600);
		yO += oSpace;

		if(optionSelected == 10) c = menuColor[MenuOptionSelected]; else c = menuColor[MenuOption];
		WCHAR htexta42345678_[80]={0};
		wsprintfW(htexta42345678_,L"GUI Options");
		FontSetColour(c);
		FontCenteredText(htexta42345678_,xO+zLeftEO,yO+zTopEO, 600);
		yO += oSpace;

		//Sound Options menu
		if(optionSelected == 11) c = menuColor[MenuOptionSelected]; else c = menuColor[MenuOption];
		WCHAR texta22345678f_[80]={0};
		wsprintfW(texta22345678f_,L"Music Player Options");
		FontSetColour(c);
		FontCenteredText(texta22345678f_,xO+zLeftEO,yO+zTopEO, 600);


		WCHAR text2345o[280]={0};
		wsprintfW(text2345o,L"Use the left analog stick to adjust the text.");
		FontSetColour(0xffff00);
		FontSmallText(text2345o,250,(480-90), 600);	

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

	if(fontResizeCO == 1) {
		unsigned char *lock=NULL;
		setTextureMode();
		makeVertexListController();
		VertexBufferController->Lock(0,sizeof(VertexList),&lock,0); if (lock==NULL) return 1;
		memcpy(lock,VertexListController,sizeof(VertexList));
		VertexBufferController->Unlock();
		Device->SetTexture(0,TexController); 
		Device->SetStreamSource(0,VertexBufferController,sizeof(CustomVertex));
		Device->SetVertexShader(D3DFVF_CUSTOMVERTEX);
		Device->DrawPrimitive(D3DPT_TRIANGLESTRIP,0,2);

		controllerMode = 0;
		drawControllerMenu();

		WCHAR text2345o[280]={0};
		wsprintfW(text2345o,L"Use the left analog stick to adjust the text.");
		FontSetColour(0xffff00);
		FontSmallText(text2345o,250,(480-90), 600);	

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


	if(screenOptionsHelp == 1) {
		unsigned char *lock=NULL;
		setTextureMode();
		makeVertexListController2();
		VertexBufferController->Lock(0,sizeof(VertexList),&lock,0); if (lock==NULL) return 1;
		memcpy(lock,VertexListController,sizeof(VertexList));
		VertexBufferController->Unlock();
		Device->SetTexture(0,TexHelp); 
		Device->SetStreamSource(0,VertexBufferController,sizeof(CustomVertex));
		Device->SetVertexShader(D3DFVF_CUSTOMVERTEX);
		Device->DrawPrimitive(D3DPT_TRIANGLESTRIP,0,2);


		makeVertexListController();
		Device->SetRenderState(D3DRS_ALPHABLENDENABLE,TRUE);
		if(fadeColor > 0) {
			fadeColor -=fadeSpeed;
			if(fadeColor < fadeSpeed) fadeColor = 0;
		}
		makeVertexListController();
		VertexBufferController->Lock(0,sizeof(VertexList),&lock,0); if (lock==NULL) return 1;
		memcpy(lock,VertexListController,sizeof(VertexList));
		VertexBufferController->Unlock();
		Device->SetTexture(0,TexMainMenu); 
		Device->SetStreamSource(0,VertexBufferController,sizeof(CustomVertex));
		Device->SetVertexShader(D3DFVF_CUSTOMVERTEX);
		Device->DrawPrimitive(D3DPT_TRIANGLESTRIP,0,2);

		Device->SetRenderState(D3DRS_ALPHABLENDENABLE,FALSE);


		
		drawGameGuideList();

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

		WCHAR text2345o[280]={0};
		wsprintfW(text2345o,L"Press \"B\" to exit.");
		FontSetColour(0xffff00);
		FontSmallText(text2345o,250,(480-80), 600);	



		return 0;
	}

	if(fontResizeCC == 1) {
		unsigned char *lock=NULL;
		setTextureMode();
		makeVertexListController();
		VertexBufferController->Lock(0,sizeof(VertexList),&lock,0); if (lock==NULL) return 1;
		memcpy(lock,VertexListController,sizeof(VertexList));
		VertexBufferController->Unlock();
		Device->SetTexture(0,TexController); 
		Device->SetStreamSource(0,VertexBufferController,sizeof(CustomVertex));
		Device->SetVertexShader(D3DFVF_CUSTOMVERTEX);
		Device->DrawPrimitive(D3DPT_TRIANGLESTRIP,0,2);

		oneByteDraw();

		DWORD color = 0xffffff;

		//if(oneByteSearch == true) {
		WCHAR bbatext2345[280]={0};
		wsprintfW(bbatext2345,L"Please enter a value between 0 and 255.");
		FontSetColour(color);
		FontSmallText(bbatext2345,sWidth/2,190, 600);

		WCHAR abbatext2345[280]={0};
		wsprintfW(abbatext2345,L"Select a digit and press \"A\" to increase.");
		FontSetColour(color);
		FontSmallText(abbatext2345,sWidth/2,210, 600);

		WCHAR aabbatext2345[280]={0};
		wsprintfW(aabbatext2345,L"or \"X\" to decrease.");
		FontSetColour(color);
		FontSmallText(aabbatext2345,sWidth/2,230, 600);

		WCHAR jtext2345[280]={0};
		wsprintfW(jtext2345,L"Press \"Y\" to search for above value.");
		FontSetColour(0xffff00);
		FontSmallText(jtext2345,sWidth/2,290, 600);

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


		WCHAR text2345o[280]={0};
		wsprintfW(text2345o,L"Use the left analog stick to adjust the text.");
		FontSetColour(0xffff00);
		FontSmallText(text2345o,250,(480-90), 600);	

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

	if(confirmDelete == 1) {
		unsigned char *lock=NULL;
		setTextureMode();
		makeVertexListController();
		VertexBufferController->Lock(0,sizeof(VertexList),&lock,0); if (lock==NULL) return 1;
		memcpy(lock,VertexListController,sizeof(VertexList));
		VertexBufferController->Unlock();
		Device->SetTexture(0,TexController); 
		Device->SetStreamSource(0,VertexBufferController,sizeof(CustomVertex));
		Device->SetVertexShader(D3DFVF_CUSTOMVERTEX);
		Device->DrawPrimitive(D3DPT_TRIANGLESTRIP,0,2);

		DWORD color = 0xffffff;

		WCHAR bbatext2345[280]={0};
		wsprintfW(bbatext2345,L"Are you sure you wish to move this file to the garbage folder?");
		FontSetColour(color);
		FontSmallText(bbatext2345,sWidth/2,190, 600);

		std::string t =fileList[FileMenuSelected].name;
		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];
		}
		color = 0xffff00;
		FontSetColour(color);
		FontSmallText(abbatext2345,sWidth/2,230, 600);

		color = 0xffffff;
		WCHAR aabbatext2345[280]={0};
		wsprintfW(aabbatext2345,L"Press \"B\" to cancel or \"A\" to confirm.");
		FontSetColour(color);
		FontSmallText(aabbatext2345,sWidth/2,270, 600);
		return 0;
	}

	if(favoriteAdd == 1) {
		unsigned char *lock=NULL;
		setTextureMode();
		makeVertexListController();
		VertexBufferController->Lock(0,sizeof(VertexList),&lock,0); if (lock==NULL) return 1;
		memcpy(lock,VertexListController,sizeof(VertexList));
		VertexBufferController->Unlock();
		Device->SetTexture(0,TexController); 
		Device->SetStreamSource(0,VertexBufferController,sizeof(CustomVertex));
		Device->SetVertexShader(D3DFVF_CUSTOMVERTEX);
		Device->DrawPrimitive(D3DPT_TRIANGLESTRIP,0,2);

		DWORD color = 0xffffff;

		WCHAR bbatext2345[280]={0};


		wsprintfW(bbatext2345,L"The following game has been added to the favorites list:");
		//	else
		//		wsprintfW(bbatext2345,L"The following game has been removed from the favorites list:");

		FontSetColour(color);
		FontSmallText(bbatext2345,sWidth/2,190, 600);

		std::string t =fileList[FileMenuSelected].name;
		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];
		}
		color = 0xffff00;
		FontSetColour(color);
		FontSmallText(abbatext2345,sWidth/2,230, 600);

		color = 0xffffff;
		/*WCHAR aabbatext2345[280]={0};
		wsprintfW(aabbatext2345,L"Press \"B\" to return to the game list");
		FontSetColour(color);
		FontSmallText(aabbatext2345,sWidth/2,270, 600);*/
		return 0;
	}


	if(fontResizeTO == 1) {
		unsigned char *lock=NULL;
		setTextureMode();
		makeVertexListController();
		VertexBufferController->Lock(0,sizeof(VertexList),&lock,0); if (lock==NULL) return 1;
		memcpy(lock,VertexListController,sizeof(VertexList));
		VertexBufferController->Unlock();
		Device->SetTexture(0,TexController); 
		Device->SetStreamSource(0,VertexBufferController,sizeof(CustomVertex));
		Device->SetVertexShader(D3DFVF_CUSTOMVERTEX);
		Device->DrawPrimitive(D3DPT_TRIANGLESTRIP,0,2);

		controllerMode = 1;
		drawControllerMenu();

		WCHAR text2345o[280]={0};
		wsprintfW(text2345o,L"Use the left analog stick to adjust the text.");
		FontSetColour(0xffff00);
		FontSmallText(text2345o,250,(480-90), 600);	

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

	if(fontResizeCCO == 1) {
		unsigned char *lock=NULL;
		setTextureMode();
		makeVertexListController();
		VertexBufferController->Lock(0,sizeof(VertexList),&lock,0); if (lock==NULL) return 1;
		memcpy(lock,VertexListController,sizeof(VertexList));
		VertexBufferController->Unlock();
		Device->SetTexture(0,TexController); 
		Device->SetStreamSource(0,VertexBufferController,sizeof(CustomVertex));
		Device->SetVertexShader(D3DFVF_CUSTOMVERTEX);
		Device->DrawPrimitive(D3DPT_TRIANGLESTRIP,0,2);

		controllerMode = 2;
		drawControllerMenu();

		WCHAR text2345o[280]={0};
		wsprintfW(text2345o,L"Use the left analog stick to adjust the text.");
		FontSetColour(0xffff00);
		FontSmallText(text2345o,250,(480-90), 600);	

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

	if(fontResizeS == 1) {
		unsigned char *lock=NULL;
		setTextureMode();
		makeVertexListController();
		VertexBufferController->Lock(0,sizeof(VertexList),&lock,0); if (lock==NULL) return 1;
		memcpy(lock,VertexListController,sizeof(VertexList));
		VertexBufferController->Unlock();
		Device->SetTexture(0,TexController); 
		Device->SetStreamSource(0,VertexBufferController,sizeof(CustomVertex));
		Device->SetVertexShader(D3DFVF_CUSTOMVERTEX);
		Device->DrawPrimitive(D3DPT_TRIANGLESTRIP,0,2);


		drawSoundOptionsMenu();


		WCHAR text2345o[280]={0};
		wsprintfW(text2345o,L"Use the left analog stick to adjust the text.");
		FontSetColour(0xffff00);
		FontSmallText(text2345o,250,(480-90), 600);	

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

	if(fontResizeG == 1) {
		unsigned char *lock=NULL;
		setTextureMode();
		makeVertexListController();
		VertexBufferController->Lock(0,sizeof(VertexList),&lock,0); if (lock==NULL) return 1;
		memcpy(lock,VertexListController,sizeof(VertexList));
		VertexBufferController->Unlock();
		Device->SetTexture(0,TexController); 
		Device->SetStreamSource(0,VertexBufferController,sizeof(CustomVertex));
		Device->SetVertexShader(D3DFVF_CUSTOMVERTEX);
		Device->DrawPrimitive(D3DPT_TRIANGLESTRIP,0,2);


		drawGeneralOptions();


		WCHAR text2345o[280]={0};
		wsprintfW(text2345o,L"Use the left analog stick to adjust the text.");
		FontSetColour(0xffff00);
		FontSmallText(text2345o,250,(480-90), 600);	

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

	if(fontResizeCD == 1) {
		unsigned char *lock=NULL;
		setTextureMode();
		makeVertexListController();
		VertexBufferController->Lock(0,sizeof(VertexList),&lock,0); if (lock==NULL) return 1;
		memcpy(lock,VertexListController,sizeof(VertexList));
		VertexBufferController->Unlock();
		Device->SetTexture(0,TexController); 
		Device->SetStreamSource(0,VertexBufferController,sizeof(CustomVertex));
		Device->SetVertexShader(D3DFVF_CUSTOMVERTEX);
		Device->DrawPrimitive(D3DPT_TRIANGLESTRIP,0,2);


		drawListOfHeats() ;


		WCHAR text2345o[280]={0};
		wsprintfW(text2345o,L"Use the left analog stick to adjust the text.");
		FontSetColour(0xffff00);
		FontSmallText(text2345o,250,(480-90), 600);	

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

	if(fontResizeM == 1) {
		unsigned char *lock=NULL;
		setTextureMode();
		makeVertexListController();
		VertexBufferController->Lock(0,sizeof(VertexList),&lock,0); if (lock==NULL) return 1;
		memcpy(lock,VertexListController,sizeof(VertexList));
		VertexBufferController->Unlock();
		Device->SetTexture(0,TexMainMenu); 
		Device->SetStreamSource(0,VertexBufferController,sizeof(CustomVertex));
		Device->SetVertexShader(D3DFVF_CUSTOMVERTEX);
		Device->DrawPrimitive(D3DPT_TRIANGLESTRIP,0,2);


		int xO = 640/2;
		int yO = 160;
		int oSpace = vSpace;
		unsigned int c = 0x00ffffff;
		//yO -= 20;
		if(optionSelectedM == 0) c = menuColor[MenuOptionSelected]; else c = menuColor[MenuOption];
		//////dprintf("V");
		WCHAR text345678_[80]={0};
		wsprintfW(text345678_,L"Select Game");
		FontSetColour(c);
		FontCenteredText(text345678_,xO+zLeftMM,yO+zTopMM, 600);
		yO += oSpace;

		if(optionSelectedM == 1) c = menuColor[MenuOptionSelected]; else c = menuColor[MenuOption];
		//////dprintf("V");
		WCHAR stext345678_[80]={0};
		wsprintfW(stext345678_,L"Favorite Games");
		FontSetColour(c);
		FontCenteredText(stext345678_,xO+zLeftMM,yO+zTopMM, 600);
		yO += oSpace;

			if(optionSelectedM == 2) c = menuColor[MenuOptionSelected]; else c = menuColor[MenuOption];
		WCHAR kaaaatext345678_[80]={0};
		wsprintfW(kaaaatext345678_,L"Music Player");
		FontSetColour(c);
		FontCenteredText(kaaaatext345678_,xO+zLeftMM,yO+zTopMM, 600);
		yO += oSpace;

		if(optionSelectedM == 3) c = menuColor[MenuOptionSelected]; else c = menuColor[MenuOption];
		WCHAR atext345678_[80]={0};
		wsprintfW(atext345678_,L"Options");
		FontSetColour(c);
		FontCenteredText(atext345678_,xO+zLeftMM,yO+zTopMM, 600);
		yO += oSpace;


		if(optionSelectedM == 4) c = menuColor[MenuOptionSelected]; else c = menuColor[MenuOption];
		WCHAR faaatext345678_[80]={0};
		wsprintfW(faaatext345678_,L"Help");
		FontSetColour(c);
		FontCenteredText(faaatext345678_,xO+zLeftMM,yO+zTopMM, 600);
		yO += oSpace;


		if(optionSelectedM == 5) c = menuColor[MenuOptionSelected]; else c = menuColor[MenuOption];
		WCHAR aaaatext345678_[80]={0};
		wsprintfW(aaaatext345678_,L"Exit");
		FontSetColour(c);
		FontCenteredText(aaaatext345678_,xO+zLeftMM,yO+zTopMM, 600);
		yO += oSpace;


		WCHAR text2345o[280]={0};
		wsprintfW(text2345o,L"Use the left analog stick to adjust the text.");
		FontSetColour(0xffff00);
		FontSmallText(text2345o,250,(480-90), 600);	

	

		return 0;
	}

	if(screenResizeG == 1) {
		unsigned char *lock=NULL;
		setTextureMode();
		MakeVertexList();
		VertexBuffer->Lock(0,sizeof(VertexList),&lock,0); if (lock==NULL) return 1;
		memcpy(lock,VertexList,sizeof(VertexList));
		VertexBuffer->Unlock();
		Device->SetTexture(0,TexMenu);
		Device->SetStreamSource(0,VertexBuffer,sizeof(CustomVertex));
		Device->SetVertexShader(D3DFVF_CUSTOMVERTEX);
		Device->DrawPrimitive(D3DPT_TRIANGLESTRIP,0,2);

		WCHAR text2345o[280]={0};
		wsprintfW(text2345o,L"Use the left and right analog sticks to adjust the image.");
		FontSetColour(0xffff00);
		FontSmallText(text2345o,250,406, 600);	

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

	if(screenResizeB == 1) {
		unsigned char *lock=NULL;
		setTextureMode();
		makeVertexListController();
		VertexBufferController->Lock(0,sizeof(VertexList),&lock,0); if (lock==NULL) return 1;
		memcpy(lock,VertexListController,sizeof(VertexList));
		VertexBufferController->Unlock();
		Device->SetTexture(0,TexController); 
		Device->SetStreamSource(0,VertexBufferController,sizeof(CustomVertex));
		Device->SetVertexShader(D3DFVF_CUSTOMVERTEX);
		Device->DrawPrimitive(D3DPT_TRIANGLESTRIP,0,2);


		makeVertexListResizeB();
		VertexBufferPreviewB->Lock(0,sizeof(VertexList),&lock,0); if (lock==NULL) return 1;
		memcpy(lock,VertexListPreviewB,sizeof(VertexList));
		VertexBufferPreviewB->Unlock();
		Device->SetTexture(0,TexNoStatePreview);
		Device->SetStreamSource(0,VertexBufferPreviewB,sizeof(CustomVertex));
		Device->SetVertexShader(D3DFVF_CUSTOMVERTEX);
		Device->DrawPrimitive(D3DPT_TRIANGLESTRIP,0,2);


		WCHAR text2345o[280]={0};
		wsprintfW(text2345o,L"Use the left and right analog sticks to adjust the image.");
		FontSetColour(0xffff00);
		FontSmallText(text2345o,250,406, 600);	

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

	if(fontResizeClip == 1) {
		unsigned char *lock=NULL;
		setTextureMode();
		makeVertexListController();
		VertexBufferController->Lock(0,sizeof(VertexList),&lock,0); if (lock==NULL) return 1;
		memcpy(lock,VertexListController,sizeof(VertexList));
		VertexBufferController->Unlock();
		Device->SetTexture(0,TexController); 
		Device->SetStreamSource(0,VertexBufferController,sizeof(CustomVertex));
		Device->SetVertexShader(D3DFVF_CUSTOMVERTEX);
		Device->DrawPrimitive(D3DPT_TRIANGLESTRIP,0,2);

		drawListOfHeats() ;
		//drawHelpMenu();



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

		WCHAR text2345o[280]={0};
		wsprintfW(text2345o,L"Use the left and right analog sticks to adjust the text clipping.");
		FontSetColour(0xffff00);
		FontSmallText(text2345o,250,(480-80), 600);	
		return 0;
	}

	

	if(screenResizeA == 1) {
		unsigned char *lock=NULL;
		setTextureMode();
		makeVertexListController();
		VertexBufferController->Lock(0,sizeof(VertexList),&lock,0); if (lock==NULL) return 1;
		memcpy(lock,VertexListController,sizeof(VertexList));
		VertexBufferController->Unlock();
		Device->SetTexture(0,TexMainMenu); 
		Device->SetStreamSource(0,VertexBufferController,sizeof(CustomVertex));
		Device->SetVertexShader(D3DFVF_CUSTOMVERTEX);
		Device->DrawPrimitive(D3DPT_TRIANGLESTRIP,0,2);


		Device->SetRenderState(D3DRS_ALPHABLENDENABLE,TRUE);
		makeAnimatedVertexList();
		AnimatedVertexBuffer->Lock(0,sizeof(VertexList),&lock,0); if (lock==NULL) return 1;
		memcpy(lock,AnimatedVertexList,sizeof(VertexList));
		AnimatedVertexBuffer->Unlock();
		Device->SetTexture(0,TexLogo);
		Device->SetStreamSource(0,AnimatedVertexBuffer,sizeof(CustomVertex));
		Device->SetVertexShader(D3DFVF_CUSTOMVERTEX);
		Device->DrawPrimitive(D3DPT_TRIANGLESTRIP,0,2);
		Device->SetRenderState(D3DRS_ALPHABLENDENABLE,FALSE);


		WCHAR text2345o[280]={0};
		wsprintfW(text2345o,L"Use the left and right analog sticks to adjust the image.");
		FontSetColour(0xffff00);
		FontSmallText(text2345o,250,406, 600);	

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


	if(screenResizeA2 == 1) {
		unsigned char *lock=NULL;
		setTextureMode();
		makeVertexListController();
		VertexBufferController->Lock(0,sizeof(VertexList),&lock,0); if (lock==NULL) return 1;
		memcpy(lock,VertexListController,sizeof(VertexList));
		VertexBufferController->Unlock();
		Device->SetTexture(0,TexMenu); 
		Device->SetStreamSource(0,VertexBufferController,sizeof(CustomVertex));
		Device->SetVertexShader(D3DFVF_CUSTOMVERTEX);
		Device->DrawPrimitive(D3DPT_TRIANGLESTRIP,0,2);


		Device->SetRenderState(D3DRS_ALPHABLENDENABLE,TRUE);
		makeAnimatedVertexListR();
		AnimatedVertexBuffer->Lock(0,sizeof(VertexList),&lock,0); if (lock==NULL) return 1;
		memcpy(lock,AnimatedVertexList,sizeof(VertexList));
		AnimatedVertexBuffer->Unlock();
		Device->SetTexture(0,TexLogo2);
		Device->SetStreamSource(0,AnimatedVertexBuffer,sizeof(CustomVertex));
		Device->SetVertexShader(D3DFVF_CUSTOMVERTEX);
		Device->DrawPrimitive(D3DPT_TRIANGLESTRIP,0,2);
		Device->SetRenderState(D3DRS_ALPHABLENDENABLE,FALSE);


		WCHAR text2345o[280]={0};
		wsprintfW(text2345o,L"Use the left and right analog sticks to adjust the image.");
		FontSetColour(0xffff00);
		FontSmallText(text2345o,250,406, 600);	

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

	if(screenResizeS == 1) {
		unsigned char *lock=NULL;
		setTextureMode();
		makeVertexListController();
		VertexBufferController->Lock(0,sizeof(VertexList),&lock,0); if (lock==NULL) return 1;
		memcpy(lock,VertexListController,sizeof(VertexList));
		VertexBufferController->Unlock();
		Device->SetTexture(0,TexMenu); 
		Device->SetStreamSource(0,VertexBufferController,sizeof(CustomVertex));
		Device->SetVertexShader(D3DFVF_CUSTOMVERTEX);
		Device->DrawPrimitive(D3DPT_TRIANGLESTRIP,0,2);


		Device->SetRenderState(D3DRS_ALPHABLENDENABLE,TRUE);


		zA = 0;

		makeStationaryAnimatedVertexList();
		StationaryAnimatedVertexBuffer->Lock(0,sizeof(VertexList),&lock,0); if (lock==NULL) return 1;
		memcpy(lock,StationaryAnimatedVertexList,sizeof(VertexList));
		StationaryAnimatedVertexBuffer->Unlock();
		Device->SetTexture(0,TexStationary_0);
		Device->SetStreamSource(0,StationaryAnimatedVertexBuffer,sizeof(CustomVertex));
		Device->SetVertexShader(D3DFVF_CUSTOMVERTEX);
		Device->DrawPrimitive(D3DPT_TRIANGLESTRIP,0,2);
		Device->SetRenderState(D3DRS_ALPHABLENDENABLE,FALSE);


		WCHAR text2345o[280]={0};
		wsprintfW(text2345o,L"Use the right analog stick to adjust the image.");
		FontSetColour(0xffffff);
		FontSmallText(text2345o,250,(sHeight/2), 600);	

		WCHAR atext2345o[280]={0};
		wsprintfW(atext2345o,L"Then place the image off the left side of the screen");
		FontSetColour(0xffffff);
		FontSmallText(atext2345o,250,(sHeight/2)+20, 600);	

		WCHAR Aatext2345o[280]={0};
		wsprintfW(Aatext2345o,L"so that it is not visible.");
		FontSetColour(0xffffff);
		FontSmallText(Aatext2345o,250,(sHeight/2)+40, 600);	

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

	

	MakeVertexList();
	setTextureMode();
	VertexBuffer->Lock(0,sizeof(VertexList),&lock,0); if (lock==NULL) return 1;
	memcpy(lock,VertexList,sizeof(VertexList));
	VertexBuffer->Unlock();
	Device->SetTexture(0,TexMenu);
	Device->SetStreamSource(0,VertexBuffer,sizeof(CustomVertex));
	Device->SetVertexShader(D3DFVF_CUSTOMVERTEX);
	Device->DrawPrimitive(D3DPT_TRIANGLESTRIP,0,2);
	Device->SetRenderState(D3DRS_ALPHABLENDENABLE,TRUE);
	VertexBufferPreview->Lock(0,sizeof(VertexList),&lock,0); if (lock==NULL) return 1;
	memcpy(lock,VertexListPreview,sizeof(VertexList));
	VertexBufferPreview->Unlock();
	if(musicPlayer == 0) {
		if(useNoRom == false)
			Device->SetTexture(0,TexPreview);	
		else 
			Device->SetTexture(0,TexPreview2);
	}
	else {
		Device->SetTexture(0,TexPreviewMedia);
	}


	if(musicPlayer == 1) {
		makeVertexListResizeGP();
		VertexBufferPreviewGP->Lock(0,sizeof(VertexList),&lock,0); if (lock==NULL) return 1;
		memcpy(lock,VertexListPreviewGP,sizeof(VertexList));
		VertexBufferPreviewGP->Unlock();
		Device->SetTexture(0,TexPreviewMedia);
		Device->SetStreamSource(0,VertexBufferPreviewGP,sizeof(CustomVertex));
		Device->SetVertexShader(D3DFVF_CUSTOMVERTEX);
		Device->DrawPrimitive(D3DPT_TRIANGLESTRIP,0,2);
	}
	else {
	
		


		Device->SetStreamSource(0,VertexBufferPreview,sizeof(CustomVertex));
		Device->SetVertexShader(D3DFVF_CUSTOMVERTEX);
		Device->DrawPrimitive(D3DPT_TRIANGLESTRIP,0,2);

		Device->SetRenderState(D3DRS_ALPHABLENDENABLE,FALSE);
		if(videoRender)
			drawMovie();
		setTextureMode();
		Device->SetRenderState(D3DRS_ALPHABLENDENABLE,TRUE);
		//draw the border
		if(useNoRom == false && showBorder == 1 && musicPlayer == 0) {
			VertexBufferPreviewBorder->Lock(0,sizeof(VertexList),&lock,0); if (lock==NULL) return 1;
			memcpy(lock,VertexListPreviewBorder,sizeof(VertexList));
			VertexBufferPreviewBorder->Unlock();
			Device->SetTexture(0,TexPreviewBorder);
			Device->SetStreamSource(0,VertexBufferPreviewBorder,sizeof(CustomVertex));
			Device->SetVertexShader(D3DFVF_CUSTOMVERTEX);
			Device->DrawPrimitive(D3DPT_TRIANGLESTRIP,0,2);
		}
	}

	if(automaticScreenShotSwitching == 1) {
		if(getAnalog() == 1) {
			if(animateScreenShot()  == 1) {
				screenShotSlotAuto++;
				if(screenShotSlotAuto > 8) screenShotSlotAuto = 1;
				changePreviewUp() ;
			}
		}
	}
	if(animateStationaryFrame2() == 1) {
		zA += animationSpeed;
		if(zA > cDist) {
			zA = 0;
		}
	}

	//drawn  animated character
	makeStationaryAnimatedVertexList();
	StationaryAnimatedVertexBuffer->Lock(0,sizeof(VertexList),&lock,0); if (lock==NULL) return 1;
	memcpy(lock,StationaryAnimatedVertexList,sizeof(VertexList));
	StationaryAnimatedVertexBuffer->Unlock();


	if(animationFrames != 0) {

		if(animateStationaryFrame() == 1) {
			currentStationaryFrame++;
			if(currentStationaryFrame > (animationFrames-1)) {  
				if(repeatAnimation == 1) { 				
					currentStationaryFrame = 0;
				}
				else {
					currentStationaryFrame = (animationFrames-1);
				}
			}
		}

		if(currentStationaryFrame == 0) Device->SetTexture(0,TexStationary_0);
		if(currentStationaryFrame == 1) Device->SetTexture(0,TexStationary_1);
		if(currentStationaryFrame == 2) Device->SetTexture(0,TexStationary_2);
		if(currentStationaryFrame == 3) Device->SetTexture(0,TexStationary_3);
		if(currentStationaryFrame == 4) Device->SetTexture(0,TexStationary_4);
		if(currentStationaryFrame == 5) Device->SetTexture(0,TexStationary_5);
		if(currentStationaryFrame == 6) Device->SetTexture(0,TexStationary_6);
		if(currentStationaryFrame == 7) Device->SetTexture(0,TexStationary_7);
		if(currentStationaryFrame == 8) Device->SetTexture(0,TexStationary_8);
		if(currentStationaryFrame == 9) Device->SetTexture(0,TexStationary_9);
		if(currentStationaryFrame == 10) Device->SetTexture(0,TexStationary_10);
		if(currentStationaryFrame == 11) Device->SetTexture(0,TexStationary_11);
		if(currentStationaryFrame == 12) Device->SetTexture(0,TexStationary_12);
		if(currentStationaryFrame == 13) Device->SetTexture(0,TexStationary_13);
		if(currentStationaryFrame == 14) Device->SetTexture(0,TexStationary_14);
		if(currentStationaryFrame == 15) Device->SetTexture(0,TexStationary_15);
		if(currentStationaryFrame == 16) Device->SetTexture(0,TexStationary_16);
		if(currentStationaryFrame == 17) Device->SetTexture(0,TexStationary_17);

		Device->SetStreamSource(0,StationaryAnimatedVertexBuffer,sizeof(CustomVertex));
		Device->SetVertexShader(D3DFVF_CUSTOMVERTEX);
		Device->DrawPrimitive(D3DPT_TRIANGLESTRIP,0,2);
		//Device->SetRenderState(D3DRS_ALPHABLENDENABLE,FALSE);
	}
	//Fade overlay
	if(fadeOption == 0) {
		Device->SetRenderState(D3DRS_ALPHABLENDENABLE,TRUE);
		if(fadeColor > 0) {
			fadeColor -=fadeSpeed;
			if(fadeColor < fadeSpeed) { fadeColor = 0; }
		}
		if(fadeColor != 0) {
			makeVertexListController();
			VertexBufferController->Lock(0,sizeof(VertexList),&lock,0); if (lock==NULL) return 1;
			memcpy(lock,VertexListController,sizeof(VertexList));
			VertexBufferController->Unlock();
			Device->SetTexture(0,TexMainMenu); 
			Device->SetStreamSource(0,VertexBufferController,sizeof(CustomVertex));
			Device->SetVertexShader(D3DFVF_CUSTOMVERTEX);
			Device->DrawPrimitive(D3DPT_TRIANGLESTRIP,0,2);
			Device->SetRenderState(D3DRS_ALPHABLENDENABLE,FALSE);
		}
	}
	else {
		Device->SetRenderState(D3DRS_ALPHABLENDENABLE,TRUE);
		if(fadeColor > 0) {
			fadeColor -=fadeSpeed;
			if(fadeColor < fadeSpeed) fadeColor = 0;
		}
		makeVertexListController();
		VertexBufferController->Lock(0,sizeof(VertexList),&lock,0); if (lock==NULL) return 1;
		memcpy(lock,VertexListController,sizeof(VertexList));
		VertexBufferController->Unlock();
		Device->SetTexture(0,TexController); 
		Device->SetStreamSource(0,VertexBufferController,sizeof(CustomVertex));
		Device->SetVertexShader(D3DFVF_CUSTOMVERTEX);
		Device->DrawPrimitive(D3DPT_TRIANGLESTRIP,0,2);

		Device->SetRenderState(D3DRS_ALPHABLENDENABLE,FALSE);
	}
	Device->SetRenderState(D3DRS_ALPHABLENDENABLE,TRUE);
	makeAnimatedVertexListR();
	AnimatedVertexBuffer->Lock(0,sizeof(VertexList),&lock,0); if (lock==NULL) return 1;
	memcpy(lock,AnimatedVertexList,sizeof(VertexList));
	AnimatedVertexBuffer->Unlock();
	Device->SetTexture(0,TexLogo2);
	Device->SetStreamSource(0,AnimatedVertexBuffer,sizeof(CustomVertex));
	Device->SetVertexShader(D3DFVF_CUSTOMVERTEX);
	Device->DrawPrimitive(D3DPT_TRIANGLESTRIP,0,2);
	Device->SetRenderState(D3DRS_ALPHABLENDENABLE,FALSE);	

	if(musicPlayer == 1)
		XBSound_DrawLevelMeters( m_pDSound, 40+360.0f+zLeftMPL, 5+125.0f+zTopMPL, 110.0f+zRightMPL, 75.0f-25+40+zBottomMPL );
	
	
	
	
	
	
	return 0;
}




void loadScreen() {
	Device->Clear( 0, NULL, D3DCLEAR_TARGET,0, 1.0f, 0L ); 
	unsigned char *lock=NULL;
	setTextureMode();
	makeVertexListController();
	VertexBufferController->Lock(0,sizeof(VertexList),&lock,0); if (lock==NULL) return;
	memcpy(lock,VertexListController,sizeof(VertexList));
	VertexBufferController->Unlock();
	Device->SetTexture(0,TexController); 
	Device->SetStreamSource(0,VertexBufferController,sizeof(CustomVertex));
	Device->SetVertexShader(D3DFVF_CUSTOMVERTEX);
	Device->DrawPrimitive(D3DPT_TRIANGLESTRIP,0,2);
	WCHAR text2345[280]={0};
	wsprintfW(text2345,L"Please wait while your selection is loading...");
	FontSetColour(0xffff00);
	FontSmallText(text2345,sWidth/2,sHeight/2, 600);	
	if(showAvailMemory) showMemory();
	Device->Present(NULL,NULL,NULL,NULL);
	Device->PersistDisplay(); 
}
extern void processOptions();
extern void setFlickerSoft();

void setVertex() {
	unsigned char *lock=NULL;
	makeVertexListLinear();
	VertexBufferLinear->Lock(0,sizeof(VertexListLinear),&lock,0); 
	memcpy(lock,VertexListLinear,sizeof(VertexListLinear));
	VertexBufferLinear->Unlock();
	Device->SetTexture(0,TexScreen);
	Device->SetStreamSource(0,VertexBufferLinear,sizeof(CustomVertex));
	Device->SetVertexShader(D3DFVF_CUSTOMVERTEX);
	Device->SetTextureStageState( 0, D3DTSS_ADDRESSU, D3DTADDRESS_CLAMP );
	Device->SetTextureStageState( 0, D3DTSS_ADDRESSV, D3DTADDRESS_CLAMP );
}
D3DPRESENT_PARAMETERS d3dpp; 



extern bool v720pAvailable; 
extern bool v480pAvailable; 
extern bool v1080iAvailable; 
extern void checkForHDTVResolutions();
extern int HDMode;
extern pixelRatio;
int DirectInit()
{

	D3DDISPLAYMODE mode;
	int ret=0;

	memset(&d3dpp,0,sizeof(d3dpp));
	memset(&mode,0,sizeof(mode));

	Direct3D=Direct3DCreate8(D3D_SDK_VERSION); if (Direct3D==NULL) return 1;

	// Set up the structure used to create the D3D device:
	sHeight = 480;
	sWidth = 640;	

	d3dpp.BackBufferWidth =sWidth;
	d3dpp.BackBufferHeight=sHeight;
	d3dpp.BackBufferCount =1;
	d3dpp.SwapEffect=D3DSWAPEFFECT_DISCARD;//WAS COPY

	DWORD XVidMode = XGetVideoFlags();

	if ( XGetAVPack() == XC_AV_PACK_HDTV) {
		if(XVidMode & XC_VIDEO_FLAGS_HDTV_480p) {
			d3dpp.Flags = D3DPRESENTFLAG_PROGRESSIVE;
			d3dpp.BackBufferFormat = D3DFMT_A8R8G8B8;
		}
		else {
			d3dpp.Flags = D3DPRESENTFLAG_INTERLACED;
			d3dpp.BackBufferFormat  = D3DFMT_LIN_R5G6B5 ;
		}
	}
	else {
		d3dpp.Flags = D3DPRESENTFLAG_INTERLACED;
		d3dpp.BackBufferFormat  = D3DFMT_LIN_R5G6B5 ;
	}

	d3dpp.FullScreen_PresentationInterval = D3DPRESENT_INTERVAL_DEFAULT;//ONE;//D3DPRESENT_INTERVAL_IMMEDIATE

	if(pixelRatio == 1 && HDMode == 0)
		d3dpp.Flags |= D3DPRESENTFLAG_10X11PIXELASPECTRATIO;


	

	DWORD videoFlags = XGetVideoFlags();
	if(XGetVideoStandard() == XC_VIDEO_STANDARD_PAL_I)
	{
		//set pal60 if available.
		if(videoFlags & XC_VIDEO_FLAGS_PAL_60Hz)
			d3dpp.FullScreen_RefreshRateInHz = 60 ;
		else
			d3dpp.FullScreen_RefreshRateInHz = 50 ;
	}
	else
		d3dpp.FullScreen_RefreshRateInHz = 60 ;





	if(vsyncEnabled == 1) d3dpp.FullScreen_PresentationInterval = D3DPRESENT_INTERVAL_ONE;
	if(vsyncEnabled == 0) d3dpp.FullScreen_PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE;//DEFAULT;//ONE;
	if(vsyncEnabled == 2) d3dpp.FullScreen_PresentationInterval = D3DPRESENT_INTERVAL_TWO;
	if(vsyncEnabled == 3) d3dpp.FullScreen_PresentationInterval = D3DPRESENT_INTERVAL_THREE;

	checkForHDTVResolutions(); 
	if(!v720pAvailable && !v1080iAvailable) { 
		HDMode = 0;
	} 
	if(v720pAvailable && HDMode == 1) { //from ini
		sWidth = 1280;
		sHeight = 720;
		d3dpp.Flags = D3DPRESENTFLAG_PROGRESSIVE | D3DPRESENTFLAG_WIDESCREEN ; 
		d3dpp.BackBufferFormat = D3DFMT_A8R8G8B8 ; 
		d3dpp.BackBufferWidth  = 1280; 
		d3dpp.BackBufferHeight  = 720; 
	} 
	if(v1080iAvailable && HDMode == 2) { //from ini
		sWidth = 1920;
		sHeight = 1080;
		d3dpp.Flags = D3DPRESENTFLAG_WIDESCREEN | D3DPRESENTFLAG_INTERLACED ; 
		d3dpp.BackBufferFormat = D3DFMT_LIN_R5G6B5 ; 
		d3dpp.BackBufferWidth  = 1920; 
		d3dpp.BackBufferHeight = 1080; 
	} 

	Direct3D->CreateDevice(0,D3DDEVTYPE_HAL,NULL,D3DCREATE_HARDWARE_VERTEXPROCESSING,&d3dpp,&Device);


	if (Device==NULL) return 1;

	Device->GetBackBuffer(0,D3DBACKBUFFER_TYPE_MONO,&DirectBack);
	if (DirectBack==NULL) return 1;

	Device->CreateVertexBuffer(sizeof(VertexList),0,D3DFVF_CUSTOMVERTEX,D3DPOOL_DEFAULT,&VertexBuffer);
	if (VertexBuffer==NULL) return 1;

	Device->CreateVertexBuffer(sizeof(AnimatedVertexList),0,D3DFVF_CUSTOMVERTEX,D3DPOOL_DEFAULT,&AnimatedVertexBuffer);
	if (AnimatedVertexBuffer==NULL) return 1;

	Device->CreateVertexBuffer(sizeof(StationaryAnimatedVertexList),0,D3DFVF_CUSTOMVERTEX,D3DPOOL_DEFAULT,&StationaryAnimatedVertexBuffer);
	if (StationaryAnimatedVertexBuffer==NULL) return 1;

	Device->CreateVertexBuffer(sizeof(VertexListPreview),0,D3DFVF_CUSTOMVERTEX,D3DPOOL_DEFAULT,&VertexBufferPreview);
	if (VertexBufferPreview==NULL) return 1;

	Device->CreateVertexBuffer(sizeof(VertexListImage),0,D3DFVF_CUSTOMVERTEX,D3DPOOL_DEFAULT,&VertexBufferImage);
	if (VertexBufferImage==NULL) return 1;

	Device->CreateVertexBuffer(sizeof(VertexListPreviewGP),0,D3DFVF_CUSTOMVERTEX,D3DPOOL_DEFAULT,&VertexBufferPreviewGP);
	if (VertexBufferPreviewGP==NULL) return 1;

	Device->CreateVertexBuffer(sizeof(VertexListPreviewBorder),0,D3DFVF_CUSTOMVERTEX,D3DPOOL_DEFAULT,&VertexBufferPreviewBorder);
	if (VertexBufferPreviewBorder==NULL) return 1;


	Device->CreateVertexBuffer(sizeof(VertexListPreviewB),0,D3DFVF_CUSTOMVERTEX,D3DPOOL_DEFAULT,&VertexBufferPreviewB);
	if (VertexBufferPreviewB==NULL) return 1;

	Device->CreateVertexBuffer(sizeof(VertexListPreview2),0,D3DFVF_CUSTOMVERTEX,D3DPOOL_DEFAULT,&VertexBufferPreview2);
	if (VertexBufferPreview2==NULL) return 1;

	Device->CreateVertexBuffer(sizeof(VertexListLinear),0,D3DFVF_CUSTOMVERTEX,D3DPOOL_DEFAULT,&VertexBufferLinear);
	if (VertexBufferLinear==NULL) return 1;

	Device->CreateVertexBuffer(sizeof(VertexListResize),0,D3DFVF_CUSTOMVERTEX,D3DPOOL_DEFAULT,&VertexBufferResize);
	if (VertexBufferResize==NULL) return 1;

	Device->CreateVertexBuffer(sizeof(VertexListController),0,D3DFVF_CUSTOMVERTEX,D3DPOOL_DEFAULT,&VertexBufferController);
	if (VertexBufferController==NULL) return 1;

	Device->CreateVertexBuffer(sizeof(VertexListOptions),0,D3DFVF_CUSTOMVERTEX,D3DPOOL_DEFAULT,&VertexBufferOptions);
	if (VertexBufferOptions==NULL) return 1;

	ret=TexScreenInit("Zelda"); if (ret) return 1;

	FontInit(fontType);

	Device->SetRenderState(D3DRS_LIGHTING,0); // Turn off lighting

	// Set up texture modes:
	Device->SetTextureStageState(0,D3DTSS_ADDRESSU,D3DTADDRESS_CLAMP);
	Device->SetTextureStageState(0,D3DTSS_ADDRESSV,D3DTADDRESS_CLAMP);

	MakeVertexList();

	unsigned char *lock=NULL;
	VertexBufferPreview->Lock(0,sizeof(VertexList),&lock,0); if (lock==NULL) return 1;
	memcpy(lock,VertexListPreview,sizeof(VertexList));
	VertexBufferPreview->Unlock();


	VertexBufferPreviewGP->Lock(0,sizeof(VertexList),&lock,0); if (lock==NULL) return 1;
	memcpy(lock,VertexListPreviewGP,sizeof(VertexList));
	VertexBufferPreviewGP->Unlock();

	VertexBufferPreviewBorder->Lock(0,sizeof(VertexList),&lock,0); if (lock==NULL) return 1;
	memcpy(lock,VertexListPreviewBorder,sizeof(VertexList));
	VertexBufferPreviewBorder->Unlock();



	VertexBufferPreviewB->Lock(0,sizeof(VertexList),&lock,0); if (lock==NULL) return 1;
	memcpy(lock,VertexListPreviewB,sizeof(VertexList));
	VertexBufferPreviewB->Unlock();

	VertexBufferPreview2->Lock(0,sizeof(VertexList),&lock,0); if (lock==NULL) return 1;
	memcpy(lock,VertexListPreview2,sizeof(VertexList));
	VertexBufferPreview2->Unlock();

	VertexBuffer->Lock(0,sizeof(VertexList),&lock,0); if (lock==NULL) return 1;
	memcpy(lock,VertexList,sizeof(VertexList));
	VertexBuffer->Unlock();

	AnimatedVertexBuffer->Lock(0,sizeof(VertexList),&lock,0); if (lock==NULL) return 1;
	memcpy(lock,AnimatedVertexList,sizeof(VertexList));
	AnimatedVertexBuffer->Unlock();


	StationaryAnimatedVertexBuffer->Lock(0,sizeof(VertexList),&lock,0); if (lock==NULL) return 1;
	memcpy(lock,StationaryAnimatedVertexList,sizeof(VertexList));
	StationaryAnimatedVertexBuffer->Unlock();

	VertexBufferLinear->Lock(0,sizeof(VertexList),&lock,0); if (lock==NULL) return 1;
	memcpy(lock,VertexListLinear,sizeof(VertexList));
	VertexBufferLinear->Unlock();

	VertexBufferResize->Lock(0,sizeof(VertexList),&lock,0); if (lock==NULL) return 1;
	memcpy(lock,VertexListResize,sizeof(VertexList));
	VertexBufferResize->Unlock();

	VertexBufferController->Lock(0,sizeof(VertexList),&lock,0); if (lock==NULL) return 1;
	memcpy(lock,VertexListController,sizeof(VertexList));
	VertexBufferController->Unlock();

	VertexBufferOptions->Lock(0,sizeof(VertexList),&lock,0); if (lock==NULL) return 1;
	memcpy(lock,VertexListOptions,sizeof(VertexList));
	VertexBufferOptions->Unlock();

	processOptions();
	setFlickerSoft();

	return 0;
}
