A title drawn into the level, the way Mario's is

A title screen for our square: a level of two screens, a box that says SQUARE, a menu, and a demo that plays by itself if you leave it alone. Play it and wait, or press Select and Start. The program is 536 instructions in 1,181 bytes, built and checked the same way.

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

On the screen

frame 30
frame 30
frame 300
frame 300
frame 600
frame 600
frame 1300
frame 1,300

The title is part of the level

Super Mario Bros. does not have a separate title picture. It clears its background, draws the first screen of its first level a few columns at a time, and then writes the title box and the menu into that same picture. Its cursor is not a sprite either: pressing Select rewrites a column of three background tiles, with the cursor at the top or the bottom. If nobody presses anything, a countdown runs out and a demo starts: the level plays by itself, and the title box scrolls away with the rest of the picture, because it is part of it. When the demo ends, or Start is pressed during it, the whole thing is cleared and drawn again. This cartridge works the same way, with a level, a box and a demo of its own.

this cartridgeSuper Mario Bros.
frames from the first write to the finished title2528
whole background tables cleared first24
tiles written after that8841,794
tiles a Select writes for the cursor3, one under another3, one under another
frames from the last Select to the demo367500
frames the demo plays before the title comes back2651,117
the title scrolls away during the demoyesyes
frames from Start in the demo to the title being drawn15
frames from Start on the title to the next screen being drawn14

As written

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

;; The title, waiting: Select moves the cursor and starts the countdown
;; over; Start wipes the title for play; the countdown running out starts
;; the demo.
waiting:
    LDA $02
    EOR #$FF
    AND $01
    TAX
    AND #$20
    BEQ noselect
    LDA $43
    EOR #$01
    STA $43
    LDA #$01
    STA $09
    LDA #$00
    STA $44
    LDA #$12
    STA $45
    RTS
noselect:
    TXA
    AND #$10
    BEQ count
    LDA #$00
    STA $41
    LDA #$06
    STA $40
    RTS
count:
    INC $44
    LDA $44
    CMP #$14
    BNE still
    LDA #$00
    STA $44
    DEC $45
    BNE still
    LDA #$04
    STA $40
still:
    RTS
;; The demo: the pad is read only for Start, which brings the title back;
;; the square is moved by the list instead, entry by entry (frames, then
;; the pad), until an entry of 0 frames, which also brings the title back.
demo:
    LDA $02
    EOR #$FF
    AND $01
    AND #$10
    BNE over
    LDA $47
    BNE playing
    LDX $46
    LDA presses,X
    BEQ over
    STA $47
    INX
    LDA presses,X
    STA $0A
    INX
    STX $46
playing:
    DEC $47
    LDA $08
    STA $02
    LDA $0A
    STA $01
    STA $08
    JSR walk
    JSR jump
    RTS
over:
    JSR start
    RTS

All the lessons