RHDL includes a browser-based simulator that compiles the IR simulation backends to WebAssembly and renders live VCD waveforms using p5.js visualization.

Overview

The web simulator lets you run RHDL designs directly in the browser — no installation required. It supports multiple execution backends, preconfigured runner presets, and interactive debugging tools.

Features

  • Multiple backends — interpreter, JIT, and compiler execution modes
  • Live waveforms — VCD signal visualization rendered with p5.js
  • Preconfigured presets — ready-made runners for Generic, CPU, MOS 6502, Apple II, and Game Boy architectures
  • Debugging tools — value breakpoints and memory inspection
  • Interactive schematic — component visualization using ELK.js layout and WebGL 2.0

Architecture

The build process has two stages:

  1. Ruby-side artifact generation — produces WASM binaries and metadata from RHDL IR
  2. Bun bundling — packages JavaScript, LitElement components, and runtime assets into web/dist/

The application uses:

  • LitElement components for the UI
  • Redux for state management
  • ELK.js for schematic layout
  • WebGL 2.0 for interactive rendering
  • SharedArrayBuffer for multi-threaded WASM execution

User Interface

The workspace is organized into tabbed panels:

PanelPurpose
I/OSet inputs, read outputs, control simulation
VCDSignal analysis with waveform viewer
MemoryBrowse and inspect memory contents
ComponentsComponent tree with drill-down
SchematicInteractive circuit visualization

Running the Simulator

Prerequisites

  • Rust toolchain with wasm-pack
  • Bun (JavaScript bundler)

Build

# Build WASM artifacts
rake web:build
 
# Bundle and serve
cd web && bun run dev

CORS Requirements

The simulator requires specific HTTP headers for SharedArrayBuffer:

Cross-Origin-Opener-Policy: same-origin
Cross-Origin-Embedder-Policy: require-corp

These are automatically configured for local development. For deployment, the build includes a service worker fallback.

Presets

The simulator ships with preconfigured presets for demonstration:

PresetDescriptionComponents
GenericBasic component testingAny single component
CPU8-bit CPU datapathALU, registers, PC, decoder
MOS 6502Full 6502 processorCPU, memory, I/O
Apple IIApple II system6502, video, keyboard, memory
Game BoyGame Boy systemSM83 CPU, PPU, APU, memory

Deployment

GitHub Actions workflows automate deployment to GitHub Pages:

# Build for production
rake web:dist
 
# Deploy (via CI)
gh workflow run deploy-web

Next Steps