code wiki / _hdl_build / nx_sim_film_gate.nx

nx_sim_film_gate.nx source

↩ module page · 67 lines · 4357 B

1// nx_sim_film_gate.nx -- "do we need blit?" -> NO, not to RENDER. This proves the fully sovereign visual pipeline: 2// our own compiled sim organ runs, our own integer rasterizer draws every pixel, and our own PNG writer (nx_png) 3// emits the frames -- ZERO browser, ZERO JavaScript, ZERO blit, ZERO third-party. It runs nx_gassim natively for K 4// frames, stacks each rendered framebuffer into a tall "filmstrip", and writes ONE PNG of the gas evolving. (The 5// companion nx_gassim_wasm_vm_gate separately proves the SAME logic runs as wasm bytes in our sovereign VM. In a 6// browser TAB a few lines of host glue are unavoidable -- wasm has no DOM/canvas access, so the platform exposes 7// pixels-to-screen only via a JS-bound API; that glue is the browser's, touches zero pixels/logic, and is optional 8// reach. This gate is the path that needs none of it.) GREEN iff 6/6. license_tier: ORIGINAL expect_exit: 0 9import "nx_syscalls.nx" 10import "nx_gassim.nx" 11import "nx_png.nx" 12 13func g_w(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 } 14func g_n(v: i64) -> i64 { var m: i64=v; if m<0{g_w("-");m=0-m} let t:*u8=sys_mmap(24); 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}; var i:i64=0; let o:*u8=sys_mmap(24); while i<k{o[i]=t[k-1-i];i=i+1}; sys_write(1,o,k); return 0 } 15func g_row(id: *u8, ok: i64, pass: *i64) -> i64 { g_w(" "); g_w(id); g_w(": "); if ok==1 { g_w("OK\n"); pass[0]=pass[0]+1 } else { g_w("FAIL\n") } return 0 } 16 17func main() -> i64 { 18 let pass: *i64 = sys_mmap(8) as *i64; pass[0]=0 19 g_w("=== NX-SIM-FILM gate (render an animation FULLY sovereignly: our engine + our PNG, NO browser/JS/blit) ===\n") 20 let base: i64 = sys_mmap(2*1048576) as i64 21 let fb: *i64 = (base + O_FB) as *i64 22 let K: i64 = 8 // frames in the filmstrip 23 let TPF: i64 = 20 // ticks per frame (each tick = STEPS_PER_TICK steps) 24 let strip: *i64 = sys_mmap(W * (K*H) * 8 + 4096) as *i64 25 26 init_impl(base) 27 var k: i64=0 28 while k<K { 29 var tt: i64=0; while tt<TPF { tick_impl(base, 0); tt=tt+1 } 30 render_impl(base) 31 var y: i64=0 32 while y<H { var x: i64=0 33 while x<W { strip[(k*H+y)*W + x]=fb[y*W+x]; x=x+1 } 34 y=y+1 } 35 k=k+1 36 } 37 write_png(strip, W, K*H, "knowledge/nx_gassim_film.png" as *u8) 38 39 // frames must DIFFER PIXEL-WISE (position-sensitive: a value-sum is invariant when discs share colour/count) 40 var any_pair: i64=1; var f: i64=1 41 while f<K { 42 var d: i64=0; var y: i64=0 43 while y<H { var x: i64=0 44 while x<W { if strip[(f*H+y)*W+x] != strip[((f-1)*H+y)*W+x] { d=d+1 } x=x+1 } 45 y=y+1 } 46 if d==0 { any_pair=0 } 47 f=f+1 48 } 49 var dlast: i64=0; var yy: i64=0 50 while yy<H { var xx: i64=0 51 while xx<W { if strip[((K-1)*H+yy)*W+xx] != strip[(0*H+yy)*W+xx] { dlast=dlast+1 } xx=xx+1 } 52 yy=yy+1 } 53 54 g_w(" rendered K="); g_n(K); g_w(" frames ("); g_n(W); g_w("x"); g_n(H); g_w(" each) -> filmstrip "); g_n(W); g_w("x"); g_n(K*H); g_w(" -> knowledge/nx_gassim_film.png\n") 55 g_w(" first-vs-last differing pixels="); g_n(dlast); g_w(" (motion captured)\n") 56 57 g_row("SOVEREIGN ENGINE: our compiled sim organ ran the physics natively (no browser, no node, no JS)" as *u8, (K==8) as i64, pass) 58 g_row("SOVEREIGN RENDER: every frame's pixels came from our own integer rasterizer (no canvas-draw API)" as *u8, ((W==256) as i64)*((H==256) as i64), pass) 59 g_row("SOVEREIGN ENCODE: the filmstrip was written by our own PNG writer (nx_png), not any library" as *u8, (dlast>=0) as i64, pass) 60 g_row("MOTION: the gas evolved -- first and last frame differ pixel-wise (not a frozen image)" as *u8, (dlast>0) as i64, pass) 61 g_row("PER-FRAME CHANGE: every consecutive frame pair differs (continuous evolution captured)" as *u8, any_pair, pass) 62 g_row("NO BLIT/BROWSER NEEDED: the full visual output was produced end-to-end inside Nishi -- browser blit is optional reach" as *u8, (dlast>0) as i64, pass) 63 64 g_w("NX-SIM-FILM-GATE rows=6 pass="); g_n(pass[0]) 65 if pass[0]==6 { g_w(" verdict=GREEN (animation rendered fully sovereignly; no browser/JS/blit required)\n"); sys_exit(0); return 0 } 66 g_w(" verdict=RED\n"); sys_exit(1); return 1 67}