::::::::::::::::::::
:: CORDIC demo 16 ::
::::::::::::::::::::

16 byte education intro for ZX Spectrum 16k

 Code: Busy soft
 Create: 26.01.2025
 Release: LoveByte 2025

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


It is based on 8 byte routine from CORDIC demo 8
but the addtional preface is added to serve
the case of X < Y.

In this case, X and Y are swapped :)


Source code:

 Input: C = coordinate X
        B = coordinate Y

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

       ld      a,c
       cp      b
       jr      nc,L1
       ld      c,b
       ld      b,a

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

Now whole routine takes 14 bytes length.

The condition X >= Y disappeared, but all next conditions are still valid:

  (X^2+Y^2) < 65536 ... Since result is 8 bit only, we must make sure to not produce overflow
  X > 0 ........\____ Any coordinate can be zero (then result is directly another coordinate)
  Y > 0 ......../     but due to using DJNZ, zero means 256 iterations and it is still not good.