0

CHIP-8 Emulator (C++)

A minimal, from-scratch CHIP-8 emulator in C++ with full opcode fidelity

CHIP-8 Emulator (C++)

Overview

CHIP-8 is an interpreted programming language developed in the 1970s for simple 8-bit systems. This project implements a minimal, from-scratch CHIP-8 emulator in C++, with an emphasis on correctness, clarity, and opcode-level fidelity. The emulator recreates the complete CHIP-8 execution environment and supports classic ROMs such as Pong and Tetris.

The implementation avoids external emulator frameworks and focuses on a clean, deterministic fetch–decode–execute pipeline.

Features

  • 4 KB memory model
  • 16 general-purpose 8-bit registers (V0–VF)
  • Index register (I) and Program Counter (PC)
  • Stack and stack pointer
  • Delay and sound timers
  • 64 × 32 monochrome display
  • 16-key hexadecimal keypad
  • Complete CHIP-8 instruction set implementation
  • Accurate opcode fetch–decode–execute cycle
  • ROM loading starting at memory address 0x200
  • Built-in fontset loading at standard locations
  • Deterministic execution loop
  • Modular opcode handler design
  • Support for test ROM–based validation

Project Structure

.
├── chip8              # Compiled executable
├── chip8.cpp          # Emulator source code
├── LICENSE            # License file
├── README.md          # Project documentation
└── ROM                # CHIP-8 ROMs
    ├── Pong.ch8
    ├── test_opcode.ch8
    └── tetris.ch8

Installation

Requirements

  • macOS or Linux
  • clang++ or g++
  • SDL2 (required only if graphics or audio output is enabled)

Clone the Repository

git clone https://github.com/adityaamehra/chip8-emulation.git
cd chip8-emulation

Compilation

Without SDL2:

clang++ chip8.cpp -o chip8

With SDL2:

clang++ chip8.cpp -o chip8 \
  -I/opt/homebrew/include \
  -L/opt/homebrew/lib \
  -lSDL2

Usage

Run the emulator by passing a CHIP-8 ROM as a command-line argument:

./chip8 ROM/Pong.ch8

Additional examples:

./chip8 ROM/tetris.ch8
./chip8 ROM/test_opcode.ch8

Included ROMs

  • Pong.ch8 — Classic Pong implementation
  • tetris.ch8 — Fully playable Tetris
  • test_opcode.ch8 — Opcode verification ROM

License

This project is licensed under the MIT License.