code wiki / _hdl_build / nx_cbz_fixture.nx

nx_cbz_fixture.nx source

↩ module page · 33 lines · 2306 B

1// nx_cbz_fixture.nx -- build a tiny DRM-free CBZ (comic = a ZIP of page images) via the sovereign OPC zip writer, 2// so the comics->.nmz rung can be gated end-to-end (nx_cbx_pages extracts -> nx_nmz_pack packs @kind=comic). The 3// page bytes start with the JPEG SOI (ff d8) so nx_cbx_pages' no-fake-green magic gate accepts them, and contain 4// EMBEDDED 0x00 bytes -- proving the binary-safe canon (nx_canon_bin) carries real image bytes that string-only 5// canon_encode would truncate. expect_exit: 0 license_tier: ORIGINAL 6import "nx_syscalls.nx" 7import "nx_opc.nx" 8 9func cf_slen(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} return n } 10func cf_p(s: *u8) -> i64 { sys_write(1, s, cf_slen(s)); return 0 } 11func cf_n(v: i64) -> i64 { let b: *u8=sys_mmap(24); var m: i64=v; if m<0{m=0-m}; let t: *u8=sys_mmap(24); var k: i64=0; if m==0{t[0]=48 as u8;k=1}; while m>0{t[k]=(48+(m%10)) as u8;m=m/10;k=k+1}; var i: i64=0; while i<k{b[i]=t[k-1-i];i=i+1}; sys_write(1,b,k); return 0 } 12func ensure_dir(path: *u8) -> i64 { __syscall(258, 0-100, path, 0x1ed, 0, 0, 0); return 0 } 13 14func main() -> i64 { 15 ensure_dir("knowledge/fixtures" as *u8) 16 // page 1: ff d8 (SOI) 00 42 00 4a ff d9 (EOI) -- embedded NULs at [2] and [4] 17 let img1: *u8 = sys_mmap(32) 18 img1[0]=(0xff) as u8; img1[1]=(0xd8) as u8; img1[2]=(0x00) as u8; img1[3]=(0x42) as u8; img1[4]=(0x00) as u8; img1[5]=(0x4a) as u8; img1[6]=(0xff) as u8; img1[7]=(0xd9) as u8 19 // page 2: ff d8 99 00 00 ff d9 -- more NULs 20 let img2: *u8 = sys_mmap(32) 21 img2[0]=(0xff) as u8; img2[1]=(0xd8) as u8; img2[2]=(0x99) as u8; img2[3]=(0x00) as u8; img2[4]=(0x00) as u8; img2[5]=(0xff) as u8; img2[6]=(0xd9) as u8 22 23 let names: *i64 = sys_mmap(8*4) as *i64 24 let datap: *i64 = sys_mmap(8*4) as *i64 25 let lens: *i64 = sys_mmap(8*4) as *i64 26 names[0]="page1.jpg" as *u8 as i64; datap[0]=img1 as i64; lens[0]=8 27 names[1]="page2.jpg" as *u8 as i64; datap[1]=img2 as i64; lens[1]=7 28 29 let w: i64 = opc_write("knowledge/fixtures/nishi_comic.cbz" as *u8, names, datap, lens, 2) 30 cf_p("CBZ-FIXTURE bytes=" as *u8); cf_n(w); cf_p(" pages=2 -> knowledge/fixtures/nishi_comic.cbz\n" as *u8) 31 if w <= 0 { cf_p("CBZ-FIXTURE-FAIL\n" as *u8); sys_exit(1); return 1 } 32 cf_p("CBZ-FIXTURE-OK\n" as *u8); sys_exit(0); return 0 33}