nx_pcb_drill.nx source
↩ module page · 50 lines · 2255 B
1// nx_pcb_drill.nx -- SOVEREIGN Excellon (NC drill) emitter: the drill half of the PCB fab package.
2// Gerber (nx_pcb_gerber) carries copper; Excellon carries the holes -- together they are the
3// COMPLETE manufacturable handoff a fab (or our own in-house drill/mill) needs. INTEGER-ONLY /
4// NO-FLOAT: tool diameters + hole positions are micrometers (um), formatted to decimal mm via the
5// SHARED g_mm6 from nx_pcb_gerber (DRY -- one formatter, one source of truth, identical rounding).
6// Decimal coordinates are emitted explicitly so zero-suppression dialect can never corrupt a hole
7// position. Standard structure: M48 header / FMAT,2 / METRIC / Tn C<dia> tool table / % / G90 G05 /
8// per-tool select + X<mm>Y<mm> hits / M30. license_tier: ORIGINAL expect_exit: 0
9import "nx_syscalls.nx"
10import "nx_pcb_gerber.nx"
11
12// Emit a complete Excellon drill program into out[]; return byte length.
13// tool index t (0-based) -> T-code (t+1). hole_tool[] holds tool INDICES.
14func excellon_emit(
15 tool_dia: *i64, n_tool: i64,
16 hole_tool: *i64, hole_x: *i64, hole_y: *i64, n_hole: i64,
17 out: *u8) -> i64 {
18 let len: *i64 = sys_mmap(8) as *i64
19 len[0] = 0
20 g_puts(out, len, "M48\n" as *u8)
21 g_puts(out, len, ";Nishi Omniforge sovereign Excellon drill (mm, decimal)\n" as *u8)
22 g_puts(out, len, "FMAT,2\n" as *u8)
23 g_puts(out, len, "METRIC\n" as *u8)
24 var t: i64 = 0
25 while t < n_tool {
26 g_puts(out, len, "T" as *u8); g_puti(out, len, t + 1)
27 g_puts(out, len, "C" as *u8); g_mm6(out, len, tool_dia[t])
28 g_puts(out, len, "\n" as *u8)
29 t = t + 1
30 }
31 g_puts(out, len, "%\n" as *u8)
32 g_puts(out, len, "G90\n" as *u8)
33 g_puts(out, len, "G05\n" as *u8)
34 t = 0
35 while t < n_tool {
36 g_puts(out, len, "T" as *u8); g_puti(out, len, t + 1); g_puts(out, len, "\n" as *u8)
37 var h: i64 = 0
38 while h < n_hole {
39 if hole_tool[h] == t {
40 g_puts(out, len, "X" as *u8); g_mm6(out, len, hole_x[h])
41 g_puts(out, len, "Y" as *u8); g_mm6(out, len, hole_y[h])
42 g_puts(out, len, "\n" as *u8)
43 }
44 h = h + 1
45 }
46 t = t + 1
47 }
48 g_puts(out, len, "M30\n" as *u8)
49 return len[0]
50}