A complete W65C02S (CMOS 6502) processor emulator written in JavaScript with an interactive trainer/debugger interface.
π Try it live!
π§ͺ Klaus Dormann 6502 Test Suite
- Full W65C02S instruction set - All 65C02 opcodes including CMOS-specific instructions
- Interactive trainer/debugger - Visual register inspector, memory viewer, single-step execution
- Browser-based - No installation required, runs entirely in the browser
- Validation tested - Passes Klaus Dormann's comprehensive 6502 functional test suite (~88M cycles)
Try the emulator immediately: https://inindev.github.io/65c02_emu/
- Start the Web Server
sh http_server.shThis starts a local HTTP server on port 8000.
- Open the Trainer
Navigate to: http://localhost:8000/
βββ index.html # Main trainer/debugger interface
βββ w65c02s.js # W65C02S CPU emulator core
βββ ram.js # Memory implementation
βββ display.js # UI and debugger logic
βββ kd_test/ # Klaus Dormann test harness
β βββ README.md # Test suite documentation
β βββ index.html # Test runner interface
β βββ test_harness.js # Test execution engine
β βββ test_ui.js # Test UI controller
βββ test/ # Legacy test interface
βββ index.html
βββ tests.js
The main interface (index.html) provides:
- View and edit all CPU registers (PC, A, X, Y, SP)
- Monitor processor flags (N, V, B, D, I, Z, C)
- Click any value to edit directly
- Hexadecimal memory dump
- Navigate to any address
- View disassembled instructions
- Step - Execute one instruction
- Run - Continuous execution
- Stop - Halt execution
- Reset - Reset CPU to initial state
- Enter 6502 assembly code or hex bytes
- Load programs into memory
- Execute from any address
This emulator has been validated against Klaus Dormann's comprehensive 6502 functional test suite, which exercises:
- All instruction opcodes and addressing modes
- Flag behavior (N, V, Z, C)
- Stack operations
- Interrupt handling
See kd_test/README.md for details on running the test suite.
Test Results:
- β 6502 Functional Test: PASSED (87,947,229 cycles)
- β 65C02 Extended Opcodes: PASSED
The emulator implements:
- All 17 addressing modes (absolute, zero page, indexed, indirect, etc.)
- Complete instruction set including 65C02 extensions
- Accurate flag behavior and timing
- Stack operations with proper push/pull semantics
Key classes:
W65C02S- Main CPU emulatorRegister6502- Register file (A, X, Y, PC, SP, flags)Flags6502- Processor status register
- 64KB addressable memory space
- Read/write operations
- 16-bit word operations (little-endian)
- Real-time register updates
- Memory visualization
- Disassembly view
- Execution control
Works in all modern browsers with ES6 support:
- Chrome/Edge
- Firefox
- Safari
No build process required - pure JavaScript:
# Start local server
sh http_server.sh
# Or use Python's built-in server
python3 -m http.server 8000- Architecture: 8-bit CMOS microprocessor
- Address Space: 64KB (16-bit addressing)
- Registers: A (accumulator), X, Y (index), PC (program counter), SP (stack pointer)
- Flags: N (negative), V (overflow), B (break), D (decimal), I (interrupt), Z (zero), C (carry)
- Stack: 256 bytes (0x0100-0x01FF), descending
- β PHP instruction - Now correctly sets B flag when pushing status to stack
- β BRK instruction - Now properly pushes PC+2 and status, sets flags, jumps to IRQ vector
GNU General Public License v3.0
Copyright Β© 2018 John Clark
See LICENSE for full license text.
Bug reports and pull requests welcome! This emulator aims for cycle-accurate emulation of the W65C02S.
Always run the Klaus Dormann test suite after making changes:
# See kd_test/README.md for setup
cd kd_test
# Download test binaries (see README)
# Open http://localhost:8000/kd_test
# Load and run tests- CPU Implementation: John Clark
- Test Suite: Klaus Dormann (6502_65C02_functional_tests)
- W65C02S Specifications: Western Design Center (Datasheet)