{$symtab-,$pagesize:84,$linesize:131,
$title:'SAVDIS.PAS -- Save - Display CRT Data'}
{	COPYRIGHT @ 1982
	Jim Holtman and Eric Holtman
	35 Dogwood Trail
	Randolph, NJ 07869
	(201) 361-3395
}
module save_display;
{$include:'simterm.inc'}
var
    first_time : boolean;
    one_line_save_area : string(160);
    display_buffer_addr [external] : word;
    bot_mem,top_mem : word;
    next_ptr : ads of string(160);
value
    first_time := TRUE;
function xfreemem : word;
    external;
function xmaxmem : word;
    external;
procedure xxvert;
    external;
function uaddok(a,b:word;var c:word) : boolean;
    external;
procedure init;
var
    inc : word;
begin
    first_time := FALSE;
    bot_mem := xfreemem;	{bottom of free memory}
    top_mem := xmaxmem-10;	{top of free memory}
    if top_mem < bot_mem then begin
	next_ptr := ads one_line_save_area;	{FAKE it}
	bot_mem := next_ptr.s;
	top_mem := bot_mem;
    end
    else begin
	top_mem := bot_mem+((top_mem-bot_mem) div 10)*10;
	next_ptr.r := 0;
	next_ptr.s := bot_mem;
    end;
    while next_ptr.s <= top_mem do begin {blank at most 64K at a time}
	next_ptr^[1] := ' ';    {blank out the buffer}
	next_ptr^[2] := chr(7);
	if (top_mem - next_ptr.s) > #FFF then inc := #FFF
	else inc := top_mem - next_ptr.s + 10;
	{move the buffer on top of itself}
	movesl(ads next_ptr^[1],ads next_ptr^[3],inc*16);
	next_ptr.s := next_ptr.s+inc;
    end;
    next_ptr.s := bot_mem;
    writeln(output,'Display Save Area = ',(top_mem-bot_mem) div 10,' lines.');
end;
procedure save_line(line : CRT_SIZE; inc : INC_LIMIT);
var
    display_buf : ads of char;
begin
    if first_time then init;
    display_buf.s := display_buffer_addr;
    display_buf.r := wrd(2*line*(RIGHT_MAR+1));
    xxvert;	{wait for retrace}
    movesl(display_buf,next_ptr,LINE_SIZE);
    eval(uaddok(next_ptr.s,wrd(10*inc),next_ptr.s));
    if next_ptr.s < bot_mem then next_ptr.s := top_mem
    else if next_ptr.s > top_mem then next_ptr.s := bot_mem;
end;
procedure display_line(line : CRT_SIZE; inc : INC_LIMIT);
var
    display_buf : ads of char;
begin
    if first_time then init;
    display_buf.s := display_buffer_addr;
    display_buf.r := wrd(2*line*(RIGHT_MAR+1));
    xxvert;	{wait for retrace}
    movesl(next_ptr,display_buf,LINE_SIZE);
    eval(uaddok(next_ptr.s,wrd(10*inc),next_ptr.s));
    if next_ptr.s < bot_mem then next_ptr.s := top_mem
    else if next_ptr.s > top_mem then next_ptr.s := bot_mem;
end;
end.
    `-B'     will cause the transmit 