CHIP-8

Last updated
Screenshot of Pong implemented in CHIP-8 PONG CHIP8.png
Screenshot of Pong implemented in CHIP-8
Telmac 1800 running CHIP-8 game Space Intercept (Joseph Weisbecker, 1978) Space intercept.png
Telmac 1800 running CHIP-8 game Space Intercept (Joseph Weisbecker, 1978)

CHIP-8 is an interpreted programming language, developed by Joseph Weisbecker on his 1802 microprocessor. It was initially used on the COSMAC VIP and Telmac 1800, which were 8-bit microcomputers made in the mid-1970s.

Contents

CHIP-8 was designed to be easy to program for, as well as using less memory than other programming languages like BASIC. [1]

Interpreters have been made for many devices, such as home computers, microcomputers, graphing calculators, mobile phones, and video game consoles. [2] [3]

Community

CHIP-8 has been used on a wide range of devices over time, the first community to use CHIP-8 started in the 1970s on microcomputers. They shared extensions and programs in newsletters such as ARESCO's VIPER for COSMAC VIP users or DREAMER for DREAM 6800 users [4] . In the VIPER newsletter, the first three issues detailed the machine code for the CHIP-8 interpreter for the VIP. [5]

In the 1990s, CHIP-8 interpreters started to be created for graphing calculators. Notable examples include CHIP-48 and SCHIP for the HP-48. [6]

CHIP-8 applications include original games, demos, as well as recreations of popular games from other systems. [7] With some CHIP-8 applications being in the public domain, using licenses like the Creative commons Zero license. [8] [9]

CHIP-8 extensions and variations

During the 1970s and 1980s, CHIP-8 users shared CHIP-8 programs, but also changes and extensions to the CHIP-8 interpreter, like in the VIPER magazine for COSMAC VIP. These extensions included CHIP-10 and Hi-Res CHIP-8, which introduced a higher resolution than the standard 64x32, and CHIP-8C and CHIP-8X, which extended the monochrome display capabilities to support limited color, among other features. [10] These extensions were mostly backwards compatible, as they were based on the original interpreter, although some repurposed rarely used opcodes for new instructions. [11]

In 1979, Electronics Australia ran a series of articles on building a kit computer similar to the COSMAC VIP, based on the Motorola 6800 architecture. [12] This computer, the DREAM 6800, came with its own version of CHIP-8. A newsletter similar to VIPER, called DREAMER [13] , was used to share CHIP-8 games for this interpreter. In 1981, Electronics Today International (ETI) ran a series of articles on building a computer, the ETI-660, which was also very similar to the VIP (and used the same microprocessor). ETI ran regular ETI-660 and general CHIP-8 columns [14] until 1985.

In 1990, a CHIP-8 interpreter called CHIP-48 was made by Andreas Gustafsson [15] for HP-48 graphing calculators. Erik Bryntse later created another interpreter based on CHIP-48, [16] titled "SUPER-CHIP",  often shortened to SCHIP or S-CHIP. SCHIP extended the CHIP-8 language with a larger resolution and several additional opcodes meant to make programming easier. [17]

David Winter's interpreter, disassembler, and extended technical documentation popularized CHIP-8/SCHIP on other platforms. It laid out a complete list of undocumented opcodes and features [18] and was distributed across hobbyist forums. Many interpreters used these works as a starting point.[ citation needed ]

However, CHIP-48 subtly changed the semantics of a few of the opcodes, and SCHIP continued to use those new semantics in addition to changing other opcodes. Many online resources about CHIP-8 propagate these new semantics, so many modern CHIP-8 games are not backwards compatible with the original CHIP-8 interpreter for the COSMAC VIP, even if they do not specifically use the new SCHIP extensions. [19]

Some extensions take opcodes or behavior from multiple extensions, like XO-CHIP which takes some from behavior from SCHIP and CHIP-8E. [20]

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 the 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 to avoid the lower 512 bytes of memory (0x000-0x1FF), and it is common to store font data there.

