don't click here

Some changes and fixes for Sonic 2

Discussion in 'Engineering & Reverse Engineering' started by Esrael, Jun 7, 2012.

  1. Esrael

    Esrael

    Neto Tech Member
    302
    249
    43
    Brazil, São Paulo, Guarulhos
    Neto Assembler Editor / Sonic 2 Delta / Neto MD-DOS
    Edit: An user in the discord pointed me that the previous changes break some collisions.
    An extra check is necessary to avoid this, but instead of increasing the processing, a
    table will be used to increase the speed.

    "The 45 to 0 degree bug".
    Why can´t CPz have loops with slanted corners (You can't go from 45 to 0 degrees)?
    Did you noticed that if you try to walk in the right side of the slanted corner the collision will behave wonk.
    Why this occur? Goto to routine Sonic_Angle and look in the code of loc_1E380:
    Code (Text):
    1.  
    2. loc_1E380:    
    3.    move.b   angle(a0),d2
    4.    addi.b   #$20,d2
    5.    andi.b   #$C0,d2
    6.    move.b   d2,angle(a0)
    7.    rts
    8.  
    The issue is caused by the line "addi.b #$20,d2".
    If you are at 135 degree the value in D2 is $E0 and adding $20 will result in 0, but if you are at 45 degree the D2 have the value $20 and adding $20 will result in $40, that are incorrect.

    How to fix?

    replace the code after loc_1E380: with this
    Code (Text):
    1.  
    2. loc_1E380:
    3.                 moveq   #$00, D2
    4.                 move.b  Obj_Angle(A0), D2
    5.                 move.b  Next_Angle_Table_Data(PC, D2), Obj_Angle(A0)          
    6.                 rts
    7. ;-------------------------------------------------------------------------------
    8. Next_Angle_Table_Data:              
    9.                 dc.b    $00, $00, $00, $00, $00, $00, $00, $00
    10.                 dc.b    $00, $00, $00, $00, $00, $00, $00, $00
    11.              
    12.                 dc.b    $00, $00, $00, $00, $00, $00, $00, $00
    13.                 dc.b    $00, $00, $00, $00, $00, $00, $00, $00
    14.  
    15.                 dc.b    $00, $40, $40, $40, $40, $40, $40, $40
    16.                 dc.b    $40, $40, $40, $40, $40, $40, $40, $40
    17.              
    18.                 dc.b    $40, $40, $40, $40, $40, $40, $40, $40
    19.                 dc.b    $40, $40, $40, $40, $40, $40, $40, $40
    20.              
    21.                 dc.b    $40, $40, $40, $40, $40, $40, $40, $40
    22.                 dc.b    $40, $40, $40, $40, $40, $40, $40, $40
    23.              
    24.                 dc.b    $40, $40, $40, $40, $40, $40, $40, $40
    25.                 dc.b    $40, $40, $40, $40, $40, $40, $40, $40
    26.              
    27.                 dc.b    $80, $80, $80, $80, $80, $80, $80, $80
    28.                 dc.b    $80, $80, $80, $80, $80, $80, $80, $80
    29.              
    30.                 dc.b    $80, $80, $80, $80, $80, $80, $80, $80
    31.                 dc.b    $80, $80, $80, $80, $80, $80, $80, $80
    32.              
    33.                 dc.b    $80, $80, $80, $80, $80, $80, $80, $80
    34.                 dc.b    $80, $80, $80, $80, $80, $80, $80, $80
    35.              
    36.                 dc.b    $80, $80, $80, $80, $80, $80, $80, $80
    37.                 dc.b    $80, $80, $80, $80, $80, $80, $80, $80
    38.              
    39.                 dc.b    $80, $C0, $C0, $C0, $C0, $C0, $C0, $C0
    40.                 dc.b    $C0, $C0, $C0, $C0, $C0, $C0, $C0, $C0
    41.              
    42.                 dc.b    $C0, $C0, $C0, $C0, $C0, $C0, $C0, $C0
    43.                 dc.b    $C0, $C0, $C0, $C0, $C0, $C0, $C0, $C0
    44.              
    45.                 dc.b    $C0, $C0, $C0, $C0, $C0, $C0, $C0, $C0
    46.                 dc.b    $C0, $C0, $C0, $C0, $C0, $C0, $C0, $C0
    47.              
    48.                 dc.b    $C0, $C0, $C0, $C0, $C0, $C0, $C0, $C0
    49.                 dc.b    $C0, $C0, $C0, $C0, $C0, $C0, $C0, $C0
    50.              
    51.                 dc.b    $00, $00, $00, $00, $00, $00, $00, $00
    52.                 dc.b    $00, $00, $00, $00, $00, $00, $00, $00
    53.              
    54.                 dc.b    $00, $00, $00, $00, $00, $00, $00, $00
    55.                 dc.b    $00, $00, $00, $00, $00, $00, $00, $00
    56. ;-------------------------------------------------------------------------------
    57.  
    Build and now you can have slopes with 45 to 0 degree in both directions.


    And if you are using Sonic and Knuckles like Sonic Delta 40, the code is at $ED7A
     
    Last edited: Sep 14, 2023
    • Like Like x 3
    • Informative Informative x 1
    • List
  2. Devon

    Devon

    Powered by a malfunctioning Motorola 68000 Tech Member
    1,040
    1,053
    93
    your mom
    There is a possible slight oversight with how the push sensor is positioned. I wrote about it for Sonic 1 here.
    I will add that Tails in general is more suspect to this oversight, because his natural and rolling hitbox heights are almost the same, and thus the threshold for him is always quite low.

    [​IMG]

    In s2.asm, go to loc_1EBE6, and add this right under addq.w #8,d2:
    Code (Text):
    1.         btst    #2,status(a0)          ; Is the Player rolling?
    2.         bne.s   +                      ; If not, branch
    3.         cmpi.b  #ObjID_Tails,id(a0)    ; Is this Tails?
    4.         bne.s   ++                     ; If not, branch
    5.         addq.w  #1,d2                  ; Offset push sensor movement when not rolling
    6. +
    7.         subq.w  #5,d2                  ; Move the push sensor up

    Then, change the "+" in this to a "++":
    Code (Text):
    1.       andi.b  #$38,d1
    2.       bne.s   +

    And you'll get this:

    [​IMG]

    You can adjust the numbers to your liking if you please. I will also note that if you make it so that the push sensor is enabled for other directions (like S3K does when running straight up/down on a wall or running on a flat ceiling), then modifications to account for that will need to be made.
     
    Last edited: Aug 10, 2023
    • Like Like x 5
    • Informative Informative x 1
    • List
  3. saxman

    saxman

    Oldbie Tech Member
    I haven't had a chance to try this, but from what you describe, this sounds like the reason they may have changed the loops. Nice to know you have a fix for it though. 20+ years later, you're still posting interesting stuff!
     
  4. OrionNavattan

    OrionNavattan

    Member
    117
    104
    43
    Oregon
    A sharp eye while observing the behavior of some badniks in frame advance mode revealed two that are not setting their display width correctly: the Turtloid and the Grabber's head/body. The Turtloid's sprite is $38 pixels across, but the width is set as if it's only $30 pixels wide, causing it to pop in abruptly at the right of the screen:
    Code (ASM):
    1. ; Sonic 2 Git
    2. Obj9A_SubObjData:
    3.    subObjData Obj9A_Obj98_MapUnc_37B62,make_art_tile(ArtTile_ArtNem_Turtloid,0,0),4,5,$18,0 ; that $18 should be $1C!
    4. ; ===========================================================================
    5. ; Sonic 2 Orion
    6. SubData_Turt:
    7.        subobjdata   Map_Turt,tile_Nem_Turtloid,render_rel,5,$30/2,id_col_null ; that $30 should be $38!

    Likewise, the Grabber's widest sprite is $2C pixels wide, but the width is set as if it's $20, causing it to both pop in and disappear prematurely at the edges of the screen:
    Code (ASM):
    1. ; Sonic 2 Git
    2. ObjA7_SubObjData:
    3.    subObjData ObjA7_ObjA8_ObjA9_Obj98_MapUnc_3921A,make_art_tile(ArtTile_ArtNem_Grabber,1,1),4,4,$10,$B ; that $10 should be $16!
    4. ; ===========================================================================
    5. ; Sonic 2 Orion
    6. SubData_Grabber:
    7.        subobjdata Map_Grab,tile_Nem_Grabber+tile_pal2+tile_hi,render_rel,4,$20/2,id_col_8x8 ; that $20 should be $2C!

    Changing the width values to the ones noted above fixes both of these bugs, however small they may be.
     
    • Like Like x 4
    • Informative Informative x 1
    • List
  5. Esrael

    Esrael

    Neto Tech Member
    302
    249
    43
    Brazil, São Paulo, Guarulhos
    Neto Assembler Editor / Sonic 2 Delta / Neto MD-DOS
    Last edited: Sep 14, 2023