code wiki / _hdl_build / nx_slicer_gate.nx

nx_slicer_gate.nx source

↩ module page · 101 lines · 3800 B

1// nx_slicer_gate.nx -- proves the sovereign slicer end-to-end WITHOUT the printer. 2// Hand-builds a binary-STL tetrahedron -> sl_slice_stl -> asserts real G-code 3// (heater command + 500+ extrusion moves + sane layer count). Same real-byte 4// path an operator's STL takes; offline, deterministic. 5// license_tier: ORIGINAL expect_exit: 0 6import "nx_syscalls.nx" 7import "nx_gcode_emit.nx" 8import "nx_slicer_lib.nx" 9import "nx_gate_verdict.nx" 10 11const F32_ZERO: i64 = 0x00000000 12const F32_TEN: i64 = 0x41200000 // +10.0 13 14func put_f32(buf: *u8, off: i64, bits32: i64) -> i64 { 15 buf[off + 0] = (bits32 & 0xff) as u8 16 buf[off + 1] = ((bits32 >> 8) & 0xff) as u8 17 buf[off + 2] = ((bits32 >> 16) & 0xff) as u8 18 buf[off + 3] = ((bits32 >> 24) & 0xff) as u8 19 return 0 20} 21func put_tri(buf: *u8, off: i64, 22 x0: i64, y0: i64, z0: i64, 23 x1: i64, y1: i64, z1: i64, 24 x2: i64, y2: i64, z2: i64) -> i64 { 25 put_f32(buf, off + 0, 0) 26 put_f32(buf, off + 4, 0) 27 put_f32(buf, off + 8, 0) 28 put_f32(buf, off + 12, x0) 29 put_f32(buf, off + 16, y0) 30 put_f32(buf, off + 20, z0) 31 put_f32(buf, off + 24, x1) 32 put_f32(buf, off + 28, y1) 33 put_f32(buf, off + 32, z1) 34 put_f32(buf, off + 36, x2) 35 put_f32(buf, off + 40, y2) 36 put_f32(buf, off + 44, z2) 37 buf[off + 48] = 0 38 buf[off + 49] = 0 39 return 0 40} 41func g_count(buf: *u8, len: i64, needle: *u8) -> i64 { 42 var nlen: i64 = 0 43 while needle[nlen] != (0 as u8) { nlen = nlen + 1 } 44 if len < nlen { return 0 } 45 var count: i64 = 0 46 var i: i64 = 0 47 let last: i64 = len - nlen 48 while i <= last { 49 var j: i64 = 0 50 var matched: i64 = 1 51 while j < nlen { 52 if buf[i + j] != needle[j] { matched = 0; j = nlen } 53 j = j + 1 54 } 55 if matched == 1 { count = count + 1 } 56 i = i + 1 57 } 58 return count 59} 60 61func main() -> i64 { 62 let ctr: *i64 = gv_ctr() 63 gv_head("nx_slicer_gate -- sovereign STL->G-code slicer (real-byte path, QIDI profile, offline)" as *u8) 64 65 let stl: *u8 = sys_mmap(512) 66 stl[80] = 4 as u8 67 put_tri(stl, 84 + 0 * 50, F32_TEN, F32_ZERO, F32_ZERO, F32_ZERO, F32_TEN, F32_ZERO, F32_ZERO, F32_ZERO, F32_TEN) 68 put_tri(stl, 84 + 1 * 50, F32_ZERO, F32_ZERO, F32_ZERO, F32_ZERO, F32_ZERO, F32_TEN, F32_ZERO, F32_TEN, F32_ZERO) 69 put_tri(stl, 84 + 2 * 50, F32_ZERO, F32_ZERO, F32_ZERO, F32_TEN, F32_ZERO, F32_ZERO, F32_ZERO, F32_ZERO, F32_TEN) 70 put_tri(stl, 84 + 3 * 50, F32_ZERO, F32_ZERO, F32_ZERO, F32_ZERO, F32_TEN, F32_ZERO, F32_TEN, F32_ZERO, F32_ZERO) 71 let stl_len: i64 = 84 + 4 * 50 72 73 let nl: *i64 = sys_mmap(8) as *i64 74 let nt: *i64 = sys_mmap(8) as *i64 75 let e: *NxGcodeEmitter = sl_slice_stl(stl, stl_len, 3277, 20, nl, nt) 76 77 var t1: i64 = 0 78 if (e as i64) != 0 { t1 = 1 } 79 gv_check("T1 slice a binary-STL tetrahedron -> G-code emitter produced" as *u8, t1, ctr) 80 81 var t2: i64 = 0 82 if nt[0] == 4 { t2 = 1 } 83 gv_check("T2 STL parse: 4 triangles recovered from raw bytes" as *u8, t2, ctr) 84 85 var t3: i64 = 0 86 if nl[0] >= 30 { if nl[0] <= 200 { t3 = 1 } } 87 gv_check("T3 sliced to a sane layer count (30..200)" as *u8, t3, ctr) 88 89 var t4: i64 = 0 90 var t5: i64 = 0 91 if (e as i64) != 0 { 92 if g_count(e.buf, e.len, "M104 S" as *u8) >= 1 { t4 = 1 } 93 if g_count(e.buf, e.len, "G1 X" as *u8) >= 500 { t5 = 1 } 94 } 95 gv_check("T4 emitted G-code contains a heater command (M104 S)" as *u8, t4, ctr) 96 gv_check("T5 emitted G-code contains 500+ extrusion moves (G1 X)" as *u8, t5, ctr) 97 98 let rc: i64 = gv_verdict("SLICER" as *u8, ctr, "sovereign STL->G-code: parse + multi-layer slice + supports + perimeters on the QIDI profile; no third-party slicer" as *u8) 99 sys_exit(rc) 100 return rc 101}