Classic Computer Magazine Archive COMPUTE! ISSUE 38 / JULY 1983 / PAGE 204

Commodore REM Revealed

John L. Darling

Did you know that you can prevent someone from easily listing your program? This is one of several hidden secrets of the REM statement. Did you ever try putting shifted or reverse video characters behind a REM? The results you get when you LIST may come as a surprise. Try these experiments to learn about the tricks you can play with REMs. For VIC, 64, and all PET/CBM models.

There are quite a few hidden surprises in the REM statement. Many are just plain fun, but a few can be put to good use. Let's go exploring.

The REM statement was designed to provide a way to add remarks or comments in a program. During execution of the program, all the characters on a line following the REM are ignored. Thus, the only time the remarks are seen is when the program is LISTed.

Also note that, for program operation, it doesn't make any difference whether the characters following the REM are enclosed in quote marks or not, but it sure can change the results you get when you LIST the program. First, let's look at the REM when quotes are not used. The results you get when the program is LISTed will be determined by the following rules:

  1. Non-shifted characters appear as typed in.
  2. Shifted characters are converted to BASIC commands if the ASCII code for the character is equivalent to a BASIC command token.
  3. Reverse fields are stripped from any character.

Before we examine these rules, you may want to put your computer into lowercase mode by typing POKE 59468,14 on the PET/CBM or by hitting shift-Commodore key on the VIC and 64. It is easier to discuss upper- and lowercase letters than it is to describe graphic symbols. Reverse video characters are produced by pressing the RVS key and then the character. The OFF key gets you out of reverse video. (On the VIC and 64, the RVS ON and RVS OFF keys are CTRL-9 and CTRL-0.)

To illustrate these rules, type in the following four lines and then LIST.

10 rem a b c d e f
20 rem A B C D E F
30 rem {RVS} a b c d e f {OFF}
40 rem {RVS} A B C D E F {OFF)
list
10 rem a b c d e f
20 rem atn peek len str$ val asc
30 rem a b c d e f
40 rem atn peek len str$ val asc

Line 10 demonstrates Rule 1. All the characters are LISTed just as they were entered. This is the normal effect that we're all used to.

Line 20 doesn't look much like the original, does it? It illustrates Rule 2: the shifted letters are interpreted as BASIC command tokens.

Lines 30 and 40 show Rule 3 in action. They look just like lines 10 and 20 because the reverse field was stripped when the lines were entered.

List Blocking

Now we get to the question of how to prevent someone from easily LISTing your program. Let's examine Rule 2 a little more closely. Certain characters become "tokens" which cause unusual effects. One will cause the LIST operation to terminate with a "syntax error" message when it is encountered. These tokens are equivalent to a shifted-L on the VIC, 64, Original and Upgrade PETs. In BASIC 4.0 this character is the shifted-[.

This can be verified by the following line.

When you attempt to list the line, the result will be:

10 rem
?syntax error
ready.

