Mimsy Were the Borogoves

Hacks: Articles about programming in Python, Perl, Swift, BASIC, and whatever else I happen to feel like hacking at.

New, improved rcheck+ for Rainbow Magazine code

Jerry Stratton, November 11, 2020

ON L GOSUB: The TRS-80 Color Computer’s Extended Color BASIC requires spaces between variable letters and THEN, GOTO, or (as in this example) GOSUB.; Color Computer; CoCo, TRS-80 Color Computer; BASIC; Beginners All-purpose Symbolic Instruction Code

This, from Le Lutin in the July 1987 Rainbow, was a very annoying and time-consuming error to debug just using rcheck. It was obvious once brought into Xroar.

I’ve added a few new features to the rcheck script to make it more useful for typing in code from The Rainbow.

--debugprovide a hexdump of the tokenized BASIC file
--rcheckuse the original rcheck rather than rcheck+
--shift <x>shift all checksums by x
--verboseshow checksums for all lines
[xxx]show checksum for line xxx
[xxx:yyy]verify line xxx against expected checksum yyy
[:yyy]verify checksum yyy at the end of the code

rcheck+ for macOS (Zip file, 2.5 KB)

The big, important change is that you can now specify the expected checksums on the command line. You can continue to use rcheck as before, and its behavior will not change. But if you add “:yyy” to a line number, it uses “yyy” as the expected checksum. For the final line, you can use simply “:yyy” or “yyy”.

  • ~/bin/rcheck MEMOCARD.BAS 130:15 210:170 320:9 :167
  • 130: 15
  • 210: 152 238 (-18); possibly a 4 where there should be an F?
  • 320: 247 238 (-18)
  • END: 149 238 (-18)

When a checksum does not match the expected checksum, the script shows the difference. This is extremely helpful, because often merely knowing that the checksum is off by, say, 32, tells you what the likely problem is—a missing or extra space, or an incorrectly-cased letter. In fact, some errors are common enough that I’ve put a check for them in the script, as you can see in the example.

  • The dash is right next to the equals on my keyboard, so that’s a common mistake.
  • I’ve no idea why I often type 4 where I should type F, but I do.
  • Ditto with typing a dash instead of an equals sign.
  • Also, very commonly spaces will not be obvious and so will not be typed when they appear in a remark, especially when they appear (I suspect) at the end of a remark.
  • Multiples of 32 can be the result of case issues, since the difference between upper and lower case characters is 32 in ASCII, or multiple missing/extra spaces.
  • Every once in a while, not only can’t I find the supposed error, but the very next block of code is also off—by the inverse of the amount the previous block was off. I suspect that these are typos in the Rainbow checksum block.

If you provide expected checksums, the script keeps track of the accumulated error, so that checkpoints that follow an erroneous checkpoint will be displayed with their correct error amount, or in green if that particular checkpoint has the “correct” checksum. That is, if, in the above MEMOCARD.BAS example, the checksum at 210 is 175 instead of 170, the script keeps track of the error, and will expect checkpoint 320 to be 14 and the end to be 172—that is, five above the listed checksum, since checkpoint 210 is five above its expected checksum.

I did this because I find myself typing either complete scripts or several columns, and so it’s nice to see all that green after one error. And I also occasionally put off looking for errors until later if I can’t find what I mistyped. By correcting for previous errors, the script makes it easier to check for errors in subsequent checkpoints without having to fix them in order.

Something you can’t see in that example is that the script also highlights good checksums with green text, and bad checksums with red. Here’s an example from Talking CoCo Cathead in the November, 1987 issue of The Rainbow:

CoCo Cathead checksums: Good and bad checksums in the program Talking CoCo Cathead from the November 1987 issue of The Rainbow.; Color Computer; CoCo, TRS-80 Color Computer; The Rainbow magazine

Also, it will not show the end total if you give it a list of checksums and the highest line in the code is less than the highest line in your list of checksums; instead it will say “END: Not finished”, because, presumably, this cannot be the end total if there are still checksums to go.

While I updated the original code to include the --debug option, I never explained it. The --debug option is really only useful for debugging rcheck itself, although I did find it helpful for one program that had clearly been tokenized differently for The Rainbow than it was on my Color Computer. Le Lutin from the July 1987 Rainbow has apparently been compressed by removing spaces directly from the tokenized code. This makes the program impossible to type in as presented, because lines such as ONLGOSUB get tokenized as if LGOSUB were a variable.1

I added the --shift option for that program, once I realized that all checksums after the offending code were off by the same amount once I fixed them. So that I was able to run

  • ~/bin/rcheck LE\ LUTIN.BAS 5 13 28 48 68 84 94 104 116 124 140 160 183 198 214 219 228 236 247 260 272 277 290 296 302 310 317 321 332 346 --shift 43

to get the checksums after line 28 to match the checksums in the magazine.

I added this before I knew what the problem was with the checksum, except that as hard as I looked I couldn’t find it. So I decided to put off dealing with it and just go on typing the rest of the program, using --shift to adjust the checksum to take into account the errors at the beginning. Fortunately, those special cases only appeared at the beginning, and I was able to complete typing the rest of the program without further problems. Once I tried to run the program, the reason for the checksum discrepancy became obvious.

Even when the error is mine rather than the magazine’s, however, it is sometimes helpful to give up for a while and just move on to the rest of the program. Errors sometimes become more obvious when I stop looking for them.

I mentioned the --rcheck option as a quick update to TRS-80 Color Computer RCHECK+ in Perl. Before rcheck+ calculated checksums, The Rainbow included an rcheck not plus that simply checked the amount of RAM that the program was using.

  • $ ~/bin/rcheck ENRAK.BAS 70 140 290 390 580 680 870 1100 1260 1360 1510 1610 1720 1830 --rcheck
  • 70: 0426
  • 140: 076F
  • END: 07AF

I’m not sure how many errors this would pick up that wouldn’t also be picked up just by looking down the right-most column of the listing. Errors that cause a BASIC statement to not tokenize would be picked up, as would extra or missing characters in the final subline of a BASIC line, since the final subline in a Rainbow listing doesn’t usually reach the rightmost (32nd) column.

I also added a --verbose option to show checksums for all line numbers (this was originally part of --debug, but it tended to obscure the hexdump). This is rarely useful.

Other minor and not-so-minor fixes since I first announced the rcheck script are that the script now handles BASIC programs with spaces in their names correctly. It was a rarely-used feature, but Disk Extended Color BASIC didn’t care if programs had spaces—such as Le Lutin.

As a side note, the two characters after the line number that rcheck skips over, that I didn’t know what they were? I’m pretty sure now that they’re the hard address of the next line number in hexadecimal.

I was inspired enough by rcheck to write a similar program for 42 Astoundingly Useful Scripts and Automations for the Macintosh, check42.

In response to TRS-80 Color Computer RCHECK+ in Perl: I much prefer to use a modern keyboard and modern windows to type in programs. But Rainbow’s RCHECK+ was too useful to give up. This script will run RCHECK+ on a text file in the macOS Terminal or any Linux/Unix command line.

  1. The same is true of letter variables in front of THEN and GOTO. They require spaces, and in Le Lutin those required spaces had been removed.