Advertisement
Iso_Kilo

Sonic 1 - Ray Main Glide Code

Aug 13th, 2019
2,484
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. PlayerControl   equ $FFFFF602
  2. Joypad      equ $FFFFF604
  3.  
  4. Held        equ 0
  5. Press       equ 1
  6.  
  7. iStart      equ     7
  8. iA      equ     6
  9. iC      equ     5
  10. iB      equ     4
  11. iRight      equ     3
  12. iLeft       equ     2
  13. iDown       equ     1
  14. iUp     equ     0
  15.  
  16. Start       equ     1<<7
  17. A       equ     1<<6
  18. C       equ     1<<5
  19. B       equ     1<<4
  20. Right       equ     1<<3
  21. Left        equ     1<<2
  22. Down        equ     1<<1
  23. Up      equ     1
  24.  
  25. ; =============================================================
  26. ; Macro to check button presses
  27. ; Arguments:    1 - buttons to check
  28. ;       2 - bitfield to check
  29. ; -------------------------------------------------------------
  30. tpress  macro
  31.     move.b  (\2+1),d0
  32.     andi.b  #\1,d0
  33.     endm
  34.  
  35. ; =============================================================
  36. ; Macro to check if buttons are held
  37. ; Arguments:    1 - buttons to check
  38. ;       2 - bitfield to check
  39. ; -------------------------------------------------------------
  40. theld   macro
  41.     move.b  \2,d0
  42.     andi.b  #\1,d0
  43.     endm
  44.  
  45. GlideCheck:
  46.         cmpi.b  #$02, ($FFFFFFF7).w ; glide state equal to 2?
  47.         beq.w   Return_JMP  ; if yes, branch
  48.         btst    #7,$22(a0)      ; was Glide flag set?
  49.         bne.w   GlideLeft       ; if yes, branch
  50.         cmpi.b  #2,$1C(a0)          ; is player rolling?
  51.         bne.w   Return_JMP  ; if no, branch
  52.         tpress  A+B+C,(PlayerControl)   ; is A, B or C pressed?
  53.         beq.w   Return_JMP      ; if not, branch
  54.         move.b  #$00, ($FFFFFFF7).w ; set glide state to 0
  55.         bset    #7,$22(a0)      ; set Glide flag
  56.         bra.w GlideLeft
  57.  
  58. Return_JMP:
  59.         jmp Return
  60.  
  61. GlideLeft:
  62.         theld   A+B+C,(PlayerControl)   ; A, B or C held?
  63.         beq.w   GlideEnd        ; if not, branch
  64.  
  65.         move.w  $12(a0),d0  ; load Y-velocity
  66.         move.w  $10(a0),d1  ; load X-velocity
  67.  
  68.         btst    #0,$22(a0)      ; is Player facing right?
  69.         beq.w   GlideRight  ; if yes, branch
  70.  
  71.         btst    #iRight,(Joypad|Press)  ; is right pressed?
  72.         beq.w   GlideLeft2  ; if not, branch
  73.         cmpi.w  #$100,$12(a0)   ; is Y-velocity greater than 100?
  74.         blt.w       GlideLeftUp ; if not, branch
  75.         tst.b       ($FFFFFFF7).w   ; glide state equal to 0?
  76.         beq.w       GlideLeftUp ; if yes, branch
  77.  
  78.         move.b  #$00, ($FFFFFFF7).w ; set glide state to 0
  79.  
  80.         cmpi.w  #$0,$10(a0) ; is X-velocity 0?
  81.         beq.w       GlideLeftUp ; if yes, branch
  82.  
  83.         divs.w  #$2,d0
  84.         add.w       #$100,d0
  85.         neg.w   d0  ;negate Y-velocity
  86.  
  87. GlideLeft2:
  88.         btst    #iLeft,(PlayerControl|Held).w   ; is Left being pressed?
  89.         beq.w   GlideLeftDown       ; if not, branch
  90.         move.b  #$01, ($FFFFFFF7).w ; set glide state to 1
  91.  
  92. GlideLeftDown:
  93.         cmpi.b  #$00, ($FFFFFFF7).w ; glide state equal to 0?
  94.         beq.w   GlideLeftUp     ; if yes, branch
  95.         move.b  #$20,$1C(a0)    ; use down glide animation
  96.         add.w       #$18,d0
  97.         sub.w       #$2C,d1
  98.         bra.w   GlideLeftCalc1
  99.  
  100. GlideLeftUp:
  101.         move.b  #$1F,$1C(a0)    ; use up glide animation
  102.         add.w       #$04,d1
  103.         btst    #6,$22(a0)  ; is Sonic underwater?
  104.         bne.s   GlideLeftCalc1  ; if yes, branch
  105.         sub.w       #$20,d0
  106.  
  107. GlideLeftCalc1:
  108.         move.w  d1,$10(a0)
  109.         cmpi.w  #-$200,$10(a0)  ; is X-velocity greater than -200?
  110.         blt.w       GlideYCalc  ; if not, branch
  111.         move.w  #-$200,$10(a0)
  112.         bra.w       GlideYCalc
  113.  
  114. GlideRight:
  115.         btst    #iLeft,(Joypad|Press)   ; is left pressed?
  116.         beq.w   GlideRight2 ; if not, branch
  117.         cmpi.w  #$100,$12(a0)   ; is Y-velocity greater than 100?
  118.         blt.w       GlideRightUp    ; if not, branch
  119.         tst.b       ($FFFFFFF7).w   ; glide state equal to 0?
  120.         beq.w       GlideRightUp    ; if yes, branch
  121.  
  122.         move.b  #$00, ($FFFFFFF7).w ; set glide state to 0
  123.  
  124.         cmpi.w  #$0,$10(a0) ; is X-velocity 0?
  125.         beq.w       GlideRightUp    ; if yes, branch
  126.  
  127.         divs.w  #$2,d0
  128.         add.w       #$100,d0
  129.         neg.w   d0  ;negate Y-velocity
  130.  
  131. GlideRight2:
  132.         btst    #iRight,(PlayerControl|Held).w  ; is right being pressed?
  133.         beq.w   GlideRightDown      ; if not, branch
  134.         move.b  #$01, ($FFFFFFF7).w ; set glide state to 1
  135.  
  136. GlideRightDown:
  137.         cmpi.b  #$00, ($FFFFFFF7).w ; glide state equal to 0?
  138.         beq.w   GlideRightUp        ; if yes, branch
  139.         move.b  #$20,$1C(a0)    ; use down glide animation
  140.         add.w       #$18,d0
  141.         add.w       #$2C,d1
  142.         bra.w   GlideRightCalc1
  143.  
  144. GlideRightUp:
  145.         move.b  #$1F,$1C(a0)    ; use up glide animation
  146.         sub.w       #$04,d1
  147.         btst    #6,$22(a0)  ; is player underwater?
  148.         bne.s   GlideRightCalc1 ; if yes, branch
  149.         sub.w       #$20,d0
  150.  
  151. GlideRightCalc1:
  152.         move.w  d1,$10(a0)
  153.         cmpi.w  #$200,$10(a0)   ; is X-velocity less than 200?
  154.         bgt.w       GlideYCalc  ; if not, branch
  155.         move.w  #$200,$10(a0)
  156.  
  157. GlideYCalc:
  158.         move.w  d0,$12(a0)
  159.         cmpi.w  #-$800,$12(a0)  ; is Y-velocity less than -800?
  160.         bgt.w       Return  ; if not, branch
  161.         move.w  #-$800,$12(a0)
  162.         bra.w   Return
  163.  
  164. GlideEnd:
  165.         move.b  #$02, ($FFFFFFF7).w ; set glide state to 2
  166.         bclr    #7,$22(a0)      ; clear Glide flag
  167.         move.b  #$2,$1C(a0) ; use rolling animation
  168.         bset    #2,$22(a0)
  169.  
  170. Return:
  171.         rts
  172. ; End of function Ray_Glide
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement