Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

47 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

W65C02S Emulator

A complete W65C02S (CMOS 6502) processor emulator written in JavaScript with an interactive trainer/debugger interface.

πŸš€ Try it live!

πŸ§ͺ Klaus Dormann 6502 Test Suite

Features

  • 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)

Quick Start

Online Demo

Try the emulator immediately: https://inindev.github.io/65c02_emu/

Local Development

  1. Start the Web Server
sh http_server.sh

This starts a local HTTP server on port 8000.

  1. Open the Trainer

Navigate to: http://localhost:8000/

Project Structure

β”œβ”€β”€ 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

Using the Trainer/Debugger

The main interface (index.html) provides:

Register Inspector

  • 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

Memory Viewer

  • Hexadecimal memory dump
  • Navigate to any address
  • View disassembled instructions

Execution Controls

  • Step - Execute one instruction
  • Run - Continuous execution
  • Stop - Halt execution
  • Reset - Reset CPU to initial state

Code Entry

  • Enter 6502 assembly code or hex bytes
  • Load programs into memory
  • Execute from any address

Validation

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

Architecture

W65C02S Core (w65c02s.js)

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 emulator
  • Register6502 - Register file (A, X, Y, PC, SP, flags)
  • Flags6502 - Processor status register

Memory Model (ram.js)

  • 64KB addressable memory space
  • Read/write operations
  • 16-bit word operations (little-endian)

Display/Debugger (display.js)

  • Real-time register updates
  • Memory visualization
  • Disassembly view
  • Execution control

Development

Browser Compatibility

Works in all modern browsers with ES6 support:

  • Chrome/Edge
  • Firefox
  • Safari

Local Development

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

Technical Details

W65C02S Specifications

  • 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

References

Known Bugs Fixed

  • βœ… 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

License

GNU General Public License v3.0

Copyright Β© 2018 John Clark

See LICENSE for full license text.

Contributing

Bug reports and pull requests welcome! This emulator aims for cycle-accurate emulation of the W65C02S.

Testing Changes

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

Credits

About

65c02 emulator

Topics

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages