How vedant416/rustynes works
Project Type & Purpose
• RustyNES is a cross‐platform NES emulator written in Rust.
• It provides a “core” emulation engine (RustyNES_core) plus three front-ends/adapters:
• A native CLI using SDL2 (RustyNES_cli)
• A WASM port library (RustyNES_wasm)
• A browser-based UI around the WASM port (RustyNES_web_ui)
File Structure
• Top-level crates:
• RustyNES_core: engine modules (CPU, PPU, APU, Mappers, Bus, Controller, ROM, Save/Load)
• RustyNES_cli: main.rs + build.rs, SDL2 binaries/libs, command‐line interface, file I/O
• RustyNES_wasm: lib.rs producing WebAssembly + JS glue (foo.js)
• RustyNES_web_ui: HTML/CSS/TS, NPM, vite dev server, bundling the WASM module
• External dependencies: SDL2 (native), wasm-pack / npm (web).
Extract Architectural Insights from the README
• Core is pure Rust with zero external deps.
• CLI uses SDL2 for graphics/audio/input.
• WASM crate compiles core for the browser.
• Web UI loads the .wasm bundle, JS bindings, and presents an HTML5 UI.
Main Components & How They Interact
a. RustyNES_core (Engine layer)
• Subcomponents: CPU (6502 instructions), PPU (render pipeline), APU (sound channels), Memory Bus, Mappers, Controller Input, ROM loading, Save/Load.
b. RustyNES_cli (Native adapter)
• Uses rusty_nes_core API → Runs emulation loop → Pushes frame buffer & audio samples → Renders via SDL2 → Reads Keyboard for controller → Reads/Writes save files.
c. RustyNES_wasm (WASM adapter)
• Compiles rusty_nes_core to WebAssembly → Exposes init(), step(), loadROM(), saveState() functions to JS.
d. RustyNES_web_ui (Browser front end)
• HTML/CSS/TS UI → Loads WASM via JS bindings → Maps browser events (keyboard) to controller API → Draws frames into <canvas> → Plays audio via Web Audio API → Provides file‐picker for ROMs & save states.
Architectural Patterns & Design Principles
• Layered architecture: Core Engine (pure logic) → Platform Adapters → Presentation/UI.
• Separation of concerns: Emulation logic is platform‐agnostic; front ends handle rendering/input.
• Modular crates (Rust’s package model) enable reuse across CLI and WASM.
• Adapter pattern: each front end “adapts” the same core API to different host environments (SDL2 vs JS).