.model compact, C
.286
extrn Done: byte
.code
old_kb_handler dd 0

new_kb_handler proc far
    push dx
    push ax
    mov dx, 60h
    in al, dx
    cmp al, 1
    jne noquit
    mov Done, 1
    noquit:
    mov al, 20h
    out 20h, al
    pop ax
    pop dx
    iret
new_kb_handler endp

public init_kb_handler, remove_kb_handler

init_kb_handler proc C
  push ds
  mov ax, 3509h
  int 21h
  mov word ptr old_kb_handler, bx
  mov word ptr old_kb_handler+2, es
  mov ax, seg new_kb_handler
  mov dx, offset new_kb_handler
  mov ds, ax
  mov ax, 2509h
  int 21h
  pop ds
  ret
init_kb_handler ENDP

remove_kb_handler proc C
  push ds
  mov dx, word ptr old_kb_handler
  mov ax, word ptr old_kb_handler+2
  mov ds, ax
  mov ax, 2509h
  int 21h
  pop ds
  ret
remove_kb_handler ENDP
END
