Submitted by Steve Fewell
Description:
On entry to the COS routine, the carry flag will be set - this indicates that the Cosine result is required (a clear carry
flag indicates that the Sine result is required!).
Store the 6502 flags to the 6502 stack, so that the carry flag can be checked later.
Call routine &A93A to obtain the Floating-Point argument and calculate the Sine or Cosine value (the value returned
will be either COS or SIN - depending on the value of the Floating-Point argument.
A90E | 008 | 08 | PHP | |
A90F | : | 032 058 169 | 20 3A A9 | JSR &A93A Get value and calculate Sine or Cosine wave |
A912 | ( | 040 | 28 | PLP |
A913 | 144 002 | 90 02 | BCC 2 --> &A917 | |
A915 | I | 230 073 | E6 49 | INC &49 |
A917 | I | 165 073 | A5 49 | LDA &49 |
A919 | 137 002 | 89 02 | BIT#&02 | |
A91B | 240 006 | F0 06 | BEQ 6 --> &A923 | |
A91D | # | 032 035 169 | 20 23 A9 | JSR &A923 |
A920 | L | 076 202 172 | 4C CA AC | JMP &ACCA Compliment FWA value [FWA=-FWA] |
A923 | J | 074 | 4A | LSR A |
A924 | 176 003 | B0 03 | BCS 3 --> &A929 | |
A926 | 169 255 | A9 FF | LDA#&FF | |
A928 | ` | 096 | 60 | RTS |
A929 | 032 017 165 | 20 11 A5 | JSR &A511 Store FWA to &046C & set argp=&046C | |
A92C | 032 166 166 | 20 A6 A6 | JSR &A6A6 Multiply the FWA by argp [i.e. &046C] | |
A92F | 169 146 | A9 92 | LDA#&92 | |
A931 | 032 139 165 | 20 8B A5 | JSR &A58B Set argp to &BF00 + A | |
A934 | 032 138 166 | 20 8A A6 | JSR &A68A Floating-Point Subtraction [FWA=argp-FWA] | |
A937 | L | 076 184 167 | 4C B8 A7 | JMP &A7B8 Floating-point Square Root [FWA = SQRT(FWA)] |
A93A | 032 218 150 | 20 DA 96 | JSR &96DA Get and Check Float (convert if Int) | |
A93D | 0 | 165 048 | A5 30 | LDA &30 |
A93F | 201 152 | C9 98 | CMP#&98 | |
A941 | j | 176 106 | B0 6A | BCS 106 --> &A9AD 'Accuracy lost' error |
A943 | 032 017 165 | 20 11 A5 | JSR &A511 Store FWA to &046C & set argp=&046C | |
A946 | 032 137 165 | 20 89 A5 | JSR &A589 Set argp to &BF2E | |
A949 | 032 224 164 | 20 E0 A4 | JSR &A4E0 Unpack (&4A, &4B) variable to FWB | |
A94C | . | 165 046 | A5 2E | LDA &2E |
A94E | ; | 133 059 | 85 3B | STA &3B |
A950 | < | 198 060 | C6 3C | DEC &3C |
A952 | 032 146 166 | 20 92 A6 | JSR &A692 FWA = FWA + FWB (PI/4) | |
A955 | 3 | 169 051 | A9 33 | LDA#&33 |
A957 | 032 212 169 | 20 D4 A9 | JSR &A9D4 Multiply FWA by &BF33 (0.636619772 - 2/PI) | |
A95A | 032 195 150 | 20 C3 96 | JSR &96C3 Convert Float to Integer | |
A95D | I | 133 073 | 85 49 | STA &49 |
A95F | + | 005 043 | 05 2B | ORA &2B |
A961 | , | 005 044 | 05 2C | ORA &2C |
A963 | ( | 240 040 | F0 28 | BEQ 40 --> &A98D |
A965 | 032 137 129 | 20 89 81 | JSR &8189 Convert Integer value (IWA) to Floating-Point (FWA) | |
A968 | q | 169 113 | A9 71 | LDA#&71 |
A96A | 032 019 165 | 20 13 A5 | JSR &A513 Store FWA to &047B | |
A96D | $ | 169 036 | A9 24 | LDA#&24 |
A96F | 032 212 169 | 20 D4 A9 | JSR &A9D4 Multiply FWA by &BF24 (-1.57080078) | |
A972 | 032 146 165 | 20 92 A5 | JSR &A592 Set argp to &046C | |
A975 | 032 141 166 | 20 8D A6 | JSR &A68D Floating-Point Addition [FWA=argp+FWA] | |
A978 | 032 025 165 | 20 19 A5 | JSR &A519 Store FWA to argp address (&4A-&4B) | |
A97B | q | 169 113 | A9 71 | LDA#&71 |
A97D | ; | 032 059 165 | 20 3B A5 | JSR &A53B Load FWA from variable at &0400 + A (i.e. &0471) |
A980 | ) | 169 041 | A9 29 | LDA#&29 |
A982 | 032 212 169 | 20 D4 A9 | JSR &A9D4 Multiply FWA by &BF29 (0.00000445445511) | |
A985 | 032 146 165 | 20 92 A5 | JSR &A592 Set argp to &046C | |
A988 | 032 141 166 | 20 8D A6 | JSR &A68D Floating-Point Addition [FWA=argp+FWA] | |
A98B | 128 003 | 80 03 | BRA 3 --> &A990 | |
A98D | 9 | 032 057 165 | 20 39 A5 | JSR &A539 Load FWA from &046C |
A990 | 032 013 165 | 20 0D A5 | JSR &A50D Store FWA to &0476 and set argp to &0476 | |
A993 | 032 166 166 | 20 A6 A6 | JSR &A6A6 Multiply the FWA by argp [i.e. &0476] | |
A996 | t | 162 116 | A2 74 | LDX#&74 |
A998 | 169 146 | A9 92 | LDA#&92 | |
A99A | 160 002 | A0 02 | LDY#&02 | |
A99C | a | 032 097 168 | 20 61 A8 | JSR &A861 Evaluate continued-fraction expansion series |
A99F | v | 169 118 | A9 76 | LDA#&76 |
A9A1 | 160 004 | A0 04 | LDY#&04 | |
A9A3 | K | 132 075 | 84 4B | STY &4B |
A9A5 | J | 133 074 | 85 4A | STA &4A |
A9A7 | 032 166 166 | 20 A6 A6 | JSR &A6A6 Multiply the FWA by argp [i.e. &0400 + A] | |
A9AA | 169 255 | A9 FF | LDA#&FF | |
A9AC | ` | 096 | 60 | RTS |