manualshive.com logo in svg
background image

Содержание TRS-80

Страница 1: ...CAT NUMBER 26 2101 USER S MANUAL Rsdie haek CUSTOM MANUFACTURED IN U S A BY RADIO SHACK MA DIVISION OF TANDY CORPORATION ...

Страница 2: ...o Shack whatsoever EXCEPT AS SPECIFICALLY PROVIDED IN THIS AGREEMENT THERE ARE NO OTHER WARRANTIES EXPRESS OR IMPLIED INCLUDING BUT NOT LIMITED TO ANY IMPLIED WARRANTIES OF MER CHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE AND IN NO EVENT SHALL RADIO SHACK BE LIABLE FOR LOSS OF PROFITS OR BENEFITS INDIRECT SPECIAL CONSEQUENTIAL OR OTHER SIMILAR DAMAGES ARISING OUT OF ANY BREACH OF THIS WARRANTY...

Страница 3: ...ontains no The only Stra fyour intelligence Beyond that attempt attempt not to insult your intimidate you u snow jobs no effor P dea that computers to sell you anything excep that bard to learn to use above i i as though savoring a goon rout ine Sit back relax fj JjV I ll supply you all let your imaS xn3t n d The real enjoyment begin becomeB facts and s eS thrcr n eative juices f Vot the other way...

Страница 4: ...o the use of the information contained herein While every pre caution has been taken in the preparation of this book the publisher assumes no responsibility for errors or omissions Neither is any liability assumed for damages resulting from the use of the information contained herein Copyright 1977 Radio Shack A Division of Tandy Corporation Fort Worth Texas 76102 U S A Printed in the United State...

Страница 5: ...Function 69 Chapter 15 More Branching Statements Subroutines ON GOTO GOSUB ON GOSUB RETURN 77 Chapter 16 READ DATA RESTORE String Variables A and B 85 Chapter 1 7 ABS Function 93 Chapter 18 Level I Shorthand Dialect Multiple Statement Lines 95 Chapter 1 9 Generating Random Numbers with RND 99 Chapter 20 Video Display Graphics SET RESET 105 Chapter 21 Arrays Using A X 123 Chapter 22 Advanced Graphi...

Страница 6: ... Chapters we ve given some Exercises to give you a chance to try out your knowledge ON YOUR OWN B A section with sample answers to the Exercises in each Chapter You can see how you make out with your attempts at programming C A section with some User s Programs some good examples of interesting and practical programs some for fun some for business some for education etc We ve also included some he...

Страница 7: ...d and 3 plugs on the other to the TAPE jack on the back of the Keyboard Assembly Be sure you get the plug to mate correctly The 3 plugs on the other end of this cable are for connecting to the CTR 41 A Connect the black plug into the EAR jack on the side of the CTR 41 This connection provides the output signal from the CTR 41 to the TRS 80 for loading Tape programs into the TRS 80 Connect the larg...

Страница 8: ...as a program recorded on it you can disconnect the plug from the EAR jack also disconnect the REM plug so you can control the CTR 41 with the keys and Play the tape you ll hear the program material from the speaker Turn on the Video Display by pressing the POWER button Tum on the TRS 80 Keyboard by pressing the POWER button on the back next to the POWER jack the red LED just to the right of the Ke...

Страница 9: ...oard Give the video tube a few seconds to warm up 3 READY ____ should appear in the upper left corner of the screen Press the QQQ Q key several times to produce a column of READY messages The Computer is trying to tell you something I m ready it s your turn to do something To make sure you start off with a clean slate erasing all traces of prior programs or tests type NEW and press 3fllia The Comp...

Страница 10: ... typed 1 Did you enclose everything after the word PRINT in quotation marks 2 Are there any extra quotation marks If everything s okay you can press l ll jp The prompt will reappear The Computer is telling you Fine what s next If It s Too Late If you find an error after you ve typed a line and pressed la il jj you cannot use the backspace key to correct it Instead retype the entire line correctly ...

Страница 11: ... take time for such things later on Learned in Chapter 1 ComftlarKte Statements PRINT Miscellaneous prompt cursor IBREAKI WU4A NEW backspace key RUN quotation marks We ll put a list like this at the end of each chapter Use it as a checkpoint to make sure you didn t miss anything Maybe you re wondering what s the difference between BASIC commands and BASIC statements Commands are executed as soon a...

Страница 12: ...Notes 10 ...

Страница 13: ...D Oh sorry about that It bombed didn t it The screen said WHAT This error message is the result of a built in troubleshooter which lets you know when you ve said the wrong thing or the right thing at the wrong time The WHAT message on the screen says No no dummy the program you wrote doesn t have any way for me to accept an answer just because it asked a question or words to that effect A later le...

Страница 14: ...inserted a space between the printing ordered in lines 10 and 20 So that s how we insert a space Another important statement is REM which stands for REMARK It is often convenient to insert REMarks into a program Why So you or someone else can refer to them later to help you remember complicated programming details or even what the program s for and how to use it It s like having a scratch pad or n...

Страница 15: ...ment is optional you can put it in or leave it out Remember though if you want to run your BASIC pro grams on fussier computers you ll probably need the END statement Let s take a close look at END By the rules governing its use most dialects of BASIC which require END insist that it be the last statement in a program telling the computer That s all folks By tradition it is given the number 99 or ...

Страница 16: ...an we be sure Think about this now Got it Sure pull a LIST of the entire program by typing list BZQ3D The screen should show the program with lines 5 10 15 20 and 98 99 should be gone Any entire line can be erased the same way The second step is just as easy Type 32767 END MJHHil and the new line is entered Pull a listing of the program to see if it was Was it Now RUN the program to see if moving ...

Страница 17: ...mbers above 32767 are beyond my ability so just HOW do you expect me to obey Pretty smart this computer Commands Learned in Lesson 2 Statements Miscellaneous LIST PRINT Space Error Messages REM WHAT END HOW Line Numbering lk general a HOW message means I m der ftihd your instruction but they re asJoag ltte to 4o i something tfeatV impossible The WHAT error message on the other hand means 1 dont un...

Страница 18: ...Notes 16 ...

Страница 19: ...an multiply We use letters for other things so it s much less confusing to use a for multiplication Confusion is one thing a computer can t tolerate So to computers is the only symbol which means multiply After using it a while you too may feel we should do away with X as a symbol for multiplication Putting all this together in a program is not difficult so let s do it First we have to erase the r...

Страница 20: ...as those we want to figure out Whenever you can it s a good idea to chose letters that remind you of the things they stand for like the D R and T of the Distance Rate Time equation To further complicate this very simple example we will point out now that there s an optional way of writing the equation using the BASIC statement LET 40 LET D R T This use of LET reminds us that making D equal R times...

Страница 21: ... the quotes RKED ON THE MOVE 1 J vj DON T RE0 BEYOND AJZ KL Jiih saw Look in Part B of this Manual for an answer for this 1st Exercise Also some notes and ideas Well the answer of 3000 is correct but its presentation was no more inspiring than the printout from a hand calculator This inevitably leads us back to where we first started this foray into the unknown the PRINT statement Note that we sai...

Страница 22: ...ply by inserting commas between them With this in mind see if you can change line 5 3 so the computer finishes the program with the following message THE DISTANCE IS 3000 impm MILES Break up the quoted message into two parts and put the variable in between them on the PRINT line 50 PRINT THE DISTANCE IS D MILES Now what about all that extra space on the printout line The reason for it is that the ...

Страница 23: ... actually writing programs to solve problems There is no better way to learn than by doing and everything covered so far is fundamental to our success in later Chapters So don t jump over these exercises it s the best way to get you into the thick of programming You ll find sample answers in Part B along with further comments Math operators they re the symbols we talked about earlier EXERCISE 3 2 ...

Страница 24: ...alance was 225 You ve written three checks for 17 35 and 225 and made two deposits 40 and 200 Write a program to adjust your old balance based on checks written and deposits made and print out your new balance i ir LET Learned in Chapter 3 Math Operators Mtsceiteneous A Z variables 22 ftem mfoer yotrcatt use any of the 26 tetters n t just l R n T they were just cpaverjient fm mt p yv j0 i f yS ...

Страница 25: ...al point Since the Computer insists on using it with very large and very small numbers we can just as well get in the good habit too Type NEW before performing the following exercises 1 EXERCISE 4 1 If one million cars drove ten thousand miles in a certain year how many miles did they drive altogether that year Write and run a simple program which will give the answer EXERCISE 4 2 Changes lines 20...

Страница 26: ...Learned in Chapter 4 Miscellaneous E notation i V E standstor exjsonent and ta urease it refers to the e pp nent oi 19 i 6 the number of sseros to the right or left of the main number 24 ...

Страница 27: ... and ABS functions are performed before multiplication and division We haven t talked about these yet but just to be complete 4 A problem listed as X Y will NOT tell the Computer to multiply X Y is for multiplication Example To convert temperature in Fahrenheit to Celsius Centigrade the following relationship is used The Fahrenheit temperature equals 32 degrees plus nine fifths of the Celsius temp...

Страница 28: ... left to right performing first the division problem 9 divided by 5 then the multiplication problem 1 8 times C then the addition problem adding 32 The parentheses really made no difference in our first example Next change 32 to 32 and move it to the front of the equation in line 30 Run it again without parentheses Did it make a difference in the answer Why not Answer Execution proceeds from left ...

Страница 29: ...of parentheses in program line 30 and remove the second pair of parentheses then RUN Note how the answer comes out correctly EXERCISE 5 4 Insert brackets in the following equation to make it correct Write a program to check it out on the TRS 80 30 9 8 7 6 28 Learned in Chapter 5 MisceltenetHis Order of Operations 27 ...

Страница 30: ...Notes 28 ...

Страница 31: ...qual to using the symbol 6 Is greater than or equal to using the symbol By adding these six relational operators to the four math operators we already know plus new STA TEMENTs called IF THEN GOTO we create a powerful system of comparing and calculating that becomes the central core of everything else that follows The IF THEN statement combined with the six relational operators above gives us the ...

Страница 32: ...A If A equals 5 THEN the Computer is directed to go to line 50 But the test fails that is A does NOT equal 5 so the Computer proceeds as usual to the next line line 30 Line 30 directs the Computer to print the fact that A DOES NOT EQUAL 5 It does not tell us what the value of A is only that it does not equal 5 The Computer then proceeds on to the next line Line 40 ENDs the program s execution With...

Страница 33: ... other lines as necessary so the same results are achieved with your program as with the one in the Example EXERCISE 6 2 Change line 10 to give A the value of 6 Leave the other four lines from 6 1 as shown Add more program lines as necessary so the program will tell us whether A is larger or smaller than 5 and RUN 31 ...

Страница 34: ...onditionally follow orders and go to 99 ENDing the run While your Radio Shack Computer is rather broad minded when it comes to accepting these various BASIC dialects many computers are not For practice change lines 40 80 and 99 as discussed above and Did the program work OK as changed Did you try it with several values of A Be sure you do so We will find many uses for the GOTO statement in the fut...

Страница 35: ...THE VALUE I WISH TO GIVE A IS _ See the question mark on the screen It means It s your turn and I m waiting Enter a number and see what happens It should be identical to what happened when you typed in the same number earlier by changing line 10 Run the program several more times to get the feel of the INPUT statement Pretty powerful isn t it Let s add a touch of class to the INPUT process by rety...

