                 { --- Page scrolling --- }

procedure page_up;      { scroll page one line up}
begin
if (page_bottom_line<n_lines) then
   begin
   if (cy<=SCREENTOP) then cursor_down;
   cy:=cy-1;
   end;
scroll_up(1);
end; { page_up }

procedure page_down;      { scroll page one line down }
begin
if page_top_line>1 then
    begin
    if cy>=SCREENBOTTOM then cursor_up;
    cy:=cy+1;
    end;
scroll_down(1);
end; { page_down }

procedure prev_page;      { back to previous page }
var d:integer;
begin
d:=min(page_top_line,PAGELEN)-1;
if d>0 then
    begin
    page_top_line:=page_top_line-d;
    find_page_bottom_line;
    find_index_above_cx(index,cx,d);
    find_index_above_cx(page_top_index,1,d);
    find_page_bottom_index;
    display_rest_page(page_top_index,1,SCREENTOP);
    end
else
    begin
    find_index_above_cx(index,cx,cy-SCREENTOP);
    cy:=SCREENTOP;
    end;
cx:=min(cx,cd_bol(index)+1);
end; { prev_page }

procedure next_page;      { forward to next page }
var d:integer;
begin
d:=min(n_lines-page_top_line,PAGELEN)-1;
if d>0 then
    begin
    page_top_line:=page_top_line+d;
    find_page_bottom_line;
    find_index_below_cx(index,cx,d);
    find_index_below_cx(page_top_index,1,d);
    find_page_bottom_index;
    display_rest_page(page_top_index,1,SCREENTOP);
    cx:=min(cx,cd_bol(index)+1);
    cy:=min(cy,page_bottom_line-page_top_line+SCREENTOP)
    end;
end; { next_page }

