code wiki / (root) / nx_world_emit.nx

nx_world_emit.nx source

↩ module page · 125 lines · 5601 B

1// nx_world_emit.nx -- NATIVE WORLD-FRAME EMISSION: the sovereign world scene, rendered SERVER-SIDE 2// by the promoted capture instrument (nx_world_snap.elf -- the same nx_wasm_craft engine source the 3// browser wasm is compiled from), PUBLISHED into the world docroot as plain media (PNG) that ANY 4// browser -- Nishi native, Chrome, Waterfox, Edge -- consumes with zero JS, zero wasm, zero WebGL, 5// zero third-party runtime. This ships the browser-board watch contract `we_world_frame_emit` 6// (browser.matrix row: Native world-frame EMISSION path, filed 2026-08-27, operator: "i want to 7// emit i dont want webgl and other 3d parties receiving our work and capabilities"): the 8// capability stops shipping client-side; only the FRAME leaves the estate. 9// COMPOSITION, NOT A TWIN: rendering stays in nx_world_snap (one engine, one ruler); this organ is 10// the missing SHIP LANE for frames -- render -> stage-assert -> atomic rename -> read-back, the 11// founding law of nx_craft_emit's page lane (what LANDED is the claim, never what was written). 12// usage: nx_world_emit [v] [seed] [ticks] (defaults v=1 seed=20260728 ticks=8; out pinned to 13// sites/nishifamily/world/emit_craft.png -- served at /world/emit_craft.png) 14// exit: 0 emitted+read-back-verified | 5 render-or-not-png | 6 deploy-rename | 7 readback 15// license_tier: ORIGINAL No hw writes (Rule 26). 16import "nx_syscalls.nx" 17 18const WE_SNAP: *u8 = "nx_world_snap.elf" as *u8 19const WE_OUT: *u8 = "sites/nishifamily/world/emit_craft.png" as *u8 20const WE_STAGE: *u8 = "sites/nishifamily/world/emit_craft.png.stage" as *u8 21// engine-canonical identity/seed/tick budget: the same values nx_desktop_craft boots with 22// (K_MAGIC_20260728 there), ticks=8 = the settle budget of the first live snap measured 23// 2026-08-27 (WORLD-SNAP v=1 seed=20260728 ticks=8 png_bytes=108223) 24const WE_DEF_V: *u8 = "1" as *u8 25const WE_DEF_SEED: *u8 = "20260728" as *u8 26const WE_DEF_TICKS: *u8 = "8" as *u8 27const WE_STYLE_NONE: *u8 = "-" as *u8 28const WE_PNG_SIG: i64 = 8 29 30func we_slen(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } return n } 31func we_puts(s: *u8) -> i64 { sys_write(1, s, we_slen(s)); return 0 } 32func we_pn(v: i64) -> i64 { 33 if v == 0 { sys_write(1, "0" as *u8, 1); return 0 } 34 var m: i64 = v 35 if m < 0 { sys_write(1, "-" as *u8, 1); m = 0 - m } 36 let t: *u8 = sys_mmap(32) as *u8 37 var k: i64 = 0 38 while m > 0 { t[k] = (48 + (m % 10)) as u8; m = m / 10; k = k + 1 } 39 let o: *u8 = sys_mmap(32) as *u8 40 var i: i64 = 0 41 while i < k { o[i] = t[k - 1 - i]; i = i + 1 } 42 sys_write(1, o, k) 43 return 0 44} 45 46// fork the promoted renderer with its full 5-arg contract; return the child exit (127 = elf absent) 47func we_run5(elf: *u8, a1: *u8, a2: *u8, a3: *u8, a4: *u8, a5: *u8) -> i64 { 48 let pid: i64 = sys_fork() 49 if pid == 0 { 50 let argv: *i64 = sys_mmap(64) as *i64 51 argv[0] = elf as i64 52 argv[1] = a1 as i64 53 argv[2] = a2 as i64 54 argv[3] = a3 as i64 55 argv[4] = a4 as i64 56 argv[5] = a5 as i64 57 argv[6] = 0 58 let envp: *i64 = sys_mmap(16) as *i64 59 envp[0] = 0 60 sys_execve(elf, argv, envp) 61 sys_exit(127) 62 } 63 if pid < 0 { return 0 - 1 } 64 let st: *i64 = sys_mmap(16) as *i64 65 sys_wait4(pid, st, 0) 66 return (st[0] >> 8) & 0xff 67} 68 69func we_png_ok(b: *u8, n: i64) -> i64 { 70 if n < WE_PNG_SIG { return 0 } 71 if (b[0] & 0xff) != 137 { return 0 } 72 if (b[1] & 0xff) != 80 { return 0 } 73 if (b[2] & 0xff) != 78 { return 0 } 74 if (b[3] & 0xff) != 71 { return 0 } 75 if (b[4] & 0xff) != 13 { return 0 } 76 if (b[5] & 0xff) != 10 { return 0 } 77 if (b[6] & 0xff) != 26 { return 0 } 78 if (b[7] & 0xff) != 10 { return 0 } 79 return 1 80} 81 82// THE WATCH-ROW SYMBOL. A native frame of the generated world lands in the served docroot, atomically, 83// and the claim is the read-back of what LANDED. Every stage announces its own numbers. 84func we_world_frame_emit(v: *u8, seed: *u8, ticks: *u8) -> i64 { 85 let rrc: i64 = we_run5(WE_SNAP, WE_STAGE, v, seed, WE_STYLE_NONE, ticks) 86 let np: *i64 = sys_mmap(16) as *i64 87 np[0] = 0 - 1 88 var sb: *u8 = 0 as *u8 89 if rrc == 0 { sb = sys_read_file(WE_STAGE, np) } 90 let n1: i64 = np[0] 91 var sig1: i64 = 0 92 if (sb as i64) != 0 { sig1 = we_png_ok(sb, n1) } 93 we_puts("WE-RENDER rc=" as *u8); we_pn(rrc) 94 we_puts(" stage_bytes=" as *u8); we_pn(n1) 95 we_puts(" png_ok=" as *u8); we_pn(sig1); we_puts("\n" as *u8) 96 if rrc != 0 { return 5 } 97 if sig1 != 1 { return 5 } 98 let drc: i64 = sys_renameat(WE_STAGE, WE_OUT) 99 we_puts("WE-DEPLOY renameat rc=" as *u8); we_pn(drc); we_puts("\n" as *u8) 100 if drc != 0 { return 6 } 101 let np2: *i64 = sys_mmap(16) as *i64 102 np2[0] = 0 - 1 103 let ob: *u8 = sys_read_file(WE_OUT, np2) 104 let n2: i64 = np2[0] 105 var sig2: i64 = 0 106 if (ob as i64) != 0 { sig2 = we_png_ok(ob, n2) } 107 we_puts("WE-READBACK of=" as *u8); we_puts(WE_OUT) 108 we_puts(" bytes=" as *u8); we_pn(n2) 109 we_puts(" png_ok=" as *u8); we_pn(sig2); we_puts("\n" as *u8) 110 if n2 != n1 { return 7 } 111 if sig2 != 1 { return 7 } 112 we_puts("WE-EMIT VERDICT rc=0 wrote=" as *u8); we_puts(WE_OUT) 113 we_puts(" (native frame, plain media, zero client-side capability)\n" as *u8) 114 return 0 115} 116 117func main(argc: i64, argv: *i64) -> i64 { 118 var v: *u8 = WE_DEF_V 119 var seed: *u8 = WE_DEF_SEED 120 var ticks: *u8 = WE_DEF_TICKS 121 if argc > 1 { v = argv[1] as *u8 } 122 if argc > 2 { seed = argv[2] as *u8 } 123 if argc > 3 { ticks = argv[3] as *u8 } 124 return we_world_frame_emit(v, seed, ticks) 125}