don't click here

How do I add Double Jump in the Sonic 1 GitHub Disassembly?

Discussion in 'Engineering & Reverse Engineering' started by Mr. Funny Suitcase, Mar 30, 2025.

  1. I really want to add this new move to my upcoming ROM Hack, but how do I do it?

    I really want to add it just like Sonic Erazor or Shadow in Sonic Megamix.
     
  2. Kilo

    Kilo

    The Scatterbrained Hacker Tech Member
    1,328
    1,265
    93
    Canada
    Sonic 1 Source Code Recration
    It'd be helpful to know what disassembly you're using but I'll just do both Hivebrain and GitHub to make things easier.

    First of all, we need to make it possible to make Sonic jump in midair. Right now, Sonic's jump function is only ever called when he's on the ground.
    We can do this by going Obj01_MdJump2 (Hivebrain) or Sonic_MdJump2 (GitHub) in the main .asm file. Right after the label insert a subroutine call to Sonic's jump function:
    Code (Text):
    1.         bsr.w    Sonic_Jump
    If you're wondering why we don't apply this change to Obj01_MdJump/Sonic_MdJump, that's because it's only ran when Sonic is in the air, but not in a ball. Unless you want Sonic to be able to jump after walking off a ledge or bouncing off a spring.

    Now we have the issue that Sonic can jump in the air infinitely! So the next step is to limit our jumps. Let's go to Sonic_Jump, which if you're using GitHub is in it's own file, _incObj/Sonic Jump.asm. Right after the label we need to do a check if the player has double jumped. We'll use the jump flag variable as a counter so we don't have to use any extra RAM.
    Code (Text):
    1. ; Hivebrain
    2.         cmpi.b    #2,$3C(a0)    ; Has the player jumped twice?
    3.         bge.w    locret_1348E    ; If so, or more, then exit.
    4.  
    5. ; GitHub
    6.         cmpi.b    #2,objoff_3C(a0)    ; Has the player jumped twice?
    7.         bge.w    locret_1348E    ; If so, or more, then exit.
    Build again, and we can still jump infinitely! This is because the jump flag is still working like a flag instead of a counter. So let's go down a couple lines until we see
    Code (Text):
    1. ; Hivebrain
    2.         move.b    #1,$3C(a0)
    3.  
    4. ; GitHub
    5.         move.b    #1,objoff_3C(a0)
    To make it count up, we simply change the move to an add.

    Now this is an extra step, but right now double jumping doesn't feel great because horizontal controls are locked, as if you roll jumped. As the roll jump lock just checks if you're in a ball state before jumping, which would be the case when you do a double jump. We can quickly fix this by going to Sonic_ChgJumpDir (Hivebrain) or _incObj/Sonic JumpDirection.asm and remove these lines:
    Code (Text):
    1. ; Hivebrain
    2.         btst    #4,$22(a0)
    3.         bne.s    Obj01_ResetScr2
    4.  
    5. ; GitHub
    6.         btst    #4,obStatus(a0)
    7.         bne.s    Obj01_ResetScr2
    And it should feel better.
     
  3. MarkeyJester

    MarkeyJester

    You smash your heart against the rocks Resident Jester
    2,306
    558
    93
    Japan
    upload_2025-3-30_17-36-41.png
    :)
     
  4. Kilo

    Kilo

    The Scatterbrained Hacker Tech Member
    1,328
    1,265
    93
    Canada
    Sonic 1 Source Code Recration
    Oops. Well consider it a two-for-one for anyone who also wants a double jump in their Hivebrain based hack.
     
  5. MarkeyJester

    MarkeyJester

    You smash your heart against the rocks Resident Jester
    2,306
    558
    93
    Japan
    Hey no worries, solid answer by the way, much simpler than I was going to suggest~