code wiki / _hdl_build / nx_wire_harness.nx

nx_wire_harness.nx source

↩ module page · 60 lines · 3088 B

1// nx_wire_harness.nx -- the SHARED SCAFFOLD extracted from the title-wiring gates (nx_wire_nethack / 2// diablo2 / endlesssky). Each of them independently grew the same four primitives: a packed-pixel 3// frame checksum, a causal binary menu decision, a rolling frame-chain fold, and an experiential 4// verdict. This lib is the ONE definition -- migrate-on-touch per the nx_game_world precedent, so 5// title N+1 wires in fewer lines and every existing title's golden checksum PROVES the extraction was 6// behaviour-preserving (that is the acceptance test, not a hope). OO consolidation that GROWS the 7// recombinator substrate, never shrinks a capability. LIB, no main. license_tier: ORIGINAL 8import "nx_syscalls.nx" 9import "nx_gamehud.nx" 10import "nx_frame_sanity.nx" 11const K_MAGIC_1469598103: i64 = 1469598103 12 13// order-sensitive checksum of a PACKED-pixel frame (v = r | g<<8 | b<<16 -- swgpu/game_raster format). 14// Byte-identical to the d2_fbck/e_fbck bodies it replaces. 15func wh_fbck(fb: *i64, count: i64) -> i64 { 16 var ck: i64 = K_MAGIC_1469598103 17 var i: i64 = 0 18 while i < count { ck = (ck*131 + (fb[i] & 0xFFFFFF)) & 0x7FFFFFFFFFFFFFFF; i = i + 1 } 19 return ck 20} 21 22// fold one frame checksum into a rolling chain (the loop-invariant the render-chains all use) 23func wh_chain(chain: i64, fk: i64) -> i64 { 24 return (chain*131 + (fk & 0xFFFFFFFF)) & 0x7FFFFFFFFFFFFFFF 25} 26 27// the causal tail shared by EVERY menu decision: full-wrap the cursor by n (exercising gh_menu_move's 28// ring arithmetic in both directions per decision, returning to the policy item at index 0) then 29// select. The RETURNED id is what the caller acts on, so inverting the wrap or the caller's response 30// provably breaks the wire = the mutation tooth. Works for menus of ANY size (variable-size callers 31// populate their items first, then call this) -- the growth over a fixed-2 primitive. 32func wh_menu_wrapsel(hud: *i64, n: i64) -> i64 { 33 gh_menu_move(hud, n) 34 return gh_menu_sel(hud) 35} 36// the CAUSAL binary menu: open [a,b] then wrap-select. Returns item a (the policy action) because the 37// full wrap returns to index 0. Now a thin composition over wh_menu_wrapsel (DRY within the harness). 38func wh_menu_pick2(hud: *i64, ida: i64, va: i64, idb: i64, vb: i64) -> i64 { 39 gh_menu_open(hud, 2) 40 gh_menu_item(hud, 0, ida, va) 41 gh_menu_item(hud, 1, idb, vb) 42 return wh_menu_wrapsel(hud, 2) 43} 44 45// count non-background pixels (permil) -- the render non-vacuity signal 46func wh_ink(fb: *i64, count: i64, bg: i64) -> i64 { 47 var n: i64 = 0 48 var i: i64 = 0 49 while i < count { if (fb[i] & 0xFFFFFF) != (bg & 0xFFFFFF) { n = n + 1 } i = i + 1 } 50 return n * 1000 / count 51} 52 53// experiential verdict on a packed-pixel frame with the calibrated real-frame thresholds: 1 = the 54// frame reads as a real scene, 0 = a gross framing/exposure defect. Writes the 5 metrics to out[0..4]. 55func wh_experiential(fb: *i64, w: i64, h: i64, out: *i64) -> i64 { 56 let th: *i64 = sys_mmap(FS_NMETRIC*8) as *i64 57 fs_default_th(th) 58 fs_score_i64(fb, w, h, out) 59 return fs_verdict(out, th) 60}