home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / PASCAL / BONUS40.ZIP / BREAK.ZIP / BREAK.PAS < prev   
Encoding:
Pascal/Delphi Source File  |  1988-01-02  |  2.8 KB  |  88 lines

  1. {$R-,S-,I-}
  2.  
  3. unit Break;
  4.  
  5. { A unit to allow Control-Break to interrupt program execution.
  6.  
  7.   Version 1.00 -  1/02/1987 - First general release
  8.  
  9.   Scott Bussinger
  10.   Professional Practice Systems
  11.   110 South 131st Street
  12.   Tacoma, WA  98444
  13.   (206)531-8944
  14.   Compuserve 72247,2671 }
  15.  
  16.  
  17. interface
  18.  
  19. uses Dos;
  20.  
  21.  
  22. implementation
  23.  
  24. const ControlBreakFlag: boolean = false;
  25.  
  26. var ExitSave: pointer;
  27.     SaveInt8: pointer;
  28.     SaveInt1B: pointer;
  29.  
  30. procedure JmpOldISR(OldISR: pointer);
  31.   { Chain to previous interrupt handler }
  32.   inline($5B/                   {  pop bx             ;BX = Ofs(OldIsr)}
  33.          $58/                   {  pop ax             ;AX = Seg(OldIsr)}
  34.          $87/$5E/$0E/           {  xchg bx,[bp+14]    ;Switch old BX and Ofs(OldIsr)}
  35.          $87/$46/$10/           {  xchg ax,[bp+16]    ;Switch old AX and Seg(OldIsr)}
  36.          $89/$EC/               {  mov sp,bp          ;Restore SP}
  37.          $5D/                   {  pop bp             ;Restore BP}
  38.          $07/                   {  pop es             ;Restore ES}
  39.          $1F/                   {  pop ds             ;Restore DS}
  40.          $5F/                   {  pop di             ;Restore DI}
  41.          $5E/                   {  pop si             ;Restore SI}
  42.          $5A/                   {  pop dx             ;Restore DX}
  43.          $59/                   {  pop cx             ;Restore CX}
  44.          $CB);                  {  retf               ;Chain to OldIsr, leaving CS and IP params on the stack}
  45.  
  46. procedure HaltProgram;
  47.   { Simple routine to halt the program }
  48.   begin
  49.   halt(255)                                      { 255 is the standard error code for ^Break }
  50.   end;
  51.  
  52. {$F+}
  53. procedure ControlBreakHandler(Flags,CS,IP,AX,BX,CX,DX,SI,DI,DS,ES,BP: Word); interrupt;
  54.   { Set a flag on seeing a ^Break }
  55.   begin
  56.   ControlBreakFlag := true
  57.   end;
  58.  
  59. procedure TimerHandler(Flags,CS,IP,AX,BX,CX,DX,SI,DI,DS,ES,BP: Word); interrupt;
  60.   { Check to see that things are safe and then halt program if ^Break flag is set }
  61.   begin
  62.   if ControlBreakFlag and                        { Wait for ^Break to be hit }
  63.      (CS>=PrefixSeg) and (CS<DSeg) then          { Make sure we're in our program (and not in DOS, etc.) }
  64.     begin
  65.     CS := seg(HaltProgram);                      { Return to the halt routine }
  66.     IP := ofs(HaltProgram)
  67.     end;
  68.   JmpOldISR(SaveInt8)                            { Chain to other timer interrupts }
  69.   end;
  70.  
  71. procedure ExitHandler;
  72.   { Cleanup after ourselves }
  73.   begin
  74.   ExitProc := ExitSave;
  75.   SetIntVec($08,SaveInt8);
  76.   SetIntVec($1B,SaveInt1B)
  77.   end;
  78. {$F-}
  79.  
  80. begin
  81. ExitSave := ExitProc;
  82. ExitProc := @ExitHandler;
  83. GetIntVec($08,SaveInt8);
  84. GetIntVec($1B,SaveInt1B);
  85. SetIntVec($1B,@ControlBreakHandler);
  86. SetIntVec($08,@TimerHandler)
  87. end.
  88.