Skip to content

thegoddo/chip_8

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

C++ Chip-8 Emulator

demo

A feature-complete Chip-8 interpreter written in C++11, using SDL2 for rendering and input handling. This emulator runs standard Chip-8 ROMs (games/programs).

Features

  • Full Opcode Support: Implements the standard Chip-8 instruction set.
  • Scalable Graphics: Resizable window with configurable scale factor.
  • Configurable Speed: Adjustable CPU cycle delay to control emulation speed.
  • Cross-Platform: Runs on Linux, Windows, and macOS (requires SDL2).
  • Keyboard Input: Maps modern keyboards to the hex keypad.

Prerequisites

To build this project, you need:

  • C++ Compiler (GCC, Clang, or MSVC) supporting C++11.
  • CMake (Version 3.14 or higher).
  • SDL2 Library (Development headers).

Installing Dependencies (Fedora Linux)

sudo dnf install gcc-c++ cmake make SDL2-devel

Installing Dependencies (Ubuntu/Debian)

sudo apt-get install build-essential cmake libsdl2-dev

Build Instructions

  1. Clone or download this repository.

  2. Open a terminal in the project folder.

  3. Run the following commands:

# Create a build directory
mkdir build
cd build

# Generate the Makefile
cmake ..

# Compile the executable
make

Usage

Run the emulator from the command line. You must provide three arguments:

./chip8 <Scale> <Delay> <ROM_Path>
  • Scale: Integer. Multiplies the original 64x32 resolution. (Recommended: 10 to 20).

  • Delay: Integer. Milliseconds to wait between CPU cycles. Lower is faster. (Recommended: 1 to 4).

  • ROM_Path: Path to a valid .ch8 or .rom file.

Example

To play Pong with 15x scale and 3ms delay:

./chip8 15 3 ../roms/PONG

Controls

The original Chip-8 used a 16-key hexadecimal keypad (0-F). This emulator maps them to the left side of your QWERTY keyboard:

Chip-8 Key Keyboard Key Action (Standard Games)
1 1
2 2
3 3
C 4 Player 2 Up (Pong)
4 Q Player 1 Up (Pong)
5 W
6 E
D R Player 2 Down (Pong)
7 A Player 1 Down (Pong)
8 S
9 D
E F
A Z
0 X
B C
F V
  • ESC: Exit the emulator.

Project Structure

  • Source/Chip8.cpp/hpp: Core CPU logic, memory, and opcode implementation.

  • Source/Platform.cpp/hpp: Handles graphics (SDL2) and input events.

  • Source/Main.cpp: Entry point, main loop, and argument parsing.

  • CMakeLists.txt: Build configuration.

Troubleshooting

  • "Segmentation Fault": Usually happens if the ROM path is incorrect. Double-check that the file exists and the path is right relative to where you are running the terminal command.

  • Game is too fast/slow: Adjust the second argument (Delay). Increase the number to slow it down, decrease it to speed it up.

A big thanks to Austin Morlan and his blog

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

 
 
 

Contributors