uses screen, memory, crt, dos;

const
VGA=$a000;

Procedure MapGen2(r:word; map :word);
var
n,c,rr:word;
xt,yt,z, m, dx, dy, x,y:integer;
begin
n:=0;
rr:=r*r;
{for c:=0 to 128*128-1 do mem[map:c]:=byte(255);}

for y:=0 to 127 do begin

   dy:=R-y;
   dy:=dy*dy;

   for x:=0 to 127 do begin

     dx:= R-x;
     M:=dx*dx;
     M:=M+dy;

     if M < R*R then begin
        Z:=(256-M div (R div 4));

        {if z>1 then mem[map:n]:=0;
        if z>1 then mem[map:n]:=byte(round(z / 6));{}

        Z:=Z div 4;
        Z:=Z+R;

        Xt:=(X-R)*r div Z;
        Yt:=(Y-R)*r div Z;
        C:= (Xt+r) + (Yt+r)*128;

        memw[map:word(n*2)]:=C * 2;

      end;
      inc(n);
   end;
   end;
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, r2,r,g,b:byte;
size:word;

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

    r:=64;
    r2:=r+r;

    mapgen2(r, vaddr);{}

    save_data('ball128.bin', word((r2*r2)*2), vaddr);

    WriteLn('Done');


readkey;


end.