83Plus:BCALLs:40D8

From WikiTI
Revision as of 20:19, 31 May 2006 by FloppusMaximus (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Synopsis

Official Name: ATan2Rad

BCALL Address: 40D8

Compute the arctangent of OP1 divided by OP2, placing the result in the correct quadrant according to the signs of its arguments.

Inputs

  • OP1 = Y coordinate
  • OP2 = X coordinate
  • D = 0 (see below)

Outputs

  • OP1 = angle in radians

Destroys

  • AF, BC, DE, HL
  • OP1-OP5

Comments

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.