A small voxel sandbox for TempleOS, written in HolyC: walk a blocky world, break blocks and place new
ones in any of the 16 system colors. One source file, HolyCraft.HC, builds two ways:
- TempleOS V5.03 (with
TOS_NATIVEdefined): draws through the window'sdraw_itcallback, reads the keyboard fromkbd.down_bitmapandScanMsg, and renders the world's exposed block faces as near-clipped, subpixel spans with reciprocal depth andGrHLine. A private drawing context lets the TempleOS compositor clip moving windows; resizing grows its buffers as needed. - The browser, compiled to WebAssembly by HolyC-wasm: a
per-pixel voxel raycaster presented with
GrSprite, with mouse look through theBrowser*globals below. This is the build TempleOS-Web plays in its Games menu.
Copy HolyCraft.HC and Run.HC into one folder on the TempleOS disk, for example C:/Home/HolyCraft/,
then at the TempleOS prompt:
#include "C:/Home/HolyCraft/Run"
Run.HC changes to its own folder, defines TOS_NATIVE and includes the game, which starts at once.
Without Run.HC, type #define TOS_NATIVE 1 first and then #include the game file.
| Key | Action |
|---|---|
| W / S | forward / back |
| A / D | strafe left / right |
| Mouse, or J / L and I / K | turn, and look up / down |
| Space | jump |
| G | fly on or off; R / F rise and sink while flying |
| Left click | break the block under the cross |
| Right click | place the selected block |
| 1 to 9, Q / E, arrow keys | pick a block |
| Esc | quit |
Compile HolyCraft.HC with HolyC-wasm without defining TOS_NATIVE. The page that hosts it talks to the
game through four globals:
| Global | Set by | Meaning |
|---|---|---|
I64 BrowserMouseCapture |
the game | 1 while it wants the pointer locked |
I64 BrowserMouseDX, BrowserMouseDY |
the page | mouse movement since the last frame; the game reads and zeroes them |
U8 BrowserKeys[128] |
the page | 1 for each scan code held down |
node tools/input.test.mjs
node tools/physics.test.mjs
node tools/window.test.mjs
node tools/render/web.mjs checkThey compile the browser build with HolyC-wasm and run it on a clock they move. The input test checks
that a still mouse leaves the camera still, one mouse move turns it once, a held key moves the player and
letting go stops it. The physics test checks that the player walks as far in a second at 10 frames a
second as at 60, that the player's box keeps the eye out of walls, ceilings and the world's edges, and
that a block is not placed where the player stands. They find HolyC-wasm in $HOLYC_WASM or beside
this repository (../HolyC-wasm). A missing compiler fails the checks. The window check guards
the HUD buffer and row padding at seven sizes, and checks that cleanup followed by Init restarts
the game. The renderer check compares all visible faces before fog with independent exact rays
at 48 fixed and seeded camera poses, including close walls, ceilings and world boundaries.
Maintenance note: the HEMU-based commands below still refer to the old
tools/hemu/ site harness. They need migration to HEMU's Kernel/Test/
harness before they can run against current TempleOS-Web. The standalone
WASM checks above do not use that harness.
The native checks use the actual TempleOS V5.03 compiler and drawing routines inside HEMU. They
need a TempleOS-Web checkout with its HEMU and HolyC-wasm dependencies, tracked snapshot/disk,
and tools/hemu/Fixtures.mjs:
export TEMPLEOS_WEB=/path/to/TempleOS-Web
node --max-old-space-size=3072 tools/render/tos.mjs check
HLE=0 node --max-old-space-size=3072 tools/render/tos.mjs check
node --max-old-space-size=3072 tools/render/tos.mjs windowsThe native ray comparison covers 45 poses. Three browser stress poses put the eye inside a
solid block, which the player box prevents during play; the native exposed-face renderer does
not support those poses. Colors identify each material and face, avoiding random dither in the
comparison. The native renderer draws each face with TempleOS's own GrFillPoly3, which fans
GrFillTri0 triangles from whole-pixel corners. That leaves single pixels on shared diagonals,
as it does in TempleOS itself, so the check allows one wrong pixel in 10,000; a face that is
missing or seen through costs whole runs of pixels (the earlier renderer failed with 2,358,992).
LIST=1 prints each wrong pixel. Depth is exact only at whole-pixel corners, so its error
against the rays is reported, not asserted. Pixels are compared out to 8 cells inside the render
distance, less 0.87 because a block's center decides whether it is drawn.
HLE=0 disables raster acceleration and asserts that it stayed disabled. The windows check
compares DrawIt with a separately rendered view at seven sizes, including odd widths and repeated
growth/shrink. It does not substitute for testing actual window occlusion in QEMU or on hardware.
When HolyC-wasm includes the recovered native oracle runner, QEMU can also check eight near-clipping/ceiling camera poses using its original TempleOS disk and compiler:
node tools/render/qemu.mjs check
REPEATS=3 node tools/render/qemu.mjs time /path/to/prior/HolyCraft.HCThe QEMU check compares 1,320,325 pre-fog pixels against independent ray results, allowing
the same diagonal pixels (at most one in 100 of a pose). It uses a deterministic scene and
reports the QEMU backend plus the path to its execution evidence. With TEMPLEOS_WEB set, it
then runs the same source and poses in HEMU and requires each frame's FNV-1a hash to equal the
one native TempleOS printed.
The timing command warms each renderer, then measures 200 spawn-view frames using guest
tS; N changes the frame count. Both renderers use the same explicit camera above
the middle terrain column. The baseline must provide the native rendering API;
the sky-row initializer is called only when that version defines it.
node tools/lifetime.test.mjs checks six startup and resize allocation failures in
original TempleOS. BACKEND=hemu runs the same source through TEMPLEOS_WEB;
BACKEND=wasm checks five browser startup failures. Each test denies one allocation
at a game call boundary, tracks owned resources, and checks cleanup or retry. It
does not inject failures inside the system's DCNew allocator. Resize keeps the
previous resource until its replacement has been allocated successfully.
The browser window check runs the native game in the site's actual one-core and four-core worker arrangements, using its installed Playwright/Chromium tools:
TEMPLEOS_WEB=/path/to/TempleOS-Web node tools/render/browser.mjsIt waits for the real compositor callback to allocate the game view, observes
frames reaching the page canvas, sends a held L key through the page, checks the
native camera response, and exits through the on-screen Escape key. It saves
before/after screenshots in the printed temporary directory (OUT overrides
that location). This checks the actual window/input/exit path without replacing
the game's drawing callback. It is not an exact compositor-pixel comparison,
steady-state FPS measurement, or proof on physical mobile devices.
To measure rendering on the current machine:
node tools/render/web.mjs bench
N=15 node --max-old-space-size=3072 tools/render/tos.mjs timeSRC can select a different HolyCraft source for a regression comparison. POSE selects one
native check pose; OUT saves its frame, depth and world arrays for diagnosis. LIVE and RAW
can select alternate snapshot/disk fixtures. No test writes to the bundled disk image.
The timing mode retains the game's actual material and sky colors. The geometry checks
replace them with face-identifying colors; those diagnostic colors must not be used to
measure optimizations that depend on whether two shades are equal.
Equal face shades use solid drawing. This preserves their color while consuming fewer
random values, so subsequent dither and sky noise need not match an older seeded frame.
Native rendering performance is still being optimized. The precise scanline renderer fixes missing blocks, but it is slower in HEMU than the earlier integer polygon path. Passing these checks establishes the listed cases, not universal parity or a frame-rate guarantee across QEMU, VirtualBox, VMware and bare metal. The native and browser rendering/input adapters still differ; replacing them with one native API path depends on HolyC-wasm runtime support.