Skip to content

Conversation

@jonathanpeppers
Copy link
Owner

It moves via the D pad.

Equivalent C program:

#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);
  }
}

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants