How to Fix Sonic 1's Debug Mode

Discussion in 'Tutorials' started by Kilo, Jun 20, 2019.

  1. Kilo

    Kilo Foxy Fren Exiled

    Joined:
    Oct 9, 2017
    Messages:
    391
    Location:
    A warm and lovely place~
    If you've screwed around with Sonic 1's debug mode, you probably have seen a few issues. We'll fix them.

    Stored Velocity
    If you were to run, and then enter placement mode, you would notice that Sonic keeps his momentum after exiting. Which personally, is kinda annoying. The reason why it occurs is that the speed is never cleared when you enter or exit placement mode. The solution is quite easy.
    Go to the "Debug_Main" routine and simply insert this:
    Code:
            clr.w   ($FFFFD000+$14).w ; Clear Inertia
            clr.w   ($FFFFD000+$12).w ; Clear X/Y Speed
            clr.w   ($FFFFD000+$10).w ; Clear X/Y Speed
    
    Below does not function correctly and can cause odd behavior with ring and monitor objects, please use Leo's fix in the replies.
    Ring and Monitor Fix
    If you ever spammed rings or monitors (And let's face it, who hasn't) you would know that you can't place anymore after you collect the initial set.
    First, go to the "Obj26_Main" routine. And below
    Code:
            move.b    $23(a0),d0
    Insert
    Code:
             bra.s    Obj26_NotBroken
    This fixes the issue with the monitors, just needs to be applied to rings.
    Go to "Obj25_Main" and under
    Code:
            move.b    (a2),d4
    Insert:
    Code:
             cmp.b    #1,d0
             beq.s    Obj25_RemState
             clr    d4
             move.b    d4,(a2)
    
    Obj25_RemState:

    And there we go! 2 issues in debug mode are now fixed. Feel free to reply with your own fixes, suggestions and criticisms.
     
    Last edited: Jun 14, 2020
    EMK-20218, Narcologer and ProjectFM like this.
  2. ADudeCalledLeo

    ADudeCalledLeo I'll make a ROM hack one of these days... Member

    Joined:
    Oct 21, 2017
    Messages:
    13
    Location:
    Null Space
    These fixes can also be applied to Sonic 2, by the way (excluding the rings, which are already fixed).

    Also, "clr" takes a size. Those "clr"s for resetting the speed values should be "clr.w"s, and the "clr d4" should be "clr.l d4"... but "moveq #0,d4" is preferred in this scenario.

    Also also, those fixes should be done in the debug mode placing routine rather than in the object itself. In "Debug_MakeItem", after the "bne.s", add:
    Code:
            clr.b    ($FFFFFC02).w    ; clear 1st entry in object state table
    Code:
            lea    ($FFFFFC00).w,a2    ; load object state table
            moveq    #0,d0            ; point at 1st entry in table (objects placed in debug mode always use this entry)
            bclr    #7,2(a2,d0.w)    ; clear bit 7 of state (makes objects delete themselves)
            bclr    #0,2(a2,d0.w)    ; clear bit 0 of state (used by monitors to determine if they were broken or not)
    (This can probably be optimized to remove the "lea" entirely. I dunno how indexing works, though.)
     
    Last edited: Jun 24, 2019
    AsuharaMoon and Kilo like this.
  3. ADudeCalledLeo

    ADudeCalledLeo I'll make a ROM hack one of these days... Member

    Joined:
    Oct 21, 2017
    Messages:
    13
    Location:
    Null Space
    Here's how to make the debug HUD work like it does in Sonic & Knuckles (AKA it only appears when debug mode is active), converted from my tutorial on how to improve S2's debug mode:

    Go to "HudUpdate", and replace:
    Code:
            tst.w    ($FFFFFFFA).w    ; is debug mode on?
    With:
    Code:
            tst.w    ($FFFFFE08).w    ; is debug mode active?
    Then, go to "Debug_Exit", and after "move.w d0,($FFFFFE08).w", add:
    Code:
            bsr.w    Hud_Base
            move.b    #1,($FFFFFE1D).w
            move.b    #1,($FFFFFE1F).w
    This reloads the HUD when exiting debug mode.
     
    Kilo likes this.
  4. Kilo

    Kilo Foxy Fren Exiled

    Joined:
    Oct 9, 2017
    Messages:
    391
    Location:
    A warm and lovely place~
    Hey! This is some pretty cool stuff. Thanks for the additions, and feedback!
    Edit: Although your fix for the ring and monitors is how it should be done, attempting to expand the debug list to include subtypes of objects won't work.
     
    Last edited: Jun 20, 2019
  5. Speems

    Speems Well-Known Member Member

    Joined:
    Mar 14, 2017
    Messages:
    83
    Location:
    Rochester Hills, MI
    Hate to bump a nearly one year old thread, but inserting the ring debug fix text in my Hivebrain disassembly just refused to let the rom work. The monitor fix and S&K display thing work, but not the ring fix. That just makes the rom refuse to start and even crashes the emulator when doing the power off command.