program Tutorial_26_spritelogo;
var  
   	org_x, x: integer;
	y, org_y,i,j, time: byte;

	sprites: incbin("sprites/tutorial26.bin", $2000);

	text: cstring=("  SPRITELOGO  ");
	tp : pointer;

@define useKernal 1

procedure InitSprites();
begin
	// 4c2
	SPRITE_MULTICOLOR:=$FF;
	SPRITE_BITMASK:=$FF;
	SPRITE_STRETCH_X:=$FF;
	SPRITE_STRETCH_Y:=$FF;
	SPRITE_MULTICOLOR_REG1:=LIGHT_BLUE;
	SPRITE_MULTICOLOR_REG2:=GREY;
	for i:=0 to 8 do begin
		SPRITE_COLOR[i]:=BLUE;
		setspriteloc(i,$80+i,0);
	end;
end;

procedure UpdateSprites();
begin
	
	x:=org_x;
	y:=org_y;

	for i:=0 to 8 do begin
		if (i=4) then begin
			x:=org_x;
			y:=y+21*2;
		end;
		spritepos(x,y,i);
		x:=x+24*2;
		
	end;

end;


interrupt Raster1();
begin
	StartIRQ(@useKernal);

//	org_x:=100;

	org_y:=sine[time*5]/4+70;
	i:=time*4+80;
	org_x:=sine[i]/4+70;


	UpdateSprites();
    asm(" ; crash");
	inc(time);
	CloseIRQ();
end;


procedure RenderText();
begin
	moveto(0,0,$04);
	tp:=text;
	for j:=0 to 25 do begin
		for i:=0 to 40 do begin
			if (tp[0]=0) then tp:=text;
			screenmemory[i]:=tp[0];
			inczp(tp,1);


		end;
		inczp(screenmemory, 40);

	end

end;


begin
	ClearScreen($20,^$0400);
	ClearScreen(DARK_GREY,^$D800);
	SCREEN_BG_COL:=DARK_GREY;	
	SCREEN_FG_COL:=BLACK;
	RenderText();
	InitSprites();
	StartRasterChain(Raster1(), 0, @useKernal);


	Loop();
end.
