Official Name: ATan2Rad
BCALL Address: 40D8
- OP1 = angle in radians
- AF, BC, DE, HL
The official documentation makes no mention of the effect of the D register; the initialization of D seems to have been left out accidentally. To obtain the documented behavior, D should be set to zero. In any case, D affects the output as follows:
- If D is between 60h and DFh, the inverse hyperbolic tangent is computed instead.
- Otherwise, if bit 5 of D is set, the answer will be returned in degrees or radians depending on the mode. If bit 5 is clear, the answer will always be returned in radians.
Furthermore, this routine also uses the low bits of D to encode the original octant. Specifically:
- If the input point is below the X-axis, 0Ch will be added to D.
- If it is left of the Y-axis, D will be XORed with 4.
- If it is closer to the Y-axis than to the X-axis, D will be ORed with 10h.
As a result, if the low bits of D are not initially zero, strange things will happen to the output octant.