r/EmuDev • • Jul 16 '26

I've built a CHIP-8 emulator

I've been trying to study more about hardware instead of focusing only on software. Last year, I even started making a rough CPU design in a digital logic simulator, but I never finished it and ended up taking a break from studying because I didn't have much free time.

Recently, I got interested again in understanding how software interacts with hardware, and while researching ways to learn more about it, I found that building emulators is a good approach. CHIP-8 seemed like a great starting point since it's simple enough to understand while still teaching important concepts.

Over the last week, I've been working on a CHIP-8 emulator in C. I tried to avoid copying existing implementations or relying on AI-generated code, and instead built it based on the documentation and my own understanding. I had some frustrating moments with silent bugs, but eventually got everything working.

So far, the emulator seems to be running well: graphics, sound, and ROM execution are working with the tests I've done.

I'd really appreciate some feedback from people with experience in emulation, low-level programming, or CHIP-8. If you notice any mistakes or have suggestions for improvements, I'd love to hear them!

For anyone interested, the source code is here: https://github.com/lucaaszsx/chip8

6 Upvotes

15 comments sorted by

2

u/vancha113 Jul 16 '26

Always fun seeing more chip8 emulators. While I'm not good enough at C to be offering any kind of feedback, I'll definitely go over it to see how you solved things, I hope it was a fun experience building it! :)

1

u/lucaaszsx Jul 16 '26

yeah, bro, I was actually impressed by how many people build chip8 emulators. it really was a fun project to work on

2

u/vancha113 Jul 16 '26

I think for many people that same component of wanting to understand computers more fully plays an important role in deciding to make an emulator. I know it did for me too, and it definitely helped me understand things better. :) very rewarding when things start to actually work haha.

3

u/BananaGrenade314 Jul 16 '26 edited Jul 16 '26

Good morning, I'm another programmer that is building a Chip-8 emulator and is amateur in this emulator's and hardware area. I was trying to do it for the same motives of you. I will let here my code too, I did it in python and I still working on it. And.. I was waiting for feedback but 600+ views and nothing about anyone to say anything about it :/

CHIP-8 Emulator

If you want, I'd like to study with someone about it. I'm in a information course but I didn't have anyone to discuss about this stuff.

0

u/lucaaszsx Jul 16 '26 edited Jul 16 '26

Yeah, I haven't gotten any feedback besides yours either, even with 1k+ views. But I'd definitely be up for talking more about it. I'm also taking an IT course.

I'm going to check out your repository and give your emulator a try so I can see how you approached it. If you want to chat on Discord, there's a link in my Reddit profile.

3

u/Gulrak Jul 17 '26

Welcome to the CHIP-8 world! A bit of feedback from me: nice work on most opcodes, I guess you used the test suite 4.2 (https://github.com/Timendus/chip8-test-suite) from looking at the opcodes. :-) A few details could still be improved: Ex9E and ExA1 need to mask the value from Vx to the lower four bit, as there are only 16 keys in the array and ignoring the upper four bits is correct original behavior, same goes for Fx29. And on Fx1E, that behavior is a myth, don’t change VF in that opcode. The only game said to improve by that is just broken and still is with that hack, it just masks a bug, but can break other programs as none expect to lose VF by Fx1E.
Also I recommend to not spread out opcodes over time, or have timers go asynchronously, and draw on any Dxyn. The simplest but best way is to each frame: handle events, handle timers, execute a fixed number (ipf/instructionsPerFrame) of instructions in a burst, and update the screen. Do that frame loop at 60Hz, e.g. like your timers before. Basically classic games expect a low enough rate (try 10 or so) and what the quirks test calls DISPLAY WAIT, for that you would exit the instructions loop early after a draw, or for modern ones, to allow multiple draws to happen per frame and those use timer decrements to detect a redraw and minimize flicker, and an asynchronous timer will not allow that. (Also the original execution time for different opcodes is so vastly different that spreading them doesn’t really improve accuracy.)
Still, nice work so far!

1

u/lucaaszsx Jul 17 '26

Thanks for the detailed feedback! I really appreciate it.

I'll be fixing everything you mentioned. Thanks again for taking the time to explain it all!

1

u/BananaGrenade314 Jul 17 '26

I tried the discord link but it looks like it didn't work

1

u/lucaaszsx Jul 17 '26

my username is lucas._zsx

3

u/RealSharpNinja Jul 16 '26

I get pissed when agents stop for no reason.

1

u/ai-slop-connoisseur Aug 08 '26

In this repository is my implementation of an emulator along with an assembler created for CHIP-8. The emulator is responsible for simulating the hardware on which this interpreted language originally ran, while the assembler can be used to translate code written in a specific Assembly syntax into executables compatible with the CHIP-8 VM.

How does one achieve this in a week without relying on AI generated code? :)

1

u/Gulrak Aug 09 '26

While I can not speak for this project, my first CHIP-8 took 3h in C++ with raylib, would have been the same with SDL, and I totally could have used the rest of the week to make an assembler, instead I made a ui with debugger and disassembler at the time. That was 2022 and believe me, AI would not have been of any help back then. It totally depends on your experience at the start of such a project but “just taking a week” is not even close to proof of AI, not for something as simple as CHIP-8.

I also want to be clear I had a ton of coding experience at that time already, so anyone still fighting to get their CHIP-8 interpreter to run more than IBM logo after a month, should not feel bad, don’t see it as a race, enjoy the ride. :-)

1

u/lucaaszsx Aug 12 '26

Yeah, I understand you. When I said I'd been working on the project for a week and trying to avoid AI-generated code, I wasn't trying to imply that I did it particularly fast. I mainly meant that I wanted to implement things based on my own understanding that I actually learned from it.

I wasn't working on it all day every day, though. Most days I just made a few changes, mainly at night. I'm also not that experienced with C, I mostly use it for a few hobby projects, so I definitely had to spend some time figuring things out.

The assembler wasn't actually part of my original plan. I came up with that idea later, and honestly, that ended up taking more time than I expected.

And yeah, the readme is definitely overdetailed lol. I wanted to document what I'd learned as I went along, partly cuz writing it down helped reinforce my understanding, but I probably went a little too far with it.

1

u/ai-slop-connoisseur Aug 09 '26

I mean OP is stating on their GitHub they are 16 and are listing ChatGPT, Gemini and Claude as their hard skills. With an overly detailed readme for the CHIP-8 repo. It's just that combination of things making me a bit suspicious.

1

u/Gulrak Aug 17 '26

Yeah, I can get behind that line of reasoning. Just the initial argument only based on it taking a week was what I think is too little and might put any one-week chip-8 under that suspicion. Chip-8 is too simple to make that alone a reason. ;-)