code wiki / _hdl_build / nx_game_touch_gate.nx

nx_game_touch_gate.nx source

↩ module page · 81 lines · 4730 B

1// nx_game_touch_gate.nx -- proves mobile game touch input, NO fake green. PART A: the sovereign zone brain 2// (nx_touch_zone) maps the 5 canonical zones to the right keyCodes + neg-controls (left is never RIGHT; 3// an invalid canvas yields no key). PART B: the game-page BUILDER (web_assets/_game_build/game_page.tpl.html) 4// actually CARRIES the touch wiring (touchstart/touchmove/touchend forwarding to gi_key + touch-action css) -- 5// read from disk, with a neg-control so the contains-check has teeth. expect_exit: 0 license_tier: ORIGINAL 6import "nx_syscalls.nx" 7import "nx_game_touch.nx" 8import "nx_gate_verdict.nx" 9 10func tg(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 } 11func tgn(v: i64) -> i64 { 12 if v == 0 { sys_write(1, "0" as *u8, 1); return 0 } 13 var m: i64 = v; if m < 0 { sys_write(1, "-" as *u8, 1); m = 0 - m } 14 let d: *u8 = sys_mmap(24); var k: i64 = 0 15 while m > 0 { d[k] = (48 + (m % 10)) as u8; m = m / 10; k = k + 1 } 16 var j: i64 = k - 1 17 while j >= 0 { sys_write(1, ((d as i64)+j) as *u8, 1); j = j - 1 } 18 return 0 19} 20// substring search: 1 if needle (nul-terminated) occurs in hay[0..haylen) 21func tg_contains(hay: *u8, haylen: i64, needle: *u8) -> i64 { 22 var nl: i64 = 0 23 while needle[nl] != (0 as u8) { nl = nl + 1 } 24 if nl == 0 { return 1 } 25 var i: i64 = 0 26 while i + nl <= haylen { 27 var k: i64 = 0 28 var ok: i64 = 1 29 while k < nl { 30 if hay[i+k] != needle[k] { ok = 0; break } 31 k = k + 1 32 } 33 if ok == 1 { return 1 } 34 i = i + 1 35 } 36 return 0 37} 38 39func main() -> i64 { 40 tg("=== nx_game_touch_gate: sovereign touch-zone brain + the game-page builder carries the wiring ===\n" as *u8) 41 var pass: i64 = 0 42 var fail: i64 = 0 43 let w: i64 = 240 44 let h: i64 = 320 45 46 // PART A -- canonical zones + neg-controls 47 if nx_touch_zone(w/2, 1, w, h) == 38 { pass=pass+1 } else { fail=fail+1; tg(" FAIL top-center!=UP\n" as *u8) } 48 if nx_touch_zone(w/2, h-1, w, h) == 40 { pass=pass+1 } else { fail=fail+1; tg(" FAIL bottom-center!=DOWN\n" as *u8) } 49 if nx_touch_zone(1, h/2, w, h) == 37 { pass=pass+1 } else { fail=fail+1; tg(" FAIL mid-left!=LEFT\n" as *u8) } 50 if nx_touch_zone(w-1, h/2, w, h) == 39 { pass=pass+1 } else { fail=fail+1; tg(" FAIL mid-right!=RIGHT\n" as *u8) } 51 if nx_touch_zone(w/2, h/2, w, h) == 32 { pass=pass+1 } else { fail=fail+1; tg(" FAIL center!=SPACE\n" as *u8) } 52 if nx_touch_zone(1, h/2, w, h) != 39 { pass=pass+1 } else { fail=fail+1; tg(" FAIL left mapped RIGHT\n" as *u8) } 53 if nx_touch_zone(0, 0, 0, 0) == 0 { pass=pass+1 } else { fail=fail+1; tg(" FAIL invalid-canvas!=0\n" as *u8) } 54 tg(" PART A touch-zone brain: 7 checks\n" as *u8) 55 56 // PART B -- the builder carries the touch wiring 57 let path: *u8 = "web_assets/_game_build/game_page.tpl.html" as *u8 58 let fd: i64 = sys_openat_rd(path) 59 if fd < 0 { tg(" FAIL cannot open game_page.tpl.html\n" as *u8); tg("GAME-TOUCH-GATE verdict=RED\n" as *u8); sys_exit(1); return 1 } 60 let buf: *u8 = sys_mmap(131072) 61 let n: i64 = sys_read(fd, buf, 131072) 62 sys_close(fd) 63 if tg_contains(buf, n, "touchstart" as *u8)==1 { pass=pass+1 } else { fail=fail+1; tg(" FAIL no touchstart\n" as *u8) } 64 if tg_contains(buf, n, "touchmove" as *u8)==1 { pass=pass+1 } else { fail=fail+1; tg(" FAIL no touchmove\n" as *u8) } 65 if tg_contains(buf, n, "touchend" as *u8)==1 { pass=pass+1 } else { fail=fail+1; tg(" FAIL no touchend\n" as *u8) } 66 if tg_contains(buf, n, "gi_key" as *u8)==1 { pass=pass+1 } else { fail=fail+1; tg(" FAIL no gi_key forward\n" as *u8) } 67 if tg_contains(buf, n, "touch-action" as *u8)==1 { pass=pass+1 } else { fail=fail+1; tg(" FAIL no touch-action css\n" as *u8) } 68 if tg_contains("no touch here" as *u8, 13, "touchstart" as *u8)==0 { pass=pass+1 } else { fail=fail+1; tg(" FAIL neg-control (false match)\n" as *u8) } 69 tg(" PART B builder carries touch: read " as *u8); tgn(n); tg(" bytes\n" as *u8) 70 71 tg("GAME-TOUCH-GATE pass=" as *u8); tgn(pass); tg(" fail=" as *u8); tgn(fail) 72 // MIGRATED onto nx_gate_verdict by nx_gate_dry_apply (D001, minimal form): every check 73 // row above is untouched, so the PASS/FAIL vector cannot change; only the hand-rolled 74 // verdict emission is replaced by the ONE shared base class. Proven by nx_gate_migrate verify. 75 let ctr__dry: *i64 = gv_ctr() 76 ctr__dry[0] = pass 77 ctr__dry[1] = pass + fail 78 let rc__dry: i64 = gv_verdict("GAME-TOUCH-GATE" as *u8, ctr__dry, "touch-zone brain + builder emits touchstart/move/end->gi_key + touch-action (every game touch-playable)" as *u8) 79 sys_exit(rc__dry) 80 return rc__dry 81}