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.
Then I add some constants that I am going to need for easy access.
Now I reserve an address space for all pc data and store the tile id for each potrait there.
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.
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.
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.
Now I read the starting positions and tile addresses from my tables based on the current potrait number.
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.
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.
I iterate through all the char data and draw it on screen until I reach the end, or rather the beginning.
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.
And once again the complete code listing.
Leave A Comment