Sonic 1 Jumpdash

Discussion in 'Tutorials Archive' started by Selbi, Mar 22, 2009.

Thread Status:
Not open for further replies.
  1. Selbi

    Selbi The Euphonic Mess Member

    Joined:
    Jul 20, 2008
    Messages:
    2,429
    Location:
    Northern Germany
    Jumpdash for Sonic 1




    I removed the Jumpdash from SSRG a long time ago. However, now it's back. It was hosted on Sofia for a while (and it's still hosted there though. LINK) EDIT: Due spambots not anymore.


    If you want to read the story, click me!


    ========Starts here=======


    Before you start read this: This code was made by me (Selbi). Everyone may use it, modify it etc. However, you ARE FORCED credit me when using it.


    Ok, you want the Jumpdash, but you have absolutly no ASM skils? No problem! Here I will give you my Jumpdash code, which has been updated a lot since the first release. Please don't argue about "hacks will get boring", because I'm pissed off with such stuff. However, here it is:


    1. Open your sonic1.asm and go to Obj01_MdJump2:. This is the Routine for Sonic's move methods when he is in the Air. Because we want to branch to our (not yet existing) Jumpdash code, add this line after the label:



    bsr.w Sonic_JumpDash



    2. Next go to Sonic_Roll:. After this Routine we have to place the Jumpdash code (don't ask why, just do it). I know it's just copy/paste, but most of you would rip off the code anyway, so I don't need a step-by-step guide only (scroll down a bit for a better explained split of that code).


    The Jumpdash code was 3 times rewritten and millions of times overwritten. But if you still find something, you think I can do better (code, comments etc.) please mention it here!


    Here it is:



    ; ---------------------------------------------------------------------------
    ; Subroutine to perform a Jumpdash


    ; ---------------------------------------------------------------------------


    Sonic_JumpDash:


    move.b ($FFFFF603).w,d0 ; is ABC pressed? (part 1)


    andi.b #$70,d0 ; is ABC pressed? (part 2)


    beq.w JD_End ; if not, branch


    tst.b ($FFFFFFEB).w ; was jumpdash flag set?


    bne.w JD_End ; if yes, branch


    move.b #1,($FFFFFFEB).w ; if not, set jumpdash flag


    move.b #$BC,d0 ; set jumpdash sound


    jsr (PlaySound_Special).l ; play jumpdash sound


    bclr #4,$22(a0) ; clear double jump flag


    move.w #$A00,d0 ; set normal jumpdash speed


    tst.b ($FFFFFE2E).w ; do you have speed shoes?


    beq.s JD_ChkUW ; if not, branch


    move.w #$B00,d0 ; set speed shoes jumpdash speed


    JD_ChkUW:


    btst #6,$22(a0) ; is Sonic underwater?


    beq.s JD_ChkDirection ; if not, branch


    move.w #$600,d0 ; set underwater jumpdash speed


    JD_ChkDirection:


    btst #0,$22(a0) ; is sonic facing left?


    beq.s JD_Move ; if yes, branch


    neg.w d0 ; if not, negate d0 (for jumping to the right)


    JD_Move:


    move.w d0,$10(a0) ; move Sonic forward with the selected speed ($10(a0) = Sonic's X-velocity)


    clr.w $12(a0) ; clear Sonic's Y-velocity to move sonic directly down


    JD_End:


    rts ; return


    ; End of function Sonic_JumpDash



    And here with explaination for every single code block:



    ; ---------------------------------------------------------------------------
    ; Subroutine to perform a Jumpdash


    ; ---------------------------------------------------------------------------



    This is just something to make this code nicer. It's comented out, so it wouldn't make any difference, if you don't write it.



    Sonic_JumpDash:


    This is the main Label. Without this, we couldn't use the Jumpdash.


    Code:
    		move.b	($FFFFF603).w,d0	; is ABC pressed? (part 1)
    		andi.b	#$70,d0			; is ABC pressed? (part 2)
    
    
    		beq.w	JD_End			; if not, branch
    
    
    This code tests if you are pressing ABC. You don't need to know how this is actually checking (I don't know it as well). We don't need a check for being in the Air, since this is done with Obj01_MdJump2:.



    tst.b ($FFFFFFEB).w ; was jumpdash flag set?
    bne.s JD_End ; if yes, branch


    move.b #1,($FFFFFFEB).w ; if not, set jumpdash flag



    This is a very important part: Without this, you could make infinite Jumpdashes in the air.



    move.w #$BC,d0 ; set jumpdash sound
    jsr (PlaySound_Special).l ; play jumpdash sound



    This is just to play a sound. You can replace the $BC with another sound ID to play another sound.



    bclr #4,$22(a0) ; clear double jump flag


    This clears the double jump flag, which is set when you are pressing jump in the air (I guess). I haven't ever tested if it's necesary. Maybe it's just there for taking an extra line. =P


    Code:
    		move.w	#$A00,d0		; set normal jumpdash speed
    		tst.b	($FFFFFE2E).w		; do you have speed shoes?
    
    
    		beq.s	JD_ChkUW		; if not, branch
    
    
    		move.w	#$B00,d0		; set speed shoes jumpdash speed
    
    
    JD_ChkUW:
    
    
    		btst	#6,$22(a0)		; is Sonic underwater?
    
    
    		beq.s	JD_ChkDirection		; if not, branch
    
    
    		move.w	#$600,d0		; set underwater jumpdash speed
    
    
    JD_ChkDirection:
    
    
    		btst	#0,$22(a0)		; is sonic facing left?
    
    
    		beq.s	JD_Move			; if yes, branch
    
    
    		neg.w	d0			; if not, negate d0 (for jumping to the right)
    
    
    JD_Move:
    
    
    		move.w	d0,$10(a0)		; move sonic forward (X-velocity)
    
    
    $10(a0) is the X-velocity. In this huge block of coding, we are setting the jumpdash speed. We could reduce this to 4 lines, but we also want a different speed for being underwater and for having speed shoes. This code also checks in which direction you are looking (this is important. Otherwise you could just jumpdash to one side).



    clr.w $12(a0) ; clear Y-velocity to move sonic directly down


    $12(a0) is the Y-velocity. While jumping upwards you set this velocity, but when you are jumpdashing, you are going directly down. Without this line you would still move a bit upwards if you perform a jumpdash.


    Code:
    JD_End:
    		rts				; return
    
    
    ; End of function Sonic_JumpDash
    
    
    With an rts every code ends. There is nothing to say.


    3. Ok, if you looked at the code, you've maybe sawn this flag $FFFFFFEB. To create a clearing code, we need to go to the routine Sonic_ResetOnFloor:L. This is the code when Sonic touches the ground again. Add this right after the label:



    clr.b ($FFFFFFEB).w ; clear jumpdash flag



    4. Step 4 is not necesary but very highly recomended: Remove the Speedcap. Just trust me. You will see why if you compare the Jumpdash with and without Speedcap.


    Ok, now you should have a Jumpdash. It works fine, but it's a little bit lame. So you should add:


    Some Extra features


    We know, your current Jumpdash is very lame. So how about adding some extras? Here is the code for those things:


    Stop Sonic, up bouncing and Jumpdashing again after destroying an enemy or a monitor.


    1. Interested? Ok, then open your sonic1.asm. We need to branch to a specific code if you destroyed a monitor with the Jumpdash. So go to loc_1AF1E: and before locret_1AF2E: add this:



    tst.b ($FFFFFFEB).w ; was the monitor destroyed with a jumpdash?
    bne.w BounceJD ; if yes, branch



    2. Now we have to do the same for Enemies. Go to loc_1AF9C: and replace it with this:



    loc_1AF9C:
    jsr AddPoints


    move.b #$27,0(a1) ; change object to points


    move.b #0,$24(a1)


    tst.b ($FFFFFFEB).w ; was the enemy destroyed with a jumpdash?


    bne.s JSR_BounceJD ; if yes, branch


    bra.s loc_1AF9C_cont ; if not, skip


    JSR_BounceJD:


    jsr BounceJD ; jump to BounceJD


    loc_1AF9C_cont:


    tst.w $12(a0)


    bmi.s loc_1AFC2


    move.w $C(a0),d0


    cmp.w $C(a1),d0


    bcc.s loc_1AFCA


    neg.w $12(a0)


    rts



    3. And now we need to add this BounceJD: Routine (yes, it's of course not in the ASM yet). Go to loc_1AFDA: and add this Routine before it:



    ; -------------------------------------------------------------------------
    ; Subroutine to stop Sonic, bounce him up and to give him the ability to


    ; Jumpdash again when he has performed a Jumpdash


    ; -------------------------------------------------------------------------


    BounceJD:


    tst.b ($FFFFFFEB).w ; was jumpdash flag set?


    beq.s BounceJD_End ; if not, branch


    clr.b ($FFFFFFEB).w ; if yes, clear jumpdash flag (allow Sonic to jumpdash again)


    clr.w $10(a0) ; clear X-velocity (stop sonic)


    move.w #-$5F0,$12(a0) ; use -$5F0 for Y-velocity (move sonic upwards)


    btst #6,$22(a0) ; is sonic underwater?


    beq.s BounceJD_Shoes ; if not, branch


    move.w #-$320,$12(a0) ; use only -$320 for Y-velocity (move sonic upwards)


    BounceJD_Shoes:


    tst.b ($FFFFFE2E).w ; does sonic has speed shoes?


    beq.s BounceJD_End ; if not, branch


    move.w #-$620,$12(a0) ; use -$620 for Y-velocity (move sonic upwards)


    BounceJD_End:


    rts ; return


    ; End of function BounceJD



    And here with descriptions (even though it's nearly working the same as the main code):



    ; -------------------------------------------------------------------------
    ; Subroutine to stop Sonic, bounce him up and to give him the ability to


    ; Jumpdash again when he has performed a Jumpdash


    ; -------------------------------------------------------------------------



    Again, this is just there to make this routine nicer. You don't need to write it as well.



    BounceJD:


    Same as above. This is necesary.


    Code:
    		tst.b	($FFFFFFEB).w	; was jumpdash flag set?
    		beq.s	BounceJD_End	; if not, branch
    
    
    		clr.b	($FFFFFFEB).w	; if yes, clear jumpdash flag (allow Sonic to jumpdash again)
    
    
    This is necesary. Otherwise this could would be always activated when destroying an enemy or a monitor.



    clr.w $10(a0) ; clear X-velocity (stop sonic)


    This stops you from moving forward. Nothing else.


    Code:
    		move.w	#-$5F0,$12(a0)	; use -$5F0 for Y-velocity (move sonic upwards)
    		btst	#6,$22(a0)	; is sonic underwater?
    
    
    		beq.s	BounceJD_Shoes	; if not, branch
    
    
    		move.w	#-$320,$12(a0)	; use only -$320 for Y-velocity (move sonic upwards)
    
    
    BounceJD_Shoes:
    
    
    		tst.b	($FFFFFE2E).w	; does sonic has speed shoes?
    
    
    		beq.s	BounceJD_End	; if not, branch
    
    
    		move.w	#-$620,$12(a0)	; use -$620 for Y-velocity (move sonic upwards)
    
    
    Here again, we could this to 1 line (the first one), but we also want a different Y-velocity when being underwater and when having Speed shoes.



    BounceJD_End:
    rts ; return


    ; End of function BounceJD



    Word.


    After doing this, you should have a perfect Jumpdash. :)


    Give credits!


    Credits:


    Me (Selbi) for everything (Guide, Code)


    Note:


    The code also works for Sonic 2! However, you will have to modify it a bit at first. But it won't be be so hard though, I guess you can do that. =P (And if not, PM me)


    Version: v3.3 (Third rewritten Version of the original guide/code - Added the descriptions for the main code and the extra code - Did some epic fixcrap after 4 months - Overwritten since the release of v3.0: 4 times)


    Last update: 5th March 2010
     
    Last edited by a moderator: Mar 5, 2010
  2. amphobius

    amphobius spreader of the pink text Member

    Joined:
    Feb 24, 2008
    Messages:
    970
    Location:
    United Kingdom
    I must say, your ASM is improving. Keep it up!
     
  3. SonicVaan

    SonicVaan I'm a cyberpunk with a taste for guns Member

    Joined:
    Sep 12, 2008
    Messages:
    456
    Location:
    Germany, Cologne
    But somehow it makes me sad. It'll get overrated and yeah, hacks get more boring. [​IMG]
     
  4. c1owd

    c1owd Previously 'CarrascoZX0' Member

    Joined:
    Dec 13, 2008
    Messages:
    364
    My thought exactly... :)
     
  5. shadowbeasts

    shadowbeasts I'm Legend Member

    Joined:
    Jan 5, 2009
    Messages:
    286
    Location:
    Good 'ol USA.
    I'm so glad someone finally put this up.
     
  6. shadowbeasts

    shadowbeasts I'm Legend Member

    Joined:
    Jan 5, 2009
    Messages:
    286
    Location:
    Good 'ol USA.
    Sorry for the double post but does this Jumpdash guide work with the Sonic 1 (Split and Text by Hivebrain) (ASM68K) disassembly?
     
  7. Hanoch

    Hanoch Well-Known Member Member

    Joined:
    Aug 3, 2008
    Messages:
    312
    Location:
    Israel
    There are no things like ASM68K/SNASM68K limitions. Every guide works for every compiler.
     
  8. Hitaxas

    Hitaxas Retro 80's themed Paladins Twich streamer Member

    Joined:
    Aug 13, 2007
    Messages:
    167
    This topic fails. With some digging, people would find I posted a superior code for jumpdash a week or so ago.
     
  9. Hanoch

    Hanoch Well-Known Member Member

    Joined:
    Aug 3, 2008
    Messages:
    312
    Location:
    Israel
    Actually, I think the best version is mine. It just tests for double jump flag ($21, using sst rather than spending a ram byte) and if there is 1 in it, it ends. Then it will check for pressing C if I am, go to jumpdash. And then testing for double jump flag in jumpdash code (again) and then setting the x velocity, clearing the y velocity setting the flag and playing the sound. Test for left/right facing and negate the x speed. Not that difficult and doesn't take as much space as this code does. Also, put the button and flag tests at locret_134C2.
     
  10. Hitaxas

    Hitaxas Retro 80's themed Paladins Twich streamer Member

    Joined:
    Aug 13, 2007
    Messages:
    167
    Sure, but mine checks for the underwater flag, and sets the jumpdash to be slower if you are underwater, thus being more accurate.


    Edit: Removed, since the OP is making some step-by-step guide.
     
    Last edited by a moderator: Mar 28, 2009
  11. Selbi

    Selbi The Euphonic Mess Member

    Joined:
    Jul 20, 2008
    Messages:
    2,429
    Location:
    Northern Germany
    To all of you, read the Title! :D It's a Simple Jumpdash, not the super killah Jumpdash, because posting this does make hacks really boring.


    EDIT: @Hitaxas: You should remove the code.
     
    Last edited by a moderator: Mar 23, 2009
  12. amphobius

    amphobius spreader of the pink text Member

    Joined:
    Feb 24, 2008
    Messages:
    970
    Location:
    United Kingdom
    He also has that over at RH, and there's no problem at all.


    Shadowbeasts: Acknolege temporary symbols like + and @cont can only be used in ASM68k and incbin, and even are illegal commands in AS. Instead, use binclude and align 2 (Yes I do use the AS version thank you)
     
  13. Selbi

    Selbi The Euphonic Mess Member

    Joined:
    Jul 20, 2008
    Messages:
    2,429
    Location:
    Northern Germany
    @hitaxas: Do you mind it when I use your underwater code in my Jumpdash (this guide)?
     
  14. Tweaker

    Tweaker OI! MIRON! Member

    Joined:
    Aug 10, 2007
    Messages:
    324
    What? There's only one kind of jump dash--one that sends you in a direction at any given speed. How the hell can you make anything but a simple jump dash?
     
  15. Entia

    Entia FUCK Member

    Joined:
    Aug 10, 2007
    Messages:
    33
    Someone could make one that homes in on enemies too instead of just going forward- oh wait.
     
  16. Hitaxas

    Hitaxas Retro 80's themed Paladins Twich streamer Member

    Joined:
    Aug 13, 2007
    Messages:
    167
    Sure, whatever.
     
  17. Selbi

    Selbi The Euphonic Mess Member

    Joined:
    Jul 20, 2008
    Messages:
    2,429
    Location:
    Northern Germany
    Partly agreed. But what I mean is, my Jumpdash has no lower speed in water, no special sounds, no homing... it's actually the oposite of Megamix' Jumpdash. =P

    Ok, done. The code is way longer now.
     
    Last edited by a moderator: Mar 24, 2009
  18. Selbi

    Selbi The Euphonic Mess Member

    Joined:
    Jul 20, 2008
    Messages:
    2,429
    Location:
    Northern Germany
    Sorry for double post, but I added a new feature: Bouncing up and jumpdashing again after destroying an enemy or a monitor.
     
  19. Selbi

    Selbi The Euphonic Mess Member

    Joined:
    Jul 20, 2008
    Messages:
    2,429
    Location:
    Northern Germany
    Triple post, but another update: I released a Source Code. It has the lastest Version of the Jumpdash and has a few ASM things for the unused monitors. Also it has a new GHZ 1 level (just made for testing). And, the source was made as small as possible, because my upload connection sucks. However, i hope you enjoy it! :p
     
  20. c1owd

    c1owd Previously 'CarrascoZX0' Member

    Joined:
    Dec 13, 2008
    Messages:
    364
    Thats cool Selbi! But seriously... I think you shouldn't give this code out... I mean then a lot of hack will have the jumpdash and then hacks will get boring...
     
Thread Status:
Not open for further replies.