unit speaker;

interface

procedure sound(freq : real);
procedure no_sound;

implementation

procedure sound(freq : real);
const
freq0 = 1.19318e6;

var
     count : word;
     b : byte;
begin
     count := round(freq0/freq);
     b := port[$61];
     if b and $03 = 0 then
     begin
          b:= b or $03;
          port[$61] := b;
          port[$B6] := $B6;
     end;
     b := Lo(count);
     port[$42] := b;
     b := Hi(count);
     port[$42] := b;
end;

procedure no_sound;
          var
             x : byte;
             begin
             port[$61] := port[$61] and $FC;
          end;

end.