pouët.net

Cordic Demo 8 by Busysoft

:::::::::::::::::::
:: CORDIC demo 8 ::
:::::::::::::::::::

8b education intro for ZX Spectrum 16k

  Code: Busy soft
  Create: 25.01.2025
  Release: LoveByte 2025

This intro shows simplified CORDIC algorithm
intended for computing size of two-dimensed vector.

Source of the 8 byte routine

  Input: C = coordinate X
         B = coordinate Y

 Output: C = result = SQR(X^2+Y^2)

        ld      a,c
    L1: sub     b
        jr      nc,L2
        inc     c
        add     c
    L2: djnz    L1

 Register C contains X coordinate, what are increased by rotating vector or moving point on the circle.
 Register B is counter of iterations or successive rotations, it is initialized to coordinate Y.
 Register A holds bresenham's iterator used for computation. At begin, it is initialized to coordinate X.

To proper working of this simplified routine, a few mandatory conditions must be fulfilled:

   (X^2+Y^2) < 65536 ... Since result is 8 bit only, we must make sure to not produce overflow
   Y <= X .............. Number of iterations cannot be bigger than input coordinate X
   Y > 0 ............... Number of iterations in priciple can be zero (then result is directly X)
                         but due to using DJNZ, zero means 256 iterations and it is not good