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

frame 128
frame 128
frame 138
frame 138
frame 141
frame 141
frame 150
frame 150

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 cartridgeSuper Mario Bros.
the walker's speed, pixels a frame0.50.5
a stomp: across, down, the frame before6, 196, 18
a stomp: the player's speed down, before and after4, -44.38, -4
frames the walker stays flattened2525
a hit: across, down, the frame before14, 08, 8
a hit: what changedthe square is back at the startthe 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

All the lessons