#ifndef GRAPHICS_BLITTER_H
#define GRAPHICS_BLITTER_H TRUE

/*
**    $VER: blit.h V0.8B
**
**    Blitter Definitions
**
**    (C) Copyright 1996-1997 DreamWorld Productions.
**        All Rights Reserved
*/

#ifndef DPKERNEL_H
#include <games/dpkernel.h>
#endif

/***************************************************************************
** Bitmap Object.
*/

#define BMPVERSION  1
#define TAGS_BITMAP ((ID_SPCTAGS<<16)|ID_BITMAP)

struct Bitmap {
  struct Head Head;    /* Standard structure header */
  APTR   Data;         /* Pointer to bitmap data area */
  WORD   Width;        /* Width */
  WORD   ByteWidth;    /* ByteWidth */
  WORD   Height;       /* Height */
  WORD   ScrType;      /* Screen type */
  LONG   LineModulo;   /* Line differential */
  LONG   PlaneModulo;  /* Plane differential */
  struct Head *Owner;  /* Bitmap owner */
  APTR   Restore;      /* Restore list for this bitmap, if any */
  LONG   Size;         /* Total size of the bitmap in bytes */
  LONG   MemType;      /* Memory type to use in allocation */
  WORD   Planes;       /* Amount of planes */

  /*** Private fields below ***/

  WORD   prvAFlags;    /* Private */
};

/***************************************************************************
** Restore Object.
*/

#define RSTVERSION   1
#define TAGS_RESTORE ((ID_SPCTAGS<<16)|ID_RESTORE)

struct Restore {
  struct Head Head;
  WORD   Buffers;        /* Amount of screen buffers */
  WORD   Entries;        /* Amount of entries */
  struct Head *Owner;    /* Owner of the restorelist, ie bitmap */

  /*** Private fields below ***/

  struct RstEntry *List1;
  struct RstEntry *List2;
  struct RstEntry *List3;
  struct RstEntry *ListPos1;
  struct RstEntry *ListPos2;
  struct RstEntry *ListPos3;
};

/* This structure is completely private */

struct RstEntry {
  struct RstEntry *Next;  /* Next restore entry in the chain */
  struct RstEntry *Prev;  /* Previous restore enty in the chain */
  APTR   Bob;             /* Bob structure belonging to the restore [*] */
  APTR   Address;         /* Screen pointer (top of screen) [*] */
  APTR   Storage;         /* Background storage or NULL */
  APTR   Control;         /* Controls from the lookup table */
  APTR   ConMask;         /* The control mask to use */
  WORD   Modulo1;         /* Modulo C */
  LONG   Modulo2;         /* Modulos A/D */
  WORD   BlitWidth;       /* [*] */
  WORD   BlitHeight;      /* [*] */
};

#define RSA_Buffers  (12|TWORD)
#define RSA_Entries  (14|TWORD)
#define RSA_Owner    (16|TAPTR)

/***************************************************************************
** Bob Object.
*/

#define BOBVERSION  1
#define TAGS_BOB    ((ID_SPCTAGS<<16)|ID_BOB)

struct  FrameList {
  WORD  XCoord;
  WORD  YCoord;
};

struct   Bob {
  struct Head Head;             /* Standard structure header */
  APTR   GfxData;               /* Pointer to graphics source */
  APTR   MaskData;              /* Pointer to mask source */
  WORD   Frame;                 /* Current frame */
  struct FrameList *GfxCoords;  /* Pointer to graphic frame coordinates */
  WORD   SrcWidth;              /* Source Page Width in bytes */
  WORD   Width;                 /* Width in pixels */
  WORD   ByteWidth;             /* Width in bytes */
  WORD   Height;                /* Height in pixels */
  WORD   XCoord;                /* To X pixel */
  WORD   YCoord;                /* To Y pixel */
  WORD   ClipLX;                /* Left X border in bytes (0/8) */
  WORD   ClipTY;                /* Top Y border (0) */
  WORD   ClipRX;                /* Right X border in bytes (320/8) */
  WORD   ClipBY;                /* Bottom Y border (256) */
  WORD   FPlane;                /* 1st Plane to blit to (planar only) */
  WORD   Planes;                /* Amount of planes */
  LONG   PlaneSize;             /* Size of source plane (planar only) */
  LONG   Attrib;                /* Attributes like CLIP and MASK */
  LONG   *PictureTags;          /* Pointer to picture tags */
  WORD   Empty;                 /* Reserved, in use by MBob */
  WORD   SrcMaskWidth;          /* Mask page width in bytes */
  struct Picture *Picture;      /* Pointer to picture structure */
  LONG   *DirectGfx;            /* Pointer to direct frame list */
  WORD   AmtFrames;             /* Amount of frames in frame/direct list */
  struct GameScreen *Screen;    /* Destination GameScreen */
  struct Bitmap *Bitmap;        /* Destination Bitmap */
  WORD   Buffers;               /* Relevant only to restore mode */
  struct FrameList *MaskCoords; /* Pointer to mask frame coordinates */
  WORD   PropWidth;             /* Expected width of source picture */
  WORD   PropHeight;            /* Expected height of source picture */
  LONG   *DirectMasks;          /* */

