]> git.sur5r.net Git - cc65/blob - libsrc/common/cc65_cos.s
Added fixpoint sine and cosine functions.
[cc65] / libsrc / common / cc65_cos.s
1 ;
2 ; Fixed point cosine function.
3 ;
4 ; Returns the cosine for the given argument as angular degree.
5 ; Valid argument range is 0..360
6 ;
7 ;
8 ; Ullrich von Bassewitz, 2009-10-29
9 ;
10
11         .export         _cc65_cos
12
13         .import         _cc65_sin
14
15
16
17 ; ---------------------------------------------------------------------------
18 ;
19
20 .code
21
22 .proc   _cc65_cos         
23
24 ; cos(x) = sin(x+90)
25
26         clc
27         adc     #90
28         bcc     L1
29         inx
30
31 ; If x is now larger than 360, we need to subtract 360.
32
33 L1:     cpx     #>360
34         bne     L2
35         cmp     #<360
36 L2:     bcc     L4
37
38         sbc     #<360
39         bcs     L3
40         dex
41 L3:     dex
42
43 L4:     jmp     _cc65_sin
44
45
46 .endproc
47
48