#ifndef _MDEP_H_
#define	_MDEP_H_


FILE *debugf;

#define CARRYBIT (1<<12)
#define A0BIT 1

/* Contorted sign-extend macro only evaluates its parameter once, and
   executes in two shifts.  This is far more efficient that any other
   sign extend procedure I can think of, and relatively safe */

#define SEX(twelvebit) ((((int)twelvebit) << (int)((sizeof(int)*8)-12)) \
                          >> (int)((sizeof(int)*8)-12))


/* Mouse values currently sampled once per frame and set in WAI code.
   This is not ideal. */
/* Define new types for the c-cpu emulator
 */

#define SW_ABORT           0x100          /* for ioSwitches */
#define SW_COIN            0x080          /* for ioSwitches */

#define UINT32 unsigned int
#define UINT16 unsigned short int
#define UINT8  unsigned char

#define INT32  signed int
#define INT16  signed short int
#define INT8   signed char

static UINT8 bBailOut = FALSE;

static UINT8 rom[0x2000] =
#include "tailgunner-data.c"    /* Preload whole eprom here */

static UINT8 ccpu_jmi_dip = 0;  /* as set by cineSetJMI */
static UINT8 ccpu_msize = 0;    /* as set by cineSetMSize */
static UINT8 ccpu_monitor = 0;  /* as set by cineSetMonitor */

/* -- Context information ends.
 */

UINT8 bFlipX;
UINT8 bFlipY;
UINT8 bSwapXY;
UINT8 bOverlay;

UINT16 ioSwitches = 0xFF;  /* high values for non-triggered switches */
UINT16 ioInputs = 0;
UINT8 ioOutputs = 0;

UINT16 RCvgColour = 0;

INT16 JoyX;
INT16 JoyY;
UINT8 bNewFrame;

INT32 sdwGameXSize;
INT32 sdwGameYSize;
INT32 sdwXOffset = 0;
INT32 sdwYOffset = 0;

/* Now the same information for Graham's machine */


/* Define new types for the c-cpu emulator */
typedef short unsigned int CINEWORD;      /* 12bits on the C-CPU */
typedef unsigned char      CINEBYTE;      /* 8 (or less) bits on the C-CPU */
typedef short signed int   CINESWORD;     /* 12bits on the C-CPU */
typedef signed char        CINESBYTE;     /* 8 (or less) bits on the C-CPU */

typedef unsigned long int  CINELONG;

typedef enum
{
	state_A = 0,
	state_AA,
	state_B,
	state_BB
} CINESTATE;

  /* C-CPU context information begins --  */
           CINEWORD  register_PC = 0;  /* C-CPU registers; program counter */
  /*register*/ CINEWORD  register_A = 0;   /* A-Register (accumulator) */
  /*register*/ CINEWORD  register_B = 0;   /* B-Register (accumulator) */
           CINEWORD /*CINEBYTE*/  register_I = 0;   /* I-Register (last access RAM location) */
           CINEWORD  register_J = 0;   /* J-Register (target address for JMP opcodes) */
           CINEWORD /*CINEBYTE*/  register_P = 0;   /* Page-Register (4 bits, shifts to high short nibble for code, hight byte nibble for ram) */
           CINEWORD  FromX = 0;        /* X-Register (start of a vector) */
           CINEWORD  FromY = 0;        /* Y-Register (start of a vector) */
           CINEWORD  register_T = 0;   /* T-Register (vector draw length timer) */
           CINEWORD  flag_C = 0;       /* C-CPU flags; carry. Is word sized, instead
                                        * of CINEBYTE, so we can do direct assignment
                                        * and then change to BYTE during inspection.
                                        */

           CINEWORD  cmp_old = 0;      /* last accumulator value */
           CINEWORD  cmp_new = 0;      /* new accumulator value */
           CINEWORD/*CINEBYTE*/  acc_a0 = 0;       /* bit0 of A-reg at last accumulator access */

           CINESTATE state = state_A;  /* C-CPU state machine current state */
           CINEWORD  ram[256];         /* C-CPU ram (for all pages) */

#ifdef NEVER

           int       ccpu_jmi_dip = 0; /* as set by cineSetJMI  Use EI, not MI */
           int       ccpu_msize = 0;   /* as set by cineSetMSize */
           int       ccpu_monitor = 0; /* as set by cineSetMonitor */

           int bNewFrame = 0;
           int bFlipX = 0;
           int bFlipY = 0;
           int bSwapXY = 0;
           int sdwGameXSize = 0;
           int sdwGameYSize = 0;
           int sdwXOffset = 0;
           int sdwYOffset = 0;
#endif
           CINEWORD  vgColour = 0;
           CINEBYTE  vgShiftLength = 0;   /* number of shifts loaded into length reg */
           int bailOut = 0;
           int       ccpu_ICount = 0;  /* */

  /* -- Context information ends. */


/* debug junk
 */

int ccpudebug = 0; /* default is off */

/***
const int xmousethresh = 2;
const int ymousethresh = 2;
static int mickeyx = 0;
static int mickeyy = 0;
static int mousecode = 0;
***/
static int Frames = 0;

/* INP $8 ? */
#define IO_START   0x80

/* INP $7 ? */
#define IO_SHIELDS 0x40

#define IO_FIRE    0x20
#define IO_DOWN    0x10
#define IO_UP      0x08
#define IO_LEFT    0x04
#define IO_RIGHT   0x02

#define IO_COIN   0x80

#define IO_KNOWNBITS (IO_START | IO_SHIELDS | IO_FIRE | IO_DOWN | IO_LEFT | IO_RIGHT)

/* initial value of shields (on a DIP) */
#define SW_SHIELDS80 ((1<<1) | (1<<4) | (1<<5))
#define SW_SHIELDS40 ((0<<1) | (1<<4) | (1<<5))
#define SW_SHIELDS15 ((0<<1) | (0<<4) | (0<<5))
#define SW_SHIELDS    SW_SHIELDS80

static int startflag = IO_START;
static int coinflag  = 0;
static int shieldsflag = IO_SHIELDS;   /* Whether shields are up (mouse or key) */
static int fireflag = IO_FIRE;



#endif

