Linesum

Author(s): C. C. Stalder
Publication: Syntax
Pub Details: Syntax/Syntax ZX80 v5 n8 (Volume 5, Issue 8)
Date: August 1984
Pages: 8-11

Locating errors made in typing from printed listings is easy when they include a checksum for every statement, and you have Linesum loaded. It displays, line by line, any BASIC present with line numbers below 9000, & displays the sum of the line’s bytes. Add the line sums to get Syntactic Sum.

Linesum’s flexibility surfaces with use. You LOAD Linesum first, then after typing in a program line you RUN 9000 & use the edit option to fix errors or type another line before returning to Linesum. That way you check every program line as you type it. Use the quit option to free the computer to calculate, and reenter Linesum at the point you left it by typing GOTO SUM.

Long programs may be finished piecemeal: if you tire, “quit” & SAVE your partial program. LOAD it later & take up where you left off. If you get an inspiration and want to try a BASIC routine while it’s fresh in your mind, do it. Lines 9536-999 are your work area. Don’t even clean up: test programs in this area vanish when you erase Linesum. With a merge utility, you can type your new program, and only append Linesum if the Syntactic Sum indicates you have made a mistake.

Once you start Linesum do not use RUN until you are all finished with Linesum. Do GOTO SUM instead to avoid killing variables.

To make your copy, LOAD your Syntactic Sum tape, then type in Linesum. Don’t type the checksums or the GRAPHICS 5, they aren’t part of the program. Syntactic Sum at this point equals 35581. If you get a different number, find and correct any typing errors. Put your ZX/TS in FAST, then SAVE this version to a scratch tape.

Next, RUN Linesum on itself, verifying each line in turn. The Print option stops at each line–the Lprint option runs by itself.

Add 1 REM with 22 placeholders

   1 REM 1234567890123456789012

Next, RUN 9505, to load the MC (machine code) into the Line 1 REM. Enter all numbers on the POKE list, then a STOP to exit the loader. EDIT Line 1 to line number 9490.

   33   40   35  205  216    9   35   35
   35  235   42   12   64  167  237   82
  235   27  114   43  115  201

Now edit line 9325, changing 9999 to 9000. Linesum will no longer work on itself, but only on program lines below 9000. The new Syntactic Sum will be 38824. RUN linesum to get the result shown:

Linesum result for the machine code REM line (checksum 2594)
Linesum result for the machine code REM line (checksum 2594)

Delete line 1. SAVE the program to tape for future use. At this step, Syntactic Sum is 36230.

Leave Linesum loaded and type in the program “DATASAVE” shown on page 5 of this issue. You won’t be able to get a correct Syntactic Sum using the standard Syntactic Sum program now, as Linesum is also present, so do RUN 9000.

Now you can step through the typed-in program 1 line at a time. When the displayed checksum differs from the printed one, use the edit option to switch to normal BASIC listing at the current line. Find & EDIT the error, then do GOTO SUM to go back to Linesum for a display of the edited line and new checksum

After everything is fixed and your line checksums agree with the printed ones, you reRUN, using the LPRINT option to get a LISTing with linesums and the Syntactic Sum.

When you finish, erase the entire Linesum program above 9000 using: GOTO 9485 & 9000 ENTER.

Linesum is menu-driven with 3 options after each line display: Next Line, Quit, or Edit Current Line. At the beginning, you choose screen or printer output. At the end of a screen session you can examine the Syntactic Sum.

Lines 9485-500 erase Linesum. Line 9485 gets the address of the next line. The relocatable machine code routine in line 9490 computes the Linesum program length (from 9000 to the end of BASIC program area) and stores this number minus 4 in the text length bytes of line 9000. When you delete line 9000, all of Linesum disappears.