Страница 36: ...E I WISH TO GIVE A IS A then delete line 10 by typing 10 then RUN The results come out exactly the same don t they Here is what you have changed 1 PRINT to INPUT 2 Both statements on the same line 3 Eliminated the extra line In the long programs which you will be writing running and converting this shortcut will be valuable Up to now all our programs have been strictly one shot affairs You type RU...

Страница 37: ... the power goes off or some other event beyond its control This is the kind of thing a Computer is best at doing something over and over again Modify some of the other programs to make them self repeating You ll find they re much more useful that way These have been 7 long and meaty lessons so go back and review them all again repeat ing those assignments where you feel weak We are moving out into...

Страница 38: ...Notes 36 ...

Страница 39: ... computer program is loaded without disturbing that program All you need to be in the calculator mode is the prompt Example How much is 3 times 4 Type in PRINT 3 4 the answer comes back 12 Example How much is 345 divided by 123 PRINT 345 123 the answer is 2 80488 Spend a few minutes making up routine arithmetic problems of your own using the calcula tor mode to solve them Any arithmetic expression...

Страница 40: ...ator mode Comdex programs dpmmlndasyoit get into more v i t PRINT A B C D E F T G H I J K L M N 0 P Q R t S T U V W X Y Z The answers depend on the values last given those variables even from much earlier pro grams If you turned off the Computer since last using some of the variables the numbers stored in those locations will be completely arbitrary and meaningless The Memory Command Since the pro...

Страница 41: ...ead for each line short or long is 4 bytes 2 Each letter number and space takes 1 byte In the above program 4 6 10 bytes Enter this additional line leaving in line 10 and calculate the amount of space remaining in memory Then check it with the PRINT MEM command 20 PRINT THIS EXAMPLE IS TH MEASURE MEMORY USAGE How much space is left in memory Answer Line 10 took up 10 bytes Line 20 takes 4 bytes fo...

Страница 42: ...Sorry you have run out of memory locations and must either cut down the pro gram size or purchase additional memory With some practice you will be able to predict how much memory a given program will need All lessons and programs furnished with Radio Shack s LEVEL I system will run in the 4K of memory you have available Y rJC i v f jrV i i i RetaemiHsr the others WWHAT Mld6 ar retarid M irye waBt ...

Страница 43: ... the TAPE jack on the back of the TRS 80 and your Cassette Tape Recorder A The small gray plug goes into the REM jack on the Recorder B The large gray plug goes into the AUX jack C The black plug goes into the EAR jack 3 Plug the Recorder into the wall outlet or install batteries 4 Type any program into your Computer preferably one that is at least several lines long RUN it to be sure it is entere...

Страница 44: ...h line of data a second will flash on and off Watch the Video Display The program is entered when READY returns and the recorder motor stops 4 RUN the program to see that the data transfer was successful In the rare event that it was not repeat the above steps being sure that all cables are properly connected the Volume is set to 7 8 and the tape recorder heads are clean Listen to the tape to be s...

Страница 45: ...ack store When you are not using the Recorder for loading or recording do not leave RECORD or PLAY keys down press STOP Do not expose recorded tapes to magnetic fields Avoid placing your tapes near the Power Supply Do not attempt to re record on a pre recorded Computer data tape Even though the new recording process erases the old recording just enough information may be left to confuse the new re...

Страница 46: ...Learned in Chapter 9 program loading indicator 44 ...

Страница 47: ...ring Type in the following program andRUN 10 PRINT HELP MY COMPUTER HAS GONE BERSERK 20 GOTO 10 You have noticed by now that the Computer is continuously writing the line HELP MY COMPUTER HAS GONE BERSERK It will continue to do so indefinitely until you tell it to stop When you have seen enough hit the BREAKj key What we created is called an endless loop Remember our earlier programs which kept co...

Страница 48: ...e FOR NEXT loop by some value other than one The STEP function allows that Change line 8 to read 8 FOR N 1 TO 5 STEP 2 and RUN Line 10 was printed only 3 times when N l N 3 and N 5 On the first pass through the program when NEXT N was hit it incremented or STEPped the value of N by 2 instead of 1 On the second pass through the loop N equalled 3 On the third pass through N equal led 5 FOR NEXT loop...

Страница 49: ... NO IT S UNDER CONTROL HELP MY COMPUTER HAS GONE BERSERK NO IT S UNDER CONTROL etc 3 more times How would you modify the program so line 10 is printed 5 times then line 30 is printed 3 times Make the changes and RUN The new program might read 8 FOR N 1 TO 5 10 PRINT HELP MY COMPUTER HAS GONE BERSERK 20 NEXT N 25 FOR M 1 TO 3 30 PRINT NO IT S UNDER CONTROL 40 NEXT M i H 47 ...

Страница 50: ...tures we learned earlier Stop now and see if you can figure out a way to construct a workable do loop substituting something else in place of FOR and NEXT Answer 8 N 1 10 PRINT HELP MY COMPUTER HAS GONE BERSERK 15 N N 1 20 IF N 6 THEN 10 30 PRINT NO IT S UNDER CONTROL We say that line 8 initializes the value of N giving it an initial or beginning value of 1 Be fore initializing to the value we wan...

Страница 51: ...N 1 THEN 10 Putting FOR NEXT to work It isn t very exciting just seeing or doing the same thing over and over so there has to be a more noble purpose for the FOR NEXT loop There are many of them and we will be learning new uses for a long long time Let s suppose we want to print out a chart showing how the time it takes to fly from Boston to San Diego varies with the speed at which we fly Remember...

Страница 52: ... It is really solving the problem from Chapter 3 nine times in a row for different values and printing out the result Your screen should look like this BOSTON TO SAN DIEGO RATE MPH TIME HOURS DISTANCE MILES 200 15 3000 300 10 3000 400 7 5 3000 500 6 3000 600 5 3000 7 00 4 28571 3000 800 3 75 3000 900 3 33333 3000 1000 3 3000 50 Haw about tbat Try doing that on the old slide Bdeetbandcafamfetorl v ...

Страница 53: ...e do loop with values of R incre mented by values of 100 mph until a final value of 1000 mph is reached Line 110 is the other half of the loop 8 Line 90 contains the actual formula which calculates the answer 9 Line 100 prints the three values They are positioned under their headings by automat ic zone spacing the commas 10 Lines 90 and 100 are indented from the rest of the program text This is a ...

Страница 54: ...X Learned in Chapter 10 Miscellaneous FOR NEXT Increment CLS Decrement STEP Initialize BREAK key CLEAR Kev Top down Display Scroll Display Do Loop 52 ...

Страница 55: ...erent keys and the space bar during the run to see what happens RUN again this time using only the up arrow to freeze the display Nifty huh Clean stop clean restart This is the key to use for temporary freezes 2 If you want a classy display you can build a pause into the program The screen will fill halt a moment and automatically go on if you don t interrupt the program The Timing Loop In order t...

Страница 56: ...ly 500 FOR NEXT loops per second That means by specifying the number of loops you can build in as long a time delay as you wish Change the program to create a 30 second delay Time it against your watch or clock to see how accurate it is Answer 2 FOR x 1 TO 15000 EXERCISE 11 1 Using the space in lines 1 through 8 design a program which asks you how many seconds delay you wish allows you to enter a ...

Страница 57: ...scloses that the Computer gave a listing starting with line 50 and either 1 filled the screenwith 16 lines or 2 went from line 50 to the end of the program whichever came first LIST and up arrow can be used to find any part of a very long program you wish Again you must have a prompt in order to continue on and do anything else Aside from using one or both of the above techniques to get to the end...

Страница 58: ...ay to slow down our run on the flight times from Boston to San Diego In the process we found out a lot more about the Computer and learned to build a timer loop Now let s see if we can build a timer loop into our big program First let s erase the test program using lines 2 3 4 5 6 7 9 by typing each of those numbers followed with l jjf One way to stop the fast parade of information in our chart is...

Страница 59: ...ps but we finally made it Now that you have picked up so many smarts in these two lessons on FOR NEXT it s your turn to put them to work EXERCISE 11 2 Modify the resident program so that MPH appears below RATE HOURS appears belowTIME and MILES appears below DISTANCE This one should be a breeze for you EXERCISE U 3 Design write and run a program which will calculate and print income at a yearly mon...

Страница 60: ... would simply take too long to generate by hand EXERCISE 11 5 You have a 1000 foot roll of fencing wire and want to create a rectangular pasture Using all of the wire determine what length and width dimensions will allow you to enclose the maximum number of square feet Use the brute force method let the Computer try different values for L and W and print out the Area fenced by each pair of L and W...

Страница 61: ...ncrements and print the answers to the following 1 Value of Load Resistance from 1 to 20 ohms 2 Total circuit power circuit current squared times source voltage I 2 10 3 Power lost in source circuit current squared times source resistance l 1 10 4 Power delivered to load circuit current squared times load resistance I 2 R Note Circuit current is found by dividing source voltage 120 volts by total ...

Страница 62: ...Learned in Chapter 1 1 Commands LIST RUN CONT Statements STOP Miscellaneous Timer Loop Up Arrow Brute force or optimizing method 60 ...

Страница 63: ...nction which is similar to the TAB on a regular type writer It is especially useful when the output is columns of numbers with headings Type in the following program and RUN 10 PRINT TAB 5 THE TAB 20 TOTAL 5 TAB 35 SPENT 20 PRINT TAB 5 BUDGET TAB 20 YEAR S TAB 35 THIS 30 PRINT TAB C 5 CATEGORY TAB 20 BUDGET s TABC 35 MONTH The RUN should appear THE TOTAL SPENT BUDGET YEAR S THI S CATEGORY BUDGET M...

Страница 64: ...d RUN the following 10 A 3 20 B 5 30 C A B 40 PRINT TAB 10 A TAB 20 j B TAB 30 M C 50 PRINT TAB 10 iA TAB 20 t B TAB 30 C It should appear A B Note that the numbers are indented one space beyond the TAB Keep it in mind when lining up or indenting headings and answers Change line 20 to read 20 B 5 and RUN See why the indenting is necessary The Long Lines Division Have you ever wondered what would h...

Страница 65: ...NT I t TAB 45 J It s the trailing semicolon that does the trick It makes the end of one PRINT line con tinue right on to the next PRINT line without activating a carriage return The combination of TAB and trailing semicolon allows you almost infinite flexibility in formatting the output Multiple Statement Lines As our parting shot in this easy lesson we re going to have a sneak preview of what s a...

Страница 66: ...here are some special considerations but with virtually everything else we ve learned so far including FOR NEXT loops it works fine saves space shortens programs and has a lot going for it EXERCISE 12 2 Rework the answer to Exercise 11 3 to include the Hourly rate of pay in the printout Use the TAB function to have the chart display all 5 columns side by side EXERCISE 12 3 Optional Rework the spec...

Страница 67: ... program 10 FOR A 1 TO 3 20 PRINT A LOOP ti 30 FOR B 1 TO 40 PRINT ii it ii B LOOP 50 NEXT B 60 NEXT A and RUN The result is A LOOP B LOOP B LOOP A LOOP B LOOP B LOOP A LOOP B LOOP B LOOP Fetfe bMyva kwabkak spaces In iine W befbrepR I HT three in Hoe 3 before FOR torn in 4 t bejfojcePR J NT aiMUhiee in 5 before NEXT 05 ...

