#ifndef GAMES_GMS_H
#define GAMES_GMS_H TRUE

/*
**   $VER: games.h V0.6B
**
**   General include file for programs using the Games Master System.
**
**   (C) Copyright 1996-1997 DreamWorld Productions.
**       All Rights Reserved
*/

#ifndef EXEC_TYPES_H
#include <exec/types.h>
#endif

#ifndef UTILITY_TAGITEM_H
#include <utility/tagitem.h>
#endif

#ifndef GMS_SOUND_H
#include <games/sound.h>
#endif

#ifndef GMS_MISC_H
#include <games/misc.h>
#endif

#ifndef GMS_IMAGE_H
#include <games/image.h>
#endif

#ifndef GMS_SCREENS_H
#include <games/screens.h>
#endif

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

#define GMSVersion  0
#define GMSRevision 6

#define TAGS       0x54414753
#define LIST       0x4C495354
#define OBJECTLIST 0x4F4C5354
#define SKIPENTRY  0
#define LISTEND    -1
#define ENDLIST    -1
#define TAGEND     0
#define DEFAULT    0

/****************************************************************************
** These are the identification codes for the structures and their related
** tag lists.
*/

#define ID_BOB        0x4242
#define ID_MBOB       0x4D42
#define ID_GAMESCREEN 0x4753
#define ID_SOUND      0x534D
#define ID_PICTURE    0x5043
#define ID_CARDSET    0x4352
#define ID_ANIM       0x414D
#define ID_MAP        0x4D50
#define ID_MOVIE      0x4D56
#define ID_FILE       0x464C
#define ID_SPRITE     0x5350
#define TG            0x5447

#define TAGS_BOB        (0x54470000|ID_BOB)
#define TAGS_MBOB       (0x54470000|ID_MBOB)
#define TAGS_GAMESCREEN (0x54470000|ID_GAMESCREEN)
#define TAGS_SOUND      (0x54470000|ID_SOUND)
#define TAGS_PICTURE    (0x54470000|ID_PICTURE)
#define TAGS_CARDS      (0x54470000|ID_CARDS)
#define TAGS_ANIM       (0x54470000|ID_ANIM)
#define TAGS_MAP        (0x54470000|ID_MAP)
#define TAGS_MOVIE      (0x54470000|ID_MOVIE)
#define TAGS_SPRITE     (0x54470000|ID_SPRITE)

/****************************************************************************
** Helpful macros and structures.
*/

#define GetX(a) (BYTE)((a)>>8)  /* Decompress ZBXY format */
#define GetY(a) (BYTE)(a)

/****************************************************************************
**
** Universal errorcodes returned by certain functions.
**
*/

#define ERR_OK           0  /* Function went OK (also NULL) */
#define ERR_NOMEM        1  /* Not enough memory available */
#define ERR_NOPTR        2  /* Required pointer not present */
#define ERR_INUSE        3  /* Previous allocations have not been freed */
#define ERR_NOVER        4  /* Structure version not supported or not found */
#define ERR_FAILED       5  /* General failure */
#define ERR_FILE         6  /* File error, eg file not found */
#define ERR_DATA         7  /* There is an error in the given data */
#define ERR_SEARCH       8  /* A search routine in this function failed */
#define ERR_SCRTYPE      9  /* Screen type not recognised */
#define ERR_GPI         10  /* Trouble initialising/using a GPI */
#define ERR_RASTCOMMAND 11  /* Invalid raster command detected */
#define ERR_RASTERLIST  12  /* Complete rasterlist failure */
#define ERR_NORASTER    13  /* Expected rasterlist is missing from GS_Rasterlist */
#define ERR_DISKFULL    14  /* Disk full error */
#define ERR_FILEMISSING 15  /* File not found */
#define ERR_WRONGVER    16  /* Wrong version or version not supported */
#define ERR_MONITOR     17  /* Monitor driver not found or cannot be used */
#define ERR_UNPACK      18  /* Problem with unpacking of data */

/****************************************************************************
** Memory types used by AllocMemBlock().  This is generally identical to the
** exec definitions but CHIP is renamed to VIDEO (displayable memory) and
** there is an addition of BLIT and SOUND specific memory.
*/

#define MEM_ANY       0
#define MEM_CLEAR     0
#define MEM_VIDEO     (1L<<1)
#define MEM_BLIT      (1L<<2)
#define MEM_SOUND     (1L<<3)
#define MEM_UNTRACKED (1L<<31)

/****************************************************************************
** File Structure.
*/

#define FL_READ   0
#define FL_WRITE  (1L<<0)
#define FL_LOCK   (1L<<1)
#define FL_NEW    (1L<<2)
#define FL_FIND   (1L<<3)
#define FL_UNPACK (1L<<4)
#define FL_BUFFER (1L<<5)

#define FL_PACK   FL_UNPACK
#define FL_SMART  FL_FIND|FL_UNPACK

#define FLV1 (ID_FILE<<16)|00

struct File {
  ULONG ID;           /* "FILE" */
  ULONG Stats;        /* Private */
  APTR  Name;         /* Pointer to name of the file on disk */
  ULONG BytePos;      /* Current position in file */
  ULONG Size;         /* Total size of the file */
  ULONG Flags;        /* File flags */
};

