Share your repls and programming experiences

← Back to all posts
CHIP-8 Emulator in Python
joningram (1)

Uses Python/Tkinter to emulate the 1970s CHIP-8 virtual machine.

For more information on CHIP-8, see
https://en.wikipedia.org/wiki/CHIP-8

There are a number of great sites that describe the process of implementing a CHIP-8 emulator. Here are some that I read while writing this emulator:

The CHIP-8 system uses a hex keypad for entry, and a 64x32 monochrome screen for output. There is also facility for producing a beep as sound output, although this hasn't been implemented.

In this emulator the hex keypad which originally had the layout
123C
456D
789E
A0BF
is simulated by using the keys
1234
QWER
ASDF
ZXCV
(this is fairly standard in CHIP-8 emulators).

There are several other shortcut keys:

  • The + and - keys speed up and slow down the emulation. By default the CPU speed is 10 cycles per 60Hz tick (for a whole 600 instructions per second!)
  • The P key pauses/unpauses the emulation.
  • Escape resets the currently loaded program
  • Backspace performs a 'soft' reset (clear registers but not memory)

CHIP-8 was implemented on several hobbyist computer systems in the 1970s, including the COSMAC VIP, and interest was revived in the 1990s when an emulator/extension called S-CHIP was produced for the HP48 range of graphical calculators, which introduced several extra features and higher-res graphics. These have not been implemented.

There are several quirks/differences between the implementations of some of the CHIP-8 opcodes between different interpreters and language levels. It appears that the S-CHIP quirks are the ones
expected by most modern programs, so these are the ones which are followed in general.

Several programs are built-in to the emulator and can be loaded directly from the menu.

  • Blitz is a 'bomber' game. Use 'W' to drop bombs. Clear the screen before you hit the buildings.
  • Opcode Test is not particularly exciting, but tests that all the CHIP-8 machine code instructions are being emulated correctly.
  • Pong is pong! Player 1 uses 1Q to move up and down. Player 2 uses 4R to do the same.
  • Tetris is Tetris! WE moves left/right. Q rotates. A drops.
  • UFO is a shooting gallery game. Use QWE to fire left/ahead/right. You score if you hit one of the moving objects.
  • Worm is a snake game. 2QSE move up/left/down/right. Sometimes a 'fruit' will fail to appear - I haven't been able to figure out if that's a bug in my emulation or the game.

There are many more CHIP-8 programs which you can download and use with this emulator on your own machine. If your interest is in running the programs, rather than emulating, though, I can strongly recommand the OCTO emulator and development environment:
https://internet-janitor.itch.io/octo
This emulates CHIP-8, and all the derivatives, includes XO-CHIP, which has 4 colours!