/*
 *  Middleware Library
 *  Copyright (c) 1998 SEGA
 *  
 *		Middleware Play
 *
 *  Module  : Library Header File
 *  File    : sg_mwply.h
 *  Create  : 1998-07-25
 *  Modify  : 1998-08-28
 *  Version : 0.57
 *  Note    :
 */

#ifndef _SG_MWPLY_H_
#define _SG_MWPLY_H_

/***********************************************************************
 *      Include Files
 ***********************************************************************/

#include <sg_xpt.h>

/***********************************************************************
 *      Constant Macro
 ***********************************************************************/

/* Copyright */
                    /*             1         2         3         4 */
                    /*    1234567890123456789012345678901234567890 */
                    /*    +++++++++++++++++++++++++++++++++        */
#define MWD_PLY_CPY_STR ("Copyright (c) 1998 SEGA")
#define MWD_PLY_CPY_SIZ	(32) 

/* Version */
                    /*             1         2         3         4 */
                    /*    1234567890123456789012345678901234567890 */
                    /*    +++++++++++++++++++++++++++++++++        */
#define MWD_PLY_VER_STR ("MWPLY Version 0.57 1998-08-28")
#define MWD_PLY_VER_SIZ     (32)

/* Library Version */
#define	MWD_PLY_VERSION_NO	(0x00)	/* Version No. */
#define	MWD_PLY_REVISION_NO	(0x57)	/* Reision No. */

/* Library ID */
#define	MWD_PLY_LID	{ \
	0xa99e5b80, 0x09f9, 0x11d2, \
	0xa5, 0xa0, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00 \
}

/* VBLANK割り込みによる呼び出し関数のプライオリティ */
/* 注意：ミドルウェアライブラリは以下の値に統一する */
#define	MWD_PLY_PRI_VBLNK		(0x70)

/* Max Number of MWPLY Handle */
#define	MWD_PLY_MAX_OBJ		(32)

/* Error Code */
#define	MWD_PLY_ERR_OK			(0)
#define	MWD_PLY_ERR_NG			(-1)
#define	MWD_PLY_ERR_FATAL		(-2)
#define	MWD_PLY_ERR_INTERNAL	(-3)
#define	MWD_PLY_ERR_PRM			(-4)

#define	MWD_PLY_ERR_NOHN		(-11)
#define	MWD_PLY_ERR_NULHN		(-12)

/* GSC Error  */
#define	MWD_PLY_ERR_GSC_INIT	(-101)
#define	MWD_PLY_ERR_GSC_OPFN	(-102)
#define	MWD_PLY_ERR_GSC_START	(-103)
#define	MWD_PLY_ERR_GSC_OPENAGAIN	(-104)

/* SJ Error */
#define	MWD_PLY_ERR_SJ_FATAL	(-201)

/***********************************************************************
 *      enumulater
 ***********************************************************************/

/* Status of MWPLY handles	*/
typedef	enum _mwe_ply_stat {
	MWE_PLY_STAT_STOP		= (0),		/*	stoped						*/
	MWE_PLY_STAT_PREP		= (1),		/*	preparing					*/
	MWE_PLY_STAT_PLAYING	= (2),		/*	playing						*/
	MWE_PLY_STAT_PLAYEND	= (3),		/*	end of playing				*/
	MWE_PLY_STAT_ERROR		= (4)		/*	error was occured			*/
} MWE_PLY_STAT;

/***********************************************************************
 *      Macro
 ***********************************************************************/

/* convert mwGetTime()'s return-value to second */
#define	MWD_PLY_TIME2SEC(ncount, tscale)	((ncount) / (tscale))

/* convert mwGetTime()'s return-value to milli-second */
#define	MWD_PLY_TIME2MSEC(ncount, tscale)	((1000 * (ncount)) / (tscale))

/***********************************************************************
 *      MWPLY Handle
 ***********************************************************************/

/* MWPLY Handle */
#ifndef MWPLY_DEFINED
#define MWPLY_DEFINED
/* Virtual Function Table */
typedef struct {
	struct _mwply_if *vtbl;
} MW_PLY_OBJ;
typedef MW_PLY_OBJ *MWPLY;
#endif

/* Callback function of error */
typedef void (*MW_PLY_ERRFN)(void *obj, Sint32 ecode);

/*	MWPLY Interface function  */
typedef struct _mwply_if {
	void (*QueryInterface)();		/*	for COM compatibility	*/
	void (*AddRef)();				/*	for COM compatibility	*/
	void (*Release)();				/*	for COM compatibility	*/
	/*== Functions of MWPLY	====================================*/ 
	/*	V-sync function 										*/
	/*	This function is called by user while v-sync interrupt.	*/
	void (*VsyncHndl)(MWPLY ply);
	/*	execute decoding one frame								*/
	/*	This function is called by user from main-loop.			*/ 
	void (*ExecSvrHndl)(MWPLY ply);
	/*	destroy MWPLY handle									*/
	void (*Destroy)(MWPLY ply);
	/*	start playing by file name 								*/
	void (*StartFname)(MWPLY ply, Sint8 *fname);
	/*	stop playing  											*/
	void (*Stop)(MWPLY ply);
	/*	get status of MWPLY handle								*/
	MWE_PLY_STAT (*GetStat)(MWPLY ply);
	/*	get playing time										*/
	/*	if playing movie is 30 fps, *tscale is 30 and 			*/
	/*		*ncount is total number of displayed frames			*/ 
	void (*GetTime)(MWPLY ply, Sint32 *ncount, Sint32 *tscale);
} MWD_IF;

/***********************************************************************
 *      Functions
 ***********************************************************************/

/*	declaration for Sofdec									*/
#include	"SFD_MW.H"

/*	declaration for Wave									*/
#include	"WAV_MW.H"

#if	0
/*	declaration for TORQ									*/
#include	"TM_MW.H"
#endif

/*	V-sync function 										*/
/*	This function is called by user while v-sync interrupt.	*/
#define mwPlyVsyncHndl(ply)			(*(ply)->vtbl->VsyncHndl)((ply))

/*	execute decoding one frame								*/
/*	This function is called by user from main-loop.			*/ 
#define mwPlyExecSvrHndl(ply)		(*(ply)->vtbl->ExecSvrHndl)((ply))

/*	destroy MWPLY handle									*/
#define mwPlyDestroy(ply)			(*(ply)->vtbl->Destroy)((ply))

/*	start playing by file name 								*/
#define mwPlyStartFname(ply, fname)	(*(ply)->vtbl->StartFname)((ply), (fname))

/*	stop playing  											*/
#define mwPlyStop(ply)				(*(ply)->vtbl->Stop)((ply))

/*	get status of MWPLY handle								*/
#define mwPlyGetStat(ply)			(*(ply)->vtbl->GetStat)((ply))

/*	get playing time										*/
/*	if playing movie is 30 fps, *tscale is 30 and 			*/
/*		*ncount is total number of displayed frames			*/ 
#define mwPlyGetTime(ply, ncount, tscale)	\
							(*(ply)->vtbl->GetTime)((ply), (ncount), (tscale))

void mwPlyVsync(void);
void mwPlyExecServer(void);
void mwPlyEntryErrFn(MW_PLY_ERRFN errfn, void *obj);

#endif	/* _SG_MWPLY_H_ */

/* end of file */
