;
_DATA   SEGMENT DWORD PUBLIC 'DATA'
;
ctlc_vector     DD      0       ;
break_vector    DD      0       ;
;
_DATA           ENDS
;
_TEXT           SEGMENT BYTE PUBLIC 'CODE'
;
                ASSUME cs:_TEXT, ds:_DATA
;
PUBLIC          disable_traps_
PUBLIC          enable_traps_
;
;
DOS             EQU     21h             ; DOS interrupt
GET_VECTOR      EQU     35h             ; DOS Get Interrupt Vector function
SET_VECTOR      EQU     25h             ; DOS Set Interrupt Vector function
;
CTLC_INT        EQU     23h             ; control-C interrupt
BREAK_INT       EQU     1bh             ; control-break interrupt
;
;
disable_traps_  PROC far
;
; Disable trapping of ctl-C and ctl-break keys.
;
; Save existing interrupt vectors.
;
                mov     al, CTLC_INT
                mov     ah, GET_VECTOR
                int     DOS             ; vector returned in ES:BX
;
                mov     WORD PTR ctlc_vector, bx    ; save offset
                mov     WORD PTR ctlc_vector+2, es  ; save segment
;
                mov     al, BREAK_INT
                mov     ah, GET_VECTOR
                int     DOS             ; vector returned in ES:BX
;
                mov     WORD PTR break_vector, bx     ; save offset
                mov     WORD PTR break_vector+2, es   ; save segment
;
; Install vectors to new service routine.
;
                mov     ax, cs
                mov     ds, ax
                lea     dx, critical_isr        ; new vector in DS:DX
;
                mov     al, CTLC_INT
                mov     ah, SET_VECTOR
                int     DOS
;
                mov     al, BREAK_INT
                mov     ah, SET_VECTOR
                int     DOS
;
                ret
;
disable_traps_  ENDP
;
;
;
enable_traps_   PROC far
;
; Enable trapping of ctl-C and ctl-break keys.
;
; Restore previous interrupt vectors, if replaced.
;
                lds     dx, ctlc_vector ; get saved vector
                mov     ax, ds          ; test vector for segment
                or      ax, dx          ;   and offset equal to zero
                jz      @F              ; jump if vector not replaced
;
                mov     al, CTLC_INT
                mov     ah, SET_VECTOR
                int     DOS
        @@:
                lds     dx, break_vector  ; get saved vector
                mov     ax, ds            ; test vector for segment
                or      ax, dx            ;   and offset equal to zero
                jz      @F                ; jump if vector not replaced

                mov     al, BREAK_INT
                mov     ah, SET_VECTOR
                int     DOS
        @@:
                ret
;
enable_traps_   ENDP
;
;
;
critical_isr    PROC FAR
;
; Replacement critical error handler ignores ctl-C and ctl-break.
;
                iret
;
critical_isr    ENDP
;
;
;
_TEXT           ENDS
                END

