This directory contains a test harness for running Klaus Dormann's comprehensive 6502/65C02 functional tests against the W65C02S emulator.
The test suite validates the emulator by executing Klaus Dormann's exhaustive test binaries, which exercise all instructions, addressing modes, and flag behaviors. A successful test run executes approximately 88 million cycles and validates correct CPU behavior.
The test binaries are not included in this repository. Download them from the Klaus Dormann test repository:
cd kd_test
# Download 6502 functional test
wget https://github.com/Klaus2m5/6502_65C02_functional_tests/raw/refs/heads/master/bin_files/6502_functional_test.bin
# Download 65C02 extended opcodes test
wget https://github.com/Klaus2m5/6502_65C02_functional_tests/raw/refs/heads/master/bin_files/65C02_extended_opcodes_test.binNote: The .bin files are git-ignored to keep the repository clean.
From the repository root directory:
sh http_server.shThis will start a local HTTP server on port 8000.
Navigate to: http://localhost:8000/kd_test
- Load Binary: Click "Load Binary" and select a test file (e.g.,
6502_functional_test.bin) - Configure Settings (optional):
- Load Address: Where to load the binary in memory (default:
0000) - Start Address: Where to begin execution (default:
0400) - Success Address: PC address indicating test completion (default:
3469) - Max Cycles: Maximum cycles before timeout (default:
100000000)
- Load Address: Where to load the binary in memory (default:
- Run Test: Click "Run Test" and wait for completion
- ✓ SUCCESS: All tests passed - the emulator is functioning correctly
- ✗ FAILURE: Test failed at a specific address (see failure details below)
On failure, the harness displays:
- The instruction opcode where execution got stuck
- Register state (A, X, Y, SP, PC, flags)
- Memory context around the failing PC
- Execution trace (last 50 instructions)
| Test File | Description | Success Address |
|---|---|---|
6502_functional_test.bin |
Core 6502 instruction test | 0x3469 |
65C02_extended_opcodes_test.bin |
65C02-specific opcodes | 0x24F1 |
Update the "Success Address" field when testing different binaries.
The Klaus Dormann test suite is written in 6502 assembly and runs directly on the "bare metal" of the emulator. It does not output text to a console. Instead, it communicates status through the Program Counter (PC):
- Sequential Validation: Tests validate instructions one by one (e.g., checking if
LDA #$00correctly sets the Zero flag) - Failure Mode: If a test fails, the program enters an infinite loop at the failure address - it effectively "hangs" where the bug was detected
- Success Mode: If all tests pass, the program jumps to the success address (e.g.,
0x3469) and loops there forever
- ✓ SUCCESS: PC reached the success address and stayed there (~88 million cycles for full test)
- ✗ FAILURE: Emulator got stuck at a different address
- Stuck Address: Indicates which test failed - earlier addresses mean basic instructions are broken
- Stuck Opcode: The instruction that triggered the trap
Set a breakpoint to pause execution at a specific address:
- Enter address in Breakpoint field (e.g.,
0x09D7) - Run test - execution stops at breakpoint
- View register state and memory context
Peek - Read memory contents:
- Enter address (e.g.,
0x0100) - Enter length in bytes (default: 16)
- Click "Peek" to display values
Poke - Write to memory:
- Enter address (e.g.,
0x0100) - Enter byte value (e.g.,
0xFF) - Click "Poke" to write
Useful for debugging or setting up custom test conditions.
Load Address: 0x0000
Start Address: 0x0400
Success Address: 0x3469
Expected Cycles: ~88 million
Expected Time: 15-20 seconds
Load Address: 0x0000
Start Address: 0x0400
Success Address: 0x24F1
Expected Cycles: ~10 million
Expected Time: 2-3 seconds
Test times out: Increase "Max Cycles" value
Wrong success address: Check that the success address matches the binary you loaded
Browser feels slow: The test runs in chunks to keep UI responsive, but 88M cycles takes time - be patient
Test fails: The emulator has a bug! Check the failure details:
- Stuck opcode shows which instruction failed
- Execution trace shows the instruction sequence leading to failure
- Memory context shows the bytes around the failing PC
The test harness:
- Loads the binary test program into emulated memory
- Sets PC to the start address
- Executes instructions using the W65C02S emulator's
step()method - Monitors for success conditions:
- PC reaches the success address and stays there (infinite loop = pass)
- PC gets stuck at a different address (test failure)
- Invalid opcode encountered
- Maximum cycles exceeded (timeout)
Test binaries created by Klaus Dormann: https://github.com/Klaus2m5/6502_65C02_functional_tests
These tests are the gold standard for validating 6502/65C02 emulators and have helped identify countless bugs across many emulator implementations.