don't click here

Basic Questions & Answers thread

Discussion in 'Engineering & Reverse Engineering' started by Tweaker, May 29, 2008.

  1. Sik

    Sik

    Sik is pronounced as "seek", not as "sick". Tech Member
    6,718
    1
    0
    being an asshole =P
    SMI = Set if minus
    SNE = Set if Not Equal


    These instructions set the contents of a register to all 1s if the condition is met. Also works with practically any condition branches support too (for always setting, use ST, which is Set if True).

    PEA = Push Effective Address

    I don't remember exactly how it worked but it's something used by compilers so you don't want to mess with it...
     
  2. PEA just pushes an effective address onto the stack. And a couple of other things to note about the Scc instructions is that they're always byte-sized, and they set the target address to false (all 0s) in case the condition isn't met (and set it to true (all 1s) if it is met, as Sik said above).
     
  3. Selbi

    Selbi

    The Euphonic Mess Member
    1,501
    52
    28
    Northern Germany
    Sonic ERaZor
    So it works basically like this?
    Code (ASM):
    1.         moveq   #5,d0       ; set d0 to $5
    2.         cmpi.b  #6,d0       ; is d0 $6?
    3.         sne d0      ; if not, set d0 to $0
    4.         cmpi.b  #0,d0       ; is d0 $0?
    5.         seq d0      ; if yes, set d0 to $1
    (Ignore the stupidity in this code, it's just so I can understand it better.)
     
  4. It sets d0 to $FF, not 1 (by all 1s I was referring to the individual bits). Basically, to give another example:
    Code (ASM):
    1.     cmp.b   #3,d5   ; is d5 3?
    2.     seq d1  ; if it is, the lowest byte of d1 becomes $FF, otherwise it becomes $0
    3.     cmp.w   #10,($FFFFFE20).w
    4.     scc d2  ;   ; if Sonic has >= 10 rings the lowest byte of d2 becomes $FF, otherwise it becomes 0
    5.     st  ($FFFFFFB0).w   ; always set a random address, same as move.b #$FF,($FFFFFFB0).w
    6.     sf  ($FFFFFFB1).w   ; always clear a random address, same as clr.b ($FFFFFFB1).w
     
  5. Hanoch

    Hanoch

    Also known as TheKnock, Birashot Member
    491
    0
    0
    Israel
    everything
    If I remember correctly it always sets to $FF
     
  6. Selbi

    Selbi

    The Euphonic Mess Member
    1,501
    52
    28
    Northern Germany
    Sonic ERaZor
    Ah got it (I wasn't sure about that 1s being bytes or bits).

    Just one last question:
    Is there any technical difference when using those commands, like it's faster, takes less space, etc?
     
  7. There's no speed difference as long as the operand isn't a data register, but st X takes up two bytes less than move.b #$FF,X. sf X and clr.b X take up the same amount of space, which is two bytes less than move.b #0,X.
     
  8. So, I'm porting Knuckles into a clean S2 Rom as an extra character, and I'm having a few troubles along the way:


    First of all, If I am standing on an object (such as a bridge) and I jump, and land on it, I sink 4 pixels into the floor.


    Second is gliding into a spring—the glide continues instead of getting canceled out as they're supposed to.


    Lastly, If I glide and then land on an object, instead of landing into a walk like in S2K/S3K, the falling stays for a bit, and then I am standing on the object.


    These are all flags not getting cleared I believe, but I cannot for the life in me find anything to fix these. Can anyone help? Thanks in advance ;)



    Anything to do with loc_3F976? I'm at a loss :(
     
  9. Selbi

    Selbi

    The Euphonic Mess Member
    1,501
    52
    28
    Northern Germany
    Sonic ERaZor
    I doubt that, but I can tell you, the flag when the player is on an object, but shouldn't fall (when he's standing on something like a bridge) is bit 3 in $22(aX). The absolute RAM address to player one is $FFFFB022.
    I would try to find the correct locations and use one of these 2 lines:
    Code (ASM):
    1.     bset    #3,($FFFFB022).w    ; set standing on object flag
    2.     bclr    #3,($FFFFB022).w    ; clear standing on object flag
     
  10. Sonic's object doesn't set the on object flag, except in a few areas. For anyone who's ported knuckles—Shobiz, Rika, SOTI, how did you get around this?
     
  11. I've never ported Knuckles actually, but the spring problem should just be a matter of locating the part inside the spring's code which sets the player's flags and adding a clr.b $21(a1) and clr.b $1F(a1) there as well (assuming it keeps the player object in a1). No idea about the other problems though.
     
  12. Vinchenz

    Vinchenz

    Yo! Hustle! Hustle! Member
    Anyone know where to edit the level... err, vector? In Sonic 1. I'm not sure what they would be called in ASM...

    But anyway, I want to change it so that the levels are two acts instead of three and I also want to add two extra zones. Where in the code can I do this? (There's probably multiple places where I have to chance it, though...)
     
  13. Selbi

    Selbi

    The Euphonic Mess Member
    1,501
    52
    28
    Northern Germany
    Sonic ERaZor
    You can edit the Level Order (misc\lvl_ord.bin). The format is a little hard to understand, but it goes basically like this (converted into ASM, but you should also get the point in a hex editor):
    Code (ASM):
    1.         dc.w    $0001, $0002    ; 1. GHZ 2 and 3 (1 is being loaded by default)
    2.         dc.w    $0200, $0000    ; 1. Go to MZ and play its first level
    3.         dc.w    $0101, $0102    ; 4. LZ 2 and 3
    4.         dc.w    $0300, $0502    ; 4. Go to SLZ and play its first level (also, set up FZ, somehow...)
    5.         dc.w    $0201, $0202    ; 2. MZ 2 and 3
    6.         dc.w    $0400, $0000    ; 2. Go to SYZ and play its first level
    7.         dc.w    $0301, $0302    ; 5. SLZ 2 and 3
    8.         dc.w    $0500, $0000    ; 5. Go to SBZ and play its first level
    9.         dc.w    $0401, $0402    ; 3. SYZ 2 and 3
    10.         dc.w    $0100, $0000    ; 3. Go to LZ and play its first level
    11.         dc.w    $0501, $0103    ; 6. SBZ 2 and LZ 4 (SBZ 3)
    12.         dc.w    $0000, $0000    ; 6. either null or play LZ, dunno...
    For the new zones, you can at least add one with this: http://info.sonicretro.org/SCHG_How-to:Add...zone_in_Sonic_1
     
  14. MainMemory

    MainMemory

    Kate the Wolf Tech Member
    4,744
    338
    63
    SonLVL
    Since asking #techies has been unhelpful, I'll have to ask here: Does anybody know where the the part of the Wing Fortress Zone cutscene that pushes the A button is? Right now he boosts off the platform and dies, so I need to change it to press the C button. fixed.
     
  15. GT Koopa

    GT Koopa

    Member
    2,021
    18
    18
    Elgin, IL
    Flicky Turncoat DX, T.L.W.S. Vs M.G.W.
    I didn't want to go public with this, but I have a problem.


    I asked MarkeyJester on this, but he couldn't find anything wrong with the code.


    We ruled out that it is a ram location problem (he suggested trying FFF7)

    That is a problem with my coding, I get the right idea of what to do and it seems plausible but doesn't work most of the time, thanks to some slight error that I overlooked. Fixing that slight error makes the cogs go, so to speak. I believe it is the same problem here.
     
  16. Selbi

    Selbi

    The Euphonic Mess Member
    1,501
    52
    28
    Northern Germany
    Sonic ERaZor
    May I ask again what you really wanted? You want a monitor, that gives the player an emerald when he finishes a level? You didn't want the emerald to be added just when the monitor got opened? You can do this:
    Code (ASM):
    1. Obj2E_ChkEggman:
    2.         cmpi.b  #1,d0           ; does monitor contain Eggman (or emerald in this case)?
    3.         bne.s   Obj2E_ChkSonic      ; if not, branch
    4.         move.b  #$A4,d0         ; set sound $A4 by default
    5.         tst.b   ($FFFFFF90).w       ; was flag already set?
    6.         bne.s   Obj2E_PlaySnd_Emerald   ; if yes, branch
    7.         addq.b  #1,($FFFFFE57).w    ; add one emerald
    8.         move.b  #$BF,d0         ; play sound $BF instead
    9.         move.b  #1,($FFFFFF90).w    ; make sure this code doesn't get used again
    10.  
    11. Obj2E_PlaySnd_Emerald:
    12.         jmp PlaySound       ; play whatever sound is in d0
    Just clear $FFFFFF90 when the next level starts (Obj3A_NextLevel).
     
  17. E-122-Psi

    E-122-Psi

    Member
    2,470
    612
    93
    Sorry if this is a dumb question (I've only edited Sonic 1 before) is there coding in the Sonic 2 dissassembly to edit the animations similar to S1's anim folder?
     
  18. Selbi

    Selbi

    The Euphonic Mess Member
    1,501
    52
    28
    Northern Germany
    Sonic ERaZor
    There is, it's just not splitted into seperate files, but right in s2.asm. Sonic's animation script is for example at SonicAniData.
     
  19. GT Koopa

    GT Koopa

    Member
    2,021
    18
    18
    Elgin, IL
    Flicky Turncoat DX, T.L.W.S. Vs M.G.W.
    I did a hybrid of your code and mine and it works! Thank you.

    Code (Text):
    1. Obj2E_ChkEggman:    ; XREF: Obj2E_Move
    2.         addq.b    #2,$24(a0)
    3.         move.w    #29,$1E(a0)
    4.         move.b    $1C(a0),d0
    5.         cmpi.b    #1,d0; does monitor contain Eggman?
    6.         bne.s    Obj2E_ChkSonic
    7.         cmpi.w    #50,($FFFFFE20).w; do you have    at least 50 rings?
    8.         bcc.s    Obj2E_Emerald; if yes, branch
    9.         move.b    #$A4,($FFFFF00A).w
    10.         rts    ; Eggman monitor does nothing
    11.    
    12. Obj2E_Emerald:    
    13.         move.b    #$A4,d0    ; set sound $A4 by default
    14.         tst.b    ($FFFFFF90).w; was flag already set?
    15.         bne.s    Obj2E_PlaySnd_Emerald; if yes, branch
    16.         addq.b    #1,($FFFFFE57).w; add one emerald
    17.         move.b    #$BF,d0    ; play sound $BF instead
    18.         move.b    #1,($FFFFFF90).w; make sure this code doesn't get used again
    19.        
    20.         Obj2E_PlaySnd_Emerald:
    21.         jmp    PlaySound; play whatever sound is in d0
    Code (Text):
    1. Obj3A_NextLevel:    ; XREF: Obj3A_Index
    2.         clr.b    ($FFFFFF90).w; emerald clear
    3.         move.b    ($FFFFFE10).w,d0
    4.         andi.w    #7,d0
    5.         lsl.w    #3,d0
    6.         move.b    ($FFFFFE11).w,d1
    7.         andi.w    #3,d1
    8.         add.w    d1,d1
    9.         add.w    d1,d0
    10.         move.w    LevelOrder(pc,d0.w),d0; load level from level order array
    11.         move.w    d0,($FFFFFE10).w; set level number
    12.         tst.w    d0
    13.         bne.s    Obj3A_ChkSS
    14.         move.b    #0,($FFFFF600).w; set game mode to level (00)
    15. ;fish
    16.  
    17.        
    18.         bra.s    Obj3A_Display2
     
  20. Vinchenz

    Vinchenz

    Yo! Hustle! Hustle! Member
    Ehh... thanks for trying to help, but this is too much of a hassle for me after all. I think I'll just stick to creating engines from scratch, ones that I can read. :/