Страница 68: ...d Makes for clear distinction on the screen between the A loop and B loop eh Line 50 completes the B loop and returns control to line 30 for as many executions of the B loop as line 30 directs So far we have printed one A and one B Line 60 ends the first pass through the A loop and sends control back to line 10 the beginning of the A loop The A loop has to be executed 3 times before the program ru...

Страница 69: ...roper nest ing Change these lines 50 NEXT A 60 NEXT B and RUN The Computer says WHAT 60 NEXT B Looking at the program we quickly see that the B loop is not nested within the A loop We have the FOR part of the B loop inside the A loop but the NEXT part is outside it This does not work A later chapter deals with something called flow charting a means of helping us plan programs and avoid this type o...

Страница 70: ...ested FOR NEXT loop now that we know what it is and can put it to use EXERCISE 13 1 Enter the original program found at the beginning of this Chapter It contains a B loop nested within the A loop Make the necessary additions to this program so a new loop called C will be nested within the B loop and will print C LOOP 4 times for each pass of the B loop EXERCISE 13 2 Alter the resident program so t...

Страница 71: ...lking about ordinary round ing what could be ordinary about your Computer Ordinary rouadirigigiyes us the closest whole number whether it s larger or smaller than X INT X on the other taand gives us the largest whole number which is less than or equal to X Ass yon 1 see In this chapter this is a very versatile form of rounding in fact you can use it topro dace the other ordinary kind of rounding a...

Страница 72: ...y never thought of by combining a FOR NEXT loop with the INTEGER function Change the program to read 30 X 3 14159 40 Y INT X 50 Z X Y 60 PRINT X X 70 PRINT i Y jV 80 PRINT Z tZ and RUN AHA I don t know what we ve discovered but it must be good for something It reads X 3 14159 Y 3 Z 141589 We ve split the value of X into its Integer whole number value and called it Y and its decimal value and calle...

Страница 73: ...change the program to accomplish rounding at a different point For example to round X off at the hundredths place 2 digits to the right of the decimal point change lines 20 and 30 to read 20 X X 005 30 X INT X 100 J 100 and RUN using several values for X HmmmmH Do you suppose there is any way to separate each of the digits in 3 14159 or in any other number Do you suppose we would have brought it u...

Страница 74: ...integer value and strip off the decimal part leaving the left hand digit standing alone Let s label the left hand digit L and see what happens Enter 90 M Z 10 100 L INT M 1 10 PRINT L L and RUN Now that s more like it It reads X 3 14159 Y 3 Z 141589 L 1 We peeled off the leftmost digit in the decimal Can you think of any way we might use a FOR NEXT loop in order to strip off some more More recorde...

Страница 75: ...eates a new decimal value of M just a temporary storage location by strip ping off the integer part Plugging in the values M 1 41589 1 41589 Line 130 does the same as line 90 did multiplies the new decimal times 10 so as to make the left hand digit an integer and vulnerable to being snatched away by the INT func tion M 41589 10 4 1589 Line 140 moves the control back to line 95 for another pass thr...

Страница 76: ...lpful of all when inserted in FOR NEXT loops so 97 PRINT 97 A A and RUN Wow The data really comes thick and fast Hard to keep track of so much information and we ve barely begun This tells what is happening during each pass of the loop Is there some way to make it more readable Sure Can you think of a way Yes there are lots of ways Indenting is just one simple way to keep the answers separated fro...

Страница 77: ... 40 FDR R l TO 10 50 A P R R 60 PRINT R A 70 NEXT R Area equals tt times the radius squared that is the radius times itself Then RUN it to make sure it works Pretty routine stuff huh Problem is who needs all those little numbers to the far right of the decimal point Oh you do Well there s one in every crowd The rest of us can do with out them Without giving any big hints modify the resident progra...

Страница 78: ... area to be accurate to 2 decimal places EXERCISE 14 4 At the risk of inducing complete boredom yet teaching an unexpectedly important lesson it s all together now Revise line 55 to introduce 3 place accuracy in the AREA calculated by the resident program Learned in Chapter 14 Functions INT X Miscellaneous Flags 76 ...

Страница 79: ...END 1 70 PRINT N 4 180 END 190 PRINT N 5 DUMMY I m I S3 I m I 1 Notice anything funny about line 70 It takes up twalines on the Display That s because it contains more than 64 characters including line number and blank spaces This is perfectly all right as you may already have discovered in your own pro gramming efforts In fact a program line can contain up to 72 charactere in duding line number a...

Страница 80: ...esn t it The ON GOTO statement is really pretty simple though it looks hard Line 20 says if the INTEGER value of N is 1 then GOTO line 110 if the INTEGER value of N is 2 then GOTO line 130 if the INTEGER value of N is 3 then GOTO line 150 if the INTEGER value of N is 4 then GOTO line 170 if the INTEGER value of N is 5 then GOTO line 190 if the INTEGER value of N is not one of the numbers listed ab...

Страница 81: ... of digits in the line numbers of the branch locations As in most of our examples we could have used any letter after ON not just N As we just saw N can be the value of a letter variable or a complete expression either calculated in place as here or in a previous line Trade Secret Due to the vagaries of rounding error and the chance the error might just round a number like N a tad below the intege...

Страница 82: ... of them in a special place in memory and they can be called up by a simple set of letters We have several at LEVEL I like INT We don t have enough memory to spare here at LEVEL I to hold all the routines in memory so we are going to use a five line subroutine instead of the SGN function to accomplish the same thing Even if you have LEVEL II BASIC in your computer you should complete this Chapter ...

Страница 83: ...program Getting Down to Business Okay now let s combine GOSUB and SGN using a subroutine to see what all this fuss is about Type 10 INPUT TYPE ANY NUMBER X 20 GOSUB 30800 30 ON T 2 GOTO 50 60 70 45 END 50 PRINT THE NUMBER IS NEGATIVE 55 END 60 PRINT THE NUMBER IS ZERO 65 END 70 PRINT THE NUMBER IS POSITIVE etc the subroutine is already typed in and RUN Try entering negative zero and positive numbe...

Страница 84: ...alue as subroutines is that they can be called repeatedly from different parts of a program which is often desirable As ordinary routines they are usually only used once and lines containing GOSUB and RETURN are not needed One value of using special routines as SUBroutines is that some are exceedingly complex to type without error and if each is typed once and saved on cassette tape it can be quic...

Страница 85: ...ns SGN X Learned in Chapter 1 5 Statement ON GOTO GOSUB ON GOSUB RETURN tneous Debugging Calling a subroutine Routines 83 ...

Страница 86: ...Notes 84 ...

Страница 87: ...ny num bers or pieces of data each separated by a comma Each piece of DATA must be read by a READ statement Each READ statement can read a number of pieces of DATA if each variable letter is separated by a comma The display shows that all 5 pieces of data in line 10 the numbers 1 2 3 4 and 5 were READ by line 20 assigned the letters A through E and printed by line 30 j pih mind this important dist...

Страница 88: ... consequence but consistency is comfortable The Plot Thickens Since you now know all about FOR NEXT loops let us see what happens when a DATA line is placed in the middle of a loop Erase the old program with NEW and type in this program 10 DATA 1 2 3 4 5 20 FDR N 1 TO 5 30 READ A 40 PRINT As 50 NEXT N then RUN That DATA line started outside the loop Now move it to line 25 and RUN What hap pened No...

Страница 89: ... can only be read once during each RUN Exceptions Exceptions Because it is sometimes necessary to read the same DATA more than once without having to RUN the complete program over a statement called RESTORE is available Whenever the program comes across a RESTORE all DATA lines are restored to their original unread condition both those that have been read and those that have not and all are availa...

Страница 90: ... are A and B pronounced A String and B String String variables can be assigned to indicate Letters Words and or Combinations of letters numbers and spaces of up to 16 characters Type NEW then type in 10 INPUT WHAT IS YDUR NAME AS 20 PRINT HELLO THERE A and RUN Hey hey How s that for a grabber If that along with what you have learned in earlier chapters doesn t make the creative juices flow nothing...

Страница 91: ...ons The first one prints SEE MY FOXY leaving a space behind the Y since string variables always run letters together allowing you the option of inserting your own space The second print is A RADIO SHACK The third print is the space enclosed in quotes The last print is TRS 80 EXERCISE 16 1 Okay now it s your turn Design a program to produce exactly the same results but using only AS not B A lot of ...

Страница 92: ... the Computer was not turned off since then it was held in memory This fact is more than a laboratory curiosity It can get you into unexplainable programming problems if you re not aware of it Oh by the way There isn t room in LEVEL I BASIC to do everything obviously and we promised earlier that you would learn how to answer YES and NO to the Computer LEVEL II allows you to do it in a straight for...

Страница 93: ...not matter as long as only Y and N are hit The present program relies on line 40 defaulting to the next line if a 1 is NOT found As a partial precaution against a user hitting the wrong letter accidentally and coming up with the wrong answer we can backstop our program with these additional lines 45 IF A THEN 50 47 PRINT PLEASE ANSWER WITH EITHER A Y OR N 49 END Analysis Line 45 insists that to ge...

Страница 94: ... Learned in Chapter 16 Statements READ DATA RESTORE Miscellaneous i V lK i V I String Variables A B Numeric Variables Y N Teaching TRS 80 to respond to YES or NO 92 ...

Страница 95: ...GATIVE NUMBER X 20 Y ABS X 30 PRINT X Y 40 PRINT X Y and RUN inputting different number values both positive and negative Regardless of what number you input as X its absolute value Y is that same number without the sign That s sign like in SGN from an earlier chapter When you re done playing with this one and understand it the chapter is over Learned in Chapter 1 7 Function ABS X absolute value o...

Страница 96: ...Notes 94 ...

Страница 97: ...rthand provision Hang Onto Your Chair Nearly every COMMAND STATEMENT and FUNCTION has a shorthand notation which is much shorter and easier to type and does exactly the same thing The complete list is inside the back cover Here is a list covering those you have learned to date NEW N LIST L RUN R PRINT P MEM M STOP ST CONT C THEN T END E ABS A RESTORE REST GOTO G INPUT IN FOR F NEXT N CSAVE CS CLOA...

Страница 98: ...quickly see that it s possible to pack the information so tightly that it becomes hard to read and also very hard to modify For most of this Manual we will avoid multiple statement lines but when we want to really pack it tight this is the only way to go More Caveat or is it more Emptor Radio Shack Level I Shorthand is nearly foolproof Knowing some of our customers we can t give an unconditional g...

Страница 99: ...r invalid procedures will be called to your attention as they are studied in future chapters NEXT MESSAGE you cannot send control to any point in a multiple statement line except to its first statement Look at Line 20 in the resident program Even if the G 70 was legal in that line there is no way to address it It shares the same line number as the first statement in the same line Only the first st...

Страница 100: ...Learned in Chapter 1 8 i Statements IF condition statement with THEN omitted MisC0 iM ps LEVEL I shorthand dialect Multiple statement lines 98 ...

