home *** CD-ROM | disk | FTP | other *** search
/ C!T ROM 2 / ctrom_ii_b.zip / ctrom_ii_b / PROGRAM / PASCAL / STRLIST / CRITERR.PAS < prev    next >
Pascal/Delphi Source File  |  1992-03-11  |  3KB  |  132 lines

  1. { Plug-in Critical error handler.  By Wilbert van Leijen }
  2.  
  3. Unit CritErr;
  4.  
  5. Interface
  6.  
  7. {$IFNDEF VER60 }
  8.   ***  Version 6.0 of Turbo Pascal required  ***
  9. {$ENDIF }
  10.  
  11. Const
  12.   mClass       = 90;
  13.   mAction      = 103;
  14.   mLocus       = 110;
  15.  
  16. Var
  17.   ExtError     : Record                { Do NOT change ordering of fields }
  18.                    Code    : Word;
  19.                    Locus   : Byte;
  20.                    Action  : Byte;
  21.                    Class   : Byte;
  22.                  end;
  23.  
  24. Procedure GetExtendedError;
  25. Function ExtErrorString(i : Integer) : String;
  26.  
  27. Implementation
  28. uses Dos;
  29.  
  30. Var
  31.   SaveInt24,
  32.   ExitSave     : Pointer;
  33.  
  34. {$S- }
  35.  
  36. { Returns some information about an Extended Error Code
  37.   Add 90 to the index to get the error class message
  38.   Add 103 to the index to get the suggested action message
  39.   Add 110 to the index to get the error locus message }
  40.  
  41. Function ExtErrorString(i : Integer) : String; External;
  42. {$L ERRORSTR.OBJ }
  43.  
  44. { Get Extended Error function from DOS.  Returns information in the
  45.   ExtError structure }
  46.  
  47. Procedure GetExtendedError; Assembler;
  48.  
  49. ASM
  50.         MOV    AH, 59h
  51.         XOR    BX, BX
  52.         INT    21h
  53.         CLD
  54.         MOV    DX, SEG @Data
  55.         MOV    ES, DX
  56.         MOV    DI, Offset [ExtError]
  57.  
  58.     { Store extended error code }
  59.  
  60.         STOSW                       
  61.  
  62.     { Store error locus }
  63.  
  64.         MOV    AL, CH
  65.         STOSB
  66.         XCHG   AX, BX
  67.  
  68.     { Store error class and suggested action }
  69.  
  70.         STOSW                       
  71. end;  { GetExtendedError }
  72.  
  73. { Critical error interrupt handler, returning extended error }
  74.  
  75. Procedure Int24Handler; Assembler;
  76.  
  77. ASM
  78.         STI
  79.  
  80.     { Remove DOS INT 24h handler flags and return address }
  81.  
  82.         ADD    SP, 6
  83.  
  84.     { Get INT 21h AX register, add 150 to the error code
  85.       (this will be the value stored in InOutRes) }
  86.  
  87.         POP    AX
  88.         AND    DI, 1Fh
  89.         ADD    DI, 150
  90.  
  91.     { DI=error code, undefined for DOS functions not using file handles }
  92.  
  93.         CMP    AH, 39h
  94.         JAE    @1
  95.         MOV    DI, -1
  96.  
  97.     { Save error code }
  98.  
  99. @1:     PUSH   DI
  100.         PUSH   CS
  101.         CALL   Near Ptr GetExtendedError
  102.  
  103.     { Restore registers, and signal 'Retry' in copy of AX on stack }
  104.  
  105.         MOV    BP, SP
  106.         OR     Byte Ptr [BP+22], 1
  107.         POP    AX
  108.         POP    BX
  109.         POP    CX
  110.         POP    DX
  111.         POP    SI
  112.         POP    DI
  113.         POP    BP
  114.         POP    DS
  115.         POP    ES
  116.         IRET
  117. end;  { Int24Handler }
  118.  
  119. Procedure ExitCritErr; Far;
  120.  
  121. Begin
  122.   ExitProc := ExitSave;
  123.   SetIntVec($24, SaveInt24);
  124. end;  { ExitCritErr }
  125.  
  126. Begin  { CritErr }
  127.   ExitSave := ExitProc;
  128.   ExitProc := @ExitCritErr;
  129.   GetIntVec($24, SaveInt24);
  130.   SetIntVec($24, @Int24Handler);
  131. end.  { CritErr }
  132.