code wiki / _hdl_build / nx_game_touch_gate.nx

nx_game_touch_gate.nx source

↩ module page · 73 lines · 4343 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" 8 9func tg(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 } 10func tgn(v: i64) -> i64 { 11 if v == 0 { sys_write(1, "0" as *u8, 1); return 0 } 12 var m: i64 = v; if m < 0 { sys_write(1, "-" as *u8, 1); m = 0 - m } 13 let d: *u8 = sys_mmap(24); var k: i64 = 0 14 while m > 0 { d[k] = (48 + (m % 10)) as u8; m = m / 10; k = k + 1 } 15 var j: i64 = k - 1 16 while j >= 0 { sys_write(1, ((d as i64)+j) as *u8, 1); j = j - 1 } 17 return 0 18} 19// substring search: 1 if needle (nul-terminated) occurs in hay[0..haylen) 20func tg_contains(hay: *u8, haylen: i64, needle: *u8) -> i64 { 21 var nl: i64 = 0 22 while needle[nl] != (0 as u8) { nl = nl + 1 } 23 if nl == 0 { return 1 } 24 var i: i64 = 0 25 while i + nl <= haylen { 26 var k: i64 = 0 27 var ok: i64 = 1 28 while k < nl { 29 if hay[i+k] != needle[k] { ok = 0; break } 30 k = k + 1 31 } 32 if ok == 1 { return 1 } 33 i = i + 1 34 } 35 return 0 36} 37 38func main() -> i64 { 39 tg("=== nx_game_touch_gate: sovereign touch-zone brain + the game-page builder carries the wiring ===\n" as *u8) 40 var pass: i64 = 0 41 var fail: i64 = 0 42 let w: i64 = 240 43 let h: i64 = 320 44 45 // PART A -- canonical zones + neg-controls 46 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) } 47 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) } 48 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) } 49 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) } 50 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) } 51 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) } 52 if nx_touch_zone(0, 0, 0, 0) == 0 { pass=pass+1 } else { fail=fail+1; tg(" FAIL invalid-canvas!=0\n" as *u8) } 53 tg(" PART A touch-zone brain: 7 checks\n" as *u8) 54 55 // PART B -- the builder carries the touch wiring 56 let path: *u8 = "web_assets/_game_build/game_page.tpl.html" as *u8 57 let fd: i64 = sys_openat_rd(path) 58 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 } 59 let buf: *u8 = sys_mmap(131072) 60 let n: i64 = sys_read(fd, buf, 131072) 61 sys_close(fd) 62 if tg_contains(buf, n, "touchstart" as *u8)==1 { pass=pass+1 } else { fail=fail+1; tg(" FAIL no touchstart\n" as *u8) } 63 if tg_contains(buf, n, "touchmove" as *u8)==1 { pass=pass+1 } else { fail=fail+1; tg(" FAIL no touchmove\n" as *u8) } 64 if tg_contains(buf, n, "touchend" as *u8)==1 { pass=pass+1 } else { fail=fail+1; tg(" FAIL no touchend\n" as *u8) } 65 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) } 66 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) } 67 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) } 68 tg(" PART B builder carries touch: read " as *u8); tgn(n); tg(" bytes\n" as *u8) 69 70 tg("GAME-TOUCH-GATE pass=" as *u8); tgn(pass); tg(" fail=" as *u8); tgn(fail) 71 if fail == 0 { tg(" verdict=GREEN -- touch-zone brain + builder emits touchstart/move/end->gi_key + touch-action (every game touch-playable)\n" as *u8); sys_exit(0); return 0 } 72 tg(" verdict=RED\n" as *u8); sys_exit(1); return 1 73}