Doom, written in Python, running in your browser: a port, not an emulator
There is a Doom engine written in Python, and you can play it at unodos.arinbakht.com/duum. It downloads about 10 MB the first time, most of that the game data, and then runs at somewhere between 30 and 50 frames a second depending on your machine. Freedoom is preloaded. If you own a real WAD, you can drop it on the page and it never leaves your computer.
The engine is the same file, byte for byte, that ships inside UnoDOS. That sentence is the whole point of this post, so I want to earn it properly, including the part where the obvious way to get it into a browser did not work.
Where Duum came from
Duum started on July 20 as an acceptance test. UnoDOS had grown a Python runtime (MicroPython, vendored, one of the few pieces of the OS not written in-repo), and the question was whether Python on this OS was a toy or a first-class way to write applications. The agent's answer was to write a Doom renderer in it.
The first commit, 62c5be84 "pc64/duum: WAD tooling + host renderer reference (M6a/b)", was 271 lines of Python: "a from-scratch, numpy-free Doom renderer written to port cleanly to MicroPython." Front-to-back BSP walk, per-column clipping, one-sided walls, two-sided portals, distance and light shading, a sky. It emits vertical column spans, which is exactly the shape of the OS's own cv.vline drawing call, so the host reference and the on-device version could be diffed against each other. The same day, 0b15aa84 produced the first DUUM.PY, 350 lines, which "streams the IWAD with uno.read_at (never slurps), parses E1M1", and 7ec40ea9 recorded that "Duum runs E1M1 on-device - the acceptance test passes (M6)", with the commit message calling it "proof that Python is genuinely first-class here."
By v3.34.0 the engine is 3,439 lines. It has sound, doors, projectiles, and since August 18 its own repository (19fd602 "duum: split the engine out into its own repository"), with the OS vendoring the built file back. The split commit is the one that made the browser version possible, and it says why: "it only ever asked its platform for six things (size, read_at, beep, quiet, and optional ticks and keys_down)."
Six calls. Hold on to that number.
The way that did not work
The OS itself runs in a browser, at /try/, under QEMU compiled to WebAssembly. The natural plan was to run Duum there too: boot the OS, open the game, done. That was the plan on paper in the launch strategy, and it had a pass bar written down before the spike ran: "Duum playable at all."
The spike commit is fc2dd8c, August 18: "Phase 0 spike: pc64 runs in a browser; Duum does not." Inside the emulated OS, in Chrome, Duum took four to six minutes to draw its first frame and then advanced at 0.13 frames a second: four presents in 30.01 seconds. The spike notes are careful to say this was not an emulator stall (the guest was executing the whole time) and careful not to retest in Firefox, because "the Chrome result is decisive." Scaling by the fastest machine available got it to roughly 0.2 fps.
So the OS widget shipped and Duum did not, which was the strategy's "outcome 2", and the fallback was already specified: build the game standalone. Not the OS in a browser with a game inside it; the game, on a browser build of its own runtime.
The way that did: a port, not an emulator
Commit 2adc04b in the duum repo, also August 18: "ports: run Duum in a browser, as a port rather than as a guest." What it is: MicroPython v1.24.1, the same version the OS vendors, compiled with Emscripten as an out-of-tree port; the OS's per-pixel span writers (cv.wall_col, cv.flat_col, cv.mask_col) transcribed to C from the OS's own mod_uno.c; and the built DUUM.PY embedded verbatim. The C and headers come to 1,079 lines. The whole engine binary, duum-wasm.wasm, is 333,012 bytes on disk, about a third of a megabyte, where the QEMU build that boots the OS is nearly twelve.
The byte-identity claim is checkable: dist/unodos/DUUM.PY in the duum repo and pc64/apps/DUUM.PY at the OS's v3.34.0 tag are both 140,227 bytes with the same MD5. The game did not get "ported to the web." Its runtime did, and the six-call platform surface is why that was a thousand lines of C and not a rewrite.
This is the first lesson, and it is not about browsers: the cheapest place to port something is the boundary where it asks for the least. Duum's engine never knew it was on UnoDOS. It knew it could read bytes at an offset, ask the screen's size, beep, and poll keys. The agent that wrote it in July did not plan a browser build; it just kept the platform surface small because the host reference renderer and the on-device one had to agree, and a small surface is easier to keep agreeing. The browser port was a dividend of a discipline adopted for a different reason.
The bug that cost a session
The port's README keeps a list of traps, and the first one is the kind of thing that only happens when you move a C program onto a machine that is not quite a machine.
MicroPython's garbage collector finds live objects by scanning the C stack for anything that looks like a pointer. On WebAssembly there is no C stack to scan: a wasm function's locals live in the VM's own frame, outside linear memory, invisible to the collector. The README's wording is exact about the consequence: "It is not incomplete, it is wrong: the object is freed and the interpreter keeps using it. The symptom is not a crash. It is an AttributeError forty frames later on an object whose type name prints as an empty string, because the type pointer now points into reused memory."
The standard remedy, Emscripten's emscripten_scan_registers(), requires ASYNCIFY, "which costs roughly half the speed and several times the size," so it was rejected. What shipped instead: MicroPython's split-heap mode, where gc_collect() only sets a flag and the real collection runs between frames at the top level, when no C local can be holding anything; plus a rule that any object held across a call into JavaScript must be registered as a root, because "A C static is not somewhere the collector looks either." A related trap, measuring the heap ceiling against wasm linear memory instead of the GC heap, produced a MemoryError in the BSP walk until the allocator was rerouted; a 6,000-frame run now settles at 64 MB against a 320 MB ceiling.
The lesson here is one the rest of this series keeps arriving at from different directions: a symptom forty frames from its cause is a symptom of the platform, not the program. The engine was fine. The runtime under it had lost a guarantee it was built on, silently, and the debugging session was spent finding out which guarantee.
Measure the platform before optimising the app
A second Duum story from the same week, and it reverses the direction of the first.
On August 18 the per-column rasteriser, the innermost loop, was moved from Python into C (d4773585 "duum: move the per-column seg rasteriser into C (cv.seg_cols)"), for the obvious reason: it runs once per screen column per visible wall segment, "a few thousand times a frame", and in MicroPython's default object representation every floating-point intermediate in it is a heap allocation. Then the engine was split into its own repository, and the vendored version went back to pure Python columns.
So which is faster? The honest answer required a real machine, and the OS repo's pc64/METAL-FINDINGS.md has the A/B from a ZimaBlade (a Celeron N3350, about as slow an x86-64 as the OS targets), same boot, arms alternated, milliseconds per draw at the spawn viewpoint:
| arm | idle view | scripted movement |
|---|---|---|
| pure Python columns | 15.608 / 15.608 / 15.613 | 11.748 / 11.745 / 11.764 |
C cv.seg_cols | 15.593 / 15.580 / 15.584 | 11.832 / 11.852 / 11.829 |
0.15% apart one way on the first test, 0.7% apart the other way on the second. The findings file concludes: "Two differences that small pointing in opposite directions is no effect." The control, a trivial app doing one clear and one rectangle, managed 15.4 draws a second to Duum's 21.5, despite a draw that is three times cheaper, because the cost was in the present path, not the renderer. On a fast desktop Duum's whole geometry pass is about 3 ms a frame, a fifth of a 60 fps budget.
The innermost loop, the one any engineer would have rewritten in C first, was not where the time went. The lesson is plain and it is the one the commit that filed the finding uses as its title: the frame rate "is the present path, not the renderer." Measure the platform before optimising the app. An agent, like a person, will optimise the loop it can see.
Two things the widget got wrong, and one still open
This post would be dishonest if it stopped at the clever parts.
Duum had no wall collision. Found on metal during the pre-launch conformance run, in both engines: the movement check "contains no reference to a linedef or a vertex", and its one wall-like guard was dead code, because a BSP partitions the whole plane and there is nowhere to be outside it. The fix (3fab45c "engine: give Duum wall collision, and a gate that keeps it") rebuilds a blockmap-style grid at level load and tests movement two ways: a box at the destination, the vanilla check, and a sweep along the path, because Duum steps by elapsed time and "on a slow frame ... a 32-unit box hops clean over the wall between them." Counting a graze as a hit sealed every narrow door in the game shut, E1M8's included, so the on-the-line case had to be decided deliberately. The gate that now exists runs 36,000 randomised moves across E1M1 to E1M9 and requires zero crossings of a solid wall. Before it, both rendering gates took the player's position as an input, so "a player standing inside a wall is an invalid viewpoint fed to a working renderer", which is how a game with no collision passed every test it had.
The OS widget shipped the wrong WAD. Three days before launch an audit found that the /try/ image carried an 11,159,840-byte DOOM1.WAD, which is id Software's file, not Freedoom (28,795,076 bytes, BSD-licensed, attribution shipped). The project's own flasher has a publish gate that refuses exactly that byte count by name; the widget build had no gate, and that is the only reason it reached production. Fixed and verified from the edge the same day. The lesson was recorded in the audit and it generalises: when a number disagrees with an artifact, find out which one is wrong first, and a gate that exists in one pipeline and not its sibling is a gate that does not exist.
Still open. The collision gate passes 4 of 4 on the shareware WAD and 1 of 4 on Freedoom: three of Freedoom's 140 use-doors do not let the player through. The public page serves Freedoom. If you hit a door that will not open, that is the bug, it is filed, and this post will not pretend otherwise.
What the widget is, stated precisely
It is not UnoDOS in your browser; that is the other page. It is the same Duum code, on a browser build of its runtime. The engine is byte-identical to the one the OS ships. The frame rates on the page are the port's, on your hardware, not the OS's. Your WAD is read with the browser's file API into a worker with no network access, every offset it asks for is clamped, and there is no endpoint to upload to, because nothing is uploaded.
Sources: https://github.com/hmofet/unodos (62c5be84, 0b15aa84, 7ec40ea9, d4773585, 30563a85; pc64/METAL-FINDINGS.md), https://github.com/hmofet/duum (19fd602, 2adc04b, 3fab45c; ports/web/README.md), July 20 to August 21.