Family 4 (Input) · rung 4.2 — drive a sprite with the pad.
The rung that turns a demo into a game: read the D-pad every frame and move a sprite with it. It reuses the whole simple_sprite setup — tiles to VRAM, palette to CGRAM 128, OBJSEL — and adds one thing, the input loop. The lesson: padHeld(0) hands you the held-button bitmask; act on it, update the sprite's position with oamSetXY, and the player is in control.
- SNES Concepts
- padHeld(0) returns a 16-bit held-button bitmask (the NMI auto-reads the pad)
- KEY_UP / KEY_DOWN / KEY_LEFT / KEY_RIGHT are the D-pad bits
- oamSetXY(id, x, y) updates only a sprite's position (tile and size stay put)
- Position is 9-bit X / 8-bit Y, so walking off an edge wraps — the OAM coordinate quirk, visible here for free
- What to Observe
- A 32x32 sprite you steer with the D-pad; hold a direction to glide, and walk off an edge to see it wrap around
- Modules Used
- console, dma, sprite, input
- See also
- input.h, sprite.h, tutorial_input
Entry point — set up one sprite, then steer it with the D-pad.
The setup is identical to simple_sprite. The only new part is the loop: read the pad, nudge (x, y), push the new position to OAM, wait a frame.
- Returns
- Never returns (infinite loop).