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

  global.h

      This include file is used by both the OS502 and 
      the Z502 Simulator.

        Revision History:
                1.0 August 1990:        first release
                1.1 Jan    1991:        Additional disks added
                1.3 July   1992:        Make as many defines as possible
                                          into shorts since PCs are happier.
                1.6 June   1995:        Minor changes
*********************************************************************/

#define         CURRENT_REL                     "1.6"
#define         FALSE                           (short)0
#define         TRUE                            (short)1

#define         PHYS_MEM_PGS                    (short)64
#define         PGSIZE                          (short)16
#define         PGBITS                          (short)4
#define         VIRTUAL_MEM_PGS                 1024
#define         VMEMPGBITS                      10
#define         MEMSIZE                         PHYS_MEM_PGS * PGSIZE

        /* Meaning of locations in a page table entry          */

#define         PTBL_VALID_BIT                  0x8000
#define         PTBL_MODIFIED_BIT               0x4000
#define         PTBL_REFERENCED_BIT             0x2000
#define         PTBL_PHYS_PG_NO                 0x0FFF

        /*  The maximum number of disks we will support:        */

#define         MAX_NUMBER_OF_DISKS             (short)12

        /*  STAT_VECTOR is a two dimensional array.  The first 
            dimension can take on values:                     */

#define         SV_ACTIVE                       (short)0
#define         SV_VALUE                        (short)1

/*      The second dimension of STAT_VECTOR is defined by these
        values of traps, faults and interrupts:                 */

        /* Definition of trap types.                            */

#define         SOFTWARE_TRAP                   (short)0

        /* Definition of fault types.                           */

#define         CPU_ERROR                       (short)1
#define         INVALID_MEMORY                  (short)2
#define         PRIVILEGED_INSTRUCTION          (short)3


        /* Definition of interrupt types.                       */

#define         TIMER_INTERRUPT                 (short)4
#define         DISK_INTERRUPT                  (short)5
#define         DISK_INTERRUPT_DISK1            (short)5
#define         DISK_INTERRUPT_DISK2            (short)6
/*      ... we could define other explicit names here           */

#define         LARGEST_STAT_VECTOR_INDEX       DISK_INTERRUPT + \
                                                MAX_NUMBER_OF_DISKS - 1


/*      Definition of the TO_VECTOR array.  The TO_VECTOR
        contains pointers to the routines which will handle
        hardware exceptions.  The pointers are accessed with
        these indices:                                          */

#define         TO_VECTOR_INT_HANDLER_ADDR              (short)0
#define         TO_VECTOR_FAULT_HANDLER_ADDR            (short)1
#define         TO_VECTOR_TRAP_HANDLER_ADDR             (short)2
#define         TO_VECTOR_TYPES                         (short)3

        /* Definition of Error codes.                           */

#define         ERR_SUCCESS                             0L
#define         ERR_BAD_PARAM                           1L
#define         ERR_NO_PREVIOUS_WRITE                   2L
#define         ERR_ILLEGAL_ADDRESS                     3L
#define         ERR_DISK_IN_USE                         4L
#define         ERR_Z502_INTERNAL_BUG                   20L
#define         ERR_OS502_GENERATED_BUG                 21L

        /* Miscellaneous                                        */

#define         NUM_CYLINDERS                           (short)100
#define         NUM_SECTORS                              (short)16
        
#define         SWITCH_CONTEXT_KILL_MODE                (short)0
#define         SWITCH_CONTEXT_SAVE_MODE                (short)1

#define         USER_MODE                               (short)0
#define         KERNEL_MODE                             (short)1

        /*      These are Portability enhancements              */

typedef         long                    INT32;
typedef         unsigned long           UINT32;
typedef         short                   INT16;
typedef         unsigned short          UINT16;
typedef         unsigned char           BOOL;

typedef         union
    {
    void        *PTR;
    INT32       VAL;
} Z502_ARG;
