So I started looking into the warp that Cartina posted
here
So far, I have at least found the address that can call stage end sequence.
If you set $002C to 08, it will end the stage exactly as is done in the twitch video. Normally, the game sets this value to 8 after the last hit on the boss. (In normal play it is 4.)
In terms of what this does, 002C is used to set the jump address for Jumps from 0002, which is where jumps are executed from in a normal frame.
The first jump is always to CE30
The second Jump changes from CEE3 when 002C is 4, to CFEA when it is 8. The next step after this is D01F when it is 9.
I haven;t tracked down exactly where 002C is changed from 4 to 8 normally yet, but this seems like a good start.
EDIT: working backwards a bit, the same behavior can be obtained by changing 003B to 1 (it's normally 0)
EDIT 2: ok, here is how 003B is normally changed to 1:
$E626:BD B8 04 LDA $04B8,X @ $04C7 = #$03 A:00 X:0F Y:00 S:F4 P:nvUbdIzc
$E629:F0 2A BEQ $E655 A:03 X:0F Y:00 S:F4 P:nvUbdIzc
$E62B:86 83 STX $0083 = #$04 A:03 X:0F Y:00 S:F4 P:nvUbdIzc
$E62D:0A ASL A:03 X:0F Y:00 S:F4 P:nvUbdIzc
$E62E:85 04 STA $0004 = #$09 A:06 X:0F Y:00 S:F4 P:nvUbdIzc
$E630:20 59 E6 JSR $E659 A:06 X:0F Y:00 S:F4 P:nvUbdIzc
$E659:BD 28 05 LDA $0528,X @ $0537 = #$11 A:06 X:0F Y:00 S:F2 P:nvUbdIzc
$E65C:0A ASL A:11 X:0F Y:00 S:F2 P:nvUbdIzc
$E65D:A8 TAY A:22 X:0F Y:00 S:F2 P:nvUbdIzc
$E65E:4A LSR A:22 X:0F Y:22 S:F2 P:nvUbdIzc
$E65F:C9 10 CMP #$10 A:11 X:0F Y:22 S:F2 P:nvUbdIzc
$E661:B0 18 BCS $E67B A:11 X:0F Y:22 S:F2 P:nvUbdIzC
$E67B:98 TYA A:11 X:0F Y:22 S:F2 P:nvUbdIzC
$E67C:E9 20 SBC #$20 A:22 X:0F Y:22 S:F2 P:nvUbdIzC
$E67E:A8 TAY A:02 X:0F Y:22 S:F2 P:nvUbdIzC
$E67F:B1 80 LDA ($80),Y @ $E6CA = #$C7 A:02 X:0F Y:02 S:F2 P:nvUbdIzC
$E681:85 02 STA $0002 = #$B0 A:C7 X:0F Y:02 S:F2 P:NvUbdIzC
$E683:C8 INY A:C7 X:0F Y:02 S:F2 P:NvUbdIzC
$E684:B1 80 LDA ($80),Y @ $E6CB = #$8B A:C7 X:0F Y:03 S:F2 P:nvUbdIzC
$E686:4C 6B E6 JMP $E66B A:8B X:0F Y:03 S:F2 P:NvUbdIzC
$E66B:85 03 STA $0003 = #$D5 A:8B X:0F Y:03 S:F2 P:NvUbdIzC
$E66D:A4 04 LDY $0004 = #$06 A:8B X:0F Y:03 S:F2 P:NvUbdIzC
$E66F:B1 02 LDA ($02),Y @ $8BCD = #$40 A:8B X:0F Y:06 S:F2 P:nvUbdIzC
$E671:85 04 STA $0004 = #$06 A:40 X:0F Y:06 S:F2 P:nvUbdIzC
$E673:C8 INY A:40 X:0F Y:06 S:F2 P:nvUbdIzC
$E674:B1 02 LDA ($02),Y @ $8BCE = #$E7 A:40 X:0F Y:07 S:F2 P:nvUbdIzC
$E676:85 05 STA $0005 = #$00 A:E7 X:0F Y:07 S:F2 P:NvUbdIzC
$E678:6C 04 00 JMP ($0004) = $E740 A:E7 X:0F Y:07 S:F2 P:NvUbdIzC
$E740:20 83 C1 JSR $C183 A:E7 X:0F Y:07 S:F2 P:NvUbdIzC
04C7 is the state of the enemy in that slot. Normally, this will be the boss. His state changes to 3 after the last hit.
Now, other enemies can normally occupy that slot too. And their state also changes to 3 when they die. That is why the next check at 0537 occurs. This checks for the ID of the enemy in that slot. The boss has ID #$11, so this is the only time when the check BCS $E67B passes. After the check passes, the code continues onwards until eventually changing 003B to 1, the jump to E740 is what we need.
Now when I change 0537 to 11 when another normal enemy has just died (has state 3) the explosion sequence occurs as if the last boss died. When I just change 003B to 1 manually, no explosion sequence happens. In the twich video, there is no explosion sequence, so I believe either 003B or 00C2 is being changed independently somewhere. But, there are very few places where this occurs, not sure where to look from here for edge cases where this might happen. Very little is happening at the time of the glitch.
EDIT 3: hmmmm, there is something in the normal level that spawns with ID $#12. If I can get this object to spawn in 04C7, perhaps somehting interesting will happen? Well, looks like 12 is the bridges, so probably nothing there.
EDIT 4: So I've been playing around with object IDs and their associated state variable. So far there are several combinations that cause glitchy things (or crash the game altogether) I haven't found anything so far that looks like a bad jump to end the level though.
One neat thing I did find though is that the running backpack enemies actually have a gun. If you set their state variable to 4, they will point a gun at you, and on rare occasions will even shoot (a single bullet.) I guess this was something that was just never used.