This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
Pico-286 is a PC emulator targeting Intel 8086/8088/80186/286 CPUs, designed to run on Raspberry Pi Pico (RP2040/RP2350) microcontrollers. The project emulates classic PC hardware including various graphics cards (CGA, TGA, EGA, VGA), sound cards (PC Speaker, Adlib, Sound Blaster, MPU-401), and peripherals.
The project uses CMake with two main build targets:
- Host build (Windows/Linux):
cmake -DCMAKE_BUILD_TYPE=Release -DPICO_PLATFORM=host - Pico RP2040:
cmake -DCMAKE_BUILD_TYPE=Release -DPICO_PLATFORM=rp2040 - Pico RP2350:
cmake -DCMAKE_BUILD_TYPE=Release -DPICO_PLATFORM=rp2350
All builds require exactly one display and one audio option:
Display options (mutually exclusive):
-DENABLE_TFT=ON- TFT display via ST7789-DENABLE_VGA=ON- VGA output-DENABLE_HDMI=ON- HDMI output (forces CPU to 378MHz)
Audio options (mutually exclusive):
-DENABLE_I2S_SOUND=ON- I2S audio output-DENABLE_PWM_SOUND=ON- PWM audio output-DENABLE_HARDWARE_SOUND=ON- Hardware audio output
- PSRAM: Default for RP2350. Use
-DONBOARD_PSRAM=ON -DONBOARD_PSRAM_GPIO=19for onboard PSRAM - Virtual Memory: Use
-DTOTAL_VIRTUAL_MEMORY_KBS=512to enable virtual memory instead of PSRAM - CPU Frequency: Set with
-DCPU_FREQ_MHZ=378(default varies by platform)
# RP2350 with VGA and PWM audio
cmake -DCMAKE_BUILD_TYPE=Release -DPICO_PLATFORM=rp2350 -DENABLE_VGA=ON -DENABLE_PWM_SOUND=ON
make -j$(nproc)
# Windows/Linux host build (Linux requires X11 development libraries)
cmake -DCMAKE_BUILD_TYPE=Release -DPICO_PLATFORM=host
make -j$(nproc)
# RP2040 with TFT and I2S
cmake -DCMAKE_BUILD_TYPE=Release -DPICO_PLATFORM=rp2040 -DENABLE_TFT=ON -DENABLE_I2S_SOUND=ON
make -j$(nproc)./build_all_firmwares.sh- Automated build script for all firmware variations across platforms, display/audio combinations, and memory configurations./merge_firmwares.sh- Merges RP2040/RP2350 firmware pairs into single .uf2 files
Emulator Core (src/emulator/):
cpu.c/cpu.h- Intel x86 CPU emulation (8086-286)memory.c- Memory management and addressingports.c- I/O port handlingemulator.h- Main emulator definitions and interfaces
Platform Abstraction:
src/pico-main.c- Raspberry Pi Pico entry point and hardware initializationsrc/win32-main.cpp- Windows host build entry point with MiniFB graphicssrc/linux-main.cpp- Linux host build entry point with X11-based MiniFB graphics
Memory Layout:
RAM[RAM_SIZE]- Main system RAM (size varies by platform, seeREADME.mdfor details).VIDEORAM[64KB]- Video memory buffer at 0xA0000-0xC0000.- See the "Platform-specific Details" and "Extended Memory (EMS/XMS)" sections in
README.mdfor a full breakdown.
Extended Memory Systems:
- PSRAM: High-speed hardware-based extended memory using an external PSRAM chip. This is the default and recommended option. It uses a custom PIO and DMA driver.
- Virtual Memory: A slower, file-based fallback for systems without PSRAM. It uses a
pagefile.syson the SD card. Enabled with-DTOTAL_VIRTUAL_MEMORY_KBS > 0.
Graphics Drivers (drivers/graphics/):
- Abstracted graphics interface supporting multiple output types
- Hardware-specific implementations: VGA, HDMI, TFT (ST7789)
- Font rendering with multiple font sizes (4x6, 6x8, 8x8, 8x16)
Video Mode Support:
- Text modes: 40x25, 80x25 (both color and monochrome)
- CGA: 320x200x4, 640x200x2, composite color modes
- TGA: 160x200x16, 320x200x16, 640x200x16
- EGA: 320x200x16, 640x200x16, 640x350x16
- VGA: 320x200x256, 640x480x16, 640x480x2
- Hercules: 720x348x2
Sound Drivers (drivers/audio/):
- Multi-platform audio abstraction (I2S, PWM, hardware DAC)
- Real-time audio mixing and output
Sound Card Emulation (src/emulator/audio/):
- PC Speaker/System Beeper
- Adlib/Sound Blaster (OPL2 FM synthesis via emu8950)
- MPU-401 MIDI with General MIDI synthesizer
- Covox Speech Thing, Disney Sound Source
- Tandy 3-voice (SN76489), Creative Music System
MiniFB Implementation (src/MiniFB.h, src/WinMiniFB.c, src/LinuxMiniFB.c):
- Unified framebuffer interface for Windows and Linux host builds
- Cross-platform API with same function signatures:
mfb_open(),mfb_update(),mfb_close() - 32-bit RGBA buffer rendering with optional scaling
- Palette support for indexed color modes
- Keyboard and mouse input handling with PC scancode translation
- FPS limiting and frame timing control
Platform-Specific Implementations:
- Windows: Uses Win32 API with
CreateWindow(),StretchDIBits()for rendering - Linux: Uses X11 with
XCreateWindow(),XPutImage()for rendering
See README.md for a more detailed explanation.
Pico (Dual-Core):
- Core 0: Runs the
exec86()emulation loop and handles input. - Core 1: Manages real-time tasks: rendering, audio, and PIT timer interrupts.
Host - Windows & Linux (Multi-threaded):
- Main thread: Runs
exec86()and manages the window. - Ticks thread: Simulates hardware timers for interrupts, rendering, and audio generation.
- Sound thread: Handles audio output to the OS.
Hardware Drivers (drivers/):
ps2/- PS/2 keyboard and mouse supportsdcard/- SD card filesystem (FAT32 via FatFS)psram/- External PSRAM via SPInespad/- NES gamepad for mouse emulationhdmi/,vga-nextgen/,st7789/- Display outputsaudio/- Audio output drivers
Driver Architecture:
- Each driver has its own CMakeLists.txt and can be conditionally compiled.
- PIO (Programmable I/O) extensively used for hardware interfaces.
- Drivers provide hardware abstraction for the emulator core.
- Note: Default hardware pinouts are now documented in the main
README.md.
No automated test framework is present. Testing relies on running actual DOS software and games.
- Serial debug output available via printf (redirected on Pico)
- Win32/Linux builds support standard debugging tools
- Debug video RAM overlay for system messages
- Linux build outputs to terminal/console for debugging
- Optimized for limited RAM environments
- Virtual memory swapping available for RP2040
- PSRAM support for extended applications
- Aggressive compiler optimizations (
-O2,-flto)
- Build system enforces exactly one display and one audio option
- HDMI builds lock CPU frequency to 378MHz
- RP2350 builds have access to more RAM and faster operation
- Font and video data is embedded in headers, not external files
- Pico builds:
\XT\fdd0.img,\XT\hdd.img(on SD card) - Host builds:
../fdd0.img,../hdd.img(relative to executable, i.e., project root directory)
- X11 development libraries:
sudo apt install libx11-dev(Ubuntu/Debian) - pthread support (included with GCC)
- CMake 3.22+ and GCC 11+ for C++20 support
This project benefits from using specialized AI agents for different development tasks:
Primary Agents:
backend-developer- For core emulator logic, CPU emulation, memory management, and platform-specific codeperformance-optimizer- Critical for this resource-constrained embedded system; use when addressing memory usage, CPU performance, or timing issuescode-archaeologist- Essential for understanding the complex emulator architecture and legacy x86 instruction handling
Secondary Agents:
documentation-specialist- For updating README.md, hardware documentation, and API referencescode-reviewer- For security and correctness review of memory management and hardware interface codeproject-analyst- For analyzing new subsystems or understanding driver interactions