                      { --- Screen display subroutines --- }

procedure clear_rest_screen(x,y:integer);
begin Cursor_to(x,y); write(ESC,'['); end;

procedure clear_rest_line(x,y:integer);
begin Cursor_to(x,y); write(ESC,'Z'); end;

procedure write_char(i:integer);
var x:integer;
    ch:char;
begin
ch:=text[i];
if ch=TAB then
    begin
    x:=x_to_bol(i)+1;
    repeat write(BLANK); x:=x+1; until x mod TABPOS = 0;
    end
else write(ch);
end; { write_char }

procedure display_char(i:integer;var x:integer; y:integer);
begin
if i<=text_end then
    begin
    if dx(i)>0 then
        begin
        if x<=LINELEN then
            begin
            if block_flag and (block_begin<=i) and (i<=block_end) then
                begin LowVideo; write_char(i); HighVideo; end
            else write_char(i);
            end
        else
            begin
            LowVideo; Cursor_to(LINELEN,y); write('+'); HighVideo;
            end;
        x:=x+dx(i);
        end;
    end;
end; { display_char }

procedure display_rest_line(index,cx,cy:integer);
var i,x: integer;
begin
Cursor_to(cx,cy);
i:=index; x:=cx;
while not eol(i) and (x<=LINELEN+1) do
    begin display_char(i,x,cy); i:=i+1; end;
if x<=LINELEN then clear_rest_line(x,cy);
end; { display_rest_line }

procedure display_rest_page(index,cx,cy:integer);
var i,x,y: integer;
begin
i:=index; x:=cx; y:=cy;
while (y<=SCREENBOTTOM) and (i<=text_end) do
    begin
    display_rest_line(i,x,y);
    i:=i+ch_to_eol(i)+1;
    x:=SCREENLEFT; y:=y+1;
    if y<=SCREENBOTTOM then Cursor_to(x,y);
    end;
if y<=SCREENBOTTOM then clear_rest_screen(x,y);
end; { display_rest_page }