Страница 101: ...riable from elsewhere in the program Type 50 PRINT RND 0 and RUN RUN it again at least 10 times Did you observe 1 A different number appeared each time 2 All numbers were between and 1 3 Very small numbers were expressed in exponential notation RUN some more until you are satisfied that these statements are true Wait a minute all this RUNning is dumb You have a Computer Build a FOR NEXT loop aroun...

Страница 102: ...etween and 1 into something useful Rather than study that technique however let s look at the Radio Shack upgrade which does it all so much easier Change line 50 to read 50 PRINT RND 15 and RUN Wow That s more like it real live random integers And they all are values that fall between 1 and 15 Figured it out already Pretty simple isn t it 1 If the number in parentheses or its INT value is 0 the nu...

Страница 103: ...W MANY TIMES SHALL WE FLIP THE COIN F CLS 30 P YOU STAND BY WHILE I DO THE FLIPPING 40 F N 1T0F X RND 2 jONXG 60 70 50 P IT BOMBED WAS NEITHER A 1 NOR A 2 END 60 H H 1 sG 80 70 T T 1 80 N N jP P sP iP 90 P HEADS TAILS TOTAL FLIPS P tP H T F 100 P 100 H F 100 T F s P P and RUN Flip the coin 100 times on the first RUN to get a feel for the program and the run time RUN as many times as it takes to co...

Страница 104: ...then passes to Line 80 and the NEXT N When the last N is used up it inserts 4 blank print lines and falls to Line 90 where the Headings are printed then the blank line then the values of H T andF Line 100 calculates and prints the percentage of heads and percentage of tails and then prints 3 blank lines at the end to make the display look less cluttered More Than One Generator at a Time It is poss...

Страница 105: ...two dice If he rolls a sum of 2 called snake eyes a 3 called cock eyes or a 12 called boxcars on the first roll he loses and the game is over That s craps 2 If the player rolls 7 or 11 on the first throw called a natural he wins and the game is over 3 If any other number is rolled it becomes the player s point He must keep rolling until he either makes his point by getting the same number again to...

Страница 106: ...planation When you re running game programs using RND it s a good idea to set the seed to an un predictable value This will ensure that you don t get the same pseudo random number sequence each time you turn on the Computer and play the game Put the following lines at the beginning of your program where they will be executed only once 1 IN ENTER A NUMBER BETWEEN 1 AND 100 N 2 F 1 1 TO N J RND 3276...

Страница 107: ...ens a particular light For graphics the screen is divided into a large number of sections See the Video Display Worksheet on the next page Each light is a rectangular block 2 dots wide by 8 dots high and each has its own address For example SET 55 32 means turn on the light at the junction of 55th X Street and 32nd Y Avenue X is the horizontal address counting across from the left hand side of the...

Страница 108: ...9 9 255 10 10 11 11 256 12 12 319 13 13 14 14 320 15 15 383 16 16 17 17 384 18 18 447 19 19 20 20 448 21 21 511 22 22 23 23 512 24 24 575 25 25 26 26 576 27 27 639 28 28 29 29 640 30 30 703 31 31 32 32 704 33 33 767 34 34 35 35 768 36 36 831 37 37 38 38 832 39 39 895 40 40 41 41 896 42 42 959 43 43 44 44 960 45 45 1023 46 46 47 47 Y 1 2 3 4 5 6 7 8 9 1 1 1 1 2 1 3 1 4 1 5 1 6 1 7 1 8 1 9 2 2 1 2 2...

Страница 109: ... of all this obviously is that we can control whether each block on the screen is white or dark on or off by talking to it at its individual address with SET and RESET statements Blinking Lights in the Sky Flying Saucers or Lightning Bugs If one has an ON OFF switch what does one do with it Is that what s called a rhetorical question With a little imagination one could create blocks that don t jus...

Страница 110: ...round You may have noticed that if a block is lit in the upper left hand corner the READY and the prompt destroy it Try X 6 and Y 6 Then X 5 and Y 5 We can avoid this problem by not returning control to the prompt by adding 99 GOTO 99 at the end of the program After running the program this line locks the Computer in an endless loop To break the loop press BREAK key You should put an endless loop ...

Страница 111: ...e top and fills to the bottom Answer 10 CLS 20 FOR Y TO 47 30 FOR X TO 127 40 SET X Y 50 NEXT X 60 NEXT Y 99 GOTO 99 Next rewrite it so it starts painting at the bottom and fills to the top NOffi Wftgn rufthmg graphfes youll profcabiy want to turn up both the Contrast and Brighten 5S slightly 4i Don t forget 6r ycrahgvetoUseth J8R EAK fcey to stop the endless loop 109 ...

Страница 112: ...XT Y 60 NEXT X 99 GOTO 99 Fantastic now you can paint the old barn at least 4 ways EXERCISE 20 1 Write a program which will allow painting only a small part of the screen you determine which part Allow keyboard INPUT of the starting and ending block num bers in both the horizontal and vertical directions DWat know1 ymcould STEP it MCfcw rds ehT Try a few of those and see how it works Try different...

Страница 113: ...X 99 GOTO 99 andRUNseveral times We can just as easily create a straight vertical line Try this 10 INPUT HORIZONTAL ADDRESS 0 TO 127 S X 20 CLS 30 FOR Y TO 47 40 SET X Y 50 NEXT Y 99 GOTO 99 And RUN this a number of times Now let s see if you can modify this last program so we can INPUT both the starting verti cal address and the length in blocks of the line Of course you haven t forgotten how to ...

Страница 114: ...tangles This program forms a rectangle After NEW type 10 INPUT HORIZONTAL STARTING POINT 0 TO 127 jX 20 INPUT VERTICAL STARTING POINT 0 TO 47 Y 30 INPUT LENGTH OF EACH SIDE IN BLOCKS TO 47 K 40 CLS 50 FOR L X TO X K 60 SET L Y 70 SET L Y K 80 NEXT L 90 FOR M Y TO Y K 100 SET X H 1 10 SET X K M 120 NEXT M 999 GOTO 999 and RUN Since our building blocks are not square but 2 by 8 rectangles we always ...

Страница 115: ...27 90 RESET X Y 100 NEXT X 999 G 999 and RUN If you re interested go back and try similar easy modifications to other demonstration pro grams and have some fun with these reverse or negative displays We can draw other straight more or less lines by just changing both X and Y addresses of SET in the FOR NEXT loop Try this next program to draw a diagonal line 10 INPUT HORIZONTAL STARTING POINT 0 TO ...

Страница 116: ... SET X L Y K 9 NEXT L or 70 SET X K Y L 80 SET X L Y 90 NEXT L Try them both What is the difference in the displays Answer They are inverted mirror images of each other Broken Lines In every graphics program we have used we could have made the lines broken by intro ducing a STEP other than 1 in the FOR NEXT loops For example we can get a broken horizontal line with 114 ...

Страница 117: ...ime but so fast you don t notice the drawing time Change the program as follows 55 RESET X Y 1 70 Y Y l 80 GOTO 40 If S is small you can see the lines being formed and cleared But if S is fairly large try 10 the line seems to move in somewhat old time movie fashion This is the way the illusion of motion is created on a TV set and in some of the popular video games Now try this next program clear o...

Страница 118: ...ordinates Take a look at line 40 40 RESET X Y l if you INPUT Y equal to 0 then the Y address really becomes Y 1 1 A no no We can get around this pesky little detail by changing line 40 to 40 RESET X Y 47 Why does this work Back to the Good Stuff We can just as easily move a point to the right with 10 INPUT HORIZONTAL STARTING POINT 90 TO 127 X 20 INPUT VERTICAL STARTING POINT 0 TO 47 jY 30 CLS 40 ...

Страница 119: ...hem See what you almost missed EXERCISE 20 3 Change the last two programs so that they move the dot up and to the left respectively Now let s have the dot move down until it strikes a barrier The program is 10 INPUT HORIZONTAL STARTING POINT 0 TO 127 X 20 INPUT VERTICAL STARTING POINT 0 TO 47 Y 30 INPUT LOWER BARRIER K 40 CLS 50 FOR M 0 TO 127 60 SET M K 70 NEXT M 80 RESET X Y 47 90 SET X Y 100 Y ...

Страница 120: ... stick to it Now let s have the dot start in the middle and ricochet from both the top and the bottom 10 CLS 20 FOR M 0 TO 127 30 SET M 0 40 SET M 47 50 NEXT M 60 Y 14 70 D l 80 RESET 64 Y 48 D 90 SET 64 Y 100 Y Y D 110 IF Y 48 THEN 130 120 IF YO 1 THEN 80 130 Y Y 2 D 140 D D 150 GOTO 90 999 GOTO 999 118 ...

Страница 121: ...than to RESET in 80 Tricky tricky You can kill the whole day messing around with this silly bouncing ball Rather good resilience eh Real Moving Pictures We can draw whatever figures we like Let s try a stick man First his legs 10 CLS 20 X 64 30 FOR K 0 TO 7 40 SET X K 40 K 50 SET X K 40 K 60 NEXT K 999 GOTO 999 and RUN Then add his body and arms 70 FOR K 0 TO 5 80 SET X K 34 K 90 SET X 34 K 100 SE...

Страница 122: ...Sure moves funny doesn t he Well I m no animator either but I m sure you re beginning to get the idea This has been one long and active Chapter and to think all this with only the SET and RESET statements Think of the good things to follow with two more commands And by simply exchanging RESET for SET in many cases we could have drawn the same pic tures with dark on a light background instead of li...

Страница 123: ...les without getting bogged down in detailed explanations of how each one works There is no substitute for lots of experimenting with graphics and you now know the basics Put in your time stuci he examples and soon you can apply for member ship in the artists guild Statements SET RESET Learned in Chapter 20 121 ...

Страница 124: ...Notes 122 ...

Страница 125: ...lection arrangement or lineup array of a number of autos all of which have different license plates address numbers To be specific we have 10 cars lined up as in an array They are all the same except for their engine size and each has a different license plate number Let s say the license plate numbers are from 1 to 10 and we want to use the Computer to quickly spit out the engine size when we ide...

Страница 126: ...car s engine is found in the first DATA Location and the 10th one s in the last location Now we have to spin up an array inside the Computer s memory to make these data elements immediately addressable Think how difficult it would be to try to address the 7th engine or the 7 thousandth for example using only what we ve learned so far It can be done using only DATA READ and RESTORE statements but i...

Страница 127: ...umber to inside the parentheses by using any of our 26 letter variables and can even do some simple arithmetic inside those paren theses if we wish Remember though there is only one array and its name is A Its elements are numbered and called A sub number Let s work some more on the program Type 170 PRINT 180 PRINT LICENSE ENGINE SIZE 210 PRINT N A N and RUN Now that s more like it We have every l...

Страница 128: ...ou wanted to be terribly inefficient about the matter you could say that this is a 3 by 10 array count ing the license number If so then our original one would have been a 2 by 10 array but who needs it As long as we keep our license numbers in a simple 1 to 10 FOR NEXT loop and our DATA in proper sequence we can keep our arrays simpler and easier to handle How then can we handle this 2 by 10 matr...

Страница 129: ...nt From the table type 300 DATA 3 1 4 3 2 4 3 2 1 3 and 80 FOR S 101 TO 110 85 READ A S 90 NEXT S to load the color code DATA into the array The array element numbers 11 through 100 are not used nor are those from 111 to the end of memory since they have not been formally assigned any values Now we need to find some way to display all this good information Change these lines 10 IN WHICH CAR S ENGI...

