We all would love to be jumping into coding some amazing games when beginning any new language. Before we do this however, we need to master some basics. Let’s get something displaying on the screen. We left our last lesson with the simple ‘Hello World’ example. Lets switch this up to printing the characters of the alphabet and making each character a different colour.
[I’m going to be using Kick Assembly for this example. Some of the elements here will be unique to its implementation]
The Main body of the Program
Let’s start with defining the memory address of Screen Ram and beginning our entry code.
Screen RAM and Color RAM
We know that everything in the C64 is addressable using memory locations. The 40 columns x 25 rows of screen you see when turning on the C64 is simply a 1000 Bytes (40×25) large area of memory called Screen RAM. This is located at address 1024 – 2023 or $0400 – $07F7.
Whatever you write into any of these 1000 locations it will show up some way on the screen. Anything placed at $0400 will print at the top left corner of the screen.
In addition to Screen RAM there is also Color RAM. This resides from location 55296 – 56295 or $D800 – $DBE7. It also spans over 1000 bytes and maps the Screen RAM locations 1:1. The lower 4 bits of the Color RAM are used to set the foreground color for the appropriate Screen RAM location.
Clearing the Screen
We want to put more emphasis on the colours of the letters, so let’s put out the lights and turn the border and background black. There are two memory locations where we need to do this – $d020 and $d021.
We have just learned that the actual screen is just an area in memory which spans over 1000 bytes. If we place a space bar in each of those locations and turn the foreground color to black we should achieve a completely black screen without any text.
We being a loop and using the four screen locations we begin to fill the screen with the space character which is $20. Since 1000 locations need to be filled out, but only 256 iterations can be done with a single byte counter we start at the four positions on the screen at once.
With this method we are able to fill the screen black with just 256 iterations. We then check our X-Index register has turned to zero with the bne (branch if not equal) command.
Looping through the Alphabet
We next want to loop through the alphabet and assign a different colour to each character.
We begin by looping through the characters of the Alphabet – at this point the value of the X register will correspond to the letter ‘A’ (decimal 1), and also the colour white ($01). As we go through the loop we increment this using inx and then check if we have completed all the characters of the alphabet (cpx #27) comparing the value in the x register to 27.
We then return from the subroutine.