program FlipDisk;
var

	const dataLoc: address = $5100;
	const spriteLoc: address = $5000;


	@requirefile "data/disksprite.bin" "Please run the raytracer file example11_diskette.fjo before compiling this program" 	
	sprite : incbin("data/disksprite.bin",dataLoc);
	
	ypos, x,i,k, curFrame,time: byte = 0;
	zp: pointer;

	const maxFrames:byte = 95;
	const xPos : byte = 70;

@define useKernal 1

procedure UpdateSprites();
begin
	// Point to sprite #curFrame.
	// One sprite is 64 bytes, and since we have 4 sprits per frame, 256 bytes. 
	// This means that we can basically just add the current frame counter to the high
	// bit of the sprite pointer!
	zp:=toPointer(hi(dataLoc)+curFrame,0);
	// Copy 256 bytes (4 sprites) worth of data
	//memcpy(atp2,0,atp3,0);
	memcpyunroll(zp,0,spriteLoc,256);
	// Poke sprite y positions
	poke(SPRITE_POS,1,ypos); 
	poke(SPRITE_POS,3,ypos); 
	poke(SPRITE_POS,5,ypos+42); 
	poke(SPRITE_POS,7,ypos+42); 
	
	// 95 frames in total
	curFrame:=mod(curFrame+1, maxFrames);

end;
/*
	Main raster

*/
interrupt Update();
begin
	startirq(@useKernal);
	
	inc(time);
	// Set y position of sprits
	ypos:=sine[time]/6 + 80;
	UpdateSprites();

	closeirq();
end;


procedure InitFloppySprites();
begin
	// Set sprite center of screen
	x:=xPos;
	// Setup sprites, 4 in total
	for i:=0 to 4 do begin
		setspriteloc(i,(($1000)/64)+i,1); // ($5000-1000)/64 = $40
		spritepos(x*2,0,i);
		sprite_color[i]:=light_blue;	
		x:=x+24;
		// Reset x
		if (i=1) then 
			x:=xPos;
	end;
	sprite_multicolor_reg1:=blue;
	sprite_multicolor_reg2:=white;

	sprite_bitmask:=%00111111;
	sprite_stretch_X:=%00001111;
	sprite_stretch_Y:=%00001111;
	sprite_multicolor:=%00001111;
end;


begin
	screen_fg_col:=black;	
	screen_bg_col:=black;	
	
	clearscreen(0,screen_char_loc);
	clearscreen(0,screen_col_loc);
	
	setbank(vic_bank1);

	InitFloppySprites();

	StartRasterChain(Update(),190, @useKernal);
	setmemoryconfig(1,@useKernal,0);
	Loop();
end.