program BitmapImage;


@VicMemoryConfig "all"
@ignoremethod "init16x8div"

@ignoremethod "init16x8mul"

@ignoremethod "init8x8div"

@ignoremethod "initrandom"


// Image in images/logo.flf

var  

// Size of image. Defined when creating and drawing the flf file
const imageWidth:byte = 20;
const imageHeight:byte = 20;

// Bitmap will be loaded as a charset
const charsetAndBitmap:address = $1400;

	i,j,k, time,t:byte;
	zp: pointer;
	charset : incbin("resources/images/logo.bin", charsetAndBitmap);


// Put all code at $2400
@startblock $2600 Code

// Copy color data from bitmap data
procedure CopyImageColor();
begin
	zp:=#charsetAndBitmap + imageWidth*imageHeight*8;
//	
	moveto(0,0,$94);
	for j:=0 to imageHeight do begin
		for i:=0 to imageWidth do begin
			k:=zp[i] | zp[i+imageWidth];
			screenmemory[i]:=k;
		end;
		screenmemory := screenmemory + imageWidth;
		zp := zp + imageWidth*2;
	end;
end;

procedure Main();
begin
	// Turn off interrupts so we won't be distrubed
	DisableVIC20IRQ();
	// Background is PURPLE and BLACK		
	SCREEN_BG_COLOR:=PURPLE*16;
	// Auxilliary color is cyan
	AUX_COLOR_AND_VOLUME:=CYAN*16;
	// Screen to $1000
	setscreenlocation($1000);
	// Set charset location to where bitmap data is
	setcharsetlocation(charsetAndBitmap);
	// Set height of columns (-1, needs to be odd)
	SCREEN_TEXT_HEIGHT:=imageHeight-1;
	// Width of screen same as bitmap
	SCREEN_TEXT_WIDTH:=imageWidth;

	// Copy color data
	CopyImageColor();

//	$900E:=10;
	

	// Draw 256 chars on the screen from 0 to 256
	moveto(0,0,$10);
	for i:=0 to 0 do 
		screenmemory[i]:=i;
	

	// After this, some random raster effect
	while (true) do begin
		time:=time+4;
		t:=sine[time]/4+32;
		
		waitforraster(t);
		aux_color_and_volume:=black*16;
		for i:=0 to 24 do begin
			screen_bg_color:=blue;
			waitnoraster(1);
						
		end;
		aux_color_and_volume:=purple*16;
		screen_bg_color:=blue*16;
	end;

end;

@endblock

begin
	Main();	
end.
