PHPackages                             andrewthecoder/6502-emulator - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. andrewthecoder/6502-emulator

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

andrewthecoder/6502-emulator
============================

A 6502 microprocessor emulator written in PHP.

v0.0.2-alpha(7mo ago)18191MITPHP

Since Oct 16Pushed 6mo agoCompare

[ Source](https://github.com/andrewthecodertx/65C02-Emulator)[ Packagist](https://packagist.org/packages/andrewthecoder/6502-emulator)[ Docs](https://andrewthecoder.com)[ RSS](/packages/andrewthecoder-6502-emulator/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)Dependencies (2)Versions (2)Used By (0)

PHP-6502: A 6502 Emulator in PHP
================================

[](#php-6502-a-6502-emulator-in-php)

A fully functional 6502 microprocessor emulator written entirely in PHP, packaged as a Composer library for building custom 6502-based systems. Features two CPU cores (NMOS 6502 and WDC 65C02) that can be paired with different system implementations.

Installation
------------

[](#installation)

Install via Composer:

```
composer require andrewthecoder/6502-emulator
```

Features
--------

[](#features)

### Dual CPU Core Support

[](#dual-cpu-core-support)

- **MOS 6502** - Original MOS Technology 6502 with 56 documented instructions and illegal opcodes
- **WDC 65C02** - Western Design Center 65C02 with 70 instructions including BRA, STZ, PHX/PHY, bit manipulation, and more
- **Hybrid execution model** combining JSON-driven and custom handler-based instruction processing
- **Interrupt support** (NMI, IRQ, RESET) with proper edge/level triggering
- **CPU monitoring** for debugging and profiling with instruction tracing and cycle counting
- **Comprehensive PHPDoc documentation** for IDE support

CPU Variants Explained
----------------------

[](#cpu-variants-explained)

This library provides two different 6502 CPU implementations:

### MOS 6502 (Original)

[](#mos-6502-original)

The **MOS 6502** refers to the original microprocessor designed by MOS Technology in 1975. It uses **NMOS** (N-channel Metal-Oxide-Semiconductor) fabrication technology. While you may see it referred to as "NMOS 6502" in technical documentation, the official product name is simply **MOS 6502** or **6502**.

**Characteristics:**

- 56 documented instructions
- Includes illegal/undocumented opcodes used by some software
- Hardware bugs (JMP indirect page boundary bug, decimal mode doesn't set N/V/Z flags)
- Found in: Commodore 64, Apple II/II+, NES, Atari 2600/5200/7800

### WDC 65C02 (Enhanced)

[](#wdc-65c02-enhanced)

The **WDC 65C02** (or simply **65C02**) is an enhanced version designed by Western Design Center using **CMOS** (Complementary Metal-Oxide-Semiconductor) fabrication technology. The "C" in the name literally stands for CMOS. This version fixed bugs from the original and added new instructions.

**Characteristics:**

- 70 instructions (14 additional instruction types)
- Fixed hardware bugs from the original
- Better power efficiency (CMOS technology)
- New addressing modes and bit manipulation instructions
- Found in: Apple IIc/IIe, later Commodore models, modern 6502-based systems

### When to Use Which?

[](#when-to-use-which)

**Use `andrewthecoder\MOS6502\CPU` when:**

- Emulating systems that require the original chip (NES, C64, original Apple II)
- You need illegal opcodes for compatibility
- You want hardware-accurate behavior including bugs

**Use `andrewthecoder\WDC65C02\CPU` when:**

- Building modern 6502-based projects
- You want the additional instructions (BRA, STZ, etc.)
- You need the bug fixes (JMP indirect, decimal mode)
- Emulating systems that use the 65C02 (Apple IIe, IIc)

Quick Start
-----------

[](#quick-start)

### Using the CPU in Your Project

[](#using-the-cpu-in-your-project)

```
