don't click here

Weird code in SBZ transporter tubes

Discussion in 'Engineering & Reverse Engineering' started by Hayate, Jan 7, 2007.

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

    Hayate

    Tech Member
    Okay, so I was busy editing the SBZ transporter object (object 72) so that it would move Sonic based on the chunk he was in, rather than predefined paths. And I noticed this:

    Code (Text):
    1. cmpi.b #7,$28(a0)
    2. bne.s loc_1670E
    3. cmpi.w #50,($FFFFFE20).w
    4. bcs.s locret_1675C
    I don't know what bcs does, but it looks like this code is meant to, for transporter number 7, only allow Sonic to use it if he has 50 rings. I've never seen this while playing the original Sonic 1, so can anyone explain this?
     
  2. Tweaker

    Tweaker

    Banned
    12,387
    2
    0
    If you have 50 rings at a certain transporter in the level, it takes you to an alternate path with a bunch of goodies. It's pretty nifty! :P
     
  3. drx

    drx

    mfw Researcher
    2,254
    350
    63
    :rolleyes:
    Woah. This is very interesting.
     
  4. Agent ME

    Agent ME

    Void where prohibited Member
    26
    0
    0
    Doesn't this mean that the "locret_1675C:" doesn't do anything? (From later in assembly:)
    Code (Text):
    1. locret_1675C:
    2.         rts
     
  5. Ultima

    Ultima

    Games Publisher Tech Member
    2,398
    1
    18
    London, England
    Publishing mobile games!
    Nope, it exits the subroutine. All locrets do that =P

    And bcs is branch if carry set - it branches if the carry flag is set after an operation.
     
  6. never knew that, ill have to check it out next time im on that game...
     
  7. SMTP

    SMTP

    Tech Member
    Yea, pretty much just a shortcut for the level.. :P
     
  8. MK

    MK

    Hacker Oldbie
    310
    0
    0
    New England, USA
    Secret :o o:
    I learned about this a while ago, it's quite a nice little feature. Now that I know where it's located, I can edit it :P thanks
     
  9. Hayate

    Hayate

    Tech Member
    Isn't that exactly the same as blt?
     
  10. drx

    drx

    mfw Researcher
    2,254
    350
    63
    :rolleyes:
    blt is signed, and checks different CCR bits
    bcs is unsigned.
     
  11. Agent ME

    Agent ME

    Void where prohibited Member
    26
    0
    0
    So how exactly does the code work? I'm new to asm and I'm trying to figure out how a lot of the stuff works. - If the "locret_1675C" is branched to, but it immediately rts's and exits - how does the game know to do anything special?
     
  12. Quickman

    Quickman

    be attitude for gains Tech Member
    5,595
    18
    18
    :x
    omg porjcet
    That code checks to see if the necessary conditions are NOT met - if they ARE met then the code immediately after that code is run and the transporter goes to the part with the hidden goodies.
     
  13. Hayate

    Hayate

    Tech Member
    Rts will return to the instruction after the last jsr or bsr that was called. So if you bcs to a label with rts in it, then you aren't returning to after the bcs.

    Ah, so that's the difference, I'll remember that. So I assume bcc is "branch if carry clear" (ie. the unsigned bge)?
     
  14. Upthorn

    Upthorn

    TAS Tech Member
    239
    0
    0
    That is correct. By the way, I suggest you google for "m68000 reference manual" and grab a pdf of the motorola m68000 programmer's reference manual. It should assist you with similar ASM questions in the future.
     
  15. Hayate

    Hayate

    Tech Member
    Well, I found the guide from a link on Sonic Retro a few hours ago. Sorry bout that. You won't get any more ASM questions from me. :P
     
  16. drx

    drx

    mfw Researcher
    2,254
    350
    63
    :rolleyes:
    Actually RTS will pull the the PC from the stack, but in most cases what you said is true (unless someone fiddles with the stack, heh).

    Ie. sometimes you can see lea 4(sp),sp, or something similar. Basically this makes RTS come back to PC 2 jsr/bsr's away. Heh =P
     
  17. Quickman

    Quickman

    be attitude for gains Tech Member
    5,595
    18
    18
    :x
    omg porjcet
    There's also addq.b #4,sp which disables the next subroutine call. =P
     
  18. drx

    drx

    mfw Researcher
    2,254
    350
    63
    :rolleyes:
    lea 4(aX),aX does the same as addq.l #4,aX

    also, using addq.b for SP is sick!
     
  19. Upthorn

    Upthorn

    TAS Tech Member
    239
    0
    0
    No need to apologize. I was just suggesting that that'll give a faster response than S2beta does most times.
     
Thread Status:
Not open for further replies.