//
//  Copyright © 1997,1998 Forest Edge Software, see License.txt for Rights
//
//  Program:    VAX Emulator, a "Virtual VAX"
//
//  Author:     Tom Cole
//
//  Module:     arch.h
//
//  Purpose:    This header file definitions for architectural features
//      of the host environment.
//
//  History:    05/18/99    Initial creation, pulled from vax.pch
//
//              09/27/99    Added initial support for TRU64 based on input and
//                          testing from Hartmut Becker <becker@rto.dec.com>
//                          and Sergey Tikhonov <tsv@excom.spb.su>
//
//              10/03/99    Okay, it seems that there's no benefit in being a
//                          truly 64-bit system, emulating a VAX.  So I'm converting
//                          all long's to an explicit definition of a 32-bit integer.
//
//                          It looks like the safe route is to use a local typedef of
//                          LONGWORD that matches what we are using.  Also, use QUADWORD to
//                          reflect a 64-bit integer.
//
//                          I WILL PROBABLY GET SOME OF THIS WRONG, SO PORTS MAY BE ROUGH
//                          FOR THE NEXT CYCLE!
//

/*
 *  This header file is typically included after the system headers
 *  from vax.pch.  This should set up the macro definitions, etc.
 *  for the box we are running on.  In the compilation mechanism
 *  for the port, specify the platform as a define on the command.
 *
 *  The "supported" platforms the system has been built for are:
 *
 *   MAC         MacOS
 *   MACHTEN     MachTen (BSD under MacOS)
 *   LINUXPPC    PowerPC-based Linux systems
 *   HPUX        HP-UX 10.20
 *   WIN         Windows 98 or Windows NT
 *   LINUX86     Intel-based Linux systems
 *   FREEBSD     Intel-based FreeBSD systems
 *   TRU64       Compaq's Unix for Alpha (64-bits!)
 *   VMS         Alpha (!) VMS
 */

#define UNKNOWN_ARCH 1

#if defined( MAC ) || defined( macintosh )
#ifndef MAC    /* CodeWarrior gives us "macintosh" */
#define MAC 1
#endif
#undef UNKNOWN_ARCH
#define BIGENDIAN   1
#endif



#ifdef VMS
#define BIGENDIAN   0
#undef UNKNOWN_ARCH
#endif

#ifdef  TRU64
#define BIGENDIAN   0
#undef UNKNOWN_ARCH
#define HAS64BITLONGS 1
#endif



#ifdef HPUX     
#define BIGENDIAN   1
#undef UNKNOWN_ARCH
#endif



#ifdef WIN
#define BIGENDIAN   0
#define INVERTEDLONGCHAR    0  /* VSS seems to want 0 here */
#undef UNKNOWN_ARCH
#endif



#ifdef FREEBSD
#define BIGENDIAN   0
#undef UNKNOWN_ARCH
#endif


#ifdef LINUX86
#define BIGENDIAN 0
#undef UNKNOWN_ARCH
#endif


#if defined( MACHTEN ) || defined( LINUXPPC )
#define BIGENDIAN 1
#undef UNKNOWN_ARCH
#endif

#ifdef HAS64BITLONGS
typedef long QUADWORD;
typedef int LONGWORD;
typedef unsigned int ULONGWORD;
#else

#ifdef WIN
typedef __int64 QUADWORD;
#else
typedef long long QUADWORD;
#endif

typedef long LONGWORD;
typedef unsigned long ULONGWORD;
#endif

#ifdef UNKNOWN_ARCH

#error Architecture not defined!
 
You must define an architecture in your build process to specify what build
environment and/or chip architecture you are using to build eVAX.  See the
file arch.h for more information.

#endif


/*
 *  Build additional definitions from the above definitions
 */

#if BIGENDIAN && !defined( INVERTEDLONGCHAR )

#define CHAR4( ch1, ch2, ch3, ch4 )   \
  ((( unsigned long ) ch1 << 24 ) |   \
   (( unsigned long ) ch2 << 16 ) |   \
   (( unsigned long ) ch3 << 8  ) |   \
   (( unsigned long ) ch4       ))

#else

#define CHAR4( ch1, ch2, ch3, ch4 )   \
  ((( unsigned long ) ch4 << 24 ) |   \
   (( unsigned long ) ch3 << 16 ) |   \
   (( unsigned long ) ch2 << 8  ) |   \
   (( unsigned long ) ch1       ))

#endif


