#ifndef GAMES_GMS_H
#define GAMES_GMS_H TRUE

/*
**   $VER: games.h 0.4 (11.10.96)
**   Includes Release xx.xx
**
**   General include file for programs using the Games Master System.
**
**   (C) Copyright 1996 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

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

#define LISTSTART   "LIST"
#define SKIPENTRY   0
#define LISTEND     -1
#define ENDLIST     -1
#define TAGEND      0

/****************************************************************************
**
** 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 */

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

#define JT_SWITCH 0
#define JT_ZBXY   1

#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<<6)          /* Fire Buttons */
#define JS_FIRE2  (1L<<7)          /* For 2 button joysticks */
#define JS_FIRE3  (1L<<11)         /* For 3 button joysticks */

#define JS_RED    (1L<<6)
#define JS_BLUE   (1L<<7)
#define JS_PLAY   (1L<<8)          /* CD32 buttons here */
#define JS_RWD    (1L<<9)
#define JS_FFW    (1L<<10)
#define JS_GREEN  (1L<<11)
#define JS_YELLOW (1L<<12)

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

#define MB_LMB    (1L<<16)         /* Mouse button flags returned from */
#define MB_RMB    (1L<<17)         /*  Read_Mouse(), in ZBXY format */
#define MB_MMB    (1L<<18)

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

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

/****************************************************************************
** 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_DEBUG    20
#define GPI_ANIM     24
#define GPI_REKO     28
#define GPI_TEXT     32

/****************************************************************************
**                       Standard screen structure
*/

#define GSV1 0x47530000

  struct   GameScreen
    {
    ULONG  VERSION;              /* Structure version - "GSV1" */
    APTR   Stats;                /* Private */
    APTR   MemPtr1;              /* Ptr to screen 1 */
    APTR   MemPtr2;              /* Ptr to screen 2 (double buffer) */
    APTR   MemPtr3;              /* Ptr to screen 3 (triple buffer) */
    APTR   ScreenLink;           /* Ptr to a linked screen */
    APTR   Palette;              /* Ptr to the screen palette */
    APTR   RasterList;           /* Ptr to a rasterlist */
    ULONG  AmtColours;           /* The amount of colours in the palette. */
    UWORD  ScrWidth;             /* The width of the visible screen */
    UWORD  ScrHeight;            /* The height of the visible screen */
    UWORD  PicWidth;             /* The width of the entire screen */
    UWORD  PicHeight;            /* The height of the entire screen */
    UWORD  Planes;               /* The amount of planes in da screen */
    WORD   ScrXOffset;           /* Hardware co-ordinate for TOS */
    WORD   ScrYOffset;           /* Hardware co-ordinate for LOS */
    WORD   PicXOffset;           /* Offset of the horizontal axis */
    WORD   PicYOffset;           /* Offset of the vertical axis */
    ULONG  ScrAttrib;            /* Special Attributes are? */
    UWORD  ScrMode;              /* What screen mode is it? */
    UBYTE  ScrType;              /* Interleaved/Planar/Chunky? */
    UBYTE  Displayed;            /* Private */
    };

/* Screen Buffer names, these are asked for in the blitter functions */

#define BUFFER1  8
#define BUFFER2  12
#define BUFFER3  16

/* SCREEN TYPES (ScrType) */

#define INTERLEAVED  1              /* These are actual numbers */
#define PLANAR       2              /* rather than bits */
#define CHUNKY       3
#define CHUNKY2      4
#define TRUECOLOUR   5

/* SCREEN ATTRIBUTES (ScrAttrib) */

#define DBLBUFFER  0x00000001       /* For double buffering */
#define TPLBUFFER  0x00000002       /* Triple buffering!! */
#define PLAYFIELD  0x00000004       /* Set if it's part of a playfield */
#define HSCROLL    0x00000008       /* Gotta set this to do scrolling */
#define VSCROLL    0x00000010       /* For vertical scrolling */
#define SPRITES    0x00000020       /* Set this if you want sprites */
#define HBUFFER    0x00000040       /* Create a buffer for horiz scrolling */
#define BLKBDR     0x00000100       /* Gives a blackborder on AGA machines */
#define NOSPRBDR   0x00000200       /* For putting sprites in the border */

/* SCREEN MODES (ScrMode) */

#define LORES      0x0000           /* Low resolution (default) */
#define HIRES      0x0001           /* High resolution */
#define SHIRES     0x0002           /* Super-High resolution */
#define INTERLACED 0x0004           /* Interlaced */
#define EXTRAHB    0x0010           /* Extra Half-Brite */
#define HAM        0x0040           /* For HAM mode */
#define COL12BIT   0x0080           /* 12 Bit colours */
#define COL24BIT   0x0000           /* 24 Bit colours (default) */

/* Screen Attribute tags */

#define TAGS 0x54414753

#define TBYTE 0
#define TWORD (1L<<30)
#define TLONG (1L<<31)

