Skip to content

ashab-k/chip8-emulator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CHIP-8 Emulator

A CHIP-8 emulator implementation in C++ using SDL2 for graphics and input handling.

Overview

This project implements a CHIP-8 virtual machine emulator. CHIP-8 is an interpreted programming language that was originally used on 8-bit microcomputers in the 1970s. The emulator recreates the CHIP-8 virtual machine, allowing you to run classic CHIP-8 programs and games.

Building

Prerequisites

  • C++ compiler (GCC, Clang, or MSVC)
  • SDL2 development libraries
  • Make (usually pre-installed on Unix systems)

Installing SDL2

macOS:

brew install sdl2

Linux (Ubuntu/Debian):

sudo apt-get install libsdl2-dev

Linux (Fedora):

sudo dnf install SDL2-devel

Windows: Download SDL2 development libraries from libsdl.org

Building with Makefile

The project includes a Makefile that automatically detects your system and SDL2 installation. Simply run:

make

This will:

  • Detect your operating system
  • Automatically find SDL2 using pkg-config or platform-specific paths
  • Compile all source files
  • Link everything into the chip8_sdl2 executable

Manual Compilation

If you prefer to compile manually or the Makefile doesn't work on your system:

Using g++/clang++ directly:

g++ -std=c++11 main.cpp src/Chip8.cpp -o chip8_sdl2 $(pkg-config --cflags --libs sdl2)

Using clang++:

clang++ -std=c++11 main.cpp src/Chip8.cpp -o chip8_sdl2 $(pkg-config --cflags --libs sdl2)

On macOS with Homebrew SDL2:

clang++ -std=c++11 main.cpp src/Chip8.cpp -o chip8_sdl2 -I/opt/homebrew/include -L/opt/homebrew/lib -lSDL2

On Windows (MinGW):

g++ -std=c++11 main.cpp src/Chip8.cpp -o chip8_sdl2.exe -I<SDL2_PATH>/include -L<SDL2_PATH>/lib -lSDL2main -lSDL2

Running

The emulator requires three command-line parameters:

./chip8_sdl2 <Scale> <Delay> <ROM>

Parameters

  1. Scale (integer)

    • Window size multiplier
    • Original CHIP-8 resolution is 64x32 pixels
    • Example: Scale = 10 creates a 640x320 pixel window
    • Recommended values: 8-20 depending on your screen size
    • Higher values = larger window, easier to see
  2. Delay (integer, milliseconds)

    • Cycle delay between instruction executions
    • Controls emulation speed/timing
    • Lower values = faster emulation
    • Recommended values: 1-5 for normal speed, 10-20 for slower/debugging
    • Example: Delay = 2 waits 2ms between cycles
  3. ROM (file path)

    • Path to the CHIP-8 ROM file (.ch8)
    • ROM files are loaded into memory starting at address 0x200
    • Example: test_opcode.ch8 or tetris.ch8

Example Usage

Run test_opcode.ch8:

Using Makefile (easiest):

make test

Or manually:

./chip8_sdl2 10 2 test_opcode.ch8

This runs the test ROM with:

  • Window scale of 10x (640x320 pixels)
  • 2ms delay between cycles
  • ROM file: test_opcode.ch8

About

emulator for the chip-8 VM

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages