Better code readability master
authorSvjatoslav Agejenko <svjatoslav@svjatoslav.eu>
Wed, 2 Jul 2025 18:12:10 +0000 (21:12 +0300)
committerSvjatoslav Agejenko <svjatoslav@svjatoslav.eu>
Wed, 2 Jul 2025 18:12:10 +0000 (21:12 +0300)
Networking/Digital data over analog audio channel/xi2msg.bas
QBasic tutorial/Group 2/02.bas
QBasic tutorial/Group 2/04.bas
QBasic tutorial/Group 2/11.bas
Simulation/Explosion/explode.bas

index 5b2bfaa..7c85c82 100644 (file)
@@ -5,7 +5,7 @@
 '
 ' Changelog:
 ' 2001, Initial version
-' 2024, Improved program readability using AI
+' 2024 - 2025, Improved program readability
 '
 ' Data is encoded in the audio by using frequency modulation.
 ' When decoding data, program locates peaks between waveforms.
@@ -35,7 +35,9 @@ DECLARE SUB byt (a)
 
 DIM SHARED file1$
 DIM SHARED file2$
-DIM SHARED buf(-100 TO 10000)
+
+' Contains the actual audio waveform samples
+DIM SHARED audioBuffer(-100 TO 10000)
 DIM SHARED bus AS STRING * 1000
 DIM SHARED bufi
 DIM SHARED bg
@@ -43,7 +45,9 @@ DIM SHARED sm
 DIM SHARED beg
 DIM SHARED wai
 DIM SHARED old2
-DIM SHARED stat(1 TO 10)
+
+' Statistical Analysis Array (contains measured peak distances)
+DIM SHARED statisticalArray(1 TO 10)
 DIM SHARED statl
 DIM SHARED aver
 DIM SHARED byte AS STRING * 1
@@ -67,7 +71,7 @@ FOR a = 1 TO 1000
     bufi = bufi + 1
     c = ASC(b$)
     IF c > 127 THEN c = c - 255
-    buf(bufi) = c
+    audioBuffer(bufi) = c
 NEXT a
 IF (EOF(2) = 0) AND (bufi < 8000) THEN GOTO 2
 anal
@@ -90,8 +94,8 @@ SUB anal
 
         ' Plot the buffer data points
         FOR b = 0 TO 200
-            PSET (b, buf(b + a - 101) + 300), 0
-            PSET (b, buf(b + a - 100) + 300), 14
+            PSET (b, audioBuffer(b + a - 101) + 300), 0
+            PSET (b, audioBuffer(b + a - 100) + 300), 14
         NEXT b
 
         LINE (old2 - a + 100, 170)-(old2 - a + 100, 430), 0
@@ -99,7 +103,7 @@ SUB anal
         ' Calculate the average value of the buffer segment
         c = 0
         FOR b = a TO a + (avv - 1)
-            c = c + buf(b)
+            c = c + audioBuffer(b)
         NEXT b
         c = c / (avv / 2)
 
@@ -127,7 +131,7 @@ SUB anal
 
     ' Shift the buffer data to the left
     FOR a = bufi - (avv - 2) TO bufi
-        buf(a - (bufi - (avv - 2)) + 1) = buf(a)
+        audioBuffer(a - (bufi - (avv - 2)) + 1) = audioBuffer(a)
     NEXT a
 
     ' Update the starting index of the buffer
@@ -171,14 +175,14 @@ SUB byt (a)
     IF statl > 8 THEN
         statl = 1
         b = 0
-        IF stat(1) = 1 THEN b = b + 128
-        IF stat(2) = 1 THEN b = b + 64
-        IF stat(3) = 1 THEN b = b + 32
-        IF stat(4) = 1 THEN b = b + 16
-        IF stat(5) = 1 THEN b = b + 8
-        IF stat(6) = 1 THEN b = b + 4
-        IF stat(7) = 1 THEN b = b + 2
-        IF stat(8) = 1 THEN b = b + 1
+        IF statisticalArray(1) = 1 THEN b = b + 128
+        IF statisticalArray(2) = 1 THEN b = b + 64
+        IF statisticalArray(3) = 1 THEN b = b + 32
+        IF statisticalArray(4) = 1 THEN b = b + 16
+        IF statisticalArray(5) = 1 THEN b = b + 8
+        IF statisticalArray(6) = 1 THEN b = b + 4
+        IF statisticalArray(7) = 1 THEN b = b + 2
+        IF statisticalArray(8) = 1 THEN b = b + 1
 
         ' Print the byte value to the screen
         LOCATE 10, 69
@@ -208,7 +212,7 @@ SUB byt (a)
     ' Print the bit value to the screen
     LOCATE 10, 50 + (statl * 2)
 
-    stat(statl) = a
+    statisticalArray(statl) = a
 
     PRINT a
 
@@ -254,7 +258,7 @@ SUB pfo (f, t, it)
 
             IF statl > 10 THEN
                 FOR a = 1 TO 10
-                    aver = aver + stat(a)
+                    aver = aver + statisticalArray(a)
                 NEXT a
 
                 aver = aver * 1.5 / 10
@@ -267,7 +271,7 @@ SUB pfo (f, t, it)
             END IF
 
             ' Store the current frame index
-            stat(statl) = f - old2
+            statisticalArray(statl) = f - old2
         END IF
 
         ' Decode the bits if we are in the decoding state
@@ -278,7 +282,7 @@ SUB pfo (f, t, it)
                 statl = 0
 
                 FOR a = 1 TO 8
-                    stat(a) = 0
+                    statisticalArray(a) = 0
                 NEXT a
 
                 GOTO 4
