BASIC DOCUMENTATION PAGE 2 03/06/81 TABLE OF CONTENTS CHAPTER 1 INTRODUCTION. . . . . . . . . . . . . . . . . . . . 1-1 1.1 STATEMENT AND LINE FORMAT. . . . . . . . . . . . 1-1 1.2 VARIABLE NAMES . . . . . . . . . . . . . . . . . 1-2 1.3 VIRTUAL ARRAYS . . . . . . . . . . . . . . . . . 1-2 1.4 STRING CONSTANTS . . . . . . . . . . . . . . . . 1-3 1.5 DATA AND FILE PRESERVATION . . . . . . . . . . . 1-3 1.6 STRING VARIABLES . . . . . . . . . . . . . . . . 1-3 1.7 EXPONENTIATION . . . . . . . . . . . . . . . . . 1-4 1.8 MCR COMMAND LINE . . . . . . . . . . . . . . . . 1-4 1.9 CONTROL C. . . . . . . . . . . . . . . . . . . . 1-5 1.10 CONTROL O . . . . . . . . . . . . . . . . . . . 1-5 1.11 LOGICAL EXPRESSIONS . . . . . . . . . . . . . . 1-5 CHAPTER 2 LOADING/RUNNING/SAVING PROGRAMS . . . . . . . . . . 2-1 2.1 STOP . . END . . . . . . . . . . . . . . . . . . 2-1 2.2 RUN. . . . . . . . . . . . . . . . . . . . . . . 2-1 2.3 CLEAR. . . . . . . . . . . . . . . . . . . . . . 2-2 2.4 SAVE [N1][-N2][,N3...]. . 2-2 2.5 OLD . . . . . . . . . 2-2 2.6 CHAIN . . . 2-2 2.7 OVERLAY . . 2-3 2.8 LIST [N1][-N2][,N3...] . . . . . . . . . . . . . 2-3 2.9 DELETE N1[-N2][,N3...] . . . . . . . . . . . . . 2-3 2.10 EXIT. . . . . . . . . . . . . . . . . . . . . . 2-4 2.11 STEP [LINE #] . . . . . . . . . . . . . . . . . 2-4 2.12 CON [LINE #]. . . . . . . . . . . . . . . . . . 2-4 CHAPTER 3 PROGRAM STATEMENTS. . . . . . . . . . . . . . . . . 3-1 3.1 GOSUB N . . GOTO N . . . . . . . . . . . . . . . 3-1 3.2 ON GOTO . . . . . . . 3-1 3.3 RETURN . . . . . . . . . . . . . . . . . . . . . 3-1 3.4 DIM. . . . . . . . . . . . . . . . . . . . . . . 3-2 3.5 DIM #N, . . . . . . . . . . . . . . . . . . 3-2 3.6 DEF. . . . . . . . . . . . . . . . . . . . . . . 3-3 3.7 LET. . . . . . . . . . . . . . . . . . . . . . . 3-3 3.8 IF . . . . . . . . . . . . . . . . . . . . . . . 3-4 3.9 REM . . !. . . . . . . . . . . . . . . . . . . . 3-4 3.10 READ . . DATA . . . . . . . . . . . . . . . . . 3-4 3.11 FOR . . . . . . . . . . . . . . . . . . . . . . 3-5 3.12 NEXT. . . . . . . . . . . . . . . . . . . . . . 3-5 3.13 BREAK . . . . . . . . . . . . . . . . . . . . . 3-5 3.14 SET PROMPT/TRACE/READ-PASS-ALL ON/OFF . . . . . 3-6 3.15 ON ERROR GOTO . . . . . . . . . . . . . . . . . 3-6 3.16 SLEEP . . . . . . . . . . . . 3-7 3.17 WAIT . . . . . . . . . . . . 3-7 3.18 PRIORITY . . . . . . . . . . . . . 3-7 3.19 TRACE ON AND OFF. . . . . . . . . . . . . . . . 3-8 CHAPTER 4 ARITHMETIC FUNCTIONS. . . . . . . . . . . . . . . . 4-1 4.1 RND. . . . . . . . . . . . . . . . . . . . . . . 4-1 4.2 RANDOMIZE. . . . . . . . . . . . . . . . . . . . 4-1 4.3 ABS. . . . . . . . . . . . . . . . . . . . . . . 4-1 BASIC DOCUMENTATION PAGE 4 03/06/81 7.10 MATXT . . CATXT . . RATXT . . . . . . . . . . . 7-7 7.11 CQNAM . . RQNAM . . . . . . . . . . . . . . . . 7-7 7.12 SPAWNB. . . . . . . . . . . . . . . . . . . . . 7-8 APPENDIX A BASIC ERROR VALUES . . . . . . . . . . . . . . . . A-1 APPENDIX B SAMPLE LOADABLE MACRO SUBROUTINE . . . . . . . . . B-1 APPENDIX C USEFUL INTERNAL BASIC SUBROUTINE CALLS . . . . . . C-1 APPENDIX D INDEX. . . . . . . . . . . . . . . . . . . . . . . D-1 INTRODUCTION PAGE 1-2 03/06/81 line without using a new line number by starting the continued line with a tab or two spaces. Continued lines are treated the same way as in BASIC-PLUS: the end of a physical line is ignored during execution so long as an individual BASIC element is not broken across line boundaries. The end of line does not serve to end a statement except when there is no continued line following it. Thus a statement which begins on a continued line must ei- ther have a concatenation character at the start of its line or the end of the previous line. There is an exception in the case of a comment (! only) terminating the previous line, in which case no concatenation character is used. Care should be taken not to start an immediate mode command with a tab or double space as it will not be executed but added to the existing program as a continuation of the last entered program line. Note that checking of program statements for verb legality as they are read in by the interpreter is no longer done as it was in earlier versions. All checking is now done at run time. 1.2 VARIABLE NAMES Variable names may be one or two characters of which the first is alpha and the second (if used) is alphanumeric, followed by an optional type character. If no type character is used, the type is REAL*4. A $ denotes a string variable, % is an integer vari- able (16 bits) and & is a byte variable (8 bits). Note that un- like standard BASIC, the second character of the variable name is allowed to be alphabetic. In order to gain this flexibility in naming variables, some restrictions had to be made in the allowed format of the program text: spaces are not allowed within a var- iable name; variable names must not be the same as BASIC key words (e.g. TO and IF). Also, ambiguities may sometimes arise when a variable is next to a keyword in the program text. This can usually be resolved by re-writing the text. Although it is theoretically possible to resolve these cases in the interpreter, the expense in terms of interpreter code length and execution time does not seem to warrant it. Consider the following example: 100 IF A < MT OR B=5. THEN 500 The T of MT and the O of OR are misinterpreted by BASIC to form the keyword TO. The statement can be rewritten unambiguously as follows: 100 IF (A < MT) OR (B=5.) THEN 500 1.3 VIRTUAL ARRAYS Virtaul arrays are used to store extensive numbers of variable values, usually more than is practical to store in an in-memory array. The use of virtual arrays involves a special form of the INTRODUCTION PAGE 1-4 03/06/81 1.7 EXPONENTIATION Exponentiation (^) is done in two ways. If the exponent is an integer, the base is multiplied (or divided) by itself the appro- priate number of times. If the exponent contains a fractional part, a log - antilog calculation sequence is used. 1.8 MCR COMMAND LINE BASIC is called from the MCR by typing BASIC (or BAS) in response to the MCR prompt. A may follow for normal interactive use or one of two other options may follow before for special uses. If a space and a ? followed by an arithmetic expression follows BAS, the value of the expression will be printed on the next line followed by a return to the MCR. This is useful for quick desk calculator type calculations. If a space (or tab) and a file name with an optional switch fol- low, then that file will be read in as a user program just as in the OLD command. If the switch (/RN) is specified, the program will also be run as though the RUN command had been typed. A switch of the form "/RN:NNN" will cause the program to start execution at line # NNN. If the switch (/CO) is added, then the file retrieved will be as- sumed to be previously compiled and a default extension of BAC will be used. NOTE Note that no quotes are used here as opposed to the OLD and RUN commands. Examples: MCR>ABASB MCR>ABASIC PROG.BAS/RNB MCR>ABAS PROG/RN:150B MCR>ABAS ? 4*3+2B INTRODUCTION PAGE 1-6 03/06/81 ANOT (X1 < 1 AND A >= 5)B LOADING/RUNNING/SAVING PROGRAMS PAGE 2-2 03/06/81 2.3 CLEAR This command clears the user data area. It closes all user files before doing the clear operation. 2.4 SAVE [N1][-N2][,N3...] Primarily an immediate mode command. It makes a copy of the pre- sent program on the file named in the string filespec (string variable or string in quotes). Optional line numbers or line number ranges can be included. The optional switch will produce a psuedo-compiled version which can be read back with the same switch without re-interpreting the code thus saving a considerable amount of time for long programs. The default extension will be BAC if the switch is included. The default file specifier is: SY:PROGRAM.BAS or the name, ex- tension and device in the last OLD, RUN, CHAIN or OVERLAY com- mand. Example: ASAVE "PROGRAM"B ASAVE "LP:"B ASAVE "DK2:PROG.BAS"B ASAVEB 2.5 OLD The OLD command reads in a previously saved or edited program from the file named in the string filespec (as in SAVE). The op- tional switch, when specified, causes truncation of REM and ! statements. The default file specifier is: SY:PROGRAM.BAS The CO switch indicates that a compiled basic file is to be used (de- fault extension BAC). Example: AOLD "PROG1"B AOLD "DK3:PROGRAM.BAS"B 2.6 CHAIN The CHAIN command reads in another BASIC program while preserving variables and open files' FCB's. GOSUB/RETURN pointers, FOR loop control tables, user DEFined functions and scratch items are all deleted from the user data area. Thus user functions must be re- defined in any new program module. LOADING/RUNNING/SAVING PROGRAMS PAGE 2-4 03/06/81 ADELETE 30B ADELETE 50-70B ADELETE 10-40,60-80B 2.10 EXIT This statement stops program execution and exits from BASIC to the MCR. All files are closed before exit. It is equivalent to a STOP followed by a ^Z from the keyboard. Example: A1000 EXITB 2.11 STEP [LINE #] This statement allows one to step through a program one line at a time. The optional line number may be used to start at a differ- ent line. If no line number is specified, execution resumes at the line following the last stop. Note that if a branch is taken the line being executed, the program will not stop until the next line after the branch. The stop uses the same internal facili- ties as the ^B break feature. Example: ASTEPB ASTEP 510B 2.12 CON [LINE #] This command allows one to resume execution of a program after stopping it for interactive de-bugging. When used with the op- tional line number, it functions just like GOTO with the excep- tion that the next available line after the one specified is used if there is no exact match. If no line number is specified, exe- cution is resumed at the line following the last stop. Example: ACONB ACON 100B PROGRAM STATEMENTS PAGE 3-2 03/06/81 i.e. it must be the first or third etc. statement in the line. Example: A10 RETURNB 3.4 DIM Declares size of arrays and strings. Also specifies strings as either fixed or variable length. Arrays may have one or two sub- scripts. String lengths are indicated in square brackets [ ] which are followed by a 'V' if the string is to have variable length. In the case of a variable length string, the length is the maximum length which the string may assume. A string undeclared in a DIM statement is assumed to be varible length with a max of 15 char- acters. For strings declared in a DIM statement, the defaults are 15 character length (or max length) and fixed type. Arrays have a zeroth element which is the same as the unsub- scripted variable name: i.e. B(0) or B(0,0) is the same as B. Unlike other versions of BASIC, arrays do not have any assumed dimensions; they must be declared if they are to be used. Example: A10 DIM A(5,5),B$[10]B A20 DIM C$[20]V(10,10),D$(5)B 3.5 DIM #N, This statement declares certain variables as "virtual arrays" and defines their allocation on the file whose LUN is the value of "exp". A virtual array has its values stored on a file and main- tains only a small part of the array in memory at any one time (currently 512 bytes - 1 disk block). The DIM # statement only defines the mapping of the array onto the file. The file itself must be opened via an OPEN statement using the /BL switch. Consequently, several DIM # statements may define several map- pings of different variables onto the same file with an effect similar to a FORTRAN EQUIVALENCE statement. The rules for mapping follow RSTS BASIC-PLUS. Essentially, no array element may cross block boundaries. This implies that var- iable sizes must be powers of two. Numeric variables automati- cally fulfill this condition. Strings are allocated their speci- fied size whether fixed or variable. Variable length strings are null padded on disk, and when used in a program context are auto- matically trimmed to their size without the null padding. Fixed length virtual strings, as with standard fixed length strings, are blank padded. If the allocation of a variable in a DIM # list would cause it to cross block boundaries because of previous PROGRAM STATEMENTS PAGE 3-4 03/06/81 3.8 IF Format: IF THEN [ELSE ][ELSE ] IF THEN " " IF GOTO " " If the logical expression is true (see Logical Expressions), then the line number following the THEN or GOTO is branched to or all statements following THEN up to the end of the line or an ELSE are executed. If the condition is false, a matching ELSE is searched for. If found, the line number following the ELSE is branched to or all statements following the ELSE to the end of the line or the next ELSE are executed. If no matching ELSE is found, execution con- tinues on the following line. IFs and ELSEs are paired like matching parentheses from the in- side out. That is, an ELSE is matched with the IF most immedi- ately preceding it in the line which does not already have a matching ELSE. This implementation of IF-THEN-ELSE is intended to match BASIC-PLUS. Example: A10 IF A > B THEN STOPB A20 IF A$ <> B$ GOTO 110 ELSE 500B A30 IF A >= 12.5 THEN 160 ELSE PRINT "A < 12.5" : GOTO 300B 3.9 REM . . ! The REMark statement is used to insert comments into the text of the BASIC program. It has two forms: REM and !. All text fol- lowing the REM or ! will be ignored by the BASIC interpreter up to the end of a physical line. No other statements may follow on the same line as they are treated as part of the comment. Example: A10 REM PROGRAM TO ADD ALL NUMBERS FROM 1 TO 10B A20 ! AND DEMONSTRATE USE OF REM AND !B 3.10 READ . . DATA The READ statement inputs data from the DATA statement. The rules for INPUT apply to READ, but DATA lists are used as needed whereas INPUT inputs an entire line from a file. Example: A10 DATA 10.5,-76,1E7,FRANKB A50 READ A,B,C,D$B PROGRAM STATEMENTS PAGE 3-6 03/06/81 Example: A110 PRINT "START TAPE INPUT";CHR$(17);B A120 BREAKB 3.14 SET PROMPT/TRACE/READ-PASS-ALL ON/OFF This statement is used to set or clear a number of system condi- tions. The number of conditions is likely to increase in the fu- ture as functionality is added. Conditions now serviced include: TRACE, PROMPT and READ-PASS-ALL. SET TRACE is equivalent to the TRACE verb and should be used in preference to it because the TRACE verb is expected to disappear in future releases of this interpreter. The PROMPT condition is used to turn the INPUT and INPUT LINE question mark prompt on or off. The normal mode of processing is ON. The OFF mode is designed for special screen or page formatting and may be used in conjunction with the BREAK command. Example: A210 SET PROMPT OFFB A220 SET TRACE ONB 3.15 ON ERROR GOTO This statement sets the line number for a transfer on any type of error. It does not cause any branching when it itself is execut- ed, rather it changes the processing of errors in the BASIC in- terpreter. If this statement has been previously executed with a non-zero line number specified, no error message will be printed and a branch to the specified statement will be made. Normal error processing will be restored after the branch is made or by executing the statement with a zero line number. Thus at least one ON ERROR GOTO must follow the last error and precede the next one for user error handling to occur. This processing is designed to minimize the chance of an endless loop occurring because of an error in the error handling routine. Precise information as to the cause of the error can be had from the functions ERR, ERL, FCS detailed elsewhere. Examples: A100 ON ERROR GOTO 1500B A510 ON ERROR GOTO 0 ! THIS RESTORES NORMAL ERROR HANDLINGB PROGRAM STATEMENTS PAGE 3-8 03/06/81 3.19 TRACE ON AND OFF This statement turns the trace feature on and off. When the trace is on, all transfers out of the normal flow of normal pro- gram execution are printed on the user's terminal. This can be used in either immediate mode or program mode (for selective tracing). Example: ATRACE ONB READY ARUNB OR A100 TRACE ONB A...B A200 TRACE OFFB ARITHMETIC FUNCTIONS PAGE 4-2 03/06/81 4.4 SGN +1 returned if argument > 0; -1 if argument 0; 0 returned if argument = 0. Example: A10 A=SGN(A1)B 4.5 INT Returns greatest integer in the argument. Note: INT(-1.5)=-2 etc. Example: A10 A=INT(X)B 4.6 LOG (NATURAL & BASE 10) LOG Returns the natural log of the value of the argument expression. Example: A30 A=LOG(X)B LOG10 Returns the base ten (common) log of the value of the argument expression Example: A50 B=LOG10(X)B 4.7 EXP Returns the base e exponential of the argument value. Example: A10 A=EXP(X)B 4.8 SIN COS These functions return the sine and cosine functions of the argu- ment values. The input argument is in radians. Example: A20 S=SIN(X)B A30 C=COS(Y)B ARITHMETIC FUNCTIONS PAGE 4-4 03/06/81 A100 A=COR(255)B 4.14 DAT$ An 8 character string is returned containing the date in the form MO/DA/YR. if the argument is absent or a single character zero, the system date (today's date hopefully!) is returned. If the argument is a positive value, the number is interpreted as the day of the century, and a corresponding date string is returned. The positive argument is interpreted modulo 36524 (the number of days in a century). If the argument is a zero or negative value (other than a single character '0'), then a null string is re- turned. Example: A50 A$=DAT$(0) : ! RETURN SYSTEM DATEB A60 PRINT DAT$(12752)B A70 A$=DAT$() : ! RETURN SYSTEM DATEB 4.15 DDAT$ This function returns a string containing the DEC standard date in the form: DD-MMM-YY. The string may be either 8 or 9 chars depending on the number of digits in the day. The argument is interpreted in the same way as in the DAT$ function. Example: A40 A$=DDAT$(0)B 4.16 TIM$ Returns time in an 8 character string in the form HR:MN:SC. If the argument is absent or a single character zero, the system time is returned. Otherwise, the argument is evaluated. If ne- gative, a null string is returned; if zero or positive, the number is interpreted as the number of seconds since midnight and the corresponding time is returned as a string. The number is interpreted modulo one day worth of seconds. Example: A30 A$=TIM$(0)B A40 A$=TIM$() : !RETURN SYSTEM TIMEB A50 A$=TIM$(A-B) : ! RETURN TIME OF DAY CORRESPONDING TOB ! A-B SECONDS SINCE MIDNIGHT 03/06/81 CHAPTER 5 STRING FUNCTIONS The functions listed in this chapter are primarily character string oriented. They provide wide capability for examining and altering variables which contain character strings, and for conversion from/to other data formats. 5.1 INX . . POS Format: POS(STRING1,STRING2 [,P1] [,P2]) This function computes the position of STRING2 in STRING1 start- ing at optional position P1 (P1 assumed to be 1 if not speci- fied). A second optional parameter P2 specifies the final char- acter position. If it is not specified, it is assumed to be the end of the first string. INX and POS are identical. Example: A10 A=POS("ABC","B")B A20 X=POS(A1$,A2$,5,7)B 5.2 LEN This function computes the length of a single string expression argument. Example: A30 X=LEN(A$)B 5.3 VAL This function takes an ASCII string containing a legal numeric expression and returns a floating point value. Example: A10 A=VAL(A$)B STRING FUNCTIONS PAGE 5-3 03/06/81 the number of characters to include. If not specified in either case all characters to the end of the string are included. A null string is returned when the first character position is not within the source string. When the ending position or length places one beyond the end of the source string, all characters to the end are included with no blank fill. If the first position is after the final, a null string is returned. If A is less than 1 a null string is returned. If B places the final character po- sition past the end of the string, it is as though the ending po- sition was specified. RIGHT LEFT and MID are provided for compatibility with other ver- sions of BASIC (in particular RSTS BASIC-PLUS). Note that the names are not followed by '$' even though the results are string values. These functions return the right-most or left most N characters of the string respectively. MID returns B characters, starting at position A, and is thus a synonym for SBS$. Note that some BASIC RIGHT functions return the N thru end characters of the string. If programs expect this action, the RIGHT(N) function should be replaced by a SBS$(N) function. Example: A10 A$=SEG$(B$,1,5)B A30 X$=SBS$(Y$,6)B 5.9 PIECE$ Format: PIECE$(STRING1,STRING2,N1 [,N2]) PIECE$ inspects a specified string (STRING1) and takes from it that substring which lies between two specified occurrences of a particular dividing string (STRING2). The resulting substring begins immediately after the N1 minus one occurrence of the di- viding string and ends immediately before the N2nd occurrence (or N1st if N2 is unspecified). Example: A110 M$=PIECE$("12/1/77","/",1) :! EXTRACT MONTH FROM STRINGB A120 A$=PIECE$("12/1/77","/",1,2) :! EXTRACT MONTH AND DAYB 5.10 STR$ Numeric to character string conversion. (No leading or trailing blanks.) The Ascii string represents the value of the argument. Format: STR$(X) Where 'X' is any legal numeric expression. Example: A30 A$=STR$(EXP(X)+1.4)B STRING FUNCTIONS PAGE 5-5 03/06/81 digits are wanted, use STR$. Numbers are rounded for printout. Example: A130 A$=FRMT$(A+6,5,2)B A140 B$=FRMT$(12.75+Z1,7)B 5.15 RJS$ . . LJS$ Format: RJS$(B$,I) LJS$(B$,I) Where I is the length of the returned string with B$ right or left justified in it and with leading or trailing blank fill if necessary. If B$ is longer than I characters, then the rightmost or leftmost I characters will be returned. Example: A40 A$=RJS$(B$,9)B A70 A$=LJS$(B$,5)B 5.16 SPACE$ . . STRING$ Format SPACE$(I) STRING$(C$,I) Where I is the length of the string to be created. In the case of SPACE$, a string of blanks is created. For STRING$, a string of characters matching the first character of C$ is created. If I is zero or negative, a null string is returned. Examples: A120 A$=SPACE$(40)B A130 B$=STRING$("-",40)B 5.17 TAB The TAB function is used only in the print statement to space to a given column (the value of the numeric argument). The column specified is the one in which subsequent printing will begin. Columns are numbered starting with 1. If the specified column is greater than the width of the device being printed on, the tab is calculated modulo the device width. If the specified column is less than the current print position, the function is ignored. TAB is ignored on binary output files. Example: A10 PRINT A;TAB(20);A$B I/O & FILE MANIPULATION PAGE 6-2 03/06/81 fit on the printing device. Note that numeric values, when con- verted in a PRINT statement normally have a space at each end. To avoid this, use the STR$ function. On binary files, the following conditions hold: TAB is ignored, no "field" justification is performed and all data list items must fit into the existing buffer. Floating values are stored as four consecutive bytes which are not word aligned. Strings and numeric values are packed together and may be combined in any order. It is up to the user to keep track of the internal sto- rage arrangement for future use with INPUT or other non-BASIC programs. A synonym for PRINT is "?" primarily for convenience in immediate mode use. Example: A50 PRINT A,3.5,"HELLO";A$B A60 PRINT #3,EXP(.5);XY;B 6.3 INPUT Format: INPUT [#N,] V1,V2,V3 etc. or INPUT #NR,V1,V2,V3 etc. Where N is an optional file number and V1, V2, V3 etc. are legal string or numeric variable names. The second form follows the rules for random access described for the PRINT statement. Numeric data must be separated by commas or spaces, successive string variables must be separated by a comma after the required number of characters have been typed in. A character legality check is performed to ensure that all characters are between oc- tal ASCII codes 40 and 137 inclusive and 11 (tab). For input from the terminal (no file number), a prompt string (only string defined in quotes allowed) may be specified before the variable list. This is equivalent to a PRINT followed by an INPUT. See third example below. For binary files the following conditions hold: four bytes are used for each numeric (floating) variable, strings use as many bytes as they have been dimensioned for. More data than vari- ables is not considered an error. Insufficient data is an error with the following exception: a variable length string will have its length shortened to the available data if data runs out, and a fixed length string will be blank filled. If data runs out while filling a numeric variable, the results are unpredictable and in any case terminate the program with an error. Example: A30 INPUT #3,A1,B1$B A50 INPUT #4R+5,X1,X2,A1$B I/O & FILE MANIPULATION PAGE 6-4 03/06/81 mode files (up to 14) may be open simultaneously subject only to total memory availability. The default device for all LUNs is SY0:. Examples: A50 OPEN #4, "LP:/WR"B A60 OPEN #3,N$B 6.7 CLOSE N1[,N2...] This command closes a user data file whose number is N1, N2 etc. Note that no # sign precedes the number. If used with no file number, all user files are closed. Example: A60 CLOSE 4B A70 CLOSE I1B A95 CLOSEB 6.8 IF END [#N] THEN This statement is used to reset the end of file branch on a given file or without the "#N", it sets the terminal end of file branch. The specified file must have been opened with the possi- bility of being read from (i.e. cannot be /AP or /WR in sequen- tial mode). Examples: A100 IF END THEN 1500 :! SET TERMINAL END OF FILE LINE NO.B A120 IF END #3 THEN 2100:! SET END OF FILE LINE NO. ON LUN 3B LOADABLE SUBROUTINES PAGE 7-2 03/06/81 7.3 CALL "NAME"(ARG1,ARG2,...) The CALL statement is used by the BASIC user to call specially written MACRO subroutines which will perform special functions. The called routine name must be enclosed in quotes as above, or reside in a string expression which is enclosed in parentheses. The NAME may be up to 6 characters in length. The enclosing par- entheses are necessary to keep the argument list which follows from appearing as a subscript to a string variable. The arguments can be string or numeric variables or expressions. In the case that a value is to be returned, the argument must be a simple variable (may be subscripted). For values which are passed, either expressions or variables may be used. The vari- ables and expressions used in the argument list must match the type (string or numeric) expected by the subroutine. User routines must preserve the text pointer (R1) and on exit, if an argument list is present, must position it just past the close parenthesis. See APPEND. B for a sample loadable routine. Example: A100 CALL "ABC"(A$,B)B A120 CALL (B$)(A-X,Y$+Z$)B 7.4 INSTRG Subroutine to insert a string into another string. BASIC CALL: 120 CALL "INSTRG"(S$,E$,P [,L]) WHERE: S$ = STRING VARIABLE INTO WHICH INSERTION IS MADE E$ = STRING EXPRESSION TO BE INSERTED P = POSITION TO START INSERTION L = OPTIONAL MAX LENGTH OF INSERTION If L is not specified, the length of E$ is used by default for the length of the insertion. If L is specified, justification of E$ in a field of that size is performed. A positive value is left justify, negative means right justify. This routine is at least three times as fast as the "cut and paste" method using the SBS$ function. If the "cut and paste" is formatted as a user de- fined function, the speed increase is a factor of seven. Therefore it is almost always preferable to the SBS$ method. 7.5 OPEN LIBRARY Format: 50 OPEN LIBRARY #N, This command functions similarly to the standard OPEN command ex- cept that a MACRO library file is opened for question text output LOADABLE SUBROUTINES PAGE 7-4 03/06/81 This type of question is usually used to solicit text information from the user (name, age etc.). Only one line is printed and the carriage (cursor) is positioned at the end of the line. Any further lines of text entered for this question type will not be displayed. Example: A.MACRO SINGLE 1 TYPE YOUR NAME: LAST, FIRST .ENDMB MULTIPLE CHOICE QUESTION This type of question is used to solicit a number response which is selected from a finite set of choices displayed to the user. A succeeding question may be selected depending on the response to the displayed question. Thus multiple choice branching struc- tures may be set up. The character used to separate the response text from its associated branching question name is the back- slash. The number of choices is the number following the ques- tion name in the .MACRO line. Example: A.MACRO MULCHC 3 SELECT YOUR STATE OF MIND GOOD\MULCH1 FAIR\MULCH2 TGIF\MULCH3 .ENDMB COMMON INFORMATION FOR ALL QUESTION PROCESSING CALLS Sbroutines are provided in three different forms to perform a number of different functions. The functions are as follows: 1) Display question 2) Position to question 3) Return question text 4) Return answer text 5) Return question name The three forms of the subroutines are as follows: 1) 'M' form: perform function by name 2) 'C' form: perform function on question linked to prev. quest. 3) 'R' form: perform function on last question accessed In general the 'M' form and 'C' form of the subroutines reset the last question accessed. The 'R' form, since it acts on the last question accessed, does not change it. The one exception is the 'C' form of the return question name function (CQNAM). It does not change the last question accessed. The 'M' form of the subroutines uses a name specified as an input string argument (3rd parameter) to position to the specified question and then perform the required action. The 'C' form uses the last question accessed (positioned to) in LOADABLE SUBROUTINES PAGE 7-6 03/06/81 The named question, linked question or previous question will be displayed respectively by the above three subroutine calls ac- cording to the following rules. If the optional parameters are not specified: MULTI-LINE INFO DISPLAY: Text is displayed as typed. Carriage (cursor) is positioned to the start of the next line. All lines up to the line with a leading .ENDM directive will be displayed. SINGLE LINE TEXT INPUT: The line of text is displayed with the carriage (cursor) to the immediate right of the text just displa- yed. Any spaces required after the text must be either included in the question text or added from the program via a PRINT state- ment. MULTIPLE CHOICE QUESTION: For this type question the first line is displayed as typed. Subsequent lines are displayed with a leading space and a number which starts at one and increases by one for each succeeding line. The number is then followed by a right parenthesis ')' and another space and then the text for that line. After all lines have been displayed, the carriage (cursor) is then positioned to the start of the next line. NOTE The total number of lines displayed is the number given as the argument on the .MACRO line plus one and is inde- pendent of where the .ENDM line occurs. This may lead to not displaying all of the typed in question text or the output of garbage if the question has not been typed in properly. If the optional parameters are specified (both must be present), the following holds: MULTI-LINE INFO DISPLAY: If N is the number specified in COUNT, then the text is displayed preceded by N characters of STRING$ for each line until the characters in STRING$ are exhausted or the display is complete (normally these should happen together). SINGLE LINE TEXT INPUT: The line of text is displayed as before but with N chracters of STRING$ preceding it. MULTIPLE CHOICE QUESTIONS: In this case the first line is dis- played as above, but the subsequent lines (answers) are each pre- ceded by N characters from STRING$. LOADABLE SUBROUTINES PAGE 7-8 03/06/81 names without having to reposition to the original question. In the second case the current question name will be returned in STRING$. 7.12 SPAWNB Subroutine to spawn a task using the IAS spawn directive. FORMAT: CALL "SPAWNB"(C$ [,S]) This routine passes the MCR command line in C$ to the operating system. Commands to another BASic program, PIP, etc may be passed in the command line just as with MCR. The exiting status of the spawned task is returned in the (optional) variable S. If the STATUS variable is present, the issuing BASIC program will STOP, and continue when the SPAWNED task exits. If no STATUS variable is present in the call, BASIC execution continues imme- diately. During the time that BASIC is STOPPED for the SPAWNED task, con- trol-C's will not have the normal effect. Also BASIC detaches the terminal so PIP lists to the terminal etc. can occur. NOTE SPAWN knows about things like DIR, PRInt, etc., but the task in question must be installed in the system. The auto-install function for infrequently used tasks does not work for SPAWNB. If SPAWN detects that the requested task is unavailable, it returns the system failure status (currently -2 -- Task not installed.) BASIC ERROR VALUES PAGE A-2 03/06/81 42. SYNTAX ERROR IN SLEEP COMMAND 43. SYNTAX ERROR IN WAIT COMMAND 44. TIMEOUT ERROR - YOU WAITED TOO LONG TO TYPE 45. PRIORITY ERROR 46. BASIC PROGRAM FILE ERROR %D 47. FILE ACCESS MODE ERROR (SEQ/RAN) 48. ERROR IN LOADED USER SUBROUTINE 49. VIRTUAL ACCESS ERROR - FCS %D 50. VIRTUAL FILE OPEN ERROR - FCS %D 51. ERROR IN SET COMMAND 52. USE OF "/CO" SWITCH WITH NORMAL BASIC SOURCE 53. IMMEDIATE MODE COMMAND IN SOURCE TEXT 62. DEBUG #1 AT R3=%P 63. DEBUGGING ERROR #2 - CALL SYSTEM MANAGER 64. LOG OF NEGATIVE OR ZERO NUMBER 65. SQUARE ROOT OF NEGATIVE NUMBER 66. FLOATING DIVIDE BY ZERO 67. NUMBER TOO LARGE TO FIX 68. FLOATING OVERFLOW 69. FLOATING UNDERFLOW 70. NON-EXISTENT VARIABLE 71. TOO MUCH DATA TYPED 72. NOT ENOUGH DATA TYPED 73. ILLEGAL CHARACTERS ON INPUT 74. ERROR IN VALUE FUNCTION 75. NOT ENOUGH DATA TYPED 76. ILLEGAL CHARACTERS ON INPUT 77. ERROR IN VALUE FUNCTION 78. SYNTAX ERROR IN FUNCTION 79. SYNTAX ERROR IN OPEN 200. FLOATING OVERFLOW 202. FLOATING UNDERFLOW 211. LOG OF NEGATIVE OR ZERO VALUE 212. SQUARE ROOT OF NEGATIVE VALUE SAMPLE LOADABLE MACRO SUBROUTINE PAGE B-2 03/06/81 1$: MOV R0,R4 ;SAVE LENGTH IN R4 BIS #160000,R0 ;MAKE R0 A "SCRATCH" DATA TYPE HEADER MOV R0,(R5)+ ;PUT HEADER IN USER AREA MOV R5,R2 ;SAVE STRING ADDRESS (IN USER AREA) MOV 4(SP),R3 ;ADDRESS OF INPUT STRING -> R3 MOV R4,R0 ;STRING LENGTH -> LOOP COUNTER ADD R4,R3 ;BUMP R3 PAST END OF INPUT STRING 2$: MOVB -(R3),(R5)+ ;REVERSE THE STRING SOB R0,2$ MOV R2,R3 ;OUTPUT STRING ADDRESS -> R3 ;STRING LENGTH STILL IS IN R4 3$: MOV SP,R5 ;GET ADD OF RETURN ARG DESCRIPTOR ADD #6,R5 ;IN R5 JSR PC,#SSTORE ;AND RETURN THE RESULT TO THE CALLER MOV (SP)+,R1 ;RESTORE TEXT PTR ADD #7*2,SP ;CLEAN STACK OF 7 WORDS RTS PC ;AND RETURN END: ;LABLE END OF CODE .END MACRO COMMAND FILE REVSTR,REVSTR/-SP=LB:[1,202]LOAMAC/ML,[1,202]REVSTR TKB COMMAND FILE REVSTR.ATK/-HD/-FP,REVSTR/-SP=REVSTR LB:[1,1]BSCPUR.STB/SS / STACK=0 UNITS=0 / USEFUL INTERNAL BASIC SUBROUTINE CALLS PAGE C-2 03/06/81 STACK ; AND POINTED TO BY SP ON RETURN. ; ON ENTRY: ; R4 POINTS TO ARG TYPE LIST (VIA JSR R4,#GTRGPI) ; OLD R4 ON STACK (WILL BE POPPED) ; ON RETURN: ; SP -> ARG LIST (ON STACK - TO BE REMOVED BY CALLING ROUTINE) ; OTHER REGISTERS: POTENTIALLY ALL ; ; ; NSTORE: TO STORE AWAY A VALUE FROM AC0 INTO A LOCATION ; STORED IN A TABLE SUCH AS THAT FILLED IN BY GETARG. ; ON CALL: R5 CONTAINS POINTER TO ADDRESS ; AC0 CONTAINS VALUE TO BE STORED ; ON RETURN: NOTHING CHANGED ; REGISTERS USED: R0, AC1 ; ; ; ; ; ; SSTORE: TAKE A STRING DESCRIBED BY LEN IN R4 AND ADDRESS IN R3 ; AND STORE IT INTO A STRING VARIABLE WHOSE TABLE ENTRY IS ; POINTED TO BY R5. ; ; ON CALL: R3 = ADDRESS OF STRING TO BE STORED ; R4 = LENGTH OF STRING TO BE STORED ; R5 = POINTER TO OUTPUT STRING TABLE ENTRY ; ; ON RETURN: R3 POINTS PAST END OF STRING ; R4 = 0 ; R5 UNCHANGED ; OTHER REGISTERS USED: R0,R2 (ALL BUT R1) ; ; ; ARGCNT: COUNT ARGUMENTS ROUTINE ; ON ENTRY: R1 POINTS TO LEADING OPEN PAREN "(" ; ON EXIT: R1 UNCHANGED ; R0 CONTAINS COUNT OF ARGUMENTS UP TO ")" IN THE LIST ; QUOTED STRINGS AND SUBSCRIPTS ARE ACCOUNTED FOR ; OTHER REGISTERS USED: R2 ; NOTE: AN END OF LINE WILL TERMINATE THE SCAN IRRESPECTIVE OF ; ENCLOSING QUOTES AS LONG AS IT IS USED AS THE INTERNAL ; LINE DELIMITER (S.EOL1 OR S.EOL2) ; ; ; ; ; TSTU00 - CHECK FOR USER STORAGE OVERFLOW ; ; CHECK FOR POSSIBLE USER STORAGE OVERFLOW USEFUL INTERNAL BASIC SUBROUTINE CALLS PAGE C-4 03/06/81 ; .RAD50 /NAME/ ;TWO WORDS OF RAD50 ENTRY POINT NAME ; .WORD ?????? ;OFFSET FROM START OF CODE PROPER ; FINALLY, ONE WORD CONTAINING NUMBER OF WORDS OF CODE PROPER: ; .WORD ?????? ;LEN (IN WORDS) OF CODE PROPER ; ; NOTE: THESE MODULES MUST BE TASK BUILT WITH /-HD/-FP AND: ; STACK=0 ; UNITS=0 ; ; IN ADDITION POSITION INDEPENDENT CODING TECHNIQUES MUST BE USED IN ; WRITING THE CODE BECAUSE ITS POSITION IN THE INTERPRETER WILL VARY ; DEPENDING ON WHAT OTHER ROUTINES ARE LOADED. INDEX PAGE D-2 03/06/81 DDAT$ . . . . . . . . . . . . . 4-4 DEC standard date function . . . 4-4 DEF . . . . . . . . . . . . . . 3-3 DELETE . . . . . . . . . . . . . 2-3 DIM . . . . . . . . . . . . . . 3-2 DIM # . . . . . . . . . . . . . 3-2 END . . . . . . . . . . . . . . 2-1 ERL . . . . . . . . . . . . . . 4-3 ERR . . . . . . . . . . . . . . 4-3 Error code functions . . . . . . 4-3 EXIT . . . . . . . . . . . . . . 2-4 EXP . . . . . . . . . . . . . . 4-2 Exponential function . . . . . . 4-2 Exponentiation . . . . . . . . . 1-4 FCS . . . . . . . . . . . . . . 4-3 File close . . . . . . . . . . . 1-3, 2-2, 6-4 File open . . . . . . . . . . . 6-3 File restore . . . . . . . . . . 6-1 FOR . . . . . . . . . . . . . . 3-5 Free core function . . . . . . . 4-3 FRMT$ . . . . . . . . . . . . . 5-4 Function - user . . . . . . . . 3-3 GOSUB . . . . . . . . . . . . . 3-1 GOTO . . . . . . . . . . . . . . 3-1 IF . . . . . . . . . . . . . . . 3-3 IF END . . . . . . . . . . . . . 6-4 IMMEDIATE mode . . . . . . . . . 1-1 Index string function . . . . . 5-1 INPUT . . . . . . . . . . . . . 6-2 INPUT LINE . . . . . . . . . . . 6-3 INSTRG . . . . . . . . . . . . . 7-2 INT . . . . . . . . . . . . . . 4-2 Integer function . . . . . . . . 4-2 Introduction . . . . . . . . . . 1-1 INX . . . . . . . . . . . . . . 5-1 LEFT . . . . . . . . . . . . . . 5-2 LEN . . . . . . . . . . . . . . 5-1 Length of string function . . . 5-1 LET . . . . . . . . . . . . . . 3-3 Library open . . . . . . . . . . 7-2 LIST . . . . . . . . . . . . . . 2-3 LJS$ . . . . . . . . . . . . . . 5-5 LOAD . . . . . . . . . . . . . . 7-1 LOG . . . . . . . . . . . . . . 4-2 LOG10 . . . . . . . . . . . . . 4-2 Logarithm - base ten . . . . . . 4-2 Logarithm - natural . . . . . . 4-2 Logical Expressions . . . . . . 1-5 LTR$ . . . . . . . . . . . . . . 5-3 INDEX PAGE D-4 03/06/81 READ-PASS-ALL . . . . . . . . . 3-6 Record count function . . . . . 4-3 REM . . . . . . . . . . . . . . 3-4 RESTORE . . . . . . . . . . . . 6-1 RETURN . . . . . . . . . . . . . 3-1 RIGHT . . . . . . . . . . . . . 5-2 Right justify function . . . . . 5-5 RJS$ . . . . . . . . . . . . . . 5-5 RND . . . . . . . . . . . . . . 4-1 RPOS . . . . . . . . . . . . . . 7-7 RQNAM . . . . . . . . . . . . . 7-7 RQTXT . . . . . . . . . . . . . 7-7 RUN . . . . . . . . . . . . . . 1-3, 2-1 SAVE . . . . . . . . . . . . . . 2-2 SBS$ . . . . . . . . . . . . . . 5-2 SCRATCH . . . . . . . . . . . . 6-3 SEC . . . . . . . . . . . . . . 4-5 SEG$ . . . . . . . . . . . . . . 5-2 SET PROMPT . . . . . . . . . . . 3-6 SET READ-PASS-ALL . . . . . . . 3-6 Set system conditions . . . . . 3-6 SET TRACE . . . . . . . . . . . 3-6 SGN . . . . . . . . . . . . . . 4-1 Sign function . . . . . . . . . 4-1 SIN . . . . . . . . . . . . . . 4-2 Sine function . . . . . . . . . 4-2 Single line execute . . . . . . 2-4 SLEEP . . . . . . . . . . . . . 3-6 SPACE$ . . . . . . . . . . . . . 5-5 SPAWN . . . . . . . . . . . . . 7-8 SQR . . . . . . . . . . . . . . 4-3 Square root function . . . . . . 4-3 Statement and line format . . . 1-1 STEP . . . . . . . . . . . . . . 2-4 STOP . . . . . . . . . . . . . . 2-1 STR$ . . . . . . . . . . . . . . 5-3 String comparison . . . . . . . 3-3 String variables . . . . . . . . 3-2 STRING$ . . . . . . . . . . . . 5-5 Strings . . . . . . . . . . . . 1-3 Suboutine call . . . . . . . . . 7-1 Substring functions . . . . . . 5-2 TAB . . . . . . . . . . . . . . 5-5 TIM$ . . . . . . . . . . . . . . 4-4 Time function . . . . . . . . . 4-4 Time string validity check . . . 4-5 TRACE . . . . . . . . . . . . . 3-6 TRACE ON and OFF . . . . . . . . 3-7 TRM$ . . . . . . . . . . . . . . 5-3 UNLOAD . . . . . . . . . . . . . 7-1 User defined functions . . . . . 3-3 User subroutine call . . . . . . 7-1