Chip-8 Technical Reference v1.0

0.0 - Table of Contents

0.1 - Using This Document

While creating this document, I took every effort to try to make it easy to read, as well as easy to find what you're looking for.

In most cases, where a hexadecimal value is given, it is followed by the equivalent decimal value in parenthesis. For example, "0x200 (512)".

In most cases, when a word or letter is italicized, it is referring to a variable value, for example, if I write "Vx", the x refers to a 4-bit value.

The most important thing to remember as you read this document is that every [TOC] link will take you back to the Table Of Contents. Also, links that you have not yet visited will appear in blue, while links you have used will be gray.

1.0 - About Chip-8

Whenever I mention to someone that I'm writing a Chip-8 interpreter, the response is always the same: "What's a Chip-8?"

Chip-8 is a simple, interpreted, programming language which was first used on some do-it-yourself computer systems in the late 1970s and early 1980s. The COSMAC VIP, DREAM 6800, and ETI 660 computers are a few examples. These computers typically were designed to use a television as a display, had between 1 and 4K of RAM, and used a 16-key hexadecimal keypad for input. The interpreter took up only 512 bytes of memory, and programs, which were entered into the computer in hexadecimal, were even smaller.

In the early 1990s, the Chip-8 language was revived by a man named Andreas Gustafsson. He created a Chip-8 interpreter for the HP48 graphing calculator, called Chip-48. The HP48 was lacking a way to easily make fast games at the time, and Chip-8 was the answer. Chip-48 later begat Super Chip-48, a modification of Chip-48 which allowed higher resolution graphics, as well as other graphical enhancements.

Chip-48 inspired a whole new crop of Chip-8 interpreters for various platforms, including MS-DOS, Windows 3.1, Amiga, HP48, MSX, Adam, and ColecoVision. I became involved with Chip-8 after stumbling upon Paul Robson's interpreter on the World Wide Web. Shortly after that, I began writing my own Chip-8 interpreter.

This document is a compilation of all the different sources of information I used while programming my interpreter.

2.0 - Chip-8 Specifications

This section describes the Chip-8 memory, registers, display, keyboard, and timers.

2.1 - Memory

The Chip-8 language is capable of accessing up to 4KB (4,096 bytes) of RAM, from location 0x000 (0) to 0xFFF (4095). The first 512 bytes, from 0x000 to 0x1FF, are where the original interpreter was located, and should not be used by programs.

Most Chip-8 programs start at location 0x200 (512), but some begin at 0x600 (1536). Programs beginning at 0x600 are intended for the ETI 660 computer.

Memory Map:

+---------------+= 0xFFF (4095) End of Chip-8 RAM
|               |
|               |
|               |
|               |
|               |
| 0x200 to 0xFFF|
|     Chip-8    |
| Program / Data|
|     Space     |
|               |
|               |
|               |
+- - - - - - - -+= 0x600 (1536) Start of ETI 660 Chip-8 programs
|               |
|               |
|               |
+---------------+= 0x200 (512) Start of most Chip-8 programs
| 0x000 to 0x1FF|
| Reserved for  |
|  interpreter  |
+---------------+= 0x000 (0) Start of Chip-8 RAM
            

2.2 - Registers

Chip-8 has 16 general purpose 8-bit registers, usually referred to as Vx, where x is a hexadecimal digit (0 through F). There is also a 16-bit register called I. This register is generally used to store memory addresses, so only the lowest (rightmost) 12 bits are usually used.

The VF register should not be used by any program, as it is used as a flag by some instructions. See section 3.0, Instructions for details.

Chip-8 also has two special purpose 8-bit registers, for the delay and sound timers. When these registers are non-zero, they are automatically decremented at a rate of 60Hz. See the section 2.5, Timers & Sound, for more information on these.

There are also some "pseudo-registers" which are not accessible from Chip-8 programs. The program counter (PC) should be 16-bit, and is used to store the currently executing address. The stack pointer (SP) can be 8-bit, it is used to point to the topmost level of the stack.

The stack is an array of 16 16-bit values, used to store the address that the interpreter should return to when finished with a subroutine. Chip-8 allows for up to 16 levels of nested subroutines.

2.3 - Keyboard

Chip-8 has a hexadecimal keypad which consists of 16 keys. The keys are mapped to hexadecimal digits 0 through F. The key states are polled by the Chip-8 interpreter.

Keypad Layout:

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

2.4 - Display

Chip-8 has a display with a resolution of 64x32 pixels. The display is a grid of 64 columns by 32 rows. Each pixel is represented by a single bit. The display is updated by the Chip-8 interpreter during each cycle, drawing or erasing pixels according to the current instructions.

Display Grid:

2.5 - Timers & Sound

The Chip-8 has two timers, the delay timer and the sound timer. These timers are decremented at a rate of 60Hz. When a timer reaches zero, it stops decrementing. The delay timer controls the speed of certain operations, while the sound timer is used to create sound effects.

The delay timer and sound timer are both 8-bit registers.

3.0 - Chip-8 Instructions

This section describes the Chip-8 instructions in detail. Instructions are represented as 16-bit opcodes.

3.1 - Instruction Format

Each Chip-8 instruction is a 16-bit opcode. The opcode is divided into nibbles (4-bit sections) and represented in hexadecimal format.

3.2 - Instruction Set

The Chip-8 instruction set includes: