{***********************************************************************}
{									}
{ __ReptKey   Set the rate and delay of keyboard auto-repeat		}
{									}
{ procedure __ReptKey(Rate, Delay : real);				}
{									}
{	      Rate	The rate at which key sequences are generated	}
{			during keyboard typematic repeat.  The rate is	}
{			measured in characters per second and can	}
{			assume values from 2.0 to 30.0. 		}
{	      Delay	The time a key must be depressed before type-	}
{			matic repeat is enabled.  The delay is measured }
{			in milliseconds, but the value is rounded to	}
{			250.0, 500.0, 750.0 or 1000.0.			}
{									}
{ Description This procedure sets the rate and delay of the keyboard	}
{	      auto repeat function.  It is available for the following	}
{	      systems:							}
{									}
{		* AT BIOS dated 11/15/85 and after			}
{		* PC XT Model 286					}
{		* all Personal System/2 machines			}
{									}
{	      Rate can be set (approximately)  from 2.0 to 30.0 char-	}
{	      acters per second.  The default value is 10.9.  The	}
{	      delay (before auto repeat begins) can be either 250, 500	}
{	      750 or 1000 milleseconds. 				}
{									}
{	      __ReptKey will take no action if out of range parameters	}
{	      are passed to it, or if the function is not supported by	}
{	      the hardware.						}
{									}
{ Version     4.00 (C)Copyright Blaise Computing Inc.  1987		}
{_______________________________________________________________________}

procedure __ReptKey(Rate, Delay : real);

  var
    Reg       : registers;
    TypeRates : array[0..31] of real;

  begin {__ReptKey}

    { First initialize a typematic rate table to be used with BIOS	}
    { keyboard function 3.  It represents the number of characters	}
    { per second (10.9) is the default.  The value passed to the BIOS	}
    { function is the index in the table.  A typed constant is not	}
    { used to initialize the table TypeRates in order to avoid the	}
    { data space overhead required.					}

    if ((Rate > 30.0) or (Rate < 2.0) or
			       (Delay < 250.0) or (Delay > 1000.0)) then
      Exit
    else
       begin
	 TypeRates[ 0] := 30.0;
	 TypeRates[ 1] := 26.7;
	 TypeRates[ 2] := 24.0;
	 TypeRates[ 3] := 21.8;
	 TypeRates[ 4] := 20.0;
	 TypeRates[ 5] := 18.5;
	 TypeRates[ 6] := 17.1;
	 TypeRates[ 7] := 16.0;
	 TypeRates[ 8] := 15.0;
	 TypeRates[ 9] := 13.3;
	 TypeRates[10] := 12.0;
	 TypeRates[11] := 10.9;
	 TypeRates[12] := 10.0;
	 TypeRates[13] :=  9.2;
	 TypeRates[14] :=  8.6;
	 TypeRates[15] :=  8.0;
	 TypeRates[16] :=  7.5;
	 TypeRates[17] :=  6.7;
	 TypeRates[18] :=  6.0;
	 TypeRates[19] :=  5.5;
	 TypeRates[20] :=  5.0;
	 TypeRates[21] :=  4.6;
	 TypeRates[22] :=  4.3;
	 TypeRates[23] :=  4.0;
	 TypeRates[24] :=  3.7;
	 TypeRates[25] :=  3.3;
	 TypeRates[26] :=  3.0;
	 TypeRates[27] :=  2.7;
	 TypeRates[28] :=  2.5;
	 TypeRates[29] :=  2.3;
	 TypeRates[30] :=  2.1;
	 TypeRates[31] :=  2.0
       end;

    with Reg do
      begin
	if (Delay < 375.0) then
	  BH := $00		       { 250 ms delay			}
	else if (Delay < 625.0) then
	  BH := $01		       { 500 ms delay			}
	else if (Delay < 875.0) then
	  BH := $02		       { 750 ms delay			}
	else
	  BH := $03;		       { 1000 ms delay			}

	BL := $20;		       { Choose typematic rate from	}
	repeat			       { the TypeRates table.  Choose	}
	  Dec(BL)		       { the closes value to Rate.	}
	until ((BL = 0) or (TypeRates[BL] >= Rate));

	AX := $0305;
	Intr(_KEYBD,Reg)

      end

  end; {__ReptKey}
