home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c082_122 / 1.ddi / WINLBSRC.ZIP / INTR.CAS < prev    next >
Encoding:
Text File  |  1992-06-10  |  5.3 KB  |  184 lines

  1. /*-----------------------------------------------------------------------*
  2.  * filename - intr.cas
  3.  *
  4.  * function(s)
  5.  *        intr - alternate 8086 software interrupt interface
  6.  *-----------------------------------------------------------------------*/
  7.  
  8. /*
  9.  *      C/C++ Run Time Library - Version 5.0
  10.  *
  11.  *      Copyright (c) 1987, 1992 by Borland International
  12.  *      All Rights Reserved.
  13.  *
  14.  */
  15.  
  16.  
  17. #pragma inline
  18. #include <asmrules.h>
  19. #include <dos.h>
  20.  
  21. #if defined(_Windows)
  22. void far pascal AllocDStoCSAlias(void);
  23. void far pascal FreeSelector(void);
  24. void far pascal GlobalFix(void);
  25. void far pascal GlobalUnfix(void);
  26. #endif
  27.  
  28. /*-----------------------------------------------------------------------*
  29.  
  30. Name            intr - alternate 8086 software interrupt interface
  31.  
  32. Usage           #include <dos.h>
  33.                 void intr(int intr_num, struct REGPACK *preg);
  34.  
  35. Prototype in    dos.h
  36.  
  37. Description     The intr function is an alternate interface for
  38.                 executing software interrupts. It generates an 8086 software
  39.                 interrupt specified by the argument intr_num.
  40.  
  41.                 intr copies register values from the REGPACK structure
  42.                 preg into the registers before executing the software
  43.                 interrupt. After the software interrupt completes, intr
  44.                 copies the current register values into preg. The flags
  45.                 are preserved.
  46.  
  47.                 The arguments passed to intr are as follows:
  48.  
  49.                   intr_num      the interrupt number to be executed
  50.  
  51.                   preg          the address of a structure containing
  52.                                 (a) the input registers before the call
  53.                                 (b) the value of the registers after the
  54.                                     interrupt call.
  55.  
  56.                 The REGPACK structure preg (described in dos.h) has the
  57.                 following format :
  58.  
  59.                   struct  REGPACK
  60.                   {
  61.                   unsigned  r_ax, r_bx, r_cx, r_dx;
  62.                   unsigned  r_bp, r_si, r_di, r_ds, r_es, r_flags;
  63.                   };
  64.  
  65. Return value    No value is returned. The REGPACK structure preg
  66.                 contains the value of the registers after the interrupt
  67.                 call.
  68.  
  69.  
  70. *------------------------------------------------------------------------*/
  71. #pragma option -r+
  72. void intr(int int_type, struct REGPACK *preg)
  73. {
  74.         void    (far * Vector)(void);
  75.         char    Code[14];
  76.  
  77. /*      #define WhereIsBP       -(sizeof(Code) + sizeof(Vector) + 12)   */
  78.  
  79. #define WhereIsBP       -34
  80.  
  81.         /* Save caller context */
  82.  
  83. asm     push    bp
  84. asm     push    ds
  85. asm     pushf
  86.  
  87.         /* Prepare Interrupt call */
  88.  
  89. asm     mov     word ptr Code, 06E8Bh
  90. asm     mov     byte ptr Code+2, WhereIsBP
  91. asm     mov     byte ptr Code+3, 0CDh
  92. asm     mov     ax, int_type
  93. asm     mov     byte ptr Code+4, al
  94. asm     cmp     al, 025h
  95. asm     jb      NormalIntr
  96. asm     cmp     al, 026h
  97. asm     ja      NormalIntr
  98. asm     mov     byte ptr Code+5, 036h
  99. asm     mov     word ptr Code+6, 00068Fh
  100. asm     mov     word ptr Code+8, cx
  101. asm     mov     byte ptr Code+10, 0CAh
  102. asm     mov     word ptr Code+11, 2
  103. asm     jmp     InitVector
  104.  
  105. asm     popf_proc proc near
  106. asm     iret                    /* this proc does a bullet-proof popf */
  107. asm     popf_proc endp
  108.  
  109. NormalIntr:
  110. asm     mov     byte ptr Code+5, 0CAh
  111. asm     mov     word ptr Code+6, 2
  112.  
  113.         /* Set up the vector to our interrupt function */
  114.  
  115. InitVector:
  116. asm     lea     cx, Code
  117. asm     mov     word ptr Vector, cx
  118.  
  119. #if !defined( _Windows )
  120. asm     mov     word ptr Vector+2, ss
  121. #else
  122. asm     push    ss
  123.         GlobalFix();
  124. asm     push    ss
  125.         AllocDStoCSAlias();
  126. asm     mov     word ptr Vector+2, ax
  127. #endif
  128.  
  129.         /* Set registers with register structure content */
  130.  
  131. asm     LDS_    di, preg
  132. asm     push    ds
  133. asm     push    di
  134.  
  135. asm     mov     ax,[di].r_ax
  136. asm     mov     bx,[di].r_bx
  137. asm     mov     cx,[di].r_cx
  138. asm     mov     dx,[di].r_dx
  139. asm     push    word ptr [di].r_bp  /* BP will be loaded before int xx */
  140. asm     mov     si,[di].r_si
  141. asm     mov     es,[di].r_es
  142. asm     lds     di,[di].r_di
  143.  
  144.         /* Call the interrupt routine */
  145.  
  146.         (* Vector)();
  147.  
  148.         /* Set register structure with registers */
  149.  
  150. asm     push    ds
  151. asm     push    di
  152. asm     push    bp
  153. asm     pushf
  154.  
  155. asm     mov     bp,sp
  156. asm     lds     di,[bp+8]     /* DS:DI points to the reg structure   */
  157. asm     mov     [di].r_ax,ax
  158. asm     mov     [di].r_bx,bx
  159. asm     mov     [di].r_cx,cx
  160. asm     mov     [di].r_dx,dx
  161. asm     mov     [di].r_si,si
  162. asm     mov     [di].r_es,es
  163. asm     pop     [di].r_flags    /* flags                             */
  164. asm     pop     [di].r_bp       /* BP                                */
  165. asm     pop     [di].r_di       /* DI                                */
  166. asm     pop     [di].r_ds       /* DS                                */
  167.  
  168. asm     add     sp,4          /* Remove saved DS:DI                  */
  169.  
  170. asm     push    cs
  171. asm     call    popf_proc       /* pop flags */
  172.  
  173. asm     pop     ds
  174. asm     pop     bp
  175.  
  176. #if defined( _Windows )
  177. asm     push    word ptr Vector+2
  178.         FreeSelector();
  179. asm     push    ss
  180.         GlobalUnfix();
  181. #endif
  182. }
  183. #pragma option -r.
  184.