Three CPU systems built from scratch on a 6,272-logic-element entry-level FPGA. This post records the whole process, quantifies the efficiency gains, and — most importantly — the traps the agent actually fell into.

1. Experimental Setup

Hardware

ItemValue
BoardEntry-level Cyclone IV dev board
DeviceEP4CE6F17C8 — 6,272 LE / 392 LAB / 30×M9K (276,480 bit)
Clock50 MHz
PeripheralsVGA (640×480@60), 32MB SDRAM, USB-UART, 4×LED, 4×buttons
ProgrammerUSB-Blaster compatible

Toolchain (final form)

StageToolConfig / Role
Synthesis & place-and-routeQuartus Prime Lite 20.1.1Running in a QEMU full-system x86-64 VM (Ubuntu 22.04); one build takes 230–530 s
Logic simulationVerilator 5.052--cc --exe --build --public; 2M cycles in about 0.5 s
FlashingopenFPGALoader ≥ 1.1.1Over SSH on a separate Linux host; -c usb-blaster
6502 assemblycc65 2.19 (ca65 / ld65)-t none + custom NROM-128 linker script
RISC-V buildxPack riscv-none-elf-gcc 15.2.0newlib included, builds NEORV32 firmware
Version controlgit14 commits, 5 hardware-verified bitstreams

Three key choices and what they cost:

  • Quartus runs in a QEMU full-system VM, not Docker — native x86-64 kernel semantics. Slow to compile but correct (230–530 s), and the only reliable path on Apple Silicon.
  • Verilator instead of iverilog for simulation — roughly 1000× faster on the same workload, shrinking “edit a line → see the result” to seconds.
  • Flashing goes through a separate Linux machine — synthesis in the VM, flashing on the physical host, no interference between the two.

2. What Was Built

System 1: NEORV32 (RISC-V soft core)

Verified: running lights, UART hello, 7-segment display, system monitor.

System 2: MOS 6502 + VGA text

  • 80×30 character VGA (640×480@60)
  • UART echo
  • Displays “Hello from MOS 6502 …” (UART + VGA)

System 3: NES (6502 + PPU)

This was the main battlefield. Final state:

PhaseScopeStatus
P0Background tile rendering, scrolling ($2005), NMI, OAM registers✅ hardware
P1Sprite rendering, H/V flip, sprite-0 hit, sprite priority, $4014 OAM DMA, 8×16 mode, palette selection✅ hardware (all 8)
P2Palette RGB565→VGA path, $3F00-$3F1F reads, nametable/attribute reads✅ hardware/sim
P2 remainder2-bit framebuffer (4 colors), 4 nametables🚫 out of memory
P3Dot-level 341×262 timing🚫 architectural

Also: a full 32MB SDRAM space scan with zero errors.

3. Efficiency Gains from the Agent (the Quantifiable Part)

3.1 Simulation iteration: from minutes to seconds

SimulatorTime for 2M cycles
iverilog> 500 s (2 ms simulated time)
Verilator0.5 s

About 1000×. This isn’t something only an agent can do, but one behavior matters: the agent actively looks for faster verification. When it first noticed iverilog was too slow, switching to Verilator turned the “edit a line → verify” loop from “go do something else and come back” into “know the answer instantly”.

3.2 End-to-end automation

The manual flow (5 steps, easy to slip up):

tar the project → generate MIF → Quartus build → scp the file → openFPGALoader flash

Collapsed into one command:

scripts/nes_build_flash.sh [rom.nes]

This doesn’t save a few seconds — it eliminates silent errors like “using a stale intermediate file”. Mid-experiment, chr.mif was generated from the wrong source (the .nes linker padding instead of chr.bin), which cost several rounds of pointless debugging.

3.3 Cross-file, cross-tool “memory”

Key facts that coexisted in this project:

  • 42 SDRAM pin assignments
  • 30+ VGA/LED/button pins
  • Three projects, each with its own toolchain and build scripts
  • Two flashing paths (local Mac / remote Linux)
  • A dozen verified design constraints (“the framebuffer must be single-write-port”, etc.)

A human engineer has to maintain notes; an agent’s advantage is that these constraints remain queryable in context, so it doesn’t “forget why the code looks like this three days later”.

3.4 Willingness to do exhaustive debugging

