A comprehensive 6502 microprocessor kernel implementation with an interactive monitor program for debugging, programming, and system control.
This project started as a continuation of a CPU/assembler/disassembler I wrote in Python. I wanted to create an actual running environment to enter code directly or load from a file and run.
I also wanted to test the abilities of AI as part of the development and documentation process.
This project implements a complete 6502-based computer system kernel for emulated environments. The kernel provides low-level system initialization, hardware control, and most importantly, a powerful interactive monitor program for direct system interaction.
Key Features:
- Complete 6502 assembly language kernel optimized for emulated environments
- Cycle-stepped WDC 65C02 CPU emulator (full CMOS instruction set, validated against the Klaus2m5/amb5l functional, decimal, and 65C02-extended test suites)
- Interactive monitor with comprehensive debugging tools
- Built-in MFC BASIC interpreter (derived from EhBASIC), launched with the
B:command (with human-readable.basLOAD/SAVE) - Memory manipulation and program execution capabilities
- Streamlined architecture with universal commands and simplified modes
- File I/O operations for loading and saving programs
- Comprehensive search, fill, move, and copy operations
The heart of this system is the 6502 Monitor - a complete interactive debugging and programming environment that provides direct control over the computer's memory and execution. The monitor offers a command-line interface with powerful tools for memory operations, program execution, and system inspection.
The monitor features a streamlined architecture with:
- Two primary modes: Command mode (default) and Write mode for interactive editing
- Simplified command processing with consistent syntax and error handling
- Command repeatability recall last command for quick replay or modification
When the system boots, you'll see:
-=MFC 6502 OPERATIONAL=-
>
The > prompt indicates you're in command mode. You can now enter any monitor command.
For complete command documentation including syntax, examples, and detailed usage information, see:
The command reference provides comprehensive documentation for all monitor commands, organized by category:
| Category | Commands | Description |
|---|---|---|
| Memory Operations | R:, W:, F:, M:, X: | Read, write, fill, move/copy, and search memory |
| Program Operations | G:, L:, S: | Execute, load, and save programs |
| Modules | B: | Module bank menu β map and run a ROM module (BASIC is bank 1) |
| Number Conversion | D:, H: | Convert between decimal and hexadecimal |
| Display Commands | C:, T:, Z: | Clear screen, show stack, show zero page |
| System Commands | ?, ESC, . | Help, exit mode, command recall |
Commands are listed alphabetically by command letter (matching the on-screen ? help):
- B: Module Bank Menu - List the available ROM modules and map/run one in the
$B000-$DFFFwindow; BASIC is module bank 1 (modules return to the monitor on exit). See docs/module_slot_design.md - C: Clear Screen - Clear the display
- D: Decimal to Hex - Convert decimal (0-65535) to hexadecimal format
- F: Fill Memory - High-performance memory filling with progress feedback
- G: Go/Run - Direct program execution with return to monitor
- H: Hex to Decimal - Convert hexadecimal (0000-FFFF) to decimal format
- L: Load File - Load a host-selected file to an address:
L:8000(host shows a file dialog) - M: Move/Copy - Smart memory operations with overlap detection (
M:src-end,dest,Bwhere B: 0=copy, 1=move) - R: Read Memory - Display bytes in memory, supports single addresses or ranges
- S: Save File - Save a memory range to a host-selected file:
S:8000-8FFF(host shows a file dialog) - T: Stack - Display the stack page ($0100-$01FF), paged
- W: Write Memory - Interactive hex editing with address advancement
- X: Search Memory - Multi-byte pattern search with paged output
- Z: Zero Page - Display zero page ($0000-$00FF), paged
- ESC - Exit the current mode and return to the command prompt
The monitor provides clear, consistent error messages:
ERROR?- Invalid command syntax or parametersRANGE?- Invalid or out-of-bounds address rangeVALUE?- Invalid hexadecimal characters in input
- $0000-$00FF: Zero Page (system workspace; monitor uses $14-$39, EhBASIC uses the rest)
- $0100-$01FF: Stack memory
- $0200-$03FF: Monitor variables and command buffers
- $0400-$07E7: Screen memory (40x25 display buffer)
- $0800-$AFFF: User RAM (module working RAM; EhBASIC program/variable space)
- $B000-$DFFF: Module window (12 KB; bank 0 = RAM, banks 1..255 = ROM modules β BASIC is bank 1)
- $E000-$FFFF: Kernel ROM (8 KB; CODE ~3,900 bytes, rest free for growth)
- $FE00-$FE22: PIA registers (keyboard, file I/O, timer) β an I/O page reserved within the kernel region
See docs/kernel_memory_map.md for the full map.
User programs can access kernel services via the jump table at $FF00:
| Address | Service | Description |
|---|---|---|
| $FF00 | PRINT_CHAR | Print single character |
| $FF03 | PRINT_MESSAGE | Print null-terminated string |
| $FF06 | PRINT_NEWLINE | Print carriage return/line feed |
| $FF09 | GET_KEYSTROKE | Wait for key press |
| $FF0C | CLEAR_SCREEN | Clear display |
| $FF0F | GET_RANDOM_NUMBER | Generate random byte |
| $FF12 | RETURN_FROM_MODULE | Module exit point β unmaps the bank, returns to monitor (BASIC BYE) |
The kernel provides memory-mapped file I/O at:
- $FE10: File command register
- $FE11: File status register
- $FE12-$FE13: Address registers
- $FE14-$FE1F: Filename buffer
- $FE20-$FE21: End address (for save operations)
- CMake 3.20 or later
- C++20 compatible compiler (GCC 10+, Clang 10+, MSVC 2019+)
- cc65 toolchain (ca65 assembler and ld65 linker)
- Qt6 or Qt5 (optional, for GUI support)
# Option 1: Use the convenient build script (recommended)
./build.sh
# Option 2: Manual out-of-source build
cd cmake-build-debug
cmake -G Ninja ..
ninja
# Build outputs:
# - Executable: cmake-build-debug/bin/6502-kernel
# - Kernel ROM: cmake-build-debug/kernel/kernel.rom
# - BASIC ROM: cmake-build-debug/kernel/basic.rom
# - Memory map: cmake-build-debug/kernel/kernel.map6502-kernel/
βββ src/ # C++ source files
β βββ computer/ # CPU, memory, VIC, PIA emulation
β βββ ui/ # Qt GUI
β βββ kernel/ # 6502 assembly (kernel.asm, basic.asm) + ld65 configs
βββ include/ # C++ header files
βββ docs/ # Documentation
βββ examples/ # Example 6502 programs
βββ tools/cmake/ # CMake modules
βββ tests/ # Unit and integration tests
For detailed development information and project context, see:
- CLAUDE.md - Development guidelines and architecture documentation
- docs/ - Detailed command documentation and requirements
- Start with Help: Use
?to see all available commands - Use Command Recall: The
.command saves time when refining commands - File Operations:
L:8000loads andS:8000-8FFFsaves; the host shows a file dialog to pick the file - Search Effectively: Use X: with multiple byte patterns for precise matching
- Number Conversion: Use D: and H: commands to convert between decimal and hex
- Program Development: Load programs with L:, test with G:, save modifications with S:
The monitor is designed for both interactive exploration and efficient program development workflows.