/*
**	Command & Conquer Red Alert(tm)
**	Copyright 2025 Electronic Arts Inc.
**
**	This program is free software: you can redistribute it and/or modify
**	it under the terms of the GNU General Public License as published by
**	the Free Software Foundation, either version 3 of the License, or
**	(at your option) any later version.
**
**	This program is distributed in the hope that it will be useful,
**	but WITHOUT ANY WARRANTY; without even the implied warranty of
**	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
**	GNU General Public License for more details.
**
**	You should have received a copy of the GNU General Public License
**	along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef VQAPLAY_H
#define VQAPLAY_H
/****************************************************************************
*
*         C O N F I D E N T I A L -- W E S T W O O D  S T U D I O S
*
*---------------------------------------------------------------------------
*
* PROJECT
*     VQA player library. (32-Bit protected mode)
*
* FILE
*     vqaplay.h
*
* DESCRIPTION
*      VQAPlay library definitions.
*
* PROGRAMMER
*     Bill Randolph
*     Denzil E. Long, Jr.
*
* DATE
*     February 23, 1995
*
****************************************************************************/

/*---------------------------------------------------------------------------
 * CONDITIONAL COMPILATION FLAGS
 *-------------------------------------------------------------------------*/

#ifdef __WATCOMC__
#define VQAVOC_ON    0  /* Enable VOC file override */
#define	VQAMONO_ON   1  /* Mono display output enable/disable */
#define VQAAUDIO_ON  1  /* Audio playback enable/disable */
#define VQAVIDEO_ON  0  /* Video manager enable/disable */
#define VQAMCGA_ON   1  /* MCGA enable/disable */
#define VQAXMODE_ON  0  /* Xmode enable/disable */
#define VQAVESA_ON   0  /* VESA enable/disable */
#define	VQABLOCK_2X2 1  /* 2x2 block decode enable/disable */
#define	VQABLOCK_2X3 1  /* 2x2 block decode enable/disable */
#define	VQABLOCK_4X2 1  /* 4x2 block decode enable/disable */
#define	VQABLOCK_4X4 1  /* 4x4 block decode enable/disable */
#else
#define VQAVOC_ON    1  /* Enable VOC file override */
#define	VQAMONO_ON   1  /* Mono display output enable/disable */
#define VQAAUDIO_ON  0  /* Audio playback enable/disable */
#define VQAVIDEO_ON  0  /* Video manager enable/disable */
#define VQAMCGA_ON   1  /* MCGA enable/disable */
#define VQAXMODE_ON  0  /* Xmode enable/disable */
#define VQAVESA_ON   0  /* VESA enable/disable */
#define	VQABLOCK_2X2 1  /* 2x2 block decode enable/disable */
#define	VQABLOCK_2X3 1  /* 2x2 block decode enable/disable */
#define	VQABLOCK_4X2 1  /* 4x2 block decode enable/disable */
#define	VQABLOCK_4X4 1  /* 4x4 block decode enable/disable */
#endif

/*---------------------------------------------------------------------------
 * GENERAL CONSTANT DEFINITIONS
 *-------------------------------------------------------------------------*/

/* Playback modes. */
#define VQAMODE_RUN  0 /* Run the movie through the end. */
#define VQAMODE_WALK 1 /* Draw the next frame then return. */
#define VQAMODE_STOP 2 /* Stop the movie. */

/* Playback timer methods */
#define VQA_TMETHOD_DEFAULT -1 /* Use default timer method. */
#define	VQA_TMETHOD_DOS      1 /* DOS timer method */
#define	VQA_TMETHOD_INT      2 /* Interrupt timer method */
#define	VQA_TMETHOD_AUDIO    3 /* Audio timer method */

/* Error/condition values */
#define	VQAERR_EOF      -1  /* Valid end of file */
#define VQAERR_OPEN     -2  /* Unable to open */
#define	VQAERR_READ     -3  /* Read error */
#define VQAERR_WRITE    -4  /* Write error */
#define VQAERR_SEEK     -5  /* Seek error */
#define VQAERR_NOTVQA   -6  /* Not a valid VQA file. */
#define VQAERR_NOMEM    -7  /* Unable to allocate memory */
#define	VQAERR_NOBUFFER -8  /* No buffer avail for load/draw */
#define	VQAERR_NOT_TIME -9  /* Not time for frame yet */
#define	VQAERR_SLEEPING -10 /* Function is in a sleep state */
#define VQAERR_VIDEO    -11 /* Video related error. */
#define VQAERR_AUDIO    -12 /* Audio related error. */

