Cordic Demo 128 by Busysoft
:::::::::::::::::::::
:: CORDIC demo 128 ::
:::::::::::::::::::::
128 byte education intro for ZX Spectrum 48k
Code: Busy soft
Create: 28.01.2025
Release: LoveByte 2025
This intro uses simplified CORDIC algorithm
to draw coloured concentric circles and then
make simple animation by shifting colors.
Draw init screen:
FOR y = 175 TO 0
FOR x = 0 TO 255
LET distance = SQR((X-128)^2+(Y-88)^2)
LET color = (d/10) MOD 8
Set pixel to this color
Make animation:
Every 40 ms do:
For each pixel do:
LET color=(color-1) MOD 8
For drawing init screen, 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)
[ back to the prod ]
