Dustlayer

Retro means old but cool.

I grew up with the Commodore C64 but was never able to master the machine. I was young, I wanted to play the latest games and let other people do the pioneer work on exploring this incredible hardware. Today I have better skills to catch up on what it takes to code the C64. I will share what I learn along the way. Enjoy the trip to the past!

Episode 3-1: Spritro - an Intro with a Sprite

Synopsis: In this huge Episode we will analyze an intro with an animated Sprite controlled via Keyboard. To spice up the action we add a new color cycle effect and open the top and bottom borders where our sprite can freely move into. Finally we fix a SID file which is not locating it's data at our desired memory location.

Download via dust: $ dust tutorials (select 'spritro')
Github Repository: Spritro Source Code on Github


Spritro - a simple intro with a Sprite

Welcome to a new multi-part tutorial on C64 programming on dustlayer.com! It's been a month since the last coding tutorial but I did not waste a lot of time in-between but  filled the site with a few in-depth knowledge base articles. 

If you have not read the Knowledge Base Series VIC-II for BeginnersMath Basics and Hardware Basics yet - I encourage to do so. 

I  improved a bit on my coding style and changed things around in how I structure new projects. This first chapter is an overview of the actual outcome of this tutorial and how everything is organized. 

But first - download the Spritro via DUST or clone it from the Github repository linked above, then build it. If you are too lazy to do this now, you can also watch the following video.

Some obvious and not so obvious features

This little intro comes with an animated Sprite - of course you know it's the famous Manta Class Ship from Uridium. It moves smoothly from right to left - but did you notice something?! Is this ship not a bit low on the screen? Shouldn't there be a border?!

It should! But by exploiting a VIC-II bug the top and bottem borders have been removed and the Sprite can freely move across 312 PAL Rasterlines on the screen. You also have some control by hitting the U or D key to move the ship up and down.

Additionally as opposed to the First Intro Tutorial we use a custom font to display some text on the screen - actually it is a very popular character set from the game Rambo First Blood Part II - used in dozens of other games and intros before. 

The different color cycle effect on the text is this time not based on a table of values but kinda syncs with the 16 frames of the Ship animation. If you don't understand at this moment - don't worry, I will explain it along the way. There is also a periodic switching of colors in the side borders to demo how to delay timing of effects while on the interrupt.  

Last but not least an awesome SID tune is playing - this time "Empty (512 Bytes)" by 4-Mat. The original SID file places it's play routine and data in a memory location not suitable for our intro so we learn how to relocate SIDs in memory. This is a task  which was rather tedious to do not so long ago but with a recently released tool it has become incredibly easy.

That's it! We have a lot of ground to cover but first, I want to explain what you find where in the project.

Project Structure

As with the last tutorial we stick to three directories and an index files. 

The index.asm file is basically something like a header file which includes all the other source code files from the project plus it sets up a BASIC loader so we do not have to type SYS 49152 ourselves after loading the .prg. It is the file you compile against to build your .prg output file.

Spritro Directory Structure

Spritro Directory Structure

If the /build-directory does not exist, it is created automatically when you compile the intro for the first time. It contains the finished executable .prg file and - if you use DUST -  a list of labels and their memory addresses are dumped here into a file and on the screen as well. If the labels are not generated you need to update DUST with the command 'dust setup' and select option 1 ("install all"). 

The /resources-directory includes  all our binaries we like to load into the intro, namely a SID file, our custom character set and of course the Sprite Data.

Finally the /code-directory includes all the routines and other code. The prefixes on each file indicate their role.

config-files set up something, e.g. place a loaded sprite at the desired memory location, initialize registers at start, setup symbols, define how to actually load a binary. 

data-files are strings or tables with information to iterate over. For Spritro it's just three lines of static text.

sub-files are subroutines. I use one file per subroutine usually and the name of the file minus the prefix corresponds to the label in the code you would jump to. 

Finally, the main.asm file is the basis of our custom interrupt routine and executes all the other subroutines either one-time or periodically during the interrupt.

Ready, Set, Go!

Now go to the next chapter which will deal with the Sprite creation process. Enjoy this new Episode and don't hesitate to send comments or like my Facebook page or follow me on Twitter.

-act