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
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 cartridge | Super Mario Bros. | |
|---|---|---|
| the score changes on the same frame as the coin count | yes | yes |
| tiles written to the bar around that frame | 11 | 8 |
| frames the coin is seen | 17 | 31 |
| pixels the coin rises | 27 | 38 |
| pictures the coin turns through, and frames each is shown | 4, 2 frames each | 4, 2 frames each |
| frames the points are seen, and pixels they rise | 40, rising 19 | 46, 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
RTSBefore 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