Cordic Demo 256 by Busysoft
::::::::::::::::::::: :: CORDIC demo 256 :: ::::::::::::::::::::: 256 byte education intro for ZX Spectrum 48k + AY Code: Busy soft Music: Noro soft Create: 08.02.2025 Release: LoveByte 2025 This intro draws concentric circles by using simplified CORDIC algoritm and then play simple color music on these circles. Draw init screen: FOR y = 175 TO 0 FOR x = 0 TO 255 LET distance = SQR((X-128)^2+(Y-88)^2) LET circle_index = INT(d/10) PLOT INVERSE circle_index MOD 2; x,y Store pixel[x,y] into set of circle[circle_index] Play color music: For every note from music: circle_base = F(note_pitch) FOR i = 7 TO 1 LET circle_index = circle_base + 7 - i Set all pixes of cicle[circle_index] to color i Every 40 ms do: For each pixel on screen do: IF color > 0 THEN LET color = color - 1 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 0..175 to -88..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 ]