Registers

CHIP-8 has 16 8-bit data registers named V0 to VF. The VF register doubles as a flag for some instructions; thus, it should be avoided. In an addition operation, VF is the carry flag, while in subtraction, it is the "no borrow" flag. In the draw instruction VF is set upon pixel collision.

The address register, which is named I, is 12 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 RCA 1802 version allocated 48 bytes for up to 12 levels of nesting; [21] modern implementations usually have more. [22] [23]

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 ranging 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

Original CHIP-8 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 are XOR'd with corresponding screen pixels. In other words, 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. This is used for collision detection.

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:

There have been many implementations of the CHIP-8 instruction set since 1978. The following specification is based on the SUPER-CHIP specification from 1991 (but without the additional opcodes that provide extended functionality), as that is the most commonly encountered extension set today. Footnotes denote incompatibilities with the original CHIP-8 instruction set from 1978.

OpcodeTypeC PseudoExplanation
0NNNCallCalls machine code routine (RCA 1802 for COSMAC VIP) at address NNN. Not necessary for most ROMs. [24]
00E0Displaydisp_clear()Clears the screen. [24]
00EEFlowreturn;Returns from a subroutine. [24]
1NNNFlowgotoNNN;Jumps to address NNN. [24]
2NNNFlow*(0xNNN)()Calls subroutine at NNN. [24]
3XNNCondif(Vx==NN)Skips the next instruction if VX equals NN (usually the next instruction is a jump to skip a code block). [24]
4XNNCondif(Vx!=NN)Skips the next instruction if VX does not equal NN (usually the next instruction is a jump to skip a code block). [24]
5XY0Condif(Vx==Vy)Skips the next instruction if VX equals VY (usually the next instruction is a jump to skip a code block). [24]
6XNNConstVx=NNSets VX to NN. [24]
7XNNConstVx+=NNAdds NN to VX (carry flag is not changed). [24]
8XY0AssigVx=VySets VX to the value of VY. [24]
8XY1BitOpVx|=VySets VX to VX or VY. (bitwise OR operation). [24]
8XY2BitOpVx&=VySets VX to VX and VY. (bitwise AND operation). [24]
8XY3 [lower-alpha 1] BitOpVx^=VySets VX to VX xor VY. [24]
8XY4MathVx+=VyAdds VY to VX. VF is set to 1 when there's an overflow, and to 0 when there is not. [24]
8XY5MathVx-=VyVY is subtracted from VX. VF is set to 0 when there's an underflow, and 1 when there is not. (i.e. VF set to 1 if VX >= VY and 0 if not). [24]
8XY6 [lower-alpha 1] BitOpVx>>=1Shifts VX to the right by 1, then stores the least significant bit of VX prior to the shift into VF. [lower-alpha 2] [24]
8XY7 [lower-alpha 1] MathVx=Vy-VxSets VX to VY minus VX. VF is set to 0 when there's an underflow, and 1 when there is not. (i.e. VF set to 1 if VY >= VX). [24]
8XYE [lower-alpha 1] BitOpVx<<=1Shifts VX to the left by 1, then sets VF to 1 if the most significant bit of VX prior to that shift was set, or to 0 if it was unset. [lower-alpha 2] [24]
9XY0Condif(Vx!=Vy)Skips the next instruction if VX does not equal VY. (Usually the next instruction is a jump to skip a code block). [24]
ANNNMEMI=NNNSets I to the address NNN. [24]
BNNNFlowPC=V0+NNNJumps to the address NNN plus V0. [24]
CXNNRandVx=rand()&NNSets VX to the result of a bitwise and operation on a random number (Typically: 0 to 255) and NN. [24]
DXYNDisplaydraw(Vx,Vy,N)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 starting from memory location I; I value does not 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 does not happen. [24]
EX9EKeyOpif(key()==Vx)Skips the next instruction if the key stored in VX is pressed (usually the next instruction is a jump to skip a code block). [24]
EXA1KeyOpif(key()!=Vx)Skips the next instruction if the key stored in VX is not pressed (usually the next instruction is a jump to skip a code block). [24]
FX07TimerVx=get_delay()Sets VX to the value of the delay timer. [24]
FX0AKeyOpVx=get_key()A key press is awaited, and then stored in VX (blocking operation, all instruction halted until next key event). [24]
FX15Timerdelay_timer(Vx)Sets the delay timer to VX. [24]
FX18Soundsound_timer(Vx)Sets the sound timer to VX. [24]
FX1EMEMI+=VxAdds VX to I. VF is not affected. [lower-alpha 3] [24]
FX29MEMI=sprite_addr[Vx]Sets I to the location of the sprite for the character in VX. Characters 0-F (in hexadecimal) are represented by a 4x5 font. [24]
FX33BCD
set_BCD(Vx)*(I+0)=BCD(3);*(I+1)=BCD(2);*(I+2)=BCD(1);
Stores the binary-coded decimal representation of VX, with the hundreds digit in memory at location in I, the tens digit at location I+1, and the ones digit at location I+2. [24]
FX55MEMreg_dump(Vx,&I)Stores from V0 to VX (including VX) in memory, starting at address I. The offset from I is increased by 1 for each value written, but I itself is left unmodified. [lower-alpha 4] [24]
FX65MEMreg_load(Vx,&I)Fills from V0 to VX (including VX) with values from memory, starting at address I. The offset from I is increased by 1 for each value read, but I itself is left unmodified. [lower-alpha 4] [24]

