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