code wiki / _hdl_build / nx_kkfacts_gate.nx
nx_kkfacts_gate.nx source
↩ module page · 108 lines · 6904 B
1// nx_kkfacts_gate.nx -- prove the Koikatsu card probe: a card is recognized by its STRUCTURE, a
2// plain PNG is not a card, truncation refuses to count. Fixture built from the published card
3// shape (PNG + IEND + KoiKatuChara marker + block names), not from any real creator's card.
4// license_tier: ORIGINAL No hw writes (Rule 26).
5import "nx_syscalls.nx"
6import "nx_gate_verdict.nx"
7import "nx_kkfacts_lib.nx"
8
9func kg_s(b: *u8, at: i64, s: *u8) -> i64 { var i: i64 = 0; var p: i64 = at; while s[i] != (0 as u8) { b[p] = s[i]; p = p + 1; i = i + 1 } return p }
10
11// minimal png head (sig + IHDR 64x32) + IEND + optional chara payload
12func kg_card(b: *u8, with_marker: i64) -> i64 {
13 var i: i64 = 0
14 while i < 512 { b[i] = 0 as u8; i = i + 1 }
15 b[0]=0x89 as u8; b[1]=0x50 as u8; b[2]=0x4e as u8; b[3]=0x47 as u8
16 b[11]=13 as u8
17 b[12]=0x49 as u8; b[13]=0x48 as u8; b[14]=0x44 as u8; b[15]=0x52 as u8
18 b[18]=0 as u8; b[19]=64 as u8
19 b[22]=0 as u8; b[23]=32 as u8
20 var p: i64 = kg_s(b, 40, "IEND" as *u8)
21 p = 40 + 4 + 4 // IEND + CRC = portrait end at 48
22 if with_marker == 0 { return p }
23 p = kg_s(b, p, "fake-lstinfo KoiKatuChara 0.0.0 " as *u8)
24 p = kg_s(b, p, "Custom " as *u8)
25 p = kg_s(b, p, "Coordinate Coordinate " as *u8)
26 p = kg_s(b, p, "Parameter Status KKEx " as *u8)
27 return p
28}
29
30func main(argc: i64, argv: *i64) -> i64 {
31 let ctr: *i64 = gv_ctr()
32 gv_head("nx_kkfacts_gate -- card structure recognized, plain PNG refused, truncation honest" as *u8)
33 let b: *u8 = sys_mmap(1024)
34 let facts: *i64 = sys_mmap(KK_N_SLOTS * 8) as *i64
35
36 // T1 a structural card parses: portrait bounds, dims, payload size, block census
37 let n1: i64 = kg_card(b, 1)
38 kk_probe(b, n1, n1, facts)
39 var t1: i64 = 0
40 if facts[0] == 1 { if facts[1] == 48 { if facts[2] == 64 { if facts[3] == 32 { if facts[4] == n1 - 48 { if facts[5] == 1 { if facts[6] == 2 { if facts[9] == 1 { t1 = 1 } } } } } } } }
41 gv_check("T1 CARD STRUCTURE MEASURED: portrait ends at IEND+8, dims 64x32, payload sized, block census Custom=1 Coordinate=2 KKEx=1 -- all from structure, no creative content read" as *u8, t1, ctr)
42
43 // T2 a plain PNG with trailing bytes but NO marker is NOT a card
44 let n2: i64 = kg_card(b, 0)
45 kk_probe(b, n2 + 64, n2 + 64, facts)
46 var t2: i64 = 0
47 if facts[0] == 0 { t2 = 1 }
48 gv_check("T2 A PLAIN PNG IS NOT A CARD: trailing bytes without the KoiKatuChara marker refuse card-ness -- presence of a tail is not presence of a character" as *u8, t2, ctr)
49
50 // T3 truncation honesty: same card, file_size larger than the window -> census slots stay -1
51 let n3: i64 = kg_card(b, 1)
52 kk_probe(b, n3, n3 + 5000, facts)
53 var t3: i64 = 0
54 if facts[0] == 1 { if facts[5] == 0 - 1 { if facts[4] == n3 + 5000 - 48 { t3 = 1 } } }
55 gv_check("T3 TRUNCATION REFUSES TO COUNT: with the payload only partially in the window the card is still detected and SIZED, but the block census stays -1 -- an undercount is worse than absence" as *u8, t3, ctr)
56
57 // T4 SLIDER DECODE EXACT: known float32 bit patterns must decode to exact permil.
58 // 0.5 = 0x3F000000 -> 500 | 1.0 = 0x3F800000 -> 1000 | 0.25 = 0x3E800000 -> 250
59 let n4: i64 = kg_card(b, 1)
60 var q: i64 = kg_s(b, n4, "shapeValueFace" as *u8)
61 b[q] = 0x93 as u8; q = q + 1
62 b[q] = 0xca as u8; b[q+1] = 0x3f as u8; b[q+2] = 0 as u8; b[q+3] = 0 as u8; b[q+4] = 0 as u8; q = q + 5
63 b[q] = 0xca as u8; b[q+1] = 0x3f as u8; b[q+2] = 0x80 as u8; b[q+3] = 0 as u8; b[q+4] = 0 as u8; q = q + 5
64 b[q] = 0xca as u8; b[q+1] = 0x3e as u8; b[q+2] = 0x80 as u8; b[q+3] = 0 as u8; b[q+4] = 0 as u8; q = q + 5
65 let vals: *i64 = sys_mmap(64) as *i64
66 let meta: *i64 = sys_mmap(16) as *i64
67 let p4: i64 = kk_decode_sliders(b, 48, q, "shapeValueFace" as *u8, vals, 8, meta)
68 var t4: i64 = 0
69 if meta[0] == 3 { if p4 == 3 { if vals[0] == 500 { if vals[1] == 1000 { if vals[2] == 250 { t4 = 1 } } } } }
70 gv_check("T4 SLIDER DECODE EXACT: msgpack fixarray of float32 0.5/1.0/0.25 decodes to permil 500/1000/250 by integer mantissa arithmetic -- the kk_decode_sliders contract fires on VALUES, not structure" as *u8, t4, ctr)
71
72 // T5 both failure polarities: a non-float element stops the parse (parsed<declared, no fabricated
73 // value), and a key the payload does not carry reports declared=-1 parsed=0.
74 var q5: i64 = kg_s(b, q, "shapeValueBody" as *u8)
75 b[q5] = 0x92 as u8; q5 = q5 + 1
76 b[q5] = 0xca as u8; b[q5+1] = 0x3f as u8; b[q5+2] = 0 as u8; b[q5+3] = 0 as u8; b[q5+4] = 0 as u8; q5 = q5 + 5
77 b[q5] = 0xc0 as u8; q5 = q5 + 1
78 let p5: i64 = kk_decode_sliders(b, 48, q5, "shapeValueBody" as *u8, vals, 8, meta)
79 var t5: i64 = 0
80 if meta[0] == 2 { if p5 == 1 { if vals[0] == 500 { t5 = 1 } } }
81 let p6: i64 = kk_decode_sliders(b, 48, q5, "shapeValueHair" as *u8, vals, 8, meta)
82 if t5 == 1 { if meta[0] == (0 - 1) { if p6 == 0 { t5 = 1 } else { t5 = 0 } } else { t5 = 0 } }
83 gv_check("T5 HONEST PARTIAL AND ABSENT: a non-float element stops the parse at parsed=1 of declared=2 (never a fabricated value), and an absent key reports declared=-1 parsed=0" as *u8, t5, ctr)
84
85 // T6/T7 THE AI SHOUJO DIALECT (2026-08-18, watch contract kk_probe_aishoujo; the REAL grounding
86 // fixture is knowledge/library/bepis/AI_248895.png, pin-verified -- this runtime fixture mirrors
87 // its measured shape: AIS_Chara marker after IEND+8, lstInfo block names, no Status block).
88 var n6: i64 = kg_card(b, 0)
89 n6 = kg_s(b, n6, "x-lstinfo AIS_Chara 1.0.0 " as *u8)
90 n6 = kg_s(b, n6, "KKEx Custom " as *u8)
91 n6 = kg_s(b, n6, "Coordinate Parameter " as *u8)
92 kk_probe_aishoujo(b, n6, n6, facts)
93 var ai_fires: i64 = 0
94 if facts[0] == 1 { if facts[5] == 1 { if facts[6] == 1 { if facts[8] == 0 { ai_fires = 1 } } } }
95 kk_probe(b, n6, n6, facts)
96 var kk_on_ai: i64 = facts[0]
97 gv_check("T6 AI DIALECT MEASURED: the AIS_Chara payload is a card to kk_probe_aishoujo (census Custom=1 Coordinate=1 Status=0 -- Status honestly absent in this family) and NOT a card to kk_probe -- the dialects discriminate, neither reads the other's family" as *u8, ((ai_fires == 1) as i64) & ((kk_on_ai == 0) as i64), ctr)
98 let n7: i64 = kg_card(b, 1)
99 kk_probe_aishoujo(b, n7, n7, facts)
100 var ai_on_kk: i64 = facts[0]
101 kk_probe_aishoujo(b, kg_card(b, 0) + 64, kg_card(b, 0) + 64, facts)
102 var ai_on_plain: i64 = facts[0]
103 gv_check("T7 neg-control-ai-refuses: the AI probe refuses BOTH a KoiKatuChara card and a plain PNG with a markerless tail -- a dialect probe that fires on foreign families is a false-ingest generator" as *u8, ((ai_on_kk == 0) as i64) & ((ai_on_plain == 0) as i64), ctr)
104
105 let rc: i64 = gv_verdict("KKFACTS-GATE", ctr, "fixtures assembled at runtime, every tooth states its own strength" as *u8)
106 sys_exit(rc)
107 return rc
108}