home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / PASCAL / WIH.ZIP / SIH.INC < prev    next >
Encoding:
Text File  |  1987-02-01  |  3.1 KB  |  66 lines

  1. {include code for interupt handler}
  2. {The following must be provided to use this code:
  3.   1.  a procedure name,
  4.   2.  a definition of the type RegisterSet,
  5.   3.  an integer constant, Interupt_Number,
  6.   4.  a series of integer variables and a register set declared
  7.       as global variables exactly as follows:
  8.         Var
  9.           IntAX,IntBX,IntCX,IntDX,IntBP,IntSI,IntDI,IntDS,IntES,
  10.             IntFlags           : Integer;
  11.           Interupt_Registers   : RegisterSet Absolute IntAX;
  12.    5. a procedure, User_Procedure.  It has no formal parameters, but may
  13.       use the register set Interupt_Registers defined above.}
  14. {The first time this procedure is called it will attach itself to the software
  15.  interupt vector specificed in Interupt_Number.  The calling program must
  16.  terminate and stay resident using DOS Function $31.}
  17. {Subsequently, when that Interupt is activated this code will again take
  18.  control, obtain the current register values, and activate User_Procedure.}
  19. {When User_Procedure returns control, this code reloads the registers
  20.  and performs an IRET to pass control to the interupting program.}
  21.  
  22. Const
  23.    First_Time           : Boolean = True;
  24.                           {Beginning of code to save registers}
  25.    Save_Regs            : Array[1..20] of Byte =
  26.                           ($1E,$06,$FB,$50,$90,         {Push ES, DS, and SS}
  27.                            $B8,$00,$00,$8E,$C8,$90,     {set CSeg}
  28.                            $B8,$00,$00,$8E,$D8,$58,$90, {set DSeg}
  29.                            $EB,$03);                    {jump to inline code}
  30. Var
  31.    Setup                : RegisterSet;
  32.    Seg_Save_Pointer     : Array[1..10] of Integer Absolute Save_Regs;
  33.  
  34. Begin (* Software Interupt Handler *)
  35.   Inline ($A3/IntAX/ {capture registers}
  36.                      $8B/$C1/$A3/IntCX/
  37.                      $8B/$C2/$A3/IntDX/
  38.                      $8B/$C3/$A3/IntBX/
  39.                      $8B/$C5/$A3/IntBP/
  40.                      $8B/$C6/$A3/IntSI/
  41.                      $8B/$C7/$A3/IntDI);
  42.  
  43.   If First_Time Then Begin          {code to initialize program}
  44.      First_Time := False;
  45.      Seg_Save_Pointer[4] := Cseg;  {modify code in Save_Regs to preserve}
  46.      Seg_Save_Pointer[7] := Dseg;  {code and data segment registers     }
  47.      Setup.DS := Seg(Save_Regs[1]); {get absolute address of code in Save_Regs}
  48.      Setup.DX := Ofs(Save_Regs[1]); {and use it in function call              }
  49.      Setup.AL := Interupt_Number;   {Unused interupt}
  50.      Setup.AH := $25;               {DOS Function to set interupt vector}
  51.      MsDos(Setup); End
  52.  
  53.   Else Begin                        {code execute with each interupt}
  54.    User_Procedure;
  55.    Inline ( $A1/IntCX/$89/$C1/
  56.             $A1/IntDX/$89/$C2/
  57.             $A1/IntBX/$89/$C3/
  58.             $A1/IntBP/$89/$C5/
  59.             $A1/IntSI/$89/$C6/
  60.             $A1/IntDI/$89/$C7/
  61.             $A1/IntAX/ {restore registers}
  62.             $07/$1F/ {Pop ES and DS} $CF {and return from interupt } );
  63.                      {NOTE: do not attempt to restore stack pointer}
  64.   End;               {      as shown in Turbo V3.0 Reference Manual}
  65.  
  66. End;{Software Interupt Handler}