home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / vol_300 / 328_02 / wsys.h < prev    next >
C/C++ Source or Header  |  1991-03-22  |  3KB  |  141 lines

  1. /*! WSYS.H
  2.  *       header file for wtwg source code programs
  3.  */
  4. #ifndef WSYS_H
  5.     #define WSYS_H
  6.  
  7. #include "wtwg.h"
  8. #include <string.h>
  9. #include <dos.h>
  10. #include <ctype.h>
  11.  
  12. #ifdef __TURBOC__
  13.     #include <alloc.h>    /* TurboC */
  14.         #ifdef  __OVERLAY__
  15.             /* not allowed to use near calls in overlayed programs */
  16.             #define W_NEAR
  17.         #else
  18.             #define W_NEAR near
  19.         #endif
  20. #else
  21.     #include <malloc.h> /* Microsoft C */
  22.     
  23.     #ifndef W_NEAR
  24.         #define W_NEAR near
  25.     #endif    /* ifndef W_NEAR */
  26.  
  27.     #include "msc.h"
  28. #endif
  29.  
  30.  
  31.  
  32. /* farmemcpy()
  33.  * in large models this is just memcpy
  34.  * but in small models it's movedata()
  35.  */
  36. #undef LARGE_DATA_MODEL
  37. #ifdef __LARGE__
  38.     #define LARGE_DATA_MODEL
  39. #endif
  40. #ifdef __COMPACT__
  41.     #define LARGE_DATA_MODEL
  42. #endif
  43. #ifdef __HUGE__
  44.     #define LARGE_DATA_MODEL
  45. #endif 
  46.  
  47.  
  48.  
  49.  
  50. #ifdef LARGE_DATA_MODEL
  51.     #define farmemcpy(aa,bb,cc)  memcpy (aa,bb,cc)
  52. #else
  53.  
  54.     /* model is small or medium - need a far * equivalent of
  55.      * memcpy, write, read, memcmp
  56.      */
  57.     #define farmemcpy(dest,src,num)  \
  58.     movedata (FP_SEG(src), FP_OFF(src), FP_SEG(dest), FP_OFF(dest), num )
  59.  
  60. #endif    /* memcpy */
  61.  
  62.  
  63.  
  64. /* NORMALIZE macros.
  65. *    Far pointer normalization routine
  66.  *        Arithmetic on far pointers only affects the offset,
  67.  *        does not carry into the segment portion.
  68.  *     to avoid overflow errors,
  69.  *        must convert seg:off pair to place as much
  70.  *         of the address as possible into the segment part.
  71.  *
  72.  *     NORMALIZE () - unconditionally normalize a far pointer.
  73.  *      _NORMALIZE () - normalize a data pointer IF memory model requires it
  74.  *
  75.  *  use _NORMALIZE for pointers not explicitly declared far.
  76.  */
  77. #ifndef __cplusplus
  78.     /* traditional C */
  79.     #define NORMALIZE(fp)        \
  80.        fp = MK_FP ( ( FP_SEG(fp) + (FP_OFF(fp)>>4) ),  \
  81.             ((unsigned)(FP_OFF(fp))& 0x000f) )
  82. #else
  83.     // C++ requires type casts for assignment
  84.     #define NORMALIZE(fp,type) \
  85.        fp = (type) MK_FP ( ( FP_SEG(fp) + (FP_OFF(fp)>>4) ),  \
  86.             ((unsigned)(FP_OFF(fp))& 0x000f) )
  87. #endif    /* NORMALIZE */
  88.  
  89.  
  90.  
  91.  
  92. #ifdef LARGE_DATA_MODEL
  93.     /* pointers are far *, need to normalize all ptrs
  94.      * except in __HUGE__ model, where they are normalized for you.
  95.      */
  96.     #ifndef __HUGE__
  97.         #define _NORMALIZE(fp)  NORMALIZE(fp)
  98.     #endif  /* HUGE */
  99. #else
  100.     /* model is SMALL or MEDIUM - data ptrs only are far if explicit far
  101.       */
  102.     #define _NORMALIZE(fp)
  103.     
  104. #endif  /* LARGE_DATA - normalize  */
  105.  
  106.  
  107.  
  108. #ifdef __HUGE__
  109.     /* data pointers are all far, but TurboC normalizes them for you */
  110.     #undef  _NORMALIZE()
  111.     #define _NORMALIZE(fp)
  112. #endif
  113.  
  114.  
  115.  
  116.  
  117.  
  118.  
  119.  
  120.  
  121.  
  122.  
  123.  
  124.     #ifdef  __TURBOC__
  125.         /*  Defining PSEUDOREGS allows using in-line interrupts 
  126.          *  in the TurboC version, but generates calls to funcs 
  127.          *  in the Microsoft version. see MSC.H
  128.          */
  129.         #define    PSEUDOREGS
  130.         #define INTERRUPT(intno)  geninterrupt ( (intno) )
  131.         #define INTERRUPTX(intno) geninterrupt ( (intno) )
  132.  
  133.     #endif    /* end of redefinning pseudoregs  */
  134.  
  135.  
  136. /*end of wsys.h*/
  137. #ifdef __BORLANDC__
  138.     #pragma hdrstop
  139. #endif /* BORLANDC */
  140.  
  141. #endif /* WSYS.H */