program Image;
@use "compression"
@use "system/z80cpm"
@use "system/system"
@use "system/screen"
@use "system/graphics"






var  
	
	data: incbin("data/disksprite.bin");
	const noFrames: byte = 64;

	frame,i,j,time : byte;
	// Width and height of image
	const width : byte = 64/4;
	const height : byte = 32;
	
	// Size of each frame
	frameLookup : array[noFrames] of integer = buildtable("i*WIDTH*HEIGHT");
	src, dst:pointer;
	
	sin : array[256] of byte = buildsinetable(100);
	
	const xbase : byte = 30;
	const ybase: byte = 30;
	
	kbcheck: byte;
	
procedure Render();
begin
	i:=sin[time];
	src:=#data +frameLookup[frame];
	dst := ($8000 + 256*xbase+ybase);
//	Screen::ClearBox(xbase, ybase+i-2, width, 2, 0);
//	Screen::ClearBox(xbase, ybase+i+height+2, width, 4, 0);
	for i:=0 to width do
	begin
		Screen::CopyToScreen(src,dst,height);
		dst+=256;
		src+=height;
	end;
	
end;

begin
	Z80CPM::Startup();
	System::CursorOff();
	Screen::ClearBox(0, 0, 128, 64, 0);

	kbcheck := 20;

//	System::SetTimerFunction(#Render);
	while (true) do
	begin
		Render();
		System::MegaWait(64);
		frame:=(frame+1)	&(noFrames-1);
		time+=1;

		kbcheck -= 1;
		if kbcheck = 0 then
		begin
			if Z80CPM::KeyPressed() then break;
			kbcheck := 20;	// check every 20 frames
		end;
	end;

	Z80CPM::GetChar();
	System::CursorOn();
	Z80CPM::Exit();

end.
