技术文档

Rewrite plan: Zibo/LevelUp logic → MSFS 2024 WASM + HTML display units

此页为项目的英文技术文档原文。 docs/REWRITE_PLAN.md

Status date: 2026-10-31. Replaces the "original plugins in LU737 Host over a WebSocket" architecture of CONVERSION_ASSESSMENT.md §2.3–2.4 for everything except the models. Keeps the stable cockpit interface (SCI, COCKPIT_IO_REDESIGN.md, SCI_IMPLEMENTATION.md) as the seam between the model and the logic.

1. Owner's decisions (2026-10-31)#

Topic Decision
Use Personal use only, never distributed. Reading the original binaries (decompiling zibomod) is authorised by the owner for this.
Scope Rewrite everything: the compiled zibomod plugin and the XLua scripts (FMS, systems, glareshield, EFB, HUD).
Fidelity Behaviour must match Zibo's ("一模一样"); proven by comparison tests against the original plugins (§4).
Displays HTML/CSS/JS display units like FlyByWire's A380X: TSX + SVG with the MSFS avionics framework (@microsoft/msfs-sdk), one instrument per display. Not the old texture/bitmap panel.
Autopilot Rewrite Zibo's AFDS/autothrottle (not the MSFS autopilot).
Engines Reproduce the CFM56-7B conversion tables exactly (N1/N2/EGT/fuel flow/thrust).
Navigation data MSFS's own (facilities), not X-Plane's files.
Sound Not in phase 1.
Host Removed from the product now; kept only as the test oracle.
Build GitHub Actions.

2. Architecture#

MSFS 2024 package
├─ lu737_systems.wasm   (wasm/, C++20, gauge LU737_Systems in panel.cfg VCockpit01)
│    electrics, APU, pneumatics, engines + CFM56 tables, fuel, hydraulics,
│    flight controls, AFDS/AT, TCAS, GPWS, annunciators, failures
│    implements the SCI contract (data/sci/contract): SCI states as
│    L:LU737_<STATE> for the model, SCI events from the clicks;
│    reads A:vars, drives MSFS through K: events
├─ display units        (avionics/, TSX + SVG, one VCockpit per display material)
│    PFD, ND, upper/lower EICAS, CDU, ISFD; FMS (MSFS facilities, flight plan)
└─ models               (unchanged: original objects as glTF, behaviours from
                         tools/msfs/generate_behaviors.py)
  • src/core never includes MSFS headers; it talks to the sim through SimIO. The same code builds natively for unit tests and for the differential tests.
  • WASM ↔ JS (FMS ↔ AFDS, CDU keys, display data that is not a single number): MSFS_CommBus (in the SDK headers) or L:vars.
  • The model's interface is the SCI contract. The behaviours read 959 SCI states as L:LU737_<STATE> and every click sends an SCI event H:LU737_<CONTROL>_<ACTION> (2,123 events; data/cockpit_io.json). The contract (data/sci/contract) defines states (kind, enum, default) and controls (type, guard, momentary positions); it names no Zibo dataref, so the model does not change when the logic is rewritten. The Zibo profile (data/sci/profiles/zibo_2S1_50) records how each SCI state and control maps to Zibo's datarefs and commands, measured on the original plugins: it is the specification of what each control does in Zibo.
  • Clicks reach WASM through JS. H events are delivered to JS instruments only (MSFS_Events.h: "HVar are events distributed to js vcockpits"), so a display unit (or a small IO instrument) receives them and forwards them to the module over CommBus. Decided in M3.
  • Duties of the removed gauge that the rewrite takes over: SCI event relay and state output, display power gates, L:LU737_SYS_LINK, screen brightness gain L:LU737_DU_GAIN, exterior fan rotation L:LU737_fan_angle_1/2 (integrated from N1), and the MSFS coupling (sim inputs, control and engine outputs, AP/AT authority).

3. Sources for the rewrite#

Source Gives
plugins/zibomod/lin_x64/zibomod.xpl (symbols kept: 6,580 named functions) Systems, engine model, AFDS, FMS path and turn computation, TCAS, GPWS. Read with tools/re/decompile.py (Ghidra's decompiler, constants resolved). Nothing decompiled is committed.
plugins/xlua/scripts/** (~230k lines of Lua) FMS/CDU (B738.a_fms, 173k lines), EFB, glareshield, HUD, calculations: readable source.
data/sci/contract, data/sci/profiles/zibo_2S1_50, data/cockpit_io.json The interface the model expects (SCI states and events) and, per control and state, the Zibo datarefs/commands behind it with measured behaviour (SCI_IMPLEMENTATION.md §3).
B738_Datarefs.txt, B738_Commands.txt Dataref and command reference.
737_80NG.acf PANEL_3D (tools/xplane/panel.py) Exact layout of every display: positions, sizes, which dataref drives what.
Owner's X-Plane screenshots Visual reference for the display units.

4. Proving parity: the oracle#

xphost/ is now a test tool. It runs the original Linux plugins headless with the SCI layer: --sci-test script.json runs SCI scripts (events, expectations on SCI states; xphost/test/sci, e.g. cold & dark power-up), and lu737host --replay in.bin --out out.bin runs recorded frame inputs (sim datarefs, SCI events, commands, dt) and writes every frame's outputs. Because both the oracle and the rewrite speak SCI, the comparison is made on SCI state names. A differential test drives the original plugins and the rewritten subsystem (native build of wasm/src/core) with the same input sequence and compares the outputs frame by frame within a stated tolerance (float32 vs double, fixed dt). Each subsystem lands with:

  1. its specification (from the decompiled function and the Lua);
  2. unit tests;
  3. differential scenarios against the oracle (e.g. cold & dark → battery → APU start → APU gen on), run in CI.

What cannot be identical, stated per milestone in the test reports:

  • flight physics is MSFS's, not X-Plane's: the AFDS control laws and gains are Zibo's, but the aircraft responds differently and may need retuning;
  • navigation data comes from MSFS (another AIRAC/provider than X-Plane);
  • the displays are redrawn as vectors in Zibo's layout, colours and symbols, not pixel copies of the bitmaps;
  • no sound in phase 1.

5. Milestones (phase 1)#

# Content Done when
M1 Toolchain: SDK in third_party/, WASM skeleton + CI, host removed from the product, oracle with --replay, decompiler Module loads in MSFS (TEST_PLAN.md M1)
M2 Specifications of electrics, APU, pneumatics, engine start, CFM56 tables from zibomod + Lua Specs reviewed; tables extracted and unit-tested
M3 Electrics, APU, bleed/packs, engine start + CFM56 model in WASM; click routing Differential tests pass; in-sim cold & dark → engines running
M4 Display units PFD, ND, upper/lower EICAS, CDU, ISFD; model display surfaces split into one material per display Compared with the owner's screenshots; in-sim
M5 FMS on MSFS navigation data (Zibo CDU pages), AFDS/AT (MCP modes, LNAV/VNAV) Differential tests of mode logic; in-sim route flight
M6 Approach/land (APP, autoland), GPWS/TCAS needed for the flight Acceptance flight: cold & dark → power → APU → engines → take-off → AP cruise → ILS landing

6. Repository map#

Path
wasm/ Systems module (C++), native tests, build script
avionics/ Display units (TSX, @microsoft/msfs-sdk)
third_party/msfs2024-sdk/ SDK headers, wasi-sysroot, SimConnect.h for CI
xphost/ Oracle: original plugins headless (--selftest, --replay)
tools/re/ Decompiler setup and the per-function decompile helper
data/ SCI contract and Zibo profile (data/sci), cockpit_io.json, physical animation map
.github/workflows/ build-wasm.yml, oracle.yml