-
Notifications
You must be signed in to change notification settings - Fork 24
Add a "moving sprite" sample #78
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
jonathanpeppers
wants to merge
19
commits into
main
Choose a base branch
from
movingsprite
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Conversation
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
It moves via the D pad.
Equivalent C program:
```C
#include <stdlib.h>
#include <string.h>
#include "neslib.h"
//#link "chr_generic.s"
const char PALETTE[32] = {
0x30, // screen color
0x11,0x30,0x27,0x0, // background palette 0
0x1c,0x20,0x2c,0x0, // background palette 1
0x00,0x10,0x20,0x0, // background palette 2
0x06,0x16,0x26,0x0, // background palette 3
0x14,0x34,0x0d,0x0, // sprite palette 0
0x00,0x37,0x25,0x0, // sprite palette 1
0x0d,0x2d,0x3a,0x0, // sprite palette 2
0x0d,0x27,0x2a // sprite palette 3
};
void main() {
char x = 40;
char y = 40;
char pad;
pal_all(PALETTE);
ppu_on_all();
while (1) {
ppu_wait_nmi();
pad = pad_poll(0);
if (pad & PAD_LEFT) x--;
if (pad & PAD_RIGHT) x++;
if (pad & PAD_UP) y--;
if (pad & PAD_DOWN) y++;
// Draw 2x2 sprite (16x16 pixels)
oam_spr(x, y, 0xD8, 0, 0);
oam_spr(x + 8, y, 0xDA, 0, 4);
oam_spr(x, y + 8, 0xD9, 0, 8);
oam_spr(x + 8, y + 8, 0xDB, 0, 12);
}
}
```
Allow multiple labels to accumulate before an emitted instruction and treat extras as aliases. Block.cs: replace single _pendingLabel with _pendingLabels list, update Emit to attach the first pending label to the instruction and record additional pending labels as aliases (_labelAliases). EmitRange now assigns all pending labels to the first emitted instruction. SetNextLabel appends labels instead of replacing. Program6502.cs: resolve label aliases during address calculation by mapping alias names to the primary label's resolved address so non-emitting IL instructions won't lose label references.
Add proper 6502 emission and stack handling for several IL opcodes: implement ILOpCode.And by emitting an AND immediate with the mask and updating the simulated stack; add handling for long unconditional Br using EmitJMP with a computed label; and implement short conditional branches Brfalse_s and Brtrue_s by emitting BEQ/BNE (via EmitWithLabel) and popping the stack when appropriate. Labels are computed from instruction offsets and signed operands; immediate mask casting is guarded with checked((byte)mask). These changes map IL branching semantics to NES opcodes and fix stack consistency.
Block.RemoveLast now preserves any label on a removed instruction by moving it back to _pendingLabels (inserted at the front). This prevents labels from being lost when instructions are rolled back and ensures they are processed first.
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.
It moves via the D pad.
Equivalent C program: