A few years ago I was taking a course on operating systems. As a way to understand more of the basics around processors and machine code, I wrote a very simple "starfield" in Assembly for the Commodore 64.
The exercise
The "starfield", stars floating by at several distances and speeds, creating a parallax effect. For some reason it is one of my go-tos when I familiarize myself to a new system when graphics are involved.
It's a simple thing, and I thought that would be advanced enough for a first journey into assembly.
Retro computers
I picked the good old Commodore 64 as a platform. Simple enough to understand every part of the computer if need be, and lots of documentation around the internet thanks to the retro computing community.
I quickly found a few resources to lean on:
I later looked into writing some code for Nintendo Entertainment System, and if I ever do another 6502 project, I will probably use cc65 instead of KickAssembler.
The result
I found a simple sprite example somewhere, and I went from there.
Using KickAssembler feels a little like cheating. It has some built in snacks that lets you load GIF files directly into sprite memory. For this simple code one could just as easily just hand-code the circles.
The code is as simple as it gets:
- Initialize border and background to black
- Clear screen
- Enable sprites, set colors and data pointers
- Pick random speeds for all sprites
- Loop
- Wait for screen blanking
- Update all sprite positions
- Recycle sprites that have moved out of the viewport
I started on some more advanced functionality like background music, but dropped it. The resulting clutter was of course left for later use.
You can have a look at the code on my Github, or just have a look at the result below:
(Edit 2023: Moved the video clip to YouTube)