50% OFF EVERYTHING | get full lifetime access now
Ends in: ...
Understanding The Chip-8
Low Level Programming

Understanding The Chip-8

CHIP-8 is a hexadecimal interpreted language created by J. Weisbecker in  1978. It was intended to be a kind of high-level machine  language which made it possible to create software, especially video-games, without programming in real machine code. Every one of it's pseudo-machine instructions is expected to be linked to the necessary machine-specific code by the interpreter.

CHIP-8 programs are run on a CHIP-8 virtual machine. It was initially used on the COSMAC VIP and Telmac 1800 8-bit microcomputers, and supports many programs such as Pac-Man, Pong, Space Invaders, and Tetris. It was made to allow video games to be more easily programmed for these computers.

The Chip-8 specification requires the use of sixteen 8-bit registers (V0-VF), a 16-bit index register, a 64-byte stack with 8-bit stack pointer, an 8-bit delay timer, an 8-bit sound timer, a 64x32 bit frame buffer, and a 16-bit program counter. The Chip8 specification also supported 4096 bytes of addressable memory. 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. All of the supported programs will start at memory location 0x200.

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.
 
Important to the specification is the 64x32 pixel display that is associated with the Chip8. Each pixel only contains the information as to whether it is on or off. All setting of pixels of this display are done through the use of sprites that are always 8 × N where N is the pixel height of the sprite. Chip8 comes with a font set (sprites) that allows character 0-9 and A-F to be printed directly to the screen. Each one of these characters fit within a 8x5 grid.

Chip-8 provides 2 timers, a delay timer and a sound timer. The delay timer is active whenever the delay timer register (DT) is non-zero. This timer does nothing more than subtract 1 from the value of DT at a rate of 60Hz. When DT reaches 0, it deactivates. The sound timer is active whenever the sound timer register (ST) is non-zero. This timer also decrements at a rate of 60Hz, however, as long as ST’s value is greater than zero, the Chip-8 buzzer will sound. When ST reaches zero, the sound timer deactivates. The output of the sound generator has one tone. In the following implementation it will have a soft tone so as to not aggravate the user.

The Chip8 interpreter works by parsing 16 bit opcodes and operating on the data. All supported op codes in the original Chip8 specification are included.
To learn more about Chip-8, visit https://dragonzap.com/course/creating-an-emulator-in-c

 

 

  • Share

Previous Post

What are registers in the x86 processor

Comments

Leave a comment