Страница 130: ...ncludes 3 different body styles coded 10 20 and 30 as follows LICENSE BODY STYLE 1 20 2 20 3 10 4 20 5 30 6 20 7 30 8 10 9 20 10 20 Modify the resident program to print the body style information along with the rest when the car is identified by license number m A Smith Wesson Beats 4 Aces If we want to create a computerized card game they make good examples to show so many things how can we set i...

Страница 131: ...erwise we might not end up at the same place at the same time Step 1 Spin up all 52 cards into an array 30 FOR C l TO 52jREAD ACO NEXT C 50 DATA 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 55 DATA 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 60 DATA 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 At this point all you can tell when RUNning is that it is taking some processing time since ...

Страница 132: ... A V equal to zero only if line 105 finds it NOT equal to zero already letting the program pointer fall through When a fall through occurs 1 The card s value is printed line 110 2 The number stored in that cell is set to zero line 120 3 Line 130 counts down the number of cards printed Line 90 initialized the number of prints at 52 4 The number of prints is tested line 140 When there are no more pr...

Страница 133: ...reluctant Answer The random number generator has to keep drawing numbers until it hits one that is the array address of an element which has not been set to zero Near the end of the deck almost all elements have been set to zero The random number generator has to keep draw ing numbers as fast as it can to find a live one Look again at the card numbers printed There will not be any duplication No s...

Страница 134: ...the largest usable array element number was about 875 Try P M 4 1 EXERCISE 21 2 Study the User programs in Part C to better understand the use of arrays for storage and access purposes Time spent studying programs written by others is wisely invested HHMNHE tfl Learned in Chapter 21 v 3 v v ir i i Miscellaneous Arrays IAgain 875 is ths result when you only hav 4K of V 132 ...

Страница 135: ...LLO THERE 200 WHEREVER YOU ARE and RUN Where is 200 Back to the Radio Shack graphics layout chart Video Display Worksheet If you don t have one handy there s one back in Chapter 20 With the aid of an ordinary household electron microscope the words PRINT AT are clearly seen on the upper left hand corner of the sheet Also an arrow pointing to a set of numbers Further scrutiny discloses a tiny X obv...

Страница 136: ...e ments printed on that last or bottom line of the video page You will soon see how valuable all this is Oh It s That Time Already Let s create a 24 hour clock Why not this obscure print statement logic Type sounds like more fun than digging through all 10 CLS 20 PRINT AT 407 H M S 30 FOR H TO 23 40 FOR M TO 59 50 FOR S TO 59 60 PRINT AT 470 Hi M S 70 FOR N 1 TO 500 NEXT N 80 NEXT S 90 NEXT M 100 ...

Страница 137: ...yout chart you can find address 407 with 470 right below it With blazing speed the HMS no no not Her Majesty s Service it stands for Hours Minutes and Seconds are printed and the HM S updated each second For the real clock nut see Part C for an operational clock program It only needs your closer calibration to be an acceptable sundial Most expensive clock in the house That s How the Ball Bounces M...

Страница 138: ...or Display Purposes A good way to get a feel for PRINT AT or any feature is to look at a fairly simple program which illustrates its use This program lays out a graph format on the screen What you do with it beyond that point depends on your own needs and interests but it is worth entering studying and getting a feel for its use Type 10 CLS 20 K 900 30 F X 1T059 40 P ATK X 50 N Xi K 964 60 FOR Y T...

Страница 139: ...f that point is lit the POINT statement says 1 If it is dark the POINT statement says 0 That s really all there is to it Of such great simplicity great power is derived Let s give POINT a little exercise before looking closer Since it also works in the calculator mode type PRINT POINTt 30 30 Since we had not lit 30 30 the answer came back with 0 It also can be abbreviated Type P P 30 30 Same thing...

Страница 140: ...could do if we set something like this up in 2 nested FOR NEXT loops so we scanned the entire screen and got a status report on each point Hmmm Almost like a radar scan of the terrain Hmmm some more 2001 Here We Come Snug up your seat belt type and RUN the following program then sit back and watch POINT in action Study the display very carefully as it runs looking for the many things that occur Th...

Страница 141: ...coordinates and their headings in lines 130 and 140 Line 30 clears the screen for action Line 40 and 50 use PRINT AT to print the heading Line 100 generates 15 addresses and SETs 15 lights Line 110 uses two nested FOR NEXT loops to establish a scanner testing every graphics point on the screen Line 120 tests to see if the point being addressed is off If so the address printing and related incremen...

Страница 142: ...oint or just left alone Line 200 is the locking loop used to keep READY and the prompt from goofing up the display Pretty simple when taken a line at a time isn t it Oh yes did you notice that the moving dot turned off the original heading Did you also notice that it took two passes of the dot to equal the width of one printed character which of course fits right in with what the layout sheet show...

Страница 143: ...s are called Modules But how are the modules related and how do you write them anyway One way to plan a program is to make a picture displaying its logic Remember a picture is worth a thousand words or is it the other way around The picture that pro grammers use is called a flowchart Flowcharts are so widely used that programmers have devised standard symbols There are many specialized symbols in ...

Страница 144: ... on when you ve forgotten There are no hard and fast rules about what goes into a flowchart and what doesn t A flow chart is supposed to help you not be more work than it s worth It helps you plan the logic of your program When it stops helping and makes you feel like you re back in arts and crafts designing mosaics then you ve gone as far as the flowchart will take you or more typically you ve pa...

Страница 145: ... if all the questions in a single student s paper have been graded The third one terminates execution when all the tests have been graded EXERCISE 23 1 Using the flowchart as a guide write a program that grades a test having five questions For more complicated problems you may want to subdivide the flochart into larger modules A master flowchart will then show the relationship between the flowchar...

Страница 146: ... 3 CREDIT UNION 4 MORTGAGE LOAN The main or Control program will select one of these 4 options using an input question execute the correct subprogram and print the answer Its flowchart might be START ENTER OPTION CALCULATE CERTIFICATE OF DEPOSIT CALCULATE FOR BAM K SAVINGS ACCOUNT CALCULATE FOR CREDIT UNION CALCULATE Ft H MORTGAGE LOAN PfllNT RETURN ON INVESTMENT 144 ...

Страница 147: ...ficate matures The order in which that pro gram inputs data and performs the calculations would be specified in its own flowchart EXERCISE 23 2 Write the master program as flowcharted with a branch to a program to calculate the return on a Bank Savings account paying simple interest EXERCISE 23 3 Choose a program from an early Chapter and design your own flowchart Learned in Chapter 23 Miscellaneo...

Страница 148: ...Notes 146 ...

Страница 149: ...3 to 4 That principle is called logical OR These ideas are both pretty logical If the cow can figure them out surely you can PASTURE 3 f f OLD BESS PASTURE 4 gate X t c gate Y 1 gatez FIGURE 2 Grit Your Teeth and Prepare to Say AAAAAGHH Somewhere in the misty history of classical mathematics a budding genius dedicated the symbol X to mean AND and to mean OR Ordinary arithmetic of course uses X to ...

Страница 150: ... the Y and N values at 1 and respectively Lines 20 30 and 40 input the gate positions as open which we defined as equal to 1 or closed defined as 0 We could have defined them the other way around in line 10 and rewritten line 60 to match if we d wanted to Line 60 is the key It reads literally If gate A is open AND gate B is open AND gate C is open then go to line 100 If any one gate is closed repo...

Страница 151: ...el and the OR logic seen in Figure 2 write a program which will report Bessie s status as determined by the position of Gates X Y and Z Teacher s Pet Here is a simple program which uses instead of the equals sign in a logical test The student passes if he or she has a final grade over 60 OR a midterm grade over 70 AND a homework grade over 75 Enter the program RUN it a few times and see how effici...

Страница 152: ... logi cal Type it in and RUN 10 INPUT FIRST NUMBER IS X 20 INPUT SECOND NUMBER IS Y 30 IF X 0 Y 0 THEN 70 40 IF X 0 Y 0 THEN 90 50 PRINT OPPOSITE SIGNS 60 END 70 PRINT BOTH POSITIVE 80 END 90 PRINT BOTH NEGATIVE With Graphics Too Yet Yes the logical symbols also work along with the graphics statements See if you can figure out the surprise caused by the logical OR in line 40 Type this program in a...

Страница 153: ... 99 What happens to the program if you replace OR with AND Sketch your estimated result then change line 40 and try it Hope you got it right If not it really sneaked up on you didn t it Using the INT function we can create an elaborate checkerboard The reasoning is In the horizontal dimension The INT X 16 16 X will equal when X equals 0 16 32 48 64 80 96 and 112 In the vertical dimension The INT Y...

Страница 154: ... a YES Using logical OR it branches to the no go statement line 130 if any one of the tests does not match the expectation 10 CLS 20 Y l N 0 30 P ANSWER THESE QUESTIONS WITH YES OR NO sP 40 IN HAS THE CAT BEEN PUT OUT A 50 IN IS THE PORCH LIGHT TURNED OFF B 60 IN ARE ALL DOORS AND WINDOWS LOCKED C 70 IN IS THE TELEVISION TURNED OFF jD 80 IN DID YOU TURN THE THERMOSTAT DOWN E 90 P s P 100 IF A N B ...

Страница 155: ...arts of a program are rewritten to accommodate the switch EXERCISE 24 2 Rewrite line 40 in th checkerboard program to produce a black on white checkerboard instead of white on black Learned in Giapter 24 Miscellaneous as a logical AND symbol as a logical OR symbol 153 ...

Страница 156: ...Notes 154 ...

Страница 157: ...pecial routines that we can call to make the computer educated beyond its intelligence Most are very mathematical and are only for rather special applications But when they are needed they are badly needed Even if you don t think you ll have use of them go through this lesson anyway You ll probably find some special program in a magazine or elsewhere that you desperately want to run on your Comput...

Страница 158: ...lls us the Computer does not recognize SQR That means we ll have to call up the SQR subroutine from Appendix A to make a workable program See the list at the end of this Chapter to determine which functions are available as sub routines in Appendix A Turn to page 216 of Appendix A and find the Square Root Subroutine There are three important things to look for when checking out any subroutine 1 Wh...

Страница 159: ... We send controjto 3 M 30 rather than 3 0i0 because J0010 and 30020 are the non working parts of the program they re just remarks for identification only That s because the Computer has to do quite a bit of thinking to compute square roots See computers aren t so smart after all If the program didn t RUN go over the main program and the subroutine very carefully Did your GOSUB statement in Line 40...

Страница 160: ...o some fairly entertaining uses Type in the following program 10 CLS 20 FOR R 2 TO 22 STEP 4 30 FOR A R TO R 40 X R R A A GOSUB 30030 Y INT Y 5 50 SET A 60 23 Y 60 SET A 60 23 Y 70 NEXT A 80 NEXT R 90 GOTD 90 And RUN If you entered the program correctly the Computer will generate a series of concentric circles The program uses the formula for finding the coordinates of a circle on a graph Y JR R X...

Страница 161: ...eighborly and let one subroutine call on another Suppose we want to compute 3 U that s 3 times itself 11 times We can compute it directly as 3 3 3 3 3 3 3 3 3 3 3 right But what about 3 1 3 that is 3 to the 11 3 power Simple multiplication isn t going to get us anywhere on this one It looks like a job for Supersub That s our Exponential Subroutine which actually calls on two other subroutines befo...

