Get the button press!

Discussion in 'Discussion and Q&A Archive' started by GrandMasterGalvatron, Mar 10, 2008.

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

    GrandMasterGalvatron Let's get Legendary Member

    Joined:
    Aug 14, 2007
    Messages:
    53
    Location:
    Hampton, Virginia
    Right, so if you're using ASM and you want to check button presses, you move $FFFFF603 or $FFFFF605 to d0. (In Sonic 1 that is) That's about all I really get at this point.


    What I do know is one of those checks for pressed buttons and one checks for held buttons. IIRC, to check for pressed buttons you have to use hex values, and you have to use decimal for the other.


    The thing is, I'm completely lost as to what values is that button. I just know that B is both $10 and #4, and I'm not really sure about the others.


    So I would like to know the both the decimal and hex values for each of the buttons. Whether you up and post it, or post a link is fine by me.
     
    Last edited by a moderator: Mar 10, 2008
  2. shobiz

    shobiz Well-Known Member Member

    Joined:
    Aug 11, 2007
    Messages:
    198
    Location:
    Karachi, Pakistan
    I think you're pretty confused. In Sonic 2, $F602 is used for buttons being held and $F603 is used for buttons being pressed newly this frame. Both these variables are bitfields, with each bit representing one button:



    Code:
    7 6 5 4 3 2 1 0
    
    S A C B R L D U
    Now there are two main ways to find out the value of a particular button - ANDing or BTSTing. A btst does what the name suggests - it tests a bit and sets the Z flag if it's equal to 0. In a btst, you supply the bit location of the button, so if for example you wanted to check if B was being held, you could do





    Code:
    btst #4, ($FFFFF602).w
    
    bne.s SomeRoutineWhenBIsHeld
    (you could transfer it to a register if you want, but it's not necessary)



    ANDing, on the other hand, does a bitwise AND operation, and actually modifies the variable being ANDed, so it's generally used with data registers. For an AND, you need to supply the actual value for the button. As an example, if C was being pressed, $F603 would look like 00100000. In hex, this is $20, so you'd do something like:





    Code:
    move.b ($FFFFF603).w, d0
    
    and.b #$20, d0
    
    bne.s SomeRoutineWhenCIsPressed
    The values for each button are:



    Code:
    $80 - Start
    
    $40 - A
    
    $20 - C
    
    $10 - B
    
    $08 - R
    
    $04 - L
    
    $02 - D
    
    $01 - U
    You can add values together for multiple buttons. Basically, if you're using an AND, you use these, if you're using a btst you just use the bit position of the button:





    Code:
    7 - Start
    
    6 - A
    
    5 - C
    
    4 - B
    
    3 - R
    
    2 - L
    
    1 - D
    
    0 - U
    This is for Sonic 2, but I'm pretty sure it's the same in Sonic 1.
     
    Last edited by a moderator: Mar 10, 2008
  3. GrandMasterGalvatron

    GrandMasterGalvatron Let's get Legendary Member

    Joined:
    Aug 14, 2007
    Messages:
    53
    Location:
    Hampton, Virginia
    Thanks a ton. I guess it shows I got lost by the wayside there.
     
  4. redhotsonic

    redhotsonic Also known as RHS Member

    Joined:
    Aug 10, 2007
    Messages:
    2,969
    Location:
    England
    I never knew the difference between btst and and. Thanks for sharing that.
     
  5. midgetonebeta

    midgetonebeta Newcomer Trialist

    Joined:
    Oct 27, 2008
    Messages:
    4
    B) Shobiz B) May I have your Permition to use this in a tutorial i want to write one based on Adding Custom Attacks Like Peel out Dash But On ButtonPress. I want to make this tutorial as detailed as possible.


    Just need your Reply. :p
     
  6. shobiz

    shobiz Well-Known Member Member

    Joined:
    Aug 11, 2007
    Messages:
    198
    Location:
    Karachi, Pakistan
    Sure, no problem.
     
  7. DeoxysKyogre

    DeoxysKyogre No idea what to put here .-. Member

    Joined:
    Jan 31, 2009
    Messages:
    298
    sorry for huge bump but someone has to say it: this topic is worth to be pinned or something!
     
Thread Status:
Not open for further replies.