Skip to content

New sample: game2048 - port of 2048-NES to C# with dotnes#440

Open
jonathanpeppers wants to merge 2 commits intomainfrom
samples/game2048
Open

New sample: game2048 - port of 2048-NES to C# with dotnes#440
jonathanpeppers wants to merge 2 commits intomainfrom
samples/game2048

Conversation

@jonathanpeppers
Copy link
Copy Markdown
Owner

Port of mmuszkow/2048-nes (Unlicense) from C/cc65 to idiomatic C# using the dotnes transpiler.

Features

  • Complete 2048 game logic: slide, merge, win/loss detection
  • Title screen with START button, scrolls to game board
  • 4x4 grid with tile redraw using set_vram_update
  • Notification sprites for newly merged tiles
  • Button release detection (original behavior preserved)
  • Pre-formatted NT_UPD buffers for vertical text messages
  • Custom CHR ROM converted from original 2048.chr

Technical details

  • All game state as top-level locals (no methods needed)
  • Flat byte[16] array with y*4+x indexing (no 2D arrays)
  • Manual VRAM buffer with NT_UPD_HORZ format for tile redraws
  • Mapper 0, horizontal mirroring, 32KB PRG + 8KB CHR

Bug fixes from original

Fixes two bugs in the original C code's MOVE DOWN logic:

  • Notification flag was applied to wrong tile (map[3][j] instead of map[2][j])
  • Wrong cell was cleared (map[1][j] = 0 instead of map[0][j] = 0)

Testing

  • Added transpiler tests (debug + release) with verified snapshot
  • All 614 tests pass

Closes #379

Port of mmuszkow/2048-nes (Unlicense) from C/cc65 to idiomatic C# using
the dotnes transpiler.

Features:
- Complete 2048 game logic: slide, merge, win/loss detection
- Title screen with START button, scrolls to game board
- 4x4 grid with tile redraw using set_vram_update
- Notification sprites for newly merged tiles
- Button release detection (original behavior preserved)
- Pre-formatted NT_UPD buffers for vertical text messages
- Custom CHR ROM converted from original 2048.chr

Technical details:
- All game state as top-level locals (no methods needed)
- Flat byte[16] array with y*4+x indexing (no 2D arrays)
- Manual VRAM buffer with NT_UPD_HORZ format for tile redraws
- Mapper 0, horizontal mirroring, 32KB PRG + 8KB CHR

Fixes two bugs from original MOVE DOWN logic:
- map[2][j] notification was applied to wrong tile (map[3][j])
- map[0][j] clear was overwriting map[1][j] instead

Closes #379

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings April 3, 2026 05:00
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

The NTADR handler's backward scan for JSR pusha found one from an
unrelated computation (e.g. p1 = 4 + i * 6) that was already consumed
by a corresponding JSR popa. This caused the handler to use a stale
constant (4) as the x argument instead of loading from the variable.

Fix: after finding a JSR pusha in the backward scan, verify it wasn't
consumed by checking for a JSR popa between the pusha and the current
position. If consumed, fall through to the 'no pusha' path which
correctly identifies adjacent LDA Absolute instructions.

Also updates game2048 Program.cs with the pre-computed NTADR args
workaround and refreshes test DLLs + verified.bin snapshot.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Port 2048-NES to C# with dotnes

2 participants