For newer CBM models with the "business style" (nongraphics) keyboard, the shifted-[ is not directly available from the keyboard. The "[" and "shift-[" appear to the computer as the same character. You can get around this by typing the following line in direct mode (without a line number):

print "10 rem" chr$(219)

When you hit RETURN, the program line should appear. (The chr$(219) will produce a graphics character.) Position the cursor on this line and hit RETURN.

Up to now, it's just been fun, but there is a reason you might want to use this line. If this special REM line is the first line in a program, it prevents a normal LISTing. Let's assume that the first line in a large program is line 100. Inserting this special REM line ahead of the program causes the LIST operation to terminate as soon as it encounters the special shifted character. However, LIST 100-will allow the program to be displayed normally.

Consider the following situation. A quiz program has the answers in DATA statements at the end of the program listing. Inserting the special REM line just ahead of these DATA statements will prevent the answers from being displayed during a LIST. Don't forget that REM statements are ignored during program execution, so they won't affect the actual program operation.

Quote Mode

Now, let's examine the quote mode. A new set of rules applies when the REM characters are enclosed in quotes:

  1. Shifted and non-shifted characters LIST as they were typed in.
  2. Reverse video characters are preserved when inside quotes (they are not stripped, as is the case in the non-quote mode).
  3. Some reverse video characters and combinations of characters behave as print control commands when LISTed.

Rules 1 and 2 produce results that you would normally expect during the LIST operation. They LIST exactly as typed in. No examples are provided for these rules, but try a few experiments to verify this for yourself.

Here are some interesting examples of Rule 3 in action. (The comments in brackets are the resultant action produced during LIST.)

Note: A dot matrix printer was used to list the examples with reverse video characters.

rem "  [delete]
rem "  [insert]
rem "  [return]
rem "  [shifted return] = *
rem "  * + [home]
rem "  * + [clear screen]
rem "  * + [cursor down]
rem "  * + [cursor up]
rem "  * + [cursor right]
rem "  * + [cursor left]

When these characters are inside a REM" statement, strange things are going to happen.

To enter the following tests, first type the line number, the REM, the quote symbol, and then RETURN. Next, edit the line by positioning the cursor past the quote mark, press the "RVS" key and then the letters. This allows you to put the reverse video characters on the screen line.

10 rem "help   ! 
list
10 rem "he
ready.

The four reverse "t" characters achieve the same thing that would occur if the DEL key was pressed during an edit operation, deleting the last four characters. Adding more reverse "t" characters (15 total) on the test line will cause the entire line to disappear after it is LISTed on the screen.

Notice that many of the cursor controls shown require the "M" (shifted RETURN) character to be the first character. This is important, for without the "shifted return" most of the cursor controls or special control codes will not be executed. As soon as this character is encountered, a shifted RETURN will be generated. All characters following the shifted-M will be printed as if they were in a PRINT statement, rather than in a REM. Consequently, if any of these characters are cursor controls, they will produce a cursor control action as if they were inside the quotes following a PRINT statement.

If the reverse t's in the previous example were replaced with reverse "MS" characters, then the LIST operation would list that line up to the ! and then the cursor will go to the top of screen since "MS" is interpreted as a HOME command. If this was listed to a Commodore printer and the paging mode was on, the printer would eject a page after LISTing that line.

A Program Within A Program

Let's try one final example to illustrate how the reverse field shifted-M works in combination with other characters. To avoid errors, here is a complete key sequence that will produce the following line:

1, 0, SPACE, R, E, M, ",", DEL, RVS, SHIFT-M,
SHIFT-S, Q, Q, Q, Q, OFF, I, SPACE, T, H, I, N, K,
SPACE, I, SPACE, A, M, SPACE, S, RVS, Q, OFF, I,
RVS, Q, OFF, C, RVS, Q, OFF, K, RVS, S, OFF, " ,
SHIFT-L

(For 4.0 BASIC, replace the final SHIFT-L with SHIFT-[. For "business style" keyboards, use the same technique as in the preceding example. Use chr$(34) in place of the quotes.)

10 " think i am " L

Can you guess the results? If you type the line correctly, the following will happen after you LIST:

  1. 10 rem" will be printed.
  2. A "clear screen" will be printed, blanking the screen and also the previous 10 rem" .
  3. Four "cursor downs" will be printed.
  4. The message "I think I am sick" will be printed with the I, C, K characters on different lines.
  5. A "cursor-home" will occur.
  6. " '@' will be printed on the top line followed by a "?syntax error" message on the next line. (Note that the special shifted character is no longer enclosed in quotes.)
  7. Finally, the "ready" message will appear with the cursor above the "I think I am s" line.

The above line could be inserted in most programs, and it will not affect the program execution performance in the least. You just can't get a normal LISTing of the program.

There are a lot more combinations to try, so have fun. It's like having a program inside another program. The second program requires a LIST command for execution instead of a RUN command.