home *** CD-ROM | disk | FTP | other *** search
/ Piper's Pit BBS/FTP: ibm 0000 - 0009 / ibm0000-0009 / ibm0003.tar / ibm0003 / TPOWER53.ZIP / TPASM.ARC / TPINT.ASM < prev    next >
Encoding:
Assembly Source File  |  1989-07-10  |  3.2 KB  |  136 lines

  1. ;******************************************************
  2. ;            TPINT.ASM 5.07
  3. ;          Interrupt routines
  4. ;     Copyright (c) TurboPower Software 1987.
  5. ; Portions copyright (c) Sunny Hill Software 1985, 1986
  6. ;     and used under license to    TurboPower Software
  7. ;         All rights reserved.
  8. ;******************************************************
  9.  
  10.     INCLUDE    TPCOMMON.ASM
  11.  
  12. ;******************************************************    Equates
  13.  
  14. ;Fields    in an IntRegisters variable
  15.  
  16.     BpR    =    0
  17.     EsR    =    2
  18.     DsR    =    4
  19.     DiR    =    6
  20.     SiR    =    8
  21.     DxR    =    10
  22.     CxR    =    12
  23.     BxR    =    14
  24.     AxR    =    16
  25.     Flags    =    22
  26.  
  27. ;******************************************************    Code
  28.  
  29. CODE    SEGMENT    BYTE PUBLIC
  30.  
  31.     ASSUME    CS:CODE
  32.  
  33.     PUBLIC    EmulateInt
  34.  
  35. ;******************************************************    EmulateInt
  36.  
  37. ;procedure EmulateInt(var Regs : IntRegisters; IntAddr : Pointer);
  38.  
  39. ;Emulates an interrupt by filling the CPU registers with the values in Regs,
  40. ;clearing interrupts, pushing the flags, and calling far to IntAddr.
  41.  
  42. ;Equates for parameters
  43.  
  44. IntAddr    EQU    DWORD PTR [BP+6]
  45. Regs    EQU    DWORD PTR [BP+10]
  46. Regs2    EQU    DWORD PTR [BP+16]    ;Regs after the    'interrupt' - pushed
  47.                     ;BP, DS, and flags figure into
  48.                     ;equation the second time around
  49.  
  50. ;Temporary variable stored in the code segment
  51.  
  52.     IntAddress    Pointer    <>
  53.  
  54. EmulateInt    PROC FAR
  55.  
  56.     PUSH    BP                ;Save BP
  57.     MOV    BP,SP                ;Set up    stack frame
  58.     PUSHF                    ;Save flags
  59.     PUSH    DS                ;Save DS
  60.  
  61.     ;Load registers    with contents of Regs
  62.  
  63.     LDS    DI,Regs                ;DS:DI points to Regs
  64.     MOV    AH,[DI].Flags            ;Get new flags into AH
  65.     SAHF                    ;Load flags from AH
  66.     MOV    AX,[DI].AxR            ;Load AX
  67.     MOV    BX,[DI].BxR            ;Load BX
  68.     MOV    CX,[DI].CxR            ;Load CX
  69.     MOV    DX,[DI].DxR            ;Load DX
  70.  
  71.     ;Set up    for the    far call with interrupts off --    this section of    code
  72.     ;is not    re-entrant
  73.  
  74.     LES    SI,IntAddr            ;ES:SI points to IntAddr
  75.     CLI                    ;Interrupts off
  76.     MOV    CS:IntAddress.Ofst,SI        ;Save offset of    IntAddr
  77.     MOV    CS:IntAddress.Segm,ES        ;Save segment
  78.     MOV    BP,[DI].BpR            ;Load BP
  79.     MOV    SI,[DI].SiR            ;Load SI
  80.     MOV    ES,[DI].EsR            ;Load ES
  81.     PUSH    [DI].DsR            ;PUSH new DS
  82.     MOV    DI,[DI].DiR            ;Load DI
  83.     POP    DS                ;POP new DS
  84.  
  85.     ;Emulate interrupt
  86.  
  87.     PUSHF                    ;PUSH flags
  88.     CALL    DWORD PTR CS:IntAddress        ;Call IntAddr
  89.  
  90.     ;Get ready to load Regs
  91.  
  92.     PUSH    BP                ;Save BP
  93.     MOV    BP,SP                ;Set up    stack frame
  94.     PUSHF                    ;Save Flags
  95.     PUSH    ES                ;Save ES
  96.     PUSH    DI                ;Save DI
  97.  
  98.     ;Load Regs with    new values
  99.  
  100.     LES    DI,Regs2            ;ES:DI points to Regs
  101.     ADD    DI,AxR                ;ES:DI points to Regs.AX
  102.     STD                    ;Go backward
  103.     STOSW                    ;Store AX
  104.     MOV    AX,BX                ;Get BX    into AX    and store it
  105.     STOSW
  106.     MOV    AX,CX                ;Get CX    into AX    and store it
  107.     STOSW
  108.     MOV    AX,DX                ;Get DX    into AX    and store it
  109.     STOSW
  110.     MOV    AX,SI                ;Get SI    into AX    and store it
  111.     STOSW
  112.     POP    AX                ;POP saved DI into AX
  113.     STOSW
  114.     MOV    AX,DS                ;Get DS    into AX    and store it
  115.     STOSW
  116.     POP    AX                ;POP saved ES into AX
  117.     STOSW
  118.                         ;ES:DI now points to Regs.BP
  119.     POP    AX                ;POP saved Flags into AX
  120.     POP    ES:[DI]                ;POP saved BP into place
  121.     MOV    ES:[DI].Flags,AL        ;Store low byte    of flags
  122.     CLD                    ;Clear direction flag
  123.  
  124.     ;Clean up and return
  125.  
  126.     POP    DS                ;Restore DS
  127.     POPF                    ;Restore flags
  128.     POP    BP                ;Restore BP
  129.     RET    8
  130.  
  131. EmulateInt    ENDP
  132.  
  133. CODE    ENDS
  134.  
  135.     END
  136.