#pragma once
#include "Thread.h"
//-----------------------------------------------------------------------------
// Path
//-----------------------------------------------------------------------------
#ifdef _XBOX
#	define EFFECT_FILE "game:\\media\\effect.fx"
//#	define DEFAULT_GAME "game:\\psxisos\\game.cue"
//#	define DEFAULT_GAME "game:\\psxisos\\castle.bin"
#	define DEFAULT_GAME "game:\\psxisos\\ff7.bin"
#	define X_FILE "game:\\media\\test.x"
#	define BG_FILE "game:\\media\\test.jpg"
#else
#	define EFFECT_FILE "Effect.fx"
#	define DEFAULT_GAME "sonic.sms"
#	define X_FILE "test.x"
#	define BG_FILE "test.jpg"
#endif

#define g_dwTileWidth   1280
#define g_dwTileHeight  256
#define g_dwFrameWidth  1280
#define g_dwFrameHeight 720

#define RENDER_D3D 0x1
#define RENDER_XUI 0x2

class Cemulator : public CThread, public CXuiCachingModule //Singleton
{
protected:
	virtual HRESULT RegisterXuiClasses();
	virtual HRESULT UnregisterXuiClasses();
public:

	static Cemulator & GetInstance()
	{
		static Cemulator instance;
		return instance;
	};
private:
	Cemulator(void){};
	Cemulator( const Cemulator & ); 
    Cemulator & operator =( const Cemulator & ); 

private:
	std::string defaut_rom;
	int mWidth;
	int mHeight;

	int mScreenWidth;
	int mScreenHeight;

	void SetSystemWidth(int w)
	{
		mWidth=w;
	};

	void SetSystemHeight(int h)
	{
		mHeight=h;
	};

	int GetSystemWidth()
	{
		return mWidth;
	};

	int GetSystemHeight()
	{
		return mHeight;
	};

	//PSx
	int GetWidth()
	{
		return mScreenWidth;
	};
	int GetHeight()
	{
		return mScreenHeight;
	};

	bool end;

	void SendExitSignal()
	{
		end=true;
	}

public:

	//PC SIDE
	void InitE();
	HRESULT InitVideo();
	HRESULT InitXui();
	void UnInitXui();
	HRESULT CloseVideo();
	void SetFilter(int i);
	//Appeler lors de l'affichage de l'emulation
	HRESULT Display();
	static DWORD WINAPI Cemulator::ThreadedDisplay(void * Obj);//Updatevideo+Render

	HRESULT LoadGame(std::string name, bool restart);

	//SYSTEM SIDE
	HRESULT InitSystem();
	HRESULT CloseSystem();

	void RenderXui();
	void RenderVideo();
	void UpdateVideo();
	void ClearScreen();

	void GetIsoFilename( char * a)
	{
		strcpy(a,defaut_rom.c_str());
	}

	void SetIsoFilename(std::string gamename)
	{
		defaut_rom=gamename;
	}

	bool IsXuiDisplayed();

	void StartEmulation();
	//Run
	HRESULT Run();
	HRESULT SetupThread();//Setup the display thread on core 2
};
