A coin from a block and the score, the way Mario's are

The solid lesson’s level with a bar along the top: a score and a coin count. Play it and jump into the block. The program is 548 instructions in 1,379 bytes, built and checked the same way.

Play it here Change it on the desk The cartridge, to play anywhere that plays NES cartridges: coins.nes

On the screen

frame 92
frame 92
frame 98
frame 98
frame 112
frame 112
frame 140
frame 140

The count changes at once, the coin takes its time

In Super Mario Bros. the coin is counted, and the points added, on the very frame Mario’s head bumps the block, and the bar at the top is written again on that frame: the coin count, and every digit of the score, even though only one of them changed. What you see afterwards is decoration. A coin sprite pops out of the block, turning through four pictures as it rises and falls, and when it is gone the points it was worth float slowly up from where it was. This cartridge keeps the same order of events, with a coin, a flight and digits of its own.

this cartridgeSuper Mario Bros.
the score changes on the same frame as the coin countyesyes
tiles written to the bar around that frame118
frames the coin is seen1731
pixels the coin rises2738
pictures the coin turns through, and frames each is shown4, 2 frames each4, 2 frames each
frames the points are seen, and pixels they rise40, rising 1946, rising 22

As written

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

;; The bar: the score's six digits on row 2 from column 2, a coin, and
;; the coins' two digits, all written again whenever either changes.
bar:
    LDA #$20
    STA $2006
    LDA #$42
    STA $2006
    LDX #$00
digits:
    LDA $60,X
    CLC
    ADC #$2A
    STA $2007
    INX
    CPX #$06
    BNE digits
    LDA #$00
    STA $2007
    STA $2007
    LDA #$08
    STA $2007
    LDA $66
    CLC
    ADC #$2A
    STA $2007
    LDA $67
    CLC
    ADC #$2A
    STA $2007
    LDA #$00
    STA $68
    RTS
;; The coin: 18 frames, rising 3 pixels a frame for 10 and falling 2 for
;; 8; then the points, 40 frames, rising a pixel every second frame.
coin:
    LDA $69
    BEQ points
    CMP #$09
    BCC sinking
    LDA $6A
    SEC
    SBC #$03
    STA $6A
    JMP flown
sinking:
    LDA $6A
    CLC
    ADC #$02
    STA $6A
flown:
    DEC $69
    BNE floated
    LDA #$28
    STA $6D
    LDA $6A
    STA $6E
    RTS

Before this one: Ground, a block and a wall, solid the way Mario's are

Next: Walkers that turn at walls and at each other, the way Mario's Goombas do

All the lessons