Add set_chr_mode() API for MMC3 CHR bank switching#307
Merged
jonathanpeppers merged 6 commits intomainfrom Mar 21, 2026
Merged
Conversation
Co-authored-by: jonathanpeppers <840039+jonathanpeppers@users.noreply.github.com> Agent-Logs-Url: https://github.com/jonathanpeppers/dotnes/sessions/f65776e2-53fb-48e6-b892-9ae98a55c48d
Co-authored-by: jonathanpeppers <840039+jonathanpeppers@users.noreply.github.com> Agent-Logs-Url: https://github.com/jonathanpeppers/dotnes/sessions/f65776e2-53fb-48e6-b892-9ae98a55c48d
Copilot
AI
changed the title
[WIP] Add support for MMC3 mapper CHR bank switching
Add mmc3_set_chr_bank() API for MMC3 CHR bank switching
Mar 21, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
Adds a first-class mmc3_set_chr_bank(byte reg, byte bank) API to neslib and wires it through the transpiler so MMC3 (mapper 4) CHR bank switching can be emitted without manual poke() sequences.
Changes:
- Added
NESLib.mmc3_set_chr_bank(reg, bank)public API stub (with MMC3 CHR register docs). - Implemented IL dispatcher support to emit
$8000/$8001writes for MMC3 bank select/data. - Added a Roslyn-based test asserting the expected 6502 byte sequence and updated
PublicAPI.Unshipped.txt.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| src/neslib/PublicAPI.Unshipped.txt | Declares the new public API surface for mmc3_set_chr_bank. |
| src/neslib/NESLib.cs | Adds the mmc3_set_chr_bank stub and XML documentation. |
| src/dotnes.tasks/Utilities/IL2NESWriter.ILDispatch.cs | Adds call-dispatch lowering that emits the MMC3 bank select/data writes. |
| src/dotnes.tests/RoslynTests.cs | Adds a regression test validating emitted bytes for constant reg/bank pairs. |
Follows nesdoug's set_chr_mode_X() convention but uses a register parameter instead of 6 separate functions. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…/tests - Verify reg is a compile-time constant (LDA immediate); throw TranspileException otherwise - Remove dead bankIsStaticField branch (_lastStaticFieldAddress is never assigned) - Update XML docs to document full bank-select byte including mode bits - Add SetChrMode_SupportsLocalBankArg test for local variable bank argument Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
jonathanpeppers
approved these changes
Mar 21, 2026
Owner
jonathanpeppers
left a comment
There was a problem hiding this comment.
All 4 review comments addressed. API renamed from mmc3_set_chr_bank to set_chr_mode (nesdoug-style). All 569 tests pass.
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.
Add
set_chr_mode(byte reg, byte bank)API for MMC3 CHR bank switching, following nesdoug'sset_chr_mode_X()naming convention but with a register parameter instead of 6 separate functions.Emits inline 6502:
LDA #reg, STA $8000, LDA #bank, STA $8001set_chr_mode(byte reg, byte bank)stub with MMC3 register docsregmust be constant,banksupports constants and localsFixes #306