This project is a functional emulator for the 6502 microprocessor, written entirely in PHP. It emulates a simple 8-bit computer, complete with a CPU, RAM, ROM, and a serial UART for input/output.
This project was heavily inspired by Ben Eater's fantastic YouTube series, "Build a 65c02-based computer from scratch". While Ben builds a physical computer, this project emulates one in software.
- A fully functional 6502 CPU emulator.
- A system bus to connect peripherals.
- RAM and ROM memory components.
- A serial UART for interactive I/O.
- Ability to run assembled 6502 machine code.
- Includes a port of the classic Wozmon monitor program.
- PHP 8.1 or higher
- Composer for dependency management
cc65
toolchain for assembling 6502 code. You can download it from the official cc65 website.
-
Clone the repository:
git clone https://github.com/your-username/6502-Emulator.git cd 6502-Emulator
-
Install PHP dependencies:
composer install
The assembly source files are located in the programs/
directory. A helper
script is provided to assemble them.
-
Assemble the BIOS:
./utilities/buildasm.sh bios.asm bios.cfg
-
Assemble Wozmon:
./utilities/buildasm.sh wozmon_uart.asm wozmon_uart.cfg
Assembled binaries (
.bin
files) will be placed in theroms/
directory.
You can run any assembled program using the loadbin.php
script.
-
Run the BIOS: The BIOS will perform a quick memory test and then wait for you to enter a memory address to jump to.
php loadbin.php bios.bin
-
Run Wozmon: Wozmon provides a simple monitor program that allows you to inspect memory and execute code.
php loadbin.php wozmon_uart.bin
Once Wozmon starts, you can interact with it. For example, to view the contents of memory starting at address
$C000
, you would typeC000.C00F
and press Enter.
The project uses PHPUnit for unit testing. To run the test suite:
./vendor/bin/phpunit
PHPStan is used for static analysis. To check the codebase:
./vendor/bin/phpstan analyse src