program Tutorial2_Timer;
var 
	col,time,line : integer = 0;
	done : integer = 0;
	screen : pointer of integer;
 	
	sin : array[256] of integer = buildsinetable(255);
	
	@export "images/image1.flf" "images/image1.bin" 256
	
	image : incbin("images/image1.bin");
	image_pal : incbin("images/image1.pal");
	
/*

This tutorial uses a timer IRQ to set the background colors


*/


interrupt VBLank();
begin
	col:=sin[(time)&255];
	time:=time+1;
	line:=0;
end;

// Set background palette
interrupt Timer();
begin
	// Set the background color
	if (line<98) then
		palette_start[0]:=col
	else 
		palette_start[0]:=0;
	
	col:=col+4;
	line:=line+1;
end;

begin
	
	SetLoRes();
	
	GetScreen(screen);

	// Copy the image palette	
	memcpy(#image_pal,0,#palette_start,0,15,2);
	// Copy the image to screen
	memcpy(#image,0,screen,0,8000,4);
	setirq(VBLank(), irq_verticalblank);
	settimerirq(Timer(),2);
		
	while (done = false) do
	begin
		done:=keypressed(sc_key_space_pressed);
	end;	
end.




