This post brings together the five entries of my development log for a CHIP-8 emulator written in Rust with SFML. The code is in the rust-chip8 repository.
Day 1
Continuing my quest for learning Rust, I elaborated a list of potential projects. I started a couple privately but then I found the suggestion of creating a Chip-8 emulator somewhere. Unfortunately, I don’t remember where it was.
I started reading about the programming language and consumed resources like CHIP-8 Classic Manual, Cowgod’s Chip-8 Technical Reference v1.0, and Guide to making a CHIP-8 emulator. The latter kind of ruined the experience because it explains it so well, it also suggested implementing the opcodes needed to get the IBM Logo ROM running. Speaking of ROMs, I got a set cloning this repository.
I started with my code reading the ROM file to a byte vector and the basic rendering window. Then I started creating variables for the program counter, the RAM, the registers, and the stack. I proceeded to wrap these variables in a struct and added the call_operation function.
The display opcode was quite fun to implement, I first used SFML Rectangles directly but then moved to use a multi-dimensional array. Oh, and my bitwise operations to extract the bits from the sprite were inverted, so it caused some confusion.
As usual, there is a lot of improvement and refactoring to be done. I like to start with a dirty proof of concept and then work on it, but the call operation needs some serious refactoring and the display can be done directly to SFML Image/Texture.
I can’t deny it was a satisfactory experience since I never did something like it. Similar to other projects that I created and that are not web-related.
Except for reading files in binary form, there is nothing new regarding Rust in this project. I also need to practice writing unit tests during the development process.

Day 2
I got momentum and started implementing the other opcodes. I ended up with a messy code, a giant switch where everything happens.
I need to take the time and do a proper refactor to it. I still thinking about how I am going to implement it and the lack of free time is not helping much.
I also added the default font sprites at 0x50. But didn’t find any ROM that actually uses it.
Not much to show or tell about, but as soon as I finish the refactor, I am going to post an update. The progress can be checked on the chip8 emulator repository.

Day 3
Navigating through a couple of hectic weeks, just for a change.
However, today afforded me the chance to delve a bit deeper into the code. I refactored the video portion of the emulator, organizing the files and opcodes a bit more efficiently. There’s not much to showcase at the moment, but my current focus is on the 0x9xy opcodes.
Day Who Knows
This post sums up the small iterations of three different days. Basically, I implemented 9xy0 and cxkk opcodes, fixed some typos, corrected a few inconsistent implementations, and added SFML redraw only when the display opcode(dxyn) was called. Hence improving the performance.
I passed both test_opcode.ch8 and BC_test.ch8 test roms, which made many other roms work as well. I still need to implement the sound, input, and delay opcodes.
It’s been an enjoyable journey so far, besides taking a bit long due to the lack of free time. I am always thrilled when I get my hands on something different that’s not web-development related.

Day++
Yes, another post describing the few minutes put iterating on this project in a span of many days, and it has finally concluded!
I discovered a test suite with a few ROMs that assisted me in completing the development and addressing a few issues. I only encountered a challenge when working with the input, as it was not functioning properly. It turns out I was incrementing the program counter in different places, thereby causing unexpected behavior.
Once again, I find myself reiterating that it has been quite an experience. I relish the opportunity to work on projects outside my comfort zone, and I believe this project is markedly distinct from my day-to-day work, providing a valuable learning experience.
While it may not be the best code I have ever written in my life, I am satisfied with the result. Onward to the next one!

