1
0
Fork 0
mirror of https://github.com/imjasonh/nescript synced 2026-07-08 17:06:04 +00:00
nescript/tests/emulator/goldens
Claude 76d0fd0d28
codegen: reuse analyzer's local allocations so inline asm {param} works
Fixes compiler-bugs.md #1 — the inline-asm `{name}` resolver
looks parameters up in the analyzer's `VarAllocation` table
(because that's the only address map it has), but `IrCodeGen::new`
was minting a parallel `$0300+` range for every function-local and
ignoring what the analyzer had picked. The spill prologue wrote the
param to the codegen's private address, the inline asm read from
the analyzer's zero-page address, and nothing ever bridged the two
— `LDA {param}` would silently load whatever the RAM clear left at
the stale slot (always `0`).

Fix: drop the `local_ram_next` loop and just look each local up in
`allocations` by the analyzer's qualified name
(`__local__{scope}__{local}`). The scope string that `gen_function`
already computed for `substitute_asm_vars` is now shared with the
new address-seeding loop via a `scope_prefix_for_fn(&str)` helper,
so the two call sites can't drift. The analyzer's layout already
satisfies the "no overlapping live locals" invariant the codegen
was relying on — it scopes every local under
`__local__<scope>__<name>` so two functions with a parameter named
`x` land in different slots.

Updated `gen_function_prologue_spills_params_to_local_ram`: the
regression test for the War-era param clobbering bug was asserting
the spill's destination specifically had to be an absolute address
at `$0300+`. That's no longer the mechanism — the spill lands in
whatever slot the analyzer assigned, which is zero page when
there's room. The test now asserts the destination is *any*
address outside `$04-$07`, which is the actual invariant.

Reverted the `LDX $04` / `LDY $05` workaround in
`examples/sha256/sha_core.ne` — every primitive there now uses
`{dst}` / `{src}` / `{w_ofs}` / `{h_ofs}` / `{k_ofs}` substitution
as originally intended. The "Parameter convention" comment that
documented the workaround is gone.

Regenerated `tests/emulator/goldens/inline_asm_demo.png`: that
example's `times_four(input)` was previously returning `input`
verbatim because the inline asm's `LDA {result}` / `ASL A` /
`ASL A` / `STA {result}` operated on a zero-page byte that was
disconnected from the NEScript-level `result` variable. With the
fix, `times_four` correctly returns `input * 4`, so the
smiley-tracker's frame-180 position shifts by the expected
`(frame_count * 4) mod 256` delta. The other 33 ROMs remain
byte-identical.

Verified:
  - `cargo clippy --all-targets -- -D warnings` clean on both
    rustc 1.94.1 and 1.95.0.
  - `cargo test --all-targets`: 616 + 3 + 75 tests pass.
  - `cargo fmt --check` clean.
  - Full emulator harness: 34/34 ROMs match goldens.
  - SHA-256 of "NES" still computes to
    `AE9145DB5CABC41FE34B54E34AF8881F462362EA20FD8F861B26532FFBB84E0D`.
  - `--memory-map` output now reflects what the generated code
    actually reads and writes (previously the codegen's $0300+
    override was invisible to the dump).

https://claude.ai/code/session_01FRmSBruVWCufm3LsUVMs8v
2026-04-16 16:03:10 +00:00
..
arrays_and_functions.audio.hash tests/emulator: record audio goldens alongside screenshots 2026-04-12 22:33:48 +00:00
arrays_and_functions.png compiler: fix three scoping bugs; war: revert all local/param workarounds 2026-04-15 20:33:41 +00:00
audio_demo.audio.hash platformer: end-to-end side-scroller demo + three runtime bug fixes 2026-04-13 13:04:26 +00:00
audio_demo.png tests/emulator: record audio goldens alongside screenshots 2026-04-12 22:33:48 +00:00
auto_chr_background.audio.hash assets: auto-generate CHR data from @nametable() PNG sources 2026-04-15 03:29:58 +00:00
auto_chr_background.png assets: auto-generate CHR data from @nametable() PNG sources 2026-04-15 03:29:58 +00:00
bitwise_ops.audio.hash tests/emulator: record audio goldens alongside screenshots 2026-04-12 22:33:48 +00:00
bitwise_ops.png
bouncing_ball.audio.hash tests/emulator: record audio goldens alongside screenshots 2026-04-12 22:33:48 +00:00
bouncing_ball.png
coin_cavern.audio.hash tests/emulator: record audio goldens alongside screenshots 2026-04-12 22:33:48 +00:00
coin_cavern.png
comparisons.audio.hash tests/emulator: record audio goldens alongside screenshots 2026-04-12 22:33:48 +00:00
comparisons.png
friendly_assets.audio.hash language: pleasant asset syntax for palettes, CHR, bg, sfx, music 2026-04-13 16:09:53 +00:00
friendly_assets.png language: pleasant asset syntax for palettes, CHR, bg, sfx, music 2026-04-13 16:09:53 +00:00
function_chain.audio.hash tests/emulator: record audio goldens alongside screenshots 2026-04-12 22:33:48 +00:00
function_chain.png tests/emulator: record audio goldens alongside screenshots 2026-04-12 22:33:48 +00:00
hello_sprite.audio.hash tests/emulator: record audio goldens alongside screenshots 2026-04-12 22:33:48 +00:00
hello_sprite.png
inline_asm_demo.audio.hash tests/emulator: record audio goldens alongside screenshots 2026-04-12 22:33:48 +00:00
inline_asm_demo.png codegen: reuse analyzer's local allocations so inline asm {param} works 2026-04-16 16:03:10 +00:00
logic_ops.audio.hash tests/emulator: record audio goldens alongside screenshots 2026-04-12 22:33:48 +00:00
logic_ops.png tests/emulator: record audio goldens alongside screenshots 2026-04-12 22:33:48 +00:00
loop_break_continue.audio.hash tests/emulator: record audio goldens alongside screenshots 2026-04-12 22:33:48 +00:00
loop_break_continue.png
match_demo.audio.hash tests/emulator: record audio goldens alongside screenshots 2026-04-12 22:33:48 +00:00
match_demo.png
metasprite_demo.audio.hash parser/lowering: declarative metasprites for multi-tile sprite groups 2026-04-15 03:13:30 +00:00
metasprite_demo.png parser/lowering: declarative metasprites for multi-tile sprite groups 2026-04-15 03:13:30 +00:00
mmc1_banked.audio.hash tests/emulator: record audio goldens alongside screenshots 2026-04-12 22:33:48 +00:00
mmc1_banked.png
mmc3_per_state_split.audio.hash main: write the real mapper byte into the iNES header 2026-04-13 01:27:42 +00:00
mmc3_per_state_split.png
nested_structs.audio.hash analyzer/lowering: support nested struct fields and array struct fields 2026-04-15 02:19:49 +00:00
nested_structs.png analyzer/lowering: support nested struct fields and array struct fields 2026-04-15 02:19:49 +00:00
noise_triangle_sfx.audio.hash audio: always enable all four tone channels on sfx trigger 2026-04-14 12:09:46 +00:00
noise_triangle_sfx.png audio: triangle and noise sfx channels 2026-04-14 10:42:53 +00:00
palette_and_background.audio.hash palette/background: first-class declarations with reset-time load and runtime swaps 2026-04-13 11:11:33 +00:00
palette_and_background.png palette/background: first-class declarations with reset-time load and runtime swaps 2026-04-13 11:11:33 +00:00
platformer.audio.hash compiler: fix three scoping bugs; war: revert all local/param workarounds 2026-04-15 20:33:41 +00:00
platformer.png feat(platformer): add stomp-or-die enemy collisions, live HUD, GameOver state 2026-04-13 20:23:07 +00:00
pong.audio.hash examples/pong: production-quality Pong game with powerups and multi-ball 2026-04-16 01:25:29 +00:00
pong.png examples/pong: production-quality Pong game with powerups and multi-ball 2026-04-16 01:25:29 +00:00
scanline_split.audio.hash main: write the real mapper byte into the iNES header 2026-04-13 01:27:42 +00:00
scanline_split.png
sfx_pitch_envelope.audio.hash audio: per-frame pitch envelopes for pulse SFX 2026-04-15 02:54:56 +00:00
sfx_pitch_envelope.png audio: per-frame pitch envelopes for pulse SFX 2026-04-15 02:54:56 +00:00
sha256.audio.hash examples/sha256: interactive SHA-256 hasher with on-screen keyboard 2026-04-16 14:02:58 +00:00
sha256.png examples/sha256: interactive SHA-256 hasher with on-screen keyboard 2026-04-16 14:02:58 +00:00
sprite_flicker_demo.audio.hash sprite-per-scanline: add cycle_sprites runtime flicker + debug telemetry 2026-04-15 22:07:19 +00:00
sprite_flicker_demo.png sprite-per-scanline: add cycle_sprites runtime flicker + debug telemetry 2026-04-15 22:07:19 +00:00
sprites_and_palettes.audio.hash tests/emulator: record audio goldens alongside screenshots 2026-04-12 22:33:48 +00:00
sprites_and_palettes.png
state_machine.audio.hash tests/emulator: record audio goldens alongside screenshots 2026-04-12 22:33:48 +00:00
state_machine.png
structs_enums_for.audio.hash tests/emulator: record audio goldens alongside screenshots 2026-04-12 22:33:48 +00:00
structs_enums_for.png
two_player.audio.hash tests/emulator: record audio goldens alongside screenshots 2026-04-12 22:33:48 +00:00
two_player.png
uxrom_banked.audio.hash examples: add uxrom_banked and jsnes golden 2026-04-13 02:04:25 +00:00
uxrom_banked.png examples: add uxrom_banked and jsnes golden 2026-04-13 02:04:25 +00:00
uxrom_banked_to_banked.audio.hash codegen: support banked → banked cross-bank function calls 2026-04-15 02:37:19 +00:00
uxrom_banked_to_banked.png codegen: support banked → banked cross-bank function calls 2026-04-15 02:37:19 +00:00
uxrom_user_banked.audio.hash codegen: user code in switchable banks via cross-bank trampolines 2026-04-14 11:41:20 +00:00
uxrom_user_banked.png codegen: user code in switchable banks via cross-bank trampolines 2026-04-14 11:41:20 +00:00
war.audio.hash compiler: close out bug #4 (W0109 sprite-per-scanline) and bug #5 (real inlining) 2026-04-15 21:33:00 +00:00
war.png examples/war: redesign card art — opaque bodies, 16x16 pips, checkerboard back 2026-04-15 18:31:15 +00:00