program Tutorial11_Lines;
var
	i, j,k,val: byte=5;
	zeropage1: pointer;
	@define address zeropage1
	@define bitmapstart "$2000"
	
	// Currently, putpixel2 and putpixel3 are supported
	@define putpixel "putpixel2();"
	
	@include "../../RasLib/bitmapgraphics.ras"


/*

	Not yet updated.
*/


/*
  switch between bank 0 and 1
*/
procedure SwitchDrawBank();
begin
	if bmg_currbank=0 then begin
		bmg_currbank := $40;
		SetBank(VIC_BANK0);
		clearbitmap(^$6400, 22); // Clear a certain window only
	end
	
	else
	begin
		bmg_currbank:=0;
		SetBank(VIC_BANK1);
		clearbitmap(^$2400, 22);
	end;
	
end;


procedure UpdateRaster();
var
	xp: array[3] of byte = (40, 70, 50);
	yp: array[3] of byte = (100, 40, 156);
	xp2: array[3] of byte = (40, 70, 50);
	yp2: array[3] of byte = (100, 40, 156);
	dxp: array[3] of byte = (1, 1, 255);
	dyp: array[3] of byte = (255, 1, 1);
	
begin
	SwitchDrawBank();
	
	Line(xp[0],yp[0],xp[1],yp[1]);
	Line(xp[1],yp[1],xp[2],yp[2]);
	Line(xp[2],yp[2],xp[0],yp[0]);

	i:=8;
	Line(xp[0]+i,yp[0]+i,xp[1]+i,yp[1]+i);
	Line(xp[1]+i,yp[1]+i,xp[2]+i,yp[2]+i);
	Line(xp[2]+i,yp[2]+i,xp[0]+i,yp[0]+i);

	Line(xp[0]+i,yp[0]+i,xp[0],yp[0]);
	Line(xp[1]+i,yp[1]+i,xp[1],yp[1]);
	Line(xp[2]+i,yp[2]+i,xp[2],yp[2]);
	

	for i:=0 to 3 do begin
		xp2[i] := xp[i];
		yp2[i] := yp[i];
		xp[i]:=xp[i]+dxp[i];
		yp[i]:=yp[i]+dyp[i];
		if xp[i]>=125 then dxp[i]:=255;
		if xp[i]<30 then dxp[i]:=1;
		if yp[i]>=150 then dyp[i]:=255;
		if yp[i]<30 then dyp[i]:=1;
		
	end;
	

end;

begin
	bmg_currbank :=0; // Current bitmap bank (added to high bit of putpixel)
	SetupPixelTables();
	inczp(zeropage1,10);
	poke(VIC_DATA_LOC, 0,$18);
	
	setmulticolormode();
	setbitmapmode();
	
	SCREEN_BG_COL:=BLUE;
	SCREEN_FG_COL:=RED;
	clearbitmap(^$2000,32);
	clearbitmap(^$6000,32);
	
	clearscreen(YELLOW,^$D800);
	clearscreen(GREEN,^$0400);
	clearscreen(BLUE,^$4400);


	while (true) do UpdateRaster();
	Loop();
	
end.
