home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c082_122 / 2.ddi / CLIBSRC3.ZIP / INT86.CAS < prev    next >
Encoding:
Text File  |  1992-06-10  |  5.6 KB  |  177 lines

  1. /*-----------------------------------------------------------------------*
  2.  * filename - int86.cas
  3.  *
  4.  * function(s)
  5.  *        int86  - general 8086 software interrupt interface
  6.  *        int86x - general 8086 software interrupt interface
  7.  *-----------------------------------------------------------------------*/
  8.  
  9. /*
  10.  *      C/C++ Run Time Library - Version 5.0
  11.  *
  12.  *      Copyright (c) 1987, 1992 by Borland International
  13.  *      All Rights Reserved.
  14.  *
  15.  */
  16.  
  17.  
  18. #pragma inline
  19. #include <asmrules.h>
  20. #include <dos.h>
  21. #include <_io.h>
  22.  
  23. /*-----------------------------------------------------------------------*
  24.  
  25. Name            int86  - general 8086 software interrupt interface
  26.  
  27. Usage           int int86(int intr_num, union REGS *inregs,
  28.                           union REGS *outregs);
  29.  
  30. Prototype in    dos.h
  31.  
  32. Description     Both of these functions execute an 8086 software
  33.                 interrupt specified by the argument intr_num.
  34.  
  35.                 Before executing the software interrupt, both functions
  36.                 copy register values from inregs into the registers.
  37.  
  38.                 In addition, int86x copies the segregs->x.ds and
  39.                 segregs->x.es values into the corresponding registers
  40.                 before executing the software interrupt. This feature
  41.                 allows programs that use far pointers, or that use a
  42.                 large data memory model, to specify which segment is
  43.                 to be used during the software interrupt.
  44.  
  45.                 After the software interrupt returns, both functions
  46.                 copy the current register values to outregs, copy the
  47.                 status of the system carry flag to the x.cflag field
  48.                 in outregs, and copy the value of the 8086 flags register
  49.                 to the x.flags field in outregs.  In addition, int86x
  50.                 restores DS, and sets the segregs->es and segregs->ds
  51.                 fields to the values of the corresponding segment
  52.                 registers.
  53.  
  54.                 If the carry flag is set, it indicates that an error
  55.                 occurred.
  56.  
  57.                 int86x allows you to invoke an 8086 software interrupt
  58.                 that takes a value of DS different from the default data
  59.                 segment, and/or that takes an argument in ES.
  60.  
  61.                 Note that inregs can point to the same structure that
  62.                 outregs points to.
  63.  
  64. Return value    int86 and int86x return the value of AX after completion
  65.                 of the software interrupt. If the carry flag is set
  66.                 (outregs->x.cflag != 0), indicating an error, these
  67.                 functions set _doserrno to the error code.
  68.  
  69. *------------------------------------------------------------------------*/
  70. int int86(int intno, union REGS *inregs, union REGS *outregs)
  71. {
  72.         struct  SREGS   s;
  73.  
  74.         segread(&s);
  75.         return(int86x(intno, inregs, outregs, &s));
  76. }
  77.  
  78. /*-----------------------------------------------------------------------*
  79.  
  80. Name            int86x  - general 8086 software interrupt interface
  81.  
  82. Usage           int int86x(int intr_num, union REGS *inregs,
  83.                           union REGS *outregs,struct SREGS *segregs);
  84.  
  85. Prototype in    dos.h
  86.  
  87. Description     see int86 above.
  88.  
  89. Return value    int86 and int86x return the value of AX after completion
  90.                 of the software interrupt. If the carry flag is set
  91.                 (outregs->x.cflag != 0), indicating an error, these
  92.                 functions set _doserrno to the error code.
  93.  
  94. *------------------------------------------------------------------------*/
  95. int int86x(int intno, union REGS *inregs, union REGS *outregs,
  96.            struct SREGS *segregs)
  97. {
  98.         void    (far * Vector)(void);
  99.         char    Code[10];
  100.  
  101.         /* Save caller context */
  102.  
  103. asm     push    ds
  104.  
  105.         /* Prepare Interrupt call */
  106.  
  107. asm     lea     cx, Code
  108. asm     mov     word ptr Vector, cx
  109. asm     mov     word ptr Vector+2, ss
  110.  
  111. asm     mov     byte ptr Code, 055h
  112. asm     mov     byte ptr Code+1, 0CDh
  113. asm     mov     ax, intno
  114. asm     mov     byte ptr Code+2, al
  115. asm     mov     word ptr Code+3, 0CB5Dh
  116. asm     cmp     al, 025h
  117. asm     jb      SetRegs
  118. asm     cmp     al, 026h
  119. asm     ja      SetRegs
  120. asm     mov     byte ptr Code+3, 036h
  121. asm     mov     word ptr Code+4, 0068Fh
  122. asm     mov     word ptr Code+6, cx
  123. asm     mov     word ptr Code+8, 0CB5Dh
  124.  
  125.         /* Set registers with register structure content */
  126.  
  127. SetRegs:
  128. asm     LDS_    si, segregs
  129. asm     push    [si].es
  130. asm     push    [si].ds
  131. asm     LDS_    si, inregs
  132. asm     mov     ax, [si].ax
  133. asm     mov     bx, [si].bx
  134. asm     mov     cx, [si].cx
  135. asm     mov     dx, [si].dx
  136. asm     mov     di, [si].di
  137. asm     mov     si, [si].si
  138. asm     pop     ds
  139. asm     pop     es
  140.  
  141.         /* Call the interrupt routine */
  142.  
  143.         (* Vector)();
  144.  
  145.         /* Set register structure with registers */
  146.  
  147. asm     pushf
  148. asm     pushf
  149. asm     push    si
  150. asm     push    ds
  151. asm     push    es
  152. #if     !LDATA
  153. asm     mov     ds, [bp-20]
  154. #endif
  155. asm     LDS_    si, segregs
  156. asm     pop     [si].es
  157. asm     pop     [si].ds
  158. asm     LDS_    si, outregs
  159. asm     pop     [si].si
  160. asm     pop     [si].flags
  161. asm     pop     [si].cflag
  162. asm     and     word ptr [si].cflag, 1
  163. asm     mov     [si].di, di
  164. asm     mov     [si].dx, dx
  165. asm     mov     [si].cx, cx
  166. asm     mov     [si].bx, bx
  167. asm     mov     [si].ax, ax
  168. asm     pop     ds
  169. asm     jz      int86Ok
  170. asm     push    ax
  171.         __IOerror(_AX);
  172. asm     pop     ax
  173.  
  174. int86Ok:
  175.         return(_AX);
  176. }
  177.