/* Glover PSX MAIN */

#include "glover.h"

UBYTE	*version = VERSIONSTR;
//****************************************************************************
UBYTE	palmode			= (PALMODE*8);		//YES*8;
UBYTE	goldcd			= GOLDCD;	//if make GOLDCD check #define's in MAIN.H
UBYTE	music			= GOLDCD;	//NO; change to "goldcd" by fred coz it's the define I forgot to change last time!
UBYTE   dovideo         = GOLDCD;
UBYTE	keygrab			= OFF; //OFF  //RECORDKEYS  //PLAYKEYS
UBYTE	level			= TITLE;//ATLANTIS1;  //TITLE  ATLANTIS1   HUB8 etc. (see menu.h)
/***************************** MAIN *************************************/
UBYTE noofplayers=1;

TextureBankType *pGenericBank;	//, *pDemoSprs;

int main(void)	//DO NOT USE LOCAL VARIABLES IN MAIN! STACK POINTER CHANGES!!!!
{
#if EXCEPTION_HANDLER==YES
	install_exc();
#endif

	DB("\n\n GLOVER PSX %s\n\n",version);
//	InitialiseFiles();

	memset((void *)DCACHE,0,DCACHETOP-DCACHE);	/*CLEAR STACK MEMORY TO 0's */
	SetMem(2);
	ResetCallback();               /* RESET ALL OF THE CALLBACKS */

	//padInitialise();	// used to do a "PadInit(0)" too, which was what screwed the dualshock start button

	InitCards(); //test stuff for cards


	memoryInitialise((__heapbase & 0x0fffffff), __heapsize-65536);
	//fileInitialise();
	DB("about to initialise files\n");
	fileInitialise();
	DB("done initialise files\n");

	XAenable=TRUE;

	if ((music==YES)||(dovideo==YES))
	{
		CdInit();
		Init_XA_Tracks();
	}

	seedRandomInt(65787);
	memset((void *)DCACHE,0,DCACHETOP-DCACHE);	/*CLEAR STACK MEMORY TO 0's */

	initCRC();
	ResetCallback();               /* RESET ALL OF THE CALLBACKS */

	DB("about to setup display\n");


	padInitialise();	// used to do a "PadInit(0)" too, which was what screwed the dualshock start button
	SHOCK_STOP(0);
	SHOCK_NOBUZZ(0);

	Set_Up_Display(YES);
	Init_PolyLists();
	DB("done polylists\n");
	modelctrl.indDepth=2048;


	sfxInitialise(0);

	globalFX=SFXLoad("GLOBAL",0);

	textureInitVRAM();
	Cls();

 	defaultpolylist=Register_ObjectPolyList(OT_LENGTH,"DEFAULT POLYS",0);

/********** MAIN LOOP*********/

	world=HUB;

	DB("main\n");
	VSyncCallback(&VblCallback);   /* INCREMENTS VBLANK EVERY FRAME */
	Cls();



#if RELEASE == YES
	{
		int i;
		int max;

		menuShowScreen("LEGAL.TIM");

#if PALMODE==YES
		max = 100;
#else
		max = 120;
#endif

		for(i = max; i > 0; i--)
		{
			VSync(2);
		}
	}
#endif


//	if (dovideo==YES)newvideo("HASBRO.STR",HASBRO_VIDEO_LEN);

	if (dovideo==YES)newvideo("ATARI.STR",ATARI_VIDEO_LEN);
	if (dovideo==YES)newvideo("GLOVER.STR",INT_VIDEO_LEN);	//1354);

	// Initialise everything 
	spriteReset();
	textReset();
	lightInitFlat();
	lscapeInit();
	Init_Camera();
	Init_All_Effects();
	overlayInitialiseList();
	InitTextList();
	menuInitHiScores();

	//turns analog mode on on dual shock pads
	//PadSetMainMode(0,1,3);
	seedRandomInt(398623);

	modelctrl.lighting=LIGHTING_PARALLEL;

	// Just keep this in RAM. We always need it ...
#ifdef MULTI_LANGUAGE
	fontList[0]=textLoadFont("GFX\\EGLOFONT.SPT", TRUE);
	fontList[1]=textLoadFont("GFX\\ESMAFONT.SPT", TRUE);
	fontList[2]=textLoadFont("GFX\\ETIPFONT.SPT", TRUE);
#else
	fontList[0]=textLoadFont("GFX\\GLOVFONT.SPT", TRUE);
	fontList[1]=textLoadFont("GFX\\SMALFONT.SPT", TRUE);
	fontList[2]=textLoadFont("GFX\\TIPFONT.SPT", TRUE);
#endif
	pGenericBank=textureLoadBank("WORLDS\\GENERIC\\GENERIC.SPT");

	modelctrl.specialFX=99;
	ballTex[7]=FindTexture("SNOW");	// need snow texture
	modelctrl.specialFX=0;


	textureDownloadBank(pGenericBank);
	textureDestroyBank(pGenericBank);

//	pDemoSprs=textureLoadBank("GFX\\MENU.SPT");
//	ASSERT(pDemoSprs);
//	textureDownloadBank(pDemoSprs);
//	textureDestroyBank(pDemoSprs);


	generic_bff = BFF_LoadFile("WORLDS\\GENERIC\\GENERIC.BFF");
	handTidyGloveObject();


// ------ I think that's the top end of stuff that's permanantly loaded --------

#ifdef MULTI_LANGUAGE
	loadLangFile(0);
#endif

//	LoadMusic();


//	textureLoadBank("GFX\\OVERLAYS.SPT");

	//watersprites=textureLoadSPT("GFX\\ANIWATER.SPT");
	//waterflowsprites=textureLoadSPT("GFX\\WATERFLO.SPT");

	//SetupSky();

 //	if (level==TITLE)

//	allowPadHandler=TRUE;


	if (level!=TITLE)
	{
		gameMainGame(level);
	}

	menuSpinHub();
	return 0;
}

/************************************************************************************/
void atDemoInitialise(void);
void atDemoFrame(void);

GameInfoType	gameInfo;
HiScoreType		hiScores[NUM_LEVELS];







