code wiki / _hdl_build / nx_border_gate.nx
nx_border_gate.nx source
↩ module page · 91 lines · 5716 B
1// nx_border_gate.nx -- VERDICT gate for the box-border PAINT rung. Renders a bordered box + a table with
2// bordered cells, reads the BMP back, and asserts each border color is present AS AN OUTLINE (not a fill:
3// the red box border count must be a perimeter, far less than the box area) + dimensions + box count.
4// Proves the `border` shorthand (unblocked by the CSS multi-token fix) actually PAINTS edges. LIAR-KILL:
5// a never-used color (#00ff00) must be absent. Expectations MEASURED via nx_border_probe. 100% sovereign.
6// license_tier: ORIGINAL
7import "nx_syscalls.nx"
8import "nx_render_html.nx"
9import "nx_layout_block.nx" // NX_INLINE_LINE_H -- the page height below is line-derived, not a constant
10
11func g_w(s: *u8) -> i64 { var k: i64=0; while s[k]!=(0 as u8){k=k+1} sys_write(1,s,k); return 0 }
12func pn(v0: i64) -> i64 { var v: i64=v0; if v<0 { let m: *u8=sys_mmap(8); m[0]=45 as u8; sys_write(1,m,1); v=0-v } let b: *u8=sys_mmap(24); var k: i64=0; if v==0 {b[0]=48;k=1} while v>0 {b[k]=(48+(v%10)) as u8; v=v/10; k=k+1} let o: *u8=sys_mmap(24); var j: i64=0; while j<k {o[j]=b[k-1-j];j=j+1} sys_write(1,o,k); return 0 }
13func u32le(d: *u8, p: i64) -> i64 { return (d[p]&0xff) + ((d[p+1]&0xff)<<8) + ((d[p+2]&0xff)<<16) + ((d[p+3]&0xff)<<24) }
14func col_count(data: *u8, off: i64, w: i64, h: i64, R: i64, G: i64, B: i64) -> i64 {
15 let row3: i64 = w*3
16 let pad: i64 = (4-(row3%4))%4
17 let rowstride: i64 = row3+pad
18 var n: i64 = 0
19 var y: i64 = 0
20 while y < h {
21 var x: i64 = 0
22 let rowbase: i64 = off + y*rowstride
23 while x < w {
24 let p: i64 = rowbase + x*3
25 if (data[p]&0xff)==B { if (data[p+1]&0xff)==G { if (data[p+2]&0xff)==R { n=n+1 } } }
26 x = x+1
27 }
28 y = y+1
29 }
30 return n
31}
32func chk(cond: i64, label: *u8, pass: *i64) -> i64 {
33 g_w(" " as *u8); g_w(label); g_w(": " as *u8)
34 if cond==1 { g_w("OK\n" as *u8); pass[0]=pass[0]+1 } else { g_w("FAIL\n" as *u8) }
35 return cond
36}
37func chkv(got: i64, want: i64, label: *u8, pass: *i64) -> i64 {
38 g_w(" " as *u8); g_w(label); g_w(": " as *u8)
39 if got==want { g_w("OK (" as *u8); pn(got); g_w(")\n" as *u8); pass[0]=pass[0]+1 }
40 else { g_w("FAIL got=" as *u8); pn(got); g_w(" want=" as *u8); pn(want); g_w("\n" as *u8) }
41 return 0
42}
43
44func main() -> i64 {
45 let pass: *i64 = sys_mmap(8) as *i64; pass[0]=0
46 g_w("=== BORDER GATE (box-border paint, asserted pixels, sovereign nx_cc->nxasm) ===\n" as *u8)
47
48 let html: *u8 = "<body><h1>Borders</h1><style>.boxed{border:5px solid #cc0000;background-color:#ffffff;height:60px;width:300px;padding-left:8px;padding-top:8px}table{border:2px solid #3333cc}td{border:1px solid #999999;padding-left:6px;padding-right:6px}</style><div class=\"boxed\">A bordered box.</div><table><tr><td>Cell A</td><td>Cell B</td></tr><tr><td>Cell C</td><td>Cell D</td></tr></table></body>\x00" as *u8
49 var hlen: i64 = 0
50 while html[hlen]!=(0 as u8) { hlen=hlen+1 }
51
52 let nbmp: i64 = nx_render_html_to_bmp(html, hlen, "knowledge/status/border_gate.bmp\x00" as *u8)
53 nx_render_html_to_png(html, hlen, "knowledge/status/border_gate.png\x00" as *u8) // viewable artifact
54 chkv(nbmp, 18, "box count == 18\x00" as *u8, pass)
55
56 let lp: *i64 = sys_mmap(8) as *i64
57 let bmp: *u8 = sys_read_file("knowledge/status/border_gate.bmp\x00" as *u8, lp)
58 let blen: i64 = lp[0]
59 chk((blen >= 54) as i64, "bmp file >= 54 bytes\x00" as *u8, pass)
60 if blen < 54 { g_w("BORDER rows=11 pass=" as *u8); pn(pass[0]); g_w(" verdict=RED (no image)\n" as *u8); sys_exit(1); return 1 }
61 chk(((bmp[0]&0xff)==66) as i64 * (((bmp[1]&0xff)==77) as i64), "BMP signature 'BM'\x00" as *u8, pass)
62 let off: i64 = u32le(bmp, 10)
63 let w: i64 = u32le(bmp, 18)
64 let h: i64 = u32le(bmp, 22)
65 chkv(w, 800, "width == 800\x00" as *u8, pass)
66 // Page height is NOT a constant: fixed chrome plus N text lines, and the line term moves with the
67 // font. Hardcoding 138 was correct only while NX_INLINE_LINE_H was 10; when the renderer adopted
68 // real 9x15 metrics (17) this read 173 and went RED with every colour/width/outline assertion still
69 // passing. DERIVED, not guessed: 138 at LH=10 and 173 at LH=17 give N=5 lines and chrome 138-50=88.
70 let BORDER_CHROME_PX: i64 = 88
71 let BORDER_TEXT_LINES: i64 = 5
72 chkv(h, BORDER_CHROME_PX + BORDER_TEXT_LINES * NX_INLINE_LINE_H, "height == chrome + 5 lines\x00" as *u8, pass)
73
74 // red .boxed border: PRESENT (painted) AND an OUTLINE not a fill. The box is 300x68 = 20400 px; an
75 // outline is a ~3.5k-px perimeter, a (buggy) fill would be ~20400. So 1000 < count < 10000 proves edge.
76 let red: i64 = col_count(bmp, off, w, h, 0xcc, 0, 0)
77 chk((red > 1000) as i64, "red border #cc0000 painted (>1000 px)\x00" as *u8, pass)
78 chk((red < 10000) as i64, "red border is OUTLINE not fill (<10000 px of a 20400 px box)\x00" as *u8, pass)
79 g_w(" (measured red px=" as *u8); pn(red); g_w(")\n" as *u8)
80
81 chk((col_count(bmp, off, w, h, 0x33, 0x33, 0xcc) > 500) as i64, "table border #3333cc painted\x00" as *u8, pass)
82 chk((col_count(bmp, off, w, h, 0x99, 0x99, 0x99) > 500) as i64, "td cell borders #999999 painted\x00" as *u8, pass)
83 chk((col_count(bmp, off, w, h, 255, 255, 255) > 10000) as i64, "white interiors present\x00" as *u8, pass)
84
85 // LIAR-KILL: a color the page never uses must be ABSENT (scanner has teeth)
86 chk((col_count(bmp, off, w, h, 0, 0xff, 0) == 0) as i64, "LIAR-KILL: green #00ff00 absent\x00" as *u8, pass)
87
88 g_w("BORDER rows=11 pass=" as *u8); pn(pass[0])
89 if pass[0]==11 { g_w(" verdict=GREEN\n" as *u8); sys_exit(0); return 0 }
90 g_w(" verdict=RED\n" as *u8); sys_exit(1); return 1
91}