code wiki / _hdl_build / nx_kkfacts_gate.nx
nx_kkfacts_gate.nx source
↩ module page · 60 lines · 3232 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 let rc: i64 = gv_verdict("KKFACTS-GATE", ctr, "synthetic structural fixture, both polarities, truncation honesty" as *u8)
58 sys_exit(rc)
59 return rc
60}