home *** CD-ROM | disk | FTP | other *** search
/ Stars of Shareware: Programmierung / SOURCE.mdf / programm / msdos / c / mscwattc / src / intr.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-01-14  |  1.9 KB  |  108 lines

  1. /* intr.c  - title
  2.     Description
  3.         What it does.
  4.         Limitations.
  5.         How to use it (compile instructions)
  6.  
  7.         Revison History
  8.     date       name         change
  9.   01/13/92  C. J. Kent      original
  10.  */
  11.  
  12. // IMPORT CONTROL MACROS
  13.  
  14. // IMPORTS
  15. # include "regpack.h"
  16.  
  17.  
  18. // LOCAL MACROS
  19.  
  20.  
  21.  
  22. // LOCAL DATA DECLARATIONS
  23.  
  24.  
  25.  
  26. // LOCAL DATA
  27.  
  28.  
  29.  
  30. // EXPORT DATA
  31.  
  32.  
  33.  
  34. // LOCAL FUNCTION PROTOTYPES
  35.  
  36.  
  37.  
  38. // FUNCTIONS
  39.  
  40. int _far intr( int IntNum, struct REGPACK _far * pRegs )
  41. {    unsigned char        Code[10];
  42.     _asm
  43.     {    push    ds
  44.         mov        Code[4],0cdh ; an 'int' opcode
  45.         mov        ax,IntNum
  46.         mov        Code[5], al    ; the interrupt number
  47.         cmp        al,25h
  48.         je        abnorm
  49.         cmp        al,26h
  50.         je        abnorm
  51.         mov        Code[6],0cbh ; a 'retf' opcode
  52.         jmp        short continue
  53.     
  54. abnorm:    mov        Code[8],0cbh ; a 'retf' opcode
  55.         mov        Code[7],044h ; a 'inc sp' opcode for flags on stack
  56.         mov        Code[6],044h ; a 'inc sp' opcode for flags on stack
  57.     
  58. continue:
  59.         mov        word ptr Code[2],ss    ; seg part of far call addr
  60.         lea        ax,word ptr Code[4]    ; offset part of far call addr
  61.         mov        word ptr Code[0],ax    ; we're going to jump onto the stack
  62.     
  63.         lds        di,pRegs    ; get struct REGPACK addr
  64.     
  65.         mov        ax,[di].r_ax
  66.         mov        bx,[di].r_bx
  67.         mov        cx,[di].r_cx
  68.         mov        dx,[di].r_dx
  69.         mov        si,[di].r_si
  70.         push    [di].r_di    ; save di, need it for indexing
  71.     
  72.         mov        es,[di].r_es
  73.         mov        ds,[di].r_ds
  74.         pop        di            ; restore di
  75.         push    bp
  76.         call    dword ptr Code[0] ; execute interrupt
  77.  
  78.         pop        bp        ; bp points to old bp
  79.         push    di        ; save di
  80.         push    ds
  81.     
  82.         lds        di,pRegs    ; get struct REGPACK addr
  83.     
  84.         mov        [di].r_es,es
  85.         pop        [di].r_ds
  86.     
  87.         mov        [di].r_ax,ax
  88.         mov        [di].r_bx,bx
  89.         mov        [di].r_cx,cx
  90.         mov        [di].r_dx,dx
  91.         mov        [di].r_si,si
  92.         pop        [di].r_di    ; restore di
  93.         jc        carry
  94.     
  95.         xor        si,si
  96.         jmp        short toend
  97.     
  98. carry:    mov        si,1
  99.     
  100. toend:    mov        [di].r_flags,si    ; set carry/no carry flag
  101.         pop        ds
  102.     }
  103.     return pRegs->r_ax;
  104. }
  105.  
  106. // intr.c
  107.  
  108.