Overview
The TI-84 Plus CE emulator core can be compiled to WebAssembly for use in web applications. The WASM bindings provide a JavaScript-friendly API usingwasm-bindgen.
Building the WASM Package
Prerequisites
- Install Rust and the WASM target:
- Install wasm-pack:
Build Command
From theweb/ directory:
--target web- Generates ES module imports for browser use--release- Optimized build (~96KB gzipped)--out-dir- Output directory for generated files
emu_core.js- JavaScript module with initialization and bindingsemu_core_bg.wasm- Compiled WebAssembly binaryemu_core.d.ts- TypeScript definitions
Loading in JavaScript/TypeScript
Basic Setup
Import the WASM module and initialize it:Singleton Pattern
The emulator uses a singleton pattern to prevent concurrent initialization:Loading and Running a ROM
Complete Example
Handling Key Input
The TI-84 Plus CE uses an 8x7 key matrix:Loading Programs
Before Boot (Pre-injection)
Inject programs into flash before powering on:Live Injection (Hot Reload)
Inject programs into a running emulator:send_file_live method invalidates any existing copy and performs a soft reset so the OS discovers the new program.
State Persistence
Save State
Capture the complete emulator state:Load State
Restore a saved state:RustBackend.ts:136-191 for implementation details.
Display Status
LCD State
Check if the LCD should display content:Device Power State
Check if the calculator is sleeping:Backlight Brightness
Get the current backlight level:Debugging
Diagnostic Status
Get debug information:Console Logging
The WASM module logs events to the browser console:Performance Considerations
Frame Rate
Target 60 FPS with 800,000 cycles per frame:Framebuffer Format
The framebuffer is returned as RGBA8888 (ready forImageData):
get_framebuffer_rgba() converts to RGBA8888 for canvas compatibility.
Error Handling
Return Codes
Methods return integer error codes:File Injection Errors
Memory Management
Cleanup
TheWasmEmu instance should be freed when done:
RustBackend class handles cleanup automatically, catching errors if the instance is still borrowed:
TypeScript Types
The generatedemu_core.d.ts provides full TypeScript definitions:
See Also
- EmulatorBackend Interface - TypeScript interface specification
- Source:
core/src/wasm.rs- WASM bindings implementation - Source:
web/src/emulator/RustBackend.ts- Browser integration layer