don't click here

How To Split Sonic's and Knuckles' Spindash Routines in S3K

Discussion in 'Engineering & Reverse Engineering' started by Ravenfreak, Aug 20, 2010.

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

    Ravenfreak

    2 Edgy 4 U Tech Member
    3,091
    187
    43
    O'Fallon Mo
    Sonic 1 Game Gear Disassembly
    So lately, I have been tweaking S3K here and there, and I came across another Spindash routine right above where Sonic's code starts. Also, I found out that Sonic and Knuckles actually share the same routine for Spindashing. Back to the other routine (there's actually 3 in S3k, one is Tails', one is Sonic's/Knux's, and the one above Sonic's.)It's fully functional, well almost. So I tweaked it a bit, and after I got it to function properly, I got an idea. What if for some reason, someone wanted to separate Sonic's/Knux's routine and give each character their own routine? So I did just that. If you wanted to, for some reason this is how. First off, you'll need the S3K/SK Buildtools and Puto's text disassembly. You must use context (or another program) for this though, as trying to open the disassembly file in notepad caused it to stop responding, due to how huge the file is. :v: (Though my computer isn't that fast I think...) First search for sub_1094C, it should look like this: (note: this is the entire routine btw.)
    Code (ASM):
    1.  
    2. sub_1094C:            ; CODE XREF: ROM:00010844p
    3.         tst.b    $3D(a0)
    4.         bne.s    loc_10998
    5.         cmpi.b    #8,$20(a0)
    6.         bne.s    locret_10996
    7.         move.b    ($FFFFF603).w,d0
    8.         andi.b    #$70,d0
    9.         beq.w    locret_10996
    10.         move.b    #9,$20(a0)
    11.         move.w    #$FFAB,d0
    12.         jsr    (Play_Sound_2).l
    13.         addq.l    #4,sp
    14.         move.b    #1,$3D(a0)
    15.         move.w    #0,$3E(a0)
    16.         cmpi.b    #$C,$2C(a0)
    17.         bcs.s    loc_10992
    18.         move.b    #2,$20(a6)
    19.  
    20. loc_10992:            ; CODE XREF: sub_1094C+3Ej
    21.         bsr.w    Player_AnglePos
    22.  
    23. locret_10996:            ; CODE XREF: sub_1094C+Cj
    24.                 ; sub_1094C+16j
    25.         rts    
    26. ; ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
    27. ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
    28.  
    29. loc_10998:            ; CODE XREF: sub_1094C+4j
    30.         move.b    ($FFFFF602).w,d0
    31.         btst    #1,d0
    32.         bne.w    loc_10A38
    33.         move.b    #7,$1E(a0)
    34.         move.b    #3,$1F(a0)
    35.         move.b    #2,$20(a0)
    36.         addq.w    #4,$14(a0)
    37.         move.b    #0,$3D(a0)
    38.         moveq    #0,d0
    39.         move.b    $3E(a0),d0
    40.         add.w    d0,d0
    41.         move.w    word_10A14(pc,d0.w),$1C(a0)
    42.         move.w    $1C(a0),d0
    43.         subi.w    #$800,d0
    44.         add.w    d0,d0
    45.         andi.w    #$1F00,d0
    46.         neg.w    d0
    47.         addi.w    #$2000,d0
    48.         lea    ($FFFFEE24).w,a1
    49.         cmpa.w    #$B000,a0
    50.         beq.s    loc_109F0
    51.         lea    ($FFFFEE28).w,a1
    52.  
    53. loc_109F0:            ; CODE XREF: sub_1094C+9Ej
    54.         move.w    d0,(a1)
    55.         btst    #0,$2A(a0)
    56.         beq.s    loc_109FE
    57.         neg.w    $1C(a0)
    58.  
    59. loc_109FE:            ; CODE XREF: sub_1094C+ACj
    60.         bset    #2,$2A(a0)
    61.         move.b    #0,$20(a6)
    62.         moveq    #-$4A,d0
    63.         jsr    (Play_Sound_2).l
    64.         bra.s    loc_10A80
    65. ; ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
    66. ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
    67. word_10A14:    dc.w $800
    68.         dc.w $880
    69.         dc.w $900
    70.         dc.w $980
    71.         dc.w $A00
    72.         dc.w $A80
    73.         dc.w $B00
    74.         dc.w $B80
    75.         dc.w $C00
    76.         dc.w $B00
    77.         dc.w $B80
    78.         dc.w $C00
    79.         dc.w $C80
    80.         dc.w $D00
    81.         dc.w $D80
    82.         dc.w $E00
    83.         dc.w $E80
    84.         dc.w $F00
    85. ; ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
    86. ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
    87.  
    88. loc_10A38:            ; CODE XREF: sub_1094C+54j
    89.         tst.w    $3E(a0)
    90.         beq.s    loc_10A50
    91.         move.w    $3E(a0),d0
    92.         lsr.w    #5,d0
    93.         sub.w    d0,$3E(a0)
    94.         bcc.s    loc_10A50
    95.         move.w    #0,$3E(a0)
    96.  
    97. loc_10A50:            ; CODE XREF: sub_1094C+F0j
    98.                 ; sub_1094C+FCj
    99.         move.b    ($FFFFF603).w,d0
    100.         andi.b    #$70,d0
    101.         beq.w    loc_10A80
    102.         move.w    #$900,$20(a0)
    103.         move.w    #$FFAB,d0
    104.         jsr    (Play_Sound_2).l
    105.         addi.w    #$200,$3E(a0)
    106.         cmpi.w    #$800,$3E(a0)
    107.         bcs.s    loc_10A80
    108.         move.w    #$800,$3E(a0)
    109.  
    110. loc_10A80:            ; CODE XREF: sub_1094C+C6j
    111.                 ; sub_1094C+10Cj ...
    112.         addq.l    #4,sp
    113.         cmpi.w    #$60,(a5)
    114.         beq.s    loc_10A8E
    115.         bcc.s    loc_10A8C
    116.         addq.w    #4,(a5)
    117.  
    118. loc_10A8C:            ; CODE XREF: sub_1094C+13Cj
    119.         subq.w    #2,(a5)
    120.  
    121. loc_10A8E:            ; CODE XREF: sub_1094C+13Aj
    122.         bsr.w    Player_AnglePos
    123.         rts    
    124. ; End of function sub_1094C
    If you ever looked at the routine for the Spindash, you'll notice it looks similar, but it's slightly different. So next, look for Player_Spindash. You only have to search once, because we need to comment out this:
    Code (ASM):
    1. bsr.w Player_Spindash
    (Note: you can also do this step with Knux's, but Sonic's code is first. xP) Replace it with this:
    Code (ASM):
    1. bsr.w sub_1094C
    Build the rom and test it out. You'll notice Sonic does spindash, but he doesn't move forward! That's because the values for the Height, Width, and Y playfield coordinate of the character are different.(In this routine they are #7, $1E #3,$1F, #4,$14.)You also need to change the joypad address. This is an easy fix. Simply search for loc_10998, it should look like this:
    Code (ASM):
    1.  
    2. loc_10998:            ; CODE XREF: sub_1094C+4j
    3.         move.b    ($FFFFF602).w,d0
    4.         btst    #1,d0
    5.         bne.w    loc_10A38
    6.         move.b    #7,$1E(a0)
    7.         move.b    #3,$1F(a0)
    8.         move.b    #2,$20(a0)
    9.         addq.w    #4,$14(a0)
    10.         move.b    #0,$3D(a0)
    11.         moveq    #0,d0
    12.         move.b    $3E(a0),d0
    13.         add.w    d0,d0
    14.         move.w    word_10A14(pc,d0.w),$1C(a0)
    15.         move.w    $1C(a0),d0
    16.         subi.w    #$800,d0
    17.         add.w    d0,d0
    18.         andi.w    #$1F00,d0
    19.         neg.w    d0
    20.         addi.w    #$2000,d0
    21.         lea    ($FFFFEE24).w,a1
    22.         cmpa.w    #$B000,a0
    23.         beq.s    loc_109F0
    24.         lea    ($FFFFEE28).w,a1
    And change it to this:
    Code (ASM):
    1.  
    2. loc_10998:            ; CODE XREF: sub_1094C+4j
    3.         move.b    ($FFFFF604).w,d0
    4.         btst    #1,d0
    5.         bne.w    loc_10A38
    6.         move.b    #$E,$1E(a0)
    7.         move.b    #7,$1F(a0)
    8.         move.b    #2,$20(a0)
    9.         addq.w    #5,$14(a0)
    10.         move.b    #0,$3D(a0)
    11.         moveq    #0,d0
    12.         move.b    $3E(a0),d0
    13.         add.w    d0,d0
    14.         move.w    word_10A14(pc,d0.w),$1C(a0)
    15.         move.w    $1C(a0),d0
    16.         subi.w    #$800,d0
    17.         add.w    d0,d0
    18.         andi.w    #$1F00,d0
    19.         neg.w    d0
    20.         addi.w    #$2000,d0
    21.         lea    ($FFFFEE24).w,a1
    22.         cmpa.w    #$B000,a0
    23.         beq.s    loc_109F0
    24.         lea    ($FFFFEE28).w,a1
    And now for the final touches. Search for loc_10992, and loc_10A8E. You'll see this:
    Code (ASM):
    1.  
    2. bsr.w Player_AnglePos
    Simply change both of them to this:
    Code (ASM):
    1.  
    2. bsr.w Call_Player_AnglePos
    Build the ROM and there you go. You won't actually notice anything different, but they now have separate routines. Also note, this affects 2 player mode a bit. The d-pad is "locked" at start if you play as Knux/Sonic. Jumping will "unlock" the d-pad. You also can't Spindash. I don't have a fix for that, yet, but I'll update this once I figure it out. :\
     
Thread Status:
Not open for further replies.