/****************************************************************************
** Universal joystick status bits returned from Read_Joystick, Sega,
** JoyPad, etc...
*/

#define JT_SWITCH 0
#define JT_ZBXY   1
#define JT_DATA   2

#define JS_LEFT   (1L<<0)          /* X axis */
#define JS_RIGHT  (1L<<1)
#define JS_UP     (1L<<2)          /* Y axis */
#define JS_DOWN   (1L<<3)
#define JS_ZIN    (1L<<4)          /* Z axis!  Reserved for later... */
#define JS_ZOUT   (1L<<5)
#define JS_FIRE1  (1L<<16)         /* Fire Buttons */
#define JS_FIRE2  (1L<<17)         /* For 2 button joysticks */
#define JS_FIRE3  (1L<<18)         /* For 3 button joysticks */
#define JS_FIRE4  (1L<<19)
#define JS_FIRE5  (1L<<20)
#define JS_FIRE6  (1L<<21)
#define JS_FIRE7  (1L<<22)
#define JS_FIRE8  (1L<<23)

#define JS_RED    (1L<<16)         /* CD32 buttons here */
#define JS_BLUE   (1L<<17)
#define JS_PLAY   (1L<<18)
#define JS_RWD    (1L<<19)
#define JS_FFW    (1L<<20)
#define JS_GREEN  (1L<<21)
#define JS_YELLOW (1L<<22)

#define JB_FIRE1  (1L<<16)         /* For the ZBXY style return type */
#define JB_FIRE2  (1L<<17)         /*  (analog joysticks) */
#define JB_FIRE3  (1L<<18)

#define MB_LMB    JB_FIRE1         /* Mouse button flags returned from */
#define MB_RMB    JB_FIRE2         /*  ReadMouse(), in ZBXY format */
#define MB_MMB    JB_FIRE3

/* Joyport specifications for calling ReadJoyStick/Mouse/JoyPad...() */

#define JPORT1    0*2
#define JPORT2    1*2
#define JPORT3    2*2
#define JPORT4    3*2

struct JoyData {
  WORD  XChange;
  WORD  YChange;
  WORD  ZChange;
  UWORD Buttons;
};

#define JD_FIRE1  0          ;Standard Fire Button (1) - LMB.
#define JD_FIRE2  1          ;Standard Fire Button (2) - RMB.
#define JD_FIRE3  2          ;Standard Fire Button (3) - MMB.
#define JD_FIRE4  3
#define JD_FIRE5  4
#define JD_FIRE6  5
#define JD_FIRE7  6
#define JD_FIRE8  7
#define JD_LMB    JD_FIRE1
#define JD_RMB    JD_FIRE2
#define JD_MMB    JD_FIRE2

/****************************************************************************
** GPI ID numbers
*/

#define GPI_SCREENS  0
#define GPI_BLITTER  4
#define GPI_SOUND    8
#define GPI_NETWORK  12
#define GPI_VECTORS  16
#define GPI_FIREBALL 20
#define GPI_MOVIE    24
#define GPI_CARDS    28
#define GPI_TEXT     32
#define GPI_OBJECTS  36
#define GPI_ANIM     40

/***************************************************************************
** Bob Structure.
*/

#define BBV1 ((ID_BOB<<16)|00)
#define MBV1 ((ID_MBOB<<16)|00)

struct Framelist { /* Standard Framelist layout if pointing to bobs */
  WORD GFX_XCoord; /* contained in a Picture structure. */
  WORD GFX_YCoord;
  WORD MSK_XCoord;
  WORD MSK_YCoord;
};

struct Directlist { /* Special Framelist layout for pointing directly */
  APTR Graphic;     /* to the raw address of a bob (use DIRECT flag). */
  APTR Mask;
};

struct   Bob {
  ULONG  VERSION;          /* Structure version */
  APTR   Stats;            /* Private */
  APTR   GfxData;          /* Pointer to graphics source */
  APTR   MaskData;         /* Pointer to mask source */
  UWORD  Frame;            /* Current frame */
  APTR   Framelist;        /* Pointer to frame list */
  WORD   SrcWidth;         /* Source Page Width in bytes */
  UWORD  Width;            /* Width in pixels */
  UWORD  ByteWidth;        /* Width in bytes */
  UWORD  Height;           /* Height in pixels */
  WORD   XCoord;           /* To X pixel */
  WORD   YCoord;           /* To Y pixel */
  UWORD  ClipLX;           /* Left X border in bytes (0/8) */
  UWORD  ClipTY;           /* Top Y border (0) */
  UWORD  ClipRX;           /* Right X border in bytes (320/8) */
  UWORD  ClipBY;           /* Bottom Y border (256) */
  UWORD  FPlane;           /* 1st Plane to blit to (planar only) */
  UWORD  Planes;           /* Amount of planes */
  ULONG  PlaneSize;        /* Size of source plane (planar only) */
  ULONG  Attrib;           /* Attributes like CLIP and MASK */
  APTR   PictureTags;      /* Pointer to picture tags */
};

