code wiki / _hdl_build / nx_nishios_docview.nx
nx_nishios_docview.nx source
↩ module page · 406 lines · 23627 B
1// nx_nishios_docview.nx -- DOC-OMNITOOL-ON-ALL-OS, rung N-DOC-1: NishiOS OPENS DOCUMENTS.
2//
3// Operator (2026-07-08): "i want nishi browser and os to support rendering these different docs ... the
4// browser is becoming the workhorse of systems." The Linux browser side shipped (nx_browser + nx_doc_view
5// fork-dispatch, gate 7/7, live PNG proof). This rung puts the same capability on NISHIOS, following the
6// proven nx_nishios_browser idiom: boot the persisted NishiOS image on the sovereign x86 emu, and ONLY
7// because the disk-loaded kernel reached LONG mode does the OS app layer open a DOCUMENT -- a persisted
8// .md file read back off disk -> the ON-OS VIEWER REGISTRY (ext -> renderer id; NishiOS has no process
9// fork yet, so renderers LINK as libs (nx_md_lib) and are invoked at ONE dispatch point; adding a format =
10// one registry row + one lib import, the dispatch core never changes) -> md_to_html -> br_layout ->
11// br_draw_fb -> composited into the NishiOS desktop as a "NISHI DOCS" window. Export = knowledge/status/
12// nishios_docview.bmp + .html = one picture of "boot NishiOS -> open report.md natively".
13//
14// KAT: T1 booted off the persisted image; T2 LONG mode; T3 UART banner 'NishiOS'; T4 registry routes .md
15// AND refuses .xyz; T5 conversion real (h1/bold/link/blockquote/pre markers in the produced HTML);
16// T6 REAL layout (ok, boxes>=15, page_h>=100); T7 heading ink pixels; T8 link-blue pixels; T9 body-text
17// pixels; T10 BMP exact size; T11 NEG 0-sector image never reaches long mode -> viewer never fires;
18// T12 NEG empty document collapses the box count vs the real document (content-sensitive evidence).
19//
20// HONEST SEAM (same as nx_nishios_browser): the emu EXECUTES the MBR loader + real->protected->long
21// transition off the on-disk bytes; the doc pipeline then runs in NishiLang as the OS's app layer painting
22// nx_fb. Renderers as x86-on-emu processes via nx_nxe_loader, on-OS networking, and live input remain
23// future rungs -- named, not claimed. MEASURED (BMP palette probe, 07-09): on this author-styled page the
24// render core paints its DEFAULT ink palette -- headings #14142b (20,20,43), body #202124 (32,33,36) --
25// author-CSS text colors (link-blue, pre backgrounds) are NOT yet applied; that render-core CSS-color rung
26// is likewise named, not claimed. The pixel KATs below assert the MEASURED palette, not a wished one.
27// NEVER-BRICK (Rule 26): FILE artifacts only; models INT 13h *reads*.
28// expect_exit: 0 license_tier: ORIGINAL
29import "nx_browser_render.nx"
30import "nx_itoa_lib.nx" // shared MSB-first emitter (zero-alloc)
31import "nx_fb.nx"
32import "nx_md_lib.nx"
33const ND_MAGIC_200000: i64 = 200000
34const ND_MAGIC_32767: i64 = 32767
35const ND_MAGIC_65536: i64 = 65536
36const ND_MAGIC_1048576: i64 = 1048576
37
38func nd_puts(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 }
39// MIGRATED to the shared emitter (debt 1785563586). The old body mmapped a scratch buffer
40// per call and never freed it. At PAGE granularity that is 4096B leaked PER CALL -- the
41// defect that took 28.5GB of a 36GB host in nx_ts_lumadiff (2MB input, ~3.66M calls).
42// nxi_* is MSB-first, allocates NOTHING, and emits identical bytes including the sign.
43func nd_num(v: i64) -> i64 { nxi_out(v); return 0 }
44func nd_slen(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} return n }
45func nd_contains(hay: *u8, hn: i64, ndl: *u8, nn: i64) -> i64 {
46 if nn==0 { return 1 }
47 var i: i64 = 0
48 while i + nn <= hn { var j: i64 = 0; var ok: i64 = 1; while j < nn { if hay[i+j]!=ndl[j] { ok=0; j=nn } else { j=j+1 } } if ok==1 { return 1 } i=i+1 }
49 return 0
50}
51func nd_mode(cr0: i64, efer: i64) -> i64 { let pe: i64=cr0&1; let pg: i64=(cr0>>31)&1; let lme: i64=(efer>>8)&1; if pe==0 { return 0 } if pg==1 { if lme==1 { return 2 } } return 1 }
52
53// UNIFIED boot-disk emu (verbatim from the proven nx_nishios_browser rung): 16-bit real-mode + INT 13h/
54// INT 10h PLUS 64-bit mov + CR0/EFER mode transition. st[0]=final cr0, st[1]=final mode.
55func nd_emu_boot_disk(mem: *u8, disk: *u8, entry: i64, console: *u8, clen: *i64, st: *i64) -> i64 {
56 var ip: i64=entry
57 var ax: i64=0
58 var bx: i64=0
59 var cx: i64=0
60 var dx: i64=0
61 var si: i64=0
62 var zf: i64=0
63 var rax: i64=0
64 var cr0: i64=0
65 var efer: i64=0
66 var guard: i64=0
67 st[0]=0; st[1]=0
68 while guard < ND_MAGIC_200000 {
69 guard = guard + 1
70 let op: i64 = mem[ip] as i64
71 if op == 0xF4 { st[0]=cr0; st[1]=nd_mode(cr0,efer); return 0 }
72 var h: i64 = 0
73 if h==0 { if op==0x48 {
74 if mem[ip+1]==(0xC7 as u8) {
75 let modrm: i64 = mem[ip+2] as i64
76 let imm: i64 = (mem[ip+3] as i64) | ((mem[ip+4] as i64)<<8) | ((mem[ip+5] as i64)<<16) | ((mem[ip+6] as i64)<<24)
77 if modrm==0xC0 { rax = imm }
78 ip=ip+7; h=1
79 }
80 } }
81 if h==0 { if op==0x0F {
82 let b1: i64 = mem[ip+1] as i64
83 if b1==0x22 { let m: i64=mem[ip+2] as i64; if ((m>>3)&7)==0 { cr0=rax }; ip=ip+3; h=1 }
84 if h==0 { if b1==0x30 { efer=rax; ip=ip+2; h=1 } }
85 if h==0 { if b1==0x05 { st[0]=cr0; st[1]=nd_mode(cr0,efer); return rax & 0xff } }
86 if h==0 { return 0 - 1 }
87 } }
88 if h==0 { if op==0xBE { si = (mem[ip+1] as i64) | ((mem[ip+2] as i64)<<8); ip=ip+3; h=1 } }
89 if h==0 { if op==0xB8 { ax = (mem[ip+1] as i64) | ((mem[ip+2] as i64)<<8); ip=ip+3; h=1 } }
90 if h==0 { if op==0xBB { bx = (mem[ip+1] as i64) | ((mem[ip+2] as i64)<<8); ip=ip+3; h=1 } }
91 if h==0 { if op==0xB9 { cx = (mem[ip+1] as i64) | ((mem[ip+2] as i64)<<8); ip=ip+3; h=1 } }
92 if h==0 { if op==0xBA { dx = (mem[ip+1] as i64) | ((mem[ip+2] as i64)<<8); ip=ip+3; h=1 } }
93 if h==0 { if op==0xAC { let al: i64 = mem[si] as i64; ax = (ax & 0xFF00) | al; si=si+1; ip=ip+1; h=1 } }
94 if h==0 { if op==0x08 { let al2: i64 = ax & 0xFF; if al2==0 { zf=1 } else { zf=0 } ip=ip+2; h=1 } }
95 if h==0 { if op==0x74 { var r: i64 = mem[ip+1] as i64; if r>127 { r=r-256 } if zf==1 { ip=ip+2+r } else { ip=ip+2 } h=1 } }
96 if h==0 { if op==0xB4 { ax = (ax & 0xFF) | ((mem[ip+1] as i64)<<8); ip=ip+2; h=1 } }
97 if h==0 { if op==0xEB { var r2: i64 = mem[ip+1] as i64; if r2>127 { r2=r2-256 } ip=ip+2+r2; h=1 } }
98 if h==0 { if op==0xE9 { var r3: i64 = (mem[ip+1] as i64) | ((mem[ip+2] as i64)<<8); if r3>ND_MAGIC_32767 { r3=r3-ND_MAGIC_65536 } ip=ip+3+r3; h=1 } }
99 if h==0 { if op==0xCD {
100 let vec: i64 = mem[ip+1] as i64
101 let ah: i64 = (ax >> 8) & 0xFF
102 if vec==0x10 { if ah==0x0E { console[clen[0]]=(ax & 0xFF) as u8; clen[0]=clen[0]+1 } }
103 if vec==0x13 { if ah==0x02 {
104 let count: i64 = ax & 0xFF
105 let sector: i64 = cx & 0xFF
106 let lba: i64 = sector - 1
107 var s: i64 = 0
108 while s < count*512 { mem[bx + s] = disk[lba*512 + s]; s=s+1 }
109 ax = ax & 0xFF
110 } }
111 ip=ip+2; h=1
112 } }
113 if h==0 { return 0 - 1 }
114 }
115 return 0 - 2
116}
117
118const ND_IMG_SZ: i64 = 1024
119
120func nd_movrax(img: *u8, base: i64, o: i64, b0: i64, b1: i64, b2: i64, b3: i64) -> i64 {
121 img[base+o]=0x48 as u8; img[base+o+1]=0xC7 as u8; img[base+o+2]=0xC0 as u8
122 img[base+o+3]=(b0&0xff) as u8; img[base+o+4]=(b1&0xff) as u8; img[base+o+5]=(b2&0xff) as u8; img[base+o+6]=(b3&0xff) as u8
123 return o+7
124}
125
126// author the 2-sector image (the proven layout): MBR loads the long-mode kernel off sector 1, jumps to it;
127// kernel prints the banner over INT 10h then does CR0.PE -> EFER.LME -> CR0.PG|PE -> LONG -> HLT.
128func nd_build_image(img: *u8) -> i64 {
129 var z: i64=0
130 while z<ND_IMG_SZ { img[z]=0 as u8; z=z+1 }
131 img[0]=0xB8 as u8; img[1]=0x01 as u8; img[2]=0x02 as u8
132 img[3]=0xBB as u8; img[4]=0x00 as u8; img[5]=0x80 as u8
133 img[6]=0xB9 as u8; img[7]=0x02 as u8; img[8]=0x00 as u8
134 img[9]=0xBA as u8; img[10]=0x80 as u8; img[11]=0x00 as u8
135 img[12]=0xCD as u8; img[13]=0x13 as u8
136 let rel16: i64 = 0x8000 - (0x7C00 + 14 + 3)
137 img[14]=0xE9 as u8; img[15]=(rel16 & 0xFF) as u8; img[16]=((rel16>>8) & 0xFF) as u8
138 img[510]=0x55 as u8; img[511]=0xAA as u8
139 var r: i64 = 0
140 img[512+r]=0xBE as u8; let si_r: i64 = r+1; r=r+3
141 let loop_r: i64 = r
142 img[512+r]=0xAC as u8; r=r+1
143 img[512+r]=0x08 as u8; img[512+r+1]=0xC0 as u8; r=r+2
144 img[512+r]=0x74 as u8; let jz_r: i64 = r+1; r=r+2
145 img[512+r]=0xB4 as u8; img[512+r+1]=0x0E as u8; r=r+2
146 img[512+r]=0xCD as u8; img[512+r+1]=0x10 as u8; r=r+2
147 img[512+r]=0xEB as u8; img[512+r+1]=((loop_r-(r+2)) & 0xFF) as u8; r=r+2
148 let after_r: i64 = r
149 r = nd_movrax(img, 512, r, 1, 0, 0, 0)
150 img[512+r]=0x0F as u8; img[512+r+1]=0x22 as u8; img[512+r+2]=0xC0 as u8; r=r+3
151 r = nd_movrax(img, 512, r, 0x00, 0x01, 0, 0)
152 img[512+r]=0x0F as u8; img[512+r+1]=0x30 as u8; r=r+2
153 r = nd_movrax(img, 512, r, 0x01, 0x00, 0x00, 0x80)
154 img[512+r]=0x0F as u8; img[512+r+1]=0x22 as u8; img[512+r+2]=0xC0 as u8; r=r+3
155 img[512+r]=0xF4 as u8; r=r+1
156 let msg_r: i64 = r
157 let msg: *u8 = "NishiOS\x0D\x0A\x00"
158 var mi: i64=0
159 while msg[mi]!=(0 as u8) { img[512+r]=msg[mi]; r=r+1; mi=mi+1 }
160 img[512+r]=0 as u8; r=r+1
161 img[512+jz_r] = ((after_r - (jz_r+1)) & 0xFF) as u8
162 let si_abs: i64 = 0x8000 + msg_r
163 img[512+si_r] = (si_abs & 0xFF) as u8
164 img[512+si_r+1] = ((si_abs>>8) & 0xFF) as u8
165 return 0
166}
167
168func nd_boot_image(img: *u8, console: *u8, clen: *i64, st: *i64, loaded: *i64) -> i64 {
169 let mem: *u8 = sys_mmap(ND_MAGIC_65536)
170 var k: i64=0
171 while k<ND_MAGIC_65536 { mem[k]=0 as u8; k=k+1 }
172 var j: i64=0
173 while j<512 { mem[0x7C00+j]=img[j]; j=j+1 }
174 loaded[0] = mem[0x8000] as i64
175 clen[0]=0
176 let rc: i64 = nd_emu_boot_disk(mem, img, 0x7C00, console, clen, st)
177 loaded[1] = mem[0x8000] as i64
178 return rc
179}
180
181// render s at (x,y) via the 8x8 ASCII font (window titles / taskbar labels)
182func nd_str(fb: *u8, W: i64, H: i64, x: i64, y: i64, s: *u8, r: i64, g: i64, b: i64) -> i64 {
183 let table: *u8 = font8x8_table()
184 var i: i64=0
185 while s[i]!=(0 as u8) {
186 let cc: i64 = s[i] as i64
187 if cc>=0x20 { if cc<=0x7E {
188 let gi: i64=(cc-0x20)*8
189 var rr: i64=0
190 while rr<8 { let bits: i64=table[gi+rr] as i64; var co: i64=0; while co<8 { if ((bits>>co)&1)==1 { fb_setpx(fb,W,H, x+i*8+co, y+rr, r,g,b) } co=co+1 } rr=rr+1 }
191 } }
192 i=i+1
193 }
194 return 0
195}
196
197func nd_write_file(path: *u8, data: *u8, n: i64) -> i64 {
198 let fd: i64 = sys_openat_wr(path, 0x1a4)
199 if fd<=0 { return 0 - 1 }
200 sys_write(fd, data, n)
201 sys_close(fd)
202 return n
203}
204
205const ND_W: i64 = 640
206const ND_H: i64 = 480
207const ND_BW: i64 = 620
208const ND_BH: i64 = 426
209const ND_OX: i64 = 10
210const ND_OY: i64 = 38
211
212func nd_count_rgb(desk: *u8, r: i64, g: i64, b: i64) -> i64 {
213 var cnt: i64 = 0
214 var y: i64 = 0
215 while y < ND_BH {
216 var x: i64 = 0
217 while x < ND_BW {
218 let d: i64 = ((ND_OY+y)*ND_W + (ND_OX+x))*3
219 if (desk[d] as i64)==r { if (desk[d+1] as i64)==g { if (desk[d+2] as i64)==b { cnt=cnt+1 } } }
220 x = x + 1
221 }
222 y = y + 1
223 }
224 return cnt
225}
226
227// full-desktop exact-RGB count (for window CHROME outside the blit interior, e.g. the title bar)
228func nd_count_rgb_full(desk: *u8, r: i64, g: i64, b: i64) -> i64 {
229 var cnt: i64 = 0
230 var y: i64 = 0
231 while y < ND_H {
232 var x: i64 = 0
233 while x < ND_W {
234 let d: i64 = (y*ND_W + x)*3
235 if (desk[d] as i64)==r { if (desk[d+1] as i64)==g { if (desk[d+2] as i64)==b { cnt=cnt+1 } } }
236 x = x + 1
237 }
238 y = y + 1
239 }
240 return cnt
241}
242
243// ---- ON-OS VIEWER REGISTRY: ext -> renderer id (data rows); ONE dispatch point invokes the linked lib.
244// Adding a format on NishiOS = one row here + one lib import (no processes on the OS yet, so link-not-exec;
245// the fork-exec registry knowledge/doc_viewers.conf is the Linux-side twin of this table).
246func nd_ext_of(name: *u8, ext: *u8) -> i64 {
247 var dot: i64=0-1; var i: i64=0
248 while name[i]!=(0 as u8) { if name[i]==(46 as u8) { dot=i } i=i+1 }
249 if dot<0 { ext[0]=0 as u8; return 0 }
250 var k: i64=0; var p: i64=dot+1
251 while name[p]!=(0 as u8) { ext[k]=name[p]; k=k+1; p=p+1 }
252 ext[k]=0 as u8
253 return k
254}
255func nd_reg_lookup(ext: *u8) -> i64 {
256 if ext[0]==(109 as u8) { if ext[1]==(100 as u8) { if ext[2]==(0 as u8) { return 1 } } } // "md" -> nx_md_lib
257 return 0
258}
259func nd_reg_render(id: i64, src: *u8, slen: i64, out: *u8) -> i64 {
260 if id==1 { return md_to_html(src, slen, out, 0 as *u8) }
261 return 0 - 1
262}
263
264func main() -> i64 {
265 nd_puts("DOC-OMNITOOL-ON-ALL-OS N-DOC-1: boot NishiOS to LONG mode -> the OS opens report.md natively (registry -> linked renderer -> desktop)\n" as *u8)
266
267 // ---- 1. author + persist the bootable NishiOS image, read the ON-DISK bytes back
268 let img: *u8 = sys_mmap(ND_IMG_SZ + 16)
269 nd_build_image(img)
270 if nd_write_file("knowledge/status/nishios_docview.img\x00" as *u8, img, ND_IMG_SZ) <= 0 { nd_puts("NISHIOS-DOCVIEW RED: cannot write image\n" as *u8); sys_exit(1); return 1 }
271 let ilp: *i64 = sys_mmap(16) as *i64
272 let rd: *u8 = sys_read_file("knowledge/status/nishios_docview.img\x00" as *u8, ilp)
273 if ilp[0] != ND_IMG_SZ { nd_puts("NISHIOS-DOCVIEW RED: image readback size\n" as *u8); sys_exit(1); return 1 }
274
275 // ---- 2. boot the on-disk image on the sovereign emu
276 let con: *u8 = sys_mmap(256)
277 let clen: *i64 = sys_mmap(8) as *i64
278 let st: *i64 = sys_mmap(64) as *i64
279 let ld: *i64 = sys_mmap(64) as *i64
280 let brc: i64 = nd_boot_image(rd, con, clen, st, ld)
281 nd_puts(" boot: 0x8000 " as *u8); nd_num(ld[0]); nd_puts("->" as *u8); nd_num(ld[1]); nd_puts(" mode=" as *u8); nd_num(st[1]); nd_puts(" (2=long) banner='" as *u8); sys_write(1, con, clen[0]); nd_puts("' rc=" as *u8); nd_num(brc); nd_puts("\n" as *u8)
282
283 // ---- 3. persist the REAL on-OS document, read the on-disk bytes back
284 let doc: *u8 = "# Family Trip Report\n\nThe **Nishi** family plans a lake weekend. See the [assistant](/assistant) hub.\n\n## Packing list\n\n- tent and chairs\n- cooler with drinks\n- board games\n\n> The browser is the workhorse of the system.\n\n```\nnx_doc_view report.md out.html\n```\n\n1. drive up Friday\n2. hike Saturday\n3. home Sunday\n\x00"
285 nd_write_file("knowledge/status/nishios_doc_report.md\x00" as *u8, doc, nd_slen(doc))
286 let dlp: *i64 = sys_mmap(16) as *i64
287 let draw: *u8 = sys_read_file("knowledge/status/nishios_doc_report.md\x00" as *u8, dlp)
288
289 // ---- 4. the ON-OS registry routes the document to its linked renderer
290 let ext: *u8 = sys_mmap(32)
291 nd_ext_of("report.md\x00" as *u8, ext)
292 let vid: i64 = nd_reg_lookup(ext)
293 let ext2: *u8 = sys_mmap(32)
294 nd_ext_of("report.xyz\x00" as *u8, ext2)
295 let vbad: i64 = nd_reg_lookup(ext2)
296 nd_puts(" registry: .md -> id=" as *u8); nd_num(vid); nd_puts(" .xyz -> id=" as *u8); nd_num(vbad); nd_puts("\n" as *u8)
297 let html: *u8 = sys_mmap(ND_MAGIC_1048576)
298 var hn: i64 = 0
299 if vid > 0 { hn = nd_reg_render(vid, draw, dlp[0], html) }
300 nd_puts(" convert: html_bytes=" as *u8); nd_num(hn); nd_puts("\n" as *u8)
301
302 // ---- 5. lay the converted preview out with the OS-agnostic browser core
303 let page: *Page = sys_mmap(NX_PAGE_BYTES) as *Page
304 page.raw = html
305 page.raw_len = hn
306 br_layout(page, ND_BW/2)
307 page.vec_headings = 2
308 nd_puts(" layout: ok=" as *u8); nd_num(page.ok); nd_puts(" boxes=" as *u8); nd_num(page.tree.count); nd_puts(" page_h=" as *u8); nd_num(page.page_h); nd_puts("\n" as *u8)
309
310 // ---- 6. the viewer paints ONLY because the disk-loaded kernel reached long mode
311 let desk: *u8 = sys_mmap(ND_W*ND_H*3 + 16)
312 let font: *u8 = sys_mmap(64)
313 let idx: *u8 = sys_mmap(8)
314 var bmpsz: i64 = 0
315 if st[1]==2 { if page.ok==1 { if hn>0 {
316 fb_nishi_font(font, idx)
317 var wy: i64=0
318 while wy<ND_H { let wr: i64=10-(8*wy)/ND_H; let wg: i64=30+(40*wy)/ND_H; let wb: i64=50+(30*wy)/ND_H; fb_rect(desk,ND_W,ND_H, 0,wy, ND_W,1, wr,wg,wb); wy=wy+1 }
319 fb_rect(desk,ND_W,ND_H, 0,0, ND_W,16, 28,28,110)
320 fb_text(desk,ND_W,ND_H, font, idx, 7, 6,4, 1, 255,255,255)
321 fb_window(desk,ND_W,ND_H, font,idx, 8,22, 624,444, 50,80,180, 210,210,225)
322 nd_str(desk,ND_W,ND_H, 8+3+66, 22+3, "- NISHI DOCS report.md\x00" as *u8, 240,240,250)
323 let bfb: *Framebuffer = sys_mmap(NX_FRAMEBUFFER_BYTES) as *Framebuffer
324 let bpx: *u8 = sys_mmap(ND_BW*ND_BH*4 + 64)
325 nx_framebuffer_init(bfb, bpx, ND_BW, ND_BH)
326 br_draw_fb(bfb, page, ND_BW/2, "nishios://docs/report.md\x00" as *u8, 24, 2)
327 var by: i64 = 0
328 while by < ND_BH {
329 var bx: i64 = 0
330 while bx < ND_BW {
331 let so: i64 = (by*ND_BW + bx)*4
332 let dof: i64 = ((ND_OY+by)*ND_W + (ND_OX+bx))*3
333 desk[dof] = bpx[so]
334 desk[dof+1] = bpx[so+1]
335 desk[dof+2] = bpx[so+2]
336 bx = bx + 1
337 }
338 by = by + 1
339 }
340 fb_rect(desk,ND_W,ND_H, 0,466, ND_W,14, 20,20,40)
341 fb_rect(desk,ND_W,ND_H, 4,469, 36,8, 80,200,80)
342 nd_str(desk,ND_W,ND_H, 46,469, "docs viewer\x00" as *u8, 200,210,230)
343 fb_cursor(desk,ND_W,ND_H, 330,240)
344 bmpsz = fb_bmp_save(desk, ND_W, ND_H, "knowledge/status/nishios_docview.bmp\x00" as *u8)
345 let vhtml: *u8 = "<!doctype html><html><body style=\x27margin:0;background:#0a0a12;display:flex;align-items:center;justify-content:center;height:100vh\x27><div><img src=\x27nishios_docview.bmp\x27 style=\x27image-rendering:pixelated;width:960px;border:1px solid #333\x27><div style=\x27color:#8af;font-family:monospace;text-align:center;margin-top:8px\x27>NishiOS boots (MBR -> LONG mode on the sovereign emu) -> the OS opens report.md NATIVELY: registry -> linked nx_md_lib renderer -> br_layout -> the NISHI DOCS window</div></div></body></html>\x00"
346 nd_write_file("knowledge/status/nishios_docview.html\x00" as *u8, vhtml, nd_slen(vhtml))
347 nd_puts(" docview composited -> knowledge/status/nishios_docview.bmp (" as *u8); nd_num(bmpsz); nd_puts(" bytes) + .html\n" as *u8)
348 } } }
349
350 // ---- 7. NEG 1: a 0-sector-load sibling image never reaches long mode -> the viewer never fires
351 let bad: *u8 = sys_mmap(ND_IMG_SZ + 16)
352 var c: i64=0
353 while c<ND_IMG_SZ { bad[c]=rd[c]; c=c+1 }
354 bad[1]=0x00 as u8
355 let con2: *u8 = sys_mmap(256)
356 let clen2: *i64 = sys_mmap(8) as *i64
357 let st2: *i64 = sys_mmap(64) as *i64
358 let ld2: *i64 = sys_mmap(64) as *i64
359 nd_boot_image(bad, con2, clen2, st2, ld2)
360 let desk2: *u8 = sys_mmap(ND_W*ND_H*3 + 16)
361 var neg_drawn: i64 = 0
362 if st2[1]==2 {
363 fb_rect(desk2,ND_W,ND_H, ND_OX,ND_OY, ND_BW,ND_BH, 255,255,255)
364 neg_drawn = 1
365 }
366 let negpx: i64 = desk2[((ND_OY+50)*ND_W + (ND_OX+50))*3] as i64
367 nd_puts(" NEG boot: mode=" as *u8); nd_num(st2[1]); nd_puts(" drawn=" as *u8); nd_num(neg_drawn); nd_puts(" probe_px=" as *u8); nd_num(negpx); nd_puts("\n" as *u8)
368
369 // ---- 8. NEG 2: an EMPTY document collapses the layout vs the real one (content-sensitive evidence)
370 let ehtml: *u8 = sys_mmap(ND_MAGIC_1048576)
371 let ehn: i64 = nd_reg_render(1, "\x00" as *u8, 0, ehtml)
372 let page2: *Page = sys_mmap(NX_PAGE_BYTES) as *Page
373 page2.raw = ehtml
374 page2.raw_len = ehn
375 br_layout(page2, ND_BW/2)
376 nd_puts(" NEG layout: empty-doc boxes=" as *u8); nd_num(page2.tree.count); nd_puts(" vs real=" as *u8); nd_num(page.tree.count); nd_puts("\n" as *u8)
377
378 // ---- KATs (RE-PINNED 07-09 render-core CSS rung: author colors now APPLY + inherit -- the md preview's
379 // body{color:#1a1d21} reaches headings AND text via br_comp_color_inh; chrome ink #202124 unchanged)
380 let ink_h: i64 = nd_count_rgb(desk, 26, 29, 33)
381 let ink_c: i64 = nd_count_rgb_full(desk, 50, 80, 180)
382 let ink_t: i64 = nd_count_rgb(desk, 32, 33, 36)
383 nd_puts(" pixels: heading=" as *u8); nd_num(ink_h); nd_puts(" chrome=" as *u8); nd_num(ink_c); nd_puts(" text=" as *u8); nd_num(ink_t); nd_puts("\n" as *u8)
384 let banner: *u8 = "NishiOS" as *u8
385 var pass: i64=0
386 var ttl: i64=0
387 ttl=ttl+1; nd_puts(" T1 booted off the persisted image (0x8000: 0->0xBE): " as *u8); if ld[0]==0 { if ld[1]==0xBE { pass=pass+1; nd_puts("PASS\n" as *u8) } else { nd_puts("FAIL\n" as *u8) } } else { nd_puts("FAIL\n" as *u8) }
388 ttl=ttl+1; nd_puts(" T2 disk-loaded kernel reached LONG mode (mode==2): " as *u8); if st[1]==2 { pass=pass+1; nd_puts("PASS\n" as *u8) } else { nd_puts("FAIL\n" as *u8) }
389 ttl=ttl+1; nd_puts(" T3 UART banner == 'NishiOS': " as *u8); if nd_contains(con, clen[0], banner, 7)==1 { pass=pass+1; nd_puts("PASS\n" as *u8) } else { nd_puts("FAIL\n" as *u8) }
390 ttl=ttl+1; nd_puts(" T4 registry routes .md (id=1) AND refuses .xyz (id=0): " as *u8); if vid==1 { if vbad==0 { pass=pass+1; nd_puts("PASS\n" as *u8) } else { nd_puts("FAIL\n" as *u8) } } else { nd_puts("FAIL\n" as *u8) }
391 ttl=ttl+1; nd_puts(" T5 conversion REAL (h1+bold+link+quote+code markers): " as *u8)
392 var t5: i64=0
393 if nd_contains(html, hn, "<h1>Family Trip Report</h1>" as *u8, 27)==1 { if nd_contains(html, hn, "<b>Nishi</b>" as *u8, 12)==1 { if nd_contains(html, hn, "<a href=\"/assistant\">assistant</a>" as *u8, 34)==1 { if nd_contains(html, hn, "<blockquote>" as *u8, 12)==1 { if nd_contains(html, hn, "<pre><code>" as *u8, 11)==1 { t5=1 } } } } }
394 if t5==1 { pass=pass+1; nd_puts("PASS\n" as *u8) } else { nd_puts("FAIL\n" as *u8) }
395 ttl=ttl+1; nd_puts(" T6 REAL layout (ok, boxes>=15, page_h>=100): " as *u8); if page.ok==1 { if page.tree.count>=15 { if page.page_h>=100 { pass=pass+1; nd_puts("PASS\n" as *u8) } else { nd_puts("FAIL\n" as *u8) } } else { nd_puts("FAIL\n" as *u8) } } else { nd_puts("FAIL\n" as *u8) }
396 ttl=ttl+1; nd_puts(" T7 AUTHOR ink composited (body #1a1d21 INHERITED into headings/text, >100 px): " as *u8); if ink_h>100 { pass=pass+1; nd_puts("PASS\n" as *u8) } else { nd_puts("FAIL\n" as *u8) }
397 ttl=ttl+1; nd_puts(" T8 NISHI DOCS window chrome composited (title-bar blue >500 px): " as *u8); if ink_c>500 { pass=pass+1; nd_puts("PASS\n" as *u8) } else { nd_puts("FAIL\n" as *u8) }
398 ttl=ttl+1; nd_puts(" T9 body-text ink composited (measured #202124, >100 px): " as *u8); if ink_t>100 { pass=pass+1; nd_puts("PASS\n" as *u8) } else { nd_puts("FAIL\n" as *u8) }
399 ttl=ttl+1; nd_puts(" T10 BMP exported at the exact expected size: " as *u8); if bmpsz==(54 + ND_W*ND_H*3) { pass=pass+1; nd_puts("PASS\n" as *u8) } else { nd_puts("FAIL\n" as *u8) }
400 ttl=ttl+1; nd_puts(" T11 NEG: 0-sector load never reaches long mode, viewer never fires: " as *u8); if st2[1]!=2 { if neg_drawn==0 { if negpx==0 { pass=pass+1; nd_puts("PASS\n" as *u8) } else { nd_puts("FAIL\n" as *u8) } } else { nd_puts("FAIL\n" as *u8) } } else { nd_puts("FAIL\n" as *u8) }
401 ttl=ttl+1; nd_puts(" T12 NEG: empty document collapses the box count (real >= empty+8): " as *u8); if page.tree.count >= page2.tree.count + 8 { pass=pass+1; nd_puts("PASS\n" as *u8) } else { nd_puts("FAIL\n" as *u8) }
402
403 nd_puts("NISHIOS-DOCVIEW-GATE passed " as *u8); nd_num(pass); nd_puts("/" as *u8); nd_num(ttl)
404 if pass==ttl { nd_puts(" verdict=GREEN (boot NishiOS -> the OS opens report.md natively; open knowledge/status/nishios_docview.html)\n" as *u8); sys_exit(0); return 0 }
405 nd_puts(" verdict=RED\n" as *u8); sys_exit(1); return 1
406}