#ifndef GRAPHICS_BLITTER_H
#define GRAPHICS_BLITTER_H TRUE

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

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

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

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

struct Bitmap {
  struct Head Head;    /* [00] Standard structure header */
  APTR   Data;         /* [12] Pointer to bitmap data area */
  WORD   Width;        /* [16] Width */
  WORD   ByteWidth;    /* [18] ByteWidth */
  WORD   Height;       /* [20] Height */
  WORD   Type;         /* [22] Screen type */
  LONG   LineMod;      /* [24] Line differential */
  LONG   PlaneMod;     /* [28] Plane differential */
  struct Head *Parent; /* [32] Bitmap owner */
  APTR   Restore;      /* [36] Restore list for this bitmap, if any */
  LONG   Size;         /* [40] Total size of the bitmap in bytes */
  LONG   MemType;      /* [44] Memory type to use in allocation */
  WORD   Planes;       /* [48] Amount of planes */
  WORD   resEmpty;     /* [50] Reserved */
  LONG   AmtColours;   /* [52] Maximum amount of colours available */

  /*** Private fields below ***/

  WORD   prvAFlags;    /* Allocation flags */
};

#define BMA_Data       (TAPTR|12)
#define BMA_Width      (TWORD|16)
#define BMA_ByteWidth  (TWORD|18)
#define BMA_Height     (TWORD|20)
#define BMA_Type       (TWORD|22)
#define BMA_LineMod    (TLONG|24)
#define BMA_PlaneMod   (TLONG|28)
#define BMA_Parent     (TAPTR|32)
#define BMA_Restore    (TAPTR|36)
#define BMA_Size       (TLONG|40)
#define BMA_MemType    (TLONG|44)
#define BMA_Planes     (TWORD|48)
#define BMA_AmtColours (TLONG|52)

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

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

struct Restore {
  struct Head Head;      /* Standard header */
  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;             /* [00] Standard structure header */
  BYTE   *GfxData;              /* [12] Pointer to graphics source */
  BYTE   *MaskData;             /* [16] Pointer to mask source */
  struct FrameList *GfxCoords;  /* [20] Pointer to graphic frame coordinates */
  WORD   Frame;                 /* [24] Current frame */
  WORD   SrcWidth;              /* [26] Source Page Width in bytes */
  WORD   Width;                 /* [28] Width in pixels */
  WORD   ByteWidth;             /* [30] Width in bytes */
  WORD   XCoord;                /* [32] To X pixel */
  WORD   YCoord;                /* [34] To Y pixel */
  WORD   Height;                /* [36] Height in pixels */
  WORD   ClipLX;                /* [38] Left X border */
  WORD   ClipTY;                /* [40] Top Y border */
  WORD   ClipRX;                /* [42] Right X border */
  WORD   ClipBY;                /* [44] Bottom Y border */
  WORD   FPlane;                /* [46] 1st Plane to blit to (planar only) */
  WORD   Planes;                /* [48] Amount of planes */
  WORD   PropHeight;            /* [50] Expected height of source picture */
  WORD   PropWidth;             /* [52] Expected width of source picture */
  WORD   Buffers;               /* [54] Relevant only to restore mode */
  LONG   PlaneSize;             /* [56] Size of source plane (planar only) */
  LONG   Attrib;                /* [60] Attributes like CLIP and MASK */
  struct Bitmap *SrcBitmap;     /* [64] Source Bitmap */
  WORD   Empty;                 /* [68] Reserved, in use by MBob */
  WORD   SrcMaskWidth;          /* [70] Mask page width in bytes */
  APTR   Source;                /* [72] Pointer to source object */
  APTR   *DirectGfx;            /* [76] Pointer to direct frame list */
  struct GScreen *Screen;       /* [80] Destination Screen */
  struct Bitmap  *DestBitmap;   /* [84] Destination Bitmap */
  struct FrameList *MaskCoords; /* [88] Pointer to mask frame coordinates */
  APTR   *DirectMasks;          /* [92] */
  WORD   AmtFrames;             /* [96] Amount of frames in frame/direct list */

  /*** 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 */
  BYTE   *prvStoreA;        /* Storage buffer 1 */
  BYTE   *prvStoreB;        /* Storage buffer 2 */
  BYTE   *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 */
  WORD   prvModuloC;        /* Modulus (C) */ 
  WORD   prvModuloB;        /* Modulus (B) */ 
  WORD   prvModuloA;        /* Modulus (A) */
  WORD   prvModuloD;        /* Modulus (D) */
  WORD   prvNSModuloC;      /* NSModulus (C) */ 
  WORD   prvNSModuloB;      /* NSModulus (B) */ 
  WORD   prvNSModuloA;      /* NSModulus (A) */ 
  WORD   prvNSModuloD;      /* NSModulus (D) */ 
  WORD   prvWordWidth;      /* The word width */
  BYTE   prvAFlags;         /* Allocation flags */
  BYTE   prvPad;
};

