Skip to content

Add metatrigger sample with pad_trigger and pad_state support#89

Merged
jonathanpeppers merged 1 commit intomainfrom
metatrigger
Feb 15, 2026
Merged

Add metatrigger sample with pad_trigger and pad_state support#89
jonathanpeppers merged 1 commit intomainfrom
metatrigger

Conversation

@jonathanpeppers
Copy link
Owner

Summary

Adds the metatrigger sample, ported from 8bitworkshop's metatrigger.c. This demonstrates two NES input APIs:

  • *\pad_trigger()* — edge detection (fires once when a button is newly pressed)
  • *\pad_state()* — held-button state (fires continuously while held)

What it does

  • Press A/B to decrease/increase virtual brightness via \pal_bright()\
  • D-pad moves the cursor using \pad_state()\ for continuous movement
  • 8 actors rendered as metasprites

Transpiler changes

  • Removed spurious \pad_trigger/\pad_state\ additions from the \oam_spr\ handler in IL2NESWriter (they polluted \UsedMethods\ even when not called)
  • \pad_poll\ is now included as a dependency when \pad_trigger\ or \pad_state\ are directly called (they call \pad_poll\ internally)
  • \pad_trigger/\pad_state\ blocks are included when directly referenced or via the existing \oam_spr+\pad_poll\ pattern (backward compatible)

Test results

All 172 tests pass (170 existing + 2 new metatrigger tests).

Demonstrates pad_trigger() for edge detection (newly pressed buttons)
and pad_state() for held-button state. Press A/B to change virtual
brightness via pal_bright(). D-pad movement uses pad_state() for
continuous input.

Transpiler changes:
- Remove spurious pad_trigger/pad_state additions from oam_spr handler
- Include pad_poll as dependency when pad_trigger/pad_state are called
- Include pad_trigger/pad_state when directly referenced or via
  oam_spr+pad_poll pattern (backward compat)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings February 15, 2026 21:17
Copy link

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.

Pull request overview

This PR adds a new metatrigger sample that demonstrates two distinct NES controller input APIs: pad_trigger() for edge-detected button presses (fires once when newly pressed) and pad_state() for continuous held-button detection. The sample is ported from the 8bitworkshop reference implementation and allows users to control virtual brightness with A/B buttons and move a cursor with the D-pad.

The PR also includes an important transpiler fix: it removes spurious additions of pad_trigger and pad_state to UsedMethods that occurred whenever oam_spr was called, even when these methods weren't actually being used. The dependency logic in Program6502.cs has been updated to properly track these methods while maintaining backward compatibility with existing samples.

Changes:

  • Added metatrigger sample demonstrating pad_trigger() and pad_state() input APIs
  • Fixed spurious UsedMethods pollution in IL2NESWriter.EmitOamSprDecsp4()
  • Updated dependency tracking in Program6502.cs to include pad_trigger/pad_state when directly called OR via the backward-compatible oam_spr+pad_poll pattern

Reviewed changes

Copilot reviewed 8 out of 11 changed files in this pull request and generated no comments.

Show a summary per file
File Description
src/dotnes.tasks/Utilities/IL2NESWriter.cs Removed incorrect UsedMethods.Add calls for pad_trigger/pad_state from EmitOamSprDecsp4
src/dotnes.tasks/ObjectModel/Program6502.cs Updated dependency logic to include pad_poll when pad_trigger/pad_state are used, and include pad_trigger/pad_state when directly called or via backward-compatible pattern
src/dotnes.tests/TranspilerTests.cs Added test cases for metatrigger sample (debug and release)
src/dotnes.tests/TranspilerTests.Write.metatrigger.verified.bin Verified binary output for metatrigger sample tests
src/dotnes.tests/Data/metatrigger.release.dll Pre-compiled release test DLL for metatrigger
src/dotnes.tests/Data/metatrigger.debug.dll Pre-compiled debug test DLL for metatrigger
samples/metatrigger/Program.cs C# implementation of metatrigger sample demonstrating pad_trigger and pad_state
samples/metatrigger/metatrigger.csproj Project file for metatrigger sample
samples/metatrigger/metatrigger.c C reference implementation from 8bitworkshop
samples/metatrigger/chr_generic.s CHR ROM character data for graphics
samples/samples.sln Added metatrigger project to solution with all build configurations

@jonathanpeppers jonathanpeppers merged commit a7399a5 into main Feb 15, 2026
7 checks passed
@jonathanpeppers jonathanpeppers deleted the metatrigger branch February 15, 2026 22:01
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.

1 participant