Страница 162: ...k questions and returns the computed value P Xv to the main program Line 50 for output Now let s go off on a tangent about Christmas trees Selecting a Christmas tree in the middle of a forest on a snowy evening in December can be a trying process Especially when you re seeking a tree that s exactly 28 feet tall the tree is going to be set up in a park downtown You can climb up each tree attach a 2...

Страница 163: ...ion cord to run from the nearest electrical outlet to the site of the tree TAN X is one of the trigonometric functions available as a subroutine for the TRS 80 Turn to page 218 of Appendix A and find the Tangent Subroutine It s the longest of the trig subroutines because it actually contains two of the others Sine and Cosine Type NEW to clear out the program memory and carefully type in the tangen...

Страница 164: ...the angle will be when you re standing 12 feet away from a 28 foot tree Then all you ll have to do is find a tree that gives you that angle reading on your surveyor s transit or simple protractor when you re standing 12 feet away Remember our formula H D TAN A Well in this case we know H Height and D Distance What we re seeking is a certain angle such that H D TAN A In short we want to find the an...

Страница 165: ...o put your points on the screen Remember that the ranges of X and SIN X will have to be adjusted to fit the 128 by 48 position screen Learned in Chapter 25 M m Subroutines regular and super Dummy variables Subroutines available in Appendix A Square Root Exponentiation Logarithms Natural and Common Exponential Powers of e Tangent Cosine Sine Arc Cosine Arc Sine Arc Tangent Sign 163 ...

Страница 166: ...Notes 164 ...

Страница 167: ...blem 2 An operator problem or 3 A software problem 1 1 i Is it Farther to Ft Worth or By Bus Starting with the least likely possibility is the Computer itself working properly Chances are and our fondest desire is that the Computer is working perfectly There are several very fast ways to find out A Type PRINT MEM 1 or just P Mi If there is no program loaded into memory the answer should be 3583 If...

Страница 168: ...0 second wait for the array to spin up the monitor should display 12 3 4 5 6 7 8 etc through 8 7 6 If the word BAD appears on the screen you may have found the problem You will probably want to enter this test program into your computer try it out before you need it then save it on tape and hope that you won t need it that is Video Display Problems The Video Display is very similar to a television...

Страница 169: ...l I til Bp W haPttt if so Go walk the dog then check it all over again If Then If the trouble was not found in the cockpit or with the hardware there is probably some thing wrong with your program Dump out the troublesome program Load in one that is known to work and run it as a final hardware and operator check For a rgaliy complete checkout load the combined Funetionahd RAM Test program listed i...

Страница 170: ...er than a single letter of the alphabet Example 10 INPUT AG S1 ERROR LEVEL I variable names can have neither more than one letter nor a letter number combination c Forget a semicolon or comma separating variables or text or bury the semicolon or comma inside quotation marks Example 10 PRINT THE VALUE I S V ERROR The semicolon is inside the quotation marks so the string of words and the variable ar...

Страница 171: ... also apply plus b Do you have a NEXT statement to match the FOR Example 10 FOR A l TO N ERROR Where s the NEXT A c Do you have all the requirements for a loop a starting point an ending point a variable name and a STEP size if it s not 1 Example 10 A l TO N ERROR Must have a FOR and a NEXT d Did you accidentally nest 2 loops using the same variable in both loops Example 10 FOR X l TO 5 20 FOR X l...

Страница 172: ... or GOTO really exist Be especially careful of this error when you eliminate a line in the process of improving or clean ing up a program 5 The error comes back as SORRY but the P M indicates there is room left in memory If you get a SORRY and are using the A X numeric array be sure to check P M then subtract 4 bytes for each array element used You have probably overrun the amount of available mem...

Страница 173: ...typing accuracy From the Ridiculous to the Sublime All the Computer can tell us is that we have or have not followed all of its rules Assuming we have followed all the rules the Computer will not ask WHAT or HOW even if we re asking it to do something that s quite silly and isn t at all what we intended It will dutifully put out garbage all day long if we feed it garbage even though we follow its ...

Страница 174: ...Use the calculator mode or a separate hand calculator to do that work 4 Remember that you can force the Computer to start running a program at any line number you choose Just type RUN where represents the desired line number This is a useful tool for working your way back through a program You give the variables acceptable values using calculator mode statements and then RUN the program starting f...

Страница 175: ...re program here and some more there but it s easy to lose sight of the purpose of the program It is at times like this when the flow chart is ignored and the trouble begins Nuff said We ll leave you some space to make notes on your own debugging and troubleshooting ideas Learned in Chapter 26 Miscellaneous Defensive programming Computer detected errors Flags Hardware checkout procedures Share them...

Страница 176: ...Notes 174 ...

Страница 177: ...Notes 175 ...

Страница 178: ...Notes 176 ...

Страница 179: ...PartB Answers to Exercises in the Chapters 177 ...

Страница 180: ... it right the first time don t be discouraged Type in line 50 above and RUN the program Then return to Chapter 3 and continue SAMPLE ANSWER FOR EXERCISE 3 2 10 REM TIME SOLUTION KNOWING DISTANCE AND RATE 20 D 3000 30 R 500 40 T D R 50 PRINT THETIME REQUIRED IS T HOURS NOTE Remember to IJJhJJ each line SAMPLE RUN FOR 3 2 THE TIME REQUIRED IS 6 HOURS Note In order to arrive at the formula in line 40...

Страница 181: ... the value of pi 3 14 SAMPLE ANSWER FOR EXERCISE 34 10 REM CIRCULAR AREA SOLUTION 20 P 3 14 30 R 5 40A P R R 50 PRINT THE CIRCLE S AREA IS A SQUARE I NCHES SAMPLE RUN FOR 34 THE CIRCLE S AREA IS 78 5 INCHES Note The LEVEL I BASIC system does not have a function which means raise to the power to handle R 2 LEVEL II BASIC does In easy cases like this one we can simply use R times R R R If you have a...

Страница 182: ...OLUTION PROGRAM 20 N 1000000 30 D 10000 40 T N D 50 PRINT THE TOTAL NUMBER DF MILES DRIVEN IS SAMPLE RUN FOR 4 1 THE TOTAL NUMBER OF MILES DRIVEN IS 1E 10 Note As discussed earlier this answer is the number 1 followed by ten zeroes 10 000 000 000 Ten Billion The Computer will not print any numbers over 999 999 without converting them to exponential nota tion B j m rrmi tii aBBWMiWMjf jMaM aHB SAMP...

Страница 183: ...t they can do is slow down calculating the answer by a few millionths of a second SAMPLE ANSWER TO EXERCISE 5 2 30 C F 32 5 9 SAMPLE RUN FOR 5 2 65 DEGREES FAHRENHEIT 47 222 DEGREES CELSIUS Note how silently and dutifully the computer came up with the WRONG answer It has done as we directed and we directed it wrong A common phrase in computer circles is GIGO pronounced gee joe It stands for Garbag...

Страница 184: ...E ANSWER TO EXERCISE 5 4 Two possible answers 30 9 8 7 6 28 30 9 8 7 6 28 Sample Programs 10 A 30 9 8 7 6 20 PRINT A Or line 10 might be A 30 9 8 7 6 Try a few on your own SAMPLE ANSWER FOR EXERCISE 6 1 10 A 5 20 IF A 5 THEN 50 30 PRINT A EQUALS 5 40 END 50 PRINT A DOES NOT EQUAL 5 SAMPLE RUN FOR 6 1 A EQUALS 5 182 ...

Страница 185: ... 90 PRINT A IS SMALLER THAN 5 SAMPLE RUN FOR 6 2 A DOES NOT EQUAL 5 A IS LARGER THAN 5 Note We had to put in another END statement line 80 to keep the program from running on to line 90 after printing line 70 SAMPLE ANSWER TO EXERCISE 11 1 2 INPUT HOW MANY SECONDS DELAY DO YOU WISH S 3 P 500 4 D 5 P 5 FOR X 1 TO D 6 NEXT X 7 PRINT DELAY IS OVER TOOK S SECONDS 183 ...

Страница 186: ...missed the real basics SAMPLE ANSWER TO EXERCISE 11 3 5 CLS 10 PRINT SALARY RATE CHART 20 PRINT 30 PRINT YEAR MONTH WEEK DAY 4 PRINT 50 FOR Y 5000 TO 25000 STEP 1000 55 REM CONVERT YEARLY INCOME INTO MONTHLY 60 M Y 12 65 REM CONVERT YEARLY INCOME INTO WEEKLY 70 W Y 52 184 The FOR NEXT STEP function is limited to hum Mrs betw n 32767 and 32767 inclusive If you specify upper or lower limits or a ste...

Страница 187: ... 11 3 YEAR SALARY RATE CHART MONTH WEEK DAY 5000 41 6 667 96 1538 19 2308 6000 500 115 385 23 0769 7000 583 333 134 615 26 9231 ETC SAMPLE ANSWER FOR EXERCISE 114 10 R 01 20 D 1 30 T 01 35 CLS 40 PRINT DAY DAILY TOTAL 50 PRINT ft RATE EARNED 60 PRINT 70 PRINT D R T 80 IF R 1E6 END 90 R R 2 185 ...

Страница 188: ...000000E 02 2E 02 4E 02 8E 02 16 32 1 000000E 02 3E 02 7E 02 15 31 63 ETC SAMPLE ANSWER FOR EXERCISE 11 5 1 REM FIND THE LARGEST AREA 5 CLS 10 PRINT WIRE FENCE LENGTH WIDTH AREA 20 PRINT FEET M FEET 30 F 1000 40 FOR L TO 500 STEP 50 50 W F 2 L 2 60 A L W 70 PRINT F L W A FEET SQ FEET I fcfi 186 ...

Страница 189: ...g 5 CLS 9 REM SET MAXIMUM AREA AT ZERO 10 M 14 REM SET DESIRED LENGTH AT ZERO 15 N 0 19 REM F IS TOTAL FEET OF FENCE AVAILABLE 20 F 1000 24 REM L IS LENGTH OF ONE SIDE OF RECTANGLE 25 FOR L TO 500 STEP 50 29 REM L IS WIDTH OF ONE SIDE OF RECTANGLE 30 W CF 2 L 2 35 A W L 39 REM COMPARE A WITH CURRENT MAXIMUM REPLACE IF NECESSARY 40 IF A M THEN GOTO 55 45 M A 49 REM ALSD UPDATE CURRENT DESIRED LENGT...

Страница 190: ...OURCE LOAD 40 PRINT RESISTANCE POWER POWER POWER 50 PRINT OHMS CWATTS WATTS WATTS 60 PRINT 70 FOR R l TO 20 80 I 120 C 10 R 90 C I I 10 R 100 S 1 1 10 110 L I I R 120 PRINT R C S L 130 NEXT R SAMPLE RUN FOR EXERCISE 11 6 LOAD CIRCUIT SOURCE LOAD RESISTANCE OHMS 1 POWER WATTS 1309 09 POWER WATTS 1190 08 POWER WATTS 1 19 008 2 1200 1000 200 3 1 107 69 852 071 255 621 ETC nrrmrernmn NOTE Use4 key to ...

