home *** CD-ROM | disk | FTP | other *** search
/ Dream 52 / Amiga_Dream_52.iso / RiscOS / APP / DEVS / FORTH / BEETLE / BEETLE.ZIP / Beetle / bportab.h < prev    next >
C/C++ Source or Header  |  1997-04-22  |  5KB  |  162 lines

  1. /* BPORTAB.H
  2.  
  3.     Vrsn  Date   Comment
  4.     ----|-------|--------------------------------------------------------------
  5.     0.00 07nov94
  6.     0.01 09nov94 ENDISM given an explicit type, as per specification, and
  7.                  ARSHIFT macro added.
  8.     0.02 18nov94 SYMMETRIC added, and definitions of floored division and
  9.                  remainder to work on symmetric division compilers (most of
  10.                  them!).
  11.     0.03 19nov94 Corrected MOD, and added ABS and SGN to do so.
  12.     0.04 25nov94 Added LINK macro to implement the LINK instruction.
  13.     0.05 01dec94 FLIP macro added to comply with debugged specification. ENDISM
  14.                  made dependent on whether BIG_ENDIAN is defined.
  15.     0.06 12jan95 Division macros changed so that both symmetric and floored
  16.                  division are provided in accordance with modified Beetle
  17.                  specification.
  18.     0.07 18jan95 SYMMETRIC changed to FLOORED, and made valueless. Added
  19.                  LRSHIFT, and #defines for BIG_ENDIAN, FLOORED and LRSHIFT.
  20.     0.08 05feb95 LINK changed to make it update SP so that the pointer can
  21.                  occupy multiple stack items as specified.
  22.     0.09 02apr95 Added GETCH.
  23.     0.10 03apr95 Added PUTCH and NEWL.
  24.     0.11 18apr95 Debugged LINK, DIV and SDIV.
  25.     0.12 06jun96 Moved machine-dependent parts to machine-specific header files
  26.          in bportab/. These are now included according to the machine
  27.          type symbol defined.
  28.     0.13 16jun96 Reduced number of machine types.
  29.     0.14 06jul96 Added missing include of bportab/unix.h.
  30.     0.15 30mar97 Removed nested comments.
  31.  
  32.     Reuben Thomas
  33.  
  34.  
  35.     Header for C Beetle defining the machine-dependent types and
  36.     definitions used in beetle.h.
  37.  
  38.     To allow C Beetle to compile on a system not mentioned here, a new machine-
  39.     specific header file must be written, modelled on those already existing,
  40.     and this file must be modified to recognise the new machine name. Commented-
  41.     out versions of the macros that must be defined are included below, as
  42.     suggestions. The file noecho.c allows the keypress primitives to be
  43.     implemented easily on many Unix systems.
  44.  
  45.     This header should never be #included, as it is automatically included by
  46.     beetle.h.
  47.  
  48.     Beetle will only work if the number representation is twos complement.
  49.  
  50. */
  51.  
  52.  
  53. #ifndef BEETLE_BPORTAB
  54. #define BEETLE_BPORTAB
  55.  
  56.  
  57. /* Include the machine-specific definitions. These are included based on the
  58.    system name symbol declared; those currently recognised are the symbols
  59.    defined by GCC on the corresponding machines.
  60.  
  61.    The current machine types recognised, and the corresponding symbol(s) that
  62.    should be defined for each type are:
  63.  
  64.    Machine type        Symbol(s)
  65.    ------------        ---------
  66.  
  67.    RISC OS        riscos
  68.    MSDOS        MSDOS
  69.    Atari TOS            atarist
  70.    Unix            unix    */
  71.  
  72. #ifdef riscos
  73.     #include "bportab/riscos.h"
  74. #endif
  75. #ifdef MSDOS
  76.     #include "bportab/msdos.h"
  77. #endif
  78. #ifdef atarist
  79.     #include "bportab/tos.h"
  80. #endif
  81. #ifdef unix
  82.     #include "bportab/unix.h"
  83. #endif
  84.  
  85.  
  86. /* Types required by CBeetle: BYTE should be an unsigned eight-bit quantity,
  87.    CELL a signed four-byte quantity, and UCELL an unsigned CELL. */
  88.  
  89. /* typedef unsigned char BYTE;  should work on most compilers */
  90. /* typedef signed long CELL;    ditto */
  91. /* typedef unsigned long UCELL; ditto */
  92.  
  93.  
  94. /* Define the value of ENDISM. This is fixed at compile-time, which seems
  95.    reasonable, as machines rarely change endianness while switched on!
  96.  
  97.    0 = Little-endian, 1 = Big-endian
  98.  
  99.    Assume big-endian if BIG_ENDIAN defined; little-endian otherwise. Also
  100.    define FLIP macro for byte addressing. */
  101.  
  102. /* #define BIG_ENDIAN */
  103.  
  104. #ifdef BIG_ENDIAN
  105.     #define ENDISM ((BYTE)1)
  106.     #define FLIP(addr) ((addr) ^ 3)
  107. #else
  108.     #define ENDISM ((BYTE)0)
  109.     #define FLIP(addr) (addr)
  110. #endif
  111.  
  112.  
  113. /* Define a macro for arithmetic right shifting (the ANSI standard does not
  114.    guarantee that this is possible with >>) */
  115.  
  116. /* #define LRSHIFT */
  117.  
  118. #ifdef LRSHIFT
  119.     #define ARSHIFT(n, p) ((n) = ((n) >> (p)) | (-((n) < 0) << (p)))
  120. #else
  121.     #define ARSHIFT(n, p) ((n) >>= (p))
  122. #endif
  123.  
  124.  
  125. /* Define division macros. FLOORED should be defined if the C compiler uses
  126.    floored division (and I've not found one that does yet). */
  127.  
  128. /* #define FLOORED */
  129.  
  130. #define ABS(x) ((x) >= 0 ? (x) : -(x))
  131. #define SGN(x) ((x) > 0 ? 1 : -1 )  /* not a proper sign function! */
  132.  
  133. #ifdef FLOORED
  134.     #define DIV(a, b) (a / b)
  135.     #define MOD(a, b, t) (a % b)
  136.     #define SDIV(a, b) ((a) / (b) + ((((a) ^ (b)) < 0) && ((a) % (b)) != 0))
  137.     #define SMOD(a, b, t) (t = (a) % (b), (((a) ^ (b)) >= 0 || t == 0)) ? t : \
  138.         SGN(a) * (ABS(b)-ABS(t))
  139. #else
  140.     #define DIV(a, b) ((a) / (b) - ((((a) ^ (b)) < 0) && ((a) % (b)) != 0))
  141.     #define MOD(a, b, t) (t = (a) % (b), (((a) ^ (b)) >= 0 || t == 0)) ? t : \
  142.         SGN(b) * (ABS(b)-ABS(t))
  143.     #define SDIV(a, b) (a / b)
  144.     #define SMOD(a, b, t) (a % b)
  145. #endif
  146.  
  147.  
  148. /* Define a macro to call the function pointed to by the top item(s) on Beetle's
  149.    data stack and increment the stack pointer to drop the pointer */
  150.  
  151. /* #define LINK SP++; (*(void (*)(void))*(SP - 1))() */
  152.  
  153.  
  154. /* Define a macro to return a keypress immediately and without echo */
  155.  
  156. /* #define GETCH ??? */
  157. /* #define PUTCH(c) ??? */
  158. /* #define NEWL ??? */
  159.  
  160.  
  161. #endif
  162.