home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c082_122 / 5.ddi / CLIBSRC2.ZIP / INTR.CAS < prev    next >
Encoding:
Text File  |  1992-06-10  |  4.8 KB  |  164 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.  
  22. /*-----------------------------------------------------------------------*
  23.  
  24. Name            intr - alternate 8086 software interrupt interface
  25.  
  26. Usage           #include <dos.h>
  27.                 void intr(int intr_num, struct REGPACK *preg);
  28.  
  29. Prototype in    dos.h
  30.  
  31. Description     The intr function is an alternate interface for
  32.                 executing software interrupts. It generates an 8086 software
  33.                 interrupt specified by the argument intr_num.
  34.  
  35.                 intr copies register values from the REGPACK structure
  36.                 preg into the registers before executing the software
  37.                 interrupt. After the software interrupt completes, intr
  38.                 copies the current register values into preg. The flags
  39.                 are preserved.
  40.  
  41.                 The arguments passed to intr are as follows:
  42.  
  43.                   intr_num      the interrupt number to be executed
  44.  
  45.                   preg          the address of a structure containing
  46.                                 (a) the input registers before the call
  47.                                 (b) the value of the registers after the
  48.                                     interrupt call.
  49.  
  50.                 The REGPACK structure preg (described in dos.h) has the
  51.                 following format :
  52.  
  53.                   struct  REGPACK
  54.                   {
  55.                   unsigned  r_ax, r_bx, r_cx, r_dx;
  56.                   unsigned  r_bp, r_si, r_di, r_ds, r_es, r_flags;
  57.                   };
  58.  
  59. Return value    No value is returned. The REGPACK structure preg
  60.                 contains the value of the registers after the interrupt
  61.                 call.
  62.  
  63.  
  64. *------------------------------------------------------------------------*/
  65. #pragma option -r+
  66. void intr(int int_type, struct REGPACK *preg)
  67. {
  68.         void    (far * Vector)(void);
  69.         char    Code[14];
  70.  
  71. /*      #define WhereIsBP       -(sizeof(Code) + sizeof(Vector) + 12)   */
  72.  
  73. #if defined(__HUGE__)
  74. #define WhereIsBP       -36
  75. #else
  76. #define WhereIsBP       -34
  77. #endif
  78.  
  79.         /* Save caller context */
  80.  
  81. asm     push    bp
  82. asm     push    ds
  83. asm     pushf
  84.  
  85.         /* Prepare Interrupt call */
  86.  
  87. asm     lea     cx, Code
  88. asm     mov     word ptr Vector, cx
  89. asm     mov     word ptr Vector+2, ss
  90.  
  91. asm     mov     word ptr Code, 06E8Bh
  92. asm     mov     byte ptr Code+2, WhereIsBP
  93. asm     mov     byte ptr Code+3, 0CDh
  94. asm     mov     ax, int_type
  95. asm     mov     byte ptr Code+4, al
  96. asm     cmp     al, 025h
  97. asm     jb      NormalIntr
  98. asm     cmp     al, 026h
  99. asm     ja      NormalIntr
  100. asm     mov     byte ptr Code+5, 036h
  101. asm     mov     word ptr Code+6, 00068Fh
  102. asm     mov     word ptr Code+8, cx
  103. asm     mov     byte ptr Code+10, 0CAh
  104. asm     mov     word ptr Code+11, 2
  105. asm     jmp     SetRegs
  106.  
  107. asm     popf_proc proc near
  108. asm     iret                    /* this proc does a bullet-proof popf */
  109. asm     popf_proc endp
  110.  
  111. NormalIntr:
  112. asm     mov     byte ptr Code+5, 0CAh
  113. asm     mov     word ptr Code+6, 2
  114.  
  115.         /* Set registers with register structure content */
  116.  
  117. SetRegs:
  118. asm     LDS_    di, preg
  119. asm     push    ds
  120. asm     push    di
  121.  
  122. asm     mov     ax,[di].r_ax
  123. asm     mov     bx,[di].r_bx
  124. asm     mov     cx,[di].r_cx
  125. asm     mov     dx,[di].r_dx
  126. asm     push    word ptr [di].r_bp  /* BP will be loaded before int xx */
  127. asm     mov     si,[di].r_si
  128. asm     mov     es,[di].r_es
  129. asm     lds     di,[di].r_di
  130.  
  131.         /* Call the interrupt routine */
  132.  
  133.         (* Vector)();
  134.  
  135.         /* Set register structure with registers */
  136.  
  137. asm     push    ds
  138. asm     push    di
  139. asm     push    bp
  140. asm     pushf
  141.  
  142. asm     mov     bp,sp
  143. asm     lds     di,[bp+8]     /* DS:DI points to the reg structure   */
  144. asm     mov     [di].r_ax,ax
  145. asm     mov     [di].r_bx,bx
  146. asm     mov     [di].r_cx,cx
  147. asm     mov     [di].r_dx,dx
  148. asm     mov     [di].r_si,si
  149. asm     mov     [di].r_es,es
  150. asm     pop     [di].r_flags    /* flags                             */
  151. asm     pop     [di].r_bp       /* BP                                */
  152. asm     pop     [di].r_di       /* DI                                */
  153. asm     pop     [di].r_ds       /* DS                                */
  154.  
  155. asm     add     sp,4          /* Remove saved DS:DI                  */
  156.  
  157. asm     push    cs
  158. asm     call    popf_proc       /* pop flags */
  159.  
  160. asm     pop     ds
  161. asm     pop     bp
  162. }
  163. #pragma option -r.
  164.