uses screen, memory, crt, dos;

const
VGA=$a000;


PROCEDURE PrecalsCircle(radius:Integer;mas:word);
VAR
   CenterX,CenterY,X,Y,m, offs:Integer;
BEGIN
      offs:=(radius*2)*4*64;
      CenterX:=radius;
      CenterY:=radius;
      x := 0;
      y := radius;
      m := 5 - 4 * radius;

      while (x <= y) do
      begin
        memw[mas:word(offs+(centerY-x) shl 2)]  :=centerX - y;
        memw[mas:word(offs+(centerY-x) shl 2+2)]:=centerX + y;
        memw[mas:word(offs+(centerY+x) shl 2)]  :=centerX - y;
        memw[mas:word(offs+(centerY+x) shl 2+2)]:=centerX + y;

        if (m > 0) then
        begin
          memw[mas:word(offs+(centerY-y) shl 2)]  :=centerX - x;
          memw[mas:word(offs+(centerY-y) shl 2+2)]:=centerX + x;
          memw[mas:word(offs+(centerY+y) shl 2)]  :=centerX - x;
          memw[mas:word(offs+(centerY+y) shl 2+2)]:=centerX + x;
          dec(y);
          m := m - 8 * y;
        end;
        inc(x);
        m:= m + (8 * x + 4);
      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, r,g,b:byte;
size:word;

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

for n:=0 to 64 do PrecalsCircle(n, vaddr);

save_data('circles.bin', 34000, vaddr);

WriteLn('Done');


readkey;


end.