
/******************************************************************************
 *
 * Flowerpower's DeBox Datatype
 *
 * Written by Christian Buchner and David N. Junod
 *
 ******************************************************************************
 * classbase.h
 *
 */

#include <dos/dos.h>
#include <dos/dosextens.h>
#include <exec/types.h>
#include <exec/ports.h>
#include <exec/memory.h>
#include <exec/lists.h>
#include <exec/semaphores.h>
#include <exec/execbase.h>
#include <intuition/classes.h>
#include <intuition/classusr.h>
#include <intuition/cghooks.h>
#include <intuition/gadgetclass.h>
#include <graphics/gfx.h>
#include <graphics/text.h>
#include <graphics/view.h>
#include <libraries/iffparse.h>
#include <datatypes/datatypes.h>
#include <datatypes/datatypesclass.h>
#include <datatypes/pictureclass.h>
#include <string.h>
#include <dos.h>

#include <clib/macros.h>
#include <clib/dos_protos.h>
#include <clib/exec_protos.h>
#include <clib/intuition_protos.h>
#include <clib/iffparse_protos.h>
#include <clib/graphics_protos.h>
#include <clib/utility_protos.h>
#include <clib/datatypes_protos.h>
#include <clib/dtclass_protos.h>
#include <clib/alib_protos.h>

#include <pragmas/dos_pragmas.h>
#include <pragmas/exec_pragmas.h>
#include <pragmas/intuition_pragmas.h>
#include <pragmas/iffparse_pragmas.h>
#include <pragmas/graphics_pragmas.h>
#include <pragmas/utility_pragmas.h>
#include <pragmas/datatypes_pragmas.h>
#include <pragmas/dtclass_pragmas.h>

/*****************************************************************************/

struct DeBoxChunk
{
	UBYTE checksum;			/* header checksum */
	UBYTE headermark;		/* always 1 */
	UWORD dontknow02;		/* varies */
	UBYTE flags;			/* some flags */
	UBYTE crunchmethod;		/* the crunch method (0-15) */
	UBYTE destinplane;		/* destination bit plane number */
	UBYTE referenceplane;	/* reference bit plane number   */
	ULONG decrunched_len;	/* The decrunched length */
	ULONG chunk_len;		/* The chunk length */
};

#define FLGB_ANOTHER_CHUNK_FOLLOWS   7
#define FLGB_USE_EXTRA_BUFFER        6
#define FLGB_XOR_REFERENCE_INTO_DEST 5
#define FLGB_SUBTRACT_ONE_BYTE       4

#define FLGF_ANOTHER_CHUNK_FOLLOWS   (1<<7)
#define FLGF_USE_EXTRA_BUFFER        (1<<6)
#define FLGF_XOR_REFERENCE_INTO_DEST (1<<5)
#define FLGF_SUBTRACT_ONE_BYTE       (1<<4)

#define CRUNCHMETHOD_PLAIN  0
#define CRUNCHMETHOD_1      1
#define CRUNCHMETHOD_2      2
#define CRUNCHMETHOD_FILL   3
#define CRUNCHMETHOD_4      4
#define CRUNCHMETHOD_5      5

struct DeBoxInfo
{
	ULONG chunk_bytes;		/* number of bytes in this chunk */
	ULONG palette_offset;	/* offset to palette UWORDs */
	ULONG strange_offset;	/* offset to strange structs */
	UWORD width;			/* image width */
	UWORD height;			/* image height */
	UBYTE depth;			/* image depth */
	UBYTE dontknow11;		/* varies */
	UWORD modeid;			/* screen mode ID */
	UBYTE numcolors;		/* number of color registers */
	UBYTE numstrange;		/* number of strange structures to follow */
	UBYTE dontknow16;		/* varies */
	UBYTE dontknow17;		/* varies */
	ULONG dontknow18;		/* always 0 */
	/* Here follows the palette: numcolors UWORDS */
	/* Here follow numstrange strange structures */
};

/*****************************************************************************/

extern UBYTE __far LibName[];

/*****************************************************************************/

struct ClassBase
{
    struct Library			 cb_Lib;
    UWORD					 cb_UsageCnt;
    struct Library			*cb_SysBase;
    struct Library			*cb_DOSBase;
    struct Library			*cb_IntuitionBase;
    struct Library			*cb_GfxBase;
    struct Library			*cb_UtilityBase;
    struct Library			*cb_IFFParseBase;
    struct Library			*cb_DataTypesBase;
    struct Library			*cb_SuperClassBase;
    BPTR					 cb_SegList;
    struct SignalSemaphore	 cb_Lock;		/* Access lock */
    Class					*cb_Class;
};

/*****************************************************************************/

#define SysBase			cb->cb_SysBase
#define DOSBase			cb->cb_DOSBase
#define UtilityBase		cb->cb_UtilityBase
#define	IntuitionBase	cb->cb_IntuitionBase
#define	IFFParseBase	cb->cb_IFFParseBase
#define	GfxBase			cb->cb_GfxBase
#define	DataTypesBase	cb->cb_DataTypesBase

/*****************************************************************************/

/* classbase.c */
Class *__asm ObtainClassEngine ( register __a6 struct ClassBase *cb );
struct Library *__asm LibInit ( register __d0 struct ClassBase *cb , register __a0 BPTR seglist , register __a6 struct Library *sysbase );
LONG __asm LibOpen ( register __a6 struct ClassBase *cb );
LONG __asm LibClose ( register __a6 struct ClassBase *cb );
LONG __asm LibExpunge ( register __a6 struct ClassBase *cb );
void __asm LibReserved( register __a6 struct ClassBase *cb );

/* dispatch.c */
ULONG setdtattrs ( struct ClassBase *cb , Object *o , ULONG data , ...);
ULONG getdtattrs ( struct ClassBase *cb , Object *o , ULONG data , ...);
Class *initClass ( struct ClassBase *cb );
ULONG __asm Dispatch ( register __a0 Class *cl , register __a2 Object *o , register __a1 Msg msg );
BOOL __asm GetPicture ( register __a6 struct ClassBase *cb , register __a0 Class *cl , register __a2 Object *o , register __a1 struct TagItem *attrs );

/* AsmSupport.asm */
void __asm XOR_Memory(register __a1 UBYTE *Source, register __a0 UBYTE *Destin, register __d0 Bytes);
ULONG __asm Method_1(register __a1 UBYTE *SourceData, register __d7 SourceSize, register __a2 UBYTE *Reference, register __a3 UBYTE *Destin, register __d6 DestinSize);
ULONG __asm Method_2(register __a1 UBYTE *SourceData, register __d7 SourceSize, register __a2 UBYTE *Reference, register __a3 UBYTE *Destin, register __d6 DestinSize);
ULONG __asm Method_4(register __a1 UBYTE *SourceData, register __d7 SourceSize, register __a2 UBYTE *Reference, register __a3 UBYTE *Destin, register __d6 DestinSize);
ULONG __asm Method_5(register __a1 UBYTE *SourceData, register __d7 SourceSize, register __a2 UBYTE *Reference, register __a3 UBYTE *Destin, register __d6 DestinSize);

/* DeBoxCRC */

BOOL __asm DeBoxCRC(register __a0 struct DeBoxChunk *chunk);
