home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / snip9707.zip / CERRTRAP.ASM < prev    next >
Assembly Source File  |  1997-07-05  |  5KB  |  137 lines

  1. ;  +++Date last modified: 05-Jul-1997
  2.  
  3.         PAGE ,132
  4.  
  5. ;  A sample Interrupt 24 (DOS critical error exception) handler
  6. ;
  7. ;  Public domain by Bob Stout
  8. ;
  9. ;  Requires MASM 5.1 or later or equivalent
  10. ;
  11. ;  Assemble with:       MASM /Mx /z ...
  12. ;                       TASM /jMASM /mx /z ...
  13.  
  14. %       .MODEL  memodel,C               ;Add model support via command
  15.                                         ;line macros, e.g.
  16.                                         ;MASM /Dmemodel=LARGE
  17.  
  18.         EXTRN cedevdvr:dword, cetype:word, ceerror:word, cereturn:byte
  19.         EXTRN read_err:far, write_err:far, term_err:far
  20.         EXTRN no_paper:far, fixup_ret:far, FAT_err:far
  21.  
  22.         ;NOTE:  All the above routines MUST set cereturn to:
  23.         ;       0 - Ignore
  24.         ;       1 - Retry
  25.         ;       2 - Abort
  26.         ;       3 - Fail (DOS 3.3 and later)
  27.  
  28.         .DATA?
  29.  
  30.         PUBLIC  osver, rmvbl, exerr, locus, class, suggest
  31. osver   db ?
  32. rmvbl   db ?
  33. exerr   dw ?
  34. locus   db ?
  35. class   db ?
  36. suggest db ?
  37.  
  38.         .CODE
  39.  
  40. ;
  41. ;  This is called by myint24
  42. ;
  43. ;  extern int (*read_err)(),
  44. ;             (*write_err)(),
  45. ;             (*term_err)(),
  46. ;             (*no_paper)(),
  47. ;             (*fixup_ret)(),
  48. ;             (*FAT_err)();
  49. ;
  50. ;  Each returns: 0 - Ignore
  51. ;                1 - Retry
  52. ;                2 - Abort
  53. ;                3 - Fail (DOS 3.3 and later)
  54. ;
  55. mynew24 PROC    USES BX
  56.         mov     ah,030h                 ;get DOS version number
  57.         int     21
  58.         or      al,al                   ;zero means DOS 1.x
  59.         jnz     NotDOS1
  60.         mov     al,1
  61. NotDOS1:
  62.         mov     osver,al                ;save DOS version
  63.         mov     ax,cetype               ;get type of exception...
  64.         mov     bx,ax                   ; & save it for later
  65.         and     ax,80h                  ;disk error?
  66.         jnz     NotDiskErr              ;no, continue
  67.         cmp     al,1                    ;yes, DOS 1.x?
  68.         jz      wrong_DOS               ;yes, can't check for removable media
  69.         mov     ah,-1                   ;no, assume removable media
  70.         test    word PTR cedevdvr,0800h ;is the media removable?
  71.         jz      removable
  72.         xor     ah,ah                   ;no, flag fixed media
  73. removable:
  74.         mov     rmvbl,ah                ;save media type
  75.         cmp     al,3                    ;DOS 3.0 or greater?
  76.         jb      wrong_DOS               ;no, skip it
  77.         push    bx                      ;yes, save cetype info...
  78.         push    ds                      ; & other regs
  79.         push    es
  80.         push    dx
  81.         push    si
  82.         push    di
  83.         push    bp
  84.         mov     ah,59h                  ;get extended error info
  85.         int     21
  86.         pop     bp                      ;restore regs
  87.         pop     di
  88.         pop     si
  89.         pop     dx
  90.         pop     es
  91.         pop     ds
  92.         mov     exerr,ax                ;save extended error code...
  93.         mov     locus,ch                ; locus...
  94.         mov     class,bh                ;  class...
  95.         mov     suggest,bl              ;   & suggested action
  96.         pop     bx                      ;restore cetype info
  97. wrong_DOS:
  98.         mov     ax,bx                   ;get exception type
  99.         and     ax,06h                  ;FAT problems?
  100.         cmp     ax,02h
  101.         jnz     ok_fat                  ;no, continue
  102.         jmp     far PTR FAT_err         ;yes, handle it
  103. ok_fat:
  104.         mov     ax,bx                   ;get exception type
  105.         and     ax,01h                  ;handle read and write separately
  106.         jz      rd_err
  107.         jmp     far PTR write_err
  108. rd_err:
  109.         jmp     far PTR read_err
  110. NotDiskErr:
  111.         test    ceerror,0009h           ;printer out of paper?
  112.         jnz     not_eop                 ;no, continue
  113.         jmp     far PTR no_paper        ;yes, handle it
  114. not_eop:
  115.         test    word PTR cedevdvr,8000h ;character device?
  116.         jnz     unknown                 ;no, continue
  117.         jmp     far PTR term_err        ;yes, assume bad terminal I/O
  118.  
  119. ;
  120. ;  If we get here, we haven't identified the error. We now call fixup_ret()
  121. ;  to resolve which action to take. This will usually involve the information
  122. ;  in exerr qualified by the version of DOS in use and is best left to coding
  123. ;  in a higher level language like C.
  124. ;
  125. ;  NOTE: It is IMPERATIVE that the return value of fixup_ret() default to 2
  126. ;        to insure that if all else fails, the critcal error handler aborts!
  127. ;
  128.  
  129. unknown:
  130.         call    far PTR fixup_ret       ;unknown error - handle loose ends...
  131.         xor     ah,ah                   ; & return
  132.         mov     cereturn,al
  133.         ret
  134. mynew24 ENDP
  135.  
  136.         end
  137.