home *** CD-ROM | disk | FTP | other *** search
/ World of Graphics / WOGRAPH.BIN / 480.DEBUG.H < prev    next >
C/C++ Source or Header  |  1992-07-30  |  6KB  |  184 lines

  1. /****************************************************************************
  2. *
  3. *                    Copyright (C) 1991 Kendall Bennett.
  4. *                            All rights reserved.
  5. *
  6. * Filename:        $RCSfile: debug.h $
  7. * Version:        $Revision: 1.7 $
  8. *
  9. * Language:        ANSI C
  10. * Environment:    any
  11. *
  12. * Description:    General header file for portable code.
  13. *
  14. * $Id: debug.h 1.7 1992/05/15 17:53:08 kjb Exp $
  15. *
  16. * Revision History:
  17. * -----------------
  18. *
  19. * $Log: debug.h $
  20. * Revision 1.7  1992/05/15  17:53:08  kjb
  21. * Modified far pointer macros.
  22. *
  23. * Revision 1.6  92/03/15  12:51:48  kjb
  24. * Added MK_FP macro and ushort typedef.
  25. * Revision 1.5  91/10/28  03:17:33  kjb
  26. * Ported to the Iris.
  27. * Revision 1.4  91/09/26  15:29:02  kjb
  28. * Added stuff for the SGI Iris 4D.
  29. * Revision 1.3  91/09/26  10:07:04  kjb
  30. * Added general typedef stuff.
  31. * Revision 1.2  91/09/03  18:19:14  ROOT_DOS
  32. * Added a few defines that are supplied by <dir.h> for UNIX compatibility.
  33. *
  34. * Revision 1.1  91/08/16  13:19:06  ROOT_DOS
  35. * Initial revision
  36. *
  37. ****************************************************************************/
  38.  
  39. #ifndef    __DEBUG_H
  40. #define    __DEBUG_H
  41.  
  42. #ifdef    DEBUG
  43. #        define D(x) x
  44. #else
  45. #        define D(x)
  46. #endif
  47.  
  48. #define    PRIVATE    static
  49. #define    PUBLIC
  50.  
  51. #ifdef     __MSDOS__                /* Compiling for MSDOS                    */
  52. #        define MS(x) x
  53. #        define UX(x)
  54. #        define IR(x)
  55. #        define _8086        /* We know we have an 8086 type processor    */
  56. #if defined(__COMPACT__) || defined(__LARGE__) || defined(__HUGE__)
  57. #        define LDATA
  58. #        define NULL    0L
  59. #else
  60. #        define NULL    0
  61. #endif
  62. #else    __MSDOS__
  63. #ifdef    __IRIS4D__                /* Compiling for the SGI Iris 4D        */
  64. #        define MS(x)
  65. #        define UX(x) x            /* The Iris is a UNIX machine            */
  66. #        define IR(x) x
  67. #        define O_BINARY 0        /* no binary input mode in UNIX open()    */
  68. #        define MAXFILE    255        /* These are defined in <dir.h>, but    */
  69. #        define MAXDIR    255        /* on UNIX machines, we just define        */
  70. #        define MAXPATH    255        /* them all to be the same size            */
  71. #        define far                /* Near and far do not exist under        */
  72. #        define near                /* UNIX or the Iris.                    */
  73. #        define NULL ((void *)0)
  74. #else    __IRIS4D__                /* Assume UNIX compilation                */
  75. #        define MS(x)
  76. #        define UX(x) x
  77. #        define IR(x)
  78. #        define O_BINARY 0        /* no binary input mode in UNIX open()    */
  79. #        define MAXFILE    255        /* These are defined in <dir.h>, but    */
  80. #        define MAXDIR    255        /* on UNIX machines, we just define        */
  81. #        define MAXPATH    255        /* them all to be the same size            */
  82. #        define far                /* Near and far do not exist under        */
  83. #        define near                /* UNIX or the Iris.                    */
  84. #        define NULL ((void *)0)
  85. #endif    __IRIS4D__
  86. #endif    __MSDOS__
  87.  
  88. /****************************************************************************
  89. *
  90. *    SEG(p)        Evaluates to the segment portion of an 8086 address.
  91. *    OFF(p)        Evaluates to the offset portion of an 8086 address.
  92. *    FP(s,o)        Creates a far pointer given a segment offset pair.
  93. *    PHYS(p)        Evaluates to a long holding a physical address
  94. *
  95. ****************************************************************************/
  96.  
  97. #ifdef    _8086
  98. #        define SEG(p)    ( ((unsigned *)&(void far *)(p))[1] )
  99. #        define OFF(p)    ( (unsigned)(p) )
  100. #        define FP(s,o)    ( (void far *)( ((unsigned long)s << 16) +    \
  101.                           (unsigned long)o ))
  102. #        define PHYS(p)    ( (unsigned long)OFF(p) +                        \
  103.                           ((unsigned long)SEG(p) << 4))
  104. #else
  105. #        define PHYS(p)     (p)
  106. #endif    _8086
  107.  
  108. /****************************************************************************
  109. *
  110. *    NUMELE(array)        Evaluates to the array size in elements
  111. *    LASTELE(array)        Evaluates to a pointer to the last element
  112. *    INBOUNDS(array,p)    Evaluates to true if p points into the array
  113. *    RANGE(a,b,c)        Evaluates to true if a <= b <= c
  114. *    max(a,b)            Evaluates to a or b, whichever is larger
  115. *    min(a,b)            Evaluates to a or b, whichever is smaller
  116. *    ABS(a)                Evaluates to the absolute value of a
  117. *    NBITS(type)            Returns the number of bits in a variable of the
  118. *                        indicated type
  119. *    MAXINT                Evaluates to the value of the largest signed integer
  120. *
  121. ****************************************************************************/
  122.  
  123. #define    NUMELE(a)        (sizeof(a)/sizeof(*(a)))
  124. #define    LASTELE(a)        ((a) + (NUMELE(a)-1))
  125. #ifdef    LDATA
  126. #define    TOOHIGH(a,p)    ((long)PHYS(p) - (long)PHYS(a) > (long)(NUMELE(a)-1))
  127. #define    TOOLOW(a,p)        ((long)PHYS(p) - (long)PHYS(a) < 0)
  128. #else
  129. #define    TOOHIGH(a,p)    ((long)(p) - (long)(a) > (long)(NUMELE(a)-1))
  130. #define    TOOLOW(a,p)        ((long)(p) - (long)(a) < 0)
  131. #endif
  132. #define    INBOUNDS(a,p)    ( ! (TOOHIGH(a,p) || TOOLOW(a,p)) )
  133.  
  134. #define    _IS(t,x) (((t)1 << (x)) != 0)    /* Evaluates true if the width of */
  135.                                         /* variable of type t is < x.      */
  136.                                         /* The != 0 assures that the      */
  137.                                         /* answer is 1 or 0                  */
  138.  
  139. #define    NBITS(t) (4 * (1 + _IS(t,4) + _IS(t,8) + _IS(t,12) + _IS(t,16) \
  140.                          + _IS(t,20) + _IS(t,24) + _IS(t,28) + _IS(t,32)))
  141.  
  142. #define    MAXINT            (((unsigned)~0) >> 1)
  143.  
  144. #ifndef    MAX
  145. #        define MAX(a,b)    ( ((a) > (b)) ? (a) : (b))
  146. #endif
  147. #ifndef    MIN
  148. #        define MIN(a,b) ( ((a) < (b)) ? (a) : (b))
  149. #endif
  150. #ifndef    ABS
  151. #        define ABS(a)    ((a) >= 0 ? (a) : -(a))
  152. #endif
  153.  
  154. #define    RANGE(a,b,c)    ( (a) <= (b) && (b) <= (c) )
  155.  
  156. /* General typedefs    */
  157.  
  158. #ifndef    __GENDEFS
  159. #define    __GENDEFS
  160. typedef    void            *ptr;
  161. typedef void near        *nearptr;
  162. typedef    void far        *farptr;
  163. typedef    unsigned char    uchar;
  164. typedef    unsigned short    ushort;
  165. typedef    unsigned int    uint;
  166. typedef    unsigned long    ulong;
  167. typedef    int                bool;
  168. #endif    __GENDEFS
  169.  
  170. /* Boolean truth values */
  171.  
  172. #define    false        0
  173. #define    true        1
  174. #define    FALSE        0
  175. #define    TRUE        1
  176. #define    NO            0
  177. #define    YES            1
  178.  
  179. #endif    __DEBUG_H
  180.