code wiki / _hdl_build / nx_inline_gate.nx
nx_inline_gate.nx source
↩ module page · 75 lines · 4323 B
1// nx_inline_gate.nx -- VERDICT gate for the INLINE multi-line flow fix. A long inline text run followed
2// by an inline RED marker: before the fix the run reserved ONE line but painted many, so the marker (and
3// every following line) OVERLAPPED line 1. After the fix the run reserves its full height and the marker
4// lands on the LAST line. Asserts the red marker is rendered and sits BELOW line 1 (min red y >= 20),
5// proving no overlap. LIAR-KILL: a never-used color absent. 100% sovereign. license_tier: ORIGINAL
6import "nx_syscalls.nx"
7import "nx_render_html.nx"
8
9func 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 }
10func 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 }
11func 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) }
12// count of (R,G,B) pixels, and set miny[0] to the smallest TOP-DOWN y where one occurs (-1 if none).
13// BMP rows are stored BOTTOM-UP, so top-down y = (h-1) - data_y. miny = the color's topmost visual row.
14func scan_color(data: *u8, off: i64, w: i64, h: i64, R: i64, G: i64, B: i64, miny: *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 first: i64 = 0 - 1
20 var y: i64 = 0
21 while y < h {
22 var x: i64 = 0
23 let rb: i64 = off + y*rowstride
24 let vy: i64 = (h - 1) - y
25 while x < w {
26 let p: i64 = rb + x*3
27 if (data[p]&0xff)==B { if (data[p+1]&0xff)==G { if (data[p+2]&0xff)==R { n=n+1; if first<0 { first=vy } else { if vy<first { first=vy } } } } }
28 x = x+1
29 }
30 y = y+1
31 }
32 miny[0] = first
33 return n
34}
35func chk(cond: i64, label: *u8, pass: *i64) -> i64 {
36 g_w(" " as *u8); g_w(label); g_w(": " as *u8)
37 if cond==1 { g_w("OK\n" as *u8); pass[0]=pass[0]+1 } else { g_w("FAIL\n" as *u8) }
38 return cond
39}
40
41func main() -> i64 {
42 let pass: *i64 = sys_mmap(8) as *i64; pass[0]=0
43 g_w("=== INLINE GATE (multi-line inline run + following marker, sovereign nx_cc->nxasm) ===\n" as *u8)
44
45 // long inline run that wraps in a 200px column, FOLLOWED by an inline red marker. The marker must end
46 // up on the LAST wrapped line (low), not overlapping line 1.
47 let html: *u8 = "<body><div class=\"p\"><style>.p{width:200px}.m{color:#cc0000}</style>This is a long lead paragraph that must wrap across several lines inside a narrow column before reaching the marker at the end. <span class=\"m\">MARKER</span></div></body>\x00" as *u8
48 var hlen: i64 = 0
49 while html[hlen]!=(0 as u8) { hlen=hlen+1 }
50 nx_render_html_to_bmp(html, hlen, "knowledge/status/inline_gate.bmp\x00" as *u8)
51 nx_render_html_to_png(html, hlen, "knowledge/status/inline_gate.png\x00" as *u8)
52
53 let lp: *i64 = sys_mmap(8) as *i64
54 let bmp: *u8 = sys_read_file("knowledge/status/inline_gate.bmp\x00" as *u8, lp)
55 let blen: i64 = lp[0]
56 chk((blen >= 54) as i64, "bmp file >= 54 bytes\x00" as *u8, pass)
57 if blen < 54 { g_w("INLINE rows=4 pass=" as *u8); pn(pass[0]); g_w(" verdict=RED (no image)\n" as *u8); sys_exit(1); return 1 }
58 let off: i64 = u32le(bmp, 10)
59 let w: i64 = u32le(bmp, 18)
60 let h: i64 = u32le(bmp, 22)
61
62 let rminy: *i64 = sys_mmap(8) as *i64
63 let red: i64 = scan_color(bmp, off, w, h, 0xcc, 0, 0, rminy)
64 let gminy: *i64 = sys_mmap(8) as *i64
65 let grn: i64 = scan_color(bmp, off, w, h, 0, 0xff, 0, gminy)
66 g_w(" measured: red_px=" as *u8); pn(red); g_w(" red_min_y=" as *u8); pn(rminy[0]); g_w(" height=" as *u8); pn(h); g_w("\n" as *u8)
67
68 chk((red > 50) as i64, "red marker rendered (>50 px)\x00" as *u8, pass)
69 chk((rminy[0] >= 20) as i64, "marker BELOW line 1 (red min y >= 20) -> no overlap\x00" as *u8, pass)
70 chk((grn == 0) as i64, "LIAR-KILL: green #00ff00 absent\x00" as *u8, pass)
71
72 g_w("INLINE rows=4 pass=" as *u8); pn(pass[0])
73 if pass[0]==4 { g_w(" verdict=GREEN\n" as *u8); sys_exit(0); return 0 }
74 g_w(" verdict=RED\n" as *u8); sys_exit(1); return 1
75}