Monday, July 31, 2017

*Blocks your path*

Back in my first post about breakable walls, reader Telnaior was asking about Knuckles-only walls. There's actually no consistent way to mark a wall Knuckles-only; each level handles it differently in the object's init code, though it's always based on the object's subtype. Some levels, such as Mushroom Hill Zone, make it so every wall is Knuckles-only.
loc_21818:
    move.w  ($FFFFB018).w,$30(a0)
    move.w  ($FFFFB062).w,$32(a0)
    moveq   #0,d1
    move.b  7(a0),d1
    addi.w  #$B,d1
    ...
When a breakable wall is marked Knuckles-only, control is deferred to loc_21818, at first identical to loc_21568, which we've studied before. The interesting bits start at loc_21862, where we check whether the wall should break.
loc_21862:
    lea      (Player_1).w,a1
    move.w  $30(a0),d1
    move.w  d6,d0
    andi.w  #1,d0
    beq.s   loc_218B0
    cmpi.b  #2,$38(a1)
    bne.s   loc_218B0
    bclr    #5,$2A(a0)
    bsr.s   sub_218CE
    btst    #6,$2A(a0)
    beq.s   loc_2185C
    lea     (Player_2).w,a1
    cmpi.b  #2,$38(a1)
    bne.s   loc_2185C
    ...
Notice that everything but the Knuckles character ID check is gone, and that an identical check is now also performed on player 2's SST. Perhaps at one point, Knuckles-only walls were considered for Competition mode.

When the wall does break, an interesting piece of code runs over at loc_218EE. It does another character ID check for Knuckles (paranoid much?), and then checks if the double jump flag at $2F(a1) is set to 1.
loc_218EE:
    move.w  $18(a1),$1C(a1)
    bclr    #5,$2A(a1)
    cmpi.b  #2,$38(a1)
    bne.s   loc_21928
    cmpi.b  #1,$2F(a1)
    bne.s   loc_21928
    move.b  #2,$2F(a1)
    move.b  #$21,$20(a1)
    bclr    #0,$2A(a1)
    tst.w   $18(a1)
    bpl.s   loc_21928
    bset    #0,$2A(a1)

loc_21928:
    ...
If both of those check out, then it means the wall was broken by a gliding Knuckles, and the object forces Knuckles out of the gliding state by setting the double jump flag to 2 and Knuckles' animation to $21, which is the falling-from-gliding animation. This is interesting because regular breakable walls don't have this bit of code, so Knuckles will happily glide right through a bunch of them.


It also turns out the rocky walls from Angel Island Zone and Lava Reef Zone are actually a different object, which does contain this code, so the fact that it's missing from the standard breakable wall object is possibly an oversight.

1 comment: