Apple IIe Applesoft Tutorial
Apple IIe Applesoft Tutorial
This manual is copyrighted. All rights are reserved . This document may
not, in whole or part, be copied, photocopied , reproduced , translated or
reduced to any electronic medium or machine readable form without prior
consent , in writing , from Apple Computer, Inc.
© 1982 by Apple Computer, Inc .
20525 Mariani Avenue
Cupertino , California 95014
(408) 996-1010
The word Apple and the Apple logo are registered trademarks of
Apple Computer, Inc.
This equipment has been tested and complies with the limits for a
Class B computing device in accordance with the specifications in
Subpart J, Part 15, of FCC rules . These rules are designed to ---l
provide reasonable protection against such interference in a
residential installation . However, there is no guarantee that the
interference will not occur in a particular installation , especially if -.l
you use a " rabbit ear" television antenna. (A " rabbit ear" antenna is
the telescoping-rod type usually contained on TV receivers.)
-
If your computer does cause interference to radio or television
reception, you can try to correct the interference by using one or
more of the following measures :
Introducing Applesoft 1
4 A First Statement
8 Unanswered Questions
8 Fancy Printing
9 Doing Calculations
13 What About IRETURNI ?
13 A Graphic Change of Pace
19 PLOT Error Messages
20 Drawing Lines
24 Variables and More Calculator Abilities
26 Distinguishing Variables
29 Summary of Variable Rules
30 A Big Timesaver
30 Precedence
32 Parenthetically Speaking
34 Chapter Summary
Elementary Programming 37
37 Deferred Execution
42 Loops : the GOTO Statement
45 Interacting with Your Program : INPUT
47 So You Want To Save Your Programs?
47 Preparations
48 Saving
49 Conditions : Determining the "Truth "
51 Symbols Used in Conditional Statements
52 Rules for Using Conditional Statements
52 Conditional Loops : the IF • •. THEN Statement
54 Using the APPLESOFT SAMPLER : COLORLOOP
56 More on the I F Statement
58 Remarks
59 FOR/NEXT Loops
62 Nesting and Crossing Loops
64 Controlling Spaces in Your Programs
70 Chapter Summary
Making Changes 73
73 The Moving Cursor: Escape Mode
73 Rules for Using Escape Mode
74 A Practice Session
76 Other Escape Commands
76 The Limits of Escape Mode
77 Inserting Text into an Existing Line
82 Getting Rid of Program Lines
83 Editing Long Programs
84 A Little History
86 Summary of Editing Features
Lots of Graphics 89
89 Constructing a Simple Game
90 Multiple Statements on a Line
91 Creating Motion
92 Screen Boundaries
93 Creating Visual Impressions
93 The Whole Thing
94 Program Interaction with Users
97 Making Sounds
100 Noise for the Bouncing Ball
100 Random Numbers
103 Simulating a Pair of Dice
103 Random Graphics
104 Subroutines: Putting the Pieces Together
108 Traces
109 A Better Horse-Drawing Routine
110 Errors
110 Variables
111 Additional Subroutines
112 A Well-Structured Program
113 High-Resolution Graphics
120 Chapter Summary
Help 167
167 If You (or Your Program) Get Stuck
168 Errors
168 Statements and Commands
168 Cassette Recorders
169 More Helpful Information
169 Printing Applesoft Programs
169 The Apple lie's Memory
170 What the Prompt Character Identifies
More Programs To Play With 171
172 Notes To New Programmers
173 SCRAMBLER
174 Analysis of Program Lines
177 Fine Tuning
178 Program Listing
180 MAGIC MENU
181 Notes To Advanced Programmers
181 How the Five Subroutines Work: A Demonstration
182 The I NPUT Routine
183 The GET RETURN Routine
183 The Screen Formatter Routine
184 The Menu Maker Routine
186 The Computer Identifier Routine
187 Notes on the Rest of MAGI C MENU
188 Program Speed
189 A Few Words about Variable Names
190 A Few Notes on Logic
192 Program Listing
201 DISK MENU
203 Renumbering and Merging Program Parts
205 Program Listing
211 CONVERTER
211 Program Listing
219 Some Final Thoughts
Glossary 221
Index 238
Learning To Program
You will learn , for example, how to tell your computer to say
hello to your friends; how to get your computer to act like a
calculator; and how to program your computer to draw horses
all over the screen.
What Is Programming?
A computer program is a set of instructions written in a code
called a computer language. Programs make things happen.
They may instruct a computer to display a message on the
screen, to do complex tax preparation calculation~, to create a
game, or to make designs. Programs, in other words, enable
you to accomplish many things with your computer.
Learning To Program
BASIC is a commonly used personal computer language. It is
easy to learn and easy to use. There are many varieties of
BASIC; each type of personal computer uses a slightly different
version . It is rather like regional dialects : even though people
speak differently, they generally use the same vocabulary and
can understand each other.
Getting Ready
Before you begin Chapter 1, get your machine and materials
ready:
Learning To Program
Things You Should Know
This tutorial is not a complete guide to Applesoft. To make
things easier, information that a beginning programmer doesn 't
need is sometimes left out. In other words, don 't be surprised
that there is more to learn-that is the reason for the Applesoft
BASIC Programmer's Reference Manual .
• Word Meanings
Computer terms with which you may be unfamiliar are in italics.
All italicized words are defined in the Glossary.
There are also several appendices that will help you with word
meanings.
• Symbols
There are three special symbols used in this manual.
The pause symbol marks points at which you can easily take a
break. You don 't have to stop working when you see this
symbol-it's just an aid .
The warning symbol lets you know when there is some vital
piece of information that you shouldn't miss. It also warns you
when you must do something for your programs to work.
Symbols
Where Else To Look
Before you begin this manual, you should read the Apple I/e
Owner's Manual and run the APPLE PRESENTS ...APPLE disk.
Learning To Program
L Introducing Applesoft
4 A First Statement
8 Unanswered Questions
8 Fancy Printing
9 Doing Calculations
13 What AboutlRETURfP
13 A Graphic Change of Pace
19 PLOT Error Messages
20 Drawing Lines
24 Variables and More Calculator Abilities
26 Distinguishing Variables
29 Summary of Variable Rules
30 A Big Timesaver
30 Precedence
32 Parenthetically Speaking
34 Chapter Summary
Introducing Applesoft
Introducing Applesoft
Now it is time to get started! Find the disk labeled DOS 3.3
SYSTEM MASTER. Place it in the disk drive and close the drive
door. Turn on your computer. When the red light on the disk
drive goes off, you should see a square bracket prompt (]) and
Figure 1-1. The Cursor and the a blinking cursor at the left edge of your screen .
Prompt
If you don 't see them, check your system . Is the disk drive
connected? Is the video monitor plugged in and turned on?
Is the Apple lie turned on?
Applesoft BASIC is built into the Apple lie, so a disk drive is not
required. If you use a cassette recorder, see the Applesoft
Reference Manual.
Once you have a cursor, press the lcAPS LOCKi key down into its
on position . It is located at the lower-left corner of the keyboard.
When the key is locked into position , you should hear a click
and notice that it is lower than the other keys.
Warning
Whenever you are using Applesoft BASIC with the Apple lie,
make sure [CAPS LOCKi is on . If it is not on and you try to give an
instruction in lowercase, you will be rewarded with a beep from
your computer and a ?SYNTAX ERROR message. Applesoft only
understands instructions in uppercase.
Introducing Applesoft
A First Statement
You are ready to give the Apple lie some instructions, so type
the words you see below. Remember that to get the double
Figure 1·2. The PR ItH Statement. quotation mark you have to press thelsH I n l key. Type
When you give instructions like this
to the Apple lie, you should type PRINT "HELLO"
exactly what you see in this manual ,
including spaces, uppercase letters,
and quotation marks . and press the IRETURNI key.
Prompt
• ]
PR I tn "HELLO"
• HELLO
1. Did you use uppercase letters? If not, press the lcAPS LOCK I
key and try again .
Introducing Applesoft
2. Is the cursor blinking next to the second quotation mark? If
so, press [RETURN[. (Every instruction must be followed by a
press of the [RETURN[ key to tell the Apple lie that you have
completed the instruction.)
3. Are there quotation marks surrounding HELLO? If not, type
the instruction again. If you used the single quotation mark,
be sure to hold the ISH I FT[ key down to produce the double
quotation mark.
If you forget the first quotation mark , the computer will print
a zero right below your instruction .
• print "hello"
?SYNTAX ERROR
PR I NT "HELLO".
PRINT HELLO
2 o
3
PRIMT "HELLO"
?SYNTAX ERROR
4 PRINT "HELLO"
HELLO
5
A First Statement
If you notice a mistake before you press iRETURNl, you can fi x it
without having to retype the whole line. Press the llEFT - ARROw l
key until the cursor is over the mistake. Type the correction.
Then press thelRIGHT-ARRow lkey until the cursor reaches the
end of the line. Press IRETURNI.
Helpful Hint: A word to the wise : nobody's perfect. Unless you are
familiar with a computer keyboard , it will probably take a while for
your fingers to find the right keys every time. But all it takes is a
little practice, so keep trying! You 'll find that once you get used to
the arrow keys, fixing mistakes won 't take long. And soon you will
realize that checking each line before you presslRETURNI makes life
much easier.
Now type the next statement, filling in your name in place of the
blank. And don 't forget to pressK TJJRij.
Now type
The Apple lie displays exactly what you told it to. Even if it's not
true!
PR I tH is t he primary Applesoft When you tell the Apple lie to PR I NT something in quotation
statement used to display marks, you instruct it to display all the characters between the
information on the screen .
quotation marks on the display screen. You can use the PR I NT
statement to tell the computer to display any message you wish .
Try it!
Introducing Applesoft
Figure 1-4. The Screen Character
•
Limi t. The length of a line on the
] PR ItH "THE QU I CK BROWN FOX JUMPED OVER T
HE LAZY DOG'S TAIL WHILE THE DOG ATE A CA
N OF CAVIAR. MY AUNT LOOKED ON IN HORROR
BECAUSE SHE WAS PLANNING TO FEED THE CAVI
AR TO HER GOLDFISH. I WAS SECRETLY HAPPY
screen is 40 characters. It takes 6 1/2
SINCE I KNOW THAT THE LAZY DOG LOVES CAVI
screen lines to reach the character AR AND HAD NOTt
limit of an Applesoft line.
PRINT 150
the computer prints the number 150 on the next line without
any error message about the missing quotation marks. Type
PRINT "150"
and it does the same thing . This only works with numbers. If you
try typing
PRINT HELLO
A First Statement
Unanswered Questions
Many times you 'll have questions about Applesoft BASIC that
are not answered directly in this book. For instance, in the
statement
PRINT "HELLO"
PRINT"HELLO"
and see what happens. When you take the time to try it yourself,
you will remember what you learn better than if you merely read
about it.
When trial and error doesn 't work, see this manual 's appendices
and the Applesoft Reference Manual.
Warning
The Apple lIe uses less electricity than an 11 -watt light bulb.
Whenever you take a short break , leave the computer turned on .
You should , however, turn the monitor off, since it uses much more
energy than the computer.
e Pause
Fancy Printing
Now that you've been introduced to the PR I NT statement, how
would you like to try another? Type
Introducing Applesoft
Isn 't that nice? Try some more PR I NT instructions of your own .
Notice that you don't have to type I NVERSE with each statement.
Once you instruct the Apple lie to use black-on-white, it will do
so until you tell it to stop. To do that, type
INVERSE
HOME
Doing Calculations
Without further study, the Apple lie can be used as an ordinary
desk calculator.
PRINT 3 + 4
DOing Calculations
The Apple lie can do five different elementary arithmetic
operations:
Introducing Applesoft
You can combine several of these arithmetic operations within
the same statement. For example, you can instruct the Apple lie
to
PRINT 3 + 51 + 9 + 400
or
PRINT 3 + 5 I 9 * 4 A 2 -
• PRINT 3
463
+ 51
PRINT 3 + 5 I 9 • 4
+ 9 + 400
A 2 - 1
10.8888889
The exact rules for such usage are given later in the chapter,
but you can experiment now if you wish.
PRINT 45.340
• 45.34
and doesn 't display the trailing zero . The Apple lie does not
display leading or trailing zeros, that is, zeros that are at the
beginning of a number and to the left of the decimal or zeros
that are at the end of a number and to the right of the decimal.
Now type
PRINT 985788.6898
Doing Calculations
Surprise! The last two digits are lost, and the number left
behind is the closest approximation the computer can find . This
process is called rounding . Try typing
PRINT 788.6898
The Apple lie did not round the number, but displayed it just the
way you typed it. Madness you say? Ah , but there is a method to
this seeming madness. Numbers are rounded only if they have
more than nine digits. Any number that has fewer than ten
digits will not be rounded . Applesoft does the best it can , but
it can only work with nine digits.
1234567890
• 1.23456789E+09
• 1 E +10
Introducing Applesoft
What AboutRETURNI?
So far, you have been pressing thelRETURH key after every line.
You might like to know why this key gets so overworked. The
reason is simple: without the~ETURNI, the computer does not
know when you have completed an instruction. For example, if
you typed
PRINT 4 + 5
PRINT 4 + 5 + 346
which nets a different answer entirely. Since the computer can 't
tell when you have finished typing an instruction, you must tell
it. You do this by pressing the lRETURH key.
• Warning
Since you always have to press thelRETURH key after typing an
instruction , this manual will no longer remind you . Pressing
RETURNI after each instruction should be a habit by now, if you have
been doing all the examples.
e Pause
When you type GR , short for " graphics, " you 'll notice that a
design quickly flashes past, the screen clears, and the cursor
moves to the bottom of the screen. (If your screen didn 't clear,
you probably forgot to pressRETURNI. And forgot that you won 't
be reminded any more.)
•
GR clears screen , sets the color to
black
Cursor _ _ _ _ _ _ _ _ _ _~
The GR statement sets the stage for doing all kinds of drawing
and fancy visual work. However, before you can see the results
of what you do on the screen, you have to tell the computer to
use a color that will show up on the black background. Try this
now, by typing these two instructions:
PLOT 20,22
PLOT 20,24
Introducing Applesoft
Note: If nothing appears on your screen, chances are you forgot
to specify a color. You must do this, no matter what kind of display
device you are using.
The PLOT statement tells the computer where to put each brick
of color by assigning two numbers on the invisible grid . The
first number in the three PLOT statements you have used so far,
20 , names the 20th vertical column out of 40. The vertical
column number is always the first in a PLOT statement. The
second number (you have used 20, 22, and 24) names the
Figure 1-6. Using PLOT Statements
horizontal row.
Now try plotting some bricks on your own . Can you put some in
the leftmost vertical column? (Hint: the first number after PLOT
should be 0, although 1 also will work.) What about the vertical
column on the far right? (Hint: the first number after PLOT
should be 39.)
Notice in Figure 1-7 that the numbering system for the vertical
columns goes from 0 to 39, left to right. The numbers for the
horizontal rows also go from 0 to 39, beginning at the top of the
screen and moving down. Those of you who know algebra will
recognize that this is a system of Cartesian coordinates. This
book refers to the coordinates as columns and rows. Since the
screen is already divided into 40 vertical columns and 40
horizontal rows, all you have to do is name the coordinate
points that go with each PLOT .
COLOR = 5
Notice that nothing new has happened on your screen yet. You
have to tell your Apple lie where to put each brick, so type
PLOT 20,21
PLOT 20,23
PLOT 20,0
/
Introducing Applesoft
/'
You should see two more bricks in the same column .
Dark gray : 1, 2, 4, 8
Medium gray : 5, 10 If you are using a black-and-white or a green-phosphor monitor,
light gray : 3, 6, 9, 12 there are five groupings of colors that will contrast well on your
Pale gray : 7, 11 , 13, 14
screen . All of the sixteen color numbers can be used, and you
White : 15
should feel free to experiment with them.
Since you have bricks on your screen that have been plotted
with COLOR =15 and COLOR = 5, try typing these instructions to
see some more contrasts:
COLOR = 3
PLOT 21,0
PLOT 21 ,20
COLOR = 1
PLOT 22,22
PLOT 22,25
PLOT 22,26
COLOR = 0
PLOT 22,27
When you want to clear your screen and do some new PLOT
statement~,
type
GR
When you are doing graphics, HOME only clears the text window.
GR must be used to clear the graphics portion of the screen .
Introducing Applesoft
PLOT Error Messages
There are two error messages that often turn up when using the
PLOT statement. You probably already know that if you type
PLAT
or
PLOP
instead of
PLOT
• ?SYNTAX ERROR
PLOT 13,85
This message means that you have tried to plot a point out of
range and off the screen . The highest number you should try to
use in a PLOT statement is 39 because the coordinates range
from 0 to 39.
Aside: There are, in fact , some ways to plot row numbers larger
than 39. They are discussed in the Applesoft Reference Manual.
message.
e Pause
GR
COLOR =1
PLOT 0,20
PLOT 1 ,20
PLOT 2,20
PLOT 39,20
COLOR = 7
HUN 0,39 AT 21
Introducing Applesoft
Figure 1-10. The HLI N Statement
Now you figure out how to draw a third contrasting line at row
22. This time, however, have it run from column 10 to column 30.
Drawing Lines
To see how PLOT and HL I N can be used together, try the
following:
COLOR = 8
HUN 29,39 AT 35
HUN 29,39 AT 37
COLOR = 10
PLOT 29,36
PLOT 39,36
COLOR = 15
In low-resolution graphics, VL I t-I VUN 0,20 AT 0
draws a vertical line in the color VUN 0,20 AT 15
indicated by the most recent COLOR=
statement. COLOR = 5
HUN 0,15 AT 0
HUN 1 ,14 AT 20
Notice that when the first horizontal line is drawn over the ends
of the vertical lines, the new color takes over, and the old color '-'
disappears. Practice making more vertical lines. Then, to clear
the screen, use the GR statement.
COLOR = 3
VU N 5,25 AT 10
and figure out the rest. Then dot the i with a PLOT statement. If
you like, add an exclamation point at column 28 (just for show).
Introducing Applesoft
Figure 1-12. Using Low-Resolution
Grid Coordinates
TheTEXT statement sets the screen When you are finished with graphics, the TEXT statement
to the nongraphics text mode : 40 returns the computer to text mode so you can use the full
characters per line and 24 lines.
When used to leave the graphics screen to work with programs. When you type
mode, it is best used in conjunction
with the HOME statement. TEXT
you 'll see a screenful of funny symbols. The technical term for
this is garbage. It is just an indication that Applesoft is switching
modes from graphics to text. To remove the garbage from your
screen, follow the TEXT statement with HOME. As you already
know, HOME clears text from the screen .
e Pause
Drawing Lines
Variables and More Calculator Abilities
In the main memory of your Apple lie are a large number of
special storage spaces. In each one of these spaces you can
store a number, the result of a computation , words, or a group
of characters. To accomplish this you need symbols to
represent the various locations, or storage spaces.
Say you want to save the number 77 . If you wanted to name the
storage space A, you would instruct the Apple lie to
-
Try typing the two statements.
Introducing Applesoft
A variable can have almost any name as long as it starts with a
letter. For example :
LET A = 77
LET RED3 = 77
LET CLOTHING = 77
CLOTHING = 100
Whenever you put a new value in a variable, the old value is erased
from memory.
However, the variables A and RED3 still contain the value 77 . Try
typing
PRINT RED3
LET A = 45
and
A = 45
THISCOLOR = 6
or
COLORFUL = 9
All you get is the ?SYNTAX ERROR message, which means you
have unwittingly included a reserved word in the name. Don 't
worry. Just choose another name. In this case, a change to the
British spelling will solve the problem and still give you a
meaningful variable name: COLOURFUL.
Distinguishing Variables
Applesoft uses only the first two characters of a variable name
to distinguish one variable from another.
81RD = 11
PRINT 81RD
PRINT 81TE
PRINT 81LLOW
Introducing Applesoft
There is a big difference between the way Applesoft interprets
PRINT CAT
and
PRINT "CAT"
The first sentence refers to little furry creatures w ith long tails.
The second sentence refers to the word itself. This is how
quotation marks are used in Applesoft. When you type
PRINT "CAT"
you are instructing the Apple lie to print the word . When you
type
PRINT CAT
you want the Apple lie to print what the word stands for.
So far, you have only used variables with a single number. You
also can store the result of a computation in a var iable. Type
A = 4 + 5
PRINT A
PRINT A + 2
FOOD = 28
PRINT FOOD
PRINT FOOD + 5
PRINT FOOD
FOOD = FOOD + 5
PRINT FOOD
FOOD = 2
PRINT FOOD
FOOD = FOOD + 3
PRINT FOOD
FOOD = FOOD * 6
PRINT FOOD
FOOD = FOOD / 10
PRINT FOOD
Introducina ADDlesoft
The Apple lie is able to store each new value of the variable
(FOOD) as it is assigned or computed. You don 't have to
PR I NT FOOD each time for that to happen. Just to make sure,
try it now.
FOOD 2
FOOD FOOD + 3
FOOD FOOD * 6
FOOD FOOD / 10
PRINT FOOD
Look at the sequence below. What answer do you expect? Try it.
APPLES = 55
BANANAS = 11
QUOTIENT = APPLES / BANANAS
PR I NT QUOT! ENT
You see from this example that once you have stored several
variables in the Apple lie you can do computations using the
variable names. Apples can't actually be divided by bananas,
but Applesoft recognizes the words as variable names and uses
their values in the division.
This section has explained how to store numbers and the results
of computations in variables. As you may recall , it is also
possible to store words and groups of characters in variables.
Chapter 5 will return to this subject.
e Pause
A Big Timesaver
You may have noticed by now that the PR I NT statement is used
a lot in Applesoft.
? "WOW! ·"
Precedence
Now that you are using the Apple lie for computations, yo u need
to know what order, or precedence , Applesoft uses in carryi ng
out your instructions. In a calculation like
PRINT 4 + 8 / 2
addition is done.
Introducing Applesoft
Here are some more examples :
PRINT -3 + 2
Applesoft applies the unary minus sign to its appropriate
number or variable before doing any arithmetic operations.
Thus -3 + 2 evaluates to -1 . If it did the addition first ,
-3 + 2 would evaluate to -5. But it doesn't. Another example
is
BRIAN = 6
PRINT -BRIAN + 10
The answer is 4 . (Notice, though , that in the arithmetic
expression 5 - 3 the minus sign is indicating subtraction ,
not a negative number.)
Precedence
Figure 1-15. Applesoft 's Order of
First: Unary, or minus, sign used to indicate a negative number
Precedence for Carrying Out
Arithmetic Operations Second : " Exponentiations, from left to right
PRINT 4 + 6 - 2 +
PRINT 5 - 4 / 2
PRINT 20 / 2 * 5
PRINT 6 * -2 + 6 / 3 + 8
PRINT 2 " 2 " 3 + 2 " 3
PRINT 8 * 2 / 2 + 3 * 2 " 2 * 1
No answers are given in this book. The Apple lie will give you
the correct answers. If you like doing these, try some of your
own. If not, keep going!
Parenthetically Speaking
Now, suppose you want to divide 12 by the result of 4 + 2. If you
type
PR I NT 12 / 4 + 2
you will get the answer 5. But this is not what you meant. To
accomplish what you meant in the first place, use parentheses
to modify the precedence. Type
PRINT 12 / (4 + 2)
Introducing Applesoft
The rule Applesoft follows is simple: it does what is in
parentheses first. If there are parentheses within parentheses,
Applesoft does what is in the innermost parentheses first. Here
is an example:
PRINT 12 I (3 + (1 + 2) " 2)
12 I (3 + 3 " 2)
PRINT (44 I 2) + 2
PRINT 100 I (200 I (1 * (9 - 5»)
PR I NT 32 I (1 + (7 I 3) + (5 I 4»
e Pause
Parenthetically Speaking
Chapter Summary
Here is what you have learned in this chapter. Impressive, isn 't
it? Each category lists the terms in order of their appearance in
the chapter. Definitions of statements are in Appendix A.
Glossary terms are defined in the Glossary.
37 Deferred Execution
42 Loops : the GOTO Statement
45 Interacting with Your Program : INPUT
47 So You Want To Save Your Programs?
47 Preparations
48 Saving
49 Conditions: Determining the "Truth "
51 Symbols Used in Conditional Statements
52 Rules for Using Conditional Statements
52 Conditional Loops : the IF ... THEN Statement
54 Using the APPLESOFT SAMPLER : COLORLOOP
56 More on the I F Statement
58 Remarks
59 FOR/NEXT Loops
62 Nesting and Crossing Loops
64 Controlling Spaces in Your Programs
70 Chapter Summary
Elementary Programming
Elementary Programming
PRINT 3 + 4
But what if you want to produce some computer magic for your
friends without typing while they watch? Or you want to write
some instructions, take a break, and return later to add some
more? To do these things, you need to be able to store the
statements for execution at a later time. This is called deferred
execution .
• Deferred Execution
To make sure that the computer's memory is cleared , type
Elementary Programming
• lNEW
]100 PRINT "MY FAVORITE FOOD IS ARTICHOKES"
1
1
]1
• LIST
----------------------~
•
in the program lines in memory.
Elementary Programming
•
Figure 2-1. Using LI ST and RUN in
Deferred Execution
The old line 100 has been replaced and is no longer in memory.
Type LIST to check. Now instruct the Apple lie to
RUN
NEW
and then
LIST
the computer's memory is erased; both lines 100 and 110 are
lost. Type
RUN
Deferred Execution
a
2 PRINT "P"
PRINT "A"
4 PRINT "E"
3 PRINT "L"
• 1
2
3
4
PRINT
PRINT
PRINT
PRINT
"A"
upll
"lll
liE"
When you run what is in memory, you see that the computer
also executes the statements in order of increasing line number.
But that's not good enough. There is a P missing. To add it, so
the computer will print
• A
P
P
L
E
3 PRINT "P"
4 PRINT "L"
5 PRINT "E"
To see what has happened, use the LIST statement, and then
type RUN .
When one of the p 's was left out of APLE, it was a bother to
retype those statements. There is, however, an easier way. It is
good programming practice to leave some room between line
numbers and before the first line. If the line numbers had been
10, 20, 30, and 40, you could have added the missing P with
line 15.
Elementary Programming
One of the advantages of deferred execution is that you can add
to or modify your instructions without having to type everything
over and over again. To see this in action , type
NEW
When you run this program it doesn 't quite print CAT vertically.
But you can go back and type
NEW
1 0 HOME
20 PRINT "MY APPLE GIVES MESSAGES:"
30 PRINT
40 PRINT "HI, THERE, PROGRAMMER!"
50 PRINT
60 PRINT "MY APPLE DOES COMPUTATI ONS : "
70 PRINT
80 PRINT 60 I 12
90 PRINT 4 A 5
RUN
Deferred Execution
• MY APPLE GIVES MESSAGES:
HI, THERE, PROGRAMMER!
MY APPLE DOES COMPUTATIONS:
5
1024
Does your screen look like this? If not, list your program to see
what went wrong . (Notice that you can list a program after you
have run it as well as before.) Here are some things to look for
when you list a program :
If you need to correct any lines simply type them over. Then list
again to make sure they look right. (In the next chapter you'll
learn some faster ways to correct and edit your program lines.)
e Pause
100 PRINT
110 PRINT 2
120 PRINT 3
Elementary Programming
and so on. But this would require 200 statements and a lot of
careful typing! Luckily, there is an easier way. You can print the
positive integers using just five statements:
NEW
100 N = 1
110 PRINT N
The GOTO statement causes a 120 N = N + 1
program to branch to the indicated 130 GOTO 110
line. It is used to create a loop in a
program.
Before you run this program, look at Figure 2-3 to see how the
program works.
Figure 2·3. The GoTo Statement
. .
•
Line 100 names the variable Nand --- I
sets its value at 1. See " Variables and
More Calculator Abilities, " Cha~ ter 1
____ 100 1'1 • 1
variable N by 1
. ' . Run the program . You will learn how to stop this program
Line 130 does Just what It says . It . shortly. Meanwhile admire the power of the program . If you
causes the program to go back to line '
110. Line 110 printsN , line 120 typed RUN when instructed, two sentences back, the Apple lie
increases N by 1, line 130 says to do has executed the statement PR I NT N a few hundred times
line 110 over again , and so on . Each I d
time, a new value of N is printed , over a rea y.
and over.
To stop the program press and hold thelcoNTRoq key while
pressing the C key.
BREAKIN110
Try it. By the way, this is an exception to the rule about pressing
RETURNI after every instruction. PressinglRETuRH is usually not
necessary when a program is stopped with ICONTROq- C.
As you look at the screen notice that the numbers keep rippling
up and out of sight. As each new number is printed at the
bottom of the screen all the others are moved up one line. This
is called scrolling. You 've been seeing it all along , but at a much
slower rate.
NEW
100 PRINT "RAIN"
110 PRINT "IS"
120 PRINT "FALLING"
130 PRINT "DOWN"
140 PRINT "DOWN"
150 PRINT "DOWN"
160 GOTO 100
RUN
RUN 130
• DOWN
DOWN
DOWN
II Elementary Programming
on your screen before the program goes back to line 100 and
begins at the beginning.
LI ST 130
the Apple lie will list only line 130 (if there is one) . If you type
LIST 130,150
or
LIST 130-150
the computer will list all the program lines in its memory
between and including line 130 and line 150. Try it. You cannot,
however, specify a range of lines in the RUN statement.
e Pause
Say you want a program that asks a person 's age and uses
whatever number the person enters to display a message. You
already know how to use PR I NT to display messages. So the
first step is to include in the program the message you want
used. You also know how to assign a variable name to a number.
Since age is a variable, you 'll use what you already have learned
The I NPUT statement allows the for this. What you haven 't yet learned is how to use the INPUT
programmer to interact with a statement.
program user from within a program .
any typing errors. Before you run it, look carefully at Fig ure 2-4.
The order, or syntax , of each statement is especially important.
• NEW
10 HOME
20 INPUT "HOW MANY YEARS OLD ARE you?n ; AGE
30 PRINT "YOU ARE n; AGE; n YEARS OLD,n
Now run the program . When you see the screen clea r and the
question
•
Statement
Elementary Programming
Here is an example of how to add a variable computation to your
I NPUT program. Leave lines 10 and 20 as they are. Add th is new
line:
Preparations
To save a program you need two things : a program to save,
Initializing, or formatting , is a and an initialized disk or a cassette tape on which to save the
process used to prepare a disk to program. Of course, you also can save programs by writing
receive information . This process is
ex plained in the Apple lie Owner's them down , but that's not nearly as much fun as using the
Manual . Apple lie.
Saving
If you have been following along, the age-asking program is still
in memory. To make a permanent copy of this program on a
SAVE , when followed by a file name, disk, give the SAVE command followed by the name you want to
is a DOS command that stores the give the program . To see this in action, make sure your
program currently in memory onto a
disk. SAVE used without a file name initialized disk is in the disk drive and type
stores the program currently in
memory on cassette tape. SAVE AGE
Your disk drive will whir briefly, and you'll see the red light go
on. When the red light goes off, type
CATALOG
and you'll see a list of all the programs on your disk. There
should be two, unless you have already saved others.
Elementary Programming
Helpful Hints: If you turned your system off and restarted it
recently, the age-asking program may be gone from memory.
To save it, type it again, and then give the SAVE AGE command.
If you are using two disk drives and want to save the program
on the disk in Drive 2, type ,D2 after the program name.
If nothing happens, type the program in again, and then save it.
If still nothing happens, ask yourself:
e Pause
PR I NT 17 ) = 18
• PRINT 17 ). 18
o
PRINT 75 )= 18
PRINT 18 )= 18
PRINT 3 )= 18
PRINT 27 )= 18
Elementary Programming
- Symbols Used in Conditional Statements
Six symbols are used in Applesoft to determine the relationship
between values. Figure 2-5 lists them and gives some examples
of each symbol.
To type the symbols for greater than or equal to and less than or
equal to on the Apple lie keyboard, first type a ( or a ) and
then an •. To type the symbol not equal to, press ( and then) .
PRINT 5 () 5
PRINT 8 (= 8
PRINT -8 ( - 7
PRINT -2 )= -5
PRINT 9 <> -9
PRINT (45 * 6) () ( - 45 + 6)
e Pause
Say you want a program that counts to 20, then stops. What you
want is a conditional statement that will limit the variable, N, to
20 or less. This would be written N < = 20.
Elementary Programming
The idea of the program is if N is less than or equal to 20 ,
then counting continues; if the assertion is false (if N is greater
than 20), then counting stops. Not surprisingly, the Applesoft
The IF ... THEN statement creates a statement for this is IF ... THEN. Here is a program that uses a
conditional program loop. conditional in the IF ... THEN statement:
NEW
200 N = 1
210 PRINT N
220 N = N + 1
230 IF N (= 20 THEN GoTo 210
To transfer the program AGE from the disk back into memory,
type
LOAD AGE
• 10 HOME
20 INPUT "HOW MANY YEARS OLD ARE YOU?" ; AGE
25 AGE • AGE * 365
30 PRINT "YOU ARE ABOUT "; AGE; " DAYS OLD!"
Figure 2-6 shows the two paths this program can take. Run the
program after you have studied the diagram.
I
I I
True False
30 PRINT "YOU WILL BE ABLE 40 PRINT "YOU AR E ELIG IBLE
TO VOTE IN " ; 18 - AGE; TO VOTE. HAVE YOU
" YEARS." REGI STERE D? "
Unless you want to erase the old program AGE , you must save t hi s
new version w ith a different name. Since it is helpful to use prog ram
names that remind you what the program does, you cou ld use
VOTE - AGE for the name of the new version .
Elementary Programming
Remove the disk you have been saving programs on from the
disk drive. Insert the APPLESOFT SAMPLER disk and close the
drive door. Type
RUN CoLoRLooP
and you will hear the drive whir as it looks for the program .
When CoLoRLOOP is loaded into the computer's memory, it will
run automatically. If CoLoRLooP doesn 't execute:
- • Type CATALOG to make sure the APPLESOFT SAMPLER
disk is in the disk drive and the program CoLoRLooP is
listed on the disk.
• Give the RUN instruction again , making sure everything
is spelled correctly and that you have specified the
appropriate drive. (Remember that if the APPLESOFT
SAMPLER disk is in Drive 2, you must type, 02 after the
program name.)
400 GR
410 ROW = 1
420 COLOR = ROW
430 HLI NO, 39 AT ROW
440 ROW = ROW + 1
450 IF ROW < 16 THEN GoTo 420
TEXT
if you want to see all the program lines as you type them in.
NEW
200 GR
210 COLOR = 9
220 PLOT 0,0
230 PLOT 0,39
240 PLOT 39,39
250 PLOT 39,0
List the program to check your typing ; then run it. Quick, isn 't
°
it? Now change line 21 to another color with
210 COLOR = 15
Elementary Programming
and run the program again. Try to list the program. Notice that
you only see lines 240 and 250. The rest of the listing slips
through the narrow text window at the bottom of the screen .
This will continue to happen unless you type
TEXT
HOME
to get rid of the garbage on the screen before you use the LIST
statement.
Now replace lines 220-250 with the following , and then list the
program (while you are still in text mode).
220 COLUMN = 0
230 VLIN 0, 39 AT COLUMN
240 COLUMN = COLUMN + 1
250 IF COLUMN < 40 THEN GoTo 230
Because you haven 't typed NEW, the old line 200 is still around . So
long as it is in the computer's memory (and it will be until you type
NEW , turn the computer off, or change the lines), you can use it in
your program.
-
Figure 2-7. The VL I N Loop Program
If the value of the variable COLUMN is - - 250 I F COLUMN < 40 THEN GOTO 230
less than 40 (if the assertion is true),
the program loops back to line 230
and draws a new vertical line in the
new column . When the value
of COLUMN reaches 40 (remember,
the rightmost column on the screen is
39) , the program stops.
Observe what happens when you run the program now. Try
typing something else. What you type doesn't show up because
the program is running continuously : it keeps going back to line
210 over and over. To stop the program, typetoNTRoq-C . To get
it going again, type CDl'H.
Remarks
As you can see from the description of the last program, what
happens on any given line can be complicated. There is a
statement in Applesoft especially for explaining what is going
REM is a statement that allows you to to happen : REM. It stands for " remark."
put remarks , or commentary, in a
program .
The computer ignores REM statements ; they are strictly for the
benefit of people. See how easy it is to follow the VL I N loop
program shown in Figure 2-8 when REM statements are used
liberally:
Elementary Programming
Figure 2·8. Using REM Statements in a
Program Program with Remarks Program without Remarks
195 REM SET GRAPHICS MODE
200 GR 200 GR
205 REM SET COLOR
210 COLOR = 15 210 COLOR = 15
If you look carefully you will see that the program still gives the
same instructions as it did before. The added REM statements
simply explain what the line (or lines) following them will do.
NEW
100 FOR NUMBER = 0 TO 12
110 PRINT NUMBER
120 NEXT NUMBER
130 PRINT "PROGRAM IS FINISHED WHEN LAST NUMBER
IN THE FOR STATEMENT IS DISPLAYED"
FOR/NEXT Loops
II
Run this program. You see that it does essentially the same
thing as the number counting program you produced with
Figure 2-9. The FOR INEXT Statement.
The line-by-line explanations could be IF ... THEN. Figure 2-9 explains how the FOR /NEXT program
inserted in the program as REM works.
statements.
•
Sets range of the variable NUMBER to - - 1 00 FOR NUMBER • 0 TO 12
0- 12 .
NEW
3000 GR
3005 REM SETS VARIABLE RANGE TO 0-15
3010 FOR ROW = 0 TO 15
3015 REM MAKES VALUE OF COLOR THE SAME AS VALUE
OF VARIABLE
3020 COLOR = ROW
3025 REM DRAWS HLIN AT EACH ROW WITHIN RANGE
3030 HLIN 0, 39 AT ROW
3035 REM WHEN LIMIT OF RANGE IS REACHED, PROGRAM ENDS
3040 NEXT ROW
To leave the graphics mode, type TEXT; type HOME to clear the
screen. Now look at the two programs that follow. They show
two ways to print the even numbers from 0 to 12. The first uses
IF ... THEN:
Elementary Programming
NEW
100 X= 0
11 0 PRINT X
120 X= X + 2
130 IF X (= 12 THEN GOTO 110
You may be wondering why you see two sets of even numbers
from 0 to 12 on your screen . Type LIST to see if you can figure
out why.
RUN 200
Notice that the statement RUN 200 also executes lines 210 and
220 because all line numbers larger than the one indicated in a
RUN statement are executed .
FOR/NEXT Loops
Nesting and Crossing Loops
Along with the convenience of the FOR statement come some
limitations. For example, FOR/NEXT loops can be nested ,
meaning one loop may be contained inside another, but
FOR/NEXT loops must not cross. Figures 2-10 and 2-11
-
demonstrate nested and crossed loops.
Figure 2-10. Nested Loops: the HUE
Program
NEW
300 GR
310 FOR HUE · 1 TO 15 - - --,
320 COLOR • HUE
330 FOR ROW • 0 TO 39 ----,
340 HLIN 0, 39 AT ROW ~
350 NEXT ROW _ _ _ _ _ _ ...J
360 COLOR • HUE - 1
370 FOR COLUMN • 0 TO 39l
380 VLIN 0, 39 AT COLUMN
390 NEXT COLUMN _ _ _ _ _....J
400 NEX T HUE _ _ _ _ _ _...J
• Warning
When writing programs using FOR statements, remember that each
FOR must have a matching NEXT.
This program doesn 't work correctly. Type TEXT , HOME , and RUN .
It is an example of what happens when each FOR doesn 't have a
matching NEXT. The program's loops are crossed , so it jumbles
the numbers as it displays them. It also gives an error message.
See if you can fix the program by uncrossing the loops.
Elementary Programming
The quilt drawing program in Figure 2-12 has three-level
nesting. QU I L T can be loaded from the APPLESOFT SAMPLER.
This program avoids using COLOR as a variable name because,
as you may recall , COLOR is a reserved word in Applesoft.
-
Applesoft..
Figure 2-12. Three-Level Nesting : the
QU I L T Program
NEW
400 GR
410 HUE· 0
420 FOR COLUMN • 0 TO 35 STEP 5------.
430 FOR LINE · 0 TO 30 STEP 10----~
440 HUE • HUE + 1
450 IF HUE) 15 THEN HUE · 0
460 COLOR • HUE
470 FOR ROW· LINE TO LINE + 9~
480 HLIN COLUMN,COLUMN + 4 AT ROWj
490 NEXT ROW -
500 NEXT LINE
510 NEXT COLUMN _ _ _ _ _ _ _ _ _ _- - l
e Pause
NEW
100 PRINT "MELLOW"
110 GoTo 100
and run the program again. The program now prints the word in
columns. Use CoNTRoL-C again to stop the program, and then -'
substitute a semicolon (; ) for the comma (, ).
Run the program again. This time the display runs together,
leaving no spaces between the words. It prints MELLOW after
MELLOW until you stop the program with CONTROL-C .
90 V = 99
100 PRINT V
100 PRINT V,
Elementary Programming
Run it again . Then change the comma to a semicolon
100 PRINT V;
and observe that the comma and semicolon also can be used
with numeric values. The ability to place numbers one after the
other without intervening spaces is sometimes quite usefu l.
100 BALLS = 3
110 STRIKES = 2
120 PRINT BALLS,STRIKES
RUN
• 3 2
120 PRINT "THE BALLS AND STRIKES ARE ";BALLS , STRI KES
unless you didn 't include a space after ARE . Another way of
writing the statement is
120 PRINT "THE BALLS ARE ";BALLS ; " AND THE STRI KES
ARE ";STRIKES
Perhaps the prettiest way to print this line (are you trying all of
these on the Apple lie?) is to add some spaces within the
PR I NT statement
BALLS 3 STRIKES 2
Now let's say you wanted to display the word HERE in the 10th
column (the screen is 40 columns across). You could use the
statement
making sure that you carefully added exactly nine blanks before
The display function TAB , which must the word HERE. Or you could use the TAB feature, which lets you
be used in a PR I NT statement, moves set a tab in your programs that acts like a tab on typewriters. Try
the cursor through tab fields on the
screen .
the statement
NEW
200 FOR N = 1 TO 24
210 PRINT TAB(N);"X"
220 NEXT N
There are two related statements you can use to position the
cursor in various parts of the screen .
VTAB moves the cursor to the VTAB moves the cursor vertically up or down the 24 horizontal
specified vertical row on the display display lines. The top line is line 1; the bottom line is line 24.
screen .
VTAB, unlike TAB, is not used within a PR I NT statement.
II Elementary Programming
The HTAB statement moves the cursor You can tab horizontally with HTAB. It works like TAB , but can
either left or right to the specified cause printing to begin either to the left or to the right of the
column (1 through 40) on the screen .
current printing position and does not have to be used with the
PR I NT statement. The leftmost character on a line is in position
1, while the rightmost character is in position 40.
10 PRINT "RUN"
20 HTAB 5
30 PRINT "FASTER, "
40 HTAB 34
50 PRINT "FASTER,"
60 HTAB 81
70 PRINT "OR ELSE!"
NEW
590 HOME
600 FOR X TO 24
610 FOR Y TO X
620 HTAB X
630 VTAB Y
640 PRINT "APPLE"
650 NEXT Y
660 NEXT X
670 GoTo 600
Before you run this program , try (it isn 't easy!) to figure out what
it will do.
While TAB, HTAB , and VTAB act somewhat like the coordinates in
PLOT, there are some differences.
NEW
300 FOR K = 1 TO 255
310 PRINT TAB(K); K
320 NEXT K
310 HTAB K
320 PRINT K
and add
330 NEXT K
II Elementary Programming
NEW
10 HOME
20 INPUT "WHAT IS YOUR FIRST NAME?II; N$
30 PRINT
40 FOR A = 1 TO 5
50 PRINT TAB (A); "H I , II,, NS; II , HOW ARE YOU?II
60 NEXT A
Th e EtiD statement causes a program 70 END
to cease execution and returns
con trol to the user.
List this program to check your typing , correct any mistakes you
might have made, and run it. If you like it, and you want to store
it on a disk for future use, all you need to do is type
SAVE WELCOME
Elementary Programming
Making Changes
Making Changes
Making Changes
You also know that when you notice a mistake after you have
pressed ~ ETUR H, you can type the line over again.
• To get into escape mode press the /Escl key. To leave escape
mode press the lsPAcEI bar. Once you are out of escape
mode all you have to do to -get back in is press the lEs cl key.
• To correct or change something using escape mode, you
must position the cursor over the first dig it in the line
number of the line you wish to fix.
• Escape mode allows you to correct only one program li ne at
a time.
Making Changes
II
• After you make a change in a line it is important to copy
over the remainder of the line with the [R I GHT - ARROW] key.
• The [@8]- and [LEFT -ARROW[ keys work differently in
escape mode than they do in normal mode. In escape mode,
they move the cursor around without affecting the
characters on the screen . The arrow keys used alone
(without pressing the[§]] key first) erase (ILEFT-ARROW~ and
copy over ([R I GHT - ARRowD the characters they go over.
---------------------------------------------------~
A Practice Session
There are several mistakes in the lines below. If you follow the
step-by-step instructions, you will get an idea of how escape
mode works.
Type exactly what you see: All the mistakes you type
appear on the screen .
NEW
10 PRINT "THE MOCKINGBIRD"
20 PRINT TAB (5); "SINGS"
30 PRINT RAB (3): "IN
SPRING"
Press and release the [ESC ) This puts you into escape
key once. mode.
Press the luP-ARROwl key two The cursor is moved to line 10.
times .
II Making Changes
Press thelbIti:ARRDw lkey Notice that the cursor moves,
once. The cursor must be but nothing else changes on
placed over the first digit. the screen while you are in
escape mode. (You can 't see it,
but nothing changes in the
computer's memory either.)
•
Press the lsPACE lbar. This takes you out of escape
mode.
Press the [RIGHT-ARRDw lkey The [RI GHT - ARRowl key copies
five times. over characters when you are
not in escape mode (so you
don't have to type them over) .
•
--
I
• L=:- >=,
: ~- = = = -: - -....: ~ -: = = =-_:;:: ===:
I-
•
If you were to run the program now, a ?SYNTAX ERROR IN 30
would appear on the screen because there are two
mistakes in line 30 that you haven 't fixed yet. RAB should be
TAB , and the colon should be a semicolon. To correct line 30,
first type LI ST , then get into escape mode by pressing the
IEsel key, and use the arrow keys to move the cursor to the
beginning of line 30.
Follow the same procedure you used for line 10: leave escape
mode, use the !RIGHT-ARRow lkey to move the cursor over the
offending characters, replace them, and copy the remainder of
the line. List again , to make sure you have corrected all the
mistakes, then run.
Making Changes
the right edge, and all around. What happens when the cursor
gets to the right edge of the screen? (Hint: it wraps around. You
saw this when you used TAB and HTAB.) What happens when
you accidentally press some other key while you are in escape
mode? Try it-finding out how it works now will save you some
headaches later. When you get tired of moving the cursor
around the screen , press the [SPAcE ibar to leave escape mode.
Helpful Hints: If you don 't position the cursor over the first digit in
the line number of the line you want to fix, some of the line will be
lost. If you don 't believe this, try it!
The reason you corrected line 10, listed it, and then corrected line
30 is because it is difficult to correct more than one line at a time in
escape mode.
Type
NEW
90 PRINT "THIS IS A SHORT PROGRAM"
Use RUN to see how the line
looks .
•
Press the [ES 9 key. This puts you into escape
mode.
•
Press ~ . This puts you back in escape
mode.
•
Press the §PACE) bar once. This takes you out of escape
mode.
Making Changes
Type TAB (10); This is the text you are add ing
to the line.
•
Press lEscl· This returns you to escape
mode.
•
Press thelLEFT-ARRowlkey This returns the cursor to the
eight times. point at which you began the
insertion . It allows you , after
you leave escape mode, to
copy over the remainder of the
line with theIRIGHT - ARROw l
key.
•
Press the ISPAC © bar once. This takes you out of escape
mode.
•
Inserting Text into an Existing Line
II
Press the SC key. This step, and the two that
follow, moves the cursor to
the right without copying the
spaces between PROGRA and
M. See the Helpful Hints that
follow for more information.
Press theiRIGHT-ARRowlkey
until the cursor is on the M•
•
Press the [SPACE lbar. This takes you out of escape
mode.
-
[RETURij. LI ST the line.
Making Changes
Now try adding VERY before SHORT in the same line. When you
are finished, the statement should LIST as
•
Helpful Hints: App lesoft uses a screen width of 40 columns-
that is, up to 40 characters can be displayed on a single line. Any
line longer than 40 characters is automatically wrapped around to
the next line and indented. When you are changing such a program
line, you must use escape mode if you don 't want the automatic
indentation copied into your revised line. This is what you were
doing when you went back into escape mode between the A and M
of PROGRAM. When the cursor is over the first character of the
second line, leave escape mode and use theiRI GHT -ARRowl key to
f inish copying.
There is also a statement you can use to narrow the screen w idth
and to instruct Applesoft to stop adding those extra spaces:
POKE 33.33 . You don 't need to learn about it now, but you can find
out about' it in the Applesoft Reference Manual when you are ready.
If you have just finished typing the line and change your mind
about it before you press~ETURH , there is a control character
you can use: ICONTROLH . Try it out by typing the line below.
Before you press lRETuRft hold the ~ONTRO q key while you
press the X key. If you torget and pressBETURNI before using
~ONTROq-x , you'll have to type NEW and try again.
As you see in the illustration and on your screen (you are doing
these exercises, aren't you?), a slash appears at the end of the
line when you usei¢oNTRoq-X . When you try to list the line,
nothing appears. You really have gotten rid of that line!
Now type
and pressBETuRHj , It you change your mind about this line now,
there are several alternatives. One is to replace the line by
typing it over with a different statement, as in
However, if you want to eliminate the line entirely, you can type
20
and it will disappear. If you don 't believe it, type LIST 20 .
Making Changes
which instructs the computer to delete a line or lines. Since it is
obviously easier to type 20 by itself than to type DEL 20,20 , you
may be wondering why the DEL statement is so great. It's not
apparent until you want to erase five or ten lines of a program .
Instead of having to type each line number separately, you can
type
DEL 10,90
This will delete every statement with line numbers between and
including 10 and 90.
The DEL statement in Applesoft looks like, but is not the same as,
the DELETE command used by the Disk Operating System (DOS) .
DELETE is a DOS command that DELETE is always used to delete entire programs from the disk and
removes the program specified by is always followed by the name of the program you want to remove
name from a disk. from the disk.
ThelDELETEI key on the Apple lie's keyboard is not the same as the
DEL or DELETE commands. See the Apple lie Owner's Manual and
the Apple lie Reference Manual for more information.
However, these uses of escape mode are a bit down the line.
A more handy tool for the present involves the use of
~OtiTROQ-S stops and resumes ICotHROU- 5 .
program listing.
LIST 10,100
and then
LIST 110,200
and then
LIST 210,300
A Little History
Eight other keys, besides the four arrow keys, can be used for
editing . If you are familiar with older models of the Apple, you
may know what those keys are. In any case, a little history is in
order.
II Making Changes
Later, this method was changed: one press of lEscj was enough
to get you into escape mode. However, the keyboard still had no
arrow keys. The four keys I , J, K, and M were used to move the
cursor. If you look at the keyboard , you 'll notice that those keys
form a diamond. Their directions are consistent with their
position: I moves the cursor up, J moves it to the left, M moves
it down, and K moves it to the right.
Figure 3.1. Key Directions Although arrow keys have been added , I , J , K, and M still work
in escape mode. And you can sti II use A, E , C, and D to move the
cursor if you precede each with !EScl. If you happen to have
learned one of the older methods, you can continue to use it
and not worry about changing to the arrow keys. Or you may
find that you like one of the older methods better. The Apple lie
was designed so that all three keys move the cursor in the same
direction. Figure 3-1 summarizes the directions.
A Little History
II
Summary of Editing Features
Escape Mode
Non-Escape Mode
To delete a character : Press thelLEFT -ARROWI key
Making Changes
Lots of Graphics
Lots of Graphics
--------------~~
Lots of Graphics
Now that you have a few more editing tools at your fingertips,
you are probably anxious for more programming challenges.
This chapter takes a great leap forward, leading you through
the construction and modification of longer and more
complicated programs. You will see how programs are built
piece by piece and how statements work as building blocks.
See Chapter 2, " Using the Before going further, load the program COLORBOUNCE from the
APPLESOFT SAMPLER : APPLESOFT SAMPLER by typing
COLORLOOP " for more information .
LOAD COLORBOUNCE
If you are not using a disk drive, turn to "The Whole Thing " in this
chapter. Type the program in, check your listing, then execute it.
To stop the program, press ICONTROLI- C. Now read the next few
sections to find out how the program works. Each section
discusses a different element of the program.
Lots of Graphics
Multiple Statements on a Line
Up to now most of the program lines you have worked with
contained one statement in each line. With this method you
might begin a program with (remember, you don 't have to do
anything but read this section):
On a program line using the colon and more than one statement,
remarks must be the last on the line.
Lots of Graphics
Creating Motion
The bouncing ball , which is really a brick plotted and moving on
the graphics grid , is created with six variables in COLORBOUNCE :
1. Set some limits in the program so the ball doesn 't appear to
move off the screen.
2. Change the direction of the ball when it reaches the edge of
the screen.
In other words, when the ball reaches the limit of the screen , 39 ,
line 580 changes XV to a negative XV . Then when line 540 is
reached in the next loop, NX becomes 38 . In the loop after that,
NX becomes 37, and so on , until the ball reaches the other
screen edge, at which point 1 is added to the value of NX with
each loop. This is how the direction is changed back and forth .
Lots of Graphics
Creating Visual Impressions
By alternating between black and a color for the ball each time
a new position is plotted for X and Y, you can make it look as if
the ball is being erased, adding to the visual effect of the ball 's
motion. This is done in CoLoRBoUNCE with the following lines:
If the order of these statements doesn 't make sense to you , try
moving them around and running the program with your
changes incorporated .
LIST 400,580
LI ST 600,780
Lots of Graphics
You have to be careful how you word the statement because
COLOR is a reserved word . If, for example, you added the line
the program would get stuck : COLOR can 't be used as a var iable
name. You could , however, write line 350 as
If you haven 't done so, add these lines to COLORBOUNCE . Then
run it to see how the lines work. (When the program executes
line 350, the word COLOR , followed by a question mark (?) , will
appear on the screen . The cursor will keep blinking until
someone types a number and pressesIRETURNI.)
You may know what to do when you see the question mark.
However, your friend may not. So it is a good idea to have the
program tell your friend (the user) what is expected . Adding
some PR I NT statements and changing to text mode at the
beginning of the program will do the trick :
Adding the new lines 280 to 350 to CDLDRBDUNCE will make the
program much more friendly for users. But there still are some
potential pitfalls for people who are not used to computers.
What if someone makes a mistake and then presses[RETURN r
Instant error messages and loud beeps!
will appear on the screen and then the program will stop. For
the most part, your friends will not know how to restart the
computer-and shouldn 't have to. Therefore you should make
the program check the number typed in by the user before
proceeding. These lines will do it:
• P?REEHTER
~?
will appear on the screen. You ' ll learn how to modify the
program to avoid this in Chapter 5 .
Lots of Graphics
It is good programming practice to make a program as
foolproof as possible. You have gotten to the point where
you are writing error messages for others to read . It may be all
right for a programmer like you to deal with such jargon as
?SYNTAX ERROR , but an innocent user shouldn 't have to.
Each time you use an I NPUT statement you should make your
program check what the user enters so the program doesn 't fail
in any way. Dealing with the untutored user (and you must
assume that users are not programmers) is an art in itself. Use
of specifically worded I NPUT statements and careful checking of
the user's response are always required.
Each time you save a different version of a program, you must give
the version a new name. Otherwise the old version will be written
over and lost.
e Pause
Making Sounds
Clicks, ticks, tocks, and various buzzes are easily generated by
the Apple lie. You can make sounds on your computer if you tap
it, scratch your fingers across it, or drop it, but the sounds you
are about to make are produced by programming it.
NEW
150 SOUND = PEEK(-16336>
Making Sounds
The PEEK function returns the PEEK is a function . In Applesoft a function is something that
contents, in decimal form , of the byte
takes one or more numbers and performs some operation on
at the memory address specified by
the argument. them to yield a single value. Applesoft has a number of built-in
arithmetic functions (like SQR, which finds the square root of a
number); some other functions can be derived . The Applesoft
Reference Manual discusses all of Applesoft 's functions.
100 5 = -16336
II Lots of Graphics
To produce a nice, resonant click, change line 150 to
For a more buzzy tone, put one of your variations into a loop. In
general, the faster the loop, the higher the pitch.
To produce even higher tones on the Apple lie, try these lines:
NEW
40 FOR PAUSE = 1 TO 2500 : NEXT PAUSE
50 5 = PEEK(-16336) : GOTO 50
To put these sound tricks to good use, load your most recent
version of COLORBOUNCE into the computer. List it, and study the
lines. Then try to add a sound for each time the ball bounces off
a wall.
Making Sounds
Noise for the Bouncing Ball
Here is one way to make the bouncing audible. Add these lines
to COLORBOUNCE:
Now try your own sounds. Why not make a different sound
bounce off each wall? When you find a sound combination you
like, don 't forget to save a new version of COLORBOUNCE with the
noisemaking lines included. The remainder of this chapter will
introduce some new programs and concepts; we' ll return to
COLORBOUNCE in Chapter 5.
e Pause
Random Numbers
Here's another Applesoft function . Try it (remember you can
stop it when you want with ICONTRO L]- C) :
NEW
100 PRINT RND(1)
110 GOTO 100
RUN
The arithmetic function RND returns a RND in line 100 stands for "random ." The RND function produces
random real number greater than or random numbers. Each time you run it, you 'll see a different
equal to zero and less than one.
sample of numbers. Try it!
Lots of Graphics
The numbers generated by this program are random decimal
fractions between zero and one. Any argument (the number in
parentheses) greater than zero will return random decimal
fractions between zero and one. Try, for example, changing
line 100 to
Although you won 't be dOing it in this tutorial, you can produce
different effects by using an argument of zero or an argument of
less than zero. See the Applesoft Reference Manual for more
information.
NEW
90 REM ASSIGNS RND NUMBER TO X
100 X = RND(1)
11 0 REM MULTIPLIES X BY 10
120 X = X * 10
130 REM CHOPS OFF THE FRACTI ON
140 X = I NT<X)
150 PRINT X
160 GOTO 100
The I NT function returns the largest Line 140 introduces I NT , the integer function. The statement
i nteger less than or equal to th e given x = I NHX) returns the largest integer that is less than or equal
argumen t .
to the value of X. For instance, if the value of X is 3.6754 , t hen
I NT<X) is equal to 3; if the value of X is -45.12345 , then
I NT< X) is equal to - 46. The parentheses after I NT can contain
any arithmetic expression or numeric variable.
Now run the program . Does it work the way you expected?
145 X = X + 1
Random Numbers
III
This program may seem a little complicated at first. To see
what happens step by step add lots of PR I NT statements. The
following program shows how. However, you don 't have to type
in the additions. The program RANDOM on the APPLESOFT
SAMPLER disk is the same as what you see.
Load and run this program to see what happens. To change the
way the numbers are displayed, you can remove the comma (,)
and the X from the end of line 160, change line 170, and add line
175, like this:
Study this line until you figure out how its parts correspond to
each of the lines in RANDOM .
II Lots of Graphics
Simulating a Pair of Dice
Now you can use what you 've learned about random numbers
to make a program act like a pair of dice.
NEW
100 PRINT "WHITE DICE",
110 PRINT INT (6 * RND(1) ) +
120 PRINT "RED DICE",
130 PRINT INT (6 * RND(1) ) + 1
Random Graphics
Here's a colorful way to combine the RND function w ith some
graphics statements :
NEW
200 GR
210 REM CHOOSE A RANDOM COLOR
220 COLOR = INT (16 * RND(1) )
230 REM CHOOSE A RANDOM POINT
240 X = INT (40 * RND~1) )
250 Y = INT (40 * RND(1) )
260 REM PLOT THE RANDOM POINT
270 PLOT X, Y
280 REM DO IT AGAIN
290 GO TO 220
Random Numbers
Try using RND in other programs. Can you write a program that
draws random lines in random colors across the screen? How
about a program that shades the graphics screen with random
colors?
NEW
1000 REM DRAW BLUE HORSE WITH WHITE FACE AND ORANGE
FEET
1010 GR
1020 COLOR = 2 : REM DARK BLUE
1030 PLOT 15,15
1040 HLIN 15,17 AT 16
1050 COLOR = 9 : REM ORANGE
1060 PLOT 15,17
1070 PLOT 17,17
1080 COLOR = 15 REM WHITE
1090 PLOT 14,15
Lots of Graphics
There is nothing wrong with this program: it draws a blue horse
with orange feet and a white face. Sut suppose you wanted to
draw another horse somewhere else on the screen . You could
rewrite this program with new values for x and Y, but that is a
bother. There should be some way of using the same program to
put a figure anywhere on the screen without having to rewrite it
each time.
With these ideas in mind, you can rewrite the horse program to
place the horse at almost any point (x, Y) on the screen . Why
almost any point? Because if the center of the horse is plotted
at the edge of the screen, part of the horse will go off the
screen. This might give you an ? I LLEGAL QUANT I TY ERROR
IN 1030 message. The number at the end of the error message
identifies the line at which the error occurs and makes it easier
for the programmer to correct the problem. Here is part of an
improved program :
NEW
1000 REM PUT A HORSE ANYWHERE ON THE SCREEN
1010 COLOR = 2 REM DARK BLUE BODY
1020 PLOT x, Y - 1 : REM CENTER OF HORSE
1030 HLIN X, X + 2 AT Y : REM REST OF BODY
1040 COLOR = 9 REM ORANGE FEET
1050 PLOT X, Y + 1 : REM FRONT FOOT
1060 PLOT X + 2, Y + 1 : REM REAR FOOT
1070 COLOR = 15 : REM WHITE HEAD
1080 PLOT X - 1, Y - 1
This program can't be run as it is. You must set the graphics
mode and choose x and y:
20 GR
30 REM FIRST HORSE CENTER
40 X 12
50 Y = 35
When you execute this, you will get one horse at the desired
location before the program ends. But you still want to put two
horses on the screen. What if you could write what you see in
Figure 4-2:
Wouldn 't that be nice and easy? The problem is that the
computer can't read those strange instructions in lines 60 and
100. It can, however, read the statement
1090 RETURN
Lots of Graphics
Combining all these lines, you have that " what if you only
could " program :
20 GR
30 REM CHOOSE CENTER OF THE FIRST HORSE
40 X = 12
50 Y= 35
60 GOSUB 1000
70 REM CHOOSE CENTER OF THE SECOND HORSE
80 X = 33
90 Y = 2
100 GoSUB 1000
1000 REM PUT A HORSE ANYWHERE ON THE SCREEN
1010 COLOR = 2 REM DARK BLUE BODY
1020 PLOT X, Y - 1 : REM CENTER OF HORSE
1030 HLIN X, X + 2 AT Y : REM REST OF BODY
1040 COLOR = 9 REM ORANGE FEET
1050 PLOT X, Y + 1 : REM FRONT FOOT
1060 PLOT X + 2, Y + 1 : REM REAR FOOT
1070 COLOR = 15 : REM WHITE HEAD
1080 PLOT X - 1, Y - 1
1090 RETURN
If you run this program , you 'll get the error message
You'll find out how to fix the program to avoid this error shortly.
Keep reading! However, despite the error message, the program
runs fine. You have just created a horse-drawing routine. Now
use the statement
GoSUB 1000
10 TRACE
DEL 20,20
To leave the graphics mode and clear the screen , type TEXT and
HOME . Then run the program .
TRACE shows that the program begins at line 10, the smallest
line number, and continues until it reaches line 60 , which sends
it to the subroutine. It executes the subroutine, returns to the
main program at line 1090, then executes the subroutine again.
When it reaches line 1090 again , not finding any smaller line
numbers, it goes to line 1000 and executes the subroutine
again. This is where the problem occurs. Do you understand
the error message now?
Lots of Graphics
To remedy the problem of endless repetition , add this new line
to the program:
Th e NOTRACE statemen t turns off If you want to TRACE only part of a program , use the NOTRACE
TRACE . statement. Add this line:
65 NOTRACE
TRACE can also be issued when you are working w ithout line
numbers in immediate execution , TRACE and then RUN. It is not a
good idea to try it out now, unless you save the current version of
the horse-drawing program first.
If there is any attempt to locate a horse off the screen , the horse
will be moved to the nearest edge. There are other programming
strategies, such as giving an error message and stopping the
program . However, limiting the range of the horse has the
advantage of not stopping the program.
Note that line 1000 is slightly different from the old line 1000 ;
the rest of these lines are additions to the subroutine.
Variables
As you have already discovered , using variables instead of
specific number assignments for colors gives a program more
flexibility. If, for example, you wanted to add a second player to
the game and give that player a horse of a different color, you
could replace line 1 01 0 COLOR = 2 with
Lots of Graphics
Then the main routine would change to :
20 GR
30 REM FIRST PLAYER'S HORSE COLOR
40 BODY 2 : REM DARK BLUE
50 FEET = 9 : REM ORANGE
60 FACE = 15 : REM WHITE
70 REM FIRST PLAYER'S HORSE CENTER
80 X = 15
90 Y = 30
100 GoSUB 1000
and so on . Now you add the lines for the second player's horse
color. Be sure to include an END statement. Run the program to
see the two horses displayed. Change your program lines until
you have color combinations you like.
Additional Subroutines
To refine the horse-drawing program even more, use
subroutines that assign the colors for each player's horse and
then have each of those subroutines go to (or call) the horse-
drawing subroutine in turn . Here are two examples :
2000 REM DRAWS BLUE HORSE WITH ORANGE FEET AND WHITE
FACE
2010 BODY 2 : REM DARK BLUE
2020 FEET 9 : REM ORANGE
2030 FACE 15 : REM WHITE
2040 GoSUB 1000
2050 RETURN
2500 REM DRAWS ORANGE HORSE WITH PINK FEET AND GREEN
FACE
2510 BODY 9 : REM ORANGE
2520 FEET 11 : REM PINK
2530 FACE 4 : REM GREEN
2540 GoSUB 1000
2550 RETURN
But first, another handy subroutine that replaces the old one at
lines 1012-1018:
A Well-Structured Program
Here is the whole program. It combines the main routine with
three subroutines. You can change the program you have been
typing in to match what you see or load HORSES from the
APPLESOFT SAMPLER.
Lots of Graphics
10 REM SET GRAPHICS MODE
20 GR
30 REM CHOOSE A RANDOM POINT
40 GOSU8 3000
50 REM PUT A 8LUE HORSE THERE
60 GOSU8 2000
70 REM CHOOSE ANOTHER RANDOM POINT
80 GOSU8 3000
90 REM PUT AN ORANGE HORSE THERE
100 GOSU8 2500
110 REM DO IT ALL AGAIN
120 GOTO 30
This is how a main routine should look if you are writing well-
structured programs: mostly REM and GOSU8 statements. The
work should be done in relatively short subroutines, each of
which is easy to write and complete in itself.
5 TRACE
130 NOTRACE
and then RUN . Compare what you see on the screen with the
program listing until you can follow the subroutines.
e Pause
High-Resolution Graphics
So far, you have used low-resolution graphics. In this section
you will be introduced to another kind of graphics called high-
resolution graphics.
High-Resolution Graphics
Figure 4-4. High-Resolution Graphics
Screen Coordinates. The horizontal o 50 100 150 200 279
coordinates range from 0 to 279 ; o
the vertical coordinates range from
o to 159.
50
100
150
159
[
Co:: :
Type
Helpful Hint: If the cursor is not visible, press RETURN until the
cursor appears near the bottom of the screen.
Lots of Graphics
High-resolution graphics is truly wonderful , but you have to
make some sacrifices to use it. There are fewer numbers
assigned to HCOLOR= , and the colors vary according to their
positions on the screen. Look at Figure 4-5 to see which number
goes with which color.
o black1 4 black2
1 green 5 orange
2 violet 6 blue
3 white1 7 white2
High-Resolution Graphics
II
To tryout high-resolution graphics, once you have issued the
HGR statement, type
HCOLOR = 2
HPLOT 130,100
HPLOT 50,50
and so on. Notice how much smaller the plotted points appear
in high resolution. This mode makes it possible to create images
with much more detail than you can achieve in low resolution.
HCOLOR = 1
HPLOT 0,0 TO 279,0
II Lots of Graphics
If you then want to draw a line from the corner at point 279 , a to
the bottom corner of the screen all you have to do is type
HPLOT TO 279,159
and a line appears along the right edge of the screen. When you
use this last statement, the new line takes its starting point and
its color from the point previously plotted (even if you have
issued a new HCOLOR= command since that po int was plotted).
To see for yourself, type
HCOLOR = 4
HPLOT TO 0,159
The color 4 is black so you would think the line wouldn 't show
up. But it does because it takes its color from its starting point,
which is green (number 1).
HCOLOR = 3
HPLOT 0,0 TO 279,0 TO 279,159 TO 0 , 159 TO 0 , 0
High-Resolution Graphics
If the top line is not visible on your screen, your television set or
video monitor needs adjustment. Try adjusting it. If that doesn't
work, replace HPLOT 0,0 TO 279,0 with HPLOT 0 ,2 TO 279,2
and so on .
Lots of Graphics
1. The center of the high-resolution screen is at the
intersection of four points, or dots, and cannot be precisely
plotted. Thus "CENTER" in lines 280 and 400 is approximate.
2. One instruction can provide the NEXT for more than one FOR
statement, as you see in lines 320 and 440. Be careful that
you list the NEXT variables in the right order, though , to
avoid crossed loops.
Can you think of ways to change the program? For example, try
making the value of HCOLOR= change randomly. Try drawing
orange then blue lines, or only blue lines.
High-Resolution Graphics
Chapter Summary
Statements Terms
PEEK
RND address
INT function
GOSUB byte
TRACE kilobyte
NOTRACE memory
END subroutine
HGR rout ine
HCOLOR= high-resolution graphics
HPLOT
Error Messages
?REENTER
?RETURN WITHOUT GOSU8 ERROR
II Lots of Graphics
Strings and Arrays
L..
d Stringing Along
A string , or bunch of characters, is a type of variable. String
variable names follow the same rules as numeric variable names
except they end with a dollar sign ($) . Here are some examples
of possible string variable names :
A$
MYNAME$
SENTENCES$
A$ = "HARRY 5 TRUMAN"
or
PRINT NAME$
will print the contents of the variable NAMES : in this case the
name of the 33rd president of the United States.
String Functions
There are several Applesoft instructions that manipulate strings.
Suppose you want to know the length of a string (how many
The string function LEN returns the characters it contains). You can use the length function, LEN , by
number of characters in a string typing
(specified in parentheses) between
o and 255.
PRINT LEN ("HARRY 5 TRUMAN")
and Applesoft will display the length of the string. As you see
(double-check by counting the characters yourself) the length
of the string NAMES is 14. Remember that the computer counts
spaces and punctuation as characters.
If, for instance, you want to PR I NT the first five letters in NAMES ,
type
• HARRY
• RUMAN
will appear.
Here's a short program that uses the functions LEN and LEFTS .
NEW
90 NAMES = "HARRY S TRUMAN"
100 FOR N = 1 TO LEN(NAMES)
110 PRINT LEFTS(NAMES,N)
120 NEXT N
PRINT MIDS(NAMES,7)
Stringing Along
II
• 5 TRUMAN
Do you get what you expect when you run the program?
Don 't go any further in this book until you 've thoroughly tested
the LEFTS, RIGHTS, and MI DS functions. Or else !
Run ALPHABET now. Then try changing line 200, and run it
again. Feel free to modify this program and change it in any way
you like.
Stringing Along
Duplicate Strings
You can duplicate a string by using a replacement statement
such as
XS = AS
XS = MIDS (AS,24,3)
Backward Spelling
Would you like the Apple lie to spell your name backward? Well ,
here's your big chance! This program will do just that.
NEW
100 REM PROGRAM TO SPELL YOUR NAME BACKWARD
11 0 I NPUT "TYPE YOUR NAME AND I WILL SHOW IT
TO YOU SPELLED BACKWARD. "jN$
120 REM REVERSE ORDER OF LETTERS
130 FOR T = LEN(NS) TO 1 STEP -1
140 RS = RS + (MID$ (NS,T,1»
150 NEXT T
160 PRINT : PRINT "YOUR NAME SPELLED BACKWARD
IS "jR$
170 PRINT: PRINT
180 GOTO 110
175 R$ = II II
Now run the program again. By using the null string near the
end of the program, the contents of R$ can be set to zero
characters after the backward name has been displayed. Then,
when the program goes back to line 110 and starts over, R$ will
be set to the new name rather than filling up with and displaying
all previous names.
CLEAR sets all variables, including There is an Applesoft statement, CLEAR, that resets all variables
strings and arrays, to zero . It is very of every size and shape, but it should be used in immediate
tricky to use within programs.
execution . Type
N = 254
PRINT N
Now type
CLEAR
and then
PRINT N
Stringing Along
Concatenation Got Your Tongue?
It is possible to add a second string onto the end of an
existing string using the plus (+) sign. This process is called
concatenation. Try the following:
C$ = "GOOD MORNING"
D$ = C$ + ", " + "BILL"
PRINT D$
and
NEW
100 INPUT "GIVE ME ABOUT HALF OF A SENTENCE. "; HALF$
105 PRINT
110 INPUT "NOW GIVE ME THE SECOND HALF OF THE
SENTENCE. "; oTHERHALF$
120 WHoLE$ = HALF$ + " " + oTHERHALF$
130 PRINT
140 PRINT WHoLE$
150 PRINT: PRINT: PRINT: GoTo 100
C$ = "123"
PRINT C$ + 7
The Apple lie will give you a ?TYPE MISMATCH ERROR . However,
The VAL function attempts to the VAL function (short for "value") can alleviate this problem .
interpret a string , up to the first The VAL function returns the value of the contents of a string as
nonnumeric character, as a real
number or an i nteger, and returns opposed to its actual contents. Type
the value of that number.
PRINT C$
PRINT VAUC$)
PRINT C$ + 5
PRINT VALCC$) + 5
and
• PRINT VALCC$) + 5
J128
Q = VAL(CS) - 21
Now type
PRINT Q
and see what you get. Are the contents of Q what you expect?
You can even use VAL to add the numeric values of two different
strings. To try this, create a new string
K$ = "12"
P = VAL(C$) + VAL(K$)
PRINT P
Try the VAL function with different strings, including strings that
begin or end with letters.
P$ = STRHP)
PRINT P$
Now that you know how VAL and STRS can be used if the
character entered isn't a positive number (lines 335-360 in
DEC I MAL) , it would be helpful to see how to add these funct ions
to a program you have already worked on. Load your most
recent version of COLORBOUNCE , and type
LI ST 350 - 400
Now you can fix the program to take care of just such a
possibility. Follow these steps:
Now run the new version and see what happens when you spell
out an entry. The CoLoRBoUNCESoUND program on the
APPLESOFT SAMPLER contains these and all the other
changes you have made to CoLoRBoUNCE.
Introducing Arrays
An array is a type of variable that is used to represent lists of
values linked together in some logical pattern . You can think of
an array as a table of numbers from which you can select
pieces, or elements. (See Figure 5-3.) The programming power
they give you more than compensates for the time spent
becoming familiar with them.
Introducing Arrays
To create an array you must first tell the computer the maximum
number of elements you want the array to accommodate. To do
When the DIM statement is executed , this use the DIM statement (D I M stands for " dimension "). The
it sets aside space for an array elements in an array are numbered from zero, so to dimension
containing the specified number
of elements. an array called A that will have a maximum of 16 elements, type
DIM A(15)
ACO)
A( 1 )
A(2)
and so on, up to
A(15)
A(9) = 45 + A(12)
Array TWO (3.7) 0,0 0,1 0,2 0,3 0,4 0,5 0,6 0,7
Introducing Arrays
NEW
200 REM DIMENSION THE ARRAY
210 DIM GLASS(8)
220 REM FILL THE ARRAY
230 FOR I = 1 TO 8
240 GLASS(I) = I
250 NEXT I
260 REM SCRAMBLE THE ARRAY AND CHOOSE EACH ELEMENT
270 FOR WINE = 1 TO 8
280 REM CHOOSE SOME OTHER ELEMENT
290 MILK = INT (RND(1) * 8) + 1
300 REM WAS MILK DIFFERENT FROM WINE?
310 REM IF NOT, TRY AGAIN
320 IF MILK = WINE THEN GOTO 280
330 REM INTERCHANGE GLASS(WINE) AND GLASS(MILK)
340 TEMP = GLASS(WINE) : GLASS(WINE) = GLASS(MILK)
GLASS(MILK) = TEMP
350 NEXT WINE
360 REM PRINT CONTENTS OF ARRAY
370 FOR C = 1 TO 8
380 PRINT GLASS(C)
390 NEXT C
.?REDIM'D ARRAY
You will get this message if you try to use a negative number
as an array subscript.
Introducing Arrays
Chapter Summary
Statements Terms
LEN string
LEFTS array
MID$ string variable
RIGHTS numeric variable
CLEAR null string
VAL co ncatenation
STR$ format
DIM element
subscript
application programs
Error Messages
Help 167
167 If You (or Your Program) Get Stuck
168 Errors
168 Statements and Commands
168 Cassette Recorders
169 More Helpful Information
169 Printing Applesoft Programs
169 The Apple lie's Memory
170 What the Prompt Character Identifies
Applesoft Tutorial
Appendices
Appendices
111
Appendix A
Summary of Statements
and Commands
ASC
The ASC function returns the decimal ASCII code for the first
character of the argument. [E]
CALL
CALL causes execution of a machine-language subroutine at
the memory location whose decimal address is specified. For
example, CALL -868 will clear the current line from the cursor
to the right margin . It is possible to obtain the same result using
anIESC) or ICONTROL) sequence. [5, E]
CATALOG
This Disk Operating System (DOS) command displays a list of all
the files on a disk in the specified disk drive. For example,
CATALOG,D2 instructs the operating system to display the files
on whatever disk is in the second disk drive. Drive 1 (D1 ) is used
by default unless another drive is specified, as in the example.
CHRS
The CHR $ function returns the ASCII character that corresponds
to the value of the argument, which must be between 0 and 255.
For example, CHR $ (65) returns the letter A. [ E]
CLEAR
This Applesoft statement sets all variables, including arrays
and strings, to zero. It should be used in immediate execution .
Because it throws away the values of all variables, it is tricky to
use within a program . [5]
COLOR=
The color for plotting in low-resolution graphics is set with the
statement COLOR= followed by an integer from 0 to 15, as in
COLOR = 5. Color is set to zero by the GR statement, so GR must
always be followed by the COLOR= statement for anything to
appear on the display screen . Color names and their assoc iated
numbers are :
III Appendix A
On black-and-white or green-phosphor screens the 16 colors
appear as four shades of gray, as shown :
Dark gray: 1, 2, 4, 8
Medium gray: 5,10
Light gray: 3,6,9,12
Pale gray: 7, 11,13,14
White : 15
[1 ]
CONT
The CO NT statement causes program execution to resume,
or continue, after ICONTROLI- C, STOP , or END is used to halt
execution. Execution resumes at the next instruction (like
GOSUB)-not the next line number. Variables are not cleared .
DATA
The DATA statement creates a list of elements that can be used
by READ statements. The elements can be constants, strings,
real numbers, integers, or a combination , as in the example
[E]
DEL
The DEL statement removes, or deletes, the specified range of
lines from the program and is written DEL 23,56. Other syntax
will be followed by a ?SYNTAX ERROR . To delete a single line, say
line 35, use the form DEL 35,35 or type the line number and
then press the RETURN key. [3]
DIM
When the DI M statement is executed , it sets aside space for
an array containing the specified number of elements. The
elements in an array, called subscripts, are numbered from zero.
DIM A (50) will dimension , or set aside space for, the array A
containing up to 51 elements. DIM 1'1$ (25) will allot
26 strings of any length to the array 1'1$ .
END
The END statement stops a program and returns control to the
user. No message is printed . [4]
FOR
A FOR statement in combination with a NEXT statement sets up a
program loop. The loop operation is carr ied out the number of
times specified with the TO portion of the statement. The use of
STEP is optional.
Appendix A
The statement FOR Q = 2 TO -3 STEP -2 ... NEXT Q illustrates
how to use STEP to count in regular increments other than one.
GOSUB
GOSUB causes the program to branch to the line number given.
The subroutine beginning at that line number should end with
a RETURN statement, which causes the program to branch back
to the statement immediately after the GOSUB. For example,
GOSUB 500 would cause the program to branch to line 500
and continue until RETURN . [4]
GOTO
The GOTO statement causes the program to branch to the
indicated line. It is used to create a loop and to run a program
without resetting all variables. [2]
GR
The GR statement sets the stage for low-resolution graphics. In
the low-resolution graphics mode set by GR, the screen has an
invisible grid of 40 vertical columns and 40 horizontal rows
numbered 0-39 and space for four lines of text at the bottom .
GR clears the screen and sets COLOR= to zero, or black. [ 1]
HCOLOR =
The color for plotting in high-resolution graphics is determined
by the HCOLOR= statement. Color numbers and their associated
names are:
a black1 4 black2
1 green 5 orange
2 violet 6 blue
3 white1 7 white2
[4]
HLIN
The HL I N statement is used to draw horizontal lines in low-
resolution graphics. It uses the most recently specified color.
The syntax of HL I N is
HUN 10,30 AT 20
HOME
Using HOME when you are in text mode will clear all text and
move the cursor to the upper-left corner of the screen . Using
HOME when you are in one of the graphics modes only clears the
four lines available for text at the bottom of the screen . (To clea r
the screen of graphics, use GR or HGR .) [ 1]
HPLOT
The HPLOT statement is used to plot dots and lines in high-
resolution graphics using the most recently specified value of
HCOLOR=. There are th ree syntax variants ; each has a different
result :
HPLOT 10,20
HPLOT TO 70,80
Plots a line from the last dot plotted to a dot at column 70,
row 80, using the color of the last dot plotted (not necessari ly
the most recent HCOLOR=) . If no previous point has been plotted ,
no line is drawn.
II Appendix A
HPLOT 30,40 TO 50,60
HTAB
The HTA8 statement moves the cursor either left or right to the
specified column (1 through 40) on the screen.
HTA8 's moves are relative to the left margin of the text window,
but independent of the line width . A line has 255 character
positions (this is the character limit of any line) . Since the
screen has a limit of 40 characters per line, HTA8 causes the
cursor to wrap around to the next screen line for positions 41-
80, the next line down for positions 81-120, and so on . [2]
IF
The IF ... THEN statement creates a conditional program loop. It
is very useful for limiting the range of a program var iable. When
the condition following the keyword I F is evaluated as false (0),
all the rest of that program line is ignored , and the computer
goes on to the next line. When the condition is true (1) , the
statement following the keyword THEN is executed .
INPUT
The I NPUT statement enables you to interact with a program
user from within a program. An I NPUT statement must name a
variable to be entered by the user and may contain a question or
statement. In the example
INPUT A
INT
The I NT function returns the largest integer less than or equal
to the given argument. In the example I NT (NUM) , if NUM is
2.389, then 2 will be returned ; if NUM is - 45.123345
then - 46 will be retu rned. [4]
INVERSE
The I NVERSE statement sets the video mode so that characters
are displayed as black letters on a white background. Use
NORMAL to return to white letters on a black background . [1]
Appendix A
LEFT$
The string function LEFTS returns the specified number
of leftmost characters from the string. If you type
PR I I'lT LEFTS ("APPLESOFT", 5) the five leftmost characters,
APPLE, will be retu rned . [5]
LEN
The string function LEN returns the number of characters in
a string (specified in parentheses) between 0 and 255. In the
example LEN ("AN APPLE A DAY") , 14 will be returned . In the
example LEN (AS), the number returned will be the count of
characters in the string AS. [5]
LET
The LET statement is used to define a variable. The variable
name to the left of the equal sign, which is used in conjunction
with LET, is assigned the value of the string or expression to
the right of the equal sign. LET is optional; the statements
LET A = 23 and A = 23 give the same result. [1]
LIST
The LIST statement displays the program lines that are in the
Apple lie's memory.
MID$
The string function MI D$ returns the substring specified in
parentheses. If you type PR I NT MI DH "AN APPLE A DAY", 4) ,
the fourth through the last characters of the string
will be returned: APPLE A DAY. In the example
MI DH "AN APPLE A DAY", 4,9) , the nine characters beginning
with the fourth character in the string will be returned :
APPLE A D. [5]
NEW
The NEW statement deletes the current program from memory
and sets all variables to zero. [2]
NEXT
NEXT is used within a FOR/NEXT loop. See the FOR statement for
explanation. [2]
NORMAL
NORMAL sets the video mode to the usual white letters on a black
background. [1]
NOTRACE
The NOTRACE statement turns off TRACE . See TRACE. [4]
Appendix A
ON ERR GoTo
ONERR GOTO is used to avoid an error message that
halts execution when an error occurs. When executed ,
ON ERR GOTO sets a flag that causes an unconditional jump to
the indicated line number if any error is later encountered . [ E]
PEEK
The PEEK function returns the contents, in decimal form ,
of the byte at the specified memory address. In the example
PEEK (-16336), the address, or argument, is - 163 36 ; this
particular address is related to the memory address of the
Apple lie's speaker. When the function is executed , the speaker
makes a barely audible click. [4,E]
PLOT
In low-resolution graphics, the PLOT statement places a brick
at the specified location. In the example PLOT 10,20 , a brick
will be placed at column 10, row 20. The color of the brick is
determined by the most recent value of COLOR= , which is black
if not specified. [ 1]
POKE
POKE stores the binary equivalent of the second argument (3
in the example below) in the memory location whose dec imal
address is given by the first argument (34 in the example).
POKE statements are useful for doing things like switching the
graphics/text window mix and for controlling the size and
scrolling of the text window. In the example POKE 34 , 3 , the top
margin of the display is set three lines down from the top and
text only scrolls up to that margin . Another example is
POKE 33 , 33 , which narrows the width of the text window. [ E]
PRINT
PR I NT is the primary Applesoft statement used to display
information on the screen . The PR I NT statement can display
a number, as in PR I NT 150 ; it can display the contents of a
variable, as in PR I NT N ; it can display a group of characters
contained in quotation marks, as in PR I NT "HELLO THERE" ; and
it can display a blank line, as in PR I NT , which causes a line feed
and RETURN to be executed.
READ
When a program executes a READ statement it looks for a DATA
statement. It uses the first element in the DATA statement as a
variable in the READ statement. Successive DATA elements are
assigned to successive variables in the READ statement each
time READ is executed . In the example READ A , 8, C$, the first
two elements in the DATA statement must be numbers and the
third element must be a string . The elements will be assigned ,
respectively, to the variables A , 8, and C$ . [ E]
REM
REM is a statement that allows you to put remarks, or
commentary, in a program. REM statements are not displayed
or executed in a program ; they are used by programmers to
explain program lines. [2]
RETURN
The RETURN statement is used at the end of subroutines. It
causes the program to branch to the statement immediately
after the most recently executed GOSU8. [4]
RIGHT$
The string function R I GHT$ returns the specified number
of rightmost characters from the string. If you type
PR I NT R I GHT$ ("SCRAPPLE" , 5) , APPLE (the five rightmost
characters) will be returned . [5]
RND
The arithmetic function RND returns a random real number
greater than or equal to zero and less than one. Every
time RND is used with any positive argument a new random
number from zero to one is generated, unless it is part of a
sequence of random numbers initiated by a negative argument.
RND( 0) returns the most recently generated random
number. [4, E]
Appendix A
RUN
The RUN statement clears all variables and begins execution at
the indicated line number.
SAVE
SAVE, when followed by a file name, is a DOS command that
stores the program currently in memory. If the command
SAVE AGE is given , and no file called AGE is found on the disk in
the specified or default drive, a file is created on that disk, and
the program currently in memory is stored under the given file
name. If the disk already contains a file in the same language
with the specified file name, the original file's contents are lost
and the current program is saved in its place. No warning is
given .
STR$
The string function STR$ returns a string that represents the
value of the argument. In the example STR$ (12. 4S) , 12. 4S is
returned . [5]
TAB
The display function TAB , which must be used in a PR I NT
statement, moves the cursor through tab fields on the screen .
Its arguments must be between 0 and 255 and enclosed in
parentheses.
TEXT
The TEXT statement sets the screen to the usual nongraphics
text mode, with 40 characters per line and 24 lines. When used
to leave the graphics mode, it is best used in conjunction with
the HOME statement. It resets the text window to fu ll screen . [ 1]
TRACE
The debugging statement TRACE causes the line number of
each statement to be displayed on the screen as it is executed.
TRACE is not turned off by RUN , CLEAR , NEW , DEL , or[RESETI.
NOTRACE turns off TRACE . [4]
VAL
The VAL function attempts to interpret a string , up to the first
nonnumeric character, as a real number or an integer and
returns the value of that number. If no number occu rs before
the first nonnumeric character, zero is returned . [5]
VLIN
In low-resolution graphics, VL I N draws a vertical line in t he
color indicated by the most recent COLOR = statement. The line
is drawn in the column indicated by the third argument. In the
exampleVLIN 10,20 AT 30 , the line is drawn f rom row 10 to
row 20 at column 30. [1]
VTAB
VTAB moves the cursor to the specified vertical row on the
display screen . The top row is row 1; the bottom row is row 24.
VTAB will move the cursor up or down , but not left or right. [2]
II Appendix A
Reserved Words
in App/esoft
II Appendix B
Applesoft "tokenizes " these reserved words: each word takes
up only one byte of storage space. Usually, one character takes
up one byte.
• •
10 COL OR FUL • 5
ADDendix B
AppendixC
Error Messages
Error Messages
II
Applesoft error messages and their explanations follow.
II Appendix C
?NEXT WITHOUT FOR ERROR
The variable in a NEXT statement did not correspond to the
variable in a FOR statement that was still in effect, or a nameless
NEXT did correspond to any FOR that was still in effect. The
three most common causes for this error are forgetting to type
the appropriate FOR or NEXT statement; typing the wrong
variable after the NEXT statement ; or accidentally branching
into the body of a FOR loop.
?OVERFLOW ERROR
The result of a calculation was too large to be represented in
Applesoft's number format. If an underflow occurs, zero is
given as the result, and execution continues without any error
message being printed .
Error Messages
?RETURN WITHOUT GOSUB ERROR
A RETURN statement was encountered without a corresponding
GOSUB statement.
?SYNTAX ERROR
There is a missing parenthesis in an expression , an illegal
character in a line, incorrect punctuation , or some other format
error. Usually this is caused by a simple typing error.
Appendix C
,.UIUC. dix D
Help
There are at least six ways to get the Apple lie back to normal.
The methods are listed in order of increasing severity. It is
always better to try steps 1 and 2 first.
Help
6. Turn off the power. You will rarely have to go this far, and it
is easier on the computer if you use the power-on restart
instead of turning the power off and on .
Errors
In this manual , Applesoft error messages are explained in the
text and in Appendix C. More information about Applesoft
errors can be found in the Applesoft Reference Manual .
Cassette Recorders
All of the programs in this manual can be saved on cassette
tape if you are not using a disk drive. The Applesoft Reference
Manual explains the use of cassette recorders with the
Apple lie.
Appendix 0
More Helpful Information
The information in this section is a bit miscellaneous, but
helpful nonetheless.
By looking at the prompt, you can easily tell (if you forget) which
language the computer is using.
Appendix D
endix E
More Programs
To Play With
You will learn how to avoid the pitfalls of " write-only code":
programs so cryptic even the programmer can 't understand
them. You will sidestep " spaghetti code" : programs with
meandering trails of GOTO statements. Instead, you will see how
professionals block-structure programs so that they and others
can comprehend and change what they have written .
Appendix E
• SCRAMBLER
Before exploring this program , run it to see what it feels like.
This discussion, and the ones that follow, assume that you have
the program in your computer as you are reading.
1. To give instructions.
RUN 1180
SCRAMBLER
discover that you can no longer control the monster you have -..l
created . By taking just a few minutes to think through the
overall program you are writing , you can avoid becoming
ensnarled in spaghetti code. When a block becomes so complex
that you no longer can see the big picture, break that block into
a series of smaller subroutine blocks.
This, and all the Appendix E programs, have basically the same
first three lines. The first (well , the zeroth) line has the name of
the program , when it was written , and who was responsible.
Including this information in your programs lets you know at a
glance what program you are looking at and when you wrote it.
Line 1 sends the program off to the main routine (which is also
the top-level block) with GOTO 1000 . The main routine begins at
line 1 000 so that there is space to make additions later if you
need to.
RUN 2
then
LIST 1350
Appendix E
Lines 1 070 to 1160 end the program. Programs should have
only one end point because you may decide at some future time
to have the program do something special. In this case, the
programmer, some two months after finishing the program ,
decided to include line 1155 , which returns the user to the
DI SK MENU program . Because the program has only one exit, it
wasn't necessary to read through the entire program looking for
other END statements before making the addition.
Line 121 0 dimensions the two string arrays used to store the
first and last sentence halves. Because space for 1000 elements
is allotted in each string , it would take a user between six and
eight hours to fill enough strings to cause an error. It is hoped
that few users are so dedicated to sentence scrambling!
SCRAMBLER
Lines 1400 to 1470 give instructions to the user. Line 1490 sets
a scrolling window, so that the user's entries will not scroll the
instructions off the screen .
Lines 1500 to 1530 form a loop : as long as the user does not
press [OPEN-APPLE)[RETURN), F is incremented by 1 and the user
can type in another string .
Line 1 520 checks to make sure that the user did type something
before incrementing F . This prevents blank lines from being
introduced into the sentence halves. Try changing the line to
read
1520 F = F + 1
Lines 1600 to 1720 get the second halves of the sentences. This
routine works like the first; only the prompt lines are different.
Line 1820 makes sure that there are halves to combine. If not, it
returns to the top-level routine. Usually, the lack of sentences
means the user wants to get out.
Line 1830 uses the TEXT statement to release the text window
set by line 1660 so that HOME will clear the whole screen .
Appendix E
Fine Tuning
SCRAMBLER has two problems that have been left for you to work
out:
For now, try adding warnings about these problems to the user
directions after line 1360. If the added instructions are too long ,
change the VTAB 4 in line 1230 to a simple PR I NT. When you are
sure the program works, save it on a disk. Later you may wish to
come back to SCRAMBLER and tryout some of your advanced
skills by correcting the original problems.
SCRAMBLER
Program Listing
Appendix E
1400 REM *** GET 1ST HALVES ***
1410 REM
1420 HOME : HTAB 9
1430 PRINT "The first haLf. •. "
1440 VTAS 20
1450 PRINT "Type the first haLves of sentences."
1460 PRINT "Press RETURN after each entry . "
1470 PRINT "Hold down OPEN- APPLE and press the" : PRINT "RETURN key after
your Last entry . " ; : REM ALWAYS USE A SEMI - COLON AFTER PRINTS ON BOT
TOM LINE
1480 F = O: OAK = 0 : REM SET COUNTER TO 0: SET OPEN-APPLE KEY VARIABLE TO
o
1490 POKE 34, 2: POKE 35,18: HOME: REM SE T SC ROllING WINDOW
1500 INPUT FIRST$(F)
1510 IF PEEK ( - 16287) > 127 THEN OAK = 1: REM CHECK QUICKLY TO SEE IF
USER IS PRESSING THE OPEN- APPLE KEY
1520 IF lEN (FIRST$(F» > 0 THEN F = F + 1: REM ADVANCE COUNTER IF A SU
CCESSFUl ENTRY
1530 IF OAK = 0 THEN 1500 : REM IF OPE N-APPLE - RETURN NOT PRESSED , lOOP BA
CK FOR THE NEXT HALF-SENTENCE
1540 RETURN
1550 REM
1600 REM *** GET 2ND HALVE S ***
1610 REM
1620 TEXT: VTAB 1: HTAB 9
1630 PRINT " • . • the seco nd half"
1640 VTAB 20
1650 PRINT "Type the second halve s of sente nce s ."
1660 S = O: OAK = 0 : POKE 34 , 2: POKE 35,18: HOME: REM SET UP SECO ND HALF
SAME WAY AS FIR ST
1670 INPUT lAST$ (S)
1680 IF PEEK ( - 16287) > 127 THEN OAK = 1: REM CHECK QUICKLY TO SEE IF
USER IS HOLDING THE OPEN- APPLE KEY
1690 IF lEN (lAST$(S» > 0 THEN S = S + 1:
1700 IF OAK = 0 THEN 1670
1710 RETURN
1720 REM
1800 REM ** DISPLAY SENTENCES **
1810 REM
1820 IF F 0 OR S = 0 THEN RETURN REM IF THERE IS NOT AT lEAST 1 COM
PlETE SENTENCE , CANCEL
1830 TEXT : HOME : HTAB 9
1840 PRINT "Sc r ambled sentences : "
1850 VTAB 20
1860 PRINT "Press RETURN for a new sentence . "
1870 PRINT "Press OPEN-APPLE-RETURN to end."
1880 OAK = 0: POKE 34,2 : POKE 35,18: HOME
1890 VTAB 17: INPUT IN$
1900 IF PEEK ( - 16287) > 127 THEN RETURN : REM IS USER PRESSING OPEN-
APPLE? YES , THEN RETURN
1910 FF = RND (1) * F: SS = RND (1) * S: REM SELECT RANDOM SENTENCE
1920 VT AB 17
1930 PRINT FIRST$(FF);" ";lAST$(SS) : REM AND PRINT IT
1940 PR INT : PR I NT
1950 GOTO 1890
SCRAMBLER
MAGI C MENU
The actual code that forms each of the blocks is very complex
and rather obscure, but this should not keep you from using
them. The blocks can be thought of as "black boxes" : give them
the input they want, and they will carry out their jobs. You
needn 't understand how a radio works to find your favorite
station; in the same way, these subroutine blocks carry out very
complex tasks, just so you don 't have to .
Appendix E
Notes To Advanced Programmers
This section will use examples, which you should tryout on your
computer. They demonstrate how the five subroutines (black
boxes) work and how they are tied together in MAG I C MENU . The
new lines you enter will allow you to look at each subroutine as
a stand-alone block of code.
If you have not yet run MAG I C MENU , do so now. Then , to clear
out everything except the subroutine package itself and keep
from running into Computer Identifier, which starts on line
63000 , type
DEL 1000,62999
2000 END
RUN 2
TEXT
MAGI C MENU
The I NPUT Routine
The I NPUT routine, when run on an Apple lie, will also look to
see if the [Escj, [OPEN-APPLEj, and,sOLlD-APPLE keys are
pressed. IfmJ is pressed , or the OPEN-APPLE or the
SOLI D-APPL keys are held down while another key is pressed ,
the program will return. ~ will equal 1 if m is pressed , OAKEY
will equal 1 if !OPEN-APPLEj is pressed , and SAKEY will equal 1 if
[SOLI D-APPLEj is pressed . AN$ will hold what the user typed
before pressing one of these keys; and OAKEY$ or SAKEY$ will
contain the key pressed at the same time as the [OPEN-APPLEj or
[SOLI 0- APPLEI key, respectively.
This example doesn 't use the special capabilities of the INPUT
routine, namely, field length and recogn ition of special keys. But
even ignoring these capabilities, you will be able to use the
blinking-underline cursor, and users will be able to type
commas and colons.
Line 1 30 lists all the variables used (and potentially changed by)
the routine. All good black box REM statements should do this.
II Appendix E
The GET RETURN Routine
Lines 300 to 399 are the GET RETURN keypress routine in the
program: they do the Apple lie equivalent of aGET loop until the
user presses lRETURN ~ There are many times in programs when
you need to say something like Press !RETURN !to see the
Oleomar arine Futures and then wait around for someone to
press RETURN. This routine does that, supplying the same
cursor as the I NPUT routine.
Lines 400 to 499 are the Screen Formatter routine. This black
box performs the equivalent of
MAGI C MENU
Third, if the program is run on an Apple II or Apple II Plus, the
Screen Formatter will convert all lowercase letters, which those
computers do not recognize, into uppercase letters. So your
whole program can take advantage of the new Apple lie
hardware, without being confined to just the Apple lie.
1000 AIlE = 1
1010 AN$ = "Margarine used to taste horrible
and came with the coloring in a separate
pouch. It has improved considerably. Is
it good enough now to compete with the $4 . 98
spread?"
1020 GOSUB 400
1030 GOSUB 100
1000 AIlE = 0
1000 AIlE = 1
II Appendix E
and enter the name of the program with
The menu selections (yes, you should enter them so you can see
Menu Maker at work) are
1100 OAKEY = 0
Finally, add
MAGIC MENU
So you can see that the correct menu item number was placed
in both AN and AN$. Writing this menu certainly took only
minutes. Now type RUN.
Magic!
Of course, all options will end the program since you are just
displaying AN , not using it. From here, you could have your
program branch to various subroutines dealing with the
different oils. See the discussion of line 1670 in the section
" Notes on the Rest of MAG I C MENU " for more information.
Now you can tryout the fifth and final block, Computer
Identifier. Right now, line 1 000 looks like this:
1000 AIlE = 1
• 0 if an Apple II or II Plus
• 32 if an Apple lie
• 64 if an Apple lie with an Apple lie aO-Column Text Card
• 1 2B if an Apple lie with an Extended aO-Column Text Card
Try running the program again . If you have neither card , nothing
will happen. If you have a text card, your screen will suddenly
display ao columns. To go back to 40 columns, just type
RUN 2
Appendix E
Notes on the Rest of MAG I C MENU
You have explored the black boxes themselves ; now take a look
at the lines of a program built upon them . There is very little
difficult code in these lines ; for the main part, you can look at
the listings and run the program to figure out what is being
done. A few lines that bear further comment are discussed in
this section .
Line 1 360 : users with an aO-column text card can look at more
text on one screen than users with a 40-column display. The
program takes advantage of this by offering more information to
users with an aO-column display.
Line 1670 sends the user off to the requested subsection of the
program. ON AN GOSUB 2000,3000,4000 will go to a subroutine
beginning on line2000 if AN = 1 ; 3000 if AN = 2; 4000 if AN = 3 ;
and so on . Note, however, that when you use ON GOSUB , t here is
no logical connection between the variable number and the
subroutine it sends the program to. Menu Maker will not allow
an illegal number, so error-checking for correct numbers in AN is
already included .
MAGI C MENU
Lines 1800 to 1890 are very similar to those described above ;
they handle the call for descriptions, branching to the
appropriate subsections.
Program Speed
II..' Appendix E
A Few Words about Variable Names
I, J, K, L, M, N, 0, P
MAGI C MENU
11
This will keep the lower-level routine from destroying values in
the higher-level routine. Menu Maker, for example, uses all
double letter variables because it calls both the I NPUT and
Screen Formatter routines.
Finally, don't use these variables unless you really need the
speed , or you are converting your favorite routines to black
boxes. You have to be able to read and understand your own
program : use descriptive variables anywhere they won 't
seriously affect your program .
x = 0 : IF A = 23 THEN X = 14
x = 14 * (A = 23)
A = 23
X = 14 * (A 23)
PRINT X
A = -32.68
X = 14 * (A 23)
PRINT X
Appendix E
When Applesoft encounters a Boolean argument (A = 23) , it
decides whether it is true (1 ) or false (0). (14 * 0) is 0 and
(14 * 1 ) is 14. (You may explore such Boolean logic further in
the section on IF ..• THEN in the Applesoft Reference Manual.)
Having done so , you may then clearly state what you are doing :
MAGI C MENU
II
When the subroutine ended , the routine that called it needed to
know if the user had answered successfully, rather than just
pressing lRETuRNj. The programmer discoved that he could tell if
an age had been successfully found by simply testing the
variable YEARS:
That worked fine until a colleague typed in the age of her new
baby: no years, 2 months. The program rounded this reply to :
YEARS = O. It didn 't matter how many times she typed it in , it
kept asking her how old " Setty" was.
You will not run out of variable names-there are more than
5000 of them . Use a flag and always give it a descriptive name.
Program Listing
II Appendix E
200 IF OAKEY THEN OAS = CHRS (P - 128) : ANS ANS + IS: PRINT IS;" ". RETURt'!,
: REM * OPEN-A PPLE KEY
205 IF SAKEY THEN SAS = CHRS ( P - 128) : ANS ANS + IS : PRINT IS;" " . RETURN
: REM * SOLID - APPLE KEY
210 IF P > 159 AND P < > 255 THEN IF J + LEN (IS) < FL THEN IF N THEN
ANS = ANS + CHRS (P - 128) : J = J + 1: PRINT CHRS (P) ; : GOTO 149
215 IF P < > 255 THEN 240: REM DELETE KEY
220 IF J THEN PR INT II ";: POKE 36,L: VTAB M + 1: PRINT CHRS (136); :J
J - 1
225 IF J = 0 THEN ANS = ""
230 IF J THEN ANS LEFTS (ANS,J)
235 GOTO 149
240 IF P < > 136 THEN 265: REM * BAC K ARROW KEY
245 IF J THEN PRINT" ";: POKE 36, L: VTAB M + 1: PRINT CHR $ (136);:1$
RIGHT$ ( ANS , 1) + I$ : J = J - 1
250 IF J = 0 THEN ANS = ""
255 IF J THEN AN$ = LEFT$ (AN$ , J)
260 GOTO 149
265 IF P 141 THEN AN$ = AN$ + 1$: PRINT 1$;" ": RETURN REM * RETURN
KEY
270 IF P < > 149 THEN 294 : REM * FORWARD ARROW KEY
275 IF NOT LEN ( 1$ ) THEN 149
280 AN$ = AN$ + LEFT$ (I$ , 1):J = J + 1: PRINT LEFT$ ( 1$ , 11;
285 IF U: N ( IS ) = 1 THEN 1$ = ''''
290 IF LE~ (1$) THEN 1$ = RIGHT$ (1$, LEN (1$) - 1)
292 GOTO 149
294 IF P = 155 THEN ESCKEY = 1: PRINT : RETURN : REM ESCAPE KEY PRESSED
296 GOTO 149
298 REM
MAGI C MENU
414 IF I > THEN IF RIGHT$ (AN$ , 1) = " " THEN AN$ = LEFTS (AN$ , I - 1
)
417 IF P + I < PEEK (33) THEN 1$ = AN$:AN$ "". GOTO 440
420 J = PEE K (33) - P + 2: 1 = J
425 I = I - 1: IF I THEN IF MID$ (AN$ , I , 1) < >" " THEN 425
430 IF I = 1 THEN I = J
431 IF I = 0 THEN PRINT: GOTO 410
435 1$ = LEFT$ (AN$,I - 1): IF LEN ( AN$) > I THEN AN$ RIGHT$ (AN$, LEN
(AN$) - 1): REM I SOLATE 1 LINE IN 1$
440 IF AIlE THEN PRINT 1$;
445 IF NOT AIl E THEN K = LEN (I$) + 1: FOR I = 1 TO LEN (I$): J = ASC
( RIGH T$ (I$ , K - Il): PRINT CHR$ (J - 32 * (J > 96 AND J < 123)) ;: NEXT
447 P = PEEK (36) : IF COL80 THEN IF P = PEEK (1147l THEN P = PEEK (14
03) ---'
450 IF LEN (AN$) THEN IF P < > 0 THEN PRINT
455 IF LEN (AN$) THEN 410
460 IF P < > 0 THEN IF MID$ (I$ , LEN (I$), 1) < > " " THEN PRINT" "
46 5 RETURN
499 REM
510 REM PUT MENU ITEM S IN MENU$(1) THROUGH MENU$(12). REMEMBER TO DIM M
ENU$(12) IF MORE THAN 10 IT EMS
515 REM PROGRAM USES INPUT ROUTINE AND SCREEN FORMATTER . ALL VARIABLE S
AFFECTED BY THEM AS WELL AS II, JJ, KK, LL, MM, NN, OO , PP , AN, 11$ A
RE AFFECTED
520 REM USER ' S CHOICE IS RETUR NED IN BOTH AN$ AND AN
525 REM IF FROM$ HAS A TITLE IN IT, ESCKEY WILL BE IF USER WANT S TO G
o BA CK TO CALLING MENU. MAIN MENUS SHOULD MAKE (NOTHING)
FRO~l$ = ""
ADDendix E
630 POKE 32,J J : POKE 33, PEEK (33) - JJ : PRINT: REM SET "WINDOW" SO THA
T TEXT OF MENU ITEM IS INDENTED
635 AN$ = MENU$( II ): GOSUB 400 : REM PRINT MENU ITEM
640 POKE 32, 0 : POKE 33, PEEK (33) + JJ : PRINT : REM "RESTORE" FULL WINDO
\oJ
645 IF NN TH EN PRINT
650 NEXT II
655 IF PEEK (37) > 16 THEN PRINT "TOO MANY MENU ITEMS OR TOO LONG LINE
S. " : STOP
660 TEXT : VTAB 17 : AN$ = "Select option >" : GOSUB 400: PRINT
665 FOR II = 1 TO PEEK (33) : PRINT" " ;: NEXT
670 IF NOT 00 OR NOT AILE THEN PRINT : REM IF ROOM , SPACE DOWN 1
675 IF LEN CFROM$) THEN AN$ = "For" + FROM$ + " : press ESC": GOSUB 400
680 PRINT
685 IF AIlE THEN PRINT "To erase : use the DELETE key"
690 AN$ = "To select: type a number from 1 to "+ STR$ (LL)
700 GOSUB 400 : PRI NT
705 I F NOT 00 THE N 720
710 IF AIlE THE N PRINT "Fo r descriptions : press OPEN - APPLE-?"
715 IF NOT AIlE THEN PRINT "FOR DESCRIPTIONS: FOLLOW ANSWER WITH ?"
720 AN$ = "To go to se lected item: press RETURN· ' : GOSUB 400: PR INT
723 IF NOT 00 THEN AN$ = "(There are no descriptions available)": GOSUB
400
725 FL = 3:AN$ = "" . REM SET-UP VALUES FOR INPUT ROUTINE BEFORE CALLING I
T
730 REM
795 VTAB 19
800 IF NOT OAKEY THEN 825
1105 IF NOT 00 OR OA$ < > "?" AND OAS < > "/" THEN 735: REM HELP NOT A
VAILABLE (00 WA S SET TO VALUE OF OAKEY AT BEGINNING OF ROUTINE) OR W
RONG KEY PRESSED
810 REM JJ WILL NOW BE USED TO HOLD LENGTH OF ANS:
8 15 JJ = VAL (ANS): IF JJ > 0 AND JJ < = LL THEN II = JJ: GOTO 880 : REM
EXIT MENU FOR HELP
820 IF JJ = 0 THEN PRINT "- - > PLEASE SE LECT A NUMBER FIRST <--";: CALL
- 868 : PRINT :ANS = "": GOTO 735
825 IF SAKEY THEN 735 : REM SOLID-APPLE KEY NOT USED FOR MENU
830 IF ESCKEY THEN IF LEN (FROM$) THEN 880: REM IF ESCAPE KEY IS PRESS
ED , MENU IS EXITED
835 JJ = VAL (ANS) : IF JJ > 0 AND JJ < = LL THEN II = JJ: REM ISOLATE N
UMBER FR OM ANS AND MAKE II EQUAL IT
840 IF LEN (ANS) = 0 THEN 735
845 IF 00 THEN IF NOT AILE AND ( RIGHT$ (ANS , 1) = "?" OR RIGHTS (A NS,
1) = "/") THEN IF II > 0 AND II < LL THEN OAKEY = 1: GOTO 880
850 IF LEN ( ANS) THE N K = 0 : FOR I = 1 TO LEN (ANS) : J = ASC ( RIGHTS
(ANS , I):K = K + (J < > 32 AND (J < 48 OR J > 57): NEXT I: IF K THEN
PRINT" --> PLEASE USE DIGIT S <--";: CALL - 868: PRINT :AN$
"" . GOTO 735
855 REM ABOVE LINE CHECKS FOR PRESENCE OF NON- NUMERIC CHARACTERS OTHER
HAN SPACE IN THE LINE; IF FOUND, THE LINE IS REJECTED
MAGI C MENU
1160 IF NOT JJ THEN IF LEN (AN$) THEN K = 0 : FOR I = 1 TO LEN ( AN$ ) : J -J
*
1000 REM •• MAIN PROGRAM .*.
101 0 I = O:AN$ = "":J = 0: 1$ = "" : K = 0 : REM DECLARE MOST OFTEN USED VARI
ABLE S FI RST FOR SP EED .
1020 GOSUB 63000 : REM FIND OUT IF AIlE OR NOT
1021 DIM ME$(20)
1025 IF RESU LT S> 64 THEN COLBO 1: PRIN T CHR$ (4);"PR#3": REM IF A
N 80-CO LUMN CARD IS PRE SE NT, USE IT. IF YOU DON'T WA NT IT , CHANGE T
HE LINE TO:
1025 PR INT CHR$(21)
1030 TEXT: PRINT: HOME: RE M TE XT CLEAR S ANY OLD WIND OWS: PRINT CLEARS
OUT ANY OLD HTAB AND VTAB INFORMATION : HOME CLE ARS THE SCREEN
1040 PRINT : HOME
1050 AN$ = "* •• Magic Menu ••• ": POKE 36, { PEEK (33) - LEN (AN$» I 2: GOSUB
400: PRINT : REM CENTER TITLE
1060 PRINT :AN$ = '~ ag i c Menu has f i ve basic sub routines upon whi ch you
can bui ld yo ur prog r ams : !!
1070 GOSUB 400: PRINT : IF COLBO THEN PRINT: REM BY CHANCE , THE SECOND
LINE IS JUST LONG ENOUGH TO CAUSE AN EXTRA CARRIAGE RETURN IN 40- CO
LUMN MODE
1080 AN$ = "1 . COMPUTER IDENTIFIER: says you are now using an AppLe" : GOSUB
400 -
1090 IF RESULT 0 THEN AN$ = " II OR II+."
1100 IF RESULT 32 THEN AN$ = "IIe."
1110 IF RESULT 64 THEN AN$ = "IIe with an 80- CoLumn Card . "
1120 IF RESULT 128 THEN AN$ = "lIe with a Memory-Expansion Card . "
1130 IF CO L80 THEN GOSUB 400:AN$ = "Th e ot her four routine s use the inf
o rmati on from COMPUTER IDENTIFIER to Let you r so ftware take fuLL adv
antage of what ever AppLe compute r it is run on . "
1140 GOSUB 400: PRINT: PRINT
1150 AN$ = "2 . SCRE EN FORMATTER: ": GOSUB 400
1160 AN$ = "controL s text dispLay so that Lines a r e ended between word s i
nstead of in the midd Le of them."
1170 IF COL80 THEN GOSUB 400:AN$ = "It aLso automaticaLLy converts aLL
Lower-case Lette r s to ca pitaLs when the program is run on an AppLe I
I o r an AppLe II +. "
1180 GOSUB 400 : PRINT: IF COLBO THEN PRINT
1190 AN$ = '~. MENU MAKER: Let s you c r eate unifo rm, friendLy menus in min
utes, instead of days. ( A sampLe menu follows . )"
1200 GOSUB 400 : PRINT: PRINT
1210 AN$ = "4. INPUT : is the flashing-underLine curso r routine you Lea r ne
d on AppLe Pre se nt s • •• APPLE.": GOSUB 400
1220 AN$ = "" : IF AIlE THEN AN$ = "(Pi ck 1 fr om menu.)"
1230 IF CO LBO THEN AN$ = " (To reacquaint yourseLf with this input r outi
ne , se Le ct option 1 from the menu that foLLows.)
1240 GOSUB 400 : PRINT: PRINT
1250 AN$ = "5 . GET RETURN: wa its f o r you to pr ess RE TURN . It i s waiting
now • .. "
1260 GOSUB 400: PRINT: PRINT
127 0 AN$ = "Pre ss RETURN t o conti nue . ": GOSUB 400 : GOSUB 300: REM PRINT P
ROMPT: WAIT FOR A RETURN
1299 REM
Appendix E
1300 REM *** "heLp" SCR EEN ***
1310 HOME
1315 IF CO lBO THEN VTAB 4
1320 AN$ = "A few wo rd s about the sampLe menu:"
1330 GOSUB 400 : PRINT : PRINT : PRINT
1340 AN$ = "The foL Lowing menu has six seL ections, onLy two of whi ch actu
aLLy do something . The first seLection shows you a famiLiar exampLe
of the fLashing- cu r sor input r outine ; the Last seLection exits the
p rog ram ."
1350 GOSUB 400
1360 IF CO l BO THEN AN$ = " The other four se Lect i ons are there to take u
p space on t he menu and in the pr ogram , so you can see how a more el
aborat'e pr ogram wouLd be st ructured." : GOSUB 400
1370 PRINT : PRINT
1375 IF CO l 80 THEN PRINT
1380 AN$ = "T he Menu Make r enabLes you to give a de sc ripti on of each menu
item , so the user needn ' t fi r st wade through pages of "+ CHR$ (34
) + "di r ections" + CHR$ (34) + ":"
1390 GOSUB 400
1400 AN$ = "t o see the description of option 1, type"
1410 GOSUB 400
1420 AN$ = "1? RETURN" : IF AIlE THEN AN$ = "1, then pr ess OPEN-APPLE-?"
1430 GOSUB 400: PRINT: PRIN T
1435 IF CGl80 THEN PRINT
1440 AN$ = " ExpLo r e the menu , then revie w the Listings in Appendix E of t
he AppLesoft Tuto r iaL manuaL fo r detaiLs on how to use these r outine
s in your o wn programs ."
1450 GOSUB 400 : PRINT
1460 VTAB 24 :AN$ = "Pre ss RETUR N to go to the menu . ": GOSUB 400: GOSUB 3
00
1499 REM
MAGI C MENU
1800 REM *** GO TO HELP ***
1810 TEXT: HOME VTAB 8
182 0 HOLD$ = AN$
1830 ON AN GOSUB 9000,9 200,9300,9400,9500 , 9600 , 9725,9825 , 9925
1850 AN$ = "Pre ss RE TURN to go to the menu . " : GOSUB 400
1860 GO SU B 300 : REM WAIT FOR RETURN
1870 AN$ = HOLD$
1880 RETURN
1890 REM BLAN K LINE S ARE DONE BY PR ESS ING THE DOWN-ARR OW KEY
Appendix E
6000 AN$ = "Sa mpLe routine number 5": GOSUB 400
6999 RETURN
7000 REM END
7005 PRINT: REM DISK COMMANDS (SEE NEXT LINE) WILL NOT WORK IF THERE IS
AN "OPEN" PRINT COMMAND SUCH AS A "PRINT;" OR "PRINT," . THEREF ORE ,
ALWAYS DO A "PRINT" BEFORE ISSUING A DOS COMMAND
7010 IF PEEK (6) = 99 AND PEEK (7) = 99 THEN PRINT CHR$ (4) ;"RUN DIS
K MENU": END
7020 REM ABOVE LI NE RUNS DISK MENU IF DISK MENU ASKED IT TO. SEE NOTES
FOLLOWING LINE 9060 OF DISK MENU .
7050 TEXT: HOME : TEXT : END : REM CLEAN UP & GO AWAY
9000 REM *HELP SCREENS*
9100 REM
9105 AN$ = "Option 1: the AppLe lIe Input Routine"
9107 VTAB 1
9110 HTAB ( PEEK (33) - LEN (AN$» I 2
9115 GOSUB 400: PRINT: PRINT
9117 IF COL80 THEN VTAB 7 : REM A DIFFERENT SPACING LOOKS MORE PLEASING
IN 80-COLUMN MODE
9120 AN$ = "The Apple lIe is equipped with a full ASCII keyboard, includi
ng the DELETE key , a new key for the AppLe II ser i es ." : GOSUB 400
9122 PRINT : IF COL80 THEN PRINT : REM BY COINCIDENCE, THE ABOVE SENTEN
CE, IN 40-COLUMN MODE , IS JUST LONG ENOUGH TO "f orce" AN EXTRA CARRI
AGE RETURN . SO , TO GET THE EXTRA SPACE IN 8o-COLUMN r~ODE, WE MUST P
RINT ONCE MORE
9125 AN$ = "Using the DELETE key and the flashing-cursor input routine in
eluded within this program , ": GOSUB 400
9130 AN$ = "you can scan forward and backward through your answers , inser
ting and deLeting characters at wi Ll . ": GOSUB 400
9135 AN$ =" The input r out ine automaticaLLy gives the standard AppLesof
t BASIC blinking cu rs or to users of the AppLe II o r II+.": GOSUB 400
MAG I C MENU
63050 DATA 8, 120, 173, 0, 224, 141, 208, 2, 173, 0, 208, 141, 209, 2,
173, 0, 212, 141, 210, 2, 173, 0, 216, 141, 211, 2, 173, 129 , 192, 1
73, 129, 192, 173, 179, 25 1, 201 , 6, 208, 73, 173
63060 DATA 23, 192, 48, 60, 173, 19, 192, 48, 39, 17 3, 22, 192, 48, 34,
160, 42, 190, 162, 3, 185, 0, 0, 150, 0, 153, 162, 3, 136, 208, 242
, 76, 1, 0, 8, 160, 42, 185, 162, 3, 153
63070 DATA 0, 0, 136, 208, 247, 104, 176, 8, 169, 128, 141, 207, 3, 76,
73, 3, 169, 64, 141, 207, 3, 76, 73, 3, 169, 32, 141, 207, 3, 76, 7
3, 3, 169, 0, 141, 207, 3, 173, 0, 224
63080 DAT A 205, 208, 2, 208, 24, 173, 0, 208, 205 , 209, 2, 208, 16, 173
, 0, 212, 205 , 210, 2, 208, 8, 173, 0, 216, 205, 211 , 2, 240, 56, 17
3, 136, 192, 173, 0, 22 4, 205, 208, 2, 240, 6
63090 DATA 173, 128, 192, 76, 161, 3, 173, 0, 208, 205, 209, 2, 240, 6,
173, 128, 192, 76, 161, 3, 173, 0, 212, 205 , 210, 2, 240, 6, 173, 1
28, 192, 76, 161, 3, 173, 0, 216, 205, 211, 2
63100 DATA 240, 3, 173, 128, 192, 40, 96, 169, 238, 141, 5, 192, 141, 3
, 192, 141, 0, 8, 173, 0, 12, 20 1, 238, 208, 14, 14, 0, 12, 173, 0,
8, 205 , 0, 12, 208, 3, 56, 176, 1, 24
63110 DATA 141, 4, 192, 141, 2, 19 2, 76, 29, 3, 234
63120 J = 975 : K = 724
63130 FOR I = 0 TO 249
63140 READ L
63150 POKE K + I,L
63160 NEXT
63170 CALL K
63180 RESULTS = PEEK (J)
63190 IF RE SULT S < > 0 THEN AIlE
63 200 RETURN
II Appendix E
DISK MENU
DISK MENU was written in two hours flat. In fact , it wasn 't exactly
written: the author used MAG I C MENU to create DI SK MENU. (Soon
you will be able to do the same!)
If you compare lines 1 00 to 900 in DISK MENU with the same lines
in MAG I C MENU, you will notice a distinct change. The subroutine
package has been compressed . Most REM statements have been
removed. Any variable name greater than two characters long
has been shortened to a minimum.
Lines 1 047 to 1 075 are the text of DISK MENU. Because the
Screen Formatter subroutine from MAG I C MENU automatically
straightens out unformatted text, the author didn 't have to be
careful about line breaks when adding these lines. Otherwise,
there is very little new and interesting in DISK MENU . This is
exactly the point of using MAGI C MENU: a functional , useful
program using standard inputs, clear instructions, and friendly
menus was created in an extremely short period of time. It took
more than a month of work to write the subroutine block
package on which this program is based; it takes only a few
hours to grow something out of it.
DISK MENU
Lines 6000 to 6999 are the little routine that simulates the
typing of the CATALOG command. The command is actually
issued in the normal manner by line 6080 . DOS commands can
be executed from within an Applesoft program by printing a
string that consists of aICONTROL} D followed by the DOS
command ; since CHRH4) is the ASCII code for ICONTROL ~ D , and
TITLE$ has been set to "CATALOG" in line 6030 , line 6080
produces a CATALOG listing on the screen .
Line 9060 is the key to why the appendix programs all come
back to DISK MENU when they are done. The problem is to
communicate among programs with a flag: if the flag is set (if
DISK MENU has been run) come back ; if not, don 't come back.
One cannot use a standard var iable for a flag between
programs, because all variables are cleared to zero when a
program is run. But many memory locations are not affected by
Applesoft. In this case, the author chose locations 6 and 7 ,
placing the arbitrary number 99 in each of them. The odds of
both locations having 99 in them by chance are only 1 in 65,536
-pretty good odds.
Appendix E
4. Those that allow you to edit program lines more easily than
escape mode does.
This example, and the longer one that follows in the next
section , is for you to tryout on your computer. Insert the DOS
3.3 SYSTEM MASTER disk into your disk drive if it is not already
there. Then type
RUN RENUMBER
If you are using one disk drive, remove the SYSTEM MASTER
disk and insert the APPLESOFT SAMPLER disk into the drive. If
you are using two drives, the APPLESOFT SAMPLER can be
placed in the second drive. (These instructions will presume you
are using one disk drive. If you are using two, remember to add
the, D2 to the next command.) Type
DEL 0,1999
DEL 3000,63999
LIST
You will see that there isn 't much left. Now, to renumber the
portion of 01 SK MENU beginning at line 7000 , type
& 7000
LIST
DISK MENU
The menu is suddenly on new line numbers. RENUMBER does
this. Using the ampersand (&) by itself would renumber the
whole program, starting at line 1 0 and incrementing by 10 .
Using & 7000 renumbers the program beginning at line 7000
and incrementing by 1 O. Now to store it away, type
&H
If you list the program now, you 'll find there isn 't anything
visible: it's on hold. &H tells DOS to hold something in the
computer's main memory so that you can bring in another
program on top of whatever is there. This tool is limited , of
course, by the size of the programs you are working with and
the size of the computer's memory.
Before you merge one program into another, make sure you are
not deleting old lines. Type
You shouldn 't see any listing since those line numbers have not
been used. You can therefore directly proceed to the process
called merging . Type
&M
to merge the new lines into the old program . By changing the
program names to new program names, including the new
name of this submenu in the main menu, and giving the address
of this new menu to the ON ... GOSUB statement in line 1 230 ,
you could index up to 12 more programs on this disk. The
author used this method (RENUMBER, &H, &M) three times to
create the three submenus in the program.
Appendix E
Program Listing
140 I = 5:J = O:K = O:L = O:M = 0 : 1$ = "":E SC O:OA O: OA$ " ": SA 0:
SA$ = "": IF FL = a THEN FL = 245
14 2 IF NOT AIlE THEN INPUT "";AN$ : RETURN
145 PRINT AN$;:J LEN (A N$)
149 M = PEEK (37)
15 3 L = PEEK (36): IF COL80 THEN IF L PEEK ( 1147) THEN L PEEK ( 14
03 )
155 PRINT" ";1$;" ";
160 N = 1: IF L + LEN (J$) > PEEK (3 3 ) - 3 AND PEEK ( 37) PE EK ( 3
5) - 1 THE~ N = 0
165 POKE 36 ,L: POKE 1403,L: VTAB M + 1
170 ! = ! - 1: IF ! < 0 THEN K = 1 - K:! = 5: PR INT C HR~ (32 + 63 * Kl;
175 POKE 36 , L : POKE 1403,L: VTAB n + 1
180 P = PEEK ( - 1638 4): IF P < 128 THEN 170
18 5 IF PEEK ( - 16287) > 127 THEN OAKEY 1
190 IF PEEK ( - 16 286) > 1 27 THEN SAKEY = 1
195 POKE - 16368 , 0 :K 0 :1 0 =
200 IF OAKEY THEN OA$ CHR$ (P - 128) :AN$ AN$ + 1$: PRINT 1$;" " . RETURN
205 IF SAK EY THEN SA$ CHR$ (P - 128) :AN$ AN$ + 1$: PRINT 1$;" ". RE TURN
2 10 IF P > 159 AND P < > 255 THEN IF J + LEN ( 1$) < FL THEN IF N THEN
AN$ = AN$ + CHR$ (P - 128) :J = J + 1: PRINT CHR$ (P) ;: GO TO 149
215 IF P < > 255 THEN 240
220 IF J THEN PRINT" ";: POKE 36 ,L: VTAB M + 1: PRINT CHR$ (136) ;:J
J - 1
225 IF J = a THEN AN$ = ""
230 I F J TH EN AN$ LEF T$ (AN$,J)
235 GOTU 149
240 IF P < > 136 THEN 265
245 IF J THEN PRINT" ";: POKE 36 , L: VTAB M + 1: PRI NT CHR$ ( 1 36);:1$
RIGHT$ (AN$ ,1) + I$:J = J - 1
250 IF J = a THEN AN$ = ""
255 IF J THEN AN$ = LEFT$ (A N$,J)
260 GOTO 149
265 IF P = 141 THEN AN$ = AN$ + 1$: PRIN T 1$;" ". RETURN
270 IF P < > 149 THEN 294
275 IF NOT LEN ( 1$) THEN 149
280 AN$ = AN$ + LEFT$ (1$,1):J = J + 1 : PRI NT LEFT$ ( 1$,1);
285 IF LEN (1$) = 1 THEN 1$ =
290 IF LEN ( 1$ ) THEN 1$ = RIGHT$ (1$ , LEN ( 1$ ) - 1)
292 GOTO 149
294 IF P = 155 THEN ESCKEY = 1: PRINT: RE TUR N
296 GOTU 14 9
300 REM
•• GET RETURN **
Dr SK MENU
350 IF L < > 0 THEN POKE 36,L - 1
355 P = PEEK ( - 16384): IF P < > 141 THEN 330
360 PRINT" ";
365 IF PEEK (37) =
23 THEN VTAB 23
370 PRINT
375 POKE - 16368,0: RETURN
400 REf~
414 IF I > THEN IF RIGHTS (ANS,1) = " " THEN ANS = LEFTS (AN$ , I - 1
)
417 IF P + I < PEEK (33) THEN IS = ANS: ANS ''' ': GOTO 440
420 J = PEEK (33) - P + 2: I = J
425 I = I - 1 : IF I THEN IF MIDS (ANS, 1,1) < > "" THEfl 425
430 IF = 1 THEN I = J
431 IF I = 0 THEN PRINT: GOTO 410
435 IS = LEFT$ (ANS , ! - 1): IF LEN (ANS) > I THEN ANS RIGHT$ (ANS, LEN
(ANS) - 1)
440 IF AIlE THEN PRINT IS;
445 IF NOT AIlE THEN K LEN (IS) + 1: FOR I = 1 TO LEN (I$):J = ASC
(RIGHTS (1S,K - Il): PRINT CHRS (J - 32. (J > 96 AND J < 123»;: NEXT
I
447 P = PEEK (36) : IF COL80 THEN IF P = PEEK (1147) THEN P = PEEK (14
03)
450 IF LEN (ANS) THEN IF P < > 0 THEN PRINT
455 IF LEN (AN$) THEN 410
460 IF P < > 0 THEN IF MIDS (1S, LEN (1S) , 1) < > " " THEN PRINT " "
465 RETURN
500 REM
81 Appendix E
660 TEXT: VTAB 17:AN$ : "Sele c t o ption > ": GOSUB 400: PRINT
665 FOR II : 1 TO PEEK (33 ) : PRINT" ";: NEXT
670 IF NOT 0 0 OR NOT AIlE THEN PRINT
67 5 IF LEN ( FROM$ ) THEN AN$ : "F o r " + FROt'1$ + ". pre ss ESC": GOS UB 400
6 80 PRINT
6 85 IF AIlE THEN PRINT "To era se : use the DELETE ke y "
690 AN$ : "To s elect: t ype a number fr om 1 to "+ STR$ (LL)
70 0 GOS UB 400: PRINT
705 IF NUT UO THEN 720
710 IF AIlE THEN PRINT "For de s cripti on s : press UPEN-APPLE-?"
7 15 IF NOT AIlE THEN PRINT "FOR DESCRIPTIONS: FOLLOW ANSWER WITH ?"
720 AN$ : "To go t o se l e cted i t ern: p re ss RETURN" : GOSUB 400: PRINT
723 IF NOT 00 THEN AN$ : "(There are no de sc ripti on s avai lable ) ": GU SUB
400
725 FL : 3:ANS : ""
735 REM
740 VTAB 17: HTAB 17: CALL - 868 : HTAB 17
745 IF AILE OR NOT LEN (FROM$) THEN GOS UB 100: GOT O 795
750 : o:J : O:M: PEEK (37) : L PEEK ( 36): OAKEY : 0
)55 I : I - 1: IF I < 0 THEN K: - K:I : 5:J : 1 - J: NORM AL IF J THEN
INVERSE
760 PRINT" ";: POKE 36 ,L: VTAB M +
765 p : PEEK ( - 16384): IF P < 1 28 THEN 75 5
770 NORMAL
775 IF P : 155 THEN POKE - 16368,0:E SCKEY 1: GOTO 795
780 L : PEEK (36): VTAB 20: HTAB 1: CALL - 868: VTAB n + 1 : HT AB L + 1
785 INPUT "" ;ANS
795 VTAB 19
800 IF NOT OAKEY THEN 82 5
805 IF NOT 00 OR OA$ < > " ? " AND UA$ < > " / " THEN 735
815 JJ: VAL (AN$): IF JJ > 0 AND J J < LL THEN II : J J: GOTO 880
8 20 IF JJ : 0 THEN PRINT "--> PLEA SE SELECT A NUMBER FI RST <--" ; : CALL
- 868: PRINT : ANS : '''': GOTO 735
825 IF SAKEY THEN 735
830 IF ESCKEY THEN IF LEN (FROfl$ ) THEN 880
835 JJ: VAL (AN$): IF JJ > 0 AND JJ < : LL THEN II : JJ
840 IF LEN (ANS ) : 0 THEN 735
845 IF 00 THEN IF NOT AIlE AND ( RI GHT$ (AN$,l ) : " ? " OR RI GHT$ ( ANS ,
1) : "/") THEN IF II > 0 AND II < LL THEN OAKEY: 1: GO TO 880
850 IF LEN (AN$) THEN K : 0 : FOR I : 1 TO LEN ( ANS ) :J ASC ( RI GH T$
(ANS , I)):K: K + (J < > 3 2 AND (J < 48 OR J > 57)): NEX T I: IF K THE N
PRINT" --> PLEASE USE DIGIT S <--";: CALL - 868 : PR INT : AI,$ :
"". GOTO 735
860 IF NOT JJ THEN IF LEN (ANS ) THEN K : 0: FOR I 1 TO LEN (AN$ ) : J
ASC ( RIGHTS (AN$,I)):K : K + ( J : 48) : NE XT I: IF NOT K THEN PRINT
--> PLEASE USE DIGIT S <--";: CALL - 868 : PR INT :AN$ : "" : GO TO
735
8 70 IF JJ > LL THEN PRINT " --> " ;JJ;" I S TOO L ARGE < __ " ; : CALL -
868 : PRINT : AN$ : "": GOTO 73 5
875 IF JJ < 1 THEN PRINT " --> 0 I S TOO SMALL <__ "; : CALL - 868 :A
N$ : 1111. GOTO 73 5
8 80 AN : II: 'TE XT : HOME : RETURN
DISK MENU
1050 AN$ = "the coLLection of programs to be studied in conjuction with t
he AppLesoft TutoriaL, with a speciaL appearance by" : GOSUB 400
1060 AN$ =
"Po stag e Rate s , the exampLe program from the AppLes o ft Referen
ce Manua L.": GOSUB 400 : PR INT : PR INT
1065 AN$ = " The foLLowing" + CHR$ (34) + "main menu" + CHR$ (34) + "
ets you seLect one of severaL" + CHR$ (34) + "sub-menus" + CHR$
34) + " with the names of the programs on this disk .": GOSUB 400
1070 AN$ "You can choose to pick a program from a sub -menu, or you can
eLect to end the" : GOSUB 400
1075 AN$ = "program. ": GOSUB 400
1076 GOSUB 400
1080 PR INT : VT AB 24
1089 AN$ = "Pres s RETURN t o go to the Main Menu." : GOSUB 400: GOSUB 300
1090 REM ** MAIN MENU **
1100 REM ** MAIN MENU LOOP **
1110 TITLE$ = "T he AppLesoft SampLer Di s k"
1120 SUBTITLE$ = "Main Menu": REM TITLE OF MENU OR SUBSECTION OF PROGRAM
1130 MENU$(1) "ExampLe Programs from The AppLe so ft TutoriaL"
1140 MENU$(2) "Tut o riaL Appendix E : More Programs To PLay With"
1150 MENU$(3) "Po s tage Rates -- From The AppLesoft Reference ManuaL"
1180 MENU$(4) "E nd the program (This op tion wi LL type CATALOG f o r you a
nd wi LL Leave you in AppLesoft.)"
1190 MENU$(5) = "END": REM MENU PROGRAM KEEPS DISPLAYING ITEMS UNTIL IT
INDS THE WORD "end"
1195 OAKEY =
0 : REM HELP NOT AVAILABLE; OPEN-APPL E KEY WILL NOT BE READ
1197 FROM$ = ''''
1200 GOSUB 500
1215 AN$ = ""
1225 VTAB 8
1230 ON AN GOSUB 2000,3000,4000 ,6000: REM RE TURN PRESSED, SO GO TO THE S
ELECTED SEC TION
1240 GOT a
1100
1250 REM
1999 REM BLANK LINE S ARE DONE BY PRESSING THE DO WN-ARR OW KEY
Appendix E
3020 TITLE$ = "AppLesoft TutoriaL"
3030 SUBTITLE$ = "SampLes"
3040 MENU$(1) "SCRAMBLER"
3050 MENU$(2) = "MAGIC MENU"
3060 MENU$(3) = "DISK MENU (Which is this very program -- seLecting it wi
LL onLy resuLt in a Long wait foLLowed by the program sta rting over .
It is incLuded here because it i s included in Appendi x E.)"
3070 IF NOT COL80 THEN MENU$(2) = MENU$(2) + CHR$ (10) :MENU$ (3) = MENU
$(3) + CHR$ (10): REM CHR$(10) I S DOWN-ARROW: ADDING DOWN-ARROWS WI
LL ADD SPACES ABOVE AND BELOW MENU OPTION 3
3080 REM IN 80 COLUMN MODE , THERE IS ENOUGH ROOM THAT THE MENU MAKER ROU
TINE WILL ADD SP ACES AUTOMATICALLY , SO WE DO IT ONLY IF THE COMPUTER
IS NOT IN 80- COLUMN MODE
3090 MENU$ (4) "C ONVERTER"
3100 MENU$(5) = "Return t o Ma in Menu"
3110 MENU$(6) = "end"
3120 FROM$ = "Ma i n Menu" : AN$ = '''':OAKEY 0 : GOSUB 500
3130 IF ESCKEY THEN RETURN
3140 IF AN = 5 THEN RETURN
3150 IF AN = 1 AND NOT AIlE THEN HOME: VTAB 10: PRINT " SORRY , SCRA MBL
ER CAN ONLY BE": PRINT "PLAYED ON AN APPLE IlE . " : VTAB 24: PRINT "PR
ESS RETURN TO GO BACK TO THE MENU . ";: GOSUB 300: GOTO 3000: REM "pa
t ch"
3160 TITLE$ MENU$(AN): REM STOR E NAME OF SE LECTION FOR USE BY EACH ROUT
INE
3165 IF AN 2 THEN TITLE$ = "MAGIC MENU": REM A DOWN-ARROW MAY HAVE BEE
N APPENDED IN LINE 3070
3170 IF AN = 3 THEN TITLE$ = "DISK MENU": RE~' A "PATCH" TO THE PROGRAM:
MENU$(3) HA S AN EXTRA DESCRIPTION
3180 GOTO 9000
3190 REM
5999 RETURN
6000 REM *** CATALOG ***
6010 HOME
6020 VTAB 10
6025 PRINT "J" ;
6030 TITLE$ = "CATALOG"
6040 FOR I = 1 TO LEN (TITLE$)
6050 PRINT MID$ (TITLE$ , I , 1);
6055 K = PEEK ( - 16336) + PEEK ( - 16336)
6060 FOR J = 1 TO 400 * RND (1) : NEXT
6070 NEXT I
6072 POKE 6, 0: POKE 7, 0: REM SEE NOTES FOLLOWING 9060
6075 PRINT
6080 PRINT CHR$ (4);TITLE$
6999 END
DISK MENU
II
9000 REM *** GO TO DI SK ***
9060 POKE 6, 99: POKE 7, 99 : REM LET THE PR OGRAMS FROM APPENDIX E KNOW THA
T THE Y CAN RETURN TO THI S PR OGRAM . US UALL Y, YOU USE A VARIA BLE TO "
TURN ON" OR "TURN OFF" AN OPTI ON
906 1 REM BUT VARIABLE S ARE ALL CLE AR ED BETWEE N PROGRAMS . LOCATIONS 6 &
7 ARE NOT AFFE CTED BY AP PLESO FT, SO THE AUTHOR CHOSE THEM AS A WAY T
o COMMUNI CATE
907 5 PR INT
908 0 PR I NT CHRS (4) ;" RUN " ; TITLES
9090 END
63000 REM *** COMPUTER 10 ***
63010 REM ••• AIlE OR NOT? • ••
63020 REM USES I , J , K, RE - - SE TS AIlE TO 1 IF IT I S AN AIl E
63030 RE M SETS RESULT DEPENDENT ON AVAILABLE HARDWARE
63040 REM RESU LT S OF a MEAN S NO T A lI E; 32 MEANS AIlE BUT NO 80 COLUMNS ;
64 ME ANS AIlE WIT H 80 CO LUM NS BUT NO AU X MEM; 128 MEAN S AIlE WITH A
UX MEM
63050 DA TA 8, 120, 173 , 0, 224 , 141 , 208 , 2, 173, 0, 208 , 141, 209 , 2,
173 , 0, 212, 141, 210, 2, 173, 0, 216, 141 , 211, 2, 173 , 129, 192, 1
73, 129 , 192 , 173 , 179 , 251 , 20 1, 6, 208 , 73, 173
63060 DATA 23, 192, 48 , 60 , 173 , 19, 192 , 48 , 39 , 173, 22 , 192, 48 , 34,
160 , 42 , 190 , 162 , 3, 185 , 0, 0, 150, 0, 153, 162, 3, 136, 208 , 242
, 76 , 1, 0, 8, 160 , 42 , 185 , 162, 3, 15 3
63070 DATA 0, 0, 136, 208 , 247 , 104 , 176, 8, 169 , 128, 141, 207 , 3, 76 ,
73 , 3, 169 , 64, 141, 20 7, 3, 76, 73, 3, 169 , 32, 141, 207 , 3, 76 , 7
3, 3, 169 , 0, 141, 207, 3, 173, 0, 22 4
63080 DATA 205 , 208 , 2, 208 , 24, 173, 0, 208, 205 , 209 , 2, 208 , 16, 173
, 0, 212 , 205 , 210, 2, 208 , 8, 173, 0, 216, 205 , 211, 2, 240 , 56, 17
3, 136 , 192 , 173 , 0, 224, 205 , 208, 2, 240, 6
63090 DATA 173 , 128 , 192 , 76 , 161, 3, 173, 0, 208 , 205 , 209 , 2, 240 , 6,
173, 128 , 192 , 76 , 161 , 3, 173 , 0, 212, 205 , 210, 2, 240, 6, 173,
28 , 192 , 76 , 161, 3, 173 , 0, 216, 205 , 21 1, 2
63 100 DATA 240 , 3, 173, 128, 192, 40 , 96 , 169 , 238 , 141 , 5, 192, 141 , 3
, 192 , 141 , 0, 8, 173, 0, 12, 201 , 238 , 208 , 14 , 14, 0, 12, 173, 0,
8, 205 , 0, 12, 208 , 3, 56, 176, 1, 24
63110 DATA 141 , 4, 192 , 141, 2, 192, 76 , 29 , 3, 234
63120 J = 975 : K = 724
63130 fOR I = 0 TO 249
63140 READ L
63150 POKE K + I , L
63160 NEXT
63170 CA LL K
63 180 RES ULT S PEEK (J )
63190 I F RESU LT S < > 0 T HE ~ AIl E
63200 RETURN
Appendix E
CONVERTER
CONVERTER stands on its own. It is based on the now-familiar
subroutine package. It was derived from MAG I C MENU , and lies in
wait for you to add the sorts of conversions you might find
useful. It can provide the most valuable sort of programming
experience : working intimately with a program written by
experts.
Program Listing
205 IF SAKEY THEN SA$ = CHR$ (P - 128) :AtJ$ = AN$ + 1$ : PR I I.T IS;" '" RE TU RtJ
2 10 IF P > 159 AND P < > 255 THEN IF J + LEN (1$) < FL TH EN I F N TH EN
AN$ = AN$ + CHR$ (P - 128) :J = J + 1: PR INT CHll$ (P) ;: GOT O 149
2 15 IF P < > 255 THEN 240
220 IF J THE N PRINT" ";: POKE 36 ,L: VTAS M + 1: PRINT CHR$ (136) ;: J =
J - 1
225 IF J = a THEN AN$ = ....
230 IF J THEN AN$ =
LEFT$ (AN$ , J)
235 GOTO 149
CONVERTER
240 IF P < > 136 THEN 265
245 IF J THEN PRINT" ";: POKE 36, L: VTAS r1 + 1: PRINT CHR$ (1 36) ;:1$
RIGHT$ (AN$ , 1) + I$ : J = J - 1
250 IF J = 0 THEN AN$ = ""
255 IF J THEN AN$ = LEFTS (AN$ , J)
260 GOTO 149
265 IF P = 141 THEN AN$ = AN$ + 1$ : PRINT 1$;" " : RETURN
270 IF P < > 149 THEN 294
275 IF NOT LEN (IS) THEN 149
280 AN$ = ANS + LEFTS (IS , 1):J = J + 1 : PRINT LEFT$ (1$,1);
285 IF LEN (1$) = 1 THEN 1$ =
290 IF LEN (IS) THE~ 1$ = RIGHT$ (1$, LEN (1$) - 1)
292 GO TO 149
294 IF P = 155 THEN ESCKEY = 1: PRINT: RETURN
296 GOTO 149
300 REr1
** GET RETURN **
414 IF I > THEN IF RIGHT$ (ANS,1) =" " THEN ANS = LEFTS (AN$,I - 1
)
417 IF P + < PEEK (33) THEN 1$ = ANS: MIS "": GOTO 440
420 J = PEEK (33) - P + 2 : 1 = J
425 I = I - 1: IF I THEN IF MIDS (AN$,I,1) < >"" THEN 425
430 IF = 1 THEN I = J
431 IF = 0 THEN PRINT: GOTO 410
435 IS = LEFT$ (ANS,I - 1) : IF LEN (AN$) > I THEN ANS RIGHTS (ANS, LEN
(AN$) - Il
440 IF AIlE THEN PRINT 1$ ;
445 IF NOT AIlE THEN K LEN (IS) + 1: FOR I = 1 TO LEN (I$):J = ASC
( RIGHT$ (I$,K - Il) : PRINT CHR$ (J - 32 * (J > 96 AND J < 123»;: NEXT
I
447 P = PEEK (36): IF COL80 THEN IF P = PEEK (1147) THE~ P = PEEK ( 14
03)
450 IF LEN (ANS) THEN IF P < > 0 THEN PRINT
455 IF LEN (ANS) THEN 410
460 IF P < > 0 THEN IF MID$ (1$, LEN (1$),1) < > " " THEN PR INT" "
465 RETURN
500 REM
Appendix E
530 J = O:K = O:JJ O:KK O: LL O:MM O:NN 0:00 O:AN 0
535 00 = OA
540 AN$ = ""
545 II = 1
550 KK = KK + INT ( LEN (MENU$(II» / (27 + 35 * (COL80 =
1»)
555 IF II < 12 THEN IF ~'ENU$(Il + 1) < > "End" AND r1ENU$(II + 1) < >
"end" AND MENU$ ( II + 1) < > "END" THEN II = II + 1: GOTD 550
560 LL II
565 NN 0: IF LL * 2 + KK < 14 THEN NN =
1
570 MM 3 : IF COL80 THEN ~IM = 9
575 JJ 3 + MM: IF LL > 9 THEN JJ = 4 + MM
590 TEXT : HOfiE
595 AN$ = TITLE$ : GOSUB 400: POKE 36, PEEK (33) - LEN (SUBTITLE$) - 1:AN
$ = SUBT ITLE$
600 GOSUB 400
605 FOR II = 1 TO PEEK (33): PRINT "
NEXT
II • •
PRINT
615 FOR I I = 1 TO LL
'"
620 HTAB riM: PRINT II;". ";
625 VTAB PEEK (37): IF COL80 THEN VTAd PEEK (15311
630 POKE 32 ,J J: POKE 33, PEEK (331 - JJ : PRINT
635 AN$ = MENU$(III: GOSUB 400
640 POKE 32 , 0: POKE 33, PEEK (331 + JJ : PR INT
645 IF NN THEN PRINT
650 NEXT II
655 IF PEEK (37) > 16 THEN PRINT "TOO MANY ~IENU ITEMS OR TOO LONG LINE
S. ": STOP
660 TEXT: VTAB 17:AN$ = "Select option >": GOSUB 400: PRINT
665 FOR II = 1 TO PEEK (331: PRINT" ";: NEXT
670 IF NOT 00 OR NOT AILE THEN PRINT
675 IF LEN IFROM$) THEN AN$ = "F or " + FROm + ": press ESC": GOSUB 400
680 PRINT
685 IF AIlE THEN PRINT "To erase: use the DELETE key"
690 AN$ = "To se Lect : type a number from 1 to "+ STR$ (LL)
700 GOSUB 400: PRINT
705 IF NOT 00 THEN 720
710 IF AIlE THEN PRINT "For descriptions: press OPEN-APPLE-?"
715 IF NOT AIlE THEN PRINT "F OR DESCRIPTIONS: FOLLOW ANSWEII WITH ? "
720 AN$ = "To go to seLected item: p re ss RETURN" : GOSUB 400: PRI IH
723 IF NOT 00 THEN AN$ = "(There are no descriptions availabLe)": GOSUB
400
725 FL = 3 : AN$ = ""
735 REM
740 VTAB 17: HTAB 17: CALL - 868: HTAB 17
745 IF AILE OR NOT LEN (FROM$) THEN GOSUB 100: GOTO 795
750 = O:J =O:M PEEK (371:L PEEK (361:0AKEY = 0
755 I = I - 1: IF I < 0 THEN K = - K :I =
5:J = 1 - J: NORMAL IF J THEN
INVERSE
760 PRINT" ";: POKE 36,L: VTAB fl +
765 P = PEEK ( - 16384): IF P < 128 THEN 755
770 NORMAL
775 IF P = 155 THEN POKE - 16368, 0 : ESCKEY 1: GOTO 795
780 L = PEEK (36) : VTAB 20 : HTAB 1 : CALL - 868: VTAB M + 1 : HTAB L + 1
785 INPUT "";AN$
795 VTAB 19
800 IF NOT OAKEY THEN 825
805 IF NOT 00 OR OA$ < > " ? " AND llA$ < >" /" THEN 735
815 JJ = VAL (AN$I: IF JJ > 0 AND JJ < =
LL THEN II =JJ: GOTO 880
820 IF J J = 0 THEN PRINT "--> PLEA SE SELECT A NUMBER FIRST <--" ;: CALL
- 868 : PRINT : AN$ = "": GO TO 735
825 IF SAKEY THEN 735
830 IF ESCKEY THEil IF LEN (FROM$) THEil 880
835 JJ = VAL (AN$): IF JJ > 0 AND JJ < LL THEN II =JJ
840 IF LEN (AN$) = 0 THEN 735
845 IF 00 THEN IF NOT AIlE AND ( RIGHT$ (AN$ , 1) = "?" OR RIGHT$ (AN$,
1) = "/") THEN IF II > 0 AND II < LL THEN OAKEY =
1 : GOTO 880
850 IF LEN (AN$) THEN K = 0 : FOR I = 1 TO LEN (AN$):J ASC ( RIGHT$
(AN$ , I ) : K = K + (J < > 32 AND (J < 48 OR J > 57) : NEXT I: IF K THEN
PRINT" --> PLEASE USE DIGITS <--";: CALL - 868 : PRINT :AN$ =
"": GOTO 735
CONVERTER
II
860 IF NOT JJ THEN IF LEN ( AN$) THEN K = 0: FOR I = 1 TO LEN (ANS) :J
ASC ( RIGHTS (AN$,I)):K = K + (J = 48): NEXT I: IF NOT K THEN PRINT
--> PLEASE US E DIGITS <- - " ; : CALL 868: PRINT :AN$ = "": GOTO
735
870 IF JJ > LL THEN PRINT" -- > ";JJ;" I S TOO LARGE <--";: CALL
863 : PRINT : ANS = "" : GOTO 735
875 IF JJ < 1 THEN PRINT" --> 0 I S TOO SMALL <--" ; : CALL - 868:A
NS = "": GOTu 735
880 AN = II: TE XT : HOME : RE TURN
1000 REM *** SUBROUTINES ***
1010 REM SOME SPEC I AL ROUTINES FOR THI S PROGRAM
1100 REM Y OR N?
1110 REM PUT NAME OF CALLING ROUTINE IN AN$
1120 REM UPON RETURN, AN WILL BE 1 IF YES , 0 IF NO
11 30 REM USES AN, AN$ , I, 11$
1135 PRINT
1140 lI$ = " Do you want to do another" + AN$ + " conversion? (Y OR N) "
1145 HTAB 1: VTAB 22 : CALL - 958 : AN$ = 11$: GOSUB 400:FL = 2: GOSUB 100
1150 I = 0: IF LEN (AN$ ) THEN ASC ( AN$ ) : IF I < > ASC ("y") AND I
< > ASC ("y ") AND I < > ASC ( "N" ) AND I < > ASC ("n") THEN 11
45
115 5 IF NOT I THEN 1145
1160 AN = 0 : IF I = ASC ( " y" ) OR ASC ("Y") THEN AN
1170 RETURN
2000 REM *** BEGIN PR OGR AM ***
20 10 REM THE CONVERTER - A PROGRAM SK ELETON USED FO R MEASUREMENT CONVERS
IONS - 1982
2020 GOSUB 63000 : REM SET AILE TO TRUE (1) OR FAL SE (0)
2025 IF RESULTS> 64 THEN CO L80 = 1: PRINT CHR$ (4) ;" PR#3": REM IF
N 80-CO LUMN CARD I S PRESENT, USE IT . IF YOU DON'T WANT IT, CHANGE T
HE LINE TO:
1025 PRINT CHR$(21)
II Appendix E
2350 MENU$( 7)
2360 MENU$ ( 8)
2370 MENU$(9)
2380 MENU$ ( 1OJ
2390 ~'ENU$(11) = ""
2400 MENU$(12) = "End th e program"
2405 IF LEN (FROM$ ) THEN MENU$ ( 12) "End program and go t o Di sk Menu"
2410 REM
2430 AN$ =
2440 OAKEY = 0 : REM NO HELP AVA I LABLE
2450 GOSUB 500: REM DO MENU
2455 IF ESCKEY THEN GOTO 22000: REM SEE NOTE S FOLLOWING LINE 9060 IN TH
E DISK MENU PROGRAM
2460 ON AN GOSUB 11000, 12000,13020,14000,15000,16000,1 7000,1 8000,190 00 , 2
0000 , 21000, 22000
2470 GOT O 227 0
10999 REM
CONVERTER
11270
11280
11 290
IF AN THEN 11200
RETURN
REM
-
11300 RETURN: REM PROGRAMMER TO CREATE CONVERSION ROUTINE HERE
12000 REM * •• lEMPERATURE ***
12010 REM
12600 RETURN: REM PROGRAMMER TO CREATE KELVIN CONVERS ION ROUTINE HERE
13000 REM *** SPEED ***
13010 REM
CONVERTER
13020 T ITLE$ = "Conve rs ions"
13030 SUBT ITLE$ = "Chang e speed measure"
13040 MENU$(1) "Ki Lometers/hour to mi Les/hour"
13050 MENU$(2) "MiLes/hour to kiLometers/hour
13060 MENU$(3) "Return to Main Menu"
13070 MENU$(4) "end"
13080 FROM$ = "Main Menu":AN$ = "" : OAKEY 0: GOSUB 500
13090 IF ESCKEY THEN RETURN
13100 IF AN 3 THEN RETURN
13110 TITLE$ =
MENU$(AN): REM STORE NAME OF SELECTION FOR USE BY EACH ROU
TINE
13120 ON AN GOSUB 13200,13400
13130 GOTO 13000
13140 REM
Appendix E
21999 RETURN
22000 REM *** SELECTION 12 ***
22010 REM *** END THE PROGRAM ***
22020 IF PEEK (6) = 99 AND PEEK (7) 99 THEN PRINT PRINT CHR$ (4)
;"RUN HELLO": END
22050 TEXT : HOME : TEXT : END
63000 REM *** COMPUTER ID ***
63010 REM *** AILE OR NOT? ***
63020 REM USES I,J,K,RE -- SETS AILE TO 1 IF IT IS AN AILE
63030 REM SE TS RESULT DEPENDENT ON AVAILABLE HARb~ARE
63040 REM RESULTS OF 0 MEANS NOT A lIE ; 32 MEANS AIlE ~UT NO 80 CO LUMN S;
64 MEANS AIlE WITH 80 COLUMNS BUT NO AUX MEM; 128 MEANS AIlE WITH A
UX MEM
63050 DATA 8, 120, 173, 0, 224 , 141, 208 , 2, 173, U, 208 , 141 , 209 , 2,
173, 0, 212, 141, 210 , 2, 173, 0, 216, 141, 211, 2, 173, 129, 19 2, 1
73 , 129, 192, 173, 179, 251 , 201 , 6, 208 , 73, 173
63060 DATA 23 , 192 , 48 , 60 , 173, 19, 192, 48, 39, 173, 22 , 192, 48, 34 ,
160, 42, 190, 162, 3, 185, 0, 0, 150, 0, 153, 162, 3, 136, 208 , 242
, 76 , 1, 0 , 8, 160 , 42 , 185, 162, 3, 153
63070 DATA 0, 0, 136, 208 , 247 , 104, 176 , 8, 169, 128 , 141, 207 , 3, 76 ,
73, 3, 169, 64 , 141, 207 , 3, 76 , 73 , 3, 169, 32, 141 , 207 , 3, 76 , 7
3, 3, 169, 0, 141 , 207 , 3, 173, 0, 224
63080 DATA 205 , 208 , 2, 208 , 24 , 173, 0, 208 , 205 , 209 , 2, 208 , 16 , 173
, 0, 212 , 205, 210, 2, 208 , 8, 173, 0, 216 , 205 , 211, 2, 240, 56 , 17
3, 136 , 192, 173, Q, 224 , 205 , 208 , 2, 240 , 6
63090 DATA 173, 128, 192, 76, 161 , 3, 173, 0, 208 , 205 , 209 , 2, 240, 6,
173, 128 , 192, 76 , 161, 3, 173 , 0, 212, 205, 210 , 2, 240, 6, 173,
28 , 192, 76, 161 , 3, 17 3, 0, 216 , 205 , 211 , 2
63100 DATA 240 , 3, 173, 128 , 192 , 40, 96, 169, 238 , 141 , 5, 192, 141 , 3
, 192, 141 , 0, 8, 173, 0, 12, 201, 238 , 208 , 14, 14, 0, 12, 173, U,
8, 205 , 0, 12, 208 , 3, 56, 176, 1, 24
63110 DATA 141, 4, 192, 141, 2, 19 2, 76, 29 , 3, 234
63120 J = 975:K = 724
63130 FOR I = 0 TO 249
63140 READ L
63150 POKE K + I , L
63160 NEXT
63170 CALL K
63180 RESULTS PEEK (J)
63190 IF RESULTS < > 0 THEN AILE
63200 RETURN
Appendix E
Some Final Thoughts
Glossary
Glossary
arithmetic expression: A combination of numbers and
arithmetic operators (such as 3 + 5) that indicates some
operation to be carried out.
Glossary
binary operator: An operator that combines two operands to
produce a result ; for example + is a binary arithmetic operator,
< is a binary relational operator, and OR is a binary logical
operator. Compare unary operator.
Glossary
central processing unit: See processor.
cold start: The process of starting up the Apple lie when the
power is first turned on (or as if the power had just been turned
on) by loading the operating system into main memory, then
loading and running a program . Compare warm start.
Glossary
conditional branch: A branch that depends on the truth of a
condition or the value of an expression; compare unconditional
branch.
Glossary
deferred execution: The saving of an Applesoft program line
for execution at a later time as part of a complete program ;
occurs when the line is typed with a line number. Compare
immediate execution.
II Glossary
display: (1) Information exhibited visually, especially on the
screen of a display device. (2) To exhibit information visually.
(3) A display device.
Glossary
fixed-point: A method of representing numbers inside the
computer in which the decimal point (more correctly, the binary
point) is con;:;idered to occur at a fixed position within the
number. Typically, the point is considered to lie at the right end
of the number, so that the number is interpreted as an integer.
Fixed-point numbers of a given length cover a narrower range
than floating-point numbers of the same length, but with
greater precision. Compare floating-point.
Glossary
high-level language: A programming language that is relatively
easy for humans to understand. FORTRAN , BASIC, and Pascal
are all examples of high-level languages. A single statement in a
high-level language typically corresponds to several instructions
of machine language.
Glossary
interface: The devices, rules, or conventions by which one
component of a system communicates with another.
K: Two to the tenth power, or 1024 (from the Greek root kilo,
meaning one thousand) ; for example, 64K equals 64 times 1024,
or 65,536.
keyboard: The set of keys built into the Apple lie compute r,
sim ilar to a typewriter keyboard , for typing information to the
computer.
Glossary
loop: A section of a program that is executed repeatedly until
the limit is met.
Glossary
nested loop: A loop contained within the body of another loop
and executed repeatedly during each pass through the
containing loop.
Glossary
program line: The basic unit of an Applesoft program ,
consisting of one or more statements separated by colons (:) .
Glossary
read-only memory: Memory whose contents can be read but
not written; used for storing firmware. Information is written
into read-only memory once, during manufacture ; it then
remains there permanently, even when the computer's power is -J
Glossary
scientific notation: A method of expressing numbers in te rms
of powers of ten , useful for expressing numbers that may vary
over a wide range, from very small to very large. For example,
the number of atoms in a gram of hydrogen is approximately
6. 02E23 , meaning 6.02 times ten to the 23rd power. (The letter E
stands for "exponent. ") The number is easier to understand in
this form than in the form 602000000000000000000000 .
Applesoft uses this method to display real precision numbers
with more than nine digits.
Glossary
subroutine: A part of a program that can be executed on
request from any point in the program , and which returns
control to the point of the request on completion.
Glossary
video monitor: A display device c~pable of receiving video
signals by direct connection only, and which cannot receive
broadcast signals such as commercial television . Can be
connected directly to the Apple lie computer as a display device.
Compare television set.
warm start: The process of restarting the Apple lie after the
power is already on , without reloading the operating system into
main memory and often without losing the program or
information already in main memory. Compare cold start.
Glossary
Index
Note: Boldface page numbers
indicate figures.
III Index
changing your work, see editing
chapter summaries
Chapter 1 34
Chapter 2 70
Chapter 3 86
Chapter 4 120
Chapter 5 141 167
character 6
limit 6, 7
strings 123 controlling spaces in your
CHRS statement 146, 202 programs 64-69
CLEAR statement 129, 146 CONVERTER program 172, 211
clearing screen , 76, 150 copy over, with [ RIGHT - ARROW I
code ix key 74
colon 90, 177 correction of lines, see editing
use, combining statements with counters 60, 175
REMs 90 creating visual impressions 93
COLOR - statement 14-18, 17, cross-referencing with utilities
20-23, 146, 160 programs 203
color crossed loops 62, 62
groups 17, 17, 146 cursor 3, 3
in high-resolution blinking-underline 182
graphics 114, 118 in high-resolution
in low-resolution graphics graphics 114
14-18, 20-23 moving to right without
plotting 17 copying spaces 80
table 146 cursor-moving keys 85
using to create visual
impressions 89 D
COLORBOUNCE program 89-100,
DATA statement 147
134-135
decimal pOints, lining up 132
adding noise 100
DECIMAL program 132
how it works 94
default drive 48
listing 93
deferred execution 37-41
COLORBOUNCESOUND
advantage of 41
program 135
execution statement, errors
columns 14
in 163
combination of statements 56
DEL statement 83, 147
comma 64, 65, 177
DELETE command 83, 145, 148
compiling 202
[DELETE I key 83
completing instructions 13
determinate variable
compressing programs 201 , 202
counter 175
computations 9-12, 27-33
determinate loops
order of 30
( IF .. • THEN) 52
Computer Identifier
DIM statement 136
Routine 180, 186
dimensioning arrays 175
computer
concepts 137
language ix
disk drive 48, x
program ix DIS K MENU 201
turning off power 8
Disk Operating System , see DOS
concatenation 130
display
conclusion 140
differences in graphics and
conditional statement 50, 52
text 66
rules 51
horizontal , use of VTAB 66
symbols 51
vertical , use of TAB 66
Applesoft Tutorial
distinguishing variables 26 escape mode 111
division 10 limits 76-77
?DIVISION BY ZERO ERROR 164 practice sessions 74-81
dollar sign rules for using 73-74
in string variables 124 summary table 86
use with variable 68 execution , program 43
DOS (Disk Operating System) 47 exponentiation 10
DOS commands 145, 156 extra spaces in program lines, --'
CATALOG 47, 202 how to avoid 80
DELETE 83, 145, 148
PRI 145, 156, 169 F
SAVE 48, 157 false 190
DOS Pro rammer 's Tool Kit 202 condition 50
DOWN-ARROW key 84 fancy printing 8
drawing 118, 150, 151 file types 146
diagonals 104 flags 191 , 202
high-resolution graphics 116 FOR statement 148
horses 104 necessity for matching
lines 20-23, 104 NE XT 62
pOints 104 FOR / NE XT
drive 2, hint using 48 loops 59
see also second disk drive statement 59-63, 60
duplicate strings 128 defining variable rang e 59
formatting 132, 201
E ?FORMULA TOO COMPLE X
editing 4-6, 73-86, 85 ERROR 164
practice sessions 74-81 40-columndisplay 175
inserting text 77-81 friendly menus 171
changing text 74-76 functions
getting rid of lines 82-83 built-in arithmet ic 98
history 84-85 I NT 152
summary of features 86 LEFH 125, 153
80-column display 175 LEN 124, 153
80-column text card 183, 187 MID$ 125, 154
keeping inactive x PEE K 155
elements 136 RI GHH 125, 156
END 109, 148 RND 156
endless repetition 108 STR$ 132, 157
equal sign (=) 27 TAB 157
erase, with ILEFT-ARROW I key 74 VAL 131 , 158
error messages, format for
163-166 G
error trapping 110, 134, 155, game construction 89
168, 188 dice 103
[ESC [E 76 garbage 23
IEsc lF 76 GET RETURN routine 183
IEsC I key 73, 167, 182 getting rid of program lines 82,
alternati ng with A, B, C, 83
and D keys 84 good programming pract ice 96
in conjunction with I , J, K , GOSUB statement 149, 173
and M keys 85 in main rout ine 111 -113
IEsC I @ 76 GOTO statement 42-45, 149
escape commands 76 GR statement 14, 149
graphics 13-18, 89-122
additional subroutines 111 ,
112
Index
drawing lines 20-23, 11-118 initialized disk 47
grid 14 I NPUT routine 182
high-resolution 113-122 I NPUT statement 45-47, 94-96,
low-resolution 13-18 152,177
text window 14, 57 execution 46
gray box x use 46
greater than or eq ual to writing 96
(>=) 50,51 inserting text
greater than zero arguments 100 into an existing line 77
step-by-step instructions 77
instructions, stored sequence
H of 40
INT function 101 , 152
&H 204
halt listing 153 Integer BASIC 146
halting program listing 84 integers
HCOLOR = statement 114-119, function 101
printing 42
115, 149,160
I NVERSE statement 8, 152
help 167
help screens 185
HGR statement 114-119,150
K
using colors with 118 keyword 5
high-resolution graphics
113-119, 115, 150 L
HIMEM : 161
LEFTS function 125, 153
HL I N statement 20-22, 21, 150
I LEFT-ARROW ) key 6, 78
syntax 20, 21
HOME statement 9-12, 150
in escape mode 74
LEN function 124, 153
horizontal coordinates 113
horizontal row 15 length function 124
horse drawing 104 less than or eq ual to ( <=) 51
LET statement 24-29, 153
HORSES program 112
HPLOT statement 116-119, 150 defining a variable with 24
syntax 25, 27
combination of lines in 117
HTAB statement 67-69, 151
value 27
use with VTAB limiting variables 52
on APPLESOFT SAMPLER 67 line breaks 183
HUE program 62 line differences, when
humanized programs 211 listed/executed 38
hung system 167 line numbers 38, 58
leaving space between 40
I lines, replacement of 39
LIST statement 38-44, 153
identifying address 170 line numbers specified in 44
IF statement 53, 56 listing programs
if you or your program get how to see whole list 57
stuck 167 how to resume 153
IF .• . THEN statement 52, LOAD command 48, 53, 145,
151 154
? ILLEGAL DIRECT ERROR 164 loading program from disk 54
? I LLEGAL QUANT I TY ERROR 19, location in memory 25
68, 96, 105, 139, 164 LOMEM: 161
immediate execution 37 long programs , to list portions
indeterminate variable of 84
counters 175
indeterminate loops (GOTO) 52
infinite loop 58
Applesoft Tutorial
loops 52
using to scan through a
o
ON , , , GOSUB 204
string 127
with the GOTO ONERR GOTO 155
~PEN-APPLE I key 167, 176, 182
statement 42-44
?OUT OF DATA ERROR 165
low-resolution graphics
? OUT OF MEMORY ERROR 165
mode 14
low-resolution grid
coordinates 23
output
in columns 64
with no spaces between
-
M words 64
?OVERFLOW ERROR 165
&M 204
machine language 50, 170 p
MAGIC MENU program 171
main memory 24 parentheses 135
making choices, Applesoft 's Applesoft rule 33
ability to 50 to modify precedence 32
making changes, see editing pause symbol xi
measurement conversion 172 PEEK function 98, 155
memory 38, 169 different numbers of
PEEKs 99
address range 98
locations 170 with variables 98
Menu Maker Routine 184 PLOT 14-22, 155
MID$ function 125, 154 as used with HL IN
minus sign (-) 10 statement 22
MOIRE program 118 coordinates 15, 67-68
Monitor program , prompt error messages 19
character (*) 170 used with HL I N 22
moving cursor 73 plotted points , fine
multiple statements on a line 90 resolution 116
multiplication 10 plus sign (+) 10, 130
POKE statement 81 , 155
power, turning off 8
N PR# command 145, 156
naming programs 54, 97 PR#1 169
nested loops 62 precedence 30, 30
NEW command 37-38, 47, 57, order for carrying out
154 arithmeHc operations 32
NEXT statement 154 PRINT statement 4-7, 4, 155
?NEXT WITHOUT FOR ERROR 165 interchangeable with question
NORMAL statement 8, 154 mark 30
NOTRAC,E statement 109, 154 use of quotation marks
null string 124, 129, 134, 185 with 27
numbering systems 16, 16, 68 using commas and
in graphics 68 semicolons 65
in text 68 with TAB statement 66
numbers, displaying 42 printing Applesoft
numeric values, comma and programs 169
semicolon used with 65 problem identification on the
numeric variables 123 screen 5
Index
program (s) RF modulator, using with
asking questions in 201-204 television set 18
block structured 89, 172-173 RIGHTS function 125, 156
building blocks in 89 [ RIGHT - ARROW I key 6, 78
compression of 201 , 202 in escape mode 74
control 173-174 RND function 100, 156, 171
correcting lines in 41 combining with graphics
execution of 43 statements 103
resuming after ROT= 160
I CONTROL ~ C 147 rounded numbers 12
how to see whole listing rows 14
of 57, 84 RUN2 174
interaction with users 94 RUN statement 38-44, 157
lines, editing 203 in regard to line numbers 61
listing 153 to start at some other line 44
loading, from disk 54
numbering lines 38, 40-41 , 57 s
saving 47-48, 97, 157 SAVE command 46-49 , 145,
speed 188-189 157
using color to create 89 saving programs , by using DOS
writing 40,172-174,180-192, (Disk Operating System) 47-48
201-204, x SCALE= 160
prompt character (J) 3, 3, 170 scientific notation 12
SCRAMBLER program 171
Q screen boundaries 92
question mark (? ) screen display 8, 157, see also
preceding error message 163 display
using instead of PRINT screen formatter routine 183
statement 30 , 32 SCRN 160
questions, unanswered 8 scrolling 44, 138, 155, 176
quotation marks ( .. ) 3, 11 , 27, scrolling window 176
41 second disk drive 48, 49, 55
in string variables 124 semicolon 64, 65
use of 5 ISH I FTI key 3
Simulating a pair of dice 103
R slash (!) 10
small numbers
radio-frequency (RF) rounding of 11
modulator 18 treatment of 11
random numbers 100-104, 176 [SOLID-APPLE I key 182
RANDOM program 102
ISPACE i bar 73
READ statement 147, 156
spaces in program lines, how to
?REDIM'DARRAYERROR 139,
avoid 80
165
SPACES program , APPLESOFT
regular increments 59 SAMPLER 67
REM statement 58, 59, 113,
spag hetti code 172, 174
156, 201 SPC 161
remarks (REM) 58
speaker, Apple lie 97
RENUMBER program 203 SPEED= 160
renumbering line numbers 202
reserved words 26
table of 160
IRETURN I key 4, 13, 43
RETURN statement 156, 173
?RETURN WITHOUT GOSUB
ERROR 107, 166, 173
Applesoft Tutorial
statement 4-7 T
and commands 168
as building blocks in TAB function 66, 157, 161
programs 89 follow with argument 66
control 91 table of symbols 51
execution 37 television set , connecting to
fixing mistakes 6 Apple lie 18
multiple on a line 21 temporary prog ram storag e 38
problems with 5 text formatting , on the
storage 40 screen 184
reasons for combining 91 text mode 23
TEXT statement 158
used in combination with one
another 56 text window 14
STEP command 61
in graphics 57
stopping program listing 84 three-level nesting 63
storage spaces 24 TO 161
TRACE statement 108-110, 108,
storage, temporary 38
STR$ function 132, 157 158
string functions 124, 131 trailing zeros , display of 11
? STR I NG TOO LONG ERROR 124, transferring programs 53
166 troubleshooting 5
strings true 190
adding together 130 true condition 50
and arrays 123-140 two-dimensional array 137
characters in 124 two-level nesting 62
duplicate 128 ? TYPE MISMAT CH ERROR 131 ,
null 124, 129, 134 166
programming practices 126 typing mistakes, correcting 73
punctuation and spaces
in 126 u
using loops with 127 unary minus sign 31
variables ?UNDEF'D FUNC T IO N
how to reset to zero 124, ERROR 166
129 ? UNDEF 'D ST ATEMENT
names 123 ERROR 166
manipulating 124 underline cursor, input
subroutine 104, 106 using 171
blocks 173, 174, 180 unformatted text 201
for displaying IUP-ARRow l key 84
instructions 171
subscripts 136
subtraction 10
switching modes, from graphics
uppercase, for instructions
users 94
checking for errors 110
3
-
to text 23
symbols , used in the tutorial xi
syntax 46
? SYNTAX ERROR 19, 26, 97,
124, 166
system identification
routine 184, 186
Index
v w
VAL function 131 , 158 warning symbol xi
value 25, 27 warnings
increasing in variable 28 ?SYNTAX ERROR 3
variables 24-30, 45, 68, 105, 110, I CAPS LOCK I key on 3
182 FOR statements 62
defining 24,153 IRETURN I key 14
defining with LET starting up 8
statement 24 turning off power 8
increasing value of 28 WELCOME program 69
listing in programs 182 wrap around 68, 77, 81
naming 24, 123, 153, 175, 189 write-protected 48
numeric 24, 123, 153
storage in memory 24, x
187-188 XPLOT 160
string 123
summary of rules 29
table 187-188
z
use in FOR/NEXT 59 , 60 zeros, how not to generate 103
use in subscript 136
using CLEAR statement 146
values are not static 92
vertical column 15
vertical coordinates 113
video mon itor x
VLIN loop program 57
VLI N statement 22, 57 , 158
VTAB statement 66-69, 158
Applesoft Tutorial