#define GSA_VERSION     (00|TLONG)
#define GSA_MemPtr1     (04|TLONG)
#define GSA_MemPtr2     (08|TLONG)
#define GSA_MemPtr3     (12|TLONG)
#define GSA_ScreenLink  (16|TLONG)
#define GSA_Palette     (20|TLONG)
#define GSA_RasterList  (24|TLONG)
#define GSA_AmtColours  (28|TLONG)
#define GSA_ScrWidth    (32|TWORD)
#define GSA_ScrHeight   (34|TWORD)
#define GSA_PicWidth    (36|TWORD)
#define GSA_PicHeight   (38|TWORD)
#define GSA_Planes      (40|TWORD)
#define GSA_ScrXOffset  (42|TWORD)
#define GSA_ScrYOffset  (44|TWORD)
#define GSA_PicXOffset  (46|TWORD)
#define GSA_PicYOffset  (48|TWORD)
#define GSA_ScrAttrib   (50|TLONG)
#define GSA_ScrMode     (54|TWORD)
#define GSA_ScrType     (56|TBYTE)

/****************************************************************************
**                 Raster/Copper commands for RasterLists.
**
**     Example of initialising a 24 bit colourlist:
**
**     LONG RasterList[] = {
**          COL24LIST(0,1,0,&ColourList),
**          RASTEND
**     };
**
** COL12      (ColourNumber,0xRGB)
** COL24      (ColourNumber,0xRRGGBB)
** COL12LIST  (StartLine,Skip,Colour,(&ColourList)
** COL24LIST  (StartLine,SKip,Colour,(&ColourList)
** SPRITE     (SpriteStruct)
** SCROLL     (Fields,PixelOffset0-16,PixelQuarterOffset 1-4)
** FLOOD      ()
** REPOINT    (&BitplanePtr)
** MIRROR     ()
** NEWPALETTE (ColStart,AmtCols,&Palette)
** WAITLINE   (Line)
** RASTEND    ()
**
** Warn: With colour related commands you must use the same amount of colour
** bits as specified in your GameScreen structure (COL12BIT or COL24BIT)
*/

#define COL12(a,b)         (00<<16)|(a),(b<<16),0
#define COL24(a,b)         (02<<16),(a),(b),0
#define COL12LIST(a,b,c,d) (04<<16)|(a),(b<<16)|(c),(LONG)(d),0
#define COL24LIST(a,b,c,d) (06<<16)|(a),(b<<16)|(c),(LONG)(d),0
#define SPRITE(a)          (08<<16),(a),0
#define SCROLL(a,b,c)      (10<<16)|(a),(b<<16)|(c),0
#define FSCROLL(a,b,c,d)   (12<<16)|(a),(b<<16)|(c),(d<<16),0
#define FLOOD              (14<<16),0
#define REPOINT(a)         (16<<16),(LONG)(a),0
#define MIRROR             (18<<16),0
#define NEWPALETTE(a,b,c)  (20<<16),(a),(b),(LONG)(c),0
#define WAITLINE(a)        (22<<16)|(a),0
#define RASTEND            0xffffffff

/***************************************************************************
** Sprite Structure.
*/

#define SPV1 0x53500000

  struct Sprite
   {
   ULONG VERSION;
   APTR  Stats;
   UWORD Number;         /* Bank number to access */
   APTR  Data;           /* Pointer to Sprite graphic */
   WORD  XPos;           /* X position */
   WORD  YPos;           /* Y position */
   UWORD Frame;          /* Frame number */
   UWORD Width;          /* Width in pixels */
   UWORD Height;         /* Height in pixels */
   UWORD AmtColours;     /* 4 or 16 */
   UWORD ColStart;       /* Colour bank to access, increments of 16 */
   UWORD Planes;         /* Amount of planes per bank */
   UWORD ScrMode;        /* HiRes/LoRes/SHiRes */
   UWORD FieldPriority;  /* Field position in relation to playfields */
   UWORD Attrib;         /* Attributes (XLONG) */
   };

#define XLONG   0x0001

/***************************************************************************
** BOB Structure.
*/

#define BBV1 0x42420000

  struct BOB
   {
   ULONG  VERSION;          /* Structure version */
   APTR   Stats;            /* Private */
   UWORD  Buffer;           /* Buffer1/Buffer2/Buffer3 */
   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 bytes */
   UWORD  Height;           /* Height in pixels */
   WORD   XPos;             /* To X pixel */
   WORD   YPos;             /* 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) */
   UWORD  Attrib;           /* Attributes like CLIP and MASK */
   struct Picture *Picture; /* Pointer to a picture struct */
   };

/* BOB Drawing Methods */

#define CLIP    0x0001  /* Allow border clipping */
#define MASK    0x0002  /* Allow masking */
#define STILL   0x0004  /* This bob is not moving */
#define CLEAR   0x0008  /* Allow automatic clearing */
#define RESTORE 0x0010  /* Allow automatic background restore */

/****************************************************************************
** Map structure
*/

#define MPV1 'M','P',0,0,0

  struct Map
   {
   char   VERSION[4];       /* 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