/* Memory limits */
#define	VQA_NUM_MAXRATES 5  /* Number of max rates in the Config struct */
#define	VQA_TIMETICKS    60 /* Clock ticks per second */

/*---------------------------------------------------------------------------
 * STRUCTURES AND RELATED DEFINITIONS
 *-------------------------------------------------------------------------*/

/* VQAConfig: Player configuration structure
 *
 * DrawerCallback - User routine for Drawer to call each frame (NULL = none)
 * Vmode          - Requested Video mode (May be promoted).
 * VBIBit         - Vertical blank bit polarity.
 * ImageBuf       - Pointer to caller's buffer for the Drawer to use as its
 *                  ImageBuf; NULL = player will allocate its own, if
 *                  VQACFGF_BUFFER is set in DrawFlags.
 * ImageWidth     - Width of Image buffer.
 * ImageHeight    - Height of Image buffer.
 * X1             - Draw window X coordinate (-1 = Center).
 * Y1             - Draw window Y coordinate (-1 = Center).
 * FrameRate      - Desired frames per second (-1 = use VQA header's value).
 * DrawRate       - Desired drawing frame rate; allows the Drawer to draw at
 *                  a separate rate from the Loader.
 * TimerMethod    - Timer method to use during playback.
 * DrawFlags      - Bits control various special drawing options. (See below)
 * OptionFlags    - Bits control various special misc options. (See below)
 * NumFrameBufs   - Desired number of frame buffers. (Default = 6)
 * NumCBBufs      - Desired number of codebook buffers. (Default = 3)
 * VocFile        - Name of VOC file to play instead of VQA audio track.
 * AudioBuf       - Pointer to audio buffer.
 * AudioBufSize   - Size of audio buffer. (Default = 32768)
 * AudioRate      - Audio data playback rate (-1 = use 22050 scaled to the
 *                  frame rate)
 * Volume         - Audio playback volume. (0x7FFF = max)
 * HMIBufSize     - Desired HMI buffer size. (Default = 2000)
 * DigiHandle     - Handle to an initialized sound driver. (-1 = none)
 * DigiCard       - HMI ID of card to use. (0 = none, -1 = auto-detect)
 * DigiPort       - Audio port address. (-1 = auto-detect)
 * DigiIRQ        - Audio IRQ. (-1 = auto-detect)
 * DigiDMA        - Audio DMA channel. (-1 = auto-detect)
 * MaxRate        - Fixed rate playback table.
 */
typedef struct _VQAConfig {
	void (*DrawerCallback)(unsigned char *screen, long framenum);
	long          Vmode;
	long          VBIBit;
	unsigned char *ImageBuf;
	long          ImageWidth;
	long          ImageHeight;
	long          X1,Y1;
	long          FrameRate;
	long          DrawRate;
	long          TimerMethod;
	long          DrawFlags;
	long          OptionFlags;
	long          NumFrameBufs;
	long          NumCBBufs;
	char          *VocFile;
	unsigned char *AudioBuf;
	long          AudioBufSize;
	long          AudioRate;
	long          Volume;
	long          HMIBufSize;
	long          DigiHandle;
	long          DigiCard;
	long          DigiPort;
	long          DigiIRQ;
	long          DigiDMA;
} VQAConfig;

/* Drawer Configuration flags (DrawFlags) */
#define	VQACFGB_BUFFER   0 /* Buffer UnVQ enable */
#define	VQACFGB_NODRAW   1 /* Drawing disable */
#define VQACFGB_NOSKIP   2 /* Disable frame skipping. */
#define	VQACFGB_VRAMCB   3 /* XMode VRAM copy enable */
#define VQACFGB_ORIGIN   4 /* 0,0 origin position */
#define	VQACFGB_SCALEX2  6 /* Scale X2 enable (VESA 320x200 to 640x400) */
#define	VQACFGF_BUFFER   (1<<VQACFGB_BUFFER)
#define	VQACFGF_NODRAW   (1<<VQACFGB_NODRAW)
#define	VQACFGF_NOSKIP   (1<<VQACFGB_NOSKIP)
#define	VQACFGF_VRAMCB   (1<<VQACFGB_VRAMCB)
#define	VQACFGF_ORIGIN   (3<<VQACFGB_ORIGIN)
#define	VQACFGF_TOPLEFT  (0<<VQACFGB_ORIGIN)
#define	VQACFGF_TOPRIGHT (1<<VQACFGB_ORIGIN)
#define	VQACFGF_BOTRIGHT (2<<VQACFGB_ORIGIN)
#define	VQACFGF_BOTLEFT  (3<<VQACFGB_ORIGIN)
#define	VQACFGF_SCALEX2  (1<<VQACFGB_SCALEX2)