The $4014 DMA bug took 25 rounds. Along the way the agent:

  • Traced AB/DO/WE cycle by cycle
  • Tried 4 trigger schemes (level / edge / address+WE / address latch)
  • Expanded OAM from 32 bytes to 256 bytes
  • Recorded how the symptom changed each time

A human would very likely have given up around round 8, or simply accepted “this feature is broken”.

4. The Traps the Agent Fell Into (This Is the Point)

If I only wrote down the successes above, the post would be worthless. The failure modes are what’s worth recording, because they repeat.

Trap 1: Trusting an unreliable verification tool

For a long stretch mid-project I believed “simulation shows OAM is all zeros”, concluded “sprite rendering is broken”, and went to rewrite the renderer.

The truth: Verilator returned wrong values when reading the oam array hierarchy in this design; the UART dump only printed some sprite rows; and the VGA screen had been showing complete sprites all along.

The resulting reliability ranking:

Verification methodReliabilityProblem
Watching the VGA screen⭐⭐⭐The only fully trustworthy one
UART dump⭐⭐Only prints part of the data
Verilator simulation⭐Unreliable reading the oam array hierarchy

Lesson: when simulation disagrees with hardware, suspect the tool first, not the design.

Trap 2: Reusing stale build artifacts

Three times I drew wrong conclusions from “a binary that hadn’t been updated”. The most typical: after fixing the trigger condition I reran oamdbg and it still showed all zeros — because it ran the old executable.

Lesson: check the artifact timestamp or rebuild before every verification.

Trap 3: Verilator accepting code that Quartus rejects

Two examples:

(1) Multiple drivers

always @(posedge clk) chr_addr <= ...;   // background pass
always @(posedge clk) chr_addr <= ...;   // sprite pass
  • Verilator: compiles fine (last assignment wins), behavior looks normal
  • Quartus: Error (10028): Can't resolve multiple constant drivers

This produced the illusion of “simulation passes, synthesis fails”, wasting two rounds.

(2) Read-modify-write inside memory

if (fb_we) fb[fb_waddr] <= fb_wdata;
if (sp_we) fb[sp_waddr] <= fb[sp_waddr] | sp_wdata;   // read-or-write-back

Quartus couldn’t map it to M9K and tried to expand it into logic → synthesis hung for 26 minutes. Rewriting it as a single write port plus an OR computed from a read register cut synthesis to 234 s.

Lesson: simulation only verifies function; the synthesizer is the hardware truth. Any “two always blocks driving the same signal” or “in-memory RMW” should be checked proactively.

Trap 4: Making several coupled changes at once

The first attempt at 8×16 sprite mode failed. The idea wasn’t wrong — I changed 5 things at once:

  • sp_pix bit allocation
  • OAM index width
  • CHR address calculation
  • Visibility test
  • Termination condition

Any one mistake breaks the whole thing, with no way to localize it. The second attempt implemented the feature without enabling it (ROM stayed 8×8), verified no regression, then turned it on — success on the first try.

Lesson: change one thing at a time, verify each. This isn’t agent-specific, but agents are more prone to it precisely because “it can change many places at once”.

Trap 5: 64 rounds without version control

The first 64 rounds had no git. Result: when a working version was broken by later edits, there was no way to roll back.

The device state was eventually restored from a leftover .svf bitstream in /tmp — but the corresponding source code was lost forever.

After git was introduced at round 65, the behavior changed immediately:

  • Breakage → git checkout
  • A commit at every milestone
  • 5 hardware-verified bitstreams committed

Lesson: version control should be step one, not step fifty.

Trap 6: Not doing the feasibility math early

I only did the memory budget after round 55:

Total:           276,480 bit
Used:            229,504 bit (83%)
Free:             47,000 bit
2-bit framebuffer delta: 61,440 bit   →  over by 14,000 bit  ❌

That calculation takes 5 minutes. Done early, it would have shown that the 4-color P2 plan was impossible from the start — no repeated attempts needed.

Lesson: do the resource budget before planning features. FPGA LE / M9K / pins are hard constraints, not “get it back with some optimization”.

5. Anatomy of a 25-Round Bug

Worth telling separately, because it shows both the agent’s strengths and weaknesses.

Symptom

NES sprites are populated through $4014 OAM DMA. After implementing the DMA controller:

  • Sprites disappeared
  • Probes showed the DMA datapath was fully correct (ram_q read 10 01 00 20)
  • Probes also showed OAM briefly holding correct values during DMA (ff → 10)
  • Yet OAM ended up all zeros

