#include "tpApi.H"
#include <Nindows.h>

#include "sndutls.h"

NJS_TEXMEMLIST	tex[100];

#define NUM 2

NJS_TEXINFO	info[NUM];
NJS_TEXNAME texname[NUM];
NJS_TEXLIST texlist = {texname,NUM};

MovieStruct movie1;

void Counter(void)
{
	sdSysServer();

	tpVSyncHandler(&movie1);
}

void njUserInit(void)
{
	sbInitSystem( NJD_RESOLUTION_640x480_NTSCNI, NJD_FRAMEBUFFER_MODE_RGB555, 2 );
	/*sbInitSystem( NJD_RESOLUTION_VGA, NJD_FRAMEBUFFER_MODE_RGB555, 1 );*/

	if (!getMovieList(".")) /* try current directory */
		getMovieList("MOVIE"); /* try directory named "MOVIE" */
	
	njInitVertexBuffer( 100000, 0, 100000, 0, 100000); /* r5 */
	njInitTexture( tex,100);

	SoundInitialize( "MANATEE.DRV", "STREAM.MLT" ); /* located in sbinit.c */

	njSetBackColor(0x000000FF,0x000000FF,0x00000000);
	njSetVSyncFunction(Counter);

	/* setting memory textures */
	njSetTextureInfo(&info[0],(void *)NULL,NJD_TEXFMT_YUV_422|NJD_TEXFMT_STRIDE,1024,512);	
	njSetTextureName(&texname[0],&info[0],0,NJD_TEXATTR_TYPE_MEMORY|NJD_TEXATTR_GLOBALINDEX);

	njLoadTexture( &texlist );
	njSetTexture( &texlist );

}


int movieCount=0;

Sint32 njUserMain(void)
{
	extern PLAYER_STATUS_CODE tp_setupDisplay(MovieHandle movie);
	extern PLAYER_STATUS_CODE tp_setupAudioDriver(MovieHandle movie);
	char *nextMovie(void);

	pdExecPeripheralServer();

	tp_MovieStructInit(&movie1, tp_setupDisplay,tp_setupAudioDriver);

	strcpy(movie1.fileName,nextMovie());
	movie1.HFB_bufferSize = 512*1024;
	/*
	movie1.noAudio = 1;
	movie1.speedTest = 1;
	*/

	tp_MovieInitAndPlay(&movie1);

	return NJD_USER_CONTINUE;

}

void njUserExit(void)
{
	sbExitSystem();
}

