Difference between revisions of "Improve ObjectMove subroutines"
From Sonic Retro
Scarred Sun (talk | contribs) m (Text replacement - "</asm>" to "</syntaxhighlight>") |
Scarred Sun (talk | contribs) m (Text replacement - "<asm>" to "<syntaxhighlight lang="asm">") |
||
Line 13: | Line 13: | ||
==Sonic 1 Hivebrain== | ==Sonic 1 Hivebrain== | ||
First find ObjectFall and change this: | First find ObjectFall and change this: | ||
− | <asm> | + | <syntaxhighlight lang="asm"> |
ObjectFall: | ObjectFall: | ||
move.l 8(a0),d2 | move.l 8(a0),d2 | ||
Line 34: | Line 34: | ||
To this: | To this: | ||
− | <asm> | + | <syntaxhighlight lang="asm"> |
ObjectFall: | ObjectFall: | ||
move.w $10(a0),d0 | move.w $10(a0),d0 | ||
Line 51: | Line 51: | ||
Next, find SpeedToPos and change this: | Next, find SpeedToPos and change this: | ||
− | <asm> | + | <syntaxhighlight lang="asm"> |
SpeedToPos: | SpeedToPos: | ||
move.l 8(a0),d2 | move.l 8(a0),d2 | ||
Line 71: | Line 71: | ||
to this: | to this: | ||
− | <asm> | + | <syntaxhighlight lang="asm"> |
SpeedToPos: | SpeedToPos: | ||
move.w $10(a0),d0 ; load horizontal speed | move.w $10(a0),d0 ; load horizontal speed | ||
Line 88: | Line 88: | ||
==Sonic 1 Git/SVN== | ==Sonic 1 Git/SVN== | ||
Open "_incObj/sub ObjectFall.asm" and change this: | Open "_incObj/sub ObjectFall.asm" and change this: | ||
− | <asm> | + | <syntaxhighlight lang="asm"> |
ObjectFall: | ObjectFall: | ||
move.l obX(a0),d2 | move.l obX(a0),d2 | ||
Line 109: | Line 109: | ||
To this: | To this: | ||
− | <asm> | + | <syntaxhighlight lang="asm"> |
ObjectFall: | ObjectFall: | ||
move.w obVelX(a0),d0 | move.w obVelX(a0),d0 | ||
Line 126: | Line 126: | ||
Next, open "_incObj/sub SpeedToPos.asm" and change this: | Next, open "_incObj/sub SpeedToPos.asm" and change this: | ||
− | <asm> | + | <syntaxhighlight lang="asm"> |
SpeedToPos: | SpeedToPos: | ||
move.l obX(a0),d2 | move.l obX(a0),d2 | ||
Line 146: | Line 146: | ||
to this: | to this: | ||
− | <asm> | + | <syntaxhighlight lang="asm"> |
SpeedToPos: | SpeedToPos: | ||
move.w obVelX(a0),d0 ; load horizontal speed | move.w obVelX(a0),d0 ; load horizontal speed | ||
Line 163: | Line 163: | ||
==Sonic 2== | ==Sonic 2== | ||
Go to "ObjectMoveAndFall:" and change this: | Go to "ObjectMoveAndFall:" and change this: | ||
− | <asm> | + | <syntaxhighlight lang="asm"> |
ObjectMoveAndFall: | ObjectMoveAndFall: | ||
move.l x_pos(a0),d2 ; load x position | move.l x_pos(a0),d2 ; load x position | ||
Line 183: | Line 183: | ||
To this: | To this: | ||
− | <asm> | + | <syntaxhighlight lang="asm"> |
ObjectMoveAndFall: | ObjectMoveAndFall: | ||
move.w x_vel(a0),d0 ; load x speed | move.w x_vel(a0),d0 ; load x speed | ||
Line 199: | Line 199: | ||
Next, go to "ObjectMove:" and change this: | Next, go to "ObjectMove:" and change this: | ||
− | <asm> | + | <syntaxhighlight lang="asm"> |
ObjectMove: | ObjectMove: | ||
move.l x_pos(a0),d2 ; load x position | move.l x_pos(a0),d2 ; load x position | ||
Line 218: | Line 218: | ||
to this: | to this: | ||
− | <asm> | + | <syntaxhighlight lang="asm"> |
ObjectMove: | ObjectMove: | ||
move.w x_vel(a0),d0 ; load horizontal speed | move.w x_vel(a0),d0 ; load horizontal speed |
Revision as of 21:46, 20 December 2015
(Original guide by redhotsonic)
(Hivebrain Addition by Luigi Hero)
Want to speed up your hack?
In S1, S2 and S3K, there are two subroutines: one allows an object to move about, and the other does the same, except it applies gravity to it. In S1, these subroutines are SpeedToPos, and ObjectFall, respectively. In S2, these are ObjectMove and ObjectMoveAndFall. Finally, in S3K, these are MoveSprite2 and MoveSprite.
S3K has the same subroutines except the code is a bit shorter and therefore, it's faster. It may not look much faster, but again, with all the objects on screen, it has to apply it for every frame.
So, let's change our subroutines to work more like S3K's. To do this, it's really simple.
Sonic 1 Hivebrain
First find ObjectFall and change this:
ObjectFall:
move.l 8(a0),d2
move.l $C(a0),d3
move.w $10(a0),d0
ext.l d0
asl.l #8,d0
add.l d0,d2
move.w $12(a0),d0
addi.w #$38,$12(a0) ; increase vertical speed
ext.l d0
asl.l #8,d0
add.l d0,d3
move.l d2,8(a0)
move.l d3,$C(a0)
rts
; End of function ObjectFall
To this:
ObjectFall:
move.w $10(a0),d0
ext.l d0
lsl.l #8,d0
add.l d0,8(a0)
move.w $12(a0),d0
addi.w #$38,$12(a0) ; increase vertical speed
ext.l d0
lsl.l #8,d0
add.l d0,$C(a0)
rts
; End of function ObjectFall
Next, find SpeedToPos and change this:
SpeedToPos:
move.l 8(a0),d2
move.l $C(a0),d3
move.w $10(a0),d0 ; load horizontal speed
ext.l d0
asl.l #8,d0 ; multiply speed by $100
add.l d0,d2 ; add to x-axis position
move.w $12(a0),d0 ; load vertical speed
ext.l d0
asl.l #8,d0 ; multiply by $100
add.l d0,d3 ; add to y-axis position
move.l d2,8(a0) ; update x-axis position
move.l d3,$C(a0) ; update y-axis position
rts
; End of function SpeedToPos
to this:
SpeedToPos:
move.w $10(a0),d0 ; load horizontal speed
ext.l d0
lsl.l #8,d0 ; multiply speed by $100
add.l d0,8(a0) ; add to x-axis position
move.w $12(a0),d0 ; load vertical speed
ext.l d0
lsl.l #8,d0 ; multiply by $100
add.l d0,$C(a0) ; add to y-axis position
rts
; End of function SpeedToPos
Sonic 1 Git/SVN
Open "_incObj/sub ObjectFall.asm" and change this:
ObjectFall:
move.l obX(a0),d2
move.l obY(a0),d3
move.w obVelX(a0),d0
ext.l d0
asl.l #8,d0
add.l d0,d2
move.w obVelY(a0),d0
addi.w #$38,obVelY(a0) ; increase vertical speed
ext.l d0
asl.l #8,d0
add.l d0,d3
move.l d2,obX(a0)
move.l d3,obY(a0)
rts
; End of function ObjectFall
To this:
ObjectFall:
move.w obVelX(a0),d0
ext.l d0
lsl.l #8,d0
add.l d0,obX(a0)
move.w obVelY(a0),d0
addi.w #$38,obVelY(a0) ; increase vertical speed
ext.l d0
lsl.l #8,d0
add.l d0,obY(a0)
rts
; End of function ObjectFall
Next, open "_incObj/sub SpeedToPos.asm" and change this:
SpeedToPos:
move.l obX(a0),d2
move.l obY(a0),d3
move.w obVelX(a0),d0 ; load horizontal speed
ext.l d0
asl.l #8,d0 ; multiply speed by $100
add.l d0,d2 ; add to x-axis position
move.w obVelY(a0),d0 ; load vertical speed
ext.l d0
asl.l #8,d0 ; multiply by $100
add.l d0,d3 ; add to y-axis position
move.l d2,obX(a0) ; update x-axis position
move.l d3,obY(a0) ; update y-axis position
rts
; End of function SpeedToPos
to this:
SpeedToPos:
move.w obVelX(a0),d0 ; load horizontal speed
ext.l d0
lsl.l #8,d0 ; multiply speed by $100
add.l d0,obX(a0) ; add to x-axis position
move.w obVelY(a0),d0 ; load vertical speed
ext.l d0
lsl.l #8,d0 ; multiply by $100
add.l d0,obY(a0) ; add to y-axis position
rts
; End of function SpeedToPos
Sonic 2
Go to "ObjectMoveAndFall:" and change this:
ObjectMoveAndFall:
move.l x_pos(a0),d2 ; load x position
move.l y_pos(a0),d3 ; load y position
move.w x_vel(a0),d0 ; load x speed
ext.l d0
asl.l #8,d0 ; shift velocity to line up with the middle 16 bits of the 32-bit position
add.l d0,d2 ; add x speed to x position ; note this affects the subpixel position x_sub(a0) = 2+x_pos(a0)
move.w y_vel(a0),d0 ; load y speed
addi.w #$38,y_vel(a0) ; increase vertical speed (apply gravity)
ext.l d0
asl.l #8,d0 ; shift velocity to line up with the middle 16 bits of the 32-bit position
add.l d0,d3 ; add old y speed to y position ; note this affects the subpixel position y_sub(a0) = 2+y_pos(a0)
move.l d2,x_pos(a0) ; store new x position
move.l d3,y_pos(a0) ; store new y position
rts
; End of function ObjectMoveAndFall
To this:
ObjectMoveAndFall:
move.w x_vel(a0),d0 ; load x speed
ext.l d0
lsl.l #8,d0 ; shift velocity to line up with the middle 16 bits of the 32-bit position
add.l d0,x_pos(a0) ; add x speed to x position ; note this affects the subpixel position x_sub(a0) = 2+x_pos(a0)
move.w y_vel(a0),d0 ; load y speed
addi.w #$38,y_vel(a0) ; increase vertical speed (apply gravity)
ext.l d0
lsl.l #8,d0 ; shift velocity to line up with the middle 16 bits of the 32-bit position
add.l d0,y_pos(a0) ; add old y speed to y position ; note this affects the subpixel position y_sub(a0) = 2+y_pos(a0)
rts
; End of function ObjectMoveAndFall
Next, go to "ObjectMove:" and change this:
ObjectMove:
move.l x_pos(a0),d2 ; load x position
move.l y_pos(a0),d3 ; load y position
move.w x_vel(a0),d0 ; load horizontal speed
ext.l d0
asl.l #8,d0 ; shift velocity to line up with the middle 16 bits of the 32-bit position
add.l d0,d2 ; add to x-axis position ; note this affects the subpixel position x_sub(a0) = 2+x_pos(a0)
move.w y_vel(a0),d0 ; load vertical speed
ext.l d0
asl.l #8,d0 ; shift velocity to line up with the middle 16 bits of the 32-bit position
add.l d0,d3 ; add to y-axis position ; note this affects the subpixel position y_sub(a0) = 2+y_pos(a0)
move.l d2,x_pos(a0) ; update x-axis position
move.l d3,y_pos(a0) ; update y-axis position
rts
; End of function ObjectMove
to this:
ObjectMove:
move.w x_vel(a0),d0 ; load horizontal speed
ext.l d0
lsl.l #8,d0 ; shift velocity to line up with the middle 16 bits of the 32-bit position
add.l d0,x_pos(a0) ; add to x-axis position ; note this affects the subpixel position x_sub(a0) = 2+x_pos(a0)
move.w y_vel(a0),d0 ; load vertical speed
ext.l d0
lsl.l #8,d0 ; shift velocity to line up with the middle 16 bits of the 32-bit position
add.l d0,y_pos(a0) ; add to y-axis position ; note this affects the subpixel position y_sub(a0) = 2+y_pos(a0)
rts
; End of function ObjectMove
Conclusion
That's that. For any object that has to move, it will now do this coding a lot quicker each frame.