/* Options Configuration (OptionFlags) */
#define	VQAOPTB_AUDIO   0 /* Audio enable */
#define	VQAOPTB_STEP    1 /* Single step enable */
#define	VQAOPTB_MONO    2 /* Mono output enable */
#define	VQAOPTB_FINF    3 /* Frame info chunk enable */
#define	VQAOPTB_SLOWPAL 4 /* Slow palette enable */
#define VQAOPTB_HMIINIT 5 /* HMI already initialized by client. */
#define	VQAOPTF_AUDIO   (1<<VQAOPTB_AUDIO)
#define	VQAOPTF_STEP    (1<<VQAOPTB_STEP)
#define	VQAOPTF_MONO    (1<<VQAOPTB_MONO)
#define	VQAOPTF_FINF    (1<<VQAOPTB_FINF)
#define	VQAOPTF_SLOWPAL (1<<VQAOPTB_SLOWPAL)
#define VQAOPTF_HMIINIT (1<<VQAOPTB_HMIINIT)

/* VQAInfo: Information about the VQA movie.
 *
 * NumFrames   - The number of frames contained in the movie.
 * ImageHeight - Height of image in pixels.
 * ImageWidth  - Width of image in pixels.
 */
typedef struct _VQAInfo {
	long NumFrames;
	long ImageWidth;
	long ImageHeight;
} VQAInfo;

/* VQAStatistics: Statistics about the VQA movie played.
 *
 * StartTime     - Time movie started.
 * EndTime       - Time movie stoped.
 * FramesLoaded  - Total number of frames loaded.
 * FramesDrawn   - Total number of frames drawn.
 * FramesSkipped - Total number of frames skipped.
 * MaxFrameSize  - Size of largest frame.
 * SamplesPlayed - Number of sample bytes played.
 * MemUsed       - Total bytes used. (Low memory)
 */
typedef struct _VQAStatistics {
	long          StartTime;
	long          EndTime;
	long          FramesLoaded;
	long          FramesDrawn;
	long          FramesSkipped;
	long          MaxFrameSize;
	unsigned long SamplesPlayed;
	unsigned long MemUsed;
} VQAStatistics;

/* VQAHandle: VQA file handle. (Must be obtained by calling VQA_Alloc()
 *            and freed through VQA_Free(). This is the only legal way
 *            to obtain and dispose of a VQAHandle.
 *
 * VQAStream - Something meaningful to the stream manager. (See DOCS)
 */
typedef struct _VQAHandle {
	unsigned long VQAStream;
} VQAHandle;

/* Possible stream command values */
#define VQACMD_INIT    1 /* Prepare the stream for a session */
#define VQACMD_CLEANUP 2 /* Terminate stream session */
#define VQACMD_OPEN    3 /* Open stream */
#define VQACMD_CLOSE   4 /* Close stream */
#define VQACMD_READ    5 /* Read bytes from stream */
#define VQACMD_WRITE   6 /* Write bytes to stream */
#define VQACMD_SEEK    7 /* Seek on stream */

/*---------------------------------------------------------------------------
 * FUNCTION PROTOTYPES
 *-------------------------------------------------------------------------*/

void VQA_INIConfig(VQAConfig *config);
void VQA_DefaultConfig(VQAConfig *config);

VQAHandle *VQA_Alloc(void);
void VQA_Free(VQAHandle *vqa);
void VQA_InitAsDOS(VQAHandle *vqa);
void VQA_Init(VQAHandle *vqa, unsigned long(*streamhandler)(VQAHandle *vqa,
		long action, void *buffer, long nbytes));

long VQA_Open(VQAHandle *vqa, char const *filename, VQAConfig *config);
void VQA_Close(VQAHandle *vqa);
long VQA_Play(VQAHandle *vqa, long mode);

void VQA_GetInfo(VQAHandle *vqa, VQAInfo *info);
void VQA_GetStats(VQAHandle *vqa, VQAStatistics *stats);
char *VQA_Version(void);
char *VQA_IDString(void);

#endif  /* VQAPLAY_H */

