TRSE Disk Management tutorial

TRSE supports easy-to use & automated management of 170K .d64 disks. This small tutorial project mirrors the source code / settings from the TRSE/tutorials/C64/disk_loader_project included with TRSE from version 0.06.

Even though there is a certain satisfaction when packing your project data *perfectly* into the c64 64k’s of memory, most larger demos and games will require both additional code and resources. These resources (such as graphics, music, sprites or pure code) can be stored as separate files on a disk, and can be loaded run-time from the program when needed.

As the original disk operating system (DOS) for the 1541 disk drive is both slow and require that interrupts are disabled while reading, modern c64 programs that require disk access are usually developed with newer “patched” versions of disk reading software – so called fastloaders. The fastloader will replace both the original DOS software on the 1541 drive and on the C64 itself (Kernal). The fastloader will be uploaded to the disk drive and will replace the original software as long as the device is turned on (it won’t overwrite the old API which is stored in ROM and loaded every time you reset the device)

The most famous / best / fastest of these user-defined c1541 loaders are called Krill’s loader (by Krill of Plush).

In TRSE, we have from version 0.06 added automated support for both Krill’s loader and management of files from disk.  In this tutorial, we will set up a .d64 project, add two image files and load these from disk run-time. You can cycle the images by pressing space bar, and we don’t turn off the screen while loading so you can experience the actual loading process.

Step 1: Setting up a project

First, create a new TRSE project and create a new .ras source file named “main.ras“. Afterwards, click the “project settings” button on the right-hand side of the main window. In the new “Target Output” tab, you can customize various target options such as:

  • Project output type : prg or disk (d64) (16kb cartridge file support will be added later)
  • Main project file: if “none”, then the compiler will only try to compile the current file you are viewing. If you select a specific file here, the compiler will always try to compile this file when pressing ctrl-B, regardless of which source file that is open.
  • If you have a disk project, then you will need to specify a .paw file that defines the contents of the disk (except the .prg file).

For this disk project, select output type “d64”, and select the main source file “main.ras”.

Defining the disk

The main program file will always be copied to the .d64 disk. In addition, you can specify which addition files you would like to be stored on the disk.

Paw files are previously used in TRSE to specify a list of data files that will be automatically packed and extracted to specified memory locations. Due to the similarities of disk files, the Paw data type is also used for specifying which files should be included on the project disk. The list contains filenames (on pc), filenames on the disk and load address. The filename will also be duplicated as a string in your program.

Here’s a detailed list of the Paw file specifications:

  • Since this is not crunching, you don’t need to specify a RAS output file, memory address to pack to and name of any address field.
  • The “packed directory” needs to be defined. This is the directory where your include files will be copied to, before being slightly modified with a header that defines the load address. These are temporary files and can be deleted anytime, as the compiler will re-create them on each build.
  • You don’t need to compile the file, it will be read and assembled every time you build your .d64 project
  • “The “name” field contains the name of the file on disk, duplicated in your TRSE project. Max 16 chars.”
  • The “file” field contains the location of the file on your pc
  • The “unpack address” field contains the memory address the resource will be loaded to.

Now, copy some mock image files from one of the tutorials (or your own image files) to the project directory and include them as shown in the picture above. Click save and build. Finally, in the “project settings” dialog / Target output, select your .paw file as the project’s file list. The next time you build the ‘main.ras’ file the D64 will be created.

Turbo Rascal and loading from disk

We have finally set up a disk project with some resources (images), so we’re ready to start coding. First of all, we need to discuss how Krill’s loader work.

Krill’s loader work in the following way:

  • Include a ~$200 “loader” code file to a specific memory address. This is the part of the fastloader that will be placed on the C64 side.
  • Include an “installer” code to a specific memory address. This is the part of the fastloader that will be placed on the 1541 side.Call the installer code before anything else. This will install the krill’s loader onto the disk drive. This memory can now be overwritten. Note: remember to disable all interrupts before calling the installer. After the fastloader has been properly uploaded to the 1541 you may enable interrupts.
  • Move the “loader” code to a desired location. We recommend $200, but we have also allowed for locations such as $1000, $2000.. $F000 etc. Finally, if you use the recommended location such as $200, you need to specify a temporary location to place this code before it will be copied to $200 (and then the original location can be overwritten). This is all done automatically in TRSE.

In the tutorial project file, this is how we decided to do it:


program disk_loader_project;
var  
   i: byte; 
   @use KrillsLoader $0200 $3000 $5000 

begin
   InitKrill();


Explanation:

  • “@use KrillsLoader” tells the preprocessor that we will be using Krills Loader. Note that the “@use” pre-processor must be used within a variable block, as it will be inserting all the required gunk for Krill.
  • The first parameter $0200 defines where you want the resident loader to be placed.
  • The second parameter “$3000” is the original location of the resident loader. When calling the TRSE krill installer method, this code will be automatically copied to $0200.
  • The third parameter “$5000” is the location of the krill’s disk installer. This code will be called when the TRSE krill installer method  InitKrill() is performed.
  • Both the data at $3000 and $5000 can be overwritten as soon as the initialization process InitKrill() is complete.

Finally, in order to load a file, all you need to do is to call

KrillLoad(my_file);

Remember that both the my_file and load address are specified in the project Paw file!

The rest of the image viewer

Here’s the source for the rest of the viewer. it will alternate with loading the first and the second file (moose / octopus) when pressing space. Since the screen is on during the load process, you can view the data being loaded real-time.


//	setmemoryconfig(1,0,0);
	setmulticolormode();
	setbitmapmode();
	// Bitmap points to $6000 etc
	VIC_DATA_LOC := $18;
	SCREEN_FG_COL:=BLACK;
	i:=0;
	setbank(VIC_BANK1);
	while (1=1) offpage do begin
		// Turn off screen during decrunching process
//		screenoff(); // turn off screen while decrunching..
		if (i=0) then KrillLoad(octopus_color);
		if (i=1) then KrillLoad(moose_color);

		copyimagecolordata(^$2000,1);
		// Decrunch image data
		if (i=0) then KrillLoad(octopus_data);
		if (i=1) then KrillLoad(moose_data);
		while (keypressed(KEY_SPACE)=0) do waitforraster(0);

		i:=i+1;

		if (i=2) then i:=0;

	end;

end.