Académique Documents
Professionnel Documents
Culture Documents
-,.J
TABLE OF CONTENTS
WELCOME
CHAPTER 1
GETTING STARTED
2 Introduction
3 What you will need
4 Hooking up the TV
4 Plugging in the game controllers
4 The Disk II
5 The cassette recorder
5 The Apple keyboard: the RESET, SHIFT and ESC keys
9 Keyboard notation
10 Control, and other characters : the CTRL and REPT keys
11 Setting the tape recorder
13 The usual procedure for loading tapes
14 Listening to a computer tape: a helpful hint
15 Using a disk drive
17 The Menu
17 Stopping the computer
18 Setting the TV color
19 Playing Little Brick Out
CHAPTER 2
BEGINNING APPLESOFT
22 A first look at the PRINT statement
25 Applesoft's format for numbers
26 More a b out RETURN
27 Easy editing features : the arrow keys
29 Putting colors on the screen: GR, TEXT, COLOR= and PLOT
31 PLOT error messages
32 Drawing lines
34 The game controls: PDL
35 Pigeonholes: an introduction to variables
39 Precedence among arithmetic operators, or who's on first?
41 How to avoid precedence
CHAPTER3
ELEMENTARY PROGRAMMING
44 Deferred execution: NEW, LIST, RUN and HOME
48 Elementary editing: DEL
5~ Elementary aerobatics: GOTO loops
5~ Some more things that make life easier : more editing tips
52 The moving cursor : editing with the ESC key
53 A word about learning Applesoft BASIC
54 An accident about to happen
55 The truth: arithmetic and logical assertions
59 Order or precedence for operations
59 The IF statement
6~ Saving programs on diskette : SAVE, CATALOG, RUN and LOAD
61 Saving programs with a cassette recorder: SAVE
62 More graphics programs : REM
64 FOR/NEXT loops
67 A wrong program
67 A last example of nested loops
68 Getting flashy: INVERSE, FLASH and NORMAL
68 PRINTs charming: comma, semi-colon, TAB, HTAB and VTAB
II
CHAPTER 4
LOTS OF GRAPHICS
74 Talking to a program on the RUN: INPUT and a bouncing ball
78 Off the walls: a program with lots of bounce
79 Making sounds: PEEK(-16336)
81 Noise for the bouncing ball
81 For higher notes
82 Random numbers: RND and INT
84 Simulating a pair of dice
85 Subroutines: drawing horses using GOSUB and RETURN
87 Traces: TRACE, NOTRACE and END
89 A better horse-drawing subroutine
91 High-resolution graphics: HGR, HCOLOR= and HPLOT
CHAPTER 5
STRINGS AND ARRAYS
l(,Hil Stringing along: LEN , LEFT$, RIGHT$, IUD$ and CLEAR
105 Concatenation got your tongue? : putting strings together
105 More string functions : VAL and STR$
108 Introducing arrays: DIM
110 Array error messages
III Conclusion
III
APPENDICES
114 Appendix A: Summary of Commands
IV
WELCOME
This manual is designed for people who want to learn to program
in Apple's Applesoft BASIC. With this manual, and an Apple
computer, and a bit of your time and attention, you will find
that there is nothing difficult about learning how to program a
compute r. At first, as with anything new, programming will be
unfamiliar, but this manual was designed to alleviate any
apprehension you might have. First of all, there are no hidden
secrets that you have to know before you can read this manual.
Everything is revealed, and only one thing at a time is
ex plained. If you start at the beginning, !EY everything as
it comes along, and make up your mind to take your time, it is
pretty much guaranteed that you will learn how to program.
The real secret is taking your time and trying everything. You
cannot learn programming by merely reading this or any other
book. Like learning to ride a bicycle or play the fiddle, you
must learn by doing. You must make mistakes and correct them,
and not feel too bad when you do make mistakes.
v
RADIO AND TELEVISION INTERFERENCE
The equipment described in this manual generates and uses radio
frequency energy. If i t is not installed and used properly,
that is in strict accordance with our instructions, it may
cause interference to radio and television reception.
This equipment has been tested and complies with the limits for
a Class B computing device in accordance with the
specifications in Subpart J of Part 15 of FCC rules. These
rules are designed to 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.
VI
•
• CHAPTER 1
• GETTING STARTED
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
INTRODUCTION
This manual Hill show you how to plug in your Apple (easy) and
Hill be a guide as you learn to program it (also easy) . If you
are an Old Hand at programming, you will find some new features
and conveniences in Applesoft BASIC that make programming a lot
more fun . If you are a Newcomer to programming , you will also
find many features a nd conven iences i n Applesoft BASIC that make
programming a lot of fun. But, if you are a Newcomer, be warned .J
that programming, though not difficult, can only be learned by
doing . Hore will be said on this topic later, but
remember- - this is a book to be used, not merely perused .
If you have not already done so, please take a few minutes to
complete and mail your OWNER/WARRAtiTY REGISTRATION CARD . This
Registration Card will register your Apple with the factory,
give you membership in the Apple Software Bank, and include you
in our list of Apple owners . If you don ' t send us this card you
will not receive any newsletters, information about new
accessories for your Apple, nor any of the other information
that is frequently mailed to Apple owners . So please mail in
the completed card .
.J
2
The purpose of this symbol is to alert you to an unusual
Applesoft feature. The situation described may cause you to
lose your program.
3
The Modulator comes with instructions on how to hook it
up. Your TV's ability to receive normal programs will not
be diminished (or enhanced) by having the Apple hooked up
to it.
HOOKING UP THE TV
If you have a color (or black and white) monitor, just connect
the appropriate cable from the jack ma.r ked VIDEO OUT (on the
rear of the Apple) to the input of the monitor.
THE DISK II
If you have a disk drive, unpack it carefully. Then read the
preface and the first chapter (pages 2 through 8) of the Disk
Operating System (usually called DOS) manual that came in the
Disk II package. Those pages will give you complete
instructions on how to set up your disk drive.
4
THE CASSETTE RECORDER
(if you are not using a disk drive, or
if you are going to use both recorder and disk)
Use the supplied cable (the one with two plugs on each end) to
connect the Apple to your cassette tape recorder. Connect one
black plug to the HIC or MICROPHONE jack on the recorder, and
the other black plug (on the opposite end of the cable) to the
jack on the back of the computer marked CASSETTE OUT. Connect
the grey plug on the recorder end of the cable to the recorder's
EAR or EARPHONE or HON or MONITOR jack on the recorder
(different brands use different words). Connect the grey plug
on the computer end of the cable to the jack marked CASSETTE IN.
"OUT" means " out of the computer" and "IN" mean·s "into the
computer ." All that remains is to plug the cassette recorder's
power cord into a wall outlet, and it will be ready to use.
Now close the top of the Apple. Plug the Apple end of the
computer's power cord into the Apple (on the rear of the Apple,
next to the power switch), and the other end into a three-prong
grounded wall outlet. Now the Apple is completely set up, and
you have only to read on to begin exploring the fascinating
world of personal computing .
5
If your screen display doesn't conform to the description, don't
worry. If you have the Applesoft II FirmHare Card that plugs
into the Apple's main board (Apple Part Number A2B0~~9X), make
sure the switch on the back of the card is in the up position.
Then turn your Apple off and turn it on again. If your screen
display still doesn't look right, or if you don't have Applesoft
on a card, press the key carked RESET in the upper right-hand
corner of the keyboard. The Apple should go "beep" when the
RESET key is released.
If you have a disk drive, turning your Apple on will give the
following results. A few clacking noises will come from it,
followed by a soft whirring sound, and a red light labelled "IN
USE" will come on. The disk drive will whir and whir until it
seems that it will never stop. As a matter of fact, it won't:
until you stop it by pressing the IlIl1D key. Do that now.
The title "APPLE II" disappears, and the prompt and cursor
appear at the bottom left of the screen.
6
Study the keyboard. If you are familiar with standard
typewriters, you .,ill find a few differences between the Apple
keyboard and a typewriter keyboard. First, there are no lower
case letters. You can get only capital letters on the Apple.
This is a ll you need for programming in Applesoft BASIC.
If you press a key which has two symbols on it, the lower symbol
will appear on the screen. If you press the same key while
holding down either of the ~ keys, the upper symbol will
appear on the screen . You will find that the SHIFTed comma and
the SHIFTed period are < and> respectively. You will also find
other symbols on the Apple keyboard that are not on a standard
typewriter. Feel free to try operating any of these keys.
7
The SHIFTed S key gives a right hand square bracket (]). The
B key has the word "BELL" above the "G". But mIlD B does
not put a bell on the screen, it just puts a "G" there. The
mea ning of the word "BELL" on the B key will be explained
later.
When the Hindu mathematicians invented the open circle for the
numeral zero, they didn't use the Roman alphabet. So they chos e
a symbol that, while not conflicting with their alphabet,
looks just like our letter "0". The computer (and any
straight-thinking individual) will want to keep zeros and oh's
distinct. The usual method for doing this, on the Apple and
many other computers, is to put a slash through the zero. Now
you can tell them apart. The keyboard and the TV display both
make the distinction clear. Try them.
(~=
8
the Apple's screen . Press 1m , and then type an " at" sign (@)
by holding down either ~ key and pressing the key marked
"P". Notice that the ESC key, unlike the ~ key, does
not need to be held down while typing another key . You have to
operate three keys to clear the screen . First press 1m and
release it. Then, while holding down ~ ,press P. Instant
gratification: the contents of the screen pro~ptly disappear.
KEYBOARD NOTATION
At this point we will introduce a simple notation.
-
keys, one above the other .
II
The upper key is to be held down while the lower key is pressed.
-
Here's how to clear the screen, using the new notation:
liD
Try it.
9
-- -- -- -- - - - - -- - --
CONTROL,
AND OTHER UNSAVORY CHARACTERS
When yo u pr ess th e a key, th e num er a l 5 a pp ears on th e TV
sc r een. You probably b elieve thi s is tru e , but tr y it a nyway .
If you hold th e mIlD key down while pressing th e a key, a
percent sign ( %) sho uld a pp ea r on th e screen . Does i t ? The
~ key pe rmit s some of th e keys on th e keyboard to have two
dif fe r e nt functions. Several of the ke ys a l so hav e a third
f un c ti on . The third fun c tion is obtaine d by holdin g th e ~
key down Hhile o th e r keys a r e pressed . " CTRL" stands fo r th e
word " ConTRoL . " Instead of putting new c ha r ac t e rs on th e sc r een
wh e n yo u use th e GiD key, th e comput er r es pond s by perfo rmin g
certain ac t io ns . Co ntrol c ha r ac t e rs neve r appear on th e screen .
II
II
It doesn 't go " din g" , but it do es go "b ee p . " Wh en ever the
comp ut e r wi s hes t o call yo ur a tt e ntion to so mething , i t wi ll
so und th e b ee pe r . GiD m is ca lled "BELL " for hist o ri ca l
r easo ns : th e pr esen t keyboard desi gn is base d on th a t of the
Teletype . On th a t venerable machine, GiD m rin gs a r ea l
b ell .
10
'~'SYNTAX ERROR
11
When you play the tape rec o rder into the Apple, it is with the
intent of putting the tape's information into the computer . If
the volume setting is too soft, the Apple will miss some of th e
information, and it will complain by giving an error message.
If the volume setting is t oo loud, the Appl e will also complain .
-
To clear the screen for action type
110
Place the tape marked COLOR DEMOS OFT into your r eco rd er. For
each position of the volume control yo u are going to do th e
following:
3. Type:
B.a ....
When you do this, the cursor will disappear. It may take up to
15 seconds before something happens . There are these
possibilities:
12
In cases band c , ma ke sure yo u wait e d for 15 seconds befo r e
giving up. If ther e is no prompt character or c ur so r, a nd th e
Appl e do es not r es pond to its keyboard, press ED , se t th e
vo lume control a bit hi ghe r and go back to step 1. Once i n a
g r ea t while th e LOAD command may not work properly , a nd th e
cursor will appea r on th e screen imnediat e l y with ou t ~1aiti n g fo r
the tape to b e LOADed . If thi s happ e ns just turn yo ur Apple off
a nd th e n on aga in with th e powe r switch on the r ea r of th e
comput e r , a nd then try LOADing th e t a pe aga in .
2 . St ar t th e tap e playing .
3. Typ e LOAD
13
4. Stop th e tape recorder and rewind the t ape . The informati o n
h as b een transferred, a nd yo u a r e finished with th e t a p e
r eco rd e r for the time being .
A HELPFUL HINT
What is it that the comput e r finds so interesting about th ese
t a p es? Li s t e n to o n e of th e m. It ' s not music to your ea r s .
Yet yo u can re cognize some of th e so unds th e computer listens
for . The in fo rmation starts with a steady tone . Then th e r e is
a short "bl ip " followed b y more of the steady t one . Th e ton e is
a t 1000 cyc l es p er second . This pit c h is just b elow th e C two
oc t aves a b ove middle C. After th e t o n e comes a bur s t of so und
rather reminiscent of a r ainstorm.
14
USING A DISK DRIVE
(Skip this section if you are not using a disk drive.)
One of the features that make the Disk II so easy to use is its
ability to store and retrieve several different groups of
information. The groups of information are filed on the disk
under names called tile names . A program that keeps track of
addresses, for instance, might be called ADDRESSES on the
diskette .
The programs that keep track of files, save and retrieve them,
and do lots of other housekeeping tasks are what make up the
Disk Operating System or DOS. The process of adding the DOS
capabilities to Applesoft (or "to any other language used by your
Apple) is called "booting DOS" or "booting the system".
There are several ways to boot DOS . One way is to simply turn
your Apple off and turn i t on again. The Disk drive's red "IN
USE" light will come on again, and the Disk II will make the
same whirring and clacking noises it made when the Apple was
turned on for the first time . This time the disk drive will
stop whirring on its own . When the whirring stops and the red
light goes off, the title APPLE II will disappear and a message
will come on the screen .
15
When you get this message, you know that DOS is booted. The
right-hand square bracket and the blinking cursor that appear at
the bottom left corner of the screen indicate that the Apple is
in the Applesoft language (or has Applesoft "up", as they say)
and is ready for instructions.
-
number six then type
Itlla
followed by the number of whatever slot the card is plugged into
and then 1ilJi!Ill3 .
The System Master is a very special diskette. It contains
programs you'll need in order to get the most out of this manual
as well as many other useful programs. To see what programs are
on the diskette, use the CATALOG command. Simply type
The first program you need is called COLOR DEMOSOFT. Locate the
name COLOR DEMOSOFT in the catalog. Now type
16
THE MENU
Computerniks call this list of numbered descriptions a "menu."
It works like a menu a t a roadside cafe . If you "Tant scrambled
eggs with hash brown potatoes, toast, jelly and coffee you can
just say, "I'll have a number S." Try selecting one of the
color demonstrations by typing its number (followed by a
~ , of course) . When you are viewing one of the demos,
jus t press the Ii!ii!lmJ to get back to the " menu ."
•
II
This will cause the prompt character and blinking cursor to
appear. The prompt character tells you that it is OK to proceed
with typing information to the computer. That is why it is
called the prompt character: it "prompts " you to type something .
RUN
Use
•
II
17
to stop the computer, and
FWN
0 BLACK 8 BROWN
HAGENTA (a slightly bluish red) 9 ORANGE
2 DARK BLUE 10 GREY
3 PURPLE (a light purple, lavender) 11 PINK
4 DARK GREEN 12 GREEN
5 GREY 13 YELLOW
6 MEDIUH BLUE 14 AQUA
7 LIGHT BLUE 15 WHITE
~
~
These colo r s will be different in Europe and some other parts of
the world .
18
Remember that this color business is quite subjective, and that
you can do whatever you want with the color . The following
instructions will give the picture that we like, using the
standard colors. But it's your eyes you must please. Besides,
the optimun settings will vary with different amounts of room
light.
Now adjust the Color knob . At one extrene, all color is lost
and the picture is black and white. This setting is handy when
you are just showing text on the screen . Adjust the Color
control until the colors are intense but not "blooming" or
spilling into one another. Lastly, adjust the Hue knob until
all the colors agree with their names . Purple, Pink and Yellow
are especially sensitive indicators . Also, make sure that the
three Blues are distinct .
Wh en the TV set's co lors are OK, press the Ii!i1!lil3 key and the
menu \dll reappear. Now try DEMO 2, which shows the color bars
with their co de numbers. Also try the other demonstrations.
You'll neve r believe how talented your TV is until you replace
the local stations with your Apple .
19
"""" •• u ••• **** ** **** ***** ******uu
:• '~1~~18~\60Mm?I~OB~~§gKGSa~N :I
• A WALL OF BRICKS WITH A BALL I
• STRUCK BY YOUR PADDLE I
I I
I I
,,
, YOU CONTROL THE PADDLE ON THE BOARD
, BY TURNING THE APPLE PADDLE ( e)
,,
,
,
,,
,
,
( EFLECT THE BALL> BY HI TT I NG IT
W TH THE PADDLE HELD OFF-CENTER
,,
,
,
·•
, ~~F8RE WE BEG IN, PLEASE TYPE
t tH~ K~~"~A~~~D T~~~T0~~§i
unn •• u"""""""""""""""•
,
:
,,
J. APPLESEED
The Apple will respond by drawing the game board complete with
paddle. The numbers just below the graphics display are the
number of points you can get for hitting bricks from the
appropriate columns. The farther you get through the brick
"wall", the more points you get per brick .
If you type a name that is more than 12 characters long, the
program will truncate the name to a length it is more
comfortable with (12 characters).
RUN
"Which control?" you ask. Try them both and see. Your Apple
will tell you if you have chosen the wrong one.
20
BEGINNING APPLESOFT ..J
If you are in Applesoft, the square bracket prompt character
(]), followed by the blinking cursor, \~ill appear at the left
edge of the screen each time you press ~ . Get into
Applesoft and, if you have a disk drive, boot DOS.
PRINT "HELLO"
and the computer will print the word
HELLO
o
If the final quote is th e last character before the 1l!ii!ImI ,
you don't have to type it: the word "HELLO" will be printed with
or without it. It's a good idea to put the end quote in any\lay,
though. The habit of putting in the final quote will become
important later. This manual will assume that you use the final
quote.
The statement
PRINT "HELLO"
I
22 ---I
much beyo nd 24~ characters, th e computer will start to beep,
then give you a backwa rd slash and let you start over again.
PRINT "150"
The comp uter ob edien tl y print s the number 15~ on the next line,
as expec t ed. But typ e
PRINT 15.0
and the computer again prints the numb er, without any fuss or
error message about the missing quotation marks. In fact, the
Apple will let yo u PRINT any number at all without enclosing it
in quotes.
PRINT 3 + 4
The answe r, 7, appears on th e nex t line. The Apple can do six
different e l ementary a rithmeti c operati ons :
PRINT 7 * 8
a nd have yo ur memory jogged.
23
4. DIVISION. As is customary, use a slash (/). To divide 63 by
7, type
PRINT 63 / 7
Try dividing 3 by 2. The answer is one and one half. The Apple
gives the answer to you in the decimal form: l.S.
One thing we should point out here is that you can do more than
one arithmetic operation in the same instruction. For example,
it is legal to say
PRINT 3 + 5 + 9 + 4
The exact rules governing such usage will be given later, but
you can experiment with it now if you wish.
PRINT 4 ~ 4 * 4 * 4 * 4
you can substitute the shorthand
PRINT 4 A 5
..a
The upward pointing arrow is typed:
24
APPLESOFT'S FORMAT FOR NUMBERS
Type
PRINT 45 . 34~
45 . 34
and didn't PRINT the trailing zero. The Apple does not PRINT
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.
NO~l type
Surprise! The last two digits are lost, and the number left
behind is the closest approximation the computer can think of.
This process is called "rounding". Try typing
Your computer did not round the number, but PRINTed it just the
way you typed it. }~dness 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. The computer does the best it can,
but it only has nine digits to work with.
123456789~
1. 23456789E+1)9
25
The numbers 123456789~ and 1.23456789E~9 have the same value.
Really. The number PRINTed by your computer is in "scientific
notation". If you need numbers like this you probably know how
to read the~. The Applesoft BASIC Programming Reference Manual
has more information if you are c urious about this strange
notation.
Try some more numbers. How many digits can a number without a
decimal point have before the Apple changes it to s c ientific
notation? If scientific notation seems complicated, don't
worry. You probably won't be wanting to use numbers that
require it for some time ye t. Remember that any numb er will be
PRINTed just the way you type i t if the number is surrounded by
quotes. However, the Apple can't use numbers in quotes for
arithmetic operations. For mor e information on scientific
notation and other types of number formatting used by the Appl e ,
refer to the Applesoft II BASIC Programming Reference Manual.
PRINT 4 + 5
PRINT 4 + 5 + 346
which would have given a different answer entirely. Since the
computer can't tell when you have finished typing an
instruction, you must tell the computer. You do this by
pressing the Ii!ii!lmI key. Since you always have to do this
after typing an instruction, we have (as you know) stopped
mentioning mmmI after every instruction. Pressing IliJm
after each instruction should be a habit by now, if yo u have
been doing all the examples.
We really hope you have been trying all the examples. Learning
to program is very much like learning to ride a bicycle, play
the piano, or throw a baseball. You can read all the books in
the world on the subject of bicycle riding, and be a great
"paper expert." But all this book-learning is of little help
when you actually get on a bicycle for the first time. Once you
26
have learned to ride, through experience (which can be a bit
painful), you can go almost a nywhere . The same is true of
programming . You can read this manual and think you understand
it . But you won't be able to program. Only if you do each
example, as it is given, will you learn to program . That's the
truth .
PRINT CDt"iPUTER"
PRINT "COMPUTER"
COMPUTER
PRINT "CDt1FUTER"
27
Sinc e you haven't pressed ~ , nothing has happen e d yet.
As shown in the photograph, the cursor is sitting to the right
of the last quote. (Sorry, we can't make the photo blink)
To c hange
COt1FUTER
into
COMPUTER
we can use the IC:I . Notice that each time you press this key,
the blinking cursor moves back (to the left) one space.
"Backspace" is also a verb. So backspace the cursor to the F.
Type a P. As you see, the P replaces the F. Now press
~ You got
COMP
••••••
mD
Tr y it .
It works! There is, however, an easier way. When you press the
III key, the cursor moves to the right. As the cursor moves to
the right across a character, it has the same effect as if that
character had been retyped. We call the CI key the "retype"
key. Again type
PRINT "COMFUTER"
28
then ba cks pace to the F and change it to P. To complete the
co rre c tion simply press the retype key five times, and then
press ~ Does it all work? The use of the backspace and
retype keys will save you a lot of time. Make a point of using
them a nunber of times on your own "mistakes," so that these
keys become familiar.
29
To use the screen colorfully, type the following instruction:
GR
TEXT
When you type this com~and the screen will suddenly change to a
lot of "at" signs (@). This is normal. Try typing the TEXT
ins truction, and then getti ng back to graphics by typing th e GR
instruction .
Before you can place a dot of color on the screen, you ~ust tell
the co~puter which color you want. Ther e are sixteen colors
available . You have seen them before: they are numbered from 0
to 15, as shown in COLOR DEMOSOFT 2.
Suppose you want to put a green dot somewhere. You must first
type the GR command, and then type
COLOR = 12
This means that any dot (or spot or brick) of color that you
place will be green. In fact, until otherwise instructed,
everything the computer puts on the screen will be green.
Except, of course, for the small area reserved at the botto~ of
the screen for your instruc tions. To put a spot of color in the
upper left-hand corner of the screen (leftmost or zeroth colu~n,
top or zeroth brick), you type
PLOT ¢'¢
30
To put a s po t o f th e s a me co l o r in th e upp e r r ig ht-h a nd co rn e r,
yo u must spec ify co lu~n 39, bric k 0. So t y p e
PLOT 39, ¢
No ti ce th a t yo u always giv e th e co lumn fi r s t. Now put an o r a n ge
bric k a t th e l owe r l e ft - ha nd co rn e r . Fir s t c ha n ge th e co l o r.
Re me mb e r --yo u s h o uld r ea ll y b e d o in g th ese exe r c i ses , n o t just
th i nkin g a bout th e m. So , put o ut yo ur fin ger s a nd t y p e
COLOR '" 9
PLOT ¢,39
FL.AT
or
PLOP
31
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 numbers you can use in a
PLOT statement are 39 for the first coordinate, and 47 for the
second. Use of numbers over 39 for the second coordinate, as in
a statement such as
PLOT 2~,45
will just give you peculiar characters in the text area at the
bottom of the screen.
message.
DRAWING LINES
Suppose you want to draw a light blue horizontal line from
column 5 to column 9 at the level of brick 14. You could type
COLOR = 7
PLOT 5, 14
PLOT 6, 14
PLOT 7,14
PLOT 8, 14
PLOT 9, 14
32
Notice that the joints between adjacent bricks do not show, and
they form a continuous line. However, there is an easier way to
do horizontal lines. There had better be. Suppose you want to
draw a dark green horizontal line across the middle of the
screen. Using the long way, it would take forty typed
statements:
COLOR = 4
PLOT ¢,2¢
PLOT 1,2¢
PLOT 2,2¢
PLOT 39,2¢
COLOR = 4
HLIN ¢,39 AT 2¢
Notice that when you put a colored dot or line at the same
location as an existing dot or line, the new color takes over,
and the old color disappears. To clear the screen of all
graphics at once, use the GR command.
33
COLOR = 9
VLIN 12,33 AT 7
PR INT PDL< 0)
and a number should appear. Move the control a bit. Now type
PR INT PDL< 0)
PR INT PDL< 0)
If the number never changes, you've got the wrong game control.
What are the highest and lowest numbers you can get? What is
the smallest change you can make?
34
PDL is a function. A function, in Applesoft, is something
that takes one or more nUMbers and then performs some operation
on them to yield a single value. The numbers that the function
uses are called its arguments and are always put in
parentheses after the function name. PDL is a function that has
one argument. The number the function finds is said to be
returned to the program.
PIGEONHOLES
AND MORE CALCULATOR ABILITIES
On many siMple calculators you can save a number for later
referen c e or use. To do this, you put the number into a special
place in the calculator --a place we shall call, for now, a
pigeonhole. Usually this is done by pressing a key marked " H"
for " Hemory. " On the Apple you can do the same thing. For
instance, to save the value 77, you type
M = 77
PRINT t1
the computer will print the value of H. Try typing the two
statements .
Now type
M = 324
Type
PRINT "t1"
t1
and
.. t1"
35
It is just like the difference between these two statements in
English:
PRINT "t1"
PRINT M
we mean to print what the letter stands for. You would never
confuse the name of someone you love with the actual person that
name stands for .
M = 4 + 5
You can see that the answer has been stored by PRINTing the
value of M.
PRINT t1 + :2
36
SUM =
56 + 34 + 1523 + 8
GAMEPOINTS = 45
PLAYER2 = 9
Some names are not allowed because they include a word that has
a special meaning to the Apple. These are known as reserved
words. One of these words is "COLOR". Thus a variable's name
must not have the word "COLOR" in it. Try typing
THISCOLOR 6
or
COLORFUL =9
All you get for your pains is an error message. Whenever a
variable name gives you the ?SYNTAX ERROR message, it means that
you have unwittingly included a reserved word in the name.
Don't worry. Just choose another name.
When you are choosing names, make them reflect the use to which
they are being put. This will make them easier to remember.
Try typing
BIRD = 11
and then
PRINT BIRD
PR INT BITE
What happens? Try
PRINT BILL
and
PRINT BILLOW
37
If you study the nanes you will notice that they all begin with
"BI". Applesoft uses only the first two characters of each
variable name to distinguish it from other variable names. So
the name
BIRD
refers to the same variable as
BITE
and
BILLOW
and so on.
Here is a useful trick. Let's say that you had some value in
the variable PRICE, and you wanted to increase this value by 5.
One way you could do this ~lOuld be to PRINT the value of PRICE,
then add 5 to that value, and finally store the resulting value
back in PRICE. For instance:
PRICE = 28
PRINT PRICE
PRINT 28 + 5
PRICE = 33
But see how much easier it is to type
PRICE 28
PRICE PRICE + 5
Try the statements on the next page in order:
PRICE -- c.."
PRINT PRICE
PRICE = PRICE + 3
PRINT PRICE
PRICE - PRICE * 6
PRINT PRICE
PRICE = PRICE ; 10
PRINT PRICE
At the end of this sequence of statenents, you will probably
have the value 3. Is this correct? Is this what you expected?
Try this sequence:
38
APPLES = 55
BANANAS = 11
QUOTIENT = APPLES / BANANAS
PRINT QUOTIENT
Fi r st think what a n swer you expect, then see if you are right.
If you are no t , find out why. Lastly, try these statements:
HELLO = 128
PRINT "HELLO"
HELLO = HELLO / 2
PRINT "HELLO"
HELLO = HELLO / 2
PRINT HELLO
What did you expect? What did you get?
PRINT 4 + 8 I 2
you can't tell whether the answer should be 6 or 8, until you
know in which order (or precedence) to carry out the arithmetic .
If you add the 4 to the 8, you get 12 . If you then divide 12 by
2, you get 6 . That ' s one possible answer . However, if you add
4 to eight - divided-by-two, you have 4 plus 4, or 8 . This is
another possible answer. Eight is the answer your Apple will
give. Here's how the Apple chooses the order in which to do
ar ithmetic:
-3 + 2
the Apple will first apply the minus sign to its appropriate
number or variable . Thus -3 + 2 evaluates to - 1. If the Apple
did the addition first, - 3 + 2 would evaluate to - 5. But it
doesn't . Another example is
39
BRIAN = 6
PRINT -BRIAN + 10
4 + 3 2
2 3 2
4. Lastly, all additions and subtrac ti ons are done, from left
t o right. Additi on (+) and subtraction (-) have equal
precedence.
40
Unless you have a lot of experience with the way computers
evaluate expressions, you should actually do these examples .
Don't do them all at once and then check \~ith the computer. Do
an example by hand and then do it on the computer. Then go on
to the next one, and so on .
3 + 2
4 + 6 - 2 + 1
8 4
4
* ,.,
eo + 1
6 / 4 + 1
5 4 I 2
4 2
I eo
,.,
6 -2 + 6 ; 3 + 8
*
4 + -2
2 2 3 +
2
2
* 2
2 +
* 3 + 3
*
2 * 2 *
*
+ 3
..,
8 ; 2 I / ... 1
8 2 I 2 + 3 2 2 1
*
20 I 2 5
* *
*
No answers are given in this book . Your Apple will give you the
correct answers.
12 I 4 + 2
you will get 12- divided - by-four, with two added on . But this is
not what you wanted . To accomplish what you wanted in the first
place, you can write
12 I (4 + 2)
12 I (3 + (1 + 2) -'. 2)
41
In this case, doing the innermost parentheses, you first add 1 +
2. Now the expression is, effectively,
12 I (3 + 3 , .. 2)
44 I (2 + 2)
(44 I 2) + 2
3 + (-2 * 2)
(3 + -2) * 2
100 I (2013 I (1 * (9 - 5) i )
32 I (1 + (7 I 3) + (5 / 4i )
42
44 Deferred execution: NEW, LIST, RUN and HOME
48 Elementary editing: DEL
5~ Elementary aerobatics: GOTO loops
5~ Some more things that make life easier: more editing tips
52 The moving cursor: editing with the ESC key
53 A word about learning Applesoft BASIC
54 An accident about to happen
55 The truth: arithmetic and logical assertions
59 Order or precedence for operations
59 The IF statement
6Q Saving programs on diskette: SAVE, CATALOG, RUN and LOAD
61 Saving programs with a cassette recorder: SAVE
62 More graphics programs: REM
64 FOR/NEXT loops
67 A wrong program
67 A last example of nested loops
68 Getting flashy: INVERSE, FLASH and·NORMAL
68 PRINTs charming: comma, semi-colon, TAB, HTAB and VTAB
43
DEFERRED EXECUTION
No, this section is not on last minute reprieves for condemned
criminals. Up to now, when you typed
PRINT 3 + 4
NEW
1010 PRINT :3 + 4
LIST
100 PRINT 3 + 4
RUN
7
appears on the screen .
44
Typing Rlll caused your stored statement to be executed, but the
computer has not forgotten the statement . You can RUN the same
statement as many times as you like. Try it .
What's more, the computer does not forget the stored statemeat
when you clear the screen. Here's a new way to clear the
screen:
HOt1E
-
The HOME command has the same effect as
1111
that you learned earlier, but it can be used in deferred
execution as well as immediate execution. To try this out type
100 HtJt1E
RUN
and then
LIST
and see what happens. Typing NEW has caused the stored
statement to be lost permanently . Type
RUN
PRINT It HELLO 41
,,: PRINT 4 5
- PR aJT 67 12
45
Nothing much has happened so far. But now type
RW
NEW
1 PRINT ilpll
0 PRINT It A~'
~ PRINT "E"
2 PRINT ilL "
No t ice th at zero is a n a ll owed line n umb e r. Th e highest line
number th a t you ca n use i s 63999. Now Rill, th ese instructions .
The results sho uld look like thi s :
P
L
E
LIST
Notice that you d o not have t o LIST a set of instructions b efo r e
you RUN them . It is, h owever, a goo d idea t o do so .
46
A set of instructions that is executed when yo u type RUN is
called a prograQ.
A
P
P
L
E
but, it seems, a PRINT statement was left out . How can you add
it in? Only by retyping the statements with line numbers 2 and
3 as statements 3 and 4, and adding a new line number 2 . To
make the corrections type this:
4 PR INT "E"
NEW
to eliminate that program and put in this one :
When you RUN this program it doesn't quite print the word " CAT "
vertically. But now you can go back and type
LIST and RUN this program. From now on this book will start all
programs at a reasonably high line number and leave plenty of
room between successive line numbers so th e re \ViII be adequate
room for inserting statements .
47
ELEMENTARY EDITING
Earlier, you discovered that the instruction
PRINT PDU¢i
NEW
and type
Now, each time you type RUN, this short program is executed and
you can see the position of the game control.
RIJt4
NEW
200 P = PDL l ¢ )
210 PRINT P
220 PR INT "1'10:,110 THE GAME CONTROL"
230 PRINT "TO A NEW POSITION"
200 P = PDL(1)
48
\fuen you t ype a statemen t ~,ith the same l ine number as one that
already exis ts in a program, the n ew line r eplaces the old one .
LIST the program to see how it has changed. RUN it a few times
to see wha t happens . Move th e other game control between RUNs .
Does this program respond to both controls? Hark a number one
on the con tr ol to which this program responds.
DEL 230/2:30
The advan t ages of the DELete are not apparent until ~~e reveal t o
you that whole sections of programs can be erased with
i nstru c tions like
As you have seen, there are several commands that help you deal
with whole programs . They are
NEW
which erases programs,
LIST
RUN
which execute s programs, beginning with the statement having th e
lowest line number. It is also possible to s t a rt executi on
elsewhere , and t o LIST only part of a program. These
capa bilities will b e covered later.
49
ELEMENTARY AEROBATICS
At this point you are beginning to fly, so this section will
discuss loops.
The best way to see how the PDL fun c tion works - -and to
und erstand program " loops"--i s to use a statement we haven ' t
discussed, until now . It ' s v e ry simple. Type the following
lines (after typing NEW, to erase any old programs th a t might b e
around) :
•
II
The GIilJ B command If:ts yo u know wher e th e program execu ti on
was s t opped by printing
50
or whatever line number the program was stopped at . (Try it) .
By the way, this is an exception to the rule about pressing
~ after every command. Pressing ~ is usually not
necessary when a program is stopped with l!ii!!I m·You can
also use the limB key to stop programs if you like, but, with
limB you will not get the message that tells you the line
number at which the program was stopped .
CfJNT
which stands for " CONTinue ." Try it, and then try this program:
NEW
100 X = PDL(ill:.
110 PRINT "GAt1E CONTROL ZERO IS "
i20 PRINT ~
1 30 '{ = P DL \ 1 :.
140 PRINT "AND CONTROL ONE IS"
150 PRHH 'y
Earlier we said that when you type RUN, the program starts
executing at the lm~est numbered line. True. However, if you
want t o start RUNning at some other line, such as line 130, you
simply type
RUN 130
LIST 130
51
THE MOVING CURSOR
HAVING WRIT
CAN ERASE OR COpy
ANY OF IT
When the backspace and r e typ e keys a re pressed, they move the
c ursor. But th ey a lso ei th er erase or r e t ype characters, as you
learned in Chapter 2 . It is possibl e to mov e th e cu r so r without
affecting anything at all (ex cept the cursor positi on) . You do
this by using pure cursor moves.
Five keys are used in exec uting pur e cursor moves . They are :
E D , II , 13 , and m·He r e ' s how to us e th em .
First you put the Apple in edit mode by pr ess ing and r eleasi n g
the 1m key, then use a to move the cursor up, D to move
it left, 13 to move it r~ght, and m to mov e it down. To !!love
the cursor repeatedly, hold down one of the cursor dir ec ti on
keys ( a , II , ct ,
or m) an d th en hold down the _ key
at the same time . The c ursor will zi p a long while both keys a r e
held down. If the cursor re ac hes the top of the screen, it will
stop. If the cursor reaches the bottom of th e screen, it will
stop, and the screen displa y will !!love upwa rds, o n e line at a
time . If it reaches the right edge of th e screen, th e c ur so r
will disappear and "wrap around" to the b eg inn ing of th e n ex t
line. Practice moving the c ursor around the screen wi th th ese
five keys .
When you get tired of pure c ursor moves just pr ess the s p ace
bar, and you will find yourself in normal typing mod e .
52
These pure cursor moves do have an application , so they are not
so pure after all . For example , type:
The backspace key only works on the line you are currently
typing . If you type a program line and th en execute a pure
cursor move before you press ~ ,the program line you just
typed, not the characters the backspace key is going over, will
be affected by the backspace key moves. The retype key,
however, does retype the characters it actually goes over.
53
PRINT "HELLO"
11~
••
Using mIllI D places a ba cks lash at th e e nd of th e lin e yo u
are typing, and it will b e as if you nev e r typed it a t a ll .
54
THE TRUTH
The Apple can d istinguish b e tween wh a t is tru e a nd Hh a t is
false . Since this is more th an ~ os t of u s can d o , a few words
of ex planation are in orde r. The symb o l > means " g r ea t e r than" .
The asse rt ion 6 > 2 (which is r ea d " six is g r ea t e r than two ")
is certainl y true . Th e Apple u ses th e numb er 1 t o indicate
truth .
If yo u type
Pj:;'INT 6 > 2
the conputer Hill repl y with a one . The asse rti on 55 > 78 is
false . The Apple u ses the number 0 to indicate false h ood . If
yo u t ype
PRINT 55 78
The symb o l < means "l ess th a n", a nd yo u ca n make s tat e ment s
uSing it as well . Here is th e full se t of symb o l s used in
making asser t ions:
> g r ea t e r th a n
< less than
eq u a l t o
>; g r ea t e r th an or e qual to
<; less th a n or e qu a l t o
<> no t e qu a l t o
5 ,-,, 5
, --'
b 2
8 8
8 .- = 8
'75:34 = 4:359
5 < 8
45 >= -4
--8 -: -7
-2 >= -5
9 -9
55
Ass e rtions can in c lud e variabl es a nd expressions as well as
numbers. For example
You hav e seen that the Apple ca n tell truth from falsehood in
simple assertio ns about nu~bers . However, an assertions such as
ABLE > BAKER may be tru e or false , depending on th e value of th e
two variabl es , ABLE and BAKER . If
ABLE = 5
and
BAKER = 9
th e n th e assertion
ABLE> BAKER
is false . But if
ABLE = - 8
and BAKER = -15
th en th e asser ti on
ABLE > BAKER
is tru e .
PRINT 3 + 14 2)
T 4 <> ·3
gives T the value 1, sin ce 4 do es not equal thr ee, and thus th e
assertion 4 <> 3 has the value 1 . The s tatement
HOT = 67 = 19
56
As we have seen, the Apple us es 1 t o ~ean tru e , an d 0 t o mean
false . If some thin g is no t tru e , it is false . If so me thin g is
not false , it is true . This may not always b e th e case in r ea l
lif e , but it is always th e case with computers . Try th is o n the
Apple:
Pi~ an t~OT 1
PRINT NOT ¢
The computer agrees: no t tru e is false and no t false is true .
Of co urs e , you ca n use exp r essio ns in s t ea d of o n es a nd zeros .
For exa mpl e
Th e sentence
TRIANGLES HAVE THREE SI DES .
is tru e . And th e se nt e n ce
THIS BOOK IS IN ENGLISH .
i s tru e . Consider th e se nt e n ce
TRIANGLES HAVE THR EE S IDES AND THIS BOOK IS IN ENGL ISH .
I s thi s sentence tru e o r false? It is tru e . Consider th e
sentence
TRIANGLES HAVE EIGHT SIDES AND THIS BOOK IS IN ENGLISH .
Thi s se nt e n ce , as a whol e , i s f a lse . Lastly, co nsi d er the
sentence
TRIANGLES HAVE EIGHT SIDES AND THIS BOOK IS IN SHAHILI.
This sen t e n ce is a lso false . In general, when yo u co ~bin e two
se nt e n ces , o r assertio n s , by joining th em with th e wo rd AND, you
find that
PRINT AND 1
PRINT i AND ¢
PRINT ¢ A hiD i
PRINT ¢ AND ¢
PRINT ("0
""~
",
J" 2) AND ¢
PRINT (NOT ¢) AND (4 5)
57
Is this sentence true or false?
A TRIANGLE HAS THREE SIDES OR THIS BOOK IS IN LATIN .
It's true. A triangle does have three sides, even if this book
isn ' t in Latin, so the sentence as a whole is true. Quod erat
demonstrandum . In general, when you combine two sentences by
joining them \Jith the word OR, you find that
PRINT 1 DR 1
PRINT 1 OR ¢
PRINT 0 OR
PRINT 0 OR 0
PRINT (4 ."'
--'- 5) OR (4 = 5)
PRINT 1 DR (10 AND 1i
PRINT ( \' ' "~) -
-,:. 4 ; OR (54 ( 337) AND (NOT 0)
AND, OR, and NOT will become very useful in the next section.
PRINT 23 OR iJ
and this:
While the following box gives the precedence rules for AND, OR,
and NOT, we strongly recommend that you use parentheses to make
your statements clear.
58
ORDER OR PRECEDENCE
FOR OPERATIONS USED
SO FAR IN THIS TEXT:
1-
2. NOT - (f or n ega tiv e values)
3.
4. * /
5. +
6. > < >= <= <>
7. AND
8. OR
THE IF STATEMENT
Supp ose yo u wa nt to p rint o ut i nt egers from 1 thr oug h 10, o ne
numb e r t o a lin e . An o b vio us way t o d o thi s is
NEW
210 PRINT
:::2:1: PRHH .-,
230
'"
PRINT :3
a nd so o n. But thi s would r eq uir e 10 statements, and i f yo u
wanted to print th e integers fr oQ 1 through 200 thi s wa y , it
wo uld r e quir e 200 s t a t ement s . Using ~lh a t yo u h ave already
lea rne d, yo u can PR I NT integers from 1 on up in just four
s t a t emen ts by u sing a l oop :
22,0 [., = 1
d]0 PRINT ~'J
22;; N =N + i
230 GOTD 210
There is a ~lay t o co ntr o l h OI. long a loop runs . Hhat yo u want
is a sta t ement th a t d oes a GOTO if N is, for exampl e , less than
11, but d oesn 't do th e GOTO if N is g r ea t e r th a n 11 . The a nswer
to yo ur wishes is th e If sta t ement . If a conditi on is me t, the
compu t er will skip th e GOTO in s tru c ti on a nd exec ut e th e
ins tru c tion o n the next l ine . If th e r e is no n ext lin e, the
program will e nd .
200 N =
210 PRINT N
220 N = t~ +
230 IF N ( 10 THEN GoTo 210
59
In gene r al, the IF statement wo rks like this :
NEW
40e. GR
410 ROW = 1
42¢ CDLOR= RDW
43¢ HUN 0, :39 AT ROW
44(0 ROW = ROW .,. 1
45(0 IF ROW < 16 THEN GOTO 420
SAVE
SAVE STRIPES
a nd the pr og ram wou ld b e saved o n th e d isket t e under th e n ame
STRIPES . Once th e p r ogram i s SAVEd , t ype
CATALOG
foll owe d by ~ to see th e n a me o f yo ur pr og r am listed with
th e o th e r pr ograms on th e di ske tt e . You would th e n b e a bl e t o
RUN th e program c alled STRIPES fro m th a t diske tt e a n y tim e yo u
wish e d by typin g
60
RUtJ STRIPES
LUl-liJ STRIPES
If you c h a n ge th e program and then .lish to RUN the new version
which is in th e Apple's memory but not SAVEd on the diskette ,
r ememb e r to t ype o n ly
If yo u forge t a nd t ype
RUi.i STRIPES
61
When you press ~ ,the blinking curso r will disappear.
Af t er 1~ o r 15 seconds , the compu t e r will g iv e a "b eep " t o let
you know the r ecordi n g h as begun . Another "b eep " wi ll sound
when the recording is comple t e d, and th e cursor will reappear .
Push th e STOP l ever on th e r ecorder , rewind th ·= tape to the
beginning, a nd yo u are ready to go back to programming. You r
program in the compu t er has n o t been affec t ed in any way by
SAVEi n g it.
t·Ji::W
1q0 GR
;::p0 C C.1UJR = q
.:.: 10 Pi_en 0, i/:
~::;''1: F:JjT 0· 3':;
.~ ~.30 ;: - L...CiT :?c' . ::;c:;.
;~;.f0 i::L..CIT :3? . 'I'
L :'::_~. ;
;:0'Z GR
.;:: -, 'p :: C:L~:JR = ::;
;:-;1' CC1UJI1N= 0
230 \:L.IN 0· :3':'\ AT COLU! 1r'~
2 4 0 COLUM~ COL0MN + 1 =
250 IF COLUMN < 40 THEN GOTD 230
Here's a b l ow -b y -blm~ explana t ion of wha t happens \~hen yo u Rm<
this program. Line 2~~ se t s GRaphi cs mode. The color is chose n
62
in line 210 . The program is to start in the screen's column 0
and work its way over to column 39. Line 220 makes sure the
program starts in column 0. At line 230, a vertical line is
drawn in column 0. Now that column 0 is filled with the desired
color, line 240 increments the column by one. The value of
COLUMN is now 1. Line 250 checks to see if the new value of
COLlJHN is less than 40. If i t is less than 40, the program goes
back to line 230 to draw a new vertical line in , that column .
HO~lever, when the value of COLUMN reaches 40 (on the Apple
screen, the rightmost column is column 39, the program does not
go back to line 230, but "drops through" (as we say) and stops
executing because it has reached the end of the program.
To eliminate the need to type Rm~ each time you \~ish to fill the
screen with color, type
26(/; GO TO 21~
Observe \~hat happens . When will this program stop? LIST the
program and make sure you understand what it does before going
further in this book .
When you are finished playing with the solid color program,
clear the computer and try the following program . It uses a new
and very important instruction: the REM statement . "REM" stands
for "REMark" . This statement allows you to put commentary in a
program . The computer ignores any REM statements; they are
stric tly for the benefit of humans. See how easy it is to
follow this program where REMs are used liberally .
63
s imi l a rl y . Th e div isi on by seven is necess ar y s inc e th e PDL
f un c ti on gi ves v a lues b e twe e n 0 a nd 255, wh e r ea s th e sc r ee n can
onl y accept c olumn and row v a lues from 0 to 39 . Dividing by
s e v e n giv es yo u v a lues from (0 / 7) = 0 t o ( 255 / 7) =
36 . 4285 71 5 . Th e n GRa phi cs mod e a ut omati call y r o und s coo rdin a t e
va lue s down to the ne a r e st int eger .,hose va lue is l es s th a n o r
e qua l t o th e g i ven v alue . In o th e r wo rd s , th e X and Y
coo rdin a t es a r e round e d down t o i nt ege r s f rom 0 to 36 so th a t
th e X a nd Y c oordinat es c an b e PLOTt e d. This me thod does no t
utilize th e full hei g ht o r width of th e s c reen . To ge t th e full
wi dth of th e sc r een, in s t ea d of
2710 X = X I 7
FOR/NEXT LOOPS
Loo ps , wh e th e r exec ut e d by a irpl a nes or c omput e r pro g r ams , have
a t op a nd a bo tt om. I n th e prog r am
NEW
100 NUMBER =0
110 PRINT NUMBER
120 NUMBER = NUMBER + 1
130 IF NUMBER (= 12 THEN GOTO 110
64
Use
3000 GR
3010 FDF t·, = OZ· TG 1 5
3220 COL!JR= hoi
3030 HLIN 0· 3~ AT N
30J.0 t'~'E)!-T rJ
65
and then LIST the program to check the results.
To PRINT just the even numbers from 0 to 12, you could use the
program
1M THING = 0
110 PRINT THING
120 THING = THING + 2
130 IF THING <= 12 THEN GOTO 110
The secret is in line 120, where 2 is added to THING. We say
that the loop steps by two. To step by two in a FOR loop, you
would type
RUN 2iZIO
You should play with the FOR statemen t for a while, if you wish
to learn t o use it. A number of the example programs from this
point on will use the FOR s t atement .
~JEW
300 GR
3110 FOR HUE = 1 TO 15- - - - . ,
32<tl COLOR= HUE
330 FOR ROW = 0 TO 39- - - . .
3410 HLIN 0.39 AT ROW
350 NEXT ROW- - - - - - - -......
369 COLOR= HUE - 1
370 FOR COLUMN = 0 TO 3
380 VLIN 10.39 AT COLUMN
390 NEXT COLUt1N - - - - - - - '
4010 NE XT HUE----------~
66
This program is an example of two-level nesting. Think about it
and RUN this program before going on to the next. Remember,
when writing programs using FOR statements, each FOR must have
a matching NEXT.
A WRONG PROGRAM
NEW
500 FOR N = 10 TO 20
510 PRINT N
520 FOR J 30 TO 40
530 PRINT .J
540 NEXT N
550 NEXT J
This program won't work. Its loops are crossed, which not only
gives an error message, but doesn't make any sense. Whenever
you find yourself writing crossed loops, your thinking has
gotten tangled. If you are sure you know what you are doing,
and still want to cross loops, use loops made with IF
statements. You can cross those all you want, for what good it
will do you.
67
GETTING FLASHY
If you're bored with plain old white print on a black
background, you will especially enjoy this section. Type
INVERSE
and take a look at the Applesoft prompt and cursor . The prompt
character should be black on a white background. Now type a
simple program such as
NEW
1~0 PR INT "BLACK AND WHITE IN COLOR"
FLASH
NORMAL
PRINTS CHARMING
As an experiment, type this program and see what it does when
you RUN it.
~~EW
1~~ PRINT "HELLO"
11~ GO TO 10~
68
and RUN the program again . As you can see, this PRINTs the word
in columns . Now substitute a semicolon (;) for the comma (,)
and RUN the program again . This time the output is packed.
This means that there are no spaces between what you told the
computer to PRINT. It prints HELLO after HELLO, until the
screen is quickly filled.
90 V = 99
100 PRINT V
100 PRINT V,
and observe that the comma and semicolon can also be used with
numerical values. The ability to place numbers one after the
other without intervening spaces is sometimes quite useful.
Commas and semicolons can be used within a PRINT statement .
Clear the old program with NEW, and type
100 STRIVES = 2
11~' BALLS = 3
120 PRINT STRI~ES,BALLS
69
In this v e rsion, a b lank is put between th e numb e rs of strikes
and balls . Perhaps the prettiest wa y of doing this ( a re you
trying a ll of these on yo ur Apple ? ) is
NEW
200 FOR N = 1 TO 24
210 PRINT TAB!Ni"X"
220 NE.<T N
You can tab horizontally <lith HTAB if you don't want to use a
PRINT s t a t ement . HTAB works like TAB exce pt th a t it is no t used
with in a PRINT statement . Al so , HTAB can ca us e printin g t o
b egi n ei th e r to the l e ft or t o th e ri ght of th e c urr ent printing
position . Th e leftmost c har ac t er on a' line is in position 1,
whil e th e ri ghtmos t character is in position 4~. On th e nex t
page is a short pr og ram that demonstrat es th e use of HTAB a nd
VTAB:
70
NEW
59 0 HOi"lE
600 FOR X TO 24
d0 i="OR 'i TO:<
,:0,20 HTAE:X.
630 './TAB '{
,::A~ PI'< un "APPLE"
650 NDT X
,~60 NEXT 'y"
t!70 GO TO 600
Before you RUN this program, try (it ain't easy!) to figure out
what it will do. It's both surprising and pretty.
TAB works for immediate execution mode, but you can only use
VTAB and HTAB in programs. While TAB, HTAB and VTAB act
somewhat like the co- ordinates in PLOT, there are some
differences. The 4~ columns for the TAB instruction are
numbered from 1 to 4~, as they would be on a typewriter, while
the first co - ordinate of a PLOT instruction can run from 0 to
39, which is more convenient for programming graphics . Since
characters a r e taller than the "bricks" we build graphics with,
there is room for only 24 lines of printing on the screen .
Therefore VTAB's limits are 1 and 24 . A zero or a number that
is too large or too small for TAB, VTAB or HTAB will give you an
The largest value for VTAB is 24, but the largest value for TAB
or HTAB is 255 . Both TAB and HTAB will tab past the length of
the screen line and "wr ap around" to the next line. To see this
in ac tion, type
NEW
300 FOR ~ = 1 TO 255
310 PRINT TABIV) V
320 NDT i';
and adding
330 NEXT~,
What happens to the program when you replace HTAB with VTAB?
71
72
TALKING TO A PROGRAM ON THE RUN
Here is a program that makes a dot of color move across the
screen, bouncing off the right and left sides.
NEW
400 REM CHOOSE BALL COLOR
42e1 BALL = 9
440 REM SET GRAPHICS MODE
460 GR
480 REM STARTING POSITION
SeIeI XOLD = 20
520 REM MOVE THE BALL BACK AND FORTH
S40 Xr10VE = 1
56\0 REM NEW X POSITION
580 XNOW = XOLD + XMOVE
600 REM IS BALL ON THE SCREEN ?
620 IF (XNOW) = 01 AND rXNOW ~ 40) THEN GOTO 720
64e1 REM CHANGE XMOVE DIRECTION
660 XMOVE - 1 * XMOVE
680 GOTO 580
700 REM PLOT THE NEW BALL
720 COLOR= BALL
740 PLOT mow, 20
760 REM ERASE OLD BALL
780 COLOR= 0
80e1 PLOT XOLD,20
820 REM SAVE NEW BALL
84e1 XOLD = XNOI~
860 REr1 r'iO'..iE AGA I N
880 GOTO 580'
You should always give some thought to the naming of variabl es .
It may seem that XNEW would be a more convenient name than XNOW
until you remember that NEW has a special meaning in Applesoft
and is a reserved word . The reason that the variable ~10VE was
called "~lOVE " will be evident if you change its value. Try
~OVE = 2 for example. If you set ~OVE too high, th e ball will
appear to jump wildly across the screen, with no tra ce b e tween
positions.
74
When you LIST this program it doesn't all fit on the screen at
once, and the program lines scroll upward too quickly to be read
easily. One way to see all the program lines is to LIST the
program in portions. For example, you could type
LIST 400,680
and only the lines with numbers greater than 4~~ and less than
68~ would be printed. Then you could LIST the rest of the
program. You can also use
II
II
to interrupt the program listing. Try LISTing the progra m and
then quickly typing
II
II
before the program lines scroll up beyond the top of th~ screen.
To start the listing again, type BiiII 0 again. BiiII II
can also be used to stop the listing. However, BiiII Ii \~ill
abort the listing so that it cannot be continued from where it
left off.
75
You may also incorporate a message into the INPUT statement:
~' REENTER
.-:;.
will appear on the screen, and the program will stop. For the
most part, the user will not know how to restart the
computer --and shouldn't have to. Therefore you should make the
program check that all numbers typed by the user are correct .
These lines will do it:
76
Each time you use an INPUT statement, your program must check
that what the user types is within certain limits, so that the
program won't "blow up" or 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 clear English
sentences and careful checking of what the us er t ypes are always
required .
By the way, you can INPUT several values with one INPUT
statement . The statement
INPUT X, '{, Z
would display a question mark as usual, and then wait for three
numbers to be t yped in. The first number would be stored in the
variable named X, the second number in the variable named Y, and
the third in the variable named Z. The three numbers must be
separated by IlIii!lll3 s or commas, and the last number must be
followed by a cm:m
SAVE your best version of the bouncing ball program, just in
case . Then, if you have not done so already, try to ad d
vertical motion to it. Use the new variables Yl, Y2 and YMOVE.
A solution is given on the next page, but try to work this out
yourself before you look .
When you have this pro gram running the way you want it to, SAVE
it on your diskette or on your tape cassette. We will use it
again later on.
77
OFF THE WALLS
He r e i s one \vay t o ma ke th e b a ll b oun ce off a ll f our wall s . Th e
s t a t ement s i n bl ack a r e t he ones th a t ha ve b een add ed t o o r
c ha nged fr om th e prog r am whi ch b ounced th e b a ll b e tween two
wa ll s .
78
7~0 REM NEW BALL POSITION
720 CCIUJR= BALL
740 PLOT XNOW,YNOW
760 REM ERASE THE OLD BALL POSTTION
7;30 CClLOR= 0
800 PLOT XOLD.YOLD
820 REM SAVE BALL POSITION
840 XOLD '" XNOlJ
8511) YOLO = YNOW
860 REM MOVE AGAIN
890 GO TO 580
As you will see \-Then you RUN t his program, the result is a bit
repetitive . You can alter the pattern of bouncing by changing
the starting values of XOLD and YOLD (lines 5~~ and 51~), but
here is a change you might like better:
One more sugges t ion . Why not have another INPUT, glvlng a value
to a variable called BACKGROUND? Fill the screen with the color
BACKGROmlD once, at the beginning of your program (right after
GR). Then, to erase the old ball position, use
or even
MAKING SOUNDS
Clicks, ticks, tocks, and various buzzes are easily generated .
You can make sounds on your Apple if you tap it, scratch your
fingers across it or drop it, but the sounds covered in this
manual are produced by programming it . So go to a quiet place,
and try working through this section .
79
To construct any sound-producing program on the Apple, you will
need this Qagic formula:
Try it.
1010 S = -16336
80
more buzzy t o nes, put one of yo ur variations into a loop . In
gen e ral, th e fast e r th e loop, the hi gher th e pit c h .
Now tr y your own sounds. Why not make a different sound off
each wall?
t .... E..~
50 S = PEE~I-l~336) GOTO 50
Now a dd
81
10 FOR PAUSE = 1 TO 2500 r~E ,( r PAUSE
RANDOM NOTES
Try this short program on your Apple .
t,.::::~
The RND in line 1~~ stands for RaNDom. The RND function returns
RaNDom numbers. Stop the program with
•
II
The numbers generated by this program were RaNDom decimal
fractions between zero and one.
82
Again stop the program with ~ ~ . Hmmm, interesting. The
random numbers are still all between zero and one. Write down
the last number that was generated so you'll remember it.
NEW
9~ REM ASSIGNS RND NUMBER TO X
100 X = RND(1)
110 REM MULTIPLIES X BY 10
120 X = X * 10
130 REM CHOPS OFF THE FRACTION
140 X = INT/X)
150 PRINT ~
100 GOTD 100
Line 14~ introduces the INT function. The statement INT(X)
gives the largest integer that is less than or equal to the
value of X. For instance, if the value of X is 3.6754, then
INT(X) is equal to 3. The parentheses following INT can contain
any arithmetic expression or numeric variable.
Now RUN the program. Does it work the way you expected? To
change the program so that it generates numbers from one to ten
instead of from zero to nine just add one to the value of X by
adding this line to your program:
145 X x + 1
Try it.
83
90 REM ASSIGNS RND NUMBER TO X
1¢0 X = RND(I) PRINT "X=RNO(l:''',X
105 PR If~T
110 REM MULTIPLIES X BY 1~
120 X = X .;; 10 PRINT "X=X*ll2)",
125 PRItH
130 REM CHOPS OFF THE FRACTION
140 X = INTIU PRINT "X=INT(;O ' ,:"
145 PRINT
150 REM ADDS 1 TO THE VALUE OF
1.:00 X = X ... 1 PRINT "X=X+1"
17~ PR rrn X
175 PRINT
180 FOR PAUSE 1 TO 200~ NEXT PAUSE
190 GOTO 101C
RUN this program, and see wh a t it does.
If you want to get fancy, you can condense this program to just
one line:
NEW
10~ PRINT "WHITEDICE",
11(0 PRINT INT (6 * RND( l») + 1
120 PRINT "REDDICE" ,
130 PRINT INT (6 * RNO(l)) + 1
This program generates random integers from one to six for each
die. To reroll the dice, reRUN the program. Can you write a
program th a t us e s these "dice" to playa game? Try it.
84
NEW
200 GR
210 REM CHOOSE A RANDOM COLOR
220 COLOR= INT (16) * RND(l)
230 REM CHOOSE A RANDOM POINT
240 X = INT (40 * RND(l)
250 Y = INT c4i * RND(l)
260 REM PLOT THE RANDOM POINT
;ne,· PLOT~.,"Y
280 REM DO IT AGAIN
2910 GO TO 220
Try using RND in other programs. Can you write a program that
draws lines in RaNDom colors across the screen?
SUBROUTINES
Imagine that there is a game for which you need a piece that
looks like a blue horse with orange feet and a white face . Her e
is a program that draws such a piece:
The key to doing this begins with the observation that you can
move a point which is at coordinates (A,B) to the right by
adding to the value of the first coordinate, A in this case .
For example, the point (4,17) moves 10 columns to the right if
you add 10 to the first coordinate, making the point (14,17).
85
Likewise, a point moves left if you subtract from the first
coordinate (or add a negative value). A simple experiment will
show you that adding to, and subtracting from, the second
coordinate moves points down and up, respectively.
NEW
112101J; REM PUT A HORSE ANYWHERE ON THE SCREEN
1010 COLOR= ry REM LIGHT BLUE
1020 PLOT l , ') 1
1030 HLIN X, X + 2 AT Y
10<10 COLOR= 9 REM ORANGE
1!O50 PLOT l,Y + 1
1060 PLOT X + 2,Y + 1
1070 COLOR= 15 REM WHITE
1080 PLOT~' - 1,,{-1
You notice that the GR has been left out. We want to use this
part of the program to put several horses on the screen. A GR
here would clear the screen before each new horse was drawn.
.::0 GR
30 REM FIRST HORSE CENTER
4i,21 X 12
50 'y' = 35
60
71/; REM SECOND HORSE CENTER
80 X .33
91j; 'y' = .2
100
Do the portion of the program at line l~~~ again and then end.
86
Wouldn't that be nice and easy? You know that the computer
can't read thos e strange instructions a t lines 6~ and l~~. It
can, however, read
, Z'°Z: RETURt4
Now you can write that "what if you only could " program:
21r ::;p
30 REM FIRST HORSE CENTER
,;;.,z .$.• .:::: 12
50 y '" 35
GiJSUB 1000
'.:.·0
'0 REM SECOND HORSE CENTER
80 X = .3:3
70 { = 2
100 GOSU8 1000
GOSUB 1000
to draw one of thes e special horses at whatever X,Y lo ca tion yo u
h ave c hosen.
TRACES
The portion of the program from line l~~~ to 1~9~ is called a
subroutine or subprogram. The portion of the program from
line 2~ to line l~~ is called th e main program.
87
To see the program's flow, or path of execution, you can invoke
a special feature called TRACE. This special feature can show
you why the Apple gave an error message when the horse-drawing
program was executed. Add this line to the main program.
it TRACE
and, for a moment, delete line 20. Put the Apple into TEXT mode
and RUN the program.
The numbers you see on the screen are the line-numbers of each
statement as it is executed. You can see how the program begins
at line 10, continues through the main program until the
subroutine call, then executes the subroutine, goes back to the
main program, executes the subroutine again, and, not finding
any smaller line numbers, goes to line 1000 and executes the
subroutine again. This is where the problem occurs. Do you
understand the error message now?
vfuen the program gets to line 110, it will do just what the line
says: end. RUN the program once more. No more error message.
As you have just seen, TRACE is very handy when you are having
problems with a program. If you want to TRACE only part of a
program, you can use the NOTRACE statement. Add this line:
88
A BETTER HORSE-DRAWING SUBROUTINE
Subroutines should be written so that problems from possible
errors do n ot arise when the program is Rilli. One problem with
our horse-drawing subroutin e is that some values of X and Y will
cause the horse to go off the edge of the screen . This can be
prevented by a set of statements such as:
leH2 IF X 1 THEt~ X = 1
,
HH4 IF X 3" THEN X = 37
llrl.~ IF V- 1 THEN Y = 1
,
U:'18 IF '{ 38 THEN Y = 38
20 GR
30 REM 1ST PLAYER'S HORSE COLOR
~0 BODY 7 REM LIGHT BLUE
50 FEET = 9 REM ORANGE
00 FACE = 15 REM WHITE
70 REM 1ST PLAYER'S HORSE CENTER
30 ,. = 1::1
'70 y =30
10'l' GOSU3 10lZ';O
89
and so on (b e s ure t o fo ll ow with an END st a t ement, b efo r e yo u
tr y to RUN it) . Tha t's a l o t of st a tement s ea ch time you wa nt a
ho rs e , but i t i s still f ewe r th a n if you ha d t o t ype o ut th e
e ntir e ho rs e pr og ram each time . For add i t io nal prog r amm i ng
ea s e , a r a th e r subtl e tri ck is t o have a s ubro utin e th a t assig ns
th e co l or s f o r each pl aye r' s h or se- - a nd have e ac h of th ose
s ubrout i n es ca ll th e ho r s e-drawi ng s ubroutin e , in turn.
2000 REM DRAWS BLUE HORSE WITH ORANGE FEET AND WHITE FACE
2010 BODY 7 REM LIGHT BLUE
2020 FEET 9 REM ORANGE
2030 FACE 15 REM WHITE
20 4 0 GOSU3 11000
20513 RET!jRt~
2500 REt1 DRAWS ORANGE HORSE WITH PINK FEET AND GREEN F~CE
25110 EOD'{ 9 REM ORAUGE
2520 FEET 11 REt1 PIN'"
2530 FACE 12 REt1 GREEN
25417! GI]SU8 111hZ'0
2550 RETURN
Now a ll yo u need, to put a blue ho r se wi th \vhit e a face a nd
o r a nge f ee t a t (10 , 11), i s
90
3000 REM CHGDSES RANDJM ~ i
:;Z,10 ~ = INT \R~Dll) * 371 + 1
3/20 i = TNT r~~Dt II • 38\ +
:'030 RETURN
HIGH-RESOLUTION GRAPHICS
We call the kind of graphics you h a ve been using so far,
low-resolution graphics . In this section you will learn to
use another kind of graphics called high-resolution graphics .
This n e\~ kind of graphics l ets you draw with much more detail
than you could with the 4~ by 4~ low-resolution grid . The new
high-resolution graphics screen is 28~ by 16~ plotting points.
The horizontal coordinates s t art with 0 at th e left of th e
screen and e nd with 279 at the right. Likewise the vertical
coordinates go f r om 0 at th e top of the screen to 159 at the
bottom.
91
Type
HGR
0 black1 4 black2
1 green 5 orange
2 violet 6 blue
3 white1 7 white2
92
The only instruction for PLOTting in high-resolution graphics is
HPLOT. To try this out, once you have issued the HGR command,
type
H,:IJLOR= .3
HPLOT iJO,10,:;
The last line will plot a white, high - resolution dot at point
X = 13~, Y = l~~ .
HPL01 O,0 TO 27 Q ,Q
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 ne~l HCOLOR comhland since that point was plotted) .
You can "chain" these commands and HPLOT several lines in one
statement if you wish.
93
Clear the screen with HGR, and try this on your APPLE:
Not only is drawing lines on your Apple easy, but diagonal lines
are just as easy to draw with high-resolution graphics . To draw
a line from the top left corner of the screen to the bottom
right corner just type
~0¢ HGR
: "; l He DLCiR -= ..
:::;:~~ " "= Fc::...,(f,
~:~.-:1: ~' =.-: PD~,: .. I
94
This program works, but it would be improved if it were easier
to draw a solid line. Those gaps between plotted points are not
always desirable. You can improve the program by typing the
following lines:
LIST the program and check it carefully to make sure you typed
everything correctly . Here's what the program does.
High-resolution graphics and HCOLOR are set, and then the
program goes to the subroutine beginning at line 100~. The
subroutine determines the value of the X and Y coordinates . The
game controls each return a maximum value of 255 . Because
high-resolution graphics uses horizontal coordinates from 0
through 279, the values returned by PDL(0) are divided by .913
to expand their range to the full screen width. Similarly, the
values returned by PDL(l) are divided by 1.6 to compress their
range down to the range of high-resolution vertical coordinates:
o to 159. As with low-resolution graphics, the coordinate
actually plotted is the nearest integer value less than or equal
to the given value. Line 1~2~ RETURNs to the main program, and
then line 23~ plots the point X,Y. Next the program goes back
to the subroutine, gives X and Y new values and RETURNs to line
25~ in the main program where a very short line is drawn from
the old point X,Y to the new X,Y. The COTO in line 26~ repeats
all of the program except the HGR and HCOLOR instructions,
getting new values for X and Y from the position of the game
controls, and then PLOTting the new X,Y position. Use ~ ~
to stop the program.
95
Now SAVE the program, a f d then RUN it .
NEW
9)0 HOt1E
1¢¢ VTAB 24 REM MOVE CURSOR TO BOTTOM lINE
12¢ HGR REM SET HI-RES GRAPHICS MODE
14¢ A = RND (1) "* 279 REt1 P Iei' AN "A" FOR CENTER
16¢ B = RND (1) * 159 REr1 prcv A ';B" FOR CENTER
18¢ N = INT ( RND (1) * 4) + 2 REM PICK A STEP 51
ZE
2¢¢ HTAB 15 PRINT "STEPPING By "iN;
22¢ FOR X ¢ TO 278 STEP N: REM STEP THROUGH A VA
LUES
24¢ FOR S ¢ TO 1 REM 2 LINES. FROM X AND X + 1
26¢ HCOlOR= 7 * S REM FIRST LINE BLACK, NEXT WHIT
E
281; REM DRAW LINE THROUGH "CEt'F ER" TO OPPOSITE SID
E
HPLOT X + s.¢ TO A. B TO 279 - X -- S, 159
NEXT 81 X
FOR '{ ep TO 158 STEP N. REr.., STEP THROUGH B VA
LUES
36¢ FOR S = ¢ TO 1 REM 2 LINES. FROM BAND B + 1
38¢ HCOLOR= 7 * S REr1 FIRST LINE BLACK. NEXT l~I·HT
E
4M REM DRAW LINE THROUGH "CEt'nER" TO OPPOSITE: S
rDE
42¢ HPLOT 279,Y + S TO A.S TO ¢' 159 - Y - S
441' NEXT S. '{
46¢ FOR PAUSE = TO 15¢¢ NEXT PAUSE REt1 DELAY
48(p GOTO 12¢
This is a rather long program; type it carefully and LIST it in
portions (LIST 0,320 for instance) to check your typing. When
you are sure it is correct, RUN the program.
96
As you saw in lines 32~ and 44~, one instruction can provide the
NEXT for ~ore than one FOR statment. Be careful that· you list
the NEXT variables in the right order, though, to avoid crossed
loops.
•-
and then
TEXT
Can you think of ways to change the program? After SAVEing this
version on your diskette or cassette recorder try making the
value of HCOLOR change randomly. Try drawing first orange then
blue lines, or only blue lines.
97
98
10~ Stringing along: LEN, LEFT$, RIGHT$, MID$ and CLEAR
105 Concatenation got your tongue?: putting strings together
105 More string functions: VAL and STR$
108 Introducing arrays: DIM
110 Array error messages
III Conclusion
99
STRINGING ALONG
Would you like to see your name spelled backwards? So far we
have played with graphics and numbers, but computers can also
manipulate letters and symbols. Your computer can deal with a
single character, or it can handle a whole string of
characters at a time. This ,~ill seem fairly natural, since we
humans also usually deal with characters in bunches. Variables
which contain character strings, like numeric variables, have
names. String variable names follow the same rules as numeric
variable names except that they end with a dollar sign ($).
Here are some examples of string variable names:
t"!{t'Mt1E$
A$
SENTENCES$
The variable A is different from the variable A$, and both can
be used in the same program.
Notice that the characters that you put into a string variable
must be enclosed in quotes. The statement
PRINT NAt1E$
will print the contents of the variable NAME$: in this case, the
name of the 33rd' President of the United States. Thus, when you
have a string of characters that you need often, you can store
the string in a variable with a short name.
PR I NT LEN (NAt1E$)
and the Apple will PRINT the LENgth of the string, in this case
15. Notice that spaces count as characters.
100
The number of characters in a string may range from 0 to 255.
If you try to use more than 255 characters in a string you will
just get the ?SYNTAX ERROR or ?STRING TOO LONG ERROR message. A
string with 0 characters is called a null string. Refer to
the Applesoft BASIC Programming Reference Manual for more
information on null strings.
If, for instance, you want to PRINT the first five letters in
NAHE$ you can type
PRINT LEFTS(NAMES.5)
and
HARRY
PRINT RIGHTS(NAMES. 5)
RUMAN
will appear. For each program you write that uses string
variables, you must assign the string value within the
program. Each time you RUN a program, all numeric variables are
first set to the value 0 and all string variables are set to
contain the null string. Here's a short program that uses the
functions LEN and LEFT$.
NEW
90 NAMES "HARRY S . TRUMAN"
100 FOR N = 1 TO LEN(NAMES)
110 PRINT LEFTS(NAMES.N)
120 NEXT N
RUN this program. The RIGHT$ command is just like the LEFT$
command except that it uses the rightmost characters in the
string. Now write another program substituting RIGHT$ for
LEFT$. What happens when you RUN it?
101
Type
PRINT MIDS(NAMES.7)
Your computer replies with
s . TRUf1AN
since S is the seventh character in the string. Now try this
program.
NEW
19¢ NAMES = "HARRY S. TRUf1AN"
2¢~ FOR N = 1 TO LENINAMES)
210 PRINT MIDSINAMES.N)
220 NEXT N
Do you get what you expect when the program is RUN?
Suppose you want to PRINT just the "y S. T" from the string
called NAME $. To do this you add another argument to the MID$
function.
PRINT MIDS(NAMES.5.6)
The first number (5) specifies the string character space at
which the Apple is to begin PRINTing. The second number (6)
tells it how many character spaces to PRINT. Thus the
instruction is interpreted by the Apple as "find the fifth
character space in NAME $ , and PRINT six character spaces
beginning at the fifth and moving to the right." Change line
2i~ of the previous program as follows, and RUN it.
NEW
20iG AS = "A13CDEFGHIJII..U1NOPGRSTU\JWXYZ"
210 PRINT
220 PRINT "TYPE A NUt1BER. FROt11 THROUGH " ; LEt'~ ( A$ ); " "
230 PRINT "AND I WILL TELL YOU wHiCH LETTER HAS THAT
POSI1ION IN THE ALPHABE T
24\Zl INPUT P
250 IF P > LEN lAS) OR P < 1 THEN GOTO 210
260 PRINT
27j2l PRINT f1IDS(AS.P. 1);" IS LETTER NUMBER " ; P ;
" IN THE ALPHABET "
280 PRINT PRINT
290 PRINT "TYPE A LETTER. AND I WILL TELL YOU"
102
300 INPUT "WHERE IT I 5 I N THE: ALPHABET ". X$
310 FOR N = 1 TO LEN(A$)
320 IF t-1ID$<A$,N, 1) = X$ THEN GOTO 370
330 NEX r t·~
340 PRUH
350 PR INT "THAT IS NOT A LETTER OF THE ALPHABET. " PRINT
360 Goro 290
370 PR It·n
:miZ' PRINT ~.* . " is LETTER NUr'iBER ", N;" IN THE ALPHABET. "
3'h" PRINT
400 GOTO ~10
YS = MID$IA$,24, 3)
103
NEW
100 REM PROGRAM TO SPELL YOUR NAME BACKWARDS
110 INPUT "TYPE YOUR NAt1E AND I WILL SHOW IT TO YOU SPELLED
BACi.'.WARDS "; N$
120 REM REVERSE ORDER OF LETTERS
130 FOR T = LEN(N$) TO 1 STEP -1
140 R$ = R$ + (MID$(N$,T. 1)
150 NEXT T
160 PRINT PRINT ",{OUR NAf~E SPELLED BACi-<.WARDS IS "i R$
170 PRINT PRINT
180 GOTO 1110
175 CLEAR
N = 254
PRINT N
Now type
CLEAR
and then
PRINT N
104
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 on your Apple.
C$ = "GOOD MORNING"
D$ = C$ + " " .~ "BILL"
PRINT D$
BILL-GOOD-MORNING
would appear on your screen.
NEW
1ei0 INPUT "GI'.,iE t1E ABOUT HAI_F OF A SENTENCE . " ; HALF$
110 INPUT "NOW GIVE ME THE SECOND HALF OF THE SENTENCE
";OTHERHALF$
120 WHOLE$ = HALF$ + OTHERHALF$
1:3ei PRINT
140 PRINT WHOLE$
150 PRINT PRINT PRINT : GOTO 100
And that's how you can do concatenation.
105
C$ ::::: It i23 11
PRINT C$ + 7
VAL
The VAL function returns the VALue of the con t ents of a string
as opposed to its actual contents . Type
PRINT C$
and then type
PRINT VAL(C$ )
PRINT C$ + 5
PRINT VAL(CS) • S
and
126
o ::: I")AL..(C$) - 21
106
Now type
PRINT G
and see what you get. Are the contents of Q as you expect? You
can even use VAL to add the numerical value of two different
strings. To try this, create a new string
IA.$. = 1112"
P = VAL(C$) + VAL(K$)
PRINT P
P$ = STR$(P)
PRINT P$
will show you how STR$ works. Here is a program that uses STR$
and VAL.
Do you understand how the program works? Why are there commas
in lines 370 and 380? Try deleting line 330 to see what its
effect is. The first four lines of this program demonstrate the
107
first steps toward making a truly "bomb proof" input routine.
See what inputs can still stop this program, and then devise
ways to catch those inputs before they can cause the program to
stop.
INTRODUCTION ARRAYS
In this section on arrays we use examples from mathematics, but
they are from recreational mathematics and require nothing
beyond elementary arithmetic.
To create an array, you must first tell the computer the maximum
number of elements you want the array to accommodate. To do
this you use a DIM statement (DIM stands for DIMension). The
elements in an array are numbered from 0, so to DIMension an
array called A that will have a maximum of 16 elements, type
DIt1 A(lS)
A<jO)
AU)
A(2)
A(lS)
Although you may find them awkward to type, they can be used
just as any other variable is used. The statement
A(9) = 45 + A(12)
is perfectly correct. The number in parentheses is called a
subscript, and the notation A(l2) is read "A-sub-twelve." The
108
subscript can be an arithmetic expression or it can be
- represented by a variable.
1 iZ,e:,
REM DIMENSION ARRAY CALLED DAYS', TO HOLD 7 NUI1BER5
i 10 DIH DA'iS(6)
120 REH FILL THE ARRAY
130 FOR NUli = 0 TO 6
140 DAYSINUMI = NUM + 1
150 NEXT WJt"
16~ REM PRINT THE ARRAY ELEMENTS
170 FOR I = 0 TO 6
180 PRINT "Dt\'>"S( "; I; ") '" "; DAYS' I)
190 NEXT I
109
Do you understand how this program works? It first fills an
array with numbers and then scrambles the contents of the array.
Notice that you don't have to start filling the array at zero.
Here's a description of what some of the more elusive program
lines do. Lines 23~ through 25~ fill the array and assign each
array element a number corresponding to its array number
(GLASS(1) = 1, etc.). Line 27~ sets the new variable WINE to
numbers 1 through 8. Line 28~ sets variable MILK to random
integers from 1 to 8. Then line 3~~ makes sure that the value
of WINE is not equal to the value of MILK at any given time.
The contents of variables GLASS(WINE) and GLASS (MILK) are
switched in line 31~. Finally the array is printed with lines
33~ through 35~.
?REDIM'D ARRAY
This error message occurs when an array is dimensioned more than
once in the same program. Often this error occurs because the
default dimension has been used, and a dimension statement has
been added to the program afterwards.
110
subscript is less than 0 or greater than 25 will give the ?BAD
SUBSCRIPT ERROR .
These are some of the ways that you can use arrays . The arrays
used here are all one dimensional arrays. You can also use
arrays tha t have two or more dimensions. See the Applesoft
BASIC Programming Reference Manual for more a more information
on arrays .
CONCLUSION
This book has presented the core of Applesoft BASIC . If you now
go through this book again, writing your own programs Ivith the
statements that have been presented here, you will solidify your
knowledge considerably . The Apple has many more abilities, and
once you have mastered those presented here, there are whole new
worlds for you to explore.
111
-
112
114 Appendix A: Summary of Commands
113
I
--'
..,......I
Arrml Keys -+ ~
The keys marked .,i th right - and left - pointing a rr ows are used to
edi t Applesoft progralils. The right-arrm~ key moves the cursor
to the right; as it does, each character i t crosses on the
screen is entered as th ough you had typed it . The left - arrow
key moves the cursor t o th e left; as it moves, o n e character is
erased from the program line which you are c urr en t ly typing,
regardless of what th e cursor is moving over .
CALL -151
CATALOG
CLEAR
114
COLOR = 12
CONT
CTRL C
CTRL X
DEL 23,56
DU1 NMIE$(50)
115
subscript. In the example, NM1E$(5~) will be allotted 5~ + 1 or
51 strings of any length. If an array element is used in a
program before it is DIMensioned, a maximum subscript of 1~ is
allotted for each dimension in the element's subscript. Array
elements are set to zero when RUN or CLEAR is executed.
END
The Escape key may be used in conjunction with the letter keys I
or J or K or M to move the cursor without affecting the
characters moved over by the cursor. To move the cursor,
first press and then release the ESC key to enter edit mode.
Then press the appropriate letter key once for each move in the
desired direction. The REPT key can be used to speed the moves
by pressing the appropriate letter key and then pressing the
REPT key while holding down the letter key.
ESC I up
ESC J left
ESC K right
ESC M down
FLASH
116
instructions; the instructions inside the loop will be executed
for W equal to 1, 2, 3, ••• 20, then the loop ends (with W = 21)
and the instruction after NEXT W is executed . The second
example illustrates how to indicate that the STEP size as you
count is to be different from 1. Checking takes place at the
end of the loop, so in the third example, the instructions
inside the loop are executed once .
GOSUB 250
GO TO 250
GR
HCOLOR = 4
o black 1 4 black2
1 green 5 orange
2 violet 6 blue
3 whitel 7 white2
lIGR
117
leaving four lines for text at the bottom. The screen is
cleared to black, and page 1 of memory is displayed. Neither
HCOLOR nor text screen memory is affected when HGR is executed.
The cursor is not moved into the text window.
HGR2
HLIN 10, 20 AT 30
HOME
Moves the cursor to the upper left screen position within the
text window, and clears all text in the window.
HPLOT 10,20
HPLOT 30,40 TO 50,60
HPLOT TO 70,80
HTAB 23
118
IF AGE < 18 THEN A = 0: B = 1: C 2
IF ANS $ = "YES" THEN GOTO 100
IF N < !·lAX THEN GOTO 25
INPUT A
INPUT "TYPE AGE THEN A COMMA THEN NAl1E. "; B, C$
In the first example, INPUT prints a question mark and waits for
the user to type a number, which will be assigned to the numeric
variable A. In the second example, INPUT prints the optional
string exactly as shown, then waits for the user to type a
number (which will be assigned to the variable B) then a comma,
then string input (which will be assigned to the string variable
C$) . Multiple entries to INPUT may be separated by commas or
RETURNs.
IllT(NUM)
INVERSE
LEFT$("APPLESOFT" , 5)
Left Arrmv
119
LEN("AN APPLE A DAY")
LEN(B$)
A = 23.567
AS = "DELICIOUS"
The variable name to the left of = is assigned the value of the
string or expression to the right of the = •
LIST
LIST 200,3000
LIST 200-3000
The first example causes the whole program to be displayed on.
the TV screen; the second and third examples cause program lines
200 through 3000 to be displayed. To list from the start of the
program through line 200, use LIST -200 ; to list from line 200
to the end of the program, use LIST 200-. LISTing is aborted
by CTRL C, and the CONT command cannot be used. To stop the
program temporarily at some point in the listing, use CTRL S.
Use CTRL S again to resume the listing.
LOAD
Attempts to find a program file with the name DOW JONES on the
diskette in the specified or default drive. If the program is
found, it will be LOADed into the Apple's memory. LOAD erases
any program in the Apple before placing the new program in
memory. This command, when followed by a file name, is a DOS
command.
120
~lID$("AN APPLE A DAY",4)
MID$(DAY$, 4,9)
NEW
NEXT
NORMAL
NOTRACE
PDL (l )
PLOT l0, 20
121
PRINT
PR INT A$; "X = "; X
COREX = 3
to be printed .
REPT
If you hold down the repeat key, labeled REPT, while pressing
any character key, the character will be repeated.
RETURN
Right Arrow
122
RND (5)
RUN 500
RUN ANNUITY
SAVE
SAVE ADDRESSES
123
STR$(l2.4S)
TAB(23)
TEXT
TRACE
VLIN l~, 20 AT 3~
124
VTAB(lS)
125
APPENDIX B: RESERVED WORDS
IN APPLESOFT
The followin g list contains all of the reserve d words in
Applesoft BASIC. Although most of these words are not covered
elsewhere in this manual, the list is handy as a gu ide for
naming variables . Refer to the Applesoft BASIC Pro graQmin g
Reference Manual to find out how to use more of these commands.
126
The ampersand (&) is intended for the computer's internal use
only; it is not a proper Applesoft command. This symbol, when
executed as an ins tru ction , causes an unconditional jump to
location $3F5 .
127
APPENDIX C: EDITING FEATURES
The Left and Right Arrow Keys +- -+
The left-pointing arrow key, also called the backspace key,
moves the cursor back (left) one space, erasing the character it
passes over . If you haven't pressed ~ at the end of the
last line you typed, the backspace key only affects the
characters on that line.
You can cause the cursor to move more quickly by pressing the
~ key while pressing one of the arrow keys.
B
liB
B
Pressing 1m gets you into edit mode. Once you are in edit
mode, pressing one of the above-mentioned letter keys will cause
the cursor to move one character in the direction of the
corresponding arrow . You can use these keys to move the cursor
anY"lhere on the screen.
For faster cursor motion, hold down one of these keys and then
hold dm-m the ~ key. The cursor will zip along \lhile both
keys are held down. If the cursor reaches the top of the
screen, it will stop. If the cursor reaches the bottom of the
128
screen, it will stop, and the lines will start to scroll upward.
If it reaches the right edge, the cursor will disappear and
reappear at the left edge, but on the next line. At the left
edge, it will reappear on the right, one line up. To return to
normal mode, press the space bar once .
Typing
••
,~ill delete the line you are currently typing . This is useful
"'hen you realize you have ;'1 ade a mistake before you have pressed
Ilimm
110
..
To clear the screen, type mI followed by an "at" sign •
The cursor will appear at the top left-hand corner of the screen
without the prompt. The prompt character will appear when you
press mi!ii3
If you are already in edit mode you can clear the screen by
simply typing an " at" sign (@). The Apple will return you to
normal mode.
129
The HOME command will also clear the screen. Si~ply t y pe
HOME
and the cursor will "home" to the top left - hand corner of the
screen.
•
.'.'
Exit edit mode Press space bar
• then II
Clear fro~ the cursor
to the end of the screen
Press •• • then
then
II
II
•• ..
and
130
APPENDIX D: FIRMWARE APPLESOFT VERSUS
DISKETTE OR CASSETTE APPLESOFT
Introduction
You do not need to read this appendix at all unless you are
using one of the following:
131
The portion of Apple's memory that is used by a particular
activi t y can be described in t erms of the memory loca ti ons
used, usually specified as a range of memory addresses . If a
ce rt ain range of memory locations is being used to store your
program, for i n stance, those same memory locations must not b e
used to c r ea te a high-r eso lution graphics display, or your
program will be l o st.
General Discussion
Apple Computer Inc . offers t~lO versions of th e BASIC programming
language . Integer BASIC, described in the Apple II BASIC
Programming Manual, is a very fast BASIC su i ted for many
a ppli ca tion s , es pecially in e duca tion, game play ing, and
g raphi cs . The o t her version of BASIC is ca ll e d " Applesoft" an d
is better suited for most business and scientific app li ca tions.
The main body of this manual assumes your Apple has firmwa r e
Applesoft i nstalled in sockets D~ through F0 on the Apple's main
printed ci r c uit bo a rd. PART 1 of this appendix gives more
details a b out ins t alling and using the plug-in Applesoft II
Firmware Card .
132
If you are using the diskette or the cassette version of
Applesoft, the
An Important Note
One of the functions of the prompt character, besides PRmfPTing
you for input to the computer, is to identify at a glance which
language the computer is programmed to respond to at that time.
Here ~re the prompt characters you are likely to see:
133
2) Remove the cover from the Apple. This is done by pulling up
on the cover at the rear edge (the edge farthest from the
keyboard) until the two corner fasteners pop apart . Do not
continue to lift the rear edge, but slide the cover backward
until it comes free .
3) Inside the Apple, across the rear of the main circuit board,
there is a row of eight long, narrow sockets called "slots."
The leftmost one (looking at the computer from th e keyboard end)
is slot UG; the rightmost one is slo t U7 . Hold the Applesoft II
Firmware Card so that its switch is toward the back of the
computer; insert the "fingers" portion of the card into the
leftmost slot, slot UG . The fingers will enter the slot with
some friction, and will then seat firmly. The Applesoft II
Firmware Card must be placed in slot U0.
5) Replace the Apple's cover: first slide the front edge into
place, then press down on th e two rear corners until they pop
into place.
With the switch in the upward position, the Apple will begin
running in Applesoft BASIC, instead of Integer BASIC, when you
turn the computer on. The prompt character 1 tells you that
you are in Applesoft.
When using the Disk Operating System (DOS), the computer will
automatically choose Integer BASIC or Applesoft, as required.
It does not matter in which position the switch is set on the
Applesoft II Firmware Card.
134
addition to the 2K bytes used by the Apple, a nd the l~K bytes
used by Applesoft BASIC loaded from diskette, the Disk Operating
System (DOS) occupies another l~.SK of memory . Th ere fore, your
computer must contain at least 24K bytes of memory to us e the
diskette version of Applesoft BASIC .
FP
FP
FP
command aga in. Or, if you know that a diff e r ent drive
contain s a di s ke tt e with APPLESOFT on it, yo u may issue th e FP
command with slot a nd drive paramet e rs . For exampl e, to load
Applesoft from th e diskette i n drive 2 connected to a disk
con tr oll e r card in slot 6, you would type
FP, S6, D2
135
APPLESOFT program on the diskette in the disk drive specified by
the LOAD or RUN command, or on the diskett e in the default disk
drive if none is specified. You may, of course, use the FP
command to change languages yourself, as described above.
3) Type LOAD
7) Type RUN and press the key marked RETURN. The screen will
display the copyright notice for APPLESOFT II and APPLESOFT's
prompt character, J.
136
Typing _ m from the Monitor program (prompt character *)
will transfer you to Integer BASIC; this will e r ase Applesoft.
Firm\vare Applesoft does not occ upy any space in the Apple's
memory, and therefore may be used with Apples of almost a n y size
memory.
137
partly occupies this portion of memory, attempting to use HGR
will erase Applesoft, and your program will be lost. The HGR
command can only be used with firmware Applesoft.
The HGR2 command uses "page 2" of graphics memory (the portion
of Apple's memory from location 16384 to location 24575). HGR2
can be used both in the firmware and in the cassette version of
Applesoft, but is only available if your Apple contains at least
24K of memory. Therefore, in a system with less than 24K of
memory, cassette Applesoft does not offer any form of
high-resolution graphics.
The command
POKE -16301,0
138
The Applesoft command IIPLOT can be used in this form if you
are using firmware Applesoft:
139
PART 5: MEMORY LOCATIONS USED BY DOS
AND BY APPLESOFT BASIC
Highest RAM Appl e ' s Memory lVithout DOS,
memory ad dr ess : Applesoft
49151 ($BFFF) ~'r---,-'-
!----------""" sets HIMEH here
on a 48K system 1~75 2 Disk [ Note 1 1
[ Note 1 1 ( $2A 0~) Operating
b y t es System
I(if boote d)
~--..!+~------------j""
I
Bootin g DOS
sets HIMEM h e r e
I [ No t e 1 1
Appl esof t strings
start at HIMEM
and build d own
--------!--------
245 76
~
( $6 ~~~)
Hi gh-resolu t io n g r a phi cs ,
Page 2
[ Note 4 1
16384 Diskette
~
( $4 ~~~) or cassette
High-resolutio n gra ph ics , Applesoft
-------
8192 ~
- - - - - Page 1
[ Note 3 1 •:- .... sets LOMEM a t
1 2291 ($3~~3)
[ Note 2 1
($2~~~) I
I
Di ske tte
~ o r ca ssette
- - - - - - - , - Appl esof t
Variables I (if used)
s t a rt at I occ upi es
LOMEM and : thi s s pa ce
build up I [Note 3 1
~--------- I
Applesoft • I
I I
prog r am lines I I
push LOMEM up I I Firmware
2 ~48 I I Applesoft
-+,~---------.:~--=----____f.... sets LOMEM h e r e
($~8~~)
BASIC Sys t e m us e : [ Note 2 1
low-reso lution graphics
Lowest RAM a nd t ex t screen, etc .
memory a ddr ess : ~.L- ___________________~
0~IJIJ ($IJIJIJIJ)
140
Note 1. HIMEM is the address of the highest memory location
available to an Applesoft program. If your system is in
Applesoft, the value of HIMEM can be found (low byte first, then
high byte) in decimal locations 115 and 116 ($73-$74,
hexadecimal). To see the current value of HIMEM, type
141
sets HIMEM to a value greater than 16383. This means that you
cannot use DOS and high-resolution graphics at the same time,
unless your system contains at least 32K of memory.
142
APPENDIX E: ERROR MESSAGES
All of the error messages that can be generated in Applesoft
BASIC are listed here along with their descriptions. See the
Applesoft BASIC Programming Reference Manual for more
information on the error messages not covered in this manual.
The follmling are the possible error codes and their meanings.
110re than two statements of the form IF "XX" THEN were executed .
143
?ILLEGAL DIRECT ERROR
Any of the following can cause this error: program too large;
too many variables; FOR loops nested more than 10 levels deep;
GOSUB's nested more than 24 levels deep; too complicated an
expression; parentheses nested more than 36 levels deep; attempt
to set LOMEM: too high; attempt to set LOMEM: lower than present
value; attempt to set HIMEI'1: too low.
?OVERFLOI.J ERROR
144
?REDIM ' D ARRAY ERROR
?SYNTAX ERROR
145
?UNDEF'D STATEMElIT ERROR
146
APPENDIX F: THE OLD MONITOR ROM
110st of this manual assumes that your Apple contains the
Autostart R0l1, which instantly starts your Apple running in
BASIC when you turn on the Apple's power switch . ~fuen you turn
on you r Apple, if it clears its own screen and prints
APPLE 1 [
at the top (and boots your disk, if you have one) then your
Apple contains th e usual Autostart ROM.
•
•••
147
Recovering from Accidental RESETs
If you r Appl e contains the Aut os tart RO/>!, pr ess ing th e t'mD
key causes no proble~s: yo u a re i~Qediately returned to th e
BASIC yo u were j ust usin g .
1. Witho ut th e Disk
II
11-
This will return yo u to th e BASIC you were using when you
pressed th e em key, without losing your program.
1111-
2. With th e Disk
11111111_
This wi ll return yo u t o DOS a nd th e BASIC you were using wh e n
you pr essed th e IlIm key, wi thout losing yo ur prograQ .
11.- II
148
will attempt to reinstate Integer BASIC as your prog r amming
language. This may erase Applesoft and any program in memor y ,
and the un initialized Integer BASIC will not work corr ec tl y .
.. - II
diske tte Applesoft us e rs should use
.. - II
diske tte Applesoft us e rs can do th e same, but th ey 'viII th en b e
in Integer BASIC, and will hav e to re-boot the disk ( PRif6 ) and
th e n reload Applesoft from diske tte ( FP). Cassette Applesoft
us e rs will also find themselves in Integer BASIC, a nd will have
to reload Applesoft from ca ssett e tape.
149
150
INDEX TO THE APPLESOFT TUTORIAL
NOTE: The pa ge numb ers in parenth eses r efe r t o the
Applesoft II BASIC Prog r amning Refe r ence ~~nual .
A BELL 8, 10
bli nking square : see cursor
additi on 23 , 39 - 42 booting DO S : see DOS
address 131 - 132 (4(.l, 41, 43 - 45) boun ci ng ball 74 - 79
AND 57 - 59 (33, 36 , 144) branc hing
Apple Di sk II Di s k Driv e : see di sk FOR/NEXT 64 - 67, 116-117, 143,
drive 144 (11 - 14, 20, 78, 79 , 152)
Applesoft BASIC 2 GOS UB/RETURN 87 - 91 , 11 7, 143 ,
co ~mand s umma ry 11 4-1 25 145, 146
error messages 143 -1 46 (15, 16, 79, 8(;1, 119, 153)
loading from casset t e 136 GOTO 5(;1, 59, 63 - 64, 117, 146
( 106-10 9) (76, 81, 153)
loading f r o~ diskette 134 -1 36 IF/THEN 59- 6(;1 , 119, 143 , 146
on casse tte 2, 92, 93, 96, 131- (9-1(;1, 76 , 154)
133, 136- 142 , 148-1 49 bytes 131 , 135 , 136, 137- 138
(106, 108, 1(9 )
on di ske tte 2, 92 , 93, 96, 131-
133, 134 -1 42, 148-149
on fi r ~ware ca rd 6, 117, 131 -
c
134, 137 - 142 , 14 8-1 49 cabl e 3, 5
(44, 106, 107, 1(9) CALL -1 51 114 , 133
Applesoft II BASIC Programming casse tt e App l esoft: see Applesoft
Re ferenc e ~ nu a l 26, 97, 101, BASIC
I l l , 114, 126 , 14 1, 143, 149 CASSETTE IN jack 5
Applesoft II Firmwa r e Ca r d 6 , casse tt e r eco rd e r
117, 131 -1 34, 137- 14 2 , 148-149 plugging in 5
(106, 107, 1(.l9) se tt ing th e volume 11 -1 4
a rgum ents 35 CASSETTE OUT jack 5
a rithmeti c 23- 24 , 59 (33, 36) CATALOG 16, 6(;1, 114
a rithmeti c operato r s 23- 24, 59 change prog ram lin e : see e ditin g
(33, 36) CLEAR 1(;14 , 11 4 (8, 52, 15(;1)
precedence of 39- 42 clearing the screen 9 , 12, 33,
arrays 1(;1 8- 111 (1 4 , 18 , 32, 58) 45 , 11 8, 129-1 3(;1
er ror messages 11(;1 - 111 colon 8 1 (1(;1, 125)
a rr ow keys 11, 27 - 29, 53 , 114, COLOR= 3(;1- 34, 11 5 (5, 11, 24,
128 (54, 55, 11(;1- 114, 15(;1) 25, 85 , 15(;1)
arrow , upward pointing 24 color (23 - 27 , 85, 89 , 131 - 134)
asse rtion s , tru e a nd false 55 - 58 hi gh-reso lution cha r ts 92, 117
(9) low-resolu ti on c ha rts 18 , 115
Autostart RON 2, 147-1 48 names and numb ers 18, 92 , 11 5,
11 7
setting TV col or 18- 19
B COLOR DEMOS OFT
on diskett e 16, 18, 3(;1
backspace key 27 - 29, 53 , 11 4, 128 on casse tt e tape 12, 18, 3(;1
beep 1(;1 co lumns
generating 78- 81 t a b fields: see tab
with LOAD and SAVE 12- 13, 62, with graphi cs 29 , 62 - 63
123 , 136 conma 68- 69 (6, 7(;1)
151
commands 114-125 (2, 122-123)
concatenation
E
strings H}5, 145 (21, 71) EAR or EARPHONE jack 5
CONT 51, 115, 143 edit mode 52, 128
(39, 4~, 67, 151) editing (54, 55, 11~-1l4)
Control: see CTRL key arrow keys 27-29, 53, 114, 128
co- ordinates changing program lines 48-49,
high-resolution 91, 95 (54, 11~-114)
low-resolution 29, 64, 71, CTRL X 54, 115, 129
85-86 DEL 49, 65, 115, 129
CTRL B 137, 147, 149 pure cursor moves (ESC with I, J,
CTRL C 17, 5~-51, 115, 12~, 148- K, and ~I) 52-53, 116, 128-129
149 (7, H1, 35, 39, 4~, 1~7- element
1~9, 151) arrays 1~8
CTRL key 1~ (35, 144) (14, 32, 58, 62 -64)
CTRL G 1~ END 88, 9(1, 11 6
CTRL S 75, 12(11 (16, 39, 118, 152)
CTRL X 54, 115, 129 equal sign
(55, 66, 69, 151) as a replacement sign 36-3 9
controller card 3, 16, 135 (12 )
cursor 5, 1~, 11, 13, 16, 22, 136 in an assertion 55 (55)
cursor position 1~, 11, 27 -29, erasing
52-53, 116, 124 programs 44-46, 121 (3, 38)
(5~-52, 54, 55, 11~-1l4, 131) the screen 9, 12, 33, 45,
129-13~ (52 )
ERR or ERRERR 12
D error messages 143-146
(l15-117, 167)
debug mode: see TRACE ESC key 8-9, 52-53, 128-13(11 (35)
decimal places 25 (18, 22) execution 44-45, 48-49, 143
deferred execution 44-45, 48, 143 (2, 36, 38-45)
(2, 36, 134) exponentation 24, 39-42
DEL 49, 65, 115, 129 (49, 151) (4, 5, 18, 31-33)
delay loop 82 (27, 41-43, 97)
delete 49, 54, 65, 115, 129
(3, 38, 49)
DIM 1~8-1~9, 115-116, 145
F
(14, 58, 152) firmware Applesoft 6, 117, 131-
dimensions: see DIM 134, 137-142, 148-149
Disk II disk drive: see disk drive (1(116, 1(117, 1(119)
disk drive 3, 4, 6, 15-16, FLASH 68, 116 (53, 152)
134-136 FOR/NEXT 64-67, 116-117, 143, 144
diskette Applesoft: see Applesoft (11-14, 2(11, 78, 79, 152)
BASIC format: see number format
Disk Operating System: see DOS function 35 (73, 1(112-1(14)
division 24, 39-42
(2, 18, 33, 36)
DOS (Disk Operating System)
booting 15-16
G
commands 16, 114, 12(11, 123, 135 game controls 3, 4, 2(11, 34, 48-51,
memory requirements 135, 137- 121 (9(11, 134, 135)
138, 14~-142 GAME I/O socket 4
recovering from accidental GOSUB/RETURN 87-91, 117, 143, 145,
RESETs 148-149 146 (15, 16, 79, 8~, 119, 153)
152
GOTO 50, 59, 62-64, 117, 146 !NT 83, 119 (19, 102, 155)
76, 81, 153)
(7, integer (2, 4)
GR 30, 33, 62, 86, 117 INT function: see INT
(5, 11, 23-25, 84, 131-134, 153) rounding 25 (18, 31)
graphics variables 36-38 (18, 31, 145)
high-resolution 91-97, 137-142 Integer BASIC 2, 132, 134, 136,
(25-27, 87-100, 126, 131-l34) 148-149
low-resolution 29 -34, 60, 62- interrupting execution: see CTRL C
67, 74-79, 85-87, 89-91 and RESET
(5, 10, 23-25, 83-87, INVERSE 68, 119 (53, 155)
131-134)
greater than [>J 55, 59
J
H J key (with ESC): see editing
153
looping 5(1, 59, 62 - 67, 116-117
(11 -1 4, 2(3 )
o
incrementing 66, 116-117 Old Monitor ROM 2, 147-149
(13, 78) one (in assertions) 55 - 58
low-resolution graphics: see OR 58-59 (33, 36)
graphics
p
M paddle 34, 121
M key (with ESC): see editing parenth eses 41-42, 58, 1(36
memory 131-132, 137-138 pause: see delay loop
(2, 8, 4(1, 41) PDL 34- 35, 48 - 51, 94 - 95, 121
HGR2 118, 138, 142 (88) (9(3, 157)
ma p 14(1-142 PEEK 8(3 - 81, 141, 144
r e quireme nts 135, 136, 14(1-142 (4(3, 131, 134-136, 157)
menu 17 PLOT 3(1- 33, 121
MIC o r MICROPHONE jack 5 (5, 1(3, 24, 85, 157)
MlD$ 11]1-11;13, 121, 144 POKE 138 , 144
(2(3, 61, 156) power co rd 3
modes POWER light 5
debug: see TRACE power switch 5
exec ution: see execution precedence of operators 39-42, 59
modul a tor, RF 3-4 (36)
NON or MONITOR jack 5 PRINT 22 - 23, 35, 44, 122
Monitor program (2, 6, 7, 7(3, 71, 157)
entering 114, 133, 148 comma 68-7(3, 122
Monitor ROM 2, 147-149 semi- co lon 68- 7(3, 122
monitor, TV 3-4 program, definit io n of 47
moving the cursor 11, 27 - 29, 52- prompt c haract e r 13, 17, 22, 133,
53, 114, 116, 128-129 136 (35, 84, 1(36, 1(38)
(5(1 - 52, 54, 55, 11(3-114, 131) PRII 16 (72, 158)
multiple statements on a line 81-82 pure c ursor moves 52 -53, 116, 128
(1(3, 125)
multiplic a tion 23, 39- 42 (2, 33, 36)
Q
N question mark
INPUT 75 - 77 (7, 66, 67)
negative numbers 39-42 quotation marks
nest ed loops 66-67, 144 INPUT 76 (66)
NEW 44 - 46, 121 (3, 8, 38, 156) PRINT 22, 27, 36
NEXT: see FOR/NEXT strings 1(1(1, 1(35 (19, 34)
NORMAL 68, 121 (53, 156)
NOT 57 (33, 34, 36)
NOTRACE 88, 121
null string 1(11
(4(3, 156) R
number format 25-26, 144 (4, 5, random number function: see RND
18, 22, 31 - 33) REENTER 76
REM 63, 122 (8, 1(3, 5(1, 118, 158)
Replacing lines: see editing
REPT key 1(1, 52, 122, 128 (55,
111-114, 158)
154
r ese rv ed wo rd s 37, 126-1 27 (7, 8 , s t o pp i ng th e comput e r 17
38, 64, 87 , 14 8) listings 75, 115, 1 2~
RESET key 6, 2~, 51, 1 2 ~, 14 7 programs 5~ - 5 1, 11 5
r ecover i ng from 148-149 (7, 1~, 16, 38, 39)
stopping a program 51 ( 39) STR$ 1r) 7, 124 (21, 22, 59 , 1 6 ~)
RETURN 87, 122 strings lr)r)-1r) 8 (1 8- 23 , 34)
(15, 16, 79, 8~, 158) co nca t ena ti o n 1r)5 (21, 52 , 71)
RETURN key lC)-l1, 17 , 26 INPUT lr)2 (66, 67, 154, 155)
(2, 3 , 7, 35) LEFT$ 1r)1, 119 ( 2 ~, 6~, 155)
r e t ype key 28 - 29 , 53 , 114, 128 LEN 1r)(}-1(}1, 120 (19, 20, 59,
RF modulator 3 155)
RIGHT$ U)l, 122, 144 MlD$ 101-10 3 , 12 1
(20, 61 , 158) (20, 2 1, 61, 156)
right - a rrow key 11, 27 - 29 , 53 , null strings 1r)1 (19, 6(), 61 ,
114, 128 (54, 55, 110-114, 15~) 67 , 69, 76, 77)
RND 82 - 85 , 123 RIGHT $ 1r)1-10 2, 122
(1 8 , 27 , 10 2 , 141, 159) STR$ 107, 124
ROM -Applesoft: see Applesoft II (2l, 22 , 59 , 16(} )
Firmware Ca rd VAL 1(}6-1r) 7, 124
r o undin g 25 (4, 5 , 18, 19, 31- 33) ( 2 1, 23 , 5 9, 161)
wi th g raphi cs 64 s ubroutin e 85 - 91
r ows 29 (16, 22, 79, 8(})
RUN 13 , 14, 16, 17, 20, 44 - 46, 51, s ub script 1(} 8 , 144
65, 123 (2 , 8, 38 , 39, 159) (14, 15, 34 , 58)
s ubtra c ti on 23 , 39- 42
SYNTAX ERROR 11, 12 , 22 , 32, 37 ,
s 145
Sys t em Mas t e r diskett e 15, 16 ,
SAVE 6~-6 2 , 123 (38 , 159) 134-1 35
savi ng pr og r ams
on diske tt e 60 - 6 1, 123
on casse tt e tape 61 - 62, 123 T
scienti fic no tati on 25 - 26 (4 , 5 )
sc r een t ab
c l earing : see c l ea ring th e HTAB 7(} - 71, 11 8 (50, 51 )
sc reen TAB 7r)-71, 12 4 (51, 16~)
ske t c hing sc reen pr og r am 63 , VTAB 7r)-71, 125 ( 5 ~)
94 TEXT 30, 62, 88 (6, 11, 84 , 160)
se mi - colon 69, 76 (3~, 33) THEN: see IF/THEN
INPUT 76 (66-67) TO: see HPLOT an d GOTO
PRINT 69 (6, 7r), 71) TRACE 87 - 88 , 91, 124
se ttin g th e tap e r eco rd e r 11-14 (40, 82 , 161 )
se tt i ng the TV color 18-1 9 TV monitor 3- 4
SHIFT key 7
s l o t s 0 thr oug h 7 1 6, 134
(71, 72)
sounds, gen er a tin g 7 8- 81
u
s pacing 6 9-71
s pea ke r 79 - 8 1 (134, 135)
s qu a r e bracke t 11, 16, 22
v
s tat ement s , multiple 81 - 82 (1~, 125 ) VAL 1r) 6- 107, 124 ( 2 1, 23, 59 ,
STEP 66 , 116-11 7 (1 3 , 78, 152) 161)
155
variables 3 7-3 8, 89 (7, 8 , 31 - 35)
array U) 8, 11(.1 04, 58)
FOR/NEXT loop s 64-67, 116,11 7,
143, 144 (12, 13, 78, 79)
INPUT 75-77, 1(.1 2-1(.13, 119
(7, 9, 66 , 67 , 71)
i nt eger 36- 38 (18, 19, 31)
names 36- 38, 1(.1(.1, 12(.1
(7, 8, 14, 18 3 1-35)
s tring 1(.1(.1-1(.14, 12(.1 (1 8)
verti cal lines, plotting : see
VLIN
VIDEO OUT jack 4
VLIN 33 - 34 , 124 (6, 25 , 86 , 161 )
VIAB 7(.1-71, 125 ( 2 7, 5(.1, 161)
w
x
Xcoo rd i n a t e 29,64, 71, 85 - 87,
91, 95
y
Y coo rdinat e 29 , 64 , 71, 85 - 87 ,
91, 95
z
ze r o 8, 22, 14 3
in assertions 55 -58
156