program part4_charsets;
var  
	// Charset at $2000
@define charLoc $2000
// Automatically export sprites on each build, so you don't have to manually export
@export "sprites/Sprites.flf" "sprites/sprites.bin" 256
// Automatically export charsets 
@export "charsets/charset1.flf" "charsets/charset1.bin" 256

   	charset1: incbin("charsets/charset1.bin", @charLoc);
	// Pointer that will point to character data location at $2000+$800=$2800
	colors :  incbin("charsets/charset1_color.bin", @charLoc+$800);
	i:byte;

// Prints a 2x2 block at position x,y with the upper left value of c, (and c+1, c+40 and c+41)
// Also prints colors based of the "colors" pointer (which must be initialized first)
procedure print2x2block(x,y,c:byte);
begin
	moveto(x,y,hi(screen_char_loc));
	screenmemory[0]:=c;
	screenmemory[1]:=c+1;
	screenmemory[40]:=c+40;
	screenmemory[41]:=c+41;

	moveto(x,y,hi(screen_col_loc));
	screenmemory[0]:=colors[c]+8;
	screenmemory[1]:=colors[c+1]+8;
	screenmemory[40]:=colors[c+40]+8;;
	screenmemory[41]:=colors[c+41]+8;;

end;


begin
	// Fill the color ram with light blue
	clearscreen(light_blue, screen_col_loc);
	// Clear screen
	clearscreen(key_space, screen_char_loc);
	screen_fg_col:=black;
	screen_bg_col:=black;
	// Set color pointer
	// Set multicolor characters (grey brown) 
	// multicolor_char_col[0] is the same as SCREEN_FG_COL
	multicolor_char_col[1]:=grey;
	multicolor_char_col[2]:=brown;
	// Enables multicolor mode!
	setmulticolormode();
	// Let the VIC know where the charset is located
	setcharsetlocation(@charLoc);

	// Draw some lines of blocks
	for 	i:=0 to 18 do
		print2x2block(3 + i*2,2,0);

	for 	i:=0 to 18 do begin
		print2x2block(3 + i*2,20,2);
		print2x2block(3 + i*2,22,4);
	end;


	Loop();

end.
