home *** CD-ROM | disk | FTP | other *** search
/ Reverse Code Engineering RCE CD +sandman 2000 / ReverseCodeEngineeringRceCdsandman2000.iso / RCE / Library / Manuels & Misc / Assembly / AOA.ZIP / CH19 / INT24.ASM < prev    next >
Encoding:
Assembly Source File  |  1994-07-17  |  2.5 KB  |  130 lines

  1. ; Sample INT 24h critical error handler.
  2. ;
  3. ; This code demonstrates a sample critical error handler.
  4. ; It patches into INT 24h and displays an appropriate error
  5. ; message and asks the user if they want to retry, abort, ignore,
  6. ; or fail (just like DOS).
  7.  
  8.         .xlist
  9.         include     stdlib.a
  10.         includelib    stdlib.lib
  11.         .list
  12.  
  13.  
  14. dseg        segment    para public 'data'
  15.  
  16. Value        word    0
  17. ErrCode        word    0
  18.  
  19. dseg        ends
  20.  
  21. cseg        segment    para public 'code'
  22.         assume    cs:cseg, ds:dseg
  23.  
  24. ; A replacement critical error handler.  Note that this routine
  25. ; is even worse than DOS', but it demonstrates how to write
  26. ; such a routine.  Note that we cannot call any Standard Library
  27. ; I/O routines in the critical error handler because they do not
  28. ; use DOS calls 1-0Ch, which are the only allowable DOS calls at
  29. ; this point.
  30.  
  31.  
  32. CritErrMsg    byte    cr,lf
  33.         byte    "DOS Critical Error!",cr,lf
  34.         byte    "A)bort, R)etry, I)gnore, F)ail? $"
  35.  
  36. MyInt24        proc    far
  37.         push    dx
  38.         push    ds
  39.         push    ax
  40.  
  41.         push    cs
  42.         pop    ds
  43. Int24Lp:    lea    dx, CritErrMsg
  44.         mov    ah, 9            ;DOS print string call.
  45.         int    21h
  46.  
  47.         mov    ah, 1            ;DOS read character call.
  48.         int    21h
  49.         and    al, 5Fh            ;Convert l.c. -> u.c.
  50.  
  51.         cmp    al, 'I'            ;Ignore?
  52.         jne    NotIgnore
  53.         pop    ax
  54.         mov    al, 0
  55.         jmp    Quit24
  56.  
  57. NotIgnore:    cmp    al, 'r'            ;Retry?
  58.         jne    NotRetry
  59.         pop    ax
  60.         mov    al, 1
  61.         jmp    Quit24
  62.  
  63. NotRetry:    cmp    al, 'A'            ;Abort?
  64.         jne    NotAbort
  65.         pop    ax
  66.         mov    al, 2
  67.         jmp    Quit24
  68.  
  69. NotAbort:    cmp    al, 'F'
  70.         jne    BadChar
  71.         pop    ax
  72.         mov    al, 3
  73. Quit24:        pop    ds
  74.         pop    dx
  75.         iret
  76.  
  77. BadChar:    mov    ah, 2
  78.         mov    dl, 7            ;Bell character
  79.         jmp    Int24Lp
  80. MyInt24        endp
  81.  
  82.  
  83.  
  84. Main        proc
  85.         mov    ax, dseg
  86.         mov    ds, ax
  87.         mov    es, ax
  88.         meminit
  89.  
  90.         mov    ax, 0
  91.         mov    es, ax
  92.         mov    word ptr es:[24h*4], offset MyInt24
  93.         mov    es:[24h*4 + 2], cs
  94.  
  95.         mov    ah, 5
  96.         mov    dl, 'a'
  97.         int    21h
  98.         rcl    Value, 1
  99.         and    Value, 1
  100.         mov    ErrCode, ax
  101.         printf
  102.         byte    cr,lf,lf
  103.         byte    "Print char returned with error status %d and "
  104.         byte    "error code %d\n",0
  105.         dword    Value, ErrCode
  106.  
  107. Quit:        ExitPgm            ;DOS macro to quit program.
  108. Main        endp
  109.  
  110. cseg            ends
  111.  
  112.  
  113.  
  114. ; Allocate a reasonable amount of space for the stack (8k).
  115. ; Note: if you use the pattern matching package you should set up a
  116. ;    somewhat larger stack.
  117.  
  118. sseg        segment    para stack 'stack'
  119. stk        db    1024 dup ("stack   ")
  120. sseg        ends
  121.  
  122.  
  123. ; zzzzzzseg must be the last segment that gets loaded into memory!
  124. ; This is where the heap begins.
  125.  
  126. zzzzzzseg    segment    para public 'zzzzzz'
  127. LastBytes    db    16 dup (?)
  128. zzzzzzseg    ends
  129.         end    Main
  130.