Input tutorial

We'll read all 12 buttons every frame and draw a colored cell per button. Held buttons light up; released ones dim out.

1. Open the starter cart

The starter reads all 12 buttons once per frame and draws a 12×12-pixel cell for each — bright (palette index 11) when held, dim (index 5) when released. The cells are arranged in a 2-row × 8-column grid at the top-left of the screen.

variable bid
: cell ( id -- )
  dup bid !
  dup 8 / 16 * 2 +              ( id y )
  swap 8 mod 16 * 2 +           ( y x )
  swap                          ( x y )
  12 12                         ( x y w h )
  bid @ btn if 11 else 5 then   ( x y w h c )
  rect ;                        ( x y w h c -- )
: update
  0 cls
  12 0 do i cell loop ;

2. The 12 button ids

IdButton
0Up
1Down
2Left
3Right
4A
5B
6X
7Y
8L
9R
10Start
11Select

3. btn vs btnp

btn returns -1 when the button is held this frame. btnp returns -1 only on the rising edge — the first frame the button transitions from up to down. Use btnp for one-shot actions (jump, fire, menu select); use btn for continuous motion.