program Demo;
@use "screen"
@use "files"
@use "demotools"

@use "compression/compression"

@export "resources/images/image2.flf" "resources/images/image2.bin" 256


var
	time,i,j,k,t2: byte;
	zp,keep : pointer;
	image1 : incbin("resources/images/image2.bin") compressed;
	
	sinx : array[256] of byte = BuildTable("Math.sin(i/256.0*Math.PI*2.0)*112+112");



procedure IRQ();
begin

	inc(time);
	inc(t2);
	if (time&3=0) then inc(t2);
	if (time&15=0) then inc(t2);
	
//	Screen::ScrollToY(sinx[time*2]);
	
@ifdef IS_DEMO
	call(keep);// Make sure that music plays
@endif
	

end;

begin
	
@ifndef IS_DEMO
	
	Screen::InitStandardScreenAndIRQ();
@endif
	// Set palette
	Screen::SetMode5();
	Screen::SetMode5Palette(#Screen::colorsRedBlue);	

	// Set custom IRQ
	keep := Screen::irqProcedure;
	Screen::irqProcedure := #IRQ;
	
	Compression::Decompress(#image1, #mode5_vram);
	

	DemoTools::WaitABit(96);


	// Restore original IRQ
	Screen::irqProcedure := keep;
	DemoTools::EndEffect();

end.
