Two-player simultaneous input with independent sprites. More...
#include <snes.h>Classes | |
| struct | Player |
| Per-player position state. More... | |
Functions | |
| int | main (void) |
| Main entry point – two-player sprite movement demo. | |
Variables | |
| Player | p1 = {64, 112} |
| Player 1 state, initialized at left-center of screen. | |
| Player | p2 = {192, 112} |
| Player 2 state, initialized at right-center of screen. | |
| static const u8 | pal_blue [] |
| Sprite palette 0 (Player 1): Blue. | |
| static const u8 | pal_red [] |
| Sprite palette 1 (Player 2): Red. | |
| static const u8 | sprite_tile [32] |
| Inline 8x8 solid square sprite tile in SNES 4bpp format (32 bytes). | |
Two-player simultaneous input with independent sprites.
Demonstrates reading two SNES controllers simultaneously via the auto-joypad registers. The NMI handler reads both ports every frame, and padHeld(0) / padHeld(1) return the held-button bitmasks for each player. Each player controls an independent 8x8 sprite with the D-pad.
Sprite tiles are defined inline as constant data (a solid 4bpp square), and two palettes (blue for Player 1, red for Player 2) are loaded to separate CGRAM sprite palette slots so each player has a distinct color.
| int main | ( | void | ) |
Main entry point – two-player sprite movement demo.
Loads a single solid-square tile to sprite VRAM, sets up two palettes (blue for Player 1, red for Player 2), and enters a loop where each player's D-pad input moves their respective sprite independently. Both controllers are read every frame via the NMI auto-joypad mechanism.
|
static |
Sprite palette 0 (Player 1): Blue.
SNES CGRAM stores 15-bit BGR555 colors (2 bytes each, little-endian). Color 0 is transparent for sprites regardless of value. Only color 3 matters here because the tile's bitplanes produce index 3 for every pixel. 0x7CFF = B=31, G=3, R=31... wait – 0xFF,0x7C = $7CFF = blue ($7C00) + some. Actual: low=0xFF high=0x7C => word $7CFF => R=31, G=7, B=15 => bright blue.
|
static |
|
static |
Inline 8x8 solid square sprite tile in SNES 4bpp format (32 bytes).
SNES 4bpp tiles are stored as 4 interleaved bitplanes. Planes 0-1 (first 16 bytes) are all 0xFF = every pixel has bits 0-1 set. Planes 2-3 (next 16 bytes) are all 0x00 = bits 2-3 clear. Result: every pixel = color index 3 (0b0011), producing a solid square in whichever palette color 3 is assigned. No external asset file needed.