Tiles

Now that the ui is on screen I’d like to fill it with something. Sometime ago I did a tileset for character potraits so let’s take that and find a way to get it on screen.

Importing the file

First off I export the tile and char set as asm data and import it into my code at address $a000 (the space normally blocked by the basic rom) for now.

Copy to Clipboard

Then I add some constants that I am going to need for easy access.

Copy to Clipboard

Now I reserve an address space for all pc data and store the tile id for each potrait there.

Copy to Clipboard

I am going to need some tables to help me find all the addresses for the tiles, chars, and screen addresses. So I create manual tables for the row starting points and offsets and use Kick Assemblers for function to generate the addressing tables.

Copy to Clipboard

Now let’s start with the code. First I write a short loop for traversing through all the portrait positions and getting the tile id for that position.

Copy to Clipboard

For drawing the portrait I need to get the current tile, starting position, char, and color data. So first off I start by getting the tile height and current potrait number.

Copy to Clipboard

Now I read the starting positions and tile addresses from my tables based on the current potrait number.

Copy to Clipboard

To get the address of the char data I read the current tile data from the address I just calculated and use it to look up my character table. As I can use the same index to load the color data addresses I do that as well.

Copy to Clipboard

I now have all the addresses I need to start actually drawing the tile. First I iterate through the tile from left to right and store the color information at its respective screen addresses. After that is done I load the portrait pixel height minus one (0 to 23) to setup the loop through the actual char data.

Copy to Clipboard

I iterate through all the char data and draw it on screen until I reach the end, or rather the beginning.

Copy to Clipboard

After the row has been successfully drawn I calculate the next screen and tile addresses and repeat the entire process until the tileheight stored in the zeropage reaches 0.

Copy to Clipboard

Compiling the code

After compiling the code the portraits have been added in their propper places.

And as allways I run it on TheC64 as well.

And once again the complete code listing.

Copy to Clipboard