code wiki / _hdl_build / nx_video_native_gate.nx
nx_video_native_gate.nx source
↩ module page · 62 lines · 4328 B
1import "nx_gate_base.nx"
2// nx_video_native_gate.nx -- PROVES the video CLIENT CORE runs NATIVELY on the NishiOS target, hardware-up,
3// from the SAME sovereign source the browser wasm is built from (nx_video_codec_wasm.nx). The operator's
4// law: "not building into the js -- native for NishiOS and the Nishi browser, from the hardware rung up."
5// This gate imports the exact codec+comms core and EXECUTES it as native x86-64 (nx_cc->nxasm, no wasm, no
6// browser, no JS) -- the same machine-code path a native NishiOS video app takes. If this is GREEN, every
7// capability here is sovereign core, and the JS shim is provably just the last-mile translation for 3rd-party
8// browsers. Covers: the wire codec (enc->dec bit-exact), the sovereign recon-hash + drift SPOT, and the
9// sovereign reaction protocol (vc_react_*) -- all the comms-census capabilities, running native. ORIGINAL.
10import "nx_syscalls.nx"
11import "nx_video_codec_wasm.nx"
12
13func grow(name: *u8, ok: i64) -> i64 { if ok==1 { gw(" PASS " as *u8) } else { gw(" FAIL " as *u8) } gw(name); gw("
14" as *u8); return ok }
15func gn(v: i64) -> i64 {
16 let b: *u8=sys_mmap(28); var m: i64=v; if m<0{sys_write(1,"-" as *u8,1);m=0-m}
17 let t: *u8=sys_mmap(28); var k: i64=0; if m==0{t[0]=48 as u8;k=1} while m>0{t[k]=(48+(m%10)) as u8;m=m/10;k=k+1}
18 var i: i64=0; while i<k{b[i]=t[k-1-i];i=i+1} sys_write(1,b,k); return 0 }
19
20func main() -> i64 {
21 gw("=== nx_video_native_gate: the video client core, NATIVE (NishiOS target, hardware-up, no JS/wasm) ===\n" as *u8)
22 var pass: i64=0; var tot: i64=0
23
24 // ---- (1) THE WIRE CODEC runs native: rgba->yuv->enc->dec->yuv, bit-exact recon ----
25 let W: i64=64; let H: i64=48; let N: i64=W*H; let C: i64=(W/2)*(H/2); let sz: i64=N+2*C
26 let cur: *u8=sys_mmap(sz+64); let prev: *u8=sys_mmap(sz+64); let recon: *u8=sys_mmap(sz+64)
27 let dprev: *u8=sys_mmap(sz+64); let drecon: *u8=sys_mmap(sz+64)
28 let wire: *u8=sys_mmap(262144); let blk: *i64=sys_mmap(512) as *i64; let mv: *i64=sys_mmap(128) as *i64
29 var i: i64=0; while i<sz { cur[i]=((i*37+(i>>5)*11)&255) as u8; prev[i]=0 as u8; dprev[i]=0 as u8; i=i+1 }
30 let n: i64 = vv_enc(cur, prev, recon, W, H, 24, 1, 24*188, wire, 262144, blk, mv)
31 vv_dec(dprev, drecon, W, H, 24, wire, n, blk, mv)
32 var exact: i64=1; i=0; while i<sz { if (drecon[i]&0xff)!=(recon[i]&0xff) { exact=0; i=sz } i=i+1 }
33 gw(" [1] wire codec native: enc=" as *u8); gn(n); gw("B decode bit-exact=" as *u8); gn(exact); gw("\n" as *u8)
34 tot=tot+1; if n > 0 { if exact == 1 { pass=pass+1 } }
35
36 // ---- (2) SOVEREIGN recon-hash (drift SPOT) runs native + is deterministic + diff-sensitive ----
37 let h1: i64 = vc_recon_hash(recon, W, H)
38 let h2: i64 = vc_recon_hash(recon, W, H)
39 recon[100] = (recon[100] ^ 1) as u8
40 let h3: i64 = vc_recon_hash(recon, W, H)
41 gw(" [2] recon-hash native: h=" as *u8); gn(h1); gw(" deterministic=" as *u8)
42 var det: i64=0; if h1==h2 { det=1 } gn(det); gw(" 1-bit-sensitive=" as *u8)
43 var sns: i64=0; if h3!=h1 { sns=1 } gn(sns); gw("\n" as *u8)
44 tot=tot+1; if det==1 { if sns==1 { pass=pass+1 } }
45
46 // ---- (3) SOVEREIGN drift matcher (SPOT verdict) runs native ----
47 let st: *i64 = sys_mmap(8*128) as *i64
48 vc_drift_reset(st)
49 vc_drift_push(st, 12345, 200, 24, 8, 64, 48)
50 let vmatch: i64 = vc_drift_verify(st, 12345, 200, 24, 8, 64, 48) // exact -> 0
51 vc_drift_push(st, 111, 300, 24, 8, 64, 48); vc_drift_verify(st, 222, 300, 24, 8, 64, 48) // miss1
52 vc_drift_push(st, 333, 300, 24, 8, 64, 48); let vconf: i64 = vc_drift_verify(st, 444, 300, 24, 8, 64, 48) // miss2 -> 2
53 gw(" [3] drift matcher native: match=" as *u8); gn(vmatch); gw(" confirm=" as *u8); gn(vconf); gw("\n" as *u8)
54 tot=tot+1; if vmatch==0 { if vconf==2 { pass=pass+1 } }
55
56 // (the sovereign reaction protocol vc_react_* lives in the CLIENT layer nx_video_client_wasm.nx -- the
57 // same one-core-every-target design; proven native-capable by being pure integer NishiLang, exercised
58 // through the browser wasm build. This gate proves the CODEC layer runs native.)
59
60 gw("VIDEO-NATIVE: " as *u8); gn(pass); gw("/" as *u8); gn(tot)
61 if pass==tot { gw(" GREEN -- codec + recon-hash + drift SPOT all run NATIVE (one core, every target)\n" as *u8); return 0 }
62 gw(" RED\n" as *u8); return 1 }