Skip to content

jaxsonp/CHIP-8

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

29 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CHIP-8 Interpreter

A basic CHIP-8 interpreter written in rust. Mostly shooting for compatibility with the original COSMAC VIP interpreter.

Written using help from Tobias Langhoff's Guide to making a CHIP-8 emulator and the Wikipedia CHIP-8 article.

keyboard layout diagram

Usage

$ chip8 [OPTIONS] <ROM>

Arguments

  • <ROM>: path of binary file (ROM) to execute

Options

  • --ips <IPS>: Set the target instructions per second (default: 700)
  • -d, --debug: Print debug information
  • -h, --help: Print help
  • -V, --version: Print version

Keyboard Input

The COSMAC VIP has a keyboard with the following layout:

1 2 3 C
4 5 6 D
7 8 9 E
A 0 B F

Typically games will use 4, 6, 2, and 8 as left, right, up, and down respectively (although some may refer to the keys mapped on a modern keyboard). Because I am targeting the COSMAC VIP, I emulated the physical layout of the buttons, hence I went with the layout shown in the diagram below:

keyboard layout diagram

Assembler

For ease of writing test programs, I slapped together an extremely basic assembler that takes a file of whitespace separated, hex encoded CHIP-8 code and writes it into a .ch8 binary file, ready to be loaded. The assembler will also ignore all lines starting with a '#', allowing for commented code.

Usage

$ assembler.py [-h] [-o output] input

Output will default to out.ch8 if no file is specified

Example source

The following is an example program that gets input from the keypad, draws the key to the screen, then beeps.

# get key press
F00A

# draw key
00E0
F029
6101 6201

# beep
631E F318

Included ROMS

There are some example roms in the /examples/ directory to test and play around with.

About

A basic CHIP-8 intepreter written in rust.

Resources

License

Stars

Watchers

Forks

Packages

No packages published