  /*** Private fields start now ***/

  WORD   prvStoreSize;      /* 4/8/12 Sizeof one store entry (MBob's) */
  APTR   prvStoreBuffer;    /* A/B/C [0/4/8] storage pointer (MBob's) */
  WORD   prvStoreMax;       /* Maximum store position */
  APTR   prvStoreMemory;    /* Master storage pointer (for the freemem) */
  WORD   prvStoreCount;     /* Counter for store, 0, 4, 8 */
  APTR   prvStoreA;         /* Storage buffer 1 */
  APTR   prvStoreB;         /* Storage buffer 2 */
  APTR   prvStoreC;         /* Storage buffer 3 */
  APTR   prvDrawRoutine;    /* Routine for drawing/clearing/storing */
  APTR   prvClearRoutine;   /* Routine for clearing */
  APTR   prvRestoreRoutine; /* Routine for restoring/clearing */
  APTR   prvHeightRoutine;  /* Replaces BS_DrawRoutine for large heights */
  LONG   prvScreenSize;     /* Size of destination plane */
  WORD   prvModulo;         /* Bob Modulo (PicWidth-BobWidth) */
  WORD   prvMaskModulo;     /* Mask Modulo (BobWidth-BobWidth for GENMASK) */
  APTR   prvMaskMemory;     /* Master mask pointer (for the freemem) */
  WORD   prvMaxHeight;      /* Maximum possible height, limited by blitter */
  WORD   prvScrLine;        /* Size of a line (for interleaved) */
  WORD   prvBOBLine;        /* Size of a Bob line (Width*Planes) */
  WORD   prvMaskLine;       /* Size of a Mask Line (Width*Planes) */
  WORD   prvTrueWidth;      /* The true pixel width (++shift) */
  WORD   prvTrueBWidth;     /* The true byte width (++shift) */
  WORD   prvTrueWWidth;     /* The true word width (++shift) */
  WORD   prvClipBLX;        /* ClipLX, byte */
  WORD   prvClipBRX;        /* ClipRX, byte */
  LONG   prvModulo1;        /* Modulus (C/B) */ 
  LONG   prvModulo2;        /* Modulus (A/D) */ 
  LONG   prvNSModulo1;      /* Modulus (C/B) */ 
  LONG   prvNSModulo2;      /* Modulus (A/D) */ 
  WORD   prvWordWidth;      /* The word width */
  BYTE   prvAFlags;         /* Allocation flags */
  BYTE   prvPad;
};

#define BBA_GfxData      (12|TAPTR)
#define BBA_MaskData     (16|TAPTR)
#define BBA_Frame        (20|TWORD)
#define BBA_GfxCoords    (22|TAPTR)
#define BBA_SrcWidth     (26|TWORD)
#define BBA_Width        (28|TWORD)
#define BBA_ByteWidth    (30|TWORD)
#define BBA_Height       (32|TWORD)
#define BBA_XCoord       (34|TWORD)
#define BBA_YCoord       (36|TWORD)
#define BBA_ClipLX       (38|TWORD)
#define BBA_ClipTY       (40|TWORD)
#define BBA_ClipRX       (42|TWORD)
#define BBA_ClipBY       (44|TWORD)
#define BBA_FPlane       (46|TWORD)
#define BBA_Planes       (48|TWORD)
#define BBA_PlaneSize    (50|TLONG)
#define BBA_Attrib       (54|TLONG)
#define BBA_PictureTags  (58|TAPTR)
#define BBA_Empty        (62|TWORD)
#define BBA_SrcMaskWidth (64|TWORD)
#define BBA_Picture      (66|TAPTR)
#define BBA_DirectGfx    (70|TAPTR)
#define BBA_AmtFrames    (74|TWORD)
#define BBA_Screen       (76|TAPTR)
#define BBA_Bitmap       (80|TAPTR)
#define BBA_Buffers      (84|TWORD)
#define BBA_MaskCoords   (86|TAPTR)
#define BBA_PropWidth    (90|TWORD)
#define BBA_PropHeight   (92|TWORD)
#define BBA_DirectMasks  (94|TAPTR)

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

