Making Chaos Emeralds give you abilities

Discussion in 'Tutorials Archive' started by shadowbeasts, May 10, 2009.

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

    shadowbeasts I'm Legend Member

    Joined:
    Jan 5, 2009
    Messages:
    286
    Location:
    Good 'ol USA.
    (The revised edition can be found here.) Lets say you wanted to add the double jump but you didn't want sonic to get that ability without having an chaos emerald. Instead you want sonic to get one Chaos emerald to use the double jump. Well here's how to do it. first put the double jump code in the ASM.


    The Double Jump Code:



    Sonic_DoubleJump:
    tst.w $12(a0); is Sonic moving upwards?


    beq.s endofdoublejump; if not, branch


    cmpi.b #$13,$1C(a0); is sonic using "bounce" animation?


    beq.w endofdoublejump; if yes, branch


    cmpi.b #2,$1C(a0); is Sonic rolling/jumping?


    move.b ($FFFFF605).w,d0


    andi.b #$20,d0; is C button pressed?


    beq.s endofdoublejump; if not, branch


    sub.w #$600,$12(a0); move Sonic upwards


    move.b #2,$1C(a0); use "rolling" animation


    move.b #1,$21(a0); set the double-jump flag


    endofdoublejump:


    rts



    Then in the beginning of the code put



    cmpi.b #1,($FFFFFE57).w ; does Sonic have 1 emerald?
    blt.s locret_134D2 ; if less than 1 emerald, branch



    but lets say you want sonic to get the double jump with a different number of emeralds, well then replace the 1 with the X number of emeralds you want sonic to get to use the double jump.


    I'll use the double jump code in my ASM as an example:



    Sonic_DoubleJump:
    cmpi.b #2,($FFFFFE57).w ; does Sonic have 2 emeralds?


    blt.s locret_134D2 ; if less than 2 emeralds, branch


    tst.w $12(a0); is Sonic moving upwards?


    beq.s endofdoublejump; if not, branch


    cmpi.b #$13,$1C(a0); is sonic using "bounce" animation?


    beq.w endofdoublejump; if yes, branch


    cmpi.b #2,$1C(a0); is Sonic rolling/jumping?


    move.b ($FFFFF605).w,d0


    andi.b #$20,d0; is C button pressed?


    beq.s endofdoublejump; if not, branch


    sub.w #$600,$12(a0); move Sonic upwards


    move.b #2,$1C(a0); use "rolling" animation


    move.b #1,$21(a0); set the double-jump flag


    endofdoublejump:


    rts



    just change the



    cmpi.b #1,($FFFFFE57).w ; does Sonic have 1 emerald?
    blt.s locret_134D2 ; if less than 1 emerald, branch



    to the X number of emeralds you want sonic to have to use the double jump. You also need to know is how to check if you have less than X emeralds.


    Here is an ASM file included with the double jump and my code, giving you the double jump with one emerald: sonic1_ASM_double_jump_with_one_emerald.rar
     

    Attached Files:

    Last edited by a moderator: Jan 13, 2010
  2. Selbi

    Selbi The Euphonic Mess Member

    Joined:
    Jul 20, 2008
    Messages:
    2,429
    Location:
    Northern Germany
    This Tutorial fails for 3 reasons:


    1. You failed at making proper tabs.


    2. You should look on the Tutorial a second time, before posting it. Reason:



    Sonic_DoubleJump:
    cmpi.b #2,($FFFFFE57).w ; does Sonic have 2 emeralds?


    bne.w locret_134D2 ; if less than 2 emeralds, branch



    See the problem? if not, look at the cmpi line.
    3. This is actually a No-Brainer, but it might be useful for the super new Members.


    Said this, you should redo the guide. Or if you want, I can fix some stuff. Really, it'll be better for you and the other Members. :)
     
  3. shadowbeasts

    shadowbeasts I'm Legend Member

    Joined:
    Jan 5, 2009
    Messages:
    286
    Location:
    Good 'ol USA.
    I have no idea how



    Sonic_DoubleJump:
    cmpi.b #2,($FFFFFE57).w ; does Sonic have 2 emeralds?


    bne.w locret_134D2 ; if less than 2 emeralds, branch



    is a problem or what you mean by making proper tabs. But then again this is my first post here so once I fix it up I'll ask staff to move it to No-Brainers. So for now I'm turning this back to code boxes.
     
  4. Selbi

    Selbi The Euphonic Mess Member

    Joined:
    Jul 20, 2008
    Messages:
    2,429
    Location:
    Northern Germany
    Sonic_DoubleJump:
    cmpi.b #2,($FFFFFE57).w ; does Sonic have 2 emeralds?


    bne.w locret_134D2 ; if less than 2 emeralds, branch



    These are proper tabs. In other words, make 2 Tabs before a line starts (except the label).
     
  5. Tweaker

    Tweaker OI! MIRON! Member

    Joined:
    Aug 10, 2007
    Messages:
    324
    Contrary to popular belief, tabs are not held to a strict standard that they must adhere to--you can use spaces just as well and the code will still compile. Tabs simply exist for organizational purposes, which you can either follow or not, depending on your own personal preference.


    In any case, it's nothing that a person following this tutorial can't fix with about 30 seconds of manual effort. Stop being so pedantic.
     
  6. Selbi

    Selbi The Euphonic Mess Member

    Joined:
    Jul 20, 2008
    Messages:
    2,429
    Location:
    Northern Germany
    Sure, but it looks nicer when using 2 tabs instead of a shit load of spaces. =P

    Chill down, dude. It was just some criticsm.
     
    Last edited by a moderator: May 11, 2009
  7. shadowbeasts

    shadowbeasts I'm Legend Member

    Joined:
    Jan 5, 2009
    Messages:
    286
    Location:
    Good 'ol USA.
    Ha. but seriously Tweaker chill and I made it look nicer Selbi is right about it looking nicer with two tabs first.
     
  8. Selbi

    Selbi The Euphonic Mess Member

    Joined:
    Jul 20, 2008
    Messages:
    2,429
    Location:
    Northern Germany
    To make it look even nicer, make sure, you don't have any spaces in the 2 tab area. Also, you actually have a tab between the command and the instruction. Look at this for the perfect instruction:



    Code:
    [TAB] [TAB] Command [TAB] Instruction [SPACE or TAB]; [SPACE] Comment
    Example:



    cmpi.b #1,($FFFFFFFF).w ; bla



    To everyone, who is ready this, it's better to use this way, if you want proper, nice and "good for guides" lines. =P
     
    Last edited by a moderator: May 11, 2009
  9. Tweaker

    Tweaker OI! MIRON! Member

    Joined:
    Aug 10, 2007
    Messages:
    324
    Why are people telling me to "chill," exactly? What exactly about my post implies that I'm not "chilled"? There's no need to cover up your own inadequacies by trying to make my point look extreme, you know.
     
  10. Selbi

    Selbi The Euphonic Mess Member

    Joined:
    Jul 20, 2008
    Messages:
    2,429
    Location:
    Northern Germany
    Answer:

    But if you mean, you were chilled, I take back everything I said.
     
  11. iojnekns

    iojnekns OBAMA '012!!!!1!!!!!&#33 Member

    Joined:
    Mar 27, 2009
    Messages:
    258
  12. Spanner

    Spanner The Tool Member

    Joined:
    Aug 9, 2007
    Messages:
    2,570
    Hey Selbi, I heard you like tabbing, here's something you'll like:




    ;===============================================================================


    ; Sub Routine PseudoRandomNumber


    ; [ Begin ]


    ;===============================================================================


    PseudoRandomNumber: ; Offset_0x0029AC:


    move.l ($FFFFF636).w, D1


    bne.s Offset_0x0029B8


    move.l #$2A6D365A, D1


    Offset_0x0029B8:


    move.l D1, D0


    asl.l #$02, D1


    add.l D0, D1


    asl.l #$03, D1


    add.l D0, D1


    move.w D1, D0


    swap.w D1


    add.w D1, D0


    move.w D0, D1


    swap.w D1


    move.l D1, ($FFFFF636).w


    rts


    ;===============================================================================


    ; Sub Routine PseudoRandomNumber


    ; [ End ]


    ;===============================================================================
     
    Last edited by a moderator: May 11, 2009
  13. nineko

    nineko I am the Holy Cat Member

    Joined:
    Mar 24, 2008
    Messages:
    1,902
    Location:
    italy
    I'm with Tweaker on this, everyone can tab in the way he prefers...


    I tend to respect tabbing in my soniNeko disasm, I admit that, but I almost never tab in my QB/VB programs. Sometimes I do, but I don't make a rule out of it, though.


    I agree that tabs are better than spaces, anyway.
     
  14. Irixion

    Irixion Well-Known Member Member

    Joined:
    Aug 11, 2007
    Messages:
    670
    Location:
    Ontario, Canada
    You're arguing over spaces? What has this world come to.



    Seeing that hamburger and that horse just makes it all worthwhile.


    As for the guide, it's not that much of a no-brainer (no-brainer would be how to edit a palette).
     
  15. Reverie

    Reverie Good sir, I do read that as "Derp" Member

    Joined:
    Mar 10, 2009
    Messages:
    54
    Location:
    your local coffee shop ^^
    Not bad for a first tutorial, but you may want to fix a very small problem.

    Be careful with pasting next time.


    And I also have to agree with Irixion, arguing over something like tabs and spaces is (very) immature.
     
    Last edited by a moderator: May 12, 2009
  16. shadowbeasts

    shadowbeasts I'm Legend Member

    Joined:
    Jan 5, 2009
    Messages:
    286
    Location:
    Good 'ol USA.
    Hey I've got to agree with you there I mean what's the point of tabbing? (uh don't answer that.) Also I fixed the tutorial.
     
  17. M3k

    M3k h4x Member

    Joined:
    Jul 28, 2008
    Messages:
    37
    Trying to keep on topic...



    Code:
    Sonic_DoubleJump:
    
    		cmpi.b	#2,($FFFFFE57).w&#59; does Sonic have 2 emerald?
    
    		blt.s	locret_134D2&#59; if less than 2 emerald, branch


    IIRC checks for emeralds should be .w, not .b





    Code:
    Sonic_DoubleJump:
    
    		cmpi.w	#2,($FFFFFE57).w&#59; does Sonic have 2 emerald?
    
    		blt.s	locret_134D2&#59; if less than 2 emerald, branch
     
  18. Selbi

    Selbi The Euphonic Mess Member

    Joined:
    Jul 20, 2008
    Messages:
    2,429
    Location:
    Northern Germany
    Why? There are only 6 emeralds, so why do we need a word? Or are there 65535 emeralds? :)
     
    Last edited by a moderator: Jun 19, 2009
  19. Oerg866

    Oerg866 Well-Known Member Member

    Joined:
    Aug 29, 2008
    Messages:
    299
    Location:
    Frankfurt, Germany
    Selbi's right here. You don't need a .w
     
  20. shadowbeasts

    shadowbeasts I'm Legend Member

    Joined:
    Jan 5, 2009
    Messages:
    286
    Location:
    Good 'ol USA.
    Update: I added an ASM file to the first post.
     
Thread Status:
Not open for further replies.