A status bar that stays still, the way Mario's does

The scroll lesson with a bar across the top that does not move while the level scrolls under it, and a timer in the bar counting down. The program is 517 instructions in 1,071 bytes, built and checked the same way.

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

On the screen

frame 100
frame 100
frame 400
frame 400
frame 800
frame 800
frame 1200
frame 1,200

One picture, two scrolls

The picture chip has one scroll, and it draws the picture a line at a time. To keep a bar still over a level that moves, the program changes the scroll partway down the picture. It has to know when, and the chip tells it one way: when the first sprite is drawn over a solid pixel of the background, a flag goes up. So a sprite sits behind the bar’s bottom line, the program waits for the flag, and then sets the level’s scroll for everything below. Super Mario Bros. was seen setting its level’s scroll on the same line every frame, and rewriting nothing in its bar but the timer.

this cartridgeSuper Mario Bros.
line the level's scroll is set on, frames it was, of the frames playedline 31, 1,440 of 1,440line 31, 180 of 180
the bar's scroll, set in the blank0, 00, 0
the timer: row, column, tiles2, 26, 33, 26, 3
the timer: frames between rewrites2423, 24, 25
other writes to the bar while playing00

As written

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

;; The split: wait for the flag from the last picture to clear, then for
;; sprite 0 to be drawn over the bar's line; everything under it gets
;; the level's scroll.
oldhit:
    BIT $2002
    BVS oldhit
newhit:
    BIT $2002
    BVC newhit
    LDA $21
    AND #$01
    ORA #$80
    STA $2000
    LDA $20
    STA $2005
    LDA #$00
    STA $2005
    JSR readpad
    JSR walk
    JSR jump
    JSR camera
    JSR strips
    JSR timer
    JSR draw
    JMP main

All the lessons