code wiki / _hdl_build / nx_wasm_arcade_gate.nx
nx_wasm_arcade_gate.nx source
↩ module page · 39 lines · 2162 B
1// nx_wasm_arcade_gate.nx -- verifies the BASE-RELATIVE arcade NATIVELY (base = mmap), which is the SAME
2// code the wasm build runs (base = 0). Since there is no browser here, the native render-to-PNG IS the
3// proof the wasm logic+raster are correct (the established "verify wasm by native PNG" loop). license_tier: ORIGINAL expect_exit: 0
4import "nx_syscalls.nx"
5import "nx_wasm_arcade.nx"
6import "nx_png.nx"
7
8func vw(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 }
9func vn(v: i64) -> i64 { let bb: *u8=sys_mmap(28); var m: i64=v; if m<0{m=0-m;sys_write(1,"-" as *u8,1)} 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} var i: i64=0; while i<k{bb[i]=t[k-1-i];i=i+1} sys_write(1,bb,k); return 0 }
10
11func main() -> i64 {
12 let buf: *u8 = sys_mmap(524288)
13 let base: i64 = buf as i64
14 init_impl(base)
15 tick_impl(base, 3)
16 tick_impl(base, 3)
17 tick_impl(base, 3) // walk right to collect goal at (3,0)
18 render_impl(base)
19
20 let st: *i64 = (base + O_ST) as *i64
21 var pass: i64 = 0
22 var total: i64 = 0
23 total=total+1; if st[2] >= 1 { pass=pass+1 } else { vw("W1 FAIL no collect\n") }
24 total=total+1; if st[0] == 3 { if st[1] == 0 { pass=pass+1 } else { vw("W2 FAIL pos\n") } } else { vw("W2 FAIL pos\n") }
25
26 write_png((base + O_FB) as *i64, W, H, "knowledge/nx_wasm_arcade_native.png" as *u8)
27
28 let fb: *i64 = (base + O_FB) as *i64
29 let pc: i64 = fb[(0*CELL+12)*W + (3*CELL+12)] // player at grid (3,0)
30 total=total+1; if (pc & 255) < ((pc >> 8) & 255) { pass=pass+1 } else { vw("W3 FAIL player not green\n") } // G>R
31
32 vw("=== nx_wasm_arcade native verify (base-relative; same code runs in wasm) ===\n")
33 vw(" W="); vn(W); vw(" H="); vn(H); vw(" player=("); vn(st[0]); vw(","); vn(st[1]); vw(") score="); vn(st[2])
34 vw(" -> knowledge/nx_wasm_arcade_native.png\n")
35 vw("WASM-ARCADE-NATIVE "); vn(pass); vw("/"); vn(total); vw("\n")
36 if pass == total { vw("WASM-ARCADE-NATIVE ALL-PASS (base-relative integer game verified; ready for wasm chain)\n"); sys_exit(0) }
37 sys_exit(1)
38 return 1
39}