Over the previous posts in this series we took the C64 apart piece by piece. Registers, memory, instructions, flow control, and the hardware chips. Now we put it all back together into something that works.
The project is a five-note mini piano. The keys Z X C V B play C D E F G. Each note changes the screen border color, plays a sound through the SID, and displays the note letter in the center of the screen. Simple enough to fit in one post, complex enough to use all three chips together.
In the four previous posts we built the complete model. Registers, memory, instructions, decisions, and loops. You already know how a program moves through memory and how the processor executes every byte it encounters. What is missing is the most surprising part of the C64 story, and probably the most elegant idea in the entire series.
Writing to memory was triggering hardware
In the post about the memory map we saw that certain regions were not regular RAM. The range from $D000 to $DFFF belonged to the hardware chips. The VIC-II, the SID, and the CIA. But what that means in practice only becomes clear when you see the code.
In the previous post we saw how the processor moves data and does arithmetic. But a program that only executes instructions in a straight line does not do much of anything useful. At some point it needs to make a decision. Go one way or another, depending on a result. It needs loops, conditionals, the ability to behave differently depending on the state of things.
In 6510 assembly, all of that is built on a single mechanism. Flags.
In the previous post we built the map. We know where data lives, how memory is organized into addresses, and why certain regions were worth more than others. Now for the missing piece. What the processor actually does while running a program.
The program is also bytes
In the post about the execution cycle we saw that the processor reads a byte, interprets it as an instruction, executes, and moves to the next. But we never talked about how a byte becomes an instruction.
In the previous post we saw that the processor has three general-purpose registers and a simple, uninterrupted execution cycle. The problem is that three registers are not enough for any real program. You need somewhere to store data while you are not using it, store the program itself, store variables and intermediate results. That place is RAM.
RAM is one giant array
If you have ever used an array in any language, you already understand RAM. The C64’s memory was exactly that:
In Part I we covered the landscape. The era, the machine, the context. Now it is time to go one level deeper and understand how the processor actually works. Where data lives, how instructions are read, and what happens every fraction of a second while a program runs.
Registers, the processor’s workspace
When you write something like x = 5 + 3 in any modern language, the processor needs to pick up the 5 from somewhere, pick up the 3 from somewhere, add them together, and store the result. That “somewhere” is the registers.
When I entered the tech industry in the back half of the 2010s, high-level languages were already the default. When I studied Computer Engineering, even embedded systems were written in C++, and that was considered the low level. In the software and games world, the abstraction went even further. Java dominated the industry, and Unity was in the middle of democratizing game development to the point where anyone with a free weekend could ship something playable.
You have probably walked past a brutalist building without knowing the style’s name. They are those raw concrete constructions, unplastered, where you can see the marks of the molds used in casting. Structure exposed. Piping sticking out. For a long time, computers were like this.
In the 80s, when you turned on a microcomputer (MSX, Apple II, or my personal favorite, the TK90x/ZX Spectrum), there was no desktop. There were no folder icons simulating an office. There was no metaphor at all. What appeared was a blinking cursor, waiting. The machine looked at you and asked: “What’s the plan for today, boss?”