::::::::::::::::::::
:: CORDIC demo 64 ::
::::::::::::::::::::
64 byte education intro for ZX Spectrum 48k
Code: Busy soft
Create: 28.01.2025
Release: LoveByte 2025
This intro uses simplified CORDIC algorithm
to create dithered monochrom concentric circles.
For each m from set {8,16,32,64,128,256} do:
FOR y = 175 TO 1
FOR x = 0 TO 255
LET distance = SQR((X-128)^2+(Y-88)^2)
IF distance MOD m > RND * m
THEN pixel is white
ELSE pixel is black
The refresh register is used as RND.
Since the quality of these random numbers
are not so high, many artefacts appear in circles.
There is needed to determine distane between
processed point [X,Y] and the middle of screen [128,88]:
distance = SQR(dx^2+dy^2)
where dx = X - 128
dy = Y - 88
Since there is a mandatory condition X > 0 and Y > 0,
coordinates cannot be negative, so we must compute
absolute value of dx and dy. And for sure,
we decided increment coordinate in case of zero.
Source code of evaluation SQR(dx^2+dy^2):
Input: C = coordinate X
B = coordinate Y
ld a,b ;; dY processing
sub #58 ;; Convert interval 1..175 to -87..0..+87
jr nc,skipy ;; If not negative result, skip the cpl
cpl ;; cpl:inc = neg changes the signum of value
skipy: inc a ;; but inc only incremens positive value to avoid zero
ld b,a ;; Result dY interval will be symmetrical +87..1,1..+87
ld a,c ;; dX processing
sub #80 ;; Convert interval 0..255 to -128..0..+127
jr nc,skipx ;; If not negative result, skip the cpl
cpl ;; cpl:inc = neg changes the signum of value
skipx: inc a ;; but inc only incremens positive value to avoid zero
ld c,a ;; Result dX interval will be symmetrical +128..1,1..+128
cp b
jr nc,L1 ;; If X < Y
ld c,b ;; Then swap X and Y
ld b,a
ld a,c ;; Simplified CORDIC
L1: sub b
jr nc,L2
inc c
add c
L2: djnz L1
Output: C = distance = SQR(dx^2+dy^2)