Inside CHIP-8

Certain old computers — most frequently those using the RCA 1802 — were fond of using an early form of byte-code interpreter for programs, especially games. The interpreter, CHIP-8, was very simple to create but offered high-level features that were tedious to recreate in the native assembly language. Because there are a fair number of simple games written in CHIP-8, there are of course, emulators for it, and [River Gillis] decided to look inside the CHIP-8 byte code interpreter.

Part of the power of CHIP-8 was it only had 35 virtual instructions. That was important when you were trying to shoehorn a game and the interpreter into a very small memory. Remember, in those days 1K of memory wasn’t an unusual number, although the prototypical CHIP-8 host would have 4K.

The virtual machine has 16 8-bit data registers and a stack. Since the idea was to create games, there are features useful for that purpose. For example, drawing to the screen (by default a 64×32 pixel screen) using sprites, you get information about any collisions on the screen automatically.  The instructions offered some virtualization of the display and input device — usually, a hex keypad — and also provides the ability to convert binary numbers to binary coded decimal.

So the interpreter isn’t difficult to create by design. However, [River] has to emulate a target machine, and that’s where part two will pick up. However, if you are interested in retrocomputing, retrogaming, or you just want a better understanding of how a byte-coded interpreter works, this is a fun read with lots of code examples.

Making a custom virtual computer is actually not a bad idea when you are trying to conserve memory space and make development easier. Java uses the same idea on steroids, although mostly for different reasons. P-Code was another similar system and Forth, at its core, is the same basic concept.

It would be fun to put CHIP-8 on a small computer today to make a super retro gaming console. Or scarf up an old 1802 CPU — they are still available. You can also make your own.

Photo credit: RCA Cosmac VIP by [Dave Ruske] CC BY 2.0

4 thoughts on “Inside CHIP-8

  1. The interpreter was featured in an article in Byte, I forget the year. The designer (and I think author) was Joseph Weisbecker, who created the 1802 among other things.There was something about the article that made me wonder if he’d created CHIP-8 and then the 1802. Byte, Dec 1978.

    The Sweet-16 interpreter in the Apple II struck me as being in a similar vein. Steve Wozniak had an article about that in Byte for Nov 1977

    1. Yes, it was in Byte of December 1978, in the article “An Easy Programming System, available in the Internet Archive: https://archive.org/details/byte-magazine-1978-12/page/n109/mode/2up

      Weisbecker did create CHIP-8 especially for the COSMAC VIP and 1802, but he had created other similar languages for his earlier 1802 prototype computers. I actually think one of the main reasons he put multiple program counters in the 1802 was to facilitate interpreters like that.

      His System 00 and FRED (Flexible Recreational and Educational Device) TTL computers from the early 70s, which eventually became the RCA CDP1801 (similar to the 1802, but on two separate chips), ran CHIP-8 precursors called FPL (Fred Programming Language) and FEL (Fred Experimental Language).

      RCA’s Video Coin Arcade machine and their VIP-like video game console, the RCA Studio II, also ran interpreters for similar languages, which their games were written in.

      There’s an extensive list of all his interpreted languages in the section “Pseudo Code” on the website of the great COSMAC emulator Emma02: https://www.emma02.hobby-site.com

  2. Even the BBC micro had one, in order to shoehorn a C compiler into 32K of memory (less in reality once screen and filing system removed). The C implementation was pretty primitive and ran pretty slow, but then it was being interpreted on a 2 meg 6502.

Leave a Reply

Please be kind and respectful to help make the comments section excellent. (Comment Policy)

This site uses Akismet to reduce spam. Learn how your comment data is processed.