program Interferens;
@use "graphics"
var  

	// Number of bitplanes	
	const bpl : byte = 3;

   	i, curFrame, time, time2: integer = 0; 
   	
   	/*
   	
   		This effect displays a bitmap effect using 16 bitmap planes. The data
   		is pre-generated using the resources/fjong/bitplane_effect.fjo file.
   	
   	
   	*/
   	
   	data : incbin("resources/data/bitplane_effect.bin") chipmem;
   	
	ptr : pointer of byte;
	
	sinx : 	array[256] of integer = buildtable( "((Math.sin((i)/256*3.14159*2)*0x7f + 0x7f))");
	// Animation number of frames
	const maxFrames : integer = 15;
	
	imgTab : array[maxFrames+1] of long = BuildTable("i*40*256");
	
	
procedure RenderFrame2(t1,t2,div1 : integer;adde:integer);
begin
		curFrame := sinx[ t1 & $FF ]/div1;
		ptr := #data ;
		ptr += imgTab[curFrame&maxFrames];
		
		if (adde=0) then
			SetCopperList32(ptr, #copper_bitplane0);
			
		if (adde=1) then
			SetCopperList32(ptr, #copper_bitplane1);
			
		if (adde=2) then
			SetCopperList32(ptr, #copper_bitplane2);
			
		if (adde=3) then
			SetCopperList32(ptr, #copper_bitplane3);

end;

begin
	Graphics::SetupNonInterlacedScreen(0,bpl);
	// Set some extra colors
	poke16(#copper_palette,2+1*0,$1010);	
	poke16(#copper_palette,2+4*1,$0800);	
	poke16(#copper_palette,2+4*2,$0F16);	
	poke16(#copper_palette,2+4*3,$0FA2);	



	time := 0;	
	while (true) do begin
	
		RenderFrame2(time, time*2,4,0);
		RenderFrame2(time*2, time2,8,1);
		RenderFrame2(time2, time2,16,2);
		
		WaitVerticalBlank();	

		time+=1;
		time2+=1;
		if (time&1=1) then time2+=1;
	end;

end.