Notes

  1. 1 2 3 4 The logical opcodes 8XY3, 8XY6, 8XY7 and 8XYE were not documented in the original CHIP-8 specification, as all the 8000 opcodes were dispatched to instructions in the 1802's ALU, and not located in the interpreter itself; these four additional opcodes were therefore presumably unintentional functionality.
  2. 1 2 CHIP-8's opcodes 8XY6 and 8XYE (the bit shift instructions), which were in fact undocumented opcodes in the original interpreter, shifted the value in the register VY and stored the result in VX. The CHIP-48 and SCHIP implementations instead ignored VY, and simply shifted VX. [19]
  3. Most CHIP-8 interpreters' FX1E instructions do not affect VF, with one exception: the CHIP-8 interpreter for the Commodore Amiga sets VF to 1 when there is a range overflow (I+VX>0xFFF), and to 0 when there is not. [25] The only known game that depends on this behavior is Spacefight 2091!, while at least one game, Animal Race, depends on VF not being affected.
  4. 1 2 In the original CHIP-8 implementation, and also in CHIP-48, I is left incremented after this instruction had been executed. In SCHIP, I is left unmodified.

Further reading

See also

Related Research Articles

<span class="mw-page-title-main">Amiga Original Chip Set</span> Chipset used in Amiga personal computer

The Original Chip Set (OCS) is a chipset used in the earliest Commodore Amiga computers and defined the Amiga's graphics and sound capabilities. It was succeeded by the slightly improved Enhanced Chip Set (ECS) and the greatly improved Advanced Graphics Architecture (AGA).

<span class="mw-page-title-main">MCS-51</span> Single chip microcontroller series by Intel

The Intel MCS-51 is a single chip microcontroller (MCU) series developed by Intel in 1980 for use in embedded systems. The architect of the Intel MCS-51 instruction set was John H. Wharton. Intel's original versions were popular in the 1980s and early 1990s, and enhanced binary compatible derivatives remain popular today. It is a complex instruction set computer, but also has some of the features of RISC architectures, such as a large register set and register windows, and has separate memory spaces for program instructions and data.

<span class="mw-page-title-main">Intel 8085</span> 8-bit microprocessor by Intel

The Intel 8085 ("eighty-eighty-five") is an 8-bit microprocessor produced by Intel and introduced in March 1976. It is the last 8-bit microprocessor developed by Intel.

