procedure Scroll(Dir:char);
begin
case upcase(Dir) Of
'U':begin                 { up }
    if currentline=1 then exit;
    dec(currentline);
    display(currentline);
    end;
'D':begin                 { down }
    if currentline=100 then exit;
    inc(currentline);
    display(currentline-(msgm[5].y-msgm[4].y));
    end;
end;
end;

procedure Direction(a:byte);
begin
case a of

  1:if currentline>1 then    { up }
    begin
    fsex:=1;
    if wherey=msgm[4].y then scroll('U') else
    begin
    dec(currentline);
    dec(fsey);
    end;
    fsex:=findlast(currentline);
    end;
  2:if currentline<100 then   { down }
    begin
    fsex:=1;
    if wherey=msgm[5].y then scroll('D') else
    begin
    inc(currentline);
    inc(fsey);
    end;
    fsex:=1;
    end;
  3:begin                       { left }
    dec(fsex);
    if fsex=0 then if currentline>1 then direction(1) else
    fsex:=1;
    end;
  4:begin                       { right }
    inc(fsex);
    if fsex=findlast(currentline)+1 then if currentline<100 then
    direction(2) else fsex:=80;
    end;

end;
goxy(fsex,fsey);
end;
