program Tutorial_1_sqrteffect;

// Place to dump generated data.
@define dataloc $1600

@userdata "$1600" "$17FA" "Generated Table"

@ignoremethod "init16x8div"

@ignoremethod "init16x8mul"

@ignoremethod "init8x8div"

@ignoremethod "initrandom"

// We actually multiply eightbit
//@ignoremethod "initeightbitmul"



var  
	// Character that builds the circle. Some random petscii ones
	vals : array[8] of byte = ($20, $2E, $2B, $51, $5A, $56, $5E, $5E );

	x,y,i,j,time,dx,dy : byte=0;
	wrk : integer;
	// Pointers to color, data and screen
	cp,data,screen:pointer;

/*
	Fills @dataLoc with 25x22 circles & 7
*/

// Calculates a bunch of circles with center 11,13
procedure Calculate();
begin
	cp:=@dataloc;
	for y:=0 to 23 do begin
		for x:=0 to 22 do begin
			dx:=abs(11-x);
			dy:=abs(13-y);
			wrk := dx*dx + dy*dy;
			i:=(sqrt(wrk)/16)&7;
			cp[x]:=i;
		end;
		inczp(cp,22);
	end;
	
end;

// Loads from dataloc and draws to screen + color screen
 
procedure Update();
begin
	screen:=$1000;//SCREEN_CHAR_LOC;
	cp:=SCREEN_COL_LOC; // Color memory
	data:=@dataloc;
	for y:=0 to 23 do begin
		for x:=0 to 22 do begin
			i:=(data[x]-time)&7;
			screen[x]:=vals[i];
			cp[x]:=i;
		end;
		inczp(screen,22);
		inczp(cp,22);
		inczp(data,22);
	end;

	inc(time);

end;



begin
	DisableVIC20IRQ();
	SCREEN_BG_COLOR := 8;
	time:=0;
	
	Calculate();
	while (1=1) do begin
		Update();
	end;
	Loop();


end.
