home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / listings / v_09_01 / 9n01056a < prev    next >
Text File  |  1990-11-14  |  4KB  |  136 lines

  1. /*========================================================================
  2.     portable.h  v1.00   Written by Scott Robert Ladd.
  3.  
  4.     _MSC_VER    Microsoft C 6.0 and later
  5.     _QC         Microsoft Quick C 2.51 and later
  6.     __TURBOC__  Borland Turbo C and Turbo C++
  7.     __ZTC__     Zortech C and C++
  8.     __WATCOMC__ WATCOM C
  9. ========================================================================*/
  10.  
  11. /* prevent multiple inclusions of this header file*/
  12. #if !defined(PORTABLE_H)
  13. #define PORTABLE_H
  14.  
  15. /*------------------------------------------------------------------------
  16.     Pointer-related macros
  17.  
  18.     MK_FP   creates a far pointer from segment and offset values
  19. ------------------------------------------------------------------------*/
  20.  
  21. #if !defined(MK_FP)
  22.     #define MK_FP(seg,off) ((void far *)(((long)(seg) << 16)|(unsigned)(off)))
  23. #endif
  24.  
  25. /*------------------------------------------------------------------------
  26.     Directory search macros and data structures
  27.  
  28.     DOSFileData     MS-DOS file data structure
  29.     FIND_FIRST      MS-DOS function 0x4E -- find first file matching spec
  30.     FIND_NEXT       MS-DOS function 0x4F -- find subsequent files
  31. ------------------------------------------------------------------------*/
  32.  
  33. /* make sure the structure is packed on byte boundary */
  34. #if defined(_MSC_VER) || defined(_QC) || defined(__WATCOMC__)
  35.     #pragma pack(1)
  36. #elif defined(__ZTC__)
  37.     #pragma align 1
  38. #elif defined(__TURBOC__)
  39.     #pragma option -a-
  40. #endif
  41.  
  42. /* use this structure in place of compiler-defined file structure */
  43. typedef struct
  44.     {
  45.     char     reserved[21];
  46.     char     attrib;
  47.     unsigned time;
  48.     unsigned date;
  49.     long     size;
  50.     char     name[13];
  51.     }
  52.     DOSFileData;
  53.  
  54. /* set structure alignment to default */
  55. #if defined (_MSC_VER) || defined(_QC) || defined(__WATCOMC__)
  56.     #pragma pack()
  57. #elif defined(__ZTC__)
  58.     #pragma align
  59. #elif defined(__TURBOC__)
  60.     #pragma option -a.
  61. #endif
  62.  
  63. /* include proper header files and create macros */
  64. #if defined(_MSC_VER) || defined(_QC) || defined(__WATCOMC__)
  65.     #include "direct.h"
  66.     #define FIND_FIRST(spec, attr, buf) \
  67. _dos_findfirst(spec, attr, (struct find_t *)buf) \
  68.     #define FIND_NEXT(buf) _dos_findnext((struct find_t *)buf)
  69. #elif defined(__TURBOC__)
  70.     #include "dir.h"
  71.     #define FIND_FIRST(spec, attr, buf) \
  72. findfirst(spec, (struct ffblk *)buf, attr)
  73.     #define FIND_NEXT(buf) findnext((struct ffblk *)buf)
  74. #elif defined(__ZTC__)
  75.     #include "dos.h"
  76.     #define FIND_FIRST(spec, attr, buf) \
  77. dos_findfirst(spec, attr, (struct DOS_FIND *)buf)
  78.     #define FIND_NEXT(buf) dos_findnext((struct DOS_FIND *)buf)
  79. #endif
  80.  
  81. /*------------------------------------------------------------------------
  82.     I/O Port Macros
  83.  
  84.     IN_PORT     read  byte from I/O port
  85.     IN_PORTW    read  word from I/O port
  86.     OUT_PORT    write byte  to  I/O port
  87.     OUT_PORTW   write word  to  I/O port
  88. ------------------------------------------------------------------------*/
  89.  
  90. #if defined(__TURBOC__)
  91.     #include "dos.h"
  92.     #define IN_PORT(port)       inportb(port)
  93.     #define IN_PORTW(port)      inport(port)
  94.     #define OUT_PORT(port,val)  outportb(port,val)
  95.     #define OUT_PORTW(port,val) outport(port,val)
  96. #else
  97.     #include "conio.h"
  98.  
  99.     #define IN_PORT(port)       inp(port)
  100.     #define IN_PORTW(port)      inpw(port)
  101.     #define OUT_PORT(port,val)  outp(port,val)
  102.     #define OUT_PORTW(port,val) outpw(port,val)
  103. #endif
  104.  
  105. /*------------------------------------------------------------------------
  106.     Borland psuedo register macros
  107.  
  108.     These macros replace references to Borland's psuedo register
  109.     variables and geninterrupt() function with traditional struct
  110.     REGS/int86 references.
  111. ------------------------------------------------------------------------*/
  112.  
  113. #if !defined(__TURBOC__)
  114.     #include "dos.h"
  115.  
  116.     struct REGS CPURegs;
  117.  
  118.     #define _AX CPURegs.x.ax
  119.     #define _BX CPURegs.x.bx
  120.     #define _CX CPURegs.x.cx
  121.     #define _DX CPURegs.x.dx
  122.  
  123.     #define _AH CPURegs.h.ah
  124.     #define _AL CPURegs.h.al
  125.     #define _BH CPURegs.h.bh
  126.     #define _BL CPURegs.h.bl
  127.     #define _CH CPURegs.h.ch
  128.     #define _CL CPURegs.h.cl
  129.     #define _DH CPURegs.h.dh
  130.     #define _DL CPURegs.h.dl
  131.  
  132.     #define geninterrupt(n) int86(n,&CPURegs,&CPURegs);
  133. #endif
  134.  
  135. #endif
  136.