code wiki / _hdl_build / nx_game_engine_gate.nx

nx_game_engine_gate.nx source

↩ module page · 56 lines · 3162 B

1// nx_game_engine_gate.nx -- the GAME-ENGINE surface gate (X-SURF-003 rung1). Drives 2// the REAL composed game loop + the actor game-logic test through the sovereign lane; 3// both green = the engine runs end-to-end on the hardware FLOOR (the compose test's 4// 16x16x8 terrain + 1bpp framebuffer + raycast map cleanly to ESP32-class silicon -- 5// product reaches the hardware rung, the operator's "from the hardware up"). 6// Durable: GAMEENGINE rows + verdict -> knowledge/status/game_engine.log (the surface 7// census reads this). Exit 0 iff both legs green. license_tier: ORIGINAL 8import "nx_syscalls.nx" 9func ge_p(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 } 10func ge_f(fd: i64, s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(fd,s,n); return 0 } 11func ge_n(fd: i64, v: i64) -> i64 { let bb: *u8=sys_mmap(28); var m: i64=v; if m<0{m=0-m}; 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(fd,bb,k); return 0 } 12func ge_run(name: *u8) -> i64 { 13 let pid: i64 = sys_fork() 14 if pid == 0 { 15 let dn: i64 = sys_openat_wr("/dev/null" as *u8, 0x1a4) 16 if dn >= 0 { sys_dup3(dn, 1, 0); sys_dup3(dn, 2, 0) } 17 let argv: *i64 = sys_mmap(32) as *i64 18 argv[0] = "_offc/nx_sov_build_run.elf" as *u8 as i64 19 argv[1] = name as i64 20 argv[2] = 0 21 let envp: *i64 = sys_mmap(16) as *i64 22 envp[0] = 0 23 sys_execve("_offc/nx_sov_build_run.elf" as *u8, argv, envp) 24 sys_exit(127) 25 } 26 let st: *i64 = sys_mmap(16) as *i64 27 sys_wait4(pid, st, 0) 28 if (st[0] % 128) != 0 { return 0 - 1 } 29 return (st[0] >> 8) & 0xff 30} 31func ge_leg(lfd: i64, name: *u8, bad: *i64) -> i64 { 32 let rc: i64 = ge_run(name) 33 ge_f(lfd, "GAMEENGINE-LEG name=" as *u8); ge_f(lfd, name) 34 ge_f(lfd, " rc=" as *u8); ge_n(lfd, rc) 35 if rc == 0 { ge_f(lfd, " verdict=GREEN\n" as *u8) } else { ge_f(lfd, " verdict=RED\n" as *u8); bad[0] = bad[0] + 1 } 36 ge_p(" " as *u8); ge_p(name) 37 if rc == 0 { ge_p(": green\n" as *u8) } else { ge_p(": RED\n" as *u8) } 38 return 0 39} 40func main() -> i64 { 41 ge_p("=== GAME-ENGINE GATE: the composed loop runs end-to-end on the hardware floor ===\n" as *u8) 42 let lfd: i64 = sys_openat_append("knowledge/status/game_engine.log" as *u8, 0x1a4) 43 if lfd < 0 { ge_p(" game_engine log open failed\n" as *u8); sys_exit(1); return 1 } 44 let bad: *i64 = sys_mmap(16) as *i64 45 bad[0] = 0 46 ge_leg(lfd, "nx_game_engine_compose_test" as *u8, bad) 47 ge_leg(lfd, "nx_actor_role_game_logic_test" as *u8, bad) 48 ge_f(lfd, "GAMEENGINE epoch=" as *u8); ge_n(lfd, sys_now_realtime_sec()) 49 ge_f(lfd, " legs=2 red=" as *u8); ge_n(lfd, bad[0]) 50 if bad[0] == 0 { ge_f(lfd, " verdict=GREEN\n" as *u8) } else { ge_f(lfd, " verdict=RED\n" as *u8) } 51 sys_close(lfd) 52 if bad[0] == 0 { ge_p(" GAME-ENGINE GATE: GREEN (terrain+framebuffer+raycast+input+fixedpt, ESP32-class floor)\n" as *u8); sys_exit(0); return 0 } 53 ge_p(" GAME-ENGINE GATE: RED\n" as *u8) 54 sys_exit(1) 55 return 1 56}