#define MBOBVERSION 1
#define TAGS_MBOB   ((ID_SPCTAGS<<16)|ID_MBOB)

struct MBob {
  struct Head Head;              /* Standard structure header */
  APTR   GfxData;                /* Pointer to graphics source */
  APTR   MaskData;               /* Pointer to mask source */
  WORD   AmtEntries;             /* Amount of entries in the list */
  struct FrameList *FrameList;   /* Pointer to frame list */
  WORD   SrcWidth;               /* Source Page Width in bytes */
  WORD   Width;                  /* Width in pixels (optional) */
  WORD   ByteWidth;              /* Width in bytes */
  WORD   Height;                 /* Height in pixels */
  APTR   EntryList;              /* Pointer to entry list */
  WORD   ClipLX;                 /* Left X border */
  WORD   ClipTY;                 /* Top Y border */
  WORD   ClipRX;                 /* Right X border */
  WORD   ClipBY;                 /* Bottom Y border */
  WORD   FPlane;                 /* 1st Plane to blit to (planar only) */
  WORD   Planes;                 /* Amount of planes */
  LONG   PlaneSize;              /* Size of source plane (planar only) */
  LONG   Attrib;                 /* Attributes like CLIP and MASK */
  APTR   PictureTags;            /* Pointer to picture tags (optional) */
  WORD   EntrySize;              /* Entry size (sizeof(struct MBEntry)) */
  WORD   SrcMaskWidth;           /* Mask page width in bytes */
  struct Picture *Picture;       /* Pointer to picture structure */
  LONG   *DirectGfx;             /* Pointer to direct frame list */
  WORD   AmtFrames;              /* Amount of frames in frame/direct list */
  struct GameScreen *Screen;     /* The MBob's GameScreen */
  struct Bitmap *Bitmap;         /* The MBob's Bitmap */
  WORD   Buffers;                /* */
  struct FrameList *MaskCoords;  /* */
  WORD   PropWidth;              /* Expected width of source picture */
  WORD   PropHeight;             /* Expected height of source picture */
  LONG   *DirectMasks;           /* */

  /* Private fields start now */

  WORD   BOB_StoreSize;      /* 4/8/12 Sizeof one store entry (MBob's) */
  APTR   BOB_StoreBuffer;    /* A/B/C [0/4/8] storage pointer (MBob's) */
  WORD   BOB_StoreMax;       /* Maximum store position */
  APTR   BOB_StoreMemory;    /* Master storage pointer (for the freemem) */
  WORD   BOB_StoreCount;     /* Counter for store, 0, 4, 8 */
  APTR   BOB_StoreA;         /* Storage buffer 1 */
  APTR   BOB_StoreB;         /* Storage buffer 2 */
  APTR   BOB_StoreC;         /* Storage buffer 3 */
  APTR   BOB_DrawRoutine;    /* Routine for drawing/clearing/storing */
  APTR   BOB_ClearRoutine;   /* Routine for clearing */
  APTR   BOB_RestoreRoutine; /* Routine for restoring/clearing */
  APTR   BOB_HeightRoutine;  /* Replaces BS_DrawRoutine for large heights */
  LONG   BOB_ScreenSize;     /* Size of destination plane */
  WORD   BOB_Modulo;         /* Bob Modulo (PicWidth-BobWidth) */
  WORD   BOB_MaskModulo;     /* Mask Modulo (BobWidth-BobWidth for GENMASK) */
  APTR   BOB_MaskMemory;     /* Master mask pointer (for the freemem) */
  WORD   BOB_MaxHeight;      /* Maximum possible height, limited by blitter */
  WORD   BOB_ScrLine;        /* Size of a line (for interleaved) */
  WORD   BOB_BOBLine;        /* Size of a Bob line (Width*Planes) */
  WORD   BOB_MaskLine;       /* Size of a Mask Line (Width*Planes) */
  WORD   BOB_TrueWidth;      /* The true pixel width (++shift) */
  WORD   BOB_TrueBWidth;     /* The true byte width (++shift) */
  WORD   BOB_TrueWWidth;     /* The true word width (++shift) */
  WORD   BOB_ClipBLX;        /* ClipLX, byte */
  WORD   BOB_ClipBRX;        /* ClipRX, byte */
  LONG   BOB_Modulo1;        /* Modulus (C/B) */ 
  LONG   BOB_Modulo2;        /* Modulus (A/D) */ 
  LONG   BOB_NSModulo1;      /* Modulus (C/B) */ 
  LONG   BOB_NSModulo2;      /* Modulus (A/D) */ 
  WORD   BOB_WordWidth;      /* The word width */
  BYTE   BOB_AFlags;         /* Allocation flags */
  BYTE   BOB_Pad;
};

