Overview: what this is and where to start
This is a document you can follow: every command is in the repo, and every conclusion has a test or a hash behind it. It also says plainly what has not been done yet — this is not a finished chip.
Four reading paths
| Who you are | Start here | Then |
|---|---|---|
| I am here to practice the flow | 10 Verification | 11 DiffTest → 12 Golden frames → 14 Synthesis → 15 Roadmap |
| I just want to run it | 01 Quickstart | If it breaks: 16 Troubleshooting |
| I want to understand the design | 03 Architecture | 04 CPU → 05 PPU → 10 Verification |
| I want to contribute or push the backend | 02 Repository map | 10 Verification → 14 Synthesis → 15 Roadmap → 17 Contributing |
What it is, and what it is not
Three execution paths
| Path | Role | Status | Best for |
|---|---|---|---|
NEMU / 6502EMU | Software reference (REF) | Playable | Playing, golden frames, CPU reference behaviour |
RTL SoC | Design under test (DUT) | Prototype | Synthesis, verification, DiffTest, future FPGA/ASIC |
GEM6502 | C functional / cycle model | Legacy | Fast PRG runs and instruction-level regression; not a full timing platform |
DUT and REF must stay independent. NEMU is never synthesized, and RTL may not borrow NEMU's implementation to “check the answer”. DiffTest compares observable state only: registers, bus transactions, frame hashes, audio samples and mapper state.
Latest verification snapshot
| Check | Result | Evidence |
|---|---|---|
| RTL unit / integration tests | 28 PASS | cd rtl && make sim |
| RTL lint | PASS | cd rtl && make lint |
| RTL CPU Klaus | PASS · PC=0x3469 | sim/klaus/ |
| RTL / NEMU golden title frame | SHA-256 match | 12 Golden frames |
| RTL gameplay after START | Rendered | 01 Quickstart |
| FPGA bitstream / board | Not yet | 15 55nm path |
Quickstart: get one frame running
The shortest path is NEMU: build once, then use roms/play.sh as often as you like. To exercise the RTL, run the same ROM through Verilator and capture a PPM frame.
Dependencies
| Tool | Purpose | Notes |
|---|---|---|
| Git | Get the repository | First clone only |
| clang / gcc + make | Build NEMU and GEM6502 | macOS needs Xcode Command Line Tools |
| SDL2 | Emulator window, keyboard and audio | brew install sdl2 / libsdl2-dev |
| Python 3 | iNES extraction, PPM to PNG | Pillow optional |
| Icarus Verilog | make sim runs 28 RTL tests | Default Icarus path |
| Verilator | RTL frame capture, Klaus, DiffTest | Needs a working C++ toolchain |
| Yosys 0.60 | Area estimates | Optional, -noabc |
Build and play NEMU
$ git clone https://github.com/OneDayOneApp/Open6502.git $ cd Open6502 $ make -C NEMU m6502_defconfig $ make -C NEMU -j8 $ ./roms/play.sh falling
You can also call the binary directly: ./NEMU/build/6502EMU roms/falling.nes. Most games start with V; 1P uses WASD + Space/Z + X, 2P uses the arrow keys and , . / '.
Bundled ROMs
| ROM | Mapper | Genre | Licence | 300-frame status |
|---|---|---|---|---|
falling.nes | 0 / NROM | Platformer | MIT | Boots, title screen |
galaxypatrol.nes | 0 / NROM | Shooter | MIT | Boots, playable; known starfield rendering gap |
hanoi.nes | 0 / NROM | Puzzle | MIT | Boots, title screen |
table_tennis.nes | 0 / NROM | 2P pong | MIT | Boots, title screen |
file-fixers.nes | 4 / MMC3 | Puzzle | MIT | Boots, title screen |
stallar.nes | 4 / MMC3 | Platformer | MIT | Boots, title screen |
roms/LICENSES/. The repository contains no commercial ROMs.
Headless screenshots (NEMU)
Both the title frame and the post-START frame can be captured without a window. This is also where the golden frames come from:
$ ./NEMU/build/6502EMU --headless --no-audio --frames=300 \ --screenshot=/tmp/nemu-falling.ppm roms/falling.nes $ ./NEMU/build/6502EMU --headless --no-audio --hold=start --frames=20 \ --screenshot=/tmp/nemu-start.ppm roms/falling.nes
# PPM to PNG; on macOS without Pillow, use sips $ python3 -c 'from PIL import Image; Image.open("/tmp/nemu-falling.ppm").save("/tmp/nemu-falling.png")'
GEM6502 C model
$ cd GEM6502 $ make $ make test $ ./gem6502 game ../roms/falling.nes 60 /tmp/gem-title.ppm $ ./gem6502 play ../roms/file-fixers.nes
play needs SDL2. Without it the CLI still builds, but play reports the missing dependency. See 13 GEM6502 for scope and limits.
Run the RTL game and capture a frame
The repository script wraps iNES extraction, the Verilator build and the run:
$ ./sim/game/run.sh roms/falling.nes /tmp/falling-rtl.ppm $ python3 -c 'from PIL import Image; Image.open("/tmp/falling-rtl.ppm").save("/tmp/falling-rtl.png")'
sim/game/run.sh defaults to macOS clang++, the macOS SDK and Homebrew LLVM's libc++ path. On Linux or a different LLVM version, override SDK=…, LIBCXX_DIR=… or CXX=…, or adjust the link flags as noted in the script.
Run the whole regression
$ cd rtl $ make lint $ make sim $ cd .. $ ./sim/difftest/run.sh $ ./sim/difftest/run_alu.sh
make sim compiles and runs 28 testbenches with Icarus. The output is large, but every step should print PASS. On Windows, use WSL2 and follow the Linux steps.
Repository map: where everything lives
The repo holds the software reference, the RTL SoC, verification scripts, a C model, a game downloader and the docs. These are the most useful entry points.
| Directory | Read first | Common command |
|---|---|---|
NEMU/ | 6502EMU.md | make -C NEMU -j8 |
rtl/ | README.md, open6502_top.sv | make lint && make sim |
sim/difftest/ | README.md | ./sim/difftest/run.sh |
GEM6502/ | README.md, docs/requirements.md | make && make test |
nesearch/ | README.en.md, PRD.md | ./nesearch/run-ui.sh |
docs/open6502-chip/ | Architecture, verification, DiffTest, area | — |
skills/xiangshan-chip-flow/ | SKILL.md | — |
Documentation index
Architecture: one clock, several phases
All sequential logic runs on the 21.477272 MHz master clock; enable phases create the CPU, PPU, APU and pixel beats, avoiding multi-clock CDC. Reset asserts asynchronously and releases synchronously. This is an NES/Famicom-compatible digital SoC, not a device-by-device copy of the NES board.
Design principles
- RTL is the only synthesizable implementation; NEMU never enters synthesis.
- NEMU is the REF, not the DUT; the two may not share an implementation to “check the answer”.
- Build CPU + bus first, then PPU/APU, then mappers and accessories.
- FPGA prototype before ASIC; every stage has exit criteria.
- Every external interface has an observable trace for DiffTest.
Clocks and reset
| Signal | Frequency | Use |
|---|---|---|
clk_21m | 21.477272 MHz | Single master clock, all sequential logic |
cpu_en | 1.789773 MHz | CPU phase (÷12) |
ppu_en | 5.369318 MHz | PPU dot phase (÷4) |
aud_en | 44.1 kHz | Audio sample |
vid_pclk | 5.369318 MHz | Pixel output |
Address space
| Address | Target | Notes |
|---|---|---|
$0000–$1FFF | 2 KB WRAM | Four mirrors |
$2000–$3FFF | PPU registers | 8-byte mirrors |
$4000–$4017 | APU / OAM DMA / controllers | $4014 triggers OAM DMA |
$4018–$401F | Test / expansion | — |
$4020–$5FFF | Expansion space | — |
$6000–$7FFF | PRG RAM | Provided by the cartridge |
$8000–$FFFF | Cartridge PRG | Reset vector at $FFFC/$FFFD |
Top-level ports
module open6502_top ( input logic clk_21m, input logic rst_n, output logic vid_pclk, output logic vid_de, output logic vid_hsync, output logic vid_vsync, output logic [11:0] vid_rgb, output logic aud_valid, output logic signed [15:0] aud_sample, input logic [7:0] joy1, input logic [7:0] joy2, output logic [15:0] cart_addr, output logic [7:0] cart_wdata, input logic [7:0] cart_rdata, output logic cart_we, input logic cart_irq, output logic dbg_valid, output logic [63:0] dbg_payload );
Module responsibilities
| Module | File | Responsibility |
|---|---|---|
| CPU | cpu/open6502_cpu.sv | 2A03 profile, instructions, bus cycles, interrupts |
| PPU | ppu/open6502_ppu.sv | Registers, VRAM/CHR/OAM/palette, per-dot background and sprite composition |
| APU | apu/open6502_apu.sv | Two pulses, triangle, noise, frame sequencer, envelope, length, sweep |
| DMC | apu/open6502_dmc.sv | Sample address/length/rate/loop/IRQ/output and DMA requests |
| Bus | bus/open6502_bus.sv | Address decode, chip selects, peripheral arbitration |
| WRAM | bus/open6502_wram.sv | 2 KB main RAM and four-way mirroring |
| Mapper | cart/open6502_mapper.sv | Mapper 0/1/2/3/4/7 banking, mirroring, IRQ |
| OAM DMA | dma/open6502_oam_dma.sv | $4014 256-byte transfer and CPU stall |
| Clocks | clocks/open6502_clocks.sv | Reset sync, CPU/PPU/audio enables |
| Video | video/open6502_video_timing.sv | 341×262 NTSC timing and sync signals |
| Controller | input/open6502_controller.sv | Controller serial shift |
| DiffTest bridge | dbg/open6502_difftest_bridge.sv | Packs CPU/BUS/PPU/APU events |
For the full block diagram, ports and v0 scope, see docs/open6502-chip/architecture.md.
CPU: get function right, then cycles
open6502_cpu is a 6502 core in the 2A03 configuration. The current goal is official instructions plus stable undocumented behaviour; cycle-level bus behaviour is still being filled in.
Covered
- Official instruction set plus target-stable undocumented instructions; decimal ADC/SBC is implemented and covered by Klaus.
- Addressing: immediate, zero page, zero-page indexed, absolute, absolute indexed, indirect, indexed indirect and branches.
- Cycle-level bus actions: fetch, operand reads, dummy reads, RMW double writes, DMA stalls.
- Interrupts: NMI edge, IRQ level, APU frame IRQ, mapper IRQ; corrected BRK/RTI return address.
- Accumulator/memory shifts, JSR/RTS, PHA/PLA/PHP/PLP, INC/DEC/BIT, JMP indirect, CMP/AND/ORA/EOR/ADC/SBC.
Evidence
| Test | Result | Notes |
|---|---|---|
| Klaus 6502 functional | PASS · PC=0x3469 | Includes decimal ADC/SBC |
| NEMU Klaus | PASS | The reference model passes too |
| Directed testbenches | PASS | ADC, BRK, decimal, INC, IRQ, JMP ind, JSR, PHP, RMW, stack, ZP37 and more |
| NEMU/RTL DiffTest | PASS | Final state, PC trace, ALU/stack |
# Prepare the Klaus binary first; the default path is /tmp/klaus.bin $ KLAUS_BIN=/path/to/klaus.bin ./sim/klaus/run.sh
PC=0x3469 proves function, not cycle-level equivalence.
PPU: it draws, but it is not a dot pipeline yet
The PPU is both the largest block and the biggest accuracy gap. It renders the title frame and gameplay, but uses “per-dot generation + end-of-scanline sprite composition” instead of the real 2C02 fetch/shift pipeline.
Implemented
- CPU-visible
$2000–$2007registers, including$2007auto-increment. - Internal storage: CHR 8 KB, VRAM 2 KB, OAM 256 B, palette 32 B.
- Background pixels generated per dot, with coarse/fine X/Y scroll and nametable mirroring.
- Sprite overlay, priority, sprite 0 hit, scanline overflow and 8×16 mode.
- VBlank/NMI and frame output;
vid_rgbuses an RGB444 palette LUT.
Registers
| Address | Name | Current implementation |
|---|---|---|
$2000 | PPUCTRL | NMI, sprite size, background/sprite pattern tables, address increment |
$2001 | PPUMASK | Background/sprite/left-column clipping, grayscale and emphasis bits |
$2002 | PPUSTATUS | VBlank, sprite 0, overflow |
$2003 | OAMADDR | OAM address pointer |
$2004 | OAMDATA | OAM read/write |
$2005 | PPUSCROLL | Two-write X/Y scroll |
$2006 | PPUADDR | Two-write high/low address |
$2007 | PPUDATA | VRAM/palette read/write and auto-increment |
Accuracy gaps
- No complete background fetch/shift register pipeline; rendering is organised per dot/scanline.
- Sprite evaluation is approximate, not the 2C02's per-scanline OAM scan.
- MMC3 A12 filtering and IRQ timing are approximate.
- PPU open bus and
$2007palette read-back are not fully covered. - Storage is expanded into flip-flops, which is why it costs 975,919 generic cells; it must become BRAM before board bring-up.
Related tests: ppu_tb, ppu_pixel_tb, ppu_sprite_tb, ppu_scroll_tb, ppu_overflow_tb. Area work is in 14 Synthesis & area.
APU & DMC: four channels, one unarbitrated bus
The APU implements the 2A03's four channels, frame sequencer, length/envelope/sweep and $4015 status, producing 16-bit samples. DMC has its own sample and DMA request logic, but bus arbitration is still missing.
| Channel | Implemented | Tests |
|---|---|---|
| Pulse 1 / 2 | Duty, envelope, length, sweep, mute | apu_tb / apu_sweep_tb |
| Triangle | Linear counter, length, mute | apu_tb |
| Noise | LFSR, envelope, length | apu_tb |
| DMC | Rate, address, length, loop, IRQ, output, 4-cycle CPU stall | dmc_tb · arbitration incomplete |
| Frame sequencer | 4/5-step, frame IRQ, length/envelope clocks | apu_tb |
| Mixer | 16-bit samples, 44.1 kHz enable | apu_tb |
Output path
RTL outputs aud_valid and a signed 16-bit aud_sample; the FPGA wrapper provides a 1-bit sigma-delta audio interface. RTL has no desktop SDL frontend: frame capture works, but real-time listening still goes through NEMU or GEM6502.
DMC open items
- DMC bus arbitration: priority and insertion timing against CPU/PPU are not complete.
- DMA and CPU stall cycle alignment is still approximate.
- DMC sample address/length behaviour across page boundaries and loop edges lacks hardware alignment.
Bus & memory: 2 KB of WRAM and its mirrors
The bus handles address decode, chip selects and peripheral arbitration. It routes CPU reads and writes to WRAM, PPU, APU, DMA, controllers and the cartridge; every peripheral should expose unique, observable transactions.
WRAM
$0000–$1FFF is 2 KB of physical WRAM mirrored every 2 KB, four times. $2000–$3FFF is the PPU's 8-byte mirror. open6502_wram handles mirror decoding and adds no wait states.
OAM DMA
A write to $4014 starts a 256-byte OAM DMA: the engine copies from CPU address space into PPU OAM and stalls the CPU. Integration tests cover the $4014 trigger, transferred data and stall behaviour; exact bus phases still need alignment.
Controllers
open6502_controller implements the standard serial shift: a write to $4016 latches, then eight reads return A/B/Select/Start/directions. The two ports are independent. Tests cover button order and the stable bits.
Known gaps
- “Every peripheral has a unique bus transaction” is not fully covered.
- Priority when OAM DMA and DMC DMA request at the same time is not verified.
- Exact CPU access timing to PPU registers (read/write latency, open bus) is approximate.
Cartridge & mapper: 0/1/2/3/4/7
RTL mappers cover NROM, MMC1, UxROM, CNROM, MMC3 and AxROM. They handle PRG/CHR banks, mirroring, PRG RAM and IRQ; MMC3 A12 filtering remains approximate.
| Mapper | Name | Key behaviour | Status |
|---|---|---|---|
| 0 | NROM | Fixed PRG/CHR, no banking | Pass |
| 1 | MMC1 | Serial shift register, PRG/CHR banks, mirroring | Basic |
| 2 | UxROM | PRG bank switching | Basic |
| 3 | CNROM | CHR bank switching | Basic |
| 4 | MMC3 | Banks, PRG RAM, scanline IRQ | A12 approximate |
| 7 | AxROM | 32 KB PRG banks, single-screen mirroring | Basic |
How ROMs enter RTL
- NEMU loads iNES directly and supports mapper 0/1/2/3/4/7.
- RTL simulation:
sim/game/extract_ines.pyturns iNES into Verilog$readmemhimages for PRG/CHR. - FPGA (future): load iNES from SPI Flash/SD into SRAM/BRAM, or use a physical cartridge connector.
file-fixers.nes and stallar.nes are the key MMC3 regression samples. Running does not mean A12/IRQ timing is exact.
Video, input and clocks: the last analogue edge
The digital side outputs 341×262 NTSC timing, RGB444 pixels and 44.1 kHz audio. Analogue video/audio and physical controller ports are left to the FPGA board or external DACs.
| Item | Current implementation | Notes |
|---|---|---|
| Scan timing | 341 dots × 262 lines | vid_pclk / de / hsync / vsync |
| Pixel format | RGB444 | Internal palette index through a LUT |
| Frame rate | NTSC, ~60 Hz | Simulation driven by the frame loop |
| Audio | 16-bit PCM / σΔ | FPGA wrapper provides 1-bit sigma-delta |
| Input | Two standard controllers | Serial shift, joy1/joy2 |
| FPGA output | Wrapper exists | No bitstream, no board validation |
FPGA wrapper
fpga/open6502_fpga_top.sv wraps VGA and sigma-delta audio, but full synthesis, BRAM inference, timing constraints and board bring-up are not done. Artix-7/Nexys A7 class is a planning target, not a verified result.
Clock strategy
No free-running multiple clocks: one clk_21m plus enables. CPU/PPU/APU relative phase is therefore deterministic in simulation and after synthesis, which makes tick-aligned DiffTest possible. The cost is enable discipline; any write missing its enable repeats across all 12 21 MHz cycles.
cpu_ce, so one CPU store committed on all 12 master clocks and $2006/$2007 writes landed wrong. The title frame only matched NEMU after the fix.
Verification: evidence, not slogans
Verification has eight levels: package/decode unit tests, CPU + bus, PPU frames, APU samples, mapper, full games, FPGA board validation, and L8 formal verification. The strongest evidence today is L0–L2, a single L3 frame, and the 19 instruction refinement proofs at L8.
| Level | Object | Method | Status |
|---|---|---|---|
| L0 | package / decode / counters | SystemVerilog unit tests | PASS |
| L1 | CPU / PPU / APU blocks | Directed tests + vectors | PASS |
| L2 | CPU + bus | Klaus, nestest, DiffTest | Klaus PASS nestest not wired up |
| L3 | PPU + CPU | PPU ROMs, frame hashes | Single frame |
| L4 | APU | apu_test, DMC, sample hashes | Block level |
| L5 | Mapper | Bank/IRQ test ROMs | Basic |
| L6 | System | Open-source games, hardware | 6 ROMs run |
| L7 | FPGA | Board video/audio/input | Not started |
| L8 | CPU ISA ↔ RTL FSM | Lean 4 refinement proofs | PASS · 19 instructions |
Current regression results
| Check | Result | Command / location |
|---|---|---|
| RTL lint | PASS | cd rtl && make lint |
| RTL unit/integration tests | 28 PASS | cd rtl && make sim |
| RTL Klaus | PASS · PC=0x3469 | sim/klaus/run.sh |
| NEMU/RTL final state | PASS | sim/difftest/run.sh |
| NEMU/RTL PC trace | PASS | sim/difftest/run.sh |
| NEMU/RTL ALU / stack | PASS | sim/difftest/run_alu.sh |
| Lean formal model | PASS · 151 opcodes | cd formal && lake build |
| FALLING title frame | SHA match | sim/game/run.sh |
| FALLING post-START frame | Rendered | 01 Quickstart |
Still missing
| Test suite | Coverage | Status |
|---|---|---|
| Klaus 6502 functional | Official instructions and flags | PASS |
| nestest | Instruction/cycle golden log | Not wired up |
| instr_test-v5 / instr_misc | Undocumented instructions | Not wired up |
| cpu_timing_test6 | Cycle-level CPU | Not wired up |
| cpu_interrupts_v2 | NMI/IRQ/BRK timing | Not wired up |
| ppu_vbl_nmi / sprite_hit / overflow / open_bus | PPU edge cases | Partial |
| apu_test / apu_reset / DMC | Audio accuracy | Partial |
| 240p Test Suite | Video and sync | Not wired up |
| Multi-game lockstep DiffTest | System-level consistency | Not wired up |
Formal verification (L8)
formal/ writes the CPU's ISA specification and a cycle-level model in Lean 4, then proves the model implements the specification: the 151-opcode decode matches the RTL dispatch; ADC/SBC (including BCD), CMP, shifts and BIT hold for all 8-bit operands; 19 instructions have mrun n m = step m refinement theorems; 15 executable program tests are run by the kernel itself; and 4 programs agree with the real RTL in co-simulation. The method follows CktFormalizer/CktLean: typed hardware representation → kernel proofs → SystemVerilog/JSON extraction → an RTL consistency gate.
Run: cd formal && lake build (about 15 s, no sorry); make check-rtl check-cosim runs the RTL cross-check and co-simulation. Entry point: formal/README.md. Known limits: cycle counts follow the current RTL (no page-cross penalty) and IRQ/NMI entry/reset are not refined yet.
Release gates
A v0 FPGA prototype needs at least: Klaus, PPU VBlank/NMI/sprite 0, four APU channels, mapper 0/1/2/3/4/7, six playable open-source ROMs, and a passing CPU + frame-level DiffTest. ASIC adds DFT, timing closure, power, package and hardware alignment.
DiffTest: make two implementations testify
The goal is to compare observable DUT (RTL) and REF (NEMU) state under identical input, from instructions and bus transactions to scanlines, frame hashes, audio samples and mapper state. It cannot prove RTL matches real NES hardware; it only proves RTL matches REF.
Event record
typedef struct packed {
logic valid;
logic [1:0] kind; // 0=cpu, 1=bus, 2=ppu, 3=apu
logic [63:0] tick;
logic [15:0] addr;
logic [7:0] data;
logic we;
logic [7:0] source;
} open6502_dbg_event;
Sync points
| Granularity | RTL | REF | Compare |
|---|---|---|---|
| Instruction | cpu_retire | cpu_step | PC / A / X / Y / SP / P / cycles |
| Bus | bus_event | bus trace | addr / data / we / tick |
| Scanline | ppu_scanline_end | PPU state | v / t / x / w / OAM / status |
| Frame | frame_end | framebuffer | frame hash |
| Audio | aud_valid | APU samples | sample hash / tolerance |
| Mapper | cart_event | mapper state | bank / IRQ / PRG RAM |
Modes and budget
cpu-only: Klaus/hello first, zero mismatches before anything else.frame-only: per-frame hash, good for NROM games.scanline: PPU state level, for test ROMs.audio: per-sample or hash tolerance.full: bus + PPU + APU + mapper.
Performance budget: Verilator + REF at least 106 cycles/s; stop at the first mismatch and keep a window around it. FPGA compares frames/hashes only; dot-level comparison stays in simulation.
Golden frames and hashes: read before changing output
Golden hashes anchor the regression. Any change that alters output must explain why the hash moved; never update the hash just to make a test pass.
| Object | Hash / value | Scope |
|---|---|---|
| RTL title frame | 41e8ebc137e3b8ede2f0adf915956fb9454346e9454e358c6dad2ee5a58f5a33 | FALLING, 256×240, same as NEMU |
| NEMU title frame | 41e8ebc137e3b8ede2f0adf915956fb9454346e9454e358c6dad2ee5a58f5a33 | Same, byte-identical |
| REF 60-frame frame hash | 67667b1cbc4c1cf3 | Bundled NROM game, REF/frontend parity |
| REF 60-frame audio hash | e78422afbcb92ac3 | Same |
| RTL Klaus end point | PC=0x3469 | Functional test, not cycle test |
Reproduce
$ ./NEMU/build/6502EMU --headless --no-audio --frames=300 \ --screenshot=/tmp/nemu-title.ppm roms/falling.nes $ ./sim/game/run.sh roms/falling.nes /tmp/rtl-title.ppm $ shasum -a 256 /tmp/nemu-title.ppm /tmp/rtl-title.ppm
41e8… comes from its own capture tooling; the comparison on this site uses the same pixel data.
GEM6502: being rewritten, do not overrate it
GEM6502 targets a gem5-style, event-driven architecture and timing platform: clock domains, resource contention, DMA arbitration, checkpoints, causal statistics and independent RTL calibration. The current implementation is still a legacy instruction-driven functional/cycle model.
| It can do now | It cannot do yet |
|---|---|
| Load NROM PRG, run instructions, print registers/cycle stats | No completed timing CPU, timing bus or calibrated chip profile |
| SDL player, PPM frames, MMC3 game regression | The event queue does not drive normal execution yet; not a chip-level timing model |
| Compare traces against NEMU | Not a pre-silicon signoff or RTL timing substitute |
$ cd GEM6502 $ make $ make test $ ./gem6502 run /tmp/gem-demo.bin 1000 $ ./gem6502 stats /tmp/gem-demo.bin $ ./gem6502 play ../roms/stallar.nes
Target specification (Chinese): requirements.md; architecture and coding rules: coding-guide.md. Those documents describe target capabilities, not implemented features.
Synthesis & area: 1.02M generic cells
Per-module synthesis uses Yosys 0.60 with read_verilog -sv -DSYNTHESIS → hierarchy → synth -flatten -noabc → stat. -noabc is used because the full PPU combinational renderer is too large for ABC mapping; the counts are generic cells.
$ yosys -s rtl/scripts/synth_open6502.ys
| Module | Generic cells | Notes |
|---|---|---|
open6502_cpu | 4,138 | Small |
open6502_apu | 1,855 | — |
open6502_dmc | 828 | — |
open6502_mapper | 745 | 6 mappers |
open6502_oam_dma | 154 | — |
open6502_wram | 37,003 | Flip-flop implementation |
open6502_bus | 171 | — |
open6502_clocks | 360 | — |
open6502_video_timing | 164 | — |
open6502_controller | 19 | — |
open6502_difftest_bridge | 65 | — |
open6502_ppu | 975,919 | Dominant |
| Hierarchical sum | 1,021,421 | — |
PPU breakdown
Most of the area is the expanded chr[8192], vram[2048], oam[256] and pal[32] storage plus per-pixel/attribute mux trees. An FPGA flow must map them to BRAM and shrink the combinational sprite scan.
Caveats you must read together
- These are generic-cell estimates, not placed-and-routed area.
SYNTHESISskips memory reset loops; simulation still initialises them.SYNTHESISlimits the PPU sprite scan to 8 sprites for runtime; simulation scans all 64.- Full top-level flatten did not finish within 600 seconds; the table is a per-module sum, not one flattened result.
- No timing closure, LUT mapping, BRAM mapping or ASIC standard-cell mapping has been done.
55nm planning estimate
| Scenario | Die area | Notes |
|---|---|---|
| Current RTL, flip-flop memories | 4–7 mm² | Not acceptable |
| SRAM + PPU refactor | 1.2–2.0 mm² | Planning target |
| Recommended planning value | ~1.5 mm² | Used for the cost model |
At 1.5–2.0 mm² and 55nm, unit cost at volume is roughly USD 0.3–0.7 (die + package + test), with mask/NRE around USD 150k–400k+. These are planning numbers, not quotes.
Toward 55nm: four gates, no skipping
The roadmap is not a schedule; it is an acceptance order: NEMU → RTL → FPGA → 55nm ASIC. A later stage may not hide an earlier failure. Without FPGA validation, physical design should not start.
| Stage | Purpose | Current status | Exit gate |
|---|---|---|---|
| 1. NEMU | Playable reference model | Working | Games playable, Klaus PASS, golden frames stable |
| 2. RTL | SystemVerilog SoC | Functional prototype | Multi-game frame match, no unexplained divergence, deterministic regression |
| 3. FPGA | Real board prototype | Not started | Bitstream runs a game; video/audio/input stable |
| 4. ASIC | 55nm tapeout | Planning | Timing/DFT/DRC/LVS clean; shuttle and funding secured |
Before RTL → FPGA
- Add bus transaction strobes for every peripheral.
- Make CPU cycle timing accurate enough for NMI/DMA-sensitive games.
- Replace PPU flip-flop storage with BRAM-friendly arrays.
- Rewrite sprite selection as a sequential scan.
- Rewrite background rendering as a fetch/shift pipeline.
- Complete DMC bus arbitration.
- Add deterministic frame-index DiffTest.
- Complete full-SoC synthesis and timing constraints.
Before FPGA → ASIC
- Replace BRAM with 55nm SRAM macros.
- Insert DFT/scan and set coverage targets.
- Define clock/reset/power intent.
- Synthesize with the 55nm standard-cell library.
- Run place-and-route and timing closure.
- Run DRC/LVS clean.
- Define package, pad ring and ESD.
- Secure a foundry shuttle and funding.
Troubleshooting: find your symptom first
These are the most common failures. First decide whether you are running NEMU, GEM6502 or RTL — their dependencies and outputs are completely different.
1. SDL2 not found, or sdl2-config missing
NEMU and the GEM6502 player need SDL2. The CLI can build without it, but play, the window and audio will be missing.
$ brew install sdl2 # Debian/Ubuntu: $ sudo apt install -y libsdl2-dev
If it is installed but still not found, make sure sdl2-config --cflags --libs is on PATH. GEM6502's Makefile probes it through that command and falls back to a no-UI build.
2. Verilator link fails with Undefined symbols ... __cxa_*
This is a known macOS mismatch between Verilator-generated code and the C++ runtime. The repo scripts explicitly select clang++, the macOS SDK and Homebrew LLVM's libc++. If your LLVM version differs, find the real path and override it:
$ ls /opt/homebrew/Cellar/llvm/*/lib/c++ $ LIBCXX_DIR=/opt/homebrew/Cellar/llvm/<version>/lib/c++ \ ./sim/game/run.sh roms/falling.nes /tmp/falling-rtl.ppm
If you only need functional verification, use Icarus first: cd rtl && make sim avoids Verilator's C++ link path.
3. make sim is slow and noisy
It compiles and runs 28 testbenches, so it is not a silent command. Run make lint first to rule out syntax errors, then redirect: make sim > /tmp/rtl-sim.log 2>&1 and finish with grep -i fail /tmp/rtl-sim.log.
4. The game runs but stays on the title screen
Most ROMs need START, not any key. NEMU's default START is V and Select is C; the GEM6502 player uses Enter / Backspace. Make sure the window has focus and the player is not paused (press P in GEM6502).
5. No sound
Check that you did not pass --no-audio (the headless screenshot commands do). GEM6502 needs an SDL2 audio device; on Linux check ALSA/PulseAudio. If opening the device fails, the player prints the SDL error and continues without audio by design.
6. RTL has no window and no sound
RTL is an SoC simulation, not a desktop emulator. It captures PPM frames through Verilator and has no SDL frontend; audio is 16-bit samples/sigma-delta only. To play on a desktop, use NEMU or GEM6502.
7. My SHA does not match the docs
Compare pixels before file bytes: PPM headers can differ between tools. Convert both to PNG and compare pixels, or generate with the repo's own capture scripts. The hashes in the docs come from the repository toolchain; confirm the format before comparing across tools.
8. Pillow is missing, so PPM → PNG fails
On macOS use sips -s format png /tmp/frame.ppm --out /tmp/frame.png, or install Pillow with python3 -m pip install Pillow. If you only want to look at an RTL frame, Preview can open PPM directly.
Still stuck?
When filing an issue, include: OS and version, the exact command, the full error, clang --version / verilator --version, and which path you are on (NEMU / GEM6502 / RTL). Use the GitHub issue or PR template; specific information gets reproduced faster.
Contributing: start with a verifiable small problem
Workstreams
| Workstream | Typical tasks | Entry point |
|---|---|---|
| CPU / bus | Cycle timing, NMI/DMA interaction, bus strobes, Klaus/nestest | rtl/cpu/, rtl/bus/ |
| PPU | Fetch/shift pipeline, sprite evaluation, open bus, mirroring, frame comparison | rtl/ppu/ |
| APU / DMC | Frame sequencer, sweep/envelope edges, DMC arbitration | rtl/apu/ |
| Cartridge / mapper | Bank/IRQ timing, MMC3 A12, iNES/NES 2.0 | rtl/cart/ |
| FPGA | Yosys synthesis, BRAM inference, timing, VGA/HDMI, audio | rtl/fpga/ |
| ASIC / 55nm | SRAM, DFT, clock/reset/power, package | docs/55nm-tapeout-roadmap.md |
| Software / CI | Lockstep DiffTest, frame index, CI, repro scripts | sim/ |
Before you submit
$ cd rtl $ make lint $ make sim $ cd .. $ ./sim/difftest/run.sh $ ./sim/difftest/run_alu.sh
- Use English commit messages and English repository docs; keep changes small and reversible.
- Add/update tests before changing RTL behaviour; state the verification evidence in the PR.
- Do not change golden hashes to “fix” a test; do not delete tests to make a change pass.
- Prefer forward fixes over reverts.
- No commercial ROMs, BIOS files or proprietary PDK data.
Good first issues
- Add a unit test for PPU
$2007palette read behaviour. - Add frame-index assertions to
sim/game. - Add a controller A/B/Select/Start order test.
- Rewrite sprite selection as a sequential scan to remove the big combinational mux.
- Add deterministic frame-hash output to DiffTest.
Further reading: find docs by goal
Repository docs are maintained in English; this page is the navigable version. When you finish here, the next step is usually one of these source documents.
docs/, or open a PR against this page's source. Documentation needs reproducible evidence just like code.