#define BBA_GfxData      (12|TAPTR)
#define BBA_MaskData     (16|TAPTR)
#define BBA_GfxCoords    (20|TAPTR)
#define BBA_Frame        (24|TWORD)
#define BBA_SrcWidth     (26|TWORD)
#define BBA_Width        (28|TWORD)
#define BBA_ByteWidth    (30|TWORD)
#define BBA_XCoord       (32|TWORD)
#define BBA_YCoord       (34|TWORD)
#define BBA_Height       (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_PropHeight   (50|TWORD)
#define BBA_PropWidth    (52|TWORD)
#define BBA_Buffers      (54|TWORD)
#define BBA_PlaneSize    (56|TLONG)
#define BBA_Attrib       (60|TLONG)
#define BBA_Empty        (64|TWORD)
#define BBA_SrcMaskWidth (70|TWORD)
#define BBA_Source       (72|TAPTR)
#define BBA_DirectGfx    (76|TAPTR)
#define BBA_Screen       (80|TAPTR)
#define BBA_DestBitmap   (84|TAPTR)
#define BBA_MaskCoords   (88|TAPTR)
#define BBA_DirectMasks  (92|TAPTR)
#define BBA_AmtFrames    (96|TWORD)

#define BBA_SourceTags   (TSTEPIN|TTRIGGER|72)

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

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

struct MBob {
  struct Head Head;              /* [00] Standard structure header */
  APTR   GfxData;                /* [12] Pointer to graphics source */
  APTR   MaskData;               /* [] Pointer to mask source */
  struct FrameList *FrameList;   /* [] Pointer to frame list */
  WORD   AmtEntries;             /* [] Amount of entries in the list */
  WORD   SrcWidth;               /* [] Source Page Width in bytes */
  WORD   Width;                  /* [] Width in pixels (optional) */
  WORD   ByteWidth;              /* [] Width in bytes */
  APTR   EntryList;              /* [] :MB: Pointer to entry list */
  WORD   Height;                 /* [] Height in pixels */
  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 */
  WORD   PropHeight;             /* [] Expected height of source picture */
  WORD   PropWidth;              /* [] Expected width of source picture */
  WORD   Buffers;                /* [] Relevent only to restore mode */
  LONG   PlaneSize;              /* [] Size of source plane (planar only) */
  LONG   Attrib;                 /* [] Attributes like CLIP and MASK */
  struct Bitmap *SrcBitmap;      /* [] Source Bitmap */
  WORD   EntrySize;              /* [] Entry size (sizeof(struct MBEntry)) */
  WORD   SrcMaskWidth;           /* [] Mask page width in bytes */
  APTR   Source;                 /* [] Pointer to source object */
  LONG   *DirectGfx;             /* [] Pointer to direct frame list */
  struct GScreen   *Screen;      /* [] The MBob's destination Screen */
  struct Bitmap    *DestBitmap;  /* [] The MBob's destination Bitmap */
  struct FrameList *MaskCoords;  /* [] */
  LONG   *DirectMasks;           /* [] */
  WORD   AmtFrames;              /* [] Amount of frames in frame/direct list */

  /*** 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 MBA_GfxData      (12|TAPTR)
#define MBA_MaskData     (16|TAPTR)
#define MBA_FrameList    (22|TAPTR)
#define MBA_AmtEntries   (20|TWORD)
#define MBA_SrcWidth     (26|TWORD)
#define MBA_Width        (28|TWORD)
#define MBA_ByteWidth    (30|TWORD)
#define MBA_EntryList    (32|TWORD)
#define MBA_Height       (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_PropHeight   (50|TWORD)
#define MBA_PropWidth    (52|TWORD)
#define MBA_Buffers      (54|TWORD)
#define MBA_PlaneSize    (56|TLONG)
#define MBA_Attrib       (60|TLONG)
/*      MBA_SrcBitmap    (64|TAPTR)*/
#define MBA_EntrySize    (68|TWORD)
#define MBA_SrcMaskWidth (70|TWORD)
#define MBA_Source       (72|TAPTR)
#define MBA_DirectList   (76|TAPTR)
#define MBA_Screen       (80|TAPTR)
#define MBA_DestBitmap   (84|TAPTR)
#define MBA_MaskCoords   (88|TAPTR)
#define MBA_DirectMasks  (92|TAPTR)
#define MBA_AmtFrames    (96|TWORD)

struct MBEntry {        /* MBob Entry Structure */
  WORD XCoord;
  WORD YCoord;
  WORD 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   */
#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 {
  WORD   Entries;
  WORD   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 */
