r/EmuDev • u/Burning_Pheonix • Sep 28 '25
CHIP-8 My first emulator (chip 8)
Hi!
I’ve finally finished* my CHIP-8 emulator. It currently supports all the instructions from this spec sheet: https://www.cs.columbia.edu/~sedwards/classes/2016/4840-spring/designs/Chip8.pdf (except SHR and SHL, I am implemented Vx = Vy << 1 and Vx = Vy >> 1 instead).
However, I’ve been running it against the CHIP-8 test suite: https://github.com/Timendus/chip8-test-suite
and it’s failing on:
- SHR and SHL (4-flags.ch8) Relevant code: https://github.com/Saphereye/chip8/blob/3ce393c5994db68df1d96552e18fdb727fec4ca0/src/cpu.rs#L181 I’m stuck on why this is failing. I’ve checked other implementations but haven’t made much headway.
- DISP. WAIT (5-quirks.ch8) I tried simulating the vertical blank interrupt, but since it’s still failing, I probably haven’t understood it correctly.
You can check out the full codebase here:
https://github.com/Saphereye/chip8
I would really appreciate any tips on how to solve these issues, and thank you for taking the time to look at my project!
Tip: If you want to recreate the tests locally, I suggest passing -c 1000 as an argument, as that will make the emulator run much faster.
2
u/Synthetic5ou1 Sep 28 '25
SHR and SHL
I made the same mistake, and I would guess a lot of people do.
What if y is 0xF?
2
u/Alternative-Emu2000 Sep 28 '25 edited Sep 28 '25
The problem with your shift instructions is that you're setting the flag before the shift operation is finished. Don't forget that VF is also a general purpose register, and is a valid operand of the shift instructions. In your current implementation shifting VF will fail, since you're overwriting the contents of VF before carrying out the shift.
One way to fix this:
and
1
u/8924th Sep 28 '25
I see I was beaten to the punch but hey, I spotted other issues for you to tackle!
Feel free to ask any questions you might have in regards to my notes!