Overview
TheEmulatorBackend interface defines the common API for all emulator backends (Rust WASM, CEmu). This abstraction allows the web app to switch between backends without code changes.
Interface Definition
Source:web/src/emulator/types.ts
Lifecycle Methods
init(): Promise<void>
Initialize the backend and load the WASM module.
Example:
- Must be called before any other methods
- Uses singleton pattern to prevent concurrent initialization
- May retry once on failure to handle HMR or StrictMode issues
destroy(): void
Clean up backend resources and free WASM memory.
Example:
- Safe to call multiple times
- Catches and ignores errors if WASM instance is borrowed
- Resets
isInitializedandisRomLoadedflags
ROM Loading Methods
loadRom(data: Uint8Array): Promise<number>
Load a TI-84 Plus CE ROM file into the emulator.
Parameters:
data- ROM file bytes (typically 4MB)
0on success- Negative error code on failure
sendFile(data: Uint8Array): number
Inject a program file (.8xp) or AppVar (.8xv) into flash before boot.
Parameters:
data- File bytes (.8xp or .8xv format)
- Number of entries injected (≥0) on success
- Negative error code on failure
-10- ROM not loaded-11- Parse error-12- No flash space-13- Already booted
- Must be called after
loadRom()but beforepowerOn() - Files are injected into the flash archive
- TI-OS will discover them on next boot
sendFileLive(data: Uint8Array): number
Inject a file into a running emulator (hot reload).
Parameters:
data- File bytes (.8xp or .8xv format)
- Number of entries injected (≥0) on success
- Negative error code on failure
- Can be called while emulator is running
- Invalidates any existing copy of the program
- Performs a soft reset so TI-OS discovers the new file
- Use this for “hot reload” workflow during development
powerOn(): void
Simulate pressing the ON button to boot the calculator.
Example:
- Must be called after
loadRom()to start emulation - Simulates a physical ON key press and release
- CPU begins executing from reset vector
reset(): void
Reset the emulator to its initial state.
Example:
- Clears all RAM and registers
- ROM must be reloaded after reset
- Use
powerOn()for a soft reset instead
Execution Methods
runCycles(cycles: number): number
Execute the emulator for a specified number of CPU cycles.
Parameters:
cycles- Number of cycles to execute
- Number of cycles actually executed
- Automatically updates the framebuffer
- Returns early if CPU halts or encounters errors
- May execute fewer cycles than requested
runFrame(): void
Convenience method to run one frame (800,000 cycles at 60 FPS).
Example:
- Equivalent to
runCycles(800_000) - Assumes 48MHz CPU speed and 60 FPS refresh rate
Display Methods
getFramebufferWidth(): number
Get the framebuffer width in pixels.
Returns:
- Width (typically 320)
getFramebufferHeight(): number
Get the framebuffer height in pixels.
Returns:
- Height (typically 240)
getFramebufferRGBA(): Uint8Array
Get the framebuffer data in RGBA8888 format.
Returns:
- Uint8Array with RGBA bytes (width × height × 4 bytes)
- Format is RGBA8888 (4 bytes per pixel: R, G, B, A)
- Ready for direct use with Canvas
ImageData - Internal format is ARGB8888 but converted for canvas compatibility
Input Methods
setKey(row: number, col: number, down: boolean): void
Set the state of a key in the 8×7 key matrix.
Parameters:
row- Key row (0-7)col- Key column (0-7)down-truefor pressed,falsefor released
| Row | Col 0 | Col 1 | Col 2 | Col 3 | Col 4 | Col 5 | Col 6 |
|---|---|---|---|---|---|---|---|
| 0 | Graph | Trace | Zoom | Window | Y= | 2nd | Mode |
| 1 | X,T,θ,n | Stat | - | ) | ( | , | ^ |
| 2 | Tan | Vars | - | ) | ( | / | Clear |
| 3 | Cos | Prgm | - | 9 | 6 | 3 | (-) |
| 4 | Sin | Apps | - | 8 | 5 | 2 | . |
| 5 | Math | XInv | - | 7 | 4 | 1 | 0 |
| 6 | Alpha | Store | - | Down | Right | Left | Enter |
| 7 | Del | - | - | Up | + | - | * |
State Persistence Methods
saveState(): Uint8Array | null
Capture the complete emulator state.
Returns:
Uint8Arraycontaining state datanullif ROM not loaded or save failed
- All CPU registers (PC, SP, AF, BC, DE, HL, IX, IY)
- All RAM and VRAM contents
- All peripheral states (LCD, timers, interrupts)
- WASM memory snapshot (for Rust backend)
loadState(data: Uint8Array): boolean
Restore a previously saved state.
Parameters:
data- State data fromsaveState()
trueon successfalseon failure
- State format is backend-specific (Rust vs CEmu)
- States are not portable between backends
- For Rust backend, includes WASM memory snapshot with header
State Query Methods
isLcdOn(): boolean
Check if the LCD should display content.
Returns:
trueif LCD is powered on and should displayfalseif LCD is off (show blank screen)
- LCD is off when control port 0x05 bit 4 is clear
- LCD is off when lcd.control bit 11 is clear
- This is separate from device sleep state
Info Properties
name: string
Readonly name of the backend implementation.
Example:
isInitialized: boolean
Readonly flag indicating if backend is initialized.
Example:
isRomLoaded: boolean
Readonly flag indicating if a ROM is loaded.
Example:
Implementation: RustBackend
The Rust WASM backend implementation: Source:web/src/emulator/RustBackend.ts
- Singleton WASM initialization
- Automatic retry on initialization failure
- Custom state snapshot format with WASM memory
- Error handling for WASM borrowing issues
Complete Usage Example
See Also
- WASM Bindings - Building and loading the WASM package
- Source:
web/src/emulator/types.ts- Interface definition - Source:
web/src/emulator/RustBackend.ts- Rust backend implementation - Source:
core/src/wasm.rs- WASM bindings