home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c065 / 2.ddi / CLIB2.ZIP / INTDOS.CAS < prev    next >
Encoding:
Text File  |  1990-06-07  |  4.3 KB  |  152 lines

  1. /*-----------------------------------------------------------------------*
  2.  * filename - intdos.cas
  3.  *
  4.  * function(s)
  5.  *        intdos  - general MS-DOS interrupt interface
  6.  *        intdosx - general MS-DOS 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        intdos - general MS-DOS interrupt interface
  27.  
  28. Usage        #include <dos.h>
  29.         int intdos(union REGS * inregs, union REGS * outregs);
  30.  
  31. Related
  32. functions usage    int intdosx(union REGS *inregs, union REGS *outregs,
  33.                 struct SREGS *segregs);
  34.  
  35. Prototype in    dos.h
  36.  
  37. Description    Both of these functions execute DOS interrupt 0x21
  38.         to invoke a specified DOS function. The value of
  39.         inregs->h.al specifies the DOS function to be invoked.
  40.  
  41.         In addition, intdosx copies the segregs->x.ds and
  42.         segregs->x.es values into the corresponding registers
  43.         before invoking the DOS function. This feature allows
  44.         programs that use far pointers, or that use a large
  45.         data memory model, to specify which segment is
  46.         to be used during the function execution.
  47.  
  48.         After the interrupt 0x21 returns, both functions copy the
  49.         current register values to outregs, copy the status of the
  50.         system carry flag to the x.cflag field in outregs, and
  51.         copy the value of the 8086 flags register to the x.flags
  52.         field in outregs.  In addition, intdosx restores DS, and
  53.         sets the segregs->es and segregs->ds fields to the values
  54.         of the corresponding segment registers.
  55.  
  56.         If the carry flag is set, it indicates that an error occurred.
  57.  
  58.         intdosx allows you to invoke a DOS function that takes a value
  59.         of DS different from the default data segment, and/or that takes
  60.         an argument in ES.
  61.  
  62.     Note that inregs can point to the same structure that outregs
  63.         points to.
  64.  
  65. Return value    intdos and intdosx return the value of AX after completion
  66.         of the DOS function call. 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 intdos(union REGS *inregs, union REGS *outregs)
  72. {
  73.     struct    SREGS    s;
  74.  
  75.     segread(&s);
  76.     return(intdosx(inregs, outregs, &s));
  77. }
  78.  
  79.  
  80. /*-----------------------------------------------------------------------*
  81.  
  82. Name        intdosx - general MS-DOS interrupt interface
  83.  
  84. Usage        #include <dos.h>
  85.                 int intdosx(union REGS *inregs, union REGS *outregs,
  86.                 struct SREGS *segregs);
  87.  
  88. Prototype in    dos.h
  89.  
  90. Description    see intdos.
  91.  
  92. *------------------------------------------------------------------------*/
  93.  
  94. int intdosx(union REGS *inregs, union REGS *outregs, struct SREGS *segregs)
  95. {
  96.     /* Save caller context */
  97.  
  98. asm    push    ds
  99.  
  100.     /* Set registers with register structure content */
  101.  
  102. asm    LDS_    si, segregs
  103. asm    push    [si].es
  104. asm    push    [si].ds
  105. asm    LDS_    si, inregs
  106. asm    mov    ax, [si].ax
  107. asm    mov    bx, [si].bx
  108. asm    mov    cx, [si].cx
  109. asm    mov    dx, [si].dx
  110. asm    mov    di, [si].di
  111. asm    mov    si, [si].si
  112. asm    pop    ds
  113. asm    pop    es
  114.  
  115.     /* Call DOS */
  116. asm    push    bp        /* just to be safe */
  117. asm    int    021h
  118. asm    pop    bp
  119.  
  120.     /* Set register structure with registers */
  121.  
  122. asm    pushf
  123. asm    pushf
  124. asm    push    si
  125. asm    push    ds
  126. asm    push    es
  127. #if    !LDATA
  128. asm    mov    ds, [bp-6]
  129. #endif
  130. asm    LDS_    si, segregs
  131. asm    pop    [si].es
  132. asm    pop    [si].ds
  133. asm    LDS_    si, outregs
  134. asm    pop    [si].si
  135. asm    pop    [si].flags
  136. asm    pop    [si].cflag
  137. asm    and    word ptr [si].cflag, 1
  138. asm    mov    [si].di, di
  139. asm    mov    [si].dx, dx
  140. asm    mov    [si].cx, cx
  141. asm    mov    [si].bx, bx
  142. asm    mov    [si].ax, ax
  143. asm    pop    ds
  144. asm    jz    intdosOk
  145. asm    push    ax
  146.     __IOerror(_AX);
  147. asm    pop    ax
  148.  
  149. intdosOk:
  150.     return(_AX);
  151. }
  152.