don't click here

How to fix accidental deletion of scattered rings

Discussion in 'Engineering & Reverse Engineering' started by redhotsonic, Jun 3, 2012.

  1. redhotsonic

    redhotsonic

    Also known as RHS Tech Member
    1,587
    9
    18
    United Kingdom
    YouTuber
    I couldn't see a topic about this subject, or I couldn't see it on the bug list, or anywhere else, so I thought I'd post my fix here



    How to fix accidental deletion of scattered rings





    The problem



    There is a glitch within the scattered rings. Let me explain. In the scattered rings code, there is a check to see if rings have reached to the bottom of the level and if so, to delete themselves. Here is some code from Sonic 2's scattered rings object.


    Code (ASM):
    1. loc_121B8:
    2.     tst.b   (Ring_spill_anim_counter).w
    3.     beq.s   BranchTo5_DeleteObject
    4.     move.w  (Camera_Max_Y_pos_now).w,d0 ; HERE
    5.     addi.w  #$E0,d0             ; HERE
    6.     cmp.w   y_pos(a0),d0            ; HERE
    7.     bcs.s   BranchTo5_DeleteObject      ; HERE
    8.     bra.w   DisplaySprite[/ASM]
    9.  
    10.  
    11. It has this code because when rings reach to the bottom of the level, they delete themselves, so they do not spawn at the top of the level (they won't loop).  This is a good thing, as we don't want rings looping, right?
    12.  
    13. But there is an issue with levels that are y-wrapped enabled.  Easiest place to explain it is in Sonic 2's Metropolis act 2.
    14.  
    15.  
    16. [img]http://rhs.sonicresearch.org/s2_008.png[/img]
    17.  
    18. Debug is enabled to explain easier (glitch will happen with debug mode on or off), but if you go to these co-ordinates in MTZ2, you will see Asteron (starfish badnik) to the right.  Go to him and let him hurt you.
    19.  
    20.  
    21. [img]http://rhs.sonicresearch.org/s2_009.png[/img]
    22.  
    23. I've just got hurt, look at all the rings that are about to scatter.  But, the bottom line of the level is right above me.
    24.  
    25.  
    26. [img]http://rhs.sonicresearch.org/s2_010.png[/img]
    27.  
    28. Look at that!  Most of my rings have suddenly vanished!  To help, I've drawn a red line.  That's the line where if the rings reach, to delete themselves.  The rings think that that line is the bottom of the level, but because this level is y-wrapped, technically, there is no "bottom of level".  So we still want the rings to be there so we can collect them.
    29.  
    30.  
    31.  
    32.  
    33. The bug is NOT fixed in S1 or S3K either, but it is quite hard to pull the glitch off.  Generally because the only time you're passing the y-wrap in S1 and S3K, is when you're sliding down the water in LZ, or the ice in ICZ.
    34.  
    35.  
    36. But if you've editing these level layouts to cross the y-wrap quite often, the glitch may become more apparent.  And you might want to fix it.
    37.  
    38.  
    39.  
    40.  
    41.  
    42. [b][size="4"]The fix[/size][/b]
    43.  
    44.  
    45. As usual, Sonic 3 and Knuckles' fix is slightly different.
    46.  
    47.  
    48. [b]The fix I have added, I've not equated.  That way, the fix is compatible with any disassembly you are using.  I've told what disassembly for which game I'm going by, but if you're using any other disassembly, you can still use my fix.[/b]
    49.  
    50.  
    51.  
    52.  
    53. [size="3"]Sonic 1[/size]
    54.  
    55.  
    56. This can be done in [b]SVN disassembly[/b].
    57.  
    58.  
    59. Go to "@chkdel:" and you'll see this:
    60.  
    61. [code=asm]  @chkdel:
    62.         tst.b   (v_ani3_time).w
    63.         beq.s   RLoss_Delete
    64.         move.w  (v_limitbtm2).w,d0
    65.         addi.w  #$E0,d0
    66.         cmp.w   obY(a0),d0  ; has object moved below level boundary?
    67.         bcs.s   RLoss_Delete    ; if yes, branch
    68.         bra.w   DisplaySprite
    69.  

    Right after the 1st branch to "RLoss_Delete" command, insert this:

    Code (ASM):
    1.         cmpi.w  #$FF00,($FFFFF72C).w        ; is vertical wrapping enabled?
    2.         beq.w   DisplaySprite           ; if so, branch

    So, you have something like this:

    Code (ASM):
    1.     @chkdel:
    2.         tst.b   (v_ani3_time).w
    3.         beq.s   RLoss_Delete
    4.         cmpi.w  #$FF00,($FFFFF72C).w        ; is vertical wrapping enabled?
    5.         beq.w   DisplaySprite           ; if so, branch
    6.         move.w  (v_limitbtm2).w,d0
    7.         addi.w  #$E0,d0
    8.         cmp.w   obY(a0),d0  ; has object moved below level boundary?
    9.         bcs.s   RLoss_Delete    ; if yes, branch
    10.         bra.w   DisplaySprite

    Done





    Sonic 2


    This can be done in Xenowhirl's 2007 disassembly.


    Go to "loc_121B8:" and you'll see this:

    Code (ASM):
    1. loc_121B8:
    2.     tst.b   (Ring_spill_anim_counter).w
    3.     beq.s   BranchTo5_DeleteObject
    4.     move.w  (Camera_Max_Y_pos_now).w,d0
    5.     addi.w  #$E0,d0
    6.     cmp.w   y_pos(a0),d0
    7.     bcs.s   BranchTo5_DeleteObject
    8.     bra.w   DisplaySprite

    Right after the 1st branch to "BranchTo5_DeleteObject" command, insert this:

    Code (ASM):
    1.         cmpi.w  #$FF00,($FFFFEECC).w        ; is vertical wrapping enabled?
    2.         beq.w   DisplaySprite           ; if so, branch

    So, you have something like this:

    Code (ASM):
    1. loc_121B8:
    2.     tst.b   (Ring_spill_anim_counter).w
    3.     beq.s   BranchTo5_DeleteObject
    4.         cmpi.w  #$FF00,($FFFFEECC).w        ; is vertical wrapping enabled?
    5.         beq.w   DisplaySprite           ; if so, branch
    6.     move.w  (Camera_Max_Y_pos_now).w,d0
    7.     addi.w  #$E0,d0
    8.     cmp.w   y_pos(a0),d0
    9.     bcs.s   BranchTo5_DeleteObject
    10.     bra.w   DisplaySprite

    Done





    Sonic 3 and Knuckles


    This can be done in SVN disassembly.


    Go to "loc_1A79C" and you'll see this:

    Code (ASM):
    1. loc_1A79C:
    2.         tst.b   (Ring_spill_anim_counter).w
    3.         beq.s   loc_1A7E4
    4.         move.w  (Camera_max_Y_pos).w,d0
    5.         addi.w  #$E0,d0
    6.         cmp.w   $14(a0),d0
    7.         bcs.s   loc_1A7E4
    8.  

    Right after the 1st branch to "loc_1A7E4" command, insert this:

    Code (ASM):
    1.         cmpi.w  #$FF00,($FFFFEE18).w        ; is vertical wrapping enabled?
    2.         beq.w   loc_1A7B0           ; if so, branch

    So, you have something like this:

    Code (ASM):
    1. loc_1A79C:
    2.         tst.b   (Ring_spill_anim_counter).w
    3.         beq.s   loc_1A7E4
    4.         cmpi.w  #$FF00,($FFFFEE18).w        ; is vertical wrapping enabled?
    5.         beq.w   loc_1A7B0           ; if so, branch
    6.         move.w  (Camera_max_Y_pos).w,d0
    7.         addi.w  #$E0,d0
    8.         cmp.w   $14(a0),d0
    9.         bcs.s   loc_1A7E4

    Done





    The bug explained

    Basically, whenever rings fell to the bottom of the level, it deletes itself to stop it looping and coming from the top of the screen (like Sonic does on y-wrapped levels). But with levels with y-wrap enabled, the rings would still delete themselves when it reached those co-ordinates. In the pictures provided as examples, those rings reached them co-ordinates and deleted themselves, which we don't want theoretically, there is no bottom of level and you want your rings back!


    So, all we've done here to all 3 games, is if y-wrap is enabled, do not delete the rings if they've reached them co-ordinates. If y-wrap is disabled, then to delete the rings once they've reached the bottom of the level.


    The rings itself will still delete themselves after a certain amount of time, so, you do not need to worry about them being around forever if y-wrap is enabled.




    That's it. Again, if anyone wants to add this to the hacking guide, feel free.

    Enjoy!

    redhotsonic
     
  2. Knucklez

    Knucklez

    I love 2B 'n' ass. Member
    683
    17
    18
    Damn RHS, you're on a roll with these guides. Keep it up.

    Now that I think of it, this issue gets on my nerves every time I play through these games. So I'm glad to know it's actually a glitch and not a permanent fixture. Well, then again nothing is permanent; it's all in the code.
     
  3. Huh, I wasn't even aware of this glitch!
    You're always coming up with great fixes for little things that I've never really noticed before, and it's awesome!
     
  4. redhotsonic

    redhotsonic

    Also known as RHS Tech Member
    1,587
    9
    18
    United Kingdom
    YouTuber
    Thanks, guys; I try my best =P
     
  5. RetroKoH

    RetroKoH

    Member
    1,661
    18
    18
    Project Sonic 8x16
    Jesus Christ... too much more and I might be out of a job, on the count of spending all my time working on putting together wikis for all these guides.

    NAH I kid, but seriously... another nice fix. I'll get to it when I can, it'll be a while though.
     
  6. redhotsonic

    redhotsonic

    Also known as RHS Tech Member
    1,587
    9
    18
    United Kingdom
    YouTuber
    No rush, mate. And yeah, when I spot a bug that I've never noticed before, I see if anyone has mentioned the bug before and if not, make a fix and share it with the world =P
     
  7. RetroKoH

    RetroKoH

    Member
    1,661
    18
    18
    Project Sonic 8x16
    BAM! There you go... another one in the books. I wasn't sure how to get those images onto the page... I'll figure that out sometime, in the meantime, I linked to this thread.

    Some of you may have noticed that I've been trying to throw a lot of your guides up on the wiki as of late. I plan on continuing this...
    I'm gonna be doing plenty of work with the SCHG How-To's in the immediate future... including adding a lot of stuff that hasn't been documented yet, (Mentioned perhaps, but not documented) and will be reorganizing EVERYTHING in the lists to make it a little less cluttered... Don't worry... I won't fuck anything up. I do know what I am doing.

    I will also be adding a template to the SCHG containing a list of Sonic 3 guides in the future, as we don't have one (due to lack of documented content). That won't come for a little while though, as I don't want to just slap one on the wiki without a substantial amount of info to put in it. I've contacted Tiddles, and he will be assisting me with this, as he probably has the most knowledge of working with Sonic 3&K, though RHS' guides like this one have a place on it as well. Anyone else with experience hacking Sonic 3 can/should also jump aboard as well. And if you can wiki shit on the site... that's a big help too, as its less work I gotta do. Of course, I'm willing to do all of it myself... as it's really a labor of love for me... I certainly enjoy doing it, and find all these guide useful... but any help would be grand. :argh:Y'arrghhhh....

    I hope you all have, and will continue to enjoy my work in trying to make sure that everything you guys offer gets documented and saved on the SCHG How-To sections for future use! And of course, a big thank you to RHS, and all of the other Members/Techs that have researched and hacked to provide this wealth of information that either has been/will be put into the SCHG. Without you all, We'd have nothing more than buggy vanilla Sonic ROMS to play with until we die of boredom.
     
  8. redhotsonic

    redhotsonic

    Also known as RHS Tech Member
    1,587
    9
    18
    United Kingdom
    YouTuber
    I'm going to have to start paying you for all these wiki adds you do lol

    Cheers for that, mate