/********************************************************************/
/* Kamui function test program										*/
/* Test of SYSTEMCONFIGSTRUCT										*/
/* Test of 2V Latency												*/
/********************************************************************/
/*   COPYRIGHT (C) NEC Corporation 1998                             */
/*   All rights reserved by NEC Corporation. This program must be   */
/*   used solely for the purpose for which it was furnished by NEC  */
/*   Corporation. No part of this program may be reproduced or      */
/*   disclosed to others, in any form, without the prior written    */
/*   permission of NEC Corporation.                                 */
/*   Use of copyright notice does not evidence publication of this  */
/*   program.                                                       */
/********************************************************************/

#define		_STRICT_UNION_

/* Set Display Mode */
#define NTSC 1
/* Set Latency Mode */
#define LATENCY_2V 1

#include	<shinobi.h>
#include	<stdio.h>
#include	<string.h>
#include	<Machine.h>
#include	<private.h>

#include "kmgeo.h"
#include "cube.h"
#include "kmsrvice.h"

/****************************************************************************/
/**	Valuables for KAMUI *****************************************************/
/****************************************************************************/
	KMSURFACEDESC		PrimarySurfaceDesc;		/* Primary frame buffer		*/
	KMSURFACEDESC		BackSurfaceDesc;		/* Back-buffer frame buffer */
	PKMSURFACEDESC		pFB[2];
	KMVERTEXBUFFDESC	VertexBufferDesc;		/* Vertex-buffer			*/
	KMVERTEXCONTEXT		VertexContext01;		/* Vertex context			*/
	KMVERTEXCONTEXT		VertexContext05;		/* Vertex context			*/
	KMSURFACEDESC		TextureDesc[30];
	KMSYSTEMCONFIGSTRUCT	SystemConfig;

unsigned char *TextureReadBuffer;

#if 0
KMSURFACEDESC		WhiteTex;
KMDWORD	Texture[] = {
	0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,
	0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,
	0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,
	0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,
	0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,
	0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,
	0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,
	0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,
	0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,
	0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,
	0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,
	0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,
	0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,
	0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,
	0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,
	0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,
	0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,
};
#endif

	/* Settings Valuables for kmgeo */
#define MAXVERTEXNUM (20000)
	KMGVERTEX			kmVertex[MAXVERTEXNUM];			/* Vertex Data */
	KMGLIGHT			LightMat;



