program Image;
@use "system/z80cpm"
@use "system/system"
@use "system/screen"
@use "system/graphics"
@use "benchmark"
@use "misc"

@define max3dobjects 1
// color 0 to clear
@define lib3d_clearlines 0 
@define linemethod "Graphics::Line"

@use "gfx/lib3d"

var  
	time, time2, i,j, curFrame : byte;
	size : integer;
	obj1 : incbin("data/torus1.bin");
	tables2d : incbin("data/2d_dump.bin", $4000);
	// number of frames of the anim
	const noFrames: byte = 100;
	const objPos : address = $2000;
	
	font: incbin("zxchars.bin");	// load an 8x8 font


procedure Render();
begin
@ifndef lib3d_clearlines
	Screen::ClearBox(22,18,34,34,0);
@endif
	Lib3d::RenderWireframeColor(0,3);
	Lib3d::ppo:=Lib3d::ppn;	
	Lib3d::ppn+=size;	
	time+=1;
	curFrame+=1;
	if (curFrame=noFrames) then
	begin
		curFrame:=0;
		Lib3d::ppn:=#tables2d;
	end;

end;	


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

	Screen::GotoXY(10,2);
	Screen::PrintStr("Precalculated data, clearing with ");
@ifdef lib3d_clearlines
	Screen::PrintStr("Line(...)");
@else
	Screen::PrintStr("ClearBox(...)");
@endif
	Screen::GotoXY(0,2);


	Lib3d::InitializeData(#objPos);	
	Lib3d::LoadObject(0, #obj1);
	size:=Lib3d::objects[0].noVerts*2;
	Lib3d::ppn:=#tables2d;
	Lib3d::ppo:=#tables2d;
	time:=0;
	Benchmark::Setup();
	Misc::InitKeyboardCheck(5);
	while (not Misc::keyPressed) do
	begin
		Render();
		time+=1;
		Benchmark::drawCount += 1;
		Misc::KeyboardCheck();
		if Benchmark::benchFps <> 0 then Benchmark::Display();
	end;

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

end.
