A picture that scrolls the way Mario's does

The square from the jump lesson in a world wider than the screen. Right walks, and once the square is a little way across, the picture follows it. The program is 441 instructions in 902 bytes, built and checked the same way.

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

On the screen

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

How the land ahead is written

The picture chip holds two screens of tiles side by side, and the scroll says where in them the picture starts. Ahead of the camera, off the right edge, the program writes the land the camera is about to reach. Watching Super Mario Bros. do this, every write it made to the picture chip’s memory logged, showed the shape: each time the camera moved 32 pixels, a strip 32 pixels wide was written, as four columns of tiles going down, spread over several frames, and then that strip’s column of colour choices. This cartridge does the same, and the table measures both the same way.

this cartridgeSuper Mario Bros.
strips written in the run6340
pixels of camera between strips31 to 33, 32 on average31 to 33, 32 on average
frames a strip's countdown runs88
columns in a strip44
tiles in a column2626
colour bytes in a strip77
pixels past the right edge where a strip starts92 to 9394 to 95
frames into the strip each column is written2, 3, 6, 71, 2, 5, 6

One frame later

This cartridge writes each column one frame later in its strip (frames 2, 3, 6, 7) than Super Mario Bros. does (frames 1, 2, 5, 6). It works out the column in its main loop and the picture chip takes it in the next blank; Super Mario Bros. runs its whole game inside the blank’s interrupt, which the autopsy marks as the loop inside the interrupt.

As written

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

;; The strips. A countdown in progress goes on; otherwise a new 32-pixel
;; step of the camera starts one, for the strip eleven past it: three
;; strips beyond the right edge, as far ahead as Mario builds.
strips:
    LDA $23
    BEQ new
    DEC $23
    LDA $23
    BEQ attr
    CMP #$06
    BEQ col0
    CMP #$05
    BEQ col1
    CMP #$02
    BEQ col2
    CMP #$01
    BEQ col3
    RTS
col0:
    LDA #$00
    JMP column
col1:
    LDA #$01
    JMP column
col2:
    LDA #$02
    JMP column
col3:
    LDA #$03
column:
    STA $04
    LDA $2B
    ASL A
    ASL A
    CLC
    ADC $04
    JSR prepcol
    LDA #$01
    STA $25
    RTS
attr:
    JSR prepattr
    LDA #$01
    STA $28
    RTS
new:
    LDA $21
    ASL A
    ASL A
    ASL A
    STA $04
    LDA $20
    LSR A
    LSR A
    LSR A
    LSR A
    LSR A
    ORA $04
    CMP $22
    BEQ nostrip
    STA $22
    CLC
    ADC #$0B
    STA $2B
    LDA #$07
    STA $23
nostrip:
    RTS

All the lessons