program tutorial_22_paw_decrunch;
var
   i:byte;	

/*
	For this tutorial to work, you must first load "tutorial_22_images.paw" and build
	the resource. 

	The .paw-file will automatically pack all listed data with their respected unpacking addresses,
	and create the include file used here. 

	press space to cycle between the two images
*/


// The following include file is automatically generated during paw file build
@include "tutorial_22_packed_resources_auto_generated.ras"


begin
	// Data located in high memory area $A000 range, so disable basic and stuff
	disableciainterrupts();
	setmemoryconfig(1,0,0);

	// Set mode
	setmulticolormode();
	setbitmapmode();
	// Bitmap points to $6000 etc
	poke(VIC_DATA_LOC, 0,$18);
	setbank(VIC_BANK1);
	SCREEN_FG_COL:=BLACK;
	i:=0;
	while (1=1) offpage do begin
		// Turn off screen during decrunching process
		screenoff(); // turn off screen while decrunching..
		// unpacks color data to $2000
		decrunchfromindex(tutorial_22_packed_address,i+1); 
		// copy color data to screen + $D800
		copyimagecolordata(^$2000,1);
		// Decrunch image data
		decrunchfromindex(tutorial_22_packed_address,i); // decrunches to vic 1
		// Turn on screen
		screenon();
		while (keypressed(KEY_SPACE)=0) do waitforraster(0);
		i:=i+2;
		// Reset counter after 3 images + data 
		if (i=6) then i:=0;

	end;
	Loop();

end.
