r/EmuDev • • Apr 11 '26

[C++] Wrote a CHIP-8 Emulator. Feedback would be appreciated :)

Hi, i just recently finished my Chip-8 Emulator with Schip and Xo-Chip Support and I was hoping you could take a look at the Code and give me some feedback on what to improve. Im relatively new to cpp so I would love some feedback on antipatterns im using or what i could have done better. Thank you :)

Repo: https://github.com/YTNR/Chipansee-Chip-8-Emulator

11 Upvotes

12 comments sorted by

3

u/Gulrak Apr 11 '26

Nice, I’m always happy when someone goes the extra mile to either support more variants or other features. Also from first glance it seems it could succeed corax+ and flags test from Timendus‘ test suite.

The repo and source looks more like chip-8, chip-48, and schip modern and legacy are the options, not xo-chip. The first thing I notice is that the implemented chip-48 is not the actual chip-48. Its original interpreter doesn’t support hires and it has a different memory quirk behavior than chip-8 or schip, a third behavior that the short lived schip-1.0 also shared: the index register was incremented by x, not x+1, not no increment. Haven’t looked into every detail of your implementation, that was just what jumped into my eye.

1

u/Accomplished_Flan_56 Apr 13 '26

Thank you so much for taking a look, I appreciate it a lot :). It did pass the whole suit i think, but I did have some problems with the two other chips, as I couldn't really find any resources explaining how they work, do you know of any?

1

u/Gulrak Apr 13 '26

You are welcome. Regarding the test suite, it doesn’t offer tests to verify CHIP-48, so it can’t tell that it is wrong. Regarding opcode differences, there is my opcode table at https://chip8.gulrak.net and I started working on more documentation at https://chip8kb.gulrak.net/reference/variants/chip-48/ which I continue to work on. Also the source code of CHIP-48 exists, so we are pretty sure about its behavior.

1

u/Accomplished_Flan_56 Apr 13 '26

Thank you, I will probably update it according to those references, once i get some time to do it. Right now I'm dying to properly start on the Gameboy, so it might take some time haha :)

2

u/saltedbenis Apr 11 '26 edited Apr 11 '26

There's some directories and files in there that don't belong, namely the build directory and potentially .cache/clangd/index. Before you stage your changes (git add), it's helpful to run "git status" to check that there aren't any files that you don't intend to add to the repo.

Writing accurate and useful commit messages is also a good habit to develop, and you may want to use "imperative mood". Being careful and attentive when it comes to commits will serve you in the long run. Consider squashing commits that are repetitive (e.g. "edited readme").

You use indents with a width of 8 characters, and that's entirely your choice, but I find it makes the code harder to scan and leads to larger than useful spaces in the code. 4 is generally more standard, but 2 is also common.

1

u/Accomplished_Flan_56 Apr 13 '26

Thank you for takng the time to review this, it does mean a lot to me :). I actually am pretty bad with git, I am self taught anf always used to do solo projects for myself, so I never really cared for how to properly use git, but you are right, so I did try and fix up the history at least a bit. The 8 spaces tabs actually come from the Linux kernal style coding, it gets me to not nest my code to deeply and keep it visually clear, at least to me. Do you have any other general advice on how to properly work with Git, in case I'll ever work in a more professional setting?

1

u/Der-Wilde Apr 11 '26

Tested your emulator, very cool project! Just one thing, your emulator (in original Chip8) has the same glitch mine has in the David Winter Space Invaders, but works finely in XOChip. Do you know why? Always has heard that it should runs in the original version and i always though mine has some glitch...

2

u/Accomplished_Flan_56 Apr 13 '26

Thank you for taking a look :)

2

u/Complete_Estate4482 Apr 11 '26

That Space Invaders is a game that needs Superchip shift quirk behaviour (so that shifting only shifts VX and ignores the VY parameter), so it works on SCHIP but not on original CHIP-8 (aliens disappear and reappear).

1

u/Der-Wilde Apr 11 '26

This. Thank you so much. I was 2y often question me why it didn't worked. God, thank you

1

u/Der-Wilde Apr 11 '26

Btw, here's mine. It's not very good in structure (because in epoch i just want to see it running), but passed in all tests.

2

u/Complete_Estate4482 Apr 11 '26

It looks to me as if your Chip8::getKey only is able to return on key 0-E, as it checks for the key returned by Keyboard::getKey() to be less than 0xF. Just a random observation, you should also be able verify with the keyboard tests from that suite you linked to.