code wiki / _hdl_build / nx_wire_endlesssky_gate.nx

nx_wire_endlesssky_gate.nx source

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