don't click here

How to add a delay to a function in Sonic 1's ASM?

saum22

Press Start Screen
Oct 10, 2022
3
3
7
I'm trying to hammer out a method for mighty's ability (the ability to stomp into spikes without getting hurt) and I've run into a problem: the flag for double jumping (the thing I'm using to prevent mighty from getting hurt) updates immediately after touching the ground, which the spikes are part of the ground

Code:
; ---------------------------------------------------------------------------
; Subroutine controlling Sonic's jump height/duration
; ---------------------------------------------------------------------------

; ||||||||||||||| S U B R O U T I N E |||||||||||||||||||||||||||||||||||||||


Sonic_JumpHeight:
tst.b $3C(a0)
beq.s loc_134C4
move.w #-$400,d1
btst #6,obStatus(a0)
beq.s loc_134AE
move.w #-$200,d1

loc_134AE:
cmp.w obVelY(a0),d1
ble.s Sonic_InstaAndShieldMoves
move.b (v_jpadhold2).w,d0
andi.b #btnABC,d0 ; is A, B or C pressed?
bne.s locret_134C2 ; if yes, branch
move.w d1,obVelY(a0)

locret_134C2:
rts
; ===========================================================================

loc_134C4:
cmpi.w #-$FC0,obVelY(a0)
bge.s locret_134D2
move.w #-$FC0,obVelY(a0)

locret_134D2:
rts
; End of function Sonic_JumpHeight

Sonic_InstaAndShieldMoves:
tst.b double_jump_flag(a0)
bne.s locret_134D2 ;if yes, branch
move.b (v_jpadpress2).w,d0
andi.b #btnABC,d0 ;A or B or C
beq.s locret_134D2 ;if not, stop function
bclr #4, obStatus(a0)

locret_11A14:
move.b #1, double_jump_flag
move.w #0, obVelX(a0)
move.w #0, obInertia(a0)
move.w # $900,obVelY(a0) ;down we go
bra New_Setup



New_Setup:
move.b 2,obTimeFrame(a0)
New_routine:
subq.b #1,obTimeFrame(a0) ; subtract 1 from time delay
bne.s New_wait ; if time still remains, branch
move.b #0, double_jump_flag

; End of function Sonic_ResetOnFloor

New_wait:
rts

and:


tst.b (v_shield).w ; does Sonic have a shield?
bne.s .hasshield ; if yes, branch
tst.w (v_rings).w ; does Sonic have any rings?
beq.w .norings ; if not, branch
tst.b double_jump_flag(a0)
bne.s .doublejump

jsr (FindFreeObj).l
bne.s .hasshield
_move.b #id_RingLoss,0(a1) ; load bouncing multi rings object
move.w obX(a0),obX(a1)
move.w obY(a0),obY(a1)

.doublejump:
move.b #4,obRoutine(a0)
bsr.w Sonic_ResetOnFloor
bset #1,obStatus(a0)
move.w #-$400,obVelY(a0) ; make Sonic bounce away from the object
move.w #-$200,obVelX(a0)
btst #6,obStatus(a0) ; is Sonic underwater?
beq.s .isdry ; if not, branch

move.w #-$200,obVelY(a0) ; slower bounce
move.w #-$100,obVelX(a0)