home *** CD-ROM | disk | FTP | other *** search
- {include code for interupt handler}
- {The following must be provided to use this code:
- 1. a procedure name,
- 2. a definition of the type RegisterSet,
- 3. an integer constant, Interupt_Number,
- 4. a series of integer variables and a register set declared
- as global variables exactly as follows:
- Var
- IntAX,IntBX,IntCX,IntDX,IntBP,IntSI,IntDI,IntDS,IntES,
- IntFlags : Integer;
- Interupt_Registers : RegisterSet Absolute IntAX;
- 5. a procedure, User_Procedure. It has no formal parameters, but may
- use the register set Interupt_Registers defined above.}
- {The first time this procedure is called it will attach itself to the software
- interupt vector specificed in Interupt_Number. The calling program must
- terminate and stay resident using DOS Function $31.}
- {Subsequently, when that Interupt is activated this code will again take
- control, obtain the current register values, and activate User_Procedure.}
- {When User_Procedure returns control, this code reloads the registers
- and performs an IRET to pass control to the interupting program.}
-
- Const
- First_Time : Boolean = True;
- {Beginning of code to save registers}
- Save_Regs : Array[1..20] of Byte =
- ($1E,$06,$FB,$50,$90, {Push ES, DS, and SS}
- $B8,$00,$00,$8E,$C8,$90, {set CSeg}
- $B8,$00,$00,$8E,$D8,$58,$90, {set DSeg}
- $EB,$03); {jump to inline code}
- Var
- Setup : RegisterSet;
- Seg_Save_Pointer : Array[1..10] of Integer Absolute Save_Regs;
-
- Begin (* Software Interupt Handler *)
- Inline ($A3/IntAX/ {capture registers}
- $8B/$C1/$A3/IntCX/
- $8B/$C2/$A3/IntDX/
- $8B/$C3/$A3/IntBX/
- $8B/$C5/$A3/IntBP/
- $8B/$C6/$A3/IntSI/
- $8B/$C7/$A3/IntDI);
-
- If First_Time Then Begin {code to initialize program}
- First_Time := False;
- Seg_Save_Pointer[4] := Cseg; {modify code in Save_Regs to preserve}
- Seg_Save_Pointer[7] := Dseg; {code and data segment registers }
- Setup.DS := Seg(Save_Regs[1]); {get absolute address of code in Save_Regs}
- Setup.DX := Ofs(Save_Regs[1]); {and use it in function call }
- Setup.AL := Interupt_Number; {Unused interupt}
- Setup.AH := $25; {DOS Function to set interupt vector}
- MsDos(Setup); End
-
- Else Begin {code execute with each interupt}
- User_Procedure;
- Inline ( $A1/IntCX/$89/$C1/
- $A1/IntDX/$89/$C2/
- $A1/IntBX/$89/$C3/
- $A1/IntBP/$89/$C5/
- $A1/IntSI/$89/$C6/
- $A1/IntDI/$89/$C7/
- $A1/IntAX/ {restore registers}
- $07/$1F/ {Pop ES and DS} $CF {and return from interupt } );
- {NOTE: do not attempt to restore stack pointer}
- End; { as shown in Turbo V3.0 Reference Manual}
-
- End;{Software Interupt Handler}