5 min read

GAME BOY EMULATOR WASM

Table of Contents

GB-EMU (WebAssembly Edition) ๐ŸŽฎ

A Game Boy (DMG) emulator written from scratch in C++17, specifically compiled for the Web using Emscripten (WebAssembly - WASM).

โš ๏ธ WORK IN PROGRESS: This project is under active development. It is incomplete and intended for educational and testing purposes only.


๐Ÿ“‚ Project Structure

GB-EMU/
โ”œโ”€โ”€ core/               # Emulator logic (CPU, MMU, Cartridge, Mappers)
โ”œโ”€โ”€ emc_main.cpp        # Main entry point for the Web version
โ”œโ”€โ”€ CMakeLists.txt      # Build configuration
โ”œโ”€โ”€ build.sh            # Automated build helper script
โ””โ”€โ”€ roms/               # (Not included) User-provided ROM files

๐Ÿ“Œ Note: This repository does NOT include ROM files. You must provide your own.


โš™๏ธ Configuration (CRITICAL STEP)

Because this project runs inside a browser sandbox, ROMs must be manually injected into Emscriptenโ€™s virtual file system at build time.


๐Ÿงฑ Step 1: Prepare your ROM

  1. Create a folder named roms in the project root (if it doesnโ€™t exist).
  2. Place your Game Boy ROM file inside it.

Example:

roms/
โ””โ”€โ”€ your_game.gb

๐Ÿ—บ๏ธ Step 2: Modify CMakeLists.txt (Virtual Path Mapping)

You must tell Emscripten:

  • Where the ROMs are located on your real machine
  • Where they should appear inside the browser

Open CMakeLists.txt and locate the target_link_options section. Modify the preload line:

"SHELL:--preload-file /YOUR/REAL/PATH/TO/roms@/roms"

Explanation:

  • Left side (before @) โ†’ Absolute path on your computer Example:

    /home/user/GB-EMU/roms
  • Right side (after @) โ†’ Virtual path inside the browser ๐Ÿ‘‰ Keep this as /roms


๐ŸŽฎ Step 3: Modify emc_main.cpp (ROM Loading)

Update the ROM path so it matches the filename inside the virtual file system:

// Change "your_game.gb" to the actual ROM filename
std::string romPath = "roms/your_game.gb";

๐Ÿš€ Build Instructions

๐Ÿ”ง Requirements

  • Emscripten SDK (emsdk) installed and activated in your terminal.

The project includes a helper script that:

  • Cleans previous builds
  • Configures CMake with Emscripten
  • Compiles the project
  • Optionally launches a local web server
# 1. Give execution permissions (only once)
chmod +x build.sh

# 2. Run the script
./build.sh

At the end of the process, the script will ask whether you want to start the web server automatically.


๐Ÿ› ๏ธ Option B: Manual Compilation

If you prefer running each step manually:

# 1. Create a clean build directory
rm -rf build_web
mkdir -p build_web && cd build_web

# 2. Configure with Emscripten
emcmake cmake ..

# 3. Compile
emmake make -j$(nproc)

โ–ถ๏ธ Running the Emulator

โš ๏ธ Do NOT open the generated HTML file directly. You must use a local web server due to WASM/CORS security restrictions.


๐Ÿ”น Via Script

If you used ./build.sh, simply type:

s + Enter

when prompted.


๐Ÿ”น Manual

emrun --no_browser --port 8888 gb-emu.html

Using Python

python3 -m http.server 8888

๐ŸŒ Access

Open your browser at:

http://localhost:8888/gb-emu.html

๐Ÿงฉ Project Status

  • ROM loading via Virtual File System
  • Basic emulator architecture
  • WebAssembly compilation pipeline
  • Complete CPU instruction set โ€” In progress
  • PPU (Graphics & Rendering)
  • Timers & Interrupts
  • Joypad input handling โ€” In progress
  • IMBC โ€” In progress
  • Users can put their own ROMs in the UI.

๐Ÿ“š Project Goals

This project aims to:

  • Learn Game Boy (DMG) architecture
  • Explore low-level emulation concepts
  • Experiment with C++ + WebAssembly
  • Build a full emulator from scratch, without external emulation libraries

Example

https://github.com/user-attachments/assets/88e74923-9da6-4370-b4ec-90aa76692b20

๐Ÿ’ก Issues, pull requests, and feedback are welcome.

This project is an independent, unofficial emulator developed for educational purposes only.

  • This repository does NOT include any copyrighted ROMs, BIOS files, or proprietary assets.
  • Users must provide their own legally obtained Game Boy ROMs.
  • Any ROM filenames shown in examples (e.g. your_game.gb) are placeholders only.
  • This project is not affiliated with, endorsed by, or associated with Nintendo.

All trademarks and registered trademarks are the property of their respective owners.