/*----------------------------------------------------------------------------
	SoH DirectX Layer
----------------------------------------------------------------------------*/

#include "soh.h"
#include "trace.h"
#include <sg_sycbl.h>

extern int kmSetAutoSortMode(int fEnable);

NJS_MATRIX		*mbuf;
NJS_VERTEX_BUF	*vbuf;
NJS_TEXMEMLIST	*texm;
Uint8 *tbuf;
extern ULONG gkmCopyTransToPunchthrough;

NJS_VIEW view;

SX_NINJAX *SDX;
SX_NINJAX wSDX;									/* ライブラリ用ワーク		*/
/*--------------------------------------------------------------------------*/
/* ライブラリの初期化														*/
SXERR sxInit(void)
{
	Sint32 mode;

	SDX=&wSDX;
	sxMemSetB(SDX, 0, sizeof(SX_NINJAX));		/* 必ず初期化すること		*/

	njSetBorderColor(0);

	mode = (syCblCheckCable() == SYE_CBL_CABLE_VGA) ?
				NJD_RESOLUTION_VGA : NJD_RESOLUTION_640x480_NTSCNI;
	sbInitSystem(mode, NJD_FRAMEBUFFER_MODE_RGB565, 1 );
	
	gkmCopyTransToPunchthrough = 0;
	kmSetAutoSortMode(1);

	vbuf=syMalloc( 1000*sizeof(NJS_VERTEX_BUF) );
	mbuf=syMalloc(  64*sizeof(NJS_MATRIX) );
	texm=syMalloc( 200*sizeof(NJS_TEXMEMLIST) );
	tbuf=syMalloc( 512*512*2 );

	njInitVertexBuffer( 50000, 0, -200000, 0,0 );
	njInitPrint(NULL, 0, 0);
	njInitMatrix( mbuf, 64,1 );
	njInit3D( vbuf, 1000);
	njInitTextureBuffer( (Sint8 *)tbuf, 512*512*2);

	SDX->texcache = syMalloc( 4096*1024 );
	njInitCacheTextureBuffer(SDX->texcache, 4096*1024 );

	njInitView(&view);
	njSetView(&view);
	
	sxInitPeripheral();
	ixInitTrace();
	
	njInitTexture(texm,200);
	nwInitSystem(200,NJD_PORT_D0);
	return SX_OK;
}
/*--------------------------------------------------------------------------*/
SXERR sxExit(void)
{
	ixExitTrace();
	sbExitSystem();
	return SX_OK;
}
/*--------------------------------------------------------------------------*/
