A stomp and a hit, told apart the way Mario does
The jump lesson’s square, and something walking toward it. Come down on it and it is flattened; walk into it and the square is sent back to the start. The program is 350 instructions in 767 bytes, built and checked the same way.
Play it here The cartridge, to play anywhere that plays NES cartridges: stomp.nes
On the screen
Above and falling is a stomp; anything else is a hit
In Super Mario Bros. we watched the slots that hold the enemies and the byte that holds Mario’s state, and read where Mario and the enemy were the frame before either changed. Landing on a Goomba happened with Mario falling and above it; walking into one, with Mario on the ground beside it. This cartridge decides the same way: when the two squares overlap, it asks whether the square is falling and is the higher of the two.
| this cartridge | Super Mario Bros. | |
|---|---|---|
| the walker's speed, pixels a frame | 0.5 | 0.5 |
| a stomp: across, down, the frame before | 6, 19 | 6, 18 |
| a stomp: the player's speed down, before and after | 4, -4 | 4.38, -4 |
| frames the walker stays flattened | 25 | 25 |
| a hit: across, down, the frame before | 14, 0 | 8, 8 |
| a hit: what changed | the square is back at the start | the player's state 8 to 11 |
What the autopsy said of it
Run over this cartridge, the autopsy marked one routine as comparing two positions, compare_C1B8, with $0011,$0060 across and $0015,$0064 down: the square’s and the walker’s. It is the routine written below as touch.
As written
The part of the program this lesson is about. The whole program is a plain text file: stomp.s
;; Touching: the two 16-pixel squares overlap when they are less than
;; 14 pixels apart across and 16 down. Then, if the square is falling
;; and is the higher of the two, it is a stomp; otherwise a hit.
touch:
LDA $62
BNE apart
SEC
LDA $11
SBC $60
BPL across
EOR #$FF
CLC
ADC #$01
across:
CMP #$0E
BCS apart
SEC
LDA $15
SBC $64
STA $04
BPL down
EOR #$FF
CLC
ADC #$01
down:
CMP #$10
BCS apart
LDA $17
BMI hit
ORA $16
BEQ hit
LDA $04
BPL hit
LDA #$04
STA $62
LDA #$19
STA $63
LDA #$00
STA $16
LDA #$FC
STA $17
LDA #$01
STA $03
INC $66
apart:
RTS