Loading...
Searching...
No Matches
main.c File Reference

Single controller input display. More...

#include <snes.h>
#include <snes/text.h>
#include <snes/gameloop.h>

Functions

int main (void)
 Entry point — gameLoopRun never returns.
 
static void on_init (void)
 One-time setup. Static labels then screen on.
 
static void on_update (void)
 Per-frame: read joypad, paint the held button name.
 

Detailed Description

Single controller input display.

Reads the SNES controller and displays which button is currently held. The simplest possible input example — one controller, one text line, real-time feedback. This is the starting point for understanding how SNES games read player input.

The SNES joypad has 12 buttons: 4 face buttons (A, B, X, Y), 2 shoulder buttons (L, R), a D-pad (4 directions), START, and SELECT. The NMI handler reads the joypad automatically every VBlank. Your code just calls padHeld(0) to get the current state as a 16-bit bitmask.

Ported from PVSnesLib "controller" example by alekmaul.

SNES Concepts
  • padHeld(0) — 16-bit bitmask of currently held buttons
  • KEY_A, KEY_B, KEY_X, KEY_Y, KEY_L, KEY_R — button constants
  • KEY_UP, KEY_DOWN, KEY_LEFT, KEY_RIGHT — D-pad constants
  • KEY_START, KEY_SELECT — system button constants
  • NMI handler reads joypads automatically (padUpdate is a no-op)
What to Observe
  • Press any button — its name appears on screen immediately
  • Release — the display clears
  • Try pressing multiple buttons — only one is shown (first match)
  • The response is instant (1 frame = 16ms latency)
Modules Used
console, sprite, dma, background, text, input
See also
input.h

Function Documentation

◆ main()

int main ( void  )

Entry point — gameLoopRun never returns.

◆ on_init()

static void on_init ( void  )
static

One-time setup. Static labels then screen on.

◆ on_update()

static void on_update ( void  )
static

Per-frame: read joypad, paint the held button name.

padHeld() returns the bitmask of currently-pressed buttons (latched by the NMI handler this frame). The if/else cascade prints the first match — multiple-button combinations only show one.