Skip to content
My version(s) of a Chip-8 emulator, which I kep rewriting in different languages
Lua Rust C++ JavaScript HTML CSS Other
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.vscode
cpp
games
lua
rust
.gitignore
LICENSE.md
README.md

README.md

Chip-8

Chip-8 programs written in Lua using Löve, C++ using SDL2, and in Rust using SDL2 or WebAssembly

https://github.com/aquova/chip8

Included are the same(ish) emulator written in different languages, as well as an assembler and disassembler in Lua.

This is not meant to an efficient, or really even a used emulator. I have always been curious about emulator development, and figured I needed to start somewhere.

The games included in games are not of my own creation, they are from several different sources and included here for ease of use.

Why all these languages?

I first simply wanted to learn how an emulator worked, as since I had been using Lua recently, I decided to use it to develop the emulator. At some point, I became interested in Rust and decided to rewrite the project as a learning tool to learn the language. In preparation to learn WebAssembly, I rewrote it again in C++, only to discover I liked the Rust WebAssembly tools better, and ended up adding a second build target in Rust.

Usage

  • Lua Emulator: With Löve installed, the emulator can be run via love . path/to/game, given you are in the lua directory.

  • C++ Emulator: In the cpp directory, run make and then ./chip8 path/to/game.

  • Rust Emulator:

    • SDL2: If cargo is installed, the emulator can be run via cargo run path/to/game from within the parent directory.
    • WASM: The wasm-pack build tool must be installed first. Then the WASM version can be run via the build-wasm.sh script, then loading the webpage in web in a webserver.
  • Disassembler: The disassembler can be run via lua disassem.lua /path/to/game.c8, where the output will be saved to game.asm.

  • Assembler: The assembler can be used to convert Chip-8 assembly code into a binary. Simply run lua assem.lua /path/to/game.asm, and the output will be saved to game.c8

Limitations

  • Currently neither the assembler nor the disassembler supports labels.

  • As far as I can tell, there is no 'official' Chip-8 assembly syntax. I've used one that's very similar to other references, and it works consistently with my assembler and disassembler. However, externally generated assembly files might have slight syntax differences and might not work with my assembler.

  • The emulator is quite buggy, I'm pretty sure the math on some opcode is wrong somewhere.

  • The WebAssembly build also doesn't handle random number generation correctly, so many games will have the same random element chosen every time

Resources

You can’t perform that action at this time.