MCI Commands and Use

From Color 64 BBS Wiki

BBS Operation - MCI Commands

Color 64 supports MCI commands--MCI stands for Message Command Interpreter, a system used on many BBS types. In short, an MCI command is a set of characters that you embed in a message to control the appearance of the text or perform special functions. One command could inform the computer to wait for a key to be pressed, and another command could turn on rainbow mode. MCI commands are not performed until the lines you have typed are viewed by you or someone else (whether listing the lines in the editor or by reading the message itself). Until then, all you see is a representation of them as you type the lines. MCI commands can also be used with the BASIC output commands (see section 3.11.1, on using MCI commands in BASIC). In fact, MCI commands can be used anywhere that output can occur, except for BASIC’s PRINT statement, because PRINT is not tied into the ML output routines.

While in the message editor, all MCI commands begin with the British Pound symbol (£). The next character in the MCI command tells the computer which command you wish to use. It must be an unshifted letter; the interpreter will not recognize shifted letter commands. A 'c' for example tells the computer to wait for a key to be pressed. On the screen the command would appear as '£c'. Of course, if you are in Uppercase/Graphics mode then unshifted characters will appear as uppercase characters (i.e. ‘C').

Some MCI commands require additional characters to supplement the command, such as the rainbow mode MCI commands. If you wish to use standard character rainbow mode, then the sequence would be £r followed by 2 to 8 colors. To type the colors, just use the CTRL and C= keys just as if you were changing the cursor color (e.g. CTRL/2 is white, C=3 is light red, etc.). The colors will be used just like the rainbow mode enacted by the ‘F3' character, except they will be your own chosen colors rather than the system colors. If you use less than 2 colors, the current rainbow mode will be left unchanged. If you use more than 8 colors, only the first 8 will be used. All rainbow modes except for Caps/Punctuation Mode accept 2 to 8 colors.

The table below defines the standard MCI commands:

Standard MCI Commands
Command Function Description
£r Character Rainbow Color changes for each character
£w Word Rainbow The color changes for each word
£s Sentence Rainbow The color changes for each sentence that ends with a period (.), question mark (?), or exclamation point (!)
£l Line Rainbow The color changes for each line that ends with a carriage return
£g Paragraph Rainbow The color changes for each paragraph that ends with two carriage returns
£p Caps/Punctuation This will use from 2 to 3 colors. If 3 colors are used, a separate color is defined for uppercase letters, lowercase letters, and punctuation/graphics characters respectively. If only 2 colors are used, then a separate color is defined for alphabetic and punctuation characters, respectively. Both versions produce a very nice-looking effect
£n Normal This command cancels the currently set mode (returning text to normal output)
£v Character Velocity This command is followed with a digit from 0 to 9. 0 sets the output speed so there is no delay between characters (which is the fastest). 9 is the slowest speed. This command is cancelled by a £v0 command or by a RETURN.
£c Wait Wait for key to be pressed by user
£t Tab A number from 0 to 79 must follow this command which indicates which tab position to go to. If the current position is less than the tab position, then spaces are printed. For example, if you were at position 5 (which would be the equivalent of hitting the spacebar 5 times), then issued a .t10 command, the computer would automatically add another five spaces to get to the correct position. If the current position is greater than the tab position, then crsr-lefts are printed.

Note: If several tabs are to be executed on the same line, they should all be in the same direction (e.g. from left to right, or from right to left). Moving back and forth on the screen may produce undesirable effects.

£i Wait for Line of Input Waits for a line of input to be entered. Up to 127 characters can be entered. The text that was entered is stored in memory and can be printed with the £a0 command (refer to Section 3.9).

There are two MCI commands that have level-restricted access, Message Output MCI and Variable MCI. You will see that their levels of use are definable in SETUP.

The Message Output MCI

£a: message output MCI. This command prints a different message depending on the digit following the command as defined in the table below.

Message MCI Commands
Command Function
£a0 Print the input typed when the last £i command was issued
£a1 Print the name/alias of the current caller (This uses the current contents of the string NA$)
£a2 Print the last calling date of the user (LD$)
£a3 Current time (T$)
£a4 Current date (DA$)
£a5 Print the name/alias of the last caller (LC$).

Note: If the last call was an incoming network exchange, then the name of the remote BBS will be stored in this variable.

£a6 Print the contents of the string variable DD$. This is the SYSOP definable "Membership Information" field in the caller's password record. See section 3.3, "Password Record Information", for information on its use.
£a7 User's real name (RN$)
£a8 User’s birth date (BD$)
£a9 User’s phone number (PH$)
£aa User’s email or street address (A1$)
£ab User’s city, state, and ZIP (A2$)

One more note about the Message (£a) MCI command. The command £a6 prints the contents of DD$ (membership information). The information in DD$ may vary as you decide how it is used. Therefore, the option of disabling the DD$ commands for security reasons is available in SETUP.

The Variable MCI Command.

£[: variable expression output.  This MCI command lets you print any type of variable or expression you want.

An expression is just a mathematical formula which you use in BASIC to calculate things. For example, 5*4+3/16 is an expression, just as a$+mid$(str$(lv),2) is an expression. Just follow the £[ with an expression and then end the string of characters with a close-bracket symbol (]). This command requires some explanation about the inner workings of BASIC.

  • Keywords and Tokens
The BASIC language is made up of what are called "keywords", which are the very base commands and functions of the BASIC language. PRINT, for example, is a BASIC keyword. Since there really aren't that many keywords, it would be a waste of time and space if the BASIC interpreter stored each letter of each of these keywords individually. Instead, the BASIC interpreter scans each line as you enter it into the program and crunches each keyword into a single character called a "token". When you LIST the program, of course, these tokens are printed as the entire keyword. The keyword crunching process saves space when the program is being stored on disk, and it saves time when the program is running (for it doesn't have to figure out what the command is by searching character by character). When you are editing a BASIC program, the whole process of keyword crunching is invisible, because it is taken care of by the computer from when you enter the line to when you LIST it again.
The £[ command is different, though, because it expects you to take care of the keyword crunching for it. The reason for this is that the regular BASIC interpreter is busy running a program and doesn't have any need to go about crunching keywords inside of MCI commands. Don't get worried, though, because I have installed a feature into this command which allows you to use it without understanding the BASIC tokens. Just read on though because the process of keyword crunching is very simple.
  • Typing in the BASIC Tokens
It is pure chance, I guess, that all the necessary keywords that would be needed in the £[ command are easily typeable from the Commodore keyboard. This fact, though, allows you to access all the functions and symbols that you would have access to when typing a line in BASIC. The only difference, though, is that all of them are represented by a single character. The enclosed chart below shows all the numeric/string symbols and functions with their token equivalents. The "C=" by a character means to press that key while holding the Commodore logo key down, just like when you type Commodore graphics characters. If something is not on the chart, then it doesn't need to be converted (such as the "%" percent sign). Also note that all mathematical symbols such as the plus and minus signs need to be converted to a token. In the following paragraphs, angle brackets "< >" will enclose special characters.
BASIC Token Reference Chart
Token Hex Key Combination CHR$()
+ AA C= + J CHR$(170)
- AB C= + K CHR$(171)
* AC C= + L CHR$(172)
/ AD C= + Z CHR$(173)
AE C= + X CHR$(174)
AND AF C= + C CHR$(175)
OR B0 C= + V CHR$(176)
> B1 C= + B CHR$(177)
= B2 C= + N CHR$(178)
< B3 C= + M CHR$(179)
SGN B4 C= + H CHR$(180)
INT B5 C= + J CHR$(181)
ABS B6 C= + L CHR$(182)
USR B7 C= + Y CHR$(183)
FRE B8 C= + U CHR$(184)
POS B9 C= + O CHR$(185)
SQR BA SHIFT-@ CHR$(186)
RND BB C= + F CHR$(187)
LOG BC C= + C CHR$(188)
EXP BD C= + X CHR$(189)
COS BE C= + V CHR$(190)
SIN BF C= + B CHR$(191)
TAN C0 SHIFT-* CHR$(192)
ATN C1 SHIFT-A CHR$(193)
PEEK C2 SHIFT-B CHR$(194)
LEN C3 SHIFT-C CHR$(195)
Example: you want the computer to print the expression "INT(RND(0)*16+5)" with the £[ command. The first thing you would do is consult the chart and find the token for "INT". This happens to be the C=J character (which looks like a thick vertical line). Then the parenthesis would be typed as normal. Next would be the keyword "RND". On the chart, it is listed as the C=F character (a small square). Then everything would be the same until the "*” character. So far, the command would be "£[", then a C=J symbol, then a “(", then a C=F symbol, then "(0)".
Next, remember that mathematical symbols like "*" are also converted to tokens. Using the chart, it would be converted to a C=D character (a small square). The "16" is fine as it is. The "+" sign is converted to C=N (a thin vertical line). And the final parenthesis is left alone. The complete command would be (without the spaces): £ [ <C=J> ( <C=F> ( 0 ) <C=D> 1 6 <C=N> 5 ) ]
On a live and breathing Commodore display, it should look like this:
A final "]" close-bracket symbol finishes the command. This example appears on the keywords sheet as it would appear on screen.
Again, anything that isn't on the chart is usable as it is. Remember that the text between the brackets is under the same rules as any BASIC expression. Therefore, you can create a SYNTAX ERROR, or any other error a bad expression may create. So be careful to make sure the expression has been entered correctly. For this reason, it is also highly recommended that use of this command is restricted to only you, or those who you can absolutely trust with using the command.
  • An Easier (but slower) Solution: Automatic Keyword Cruncher
If you still do not understand tokens, it is perfectly fine. This is a concept that rarely comes up in everyday practical programming. That is why I included the "automatic keyword cruncher". Be forewarned, though, that the automatic keyword cruncher calculates the expression a lot slower than a manually crunched expression. Keep this fact in mind if you notice slight delays while printing a file that uses a lot of Variable MCI commands. To use the automatic keyword cruncher, just include the ">“ greater-than symbol right after the "[" opening bracket. Here is a comparison of how the £[ command would be with and without the automatic keyword-cruncher, using the expression int(rnd(0)*16+5):
Automatic Keyword Cruncher Example "int(rnd(0)*16+5)"
With Automatic Keyword Cruncher Without Automatic Keyword Cruncher
As you can see, the automatic version is a lot simpler to read, although it takes up more room (in characters).

MCI Command Security

You can set the levels for the "£a" Message and the "£[" Variable MCI commands in SETUP. If the caller doesn't have access to a command, then he will not be allowed to type the character after a "£". Also, the default message loader will sift out any unauthorized use of MCI commands if the levels do not permit their use.

The way the security measures are accomplished involves substituting special characters in the place of what the caller is typing. For example, if the caller has access to the £a command, the input routine will convert the "a” in the command to an F2 (function key two) character. This process is completely invisible to the caller, and it appears that an "a" is being typed because that is what is printed. Internally, though, the command sequence is stored as a "£" character and an F2 character. If the £[ command is used, then the "[" character is converted to an F4 (function key four).

All of this may seem to be a lot of programming to accomplish nothing, but it is the most effective way to prevent tampering of the MCI commands. Both the F2 character and the F4 character are "impossible keys" when online, meaning that no matter what a caller does, there is no way to directly input a converted MCI command if they do not have access.

Using MCI Commands in BASIC

Because of the security measures mentioned above, it is necessary for you to use the £a and £[ commands in their native form when programming in BASIC. This means that instead of typing "£" then "a" for a Message MCI command inside the quotes of a BASIC statement, you will have to type "£" then F2 (an uppercase reverse "I"). The same with the Variable MCI, which instead of appearing as "£[" like in the message editor, it will appear as a “£” then F4 (an uppercase reverse 'J').

Next Section: Text Editing Features

BBS Operation