Repository navigation
[PCL] Add Chip-8 emulator test program - #131
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Implements a small emulator for the Chip-8, a bytecode VM from the 1970s, originally designed for the Cosmac VIP personal computer, and further popularized by later implementations targetting HP-48 graphing calculators. The code uses this page as a reference for the Chip-8 instruction set.
Thanks to its simplicity, the Chip-8 is one of the most common systems to make an emulator for, with over 14 thousand implementations on Github.
The emulator comes with 3 builtin "games", which are all public domain and can thus be freely distributed. These games are hardcoded into the source code in a fairly awkward way, since the PCL specification does not include file IO or array initializers. In addition, the games all render to the terminal, and do not accept keyboard input (as PCL stdlib can't read from the keyboard in a non-blocking manner).
PCL also has several other intricacies that make it awkward to write an emulator with:
modcalculates a signed remainder, so operations like(a - b) & 0xFFin C can't be done easily, because if (a-b) goes into the negatives, the calculated mod will be negative too (and not an 8-bit integer like we want it to be)There's hundreds of other chip-8 games that could be added, many of which can be found here: https://johnearnest.github.io/chip8Archive/. However, some games might require adjustments to the emulator
Below are screenshots of the 3 games built into the source code. Some "artifacts" (things disappearing in certain frames) aren't bugs, and are actually just a side effect of how rendering works on the chip-8. You can toggle how long the emulator runs for, and how many instructions to actually execute per frame, by changing some constants inside the source code.
Space Invaders:

Pong:

IBM logo:
