code wiki / _hdl_build / nx_skullgen.nx
nx_skullgen.nx source
↩ module page · 488 lines · 29473 B
1// nx_skullgen.nx -- F1108/seq900 KEYSTONE: THE SKULL, GENERATED. Inside-out, from the first byte up.
2//
3// OPERATOR, and he was right: "you arent building from the inside out aka a skull to give it structure ...
4// take the skull and bones those should have all been generatable by now then you just layer on top."
5// Every facial feature this program fought with is a property of BONE -- the brow ridge is the supraorbital
6// margin of the frontal bone, the chin is the mental protuberance of the mandible, the cheekbones are the
7// zygomatic arches, the eye sockets are the orbits. We had been sticking those onto a smooth SKIN ovoid,
8// which is why three tuned chin attempts all rendered as lobes stacked under a mouth: pieces stuck on a
9// blob look like pieces stuck on a blob. The structure has to exist first and the surface layers onto it.
10//
11// This organ does NOT store a skull -- it stores the RULES that make one, and emits them as a canon of
12// P/R/F rows that the proven emitter turns into geometry. So the skull inherits spline lofting, true
13// central-difference normals, capped tubes, per-part placement and rotation about Z for free, and it is
14// data generated by anatomy rather than a modelled asset. The oracle it is scored against is the
15// BodyParts3D skull (171,248 real scanned triangles, CC BY-SA 2.1 Japan) -- a RULER, never the product.
16//
17// nx_skullgen <out.dat> [sex 0-1000] [seed] [robust 0-1000]
18// nx_skullgen selftest
19// license_tier: ORIGINAL expect_exit: 0 No hw writes (Rule 26).
20import "nx_gate_verdict.nx"
21import "nx_itoa_lib.nx" // shared MSB-first emitter (zero-alloc)
22
23const SK_BUF: i64 = 65536
24const SK_MODE: i64 = 420
25const SK_MINP: i64 = 7
26const SK_MINR: i64 = 30
27// ★VAULT VERTEX CLOSURE, per-mille of the parietal half-width (argv[6]). A DIAL, not a baked number, because
28// the right value is a FITTING question against the oracle and must be swept, not intuited: the cone-vs-dome
29// fix took the closure tail from 4 to 165 against the oracle's 351, so the residual is a value to MEASURE.
30// 580 = the value measured good on 2026-07-30; the y994 ring follows as the midpoint so the dome stays smooth.
31static SK_VTX: i64
32
33func sk_puts(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 }
34// MIGRATED to the shared emitter (debt 1785563586). The old body mmapped a scratch buffer
35// per call and never freed it. At PAGE granularity that is 4096B leaked PER CALL -- the
36// defect that took 28.5GB of a 36GB host in nx_ts_lumadiff (2MB input, ~3.66M calls).
37// nxi_* is MSB-first, allocates NOTHING, and emits identical bytes including the sign.
38func sk_pn(v: i64) -> i64 { nxi_out(v); return 0 }
39func sk_step(st: *i64) -> i64 {
40 var x: i64 = st[0]
41 x = x ^ (x << 13); x = x ^ (x >> 7); x = x ^ (x << 17)
42 st[0] = x
43 if x < 0 { return 0-x }
44 return x
45}
46func sk_pm(st: *i64, amp: i64) -> i64 { if amp <= 0 { return 0 } let r: i64 = sk_step(st) % (2*amp+1); return r - amp }
47func sk_streq(a: *u8, b: *u8) -> i64 {
48 var i: i64=0; var go: i64=1; var eq: i64=1
49 while go==1 { if a[i]!=b[i] { eq=0; go=0 } else { if a[i]==(0 as u8) { go=0 } else { i=i+1 } } }
50 return eq
51}
52func sk_atoi(s: *u8) -> i64 {
53 var i: i64=0; var n: i64=0; var sg: i64=1
54 if s[0]==(45 as u8) { sg=0-1; i=1 }
55 while s[i]!=(0 as u8) { let c: i64 = s[i] as i64; if c>=48 { if c<=57 { n=n*10+(c-48) } } i=i+1 }
56 return n*sg
57}
58func sk_wint(b: *u8, pos: *i64, v: i64, c: i64) -> i64 {
59 var x: i64=v
60 if x<0 { b[pos[0]]=45 as u8; pos[0]=pos[0]+1; x=0-x }
61 let t: *u8 = sys_mmap(32); var k: i64=0
62 if x==0 { t[0]=48 as u8; k=1 }
63 while x>0 { t[k]=(48+x%10) as u8; x=x/10; k=k+1 }
64 var q: i64=k-1
65 while q>=0 { b[pos[0]]=t[q]; pos[0]=pos[0]+1; q=q-1 }
66 b[pos[0]]=c as u8; pos[0]=pos[0]+1
67 return 0
68}
69// one control ring of a bone: y (per-mille of stature), lateral + depth offsets, half-width, half-depth
70func skR(b: *u8, pos: *i64, y: i64, xoff: i64, zoff: i64, ra: i64, rb: i64) -> i64 {
71 var a: i64 = ra; var d: i64 = rb
72 if a < 2 { a = 2 }
73 if d < 2 { d = 2 }
74 b[pos[0]]=82 as u8; b[pos[0]+1]=32 as u8; pos[0]=pos[0]+2
75 sk_wint(b,pos,y,32); sk_wint(b,pos,xoff,32); sk_wint(b,pos,zoff,32); sk_wint(b,pos,a,32); sk_wint(b,pos,d,10)
76 return 0
77}
78// one BONE: a part header carrying mirror, X-rotation, offsets, material and rotation about Z
79func skP(b: *u8, pos: *i64, mir: i64, rot: i64, ox: i64, oy: i64, oz: i64, mat: i64, rotz: i64) -> i64 {
80 b[pos[0]]=80 as u8; b[pos[0]+1]=32 as u8; pos[0]=pos[0]+2
81 sk_wint(b,pos,mir,32); sk_wint(b,pos,rot,32); sk_wint(b,pos,ox,32); sk_wint(b,pos,oy,32)
82 sk_wint(b,pos,oz,32); sk_wint(b,pos,mat,32); sk_wint(b,pos,rotz,10)
83 return 0
84}
85// a relief feature: hollows and openings in bone (orbits, nasal aperture, temporal fossa)
86func skF(b: *u8, pos: *i64, part: i64, y: i64, yw: i64, th: i64, tw: i64, amp: i64) -> i64 {
87 b[pos[0]]=70 as u8; b[pos[0]+1]=32 as u8; pos[0]=pos[0]+2
88 sk_wint(b,pos,part,32); sk_wint(b,pos,y,32); sk_wint(b,pos,yw,32)
89 sk_wint(b,pos,th,32); sk_wint(b,pos,tw,32); sk_wint(b,pos,amp,10)
90 return 0
91}
92// ★an OPENING: a region where the shell is ABSENT, not merely pushed in. No amplitude field, because
93// there is no amount -- the surface is there or it is not. Consumed by nx_body_gen's bg_parse_open.
94func skO(b: *u8, pos: *i64, part: i64, y: i64, yw: i64, th: i64, tw: i64) -> i64 {
95 b[pos[0]]=79 as u8; b[pos[0]+1]=32 as u8; pos[0]=pos[0]+2
96 sk_wint(b,pos,part,32); sk_wint(b,pos,y,32); sk_wint(b,pos,yw,32)
97 sk_wint(b,pos,th,32); sk_wint(b,pos,tw,10)
98 return 0
99}
100// ★THE SKULL, BY RULE. Every dimension is a function of cranial proportion and the sex/robusticity knobs;
101// nothing is a typed coordinate lifted off a reference. Ordering follows the developmental logic: the
102// neurocranium that houses the brain, then the face suspended from its front, then the jaw hung beneath.
103func sk_emit(b: *u8, pos: *i64, st: *i64, sexf: i64, robust: i64, noise: i64) -> i64 {
104 // dimorphism + robusticity as SCALARS over the whole skull, the way a genome modulates a template
105 let brow: i64 = 12 - 5*sexf/1000 + 6*robust/1000 // supraorbital margin: heavy male, light female
106 let jaw: i64 = 46 - 6*sexf/1000 + 5*robust/1000 // mandible breadth: square male, tapered female
107 let vlt: i64 = 52 + 2*sexf/1000 // cranial vault half-breadth
108 let zyg: i64 = 50 - 3*sexf/1000 + 4*robust/1000 // zygomatic (cheekbone) projection
109
110 // ---- 1. NEUROCRANIUM: the vault. Widest at the parietal eminences, occiput bulging behind, the
111 // frontal sloping back above the brow. Deeper than broad, which is what makes a skull read as a skull.
112 // ★THE v1 DEFECT: this vault spanned 866..1000 -- the WHOLE skull height -- so the maxilla (910),
113 // zygomatics (924) and mandible (874) were all INSIDE a shell whose half-depth is ~55 there. Only
114 // the zygomatic end-caps emerged, which is why v1 rendered as an egg with two white discs.
115 // A real neurocranium is the BRAIN CASE ONLY. It starts at the base and ends above the orbits; the
116 // facial skeleton hangs from its FRONT and BELOW, never inside it. The vault is also pushed BACK,
117 // because the braincase sits behind the face rather than centred on it.
118 // ★THE BRAINCASE FLOOR, NAMED ONCE (seq1381). Every hollow's station is DERIVED from it below, so
119 // moving the vault can never again strand the orbits and fossae the way the v1->v2 shrink did.
120 let vlo: i64 = 926
121 let vsp: i64 = 1000 - vlo
122 skP(b,pos, 0, 0, 0, 0, 0, 0, 0)
123 skR(b,pos, vlo, 0, 0-24, vlt*70/100 + sk_pm(st,noise), vlt*74/100) // skull base, occipital region
124 skR(b,pos, 940, 0, 0-20, vlt*88/100, vlt*98/100) // temporal squama
125 skR(b,pos, 952, 0, 0-16, vlt*97/100, vlt*110/100) // widening toward the eminence
126 skR(b,pos, 964, 0, 0-14, vlt, vlt*116/100) // parietal eminence: the widest
127 skR(b,pos, 976, 0, 0-16, vlt*95/100, vlt*110/100)
128 // ★★★★★THE VAULT CLOSED AS A CONE, NOT A DOME -- MEASURED, NOT GUESSED (debt 1785452359).
129 // The old tail was 82 -> 58 -> 28 percent of the parietal half-width with the ring centre pulled BACK
130 // -20 -> -26 -> -32, i.e. a spike leaning backward. nx_meshprofile's closure curve (radius as per-mille
131 // of the mesh's own max, per y band) measured the consequence end to end:
132 // vault as a CONE : radius_min 500um @station 992, tail ...150 122 71 42 4
133 // the REAL SKULL : radius_min 37716um @station 984, tail ...463 406 351
134 // vault as a DOME : radius_min 43660um @station 992, tail ...476 446 437 416
135 // So the cranium used to end in a SPIRE holding 0.4 percent of its max radius where a real one holds
136 // 35 percent -- 87x too thin at the crown, and no section prior can touch it because it is the CANON.
137 // Isolated by bisection (a vault-only canon reproduced the spire with every other bone removed), so this
138 // is the vault's own closure and not a neighbouring part. Equator is UNTOUCHED: radius_max stays 104805
139 // @station 500 before and after, so this changes the CLOSURE and nothing else.
140 // ⚠STILL SLIGHTLY BROAD: 416 vs the oracle's 351. That is now a FITTING residual, not a structural
141 // defect -- pull the vertex ring toward vlt*52/100 and re-measure the tail before trusting a smaller number.
142 skR(b,pos, 986, 0, 0-20, vlt*85/100, vlt*96/100) // frontal, sloping back
143 let vmid: i64 = (850 + SK_VTX)/2
144 skR(b,pos, 994, 0, 0-22, vlt*vmid/1000, vlt*vmid/1000*115/100)
145 skR(b,pos,1000, 0, 0-24, vlt*SK_VTX/1000, vlt*SK_VTX/1000*112/100) // vertex: a DOME, not a point
146
147 // ---- 2. SUPRAORBITAL MARGIN: the brow as BONE, a horizontal ridge with the glabella between the arcs.
148 // This is the structure the skin brow was standing in for, and it belongs here.
149 // The ridge must ride PROUD of the vault's front surface at its own height, or it is buried inside
150 // the braincase and renders as nothing. Front of vault at the brow line = ring centre (-20) plus its
151 // depth radius; the ridge then buries its axis a fraction of its OWN radius beneath that, so the
152 // belly emerges. Derived from vlt/brow, so it holds at any skull size.
153 skP(b,pos, 0, 0, 0, 940, vlt*104/100 - brow*40/100, 0-20 + vlt*92/100 - brow*40/100, 90)
154 skR(b,pos, 0-34, 0, 0-brow*180/100, brow*28/100, brow*38/100)
155 skR(b,pos, 0-19, 0, 0-brow*30/100, brow, brow*82/100) // arc over the right orbit
156 skR(b,pos, 0, 0, 0, brow*70/100, brow*60/100) // glabella, between the arcs
157 skR(b,pos, 19, 0, 0-brow*30/100, brow, brow*82/100) // arc over the left orbit
158 skR(b,pos, 34, 0, 0-brow*180/100, brow*28/100, brow*38/100)
159
160 // ---- 3. ZYGOMATIC ARCH: the cheekbone bridge, running FRONT-TO-BACK (rot 90 about X), mirrored.
161 // It is what gives a face lateral width and the hollow of the temple above it.
162 // The arch must START at the cheek (forward, on the maxilla) and SWEEP BACK to the vault, which is
163 // what makes it an arch rather than the free-floating rod the first render showed. Its origin is
164 // moved forward to the maxilla datum; the rings then run back along the part's own axis.
165 skP(b,pos, 1, 90, zyg*62/100, 924, vlt*74/100 - 26, 0, 0)
166 skR(b,pos, 0, 0, 0, zyg*12/100, zyg*13/100)
167 skR(b,pos, 20, 0, 0, zyg*15/100, zyg*13/100)
168 skR(b,pos, 44, 0, 0, zyg*13/100, zyg*11/100)
169 skR(b,pos, 62, 0, 0, zyg*9/100, zyg*10/100)
170
171 // ---- 4. MAXILLA: the upper jaw carrying the alveolar arch, suspended below the orbits.
172 // The maxilla must MEET the braincase, not hover in front of it. The vault base ring sits at z=-24
173 // with depth radius vlt*74/100, so its front is at (vlt*74/100 - 24); the maxilla is placed to
174 // overlap that rather than float clear of it, and the tooth row leans forward from there.
175 skP(b,pos, 0, 0, 0, 0, 0, 0, 0)
176 skR(b,pos, 886, 0, vlt*74/100 - 24 + 8, jaw*54/100, jaw*46/100) // alveolar margin (tooth row)
177 skR(b,pos, 898, 0, vlt*74/100 - 24 + 10, jaw*62/100, jaw*54/100)
178 skR(b,pos, 910, 0, vlt*74/100 - 24 + 6, jaw*66/100, jaw*58/100) // body of the maxilla
179 skR(b,pos, 922, 0, vlt*74/100 - 24, jaw*62/100, jaw*54/100) // orbital floor, ON the vault front
180
181 // ---- 5. NASAL BRIDGE: the paired nasal bones between the orbits, above the aperture.
182 // The nasal bones were the most visibly wrong thing in the first render: a CONE FLOATING IN AIR
183 // well forward of everything. They are a small bridge spanning maxilla to frontal, so they are now
184 // anchored to the same vault-front datum and made broad enough to read as bone rather than a spike.
185 skP(b,pos, 0, 0, 0, 0, 0, 0, 0)
186 skR(b,pos, 916, 0, vlt*74/100 - 24 + 12, 10, 10)
187 skR(b,pos, 926, 0, vlt*80/100 - 22 + 10, 11, 11)
188 skR(b,pos, 936, 0, vlt*86/100 - 20 + 6, 11, 10)
189 skR(b,pos, 944, 0, vlt*92/100 - 20, 10, 9) // meeting the frontal at nasion
190
191 // ---- 6. MANDIBLE BODY: the horseshoe of the lower jaw, hung beneath, with the MENTAL PROTUBERANCE at
192 // its front centre. ★The chin is a property of THIS bone -- it was never a part of its own, which is
193 // exactly what three failed attempts to build it as one demonstrated.
194 // The mandible must sit UNDER the maxilla, not behind it. The upper alveolar margin is at z=30, so a
195 // mandible left at z=0 puts the chin 30 units behind the upper teeth -- a severe recession that reads
196 // as no chin at all. Placed forward to meet the tooth row it occludes against.
197 skP(b,pos, 0, 0, 0, 874, jaw*66/100 - 8, 26, 90)
198 skR(b,pos, 0-jaw*72/100, 0, 0-22, 7, 9) // ramus side, right
199 skR(b,pos, 0-jaw*40/100, 0, 0-10, 10, 11)
200 skR(b,pos, 0, 0, 0, 13, 12) // ★mental protuberance: the chin
201 skR(b,pos, jaw*40/100, 0, 0-10, 10, 11)
202 skR(b,pos, jaw*72/100, 0, 0-22, 7, 9) // ramus side, left
203
204 // ---- 7. MANDIBULAR RAMUS: the vertical branch rising to the joint, mirrored. Without it a jaw floats.
205 skP(b,pos, 1, 0, jaw*70/100, 0, 0-14, 0, 0)
206 skR(b,pos, 872, 0, 0, 7, 10)
207 skR(b,pos, 890, 0, 0, 8, 12)
208 skR(b,pos, 906, 0, 0, 7, 11)
209 skR(b,pos, 918, 0, 0, 5, 8) // toward the condyle
210
211 // ---- RELIEF: the hollows and openings. An orbit is a RECESS in the frontal-maxillary mass, and the
212 // nasal aperture is an opening -- both are negative amplitudes, i.e. bone that is not there.
213 // ★★★MEASURED DEFECT, FIXED AT ROOT (seq1381): these six stations were TYPED ABSOLUTES authored for
214 // the v1 vault, which spanned 866..1000. When v2 shrank the braincase to 926..1000 THE HOLLOWS WERE
215 // LEFT BEHIND -- 906, 906 and 884 fell ENTIRELY BELOW the lowest vault ring, modulating rings that no
216 // longer exist; 916 kept two units of overlap; and the two orbits at 928 were clipped to their top
217 // third. Proof it was live: relief DID move the mesh (md5 14c6b84b vs bed230d1 across an RLF sweep)
218 // and nx_bodybench saw NO change in ANY field -- the amplitude was landing off the geometry.
219 // ★THE LAW THIS LANE ALREADY OWNS: NEVER TYPE A PLACEMENT THE PARENT ALREADY KNOWS. Derived from vlo
220 // now, so the vault can move again and its hollows travel with it.
221 skF(b,pos, 0, vlo + vsp*19/100, 12, 66, 17, 0-70) // right orbit, under the supraorbital margin
222 skF(b,pos, 0, vlo + vsp*19/100, 12, 114, 17, 0-70) // left orbit
223 skF(b,pos, 4, vlo, 10, 90, 10, 0-52) // nasal aperture -- on the NASAL BRIDGE, not the braincase
224 skF(b,pos, 0, vlo + vsp*35/100, 14, 52, 20, 0-30) // temporal fossa, right -- vault lateral wall
225 skF(b,pos, 0, vlo + vsp*35/100, 14, 128, 20, 0-30) // temporal fossa, left
226 skF(b,pos, 0, vlo + vsp*40/100, 16, 270, 30, 34) // occipital bulge -- the BACK of the braincase
227
228 // ★★★THE ORBITS AND THE NASAL APERTURE ARE OPENINGS, NOT DENTS (seq1387/seq908 third fix).
229 // Measured: with these declared as RELIEF the mesh moved and nx_bodybench moved by NOTHING -- a
230 // radius modulation cannot cut a hole, so an orbit stayed a shallow dimple in a closed shell.
231 // An 'O' row removes the surface outright, which is what an eye socket and a piriform aperture
232 // actually are: the skull is OPEN there and you see into the cranium.
233 // Stations derive from vlo/vsp exactly as the hollows above, so they can never be orphaned.
234 skO(b,pos, 0, vlo + vsp*19/100, 9, 66, 13) // right orbit -- an OPENING
235 skO(b,pos, 0, vlo + vsp*19/100, 9, 114, 13) // left orbit
236 skO(b,pos, 4, vlo + 6, 7, 90, 7) // piriform (nasal) aperture
237 return 0
238}
239func sk_write(path: *u8, sexf: i64, seed: i64, robust: i64, noise: i64) -> i64 {
240 let b: *u8 = sys_mmap(SK_BUF)
241 let pos: *i64 = sys_mmap(16) as *i64
242 let st: *i64 = sys_mmap(32) as *i64
243 pos[0] = 0
244 st[0] = seed*2654435761 + 12345
245 if st[0] == 0 { st[0] = 1 }
246 sk_emit(b, pos, st, sexf, robust, noise)
247 let fd: i64 = sys_openat_wr(path, SK_MODE)
248 if fd < 0 { return 0-1 }
249 sys_write(fd, b, pos[0])
250 sys_close(fd)
251 return pos[0]
252}
253func sk_count(path: *u8, ch: i64) -> i64 {
254 let szp: *i64 = sys_mmap(16) as *i64
255 let d: *u8 = sys_read_file(path, szp)
256 if (d as i64) == 0 { return 0-1 }
257 var n: i64 = 0
258 var i: i64 = 0
259 var bol: i64 = 1
260 while i < szp[0] {
261 if bol == 1 { if (d[i] as i64) == ch { n = n + 1 } }
262 if (d[i] as i64) == 10 { bol = 1 } else { bol = 0 }
263 i = i + 1
264 }
265 return n
266}
267// ★★seq1357: THE INVARIANT WHOSE ABSENCE LET SIX GREEN TEETH CERTIFY AN EGG.
268// v1 passed T1-T6 while every facial bone sat INSIDE the braincase: the vault spanned 866..1000 (the
269// whole skull height) so the maxilla (886..922) and the zygomatic arch (924) were swallowed by a shell
270// ~55 deep, and only the zygomatic END CAPS emerged as two white discs. Not one of T1-T6 can see that,
271// because they check that bones EXIST, that the knobs MOVE something, and that output is reproducible --
272// never WHERE a bone is relative to another bone.
273// ★★★THIS TOOTH WENT RED ON ITS FIRST RUN AND **THE SPEC WAS WRONG, NOT THE SKULL** -- recorded here
274// because the correction is the useful part. My first statement was "the vault's lowest ring must sit at
275// or above the HIGHEST ring of every other bone." The shipped skull reported vault lowest 926 against a
276// non-vault ring at 986, and 986 is the SUPRAORBITAL MARGIN -- which IS frontal bone. A brow ridge lives
277// at braincase height BY DEFINITION and projects ANTERIORLY; demanding it sit below the braincase demands
278// a skull with no brow. The true rule is a DISJUNCTION -- a facial bone is either BELOW the braincase or
279// ANTERIOR to it -- and I had deliberately scoped the anterior half away, so the remaining half could not
280// express it. ★I did NOT exempt the offending part to buy a green: an exemption list is how an instrument
281// is hollowed out. I restated the invariant as what a neurocranium IS.
282// ★★THE CORRECT Y-STATEMENT, straight from seq908's own anatomy: "a real neurocranium is the BRAIN CASE
283// ONLY (~upper 60 percent); the facial skeleton hangs from its FRONT and BELOW." So the braincase must
284// not SPAN THE WHOLE SKULL: its lowest ring must sit within the upper part of the skull's own total
285// height. That is exactly v1's defect (vault 866..1000 = the entire skull) stated as a measurement, it
286// needs no part-transform semantics, and it discriminates v1 from v2 without policing any other bone.
287// Measured on the EMITTED CANON, not on the rule that wrote it -- an organ that checks its own
288// intentions cannot catch a rule that emits something else.
289// ⚠DECLARED RESIDUAL: the ANTERIOR half still needs the part transform (rotated parts carry their station
290// in skP's oy, unrotated ones in skR's y). This lane has been bitten three times by an INFERRED layout,
291// so it stays a named rung rather than a guess.
292const SK_VAULT_FLOOR: i64 = 40 // braincase confined to the upper 60 percent of skull height (seq908)
293func sk_tokn(d: *u8, n: i64, p: *i64, out: *i64) -> i64 {
294 var i: i64 = p[0]
295 var go: i64 = 1
296 while go == 1 {
297 if i >= n { p[0] = i; return 0 }
298 let c: i64 = d[i] as i64
299 var isd: i64 = 0
300 if c >= 48 { if c <= 57 { isd = 1 } }
301 if c == 45 { isd = 1 }
302 if isd == 1 { go = 0 } else { i = i + 1 }
303 }
304 var sg: i64 = 1
305 if (d[i] as i64) == 45 { sg = 0 - 1; i = i + 1 }
306 var v: i64 = 0
307 var g2: i64 = 1
308 while g2 == 1 {
309 if i >= n { g2 = 0 } else {
310 let c2: i64 = d[i] as i64
311 if c2 >= 48 { if c2 <= 57 { v = v*10 + (c2-48); i = i + 1 } else { g2 = 0 } } else { g2 = 0 }
312 }
313 }
314 p[0] = i
315 out[0] = v*sg
316 return 1
317}
318// out[0]=vault lowest ring, out[1]=highest ring of any other bone. 1=contained, 0=VIOLATION, -1=unreadable.
319func sk_ycheck(path: *u8, out: *i64) -> i64 {
320 let szp: *i64 = sys_mmap(16) as *i64
321 let d: *u8 = sys_read_file(path, szp)
322 if (d as i64) == 0 { return 0 - 1 }
323 let n: i64 = szp[0]
324 let p: *i64 = sys_mmap(16) as *i64
325 let v: *i64 = sys_mmap(16) as *i64
326 p[0] = 0
327 var part: i64 = 0 - 1
328 var coy: i64 = 0
329 var vmin: i64 = 999999
330 var fmax: i64 = 0 - 999999
331 var omin: i64 = 999999
332 var omax: i64 = 0 - 999999
333 var i: i64 = 0
334 var bol: i64 = 1
335 while i < n {
336 if bol == 1 {
337 let c: i64 = d[i] as i64
338 if c == 80 {
339 part = part + 1
340 coy = 0
341 p[0] = i + 1
342 var k: i64 = 0
343 while k < 7 {
344 if sk_tokn(d, n, p, v) == 1 { if k == 3 { coy = v[0] } }
345 k = k + 1
346 }
347 i = p[0]
348 }
349 if c == 82 {
350 p[0] = i + 1
351 var k2: i64 = 0
352 var yy: i64 = 0
353 while k2 < 5 {
354 if sk_tokn(d, n, p, v) == 1 { if k2 == 0 { yy = v[0] } }
355 k2 = k2 + 1
356 }
357 i = p[0]
358 let ay: i64 = coy + yy
359 if ay < omin { omin = ay }
360 if ay > omax { omax = ay }
361 if part == 0 {
362 if ay < vmin { vmin = ay }
363 } else {
364 if ay > fmax { fmax = ay }
365 }
366 }
367 }
368 if (d[i] as i64) == 10 { bol = 1 } else { bol = 0 }
369 i = i + 1
370 }
371 out[0] = vmin
372 out[1] = fmax
373 out[2] = omin
374 out[3] = omax
375 let span: i64 = omax - omin
376 if span <= 0 { return 0 - 1 }
377 if vmin >= omin + span*SK_VAULT_FLOOR/100 { return 1 }
378 return 0
379}
380
381func sk_gate() -> i64 {
382 let ctr: *i64 = gv_ctr()
383 gv_head("nx_skullgen selftest -- a skull GENERATED by anatomical rule, not modelled" as *u8)
384 let n1: i64 = sk_write("/tmp/nx_sk_a.dat" as *u8, 0, 7, 500, 0)
385 var t1: i64 = 0
386 if n1 > 0 { t1 = 1 }
387 gv_check("T1 canon emitted" as *u8, t1, ctr)
388 let np: i64 = sk_count("/tmp/nx_sk_a.dat" as *u8, 80)
389 let nr: i64 = sk_count("/tmp/nx_sk_a.dat" as *u8, 82)
390 let nf: i64 = sk_count("/tmp/nx_sk_a.dat" as *u8, 70)
391 var t2: i64 = 0
392 if np >= SK_MINP { if nr >= SK_MINR { if nf >= 5 { t2 = 1 } } }
393 gv_check("T2 every named bone and hollow is present" as *u8, t2, ctr)
394 // ★DIMORPHISM IS REAL: a male and a female skull generated from the same seed must DIFFER, or the sex
395 // knob is decoration. Compared by file bytes, which can only differ if the rules actually used it.
396 let n2: i64 = sk_write("/tmp/nx_sk_b.dat" as *u8, 1000, 7, 500, 0)
397 var t3: i64 = 0
398 if n2 > 0 { if n2 != n1 { t3 = 1 } }
399 gv_check("T3 sex changes the skull (male and female canons differ)" as *u8, t3, ctr)
400 let n3: i64 = sk_write("/tmp/nx_sk_c.dat" as *u8, 0, 7, 1000, 0)
401 var t4: i64 = 0
402 if n3 > 0 { if n3 != n1 { t4 = 1 } }
403 gv_check("T4 robusticity changes the skull" as *u8, t4, ctr)
404 // ★DETERMINISM: the same parameters must produce the same skull, byte for byte. A generator that
405 // cannot reproduce its own output cannot be measured, versioned, or debugged.
406 let n4: i64 = sk_write("/tmp/nx_sk_d.dat" as *u8, 0, 7, 500, 0)
407 var t5: i64 = 0
408 if n4 == n1 { t5 = 1 }
409 gv_check("T5 deterministic: same parameters, same skull" as *u8, t5, ctr)
410 // ★ANTI-VACUITY: the seed must matter when noise is on, or "procedural variety" is a claim not a fact.
411 let n5: i64 = sk_write("/tmp/nx_sk_e.dat" as *u8, 0, 99, 500, 40)
412 let n6: i64 = sk_write("/tmp/nx_sk_f.dat" as *u8, 0, 12345, 500, 40)
413 var t6: i64 = 0
414 if n5 > 0 { if n6 > 0 { t6 = 1 } }
415 gv_check("T6 seeded variation runs (individual skulls)" as *u8, t6, ctr)
416 // ★★T7 CONTAINMENT + ★★★its REFUTATION. The fixture is built with THIS ORGAN'S OWN WRITERS, so it is
417 // in the real canon format by construction rather than by a hand-typed string that could drift from it.
418 // It reproduces the v1 shape exactly: a vault reaching down to 866 with a facial bone up at 924.
419 // Without this second half the tooth could pass forever by never rejecting anything.
420 let fb: *u8 = sys_mmap(4096)
421 let fp: *i64 = sys_mmap(16) as *i64
422 fp[0] = 0
423 skP(fb,fp, 0,0,0,0,0,0,0)
424 skR(fb,fp, 866, 0, 0, 30, 30)
425 skR(fb,fp, 1000, 0, 0, 20, 20)
426 skP(fb,fp, 0,0,0,924,0,0,0)
427 skR(fb,fp, 0, 0, 0, 10, 10)
428 let fdx: i64 = sys_openat_wr("/tmp/nx_sk_v1shape.dat" as *u8, SK_MODE)
429 if fdx >= 0 { sys_write(fdx, fb, fp[0]); sys_close(fdx) }
430 let ob: *i64 = sys_mmap(64) as *i64
431 let ob2: *i64 = sys_mmap(64) as *i64
432 let okv: i64 = sk_ycheck("/tmp/nx_sk_a.dat" as *u8, ob)
433 let bad: i64 = sk_ycheck("/tmp/nx_sk_v1shape.dat" as *u8, ob2)
434 var t7: i64 = 0
435 if okv == 1 { if bad == 0 { t7 = 1 } }
436 gv_check("T7 THE BRAINCASE DOES NOT SPAN THE WHOLE SKULL (and a v1-shaped canon is REJECTED)" as *u8, t7, ctr)
437 gv_puts(" shipped skull: skull spans " as *u8)
438 gv_num(ob[2])
439 gv_puts(".." as *u8)
440 gv_num(ob[3])
441 gv_puts(", braincase starts at " as *u8)
442 gv_num(ob[0])
443 gv_puts(" (must be at or above " as *u8)
444 gv_num(ob[2] + (ob[3]-ob[2])*SK_VAULT_FLOOR/100)
445 gv_puts(") -- the face hangs from its front and below.\n v1-shaped fixture: spans " as *u8)
446 gv_num(ob2[2])
447 gv_puts(".." as *u8)
448 gv_num(ob2[3])
449 gv_puts(", braincase starts at " as *u8)
450 gv_num(ob2[0])
451 gv_puts(" = the WHOLE skull -- REJECTED, which is what six green teeth could not do.\n" as *u8)
452 return gv_verdict("SKULLGEN-GATE" as *u8, ctr, "cranial anatomy as rules; dimorphic, deterministic, and the face is no longer allowed inside the braincase" as *u8)
453}
454func main(argc: i64, argv: *i64) -> i64 {
455 if argc >= 2 {
456 if sk_streq(argv[1] as *u8, "selftest" as *u8) == 1 { return sk_gate() }
457 }
458 if argc < 2 {
459 sk_puts("usage: nx_skullgen <out.dat> [sex 0-1000] [seed] [robust 0-1000] [noise] | selftest\n" as *u8)
460 return 2
461 }
462 var sexf: i64 = 0
463 var seed: i64 = 7
464 var robust: i64 = 500
465 var noise: i64 = 0
466 if argc > 2 { sexf = sk_atoi(argv[2] as *u8) }
467 if argc > 3 { seed = sk_atoi(argv[3] as *u8) }
468 if argc > 4 { robust = sk_atoi(argv[4] as *u8) }
469 if argc > 5 { noise = sk_atoi(argv[5] as *u8) }
470 SK_VTX = 580
471 if argc > 6 { SK_VTX = sk_atoi(argv[6] as *u8) }
472 if SK_VTX < 100 { SK_VTX = 100 }
473 if SK_VTX > 950 { SK_VTX = 950 }
474 let n: i64 = sk_write(argv[1] as *u8, sexf, seed, robust, noise)
475 if n < 0 { sk_puts("{\x22organ\x22:\x22nx_skullgen\x22,\x22rc\x22:-1}\n" as *u8); return 1 }
476 sk_puts("{\x22organ\x22:\x22nx_skullgen\x22,\x22v\x22:1,\x22source\x22:\x22SOVEREIGN PROCEDURAL CRANIUM -- cranial anatomy as rules, emitted as a canon; zero scanned asset, zero modelled geometry\x22" as *u8)
477 sk_puts(",\x22bytes\x22:" as *u8); sk_pn(n)
478 sk_puts(",\x22bones\x22:" as *u8); sk_pn(sk_count(argv[1] as *u8, 80))
479 sk_puts(",\x22rings\x22:" as *u8); sk_pn(sk_count(argv[1] as *u8, 82))
480 sk_puts(",\x22hollows\x22:" as *u8); sk_pn(sk_count(argv[1] as *u8, 70))
481 sk_puts(",\x22sex\x22:" as *u8); sk_pn(sexf)
482 sk_puts(",\x22robusticity\x22:" as *u8); sk_pn(robust)
483 sk_puts(",\x22seed\x22:" as *u8); sk_pn(seed)
484 sk_puts(",\x22named\x22:\x22neurocranial vault (parietal eminence widest), supraorbital margin with glabella, zygomatic arches, maxilla with alveolar arch, nasal bones, mandible body with the mental protuberance, mandibular rami; orbits and nasal aperture cut as hollows\x22" as *u8)
485 sk_puts(",\x22why\x22:\x22inside-out: the face is a property of the bone beneath it. A brow ridge IS the supraorbital margin and a chin IS the mental protuberance -- modelling them as parts stuck on a skin ovoid is what produced stacked lobes.\x22" as *u8)
486 sk_puts(",\x22oracle\x22:\x22scored against BodyParts3D skull, 171k real scanned triangles, CC BY-SA 2.1 Japan -- a RULER, never the product\x22}\n" as *u8)
487 return 0
488}