Advertisement
NovaYoshi

SpeedAngle2Offset for asm6

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