index 39b2c4e..4495c79 100755 (executable)
@@ -1,14 +1,26 @@
-1\r
-s = s + 1       ' speed\r
-PRINT s; "x"\r
+' Simple Sound Sweep Program\r
 \r
-FOR a = 100 TO 1000 STEP s\r
-  SOUND a, .1\r
-NEXT a\r
+' Start label for infinite loop\r
+beginLoop:\r
 \r
-FOR a = 1000 TO 100 STEP -s\r
-  SOUND a, .1\r
-NEXT a\r
+' Increase speed on each pass - this controls how quickly frequencies change\r
+speed = speed + 1\r
 \r
-GOTO 1\r
+' Show current speed multiplier to user\r
+PRINT speed; "x"\r
 \r
+' Forward frequency sweep from 100Hz to 1000Hz\r
+FOR currentFrequency = 100 TO 1000 STEP speed\r
+  ' Create sound with current frequency for 0.1 seconds\r
+  ' SOUND format: SOUND frequency, duration\r
+  SOUND currentFrequency, .1\r
+NEXT currentFrequency\r
+\r
+' Reverse frequency sweep from 1000Hz to 100Hz\r
+FOR currentFrequency = 1000 TO 100 STEP -speed\r
+  ' Create sound with current frequency for 0.1 seconds\r
+  SOUND currentFrequency, .1\r
+NEXT currentFrequency\r
+\r
+' Jump back to beginning for continuous effect\r
+GOTO beginLoop\r
index a428f1e..2ef6a57 100755 (executable)
@@ -1,11 +1,13 @@
 CLS\r
 \r
-a$ = "-two-"\r
-PRINT a$\r
+' Initialize the string variable with "-two-"\r
+stringValue$ = "-two-"\r
+PRINT stringValue$\r
 \r
-a$ = a$ + "three"\r
-PRINT a$\r
-\r
-a$ = "one" + a$\r
-PRINT a$\r
+' Append "three" to the existing string\r
+stringValue$ = stringValue$ + "three"\r
+PRINT stringValue$\r
 \r
+' Prepend "one" to the string to form a complete sequence\r
+stringValue$ = "one" + stringValue$\r
+PRINT stringValue$\r
index 0831a84..ef910ae 100755 (executable)
@@ -1,10 +1,19 @@
+' Simple Character Extractor Program\r
+' This program takes user input and prints each character individually\r
+\r
 CLS\r
 \r
-INPUT "Enter some text:", t$\r
+' Get user input\r
+INPUT "Enter some text:", userInput$\r
+\r
+' Process each character in the input string\r
+FOR charPosition = 1 TO LEN(userInput$)\r
+  ' Get the left portion of the string up to current position\r
+  leftPortion$ = LEFT$(userInput$, charPosition)\r
 \r
-FOR i = 1 TO LEN(t$)\r
-  a$ = LEFT$(t$, i)\r
-  b$ = RIGHT$(a$, 1)\r
-  PRINT "letter:"; b$\r
-NEXT i\r
+  ' Extract the current character (rightmost character of left portion)\r
+  currentChar$ = RIGHT$(leftPortion$, 1)\r
 \r
+  ' Print the current character with label\r
+  PRINT "letter:"; currentChar$\r
+NEXT charPosition\r
index feb1258..ad6c53d 100755 (executable)
@@ -130,26 +130,22 @@ FOR y = 2 TO 99
     FOR x = 2 TO 99\r
         ' Update pressure based on speed in the x-direction.\r
         IF spdx(x, y) > 0 THEN\r
-            spdxp(x - 1, y) = ((press(x, y) * spdx(x - 1, y)) + (spdx(x, y) * spdx(x, y))) /\r
-                               (press(x, y) + spdx(x, y)) - spdx(x - 1, y)\r
+            spdxp(x - 1, y) = ((press(x, y) * spdx(x - 1, y)) + (spdx(x, y) * spdx(x, y))) / (press(x, y) + spdx(x, y)) - spdx(x - 1, y)\r
         END IF\r
 \r
         ' Update pressure based on speed in the y-direction.\r
         IF spdy(x, y) > 0 THEN\r
-            spdyp(x, y - 1) = ((press(x, y) * spdy(x, y - 1)) + (spdy(x, y) * spdy(x, y))) /\r
-                               (press(x, y) + spdy(x, y)) - spdy(x, y - 1)\r
+            spdyp(x, y - 1) = ((press(x, y) * spdy(x, y - 1)) + (spdy(x, y) * spdy(x, y))) / (press(x, y) + spdy(x, y)) - spdy(x, y - 1)\r
         END IF\r
 \r
         ' Handle negative speeds in the x-direction.\r
         IF spdx(x - 1, y) < 0 THEN\r
-            spdxp(x, y) = ((press(x, y) * spdx(x, y)) - (spdx(x - 1, y) * spdx(x - 1, y))) /\r
-                           (press(x, y) - spdx(x - 1, y)) - spdx(x, y)\r
+            spdxp(x, y) = ((press(x, y) * spdx(x, y)) - (spdx(x - 1, y) * spdx(x - 1, y))) / (press(x, y) - spdx(x - 1, y)) - spdx(x, y)\r
         END IF\r
 \r
         ' Handle negative speeds in the y-direction.\r
         IF spdy(x, y - 1) < 0 THEN\r
-            spdyp(x, y) = ((press(x, y) * spdy(x, y)) - (spdy(x, y - 1) * spdy(x, y - 1))) /\r
-                           (press(x, y) - spdy(x, y - 1)) - spdy(x, y)\r
+            spdyp(x, y) = ((press(x, y) * spdy(x, y)) - (spdy(x, y - 1) * spdy(x, y - 1))) / (press(x, y) - spdy(x, y - 1)) - spdy(x, y)\r
         END IF\r
     NEXT x\r
 NEXT y\r