A name typed from a grid, the way Zelda's is

A screen for typing a name, with a grid of letters we drew ourselves. Play it: the arrows move the cursor, A types the letter under it, and holding an arrow keeps it moving. The program is 268 instructions in 611 bytes, built and checked the same way.

Play it here The cartridge, to play anywhere that plays NES cartridges: menu.nes

On the screen

frame 40
frame 40
frame 100
frame 100
frame 170
frame 170
frame 230
frame 230

The cursor sits behind the letters

On the screen where you register your name, The Legend of Zelda’s cursor is a sprite drawn behind the background, so the letter under it shows through, and it blinks. It moves the frame after you press, and if you hold the button it waits a moment and then keeps going, faster. At the edge of the grid it does not stop: it carries on in reading order, so going left from the first letter takes you to the last cell. Every step makes a click, and A writes one tile, the letter, into your name the frame after. This cartridge does the same with a grid, a wait, a beat and a click of its own.

this cartridgeThe Legend of Zelda
frames from a press to the cursor moving01
frames held before it moves again2017
then frames between moves69
letters across the grid1011
left from the first cell goes to cell3943
tiles written for each letter typed, and frames after A1, 1 after1, 1 after
the cursor is drawn behind the lettersyesyes
frames the cursor is shown, then hidden16, then 168, then 8
moves that made a click13 of 1311 of 11

As written

The part of the program this lesson is about. The whole program is a plain text file: menu.s

;; Up, Down, Left and Right (bits 3 to 0 of the pad). A new press moves
;; at once and sets the wait at 20 frames; held, the cursor moves again
;; when the wait runs out, and then every 6.
steer:
    LDA $01
    AND #$0F
    BEQ still
    LDA $02
    AND #$0F
    BNE held
    LDA #$14
    STA $06
    JMP step
held:
    DEC $06
    BNE still
    LDA #$06
    STA $06
step:
    LDA $01
    LSR A
    BCS right
    LSR A
    BCS left
    LSR A
    BCS down
    LDA $40
    SEC
    SBC #$0A
    BCS moved
    ADC #$28
    JMP moved
down:
    LDA $40
    CLC
    ADC #$0A
    CMP #$28
    BCC moved
    SBC #$28
    JMP moved
left:
    LDA $40
    SEC
    SBC #$01
    BCS moved
    LDA #$27
    JMP moved
right:
    LDA $40
    CLC
    ADC #$01
    CMP #$28
    BCC moved
    LDA #$00
moved:
    STA $40
;; The click: a short high note on the first square channel.
    LDA #$9F
    STA $4000
    LDA #$00
    STA $4001
    LDA #$40
    STA $4002
    LDA #$00
    STA $4003
still:
    RTS
;; A new press of A: the letter under the cursor waits to be written at
;; the end of the name, while the name has room. The empty cell types a
;; space: nothing is written and the name moves on.
type:
    LDA $02
    EOR #$FF
    AND $01
    AND #$80
    BEQ full
    LDA $41
    CMP #$08
    BCS full
    CLC
    ADC #$CC
    STA $43
    INC $41
    LDA $40
    JSR tileof
    STA $42

All the lessons