Can I get help Backporting Super Sonic to Sonic 1?

Discussion in 'Discussion and Q&A Archive' started by DarkLeach, Jul 31, 2011.

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

    DarkLeach Well-Known Member Member

    Joined:
    Jul 3, 2011
    Messages:
    193
    Location:
    In the middle of desert heat
    I was trying to Backport Super Sonic to Super Sonic, I was first trying to make a code to do it all by myself and start from there (Looking for the same routines else where such as Sonic 2 but I can't seem to get the hang of it) Can I please get some help? Here is my code but it doesn't work... I want to know why. (Note: The code is basic and I just wanted to see if I could do it, it will be changed later to look more professional once I learn how.



    Code:
    
    ; ||||||||||||||| S U B R O U T I N E |||||||||||||||||||||||||||||||||||||||
    
    ; SUBROUTINE TO MAKE SONIC GO SUPER
    
    Sonic_SuperSonic:
    
    ;tst.b #1,(FFFFFF00).w ; is Sonic already Super?
    
    ;bne.s Cancel_SuperTransformation  ; if yes, branch
    
    cmpi.b  #2,$1C(a0) ; is "jumping" animation displayed?
    
    bne.s Cancel_SuperTransformation
    
    cmpi.b #6,($FFFFFE57).w ; do you have all 6 emeralds?
    
    bne.s Cancel_SuperTransformation  ; if not, branch
    
    cmpi.w #50,($FFFFFE20).w ; do you have at least 50 rings?
    
    bcs.s Cancel_SuperTransformation  ; if not, branch
    
    bsr.w Sonic_GoSuper
    
     
    
    Sonic_GoSuper:
    
    move.b #1,($FFFFFE2D).w ; make Sonic invincible
    
    move.b #1,($FFFFFE2E).w ; speed up the BG music
    
    move.w #$C00,($FFFFF760).w ; change Sonic's top speed
    
    move.w #$18,($FFFFF762).w
    
    move.w #$80,($FFFFF764).w
    
    move.w #$E2,d0
    
    jmp (PlaySound).l ; Speed up the music
    
    cmpi.w #1,($FFFFFE20).w ; do you have at least 1 ring?
    
    bcs.s Sonic_SuperEnd ; If not branch
    
    subq.w #1,($FFFFFE20).w ; subtract 1 from remaining rings
    
     
    
    Sonic_SuperEnd:
    
    move.b #0,($FFFFFE2D).w ; make Sonic not invincible
    
    move.b #0,($FFFFFE2E).w ; slowdown the BG music
    
    bsr.w Cancel_SuperTransformation
    
     
    
    Cancel_SuperTransformation:
    
      rts
    
    ; End of function Sonic_SuperSonic
    
    ; ==========================================================================
    
    
    [/CODE]
     
    Last edited by a moderator: Jul 31, 2011
  2. rika_chou

    rika_chou Adopt Member

    Joined:
    Aug 11, 2007
    Messages:
    689
    I'm no good at this stuff, but it looks like your "Sonic_GoSuper:" routine leads directly to the "Sonic_SuperEnd:" routine.


    As in, as soon as it would give Sonic more speed and stuff, it would also revert it back to normal at the same time.


    Again, I'm no good at this stuff so I am likley wrong.
     
  3. redhotsonic

    redhotsonic Also known as RHS Member

    Joined:
    Aug 10, 2007
    Messages:
    2,969
    Location:
    England
    rika_chou is practically right.



    Sonic_GoSuper:
    move.b #1,($FFFFFE2D).w ; make Sonic invincible


    move.b #1,($FFFFFE2E).w ; speed up the BG music


    move.w #$C00,($FFFFF760).w ; change Sonic's top speed


    move.w #$18,($FFFFF762).w


    move.w #$80,($FFFFF764).w


    move.w #$E2,d0


    jmp (PlaySound).l ; Speed up the music


    cmpi.w #1,($FFFFFE20).w ; do you have at least 1 ring?


    bcs.s Sonic_SuperEnd ; If not branch


    subq.w #1,($FFFFFE20).w ; subtract 1 from remaining rings



    At the end of this, there is no rts, or anything for it to branch, so it immediately goes onto the next bit, which is this:



    Sonic_SuperEnd:
    move.b #0,($FFFFFE2D).w ; make Sonic not invincible


    move.b #0,($FFFFFE2E).w ; slowdown the BG music


    bsr.w Cancel_SuperTransformation


    Cancel_SuperTransformation:


    rts


    ; End of function Sonic_SuperSonic



    Because of this, it will immediately kill of SuperSonic routine because you told it to. So, in the "Sonic_GoSuper:" label, after:



    subq.w #1,($FFFFFE20).w ; subtract 1 from remaining rings



    add an rts and see if that works.


    Plus, change this bit:



    cmpi.w #1,($FFFFFE20).w ; do you have at least 1 ring?
    bcs.s Sonic_SuperEnd ; If not branch



    to this:



    tst.w ($FFFFFE20).w ; do you have 0 ring?
    beq.s Sonic_SuperEnd ; If so, branch



    That way, when Sonic has no rings left, he will branch to kill SuperSonic, otherwise, it won't branch (and that's what you want).


    EDIT: You also don't want



    bsr.w Cancel_SuperTransformation



    under the "Sonic_SuperEnd:" label, seeming as it's going to go to that bit next anyway. So I would comment that line out.


    So here is what you're looking at:



    |||||||||||||| S U B R O U T I N E |||||||||||||||||||||||||||||||||||||||
    ; SUBROUTINE TO MAKE SONIC GO SUPER


    Sonic_SuperSonic:


    ;tst.b #1,(FFFFFF00).w ; is Sonic already Super?


    ;bne.s Cancel_SuperTransformation ; if yes, branch


    cmpi.b #2,$1C(a0) ; is "jumping" animation displayed?


    bne.s Cancel_SuperTransformation


    cmpi.b #6,($FFFFFE57).w ; do you have all 6 emeralds?


    bne.s Cancel_SuperTransformation ; if not, branch


    cmpi.w #50,($FFFFFE20).w ; do you have at least 50 rings?


    bcs.s Cancel_SuperTransformation ; if not, branch


    bsr.w Sonic_GoSuper


    Sonic_GoSuper:


    move.b #1,($FFFFFE2D).w ; make Sonic invincible


    move.b #1,($FFFFFE2E).w ; speed up the BG music


    move.w #$C00,($FFFFF760).w ; change Sonic's top speed


    move.w #$18,($FFFFF762).w


    move.w #$80,($FFFFF764).w


    move.w #$E2,d0


    jmp (PlaySound).l ; Speed up the music


    tst.w ($FFFFFE20).w ; do you have 0 ring?


    beq.s Sonic_SuperEnd ; If so, branch


    subq.w #1,($FFFFFE20).w ; subtract 1 from remaining rings


    rts


    Sonic_SuperEnd:


    move.b #0,($FFFFFE2D).w ; make Sonic not invincible


    move.b #0,($FFFFFE2E).w ; slowdown the BG music


    ;bsr.w Cancel_SuperTransformation ;commented out, seeming as the next label is what it’s subroutining to


    Cancel_SuperTransformation:


    rts


    ; End of function Sonic_SuperSonic


    ; ==========================================================================
     
    Last edited by a moderator: Jul 31, 2011
  4. MarkeyJester

    MarkeyJester ♡ ! Member

    Joined:
    Jun 27, 2009
    Messages:
    2,867
    What would be even more helpful is if you change:


    jmp (PlaySound).l


    to


    jsr (PlaySound).l


    As jmp doesn't store it's location to the stack for returning.


    EDIT: removing additional shit that the board added on (this updated IPB is really starting to get on my nerves now for it's stupid "Trying to predict what I want" crap)
     
    Last edited by a moderator: Jul 31, 2011
  5. redhotsonic

    redhotsonic Also known as RHS Member

    Joined:
    Aug 10, 2007
    Messages:
    2,969
    Location:
    England

    Well spotted. Didn't notice he put a jmp instead of jsr.


    And, what predictive typing?
     
  6. DarkLeach

    DarkLeach Well-Known Member Member

    Joined:
    Jul 3, 2011
    Messages:
    193
    Location:
    In the middle of desert heat
    I tried to add the new code that redhotsonic fixed (with the jmp to jsr fix that MarkeyJester said) and Now I get a ton of build errors, something about Op-code not recognized, or something to that effect. I attached a video with me running the build process and showing what happens.

    Sonic Build Error.zip
     

    Attached Files:

    Last edited by a moderator: Jul 31, 2011
  7. vladikcomper

    vladikcomper Well-Known Member Member

    Joined:
    Dec 2, 2009
    Messages:
    415
    Just add tabs or spaces before each instruction and the errors will be gone.


    EDIT:



    bsr.w Sonic_GoSuper

    Sonic_GoSuper:



    Like redhotsonic said about 'bsr.w Cancel_SuperTransformation', remove a BSR here as well. You don't need to branch label in such a way, if you do, the code you jump to will work twice.
     
    Last edited by a moderator: Jul 31, 2011
  8. DarkLeach

    DarkLeach Well-Known Member Member

    Joined:
    Jul 3, 2011
    Messages:
    193
    Location:
    In the middle of desert heat
    It's still giving me "Error : Op-code not recognised"



    Code:
    
    ; SUBROUTINE TO MAKE SONIC GO SUPER
    
    Sonic_SuperSonic:
    
    ;tst.b  #1,(FFFFFF00).w ; is Sonic already Super?
    
    ;bne.s  Cancel_SuperTransformation ; if yes, branch
    
    cmpi.b  #2,$1C(a0) ; is "jumping" animation displayed?
    
    bne.s  Cancel_SuperTransformation
    
    cmpi.b  #6,($FFFFFE57).w ; do you have all 6 emeralds?
    
    bne.s  Cancel_SuperTransformation ; if not, branch
    
    cmpi.w  #50,($FFFFFE20).w ; do you have at least 50 rings?
    
    bcs.s  Cancel_SuperTransformation ; if not, branch
    
    bsr.w  Sonic_GoSuper
    
     
    
    Sonic_GoSuper:
    
    move.b  #1,($FFFFFE2D).w ; make Sonic invincible ;<---- "Error: Op-code not recognised"
    
    move.b  #1,($FFFFFE2E).w ; speed up the BG music  ;<---- "Error: Op-code not recognised"
    
    move.w  #$C00,($FFFFF760).w ; change Sonic's top speed  ;<---- "Error: Op-code not recognised"
    
    move.w  #$18,($FFFFF762).w ;<---- "Error: Op-code not recognised"
    
    move.w  #$80,($FFFFF764).w ;<---- "Error: Op-code not recognised"
    
    move.w  #$E2,d0 ;<---- "Error: Op-code not recognised"
    
    jsr  (PlaySound).l ; Speed up the music  ;<---- "Error: Op-code not recognised"
    
    tst.w  ($FFFFFE20).w ; do you have 0 ring? ; <---- "Error: Op-code not recognised"
    
    beq.s  Sonic_SuperEnd ; If so, branch  ;<---- "Error: Op-code not recognised"
    
    subq.w  #1,($FFFFFE20).w ; subtract 1 from remaining rings  ;<---- "Error: Op-code not recognised"
    
    rts
    
     
    
    Sonic_SuperEnd:
    
    move.b  #0,($FFFFFE2D).w ; make Sonic not invincible ;<---- "Error: Op-code not recognised"
    
    move.b  #0,($FFFFFE2E).w ; slowdown the BG music ;<---- "Error: Op-code not recognised"
    
    ;bsr.w Cancel_SuperTransformation ;commented out, seeming as the next label is what it&#8217;s subroutining to
    
     
    
    Cancel_SuperTransformation:
    
    rts  ;<---- "Label 'rts' multiply defined"
    
    ; End of function Sonic_SuperSonic
    
    
    [/CODE]
     
  9. Selbi

    Selbi The Euphonic Mess Member

    Joined:
    Jul 20, 2008
    Messages:
    2,429
    Location:
    Northern Germany
    There must be at least one space in front of every command. Otherwise the assemblier might think it's a label, instead of a command.
     
  10. vladikcomper

    vladikcomper Well-Known Member Member

    Joined:
    Dec 2, 2009
    Messages:
    415
    Yeah, that's what I was meaning in my post above.


    DarkLeach7, in the code you show, you still have 'bsr.w Sonic_GoSuper' there and no spaces before the commands. What have you changed?
     
  11. DarkLeach

    DarkLeach Well-Known Member Member

    Joined:
    Jul 3, 2011
    Messages:
    193
    Location:
    In the middle of desert heat
    There was no build error now thank you Selbi but It's not functioning at all, do I have the wrong test or did I put the whole Subroutine in the wrong spot? Should I choose something other than:



    Code:
    
      cmpi.b  #2,$1C(a0) ; is "jumping" animation displayed?
    
      bne.s  Cancel_SuperTransformation
    
    
    I tried to find a check to see if Sonic was at the peak of his jump but I couldn't find anything that resembled that, I found it in Sonic 2, but It didn't work and I don't know how to convert it. So here's where I put it.



    Code:
    
    ; End of function Sonic_MoveRight
    
     
    
    ;===================================================================
    
    ; SUBROUTINE TO MAKE SONIC GO SUPER
    
    Sonic_SuperSonic:
    
    ;tst.b  #1,(FFFFFF00).w ; is Sonic already Super?
    
    ;bne.s  Cancel_SuperTransformation ; if yes, branch
    
    cmpi.b  #2,$1C(a0) ; is "jumping" animation displayed?
    
    bne.s  Cancel_SuperTransformation
    
    cmpi.b  #6,($FFFFFE57).w ; do you have all 6 emeralds?
    
    bne.s  Cancel_SuperTransformation ; if not, branch
    
    cmpi.w  #50,($FFFFFE20).w ; do you have at least 50 rings?
    
    bcs.s  Cancel_SuperTransformation ; if not, branch
    
    bsr.w  Sonic_GoSuper
    
     
    
    Sonic_GoSuper:
    
    move.b  #1,($FFFFFE2D).w ; make Sonic invincible
    
    move.b  #1,($FFFFFE2E).w ; speed up the BG music
    
    move.w  #$C00,($FFFFF760).w ; change Sonic's top speed
    
    move.w  #$18,($FFFFF762).w
    
    move.w  #$80,($FFFFF764).w
    
    move.w  #$E2,d0
    
    jsr  (PlaySound).l ; Speed up the music
    
    tst.w  ($FFFFFE20).w ; do you have 0 ring?
    
    beq.s  Sonic_SuperEnd ; If so, branch
    
    subq.w  #1,($FFFFFE20).w ; subtract 1 from remaining rings
    
    rts
    
     
    
    Sonic_SuperEnd:
    
    move.b  #0,($FFFFFE2D).w ; make Sonic not invincible
    
    move.b  #0,($FFFFFE2E).w ; slowdown the BG music
    
    ;bsr.w Cancel_SuperTransformation ;commented out, seeming as the next label is what it&#8217;s subroutining to
    
     
    
    Cancel_SuperTransformation:
    
    rts
    
    ; End of function Sonic_SuperSonic
    
    ; ==========================================================================
    
    ; ---------------------------------------------------------------------------
    
    ; Subroutine to change Sonic's speed as he rolls
    
    ; ---------------------------------------------------------------------------
    
    

    vladikcomper I didn't change anything I just copied it over from your post and it didn't work. Now I'm confused.

    [/CODE]
     
  12. Animemaster

    Animemaster Lets get to work! Member

    Joined:
    Mar 20, 2009
    Messages:
    1,229
    Location:
    UK
     
    Last edited by a moderator: Jul 31, 2011
  13. vladikcomper

    vladikcomper Well-Known Member Member

    Joined:
    Dec 2, 2009
    Messages:
    415
    I think you didn't understand me.


    In that post, I just quoted your old code and tried to explain what's wrong in it. You didn't have to copy that code, it's the same, it's yours. Just remove or comment out a 'bsr.w Sonic_GoSuper' line. The branch in that place is incorrect and pointless. Of course, it will not cause any compilation errors, but it may add few bugs in game.


    ADDED:

    $10(a0) is X-velocity


    $12(a0) is Y-velocity


    When Sonic moves upwards, its Y-velocity is negative. Therefore, when he falls, the speed is positive.


    On the peak of Sonic jump, the negative Y-velocity reaches zero and goes past it, so Sonic starts to fall. If you need to test for the peak of the jump, check if $12(a0) is near to zero.


    Let's take the value $100 for example and say, if Y-velocity is more than -$100, but less than $100, it's the peak of jump.



    move.w $12(a0),d0 ; d0 -> Y-vel
    bpl.s @NoNeg ; if Y-vel >= 0, branch


    neg.w d0 ; d0 -> Abs(Y-vel)


    @NoNeg:


    cmpi.w #$100,d0 ; is Abs(Y-vel) < $100?


    bhi.s @Return ; if not, branch


    ; Sonic is on the peak of the jump!


    ; <your code here>


    @Return:


    rts



    If this won't fit, you can change value $100 to something else for best results.
     
    Last edited by a moderator: Jul 31, 2011
  14. DarkLeach

    DarkLeach Well-Known Member Member

    Joined:
    Jul 3, 2011
    Messages:
    193
    Location:
    In the middle of desert heat
    Animemaster, You mean this?



    Code:
    
    tst.b y_vel(a0)  ; is Sonic exactly at the height of his jump?
    
    beq.s Sonic_CheckGoSuper ; if yes, test for turning into Super Sonic
    
    rts
    
    

    How do I change it to work with Sonic 1's Code?


    vladikcomper now that you mention it, yeah I have to remove those because otherwise Sonic would be turning Super Twice at once or it would go to he same routine twice, don't know how that would work out with the game.

    [/CODE]
     
  15. DarkLeach

    DarkLeach Well-Known Member Member

    Joined:
    Jul 3, 2011
    Messages:
    193
    Location:
    In the middle of desert heat
    My bad I posted my post before I saw your edit, but where is that code in Sonic 2?
     
  16. vladikcomper

    vladikcomper Well-Known Member Member

    Joined:
    Dec 2, 2009
    Messages:
    415
    If you mean the code to test peak of jump, you have already found it =P


    This one from you previous post:



    tst.b y_vel(a0) ; is Sonic exactly at the height of his jump?
    beq.s Sonic_CheckGoSuper ; if yes, test for turning into Super Sonic


    rts



    Believe or not, it does almost the same thing as I did. The code from my previous post was written by me, it wasn't taken from Sonic 2, because I was too lazy to check its disassembly. By the way, you may find a similar code in many places, it's the best way to check value range from -X to X.


    But well, the code from Sonic 2 is smarter and better. In my code I forgot to take into account how exactly your new Sonic ability will be performed, so it is not suitable for you case =P


    The code from Sonic 2 checks if the high byte of Y-velocity is zero. For example, the hi-byte for $0400 is $04, for $0180 is $01, for $00FF is $00. The high byte is zero for values from $0000 to $00FF, in case of velocity, these are quite little values. The branch will work as soon as Sonic starts to fall. That's what you need.


    To port this code to Sonic 1, just replace "y_vel(a0)" with "$12(a0)".
     
  17. DarkLeach

    DarkLeach Well-Known Member Member

    Joined:
    Jul 3, 2011
    Messages:
    193
    Location:
    In the middle of desert heat
    Thank You vladikcomper! The basic physics of my Super Sonic are working! I'll add some to it more later! Anyway though, why is it starting my code when I'm on the ground? As soon as I get 50 Rings, my code starts. But not when I'm in the air, If I get the 50th ring in the air my code starts as well , but I want to make it so he has to jump to activate it. At least I know my code partially works. But the rings don't decrease which leads me to believe I did the labels wrong (tst.b , subq.w ,etc.) could I get some help with that? I could never understand those completely...
     
    Last edited by a moderator: Jul 31, 2011
  18. redhotsonic

    redhotsonic Also known as RHS Member

    Joined:
    Aug 10, 2007
    Messages:
    2,969
    Location:
    England
    You may still have the code in the wrong place. Look at Sonic 2 and see where it's located for a guideline.
     
  19. Animemaster

    Animemaster Lets get to work! Member

    Joined:
    Mar 20, 2009
    Messages:
    1,229
    Location:
    UK
    Make sure your code is under the "Sonic_JumpHeight" routine. And make sure you've put the check for the peak of his jump in the correct place also. Like Redhotsonic said, compare between sonic 1 and 2.
     
    Last edited by a moderator: Aug 1, 2011
  20. Crash

    Crash Well-Known Member Member

    Joined:
    Jul 15, 2010
    Messages:
    302
    Location:
    Australia
    Aaaaargh Jesus FUCK porting the Super Sonic mappings/animations to sonic 1 is the most tedious shit :) Surely there's an easy way to do this :)
     
Thread Status:
Not open for further replies.