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

@use "compression/compression"

//@endif

@export "resources/images/image1.flf" "resources/images/trse.bin" 100


/*
	Displays the TRSE logo

*/


var
	time,i,j,k,t2: byte;
	@donotremove line_1
	zp,keep,sp,zp2,sp2 : pointer;
	
	image1 : incbin("resources/images/trse.bin") compressed;
//	image1 : incbin("resources/images/kid1.bin");
//	image2 : incbin("resources/images/kid2.bin");


//	sinx : array[256] of byte = BuildTable("Math.sin(i/256.0*Math.PI*2.0)*16+48");
	sinx : array[256] of byte = BuildTable("Math.sin(i/256.0*Math.PI*2.0)*112+112");
//	sinx : array[256] of byte = BuildTable("Math.cos(i/256.0*Math.PI*2.0)*6+6");




procedure IRQ();
begin

	inc(time);
//	Screen::SetBorderColor(time);


	inc(t2);
	if (time&3=0) then inc(t2);
	if (time&15=0) then inc(t2);
	
	

//	Screen::ScrollToY(sinx[time*2]);
//	Screen::SetWindowHeight(sinx[time*4]>>4+8);

@ifdef IS_DEMO
	call(keep);// Make sure that music plays
@endif
	

//	Screen::SetBackgroundColor(time);
end;

procedure CopyData();
begin
	zp:=#image1;
	sp := #mode5_vram;
	zp2:=#image1+$2700;
	sp2 := #mode5_vram+$2700;
	for i:=0 to 20 do
	begin
		for j:=0 to 0 do
		begin
			sp[j]:=zp[j];
			sp2[j]:=zp2[j];
			if (j&15=0) then
			Screen::WaitForVerticalSync();
		end;
		asm(" inc sp+1");
		asm(" inc zp+1");
		asm(" dec sp2+1");
		asm(" dec zp2+1");
	end;
end;



begin
	
@ifndef IS_DEMO
	
	Screen::InitStandardScreenAndIRQ();
@endif
	Screen::SetMode5();
	//Screen::SetMode5Palette(#Screen::colorsBluePurpleWhite);	
	Screen::SetMode5Palette(#Screen::colorsBlue);	
	Screen::FillBanks(#mode5_vram, 0,$28);
	// Clear the screen

	keep := Screen::irqProcedure;
	Screen::irqProcedure := #IRQ;
	Compression::Decompress(#image1, #mode5_vram);
//	CopyData();
	
	DemoTools::WaitABit(10);


	Loop();
	Screen::irqProcedure := keep;
	DemoTools::EndEffect();

end.
