Fix climber jump sprite disappearing (#276)#291
Merged
jonathanpeppers merged 3 commits intomainfrom Mar 20, 2026
Merged
Conversation
HandleStelemI1 only tracked one standalone value local (valueLocalIdx), so arr[i] = (byte)(prev_lo + dv) was emitted as LDA dv; CLC; ADC # instead of LDA prev_lo; CLC; ADC dv. The second ldloc overwrote the first, and addValue stayed 0 because the add wasn't preceded by a constant. Track both locals (valueLocalIdx + valueLocalIdx2) and emit the correct LDA local1; CLC; ADC local2 / SEC; SBC local2 pattern. This caused the climber sample's jump physics to set actor_yy_lo = dv instead of prev_lo + dv, making the Y position diverge wildly and triggering the off-screen check (rel_hi != 0), hiding the player sprite. Fixes #276 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes a transpiler codegen bug that caused incorrect byte-array element updates in the climber sample, which in turn made the player sprite disappear during jumps.
Changes:
- Extend
HandleStelemI1value-expression analysis to track a second standaloneldlocoperand. - Emit
LDA local1; CLC/SEC; ADC/SBC local2forarr[i] = (byte)(local1 +/- local2)patterns. - Update the climber
verified.binsnapshot to reflect corrected ROM output.
Reviewed changes
Copilot reviewed 1 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
src/dotnes.tasks/Utilities/IL2NESWriter.ArrayHandling.cs |
Updates stelem.i1 pattern detection/emission to support two-local add/sub value expressions. |
src/dotnes.tests/TranspilerTests.Write.climber.verified.bin |
Snapshot update for climber ROM bytes after corrected codegen. |
- Only set valueLocalIdx2 when still unset, ignoring 3rd+ locals - Use hasAdd != hasSub (XOR) so both flags set falls through - Add RoslynTests for arr[i]=(byte)(local1+local2) and subtraction Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The player sprite disappeared during jumps in the climber sample (#276).
Root Cause
The transpiler's
HandleStelemI1inIL2NESWriter.ArrayHandling.csonly tracked ONE standalone value local when analyzing the value expression for array stores. For the pattern:The second
ldloc(dv) overwrote the first (prev_lo) invalueLocalIdx, andaddValuestayed 0 because theaddinstruction wasn't preceded by a constant. This caused the transpiler to emit:Instead of the correct:
This made
actor_yy_lo[pi] = dvinstead ofprev_lo + dv, causing the Y position to diverge wildly from the scroll position. After a few frames,rel_hi != 0triggered the off-screen check, hiding the player sprite.Fix
Track both value locals (
valueLocalIdx+valueLocalIdx2) in the stelem handler's backward IL scan. When both are present with anaddorsuboperation, emitLDA local1; CLC; ADC local2(orSEC; SBC local2).Verification