Guest User

KoH Tails_Animate

a guest
May 18th, 2020
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ; ---------------------------------------------------------------------------
  2. ; Subroutine to animate Tails's sprites
  3. ; ---------------------------------------------------------------------------
  4.  
  5. ; ||||||||||||||| S U B R O U T I N E |||||||||||||||||||||||||||||||||||||||
  6.  
  7.  
  8. Tails_Animate:
  9.         lea     (Ani_Tails).l,a1
  10. Tails_Animate_2:
  11.         moveq   #0,d0
  12.         move.b  obAnim(a0),d0
  13.         cmp.b   obNextAni(a0),d0 ; is animation set to restart?
  14.         beq.s   @do     ; if not, branch
  15.         move.b  d0,obNextAni(a0) ; set to "no restart"
  16.         clr.b   obAniFrame(a0) ; reset animation
  17.         clr.b   obTimeFrame(a0) ; reset frame duration
  18.         bclr    #staPush,obStatus(a0) ; clear pushing flag
  19.  
  20.     @do:
  21.         add.w   d0,d0
  22.         adda.w  (a1,d0.w),a1    ; jump to appropriate animation script
  23.         move.b  (a1),d0
  24.         bmi.s   @walkrunroll    ; if animation is walk/run/roll/jump, branch
  25.         move.b  obStatus(a0),d1
  26.         andi.b  #1,d1
  27.         andi.b  #$FC,obRender(a0)
  28.         or.b    d1,obRender(a0)
  29.         subq.b  #1,obTimeFrame(a0) ; subtract 1 from frame duration
  30.         bpl.s   @delay      ; if time remains, branch
  31.         move.b  d0,obTimeFrame(a0) ; load frame duration
  32.  
  33.     @loadframe:
  34.         moveq   #0,d1
  35.         move.b  obAniFrame(a0),d1   ; load current frame number
  36.         move.b  1(a1,d1.w),d0       ; read sprite number from script
  37.         cmp.b   #$FD,d0             ; MJ: is it a flag from FD to FF?
  38.         bhs     @end_FF             ; MJ: if so, branch to flag routines
  39.  
  40.     @next:
  41.         move.b  d0,obFrame(a0)  ; load sprite number
  42.         addq.b  #1,obAniFrame(a0) ; next frame number
  43.  
  44.     @delay:
  45.         rts
  46. ; ===========================================================================
  47.  
  48. @end_FF:
  49.         addq.b  #1,d0       ; is the end flag = $FF ?
  50.         bne.s   @end_FE     ; if not, branch
  51.         clr.b   obAniFrame(a0) ; restart the animation
  52.         move.b  1(a1),d0    ; read sprite number
  53.         bra.s   @next
  54. ; ===========================================================================
  55.  
  56. @end_FE:
  57.         addq.b  #1,d0       ; is the end flag = $FE ?
  58.         bne.s   @end_FD     ; if not, branch
  59.         move.b  2(a1,d1.w),d0   ; read the next byte in the script
  60.         sub.b   d0,obAniFrame(a0) ; jump back d0 bytes in the script
  61.         sub.b   d0,d1
  62.         move.b  1(a1,d1.w),d0   ; read sprite number
  63.         bra.s   @next
  64. ; ===========================================================================
  65.  
  66.     @end_FD:
  67.         addq.b  #1,d0       ; is the end flag = $FD ?
  68.         bne.s   @end        ; if not, branch
  69.         move.b  2(a1,d1.w),obAnim(a0) ; read next byte, run that animation
  70.  
  71.     @end:
  72.         rts
  73. ; ===========================================================================
  74.  
  75.     @walkrunroll:
  76.         subq.b  #1,obTimeFrame(a0) ; subtract 1 from frame duration
  77.         bpl.s   @delay      ; if time remains, branch
  78.         addq.b  #1,d0       ; is animation walking/running?
  79.         bne.w   @rolljump   ; if not, branch
  80.         moveq   #0,d1
  81.         move.b  obAngle(a0),d0  ; get Tails's angle
  82.         bmi.s   @ble            ; better handling of angles
  83.         beq.s   @ble
  84.         subq.b  #1,d0
  85.  
  86.     @ble:
  87.         move.b  obStatus(a0),d2
  88.         andi.b  #1,d2       ; is Tails mirrored horizontally?
  89.         bne.s   @flip       ; if yes, branch
  90.         not.b   d0      ; reverse angle
  91.  
  92.     @flip:
  93.         addi.b  #$10,d0     ; add $10 to angle
  94.         bpl.s   @noinvert   ; if angle is $0-$7F, branch
  95.         moveq   #3,d1
  96.  
  97.     @noinvert:
  98.         andi.b  #$FC,obRender(a0)
  99.         eor.b   d1,d2
  100.         or.b    d2,obRender(a0)
  101.         btst    #staPush,obStatus(a0)   ; is Tails pushing something?
  102.         bne.w   @push       ; if yes, branch
  103.  
  104.         lsr.b   #4,d0       ; divide angle by $10
  105.         andi.b  #6,d0       ; angle must be 0, 2, 4 or 6
  106.         move.w  obInertia(a0),d2 ; get Tails's speed
  107.         bpl.s   @nomodspeed
  108.         neg.w   d2      ; modulus speed
  109.  
  110.     @nomodspeed:
  111.         move.b  d0,d3
  112.         add.b   d3,d3
  113.         add.b   d3,d3
  114.         lea (TailAni_Walk).l,a1
  115.  
  116.         cmpi.w  #$600,d2        ; is Tails going pretty fast?
  117.         bcs.s   @speedselected      ; if not, branch
  118.         lea (TailAni_Run).l,a1
  119.         move.b  d0,d1
  120.         lsr.b   #1,d1
  121.         add.b   d1,d0
  122.         add.b   d0,d0
  123.         move.b  d0,d3
  124.  
  125.         cmpi.w  #$700,d2        ; is Tails going really fast?
  126.         bcs.s   @speedselected      ; if not, branch
  127.         lea (TailAni_Dash).l,a1
  128.  
  129.     @speedselected:
  130.         neg.w   d2
  131.         addi.w  #$800,d2
  132.         bpl.s   @belowmax
  133.         moveq   #0,d2       ; max animation speed
  134.  
  135. ; Previous code... I'm guessing this didn't work either?
  136. ; Based on the code I used for Sonic
  137. ;   @nomodspeed:
  138. ;       lea     (TailAni_Dash).l,a1 ; use Dashing animation
  139. ;       cmpi.w  #$A00,d2    ; is Tails at Dashing speed?
  140. ;       bcc.s   @running    ; if yes, branch
  141. ;
  142. ;       lea     (TailAni_Run).l,a1 ; use running    animation
  143. ;       cmpi.w  #$600,d2    ; is Tails at running speed?
  144. ;       bcc.s   @running    ; if yes, branch
  145. ;
  146. ;       lea     (TailAni_Walk).l,a1 ; use walking animation
  147. ;       move.b  d0,d1
  148. ;       lsr.b   #1,d1
  149. ;       add.b   d1,d0
  150.  
  151. ;   @running:
  152. ;       add.b   d0,d0
  153. ;       move.b  d0,d3
  154. ;       neg.w   d2
  155. ;       addi.w  #$800,d2
  156. ;       bpl.s   @belowmax
  157. ;       moveq   #0,d2       ; max animation speed
  158. ; ----- Previous code ended
  159.  
  160.     @belowmax:
  161.         lsr.w   #8,d2
  162.         move.b  d2,obTimeFrame(a0)  ; modify frame duration
  163.         bsr.w   @loadframe
  164.         add.b   d3,obFrame(a0)      ; modify frame number
  165.         rts
  166. ; ===========================================================================
  167.  
  168. @rolljump:
  169.         addq.b  #1,d0       ; is animation rolling/jumping?
  170.         bne.s   @push       ; if not, branch
  171.         move.w  obInertia(a0),d2 ; get Tails's speed
  172.         bpl.s   @nomodspeed2
  173.         neg.w   d2
  174.  
  175.     @nomodspeed2:
  176.         lea     (TailAni_Roll2).l,a1 ; use fast animation
  177.         cmpi.w  #$600,d2    ; is Tails moving fast?
  178.         bcc.s   @rollfast   ; if yes, branch
  179.         lea     (TailAni_Roll).l,a1 ; use slower    animation
  180.  
  181.     @rollfast:
  182.         neg.w   d2
  183.         addi.w  #$400,d2
  184.         bpl.s   @belowmax2
  185.         moveq   #0,d2
  186.  
  187.     @belowmax2:
  188.         lsr.w   #8,d2
  189.         move.b  d2,obTimeFrame(a0) ; modify frame duration
  190.         move.b  obStatus(a0),d1
  191.         andi.b  #1,d1
  192.         andi.b  #$FC,obRender(a0)
  193.         or.b    d1,obRender(a0)
  194.         bra.w   @loadframe
  195. ; ===========================================================================
  196.  
  197. @push:
  198.         move.w  obInertia(a0),d2 ; get Tails's speed
  199.         bmi.s   @negspeed
  200.         neg.w   d2
  201.  
  202.     @negspeed:
  203.         addi.w  #$800,d2
  204.         bpl.s   @belowmax3 
  205.         moveq   #0,d2
  206.  
  207.     @belowmax3:
  208.         lsr.w   #6,d2
  209.         move.b  d2,obTimeFrame(a0) ; modify frame duration
  210.         lea     (TailAni_Push).l,a1
  211.         move.b  obStatus(a0),d1
  212.         andi.b  #1,d1
  213.         andi.b  #$FC,obRender(a0)
  214.         or.b    d1,obRender(a0)
  215.         bra.w   @loadframe
  216.  
  217. ; End of function Tails_Animate
Advertisement
Add Comment
Please, Sign In to add comment