Skip to content

pedroafonso18/Rustic_Chip8

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

rustic_chip

rustic_chip is a CHIP-8 emulator written in Rust. It uses SDL2 for video/input and Rodio for audio, and it supports loading and running CHIP-8 ROMs from the command line.

Screenshot

CHIP-8 emulator screenshot

Features

  • CHIP-8 CPU core with opcode decoding and execution
  • 64x32 monochrome framebuffer
  • SDL2 window rendering
  • Keyboard input mapped to the CHIP-8 keypad
  • Basic beep sound support through Rodio
  • Fontset loaded into memory at startup

Requirements

Rust

  • Rust toolchain with Cargo

Native dependencies

SDL2 needs the native development libraries installed on your system.

On Debian or Ubuntu:

sudo apt update
sudo apt install libsdl2-dev

On Fedora:

sudo dnf install SDL2-devel

On Arch Linux:

sudo pacman -S sdl2

Build

cargo build

For a faster optimized binary:

cargo build --release

Run

The emulator expects a CHIP-8 ROM path as the first argument.

cargo run -- "/path/to/your/rom.ch8"

If you already built the binary:

./target/debug/rustic_chip "/path/to/your/rom.ch8"

If the ROM path contains spaces or brackets, keep it quoted.

ROM source

This repository does not include ROM files. You can get CHIP-8 ROMs from:

https://github.com/kripod/chip8-roms/tree/master

Controls

The keypad uses a standard CHIP-8 layout:

CHIP-8 keypad        Keyboard mapping

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

Additional keys:

  • Escape exits the emulator

Project Structure

src/
  main.rs
  display/
    display.rs
    mod.rs
  internals/
    audio.rs
    chip8.rs
    constants.rs
    mod.rs
    opcodes.rs

src/internals/chip8.rs

This contains the main emulator state:

  • memory
  • registers
  • index register
  • program counter
  • video buffer
  • stack
  • timers
  • keypad state

It also handles:

  • loading ROMs
  • advancing CPU cycles
  • mapping SDL keyboard input into the CHIP-8 keypad

src/internals/opcodes.rs

This file contains:

  • opcode enum definitions
  • opcode decoding
  • opcode execution logic

src/display/display.rs

This file handles:

  • creating the SDL2 window
  • uploading the CHIP-8 framebuffer to a streaming texture
  • presenting frames on screen

Emulator Loop

The current loop in src/main.rs does the following:

  1. Reads the ROM path from the command line
  2. Creates a Chip8 instance
  3. Loads the ROM into memory
  4. Creates the SDL2 display
  5. Polls SDL events
  6. Executes multiple CPU cycles per frame
  7. Presents the framebuffer
  8. Sleeps briefly to keep the loop close to 60 Hz

About

A simple Chip8 emulator made in Rust!

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages