Let’s add a scene! Part 3

This tutorial corresponds to file “C64/DemoMaker/demo_part3.ras”  in the TRSE tutorials folder.

Ok, so we’ve created the skeleton of our demo, but still lack any effects. Let’s start by adding the most basic of basic effects: displaying an image. When this tutorial is done, you will have a music-playing demo that initializes and decrunches two images (all while playing music) – re-using the same scene code.

Thinking ahead, let’s decide on collecting all our resources into a TRSE Paw file. The idea is simple:

  • Keep all resources packed neatly together in a part of memory that is seldom used (like $A000$F000). Let’s call this “Packed area
  • Whenever you need to set up a scene (with either images or charsets or level data), unpack to bank1 or 2 ($4000-$A000). Let’s call this “Temporary data area“, because the data can be overwritten by the next scene.
  • Keep the code below $4000, if you can’t move parts of it to a place where it won’t be overwritten.

A TRSE Paw file is a simple text file where you can add resources (images, charsets, any data) that will be packed together and included automatically into your project. Let’s decide on adding two multicolor images ( 2x data + 2x color info) and a standard character set for some nifty effects. Here’s a screenshot of the packed paw file :

Some comments:

  • Compressed files will be packed to a “compressed/” folder within the current project
  • The automatically generated .ras include file will be called “packed_resources.ras“. Remember to include this file in your main demo right after the variable declarations.
  • The data will be packed to $BB73 (the reason for this address becomes evident afterwards)
  • The images unpack to $6000 on bank 1, while the color data is unpacked to $4800 (before being copied to color ram later)
  • Character set is located on $6800 om bank 1.

Here’s what the memory setup looks like :

Notice how all the packed data is stuffed directly right after the SID music file – which ends at $BB73. No space wasted!

We’re now ready to create our first scene, an image viewer.

Scene 1

Let’s create a new file in  “include/scene1.ras”. In its simplest form a scene must contain two elements:


interrupt RasterScene1();
begin
	startirq(@useKernal);
        ProgressTracker();

	closeIRQ();
end;


procedure InitScene1();
begin
end;

Now make sure that these two methods are used in the main demo ras file


procedure InitSceneRaster();
begin
	if (nextScene=@scene1) then 
		RasterIRQ(RasterScene1(),0,@useKernal);
end;

procedure MainLoopInitScene();
begin
	if (nextScene=@scene1) then 
		InitScene1();

end;

Initializing the scene

This is quite straight-forward: Set VIC data location, decrunch data, copy colors, done! We also use a little trick to be able to reuse the scene all while displaying different images:


procedure InitScene1();
begin
	SCREEN_BG_COL:=BLACK;
	SCREEN_FG_COL:=BLACK;
	setbank(VIC_BANK1);
	// Use the 3rd column of the timestamp to specify index of the packed data!
	i:=timeStamps[currentPart*4+2];
	// Enable reading $D000-$DFFF
	enableallram();
	// Decrunch image data to $6000	
	decrunchfromindex(packed_data_addresses,i); 
	// Decrunch color data to $4800
	decrunchfromindex(packed_data_addresses,i+1);
	// Restore memory config
	poke(^$01, 0,keep01);
	// Copy color data to bank 1 and $D800
	copyimagecolordata(^$4800,1);
	// Enable multicolor bitmap image at location $6000
	poke(VIC_DATA_LOC, 0,$18);
	setbitmapmode();
	setmulticolormode();

end;

 

Comments:

  • Don’t turn on screen or change to bitmap graphics until the very end
  • We use the 3rd column of the timeStamp array (user data #1) as the *index* of which crunched data to decrunch. Remember the image of the .paw file above? The 0th index corresponds to image1_data, index 1 is image1_color, index 2 is image2_data etc…. This way, we can reuse scene1 as a generic image displayer.
  • Since our crunched data overlaps $D000-$DFFF (reserved for the VIC), we need to enable all ram before decrunching.  Original memory configuration is restored afterwards (value in keep01)
  • Finally, copy the color information and turn on multicolor bitmap mode with data located at $6000!

Finally, let’s set up the scene timestamps to show our two fabulous images. In the main ras file, change the timeStamps to


	timeStamps: array[64] of byte = (		
           @scene1, $7, 0,0, 
           @scene1, $10,2,0
	);

When running this tutorial demo (part 3), you’ll have to wonderful images that load and decrunch (at time4=$7 and $10) while the music is playing in the background.

In the next tutorial, we will be adding a character based effect as the second scene, and provide transitions to all our effects.