ThomasSpeedrunner

Spindash code FIXED

Oct 3rd, 2014
371
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ; ---------------------------------------------------------------------------
  2. ; Subroutine to make Sonic perform a spindash
  3. ; ---------------------------------------------------------------------------
  4.  
  5. ; ||||||||||||||| S U B R O U T I N E |||||||||||||||||||||||||||||||||||||||
  6.  
  7.  
  8. Sonic_SpinDash:
  9.         tst.b   $39(a0)             ; already Spin Dashing?
  10.         bne.s   Spindash_CheckRelease       ; if set, branch
  11.         cmpi.b  #8,$1C(a0)          ; is anim duck
  12.         bne.s   Spindash_Return         ; if not, return
  13.         move.b  ($FFFFF603).w,d0        ; read controller
  14.         andi.b  #$70,d0             ; pressing A/B/C ?
  15.         beq.s   Spindash_Return         ; if not, return
  16.         move.b  #9,$1C(a0)          ; set Spin Dash anim (9 in s2)
  17.         move.w  #$D1,d0             ; spin sound ($E0 in s2)
  18.         jsr (PlaySound_Special).l       ; play spin sound
  19.         addq.l  #4,sp               ; increment stack ptr
  20.         move.b  #1,$39(a0)          ; set Spin Dash flag
  21.         move.b  #0,$3A(a0)          ; set charge count to 0
  22.         cmpi.b  #$C,$28(a0)         ; ??? oxygen remaining?
  23.         bcs.s   Spindash_CallNecessaryRoutines  ; ??? branch if carry
  24.         move.b  #2,($FFFFD11C).w        ; ??? $D11C is used for
  25.                             ; the smoke/dust object
  26. Spindash_CallNecessaryRoutines:
  27.         bsr.w   Sonic_LevelBoundaries
  28.         bsr.w   Sonic_AnglePos
  29.  
  30. Spindash_Return:
  31.         rts
  32. ; ---------------------------------------------------------------------------
  33.  
  34. Spindash_CheckRelease:
  35. ;       move.b  #9,$1C(a0)
  36.         move.b  ($FFFFF602).w,d0        ; read controller
  37.         btst    #1,d0               ; check down button
  38.         bne.w   Spindash_StillCharging      ; if set, branch
  39.         move.b  #$E,$16(a0)         ; $16(a0) is height/2
  40.         move.b  #7,$17(a0)          ; $17(a0) is width/2
  41.         move.b  #2,$1C(a0)          ; set animation to roll
  42.         addq.w  #5,$C(a0)           ; $C(a0) is Y coordinate
  43.         move.b  #0,$39(a0)          ; clear Spin Dash flag
  44.         moveq   #0,d0
  45.         move.b  $3A(a0),d0          ; copy charge count
  46.         add.w   d0,d0               ; double it
  47.         move.w  Dash_Speeds(pc,d0.w),$14(a0)    ; get normal speed
  48.         move.w  $14(a0),d0          ; get inertia
  49.         subi.w  #$800,d0            ; subtract $800
  50.         add.w   d0,d0               ; double it
  51.         andi.w  #$1F00,d0           ; mask it against $1F00
  52.         neg.w   d0              ; negate it
  53.         addi.w  #$2000,d0           ; add $2000
  54.         move.w  d0,($FFFFEED0).w        ; move to $EED0
  55.         btst    #0,$22(a0)          ; is sonic facing right?
  56.         beq.s   Spindash_Release2       ; if not, branch
  57.         neg.w   $14(a0)             ; negate inertia
  58.  
  59. Spindash_Release2:
  60.         bset    #2,$22(a0)          ; set rolling flag
  61.         move.b  #0,($FFFFD11C).w        ; clear $D11C (smoke)
  62.         move.w  #$BC,d0             ; spin release sound
  63.         jsr (PlaySound_Special).l       ; play it!
  64.  
  65.         move.b  angle(a0),d0            ; Load Sonic's angle to d0.
  66.         jsr (CalcSine).l            ; Calculate Sonic's sine and cosine based on his angle.
  67.         muls.w  inertia(a0),d1          ; Multiply d1 by Sonic's inertia.
  68.         asr.l   #8,d1               ; Divide the longword in d1 by 2*2*2*2*2*2*2*2 = 256 (also read as 2^8 = 256).
  69.         move.w  d1,x_vel(a0)            ; Give Sonic horizontal velocity. This has no effect when Sonic is on flat ground at a 0- or 180-degree angle.
  70.         muls.w  inertia(a0),d0          ; Multiply d0 by Sonic's inertia.
  71.         asr.l   #8,d0               ; Divide the longword in d0 by 2*2*2*2*2*2*2*2 = 256 (also read as 2^8 = 256).
  72.         move.w  d0,y_vel(a0)            ; Give Sonic vertical velocity. This has no effect when Sonic is on flat ground that is at a 90- or 270-degree angle.
  73.  
  74.         bra.s   Spindash_ResetScr
  75. ; ===========================================================================
  76. Dash_Speeds:
  77.         dc.w  $800      ; 0
  78.         dc.w  $880      ; 1
  79.         dc.w  $900      ; 2
  80.         dc.w  $980      ; 3
  81.         dc.w  $A00      ; 4
  82.         dc.w  $A80      ; 5
  83.         dc.w  $B00      ; 6
  84.         dc.w  $B80      ; 7
  85.         dc.w  $C00      ; 8
  86. ; ===========================================================================
  87.  
  88. Spindash_StillCharging:                 ; If still charging the dash...
  89.         tst.b   $3A(a0)             ; check charge count
  90.         beq.s   Spindash_Recharge       ; if zero, branch
  91.         move.b  $3A(a0),d0          ; otherwise put it in d0
  92.         lsr.b   #5,d0               ; shift right 5 (divide it by 32)
  93.         sub.b   d0,$3A(a0)          ; subtract from charge count
  94.         bcc.s   Spindash_Recharge       ; ??? branch if carry clear
  95.         move.b  #0,$3A(a0)          ; set charge count to 0
  96.  
  97. Spindash_Recharge:
  98.         move.b  ($FFFFF603).w,d0        ; read controller
  99.         andi.b  #$70,d0             ; pressing A/B/C?
  100.         beq.w   Spindash_ResetScr       ; if not, branch
  101.         move.w  #$900,$1C(a0)           ; reset spdsh animation
  102.         move.w  #$D1,d0             ; was $E0 in sonic 2
  103.         jsr (PlaySound_Special).l       ; play charge sound
  104.         addi.b  #$1,spindash_counter(a0)
  105.         cmpi.b  #$8,spindash_counter(a0)
  106.         bcs.s   Spindash_ResetScr
  107.         move.b  #$8,spindash_counter(a0)
  108.         bra.s   Spindash_ResetScr
  109.         move.b  #$8,spindash_counter(a0)
  110.  
  111. Spindash_ResetScr:
  112.         addq.l  #4,sp               ; increase stack ptr
  113.         cmpi.w  #$60,($FFFFEED8).w      ; $EED8 only ever seems
  114.         beq.s   Spindash_CallNecessaryRoutines2 ; to be used in Spin Dash
  115.         bcc.s   Spindash_ResetScr_Part2
  116.         addq.w  #4,($FFFFEED8).w
  117.  
  118. Spindash_ResetScr_Part2:
  119.         subq.w  #2,($FFFFEED8).w
  120.  
  121. Spindash_CallNecessaryRoutines2:
  122.         bsr.w   Sonic_LevelBoundaries
  123.         bsr.w   Sonic_AnglePos
  124. ;       move.w  #$60,($FFFFF73E).w      ; reset looking up/down
  125.         rts
  126. ; End of subroutine Sonic_SpinDash
  127. ; ===========================================================================
  128.         align 4
Advertisement