A jump that feels like Mario's
A red square on a strip of ground. Right walks, A jumps. The program is 228 instructions in 513 bytes, written in the same text the autopsy writes its listings in and turned into the cartridge by the same assembler, which checks that the text gives back the cartridge byte for byte.
Play it here The cartridge, to play anywhere that plays NES cartridges: jump.nes
On the screen
Where the numbers came from
Every number in the program was read off Super Mario Bros. by playing it on our console and watching its memory after each frame: how fast the speed across grows while Right is held, how fast the jump starts, and how much is added to the speed down each frame. Two of those depend on A: while A is held and the jump is still rising, the pull is light; let go, or start to fall, and it is much stronger. That is why a tap is a hop and a long press goes high.
The two, played the same way
The same presses, played on this cartridge and on Super Mario Bros., frame for frame.
| this cartridge | Super Mario Bros. | |
|---|---|---|
| frames of Right to full speed | 38 | 40 |
| full speed, pixels a frame | 1.5 | 1.5 |
| A held 4 frames: frames in the air, pixels risen | 27 frames, 34 pixels | 27 frames, 34 pixels |
| A held 20 frames: frames in the air, pixels risen | 45 frames, 63 pixels | 45 frames, 63 pixels |
| A held 80 (70) frames: frames in the air, pixels risen | 58 frames, 71 pixels | 57 frames, 71 pixels |
One line in the wrong place
The first version pulled before it moved: each frame it added the pull to the speed and then moved by the new speed, and every jump came out lower than Mario’s. The program below moves first and pulls after, and the table above is what that order gives. What is left: with A held 80 (70) frames, this cartridge gives 58 frames, 71 pixels and Super Mario Bros. gives 57 frames, 71 pixels.
As written
The part of the program this lesson is about. The whole program is a plain text file: jump.s
;; Up and down: a new press of A on the ground starts a jump.
jump:
LDA $03
BNE air
LDA $02
EOR #$FF
AND $01
AND #$80
BEQ done
LDA #$00
STA $16
LDA #$FC
STA $17
LDA #$01
STA $03
air:
CLC
LDA $14
ADC $16
STA $14
LDA $15
ADC $17
STA $15
LDX #$60
LDA $01
AND #$80
BEQ pull
LDA $17
BPL pull
LDX #$1E
pull:
TXA
CLC
ADC $16
STA $16
LDA $17
ADC #$00
STA $17
BMI fall
CMP #$04
BCC fall
LDA #$00
STA $16
LDA #$04
STA $17
fall:
LDA $17
BMI done
LDA $15
CMP #$B0
BCC done
LDA #$B0
STA $15
LDA #$00
STA $14
STA $16
STA $17
STA $03
done:
RTS