Страница 191: ...GET TAB 32 MONTH SAMPLE ANSWER FOR EXERCISE 12 2 30 PRINT TAB 1 YEAR TAB 1 2 j MONTH TAB C 2 5 WEEK 40 PRINT TAB 38 DAY TABt 51 HOUR 85 REM CONVERT WEEKLY INCOME INTO HOURLY 90 H W 40 SAMPLE RUN FOR 12 2 SALARY RATE CHART YEAR MONTH WEEK DAY 5000 6000 416 667 500 96 1538 115 385 19 2308 23 0769 HOUR 2 40385 2 88462 ETC 189 ...

Страница 192: ...10 OHMS TAB 21 WATTS 55 PRINT TAB 36 WATTS TAB 51 WATTS 120 PRINT 10 M TAB 10 R TAB 20 C TAB 35 S TAB 50 L SAMPLE RUN FOR EXERCISE 12 3 INTER LOAD CIRCUIT SOURCE LOAD RESIST RESIST POWER POWER POWER OHMS OHMS WATTS WATTS WATTS 10 1 1309 09 1 190 08 1 19 008 10 2 1200 1000 200 10 3 1107 69 852 071 255 621 ETC SAMPLE ANSWER FOR EXERCISE 1 3 1 10 FOR A 1 TO 3 20 PRINT A LOOP 30 FOR B 1 TO 2 40 PRINT ...

Страница 193: ...this 4 deep nesting stop the RUN frequently to examine the nesting relationships between each of the loops SAMPLE ANSWER FOR EXERCISE 14 1 Addition of the following single line gives a nice clean printout with all values rounded to their integer value 55 A INT A Worth all the effort to learn it wasn t it SAMPLE ANSWER FOR EXERCISE 14 2 55 A INTC 10 A 10 When 3 14159 was multiplied times If it beca...

Страница 194: ...he lesson Go back and read it OK 32727 is the largest permissible number inside the brackets of INT A When the pro gram tried to execute the fourth pass of the loop it hit INT 1000 5 3 2654 etc which becomes INT 5 3265 4 which is of course too big So the Computer said HOW But wait there is a way to get the desired result Try 55A INT A INK A INK A 1000 1 000 SAMPLE ANSWER FOR EXERCISE 15 1 10 INPUT...

Страница 195: ...ving a space for the printing from the upcoming A and has a trailing semicolon so the carriage return is suppressed Line 5 establishes a two pass FOR NEXT loop Line 10 Reads RADIO SHACK Line 20 contains the two DATA strings separated by a comma Line 30 PRINTs RADIO SHACK and a space on the first pass of the N loop Note the trailing semi colon to again suppress the carriage return Line 40 returns c...

Страница 196: ...LOCK C0 TO 47 W 50 CLS 60 FOR X H TO I 70 FOR Y V TO W 80 SET X Y 90 NEXT Y 100 NEXT X 999 GOTO 999 SAMPLE ANSWER FOR EXERCISE 20 2 The following lines are changed The rest are the same 50 FOR L X TO X K 2 l 70 SETtL Y K l 90 FOR M Y TO Y K l 110 SET X K 2 1 M wmmmmmmmmmemmmmgmmsmmammmsamgsn SAMPLE ANSWER FOR EXERCISE 20 3 A MOVE THE DOT UP 10 INPUT HORIZONTAL STARTING POINT 0 TO 127 X 194 ...

Страница 197: ...Y Y 48 90 GOTO 40 99 GOTO 99 B MO VE THE DOT TO THE LEFT 10 INPUT HORIZONTAL STARTING POINTC0 TO 127 X 20 INPUT VERTICAL STARTING POINT 0 TO 47 jY 30 CLS 40 RESET X l Y 50 SET X Y 60 X X l 70 OF X g THEN 40 80 X X 128 90 GOTO 40 999 GOTD 999 SAMPLE ANSWER FOR EXERCISE 21 1 Add or change the following lines ...

Страница 198: ...00 DATA 20 20 10 20 30 20 30 10 20 20 SAMPLE ANSWER FOR EXERCISE 22 1 Insert the following lines 105 IF Y 46 THEN 180 115 IF Y l THEN 180 150 PRINT AT Y 64 32 160 G 90 i tv ii ujin n i iu iHiiHi i IN w j m u i i mii i MnjrTirriiifTr T iTTTnT n vr 180 PRINT AT Y 64 32 PING 190 G 90 Note that line 180 prints the ping and line 150 makes it disappear by printing blanks in its place 196 ...

Страница 199: ...RESTORE 60 N 0 70 FOR 1 1 TO 5 80 PRINT ANSWER NUMBER I 90 INPUT A 100 READ B 110 PRINT A B 120 IF A B THEN PRINT CORRECT N N 1 130 PRINT 140 NEXT I 150 PRINT N RIGHT OUT OF 5 160 PRINT N 5 100 170 P ANY MORE TESTS TO GRADE 180 IN 1 YES 2 NO jZ 190 IF Z l GOTO 50 200 DATA 65 23 17 56 39 SAMPLE ANSWER FOR EXERCISE 23 2 10 REM SAMPLE ANSWER 23 2 197 ...

Страница 200: ...ERTIFICATE OF DEPOSIT PROGRAM GOES HERE 1010 P THE CD PROGRAM HAS YET TO BE WRITTEN 1020 GOS 10000 G 100 2000 REM BANK SAVINGS ACCOUNT PROGRAM 2010 CLS P iP THIS ROUTINE CALCULATES SIMPLE INTEREST ON 2020 P DOLLARS HELD IN DEPOSIT FOR A SPECIFIED PERIOD 2030 P USINGA SPECIFIED PERCENTAGE OF INTEREST P 2040 P J IN HOW LARGE IS THE DEPOSIT IN DOLLARS jP 2050 IN HOW LONG WILL YOU LEAVE IT IN IN DAYS ...

Страница 201: ...GE LOAN PROGRAM GOES HERE 4010 P THE M L PROGRAM HAS YET TO BE WRITTEN 4020 GOS 10000 G 100 10000 F I lTO2000sN I RET SAMPLE ANSWER TO EXERCISE 24 1 Changes in only two lines are required 60 IF CA 1 B l c l THEN 100 100 P A GATE IS OPEN OLD BESSIE IS FREE TO WANDER Line 60 reads If gate A is open OR gate B is open OR gate C is open then GOTO 100 SAMPLE ANSWER TO EXERCISE 24 2 40 IF INT X 16 16 XlO...

Страница 202: ...SE 25 1 10 INPUT DISTANCE FROM TREE D 20 INPUT HEIGHT OF TREE YOU RE SEEKING H 30 X H D GOSUB 30660 40 PRINT REQUIRED ANGLE IS C DEGREES SAMPLE ANSWER FOR EXERCISE 25 2 1 CLS 10 FOR A 0 TO 360 20 X A GOSUB 30370 30 Y Y 20 40 SET A 3 Y 22 50 NEXT A 60 GOTO 1 200 ...

Страница 203: ...PartC Some User s Programs USE ME BUT BE GENTLE 201 ...

Страница 204: ...EST FROM iBt A j i 270 FOR 1 1 TO N 280 P At 1 t 290 READ 2 300 P Z 310 IF A I Z P CORRECT j R R 1 320 P 330 NEXT I 340 P PERCENTAGE CORRECT I NT R N 1 00 5 350 P 360 G 150 370 DATA 5 3 A D C E T T F T mm Slowpoke The kiddies of all ages will enjoy this one It tests reaction time When the com puter says G you press any key to stop it Then it s the next player s turn to RUN it The player who stops ...

Страница 205: ... 9 G 1 10 100 G 300 110 A 0 120 a B i 130 IF B 5 G 150 140 G 300 150 B 0 160 C C 1 170 IF C 9 G 190 180 G 300 190 C 0 200 C D 1 210 IF D 5 G 230 220 G 300 230 0 0 240 E 1 250 IF E 9 G 270 260 G 290 270 E 0 280 F F 1 290 IF F 1 E 3 A 0 B 0 C 0 iD 0 E 1 iF 0 300 CLS 310 P AT 470 F Ei i DtCi tB A 320 G 70 Checksum For Business For those responsible for inventory numbers or check clearing and balancin...

Страница 206: ... even when not raised very far off the ground Electrically it consists of two loops of wire one of which is fed with coaxial cable or twin lead the other simply soldered together at its ends Figure 1 is an illustra tion of a quad The program inputs only your desired operating frequency It then calculates and outputs all the mechanical dimensions needed so you can construct your own quad Happy desi...

Страница 207: ...DER BOOMLESS QUAD MOUNT IS USED 700 P EACH SPREADER WILL HAVE TO BE AT LEAST jP FEET 730 P 740 P THE TURNING RADIUS FOR TREE CLEARANCE ETC WILL VARY 745 P BETWEEN iTi FEET AND Ui FEET DEPENDING ON THE LENGTH 750 P OF THE BOOM 755 P 760 P T 20 PRESS ENTER TO CONTINUE IN AS 770 790 795 800 810 840 845 855 860 880 9999 10000 10010 10020 10030 10040 10050 10060 10070 10080 10090 10 100 CLS P THIS QUAD...

Страница 208: ...RISTLY BLACK LASHES AND SLIGHTLY tGOS 5 206 116 P TILTED AT THE ENDS ABOVE THEM HER THICK BLACK BROWS iGOS 5 118 P SLANTED UPWARDS CUTTING A STARTLING OBLIQUE LINE IN HER GOS 5 120 P MAGNOLIA WHITE SKIN THAT SKIN SO PRIZED BY SOUTHERN iGOS 5 122 P WOMEN AND SO CAREFULLY GUARDED WITH BONNETS VEILS AND iGOS 5 124 P MITTENS AGAINST HOT GEORGIA SUNS GOS S The Wheel Of Fortune Or Never Give a Sucker an...

Страница 209: ...FDR Z 1 TO R NEXT Z Z3S P P 1 236 IF P 0 P 54 240 N SiP TAB 29 iQ A P 4 iGOS 2000 iX 0 2 50 P TAB 22 i YOUR C HO ICE WAS i Q G iGOS 2 000 260 P TAB 23 i IFG A P 4 P YOU WIN AT D TO 1 iE 270 P YOU LOSE E 500 D 1 2 80 1 5 1 2 1 10 1 2 1 5 1 2 1 5 l Z I 0 1 2 10 510 D 1 2 1 5 1 2 I 5 1 2 13 1 2 1 10 1 2 1 2 520 D 1 20 1 2 5 1 2 10 1 2 5 2000 Q IFtOOl 3 Q 8 P Q RET 2010 0 40 i AS JOKER IFQ 80 AJ TRS 8...

Страница 210: ...0 D E D 260 N N 265 P 208 266 G 310 270 P WHAT IS THE TOTAL PROJECTED EARNINGS FOR 1 SHARE OF 280 P EACH 285 INPUT D 290 REM I ESTIMATED INFLATION RATE 310 P WHAT PERCENTAGE IS THE INFLATION RATE 320 INPUT I 330 T D IK P I 01 340 R T D 350 P 360 P I NFL RATE DJI EARN PRO J D J AVG AVG EARN RATIO 370 P 380 P I D T R 390 D ALLIED CHEM ALCOA AMER BRANDS AMER CAN A T T 400 O BETH STEEL CHRYSLER DUPONT...

