commit a3daf2745aee5bd7ea3e1f560d2bfeeaac255565
parent b9bc0b9619ffa25bcb3c76fd23d084249b490583
Author: anon <anon@example.com>
Date: Tue, 13 Oct 2026 00:53:41 +0000
Execute original AO render method as Rust and WebAssembly
Diffstat:
2 files changed, 128 insertions(+), 3 deletions(-)
diff --git a/.gitignore b/.gitignore
@@ -7,6 +7,13 @@ tools/*.exe
tools/*.log
tools/cellao-reference/
tools/browser-reference/
+tools/rust/
+browser/**/target/
+browser/native-render/pkg/
+browser/native-render/src/generated.rs
+browser/native-render/src/generated/
+browser/native-render/data/
+browser/native-render/report.html
tools/*.json
tools/*.png
tools/*.jpg
diff --git a/docs/browser-porting.md b/docs/browser-porting.md
@@ -196,9 +196,8 @@ the original game libraries. Those libraries would need translation/linkage or
replacements as well.
This is an observed import/source mismatch, not a translator runtime failure.
-The translator was not run because this host has no Rust toolchain. Instruction
-coverage, DLL translation strategy, complete API coverage and browser performance
-remain untested. `tools/browser_probe.py` reproduces the PE inventory and module
+The translator had not been run at this assessment stage. The subsequent
+13.2 execution experiment is recorded below. `tools/browser_probe.py` reproduces the PE inventory and module
comparison against checkouts under `tools/browser-reference/`; its reports are
`tools/browser-imports.json` and `tools/browser-compatibility.json`.
@@ -283,3 +282,122 @@ are provisional. Successful WebGL drawing does not satisfy the AO-port success
criteria above. It provides a concrete starting scene while the full original-
binary compatibility questions remain open. Local generation and launch
instructions live in [browser/README.md](../browser/README.md).
+
+## Original AO method translation
+
+The current direction is to preserve native AO code through Theseus, Rust and
+WASM, with browser replacements at the operating-system and graphics boundaries.
+The terrain prototype remains useful for asset comparison; it is not the chosen
+replacement for the original engine. This experiment uses the independently
+installed **13.2** target described in [versions-and-patches.md](versions-and-patches.md).
+
+### Actual complete-executable translation attempt
+
+Theseus revision `ca302a35c0a680634cfb76ea3d241e8c8d5e592e` was built and run
+against `client-target/Clientr.exe`. Its default traversal reported 547 blocks
+and 41.6% coverage of the executable's code range. That is discovery coverage
+inside this small EXE, not coverage of AO's DLLs, or proof that those blocks run.
+
+Generation failed during Rust formatting: imported names such as
+`ddr::??1EnvOptionModule_t@@QAE@XZ_stdcall` are invalid Rust identifiers.
+The captured diagnostic is `tools/theseus-ao13-main.log`. Escaping the names
+would only remove this first syntax problem. The imports still need correct
+implementations or linkage to the native game DLLs, including their calling
+conventions. A C++ member function import must not automatically become a
+Win32 stdcall wrapper.
+
+### Recovered Direct3D contract
+
+The inspected `client-target/bbr.dll` SHA-256 is
+`0c61958075bb39a1848736aa515d81fd0830dfab706c2896d99d5d6ded45823d`.
+PE imports, embedded interface GUIDs and exported type names identify DirectDraw
+and **Direct3D 7**. Imports include `DirectDrawCreate`, `DirectDrawCreateEx` and
+`DirectDrawEnumerateExA`; interface evidence includes `IDirectDraw7`,
+`IDirect3D7`, HAL and TnL HAL devices. Inspected modules do not import D3D8/9.
+
+One short export provides a clean execution boundary:
+
+```
+?Render@TriList@@QBEXPAUIDirect3DDevice7@@PBVRLVertex@@I@Z
+```
+
+Its original code occupies `0x101075b0..0x101075f9` (73 bytes), with no direct
+DLL imports or exception machinery. `ECX` holds the `TriList` object; three
+stack arguments supply the device, vertices and vertex count. The method reads
+index begin/end pointers from object offsets `0x0c` and `0x10`, computes the
+16-bit index count, and calls device vtable offset `0x68` (slot 26):
+
+| Submitted argument | Value/meaning |
+| --- | --- |
+| Primitive | `4`, triangle list |
+| Vertex format | `0x112`, XYZ + normal + one UV pair |
+| Vertex stride | 32 bytes; XYZ at 0, normal at 12, UV at 24 |
+| Indices | Unsigned 16-bit indices from the `TriList` object |
+| Flags | `0` |
+| Return | AO method `ret 0x0c`; COM method stdcall with eight arguments including the device |
+
+The companion export at `0x10107540` calls slot 32,
+`DrawIndexedPrimitiveVB`. Slot numbers and formats were checked against Wine's
+[Direct3D interface definitions](https://raw.githubusercontent.com/wine-mirror/wine/master/include/d3d.h)
+and [type definitions](https://raw.githubusercontent.com/wine-mirror/wine/master/include/d3dtypes.h).
+Static evidence is retained in `tools/graphics-13.2-inventory.json` and
+`tools/graphics-13.2-render-wrapper.json`.
+
+The focused translator extracts those original bytes after checking the DLL
+fingerprint and lets Theseus generate their Rust operations and continuations.
+The harness supplies guest memory and a COM vtable; the translated AO method
+itself computes and submits the draw arguments. A Rust stdcall callback reads
+those buffers and forwards them to WebGL. The geometry is a synthetic fixture.
+DLL startup and the generated image initializer are deliberately not executed:
+this method only needs the supplied object, buffers and device.
+
+The native Rust test verifies one triangle draw, FVF `0x112`, three vertices
+and indices, flags zero and restored guest stack `0xf000`. The same generated
+code was compiled to WASM and executed in the in-app browser: a colored triangle
+was visible, the submitted arguments and stack matched the native test, and
+there were no warning/error console messages. Evidence is retained in
+`tools/browser-native-render.png` and `tools/browser-native-render-runtime.json`.
+Reproduction instructions are in [browser/native-render/README.md](../browser/native-render/README.md).
+This does not establish full AO startup, world rendering or usable performance.
+
+### Native DLL linkage remains necessary
+
+The inspected Theseus architecture currently describes one DOS or Windows
+module per translation. Its CLI accepts EXE/COM filenames; its lower-level PE
+parser can parse DLL bytes, but parsing is not native dependency loading.
+`tc/src/exe.rs::load_pe` maps one preferred image base, and
+`tc/src/lib.rs::State::write_iat` assigns imports synthetic built-in addresses.
+The compiler does not invoke the available `exe::apply_relocs` machinery to
+rebase a set of native DLLs. Runtime `LoadLibrary`/`GetProcAddress` resolve
+registered host modules and exports, not arbitrary PE files.
+
+A native DLL path needs shared guest memory, non-overlapping module mappings,
+HIGHLOW relocations, exact export/ordinal resolution and IAT entries pointing
+to translated guest functions. Guest calls must preserve their original
+register/stack conventions. All modules' blocks must share one dispatch table.
+DLL initialization, dynamic export registration and any TLS callbacks must
+also be accounted for. Code discovery must include indirect targets, exports
+and runtime-observed missing addresses; translating only the EXE entry point
+cannot establish complete coverage.
+
+The next bounded linking test should execute an original imported function
+across two game modules before attempting their complete startup. That isolates
+IAT resolution and guest calling conventions from unfinished Windows APIs.
+
+### Graphics and editable Rust boundaries
+
+Theseus already has COM-address dispatch and stdcall wrappers, which the proof
+reuses. Its existing DirectDraw presentation is 2D Canvas/ImageData. The
+inspected implementation lacks Direct3D interfaces; `DirectDrawEnumerateExA`
+is absent, and the DirectDraw7 `QueryInterface`/`GetCaps` methods are unfinished.
+Full AO graphics require capability reporting, device and vertex-buffer
+interfaces, surface-backed textures, transforms, fixed-function render and
+texture-stage states, lighting/fog and presentation. The single triangle hook
+does not implement those contracts.
+
+Generated Rust expresses instructions through registers and guest-memory
+reads/writes. It does not recover the original C++ classes or become idiomatic
+Rust automatically. Keep generated code reproducible; place readable graphics,
+network and platform adapters alongside it. Selected methods can later be
+replaced with recovered Rust implementations after comparing their outputs
+and side effects against the translated/native behavior.