x86 assembly language is the name for the family of assembly languages which provide some level of backward compatibility with CPUs back to the Intel 8008 microprocessor, which was launched in April 1972. It is used to produce object code for the x86 class of processors.

Fetching the instruction opcodes from program memory well in advance is known as prefetching and it is served by using a prefetch input queue (PIQ). The pre-fetched instructions are stored in a queue. The fetching of opcodes well in advance, prior to their need for execution, increases the overall efficiency of the processor boosting its speed. The processor no longer has to wait for the memory access operations for the subsequent instruction opcode to complete. This architecture was prominently used in the Intel 8086 microprocessor.

<span class="mw-page-title-main">ELF II</span> 1978 microcomputer trainer kit by RCA

The Netronics ELF II was an early microcomputer trainer kit featuring the RCA 1802 microprocessor, 256 bytes of RAM, DMA-based bitmap graphics, hexadecimal keypad, two digit hexadecimal LED display, a single "Q" LED, and 5 expansion slots. The system was developed and sold by Netronics Research and Development Limited in New Milford, CT, USA.

<span class="mw-page-title-main">RCA 1802</span> Early microprocessor

The COSMAC is an 8-bit microprocessor family introduced by RCA. It is historically notable as the first CMOS microprocessor. The first production model was the two-chip CDP1801R and CDP1801U, which were later combined into the single-chip CDP1802. The 1802 represented the majority of COSMAC production, and today the entire line is known simply as the RCA 1802.

<span class="mw-page-title-main">COSMAC VIP</span> 1977 microcomputer

The COSMAC VIP (1977) was an early microcomputer that was aimed at video games. Essentially, it was a COSMAC ELF with a supplementary CDP1861/CDP1864 video display chip. 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 × 28 cm, and it had an RCA 1802 processor; along with a crystal clock operating at 1.76 MHz. It had 2 KB of RAM, which could be expanded to 4 KB on board, and 32 KB via an expansion slot. Its 5V DC CDP18S023 power supply had an output of 600 mA. I/O ports could be added to connect to sensors, interface relays, an ASCII keyboard, or a printer.

<span class="mw-page-title-main">COSMAC ELF</span>

The COSMAC Elf was an RCA 1802 microprocessor-based computer described in a series of construction articles in Popular Electronics magazine in 1976 and 1977. Through the back pages of electronics magazines, both Netronics and Quest Electronics offered low-priced, enhanced kits that were based on this design. The system was a very early single-board personal computer. It was operated without built-in ROMs and programs were entered directly with help of the CPU integrated DMA using 8 toggle switches and an Input push button.

<span class="mw-page-title-main">Blackfin</span> Family of 16-/32-bit microprocessors

The Blackfin is a family of 16-/32-bit microprocessors developed, manufactured and marketed by Analog Devices. The processors have built-in, fixed-point digital signal processor (DSP) functionality performed by 16-bit multiply–accumulates (MACs), accompanied on-chip by a microcontroller. It was designed for a unified low-power processor architecture that can run operating systems while simultaneously handling complex numeric tasks such as real-time H.264 video encoding.

TLCS is a prefix applied to microcontrollers made by Toshiba. The product line includes multiple families of CISC and RISC architectures. Individual components generally have a part number beginning with "TMP". E.g. the TMP8048AP is a member of the TLCS-48 family.

The VEX prefix and VEX coding scheme are an extension to the IA-32 and x86-64 instruction set architecture for microprocessors from Intel, AMD and others.

Each time Intel launched a new microprocessor, they simultaneously provided a system development kit (SDK) allowing engineers, university students, and others to familiarise themselves with the new processor's concepts and features. The SDK single-board computers allowed the user to enter object code from a keyboard or upload it through a communication port, and then test run the code. The SDK boards provided a system monitor ROM to operate the keyboard and other interfaces. Kits varied in their specific features but generally offered optional memory and interface configurations, a serial terminal link, audio cassette storage, and EPROM program memory. Intel's Intellec development system could download code to the SDK boards.

