LIMITED WARRANTY Radio Shack warrants for a period of 90 days from the date of delivery to customer that the computer hardware described herein shall be free from defects in material and workmanship under normal use and service. This warranty shall be void if the computer case or cabinet is opened or if the unit is altered or modified. During this period, if a defect should occur, the product must be returned to a Radio Shack store or dealer for repair.
A DIVISION OF TANDY CORPORATION One Tandy Center Fort Worth, Texas 76102
Second Edition - 1979 Second Printing - 1979 All rights reserved. Reproduction or use, without express permission, of editorial or pictorial content, in any manner, is prohibited. No patent liability is assumed with respect to the use of the information contained herein. While every precaution has been taken in the preparation of this book, the publisher assumes no responsibility for errors or omissions. Neither is any liability assumed for damages resulting from the use of the information contained herein.
CONTENTS Setting up the System.................................................................................................. i-iii 1 / General Information ........................................................................................... 1/1-10 2 / Commands............................................................................................................... 2/1-7 3 / Input-Output ........................................................................................................
This Reference Manual and You We've prepared this Reference Manual with the assumption that you - the user - already have considerable experience with programming in BASIC. Our LEVEL I User's Manual was written for the total beginner - and has been greeted with wide acclaim. We freely admit this Manual has not been written from the same perspective. If this is your first experience with programming, you may want to use the LEVEL I Users Manual to get the "hang" of it.
Setting up the System Carefully unpack the system. Remove all packing material. Be sure you locate all cables, papers, tapes, etc. Save the packing material in case you need to transport the system. Connecting the Video Display and Keyboard: 1. Connect the power cord from the Video Display to a source of 120 volts, 60 Hz AC power. Note that one prong of the AC plug is wider than the other - the wide prong should go into the widest slot of the AC socket.
A. Connect the black plug into the EAR jack on the side of the CTR-80. This connection provides the output signal from the CTR-80 to the TRS-80 (for loading Tape programs into the TRS-80). B. Connect the larger gray plug into the AUX jack on the CTR-80. This connection provides the recording signal to record programs from the TRS-80 onto the CTR-80's tape. Leave the AUX plug in whether you are recording or playing back cassette data. C. Connect the smaller gray plug into the smaller MIC jack on the CTR-80.
5. When you are not going to use a CTR-80 for loading or recording programs, do not leave RECORD or PLAY keys down (press STOP). 6. REWIND and FAST-FORWARD are not under remote control; simply press the appropriate key until the tape has moved to the desired position. 7. If you want to save a taped program permanently, break off the erase protect tab on the cassette (see CTR-80 Manual). 8. Do not expose recorded tapes to magnetic fields. Avoid placing your tapes near the Power Supply. 9.
1 / General Information This chapter will provide you with an overview of LEVEL II BASIC - what some of its special features are, how it differs from LEVEL I, and generally, what you need to get going. In addition, there's a short glossary at the end of the chapter. Power-Up Connect Keyboard-Computer, Video Display and Power Supply as explained in the previous section. Plug Video Display and Power Supply into 120-volt AC outlets.
RADIO SHACK LEVEL II BASIC READY >_ will appear on the screen. You are now ready to use LEVEL II BASIC. Reset The Reset button is on the back of the keyboard on the left side, next to the Expansion Card Edge. If your TRS-80 "freezes up" (you can't type anything) you can press Reset to return to the MEMORY SIZE? question. Any BASIC program in memory will be lost.
Special Function Keys LEVEL II BASIC offers the same special function keys as LEVEL I plus a few extras. The function of the key depends on what mode the Computer is in. Command Mode: [ENTER] Effects a carriage return; Computer "looks at" line just typed in and acts accordingly. If line just typed in has no line number, Computer will interpret and execute the statements contained in the line. If Line has a line number, Computer stores the line in program memory.
Variable Names Variable names must begin with a letter (A-Z) and may be followed by another letter or digit (0-9). So the following are all valid and distinct variable names: A ZZ Z1 A2 AA AZ G9 GP M MU Variable names may be longer than two characters, but only the first two characters will be used by the computer to distinguish between variables. For example "SUM", "SUB" and "SU" will be treated as one and tile same variable by LEVEL II BASIC.
The same variable name may be used for different variable types, and the Computer will still keep them distinct, because of the type declaration character: For example, A$, A%, A!, A# are distinct variable names. Variables without declaration characters are assumed to be single-precision; this assumption can be changed with DEFine statements (Chapter 4). Arrays Any valid variable name can be used to name an array in LEVEL II BASIC; and arrays are not limited to one dimension.
Relational Operators These are the same as LEVEL I. < (less than) > (greater than) =(equal to) <> (not equal to) <=(less than or equal to) >=(greater than or equal to) These operators are useful both for IF … THEN statements and for logical arithmetic. Example: 100 IF C<=0 THEN C=127 Logical Operators In LEVEL I BASIC, * and + were used to represent the logical operators AND and OR. In LEVEL II, we don't use symbols, we use AND and OR directly. We also have another operator, NOT.
String Operators Strings may be compared and concatenated ("strung together") in LEVEL ll. A whole chapter of this Manual is devoted to string manipulations.
Intrinsic Functions Most of the subroutines in the LEVEL I manual are built-in to LEVEL II. They are faster, more accurate (to seven digits generally), and much easier to use. For example, SIN(X), COS(X), TAN(X) can be computed directly. Graphics Level II has the same SET, RESET and POINT functions as LEVEL I for turning graphics blocks on and off and determining whether an individual block is on or off. (There are a few differences - see Chapter 8.
Keyboard Rollover With the LEVEL I TRS-80 (and many other computers) you have to release one key before the Computer will allow entry of another key. LEVEL II lets you hit the second key before you have released the first key. This is great for you touch typists. This feature also makes some of the LEVEL II keyboards susceptible to "keybounce", multiple entries for a single keystroke. To eliminate this annoyance, use the machine-language program, KBFIX, included on tape with affected LEVEL II computers.
Glossary for LEVEL II BASIC address a value specifying the location of a byte in memory; decimal values are used in LEVEL II alphanumerics the set of letters A-Z, the numerals 0-9, and various punctuation marks and special characters argument the value which is supplied to a function and then operated on to derive a result array an arrangement of elements in one or more dimensions ASCII American Standard Code for Information Interchange; in LEVEL II BASIC, decimal values are used to specify ASCII codes asse
2 / Commands Whenever a prompt > is displayed, your Computer is in the Command Mode. You can type in a command, [ENTER] it, and the Computer will respond immediately. This chapter describes the commands you'll use to control the Computer – to change modes, begin input and output procedures, alter program memory, etc. All of these commands – except CONT – may also be used inside your program as statements. In some cases, this is useful; other times it is just for very specialized applications.
CLEAR n When used without an argument (e.g., type CLEAR and hit [ENTER]), this command resets all numeric variables to zero, and all string variables to null. When used with an argument (e.g., CLEAR 100), this command performs a second function in addition to the one just described: it makes the specified number of bytes available for string storage. Example: CLEAR 100 makes 100 bytes available for strings. When you turn on the Computer a CLEAR 50 is executed automatically.
CLOAD? "file name" Lets you compare a program stored on cassette with one presently in the Computer. This is useful when you have dumped a program onto tape (using CSAVE) and you wish to check that the transfer was successful. If you labeled the file when you CSAVEd it, you may specify CLOAD? "file-name". Otherwise, if you don't specify a file-name, the first program encountered will be tested. During CLOAD?, the program on tape and the program in memory are compared byte for byte.
CSAVE "file name" Stores the resident program on cassette tape. (Cassette recorder must be properly connected, cassette loaded, and in the Record mode, before you enter the CSAVE command.) You must specify a file-name with this command. This file-name may be any alphanumeric character other than double-quotes ("). The program stored on tape will then bear the specified file-name, so that it can be located by a CLOAD command, which asks for that particular file-name.
EDIT line number Puts the Computer in the Edit Mode so you can modify your resident program. The longer and more complex your programs are, the more important EDIT will be. The Edit Mode has its own selection of subcommands, and we have devoted Chapter 9 to the subject. LIST line number-line number Instructs the Computer to display all program lines presently stored in memory. If you enter LIST without an argument, the entire program will scroll continuously up the screen.
RUN line number Causes Computer to execute the program stored in memory. If no line number is specified, execution begins with lowest numbered program line. If a line number is specified, execution begins with the line number. (Error occurs if you specify an unused line number.) Whenever RUN is executed, Computer also executes a CLEAR.
TROFF Turns off the Trace function. See TRON. TRON Turns on a Trace function that lets you follow program-flow for debugging and execution analysis. Each time the program advances to a new program line, that line number will be displayed inside a pair of brackets. For example, enter the following program: 10 20 30 40 PRINT "START" PRINT "GOING" GOTO 20 PRINT "GONE" Now type in TRON, [ENTER], and RUN, [ENTER]. <10> <20> <30> <30> START GOING <20> GOING <20> GOING etc.
3 / Input-Output The statements described in this chapter let you send data from Keyboard to Computer, Computer to Display, and back and forth between Computer and the Cassette interface. These will primarily be used inside programs to input data and output results and messages.
-------------------------------------------------30 X=25 40 PRINT 25 "IS EQUAL TO" X RUN 25 IS EQUAL TO 25 -------------------------------------------------70 A=5:B=10:C=3 80 PRINT ABC RUN 0 -------------------------------------------------Positive numbers are printed with a leading blank (instead of a plus sign); all numbers are printed with a trailing blank; and no blanks are inserted before or after strings (you can insert them with quotes as in line 20.
PRINT @ position, item list Specifies exactly where printing is to begin. (AT was used in LEVEL I BASIC.) The @ modifier must follow PRINT immediately, and the location specified must be a number from 0 to 1023. Refer to the Video Display worksheet, Appendix C, for the exact position of each location 0-1023: 100 PRINT @ 550, "LOCATION 550" RUN this to find out where location 550 is.
PRINT USING string; item list PRINT USING – This statement allows you to specify a format for printing string and numeric values. It can be used in many applications such as printing report headings, accounting reports, checks … or wherever a specific print format is required. The PRINT USING statement uses the following format: PRINT USING string; value String and value may be expressed as variables or constants.
+ When a + sign is placed at the beginning or end of the field, it will be printed as specified as a + for positive numbers or as a for negative numbers. – When a – sign is placed at the end of the field, it will cause a negative sign to appear after all negative numbers and will appear as a space for positive numbers. % spaces % To specify a string field of more than one character, % spaces % is used. The length of the string field will be 2 plus the number of spaces between the percent signs.
? +##.##,12.12 +12.12 ? "THE ANSWER IS "+##.##,-12.12 THE ANSWER IS -12.12 ? ##,##+,12.12 12.12+ ? "THE ANSWER IS ##.##+.",-12.12 THE ANSWER IS 12.12-. ? "THE ANSWER IS ##.##-.",12.12 THE ANSWER IS 12.12. ? ##.##-,-12.12 12.12? "**## IN TOTAL.",12.12 ** 12 IN TOTAL. ? **##.##,1212.12 1212.12 ? $$##.##,12.12 $12.12 ? "##,####",12121.2 12,121 ? "####,# IN TOTAL.",12121.2 12,121 IN TOTAL. ? "### IN TOTAL.",1212 % 1212 IN TOTAL.
Multiple strings or string variables can be joined together (concatenated) by these specifiers. The "!" sign will allow only the first letter of each string to be printed. For example: 10 INPUT A$, B$, C$ 20 PRINT USING "!";A$;B$;C$ And RUN it .… ? ABC,DEF,GHI ADG By using more than one "!" sign, the first letter of each string will be printed with spaces inserted corresponding to the spaces inserted between the "!" signs.
WHAT IS YOUR LAST NAME? JONES ENTER AMOUNT PAYABLE? 12345.6 PAY TO THE ORDER OF J. P. JONES *******$12,345.60 DOLLARS If you want to use an amount greater than 999,999 without rounding off or going into scientific notation, then simply add the double precision sign (#) after the variable P in Lines 60 and 100. You will then be able to use amounts up to 16 decimal places long. INPUT item list Causes Computer to stop execution until, you enter the specified number of values via the keyboard.
Be sure to enter the correct type of value according to what is called for by the INPUT statement. For example, you can't input a string-value into a numerical variable. If you try to, the Computer will display a ?REDO ?_ and give you another chance to enter the correct type of data value, starting with the first value called for by the INPUT list. NOTE: You cannot input an expression into a numerical value you must input a simple numerical constant.
Example: 100 INPUT "ENTER YOUR NAME AND AGE (NAME,AGE)";N$,A (RUN) ENTER YOUR NAME AND AGE (NAME,AGE)?_ DATA item list Lets you store data inside your program to be accessed by READ statements. The data items will be read sequentially, starting with the first item in the first DATA statement, and ending with the last item in the last DATA statement. Items in a DATA list may be string or numeric constants - no expressions are allowed.
50 100 110 120 130 140 150 160 170 PRINT "NAME","AGE" READ N$ IF N$="END" PRINT "END OF LIST":END READ AGE IF AGE < 18 PRINT N$,AGE GOTO100 DATA "SMITH, JOHN",30,"ANDERSON,T.M.",20 DATA "JONES, BILL", 15,"DOE,SALLY",21 DATA "COLLINS,W.P.",17,END RUN NAME JONES, BILL COLLINS,W.P. END OF LIST AGE 15 17 READY >_ The program locates and prints all the minors' names from the data supplied. Note the use of an END string to allow READing lists of unknown length.
PRINT #-1, item list Prints the values of the specified variables onto cassette tape. (Recorder must be properly connected and set in Record mode when this statement is executed.) The PRINT # statement must always specify a device number. This is because the TRS-80 can actually input/output to two cassette machines, once you've added the Expansion Interface described in Chapter 10. For normal use with just one recorder connected, the device number must be -1, e.g.
When this statement is executed, the Computer will turn on the tape machine, input values in the order specified, then turn off the tape machine and advance to the next statement. If a string is encountered when the INPUT list calls for a number, a bad file data error will occur. If there are not enough data items on the tape to "fill" the INPUT statement, an Out of Data error will occur.
4 / Program Statements LEVEL II BASIC makes several assumptions about how to run your programs. For example: * Variables are assumed to be single-precision (unless you use type declaration characters - see Chapter 1, "Variable Types"). * A certain amount of memory is automatically set aside for strings and arrays - whether you use all of it or not. * Execution is sequential, starting with the first statement in your program and ending with the last.
DEFINT letter range Variables beginning with any letter in the specified range will be stored and treated as integers, unless a type declaration character is added to the variable name. This lets you conserve memory, since integer values take up less memory than other numeric types. And integer arithmetic is faster than single or double precision arithmetic. However, a variable defined as integer can only take on values between -32768 and +32767 inclusive.
DEFSNG letter range Causes any variable beginning with a letter in the specified range to be stored and treated as single precision, unless a type declaration character is added. Single precision variables and constants are stored with 7 digits of precision and printed out with 6 digits of precision.
DEFSTR letter range Causes variables beginning with one of the letters in the specified range to be stored and treated as strings, unless a type declaration character is added. If you have CLEARed enough string storage space, each string can store up to 255 characters. Example: 10 DEFSTR L-Z Causes variables beginning with any letter L through Z to be string variables, unless a type declaration character is added. After line 10 is executed, the assignment L1 = "WASHINGTON" will be valid.
Example: 10 DIM A(5),B(2,3),C$(20) Sets up a one-dimension array A with subscripted elements 0-5; a two-dimension array B with subscripted elements 0,0 to 2,3; and a one-dimension string array C$ with subscripted elements 0-20. Unless previously defined otherwise, arrays A and B will contain single-precision values. DIM statements may be placed anywhere in your program, and the depth specifier may be a number or a numerical expression.
END Terminates execution normally (without a BREAK message). Some versions of BASIC require END as the last statement in a program; with LEVEL 11 it is optional. END is primarily used to force execution to terminate at some point other than the physical end of the program. Example: 10 20 . . . 99 100 110 INPUT S1,S2 GOSUB 100 END H=SQR(S1*S1+S2*S2) RETURN The END statement in line 99 prevents program control from "crashing" into the subroutine.
GOTO line number Transfers program control to the specified line number. Used alone, GOTO line number results in an unconditional (or automatic) branch; however, test statements may precede the GOTO to effect a conditional branch. Example: 200 GOTO 10 When 200 is executed, control will automatically jump back to line 10. You can use GOTO in the Command Mode as an alternative to RUN. GOTO line number causes execution to begin at the specified line number, without an automatic CLEAR.
Control branches from line 100 to the subroutine beginning at line 200. Line 210 instructs Computer to return to the statement immediately following GOSUB, that is, line 110. RETURN Ends a subroutine and returns control to statement immediately following the most recently executed GOSUB. If RETURN is encountered without execution of a matching GOSUB, an error will occur. See GOSUB.
Sample Program Using ON n GOTO 100 200 220 230 240 INPUT "ENTER A NUMBER";X ON SGN(X)+2 GOTO 220,230,240 PRINT "NEGATIVE":END PRINT "ZERO":END PRINT "POSITIVE":END SGN(X) returns -1 for X less than zero; 0 for X equal to zero; and +1 for X greater than 0. By adding 2, the expression takes on the values 1, 2, and 3, depending on whether X is negative, zero, or positive. Control then branches to the appropriate line number.
FOR counter = exp TO exp STEP exp NEXT counter Opens an iterative (repetitive) loop so that a sequence of program statements may be executed over and over a specified number of times. The general form is (brackets indicate optional material): line # . . . line # FOR counter-variable = initial value TO final value [STEP increment] [program statements] NEXT [counter-variable] In the FOR statement, initial value, final value and increment can be constants, variables or expressions.
10 20 30 FOR K=0 TO 1 STEP.3 PRINT K; NEXT RUN 0 .3 READY >_ .6 .9 After K=.9 is incremented by .3, K=1.2. This is greater than the final value 1, therefore loop ends without ever printing final value. -------------------------------------10 20 30 FORK = 4 TO 0 PRINT K; NEXT RUN 4 READY >_ No STEP is specified, so STEP 1 is assumed After K is incremented the first time, its value is 5. Since 5 is greater than the final value 0, the loop ends.
FOR-NEXT loops may be "nested": 10 20 30 40 50 60 FOR I=1TO3 PRINT"OUTER LOOP" FOR J=1 TO 2 PRINT" INNER LOOP" NEXT J NEXT I RUN OUTER LOOP INNER LOOP INNER LOOP OUTER LOOP INNER LOOP INNER LOOP OUTER LOOP INNER LOOP INNER LOOP Note that each NEXT statement specifies the appropriate counter variable; however, this is just a programmer's convenience to help keep track of the nesting order. The counter variable may be omitted from the NEXT statements.
ERROR code Lets you "simulate" a specified error during program execution. The major use of this statement is for testing an ON ERROR GOTO routine. When the ERROR code statement is encountered, the Computer will proceed exactly as if that kind of error had occurred. Refer to Appendix B for a listing of error codes and their meanings. Example Program: 100 ERROR 1 RUN ?NF ERROR READY >_ 1 is the error code for "attempt to execute NEXT statement without a matching FOR statement". See ON ERROR GOTO, RESUME.
The ON ERROR GOTO statement can be disabled by executing an ON ERROR GOTO 0. If you use this inside an error-trapping routine, BASIC will handle the current error normally. The error handling routine must be terminated by a RESUME statement. See RESUME. RESUME line number Terminates an error handling routine by specifying where normal execution is to resume. RESUME without a line number and RESUME 0 cause the Computer to return to the statement in which the error occurred.
REM Instructs the Computer to ignore the rest of the program line. This allows you to insert comments (REMarks) into your program for documentation. Then, when you (or someone else) look at a listing of your program, it'll be a lot easier to figure out. If REM is used in a multi-statement program line, it must be the last statement. Examples Program: 10 20 30 40 50 60 70 80 90 REM ** THIS REMARK INTRODUCES THE PROGRAM ** REM ** AND POSSIBLY THE PROGRAMMER, TOO.
100 IF 0<=X AND X<=90 THEN Y=X+180 If both expressions are True then Y will be assigned the value X+180. Otherwise, control will pass directly to the next program line, skipping the THEN clause. NOTE: THEN is optional in the above and similar statements. However, THEN is sometimes required to eliminate an ambiguity. For example, 400 IF Y=M THEN M=O won't work without THEN. 500 INPUT A$: IF A$="YES" THEN 100 600 INPUT A$: IF A$="YES" GOTO 100 The two statements have the same effect.
ELSE statement or line number Used after IF to specify an alternative action in case the IF test fails. (When no ELSE statement is used, control falls through to the next program line after a test fails.) Examples: 100 INPUT A$: IF A$="YES" THEN 300 ELSE END In line 100, if A$ equals "YES" then the program branches to line 300. But if A$ does not equal "YES", program skips over to the ELSE statement which then instructs the Computer to end execution.
Data Conversion Every number used during execution must be typed as either integer, single precision or double precision. Often this typing involves converting a number from one form to another. This may produce unexpected, confusing results unless you understand the rules governing such automatic typing and type conversion. Typing of Constants Constants are the actual numbers (not the variable names) used by LEVEL II BASIC during execution.
Type Conversion When operations are performed on one or two numbers, the result must be typed as integer, double or single-precision. When a +, -, or * operation is performed, the result will have the same degree of precision as the most precise operand. For example, if one operand is single-precision, and the other double-precision, the result will be double precision. Only when both operands are integers will a result be integer.
Effects of Type Conversions on Accuracy When a number is converted to integer type, it is "rounded down"; i.e., the largest integer, which is not greater than the number is used. (This is the same thing that happens when the INT function is applied to the number.) When a number is converted from double to single precision, it is "4/5 rounded" (the least significant digit is rounded up if the fractional part > =5. Otherwise, it is left unchanged).
.6666666865348816 READY >_ 2/3 is converted to a single precision constant; therefore only the first seven digits of A# are accurate. ---------------------------------10 20 A#=2/3# PRINT A# RUN .66666666666666667 READY >_ Since the expression 2/3# is evaluated as a double precision constant, all 16 digits of A# are accurate, with the least significant properly 4/5- rounded.
Assigning Double-Precision Values Here are three ways to be sure double-precision values are stored without any trailing "garbage digits". The first two (lines 10 and 20) are for entering constants (either in assignment statements or via INPUT responses); the third (line 30) is for converting from singleprecision to double-precision values. 10 20 30 40 A#=0.1D0 B#=0.1000000 C#=VAL(STR$(0.1)) PRINT A#,B#,C# RUN .1 .1 .
5 / Strings "Without string-handling capabilities, a computer is just a super-powered calculator." There's an element of truth in that exaggeration; the more you use the string capabilities of LEVEL II, the truer the statement will seem. LEVEL I BASIC offered two string variables, which could be input and output to make your programs look "friendly" (as in HELLO, BOB!). In LEVEL II you can do much more than that.
String Input/Output String constants -sequences of alphanumeric characters - may be input to a program just as numeric constants are input, using INPUT, READ/DATA, and INPUT # (input from cassette).
String Comparisons Strings may be compared for equality or alphabetic precedence. When they are checked for equality, every character, including any leading or trailing blanks, must be the same or the test fails. 600 IF Z$="END"THEN999 Strings are compared character-for-character from left to right. Actually, the ASCII codes for the characters are compared, and the character with the lower code number is considered to precede the other character. (See Appendix C, ASCII Codes.
String Operations Not including the functions described below, there is only one string operation - concatenation, represented by the plus symbol +. Example Programs: 10 20 30 40 50 CLEAR 75 A$="A ROSE" B$=" IS A ROSE" C$=A$+B$+B$+B$+".' PRINT C$ RUN A ROSE IS A ROSE IS A ROSE IS A ROSE. READY >_ In line 40, the strings are concatenated - strung together. 10 20 30 40 50 T$="100" SUB$="5" CODE="32L" LC$=T$+"."+SUB$+CODE$ PRINT LC$ RUN 100.
ASC (string) Returns the ASCII code (in decimal form) for the first character of the specified string. The string-argument must be enclosed in parentheses. A null-string argument will cause an error to occur. 100 PRINT ASC("A") 110 T$="AB": PRINT ASC(T$) Lines 100 and 110 will print the same number. The argument may be an expression involving string operators and functions: 200 PRINT ASC(RIGHT$(T$,1)) Refer to the ASCII Code Table, Appendix C.
CHR$ may also be used to display any of the 64 graphics characters. (See Appendix C, Graphics Codes.) 10 20 30 40 50 CLS FOR I=129 TO 191 PRINT I;CHR$(I), NEXT GOT0 50 (RUN the program to see the various graphics characters.) Codes 0-31 are display control codes. Instead of returning an actual display character, they return a control character. When the control character is PRINTed, the function is performed.
INKEY$ Returns a one-character string determined by an instantaneous keyboard strobe. The last key pressed before the strobe is returned. If no key is pressed during the strobe, a null string (length zero) is returned. This is a very powerful function because it lets you input values while the Computer is executing - without using the [ENTER] key. The popular video games which let you fire at will, guide a moving dot through a maze, play tennis, etc.
LEFT$ (string, n) Returns the first n characters of string. The arguments must be enclosed in parentheses. string may be a string constant or expression, and n may be a numeric expression Example Program 10 20 30 A$="TIMOTHY" B$=LEFT$(A$,3) PRINTB$;"--THAT'S SHORT FOR ";A$ RUN TIM--THAT'S SHORT FOR TIMOTHY READY >_ LEN (string) returns the character length of the specified string. The string variable, expression, or constant must be enclosed in parentheses.
MID$ (string, p, n) Returns a substring of string with length n and starting at position p. The string name, length and starting position must be enclosed in parentheses. string may be a string constant or expression, and n and p may be numeric expressions or constants. For example, M 1 D$(L$,3,1) refers to a one-character string beginning with the 3rd character of L$. Example Program: The first three digits of a local phone number are sometimes called the "exchange" of the number.
Example Program 10 20 30 40 50 A=58.5: B=-58.5 PRINT STR$(A) PRINT STR$(B) PRINT STR$(A+B) PRINT STR$(A)+STR$(B) RUN 58.5 -58.5 0 58.5-58.5 READY >_ Note that the leading blank is filled by the minus sign in STR$(B). STRING$ (n, "character" or number) Returns a string composed of n character-symbols. For example, STRING $(30,"*") returns "******************************" STRING$ is useful in creating graphs, tables, etc. The argument n is any numerical expression with a value of from zero to 255.
VAL (string) Performs the inverse of the STR$ function: returns the number represented by the characters in a string argument. The numerical type of the result can be integer, single precision, or double precision, as determined by the rules for the typing of constants (see page 4/18). For example, if A$="12" and B$="34" then VAL(A$+ "."+B$) returns the value 12.34. VAL(A$+"E"+B$) returns the value 12E34, that is 12 x 1034.
Coding/Decoding Program 5 10 20 30 40 60 70 80 90 100 110 120 130 140 150 160 170 CLS: PRINT CHR$(23) CLEAR 1000 INPUT "ENTER MESSAGE"; M$ FOR K=1 TO LEN(M$) T$=MID$(M$, K, 1 ) CD=ASC(T$)+5: IF CD>255 CD=CD-255 NU$=NU$ + CHR$(CD) NEXT PRINT "THE CODED MESSAGE IS" PRINT NU$ FOR K=1 TO LEN(NU$) T$=MID$(NU$, K, 1) CD=ASC(T$)-5: IF CD < 0 CD=CD+255 OLDS=OLD$+CHR$(CD) NEXT PRINT "THE DECODED MESSAGE IS" PRINT OLD$ RUN the program.
Here's a sample program using the INSTRING subroutine. (Type in the above lines 999-1020 plus the following.
6 / Arrays An array is simply an ordered list of values. In LEVEL II these values may be either numbers or strings, depending on how the array is defined or typed. Arrays provide a fast and organized way of handling large amounts of data. To illustrate the power of arrays, this chapter traces the development of an array to store checkbook data: check numbers, dates written, and amounts for each check. In addition, several matrix manipulation subroutines are listed at the end of this chapter.
Let's set up an array, CK, to correspond to the checkbook information table. Since the table contains 6 rows and 3 columns, array CK will need two dimensions: one for row numbers, and one for column numbers. We can picture the array like this: A(1,1)=025 . . . . A(6,1)=030 A(1,2)=1.0178 . . . . A(6,2)=1.1578 A(1,3)=10.00 . . . . A(6,3)=12.49 Notice that the date information is recorded in the form mm.ddyy. where mm=month number, dd=day of month, and yy = last two digits of year.
Now that our array is set up, we can begin taking advantage of its built-in structure. For example, suppose we want to add up all the checks written. Add the following lines to the program: 100 110 120 130 140 FOR ROW=1 TO 6 SUM=SUM+CK(ROW,3) NEXT PRINT"TOTAL OF CHECKS WRITTEN"; PRINT USING"$$###.##";SUM Now let's add program steps to print out all checks that were written on a given day. 200 210 230 240 250 260 270 PRINT "SEEKING CHECKS WRITTEN ON WHAT DATE (MM.
Other Types of Arrays Remember, in LEVEL II the number of dimensions an array can have (and the size or depth of the array), is limited only by the amount of memory available. Also remember that string arrays can be used. For example, C$(X) would automatically be interpreted as a string array. And if you use DEFSTR A at the beginning of your program, any array whose name begins with A would also be a string array.
To use this subroutine, your main program must supply values for three variables N1 (size of dim#1), N2 (size of dim#2) and N3 (size of dim#3). Within the subroutine, you can assign values to each element of the array using READ and DATA statements. You must supply I x J x K elements in the following order: row by row for K=1, row by row for K=2, row by row for K=3, and so on for each value of N3. 30200 REM MATRIX READ SUBROUTINE (3 DIMENSION) 30205 REM REQUIRES DATA STMTS.
Main program supplies values for variables N1 , N2, N3. Within the subroutine, you can assign values to each element of the array using the INPUT statement.
Matrix Addition (3 Dimensional) 30800 FOR K=1 TO N3 30810 FOR J = 1 TO N2 30820 FOR I=1 TO N1 30830 C(I,J,K)=A(I,J,K)+B(I,J,K) 30840 NEXT I 30850 NEXT J 30860 NEXT K 30870 RETURN ----------------------------------------------Array Element-wise Multiplication (3 Dimensional) 30900 FOR K=1 TO N3 30910 FOR J=1 TO N2 30920 FOR I=1 TON I 30930 C(I,J,K)=A(I,J,K)*B(I,J,K) 30940 NEXT I 30950 NEXT J 30960 NEXT K Multiplies each element in A times its corresponding element in B.
7 / Arithmetic Functions LEVEL II BASIC offers a wide variety of intrinsic ("built-in") functions for performing arithmetic and special operations. The special-operation functions are described in the next chapter. All the common math functions described in this chapter return single-precision values accurate to six decimal places. ABS, FIX and INT return values whose precision depends on the precision of the argument. The conversion functions (LINT, CDBL, etc.
CDBL (x) Returns a double-precision representation of the argument. The value returned will contain 17 digits, but only the digits contained in the argument will be significant. CDBL may be useful when you want to force an operation to be done in double-precision, even though the operands are single precision or even integers. For example CDBL (I%)/J% will return a fraction with 17 digits of precision.
EXP (x) Returns the "natural exponential" of X, that is, ex. This is the inverse of the LOG function, so X=EXP(LOG(X)). 100 PRINT EXP(-X) FIX (x) Returns a truncated representation of the argument. All digits to the right of the decimal point are simply chopped off, so the resultant value is an integer. For non-negative X, FIX(X)=lNT(X). For negative values of X, FIX(X)=INT(X)+1. For example, FIX(2.2) returns 2, and FIX(-2.2) returns -2.
RANDOM RANDOM is actually a complete statement rather than a function. It reseeds the random number generator. If a program uses the RND function, you may want to put RANDOM at the beginning of the program. This will ensure that you get an unpredictable sequence of pseudo-random numbers each time you turn on the Computer, load the program, and run it. 10 20 . . .
SQR(x) Returns the square root of the argument. SQR(X) is the same as X↑(1/2), only faster. 100 Y=SQR(X↑ ↑2-H↑ ↑2) TAN(x) Returns the tangent of the argument (argument must be in radians). To obtain the tangent of X when X is in degrees, use TAN(X*.01745329). 100 Z=TAN(2*A) NOTE: A great many other functions may be created using the above functions. See Appendix F, "Derived Functions".
8 / Special Features LEVEL II BASIC offers some unusual functions and operations that deserve special highlighting. Some may seem highly specialized; as you learn more about programming and begin to experiment with machine-language routines, they will take on more significance. Other functions in the chapter are of obvious benefit and will be used often (for example, the graphics functions).
Examples: 100 SET(RND(128)-1,RND(48)-1) Lights up a random point on the Display. 100 INPUT X,Y: SET(X,Y) RUN to see where the blocks are. RESET(x,y) Turns off a graphics block at the location specified by the coordinates x and y. This function has the same limits and parameters as SET(x,y). 200 RESET(X,3) CLS "Clear-Screen" – turns off all the graphics blocks on the Display and moves the cursor to the upper left corner. This wipes out alphanumeric characters as well as graphics blocks.
ERL Returns the line number in which an error has occurred. This function is primarily used inside an error-handling routine accessed by an ON ERROR GOTO statement. If no error has occurred when ERL is called, line number 0 is returned. However, if an error has occurred since power-up, ERL returns the line number in which the error occurred. If error occurred in direct mode, 65535 is returned (largest number representable in two bytes). Example Program using ERL 5 10 20 30 40 . . .
ERR /2+1 Similar to ERL, except ERR returns a value related to the code of the error rather than the line in which the error occurred. Commonly used inside an error handling routine accessed by an ON ERROR GOTO statement. See Appendix B, "Error Codes.
MEM Returns the number of unused and unprotected bytes in memory. This function may be used in the Command Mode to see how much space a resident program takes up; or it may be used inside the program to avert OM (Out of Memory) errors by allocating less string space, DIMensioning smaller array sizes, etc. MEM requires no argument. Example: 100 IF MEM < 80 THEN 900 110 DIM A(15) . . .
PEEK(address) Returns the value stored at the specified byte address (in decimal form). To use this function, you'll need to refer to two sections of the Appendix: the Memory Map (so you')) know where to PEEK) and the Table of Function, ASCII and Graphics Codes (so you'll know what the values represent). If you're using PEEK to examine object files, you'll also need a microprocessor instruction set manual (one is included with the TRS-80 Editor/Assembler Instruction Manual).
We can use POKE to turn on the entire PRINT position (6 bits) at one time. When we use SET, only 1 bit is turned on. Therefore POKE is about 6 times faster than SET. The following program demonstrates this speed. 10 20 30 40 50 CLS FOR X=15360 TO 16383 POKE X,191 NEXT GOT0 50 RUN the program to see how fast the screen is "painted" white. (191 is the code for "all bits on". 15360 to 16383 are the Video Display memory addresses.
USR (x) This function lets you call a machine-language subroutine and then continue execution of your BASIC program. "Machine language" is the low-level language used internally by your Computer. It consists of Z-80 microprocessor instructions. Machine-language subroutines are useful for special applications (things you can't do in BASIC) and simply because they can do things very fast (like white-out the Display).
For example, if the entry point is at 32700: 32700 decimal = 7FBC hexadecimal LSB = BC hexadecimal = 188 decimal MSB = 7F hexadecimal = 127 decimal So use the statements: POKE 16526, 188 POKE 16527, 127 to tell BASIC that the USR routine entry is at 32700. Making the USR call At the point in your BASIC program where you want to call the subroutine, insert a statement like X = USR(N) where N can be an expression and must have a value between -32768 and +32767 inclusive.
Control will pass back to your program, and the integer in HL will replace USR(N). For example, if the call was X=USR(N) then X will be given the value in HL. Sample USR routines Listed below is an assembled program to white out the display (an "inverse" CLEAR key!).
170 180 190 192 194 196 200 205 210 220 225 230 240 250 260 270 280 290 300 310 320 330 READ A POKE X,A NEXT X ' ' ******* CLEAR SCREEN & PRINT NUMBERS 1 THRU 100 ******* ' CLS PRINT TAB(15);"WHITE-OUT USER ROUTINE": PRINT FOR X=1 TO 100 PRINT X; A$=INKEY$: IF A$="@" THEN END NEXT X ' ' ******* JUMP TO WHITE-OUT SUBROUTINE ******* ' X=USR (0) FOR X=1 TO 1000: NEXT X 'DELAY LOOP GOTO 200 ' ' ******* DATA IS DECIMAL CODE FOR HEX PROGRAM ******* ' DATA 33,0,60,54,191,17,1,60,1,255,3,237,176,201 RUN the progr
7D03 CB15 00250 7D05 CB14 00260 7D07 C39A0A 00270 00280 ; 7D00 00290 RL RL JP L H PUTANS END SHIFT ;SHIFT L ;SHIFT H - ANSWER IN HL ;RETURN TO BASIC W/ANSWER The following program includes the decimal code for the SHIFT routine. The code is POKEd into RAM and then accessed as a USR routine. RUN the program; to stop, enter a value of zero.
VARPTR (variable name) Returns an address-value, which will help you locate where the variable name and its value are stored in memory. If the variable you specify has not been assigned a value, an FC error will occur when this function is called. If VARPTR(integer variable) returns address K: Address K contains the least significant byte (LSB) of 2-byte integer. Address K+1 contains the most significant byte (MSB) of integer.
The address will probably be in high RAM where string storage space has been set aside. But, if your string variable is a constant (a string literal), then it will point to the area of memory where the program line with the constant is stored, in the program buffer area. Thus, program statements like A$="HELLO" do not use string storage space. For all of the above variables, addresses (K-1) and (K-2) will store the TRS-80 Character Code for the variable name.
Examples A! = 2 will be stored as follows 2 = 10 Binary, normalized as .1 E2 = .1 x 22 So exponent of A is 128+2 = 130 (called excess 128) MSB of A is 10000000; however, the high bit is changed to zero since the value is positive (called hidden or implied leading one). So A! is stored as Exponent (K+3) MSB (K+2) Next MSB (K+l) 130 0 0 LSB (K) 0 A!= -.
The operations are performed in bitwise fashion; this means that each bit of the result is obtained by examining the bit in the same position for each argument. The following truth tables show the logical relationship between bits: OPERATOR AND OPERATOR OR OPERATOR NOT ARGUMENT I 1 0 1 0 ARGUMENT I 1 1 0 0 ARGUMENT 1 0 ARGUMENT 2 1 1 0 0 ARGUMENT 2 1 0 1 0 RESULT 1 0 0 0 RESULT 1 1 1 0 RESULT 0 1 EXAMPLES: (In all of the examples below, leading zeroes on binary numbers are not shown.
NOT 0 = -1 The bit complement of binary 0 to 16 places is six-teen ones (1111111111111111) or-1. Also NOT -1=0. NOT X NOT X is equal to -(X+1). This is because to form the sixteen bit two's complement of the number, you take the bit (one's) complement and add one. NOT 1 = -2 The sixteen bit complement of 1 is 1111111111111110, which is equal to -(1+1) or -2. A typical use of the bitwise operators is to test bits set in the TRS-80's input ports which reflect the state of some external device.
9 / Editing LEVEL I users undoubtedly spent lots of time retyping long program lines, all because of a typo, or maybe just to make a minor change. Once a line had been entered, there was no way to alter the line - without starting all over and retyping it. LEVEL II's editing features eliminate much of this extra work. In fact, it's so easy to alter program lines, you'll probably be able to do much more experimenting with multi-statement lines, complex expressions, etc.
Now type EDIT 100 and hit [ENTER]. The Computer will display: 100 _ You are now in the Edit Mode and may begin editing line 100. NOTE: EDITing a program line automatically clears all variable values and eliminates pending FOR/NEXT and GOSUB operations. If BASIC encounters a syntax error during program execution, it will automatically put you in the EDIT mode. Before EDITing the line, you may want to examine current variable values. In this case, you must type Q as your first EDIT command.
Now type 8 and hit the Space-bar. The cursor will move over 8 spaces to the right, and 8 more characters will be displayed. n ←(Backspace) Moves the cursor to the left by n spaces. If no number n is specified, the cursor moves back one space. When the cursor moves to the left, all characters in its "path" are erased from the display, but they are not deleted from the program line. Using this in conjunction with D or K or C can give misleading Video Displays of your program lines.
L (List Line) When the Computer is in the Edit Mode, and is not currently executing one of the subcommands below, hitting L causes the remainder of the program line to be displayed. The cursor drops down to the next line of the Display, reprints the current line number, and moves to the first position of the line. For example, when the Display shows 100 _ hit L (without hitting [ENTER] key) and line 100 will be displayed: 100 FOR I=1 TO 10 STEP .
I (Insert) Allows you to insert material beginning at the current cursor position on the line. (Hitting ← will actually delete material from the line in this mode.) For example, type and [ENTER] the EDIT 100 command, then use the Space Bar to move over to the decimal point in line 100. The Display will show: 100 FOR I=1 TO 10 STEP ._ Suppose you want to change the increment from .5 to .25. Hit the I key (don't hit [ENTER]) and the Computer will now let you insert material at the current position.
Q (Cancel and Exit) Tells Computer to end editing and cancel all changes made in the current editing session. If you've decided not to change the line, type Q to cancel changes and leave Edit Mode. H (Hack and Insert) Tells Computer to delete remainder of line and lets you insert material at the current cursor position. Hitting ← will actually delete a character from the line in this mode. For example, using line 100 listed above, enter the Edit Mode and space over to the last statement, PRINT"DONE".
nC (Change) Tells the Computer to let you change the specified number of characters beginning at the current cursor position. If you type C without a preceding number, the Computer assumes you want to change one character. When you have entered n number of characters, the Computer returns you to the Edit Mode (so you're not in the nC Subcommand). For example, using line 100, suppose you want to change the final value of the FOR-NEXT loop, from " 10" to " 15".
nKc (Search and "Kill") Tells the Computer to delete ail characters up to the nth occurrence of character c, and move the cursor to that position. For example, using the current version of line 100, suppose we want to delete the entire line up to the END statement. Type EDIT 100 ( [ENTER] ), and then type 2K: . This tells the Computer to delete all characters up to the 2nd occurrence of the colon. Display should show: 100 !FOR I=1 TO 15 STEP .
10 / Expansion Interface An Expansion Interface is available for the TRS-80 LEVEL II Computer. This interface will allow the use of additional Input/Output devices. There is also a provision for adding RAM memory. The Interface will allow four major additions to the TRS-80: 1. 2. 3. 4. An additional cassette deck A TRS-80 Line Printer Up to four Mini-Disks Up to 48K bytes of RAM Memory (32K in the Expansion Interface) These devices are available through your Radio Shack store or dealer.
This is a very simple application; however, very powerful routines can be constructed to allow input and output of data using two tapes simultaneously. Commands can also be given the device numbers to allow you to control the cassette decks. The cassette related commands are CLOAD, CSAVE, and CLOAD? When given the cassette numbers (1 or 2) they will specify the cassette that is to operate. For example: CLOAD #-1,"A" (the position of the comma is very important) will load the file "A" from cassette # 1.
LLIST Works like LIST, but outputs to the Printer LLIST List current program to printer. LLIST 100- Will list line 100 to the end of the program to the line printer. LLIST 100-200 Will list line 100 through 200 to the line printer. LLIST. Lists current line to the line printer. LLIST-100 Lists all lines up to and including line 100 to the line printer. See Chapter 2, LIST. LPRINT This command or statement allows you to output information to the Line Printer.
Codes Several codes are used to control the output of the line printer. You can LPRINT CHR$(n) where n is the TRS-80 Control Code from the chart below to execute these functions. LPRINT CHR$(10) will generate a line feed.
page, it figures the number of lines to leave blank and then it spaces down this amount to start the next page. When the Computer is first powered up, the page size is initialized to 66 lines per page, but you can change this by using the POKE command to change the value stored at address 16424. For example: POKE 16424,40 changes the size to 39 lines per page. The value at 16424 = page length + 1. At the beginning of your program you should set the line counter to 1. This only needs to be done once.
Mini-Disks - (DISK BASIC) The TRS-80 Mini Disk System is a small version of a floppy disk. The disk allows vast file storage space and much quicker access time than you get with tape storage. Drive 0 will contain about 58,880 bytes of free space for files. Each additional disk will have 83,060 bytes of file space. The disk system has its own set of commands, which allow manipulations of files and expanded abilities in file use. The TRS-80 Mini Disk System allows both sequential and random access.
Expansion of RAM Memory The TRS-80 Expansion Interface has provisions for adding extra RAM memory. This is done by adding RAM memory chips. You can add up to 32,768 additional bytes of memory. For price information and free installation, see your Radio Shack store or dealer.
11 / Saving Time and Space Most LEVEL II programs are faster and take up less memory space than their LEVEL I counterparts. But even with its inherently more efficient features, LEVEL II can be further streamlined by following a few simple guidelines when constructing your program. Saving Memory Space 1) When your program is operating properly, delete all unnecessary REM statements from your running version. 2) Do not use unnecessary spaces between statements, operators, etc.
Speeding Up Execution The speed at which a program is processed will depend on the complexity of the operations and the number of instructions. In most simple programs, speed will not be a factor. It will seem as though the answer is returned the moment you enter RUN. However, as you begin writing longer and more intricate programs, speed will become a significant factor. Here are some suggestions to guide you in designing speedier programs.
Appendix
A / Level II Summary Command Mode Function Page [ENTER] Return carriage and interpret command 1/3 [\À\] Cursor backspace and delete last character typed 1/3 [SHIFT] [\À\] Cursor to beginning of line; erase line 1/3 [\Ã\] Linefeed 1/3 : Statement delimiter; use between statements on same logical line 1/3 [\Â\] Move cursor to next tab stop. Tab stops are at positions 0, 8, 16, 24, 32, 48, and 56.
Type Declaration Characters Character Type Examples Page $ String A$, ZZ$ 1/4 % Integer A1%, SUM% 1/4 ! Single-Precision B!, N1! 1/4 # Double-Precision A#, 1/3# 1/4 D Double-Precision (exponential notation) 1.23456789D-12 1/4 E Single-Precision (exponential notation) 1.23456E+30 1/4 Arithmetic Operators Page + add 1/5 - subtract 1/5 * multiply 1/5 / divide 1/5 ↑ exponentiate (e.g.
Order of Operations Page ↑ (Exponentiation) 1/7 – (Negation) 1/7 *, / 1/7 +, - 1/7 Relational operators 1/7 NOT 1/7 AND 1/7 OR 1/7 Precedence order is from left to right for operators on the same level 1/7 Commands Command/Function Examples Page AUTO mm,nn Turn on automatic line numbering beginning with mm, using increment of nn. AUTO AUTO 10 AUTO 5,5 AUTO.,10 CLEAR 2/1 CLEAR n Same as CLEAR but also sets aside n bytes for strings.
Command/Function Examples Page CSAVE CSAVE "A" CSAVE #-2,"A" 2/4 Save a BASIC program on tape (with expansion interface) DELETE mm-nn Delete program line from line mm to line nn. DELETE 100 DELETE 10-50 DELETE . 2/4 EDIT mm Enter Edit Mode for line mm. See Edit Mode Subcommands below. EDIT 100 EDIT . 2/5 LIST mm-nn List all program lines from mm to nn. LIST LIST LIST LIST LIST 2/5 NEW NEW 2/5 RUN mm Execute program beginning at lowest numbered line or mm if specified.
Edit Mode Subcommands and Function Keys SubCommand Function Page ENTER End editing and return to Command Mode. 9/2 SHIFT ↑ Escape from X, I, and H subcommands and remain in Edit Mode. 9/3 nSpace-Bar Move cursor n spaces to right. 9/2 n← Move cursor n spaces to left. 9/3 L List remainder of program line and return to beginning of line. 9/4 X List remainder of program line, move cursor to end of line, and start Insert subcommand.
Input/Output Statements Statement/Function Examples PRINT exp* Output to Display the value of exp. Exp may be a numeric or string expression or constant, or a list of such items. PRINT A$ PRINT X+3 PRINT "D=" D Page 3/1-2 Comma serves as a PRINT modifier. Causes cursor to advance to next print zone. PRINT 1,2,3,4 PRINT "1","2" PRINT 1,,2 Semi-colon serves as a PRINT modifier. Inserts a space after a numeric item in PRINT list. Inserts no space after a string item.
Statement/Function Examples Page DATA item list Hold data for access by READ statement DATA 22,33,11,1.2345 DATA "HALL ","SMITH ","DOE 3/10 READ variable list Assign value(s) to the specified variable(s), starting with current DATA element. READ A,A1,A2,A3 READ A$,B$,C$,D 3/10-11 RESTORE Reset DATA pointer to first item in first DATA statement. RESTORE 3/11 Field Specifiers for PRINT USING statements Numeric Character Function Example Page # Numeric field (one digit digit per #).
String Character Function Example Page ! Single character. ! 3/5 %spaces% String with length equal to 2 plus number of spaces between % symbols. % % 3/5 Program Statements Statement/Function Examples Page DEFDBL letter list or range Define as double-precision all variables beginning with specified letter, letters or range of letters.
Statement/Function Examples Page LET variable=expression Assign value of expression to variable. LET is optional in LEVEL II BASIC. LET A$="CHARLIE" LET B1=C1 LET A%=I# 4/5 99 END 4/6 100 STOP 4/6 GOTO line-number Branch to specified line-number. GOTO 100 4/7 GOSUB line-number Branch to sub-routine beginning at line-number. GOSUB 3000 4/7 RETURN Branch to statement following last-executed GOSUB.
Statement/Functions Examples Page NEXT variable Close FOR-NEXT loop. Variable may be omitted. To close nested loops, a variable list may be used. See Chapter 4. NEXT NEXT I NEXT I,J,K 4/10-12 ERROR (code) Simulate the error specified by code (See Error Code Table). ERROR (14) 4/ 13 ON ERROR GOTO line-number If an error occurs in subsequent program lines, branch to error routine beginning at linenumber. ON ERROR GOTO 999 4/13 RESUME n Return from error routine to line specified by n.
Statement/Function Examples Page CLS 8/2 RESET(x,y) Turn off the graphics block with horizontal coordinate x and vertical coordinate y, 0 <= X < 128 and 0 <= Y < 48 RESET (8+B,11) 8/2 SET(x,y) Turn on the graphics block specified by coordinates x and y. Same argument limits as RESET SET(A*2,B+C) 8/1-2 POKE location, value Load value into memory location (both arguments in decimal form) 0 <= value <=255.
String Functions Function Operation Examples Page ASC(string) Returns ASCII code of first character in string argument. ASC(B$) ASC ("H") 5/5 CHR$(code exp) Returns a one-character string defined by code. If code specifies a control function, that function is activated. CHR$(34) CHR$(I) 5/5-6 FRE(string) Returns amount of memory available for string storage Argument is a dummy variable.
Arithmetic Functions* Function Operation (unless noted otherwise, -1.7E+38<= exp < =1.7E+38) ABS(exp) Examples Page Returns absolute value. ABS(L*.7) ABS(SIN(X)) 7/1 ATN(exp) Returns arctangent in radians. ATN(2.7) ATN(A*3) 7/1 CDBL(exp) Returns double-precision representation of exp. CDBL(A) CDBL(A+1/3#) 7/2 CINT(exp) Returns largest integer not greater than exp. Limits: -32768 <= exp <+32768. CINT(A#+B) 7/2 COS(exp) Returns the cosine of exp; assumes exp is in radians.
Function Operation Examples Page SGN(exp) Returns -1 for negative exp; 0 for zero exp; +1 for positive exp. SGN(A*B+3) SGN(COS(X)) 7/4 SIN(exp) Returns the sine of exp; assumes exp is in radians. SIN(A/B) SIN(90/57.29578) 7/4 SQR(exp) Returns square root of exp. Limits: exp must be non-negative. SQR(A*A-B*B) 7/5 TAN(exp) Returns the tangent of exp; assumes exp is in radians. TAN(X) TAN(X*.
Function Operation and Limits Examples Page USR(n) Branches to machine language subroutine. See Chapter 8. USR(0) 8/8-12 VARPTR(var) Returns the address where the specified VARPTR(A$) variable's name, value and pointer are VARPTR(N1 ) stored, var must be a valid variable name.
LEVEL II Reserved Words* @ ABS AND ASC ATN AUTO CDBL CHR$ CINT CLEAR CLOCK CLOSE CLS CMD CONT COS CSNG CVD CVI CVS DATA DEFDBL DEFFN DEFINT DEFSNG DEFUSR DEFSTR DELETE DIM EDIT ELSE END EOF ERL ERR ERROR EXP FIELD FIX * FIX FOR FORMAT FRE FREE GET GOSUB GOTO IF INKEY$ INP INPUT INSTR INT KILL LEFT $ LET LSET LEN LINE LIST LOAD LOC LOF LOG MEM MERGE MID$ MKD$ MKI$ MKS$ NAME NEW NEXT NOT ON OPEN OR OUT PEEK POINT POKE POS POSN PRINT PUT RANDOM READ REM RENAME RESET RESTORE RESUME RETURN RIGHT $ RND RSET SAV
Program Limits and Memory Overhead RANGES Integers Single Precision Double Precision -32768 to +32767 inclusive -1.701411E±38 to +1.701411E±38 inclusive -1.701411834544556E+38 to +1.
B / Error Codes CODE ABBREVIATION ERROR 1 NF NEXT without FOR 2 SN Syntax error 3 RG Return without GOSUB 4 OD Out of data 5 FC Illegal function call 6 OV Overflow 7 OM Out of memory 8 UL Undefined line 9 BS Subscript out of range 10 DD Redimensioned array 11 /0 Division by zero 12 ID Illegal direct 13 TM Type mismatch 14 OS Out of string space 15 LS String too long 16 ST String formula too complex 17 CN Can't continue 18 NR NO RESUME 19 RW RESUME w
Explanation of Error Messages NF NEXT without FOR: NEXT is used without a matching FOR statement. This error may also occur if NEXT variable statements are reversed in a nested loop. SN Syntax Error: This usually is the result of incorrect punctuation, open parenthesis, an illegal character or a mis-spelled command. RG RETURN without GOSUB: A RETURN statement was encountered before a matching GOSUB was executed. OD Out of Data.
LS String Too Long: A string variable was assigned a string value which exceeded 255 characters in length. ST String Formula Too Complex: A string operation was too complex to handle. Break up the operation into shorter steps. CN Can't Continue: A CONT was issued at a point where no continuable program exists, e.g., after program was ENDed or EDITed., NR No RESUME: End of program reached in error-trapping mode. RW RESUME without ERROR: A RESUME was encountered before ON ERROR GOTO was executed.
C / TRS-80 Character Codes Bit-Pattern Codes The following table illustrates the bit pattern for each of the 128 TRS-80 characters. The remaining 128 codes represent special graphics and space compression characters, as described later. See Notes. To use the table: Combine the most significant and least significant bit-patterns for a given character. For example, the character Q is represented by the pattern: 1010001 (decimal 81).
Decimal/Hexadecimal Codes Dec. Code 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 Hex. Code 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F 10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F Char. NULL BREAK STX ETX EOT ENO ACK BEL BKSP HT LF VT FF CR CURON CUROF DLE DC1 DC2 DC3 DC4 NAK SYN ETB CAN EM SUB ESC HOME BOL EREOL EREOF Dec. Code 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 Hex.
Control Codes: 0-31 Dec. Code Hex Code Function 0-7 00-07 None 8 08 Backspace and erases current character 9 09 None 10 0A Line feed with carriage return 11 0B Move carriage to top of form (page) 12 0C Move carriage to top of form (page) 13 0D Line feed with carriage return 14 0E Turns on cursor 15 0F Turns off cursor 16-22 10-16 None 23 17 Converts to 32 character/line mode (Certain features work differently in 32 cpl. CHR$(25) spaces only one-half to the right.
The following control characters may be entered directly from the Keyboard: Character Key Character Key BREAK [BREAK] EM [SHIFT] [\À\] BKSP [\À\] SUB [SHIFT] [\À\] HT [\Â\] ESC [SHIFT] [\À\] LF [\Á\] EREOF [CLEAR] CR [ENTER] SP [SPACE–BAR] CAN [SHIFT] [\À\] Graphics Codes: 128-191 For a description of the graphics characters, run the following program. If you do not have a line printer connected, change all LPRINTs to PRINTS and use the shift-@ key to pause the display.
Space Compression Codes: 192 to 255 Decimal Codes Hex Codes Function 192-255 C0-FF Tabs for 0 to 63 spaces, respectively The space-compression codes provide a compact means of representing strings of blanks from zero to 63 blanks. For example, PRINT CHR$(192) produces zero blanks; PRINT CHR$(193), one blank; PRINT CHR$(194), two blanks; … PRINT CHR$(225), 63 blanks.
Graphic Characters
D / Memory Map Decimal Address 0 Hex Address 0000 LEVEL II ROM 12287 12288 15359 15360 RESERVED FOR MEMORY-MAPPED I /O 3000 3001 3BFF 3C00 VIDEO MEMORY 16383 16384 16405 16413 16421 16429 16870 17129 BASIC VECTORS (RST's 1-7) KEYBOARD DCB 3FFF 4000 4015 4010 VIDEO DCB LINE PRINTER DCB 4025 402D RESERVED 41EC I/O BUFFER BASIC PROGRAM TEXT 42E9 SIMPLE VARIABLES ARRAYS FREE MEMORY STACK STRING SPACE RESERVED WITH MEM.
Important Addresses Decimal Hexadecimal 14302 14303 14304 14305 14308 14312 14316 16405 16406 16407 16408 16409 16410 16411 16412 16413 16414 16415 16416 16417 16418 16419 16420 16421 16422 16423 16424 16425 16426 16427 16428 16464 16466 16478 17128 37DE 37DF 37E0 37E1 37E4 37E8 37EC 4015 4016 4017 4018 4019 401A 401B 401C 401D 401E 401F 4020 4021 4022 4023 4024 4025 4026 4027 4028 4029 402A 402B 402C 4050 4052 405E 42E8 Communication Status Address Communication Data Address Interrupt Latch Address Dis
E / Internal Codes for BASIC Keywords The following are the internal codes that the Computer uses to store BASIC keywords. If you PEEK at the program buffer area (starting at address 17129 in decimal) you will find your program stored in the following codes. Dec. Code BASIC Keyword Dec.
Dec. Code 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 BASIC Keyword + – * / ↑ AND OR > = < SGN INT ABS FRE INP POS SQR RND LOG EXP COS SIN TAN ATN PEEK CVI Dec.
F / Derived Functions Function Function Expressed in Terms of Level II Basic Functions SECANT COSECANT COTANGENT INVERSE SINE INVERSE COSINE INVERSE SECANT INVERSE COSECANT INVERSE COTANGENT HYPERBOLIC SINE HYPOBOLIC COSINE HYPERBOLIC TANGENT HYPERBOLIC SECANT HYPERBOLIC COSECANT HYPERBOLIC COTANGENT INVERSE HYPERBOLIC SINE INVERSE HYPERBOLIC COSINE INVERSE HYPERBOLIC TANGENT INVERSE HYPERBOLIC SECANT INVERSE HYPERBOLIC COSECANT INVERSE HYPERBOLIC COTANGENT SEC(X) = 1/COS(X) CSC(X) = 1/SIN(X) COT(X) = 1/
G / Base Conversions The following table lists base conversions for all one-byte values. DEC. BINARY HEX. OCT. DEC. BINARY HEX. OCT.
DEC. BINARY HEX. OCT. DEC. BINARY HEX. OCT.
DEC. BINARY HEX. OCT. DEC. BINARY HEX. OCT.
H / User Programs Special Keyboard Input Routine Here's a general-purpose keyboard input routine (lines 100-175) for use in any program where the user will need to input a specific number of characters. Lines 1000-1040 contain a demonstrator program, which calls the routine. When the main program asks for the field length, you can type in either a negative or positive number.
700 ' 800 ' *** MAIN PROGRAM *** 900 ' 1000 PRINT: FL$="": INPUT"FIELD-LENGTH (FL) = ";FL$ 1005 IF FLT<>"" THEN FL=VAL(FL$) ELSE PRINTTAB(20);CHR$(27);FL 1006 IF ABS(FL) > 63 THEN PRINT "ENTER A VALUE IN THE RANGE <-63,+63>": GOTO 1000 1007 IF FL=0 THEN END 1010 GOSUB 100: PRINT: PRINT TAB(16)"LENGTH ="LEN(IN$) 1020 PRINT TAB(16)"STRING = "CHR$(136)IN$;CHR$(136) 1030 PRINT TAB(16)" VALUE = "VAL(IN$) 1040 GOTO 1000 Storing a USR Routine in a String This program illustrates a special technique for storing ma
157 ' 160 INPUTA$: IF A$="END" THEN PRINT@576,CHR$(31);: END 170 IF N<6 THEN N=N+1 174 ' 175 ' IF BOTTOM OF SCREEN HAS 6 LINES. THEN SCROLL 176 ' 180 IF N=6 THEN GOSUB 1000: PRINT@896,CHR$(31); 190 GOT0160 700 800 ' *** SCROLL ROUTINE *** 900 ' 1000 POKE 16526 PEEK(VARPTR
230 240 250 260 270 280 290 300 310 320 330 340 350 360 370 IF A(L) < A(J) THEN TEMP = RtJ): A(J) = A(L): A(L) = TEMP: J = J-D: IF J>0 THEN 220 NEXT I GOTO 170 END ' PRINT SORTED ARRAY ' PRINT: INPUT"PRESS 'ENTER' TO LIST SORTED ARRAY";A$ FOR I=1 TO N PRINT A(I), NEXT I END ' STORE NUMBER OF DATA ELEMENTS HERE DATA 10 ' STORE ACTUAL DATA HERE DATA 10.8,9,8.7,8.3,7,3.333,2.010,2,10,0.
• • Landing conditions are different for each planetary body because each has its own particular gravity: Earth = 980 cm/sect ; Moon = 162 cm/sect : Mars = 372 cm/sect ; Vesta = 17.5 cm/sect . The up arrow ↑ appears as a left bracket [ in this printout. Remember to enter it as an up arrow (for exponentiation).
1040 1050 1100 1110 1120 1140 1150 1160 5000 5010 5020 IF V2<5000 PRINT "MADE A NEW CRATER" : GOTO 5000 IF V2>4999 PRINT "BORED A HOLE INTO THE PLANET" : GOTO 5000 IF V2<1 PRINT "NICE TOUCH--VERY GOOD" : GOTO 5000 IF V2<5 PRINT "NOT T00 BAD" : GOTO 5000 PRINT "KIND OF ROUGH" : GOTO 5000 IF V2<30 PRINT "YOU WILL NOT BE ABLE TO TAKE OFF" : GOTO 5000 IF V2<45 PRINT "YOU ARE INJURED.
410 415 420 430 440 450 460 470 480 500 510 520 530 540 550 600 610 620 630 640 FOR I=1 TO P1 :IF N$=N$(I) GOTO430 NEXT PRINT"NAME NOT IN FILE" :GOTO460 PRINT"ENTER THE CORRECTED INFO.: NAME, ADDRESS, PHONE" INPUT N$(I), A$(I), P$(I) PRINT"THE LINE NOW READS :" :PRINT N$(I), A$(I), P$(I) INPUT"FOR ANOTHER CORRECTION TYPE 1. OTHERWISE 0"; X IF X=1 GOTO400 GOTO20 CLS :INPUT "MAKE PREPARATIONS FOR CASSETTE WHEN READY HIT ENTER": X PRINT"COPYING...
400 'ASA 410 PRINT"ENTER 2 ANGLES AND 1 SIDE: THETA1, THETR2, AB: 420 INPUT T1, T2, L2 425 T1 = (T1 * 3.14159) / 180 : T2 = (T2 * 3.14159) / 180 430 Y3 = L2 * SIN(T1) 440 B1 = COSC(T1) * L2 450 B2 = Y3 / TAN(T2) 460 L1 = B1 + B2 : X3 = B1 : IF L2 > L1 THEN X = L1 : L1 = L2 : L2 = X 470 AR = (L2 * Y3) / 2 500 CLS : F=1 : IF L1>50 OR Y3>30 OR L2>50 THEN GOSUB708 510 VC = (3.14159 * ( L1 * F - X3 * F) * (Y3 * F) C2) / 3 520 VS = (3.
1 CLS:PRINT : PRINT CHR$(23) ; "HIT 'Z' KEY TO AIM LEFT." 2 PRINT "HIT '/' KEY TO RIM RIGHT." 3 PRINT "HIT SPACE BAR TO FIRE.
100 IF Y=47 THEN 120 105 IF Y=0 GOSUB 900 110 IF Y <> -1 OR X <> -1 THEN 60 120 Y= Y- 2 * D : D= -D : GOTO 60 500 IF X=Z OR X=Q+Z OR X=2 * Q+Z OR X=3 * Q+Z OR X=Q * 4+Z THEN IF Y=24 GOSUB 600 510 IF Y=23 OR Y=24 OR Y=25 THEN IF X=Z GOSUB 600 520 RETURN 600 X=1 610 FOR Z=1 TO 50 : PRINT@ 550,"HIT !!!"; : NEXT 620 FOR Z=1 TO 25 : PRINT@ 550," ";: NEXT 630 X=X+1 : IF X<5 GOTO 610 640 GOTO 2000 700 X=X-2 * Q : Q= -Q : RETURN 900 T$ = INKEY$ : A$ = "" : B$ = "" : C$ = "" 1000 A$= INKEY$ : IF LEN(A$) = 0 THEN 100
I / Converting LEVEL I Programs Because of the differences between LEVEL I BASIC and LEVEL II BASIC, you will need to use the CONV program to translate LEVEL I programs to run under LEVEL II BASIC. Even after converting a program, you'll need to make minor changes in punctuation, syntax and function arguments before the program will run. The following is a list of the kinds of changes you'll need to make on the converted program. 1.
This statement would allow you to use array elements A(0) through A(30). Of course, you can use any variable name as an array name in LEVEL II BASIC. 6. In LEVEL I, an INPUT statement allows you to type in variables and expressions, not just constants. In LEVEL 11, you have to type in a constant, either string or numeric, depending on the INPUT variable.
J / Important Information for Cassette Users Free Modification for LEVEL II Units A modification that helps cassette loads in LEVEL II computers is available free to TRS-80 LEVEL II owners. This modification makes the volume setting less critical so that variations in different tapes usually will not require volume readjustments. Some of the more recent LEVEL II Keyboard units have had this modification factory-installed.
Notice that volume ranges for LEVEL I and LEVEL II are different. This is because the LEVEL II data transfer rate is faster (500 baud vs. 250 baud). Also, notice that pre-recorded Radio Shack programs need a slightly higher volume setting than that required by your own CSAVEd tapes. The prerecorded tapes are produced with high-speed audio equipment at a slightly lower level than the CSAVE process provides.
LEVEL I Sometimes you will get an error message during an attempted CLOAD. This means that some information was lost or garbled. Adjust the volume level slightly and try again. LEVEL II In case of an error message, proceed as above. With SYSTEM tapes, a "C" will appear in place of one asterisk. In LEVEL II, there is also a rare case in which the program has not loaded correctly even though no error is generated. So after CLOADing a program, be sure to LIST it.
Index
Index Subject Page Subject Page Accuracy...................................................4/18 4/21 Constants Precision of .................................4/20-4/22 Typing of............................................. 4/18 Conversion of...................................... 4/19 AND ................................................. 1/6, 8/15-8/17 CONT................................................................ 2/3 Arithmetic Functions ..................................
Index Subject Page Subject Page Logical Operators..............................1/6,8/15-8/17 LPRINT ................................................... 10/3-10/5 File Name ....................................................2/2-2/4 FIX ..................................................................... 7/3 Machine Language Call......................2/6,8/8-8/12 FOR TO STEP NEXT .............................4/10-4/12 MEM ..................................................................
Index Subject Page Subject Page POINT................................................................8/2 Specifications ................................................. A/17 POKE .................................................................8/6 Speeding Up Execution .................................. 11/2 Port (see INP and OUT) .............................8/4,8/5 SQR.................................................................... 7/5 POS ...................................................
RADIO SHACK A DIVISION OF TANDY CORPORATION U.S.A.: FORT WORTH, TEXAS 76102 CANADA: BARRIE, ONTARIO L4M 4W5 TANDY CORPORATION 2980086 AUSTRALIA BELGIUM U.K. 280-316 VICTORIA ROAD RYDALMERE, N.S.W. 2116 PARC INDUSTRIEL DE NANINNE 5140 NANINNE BILSTON ROAD WEDNESBURY WEST MIDLANDS WS10 7JN Printed in U.S.A.