Selbi's little questions

Discussion in 'Discussion and Q&A Archive' started by Selbi, Mar 25, 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
    EDIT: It seems like I have a question every day. So instead of bumping this forum with thousands of question threads I'm using this one now.


    I have this:



    SomeRoutine:
    move.w ($FFFFFFF1).w,d0 ; move adress 1 to d0


    move.w ($FFFFFFF2).w,d1 ; move adress 2 to d1


    cmp.w d0,d1.w ; compare d0 and d1


    beq.s SomeRoutine_IfEqual ; branch if equal



    My question is, can I reduce the first 3 lines to 1? I've tried this:



    SomeRoutine:
    cmp.w ($FFFFFFF1).w,($FFFFFFF2).w ; compare the 2 adresses


    beq.s SomeRoutine_IfEqual ; branch if equal



    But then I get the error Illegal adressing mode (for the cmp). I looked through my ASM and found the same for move:



    move.w ($FFFFFFF3).w,($FFFFFFF4).w ; move adress 1 to 2



    And this works. So, how can I so the same for the cmp? If you know, how to reduce it to 2 lines, don't tell me, because I just want 1 singel line.


    Hopefully someone knows how to do this. :p
     
    Last edited by a moderator: Mar 28, 2009
  2. Malevolence

    Malevolence Well-Known Member Member

    Joined:
    Jul 29, 2008
    Messages:
    97
    move.w ($FFFFFFF1).w,d0 ; move adress 1 to d0


    move.w ($FFFFFFF2).w,d1 ; move adress 2 to d1


    cmp.w d0,d1.w ; compare d0 and d1


    beq.s SomeRoutine_IfEqual ; branch if equal



    Alrighty, first of all, you're trying to move FFF1 and FFF2 when you move the address to d0, you're specifying word length, not byte (move.w, you probably want move.b), which won't work. Accessing odd RAM addresses as words doesn't work (maybe on some emulators, not real hardware). Secondly, you would be able to do it with:



    move.b ($FFFFFFF1).w,d0
    cmp.b ($FFFFFFF2).w,d0


    beq.s SomeRoutine_IfEqual



    I don't believe there's anything less than that that would work.
     
    Last edited by a moderator: Mar 25, 2009
  3. Selbi

    Selbi The Euphonic Mess Member

    Joined:
    Jul 20, 2008
    Messages:
    2,429
    Location:
    Northern Germany
    There's nothing shorter? That sucks. However, thanks to the information. But what about .b and .w? Where is the problem when I use .w (I have problems with all these .x things... even with .s for branch commands)?
     
    Last edited by a moderator: Mar 25, 2009
  4. Malevolence

    Malevolence Well-Known Member Member

    Joined:
    Jul 29, 2008
    Messages:
    97
    For not branching commands, .b and .w tells the size. For example, $FFFFFFF1 should be just .b, because if you use .w it will us $FFFFFFF1 and $FFFFFFF2 because those two bytes are equal to a word. If you used .l you'd be using $FFFFFFF1 all the way to $FFFFFFF5 (each thing of ram is worth one byte, a long word is worth four bytes). Real hardware isn't able to take an odd address (F1 is abbreviating the RAM) such as F1 and use it as a word. Words and long words have to be an even number.
     
  5. Selbi

    Selbi The Euphonic Mess Member

    Joined:
    Jul 20, 2008
    Messages:
    2,429
    Location:
    Northern Germany
    Aha ok. But what is this .s doing? I know, when I have it in a branch, I can't jump very far away, usually only up to 5 labels. Does it mean "Short" or something like this?
     
  6. Spanner

    Spanner The Tool Member

    Joined:
    Aug 9, 2007
    Messages:
    2,570
    Yes, it means short.


    .l means long and .w means word I think.
     
  7. Selbi

    Selbi The Euphonic Mess Member

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


    Is it better when I use:



    clr.b ($FFFFFFFF).w ; clear something



    Or:



    move.b #0,($FFFFFFFF).w ; move o to something



    Technically seen the same thing is happening, but what's better to use?
     
    Last edited by a moderator: Mar 28, 2009
  8. Tweaker

    Tweaker OI! MIRON! Member

    Joined:
    Aug 10, 2007
    Messages:
    324
    I personally suggest clr.b, myself; if I remember correctly, it saves you a byte or two in-ROM compared to moving #0 to any given address.


    If you're working with registers, I suggest using moveq instead--it's not only smaller, but it's quite a bit faster as well.
     
  9. Selbi

    Selbi The Euphonic Mess Member

    Joined:
    Jul 20, 2008
    Messages:
    2,429
    Location:
    Northern Germany
    Ah Ok. About moveq, I personally don't like this command... exspecially because I can't have more than $8... but Ok.


    Another question: How can I check if Sonic is on the ground and is not moving?
     
  10. Tweaker

    Tweaker OI! MIRON! Member

    Joined:
    Aug 10, 2007
    Messages:
    324
    After checking $22(a0) to make sure that Sonic is standing on the ground (in other words, not in the air), do a check against his inertia value to make sure that it's $0; if it's not, then don't execute the move.


    Something like this should do:



    CheckShit:
    btst #1,$22(a0) ; check if Sonic is in the air


    bne.s GetOutFaggot ; if he is, get the fuck out


    tst.l $10(a0) ; check X and Y speed


    bne.s GetOutFaggot ; if Sonic is moving, then get out


    tst.w $14(a0) ; check inertia


    bne.s GetOutFaggot ; if Sonic has potential to move, then get out


    DoShit:


    put whatever here


    GetOutFaggot:


    rts



    You may be able to get away without checking inertia; I'm not entirely positive. I'm also not sure if you use tst with a long; if you can't, then change it to cmp.l or something.
     
  11. Selbi

    Selbi The Euphonic Mess Member

    Joined:
    Jul 20, 2008
    Messages:
    2,429
    Location:
    Northern Germany
    This was the greatest example in the world, and for 90% it works! Thanks Tweaker. Hope you can help me for my next problem, which is currently not there....
     
  12. Selbi

    Selbi The Euphonic Mess Member

    Joined:
    Jul 20, 2008
    Messages:
    2,429
    Location:
    Northern Germany
    Ok, another question: How can I check if Sonic has running animation? This is my example:



    XCode:
    *unknown code* ; does sonic has the running animation?


    bne.s CheckStuff ; if not, branch


    move.b #1,($FFFFFFFF).w ; set CheckStuff flag


    CheckStuff:


    tst.b ($FFFFFFFF).w ; was XCode flag set?


    beq.s Exit ; if not, branch


    move.b #2,($FFFFFFFF).w ; if yes, do this


    Exit:


    rts



    I guess it's a bad example, but that's no problem, since I just want to know the check for running animation. I don't want a velocity check, because in my code somewhere above this check, my velocity got replaced.
     
    Last edited by a moderator: Mar 30, 2009
  13. Hanoch

    Hanoch Well-Known Member Member

    Joined:
    Aug 3, 2008
    Messages:
    312
    Location:
    Israel
    cmpi.b #$1,$1C(a0) is the running animation (since 1 is the running animation) but you could always check for the speed of sonic ($600 while he is running).
     
  14. Selbi

    Selbi The Euphonic Mess Member

    Joined:
    Jul 20, 2008
    Messages:
    2,429
    Location:
    Northern Germany
    cmpi.b #1,$1C(a0) doesn't work correctly. He's always branching, because this isn't the correct code. So I will try it with checking Sonic's speed.
     
  15. Selbi

    Selbi The Euphonic Mess Member

    Joined:
    Jul 20, 2008
    Messages:
    2,429
    Location:
    Northern Germany
    Ok, another question: Where is the code for setting the position for the Live Counter? Or better, where is the code for the live counter?
     
  16. Selbi

    Selbi The Euphonic Mess Member

    Joined:
    Jul 20, 2008
    Messages:
    2,429
    Location:
    Northern Germany
    Ok, I found the code for the numbers. But, where is the code for the Sonic Icon? I searched for it and found Nem_Lives, but there's nothing, which jumps to this line... where is the code for loading the Sonic Live Icon?
     
  17. Hanoch

    Hanoch Well-Known Member Member

    Joined:
    Aug 3, 2008
    Messages:
    312
    Location:
    Israel
    It loads from ArtLoadCues (Pattern load cues.asm)
     
  18. Selbi

    Selbi The Euphonic Mess Member

    Joined:
    Jul 20, 2008
    Messages:
    2,429
    Location:
    Northern Germany
    Time to bump my topic.


    However, this is a really small question, but I want to know it: What are the branch commands bpl, bhi and bmi doing? I'm sure they are listed somewhere on Retro, but I can't find them. So I ask along here.


    Qjimbo edit: Before anyone else makes the same mistake, this has been answered on page 2...
     
    Last edited by a moderator: May 26, 2009
  19. nineko

    nineko I am the Holy Cat Member

    Joined:
    Mar 24, 2008
    Messages:
    1,902
    Location:
    italy
  20. Qjimbo

    Qjimbo Well-Known Member Member

    Joined:
    Feb 27, 2008
    Messages:
    850
    Location:
    Vancouver, BC
    Last edited by a moderator: May 25, 2009
Thread Status:
Not open for further replies.