uses screen, memory, crt, dos;

const
VGA=$a000;
f_scale=4;
f_width=64  *f_scale;
f_heigh=256 *f_scale;
f_count=14; {max 20, если мы храним меш внизу видеобуфера}

function FloorMeshGen(where:word):word;
var r,m,n:word;
f_x1, f_y1, f_y2:integer;
x, y, z, p:integer;
size:word;
begin
f_x1:=-(f_count*f_width div 2);
f_y1:=-(f_heigh div 2);
f_y2:=  f_heigh div 2;
z:=0;
for n:=0 to f_count-1 do begin
p:=n*18 *2;
m:=f_width*n;
memw[where:0+p]:=word(f_x1 +m);           memw[where:1*2+p]:=word(f_y1);  memw[where:2*2+p]:=word(z);
memw[where:3*2+p]:=word(f_x1+f_width +m); memw[where:4*2+p]:=word(f_y1);  memw[where:5*2+p]:=word(z);
memw[where:6*2+p]:=word(f_x1+f_width +m); memw[where:7*2+p]:=word(f_y2);  memw[where:8*2+p]:=word(z);
memw[where:9*2+p]:=word(f_x1+f_width +m); memw[where:10*2+p]:=word(f_y2); memw[where:11*2+p]:=word(z);
memw[where:12*2+p]:=word(f_x1 +m);        memw[where:13*2+p]:=word(f_y2); memw[where:14*2+p]:=word(z);
memw[where:15*2+p]:=word(f_x1 +m);        memw[where:16*2+p]:=word(f_y1); memw[where:17*2+p]:=word(z);
end;
z:=-110 *f_scale;
for n:=f_count to f_count*2-1 do begin
p:=n*18 *2;
m:=f_width*(n-f_count);
memw[where:0+p]:=word(f_x1 +m);           memw[where:1*2+p]:=word(f_y2);  memw[where:2*2+p]:=0;
memw[where:3*2+p]:=word(f_x1+f_width +m); memw[where:4*2+p]:=word(f_y2);  memw[where:5*2+p]:=0;
memw[where:6*2+p]:=word(f_x1+f_width +m); memw[where:7*2+p]:=word(f_y2);  memw[where:8*2+p]:=word(z);
memw[where:9*2+p]:=word(f_x1+f_width +m); memw[where:10*2+p]:=word(f_y2); memw[where:11*2+p]:=word(z);
memw[where:12*2+p]:=word(f_x1 +m);        memw[where:13*2+p]:=word(f_y2); memw[where:14*2+p]:=word(z);
memw[where:15*2+p]:=word(f_x1 +m);        memw[where:16*2+p]:=word(f_y2); memw[where:17*2+p]:=0;
end;

FloorMeshGen:=16*2+p  +2; {size}

end;


procedure save_data(name:string; size:longint; from:word);
var fw1:file;
i:word;
begin
Assign(fw1, name);
Rewrite(fw1,1);
Reset(fw1, 1);
for i:=0 to size-1 do BlockWrite(fw1, mem[from:i], 1);
Close(fw1);
end;


var
fw1,fw2:file;

c, i, x,y,n,m,yy,xx:word;
fr:file;
col, r,g,b:byte;
size:word;

begin
SetUpVirtual(scr,vaddr);
SetUpVirtual(scr2, vaddr2);
SetUpVirtual(scr3, vaddr3);

  size:=FloorMeshGen(vaddr);
  save_data('flr_mesh.bin', size, vaddr);

  WriteLn(size, ' byte done');


readkey;


end.