Wrong hypotheses, round after round

RoundsHypothesisResult
45–48Trigger condition wrong (WE timing)Switched to pure address trigger, still failed
49–52Datapath problemProbes proved the data correct, hypothesis dead
53–57OAM reset init blocking writesRemoved it; OAM became 0xFF, still no sprites
58–60CPU and DMA fighting over RAMAdded RDY stalls, still failed
61–70Sprite renderer brokenRewrote the renderer, no effect

The truth

DMA copied 256 bytes, but OAM is only 32 bytes.

The address wrapped 8 times, and the final 32 writes (RAM[$02E0..$02FF], uninitialized zeros) overwrote every correct write before them.

// wrong
if (dma_idx == 8'd255) begin dma_act <= 1'b0; end   // 256 bytes
// right
if (dma_idx == 8'd31)  begin dma_act <= 1'b0; end   // OAM is only 32 bytes

One constant — and the sprites appeared immediately.

Why it was so hard to find

Because everything the probes showed was correct. Data correct, trigger correct, write-enable correct, OAM intermediate values correct.

It’s a classic buffer-overflow-shaped bug: the result is decided by the last write, while every intermediate step was fine.

How the agent performed

  • Strength: it didn’t give up — 25 rounds of experiments and notes
  • Weakness: it never did the basic sanity check (“DMA length vs OAM capacity”), which would have found it in 5 minutes on round one

6. A Methodology for “FPGA Development with an Agent”

Based on this 97-round experiment, the process I’d recommend:

Must-do (in order)

  1. Set up git first; the first commit is a “compiles and runs” baseline
  2. Budget resources (LE / M9K / pins) before planning features
  3. Be careful using simulation as the final judge — it’s good for logic errors, bad for synthesis issues and memory behavior
  4. Change one thing at a time, commit each separately
  5. Confirm the artifact is fresh before every verification
change one thing → simulate (seconds; catch logic errors)
                 → synthesize (minutes; catch structural errors)
                 → run on hardware (human observation; catch real behavior)
                 → git commit

The three stages catch non-overlapping classes of problems:

StageCatchesMisses
SimulationLogic, timing, state machinesSynthesis feasibility, M9K inference, real timing
SynthesisMultiple drivers, RAM inference, over-limit resourcesOn-hardware behavior
HardwareEverythingRequires human observation

Concrete advice for working with agents

  • Explicitly require the agent to do the resource math before writing code
  • Require each change to be verified on its own — forbid “change five places, then test”
  • When simulation and hardware disagree, make the agent trust the hardware
  • Have the agent record every failed hypothesis (in this experiment, the record of failed hypotheses is what eventually pointed at the root cause)

7. Conclusion

The efficiency gain is real, but not free

DimensionChange
Simulation iteration1000× (iverilog → Verilator)
Build/flash5 manual steps → 1 command
Context upkeepA dozen design constraints always queryable, never forgotten
Exhaustive debugging25 rounds without giving up

But at the same time:

ProblemCost
Trusting unreliable verification~20 rounds wasted
No version controlA working version lost forever
Changing many things at once2 rounds of wasted attempts
No early resource mathRepeated attempts at something impossible

Final verdict

Where the agent stands in FPGA development:

  • ✅ Extremely strong: cross-file information integration, toolchain setup, long-term consistency, exhaustive debugging
  • ⚠️ Needs human constraints: change granularity, choice of verification methods, resource-budget awareness
  • ❌ Irreplaceable: hardware observation (what the VGA screen actually shows)

In this experiment, the decisive breakthroughs all came from human observation:

“VGA stably shows A E P0 OK” “Background only, no text” “Blue background confirmed”

Each one pulled the agent out of a wrong simulation conclusion.

So the most effective mode is not “agent replaces human”, but “agent does the exhaustive search, human provides the ground truth”.

Appendix: Experiment Data

ItemValue
Target rounds97
git commits14
Verified bitstreams5
Documentation824 lines
Longest single bug hunt25 rounds
Longest synthesis time26 minutes (hung; later fixed to 234 s)
Final utilization2,374 LE / 6,272 (38%), 231,424 bit / 276,480 (84%)

Get the next essay

New essays on products, business and tech — plus what the experiment's numbers actually say.