An item screen the picture slides away to show, the way Zelda's does

A room with a bar, and an item screen of our own: a box, a word and three things. Play it, walk, and press Start to slide the picture down; press Start again to slide it back. The program is 339 instructions in 737 bytes, built and checked the same way.

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

On the screen

frame 50
frame 50
frame 80
frame 80
frame 120
frame 120
frame 200
frame 200

The item screen is above the room

The Legend of Zelda does not cover the room with a box when you press Start. The whole picture, room and bar together, slides down a few pixels each frame, and the item screen comes into view above it. The console has room for two screens of background, and on this board they are stacked one above the other; the item screen lives in the other one. The game draws it there a row at a time, from the bottom up, just ahead of the slide, so it never draws a row before it is about to be seen. Nothing splits the picture while it moves, and a second Start in the middle of the slide is not read. Pressing Start when it has stopped slides everything back, and nothing is drawn on the way. This cartridge does the same with a room and an item screen of its own.

this cartridgeThe Legend of Zelda
pixels the picture slides each frame43
pixels it slides in all176175
frames from Start until it stops4465
rows of the item screen drawn while it slides, and how many frames apart22, every 223, every 2
the rows are drawn from the bottom upyesyes
a second Start in the middle of the slide changed nothingyesyes
the picture is split while it slidesnono
the board's arrangement of the two screens changesno, fixed by the boardno
frames from Start until the room is back4560
rows drawn on the way back00

As written

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

;; While opening, the item screen's row that the slide is about to show,
;; if it is not there yet.
picture:
    LDA $40
    CMP #$01
    BNE nodraw
    LDA $41
    LSR A
    LSR A
    LSR A
    CMP $43
    BEQ nodraw
    STA $43
    JSR itemrow
nodraw:
    RTS
;; Row $43 of the item screen, built in $0300 and written across: the
;; box's edge on rows 10 and 27, its sides between them, the word ITEMS
;; on row 12 and the three things on row 18.
itemrow:
    LDA #$00
    LDX #$1F
empty:
    STA $0300,X
    DEX
    BPL empty
    LDA $43
    CMP #$0A
    BEQ edge
    CMP #$1B
    BEQ edge
    BCS built
    CMP #$0A
    BCC built
    LDA #$05
    STA $0304
    STA $031B
    LDA $43
    CMP #$0C
    BNE things
    LDX #$04
word:
    LDA letters,X
    STA $030D,X
    DEX
    BPL word
things:
    LDA $43
    CMP #$12
    BNE built
    LDA #$0B
    STA $030A
    LDA #$0C
    STA $030F
    LDA #$0D
    STA $0314
    JMP built
edge:
    LDA #$05
    LDX #$17
top:
    STA $0304,X
    DEX
    BPL top
built:
    LDA #$80
    STA $2000
    LDA $43
    LSR A
    LSR A
    LSR A
    ORA #$28
    STA $2006
    LDA $43
    ASL A
    ASL A
    ASL A
    ASL A
    ASL A
    STA $2006
    LDX #$00
copy:
    LDA $0300,X
    STA $2007
    INX
    CPX #$20
    BNE copy
    RTS

All the lessons