CHIP-8
Encyclopedia
CHIP-8 is an interpreted
programming language
, developed by the late Joseph Weisbecker. It was initially used on the COSMAC VIP
and Telmac 1800
8-bit
microcomputer
s in the mid-1970s. CHIP-8 programs
are run on a CHIP-8 virtual machine
. It was made to allow video games to be more easily programmed for said computers.
Roughly twenty years after CHIP-8 was introduced, derived interpreters appeared for some models of graphing calculator
s (from the late 1980s onward, these handheld devices in many ways have more computing power than most mid-1970s microcomputers for hobbyists).
An active community of users and developers existed in the late 1970s, beginning with ARESCO's "VIPer" newsletter whose first three issues revealed the machine code behind the CHIP-8 interpreter.
, Space Invaders
, Tetris
, and Pac-Man
. There's also a random maze generator available. These programs are reportedly placed in the public domain
, and can be easily found on the Internet
.
CHIP-8 has a descendant called SCHIP (Super Chip), introduced by Erik Bryntse. In 1990, a CHIP-8 interpreter called CHIP-48 was made for HP-48 graphing calculator
s so that games could be programmed more easily. Its extensions to CHIP-8 are what became known as SCHIP. It features a larger resolution and several additional opcodes which make programming easier. If it were not for the development of the CHIP-48 interpreter, CHIP-8 would not be as well known today.
The next most influential developments (which popularized S/CHIP-8 on many other platforms) were David Winter's emulator, disassembler, and extended technical documentation. It laid out a complete list of undocumented opcodes and features, and was distributed across many hobbyist forums. Many of the emulators listed below had these works as a starting point.
es range from 200h to FFFh, making for 3,584 bytes. The reason for the memory starting at 200h is that on the Cosmac VIP and Telmac 1800, the first 512 bytes are reserved for the interpreter
. On those machines, the uppermost 256 bytes (F00h-FFFh on a 4K machine) were reserved for display refresh, and the 96 bytes below that (EA0h-EFFh) were reserved for the call stack, internal use, and the variables.
data registers
named from V0 to VF. The VF register doubles as a carry flag
.
The address register, which is named I, is 16 bits wide and is used with several opcode
s that involve memory operations.
is only used to store return addresses when subroutine
s are called. The original 1802 version allocated 48 bytes for up to 12 levels of nesting; modern implementations normally have at least 16 levels.
, until they reach 0.
keyboard
that has 16 keys which range from 0 to F. The '8', '4', '6', and '2' keys are typically used for directional input. Three opcodes are used to detect input. One skips an instruction if a specific key is pressed, while another does the same if a specific key is not pressed. The third waits for a key press, and then stores it in one of the data registers.
is 64×32 pixel
s, and color is monochrome
. Graphics are drawn to the screen solely by drawing sprites, which are 8 pixels wide and may be from 1 to 15 pixels in height. Sprite pixels that are set flip the color of the corresponding screen pixel, while unset sprite pixels do nothing. The carry flag (VF) is set to 1 if any screen pixels are flipped from set to unset when a sprite is drawn and set to 0 otherwise.
As previously described, a beeping sound is played when the value of the sound timer is nonzero.
s, which are all two bytes long. The most significant byte is stored first. The opcodes are listed below, in hexadecimal and with the following symbols:
Interpreter (computing)
In computer science, an interpreter normally means a computer program that executes, i.e. performs, instructions written in a programming language...
programming language
Programming language
A programming language is an artificial language designed to communicate instructions to a machine, particularly a computer. Programming languages can be used to create programs that control the behavior of a machine and/or to express algorithms precisely....
, developed by the late Joseph Weisbecker. It was initially used on the COSMAC VIP
COSMAC VIP
The COSMAC VIP was an early microcomputer that was aimed at video games. For a price of US$275, it could be purchased from RCA by mail order. It came in kit form, and had to be assembled. Its dimensions were 22 x 28 cm, and it had a RCA 1802 processor; along with a crystal clock operating at 1.76...
and Telmac 1800
Telmac 1800
The Telmac 1800 was an early microcomputer delivered in kit form. It was introduced in 1977 by Telercas, the Finnish importer of RCA microchips. Most of the 2,000 kits manufactured were bought by electronics enthusiasts in Finland and Sweden....
8-bit
8-bit
The first widely adopted 8-bit microprocessor was the Intel 8080, being used in many hobbyist computers of the late 1970s and early 1980s, often running the CP/M operating system. The Zilog Z80 and the Motorola 6800 were also used in similar computers...
microcomputer
Microcomputer
A microcomputer is a computer with a microprocessor as its central processing unit. They are physically small compared to mainframe and minicomputers...
s in the mid-1970s. CHIP-8 programs
Computer program
A computer program is a sequence of instructions written to perform a specified task with a computer. A computer requires programs to function, typically executing the program's instructions in a central processor. The program has an executable form that the computer can use directly to execute...
are run on a CHIP-8 virtual machine
Virtual machine
A virtual machine is a "completely isolated guest operating system installation within a normal host operating system". Modern virtual machines are implemented with either software emulation or hardware virtualization or both together.-VM Definitions:A virtual machine is a software...
. It was made to allow video games to be more easily programmed for said computers.
Roughly twenty years after CHIP-8 was introduced, derived interpreters appeared for some models of graphing calculator
Graphing calculator
A graphing calculator typically refers to a class of handheld calculators that are capable of plotting graphs, solving simultaneous equations, and performing numerous other tasks with variables...
s (from the late 1980s onward, these handheld devices in many ways have more computing power than most mid-1970s microcomputers for hobbyists).
An active community of users and developers existed in the late 1970s, beginning with ARESCO's "VIPer" newsletter whose first three issues revealed the machine code behind the CHIP-8 interpreter.
CHIP-8 applications
There are a number of classic video games ported to CHIP-8, such as PongPong
Pong is one of the earliest arcade video games, and is a tennis sports game featuring simple two-dimensional graphics. While other arcade video games such as Computer Space came before it, Pong was one of the first video games to reach mainstream popularity...
, Space Invaders
Space Invaders
is an arcade video game designed by Tomohiro Nishikado, and released in 1978. It was originally manufactured and sold by Taito in Japan, and was later licensed for production in the United States by the Midway division of Bally. Space Invaders is one of the earliest shooting games and the aim is to...
, Tetris
Tetris
Tetris is a puzzle video game originally designed and programmed by Alexey Pajitnov in the Soviet Union. It was released on June 6, 1984, while he was working for the Dorodnicyn Computing Centre of the Academy of Science of the USSR in Moscow, Russian Soviet Federative Socialist Republic...
, and Pac-Man
Pac-Man
is an arcade game developed by Namco and licensed for distribution in the United States by Midway, first released in Japan on May 22, 1980. Immensely popular from its original release to the present day, Pac-Man is considered one of the classics of the medium, virtually synonymous with video games,...
. There's also a random maze generator available. These programs are reportedly placed in the public domain
Public domain
Works are in the public domain if the intellectual property rights have expired, if the intellectual property rights are forfeited, or if they are not covered by intellectual property rights at all...
, and can be easily found on the Internet
Internet
The Internet is a global system of interconnected computer networks that use the standard Internet protocol suite to serve billions of users worldwide...
.
CHIP-8 today
There is a CHIP-8 implementation for almost every platform imaginable, as well as some development tools. Despite this, there are only a small number of games for the CHIP-8.CHIP-8 has a descendant called SCHIP (Super Chip), introduced by Erik Bryntse. In 1990, a CHIP-8 interpreter called CHIP-48 was made for HP-48 graphing calculator
Graphing calculator
A graphing calculator typically refers to a class of handheld calculators that are capable of plotting graphs, solving simultaneous equations, and performing numerous other tasks with variables...
s so that games could be programmed more easily. Its extensions to CHIP-8 are what became known as SCHIP. It features a larger resolution and several additional opcodes which make programming easier. If it were not for the development of the CHIP-48 interpreter, CHIP-8 would not be as well known today.
The next most influential developments (which popularized S/CHIP-8 on many other platforms) were David Winter's emulator, disassembler, and extended technical documentation. It laid out a complete list of undocumented opcodes and features, and was distributed across many hobbyist forums. Many of the emulators listed below had these works as a starting point.
Memory
CHIP-8's memory addressMemory address
A digital computer's memory, more specifically main memory, consists of many memory locations, each having a memory address, a number, analogous to a street address, at which computer programs store and retrieve, machine code or data. Most application programs do not directly read and write to...
es range from 200h to FFFh, making for 3,584 bytes. The reason for the memory starting at 200h is that on the Cosmac VIP and Telmac 1800, the first 512 bytes are reserved for the interpreter
Interpreter (computing)
In computer science, an interpreter normally means a computer program that executes, i.e. performs, instructions written in a programming language...
. On those machines, the uppermost 256 bytes (F00h-FFFh on a 4K machine) were reserved for display refresh, and the 96 bytes below that (EA0h-EFFh) were reserved for the call stack, internal use, and the variables.
Registers
CHIP-8 has 16 8-bitBit
A bit is the basic unit of information in computing and telecommunications; it is the amount of information stored by a digital device or other physical system that exists in one of two possible distinct states...
data registers
Processor register
In computer architecture, a processor register is a small amount of storage available as part of a CPU or other digital processor. Such registers are addressed by mechanisms other than main memory and can be accessed more quickly...
named from V0 to VF. The VF register doubles as a carry flag
Status register
A status register or flag register is a collection of flag bits for a processor. An example is the FLAGS register of the x86 architecture....
.
The address register, which is named I, is 16 bits wide and is used with several opcode
Opcode
In computer science engineering, an opcode is the portion of a machine language instruction that specifies the operation to be performed. Their specification and format are laid out in the instruction set architecture of the processor in question...
s that involve memory operations.
The stack
The stackCall stack
In computer science, a call stack is a stack data structure that stores information about the active subroutines of a computer program. This kind of stack is also known as an execution stack, control stack, run-time stack, or machine stack, and is often shortened to just "the stack"...
is only used to store return addresses when subroutine
Subroutine
In computer science, a subroutine is a portion of code within a larger program that performs a specific task and is relatively independent of the remaining code....
s are called. The original 1802 version allocated 48 bytes for up to 12 levels of nesting; modern implementations normally have at least 16 levels.
Timers
CHIP-8 has two timers. They both count down at 60 hertzHertz
The hertz is the SI unit of frequency defined as the number of cycles per second of a periodic phenomenon. One of its most common uses is the description of the sine wave, particularly those used in radio and audio applications....
, until they reach 0.
- Delay timer: This timer is intended to be used for timing the events of games. Its value can be set and read.
- Sound timer: This timer is used for sound effects. When its value is nonzero, a beeping sound is made.
Input
Input is done with a hexHexadecimal
In mathematics and computer science, hexadecimal is a positional numeral system with a radix, or base, of 16. It uses sixteen distinct symbols, most often the symbols 0–9 to represent values zero to nine, and A, B, C, D, E, F to represent values ten to fifteen...
keyboard
Computer keyboard
In computing, a keyboard is a typewriter-style keyboard, which uses an arrangement of buttons or keys, to act as mechanical levers or electronic switches...
that has 16 keys which range from 0 to F. The '8', '4', '6', and '2' keys are typically used for directional input. Three opcodes are used to detect input. One skips an instruction if a specific key is pressed, while another does the same if a specific key is not pressed. The third waits for a key press, and then stores it in one of the data registers.
Graphics and sound
Display resolutionDisplay resolution
The display resolution of a digital television or display device is the number of distinct pixels in each dimension that can be displayed. It can be an ambiguous term especially as the displayed resolution is controlled by all different factors in cathode ray tube , flat panel or projection...
is 64×32 pixel
Pixel
In digital imaging, a pixel, or pel, is a single point in a raster image, or the smallest addressable screen element in a display device; it is the smallest unit of picture that can be represented or controlled....
s, and color is monochrome
Monochrome
Monochrome describes paintings, drawings, design, or photographs in one color or shades of one color. A monochromatic object or image has colors in shades of limited colors or hues. Images using only shades of grey are called grayscale or black-and-white...
. Graphics are drawn to the screen solely by drawing sprites, which are 8 pixels wide and may be from 1 to 15 pixels in height. Sprite pixels that are set flip the color of the corresponding screen pixel, while unset sprite pixels do nothing. The carry flag (VF) is set to 1 if any screen pixels are flipped from set to unset when a sprite is drawn and set to 0 otherwise.
As previously described, a beeping sound is played when the value of the sound timer is nonzero.
Opcode table
CHIP-8 has 35 opcodeOpcode
In computer science engineering, an opcode is the portion of a machine language instruction that specifies the operation to be performed. Their specification and format are laid out in the instruction set architecture of the processor in question...
s, which are all two bytes long. The most significant byte is stored first. The opcodes are listed below, in hexadecimal and with the following symbols:
- NNN: address
- NN: 8-bit constant
- N: 4-bit constant
- X and Y: 4-bit register identifier
Opcode | Explanation |
---|---|
0NNN | Calls RCA 1802 RCA 1802 The RCA CDP1802, also known as the COSMAC , is an 8-bit CMOS microprocessor introduced by RCA in early 1976. It is being by Intersil Corporation as a high-reliability microprocessor... program at address NNN. |
00E0 | Clears the screen. |
00EE | Returns from a subroutine. |
1NNN | Jumps to address NNN. |
2NNN | Calls subroutine at NNN. |
3XNN | Skips the next instruction if VX equals NN. |
4XNN | Skips the next instruction if VX doesn't equal NN. |
5XY0 | Skips the next instruction if VX equals VY. |
6XNN | Sets VX to NN. |
7XNN | Adds NN to VX. |
8XY0 | Sets VX to the value of VY. |
8XY1 | Sets VX to VX or Logical disjunction In logic and mathematics, a two-place logical connective or, is a logical disjunction, also known as inclusive disjunction or alternation, that results in true whenever one or more of its operands are true. E.g. in this context, "A or B" is true if A is true, or if B is true, or if both A and B are... VY. |
8XY2 | Sets VX to VX and Logical conjunction In logic and mathematics, a two-place logical operator and, also known as logical conjunction, results in true if both of its operands are true, otherwise the value of false.... VY. |
8XY3 | Sets VX to VX xor VY. |
8XY4 | Adds VY to VX. VF is set to 1 when there's a carry, and to 0 when there isn't. |
8XY5 | VY is subtracted from VX. VF is set to 0 when there's a borrow, and 1 when there isn't. |
8XY6 | Shifts VX right by one. VF is set to the value of the least significant bit Least significant bit In computing, the least significant bit is the bit position in a binary integer giving the units value, that is, determining whether the number is even or odd. The lsb is sometimes referred to as the right-most bit, due to the convention in positional notation of writing less significant digits... of VX before the shift. |
8XY7 | Sets VX to VY minus VX. VF is set to 0 when there's a borrow, and 1 when there isn't. |
8XYE | Shifts VX left by one. VF is set to the value of the most significant bit Most significant bit In computing, the most significant bit is the bit position in a binary number having the greatest value... of VX before the shift. |
9XY0 | Skips the next instruction if VX doesn't equal VY. |
ANNN | Sets I to the address NNN. |
BNNN | Jumps to the address NNN plus V0. |
CXNN | Sets VX to a random number and NN. |
DXYN | Draws a sprite at coordinate (VX, VY) that has a width of 8 pixels and a height of N pixels. Each row of 8 pixels is read as bit-coded (with the most significant bit of each byte displayed on the left) starting from memory location I; I value doesn't change after the execution of this instruction. As described above, VF is set to 1 if any screen pixels are flipped from set to unset when the sprite is drawn, and to 0 if that doesn't happen. |
EX9E | Skips the next instruction if the key stored in VX is pressed. |
EXA1 | Skips the next instruction if the key stored in VX isn't pressed. |
FX07 | Sets VX to the value of the delay timer. |
FX0A | A key press is awaited, and then stored in VX. |
FX15 | Sets the delay timer to VX. |
FX18 | Sets the sound timer to VX. |
FX1E | Adds VX to I. |
FX29 | Sets I to the location of the sprite for the character in VX. Characters 0-F (in hexadecimal) are represented by a 4x5 font. |
FX33 | Stores the Binary-coded decimal Binary-coded decimal In computing and electronic systems, binary-coded decimal is a digital encoding method for numbers using decimal notation, with each decimal digit represented by its own binary sequence. In BCD, a numeral is usually represented by four bits which, in general, represent the decimal range 0 through 9... representation of VX, with the most significant of three digits at the address in I, the middle digit at I plus 1, and the least significant digit at I plus 2. |
FX55 | Stores V0 to VX in memory starting at address I. |
FX65 | Fills V0 to VX with values from memory starting at address I. |
Additional Resources
- "RCA COSMAC VIP CDP18S711 Instruction Manual," RCA Solid State Division, Somerville, NJ 08776, February 1978. Part VIP-311. pp. 13–18, 35-37.
- BYTE magazine, December 1978, pp. 108–122. "An Easy Programming System," by Joseph Weisbecker. Describes CHIP-8 with specific example of a rocketship and UFO shooting-gallery game.
- Chip8.com Website dedicated to Chip-8 and related systems. Maintains the most complete collection of Chip-8 programs on the net.
- David Winter's Chip-8 Emulator, utilities and games.
- Let's Emu : Chip-8 Emulator – A list of CHIP-8 and SCHIP emulators.
- Revival Studios Developer of new Chip-8/SuperChip/MegaChip8 games.
- BytePusher A minimalist virtual machine inspired by the CHIP-8.