RL78 Family is a 16-bit CPU core for embedded microcontrollers of Renesas Electronics introduced in 2010.

The PIC instruction set refers to the set of instructions that Microchip Technology PIC or dsPIC microcontroller supports. The instructions are usually programmed into the Flash memory of the processor, and automatically executed by the microcontroller on startup.

<span class="mw-page-title-main">STM8</span>

The STM8 is an 8-bit microcontroller family by STMicroelectronics. The STM8 microcontrollers use an extended variant of the ST7 microcontroller architecture. STM8 microcontrollers are particularly low cost for a full-featured 8-bit microcontroller.

Joseph A. Weisbecker was an early microprocessor and microcomputer designer and researcher, as well and designer of toys and games. He was a recipient of the David Sarnoff award for outstanding technical achievement, recipient of IEEE Computer magazine's "Best Paper" award, as well as several RCA lab awards for his work.

<span class="mw-page-title-main">Electronic Arrays 9002</span> 1976 microprocessor

The Electronic Arrays 9002, or EA9002, was an 8-bit microprocessor released in 1976. It was designed to be easy to implement in systems with few required support chips. It included 64 bytes of built-in RAM and could be directly connected to TTL devices. It was packaged in a 28-pin DIP which made it less expensive to implement than contemporary designs like the 40-pin MOS 6502 and Zilog Z80. Today it would be known as a microcontroller, although that term did not exist at the time.

<span class="mw-page-title-main">Gigatron TTL</span>

The Gigatron TTL is a retro-style 8-bit computer, where the CPU is implemented by a set of TTL chips instead of a single microprocessor, imitating the hardware present in early arcades. Its target is the computing enthusiasts, for studying or hobby purposes.

References

  1. "An Easy Programming System". BYTE . Vol. 3, no. 12. December 1978. p. 108.
  2. "The CHIP-8 Emulator HomePage".
  3. "Nintendo Game & Watch hacking scene brings Pokémon, CHIP-8 and more to the $50 handheld". 8 December 2020.
  4. https://archive.org/details/dreamer_newsletter_01/mode/2up
  5. "VIPER for RCA VIP owner". Intelligent Machines Journal (InfoWorld). InfoWorld Media Group. 1978-12-11. p. 9. Retrieved 2010-01-30.
  6. "[What I Learned About] Python and Emulators [by] Making a Chip-8 Emulator". 15 December 2019.
  7. "The CHIP-8 Emulator HomePage".
  8. "Chip-8 Public Domain ROMs - Zophar's Domain".
  9. CHIP-8 Archive
  10. CHIP‐8 Extensions Reference by Matthew Mikolay
  11. https://github.com/trapexit/chip-8_documentation
  12. https://archive.org/stream/EA1979/EA%201979-05%20May#page/n85/mode/2up
  13. https://archive.org/details/dreamer_newsletter_01/mode/2up
  14. https://archive.org/stream/ETIA1981/ETI%201981-11%20November#page/n113/mode/2up
  15. "CHIP-48 source code". GitHub .
  16. SCHIP 1.1 documentation
  17. HP48-Superchip Repository on GitHub
  18. CHIP8.pdf by David WINTER (HPMANIAC)
  19. 1 2 Mastering SuperChip Compatibility section
  20. "XO-CHIP Specification by John Earnest". GitHub .
  21. RCA COSMAC VIP CDP18S711 Instruction Manual. Somerville: RCA Solid State Division. 1978. p. 36.
  22. Greene, Thomas P. (1997-08-30). "Cowgod's Chip-8 Technical Reference". devernay.free.fr. Archived from the original on 2024-01-03. Retrieved 2020-02-03.
  23. Mikolay, Matthew. "Mastering CHIP-8 : Subroutines". mattmik.com. Retrieved 2020-02-03.
  24. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 Schümann, Steffen "Gulrak". "CHIP-8 Variant Opcode Table". chip8.gulrak.net.
  25. "FX1E and VF · Issue #2 · Chromatophore/HP48-Superchip · GitHub". GitHub .