DOOM, computed by curl
There's a fine tradition of running DOOM on things that shouldn't run DOOM: calculators, pregnancy tests, a Lego brick. Someone has also put DOOM behind curl. In that project the game runs on a server and curl just carries the pixels to your terminal.
I wanted to go one step further and make curl the CPU.
So that's what this is: a RISC-V (RV32IM) computer where each instruction DOOM executes, multiplies and divides included, is one curl -K next.cfg process. That process reads and writes small files on a RAM disk. No server, no interpreter and no shell arithmetic ever touches the machine's state. Everything is computed by curl's config parser.
It's slow. A gameplay frame takes about 40 minutes. It's also correct: every frame curl has produced so far is bit-identical to what a normal emulator produces.
How this was made
I didn't write the code for this, and I'm not going to pretend I did. The idea and the brief were mine, and so were the calls along the way, like adding multiply/divide and building a stripped-down curl. Everything else was written by Claude, Anthropic's AI model, working in Claude Code: the table generator, the step templates, the reference emulator, the simulator, the tests and the measurements. That includes the hosting setup and most of this post. Every commit in the repository says so.
What made that workable is the same thing that makes the result believable: nothing is taken on trust. Every claim below is checked by an independent implementation, and every frame curl produces is compared, hash for hash, against one computed another way.
The rules
"curl runs DOOM" is easy to fake, so the project started with rules, before any code was written:
- The driver is a clock. A bash loop runs
curl -K next.cfgover and over. It never reads machine state and never branches on it. It only checks for a pause or stop file and counts its own iterations. - curl chooses the next instruction. Each step writes
next.cfgitself, so curl decides what the next process will do. - All branching happens through file lookups. Instruction decode, carries, comparisons, branch targets: every decision is a file whose path was built from machine state.
- Observers are read-only. The web page and status tools only read files.
- Any shortcut is disclosed. More on this one below.
Here's the entire "CPU loop", minus the status bookkeeping:
while :; do
[[ -e ctl/stop ]] && break # the machine executed ebreak
[[ -e control/stop ]] && break # I pressed stop
[[ -e control/pause ]] && { sleep 1; continue; }
curl -q -K next.cfg || exit 3 # a non-zero exit is a machine fault
done
The trick: curl's config file is a programming language (sort of)
Two curl features make this possible.
--variable and --expand-variable (curl 8.3+). A variable can be loaded from a file (name@path), and an expand-variable line can use earlier variables in the path it reads from. So each line of a config file can be a lookup whose address depends on the previous lookups.
Byte ranges on variables (curl 8.12+). x[2-3]=... keeps only characters 2 to 3. That's a substring operation with no string functions involved. The range itself can come from a variable, which matters later.
curl evaluates all of these variables while it parses the config, before any transfer starts. A config file is therefore a straight-line program of dependent table lookups. That turns out to be enough to build a computer.
The machine is a directory
All machine state lives in files on a RAM disk, one file per 32-bit word, each holding 8 hex digits:
cpu/pc 80040bf0
cpu/r/05 0000002a
mem/80/01/2a/fc the word at address 0x80012afc
All of memory is files: code, data, heap, stack, the framebuffer and the 4 MB shareware WAD. That's about 2.4 million files.
The ALU is lookup tables. lut/adc/0/7f/01 holds 080: carry 0, and 0x7f + 0x01 with no carry in gives 0x80. Adding two 32-bit registers means four of those lookups, each one using the carry from the previous byte in its path. There are 764,341 table files in total: add, subtract, and/or/xor, compare, shift funnels, register decode, a little automaton that decodes the next instruction, and so on.
One instruction, one curl process
Here's the real add step, trimmed a bit. Every line is a file read whose path came from earlier lines:
# fetch: read the pc, cut it into bytes, read the instruction word
expand-variable "pc@cpu/pc"
expand-variable "p0[6-7]={{pc}}"
expand-variable "p1[4-5]={{pc}}"
expand-variable "p2[2-3]={{pc}}"
expand-variable "p3[0-1]={{pc}}"
expand-variable "in@mem/{{p3}}/{{p2}}/{{p1}}/{{p0}}"
# decode: register numbers from tables keyed by instruction digits
expand-variable "rs1@lut/reg/{{h3}}{{h4}}"
expand-variable "a@cpu/r/{{rs1}}"
expand-variable "rs2@lut/reg2/{{h1}}{{h2}}"
expand-variable "b@cpu/r/{{rs2}}"
# execute: a byte-wise carry chain through the adc table
expand-variable "rt0@lut/adc/0/{{a0}}/{{b0}}"
expand-variable "r0[1-2]={{rt0}}"
expand-variable "rc0[0-0]={{rt0}}"
expand-variable "rt1@lut/adc/{{rc0}}/{{a1}}/{{b1}}"
...
# next pc (pc + 4, through tables again), then decode the NEXT instruction
expand-variable "k0@lut/dfa/s/{{nb0}}"
expand-variable "k1@lut/dfa/{{k0}}/{{nb1}}"
expand-variable "k2@lut/dfa/{{k1}}/{{nb2}}"
expand-variable "k3@lut/dfa/{{k2}}/{{nb3}}"
# commit: copy the next instruction's template to next.cfg...
expand-url "file:///proc/self/cwd/tpl/k/{{k3}}.cfg"
output "next.cfg"
# ...and write the results
expand-write-out "{{wr}}{{r3}}{{r2}}{{r1}}{{r0}}%output{cpu/pc}{{zv3}}{{zu2}}{{zq1}}{{zq0}}"
The last three lines are where curl "chooses" its next step. The decoder automaton walks the next instruction's four bytes and lands on a template name (add, lw, beq, illegal...). The step's single transfer copies tpl/k/<that name>.cfg over next.cfg. Then --write-out with %output{file} writes the destination register and the new pc. The driver just runs next.cfg again.
Even the destination register is a lookup. lut/wr/05 contains the text %output{cpu/r/05}, and writes to x0 go to a sink file nobody reads.
Branches work by computing both possible next-pc values, gluing them together as FALLTHROUGH‖TARGET, and slicing with a range that a comparison table returned: 0-7 or 8-15. A branch without a branch.
Multiply sums byte products from lut/mul through the same carry tables. Divide is restoring division unrolled into 32 rounds of shift, subtract, and a table that picks which remainder to keep. A div is 354 file lookups in one curl process. Division by zero and INT_MIN / -1 come out exactly as the RISC-V spec requires, without a single special case.
An average DOOM instruction costs 21.8 lookups, and there are 51 templates: the 45 RV32IM instructions plus fence, ecall, ebreak, boot, halted and illegal.
Talking to DOOM
The guest is doomgeneric compiled with clang for rv32im against picolibc, with a tiny platform layer:
- no system calls at all
ecallmeans "frame ready". That template copies the 64,000-byte framebuffer and palette (16,192 word reads) intoframes/NNNNNNNN.hexebreakmeans halt- the WAD is read-only memory, and writes to it are refused by the store tables
- a virtual clock advances one tic per frame
There's no input, so DOOM does what it does when nobody touches it: it plays the shareware demos.
How do I know it's right?
When one frame takes 40 minutes, you don't debug on the real machine. Before curl ran a single DOOM instruction there were three independent implementations:
- A reference RV32IM emulator in C, which passes the official
rv32ui/rv32umtest suites. - A step simulator that interprets the exact curl subset the templates use: curl's config-line rules, variable expansion, range clipping, and
%output{}truncation. It refuses anything curl would quietly do differently. It runs in lockstep with the reference emulator, comparing every register after every instruction. Boot plus 300 frames, 175 million instructions: identical. - Real curl. The test suites also ran on real curl, every template was fuzzed on random states against the simulator, and there were 200 "spot checks" where real curl takes over from the simulator at a random moment and has to agree with it 50 steps later.
curl has some interesting edge cases here, and the simulator knows about all of them:
- An undefined
{{name}}silently expands to nothing. - If
%output{}can't open its target, curl silently keeps writing to the previous target. - Several URLs written to the same
-otruncate each other.
Every one of these would corrupt the machine without any error, so the templates are generated to never hit them, and the simulator fails loudly if they ever would.
The handoff (rule 5)
Booting DOOM takes 10.7 million instructions, and the title screen another 170 frames. At curl speed that's about 35 hours of watching a static picture. So by default the simulator computes boot and frames 0 to 170. The machine state is then handed to curl at frame 171, the first frame of DEMO1.
This is a shortcut, so it's disclosed. The web page labels every frame with where it came from. The run's manifest records the handoff frame, step number and state hash. init --handoff-frame 0 makes curl do the whole thing from reset if you have a day and a half.
From frame 171 on it's all curl. Frame 171 is the level load, which is 5.8 million instructions on its own. It took 2.9 hours and matched the simulator's hash byte for byte:
After that came 40 frames of DOOM's melt wipe:
Making it fast(er)
The first version was RV32I with Ubuntu's curl. One step took 13.4 ms and a gameplay frame took 8.3 hours. Two changes fixed most of that.
Most of the time was curl starting up. The distro binary loads 33 shared libraries and initializes OpenSSL before it reads a single byte of config. So the machine now uses a static build of the same upstream curl 8.18.0, with every protocol except file:// left out. The release signature is checked, and none of the config, variable or write-out code is touched. It starts in roughly the time /bin/true takes. The distro curl still runs the machine identically, just about 5× slower.
Software multiply/divide was 43.6% of DOOM's instructions. DOOM's fixed-point math (FixedMul) goes through libgcc's __muldi3 without the M extension. Adding multiply and divide as lookup-table instructions cut a gameplay frame from 2.23M to 1.24M instructions.
| RV32I + distro curl | RV32IM + static curl | |
|---|---|---|
| one step (curl process) | 13.4 ms | 1.82 ms |
| gameplay frame | 2.23M instructions, ~8.3 h | 1.24M instructions, ~37 min |
| frame 171 (level load) | ~27 h | ~2.9 h |
The RAM disk mattered too. 2.4 million tiny files on tmpfs cost about 5 KB each in memory that can't be freed. ext4 with inline_data on a zstd zram device stores them at 43 bytes per file. The whole machine takes 85 MiB of RAM for its block device.
The numbers
| ISA | RV32IM |
| curl | 8.18.0, static, file:// only |
| processes per instruction | 1 |
| file lookups per instruction | 10–354, 21.8 on average |
| table files (the "microcode") | 764,341 |
| machine files in total | ~2.4 million |
| live speed | ~400–550 instructions per second |
| gameplay frame | ~37–40 minutes |
Watch it
The live page shows the latest frame, progress through the current one, and the simulator's prediction next to curl's output, with a green check when the hashes match. The machine checkpoints itself every six hours by freezing the filesystem and copying the zram device, so it can survive a reboot and keep going from the exact same step.
If you want to run your own, you need Linux, a few GB of RAM to spare, a RISC-V cross toolchain, and the shareware doom1.wad. Then:
./scripts/fetch-deps.sh
make && make check
./curlmachine init
./curlmachine start
Then wait. A lot.
Code and first draft of this post by Claude (Anthropic), directed by me. DOOM is © id Software. This uses the freely distributable shareware doom1.wad, which isn't included in the repository. doomgeneric is GPL-2.0. curl is by Daniel Stenberg and contributors.
Comments