Improving Sonic 2's debug mode

Discussion in 'Tutorials' started by ADudeCalledLeo, Jun 16, 2019.

  1. ADudeCalledLeo

    ADudeCalledLeo Newcomer Member

    Joined:
    Oct 21, 2017
    Messages:
    11
    Location:
    Null Space (Extended Edition)
    Here's a ROM with all the following changes applied: https://www.dropbox.com/s/4fgnmu32ho0nmda/Sonic 2 Improved Debug Mode.bin?dl=0

    Letting Tails use debug mode
    If you've never played Sonic 2 before, Tails cannot access debug mode when you're playing as Tails alone. Let's fix that.
    To start, go to "Obj02" and after "move.w (Camera_Max_Y_pos_now).w,(Tails_Max_Y_pos).w", add:
    Code:
        tst.w    (Debug_placement_mode).w    ; is debug mode being used?
        beq.s    +                ; if not, branch
        jmp    (DebugMode).l
    Then, go to "Obj02_Control" and after "bne.s Obj02_Control_Joypad2", add:
    Code:
        tst.w    (Debug_mode_flag).w    ; is debug cheat enabled?
        beq.s    +            ; if not, branch
        btst    #button_B,(Ctrl_1_Press).w    ; is button B pressed?
        beq.s    +            ; if not, branch
        move.w    #1,(Debug_placement_mode).w    ; change Sonic into a ring/item
        clr.b    (Control_Locked).w        ; unlock control
        rts
    +
    Then, go to "Obj02_Hurt" and after the label, add:
    Code:
        cmpi.w    #2,(Player_mode).w
        bne.s    +
        tst.w    (Debug_mode_flag).w
        beq.s    +
        btst    #button_B,(Ctrl_1_Press).w
        beq.s    +
        move.w    #1,(Debug_placement_mode).w
        clr.b    (Control_Locked).w
        rts
    +
    Do the same thing for "Obj02_Dead".
    Tails will now be able to use debug mode! However, if we enter and then exit debug mode as Tails, Tails' sprite will get glitched up.
    To fix this, go to "Debug_ExitDebugMode". First, move this (under ".notTwoPlayerMode"):
    Code:
        move.b    #$13,y_radius(a1)
    To be below "lea (MainCharacter).w,a1 ; a1=character". Then, just below the line you moved, add:
    Code:
        cmpi.w    #2,(Player_mode).w
        bne.s    .notTails
        move.b    #$F,y_radius(a1)
        move.l    #MapUnc_Tails,mappings(a1)
        move.w    #make_art_tile(ArtTile_ArtUnc_Tails,0,0),art_tile(a1)
        tst.w    (Two_player_mode).w
        beq.s    .notTwoPlayerMode
        move.w    #make_art_tile_2p(ArtTile_ArtUnc_Tails,0,0),art_tile(a1)
        bra.s    .notTwoPlayerMode
    .notTails:
    Also, at "Debug_ExitDebugMode", change:
    Code:
        beq.s   return_41CB6
    To:
    Code:
        beq.w   return_41CB6
    This prevents a "branch too large" error.
    Making debug HUD only show when placement mode is active
    In Sonic (3) & Knuckles, the debug HUD (the one with the hex digits) is only shown when debug mode is activated, and the normal HUD is restored when it's deactivated. Let's shove that into Sonic 2!
    Go to "HudUpdate". You should see this line:
    Code:
        tst.w    (Debug_mode_flag).w    ; is debug mode on?
    Change it to:
    Code:
        tst.w    (Debug_placement_mode).w    ; is debug mode active?
    The debug HUD will now be displayed only when debug mode is actively being used. However, if you enter and then exit debug mode, you'll notice that your HUD is still displaying the hex digits.
    To fix this, go to "Debug_ExitDebugMode" and just after "move.w d0,(Debug_placement_mode).w", add:
    Code:
        bsr.w    Hud_Base
        move.b    #1,(Update_HUD_rings).w
        move.b    #1,(Update_HUD_score).w
    This will reload the HUD and tell the game to update the HUD's rings and score counter (since those got reset to 0 by reloading the HUD).
    Fixing a crash bug when placing objects after dying
    Go to "BuildSprites_ObjLoop". You should be able to work out what to do based on the disassembly's comments.
     
    Last edited: Jul 8, 2019
    Aier, Painto and ProjectFM like this.
  2. ADudeCalledLeo

    ADudeCalledLeo Newcomer Member

    Joined:
    Oct 21, 2017
    Messages:
    11
    Location:
    Null Space (Extended Edition)
    Fixed an error in the code that could have caused Tails' height to not be reset properly when exiting debug mode.