Skip to content

Add oam_spr_2x2 for drawing 16x16 sprites from sequential tiles#446

Draft
Copilot wants to merge 3 commits intomainfrom
copilot/add-oam-spr-2x2
Draft

Add oam_spr_2x2 for drawing 16x16 sprites from sequential tiles#446
Copilot wants to merge 3 commits intomainfrom
copilot/add-oam-spr-2x2

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 4, 2026

Drawing a 2×2 (16×16) sprite currently requires 4 oam_spr calls with manual offset math. oam_spr_2x2 replaces this with a single call:

// Before: 4 calls with manual x+8, y+8 offsets and OAM slot math
oam_spr(x, y, 0xD8, 0, 0);
oam_spr((byte)(x + 8), y, 0xDA, 0, 4);
oam_spr(x, (byte)(y + 8), 0xD9, 0, 8);
oam_spr((byte)(x + 8), (byte)(y + 8), 0xDB, 0, 12);

// After
oam_spr_2x2(x, y, 0xD8, 0xD9, 0xDA, 0xDB, 0, 0);

Implementation

Implemented as a compile-time intrinsic — no new 6502 subroutine needed:

  • NESLib.cs — Method stub: byte oam_spr_2x2(byte x, byte y, byte topLeft, byte bottomLeft, byte topRight, byte bottomRight, byte attr, byte sprid)
  • IL2NESWriter.OamSprites.csEmitOamSpr2x2() handler that:
    • Backward-scans IL to classify 8 args (with Stloc skip logic for Roslyn Release optimizer reordering)
    • Builds a 17-byte metasprite array at compile time from tile/attr constants
    • Emits the existing oam_meta_spr calling convention (TEMP=x, TEMP2=y, PTR=array, A=sprid)
  • IL2NESWriter.ILDispatch.cs — Dispatch routing
  • Program6502.cs — Include oam_meta_spr subroutine when oam_spr_2x2 is used

Sample updates

  • staticsprite — 4 oam_spr → 1 oam_spr_2x2 (all constant args)
  • movingsprite — 4 oam_spr → 1 oam_spr_2x2 (local x/y, constant tiles)
  • pong — Not updated (uses 1×3 paddles + single ball, not 2×2 patterns)

Tests

Two RoslynTests added: OamSpr2x2WithConstantArgs and OamSpr2x2WithLocalArgs.

Copilot AI and others added 2 commits April 4, 2026 03:06
- Add oam_spr_2x2 method stub in NESLib.cs with 8 parameters
- Add IL dispatch case in IL2NESWriter.ILDispatch.cs
- Implement EmitOamSpr2x2() handler that builds metasprite array at compile time and emits oam_meta_spr call
- Ensure oam_meta_spr subroutine is included when oam_spr_2x2 is used
- Update staticsprite and movingsprite samples to use oam_spr_2x2
- Add two RoslynTests for constant and local argument patterns
- Update PublicAPI.Unshipped.txt

Agent-Logs-Url: https://github.com/jonathanpeppers/dotnes/sessions/21fbfb2a-9c75-4408-b1f8-04fea4eee6a9

Co-authored-by: jonathanpeppers <840039+jonathanpeppers@users.noreply.github.com>
Copilot AI changed the title [WIP] Add oam_spr_2x2 for drawing 16x16 sprites from sequential tiles Add oam_spr_2x2 for drawing 16x16 sprites from sequential tiles Apr 4, 2026
Copilot AI requested a review from jonathanpeppers April 4, 2026 03:15
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.

Add oam_spr_2x2 for drawing 16x16 sprites from sequential tiles

2 participants