home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / pascal / library / dos / keyboard / atkybd / atkybd.pas
Pascal/Delphi Source File  |  1988-06-04  |  5KB  |  139 lines

  1. {$M 16324,0,16324}
  2. program atkybd; { Set AT keyboard delay and typematic.  Turbo Pascal 4.0 }
  3.  
  4. { Keying On A Standard, Bob Smith, PC Tech Journal, July 87, p134
  5.   Rev Up The AT Keyboard, Kevin M Crenshaw, PC Tech Journal, May 85, p39
  6.   Speedier AT Keyboard, Robert Patenaude, PC Magazine, Mar 25, 1986, p289}
  7.  
  8. { John Haluska CIS 74000,1106 }
  9.  
  10. const
  11.   DlyVal : array[0..3] of string[3] = ('.25','.5','.75','1.0');
  12.   RepVal : array[0..31] of string[5] = ('30','26.7','24','21.8','20','18.5',
  13.              '17.1','16','15','13.3','12','10.9','10','9.2','8.6','8','7.5',
  14.              '6.7','6','5.5','5','4.6','4.3','4','3.7','3.3','3','2.7','2.5',
  15.              '2,3','2.1','2');
  16. var
  17.   Dly1, Repeat1    : byte;
  18.   Result1,Result2  : integer;
  19.   Error            : byte;
  20.  
  21. {----------------------------------------------------------------------------}
  22. { Set AT Keyboard Delay code 0-3 (.25, .5, .75, or 1 sec) before start of
  23.   Typematic code 0-31 (30, 26.7, 24, 21.8, 20, 18.5, 17.1, 16, 15, 13.3, 12,
  24.   10.9, 10, 9.2, 8.6, 8, 7.5, 6.7, 6, 5.5, 5, 4.6, 4.3, 4.0, 3.7, 3.3, 3, 2.7,
  25.   2.5, 2.3, 2.1 or 2 repeats/sec). Return Error code 0 (Operation successful),
  26.   1 (Invalid Delay and/or Typematic code), 2 (Hardware error or feature not
  27.   supported) }
  28.  
  29. procedure SetATKybdDelayTypematic(Delay,Typematic:byte; var Error: byte);
  30.  
  31. procedure Xmit(Data:byte; var Error:byte);
  32.           {Transmit info to keyboard}
  33. var
  34.   Rdy1        : byte;
  35.   TickCount   : ^longint;
  36.   Tc1         : longint;
  37.  
  38. begin
  39.   Error:=0;
  40.   TickCount := Ptr($40,$6C);   { location of DOS clock }
  41.   Tc1 := TickCount^;           { 18.2 tickcounts/second }
  42.   repeat
  43.     Rdy1 := Port[$64];         { Is data waiting for the controller? }
  44.     if (TickCount^ - Tc1) > 36 then
  45.       begin
  46.         Error:=2; Exit;   { Time out - hardware error or not supported }
  47.       end;
  48.   until Rdy1 and 2 = 0;
  49.   Port[$60] := Data;           { Send data to keyboard }
  50.   Tc1 := TickCount^;
  51.   repeat
  52.     Rdy1 := Port[$64];         { Wait for keyboard to read data }
  53.     if (TickCount^ - Tc1) > 36 then
  54.       begin
  55.         Error:=2; Exit;
  56.       end;
  57.   until Rdy1 and 2 = 0;
  58.   Tc1 := TickCount^;
  59.   repeat
  60.     Rdy1 := Port[$64];         { Wait for keyboard to send ACK }
  61.     if (TickCount^ - Tc1) > 36 then
  62.       begin
  63.         Error:=2; Exit;
  64.       end;
  65.   until Rdy1 and 1 = 0;
  66.   Tc1 := TickCount^;
  67.   repeat until (TickCount^ - Tc1) > 2;
  68.   Rdy1 := Port[$60];
  69.   if Rdy1 <> $FA then Error:=2;   { Was it ACK? }
  70. end; {Xmit}
  71.  
  72. begin
  73.   Error:=0;
  74.   if (Delay<0) or (Delay>3) or (Typematic<0) or (Typematic>31) then
  75.     begin
  76.       Error:=1;  Exit;
  77.     end;
  78.   Xmit($F3,Error);              { send command to set delay and typematic }
  79.   if Error = 2 then Exit;
  80.   Xmit(Delay shl 5 + Typematic,Error);  { send delay and typematic values }
  81. end;{SetATKybdDelayTypematic}
  82. {----------------------------------------------------------------------------}
  83.  
  84. begin
  85.   case ParamCount of
  86.     0: begin
  87. Writeln('                  Set AT Keyboard Delay and Repeat Rate');
  88. Writeln;
  89. Writeln('            Syntax: ATKYBD [Delay Code] [Repeats/Sec Code] ');
  90. Writeln;
  91. Writeln('                   Code  Delay(Sec)    Code  Delay(Sec)');
  92. Writeln('                     0     .25           2      .75 ');
  93. Writeln('                     1     .50*          3     1.00 ');
  94. Writeln;
  95. Writeln('       Code Rep/Sec    Code Rep/Sec    Code Rep/Sec   Code Rep/Sec ');
  96. Writeln;
  97. Writeln('         0    30         8    15        16    7.5      24    3.7 ');
  98. Writeln('         1    26.7       9    13.3      17    6.7      25    3.3 ');
  99. Writeln('         2    24        10    12        18    6        26    3.0 ');
  100. Writeln('         3    21.8      11    10.9*     19    5.5      27    2.7 ');
  101. Writeln('         4    20        12    10        20    5        28    2.5 ');
  102. Writeln('         5    18.5      13     9.2      21    4.6      29    2.3 ');
  103. Writeln('         6    17.1      14     8.6      22    4.3      30    2.1 ');
  104. Writeln('         7    16        15     8.0      23    4.0      31    2.0 ');
  105. Writeln;
  106. Writeln('          * Standard Values');
  107.        end;
  108.     2: begin
  109.          Val(ParamStr(1),Dly1,Result1);
  110.          Val(ParamStr(2),Repeat1,Result2);
  111.          if (Result1 > 0) or (Result2 > 0) then
  112.            begin
  113.              Writeln('Syntax error - Exit Program');  Exit;
  114.            end
  115.          else
  116.            begin
  117.              SetATKybdDelayTypematic(Dly1,Repeat1,Error);
  118.              case Error of
  119.                0: begin
  120.                     Write('AT Keyboard Delay: ',DlyVal[Dly1],' sec.  ');
  121.                     Writeln('Typematic: ',RepVal[Repeat1],' repeats/sec');
  122.                   end;
  123.                1: begin
  124.                     Writeln('Syntax Error - Exit Program'); Exit;
  125.                   end;
  126.                2: begin
  127.                     Write('Hardware error or feature not supported');
  128.                     Writeln(' - Exit Program');  Exit;
  129.                   end;
  130.                end;
  131.            end;
  132.        end;
  133.     else           { 1 or greater than 2 command line parameters }
  134.       begin
  135.         Writeln('Syntax error - Exit Program');  Exit;
  136.       end;
  137.    end;
  138.  end.
  139.