
procedure RenderScrollerText(rs_ypos:byte);
begin
	if (ms_scroll>=127) then begin
		val:=zeropage1[0];
		moveto(0,rs_ypos, $84);
		if (val=$20) then val2:=val
		else begin
			if val>=64 then val:=val-65;
			if val>=16 then val:=val+24;  
			val:=val*2;
		
			val:=val + ms_sshift;
			val2:=val+40;
		end;

		screenmemory[39]:=val;
		screenmemory[39+40]:=val2;
		ms_scroll := 7;
		inc(ms_sshift);
		if (ms_sshift=2) then begin
			ms_sshift:=0;
			inczp(zeropage1,1);
			//if (rs_text[0]=0) then inczp(rs_text,1);
	
		end;


	end;



end;


procedure RenderText2x2();
begin
	i:=0;
	val:=@renderText2x2[0];
	k:=0;
	while val<>0 do begin
		if val>=64 then val:=val-65;// Find value
		if val<>$20 then begin

			if val>=16 then val:=val+24;  
			val:=val*2;
		
			val:=val + k;
		
			screenmemory[i]:=val;
			screenmemory[i+40]:=val + 40;
			screenmemory[i+1]:=val+1;
			screenmemory[i+41]:=val  + 41;

		end;
		i:=i+2;

		inczp(@renderText2x2,1);
		val:=@renderText2x2[0];

	end;


end;


procedure RenderLevel(rl_levels: pointer; m_li, m_lj, m_screen: byte);
var
   m_rl_width, m_rl_height : byte;
   m_rl_sizex, m_rl_sizey : byte;
   m_rl_startx, m_rl_starty : byte;
   m_rl_dataSize, m_rl_pos : byte;
   m_rl_i, m_rl_j, m_rl_val, m_rl_val2, m_rl_idx: byte;
   m_rl_chunksize, m_rl_chunks : byte;

begin
	// Fluff files have 13 byte headers
	inczp(rl_levels, 13); // Fluff header

	// Read level header info

	m_rl_sizex := rl_levels[0];
	m_rl_sizey := rl_levels[1];

	m_rl_width := rl_levels[2];
	m_rl_height := rl_levels[3];

	m_rl_startx := rl_levels[4];
	m_rl_starty := rl_levels[5];


	m_rl_chunks := rl_levels[6];
	m_rl_chunksize := rl_levels[7];

	m_rl_dataSize := rl_levels[8];

	
	// Go past header

	inczp(rl_levels, 9);

	// Calculate position in level layout

	m_rl_pos := m_rl_sizex*m_lj + m_li;
	
	m_rl_val := m_rl_width*m_rl_height;
//	m_rl_val := m_rl_val;// + m_width; 

	// Skip levels
	if m_rl_pos<>0 then
	for m_rl_j:=0 to m_rl_pos do begin
			inczp(rl_levels,m_rl_val);
			inczp(rl_levels,m_rl_val);
			inczp(rl_levels,m_rl_dataSize);
	end;

	// Set screen position 

	moveto(m_rl_startx, m_rl_starty, m_screen);
	
	// Fill screen with chars
	//call(SIDFILE_1_PLAY);
	
	for m_rl_j:=0 to m_rl_height do begin
		for m_rl_i:=0 to m_rl_width do begin
			m_rl_val := peek(rl_levels,m_rl_i);
			m_rl_idx:=m_rl_i*2;

			screenmemory[m_rl_idx]:=m_rl_val;
			screenmemory[m_rl_idx+1]:=m_rl_val+1;
			screenmemory[m_rl_idx+40]:=m_rl_val+40;
			screenmemory[m_rl_idx+41]:=m_rl_val+41;
		 end;
		inczp(screenmemory, 80);
		inczp(rl_levels,m_rl_width);
	end;
	// Then colors
	moveto(m_rl_startx, m_rl_starty, $D8);
