Final Zone Boss Hit Count Underflow Fix - RetroKoH/S1Fixed GitHub Wiki
(Original guide by Mercury)
Source: ReadySonic
Commit: 98c9270
Typically when you fight the Final Zone boss, you can only hit Eggman once for each time that he appears in his pillar, due to the length of his hurt frames. When landing the final hit, the pillara retract more slowly as they explode.
It's actually possible to hit Robotnik a 9th time during this exploding phase and cause an underflow glitch, requiring him to be hit 255 more times in order to be defeated! We can't have that. Let's look at why this happens and how we fix it.
Open up _incObj/85 Boss - Final.asm and find the label loc_19F50:. All we need to do is add a check like so:
loc_19F6A:
move.w d0,(v_player+obVelX).w
tst.b objoff_35(a0)
bne.s loc_19F88
+ tst.b obColProp(a0) ; has the boss been defeated?
+ beq.s loc_19F9C ; if so, don't let it be hit again.
subq.b #1,obColProp(a0)
move.b #$64,objoff_35(a0)
move.w #sfx_HitBoss,d0
jsr (PlaySound_Special).l ; play boss damage sound
The problem is that any time we hit the boss when its hurt frames (objoff_35) are zero, its "HP" (obColProp) will decrement by 1. If this value is decremented again at 0, it will loop back to $FF (255). This takes the boss out of its exploding phase and returns it to its normal behavior, pulling you back into the fight.
To fix this, we simply add a check to see if obColProp is already at 0. If it is, we simply skip decrementing its "HP", allowing the boss to finish with its exploding phase.