Unit UKeys;

   Interface

Type Vector_Table = Array[0..255] Of Pointer;

  Var
  Keys    : array [ 1..127 ] of boolean;
  IntVec  : Vector_Table Absolute 0:0;
  Old:Procedure;
  KeySeg,KeyOfs:Word;



 Procedure KeyInit;
 Procedure KeyDone;


   Implementation
  Uses Crt;



Procedure keystatus; Interrupt;
{Begin
  Asm PushF End;
  Old;
  Keys[Port[$60] Mod $80]:= Port[$60]<$80;
End;}
Assembler;
  Asm
    PushF
    call old
    Xor  Ax,Ax
    mov  bl,0127d
    in   al,060h
    mov  dh,al
    and  al,bl
    mov  ES,Keyseg
    mov  DI,KeyOfs
    add  di,ax
    dec  di
    cmp  dh,al
    je   @A
    mov  al,FALSE
    jmp  @SF
@A: mov  al,TRUE
@SF:StosB
    Mov Ax,040h
    Mov Es,Ax
    Mov Di,01ah
    Mov Al,Es:[Di]
    Mov Di,01ch
    Mov Es:[Di],Al
End;

Procedure Keyinit;
Var
  Count : Byte;
Begin
  For count:=1 to 127 do
    Keys[count]:=false;
  KeySeg:=Seg(Keys);
  KeyOfs:=Ofs(Keys);
  @Old:=IntVec[9];
  intvec[9]:=@keystatus;
End;

Procedure Keydone;
begin
  intvec[9]:=@old
end;

 Begin
 End.