******************************************************** * ** NAME: SinCos - get sin and cos for a value from a table * * Purpose: * * Entry: A[B] is [0,255], an angle to look up sin/cos for, * where there are 256 divisions of the circle * * Exit: A[B] is sin of angle, C[B] is cos, in 1.7 Fixed point signed number, * so the output range is [-1,+0.9928] (values are clamped) * * Alters: C[A], A[B], D0 * * Calls: * * Stack Levels: 0 * * ******************************************************** * table for the sin/cos stuff, stored for angles 0 to 63 (where 0 is 0 radians and 64 is Pi/2 radians) * stored as cos, then sin, each entry a byte, stored in 1.7 fixed point * todo - cut table in half, use 0->45 degrees, and symmetry NIBHEX F700F730F760F790F7D0F701F731E761E791D7C1C7F1B722A752A78297B277E2 NIBHEX 67135743477327A317C3F6F3E624C644A67496A476C456F436151645F565D585 NIBHEX B5B585D565F545161536F456C476A49674A644C624E6F3F6C317A32773474357 NIBHEX 1367E277B29782A752A722B7F1C7C1D791E761E731F701F7D0F790F760F730F7 * old table of 32 values * NIBHEX F700F760F7D0F731E791C7F1A75297B26713477317C3E624A67476C43615F565 * NIBHEX B5B565F51536C47674A624E6C31773471367B29752A7F1C791E731F7D0F760F7 SinCos C=PC * get program counter AD0EX * save A[A] LA(5) 2*(128+2) * this far back in table in nibbles C=C-A A * table pointer value CD0EX * D0 now points properly to start of table, C is original A A=C B * get value back LC(5) 63 * mask C=C&A A * C is lookup value [0,63] AD0EX C=C+C A * value in nibbles C=C+C A * value (2 bytes per entry) A=A+C A * look at this nibble offset (sin, cos each 2 nibbles, interleaved) AD0EX * D0 now points to proper entry, A is original value C=DAT0 B * get cos value D0=D0+ 2 * point to sin entry, and check quadrants ?ABIT=1 7 GOYES Q34 * quad 3,4 ?ABIT=1 6 GOYES Q2 * quadrant 2 A=DAT0 B * sin value, from quadrant 1 RTN Q2 A=DAT0 B * sin value ACEX B * swap values C=-C B * cos is negative here RTN Q34 ?ABIT=1 6 GOYES Q4 C=-C B * we're in Q3, sin and cos are negative A=DAT0 B A=-A B RTN Q4 A=DAT0 B ACEX B * swap values A=-A B RTN * end file - SinCos.s