STRINGS Strinq variables enable a programmer to store and Manipulate words in a E'-ASIC program* In this Module campers will experiment with the various string handling features of the Atari* Upon completing this module, campers will be able to write a program that converts English to Pig Latin* were originally introduced in the If you feel you need to brush up on to read the following materials* Inside Atar i BASIC t pp* 40 - 44 Your Atar i Computer I pp ♦ 64 - 65 Atar i 40 0/80 Q E'-ASIC Reference Manual t pp* 37 - 40 If you feel that any of your campers are unsure of how to dimension strings* you can use the accompanying worksheet entitled* "String Variables Worksheet*" to review initializing string variables* When you are discussing any type of variable* we recommend that you encourage your campers to use descriptive variable names* For example* NAME$ is much more meaningful to the reader than N$* Also* encourage your campers to reserve ample space for their strings in order to account for the largest conceivable input that may need to be stored in the string* String variables can be as large as you wish* as long as they will fit in the computer's memory* IE r-i =c ± r-i <3 S t- ± r~i <3: ss Indexing strings enables you to extract or change a portion of a string* Isolating a portion of a string becomes particularly useful when strings are used to hold data* Explain the format and procedure for accessing a portion of a string using an index* Campers should understand the following concepts* 1* One index in parentheses sets up a substring that includes the indexed element of the string to the last elemert of the original string* An example of using a single index is listed below* The program prints M LF"' on the screen* Copyright Atari* Inc* 1983* All rights reserved* 1 - String variables module on variables* strings* you may want INDEXING STRINGS < Continued ) DIM WORD$(10) WORD$ = "HELP" PRINT W0RD$(3) LP 2* Two indices in parentheses can be used to isolate any one element, or a group of elements, in a string* A ssnple program using two indices is listed below* DIM WORD$<20> WORD* = "ATARI CAMP PRINT W0RD$<2,9> TARI CAM PRINT WORD$(7*10) CAMP PRINT W0RD$<2,4) TAR Acti vi ty ♦ 1 1 « Have the csnpers type In the following progran* Canpers should insert their own nawe in quotes on line 40* Discuss what happens to the substring that is printed on the screen each tine the index in parentheses is incremented ♦ 10 REM * INDEX TO A STRING - 20 REM 30 DIM NAME$<30) 40 NAME$ = "GEORGE WASHINGTON 50 PRINT NAME$ ( 1 ) 60 PRINT NAME*<2) 70 PRINT NAME$ ( 3 ) 2* Have the campers change the index* so that only the last letter in their name is printed on the screen* xxx Leave the NAMES program in memory for the next activity* Copyr ight Atari* Inc. 1983* All rights reserved* INDEXING STRINGS ( Continued ) Activity *2 This progran exenplifies how to isolate 3 substring by using two indices* 1* Edit the NAME* progran currently in nenory by typing in the three additional lines listed below* Ask the canpers to predict what will be printed on the screen* 2* Have the canpers edit the progran to print their initials* Act i v i ty *3 1# A variable can be used in the place of an index to a string* For exanple* the variable COUNT represents an index of three in the program below* Using a variable enables you to change the index without repeating the string statement* This is particularly useful when you W3nt to ex tract one element of a string at a tine* In the progran below* canpers will print their name in big letters on the screen* By using a variable index* they will be able to print one letter of their nane at a tine* A delay loop holds the current letters on the screen before the next letter is printed* Without the delay loop it would appear as though all the letters were printed on the screen at the sane 50 60 70 PRINT NAME* ( 1*1) PRINT NAME*<1*3> PRINT NAME$<5*5) COUNT = 3 NAME$ = "ROBERT" PRINT NAME$(C0UNT*6) BERT Copyright Atari* Inc* 1983* All rights reserved* 3 INDEXING STRINGS ( CONTINUED ) tine* Note that the counter (LETTER) to the FOR ♦ ♦ ♦ Next loop is also used to increment the position of where the next letter will be printed* Have the canpers type in the program listed below* Be sure that they insert their own nane on line 140 and the number of letters in their nane on line 150* 100 REM * VARIABLE INDEX 110 REM * 120 GRAPHICS 2+16 130 DIM NAME*<20> 140 NAME* = "JOHN JONES" 150 LENOFNAME = 10 160 FOR CHAR = 1 TO LENOFNAME 170 POSITION CHAR+3*5 180 PRINT *6;NAME$(CHAR,CHAR) 190 FOR DELAY = 1 TO 500 * NEXT DELAY 200 NEXT CHAR 2* Have the caMpers experinent with printing their full nane on the screen, printing their nane on a diagonal • etc* Challenge the canpers to print the letters of their nane in the reverse order* This can be done by using the following FOR ♦ ♦ NEXT loop on line 160* FOR CHAR = LENOFNAME TO 1 STEP -1 Activity *4 1* It is also possible to alter a portion of s* string by using indices* In the example below* new letters are being assigned to the 10th through the 13th elenent of the SOUP AND SALAD string* Ask the canpers to predict what the program listed below will print on the screen* before to typing it into the computer* Have then RUN the progran to test their hypotheses ♦ 10 REM * A SUBSTRING SWITCH 20 REM x 30 DIM LUNCH*(2Q> 40 LUNCH* = "SOUP AND SALAD" 50 PRINT LUNCH$ 60 LUNCH* < 10 , 13) = "BREA" 70 PRINT LUNCH* Copyright Atari* Inc ♦ 1983* All rights reserved* 4 INDEXING STRINGS < Continued ) 2 ♦ Ask the canpers to edit the progran to print SOUP A LA CARTE* They will need to change the indices, as well as the substring in line 60* Copyright Atari, Inc. 1983* All rights reserved* G c:> r* ■ «{.::: o 1:, €E* r~n -fc. il i~i <"jfc S "t i c~b «cj 50 PRINT "TYPE IN A WORD" \ 60 INPUT WORD* 70 PRINT "THERE ARE " J LEN ( WORD* ) J " LETTERS IN YOUR WORD* 2» The canpers should be able to explain why there are seni-colons used in line 70, and why there is a space enclosed in quotes following the word "are" and before the word "letter". RUN the program* 3* Have the students RUN the progran a second tine* This tine, type 5 spaces and then type the word* Use the sane word both tines* Ask you canpers if the progran reported the sane nunber of letters for the word both tines* xxx Leave the progran in nenory so that it can be edited in the next activity* Copyright Atari* Inc* 1983* All rights reserved* 7 Explain how to compare strings in BASIC* Emphasize the fact that the strings being compared must be identical » Upper and lower case letters do not natch* YES followed by a space does not natch a YES response with no spaces before or after it* Activity i 1 1* The students should edit the LEN function program by typing in the following lines* 20 REM * STRING COMPARISON 40 DIM WQRD$<20 ) , ANSWER$(3) 80 PRINT "WOULD YOU LIKE TO KNOW HOW LONG 90 PRINT "ANOTHER WORD IS" J 10 0 INPUT ANSWERS 110 IF ANSWER*="YES" THEN GOTO 50 2* Have the students RUN the program and experiment with the following responses* NO* Yes* YES * and MAYBE 3* One way to avoid errors or confusion on the part of the user giving a response is to dimension ANSWERS with one character and ask for a "Y" or "N" response* Then the comparison will be made with the first letter of the response regardless of what the user types in* YES* YEP* and Yes will all be treated as "yes*" Note how ANSWERS is dimensioned to one character in the following program* Activity |2 1* Now use indices* substrings ♦ concatenation* and LEN to write words in Pig Latin* Pig Latin takes the first letter of a word, moves it to the end of the word and adds an "ay" on the end* The students should fill in the missing information in the program listed below and type it into the comp uter ♦ Copyright Atari* Inc * 1983* All rights reserved* 8 10 REM * FIG LATIN 2 0 rem * 30 DIM WORD* < 20 ) * ANSWER** < 1 ) » GUAR* ( 1 ) 40 PRINT " TYPE IN A WORD" J 50 INPUT 55 PRINT 60 LEINGTH ■ (WORD*) 70 CHAR* = WORD*( , ) I REM CHAR* IS ASSIGNED THE FIRST ELEMENT OF WORD* 80 PRINT "THERE ARE " }" LETTERS IN YOUR WORD." 85 PRINT 90 PRINT WORD*(2)J ,M AY IS YOUR WORD IN PIG LATIN." 95 PRINT 100 PRINT "WOULD YOU LIKE TO KNOW ANOTHER WORD" 110 PRINT "IN PIG LATIN? (TYPE Y OR N.)" 115 PRINT 120 INPUT 130 IF ANSWER* = "Y" THEN GOTO 40 Copyright Atari. Inc. 1983. All rights reserved. 9 I R O O R A M M X N! 13 C II I _ I E M G E S U S3 IC M G s t i 3: m s 1 ♦ Write an entire Message in Pig Latin* Have a user type in a Message in English and you print the Message in Pig Latin* E'.e sure to reserve enough space in a string to input a very long Message, in case the user is extrenely verbose* Starting with the first letter of the Message, cOMpare each eleMent of the string to a space in order to find the break between each word* Each tine you encounter a space* convert the previous word to Pig Latin* print in on the screen* and read on* The following EiJASIC code May prove to be useful to you ♦ FOR LETTER ■ 1 TO LENGTH CHAR* = MESSAGE* (LETTER* LETTER) IF CHAR* <> M 11 THEN WORD* ( INDEX * INDEX ) ■ CHAR* INDEX = INDEX + 1 NEXT LETTER PRINT WORD* (2) J * * * 2* Devise your own secret code* Write a prograM that converts a Message typed into the coMputer into your secret code* One technique for writing a secret code is to switch letters for other letters in the alphabet* For exaMple* all the "A's" could be converted to "Z's*" Be creative* 3* Write a prograM that juMbles up the letters in a word* The juMbled word is printed on the screen* The user is asked to guess what the word is and type the letters of the word in their correct order* Give the user additional guesses for incorrect responses* Copyright Atari ♦ Inc* 1983* All rights reserved* 10 S T Ffc X IM G S CAMPER COPY oxo String Indexing Prograns «no 10 REIM * INDEX TO A STRING 2 0 REIM 30 DIM NAME:$(30) 40 NAME* = 11 GEORGE WASHINGTON" 50 PRINT NAME$<1) 60 PRINT NAME:* (2) 70 PRINT NAME$<3) 50 PRINT NAME$< 1,1) 60 PRINT NAME$( 1,3) 70 PRINT NAME$(5,5) 100 110 120 130 140 150 160 170 180 190 200 REIM * VARIABLE INDEX REIM * GRAPHICS 2+16 DIM NAME* (20) NAME* = "JOHN JONES" LENOFNAME = 10 FOR CHAR = 1 TO LENOF r NAME POSITION CHAR+3,5 PRINT *6JNAME$( CHAR, CHAR) FOR DELAY - 1 TO 500 : NEXT DELAY NEXT CHAR 10 REM * A SUBSTRING SWITCH 2 0 REM * 30 DIM LUNCH$(20) 40 LUNCH$ = "SOUP AND SALAD" 50 PRINT LUNCH* 60 LUNCH* CIO ,13) = "BREA" 70 PRINT LUNCH* Copyright Atari, Inc* 1983* 11 All rights reserved* S T R 31 M G S3 Canper Copy Continued xxxxx Concatenation ProgrsMS xxxxx 10 REM x STRING CONCATENATION 20 REM x 30 DIM PREFIX* (10), ROOT* (10) 40 PREFIX* = "TELE" 50 ROOT* = "VISION " 60 PRINT PREFIX* J ROOT* 10 REM x CONCATENATE A SUBSTRING 20 REM x 30 DIM ORIGINAL*( 10 ) , EXTENSION* ( 1 0 > 40 ORIGINAL* = "TELEPHONE" 50 EXTENSION* » "GRAPH" 60 0RIGINAL*<5,9) = EXTENSION* 70 PRINT ORIGINAL* xxxxx LEN Function Prograns xxxxx 10 REM x THIS PROGRAM DEMONSTRATES 20 REM x THE LEN FUNCTION 30 REM x 40 DIM WORD*(20) 50 PRINT "TYPE IN A WORD" i 60 INPUT WORD* 70 PRINT "THERE ARE " J LEN ( WORD* ) J " LETTERS IN YOUR WORD," Copyright Atari, Inc. 1983. All rights reserved. 12 S T r C I! t i G S Cstiper Copy G o n t i ft u e d xxxxx CoMp3ring Strings xxxxx 20 REM x STRING COMPARISON 80 PRINT " WOULD YOU LIKE TO KNOW HOW LONG" 90 PRINT "ANOTHER WORD IS" J 100 INPUT ANSWER* 110 IF ANSWER*="YES" THEN GOTO 50 xxxxx Pig Latin Program xxxxx 10 REM * PIG LATIN 20 REM * 30 DIM WORD*(20 ) ,ANSWER*( 1 ) ,CHAR*( 1 ) 40 PRINT "TYPE IN A WORD" J 50 INPUT 55 PRINT 60 LENGTH = (WORD*) 70 CHAR* = WORD*( , KREM CHAR* IS ASSIGNED THE FIRST ELEMENT OF WORD* 80 PRINT "THERE ARE "J '," LETTERS IN YOUR WORD." 85 PRINT 90 PRINT W0RD*<2>; J "AY IS YOUR WORD IN PIG LATIN." 95 PRINT 100 PRINT "WOULD YOU LIKE TO KNOW ANOTHER WORD" 110 PRINT "IN PIG LATIN? (TYPE Y OR N . ) " 115 PRINT 120 INPUT 130 IF ANSWER* = "Y" THEN GOTO 40 Copyright Atari, Inc. 1983. All rights reserved. 13 TRING VARIABLE RE VXEW WORKSHEET String variables Must first be dimensioned with a DIM instruction* The dimension statement determines the maximum number of characters which can be held in the string* 1« Type in the following program and RUN it to see what happens ♦ 10 REM x A PROGRAM TO DEMONSTRATE 20 REM x THE DIM FUNCTION ♦ 30 REM * 40 DIM FRUIT*<5) 50 FRUIT* = "APPLE" 60 PRINT FRUIT* 2* Note that the word being assigned to the string must be in quotes* If you change APPLE to BANANA * what will be printed on the screen? \ Try it and see* 3* A string variable can contain any combination of letters* numbers* spaces* and symbols* Also* the contents of a string can be assigned from within a program or from input* Type in the following program* 10 REM x THIS PROGRAM DEMONSTRATES 20 REM x THE VARIOUS POSSIBLE ELEMENTS 30 REM x OF A STRING FROM INPUT* 40 REM x 50 DIM TIME$(40) 60 PRINT "WHAT TIME IT IT"; 70 INPUT TIMES 80 PRINT "IT'S M J TIME$J 41 ! I'M LATE! BYE*" 3* When you are asked what time it is, type in 10:30 am* and RUN the program* 5« What would be printed out if your typed in ten-thirty? Try it and see* Copyright Atari* Inc* 1983* All rights reserved* 14 r> nr & #. This nodule introduces three BASIC statements* READ* DATA* and RESTORE enable 3 programmer to assign values to variables More efficiently than the individual variable assignments presented thus far* Reading and storing data ar explained* and campers can experiment with various types of data* After completing this module* campers should be familiar with how to write versatile programs that systematically read data and check for the last data entry* Before participating in the activities in this module* campers must understand the difference between a numeric and a string variable* The participants also must have had experience programming SOUND on the Atari* If you are unfamiliar with the READ* DATA* or RESTORE statements* they are explained in the following books* Inside Atari BASIC ♦ pp* 60-63 Your Atar i Computer * pp* 76-78 Re-a=dl and Data 1* In order to familiarize campers with the READ and DATA statements* start by writing a simple program on the board like this one* 10 REM * READ DATA DEMO 20 REM * 30 DIM DAY*<20> 40 NUMOFDAYS = 7 50 PRINT 60 FOR DAYOFWEEK = 1 TO NUMOFDAYS 70 READ DAY* 80 PRINT DAY* 90 NEXT DAYOFWEEK 100 DATA SUNDAY* MONDAY* TUESDAY 110 DATA WEDNESDAY* THURSDAY* FRIDAY 120 DATA SATURDAY 2* Explain the format and function of the READ and the DATA statements* A READ statement enables a programmer to retrieve values from a list of data* Copyright Atari* Inc* 1983* All rights reserved* 1 FcEI^O bi D DATA ( Continued ) The DATA st3tefient allows the programmer to store large quantities of data ef f iciently ♦ Note that each elenent of data is separated by a comm3* Even though we are assigning a word to the string variable DAY*, no quotation Marks are needed in the list of data* 3* Explain that the READ statement looks for the first ■•unread" eleMent of data* The concept of a "pointer" should be explained here* The conputer Maintains a pointer that points to the next data iteM to be READ* Each tine an eleMent of data is read* the pointer is advanced to the next eleMent of data* 4* READ stateMents are custoMarily used in a loop* In this exaMple* we are using a FOR ♦ ♦ NEXT loop* When a FOR ♦ ♦ NEXT loop is used* the nunber 'of tiMes the loop is to be executed Must correspond to the quantity of data* If a READ statenent is executed and all of the data has been read* you will get an error Message* 5* Step through the prograM and execute each instruction just as the coMputer would* Write each DAY* on the board as you execute the PRINT DAY* instruction* Each tiMe an eleMent of data is read* the "pointer" is advanced to the next data* Use your pencil to point to the data to be read as you step through the prograM* Call the caMpers' attention to the fact that data can appear on More than one line* The coMputer's pointer autoMatical ly advances to data on the next line* DATA lists are always read in the order of their line nuMber * froM the lowest to the highest* Activity *1 1* Have the caMpers type in the days of the week prograM listed below* • 10 REM * READ DATA DEMO 20 REM x 30 DIM DAY*<20> 40 NUMOFDAYS = 7 50 PRINT 60 FOR DAYOFWEEK = 1 TO NUMOFDAYS 70 READ DAY* 80 PRINT DAY* 90 NEXT DAYOFWEEK 100 DATA SUNDAY, MONDAY, TUESDAY 110 DATA WEDNESDAY, THURSDAY, FRIDAY 120 DATA SATURDAY Copyright Atari, Inc. 1983. All rights reserved. 2 FC EI iAi D At M D DATA ( Continued ) 2« Cafipers should RUN the progran to see what is printed on the screen* Have the campers change the NUMQFDAYS assignment to NUHOFDAYS m 2* RUN the program again to see what happens* Then have the campers assign 8 days to the NUMOFDAYS variable* Once again* RUN the program to see what happens* Activity * 2 1* A conditional statement* such as IF ♦ ♦ THEN* also can be used to set up a loop to read data* A GOTO* intructs the computer to re-execute a set of instructions until the IF * ♦ THEN condition is met* The IF ♦ ♦ THEN statement searches for the "flag" at the end of the list of data* The flag is an unlikely element of data that has been placed at the end of the data list to indicate that there is no more data* The IF ♦ ♦ THEN statement checks each element of data that is READ and when the flag is encountered* the loop is terminated* In the following activity* the word "FINISH" has been placed at the end of the list of days to serve as a f lag* 210 DATA SATURDAY * 7TH * FINISH When FINISH is READ* the program ends* You may want to take this opportunity to point out to the campers that using a conditional statement with a "flag" makes a program more versatile* The data can be changed or replaced with another set of data* and the program will still work* as long as the flag is the last element of data* 2* More than one variable can be READ from a list of data* The program below shows how two string variables can be assigned values from the same DATA statement* Explain to the students that the pointer continues to advance to the next element of data each time a READ instruction is executed* regardless of which variable is being assigned a value* Have the campers type in the program listed below in order to experiment with the instructions* This time* a conditional loop is used with a flag* Copyright Atari* Inc* 1983* All rights reserved* 3 t^t-to r> x ( Cont i nued ) 100 REM * TWO STRING VARIABLES 110 REM * 120 DIM DAY*<15> ,ORDER*<10> 130 PRINT 140 READ DAY* 150 IF DAY* 5 *" FINISH" THEN END 160 READ ORDER* 170 PRINT DAY*?" IS THE " i ORDER* J " OF THE WEEK." 180 GOTO 140 190 DATA SUNDAY, 1ST, MONDAY, 2ND. TUESDAY, 3RD 200 DATA WEDNESDAY, 4TH, THURSDAY, 5TH, FRIDAY, 6TH 210 DATA SATURDAY, 7TH, FINISH 220 END If the campers' output from this prograM looks odd, remind then to check their spacing on line 170* Note that when DAY* was compared with the FINISH flag on line 150, FINISH was in quotes* When a string is compared with a word, the word Must appear in quotes* Have the campers type " .FINISH" at the end of line 190* Line 190 should look like this after it has been edited* 190 DATA SUNDAY, FIRST, MONDAY, SECOND, TUESDAY, THIRD, FINISH Ask then to predict what the program will print before RUNing it* Then insert a space before the word FINISH on line 190 and see what happens* 190 DATA SUNDAY, FIRST, MONDAY, SECOND, TUESDAY, THIRD, FINISH t Ask the campers to explain why "FINISH" did not end the program this time* Copyright Atari, Inc. 1983* All rights reserved* FCEI^O AND DAT" A < Continued ) Activity *3 READ stateMents can be used to assign values to nuneric variables as well* In fact, one DATA list can hold both nuweric and string data* Ask the canpers to type in the prograM listed below* Each canper should list the nanes of each Member in his or her family and the person's age* separated by coMhas* on line 190-200* Since there is no way of knowing how Many people there are in each caMper's fanily and therefore no way of knowing how Much data will be listed on lines 190-200* a different kind of loop for reading the data is used* This tine the TRAP instruction is used. Before to beginning the READ ♦ ♦ DATA loop, a TRAP is set to avoid an M 0UT OF DATA 11 error Message* When the READ stateMent on line 150 is executed* if there is no data left* ordinarily the prograM would stop and you would get an error Message* By using the TRAP 210 instruction* we can trap that error and redirect the coMPuter to continue with the instruction listed on line 210* Explain this third Method of reading data, and have the caMpers experiMent with the prograM listed below* 100 REM x TRAPPED DATA 110 REM * 120 DIM PERSQN*<20> 130 PRINT 140 TRAP 210 150 READ PERSON* 160 READ AGE 170 PRINT PERS0N$; M IS *JAGET* YEARS OLD ♦ 11 180 GOTO 140 190 DATA MARGIE * 47 * JOHN ♦ 50 ♦ BETH * 12 200 DATA 210 END Copyright Atari* Inc* 1983* All rights reserved* 5 RESTORE Activity *1 READ and DATA statements are commonly and quite conveniently used to play music on the Atari ♦ The values for the voice, pitch, distortion, and/or loudness of the note can be stored as DATA and read as the tune is played* In this activity the RESTORE command is introduced in a program that plays music* Campers will use the RESTORE instruction to reset the pointer to the beginning of a list of SOUND data, so that the tune will be replayed* Explain the RESTORE instruction to the campers* RESTORE resets the data pointer back to the first element of DATA listed in the program* (It is also possible to give a line number in the RESTORE instruction in order to redirect the pointer to a specific set of DATA* This will be discussed in the next activity*) You also may need to briefly review the four components of the SOUND command* In the following program four values are being READ from DATA: PITCH, DISTORTION, LOUDNESS, and TIME* TIME indicates the length of the delay between each note* The voice is always zero* A minus one is used as a flag at the end of the DATA* Have the campers type in the program listed below* 100 REM * MUSIC 110 REM * 120 READ PITCH, DISTORT, LOUD, TIME 130 IF TIME - -1 THEN GOTO 210 140 SOUND 0, PITCH, DISTORT, LOUD 150 FOR DELAY = 1 TO TIME t NEXT DELAY 160 GOTO 120 170 DATA 121,10,10,40,91,10,10,37 180 DATA 0,0,0,3,91,10,10,40,108,10,10,28 190 DATA 0,0,0,2,108,10,10,10,91,10,10,30 200 DATA 108,10,10,10,121,10,10,80,0,0,0,0,-1 210 END Note that the three variables being read can be listed with one READ instruction on line 120* RUN the program to hear the little tune* Copyright Atari » Inc« 1983* All rights reserved. 6 restore: ( Continued ) Explain how to insert the RESTORE instruction on line 130 in order to repeat the tune* The edited fornat for line 130 appears below* 130 IF TIME = -1 THEN RESTORE: GOTO 120 RUN the edited program* To stop the prograM and turn off the sound* you Must press SYSTEM RESET because the progran is in an infinite loop* After this activity* you nay never want to teach the READ* DATA* and RESTORE instructions using Music in a classrooM with 12 coMputers again* Activity *2 This next activity gives the caMpers an opportunity to experiwent with a More lengthy prograM that uses the READ* DATA* and RESTORE stateMents* Explain to the caMpers that READ and DATA stateMents can go anywhere in a prograM* If the prograM is quite short* or if there is only one set of data used repeatedly froM various places in the prograM* we reconnend that the DATA be placed at the end of the prograM* Otherwise* the DATA should follow soon after the READ stateMent for prograM clarity* Giving the DATA line nunber in the RESTORE coMMand enables the prograMMer to dictate which part of the data the pointer will be restored to* So if a RESTORE instruction reads* RESTORE 400* the data pointer is reset to the first eleMent of data appearing on line 400* The following prograM is the beginning of an interactive art show* The person using the prograM selects froM a list of snail pictures to Make a scene on the screen* The prograM uses the READ and DATA stateMents to draw the little pictures on the screen* The coordinates for each iMage are stored in separate DATA lists* The READ stateMent reads each set of coordinates to be used by the DRAWTO instruction on line 270* This is a very efficient way of storing coMputer illustration data* The RESTORE instruction is critical in this prograM* Once a shape has been selected by the prograM user* the RESTORE instruction is used to set the data pointer to the specific set of coordinates needed to draw the shape * Copyright Atari* Inc* 1983* All rights reserved* 7 F"C E S T O Fx E ( Continued ) Note how the RESTORE command is used to control which list of data is being READ* Since the READ statement on line 250 reads both X and Y, two flags are required at the end of the list of DATA* Otherwise the READ statement on line 250 will continue to look for DATA for Y before it will check for the flag on line 260* If there is no More DATA left, you will get an Out of DATA Error* Ask the campers to explain why a TRAP instruction cannot be used to end the READ loop in lines 230 or 280* Have the campers predict what would happen if the line numbers were removed from the RESTORE commands in lines 150-170 ♦ Copyright Atari, Inc* 1983* All rights reserved* 8 RESTORE ( Continued) 100 REM x ART SHOW 105 REM x 110 MENU=90 0:REM MENU LINE NUMBER 115 GRAPHICS 7 t COLOR 3 120 REM x 125 REM xxxxx MAIN LOOP xxxxx 130 GDSUB MENU 140 INPUT RESPONSE 150 IF RESP0NSE<1 OR RESPONSES THEN 140 160 IF RESPONSES THEN RESTORE 500 170 IF RESP0NSE=2 THEN RESTORE 600 180 IF RESPONSES THEN RESTORE 700 190 IF RESPONSES THEN RESTORE 800 200 REM x 210 REM xxxxx DRAW ROUTINE xxxxx 220 REM x 230 READ X,Y 240 plot x,y:rem PICTURE START POINT 250 READ X,Y:REM GET DRAWTO DATA 260 IF X=-l THEN 130JREM THE FLAG? 270 DRAWTO X,Y §GOTO 250JREM GET MORE DATA REM x REM xxxxx MOUNTAIN xxxxx 510 REM x 520 DATA 0,26,12,20,20,23,30,18,35,12,42,13,45, 10,58,6 530 DATA 62,3,70,1,82,3,90,8,102,20,112,26,120,23 540 DATA 130,38,135,36,150,43,-1,-1 550 REM x 600 REM xxxxx BARN xxxxx610 REM x 610 REM x 620 DATA 43,50,43,46,47,46,47,50,40,50 630 DATA 40,44,45,41,50,44,50,50,40,50,-1,-1 64 0 REM x 700 REM xxxxx STAR xxxxx 710 REM x 720 DATA 128,10,127,11,126,11,127,12,126,13,127,13,128,14,129,13 730 DATA 130,13,129,12,130,11,129,11,128,11,128,14,-1,-1 740 REM x 800 REM xxxxx HORSE xxxxx 810 REM x 820 DATA 52 , 47 , 54 , 46 , 54 , 45 , 54 , 50 , 54 , 48 , 57 , 48 , 58 , 47 , 57 , 48 , 57 , 50 , -1 , -1 90 0 REM x 910 REM xxxxx MENU xxxxx 920 REM x 930 PRINT 940 PRINT "1. MOUNTAIN 3. STAR" 9Mk PRINT "2. BARN 4. HORSE" PRINT "WHICH PICTURE (1, 2, 3, OR 4) "J 970 RETURN Copyright Atari, Inc. 1983. All rights reserved. 9 PROGRAMMING CHALLENGES U <3 HI M G READ * OA T A #. AMD RESTORE It Write 3 progrsM that lists the necessary values for a song in DATA statements* Use the RESTORE command to repeat the chorus of the song in between the verses* 2. Add pictures to the ART SHOW program* 3* Set up a PLOT subroutine like the DRAWTO subroutine in the ART SHOW program* Add a plotted image to the list of pictures one can put on the screen* For example* offer to draw stars and PLOT tiny dots in the sky using READ and DATA statements* Allow the user to draw the shapes anywhere on the screen* For example* when a person selects the barn* ask for the coordinates of the cabin's location on the screen* Be sure to tell the user the range of possible coordinates when asking for INPUT* Then add the person's coordinates to the DATA coordinates in the DRAWTO statement (DRAWTO X+XCOQR* Y+YCOOR) ♦ This way the person can put as many barns on the screen as he or she wants as well as put them anywhere in the picture* 5* Draw the shapes in different colors* Store the color of the shape as the first element of the shape data* READ the value into the COLOR instruction before drawing the image* 6* Experiment with combining different graphic modes* colors* sounds* etc* into a little show using the READ* DATA* and RESTORE statements* Copyright Atari* Inc* 1983* All rights reserved* 10 Fv FZ A O , DATA ^ AND RESTORE CAMPER COPY xxxxx Read DATA Deno xxxxx 10 REM * READ DATA DEMO 20 REM x 30 DIM DAY*<20> 40 NUMOFDAYS = 7 50 PRINT 60 FOR COUNTER = 1 TO NUMOFDAYS 70 READ DAY* 80 PRINT DAY* 90 NEXT COUNTER 100 DATA SUNDAY, MONDAY, TUESDAY 110 DATA WEDNESDAY > THURSDAY, FRIDAY 120 DATA SATURDAY xxxxx READ Two String Variables xxxxx 100 REM x TWO STRING VARIABLES 110 REM x 120 DIM DAY*<15) ,ORDER*<10> 130 PRINT 140 READ DAY* 150 IF DAY*="FINISH" THEN GOTO 220 160 READ ORDER* 170 PRINT DAY* J " IS THE "J ORDER* J" OF THE WEEK." 180 GOTO 140 190 DATA SUNDAY, FIRST, MONDAY, SECOND. TUESDAY, THIRD 200 DATA WEDNESDAY, FOURTH, THURSDAY, FIFTH, FRIDAY, SIXTH 210 DATA SATURDAY, SEVENTH, FINISH 220 END 190 DATA SUNDAY, FIRST, MONDAY, SECOND, TUESDAY, THIRD, FINISH 190 DATA SUNDAY, FIRST, MONDAY, SECOND, TUESDAY, THIRD, FINISH T Copyright Atari, Inc. 1983. All rights reserved. 11 READ ^ DATA* AND RESTORE CAMPER COPY CONTINUED- xxxxi Trapped DATA xxxxx 100 REM * TRAPPED DATA 110 REM * 120 DIM PERSON* (20) 130 PRINT 140 READ PERSON* 150 TRAP 210 160 READ AGE 170 PRINT PERSON* J " IS " > AGE J " YEARS OLD," 180 GOTO 140 190 DATA MARGIE, 47, JOHN, 50, BETH, 12 200 DATA 210 END xxxxx Music xxxxx 100 REM x MUSIC 110 REM x 120 READ PITCH, DISTORT, LOUD, TIME 130 IF TIME ■ -1 THEN GOTO 210 140 SOUND 0, PITCH, DISTORT, LOUD 150 FOR DELAY = 1 TO TIME 5 NEXT DELAY 160 GOTO 120 170 DATA 121,10,10,40,91,10,10,37 180 DATA 0,0,0,3,91,10,10,40,108,10,10,28 190 DATA 0,0,0,2,108,10,10,10,91,10,10,30 200 DATA 108,10,10,10,121,10,10,80,0,0,0,0,-1 210 END Copyright Atari, Inc. 1983. All rights reserved. 12 F C E: t-'-i O , O/^TA^ t^t It H> RESTORE CAMPER COPY CONTINUED 100 REM x ART SHOW 105 REM x no menu=?oo:rem menu line number 115 GRAPHICS 7 * COLOR 3 120 REM x 125 REM xxxxx MAIN LOOP xxxxx 130 GOSUB MENU 140 INPUT RESPONSE 150 IF RESP0NSE<1 OR RESPONSES THEN 140 160 IF RESPONSES THEN RESTORE 500 170 IF RESP0NSE=2 THEN RESTORE 600 180 IF RESP0NSE=3 THEN RESTORE 700 190 IF RESPONSES THEN RESTORE 800 200 REM x 210 REM xxxxx DRAW ROUTINE xxxxx 220 REM x 230 READ X,Y 240 PLOT X,Y:REM PICTURE START POINT 250 READ X,Y:REM GET DRAWTO DATA 260 IF X=-l THEN 130 J REM THE FLAG? 270 DRAWTO X,Y 4B0 GOTO 250 : REM GET MORE DATA |0 REM x 00 REM xxxxx MOUNTAIN xxxxx 510 REM x 520 DATA 0,26,12,20,20,23,30,18,35,12,42,13,45,10,58,6 530 DATA 62,3,70,1,82,3,90,8,102,20,112,26,120,23 540 DATA 130,38,135,36,150,43,-1,-1 550 REM x 600 REM xxxxx BARN xxxxx610 REM x 610 REM x 620 DATA 43,50,43,46,47,46,47,50,40,50 630 DATA 40,44,45,41,50,44,50,50,40,50,-1,-1 640 REM x 700 REM xxxxx STAR xxxxx 710 REM x 720 DATA 128, 10 ,127, 11 , 126, 11 , 127 , 12 , 126 , 13 , 127 , 13 , 128 , 14 , 129 , 13 730 DATA 130,13,129,12,130,11,129,11,128,11,128,14,-1,-1 740 REM x 800 REM xxxxx HORSE xxxxx 810 REM x 820 DATA 52,47,54,46,54,45,54,50 ,54,48,57,48,58,47,57,48,57,50,-1 90 0 REM x 910 REM xxxxx MENU xxxxx 920 REM x 930 PRINT 940 PRINT "1. MOUNTAIN 3* STAR" tO PRINT "2, BARN 4. HORSE" 0 PRINT "WHICH PICTURE (1, 2, 3, OR 4) "} 970 RETURN Copyright Atari, Inc. 1983. All rights reserved. 13 fZT" III" jHS. "'v" CZt Arrays enable s progranfier to store and Manipulate large quantities of information systematically and efficiently* Arrays are one of the more complex features of Atari BASIC* and it may take some practice for your campers to fully understand them* You may find that you need to spend time drawing representations of arrays and stepping through programs on the board more than you have in previous modules* One objective of this module is to help campers to recognize programming problems that are well-suited to using an array* In this module the campers will use an array to reverse the order of a list of numbers and to write and store a musical tune* To do this module you will need a chalk board or large pieces of chart paper and felt tip pens to map out arrays* If you feel unsure of how to use an array in a program or you would like to see more examples of arrays* you may want to look over the following references* ATARI 4Q0/80Q E'.ASIC Reference Manual: pp* 3* ^1-^3 Inside Your Atari* pp* 66-7^ Your ATARI Computer* pp 65-67 An array can be thought of as a series of boxes* each of which holds one numeric value* The following is an example of an array* i i I 2 I l_„l 161 | r?~i i„_i 133 I l„_l I 0 | An array is a group of numeric variables that have something in common* The values in the array* for example* can be students' scores on a test or the number of raffle tickets each teacher sold for the school bake sale* Once you have stored the values in an array* you can do all kinds of calculations on the numbers* Copyright Atari* Inc» 1983* All rights reserved* 1 ARRAYS (Continued) An array of swiMMers' tines in a race could be called SWIMMER* Each nunber in the SWIMMER array is called an "element" of the array* An index is used to identify which elefient of the SWIMMER array or which swinMer you are referring to* For exaMple* in the array below* SWIMMER(l) swan the race in three Minutes* SWIMMER(^) took five Minutes ♦ SWIMMER(l) SWIMMER(2) SHIMMER ( 3 ) SWIMMERS) I 3 | I I I 4 I I I I 6 | I I I 5 | Just as we Must reserve space in MeMory for a string* MeMory Must be reserved for an array* You use the DIM stateMent to dimension the m a x i m u m nuMber of boxes or elenents your array could possibly need* DIM SWIMMER<25) enables the prograMMer to store up to 25 eleMents or swiM tines in the SWIMMER array* DIM SWIMMERC25) SWIMMER(l) SWIMMER < 2 ) ♦ SWIMMER ( 10 ) ♦ ♦ SWIMMER(20) ♦ SWIMMERC25) As long as there is sufficient rooM in MeMory* there i no restriction on the size of an array that can be stored* Copyright Atari, Inc* 1983* All rights reserved* ARRAYS < Continued ) Values are stored in an array by specifying the nawe of the array and the index of the element* For example ♦ SWIMMER<1)=3 assigns a value of 3 to the first element of the SWIMMER array or swinner nunber one* SWIMMERC3) = 6 assigns a 6 to the third element of the SWIMMER array, swinner nunber three ♦ SWIMMER(l) SWIMMER(2) SWIMMER(3) SWIMMERS) I 3 | I I I 4 I I I I 6 | I I I 5 I The index to an array can contain a numeric value or variable nane* For exanple* the third element of the SWIMMER 3rray is assigned a 6 in the code below as well* NUM ■ 3 SWIMMER NUMBER ( 1 ) NUMBER(2)=11Q > NUMBER (2) NUMBER (3) NUMBER ( 4 ) NUMBER < 5) Ask cahpers to suggest the numbers to be stored in the array* Assign the value to the element of the array (NUMBER(3)=98) before filling the box in the array* 3* Ask the cawpers how they night go about printing one of these values in the array on the screen* Write out the cownand on the board as it is given* For example* PRINT NUMBER ( 1 ) or PRINT NUMBER < 2 ) ♦ Be sure the csMpers understand the difference between PRINT 2 and PRINT NUMBER < 2 ) ♦ Explain that a variable nane can be used as an index to an array* as was explained in the introduction to this Module* Denonstrate the use of a variable as an index when using a FOR ♦ ♦ NEXT loop to PRINT out all of the elements of an array* A sanple listing of the code appears below* MAXNUMS = 5 FOR ELEMENT = 1 TO MAXNUMS PRINT NUMBER (ELEMENT) NEXT ELEMENT Write this subroutine on the board alongside a series of boxes holding the elements of the NUMBER array* Step through the subroutine t printing each nunber on the board as the PRINT NUMBER (ELEMENT) statement is executed* Copyright Atari, Inc* 1983* All rights reserved* 25 110 ARRAYS ( Continued ) 5* Given the FOR ♦ ♦ NEXT loop above to PRINT the numbers on the screen, ask the calipers how they could program the computer to PRINT the numbers in the reverse order* A FOR ♦ ♦ NEXT loop like the following should evolve from the campers suggestions* FOR ELEMENT = MAXNUMS TO 1 STEP -1 PRINT NUMBER (ELEMENT ) NEXT ELEMENT Encourage the campers to use descriptive variable names* Again* step through the program* PRINTing the numbers that would be output on the board* If you think your campers are catching on to arrays and variable indices* proceed with the next activity* Otherwise* review the previous examples* using a different Brra^ name and new data* Copyright Atari* Inc* 1983* All rights reserved* ARRAYS ( Continued ) Activity *2 1. In this activity the campers will gradually enter a program that INPUTs five numbers* stores them in an array* PRINTs them on the screen* and then PRINTs them in the reverse order* Note that the variable MAXNUMS can be used to DIMension the array* Have the campers type in the following program ♦ 100 REM * ARRAY OF NUMBERS 110 REM * 120 MAXNUMS = 5 . REM MAXIMUM NUMBERS WHICH CAN BE INPUT 130 DIM NUMS(MAXNUMS) 140 REM * 150 REM * FILL ARRAY 160 REM * 170 FOR COUNT = 1 TO MAXNUMS 180 PRINT "TYPE IN A NUMBER", 190 INPUT VALUE 200 NUMS(COUNT) = VALUE « REM STORE INPUT VALUE IN ARRAY 210 NEXT COUNT Ask the campers to add a line at the end of the program to PRINT the first element of the array* Add another line that PRINTs the last number in the array* using MAXNUMS as the index to the NUMS array. 2. Have the campers type in the following lines as a continuation of the Array of Numbers program* Jhe following lines PRINT the entire sequence of numbers in the array. RUN the program. 22 23 24 25 26 27 28 29 30 31 32 PRINT NUMBERS IN ORDER 0 REM * 0 REM * 0 REM * 0 PRINT 0 PRINT 0 PRINT 0 PRINT 0 FOR COUNT = 1 TO MAXNUMS 0 PRINT NUMS(COUNT) ," "* .REM PRINT VALUE 0 NEXT COUNT 0 PRINT "YOU TYPED IN THE NUMBERS IN THE" "FOLLOWING ORDERt" + SPACES Copyright Atari, Inc. 1983. All rights reserved. 6 iz> cri" a y dt ( Continued ) 3* E'.ased on what the campers know, ask then to complete the following lines, which print the numbers in the array in the reverse order ♦ 330 REM * 340 REM * PRINT NUMBERS IN REVERSE ORDER 350 REM * 360 PRINT 370 PRINT 11 YOUR NUME'.ERS IN THE REVERSE ORDER ARE ♦ 11 380 PRINT 390 FOR COUNT = TO STEP 400 PRINT < )l" N * f 410 NEXT 420 PRINT 430 END The campers should RUN the program to see if it does wha they intended* Activity *3 1* This next activity demonstrates additional uses of an array* Once again, the program INPUTs numbers* This time* the numbers are used as the PITCH for a SOUND command* The person using the program can create a little tune* Start by discussing the program with the campers* 2* First* pose the question* "Suppose you wanted to use an array to write a tune* What instruction must appear in the program before the computer will allow you to use an array?" (Answert DIM TUNE ( ??? ) ) When you get the appropriate answer* draw an array of boxes on the board alongside the dimension statement* Copyright Atari, Inc* 1983* All rights reserved* 7 ARRAYS < Continued ) 3* Now explain that as a prograMMer you want to INPUT the numbers that will serve as the values for the PITCH in the SOUND cofifisnd* You want to store the PITCH values in an array in order to play back the tune for the program user ♦ List the following INPUT code and ask the csMpers to explain what it does* 100 REM * SOUND NITH AN ARRAY 110 REM * 120 DIM TUNE(IOO) 130 XNOTE = 0 140 INPUT PITCH 150 IF PITCH = -1 THEN NUMNOTES = XNOTE ♦ GOTO 200 160 XNOTE ■ XNOTE + 1 170 TUNE ( XNOTE ) ■ PITCH 180 GOTO 140 The Minus one serves as a flag, indicating that the l3st note of the tune has been entered* Using a flag enables the user to enter as Many notes as he or she wishes* The user Must be told to type in a Minus one as a flag for the last note of the tune* The INPUT instruction is in a loop that continually checks for the Minus one flag* Explain to the caMpers that XNOTE is used instead of NOTE because NOTE is a reserve word* NUMNOTES is assigned the total number of notes typed in* Step through the INPUT routine a few tiMes and place soMe INPUT values in the box array you drew beside the DIM stateMent* 4* Now that the notes are stored in the TUNE ajpray* we need to write the BASIC routine which will play the tune* The idea here is to get the caMpers to generate the code froM your English description of the prograM* To play the tune* the routine Must use each of the elenents of the array in the SOUND coMMand* Ask what would be an efficient way to use each value in the SOUND instruction* Establish a FOR loop using the sane variable nattes as were introduced in the INPUT routine* FOR NUM = 1 TO XNOTE In this exaMple use voice zero in the SOUND coMMand and use ten for both the distortion and loudness for all of the notes* Thus* use the following SOUND coMMand: SOUND 0*TUNE0 INPUT PITCH 59 0 IF PITCH>255 OR PITCHOl THEN 580 60 0 REM x MINUS ONE IS A FLAG FOR THE END OF THE DATA 610 IF PITCH*- 1 THEN NUMNOTES=XNOTE ! RETURN 620 XNOTE=XNOTE+l .REM NOTES COUNTER 630 TUNE(XNOTE)=PITCH 640 GOTO 580 700 REM x 710 REM x PLAY TUNE 720 REM x 730 FOR XNOTE=l TO NUMNOTES 740 SOUND O, TUNE(XNOTE) , 10 , 10 750 FOR DELAY=1 TO 10. NEXT DELAY . i3 NEXT XNOTE 770 SOUND 0 t 0,0,0 780 RETURN 900 REM x 910 REM x LIST NOTES 920 REM x 930 FOR XNOTE=l TO NUMNOTES Copyright Atari, Inc. 19S3. 940 PRINT "TUNEC'JXNOTE;")";" ";TUNE(XNOTE) 11 OCA MPVT VMHTC ARRAYS ( Continued ) Activity Thus far we have used INPUT to fill the elements of an array* It is also possible to fill an array by READing DATA from within a program into an array* For example* music data could be stored in the program* read into an array* and sections of the array could be called at given tines in order to play a verse and then repeat a Melody* However* be careful with the READ statement* In Atari BASIC the READ instruction will only accept a simple variable* not an indexed variable* For example* the computer will accept the following READ statement* READ XNOTE The computer will not accept the following* READ TUNE ( 3 ) or READ TUNE ( XNOTE) Thus* you must READ the DATA into a simple variable and then transfer that value into the array* READ NUMBER ♦ TUNE(l) = NUMBER or READ NUMBER I TUNE ( XNOTE ) = NUMBER Have the campers RUN the TUNE program on their BASIC Utility Disk and look over the program in their^ program listings* The TUNE program is essentially the same as the MUSIC program in the READ* DATA* AND RESTORE Module* However ♦ having the data in an array enables you to repeat any note or sequence of notes in the tune* Have the campers experiment with changing the values for START and FINISH in order to make up different tunes* Copyright Atari* Inc* 1983* All rights reserved* 12 «£% FC Fc & Y S ( Continued ) 100 REM x TUNE ARRAY 110 REM x 120 DIM PITCHC50) ,DISTORT(50> ,LOUD<50> ,TIME<50) 130 INIT=500:REM INITIALIZATION LINE* 140 play=3oo:rem play tune routine 150 MAXNOTES=ll 20 0 REM x 210 REM xxxxx MAIN LOOP xxxxx 220 REM x 230 GOSUB INIT 240 start=i:finish=5:gosub PLAY 25 0 START=6tFINISH=ll t GOSUB PLAY 260 START=1 J FINISH=4 : GOSUB PLAY 270 END 300 REM ^^0 REM xxxxx PLAY xxxxx REM x 330 REM x PLAYS A SEQUENCE OF NOTES USING DATA ARRAYS. 340 REM x INDICES DETERMINED BY VALUES OF START AND 350 REM x FINISH IN MAIN LOOP 360 REM x 370 FOR XNOTE=START TO FINISH 380 SOUND 0 » PITCH ( XNOTE) , DISTORT ( XNOTE ) , LOUD ( XNOTE ) 370 FOR DELAY=1 TO TIME ( XNOTE K NEXT DELAY 400 NEXT XNOTE 410 RETURN 420 REM x 50 0 REM xxxxx INIT ARRAY xxxxx 510 REM x 520 FOR FILL=1 TO MAXNOTES 530 READ PITCH, DISTORT, LOUD, TIME 54 0 PITCH < FILL ) =PITCH : DISTORT ( FILL ) =DISTORT : LOUD ( FILL ) =LSUD : TIME < FILL ) =TIME 550 NEXT FILL 560 RETURN 57 0 DATA 121,10,10,40,91,10,10,37,0,0,0,3,91,10,10,40,108,10,10,28 58 0 DATA 0,0, 0,2, 108, 10, 10, 10, 91, 10, 10, 30, 108, 10, 10, 10, 121, 10, 10, 80, 0,0, 0,0 Copyright Atari, Inc. 1983. All rights reserved. 13 ARRAYS (Continued) Activity *5 A Group Discussion* In each of the programs where an array was used, all the data needed to be stored before you could do anything with it* For example* in the first program* you needed to know all the numbers before you could print then in the reverse order* In the SOUNDARY program* all the pitch values needed to be stored before they could be played back as a tune* Arrays are especially useful whenever you need to have access to all of the data before any thing is done with it* Ask the campers to think about each of the following programing problems and explain why using an array is or is not a good idea in each case* Find the average of five numbers that are INPUT by the program user* (Answer* No* because the numbers can be added together as they are INPUT into the computer and then divided by the number of values typed in*) SUM = 0 FOR COUNT = 1 TO 5 INPUT NUM SUM = SUM + NUM NEXT COUNT AVERAGE ■ SUM/5 Given a list of numbers ♦ which numbers are larger than the average of the numbers* (Answer J Yes* All the numbers must be saved in order to look back and see which are greater than the average*) Ask campers to try to solve this without an array* What if you knew there would only be five numbers? Can you think of some more examples? Copyright Atari* Ir.c* 1983* All rights reserved* 14 F" R: O G R A M M X M & CHALLENGES USXNG ARRAYS 1* Store your own tune data in the SOUNDARY progran* READ it into an array and play different sequences of notes from the nain loop* 2* Give the person using your program the option to edit his or her tune, one note at a tine* Ask the person which note he or she wants to change and use that number as the index to your array* Then ask what the new note value will be* Change the array element accordingly and return to the menu* 3* Write a program which INPUTs a series of numbers* and then lists those numbers which are larger than the average of all the numbers which were typed in* Use an array to store the values which the person types in* 4* Use two different arrays* HUE(IOO) and LUh(lOO)* to create a light show* Your program should contain a statement like the following onet SETCOLOR 0*HUE(COUNT) *LUM(COUNT) Copyright Atari* Inc* 1983* All rights reserved* 15 ARRAYS CAMPER COPY 10 0 REM x ARRAY OF NUMBERS 110 REM x 120 MAXNUMS = 5 {REM MAXIMUM NUMBERS WHICH CAN BE INPUT 130 DIM NUMS(MAXNUMS) 140 REM x 150 REM * FILL ARRAY 160 REM * 170 FOR COUNT = 1 TO MAXNUMS 180 PRINT "TYPE IN A NUMBER"; 190 INPUT VALUE 200 NUMS(COUNT) - VALUE {REM STORE INPUT VALUE IN ARRAY 210 NEXT COUNT 220 REM * 230 REM x PRINT NUMBERS IN ORDER 240 REM x 250 PRINT 260 PRINT "YOU TYPED IN THE NUMBERS IN THE" 270 PRINT "FOLLOWING ORDER ♦ " 280 PRINT 290 FOR COUNT = 1 TO MAXNUMS 30 0 PRINT NUMS ( COUNT ) }" "{ {REM PRINT VALUE + SPACES 310 NEXT COUNT 320 PRINT 100 REM * SOUND WITH AN ARRAY 110 REM x 120 DIM TUNE(IOO) 130 XNOTE = 0 140 INPUT PITCH 150 IF PITCH = -1 THEN NUMNOTES = XNOTE{GOTO 200 160 XNOTE = XNOTE + 1 170 TUNE < XNOTE ) ■ PITCH 180 GOTO 140 Copyright Atari, Inc. 1983. All rights reserved. 16 Ft Fi Y S CAMPER COPY CONTINUED 200 REM x 210 REM x PLAY TUNE 220 REM x 230 FOR XNOTE = 1 to NUMNOTES 240 SOUND 0 , TUNE ( XNOTE ) , 1 0 , 1 0 250 FOR DELAY = 1 TO 1 0 ♦ NEXT DELAY 260 NEXT XNOTE 270 SOUND 0,0,0,0 100 REM x SOUND WITH AN ARRAY PLUS PLAY TUNE 110 REM x 120 .DIM TUNE(IOO) 130 XNOTE = 0 140 INPUT PITCH 150 IF PITCH « -1 THEN NUMNOTES = XNOTEJGOTO 200 160 XNOTE = XNOTE + 1 170 TUNE (XNOTE ) = PITCH 180 GOTO 140 20 0 REM x 210 REM x PLAY TUNE 220 REM x 230 FOR XNOTE = 1 to NUMNOTES 240 SOUND 0 ,TUNE(XNOTE) ,10,10 250 FOR DELAY = 1 TO 10J NEXT DELAY 260 NEXT XNOTE 270 SOUND 0,0,0,0 Copyright Atari, Inc. 1983* All rights reserved* 17 ARRAYS CAMPER COPY CONTINUED 100 REM x SOUND ARRAY 110 REM x 120 REM x SOUNDARY 130 REM x INITIALIZE VARIABLES AND ARRAY 14.0 REM x 150 DIM TUNE(IOO) 160 XNOTE=0 165 REM x ASSIGN LABELS TO LINE NUMBERS 170 MENU=300 180 VALUES=50O 190 PLAY=700 ZOO NUMBERS=90 0 210 REM x 220 REM x MAIN LOOP 230 REM x 240 GOSUB MENU 250 INPUT RESPONSE 260 IF RESPONSES THEN GOSUB VALUES 270 IF RESP0NSE=2 THEN GOSUB PLAY 280 IF RESP0NSE=3 THEN GOSUB NUMBERS 0 GOTO 24 0: REM REPEAT MAIN LOOP 0 REM x 310 REM x MENU 320 REM x 330 PRINT 34 0 PRINT "WOULD YOU LIKE TOt" 350 PRINT " 1. TYPE IN A TUNE." 360 PRINT " 2. PLAY YOUR TUNE." 370 PRINT " 3. LIST THE NOTES." 380 PRINT 390 PRINT "TYPE IN A NUMBER" * 100 PRINT :REM INPUT IN MAIN LOOP 410 RETURN 500 REM x 510 REM x INPUT VALUES FOR NOTES 520 REM x 530 PRINT " TYPE IN NUMBERS BETWEEN 0" 54 0 PRINT " AND 255 TO BE THE NOTES" 550 PRINT " OF A TUNE. TYPE ONE NOTE" 560 PRINT " PER ?. WHEN YOU ARE FINISHED," 57C PRINT " TYPE A -1 FOR THE . LAST NOTE." SCO INPUT PITCH 59 0 IF PITCH>255 OR PITCHOl THEN 580 £0 0 REM x MINUS ONE IS A FLAG FOR THE END OF THE DATA 610 IF PITCH=-1 THEN NUMNOTES=XNOTE : RETURN S20 XNOTE=XNOTE+i:REM NOTES COUNTER 0 TUNE(XNOTE)=PITCH GOTO 580 Copyright Atari, Inc. 1983. All rights reserved. 18 ARRAYS CAMPER COPY CONTINUED TUNE REM X TUNE ARRAY 110 REM x 120 DIM PITCH<50> ,DISTORT<50> ,LOUD<50> ,TIME<50> 130 init=soo:rem INITIALIZATION LINE* 140 PLAY=300:REM play tune routine 150 MAXNOTES=ll 200 REM x 210 REM xxxkx MAIN LOOP xxxxx 220 REM x 230 GOSUB INIT 240 START=1 * FINISH=5 J GOSUB PLAY 250 start=6:finish=ii :gosub PLAY 260 start=i:finish=4:gosub play 270 END 300 REM 32TT REM x . 330 REM x PLAYS A SEQUENCE OF NOTES USING DATA ARRAYS. 34 0 REM x INDICES DETERMINED BY VALUES OF START AND 350 REM x FINISH IN MAIN LOOP 360 REM x 370 FOR XNOTE=START TO FINISH 380 SOUND 0 , PITCH ( XNOTE ) , DISTORT ( XNOTE ) , LOUD < XNOTE ) 390 FOR DELAY=1 TO TIME < XNOTE) : NEXT DELAY 40 0 NEXT XNOTE 410 RETURN 420 REM x 50 0 REM xxxxx INIT ARRAY xxxxx 510 REM x 520 FOR FILL=1 TO MAXNOTES 530 READ PITCH, DISTORT, LOUD, TIME 54 0 PITCH ( FILL )=PITCH: DISTORT < FILL )=DISTORT: LOUD ( FILL )=LflUD: TIME ( FILL )=TIME 550 NEXT FILL 560 RETURN 57 0 DATA 121, 10, 10, 40, 91, 10, 10, 37, 0,0, 0,3, 91 , 10, 10, 40, 108, 10, 10, 28 58 0 DATA 0,0,0,2,108,10,10,10,91,10,10,30,108,10,10,10,121,10,10,80,0,0,0,0 REM xxxxx PLAY xxxxx Copyright Atari, Inc. 1983. All rights reserved. 20 MATRICES An even more complex and more powerful array is called a "Matrix" or a "two dimensional array*" A matrix is an array of arrays* which is best explained with diagrams* The activities in this module take the campers through the steps required to write a battleship game that uses a matrix* If you would like to read about two dimensional arrays, or review some applications for matrices, you may want to look through the following references* (These are the same resources that were listed in the Arrays Module*) ATARI ^00/800 BASIC Reference Manual: pp*3* ^1-^3 Inside Your Atari* pp* 66-7^ Your ATARI Computer t pp* 65-67 Suppose you had a list of swimmers 7 times from three different swim meets* And* suppose you wanted to compare each swimmer's time for the butterfly in each of the three meets* A matrix is especially well-suited to Just such a problem* The following diagram illustrates how the swimmers' data can be stored in a matrix* SWIM MEETS SWIMMER #1 SWIMMER #2 SWIMMER *3 SWIMMER M 25 31 28 37 8 30 ^2 8 35 TIMES The swim times for each meet are stored in separate columns* The swimmers are listed in the rows of the matrix* Swimmer number one swam the race in the second meet in 28 seconds* In BASIC* this is written in the following way* Copyright Atari* Inc ♦ 1983* 1 All rights reserved* MATRICES ( Continued ) SWIMMER < 1 #2) = 28 / \ ROW COLUMN SWIMMER* MEET* Two indices are used* One holds the row value, which is the SWIMMER number* The second index is the colunn value, which in this case is the swim meet nunber* Swinner nunber three's slowest tine was in the second Meet* SWIMMER<3*2) ■ 30 / \ ROW COLUMN SWIMMER* MEET* Activity *1 1* Any data which conveniently fits into a grid or Matrix format* is well-suited to a two dimensional array in a BASIC program* Describe some programming examples in which you might use a two dimensional array* Explain the format of the indices for accessing an element of the matrix* Draw a matrix similar to the SWIMMER matrix on the board* Give the campers an opportunity to practice with indices by presenting some sample statements to complete* like the following examples* SWIMMER(3*1) = SWIMMER(2,1) = 4 SWIMMER(3*_) = 26 SWIMMER<_, 1 ) = 28 2* The format of a DIM statement for a matrix is shown below* DIM SWIMMERS, 3.) / \ Maximum * Maximum * of rows* of columns \ / In the matrix called SWIMMER* Copyright Atari* Inc* 1983* All rights reserved* Activity *2 1* The next prograhMing activity involves developing 3 BASIC progran for 3 "battleship" qawe* It May be helpful for the canpers to be 3ble to sinulate the progran on the board first* Draw 3 four by four Matrix on the boards like the one below ♦ COLUMNS 12 3 4 1 X LOCATION < 1 ,2) R 0 2 W S3 4 In the prograMt the randoM number function will be used to secretly position 3 host on the hoard* For now* play the gane on the blackboard* Ask one canper to secretly decide where the boat will be hidden on the battleship gane board* Then have the other canpers guess where the boat is by giving the matrix nane and the indices of the guessed location* List the guesses on the board beside the Matrix and place an "X" on the Matrix for each incorrect guess* Do this until the boat is found* You M3y want to play the gaine a couple of tines in order to give the canpers practice with using two indices ♦ Copyright Atari* Inc* 1983* All rights reserved* 3 ( Continued ) Activity *3 1 * To program this probleM^ first we Must be sure that the battleship board is cleared to zero, so that no extraneous data in Menory interferes with the game* This is called initializing the array* Explain that variables can be used as indices to a matrix* For example, BOARD < ROW * COLUMN ) = 0 * will place a zero in the specified location in the matrix* Ask the campers to suggest how they might initialize the BOARD matrix, using two nested FOR loops (like the example listed in number 2 below)* Record the initialization routine on the board* as the campers plan it* Draw a ^X^ matrix on the board* like the one above* and step through the loop routine, placing zeros in the matrix everytime a zero is assigned to a location* 2 ♦ Have the campers compare their code with the initialization routine listed below* Ask the campers to type in the following subroutine* Note that a variable can be used to dimension the matrix* 130 REM x 140 MAXL0CATI0NS=4 150 DIM BOARD (MAXLOCATIONS*MAXLOCATIONS) 160 COLUMN=0 :ROW=0 200 REM * 210 REM * I NIT MATRIX 220 REM x * 230 FOR ROW * 1 TO MAXLOCATIONS 240 FOR COLUMN = 1 TO MAXLOCATIONS 250 B 0 A R D < ROW f COLUMN > * 0 ♦ R E M STORE A 0 260 PRINT LOCATION 270 NEXT COLUMN 2S0 NEXT ROW Line 260 prints the contents of each element of the matrix* RUN the program to confirm that each element of the matrix got a zero as planned* E'.e sure the campers understand how the nested FOR loops work in lines 230 and 2^0 by "playing computer" and filling in a matrix on the blackboard in the order the computer does it* 100 110 120 REM * REM x REM x BATTLESHIP INITIALIZE VARIABLES Copyright Atari, I no 1983* All rights reserved* ( Cont i nued ) 3* Now the ship nust be hidden* Two randoh numbers Must be generated, one for the row value and one for the colu«n value in order to hide a ship in the matrix* A one is placed in the natrix in the location of the hidden ship in order to distinquish it from the empty spaces (zeros) on the board* Go over the following routine with the campers* Explain why and how the random numbers were used for the ship's location* Discuss why a one is put in the location of the ship* Ask campers what they think BOARD < SHIPROW , SHIPCQL > = 1 will do* Have the campers add the following code to their program which initializes the battleship matrix* ^00 REM * 410 REM X PLACE SHIP 420 REM x 430 SHIPROW ■ INT (RND ( 0 ) *40* 1 t REM A RANDOM NUMBER 440 SHIPCQL " INT ( RND ( 0 > +4 ) + 1 *REM BETWEEN 1 AND 4 450 BOARD (SHIPROW f SHIPCOL ) * 1 *REM ONE IS ASSIGNED TO RANDOM LOCATION 4* To play the game you must INPUT the user's guess and see if there is a "one" stored in that location* If the contents of the guessed location is one* the ship has been found* If not* let the user guess again* Explain* in English* the sequence of steps the program must take in order for someone to play the game* Have the campers come up with the BASIC code* Record the campers suggestions on the boardt as they are given* 1* First* get the user's INPUT for the ROW value* print u row; ";: input rowguess Get the COLUMN value* PRINT ''COLUMN: " J ♦ INPUT COLGUESS 3* Check to see if the location in the matrix guessed by the program user holds a ship* If so* PRINT "YOU FOUND IT!"* IF BOARD < ROWGUESS , COLGUESS ) « 1 THEN PRINT "YOU FOUND IT!"*END Copyright Atari* Inc* 1983* All rights reserved* MATRICES ( Continued ) 4, Otherwise PRINT "TRY AGAIN" and go back to the line which INPUTS the ROW value. Conpare the canpers' listing with the gane play routine below ♦ 700 720 730 7^0 750 760 770 780 790 800 810 820 83 0 840 1 1 TYPE IN THE COORDINATES OF" "YOUR GUESS » THE NUMBER MUST " BE BETWEEN 1 AND 1 1 REM * PLAY REM x PRINT PRINT PRINT PRINT PRINT "row: INPUT ROWGUESS PRINT "COLUMN: INPUT COLGUESS IF BOARD (ROWGUESS, COLGUESS )=1 THEN PRINT PRINT PRINT "TRY AGAIN" GOTO 770 1 1 ♦ ll ♦ f "YOU F r OUND IT ! » t END Have the csnpers type in the PLAY routine* Renefiber ♦ the Matrix is only a ^X*t Matrix* Rewind campers that if they type in a coordinate for the ship which is less than one or greater than four the program will bonb* Act i vity 4-4 1« To see how the sane code can be dressed up with a few PRINT statements, RUN the SHIP program on the BASIC Utility Disk* Copyright Atari* Inc* 1983* All rights reserved* 6 PROGRAMMING CHALLENGES USIENG MATRICES 1* Place nore than one ship on the battleship board in 3 randon location for the user to find* 2* Make the ship larger ♦ so that it takes up two or three locations on the grid of elements in the Matrix* Give the outer limits of the ship different values than the middle of the ship* This way* you can give the player feedback on his or her guess* (eg* "You hit the front of the ship*") 3* Give the player hints in response to his or her guesses* For example* if the program player's guess for the row position is one away froM the ship, PRINT "YOUR ROW GUESS IS HOT!" If the next row guess is nore than one away from the ship's location* PRINT "YOUR ROW INDEX IS GETTING COLDER ♦ " Do the sane for the column values* ^* Place friendly ships and enemy ships on the game board* Give the friendly ships one value and the enemy ships another value in order to differentiate the two* Keep score for the player* When an enemy ship is encounter ed * the player gains points* When an allies ship is hit* the player looses points * 5* Experiment with different graphics nodes* drawing a grid* and displaying the actual ships on the screen* Copyright Atari* Inc* 1983* All rights reserved* 7 MATRICES Csnper Copy xxxxx BATTLESHIP xxx*x 100 REM * BATTLESHIP 110 REM X 120 REM * INITIALIZE VARIABLES 130 REM * 140 MAXL0CATIGNS=4 150 DIM BOARD < MAXLOC ATIQNS f MAXLOCATIONS ) 160 COLUMN=0 :ROW=0 200 REM x 210 REM * INIT MATRIX 220 REM x 230 FOR ROW = 1 TO MAXLOCATIONS 240 FOR COLUMN = 1 TO MAXLOCATIONS 250 BOARD(ROW,COLUMN>=0 260 PRINT LOCATION(ROW, COLUMN) 270 NEXT COLUMN 280 NEXT ROW xxxxx PLACE SHIP xxxxx 400 REM x 410 REM * PLACE SHIP 420 REM * 430 SHIPROW = INT(RND< 0 )*40+l ! REM A RANDOM NUMBER 440 SHIPCOL * INT ( RND < Q ) +4 ) + 1 5 REM BETWEEN 1 AND 4 450 BOARD=0 560 PRINT BOARD (ROW, COLUMN) 570 NEXT COLUMN 58 0 NEXT ROW 590 RETURN 70 0 REM x 710 REM x PLACE SHIP 720 REM x «? 730 SHIPR0W=INT*4)+1 :REM RANDOM NUMBER 74 0 SHIPCOL«INT < RNDC Q ) *4 > + 1 J REM BETWEEN 1 AND 4 750 BOARD ( SHIPROW, SHIPCOL > =1 : REM PLACE SHIP IN RANDOM LOCATION 760 RETURN 90 0 REM x 910 REM x PLAY 920 REM x 930 GRAPHICS 2 940 POSITION 0,0 95 0 PRINT #6 J 1 ' columns" 960 FOR NUMBER*! TO 4 970 POSITION 2,NUMBERx2tREM ROW COORDINATES 980 PRINT #6? NUMBER 990 POSITION NUMBERx4,l :REM COLUMN COORDINATES 1 0 0 0 PRINT 4-6 t NUMBER 1010 NEXT NUMBER Copyrioht Atari, Inc* 1983* All rights reserved* 10 MATRICES Csnper Copy Continued 1020 10 3 0 1 0 4 Q 1050 10 6 0 107 0 1080 10 9 0 110 0 1 1 1 0 1120 1130 11*0 115 0 1 16 0 117 0 11 30 1190 1300 1310 132 0 133 0 1340 1350 136 0 137 0 138 0 1 39 0 140 0 1410 1420 0,3 {PRINT *61 ,I R* 0,4 J PRINT ♦Ai'VO" 0*5* PRINT *6;"W" o, 6: print #6; i, s n type in the coordinates your guess » the number be between 1 and 4 ••row: POSITION POSITION POSITION POSITION PRINT PRINT PRINT PRINT INPUT ROWGUESS IF ROWGUESS4 THEN 1090 it ♦ t THEN 1120 C0LGUESS>4 IF BOARD (ROWGUESS, COLGUESS )=1 THEN GOSUB WIN J RETURN POSITION C0LGUESSx4rR0WGUESSx2rREM PUT x ON BOARD PRINT *6r ,, * H PRINT : PRINT "TRY GOTO 1090 REM * REM * WIN REM x PRINT AGAIN" FOUND IT ! " ♦PRINT "YOU FOR CQUNT=1 TO 10 POSITION C0LGUESS*4 t ROWGUESSX2 PRINT #6;" " J ♦REM ERASE X FOR DELA Y~ 1 TO 75 t NEXT DELAY POSITION C0LGUESSX4 , R0WGUESS*2 print *6; m *";:rem flash x FOR DELAY-1 TO 75tNEXT DELAY NEXT COUNT RETURN Copyr iqht Alar i , Inc * 1933* 11 All rights reserved* PEEK & ND F> O K EH In the sane way that human beings have all sorts of pieces of information stored in their brain like telephone numbers and lock combinations* the computer also maintains hundreds of pieces of information ♦ When you turn on your computer the operating system stores all the necessary information the computer needs to process your programs* The PEEK instruction enables you to look at the contents of any memory location. The POKE instruction allows you to change a value stored in memory* To read more about the PEEK and POKE instructions* you may want to consult the following books* Atari 400/800 BASIC Reference Manual: pp* 35 Inside Atari BASIC ♦ pp 132-13? Your Atari Computer: pp 113* 379* 398 All the information stored in memory is stored in the form of numbers* Each number is held in a separate location* Memory can be thought of as a long series of boxes* each holding one piece of information* a number* There are 65*536 memory locations in a 64K Atari* Each box or memory location has an address which enables the programmer to identify which of the memory locations he or she is referring to* When you use the PEEK or POKE instructions you must specify the address of the memory location you want* The PEEK instruction enables us to peer in at the contents of the specified memory location* For example* PEEK(82) is the value stored in memory location 82* The address of the memory box you want to look at in this example, 82* is listed in parentheses following the PEEK instruction* Memory location 82 happens to hold the number of spaces used by the computer to set the left margin on the screen* To see the number of spaces that the left margin is currently set to* type the following instruction* PRINT PEEK (82) Have you ever noticed that there are two blank spaces on the left hand side of the screen* This is because the left margin* memory location 82* is set to 2 by the operating system* when you turn on your computer* Copyright Atari* Inc* 1983* All rights reserved* 1 PEEK **MD POKE (Continued) The POKE instruction enables you to change a value stored in Menory* For example* we could use a POKE instruction to change the left Margin ♦ POKE 82,5 To poke a value into Menory> the address of MeMory is listed, followed by a comm3 and the new value to be stored in «e*ory* Have the canpers type in the POKE 82,5 instruction to see what happens* Experiment with poking the following values into «enory for the left Margin* Retype the entir instruction using the values listed below* 5, 10, 20, 39 After poking 3? into nenory location 82, have the canpers try to Move the cursor to the left or to the right* Ask the canpers why the cursor will not Move to the left or right* It is also possible to use a variable as the value to be poked into MeMory with the POKE instruction* For exaMple, if COUNT is 1 then POKE 82, COUNT will store a 1 in MeMory location 82* Have the campers type in the following routine that uses a variable in a FOR * * NEXT loop to change the setting of the left Margin* 10 REM ** POKING THE LEFT MARGIN 20 REM * 30 PRINT 40 FOR LEFTMARGIN - 0 "TO 39 STEP 5 50 POKE 82, COUNT 60 PRINT 70 PRINT "LEFT MARGIN " 80 NEXT LEFTMARGIN RUN the prograM# Then ask the canpers to LIST their prograM* Why does everyone's code look so peculiar? Encourage the canpers to experinent with changing the values in this routine and running the prograM* Copyright Atari, Inc* 1983* All rights reserved* 2 PEEK tf=*MD POKE (Continued) The value for the right margin is stored in memory location 83* Have the campers type the following instruction to see what the right margin has been set to* * PRINT PEEK<83) The right Margin is routinely set to 39 * the last column on the graphics zero screen* Try poking a 20 into memory location 83* POKE 83,20 Have the campers try all sorts of values* If they get to a point where they are unable to return the margin to a reasonable setting* press SYSTEM RESET to reset the margins to their customary setting* Have the campers type in the following routine and RUN it* The program is simply a loop which continuously decrements the right margin by 5* 100 REM *xx*x DECREMENT RIGHT MARGIN 110 REM x 120 PRINT 130 FOR RIGHTMARGIN m 39 TO 0 STEP -1 140 POKE 83 ♦ RIGHTMARGIN 150 PRINT "RIGHT MARGIN" i 140 FOR DELAY - 1 TO 50* NEXT DELAY 170 NEXT RIGHTMARGIN Once again* when the program is completed the margins are so close together that the computer does not understand any instructions which are typed im Press SYSTEM RESET to return the margins to normal* Then have the camper LIST the routine* Typing SYSTEM RESET does not affect the program in memory* Now have the campers type in the following POKE instruction* POKE 755*6 Copyright Atari* Inc* 1983* All rights reserved* 3 F > E E K AND POK IE (Continued) All the letters on the screen should be inverted* To return the letters to their upright position type the following POKE instruction* . ■ . POKE 755,2 For wore locations to PEEK ♦ POKE* and play with* see the following resources* Atari Connection* Sunner ♦ 1983* pp 31-32 Inside Atari BASIC: pp 132-139 Master MeMory Map All of these references are available in the caMP library* The sunner issue of The Atari Connection has an article entitled "PEEKS AND POKES* CoMMonly Used and Helpful Mewory Locations*" This article has lots of fun ideas for exper inenting with PEEK and POKE and an explanation for each exanple* Inside Atari BASIC also suggests various locations to PEEK and POKE for fun* The Master Menory Map* produced by Educational Software Inc** lists all the significant newory locations* their contents* and what changes you can Make* Encourage the caMpers to look over the MeMory Map and experinent with changing the suggested locations* And finally* reassure the caMpers that it is iMpossible to danage or perManently alter MeMory* Have fun! Copyright Atari* Inc* 1983* All rights reserved. 4 PEEK AMD POKEI CAMPER COPY xxxxx PEEK AT THE LEFT MARGIN SETTING xxxxx PRINT PEEK (82) xxxxx POKE THE LEFT MARGIN WITH A NEW VALUE xxxxx 5, 10, 20, 39 xxxxx POKING THE LEFT MARGIN USING A VARIABLE xxxxx 10 REM xx POKING THE LEFT MARGIN 20 REM * 30 PRINT 40 FOR LEFTMARGIN m 0 TO 3? STEP 5 50 POKE 82, COUNT 60 PRINT 70 PRINT "LEFT MARGIN " 80 NEXT LEFTMARGIN xxxxx PEEK AT THE RIGHT MARGIN xxxxx PRINT PEEK (83) xxxxx POKE THE RIGHT MARGIN xxxxx POKE 83,20 Copyright Atari, Inc, 1983. All rights reserved F > EEL EE l-C CAMPER AND F-OKE COPY CONTINUED xxxxx POKING THE RIGHT MARGIN WITH A VARIABLE xxxxx 100 REM xx DECREMENT RIGHT MARGIN 110 REM x 120 PRINT 130 FOR RIGHTMARGIN - 39 TO 0 STEP -1 H0 POKE 83 f RIGHTMARGIN 150 PRINT "RIGHT MARGIN" i 160 FOR DELAY ■ 1 TO 50 J NEXT DELAY 170 NEXT RIGHTMARGIN xxxxx INVERTED PRINT xxxxx POKE 755,6 POKE 755,2 xxxxx REFERENCES WITH MORE IDEAS FOR MEMORY LOCATIONS TO PEEK AND POKE xxxxx Atari Connection, SuMner,1983J pp 31-32 Inside Atari BASIC! pp 132-139 Master Mewory Map Copyright Atari, Inc* 1983. 6 All rights reserved.