CHIP-8

Telmac 1800 running CHIP-8 game Space Intercept (Joseph Weisbecker, 1978)

CHIP-8 is an interpreted programming language, developed by Joseph Weisbecker. It was initially used on the COSMAC VIP and Telmac 1800 8-bit microcomputers 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 calculators (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.[1]

CHIP-8 applications

There are a number of classic video games ported to CHIP-8, such as Pong, 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 today

There is a CHIP-8 implementation for almost every platform, 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 calculators 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.

While CHIP-8 and SCHIP have commonly been implemented as emulators, a pure hardware implementation (written in the Verilog language) also exists for certain FPGA boards.

Virtual machine description

Memory

CHIP-8 was most commonly implemented on 4K systems, such as the Cosmac VIP and the Telmac 1800. These machines had 4096 (0x1000) memory locations, all of which are 8 bits (a byte) which is where the term CHIP-8 originated. However, the CHIP-8 interpreter itself occupies the first 512 bytes of the memory space on these machines. For this reason, most programs written for the original system begin at memory location 512 (0x200) and do not access any of the memory below the location 512 (0x200). The uppermost 256 bytes (0xF00-0xFFF) are reserved for display refresh, and the 96 bytes below that (0xEA0-0xEFF) were reserved for call stack, internal use, and other variables.

In modern CHIP-8 implementations, where the interpreter is running natively outside the 4K memory space, there is no need for any of the lower 512 bytes memory space to be used, but it is common to store font data in those lower 512 bytes (0x000-0x200).

Registers

CHIP-8 has 16 8-bit 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 opcodes that involve memory operations.

The stack

The stack is only used to store return addresses when subroutines 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 hertz, until they reach 0.

Input

Input is done with a hex 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.

Graphics and sound

Display resolution is 64×32 pixels, 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.

Opcode table

CHIP-8 has 35 opcodes, which are all two bytes long and stored Big-endian. The opcodes are listed below, in hexadecimal and with the following symbols:

Opcode Explanation
0NNN Calls RCA 1802 program at address NNN. Not necessary for most ROMs.
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 VY.
8XY2 Sets VX to VX and 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 of VX before the shift.[2]
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 of VX before the shift.[2]
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 the result of a bitwise and operation on a random number and NN.
DXYN Sprites stored in memory at location in index register (I), 8bits wide. Wraps around the screen. If when drawn, clears a pixel, register VF is set to 1 otherwise it is zero. All drawing is XOR drawing (i.e. it toggles the screen pixels). Sprites are drawn starting at position VX, VY. N is the number of 8bit rows that need to be drawn. If N is greater than 1, second line continues at position VX, VY+1, and so on.
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.[3]
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 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. (In other words, take the decimal representation of VX, place the hundreds digit in memory at location in I, the tens digit at location I+1, and the ones digit at location I+2.)
FX55 Stores V0 to VX in memory starting at address I.[4]
FX65 Fills V0 to VX with values from memory starting at address I.[4]

Notes

  1. "VIPER for RCA VIP owner". Intelligent Machines Journal (InfoWorld) (InfoWorld Media Group). 1978-12-11. p. 9. Retrieved 2010-01-30.
  2. 1 2 On the original interpreter, the value of VY is shifted, and the result is stored into VX. On current implementations, Y is ignored.
  3. VF is set to 1 when range overflow (I+VX>0xFFF), and 0 when there isn't. This is undocumented feature of the CHIP-8 and used by Spacefight 2091! game.
  4. 1 2 On the original interpreter, when the operation is done, I=I+X+1. On current implementations, I is left unchanged.

Additional Resources

This article is issued from Wikipedia - version of the Friday, November 27, 2015. The text is available under the Creative Commons Attribution/Share Alike but additional terms may apply for the media files.