//	call(SIDFILE_1_PLAY);
	@colorpointer:=rl_levels;
	for m_rl_j:=0 to m_rl_height do begin
		for m_rl_i:=0 to m_rl_width do begin
			m_rl_val := peek(rl_levels,m_rl_i)&7 + 8;
			m_rl_idx:=m_rl_i*2;
	
			screenmemory[m_rl_idx]:=m_rl_val;
			screenmemory[m_rl_idx+1]:=m_rl_val;
			screenmemory[m_rl_idx+40]:=m_rl_val;
			screenmemory[m_rl_idx+41]:=m_rl_val;
			


	 	end;
		inczp(screenmemory,80);
		inczp(rl_levels, m_rl_width);
	
	end;
	// Set multicolor colors
	//call(SIDFILE_1_PLAY);
	m_rl_val :=  peek(rl_levels,0);
	poke(MULTICOLOR_CHAR_COL, 0, m_rl_val);
	m_rl_val :=  peek(rl_levels,1);
	poke(MULTICOLOR_CHAR_COL, 2, m_rl_val); 
	m_rl_val :=  peek(rl_levels,2);
	poke(MULTICOLOR_CHAR_COL, 1, m_rl_val);

	inczp(rl_levels, 3);

	@levelpointer:= rl_levels;
	// levelpointer now points to chunk data!

end;


/*
Renders a .flf level at map pos x,y
*/


//Goes through all data and resets the isdead flag to 0

procedure ResetLevels(rl_levelp:pointer);
begin
	inczp(rl_levelp, 13); // Fluff header
	inczp(rl_levelp, 9); // Level designer header
	m_rl_val := m_rl_width*m_rl_height;
	k:=m_rl_sizex*m_rl_sizey;
	if k<>0 then	
	for m_rl_j:=0 to k do begin
		inczp(rl_levelp,m_rl_val); // Data
		inczp(rl_levelp,m_rl_val); // Colors
		inczp(rl_levelp,3); // MC/BG Colors
		
		for i:=0 to m_rl_chunks do begin
			rl_levelp[@entity_isdead]:=0;
			inczp(rl_levelp,m_rl_chunksize);
		end;
		//			inczp(@levelpointer,m_rl_dataSize);
	end;
	
	
end;



// Prints colored text (slow, unused for now)
Procedure PrintTextColor();
begin
	j:=time/4;
	for i:=0 to 40 do begin
		
		val := LIGHT_GREY; //Yellow in MC//fade[(i+j)&15];
		poke(^$D800,i,val);
		poke(^$D828,i,val);
		//poke($D800, i,val );
		//poke($D800+ 40, i, val);
	end;
	
end;

// Renders upper and lower text
procedure PrintText();
begin
	// The "Rogue Burger" logo
/*	for i:=0 to 25 do begin
		poke(^$8400, i, i + 120);
		poke(^$8400+ ^40, i, i + 160);
		//poke(@screenmem2, i, i + 120);
		//poke(@screenmem2+ ^40, i, i + 160);
		val := fade[i&15];
		poke(^$D800, i,val );
		poke(^$D800+ ^40, i, val);
	end;*/
	
	@renderText2x2:=TextRogueBurger;
	moveto(0,0,$84);
	RenderText2x2();
	

	moveto(0, 24, $D8);
	for i:=0 to 40 do
		screenmemory[i] := RED;
	
	moveto(30, 1, @screen1hi);
	
	printstring("SCORE", 0, 10);
	
	moveto(1, 24, @screen1hi);
	
	printstring("LIFE", 0, 10);
	
	//moveto(30, 24, @screen1hi);
	
	//	printstring("AMMO", 0, 10);
	
end;

procedure ClearText();
begin
	for i:=0 to 25 do begin
		poke(@screenmem1, i, @clearchar);
		poke(@screenmem1+ ^40, i, @clearchar);
		
	end;
	moveto(0, 24, $D8);
	for i:=0 to 40 do
		screenmemory[i] := @clearchar;
	
	
end;

/*
Draw some hearts
*/


procedure RenderHealthBar();
begin
	moveto(6, 24, $D8);
	zeropage1 := screenmemory;
	moveto(6, 24, @screen1hi);
	
	tmp2 := player_maxhealth/8;
	k := player_health/8;

	if tmp2<>0 then	
	for i:=0 to tmp2 do begin
		screenmemory[i] := 96;
		if i<k then
			zeropage1[i] := YELLOW
		else
			zeropage1[i] := RED;
	end;
end;

procedure RenderBulletBar();
begin
	moveto(34, 24, $D8);
	zeropage1 := screenmemory;
	moveto(34, 24, @screen1hi);
	
	tmp2 := 10/2;
	k := bullet_count/2;
	j:=bullet_dmg/4;
	if j>=8 then j:=8;
	if tmp2<>0 then	
	for i:=0 to tmp2 do begin
		screenmemory[i] := 103 +j;
		if i<k then
			zeropage1[i] := YELLOW
		else
			zeropage1[i] := RED;
	end;
end;
