/**********************************************************************
*
*       GDV.CPP
*
*
*       Summary:	Play a GDV file
*
*       Author:   Kevin Dudley / Tony Crowther / Graeme Ing
*
*       Project:  Normality Inc   PC
*
*       Dated:    1527995 Wednesday 27-9-1995 15:59.
*
**********************************************************************/

#include <iostream.h>
#include <stdlib.h>
#include <stdio.h>
#include <graph.h>
#include <i86.h>
#include <dos.h>
#include <conio.h>
#include <float.h>
#include <time.h>
#include <math.h>
#include <string.h>


#include "defines.h"
#include "data.equ"
#include "3deng.h"
#include "menudisp.h"
#include "menu.h"
#include "video.h"
#include "vesa.h"
#include "unmangle.h"
#include "actua.h"
#include "memory.h"
#include "gamedata.h"
#include "menudata.h"

#include "config.h"
#include "sos.h"
#include "timer.h"
#include "digi.h"
#include "midi.h"

#include "playdam.h"							// Structure Definitions for Digital Video
#include "playcall.h"						// Call Defininitions for Digital Video
#include "animlink.h"
#include "calldef.h"
#include "memstruc.h"
#include "rothlink.h"
#include "mallocx.h"

#include "euro.equ"
#include "euro_def.h"
#include "euro_var.h"
#include "euro_grf.h"
#include "euro_dsk.h"
#include "euro_fix.h"
#include "euro_sel.h"
#include "euro_inf.h"
#include "euro_cnt.h"
#include "euro_usr.h"
#include "euro_net.h"

#define	GDV_MEM	512*1024
#define GDV_ABORT				0x01
#define GDV_LOOP				0x08
#define DEFAULT_FADEIN		0
#define DEFAULT_FADEOUT		0
#define DEFAULT_DELAYEXIT	25

extern	"C"	volatile int count;
extern	int	testVESA;
extern	int 	VESAmode(int *);
extern	int	gdv_gran;
extern 	"C" 	volatile char keys[256];
extern	 	char	return_doskey;
extern	BYTE 		palette_buffer[];
extern	BYTE 		work_buffer[768];

extern	ModeInfoBlock *vmode_inf;
char	out;



BYTE	presents[]={
  	0x3F,0x33,0x00,0x3F,0x33,0x0C,0x3F,0x33,0x19,0x3F,0x3F,0x26,
			};

//---------------------------------------------------
long int GDVCallbackRoutine(long int mode,void *header,void *data,short int frame)
//---------------------------------------------------
//
// Callback generated by GDV player.
// Test for abort GDV.
//---------------------------------------------------
{
	out	=	NULL;

	if (mode == CBM_LookForAbort)
	{
		ReadMouseData(0);

			for (int i=1; i<255; i++)
			{
		 		if (keys[i])
					out	=	1;
			}
		if (MouseBUTTONS & 3)
			out	=	1;

		if (out!=NULL)
			return(CBX_Abort);
	}
	return(CBX_Normal);
}


//---------------------------------------------------
void PlayGDV()
//---------------------------------------------------
//
// Play a GDV using an Anim structure
//---------------------------------------------------
{
	char	file[128]; 
	unsigned char *mem;
	unsigned long int Error;
	_PlayAnimBlock PlayBlock = { 0 };

	mem=(unsigned char *)mallocx(GDV_MEM);		// allocate mem for player


	if (mem == 0)
 		return;
	memset( mem, 0, GDV_MEM );

	strcpy	(file, EuroGDVfile);

	PlayBlock.FileName 	= 	&file[0];
	PlayBlock.Flags    	= 	NULL;
	PlayBlock.Screen	= 	0x110;
	PlayBlock.ScreenXSize	= 	640;
	PlayBlock.ScreenYSize	= 	480;
      	PlayBlock.ScreenGran	=	0;   

      	if (SoundCard==0)
      		PlayBlock.Flags|=	PAF_NoAudio;

        PlayBlock.CallBack = &GDVCallbackRoutine;
      	PlayBlock.DrvPath="DIGI\\";
	PlayBlock.MemBlock=mem;
	PlayBlock.MemBlockSize=GDV_MEM;
	
	if (SoundCard==0)
		PlayBlock.Flags|= 	PAF_NoAudio;
	else
		PlayBlock.DIGIHandle_SOS=DIGIDriverHandle;

	PlayBlock.DriveCap_SOS=&DIGICapabilities;
	PlayBlock.SNDID=SoundCard;
	PlayBlock.SNDPort=SoundPort;
	PlayBlock.SNDIRQ=SoundIRQ;
	PlayBlock.SNDDMA=SoundDMA;
	PlayBlock.SNDPara=0;


	if(!(Error=InitAnim(&PlayBlock)))
	{
		Error=StartAnim(&PlayBlock);
		CloseAnim(&PlayBlock);
	}

	freex(mem);
}


//------------------------------------------------------
// PlaySample routines to link with Tony's ROTH sample stuff!
//------------------------------------------------------

extern WORD PlaySample (_SOS_START_SAMPLE *mysample, void (far cdecl*callback)(WORD,WORD,WORD))
{
	mysample->lpCallback=(void cdecl (far*)(WORD,WORD,WORD))callback;
   return (sosDIGIStartSample( DIGIDriverHandle, mysample));
} /* PlaySample */


extern WORD StopPlaySample (WORD handle)
{
   return (sosDIGIStopSample( DIGIDriverHandle, handle));
}

extern WORD ChangeSampleVol (WORD handle,int vol)
{
   return (sosDIGISetSampleVolume( DIGIDriverHandle, handle,vol));
}

extern WORD ChangeSamplePan (WORD handle,int pan)
{
   return (sosDIGISetPanLocation( DIGIDriverHandle, handle,pan));
}
