Advertisement
NovaYoshi

SpeedAngle2Offset

May 6th, 2016
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. .macro neg16 lo, hi
  2.   sec             ;Ensure carry is set
  3.   lda #0          ;Load constant zero
  4.   sbc lo          ;... subtract the least significant byte
  5.   sta lo          ;... and store the result
  6.   lda #0          ;Load constant zero again
  7.   sbc hi          ;... subtract the most significant byte
  8.   sta hi          ;... and store the result
  9. .endmacro
  10.  
  11. ; Calculates a horizontal and vertical speed from a speed and an angle
  12. ; input: A (speed) Y (angle, 0-31)
  13. ; output: 0,1 (X offset), 2,3 (Y offset)
  14. .proc SpeedAngle2Offset
  15. Angle = 4
  16. Speed = 5
  17.   sty Angle
  18.   sta Speed
  19.  
  20.   lda CosineTable,y
  21.   php         ; Save whether it's negative or positive
  22.   bpl :+      ; Take the absolute value
  23.   eor #255
  24.   add #1
  25. : ldy Speed
  26.   jsr mul8    ; Multiply the absolute value by the speed
  27.   sty 0       ; Write the offset
  28.   sta 1
  29.  
  30.   plp
  31.   bpl :+      ; If it was negative, make it negative again
  32.   neg16 0, 1
  33. :
  34.  
  35.   ldy Angle
  36.   lda SineTable,y
  37.   php        ; Save whether it's positive or negative
  38.   bpl :+     ; Take the absolute value
  39.   eor #255
  40.   add #1
  41. : ldy Speed
  42.   jsr mul8   ; Multiply the absolute value by the speed
  43.   sty 2
  44.   sta 3
  45.   plp
  46.   bpl :+     ; If it was negative, make it negative again
  47.   neg16 2, 3
  48. :
  49.   rts
  50. .endproc
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement