Host ABIs and the console
Lesson from the WasmPascal in-browser Learn Pascal tutorial. Source: webpascal/index.html.
wasmpascal detects how to boot a compiled program by peeking its exports — you never pick the ABI yourself. There are four:
- console-only — no entry export; plain
write/writeln/readln/TextColorprograms (all the lessons above). - pascaldom — exports
pascaldom_main; self-wires its canvas + event loop via thepascaldom_envDOM/canvas imports. Reach it withuses WEB: that embedded unit declares the whole bridge, so your program writes noexternalblock, picks noCB_*callback ids, keeps nocase id ofdispatcher and needs noexportsclause — the program body ispascaldom_main— and handlers go in by name:web.On(h, 'mousedown', HandleDown),web.OnTick(HandleTick). Seeweb_dom.pasfor the tour,sweep.pas(7 units),paint.pasandmusicbox.pasfor real programs.pascaldom_probe.pasdoes the same job against the raw bridge, for comparison. - batchiness — exports
batchiness_main; batched-canvas games + Web Audio SFX viaapp_env. Games self-wire their own keyboard (see the?reference's Host ABIs section). Examples:pascaloids.pas,pong.pas,transforms.pas,sparks.pas,growable.pas,flightleader.pas(FLIGHT LEADER, a 6-unit space combat game),xonix.pas(a Xonix clone: draw lines to claim land — the fill floods from the balls, so it can never cover one),floaty_car.pas(Floaty Car endless driver — stay on the winding road; it only gets faster),dugster.pas(DUGSTER — a Digger-style dig-em-up in five units). - basic_canvas — exports
wasm_init/wasm_update/wasm_click/wasm_get_pixels/wasm_get_width/wasm_get_height, plus optionalwasm_pointer_down/wasm_pointer_move/wasm_pointer_upfor press-and-drag (mouse or touch); the host drives a fixed-step loop and blits your RGBA buffer. Examples:basic_canvas.pas,classic_dots.pas.
The ? quick reference's Host ABIs section has the full details and examples. When you want the DOM or a canvas, load web_dom.pas, press Run, and study how it builds the page with web.CreateElement / web.On — that is the whole setup. Only write raw external 'pascaldom_env' ... declarations when you need a bridge entry the unit does not wrap — and note that a console program must keep them: uses WEB would make its body the pascaldom entry point and the console ABI would be gone.