You are browsing as a guest. Sign up (or log in) to start making projects!

Chip8 Emulator

  • 2 Devlogs
  • 22 Total hours

An emulator/interpreter of the Chip8 programming language using C++ and SDL3

Ship #1 Pending review

I made an emulator of the Chip8 interpreter, which was originally made for micro computers like the COSMAC VIP to introduce people to programming. Now, it’s introduced me to emulator development, and is a stepping stone to me creating my own Gameboy emulator (that’ll be next!). It also let me learn more about C++ in larger projects, as I hitherto mainly used it for competitive programming (not much oop in that!)

I’m most proud of how the Dear ImGui interface turned out, and learning to use the library was surprisingly easy and little code creates great looks. I understand why it’s so popular now!

The project has a pre-built binary for MacOS and installation instructions, as well as instructions on building from source for other operating systems (although it is untested, your mileage may vary).

  • 2 devlogs
  • 22h
Try project → See source code →
Open comments for this post

8h 49m 49s logged

Emulator Complete!

I am proud to write that I have finished my emulator and it is now fully public on GitHub and has a downloadable binary for MacOS.

Since the last devlog I have:

  • Fixed various bugs with opcodes not working correctly
  • Added memory out of bonds read/write protection using a genius snippet of code with the help of someone from the EmuDev discord!
  • Fixed all quirks and made it so that they can be toggled
  • Added a setting menu that can be toggled with backtick that uses Dear ImGui and allows you to change quirks, ipf, and the colours!

Out of all of this, the biggest challenge (although it was minor, it was very annoying) was figuring out a way to map the colour picker in Dear ImGui to the actual colours drawn in SDL3. The frame buffer expected a 32 bit integer representing the RGBA hex code of the colour, while ImGui wanted a float array with each colour being from 0.0-1.0. I tried to use methods like ImGui::ColorConvertFloat4ToU32, but it ended up all using types native to ImGui that SDL does not support, so I ended up using a standard float array and then writing a simple function to multiply the values by 255 and shift the bits to turn it in to the value SDL expects. Here’s the code: (I know I could’ve only had the bit shifting logic once but why have DRY code when it can be wet 🤣)

int Config::getColor(bool fg){
    if(fg){
        return static_cast<int>(fgColor[0] * 255) << 24 | static_cast<int>(fgColor[1] * 255) << 16 | static_cast<int>(fgColor[2] * 255) << 8 | 0xFF;
    }

    return static_cast<int>(bgColor[0] * 255) << 24 | static_cast<int>(bgColor[1] * 255) << 16 | static_cast<int>(bgColor[2] * 255) << 8 | 0xFF;
}

Attached is a picture of the emulator running a ROM that is essentially a backport of the chrome dino game. This was a really fun project and a perfect stepping stone to eventually making a Gameboy emulator!!

0
0
2
Open comments for this post

12h 46m 23s logged

I’ve implemented all of the Chip8 opcodes in C++ and the emulator/interpreter is able to execute them all correctly. I used various test files/ROMs to verify this and debug it along the way. I chose SDL3 to render the project because of the easy support for an array of ints that represent pixel values/colors. It also uses SDL3 for playing sound (using the sound timer) and getting input using the hexadecimal keyboard. I’m now going to work on adding configurable settings (such as background and foreground color) using Dear IMGUI and then porting the project to the web with Emscripten

0
0
29

Delete project?

Are you sure you want to permanently delete this project? This action cannot be undone.

All devlogs, followers, and associated data will be removed.

Followers

Loading…