/*
	Ninja Library
	
	COPYRIGHT (C) SEGA ENTERPRISES,LTD.

*/
#ifndef _NU_TEXTURE_H_
#define	_NU_TEXTURE_H_

#ifdef __cplusplus
extern "C" {
#endif 

/* Pvm Define */
#define NUD_PVM_PVMH_TAG	'HMVP'
#define NUD_PVM_MDLN_TAG	'NLDM'
#define NUD_PVM_CONV_TAG	'VNOC'
#define NUD_PVM_PVMI_TAG	'IMVP'
#define NUD_PVM_IMGC_TAG	'CGMI'
#define NUD_PVM_PVRT_TAG	'TRVP'
#define NUD_PVM_COMM_TAG	'MMOC'
#define NUD_PVM_PVPL_TAG	'LPVP'

#define NUD_PVMH_PS_PVRNAME			BIT_0
#define NUD_PVMH_PS_CATEGORYCODE	BIT_1
#define NUD_PVMH_PS_ENTRYINFO		BIT_2
#define NUD_PVMH_PS_GLOBALINDEX		BIT_3
#define NUD_PVMH_PS_CHUNK_MDLN		BIT_4
#define NUD_PVMH_PS_CHUNK_CONV		BIT_5
#define NUD_PVMH_PS_CHUNK_PVMI		BIT_6
#define NUD_PVMH_PS_CHUNK_IMGC		BIT_7
#define NUD_PVMH_PS_CHUNK_PVRT		BIT_8
#define NUD_PVMH_PS_CHUNK_COMM		BIT_9
#define NUD_PVMH_PS_BANKID			BIT_10
#define NUD_PVMH_PS_CHUNK_PVPL		BIT_11

#define NUD_TEX_MODE_OPEN 			(0)
#define NUD_TEX_MODE_START			(1)
#define NUD_TEX_MODE_FILEOPEN		(2)
#define NUD_TEX_MODE_FILEREAD		(3)
#define NUD_TEX_MODE_FILEREADWAIT	(4)
#define NUD_TEX_MODE_FILEHEADER		(5)
#define NUD_TEX_MODE_MEMORYHEADER	(6)
#define NUD_TEX_MODE_GETSURFACE		(7)
#define NUD_TEX_MODE_LOAD			(8)
#define NUD_TEX_MODE_LOADWAITDMA	(9)

#define NUD_TEX_STAT_READ			(0)
#define NUD_TEX_STAT_END			(1)
#define NUD_TEX_STAT_ERR			(-1)

#define NUM_FREAD_ERR(gdfs,errcode)	{\
									_nj_texerr_.gdstat = gdFsGetStat((gdfs));\
									_nj_texerr_.gderr = gdFsGetErrStat((gdfs));\
									_nj_texerr_.texerr = (errcode);\
									}\

typedef struct {			/* 12bytes					*/
	Sint32 nextptr;			/* nextpointer				*/
	Uint16 mode;			/* color mode				*/
	Sint16 bank;			/* bank						*/
	Sint16 entryoffset;		/* 0 - 1023					*/
	Sint16 entrycount;		/* 1 - 1024					*/
}NUS_PALETTE_HEADR;			

typedef struct {			/* 12 bytes 				*/
	Sint32 chunk;			/* PVMH						*/
	Sint32 nextptr;			/* nextpointer				*/
	Uint16 pvmstatus;		/* pvm texture status		*/
	Sint16 entrycount;		/* entry count				*/
}NUS_PVM_PVMH_HEAD;

typedef struct {			/* 16 bytes 				*/
	Sint32 chunk;			/* PVRT						*/
	Sint32 nextptr;			/* nextpointer				*/
	NJS_PVRHEADERDATA data;	/* DATA						*/
}NUS_PVR_PVRT_HEAD;

/* Texture Buffer (nuInitTextureBuffer.c)*/
void nuInitTextureBuffer(Sint8 *buf,Int size);
void nuGetTextureBuffer(Sint8 **buf,Int *size);

/* Pvr Load (nuLoadTexture.c)*/
Sint32 nuLoadTexture(NJS_TEXLIST *texlist);
Sint32 nuLoadTextureNum(Uint32 n);

/* Pvm Load (nuLoadTexPvmXXX.c)*/
Sint32 nuLoadTexturePvmFile(const char *filename,NJS_TEXLIST *texlist);
Sint32 nuLoadTexturePvmMemory(Sint8 *pTexture,NJS_TEXLIST *texlist);

/* Pvm Texlist (nuSetPvmTextureList.c)*/
void nuSetPvmTextureList(NJS_TEXLIST *texlist,NJS_TEXNAME *texname,char* filename,Sint32 size);

/* Pvr Load Req (nuLoadTextureReq.c)*/
Sint32 nuLoadTextureReq(NJS_TEXLIST *texlist);
Sint32 nuLoadTextureReqStop(void);
Sint32 nuGetLoadTextureReqMode(void);

/* Load setting globalIndex (nuLoadTextureSetG.c) */
Sint32 nuLoadTextureSetG(NJS_TEXLIST *texlist);

/* ReloadTexture (nuReLoadTexture.c) */
Sint32 nuReLoadTextureNum(Uint32 n,void *texaddr,Uint32 attr,Uint32 lod);
Sint32 nuReLoadTextureNumG(Uint32 globalIndex,void *texaddr,Uint32 attr,Uint32 lod);

/* ReloadRectangle (nuReLoadRectangleTexturePart.c) */
Sint32 nuReLoadRectangleTexturePartNum(Uint32 n,void *texaddr,Uint32 attr,Uint32 *p);
Sint32 nuReLoadRectangleTexturePartNumG(Uint32 globalIndex,void *texaddr,Uint32 attr,Uint32 *p);

/* Reload Vq Codebook (nuReLoadVQCodebook.c) */
Sint32 nuReLoadVQCodebookNum(Uint32 n,void *texaddr,Uint32 attr);
Sint32 nuReLoadVQCodebookNumG(Uint32 globalIndex,void *texaddr,Uint32 attr);

/* Load palette (nuLoadPaletteFile.c) */
Sint32 nuLoadPaletteFile(const char *filename,NJS_TEXPALETTE *pl);

/* Basic File Load (nuTexFile.c)*/
Sint32 nuTexFopen(const char* filename);
void nuTexFclose(void);
void nuTexFseek(Sint32 size,Int type);
Sint32 nuTexFread(void* buf,Sint32 size);
Sint32 nuTexFreadReq(void* buf,Sint32 size);
Sint32 nuTexFreadAll(const char *filename,void *buf,Int size);

#ifdef __cplusplus
}
#endif

#endif	/*_NU_TEXTURE_H_*/
