program MyProgram;
var  
	ok, i, j ,k,m,dx,dy,time,l,curFrame,val,g0,g1,c,maxFrames, pass : byte = 0;
	hasTimeStamps, compressionType, endChar, skipChar : byte;
	zp,cp: pointer;

	@define mpos $3000

	movie: incBin("movie/movie.trm", @mpos);

	@define useKernal 0



procedure ReadAnimationHeader();
begin
	zp:=@mpos;
	maxFrames := zp[2];
	compressionType := zp[3];
	hasTimeStamps:=zp[4];
	endChar:=zp[5];
	skipChar:=zp[6];
	inczp(zp,7);
	curFrame:=0;

end;


/*procedure RenderNextPackedFrame1();
begin
//	moveto(5,2,$D8);
//	cp:=screenmemory;
	cp:=SCREEN_COL_LOC-1;
	screenmemory:=$1C00-1;

	m:=0;
	dy:=0;
	dx:=1;
	i:=zp[0];
	g0:=0;
	
	while (g0=0) do begin
		g1:=getbit(zp[0],7);
//		screenmemory[0]:=2;
		if (g1=0) then begin
			c:=zp[0]&15;
			k:=zp[1];
			inczp(screenmemory, k);
			inczp(cp, k);
			inczp(zp, 2);
		
		end
		else 
		begin
				cp[0]:=zp[0]&7;
				screenmemory[0]:=zp[1]+128;
				inczp(screenmemory,1);
				inczp(cp,1);
				inczp(zp,2);
		end;
		g0:=1-getbit(zp[0],6);

	end;
	dx:=0;
	inc(curFrame);
	inczp(zp,1);

end;
*/

procedure RenderNextPackedFrameCompressionType2();
begin

	m:=0;
	dy:=0;
	dx:=1;
	inczp(zp,1);
	i:=zp[0];
	g0:=0;

	for pass:=0 to 2 do begin

	if pass=1 then
		screenmemory:=$9400;

	if pass=0 then
		screenmemory:=$1C00;
	
	while (g0<>endChar) do begin
	
//		screenmemory[0]:=2;
		if (zp[0] = skipChar) then begin
			k:=zp[1];
			inczp(screenmemory, k);
			inczp(zp, 2);
		
		end
		else 
		begin
			screenmemory[0]:=zp[0]+128;
			inczp(screenmemory,1);
			inczp(zp,1);
		end;
		g0:=zp[0];

	end;
	dx:=0;
	inczp(zp,1);
	g0:=0;
	end;

	if (hasTimeStamps=1) then inczp(zp,1);

	inc(curFrame);

end;

procedure RenderNextPackedFrameCompressionType3();
begin
//	moveto(5,2,$D8);
//	cp:=screenmemory;

	m:=0;
	dy:=0;
	dx:=1;
	i:=zp[0];
	g0:=0;

	for pass:=0 to 2 do begin


	if pass=1 then
		screenmemory:=$9400-1;

	if pass=0 then
		screenmemory:=$1C00-1;
	

	while (g0<>endChar) do begin
	
			g1:=zp[0];
			i:=zp[1]+128;
			fill(screenmemory,i,g1);
			inczp(screenmemory,g1);
			inczp(zp,2);

		g0:=zp[0];

	end;
	dx:=0;
//	Loop();
	inczp(zp,1);
	g0:=0;
	end;

	if (hasTimeStamps=1) then inczp(zp,1);

	inc(curFrame);

end;

begin
	DefineScreen();
	SCREEN_BG_COLOR:=0;
	//Clearscreen($20, ^$0400);	
	setscreenlocation($1C00);
	
	while(1=1) do begin
		if (compressionType=3) then 
			RenderNextPackedFrameCompressionType3();

		if (compressionType=2) then 
			RenderNextPackedFrameCompressionType2();
	
		for i:=0 to 25 do 
			waitforraster(0);

		if (curFrame>maxFrames) then begin
			ReadAnimationHeader();

		end;
	end;

	Loop();

end.


