program Tutorial8_Text8x8;
@use "text/text"
var 
	done,i,j,x,y,time : integer = 0;
	// pointer to the screen
	screen : ^byte;
	

	// Export 1 bitplane from the font in order to save space
	@export "fonts/font8x8.flf" "images/font8x8.bin" 256 1 // 1 here means 1 bitplane

	// Include the font data
	font : incbin("images/font8x8.bin") aligned;
	// wobbling text
	text : string = "I FEEL LIKE PETSCII";

	sin : array[256] of integer = buildsinetable(64);



procedure DrawText();
begin
	x:=2;
	j:=time;
	for i:=0 to length(text) do 
	begin
		y:=100 + sin[j&255];
		// Clear the line above each letter
		screen[y*160 + x]:=0;
		Text::DrawChar(text[i], x ,y+1, screen);		
		// Increase phase by some random number
		j+=11;
		x+=8;
	end;
	
end;

begin
	// Set to lores mode
	SetLoRes();
	
	// Get screen pointer
	GetScreen(screen);
	
	// Set black background
	poke16(#palette_start, 0,0);
	// Color 1 white
	poke16(#palette_start, 2,$FFF);
	// Color 2 purple
	poke16(#palette_start, 4,$E3F);

	Text::Init(#font, 160, 64, 8, 8, #Text::lookup8x8);
	
	
	Text::Draw("HELLO WORLD ATARI", 0,20, screen);
	
	//Loop until keypressed
	while (done = false) do
	begin
		DrawText();	
		time+=1;
		waitverticalblank();
		done:=keypressed(sc_key_space_pressed);
	end;	
end.


