From b6fca6682fc6cf6bb0ad2196f6edaea52f74e13e Mon Sep 17 00:00:00 2001 From: Svjatoslav Agejenko Date: Sun, 23 Feb 2025 01:01:14 +0200 Subject: [PATCH] Improve code readability --- Math/Truth table calculator/truth.bas | 146 ++++++++++++++------------ index.org | 7 +- 2 files changed, 85 insertions(+), 68 deletions(-) diff --git a/Math/Truth table calculator/truth.bas b/Math/Truth table calculator/truth.bas index 6ecf0f8..204c161 100755 --- a/Math/Truth table calculator/truth.bas +++ b/Math/Truth table calculator/truth.bas @@ -23,7 +23,7 @@ ' AND ( Keyboard shortcut: 4 ) ' NOT ( Keyboard shortcut: 5 ) -DECLARE SUB rmslg (x1!, x3!, l!) +DECLARE SUB removeRedundancies (startIndex!, endIndex!, removalCount!) DECLARE SUB getP (a!, b!) DECLARE SUB movM (x1!, n!) DECLARE SUB lihts (x1, x2, l) @@ -176,14 +176,14 @@ m = c - x1 + 1 END SUB SUB lihts (x1, x2, l) -' Removes redundant parentheses from the logical expression -rmslg x1, x2, l1 -l = l1 -'BEEP -prnp = prnp + 1 -FOR a = x1 TO x2 - l - prn a, 0, 13, 1, CHR$(tehe(a)) -NEXT a + ' Removes redundant parentheses from the logical expression and marks how many were removed + removeRedundancies x1, x2, l1 + l = l1 + 'BEEP + prnp = prnp + 1 + FOR a = x1 TO x2 - l + prn a, 0, 13, 1, CHR$(tehe(a)) + NEXT a END SUB SUB mov (x1, n) @@ -246,62 +246,74 @@ a$ = INPUT$(1) END SUB SUB prn (x, y, c, c1, a$) -' Prints characters to the screen in a specific location and color -x1 = x * 8 -y1 = (y + prnp) * 8 - -FOR b = 1 TO LEN(a$) - LINE (x1, y1)-(x1 + 7, y1 + 7), c1, BF - d = ASC(RIGHT$(LEFT$(a$, b), 1)) - IF d > 122 THEN GOTO 22 - FOR y2 = 0 TO 7 - FOR x2 = 0 TO 7 - c2 = font(x2, y2, d) - IF c2 > 0 THEN PSET (x1 + x2, y1 + y2), c - NEXT x2 - NEXT y2 - 22 - x1 = x1 + 8 -NEXT b + ' Prints characters to the screen at location (x,y) with color c, background c1 + x1 = x * 8 + y1 = (y + prnp) * 8 + + FOR b = 1 TO LEN(a$) + LINE (x1, y1)-(x1 + 7, y1 + 7), c1, BF + d = ASC(RIGHT$(LEFT$(a$, b), 1)) + IF d > 122 THEN GOTO 22 + FOR y2 = 0 TO 7 + FOR x2 = 0 TO 7 + c2 = font(x2, y2, d) + IF c2 > 0 THEN PSET (x1 + x2, y1 + y2), c + NEXT x2 + NEXT y2 +22 x1 = x1 + 8 + NEXT b END SUB -SUB rmslg (x1, x3, l) -' Removes redundant parentheses from the logical expression -x2 = x3 -l2 = 0 +SUB removeRedundancies (startIndex, endIndex, removalCount) + ' This procedure scans for parentheses that can be safely removed + ' without changing the logic of the expression, then removes them. -a = x1 -26 -IF tehe(a) = 40 THEN - IF a = x1 THEN p1 = 100 ELSE getP tehe(a - 1), p1 - c = a - d = 1 - p2 = 0 - 25 - c = c + 1 - IF tehe(c) = 40 THEN d = d + 1 - IF tehe(c) = 41 THEN d = d - 1 - IF d = 1 THEN - IF (tehe(c) > 0) AND (tehe(c) <= 5) THEN - getP tehe(c), b - IF b > p2 THEN p2 = b + DIM currentEnd, parenthesesCount + currentEnd = endIndex + parenthesesCount = 0 + + a = startIndex +26 IF tehe(a) = 40 THEN + ' We found an opening parenthesis. Now let's see if it can be removed. + IF a = startIndex THEN p1 = 100 ELSE getP tehe(a - 1), p1 + + c = a + d = 1 + p2 = 0 + +25 c = c + 1 + IF tehe(c) = 40 THEN d = d + 1 + IF tehe(c) = 41 THEN d = d - 1 + + ' Once d returns to 1, we are back to one level of parentheses, + ' meaning we can check operator priority inside. + IF d = 1 THEN + IF (tehe(c) > 0) AND (tehe(c) <= 5) THEN + getP tehe(c), b + IF b > p2 THEN p2 = b + END IF + END IF + + IF d > 0 THEN GOTO 25 + + IF c + 1 > currentEnd THEN p3 = 100 ELSE getP tehe(c + 1), p3 + + ' If the operator outside is higher priority than what's inside, + ' we can safely remove the parentheses. + IF (p1 > p2) AND (p3 >= p2) THEN + movM c, 1 + movM a, 1 + parenthesesCount = parenthesesCount + 2 + currentEnd = currentEnd - 2 + a = a - 1 END IF END IF - IF d > 0 THEN GOTO 25 - IF c + 1 > x2 THEN p3 = 100 ELSE getP tehe(c + 1), p3 - - IF (p1 > p2) AND (p3 >= p2) THEN - movM c, 1 - movM a, 1 - l2 = l2 + 2 - x2 = x2 - 2 - a = a - 1 - END IF -END IF -a = a + 1 -IF a <= x2 THEN GOTO 26 -l = l2 + + a = a + 1 + IF a <= currentEnd THEN GOTO 26 + + removalCount = parenthesesCount END SUB SUB sist @@ -504,14 +516,16 @@ FOR a = x1 TO x2 NEXT a GOTO 9 + mkneg: -FOR c = 1 TO tehl - d = opr(oprm, c) - IF d = ASC("t") THEN d = ASC("v") ELSE d = ASC("t") - prn xloc(ngx), c, 4, 0, CHR$(d) - opr(oprm, c) = d -NEXT c -ng = 0 + ' NOT operation (negation) is applied to the current operand + FOR c = 1 TO tehl + d = opr(oprm, c) + IF d = ASC("t") THEN d = ASC("v") ELSE d = ASC("t") + prn xloc(ngx), c, 4, 0, CHR$(d) + opr(oprm, c) = d + NEXT c + ng = 0 RETURN 9 diff --git a/index.org b/index.org index 2902d06..55dd852 100644 --- a/index.org +++ b/index.org @@ -236,8 +236,8 @@ auto-apply it, here is how you can set it manually: 1. Edit file: : ~/.dosbox/dosbox-.conf -2. Modify *keyboardlayout* field as follows - : keyboardlayout=dv103 +2. Disable scancodes usage: + : usescancodes=false 3. Save the changes and restart DOSBox for the configuration to take effect. @@ -257,6 +257,9 @@ appear small. To make it bigger: 3. Save the changes and restart DOSBox for the configuration to take effect. +4. If scaling did not work, set output to opengl: + : output=opengl + *** Exit mouse capture DOSBox detects when a game uses mouse control. When you click on the -- 2.20.1