home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 1997 May / Pcwk0597.iso / sybase / starbuck / h.z / I86.H < prev    next >
C/C++ Source or Header  |  1996-07-24  |  6KB  |  253 lines

  1. /*
  2.  *  i86.h    Defines the structs and unions used to handle the input and
  3.  *        output registers for the Intel x86 and 386 interrupt interface
  4.  *        routines.
  5.  *
  6.  *  Copyright by WATCOM International Corp. 1988-1996.  All rights reserved.
  7.  */
  8. #ifndef _I86_H_INCLUDED
  9. #define _I86_H_INCLUDED
  10. #ifdef __cplusplus
  11. extern "C" {
  12. #endif
  13.  
  14. #if !defined(_M_IX86)
  15. #error i86.h is for use with Intel platforms
  16. #endif
  17.  
  18. #ifndef _COMDEF_H_INCLUDED
  19.  #include <_comdef.h>
  20. #endif
  21.  
  22. #if defined(_M_IX86)
  23.   #pragma pack(__push,1);
  24. #else
  25.   #pragma pack(__push,8);
  26. #endif
  27. #undef __FILLER
  28. #if defined(__386__) && !defined(__WINDOWS_386__)
  29. /* dword registers */
  30.  
  31. struct DWORDREGS {
  32.     unsigned int eax;
  33.     unsigned int ebx;
  34.     unsigned int ecx;
  35.     unsigned int edx;
  36.     unsigned int esi;
  37.     unsigned int edi;
  38.     unsigned int cflag;
  39. };
  40.  #define __FILLER(a) unsigned short a;
  41. #else
  42.  #define __FILLER(a)
  43. #endif
  44.  
  45. /* word registers */
  46.  
  47. struct WORDREGS {
  48.     unsigned short ax;  __FILLER(_1)
  49.     unsigned short bx;  __FILLER(_2)
  50.     unsigned short cx;  __FILLER(_3)
  51.     unsigned short dx;  __FILLER(_4)
  52.     unsigned short si;  __FILLER(_5)
  53.     unsigned short di;  __FILLER(_6)
  54. #if defined(__WINDOWS_386__)
  55.     unsigned short cflag;
  56. #else
  57.     unsigned int cflag;
  58. #endif
  59. };
  60.  
  61. /* byte registers */
  62.  
  63. struct BYTEREGS {
  64.     unsigned char al, ah;  __FILLER(_1)
  65.     unsigned char bl, bh;  __FILLER(_2)
  66.     unsigned char cl, ch;  __FILLER(_3)
  67.     unsigned char dl, dh;  __FILLER(_4)
  68. };
  69.  
  70. /* general purpose registers union - overlays the corresponding dword,
  71.  * word, and byte registers.
  72.  */
  73.  
  74. union REGS {
  75. #if defined(__386__) && !defined(__WINDOWS_386__)
  76.     struct DWORDREGS x;
  77. #else
  78.     struct WORDREGS  x;
  79. #endif
  80.     struct WORDREGS  w;
  81.     struct BYTEREGS  h;
  82. };
  83. #define _REGS REGS
  84.  
  85. /* segment registers */
  86.  
  87. struct SREGS {
  88.     unsigned short es, cs, ss, ds;
  89. #if defined(__386__)
  90.     unsigned short fs, gs;
  91. #endif
  92. };
  93. #define _SREGS SREGS
  94.     
  95.  
  96. /* intr structs */
  97.  
  98. struct REGPACKB {
  99.     unsigned char al, ah;  __FILLER(_1)
  100.     unsigned char bl, bh;  __FILLER(_2)
  101.     unsigned char cl, ch;  __FILLER(_3)
  102.     unsigned char dl, dh;  __FILLER(_4)
  103. };
  104.  
  105. struct REGPACKW {
  106.     unsigned short ax;  __FILLER(_1)
  107.     unsigned short bx;  __FILLER(_2)
  108.     unsigned short cx;  __FILLER(_3)
  109.     unsigned short dx;  __FILLER(_4)
  110.     unsigned short bp;  __FILLER(_5)
  111.     unsigned short si;  __FILLER(_6)
  112.     unsigned short di;  __FILLER(_7)
  113.     unsigned short ds;
  114.     unsigned short es;
  115. #if defined(__386__) && !defined(__WINDOWS_386__)
  116.     unsigned short fs;
  117.     unsigned short gs;
  118. #endif
  119. #if defined(__WINDOWS_386__)
  120.     unsigned short flags;
  121. #else
  122.     unsigned int flags;
  123. #endif
  124. };
  125.  
  126. struct REGPACKX {
  127.     unsigned int   eax, ebx, ecx, edx, ebp, esi, edi;
  128.     unsigned short ds, es, fs, gs;
  129.     unsigned int   flags;
  130. };
  131.  
  132. union REGPACK {
  133.     struct REGPACKB h;
  134.     struct REGPACKW w;
  135. #if defined(__386__) && !defined(__WINDOWS_386__)
  136.     struct REGPACKX x;
  137. #else
  138.     struct REGPACKW x;
  139. #endif
  140. };
  141.  
  142. /* input parm to an 'interrupt' function is union INTPACK */
  143. /* e.g.  interrupt int10( union INTPACK r ) {}          */
  144.  
  145. struct INTPACKX {
  146.     unsigned gs,fs,es,ds,edi,esi,ebp,esp,ebx,edx,ecx,eax,eip,cs,flags;
  147. };
  148. /*
  149.    NOTE: The gs and fs fields will not be correct unless the compiler
  150.      is invoked with at least the /3 switch.
  151. */
  152. struct INTPACKW {
  153.     unsigned short gs;  __FILLER(_1)
  154.     unsigned short fs;  __FILLER(_2)
  155.     unsigned short es;  __FILLER(_3)
  156.     unsigned short ds;  __FILLER(_4)
  157.     unsigned short di;  __FILLER(_5)
  158.     unsigned short si;  __FILLER(_6)
  159.     unsigned short bp;  __FILLER(_7)
  160.     unsigned short sp;  __FILLER(_8)
  161.     unsigned short bx;  __FILLER(_9)
  162.     unsigned short dx;  __FILLER(_a)
  163.     unsigned short cx;  __FILLER(_b)
  164.     unsigned short ax;  __FILLER(_c)
  165.     unsigned short ip;  __FILLER(_d)
  166.     unsigned short cs;  __FILLER(_e)
  167.     unsigned flags;
  168. };
  169. struct INTPACKB {
  170. #if defined(__386__)
  171.     unsigned /*gs*/ :32,/*fs*/ :32,
  172.          /*es*/ :32,/*ds*/ :32,
  173.          /*edi*/:32,/*esi*/:32,
  174.          /*ebp*/:32,/*esp*/:32;
  175. #else
  176.     unsigned /*gs*/:16,/*fs*/:16,
  177.          /*es*/:16,/*ds*/:16,
  178.          /*di*/:16,/*si*/:16,
  179.          /*bp*/:16,/*sp*/:16;
  180. #endif
  181.     unsigned char bl, bh; __FILLER(_1)
  182.     unsigned char dl, dh; __FILLER(_2)
  183.     unsigned char cl, ch; __FILLER(_3)
  184.     unsigned char al, ah; __FILLER(_4)
  185. };
  186. union  INTPACK {
  187.     struct INTPACKB h;
  188.     struct INTPACKW w;
  189. #if defined(__386__)
  190.     struct INTPACKX x;
  191. #else
  192.     struct INTPACKW x;
  193. #endif
  194. };
  195.  
  196. /* bits defined for flags field defined in REGPACKW and INTPACKW */
  197.  
  198. enum {
  199.     INTR_CF    = 0x0001,    /* carry */
  200.     INTR_PF    = 0x0004,    /* parity */
  201.     INTR_AF    = 0x0010,    /* auxiliary carry */
  202.     INTR_ZF    = 0x0040,    /* zero */
  203.     INTR_SF    = 0x0080,    /* sign */
  204.     INTR_TF    = 0x0100,    /* trace */
  205.     INTR_IF    = 0x0200,    /* interrupt */
  206.     INTR_DF    = 0x0400,    /* direction */
  207.     INTR_OF    = 0x0800    /* overflow */
  208. };
  209.  
  210. _WCIRTLINK extern void _disable( void );
  211. _WCIRTLINK extern void _enable( void );
  212.  
  213. #ifdef    __INLINE_FUNCTIONS__
  214.  #pragma intrinsic(_disable,_enable)
  215. #endif
  216.  
  217. _WCRTLINK extern void     delay(unsigned int __milliseconds);
  218. #if defined(__386__) && !defined(__WINDOWS_386__)
  219. _WCRTLINK extern int     int386( int, union REGS *, union REGS * );
  220. _WCRTLINK extern int     int386x( int, union REGS *, union REGS *, 
  221.                   struct SREGS * );
  222. #else
  223. _WCRTLINK extern int     int86( int, union REGS *, union REGS * );
  224. _WCRTLINK extern int     int86x( int, union REGS *, union REGS *, 
  225.                  struct SREGS * );
  226. #endif
  227. _WCRTLINK extern void     intr( int, union REGPACK * );
  228. _WCRTLINK extern void     nosound( void );
  229. _WCRTLINK extern void     segread( struct SREGS * );
  230. _WCRTLINK extern void     sound( unsigned __frequency );
  231.  
  232. /* macros to break 'far' pointers into segment and offset components */
  233.  
  234. #define  FP_OFF(__p) ((unsigned)(__p))
  235. #define _FP_OFF(__p) ((unsigned)(__p))
  236.  
  237. #if defined(__386__)
  238.   unsigned short FP_SEG( const volatile void __far * );
  239.   #pragma aux     FP_SEG = __parm __caller [eax dx] __value [dx];
  240. #else
  241.   #define FP_SEG(__p) ((unsigned)((unsigned long)(void __far*)(__p) >> 16))
  242. #endif
  243. #define _FP_SEG FP_SEG
  244.  
  245. /* make a far pointer from segment and offset */
  246. #define MK_FP(__s,__o) (((unsigned short)(__s)):>((void __near *)(__o)))
  247.  
  248. #pragma pack(__pop);
  249. #ifdef __cplusplus
  250. };
  251. #endif
  252. #endif
  253.