home *** CD-ROM | disk | FTP | other *** search
/ Media Share 13 / mediashare_13.zip / mediashare_13 / ZIPPED / PROGRAM / SNIP9404.ZIP / CERRTRAP.ASM < prev    next >
Assembly Source File  |  1994-04-03  |  5KB  |  135 lines

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