Prevent DLEs in Special Stage and Title Screen - RetroKoH/S1Fixed GitHub Wiki
(Original guide by Mercury)
Source: ReadySonic
Commit: 6f4d139
Per Mercury:
In Sonic 1, the routine that handles the multi-layer background effects (_inc\DeformLayers.asm and _inc\DeformLayers) also calls the routine that handles the "Dynamic Level Events", or "DLEs" (found in _inc\DynamicLevelEvents.asm). The problem is, some screen modes (the Title Screen and the Special Stage) require the background effects, but don't need the DLE system.
This doesn't affect anything in the original game (either Sonic Team got lucky or they worked around it), but if you want to make modifications for your hack, such as showing a different level behind the Title Screen or even something as simple as changing the size of a level, the game can behave erratically. Basically, the Title Screen or Special Stage might do something strange like try to load a Boss object, or alter the water level. To fix this, we simply need to exit the DLE routine if we're on the Title Screen or in a Special Stage.
In _inc\DynamicLevelEvents.asm, at the start of DynamicLevelEvents, add these lines right after the label:
DynamicLevelEvents:
+ cmpi.b #id_Title,(v_gamemode).w ; exit if on the Title Screen
+ beq.s DLE_NoChg
+ cmpi.b #id_Special,(v_gamemode).w ; exit if in a Special Stage
+ beq.s DLE_NoChg
moveq #0,d0
move.b (v_zone).w,d0
add.w d0,d0
move.w DLE_Index(pc,d0.w),d0
jsr DLE_Index(pc,d0.w) ; run level-specific events
Conventional wisdom would suggest simply NOT calling DynamicLevelEvents when in these screen modes, but that's not an option. Both screen modes need to call DeformLayers, and that subroutine calls for DLEs in the middle of its code. All we can really do is add these checks.