home *** CD-ROM | disk | FTP | other *** search
/ Groovy Bytes: Behind the Moon / groovybytes.iso / GROOVY / SND_TOOL / FUNK108A.ZIP / DOS32V30.ZIP / EXAMPLES / REALMODE.ASM < prev    next >
Encoding:
Assembly Source File  |  1995-06-07  |  3.6 KB  |  154 lines

  1. ; REALMODE.ASM
  2. ;
  3. ;     Example on hooking a real mode interrupt.
  4. ;
  5. ; This program will hook real mode interrupt 24h which is the DOS critical
  6. ; error handler. Normally the command interpreter ( e.g COMMAND.COM )
  7. ; hooks this interrupt and displays a message on the screen asking the user
  8. ; to Abort, Ignore, Fail or Retry the operation.
  9. ; The protected mode critical error handler below works in a similar way.
  10. ;
  11. ;
  12. .386
  13. .model flat
  14. .stack
  15.  
  16. .data
  17.  
  18. Address_Zero            DD ?
  19. Old_RM_Int24h_vector    DD ?
  20. return_code             db ?
  21.  
  22. .code
  23.  
  24. dummyfile    db 'a:\d',0
  25. mesg1        db ' Please remove disk from drive A, so that the INT 24h critical error is called.'
  26.              db 13,10,13,10,'Press any key ...',13,10,36
  27. exit_mesg    db 'Program is exiting ',13,10,36
  28.  
  29.  
  30. start:
  31.  
  32.   ; Call get DOS32 address information. We need to find a pointer that
  33.   ; will address physical location zero.
  34.  
  35.     mov    AX,0EE02h
  36.     int    31h
  37.     neg    ebx
  38.     mov    Address_Zero,ebx
  39.  
  40.   ;
  41.   ; Save the real mode INT 24h vector before we modify it
  42.   ;
  43.     mov    esi,Address_Zero
  44.     mov    eax,[esi+24h*4]
  45.     mov    Old_RM_Int24h_vector,eax
  46.  
  47.  
  48.    ;
  49.    ; Allocate a real mode call back address ( for an IRET stack frame).
  50.    ;
  51.     mov     ax,0EE21h
  52.     mov     esi,Offset CallBack_Handler
  53.     int     31h
  54.     jc Exit
  55.  
  56.  
  57.    ;
  58.    ; Set the real mode INT 24h vector to the returned real mode address (CX:DX)
  59.    ;
  60.     mov    esi,Address_Zero
  61.     mov    [esi+24h*4],dx
  62.     mov    [esi+24h*4+2],cx
  63.  
  64.  
  65.   ; Display a message to let the user know the critical error handler
  66.   ; is about to be invoked.
  67.     mov     edx,offset mesg1
  68.     mov     ah,9
  69.     int     21h
  70.     mov     ah,0            ; wait for a key
  71.     int     16h
  72.  
  73.   ;
  74.   ; Access drive A just to make DOS invoke INT 24h.
  75.   ;
  76.     mov     ax,3D00h
  77.     mov     edx,offset dummyfile
  78.     int     21h
  79.  
  80.    ;
  81.    ; Restore the origonal real mode INT 24h vector
  82.    ;
  83.     mov    esi,Address_Zero
  84.     mov    eax,Old_RM_Int24h_vector
  85.     mov    [esi+24h*4],eax
  86.  
  87.    ;
  88.    ; Exit program with a message.
  89.    ;
  90.         mov     edx,offset exit_mesg
  91.         mov     ah,9
  92.         int     21h
  93. Exit:   mov     ax,4c00h
  94.         int     21h
  95.  
  96.  
  97. ;************************************************************************
  98. ;
  99. ; THE CRITICAL ERROR HANDLER
  100. ;
  101. ;************************************************************************
  102. CallBack_Handler PROC FAR
  103.         push     ds                                 ; Save registers used
  104.         pushad
  105.         mov        ax,_DATA                           ; load DS with data selector
  106.         mov     ds,ax
  107.  
  108.         mov     edx,offset Error_message
  109.         mov     ah,9
  110.         int     21h
  111.  
  112.   ; Loop around to read the keyboard
  113.   ;
  114.  
  115. getkeyLOOP:
  116.         mov     ah,0            ; get key
  117.         int     16h
  118.         cmp     ah,17h
  119.         jne  J09
  120.          mov    return_code,0   ; ignore
  121.          jmp gotkey
  122. J09:
  123.         cmp     ah,21h
  124.         jne  J08
  125.          mov    return_code,3   ; Fail
  126.          jmp gotkey
  127. J08:
  128.         cmp     ah,13h
  129.         jne  J07
  130.          mov    return_code,1   ; Try again
  131.          jmp gotkey
  132. J07:
  133.     jmp getkeyLOOP
  134. gotkey:
  135.  
  136.  
  137.         popad
  138.         mov     al,return_code
  139.         pop     ds
  140.         retf                    ; Return from the Real Mode call back.
  141.  
  142. Error_message  LABEL BYTE
  143. db 13,10
  144. db ' The critical error handler has been invoked (protected mode) ',10,13,10
  145. db ' Please select one of the following actions ',13,10
  146. db ' F) fail',13,10
  147. db ' R) retry',13,10
  148. db ' I) ignore',13,10
  149. db '$'
  150.  
  151. CallBack_Handler ENDP
  152.  
  153. end start
  154.