/*
	Gdfs Sample
	
	COPYRIGHT (C) SEGA ENTERSRISES,LTD.
	
	open test
	
	1998.9.29
*/

#include <shinobi.h>
#include <sg_sybt.h>


/*** main routine ***/


void njUserInit(void)
{
	njSetBorderColor( 0 ) ;
	sbInitSystem( NJD_RESOLUTION_320x240_NTSCNI, NJD_FRAMEBUFFER_MODE_RGB565, 1 );
	njInitVertexBuffer( 100000, 0, 100000, 0, 0 );
	njInitPrint(NULL, 0, 0);
	
	njSetBackColor(0x00000000,0x00000000,0x000000FF);
}



Sint32 njUserMain(void)
{
	static Sint32 reqdstat = 0;
	Sint32 dstat;
	
	njPrintC(NJM_LOCATION(2,2), "GDFS OPEN TEST");
	
	if (reqdstat) {
		/* wait until complete of updating the drive status */
		Sint32 stat;
		GDFS sys;
		
		sys = gdFsGetSysHn();
		stat = gdFsGetStat(sys);
		if (stat == GDD_STAT_COMPLETE) {
			/* complete */
			reqdstat = 0;
			
		} else if (stat == GDD_STAT_ERR) {
			/* error */
			Sint32 err;
			err = gdFsGetErrStat(sys);
			reqdstat = 0;
			
			if (err == GDD_ERR_TRAYOPEND) {
				njPrintC(NJM_LOCATION(2,10), "=== TRAYOPEND ===");
#if 0
				return NJD_USER_EXIT;
#endif
				
			} else if (err == GDD_ERR_CHECKBUSY) {
				njPrintC(NJM_LOCATION(2,11), "=== CHECKBUSY ===");
				
			} else if (err == GDD_ERR_UNITATTENT) {
				njPrintC(NJM_LOCATION(2,12), "=== UNITATTENT ===");
				return NJD_USER_EXIT;
			}
		}
	}
	
	
	/* check the drive status */
	dstat = gdFsGetDrvStat();
	if (dstat == GDD_DRVSTAT_OPEN) {
		njPrintC(NJM_LOCATION(8,8), "-- OPEN --");
#if 0
		return NJD_USER_EXIT;
#endif
	}
	
	
	/* update the drive status */
	if (! reqdstat) {
		if (gdFsReqDrvStat() == GDD_ERR_OK) reqdstat = 1;
	}
	
	return NJD_USER_CONTINUE;
}



void njUserExit(void)
{
	njExitPrint();
	sbExitSystem();
	syBtExit();
}

/* eof */
