Budget one execution window and two dependency slots
The survey needs a terrain cost and a scoring bonus. Both rules fit in a 4 KiB execution window at $6000. Give the disk reader a staging region at $9000 and the loader a 12 KiB REU reservation beginning at $030000. The registry reserves three 4 KiB slots, one for the current module and one for each dependency. This run fills the two dependency slots.
The producer and caller agree on the exported name and signature. Compile the producer first. Its .zpmod.json and .zpmod.relocsim.json tell the caller how to link the signature and prepare relocation. Its .zpmod.disk.prg goes on the disk. Keep those artifacts from the same build.
Compare the exported function with the typed binding
Terrain rule producer
module terrain_rules abi 1 {
export cost;
}
fn cost(terrain: u8) callconv(.stack) u8 {
return terrain + 2;
}
Survey caller
extern module Terrain = terrain_rules {
fn cost(terrain: u8) u8;
}
// In showCosts:
if (Terrain.cost(3)) |before| {
if (FixedMath.bias(4)) |bonus| {
if (Terrain.cost(4)) |after| {
// Use the three results.
}
}
}
Terrain rule source · Scoring rule source · Complete survey caller
Trace disk loads separately from window changes
| Operation | Bytes transferred | Active code |
|---|---|---|
| Acquire both modules | Each disk entry goes through staging to its own REU cache slot. | Neither rule needs the window yet. |
Terrain.cost(3) | Terrain's payload at REU $031000 goes to the window. | Terrain returns 5. |
FixedMath.bias(4) | FixedMath's payload at REU $032000 replaces Terrain's code. | FixedMath returns 7. |
Terrain.cost(4) | Terrain's cached payload returns to the window. | Terrain returns 6. |
The third call can reuse the REU bytes because the caller still owns a reference. The two functions return before the next module takes the window. Code addresses in a shared window are only meaningful for the active module. Keep state that must survive a swap in resident RAM, or reserve a saved state range for the loader to copy out and restore.
In VICE, a trace at the two loader disk paths and the two activation routines shows two disk loads followed by three activations, in the order shown above. The diagnosis chapter shows how to reproduce that observation.
Boot the disk, then remove one dependency
Build both DLLs and boot the survey disk
Expect COST 05 BONUS 07 COST 06 and a green border. Build a second disk that contains boot and terrain only. It should print RULES UNAVAILABLE and set a red border. The caller releases Terrain if FixedMath acquisition fails, and it releases both after the call sequence finishes.
The DLL lifecycle guide extends this example with graph acquire, automatic loading policies, state snapshots, and RAM under ROM. The score updater shows how to combine a cache with a separate REU data arena.