Emulator Core Architecture
The TI-84 Plus CE emulator core is a from-scratch Rust implementation that accurately recreates the TI-84 Plus CE hardware in software. The core is platform-agnostic, with no OS dependencies, and provides a stable C ABI for integration with Android, iOS, and web applications.Module Organization
The emulator core is organized into several focused modules, each handling a specific aspect of the hardware:Core Modules
emu.rs - Emulator Orchestrator
The Emu struct is the main entry point that coordinates all subsystems:
- CPU Execution: Manages the eZ80 CPU instruction stepping
- Event Scheduling: Coordinates timed events (timers, LCD, RTC)
- Frame Rendering: Converts VRAM to ARGB8888 framebuffer
- State Management: Handles reset, save states, and ROM loading
- Cycle Accounting: Tracks total cycles for accurate emulation timing
load_rom(): Load TI-84 CE ROM into flash memoryrun_cycles(): Execute for N cycles, returns actual cycles executedstep(): Execute one instruction, returns detailed trace informationrender_frame(): Update framebuffer from VRAMset_key(): Handle keypad input
cpu/ - eZ80 CPU Implementation
Implements the complete eZ80 instruction set with ADL mode support:
- Register Set: 24-bit BC, DE, HL, IX, IY in ADL mode
- Instruction Execution: Cycle-accurate instruction timing
- Interrupt Handling: Maskable (IRQ) and non-maskable (NMI) interrupts
- ADL Mode: 24-bit addressing with mixed-mode support
- Prefetch Buffer: Matches CEmu’s cycle timing for instruction fetches
memory.rs - Memory Subsystem
Manages the three main memory types:
- Flash: 4MB NOR flash for OS and programs (lazy allocation)
- RAM: 256KB user RAM + ~150KB VRAM
- Ports: Memory-mapped I/O peripherals
bus.rs - System Bus
Provides address decoding and routes memory accesses:
- Address Decoding: Maps 24-bit addresses to appropriate memory regions
- Wait States: Adds accurate timing for flash/RAM/port accesses
- Flash Cache: Serial flash cache simulation for newer CE models
- Memory Protection: Enforces privileged/unprivileged code boundaries
- I/O Tracing: Comprehensive logging for debugging and parity testing
peripherals/ - Hardware Peripherals
Emulates TI-84 CE hardware devices:
- LCD Controller: 320x240 16-bit color display with DMA
- Keypad: 8x7 key matrix with scan modes
- Timers: 3 general-purpose timers with interrupts
- RTC: Real-time clock with latching
- Interrupt Controller: Manages hardware interrupt sources
- SPI: Serial peripheral interface for hardware communication
- Flash Controller: Flash memory configuration and wait states
scheduler.rs - Event Scheduling
Cycle-accurate event system for timed peripherals:
- Event Types: LCD DMA, timers, RTC, SPI transfers
- CPU Speed Scaling: Adjusts event timing when CPU speed changes (6/12/24/48 MHz)
- Second Boundaries: Handles second rollover for RTC
- Batched Processing: Optimizes HALT loops by batching events
Execution Flow
The emulator follows this execution model:Cycle Accounting
The emulator uses dual cycle counters for CEmu parity:bus.cycles: CPU internal timing (instruction execution)bus.mem_cycles: Memory access timing (flash/RAM wait states)- Total cycles:
bus.cycles + bus.mem_cycles
- Flash wait states (10 cycles for parallel flash, 2-197 for serial flash cache)
- RAM timing (4 cycles read, 2 cycles write)
- Port access delays (2-4 cycles depending on peripheral)
- CPU speed changes (6/12/24/48 MHz via port 0x01)
C API Layer
The core provides a C-compatible API for platform integration:Mutex<Emu> wrapper for thread safety.
Memory Management
The core uses lazy allocation for efficiency:- Flash: Empty
Vecuntilload_rom()called, then allocated to 4MB - RAM: Empty
Vecuntil first write, then allocated to full size - No Pre-allocation: Reduces memory footprint for unused regions
Build Targets
The core supports multiple compilation targets:- Android: Static library (
.a) via Android NDK - iOS: Static library (
.a) via cargo with iOS targets - Web: WebAssembly (
.wasm) viawasm-pack - Native: Standalone for debugging and testing
Testing Strategy
The core includes comprehensive testing:- Unit Tests: Per-module tests for memory, CPU instructions, peripherals
- Integration Tests: Calculator boot sequence, keypad, LCD rendering
- Parity Testing: Trace comparison with CEmu reference emulator
- Debug Tools: Instruction tracing, memory dumps, screen rendering
Performance Characteristics
- Native: 1000+ FPS emulation speed on modern hardware
- WASM: 60+ FPS in browser with ~96KB gzipped bundle
- Mobile: 60 FPS target on mid-range devices
- HALT Optimization: Batched event processing during idle loops
Next Steps
- Dual Backend Architecture - Rust vs CEmu backend comparison
- Memory Map - TI-84 CE address space layout
- CPU Architecture - eZ80 instruction set and ADL mode