o
odinpkg.dev
packages / library / CHIP8EmulatorOdin

CHIP8EmulatorOdin

35462c3library

CHIP-8 emulator in Odin programming language

MIT · updated 7 months ago

CHIP-8 emulator in Odin

Overwiew

Implemented with the guide from Tobias V. Langhoff.

This guide also contains some ambiguous instructions so I additionally looked at Cowgod's Chip-8 Technical Reference v1.0 (e.g. shift instructions like 8XY6 and 8XYE or jump with offset BNNN).

Specification

  • 4Kb of RAM
  • 64 * 32 pixels display ("pixel" actually 16*16 pixels)
  • program counter (PC), which points at the current insruction in memory
  • one 16-bit index register (I) which is used to point at locations in memory
  • stack of 16-bit addresses
  • 8-bit delay timer which is decremented at a rate of 60 Hz
  • 8-bit sound timer which functions like the delay timer, but which also gives off a beeping sound as long as it’s not 0
  • 16 8-bit registers, numbered 0 through F, and called V0 through VF
    • VF - flag register
  • instructions are executed at 700Hz (700 instructions/second)
Original keypad Keyboard keypad
1 2 3 C 1 2 3 4
4 5 6 D Q W E R
7 8 9 E A S D F
A 0 B F Z X C V

Keypad button is considered pressed when it released. In this implementation emulator doesn't support multiple buttons pressed at the same time. In this case it will consider pressed only first button from KeypadButtons bit_set.

Running examples

Examples directory contains some CHIP-8 ROM-s which can be executed with this emulator.

To build emulator and then run example use this commands:

odin build src -o:speed -out:chip8emu
./chip8emu examples/Chip8-Picture.ch8

Or you can run it without build:

odin run src -o:speed -- examples/Chip8-Picture.ch8