#ifndef GMS_GAMES_H
#define GMS_GAMES_H TRUE

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

#ifndef GMS_TYPES_H
#include <games/types.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_BLIT_H
#include <games/blit.h>
#endif

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

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

#define GMSVersion  0
#define GMSRevision 7

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

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

#define JMP_AMIGA 0

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

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

#define TAGS_BOB        ((TG<<16)|ID_BOB)
#define TAGS_MBOB       ((TG<<16)|ID_MBOB)
#define TAGS_GAMESCREEN ((TG<<16)|ID_GAMESCREEN)
#define TAGS_SOUND      ((TG<<16)|ID_SOUND)
#define TAGS_PICTURE    ((TG<<16)|ID_PICTURE)
#define TAGS_CARDS      ((TG<<16)|ID_CARDS)
#define TAGS_ANIM       ((TG<<16)|ID_ANIM)
#define TAGS_MAP        ((TG<<16)|ID_MAP)
#define TAGS_MOVIE      ((TG<<16)|ID_MOVIE)
#define TAGS_SPRITE     ((TG<<16)|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_STRUCT       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 */
#define ERR_ARGS        19  /* Invalid arguments passed to function */

/****************************************************************************
** 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_OLDFILE 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_NEWFILE (1L<<6)
#define FL_READ    ((0)|FL_OLDFILE)

#define FL_PACK   FL_UNPACK
#define FL_SMART  FL_FIND|FL_UNPACK

struct File {
  UWORD ID;        /* ID_FILE */
  UWORD Version;   /* 00 */
  ULONG Stats;     /* Private */
  BYTE  *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 */

  /* Private fields start now */

  ULONG Handle;
  ULONG Key;
  ULONG LastPos;
};

/****************************************************************************
** 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_MASTER    0  /* Master   */
#define GPI_BLITTER   4  /* Standard */
#define GPI_SOUND     8  /* Standard */
#define GPI_SCREENS  12  /* Standard */
#define GPI_VECTORS  16  /* Extra    */
#define GPI_FIREBALL 20  /* Extra    */
#define GPI_ANIM     24  /* Extra    */
#define GPI_CARDS    28  /* Extra    */
#define GPI_TEXT     32  /* Extra    */
#define GPI_OBJECTS  36  /* AutoLoad */
#define GPI_NETWORK  40  /* Extra    */

#endif
