11.07.2015 Views

Untitled - TRS-80 Color Computer Archive

Untitled - TRS-80 Color Computer Archive

Untitled - TRS-80 Color Computer Archive

SHOW MORE
SHOW LESS
  • No tags were found...

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

The Beginner's PageC. RegenaThe RESTORE StatementLast month we talked about READand DATA statements. A oftenused associated statement is RESTORE, which can be used withREAD and DATA. RESTORE forcesthe computer to start READing thevery first item in the first DATAstatement in the program. You thuscan reuse DATA statements if necessary. Here is a simple example:10 READ A,B,C20 DATA 2,4,3,8,2,730 PRINT A + B+C40 READ D,E50 PRINT D'E60 ENDWhen this program is run, line10 reads data (from line 20) for thevariables A, B, and C. A will equal2, B will be 4, and C will have thevalue 3. Line 30 prints the sum.Line 40 is another READ statementwhich reads the next two data itemsfor D and E. D will have the value 8and E will be 2. Line 50 prints theproduct. (Remember that you canput the DATA statement of line 20anywhere in the program and theresults will be the same.)Now add a line:35 RESTOREThis line says to restore the data, orto start the list of data items overagain with the very next READstatement. This time the values forD and E will be 2 and 4 because thedata pointer starts with the veryfirst data item in the program.Restoring DATA LinesMany versions of BASIC evenallow you to RESTORE a certaindata line. For example, RESTORE200 means "With the very nextREAD statement encountered, startthe data with the DATA statementin line 200." This feature makesprogramming with DATA statements much easier because you canmake sure the READ statementsstart with certain DATA statements. It's particularly helpful inlong programs with many DATAstatements.The RESTORE statement neednot appear right next to the READstatement. It simply resets the datapointer.Here is a way you can makeuse of DATA, READ, and RESTORE. Write a short program toread numbers for musical note values, and then play those notes.Place this in a subroutine at line900. An example for the Atari STmight be:900 FOR C = l TO X910 READ NOTE,OCTAVE920 SOUND 1,15,NOTE,OCTAVE,10930 NEXT C940 RETURNNow in your main programyou can have DATA statementscontaining numbers for musicalphrases. The variable X in this example is the number of notes in thephrase. Using RESTORE you canplay phrases more than once without retyping DATA statements. Forexample:100 X=35110 GOSUB 900120 DATA ...(numbers for music)130 DATA ...(more note numbers)140 DATA ...(more note numbers)150X = I4160 RESTORE 130170 GOSUB 9001<strong>80</strong> X=7190 RESTORE 140200 GOSUB 900210 RESTORE220 GOSUB 900230 ENDFirst, X is set to 35, and thesubroutine will read and play 35notes from the data starting at line120. Line 160 says to start the dataover beginning with line 130. Fourteen notes will be played—a chorus,for example. Line 190 then says tostart the data over with line 140 andplay 7 notes—repeating a musicalphrase. Line 210 says to restore thedata completely, or to start with thevery first line of data. The value ofX is still 7, so 7 notes will be playedand the rest of the data will beignored.Selecting Items FromA List<strong>Computer</strong>s which use line labelspermit a RESTORE to target a particular label. For example, RESTORE UTAH tells the computerthat with the very next READ statement start the data with the linelabeled UTAH. The data might beinformation used by the program todraw the state using numbers forgraphic coordinates.RESTORE is also used if youhave lots of information and thecomputer is supposed to select particular items from a list. Supposeyou have names, addresses, phonenumbers, and codes in data statements for a list of clients. You canfirst read each item and print onlythose with a certain zip code. Next,you can RESTORE the data, thenread each item, and print only thosewith a certain phone prefix. Another time you could RESTORE thedata, then read each item, and printonly those with a certain code. Youcan let the computer do the work ofsearching through information inone data list and save your havingto write several different programs.This should get you started onunderstanding programs withDATA, READ, and RESTOREstatements. You might not evenconsider yourself a beginner anymore if you can manipulate DATAstatements, but I hope to see youagain next month. ®<strong>80</strong> COMPUTEI February 1987

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!