code wiki / _hdl_build / _pe_dchan.nx
_pe_dchan.nx source
↩ module page · 22 lines · 673 B
1// AUTHORED BY THE NISHI BUILDER (pattern: STRUCT_WALK v2 magic/tailrest) -- field-table walk, no Claude logic
2import "nx_syscalls.nx"
3func _pe_dchan_locate(b: *u8, n: i64, out: *i64) -> i64 {
4 var off: i64 = 0
5 off = off + 1
6 if off > n { return 0 - 1 }
7 off = off + 8
8 if off > n { return 0 - 1 }
9 off = off + 8
10 if off > n { return 0 - 1 }
11 off = off + 4
12 if off > n { return 0 - 1 }
13 off = off + 4
14 if off > n { return 0 - 1 }
15 if off + 2 > n { return 0 - 1 }
16 let tl: i64 = ((b[off] & 0xff) << 8) | (b[off + 1] & 0xff)
17 if off + 2 + tl > n { return 0 - 1 }
18 out[0] = off + 2
19 out[1] = tl
20 return 0
21 return 0 - 1
22}