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 64*64 do mem[map:c*2+1]:=byte(0);

for y:=0 to 63 do begin

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

   for x:=0 to 63 do begin

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

     if M < R*R then begin
        Z:=byte(255-M div (R div 8));

{        mem[map:n*2]:=1;
        if z>59 then mem[map:n*2 +8-64*8-6]:=byte( round(z*0.8) and 252);{}

        Z:=Z div 8;
        Z:=Z+R;

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

        memw[map:word(x*2+y*256)]:=C * 4;

      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:=32;
    r2:=r+r;

    mapgen2(r, vaddr);{}

    save_data('ball64.bin', word(r2*2+r2*256), vaddr);

    WriteLn('Done');


readkey;


end.