/****************************************************************************/
/**	KAMUI Initialize ********************************************************/
/****************************************************************************/
void SetupKamui(void)
{
	/* Settings for Display Mode */
#if NTSC
	sbInitSystem( NJD_RESOLUTION_640x480_NTSCNI, NJD_FRAMEBUFFER_MODE_RGB555, 1 );
#else
	sbInitSystem( NJD_RESOLUTION_VGA, NJD_FRAMEBUFFER_MODE_RGB555, 1 );
#endif
	pFB[0] = &PrimarySurfaceDesc;
	pFB[1] = &BackSurfaceDesc;

	/*----------------------------------------------------------------------------------- */
	/* Set up SYSTEMCONFIGSTRUCT */
	/* for System Flag */
	SystemConfig.dwSize	=	sizeof(KMSYSTEMCONFIGSTRUCT);
	SystemConfig.flags	=	KM_CONFIGFLAG_ENABLE_CLEAR_FRAMEBUFFER | KM_CONFIGFLAG_ENABLE_2V_LATENCY;

	/* for Frame buffer */
	SystemConfig.ppSurfaceDescArray	=	pFB;
	SystemConfig.nNumOfFrameBuffer	=	2;
	SystemConfig.nWidth				=	0;
	SystemConfig.nHeight			=	0;
	SystemConfig.nBpp				=	0;

	/* for Texture Memory */
	SystemConfig.nTextureMemorySize	=	(0x400000/sizeof(KMDWORD));	/* 4M byteĚTexture*/

#define VERTEXBUFFERSIZE (0x100000 / sizeof(KMDWORD))

	/* for Vertex buffer */
	SystemConfig.pBufferDesc		=	&VertexBufferDesc;			/* VertexBufferDesc */

	SystemConfig.pVertexBuffer		=	(PKMDWORD)(
											   ((KMDWORD)syMalloc(VERTEXBUFFERSIZE)
											   & 0x0FFFFFFF)
											   | 0xA0000000
											  );
	if(SystemConfig.pVertexBuffer == NULL)
	{
		while(1);	/* Error */
	}
	SystemConfig.nVertexBufferSize	=	(VERTEXBUFFERSIZE/sizeof(KMDWORD));	/* VertexBuffer:1.5MB */

	SystemConfig.fBufferSize[0]		=	50.0f;		/* Opaque 50% */
	SystemConfig.fBufferSize[1]		=	 0.0f;		/*	0% */
	SystemConfig.fBufferSize[2]		=	50.0f;		/* Trans 50% */
	SystemConfig.fBufferSize[3]		=	 0.0f;		/*	0% */
	SystemConfig.fBufferSize[4]		=	 0.0f;		/*	0% */

	/* for Latency Model */
#if LATENCY_2V
	SystemConfig.nVbufModel			=	 KM_VERTEXBUFMODEL_NOBUF_OPAQUE;
#else
	SystemConfig.nVbufModel			=	 KM_VERTEXBUFMODEL_NORMAL;
#endif
	kmSetSystemConfiguration( &SystemConfig );

	/* Initialize VertexContext */
	/* Floating Color , Textured Grouraud */
	memset(&VertexContext05, 0, sizeof(KMVERTEXCONTEXT));
	kmgDefaultGouraudTransSetting(&VertexContext05);

	VertexContext05.ShadingMode	= KM_TEXTUREGOURAUD;
	VertexContext05.ColorType	= KM_FLOATINGCOLOR;
	VertexContext05.UserClipMode= KM_USERCLIP_DISABLE;
	VertexContext05.bUseSpecular= TRUE;
	VertexContext05.RenderState = KM_COLORTYPE
								| KM_USERCLIPMODE
								| KM_USESPECULAR
								| KM_SHADINGMODE;
	kmProcessVertexRenderState(&VertexContext05);

}

