/* C include file for the iff.library       Last update: 12-Jul-88
   The C-Asm interface for Aztec C is also in this file, you can
   convert it to a library if you want. I think this does not run
   under Lattice C (I didn't try).
 */

#ifndef LIBRARIES_IFF_H
#define LIBRARIES_IFF_H
#ifndef EXEC_TYPES_H
#include "exec/types.h"
#endif

#define IFFNAME "iff.library"
#define IFFVERSION 15L              /* Current library version */


/************** E R R O R - C O D E S ***********************************/

#define IFF_BADTASK -1              /* IffError() called by wrong task */

#define IFF_CANTOPENFILE 16         /* File not found */
#define IFF_READERROR 17            /* Error reading file */
#define IFF_NOMEM 18                /* Not enough memory */
#define IFF_NOTIFF 19               /* File is not an IFF file */
#define IFF_WRITEERROR 20           /* Error writing file */

#define IFF_NOILBM 24               /* IFF file is not of type ILBM */
#define IFF_NOBMHD 25               /* BMHD chunk not found */
#define IFF_NOBODY 26               /* BODY chunk not found */
#define IFF_TOOMANYPLANES 27        /* BODY has more planes than BitMap */
#define IFF_UNKNOWNCOMPRESSION 28   /* Unknown compression type */


/************** S T R U C T U R E S *************************************/

struct Chunk
{
   LONG  ckID;
   LONG  ckSize;
   UBYTE ckData[1];	/* should be UBYTE ckData[ckSize] */
};


struct BitMapHeader
{
   UWORD w,h;
   WORD  x,y;
   UBYTE nPlanes;
   UBYTE masking;
   UBYTE compression;
   UBYTE pad1;
   UWORD transparentColor;
   UBYTE xAspect,yAspect;
   WORD  pageWidth,pageHeight;
};


/************** F U N C T I O N   D E C L A R A T I O N S ***************/

APTR OpenIFF();
void CloseIFF();
struct Chunk *FindChunk();
LONG GetColorTab();
struct BitMapHeader *GetBMHD();
BOOL DecodePic();
BOOL SaveBitMap();
BOOL SaveClip();
LONG IffError();
UWORD GetViewModes();


/************** C - A S S E M B L E R   I N T E R F A C E ***************/

#asm
; :ts=8
		public	_IFFBase

		public	_OpenIFF
_OpenIFF:	move.l	4(sp),a0
		move.l	_IFFBase,a6
		jmp	-30(a6)

		public	_CloseIFF
_CloseIFF:	move.l	4(sp),a1
		move.l	_IFFBase,a6
		jmp	-36(a6)

		public	_FindChunk
_FindChunk:	move.l	4(sp),a1
		move.l	8(sp),d0
		move.l	_IFFBase,a6
		jmp	-42(a6)

		public	_GetBMHD
_GetBMHD:	move.l	4(sp),a1
		move.l	_IFFBase,a6
		jmp	-48(a6)

		public	_GetColorTab
_GetColorTab:	move.l	4(sp),a1
		move.l	8(sp),a0
		move.l	_IFFBase,a6
		jmp	-54(a6)

		public	_DecodePic
_DecodePic:	move.l	4(sp),a1
		move.l	8(sp),a0
		move.l	_IFFBase,a6
		jmp	-60(a6)

		public	_SaveBitMap
_SaveBitMap:	move.l	a2,-(sp)
		movem.l	8(sp),a0/a1/a2
		move.l	20(sp),d0
		move.l	_IFFBase,a6
		jsr	-66(a6)
		move.l	(sp)+,a2
		rts

		public	_SaveClip
_SaveClip:	movem.l	d4/a2,-(sp)
		movem.l	24(sp),d0-d4
		movem.l	12(sp),a0-a2
		move.l	_IFFBase,a6
		jsr	-72(a6)
		movem.l	(sp)+,d4/a2
		rts

		public	_IffError
_IffError:	move.l	_IFFBase,a6
		jmp	-78(a6)

		public	_GetViewModes
_GetViewModes:	move.l	4(sp),a1
		move.l	_IFFBase,a6
		jmp	-84(a6)
#endasm

#endif !LIBRARIES_IFF_H
