Actions

SCHG How-to

Difference between revisions of "Remove the Air Speed Cap"

From Sonic Retro

m
(Cleanup.)
Line 5: Line 5:
 
Go to ''Sonic_ChgJumpDir'', which should look like this in Xenowhirl's 2007 Sonic 2 disassembly:
 
Go to ''Sonic_ChgJumpDir'', which should look like this in Xenowhirl's 2007 Sonic 2 disassembly:
 
<asm>Sonic_ChgJumpDir:
 
<asm>Sonic_ChgJumpDir:
move.w (Sonic_top_speed).w,d6
+
move.w (Sonic_top_speed).w,d6
move.w (Sonic_acceleration).w,d5
+
move.w (Sonic_acceleration).w,d5
asl.w #1,d5
+
asl.w #1,d5
btst #4,status(a0) ; did Sonic jump from rolling?
+
btst #4,status(a0) ; did Sonic jump from rolling?
bne.s Obj01_Jump_ResetScr ; if yes, branch to skip midair control
+
bne.s Obj01_Jump_ResetScr ; if yes, branch to skip midair control
move.w x_vel(a0),d0
+
move.w x_vel(a0),d0
btst #2,(Ctrl_1_Held_Logical).w
+
btst #2,(Ctrl_1_Held_Logical).w
beq.s + ; if not holding left, branch
+
beq.s + ; if not holding left, branch
  
bset #0,status(a0)
+
bset #0,status(a0)
sub.w d5,d0 ; add acceleration to the left
+
sub.w d5,d0 ; add acceleration to the left
move.w d6,d1
+
move.w d6,d1
neg.w d1
+
neg.w d1
cmp.w d1,d0 ; compare new speed with top speed
+
cmp.w d1,d0 ; compare new speed with top speed
bgt.s + ; if new speed is less than the maximum, branch
+
bgt.s + ; if new speed is less than the maximum, branch
move.w d1,d0 ; limit speed in air going left, even if Sonic was already going faster (speed limit/cap)
+
move.w d1,d0 ; limit speed in air going left, even if Sonic was already going faster (speed limit/cap)
 
+
 
+
btst #3,(Ctrl_1_Held_Logical).w
+
btst #3,(Ctrl_1_Held_Logical).w
beq.s + ; if not holding right, branch
+
beq.s + ; if not holding right, branch
 
+
bclr #0,status(a0)
bclr #0,status(a0)
+
add.w d5,d0 ; accelerate right in the air
add.w d5,d0 ; accelerate right in the air
+
cmp.w d6,d0 ; compare new speed with top speed
cmp.w d6,d0 ; compare new speed with top speed
+
blt.s + ; if new speed is less than the maximum, branch
blt.s + ; if new speed is less than the maximum, branch
+
move.w d6,d0 ; limit speed in air going right, even if Sonic was already going faster (speed limit/cap)
move.w d6,d0 ; limit speed in air going right, even if Sonic was already going faster (speed limit/cap)
 
 
; Obj01_JumpMove:
 
; Obj01_JumpMove:
 
+ move.w d0,x_vel(a0)</asm>
 
+ move.w d0,x_vel(a0)</asm>
 
If you look closely, you will notice that this code works excactly like in Sonic 1. This is good, because we can use the excact same methods to fix it. After the line '''''bgt.s + ; if new speed is less than the maximum, branch''''' add these lines:
 
If you look closely, you will notice that this code works excactly like in Sonic 1. This is good, because we can use the excact same methods to fix it. After the line '''''bgt.s + ; if new speed is less than the maximum, branch''''' add these lines:
<asm> add.w d5,d0 ; +++ air speed cap fix
+
<asm> add.w d5,d0 ; +++ remove this frame's acceleration change
cmp.w d1,d0 ; +++ air speed cap fix
+
cmp.w d1,d0 ; +++ compare speed with top speed
ble.s + ; +++ air speed cap fix</asm>
+
ble.s + ; +++ if speed was already greater than the maximum, branch</asm>
 
Do the same thing after '''''blt.s + ; if new speed is less than the maximum, branch''''' by using these lines:
 
Do the same thing after '''''blt.s + ; if new speed is less than the maximum, branch''''' by using these lines:
<asm> sub.w d5,d0 ; +++ air speed cap fix
+
<asm> sub.w d5,d0 ; +++ remove this frame's acceleration change
cmp.w d6,d0 ; +++ air speed cap fix
+
cmp.w d1,d0 ; +++ compare speed with top speed
bge.s + ; +++ air speed cap fix</asm>
+
ble.s + ; +++ if speed was already greater than the maximum, branch</asm>
  
 
The final result should look like this:
 
The final result should look like this:
 
<asm>Sonic_ChgJumpDir:
 
<asm>Sonic_ChgJumpDir:
move.w (Sonic_top_speed).w,d6
+
move.w (Sonic_top_speed).w,d6
move.w (Sonic_acceleration).w,d5
+
move.w (Sonic_acceleration).w,d5
asl.w #1,d5
+
asl.w #1,d5
btst #4,status(a0) ; did Sonic jump from rolling?
+
btst #4,status(a0) ; did Sonic jump from rolling?
bne.s Obj01_Jump_ResetScr ; if yes, branch to skip midair control
+
bne.s Obj01_Jump_ResetScr ; if yes, branch to skip midair control
move.w x_vel(a0),d0
+
move.w x_vel(a0),d0
btst #2,(Ctrl_1_Held_Logical).w
+
btst #2,(Ctrl_1_Held_Logical).w
beq.s + ; if not holding left, branch
+
beq.s + ; if not holding left, branch
  
bset #0,status(a0)
+
bset #0,status(a0)
sub.w d5,d0 ; add acceleration to the left
+
sub.w d5,d0 ; add acceleration to the left
move.w d6,d1
+
move.w d6,d1
neg.w d1
+
neg.w d1
cmp.w d1,d0 ; compare new speed with top speed
+
cmp.w d1,d0 ; compare new speed with top speed
bgt.s + ; if new speed is less than the maximum, branch
+
bgt.s + ; if new speed is less than the maximum, branch
add.w d5,d0 ; +++ air speed cap fix
+
add.w d5,d0 ; +++ remove this frame's acceleration change
cmp.w d1,d0 ; +++ air speed cap fix
+
cmp.w d1,d0 ; +++ compare speed with top speed
ble.s + ; +++ air speed cap fix
+
ble.s + ; +++ if speed was already greater than the maximum, branch
move.w d1,d0 ; limit speed in air going left, even if Sonic was already going faster (speed limit/cap)
+
move.w d1,d0 ; limit speed in air going left, even if Sonic was already going faster (speed limit/cap)
 
+
 
+
btst #3,(Ctrl_1_Held_Logical).w
+
btst #3,(Ctrl_1_Held_Logical).w
beq.s + ; if not holding right, branch
+
beq.s + ; if not holding right, branch
  
bclr #0,status(a0)
+
bclr #0,status(a0)
add.w d5,d0 ; accelerate right in the air
+
add.w d5,d0 ; accelerate right in the air
cmp.w d6,d0 ; compare new speed with top speed
+
cmp.w d6,d0 ; compare new speed with top speed
blt.s + ; if new speed is less than the maximum, branch
+
blt.s + ; if new speed is less than the maximum, branch
sub.w d5,d0 ; +++ air speed cap fix
+
sub.w d5,d0 ; +++ remove this frame's acceleration change
cmp.w d6,d0 ; +++ air speed cap fix
+
cmp.w d1,d0 ; +++ compare speed with top speed
bge.s + ; +++ air speed cap fix
+
ble.s + ; +++ if speed was already greater than the maximum, branch
move.w d6,d0 ; limit speed in air going right, even if Sonic was already going faster (speed limit/cap)
+
move.w d6,d0 ; limit speed in air going right, even if Sonic was already going faster (speed limit/cap)
 
; Obj01_JumpMove:
 
; Obj01_JumpMove:
 
+ move.w d0,x_vel(a0)</asm>
 
+ move.w d0,x_vel(a0)</asm>
  
 
[[Category:SCHG How-tos|Remove the Air Speed Cap]]
 
