Altair_8800_BASIC_Reference_Manual_1975 BASIC Manual 75
User Manual: BASIC Manual 75
Open the PDF directly: View PDF .
Page Count: 108
Download | |
Open PDF In Browser | View PDF |
M!TS ALTA!R BASiC REFERENCE MANUAL 1ab!e of Contents: INTRODUCTION I GETTING STARTED WITH BASIC 1 REFERENCE M A T E R I A L 23 APPENDICES A) H O W TO LOAD BASIC B) INITIALIZATION DIALOG C) ERROR M E S S A G E S D) SPACE H I N T S E) SPEED H I N T S F) D E R I V E D FUNCTIONS G) SIMULATED M A T H FUNCTIONS H) CONVERTING BASIC PROGRAMS N O T WRITTEN FOR THE A L T A I R I) USING THE A C R INTERFACE J) BASIC/MACHINE LANGUAGE INTERFACE K) A S C I I CHARACTER C O D E S L) E X T E N D E D BASIC M) BASIC T E X T S 45 46 51 53 56 58 59 60 62 64 66 69 71 73 @ M I T S , Inc., 1975 PRtNTED )N U.S.A. "Creative E!ectronics" P.O. B O X 8 6 3 6 A L B U Q U E R Q U E . N E W M E X t C O 87108 ALM1R - ---- —— Bd5ir The following are additions and corrections to the ALTAIR BASIC REFERENCE M A N U A L . Be sure to read this over carefully before c o n t i n u i n g . 1) If you are loading BASIC from paper t a p e , be sure your Serial I/O board is strapped for eight data bits and no parity b i t . 2) On page 53 in A p p e n d i x C , the meaning for an "OS" error should read: Out of String S p a c e . A l l o c a t e m o r e string space by using the "CLEAR" command with an argument (see p a g e 4 2 ) , and then run your p r o g r a m a g a i n . If you cannot allocate m o r e string s p a c e , try using smaller strings or less string v a r i a b l e s . 3) On p a g e 4 2 , under the "CLEAR" c o m m a n d , It is stated that "CLEAR" with no argument sets the amount of string space to 200 b y t e s . This is inc o r r e c t . "CLEAR" with no argument leaves the amount of string space u n c h a n g e d . When BASIC is brought u p , the amount of string space is initially set to 50 b y t e s . 4) On p a g e 3 0 , u n d e r the "DATA" s t a t e m e n t , the sentence "IN THE 4K VERSION OF B A S I C , DATA S T A T E M E N T S M U S T BE THE FIRST STATEMENTS ON A LINE," should be changed to r e a d , "IN THE 4K VERSION OF B A S I C , A DATA STATEM E N T M U S T BE ALONE ON A LINE." 5) If you desire to u s e a terminal interfaced to the ALTAIR with a Parallel I/O board as your system c o n s o l e , you should load from the A C R interface (wired for address 6 ) . Use the A C R load procedure described in A p p e n d i x A , except that you should raise switches 15 § 13 when you start the b o o t . T h e Parallel I/O board must be strapped to address 0 . 6) If you get a checksum error while loading BASIC from a p a p e r tape or a c a s s e t t e , you m a y b e able to restart the boot loader at location 0 with the appropriate sense switch s e t t i n g s . This depends on when the error o c c u r s . T h e boot loader is not written over until the last block of BASIC is being read; w h i c h occurs during approximately the last two feet of a paper t a p e , or the last 10 to 15 seconds of a c a s s e t t e . If the checksum error occurs during the reading of the last block of B A S I C , the boot will be overwritten and you will have to key it in a g a i n . 7) T h e number of nulls punched after a carriage return/line feed does not need to be set >=3 for Teletypes or >=6 for 30 CPS paper tape t e r m i n a l s , as described under the "NULL" command on p a g e 23 of the BASIC m a n u a l . In almost all c a s e s , n o extra nulls need be punched after a CR/LF on T e l e t y p e s , and a setting of nulls to 3 should be sufficient for 30 CPS p a p e r tape t e r m i n a l s . If any problems occur when reading tape (the first few characters of lines are l o s t ) , change the null setting to 1 for Teletypes and 4 for 30 CPS t e r m i n a l s . 8) If you have any problems loading B A S I C , check to make sure that your terminal interface board (SIO or PIO) is working p r o p e r l y . Key in the appropriate echo program from b e l o w , and start it at location zero. Each character typed should be typed or displayed on your t e r m i n a l . If this is not the c a s e , first be sure that you are using the correct echo p r o g r a m . If you are using the correct p r o g r a m , but it is not functioning p r o p e r l y , then m o s t likely the interface board or the terminal is not operating c o r r e c t l y . Jn tAe /bZZoMtng program ZtsttMjs^ t^e MM/n&er to t^e Z-e/t t^e sZasTz ts t^e oetaZ address and t^e TiMW^er to t&e rtjAt ^s t^e ocMZ. code /or t^at address. FOR REV 0 SERIAL I/O BOARDS WITHOUT THE STATUS BIT MODIFICATION 0/333 3/040 b / 000 11 / 353 14 / 000 1 / QOQ 4/313 7 / 333 13 / 001 15 / 000 2 5 10 13 / / / / 34b 000 001 303 3 5 10 13 / / / / 017 000 333 000 3 5 10 13 / / / / 34b 000 001 303 FOR REV 1 SERIAL I/O BOARDS (AND REV 0 MODIFIED BOARDS) 0 / 333 3 / 33E b / 333 11 / 001 1 / 000 4 / 000 7 / 001 IB / 303 14 / 000 FOR PARALLEL 1/0 BOARDS 0 / 3 / t= / 11 / 14 / 333 003 000 333 000 1 4 7 13 15 / / / / / 000 313 333 001 000 For those of you with the b o o k , MY COMPUTER LIKES ME when i speak in B A S I C , b y Bob A l b r e c h t , the following information m a y be h e l p f u l . 1) A L T A I R BASIC uses "NEW" instead of "SCR" to delete the current program. 2) U s e Control-C to stop execution of a p r o g r a m . U s e a carriagereturn to stop a p r o g r a m at an "INPUT" s t a t e m e n t . 3) You don't need an "END" statement at the end of a BASIC p r o g r a m . Before a computer can perform any useful function, it must be "told" what to do. Unfortunately, at this time, computers are not capable of understanding English or any other "human" language. This is primarily because our languages are rich with ambiguities and implied meanings. The computer must be told precise instructions and the exact sequence of operations to be performed in order to accomplish any specific task. Therefore, in order to facilitate human communication with a computer, programming languages have been developed. ALTAIR BASIC* is a programming language both easily understood and simple to use. It serves as an excellent "tool" for applications in areas such as business, science and education. Mith only a few hours of using BASIC, you will find that you can already write programs with an ease that few other computer languages can duplicate. Originally developed at Dartmouth University, BASIC language has found wide acceptance in the computer field. Although it is one of the simplest computer languages to use, it is very powerful. BASIC uses a small set of common English words as its "commands". Designed specifically as an "interactive" language, you can give a command such as "PRINT 2 + 2", and ALTAIR BASIC will immediately reply with "4". It isn't necessary to submit a card deck with your program on it and then wait hours for the results. Instead the full power of the ALTAIR is "at your fingertips". Generally, if the computer does not way you expected it to, there is a "Bug" else there is an error in the data which its answer. If you encounter any errors know and we'll see that it's corrected. the following information: solve a particular problem the or error in your program, or the program used to calculate in BASIC itself, please let us Write a letter to us containing 1) System Configuration 2) Version of BASIC 3) A detailed description of the error Include all pertinent information such as a listing of the program in which the error occurred, the data placed into the program and BASIC'S printout. All of the information listed above will be necessary in order to properly evaluate the problem and correct it as quickly as possible. We wish to maintain as high a level of quality as possible with all of our ALTAIR software. * BASIC ^s g reg-z^gre^ trademark o/ Par^moM^T: Z/n^grst^z/. Me hope that you enjoy ALTAIR BASIC, and are successful in using it to solve all of your programming needs. In order to maintain a maximum quality level in our documentation, we will be continuously revising this manual. If you have any suggestions on how we can improve it, please let us know. If you are already familiar with BASIC programming, the following section may be skipped. Turn directly to the Reference Material on page 22. M9TE; M Z T F 4LT4.Z7? R 4 R T C ts a t ? a t ^ a M e u n d e r ^ o e n s e o r pMrcTxzse agreements. 6*op$/tn< <= => MEANING EQUAL TO GREATER THAN LESS THAN N O T EQUAL TO LESS THAN OR EQUAL TO GREATER THAN OR EQUAL TO T h e IF statement is either true or f a l s e , depending upon whether the two expressions satisfy the relation or n o t . For e x a m p l e , in the program we just d i d , if 0 was typed in for B the IF statement would be true because 0 = 0 . In this c a s e , since the number after the THEN is 5 0 , execution of the program would continue at line 5 0 . T h e r e f o r e , "ZERO" would be printed and then the program would jump back to line 10 (because of the GOTO statement in line 6 0 ) . Suppose a 1 was typed in for B . Since 1=0 is f a l s e , the IF statem e n t would be false and the program would continue execution with the next line. T h e r e f o r e , "NON-ZERO" would be printed and the GOTO in line 40 would send the program back to line 10. Now try the following program for comparing two numbers: 10 20 30 40 50 60 70 80 90 INPUT A , B IF A<=B THEN 50 PRINT "A IS BIGGER" GOTO 10 IF A < B THEN 80 PRINT "THEY ARE THE SAME" GOTO 10 PRINT "B IS BIGGER" GOTO 10 When this program is r u n , line 10 will input two numbers from the t e r m i n a l . A t line 2 0 , if A is greater than B , A < = B will be f a l s e . This will cause the next statement to be e x e c u t e d , printing "A IS BIGGER" and then line 40 sends the computer back to line 10 to begin a g a i n . A t line 2 0 , if A has the same v a l u e as B , A < = B is true so we go to line 5 0 . A t line 5 0 , since A has the same v a l u e as B , A < B is false; t h e r e f o r e , we go to the following statement and print "THEY ARE THE SAME" Then line 70 sends us back to the beginning a g a i n . A t line 2 0 , if A is smaller than B , A < = B is true so w e go to line 50 A t line 5 0 , A < B will be true so w e then go to line 8 0 . "B IS BIGGER" is then printed and again w e go back to the b e g i n n i n g . T r y running the last two programs several t i m e s . It m a y m a k e it easier to understand if you try writing your own program at this time using the IF-THEN s t a t e m e n t . A c t u a l l y trying programs of your own is the quickest and easiest way to understand how BASIC w o r k s . R e m e m b e r , to stop these programs just give a carriage return to the input statement. 11 One advantage of computers is their ability to perform repetitive t a s k s . Let's take a closer look and see how this w o r k s . Suppose we want a table of square roots from 1 to 10. The BASIC function for square root is "SQR"; the form being S Q R ( X ) , X being the number you wish the square root calculated f r o m . We could write the program as follows: 10 PRINT 20 PRINT 30 PRINT 40 PRINT 50 PRINT 60 PRINT 70 PRINT 80 PRINT 90 PRINT 100 PRINT 1,SQR(1) 2,SQR(2) 3,SQR(3) 4,SQR(4) 5,SQR(5) 6,SQR(6) 7,SQR(7) 8,SQR(8) 9,SQR(9) 10,SQR(10) This program will do the job; h o w e v e r , it is terribly i n e f f i c i e n t . We can improve the program tremendously by using the IF statement just introduced as follows: 10 20 30 40 N=1 PRINT N , S Q R ( N ) N=N+1 IF N<=10 THEN 20 When this program is r u n , its output will look exactly like that of the 10 statement program above i t . Let's look at how it w o r k s . At line 10 w e h a v e a LET statement which sets the value of the variable N at 1 . At line 20 w e print N and the square root of N using its current v a l u e . It thus becomes 20 PRINT 1 , S Q R ( 1 ) , and this calculation is printed o u t . A t line 30 w e u s e w h a t w i l l appear at first to b e a rather u n u s u a l LET s t a t e m e n t . M a t h e m a t i c a l l y , the statement N = N + 1 is n o n s e n s e . H o w e v e r , the important thing to remember is that in a LET s t a t e m e n t , the symbol " = " does n o t signify e q u a l i t y . In this case " = " means "to be replaced w i t h " . A l l the statement does is to take the current value of N and add 1 to i t . T h u s , after the first time through line 3 0 , N becomes 2 . A t line 4 0 , since N now equals 2 , N<=10 is true so the THEN portion branches us back to line 2 0 , with N now at a v a l u e of 2 . T h e overall result is that lines 20 through 40 are r e p e a t e d , each time adding 1 to the v a l u e of N . When N finally equals 10 at line 2 0 , the next line will increment it to 1 1 . This results in a false statem e n t at line 4 0 , and since there are no further statements to the program it s t o p s . This technique is referred to as "looping" or " i t e r a t i o n " . Since it is used quite extensively in p r o g r a m m i n g , there are special BASIC statements for using i t . We can show these with the following program. 12 10 FOR N=1 TO 10 20 PRINT N,SQR(N) 30 NEXT N The output of the program listed above will be exactly the same as the previous two programs. At line 10, N is set to equal 1. Line 20 causes the value of N and the square root of N to be printed. At line 30 we see a new type of statement. The "NEXT N" statement causes one to be added to N , and then if N<=10 we go back to the statement following the "FOR" statement. The overall operation then is the same as with the previous program. Notice that the variable following the "FOR" is exactly the same as the variable after the "NEXT". There is nothing special about the N in this case. Any variable could be u s e d , as long as they are the same in both the "FOR" and the "NEXT" statements. For instance, "Zl" could be substituted everywhere there is an "N" in the above program and it would function exactly the same. Suppose we wanted to print a table of square roots from 10 to 20, only counting by two's. The following program would perform this task: 10N=10 20 PRINT N,SQR(N) 30 N=N+2 40 IF N<=20 THEN 20 Note the similar structure between this program and the one listed on page 12 for printing square roots for the numbers 1 to 10. This program can also be written using the "FOR" loop just introduced. 10 FOR N=10 TO 20 STEP 2 20 PRINT N,SQR(N) 30 NEXT N Notice that the only major difference between this program and the previous one using "FOR" loops is the addition of the "STEP 2" clause. This tells BASIC to add 2 to N each time, instead of 1 as in the previous program. If no "STEP" is given in a "FOR" statement, BASIC assumes that one is to be added each time. The "STEP" can be followed by any expression. Suppose we wanted to count backwards from 10 to 1. doing this would be as follows: 10 20 30 40 A program for 1=10 PRINT I 1=1-1 IF I>=1 THEN 20 Notice that we are now checking to see that I is greater than or equal to the final v a l u e . The reason is that we are now counting by a negative number. In the previous examples it was the opposite, so we were checking for a variable less than or equal to the final value. 13 The "STEP" statement p r e v i o u s l y shown can also be used with negative numbers to accomplish this same p u r p o s e . This can be done using the same format as in the other p r o g r a m , as follows: 10 FOR 1=10 TO 1 STEP -1 20 PRINT I 30 N E X T I "FOR" loops can also be " n e s t e d " . A n example of this procedure fol- lows: 10 20 30 40 50 FOR 1=1 TO 5 FOR J=1 TO 3 PRINT I,J NEXT J NEXT I N o t i c e that the "NEXT J" comes before the "NEXT I". This is because the J - l o o p is inside of the 1 - l o o p . T h e following program is incorrect; run it and see what h a p p e n s . 10 20 30 40 50 FOR 1=1 TO 5 FOR J=1 TO 3 PRINT I,J NEXT I NEXT J It does not work b e c a u s e when the "NEXT I" is e n c o u n t e r e d , all knowledge of the J - l o o p is lost. This happens because the J - l o o p is "inside" of the 1 - l o o p . It is often convenient to be able to select any element in a table of n u m b e r s . BASIC allows this to be done through the u s e of m a t r i c e s . A m a t r i x is a table of n u m b e r s . T h e name of this t a b l e , called the m a t r i x n a m e , is any legal v a r i a b l e n a m e , "A" for e x a m p l e . The m a t r i x n a m e "A" is distinct and separate from the simple variable " A " , and you could use both in the same p r o g r a m . To select an element of the t a b l e , w e subscript "A" : that is to select the I'th e l e m e n t , we enclose I in parenthesis "(I)" and then follow "A" by this s u b s c r i p t . T h e r e f o r e , "A(I)" is the I'th element in the matrix "A". M3TF; JTn t M s section of t&e manual Me zJtZZ &e concerned h^t?! one-dtmenstonaZ matrices (Fee Reference A/atertaZJ "A(I)" is o n l y o n e element of m a t r i x A , and BASIC m u s t b e told how m u c h space to allocate for the entire m a t r i x . This is d o n e with a "DIM" s t a t e m e n t , using the format "DIM A ( 1 5 ) " . In this c a s e , w e have reserved space for the m a t r i x index "I" to go from 0 to 15. M a t r i x subscripts always start at 0; t h e r e f o r e , in the above e x a m p l e , w e h a v e allowed for 16 numbers in m a t r i x A . 14 If "A(I)" is used in a program before it has been d i m e n s i o n e d , BASIC reserves space for 11 elements (0 through 10). As an example of how matrices are u s e d , try the following program to sort a list of 8 numbers with you picking the numbers to be s o r t e d . 10 DIM A ( 8 ) 20 FOR 1=1 TO 8 30 INPUT A ( I ) 50 N E X T I 70F=0 80 FOR 1=1 TO 7 90 IF A ( I ) < = A ( I + 1 ) THEN 140 100T=A(I) 110 A(I)= A ( I + 1 ) 120A(I+1)=T 130 F=1 140 N E X T I 150 IF F=1 THEN 70 160 FOR 1=1 TO 8 170 PRINT A ( I ) , 180 NEXT I When line 10 is e x e c u t e d , BASIC sets aside space for 9 numeric v a l u e s , A(0) through A ( 8 ) . Lines 20 through 50 get the unsorted list from the u s e r . T h e sorting itself is done by going through the list of numbers and upon finding any two that are not in o r d e r , w e switch t h e m . "F" is used to indicate if any switches w e r e d o n e . If any were d o n e , line 150 tells BASIC to go back and check some m o r e . If we did not switch any n u m b e r s , or after they are all in o r d e r , lines 160 through 180 will p r i n t out the sorted l i s t . N o t e that a subscript can b e any e x p r e s s i o n . Another useful pair of statements are "GOSUB" and " R E T U R N " . If you have a program that performs the same action in several different p l a c e s , you could duplicate the same statements for the action in each place within the p r o g r a m . T h e "GOSUB"-"RETURN" statements can be used to avoid this d u p l i c a t i o n . When a "GOSUB" is e n c o u n t e r e d , BASIC branches to the line w h o s e number follows the " G O S U B " . H o w e v e r , BASIC remembers where it was in the program before it b r a n c h e d . When the "RETURN" statement is e n c o u n t e r e d , BASIC goes back to the first statement following the last "GOSUB" that was exec u t e d . Observe the following p r o g r a m . 10 PRINT "WHAT IS THE NUMBER"; 30 GOSUB 100 40T=N 50 PRINT "WHAT IS THE SECOND N U M B E R " ; 70 GOSUB 100 80 PRINT "THE SUM OF THE TWO N U M B E R S IS",T+N 90 STOP 100 INPUT N 15 110 120 130 140 IF N = INT(N) THEN 140 PRINT " S O R R Y , NUMBER MUST BE AN INTEGER. GOTO 100 RETURN TRY AGAIN." What this program does is to ask for two numbers which must be integ e r s , and then prints the sum of the t w o . T h e subroutine in this program is lines 100 to 1 3 0 . The subroutine asks for a n u m b e r , and if it is not an i n t e g e r , asks for a number a g a i n . It will continue to ask u n t i l an integer value is typed i n . T h e m a i n program prints " hJHAT IS THE NUMBER " , and then calls the subroutine to get the v a l u e of the number into N . When the subroutine returns (to line 4 0 ) , the v a l u e input is saved in the variable T . This is done so that when the subroutine is called a second t i m e , the value of the first number will not be lost. " hiHAT IS THE SECOND NUMBER " is then p r i n t e d , and the second value is entered when the subroutine is again c a l l e d . When the subroutine returns the second t i m e , " THE SUM OF THE Th<0 NUMBERS IS " is p r i n t e d , followed by the v a l u e of their s u m . T contains the v a l u e of the first n u m b e r that was entered and N contains the v a l u e of the second n u m b e r . The next statement in the program is a "STOP" s t a t e m e n t . This causes the program to stop execution at line 9 0 . If the "STOP" statement was not included in the p r o g r a m , we would "fall into" the subroutine at line 1 0 0 . This is undesirable because w e would be asked to input another n u m b e r . If w e d i d , the subroutine would try to return; and since there was no "GOSUB" which called the s u b r o u t i n e , an RG error would o c c u r . Each "GOSUB" executed in a program should have a matching "RETURN" executed l a t e r , and the opposite a p p l i e s , i . e . a "RETURN" should be encountered only if it is part of a subroutine w h i c h has been called b y a " G O S U B " . Either "STOP" or "END" can be used to separate a program from its s u b r o u t i n e s . In the 4K version of B A S I C , there is no difference between the "STOP" and the " E N D " . In the 8K v e r s i o n , "STOP" will print a message saying at what line the "STOP" was e n c o u n t e r e d . Suppose you had to enter numbers to your program that didn't change each time the program was r u n , but you would like it to be easy to change them if n e c e s s a r y . BASIC contains special statements for this p u r p o s e , called the "READ" and "DATA" s t a t e m e n t s . Consider the following program: 10 20 30 40 50 60 70 90 95 PRINT "GUESS A N U M B E R " ; INPUT G READ D IF D=-999999 THEN 90 IF D o G THEN 30 PRINT "YOU ARE CORRECT" END PRINT "BAD G U E S S , TRY AGAIN." RESTORE 16 100 GOTO 10 110 DATA 1,393,-39,28,391,-8,0,3.14,90 120 DATA 89,5,10,15,-34,-999999 This is w h a t happens when this program is r u n . When the "READ" statement is e n c o u n t e r e d , the effect is the same as an INPUT s t a t e m e n t . B u t , instead of getting a n u m b e r from the t e r m i n a l , a n u m b e r is read from the "DATA" s t a t e m e n t s . T h e first time a n u m b e r is needed for a R E A D , the first number in the first D A T A statement is r e t u r n e d . T h e second time one is n e e d e d , the second n u m b e r in the first D A T A statement is r e t u r n e d . When the entire contents of the first D A T A statement have been read in this m a n n e r , the second D A T A statement w i l l then b e u s e d . DATA is always read seq u e n t i a l l y in this m a n n e r , and there m a y be any number of DATA statements in your p r o g r a m . The p u r p o s e of this p r o g r a m is to p l a y a little game in which you try to guess one of the numbers contained in the DATA s t a t e m e n t s . For each guess that is typed i n , w e read through all of the numbers in the D A T A statements until w e find one that matches the g u e s s . If m o r e values are read than there are numbers in the DATA statem e n t s , an out of data (OD) error o c c u r s . T h a t is w h y in line 40 w e check to see if -999999 was r e a d . This is n o t one of the numbers to b e m a t c h e d , but is used as a flag to indicate that all of the data (possible correct guesses) has been r e a d . T h e r e f o r e , if -999999 was r e a d , w e know that the guess given was i n c o r r e c t . Before going back to line 10 for another g u e s s , w e need to m a k e the READ'S begin w i t h the first p i e c e of d a t a a g a i n . This is the function of the " R E S T O R E " . A f t e r the RESTORE is e n c o u n t e r e d , the next p i e c e of data read will b e the first p i e c e in the first DATA statement a g a i n . DATA statements m a y b e placed anywhere within the p r o g r a m . O n l y READ statements m a k e u s e of the D A T A statements in a p r o g r a m , and any other time they are encountered during program execution they will be ignored. TRE FCLLCWiWC JT^FOFAMyJOF APPLIES TO 2WF VERSION OF B A S I C ( W L Y A list of characters is referred to as a " S t r i n g " . M I T S , A L T A I R , and T H I S IS A T E S T are all s t r i n g s . Like n u m e r i c v a r i a b l e s , string variables can be assigned specific v a l u e s . String variables are distinguished from numeric v a r i a b l e s by a "$" after the variable n a m e . For e x a m p l e , try the following: A$="ALTAIR8800" OK PRINT A$ ALTAIR aaoo OK 17 In this e x a m p l e , w e set "ALTAIR 8 8 0 0 " . N o t e that we signed to A$ in q u o t e s . Now that w e have set A$ length of this v a l u e is (the this as follows: the string variable A$ to the string value also enclosed the character string to be asto a string v a l u e , we can find out what the number of characters it c o n t a i n s ) . We do PRINT LEN(A$),LEN("MITS") 11 4 OK T h e "LBN" function returns an integer equal to the number of characters in a s t r i n g . The number of characters in a string expression m a y range from 0 to 2 5 5 . A string which contains 0 characters is called the "NULL" s t r i n g . Before a string v a r i a b l e is set to a v a l u e in the p r o g r a m , it is initialized to the null s t r i n g . Printing a null string on the terminal will cause no characters to b e p r i n t e d , and the print head or cursor will not be advanced to the n e x t c o l u m n . T r y the following: PRINT LEN(Q$);Q$;3 Q 3 OK A n o t h e r way to create the null string is: Q$="" Setting a string v a r i a b l e to the null string can be used to free up the string space used b y a non-null string v a r i a b l e . Often it is d e s i r a b l e to access parts of a string and m a n i p u l a t e t h e m . Now that we h a v e set A$ to "ALTAIR 8 8 0 0 " , w e might want to print out only the first six characters of A $ . We would do so like this: PRINT LEFT$(A$,6) ALTAIR OK "LEFT$" is a string function which returns a string composed of the leftmost N characters of its string a r g u m e n t . Here's another example: FOR N=1 TO LEN(A$):PRINT LEFT$(A$,N):NEXT N A AL ALT ALTA ALTAI ALTAIR ALTAIR ALTAIR 5 ALTAIR 66 18 ALTAIR 660 ALTAIR 6600 OK Since A$ has 11 c h a r a c t e r s , this loop will be executed with N = l , 2 , 3 , . . . , 1 0 , 1 1 . The first time through only the first chatacter will be p r i n t e d , the second time the first two characters will be p r i n t e d , e t c . T h e r e is another string function called "RIGHT$y which returns the right N characters from a string e x p r e s s i o n . T r y substituting "iRlGHT$" for "LEFT$" in the p r e v i o u s example and see what h a p p e n s . T h e r e is also a string function which allows us to take characters from the m i d d l e of a s t r i n g . T r y the following: FOR N=1 TO LEN(A$):PRINT M I D $ ( A $ , N ) : N E X T N ALTAIR 6600 LTAIR 6600 TAIR 6600 AIR 6600 IR 6600 R 6600 6600 6600 600 00 0 OK "MID$" returns a string starting at the Nth position of A$ to the end (last character) of A $ . T h e first position of the string is position 1 and the last p o s s i b l e position of a string is position 2 5 5 . V e r y often it is d e s i r a b l e to extract only the Nth character from a s t r i n g . This can be d o n e b y calling MID$ with three a r g u m e n t s . T h e third argument specifies the number of characters to r e t u r n . For example: FOR N = 1 TO LEN(A$):PRINT M I D $ ( A $ , N , 1 ) , M I D $ ( A $ , N , 2 ) : N E X T N A L T A 1 R 6 6 0 0 AL LT fA AI IR R 6 66 60 00 0 OK 19 See the Reference Material for more details on the workings of " L E F T $ " , "RIGHT$" and " M I D $ " . Strings m a y also b e concatenated (put or joined together) through the u s e of the "+" o p e r a t o r . T r y the following: B$="MITS"+" "+A$ OK PRINT B$ NITS ALTAIR 6600 OK C o n c a t e n a t i o n is especially useful if you wish to take a string apart and then put it back t o g e t h e r with slight m o d i f i c a t i o n s . For instance: C$=LEFT$(B$,4)+"-"+MID$(B$,6,6)+"-"+RIGHT$(B$,4) OK PRINT C$ HITS-ALTAIR-6600 OK Sometimes it is d e s i r a b l e to convert a number to its string representation and v i c e - v e r s a . "VAL" and "STR$" perform these f u n c t i o n s . Try the following: STRING$="567.8" OK PRINT V A L ( S T R I N G $ ) 5L7.6 OK STRING$=STR$(3.1415) OK PRINT STRING$,LEFT$(STRING$,5) 3-1415 OK 3-14 "STR$" can be used to p e r f o r m formatted I/O on n u m b e r s . You can convert a number to a string and then u s e L E F T $ , R I G H T $ , MID$ and concatenation to reformat t h e n u m b e r as d e s i r e d . "STR$" can also b e u s e d to conveniently find out how m a n y p r i n t columns a n u m b e r will t a k e . For example: PRINT LEN(STR$(3.157)) b 20 OK If you have an application where a user is typing in a question as "WHAT IS THE VOLUME OF A CYLINDER OF RADIUS 5.36 F E E T , OF HEIGHT FEET?" you can u s e "VAL" to extract the numeric values 5.36 and 5.1 the q u e s t i o n . For further functions "CHR$" and "ASC" see Appendix such 5.1 from K. T h e following program sorts a list of string d a t a and prints out the sorted list. This p r o g r a m is v e r y similar to the one given earlier for sorting a n u m e r i c l i s t . 100 110 120 130 DIM A $ ( 1 5 ) : R E M ALLOCATE SPACE FOR STRING MATRIX FOR 1=1 T O 15:READ A $ ( I ) : N E X T I:REM READ IN STRINGS F=0:I=1:REM SET EXCHANGE FLAG TO ZERO AND SUBSCRIPT TO 1 IF A $ ( I ) < = A $ ( I + 1 ) THEN 180:REM DON'T EXCHANGE IF ELEMENTS IN ORDER 140 T $ = A $ ( I + 1 ) : R E M USE T$ TO SAVE A $ ( I + 1 ) 150 A $ ( I + 1 ) = A $ ( I ) : R E M EXCHANGE TWO CONSECUTIVE ELEMENTS 160A$(I)=T$ 170 F=1:REM FLAG T H A T WE EXCHANGED TWO ELEMENTS 180 1=1+1: IF I<15 GOTO 130 185 REM ONCE WE HAVE MADE A PASS THRU ALL E L E M E N T S , CHECK 187 REM TO SEE IF WE EXCHANGED A N Y . IF N O T , DONE S O R T I N G . 190 IF F THEN 120:REM EQUIVALENT TO IF F<>0 THEN 120 200 FOR 1=1 T O 15:PRINT A $ ( I ) : N E X T I: R E M PRINT SORTED LIST 210 REM STRING DATA FOLLOWS 220 DATA A P P L E , D O G , C A T , M I T S , A L T A I R , R A N D O M 230 DATA M O N D A Y , " * * * A N S W E R * * * " , " FOO" 240 DATA C O M P U T E R , FOO,ELP,MILWAUKEE,SEATTLE,ALBUQUERQUE 2! u u 22 o B451C LAfVEU^EE O 23 COMMANDS A command is u s u a l l y given after BASIC has typed O K . This is called the "Command L e v e l " . Commands m a y be used as program s t a t e m e n t s . Certain c o m m a n d s , such as L I S T , N E W and CLOAD will terminate program execution when they f i n i s h . NAME EXAMPLE PURPOSE/USE CLEAR *(SEE PAGE 42 FOR EXAMPLES A N D EXPLANATION) LIST LIST LIST 100 Lists current program optionally starting at specified line. List can b e control-C'd (BASIC will finish listing the current line) NULL NULL 3 (Null command only in 8K v e r s i o n , but paragraph applicable to 4K version also) Sets the number of null (ASCII 0) characters printed after a carriage return/line f e e d . The number of nulls printed m a y be set from 0 to 71. This is a must for h a r d c o p y terminals that require a delay after a CRLFf It is necessary to set the number of nulls typed on CRLF to 0 b e f o r e a paper tape of a program is read in from a Teletype (TELETYPE ts a r e g i s t e r e d trademark of *7:e TELFTTPF CCRP0A4T.RW . In the 8K v e r s i o n , u s e the null command to set the number of nulls to z e r o . In the 4K v e r s i o n , this is accomplished by patching location 46 octal to contain the number of nulls to be typed plus 1. (Depositing a 1 in location 46 would set the number of nulls typed to zero.) When you punch a paper tape of a program using the list c o m m a n d , null should be set >=3 for 10 CPS t e r m i n a l s , >=6 for 30 CPS term i n a l s . When not making a t a p e , we recommend that you u s e a null setting of 0 or 1 for T e l e t y p e s , and 2 or 3 for hard copy 30 CPS t e r m i n a l s . A setting of 0 will work with T e l e t y p e compatible C R T ' s . RUN RUN Starts execution of the program currently in m e m o r y at the lowest numbered statem e n t . Run deletes all variables (does a CLEAR) and restores D A T A . If you have stopped your program and wish to continue execution at some point in the p r o g r a m , u s e a direct GOTO statement to start execution of your program at the desired line. 24 *CRLF=carriage return/line feed NEhJ RUN EDO (8K version only) optionally starting at the specified line number NEM Deletes current program and all variables T R E F C L L C M Z W C C O M M A N D S A R E JFV T R E FX K E R R K W ONLY CONT CONT Continues program execution after a control/C is typed or a STOP statement is e x e c u t e d . You cannot continue after any e r r o r , after modifying your p r o g r a m , or before your program has been r u n . One of the main purposes of CONT is deb u g g i n g . Suppose at some point after running your p r o g r a m , nothing is p r i n t e d . This m a y b e because your program is performing some time consuming c a l c u l a t i o n , but it m a y be because you have fallen into an "infinite loop". An infinite loop is a series of BASIC statements from which there is no e s c a p e . T h e A L T A I R will keep executing the series of statements over and o v e r , until you intervene or until power to the ALTAIR is cut o f f . If you suspect your program is in an infinite l o o p , type in a c o n t r o l / C . In the 8K v e r s i o n , the line number of the statement BASIC was executing will be typed o u t . A f t e r BASIC has typed out O K , you can u s e PRINT to type out some of the values of your v a r i a b l e s . After examining these values you m a y become satisfied that your program is functioning c o r r e c t l y . You should then type in CONT to continue executing your program where it left o f f , or type a direct GOTO statement to resume execution of the program at a different line. You could also u s e assignment (LET) statements to set some of your variables to different v a l u e s . R e m e m b e r , if you control/C a program and expect to continue it l a t e r , you m u s t not get any errors or type in any new program lines. If you d o , you won't be able to continue and will get a "CN" (continue not) e r r o r . It is impossible to continue a direct c o m m a n d . CONT always resumes execution at the next statement to be executed in your program when control/C was t y p e d . 25 CLOAD CLOAD P Loads the program named P from the cassette t a p e . A NEW command is autom a t i c a l l y done before the CLOAD command is e x e c u t e d . When d o n e , the CLOAD will type out OK as u s u a l . The onecharacter program designator m a y be any printing c h a r a c t e r . CSAVE and CLOAD u s e I/O ports 6 § 7. See Appendix I for m o r e information. CSAVE CSAVE P Saves on cassette tape the current program in the ALTAIR's m e m o r y . T h e program in m e m o r y is left u n c h a n g e d . More than one program m a y be stored on cassette using this c o m m a n d . CSAVE and CLOAD use I/O ports 6 § 7. See Appendix I for m o r e information OPERATORS SYMBOL t SAMPLE STATEMENT PURPOSE/USE A=100 LET Z=E-5 Assigns a value to a variable T h e LET is optional B=-A N e g a t i o n . N o t e that 0-A is s u b t r a c t i o n , while -A is n e g a t i o n . 130 PRINT X+3 Exponentiation (8K v e r s i o n ) (equal to X*X*X in the sample statement) 0+0=1 0 to any other power = 0 A t B , with A negative and B not an integer gives an FC e r r o r . 140 X=R*(B*D) Multiplication 150 PRINT X/1.3 Division IbO Z=R+T+3 Addition 170 J=100-I Subtraction RULES FOR EVALUATING EXPRESSIONS: 1) Operations of higher precedence are performed before operations of lower p r e c e d e n c e . This means the multiplication and divisions are performed before additions and s u b t r a c t i o n s . As an e x a m p l e , 2+10/5 equals 4 , n o t 2.4. When operations of equal precedence are found in a f o r m u l a , the left hand one is executed first: 6 - 3 + 5 = 8 , not - 2 . 26 2) T h e order in which operations are performed can always be specified explicitly through the u s e of p a r e n t h e s e s . For ins t a n c e , to add 5 to 3 and then divide that by 4 , we would u s e (5+3)/4, which equals 2. If instead we had used 5 + 3 / 4 , we would get 5.75 as a result (5 plus 3 / 4 ) . T h e p r e c e d e n c e of operators used in evaluating expressions is as f o l l o w s , in order beginning with the highest precedence: fFVcte; Operators Zested on the same Ztne have the same precedence J 1) FORMULAS ENCLOSED IN PARENTHESIS ARE ALhJAYS EVALUATED FIRST 5) + EXPONENTIATION C3R VER32YW ONLY; 3) NEGATION -X UHERE X MAY BE A FORMULA 4) * MULTIPLICATION AND DIVISION 5) L) + ADDITION AND SUBTRACTION RELATIONAL OPERATORS: = E<2UAL feq^aZ precedence for <> NOT Et2UAL a n s^; < LESS THAN > GREATER THAN <= LESS THAN OR E<2UAL >= GREATER THAN OR Et2UAL / VERSION ONLY) (These 2 be^oM are Log^caZ Operators) 7) NOT LOGICAL AND BITWISE "NOT" LIKE NEGATION, NOT TAKES ONLY THE FORMULA TO ITS RIGHT AS AN ARGUMENT a) AND LOGICAL AND BITWISE "AND" OR LOGICAL AND BITWISE "OR" In the 4K version of B A S I C , relational operators can only be used once in an IF s t a t e m e n t . H o w e v e r , in the 8K version a relational expression can be used as part of any e x p r e s s i o n . Relational O p e r a t o r expressions will always h a v e a v a l u e of or a v a l u e of False (0). T h e r e f o r e , (5#4)=0, (5=5)=-l, (4>5)=0, etc. T h e THEN clause of an IF statement is executed whenever the after the IF is not equal to 0 . T h a t is to s a y , IF X T H E N . . . is to IF X<>0 T H E N . . . . 27 True (-1) (4<5)=-l, formula equivalent SYMBOL SAMPLE STATEMENT PURPOSE/USE ID IF A=15 THEN 40 Expression Equals Expression 70 IF A<>0 THEN 5 Expression Does Not Equal Expression 30 IF B>100 THEN 5 Expression Greater Than Expression 1L0 IF B<3 THEN 10 Expression Less Than Expression <=,=< 130 IF 100<=B+C THEN 10 Expression Less Than Or Equal To Expression >=,=> 110 IF (2=>R THEN 50 Expression Greater Than Or Equal To Expression AND B IF A<5 AND BC)*B-(B<=C)*C This statement will set the variable A to M A X ( B , C ) = the larger of the two variables B and C . STATEMENTS /Vote; -Tn tTze f o Z Z o n i n g description o f s t a t e m e n t s , an a r j M m e n t o f 7 or ^ d e n o t e s a n M m e r i c v a r i a M e , X denotes a numeric e x p r e s s i o n , denotes a string expression a n d a n Z o r <7 d e n o t e s a n expression tTzat is trMncated to an integer b e f o r e t/ze statement is e x e c u t e d . Truncation m e a n s t M t any f r a c t i o n a l p a r t o f t&e n u m b e r is Zest, e . g . 3.3 becomes 3, 4.0Z. becomes ^ n expression is a series o f u a r i a M e s , o p e r a t o r s , f u n c t i o n c a M s a n d constants M^ic/: a f t e r tTze operations a n d f u n c t i o n c a H s are p e r f o r m e d Msing t^e p r e c e d e n c e r n ^ e s , eva&Ma^es a numeric o r string t?a%ne. 4 c o n s t a n t is either a n u m b e r /3.J4J or a string ZiteraZ ( " F W J . 30 NAME EXAMPLE PUKPOSii/USE DATA 10 DATA li3-.-lE3-..04 Specifies d a t a , read from left to r i g h t . Information appears in d a t a statements in the same order as it will be read in the p r o g r a m . IN THE 4K VERSION OF B A S I C , DATA STATEMENTS M U S T BE THE FIRST STATEM E N T S ON A LINE. Expressions m a y also appear in the 4K version d a t a s t a t e m e n t s . BO DATA " FOO",ZOO C3R Verstcn,) Strings m a y be read from DATA s t a t e m e n t s . If you want the string to contain leading spaces (blanks), colons (:) or commas (,), you must enclose the string in double q u o t e s . It is impossible to have a double quote within string data or a string literal. (""MITS"" is illegal) 100 DEF FNA(V)=V/B+C (RK Vers^cMj T h e user can define functions like the built-in functions (SQR, S G N , A B S , etc.) through the u s e of the DEF s t a t e m e n t . T h e name of the function is "FN" followed by any legal variable n a m e , for example: F N X , F N J 7 , F N K O , F N R 2 . User defined functions are restricted to one l i n e . A function m a y be defined to be any express i o n , but m a y only have one a r g u m e n t . In the example B 6 C are variables that are used in the p r o g r a m . Executing the DEF statement defines the function. User defined functions can be redefined by executing another DEF statement for the same f u n c t i o n . User defined string functions are not a l l o w e d . "V" is called the dummy variable. Execution of this statement following the above would cause Z to be set to 3 / B + C , but the v a l u e of V would be u n c h a n g e d . DEF 110 Z=FNA(3) DIM 113 DIM A(3),B(10) Allocates space for m a t r i c e s . All m a t r i x elements are set to zero b y the DIM statement. 114 DIM R 3 ( 5 , 5 ) , D 3 ( B , B , E ) (SR Vers^cnJ Matrices can h a v e m o r e than one d i m e n s i o n . Up to 255 dimensions are a l l o w e d , but due to the restriction of 72 characters per line the practical maximum is about 34 dimensions. 115 DIM <21(N),Z(E*I) Matrices can b e dimensioned dynamically during program e x e c u t i o n . If a m a t r i x is not explicitly dimensioned with a DIM s t a t e m e n t , it is assumed to be a single dimensioned m a t r i x of w h o s e single subscript M 117 A(B)=4 END m a y range from 0 to 10 (eleven e l e m e n t s ) . If this statement was encountered before a DIM statement for A was found in the p r o g r a m , it would be as if a DIM A(10) had been executed previous to the execution of line 117. All subscripts start at zero (0), which means that DIM X(100) really allocates 101 matrix e l e m e n t s . END m FOR 300 FOR V = 1 TO 1 - 3 STEP -b , j Terminates program execution without printing a BREAK m e s s a g e , (see STOP) C O N T after an END statement causes execution to resume at the statement after the END s t a t e m e n t . END can b e used anywhere in the p r o g r a m , and is o p t i o n a l . (see N E X T statement) V is set equal to the v a l u e of the expression following the equal s i g n , in this case 1. This value is called the initial v a l u e . Then the statements between FOR and N E X T are e x e c u t e d . The final value is the v a l u e of the expression following the T O . T h e step is the v a l u e of the expression following S T E P . When the N E X T statement is encount e r e d , the step is added to the variable. 3ld FOR V = 1 TO 1 - 3 If no STEP was s p e c i f i e d , it is assumed to b e o n e . If the step is positive and the new value of the v a r i a b l e is <= the final value (9.3 in this e x a m p l e ) , or the step value is negative and the new value of the variable is => the final v a l u e , then the first statement following the FOR statement is e x e c u t e d . O t h e r w i s e , the statement following the N E X T statement is e x e c u t e d . All FOR loops execute the statements between the FOR and the NEXT at least o n c e , even in cases like FOR V=1 TO 0 . 315 FOR V=10*N TO 3-4/(3 STEP S(3R(R) N o t e that expressions (formulas) m a y be used for the ini t i a l , final and step values in a FOR l o o p . T h e values of the expressions are computed only o n c e , before the body of the FOR NEXT loop is e x e c u t e d . 32 ^ 330 FOR V=1 TO 1 STEP -1 When the statement after the NEXT is e x e c u t e d , the loop variable is never equal to the final v a l u e , but is equal to whatever value caused the FOR...NEXT loop to term i n a t e . T h e statements between the FOR and its corresponding NEXT in both examples above (310 § 320) would be executed 9 t i m e s . Error: do not 330 FOR U=1 TO 10: FOR U=1 TO :NEXT L):NEXT h) u s e nested FOR...NEXT loops with the same index v a r i a b l e . FOR loop nesting is limited only by the available m e m o r y , (see Appendix D ) GOTO 50 GOTO 100 GOSUB 10 GOSUB 110 :hes to the statement s p e c i f i e d . Branches to the specified statement (910) until a RETURN is encountered; when a branch is then m a d e to the statement after the G O S U B . GOSUB nesting is limited only by the available m e m o r y , (see Appendix D ) IF...GOTO 33 IF X<=Y+B3-4 GOTO 13 (6R VersioHj Equivalent to IF...THEN, except that IF...GOTO m u s t be followed by a line n u m b e r , while IF...THEN can be followed by either a line number or another s t a t e m e n t . IF...THEN IF X<10 THEN 5 Branches to specified statement if the relation is T r u e . 30 IF X<0 THEN PRINT "X LESS THAN 0" Executes all of the statements on the remainder of the line after the THEN if the relation is T r u e . 35 IF X=5 THEN 50:Z=A W A R N I N G . The "Z=A" will never be executed because if the relation is t r u e , BASIC will branch to line 5 0 . If the relation is false Basic will proceed to the line after line 25. Bb IF X<0 THEN PRINT "ERROR, X NEGATIVE": GOTO 350 In this e x a m p l e , if X is less than 0 , t h e PRINT statement will be executed and then the GOTO statement will branch to line 3 5 0 . If the X was 0 or p o s i t i v e , BASIC will proceed to execute the lines after line 2 6 . 33 INPUT 3 INPUT V,U,U3 5 INPUT "VALUE";V Requests data from the terminal (to be typed i n ) . Each value must be separated from the preceeding value by a comma (,). The last value typed should be followed by a carriage r e t u r n . A "?" is typed as a prompt c h a r a c t e r . In the 4K v e r s i o n , a value typed in as a response to an INPUT statement m a y be a f o r m u l a , such as 2*SIN(.16)-3. H o w e v e r , in the 8K v e r s i o n , only constants m a y be typed in as a response to an INPUT s t a t e m e n t , such as 4.SE-3 or " C A T " . If more data was requested in an INPUT statement than was typed i n , a "??" is printed and the rest of the data should be typed i n . If m o r e data was typed in than was r e q u e s t e d , the extra data will be ignored. The 8K version will print the warning "EXTRA IGNORED" when this h a p p e n s . The 4K version will not print a warning m e s s a g e . (FX VerstCMj Strings must be input in the same format as they are specified in DATA statements. (<% Vers^cnJ Optionally types a prompt string ("VALUE") before requesting data from the t e r m i n a l . If carriage return is typed to an input s t a t e m e n t , BASIC returns to command m o d e . Typing CONT after an INPUT command has been interrupted will cause execution to resume at the INPUT s t a t e m e n t . LET 300 LET W=X 310V=5.1 Assigns a v a l u e to a variable "LET" is o p t i o n a l . NEXT 340 NEXT V 345 NEXT Marks the end of a FOR l o o p . C3.K Version) If no variable is g i v e n , matches the m o s t recent FOR loop. fRK VorstCMj A single NEXT m a y be used to match m u l t i p l e FOR s t a t e m e n t s . Equivalent to N E X T V : N E X T W . 350 NEXT V,h) ON...GOTO 100 ON I GOTO 10,30,30,40 (FX VersionJ Branches to the line indicated by the I'th number after the G O T O . That is: IF 1 = 1 , THEN GOTO LINE 10 IF 1 = 2 , THEN GOTO LINE 20 IF 1=3, THEN GOTO LINE 30 IF 1 = 4 , THEN GOTO LINE 4 0 . 34 If 1=0 or I attempts to select a nonexistent line (>=5 in this c a s e ) , the statement after the ON statement is e x e c u t e d . H o w e v e r , if I is >255 or < 0 , an FC error m e s s a g e will r e s u l t . As m a n y line numbers as will fit on a line can follow an O N . . . G O T O . 105 ON SGN(X)+2 GOTO H0,50,L0 This statement will branch to line 40 if the expression X is less than z e r o , to line 50 if it equals z e r o , and to line 60 if it is greater than zero. ON...GOSUB 110 ON I GOSUB 50,bO (FR Version; Identical to " O N . . . G O T O " , except that a subroutine call (GOSUB) is executed instead of a G O T O . RETURN from the GOSUB branches to the statement after the O N . . . G O S U B . OUT 355 OUT I,J (RK Version; Sends the byte J to the output port I. Both I § J must be >=0 and < = 2 5 5 . POKE 357 POKE I,J CSR Version; The POKE statement stores the byte specified by its second argument (J) into the location given by its first argument (I). The byte to be stored m u s t be =>0 and < = 2 5 5 , or an FC error will o c c u r . T h e address (I) must be =>0 and < = 3 2 7 6 7 , or an FC error will r e s u l t . Careless u s e of the POKE statement will probably cause you to "poke" BASIC to death; that i s , the m a c h i n e will h a n g , and you will have to reload BASIC and will lose any program you had typed i n . A POKE to a non-existent m e m o r y location is h a r m l e s s . O n e of the main uses of POKE is to pass arguments to m a c h i n e language s u b r o u t i n e s . (see Appendix J ) You could also u s e PEEK and POKE to write a m e m o r y diagnostic or an assembler in B A S I C . PRINT 3L0 370 360 310 400 PRINT PRINT PRINT PRINT PRINT X,Y;Z Prints the value of expressions on the t e r m i n a l . If the list of values to be X,Y; printed out does not end with a comma (,) "VALUE IS";A or a semicolon (;), then a carriage AE,B, return/line feed is executed after all the values have been p r i n t e d . Strings enclosed in quotes (") m a y also be p r i n t e d . If a semicolon separates two expressions in the l i s t , their values are printed next to each o t h e r . If a comma appears after an 35 expression in the l i s t , and the print head is at print position 56 or m o r e , then a carriage return/line feed is e x e c u t e d . If the print head is before print position 5 6 , then spaces are printed until the carriage is at the beginning of the next 14 column field (until the carriage is at column 1 4 , 2 8 , 42 or 56...). If there is no list of expressions to be p r i n t e d , as in line 370 of the e x a m p l e s , then a carriage return/line feed is executed. 410 PRINT MIDt(A3,B); (RK Version) String expressions m a y be printed. READ 410 READ ViM Reads data into specified variables from a DATA s t a t e m e n t . T h e first piece of data read will be the first piece of data listed in the first DATA statement of the prog r a m . T h e second p i e c e of data read will be the second piece listed in the first DATA s t a t e m e n t , and so o n . When all of the data have been read from the first DATA s t a t e m e n t , the next piece of data to be read will be the first piece listed in the second DATA statement of the p r o g r a m . Attempting to read m o r e data than there is in all the DATA statements in a program will cause an OD (out of data) e r r o r . In the 4K v e r s i o n , an SN error from a READ statement can mean the data it was attempting to read from a DATA statement was improperly f o r m a t t e d . In the 8K v e r s i o n , the line number given in the SN error will refer to the line number where the error actually is l o c a t e d . REM 500 REN NOtd SET V-0 Allows the programmer to put comments in his p r o g r a m . REM statements are not exec u t e d , but can be branched t o . A REM statement is terminated by end of l i n e , but n o t b y a " : " . In this case the V=0 will never be executed by B A S I C . In this case V=0 will be executed 505 REM SET V=0: V=0 50k V-0: REM S E T V-0 RESTORE 510 RESTORE A l l o w s the re-reading of DATA s t a t e m e n t s . A f t e r a R E S T O R E , the next piece of data read will be the first piece listed in the first DATA statement of the p r o g r a m . T h e second p i e c e of data read will b e the second p i e c e listed in the first DATA s t a t e m e n t , and so on as in a normal READ o p e r a t i o n . 36 RETURN 50 RETURN Causes a subroutine to return to the statement after the most recently executed G O S U B . STOP 1000 STOP Causes a program to stop execution and to enter command m o d e . C3R Version; Prints BREAK IN LINE 9 0 0 0 . (as per this example) C0NT after a STOP branches to the statement following the STOP. UAIT B05 UAIT I,J,K B0L MAIT I,J (3R Version; This statement reads the status of input port I , exclusive OR's K with the s t a t u s , and then AND's the result with J until a non-zero result is o b t a i n e d . Execution of the program continues at the statement following the WAIT s t a t e m e n t . If the WAIT statement only has two a r g u m e n t s , K is assumed to be zero. If you are waiting for a bit to become z e r o , there should be a one in the corresponding position of K . I , J and K must be =>0 and < = 2 5 5 . 4K INTRINSIC F U N C T I O N S ABS(X) 150 PRINT ABS(X) Gives the absolute v a l u e of the expression X . A B S returns X if X > = 0 , -X o t h e r w i s e . INT(X) 140 PRINT INT(X) Returns the largest integer less than or equal to its argument X . For example: I N T ( . 2 3 ) = 0 , I N T ( 7 ) = 7 , I N T ( - . 1 ) = - 1 , INT (-2)= - 2 , INT(1.1)=1. T h e following would round X to D decimal places: INT(X*10tD+.5)/10+D RND(X) 170 PRINT RND(X) Generates a random number between 0 and 1. T h e argument X controls the generation of random numbers as follows: X<0 starts a new sequence of random numbers using X . Calling RND with the same X starts the same random number s e q u e n c e . X=0 gives the last random number g e n e r a t e d . Repeated calls to RND(0) will always return the same random n u m b e r . X>0 generates a new random n u m b e r between 0 and 1 . N o t e that (B-A)*RND(1)+A will generate a random number between A S B . 37 SGN(X) 230 PRINT SGN(X) Gives 1 if X > 0 , 0 if X = 0 , and -1 if X < 0 . SIN(X) 110 PRINT SIN(X) Gives the sine of the expression X . X is interpreted as being in r a d i a n s . Note: COS (X)=SIN(X+3.14159/2) and that 1 Radian =180/PI degrees=57.2958 degrees; so that the sine of X degrees= S I N ( X / 5 7 . 2 9 5 8 ) . S(3R(X) 160 PRINT S(2R(X) Gives the square root of the argument X . A n FC error will occur if X is less than zero. TAB(I) B40 PRINT TAB(I) Spaces to the specified print position (column) on the t e r m i n a l . M a y be used only in PRINT s t a t e m e n t s . Zero is the leftmost column on the t e r m i n a l , 71 the r i g h t m o s t . If the carriage is beyond position I , then no printing is d o n e . I m u s t be =>0 and <=255. USR(I) BOO PRINT USR(I) Calls the user's m a c h i n e language subroutine with the argument I . See POKE PEEK and Appendix J . 8K FUNCTIONS f i n c h e s a H those M s t e d M7K?er 4R J N y R J N S Z C F W C y f O N S p ^ M S the foZZ.oMtMQ' tw a&Ztt-MM.J ATN(X) BIO PRINT ATN(X) Gives the arctangent of the argument X . T h e result is returned in radians and ranges from -PI/2 to P I / 2 . (PI/2=1.5708) COS(X) BOO PRINT COS(X) Gives the cosine of the expression X . is interpreted ias being in r a d i a n s . EXP(X) 150 PRINT EXP(X) Gives the constant "E" (2.71828) raised to the power X . (E+X) The maximum argument that can be passed to EXP without overflow occuring is 87.3365. FRE(X) B70 PRINT FRE(0) Gives the number of m e m o r y bytes currently unused by B A S I C . M e m o r y allocated for STRING space is not included in the count returned by F R E . To find the number of free bytes in STRING s p a c e , call FRE with a STRING a r g u m e n t , (see FRE u n d e r STRING FUNCTIONS) INP(I) Bb5 PRINT INP(I) Gives the status of (reads a byte from) input port I. Result is =>0 and < = 2 5 5 . 38 X LOG(X) IbO PRINT LOG(X) Gives the natural (Base ii) lonarithm of Its argument X . To obtain the Huso Y logarithm of X use the formula LOG (X)/LOG (Y) Example: T h e base 10 (common) log of 7 = LOG(7)/ LOG(10). PEEK 35b PRINT PEEK(I) T h e PEEK function returns the contents of m e m o r y address I. T h e value returned will be =>0 and < = 2 5 5 . If I is >32767 or < 0 , an FC error will o c c u r . An attempt to read a non-existent m e m o r y address will return 255. (see POKE statement) POS(I) BbO PRINT POS(I) Gives the current position of the terminal print head (or cursor on C R T ' s ) . The leftmost character position on the terminal is position zero and the rightmost is 71. SPC(I) B5Q PRINT SPC(I) Prints I space (or blank) characters on the t e r m i n a l . M a y be used only in a PRINT s t a t e m e n t . X m u s t be =>0 and <=255 or an FC error will r e s u l t . TAN(X) BQ0 PRINT TAN(X) Gives the tangent of the expression X . X is interpreted as being in r a d i a n s . STRINGS (FX Version OnZz/J 1) A string m a y be from 0 to 255 characters in length. All string variables end in a dollar sign ( $ ); for e x a m p l e , A $ , B 9 $ , K $ , HELL0$. 2) String matrices m a y be dimensioned exactly like numeric m a t r i c e s . For i n s t a n c e , DIM A $ ( 1 0 , 1 0 ) creates a string m a t r i x of 121 e l e m e n t s , eleven rows by eleven columns (rows 0 to 10 and columns 0 to 10). Each string m a t r i x element is a complete s t r i n g , which can be up to 255 characters in l e n g t h . 3) T h e total number of characters in u s e in strings at any time during program execution cannot execeed the amount of string s p a c e , or an OS error will r e s u l t . A t i n i t i a l i z a t i o n , you should set up string space so that it can contain the maximum number of characters which can be used b y strings at any one time during program e x e c u t i o n . NAME EXAMPLE PURPOSE/USE DIN B5 DIM A3(10,10) Allocates space for a pointer and length for each element of a string m a t r i x . No string space is a l l o c a t e d . See Appendix D . 39 LET 37 LET A6="FOO"+V6 Assigns the value of a string expression to a string v a r i a b l e . LET is o p t i o n a l . String comparison o p e r a t o r s . Comparison is m a d e on the basis of ASCII c o d e s , a character at a time until a difference is f o u n d . If during the comparison of two s t r i n g s , the end of one is r e a c h e d , the shorter string is considered smaller, N o t e that "A " is greater than "A" since trailing spaces are s i g n i f i c a n t . > < <= >= 30 LET Z 3 = R 3 + % 3 String c o n c a t e n a t i o n . T h e resulting string must be less than 256 characters in length or an LS error will o c c u r . INPUT 40 INPUT X3 Reads a string from the user's t e r m i n a l . String does not have to be quoted; but if n o t , leading blanks will be ignored and the string will be terminated on a "," or ":" c h a r a c t e r . READ 50 READ X3 Reads a string from DATA statements within the p r o g r a m . Strings do not have to be quoted; but if they are n o t , they are terminated on a "," or ":" character or end of line and leading spaces are ignored. See DATA for the format of string d a t a . PRINT bO PRINT X* 70 PRINT "F00"+A3 Prints the string expression on the user's terminal. STRING FUNCTIONS C8X Version OM^j ASC(X3) 300 PRINT ASC(X3) Returns the ASCII numeric value of the first character of the string expression X $ . See Appendix K for an A S C I I / n u m b e r conversion t a b l e . An FC error will occur if X$ is the null s t r i n g . CHR3M) 375 PRINT CHR3(I) Returns a one character string whose single character is the ASCII equivalent of the v a l u e of the argument (I) which must be =>0 and < = 2 5 5 . See Appendix K . FRE(X3) 373 PRINT FREf"") When called with a string a r g u m e n t , FRE gives the number of free bytes in string space. LEFT3(X3,I) Gives the leftmost I characters of the 310 PRINT L E F T 3 ( X 3 , I ) string expression X $ . If I<=0 or >255 an FC error o c c u r s . 40- LEN(X3) 330 PRINT LEN(X3) Gives the length of the string expression X$ in characters (bytes). Non-printing characters and blanks are counted as part of the length. MIDS(X$,I) MID$ called with two arguments returns characters from the string expression X$ starting at character position I. If I > L E N ( I $ ) , then MID$ returns a null (zero length) s t r i n g . If I<=0 or > 2 5 5 , an FC error o c c u r s . MID3(X3,I,J) MID$ called with three arguments returns 340 PRINT MID3(X3,I,J) a string expression composed of the characters of the string expression X$ starting at the 1th character for J chara c t e r s . If I > L E N ( X $ ) , MID$ returns a null s t r i n g . If I or J <=0 or > 2 5 5 , an FC error o c c u r s . If J specifies m o r e characters than are left in the s t r i n g , all characters from the 1th on are r e t u r n e d . 330 PRINT M I D 3 ( X 3 , I ) RIGHTS(XS,I) 330 PRINT RIGHTS(XS,I) Gives the rightmost I characters of the string expression X $ . When I<=0 or >255 an FC error will o c c u r . If I>=LEN(X$) then RIGHT$ returns all of X$. STRS(X) 310 PRINT STRS(X) Gives a string which is the character representation of the n u m e r i c expression X . For i n s t a n c e , STR$(3.1)=" 3 . 1 " . VAL(XS) 330 PRINT VAL(XS) Returns the string expression X$ converted to a n u m b e r . For i n s t a n c e , V A L ( " 3 . 1 " ) = 3 . 1 If the first non-space character of the string is not a plus (+) or minus ( - ) sign a digit or a decimal point (.) then zero will be r e t u r n e d . SPECIAL C H A R A C T E R S CHARACTER USE @ Erases current line being t y p e d , and types a carriage r e t u r n / l i n e f e e d . An is u s u a l l y a s h i f t / P . -*- f&acAxEPrczj o r w a f e r Hue,) Erases last character t y p e d . If no m o r e characters are left on the l i n e , types a carriage return/line f e e d . "-<-" is u s u a l l y a s h i f t / 0 . 41 C A R R I A G E RETURN A c a r r i a g e r e t u r n m u s t end every line typed i n . Returns p r i n t head or C R T c u r s o r to the first position (leftmost) on l i n e . A line feed is always e x e c u t e d after a carriage return. CONTROL/C I n t e r r u p t s e x e c u t i o n o f a p r o g r a m or a list c o m m a n d . C o n t r o l / C has e f f e c t w h e n a s t a t e m e n t f i n i s h e s exec u t i o n , or in the c a s e o f i n t e r r u p t i n g a LIST comm a n d , w h e n a c o m p l e t e line has f i n i s h e d p r i n t i n g . In b o t h c a s e s a r e t u r n is m a d e to B A S I C ' S c o m m a n d level and OK is t y p e d . C<% Version,) P r i n t s " B R E A K IN LINE X X X X " , w h e r e X X X X is t h e line n u m b e r o f t h e n e x t s t a t e m e n t to be executed. : A c o l o n is u s e d to s e p a r a t e s t a t e m e n t s on a l i n e . C o l o n s m a y be u s e d in d i r e c t and i n d i r e c t s t a t e m e n t s . T h e o n l y l i m i t o n t h e n u m b e r of s t a t e m e n t s p e r line is t h e line l e n g t h . It is n o t p o s s i b l e to G O T O or G O S U B to the m i d d l e of a l i n e . (colon) CONTROL/O T y p i n g a C o n t r o l / 0 o n c e c a u s e s BASIC to s u p p r e s s all o u t p u t u n t i l a r e t u r n is m a d e to c o m m a n d l e v e l , an i n p u t s t a t e m e n t is e n c o u n t e r e d , a n o t h e r c o n t r o l / 0 is t y p e d , or an e r r o r o c c u r s . ? Q u e s t i o n m a r k s a r e e q u i v a l e n t to P R I N T . F o r i n s t a n c e , ? 2+2 is e q u i v a l e n t to P R I N T 2 + 2 . Q u e s t i o n m a r k s c a n a l s o be u s e d in i n d i r e c t s t a t e m e n t s . 10 ? X , w h e n l i s t e d w i l l b e t y p e d as 10 P R I N T X . MISCELLANEOUS 1) T o r e a d in a p a p e r t a p e w i t h a p r o g r a m on it (8K V e r s i o n ) , t y p e a c o n t r o l / 0 and feed in t a p e . T h e r e w i l l b e n o p r i n t i n g as the tape is r e a d i n . T y p e c o n t r o l / 0 a g a i n w h e n t h e t a p e is t h r o u g h . A l t e r n a t i v e l y , s e t n u l l s = 0 and f e e d in t h e p a p e r t a p e , and w h e n d o n e r e s e t n u l l s to t h e a p p r o p r i a t e s e t t i n g for y o u r t e r m i n a l . E a c h line m u s t b e f o l l o w e d b y two r u b o u t s , or a n y o t h e r n o n - p r i n t i n g c h a r a c t e r . If t h e r e a r e lines w i t h o u t line n u m b e r s (direct c o m m a n d s ) t h e A L T A I R w i l l f a l l b e h i n d the i n p u t c o m i n g from p a p e r t a p e , so t h i s in n o t r e c o m m e n d i n g . U s i n g n u l l in t h i s f a s h i o n w i l l p r o d u c e a l i s t i n g o f y o u r tape in t h e 8K v e r s i o n (use c o n t r o l / 0 m e t h o d if y o u d o n ' t w a n t a l i s t i n g ) . T h e n u l l m e t h o d is t h e o n l y w a y to r e a d in a t a p e in the 4K v e r s i o n . T o r e a d in a p a p e r t a p e o f a p r o g r a m in t h e 4K v e r s i o n , set t h e n u m b e r o f n u l l s t y p e d o n c a r r i a g e r e t u r n / l i n e feed to zero b y p a t c h ing l o c a t i o n 4 6 (octal) t o b e a 1 . F e e d in t h e p a p e r t a p e . W h e n 42 the tape has finished r e a d i n g , stop the CPU and repatch location 46 to be the appropriate n u m b e r of null characters (usually 0 , so deposit a 1 ) . When the tape is f i n i s h e d , BASIC will print SN ERROR because of the "OK" at the end of the t a p e . 2) To punch a p a p e r tape of a p r o g r a m , set the number of nulls to 3 for 110 BAUD terminals (Teletypes) and 6 for 300 BAUD t e r m i n a l s . T h e n , type LIST; b u t , do not type a carriage r e t u r n . N o w , turn on the terminal's p a p e r tape p u n c h . Put the terminal on local and hold down the R e p e a t , C o n t r o l , Shift and P keys at the same t i m e . Stop after you h a v e punched about a 6 to 8 inch leader of n u l l s . T h e s e nulls will be ignored by BASIC when the p a p e r tape is read i n . Put the terminal back on line. Now hit carriage r e t u r n . A f t e r the program has finished p u n c h i n g , put some trailer on the paper tape by holding down the same four keys as b e f o r e , with the terminal on local. After you have punched about a six inch t r a i l e r , tear off the paper tape and save for later u s e as d e s i r e d . 3) Restarting BASIC at location zero (by toggling S T O P , Examine location 0 , and RUN) will cause BASIC to return to command level and type " O K " . H o w e v e r , typing Control/C is preferred because Control/ C is guaranteed not to leave garbage on the stack and in v a r i a b l e s , and a Control C'd p r o g r a m m a y be c o n t i n u e d , (see CONT command) 4) T h e m a x i m u m line length is 72 characters?* If you attempt to type too m a n y characters into a l i n e , a bell (ASCII 7) is e x e c u t e d , and the character you typed in will not be e c h o e d . At this point you can either type backarrow to delete part of the l i n e , or at-sign to delete t h e w h o l e line. T h e character you typed which caused BASIC to type the bell is not inserted in the line as it occupies the character position one beyond the end of the l i n e . *CLEAR CLEAR CLEAR X 10 CLEAR SO Deletes all v a r i a b l e s . f<% Version; Deletes all v a r i a b l e s . When used with an argument " X " , sets the amount of space to b e allocated for u s e b y string v a r i a b l e s to the number indicated b y its argument " X " . C3R Version; Same as above; b u t , m a y be used at the beginning of a program to set the exact amount of string space n e e d e d , leaving a m a x i mum amount of m e m o r y for the program i t s e l f . NOTE: If no argument is g i v e n , the string space is set at 200 b y d e f a u l t . A n O M error will occur if an attempt is m a d e to allocate m o r e string space than there is available memory. .**For inputting o n l y . 43 u u u 44 45 HOW TO LOAD BASIC When the ALTAIR is first turned o n , there is random garbage in its m e m o r y . BASIC is supplied on a paper tape or audio c a s s e t t e . Somehow the information on the paper tape or cassette m u s t be transfered into the c o m p u t e r . Programs that perform this type of information transfer are called l o a d e r s . Since initially there is nothing of use in m e m o r y ; you m u s t toggle i n , using the switches on the front p a n e l , a 20 instruction bootstrap loader. This loader will then load B A S I C . To load BASIC follow these steps: 1) Turn the ALTAIR o n . 2) Raise the STOP switch and RESET switch 3) Turn your terminal (such as a Teletype) to L I N E . simultaneously. Because the instructions m u s t be toggled in v i a the switches on the front p a n e l , it is r a t h e r inconvenient to specify the positions of each switch as "up" or " d o w n " . T h e r e f o r e , the switches are arranged in groups of 3 as indicated by the broken lines below switches 0 through 1 5 . To specify the p o s i t i o n s of each s w i t c h , w e u s e the numbers 0 through 7 as shown below: 3 SWITCH GROUP LEFTMOST MIDDLE RIGHTMOST Down Down Down Down Up Up Up Up Down Down Up Up Down Down Up Up Down Up Down Up Down Up Down Up OCTAL NUMBER 0 1 2 3 4 5 S o , to p u t the octal n u m b e r 315 in switches 0 through 7 , the switches would have the following p o s i t i o n s : 7 6 5 4 3 2 1 0 -SWITCH UP UP DOWN DOWN UP UP DOWN UP -POSITION 3 1 5 46 -OCTAL N O . N o t e that switches 8 through IS were not u s e d . Switches 0 through 7 correspond to the switches labeled DATA on the front p a n e l . A memory address would use all 16 s w i t c h e s . The following program is the bootstrap loader for users loading from paper t a p e , and not using a REV 0 Serial I/O Board. OCTAL A D D R E S S 000 001 002 003 004 005 006 007 010 011 012 013 014 015 016 017 020 021 022 023 OCTAL DATA 041 17S 037 (for 8K; for 4K use 017) 061 022 000 333 000 017 330 333 001 275 310 055 167 300 351 003 000 T h e following 21 b y t e bootstrap loader is for users loading from a p a p e r tape and using a REV 0 Serial I/O Board on which the u p d a t e changing the flag bits has not been m a d e . If the u p d a t e has been m a d e , use the above bootstrap loader. OCTAL A D D R E S S 000 001 002 003 004 005 006 007 010 011 012 013 014 015 016 017 020 OCTAL D A T A 041 175 037 (for 8K; for 4K u s e 017) 061 023 000 333 000 346 040 310 333 001 275 310 055 167 47 OCTAL ADDRESS OCTAL DATA (cont.)" 021 022 023 024 * ' j ^ 300 351 003 000 T h e following bootstrap loader is for users With BASIC supplied on an audio c a s s e t t e . OCTAL ADDRESS 006 001 002 003 004 005 006 007 010 011 012 013 014 015 016 017 020 021 022 023 To load a bootstrap OCTAL DATA 041 175 037 (for 8K; for 4K u s e 017) 061 022 000 333 006 017 330 333 007 275 310 055 167 300 351 003 000 loader: 1) Put switches 0 through 15 in the down p o s i t i o n . 2) Raise EXAMINE. 3) Put 041 (data for address 000) in switches 0 through 7 . 4) Raise D E P O S I T . 5) Put the data for the n e x t address in switches 0 through 7 . 6) Depress D E P O S I T N E X T . 7) R e p e a t steps 5 § 6 u n t i l the entire loader is toggled i n . 8) Put switches 0 through 15 in the down p o s i t i o n . 9) Raise EXAMINE. 10) Check that lights DO through D7 correspond with the data that should ^ ^ be in address 0 0 0 . A light on means the switch was u p , a light off means the switch was d o w n . So for address 0 0 0 , lights D1 through D4 and lights D6 § D7 should be o f f , and lights DO and DS should be o n . If the correct v a l u e is t h e r e , go to step 13. continue with step 11. If the value is w r o n g , 11) Put the correct v a l u e in switches 0 through 7. 12) Raise D E P O S I T . 13) Depress EXAMINE N E X T . 14) Repeat steps 10 through 1 3 , checking to see that the correct data is in each corresponding address for the entire loader. 15) If you encountered any mistakes while checking the l o a d e r , go back now and re-check the w h o l e program to be sure it is c o r r e c t e d . 16) Put the tape of BASIC into the tape r e a d e r . Be sure the tape is positioned at the beginning of the leader. The leader is the section of tape at the beginning with 6 out of the 8 holes p u n c h e d . If you are loading from audio c a s s e t t e , put the cassette in the rec o r d e r . Be sure the tape is fully r e w o u n d . 17) Put switches 0 through 15 in the down p o s i t i o n . 18) Raise EXAMINE. 19) If you have connected to your terminal a REV 0 Serial I/O Board on which the u p d a t e changing the flag bits has not been m a d e , raise switch 14; if you are loading from an audio c a s s e t t e , raise switch 15 a l s o . If you have a REV 0 Serial I/O Board which has been u p d a t e d , or h a v e a REV 1 I/O B o a r d , switch 14 should remain down and switch 15 should be raised only if you are loading from audio c a s s e t t e . 20) Turn on the tape r e a d e r and then depress R U N . Be sure RUN is depressed while the reader is still on the leader. Do not depress run before turning on the r e a d e r , since this m a y cause the tape to be read incorrectly. If you are loading from a c a s s e t t e , turn the cassette recorder to Play'. Wait 15 seconds and then depress R U N . 21) Wait for the tape to be read i n . This should take about 12 minutes for 8K BASIC and 6 m i n u t e s for 4K B A S I C . It takes about 4 m i n u t e s to load 8K BASIC from c a s s e t t e , and about 2 minutes for 4K B A S I C . Do not m o v e the switches while the tape is being read i n . 49 22J if a (J or an 0 is printed on the terminal as the tape reads in, the tape has been mis-read and you should start over at step 1 on page 46. 23) When the tape finishes r e a d i n g , BASIC should start up and print MEMORY S I Z E ? . See A p p e n d i x B for the initialization p r o c e d u r e . 24) If BASIC refuses to load from the Audio C a s s e t t e , the A C R Demodulator m a y need a l i g n m e n t . T h e flip side of the cassette contains 90 seconds of 125's (octal) which w e r e recorded at the same tape speed as B A S I C . U s e the Input T e s t Program described on pages 22 and 28 of the A C R m a n u a l to p e r f o r m the n e c e s s a r y a l i g n m e n t . U 50 APPENDIXASUPPLEMENT INITIALIZATION DIALOG STARTING BASIC Leave the sense switches as they were set for loading BASIC (Appendix A ) . After the initialization dialog is complete, and BASIC types O K , you are free to use the sense switches as an input device (I/O port 255). After you have loaded BASIC, it will respond: MEMORY SIZE? If you type a carriage return to MEMORY SIZE?, BASIC will use all the contiguous memory upwards from location zero that it can find. BASIC will stop searching when it finds one byte of ROM or non-existent memory. If you wish to allocate only part of the ALTAIR's memory to BASIC, type the number of bytes of memory you wish to allocate in decimal. This might be done, for instance, if you were using part of the memory for a machine language subroutine. There are 4096 bytes of memory in a 4K system, and 8192 bytes in an 8K system. BASIC will then ask: TERMINAL UIDTHf This is to set the output line width for PRINT statements o n l y . Type in the number of characters for the line width for the particular terminal or other output device you are u s i n g . This may be any number from 1 to 255, depending on the terminal. If no answer is given (i.e. a carriage return is typed) the line width is set to 72 characters. Now ALTAIR BASIC will enter a dialog which will allow you to delete some of the arithmetic functions. Deleting these functions will give more memory space to store your programs and variables. However, you will not be able to call the functions you delete. Attempting to do so will result in an FC error. The only way to restore a function that has been deleted is to reload BASIC. The following is the dialog which will occur: 4K Version UANT SIN? Answer " Y " to retain SIN, SQR and R N D . If you answer " N " , asks next question. MANT S(2R? Answer " Y " to retain SQR and R N D . If you answer " N " , asks next question. H UANT RND? Answer " Y " to retain R N D . Answer " N " to delete R N D . 8K Version DANT S I N - C O S - T A N - A T N ? A n s w e r " Y " to retain all four of the f u n c t i o n s , " N " t o delete all f o u r , or " A " to delete ATN o n l y . Now BASIC will type out: XXXX BYTES FREE ALTAIR BASIC VERSION 3 - D [FOUR-K VERSION] (or) [EIGHT-K VERSION] "XXXX" is the number of bytes available for p r o g r a m , v a r i a b l e s , matrix storage and the s t a c k . It does not include string s p a c e . You will now be r e a d y to begin using ALTAIR B A S I C . 52 APPENDIX M ERROR MESSAGES After an error occurs, BASIC returns to command level and types O K . Variable values and the program text remain intact, but the program can not be continued and all GOSUB and FOR context is lost. When an error occurs in a direct statement, no line number is p r i n t e d . Format of error messages: Direct Statement fXX ERROR Indirect Statement ?XX ERROR IN YYYYY In both of the above examples, "XX" will be the error code. The "YYYYY" will be the line number where the error occured for the indirect statement. The following are the possible error codes and their meanings: ERROR CODE MEANING BS Bad Subscript. An attempt was made to reference a matrix element which is outside the dimensions of the matrix. In the 8K version, this error can occur if the wrong number of dimensions are used in a matrix reference; for instance, LET A(1,1,1)=Z when A has been dimensioned DIM A(2,2). DD Double Dimension. After a matrix was dimensioned, another dimension statement for the same matrix was encountered. This error often occurs if a matrix has been given the default dimension 10 because a statement like A(I)=3 is encountered and then later in the program a DIM A(100) is found. FC Function Call error. The parameter passed to a math or string function was out of range. FC errors can occur due to: a) a negative matrix subscript (LET A(-1)=0) b) an unreasonably large matrix subscript (>32767) c) LOG-negative or zero argument d) SQR-negative argument 53 e) A+B with A negative and B not an integer f) a call to USH b e f o r e the a d d r e s s o!* the m a c h i n e language s u b r o u t i n e has been p a t c h e d in g) c a l l s to M I D $ , L E F T $ , R I G H T $ , I N P , O U T , W A I T , P E E K , P O K E , T A B , SPC or O N . . . G O T O w i t h an i m p r o p e r a r g u m e n t . ID I l l e g a l D i r e c t . Y o u c a n n o t u s e an INPUT or ft?! FX V e r s i o n J D E F F N s t a t e m e n t as a d i r e c t c o m m a n d . NF N E X T w i t h o u t F O R . T h e v a r i a b l e in a N E X T s t a t e m e n t c o r r e s p o n d s t o n o p r e v i o u s l y e x e c u t e d FOR s t a t e m e n t . OD O u t o f D a t a . A R E A D s t a t e m e n t was e x e c u t e d but all of t h e D A T A s t a t e m e n t s in t h e p r o g r a m h a v e a l r e a d y b e e n r e a d . T h e p r o g r a m t r i e d to read too m u c h d a t a or insuff i c i e n t d a t a w a s i n c l u d e d in the p r o g r a m . OH O u t o f M e m o r y . P r o g r a m too l a r g e , too m a n y v a r i a b l e s , too m a n y F O R l o o p s , too m a n y G O S U B ' s , too c o m p l i c a t e d an e x p r e s s i o n or a n y c o m b i n a t i o n o f the a b o v e , (see Appendix D) OV O v e r f l o w . T h e r e s u l t o f a c a l c u l a t i o n was too large to be r e p r e s e n t e d in B A S I C ' S n u m b e r f o r m a t . If an u n d e r f l o w o c c u r s , zero is g i v e n as t h e r e s u l t and e x e c u t i o n c o n t i n u e s without any error message being printed. SN S y n t a x e r r o r . M i s s i n g p a r e n t h e s i s in an e x p r e s s i o n , i l l e g a l c h a r a c t e r in a l i n e , i n c o r r e c t p u n c t u a t i o n , e t c . RG RETURN without GOSUB. A RETURN statement was encountered without a previous GOSUB statement being executed. US U n d e f i n e d S t a t e m e n t . A n a t t e m p t w a s m a d e to G O T O , G O S U B or T H E N to a s t a t e m e n t w h i c h d o e s n o t e x i s t . /U Division by Zero. FX CN (Jnc^M^es c/ the prey^cMS cccZes w foZ^CM^g*. J a & % t t o n to the C o n t i n u e e r r o r . A t t e m p t to c o n t i n u e a p r o g r a m w h e n n o n e e x i s t s , an e r r o r o c c u r e d , or a f t e r a n e w line was typed into the program. 54 Long S t r i n g . Attempt was m a d e by u s e of the concatenation operator to create a string more than 255 characters long. Out of String S p a c e . Save your program on paper tape or c a s s e t t e , reload BASIC and allocate m o r e string space or u s e smaller strings or less string v a r i a b l e s . String T e m p o r a r i e s . A string expression was too c o m p l e x . Break it into two or m o r e shorter o n e s . T y p e M i s m a t c h . T h e left hand side of an assignment statement was a numeric v a r i a b l e and the right hand side was a s t r i n g , or v i c e versa; o r , a function which expected a string argument was given a numeric one or vice versa. U n d e f i n e d F u n c t i o n . Reference was m a d e to a user defined function which had n e v e r been d e f i n e d . 55 APPENDIX M SPACE HINTS In order to make your program smaller and save space, the following hints may be useful. 1) Use multiple statements per line. There is a small amount of overhead (5bytes) associated with each line in the program. Two of these five bytes contain the line number of the line in binary. This means that no matter how many digits you have in your line number (minimum line number is 0 , maximum is 6SS29), it takes the same number of bytes. Putting as many statements as possible on a line will cut down on the number of bytes used by your program. 2) Delete all unnecessary spaces from your program. For instance: 10 PRINT X , Y , Z uses three more bytes than 10 PRINTX,Y,Z Note: All spaces between the line number and the first nonblank character are ignored. 3) Delete all REM statements. Each REM statement uses at least one byte plus the number of bytes in the comment text. For instance, the statement 130 REM THIS IS A COMMENT uses up 24 bytes of memory. In the statement 140 X=X+Y: REM UPDATE S U M , the REM uses 14 bytes of memory including the colon before the R E M . 4) Use variables instead of constants. Suppose you use the constant 3.14159 ten times in your program. If you insert a statement 10 P=3.14159 in the program, and use P instead of 3.14159 each time it is n e e d e d , you will save 40 bytes. This will also result in a speed improvement. 5) A program need not end with an END; s o , an END statement at the end of a program may be deleted. 6) Reuse the same variables. If you have a variable T which is used to hold a temporary result in one part of the program and you need a temporary variable later in your program, use it again. O r , if you are asking the terminal user to give a YES or NO answer to two different questions at two different times during the execution of the program, use the same temporary variable A$ to store the reply. 7) Use GOSUB's to execute sections of program statements that perform identical actions. 8) If you are using the 8K version to run your stead. This will give you as opposed to the 1.6K you 8K version of BASIC. the 8K version and don't need the features of program, consider using the 4K version inapproximately 4.7K to work with in an 8K m a c h i n e , have available in an 8K machine running the 56 9) U s e the zero elements of m a t r i c e s ; for i n s t a n c e , A ( 0 ) , B(0,X). STORAGE ALLOCATION INFORMATION Simple (non-matrix) numeric variables like V u s e 6 bytes; 2 for the v a r i a b l e n a m e , and 4 for the v a l u e . Simple non-matrix string variables also use 6 bytes; 2 for the v a r i a b l e n a m e , 2 for the l e n g t h , and 2 for a pointer. M a t r i x variables u s e a minimum of 12 b y t e s . Two bytes are used for the variable n a m e , two for the size of the m a t r i x , two for the number of dimensions and two for each dimension along with four bytes for each of the m a t r i x e l e m e n t s . \ String variables also u s e one byte of string space for each character in the s t r i n g . This is true whether the string v a r i a b l e is a simple string v a r i a b l e like A $ , or an element of a string m a t r i x such as Q l $ ( 5 , 2 ) . When a new function is defined by a DEF s t a t e m e n t , 6 bytes are used to store the d e f i n i t i o n . Reserved words such as F O R , GOTO or N O T , and the names or the intrinsic functions such as C O S , INT and STR$ take up only one byte of program s t o r a g e . All other characters in programs use one byte of program storage e a c h . When a program is being e x e c u t e d , space is dynamically allocated on the stack as follows: 1) Each active FOR...NEXT loop uses 16 b y t e s . 2) Each active GOSUB (one that has not returned yet) uses 6 b y t e s . 3) Each parenthesis encountered in an expression uses 4 bytes and each temporary result calculated in an expression uses 12 b y t e s . .57 APPENDIXASUPPLEMENT SPEED HINTS The hints below should improve the execution time of your BASIC program. Note that some of these hints are the same as those used to decrease the space used by your programs. This means that in many cases you can increase the efficiency of both the speed and size of your programs at the same time. 1) Delete all unnecessary spaces and REM's from the program. This may cause a small decrease in execution time because BASIC would otherwise have to ignore or skip over spaces and REM statements. 2) TRZS Z S PROBABLY TRE A/OFT IMPORTANT SPEED RLNT B Y A FACTOR OF Use variables instead of constants. It takes more time to convert a constant to its floating point representation than it does to fetch the value of a simple or matrix variable. This is especially important within FOR...NEXT loops or other code that is executed repeatedly. 3) Variables which are encountered first during the execution of a BASIC program are allocated at the start of the variable table. This means that a statement such as 5 A=0:B=A:C=A, will place A first, B second, and C third in the symbol table (assuming line 5 is thie first statement executed in the program). Later in the program, when BASIC finds a reference to the variable A , it will search only one entry in the symbol table to find A , two entries to find B and three entries to find C , etc. 4) f<% FerstonJ NEXT statements without the index variable. NEXT is somewhat faster than NEXT I because no check is made to see if the variable specified in the NEXT is the same as the variable in the most recent FOR statement. 5) Use the 8K version instead of the 4K version. The 8K version is about 40% faster than the 4K due to improvements in the floating point arithmetic routines. 6) The math functions in the 8K version are much faster than their counterparts simulated in the 4K version, (see Appendix G) APPENDIX M DERIVED FUNCTIONS The following functions, while not intrinsic to ALTAIR BASIC, can be calculated using the existing BASIC functions. FUNCTION FUNCTION EXPRESSED IN TERMS OF BASIC FUNCTIONS SECANT COSECANT COTANGENT INVERSE SINE INVERSE COSINE INVERSE SECANT INVERSE COSECANT INVERSE COTANGENT HYPERBOLIC SINE HYPERBOLIC 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) = l/COS(X) CSC(X) = 1/SIN(X) COT(X) = 1/TAN(X) ARCSIN(X) = ATN(X/SQR(-X*X+1)) ARCCOS(X) = -ATN(X/SQR(-X*X+1))+1.5708 ARCSEC(X) = ATN(SQR(X*X-1))+(SGN(X)-1)*1.5708 ARCCSC(X) = ATN(1/SQR(X*X-1))+(SGN(X)-1)"1.5708 ARCCOT(X) = -ATN(X)+1.5708 SINH(X) = (EXP(X)-EXP(-X))/2 COSH(X) = (EXP(X)+EXP(-X))/2 TANH(X) = -EXP(-X)/(EXP(X)+EXP(-X))*2+1 SECH(X) = 2/(EXP(X)+EXP(-X)) CSCH(X) = 2/(EXP(X)-EXP(-X)) COTH(X) = EXP(-X)/(EXP(X)-EXP(-X))*2+1 ARGSINH(X) = LOG(X+SQR(X*X+l)) ARGCOSH(X) = LOG(X+SQR(X*X-l)) ARGTANH(X) = LOG((l+X)/(l-X))/2 ARGSECH(X) = LOG((SQR(-X*X+l)+l)/X) ARGCSCH(X) = L0G((SGN(X)*SQR(X*X+1)+1)/X) ARGCOTH(X) = LOG((X+l)/(X-l))/2 59 APPENDIX M SIMULATED MATH FUNCTIONS The following subroutines are intended for 4K BASIC users who want to use the transcendental functions not built into 4K BASIC. The corresponding routines for these functions in the 8K version are much faster and more accurate. The REM statements in these subroutines are given for documentation purposes only, and should not be typed in because they take up a large amount of m e m o r y . The following are the subroutine calls and their 8K equivalents: 8K EQUIVALENT SUBROUTINE CALL P9=X9+Y9 L9=LOG(X9) E9=EXP(X9) C9=COS(X9) T9=TAN(X9) A9=ATN(X9) GOSUB GOSUB GOSUB GOSUB GOSUB GOSUB 60030 60090 60160 60240 60280 60310 The unneeded subroutines should not be typed in. Please note which variables are used by each subroutine. Also note that TAN and COS require that the SIN function be retained when BASIC is loaded and initialized. bOOOO L0010 bOOBO b0030 REM EXPONENTIATION: P^=X1TYT REM NEED: EXPn LOG REM VARIABLES USED: P1=l : E1=0 : IF Y^=0 THEN RETURN b0040 IF X1<0 THEN IF INT(Y1)=YT THEN P1=1-3*Y1+4*INT(Y1/B) : X1=-X1 b0050 bOObO b0070 bOOaO bOOlO bOOIS bOlOO bOHO bOlBO b0130 b0135 bOl^O b0150 bOlbO b0170 b0175 bOlBO bOllO bOlTS b01*=17 IF X^<>0 THEN GOSUB bOOlO : X1=Y1*LT : GOSUB bOlbO P ^ P ^ E I : RETURN REM NATURAL LOGARITHM: L1=L0G(X1) REM VARIABLES USED: A1nB1-,C1iE'l-,L'lnX'l E^=0 : IF X1<=0 THEN PRINT "LOG FC ERROR"^ : STOP A^=l : B^=B : : REM THIS DILL SPEED UP THE FOLLOWING IF X^>=A^ THEN : : GOTO bOlOO IF X*=! 0 THEN PRINT "EXP OV ERROR"^ : STOP E^=0 : RETURN E^=.b^3147*L^-X5 : A^=1.3BiaaE-3-1.4131bE-H*E1 A^=(-3013bE-3).lb57WE-B) E^= (((A*!-. Ibbbb5) . 5) *E1-1) *E^+1 : AT^B IF L^<=0 THEN A^=-5 : L ^ - L T : IF L1=0 THEN RETURN 60 bOEOO bOElO LOEEO L0E30 bOBHO b0350 bOBLO b0B70 bOBRO LOBIO b0300 L0310 L0330 ^0330 L0340 b0350 FOR X1=l TO LI : E1=A1*E1 : NEXT XT : RETURN REM COSINE: C1=COS(X1) REM N-B- SIN MUST BE RETAINED AT LOAD-TINE REM VARIABLES USED: CliXI C1=SIN(X1+1.5706) : RETURN REN TANGENT: T1=TAN(X1) REN NEEDS COS- (SIN NUST BE RETAINED AT LOAD-TINE) REN VARIABLES USED: CliTI.XI GOSUB L0340 : T1=SIN(X1)/C1 : RETURN REN ARCTANGENT: A1=ATN(X1) REN VARIABLES USED: A1iB1-,C1-.T1nX1 T1=SGN(X1): X1=ABS(X1): C1=0 : IF X1>1 THEN C1=l : X1=l/X1 A1=X1*X1 : B1=((B.6bb33E-3*A1-l.blb57E-B)*A1+4.B101bE-B)*A1 B1=((((B1-7.5BR1E-3)* A1+.10b5b3)* A1-.143031)*A1+.11113b)*A1 A1=((B1-.33333E)*A1+1)*X1 : IF C1=l THEN A1-1.S70B-A1 A1=T1*A1 : RETURN 2! APPENDIXASUPPLEMENT CONVERTING BASIC PROGRAMS NOT WRITTEN FOR THE ALTAIR Though implementations of BASIC on different computers are in many ways similar, there are some incompatibilites which you should watch for if you are planning to convert some BASIC programs that were not written for the ALTAIR. 1) Matrix subscripts. Some BASICs use " [ " and " ] " to denote matrix subscripts. ALTAIR BASIC uses " ( " and " ) " . 2) Strings. A number of BASICs force you to dimension (declare) the length of strings before you use them. You should remove all dimension statements of this type from the program. In some of these BASICs, a declaration of the form DIM A$(I,J) declares a string matrix of J elements each of which has a length I. Convert DIM statements of this type to equivalent ones in ALTAIR BASIC: DIM A $ ( J ) . ALTAIR BASIC uses " + " for string concatenation, not " , " or " § " . ALTAIR BASIC uses LEFT$, RIGHT$ and MID$ to take substrings of strings. Other BASICs use A$(I) to access the 1th character of the string A $ , and A$(I,J) to take a substring of A$ from character position I to character position J . Convert as follows: OLD NEW A$(I) MID$(A$,I,1) A$(I,J) MID$(A$,I,J-I+1) This assumes that the reference to a substring of A$ is in an expression or is on the right side of an assignment. If the reference to A$ is on the left hand side of an assignment, and X$ is the string expression used to replace characters in A $ , convert as follows: OLD NEW A$(I)=X$ A$=LEFT$(A$,1-1)+X$+MID$(A$,1+1) A$(I,J)=X$ A$=LEFT$(A$,1-1)+X$+MID$(A$,J+l) 3) Multiple assignments. Some BASICs allow statements of the form: 500 LET B=C=0. This statement would set the variables B § C to zero. In 8K ALTAIR BASIC this has an entirely different effect. All the " ='s " to the right of the first one would be interpreted as logical comparison operators. This would set the variable B to -1 if C equaled 0. If C did not equal 0 , B would be set to 0 . The easiest way to convert statements like this one is to rewrite them as follows: 62 500 C - 0 : B = C . 4) Some BASICs u s e " '\ " instead o f " : " to d e l i m i t m u l t i p l e s t a t e m e n t s p e r l i n e . C h a n g e t h e " \'s " to " :'s " in t h e p r o g r a m . 5) P a p e r t a p e s p u n c h e d b y o t h e r BASICs m a y h a v e n o n u l l s at t h e end of each l i n e , i n s t e a d o f t h e t h r e e p e r line r e c o m m e n d e d for u s e w i t h ALTAIR BASIC. T o get a r o u n d t h i s , t r y to u s e the t a p e feed c o n t r o l on t h e T e l e t y p e to s t o p t h e t a p e from r e a d i n g as soon as A L T A I R BASIC t y p e s a carr i a g e r e t u r n at t h e end o f t h e l i n e . W a i t a s e c o n d , and t h e n c o n t i n u e f e e d i n g in t h e t a p e . W h e n y o u h a v e f i n i s h e d r e a d i n g in the p a p e r tape o f t h e p r o g r a m , b e sure to p u n c h a n e w t a p e in A L T A I R B A S I C ' S f o r m a t . T h i s w i l l save y o u from h a v i n g to r e p e a t this p r o c e s s a s e c o n d t i m e . 6) P r o g r a m s w h i c h u s e t h e M A T f u n c t i o n s a v a i l a b l e in some BASICs w i l l h a v e to b e r e - w r i t t e n u s i n g F O R . . . N E X T loops to p e r f o r m the appropriate operations. 63 APPENDIXASUPPLEMENT USING THE ACR INTERFACE NOTE; T&e cassette features, CL&4P and C5/4VE, are onZz/ present in 5X BAFJCs M^ic?! are districted on cassette. BASIC on paper tape MiZZ gi^e t/ze z^ser abo^t more &z/tes of free memory, &nt it MiZZ not recognise t&e CL0/4D or commands. The CSAVE command saves a program on cassette tape. CSAVE takes one argument which can be any printing character. CSAVE can be given directly or in a program. Before giving the CSAVE command start your audio recorder on Record, noting the position of the tape. CSAVE writes data on channel 7 and expects the device status from channel 6. Patches can easily be made to change these channel numbers. When CSAVE is finished, execution will continue with the next statement. What is written onto the tape is BASIC'S internal representation of the program in memory. The amount of data written onto the tape will be equal to the size of the program in memory plus seven. Variable values are not saved on the tape, nor are they affected by the CSAVE command. The number of nulls being printed on your terminal at the start of each line has no affect on the CSAVE or CLOAD commands. CLOAD takes its one character argument just like the CSAVE command. For example, CLOAD E . The CLOAD command first executes a "NEW" command, erasing the current program and all variable values. The CLOAD command should be given before you put your cassette recorder on P l a y . BASIC will read a byte from channel 7 whenever the character ready flag comes up on channel 6. When BASIC finds the program on the tape, it will read all characters received from the tape into memory until it finds three consecutive zeros which mark the end of the program. Then BASIC will return to command level and type "OK". Statements given on the same line as a CLOAD command are ignored. The program on the cassette is not in a checksummed format, so the program must be checked to make sure it read in properly. If BASIC does not return to command level and type "OK", it means that BASIC either never found a file with the right filename character, or that BASIC found the file but the file never ended with three consecutive zeros. By carefully watching the front panel lights, you can tell if BASIC ever finds a file with the right n a m e . Stopping the ALTAIR and restarting it at location 0 will prevent BASIC from searching forever. However, it is likely that there will either be no program in the machine, or a partial program that has errors. Typing NEW will always clear out whatever program is in the machine. Reading and writing data from the cassette is done with the INP, OUT and WAIT statements. Any block of data written on the tape should have its beginning marked with a character. The main thing to be careful of is allowing your program to fall behind while data passes by unread. Data read from the cassette should be stored in a matrix, since 64 there isn't time to process data as it is being read i n . You will probably want to detect the end of data on the tape with a special c h a r a c t e r . 65 APPENDIX M BASIC/MACHINE LANGUAGE INTERFACE In all v e r s i o n s o f BASIC the u s e r c a n link to a m a c h i n e l a n g u a g e s u b r o u t i n e . T h e f i r s t s t e p is to set a s i d e e n o u g h m e m o r y for t h e subr o u t i n e . W h e n BASIC a s k s " M E M O R Y S I Z E ? " , y o u s h o u l d n ' t t y p e a r e t u r n , b e c a u s e BASIC w o u l d t h e n w r i t e into all o f m e m o r y t r y i n g to find out how m u c h m e m o r y y o u r m a c h i n e has and then u s e w h a t e v e r m e m o r y it f i n d s . T h e m e m o r y t h a t B A S I C a c t u a l l y u s e s is c o n s t a n t l y m o d i f i e d , so y o u c a n n o t s t o r e y o u r m a c h i n e l a n g u a g e r o u t i n e in t h o s e l o c a t i o n s . BASIC a l w a y s u s e s m e m o r y s t a r t i n g at l o c a t i o n 0 and as h i g h u p w a r d s as y o u let i t . BASIC c a n n o t u s e n o n - c o n t i g u o u s b l o c k s of m e m o r y . T h e r e f o r e , it is b e s t to r e s e r v e t h e top l o c a t i o n s o f m e m o r y for y o u r m a c h i n e language program. For e x a m p l e , if y o u h a v e a 4K m a c h i n e and w a n t to u s e a 200 b y t e subr o u t i n e , y o u s h o u l d set m e m o r y size to 3 8 9 6 . R e m e m b e r , BASIC a l w a y s acc e p t s n u m b e r s in d e c i m a l and t h a t 4K is r e a l l y 2 + 1 2 = 4 0 9 6 r a t h e r than 4 0 0 0 . N o w BASIC w i l l n o t u s e a n y l o c a t i o n >=* 3 8 9 6 . If y o u t r y to a l l o c a t e too m u c h m e m o r y for y o u r m a c h i n e l a n g u a g e prog r a m , y o u w i l l get an O M (out o f m e m o r y ) e r r o r . T h i s is b e c a u s e there is a c e r t a i n a m o u n t of m e m o r y t h a t BASIC m u s t h a v e or it w i l l g i v e an OM e r r o r and go b a c k to t h e " M E M O R Y S I Z E ? " q u e s t i o n . T h e s t a r t i n g l o c a t i o n o f y o u r r o u t i n e m u s t b e stored in a I d e a t i o n k n o w n as " U S R L O C " . T h e e x a c t o c t a l l o c a t i o n o f U S R L O C w i l l b e g i v e n w i t h each d i s t r i b u t e d v e r s i o n o f B A S I C . It is n o t t h e same for t h e 4K and 8K versions. U S R L O C for V e r s i o n 3.0: 8K (both p a p e r t a p e § c a s s e t t e ) = lll(octal) 4K=103(octal) I n i t i a l l y U S R L O C is set u p to c o n t a i n t h e a d d r e s s o f " I L L F U N " , w h i c h is t h e r o u t i n e that g i v e s an FC (function c a l l ) e r r o r . U S R L O C is t h e two b y t e a b s o l u t e a d d r e s s o f the l o c a t i o n BASIC c a l l s w h e n USR is i n v o k e d . U S R is a f u n c t i o n just like A B S or INT a n d is c a l l e d as f o l l o w s : 10 X = U S R ( 3 ) . W h e n y o u r r o u t i n e is c a l l e d t h e s t a c k p o i n t e r is set u p and y o u are a l l o w e d to u s e u p to 8 levels o f stack (16 b y t e s ) . If y o u w a n t to u s e m o r e , y o u h a v e to save B A S I C ' S s t a c k p o i n t e r (SP), set u p y o u r o w n , and r e s t o r e B A S I C ' S b e f o r e y o u r e t u r n b a c k to B A S I C . A l l o f t h e r e g i s t e r s (A, B , C , D , E , H , L and P S W ) can b e c h a n g e d . It is d a n g e r o u s to m o d i f y l o c a t i o n s in BASIC i t s e l f u n l e s s y o u know w h a t y o u a r e d o i n g . T h i s is u n l i k e l y u n l e s s y o u h a v e p u r c h a s e d a s o u r c e copy of B A S I C . P o p p i n g m o r e e n t r i e s off o f t h e s t a c k t h a n y o u p u t on is a l m o s t guaranteed to cause trouble. T o r e t r i e v e the a r g u m e n t p a s s e d to U S R , y o u m u s t call the r o u t i n e w h o s e a d d r e s s is g i v e n in l o c a t i o n 4 and 5 ( D E I N T ) . T h e low o r d e r 8 b i t s o f an a d d r e s s a r e a l w a y s s t o r e d in t h e lower a d d r e s s (4 in this c a s e ) , and the h i g h o r d e r 8 b i t s a r e s t o r e d in t h e n e x t (higher) m e m o r y a d d r e s s (5 in this c a s e ) . 66 T h e argument to U S R is truncated to an integer (calling USR with 3.8 is the same as calling it with 3 ) . If the argument is greater than 32767 or less than - 3 2 7 6 8 , an FC error will r e s u l t . When DEINT r e t u r n s , the two byte signed v a l u e of the argument will be in registers D § E . T h e high order byte would be in D , the low order byte in E . For instance: if the argument to USR was - 1 , D would equal 255 and E would equal 255; if the argument was 4 0 0 , D would equal 1 and E would equal 1 4 4 . T o pass back a v a l u e from U S R , set u p a two b y t e v a l u e in registers A § B and call the r o u t i n e w h o s e address is given in locations 6 and 7 . A § B should be set up in the same m a n n e r that D 5 E are when a v a l u e is passed to USR (A should contain the high order byte and B the low order byte). If the routine w h o s e address is given in locations 6 and 7 is not c a l l e d , the function USR in the user's program will b e an identity funct i o n . T h a t i s , USR(X) w i l l equal X . A t the end of the U S R routine a RET m u s t be done to get back to BASIC. T h e BASIC p r o g r a m is completely stopped while USR is being executed and the program w i l l not b e continued until USR r e t u r n s . In the 4K v e r s i o n , the USR routine should not enable interrupts from a d e v i c e . 4K BASIC uses the RST 7 location (56 d e c i m a l , 70 octal) to store a s u b r o u t i n e . If an interrupt o c c u r s , this subroutine will be called which will have an undetermined and undesirable effect on the way BASIC b e h a v e s . In the 8K B A S I C , locations 5 6 , 57 and 58 decimal have been set aside to store a JMP to a user-provided interrupt service r o u t i n e . Initially a RET instruction is stored at location 5 6 , so until a u s e r sets up the call to his interrupt service r o u t i n e , interrupts will have no e f f e c t . C a r e m u s t be taken in interrupt routines to save and restore the stack p o i n t e r , (A, B , C , D , E , H 5 L) and the P S W . Interrupt routines can pass data using P E E K , and can receive data using P O K E . The interrupt service routine should re-enable interrupts with an EI instruction b e f o r e it r e t u r n s , as interrupts are automatically disabled when the interrupt o c c u r s . If this procedure is not f o l l o w e d , the interrupt service routine will n e v e r "see" another i n t e r r u p t . Though there is only one way of calling a m a c h i n e language s u b r o u t i n e , this does not restrict the u s e r to a single s u b r o u t i n e . T h e argument passed to USR can be used to determine which routine gets c a l l e d . M u l t i p l e arguments to a m a c h i n e language routine can b e passed with POKE or through m u l t i p l e calls to USR b y the BASIC p r o g r a m . T h e m a c h i n e language routine can b e loaded from paper tape or cassette before or after BASIC is loaded. The checksum l o a d e r , an unchecksummed loader, the console s w i t c h e s , or m o r e conveniently the POKE function can be used to load the r o u t i n e . A common u s e of USR for 4K users will be doing IN's and OUT's to special d e v i c e s . For e x a m p l e , on a 4K m a c h i n e a user wants USR to pass back the v a l u e of the front panel switch register: A n s w e r to M E M O R Y SIZE? : 4050 USRLOC patched to contain 117,322]=7722 Base 8=4050 decimal 67 At location 4050=7722 B a s e i 8 put: 7722/333 7723/377 7724/107 7725/257 7726/052 7727/006 7730/000 7731/351 IN 255 MOV XRA LHLD B,A A 6 ;(255 Base 10=377 Base 8) Get ;the value of the switches in A ;B gets low part of answer ;A gets high part of answer ;get address of routine ;that floats [A,B] ;go to that routine which will ;return to BASIC ;with the answer PCHL MORE ON PEEK AND POKE KERFJON (WLYJ As mentioned b e f o r e , POKE can b e used to set up your m a c h i n e language routine in high m e m o r y . BASIC does not restrict which addresses you can P O K E . Modifying USRLOC can be accomplished using two successive calls to P O K E . Patches whibh a user wishes to include in his BASIC can also be m a d e using P O K E . Using the PEEK function and OUT statement of 8K B A S I C , the u s e r can w r i t e a binary dump p r o g r a m in B A S I C . Using INP and POKE it is possible to w r i t e a binary l o a d e r . PEEK and POKE can be used to store byte oriented i n f o r m a t i o n . When you initialize B A S I C , answer the MEMORY SIZE? question with the amount of m e m o r y in your A L T A I R m i n u s the amount of m e m o r y you wish to use as storage for byte formatted d a t a . You are now free to u s e the m e m o r y in the top of m e m o r y in your A L T A I R as byte s t o r a g e . See PEEK and POKE in the Reference Material for a further description of their p a r a m e t e r s . 68 APPENDIX M ASCII CHARACTER CODES DECIMAL CHAR. DECIMAL CHAR. DECIMAL CHA! 000 001 002 003 004 005 006 007 008 009 010 NUL SOH STX ETX EOT ENQ ACK BEL BS HT LF VT FF CR SO SI DLE DC1 DC 2 DC3 DC4 NAK SYN ETB CAN EM SUB ESCAPE FS GS RS US SPACE 043 044 045 046 047 048 049 050 051 052 053 054 055 056 057 058 059 060 061 062 063 064 065 066 067 068 069 070 071 072 073 074 075 076 077 078 079 080 081 082 083 084 085 + 086 087 088 089 090 091 092 093 094 095 096 097 098 099 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 V W X Y Z Oil 012 013 014 015 016 017 018 019 020 021 022 023 024 025 026 027 028 029 030 031 032 033 034 035 036 037 038 039 040 041 042 t " # $ % ( ) LF=Line Feed FF=Form Feed * - / 0 1 2 3 4 5 6 7 8 9 < = > ? e A B C D E F G H 1 J K L M N 0 P * Q R S T U CR=Carriage Return 69 [ \ ] + -t** a b c d e f g h i j k 1 m n o P q r s t u V w X y z { t } ^ DEL DEL=Rubout C H R $ is c o n t a i n s the t a b l e on the and c o n v e r t s a string f u n c t i o n w h i c h r e t u r n s a o n e c h a r a c t e r s t r i n g w h i c h A S C I I e q u i v a l e n t o f the a r g u m e n t , a c c o r d i n g to the c o n v e r s i o n p r e c e e d i n g p a g e . A S C t a k e s t h e first c h a r a c t e r of a string it to its A S C I I d e c i m a l v a l u e . O n e o f the m o s t c o m m o n u s e s o f C H R $ is to send a s p e c i a l c h a r a c t e r to the u s e r ' s t e r m i n a l . T h e m o s t o f t e n u s e d o f t h e s e c h a r a c t e r s is the BEL (ASCII 7 ) . P r i n t i n g t h i s c h a r a c t e r w i l l c a u s e a b e l l to ring on some t e r m i n a l s and a " b e e p " o n m a n y C R T ' s . T h i s m a y b e u s e d as a p r e f a c e to an e r r o r m e s s a g e , as a n o v e l t y , or j u s t to w a k e u p the u s e r if h e has fallen asleep. (Example: P R I N T C H R $ ( 7 ) ; ) A m a j o r u s e o f s p e c i a l c h a r a c t e r s is on t h o s e C R T ' s t h a t h a v e c u r s o r p o s i t i o n i n g and o t h e r s p e c i a l f u n c t i o n s (such as t u r n i n g o n a h a r d copy printer). As an e x a m p l e , t r y s e n d i n g a form feed (CHR$(12)) to y o u r C R T . On m o s t C R T ' s t h i s w i l l u s u a l l y c a u s e t h e s c r e e n t o e r a s e and t h e c u r s o r to " h o m e " or m o v e to t h e u p p e r left c o r n e r . S o m e C R T ' s g i v e t h e u s e r t h e c a p a b i l i t y o f d r a w i n g g r a p h s and c u r v e s in a s p e c i a l p o i n t - p l o t t e r m o d e . T h i s f e a t u r e m a y e a s i l y b e t a k e n a d v a n t a g e of t h r o u g h u s e of A L T A I R B A S I C ' S C H R $ f u n c t i o n . 70 APPENDIX L EXTENDED BASIC When EXTENDED BASIC is sent o u t , the BASIC manual will be updated to contain an extensive section about EXTENDED BASIC. A l s o , at this time the part of the manual relating to the 4K and 8K versions will be revised to correct any errors and explain more carefully the areas users are having trouble w i t h . This section is here mainly to explain what EXTENDED BASIC will contain. INTEGER VARIABLES These are stored as double byte signed quantities ranging from -32768 to +32767. They take up half as much space as normal variables and are about ten times as fast for arithmetic. They are denoted by using a percent sign (%) after the variable n a m e . The user doesn't have to worry about conversion and can mix integers with other variable types in expressions. The speed improvement caused by using integers for loop variables, matrix indices, and as arguments to functions such as A N D , OR or NOT will be substantial. An integer matrix of the same dimensions as a floating point matrix will require half as much memory. DOUBLE-PRECISION Double-Precision variables are almost the opposite of integer variables, requiring twice as much space (8bytes per value) and taking 2 to 3 times as long to do arithmetic as single-precision variables. Double-Precision variables are denoted by using a number sign (#) after the variable name. They provide over 16 digits of accuracy. Functions like SIN, ATN and EXP will convert their arguments to singleprecision, so the results of these functions will only be good to 6 digits. Negation, addition, subtraction, multiplication, division, comparision, input, output and conversion are the only routines that deal with DoublePrecision values. Once again, formulas may freely mix Double-Precision values with other numeric values and conversion of the other values to Double-Precision will be done automatically. PRINT USING Much like COBOL picture clauses or FORTRAN format statements, PRINT USING provides a BASIC user with complete control over his output format. The user can control how many digits of a number are printed, whether the number is printed in scientific notation and the placement of text in output. All of this can be done in the 8K version using string functions such as STR$ and M I D $ , but PRINT USING makes it much easier. DISK I/O EXTENDED BASIC will come in two versions, disk and nondisk. There will only be a copying charge to switch from one to the other. With disk features, EXTENDED BASIC will allow the user to save and recall programs and data files from the ALTAIR FLOPPY D I S K . Random access as well as sequential access will be provided. Simultaneous use of multiple data files will be allowed. Utilities will format new disks, delete files and print directories. These will be BASIC programs using special BASIC functions to get access to' disk information such as file length, etc. User programs can also access these disk functions, enabling the user to write his own file access method or other special purpose 7! disk routine. T h e file format can be changed to allow the use of other (non-floppy) d i s k s . This type of modification will be done by Ml'i'S under special a r r a n g e m e n t . OTHER FEATURES Other n i c e features which will be added are: Fancy Error M e s s a g e s An ELSE clause in IF statements L I S T , DELETE commands with line range as arguments Deleting M a t r i c e s in a program TRACE ON/OFF commands to m o n i t o r program flow EXCHANGE statement to switch variable values (this will speed up string sorts b y at least a factor of t w o ) . M u l t i - A r g u m e n t , u s e r defined functions with string arguments and v a l u e s allowed Other features contemplated for future release are: A m u l t i p l e user BASIC Explicit m a t r i x manipulation Virtual m a t r i c e s Statement m o d i f i e r s Record I/O Paramaterized GOSUB Compilation M u l t i p l e USR functions "Chaining" EXTENDED BASIC will u s e about 11K o f m e m o r y for its own code (10K for the non-disk v e r s i o n ) leaving IK free on a 12K m a c h i n e . It will take almost 20 minutes to load from paper t a p e , 7 minutes from c a s s e t t e , and less than 5 seconds to load from d i s k . We welcome any suggestions concerning current features or possible additions of extra f e a t u r e s . J u s t send them to the A L T A I R SOFTWARE DEPARTMENT. 72 APPENDIX M BASIC TEXTS Below are a few of the many texts that may be helpful in learning BASIC. 1) BASIC PROGRAMMING, John G . Kemeny, Thomas E Kurtz, 1967, pl45 2) BASIC, Albrecht, Finkel and Brown, 1973 3) A GUIDED TOUR OF COMPUTER PROGRAMMING IN BASIC, Thomas A Dwyer and Michael S . Kaufman; Boston: Houghton Mifflin C o . , 1973 Books numbered 1 $ 2 may be obtained from: People's Computer Company P . O . Box 310 Menlo Park, California 94025 They also have other books of interest, such as: 101 BASIC G A M E S , E d . David A h l , 1974 p250 WHAT TO DO AFTER YOU HIT RETURN or PCC's FIRST BOOK OF COMPUTER GAMES COMPUTER LIB § DREAM MACHINES, Theodore H . N e l s o n , 1974, pl86 73 u u u 75 ALTAIR EXTENDED BASIC PRELIMINARY DOCUMENTATION THE FOLLOWING PAGES CONTAIN A CONDENSED VERSION OF THE COMPLETE "ALTAIR EXTENDED BASIC" DOCUMENTATION. In order to get this software to our customers with a minimum of delay, it was decided to print this preliminary documentation. This will help to expedite the deliveries. The complete manual will be printed at a later date, and will be in much the same format as the previous existing BASIC documentation. READ THESE PAGES OVER CAREFULLY. SOME OF THE INFORMATION CONTAINED HERE ALSO APPLIES TO THE 4K AND 8K VERSIONS OF BASIC. This is meant to be an additional section to the "ALTAIR BASIC REFERENCE MANUAL", and not a separate manual in itself. December '75 ALTAIR EXTENDED BASIC ALTAIR EXTENDED BASIC Includes all of the features found In the 8K version of BASIC, with some variations. There are also a large number of additional features making this version one of the most powerful BASICs available. The following section contains the EXTENDED BASIC features and Its variations from the 8K BASIC. COMMANDS NAME EXAMPLE PURPOSE/USE DELETE DELETE X Deletes line In a program with the line number "X". "ILLEGAL FUNCTION CALL" error occurs 1f there Is no line "X". DELETE -X Deletes all lines In a program up to and Including line number "X". "ILLEGAL FUNCTION CALL" 1f no line "X". DELETE Y-X Deletes all lines In a program from the line number equal to or greater than "Y" up to and Including the first line equal to or less than "X". "ILLEGAL FUNCTION CALL" If no line "X". If deletion 1s performed, all variable values are lost. Also continuing 1s not allowed, and all "F0R"s and "G0SUB"s are made Inactive. (This 1s the same effect caused whenever a program 1s modified.) LIST LIST X Lists H n e "X" 1f there Is one. LIST or LIST- Lists the entire program. LIST X- Lists all lines in a program with a H n e number equal to or greater than "X". LIST -X Lists all of the lines 1n a program with a H n e number less than or equal to "X". LIST Y-X Lists all of the lines within a program with H n e numbers equal to or greater than "Y", and less than or equal to "X". 77 EXAMPLE PURPOSE/USE ERASE J% Eliminates an array. If no such array exists an "ILLEGAL FUNCTION CALL" error will occur. ERASE must refer to an array, not an array element [ERASE B(9) would be Illegal]. The space the array Is using 1s freed up and made available for other uses. The array can be dimensioned again, but the values before the ERASE are lost. ERASE XX, I# ERASE A$ ERASE D#,NMSX SMAP IX,JX SWAP B$(7),T$ SWAP D#(I),D#(I+1) Exchanges the value of two variables. (If X=1 & Y=5, after SMAP X,Y the values would be switched; that 1s, now X=5 & Y=l.) Both, one or neither of the variables may be array elements. If a non-array variable that has not been assigned a value Is referenced an "ILLEGAL FUNCTION CALL" error will occur. Both variables must be of the same type (both Integers, both strings, both double precision or both single precision), otherwise a "TYPE MISMATCH" error will occur. TRON Turns on the trace flag. TROFF Turns off the trace flag. TRON & TROFF can be given In either direct or Indirect (program) mode. When the trace flag Is on, each time a new program line Is started, that line number 1s printed enclosed 1n "[]". No spaces are printed. For example: TRON OK 10 PRINT 1: 20 STOP RUN PRINT "A" DO] 1 A [20] BREAK IN 20 "NEW" will also turn off the trace flag along with Its other functions. STATEMENTS IF-THEN-ELSE (Similar to 8K version IF-THEN statement, only with the addition of a new "ELSE" clause.) IF X>Y THEN PRINT "GREATER" ELSE PRINT "NOT GREATER" In the above example, first the relational condition would be tested. If it is true, the THEN clause would be executed ("GREATER" would be printed). If it is false, the ELSE clause would be executed ("NOT GREATER" would be printed). 10 IF A>B THEN PRINT "A>B" ELSE IF B>A THEN PRINT "B>A" ELSE PRINT "A=B" The above example would indicate which of the two variables was the largest, or if they were equal. As this example indicates, IF statements may be nested to any desired level (regulated only by the maximum line length). An IF-THEN-ELSE statement may appear anywhere within a multiple-statement H n e ; the THEN clause being always mandatory with each IF clause and the ELSE clause optional. Care must be taken to insure that IFs without ELSE clauses do not cause an ELSE to be associated with the wrong IF. 5 IF A=B THEN IF A=C THEN PRINT "A=C ELSE PRINT "A<>C" ELSE PRINT "A<>B" 79 In the above example, the double under-lined portion of the line is an IF-THEN-ELSE statement which is all a part of the THEN clause of the first IF statement in the line. The second ELSE (single under-lined) is part of the first IF, and will be executed only if the first relational expression is false (A<>B). If a line does not contain the same number of ELSE and THEN clauses, the last ELSE is matched with the closest THEN. TYPING Normally, numbers used In BASIC operations are stored and acted upon as single precision floating point numbers. This allows for 7 digits of accuracy. In the extended version of BASIC greater accuracy may be obtained by typing numbers as double precision. This allows for 16 digits of accuracy. In cases where speed is critical, it is, however, slower than single precision. The greatest advantage, in both speed and storage space can be obtained by using integer operations whenever possible. These fall within the rage <=32767 to >=-32768. Examples: (single precision) PRINT 1/3 .3333333 (double precision) PRINT 1/3D .3333333333333333 (integer) PRINT 1/3% 0 PRINT 2.76% 2 The use of these types of numbers will become clearer further on in the text. Examples: I%(10) uses (11 * 2) + 6 + (2 * 1) = 30 I (5,5) uses (6 * 6 * 4) + 6 + (2 * 2) = 154 TYPING There are four types of values used 1n EXTENDED BASIC programming: NAME SYMBOL # OF BYTES/VALUE STRINGS (0 to 255 characters) $ 3 INTEGERS (must be -32768 and =< 32767) % 2 DOUBLE PRECISION (exponent: -38 to +38) 16 digits # 8 SINGLE PRECISION (exponent: -38 to +38) 7 digits ! 4 The type a variable will be is explicitly declared by using one of the four symbols listed above. Otherwise, the first letter of the variable is used to look into the table that indicates the default type for that letter. Initially (after CLEAR, after RUN, after NEW, or after modifying a program) all letters are defaulted to SINGLE PRECISION. The following four statements can be used to modify the DEFAULT table: STATEMENT DEFAULTS VARIABLE TO DEFINT r DEFSTRr DEFDBL r DEFSNG r INTEGER STRING DOUBLE PRECISION SINGLE PRECISION r above indicates the position for the range to be given. This is to be of the following format: letter or letter 1 - letter 2. (In the second format, the "-" indicates from letter 1 through letter 2 inclusive.) In the above four statements the default type of all of the letters within the range is changed, depending on which DEF "type" is used. Initially, DEFSNG A-Z is assumed. Care should be taken when using these statements since variables referred to without type indicators may not be the same after the statement is executed. It is recommended that these statements be used only at the start of a program, before any other statements are executed. The following will illustrate some of the above information: 81 10 20 30 40 50 60 70 80 90 100 110 I%=1 n=2 I#=3 I$="ABC" PRINT 1 DEFINT 1 PRINT 1 DEFSTR 1 PRINT 1 DEFDBL 1 PRINT 1 The example on the left would print out: 2 at line # 50 1 at line # 70 ABC at line # 90 3 at H n e # 110 TYPING OF CONSTANTS The type that a particular constant will be is determined by the following: 1) if it is more than 7 digits or "D" is used in the exponent, then it will be DOUBLE PRECISION. 2) if it is >32767 or <-32768, a decimal point (.) is used, or an "E" is used, then it is SINGLE PRECISION. 3) otherwise, it is an integer. When a + or * operation or a comparison is performed, the operands are converted to both be of the same type as the most accurate operand. Therefore, if one or both operands are double precision, the operation is done in double precision (accurate but slow). If neither is double precision but one or more operands are single precision floating point, then the operation will be done in single precision floating point. Otherwise, both operands must be integers, and the operation is performed in integer representation. If the result of an integer + or * is too big to be an integer, the operation will be done in single precision and the result will be single precision. Division (/) is done the same as the above operator, except it is never done at the integer level. If both operands are integers, the operation is done as a single precision divide. The operators AND, OR, NOT, \ , and MOD force both operands to be integers before the operation is done. If one of the operands is >32767 or <-32768, an overflow error will occur. The result of these operators will always be an integer. (Except -32768\-l gives single precision.) No matter what the operands to + are, they will both be converted to single precision. The functions SIN, COS, ATN, TAN, SQR, LOG, EXP, and RND also convert their arguments to single precision and give the result as such, accurate to 6 digits. Using a subscript >32767 and assigning an integer variable a value too large to be an integer gives an overflow error. 82 TYPE CONVERSION When a number Is converted to an integer, it is truncated (rounded down). For example: I%=.999 PRINT 1% 0 A%=-.01 PRINT A% -1 It will perform as if the INT function was applied. When a double precision number is converted to single precision, it is rounded off. For example: D#=77777777 I!=D# PRINT I! 7.77778E+07 No automatic conversion is done between strings and numbers. NUM, ASC, and CHR$ functions for this purpose. See the STR$, NEW FUNCTIONS CINT Convert the argument to an integer number CSNG Convert the argument to a single precision number CDBL Convert the argument to a double precision number Examples: CDBL(3)=3D CINT(3.9)=3 CINT(-.01)=-1 CSNG(312456.8)=312457 NOTE: if X<=32767 and =>-32768 then CINT(X)=INT(X) otherwise, CINT will give an overflow error NEW OPERATORS \(backslash=shift L) Integer Division Examples: 1\3=0 7\2=3 -3\-l=3 300\7=42 -8\3=-2 -1\3=0 The integer division operator forces both arguments to integers and gives the integer value of the division operation. (The only exception to this is -37268\-l, which results in a value too l*arge to be an integer.) NOTE: A\B does not equal INT(A/B) (if A=-l & B=7, 0 does not equal -1) Integer division is about eight times as fast as single precision division. Its precedence is just below that of *&/. NEW OPERATORS (cont.J MOD Examples: The MOD operator forces both arguments to integers and returns a result according to the following formula: 4 MOD 7=4 13 MOD 3=1 7 MOD -11=7 -6 MOD -4=-2 A MOD B = A - [B * (A\B)] If B=0 then a division by zero error will occur. MODs precedence is just below that of integer division and just above + and -. USER-DEFINED-FUNCTIONS In the Extended version of BASIC, a user-defined function can be of any type and can take any number of arguments of any type. Examples: DEF FNRAND0M%=10*RND(1)+1 DEF FNTW0$(X$)=X$+X$ DEF FNA(X,Y,Z,I%)=X+Z+I%*Y The result of the function will be forced to the function type before the value is substituted into the formula with the function call. FOR LOOPS (Integer) The loop variable in a FOR loop can be an integer as well as a single precision number. Attempting to use a string or double precision variable as the loop variable will cause a Type Mismatch error to occur. Integer FOR loops are about three times as fast as single precision FOR loops. If the addition of the increment to the loop variable gives a result that is too big to be an integer, an overflow error will occur. The initial loop value, increment value and the final value must all be in the legal range for integers or an overflow error will occur when the FOR is executed. Example: 1 FOR I%=20000 TO 30000 STEP 20000 2 PRINT 1% 3 NEXT 1% RUN 20000 OVERFLOW IN 3 OK 84 These messages replace the old error messages listed In APPENDIX C (p. 53) the BASIC manual. NEXT WITHOUT FOR SYNTAX ERROR RETURN WITHOUT GOSUB OUT OF DATA ILLEGAL FUNCTION CALL OVERFLOW OUT OF MEMORY UNDEFINED STATEMENT SUBSCRIPT OUT OF RANGE REDIMENSIONED ARRAY DIVISION BY ZERO ILLEGAL DIRECT TYPE MISMATCH OUT OF STRING SPACE STRING TOO LONG STRING FORMULA TOO COMPLEX CAN'T CONTINUE UNDEFINED USER FUNCTION Examples: 10 GOTO 50 RUN UNDEFINED STATEMENT IN 50 OK PRINT 1/0 DIVISION BY ZERO OK ADDITIONAL NOTES ON EXTENDED BASIC PEEK & POKE Examples: INT In the 8K version of BASIC you can't PEEK at or POKE Into memory locations above 32767. In the Extended version this can be done by using a negative argument. If the address to be PEEKed or POKEd is greater than 32767, subtract 65536 from it to give the proper argument. to PEEK at 65535 PEEK(-l) to POKE at 32768 POKE -32768,1% The INT function will work on numbers both single & double precision which are too large to be integers. Double precision numbers maintain full accuracy, (see CINT) Examples: 1NT(1E38)=1E38 INT(123456789.6)=123456789 85 ADDITIONAL NOTES (cont.) (miscellaneous) Extended BASIC uses 10.2K of memory to reside. String space is defaulted to 100 in the Extended version. A comma before the THEN in an IF statement is allowed. USR pass routine [4,5] passes in [H,L] not [D,E], and the pass back routine [6,7] receives in [H,LJ not [A,B]. Files CSAVEd in 8K BASIC cannot be CLOADed in EXTENDED BASIC, nor the opposite. UPDATE TO EXISTING MATERIAL In cassette BASICs (both 8K* and Extended), CLOAD? some character file name, reads the specified file and checks it against the file in core. If the files do not match, the message "NO GOOD" is printed. If they do match, BASIC returns to command level and prints "OK". In the Extended version of BASIC, active FOR loops (integer or single precision) require 17 bytes. Each non-array ["string Ivariable uses [*6"1 bytes. integer 5 double precision 11 single precision This is because, it takes 3 bytes to store the name of a variable. Each array uses: (# of elements)* "INT=2 DBL=8 STR=3 SNG=4 +6+2*(# of dimensions). Examples: I%(_10) uses (ll*2)+6+(2*l)=30 bytes 1(5,5) uses (6*6*4)+6+(2*2)=154 bytes Stored programs take exactly the same amount of space as in the 8K version of BASIC, except the reserved word ELSE takes 2 bytes instead of 1 byte as with the other reserved words. 86 UPDATE TO EXISTING MATERIAL (Applies to 8K versions 3.2 and later.) In both Extended & 8K* BASIC, if a number is between >=lE-2 and <1E-1, the number will be printed as: .OXXXXXX (trailing zeros suppressed) instead of X.XXXXXXE-2 An 8K BASIC program should run exactly the same under Extended BASIC. No conversion should be necessary. USRLOC in extended is: 101 octal=65 decimal, still 111 in 8K and 4K to load. EXTENDed: (Non-disk) location 002 in the BOOT should be 57 (8K=37, 4K=17) UPDATE TO EXISTING MATERIAL (Applies to page 57 of version 3.2 and later.) Each active GOSUB takes 5 bytes. Each active FOR loop takes 16 bytes. !7 EDIT COMMAND The EDIT command Is for the purpose of allowing modifications and additions to be made to existing program lines without having to retype the entire line each time. Commands typed in the EDIT mode are, as a rule, not echoed. Most commands may be preceded by an optional numeric repetition factor which may be used to repeat the command a number of times. This repetition factor should be in the range 0 to 255 (0 is equivalent to 1). If the hepetition factor is omitted, it is assumed to be 1. In the following examples a lower case "n" before the command stands for the repetition factor. In the following description of the EDIT commands, the "cursor" refers to a pointer which is positioned at a character in the H n e being edited. To EDIT a H n e , type EDIT followed by the number of the H n e and hit the carriage return. The H n e number of the H n e being EDITed will be printed, followed by a space. The cursor will now be positioned to the left of the first character in the H n e . NOTE: The best way of getting the "feel" of the EDIT command is to try EDITing a few lines yourself. Commands not recognized as part of the EDIT commands will be ignored. MOVING THE CURSOR A space typed in will move the cursor to the right and cause the character passed over to be printed out. A number preceding the space (nS) will cause the cursor to pass over and print out the number (n) df characters chosen. INSERTING CHARACTERS I Inserts new characters into the H n e being edited. After the I is typed, each character typed in will be inserted at the current cursor position and typed on the terminal. To stop inserting characters, type "escape" (or Alt-<-mode on some terminals). If an attempt is made to insert a character that will make the H n e longer than the maximum allowed (72 characters), a bell will be typed (control G) on the terminal and the character will not be inserted. WARNING: It is possible using EDIT to create a H n e which, when listed with its H n e number, is longer than 72 characters. Punched paper tapes containing such lines will not be read in properly. However, such lines may be CSAVEd and CLOADed without error. A backarrow (or underline) typed during an insert command will delete the character to the left of the cursor. Characters up to the beginning of the line may be deleted in this manner, and a backarrow will be echoed for each character deleted. However, if no characters exist to the left of the cursor, a bell 1s echoed instead of a backarrow. If a carriage return is typed during an insert command, it will be as if an escape and then carriage return was typed. That is, all characters to the right of the cursor will be printed and the EDITed line will replace the original line. X is the same as I, except that all characters to the right of the cursor are printed, and the cursor moves to the end of the line. At this point it will automatically enter the insert mode (see I command). X is very useful when you wish to add a new statement to the end of an existing line. For example: Typed by User Typed by ALTAIR Typed by User EDIT 50 (carriage return) 50 X=X+1:Y=Y+1 X :Y=Y+1 (carriage return) In the above example, the original line #50 was: 50 X=X+1 The new EDITed line #50 will now read: 50 X=X+1:Y=Y+1 H is the same as I, except that all characters to the right of the cursor are deleted (they will not be typed). The insert mode (see I command) will then automatically be entered. H is most useful when you wish to replace the last statements on a line with new ones. DELETING CHARACTERS nD deletes n number of characters to the right of the cursor. If less than n characters exist to the right of the cursor, only that many characters will be deleted. The cursor is positive to the right of the last character deleted. The characters deleted are enclosed in backslashes (\). For example: Typed Typed Typed Typed by by by by User User ALTAIR User 20 X=X+1:REM JUST INCREMENT X EDIT 20 (carriage return) 20 \X=X+1:\REM JUST INCREMENT X 6D (carriage return) The new line #20 will no longer contain the characters which are enclosed by the backslashes. SEARCHING S The nSy command searches for the n^ occurance of the character y in the H n e . The search begins at the character one to the right of the cursor. All characters passed over during the search are printed. If the character is not found, the cursor will be at the end of the H n e . If it is found, the cursor will stop at that point and all of the characters to its left will have been printed. For example: Typed Typed Typed Typed by by by by User User ALTAIR User 50 REM INCREMENT X EDIT 50 50 REM INCR 2SE nt^y is equivalent to S, except that all of the characters passed over during the search are deleted. The deleted characters are enclosed in backslashes. For example: Typed Typed Typed Typed by by by by User User ALTAIR User 10 TEST LINE EDIT 10 10 \TEST\ KL TEXT REPLACEMENT C A character in a H n e may be changed by the use of the C command. Cy, where y is some character, will change the character to the right of the cursor to y . The y will be typed on the terminal and the cursor will be advanced one position. nCy may be used to change n number of characters in a H n e as they are typed in from the terminal. (See example below.) If an attempt is made to change a character which does net exist, the change mode will be exited. Example: Typed Typed Typed Typed by by by by User User ALTAIR User 10 FOR 1=1 TO 100 EDIT 10 10 FOR 1=1 TO 256 2S1 3C256 ENDING AND RESTARTING Carriage Return Tells the computer to finish editing and print the remainder of the H n e . The edited H n e replaces the original Hne. E E is the same as a carriage return, except the remainder of the H n e is not printed. 90 Q Quit. Changes to a line do not take effect until an E or carriage return is typed. Q allows the user to restore the original line without any changes which may have been made, if an E or carriage return has not yet been typed. "OK" will be typed and BASIC will await further commands. L Causes the remainder of the line to be printed, and then prints the line number and restarts EDITing at the beginning of the line. The cursor will be positioned to the left of the first character in the line. L is most useful when you wish to see how the changes in a line look so that you can decide if further EDITs are necessary. Example: Typed Typed Typed Typed by by by by User ALTAIR User ALTAIR EDIT 50 50 REM INCREMENT X 2SM L 50 Causes the original copy of the line to be restored, and EDITing to be restarted at the beginning of the line. For example: Typed Typed Typed Typed Typed by by by by by User User ALTAIR User ALTAIR 10 TEST LINE EDIT 10 10 \TEST LINE\ 10D A 10 In the above example, the user made a mistake when he deleted TEST LINE. Suppose that he wants to type "ID" instead of "10D" By using A command, the original line 10 is reentered and is ready for further EDITing. IMPORTANT Whenever a SYNTAX ERROR is discovered during the execution of a source program, BASIC will automatically begin EDITing the line that caused the error as if an EDIT command had been typed. For Example: 10 APPLE RUN SYNTAX ERROR IN 10 10 Complete editing of a line causes the line edited to be re-inserted. Re-inserting a line causes all variable values to be deleted, therefore you may want to exit the EDIT command without correcting the line so that you can examine the variable values. This can be easily accomplished by typing the Q command while in the EDIT mode. If this is done, BASIC will type OK and all variable values will be preserved. 91 PRINT USING The PRINT USING statement can be employed in situations where a specific output format is desired. This situation might be encountered in such applications as printing payroll checks or an accounting report. Other uses for this statement will become more apparent as you go through the text. The general format for the PRINT USING statement is as follows: (line number) PRINT USING ; The "string" may be either a string variable, string expression or a string constant which is a precise copy of the line to be printed. All of the characters in the string will be printed just as they appear, with the exception of the formatting characters. The "value list" is a list of the items to be printed. The string will be repeatedly scanned until: 1) the string ends and there are no values in the value list 2) a field is scanned in the string, but the value list is exhausted. The string should be constructed according to the following rules: STRING FIELDS ! Specifies a single character string field. is specified in the value list.) (The string itself \n spaces\ Specifies a string field consisting of 2+n characters. Backslashes with no spaces between them would indicate a field of 2 characters width, one space between them would indicate a field 3 characters in width, etc. In both cases above, if the string has more characters than the field width, the extra characters will be ignored. If the string has less characters than the field width, extra spaces will be printed to fill out the entire field. Trying to print a number in a string field will cause a TYPE MISMATCH error to occur. Example: 10 A$="ABCDE":B$="FGH" 20 PRINT USING "!";A$,B$ 30 PRINT USING "\ \";B$,A$ (the above would print out) AF FGHABCD Note that where the "!" was used only the first letter of each string was printed. Where the backslashes were enclosed by two spaces, four letters from each string were printed (an extra space was printed for B$ which has only three characters). The extra characters in the first case and for A$ in the second case were ignored. 92 NUMERIC FIELDS With the PRINT USING statement, numeric prin-outs may be altered to suit almost any applications which may be found necessary. This should be done according to the following rules: # Numeric fields are specified by the # sign, each of which will represent a digit position. These digit positions are always filled. The numeric field will be right justified; that is, if the number printed is too small to fill all of the digit positions specified, leading spaces will be printed as necessary to fill the entire field. The decimal point position may be specified in any particular arrangement as desired; rounding is performed as necessary. If the field format specifies a digit is to precede the decimal point, that digit will always be printed (as 0 if necessary). The following program will help illustrate these rules: 10 INPUT A$,A 20 PRINT USING A$;A 30 GOTO 10 RUN ? ##,12 IE ? ###,12 IB ? #####,12 IB ?##.##,12 IB. 00 ? ###.,12 IB. ? #.###,.02 O-OEO ? ##.#,2.36 E-4 t This sign may be used at either the beginning or end of the numeric field, and will force the + sign to be printed at either end of the field as specified, if the number is positive. If it is used at the end of the field, and the number is negative, a -sign will be forced at the end of the number. The - sign when used at the end of the numeric field designation will force the sign to be printed trailing the number, If it is negative. If the number 1s positive, a space is printed. NOTE: There are cases where forcing the sign of a number to be printed on the trailing side will free an extra space for leading digits. (See exponential format.) 93 ** The ** placed at the beginning of a numeric field designation will cause any unused spaces in the leading portion of the number printed out to be filled with asterisks. The ** also specifies positions for 2 more digits. (Termed "asterisk fill") $$ When the $$ is used at the beginning of a numeric field designation, a $ sign will be printed in the space immediately preceding the number printed. Note that the $$ also specifies positions for two more digits, but the $ itself takes up one of these spaces. Exponential format cannot be used leading $ signs, nor can negative numbers be output unless the sign is forced to be trailing. **$ The **$ used at the beginning of a numeric field designation causes both of the above (** & $$) to be performed on the number being printed out. All of the previous conditions apply, except that **$ allows for 3 additional digit positions, one of which is the $ sign. , A comma appearing to the left of the decimal point in a numeric field designation will cause a comma to be printed every three digits to the left of the decimal point in the number being printed out. The comma also specifies another digit position. A comma to the right of the decimal point in a numeric field designation is considered a part of the string itself and will be treated as a printing character. tTTT Exponential Format. If the exponential format of a number is desired in the print out, the numeric field designation should be followed by tTTT (allows space for E±XX). As with the other formats, any decimal point arrangement is allowed. In this case, the significant digits are left justified and the exponent is adjusted. % If the number to be printed out is larger than the specified numeric field, a % character will be printed and then the number itself in its standard format. (The user will see the entire number.) If rounding a number causes it to exceed the specified field, the % character will be printed followed by the rounded number. (Such as field= .##, and the number is .999 will print % 1.00.) If the number of digits specified exceeds 24, a FUNCTION CALL error will occur. Try going through the following examples to help illustrate the preceding rules. A single program such as follows is the easiest method for learning PRINT USING. Examples: Program: Type the short program into your machine as it is listed below. This program will keep looping and allow you to experiment with PRINT USING as you go along. 10 INPUT A$,A 20 PRINT USING A$;A 30 GOTO 10 RUN The computer will start by typing a ?. Fill in the numeric field designator and value list as desired, or follow along below. ?+#,9 +T ?+#,io X+10 ?##,-2 -B ?+#,-2 -3 ?#,-2 X-3 ?+.###,.02 + .030 ? ####.#,100 100.0 ?##+,2 3+ ? THIS IS A NUMBER ##,2 THIS IS A NUMBER 3 ? BEFORE ## AFTER,12 BEFORE 13 AFTER ? ####,44444 xnnmm ?**##,i ? **##,12 **1B ? **##,123 *1B3 ? **##,1234 1334 ? **##,12345 X13345 ?**,1 *1 ?**,22 33 ? **.##,12 13-00 ? **####,l ****m 95 (note: not floating $) (note: floating $) ? $####.##,12.34 3 IE.34 ? $$####.##,12.56 eiB.sb ? $$.##,1.23 31. E3 ? $$.##,12.34 X31E-34 ? $$###,0.23 30 ? $$####.##,0 30-00 ? **$###.##,1.23 ****31.E3 ? **$.##,1.23 *31.E3 ?**$###,l ****$! ?#,6.9 7 ?#.#,6.99 7.0 ?##-,2 B ? ##-,-2 E?##+,2 E+ ? ##+,-2 E? ##tttt,2 BE+00 ? ##tttt,12 1E+01 ? #####.###TTtT,2.45678 B45b.?a0E-03 ? #.###tttt,123 0.1E3E+03 ? #.##tttt,-123 --1EE+03 ? #####,###.#,1234567.89 lnE34nS!3?.T 96 APPENDIX A SUPPLEMENT HOW TO LOAD BASIC For BASIC versions 3.2 and later, the load procedure has been updated to allow the use of the new I/O boards (2SI0 & 4PI0), the old 88-PIO board, and more general channel assignments. Location 001 of the bootstrap loaders listed in APPENDIX A must be changed from 175 to 256 to load BASIC versions 3.2 and later. For the older versions of BASIC, the location should be left at 175. For EXTENDED BASIC, location 002 (set at 017 for 4K & 037 for 8K) should be set at 057. The checksum loader has a new error message "M" which indicates that the data that was loaded into memory did not read back properly (see step 22 on page 50 of APPENDIX A). Loading into non-existent, protected or malfunctioning memory can cause this to occur. The new error message will also be sent repeatedly, instead of only once. The message is sent on channels 1, 21 and 23; so, if no terminal device is on one of these three channels, the panel lights must be examined to see if a checksum error has occured. Error Detection The new checksum loader (BASIC versions 3.2 & later) will display X7647 on the address lights when running properly. (X above will be 0 for 4K BASIC, 1 for 8K or 2 for EXTENDED.) When an error occurs (checksum "C"-bad tape data, memory "M"-data won't store properly, overlay "0"-attempt to load over top of the checksum loader) the address lights will then display X7637. The ASCII error code will be stored in the accumulator (A). More simply, A5 should be on with A4 & A3 off during proper loading. When an error occurs, A5 will turn off and A4 & A3 will turn on. Load Options LOAD DEVICE SIOA,B,C (not REV 0) ACR SWITCHES UP none Al5(and terminal opts) OCTAL CHANNELS STATUS BITS ACTIVE OCTAL MASKS 0,1 low 1/200 6,7 low 1/200 SIOA,B,C (REV 0) A14 0,1 high 40/2 88-PIO A13 0,1 high 2/1 4PIO A12 20,21 high 100/100 All(andA10 20,21 up=lstop bit down=2 stop bits) ay high 1/2 2SIO There are six different bootstrap loaders, one for each of the six types of I/O boards listed in the Load Option chart. Be sure that you use the correct one for your particular board. If the load device is an ACR, the Terminal Options (see second chart) can be set in the switches (along with A15) before the loading is done. If A15 is set, the checksum loader will ignore all of the other switches and BASIC will ignore A15. If the load device and the terminal device are not the same, and the load device is not an ACR, then only the load options should be set before the loading. When the load completes, BASIC will start-up and try to send a message to the load device. STOP BASIC, EXAMINE LOCATION 0, SET THE TERMINAL OPTION SWITCHES, AND THEN DEPRESS RUN. If the initialization dialog hasn't completed, everytime BASIC is restarted at zero, it will examine the sense switches and reconfigure the terminal input/output options. Once the initialization dialog is complete, the sense switches are no longer examined and the I/O configuration is fixed until BASIC is reloaded. Terminal Options TERMINAL DEVICE SWITCHES UP OCTAL CHANNEL DEFAULT SIOA,B,C (not REV 0) none 0,1 SIOA,B,C(REVO) A14 0,1 88-PIO A13 0,1 4PIO A12 20,21 (INPUT) 22,23 (OUTPUT) 2SIO All 20,21 (A10 up=l stop bit down=2 stop bits) The default channels listed above may be changed as desired by raising A8 and storing the lowest channel number (Input flag channel) in one of the following locations: 7777 (octal) for 4K BASIC 17777 (octal) for 8K BASIC 27777 (octal) for EXTENDED BASIC (non-disk version) NOTE: The "Input flag channel" may also be refered to as the "control channel" in other ALTAIR documentation. The above information is useful only when the load device and terminal device are not the same. During the load procedure A8 will be ignored; therefore, the board from which BASIC is loaded must be strapped for the channels listed in the Load Option chart. The following page contains three new bootstrap loaders for the 88-PIO, 4PIO and 2SIO boards. The conditions for using the other loaders listed in APPENDIX A are given at the beginning of this supplement. 98 88-PIO (for versions 3.2 & later only) OCTAL ADDRESS 000 001 002 003 004 005 Q06 007 010 011 012 013 014 015 016 017 020 021 022 023 024 OCTAL CODE 041 256 017 (for 4K, 037 for 8K, 057 for EXTENDED) 061 023 000 333 000 346 NOTE: Switch A13 should be up; 040 88-PIO should be strapped 310 for channels 0,1. 333 001 275 310 055 167 300 351 003 000 2SIO (for versions 3.2 & later only) OCTAL ADDRESS 000 001 002 003 004 005 006 007 010 011 012 013 014 015 016 017 020 021 022 023 024 025 026 027 OCTAL CODE OCTAL ADDRESS OCTAL CODE 076 030 300 003 031 351 323 032 013 020 033 000 076 021 (=2 stop bits 323 025=1 stop bit) 020 041 256 017 (for 4K, 037 for 8K, 057 for EXTENDED) 061 032 000 NOTE: Switch All should be up; 333 If the 2SIO also is the 020 terminal device, set A10 017 up for 1 stop bit or down 320 for 2 stop bits. The 2SIO 333 should be strapped for 021 channels 20,21. 275 310 055 167 4PI0 (for versions 3.2 & later only) OCTAL ADDRESS OCTAL CODE 000 001 002 003 004 005 006 007 010 257 323 020 000 323 021 076 004 323 011 020 012 013 014 015 016 017 020 021 022 023 024 025 026 027 030 031 032 033 034 035 036 041 256 017 (for 4K, 037 for 8K, 057 for EXTENDED) 061 035 000 333 NOTE: Switch A12 should be up. 020 346 100 310 333 021 275 310 055 167 300 351 015 000 The following three programs are echo programs for the 88-PIO, the 4PIO and the 2SI0 boards. If you wish to test a device that does Input only, dump the echoed characters on a faster device or store them in memory for examination. For an Output only device, send the data in the sense switches or some constant for the test character. Make sure to check the ready-to-receive bit before doing output. If the echo program works, but BASIC doesn't; make sure the load device's UART is strapped for 8 data bits and that the ready-to-receive flag gets set properly on the terminal device. 100 ECHO PROGRAMS: 88-PIO OCTAL ADDRESS OCTAL CODE OCTAL ADDRESS OCTAL CODE 000 001 002 003 OM 005 006 333 000 346 040 312 000 000 007 010 Oil 012 013 014 015 333 001 323 001 303 000 000 OCTAL ADDRESS OCTAL CODE OCTAL ADDRESS OCTAL CODE 2SIO 000 001 002 003 004 005 006 007 010 011 012 076 003 323 020 (flag ch.) 076 0 2 1 ( l s t . bt., 323 025 for 2) 020 333 020 017 013 014 015 016 017 020 021 022 023 024 322 010 000 333 021 (data ch.) 323 021 303 010 000 4PIO OCTAL ADDRESS 000 001 002 003 004 005 006 007 010 Oil 012 013 014 015 016 017 020 021 022 023 OCTAL CODE 257 323 020 323 021 323 022 057 323 023 076 OM 323 020 323 022 333 020 346 100 OCTAL ADDRESS 024 025 026 027 030 031 032 033 034 035 036 037 040 041 042 043 044 101 OCTAL CODE 312 020 000 333 022 346 100 312 027 000 333 021 323 023 303 020 000 u 24SO Alamo SB Albuquerque, NM 87106 ! 88-4MCS PARTS LIST .APRIL, 1976 BAG 6 2 1 3 2 2 1 741300 74LS04 74LS13 74LS14 74367 7805 101069 101042 101124 101123 101040 101074 2102A-4 101107 BAG 3 42 .IMF 12-16V 6-32 x 3/8" Screw #6-32 #6-32 Nut Nut #6 #6 Lock Lock Washer Washer Heat Sink Sink (Large) (Large) Heat Ferrite Beads 100925 100933 100942 101870 101876 BAG 7 BAG 2 32 5 1 1 1 2 34 8 1 2 1 16 Pin Socket 14 Pin Socket Dip Dip Switch Switch (4-SPDT) (4-SPDT) Card Guides 100 Pin Pin Connector Connector 100 102103 102102 102102 102321 101714 101864 100348 MISC. BAG 4 2 1 3 .01MF 16V-1KV 16V-1KV IMF 20V 33MF 16V 1 1 100321 100321 100325 100325 100326 100326 BAG 5 1 2 2 4 Ohm 5W 3W 10% 100 0 h m . % W l Q % 2.2K %W 10% 102007 102007 101924 101945 P . C . Board 4MCS Manual 1O0187 101533
Source Exif Data:
File Type : PDF File Type Extension : pdf MIME Type : application/pdf PDF Version : 1.3 Linearized : Yes Producer : ABBYY FineReader 10 Title : Altair_8800_BASIC_Reference_Manual_1975 Create Date : 2013:06:22 17:04:44+09:30 Modify Date : 2013:06:22 17:04:44+09:30 Page Count : 108EXIF Metadata provided by EXIF.tools