program Tunnel;

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

@ignoremethod "init16x8div"
@ignoremethod "initrandom"

var

// Place to dump generated data.
const dataloc:address = $1800;
const lineloc:address = $1A00;

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

const charsetLoc:address = $1c00;

@export "resources/charsets/charset.flf" "resources/charsets/charset.bin" 256
	charset:incbin("resources/charsets/charset.bin", @charsetLoc);
/*
	Fills dataLoc with 25xscreen_width circles & 7
*/

procedure Calculate();
begin
	cp:=#dataloc;
	screen:=#lineloc;
	for y:=0 to screen_height do 
	begin
		for x:=0 to screen_width do 
		begin
			dx:=abs(11-x);
			dy:=abs(12-y);
			wrk := (dx*dx) + (dy*dy);
			i:=(sqrt(wrk)/2);
//			cp[x]:=255/i;
			cp[x]:=i/4;

			i:=atan2(11,x,12,y);
		
			screen[x]:=i/8;
		end;
		screen:=screen+screen_width;
		cp:=cp+screen_width;
	end;
	
end;

procedure Update();
begin
	screen:=#screen_char_loc;
	cp:=#screen_col_loc; // Color memory
	c1:=#dataloc;
	l1:=#lineloc;
	for y:=0 to screen_height do begin
		for x:=0 to screen_width do begin
			i:=(l1[x]-time);
//			j:=c1[x];//+time2;
			k:=(i+sine[c1[x]]/8)&15;
			screen[x]:=k+80;
			cp[x]:=(k/4)&1+2;
		end;
		screen:=screen+screen_width;
		cp:=cp+screen_width;
		l1:=l1+screen_width;
		c1:=c1+screen_width;
		
	end;

	inc(time);
	time2:=time2+4;
end;



begin
	DisableVIC20IRQ();
	screen_bg_color:=black;
	setcharsetlocation(charsetLoc);
	time:=0;
	
	Calculate();
	while (true) do begin
		Update();
	end;
	Loop();


end.
