-
Notifications
You must be signed in to change notification settings - Fork 33
Unforgotten: Palo Alto BASIC
Tiny Basic was first proposed in Dr. Dobb's Journal. Li-Chen Wang's version of Palo Alto Tiny Basic originally appeared in Issue No.5, May 1976 of Dr. Dobb's Journal. A complete listing was printed, but Dr. Wang did the assembly on an IBM computer and he defined different mnemonics. In order to assemble with an Intel Compatible Assembler a translation of most mnemonics had to be performed.
I had developed my own system, which consists of two small p.c. boards, one containing the 8080 CPU, 4k of 2708 type EROM and 1K of RAM. The other PCB contained the RS-232 Interface using the Intel 8251. So I wanted to change the I/O section. If you want to change I/O, all routines are contained in the OUTC and CHKIO routines. My system uses the following configuration:
2708 EPROMS 0000H TO 07FFH
1k OF RAM 1000H TO 13FFH
(technical details omitted)
The program is contained in locations OOOOH to 0768H. In 1K of RAM 847 bytes are left over for program. Tiny Basic does not offer much in terms of functions and general mathematical capabilities. But it is great to teach programming basics to children (and adults) and for games, since it has the RN0 function. It takes up little memory space and executes a lot faster than other basics. Dr. Wang was very helpful and assisted me all the way. Some errors were eliminated. I appreciate his help and he deserves a lot of credit for his implementation of Tiny Basic (see Microcomputer Software Depository Program Index for Copies of this program).
In Tiny Basic, all numbers are integers and must be less than or equal to 32767.
There are 26 variables denoted by letters A through Z. There is also a single array @(1). The dimension of this array (i.e., the range of value of the index 1) is set automatically to make use of all the memory space that is left unused by the program. (i.e., 0 through SIZE/2, see SIZE function below.)
For the time being, there are only 3 functions:
- ABS(X) gives the absolute value of X.
- RND(X) gives a random number between 1 and X (inclusive).
- SIZE gives the number of bytes left unused by the program.
/ divide. Note that since we have integers only, 2/3=0.
* multiply.
- subtract.
+ add.
> compare if greater than.
< compare if less than.
= if equal to. Note that to certain ver sions of Basic "LET A=B=O" means "set both A and B to 0". To this version of Tiny Basic, it means "set A to the result of comparing B with
# compare if not equal to.
>= compare if greater than or equal to.
<= compare if less than or equal to.
+, -, *, and I operations result in a value of between -32767 and 32767.
All compare operators result in a 1 if true and a 0 if not true.
Expressions are formed with numbers, variables, and functions with arithmetic and compare operators between them. + and - signs can also be used at the beginning of an expression. The value of an expression is evaluated from left to right. except that * and I are always done first. and then + and - , and then com- pare operators. Parentheses can also be used to alter the order of evaluation.
A Tiny Basic statement consists of a statement number between 1 and 32767 followed by one or more commands. Commands in the same statement are separated by a semi-colon ";". "GOTO", "STOP", and "RETURN" commands must be the last command in any given statement.
A Tiny BASIC program consists of one or more statements. When a direct command "RUN" is issued, the statement with the lowest statement number is executed first. then the one with the next lowest statement number, etc. However, the "GOTO", "GOSUB", "STOP", and "RETURN" commands can alter this normal sequence. Within the statement. ex- ecution of the commands is from left to right. The "IF" command can cause the execution of all the com- mands to its right in the same statement to be skipped over.
Tiny Basic commands are listed below with examples. Remember that commands can be concatenated with semi-colons. In order to store the statement. you must also have a statement number in front of the commands. The statement number and the concatenation are not shown in the examples.
REM or REMARK Command
REM anything goes
This line will be ignored by TBI.
LET Command
LET A=234-56, A=AI2, X=A-100, @(X+9)=A-1 will set the variable A to the value of the expression 234-56 (i.e., 204). set the variable A (again) to the value of the expression AI2 (i.e., 102). set the variable X to the value of the expression A-100 (i.e., 2). and then set the variable @(11) to 101 (where 11 is the value of the expression X+9 and 101 is the value of the expression A-1).
LET U=A#B, V=(A>B)*X+(A<B)*Y will set the variable U to either 1 or 0 depending on whether A is not equal to or is equal to B; and set the variable V to either X, Y or 0 depending on whether A is greater than, less than, or equal to B.
PRINT Command
PRINT will cause a carriage-return (CR) and a line-feed (LF) on the output device.
PRINT A *3+ 1, "ABC 123 !@#", ' CBA ' will print the value of the expression A * 3 + 1 (i.e.,30n the string of characters "ABC 123 !@#", and the string " CBA ", and then a CR-LF. Note that either single or double quotes can be used to quote strings, but pairs must be matched.
PRINT A*3+1. "ABC 123 !@#", ' CBA " will produce the same output as before, except that there is no CR-LF after the last item is printed. This enables the program to continue printing on the same line with another "PRINT".
PRINT A, B, #3, C, D, E, #10, F,G will print the values of A and B in 6 spaces, the values of C, D, and E in 3 spaces, and the values of F and G in 10 spaces. If there are not enough spaces specified for a given value to be printed, the value will be printed with enough spaces anyway.
PRINT 'ABC', +-; 'XXX' will print the string "ABC", a CR without a LF, and then the string "XXX" (over the ABC) followed by a CR-LF.
INPUT Command
INPUT A, B When this command is executed, Tiny Basic will print "A:" and wait to read in an expression from the input device. The variable A will be set to the value of this expression. Then "B:" ·is printed and variable B is set to the value of the next expression read from the input device. Note that not only numbers, but also expressions can be read as input.
INPUT 'WHAT IS THE WEIGHT'A. "AND SIZE"B This is the same as the command above, except the prompt "A:" is replaced by "WHAT IS THE WEIGHT:" and the prompt "B:" is replaced by "AND SIZE:". Again, both single and double quotes can be used as long as they are matched.
(some details omitted)
IF Command
IF A<B LET X=3; PRINT 'THIS STRING' will test the value of the expression A < B. If it is not zero (i.e., if it is true). the commands in the rest of this statement will be executed. If the value of the expression is zero (i.e., if it is not true). the rest of this statement will be skipped over and execution continues at next statement. Note that the word "THEN" is not used.
GOTO Command
GOTO 120 will cause the execution to jump to statement 120. Note that GOTO command cannot be followed by a semi-colon and other commands. It must be ended with a CR.
GOTO A* 10+B will cause the execution to jump to a different statement number as computed from the value of the expression.
GOSUB and RETURN Commands
GOSUB command is similar to GOTO command except that: a) the current statement number and position within the statement is remembered; and b) a semicolon and other commands can follow it in the same statement.
GOSUB 120 will cause the execution to jump to statement 120. GOSU B A * 1 0 + B will cause the execution to jump to different statements as computed from the value of the expression A*10+B.
RETURN A RETURN command must be the last command in a statement and followed by a CR. When a RETURN command is encountered, it will cause the execution to jump back to the command following the most recent GOSUB command. GOSUB can be nested. The depth of nesting is limited only by the stack space.
Stopping the Execution
The execution of program or listing of program can be stopped by the Control-C key on the input device.
Abbreviation and blanks
You may use blanks freely, except that numbers, command key words, and function names can not have embedded blanks. You can truncate all command key werds and function names and follow each by a period. "P.", "PR.", "PRI.", and "PRIN." all stand for "PRINT." Also the word LET in LET command can be omitted. The "shortest" abbreviation for all the key words are as follows:
(omitted)
Control of Output Device
The Control-O key on the input device can be used to turn the output device ON and OFF. This is useful when you want to read in a program punched on paper tape. To produce such a paper tape, type "LIST' without CR. Turn on the paper tape punch and type a few Control-Shift-P's and then a CR. When listing is finished, type more Control-Shift-P's and turn off the punch. To read back such a paper tape, type "NEW," CR, and Control-O, then turn on the paper tape reader.
When the paper tape is finished, turn it off and type a Control-O again. Control-Shift-P's and turn off the punch. To read back such a paper tape, type "NEW," CR. and Control-?, then turn on the paper tape reader. When the paper tape is finished, turn it off and type a Control-O. then turn on the paper tape reader. When the paper tape is finished, turn it off and type a Control-O again.
Error Report
There are only three error conditions in TINY BASIC. The statement with the error is printed out with a question mark inserted at the point where the error is detected.
(1) WHAT? means it does not understand you.
(2) HOW? means it understands you but does not know to do it.
(3) SORRY means it understands you and knows how to do it but there is not enough memory to do it.
Error Corrections
If you notice an error in typing before you hit the CR. you can delete the last character by the Rub-Out key or delete the entire line by the Alt-Mode key. Tiny basic will echo a backslash for each Rub-Out. Echo for Alt-Mode consists of a LF, a CR, and an up-arrow. To correct a statement, you can retype the statement number and the correct commands. Tiny Basic will replace the old statement with the new one. To delete a statement, type the statement number and a CR only. Verify the corrections by "LIST nnnn" and hit the Control-C key while the line is being printed.
FOR and NEXT Commands
FOR X=A+1 TO 3*B STEP C-1 The variable X is set to the value of the expression A + 1. The values of the expressions (not the expressions themselves) 3 * B and C-1 are remembered. The name of the variable X. the statement number and the position of this command within the statement are also remembered. Execution then continues the normal way until a NEXT command is encountered.
The STEP can be positive, negative or even zero. The word STEP and the expression following it can be omitted if the desired STEP is + 1.
NEXT X
The name of the variable (X) is checked with that of the most recent FOR command. If they do not agree, that FOR is terminated and the next recent FOR is checked, etc. When a match is found, this variable will be set to its current value plus the value of the STEP expression saved by the FOR command. The updated value is then compared with the value of the TO expression also saved by the FOR command. If this is within the limit. execution will jump back to the command following the FOR command. If this is outside the limit. execution continues following the NEXT command itself. FOR can be nested. The depth of nesting is limited only by the stack space. If a new FOR command with the same control variable as that of an old FOR command is encountered, the old FOR will be terminated automatically.
STOP Command STOP
This command stops the execution of the program and returns control to direct commands from the input device. It can appear many times in a program but must be the last command in any given statement. i.e., it cannot be followed by semicolon and other commands.
Direct Commands
As defined earlier, a statement consists of a statement number followed by commands. If the statement number is missing, or if it is 0, the commands will be executed after you have typed the CR. All the commands described above can be used as direct commands. There are three more commands that can be used as direct command but not as part of a statement:
RUN will start to execute the program starting at the lowest statement number.
LIST will print out all the statements in numerical order.
NEW will delete all the statements.