#include <xtl.h>
/*
extern "C" {
	//#include "PsxCommon.h"
	#include "DEBUG.h"
	#include "MISC.h"
}
*/
#include "psxcommon.h"
extern "C"{
	#include "plugins.h"
}

static DWORD dThreadId;

HRESULT ReadConfig()
{
	//doit etre envoyer au thread 0 ...
	//strcpy(Config.Bios, "SCPH1001.BIN"); // Use actual BIOS
	strcpy(Config.Bios, "HLE"); // Use actual BIOS
	strcpy(Config.BiosDir, "game:\\BIOS\\");
	strcpy(Config.PatchesDir, "game:\\PATCHES\\");
	strcpy(Config.Net,"Disabled");
	strcpy(Config.Mcd1,"game:\\BIOS\\Memcard1.mcd");
	strcpy(Config.Mcd2,"game:\\BIOS\\Memcard2.mcd");

	Config.PsxOut = 0;
	Config.HLE = 0;
	Config.Xa = 0;  //XA enabled
	Config.Cdda = 0;
	Config.PsxAuto = 0; //Autodetect

	return S_OK;
}

HRESULT InitConfig()
{
	XMemSet(&Config, 0, sizeof(PcsxConfig));
	return S_OK;
}

void SetDynarec(int disable)
{
	Config.Cpu = disable;
}


HRESULT RunPsx()
{
	ReadConfig();

	SysPrintf("start main()\r\n");

	if (SysInit() == -1) 
	{
		printf("SysInit() Error!\n");
		return E_FAIL;
	}
	int operrror = OpenPlugins();

	SysReset();

	SysPrintf("CheckCdrom\r\n");
	int res = CheckCdrom();
	if(res)
		SysPrintf("CheckCdrom: %08x\r\n",res);
	res=LoadCdrom();
	if(res)
		SysPrintf("LoadCdrom: %08x\r\n",res);


	SysPrintf("Execute\r\n");
	Config.PsxOut = 0;
	psxCpu->Execute();

	return S_OK;
}
