home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1994 #1 / monster.zip / monster / PROG_C / SNIP9404.ZIP / PORTABLE.H < prev    next >
C/C++ Source or Header  |  1994-04-03  |  5KB  |  167 lines

  1. /*============================================================================
  2.  
  3.     portable.h   v1.00      Written by Scott Robert Ladd.
  4.  
  5.     _MSC_VER        Microsoft C 6.0 and later
  6.     _QC             Microsoft Quick C 2.51 and later
  7.     __TURBOC__      Borland Turbo C, Turbo C++, and Borland C++
  8.     __BORLANDC__    Borland C++
  9.     __ZTC__         Zortech C++ and Symantec C++
  10.     __SC__          Symantec C++
  11.     __WATCOM__      WATCOM C
  12.     __POWERC        Mix Power C
  13.  
  14.     Revised:
  15.     09/14/93  Fred Cole  Moved MK_FP() macro to end of file to avoid
  16.                          redefinition error when dos.h gets included
  17.                          at the in/outport definitions for __TURBOC__
  18.     09/15/93  Thad Smith Add conditional code for TC 2.01
  19.                          Fix findfirst/findnext support for ZTC 3.0
  20.     10/15/93  Bob Stout  Revise find first/next support
  21.     04/03/94  Bob Stout  Add Power C support, FAR
  22. ============================================================================*/
  23.  
  24.  
  25. /* prevent multiple inclusions of this header file */
  26.  
  27. #if !defined(PORTABLE_H)
  28. #define PORTABLE_H
  29.  
  30. /*
  31. **  Correct far pointer syntax
  32. */
  33.  
  34. #if defined(__POWERC) || (defined(__TURBOC__) && !defined(__BORLANDC__))
  35.  #define FAR far
  36. #else
  37.  #define FAR _far
  38. #endif
  39.  
  40. /*----------------------------------------------------------------------------
  41.     Directory search macros and data structures
  42.  
  43.     DOSFileData         MS-DOS file data structure
  44.     FIND_FIRST          MS-DOS function 0x4E -- find first file matchine spec
  45.     FIND_NEXT           MS-DOS function 0x4F -- find subsequent files
  46. ----------------------------------------------------------------------------*/
  47.  
  48. /* make sure the structure is packed on byte boundary */
  49.  
  50. #if defined(_MSC_VER) || defined(_QC) || defined(__WATCOM__)
  51.     #pragma pack(1)
  52. #elif defined(__ZTC__)
  53.     #pragma ZTC align 1
  54. #elif defined(__TURBOC__) && (__TURBOC__ > 0x202)
  55.     #pragma option -a-
  56. #endif
  57.  
  58. /* use this structure in place of compiler-defined file structure */
  59.  
  60. typedef struct {
  61.       char        reserved[21];
  62.       char        attrib;
  63.       unsigned    time;
  64.       unsigned    date;
  65.       long        size;
  66.       char        name[13];
  67.       } DOSFileData;
  68.  
  69. /* set structure alignment to default */
  70.  
  71. #if defined (_MSC_VER) || defined(_QC) || defined(__WATCOMC__)
  72.  #pragma pack()
  73. #elif defined (__ZTC__)
  74.  #pragma ZTC align
  75. #elif defined(__TURBOC__) && (__TURBOC__ > 0x202)
  76.  #pragma option -a.
  77. #endif
  78.  
  79. /* include proper header files and create macros */
  80.  
  81. #if defined (_MSC_VER) || defined(_QC) || defined(__WATCOMC)
  82.  #include "direct.h"
  83.  #define FIND_FIRST(spec,attr,buf) _dos_findfirst(spec,attr,\
  84.        (struct find_t *)buf)
  85.  #define FIND_NEXT(buf) _dos_findnext((struct find_t *)buf)
  86. #elif defined (__TURBOC__)
  87.  #include "dir.h"
  88.  #define FIND_FIRST(spec,attr,buf) findfirst(spec,(struct ffblk *)buf,attr)
  89.  #define FIND_NEXT(buf) findnext((struct ffblk *)buf)
  90. #elif defined (__ZTC__)
  91.  #include "dos.h"
  92.  #define FIND_FIRST(spec,attr,buf) _dos_findfirst(spec,attr,\
  93.        (struct find_t *)buf)
  94.  #define FIND_NEXT(buf) _dos_findnext((struct find_t *)buf)
  95. #endif
  96.  
  97. /*----------------------------------------------------------------------------
  98.     I/O Port Macros
  99.  
  100.     IN_PORT     read byte from I/O port
  101.     IN_PORTW    read word from I/O port
  102.     OUT_PORT    write byte to I/O port
  103.     OUT_PORTW   write word to I/O port
  104. ----------------------------------------------------------------------------*/
  105.  
  106. #if defined(__TURBOC__)
  107.  #include "dos.h"
  108.  #define IN_PORT(port)           inportb(port)
  109.  #define IN_PORTW(port)          inport(port)
  110.  #define OUT_PORT(port, val)     outportb(port, val)
  111.  #define OUT_PORTW(port, val)    outport(port, val)
  112. #else
  113.  #include "conio.h"
  114.  
  115.  #define IN_PORT(port)           inp(port)
  116.  #define IN_PORTW(port)          inpw(port)
  117.  #define OUT_PORT(port, val)     outp(port, val)
  118.  #define OUT_PORTW(port, val)    outpw(port, val)
  119.  
  120. /*----------------------------------------------------------------------------
  121.     Borland pseudo register macros
  122.  
  123.     These macros replace references to Borland's pseudo register
  124.     variables and geninterrup() funciton with traditional struct
  125.     REGS/int86 references.
  126. ----------------------------------------------------------------------------*/
  127.  
  128. #if !defined(__TURBOC__)
  129.  #include "dos.h"
  130.  
  131.  extern union REGS CPURegs;
  132.  
  133.  #define _AX CPURegs.x.ax
  134.  #define _BX CPURegs.x.bx
  135.  #define _CX CPURegs.x.cx
  136.  #define _DX CPURegs.x.dx
  137.  
  138.  #define _AH CPURegs.h.ah
  139.  #define _AL CPURegs.h.al
  140.  #define _BH CPURegs.h.bh
  141.  #define _BL CPURegs.h.bl
  142.  #define _CH CPURegs.h.ch
  143.  #define _CL CPURegs.h.cl
  144.  #define _DH CPURegs.h.dh
  145.  #define _DL CPURegs.h.dl
  146.  
  147.  #define geninterrupt(n) int86(n,&CPURegs,&CPURegs);
  148.  #define O_DENYALL   0x10
  149.  #define O_DENYWRITE 0x20
  150.  #define O_DENYREAD  0x30
  151.  #define O_DENYNONE  0x40
  152. #endif
  153.  
  154. #endif
  155.  
  156. /*----------------------------------------------------------------------------
  157.     Pointer-related macros
  158.  
  159.     MK_FP   creates a far pointer from segment and offset values
  160. ----------------------------------------------------------------------------*/
  161.  
  162. #if !defined(MK_FP)
  163.     #define MK_FP(seg,off) ((void FAR *)(((long)(seg) << 16)|(unsigned)(off)))
  164. #endif
  165.  
  166. #endif
  167.