[[Category:SCHG How-tos|Remove the Air Speed Cap]]

Revision as of 16:46, 9 September 2010

(Guide written by Selbi; code by Puto, taken from the Sonic 1 Speed Cap page)

In Sonic 1 is a function, that limits Sonic's top speed when you are keep pressing in the direction you are looking at (you can feel that best when running down a hill). In Sonic 2 this function doesn't apply; well, at least not completely. Running on the ground works just fine, but in the air you still have it. So let's fix that:

Go to Sonic_ChgJumpDir, which should look like this in Xenowhirl's 2007 Sonic 2 disassembly: <asm>Sonic_ChgJumpDir: move.w (Sonic_top_speed).w,d6 move.w (Sonic_acceleration).w,d5 asl.w #1,d5 btst #4,status(a0) ; did Sonic jump from rolling? bne.s Obj01_Jump_ResetScr ; if yes, branch to skip midair control move.w x_vel(a0),d0 btst #2,(Ctrl_1_Held_Logical).w beq.s + ; if not holding left, branch

bset #0,status(a0) sub.w d5,d0 ; add acceleration to the left move.w d6,d1 neg.w d1 cmp.w d1,d0 ; compare new speed with top speed bgt.s + ; if new speed is less than the maximum, branch move.w d1,d0 ; limit speed in air going left, even if Sonic was already going faster (speed limit/cap) + btst #3,(Ctrl_1_Held_Logical).w beq.s + ; if not holding right, branch bclr #0,status(a0) add.w d5,d0 ; accelerate right in the air cmp.w d6,d0 ; compare new speed with top speed blt.s + ; if new speed is less than the maximum, branch move.w d6,d0 ; limit speed in air going right, even if Sonic was already going faster (speed limit/cap)

Obj01_JumpMove

+ move.w d0,x_vel(a0)</asm> If you look closely, you will notice that this code works excactly like in Sonic 1. This is good, because we can use the excact same methods to fix it. After the line bgt.s + ; if new speed is less than the maximum, branch add these lines: <asm> add.w d5,d0 ; +++ remove this frame's acceleration change cmp.w d1,d0 ; +++ compare speed with top speed ble.s + ; +++ if speed was already greater than the maximum, branch</asm> Do the same thing after blt.s + ; if new speed is less than the maximum, branch by using these lines: <asm> sub.w d5,d0 ; +++ remove this frame's acceleration change cmp.w d1,d0 ; +++ compare speed with top speed ble.s + ; +++ if speed was already greater than the maximum, branch</asm>

The final result should look like this: <asm>Sonic_ChgJumpDir: move.w (Sonic_top_speed).w,d6 move.w (Sonic_acceleration).w,d5 asl.w #1,d5 btst #4,status(a0) ; did Sonic jump from rolling? bne.s Obj01_Jump_ResetScr ; if yes, branch to skip midair control move.w x_vel(a0),d0 btst #2,(Ctrl_1_Held_Logical).w beq.s + ; if not holding left, branch

bset #0,status(a0) sub.w d5,d0 ; add acceleration to the left move.w d6,d1 neg.w d1 cmp.w d1,d0 ; compare new speed with top speed bgt.s + ; if new speed is less than the maximum, branch add.w d5,d0 ; +++ remove this frame's acceleration change cmp.w d1,d0 ; +++ compare speed with top speed ble.s + ; +++ if speed was already greater than the maximum, branch move.w d1,d0 ; limit speed in air going left, even if Sonic was already going faster (speed limit/cap) + btst #3,(Ctrl_1_Held_Logical).w beq.s + ; if not holding right, branch

bclr #0,status(a0) add.w d5,d0 ; accelerate right in the air cmp.w d6,d0 ; compare new speed with top speed blt.s + ; if new speed is less than the maximum, branch sub.w d5,d0 ; +++ remove this frame's acceleration change cmp.w d1,d0 ; +++ compare speed with top speed ble.s + ; +++ if speed was already greater than the maximum, branch move.w d6,d0 ; limit speed in air going right, even if Sonic was already going faster (speed limit/cap)

Obj01_JumpMove

+ move.w d0,x_vel(a0)</asm>