home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 5 / 05.iso / a / a013 / 1.ddi / SOURCE.EXE / INT24.ASM < prev    next >
Encoding:
Assembly Source File  |  1991-01-25  |  6.2 KB  |  154 lines

  1. ; ---------------------------------------------------------------
  2. ; FILENAME:  INT24.ASM  -- Critical error (interrupt 24) handler
  3. ;
  4. ; FUNCTIONS:
  5. ;
  6. ; INT24 ---- Internal function. Called by DOS on a critical error
  7. ; GETINT24 - Returns a critical error number to Clipper
  8. ; SETINT24 - Activates the critical error (interrupt 24) handler
  9. ; ---------------------------------------------------------------
  10. ; Copyright(c)  1988-1990 - James Occhiogrosso
  11. ;
  12. INCLUDE DEVELOP.MAC      ; Include Developer's Library macro file
  13.  
  14.                          ; Declare function names
  15. PUBLIC   SETINT24        ; Sets DOS INT24 vector to our function
  16. PUBLIC   GETINT24        ; Returns INT24 critical error code
  17. PUBLIC   INT24           ; Our internal INT24 handler
  18.  
  19.  
  20.                          ; Declare Clipper externals
  21. EXTRN    __RET:FAR       ; Return nothing to Clipper
  22. EXTRN    __RETNI:FAR     ; Return numeric integer to Clipper
  23. EXTRN    __RETL:FAR      ; Return logical to Clipper
  24. EXTRN    __PARINFO:FAR   ; Get Clipper parameter information
  25. EXTRN    __PARL:FAR      ; Get Clipper logical
  26.  
  27. CODESEG  SEGMENT 'CODE'
  28.          ASSUME CS:CODESEG
  29.  
  30. ;----------------------------------------------------------------
  31. SETINT24 PROC  FAR              ; Toggle setting of INT24 handler
  32. ;----------------------------------------------------------------
  33.  
  34.          JMP BEGIN              ; Jump around data storage area
  35.  
  36.          OLD_INT24  DD ?        ; Storage for DOS INT24 address
  37.          RET_VALUE  DB 0        ; SETINT24 return value
  38.          INT24_STAT DB 0        ; Current INT24 handler status
  39.          INT24_ERR  DB 0        ; GETINT24 error number
  40.  
  41.  
  42. BEGIN:
  43.          PUSH_REGS              ; Save Clipper registers
  44.  
  45.          P_TYPE 1               ; Get parameter type to AX
  46.          CMP AX, 4              ; Was a logical value passed?
  47.          MOV AH, 0              ; No! Set up for the current
  48.          MOV AL, CS:INT24_STAT  ;     status byte to be
  49.          JNE SET_RETURN         ;     returned to Clipper
  50.  
  51.          GET_PARL  1            ; Yes! Put logical value in AX
  52.          MOV CX, AX             ; Save passed parameter in CX
  53.          MOV AH, 0
  54.          MOV AL, CS:INT24_STAT  ; Get current handler status
  55.          CMP AX, CX             ; Is it same as incoming?
  56.          JNE CONTINUE           ; No! Continue
  57.  
  58. SET_RETURN:
  59.          MOV CS:RET_VALUE, AL   ; Yes! Set up return value
  60.          JMP EXIT_SETINT24      ;    and return it to Clipper
  61.  
  62. CONTINUE:
  63.          PUSH CS                ; Move code segment address
  64.          POP DS                 ;   into data segment register
  65.          ASSUME DS:NOTHING      ;   and tell the assembler.
  66.          MOV CS:RET_VALUE, AL   ; Set return to current status
  67.          CMP CX, 1              ; Are we installing interrupt?
  68.          JE  INSTALL_INT24      ; Yes! Set DOS vector address
  69.  
  70. REMOVE_INT24:                   ; No! Default to removing it
  71.          CMP CS:INT24_STAT, 0   ; Is it already removed?
  72.          JE  EXIT_SETINT24      ; Yes! Return to Clipper
  73.  
  74.          MOV CS:INT24_STAT, 0   ; No! Change handler status byte
  75.          MOV CS:INT24_ERR, 0    ; Reset error number to 0.
  76.          MOV DI, OFFSET CS:OLD_INT24   ; Get data address for DOS
  77.                                        ; INT24 handler
  78.          MOV DX, [DI]           ; Move offset to DX
  79.          MOV DS, [DI+2]         ; Move segment to DS
  80.          JMP SET_VECTOR         ; Set vector to original value
  81.  
  82. INSTALL_INT24:
  83.          CMP CS:INT24_STAT, 1   ; Is it already installed?
  84.          JE  EXIT_SETINT24      ; Yes! Return to Clipper
  85.  
  86.          MOV CS:INT24_STAT, 1   ; No! Set handler status byte
  87.          MOV CS:RET_VALUE,  0   ; Reset return value to zero
  88.          MOV CS:INT24_ERR,  0   ; Reset error number to 0
  89.          MOV AL, 24h            ; DOS critical error handler
  90.          MOV AH, 35h            ; DOS request for vector address
  91.          INT 21h
  92.  
  93.          MOV DI, OFFSET CS:OLD_INT24 ; Get address for old vector
  94.          MOV [DI], BX           ; Save offset
  95.          MOV [DI+2], ES         ; Save segment
  96.  
  97.          MOV DX, OFFSET CS:INT24  ; Get address of our handler
  98.  
  99. SET_VECTOR:
  100.          MOV AL, 24h            ; DOS critical error handler
  101.          MOV AH, 25h            ; DOS request to set vector
  102.          INT 21h
  103.  
  104. EXIT_SETINT24:
  105.          SUB AH, AH             ; Put Clipper return value
  106.          MOV AL, CS:RET_VALUE   ;   in AX
  107.          POP_REGS               ; Restore all registers
  108.          RET_LOGIC              ; Return logic value to Clipper
  109.  
  110. SETINT24 ENDP                   ; End SETINT24 procedure
  111.  
  112.  
  113. ;----------------------------------------------------------------
  114. GETINT24 PROC  FAR         ; Return INT24 error number to Clipper
  115. ;----------------------------------------------------------------
  116.  
  117.          SUB AX, AX             ; Get pending error code
  118.          MOV AL, CS:INT24_ERR
  119.          MOV CS:INT24_ERR, 0    ; Reset code to zero
  120.          RET_INT                ; Return error code to Clipper
  121.  
  122. GETINT24 ENDP                   ; End Procedure
  123.  
  124.  
  125. ;----------------------------------------------------------------
  126. INT24    PROC  FAR         ; Critical error (INT24) handler
  127. ;----------------------------------------------------------------
  128.  
  129. ; This is the actual interrupt handler procedure. It replaced the
  130. ; normal DOS INT 24 handler, and stores the critical error in its
  131. ; code segment for return to Clipper.
  132.  
  133.          CMP AH, 128             ; Disk status byte - if < 128,
  134.          JB SAVE_ERROR           ; error was disk I/O, save it
  135.  
  136.          JMP DWORD PTR CS:[OLD_INT24] ; Otherwise, let DOS handle 
  137.          JMP EXIT_INT24               ; it, then return.
  138.  
  139. SAVE_ERROR:
  140.          MOV AX, DI              ; Put the error number in AX,
  141.          INC AL                  ; Increment for Clipper return
  142.          MOV CS:INT24_ERR, AL    ;   and save it
  143.          MOV AX, 3               ; Tell DOS to return 
  144.                                  ;   using Int 23h
  145. EXIT_INT24:
  146.          IRET                    ; Return from INT24 handler
  147.  
  148. INT24    ENDP                    ; End interrupt handler
  149.  
  150.  
  151. CODESEG  ENDS                    ; End of code segment
  152.          END                     ; End of assembly
  153.  
  154.