Top Boundary Fix - RetroKoH/S1Fixed GitHub Wiki

(Original guide by Mercury)
Source: ReadySonic
Commit: a03cb4b

Sonic is supposed to die when he falls below the bottom screen boundary of a level. This is what's referred to as a "bottomless pit"! The same isn't supposed to happen, however, if Sonic crosses the top boundary, and it normally doesn't. It does happen in one circumstance, however: when Sonic is thrown back by being hit. This is most noticeable on the highest routes in Star Light Zone if you jump onto the top of one of the Orbinaut badniks. As Sonic flies upward, he'll go offscreen and then immediately die! This is obviously unwanted behavior. Let's fix this!

In _incObj\Sonic (part 2).asm, at Sonic_HurtStop, remove this code:

Sonic_HurtStop:
-	move.w	(v_limitbtm2).w,d0
-	addi.w	#$E0,d0
-	cmp.w	obY(a0),d0
-	bcs.w	KillSonic

The code we just removed was an extra (unnecessary) check to see if his Y position is greater than the bottom boundary. The problem is, the check incorrectly interprets a negative Y position as greater, because the bcs instruction treats values such as $FF as 255 (unsigned) instead of -1 (signed). This could be fixed by changing the "bcs" to "blt", but that would be redundant, as Sonic_LevelBound already does the proper check and runs during Sonic's "hurt" routine anyway.

NOTE: In s1disasm, there is a FixBugs addition that is inserted here in order to fix a different boundary bug, but S1Fixed removes this entirely in favor of fixing that bug in a different manner. More on that bug fix can be found once that page is finished.