home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS - Coast to Coast / simteldosarchivecoasttocoast2.iso / asmutil / 80x0393.zip / CTRLC.ASM < prev    next >
Assembly Source File  |  1992-09-30  |  3KB  |  115 lines

  1. ; CTRLC.ASM
  2. ; Trap Ctrl-C, Ctrl-Break, and PrintScreen
  3. ; Public domain by Matthew Hildebrand
  4. ; This module may not be overlaid
  5.  
  6. IDEAL
  7. P386                                  ; no 386 code; just for alignment
  8. MODEL LARGE
  9.  
  10.         CODESEG
  11.  
  12.         LABEL old9Vect DWORD
  13. old9Off        dw        ?
  14. old9Seg        dw        ?
  15. old1BOff       dw        ?
  16. old1BSeg       dw        ?
  17.  
  18.  
  19.         PUBLIC C disableCtrlC
  20. PROC C disableCtrlC
  21.   push ds
  22.  
  23.   mov ax,3509h                        ; get the old 09h vector
  24.   int 21h
  25.   mov [old9Off],bx
  26.   mov [old9Seg],es
  27.   mov ax,251Bh                        ; get the old 1Bh vector
  28.   int 21h
  29.   mov [old1BOff],bx
  30.   mov [old1BSeg],es
  31.  
  32.   mov ax,2509h                        ; set the new 09h vector
  33.   mov dx,SEG isr
  34.   mov ds,dx
  35.   mov dx,OFFSET isr
  36.   int 21h
  37.   mov ax,251Bh                        ; set the new 1Bh vector
  38.   mov dx,SEG ctrlBreak
  39.   mov ds,dx
  40.   mov dx,OFFSET ctrlBreak
  41.   int 21h
  42.  
  43.   pop ds
  44.   retcode
  45. ENDP
  46.  
  47.         PUBLIC C enableCtrlC
  48. PROC C enableCtrlC
  49.   push ds
  50.  
  51.   mov ax,2509h                        ; restore the old 09h vector
  52.   mov ds,[old9Seg]
  53.   mov dx,[old9Off]
  54.   int 21h
  55.   mov ax,251Bh                        ; restore the old 1Bh vector
  56.   mov ds,[old1BSeg]
  57.   mov dx,[old1BOff]
  58.   int 21h
  59.  
  60.   pop ds
  61.   retcode
  62. ENDP
  63.  
  64. PROC isr FAR
  65.   push ax dx es
  66.  
  67.   in al,60h                           ; read keyboard input
  68.   mov ah,al                           ; store it
  69.   test al,80h                         ; was key pressed or released?
  70.   jz @@L1
  71.   xor dl,dl                           ; released
  72.   jmp short @@L2
  73.         @@L1:
  74.   mov dl,1                            ; pressed
  75.  
  76.         @@L2:
  77.   ; Trap unwanted keystrokes
  78.   and al,01111111b                    ; strip high bit
  79.  
  80.   cmp al,55                           ; PrintScreen
  81.   je @@Exit
  82.  
  83.   cmp al,46                           ; C
  84.   jne @@oldHandler
  85.   mov ah,12h                          ; Get enhanced keyboard flags
  86.   int 16h
  87.   test al,00000100b                   ; bit for either Ctrl key pressed
  88.   jne @@Exit
  89.  
  90.         @@oldHandler:                 ; Pass control to old handler
  91.   pushf                               ; so old9Vect's iret will work
  92.   call [old9Vect]
  93.   pop es dx ax
  94.   iret
  95.  
  96.         @@Exit:                       ; Ignore a keystroke
  97.   in al,61h                           ; acknowledge keystroke
  98.   mov ah,al
  99.   or al,80h
  100.   out 61h,al
  101.   mov al,ah
  102.   out 61h,al
  103.   mov al,20h
  104.   out 20h,al
  105.   pop es dx ax                        ; clean up and leave
  106.   iret
  107. ENDP
  108.  
  109. PROC ctrlBreak FAR
  110.   iret
  111. ENDP
  112.  
  113.         ENDS
  114. END
  115.