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