home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / turpas70.zip / INTR.ASM < prev    next >
Assembly Source File  |  2000-09-03  |  4KB  |  136 lines

  1. ;*******************************************************}
  2. ;                                                       }
  3. ;       Turbo Pascal Version 7.0                        }
  4. ;       Graphic Vision Unit (GDos)                      }
  5. ;                                                       }
  6. ;       Copyright 1997,2000 Jason G Burgon              }
  7. ;                                                       }
  8. ;*******************************************************}
  9.  
  10. IDEAL
  11. %TITLE "INTR"
  12. %NOINCL
  13.  
  14. P286
  15. include "gdos.inc"
  16.  
  17. IFDEF _DPMI_
  18.  
  19. DATASEG
  20.            extrn  SelectorInc:WORD
  21. ENDS
  22.  
  23. CODESEG
  24.     public IntrApp      ; Call the given protected mode interrupt
  25.     public MsDosPM
  26.  
  27.     proc MsDosPM
  28.  
  29. ELSE
  30.  
  31. CODESEG
  32.  
  33.    public MsDos         ; Call the DOS interrupt $21
  34.    public Intr          ; Call the given (real mode) interrupt
  35.    public IntrApp       ; Call the given application (real-mode) interrupt
  36.  
  37.    proc MsDos
  38.  
  39. ENDIF
  40.             pop   si
  41.             pop   dx
  42.             pop   cx
  43.             pop   bx
  44.             mov   al,21h
  45.             push  ax
  46.             push  bx
  47.             push  cx
  48.             push  dx
  49.             push  si
  50.    endp
  51.  
  52. P8086
  53.             proc IntrApp
  54. IFNDEF _DPMI_
  55.             proc Intr
  56.             endp Intr
  57. ENDIF
  58.             arg IntNo:Byte, Regs:PRegisters
  59.             push  ds
  60. P386
  61.  
  62.  ; Self-modifying code is required here to set the Int X interrupt number
  63.  
  64.      IFDEF _DPMI_
  65.             mov   ax,cs
  66.             add   ax,[SelectorInc]
  67.             push  ax                        ; Save CS + SelectorInc
  68.             mov   ds,ax
  69.             push  [word ptr ds:Interrupt]   ; Save self-modified byte
  70.             mov   al,[IntNo]
  71.         mov   [byte ptr ds:Interrupt+1],al
  72.      ELSE
  73.             push  [word ptr cs:Interrupt]   ; Save self-modified byte
  74.             mov   al,[IntNo]
  75.             mov   [byte ptr cs:Interrupt+1],al
  76.      ENDIF
  77.             lds   si,[Regs]
  78.             mov   ebx,[si+TRegisters.EBX]   ; EBX = Regs.EBX
  79.             mov   ecx,[si+TRegisters.ECX]   ; ECX = Regs.ECX
  80.             push  [si+TRegisters.EAX]       ; push user EAX on stack
  81.             mov   edx,[si+TRegisters.EDX]   ; EDX = Regs.EDX
  82.             mov   ebp,[si+TRegisters.EBP]   ; BP = Regs.BP
  83.             push  [si+TRegisters.ESI]       ; push user ESI on stack
  84.             mov   edi,[si+TRegisters.EDI]   ; EDI = Regs.EDI
  85.     IFDEF _DPMI_
  86.             mov   ax,[si+TRegisters.ES]
  87.             verr  ax
  88.             jnz   @@1
  89.             xor   ax,ax
  90. @@1:        mov   es,ax                     ; ES = Regs.ES or zero
  91.             mov   ax,[si+TRegisters.DS]
  92.             verr  ax
  93.             jnz   @@2
  94.             xor   ax,ax
  95. @@2:        mov   ds,ax                     ; DS = Regs.ES or zero
  96.     ELSE
  97.             mov   es,[si+TRegisters.ES]     ; ES = Regs.ES
  98.             mov   ds,[si+TRegisters.DS]     ; DS = Regs.DS Regs not available
  99.     ENDIF
  100.             pop   esi                       ; SI = Regs.ESI
  101.             pop   eax                       ; AX = Regs.EAX
  102.  
  103. Interrupt:  int   0
  104.  
  105.             pushf                           ; push new Regs.Flags
  106.             push  ds                        ; push new Regs.DS
  107.             push  esi                       ; push new Regs.SI
  108.             push  ebp                       ; push new Regs.BP
  109.             mov   bp,sp                     ; Restore stack frame
  110.             add   bp,4 * (type Word) + 2 * (type dword) ; Restore local BP
  111.             lds   si,[Regs]                 ; DS:SI = @Regs
  112.             mov   [si+TRegisters.EAX],eax
  113.             mov   [si+TRegisters.EBX],ebx
  114.             mov   [si+TRegisters.ECX],ecx
  115.             mov   [si+TRegisters.EDX],edx
  116.             mov   [si+TRegisters.EDI],edi
  117.             mov   [si+TRegisters.ES],es
  118.             pop   [si+TRegisters.EBP]       ; pop new Regs.BP
  119.             pop   [si+TRegisters.ESI]       ; pop new Regs.SI
  120.             pop   [si+TRegisters.DS]        ; pop new Regs.DS
  121.             pop   [si+TRegisters.Flags]     ; pop new Regs.Flags
  122.     IFDEF _DPMI_
  123.             pop   ds                        ; DS = CS + SelectorInc
  124.         pop   [word ptr ds:Interrupt]   ; Restore Self-modified byte
  125.     ELSE
  126.         pop   [word ptr cs:Interrupt]   ; Restore Self-modified byte
  127.     ENDIF
  128.             pop   ds                        ; Restore global DS
  129. P8086
  130.             ret
  131. endp
  132.  
  133. ENDS
  134.  
  135. END
  136.