How to add a way to not die by level boundaries when exiting Debug Mode. (Sonic 1 Hivebrain)

Discussion in 'Tutorials' started by Delta, Dec 11, 2022.

  1. Delta

    Delta Newcomer Trialist

    Joined:
    Nov 27, 2022
    Messages:
    6
    Do you hate the fact that when you die, you cant enter debug mode? Well this tutorial is for you!
    Reminder: this is for the Hivebrain 2007 dissasembly, the one i'm using is ASM68K.

    Firstly, go to KillSonic:
    There, you will find this whole batch of code.

    Code:
    ; ---------------------------------------------------------------------------
    ; Subroutine to    kill Sonic
    ; ---------------------------------------------------------------------------
    
    ; ||||||||||||||| S U B    R O U T    I N E |||||||||||||||||||||||||||||||||||||||
    
    
    KillSonic:
            tst.w    ($FFFFFE08).w    ; is debug mode    active?
            bne.s    Kill_NoDeath    ; if yes, branch
            move.b    #0,($FFFFFE2D).w ; remove invincibility
            move.b    #6,$24(a0)
            bsr.w    Sonic_ResetOnFloor
            bset    #1,$22(a0)
            move.w    #-$700,$12(a0)
            move.w    #0,$10(a0)
            move.w    #0,$14(a0)
            move.w    $C(a0),$38(a0)
            move.b    #$18,$1C(a0)
            bset    #7,2(a0)
            move.w    #$A3,d0        ; play normal death sound
            cmpi.b    #$36,(a2)    ; check    if you were killed by spikes
            bne.s    Kill_Sound
            move.w    #$A6,d0        ; play spikes death sound
    
    Kill_Sound:
            jsr    (PlaySound_Special).l
    
    Kill_NoDeath:
            moveq    #-1,d0
            rts
    ; End of function KillSonic
    Now that we got here, lets make the new label.
    Under Kill_NoDeath:, and just right before the ; End of function, put whatever subroutine name you want. For this tutorial, i put Sonic_AvoidDeath.

    Code:
    Sonic_AvoidDeath:
    Congrats! you made your code! now to make it work.

    After the KillSonic label, add this:
    Code:
            tst.w    ($FFFFFFFA).w    ;  DE: is debug mode on?
            bne.s    Sonic_AvoidDeath    ; DE: if active, branch
    Once you try to build, Uh oh! something went wrong!

    You will see that sonic doesn't die, but he goes offscreen. This might be intentional for you, but for this tutorial, it is not.

    Go to the Sonic_AvoidDeath: label, and add however way you want Sonic to repel back up in the air. If you are still confused, keep reading.
    Under the label, add this
    Code:
           move.w    #-$700,$12(a0)
           move.b    #$10,$1C(a0)
    Good job! you found out how to avoid sonic dying when exiting debug mode! For those users who want a sound effect, add this under the code mentioned above:
    Code:
            move.w    #$CC,d0
            jsr    (PlaySound_Special).l ;    play spring sound
     
    Last edited: Dec 11, 2022
    EddyTF and Nik Pi like this.