code wiki / (root) / nx_wasm_2048.nx

nx_wasm_2048.nx

buildroot/runtime/nx_wasm_2048.nx

8272 B204 linesdepth 1pulls 1 transitivereach 1 importersview sourcekind librarytopic wasm
docsdependenciesstructsconstsfunctions

about

nx_wasm_2048.nx -- the SECOND sovereign browser game genre: a 2048 sliding-tile PUZZLE, pure-Nishi NO-FLOAT, BASE-RELATIVE (same code native [base=mmap, render a PNG] and in our WASM [base=0]). Structurally distinct from the collect-class arcade (merge logic + RNG spawns, not avatar movement) -> proves the emitter generalises across genres ([[feedback-games-as-test-avenues-for-layer-completeness]]). Integer state machine + integer rasteriser + the sovereign Nishi font for tile numbers. Exports init/tick/render/score/ww/hh/fb_off = the SAME wasm interface as the arcade, so the SAME blit-only html packager serves it. license_tier: ORIGINAL

dependencies 1 imports · 1 importers

nx_nishi_font_core.nx nx_wasm_2048.nx nx_wasm_2048_gate.nx

imports: nx_nishi_font_core.nx

imported by: nx_wasm_2048_gate.nx

structs

none

consts

8const O_MAGIC_1103515245: i64 = 1103515245
9const O_MAGIC_12345: i64 = 12345
10const O_MAGIC_2025: i64 = 2025
11const W: i64 = 240
12const H: i64 = 240
13const N: i64 = 4
14const MARGIN: i64 = 12
15const CELL: i64 = 50
16const GAP: i64 = 5
17const O_FB: i64 = 0 // W*H i64 packed RGB = 460800
18const O_GRID: i64 = 460800 // N*N i64 tile values (0=empty, else power of 2)
19const O_ST: i64 = 461824 // [0]=score [1]=rng [2]=moved [3]=won
20const O_LINE: i64 = 462848 // scratch line (N i64)
21const O_TMP: i64 = 463360 // scratch line (N i64)
22const O_MSK: i64 = 464384 // font glyph scratch (base-relative)
23const O_STR: i64 = 473600 // tile-number string scratch

functions

25func rgb(r: i64, g: i64, b: i64) -> i64 { return (r & 255) | ((g & 255) << 8) | ((b & 255) << 16) }
26func fillr(base: i64, x0: i64, y0: i64, x1: i64, y1: i64, c: i64) -> i64
called by 1: render_impl
38func gget(base: i64, i: i64) -> i64 { let g: *i64 = (base + O_GRID) as *i64; return g[i] }
39func gset(base: i64, i: i64, v: i64) -> i64 { let g: *i64 = (base + O_GRID) as *i64; g[i] = v; return 0 }
40func lget(base: i64, off: i64, i: i64) -> i64 { let p: *i64 = (base + off) as *i64; return p[i] }
41func lset(base: i64, off: i64, i: i64, v: i64) -> i64 { let p: *i64 = (base + off) as *i64; p[i] = v; return 0 }
44func rng_next(base: i64) -> i64 { let st: *i64 = (base + O_ST) as *i64; st[1] = (st[1]*O_MAGIC_1103515245 + O_MAGIC_12345) & 0x7fffffff; return st[1] }
called by 1: spawn
47func spawn(base: i64) -> i64
called by 2: init_impltick_impl calls 3: ggetrng_nextgset
62func init_impl(base: i64) -> i64
called by 2: initmain calls 2: gsetspawn
72func line_move(base: i64) -> i64
called by 2: tick_implmain calls 2: lgetlset
98func read_line(base: i64, dir: i64, k: i64) -> i64
called by 1: tick_impl calls 2: lsetgget
111func write_line(base: i64, dir: i64, k: i64) -> i64
called by 1: tick_impl calls 2: gsetlget
124func tick_impl(base: i64, dir: i64) -> i64
139func tile_color(v: i64) -> i64
called by 1: render_impl calls 1: rgb
153func num_str(base: i64, v: i64) -> i64
called by 1: render_impl
165func render_impl(base: i64) -> i64
198func init() -> i64 { return init_impl(0) }
calls 1: init_impl
199func tick(dir: i64) -> i64 { return tick_impl(0, dir) }
calls 1: tick_impl
200func render() -> i64 { return render_impl(0) }
calls 1: render_impl
201func score() -> i64 { let st: *i64 = (0 + O_ST) as *i64; return st[0] }
202func fb_off() -> i64 { return O_FB }
203func ww() -> i64 { return W }
204func hh() -> i64 { return H }