/****************************************************************************/
/**	Background surface setting **********************************************/
/****************************************************************************/
void	InitBackGround(void)
{
	KMSTATUS			status;
	KMVERTEXCONTEXT		BackVertexContext;		/* Vertex context */
	KMVERTEX_01			BV[3];					/* pointer to Vertex */
	PVOID				pBV[3];					/* pointer to Vertex */

	/* Clear VertexContext */
	memset(&BackVertexContext,0,sizeof(KMVERTEXCONTEXT));

	/* Setup VertexContext */
	BackVertexContext.RenderState	= KM_DEPTHMODE  		| KM_CULLINGMODE				/* ISP/TSP IW */
									| KM_SCREENCOORDINATION	| KM_SHADINGMODE
									| KM_MODIFIER 			| KM_ZWRITEDISABLE				/* TSP CW */
									| KM_SRCBLENDINGMODE
									| KM_SRCSELECT			| KM_DSTSELECT
									| KM_FOGMODE			| KM_USESPECULAR
									| KM_USEALPHA			| KM_IGNORETEXTUREALPHA
									| KM_FLIPUV 			| KM_CLAMPUV 
									| KM_FILTERMODE			| KM_SUPERSAMPLE
									| KM_MIPMAPDADJUST 		| KM_TEXTURESHADINGMODE
									| KM_PARAMTYPE 			| KM_LISTTYPE 					/* Param CW */
									| KM_COLORTYPE			| KM_USESPECULAR
									| KM_UVFORMAT;

	/* for ParameterControlWord  */
	BackVertexContext.ParamType				= KM_POLYGON;
	BackVertexContext.ListType				= KM_OPAQUE_POLYGON;
	BackVertexContext.ColorType				= KM_FLOATINGCOLOR;
	BackVertexContext.bUseSpecular			= FALSE;
	BackVertexContext.UVFormat				= KM_32BITUV;

	/* for ISP/TSP InstructionWord  */
	BackVertexContext.DepthMode				= KM_GREATER;
	BackVertexContext.CullingMode			= KM_NOCULLING;
	BackVertexContext.ScreenCoordination	= KM_SCREEN;
	BackVertexContext.ShadingMode			= KM_NOTEXTUREGOURAUD;
	BackVertexContext.SelectModifier		= KM_NOMODIFIER;
	BackVertexContext.bZWriteDisable		= FALSE;			/* not effective on ARC1 */

	/* for TSP ControlWord  */
	BackVertexContext.SRCBlendingMode		= KM_ONE;
/*	BackVertexContext.DSTBlendingMode		= KM_ZERO;	// must not set this parameter on background plane */
	BackVertexContext.bSRCSel				= FALSE;			/* not effective on ARC1 */
	BackVertexContext.bDSTSel				= FALSE;			/* not effective on ARC1 */
	BackVertexContext.FogMode				= KM_NOFOG;			/* 11 is reserved */
	BackVertexContext.bUseSpecular			= FALSE;
	BackVertexContext.bUseAlpha				= FALSE;
	BackVertexContext.ClampUV				= KM_NOCLAMP;
	BackVertexContext.FilterMode			= KM_POINT_SAMPLE;
	BackVertexContext.bSuperSample			= FALSE;
	BackVertexContext.MipMapAdjust			= 0x00000004;		/* D=1.00 */
	BackVertexContext.TextureShadingMode	= KM_MODULATE;
	
	/* for Texture ControlBit */

	/* No effect on ARC1 */
	BackVertexContext.bColorClamp			= FALSE;
	BackVertexContext.PaletteBank			= 0;

	/* for GlobalColorData */
	BackVertexContext.fFaceColorAlpha		= 1.0f;		/* Face Color Alpha */
	BackVertexContext.fFaceColorRed			= 1.0f;		/* Face Color Red */
	BackVertexContext.fFaceColorGreen		= 1.0f;		/* Face Color Green */
	BackVertexContext.fFaceColorBlue		= 1.0f;		/* Face Color Blue */
	BackVertexContext.fOffsetColorAlpha		= 1.0f;		/* Specular Color Alpha */
	BackVertexContext.fOffsetColorRed		= 1.0f;		/* Specular Color Red */
	BackVertexContext.fOffsetColorGreen		= 1.0f;		/* Specular Color Green */
	BackVertexContext.fOffsetColorBlue		= 1.0f;		/* Specular Color Blue */

	status = kmProcessVertexRenderState(&BackVertexContext);
	status = kmSetBackGroundRenderState(&BackVertexContext);

	/*----------------------------------------------------------------------------------- */
	/* set VERTEX DATA */

	/* Vertex #1 */
	BV[0].ParamControlWord	= KM_VERTEXPARAM_NORMAL;
	BV[0].fX				=   0.0f;
	BV[0].fY				= 479.0f;
#if defined(_STRICT_UNION_)
	BV[0].u.fZ				=  0.0001f;
#else
	BV[0].fZ				=  0.0001f;
#endif
	BV[0].fBaseAlpha		=   0.0f;
	BV[0].fBaseRed			=   0.71f;
	BV[0].fBaseGreen		=   0.0f;
	BV[0].fBaseBlue			=   0.0f;

	/* Vertex #2 */
	BV[1].ParamControlWord	= KM_VERTEXPARAM_NORMAL;
	BV[1].fX				= 320.0f;
	BV[1].fY				=   0.0f;
#if defined(_STRICT_UNION_)
	BV[1].u.fZ				=  0.0001f;
#else
	BV[1].fZ				=  0.0001f;
#endif
	BV[1].fBaseAlpha		=   0.0f;
	BV[1].fBaseRed			=   0.0f;
	BV[1].fBaseGreen		=   0.71f;
	BV[1].fBaseBlue			=   0.0f;

	/* Vertex #3 */
	BV[2].ParamControlWord	= KM_VERTEXPARAM_ENDOFSTRIP;
	BV[2].fX				= 639.0f;
	BV[2].fY				= 479.0f;
#if defined(_STRICT_UNION_)
	BV[2].u.fZ				=  0.0001f;
#else
	BV[2].fZ				=  0.0001f;
#endif
	BV[2].fBaseAlpha		=   0.0f;
	BV[2].fBaseRed			=   0.0f;
	BV[2].fBaseGreen		=   0.0f;
	BV[2].fBaseBlue			=   0.71f;

	pBV[0] = &BV[0];
	pBV[1] = &BV[1];
	pBV[2] = &BV[2];

	/*----------------------------------------------------------------------------------- */
	/* set VERTEX */
	status = kmSetBackGroundPlane(	pBV,					/* pVertex */
									KM_VERTEXTYPE_01,		/* VertexType */
									sizeof(KMVERTEX_01)		/* StructSize */
									);
}

