home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / caway349.zip / MISC / CRITICAL.ASM next >
Assembly Source File  |  1994-06-01  |  2KB  |  123 lines

  1. ; demo critical error handler by John Wildsmith
  2.     .386
  3.     .model small
  4.     .stack 1024
  5.  
  6.     include cw.inc
  7.  
  8. b    equ    byte ptr
  9. w    equ    word ptr
  10. d    equ    dword ptr
  11.  
  12.  
  13. ;
  14. ;If you set this EQU to nonzero then a short handler is used that simply
  15. ;returns a fail code. The longer version prompts the user for what to do.
  16. ;
  17. SHORTONE    equ    0
  18.  
  19.  
  20.     .code
  21.  
  22.  
  23. Start    proc    near
  24.     mov    ax,DGROUP        ;Make data addressable.
  25.     mov    ds,ax
  26.     ;
  27.     mov    bl,24h
  28.     sys    GetVect        ;Get current setting in case it's
  29.     mov    d[OldInt24],edx    ;needed for chaining.
  30.     mov    w[OldInt24+2],cx
  31.     mov    edx,offset CriticalHandler
  32.     mov    cx,cs
  33.     sys    SetVect        ;Install new handler.
  34.     ;
  35.     mov    edx,offset DummyName    ;Try opening a file on A: to
  36.     mov    ax,3d02h        ;trigger a critical error.
  37.     int    21h
  38.     jnc    NoError
  39.     ;
  40.     mov    edx,offset FailedMessage    ;Print a message so we know it
  41.     mov    ah,9        ;failed.
  42.     int    21h
  43.     ;
  44. NoError:    mov    ax,4c00h
  45.     int    21h
  46. Start    endp
  47.  
  48.  
  49.     if    SHORTONE
  50. ;-------------------------------------------------------------------------
  51. ;
  52. ;Critical error handler, returns FAIL code so just checking for carry should
  53. ;take care of things.
  54. ;
  55. CriticalHandler proc far
  56.     mov    ax,3
  57.     iretd
  58. CriticalHandler endp
  59.  
  60.  
  61.     else
  62.  
  63.  
  64. ;-------------------------------------------------------------------------
  65. ;
  66. ;This version prompts the user to see what they want to do.
  67. ;
  68. CriticalHandler proc far
  69.     push    ebx
  70.     push    ecx
  71.     push    edx
  72.     push    esi
  73.     push    edi
  74.     push    ebp
  75.     push    ds
  76.     push    es
  77.     mov    ax,DGROUP
  78.     mov    ds,ax
  79.     mov    es,ax
  80.     ;
  81. @@0:    mov    edx,offset CriticalPrompt
  82.     mov    ah,9        ;Display the prompt.
  83.     int    21h
  84.     mov    ah,1
  85.     int    21h        ;Get key press.
  86.     mov    edi,offset CriticalKeys
  87.     mov    ecx,8
  88.     cld
  89.     repne    scasb        ;Scan for valid response.
  90.     jnz    @@0
  91.     movzx    eax,b[edi+7]
  92.     cmp    eax,2
  93.     jz    @@Terminate        ;Terminate the program.
  94.     ;
  95.     pop    es        ;Otherwise return the code to
  96.     pop    ds        ;DOS.
  97.     pop    ebp
  98.     pop    edi
  99.     pop    esi
  100.     pop    edx
  101.     pop    ecx
  102.     pop    ebx
  103.     iretd
  104.     ;
  105. @@Terminate:    mov    ax,4cffh
  106.     int    21h
  107. CriticalHandler endp
  108.     endif
  109.  
  110.  
  111.     .data
  112. ;
  113. FailedMessage    db 13,10,"Critical error handled without problems if you see this.",13,10,"$"
  114. DummyName    db "a:test.bin",0
  115. OldInt24    df ?
  116. CriticalPrompt    db 13,10,'Critical Error: Abort, Retry, Ignore, Fail? $'
  117. CriticalKeys    db 'aArRiIfF'
  118. CriticalCodes    db 2,2,1,1,0,0,3,3
  119. ;
  120.     end    Start
  121.  
  122.  
  123.