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

Discussion in 'Tutorials Archive' started by Ravenfreak, Aug 20, 2010.

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

    Ravenfreak Still hacking the 8-bit titles Member

    Joined:
    Feb 10, 2010
    Messages:
    410
    Location:
    O'Fallon, MO
    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. (That's what I used, found here:http://info.sonicretro.org/images/8/8b/Sonic_%26_Knuckles_%28Text_Format_by_Pu7o%29.zip, and here: http://info.sonicretro.org/images/e/e8/SnK...uildtools.zip.) 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: First search for sub_1094C, it should look like this: (note: this is the entire routine btw.)



    Code:
    sub_1094C:			&#59; CODE XREF: ROM:00010844p
    
    		tst.b	$3D(a0)
    
    		bne.s	loc_10998
    
    		cmpi.b	#8,$20(a0)
    
    		bne.s	locret_10996
    
    		move.b	($FFFFF603).w,d0
    
    		andi.b	#$70,d0
    
    		beq.w	locret_10996
    
    		move.b	#9,$20(a0)
    
    		move.w	#$FFAB,d0
    
    		jsr	(Play_Sound_2).l
    
    		addq.l	#4,sp
    
    		move.b	#1,$3D(a0)
    
    		move.w	#0,$3E(a0)
    
    		cmpi.b	#$C,$2C(a0)
    
    		bcs.s	loc_10992
    
    		move.b	#2,$20(a6)
    
    
    
    loc_10992:			&#59; CODE XREF: sub_1094C+3Ej
    
    		bsr.w	Player_AnglePos
    
    
    
    locret_10996:			&#59; CODE XREF: sub_1094C+Cj
    
    				&#59; sub_1094C+16j
    
    		rts	
    
    ; ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
    
    ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
    
    
    
    loc_10998:			&#59; CODE XREF: sub_1094C+4j
    
    		move.b	($FFFFF602).w,d0
    
    		btst	#1,d0
    
    		bne.w	loc_10A38
    
    		move.b	#7,$1E(a0)
    
    		move.b	#3,$1F(a0)
    
    		move.b	#2,$20(a0)
    
    		addq.w	#4,$14(a0)
    
    		move.b	#0,$3D(a0)
    
    		moveq	#0,d0
    
    		move.b	$3E(a0),d0
    
    		add.w	d0,d0
    
    		move.w	word_10A14(pc,d0.w),$1C(a0)
    
    		move.w	$1C(a0),d0
    
    		subi.w	#$800,d0
    
    		add.w	d0,d0
    
    		andi.w	#$1F00,d0
    
    		neg.w	d0
    
    		addi.w	#$2000,d0
    
    		lea	($FFFFEE24).w,a1
    
    		cmpa.w	#$B000,a0
    
    		beq.s	loc_109F0
    
    		lea	($FFFFEE28).w,a1
    
    
    
    loc_109F0:			&#59; CODE XREF: sub_1094C+9Ej
    
    		move.w	d0,(a1)
    
    		btst	#0,$2A(a0)
    
    		beq.s	loc_109FE
    
    		neg.w	$1C(a0)
    
    
    
    loc_109FE:			&#59; CODE XREF: sub_1094C+ACj
    
    		bset	#2,$2A(a0)
    
    		move.b	#0,$20(a6)
    
    		moveq	#-$4A,d0
    
    		jsr	(Play_Sound_2).l
    
    		bra.s	loc_10A80
    
    ; ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
    
    ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
    
    word_10A14:	dc.w $800
    
    		dc.w $880
    
    		dc.w $900
    
    		dc.w $980
    
    		dc.w $A00
    
    		dc.w $A80
    
    		dc.w $B00
    
    		dc.w $B80
    
    		dc.w $C00
    
    		dc.w $B00
    
    		dc.w $B80
    
    		dc.w $C00
    
    		dc.w $C80
    
    		dc.w $D00
    
    		dc.w $D80
    
    		dc.w $E00
    
    		dc.w $E80
    
    		dc.w $F00
    
    ; ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
    
    ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
    
    
    
    loc_10A38:			&#59; CODE XREF: sub_1094C+54j
    
    		tst.w	$3E(a0)
    
    		beq.s	loc_10A50
    
    		move.w	$3E(a0),d0
    
    		lsr.w	#5,d0
    
    		sub.w	d0,$3E(a0)
    
    		bcc.s	loc_10A50
    
    		move.w	#0,$3E(a0)
    
    
    
    loc_10A50:			&#59; CODE XREF: sub_1094C+F0j
    
    				&#59; sub_1094C+FCj
    
    		move.b	($FFFFF603).w,d0
    
    		andi.b	#$70,d0
    
    		beq.w	loc_10A80
    
    		move.w	#$900,$20(a0)
    
    		move.w	#$FFAB,d0
    
    		jsr	(Play_Sound_2).l
    
    		addi.w	#$200,$3E(a0)
    
    		cmpi.w	#$800,$3E(a0)
    
    		bcs.s	loc_10A80
    
    		move.w	#$800,$3E(a0)
    
    
    
    loc_10A80:			&#59; CODE XREF: sub_1094C+C6j
    
    				&#59; sub_1094C+10Cj ...
    
    		addq.l	#4,sp
    
    		cmpi.w	#$60,(a5)
    
    		beq.s	loc_10A8E
    
    		bcc.s	loc_10A8C
    
    		addq.w	#4,(a5)
    
    
    
    loc_10A8C:			&#59; CODE XREF: sub_1094C+13Cj
    
    		subq.w	#2,(a5)
    
    
    
    loc_10A8E:			&#59; CODE XREF: sub_1094C+13Aj
    
    		bsr.w	Player_AnglePos
    
    		rts	
    
    ; 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 bsr.w Player_Spindash.(Note: you can also do this step with Knux's, but Sonic's code is first. xP) Replace it with 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:
    loc_10998:			&#59; CODE XREF: sub_1094C+4j
    
    		move.b	($FFFFF602).w,d0;also this
    
    		btst	#1,d0
    
    		bne.w	loc_10A38
    
    		move.b	#7,$1E(a0);this is what we need
    
    		move.b	#3,$1F(a0);to change
    
    		move.b	#2,$20(a0)
    
    		addq.w	#4,$14(a0);this too
    
    		move.b	#0,$3D(a0)
    
    		moveq	#0,d0
    
    		move.b	$3E(a0),d0
    
    		add.w	d0,d0
    
    		move.w	word_10A14(pc,d0.w),$1C(a0)
    
    		move.w	$1C(a0),d0
    
    		subi.w	#$800,d0
    
    		add.w	d0,d0
    
    		andi.w	#$1F00,d0
    
    		neg.w	d0
    
    		addi.w	#$2000,d0
    
    		lea	($FFFFEE24).w,a1
    
    		cmpa.w	#$B000,a0
    
    		beq.s	loc_109F0
    
    		lea	($FFFFEE28).w,a1
    And change it to this:



    Code:
    loc_10998:			&#59; CODE XREF: sub_1094C+4j
    
    		move.b	($FFFFF604).w,d0
    
    		btst	#1,d0
    
    		bne.w	loc_10A38
    
    		move.b	#$E,$1E(a0)
    
    		move.b	#7,$1F(a0)
    
    		move.b	#2,$20(a0)
    
    		addq.w	#5,$14(a0)
    
    		move.b	#0,$3D(a0)
    
    		moveq	#0,d0
    
    		move.b	$3E(a0),d0
    
    		add.w	d0,d0
    
    		move.w	word_10A14(pc,d0.w),$1C(a0)
    
    		move.w	$1C(a0),d0
    
    		subi.w	#$800,d0
    
    		add.w	d0,d0
    
    		andi.w	#$1F00,d0
    
    		neg.w	d0
    
    		addi.w	#$2000,d0
    
    		lea	($FFFFEE24).w,a1
    
    		cmpa.w	#$B000,a0
    
    		beq.s	loc_109F0
    
    		lea	($FFFFEE28).w,a1
    And now for the final touches. Search for loc_10992, and loc_10A8E. You'll see this:



    Code:
    bsr.w Player_AnglePos
    Simply change this to

    Code:
    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.