/****************************************************************************/
/**	Load Cuve Data **********************************************************/
/****************************************************************************/
int LoadCube(void)
{
	int	Face;
	int	iStrip;
	int	iVertex = 0;

	for (Face = 0; Face < sizeof(DXF3DFACEDATA)/sizeof(STRIPLIST); Face++)
	{
		for ( iStrip = 0 ; iStrip < DXF3DFACEDATA[Face].nVertexCount ; iStrip++ ) {
			kmVertex[iVertex] = DXF3DFACEDATA[Face].pStrip[iStrip];
			kmVertex[iVertex].MaterialColor[KMG_COLOR_A] = 0.5f;
			iVertex++;
		}
	}

	return Face;
}

/****************************************************************************/
/**	Load texture ************************************************************/
/****************************************************************************/
int LoadTexture(char *filename, GDFS_DIRREC dirrec, PKMSURFACEDESC pSurface)
{
    GDFS gdfs;
    Sint32 ret;
    Sint32 size;
	unsigned long *pSearch,nTextureSize;
	unsigned short *pInfo;
	int nLoop;
	KMINT32	nWidth, nHeight;
	KMTEXTURETYPE nTextureType;

    /* open file */
    gdfs = gdFsOpen(filename, dirrec);
    if (gdfs == NULL) return -1;	  	/* File Open Error */

    gdFsGetFileSize(gdfs, &size);     	/* get file size */
    size = gdFsCalcSctSize(size);   	/* calc sctor size */
    ret = gdFsRead(gdfs, size, (void *)TextureReadBuffer);    /* read file */
    gdFsClose(gdfs);					/* close file */
    if (ret != GDD_ERR_OK) return -2;	/* file read error */

	/* Check Texture Header */
	/* search 'PVRT' in Header */
	pSearch = (unsigned long *)TextureReadBuffer;
	nLoop = 0;
	while(nLoop < 8)
	{
		if(*pSearch == 0x54525650) break;
		pSearch++;
	}
	if(nLoop >= 8) return -3;	/* Can not find 'PVRT' */

	pSearch++;
	nTextureSize = *pSearch++;
	nTextureType = (KMTEXTURETYPE)*pSearch++;
	pInfo = (unsigned short *)pSearch;
	nWidth = (KMINT32)*pInfo++;
	nHeight = (KMINT32)*pInfo++;
	/* Surface Create */
	if (kmCreateTextureSurface(	pSurface,
							nWidth,
							nHeight,
							nTextureType) 
		!= KMSTATUS_SUCCESS) return -4;
	/* Texture Load */
	if (kmLoadTexture(		pSurface,
							(PKMDWORD)pInfo,
							FALSE,
							FALSE) != KMSTATUS_SUCCESS)
	{
		kmFreeTexture( pSurface );
		return -5;
	}
    return 0;
}

/****************************************************************************/
/**	Main ********************************************************************/
/****************************************************************************/
NJS_PERIPHERAL *per,*per1;

