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