Now, you’ve heard the soulful sounds of part one, this is part two. Are you ready?
Introducing the players:
The Sim, The Book, The Reference
The Sim is a wonder in itself, you’ll want that open in another tab while you read on, dear friends. If you want to be taken back to the heady days of 8-bit gaming, load up “Adventure” from the examples menu. (Use WSAD to move).
In our happy little 8 bit wonder, we have several things to keep track of.
There are a total of three general use registers:
Register X
Register Y
The Accumulator
The Accumulator handles all arithmetic and logic.
X and Y are general purpose registers that hold one byte (8 bits) of data. By the by, this is a joke that should be on the inside of
a laffy taffy wrapper:
Q: What do you call one half of a byte?
A: A Nibble
I’m sorry, our friend mentioned in part one had used the word ‘nibble’ so many times that it wasn’t funny to him anymore, but it made me laugh. Onward!
You can load X and Y, and A with a value directly:
LDA #02 ; Loads the value 2 into the accumulator LDX #00 ; Loads the value 0 into register X
Now then, we have two values that are loaded, one that we can use as a color (2 is red in this sim), we’d like to store that color in a memory address. We do so, like so:
STA $0200 // Store the value of the accumulator in memory address $0200
Compile that, and run it, and you should have a little red ‘pixel’ on the right. Keep in mind that this simulator is visually showing you the contents of memory as a color in that block.
STA can also take a register as an offset, thusly:
STA $0200,x ; Store the value of the accumulator in memory address $0200 plus an offset of the value in the X register.
Yes, yes, all very useful, but we need a looping construct! Enter JMP.
LDA #02 LDX #00 paint: ; Make a new subroutine called 'paint' STA $0200,x INX JMP paint ; jump back to the subroutine called 'paint'
This happy little 6502 program will continue to paint the town red. See how proudly it paints? Jump Forever!
Red is nice, but there is a way to make the program paint pretty stripes instead using only one new instruction. See if you can figure out how. You’ll need just one other instruction we haven’t used before in your paint subroutine. Here is the reference again for your perusing pleasure.

Part 3 will cover processor flags, and what amazing possibilities await you armed with those tools!