#define BBA_GfxData      (8|TAPTR)
#define BBA_MaskData    (12|TAPTR)
#define BBA_Frame       (16|TWORD)
#define BBA_Framelist   (18|TAPTR)
#define BBA_SrcWidth    (22|TWORD)
#define BBA_Width       (24|TWORD)
#define BBA_ByteWidth   (26|TWORD)
#define BBA_Height      (28|TWORD)
#define BBA_XCoord      (30|TWORD)
#define BBA_YCoord      (32|TWORD)
#define BBA_ClipLX      (34|TWORD)
#define BBA_ClipTY      (36|TWORD)
#define BBA_ClipRX      (38|TWORD)
#define BBA_ClipBY      (40|TWORD)
#define BBA_FPlane      (42|TWORD)
#define BBA_Planes      (44|TWORD)
#define BBA_PlaneSize   (46|TLONG)
#define BBA_Attrib      (50|TLONG)
#define BBA_PictureTags (54|TAPTR)

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

struct MBob {
  ULONG  VERSION;          /* Structure version */
  APTR   Stats;            /* Private */
  APTR   GfxData;          /* Pointer to graphics source */
  APTR   MaskData;         /* Pointer to mask source */
  UWORD  AmtEntries;       /* Amount of entries in the list */
  APTR   Framelist;        /* Pointer to frame list */
  WORD   SrcWidth;         /* Source Page Width in bytes */
  UWORD  Width;            /* Width in pixels (optional) */
  UWORD  ByteWidth;        /* Width in bytes */
  UWORD  Height;           /* Height in pixels */
  APTR   EntryList;        /* Pointer to entry list */
  UWORD  ClipLX;           /* Left X border in bytes (0/8) */
  UWORD  ClipTY;           /* Top Y border (0) */
  UWORD  ClipRX;           /* Right X border in bytes (320/8) */
  UWORD  ClipBY;           /* Bottom Y border (256) */
  UWORD  FPlane;           /* 1st Plane to blit to (planar only) */
  UWORD  Planes;           /* Amount of planes */
  ULONG  PlaneSize;        /* Size of source plane (planar only) */
  ULONG  Attrib;           /* Attributes like CLIP and MASK */
  APTR   PictureTags;      /* Pointer to picture origin (optional) */
  UWORD  EntrySize;        /* Entry size (sizeof(struct MBEntry)) */
};

#define MBA_GfxData      (8|TAPTR)
#define MBA_MaskData    (12|TAPTR)
#define MBA_AmtEntries  (16|TWORD)
#define MBA_Framelist   (18|TAPTR)
#define MBA_SrcWidth    (22|TWORD)
#define MBA_Width       (24|TWORD)
#define MBA_ByteWidth   (26|TWORD)
#define MBA_Height      (28|TWORD)
#define MBA_EntryList   (30|TWORD)
#define MBA_ClipLX      (34|TWORD)
#define MBA_ClipTY      (36|TWORD)
#define MBA_ClipRX      (38|TWORD)
#define MBA_ClipBY      (40|TWORD)
#define MBA_FPlane      (42|TWORD)
#define MBA_Planes      (44|TWORD)
#define MBA_PlaneSize   (46|TLONG)
#define MBA_Attrib      (50|TLONG)
#define MBA_PictureTags (54|TAPTR)
#define MBA_EntrySize   (58|TWORD)

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

#define MBE_SIZEOF sizeof(struct BobEntry)

/* Bob Attributes (Bob.Attrib) */

#define CLIP      0x00000001 /* Allow border clipping */
#define MASK      0x00000002 /* Allow masking */
#define STILL     0x00000004 /* This bob is not moving */
#define CLEAR     0x00000008 /* Allow automatic clearing */
#define RESTORE   0x00000010 /* Allow automatic background restore */
#define DIRECT    0x00000020 /* Using direct graphics and mask pointers */
#define FILLMASK  0x00000040 /* Fill any holes in the mask on generation */
#define GENMASKS  0x00000082 /* Create and use masks for drawing this bob */
#define CLRMASK   0x00000100 /* Use masks when clearing */
#define CLRNOMASK 0x00000000 /* Do not use masks when clearing (default) */

#define GENMASK 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 structure
*/

#define MPV1 ((ID_MAP<<16)|00)

struct Map {
  ULONG  VERSION;          /* The structure version, MPV1 */
  ULONG  Stats;            /* Private */
  UWORD  Buffer;           /* Destination buffer */
  UWORD  Number;           /* Map number to access for data */
  APTR   MapList;          /* Pointer to the map datalist */
  UWORD  Width;            /* Total width of map */
  UWORD  Height;           /* Total height of map */
  UWORD  XStart;           /* Get block data starting from X [byte] */
  UWORD  YStart;           /* Get block data starting from Y */
  UWORD  EntrySize;        /* Byte/Word/Long */
  ULONG  EntryMask;        /* For special cases */
  UWORD  TileWidth;        /* The width/8 of each tile (bytes) */
  UWORD  TileHeight;       /* The height of each tile */
  UWORD  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
