Rust WebAssembly

Emu16Bit — 16-Bit WebAssembly Emulator

How my journey learning Rust—continuing my exploration of memory layouts and machine instructions—led down a rabbit hole into 16-bit CPU opcodes, virtual processor dispatch, and a browser-based 16-bit emulator.

By Robert Long | November 3, 2026
Stack Rust WebAssembly WebGL 2.0 HTML5 Canvas
Technologies 16-Bit Emulation Virtual Processor Opcodes & ASM Memory Layout
Emu16Bit 16-Bit Emulator WebAssembly interface

A Journey into Rust, Memory Layouts & Machine Instructions

Emu16Bit didn't start with a plan to build a game emulator. It grew out of my journey learning Rust—wanting to understand not just the language's syntax, but how it models ownership and physical bytes in memory. Coming directly off the bare-metal memory layout and x86-64 disassembly work in my HPC Recursive DFS Series, I was already fascinated by how data layout and low-level machine instructions dictate everything that happens at runtime.

Poking at Rust structs, slice borrowing, and byte alignment naturally pulled me deeper down the rabbit hole—from contiguous memory layouts into hardware address buses, and from assembly output straight into 16-bit instruction sets and CPU opcodes. At some point, building a dedicated 16-bit emulator felt like the most rewarding way to tie all of those ideas together around one concrete goal: running classic 16-bit console hardware right inside the browser.

The 16-Bit Machine, Opcodes & Instruction Dispatching

At the heart of the machine is a 16-bit WDC 65C816 processor where registers aren't even fixed width—processor status flags dynamically flip the accumulator and index registers between 8-bit and 16-bit modes mid-stream. Every instruction step runs through a tight fetch-decode-execute cycle: reading the next opcode byte off the 24-bit banked bus, indexing into a dispatch table, resolving addressing modes across bank boundaries, and updating processor flags deterministically.

To keep that loop clean and predictable, the machine's working RAM, video memory, and bank-mapped bus live inside flat, contiguous Rust arrays rather than scattered heap allocations. Just like the bit-packed memory structures in the HPC Recursive DFS Series, keeping the entire state layout flat eliminates pointer chasing and lets Rust's borrow rules enforce clean boundaries between CPU execution, DMA transfers, and frame rendering.

Emulators as System Virtual Machines & Virtual Processors

Working on Emu16Bit drove home how closely hardware emulators mirror system virtual machines and bytecode interpreters. Under the hood, an emulator is a virtual processor—an instruction-set abstract machine that maintains a guest register file, translates virtual or banked addresses across a memory bus, and steps through binary opcodes one state transition at a time. The mental model is almost identical to how managed language runtimes and virtual machines interpret or lower portable bytecode onto host silicon.

WebAssembly Sandboxing & Binary Opacity

Compiling the Rust core straight to WebAssembly (WASM) pairs one virtual machine inside another: the 16-bit virtual processor executes entirely inside the browser's memory-safe WASM sandbox while streaming rendered frames to an HTML5 canvas over WebGL 2.0. Because the browser receives a compiled, stripped WebAssembly binary module rather than readable source scripts, execution stays sandboxed and secure—while keeping the underlying runtime logic compact and naturally difficult to reverse engineer. In-game battery saves (.srm) persist locally in browser localStorage so party progress carries seamlessly across sessions.