9000 REM "LINESUM" DISPLAYS A PROGRAM ONE LINE AT A TIME, ALONG  WITH THE CHECKSUM OF ITS BYTES.
9005 REM
9010 REM IF THE CHECKSUM REVEALSENTRY ERROR THE CURRENT LINE CANBE EDITED, AND THEN RE-CHECKED.
9015 REM
9020 REM ▛▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▜
9025 REM ▌DO NOT USE RUN AFTER ▐
9030 REM ▌ AN EDIT OPERATION. ▐
9035 REM ▌ RE-ENTER LINESUM BY ▐
9040 REM ▌THE COMMAND GOTO SUM ▐
9045 REM ▙▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▟
9050 REM
9055 FAST
9060 REM THE ENTIRE LINESUM PRO-GRAM FROM LINE 9900 UP CAN BE ERASED BY THESE TWO COMMANDS:
9065 REM <<GOTO 9485>>
9070 REM <<9000 ENTER>>
9075 LET SUM=9135
9080 PRINT "(P)PRINT (L)LPRINT (Q)QUIT"
9085 PAUSE 4E4
9090 LET K$=INKEY$
9095 IF K$<>"P" AND K$<>"L" AND K$<>"Q" THEN GOTO 9085
9100 IF K$="P" THEN LET FL=0
9105 IF K$="L" THEN LET FL=1
9110 IF K$="Q" THEN CLS
9115 IF K$="Q" THEN LIST 9000
9120 LET CA=16509
9125 LET TOT=0
9130 LET LA=CA
9135 LET CA=LA
9140 IF FL=0 THEN LET K$="P"
9145 LET LSUM=0
9150 LET L$=""
9155 LET NA=CA+PEEK (CA+2)+256*PEEK (CA+3)+4
9160 LET L$=L$+STR$ (256*PEEK CA+PEEK (CA+1))
9165 IF LEN L$<4 THEN LET L$=" "+L$
9170 IF LEN L$<4 THEN GOTO 9165
9175 LET LSUM=LSUM+PEEK CA+PEEK (CA+1)+PEEK (CA+2)+PEEK (CA+3)
9180 LET CA=CA+4
9185 LET BV=PEEK CA
9190 LET LSUM=LSUM+BV
9195 IF BV=118 THEN GOTO 9235
9200 IF BV<>126 THEN GOTO 9220
9205 LET LSUM=LSUM+PEEK (CA+1)+PEEK (CA+2)+PEEK (CA+3)+PEEK (CA+4)+PEEK (CA+5)
9210 LET CA=CA+6
9215 GOTO 9185
9220 LET L$=L$+CHR$ BV
9225 LET CA=CA+1
9230 GOTO 9185
9235 CLS
9240 PRINT L$;
9245 LET C=33-PEEK 16441
9250 LET R=24-PEEK 16442
9255 IF C<31-LEN STR$ LSUM THEN GOTO 9265
9260 LET R=R+1
9265 PRINT AT R,31-(LEN STR$ LSUM);"▌";LSUM;
9270 IF FL=1 THEN GOTO 9430
9275 PRINT AT 19,0;"CHOOSE: (N)NEXT LINE (Q)QUIT (E)EDIT CURRENT PROGRAM LINE"
9280 PAUSE 4E4
9285 LET K$=INKEY$
9290 IF K$="Q" THEN CLS
9295 IF K$="Q" THEN LIST 9000
9300 IF K$="E" THEN CLS
9305 IF K$="E" THEN LIST 256*PEEK LA+PEEK (LA+1)
9310 IF K$<>"N" THEN GOTO 9280
9315 LET TOT=TOT+LSUM
9320 IF TOT>65535 THEN LET TOT=TOT-65536
9325 IF 256*PEEK NA+PEEK (NA+1)>=9999 THEN GOTO 9340
9330 LET CA=NA
9335 GOTO 9130
9340 CLS
9345 IF FL=1 THEN LET K$="S"
9350 IF FL=1 THEN GOTO 9395
9355 PRINT "FINAL PROGRAM LINE EXAMINED."
9360 PRINT AT 19,0;"CHOOSE: (Q)QUIT (S)SYNTACTIC SUM"
9365 PAUSE 4E4
9370 LET K$=INKEY$
9375 IF K$="S" THEN GOTO 9395
9380 IF K$<>"Q" THEN GOTO 9365
9385 IF K$="Q" THEN CLS
9390 IF K$="Q" THEN LIST
9395 CLS
9400 PRINT "SYNTACTIC SUM: ";TOT;", 8K ROM"
9405 IF FL=1 THEN GOTO 9430
9410 IF FL=0 THEN PRINT AT 19,0;"PRESS ANY KEY TO LIST 9000"
9415 PAUSE 4E4
9420 CLS
9425 LIST 9000
9430 LET L$=""
9435 LET DFA=PEEK 16396+256*PEEK 16397+1
9440 LET END=PEEK 16398+256*PEEK 16399
9445 IF DFA=END THEN GOTO 9470
9450 IF PEEK DFA=118 THEN GOTO 9460
9455 LET L$=L$+CHR$ PEEK DFA
9460 LET DFA=DFA+1
9465 GOTO 9445
9470 LPRINT L$
9475 IF K$="S" THEN STOP
9480 GOTO 9315
9485 RAND USR (PEEK 16425+256*PEEK 16426+5)
9490 REM <<MACHINE CODE ROUTINE GOES IN THIS LINE>>
9495 CLS
9500 LIST 9000
9505 LET CA=16514
9510 PRINT "ENTER DEC CODE"
9515 INPUT K
9520 POKE CA,K
9525 LET CA=CA+1
9530 CLS
9535 GOTO 9510
SYNTACTIC SUM: 35581, 8K ROM

Line checksums as printed beside each line:

line  checksum
9000   3865
9005    434
9010   3968
9015    444
9020    674
9025   1423
9030   1368
9035   1444
9040   1465
9045   3507
9050    479
9055    479
9060   3748
9065    924
9070    955
9075   1309
9080   1613
9085    999
9090    676
9095   3193
9100   1448
9105   1579
9110   1193
9115   1758
9120   1348
9125    912
9130    756
9135    761
9140   1488
9145    980
9150    695
9155   2887
9160   2363
9165   1850
9170   2132
9175   3435
9180   1115
9185   1034
9190   1203
9195   2194
9200   2349
9205   4518
9210   1211
9215   1206
9220    887
9225    900
9230    966
9235    426
9240    515
9245   1607
9250   1689
9255   2690
9260    887
9265   2187
9270   1839
9275   3549
9280    939
9285    616
9290   1118
9295   1683
9300   1116
9305   2475
9310   1747
9315   1094
9320   2819
9325   3742
9330    703
9335   1096
9340    531
9345   1571
9350   2044
9355   1752
9360   2669
9365   1024
9370    701
9375   1828
9380   1909
9385   1213
9390   1207
9395    586
9400   1770
9405   1974
9410   3163
9415   1074
9420    611
9425   1176
9430    720
9435   2855
9440   2571
9445   2055
9450   2566
9455   1359
9460   1225
9465   1220
9470    699
9475   1026
9480    966
9485   2900
9490   2056
9495    431
9500    996
9505    974
9510   1023
9515    487
9520    605
9525    945
9530    456
9535   1033

[Editor’s note: the printed checksum for line 9530 is 456; Linesum computes 466 for 9530 CLS, so 456 is a misprint.]

Note: Type-in program listings on this website use ZMAKEBAS notation for graphics characters.