void main(int argc, char *argv[])
{
	float	fTranBuf[500][2];
	int nFace, Frame = 1;
	kmgVector tran_vec, scale_vec;
	int nDiffLine;
	int	nBox;
	int	i;
	int FadeCount = 0xC0;
	int ErrorCode;
	int light_num = 0;
	int tex_num = 0;
	#define light_num_max 4
	#define tex_num_max 4
	KMINT32	CurrentScanLine;
	KMPACKEDARGB Bordar;
	float	fBaseX = 0.0f, fBaseY = 0.0f;
	float	fSize;
	float	fLightZ = 0.0f;
	float	fAngleSpeed1, fAngleSpeed2;
	float	tran_x = 0.01f;
	float	tran_y = 0.01f;
	float	tran_z = 0.01f;
	tran_vec[0] = 0.f;
	tran_vec[1] = 0.f;
	tran_vec[2] = 1.f;

#ifdef __GNUC__
	shinobi_workaround();
#endif

	
	SetupKamui();			/* Initialize all settings for Kamui */
	/* Initialize for GUN Mode */
	txt_InitDisplayString();

	InitBackGround();		/* Setup background plane */

	/*  Texture File Read  */
#define TEXTUREBUFFSIZE (512*512*2)
	TextureReadBuffer = (unsigned char *)syMalloc(TEXTUREBUFFSIZE); /* Alloc Texture Load Buffer */
	ErrorCode = LoadTexture("m256tw2.pvr", NULL, &TextureDesc[0]);
	if(ErrorCode == 0)
	{
		VertexContext05.pTextureSurfaceDesc	= &TextureDesc[0];
		kmProcessVertexRenderState(&VertexContext05);
	}

	TextureReadBuffer = (unsigned char *)syMalloc(TEXTUREBUFFSIZE); /* Alloc Texture Load Buffer */
	ErrorCode = LoadTexture("yashi_ha.pvr", NULL, &TextureDesc[1]);
/*	if(ErrorCode == 0)
	{
		VertexContext05.pTextureSurfaceDesc	= &TextureDesc[1];
		kmProcessVertexRenderState(&VertexContext05);
	}
*/
	TextureReadBuffer = (unsigned char *)syMalloc(TEXTUREBUFFSIZE); /* Alloc Texture Load Buffer */
	ErrorCode = LoadTexture("a007.pvr", NULL, &TextureDesc[2]);
/*	if(ErrorCode == 0)
	{
		VertexContext05.pTextureSurfaceDesc	= &TextureDesc[2];
		kmProcessVertexRenderState(&VertexContext05);
	}
*/
	TextureReadBuffer = (unsigned char *)syMalloc(TEXTUREBUFFSIZE); /* Alloc Texture Load Buffer */
	ErrorCode = LoadTexture("cggirls.pvr", NULL, &TextureDesc[3]);
/*	if(ErrorCode == 0)
	{
		VertexContext05.pTextureSurfaceDesc	= &TextureDesc[3];
		kmProcessVertexRenderState(&VertexContext05);
	}
*/
	syFree( &TextureReadBuffer );

	/* Set Screen */

	kmgSetScreen(320.0f, 240.0f, 0.6f, -0.6f, 1600.0f);

	nFace = LoadCube();

	fSize = 0.1f;
	scale_vec[0] = fSize;
	scale_vec[1] = fSize;
	scale_vec[2] = fSize;

	/* Set Light */

	LightMat.Mode = KMG_LIGHT_PARALLEL;
	LightMat.AmbientColor[KMG_COLOR_R]			= 0.3;
	LightMat.AmbientColor[KMG_COLOR_G]			= 0.3;
	LightMat.AmbientColor[KMG_COLOR_B]			= 0.3;

	LightMat.ParallelLightDir[KMG_X]			= 0.577f;
	LightMat.ParallelLightDir[KMG_Y]			= 0.577f;
	LightMat.ParallelLightDir[KMG_Z]			= -0.577f;

	LightMat.ParallelLightColor[KMG_COLOR_R]	= 1.0f;
	LightMat.ParallelLightColor[KMG_COLOR_G]	= 1.0f;
	LightMat.ParallelLightColor[KMG_COLOR_B]	= 1.0f;
	LightMat.ParallelLightColor[KMG_COLOR_A]	= 0.0f;	/* Fog Vertex Intensity */
	LightMat.ParallelLightIntensity				= 1.0f;

	LightMat.Mode = KMG_LIGHT_POINT;

	LightMat.PointLightPosition[KMG_X]		= 0.0f;
	LightMat.PointLightPosition[KMG_Y]		= 0.0f;
	LightMat.PointLightPosition[KMG_Z]		= 0.95f;

	LightMat.PointLightColor[KMG_COLOR_R]	= 0.8f;
	LightMat.PointLightColor[KMG_COLOR_G]	= 0.8f;
	LightMat.PointLightColor[KMG_COLOR_B]	= 0.9f;
	LightMat.PointLightIntensity			= 0.1f;

	nBox = 1;

	LightMat.Mode = KMG_LIGHT_PARALLEL;

	fAngleSpeed1 = 0.8f;
	fAngleSpeed2 = 1.2f;

	/* Render roop */
	while(1)
	{
		per = (NJS_PERIPHERAL *) njGetPeripheral(NJD_PORT_A0);
		if( per->on & NJD_DGT_KL)
		{ tran_vec[0] = tran_vec[0] - tran_x;
		}
		if( per->on & NJD_DGT_KR)
		{ tran_vec[0] = tran_vec[0] + tran_x;
		}
		if( per->on & NJD_DGT_KD)
		{ tran_vec[1] = tran_vec[1] - tran_y;
		}
		if( per->on & NJD_DGT_KU)
		{ tran_vec[1] = tran_vec[1] + tran_y;
		}
		if( per->on & NJD_DGT_TX)
		{ tran_vec[2] = tran_vec[2] - tran_z;
		}
		if( per->on & NJD_DGT_TY)
		{ tran_vec[2] = tran_vec[2] + tran_z;
		}
		if( per->press & NJD_DGT_TA)
		{ light_num++;
			if( light_num >= light_num_max)
			{ light_num = 0;
			}
			switch(light_num){
			default:
			case 0:
				LightMat.Mode = KMG_LIGHT_PARALLEL;
				break;
			case 1:
				LightMat.Mode = KMG_LIGHT_POINT;
				break;
			case 2:
				LightMat.Mode = KMG_LIGHT_CONE;
				break;
			case 3:
				LightMat.Mode = KMG_LIGHT_LINEAR;
				break;
			}
		}
		if( per->press & NJD_DGT_TB)
		{ tex_num++;
			if( tex_num >= tex_num_max)
			{ tex_num = 0;
			}
		  VertexContext05.pTextureSurfaceDesc = &TextureDesc[tex_num];
		  kmProcessVertexRenderState(&VertexContext05);
		}
		
		kmSetVertexRenderState(&VertexContext05);
		kmgSetIdentity();
		kmgScale(scale_vec);

		kmgRotate((float)Frame*fAngleSpeed1, Y_AXIS);
		kmgRotate((float)Frame*fAngleSpeed2, X_AXIS);
		kmgTranslate(tran_vec);
		kmgDraw(&LightMat,1,&VertexBufferDesc, kmVertex, nFace);
		txt_SetCursor( 2, 1 );
		PRINTOUT(("FRAME: %d", Frame));
		txt_SetCursor( 2, 2 );
		PRINTOUT(("ErrorCode: %d", ErrorCode));
		txt_SetCursor( 2, 3 );
		PRINTOUT(("x_pos: %f", tran_vec[0]));
		PRINTOUT(("  y_pos: %f", tran_vec[1]));
		PRINTOUT(("  z_pos: %f", tran_vec[2]));
		txt_SetCursor( 2, 4 );
		PRINTOUT(("Light Mode: %d", LightMat.Mode));
		txt_DispScreen(VertexBufferDesc);

		kmRender();
		kmFlipFrameBuffer();
		pdExecPeripheralServer();
		txt_ClearScreen();
		Frame++;
	}

}