#define MBA_GfxData      (12|TAPTR)
#define MBA_MaskData     (16|TAPTR)
#define MBA_AmtEntries   (20|TWORD)
#define MBA_FrameList    (22|TAPTR)
#define MBA_SrcWidth     (26|TWORD)
#define MBA_Width        (28|TWORD)
#define MBA_ByteWidth    (30|TWORD)
#define MBA_Height       (34|TWORD)
#define MBA_EntryList    (36|TWORD)
#define MBA_ClipLX       (38|TWORD)
#define MBA_ClipTY       (40|TWORD)
#define MBA_ClipRX       (42|TWORD)
#define MBA_ClipBY       (44|TWORD)
#define MBA_FPlane       (46|TWORD)
#define MBA_Planes       (48|TWORD)
#define MBA_PlaneSize    (50|TLONG)
#define MBA_Attrib       (54|TLONG)
#define MBA_PictureTags  (58|TAPTR)
#define MBA_EntrySize    (62|TWORD)
#define MBA_SrcMaskWidth (64|TWORD)
#define MBA_Picture      (66|TAPTR)
#define MBA_DirectList   (70|TAPTR)
#define MBA_AmtFrames    (74|TWORD)
#define MBA_Screen       (76|TAPTR)
#define MBA_Bitmap       (80|TAPTR)
#define MBA_Buffers      (84|TWORD)
#define MBA_MaskCoords   (86|TAPTR)
#define MBA_PropWidth    (90|TWORD)
#define MBA_PropHeight   (92|TWORD)
#define MBA_DirectMasks  (94|TAPTR)

struct  MBEntry {        /* MBOB Entry Structure */
  WORD   XCoord;
  WORD   YCoord;
  UWORD  Frame;
};

#define MBE_SIZEOF sizeof(struct BobEntry)

/* Bob Attributes (Bob.Attrib) */

#define BBF_CLIP      0x00000001 /* Allow border clipping */
#define BBF_MASK      0x00000002 /* Allow masking */
#define BBF_STILL     0x00000004 /* This bob is not moving */
#define BBF_CLEAR     0x00000008 /* Allow automatic clearing */
#define BBF_RESTORE   0x00000010 /* Allow automatic background restore */
/*#define           0x00000020    Using direct graphics and mask pointers */
#define BBF_FILLMASK  0x00000040 /* Fill any holes in the mask on generation */
#define BBF_GENONLY   0x00000080 /* Create masks but do not use them yet */
#define BBF_GENMASKS  0x00000082 /* Create and use masks for drawing this bob */
#define BBF_CLRMASK   0x00000100 /* Use masks when clearing */
#define BBF_CLRNOMASK 0x00000000 /* Do not use masks when clearing (default) */

#define BBF_GENMASK BBF_GENMASKS /* Synonym */

#define SKIPIMAGE 32000

/****************************************************************************
** Pixel list structures.
*/

struct PixelEntry {
  WORD  XCoord;
  WORD  YCoord;
  LONG  Colour;
};

struct PixelList {
  UWORD  Entries;
  UWORD  EntrySize;
  struct PixelEntry *EntryList;
};

#define SKIPPIXEL -32000
#define PIXELLIST(a)

/****************************************************************************
** Map object.
*/

#define MAPVERSION 1
#define TAGS_MAP   ((ID_SPCTAGS<<16)|ID_MAP)

struct Map {
  struct Head Head;            /* Standard structure header */
  WORD   Buffer;               /* Destination buffer */
  WORD   Number;               /* Map number to access for data */
  APTR   MapList;              /* Pointer to the map datalist */
  WORD   Width;                /* Total width of map */
  WORD   Height;               /* Total height of map */
  WORD   XStart;               /* Get block data starting from X [byte] */
  WORD   YStart;               /* Get block data starting from Y */
  WORD   EntrySize;            /* Byte/Word/Long */
  LONG   EntryMask;            /* For special cases */
  WORD   TileWidth;            /* The width/8 of each tile (bytes) */
  WORD   TileHeight;           /* The height of each tile */
  WORD   Options;              /* Applicable Map options, eg LOCKED */
  struct Picture *Picture;     /* Points to the map's graphics picture */
  char   *File;                /* Where to get the map data */
};

#define LOCKED      0x0001 /* Blocks are blitted on 16 pixel boundaries  */
#define ESIZE_BYTE  1      /* Entry size is in bytes */
#define ESIZE_WORD  2      /* Entry size is in words */
#define ESIZE_LONG  3      /* Entry size is in longs */

#endif /* GRAPHICS_BLITTER_H */