Страница 211: ...B6000 2100 P AT525 OF EASY WIND AND DOWNYFLAKE 2101 GOSUB6000 2200 P ATS25 THE WOODS ARE LOVELY DARK AND DEEP 2201 GOSUB6000 2300 P AT5S9 BUT I HAVE PROMISES TO KEEP 2305 1 3 2310 GDSUB6000 2 00 P AT6S3 AND MILES TO GO BEFORE I SLEEP 2405 1 6 2 10 GOSUB6000 2500 P AT717 AND MILES TO GO BEFORE I SLEEP 2505 1 9 2510 GOSUB6000 5000 SET RND 1 27 RND 47 5001 G 5000 6000 F N 1TO20 6020 X RND 127 6030 Y ...

Страница 212: ...GAME OF SORRY 11 IN ENTER A NUMBER FROM 1 TO 100 N 12 F 1 1 TO Ni J RND 32767 iN I 15 CLS 20 P STAND BY FOR THE SHUFFLING OF THE DECK OF CARDS 21 P 22 P 30 P 40 FOR N l TO 45 50 READ A N 60 NEXT N 66 P lP iP 70 Y l 75 P SHUFFLING COMPLETED GAME CONTINUES 80 B 90 GDTG 110 100 S 35 1 1 R INT RNDI 45 120 M A R 130 IF M 0 GOTO 1 1 140 A R 150 T 0 160 FOR Z l TO 45 170 T A Z T 180 NEXT Z 185 P T 27 PRE...

Страница 213: ...at the next Rotary Club Country Fair or other ticket drawing giveaway This program uses the random number generator to pick the lucky number s and eliminate charges of stuffing the ticket box besides giving the whole affair some pizzaz If your own number comes up and you are charged with rigging the computer you re on your own 3 IN ENTER A NUMBER FROM 1 TO 100 N 4 F I 1 TD N J RND 32 76 7 N I 5 CL...

Страница 214: ... 100 100 110 120 60 REM USED FOR THE ON STATEMENT IF P l WHICH IT CAN T 100 P YOUR POINT IS NtGOTO 130 110 PRINT YOU WIN P END 120 PRINT YOU LD5E 1P 1END 130 GOSUB 300 M N 135 p t p you Rolled i a 1 and iB 140 IF P M THEN 1 10 150 IF M 7 THEN 120 160 G 130 300 A RND 6 B RND 6 N A B 1 RET 310 RETURN Fire When Ready Gridley You have probably seen this popular graphics display at your Radio Shack Sto...

Страница 215: ...0 RESET 7 43 1 140 RESET 8 43 1190 REM THIS WILL MAKE THE CANNON RECOIL 1200 FOR X l TO 100 NEXT X 1210 RESET 73 12 1220 RESET 73 13 1230 RESET 74 12 1240 RESET 74 13 1250 SET 101 12 1260 SET 101 13 1270 SET 102 12 1280 SET t 102 13 1290 FOR X l TO 100INEXT X 1300 SET 74 12 1310 SET 74 13 1320 SET 73 12 1330 SET 73 13 1340 RESET 102 12 1350 RESET 102 13 1360 RESET 101 12 1370 RESET 101 13 1500 FOR...

Страница 216: ...llment plan for the repay ment of small to moderate size loans such as car or home improvement loans The program includes all instructions necessary to using it Use it with common sense in the last payment period amounts may be carried out to a fraction of a cent Challenge modify the program to eliminate fractional cent payments without changing the total amount paid as interest or principal 10 C ...

Страница 217: ... IF THIS BOTHERS YOU WE U HAVE IT REMOVED Appendix A Subroutines B Cassette Data Files C Combined Function and ROM Test ...

Страница 218: ...hatever combina tions are useful to you Each subroutine listing has a set of instructions in the margin Study them closely You ll see that some subroutines require other subroutines for in ternal calculations You must enter these auxiliary subroutines when the instructions call for them Always enter 30000 END as a protective block when using subroutines For complete information on the use of subro...

Страница 219: ...30110 REM ALSO USES E L A B C INTERNALLY 30120 P l E 2 j IF Y T RET 30130 IF X 0 INT Y Y1 T P l 2 Y 4 INT Y 2 t X X 33140 IF XO0 T GOS 30190 t X Y L GOS 30250 32150 P P E RET 30000 END 30170 REM NATURAL COMMON LOG INPUT X OUTPUT L X 30175 REM OUTPUT L IS NATURAL LOG OUTPUT X IS COMMON LOG 30180 REM ALSO USES A B C INTERNALLY 30190 E 0 IF X 2 T P LOG UNDEFINED AT jX STOP 30195 A l i B 2 C 5 32200 I...

Страница 220: ...30350 REM COSINE INPUT X IN DEGREES OUTPUT Y 30351 REM ALSO USES W Z INTERNALLY 30360 W ABS X X X X 90 i GOS 321376 J F Z l W 1 T Y 30365 RET Sine Computes SIN X lnp t X degrees Output Y Also uses Z internally Value of X is changed Other subroutines required None How to Call GOSUB 30376 30000 END 38370 REM SIN INPUT X IN DEGREES OUTPUT Y 33371 REM ALSO USES Z INTERNALLY 30376 2 ABS X XiX Z x 303BB...

Страница 221: ... X 1 S S i IF X 0 T P Si IS OUT OF RANGE STOP 30570 W X 2 t Z 0 30580 Y X W W 2 IF Y 0 Y Z T X W G 30610 30600 W W Y i Z Y G 30580 30610 Y X X X X 6 X X X X X 075 X X X X X X X 4 464286 E 2 30620 W Y X X X X X X X X X 3 038194E 2 30625 IF ABS S 707107 T W 1 570796 W 30630 Y W 57 29578 RET ArcTangent Computes ATN X angle whose tangent is X Input x O ut v n de e3j A in ricnans Also uses B T internal...

Страница 222: ... to 1 for X negative for X zero Ifllll 1 for X positive Also uses No other variables Other subroutines required None How to call GOSUB 30810 220 30000 END 30802 REM SIGN INPUT X OUTPUT T t 0 OR 1 30810 IF X 0 T T l 30820 IF X T T 0 30830 IF X 0 T T l 30840 RET ...

Страница 223: ... your Recorder at the same time then type in the fol lowing lines and run s 50 A l B 2 jC 3 100 PRINT A B C Note the special punctuation required to separate each variable to be printed onto tape The sequence of five characters must be inserted between every two variables in a PRINT statement This program causes three things to happen 1 The Tape Recorder is automatically started assuming you have ...

Страница 224: ...ers have been read the Recorder motion is stopped Line 120 prints a reassuring message This is important when the Computer is using an external device such as a Tape Recorder Print messages are also valuable as prompting instructions to the user regarding the control of the Recorder For example before the Computer executes a PRINT statement we can have it print a message telling the user to put th...

Страница 225: ...T D TEMPERATURE TODAY T WHAT WAS THE D l THEN 160 HUMIDITY H IN IN IF P LOAD PREVIOUS TEMPERATURES AND P FIRST REWIND TAPE TO BEGINNING P THEN PRESS RECORDER S PLAY KEY IN PRESS ENTER WHEN READY A FOR X l TO D 1 INPUT Y Z B B Y C C Z NEXT X B B T D C CC H D CLS P THE AVERAGE HUMIDITIES THIS MONTH OF DATA FILE TEMPERATURE IS B THE AVERAGE HUMIDITY IS C sP NOW THE TRS 80 WILL WRITE TODAY S TEMPERATU...

Страница 226: ...when to use the RECORD PLAY and STOP keys Write a grader program that uses the data file created above to read each student s name and responses grade the test and then read the next student s test Be sure to leave time for the teacher to mark down the names and grades in his or her little black book 2 Inventory Write a program that sets up an array in which you store the following infor mation ab...

Страница 227: ... straight line distortion etc Takes hardly any time at all press Mflhl to redraw test pattern If at any point the Computer comes back with a BREAK AT will be a line number you know that one of the functions isn t performing properly ROM error In case of a RAM error BREAK message will be preceded by the message RAM ERROR If you don t get a BREAK message or an infinite loop you can relax about the T...

Страница 228: ...30 120 STOP 130 GOS 150 140 GQTO160 150 RETURN 160 ONXGOTO180 170 STOP 180 SET X Y 185 IFPOINTCX Y G 190 187 STOP 190 RESETCX Y 200 IFXOY 1STOP 210 IFY X 1G 230 220 STOP 230 Z RND 0 240 X l 1 sX INT X 245 Y ABS X 2 5 250 IFY 1G 270 260 STOP 270 REM EVERYTHING IS OK 226 ...

Страница 229: ...X 0TOA j IFA X OQP RAM ERROR sSTOP 350 N X 360 P AT68 Q iN Y jP AT0 THE RAM TEST IS COMPLETE 370 F A 1TO2500 N A 400 CLSsK l 410 A GH 420 F X 1T032 sP A N X 430 F X 1TD14 iP T 29 A N X 440 P AT 469 450 F X 1T09 P A N X sP 460 P T 21 sF X 1T09 P A i N X 470 P AT960 480 F X 1T031 sP AS N X 490 IN BS 500 IFK 0A 80 510 IF K 0A GH 520 K K 530 CLStG 420 227 ...

Страница 230: ... Peripheral Write Strobe Output 13 WR Memory Write Strobe Output 14 INTAK Interrupt Acknowledge Output 15 RD Memory Read Strobe Output 16 MUX Multiplexor Control Output for 16 Pin Dynamic Rams 17 A9 Address Output 18 D4 Bidirectional Data Bus 19 IN Peripheral Read Strobe Output 20 D7 Bidirectional Data Bus 21 INT Interrupt Input Maskable 22 Dl Bidirectional Data Bus 23 TEST A Logic 0 on TEST Input...

Страница 231: ...Notes 229 ...

Страница 232: ...Notes 230 ...

Страница 233: ...Notes 231 ...

Страница 234: ... sign Transfers program control 10 GOTO 300 to designated program line Statements Purpose Described in Example Chapters IF THEN Establishes a test point 10IFA B THEN 300 6 FOR NEXT Sets up a do loop to be executed a specified number of times 10 FOR 1 1 TO 10 10 11 20 NEXT I 13 STEP Specifies size of increment 10 FOR 1 0 TO 10 STEP 2 10 to be used in FOR NEXT loops STOP Stops program execution and ...

Страница 235: ... Chapters Is less than A B 6 Is greater than A B 6 Is equal to A B 6 Is less than or equal to A B 6 Is greater than or equal to A B 6 Is not equal to AOB 6 Logical Described in Operators Function Example Chapter s AND A 3 A 7 A equals 3 and A equals 7 24 OR A 3 B 7 A equals 3 or B equals 7 24 Variables Purpose A through Z Take on number values A and B Take on string values A X Store the elements o...

Страница 236: ...N U S A FORT WORTH TEXAS 76102 CANADA BARRIE ONTARIO L4M 4W5 TANDY CORPORATION AUSTRALIA BELGIUM U K 280 316 VICTORIA ROAD PARC INDUSTRIEL DE NANINNE BILSTON ROAD WEDNESBURY RYDALMERE NSW 2116 5140 NANINNE WEST MIDLANDS WS10 7JN PRINTED IN U S A ...

Отзывы: