code wiki / _hdl_build / nx_wire_endlesssky_gate.nx
nx_wire_endlesssky_gate.nx source
↩ module page · 706 lines · 29437 B
1// nx_wire_endlesssky_gate.nx -- TITLE WIRING #3: Endless Sky (space trading / adventure). An actual
2// playable trading loop built ONLY from certified parts: nx_worldsim holds 5 factions (player-trader +
3// 4 governments) whose economy CONSERVES wealth exactly (trades move credits, production is accounted);
4// nx_plotgen generates mission graphs that the REAL nx_story_vm executes stepwise (branches taken when
5// their flag-gates are satisfied, REFUSED when not); mission content round-trips through nx_gamesave as
6// a durable content file; ship outfits apply as nx_rpgstats modifiers to cargo capacity and the trading
7// skill ranks up through rs_skill_rank; the ambient theme renders through nx_gamemusic; the whole game
8// state passes the GX-9 save/load transparency test.
9//
10// CAPS EXERCISED (bit = nx_gamebench capability index; measured mask = artifact payload[0]):
11// bit 21 world-sim-factions bit 12 dialogue-tree-branching bit 19 scripting-content-format
12// bit 9 rpg-stats-progression bit 16 audio-sfx-music bit 15 save-load-persistence
13// bit 18 ui-menus-hud (nx_gamehud: every OUTFIT PURCHASE decided through a modal menu, returned id
14// drives the buy) + bit 0 render-2d (nx_game_raster: live mission-map frame, pure fn of state).
15// NOT exercised: none of the title's required vector remains unproven by this loop.
16//
17// FLAGSHIP (mutation target): CONSERVATION. Paying a mission reward by MINTING credits instead of
18// transferring them from the government's treasury must drive the economy tooth RED (total grew beyond
19// accounted production) while the game still plays to a win.
20//
21// DIALECT: no `else if`, no `||`, no multiline `else` (nx_cc parser desync -- see nx_wire_probe.nx aux2).
22// license_tier: ORIGINAL expect_exit: 0
23import "nx_syscalls.nx"
24import "nx_gamehud.nx"
25import "nx_game_raster.nx"
26import "nx_frame_sanity.nx"
27import "nx_wire_harness.nx"
28import "nx_gamesave.nx"
29import "nx_rpgstats.nx"
30import "nx_worldsim.nx"
31import "nx_plotgen.nx"
32import "nx_gamemusic.nx"
33import "nx_audio_wav.nx"
34
35// ---- shape (data at the top, rule 11) ----
36const ES_NFAC: i64 = 5 // 0 = player-trader, 1..4 = governments
37const ES_RATE: i64 = 3 // production per territory per tick
38const ES_MAXT: i64 = 300
39const ES_MNODES: i64 = 12 // mission graph nodes
40const ES_MISSIONS_WIN: i64 = 3
41const ES_CREDITS_WIN: i64 = 1500
42const ES_CARGO_BASE: i64 = 40
43const ES_SKILL_TH: i64 = 8 // trades per skill rank
44const ES_SKILL_MAX: i64 = 5
45const ES_OUTFIT_MAX: i64 = 4
46const ES_OUTFIT_COST: i64 = 300
47// save shape
48const ES_HDRN: i64 = 24
49const ES_WSW: i64 = 52 // ws_words(5)
50const ES_NSV: i64 = 76 // 24 hdr + 52 worldsim words
51const ES_SCHEMA: i64 = 7309
52const ES_CONTENT_SCHEMA: i64 = 7319
53const ES_ART_SCHEMA: i64 = 7329
54// transparency window (tune to sit fully before the measured win turn)
55const ES_T1W: i64 = 8
56const ES_T2W: i64 = 25
57// arena offsets (i64 words)
58const EW_O_WS: i64 = 24
59const EO_CHT: i64 = 80
60const EO_CHR: i64 = 128
61const EO_CHS: i64 = 176
62const EO_IEN: i64 = 224
63const EO_HUD: i64 = 240 // nx_gamehud arena APPENDED (transient UI; hud[63]=777 lazy-init marker
64 // so restore into a zeroed arena re-inits without touching e_new/e_restore)
65const EG_WORDS: i64 = 304
66const ES_HUDINK: i64 = 30 // T11 experiential min ink (mission map is sparser than a 3D scene)
67// header fields
68const E_SEED: i64 = 0
69const E_TICK: i64 = 1
70const E_TRADES: i64 = 2
71const E_MDONE: i64 = 3
72const E_CUR: i64 = 4
73const E_FLAGS: i64 = 5
74const E_GATED: i64 = 6
75const E_BLOCKED: i64 = 7
76const E_OUTFITS: i64 = 8
77const E_WIN: i64 = 9
78const E_EXPADD: i64 = 10 // accumulated ACCOUNTED production
79const E_START: i64 = 11 // total wealth at game start
80const E_NMODS: i64 = 12
81const E_MODP: i64 = 13 // 4 pairs (kind,val) -> 13..20
82const E_STEPS: i64 = 21 // mission steps executed via sv_choose
83const E_RES1: i64 = 22
84const E_RES2: i64 = 23
85
86func ww(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 }
87func wn(v: i64) -> i64 {
88 if v==0 { sys_write(1,"0" as *u8,1); return 0 }
89 var m: i64=v; if m<0 { sys_write(1,"-" as *u8,1); m=0-m }
90 let t: *u8=sys_mmap(32); var k: i64=0
91 while m>0 { t[k]=(48+(m%10)) as u8; m=m/10; k=k+1 }
92 let o: *u8=sys_mmap(32); var q: i64=k-1; var i: i64=0
93 while q>=0 { o[i]=t[q]; i=i+1; q=q-1 }
94 sys_write(1,o,i); return 0
95}
96func ebit(i: i64) -> i64 { var v: i64=1; var k: i64=0; while k<i { v=v*2; k=k+1 } return v }
97func eckv(ck: i64, v0: i64) -> i64 {
98 var v: i64 = v0
99 if v<0 { v = (0-v)*2+1 } else { v = v*2 }
100 return (ck*131 + v) & 0x7FFFFFFFFFFFFFFF
101}
102func e_ws(e: *i64) -> *i64 { return (e as i64 + EW_O_WS*8) as *i64 }
103func e_mseed(e: *i64) -> i64 { return e[E_SEED]*31 + e[E_MDONE]*101 + 7 }
104// outfit catalog (DATA): kind 0 = +cargo, kind 1 = +cargo%
105func e_outfit_kind(i: i64) -> i64 { if i%2==0 { return 0 } return 1 }
106func e_outfit_val(i: i64) -> i64 {
107 if i==0 { return 15 }
108 if i==1 { return 20 }
109 if i==2 { return 10 }
110 return 25
111}
112func e_new(e: *i64, seed: i64) -> i64 {
113 var i: i64=0
114 while i<ES_HDRN { e[i]=0; i=i+1 }
115 e[E_SEED]=seed
116 let w: *i64 = e_ws(e)
117 ws_init(w, ES_NFAC, seed*7+1)
118 ws_set_res(w, 0, 500)
119 ws_set_pop(w, 0, 100)
120 ws_set_terr(w, 0, 0) // the player produces nothing: wealth only MOVES to them
121 var f: i64=1
122 while f<ES_NFAC {
123 ws_set_res(w, f, 2000 + f*500)
124 ws_set_pop(w, f, 500)
125 ws_set_terr(w, f, 2 + f)
126 f=f+1
127 }
128 e[E_START]=ws_total_res(w)
129 let cht: *i64 = (e as i64 + EO_CHT*8) as *i64
130 let chr: *i64 = (e as i64 + EO_CHR*8) as *i64
131 let chs: *i64 = (e as i64 + EO_CHS*8) as *i64
132 let ien: *i64 = (e as i64 + EO_IEN*8) as *i64
133 let ms: i64 = e_mseed(e)
134 pg_gen(cht, chr, chs, ien, ES_MNODES, ms)
135 return 0
136}
137func e_cargo(e: *i64) -> i64 {
138 let mods: *i64 = (e as i64 + E_MODP*8) as *i64
139 return rs_apply_mods(ES_CARGO_BASE, mods, e[E_NMODS])
140}
141// one game tick
142func e_tick(e: *i64) -> i64 {
143 if e[E_WIN]==1 { return 0 }
144 let w: *i64 = e_ws(e)
145 // 1. accounted production, then the world tick
146 let exp: i64 = ws_production(w, ES_RATE)
147 e[E_EXPADD]=e[E_EXPADD]+exp
148 ws_tick(w, ES_RATE)
149 // 2. a trading run: buy from gov A, sell to gov B at a margin; cargo caps the load
150 let gA: i64 = 1 + (e[E_TICK]%4)
151 let gB: i64 = 1 + ((e[E_TICK]+1)%4)
152 var load: i64 = 50 + (e[E_TICK]%30)
153 let cargo: i64 = e_cargo(e)
154 if load>cargo { load=cargo }
155 let skill: i64 = rs_skill_rank(e[E_TRADES], ES_SKILL_TH, ES_SKILL_MAX)
156 let margin: i64 = load/5 + skill*2
157 let m1: i64 = ws_trade(w, 0, gA, load)
158 let back: i64 = m1 + margin
159 ws_trade(w, gB, 0, back)
160 e[E_TRADES]=e[E_TRADES]+1
161 // 3. one mission step through the REAL story VM: prefer the branch choice, fall back to the spine
162 let cht: *i64 = (e as i64 + EO_CHT*8) as *i64
163 let chr: *i64 = (e as i64 + EO_CHR*8) as *i64
164 let chs: *i64 = (e as i64 + EO_CHS*8) as *i64
165 let ien: *i64 = (e as i64 + EO_IEN*8) as *i64
166 let fl: *i64 = (e as i64 + E_FLAGS*8) as *i64
167 let base: i64 = e[E_CUR]*SV_NCH
168 var stepped: i64=0
169 if cht[base+1]>=0 {
170 let wasreq: i64 = chr[base+1]
171 let nxt: i64 = sv_choose(cht, chr, chs, e[E_CUR], 1, fl)
172 if nxt>=0 {
173 if wasreq>0 { e[E_GATED]=e[E_GATED]+1 }
174 e[E_CUR]=nxt
175 stepped=1
176 e[E_STEPS]=e[E_STEPS]+1
177 }
178 if nxt<0 { e[E_BLOCKED]=e[E_BLOCKED]+1 }
179 }
180 if stepped==0 {
181 let nx2: i64 = sv_choose(cht, chr, chs, e[E_CUR], 0, fl)
182 if nx2>=0 { e[E_CUR]=nx2; e[E_STEPS]=e[E_STEPS]+1 }
183 }
184 if sv_is_end(ien, e[E_CUR])==1 {
185 // mission complete: the reward is a CONSERVED TRANSFER from the issuing government
186 let gv: i64 = 1 + (e[E_MDONE]%4)
187 let rew: i64 = 200 + e[E_MDONE]*50
188 ws_trade(w, gv, 0, rew)
189 e[E_MDONE]=e[E_MDONE]+1
190 e[E_CUR]=0
191 e[E_FLAGS]=0
192 let ms: i64 = e_mseed(e)
193 pg_gen(cht, chr, chs, ien, ES_MNODES, ms)
194 }
195 // 4. outfit purchase THROUGH THE MENU (bit 18): when a purchase is affordable the shipyard menu
196 // opens [buy, hold]; the RETURNED id drives the trade -- causal, full-wrap exercised per decision;
197 // policy (buy when affordable) rides menu ORDER so behavior and every banked ck are unchanged.
198 if e[E_OUTFITS]<ES_OUTFIT_MAX {
199 let credits: i64 = ws_res(w,0)
200 let need: i64 = 800 + 400*e[E_OUTFITS]
201 if credits>need {
202 let hud: *i64 = (e as i64 + EO_HUD*8) as *i64
203 if hud[63]!=777 { gh_init(hud, 5); hud[63]=777 }
204 let dec: i64 = wh_menu_pick2(hud, 1, ES_OUTFIT_COST, 2, credits) // MIGRATED to nx_wire_harness
205 var paid: i64 = 0
206 if dec==1 { paid = ws_trade(w, 0, 1, ES_OUTFIT_COST) }
207 if paid==ES_OUTFIT_COST {
208 let oi: i64 = e[E_OUTFITS]
209 let kk: i64 = e_outfit_kind(oi)
210 let vv: i64 = e_outfit_val(oi)
211 e[E_MODP + e[E_NMODS]*2]=kk
212 e[E_MODP + e[E_NMODS]*2 + 1]=vv
213 e[E_NMODS]=e[E_NMODS]+1
214 e[E_OUTFITS]=e[E_OUTFITS]+1
215 }
216 }
217 }
218 // 5. win check
219 if e[E_MDONE]>=ES_MISSIONS_WIN { if ws_res(w,0)>=ES_CREDITS_WIN { e[E_WIN]=1 } }
220 e[E_TICK]=e[E_TICK]+1
221 return 0
222}
223func e_run_full(e: *i64) -> i64 {
224 var go: i64=1
225 while go==1 {
226 if e[E_WIN]==1 { go=0 }
227 if e[E_TICK]>=ES_MAXT { go=0 }
228 if go==1 { e_tick(e) }
229 }
230 return e[E_TICK]
231}
232// render-2d (bit 0): the galaxy as a live 2D faction map via the certified nx_game_raster part.
233// PURE fn of state -- 5 faction columns, bar height = wealth, disc size = territory, plus a top strip
234// for missions-done + credits. 320x180.
235const ER2_W: i64 = 320
236const ER2_H: i64 = 180
237func e_render(e: *i64, fb: *i64) -> i64 {
238 let w: *i64 = e_ws(e)
239 gr_clear(fb, ER2_W, ER2_H, gr_pack(8, 10, 24))
240 var f: i64=0
241 while f<ES_NFAC {
242 let cx: i64 = 24 + f*60
243 let res: i64 = ws_res(w, f)
244 var bh: i64 = res/40
245 if bh>150 { bh=150 }
246 if bh<1 { bh=1 }
247 var cr: i64 = 90
248 var cg: i64 = 140
249 var cb: i64 = 240
250 if f>0 { cr = 60 + f*40; cg = 90; cb = 110 + f*20 }
251 gr_rect(fb, ER2_W, ER2_H, cx-14, 158-bh, cx+14, 158, gr_pack(cr, cg, cb))
252 let terr: i64 = ws_terr(w, f)
253 var rad: i64 = 3 + terr
254 if rad>14 { rad=14 }
255 gr_disc(fb, ER2_W, ER2_H, cx, 168, rad, gr_pack(cr, cg, cb))
256 f=f+1
257 }
258 gr_rect(fb, ER2_W, ER2_H, 0, 2, 6 + e[E_MDONE]*24, 8, gr_pack(240, 200, 60))
259 var credbar: i64 = ws_res(w,0)/20
260 if credbar>316 { credbar=316 }
261 gr_rect(fb, ER2_W, ER2_H, 0, 11, 4 + credbar, 16, gr_pack(120, 220, 140))
262 return 0
263}
264func e_fbck(fb: *i64) -> i64 {
265 return wh_fbck(fb, ER2_W*ER2_H) // MIGRATED to nx_wire_harness (shared frame checksum)
266}
267// T11 instrument: replay, rendering per tick; out[0]=changed frames, out[1]=final ink, out[2..7]=mid fs.
268func e_rchain(seed: i64, ticks: i64, out: *i64) -> i64 {
269 let e: *i64 = sys_mmap(EG_WORDS*8) as *i64
270 e_new(e, seed)
271 let fb: *i64 = sys_mmap(ER2_W*ER2_H*8) as *i64
272 var chain: i64 = 1469598103
273 var prev: i64=0
274 var moved: i64=0
275 var ink: i64=0
276 var t: i64=0
277 while t<ticks {
278 e_tick(e)
279 e_render(e, fb)
280 let fk: i64 = e_fbck(fb)
281 if t>0 { if fk!=prev { moved=moved+1 } }
282 prev=fk
283 chain = (chain*131 + (fk & 0xFFFFFFFF)) & 0x7FFFFFFFFFFFFFFF
284 if t==ticks/2 { fs_score_i64(fb, ER2_W, ER2_H, ((out as i64) + 2*8) as *i64) }
285 t=t+1
286 }
287 var q: i64=0
288 while q<ER2_W*ER2_H { if (fb[q] & 0xFFFFFF)!=gr_pack(8,10,24) { ink=ink+1 } q=q+1 }
289 out[0]=moved
290 out[1]=ink*1000/(ER2_W*ER2_H)
291 return chain
292}
293func e_serialize(e: *i64, S: *i64) -> i64 {
294 var i: i64=0
295 while i<ES_HDRN { S[i]=e[i]; i=i+1 }
296 let w: *i64 = e_ws(e)
297 var k: i64=0
298 while k<ES_WSW { S[ES_HDRN+k]=w[k]; k=k+1 }
299 return ES_NSV
300}
301func e_restore(e: *i64, S: *i64) -> i64 {
302 var i: i64=0
303 while i<ES_HDRN { e[i]=S[i]; i=i+1 }
304 let w: *i64 = e_ws(e)
305 var k: i64=0
306 while k<ES_WSW { w[k]=S[ES_HDRN+k]; k=k+1 }
307 // the mission graph is a PURE function of (seed, missions_done): regenerate it
308 let cht: *i64 = (e as i64 + EO_CHT*8) as *i64
309 let chr: *i64 = (e as i64 + EO_CHR*8) as *i64
310 let chs: *i64 = (e as i64 + EO_CHS*8) as *i64
311 let ien: *i64 = (e as i64 + EO_IEN*8) as *i64
312 let ms: i64 = e_mseed(e)
313 pg_gen(cht, chr, chs, ien, ES_MNODES, ms)
314 return 0
315}
316// checksum over hdr + the FULL worldsim arena (graph is a pure fn of hdr fields, covered transitively)
317func e_ck(e: *i64) -> i64 {
318 var ck: i64 = 1469598103
319 var i: i64=0
320 while i<ES_HDRN { ck = eckv(ck, e[i]); i=i+1 }
321 let w: *i64 = e_ws(e)
322 var k: i64=0
323 while k<ES_WSW { ck = eckv(ck, w[k]); k=k+1 }
324 return ck
325}
326// the ambient theme (different DATA than the D2 theme -- data-driven songs are the part's claim)
327func e_song(sng: *i64, k: i64, a2: i64, b2: i64, c2: i64) -> i64 {
328 sng[k*3]=a2; sng[k*3+1]=b2; sng[k*3+2]=c2
329 return 0
330}
331func e_render_theme(smp: *i64, nsamp: i64) -> i64 {
332 var i: i64=0
333 while i<nsamp { smp[i]=0; i=i+1 }
334 let mel: *i64 = sys_mmap(12*3*8) as *i64
335 e_song(mel,0, 0,5,3)
336 e_song(mel,1, 4,5,3)
337 e_song(mel,2, 7,5,3)
338 e_song(mel,3, 4,5,3)
339 e_song(mel,4, 0,5,6)
340 e_song(mel,5, 0-1,0,3)
341 e_song(mel,6, 9,4,3)
342 e_song(mel,7, 0,5,3)
343 e_song(mel,8, 4,5,6)
344 e_song(mel,9, 0-1,0,3)
345 e_song(mel,10, 7,4,6)
346 e_song(mel,11, 0,5,6)
347 let pad: *i64 = sys_mmap(6*3*8) as *i64
348 e_song(pad,0, 0,3,12)
349 e_song(pad,1, 7,2,12)
350 e_song(pad,2, 9,2,12)
351 e_song(pad,3, 4,3,6)
352 e_song(pad,4, 0,3,6)
353 e_song(pad,5, 0-1,0,6)
354 let TS: i64 = 1000
355 mus_render(smp, nsamp, mel, 12, 8000, 8000, TS)
356 mus_render(smp, nsamp, pad, 6, 8000, 6000, TS)
357 return nsamp
358}
359
360func main() -> i64 {
361 ww("=== nx_wire_endlesssky_gate: does the trading/adventure loop run on the certified parts? ===\n\n")
362 var pass: i64=0
363 var checks: i64=0
364 var mask: i64=0
365 let SEED: i64 = 1701
366 let e1: *i64 = sys_mmap(EG_WORDS*8) as *i64
367 let e2: *i64 = sys_mmap(EG_WORDS*8) as *i64
368 let S: *i64 = sys_mmap(ES_NSV*8+64) as *i64
369 let S2: *i64 = sys_mmap(ES_NSV*8+64) as *i64
370
371 // ---------- full deterministic run ----------
372 e_new(e1, SEED)
373 e_run_full(e1)
374 let w1: *i64 = e_ws(e1)
375 let fck: i64 = e_ck(e1)
376 let runwin: i64 = e1[E_WIN]
377 let runtick: i64 = e1[E_TICK]
378 let runmiss: i64 = e1[E_MDONE]
379 let runcred: i64 = ws_res(w1,0)
380 ww(" [run] ticks="); wn(e1[E_TICK]); ww(" win="); wn(e1[E_WIN])
381 ww(" missions="); wn(e1[E_MDONE]); ww(" credits="); wn(runcred)
382 ww(" trades="); wn(e1[E_TRADES]); ww(" steps="); wn(e1[E_STEPS])
383 ww(" gated-taken="); wn(e1[E_GATED]); ww(" blocked="); wn(e1[E_BLOCKED])
384 ww(" outfits="); wn(e1[E_OUTFITS]); ww(" ck="); wn(fck); ww("\n")
385
386 // ---------- T1 world-sim-factions (bit 21, FLAGSHIP): conservation + accounted growth ----------
387 checks=checks+1
388 var t1: i64=0
389 let endtot: i64 = ws_total_res(w1)
390 let expect: i64 = e1[E_START] + e1[E_EXPADD]
391 let r01: i64 = ws_rel(w1,0,1)
392 let r10: i64 = ws_rel(w1,1,0)
393 var negbal: i64=0
394 var f: i64=0
395 while f<ES_NFAC { if ws_res(w1,f)<0 { negbal=negbal+1 } f=f+1 }
396 if endtot==expect { if r01==r10 { if r01>0 { if negbal==0 {
397 ww("T1 GREEN worldsim: total "); wn(e1[E_START]); ww(" + accounted production "); wn(e1[E_EXPADD])
398 ww(" == final "); wn(endtot); ww(" EXACT across "); wn(e1[E_TRADES]*2)
399 ww("+ trades; relations symmetric (rel(0,1)="); wn(r01); ww("==rel(1,0)="); wn(r10)
400 ww(", warmed by trade), 0 negative balances\n")
401 t1=1; pass=pass+1
402 mask=mask+ebit(21)
403 } } } }
404 if t1==0 {
405 ww("T1 RED worldsim: end="); wn(endtot); ww(" expect="); wn(expect)
406 ww(" r01="); wn(r01); ww(" r10="); wn(r10); ww(" negbal="); wn(negbal); ww("\n")
407 }
408
409 // ---------- T2 dialogue-tree-branching (bit 12): gates TAKEN and REFUSED in-loop ----------
410 checks=checks+1
411 var t2: i64=0
412 if e1[E_GATED]>=1 { if e1[E_BLOCKED]>=1 { if e1[E_STEPS]>=10 { if e1[E_MDONE]>=1 {
413 ww("T2 GREEN dialogue: "); wn(e1[E_STEPS]); ww(" sv_choose steps; ")
414 wn(e1[E_GATED]); ww(" flag-gated branches TAKEN (requirement satisfied), ")
415 wn(e1[E_BLOCKED]); ww(" gated choices REFUSED (requirement unmet) -- branching is enforced, not decorative\n")
416 t2=1; pass=pass+1
417 mask=mask+ebit(12)
418 } } } }
419 if t2==0 {
420 ww("T2 RED dialogue: steps="); wn(e1[E_STEPS]); ww(" gated="); wn(e1[E_GATED])
421 ww(" blocked="); wn(e1[E_BLOCKED]); ww(" missions="); wn(e1[E_MDONE]); ww("\n")
422 }
423
424 // ---------- T3 scripting-content-format (bit 19): mission content round-trips through a FILE ----------
425 checks=checks+1
426 var t3: i64=0
427 let CN: i64 = ES_MNODES*SV_NCH*3 + ES_MNODES
428 let cbuf: *i64 = sys_mmap(CN*8+64) as *i64
429 let gt: *i64 = sys_mmap(ES_MNODES*SV_NCH*8+64) as *i64
430 let gr: *i64 = sys_mmap(ES_MNODES*SV_NCH*8+64) as *i64
431 let gs2: *i64 = sys_mmap(ES_MNODES*SV_NCH*8+64) as *i64
432 let ge: *i64 = sys_mmap(ES_MNODES*8+64) as *i64
433 e_new(e2, SEED)
434 let ms0: i64 = e_mseed(e2)
435 pg_gen(gt, gr, gs2, ge, ES_MNODES, ms0)
436 var ci: i64=0
437 while ci<ES_MNODES*SV_NCH { cbuf[ci]=gt[ci]; ci=ci+1 }
438 var c2i: i64=0
439 while c2i<ES_MNODES*SV_NCH { cbuf[ES_MNODES*SV_NCH + c2i]=gr[c2i]; c2i=c2i+1 }
440 var c3i: i64=0
441 while c3i<ES_MNODES*SV_NCH { cbuf[ES_MNODES*SV_NCH*2 + c3i]=gs2[c3i]; c3i=c3i+1 }
442 var c4i: i64=0
443 while c4i<ES_MNODES { cbuf[ES_MNODES*SV_NCH*3 + c4i]=ge[c4i]; c4i=c4i+1 }
444 let csr: i64 = gs_save("knowledge/nx_wire_es_missions.sav" as *u8, ES_CONTENT_SCHEMA, cbuf, CN, 20260720)
445 let cload: *i64 = sys_mmap(CN*8+64) as *i64
446 let clr: i64 = gs_load("knowledge/nx_wire_es_missions.sav" as *u8, cload, CN, 0 as *i64)
447 var cdiff: i64=0
448 ci=0
449 while ci<CN { if cload[ci]!=cbuf[ci] { cdiff=cdiff+1 } ci=ci+1 }
450 // and the loaded content matches what the LIVE game executes for mission 0 (same pure generator)
451 let cht2: *i64 = (e2 as i64 + EO_CHT*8) as *i64
452 var gdiff: i64=0
453 ci=0
454 while ci<ES_MNODES*SV_NCH { if cht2[ci]!=cload[ci] { gdiff=gdiff+1 } ci=ci+1 }
455 if csr>0 { if clr==CN { if cdiff==0 { if gdiff==0 { if runmiss>=1 {
456 ww("T3 GREEN content-format: mission graph ("); wn(CN)
457 ww(" fields) saved to knowledge/nx_wire_es_missions.sav, loaded back 0-diff, matches the live")
458 ww(" game's executed mission 0, and the engine walked it to "); wn(runmiss); ww(" completions\n")
459 t3=1; pass=pass+1
460 mask=mask+ebit(19)
461 } } } } }
462 if t3==0 {
463 ww("T3 RED content: save="); wn(csr); ww(" load="); wn(clr); ww(" cdiff="); wn(cdiff)
464 ww(" gdiff="); wn(gdiff); ww(" missions="); wn(runmiss); ww("\n")
465 }
466
467 // ---------- T4 rpg-stats (bit 9): outfits ORDER-INDEPENDENT + skill rank exact ----------
468 checks=checks+1
469 var t4: i64=0
470 let mods: *i64 = (e1 as i64 + E_MODP*8) as *i64
471 let nm: i64 = e1[E_NMODS]
472 let cfwd: i64 = rs_apply_mods(ES_CARGO_BASE, mods, nm)
473 let mrev: *i64 = sys_mmap(16*8) as *i64
474 var r: i64=0
475 while r<nm {
476 mrev[r*2] = mods[(nm-1-r)*2]
477 mrev[r*2+1] = mods[(nm-1-r)*2+1]
478 r=r+1
479 }
480 let crev: i64 = rs_apply_mods(ES_CARGO_BASE, mrev, nm)
481 let rank: i64 = rs_skill_rank(e1[E_TRADES], ES_SKILL_TH, ES_SKILL_MAX)
482 if nm>=2 { if cfwd==crev { if cfwd>ES_CARGO_BASE { if rank>=1 { if rank<=ES_SKILL_MAX {
483 ww("T4 GREEN rpgstats: "); wn(nm); ww(" outfit mods -> cargo "); wn(cfwd)
484 ww(" (fwd == rev "); wn(crev); ww(", ORDER-INDEPENDENT, > base "); wn(ES_CARGO_BASE)
485 ww("); trading skill rank "); wn(rank); ww(" from "); wn(e1[E_TRADES]); ww(" trades (exact, capped)\n")
486 t4=1; pass=pass+1
487 mask=mask+ebit(9)
488 } } } } }
489 if t4==0 {
490 ww("T4 RED rpgstats: nmods="); wn(nm); ww(" fwd="); wn(cfwd); ww(" rev="); wn(crev)
491 ww(" rank="); wn(rank); ww("\n")
492 }
493
494 // ---------- T5 music (bit 16): ambient theme, bounded + deterministic ----------
495 checks=checks+1
496 var t5: i64=0
497 let NS: i64 = 40000
498 let smp: *i64 = sys_mmap(NS*8+64) as *i64
499 e_render_theme(smp, NS)
500 var over: i64=0
501 var nonz: i64=0
502 var si: i64=0
503 while si<NS {
504 var v: i64=smp[si]
505 if v<0 { v=0-v }
506 if v>MUS_SAMPMAX { over=over+1 }
507 if v>0 { nonz=nonz+1 }
508 si=si+1
509 }
510 var sck1: i64=1469598103
511 si=0
512 while si<NS { sck1 = eckv(sck1, smp[si]); si=si+1 }
513 let smp2: *i64 = sys_mmap(NS*8+64) as *i64
514 e_render_theme(smp2, NS)
515 var sck2: i64=1469598103
516 si=0
517 while si<NS { sck2 = eckv(sck2, smp2[si]); si=si+1 }
518 let wbuf: *u8 = sys_mmap(NS*4+128)
519 let wlen: i64 = wav_render_stereo(smp, smp, NS, 8000, wbuf)
520 wav_save("knowledge/nx_wire_endlesssky.wav" as *u8, wbuf, wlen)
521 var riff: i64=0
522 if wbuf[0]==(82 as u8) { if wbuf[1]==(73 as u8) { if wbuf[2]==(70 as u8) { if wbuf[3]==(70 as u8) { riff=1 } } } }
523 if nonz>10000 { if over==0 { if sck1==sck2 { if riff==1 { if wlen>100 {
524 ww("T5 GREEN music: ambient theme (2 layers) "); wn(nonz)
525 ww(" non-zero samples, 0 past ceiling, byte-identical re-render (ck "); wn(sck1)
526 ww("), RIFF WAV "); wn(wlen); ww("B -> knowledge/nx_wire_endlesssky.wav\n")
527 t5=1; pass=pass+1
528 mask=mask+ebit(16)
529 } } } } }
530 if t5==0 {
531 ww("T5 RED music: nonz="); wn(nonz); ww(" over="); wn(over)
532 ww(" ck1="); wn(sck1); ww(" ck2="); wn(sck2); ww(" riff="); wn(riff); ww("\n")
533 }
534
535 // ---------- T6 save/load TRANSPARENCY (bit 15) ----------
536 checks=checks+1
537 var t6: i64=0
538 let bank: *i64 = sys_mmap((ES_T2W-ES_T1W+2)*8) as *i64
539 e_new(e1, SEED)
540 var t: i64=0
541 while t<ES_T1W { e_tick(e1); t=t+1 }
542 let nv_trades: i64 = e1[E_TRADES]
543 let nv_prod: i64 = e1[E_EXPADD]
544 let nv_prog: i64 = e1[E_MDONE]*100 + e1[E_CUR]
545 let ckt1: i64 = e_ck(e1)
546 bank[0]=ckt1
547 t=ES_T1W
548 while t<ES_T2W { e_tick(e1); t=t+1; let c: i64 = e_ck(e1); bank[t-ES_T1W]=c }
549 let contwin: i64 = e1[E_WIN]
550 e_new(e2, SEED)
551 t=0
552 while t<ES_T1W { e_tick(e2); t=t+1 }
553 e_serialize(e2,S2)
554 let sr: i64 = gs_save("knowledge/nx_wire_endlesssky_mid.sav" as *u8, ES_SCHEMA, S2, ES_NSV, 20260720)
555 var zi: i64=0
556 while zi<EG_WORDS { e2[zi]=0; zi=zi+1 }
557 let Sl: *i64 = sys_mmap(ES_NSV*8+64) as *i64
558 let lr: i64 = gs_load("knowledge/nx_wire_endlesssky_mid.sav" as *u8, Sl, ES_NSV, 0 as *i64)
559 e_restore(e2, Sl)
560 let ckr: i64 = e_ck(e2)
561 var mismatch: i64=0
562 if ckr!=bank[0] { mismatch=mismatch+1 }
563 t=ES_T1W
564 while t<ES_T2W {
565 e_tick(e2)
566 t=t+1
567 let c2v: i64 = e_ck(e2)
568 if c2v!=bank[t-ES_T1W] { mismatch=mismatch+1 }
569 }
570 e_serialize(e1,S)
571 e_serialize(e2,S2)
572 var fdiff: i64=0
573 var i2: i64=0
574 while i2<ES_NSV { if S[i2]!=S2[i2] { fdiff=fdiff+1 } i2=i2+1 }
575 if sr>0 { if lr==ES_NSV { if mismatch==0 { if fdiff==0 { if nv_trades>=1 { if nv_prod>0 { if nv_prog>0 { if contwin==0 {
576 ww("T6 GREEN save/load TRANSPARENT: save tick "); wn(ES_T1W)
577 ww(" -> ZEROED arena -> resume to "); wn(ES_T2W); ww(": all "); wn(ES_T2W-ES_T1W+1)
578 ww(" per-tick checksums identical, 0/"); wn(ES_NSV)
579 ww(" fields differ (world live: trades="); wn(nv_trades)
580 ww(" production="); wn(nv_prod); ww(" mission-progress="); wn(nv_prog); ww(")\n")
581 t6=1; pass=pass+1
582 mask=mask+ebit(15)
583 } } } } } } } }
584 if t6==0 {
585 ww("T6 RED transparency: save="); wn(sr); ww(" load="); wn(lr)
586 ww(" mism="); wn(mismatch); ww(" fdiff="); wn(fdiff); ww(" trades="); wn(nv_trades)
587 ww(" prod="); wn(nv_prod); ww(" prog="); wn(nv_prog); ww(" contwin="); wn(contwin); ww("\n")
588 }
589
590 // ---------- T7 corruption refused ----------
591 checks=checks+1
592 var t7: i64=0
593 let lenp: *i64 = sys_mmap(8) as *i64
594 lenp[0]=0
595 let raw: *u8 = sys_read_file("knowledge/nx_wire_endlesssky_mid.sav" as *u8, lenp)
596 if (raw as i64)!=0 {
597 let rl: i64 = lenp[0]
598 let flip: i64 = 48+40
599 raw[flip] = (raw[flip] as i64 ^ 255) as u8
600 let cfd: i64 = sys_openat_wr("knowledge/nx_wire_endlesssky_corrupt.sav" as *u8, 0x1a4)
601 if cfd>=0 {
602 sys_write(cfd, raw, rl)
603 sys_close(cfd)
604 let Sc: *i64 = sys_mmap(ES_NSV*8+64) as *i64
605 Sc[0]=777777
606 let cr: i64 = gs_load("knowledge/nx_wire_endlesssky_corrupt.sav" as *u8, Sc, ES_NSV, 0 as *i64)
607 if cr==(0-6) { if Sc[0]==777777 { t7=1 } }
608 }
609 }
610 if t7==1 {
611 ww("T7 GREEN corruption refused LOUD (rc=-6) and caller state untouched\n")
612 pass=pass+1
613 }
614 if t7==0 { ww("T7 RED corrupt-save handling failed\n") }
615
616 // ---------- T8 determinism ----------
617 checks=checks+1
618 var t8: i64=0
619 e_new(e2, SEED)
620 e_run_full(e2)
621 let fck2: i64 = e_ck(e2)
622 if fck==fck2 { if runwin==e2[E_WIN] {
623 ww("T8 GREEN deterministic: two independent full runs -> identical final checksum "); wn(fck)
624 ww(" at tick "); wn(e2[E_TICK]); ww("\n")
625 t8=1; pass=pass+1
626 } }
627 if t8==0 { ww("T8 RED run1 ck="); wn(fck); ww(" run2 ck="); wn(fck2); ww("\n") }
628
629 // ---------- T9 anti-vacuity: the trader PLAYED and WON ----------
630 checks=checks+1
631 var t9: i64=0
632 let w2: *i64 = e_ws(e2)
633 let cred2: i64 = ws_res(w2,0)
634 if e2[E_WIN]==1 { if e2[E_TICK]>10 { if e2[E_TICK]<ES_MAXT { if e2[E_MDONE]>=ES_MISSIONS_WIN { if cred2>=ES_CREDITS_WIN { if e2[E_TRADES]>=10 {
635 ww("T9 GREEN the trader PLAYED and WON: "); wn(e2[E_MDONE]); ww(" missions + ")
636 wn(cred2); ww(" credits (from 500) in "); wn(e2[E_TICK]); ww(" ticks, ")
637 wn(e2[E_TRADES]); ww(" trade runs\n")
638 t9=1; pass=pass+1
639 } } } } } }
640 if t9==0 {
641 ww("T9 RED loop hollow: win="); wn(e2[E_WIN]); ww(" ticks="); wn(e2[E_TICK])
642 ww(" missions="); wn(e2[E_MDONE]); ww(" credits="); wn(cred2); ww(" trades="); wn(e2[E_TRADES]); ww("\n")
643 }
644
645 // ---------- T10 ui-menus-hud (bit 18): every outfit buy decided through the shipyard menu ----------
646 checks=checks+1
647 let hud1: *i64 = (e1 as i64 + EO_HUD*8) as *i64
648 let esel: i64 = hud1[GH_F_NSEL]
649 // CAUSAL invariant: E_OUTFITS is incremented ONLY inside the dec==1 (menu "buy") branch, so every
650 // purchase passed through a menu decision. nsel counts ALL shipyard visits (a menu can open and the
651 // buy not complete when a later mission reward is still pending) => nsel >= outfits >= 1. The buy
652 // policy rides menu ORDER, so removing the menu (mutation: select "hold") drops outfits to 0 = RED.
653 var t10: i64=0
654 if esel>=1 { if e1[E_OUTFITS]>=1 { if esel>=e1[E_OUTFITS] { t10=1 } } }
655 if t10==1 {
656 ww("T10 GREEN ui-menus-hud: "); wn(e1[E_OUTFITS]); ww(" outfit purchases ALL gated by menu buy-decisions (")
657 wn(esel); ww(" shipyard visits >= "); wn(e1[E_OUTFITS]); ww(" completed buys)\n")
658 pass=pass+1
659 mask=mask+ebit(18)
660 }
661 if t10==0 { ww("T10 RED ui-menus-hud: nsel="); wn(esel); ww(" outfits="); wn(e1[E_OUTFITS]); ww("\n") }
662
663 // ---------- T11 render-2d-raster (bit 0): the galaxy renders as a live faction map ----------
664 checks=checks+1
665 let o11a: *i64 = sys_mmap(8*8) as *i64
666 let o11b: *i64 = sys_mmap(8*8) as *i64
667 let ch11a: i64 = e_rchain(SEED, ES_T2W, o11a)
668 let ch11b: i64 = e_rchain(SEED, ES_T2W, o11b)
669 let fsth11: *i64 = sys_mmap(FS_NMETRIC*8) as *i64
670 fs_default_th(fsth11)
671 fsth11[2]=1
672 fsth11[3]=0
673 let fsm11: *i64 = ((o11a as i64) + 2*8) as *i64
674 var t11: i64=0
675 if ch11a==ch11b { if o11a[0]>=2 { if o11a[1]>=ES_HUDINK { if fsm11[0]<=fsth11[0] { if fsm11[1]<=fsth11[1] { t11=1 } } } } }
676 if t11==1 {
677 ww("T11 GREEN render-2d: faction map deterministic over "); wn(ES_T2W); ww(" ticks, ")
678 wn(o11a[0]); ww(" frame changes, "); wn(o11a[1]); ww(" ink px, no blown/void (")
679 wn(fsm11[0]); ww("/"); wn(fsm11[1]); ww("/"); wn(fsm11[2]); ww("/"); wn(fsm11[3]); ww("/"); wn(fsm11[4]); ww(")\n")
680 pass=pass+1
681 mask=mask+ebit(0)
682 }
683 if t11==0 {
684 ww("T11 RED render-2d: chA="); wn(ch11a); ww(" chB="); wn(ch11b); ww(" changes="); wn(o11a[0])
685 ww(" ink="); wn(o11a[1]); ww(" fs="); wn(fsm11[0]); ww("/"); wn(fsm11[1]); ww("\n")
686 }
687
688 // ---------- wiring evidence artifact ----------
689 let art: *i64 = sys_mmap(16*8) as *i64
690 art[0]=mask
691 art[1]=fck
692 art[2]=runtick
693 art[3]=runmiss
694 art[4]=runcred
695 art[5]=e1[E_TRADES]
696 art[6]=e1[E_GATED]
697 art[7]=runwin
698 let aw2: i64 = gs_save("knowledge/nx_wire_endlesssky.sav" as *u8, ES_ART_SCHEMA, art, 8, 20260720)
699 ww("\nwiring artifact knowledge/nx_wire_endlesssky.sav bytes="); wn(aw2)
700 ww(" exercised_mask="); wn(mask); ww(" (bits 0,21,12,19,9,16,15,18 when all their teeth pass)\n")
701
702 ww("\n=== nx_wire_endlesssky_gate "); wn(pass); ww("/"); wn(checks)
703 if pass==checks { ww(" verdict=GREEN ===\n"); return 0 }
704 ww(" RED ===\n")
705 return 1
706}